aboutsummaryrefslogtreecommitdiffstats
path: root/packages/subproviders
diff options
context:
space:
mode:
Diffstat (limited to 'packages/subproviders')
-rw-r--r--packages/subproviders/CHANGELOG.json9
-rw-r--r--packages/subproviders/CHANGELOG.md6
-rw-r--r--packages/subproviders/package.json16
-rw-r--r--packages/subproviders/src/index.ts1
-rw-r--r--packages/subproviders/src/subproviders/ledger.ts18
-rw-r--r--packages/subproviders/src/subproviders/nonce_tracker.ts3
-rw-r--r--packages/subproviders/src/subproviders/subprovider.ts5
-rw-r--r--packages/subproviders/src/utils/subprovider_utils.ts15
-rw-r--r--packages/subproviders/src/utils/wallet_utils.ts4
-rw-r--r--packages/subproviders/test/integration/ledger_subprovider_test.ts13
-rw-r--r--packages/subproviders/test/unit/ledger_subprovider_test.ts8
-rw-r--r--packages/subproviders/test/unit/mnemonic_wallet_subprovider_test.ts5
-rw-r--r--packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts5
13 files changed, 76 insertions, 32 deletions
diff --git a/packages/subproviders/CHANGELOG.json b/packages/subproviders/CHANGELOG.json
index 799c2c99a..d3bf79ac4 100644
--- a/packages/subproviders/CHANGELOG.json
+++ b/packages/subproviders/CHANGELOG.json
@@ -1,5 +1,14 @@
[
{
+ "timestamp": 1527009133,
+ "version": "0.10.2",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
"timestamp": 1525477860,
"version": "0.10.1",
"changes": [
diff --git a/packages/subproviders/CHANGELOG.md b/packages/subproviders/CHANGELOG.md
index 22a5f90e8..8c4990a7c 100644
--- a/packages/subproviders/CHANGELOG.md
+++ b/packages/subproviders/CHANGELOG.md
@@ -5,7 +5,11 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
-## v0.10.1 - _May 5, 2018_
+## v0.10.2 - _May 22, 2018_
+
+ * Dependencies updated
+
+## v0.10.1 - _May 4, 2018_
* Dependencies updated
diff --git a/packages/subproviders/package.json b/packages/subproviders/package.json
index 21e47b85a..3cd5f0e9b 100644
--- a/packages/subproviders/package.json
+++ b/packages/subproviders/package.json
@@ -1,6 +1,6 @@
{
"name": "@0xproject/subproviders",
- "version": "0.10.1",
+ "version": "0.10.2",
"engines": {
"node": ">=6.12"
},
@@ -39,10 +39,10 @@
}
},
"dependencies": {
- "@0xproject/assert": "^0.2.9",
- "@0xproject/types": "^0.6.3",
- "@0xproject/typescript-typings": "^0.3.1",
- "@0xproject/utils": "^0.6.1",
+ "@0xproject/assert": "^0.2.10",
+ "@0xproject/types": "^0.7.0",
+ "@0xproject/typescript-typings": "^0.3.2",
+ "@0xproject/utils": "^0.6.2",
"@ledgerhq/hw-app-eth": "^4.3.0",
"@ledgerhq/hw-transport-u2f": "^4.3.0",
"bip39": "^2.5.0",
@@ -57,9 +57,9 @@
"web3-provider-engine": "^14.0.4"
},
"devDependencies": {
- "@0xproject/monorepo-scripts": "^0.1.19",
- "@0xproject/tslint-config": "^0.4.17",
- "@0xproject/utils": "^0.6.1",
+ "@0xproject/monorepo-scripts": "^0.1.20",
+ "@0xproject/tslint-config": "^0.4.18",
+ "@0xproject/utils": "^0.6.2",
"@types/bip39": "^2.4.0",
"@types/lodash": "4.14.104",
"@types/mocha": "^2.2.42",
diff --git a/packages/subproviders/src/index.ts b/packages/subproviders/src/index.ts
index ff28b8a8d..6cc650a4d 100644
--- a/packages/subproviders/src/index.ts
+++ b/packages/subproviders/src/index.ts
@@ -4,6 +4,7 @@ export { ECSignature } from '@0xproject/types';
import { LedgerEthereumClient } from './types';
+export { prependSubprovider } from './utils/subprovider_utils';
export { EmptyWalletSubprovider } from './subproviders/empty_wallet_subprovider';
export { FakeGasEstimateSubprovider } from './subproviders/fake_gas_estimate_subprovider';
export { InjectedWeb3Subprovider } from './subproviders/injected_web3';
diff --git a/packages/subproviders/src/subproviders/ledger.ts b/packages/subproviders/src/subproviders/ledger.ts
index 347eda55f..467299db0 100644
--- a/packages/subproviders/src/subproviders/ledger.ts
+++ b/packages/subproviders/src/subproviders/ledger.ts
@@ -113,9 +113,12 @@ export class LedgerSubprovider extends BaseWalletSubprovider {
const tx = new EthereumTx(txParams);
// Set the EIP155 bits
- tx.raw[6] = Buffer.from([this._networkId]); // v
- tx.raw[7] = Buffer.from([]); // r
- tx.raw[8] = Buffer.from([]); // s
+ const vIndex = 6;
+ tx.raw[vIndex] = Buffer.from([this._networkId]); // v
+ const rIndex = 7;
+ tx.raw[rIndex] = Buffer.from([]); // r
+ const sIndex = 8;
+ tx.raw[sIndex] = Buffer.from([]); // s
const txHex = tx.serialize().toString('hex');
try {
@@ -127,7 +130,8 @@ export class LedgerSubprovider extends BaseWalletSubprovider {
tx.v = Buffer.from(result.v, 'hex');
// EIP155: v should be chain_id * 2 + {35, 36}
- const signedChainId = Math.floor((tx.v[0] - 35) / 2);
+ const eip55Constant = 35;
+ const signedChainId = Math.floor((tx.v[0] - eip55Constant) / 2);
if (signedChainId !== this._networkId) {
await this._destroyLedgerClientAsync();
const err = new Error(LedgerSubproviderErrors.TooOldLedgerFirmware);
@@ -169,8 +173,10 @@ export class LedgerSubprovider extends BaseWalletSubprovider {
fullDerivationPath,
ethUtil.stripHexPrefix(data),
);
- const v = result.v - 27;
- let vHex = v.toString(16);
+ const lowestValidV = 27;
+ const v = result.v - lowestValidV;
+ const hexBase = 16;
+ let vHex = v.toString(hexBase);
if (vHex.length < 2) {
vHex = `0${v}`;
}
diff --git a/packages/subproviders/src/subproviders/nonce_tracker.ts b/packages/subproviders/src/subproviders/nonce_tracker.ts
index 907330111..345e5e975 100644
--- a/packages/subproviders/src/subproviders/nonce_tracker.ts
+++ b/packages/subproviders/src/subproviders/nonce_tracker.ts
@@ -93,7 +93,8 @@ export class NonceTrackerSubprovider extends Subprovider {
// Increment the nonce from the previous successfully submitted transaction
let nonce = ethUtil.bufferToInt(transaction.nonce);
nonce++;
- let nextHexNonce = nonce.toString(16);
+ const hexBase = 16;
+ let nextHexNonce = nonce.toString(hexBase);
if (nextHexNonce.length % 2) {
nextHexNonce = `0${nextHexNonce}`;
}
diff --git a/packages/subproviders/src/subproviders/subprovider.ts b/packages/subproviders/src/subproviders/subprovider.ts
index 56d2381a0..cb6dffc4a 100644
--- a/packages/subproviders/src/subproviders/subprovider.ts
+++ b/packages/subproviders/src/subproviders/subprovider.ts
@@ -13,10 +13,11 @@ export abstract class Subprovider {
// Ported from: https://github.com/MetaMask/provider-engine/blob/master/util/random-id.js
private static _getRandomId(): number {
const extraDigits = 3;
+ const baseTen = 10;
// 13 time digits
- const datePart = new Date().getTime() * Math.pow(10, extraDigits);
+ const datePart = new Date().getTime() * Math.pow(baseTen, extraDigits);
// 3 random digits
- const extraPart = Math.floor(Math.random() * Math.pow(10, extraDigits));
+ const extraPart = Math.floor(Math.random() * Math.pow(baseTen, extraDigits));
// 16 digits
return datePart + extraPart;
}
diff --git a/packages/subproviders/src/utils/subprovider_utils.ts b/packages/subproviders/src/utils/subprovider_utils.ts
new file mode 100644
index 000000000..24ebedd06
--- /dev/null
+++ b/packages/subproviders/src/utils/subprovider_utils.ts
@@ -0,0 +1,15 @@
+import ProviderEngine = require('web3-provider-engine');
+
+import { Subprovider } from '../subproviders/subprovider';
+
+/**
+ * Prepends a subprovider to a provider
+ * @param provider Given provider
+ * @param subprovider Subprovider to prepend
+ */
+export function prependSubprovider(provider: ProviderEngine, subprovider: Subprovider): void {
+ subprovider.setEngine(provider);
+ // HACK: We use implementation details of provider engine here
+ // https://github.com/MetaMask/provider-engine/blob/master/index.js#L68
+ (provider as any)._providers = [subprovider, ...(provider as any)._providers];
+}
diff --git a/packages/subproviders/src/utils/wallet_utils.ts b/packages/subproviders/src/utils/wallet_utils.ts
index cd5cd9ba0..c36fdb9fc 100644
--- a/packages/subproviders/src/utils/wallet_utils.ts
+++ b/packages/subproviders/src/utils/wallet_utils.ts
@@ -30,10 +30,10 @@ class DerivedHDKeyInfoIterator implements IterableIterator<DerivedHDKeyInfo> {
baseDerivationPath,
derivationPath: fullDerivationPath,
};
- const done = this._index === this._searchLimit;
+ const isDone = this._index === this._searchLimit;
this._index++;
return {
- done,
+ done: isDone,
value: derivedKey,
};
}
diff --git a/packages/subproviders/test/integration/ledger_subprovider_test.ts b/packages/subproviders/test/integration/ledger_subprovider_test.ts
index 70fd2cfce..d3e9d0fde 100644
--- a/packages/subproviders/test/integration/ledger_subprovider_test.ts
+++ b/packages/subproviders/test/integration/ledger_subprovider_test.ts
@@ -20,6 +20,8 @@ import { reportCallbackErrors } from '../utils/report_callback_errors';
chaiSetup.configure();
const expect = chai.expect;
+const DEFAULT_NUM_ACCOUNTS = 10;
+const EXPECTED_SIGNATURE_LENGTH = 132;
async function ledgerEthereumNodeJsClientFactoryAsync(): Promise<LedgerEthereumClient> {
const ledgerConnection = await TransportNodeHid.create();
@@ -41,7 +43,7 @@ describe('LedgerSubprovider', () => {
it('returns default number of accounts', async () => {
const accounts = await ledgerSubprovider.getAccountsAsync();
expect(accounts[0]).to.not.be.an('undefined');
- expect(accounts.length).to.be.equal(10);
+ expect(accounts.length).to.be.equal(DEFAULT_NUM_ACCOUNTS);
});
it('returns the expected accounts from a ledger set up with the test mnemonic', async () => {
const accounts = await ledgerSubprovider.getAccountsAsync();
@@ -105,7 +107,7 @@ describe('LedgerSubprovider', () => {
};
const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => {
expect(err).to.be.a('null');
- expect(response.result.length).to.be.equal(10);
+ expect(response.result.length).to.be.equal(DEFAULT_NUM_ACCOUNTS);
done();
});
ledgerProvider.sendAsync(payload, callback);
@@ -123,7 +125,7 @@ describe('LedgerSubprovider', () => {
};
const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => {
expect(err).to.be.a('null');
- expect(response.result.length).to.be.equal(132);
+ expect(response.result.length).to.be.equal(EXPECTED_SIGNATURE_LENGTH);
expect(response.result.substr(0, 2)).to.be.equal('0x');
done();
});
@@ -143,7 +145,7 @@ describe('LedgerSubprovider', () => {
};
const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => {
expect(err).to.be.a('null');
- expect(response.result.length).to.be.equal(132);
+ expect(response.result.length).to.be.equal(EXPECTED_SIGNATURE_LENGTH);
expect(response.result.substr(0, 2)).to.be.equal('0x');
done();
});
@@ -197,7 +199,8 @@ describe('LedgerSubprovider', () => {
const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => {
expect(err).to.be.a('null');
const result = response.result;
- expect(result.length).to.be.equal(66);
+ const signedTxLength = 66;
+ expect(result.length).to.be.equal(signedTxLength);
expect(result.substr(0, 2)).to.be.equal('0x');
done();
});
diff --git a/packages/subproviders/test/unit/ledger_subprovider_test.ts b/packages/subproviders/test/unit/ledger_subprovider_test.ts
index 6455454cb..8571f7d11 100644
--- a/packages/subproviders/test/unit/ledger_subprovider_test.ts
+++ b/packages/subproviders/test/unit/ledger_subprovider_test.ts
@@ -21,6 +21,7 @@ import { reportCallbackErrors } from '../utils/report_callback_errors';
chaiSetup.configure();
const expect = chai.expect;
const FAKE_ADDRESS = '0xb088a3bc93f71b4de97b9de773e9647645983688';
+const DEFAULT_NUM_ACCOUNTS = 10;
describe('LedgerSubprovider', () => {
const networkId: number = 42;
@@ -73,7 +74,7 @@ describe('LedgerSubprovider', () => {
it('returns default number of accounts', async () => {
const accounts = await ledgerSubprovider.getAccountsAsync();
expect(accounts[0]).to.be.equal(FAKE_ADDRESS);
- expect(accounts.length).to.be.equal(10);
+ expect(accounts.length).to.be.equal(DEFAULT_NUM_ACCOUNTS);
});
it('returns requested number of accounts', async () => {
const numberOfAccounts = 20;
@@ -119,7 +120,7 @@ describe('LedgerSubprovider', () => {
};
const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => {
expect(err).to.be.a('null');
- expect(response.result.length).to.be.equal(10);
+ expect(response.result.length).to.be.equal(DEFAULT_NUM_ACCOUNTS);
expect(response.result[0]).to.be.equal(FAKE_ADDRESS);
done();
});
@@ -176,7 +177,8 @@ describe('LedgerSubprovider', () => {
};
const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => {
expect(err).to.be.a('null');
- expect(response.result.raw.length).to.be.equal(192);
+ const rawTxLength = 192;
+ expect(response.result.raw.length).to.be.equal(rawTxLength);
expect(response.result.raw.substr(0, 2)).to.be.equal('0x');
done();
});
diff --git a/packages/subproviders/test/unit/mnemonic_wallet_subprovider_test.ts b/packages/subproviders/test/unit/mnemonic_wallet_subprovider_test.ts
index 52b636ac2..90565181e 100644
--- a/packages/subproviders/test/unit/mnemonic_wallet_subprovider_test.ts
+++ b/packages/subproviders/test/unit/mnemonic_wallet_subprovider_test.ts
@@ -18,6 +18,7 @@ import { reportCallbackErrors } from '../utils/report_callback_errors';
chaiSetup.configure();
const expect = chai.expect;
+const DEFAULT_NUM_ACCOUNTS = 10;
describe('MnemonicWalletSubprovider', () => {
let subprovider: MnemonicWalletSubprovider;
@@ -33,7 +34,7 @@ describe('MnemonicWalletSubprovider', () => {
const accounts = await subprovider.getAccountsAsync();
expect(accounts[0]).to.be.equal(fixtureData.TEST_RPC_ACCOUNT_0);
expect(accounts[1]).to.be.equal(fixtureData.TEST_RPC_ACCOUNT_1);
- expect(accounts.length).to.be.equal(10);
+ expect(accounts.length).to.be.equal(DEFAULT_NUM_ACCOUNTS);
});
it('signs a personal message', async () => {
const data = ethUtils.bufferToHex(ethUtils.toBuffer(fixtureData.PERSONAL_MESSAGE_STRING));
@@ -90,7 +91,7 @@ describe('MnemonicWalletSubprovider', () => {
const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => {
expect(err).to.be.a('null');
expect(response.result[0]).to.be.equal(fixtureData.TEST_RPC_ACCOUNT_0);
- expect(response.result.length).to.be.equal(10);
+ expect(response.result.length).to.be.equal(DEFAULT_NUM_ACCOUNTS);
done();
});
provider.sendAsync(payload, callback);
diff --git a/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts b/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts
index f9c47f141..fdbbb332c 100644
--- a/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts
+++ b/packages/subproviders/test/unit/redundant_rpc_subprovider_test.ts
@@ -14,6 +14,7 @@ import { reportCallbackErrors } from '../utils/report_callback_errors';
const expect = chai.expect;
chaiSetup.configure();
+const DEFAULT_NUM_ACCOUNTS = 10;
describe('RedundantSubprovider', () => {
let provider: Web3ProviderEngine;
@@ -32,7 +33,7 @@ describe('RedundantSubprovider', () => {
};
const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => {
expect(err).to.be.a('null');
- expect(response.result.length).to.be.equal(10);
+ expect(response.result.length).to.be.equal(DEFAULT_NUM_ACCOUNTS);
done();
});
provider.sendAsync(payload, callback);
@@ -55,7 +56,7 @@ describe('RedundantSubprovider', () => {
};
const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => {
expect(err).to.be.a('null');
- expect(response.result.length).to.be.equal(10);
+ expect(response.result.length).to.be.equal(DEFAULT_NUM_ACCOUNTS);
done();
});
provider.sendAsync(payload, callback);