mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-30 20:28:09 +00:00
DiscoveryReducer: HDKey only for ethereum
This commit is contained in:
parent
90b020e355
commit
c6ce9a94d7
@ -19,9 +19,6 @@ import type { Account } from './AccountsReducer';
|
|||||||
|
|
||||||
export type Discovery = {
|
export type Discovery = {
|
||||||
network: string;
|
network: string;
|
||||||
publicKey: string;
|
|
||||||
chainCode: string;
|
|
||||||
hdKey: HDKey;
|
|
||||||
basePath: Array<number>;
|
basePath: Array<number>;
|
||||||
deviceState: string;
|
deviceState: string;
|
||||||
accountIndex: number;
|
accountIndex: number;
|
||||||
@ -29,7 +26,11 @@ export type Discovery = {
|
|||||||
completed: boolean;
|
completed: boolean;
|
||||||
waitingForDevice: boolean;
|
waitingForDevice: boolean;
|
||||||
waitingForBlockchain: boolean;
|
waitingForBlockchain: boolean;
|
||||||
}
|
|
||||||
|
publicKey: string; // used in ethereum only
|
||||||
|
chainCode: string; // used in ethereum only
|
||||||
|
hdKey: HDKey; // used in ethereum only
|
||||||
|
};
|
||||||
|
|
||||||
export type State = Array<Discovery>;
|
export type State = Array<Discovery>;
|
||||||
const initialState: State = [];
|
const initialState: State = [];
|
||||||
@ -38,14 +39,16 @@ 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 = Buffer.from(action.publicKey, 'hex');
|
let hdKey: ?HDKey;
|
||||||
hdKey.chainCode = Buffer.from(action.chainCode, 'hex');
|
if (action.network.type === 'ethereum') {
|
||||||
|
hdKey = new HDKey();
|
||||||
|
hdKey.publicKey = Buffer.from(action.publicKey, 'hex');
|
||||||
|
hdKey.chainCode = Buffer.from(action.chainCode, 'hex');
|
||||||
|
}
|
||||||
|
|
||||||
const instance: Discovery = {
|
const instance: Discovery = {
|
||||||
network: action.network,
|
network: action.network.shortcut,
|
||||||
publicKey: action.publicKey,
|
|
||||||
chainCode: action.chainCode,
|
|
||||||
hdKey,
|
|
||||||
basePath: action.basePath,
|
basePath: action.basePath,
|
||||||
deviceState,
|
deviceState,
|
||||||
accountIndex: 0,
|
accountIndex: 0,
|
||||||
@ -53,10 +56,14 @@ const start = (state: State, action: DiscoveryStartAction): State => {
|
|||||||
completed: false,
|
completed: false,
|
||||||
waitingForDevice: false,
|
waitingForDevice: false,
|
||||||
waitingForBlockchain: false,
|
waitingForBlockchain: false,
|
||||||
|
|
||||||
|
publicKey: action.publicKey,
|
||||||
|
chainCode: action.chainCode,
|
||||||
|
hdKey,
|
||||||
};
|
};
|
||||||
|
|
||||||
const newState: State = [...state];
|
const newState: State = [...state];
|
||||||
const index: number = findIndex(state, action.network, deviceState);
|
const index: number = findIndex(state, action.network.shortcut, deviceState);
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
newState[index] = instance;
|
newState[index] = instance;
|
||||||
} else {
|
} else {
|
||||||
@ -107,15 +114,16 @@ const waitingForDevice = (state: State, action: DiscoveryWaitingAction): State =
|
|||||||
const instance: Discovery = {
|
const instance: Discovery = {
|
||||||
network: action.network,
|
network: action.network,
|
||||||
deviceState,
|
deviceState,
|
||||||
publicKey: '',
|
|
||||||
chainCode: '',
|
|
||||||
hdKey: null,
|
|
||||||
basePath: [],
|
basePath: [],
|
||||||
accountIndex: 0,
|
accountIndex: 0,
|
||||||
interrupted: false,
|
interrupted: false,
|
||||||
completed: false,
|
completed: false,
|
||||||
waitingForDevice: true,
|
waitingForDevice: true,
|
||||||
waitingForBlockchain: false,
|
waitingForBlockchain: false,
|
||||||
|
|
||||||
|
publicKey: '',
|
||||||
|
chainCode: '',
|
||||||
|
hdKey: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const index: number = findIndex(state, action.network, deviceState);
|
const index: number = findIndex(state, action.network, deviceState);
|
||||||
@ -134,15 +142,16 @@ const waitingForBlockchain = (state: State, action: DiscoveryWaitingAction): Sta
|
|||||||
const instance: Discovery = {
|
const instance: Discovery = {
|
||||||
network: action.network,
|
network: action.network,
|
||||||
deviceState,
|
deviceState,
|
||||||
publicKey: '',
|
|
||||||
chainCode: '',
|
|
||||||
hdKey: null,
|
|
||||||
basePath: [],
|
basePath: [],
|
||||||
accountIndex: 0,
|
accountIndex: 0,
|
||||||
interrupted: false,
|
interrupted: false,
|
||||||
completed: false,
|
completed: false,
|
||||||
waitingForDevice: false,
|
waitingForDevice: false,
|
||||||
waitingForBlockchain: true,
|
waitingForBlockchain: true,
|
||||||
|
|
||||||
|
publicKey: '',
|
||||||
|
chainCode: '',
|
||||||
|
hdKey: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const index: number = findIndex(state, action.network, deviceState);
|
const index: number = findIndex(state, action.network, deviceState);
|
||||||
|
Loading…
Reference in New Issue
Block a user