From: Chris Duncan Date: Mon, 18 May 2026 17:12:00 +0000 (-0700) Subject: Top-level sign is queued, so remove it from internals. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=3c624d6d6b95e7810dfd97b13bd90dbaa45a7a73;p=libnemo.git Top-level sign is queued, so remove it from internals. --- diff --git a/src/lib/ledger/sign.ts b/src/lib/ledger/sign.ts index e2263e5..0bf5de7 100644 --- a/src/lib/ledger/sign.ts +++ b/src/lib/ledger/sign.ts @@ -7,7 +7,6 @@ import { Block } from '../block' import { HARDENED_OFFSET } from '../constants' import { bytes, dec, hex, utf8 } from '../convert' import { _cache } from './cache' -import { queue } from './queue' export async function _sign (transport: LedgerTransport, index: number, data: string | Block, frontier?: Block): Promise { try { @@ -36,13 +35,6 @@ export async function _sign (transport: LedgerTransport, index: number, data: st } } -/** - * Sign a block with the Ledger device. - * - * @param {number} index - Account number - * @param {object} block - Block data to sign - * @returns {Promise} Status, signature, and block hash - */ async function signBlock (transport: LedgerTransport, index: number, block: Block): Promise { if (block.signature !== undefined) { throw new TypeError('Block signature already exists', { cause: block.signature }) @@ -58,31 +50,23 @@ async function signBlock (transport: LedgerTransport, index: number, block: Bloc const previous = block.previous const link = block.link const representative = hex.toBytes(block.representative.publicKey, 32) - const balance = hex.toBytes(BigInt(block.balance).toString(16), 16) + const balance = hex.toBytes(block.balance.toString(16), 16) const data = new Uint8Array([...DERIVATION_PATH, ...account, ...previous, ...link, ...representative, ...balance]) - const res = await queue(async () => req(transport, APDU_CODES.signBlock, data as Buffer)) + const res = await req(transport, APDU_CODES.signBlock, data as Buffer) if (res.hash !== block.hash) { throw new Error('Hash from Ledger does not match hash from block', { cause: `${res.hash} | ${block.hash}` }) } return res.signature } -/** - * Sign a nonce with the Ledger device. - * - * @param {number} index - Account number - * @param {Uint8Array} nonce - 128-bit value to sign - * @returns {Promise} Status and signature - */ async function signNonce (transport: LedgerTransport, index: number, nonce: Uint8Array): Promise { if (nonce.byteLength !== 16) { throw new RangeError('Nonce must be 16-byte string') } - const derivationAccount = dec.toBytes(index + HARDENED_OFFSET, 4) const data = new Uint8Array([...DERIVATION_PATH, ...derivationAccount, ...nonce]) - const res = await queue(async () => req(transport, APDU_CODES.signNonce, data as Buffer)) + const res = await req(transport, APDU_CODES.signNonce, data as Buffer) return res.signature } @@ -94,10 +78,8 @@ async function req (transport: LedgerTransport, command: typeof APDU_CODES.signB .send(APDU_CODES.class, command, APDU_CODES.paramUnused, APDU_CODES.paramUnused, data) .catch((err: any) => dec.toBytes(err.statusCode)) .finally(async () => await t.close()) as Uint8Array - const statusCode = bytes.toDec(response.slice(-2)) as number const status = STATUS_CODES[statusCode] ?? 'UNKNOWN_ERROR' - if (status !== 'OK') { throw new Error('Signing with ledger failed', { cause: status }) }