@onekeyfe/hd-core 1.0.33-alpha.8 → 1.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist/api/GetPassphraseState.d.ts +1 -1
  2. package/dist/api/GetPassphraseState.d.ts.map +1 -1
  3. package/dist/api/allnetwork/AllNetworkGetAddress.d.ts +1 -3
  4. package/dist/api/allnetwork/AllNetworkGetAddress.d.ts.map +1 -1
  5. package/dist/api/helpers/hexUtils.d.ts +1 -0
  6. package/dist/api/helpers/hexUtils.d.ts.map +1 -1
  7. package/dist/core/index.d.ts.map +1 -1
  8. package/dist/device/Device.d.ts +3 -8
  9. package/dist/device/Device.d.ts.map +1 -1
  10. package/dist/device/DeviceCommands.d.ts +5 -7
  11. package/dist/device/DeviceCommands.d.ts.map +1 -1
  12. package/dist/events/device.d.ts +0 -3
  13. package/dist/events/device.d.ts.map +1 -1
  14. package/dist/events/ui-request.d.ts +1 -2
  15. package/dist/events/ui-request.d.ts.map +1 -1
  16. package/dist/events/ui-response.d.ts +0 -1
  17. package/dist/events/ui-response.d.ts.map +1 -1
  18. package/dist/index.d.ts +8 -19
  19. package/dist/index.js +69 -165
  20. package/dist/utils/deviceFeaturesUtils.d.ts +2 -16
  21. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  22. package/dist/utils/patch.d.ts +1 -1
  23. package/dist/utils/patch.d.ts.map +1 -1
  24. package/package.json +4 -4
  25. package/src/api/GetPassphraseState.ts +3 -19
  26. package/src/api/allnetwork/AllNetworkGetAddress.ts +20 -18
  27. package/src/api/evm/EVMSignTypedData.ts +2 -2
  28. package/src/api/helpers/hexUtils.ts +29 -0
  29. package/src/core/index.ts +7 -12
  30. package/src/data/messages/messages.json +2 -57
  31. package/src/device/Device.ts +7 -54
  32. package/src/device/DeviceCommands.ts +4 -15
  33. package/src/events/device.ts +0 -4
  34. package/src/events/ui-request.ts +1 -2
  35. package/src/events/ui-response.ts +0 -1
  36. package/src/utils/deviceFeaturesUtils.ts +7 -71
@@ -3021,8 +3021,7 @@
3021
3021
  "ButtonRequest_Success": 17,
3022
3022
  "ButtonRequest_Warning": 18,
3023
3023
  "ButtonRequest_PassphraseEntry": 19,
3024
- "ButtonRequest_PinEntry": 20,
3025
- "ButtonRequest_AttachPin": 8000
3024
+ "ButtonRequest_PinEntry": 20
3026
3025
  }
3027
3026
  }
3028
3027
  }
@@ -3072,10 +3071,6 @@
3072
3071
  "options": {
3073
3072
  "deprecated": true
3074
3073
  }
3075
- },
3076
- "exists_attach_pin_user": {
3077
- "type": "bool",
3078
- "id": 8000
3079
3074
  }
3080
3075
  }
3081
3076
  },
@@ -3095,10 +3090,6 @@
3095
3090
  "on_device": {
3096
3091
  "type": "bool",
3097
3092
  "id": 3
3098
- },
3099
- "on_device_attach_pin": {
3100
- "type": "bool",
3101
- "id": 8000
3102
3093
  }
3103
3094
  }
3104
3095
  },
@@ -6060,10 +6051,6 @@
6060
6051
  "derive_cardano": {
6061
6052
  "type": "bool",
6062
6053
  "id": 3
6063
- },
6064
- "passphrase_state": {
6065
- "type": "string",
6066
- "id": 8000
6067
6054
  }
6068
6055
  }
6069
6056
  },
@@ -6442,14 +6429,6 @@
6442
6429
  "onekey_se04_state": {
6443
6430
  "type": "OneKeySEState",
6444
6431
  "id": 624
6445
- },
6446
- "attach_to_pin_user": {
6447
- "type": "bool",
6448
- "id": 625
6449
- },
6450
- "unlocked_attach_pin": {
6451
- "type": "bool",
6452
- "id": 626
6453
6432
  }
6454
6433
  },
6455
6434
  "nested": {
@@ -7554,38 +7533,6 @@
7554
7533
  }
7555
7534
  }
7556
7535
  },
7557
- "GetPassphraseState": {
7558
- "fields": {
7559
- "passphrase_state": {
7560
- "type": "string",
7561
- "id": 1
7562
- },
7563
- "_only_main_pin": {
7564
- "type": "bool",
7565
- "id": 2
7566
- },
7567
- "allow_create_attach_pin": {
7568
- "type": "bool",
7569
- "id": 3
7570
- }
7571
- }
7572
- },
7573
- "PassphraseState": {
7574
- "fields": {
7575
- "passphrase_state": {
7576
- "type": "string",
7577
- "id": 1
7578
- },
7579
- "session_id": {
7580
- "type": "bytes",
7581
- "id": 2
7582
- },
7583
- "unlocked_attach_pin": {
7584
- "type": "bool",
7585
- "id": 3
7586
- }
7587
- }
7588
- },
7589
7536
  "MoneroTransactionSourceEntry": {
7590
7537
  "fields": {
7591
7538
  "outputs": {
@@ -12197,9 +12144,7 @@
12197
12144
  "MessageType_ListResDir": 10023,
12198
12145
  "MessageType_FileInfoList": 10024,
12199
12146
  "MessageType_OnekeyGetFeatures": 10025,
12200
- "MessageType_OnekeyFeatures": 10026,
12201
- "MessageType_GetPassphraseState": 10028,
12202
- "MessageType_PassphraseState": 10029
12147
+ "MessageType_OnekeyFeatures": 10026
12203
12148
  }
12204
12149
  },
12205
12150
  "google": {
@@ -33,13 +33,7 @@ import {
33
33
  type Features,
34
34
  type UnavailableCapabilities,
35
35
  } from '../types';
36
- import {
37
- DEVICE,
38
- DeviceButtonRequestPayload,
39
- DeviceFeaturesPayload,
40
- PassphraseRequestPayload,
41
- UI_REQUEST,
42
- } from '../events';
36
+ import { DEVICE, DeviceButtonRequestPayload, DeviceFeaturesPayload, UI_REQUEST } from '../events';
43
37
  import { PROTO } from '../constants';
44
38
  import { DataManager } from '../data-manager';
45
39
  import TransportManager from '../data-manager/TransportManager';
@@ -67,11 +61,7 @@ export interface DeviceEvents {
67
61
  [DEVICE.PASSPHRASE_ON_DEVICE]: [Device, ((response: any) => void)?];
68
62
  [DEVICE.BUTTON]: [Device, DeviceButtonRequestPayload];
69
63
  [DEVICE.FEATURES]: [Device, DeviceFeaturesPayload];
70
- [DEVICE.PASSPHRASE]: [
71
- Device,
72
- PassphraseRequestPayload,
73
- (response: PassphrasePromptResponse, error?: Error) => void
74
- ];
64
+ [DEVICE.PASSPHRASE]: [Device, (response: PassphrasePromptResponse, error?: Error) => void];
75
65
  [DEVICE.SELECT_DEVICE_IN_BOOTLOADER_FOR_WEB_DEVICE]: [
76
66
  Device,
77
67
  (err: any, deviceId: string) => void
@@ -333,26 +323,6 @@ export class Device extends EventEmitter {
333
323
  Log.debug('tryFixInternalState session cache: ', deviceSessionCache);
334
324
  }
335
325
 
336
- // attach to pin to fix internal state
337
- updateInternalState(state: string, deviceId: string, sessionId: string | null = null) {
338
- Log.debug(
339
- 'updateInternalState session param: ',
340
- `device_id: ${deviceId}`,
341
- `passphraseState: ${state}`,
342
- `sessionId: ${sessionId}`
343
- );
344
-
345
- if (sessionId) {
346
- deviceSessionCache[this.generateStateKey(deviceId, state)] = sessionId;
347
- // delete the old sessionId
348
- const oldKey = `${deviceId}`;
349
- if (deviceSessionCache[oldKey]) {
350
- delete deviceSessionCache[oldKey];
351
- }
352
- }
353
- Log.debug('updateInternalState session cache: ', deviceSessionCache);
354
- }
355
-
356
326
  private setInternalState(state: string, initSession?: boolean) {
357
327
  Log.debug(
358
328
  'setInternalState session param: ',
@@ -391,7 +361,7 @@ export class Device extends EventEmitter {
391
361
  }
392
362
 
393
363
  async initialize(options?: InitOptions) {
394
- // Log.debug('initialize param:', options);
364
+ Log.debug('initialize param:', options);
395
365
 
396
366
  this.passphraseState = options?.passphraseState;
397
367
 
@@ -408,14 +378,8 @@ export class Device extends EventEmitter {
408
378
  if (options?.deriveCardano) {
409
379
  payload.derive_cardano = true;
410
380
  }
411
- payload.passphrase_state = options?.passphraseState;
412
381
 
413
- // Log.debug('initialize payload:', payload);
414
- console.log('=====>>>>>> initialize device begin: ', payload, {
415
- deviceId: options?.deviceId,
416
- passphraseState: options?.passphraseState,
417
- initSession: options?.initSession,
418
- });
382
+ Log.debug('initialize payload:', payload);
419
383
 
420
384
  try {
421
385
  // @ts-expect-error
@@ -429,7 +393,6 @@ export class Device extends EventEmitter {
429
393
  }),
430
394
  ]);
431
395
 
432
- console.log('=====>>>>>> initialize device end: ', message);
433
396
  this._updateFeatures(message, options?.initSession);
434
397
  await TransportManager.reconfigure(this.features);
435
398
  } catch (error) {
@@ -730,22 +693,12 @@ export class Device extends EventEmitter {
730
693
  return false;
731
694
  }
732
695
 
733
- async checkPassphraseStateSafety(passphraseState?: string, useEmptyPassphraseState?: boolean) {
696
+ async checkPassphraseStateSafety(passphraseState?: string) {
734
697
  if (!this.features) return false;
735
- const { passphraseState: newPassphraseState, unlockedAttachPin } =
736
- await getPassphraseStateWithRefreshDeviceInfo(this, {
737
- expectPassphraseState: passphraseState,
738
- onlyMainPin: useEmptyPassphraseState,
739
- });
740
-
741
- // Main wallet and unlock Attach Pin, throw safe error
742
- if (unlockedAttachPin && useEmptyPassphraseState) {
743
- this.clearInternalState();
744
- return Promise.reject(ERRORS.TypedError(HardwareErrorCode.DeviceCheckUnlockTypeError));
745
- }
698
+ const newState = await getPassphraseStateWithRefreshDeviceInfo(this);
746
699
 
747
700
  // When exists passphraseState, check passphraseState
748
- if (passphraseState && passphraseState !== newPassphraseState) {
701
+ if (passphraseState && passphraseState !== newState) {
749
702
  this.clearInternalState();
750
703
  return false;
751
704
  }
@@ -4,13 +4,12 @@ import TransportManager from '../data-manager/TransportManager';
4
4
  import DataManager from '../data-manager/DataManager';
5
5
  import { patchFeatures, getLogger, LoggerNames, getDeviceType } from '../utils';
6
6
  import type { Device } from './Device';
7
- import { DEVICE, type PassphraseRequestPayload } from '../events';
7
+ import { DEVICE } from '../events';
8
8
  import { DeviceModelToTypes } from '../types';
9
9
 
10
10
  export type PassphrasePromptResponse = {
11
11
  passphrase?: string;
12
12
  passphraseOnDevice?: boolean;
13
- attachPinOnDevice?: boolean;
14
13
  cache?: boolean;
15
14
  };
16
15
 
@@ -439,17 +438,8 @@ export class DeviceCommands {
439
438
  }
440
439
 
441
440
  if (res.type === 'PassphraseRequest') {
442
- const existsAttachPinUser = res.message.exists_attach_pin_user;
443
- return this._promptPassphrase({
444
- existsAttachPinUser,
445
- }).then(response => {
446
- const { passphrase, passphraseOnDevice, attachPinOnDevice } = response;
447
-
448
- // Attach PIN on device
449
- if (attachPinOnDevice && existsAttachPinUser) {
450
- return this._commonCall('PassphraseAck', { on_device_attach_pin: true });
451
- }
452
-
441
+ return this._promptPassphrase().then(response => {
442
+ const { passphrase, passphraseOnDevice } = response;
453
443
  return !passphraseOnDevice
454
444
  ? this._commonCall('PassphraseAck', { passphrase })
455
445
  : this._commonCall('PassphraseAck', { on_device: true });
@@ -511,7 +501,7 @@ export class DeviceCommands {
511
501
  });
512
502
  }
513
503
 
514
- _promptPassphrase(options: PassphraseRequestPayload) {
504
+ _promptPassphrase() {
515
505
  return new Promise<PassphrasePromptResponse>((resolve, reject) => {
516
506
  const cancelAndReject = (_error?: Error) =>
517
507
  cancelDeviceInPrompt(this.device, false)
@@ -537,7 +527,6 @@ export class DeviceCommands {
537
527
  this.device.emit(
538
528
  DEVICE.PASSPHRASE,
539
529
  this.device,
540
- options,
541
530
  (response: PassphrasePromptResponse, error?: Error) => {
542
531
  this.device.clearCancelableAction();
543
532
  if (error) {
@@ -44,10 +44,6 @@ export interface DeviceButtonRequestPayload extends Omit<PROTO.ButtonRequest, 'c
44
44
  code?: PROTO.ButtonRequest['code'] | 'ButtonRequest_FirmwareUpdate';
45
45
  }
46
46
 
47
- export type PassphraseRequestPayload = {
48
- existsAttachPinUser?: boolean;
49
- };
50
-
51
47
  export interface DeviceButtonRequest {
52
48
  type: typeof DEVICE.BUTTON;
53
49
  payload: DeviceButtonRequestPayload & { device: Device | null };
@@ -66,7 +66,7 @@ export type UiRequestDeviceAction = {
66
66
  type: typeof UI_REQUEST.REQUEST_PIN;
67
67
  payload: {
68
68
  device: Device;
69
- type?: PROTO.PinMatrixRequestType | 'ButtonRequest_PinEntry' | 'ButtonRequest_AttachPin';
69
+ type?: PROTO.PinMatrixRequestType | 'ButtonRequest_PinEntry';
70
70
  };
71
71
  };
72
72
 
@@ -80,7 +80,6 @@ export interface UiRequestPassphrase {
80
80
  payload: {
81
81
  device: Device;
82
82
  passphraseState?: string;
83
- existsAttachPinUser?: boolean;
84
83
  };
85
84
  }
86
85
 
@@ -18,7 +18,6 @@ export interface UiResponsePassphrase {
18
18
  payload: {
19
19
  value: string;
20
20
  passphraseOnDevice?: boolean;
21
- attachPinOnDevice?: boolean;
22
21
  save?: boolean;
23
22
  };
24
23
  }
@@ -73,30 +73,11 @@ export const supportNewPassphrase = (features?: Features): SupportFeatureType =>
73
73
  return { support: semver.gte(currentVersion, '2.4.0'), require: '2.4.0' };
74
74
  };
75
75
 
76
- export const getPassphraseStateWithRefreshDeviceInfo = async (
77
- device: Device,
78
- options?: {
79
- expectPassphraseState?: string;
80
- onlyMainPin?: boolean;
81
- }
82
- ) => {
76
+ export const getPassphraseStateWithRefreshDeviceInfo = async (device: Device) => {
83
77
  const { features, commands } = device;
84
78
  const locked = features?.unlocked === false;
85
79
 
86
- const { passphraseState, newSession, unlockedAttachPin } = await getPassphraseState(
87
- features,
88
- commands,
89
- {
90
- ...options,
91
- }
92
- );
93
-
94
- // Attach to pin try to fix internal state
95
- if (newSession && passphraseState && features?.device_id) {
96
- console.log('=====>>>>>> run updateInternalState newSession:', newSession);
97
- device.updateInternalState(passphraseState, features.device_id, newSession);
98
- }
99
-
80
+ const passphraseState = await getPassphraseState(features, commands);
100
81
  const isModeT =
101
82
  getDeviceType(features) === EDeviceType.Touch || getDeviceType(features) === EDeviceType.Pro;
102
83
 
@@ -112,55 +93,14 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
112
93
  await device.getFeatures();
113
94
  }
114
95
 
115
- return { passphraseState, newSession, unlockedAttachPin };
96
+ return passphraseState;
116
97
  };
117
98
 
118
99
  export const getPassphraseState = async (
119
100
  features: Features | undefined,
120
- commands: DeviceCommands,
121
- options?: {
122
- expectPassphraseState?: string;
123
- onlyMainPin?: boolean;
124
- // createAttachPinWallet?: boolean;
125
- }
126
- ): Promise<{
127
- passphraseState: string | undefined;
128
- newSession: string | undefined;
129
- unlockedAttachPin: boolean | undefined;
130
- }> => {
131
- if (!features)
132
- return { passphraseState: undefined, newSession: undefined, unlockedAttachPin: undefined };
133
-
134
- const firmwareVersion = getDeviceFirmwareVersion(features);
135
- const deviceType = getDeviceType(features);
136
-
137
- if (deviceType === EDeviceType.Pro && semver.gte(firmwareVersion.join('.'), '4.13.2')) {
138
- console.log(
139
- '=====>>>>>> getPassphraseState begin: ',
140
- options?.onlyMainPin,
141
- options?.expectPassphraseState
142
- );
143
-
144
- const { message, type } = await commands.typedCall('GetPassphraseState', 'PassphraseState', {
145
- passphrase_state: options?.onlyMainPin ? undefined : options?.expectPassphraseState,
146
- // allow_create_attach_pin: options?.createAttachPinWallet,
147
- // _only_main_pin: options?.onlyMainPin,
148
- });
149
-
150
- console.log('=====>>>>>> getPassphraseState end: result ', message);
151
-
152
- // @ts-expect-error
153
- if (type === 'CallMethodError') {
154
- throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Get the passphrase state error');
155
- }
156
-
157
- return {
158
- passphraseState: message.passphrase_state,
159
- newSession: message.session_id,
160
- unlockedAttachPin: message.unlocked_attach_pin,
161
- };
162
- }
163
-
101
+ commands: DeviceCommands
102
+ ) => {
103
+ if (!features) return false;
164
104
  const { message, type } = await commands.typedCall('GetAddress', 'Address', {
165
105
  address_n: [toHardened(44), toHardened(1), toHardened(0), 0, 0],
166
106
  coin_name: 'Testnet',
@@ -173,11 +113,7 @@ export const getPassphraseState = async (
173
113
  throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Get the passphrase state error');
174
114
  }
175
115
 
176
- return {
177
- passphraseState: message.address,
178
- newSession: undefined,
179
- unlockedAttachPin: undefined,
180
- };
116
+ return message.address;
181
117
  };
182
118
 
183
119
  export const supportBatchPublicKey = (