//! 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 = {
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)
}
//! 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'
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])
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)
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
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