From 3dabc7dda6e5836f2da6e06255141b022a29f28e Mon Sep 17 00:00:00 2001 From: Szymon Lesisz Date: Mon, 7 May 2018 16:02:10 +0200 Subject: [PATCH] add new address fix (discovery HDKey refference) --- src/js/actions/DiscoveryActions.js | 16 +++++++++------- src/js/reducers/DiscoveryReducer.js | 21 ++++++++++++++++----- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/js/actions/DiscoveryActions.js b/src/js/actions/DiscoveryActions.js index b445b886..e614fc73 100644 --- a/src/js/actions/DiscoveryActions.js +++ b/src/js/actions/DiscoveryActions.js @@ -29,9 +29,9 @@ export type DiscoveryStartAction = { type: typeof DISCOVERY.START, device: TrezorDevice, network: string, - xpub: string, + publicKey: string, + chainCode: string, basePath: Array, - hdKey: HDKey } export type DiscoveryWaitingAction = { @@ -174,18 +174,15 @@ const begin = (device: TrezorDevice, network: string): AsyncAction => { if (discoveryProcess && discoveryProcess.interrupted) return; const basePath: Array = response.payload.path; - const hdKey = new HDKey(); - hdKey.publicKey = new Buffer(response.payload.publicKey, 'hex'); - hdKey.chainCode = new Buffer(response.payload.chainCode, 'hex'); // send data to reducer dispatch({ type: DISCOVERY.START, network: coinToDiscover.network, device, - xpub: response.payload.publicKey, + publicKey: response.payload.publicKey, + chainCode: response.payload.chainCode, basePath, - hdKey, }); dispatch( start(device, network) ); @@ -195,6 +192,11 @@ const begin = (device: TrezorDevice, network: string): AsyncAction => { const discoverAddress = (device: TrezorDevice, discoveryProcess: Discovery): AsyncAction => { return async (dispatch: Dispatch, getState: GetState): Promise => { + //const hdKey = discoveryProcess.hdKey + console.log("TYPEOF", typeof discoveryProcess.hdKey.derive, discoveryProcess.hdKey) + console.log("TYPEOF", typeof discoveryProcess.hdKey.derive === typeof HDKey); + + const derivedKey = discoveryProcess.hdKey.derive(`m/${discoveryProcess.accountIndex}`); const path = discoveryProcess.basePath.concat(discoveryProcess.accountIndex); const publicAddress: string = EthereumjsUtil.publicToAddress(derivedKey.publicKey, true).toString('hex'); diff --git a/src/js/reducers/DiscoveryReducer.js b/src/js/reducers/DiscoveryReducer.js index 6977efc0..bf187179 100644 --- a/src/js/reducers/DiscoveryReducer.js +++ b/src/js/reducers/DiscoveryReducer.js @@ -21,7 +21,8 @@ import type { export type Discovery = { network: string; - xpub: string; + publicKey: string; + chainCode: string; hdKey: HDKey; basePath: Array; deviceState: string; @@ -41,10 +42,14 @@ const findIndex = (state: State, network: string, deviceState: string): number = const start = (state: State, action: DiscoveryStartAction): State => { const deviceState: string = action.device.state || '0'; + const hdKey: HDKey = new HDKey(); + hdKey.publicKey = new Buffer(action.publicKey, 'hex'); + hdKey.chainCode = new Buffer(action.chainCode, 'hex'); const instance: Discovery = { network: action.network, - xpub: action.xpub, - hdKey: action.hdKey, + publicKey: action.publicKey, + chainCode: action.chainCode, + hdKey, basePath: action.basePath, deviceState, accountIndex: 0, @@ -99,7 +104,8 @@ const waitingForDevice = (state: State, action: DiscoveryWaitingAction): State = const instance: Discovery = { network: action.network, deviceState, - xpub: '', + publicKey: '', + chainCode: '', hdKey: null, basePath: [], accountIndex: 0, @@ -125,7 +131,8 @@ const waitingForBackend = (state: State, action: DiscoveryWaitingAction): State const instance: Discovery = { network: action.network, deviceState, - xpub: '', + publicKey: '', + chainCode: '', hdKey: null, basePath: [], accountIndex: 0, @@ -163,8 +170,12 @@ export default function discovery(state: State = initialState, action: Action): return waitingForBackend(state, action); case DISCOVERY.FROM_STORAGE : return action.payload.map(d => { + const hdKey: HDKey = new HDKey(); + hdKey.publicKey = new Buffer(d.publicKey, 'hex'); + hdKey.chainCode = new Buffer(d.chainCode, 'hex'); return { ...d, + hdKey, interrupted: false, waitingForDevice: false, waitingForBackend: false,