From: Chris Duncan Date: Mon, 7 Jul 2025 13:26:01 +0000 (-0700) Subject: Alphabetize function order. X-Git-Tag: v0.10.5~96 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=d52e1dbd148725b7f9d9a6adb5b06e073075118f;p=libnemo.git Alphabetize function order. --- diff --git a/src/lib/wallets/ledger-wallet.ts b/src/lib/wallets/ledger-wallet.ts index f1c12b5..94f02e6 100644 --- a/src/lib/wallets/ledger-wallet.ts +++ b/src/lib/wallets/ledger-wallet.ts @@ -279,43 +279,6 @@ export class LedgerWallet extends Wallet { return account } - /** - * Cache frontier block in device memory. - * - * @param {number} index - Account number - * @param {any} block - Block data to cache - * @returns Status of command - */ - async cacheBlock (index: number = 0, block: SendBlock | ReceiveBlock | ChangeBlock): Promise { - if (typeof index !== 'number' || index < 0 || index >= HARDENED_OFFSET) { - throw new TypeError('Invalid account index') - } - if (!(block instanceof SendBlock) && !(block instanceof ReceiveBlock) && !(block instanceof ChangeBlock)) { - throw new TypeError('Invalid block format') - } - if (!block.signature) { - throw new ReferenceError('Cannot cache unsigned block') - } - - const purpose = dec.toBytes(BIP44_PURPOSE + HARDENED_OFFSET, 4) - const coin = dec.toBytes(BIP44_COIN_NANO + HARDENED_OFFSET, 4) - const account = dec.toBytes(index + HARDENED_OFFSET, 4) - const previous = hex.toBytes(block.previous) - const link = hex.toBytes(block.link) - const representative = hex.toBytes(block.representative.publicKey) - const balance = hex.toBytes(BigInt(block.balance).toString(16), 16) - const signature = hex.toBytes(block.signature) - const data = new Uint8Array([LEDGER_ADPU_CODES.bip32DerivationLevel, ...purpose, ...coin, ...account, ...previous, ...link, ...representative, ...balance, ...signature]) - - const transport = await this.DynamicTransport.create(this.openTimeout, this.listenTimeout) - const response = await transport.send(LEDGER_ADPU_CODES.class, LEDGER_ADPU_CODES.cacheBlock, LEDGER_ADPU_CODES.paramUnused, LEDGER_ADPU_CODES.paramUnused, data as Buffer) - .then(res => bytes.toDec(res)) - .catch(err => err.statusCode) as number - await transport.close() - - return { status: LEDGER_STATUS_CODES[response] } - } - /** * Sign a block with the Ledger device. * @@ -415,7 +378,7 @@ export class LedgerWallet extends Wallet { } input = res.contents } - return this.cacheBlock(index, input) + return this.#cacheBlock(index, input) } /** @@ -455,6 +418,43 @@ export class LedgerWallet extends Wallet { } } + /** + * Cache frontier block in device memory. + * + * @param {number} index - Account number + * @param {any} block - Block data to cache + * @returns Status of command + */ + async #cacheBlock (index: number = 0, block: SendBlock | ReceiveBlock | ChangeBlock): Promise { + if (typeof index !== 'number' || index < 0 || index >= HARDENED_OFFSET) { + throw new TypeError('Invalid account index') + } + if (!(block instanceof SendBlock) && !(block instanceof ReceiveBlock) && !(block instanceof ChangeBlock)) { + throw new TypeError('Invalid block format') + } + if (!block.signature) { + throw new ReferenceError('Cannot cache unsigned block') + } + + const purpose = dec.toBytes(BIP44_PURPOSE + HARDENED_OFFSET, 4) + const coin = dec.toBytes(BIP44_COIN_NANO + HARDENED_OFFSET, 4) + const account = dec.toBytes(index + HARDENED_OFFSET, 4) + const previous = hex.toBytes(block.previous) + const link = hex.toBytes(block.link) + const representative = hex.toBytes(block.representative.publicKey) + const balance = hex.toBytes(BigInt(block.balance).toString(16), 16) + const signature = hex.toBytes(block.signature) + const data = new Uint8Array([LEDGER_ADPU_CODES.bip32DerivationLevel, ...purpose, ...coin, ...account, ...previous, ...link, ...representative, ...balance, ...signature]) + + const transport = await this.DynamicTransport.create(this.openTimeout, this.listenTimeout) + const response = await transport.send(LEDGER_ADPU_CODES.class, LEDGER_ADPU_CODES.cacheBlock, LEDGER_ADPU_CODES.paramUnused, LEDGER_ADPU_CODES.paramUnused, data as Buffer) + .then(res => bytes.toDec(res)) + .catch(err => err.statusCode) as number + await transport.close() + + return { status: LEDGER_STATUS_CODES[response] } + } + /** * Gets the public key for an account from the Ledger device. *