How to use @ledgerhq/errors - 10 common examples

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 / ledger-live-common / src / families / bitcoin / test-dataset.js View on Github external
name: "on segwit recipient",
              transaction: fromTransactionRaw({
                family: "bitcoin",
                recipient: "34N7XoKANmM66ZQDyQf2j8hPaTo6v5X8eA",
                amount: "998",
                feePerByte: "1",
                networkInfo
              }),
              expectedStatus: {
                amount: BigNumber("998"),
                // FIXME fee are reloaded?
                // estimatedFees: BigNumber("250"),
                // totalSpent: BigNumber("1248"),
                errors: {},
                warnings: {
                  feeTooHigh: new FeeTooHigh()
                }
              }
            },
            {
              name: "on native segwit recipient",
              transaction: fromTransactionRaw({
                family: "bitcoin",
                recipient: "bc1qqmxqdrkxgx6swrvjl9l2e6szvvkg45all5u4fl",
                amount: "997",
                feePerByte: "1",
                networkInfo
              }),
              expectedStatus: {
                amount: BigNumber("997"),
                // FIXME fee are reloaded?
                // estimatedFees: BigNumber("250"),
github LedgerHQ / ledger-live-common / src / families / tezos / test-dataset.js View on Github external
{
          raw: accountTZnew,
          test: (expect, account) => {
            expect(account.operations).toEqual([]);
          },
          transactions: [
            {
              name: "send 10% to existing tz",
              transaction: t => ({
                ...t,
                recipient: addressTZregular,
                useAllAmount: true
              }),
              expectedStatus: {
                errors: {
                  amount: new NotEnoughBalance()
                },
                warnings: {}
              }
            }
          ]
        }

        // FIXME libcore bugs
        /*
        {
          raw: accountTZwithKT,
          transactions: [
            {
              name: "from KT 1, send max to new account",
              transaction: (t, account) => (
                invariant(account.subAccounts, "subAccounts"),
github LedgerHQ / ledger-live-common / src / families / bitcoin / test-specifics.js View on Github external
};
      let status = await bridge.getTransactionStatus(account, t);
      expect(status.errors.recipient).toBeUndefined();
      expect(status.errors.feePerByte).toEqual(new FeeNotLoaded());
      t = await bridge.prepareTransaction(account, t);
      expect(t.feePerByte).toBeInstanceOf(BigNumber);
      t.feePerByte = BigNumber(1); // for predictible tests
      status = await bridge.getTransactionStatus(account, t);
      expect(status.errors.feePerByte).toBeUndefined();
      t = {
        ...t,
        feePerByte: BigNumber(0)
      };
      t = await bridge.prepareTransaction(account, t);
      status = await bridge.getTransactionStatus(account, t);
      expect(status.errors.feePerByte).toEqual(new FeeRequired());
    });
github LedgerHQ / ledgerjs / packages / hw-transport-web-ble / src / TransportWebBLE.js View on Github external
log("ble-frame", "<= " + value.toString("hex"));
    }),
    share()
  );

  const notif = notifyObservable.subscribe();

  const transport = new BluetoothTransport(
    device,
    writeC,
    notifyObservable,
    deviceModel
  );

  if (!device.gatt.connected) {
    throw new DisconnectedDevice();
  }

  // eslint-disable-next-line require-atomic-updates
  transportsCache[transport.id] = transport;
  const onDisconnect = e => {
    console.log("onDisconnect!", e);
    delete transportsCache[transport.id];
    transport.notYetDisconnected = false;
    notif.unsubscribe();
    device.removeEventListener("gattserverdisconnected", onDisconnect);
    log("ble-verbose", `BleTransport(${transport.id}) disconnected`);
    transport.emit("disconnect", e);
  };
  device.addEventListener("gattserverdisconnected", onDisconnect);

  let beforeMTUTime = Date.now();
github LedgerHQ / ledger-live-desktop / src / hw-transport-node-ble / src / TransportNodeBLE.js View on Github external
tap(value => {
      logSubject.next({
        type: 'ble-frame-read',
        message: value.toString('hex'),
      })
    }),
    share(),
  )

  const notif = notifyObservable.subscribe()
  const deviceModel = null // FIXME

  const transport = new BluetoothTransport(device, writeC, notifyObservable, deviceModel)

  if (device.state === 'disconnected') {
    throw new DisconnectedDevice()
  }

  transportsCache[transport.id] = transport
  const onDisconnect = e => {
    delete transportsCache[transport.id]
    transport.notYetDisconnected = false
    notif.unsubscribe()
    device.removeListener('disconnect', onDisconnect)
    logSubject.next({
      type: 'verbose',
      message: `BleTransport(${transport.id}) disconnected`,
    })
    transport.emit('disconnect', e)
  }
  device.addListener('disconnect', onDisconnect) // will it catch their own "on" events? peripheral.once('disconnect', callback);
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;
        log("hid-verbose", "transport instance was disconnected");
github LedgerHQ / ledger-live-mobile / src / context / AuthPass / AuthScreen.js View on Github external
submit = async () => {
    const id = ++this.submitId;
    const { password } = this.state;
    const { unlock } = this.props;
    if (!password) return;
    try {
      const credentials = await Keychain.getGenericPassword();
      if (id !== this.submitId) return;
      if (credentials && credentials.password === password) {
        unlock();
      } else if (credentials) {
        Vibration.vibrate(VIBRATION_PATTERN_ERROR);
        this.setState({
          passwordError: new PasswordIncorrectError(),
          password: "",
        });
      } else {
        console.log("no credentials stored"); // eslint-disable-line
      }
    } catch (err) {
      if (id !== this.submitId) return;
      console.log("could not load credentials"); // eslint-disable-line
      this.setState({ passwordError: err, password: "" });
    }
  };
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))
            }
          ]
        }