UNPKG

@safik/fk-plug-controller

Version:

Internet Computer Plug wallet's controller

99 lines (98 loc) 3.93 kB
/// <reference types="node" /> import CryptoJS from 'crypto-js'; import { PublicKey } from '@dfinity/agent'; import { BinaryBlob } from '@dfinity/candid'; import { NFTDetails, NFTCollection } from '@safik/fk-dab-js'; import { GetTransactionsResponse } from '../utils/dfx/history/rosetta'; import PlugWallet, { TokenBalance } from '../PlugWallet'; import { SendOpts } from '../utils/dfx/ledger/methods'; import { SendResponse } from '../utils/dfx/token'; import { StandardToken } from '../interfaces/ext'; import { BurnResult } from '../interfaces/xtc'; import { ConnectedApp } from '../interfaces/account'; interface KeyringStorage { isSupported: boolean; get: () => Promise<unknown>; set: (state: unknown) => Promise<void>; clear: () => Promise<void>; } interface PlugState { wallets: Array<PlugWallet>; password?: string; mnemonic?: string; currentWalletId?: number; } interface CreatePrincipalOptions { name?: string; icon?: string; } interface CreateOptions extends CreatePrincipalOptions { password: string; entropy?: Buffer; } interface ImportMnemonicOptions { mnemonic: string; password: string; } declare class PlugKeyRing { private state; private storage; private fetch; private crypto; isUnlocked: boolean; isInitialized: boolean; currentWalletId?: number; constructor(StorageAdapter?: KeyringStorage, CryptoAdapter?: typeof CryptoJS, FetchAdapter?: any); init: () => Promise<void>; getPublicKey: (subAccount: any) => Promise<PublicKey>; getNFTs: (subAccount?: number | undefined) => Promise<NFTCollection[] | null>; transferNFT: ({ subAccount, token, to, }: { subAccount?: number | undefined; token: NFTDetails; to: string; standard: string; }) => Promise<NFTCollection[]>; private loadFromPersistance; burnXTC: ({ to, amount, subAccount, }: { to: string; amount: string; subAccount: number; }) => Promise<BurnResult>; create: ({ password, icon, name, entropy, }: CreateOptions) => Promise<{ wallet: PlugWallet; mnemonic: string; }>; importMnemonic: ({ mnemonic, password, }: ImportMnemonicOptions) => Promise<{ wallet: PlugWallet; mnemonic: string; }>; createPrincipal: (opts?: CreatePrincipalOptions | undefined) => Promise<PlugWallet>; setCurrentPrincipal: (walletNumber: number) => Promise<void>; getState: () => Promise<PlugState>; sign: (payload: BinaryBlob, subAccount?: number | undefined) => Promise<BinaryBlob>; unlock: (password: string) => Promise<boolean>; lock: () => Promise<void>; editPrincipal: (walletNumber: number, { name, emoji }: { name?: string | undefined; emoji?: string | undefined; }) => Promise<void>; registerToken: (canisterId: string, standard?: string, subAccount?: number | undefined) => Promise<Array<StandardToken>>; getBalance: (subAccount?: number | undefined) => Promise<Array<TokenBalance>>; getTokenInfo: (canisterId: string, standard?: string, subAccount?: number | undefined) => Promise<{ token: StandardToken; amount: string; }>; getTransactions: (subAccount?: number | undefined) => Promise<GetTransactionsResponse>; private validateSubaccount; private checkInitialized; send: (to: string, amount: string, canisterId?: string | undefined, opts?: SendOpts | undefined) => Promise<SendResponse>; addConnectedApp: (app: ConnectedApp, subAccount?: number | undefined) => Promise<Array<ConnectedApp>>; deleteConnectedApp: (id: string, subAccount?: number | undefined) => Promise<Array<ConnectedApp>>; get currentWallet(): PlugWallet; getPemFile: (walletNumber?: number | undefined) => string; private checkUnlocked; private createAndPersistKeyRing; private saveEncryptedState; private decryptState; } export default PlugKeyRing;