]> git.codecow.com Git - libnemo.git/commitdiff
Replace more toString calls and fix blake test.
authorChris Duncan <chris@codecow.com>
Fri, 3 Jul 2026 07:44:59 +0000 (00:44 -0700)
committerChris Duncan <chris@codecow.com>
Fri, 3 Jul 2026 07:44:59 +0000 (00:44 -0700)
src/lib/crypto/bip44.ts
src/lib/ledger/cache.ts
src/lib/ledger/sign.ts
test/test.blake2b.mjs

index 7431ebbe2cab1aa3b58f0e52c0a822e23e844910..e8313690f3d45b74b61dfdf3e8d87b5e2fff407b 100644 (file)
@@ -2,6 +2,7 @@
 //! SPDX-License-Identifier: GPL-3.0-or-later
 
 import { Point, getPublicKey as secp256k1_getPublicKey } from '@noble/secp256k1'
+import { dec } from '../convert'
 
 type Curve = 'Bitcoin seed' | 'ed25519 seed'
 type ExtendedKey = {
@@ -41,25 +42,25 @@ export function Bip44 (curve: unknown, seed: unknown, coin: unknown, account: un
                throw new RangeError(`Invalid coin ${coin}`)
        }
        if (!Number.isSafeInteger(coin) || coin < 0 || coin > 0x7fffffff) {
-               throw new RangeError(`Invalid coin 0x${coin.toString(16)}`)
+               throw new RangeError(`Invalid coin 0x${dec.toHex(coin)}`)
        }
        if (typeof account !== 'number') {
                throw new RangeError(`Invalid account index ${account}`)
        }
        if (!Number.isSafeInteger(account) || account < 0 || account > 0x7fffffff) {
-               throw new RangeError(`Invalid account index 0x${account.toString(16)}`)
+               throw new RangeError(`Invalid account index 0x${dec.toHex(account)}`)
        }
        if (change !== undefined && typeof change !== 'number') {
                throw new RangeError(`Invalid change index ${change}`)
        }
        if (change !== undefined && (!Number.isSafeInteger(change) || change < 0 || change > 1)) {
-               throw new RangeError(`Invalid change index 0x${account.toString(16)}`)
+               throw new RangeError(`Invalid change index 0x${dec.toHex(account)}`)
        }
        if (address !== undefined && typeof address !== 'number') {
                throw new RangeError(`Invalid address index ${address}`)
        }
        if (address !== undefined && (!Number.isSafeInteger(address) || address < 0 || address > 0x7fffffff)) {
-               throw new RangeError(`Invalid address index 0x${account.toString(16)}`)
+               throw new RangeError(`Invalid address index 0x${dec.toHex(account)}`)
        }
        return ckd(curve, seed, coin, account, change, address)
 }
index 255f90918fea9998000696722098e3908e6bf7ef..de99122b7c604e359d3ed68b783884e4d33576c8 100644 (file)
@@ -2,7 +2,7 @@
 //! SPDX-License-Identifier: GPL-3.0-or-later
 
 import { TransportStatusError } from '@ledgerhq/errors'
-import { APDU_CODES, LedgerResponse, LedgerTransport, LISTEN_TIMEOUT, OPEN_TIMEOUT, STATUS_CODES } from '.'
+import { APDU_CODES, LISTEN_TIMEOUT, LedgerResponse, LedgerTransport, OPEN_TIMEOUT, STATUS_CODES } from '.'
 import { Account } from '../account'
 import { Block } from '../block'
 import { BIP44_COIN_NANO, BIP44_PURPOSE, HARDENED_OFFSET } from '../constants'
@@ -29,7 +29,7 @@ export async function _cache (transport: LedgerTransport, index: number = 0, blo
                const previous = block.previous
                const link = block.link
                const representative = hex.toBytes(block.representative.publicKey, 32)
-               const balance = hex.toBytes(block.balance.toString(16), 16)
+               const balance = dec.toBytes(block.balance, 16)
                const signature = hex.toBytes(block.signature, 64)
                const data = new Uint8Array([APDU_CODES.bip32DerivationLevel, ...purpose, ...coin, ...account, ...previous, ...link, ...representative, ...balance, ...signature])
 
index ccd4f3415b94b4544685eab97777cfa7791401c6..f73f616e9900d48d3591559bfb5afa489eb62a5c 100644 (file)
@@ -50,7 +50,7 @@ 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(block.balance.toString(16), 16)
+       const balance = dec.toBytes(block.balance, 16)
        const data = new Uint8Array([...DERIVATION_PATH, ...account, ...previous, ...link, ...representative, ...balance])
 
        const res = await req(transport, APDU_CODES.signBlock, data as Buffer)
index 87ab22ff47df50bcd6190d1b4a5c43535b8e5089..2c3c9c584f0773b54014f3de2d92595fbe34d37e 100644 (file)
@@ -33,7 +33,7 @@ await Promise.all([
                                try {\r
                                        /** @type {string} */\r
                                        const hex = new Blake2b(64, key).update(input).digest('hex')\r
-                                       assert.equal(hex, test.out)\r
+                                       assert.equal(hex, test.out.toUpperCase())\r
                                } catch (err) {\r
                                        console.error(`blake2b reference test vector ${i} failed`, { cause: err })\r
                                }\r
@@ -85,7 +85,7 @@ await Promise.all([
                                try {\r
                                        /** @type {string} */\r
                                        const hex = new Blake2b(test.outlen ?? 64, key, salt, personal).update(input).digest('hex')\r
-                                       assert.equal(hex, test.out)\r
+                                       assert.equal(hex, test.out.toUpperCase())\r
                                } catch (err) {\r
                                        console.error(`blake2b libsodium test vector ${i} failed`, { cause: err })\r
                                }\r