How to use the @ledgerhq/hw-app-btc function in @ledgerhq/hw-app-btc

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 / 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-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)
    }
  }
github blockstack / stacks-wallet / app / common / lib / addresses.js View on Github external
const getLedgerAddress = async () => {
  try {
    const transport = await Transport.create();
    const appbtc = await new AppBtc(transport);
    const walletData = await appbtc.getWalletPublicKey(PATH);
    if (!walletData) return;
    const ecPair = bitcoin.ECPair.fromPublicKey(
      Buffer.from(walletData.publicKey, "hex")
    );
    return getAddressesFromPublicKey(ecPair.publicKey);
  } catch (e) {
    const error = "Failed to get address from Ledger";
    throw new Error(e.message || error);
  }
};

@ledgerhq/hw-app-btc

Ledger Hardware Wallet Bitcoin Application API

MIT
Latest version published 10 days ago

Package Health Score

90 / 100
Full package analysis

Popular @ledgerhq/hw-app-btc functions