]> git.codecow.com Git - libnemo.git/commitdiff
Update type definitions.
authorChris Duncan <chris@zoso.dev>
Wed, 20 Aug 2025 21:03:38 +0000 (14:03 -0700)
committerChris Duncan <chris@zoso.dev>
Wed, 20 Aug 2025 21:03:38 +0000 (14:03 -0700)
src/types.d.ts

index 012487946c9d57b25dc2e689a523681494ea53b5..cb070a22de93d7cdd7463fdadd2cd48325c6875f 100644 (file)
@@ -18,12 +18,14 @@ export declare class Account {
        get publicKey (): string
        get confirmed_balance (): bigint | undefined
        get confirmed_block_height (): number | undefined
-       get confirmed_frontier_block (): string | 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_height (): number | undefined
-       get frontier_block (): string | undefined
+       get frontier (): string | undefined
+       get frontier_block (): Block | undefined
        get open_block (): string | undefined
        get receivable (): bigint | undefined
        get representative (): Account | undefined
@@ -31,12 +33,14 @@ export declare class Account {
        get weight (): bigint | undefined
        set confirmed_balance (v: bigint | number | string)
        set confirmed_block_height (v: number | undefined)
-       set confirmed_frontier_block (v: string | 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_height (v: number | undefined)
-       set frontier_block (v: string | 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)
@@ -122,7 +126,7 @@ export declare class Account {
        */
        refresh (rpc: Rpc | string | URL): Promise<void>
        /**
-       * Validates a Nano address with 'nano' and 'xrb' prefixes
+       * 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
@@ -249,6 +253,7 @@ export declare class Blake2b {
 */
 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
@@ -344,17 +349,6 @@ export declare class Block {
        */
        sign (key: string): 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 (index: number, frontier?: Block): 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.
@@ -365,6 +359,17 @@ export declare class Block {
        */
        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.
        *
@@ -405,7 +410,7 @@ export type KeyPair = {
 * saved under one nickname.
 */
 export declare class Rolodex {
-       static #private
+       #private
        /**
        * Adds an address to the rolodex under a specific nickname.
        *
@@ -514,13 +519,13 @@ export declare function sign (key: Key, ...input: string[]): Promise<string>
 * 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|Ledger)} wallet - Wallet from which to sweep funds
+* @param {(Wallet)} wallet - Wallet from which to sweep funds
 * @param {string} recipient - Destination address for all swept funds
-* @param {number} from - Starting account index to sweep
-* @param {number} to - Ending account index to sweep
+* @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 | Ledger, recipient: string, from?: number, to?: number): Promise<SweepResult[]>
+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.
 *
@@ -555,6 +560,13 @@ export declare class Wallet {
        */
        static backup (): Promise<NamedData[]>
        /**
+       * Creates a new Ledger wallet manager.
+       *
+       * @param {string} type - Encrypts the wallet to lock and unlock it
+       * @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.
        *
@@ -562,7 +574,7 @@ export declare class Wallet {
        * @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>
+       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
@@ -604,7 +616,7 @@ export declare class Wallet {
        */
        get id (): string
        /**
-       * Method used to create wallet and derive accounts.
+       * Algorithm or device used to create wallet and derive accounts.
        */
        get type (): WalletType
        /**
@@ -668,8 +680,8 @@ export declare class Wallet {
        * ```
        *
        * If `from` is greater than `to`, their values will be swapped.
-       * @param {number} from - Start index of accounts. Default: 0
-       * @param {number} to - End index of accounts. Default: `from`
+       * @param {number} [from=0] - Start index of accounts. Default: 0
+       * @param {number} [to=from] - End index of accounts. Default: `from`
        * @returns {AccountList} Promise for a list of Accounts at the specified indexes
        */
        accounts (from?: number, to?: number): Promise<AccountList>
@@ -679,7 +691,12 @@ export declare class Wallet {
        */
        destroy (): Promise<void>
        /**
-       * Clears the seed and mnemonic from the vault.
+       * 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
        /**
@@ -688,8 +705,8 @@ export declare class Wallet {
        *
        * 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<Account[]>} Accounts with updated balances, frontiers, and representatives
+       * @param {(Rpc|string|URL)} rpc - RPC node information required to refresh accounts, calculate PoW, and process blocks
+       * @returns {Promise<AccountList>} Promise for accounts with updated balances, frontiers, and representatives
        */
        refresh (rpc: Rpc | string | URL, from?: number, to?: number): Promise<AccountList>
        /**
@@ -698,10 +715,24 @@ export declare class Wallet {
        * 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} 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