]> git.codecow.com Git - libnemo.git/commitdiff
Fix Ledger verify method.
authorChris Duncan <chris@zoso.dev>
Mon, 15 Sep 2025 15:24:47 +0000 (08:24 -0700)
committerChris Duncan <chris@zoso.dev>
Mon, 15 Sep 2025 15:24:47 +0000 (08:24 -0700)
src/lib/wallet/ledger.ts
test/GLOBALS.mjs
test/VECTORS.mjs
test/test.ledger.mjs

index 311faaa5e4112a1275d672851522dcb43e817d58..bed221c98a04e71d354b5d2c976284fd98840055 100644 (file)
@@ -271,12 +271,13 @@ export class Ledger {
                const testOpenBlock = await new Block(testAccount.address, '0', testAccount.publicKey, testAccount.address)
                        .receive(testAccount.publicKey, 0)
                        .sign(testWallet, 0)
-               const testSendBlock = new Block(testAccount.address, '0', testOpenBlock.hash, testAccount.address)
+               const testSendBlock = await new Block(testAccount.address, '0', testOpenBlock.hash, testAccount.address)
                        .send(testAccount.address, 0)
-               await testWallet.sign(0, testOpenBlock)
+                       .sign(testWallet, 0)
+               const testSignature = testSendBlock.signature
                try {
-                       await Ledger.sign(0, testSendBlock, testOpenBlock)
-                       return testSendBlock.signature === testOpenBlock.signature
+                       const ledgerSignature = await Ledger.sign(0, testSendBlock, testOpenBlock)
+                       return ledgerSignature === testSignature
                } catch (err) {
                        throw new Error('Failed to verify wallet', { cause: err })
                }
index 8388c0c746d9f402984665b5abeb84434a1b492e..f8a284b853eaf7e805c15c2d54a0acacde0871fe 100644 (file)
@@ -293,7 +293,7 @@ export class assert {
 
        /**
         * @param {unknown} fn
-        * @param {any} msg
+        * @param {any} [msg]
         * @returns {asserts fn is Function}
         */
        static throws (fn, msg) {
index e788a638b82fa95d50bf816e09c191b100fe58c1..a98a1373b4af3cce28acda0c3710ce1c44a77381 100644 (file)
@@ -222,6 +222,7 @@ export const CUSTOM_TEST_VECTORS = Object.freeze({
 
        // derived using BIP-44 from actual Ledger Nano S hardware wallet designated for dedicated testing
        LEDGER_MNEMONIC: "slight govern pepper assist escape target bread repair long faith maid bread donor situate swamp toss garage master stage gift vendor jacket client upset",
+       LEDGER_SEED: "1913E77BCFD9AA95BCB5171B1E781EC0EA3531F1FC427686D8BBA3D655BEFA43FDED6985B5E5806199A33539332DF8780426EDAD17E7BC2D95324D678BEEEE34",
        LEDGER_PRIVATE_0: "174A5E324A107D66E1AB17D9BCFC676D89F2940A4B90CB64A6656005756EBDA1",
        LEDGER_PUBLIC_0: "4423C456B9AF40A82807114BA3F77822E5CE1E5B4C2885296C6BBE7B9B377D48",
        LEDGER_ADDRESS_0: "nano_1j35rjddmdt1o1n1g6cdnhuqiaq7srh7pm3ainnprtxyhgfmgzcat494fyrr",
index ab87f59ecbf8a02fb0251f41f55699b03dae0718..a2177a10d2eec6f201ebbd17930be1d77ca307ae 100644 (file)
@@ -4,7 +4,7 @@
 'use strict'
 
 import { assert, click, env, 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}
@@ -34,11 +34,17 @@ const rpc = new Rpc(env.NODE_URL ?? '', env.API_KEY_NAME)
 /**
 * HID interactions require user gestures, so to reduce clicks, the variables
 * shared among tests like wallet and account are declared at the top-level.
+*
+* Some of these tests depend on a specific Ledger wallet owned by the developer
+* and dedicated to testing. Project clones or forks will need to modify the test
+* vectors to use the mnemonics, seeds, private keys, public keys, and addresses
+* from their own Ledger hardware wallets.
 */
 await Promise.all([
        /* node:coverage disable */
        suite('Ledger hardware wallet', { skip: false || isNode || navigator?.usb == null }, async () => {
 
+               const { LEDGER_MNEMONIC, LEDGER_SEED, LEDGER_PUBLIC_0, LEDGER_ADDRESS_0 } = CUSTOM_TEST_VECTORS
                const { OPEN_BLOCK, RECEIVE_BLOCK, SEND_BLOCK } = NANO_TEST_VECTORS
                let wallet, account, openBlock, sendBlock, receiveBlock
                try {
@@ -76,13 +82,31 @@ await Promise.all([
                        assert.equal(wallet.isLocked, false)
                })
 
+               await test('verify mnemonic', async () => {
+                       const isVerified = await wallet.verify(LEDGER_MNEMONIC)
+
+                       assert.exists(isVerified)
+                       assert.equal(typeof isVerified, 'boolean')
+                       assert.equal(isVerified, true)
+               })
+
+               await test('verify seed', async () => {
+                       const isVerified = await wallet.verify(LEDGER_SEED)
+
+                       assert.exists(isVerified)
+                       assert.equal(typeof isVerified, 'boolean')
+                       assert.equal(isVerified, true)
+               })
+
                await test('get first account', async () => {
                        account = await wallet.account()
 
                        assert.exists(account)
                        assert.ok(account instanceof Account)
-                       assert.exists(account.address)
                        assert.exists(account.publicKey)
+                       assert.equal(account.publicKey, LEDGER_PUBLIC_0)
+                       assert.exists(account.address)
+                       assert.equal(account.address, LEDGER_ADDRESS_0)
                })
 
                await test('get second and third accounts', async () => {