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

To help you get started, we’ve selected a few @ledgerhq/hw-transport 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 DefinitelyTyped / DefinitelyTyped / types / ledgerhq__hw-transport / ledgerhq__hw-transport-tests.ts View on Github external
import Transport from '@ledgerhq/hw-transport';

// $ExpectType Promise
Transport.isSupported();
// $ExpectType Promise>
Transport.list();
// $ExpectType Promise>
Transport.open('test');

const test = Transport.open('test').then(transport => {
    // $ExpectType void
    transport.setScrambleKey('test');

    // $ExpectType Promise
    transport.exchange(Buffer.from('test', 'hex'));

    // $ExpectType Promise
    transport.send(0, 1, 2, 3);
    // $ExpectType Promise
    transport.send(0, 1, 2, 3, Buffer.from('abcd', 'hex'));
    // $ExpectType Promise
    transport.send(0, 1, 2, 3, Buffer.from('abcd', 'hex'), [0x1111, 0x9000]);

    // $ExpectType Promise
github DefinitelyTyped / DefinitelyTyped / types / ledgerhq__hw-transport / ledgerhq__hw-transport-tests.ts View on Github external
import Transport from '@ledgerhq/hw-transport';

// $ExpectType Promise
Transport.isSupported();
// $ExpectType Promise>
Transport.list();
// $ExpectType Promise>
Transport.open('test');

const test = Transport.open('test').then(transport => {
    // $ExpectType void
    transport.setScrambleKey('test');

    // $ExpectType Promise
    transport.exchange(Buffer.from('test', 'hex'));

    // $ExpectType Promise
    transport.send(0, 1, 2, 3);
    // $ExpectType Promise
    transport.send(0, 1, 2, 3, Buffer.from('abcd', 'hex'));
    // $ExpectType Promise
    transport.send(0, 1, 2, 3, Buffer.from('abcd', 'hex'), [0x1111, 0x9000]);

    // $ExpectType Promise
    transport.close();
});
github DefinitelyTyped / DefinitelyTyped / types / ledgerhq__hw-transport / ledgerhq__hw-transport-tests.ts View on Github external
import Transport from '@ledgerhq/hw-transport';

// $ExpectType Promise
Transport.isSupported();
// $ExpectType Promise>
Transport.list();
// $ExpectType Promise>
Transport.open('test');

const test = Transport.open('test').then(transport => {
    // $ExpectType void
    transport.setScrambleKey('test');

    // $ExpectType Promise
    transport.exchange(Buffer.from('test', 'hex'));

    // $ExpectType Promise
    transport.send(0, 1, 2, 3);
    // $ExpectType Promise
    transport.send(0, 1, 2, 3, Buffer.from('abcd', 'hex'));
github DefinitelyTyped / DefinitelyTyped / types / ledgerhq__hw-transport / ledgerhq__hw-transport-tests.ts View on Github external
import Transport from '@ledgerhq/hw-transport';

// $ExpectType Promise
Transport.isSupported();
// $ExpectType Promise>
Transport.list();
// $ExpectType Promise>
Transport.open('test');

const test = Transport.open('test').then(transport => {
    // $ExpectType void
    transport.setScrambleKey('test');

    // $ExpectType Promise
    transport.exchange(Buffer.from('test', 'hex'));

    // $ExpectType Promise
    transport.send(0, 1, 2, 3);
    // $ExpectType Promise
    transport.send(0, 1, 2, 3, Buffer.from('abcd', 'hex'));
    // $ExpectType Promise
    transport.send(0, 1, 2, 3, Buffer.from('abcd', 'hex'), [0x1111, 0x9000]);
github LedgerHQ / ledgerjs / packages / react-native-hw-transport-ble / src / index.js View on Github external
bleManager.startDeviceScan(null, null, (bleError, device) => {
          if (bleError) {
            observer.error(bleError);
            unsubscribe();
            return;
          }
          // FIXME this is not the final filtering. we should eventually use the serviceUUIDs
          if (device.name === "Blue" || device.id === "3A:11:99:A9:08:C4") {
            observer.next({ type: "add", descriptor: device });
          }
        });
        if (sub) sub.remove();
      } else if (state === "Unsupported") {
        unsubscribe();
        observer.error(
          new TransportError(
            "Bluetooth BLE is not supported",
            "BLENotSupported"
          )
        );
      }
    };
    const sub = bleManager.onStateChange(onBleStateChange, true);
github LedgerHQ / ledgerjs / packages / react-native-hw-transport-ble / src / index.js View on Github external
subscription = characteristic.monitor((error, c) => {
      if (error) return reject(error);
      try {
        const value = Buffer.from(c.value, "base64");
        if (debug) {
          console.log("<=", value.toString("hex"));
        }
        const tag = value.readUInt8(0);
        const index = value.readUInt16BE(1);
        let data = value.slice(3);

        if (tag !== TagId) {
          throw new TransportError(
            "Invalid tag " + tag.toString(16),
            "InvalidTag"
          );
        }
        if (notifiedIndex !== index) {
          throw new TransportError(
            "BLE: Invalid sequence number. discontinued chunk. Received " +
              index +
              " but expected " +
              notifiedIndex,
            "InvalidSequence"
          );
        }
        if (index === 0) {
          notifiedDataLength = data.readUInt16BE(0);
          data = data.slice(2);
github LedgerHQ / ledgerjs / packages / react-native-hw-transport-ble / src / index.js View on Github external
const value = Buffer.from(c.value, "base64");
        if (debug) {
          console.log("<=", value.toString("hex"));
        }
        const tag = value.readUInt8(0);
        const index = value.readUInt16BE(1);
        let data = value.slice(3);

        if (tag !== TagId) {
          throw new TransportError(
            "Invalid tag " + tag.toString(16),
            "InvalidTag"
          );
        }
        if (notifiedIndex !== index) {
          throw new TransportError(
            "BLE: Invalid sequence number. discontinued chunk. Received " +
              index +
              " but expected " +
              notifiedIndex,
            "InvalidSequence"
          );
        }
        if (index === 0) {
          notifiedDataLength = data.readUInt16BE(0);
          data = data.slice(2);
        }
        notifiedIndex++;
        notifiedData = Buffer.concat([notifiedData, data]);
        if (notifiedData.length > notifiedDataLength) {
          throw new TransportError(
            "BLE: received too much data. discontinued chunk. Received " +
github LedgerHQ / ledger-live-mobile / src / react-native-hw-transport-ble / BleTransport.js View on Github external
const characteristics = await device.characteristicsForService(ServiceUuid);
    if (!characteristics) {
      throw new TransportError("service not found", "BLEServiceNotFound");
    }
    let writeC;
    let notifyC;
    for (const c of characteristics) {
      if (c.uuid === WriteCharacteristicUuid) {
        writeC = c;
      } else if (c.uuid === NotifyCharacteristicUuid) {
        notifyC = c;
      }
    }
    if (!writeC) {
      throw new TransportError(
        "write characteristic not found",
        "BLEChracteristicNotFound",
      );
    }
    if (!notifyC) {
      throw new TransportError(
        "notify characteristic not found",
        "BLEChracteristicNotFound",
      );
    }
    if (!writeC.isWritableWithResponse) {
      throw new TransportError(
        "write characteristic not writableWithResponse",
        "BLEChracteristicInvalid",
      );
    }
github LedgerHQ / ledger-live-mobile / src / react-native-hw-transport-ble / BleTransport.js View on Github external
}
    }
    if (!writeC) {
      throw new TransportError(
        "write characteristic not found",
        "BLEChracteristicNotFound",
      );
    }
    if (!notifyC) {
      throw new TransportError(
        "notify characteristic not found",
        "BLEChracteristicNotFound",
      );
    }
    if (!writeC.isWritableWithResponse) {
      throw new TransportError(
        "write characteristic not writableWithResponse",
        "BLEChracteristicInvalid",
      );
    }
    if (!notifyC.isNotifiable) {
      throw new TransportError(
        "notify characteristic not notifiable",
        "BLEChracteristicInvalid",
      );
    }

    logSubject.next({ type: "verbose", message: `device.mtu=${device.mtu}` });

    const notifyObservable = monitorCharacteristic(notifyC).pipe(
      tap(value => {
        logSubject.next({
github LedgerHQ / ledgerjs / packages / react-native-hw-transport-ble / src / index.js View on Github external
}
    }
    if (!writeC) {
      throw new TransportError(
        "write characteristic not found",
        "BLEChracteristicNotFound"
      );
    }
    if (!notifyC) {
      throw new TransportError(
        "notify characteristic not found",
        "BLEChracteristicNotFound"
      );
    }
    if (!writeC.isWritableWithResponse) {
      throw new TransportError(
        "write characteristic not writableWithResponse",
        "BLEChracteristicInvalid"
      );
    }
    if (!notifyC.isNotifiable) {
      throw new TransportError(
        "notify characteristic not notifiable",
        "BLEChracteristicInvalid"
      );
    }
    return new BluetoothTransport(device, writeC, notifyC);
  }