@celo/wallet-base
Version:
Wallet base implementation
67 lines (66 loc) • 2.69 kB
TypeScript
/// <reference types="node" />
import { Address, CeloTx, EncodedTransaction, ReadOnlyWallet, Signer } from '@celo/connect';
import { EIP712TypedData } from '@celo/utils/lib/sign-typed-data-utils';
type addInMemoryAccount = (privateKey: string) => void;
type addRemoteAccount = (privateKey: string, passphrase: string) => Promise<string>;
export interface Wallet extends ReadOnlyWallet {
addAccount: addInMemoryAccount | addRemoteAccount;
}
export interface UnlockableWallet extends Wallet {
unlockAccount: (address: string, passphrase: string, duration: number) => Promise<boolean>;
isAccountUnlocked: (address: string) => boolean;
}
export declare abstract class WalletBase<TSigner extends Signer> implements ReadOnlyWallet {
private accountSigners;
/**
* Gets a list of accounts that have been registered
*/
getAccounts(): Address[];
/**
* Removes the account with the given address. Needs to be implemented by subclass, otherwise throws error
* @param _address The address of the account to be removed
*/
removeAccount(_address: string): void;
/**
* Returns true if account has been registered
* @param address Account to check
*/
hasAccount(address?: Address): boolean;
/**
* Adds the account-signer set to the internal map
* @param address Account address
* @param signer Account signer
*/
protected addSigner(address: Address, signer: TSigner): void;
/**
* Removes the account-signer
* @param address Account address
*/
protected removeSigner(address: Address): void;
/**
* Gets the signer based on the 'from' field in the tx body
* @param txParams Transaction to sign
*/
signTransaction(txParams: CeloTx): Promise<EncodedTransaction>;
/**
* Sign a personal Ethereum signed message.
* @param address Address of the account to sign with
* @param data Hex string message to sign
* @return Signature hex string (order: rsv)
*/
signPersonalMessage(address: Address, data: string): Promise<string>;
/**
* Sign an EIP712 Typed Data message.
* @param address Address of the account to sign with
* @param typedData the typed data object
* @return Signature hex string (order: rsv)
*/
signTypedData(address: Address, typedData: EIP712TypedData): Promise<string>;
protected getSigner(address: string): TSigner;
decrypt(address: string, ciphertext: Buffer): Promise<Buffer>;
/**
* Computes the shared secret (an ECDH key exchange object) between two accounts
*/
computeSharedSecret(address: Address, publicKey: string): Promise<Buffer>;
}
export {};