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

To help you get started, we’ve selected a few @ledgerhq/hw-transport-mocker 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-http-proxy-devserver / src / cmd.js View on Github external
let Transport;
let saveToFile = null;
let recordStore;

const log = mainOptions.silent ? () => {} : (...args) => console.log(...args);

// --mock 
// There are two ways to use the mock, either you record or you replay
// - record means that it's a decoration in node-hid that will just save to a file
// - replay means that it's going to re-use a recorded file and mock a transport instead of using an actual device
// replay mode is the default unless environment RECORD_APDU_TO_FILE is defined, this allow to easily replay tests in record mode.
if (mainOptions.file) {
  if (process.env.RECORD_APDU_TO_FILE) {
    log(`the APDUs will be recorded in ${mainOptions.file}`);
    saveToFile = mainOptions.file;
    recordStore = new RecordStore([]);
    Transport = createTransportRecorder(
      require("@ledgerhq/hw-transport-node-hid").default,
      recordStore
    );
  } else {
    recordStore = RecordStore.fromString(
      fs.readFileSync(mainOptions.file, "utf8")
    );
    if (recordStore.isEmpty()) {
      process.exit(0);
    }
    log(
      `${recordStore.queue.length} mocked APDUs will be replayed from ${mainOptions.file}`
    );
    Transport = createTransportReplayer(recordStore);
  }
github LedgerHQ / ledger-live-common / cli / src / commands / proxy.js View on Github external
const getTransportLike = () => {
      return {
        open: () => open(device || ""),
        create: () => open(device || "")
      };
    };

    // --file 
    // There are two ways to use the mock, either you record or you replay
    // record: using --record means that it's a decoration in node-hid that will just save to a file
    // replay: without --record, it's going to re-use a recorded file and mock a transport instead of using an actual device
    if (file) {
      if (record) {
        log("proxy", `the APDUs will be recorded in ${file}`);
        saveToFile = file;
        recordStore = new RecordStore([]);
        Transport = createTransportRecorder(getTransportLike(), recordStore);
      } else {
        recordStore = RecordStore.fromString(fs.readFileSync(file, "utf8"));
        if (recordStore.isEmpty()) {
          process.exit(0);
        }
        log(
          "proxy",
          `${recordStore.queue.length} mocked APDUs will be replayed from ${file}`
        );
        Transport = createTransportReplayer(recordStore);
      }
    } else {
      Transport = getTransportLike();
    }

@ledgerhq/hw-transport-mocker

Ledger Hardware Wallet mocker utilities used for tests

MIT
Latest version published 12 days ago

Package Health Score

84 / 100
Full package analysis