mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-13 20:08:56 +00:00
add new address fix (discovery HDKey refference)
This commit is contained in:
parent
4613d524b5
commit
3dabc7dda6
@ -29,9 +29,9 @@ export type DiscoveryStartAction = {
|
||||
type: typeof DISCOVERY.START,
|
||||
device: TrezorDevice,
|
||||
network: string,
|
||||
xpub: string,
|
||||
publicKey: string,
|
||||
chainCode: string,
|
||||
basePath: Array<number>,
|
||||
hdKey: HDKey
|
||||
}
|
||||
|
||||
export type DiscoveryWaitingAction = {
|
||||
@ -174,18 +174,15 @@ const begin = (device: TrezorDevice, network: string): AsyncAction => {
|
||||
if (discoveryProcess && discoveryProcess.interrupted) return;
|
||||
|
||||
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
|
||||
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<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 path = discoveryProcess.basePath.concat(discoveryProcess.accountIndex);
|
||||
const publicAddress: string = EthereumjsUtil.publicToAddress(derivedKey.publicKey, true).toString('hex');
|
||||
|
@ -21,7 +21,8 @@ import type {
|
||||
|
||||
export type Discovery = {
|
||||
network: string;
|
||||
xpub: string;
|
||||
publicKey: string;
|
||||
chainCode: string;
|
||||
hdKey: HDKey;
|
||||
basePath: Array<number>;
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user