From 6e209b8b73c0cba09ef2321f25355c6df14b34c7 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Thu, 14 Aug 2025 13:58:04 -0700 Subject: [PATCH] Test using Ledger-derived data. --- test/test.blocks.mjs | 25 ++++++++++++++++++++++--- test/test.ledger.mjs | 8 ++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/test/test.blocks.mjs b/test/test.blocks.mjs index 731df8e..04d0523 100644 --- a/test/test.blocks.mjs +++ b/test/test.blocks.mjs @@ -4,8 +4,12 @@ 'use strict' import { assert, isNode, suite, test } from './GLOBALS.mjs' -import { NANO_TEST_VECTORS } from './VECTORS.mjs' +import { CUSTOM_TEST_VECTORS, NANO_TEST_VECTORS } from './VECTORS.mjs' +/** +* @type {typeof import('../dist/types.d.ts').Account} +*/ +let Account /** * @type {typeof import('../dist/types.d.ts').Block} */ @@ -15,9 +19,9 @@ let Block */ let Wallet if (isNode) { - ({ Block, Wallet } = await import('../dist/nodejs.min.js')) + ({ Account, Block, Wallet } = await import('../dist/nodejs.min.js')) } else { - ({ Block, Wallet } = await import('../dist/browser.min.js')) + ({ Account, Block, Wallet } = await import('../dist/browser.min.js')) } await Promise.all([ @@ -96,6 +100,7 @@ await Promise.all([ suite('Block signing using official test vectors', async () => { const { ADDRESS_0, BIP39_SEED, BLAKE2B_ADDRESS_1, BLAKE2B_PUBLIC_1, BLAKE2B_SEED, OPEN_BLOCK, PASSWORD, PUBLIC_0, PRIVATE_0, RECEIVE_BLOCK, SEND_BLOCK } = NANO_TEST_VECTORS + const { LEDGER_ADDRESS_0, LEDGER_MNEMONIC, LEDGER_PRIVATE_0, LEDGER_PUBLIC_0, LEDGER_OPEN_BLOCK } = CUSTOM_TEST_VECTORS await test('sign open block with BLAKE2b wallet', async () => { const wallet = await Wallet.load('BLAKE2b', PASSWORD, BLAKE2B_SEED) @@ -159,6 +164,20 @@ await Promise.all([ assert.nullish(block.work) }) + await test('sign Ledger-derived receive block', async () => { + const wallet = await Wallet.load('BIP-44', '', LEDGER_MNEMONIC) + await wallet.unlock('') + const account = await wallet.account() + assert.equal(account.publicKey, LEDGER_PUBLIC_0) + assert.equal(account.address, LEDGER_ADDRESS_0) + const block = new Block(LEDGER_OPEN_BLOCK.account, LEDGER_OPEN_BLOCK.balance, LEDGER_OPEN_BLOCK.previous, LEDGER_OPEN_BLOCK.representative) + .receive(LEDGER_OPEN_BLOCK.link, LEDGER_OPEN_BLOCK.balance) + assert.equal(block.hash, LEDGER_OPEN_BLOCK.hash) + await wallet.sign(0, block) + assert.equal(block.signature, LEDGER_OPEN_BLOCK.signature) + assert.ok(await block.verify(account.publicKey)) + }) + // skip since nano.org send block sample has receive block work difficulty await test('sign send block', { skip: true }, async () => { const block = await new Block(SEND_BLOCK.account, SEND_BLOCK.balance, SEND_BLOCK.previous, SEND_BLOCK.representative) diff --git a/test/test.ledger.mjs b/test/test.ledger.mjs index cfd0caa..cb043ea 100644 --- a/test/test.ledger.mjs +++ b/test/test.ledger.mjs @@ -39,7 +39,7 @@ await Promise.all([ /* node:coverage disable */ suite('Ledger hardware wallet', { skip: false || isNode || Ledger.isUnsupported }, async () => { - const { RECEIVE_BLOCK, SEND_BLOCK } = NANO_TEST_VECTORS + const { OPEN_BLOCK, RECEIVE_BLOCK, SEND_BLOCK } = NANO_TEST_VECTORS let wallet, account, openBlock, sendBlock, receiveBlock @@ -114,14 +114,14 @@ await Promise.all([ }) await test('sign open block from block', async () => { - openBlock = new Block(account, '0', '0', RECEIVE_BLOCK.representative) - .receive(RECEIVE_BLOCK.link, RECEIVE_BLOCK.balance) + openBlock = new Block(account, '0', '0', OPEN_BLOCK.representative) + .receive(OPEN_BLOCK.link, '0') assert.ok(/^[A-F0-9]{64}$/i.test(openBlock.hash)) assert.nullish(openBlock.signature) assert.equal(openBlock.account.publicKey, account.publicKey) - const signature = await wallet.sign(0, openBlock, 'hex') + const signature = await wallet.sign(0, openBlock) assert.ok(/^[A-F0-9]{128}$/i.test(signature)) -- 2.47.3