How to use the @ledgerhq/live-common/lib/derivation.isSegwitDerivationMode function in @ledgerhq/live-common

To help you get started, weā€™ve selected a few @ledgerhq/live-common 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-mobile / src / libcore / signAndBroadcast.js View on Github external
: undefined;
  if (isCancelled()) return;

  const lockTime = undefined;

  onSigning();

  const signedTransaction = await hwApp.createPaymentTransactionNew(
    // $FlowFixMe not sure what's wrong
    inputs,
    associatedKeysets,
    changePath,
    outputScriptHex,
    lockTime,
    sigHashType,
    isSegwitDerivationMode(derivationMode),
    initialTimestamp || undefined,
    additionals,
    expiryHeight,
  );

  return signedTransaction; // eslint-disable-line
}
github LedgerHQ / ledger-live-desktop / src / helpers / libcore.js View on Github external
{
    currency,
    derivationMode,
  }: {
    currency: CryptoCurrency,
    derivationMode: DerivationMode,
  },
): NJSWallet {
  const pool = core.getPoolInstance()
  try {
    const wallet = await timeoutTagged('getWallet', 5000, pool.getWallet(walletName))
    return wallet
  } catch (err) {
    const currencyCore = await timeoutTagged('getCurrency', 5000, pool.getCurrency(currency.id))
    const derivationScheme = getDerivationScheme({ currency, derivationMode })
    const walletConfig = isSegwitDerivationMode(derivationMode)
      ? {
          KEYCHAIN_ENGINE: 'BIP49_P2SH',
          KEYCHAIN_DERIVATION_SCHEME: derivationScheme,
        }
      : {
          KEYCHAIN_DERIVATION_SCHEME: derivationScheme,
        }
    const njsWalletConfig = createWalletConfig(core, walletConfig)
    const wallet = await timeoutTagged(
      'createWallet',
      10000,
      core.getPoolInstance().createWallet(walletName, currencyCore, njsWalletConfig),
    )
    return wallet
  }
}
github LedgerHQ / ledger-live-desktop / src / components / EnsureDeviceApp.js View on Github external
async function getAddressFromAccountOrCurrency(device, account, currency) {
  const { address } = await getAddress
    .send({
      derivationMode: account ? account.derivationMode : '',
      devicePath: device.path,
      currencyId: currency.id,
      path: account
        ? account.freshAddressPath
        : runDerivationScheme(getDerivationScheme({ currency, derivationMode: '' }), currency),
      segwit: account ? isSegwitDerivationMode(account.derivationMode) : false,
    })
    .toPromise()
  return address
}
github LedgerHQ / ledger-live-mobile / src / libcore / index.js View on Github external
let wallet;
    try {
      wallet = await core.coreWalletPool.getWallet(poolInstance, walletName);
    } catch (err) {
      const currencyCore = await core.coreWalletPool.getCurrency(
        poolInstance,
        currency.id,
      );
      const config = await core.coreDynamicObject.newInstance();

      const derivationScheme = getDerivationScheme({
        currency,
        derivationMode,
      });

      if (isSegwitDerivationMode(derivationMode)) {
        core.coreDynamicObject.putString(
          config,
          "KEYCHAIN_ENGINE",
          "BIP49_P2SH",
        );
      }
      core.coreDynamicObject.putString(
        config,
        "KEYCHAIN_DERIVATION_SCHEME",
        derivationScheme,
      );

      wallet = await core.coreWalletPool.createWallet(
        poolInstance,
        walletName,
        currencyCore,
github LedgerHQ / ledger-live-mobile / src / libcore / getOrCreateWallet.js View on Github external
let wallet;
    try {
      wallet = await core.coreWalletPool.getWallet(poolInstance, walletName);
    } catch (err) {
      const currencyCore = await core.coreWalletPool.getCurrency(
        poolInstance,
        currency.id,
      );
      const config = await core.coreDynamicObject.newInstance();

      const derivationScheme = getDerivationScheme({
        currency,
        derivationMode,
      });

      if (isSegwitDerivationMode(derivationMode)) {
        await core.coreDynamicObject.putString(
          config,
          "KEYCHAIN_ENGINE",
          "BIP49_P2SH",
        );
      }
      await core.coreDynamicObject.putString(
        config,
        "KEYCHAIN_DERIVATION_SCHEME",
        derivationScheme,
      );

      wallet = await core.coreWalletPool.createWallet(
        poolInstance,
        walletName,
        currencyCore,
github LedgerHQ / ledger-live-desktop / src / helpers / libcore.js View on Github external
xpub: string,
  derivationMode: DerivationMode,
  seedIdentifier: string,
}) {
  const currency = getCryptoCurrencyById(currencyId)
  const walletName = getWalletName({
    currency,
    seedIdentifier,
    derivationMode,
  })

  const wallet = await getOrCreateWallet(core, walletName, { currency, derivationMode })

  const index = 0

  const isSegwit = isSegwitDerivationMode(derivationMode)

  const extendedInfos = {
    index,
    owners: ['main'],
    derivations: [
      `${isSegwit ? '49' : '44'}'/${currency.coinType}'`,
      `${isSegwit ? '49' : '44'}'/${currency.coinType}'/0`,
    ],
    extendedKeys: [xpub],
  }

  const account = await wallet.newAccountWithExtendedKeyInfo(extendedInfos)
  await coreSyncAccount(core, account)
  const query = account.queryOperations()
  const ops = await query.complete().execute()
  const rawAccount = await buildAccountRaw({
github LedgerHQ / ledger-live-desktop / src / helpers / libcore.js View on Github external
devicePath,
  currency,
  onAccountScanned,
  isUnsubscribed,
  derivationMode,
  showNewAccount,
}: {
  core: *,
  devicePath: string,
  currency: CryptoCurrency,
  onAccountScanned: AccountRaw => void,
  isUnsubscribed: () => boolean,
  derivationMode: DerivationMode,
  showNewAccount: boolean,
}): Promise {
  const isSegwit = isSegwitDerivationMode(derivationMode)
  const unsplitFork = isUnsplitDerivationMode(derivationMode) ? currency.forkedFrom : null
  const { coinType } = unsplitFork ? getCryptoCurrencyById(unsplitFork) : currency
  const path = `${isSegwit ? '49' : '44'}'/${coinType}'`

  const { publicKey: seedIdentifier } = await withDevice(devicePath)(transport =>
    from(getAddress(transport, currency, path)),
  ).toPromise()

  if (isUnsubscribed()) return []

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