How to use the @ledgerhq/hw-app-eth/erc20.byContractAddress function in @ledgerhq/hw-app-eth

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 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 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);
    }
  }
});
github go-faast / faast-web / src / services / Ledger / LedgerEth.ts View on Github external
setERC20ContractAddress(contractAddress: string): Promise {
    const info = byContractAddress(contractAddress)
    if (info) {
      return this.provideERC20TokenInformation(info)
    }
    return Promise.resolve()
  }
}
github LedgerHQ / ledger-live-common / src / families / ethereum / libcore-hw-signTransaction.js View on Github external
transport: Transport<*>,
  account: Account,
  currency: CryptoCurrency,
  subAccountId: ?string,
  coreCurrency: CoreCurrency,
  coreTransaction: CoreEthereumLikeTransaction
}) {
  const hwApp = new Eth(transport);
  const subAccount = subAccountId
    ? account.subAccounts &&
      account.subAccounts.find(t => t.id === 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 result = await hwApp.signTransaction(
    account.freshAddressPath,
    await coreTransaction.serialize()
  );

  await coreTransaction.setSignature(result.v, result.r, result.s);

  const raw = await coreTransaction.serialize();
github MyCryptoHQ / MyCrypto / shared / enclave / server / wallets / ledger.ts View on Github external
async signTransaction(tx, path) {
    const app = await getEthApp();
    const ethTx = new EthTx({
      ...tx,
      v: Buffer.from([tx.chainId]),
      r: toBuffer(0),
      s: toBuffer(0)
    });

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

    const rsv = await app.signTransaction(path, ethTx.serialize().toString('hex'));
    const signedTx = new EthTx({
      ...tx,
      r: addHexPrefix(rsv.r),
      s: addHexPrefix(rsv.s),
      v: addHexPrefix(rsv.v)
    });
    return {
      signedTransaction: signedTx.serialize().toString('hex')
    };
  },

@ledgerhq/hw-app-eth

Ledger Hardware Wallet Ethereum Application API

MIT
Latest version published 18 days ago

Package Health Score

90 / 100
Full package analysis