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'
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
*/
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)
}
/**
--- /dev/null
+//! 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()
+ }
+}