@onekeyfe/hd-core 1.1.27-alpha.40 → 1.1.27-alpha.42

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 (54) hide show
  1. package/__tests__/logBlockEvent.test.ts +37 -0
  2. package/__tests__/protocol-v2.test.ts +158 -14
  3. package/dist/api/device/DeviceLock.d.ts.map +1 -1
  4. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts +1 -1
  5. package/dist/api/protocol-v2/DeviceGetOnboardingStatus.d.ts.map +1 -1
  6. package/dist/api/protocol-v2/FilesystemDiskControl.d.ts +1 -1
  7. package/dist/api/solana/SolGetAddress.d.ts +1 -6
  8. package/dist/api/solana/SolGetAddress.d.ts.map +1 -1
  9. package/dist/api/sui/SuiGetAddress.d.ts +3 -0
  10. package/dist/api/sui/SuiGetAddress.d.ts.map +1 -1
  11. package/dist/api/sui/SuiGetPublicKey.d.ts +3 -0
  12. package/dist/api/sui/SuiGetPublicKey.d.ts.map +1 -1
  13. package/dist/api/sui/SuiSignMessage.d.ts +3 -0
  14. package/dist/api/sui/SuiSignMessage.d.ts.map +1 -1
  15. package/dist/api/sui/SuiSignTransaction.d.ts +3 -0
  16. package/dist/api/sui/SuiSignTransaction.d.ts.map +1 -1
  17. package/dist/api/ton/TonGetAddress.d.ts +3 -0
  18. package/dist/api/ton/TonGetAddress.d.ts.map +1 -1
  19. package/dist/api/ton/TonSignData.d.ts +5 -0
  20. package/dist/api/ton/TonSignData.d.ts.map +1 -1
  21. package/dist/api/ton/TonSignMessage.d.ts +3 -0
  22. package/dist/api/ton/TonSignMessage.d.ts.map +1 -1
  23. package/dist/api/ton/TonSignProof.d.ts +3 -0
  24. package/dist/api/ton/TonSignProof.d.ts.map +1 -1
  25. package/dist/api/tron/TronGetAddress.d.ts +0 -4
  26. package/dist/api/tron/TronGetAddress.d.ts.map +1 -1
  27. package/dist/device/Device.d.ts +2 -2
  28. package/dist/device/Device.d.ts.map +1 -1
  29. package/dist/events/logBlockEvent.d.ts +1 -0
  30. package/dist/events/logBlockEvent.d.ts.map +1 -1
  31. package/dist/index.d.ts +6 -5
  32. package/dist/index.js +511 -248
  33. package/dist/types/api/protocolV2.d.ts +2 -2
  34. package/dist/types/api/protocolV2.d.ts.map +1 -1
  35. package/dist/utils/patch.d.ts +1 -1
  36. package/dist/utils/patch.d.ts.map +1 -1
  37. package/package.json +4 -4
  38. package/src/api/device/DeviceLock.ts +1 -3
  39. package/src/api/evm/EVMSignTypedData.ts +1 -1
  40. package/src/api/protocol-v2/DeviceGetOnboardingStatus.ts +1 -5
  41. package/src/api/solana/SolGetAddress.ts +1 -6
  42. package/src/api/sui/SuiGetAddress.ts +3 -0
  43. package/src/api/sui/SuiGetPublicKey.ts +3 -0
  44. package/src/api/sui/SuiSignMessage.ts +3 -0
  45. package/src/api/sui/SuiSignTransaction.ts +3 -0
  46. package/src/api/ton/TonGetAddress.ts +3 -0
  47. package/src/api/ton/TonSignData.ts +10 -3
  48. package/src/api/ton/TonSignMessage.ts +3 -0
  49. package/src/api/ton/TonSignProof.ts +3 -0
  50. package/src/api/tron/TronGetAddress.ts +0 -4
  51. package/src/data/messages/messages-protocol-v2.json +489 -268
  52. package/src/device/Device.ts +16 -7
  53. package/src/events/logBlockEvent.ts +23 -0
  54. package/src/types/api/protocolV2.ts +2 -2
@@ -51,7 +51,7 @@ import type {
51
51
  } from '../events';
52
52
  import type { PassphrasePromptResponse } from './DeviceCommands';
53
53
  import type { Deferred, HardwareConnectProtocol } from '@onekeyfe/hd-shared';
54
- import type { OneKeyDeviceInfo as DeviceDescriptor } from '@onekeyfe/hd-transport';
54
+ import type { OneKeyDeviceInfo as DeviceDescriptor, Success } from '@onekeyfe/hd-transport';
55
55
  import type DeviceConnector from './DeviceConnector';
56
56
 
57
57
  export type InitOptions = {
@@ -862,7 +862,11 @@ export class Device extends EventEmitter {
862
862
  return false;
863
863
  }
864
864
 
865
- async lockDevice() {
865
+ async lockDevice(): Promise<Success> {
866
+ if (getDeviceType(this.features) === EDeviceType.Pro2) {
867
+ return { message: 'LockDevice skipped for Pro2' };
868
+ }
869
+
866
870
  const res = await this.commands.typedCall('LockDevice', 'Success', {});
867
871
  return res.message;
868
872
  }
@@ -940,14 +944,11 @@ export class Device extends EventEmitter {
940
944
  onlyMainPin: useEmptyPassphrase,
941
945
  });
942
946
 
943
- if (skipPassphraseCheck) {
944
- return true;
945
- }
946
-
947
947
  // Main wallet and unlock Attach Pin, throw safe error
948
948
  const mainWalletUseAttachPin = unlockedAttachPin && useEmptyPassphrase;
949
949
  const useErrorAttachPin =
950
950
  unlockedAttachPin && passphraseState && passphraseState !== newPassphraseState;
951
+ const passphraseStateMismatch = !!passphraseState && passphraseState !== newPassphraseState;
951
952
 
952
953
  Log.debug('Check passphrase state safety: ', {
953
954
  passphraseState,
@@ -956,6 +957,14 @@ export class Device extends EventEmitter {
956
957
  useEmptyPassphrase,
957
958
  });
958
959
 
960
+ if (skipPassphraseCheck) {
961
+ if (passphraseStateMismatch) {
962
+ this.clearInternalState();
963
+ return false;
964
+ }
965
+ return true;
966
+ }
967
+
959
968
  if (mainWalletUseAttachPin || useErrorAttachPin) {
960
969
  try {
961
970
  await this.lockDevice();
@@ -967,7 +976,7 @@ export class Device extends EventEmitter {
967
976
  }
968
977
 
969
978
  // When exists passphraseState, check passphraseState
970
- if (passphraseState && passphraseState !== newPassphraseState) {
979
+ if (passphraseStateMismatch) {
971
980
  this.clearInternalState();
972
981
  return false;
973
982
  }
@@ -4,3 +4,26 @@ export const LogBlockEvent: Set<string> = new Set([
4
4
  UI_RESPONSE.RECEIVE_PIN,
5
5
  UI_RESPONSE.RECEIVE_PASSPHRASE,
6
6
  ]);
7
+
8
+ const LogBlockMethod: Set<string> = new Set(['evmSignTypedData']);
9
+
10
+ export function getLogBlockLabel(message: unknown): string | undefined {
11
+ if (!message || typeof message !== 'object') return undefined;
12
+
13
+ const { type, payload, method } = message as {
14
+ type?: string;
15
+ payload?: { method?: string };
16
+ method?: string;
17
+ };
18
+
19
+ if (type && LogBlockEvent.has(type)) {
20
+ return type;
21
+ }
22
+
23
+ const methodName = method ?? payload?.method;
24
+ if (methodName && LogBlockMethod.has(methodName)) {
25
+ return methodName;
26
+ }
27
+
28
+ return undefined;
29
+ }
@@ -2,11 +2,11 @@ import type { CommonParams, Response } from '../params';
2
2
  import type {
3
3
  DeviceFirmwareTarget,
4
4
  DeviceFirmwareUpdateStatus,
5
- DeviceOnboardingStatus,
6
5
  DeviceInfoTargets,
7
6
  DeviceInfoTypes,
8
7
  DeviceRebootType,
9
8
  FactoryDeviceInfo,
9
+ OnboardingStatus,
10
10
  ProtoVersion,
11
11
  ProtocolV2DeviceInfo,
12
12
  Success,
@@ -162,7 +162,7 @@ export declare function deviceGetDeviceInfo(
162
162
  export declare function deviceGetOnboardingStatus(
163
163
  connectId: string,
164
164
  params?: CommonParams
165
- ): Response<DeviceOnboardingStatus>;
165
+ ): Response<OnboardingStatus>;
166
166
 
167
167
  export declare function deviceFirmwareUpdate(
168
168
  connectId: string,