1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-24 09:18:09 +00:00

add new address fix (discovery HDKey refference)

This commit is contained in:
Szymon Lesisz 2018-05-07 16:02:10 +02:00
parent 4613d524b5
commit 3dabc7dda6
2 changed files with 25 additions and 12 deletions

View File

@ -29,9 +29,9 @@ export type DiscoveryStartAction = {
type: typeof DISCOVERY.START, type: typeof DISCOVERY.START,
device: TrezorDevice, device: TrezorDevice,
network: string, network: string,
xpub: string, publicKey: string,
chainCode: string,
basePath: Array<number>, basePath: Array<number>,
hdKey: HDKey
} }
export type DiscoveryWaitingAction = { export type DiscoveryWaitingAction = {
@ -174,18 +174,15 @@ const begin = (device: TrezorDevice, network: string): AsyncAction => {
if (discoveryProcess && discoveryProcess.interrupted) return; if (discoveryProcess && discoveryProcess.interrupted) return;
const basePath: Array<number> = response.payload.path; const basePath: Array<number> = 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 // send data to reducer
dispatch({ dispatch({
type: DISCOVERY.START, type: DISCOVERY.START,
network: coinToDiscover.network, network: coinToDiscover.network,
device, device,
xpub: response.payload.publicKey, publicKey: response.payload.publicKey,
chainCode: response.payload.chainCode,
basePath, basePath,
hdKey,
}); });
dispatch( start(device, network) ); dispatch( start(device, network) );
@ -195,6 +192,11 @@ const begin = (device: TrezorDevice, network: string): AsyncAction => {
const discoverAddress = (device: TrezorDevice, discoveryProcess: Discovery): AsyncAction => { const discoverAddress = (device: TrezorDevice, discoveryProcess: Discovery): AsyncAction => {
return async (dispatch: Dispatch, getState: GetState): Promise<void> => { return async (dispatch: Dispatch, getState: GetState): Promise<void> => {
//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 derivedKey = discoveryProcess.hdKey.derive(`m/${discoveryProcess.accountIndex}`);
const path = discoveryProcess.basePath.concat(discoveryProcess.accountIndex); const path = discoveryProcess.basePath.concat(discoveryProcess.accountIndex);
const publicAddress: string = EthereumjsUtil.publicToAddress(derivedKey.publicKey, true).toString('hex'); const publicAddress: string = EthereumjsUtil.publicToAddress(derivedKey.publicKey, true).toString('hex');

View File

@ -21,7 +21,8 @@ import type {
export type Discovery = { export type Discovery = {
network: string; network: string;
xpub: string; publicKey: string;
chainCode: string;
hdKey: HDKey; hdKey: HDKey;
basePath: Array<number>; basePath: Array<number>;
deviceState: string; deviceState: string;
@ -41,10 +42,14 @@ const findIndex = (state: State, network: string, deviceState: string): number =
const start = (state: State, action: DiscoveryStartAction): State => { const start = (state: State, action: DiscoveryStartAction): State => {
const deviceState: string = action.device.state || '0'; 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 = { const instance: Discovery = {
network: action.network, network: action.network,
xpub: action.xpub, publicKey: action.publicKey,
hdKey: action.hdKey, chainCode: action.chainCode,
hdKey,
basePath: action.basePath, basePath: action.basePath,
deviceState, deviceState,
accountIndex: 0, accountIndex: 0,
@ -99,7 +104,8 @@ const waitingForDevice = (state: State, action: DiscoveryWaitingAction): State =
const instance: Discovery = { const instance: Discovery = {
network: action.network, network: action.network,
deviceState, deviceState,
xpub: '', publicKey: '',
chainCode: '',
hdKey: null, hdKey: null,
basePath: [], basePath: [],
accountIndex: 0, accountIndex: 0,
@ -125,7 +131,8 @@ const waitingForBackend = (state: State, action: DiscoveryWaitingAction): State
const instance: Discovery = { const instance: Discovery = {
network: action.network, network: action.network,
deviceState, deviceState,
xpub: '', publicKey: '',
chainCode: '',
hdKey: null, hdKey: null,
basePath: [], basePath: [],
accountIndex: 0, accountIndex: 0,
@ -163,8 +170,12 @@ export default function discovery(state: State = initialState, action: Action):
return waitingForBackend(state, action); return waitingForBackend(state, action);
case DISCOVERY.FROM_STORAGE : case DISCOVERY.FROM_STORAGE :
return action.payload.map(d => { 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 { return {
...d, ...d,
hdKey,
interrupted: false, interrupted: false,
waitingForDevice: false, waitingForDevice: false,
waitingForBackend: false, waitingForBackend: false,