diff options
author | Fabio Berger <me@fabioberger.com> | 2018-06-26 04:59:41 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2018-06-26 04:59:41 +0800 |
commit | 31e3b9ff8baac145be3e00eedc6d0ae065474b8d (patch) | |
tree | 2ee3bc050892eff5f221b7565ac9cca49c594b47 | |
parent | b2e32aaf588196b21a453fe7f7e38eb6eb154c22 (diff) | |
download | dexon-0x-contracts-31e3b9ff8baac145be3e00eedc6d0ae065474b8d.tar.gz dexon-0x-contracts-31e3b9ff8baac145be3e00eedc6d0ae065474b8d.tar.zst dexon-0x-contracts-31e3b9ff8baac145be3e00eedc6d0ae065474b8d.zip |
Fix and imprrove ethLightWalletSubprovider
3 files changed, 17 insertions, 15 deletions
diff --git a/packages/subproviders/package.json b/packages/subproviders/package.json index c3e588718..76b88cee0 100644 --- a/packages/subproviders/package.json +++ b/packages/subproviders/package.json @@ -41,7 +41,7 @@ }, "dependencies": { "@0xproject/assert": "^0.2.12", - "@0xproject/types": "^0.8.1", + "@0xproject/types": "^1.0.0", "@0xproject/typescript-typings": "^0.4.1", "@0xproject/utils": "^0.7.1", "@ledgerhq/hw-app-eth": "^4.3.0", diff --git a/packages/subproviders/src/subproviders/eth_lightwallet_subprovider.ts b/packages/subproviders/src/subproviders/eth_lightwallet_subprovider.ts index 7507eeb49..a908ab5fc 100644 --- a/packages/subproviders/src/subproviders/eth_lightwallet_subprovider.ts +++ b/packages/subproviders/src/subproviders/eth_lightwallet_subprovider.ts @@ -15,14 +15,12 @@ import { BaseWalletSubprovider } from './base_wallet_subprovider'; * Source: https://github.com/MetaMask/provider-engine/blob/master/subproviders/subprovider.js */ export class EthLightwalletSubprovider extends BaseWalletSubprovider { - private _signing: any; - private _keystore: any; + private _keystore: lightwallet.keystore; private _pwDerivedKey: Uint8Array; - constructor(signing: lightwallet.signing, keystore: lightwallet.keystore, pwDerivedKey: Uint8Array) { + constructor(keystore: lightwallet.keystore, pwDerivedKey: Uint8Array) { super(); - this._signing = signing; this._keystore = keystore; this._pwDerivedKey = pwDerivedKey; } @@ -54,8 +52,7 @@ export class EthLightwalletSubprovider extends BaseWalletSubprovider { const tx = new EthereumTx(txParams); const txHex = tx.serialize().toString('hex'); - let signedTxHex: string = this._signing.signTx( - this._keystore, this._pwDerivedKey, txHex, txParams.from, this._keystore.hdPathString); + let signedTxHex: string = lightwallet.signing.signTx(this._keystore, this._pwDerivedKey, txHex, txParams.from); signedTxHex = `0x${signedTxHex}`; @@ -78,10 +75,14 @@ export class EthLightwalletSubprovider extends BaseWalletSubprovider { } assert.isHexString('data', data); assert.isETHAddressHex('address', address); - const result: ECSignatureBuffer = await this._signing.signMsgHash( - this._keystore, this._pwDerivedKey, data, address, this._keystore.hdPathString); + const result: ECSignatureBuffer = lightwallet.signing.signMsgHash( + this._keystore, + this._pwDerivedKey, + data, + address, + ); - const signature = this._signing.concatSig(result); + const signature = lightwallet.signing.concatSig(result); return signature; } diff --git a/packages/subproviders/test/unit/eth_lightwallet_subprovider_test.ts b/packages/subproviders/test/unit/eth_lightwallet_subprovider_test.ts index 77a1ac58e..b99dbff2f 100644 --- a/packages/subproviders/test/unit/eth_lightwallet_subprovider_test.ts +++ b/packages/subproviders/test/unit/eth_lightwallet_subprovider_test.ts @@ -1,8 +1,7 @@ -import { JSONRPCResponsePayload } from '@0xproject/types'; import * as chai from 'chai'; import * as lightwallet from 'eth-lightwallet'; +import { JSONRPCResponsePayload } from 'ethereum-types'; import Web3ProviderEngine = require('web3-provider-engine'); -import RpcSubprovider = require('web3-provider-engine/subproviders/rpc'); import { EthLightwalletSubprovider } from '../../src'; import { DoneCallback } from '../../src/types'; @@ -59,7 +58,7 @@ describe('EthLightwalletSubprovider', () => { keystore.generateNewAddress(pwDerivedKey, NUM_GENERATED_ADDRESSES); // Initialize Subprovider - ethLightwalletSubprovider = new EthLightwalletSubprovider(lightwallet.signing, keystore, pwDerivedKey); + ethLightwalletSubprovider = new EthLightwalletSubprovider(keystore, pwDerivedKey); }); describe('direct method calls', () => { describe('success cases', () => { @@ -73,8 +72,10 @@ describe('EthLightwalletSubprovider', () => { // Keccak-256 hash of 'hello world' const messageHash = '0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad'; - const ecSignatureHex = - await ethLightwalletSubprovider.signPersonalMessageAsync(messageHash, signingAccount); + const ecSignatureHex = await ethLightwalletSubprovider.signPersonalMessageAsync( + messageHash, + signingAccount, + ); expect(ecSignatureHex).to.be.equal( // tslint:disable-next-line:max-line-length '0xa46b696c1aa8f91dbb33d1a66f6440bf3cf334c9dc45dc389668c1e60e2db31e259400b41f31632fa994837054c5345c88dc455c13931332489029adee6fd24d1b', |