]> git.codecow.com Git - libnemo.git/commitdiff
Verify Ledger secret by signing simpler nonce instead of blocks.
authorChris Duncan <chris@codecow.com>
Wed, 13 May 2026 05:15:05 +0000 (22:15 -0700)
committerChris Duncan <chris@codecow.com>
Wed, 13 May 2026 05:15:05 +0000 (22:15 -0700)
src/lib/ledger.ts
src/lib/wallet/index.ts

index 118e4e9b4b1d548cc809273fca12e9cce99d3a26..24fa3687a3ba29a25b9be7a758ea875ddc7763c7 100644 (file)
@@ -234,7 +234,7 @@ export class Ledger {
        * The actual message signed is a string which can be expressed as the
        * following template literal:
        *
-       * `Nano Signed Nonce:\n${nonceBytes}`
+       * `Nano Signed Nonce:\n${nonce_bytes_as_hex}`
        *
        * IMPORTANT: The current version of the Nano app for Ledger devices will NOT
        * prompt users to confirm the signature. If valid, the nonce will immediately
@@ -346,19 +346,12 @@ export class Ledger {
        static async verify (secret: string): Promise<boolean> {
                const testWallet = await Wallet.load('BIP-44', '', secret)
                secret = ''
+               const nonce = crypto.randomUUID().slice(-16)
                try {
                        await testWallet.unlock('')
-                       const { address, publicKey } = await testWallet.account(0)
-                       const testOpenBlock = await new Block(address, '0', publicKey, address)
-                               .receive(publicKey, 0)
-                               .sign(testWallet, 0)
-                       const testSendBlock = await new Block(address, '0', testOpenBlock.hash, address)
-                               .send(address, 0)
-                               .sign(testWallet, 0)
-                       const testSignature = testSendBlock.signature
-                       testSendBlock.signature = undefined
+                       const testSignature = await testWallet.sign(0, `Nano Signed Nonce:\n${utf8.toHex(nonce)}`)
                        try {
-                               const ledgerSignature = await this.sign(0, testSendBlock, testOpenBlock)
+                               const ledgerSignature = await this.sign(0, nonce)
                                return ledgerSignature === testSignature
                        } catch (err) {
                                throw new Error('Failed to verify wallet', { cause: err })
@@ -625,8 +618,6 @@ export class Ledger {
        /**
        * Sign a nonce with the Ledger device.
        *
-       * nonce signing is currently broken: https://github.com/LedgerHQ/app-nano/pull/14
-       *
        * @param {number} index - Account number
        * @param {Uint8Array} nonce - 128-bit value to sign
        * @returns {Promise} Status and signature
index aeb8a43355c9e00bdb7d010e605263a5bd3cec6c..2ee4f44a160353deb3d0c76f12ad21d45c917105 100644 (file)
@@ -342,7 +342,7 @@ export class Wallet {
        * actual message signed is a string which can be expressed as the following\r
        * template literal:\r
        *\r
-       * `Nano Signed Nonce:\n${nonceBytes}`\r
+       * `Nano Signed Nonce:\n${nonce_bytes_as_hex}`\r
        *\r
        * IMPORTANT: The current version of the Nano app for Ledger devices will NOT\r
        * prompt users to confirm the signature. If valid, the nonce will immediately\r