Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function main() {
const api = apiForEndpointConfig(RippleAPI)
try {
await api.connect()
const serverInfo = await getServerInfo()
const ledgers = serverInfo.completeLedgers.split('-')
const minLedgerVersion = Number(ledgers[0])
const maxLedgerVersion = Number(ledgers[1])
const derivationModes = getDerivationModesForCurrency(currency)
for (const derivationMode of derivationModes) {
const derivationScheme = getDerivationScheme({
derivationMode,
currency,
})
const stopAt = isIterableDerivationMode(derivationMode) ? 255 : 1
for (let index = 0; index < stopAt; index++) {
if (!derivationModeSupportsIndex(derivationMode, index)) continue
const freshAddressPath = runDerivationScheme(derivationScheme, currency, {
account: index,
})
const { address } = await getAddress
.send({
derivationMode,
currencyId: currency.id,
devicePath: deviceId,
path: freshAddressPath,
withDevicePolling(meta.deviceId)(transport =>
from(
meta.deviceId.startsWith("mock")
? [
{
...meta,
addressInfo: { address: "" },
},
]
: getAddress(transport, {
currency,
derivationMode: "",
path: runDerivationScheme(
getDerivationScheme({ currency, derivationMode: "" }),
currency,
),
}),
),
).pipe(
onClickStressDevice = (device: *) => async () => {
try {
const currency = getCryptoCurrencyById('bitcoin')
const derivationScheme = getDerivationScheme({
currency,
derivationMode: 'segwit',
})
for (let x = 0; x < 20; x++) {
const { address, path } = await getAddress
.send({
derivationMode: 'segwit',
path: runDerivationScheme(derivationScheme, currency, { account: x }),
currencyId: currency.id,
devicePath: device.path,
})
.toPromise()
this.log(`derivated ${path} = ${address}`)
}
} catch (e) {
this.error(e)
execInQueue(async () => {
const { derivationMode, currency, index: account } = this.props;
try {
const p = transportGlobalP || TransportWebUSB.create();
transportGlobalP = p;
const transport = await p;
const { address, path } = await getAddress(transport, {
currency,
path: runDerivationScheme(
getDerivationScheme({ currency, derivationMode }),
currency,
{ account }
),
derivationMode,
verify
});
this.setState({ address, path });
} catch (error) {
this.setState({ error });
}
});
walletName: string,
{
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
}
walletName: string,
currency: CryptoCurrency,
derivationMode: DerivationMode,
}) => {
const poolInstance = core.getPoolInstance();
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,
);
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
}