@ledgerhq/hw-transport

  • Version 6.27.6
  • Published
  • 83.2 kB
  • 3 dependencies
  • Apache-2.0 license

Install

npm i @ledgerhq/hw-transport
yarn add @ledgerhq/hw-transport
pnpm add @ledgerhq/hw-transport

Overview

Ledger Hardware Wallet common interface of the communication layer

Index

Classes

class Transport

class Transport {}
  • Transport defines the generic interface to share between node/u2f impl A **Descriptor** is a parametric type that is up to be determined for the implementation. it can be for instance an ID, an file path, a URL,...

property deviceModel

deviceModel: any;

    property ErrorMessage_ListenTimeout

    static ErrorMessage_ListenTimeout: string;

      property ErrorMessage_NoDeviceFound

      static ErrorMessage_NoDeviceFound: string;

        property exchangeAtomicImpl

        exchangeAtomicImpl: (f: () => Promise<Buffer | void>) => Promise<Buffer | void>;

          property exchangeBusyPromise

          exchangeBusyPromise: Promise<void>;

            property exchangeTimeout

            exchangeTimeout: number;

              property isSupported

              static readonly isSupported: () => Promise<boolean>;
              • Statically check if a transport is supported on the user's platform/browser.

              property list

              static readonly list: () => Promise<Array<any>>;
              • List once all available descriptors. For a better granularity, checkout listen(). a promise of descriptors

                Example 1

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

              property listen

              static readonly listen: (
              observer: Observer<DescriptorEvent<any>>
              ) => Subscription;
              • Listen all device events for a given Transport. The method takes an Obverver of DescriptorEvent and returns a Subscription (according to Observable paradigm https://github.com/tc39/proposal-observable ) a DescriptorEvent is a { descriptor, type } object. type can be "add" or "remove" and descriptor is a value you can pass to open(descriptor). each listen() call will first emit all potential device already connected and then will emit events can come over times, for instance if you plug a USB device after listen() or a bluetooth device become discoverable.

                Parameter observer

                is an object with a next, error and complete function (compatible with observer pattern) a Subscription object on which you can .unsubscribe() to stop listening descriptors.

                Example 1

                const sub = TransportFoo.listen({ next: e => { if (e.type==="add") { sub.unsubscribe(); const transport = await TransportFoo.open(e.descriptor); ... } }, error: error => {}, complete: () => {} })

              property open

              static readonly open: (descriptor?: any, timeout?: number) => Promise<Transport>;
              • attempt to create a Transport instance with potentially a descriptor.

                Parameter descriptor

                : the descriptor to open the transport with.

                Parameter timeout

                : an optional timeout a Promise of Transport instance

                Example 1

                TransportFoo.open(descriptor).then(transport => ...)

              property send

              send: (
              cla: number,
              ins: number,
              p1: number,
              p2: number,
              data?: Buffer,
              statusList?: Array<number>
              ) => Promise<Buffer>;
              • wrapper on top of exchange to simplify work of the implementation.

                Parameter cla

                Parameter ins

                Parameter p1

                Parameter p2

                Parameter data

                Parameter statusList

                is a list of accepted status code (shorts). [0x9000] by default a Promise of response buffer

              property unresponsiveTimeout

              unresponsiveTimeout: number;

                method close

                close: () => Promise<void>;
                • close the exchange with the device. a Promise that ends when the transport is closed.

                method create

                static create: (
                openTimeout?: number,
                listenTimeout?: number
                ) => Promise<Transport>;
                • 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)

                  Example 1

                  TransportFoo.create().then(transport => ...)

                method decorateAppAPIMethod

                decorateAppAPIMethod: <R, A extends any[]>(
                methodName: string,
                f: (...args: A) => Promise<R>,
                ctx: any,
                scrambleKey: string
                ) => (...args: A) => Promise<R>;

                  method decorateAppAPIMethods

                  decorateAppAPIMethods: (
                  self: Record<string, any>,
                  methods: Array<string>,
                  scrambleKey: string
                  ) => void;

                    method emit

                    emit: (event: string, ...args: any) => void;

                      method exchange

                      exchange: (_apdu: Buffer) => Promise<Buffer>;
                      • low level api to communicate with the device This method is for implementations to implement but should not be directly called. Instead, the recommanded way is to use send() method

                        Parameter apdu

                        the data to send a Promise of response data

                      method off

                      off: (eventName: string, cb: (...args: Array<any>) => any) => void;
                      • Stop listening to an event on an instance of transport.

                      method on

                      on: (eventName: string, cb: (...args: Array<any>) => any) => void;
                      • Listen to an event on an instance of transport. Transport implementation can have specific events. Here is the common events: * "disconnect" : triggered if Transport is disconnected

                      method setDebugMode

                      setDebugMode: () => void;
                      • Enable or not logs of the binary exchange

                      method setExchangeTimeout

                      setExchangeTimeout: (exchangeTimeout: number) => void;
                      • Set a timeout (in milliseconds) for the exchange call. Only some transport might implement it. (e.g. U2F)

                      method setExchangeUnresponsiveTimeout

                      setExchangeUnresponsiveTimeout: (unresponsiveTimeout: number) => void;
                      • Define the delay before emitting "unresponsive" on an exchange that does not respond

                      method setScrambleKey

                      setScrambleKey: (_key: string) => void;
                      • set the "scramble key" for the next exchanges with the device. Each App can have a different scramble key and they internally will set it at instanciation.

                        Parameter key

                        the scramble key

                      Interfaces

                      interface DescriptorEvent

                      interface DescriptorEvent<Descriptor> {}
                      • 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

                      property descriptor

                      descriptor: Descriptor;

                        property device

                        device?: Device;

                          property deviceModel

                          deviceModel?: DeviceModel | null | undefined;

                            property type

                            type: DescriptorEventType;

                              Type Aliases

                              type DescriptorEventType

                              type DescriptorEventType = 'add' | 'remove';

                                type Device

                                type Device = any;

                                type Observer

                                type Observer<Ev> = Readonly<{
                                next: (event: Ev) => unknown;
                                error: (e: any) => unknown;
                                complete: () => unknown;
                                }>;

                                type Subscription

                                type Subscription = {
                                unsubscribe: () => void;
                                };

                                Package Files (1)

                                Dependencies (3)

                                Dev Dependencies (0)

                                No dev dependencies.

                                Peer Dependencies (0)

                                No peer dependencies.

                                Badge

                                To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@ledgerhq/hw-transport.

                                • Markdown
                                  [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@ledgerhq/hw-transport)
                                • HTML
                                  <a href="https://www.jsdocs.io/package/@ledgerhq/hw-transport"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>