simple-nano-wallet
Version:
Benskalz' simple-nano-wallet rewritten in TypeScript with some additional features.
86 lines (85 loc) • 2.95 kB
TypeScript
import { NanoAccount, WalletConfig, PendingTransaction } from './types';
import { Tools } from './tools';
declare class Wallet {
private readonly config;
private accountMap;
private processedTransactionHashes;
private lastIndex;
private readonly rpc;
private websocket?;
private activeSubscriptions;
private toolsInstance;
constructor(config: WalletConfig);
send: (params: {
source: string;
destination: string;
amount: string;
}) => Promise<string>;
receive: (account: string, transaction: PendingTransaction) => Promise<string>;
/**
* Get the list of accounts addresses in the wallet
*/
get accounts(): string[];
/**
* Get the map of accounts with their public and private keys, indexed by address
*/
get accountsWithKeys(): Map<string, NanoAccount>;
/**
* Get the tools instance for this wallet, providing utility functions for working with Nano amounts
*/
get tools(): Tools;
private validateConfig;
private initializeWebSocket;
private setupWebSocketHandlers;
/**
* Initialize the wallet with a specific seed
* @returns A new wallet with a random seed and a single account
*/
generateWallet(): {
seed: string;
address: string;
};
private initializeWallet;
/**
* Generate a number of new accounts from the wallet seed
* @param count Amount of accounts to generate
* @returns List of generated account addresses
*/
generateAccounts(count: number): string[];
private formatAccount;
/**
* Send funds from one account to another
* @param params Source, destination and RAW amount of the transaction
* @returns Transaction hash if successful
* @throws AccountError if the source or destination address is invalid
* @throws TransactionFailedError if the transaction fails
*/
sendFunds(params: {
source: string;
destination: string;
amount: string;
}): Promise<string>;
/**
* Receive receivable funds for an account
* @param account Account address to receive funds for
* @param transaction Receivable transaction to receive (amount in RAW)
* @returns Transaction hash if successful
* @throws AccountError if the account address is invalid
* @throws TransactionFailedError if the transaction fails
*/
receiveFunds(account: string, transaction: PendingTransaction): Promise<string>;
private validateAddress;
private validateRawAmount;
private getPrivateKey;
private removeOldProcessedTransactions;
private parseWebSocketMessage;
private handleAutoReceive;
private subscribeToAccounts;
private resubscribeAccounts;
private prepareReceiveBlock;
/**
* Shutdown the wallet, closing the WebSocket connection and clearing all account data
*/
shutdown(): void;
}
export { Wallet };