aboutsummaryrefslogtreecommitdiffstats
path: root/packages/subproviders/src/utils/wallet_utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/subproviders/src/utils/wallet_utils.ts')
-rw-r--r--packages/subproviders/src/utils/wallet_utils.ts40
1 files changed, 18 insertions, 22 deletions
diff --git a/packages/subproviders/src/utils/wallet_utils.ts b/packages/subproviders/src/utils/wallet_utils.ts
index d5ebf5ce6..a37597dff 100644
--- a/packages/subproviders/src/utils/wallet_utils.ts
+++ b/packages/subproviders/src/utils/wallet_utils.ts
@@ -2,37 +2,35 @@ import ethUtil = require('ethereumjs-util');
import HDNode = require('hdkey');
import * as _ from 'lodash';
-import { DerivedHDKey, WalletSubproviderErrors } from '../types';
+import { DerivedHDKeyInfo, WalletSubproviderErrors } from '../types';
-const DEFAULT_ADDRESS_SEARCH_OFFSET = 0;
-const BATCH_SIZE = 10;
const DEFAULT_ADDRESS_SEARCH_LIMIT = 1000;
-class DerivedHDKeyIterator implements IterableIterator<DerivedHDKey> {
- private _initialDerivedKey: DerivedHDKey;
+class DerivedHDKeyInfoIterator implements IterableIterator<DerivedHDKeyInfo> {
+ private _initialDerivedKey: DerivedHDKeyInfo;
private _searchLimit: number;
private _index: number;
- constructor(initialDerivedKey: DerivedHDKey, searchLimit: number = DEFAULT_ADDRESS_SEARCH_OFFSET) {
+ constructor(initialDerivedKey: DerivedHDKeyInfo, searchLimit: number = DEFAULT_ADDRESS_SEARCH_LIMIT) {
this._searchLimit = searchLimit;
this._initialDerivedKey = initialDerivedKey;
this._index = 0;
}
- public next(): IteratorResult<DerivedHDKey> {
- const derivationBasePath = this._initialDerivedKey.derivationBasePath;
+ public next(): IteratorResult<DerivedHDKeyInfo> {
+ const baseDerivationPath = this._initialDerivedKey.baseDerivationPath;
const derivationIndex = this._index;
const isChildKey = this._initialDerivedKey.isChildKey;
// If the DerivedHDKey is a child then we walk relative, if not we walk the full derivation path
- const fullDerivationPath = `m/${derivationBasePath}/${derivationIndex}`;
+ const fullDerivationPath = `m/${baseDerivationPath}/${derivationIndex}`;
const relativeDerivationPath = `m/${derivationIndex}`;
const path = isChildKey ? relativeDerivationPath : fullDerivationPath;
const hdKey = this._initialDerivedKey.hdKey.derive(path);
const address = walletUtils.addressOfHDKey(hdKey);
- const derivedKey: DerivedHDKey = {
+ const derivedKey: DerivedHDKeyInfo = {
address,
hdKey,
- derivationBasePath,
+ baseDerivationPath,
derivationIndex,
derivationPath: fullDerivationPath,
isChildKey,
@@ -45,29 +43,27 @@ class DerivedHDKeyIterator implements IterableIterator<DerivedHDKey> {
};
}
- public [Symbol.iterator](): IterableIterator<DerivedHDKey> {
+ public [Symbol.iterator](): IterableIterator<DerivedHDKeyInfo> {
return this;
}
}
export const walletUtils = {
- DEFAULT_ADDRESS_SEARCH_LIMIT,
- DEFAULT_NUM_ADDRESSES_TO_FETCH: 10,
- calculateDerivedHDKeys(initialDerivedKey: DerivedHDKey, numberOfKeys: number): DerivedHDKey[] {
- const derivedKeys: DerivedHDKey[] = [];
- const derivedKeyIterator = new DerivedHDKeyIterator(initialDerivedKey, numberOfKeys);
+ calculateDerivedHDKeyInfos(initialDerivedKey: DerivedHDKeyInfo, numberOfKeys: number): DerivedHDKeyInfo[] {
+ const derivedKeys: DerivedHDKeyInfo[] = [];
+ const derivedKeyIterator = new DerivedHDKeyInfoIterator(initialDerivedKey, numberOfKeys);
for (const key of derivedKeyIterator) {
derivedKeys.push(key);
}
return derivedKeys;
},
- findDerivedKeyByAddress(
+ findDerivedKeyInfoForAddressIfExists(
address: string,
- initialDerivedKey: DerivedHDKey,
+ initialDerivedKey: DerivedHDKeyInfo,
searchLimit: number,
- ): DerivedHDKey | undefined {
- let matchedKey: DerivedHDKey | undefined;
- const derivedKeyIterator = new DerivedHDKeyIterator(initialDerivedKey, searchLimit);
+ ): DerivedHDKeyInfo | undefined {
+ let matchedKey: DerivedHDKeyInfo | undefined;
+ const derivedKeyIterator = new DerivedHDKeyInfoIterator(initialDerivedKey, searchLimit);
for (const key of derivedKeyIterator) {
if (key.address === address) {
matchedKey = key;