From c8069e2ea4a26eddb985698a8bb2fe4631157604 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Wed, 6 Aug 2025 12:37:45 -0700 Subject: [PATCH] Update wallet type definitions. --- src/types.d.ts | 68 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 13 deletions(-) diff --git a/src/types.d.ts b/src/types.d.ts index 6d16628..4041d41 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -668,7 +668,7 @@ export declare class Wallet { /** * Retrieves an existing wallet from the database using its UUID. * - * @param {string} id - Entered by user when the wallet was initially created + * @param {string} id - Generated when the wallet was created or imported * @returns {Wallet} Restored locked Wallet */ static restore (id: string): Promise @@ -678,7 +678,7 @@ export declare class Wallet { get mnemonic (): string | undefined /** Set when calling `create()` and self-destructs after the first read. */ get seed (): string | undefined - constructor (type: WalletType) + constructor (type: WalletType, id?: string) /** * Retrieves an account from a wallet using its child key derivation function. * Defaults to the first account at index 0. @@ -751,7 +751,17 @@ export declare class Wallet { * @param {(Block)} block - Block data to be hashed and signed * @returns {Promise} Hexadecimal-formatted 64-byte signature */ - sign (index: number, block: Block): Promise + sign (index: number, block: Block): Promise> + /** + * 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 + * @returns {Promise} Hexadecimal-formatted 64-byte signature + */ + sign (index: number, block: Block, format: 'hex'): Promise /** * Unlocks the wallet using the same password as used prior to lock it. * @@ -840,6 +850,37 @@ export declare class Ledger extends Wallet { get status (): DeviceStatus private constructor () /** + * Gets the public key for an account from the Ledger device. + * + * @param {number[]} indexes - Indexes of the accounts + * @returns {Promise} + */ + account (index: number): Promise + /** + * 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. + * + * ``` + * console.log(await wallet.accounts(5)) + * // outputs sixth account of the wallet + * // { + * // 5: { + * // privateKey: <...>, + * // index: 5 + * // } + * // } + * ``` + * + * @param {number} from - Start index of secret keys. Default: 0 + * @param {number} to - End index of secret keys. Default: `from` + * @returns {AccountList} Object with keys of account indexes and values of the corresponding Accounts + */ + accounts (from?: number, to?: number): Promise + /** * Check if the Nano app is currently open and set device status accordingly. * * @returns Device status as follows: @@ -873,10 +914,18 @@ export declare class Ledger extends Wallet { * Sign a block with the Ledger device. * * @param {number} index - Account number - * @param {Block} block - Block data to sign + * @param {object} block - Block data to sign * @returns {Promise} Signature */ - sign (index: number, block: Block, frontier?: Block): Promise + sign (index: number, block: Block): Promise> + /** + * Sign a block with the Ledger device. + * + * @param {number} index - Account number + * @param {object} block - Block data to sign + * @returns {Promise} Signature + */ + sign (index: number, block: Block, format?: 'hex', frontier?: Block): Promise /** * Attempts to connect to the Ledger device. * @@ -890,7 +939,7 @@ export declare class Ledger extends Wallet { * Update cache from raw block data. Suitable for offline use. * * @param {number} index - Account number - * @param {Block} block - JSON-formatted block data + * @param {object} block - JSON-formatted block data */ updateCache (index: number, block: Block): Promise /** @@ -928,13 +977,6 @@ export declare class Ledger extends Wallet { * @returns Status, process name, and version */ version (): Promise - /** - * Gets the public key for an account from the Ledger device. - * - * @param {number[]} indexes - Indexes of the accounts - * @returns {Promise} - */ - ckd (indexes: number[]): Promise } /** -- 2.47.3