How to use @ledgerhq/logs - 10 common examples

To help you get started, we’ve selected a few @ledgerhq/logs 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 / BleTransport.js View on Github external
device = await bleManager.connectToDevice(deviceOrId);
        } else {
          throw e;
        }
      }
    }

    if (!device) {
      throw new CantOpenDevice();
    }
  } else {
    device = deviceOrId;
  }

  if (!(await device.isConnected())) {
    log("ble-verbose", "not connected. connecting...");
    try {
      await device.connect(connectOptions);
    } catch (e) {
      if (e.errorCode === BleErrorCode.DeviceMTUChangeFailed) {
        // eslint-disable-next-line require-atomic-updates
        connectOptions = {};
        await device.connect();
      } else {
        throw e;
      }
    }
  }

  await device.discoverAllServicesAndCharacteristics();

  let res = retrieveInfos(device);
github LedgerHQ / ledgerjs / packages / react-native-hw-transport-ble / src / BleTransport.js View on Github external
if (!device) {
      // works for iOS but not Android
      const devices = await bleManager.devices([deviceOrId]);
      log("ble-verbose", `found ${devices.length} devices`);
      [device] = devices;
    }

    if (!device) {
      const connectedDevices = await bleManager.connectedDevices(
        getBluetoothServiceUuids()
      );
      const connectedDevicesFiltered = connectedDevices.filter(
        d => d.id === deviceOrId
      );
      log(
        "ble-verbose",
        `found ${connectedDevicesFiltered.length} connected devices`
      );
      [device] = connectedDevicesFiltered;
    }

    if (!device) {
      log("ble-verbose", `connectToDevice(${deviceOrId})`);
      try {
        device = await bleManager.connectToDevice(deviceOrId, connectOptions);
      } catch (e) {
        if (e.errorCode === BleErrorCode.DeviceMTUChangeFailed) {
          // eslint-disable-next-line require-atomic-updates
          connectOptions = {};
          device = await bleManager.connectToDevice(deviceOrId);
        } else {
github LedgerHQ / ledgerjs / packages / hw-transport-webhid / src / TransportWebHID.js View on Github external
this.exchangeAtomicImpl(async () => {
      const { channel, packetSize } = this;
      log("apdu", "=> " + apdu.toString("hex"));

      const framing = hidFraming(channel, packetSize);

      // Write...
      const blocks = framing.makeBlocks(apdu);
      for (let i = 0; i < blocks.length; i++) {
        log("hid-frame", "=> " + blocks[i].toString("hex"));
        await this.device.sendReport(0, blocks[i]);
      }

      // Read...
      let result;
      let acc;
      while (!(result = framing.getReducedResult(acc))) {
        const buffer = await this.read();
        log("hid-frame", "<= " + buffer.toString("hex"));
        acc = framing.reduceResponse(acc, buffer);
      }

      log("apdu", "<= " + result.toString("hex"));
      return result;
    }).catch(e => {
      if (e && e.message && e.message.includes("write")) {
github LedgerHQ / ledger-live-desktop / src / helpers / reset.js View on Github external
async function resetLibcore() {
  log('clear-cache', 'resetLibcore...')
  // we need to stop everything that is happening right now, like syncs
  await killInternalProcess()
  log('clear-cache', 'killed.')

  await removeSQLite()
  log('clear-cache', 'removeSQLite done.')
}
github LedgerHQ / ledger-live-desktop / src / helpers / reset.js View on Github external
async function resetLibcore() {
  log('clear-cache', 'resetLibcore...')
  // we need to stop everything that is happening right now, like syncs
  await killInternalProcess()
  log('clear-cache', 'killed.')

  await removeSQLite()
  log('clear-cache', 'removeSQLite done.')
}
github LedgerHQ / ledgerjs / packages / hw-transport-node-hid-noevents / src / TransportNodeHid.js View on Github external
const framing = hidFraming(channel, packetSize);

      // Write...
      const blocks = framing.makeBlocks(apdu);
      for (let i = 0; i < blocks.length; i++) {
        log("hid-frame", "=> " + blocks[i].toString("hex"));
        await this.writeHID(blocks[i]);
      }

      // Read...
      let result;
      let acc;
      while (!(result = framing.getReducedResult(acc))) {
        const buffer = await this.readHID();
        log("hid-frame", "<= " + buffer.toString("hex"));
        acc = framing.reduceResponse(acc, buffer);
      }

      log("apdu", "<= " + result.toString("hex"));
      return result;
    });
github LedgerHQ / ledger-live-common / src / libcore / access.js View on Github external
async function load(): Promise {
  if (core) {
    return core;
  }
  if (!corePromise) {
    if (!loadCoreImpl) {
      console.warn("loadCore implementation is missing");
      throw new Error("loadCoreImpl missing");
    }
    log("libcore/access", "load core impl");
    corePromise = loadCoreImpl();
  }
  core = await corePromise;
  return core;
}
github LedgerHQ / ledger-live-desktop / src / helpers / reset.js View on Github external
export async function softReset({ cleanAccountsCache }: *) {
  log('clear-cache', 'clearBridgeCache()')
  clearBridgeCache()
  log('clear-cache', 'cleanAccountsCache()')
  cleanAccountsCache()
  await delay(500)
  log('clear-cache', 'db.cleanCache()')
  await db.cleanCache()
  await resetLibcore()
  log('clear-cache', 'reload()')
  reload()
}
github LedgerHQ / ledgerjs / packages / hw-transport-web-ble / src / TransportWebBLE.js View on Github external
write = async (buffer: Buffer) => {
    log("ble-frame", "=> " + buffer.toString("hex"));
    await this.writeCharacteristic.writeValue(buffer);
  };
github LedgerHQ / ledger-live-common / src / libcore / access.js View on Github external
export async function reset() {
  log("libcore/access", "reset");
  if (!core) return;
  invariant(libcoreJobsCounter === 0, "some libcore jobs are still running");
  await core.getPoolInstance().freshResetAll();
  core = null;
  corePromise = null;
}

@ledgerhq/logs

Ledger logs central point

MIT
Latest version published 1 year ago

Package Health Score

78 / 100
Full package analysis

Popular @ledgerhq/logs functions