libnemo
Version:
Nano cryptocurrency wallet library.
877 lines (856 loc) • 33.8 kB
TypeScript
//! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
//! SPDX-License-Identifier: GPL-3.0-or-later
import { default as TransportBLE } from '@ledgerhq/hw-transport-web-ble'
import { default as TransportUSB } from '@ledgerhq/hw-transport-webusb'
import { default as TransportHID } from '@ledgerhq/hw-transport-webhid'
/**
* 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 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
}
/**
* Represents a mnemonic phrase that identifies a wallet as defined by BIP-39.
*/
export declare class Bip39 {
#private
encoder: TextEncoder
/**
* SHA-256 hash of entropy that is appended to the entropy and subsequently
* used to generate the mnemonic phrase.
*
* @param {Uint8Array<ArrayBuffer>} entropy - Cryptographically strong pseudorandom data of length N bits
* @returns {Promise<bigint>} First N/32 bits of the hash as a bigint
*/
static checksum (entropy: Uint8Array<ArrayBuffer>): Promise<bigint>
/**
* Derives a mnemonic phrase from source of entropy or seed.
*
* The entropy must be between 16-32 bytes (32-64 characters) to stay within
* the limit of 128-256 bits defined in BIP-39. Typically, wallets use the
* maximum entropy allowed.
*
* @param {(ArrayBuffer|Uint8Array<ArrayBuffer>)} entropy - Cryptographically secure random value
* @returns {Promise<Bip39>} Mnemonic phrase created using the BIP-39 wordlist
*/
static fromEntropy (entropy: ArrayBuffer | Uint8Array<ArrayBuffer>): Promise<Bip39>
/**
* Imports and validates an existing mnemonic phrase.
*
* The phrase must be valid according to the BIP-39 specification. Typically,
* wallets use the maximum of 24 words.
*
* @param {string} phrase - String of 12, 15, 18, 21, or 24 words
* @returns {Promise<Bip39>} Mnemonic phrase validated using the BIP-39 wordlist
*/
static fromPhrase (phrase: string): Promise<Bip39>
/**
* Validates a mnemonic phrase meets the BIP-39 specification.
*
* @param {string} mnemonic - Mnemonic phrase to validate
* @returns {Promise<boolean>} True if the mnemonic phrase is valid
*/
static validate (mnemonic: string): Promise<boolean>
private constructor ()
/**
* BIP-39 mnemonic phrase, normlized using Normalization Form Compatibility
* Decomposition (NFKD).
*/
get phrase (): string | undefined
/**
* Erases seed bytes and releases variable references.
*/
destroy (): void
/**
* Converts the mnemonic phrase to a BIP-39 seed.
*
* A passphrase string can be specified. If the passphrase is undefined, null,
* or not a string, the empty string ("") is used instead.
*
* @param {string} [passphrase=''] - Used as the PBKDF2 salt. Default: ""
* @returns {Promise<Uint8Array<ArrayBuffer>>} Promise for seed as bytes
*/
toBip39Seed (passphrase: string): Promise<Uint8Array<ArrayBuffer>>
/**
* Converts the mnemonic phrase to a BIP-39 seed.
*
* A passphrase string can be specified. If the passphrase is undefined, null,
* or not a string, the empty string ("") is used instead.
*
* @param {string} [passphrase=''] - Used as the PBKDF2 salt. Default: ""
* @returns {Promise<string>} Promise for seed as hexadecimal string
*/
toBip39Seed (passphrase: string, format: 'hex'): Promise<string>
/**
* Converts the mnemonic phrase to a BLAKE2b seed.
*
* @returns {Uint8Array<ArrayBuffer>} Seed as bytes
*/
toBlake2bSeed (): Uint8Array<ArrayBuffer>
/**
* Converts the mnemonic phrase to a BLAKE2b seed.
*
* @param {string} format
* @returns {string} Seed as hexadecimal string
*/
toBlake2bSeed (format: 'hex'): string
/**
* https://github.com/bitcoin/bips/blob/master/bip-0039/english.txt
*/
static wordlist: readonly string[]
}
/**
* Implementation derived from blake2b@2.1.4. Copyright 2017 Emil Bay
* <github@tixz.dk> (https://github.com/emilbayes/blake2b). See LICENSES/ISC.txt
*
* Modified to use BigUint64 values, eliminate dependencies, port to TypeScript,
* and embed in web workers.
*
* Original source commit: https://github.com/emilbayes/blake2b/blob/1f63e02e3f226642959506cdaa67c8819ff145cd/index.js
*/
export declare class Blake2b {
#private
/**
* Derives account private keys from a wallet seed using the BLAKE2b hashing
* algorithm.
*
* Separately, account public keys are derived from the private key using the
* Ed25519 key algorithm, and account addresses are derived from the public key
* as described in the Nano documentation.
* https://docs.nano.org/integration-guides/the-basics/
*
* @param {ArrayBuffer} seed - 32-byte secret seed of the wallet
* @param {number} index - 4-byte index of account to derive
* @returns {ArrayBuffer} Private key for the account
*/
static ckd (seed: ArrayBuffer, index: number): Promise<ArrayBuffer>
static get OUTBYTES_MIN (): 1
static get OUTBYTES_MAX (): 64
static get KEYBYTES_MIN (): 1
static get KEYBYTES_MAX (): 64
static get SALTBYTES (): 16
static get PERSONALBYTES (): 16
static get IV (): bigint[]
static get SIGMA (): number[][]
/**
* Creates a BLAKE2b hashing context.
*
* @param {number} length - Output length between 1-64 bytes
* @param {Uint8Array} [key] - (_optional_) Used for keyed hashing (MAC and PRF)
* @param {Uint8Array} [salt] - (_optional_) Used to simplify randomized hashing for digital signatures
* @param {Uint8Array} [personal] - (_optional_) Arbitrary user-specified value
*/
constructor (length: number, key?: Uint8Array<ArrayBuffer>, salt?: Uint8Array<ArrayBuffer>, personal?: Uint8Array<ArrayBuffer>)
update (input: ArrayBuffer | Uint8Array): Blake2b
digest (): Uint8Array<ArrayBuffer>
}
/**
* Represents a block as defined by the Nano cryptocurrency protocol.
*/
export declare class Block {
#private
[key: string]: bigint | string | Account | Function | Uint8Array<ArrayBuffer> | 'send' | 'receive' | 'change' | undefined
subtype?: 'send' | 'receive' | 'change'
account: Account
balance: bigint
previous: Uint8Array<ArrayBuffer>
representative?: Account
link?: Uint8Array<ArrayBuffer>
signature?: string
work?: string
/**
* Initialize a block with the current state of an account so that it can
* subsequently be configured as a change, receive, or send transaction.
*
* All parameters are eventually required in order to initialize the block, but
* but if `account` is an Account class object, its properties can be used for
* the other parameters instead of passing them into the constructor.
*
* @param {(string|Account)} account - Target of the transaction; can include `balance`, `frontier`, `representative`
* @param {(bigint|number|string)} [balance] - Current balance of the target account in raw
* @param {string} [previous] - Current frontier block hash of the target account
* @param {(string|Account)} [representative] - Current representative of the target account
*/
constructor (account: string | Account, balance?: bigint | number | string, previous?: string, representative?: string | Account)
/**
* Calculates the block hash using Blake2b.
*
* @returns {string} Hexadecimal representation of 32-byte hash of block data
*/
get hash (): string
/**
* Converts the block to JSON format as expected by the `process` RPC.
*
* @returns {string} JSON representation of the block
*/
toJSON (): {
[key: string]: string
}
/**
* Set the subtype, link, and target account to configure this as a change
* representative block.
*
* @param {(string|Account)} account - Account to choose as representative, or its address or public key
* @returns {Block} This block with link, representative, and subtype configured
*/
change (representative: string | Account): Block
/**
* Calculates proof-of-work using a pool of Web Workers.
*
* A successful response sets the `work` property.
*/
pow (work?: string): Promise<Block>
/**
* Sends the block to a node for processing on the network.
*
* The block must already be signed (see `sign()` for more information).
* The block must also have a `work` value.
*
* @param {Rpc|string|URL} rpc - RPC node information required to call `process`
* @returns {Promise<string>} Hash of the processed block
*/
process (rpc: Rpc): Promise<string>
/**
* Set the amount of nano that this block will receive from a corresponding
* send block.
*
* @param {(string|Block)} sendBlock - Corresponding send block or its hash
* @param {(bigint|number|string)} amount - Amount to be received from sender
* @param {string} [unit] - Unit of measure for amount (e.g. 'NANO' = 10³⁰ RAW). Default: "RAW"
* @returns {Block} This block with balance, link, and subtype configured
*/
receive (sendBlock: string | Block, amount: bigint | number | string, unit?: string): Block
/**
* Set the amount of nano that this block will send to a recipient account.
*
* @param {(string|Account)} account - Account to target or its address or public key
* @param {(bigint|number|string)} amount - Amount to send to recipient
* @param {string} [unit] - Unit of measure for amount (e.g. 'NANO' = 10³⁰ RAW). Default: "RAW"
* @returns {Block} This block with balance, link, and subtype configured
*/
send (account: string | Account, amount: bigint | number | string, unit?: string): Block
/**
* Sets the `signature` property of the block to a precalculated value.
*
* @param {string} signature - 64-byte hexadecimal signature
* @returns Block with `signature` value set
*/
sign (signature: string): Block
/**
* Signs the block using a private key. If successful, the result is stored in
* the `signature` property of the block.
*
* @param {string} [key] - 32-byte hexadecimal private key to use for signing
* @returns Block with `signature` value set
*/
sign (key: string): Promise<Block>
/**
* Signs the block using a Wallet. If successful, the result is stored in
* the `signature` property of the block. The wallet must be unlocked prior to
* signing.
*
* @param {Wallet} wallet - Wallet to use for signing
* @param {number} index - Account in wallet to use for signing
* @returns Block with `signature` value set
*/
sign (wallet: Wallet, index: number): Promise<Block>
/**
* Signs the block using a Ledger hardware wallet. If that fails, an error is
* thrown with the status code from the device. If successful, the result is
* stored in the `signature` property of the block. The wallet must be unlocked
* prior to signing.
*
* @param {number} index - Account index between 0x0 and 0x7fffffff
* @param {object} [frontier] - JSON of frontier block for offline signing
* @returns Block with `signature` value set
*/
sign (wallet: Wallet, index: number, frontier?: Block): Promise<Block>
/**
* Verifies the signature of the block. If a key is not provided, the public
* key of the block's account will be used if it exists.
*
* @param {string} [key] - Hexadecimal-formatted public key to use for verification
* @returns {boolean} True if block was signed by the matching private key
*/
verify (key?: string): Promise<boolean>
}
export type BlockInfo = {
blocks: {
[hash: string]: {
[p: string]: string
} & {
contents: {
[p: string]: string
}
}
}
}
export type Data = boolean | number | number[] | string | string[] | Account | ArrayBuffer | CryptoKey | { [key: string]: Data }
export type NamedData<T extends Data = Data> = {
[key: string]: T
}
export type KeyPair = {
index?: number
privateKey?: string | Uint8Array<ArrayBuffer>
publicKey?: string | Uint8Array<ArrayBuffer>
}
export type LedgerStatus = 'DISCONNECTED' | 'BUSY' | 'LOCKED' | 'CONNECTED'
interface LedgerResponse {
status: string
}
interface LedgerVersionResponse extends LedgerResponse {
name: string | null,
version: string | null
}
interface LedgerAccountResponse extends LedgerResponse {
publicKey: string | null,
address: string | null
}
interface LedgerSignResponse extends LedgerResponse {
signature: string | null,
hash?: string
}
/**
* Represents a basic address book of Nano accounts. Multiple addresses can be
* saved under one nickname.
*/
export declare class Rolodex {
static get DB_NAME (): 'Rolodex'
/**
* Adds an address to the rolodex under a specific nickname.
*
* If the name exists, add the address as a new association to that name. If
* the account exists under a different name, update the name. If no matches
* are found at all, add a new entry.
*
* @param {string} name - Contact alias for the address
* @param {string} address - Nano account address
* @returns {Promise<boolean>} Promise for true if name and address are added to the rolodex, else false
*/
static add (name: string, address: string): Promise<boolean>
/**
* Removes a Nano address from its related contact in the rolodex.
*
* @param {string} address - Nano account address
* @returns {Promise<boolean>} Promise for true if address successfully removed, else false
*/
static deleteAddress (address: string): Promise<boolean>
/**
* Removes a contact and its related Nano addresses from the rolodex.
*
* @param {string} name - Contact name to delete
* @returns {Promise<boolean>} Promise for true if name and related addresses successfully removed, else false
*/
static deleteName (name: string): Promise<boolean>
/**
* Gets all Nano account addresses associated with a name from the rolodex.
*
* @param {string} name - Alias to look up
* @returns {Promise<string[]>} Promise for a list of Nano addresses associated with the name
*/
static getAddresses (name: string): Promise<string[]>
/**
* Gets all names stored in the rolodex.
*
* @returns {Promise<string[]>} Promise for a list of all names stored in the rolodex
*/
static getAllNames (): Promise<string[]>
/**
* Gets the name associated with a specific Nano address from the rolodex.
*
* @param {string} address - Nano account address
* @returns {Promise<string|null>} Promise for the name associated with the address, or null if not found
*/
static getName (address: string): Promise<string | null>
/**
* Verifies whether the public key of any Nano address saved under a specific
* name in the rolodex was used to sign a specific set of data.
*
* @param {string} name - Alias to look up
* @param {string} signature - Signature to use for verification
* @param {...string} data - Signed data to verify
* @returns {Promise<boolean>} True if the signature was used to sign the data, else false
*/
static verify (name: string, signature: string, ...data: string[]): Promise<boolean>
}
/**
* Represents a Nano network node. It primarily consists of a URL which will
* accept RPC calls, and an optional API key header construction can be passed if
* required by the node. Once instantiated, the Rpc object can be used to call
* any action supported by the Nano protocol. The URL protocol must be HTTPS; any
* other value will be changed automatically.
*/
export declare class Rpc {
#private
constructor (url: string | URL, apiKeyName?: string)
/**
* Sends a nano RPC call to a node endpoint.
*
* @param {string} action - Nano protocol RPC call to execute
* @param {object} [data] - JSON to send to the node as defined by the action
* @returns {Promise<any>} JSON-formatted RPC results from the node
*/
call (action: string, data?: {
[key: string]: unknown
}): Promise<any>
}
type SweepResult = {
status: "success" | "error"
address: string
message: string
}
/**
* Converts a decimal amount of nano from one unit divider to another.
*
* @param {(bigint|number|string)} amount - Decimal amount to convert
* @param {string} inputUnit - Current denomination
* @param {string} outputUnit - Desired denomination
* @param {string} [format] - Data type of output
*/
export declare function convert (amount: bigint | number | string, inputUnit: string, outputUnit: string): string
export declare function convert (amount: bigint | number | string, inputUnit: string, outputUnit: string, format: 'bigint'): bigint
export declare function convert (amount: bigint | number | string, inputUnit: string, outputUnit: string, format: 'number'): number
export declare function convert (amount: bigint | number | string, inputUnit: string, outputUnit: string, format: 'string'): string
declare function hash (data: string | string[], encoding?: 'hex'): Uint8Array<ArrayBuffer>
/**
* Signs arbitrary strings with a private key using the Ed25519 signature scheme.
* The strings are first hashed to a 32-byte value using BLAKE2b.
*
* @param {string | Uint8Array<ArrayBuffer>} key - Hexadecimal-formatted private key to use for signing
* @param {...string} input - Data to be signed
* @returns {Promise<string>} Hexadecimal-formatted signature
*/
export declare function sign (key: string | Uint8Array<ArrayBuffer>, ...input: string[]): Promise<string>
/**
* Collects the funds from a specified range of accounts in a wallet and sends
* them all to a single recipient address. Hardware wallets are unsupported.
*
* @param {Rpc|string|URL} rpc - RPC node information required to refresh accounts, calculate PoW, and process blocks
* @param {(Wallet)} wallet - Wallet from which to sweep funds
* @param {string} recipient - Destination address for all swept funds
* @param {number} [from=0] - Starting account index to sweep
* @param {number} [to=from] - Ending account index to sweep
* @returns An array of results including both successes and failures
*/
export declare function sweep (rpc: Rpc | string | URL, wallet: Wallet, recipient: string, from?: number, to?: number): Promise<SweepResult[]>
/**
* Verifies the signature of arbitrary strings using a public key.
*
* @param {string | Uint8Array<ArrayBuffer>} key - Hexadecimal-formatted public key to use for verification
* @param {string} signature - Hexadcimal-formatted signature
* @param {...string} input - Data to be verified
* @returns {Promise<boolean>} True if the data was signed by the public key's matching private key
*/
export declare function verify (key: string | Uint8Array<ArrayBuffer>, signature: string, ...input: string[]): Promise<boolean>
export declare const Tools: {
convert: typeof convert
hash: typeof hash
sign: typeof sign
sweep: typeof sweep
verify: typeof verify
}
export type WalletType = 'BIP-44' | 'BLAKE2b' | 'Ledger'
/**
* Represents a wallet containing numerous Nano accounts derived from a single
* source, the form of which can vary based on the type of wallet. Currently,
* three types of wallets are supported: BIP-44, BLAKE2b, and Ledger.
*/
export declare class Wallet {
#private
static get DB_NAME (): 'Wallet'
/**
* Retrieves all wallets with encrypted secrets and unencrypted metadata from
* the database.
*
* @returns id, type, iv, salt, encrypted
*/
static backup (): Promise<NamedData[]>
/**
* Creates a new hardware wallet manager.
*
* @param {string} type - Wallet manufacturer
* @returns {Wallet} A newly instantiated Wallet
*/
static create (type: 'Ledger'): Promise<Wallet>
/**
* Creates a new HD wallet by using an entropy value generated using a
* cryptographically strong pseudorandom number generator.
*
* @param {string} type - Algorithm used to generate wallet and child accounts
* @param {string} password - Encrypts the wallet to lock and unlock it
* @param {string} [salt=''] - Used when generating the final seed
* @returns {Wallet} A newly instantiated Wallet
*/
static create (type: 'BIP-44' | 'BLAKE2b', password: string, mnemonicSalt?: string): Promise<Wallet>
/**
* Imports an existing HD wallet by using an entropy value generated using a
* cryptographically strong pseudorandom number generator.NamedD
*
* @param {string} type - Algorithm used to generate wallet and child accounts
* @param {string} password - Encrypts the wallet to lock and unlock it. Discard as soon as possible after loading the wallet.
* @param {string} seed - Used to derive child accounts
* @returns Wallet in a locked state
*/
static load (type: 'BIP-44' | 'BLAKE2b', password: string, seed: string): Promise<Wallet>
/**
* Imports an existing HD wallet by using an entropy value generated using a
* cryptographically strong pseudorandom number generator.
*
* @param {string} type - Algorithm used to generate wallet and child accounts
* @param {string} password - Encrypts the wallet to lock and unlock it. Discard as soon as possible after loading the wallet.
* @param {string} mnemonicPhrase - Used to derive the wallet seed
* @param {string} [mnemonicSalt] - Used to alter the seed derived from the mnemonic phrase
* @returns Wallet in a locked state
*/
static load (type: 'BIP-44' | 'BLAKE2b', password: string, mnemonicPhrase: string, mnemonicSalt?: string): Promise<Wallet>
/**
* Instantiates a Wallet from an existing record in the database using its UUID.
*
* @param {string} id - Generated when the wallet was created or imported
* @returns {Promise<Wallet>} Restored locked Wallet
*/
static restore (id: string): Promise<Wallet>
/**
* Instantiates Wallet objects from records in the database.
*
* @param {string} id - Generated when the wallet was created or imported
* @returns {Promise<Wallet[]>} Restored locked Wallets
*/
static restore (): Promise<Wallet[]>
constructor (type: WalletType, id?: string)
/**
* @returns UUID of the wallet.
*/
get id (): string
/**
* @returns True if the wallet is locked, else false
*/
get isLocked (): boolean
/**
* Algorithm or device used to create wallet and derive accounts.
*/
get type (): WalletType
/**
* Set when calling `create()`. Self-destructs after the first read.
* @returns Mnemonic phrase used to derive the wallet seed.
*/
get mnemonic (): string | undefined
/**
* Set when calling `create()`. Self-destructs after the first read.
* @returns Seed used to derive accounts.
*/
get seed (): string | undefined
/**
* Retrieves an account from a wallet using its child key derivation function.
* Defaults to the first account at index 0.
*
* The returned object will have keys corresponding with the requested range
* of account indexes. The value of each key will be the Account derived for
* that index in the wallet.
*
* ```
* const account = await wallet.account(1)
* // outputs the second account of the wallet
* console.log(account)
* // { address: <...>, publicKey: <...>, index: 1, <etc...> }
* ```
*
* @param {number} index - Wallet index of account. Default: 0
* @returns Promise for the Account at the specified index
*/
account (index?: number): Promise<Account>
/**
* Retrieves accounts from a wallet using its child key derivation function.
* Defaults to the first account at index 0.
*
* The returned object will have keys corresponding with the requested range
* of account indexes. The value of each key will be the Account derived for
* that index in the wallet.
*
* ```
* const accounts = await wallet.accounts(0, 1))
* // outputs the first and second account of the wallet
* console.log(accounts)
* // {
* // 0: {
* // address: <...>,
* // publicKey: <...>,
* // index: 0,
* // <etc...>
* // },
* // 1: {
* // address: <...>,
* // publicKey: <...>,
* // index: 1,
* // <etc...>
* // }
* // }
* // individual accounts can be referenced using array index notation
* console.log(accounts[1])
* // { address: <...>, publicKey: <...>, index: 1, <etc...> }
* ```
*
* If `from` is greater than `to`, their values will be swapped.
* @param {number} [from=0] - Start index of accounts. Default: 0
* @param {number} [to=from] - End index of accounts. Default: `from`
* @returns {Promise<Map<number, Account>>} Promise for a list of Accounts at the specified indexes
*/
accounts (from?: number, to?: number): Promise<Map<number, Account>>
/**
* Configures Ledger connection settings.
* @param {string} connection - Transport interface to use
*/
config (settings: {
connection: 'hid' | 'ble' | 'usb'
}): Promise<void>
/**
* Configures vault worker settings.
* @param {number} timeout - Measured in seconds of inactivity before wallet automatically locks
*/
config (settings: {
timeout: number
}): Promise<void>
/**
* Removes encrypted secrets in storage, releases variable references to
* allow garbage collection, and terminates vault worker.
*/
destroy (): Promise<void>
/**
* For BIP-44 and BLAKE2b wallets, clears the seed and mnemonic from the vault.
*
* For Ledger hardware wallets, revokes permission granted by the user to
* access the Ledger device. The 'quit app' ADPU command is uncooperative, so
* this is currently the only way to ensure the connection is severed.
* `setTimeout` is used to expire any lingering transient user activation.
*/
lock (): void
/**
* Refreshes wallet account balances, frontiers, and representatives from the
* current state on the network.
*
* A successful response will set these properties on each account.
*
* @param {(Rpc|string|URL)} rpc - RPC node information required to refresh accounts, calculate PoW, and process blocks
* @returns {Promise<Map<number, Account>>} Promise for accounts with updated balances, frontiers, and representatives
*/
refresh (rpc: Rpc | string | URL, from?: number, to?: number): Promise<Map<number, Account>>
/**
* Signs arbitrary strings using the private key of the account at the wallet
* index specified and returns a detached signature as a hexadecimal string.
* For compatibility with other Nano tools, the data is first hashed to a
* 32-byte value using BLAKE2b. The wallet must be unlocked prior to signing.
*
* @param {number} index - Account to use for signing
* @param {(string|string[])} data - Arbitrary data to be hashed and signed
*/
sign (index: number, data: string | string[]): Promise<string>
/**
* Signs a block using the private key of the account at the wallet index
* specified. The signature is appended to the signature field of the block
* before being returned. The wallet must be unlocked prior to signing.
*
* @param {number} index - Account to use for signing
* @param {Block} block - Block data to be hashed and signed
*/
sign (index: number, block: Block): Promise<void>
/**
* Signs a block using a Ledger hardware wallet at the wallet index specified.
* The signature is appended to the signature field of the block before being
* returned. The wallet must be unlocked prior to signing.
*
* @param {number} index - Account to use for signing
* @param {Block} block - Block data to be hashed and signed
* @param {Block} [frontier] - Previous block data to be cached by Ledger wallet
*/
sign (index: number, block: Block, frontier?: Block): Promise<void>
/**
* Attempts to connect to the Ledger device.
*/
unlock (): Promise<void>
/**
* Unlocks the wallet using the same password as used prior to lock it.
*
* @param {string} password Used previously to lock the wallet
*/
unlock (password: string): Promise<void>
/**
* Fetches the lowest-indexed unopened account from a wallet in sequential
* order. An account is unopened if it has no frontier block.
*
* @param {Rpc|string|URL} rpc - RPC node information required to refresh accounts, calculate PoW, and process blocks
* @param {number} batchSize - Number of accounts to fetch and check per RPC callout
* @param {number} from - Account index from which to start the search
* @returns {Promise<Account>} The lowest-indexed unopened account belonging to the wallet
*/
unopened (rpc: Rpc, batchSize?: number, from?: number): Promise<Account>
/**
* Updates the password used to encrypt the wallet. The wallet must be unlocked
* prior to update.
*
* @param {string} password Used to re-encrypt the wallet
*/
update (password: string): Promise<void>
/**
* Checks whether a given seed matches the wallet seed. The wallet must be
* unlocked prior to verification.
*
* @param {string} seed - Hexadecimal seed to be matched against the wallet data
* @returns True if input matches wallet seed
*/
verify (seed: string): Promise<boolean>
/**
* Checks whether a given mnemonic phrase matches the wallet mnemonic. If a
* personal salt was used when generating the mnemonic, it cannot be verified.
* The wallet must be unlocked prior to verification.
*
* @param {string} mnemonic - Phrase to be matched against the wallet data
* @returns True if input matches wallet mnemonic
*/
verify (mnemonic: string): Promise<boolean>
}