aboutsummaryrefslogtreecommitdiffstats
path: root/packages/subproviders/src
diff options
context:
space:
mode:
authorJacob Evans <jacob@dekz.net>2018-04-11 12:22:02 +0800
committerJacob Evans <jacob@dekz.net>2018-04-11 12:39:55 +0800
commit3ad693d33409dfd9d61beff3f43c4abaa369c6b1 (patch)
tree54eb616082ac245555a8072020b387a50eee42fa /packages/subproviders/src
parent4aa67e292504fea307a4e5f15a124349fc769da6 (diff)
downloaddexon-sol-tools-3ad693d33409dfd9d61beff3f43c4abaa369c6b1.tar.gz
dexon-sol-tools-3ad693d33409dfd9d61beff3f43c4abaa369c6b1.tar.zst
dexon-sol-tools-3ad693d33409dfd9d61beff3f43c4abaa369c6b1.zip
Test valid address format but not found
Diffstat (limited to 'packages/subproviders/src')
-rw-r--r--packages/subproviders/src/subproviders/ledger.ts2
-rw-r--r--packages/subproviders/src/subproviders/mnemonic_wallet.ts7
-rw-r--r--packages/subproviders/src/utils/wallet_utils.ts9
3 files changed, 11 insertions, 7 deletions
diff --git a/packages/subproviders/src/subproviders/ledger.ts b/packages/subproviders/src/subproviders/ledger.ts
index 0c037b488..9b2d9d7d0 100644
--- a/packages/subproviders/src/subproviders/ledger.ts
+++ b/packages/subproviders/src/subproviders/ledger.ts
@@ -222,7 +222,7 @@ export class LedgerSubprovider extends BaseWalletSubprovider {
};
}
private _findDerivedKeyByPublicAddress(initalHDKey: DerivedHDKey, address: string): DerivedHDKey {
- if (_.isUndefined(address)) {
+ if (_.isUndefined(address) || !addressUtils.isAddress(address)) {
throw new Error(WalletSubproviderErrors.FromAddressMissingOrInvalid);
}
const matchedDerivedKey = walletUtils.findDerivedKeyByAddress(address, initalHDKey, this._addressSearchLimit);
diff --git a/packages/subproviders/src/subproviders/mnemonic_wallet.ts b/packages/subproviders/src/subproviders/mnemonic_wallet.ts
index 855db21ad..de34a9d11 100644
--- a/packages/subproviders/src/subproviders/mnemonic_wallet.ts
+++ b/packages/subproviders/src/subproviders/mnemonic_wallet.ts
@@ -1,4 +1,5 @@
import { assert } from '@0xproject/assert';
+import { addressUtils } from '@0xproject/utils';
import * as bip39 from 'bip39';
import ethUtil = require('ethereumjs-util');
import HDNode = require('hdkey');
@@ -43,8 +44,10 @@ export class MnemonicWalletSubprovider extends BaseWalletSubprovider {
this._derivationBasePath = derivationBasePath;
this._derivedKey = {
address: walletUtils.addressOfHDKey(hdKey),
+ // HACK this isn't the base path for this root key, but is is the base path
+ // we want all of the derived children to spawn from
derivationBasePath: this._derivationBasePath,
- derivationPath: `${this._derivationBasePath}/${0}`,
+ derivationPath: 'm/0',
derivationIndex: 0,
hdKey,
isChildKey: false,
@@ -119,7 +122,7 @@ export class MnemonicWalletSubprovider extends BaseWalletSubprovider {
return privateKeyWallet;
}
private _findDerivedKeyByPublicAddress(address: string): DerivedHDKey {
- if (_.isUndefined(address)) {
+ if (_.isUndefined(address) || !addressUtils.isAddress(address)) {
throw new Error(WalletSubproviderErrors.FromAddressMissingOrInvalid);
}
const matchedDerivedKey = walletUtils.findDerivedKeyByAddress(
diff --git a/packages/subproviders/src/utils/wallet_utils.ts b/packages/subproviders/src/utils/wallet_utils.ts
index 097d2b82f..d5ebf5ce6 100644
--- a/packages/subproviders/src/utils/wallet_utils.ts
+++ b/packages/subproviders/src/utils/wallet_utils.ts
@@ -22,19 +22,20 @@ class DerivedHDKeyIterator implements IterableIterator<DerivedHDKey> {
public next(): IteratorResult<DerivedHDKey> {
const derivationBasePath = this._initialDerivedKey.derivationBasePath;
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 relativeDerivationPath = `m/${derivationIndex}`;
- const path = this._initialDerivedKey.isChildKey ? relativeDerivationPath : fullDerivationPath;
+ const path = isChildKey ? relativeDerivationPath : fullDerivationPath;
const hdKey = this._initialDerivedKey.hdKey.derive(path);
const address = walletUtils.addressOfHDKey(hdKey);
const derivedKey: DerivedHDKey = {
address,
hdKey,
- derivationPath: fullDerivationPath,
- derivationBasePath: this._initialDerivedKey.derivationBasePath,
+ derivationBasePath,
derivationIndex,
- isChildKey: this._initialDerivedKey.isChildKey,
+ derivationPath: fullDerivationPath,
+ isChildKey,
};
const done = this._index === this._searchLimit;
this._index++;