Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
);
const [
{ value: freshAddressStr },
{ value: freshAddressPath },
] = await Promise.all([
core.coreAddress.toString(coreFreshAddress),
core.coreAddress.getDerivationPath(coreFreshAddress),
]);
const freshAddress = {
str: freshAddressStr,
path: `${accountPath}/${freshAddressPath}`,
};
const name =
coreOperations.length === 0
? getNewAccountPlaceholderName({
currency,
index: accountIndex,
derivationMode,
})
: getAccountPlaceholderName({
currency,
index: accountIndex,
derivationMode,
});
// retrieve xpub
const { value: xpub } = await core.coreAccount.getRestoreKey(coreAccount);
const id = encodeAccountId({
type: "libcore",
version: "1",
const freshAddresses = await coreAccount.getFreshPublicAddresses();
const [coreFreshAddress] = freshAddresses;
if (!coreFreshAddress) throw new Error("expected at least one fresh address");
const [freshAddressStr, freshAddressPath] = await Promise.all([
coreFreshAddress.toString(),
coreFreshAddress.getDerivationPath(),
]);
if (!freshAddressPath) throw new Error("expected freshAddressPath");
const freshAddress = {
str: freshAddressStr,
path: `${accountPath}/${freshAddressPath}`,
};
const name =
coreOperations.length === 0
? getNewAccountPlaceholderName({
currency,
index: accountIndex,
derivationMode,
})
: getAccountPlaceholderName({
currency,
index: accountIndex,
derivationMode,
});
// retrieve xpub
const xpub = await coreAccount.getRestoreKey();
const accountId = encodeAccountId({
type: "libcore",
version: "1",
if (txs.length === 0 && balance.isZero()) {
// this is an empty account
if (derivationMode === '') {
// is standard derivation
if (newAccountCount === 0) {
// first zero account will emit one account as opportunity to create a new account..
const account: $Exact = {
type: 'Account',
id: accountId,
seedIdentifier: freshAddress,
freshAddress,
freshAddressPath,
freshAddresses: [{ address: freshAddress, derivationPath: freshAddressPath }],
derivationMode,
name: getNewAccountPlaceholderName({
currency,
index,
derivationMode,
}),
balance,
blockHeight: currentBlock.height,
index,
currency,
operations: [],
pendingOperations: [],
unit: currency.units[0],
lastSyncDate: new Date(),
}
return { account, complete: true }
}
newAccountCount++
}
}
// fresh address is address. ripple never changes.
const freshAddress = address
if (!info) {
// account does not exist in Ripple server
// we are generating a new account locally
if (derivationMode === '') {
o.next({
type: 'Account',
id: accountId,
seedIdentifier: freshAddress,
derivationMode,
name: getNewAccountPlaceholderName({
currency,
index,
derivationMode,
}),
freshAddress,
freshAddressPath,
freshAddresses: [{ address: freshAddress, derivationPath: freshAddressPath }],
balance: BigNumber(0),
blockHeight: maxLedgerVersion,
index,
currency,
operations: [],
pendingOperations: [],
unit: currency.units[0],
archived: false,
lastSyncDate: new Date(),
path: `${accountPath}/${njsAddress.getDerivationPath()}`,
}))
if (addresses.length === 0) {
throw new NoAddressesFound()
}
const { str: freshAddress, path: freshAddressPath } = addresses[0]
ops.sort((a, b) => b.getDate() - a.getDate())
const operations = ops.map(op => buildOperationRaw({ core, op, xpub }))
const name =
operations.length === 0
? getNewAccountPlaceholderName({ currency, index: accountIndex, derivationMode })
: getAccountPlaceholderName({
currency,
index: accountIndex,
derivationMode,
})
const rawAccount: AccountRaw = {
id: encodeAccountId({
type: 'libcore',
version: '1',
currencyId: currency.id,
xpubOrAddress: xpub,
derivationMode,
}),
seedIdentifier,
derivationMode,