How to use the @ledgerhq/hw-transport.TransportError function in @ledgerhq/hw-transport

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 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);
  }
github LedgerHQ / ledger-live-mobile / src / react-native-hw-transport-ble / monitorCharacteristic.js View on Github external
const subscription = characteristic.monitor((error, c) => {
      if (error) {
        logSubject.next({
          type: "verbose",
          message: "error monitor " + characteristic.uuid + ": " + error,
        });
        o.error(error);
      } else if (!c) {
        o.error(
          new TransportError(
            "characteristic monitor null value",
            "CharacteristicMonitorNull",
          ),
        );
      } else {
        try {
          const value = Buffer.from(c.value, "base64");
          o.next(value);
        } catch (error) {
          o.error(error);
        }
      }
    });
github LedgerHQ / ledger-live-mobile / src / react-native-hw-transport-ble / receiveAPDU.js View on Github external
next: value => {
        const tag = value.readUInt8(0);
        const index = value.readUInt16BE(1);
        let data = value.slice(3);

        if (tag !== TagId) {
          o.error(
            new TransportError("Invalid tag " + tag.toString(16), "InvalidTag"),
          );
          return;
        }

        if (notifiedIndex !== index) {
          o.error(
            new TransportError(
              "BLE: Invalid sequence number. discontinued chunk. Received " +
                index +
                " but expected " +
                notifiedIndex,
              "InvalidSequence",
            ),
          );
          return;
        }

        if (index === 0) {
          notifiedDataLength = data.readUInt16BE(0);
          data = data.slice(2);
        }
        notifiedIndex++;
        notifiedData = Buffer.concat([notifiedData, data]);
github LedgerHQ / ledger-live-mobile / src / react-native-hw-transport-ble / BleTransport.js View on Github external
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",
      );
    }
    if (!notifyC.isNotifiable) {
      throw new TransportError(
        "notify characteristic not notifiable",
        "BLEChracteristicInvalid",
      );
    }
github LedgerHQ / ledgerjs / packages / react-native-hw-transport-ble / src / index.js View on Github external
}
    */
    const characteristics = await device.characteristicsForService(ServiceUuid);
    if (!characteristics) {
      throw new TransportError("service not found", "BLEServiceNotFound");
    }
    let writeC, 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"
      );
    }