@onekeyfe/hd-core 1.0.38-alpha.0 → 1.0.39-alpha.1

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 (61) hide show
  1. package/dist/api/GetPassphraseState.d.ts +1 -1
  2. package/dist/api/allnetwork/AllNetworkGetAddress.d.ts +3 -1
  3. package/dist/api/allnetwork/AllNetworkGetAddress.d.ts.map +1 -1
  4. package/dist/api/device/DeviceUnlock.d.ts +7 -0
  5. package/dist/api/device/DeviceUnlock.d.ts.map +1 -0
  6. package/dist/api/index.d.ts +1 -0
  7. package/dist/api/index.d.ts.map +1 -1
  8. package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -1
  9. package/dist/core/index.d.ts.map +1 -1
  10. package/dist/data-manager/DataManager.d.ts.map +1 -1
  11. package/dist/data-manager/TransportManager.d.ts.map +1 -1
  12. package/dist/device/Device.d.ts +9 -4
  13. package/dist/device/Device.d.ts.map +1 -1
  14. package/dist/device/DeviceCommands.d.ts +7 -5
  15. package/dist/device/DeviceCommands.d.ts.map +1 -1
  16. package/dist/events/device.d.ts +3 -0
  17. package/dist/events/device.d.ts.map +1 -1
  18. package/dist/events/ui-request.d.ts +2 -1
  19. package/dist/events/ui-request.d.ts.map +1 -1
  20. package/dist/events/ui-response.d.ts +1 -0
  21. package/dist/events/ui-response.d.ts.map +1 -1
  22. package/dist/index.d.ts +27 -12
  23. package/dist/index.js +198 -71
  24. package/dist/inject.d.ts.map +1 -1
  25. package/dist/types/api/deviceUnlock.d.ts +4 -0
  26. package/dist/types/api/deviceUnlock.d.ts.map +1 -0
  27. package/dist/types/api/index.d.ts +2 -0
  28. package/dist/types/api/index.d.ts.map +1 -1
  29. package/dist/types/params.d.ts +1 -0
  30. package/dist/types/params.d.ts.map +1 -1
  31. package/dist/types/settings.d.ts +1 -1
  32. package/dist/types/settings.d.ts.map +1 -1
  33. package/dist/utils/deviceFeaturesUtils.d.ts +16 -2
  34. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  35. package/dist/utils/logger.d.ts +0 -2
  36. package/dist/utils/logger.d.ts.map +1 -1
  37. package/dist/utils/patch.d.ts +1 -1
  38. package/dist/utils/patch.d.ts.map +1 -1
  39. package/package.json +4 -4
  40. package/src/api/FirmwareUpdate.ts +1 -1
  41. package/src/api/GetPassphraseState.ts +4 -4
  42. package/src/api/allnetwork/AllNetworkGetAddress.ts +18 -20
  43. package/src/api/device/DeviceUnlock.ts +26 -0
  44. package/src/api/index.ts +1 -0
  45. package/src/api/stellar/StellarSignTransaction.ts +0 -3
  46. package/src/core/index.ts +17 -8
  47. package/src/data/messages/messages.json +49 -2
  48. package/src/data-manager/DataManager.ts +1 -1
  49. package/src/data-manager/TransportManager.ts +0 -3
  50. package/src/device/Device.ts +92 -20
  51. package/src/device/DeviceCommands.ts +15 -5
  52. package/src/events/device.ts +4 -0
  53. package/src/events/ui-request.ts +2 -1
  54. package/src/events/ui-response.ts +1 -0
  55. package/src/inject.ts +2 -0
  56. package/src/types/api/deviceUnlock.ts +4 -0
  57. package/src/types/api/index.ts +2 -0
  58. package/src/types/params.ts +5 -0
  59. package/src/types/settings.ts +1 -9
  60. package/src/utils/deviceFeaturesUtils.ts +65 -7
  61. package/src/utils/logger.ts +0 -2
@@ -73,11 +73,24 @@ 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 (device: Device) => {
76
+ export const getPassphraseStateWithRefreshDeviceInfo = async (
77
+ device: Device,
78
+ options?: {
79
+ expectPassphraseState?: string;
80
+ onlyMainPin?: boolean;
81
+ }
82
+ ) => {
77
83
  const { features, commands } = device;
78
84
  const locked = features?.unlocked === false;
79
85
 
80
- const passphraseState = await getPassphraseState(features, commands);
86
+ const { passphraseState, newSession, unlockedAttachPin } = await getPassphraseState(
87
+ features,
88
+ commands,
89
+ {
90
+ ...options,
91
+ }
92
+ );
93
+
81
94
  const isModeT =
82
95
  getDeviceType(features) === EDeviceType.Touch || getDeviceType(features) === EDeviceType.Pro;
83
96
 
@@ -93,14 +106,55 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (device: Device) =>
93
106
  await device.getFeatures();
94
107
  }
95
108
 
96
- return passphraseState;
109
+ // Attach to pin try to fix internal state
110
+ if (features?.device_id) {
111
+ device.updateInternalState(
112
+ device.features?.passphrase_protection ?? false,
113
+ passphraseState,
114
+ device.features?.device_id ?? '',
115
+ newSession,
116
+ device.features?.session_id
117
+ );
118
+ }
119
+
120
+ return { passphraseState, newSession, unlockedAttachPin };
97
121
  };
98
122
 
99
123
  export const getPassphraseState = async (
100
124
  features: Features | undefined,
101
- commands: DeviceCommands
102
- ) => {
103
- if (!features) return false;
125
+ commands: DeviceCommands,
126
+ options?: {
127
+ expectPassphraseState?: string;
128
+ onlyMainPin?: boolean;
129
+ }
130
+ ): Promise<{
131
+ passphraseState: string | undefined;
132
+ newSession: string | undefined;
133
+ unlockedAttachPin: boolean | undefined;
134
+ }> => {
135
+ if (!features)
136
+ return { passphraseState: undefined, newSession: undefined, unlockedAttachPin: undefined };
137
+
138
+ const firmwareVersion = getDeviceFirmwareVersion(features);
139
+ const deviceType = getDeviceType(features);
140
+
141
+ if (deviceType === EDeviceType.Pro && semver.gte(firmwareVersion.join('.'), '4.15.0')) {
142
+ const { message, type } = await commands.typedCall('GetPassphraseState', 'PassphraseState', {
143
+ passphrase_state: options?.onlyMainPin ? undefined : options?.expectPassphraseState,
144
+ });
145
+
146
+ // @ts-expect-error
147
+ if (type === 'CallMethodError') {
148
+ throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Get the passphrase state error');
149
+ }
150
+
151
+ return {
152
+ passphraseState: message.passphrase_state,
153
+ newSession: message.session_id,
154
+ unlockedAttachPin: message.unlocked_attach_pin,
155
+ };
156
+ }
157
+
104
158
  const { message, type } = await commands.typedCall('GetAddress', 'Address', {
105
159
  address_n: [toHardened(44), toHardened(1), toHardened(0), 0, 0],
106
160
  coin_name: 'Testnet',
@@ -113,7 +167,11 @@ export const getPassphraseState = async (
113
167
  throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Get the passphrase state error');
114
168
  }
115
169
 
116
- return message.address;
170
+ return {
171
+ passphraseState: message.address,
172
+ newSession: undefined,
173
+ unlockedAttachPin: undefined,
174
+ };
117
175
  };
118
176
 
119
177
  export const supportBatchPublicKey = (
@@ -157,7 +157,6 @@ export enum LoggerNames {
157
157
  HdTransportHttp = '@onekey/hd-transport-http',
158
158
  HdTransportLowLevel = '@onekey/hd-transport-lowlevel',
159
159
  HdBleTransport = '@onekey/hd-ble-transport',
160
- HdWebBleTransport = '@onekey/hd-web-ble-transport',
161
160
  Connect = '@onekey/connect',
162
161
  Iframe = 'IFrame',
163
162
  SendMessage = '[SendMessage]',
@@ -175,7 +174,6 @@ export const LoggerMap = {
175
174
  [LoggerNames.HdBleSdk]: initLog(LoggerNames.HdBleSdk),
176
175
  [LoggerNames.HdTransportHttp]: initLog(LoggerNames.HdTransportHttp),
177
176
  [LoggerNames.HdBleTransport]: initLog(LoggerNames.HdBleTransport),
178
- [LoggerNames.HdWebBleTransport]: initLog(LoggerNames.HdWebBleTransport),
179
177
  [LoggerNames.HdTransportLowLevel]: initLog(LoggerNames.HdTransportLowLevel),
180
178
  [LoggerNames.Connect]: initLog(LoggerNames.Connect),
181
179
  [LoggerNames.Iframe]: initLog(LoggerNames.Iframe),