import { Account, Connection, keyStores, Near, utils } from "near-api-js"; import type { Transaction, Action, Optional } from "@near-wallet-selector/core"; import { IMeteorActionResponse_Output, IOMeteorWalletSdk_RequestSignIn_Inputs, IOMeteorWalletSdk_SignIn_Output, IOMeteorWalletSdkAccount_SignAndSendTransaction_Input, IORequestSignTransactions_Inputs, IODappAction_VerifyOwner_Input, IODappAction_VerifyOwner_Output, IOWalletExternalLinkedContract, IODappAction_SignMessage_Input, IODappAction_SignMessage_Output } from "../../meteor-common/src/modules_feature/dapp_connect/types_dappConnect"; import type { FinalExecutionOutcome } from "near-api-js/lib/providers"; import type { NearConfig } from "near-api-js/lib/near"; import { AccessKeyInfoView } from "@perk.money/perk-swap-core"; interface IMeteorAuthData { allKeys: string[]; accountId?: string; signedInContract?: IOWalletExternalLinkedContract; } export interface IMeteorWallet_Constructor { near: Near; appKeyPrefix?: string; } export interface IMeteorWallet_create_Inputs extends Partial { networkId: string; appKeyPrefix?: string; } declare global { interface Window { meteorWallet: any; } } /** * This class is used in conjunction with `near-api-js` and `BrowserLocalStorageKeyStore`. * It directs users to the Meteor Extension or (if not available) a popup of the Meteor Wallet website for key management. * * @example * ```js * import { MeteorWallet } from "@meteorwallet/sdk"; * * // create new MeteorWallet instance (passing in your initialized Near connection) * const meteorWallet = new MeteorWallet({ near: connectedNear, appKeyPrefix: 'my-app' }); * * // -- or -- (for a quick and default Near connection config) * const meteorWallet = MeteorWallet.init({ networkId: "testnet" }); * * // If not signed in, start the sign-in flow with Meteor Wallet. * // Keys will be stored in the BrowserLocalStorageKeyStore * if(!meteorWallet.isSignedIn()) { * const { accountId } = await meteorWallet.requestSignIn(); * } * ``` */ export declare class MeteorWallet { /** @hidden */ _walletBaseUrl: string; /** @hidden */ _authDataKey: string; /** @hidden */ _keyStore: keyStores.KeyStore; /** @hidden */ _authData: IMeteorAuthData; /** @hidden */ _networkId: string; /** @hidden */ _near: Near; /** @hidden */ _connectedAccount: ConnectedMeteorWalletAccount | undefined; /** @hidden */ _initializationPromises: Promise[]; /** * The easiest way to set up the SDK. Returns an instance of MeteorWallet, automatically connected to the Near API. * * If you need more control over the Near Network configuration- rather use {@link MeteorWallet:constructor} * * @example * ```js * const wallet = await MeteorWallet.init({ networkId: "testnet" }); * ``` */ static init({ walletUrl, ...config }: IMeteorWallet_create_Inputs): Promise; /** * Construct MeteorWallet. If you'd a quick and default way, you can also use {@link MeteorWallet.init} * * @example * ```js * // create new MeteorWallet instance (passing in your initialized Near connection) * const meteorWallet = new MeteorWallet({ near: connectedNear, appKeyPrefix: 'my-app' }); * * if(!meteorWallet.isSignedIn()) { * const { accountId } = await meteorWallet.requestSignIn(); * } * ``` */ constructor({ near, appKeyPrefix, }: IMeteorWallet_Constructor); isExtensionInstalled(): boolean; /** * Returns true, if this app is authorized with an account in the wallet. * @example * ```js * const wallet = new MeteorWallet({ near: connectedNear, appKeyPrefix: 'my-app' }); * wallet.isSignedIn(); * ``` */ isSignedIn(): boolean; /** * Returns authorized Account ID. * @example * ```js * const wallet = new MeteorWallet(near, 'my-app'); * const accountId = wallet.getAccountId(); * ``` */ getAccountId(): string | undefined; /** * Verifies that the user is the owner of a specific Near account, available in the wallet. * Removes the need to do blockchain operations for simple Dapp actions. * Signs a payload with the wallet's private key. Will return a promise with a payload like so: * * ```ts * interface VerifiedOwner { * accountId: string; * message: string; // The same passed message, unencrypted * blockId: string; * publicKey: string; // The public key which should be verified as belonging to this account * signature: string; // The signed payload (this exact same object JSON stringified, excluding this "signature" property) * keyType: utils.key_pair.KeyType; // Type from inside the near-api-js package * } * ``` * * or throw a {@link MeteorActionError} error if the verification failed for whatever reason. * */ verifyOwner(options: IODappAction_VerifyOwner_Input): Promise>; /** * Requests a sign-in using Meteor Wallet. Will return a promise with the `accountId` of the * signed-in account, or throw a {@link MeteorActionError} error if the sign-in failed for whatever reason. * */ requestSignIn(options: IOMeteorWalletSdk_RequestSignIn_Inputs): Promise>; /** * Sign out from the current account */ signOut(): Promise; /** * Allows users to sign a message for a specific recipient using their NEAR account, based on the [NEP413](https://github.com/near/NEPs/pull/413). * * Will return a promise with a payload like so: * * ```ts * interface signMessage { * accountId: string; // The account name to which the publicKey corresponds as plain text * publicKey: string; // The public counterpart of the key used to sign * signature: string; // The base64 representation of the signature * state?: string; // The same state passed in. * } * ``` * * or throw a {@link MeteorActionError} error if the signing failed for whatever reason. * */ signMessage({ message, nonce, recipient, callbackUrl, state, accountId, }: IODappAction_SignMessage_Input): Promise>; /** * Sign transactions using Meteor Wallet. Will return a promise with an array of `FinalExecutionOutcome` * of the given transactions. * */ requestSignTransactions(inputs: IORequestSignTransactions_Inputs): Promise; /** * Returns the current connected wallet account */ account(): ConnectedMeteorWalletAccount | undefined; transformTransactions(transactions: Array>): Promise; } /** * Near Account implementation which makes use of {@link MeteorWallet} when no local key is available. * * Generally won't be created directly- can be obtained by using {@link MeteorWallet.account} * * @example * ```js * const account = meteorWallet.account(); * * // uses Meteor Wallet to sign the transaction using this account * const response = await account.requestSignTransaction({ * actions: transactionActions, * receiverId: "my-contract" * }); * ``` */ export declare class ConnectedMeteorWalletAccount extends Account { /** @hidden */ meteorWallet: MeteorWallet; /** @hidden */ constructor(walletConnection: MeteorWallet, connection: Connection, accountId: string); /** * Sign a transaction using Meteor Wallet. Overrides the Near Account API method of the same name, makes use of {@link ConnectedMeteorWalletAccount.signAndSendTransaction_direct} */ signAndSendTransaction(...args: any[]): Promise; /** @hidden */ private trySendOrCreateTransaction; /** * Sign a transaction using Meteor Wallet * @see {@link MeteorWallet.requestSignTransactions} */ signAndSendTransaction_direct({ receiverId, actions, }: IOMeteorWalletSdkAccount_SignAndSendTransaction_Input): Promise; /** @hidden */ /** * Check if given access key allows the function call or method attempted in transaction * @param accessKey Array of {access_key: AccessKey, public_key: PublicKey} items * @param receiverId The NEAR account attempting to have access * @param actions The action(s) needed to be checked for access */ accessKeyMatchesTransaction(accessKey: AccessKeyInfoView, receiverId: string, actions: Action[]): Promise; /** * Helper function returning the access key (if it exists) to the receiver that grants the designated permission * @param localKey A local public key provided to check for access * @returns Promise */ accessKeyForTransaction(localKey?: utils.PublicKey): Promise; } export {};