@ledgerhq/hw-transport-node-hid-noevents
Version:
Ledger Hardware Wallet Node implementation of the communication layer, using node-hid. without usb events
143 lines (87 loc) • 4.97 kB
Markdown
<img src="https://user-images.githubusercontent.com/4631227/191834116-59cf590e-25cc-4956-ae5c-812ea464f324.png" height="100" />
[GitHub](https://github.com/LedgerHQ/ledger-live/),
[Ledger Devs Discord](https://developers.ledger.com/discord-pro),
[Developer Portal](https://developers.ledger.com/)
## @ledgerhq/hw-transport-node-hid-noevents
Allows to communicate with Ledger Hardware Wallets.
**\[Node]**/Electron **(HID)** – uses **only** `node-hid`. Does not provide USB events.
## API
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
#### Table of Contents
* [createHIDframing](#createhidframing)
* [Parameters](#parameters)
* [makeBlocks](#makeblocks)
* [Parameters](#parameters-1)
* [reduceResponse](#reduceresponse)
* [Parameters](#parameters-2)
* [getReducedResult](#getreducedresult)
* [Parameters](#parameters-3)
* [TransportNodeHidNoEvents](#transportnodehidnoevents)
* [Parameters](#parameters-4)
* [Examples](#examples)
* [exchange](#exchange)
* [Parameters](#parameters-5)
* [close](#close)
* [isSupported](#issupported)
* [list](#list)
* [listen](#listen)
* [Parameters](#parameters-6)
* [open](#open)
* [Parameters](#parameters-7)
### createHIDframing
Object to handle HID frames (encoding and decoding)
#### Parameters
* `channel` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** 
* `packetSize` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** The HID protocol packet size in bytes (usually 64)
### makeBlocks
Frames/encodes an APDU message into HID USB packets/frames
#### Parameters
* `apdu` **[Buffer](https://nodejs.org/api/buffer.html)** The APDU message to send, in a Buffer containing \[cla, ins, p1, p2, data length, data(if not empty)]
Returns **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Uint8Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array)<[ArrayBuffer](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)>>** an array of HID USB frames ready to be sent
### reduceResponse
Reduces HID USB packets/frames to one response.
#### Parameters
* `acc` **ResponseAcc** The value resulting from (accumulating) the previous call of reduceResponse.
On first call initialized to `initialAcc`. The accumulator enables handling multi-frames messages.
* `chunk` **[Buffer](https://nodejs.org/api/buffer.html)** Current chunk to reduce into accumulator
Returns **ResponseAcc** An accumulator value updated with the current chunk
### getReducedResult
Returns the response message that has been reduced from the HID USB frames
#### Parameters
* `acc` **ResponseAcc** The accumulator
Returns **([Buffer](https://nodejs.org/api/buffer.html) | null | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))** A Buffer containing the cleaned response message, or null if no response message, or undefined if the
accumulator is incorrect (message length is not valid)
### TransportNodeHidNoEvents
**Extends Transport**
node-hid Transport minimal implementation
#### Parameters
* `device` **HID.HID** 
* `$1` **{context: TraceContext?, logType: LogType?}** (optional, default `{}`)
* `$1.context`  
* `$1.logType`  
#### Examples
```javascript
import TransportNodeHid from "@ledgerhq/hw-transport-node-hid-noevents";
...
TransportNodeHid.create().then(transport => ...)
```
#### exchange
Exchange with the device using APDU protocol.
##### Parameters
* `apdu` **[Buffer](https://nodejs.org/api/buffer.html)** 
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[Buffer](https://nodejs.org/api/buffer.html)>** a promise of apdu response
#### close
release the USB device.
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<void>** 
#### isSupported
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)<[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)>** 
#### list
Returns **[Promise](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<any>** 
#### listen
##### Parameters
* `observer` **Observer\<DescriptorEvent\<any>>** 
Returns **Subscription** 
#### open
if path="" is not provided, the library will take the first device
##### Parameters
* `path` **([string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String) | null | [undefined](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined))**