]> git.codecow.com Git - libnemo.git/commitdiff
Top-level sign is queued, so remove it from internals.
authorChris Duncan <chris@codecow.com>
Mon, 18 May 2026 17:12:00 +0000 (10:12 -0700)
committerChris Duncan <chris@codecow.com>
Mon, 18 May 2026 17:12:00 +0000 (10:12 -0700)
src/lib/ledger/sign.ts

index e2263e54dc6f12f11dd9cad5b7a4509878e5ae80..0bf5de70f94b33e237efdbcb5d5b3b04e5c9fe9d 100644 (file)
@@ -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<string> {
        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<string> {
        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<ArrayBuffer>): Promise<string> {
        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 })
        }