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

To help you get started, we’ve selected a few @ledgerhq/hw-app-btc 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-desktop / alix.js View on Github external
waitForDevices(async device => {
  // const accounts = await scanAccountsOnDevice({
  //   devicePath: device.path,
  //   currencyId: 'bitcoin_testnet',
  // })
  // console.log(accounts)
  try {
    console.log(`> Creating transport`)
    const transport = await CommNodeHid.open(device.path)

    // transport.setDebugMode(true)

    console.log(`> Instanciate BTC app`)
    const hwApp = new Btc(transport)

    console.log(`> Get currency`)
    const currency = await getCurrency('bitcoin_testnet')

    console.log(`> Create wallet`)
    const wallet = CREATE ? await createWallet('khalil', currency) : await getWallet('khalil')

    console.log(`> Create account`)
    const account = CREATE ? await createAccount(wallet, hwApp) : await wallet.getAccount(0)

    console.log(`> Sync account`)
    if (CREATE) {
      await syncAccount(account)
    }

    console.log(`> Create transaction`)
github LedgerHQ / ledgerjs / packages / example-node / src / index.js View on Github external
async function example() {
  const transport = await TransportNodeHid.create(5000);
  transport.setDebugMode(true);
  const appBtc = new AppBtc(transport);
  const o = await appBtc.getWalletPublicKey("44'/0'/0'/0");
  console.log("getWalletPublicKey:", o);
}
github LedgerHQ / ledger-live-desktop / alix.js View on Github external
async function scanAccountsOnDevice(props) {
  try {
    const { devicePath, currencyId } = props
    console.log(`get or create wallet`)
    const wallet = await getOrCreateWallet(currencyId)
    console.log(`open device`)
    const transport = await CommNodeHid.open(devicePath)
    console.log(`create app`)
    const hwApp = new Btc(transport)
    console.log(`scan account`)
    const accounts = await scanNextAccount(wallet, hwApp)
    console.log(accounts)
    return []
  } catch (err) {
    console.log(err)
  }
}
github LedgerHQ / ledger-live-mobile / src / screens / ReceiveFunds.js View on Github external
async transport => {
          try {
            transport.setDebugMode(true);
            const btc = new AppBtc(transport);
            const { bitcoinAddress } = await btc.getWalletPublicKey(
              path,
              verify
            );
            this.setState({ address: bitcoinAddress });
          } catch (error) {
            this.setState({ error });
          }
        },
        error => {
github LedgerHQ / ledger-live-desktop / src / helpers / libcore.js View on Github external
const { publicKey, chainCode } = await withDevice(devicePath)(transport =>
          from(new Btc(transport).getWalletPublicKey(derivation)),
        ).toPromise()
github LedgerHQ / ledgerjs / packages / example-browser / index.js View on Github external
onGetLedgerBitcoinAddress = async () => {
    try {
      this.setState({ error: null });
      const transport = await TransportU2F.create();
      const btc = new Btc(transport);
      const { bitcoinAddress } = await btc.getWalletPublicKey("44'/0'/0'/0");
      this.setState({ address: bitcoinAddress });
    } catch (error) {
      this.setState({ error });
    }
  };
  onGetLedgerEthereumAddress = async () => {
github LedgerHQ / ledger-live-common / src / families / bitcoin / hw-getAddress.js View on Github external
const resolver: Resolver = async (
  transport,
  { currency, path, verify, derivationMode, skipAppFailSafeCheck }
) => {
  const btc = new Btc(transport);
  const format = getAddressFormatDerivationMode(derivationMode);
  invariant(
    format === "legacy" || format === "p2sh" || format === "bech32",
    "unsupported format %s",
    format
  );

  const { bitcoinAddress, publicKey, chainCode } = await btc.getWalletPublicKey(
    path,
    {
      verify,
      format
    }
  );

  if (!skipAppFailSafeCheck) {
github LedgerHQ / ledger-live-mobile / src / libcore / scanAccountsOnDevice.js View on Github external
if (isUnsubscribed()) return;

        const derivationModes = getDerivationModesForCurrency(currency);
        for (let i = 0; i < derivationModes.length; i++) {
          const derivationMode = derivationModes[i];

          const isSegwit = isSegwitDerivationMode(derivationMode);
          const unsplitFork = isUnsplitDerivationMode(derivationMode)
            ? currency.forkedFrom
            : null;
          const { coinType } = unsplitFork
            ? getCryptoCurrencyById(unsplitFork)
            : currency;
          const path = `${isSegwit ? "49" : "44"}'/${coinType}'`;

          const hwApp = new Btc(transport);
          const { publicKey: seedIdentifier } = await hwApp.getWalletPublicKey(
            path,
            false,
            isSegwit,
          );

          if (isUnsubscribed()) return;

          const walletName = getWalletName({
            seedIdentifier,
            currency,
            derivationMode,
          });

          const wallet = await getOrCreateWallet({
            core,
github liquality / chainabstractionlayer / dist / index.esm.js View on Github external
return regeneratorRuntime.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                if (this._ledgerBtc) {
                  _context.next = 5;
                  break;
                }

                _context.next = 3;
                return Transport.create();

              case 3:
                transport = _context.sent;

                this._ledgerBtc = new LedgerBtc(transport);

              case 5:
              case 'end':
                return _context.stop();
            }
          }
        }, _callee, this);
      }));
github LedgerHQ / ledger-live-desktop / src / helpers / getAddressForCurrency / btc.js View on Github external
export default async (
  transport: Transport<*>,
  currency: CryptoCurrency,
  path: string,
  {
    segwit = true,
    verify = false,
  }: {
    segwit?: boolean,
    verify?: boolean,
  },
) => {
  const btc = new Btc(transport)
  const { bitcoinAddress, publicKey } = await btc.getWalletPublicKey(path, verify, segwit)

  const { bitcoinLikeInfo } = currency
  if (bitcoinLikeInfo) {
    const { P2SH, P2PKH } = await getBitcoinLikeInfo(transport)
    if (P2SH !== bitcoinLikeInfo.P2SH || P2PKH !== bitcoinLikeInfo.P2PKH) {
      if (
        currency.id in oldP2SH &&
        P2SH === oldP2SH[currency.id] &&
        P2PKH === bitcoinLikeInfo.P2PKH
      ) {
        throw new UpdateYourApp(`UpdateYourApp ${currency.id}`, currency)
      }
      throw new BtcUnmatchedApp(`BtcUnmatchedApp ${currency.id}`, currency)
    }
  }

@ledgerhq/hw-app-btc

Ledger Hardware Wallet Bitcoin Application API

MIT
Latest version published 2 months ago

Package Health Score

90 / 100
Full package analysis

Popular @ledgerhq/hw-app-btc functions