aboutsummaryrefslogtreecommitdiffstats
path: root/packages/subproviders/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/subproviders/src')
-rw-r--r--packages/subproviders/src/subproviders/ledger.ts17
-rw-r--r--packages/subproviders/src/subproviders/mnemonic_wallet.ts6
2 files changed, 11 insertions, 12 deletions
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);