How to use @ledgerhq/hw-app-eth - 10 common examples

To help you get started, we’ve selected a few @ledgerhq/hw-app-eth 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 cryppadotta / dotta-license / dot-abi-cli / bin / test-ledger-address.js View on Github external
const getAddress = async () => {
  console.log('Testing Ledger Hardware...');
  console.log('supported:', await Transport.isSupported());
  console.log('Devices:');
  console.log(await Transport.list());
  const transport = await Transport.create();
  const eth = new AppEth(transport);

  // note: this path matches MEWs: m/44'/60'/0'
  const result = await eth.getAddress("m/44'/60'/0'/0");
  return result;
};
getAddress().then(a => console.log(a));
github cryppadotta / dotta-license / dotlicense-cli / lib / experiments / get-ledger-address.js View on Github external
const getAddress = async () => {
  console.log('Testing Ledger Hardware...');
  console.log('supported:', await Transport.isSupported());
  console.log('Devices:');
  console.log(await Transport.list());
  const transport = await Transport.create();
  const eth = new AppEth(transport);

  // note: this path matches MEWs: m/44'/60'/0'
  const result = await eth.getAddress("m/44'/60'/0'/0");
  return result;
};
getAddress().then(a => console.log(a));
github unstoppabledomains / browseth / src / signers / ledger.ts View on Github external
public async initialize(): Promise<{app: AppEth; close(): void}> {
    if (!Ledger.allowParallel && Ledger.initialized) {
      throw new Error('another ledger wallet call is already initialized');
    }

    Ledger.initialized = true;
    const transport = await Ledger.Transport.create();

    // transport.setDebugMode(true);
    return {
      app: new AppEth(transport),
      close: () => {
        Ledger.initialized = false;
        transport.close();
      },
    };
  }
github LedgerHQ / ledgerjs / packages / web3-subprovider / src / index.js View on Github external
async function signTransaction(txData) {
    const path = addressToPathMap[txData.from.toLowerCase()];
    if (!path) throw new Error("address unknown '" + txData.from + "'");
    const transport = await getTransport();
    try {
      const eth = new AppEth(transport);
      const tx = new EthereumTx(txData);

      // Set the EIP155 bits
      tx.raw[6] = Buffer.from([networkId]); // v
      tx.raw[7] = Buffer.from([]); // r
      tx.raw[8] = Buffer.from([]); // s

      // Pass hex-rlp to ledger for signing
      const result = await eth.signTransaction(
        path,
        tx.serialize().toString("hex")
      );

      // Store signature in transaction
      tx.v = Buffer.from(result.v, "hex");
      tx.r = Buffer.from(result.r, "hex");
github MyCryptoHQ / MyCrypto / common / v2 / services / WalletService / deterministic / ledger.ts View on Github external
public async signRawTransaction(t: EthTx): Promise {
    const txFields = getTransactionFields(t);
    t.v = toBuffer(t.getChainId());
    t.r = toBuffer(0);
    t.s = toBuffer(0);

    try {
      const ethApp = await makeApp();

      if (t.getChainId() === 1) {
        const tokenInfo = byContractAddress(t.to.toString('hex'));
        if (tokenInfo) {
          await ethApp.provideERC20TokenInformation(tokenInfo);
        }
      }

      const result = await ethApp.signTransaction(this.getPath(), t.serialize().toString('hex'));

      let v = result.v;
      if (t.getChainId() > 0) {
        // EIP155 support. check/recalc signature v value.
        // Please see https://github.com/LedgerHQ/blue-app-eth/commit/8260268b0214810872dabd154b476f5bb859aac0
        // currently, ledger returns only 1-byte truncated signatur_v
        const rv = parseInt(v, 16);
        let cv = t.getChainId() * 2 + 35; // calculated signature v, without signature bit.
        /* tslint:disable no-bitwise */
        if (rv !== cv && (rv & cv) !== rv) {
github LedgerHQ / ledger-live-common / src / families / ethereum / libcore-signOperation.js View on Github external
transaction,
  coreTransaction,
  onDeviceSignatureGranted,
  onDeviceSignatureRequested
}) {
  // sign with device

  const hwApp = new Eth(transport);
  const subAccount =
    transaction.subAccountId && subAccounts
      ? subAccounts.find(t => t.id === transaction.subAccountId)
      : null;

  if (subAccount && subAccount.type === "TokenAccount") {
    const { token } = subAccount;
    const tokenInfo = byContractAddress(token.contractAddress);
    invariant(
      tokenInfo,
      `contract ${token.contractAddress} data for ${token.id} ERC20 not found`
    );
    await hwApp.provideERC20TokenInformation(tokenInfo);
  }

  const serialized = await coreTransaction.serialize();

  onDeviceSignatureRequested();
  const result = await hwApp.signTransaction(freshAddressPath, serialized);
  onDeviceSignatureGranted();

  await coreTransaction.setSignature(result.v, result.r, result.s);
  const signature = await coreTransaction.serialize();
github MyCryptoHQ / MyCrypto / common / libs / wallet / deterministic / ledger.ts View on Github external
public async signRawTransaction(t: EthTx): Promise {
    const txFields = getTransactionFields(t);
    t.v = toBuffer(t._chainId);
    t.r = toBuffer(0);
    t.s = toBuffer(0);

    try {
      const ethApp = await makeApp();

      if (t.getChainId() === 1) {
        const tokenInfo = byContractAddress(t.to.toString('hex'));
        if (tokenInfo) {
          await ethApp.provideERC20TokenInformation(tokenInfo);
        }
      }

      const result = await ethApp.signTransaction(this.getPath(), t.serialize().toString('hex'));

      let v = result.v;
      if (t._chainId > 0) {
        // EIP155 support. check/recalc signature v value.
        // Please see https://github.com/LedgerHQ/blue-app-eth/commit/8260268b0214810872dabd154b476f5bb859aac0
        // currently, ledger returns only 1-byte truncated signatur_v
        const rv = parseInt(v, 16);
        let cv = t._chainId * 2 + 35; // calculated signature v, without signature bit.
        /* tslint:disable no-bitwise */
        if (rv !== cv && (rv & cv) !== rv) {
github MyEtherWallet / MyEtherWallet / src / wallets / hardware / ledger / index.js View on Github external
const txSigner = async tx => {
      tx = new Transaction(tx, {
        common: commonGenerator(store.state.network)
      });
      const networkId = tx.getChainId();
      tx.raw[6] = networkId;
      tx.raw[7] = Buffer.from([]);
      tx.raw[8] = Buffer.from([]);
      const tokenInfo = byContractAddress('0x' + tx.to.toString('hex'));
      if (tokenInfo) await this.ledger.provideERC20TokenInformation(tokenInfo);
      const result = await this.ledger.signTransaction(
        accountPath,
        tx.serialize().toString('hex')
      );

      // EIP155 support. check/recalc signature v value.
      let v = result.v;
      const rv = parseInt(v, 16);
      let cv = networkId * 2 + 35;
      if (rv !== cv && (rv & cv) !== rv) {
        cv += 1; // add signature v bit.
      }
      v = cv.toString(16);

      tx.v = getBufferFromHex(v);
github airswap / AirSwap.js / src / ledger / index.js View on Github external
async function signTransaction(txData) {
    const dPath = addressToPathMap[txData.from]
    if (!dPath) throw new Error(`address unknown '${txData.from}'`)
    const transport = await getTransport()

    try {
      const eth = new AppEth(transport)
      const tx = new EthereumTx(txData)

      // Set the EIP155 bits
      tx.raw[6] = Buffer.from([networkId]) // v
      tx.raw[7] = Buffer.from([]) // r
      tx.raw[8] = Buffer.from([]) // s

      // Pass hex-rlp to ledger for signing
      const result = await eth.signTransaction(dPath, tx.serialize().toString('hex'))

      // Store signature in transaction
      tx.v = Buffer.from(result.v, 'hex')
      tx.r = Buffer.from(result.r, 'hex')
      tx.s = Buffer.from(result.s, 'hex')

      // EIP155: v should be chain_id * 2 + {35, 36}
github LedgerHQ / ledger-live-common / src / __tests__ / helpers / currencies.js View on Github external
test("erc20 are all consistent with those on ledgerjs side", () => {
  const normalList = listTokens();
  const delistedList = listTokens({ withDelisted: true });
  expect(delistedList.length).toBeGreaterThan(normalList.length);
  for (const token of delistedList) {
    if (token.delisted) {
      expect(normalList.find(o => o.id === token.id)).toBeUndefined();
    }
    if (token.tokenType === "erc20") {
      const tokenData = byContractAddress(token.contractAddress);
      if (!tokenData) {
        throw new Error(token.name + " not available in ledgerjs data");
      }
      expect(token.ticker.toLowerCase()).toBe(tokenData.ticker.toLowerCase());
      expect(token.contractAddress.toLowerCase()).toBe(
        tokenData.contractAddress.toLowerCase()
      );
      expect(token.units[0].magnitude).toBe(tokenData.decimals);
    }
  }
});

@ledgerhq/hw-app-eth

Ledger Hardware Wallet Ethereum Application API

MIT
Latest version published 10 days ago

Package Health Score

84 / 100
Full package analysis