UNPKG

libnemo

Version:

Nano cryptocurrency wallet library.

165 lines (164 loc) 6.5 kB
import { Block } from '../block'; import { Rpc } from '../rpc'; type KeyPair = { index?: number; privateKey?: string | Uint8Array<ArrayBuffer>; publicKey?: string | Uint8Array<ArrayBuffer>; }; /** * Represents a single Nano address and the associated public key. To include the * matching private key, it must be known at the time of object instantiation. * The frontier, balance, and representative for the account can also be set or * be fetched from the network. */ export declare class Account { #private; [key: string]: any; static get isInternal(): boolean; /** * @returns {'Account'} */ static get DB_NAME(): 'Account'; get address(): string; get index(): number | undefined; get publicKey(): string; get confirmed_balance(): bigint | undefined; get confirmed_height(): number | undefined; get confirmed_frontier(): string | undefined; get confirmed_frontier_block(): Block | undefined; get confirmed_receivable(): bigint | undefined; get confirmed_representative(): Account | undefined; get balance(): bigint | undefined; get block_count(): number | undefined; get frontier(): string | undefined; get frontier_block(): Block | undefined; get open_block(): string | undefined; get receivable(): bigint | undefined; get representative(): Account | undefined; get representative_block(): string | undefined; get weight(): bigint | undefined; set confirmed_balance(v: bigint | number | string); set confirmed_height(v: number | undefined); set confirmed_frontier(v: string | undefined); set confirmed_frontier_block(v: Block | undefined); set confirmed_receivable(v: bigint | number | string); set confirmed_representative(v: unknown); set balance(v: bigint | number | string); set block_count(v: number | undefined); set frontier(v: string | undefined); set frontier_block(v: Block | undefined); set open_block(v: string | undefined); set receivable(v: bigint | number | string); set representative(v: unknown); set representative_block(v: string | undefined); set weight(v: bigint | number | string); private constructor(); /** * Releases variable references to allow garbage collection. */ destroy(): Promise<void>; /** * Stringifies public properties into a JSON object so it can be further * stringified by JSON.stringify() */ toJSON(): { address: string; index: number | undefined; publicKey: string; confirmed_balance: string | undefined; confirmed_height: string | undefined; confirmed_frontier: string | undefined; confirmed_receivable: string | undefined; confirmed_representative: string | undefined; balance: string | undefined; block_count: number | undefined; frontier: string | undefined; open_block: string | undefined; receivable: string | undefined; representative: string | undefined; representative_block: string | undefined; weight: string | undefined; }; /** * Instantiates an Account object from its Nano address. * * @param {string} address - Address of the account * @returns {Account} A new Account object */ static load(address: string): Account; /** * Instantiates Account objects from their Nano addresses. * * @param {string[]} addresses - Addresses of the accounts * @returns {Account[]} Array of new Account objects */ static load(addresses: string[]): Account[]; /** * Instantiates an Account object from its public key. It is unable to sign * blocks or messages since it has no private key. * * @param {string | Uint8Array<ArrayBuffer>} publicKey - Public key of the account * @returns {Account} A new Account object */ static load(publicKey: string | Uint8Array<ArrayBuffer>): Account; /** * Instantiates Account objects from their public keys. They are unable to sign * blocks or messages since they have no private key. * * @param {string | Uint8Array<ArrayBuffer>[]} publicKeys - Public keys of the accounts * @returns {Account[]} Array of new Account objects */ static load(publicKeys: string | Uint8Array<ArrayBuffer>[]): Account[]; /** * Instantiates an Account object from its public key. It is unable to sign * blocks or messages since it has no private key. * * @param {KeyPair} keypair - Index and keys of the account * @returns {Account} A new Account object */ static load(keypair: KeyPair): Account; /** * Instantiates Account objects from their public keys. They are unable to sign * blocks or messages since they have no private key. * * @param {KeyPair[]} keypairs - Indexes and keys of the accounts * @returns {Account[]} Array of new Account objects */ static load(keypairs: KeyPair[]): Account[]; /** * Instantiates an Account object from its private key which is used to derive * a public key and then discarded. * * @param {KeyPair} keypair - Index and key of the account * @param {string} type - Indicates a private key * @returns {Promise<Account>} Promise for a new Account object */ static load(keypair: KeyPair, type: 'private'): Promise<Account>; /** * Instantiates Account objects from their private keys which are used to * derive public keys and then discarded. * * @param {KeyPair[]} keypairs - Indexes and keys of the accounts * @param {string} type - Indicates private keys * @returns {Promise<Account[]>} Promise for array of new Account objects */ static load(keypairs: KeyPair[], type: 'private'): Promise<Account[]>; /** * Refreshes the account from its current state on the network. * * A successful response sets the balance, frontier, and representative * properties. * * @param {(Rpc | string | URL)} rpc - RPC node information required to call `account_info` */ refresh(rpc: Rpc | string | URL): Promise<void>; /** * Validates a Nano address with 'nano' and 'xrb' prefixes. * Derived from https://github.com/alecrios/nano-address-validator * * @param {string} address - Nano address to validate * @throws Error if address is undefined, not a string, or an invalid format */ static validate(address: string): asserts address is string; } export {};