How to use @ledgerhq/hw-transport-node-hid-noevents - 10 common examples

To help you get started, we’ve selected a few @ledgerhq/hw-transport-node-hid-noevents examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LedgerHQ / ledgerjs / packages / hw-transport-node-hid-singleton / src / TransportNodeHid.js View on Github external
return Promise.resolve().then(() => {
      if (transportInstance) {
        log("hid-verbose", "reusing opened transport instance");
        return transportInstance;
      }

      const device = getDevices()[0];
      if (!device) throw new CantOpenDevice("no device found");
      log("hid-verbose", "new HID transport");
      transportInstance = new TransportNodeHidSingleton(
        new HID.HID(device.path)
      );
      const unlisten = listenDevices(
        () => {},
        () => {
          // assume any ledger disconnection concerns current transport
          if (transportInstance) {
            transportInstance.emit("disconnect");
          }
        }
      );
      const onDisconnect = () => {
        if (!transportInstance) return;
github LedgerHQ / ledgerjs / packages / hw-transport-node-hid-singleton / src / TransportNodeHid.js View on Github external
static listen = (observer: Observer>): Subscription => {
    let unsubscribed;
    Promise.resolve(getDevices()).then(devices => {
      // this needs to run asynchronously so the subscription is defined during this phase
      for (const device of devices) {
        if (!unsubscribed) {
          const deviceModel = identifyUSBProductId(device.productId);
          observer.next({
            type: "add",
            descriptor: "",
            device: { name: device.deviceName },
            deviceModel
          });
        }
      }
    });

    const onAdd = device => {
      const deviceModel = identifyUSBProductId(device.productId);
github LedgerHQ / ledgerjs / packages / hw-transport-node-hid / src / TransportNodeHid.js View on Github external
static listen = (
    observer: Observer>
  ): Subscription => {
    let unsubscribed = false;
    Promise.resolve(getDevices()).then(devices => {
      // this needs to run asynchronously so the subscription is defined during this phase
      for (const device of devices) {
        if (!unsubscribed) {
          const descriptor: string = device.path;
          const deviceModel = identifyUSBProductId(device.productId);
          observer.next({ type: "add", descriptor, device, deviceModel });
        }
      }
    });
    const { events, stop } = listenDevices(
      listenDevicesDebounce,
      listenDevicesPollingSkip
    );

    const onAdd = device => {
      if (unsubscribed || !device) return;
github LedgerHQ / ledgerjs / packages / hw-transport-node-hid-singleton / src / TransportNodeHid.js View on Github external
import { listenDevices } from "./listenDevices";

let transportInstance;

/**
 * node-hid Transport implementation
 * @example
 * import TransportNodeHid from "@ledgerhq/hw-transport-node-hid-singleton";
 * ...
 * TransportNodeHid.create().then(transport => ...)
 */
export default class TransportNodeHidSingleton extends TransportNodeHidNoEvents {
  /**
   *
   */
  static isSupported = TransportNodeHidNoEvents.isSupported;

  /**
   *
   */
  static list = TransportNodeHidNoEvents.list;

  /**
   */
  static listen = (observer: Observer>): Subscription => {
    let unsubscribed;
    Promise.resolve(getDevices()).then(devices => {
      // this needs to run asynchronously so the subscription is defined during this phase
      for (const device of devices) {
        if (!unsubscribed) {
          const deviceModel = identifyUSBProductId(device.productId);
          observer.next({
github LedgerHQ / ledgerjs / packages / hw-transport-node-hid-singleton / src / TransportNodeHid.js View on Github external
* node-hid Transport implementation
 * @example
 * import TransportNodeHid from "@ledgerhq/hw-transport-node-hid-singleton";
 * ...
 * TransportNodeHid.create().then(transport => ...)
 */
export default class TransportNodeHidSingleton extends TransportNodeHidNoEvents {
  /**
   *
   */
  static isSupported = TransportNodeHidNoEvents.isSupported;

  /**
   *
   */
  static list = TransportNodeHidNoEvents.list;

  /**
   */
  static listen = (observer: Observer>): Subscription => {
    let unsubscribed;
    Promise.resolve(getDevices()).then(devices => {
      // this needs to run asynchronously so the subscription is defined during this phase
      for (const device of devices) {
        if (!unsubscribed) {
          const deviceModel = identifyUSBProductId(device.productId);
          observer.next({
            type: "add",
            descriptor: "",
            device: { name: device.deviceName },
            deviceModel
          });
github LedgerHQ / ledgerjs / packages / hw-transport-node-hid / src / listenDevices.js View on Github external
const poll = () => {
    if (!listenDevicesPollingSkip()) {
      log("hid-listen", "Polling for added or removed devices");

      let changeFound = false;
      const currentDevices = getFlatDevices();
      const newDevices = currentDevices.filter(d => !lastDevices.includes(d));

      if (newDevices.length > 0) {
        log("hid-listen", "New device found:", newDevices);

        listDevices = getDevices();
        events.emit("add", getDeviceByPaths(newDevices));

        changeFound = true;
      } else {
        log("hid-listen", "No new device found");
      }

      const removeDevices = lastDevices.filter(
        d => !currentDevices.includes(d)
      );

      if (removeDevices.length > 0) {
        log("hid-listen", "Removed device found:", removeDevices);

        events.emit("remove", getDeviceByPaths(removeDevices));
        listDevices = listDevices.filter(
github LedgerHQ / ledgerjs / packages / hw-transport-node-hid / src / TransportNodeHid.js View on Github external
return Promise.resolve().then(() => {
      if (path) {
        return new TransportNodeHid(new HID.HID(path));
      }
      const device = getDevices()[0];
      if (!device) throw new TransportError("NoDevice", "NoDevice");
      return new TransportNodeHid(new HID.HID(device.path));
    });
  }
github LedgerHQ / ledgerjs / packages / hw-transport-node-hid / src / listenDevices.js View on Github external
export default (
  delay: number,
  listenDevicesPollingSkip: () => boolean
): ({
  events: EventEmitter,
  stop: () => void
}) => {
  const events = new EventEmitter();
  events.setMaxListeners(0);

  let listDevices = getDevices();

  const flatDevice = d => d.path;

  const getFlatDevices = () => [
    ...new Set(getDevices().map(d => flatDevice(d)))
  ];

  const getDeviceByPaths = paths =>
    listDevices.find(d => paths.includes(flatDevice(d)));

  let lastDevices = getFlatDevices();

  const poll = () => {
    if (!listenDevicesPollingSkip()) {
      log("hid-listen", "Polling for added or removed devices");
github LedgerHQ / ledgerjs / packages / hw-transport-node-hid / src / listenDevices.js View on Github external
const getFlatDevices = () => [
    ...new Set(getDevices().map(d => flatDevice(d)))
  ];
github MyCryptoHQ / MyCrypto / shared / enclave / server / wallets / ledger.ts View on Github external
async function getEthApp() {
  try {
    if (!transport) {
      transport = await TransportNodeHid.create();
      transport.on('disconnect', () => (transport = null));
    }
    return new LedgerEth(transport);
  } catch (err) {
    if (err && err.name === 'TransportError') {
      throw new Error('ENCLAVE_LEDGER_IN_USE');
    }
    if (err && err.message && err.message.includes('cannot open device with path')) {
      throw new Error('ENCLAVE_LEDGER_IN_USE');
    }
    throw err;
  }
}

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

Ledger Hardware Wallet Node implementation of the communication layer, using node-hid. without usb events

MIT
Latest version published 3 months ago

Package Health Score

90 / 100
Full package analysis