From aaf424e526b87d48651f477c087b4a81755a7b4e Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Tue, 16 Sep 2025 13:32:03 -0700 Subject: [PATCH] Reorganize Ledger class to top lib directory instead of wallet. --- src/lib/{wallet => }/ledger.ts | 12 ++++++------ src/lib/wallet/accounts.ts | 2 +- src/lib/wallet/config.ts | 2 +- src/lib/wallet/create.ts | 2 +- src/lib/wallet/load.ts | 2 +- src/lib/wallet/lock.ts | 2 +- src/lib/wallet/sign.ts | 2 +- src/lib/wallet/unlock.ts | 2 +- src/lib/wallet/verify.ts | 2 +- 9 files changed, 14 insertions(+), 14 deletions(-) rename src/lib/{wallet => }/ledger.ts (99%) diff --git a/src/lib/wallet/ledger.ts b/src/lib/ledger.ts similarity index 99% rename from src/lib/wallet/ledger.ts rename to src/lib/ledger.ts index 85cf0ff..9d3b4b4 100644 --- a/src/lib/wallet/ledger.ts +++ b/src/lib/ledger.ts @@ -6,12 +6,12 @@ import { default as TransportBLE } from '@ledgerhq/hw-transport-web-ble' import { default as TransportHID } from '@ledgerhq/hw-transport-webhid' import { default as TransportUSB } from '@ledgerhq/hw-transport-webusb' import { LedgerStatus, LedgerAccountResponse, LedgerResponse, LedgerSignResponse, LedgerVersionResponse } from '#types' -import { Account } from '../account' -import { Block } from '../block' -import { BIP44_COIN_NANO, BIP44_PURPOSE, HARDENED_OFFSET } from '../constants' -import { bytes, dec, hex } from '../convert' -import { Rpc } from '../rpc' -import { Wallet } from '../wallet' +import { Account } from './account' +import { Block } from './block' +import { BIP44_COIN_NANO, BIP44_PURPOSE, HARDENED_OFFSET } from './constants' +import { bytes, dec, hex } from './convert' +import { Rpc } from './rpc' +import { Wallet } from './wallet' /** * Ledger hardware wallet created by communicating with a Ledger device via ADPU diff --git a/src/lib/wallet/accounts.ts b/src/lib/wallet/accounts.ts index 1939c40..556e7aa 100644 --- a/src/lib/wallet/accounts.ts +++ b/src/lib/wallet/accounts.ts @@ -27,7 +27,7 @@ export async function _accounts (type: WalletType, accounts: Map 0) { const publicAccounts = [] if (type === 'Ledger') { - const { Ledger } = await import('./ledger') + const { Ledger } = await import('../ledger') for (const index of indexes) { const { status, publicKey } = await Ledger.account(index) if (status !== 'OK' || publicKey == null) { diff --git a/src/lib/wallet/config.ts b/src/lib/wallet/config.ts index e9b7d97..6166d0a 100644 --- a/src/lib/wallet/config.ts +++ b/src/lib/wallet/config.ts @@ -12,7 +12,7 @@ export async function _config (type: WalletType, vault: Vault, settings: unknown } const { connection, timeout } = settings as { [key: string]: unknown } if (type === 'Ledger') { - const { Ledger } = await import('./ledger') + const { Ledger } = await import('../ledger') if (connection !== undefined && connection !== 'hid' && connection !== 'ble' && connection !== 'usb') { throw new Error('Ledger connection must be hid, ble, or usb', { cause: connection }) } diff --git a/src/lib/wallet/create.ts b/src/lib/wallet/create.ts index 2aec6fe..691358d 100644 --- a/src/lib/wallet/create.ts +++ b/src/lib/wallet/create.ts @@ -17,7 +17,7 @@ export async function _create (wallet: Wallet, vault: Vault, password: unknown, type: wallet.type } if (wallet.type === 'Ledger') { - const { Ledger } = await import('./ledger') + const { Ledger } = await import('../ledger') try { if (Ledger.isUnsupported) { throw new Error('Browser is unsupported') diff --git a/src/lib/wallet/load.ts b/src/lib/wallet/load.ts index 406c539..08cb559 100644 --- a/src/lib/wallet/load.ts +++ b/src/lib/wallet/load.ts @@ -17,7 +17,7 @@ export async function _load (wallet: Wallet, vault: Vault, password: unknown, se } if (wallet.type === 'Ledger') { - const { Ledger } = await import('./ledger') + const { Ledger } = await import('../ledger') if (Ledger.isUnsupported) { throw new Error('Failed to initialize Ledger wallet', { cause: 'Browser is unsupported' }) } diff --git a/src/lib/wallet/lock.ts b/src/lib/wallet/lock.ts index a65773f..14fc500 100644 --- a/src/lib/wallet/lock.ts +++ b/src/lib/wallet/lock.ts @@ -7,7 +7,7 @@ import { Wallet } from '../wallet' export async function _lock (wallet: Wallet, vault: Vault): Promise { try { if (wallet.type === 'Ledger') { - const { Ledger } = await import('./ledger') + const { Ledger } = await import('../ledger') Ledger.disconnect() } else { await vault.request({ diff --git a/src/lib/wallet/sign.ts b/src/lib/wallet/sign.ts index 3078172..4ff689e 100644 --- a/src/lib/wallet/sign.ts +++ b/src/lib/wallet/sign.ts @@ -44,7 +44,7 @@ export async function _signBlock (wallet: Wallet, vault: Vault, index: unknown, throw new TypeError('Invalid Block', { cause: block }) } if (wallet.type === 'Ledger') { - const { Ledger } = await import('./ledger') + const { Ledger } = await import('../ledger') const account = await wallet.account(index) if (frontier instanceof Block) { try { diff --git a/src/lib/wallet/unlock.ts b/src/lib/wallet/unlock.ts index bf5ba37..d021699 100644 --- a/src/lib/wallet/unlock.ts +++ b/src/lib/wallet/unlock.ts @@ -15,7 +15,7 @@ export async function _unlock (wallet: Wallet, vault: Vault, password: unknown): type: wallet.type } if (wallet.type === 'Ledger') { - const { Ledger } = await import('./ledger') + const { Ledger } = await import('../ledger') const status = await Ledger.connect() if (await status !== 'CONNECTED') { throw new Error('Failed to unlock wallet', { cause: status }) diff --git a/src/lib/wallet/verify.ts b/src/lib/wallet/verify.ts index 8a5d22d..47b439d 100644 --- a/src/lib/wallet/verify.ts +++ b/src/lib/wallet/verify.ts @@ -12,7 +12,7 @@ export async function _verify (type: WalletType, vault: Vault, secret: unknown): throw new TypeError('Wallet secret must be a string', { cause: typeof secret }) } if (type === 'Ledger') { - const { Ledger } = await import('./ledger') + const { Ledger } = await import('../ledger') return await Ledger.verify(secret) } else { const data: NamedData = { -- 2.47.3