]> git.codecow.com Git - libnemo.git/commitdiff
Extract verify function.
authorChris Duncan <chris@codecow.com>
Mon, 18 May 2026 19:53:32 +0000 (12:53 -0700)
committerChris Duncan <chris@codecow.com>
Mon, 18 May 2026 19:53:32 +0000 (12:53 -0700)
src/lib/ledger/index.ts
src/lib/ledger/verify.ts [new file with mode: 0644]

index 07a5f5e08798aeeac01763aad9cd986287863fcd..2b49f67a13eaa1e8f1e48485b59dd7067d2420fb 100644 (file)
@@ -7,9 +7,8 @@ import { default as TransportHID } from '@ledgerhq/hw-transport-webhid'
 import { default as TransportUSB } from '@ledgerhq/hw-transport-webusb'
 import { Block } from '../block'
 import { BIP44_COIN_NANO, BIP44_PURPOSE, HARDENED_OFFSET } from '../constants'
-import { dec, utf8 } from '../convert'
+import { dec } from '../convert'
 import { Rpc } from '../rpc'
-import { Wallet } from '../wallet'
 import { _account } from './account'
 import { _cache } from './cache'
 import { _close } from './close'
@@ -19,6 +18,7 @@ import { LedgerEvent } from './event'
 import { _open } from './open'
 import { queue } from './queue'
 import { _sign } from './sign'
+import { _verify } from './verify'
 
 export type LedgerStatus = 'UNSUPPORTED' | 'DISCONNECTED' | 'BUSY' | 'LOCKED' | 'CONNECTED'
 export type LedgerTransport = typeof TransportHID | typeof TransportBLE | typeof TransportUSB
@@ -263,21 +263,7 @@ export class Ledger {
         */
        static async verify (mnemonic: string): Promise<boolean>
        static async verify (secret: string): Promise<boolean> {
-               const testWallet = await Wallet.load('BIP-44', '', secret)
-               secret = ''
-               const nonce = crypto.randomUUID().slice(0, 16)
-               try {
-                       await testWallet.unlock('')
-                       const testSignature = await testWallet.sign(0, `Nano Signed Nonce:\n${utf8.toHex(nonce)}`)
-                       try {
-                               const ledgerSignature = await this.sign(0, nonce)
-                               return ledgerSignature === testSignature
-                       } catch (err) {
-                               throw new Error('Failed to verify wallet', { cause: err })
-                       }
-               } finally {
-                       await testWallet.destroy()
-               }
+               return _verify(secret)
        }
 
        /**
diff --git a/src/lib/ledger/verify.ts b/src/lib/ledger/verify.ts
new file mode 100644 (file)
index 0000000..ba0e891
--- /dev/null
@@ -0,0 +1,23 @@
+//! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@codecow.com>
+//! SPDX-License-Identifier: GPL-3.0-or-later
+import { Ledger } from '.'
+import { utf8 } from '../convert'
+import { Wallet } from '../wallet'
+
+export async function _verify (secret: string): Promise<boolean> {
+       const testWallet = await Wallet.load('BIP-44', '', secret)
+       secret = ''
+       const nonce = crypto.randomUUID().slice(0, 16)
+       try {
+               await testWallet.unlock('')
+               const testSignature = await testWallet.sign(0, `Nano Signed Nonce:\n${utf8.toHex(nonce)}`)
+               try {
+                       const ledgerSignature = await Ledger.sign(0, nonce)
+                       return ledgerSignature === testSignature
+               } catch (err) {
+                       throw new Error('Failed to verify wallet', { cause: err })
+               }
+       } finally {
+               await testWallet.destroy()
+       }
+}