aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJacob Evans <jacob@dekz.net>2018-04-12 15:26:17 +0800
committerJacob Evans <jacob@dekz.net>2018-04-12 15:26:17 +0800
commit9a91e39b3f9419287ba0c508b86d519db4e72dd7 (patch)
tree9309620dab3f51c1c9a2b778f0e0b27e829278cc
parentce3f25d48f3eb7a71953515e30a3f0c49881eac4 (diff)
downloaddexon-sol-tools-9a91e39b3f9419287ba0c508b86d519db4e72dd7.tar
dexon-sol-tools-9a91e39b3f9419287ba0c508b86d519db4e72dd7.tar.gz
dexon-sol-tools-9a91e39b3f9419287ba0c508b86d519db4e72dd7.tar.bz2
dexon-sol-tools-9a91e39b3f9419287ba0c508b86d519db4e72dd7.tar.lz
dexon-sol-tools-9a91e39b3f9419287ba0c508b86d519db4e72dd7.tar.xz
dexon-sol-tools-9a91e39b3f9419287ba0c508b86d519db4e72dd7.tar.zst
dexon-sol-tools-9a91e39b3f9419287ba0c508b86d519db4e72dd7.zip
Revert Ledger back to assigning ledgerClient to instance variable
-rw-r--r--packages/subproviders/CHANGELOG.json14
-rw-r--r--packages/subproviders/src/subproviders/ledger.ts17
-rw-r--r--packages/subproviders/src/subproviders/mnemonic_wallet.ts6
3 files changed, 22 insertions, 15 deletions
diff --git a/packages/subproviders/CHANGELOG.json b/packages/subproviders/CHANGELOG.json
index 9166c93d5..d3ba7a928 100644
--- a/packages/subproviders/CHANGELOG.json
+++ b/packages/subproviders/CHANGELOG.json
@@ -8,16 +8,24 @@
"pr": 500
},
{
- "note": "Add private key subprovider and refactor shared functionality into a base wallet subprovider",
+ "note": "Add PrivateKeySubprovider and refactor shared functionality into a base wallet subprovider",
"pr": 506
},
{
- "note": "Add mnemonic wallet subprovider, deprecating our truffle-hdwallet-provider fork.",
+ "note": "Add MnemonicWalletsubprovider, deprecating our truffle-hdwallet-provider fork",
+ "pr": 507
+ },
+ {
+ "note": "Support multiple addresses in ledger and mnemonic wallets",
"pr": 507
},
{
"note":
- "Support multiple addresses in ledger and mnemonic wallets. Renamed derivationPath to baseDerivationPath.",
+ "Refactors LedgerSubprovider such that explicitly setting the `pathIndex` is no longer required. Simply set the request `from` address as desired",
+ "pr": 507
+ },
+ {
+ "note": "Renamed derivationPath to baseDerivationPath.",
"pr": 507
}
],
diff --git a/packages/subproviders/src/subproviders/ledger.ts b/packages/subproviders/src/subproviders/ledger.ts
index d956a4f9d..563e5a56a 100644
--- a/packages/subproviders/src/subproviders/ledger.ts
+++ b/packages/subproviders/src/subproviders/ledger.ts
@@ -26,7 +26,6 @@ const ASK_FOR_ON_DEVICE_CONFIRMATION = false;
const SHOULD_GET_CHAIN_CODE = true;
const DEFAULT_NUM_ADDRESSES_TO_FETCH = 10;
const DEFAULT_ADDRESS_SEARCH_LIMIT = 1000;
-const INITIAL_KEY_DERIVATION_INDEX = 0;
/**
* Subprovider for interfacing with a user's [Ledger Nano S](https://www.ledgerwallet.com/products/ledger-nano-s).
@@ -109,7 +108,7 @@ export class LedgerSubprovider extends BaseWalletSubprovider {
const initialDerivedKeyInfo = await this._initialDerivedKeyInfoAsync();
const derivedKeyInfo = this._findDerivedKeyInfoForAddress(initialDerivedKeyInfo, txParams.from);
- const ledgerClient = await this._createLedgerClientAsync();
+ this._ledgerClientIfExists = await this._createLedgerClientAsync();
const tx = new EthereumTx(txParams);
@@ -121,7 +120,7 @@ export class LedgerSubprovider extends BaseWalletSubprovider {
const txHex = tx.serialize().toString('hex');
try {
const fullDerivationPath = derivedKeyInfo.derivationPath;
- const result = await ledgerClient.signTransaction(fullDerivationPath, txHex);
+ const result = await this._ledgerClientIfExists.signTransaction(fullDerivationPath, txHex);
// Store signature in transaction
tx.r = Buffer.from(result.r, 'hex');
tx.s = Buffer.from(result.s, 'hex');
@@ -163,10 +162,13 @@ export class LedgerSubprovider extends BaseWalletSubprovider {
const initialDerivedKeyInfo = await this._initialDerivedKeyInfoAsync();
const derivedKeyInfo = this._findDerivedKeyInfoForAddress(initialDerivedKeyInfo, address);
- const ledgerClient = await this._createLedgerClientAsync();
+ this._ledgerClientIfExists = await this._createLedgerClientAsync();
try {
const fullDerivationPath = derivedKeyInfo.derivationPath;
- const result = await ledgerClient.signPersonalMessage(fullDerivationPath, ethUtil.stripHexPrefix(data));
+ const result = await this._ledgerClientIfExists.signPersonalMessage(
+ fullDerivationPath,
+ ethUtil.stripHexPrefix(data),
+ );
const v = result.v - 27;
let vHex = v.toString(16);
if (vHex.length < 2) {
@@ -188,7 +190,6 @@ export class LedgerSubprovider extends BaseWalletSubprovider {
}
const ledgerEthereumClient = await this._ledgerEthereumClientFactoryAsync();
this._connectionLock.release();
- this._ledgerClientIfExists = ledgerEthereumClient;
return ledgerEthereumClient;
}
private async _destroyLedgerClientAsync() {
@@ -202,12 +203,12 @@ export class LedgerSubprovider extends BaseWalletSubprovider {
this._connectionLock.release();
}
private async _initialDerivedKeyInfoAsync(): Promise<DerivedHDKeyInfo> {
- const ledgerClient = await this._createLedgerClientAsync();
+ this._ledgerClientIfExists = await this._createLedgerClientAsync();
const parentKeyDerivationPath = `m/${this._baseDerivationPath}`;
let ledgerResponse;
try {
- ledgerResponse = await ledgerClient.getAddress(
+ ledgerResponse = await this._ledgerClientIfExists.getAddress(
parentKeyDerivationPath,
this._shouldAlwaysAskForConfirmation,
SHOULD_GET_CHAIN_CODE,
diff --git a/packages/subproviders/src/subproviders/mnemonic_wallet.ts b/packages/subproviders/src/subproviders/mnemonic_wallet.ts
index 287dcfd7d..080bfeb4c 100644
--- a/packages/subproviders/src/subproviders/mnemonic_wallet.ts
+++ b/packages/subproviders/src/subproviders/mnemonic_wallet.ts
@@ -14,7 +14,6 @@ import { PrivateKeyWalletSubprovider } from './private_key_wallet';
const DEFAULT_BASE_DERIVATION_PATH = `44'/60'/0'/0`;
const DEFAULT_NUM_ADDRESSES_TO_FETCH = 10;
const DEFAULT_ADDRESS_SEARCH_LIMIT = 1000;
-const INITIAL_KEY_DERIVATION_INDEX = 0;
/**
* This class implements the [web3-provider-engine](https://github.com/MetaMask/provider-engine) subprovider interface.
@@ -34,15 +33,14 @@ export class MnemonicWalletSubprovider extends BaseWalletSubprovider {
* @return MnemonicWalletSubprovider instance
*/
constructor(config: MnemonicWalletSubproviderConfigs) {
- const mnemonic = config.mnemonic;
- assert.isString('mnemonic', mnemonic);
+ assert.isString('mnemonic', config.mnemonic);
const baseDerivationPath = config.baseDerivationPath || DEFAULT_BASE_DERIVATION_PATH;
assert.isString('baseDerivationPath', baseDerivationPath);
const addressSearchLimit = config.addressSearchLimit || DEFAULT_ADDRESS_SEARCH_LIMIT;
assert.isNumber('addressSearchLimit', addressSearchLimit);
super();
- this._mnemonic = mnemonic;
+ this._mnemonic = config.mnemonic;
this._baseDerivationPath = baseDerivationPath;
this._addressSearchLimit = addressSearchLimit;
this._derivedKeyInfo = this._initialDerivedKeyInfo(this._baseDerivationPath);