UNPKG

@aptos-labs/wallet-adapter-core

Version:
267 lines 9.52 kB
import EventEmitter from "eventemitter3"; import { AccountAuthenticator, AnyRawTransaction, InputSubmitTransactionData, Network, PendingTransactionResponse, TransactionSubmitter } from "@aptos-labs/ts-sdk"; import { AptosWallet, AptosSignAndSubmitTransactionOutput, NetworkInfo, AccountInfo, AptosSignMessageInput, AptosSignMessageOutput, AptosChangeNetworkOutput, AptosSignInInput, AptosSignInOutput } from "@aptos-labs/wallet-standard"; import { AptosConnectWalletConfig } from "@aptos-connect/wallet-adapter-plugin"; export type { NetworkInfo, AccountInfo, AptosSignAndSubmitTransactionOutput, AptosSignTransactionOutputV1_1, AptosSignMessageInput, AptosSignMessageOutput, AptosChangeNetworkOutput, } from "@aptos-labs/wallet-standard"; export type { AccountAuthenticator, AnyRawTransaction, InputGenerateTransactionOptions, PendingTransactionResponse, InputSubmitTransactionData, Network, AnyPublicKey, AccountAddress, TransactionSubmitter, } from "@aptos-labs/ts-sdk"; import { WalletReadyState } from "./constants"; import { AvailableWallets, InputTransactionData } from "./utils/types"; export type AdapterWallet = AptosWallet & { readyState?: WalletReadyState; isAptosNativeWallet?: boolean; }; export type AdapterNotDetectedWallet = Omit<AdapterWallet, "features" | "version" | "chains" | "accounts"> & { readyState: WalletReadyState.NotDetected; }; export interface DappConfig { network: Network; /** * If provided, the wallet adapter will submit transactions using the provided * transaction submitter rather than via the wallet. */ transactionSubmitter?: TransactionSubmitter; aptosApiKeys?: Partial<Record<Network, string>>; aptosConnectDappId?: string; aptosConnect?: Omit<AptosConnectWalletConfig, "network">; /** * @deprecated will be removed in a future version */ mizuwallet?: { manifestURL: string; appId?: string; }; msafeWalletConfig?: { appId?: string; appUrl?: string; }; crossChainWallets?: boolean; } export declare interface WalletCoreEvents { connect(account: AccountInfo | null): void; disconnect(): void; standardWalletsAdded(wallets: AdapterWallet): void; standardNotDetectedWalletAdded(wallets: AdapterNotDetectedWallet): void; networkChange(network: NetworkInfo | null): void; accountChange(account: AccountInfo | null): void; } export type AdapterAccountInfo = Omit<AccountInfo, "ansName"> & { ansName?: string; }; export declare class WalletCore extends EventEmitter<WalletCoreEvents> { private _wallet; private readonly _sdkWallets; private _standard_wallets; private _standard_not_detected_wallets; private _network; private _connected; private _connecting; private _account; private _dappConfig; private _optInWallets; private _disableTelemetry; private readonly ga4; constructor(optInWallets?: ReadonlyArray<AvailableWallets>, dappConfig?: DappConfig, disableTelemetry?: boolean); private fetchExtensionAIP62AptosWallets; /** * Set AIP-62 extension wallets * * @param extensionwWallets */ private setExtensionAIP62Wallets; /** * Set AIP-62 SDK wallets */ private fetchSDKAIP62AptosWallets; private isAptosNativeWallet; private appendNotDetectedStandardSupportedWallets; /** * A function that excludes an AIP-62 compatible wallet the dapp doesnt want to include * * @param wallet AdapterWallet | AdapterNotDetectedWallet * @returns boolean */ excludeWallet(wallet: AdapterWallet | AdapterNotDetectedWallet): boolean; private recordEvent; /** * Helper function to ensure wallet exists * * @param wallet A wallet */ private ensureWalletExists; /** * Helper function to ensure account exists * * @param account An account */ private ensureAccountExists; /** * Queries and sets ANS name for the current connected wallet account */ private setAnsName; /** * Function to cleat wallet adapter data. * * - Removes current connected wallet state * - Removes current connected account state * - Removes current connected network state * - Removes autoconnect local storage value */ private clearData; /** * Sets the connected wallet * * @param wallet A wallet */ setWallet(wallet: AptosWallet | null): void; /** * Sets the connected account * * @param account An account */ setAccount(account: AccountInfo | null): void; /** * Sets the connected network * * @param network A network */ setNetwork(network: NetworkInfo | null): void; /** * Helper function to detect whether a wallet is connected * * @returns boolean */ isConnected(): boolean; /** * Getter to fetch all detected wallets */ get wallets(): ReadonlyArray<AptosWallet>; get notDetectedWallets(): ReadonlyArray<AdapterNotDetectedWallet>; /** * Getter for the current connected wallet * * @return wallet info * @throws WalletNotSelectedError */ get wallet(): AptosWallet | null; /** * Getter for the current connected account * * @return account info * @throws WalletAccountError */ get account(): AccountInfo | null; /** * Getter for the current wallet network * * @return network info * @throws WalletGetNetworkError */ get network(): NetworkInfo | null; /** * Helper function to run some checks before we connect with a wallet. * * @param walletName. The wallet name we want to connect with. */ connect(walletName: string): Promise<void | string>; /** * Signs into the wallet by connecting and signing an authentication messages. * * For more information, visit: https://siwa.aptos.dev * * @param args * @param args.input The AptosSignInInput which defines how the SIWA Message should be constructed * @param args.walletName The name of the wallet to sign into * @returns The AptosSignInOutput which contains the account and signature information */ signIn(args: { input: AptosSignInInput; walletName: string; }): Promise<AptosSignInOutput>; /** * Connects a wallet to the dapp. * On connect success, we set the current account and the network, and keeping the selected wallet * name in LocalStorage to support autoConnect function. * * @param selectedWallet. The wallet we want to connect. * @emit emits "connect" event * @throws WalletConnectionError */ private connectWallet; /** * Disconnect the current connected wallet. On success, we clear the * current account, current network and LocalStorage data. * * @emit emits "disconnect" event * @throws WalletDisconnectionError */ disconnect(): Promise<void>; /** * Signs and submits a transaction to chain * * @param transactionInput InputTransactionData * @returns AptosSignAndSubmitTransactionOutput */ signAndSubmitTransaction(transactionInput: InputTransactionData): Promise<AptosSignAndSubmitTransactionOutput>; /** * Signs a transaction * * This method supports 2 input types - * 1. A raw transaction that was already built by the dapp, * 2. A transaction data input as JSON. This is for the wallet to be able to simulate before signing * * @param transactionOrPayload AnyRawTransaction | InputTransactionData * @param asFeePayer optional. A flag indicates to sign the transaction as the fee payer * @param options optional. Transaction options * * @returns AccountAuthenticator */ signTransaction(args: { transactionOrPayload: AnyRawTransaction | InputTransactionData; asFeePayer?: boolean; }): Promise<{ authenticator: AccountAuthenticator; rawTransaction: Uint8Array; }>; /** * Sign a message (doesnt submit to chain). * * @param message - AptosSignMessageInput * * @return response from the wallet's signMessage function * @throws WalletSignMessageError */ signMessage(message: AptosSignMessageInput): Promise<AptosSignMessageOutput>; /** * Submits transaction to chain * * @param transaction - InputSubmitTransactionData * @returns PendingTransactionResponse */ submitTransaction(transaction: InputSubmitTransactionData): Promise<PendingTransactionResponse>; /** Event for when account has changed on the wallet @return the new account info @throws WalletAccountChangeError */ onAccountChange(): Promise<void>; /** Event for when network has changed on the wallet @return the new network info @throws WalletNetworkChangeError */ onNetworkChange(): Promise<void>; /** * Sends a change network request to the wallet to change the connected network * * @param network - Network * @returns AptosChangeNetworkOutput */ changeNetwork(network: Network): Promise<AptosChangeNetworkOutput>; /** * Signs a message and verifies the signer * @param message - AptosSignMessageInput * @returns boolean */ signMessageAndVerify(message: AptosSignMessageInput): Promise<boolean>; } //# sourceMappingURL=WalletCore.d.ts.map