Skip to content

Commit

Permalink
Remove dependency from all transports
Browse files Browse the repository at this point in the history
  • Loading branch information
hippocampus-web3 committed Dec 3, 2023
1 parent 05bfbae commit a92e80b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 37 deletions.
17 changes: 11 additions & 6 deletions packages/xchain-bitcoin/__e2e__/bitcoin-ledger-client.e2e.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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)
Expand Down
5 changes: 2 additions & 3 deletions packages/xchain-bitcoin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
}
18 changes: 3 additions & 15 deletions packages/xchain-bitcoin/src/clientLedger.ts
Original file line number Diff line number Diff line change
@@ -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
*/
Expand All @@ -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<AppBtc> {
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
}
Expand Down
13 changes: 0 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit a92e80b

Please sign in to comment.