@ledgerhq/hw-transport-node-hid-singleton
v6.31.5
Published
Ledger Hardware Wallet Node implementation of the communication layer, using node-hid and node-usb
Downloads
3,595
Readme
GitHub, Ledger Devs Discord, Developer Portal
@ledgerhq/hw-transport-node-hid-singleton
Allows to communicate with Ledger Hardware Wallets.
[Node]/Electron (HID) – uses node-hid
and node-usb
. Keep transport opened and re-use it as a singleton, one device at a time on a computer but more robust implementation.
Are you adding Ledger support to your software wallet?
You may be using this package to open a USB connection between your desktop application and the device.
For a smooth and quick integration:
- See the developers’ documentation on the Developer Portal and
- Go on Discord to chat with developer support and the developer community.
API
Table of Contents
TransportNodeHidSingleton
Extends TransportNodeHidNoEvents
node-hid Transport implementation
Parameters
device
HID.HID$1
{context: TraceContext?} (optional, default{}
)$1.context
Examples
import TransportNodeHid from "@ledgerhq/hw-transport-node-hid-singleton";
...
TransportNodeHid.create().then(transport => ...)
exchange
Exchanges with the device using APDU protocol
Parameters
apdu
Buffer
Returns Promise<Buffer> a promise of apdu response
close
Closes the transport instance by triggering a disconnection after some inactivity (no new open
).
Intentionally not disconnecting the device/closing the hid connection directly: The HID connection will only be closed after some inactivity.
Returns Promise<void>
isSupported
list
listen
Parameters
observer
Observer<ListenDescriptorEvent>
Returns Subscription
setDisconnectAfterInactivityTimeout
Disconnects device from singleton instance after some inactivity (no new open
).
Currently, there is only one transport instance (for only one device connected via USB).
disconnect
Disconnects from the HID device associated to the transport singleton.
If you want to try to re-use the same transport instance at the next action (when calling open
again), you can use
the transport instance close
method: it will only enable a disconnect after some inactivity.
open
Connects to the first Ledger device connected via USB
Reusing the same TransportNodeHidSingleton instance until a disconnection happens. Pitfall: this implementation only handles 1 device connected via USB
Legacy: _descriptor
is needed to follow the Transport definition
Parameters
Returns Promise<TransportNodeHidSingleton>
onDisconnect
Disconnect event received from the transport instance.
It could be after a disconnection coming from the HID library (e.g. device unplugged) or from the transport instance itself (e.g. close). Clearing the singleton instance. Currently, only 1 device at a time is supported.