UNPKG

@aeternity/aepp-sdk

Version:

SDK for the æternity blockchain

77 lines (76 loc) 3.11 kB
import AeSdkBase from './AeSdkBase.js'; import { OnAccount } from './AeSdkMethods.js'; import AccountBase from './account/Base.js'; import { Encoded } from './utils/encoder.js'; import { Accounts, WalletInfo, Network, WalletApi, AeppApi, Node as NodeRpc, NetworkToSelect } from './aepp-wallet-communication/rpc/types.js'; import RpcClient from './aepp-wallet-communication/rpc/RpcClient.js'; import { METHODS, SUBSCRIPTION_TYPES } from './aepp-wallet-communication/schema.js'; import BrowserConnection from './aepp-wallet-communication/connection/Browser.js'; /** * RPC handler for AEPP side * Contain functionality for wallet interaction and connect it to sdk * @deprecated use WalletConnectorFrame instead * @category aepp wallet communication */ export default class AeSdkAepp extends AeSdkBase { name: string; onAddressChange: (a: Accounts) => void; onDisconnect: (p: any) => void; onNetworkChange: (a: Network) => void; rpcClient?: RpcClient<WalletApi, AeppApi>; _accounts?: Accounts; /** * @param options - Options * @param options.name - Aepp name * @param options.onAddressChange - Call-back function for update address event * @param options.onDisconnect - Call-back function for disconnect event * @param options.onNetworkChange - Call-back function for update network event */ constructor({ name, onAddressChange, onDisconnect, onNetworkChange, ...other }: { name: string; onAddressChange?: (a: Accounts) => void; onDisconnect?: (p: any) => void; onNetworkChange?: (a: Network) => void; } & ConstructorParameters<typeof AeSdkBase>[0]); _resolveAccount(account?: OnAccount): AccountBase; addresses(): Encoded.AccountAddress[]; /** * Connect to wallet * @param connection - Wallet connection object * @param options - Options * @param options.connectNode - Request wallet to bind node * @param options.name - Node name */ connectToWallet(connection: BrowserConnection, { connectNode, name }?: { connectNode?: boolean; name?: string; }): Promise<WalletInfo & { node?: NodeRpc; }>; /** * Disconnect from wallet */ disconnectWallet(): void; /** * Ask addresses from wallet * @returns Addresses from wallet */ askAddresses(): Promise<Encoded.AccountAddress[]>; /** * Subscribe for addresses from wallet * @param type - Subscription type * @param value - Should be one of 'current' (the selected account), 'connected' (all) * @returns Accounts from wallet */ subscribeAddress(type: SUBSCRIPTION_TYPES, value: 'current' | 'connected'): Promise<ReturnType<WalletApi[METHODS.subscribeAddress]>>; /** * Ask wallet to select a network */ askToSelectNetwork(network: NetworkToSelect): Promise<void>; _ensureConnected(): asserts this is AeSdkAepp & { rpcClient: NonNullable<AeSdkAepp['rpcClient']>; }; _ensureAccountAccess(): asserts this is AeSdkAepp & { rpcClient: NonNullable<AeSdkAepp['rpcClient']>; }; }