How to use the @ledgerhq/live-common/lib/hw/deviceAccess.withDevice 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-common / cli / src / commands / appsUpdateTestAll.js View on Github external
job: ({ device, index }: $Shape<{ device: string, index: number }>) =>
    withDevice(device || "")(t => {
      const exec = execWithTransport(t);
      // $FlowFixMe
      return from(getDeviceInfo(t)).pipe(
        mergeMap(deviceInfo =>
          listApps(t, deviceInfo).pipe(
            filter(e => e.type === "result"),
            map(e => e.result)
          )
        ),
        mergeMap(listAppsResult => {
          return listAppsResult.appsListNames.slice(index || 0).reduce(
            ($state, name) =>
              $state.pipe(
                mergeMap(s => {
                  if (s.currentError) {
                    console.error(
github LedgerHQ / ledger-live-desktop / src / helpers / libcore.js View on Github external
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,
  })

  // retrieve or create the wallet
  const wallet = await getOrCreateWallet(core, walletName, { currency, derivationMode })

  // recursively scan all accounts on device on the given app
  // new accounts will be created in sqlite, existing ones will be updated
github LedgerHQ / ledger-live-desktop / src / commands / testApdu.js View on Github external
const cmd: Command = createCommand('testApdu', ({ apduHex, devicePath }) =>
  withDevice(devicePath)(transport =>
    from(
      transport
        .exchange(Buffer.from(apduHex, 'hex'))
        .then(res => ({ responseHex: res.toString('hex') })),
    ),
  ),
)
github LedgerHQ / ledger-live-mobile / src / components / DeviceJob / steps.js View on Github external
run: meta =>
    withDevice(meta.deviceId)(transport =>
      from(
        getDeviceNameTransport(transport).then(deviceName => ({
          ...meta,
          deviceName,
        })),
      ),
    ),
};
github LedgerHQ / ledger-live-desktop / src / commands / listApps.js View on Github external
const cmd: Command = createCommand('listApps', ({ devicePath, deviceInfo }) =>
  withDevice(devicePath)(transport => listApps(transport, deviceInfo)),
)
github LedgerHQ / ledger-live-desktop / src / commands / getAppAndVersion.js View on Github external
const cmd: Command = createCommand('getAppAndVersion', ({ devicePath }) =>
  withDevice(devicePath)(transport =>
    from(getAppAndVersion(transport).then(({ name, version }) => ({ name, version }))),
  ),
)
github LedgerHQ / ledger-live-desktop / src / commands / appOpExec.js View on Github external
({ devicePath, appOp, targetId, app }) =>
    withDevice(devicePath)(transport => execWithTransport(transport)(appOp, targetId, app)),
)
github LedgerHQ / ledger-live-mobile / src / screens / ReceiveFunds / 03-Confirmation.js View on Github external
verifyOnDevice = async (deviceId: string) => {
    const { account, parentAccount, navigation } = this.props;
    if (!account) return;
    const mainAccount = getMainAccount(account, parentAccount);

    this.sub = withDevice(deviceId)(transport =>
      mainAccount.id.startsWith("mock")
        ? of({}).pipe(
            delay(1000),
            rejectionOp(),
          )
        : from(
            getAddress(transport, {
              derivationMode: mainAccount.derivationMode,
              currency: mainAccount.currency,
              path: mainAccount.freshAddressPath,
              verify: true,
            }),
          ),
    ).subscribe({
      complete: () => {
        this.setState({ verified: true });
github LedgerHQ / ledger-live-desktop / src / commands / getAddress.js View on Github external
({ currencyId, devicePath, ...options }) =>
    withDevice(devicePath)(transport =>
      from(
        getAddress(transport, {
          currency: getCryptoCurrencyById(currencyId),
          ...options,
        }),
      ),
    ),
)
github LedgerHQ / ledger-live-mobile / src / screens / DebugBLE.js View on Github external
connect = async () => {
    const { navigation } = this.props;
    const deviceId = navigation.getParam("deviceId");
    try {
      await withDevice(deviceId)(() => from([{}])).toPromise();
    } catch (error) {
      this.addError(error, "connect");
    }
  };