From a92e80bfbb76c44e83d4ba564acba33f77f144aa Mon Sep 17 00:00:00 2001 From: hippocampus-web3 Date: Sun, 3 Dec 2023 16:42:48 +0100 Subject: [PATCH] Remove dependency from all transports --- .../__e2e__/bitcoin-ledger-client.e2e.ts | 17 +++++++++++------ packages/xchain-bitcoin/package.json | 5 ++--- packages/xchain-bitcoin/src/clientLedger.ts | 18 +++--------------- yarn.lock | 13 ------------- 4 files changed, 16 insertions(+), 37 deletions(-) diff --git a/packages/xchain-bitcoin/__e2e__/bitcoin-ledger-client.e2e.ts b/packages/xchain-bitcoin/__e2e__/bitcoin-ledger-client.e2e.ts index f4e632e99..29812567c 100644 --- a/packages/xchain-bitcoin/__e2e__/bitcoin-ledger-client.e2e.ts +++ b/packages/xchain-bitcoin/__e2e__/bitcoin-ledger-client.e2e.ts @@ -1,7 +1,8 @@ +import TransportNodeHid from '@ledgerhq/hw-transport-node-hid' import { Network, UtxoClientParams } from '@xchainjs/xchain-client' import { assetAmount, assetToBase } from '@xchainjs/xchain-util' -import { ClientLedger, TRANSPORT_TYPES } from '../src/clientLedger' +import { ClientLedger } from '../src/clientLedger' import { AssetBTC, BlockcypherDataProviders, @@ -28,12 +29,16 @@ const defaultBTCParams: UtxoClientParams = { }, } -const btcClient = new ClientLedger({ - transportType: TRANSPORT_TYPES.NODE, - ...defaultBTCParams, -}) - describe('Bitcoin Client Ledger', () => { + let btcClient: ClientLedger + beforeAll(async () => { + const transport = await TransportNodeHid.create() + + btcClient = new ClientLedger({ + transport, + ...defaultBTCParams, + }) + }) it('get address async', async () => { const address = await btcClient.getAddressAsync() console.log('address', address) diff --git a/packages/xchain-bitcoin/package.json b/packages/xchain-bitcoin/package.json index 5f4faa098..42b7c9fbc 100644 --- a/packages/xchain-bitcoin/package.json +++ b/packages/xchain-bitcoin/package.json @@ -33,6 +33,7 @@ "postversion": "git push --follow-tags" }, "devDependencies": { + "@ledgerhq/hw-transport-node-hid": "^6.28.0", "@types/wif": "^2.0.2", "@xchainjs/xchain-client": "^0.15.4", "@xchainjs/xchain-crypto": "^0.3.0", @@ -58,8 +59,6 @@ "access": "public" }, "dependencies": { - "@ledgerhq/hw-app-btc": "^10.1.0", - "@ledgerhq/hw-transport-node-hid": "^6.28.0", - "@ledgerhq/hw-transport-node-hid-singleton": "^6.30.0" + "@ledgerhq/hw-app-btc": "^10.1.0" } } diff --git a/packages/xchain-bitcoin/src/clientLedger.ts b/packages/xchain-bitcoin/src/clientLedger.ts index 29d35859e..4289d3d46 100644 --- a/packages/xchain-bitcoin/src/clientLedger.ts +++ b/packages/xchain-bitcoin/src/clientLedger.ts @@ -1,18 +1,11 @@ import AppBtc from '@ledgerhq/hw-app-btc' import { Transaction } from '@ledgerhq/hw-app-btc/lib/types' -import TransportNodeHid from '@ledgerhq/hw-transport-node-hid' -import TransportNodeHidSingleton from '@ledgerhq/hw-transport-node-hid-singleton' import { FeeOption, FeeRate, TxHash, TxParams, UTXO, UtxoClientParams } from '@xchainjs/xchain-client' import { Address } from '@xchainjs/xchain-util' import * as Bitcoin from 'bitcoinjs-lib' import { Client } from './client' -export enum TRANSPORT_TYPES { - NODE = 'NODE', - DESKTOP = 'DESKTOP', -} - /** * Custom Ledger Bitcoin client */ @@ -21,22 +14,17 @@ class ClientLedger extends Client { // eslint-disable-next-line @typescript-eslint/no-explicit-any private transport: any // TODO: Parametrize private app: AppBtc | undefined - private transportType: TRANSPORT_TYPES - constructor(params: UtxoClientParams & { transportType: TRANSPORT_TYPES }) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + constructor(params: UtxoClientParams & { transport: any }) { super(params) - this.transportType = params.transportType + this.transport = params.transport } public async getApp(): Promise { if (this.app) { return this.app } - if (this.transportType === TRANSPORT_TYPES.NODE) { - this.transport = await TransportNodeHid.create() - } else { - this.transport = await TransportNodeHidSingleton.create() - } this.app = new AppBtc({ transport: this.transport }) return this.app } diff --git a/yarn.lock b/yarn.lock index 879508a99..578989f8a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1318,19 +1318,6 @@ "@ledgerhq/logs" "^6.12.0" node-hid "^2.1.2" -"@ledgerhq/hw-transport-node-hid-singleton@^6.30.0": - version "6.30.0" - resolved "https://registry.yarnpkg.com/@ledgerhq/hw-transport-node-hid-singleton/-/hw-transport-node-hid-singleton-6.30.0.tgz#7f0cb0c6db8c4c8164021fd393cfbd7e070f7100" - integrity sha512-qTc0eeqrx0NShtpXSG3n8mhb8316eWp/AAusOxvOaUCzqH4rjAGUlkHfRdKo2bm84J6k5RMxFYAndDi3kX5o4g== - dependencies: - "@ledgerhq/devices" "^8.1.0" - "@ledgerhq/errors" "^6.16.0" - "@ledgerhq/hw-transport" "^6.30.0" - "@ledgerhq/hw-transport-node-hid-noevents" "^6.29.0" - "@ledgerhq/logs" "^6.12.0" - node-hid "^2.1.2" - usb "2.9.0" - "@ledgerhq/hw-transport-node-hid@^5.10.0": version "5.51.1" resolved "https://registry.yarnpkg.com/@ledgerhq/hw-transport-node-hid/-/hw-transport-node-hid-5.51.1.tgz#fe8eb81e18929663540698c80905952cdbe542d5"