aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--packages/contract-wrappers/src/utils/decorators.ts8
-rw-r--r--packages/contract-wrappers/src/utils/exchange_transfer_simulator.ts3
-rw-r--r--packages/contract-wrappers/src/utils/filter_utils.ts4
-rw-r--r--packages/contract-wrappers/test/ether_token_wrapper_test.ts4
-rw-r--r--packages/contract-wrappers/test/exchange_wrapper_test.ts4
-rw-r--r--packages/contract-wrappers/test/subscription_test.ts2
-rw-r--r--packages/contract-wrappers/test/token_wrapper_test.ts4
-rw-r--r--packages/order-watcher/src/order_watcher/order_watcher.ts14
-rw-r--r--packages/subproviders/CHANGELOG.json8
-rw-r--r--packages/subproviders/package.json4
-rw-r--r--packages/subproviders/src/globals.d.ts5
-rw-r--r--packages/subproviders/src/index.ts1
-rw-r--r--packages/subproviders/src/subproviders/eth_lightwallet_subprovider.ts73
-rw-r--r--packages/subproviders/test/unit/eth_lightwallet_subprovider_test.ts167
-rw-r--r--packages/subproviders/test/unit/private_key_wallet_subprovider_test.ts14
-rw-r--r--packages/types/CHANGELOG.json3
-rw-r--r--packages/types/src/index.ts6
-rw-r--r--packages/typescript-typings/CHANGELOG.json4
-rw-r--r--packages/typescript-typings/types/eth-lightwallet/index.d.ts50
-rw-r--r--yarn.lock101
20 files changed, 440 insertions, 39 deletions
diff --git a/packages/contract-wrappers/src/utils/decorators.ts b/packages/contract-wrappers/src/utils/decorators.ts
index 494575e7b..ccb4c6e11 100644
--- a/packages/contract-wrappers/src/utils/decorators.ts
+++ b/packages/contract-wrappers/src/utils/decorators.ts
@@ -30,8 +30,8 @@ const schemaErrorTransformer = (error: Error) => {
*/
const asyncErrorHandlerFactory = (errorTransformer: ErrorTransformer) => {
const asyncErrorHandlingDecorator = (
- target: object,
- key: string | symbol,
+ _target: object,
+ _key: string | symbol,
descriptor: TypedPropertyDescriptor<AsyncMethod>,
) => {
const originalMethod = descriptor.value as AsyncMethod;
@@ -57,8 +57,8 @@ const asyncErrorHandlerFactory = (errorTransformer: ErrorTransformer) => {
const syncErrorHandlerFactory = (errorTransformer: ErrorTransformer) => {
const syncErrorHandlingDecorator = (
- target: object,
- key: string | symbol,
+ _target: object,
+ _key: string | symbol,
descriptor: TypedPropertyDescriptor<SyncMethod>,
) => {
const originalMethod = descriptor.value as SyncMethod;
diff --git a/packages/contract-wrappers/src/utils/exchange_transfer_simulator.ts b/packages/contract-wrappers/src/utils/exchange_transfer_simulator.ts
index 527b8575d..279f2a796 100644
--- a/packages/contract-wrappers/src/utils/exchange_transfer_simulator.ts
+++ b/packages/contract-wrappers/src/utils/exchange_transfer_simulator.ts
@@ -1,8 +1,7 @@
-import { BlockParamLiteral, ExchangeContractErrs } from '@0xproject/types';
+import { ExchangeContractErrs } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import { AbstractBalanceAndProxyAllowanceLazyStore } from '../abstract/abstract_balance_and_proxy_allowance_lazy_store';
-import { TokenWrapper } from '../contract_wrappers/token_wrapper';
import { TradeSide, TransferType } from '../types';
import { constants } from '../utils/constants';
diff --git a/packages/contract-wrappers/src/utils/filter_utils.ts b/packages/contract-wrappers/src/utils/filter_utils.ts
index 5256d010f..f96dc573f 100644
--- a/packages/contract-wrappers/src/utils/filter_utils.ts
+++ b/packages/contract-wrappers/src/utils/filter_utils.ts
@@ -30,7 +30,7 @@ export const filterUtils = {
blockRange?: BlockRange,
): FilterObject {
const eventAbi = _.find(abi, { name: eventName }) as EventAbi;
- const eventSignature = filterUtils.getEventSignatureFromAbiByName(eventAbi, eventName);
+ const eventSignature = filterUtils.getEventSignatureFromAbiByName(eventAbi);
const topicForEventSignature = ethUtil.addHexPrefix(jsSHA3.keccak256(eventSignature));
const topicsForIndexedArgs = filterUtils.getTopicsForIndexedArgs(eventAbi, indexFilterValues);
const topics = [topicForEventSignature, ...topicsForIndexedArgs];
@@ -46,7 +46,7 @@ export const filterUtils = {
}
return filter;
},
- getEventSignatureFromAbiByName(eventAbi: EventAbi, eventName: ContractEvents): string {
+ getEventSignatureFromAbiByName(eventAbi: EventAbi): string {
const types = _.map(eventAbi.inputs, 'type');
const signature = `${eventAbi.name}(${types.join(',')})`;
return signature;
diff --git a/packages/contract-wrappers/test/ether_token_wrapper_test.ts b/packages/contract-wrappers/test/ether_token_wrapper_test.ts
index b13ac72bb..f401ef90a 100644
--- a/packages/contract-wrappers/test/ether_token_wrapper_test.ts
+++ b/packages/contract-wrappers/test/ether_token_wrapper_test.ts
@@ -277,7 +277,7 @@ describe('EtherTokenWrapper', () => {
it('should cancel outstanding subscriptions when ZeroEx.setProvider is called', (done: DoneCallback) => {
(async () => {
const callbackNeverToBeCalled = callbackErrorReporter.reportNodeCallbackErrors(done)(
- (logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
+ (_logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
done(new Error('Expected this subscription to have been cancelled'));
},
);
@@ -307,7 +307,7 @@ describe('EtherTokenWrapper', () => {
it('Should cancel subscription when unsubscribe called', (done: DoneCallback) => {
(async () => {
const callbackNeverToBeCalled = callbackErrorReporter.reportNodeCallbackErrors(done)(
- (logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
+ (_logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
done(new Error('Expected this subscription to have been cancelled'));
},
);
diff --git a/packages/contract-wrappers/test/exchange_wrapper_test.ts b/packages/contract-wrappers/test/exchange_wrapper_test.ts
index cf69d4813..c945b4c70 100644
--- a/packages/contract-wrappers/test/exchange_wrapper_test.ts
+++ b/packages/contract-wrappers/test/exchange_wrapper_test.ts
@@ -999,7 +999,7 @@ describe('ExchangeWrapper', () => {
it('Outstanding subscriptions are cancelled when contractWrappers.setProvider called', (done: DoneCallback) => {
(async () => {
const callbackNeverToBeCalled = callbackErrorReporter.reportNodeCallbackErrors(done)(
- (logEvent: DecodedLogEvent<LogFillContractEventArgs>) => {
+ (_logEvent: DecodedLogEvent<LogFillContractEventArgs>) => {
done(new Error('Expected this subscription to have been cancelled'));
},
);
@@ -1024,7 +1024,7 @@ describe('ExchangeWrapper', () => {
it('Should cancel subscription when unsubscribe called', (done: DoneCallback) => {
(async () => {
const callbackNeverToBeCalled = callbackErrorReporter.reportNodeCallbackErrors(done)(
- (logEvent: DecodedLogEvent<LogFillContractEventArgs>) => {
+ (_logEvent: DecodedLogEvent<LogFillContractEventArgs>) => {
done(new Error('Expected this subscription to have been cancelled'));
},
);
diff --git a/packages/contract-wrappers/test/subscription_test.ts b/packages/contract-wrappers/test/subscription_test.ts
index 4d638bf9b..b9417ca3d 100644
--- a/packages/contract-wrappers/test/subscription_test.ts
+++ b/packages/contract-wrappers/test/subscription_test.ts
@@ -80,7 +80,7 @@ describe('SubscriptionTest', () => {
});
it('Should allow unsubscribeAll to be called successfully after an error', (done: DoneCallback) => {
(async () => {
- const callback = (err: Error | null, logEvent?: DecodedLogEvent<ApprovalContractEventArgs>) => _.noop;
+ const callback = (_err: Error | null, _logEvent?: DecodedLogEvent<ApprovalContractEventArgs>) => _.noop;
contractWrappers.token.subscribe(tokenAddress, TokenEvents.Approval, indexFilterValues, callback);
stubs = [
Sinon.stub((contractWrappers as any)._web3Wrapper, 'getBlockAsync').throws(
diff --git a/packages/contract-wrappers/test/token_wrapper_test.ts b/packages/contract-wrappers/test/token_wrapper_test.ts
index c9722c7b4..86b93b3f9 100644
--- a/packages/contract-wrappers/test/token_wrapper_test.ts
+++ b/packages/contract-wrappers/test/token_wrapper_test.ts
@@ -484,7 +484,7 @@ describe('TokenWrapper', () => {
it('Outstanding subscriptions are cancelled when contractWrappers.setProvider called', (done: DoneCallback) => {
(async () => {
const callbackNeverToBeCalled = callbackErrorReporter.reportNodeCallbackErrors(done)(
- (logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
+ (_logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
done(new Error('Expected this subscription to have been cancelled'));
},
);
@@ -508,7 +508,7 @@ describe('TokenWrapper', () => {
it('Should cancel subscription when unsubscribe called', (done: DoneCallback) => {
(async () => {
const callbackNeverToBeCalled = callbackErrorReporter.reportNodeCallbackErrors(done)(
- (logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
+ (_logEvent: DecodedLogEvent<ApprovalContractEventArgs>) => {
done(new Error('Expected this subscription to have been cancelled'));
},
);
diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts
index 140aa341b..3418b4ee9 100644
--- a/packages/order-watcher/src/order_watcher/order_watcher.ts
+++ b/packages/order-watcher/src/order_watcher/order_watcher.ts
@@ -1,7 +1,10 @@
import {
BalanceAndProxyAllowanceLazyStore,
ContractWrappers,
+ LogCancelContractEventArgs,
+ LogFillContractEventArgs,
OrderFilledCancelledLazyStore,
+ WithdrawalContractEventArgs,
} from '@0xproject/contract-wrappers';
import { schemas } from '@0xproject/json-schemas';
import { getOrderHashHex, OrderStateUtils } from '@0xproject/order-utils';
@@ -23,14 +26,8 @@ import {
DepositContractEventArgs,
EtherTokenContractEventArgs,
EtherTokenEvents,
- WithdrawalContractEventArgs,
} from '../generated_contract_wrappers/ether_token';
-import {
- ExchangeContractEventArgs,
- ExchangeEvents,
- LogCancelContractEventArgs,
- LogFillContractEventArgs,
-} from '../generated_contract_wrappers/exchange';
+import { ExchangeContractEventArgs, ExchangeEvents } from '../generated_contract_wrappers/exchange';
import {
ApprovalContractEventArgs,
TokenContractEventArgs,
@@ -301,6 +298,7 @@ export class OrderWatcher {
}
case EtherTokenEvents.Withdrawal: {
// Invalidate cache
+ // tslint:disable-next-line
const args = decodedLog.args as WithdrawalContractEventArgs;
this._balanceAndProxyAllowanceLazyStore.deleteBalance(decodedLog.address, args._owner);
// Revalidate orders
@@ -317,6 +315,7 @@ export class OrderWatcher {
}
case ExchangeEvents.LogFill: {
// Invalidate cache
+ // tslint:disable-next-line
const args = decodedLog.args as LogFillContractEventArgs;
this._orderFilledCancelledLazyStore.deleteFilledTakerAmount(args.orderHash);
// Revalidate orders
@@ -329,6 +328,7 @@ export class OrderWatcher {
}
case ExchangeEvents.LogCancel: {
// Invalidate cache
+ // tslint:disable-next-line
const args = decodedLog.args as LogCancelContractEventArgs;
this._orderFilledCancelledLazyStore.deleteCancelledTakerAmount(args.orderHash);
// Revalidate orders
diff --git a/packages/subproviders/CHANGELOG.json b/packages/subproviders/CHANGELOG.json
index 65a74f7a8..c4dca2864 100644
--- a/packages/subproviders/CHANGELOG.json
+++ b/packages/subproviders/CHANGELOG.json
@@ -1,5 +1,13 @@
[
{
+ "version": "0.11.0",
+ "changes": [
+ {
+ "note": "Add `EthLightwalletSubprovider`"
+ }
+ ]
+ },
+ {
"timestamp": 1529397769,
"version": "0.10.4",
"changes": [
diff --git a/packages/subproviders/package.json b/packages/subproviders/package.json
index e87d7bf94..651d0e708 100644
--- a/packages/subproviders/package.json
+++ b/packages/subproviders/package.json
@@ -41,14 +41,14 @@
},
"dependencies": {
"@0xproject/assert": "^0.2.12",
- "@0xproject/types": "^0.8.1",
- "@0xproject/typescript-typings": "^0.4.1",
+ "@0xproject/types": "^1.0.0",
"@0xproject/utils": "^0.7.1",
"@ledgerhq/hw-app-eth": "^4.3.0",
"@ledgerhq/hw-transport-u2f": "^4.3.0",
"ethereum-types": "^0.0.2",
"bip39": "^2.5.0",
"bn.js": "^4.11.8",
+ "eth-lightwallet": "^3.0.1",
"ethereumjs-tx": "^1.3.5",
"ethereumjs-util": "^5.1.1",
"ganache-core": "0xProject/ganache-core",
diff --git a/packages/subproviders/src/globals.d.ts b/packages/subproviders/src/globals.d.ts
index c00dc4099..94e63a32d 100644
--- a/packages/subproviders/src/globals.d.ts
+++ b/packages/subproviders/src/globals.d.ts
@@ -1,8 +1,3 @@
-// tslint:disable:max-classes-per-file
-// tslint:disable:class-name
-// tslint:disable:async-suffix
-// tslint:disable:completed-docs
-
declare module '*.json' {
const json: any;
/* tslint:disable */
diff --git a/packages/subproviders/src/index.ts b/packages/subproviders/src/index.ts
index 9194c1341..802a27cb1 100644
--- a/packages/subproviders/src/index.ts
+++ b/packages/subproviders/src/index.ts
@@ -15,6 +15,7 @@ export { Subprovider } from './subproviders/subprovider';
export { NonceTrackerSubprovider } from './subproviders/nonce_tracker';
export { PrivateKeyWalletSubprovider } from './subproviders/private_key_wallet';
export { MnemonicWalletSubprovider } from './subproviders/mnemonic_wallet';
+export { EthLightwalletSubprovider } from './subproviders/eth_lightwallet_subprovider';
export {
Callback,
ErrorCallback,
diff --git a/packages/subproviders/src/subproviders/eth_lightwallet_subprovider.ts b/packages/subproviders/src/subproviders/eth_lightwallet_subprovider.ts
new file mode 100644
index 000000000..3cd94dac3
--- /dev/null
+++ b/packages/subproviders/src/subproviders/eth_lightwallet_subprovider.ts
@@ -0,0 +1,73 @@
+import { assert } from '@0xproject/assert';
+import { addressUtils } from '@0xproject/utils';
+import * as lightwallet from 'eth-lightwallet';
+import EthereumTx = require('ethereumjs-tx');
+import * as ethUtil from 'ethereumjs-util';
+import * as _ from 'lodash';
+
+import { PartialTxParams, WalletSubproviderErrors } from '../types';
+
+import { BaseWalletSubprovider } from './base_wallet_subprovider';
+import { PrivateKeyWalletSubprovider } from './private_key_wallet';
+
+/*
+ * This class implements the web3-provider-engine subprovider interface and forwards
+ * requests involving user accounts and signing operations to eth-lightwallet
+ *
+ * Source: https://github.com/MetaMask/provider-engine/blob/master/subproviders/subprovider.js
+ */
+export class EthLightwalletSubprovider extends BaseWalletSubprovider {
+ private _keystore: lightwallet.keystore;
+ private _pwDerivedKey: Uint8Array;
+ constructor(keystore: lightwallet.keystore, pwDerivedKey: Uint8Array) {
+ super();
+ this._keystore = keystore;
+ this._pwDerivedKey = pwDerivedKey;
+ }
+ /**
+ * Retrieve the accounts associated with the eth-lightwallet instance.
+ * This method is implicitly called when issuing a `eth_accounts` JSON RPC request
+ * via your providerEngine instance.
+ *
+ * @return An array of accounts
+ */
+ public async getAccountsAsync(): Promise<string[]> {
+ const accounts = this._keystore.getAddresses();
+ return accounts;
+ }
+ /**
+ * Signs a transaction with the account specificed by the `from` field in txParams.
+ * If you've added this Subprovider to your app's provider, you can simply send
+ * an `eth_sendTransaction` JSON RPC request, and this method will be called auto-magically.
+ * If you are not using this via a ProviderEngine instance, you can call it directly.
+ * @param txParams Parameters of the transaction to sign
+ * @return Signed transaction hex string
+ */
+ public async signTransactionAsync(txParams: PartialTxParams): Promise<string> {
+ // Lightwallet loses the chain id information when hex encoding the transaction
+ // this results in a different signature on certain networks. PrivateKeyWallet
+ // respects this as it uses the parameters passed in
+ let privKey = this._keystore.exportPrivateKey(txParams.from, this._pwDerivedKey);
+ const privKeyWallet = new PrivateKeyWalletSubprovider(privKey);
+ privKey = '';
+ const privKeySignature = await privKeyWallet.signTransactionAsync(txParams);
+ return privKeySignature;
+ }
+ /**
+ * Sign a personal Ethereum signed message. The signing account will be the account
+ * associated with the provided address.
+ * If you've added the MnemonicWalletSubprovider to your app's provider, you can simply send an `eth_sign`
+ * or `personal_sign` JSON RPC request, and this method will be called auto-magically.
+ * If you are not using this via a ProviderEngine instance, you can call it directly.
+ * @param data Hex string message to sign
+ * @param address Address of the account to sign with
+ * @return Signature hex string (order: rsv)
+ */
+ public async signPersonalMessageAsync(data: string, address: string): Promise<string> {
+ let privKey = this._keystore.exportPrivateKey(address, this._pwDerivedKey);
+ const privKeyWallet = new PrivateKeyWalletSubprovider(privKey);
+ privKey = '';
+ const result = privKeyWallet.signPersonalMessageAsync(data, address);
+ return result;
+ }
+}
diff --git a/packages/subproviders/test/unit/eth_lightwallet_subprovider_test.ts b/packages/subproviders/test/unit/eth_lightwallet_subprovider_test.ts
new file mode 100644
index 000000000..f17c21f02
--- /dev/null
+++ b/packages/subproviders/test/unit/eth_lightwallet_subprovider_test.ts
@@ -0,0 +1,167 @@
+import * as chai from 'chai';
+import * as lightwallet from 'eth-lightwallet';
+import { JSONRPCResponsePayload } from 'ethereum-types';
+import * as ethUtils from 'ethereumjs-util';
+import Web3ProviderEngine = require('web3-provider-engine');
+
+import { EthLightwalletSubprovider } from '../../src';
+import { DoneCallback } from '../../src/types';
+import { chaiSetup } from '../chai_setup';
+import { fixtureData } from '../utils/fixture_data';
+import { ganacheSubprovider } from '../utils/ganache_subprovider';
+import { reportCallbackErrors } from '../utils/report_callback_errors';
+
+chaiSetup.configure();
+const expect = chai.expect;
+
+const DEFAULT_NUM_ACCOUNTS = 10;
+const PASSWORD = 'supersecretpassword99';
+const SALT = 'kvODghzs7Ff1uqHyI0P3wI4Hso4w4iWT2e9qmrWz0y4';
+
+describe('EthLightwalletSubprovider', () => {
+ let ethLightwalletSubprovider: EthLightwalletSubprovider;
+ before(async () => {
+ const options = {
+ password: PASSWORD,
+ seedPhrase: fixtureData.TEST_RPC_MNEMONIC,
+ salt: SALT,
+ hdPathString: fixtureData.TESTRPC_BASE_DERIVATION_PATH,
+ };
+ const createVaultAsync = async (vaultOptions: lightwallet.VaultOptions) => {
+ return new Promise<lightwallet.keystore>(resolve => {
+ lightwallet.keystore.createVault(vaultOptions, (err: Error, vaultKeystore) => {
+ if (err) {
+ throw new Error(`Failed to createVault: ${err}`);
+ }
+ resolve(vaultKeystore);
+ });
+ });
+ };
+ const deriveKeyFromPasswordAsync = async (vaultKeystore: lightwallet.keystore) => {
+ return new Promise<Uint8Array>(resolve => {
+ vaultKeystore.keyFromPassword(PASSWORD, (err: Error, passwordDerivedKey: Uint8Array) => {
+ if (err) {
+ throw new Error(`Failed to get key from password: ${err}`);
+ }
+ resolve(passwordDerivedKey);
+ });
+ });
+ };
+ const keystore: lightwallet.keystore = await createVaultAsync(options);
+ const pwDerivedKey: Uint8Array = await deriveKeyFromPasswordAsync(keystore);
+
+ // Generate 10 addresses
+ keystore.generateNewAddress(pwDerivedKey, DEFAULT_NUM_ACCOUNTS);
+
+ ethLightwalletSubprovider = new EthLightwalletSubprovider(keystore, pwDerivedKey);
+ });
+ describe('direct method calls', () => {
+ describe('success cases', () => {
+ it('returns a list of accounts', async () => {
+ const accounts = await ethLightwalletSubprovider.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(DEFAULT_NUM_ACCOUNTS);
+ });
+ it('signs a personal message hash', async () => {
+ const accounts = await ethLightwalletSubprovider.getAccountsAsync();
+ const signingAccount = accounts[0];
+ const data = ethUtils.bufferToHex(ethUtils.toBuffer(fixtureData.PERSONAL_MESSAGE_STRING));
+ const ecSignatureHex = await ethLightwalletSubprovider.signPersonalMessageAsync(data, signingAccount);
+ expect(ecSignatureHex).to.be.equal(fixtureData.PERSONAL_MESSAGE_SIGNED_RESULT);
+ });
+ it('signs a transaction', async () => {
+ const txHex = await ethLightwalletSubprovider.signTransactionAsync(fixtureData.TX_DATA);
+ expect(txHex).to.be.equal(fixtureData.TX_DATA_SIGNED_RESULT);
+ });
+ });
+ });
+ describe('calls through a provider', () => {
+ let provider: Web3ProviderEngine;
+ before(() => {
+ provider = new Web3ProviderEngine();
+ provider.addProvider(ethLightwalletSubprovider);
+ provider.addProvider(ganacheSubprovider);
+ provider.start();
+ });
+ describe('success cases', () => {
+ it('returns a list of accounts', (done: DoneCallback) => {
+ const payload = {
+ jsonrpc: '2.0',
+ method: 'eth_accounts',
+ params: [],
+ id: 1,
+ };
+ 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(DEFAULT_NUM_ACCOUNTS);
+ done();
+ });
+ provider.sendAsync(payload, callback);
+ });
+ it('signs a personal message hash with eth_sign', (done: DoneCallback) => {
+ const data = ethUtils.bufferToHex(ethUtils.toBuffer(fixtureData.PERSONAL_MESSAGE_STRING));
+ const account = fixtureData.TEST_RPC_ACCOUNT_0;
+ const payload = {
+ jsonrpc: '2.0',
+ method: 'eth_sign',
+ params: [account, data],
+ id: 1,
+ };
+ const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => {
+ expect(err).to.be.a('null');
+ expect(response.result).to.be.equal(fixtureData.PERSONAL_MESSAGE_SIGNED_RESULT);
+ done();
+ });
+ provider.sendAsync(payload, callback);
+ });
+ it('signs a transaction', (done: DoneCallback) => {
+ const payload = {
+ jsonrpc: '2.0',
+ method: 'eth_signTransaction',
+ params: [fixtureData.TX_DATA],
+ id: 1,
+ };
+ const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => {
+ expect(err).to.be.a('null');
+ expect(response.result.raw).to.be.equal(fixtureData.TX_DATA_SIGNED_RESULT);
+ done();
+ });
+ provider.sendAsync(payload, callback);
+ });
+ });
+ describe('failure cases', () => {
+ it('should throw if `data` param not hex when calling eth_sign', (done: DoneCallback) => {
+ const nonHexMessage = 'hello world';
+ const payload = {
+ jsonrpc: '2.0',
+ method: 'eth_sign',
+ params: [fixtureData.TEST_RPC_ACCOUNT_0, nonHexMessage],
+ id: 1,
+ };
+ const callback = reportCallbackErrors(done)((err: Error, _response: JSONRPCResponsePayload) => {
+ expect(err).to.not.be.a('null');
+ expect(err.message).to.be.equal('Expected data to be of type HexString, encountered: hello world');
+ done();
+ });
+ provider.sendAsync(payload, callback);
+ });
+ it('should throw if `data` param not hex when calling personal_sign', (done: DoneCallback) => {
+ const nonHexMessage = 'hello world';
+ const payload = {
+ jsonrpc: '2.0',
+ method: 'personal_sign',
+ params: [nonHexMessage, fixtureData.TEST_RPC_ACCOUNT_0],
+ id: 1,
+ };
+ const callback = reportCallbackErrors(done)((err: Error, _response: JSONRPCResponsePayload) => {
+ expect(err).to.not.be.a('null');
+ expect(err.message).to.be.equal('Expected data to be of type HexString, encountered: hello world');
+ done();
+ });
+ provider.sendAsync(payload, callback);
+ });
+ });
+ });
+});
diff --git a/packages/subproviders/test/unit/private_key_wallet_subprovider_test.ts b/packages/subproviders/test/unit/private_key_wallet_subprovider_test.ts
index a41ad7790..ab321bcff 100644
--- a/packages/subproviders/test/unit/private_key_wallet_subprovider_test.ts
+++ b/packages/subproviders/test/unit/private_key_wallet_subprovider_test.ts
@@ -60,6 +60,20 @@ describe('PrivateKeyWalletSubprovider', () => {
});
provider.sendAsync(payload, callback);
});
+ it('signs a transaction', (done: DoneCallback) => {
+ const payload = {
+ jsonrpc: '2.0',
+ method: 'eth_signTransaction',
+ params: [fixtureData.TX_DATA],
+ id: 1,
+ };
+ const callback = reportCallbackErrors(done)((err: Error, response: JSONRPCResponsePayload) => {
+ expect(err).to.be.a('null');
+ expect(response.result.raw).to.be.equal(fixtureData.TX_DATA_SIGNED_RESULT);
+ done();
+ });
+ provider.sendAsync(payload, callback);
+ });
it('signs a personal message with eth_sign', (done: DoneCallback) => {
const messageHex = ethUtils.bufferToHex(ethUtils.toBuffer(fixtureData.PERSONAL_MESSAGE_STRING));
const payload = {
diff --git a/packages/types/CHANGELOG.json b/packages/types/CHANGELOG.json
index a0be5d7fe..46e67c970 100644
--- a/packages/types/CHANGELOG.json
+++ b/packages/types/CHANGELOG.json
@@ -4,6 +4,9 @@
"changes": [
{
"notes": "Updated types for V2 of 0x protocol"
+ },
+ {
+ "note": "Add `ECSignatureBuffer`"
}
]
},
diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts
index 4ad10fdee..9514320da 100644
--- a/packages/types/src/index.ts
+++ b/packages/types/src/index.ts
@@ -48,6 +48,12 @@ export interface ECSignature {
s: string;
}
+export interface ECSignatureBuffer {
+ v: number;
+ r: Buffer;
+ s: Buffer;
+}
+
/**
* Validator signature components
*/
diff --git a/packages/typescript-typings/CHANGELOG.json b/packages/typescript-typings/CHANGELOG.json
index 1f397e622..1d4230783 100644
--- a/packages/typescript-typings/CHANGELOG.json
+++ b/packages/typescript-typings/CHANGELOG.json
@@ -3,6 +3,10 @@
"version": "0.4.2",
"changes": [
{
+ "note": "Add types for `eth-lightwallet`",
+ "pr": 775
+ },
+ {
"note": "Improve 'web3-provider-engine' typings",
"pr": 768
},
diff --git a/packages/typescript-typings/types/eth-lightwallet/index.d.ts b/packages/typescript-typings/types/eth-lightwallet/index.d.ts
new file mode 100644
index 000000000..58096e9f4
--- /dev/null
+++ b/packages/typescript-typings/types/eth-lightwallet/index.d.ts
@@ -0,0 +1,50 @@
+// eth-lightwallet declarations
+declare module 'eth-lightwallet' {
+ import { ECSignatureBuffer } from '@0xproject/types';
+
+ // tslint:disable-next-line:class-name
+ export class signing {
+ public static signTx(
+ keystore: keystore,
+ pwDerivedKey: Uint8Array,
+ rawTx: string,
+ signingAddress: string,
+ ): string;
+ public static signMsg(
+ keystore: keystore,
+ pwDerivedKey: Uint8Array,
+ rawMsg: string,
+ signingAddress: string,
+ ): ECSignatureBuffer;
+ public static signMsgHash(
+ keystore: keystore,
+ pwDerivedKey: Uint8Array,
+ msgHash: string,
+ signingAddress: string,
+ ): ECSignatureBuffer;
+ public static concatSig(signature: any): string;
+ }
+ // tslint:disable-next-line:class-name
+ export class keystore {
+ public static createVault(options: any, callback?: (error: Error, keystore: keystore) => void): keystore;
+ public static generateRandomSeed(): string;
+ public static isSeedValid(seed: string): boolean;
+ public static deserialize(keystore: string): keystore;
+ public serialize(): string;
+ public keyFromPassword(
+ password: string,
+ callback?: (error: Error, pwDerivedKey: Uint8Array) => void,
+ ): Uint8Array;
+ public isDerivedKeyCorrect(pwDerivedKey: Uint8Array): boolean;
+ public generateNewAddress(pwDerivedKey: Uint8Array, numberOfAddresses: number): void;
+ public getSeed(pwDerivedKey: Uint8Array): string;
+ public exportPrivateKey(address: string, pwDerivedKey: Uint8Array): string;
+ public getAddresses(): string[];
+ }
+ interface VaultOptions {
+ password: string;
+ seedPhrase: string;
+ salt?: string;
+ hdPathString: string;
+ }
+}
diff --git a/yarn.lock b/yarn.lock
index 4570dd774..10135fa86 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -330,7 +330,7 @@
"@types/mocha@^5.2.2":
version "5.2.3"
- resolved "https://registry.npmjs.org/@types/mocha/-/mocha-5.2.3.tgz#11f3a5629d67cd444fa6c94536576244e6a52ea9"
+ resolved "https://registry.yarnpkg.com/@types/mocha/-/mocha-5.2.3.tgz#11f3a5629d67cd444fa6c94536576244e6a52ea9"
"@types/nock@^9.1.2":
version "9.1.3"
@@ -1608,6 +1608,12 @@ base-x@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/base-x/-/base-x-1.1.0.tgz#42d3d717474f9ea02207f6d1aa1f426913eeb7ac"
+base-x@^3.0.2:
+ version "3.0.4"
+ resolved "https://registry.yarnpkg.com/base-x/-/base-x-3.0.4.tgz#94c1788736da065edb1d68808869e357c977fa77"
+ dependencies:
+ safe-buffer "^5.0.1"
+
base64-js@0.0.8:
version "0.0.8"
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-0.0.8.tgz#1101e9544f4a76b1bc3b26d452ca96d7a35e7978"
@@ -1760,6 +1766,24 @@ bip66@^1.1.3:
dependencies:
safe-buffer "^5.0.1"
+bitcore-lib@^0.15.0:
+ version "0.15.0"
+ resolved "https://registry.yarnpkg.com/bitcore-lib/-/bitcore-lib-0.15.0.tgz#f924be13869f2aab7e04aeec5642ad3359b6cec2"
+ dependencies:
+ bn.js "=4.11.8"
+ bs58 "=4.0.1"
+ buffer-compare "=1.1.1"
+ elliptic "=6.4.0"
+ inherits "=2.0.1"
+ lodash "=4.17.4"
+
+bitcore-mnemonic@^1.5.0:
+ version "1.5.0"
+ resolved "https://registry.yarnpkg.com/bitcore-mnemonic/-/bitcore-mnemonic-1.5.0.tgz#c7e785beb6bf0616ed4992785dc3658670425a39"
+ dependencies:
+ bitcore-lib "^0.15.0"
+ unorm "^1.3.3"
+
bl@^1.0.0:
version "1.2.2"
resolved "https://registry.yarnpkg.com/bl/-/bl-1.2.2.tgz#a160911717103c07410cef63ef51b397c025af9c"
@@ -1805,10 +1829,14 @@ bn.js@4.11.7:
version "4.11.7"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.7.tgz#ddb048e50d9482790094c13eb3fcfc833ce7ab46"
-bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.10.0, bn.js@^4.11.0, bn.js@^4.11.3, bn.js@^4.11.6, bn.js@^4.11.8, bn.js@^4.4.0, bn.js@^4.8.0:
+bn.js@=4.11.8, bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.10.0, bn.js@^4.11.0, bn.js@^4.11.3, bn.js@^4.11.6, bn.js@^4.11.8, bn.js@^4.4.0, bn.js@^4.8.0:
version "4.11.8"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f"
+bn.js@^2.0.3:
+ version "2.2.0"
+ resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-2.2.0.tgz#12162bc2ae71fc40a5626c33438f3a875cd37625"
+
body-parser@1.18.2, body-parser@^1.16.0, body-parser@^1.17.1:
version "1.18.2"
resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.18.2.tgz#87678a19d84b47d859b83199bd59bce222b10454"
@@ -1979,6 +2007,12 @@ browserslist@^2.1.2:
caniuse-lite "^1.0.30000792"
electron-to-chromium "^1.3.30"
+bs58@=4.0.1:
+ version "4.0.1"
+ resolved "https://registry.yarnpkg.com/bs58/-/bs58-4.0.1.tgz#be161e76c354f6f788ae4071f63f34e8c4f0a42a"
+ dependencies:
+ base-x "^3.0.2"
+
bs58@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/bs58/-/bs58-2.0.1.tgz#55908d58f1982aba2008fa1bed8f91998a29bf8d"
@@ -2000,6 +2034,10 @@ btoa@1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/btoa/-/btoa-1.1.2.tgz#3e40b81663f81d2dd6596a4cb714a8dc16cfabe0"
+buffer-compare@=1.1.1:
+ version "1.1.1"
+ resolved "https://registry.yarnpkg.com/buffer-compare/-/buffer-compare-1.1.1.tgz#5be7be853af89198d1f4ddc090d1d66a48aef596"
+
buffer-crc32@~0.2.3:
version "0.2.13"
resolved "https://registry.yarnpkg.com/buffer-crc32/-/buffer-crc32-0.2.13.tgz#0d333e3f00eac50aa1454abd30ef8c2a5d9a7242"
@@ -2036,7 +2074,7 @@ buffer@^3.0.1:
ieee754 "^1.1.4"
isarray "^1.0.0"
-buffer@^4.3.0:
+buffer@^4.3.0, buffer@^4.9.0:
version "4.9.1"
resolved "https://registry.yarnpkg.com/buffer/-/buffer-4.9.1.tgz#6d1bb601b07a4efced97094132093027c95bc298"
dependencies:
@@ -2903,7 +2941,7 @@ copyfiles@^1.2.0:
copyfiles@^2.0.0:
version "2.0.0"
- resolved "https://registry.npmjs.org/copyfiles/-/copyfiles-2.0.0.tgz#bbd78bb78e8fd6db5c67adf54249317b24560f2a"
+ resolved "https://registry.yarnpkg.com/copyfiles/-/copyfiles-2.0.0.tgz#bbd78bb78e8fd6db5c67adf54249317b24560f2a"
dependencies:
glob "^7.0.5"
minimatch "^3.0.3"
@@ -3058,7 +3096,7 @@ crypto-js@3.1.9-1, crypto-js@^3.1.9-1:
version "3.1.9-1"
resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-3.1.9-1.tgz#fda19e761fc077e01ffbfdc6e9fdfc59e8806cd8"
-crypto-js@^3.1.4:
+crypto-js@^3.1.4, crypto-js@^3.1.5:
version "3.1.8"
resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-3.1.8.tgz#715f070bf6014f2ae992a98b3929258b713f08d5"
@@ -3720,7 +3758,7 @@ elliptic@6.3.3:
hash.js "^1.0.0"
inherits "^2.0.1"
-elliptic@^6.0.0, elliptic@^6.2.3, elliptic@^6.4.0:
+elliptic@=6.4.0, elliptic@^6.0.0, elliptic@^6.2.3, elliptic@^6.4.0:
version "6.4.0"
resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.4.0.tgz#cac9af8762c85836187003c8dfe193e5e2eae5df"
dependencies:
@@ -3732,6 +3770,15 @@ elliptic@^6.0.0, elliptic@^6.2.3, elliptic@^6.4.0:
minimalistic-assert "^1.0.0"
minimalistic-crypto-utils "^1.0.0"
+elliptic@^3.1.0:
+ version "3.1.0"
+ resolved "http://registry.npmjs.org/elliptic/-/elliptic-3.1.0.tgz#c21682ef762769b56a74201609105da11d5f60cc"
+ dependencies:
+ bn.js "^2.0.3"
+ brorand "^1.0.1"
+ hash.js "^1.0.0"
+ inherits "^2.0.1"
+
emojis-list@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-2.1.0.tgz#4daa4d9db00f9819880c79fa457ae5b09a1fd389"
@@ -4031,6 +4078,22 @@ eth-lib@0.2.7:
elliptic "^6.4.0"
xhr-request-promise "^0.1.2"
+eth-lightwallet@^3.0.1:
+ version "3.0.1"
+ resolved "https://registry.yarnpkg.com/eth-lightwallet/-/eth-lightwallet-3.0.1.tgz#297022932aa568f4e4eb0873bff257f5e5b78709"
+ dependencies:
+ bitcore-lib "^0.15.0"
+ bitcore-mnemonic "^1.5.0"
+ buffer "^4.9.0"
+ crypto-js "^3.1.5"
+ elliptic "^3.1.0"
+ ethereumjs-tx "^1.3.3"
+ ethereumjs-util "^5.1.1"
+ rlp "^2.0.0"
+ scrypt-async "^1.2.0"
+ tweetnacl "0.13.2"
+ web3 "0.20.2"
+
eth-query@^2.0.2, eth-query@^2.1.0, eth-query@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/eth-query/-/eth-query-2.1.2.tgz#d6741d9000106b51510c72db92d6365456a6da5e"
@@ -5859,7 +5922,7 @@ inherits@2, inherits@2.0.3, inherits@^2.0.1, inherits@^2.0.3, inherits@~2.0.0, i
version "2.0.3"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
-inherits@2.0.1:
+inherits@2.0.1, inherits@=2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.1.tgz#b17d08d326b4423e568eff719f91b0b1cbdf69f1"
@@ -7204,7 +7267,7 @@ lodash@4.17.2:
version "4.17.2"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.2.tgz#34a3055babe04ce42467b607d700072c7ff6bf42"
-lodash@4.17.4:
+lodash@4.17.4, lodash@=4.17.4:
version "4.17.4"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae"
@@ -10216,7 +10279,7 @@ run-queue@^1.0.0, run-queue@^1.0.3:
run-s@^0.0.0:
version "0.0.0"
- resolved "https://registry.npmjs.org/run-s/-/run-s-0.0.0.tgz#599912be20c00ba7698655c9936d075d31b71754"
+ resolved "https://registry.yarnpkg.com/run-s/-/run-s-0.0.0.tgz#599912be20c00ba7698655c9936d075d31b71754"
rustbn.js@~0.1.1:
version "0.1.2"
@@ -10284,6 +10347,10 @@ scoped-regex@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/scoped-regex/-/scoped-regex-1.0.0.tgz#a346bb1acd4207ae70bd7c0c7ca9e566b6baddb8"
+scrypt-async@^1.2.0:
+ version "1.3.1"
+ resolved "https://registry.yarnpkg.com/scrypt-async/-/scrypt-async-1.3.1.tgz#a11fd6fac981b4b823ee01dee0221169500ddae9"
+
scrypt-js@2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/scrypt-js/-/scrypt-js-2.0.3.tgz#bb0040be03043da9a012a2cea9fc9f852cfc87d4"
@@ -11736,6 +11803,10 @@ tunnel-agent@^0.6.0:
dependencies:
safe-buffer "^5.0.1"
+tweetnacl@0.13.2:
+ version "0.13.2"
+ resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.13.2.tgz#453161770469d45cd266c36404e2bc99a8fa9944"
+
tweetnacl@^0.14.3, tweetnacl@~0.14.0:
version "0.14.5"
resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64"
@@ -12662,6 +12733,16 @@ web3-utils@1.0.0-beta.34:
underscore "1.8.3"
utf8 "2.1.1"
+web3@0.20.2:
+ version "0.20.2"
+ resolved "https://registry.yarnpkg.com/web3/-/web3-0.20.2.tgz#c54dac5fc0e377399c04c1a6ecbb12e4513278d6"
+ dependencies:
+ bignumber.js "git+https://github.com/frozeman/bignumber.js-nolookahead.git"
+ crypto-js "^3.1.4"
+ utf8 "^2.1.1"
+ xhr2 "*"
+ xmlhttprequest "*"
+
web3@^0.18.0:
version "0.18.4"
resolved "https://registry.yarnpkg.com/web3/-/web3-0.18.4.tgz#81ec1784145491f2eaa8955b31c06049e07c5e7d"
@@ -13169,7 +13250,7 @@ yargs@^10.0.3:
yargs@^11.0.0:
version "11.0.0"
- resolved "https://registry.npmjs.org/yargs/-/yargs-11.0.0.tgz#c052931006c5eee74610e5fc0354bedfd08a201b"
+ resolved "https://registry.yarnpkg.com/yargs/-/yargs-11.0.0.tgz#c052931006c5eee74610e5fc0354bedfd08a201b"
dependencies:
cliui "^4.0.0"
decamelize "^1.1.1"