@funded-labs/plug-controller
Version:
Internet Computer Plug wallet's controller
164 lines (163 loc) • 6.17 kB
TypeScript
/// <reference types="node" />
import CryptoJS from 'crypto-js';
import { CreateCertificateOptions, HttpAgent, PublicKey } from '@dfinity/agent';
import { NFTDetails, TokenInterfaces } from '@funded-labs/dab-js';
import PlugWallet from '../PlugWallet';
import { PlugStateStorage } from '../interfaces/plug_keyring';
import { FormattedTransactions } from '../interfaces/transactions';
import { KeyringStorage } from '../interfaces/storage';
import { TokenBalance, StandardToken } from '../interfaces/token';
import { WalletNFTCollection, WalletNFTInfo } from '../interfaces/plug_wallet';
import { Address } from '../interfaces/contact_registry';
import { RegisteredNFT } from './modules/NetworkModule/Network';
import { CreateImportResponse, CreateOptions, CreatePrincipalOptions, ImportMnemonicOptions, ImportFromPemOptions, GetPrincipalFromPem, ValidatePemResponse, ImportFromSecretKey } from './interfaces';
import { GenericSignIdentity } from '../utils/identity/genericSignIdentity';
declare class PlugKeyRing {
private state;
isUnlocked: boolean;
isInitialized: boolean;
currentWalletId: string;
mnemonicWalletCount: number;
private storage;
private fetch;
private crypto;
private networkModule;
private blsVerify?;
getBalances: (args?: {
subaccount?: string;
}) => Promise<Array<TokenBalance>>;
getNFTs: (args?: {
subaccount?: string;
refresh?: boolean;
}) => Promise<WalletNFTCollection[] | null>;
transferNFT: (args: {
subaccount?: string;
token: NFTDetails;
to: string;
standard: string;
}) => Promise<boolean>;
burnXTC: (args?: {
to: string;
amount: string;
subaccount?: string;
}) => Promise<TokenInterfaces.BurnResult>;
registerToken: (args: {
canisterId: string;
standard?: string;
subaccount?: string;
logo?: string;
shouldFetchBalance?: boolean;
}) => Promise<TokenBalance>;
removeToken: (args: {
canisterId: string;
subaccount?: string;
}) => Promise<Array<StandardToken>>;
getTokenInfo: (args: {
canisterId: string;
standard?: string;
subaccount?: string;
}) => Promise<TokenBalance>;
getICNSData: (args: {
subaccount?: string;
}) => Promise<{
names: string[];
reverseResolvedName: string | undefined;
}>;
setReverseResolvedName: (args: {
name: string;
subaccount?: string;
}) => Promise<string>;
sign: (args: {
payload: ArrayBuffer;
subaccount?: string;
}) => Promise<ArrayBuffer>;
getContacts: (args: {
subaccount?: string;
}) => Promise<Array<Address>>;
addContact: (args: {
contact: Address;
subaccount?: string;
}) => Promise<boolean>;
deleteContact: (args: {
addressName: string;
subaccount?: string;
}) => Promise<boolean>;
getAgent: (args?: {
subaccount?: string;
host?: string;
}) => HttpAgent;
getBalance: (args: {
token: StandardToken;
subaccount?: string;
}) => Promise<TokenBalance>;
getTransactions: (args: {
subaccount?: string;
icpPrice: number;
}) => Promise<FormattedTransactions>;
send: (args: {
subaccount?: string;
to: string;
amount: string;
canisterId: string;
opts?: TokenInterfaces.SendOpts;
}) => Promise<TokenInterfaces.SendResponse>;
delegateIdentity: (args: {
to: Buffer;
targets: string[];
subaccount?: string;
}) => Promise<string>;
getNFTInfo: (args: {
canisterId: string;
standard?: string;
subaccount?: string;
}) => Promise<WalletNFTInfo>;
registerNFT: (args: {
canisterId: string;
standard?: string;
subaccount?: string;
}) => Promise<RegisteredNFT[]>;
approve: (args: {
spender: string;
amount: bigint;
canisterId: string;
nonce?: bigint;
}) => Promise<TokenInterfaces.ApproveResponse>;
constructor(StorageAdapter?: KeyringStorage, CryptoAdapter?: typeof CryptoJS, FetchAdapter?: any, blsVerify?: CreateCertificateOptions['blsVerify']);
private exposeWalletMethods;
private exposeMainWalletMethods;
getPublicKey: (subaccount?: string | undefined) => Promise<PublicKey>;
private getWallet;
private updateWallet;
getWalletIdFromIndex: (index: number) => Promise<String>;
init: () => Promise<void>;
getMnemonic(password: string): Promise<string>;
private loadFromPersistance;
create: ({ password, icon, name, entropy, }: CreateOptions) => Promise<CreateImportResponse>;
importMnemonic: ({ mnemonic, password, }: ImportMnemonicOptions) => Promise<CreateImportResponse>;
importAccountFromPem: ({ icon, name, pem, }: ImportFromPemOptions) => Promise<PlugWallet>;
importAccountFromPrivateKey: ({ icon, name, secretKey, }: ImportFromSecretKey) => Promise<PlugWallet>;
getPrincipalFromPem: ({ pem, }: GetPrincipalFromPem) => Promise<string>;
deleteImportedAccount: (walletId: string) => Promise<void>;
validatePem: ({ pem, }: ImportFromPemOptions) => Promise<ValidatePemResponse>;
private checkRepeatedAccount;
createPrincipal: (opts?: CreatePrincipalOptions | undefined) => Promise<PlugWallet>;
setCurrentPrincipal: (walletId: string) => Promise<void>;
getState: () => Promise<PlugStateStorage>;
unlock: (password: string) => Promise<boolean>;
lock: () => Promise<void>;
editPrincipal: (walletId: string, { name, emoji }: {
name?: string | undefined;
emoji?: string | undefined;
}) => Promise<void>;
private validateSubaccount;
private checkInitialized;
getPemFile: (walletId?: string | undefined) => Promise<string>;
getIdentity: (walletId?: string | undefined) => Promise<GenericSignIdentity>;
private checkUnlocked;
private createAndPersistKeyRing;
private saveEncryptedState;
private decryptState;
checkPassword: (password: string) => Promise<boolean>;
private getMainAccountId;
}
export default PlugKeyRing;