Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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(
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
const cmd: Command = createCommand('testApdu', ({ apduHex, devicePath }) =>
withDevice(devicePath)(transport =>
from(
transport
.exchange(Buffer.from(apduHex, 'hex'))
.then(res => ({ responseHex: res.toString('hex') })),
),
),
)
run: meta =>
withDevice(meta.deviceId)(transport =>
from(
getDeviceNameTransport(transport).then(deviceName => ({
...meta,
deviceName,
})),
),
),
};
const cmd: Command = createCommand('listApps', ({ devicePath, deviceInfo }) =>
withDevice(devicePath)(transport => listApps(transport, deviceInfo)),
)
const cmd: Command = createCommand('getAppAndVersion', ({ devicePath }) =>
withDevice(devicePath)(transport =>
from(getAppAndVersion(transport).then(({ name, version }) => ({ name, version }))),
),
)
({ devicePath, appOp, targetId, app }) =>
withDevice(devicePath)(transport => execWithTransport(transport)(appOp, targetId, app)),
)
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 });
({ currencyId, devicePath, ...options }) =>
withDevice(devicePath)(transport =>
from(
getAddress(transport, {
currency: getCryptoCurrencyById(currencyId),
...options,
}),
),
),
)
connect = async () => {
const { navigation } = this.props;
const deviceId = navigation.getParam("deviceId");
try {
await withDevice(deviceId)(() => from([{}])).toPromise();
} catch (error) {
this.addError(error, "connect");
}
};