@onekeyfe/hd-core 1.0.34-alpha.1 → 1.0.35

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 (58) 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/btc/BTCGetPublicKey.d.ts.map +1 -1
  6. package/dist/api/btc/helpers/xpubUtils.d.ts +1 -0
  7. package/dist/api/btc/helpers/xpubUtils.d.ts.map +1 -1
  8. package/dist/api/helpers/hexUtils.d.ts +1 -0
  9. package/dist/api/helpers/hexUtils.d.ts.map +1 -1
  10. package/dist/api/index.d.ts +0 -1
  11. package/dist/api/index.d.ts.map +1 -1
  12. package/dist/core/index.d.ts.map +1 -1
  13. package/dist/device/Device.d.ts +3 -9
  14. package/dist/device/Device.d.ts.map +1 -1
  15. package/dist/device/DeviceCommands.d.ts +5 -7
  16. package/dist/device/DeviceCommands.d.ts.map +1 -1
  17. package/dist/events/device.d.ts +0 -3
  18. package/dist/events/device.d.ts.map +1 -1
  19. package/dist/events/ui-request.d.ts +1 -2
  20. package/dist/events/ui-request.d.ts.map +1 -1
  21. package/dist/events/ui-response.d.ts +0 -1
  22. package/dist/events/ui-response.d.ts.map +1 -1
  23. package/dist/index.d.ts +10 -26
  24. package/dist/index.js +97 -219
  25. package/dist/inject.d.ts.map +1 -1
  26. package/dist/types/api/firmwareUpdate.d.ts +1 -1
  27. package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
  28. package/dist/types/api/index.d.ts +0 -2
  29. package/dist/types/api/index.d.ts.map +1 -1
  30. package/dist/utils/deviceFeaturesUtils.d.ts +2 -16
  31. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  32. package/dist/utils/patch.d.ts +1 -1
  33. package/dist/utils/patch.d.ts.map +1 -1
  34. package/package.json +4 -4
  35. package/src/api/GetPassphraseState.ts +3 -19
  36. package/src/api/allnetwork/AllNetworkGetAddress.ts +20 -18
  37. package/src/api/btc/BTCGetPublicKey.ts +10 -1
  38. package/src/api/btc/helpers/xpubUtils.ts +37 -10
  39. package/src/api/evm/EVMSignTypedData.ts +2 -2
  40. package/src/api/helpers/hexUtils.ts +29 -0
  41. package/src/api/index.ts +0 -1
  42. package/src/core/index.ts +7 -12
  43. package/src/data/messages/messages.json +2 -57
  44. package/src/device/Device.ts +7 -75
  45. package/src/device/DeviceCommands.ts +4 -15
  46. package/src/events/device.ts +0 -4
  47. package/src/events/ui-request.ts +1 -2
  48. package/src/events/ui-response.ts +0 -1
  49. package/src/inject.ts +0 -2
  50. package/src/types/api/firmwareUpdate.ts +1 -1
  51. package/src/types/api/index.ts +0 -2
  52. package/src/utils/deviceFeaturesUtils.ts +7 -71
  53. package/dist/api/device/DeviceUnlock.d.ts +0 -7
  54. package/dist/api/device/DeviceUnlock.d.ts.map +0 -1
  55. package/dist/types/api/deviceUnlock.d.ts +0 -4
  56. package/dist/types/api/deviceUnlock.d.ts.map +0 -1
  57. package/src/api/device/DeviceUnlock.ts +0 -26
  58. package/src/types/api/deviceUnlock.ts +0 -4
@@ -11,31 +11,54 @@ const VERSION_BYTES = {
11
11
  ZPUB: 0x04b24746,
12
12
  };
13
13
 
14
- function getVersionBytes(coinName: string, scriptType?: InputScriptType): number {
14
+ export function getVersionBytes(
15
+ coinName: string,
16
+ scriptType?: InputScriptType
17
+ ): number | undefined {
15
18
  if (coinName.toLowerCase() === 'bitcoin') {
16
19
  switch (scriptType) {
17
20
  case 'SPENDADDRESS':
18
21
  case 'SPENDMULTISIG':
22
+ // 44、48
19
23
  return VERSION_BYTES.XPUB;
20
24
  case 'SPENDP2SHWITNESS':
25
+ // 49
21
26
  return VERSION_BYTES.YPUB;
22
27
  case 'SPENDWITNESS':
28
+ // 84
23
29
  return VERSION_BYTES.ZPUB;
24
30
  default:
31
+ // 86、10025
25
32
  return VERSION_BYTES.XPUB;
26
33
  }
27
- } else if (coinName.toLowerCase() === 'testnet') {
28
- return 0x043587cf;
29
- } else if (coinName.toLowerCase() === 'regtest') {
30
- return 0x043587cf;
31
34
  } else if (coinName.toLowerCase() === 'litecoin') {
32
- return 0x019da462;
35
+ switch (scriptType) {
36
+ case 'SPENDADDRESS':
37
+ case 'SPENDMULTISIG':
38
+ // 44、48
39
+ return 0x019da462;
40
+ case 'SPENDP2SHWITNESS':
41
+ // 49
42
+ return 0x01b26ef6;
43
+ case 'SPENDWITNESS':
44
+ // 84
45
+ return 0x04b24746;
46
+ default:
47
+ // not support 86、10025 path
48
+ return undefined;
49
+ }
33
50
  } else if (coinName.toLowerCase() === 'dogecoin') {
34
- return 0x02facafd;
35
- } else if (coinName.toLowerCase() === 'dash') {
36
- return 0x02fe52cc;
51
+ if (scriptType === 'SPENDADDRESS') {
52
+ // 44
53
+ return 0x02facafd;
54
+ }
55
+ if (scriptType === 'SPENDMULTISIG') {
56
+ // 48
57
+ return 0x0488b21e;
58
+ }
59
+ return undefined;
37
60
  }
38
- return VERSION_BYTES.XPUB;
61
+ return undefined;
39
62
  }
40
63
 
41
64
  function base58Check(data: Buffer): string {
@@ -76,6 +99,10 @@ function generateExtendedPublicKey(
76
99
  ): string {
77
100
  const versionBytes = getVersionBytes(coinName, scriptType);
78
101
 
102
+ if (!versionBytes) {
103
+ throw new Error(`Invalid coinName, not support generate xpub for scriptType: ${scriptType}`);
104
+ }
105
+
79
106
  const buffer = Buffer.alloc(78);
80
107
  buffer.writeUInt32BE(versionBytes, 0);
81
108
  buffer.writeUInt8(depth, 4);
@@ -13,7 +13,7 @@ import { UI_REQUEST } from '../../constants/ui-request';
13
13
  import { validatePath } from '../helpers/pathUtils';
14
14
  import { BaseMethod } from '../BaseMethod';
15
15
  import { validateParams } from '../helpers/paramsValidator';
16
- import { formatAnyHex, stripHexStartZeroes } from '../helpers/hexUtils';
16
+ import { formatAnyHex, parseChainId, stripHexStartZeroes } from '../helpers/hexUtils';
17
17
  import { getDeviceFirmwareVersion, getDeviceType } from '../../utils';
18
18
  import {
19
19
  DeviceModelToTypes,
@@ -217,7 +217,7 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
217
217
  gasToken: data.message.gasToken,
218
218
  refundReceiver: data.message.refundReceiver,
219
219
  nonce: formatAnyHex(new BigNumber(data.message.nonce).toString(16)),
220
- chain_id: new BigNumber(data.domain.chainId ?? '0x', 16).toNumber(),
220
+ chain_id: parseChainId(data.domain.chainId),
221
221
  verifyingContract: data.domain.verifyingContract,
222
222
  };
223
223
  response = await typedCall(
@@ -1,3 +1,5 @@
1
+ import BigNumber from 'bignumber.js';
2
+
1
3
  export const hasHexPrefix = (str: string): boolean => str.slice(0, 2).toLowerCase() === '0x';
2
4
 
3
5
  // remove hex prefix
@@ -80,3 +82,30 @@ export function hexToBytes(hex: string): Uint8Array {
80
82
  }
81
83
  return array;
82
84
  }
85
+
86
+ export function parseChainId(chainId: string | number | undefined): number {
87
+ if (!chainId) {
88
+ return 0;
89
+ }
90
+
91
+ if (typeof chainId === 'string') {
92
+ if (chainId.trim() === '') {
93
+ return 0;
94
+ }
95
+
96
+ if (chainId.match(/^[0-9]+$/)) {
97
+ return new BigNumber(chainId, 10).toNumber();
98
+ }
99
+ if (chainId.startsWith('0x') || chainId.match(/^[0-9a-fA-F]+$/)) {
100
+ return new BigNumber(chainId, 16).toNumber();
101
+ }
102
+
103
+ throw new Error(`Invalid chainId ${chainId}`);
104
+ }
105
+
106
+ if (typeof chainId === 'number') {
107
+ return new BigNumber(chainId).toNumber();
108
+ }
109
+
110
+ throw new Error(`Invalid chainId ${chainId}`);
111
+ }
package/src/api/index.ts CHANGED
@@ -27,7 +27,6 @@ export { default as deviceWipe } from './device/DeviceWipe';
27
27
  export { default as deviceFullyUploadResource } from './device/DeviceFullyUploadResource';
28
28
  export { default as deviceUpdateBootloader } from './device/DeviceUpdateBootloader';
29
29
  export { default as deviceLock } from './device/DeviceLock';
30
- export { default as deviceUnlock } from './device/DeviceUnlock';
31
30
  export { default as deviceCancel } from './device/DeviceCancel';
32
31
 
33
32
  export { default as setU2FCounter } from './u2f/SetU2FCounter';
package/src/core/index.ts CHANGED
@@ -342,8 +342,7 @@ const onCallDevice = async (
342
342
 
343
343
  // Check Device passphrase State
344
344
  const passphraseStateSafety = await device.checkPassphraseStateSafety(
345
- method.payload?.passphraseState,
346
- method.payload?.useEmptyPassphrase
345
+ method.payload?.passphraseState
347
346
  );
348
347
 
349
348
  // Double check, handles the special case of Touch/Pro
@@ -837,12 +836,12 @@ const onDevicePinHandler = async (...[device, type, callback]: DeviceEvents['pin
837
836
  const onDeviceButtonHandler = (...[device, request]: [...DeviceEvents['button']]) => {
838
837
  postMessage(createDeviceMessage(DEVICE.BUTTON, { ...request, device: device.toMessageObject() }));
839
838
 
840
- if (request.code === 'ButtonRequest_PinEntry' || request.code === 'ButtonRequest_AttachPin') {
841
- Log.log('request Confirm Input PIN or Attach PIN');
839
+ if (request.code === 'ButtonRequest_PinEntry') {
840
+ Log.log('request Confirm Input PIN');
842
841
  postMessage(
843
842
  createUiMessage(UI_REQUEST.REQUEST_PIN, {
844
843
  device: device.toMessageObject() as KnownDevice,
845
- type: request.code,
844
+ type: 'ButtonRequest_PinEntry',
846
845
  })
847
846
  );
848
847
  } else {
@@ -855,31 +854,27 @@ const onDeviceFeaturesHandler = (...[_, features]: [...DeviceEvents['features']]
855
854
  postMessage(createDeviceMessage(DEVICE.FEATURES, { ...features }));
856
855
  };
857
856
 
858
- const onDevicePassphraseHandler = async (
859
- ...[device, requestPayload, callback]: DeviceEvents['passphrase']
860
- ) => {
857
+ const onDevicePassphraseHandler = async (...[device, callback]: DeviceEvents['passphrase']) => {
861
858
  Log.debug('onDevicePassphraseHandler');
862
859
  const uiPromise = createUiPromise(UI_RESPONSE.RECEIVE_PASSPHRASE, device);
863
860
  postMessage(
864
861
  createUiMessage(UI_REQUEST.REQUEST_PASSPHRASE, {
865
862
  device: device.toMessageObject() as KnownDevice,
866
863
  passphraseState: device.passphraseState,
867
- existsAttachPinUser: requestPayload.existsAttachPinUser,
868
864
  })
869
865
  );
870
866
  // wait for passphrase
871
867
  const uiResp = await uiPromise.promise;
872
- const { value, passphraseOnDevice, save, attachPinOnDevice } = uiResp.payload;
868
+ const { value, passphraseOnDevice, save } = uiResp.payload;
873
869
  // send as PassphrasePromptResponse
874
870
  callback({
875
871
  passphrase: value.normalize('NFKD'),
876
872
  passphraseOnDevice,
877
- attachPinOnDevice,
878
873
  cache: save,
879
874
  });
880
875
  };
881
876
 
882
- const onEmptyPassphraseHandler = (...[_, , callback]: DeviceEvents['passphrase']) => {
877
+ const onEmptyPassphraseHandler = (...[_, callback]: DeviceEvents['passphrase']) => {
883
878
  Log.debug('onEmptyPassphraseHandler');
884
879
  // send as PassphrasePromptResponse
885
880
  callback({ passphrase: '' });
@@ -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,43 +693,12 @@ export class Device extends EventEmitter {
730
693
  return false;
731
694
  }
732
695
 
733
- async lockDevice() {
734
- const res = await this.commands.typedCall('LockDevice', 'Success', {});
735
- return res.message;
736
- }
737
-
738
- async checkPassphraseStateSafety(passphraseState?: string, useEmptyPassphraseState?: boolean) {
696
+ async checkPassphraseStateSafety(passphraseState?: string) {
739
697
  if (!this.features) return false;
740
- const { passphraseState: newPassphraseState, unlockedAttachPin } =
741
- await getPassphraseStateWithRefreshDeviceInfo(this, {
742
- expectPassphraseState: passphraseState,
743
- onlyMainPin: useEmptyPassphraseState,
744
- });
745
-
746
- // Main wallet and unlock Attach Pin, throw safe error
747
- const mainWalletUseAttachPin = unlockedAttachPin && useEmptyPassphraseState;
748
- const useErrorAttachPin =
749
- unlockedAttachPin && passphraseState && passphraseState !== newPassphraseState;
750
-
751
- console.log('=====>>>>>> checkPassphraseStateSafety passphraseState: ', {
752
- passphraseState,
753
- newPassphraseState,
754
- unlockedAttachPin,
755
- useEmptyPassphraseState,
756
- });
757
-
758
- if (mainWalletUseAttachPin || useErrorAttachPin) {
759
- try {
760
- await this.lockDevice();
761
- } catch (error) {
762
- // ignore error
763
- }
764
- this.clearInternalState();
765
- return Promise.reject(ERRORS.TypedError(HardwareErrorCode.DeviceCheckUnlockTypeError));
766
- }
698
+ const newState = await getPassphraseStateWithRefreshDeviceInfo(this);
767
699
 
768
700
  // When exists passphraseState, check passphraseState
769
- if (passphraseState && passphraseState !== newPassphraseState) {
701
+ if (passphraseState && passphraseState !== newState) {
770
702
  this.clearInternalState();
771
703
  return false;
772
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
  }
package/src/inject.ts CHANGED
@@ -138,8 +138,6 @@ export const createCoreApi = (
138
138
  call({ ...params, connectId, method: 'getPassphraseState' }),
139
139
  deviceCancel: (connectId, params) => call({ ...params, connectId, method: 'deviceCancel' }),
140
140
  deviceLock: (connectId, params) => call({ ...params, connectId, method: 'deviceLock' }),
141
- deviceUnlock: (connectId, params) =>
142
- call({ ...params, useEmptyPassphrase: true, connectId, method: 'deviceUnlock' }),
143
141
 
144
142
  getNextU2FCounter: (connectId, params) =>
145
143
  call({ ...params, connectId, method: 'getNextU2FCounter' }),
@@ -25,7 +25,7 @@ export declare function firmwareUpdate(
25
25
  params: Params<FirmwareUpdateBinaryParams> & { rebootOnSuccess?: boolean }
26
26
  ): Response<PROTO.Success>;
27
27
 
28
- type IPlatform = 'native' | 'desktop' | 'ext' | 'web' | 'webEmbed';
28
+ type IPlatform = 'native' | 'desktop' | 'ext' | 'web' | 'web-embed';
29
29
  type Platform = { platform: IPlatform };
30
30
 
31
31
  export declare function firmwareUpdateV2(
@@ -35,7 +35,6 @@ import { deviceSupportFeatures } from './deviceSupportFeatures';
35
35
  import { deviceFullyUploadResource } from './deviceFullyUploadResource';
36
36
  import { deviceUpdateBootloader } from './deviceUpdateBootloader';
37
37
  import { deviceLock } from './deviceLock';
38
- import { deviceUnlock } from './deviceUnlock';
39
38
  import { deviceCancel } from './deviceCancel';
40
39
 
41
40
  import { getNextU2FCounter } from './getNextU2FCounter';
@@ -215,7 +214,6 @@ export type CoreApi = {
215
214
  deviceFullyUploadResource: typeof deviceFullyUploadResource;
216
215
  deviceUpdateBootloader: typeof deviceUpdateBootloader;
217
216
  deviceLock: typeof deviceLock;
218
- deviceUnlock: typeof deviceUnlock;
219
217
  deviceCancel: typeof deviceCancel;
220
218
  getNextU2FCounter: typeof getNextU2FCounter;
221
219
  setU2FCounter: typeof setU2FCounter;
@@ -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.14.0')) {
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 = (
@@ -1,7 +0,0 @@
1
- import { LockDevice } from '@onekeyfe/hd-transport';
2
- import { BaseMethod } from '../BaseMethod';
3
- export default class DeviceUnlock extends BaseMethod<LockDevice> {
4
- init(): void;
5
- run(): Promise<import("@onekeyfe/hd-transport").Features>;
6
- }
7
- //# sourceMappingURL=DeviceUnlock.d.ts.map