How to use the @ledgerhq/errors.TransportError function in @ledgerhq/errors

To help you get started, we’ve selected a few @ledgerhq/errors 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-webhid / src / TransportWebHID.js View on Github external
const getHID = (): HID => {
  // $FlowFixMe
  const { hid } = navigator;
  if (!hid)
    throw new TransportError(
      "navigator.hid is not supported",
      "HIDNotSupported"
    );
  return hid;
};
github LedgerHQ / ledgerjs / packages / hw-transport-u2f / src / TransportU2F.js View on Github external
function wrapU2FTransportError(originalError, message, id) {
  const err = new TransportError(message, id);
  // $FlowFixMe
  err.originalError = originalError;
  return err;
}
github LedgerHQ / ledgerjs / packages / hw-transport-webauthn / src / TransportWebAuthn.js View on Github external
const attemptExchange = (
  apdu: Buffer,
  timeout: number,
  scrambleKey: ?Buffer
): Promise => {
  if (!scrambleKey) {
    throw new TransportError(
      "transport.setScrambleKey must be used to set a scramble key. Refer to documentation.",
      "NoScrambleKey"
    );
  }

  if (!navigator.credentials) {
    throw new TransportError("WebAuthn not supported", "NotSupported");
  }

  return (
    navigator.credentials
      // $FlowFixMe
      .get({
        publicKey: {
          timeout,
          challenge: new Uint8Array(32),
          allowCredentials: [
            {
              type: "public-key",
              id: new Uint8Array(wrapApdu(apdu, scrambleKey))
            }
          ]
        }
github LedgerHQ / ledgerjs / packages / hw-transport / src / Transport.js View on Github external
send = async (
    cla: number,
    ins: number,
    p1: number,
    p2: number,
    data: Buffer = Buffer.alloc(0),
    statusList: Array = [StatusCodes.OK]
  ): Promise => {
    if (data.length >= 256) {
      throw new TransportError(
        "data.length exceed 256 bytes limit. Got: " + data.length,
        "DataLengthTooBig"
      );
    }
    const response = await this.exchange(
      Buffer.concat([
        Buffer.from([cla, ins, p1, p2]),
        Buffer.from([data.length]),
        data
      ])
    );
    const sw = response.readUInt16BE(response.length - 2);
    if (!statusList.some(s => s === sw)) {
      throw new TransportStatusError(sw);
    }
    return response;
github LedgerHQ / ledgerjs / packages / hw-transport-web-ble / src / receiveAPDU.js View on Github external
complete: () => {
        o.error(new TransportError("Disconnected", "Disconnected"));
        sub.unsubscribe();
      },
      error: e => {
github LedgerHQ / ledgerjs / packages / hw-transport / src / Transport.js View on Github external
? setTimeout(() => {
            sub.unsubscribe();
            reject(
              new TransportError(
                this.ErrorMessage_ListenTimeout,
                "ListenTimeout"
              )
            );
          }, listenTimeout)
        : null;
github LedgerHQ / ledgerjs / packages / hw-transport-node-ble / src / platform.js View on Github external
export const retrieveServiceAndCharacteristics = async (device: *) => {
  const [service] = await discoverDeviceServices(device);
  const infos = getInfosForServiceUuid(service.uuid);
  if (!infos) {
    throw new TransportError("service not found", "BLEServiceNotFound");
  }
  const characteristics = await discoverServiceCharacteristics(service);
  let writeC;
  let notifyC;
  for (const c of characteristics) {
    if (c.uuid === infos.writeUuid.replace(/-/g, "")) {
      writeC = c;
    } else if (c.uuid === infos.notifyUuid.replace(/-/g, "")) {
      notifyC = c;
    }
  }
  if (!writeC || !notifyC) {
    throw new TransportError(
      "missing characteristics",
      "BLEMissingCharacteristics"
    );
github LedgerHQ / ledgerjs / packages / hw-transport-web-ble / src / receiveAPDU.js View on Github external
notifiedIndex,
              "InvalidSequence"
            )
          );
          return;
        }

        if (index === 0) {
          notifiedDataLength = data.readUInt16BE(0);
          data = data.slice(2);
        }
        notifiedIndex++;
        notifiedData = Buffer.concat([notifiedData, data]);
        if (notifiedData.length > notifiedDataLength) {
          o.error(
            new TransportError(
              "BLE: received too much data. discontinued chunk. Received " +
                notifiedData.length +
                " but expected " +
                notifiedDataLength,
              "BLETooMuchData"
            )
          );
          return;
        }
        if (notifiedData.length === notifiedDataLength) {
          o.next(notifiedData);
          o.complete();
          sub.unsubscribe();
        }
      }
    });
github LedgerHQ / ledgerjs / packages / hw-transport-http / src / WebSocketTransport.js View on Github external
socket.onmessage = e => {
          if (typeof e.data !== "string") return;
          const data = JSON.parse(e.data);
          switch (data.type) {
            case "opened":
              return resolve(exchangeMethods);
            case "error":
              reject(new Error(data.error));
              return exchangeMethods.rejectExchange(
                new TransportError(data.error, "WSError")
              );
            case "response":
              return exchangeMethods.resolveExchange(
                Buffer.from(data.data, "hex")
              );
          }
        };
      } catch (e) {
github LedgerHQ / ledgerjs / packages / hw-transport-web-ble / src / 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]);