npm.io
6.36.0 • Published 1 month ago

@ledgerhq/hw-transport-node-hid-noevents

Licence
Apache-2.0
Version
6.36.0
Deps
5
Size
119 kB
Vulns
0
Weekly
0
Stars
610

GitHub, Ledger Devs Discord, Developer Portal

@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

Table of Contents
createHIDframing

Object to handle HID frames (encoding and decoding)

Parameters
  • channel number
  • packetSize number The HID protocol packet size in bytes (usually 64)
makeBlocks

Frames/encodes an APDU message into HID USB packets/frames

Parameters
  • apdu Buffer The APDU message to send, in a Buffer containing [cla, ins, p1, p2, data length, data(if not empty)]

Returns Array<Uint8Array<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 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 | null | 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
import TransportNodeHid from "@ledgerhq/hw-transport-node-hid-noevents";
...
TransportNodeHid.create().then(transport => ...)
exchange

Exchange with the device using APDU protocol.

Parameters

Returns Promise<Buffer> a promise of apdu response

close

release the USB device.

Returns Promise<void>

isSupported

Returns Promise<boolean>

list

Returns Promise<any>

listen
Parameters
  • observer Observer<DescriptorEvent<any>>

Returns Subscription

open

if path="" is not provided, the library will take the first device

Parameters

Keywords