6.31.4 • Published 2 months ago

@ledgerhq/hw-transport v6.31.4

Weekly downloads
37,647
License
Apache-2.0
Repository
github
Last release
2 months ago

GitHub, Ledger Devs Discord, Developer Portal

@ledgerhq/hw-transport

@ledgerhq/hw-transport implements the generic interface of a Ledger Hardware Wallet transport.

API

Table of Contents

Subscription

Type: {unsubscribe: function (): void}

Properties

  • unsubscribe function (): void

Device

Type: any

DescriptorEvent

A "descriptor" is a parameter that is specific to the implementation, and can be an ID, file path, or URL. type: add or remove event descriptor: a parameter that can be passed to open(descriptor) deviceModel: device info on the model (is it a nano s, nano x, ...) device: transport specific device info

Observer

Observer generic type, following the Observer pattern

Type: Readonly<{next: function (event: EventType): any, error: function (e: EventError): any, complete: function (): any}>

Transport

The Transport class defines a generic interface for communicating with a Ledger hardware wallet. There are different kind of transports based on the technology (channels like U2F, HID, Bluetooth, Webusb) and environment (Node, Web,...). It is an abstract class that needs to be implemented.

Parameters

  • $0 {context: TraceContext?, logType: LogType?} (optional, default {})

    • $0.context
    • $0.logType

exchange

Send data to the device using a low level API. It's recommended to use the "send" method for a higher level API.

Parameters
  • _apdu Buffer
  • options Object Contains optional options for the exchange function* abortTimeoutMs: stop the exchange after a given timeout. Another timeout exists to detect unresponsive device (see unresponsiveTimeout). This timeout aborts the exchange. (optional, default {})

    • options.abortTimeoutMs
  • apdu Buffer The data to send.

Returns Promise[Buffer](https://nodejs.org/api/buffer.html) A promise that resolves with the response data from the device.

exchangeBulk

Send apdus in batch to the device using a low level API. The default implementation is to call exchange for each apdu.

Parameters

Returns Subscription A Subscription object on which you can call ".unsubscribe()" to stop sending apdus.

setScrambleKey

Set the "scramble key" for the next data exchanges with the device. Each app can have a different scramble key and it is set internally during instantiation.

Parameters

close

Close the connection with the device.

Note: for certain transports (hw-transport-node-hid-singleton for ex), once the promise resolved, the transport instance is actually still cached, and the device is disconnected only after a defined timeout. But for the consumer of the Transport, this does not matter and it can consider the transport to be closed.

Returns Promise\ A promise that resolves when the transport is closed.

on

Listen for an event on the transport instance. Transport implementations may have specific events. Common events include: "disconnect" : triggered when the transport is disconnected.

Parameters
  • eventName string The name of the event to listen for.
  • cb function (...args: Array\): any

Returns void

off

Stop listening to an event on an instance of transport.

Parameters

Returns void

setDebugMode

Enable or not logs of the binary exchange

setExchangeTimeout

Set a timeout (in milliseconds) for the exchange call. Only some transport might implement it. (e.g. U2F)

Parameters

Returns void

setExchangeUnresponsiveTimeout

Define the delay before emitting "unresponsive" on an exchange that does not respond

Parameters

Returns void

send

Send data to the device using the higher level API.

Parameters
  • cla number The instruction class for the command.
  • ins number The instruction code for the command.
  • p1 number The first parameter for the instruction.
  • p2 number The second parameter for the instruction.
  • data Buffer The data to be sent. Defaults to an empty buffer. (optional, default Buffer.alloc(0))
  • statusList Array[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number) A list of acceptable status codes for the response. Defaults to [StatusCodes.OK]. (optional, default [StatusCodes.OK])
  • options Object Contains optional options for the exchange function* abortTimeoutMs: stop the send after a given timeout. Another timeout exists to detect unresponsive device (see unresponsiveTimeout). This timeout aborts the exchange. (optional, default {})

    • options.abortTimeoutMs

Returns Promise[Buffer](https://nodejs.org/api/buffer.html) A promise that resolves with the response data from the device.

exchangeAtomicImpl

Wrapper to make an exchange "atomic" (blocking any other exchange)

It also handles "unresponsiveness" by emitting "unresponsive" and "responsive" events.

Parameters
  • f function (): Promise\ The exchange job, using the transport to run

Returns Promise\ a Promise resolving with the output of the given job

setTraceContext

Sets the context used by the logging/tracing mechanism

Useful when re-using (cached) the same Transport instance, but with a new tracing context.

Parameters
  • context TraceContext? A TraceContext, that can undefined to reset the context

updateTraceContext

Updates the context used by the logging/tracing mechanism

The update only overrides the key-value that are already defined in the current context.

Parameters
  • contextToAdd TraceContext A TraceContext that will be added to the current context

getTraceContext

Gets the tracing context of the transport instance

Returns (TraceContext | undefined)

isSupported

Check if the transport is supported on the current platform/browser.

Type: function (): Promise[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)

Returns Promise[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean) A promise that resolves with a boolean indicating support.

list

List all available descriptors for the transport. For a better granularity, checkout listen().

Type: function (): Promise[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\<any>

Examples
TransportFoo.list().then(descriptors => ...)

Returns Promise[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)\<any> A promise that resolves with an array of descriptors.

listen

Listen for device events for the transport. The method takes an observer of DescriptorEvent and returns a Subscription. A DescriptorEvent is an object containing a "descriptor" and a "type" field. The "type" field can be "add" or "remove", and the "descriptor" field can be passed to the "open" method. The "listen" method will first emit all currently connected devices and then will emit events as they occur, such as when a USB device is plugged in or a Bluetooth device becomes discoverable.

Type: function (observer: Observer<DescriptorEvent\>): Subscription

Parameters
  • observer Observer<DescriptorEvent\> An object with "next", "error", and "complete" functions, following the observer pattern.
Examples
const sub = TransportFoo.listen({
next: e => {
if (e.type==="add") {
sub.unsubscribe();
const transport = await TransportFoo.open(e.descriptor);
...
}
},
error: error => {},
complete: () => {}
})

Returns Subscription A Subscription object on which you can call ".unsubscribe()" to stop listening to descriptors.

open

Attempt to create a Transport instance with a specific descriptor.

Type: function (descriptor: any, timeoutMs: number, context: TraceContext): Promise<Transport>

Parameters
  • descriptor any The descriptor to open the transport with.
  • timeout number An optional timeout for the transport connection.
  • context TraceContext Optional tracing/log context
Examples
TransportFoo.open(descriptor).then(transport => ...)

Returns Promise<Transport> A promise that resolves with a Transport instance.

create

create() allows to open the first descriptor available or throw if there is none or if timeout is reached. This is a light helper, alternative to using listen() and open() (that you may need for any more advanced usecase)

Parameters
  • openTimeout (optional, default 3000)
  • listenTimeout number?
Examples
TransportFoo.create().then(transport => ...)

Returns Promise<Transport>

@thorswap-lib/hdwallet-ledger-webusb@syoonk/perijs@ledgerhq/hw-app-swaphw-app-trxkapilteztest2test-ledger-signerperi-finance-js@horizon-protocol/horizon-jsethers_evaledgerjs-hw-app-ergothor-ledger@confluxproject/hardware-walletsgotabit@bosagora/hardware-walletsboaproject-hardware-wallets@everything-registry/sub-chunk-540paras-wallet-selectorparas-wallet-selector-here-wallethw-app-bananotaquito-ledger-signersymbol-ledger-typescriptsynthetix-jssynthetix-js-asynthetix-js-oikossynthetix-js-v2synthetix-js_kdswanchain-js-sdkweb3-wallet-selectorrh-ethersswitcheo-jstezos-oracletezos-oracle-lib@deltalabs/eos-transit-ledger-provider@ninjago666/tronwallet-adapter-ledger-v3lit-pkp-ethersmew-coreledgerhw-app-bitcoin-new-jsledger-bitcoinledger-bitsong-jsledger-cosmos-jsledger-web-hw-transportledger-polkadotledger-terra-cosmosledger-terra-js-forked-accountledger-matrixledger-mpc-appledger-mxw-jsledger-oasis-jsledger-orbitium-jsmudgen-hardware-walletshavven-jshw-app-alamguhw-app-btchw-app-ckbhw-app-ckb-testhw-app-cschw-app-dfihw-app-eos-testhw-app-kdahw-app-nanhw-app-nanohw-app-nano-xrohw-app-paciolihw-app-qkchw-app-ttchw-app-unohw-app-vaphw-ledger-providerhwapi-app-thetahw-transport-node-speculos-httpjurosh-ethersproject-hardware-wallets-debugjurosh-hardware-wallets-optionaltesthelios-transporthelium-wallet-utilitynear-wallet-selectornano-app-web-installer-libnano-app-web-installer-lib-testmxw-ledger-signerprobe-ethersnesciuntvoluptasmvs-ledgernumbatxquais5pynthetix-jssf-ethersturtlecoin-utilstradehub-api-jstrevorcontractkitton-ledger@astrox/identity-ledgerhq@authereum/ethersproject-hardware-wallets@arkecosystem/ledger-transport@avalabs/core-wallets-sdk@avalabs/hw-app-avalanche@avalabs/avalanche-wallet-sdk@akhmetovdev/ledger-connector@aleworm/hw-transport-node-hid@aleworm/hw-transport-node-hid-noevents@alephium/ledger-app@axia-js/hw-ledger-transports
6.31.4

2 months ago

6.31.4-next.0

2 months ago

6.31.3

2 months ago

6.31.3-next.0

2 months ago

6.31.3-nightly.3

2 months ago

6.31.3-nightly.2

3 months ago

6.31.3-nightly.1

3 months ago

6.31.0-next.0

5 months ago

6.31.2

4 months ago

6.31.0

5 months ago

6.31.1

4 months ago

6.31.1-next.0

5 months ago

6.31.2-hotfix.0

4 months ago

6.31.3-nightly.0

3 months ago

6.31.0-nightly.1

6 months ago

6.31.0-nightly.2

6 months ago

6.31.0-nightly.3

6 months ago

6.31.1-nightly.2

5 months ago

6.31.1-nightly.1

5 months ago

6.31.1-nightly.0

5 months ago

6.31.0-nightly.0

6 months ago

6.30.6

7 months ago

6.30.6-next.0

8 months ago

6.30.6-nightly.0

8 months ago

6.30.5

8 months ago

6.30.5-nightly.1

9 months ago

6.30.5-nightly.0

9 months ago

6.30.5-next.0

9 months ago

6.30.4-new-wc.0

9 months ago

6.30.4

9 months ago

6.30.4-wc-test.0

9 months ago

6.30.4-next.0

9 months ago

6.30.4-nightly.0

10 months ago

6.30.3

10 months ago

6.30.2

10 months ago

6.30.3-next.0

10 months ago

6.30.2-nightly.1

10 months ago

6.30.2-next.0

10 months ago

6.30.2-nightly.0

11 months ago

6.30.1

12 months ago

6.30.1-next.0

12 months ago

6.28.8-next.0

1 year ago

6.30.1-nightly.0

12 months ago

6.29.0

1 year ago

6.30.0-next.0

1 year ago

6.28.8

1 year ago

6.28.6

1 year ago

6.28.7

1 year ago

6.30.0

12 months ago

6.29.0-next.0

1 year ago

6.28.7-next.0

1 year ago

6.28.6-next.0

1 year ago

6.28.3-next.0

2 years ago

6.28.3

2 years ago

6.28.4

1 year ago

6.28.5

1 year ago

6.28.5-next.0

1 year ago

6.28.4-next.0

2 years ago

6.28.4-nightly.0

2 years ago

6.28.3-nightly.0

2 years ago

6.28.2

2 years ago

6.28.2-next.0

2 years ago

6.28.2-nightly.1

2 years ago

6.28.2-nightly.0

2 years ago

6.28.2-nightly.2

2 years ago

6.28.0-next.0

2 years ago

6.28.0

2 years ago

6.28.1

2 years ago

6.28.1-next.0

2 years ago

6.28.1-nightly.0

2 years ago

6.27.9-protect.1

2 years ago

6.27.9-protect.0

2 years ago

6.27.7-next.0

2 years ago

6.27.7-nightly.1

2 years ago

6.27.7-nightly.2

2 years ago

6.27.7-nightly.3

2 years ago

6.27.8-next.0

2 years ago

6.27.10

2 years ago

6.27.9

2 years ago

6.27.7

2 years ago

6.27.8

2 years ago

6.27.10-next.0

2 years ago

6.27.9-nightly.1

2 years ago

6.27.9-nightly.0

2 years ago

6.27.9-nightly.2

2 years ago

6.27.9-next.0

2 years ago

6.27.8-nightly.0

2 years ago

6.27.7-nightly.0

2 years ago

6.27.5

2 years ago

6.27.6

2 years ago

6.27.7-ts-llm.0

2 years ago

6.27.6-next.0

2 years ago

6.27.5-next.0

2 years ago

6.27.3

2 years ago

6.27.4

2 years ago

6.27.4-next.0

2 years ago

6.27.5-nightly.2

2 years ago

6.27.5-nightly.0

2 years ago

6.27.5-nightly.1

2 years ago

6.27.4-nightly.0

2 years ago

6.27.2-next.0

2 years ago

6.27.2-yolo.0

2 years ago

6.27.2

2 years ago

6.27.3-next.0

2 years ago

6.27.2-nightly.1

2 years ago

6.27.3-nightly.0

2 years ago

6.27.2-nightly.0

3 years ago

6.27.1-fts.6

3 years ago

6.27.1

3 years ago

6.25.1-alpha.3

3 years ago

6.24.1

3 years ago

6.20.0

3 years ago

6.19.0

3 years ago

6.11.2

3 years ago

6.11.0

3 years ago

6.9.1-taproot.0

3 years ago

6.10.0

3 years ago

6.7.0

3 years ago

6.3.0

3 years ago

6.2.0-bsc.5

3 years ago

6.2.0-bsc.4

3 years ago

6.2.0

3 years ago

6.2.0-bsc.1

3 years ago

6.2.0-bsc.2

3 years ago

6.2.0-bsc.3

3 years ago

6.2.0-bsc.0

3 years ago

6.1.0

3 years ago

6.0.1

3 years ago

6.0.0

3 years ago

6.0.2

3 years ago

6.0.0-rc.0

3 years ago

6.0.0-alpha.5

3 years ago

5.48.1-alpha.25

4 years ago

5.50.0

4 years ago

5.51.1

4 years ago

5.51.0

4 years ago

5.49.0

4 years ago

5.48.1-uglify.0

4 years ago

5.48.0

4 years ago

5.46.0

4 years ago

5.45.0

4 years ago

5.43.0

4 years ago

5.41.0

4 years ago

5.40.0

4 years ago

5.39.1

4 years ago

5.39.0

4 years ago

5.38.0

4 years ago

5.36.0

4 years ago

5.34.0

4 years ago

5.33.1-alpha.3

4 years ago

5.30.0

4 years ago

5.29.0

4 years ago

5.28.0

4 years ago

5.26.0

4 years ago

5.25.0

4 years ago

5.23.0

4 years ago

5.22.0

4 years ago

5.21.0

4 years ago

5.19.1

4 years ago

5.19.0

4 years ago

5.17.0

4 years ago

5.15.0

5 years ago

5.13.1

5 years ago

5.13.0

5 years ago

5.12.0

5 years ago

5.11.0

5 years ago

5.9.0

5 years ago

5.8.0

5 years ago

5.7.0

5 years ago

5.6.0

5 years ago

5.5.0

5 years ago

5.3.0

5 years ago

5.1.1-alpha.2

5 years ago

5.2.0

5 years ago

5.0.0-rc.4

5 years ago

5.0.0

5 years ago

5.0.0-babel7.4

5 years ago

5.0.0-babel7.3

5 years ago

4.78.0

5 years ago

5.0.0-babel7.1

5 years ago

4.77.0

5 years ago

5.0.0-alpha.7

5 years ago

5.0.0-alpha.5

5 years ago

5.0.0-alpha.4

5 years ago

4.74.3-alpha.6

5 years ago

5.0.0-alpha.3

5 years ago

4.74.2

5 years ago

4.74.1

5 years ago

4.74.0

5 years ago

4.73.7

5 years ago

4.73.5

5 years ago

4.73.4

5 years ago

4.73.3

5 years ago

4.73.2

5 years ago

4.73.1

5 years ago

4.72.2

5 years ago

4.72.1

5 years ago

4.72.0

5 years ago

4.71.0

5 years ago

4.70.3

5 years ago

4.70.2

5 years ago

4.70.0

5 years ago

4.69.3-alpha.1

5 years ago

4.68.4

5 years ago

4.68.2

5 years ago

4.68.0

5 years ago

4.66.0

5 years ago

4.64.1

5 years ago

4.64.0

5 years ago

4.63.2

5 years ago

4.63.1

5 years ago

4.62.0

5 years ago

4.61.0

5 years ago

4.60.3

5 years ago

4.60.2

6 years ago

4.60.0

6 years ago

4.59.1-alpha.2

6 years ago

4.58.0

6 years ago

4.57.0

6 years ago

4.56.0

6 years ago

4.55.1-alpha.2

6 years ago

4.55.0

6 years ago

4.54.0

6 years ago

4.53.0

6 years ago

4.52.0

6 years ago

4.50.0

6 years ago

4.48.0

6 years ago

4.47.0

6 years ago

4.46.0

6 years ago

4.45.0

6 years ago

4.44.2

6 years ago

4.44.0

6 years ago

4.43.1-alpha.0

6 years ago

4.43.0

6 years ago

4.41.1

6 years ago

4.39.0

6 years ago

4.38.6

6 years ago

4.38.0

6 years ago

4.36.2

6 years ago

4.37.0

6 years ago

4.35.1-beta.28

6 years ago

4.35.0

6 years ago

4.32.0

6 years ago

4.24.0

6 years ago

4.21.0

6 years ago

4.19.0

6 years ago

4.15.0

6 years ago

4.13.0

6 years ago

4.12.0

7 years ago

4.7.3

7 years ago

4.7.0

7 years ago

4.6.0

7 years ago

4.3.0

7 years ago

4.2.0

7 years ago

4.0.0

7 years ago

3.0.0

7 years ago

2.2.0

7 years ago

2.1.3

7 years ago

2.1.2

7 years ago

2.1.0

7 years ago

2.0.5

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.1.0

7 years ago

1.0.8

7 years ago

1.0.5

7 years ago