@onekeyfe/hd-core 1.0.36-alpha.1 → 1.0.37-alpha.3

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 (62) 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 +28 -11
  23. package/dist/index.js +213 -68
  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 +2 -0
  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/firmware/FirmwareUpdateBaseMethod.ts +2 -2
  45. package/src/api/index.ts +1 -0
  46. package/src/api/stellar/StellarSignTransaction.ts +0 -3
  47. package/src/core/index.ts +17 -8
  48. package/src/data/messages/messages.json +49 -2
  49. package/src/data-manager/DataManager.ts +1 -1
  50. package/src/data-manager/TransportManager.ts +3 -0
  51. package/src/device/Device.ts +92 -20
  52. package/src/device/DeviceCommands.ts +15 -5
  53. package/src/events/device.ts +4 -0
  54. package/src/events/ui-request.ts +2 -1
  55. package/src/events/ui-response.ts +1 -0
  56. package/src/inject.ts +2 -0
  57. package/src/types/api/deviceUnlock.ts +4 -0
  58. package/src/types/api/index.ts +2 -0
  59. package/src/types/params.ts +5 -0
  60. package/src/types/settings.ts +10 -1
  61. package/src/utils/deviceFeaturesUtils.ts +72 -8
  62. package/src/utils/logger.ts +2 -0
@@ -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 = (
@@ -130,12 +188,18 @@ export const supportBatchPublicKey = (
130
188
  if (!!options?.includeNode && deviceType === EDeviceType.Pro) {
131
189
  return semver.gte(currentVersion, '4.14.0');
132
190
  }
191
+ if (!!options?.includeNode && deviceType === EDeviceType.Touch) {
192
+ return semver.gte(currentVersion, '4.11.0');
193
+ }
133
194
  if (!!options?.includeNode && DeviceModelToTypes.model_classic1s.includes(deviceType)) {
134
195
  return semver.gte(currentVersion, '3.12.0');
135
196
  }
136
- if (!!options?.includeNode && deviceType === EDeviceType.Classic) {
197
+ if (!!options?.includeNode && DeviceModelToTypes.model_mini.includes(deviceType)) {
137
198
  return semver.gte(currentVersion, '3.10.0');
138
199
  }
200
+ if (options?.includeNode) {
201
+ return false;
202
+ }
139
203
 
140
204
  // support batch get public key
141
205
  if (deviceType === EDeviceType.Touch || deviceType === EDeviceType.Pro) {
@@ -157,6 +157,7 @@ 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',
160
161
  Connect = '@onekey/connect',
161
162
  Iframe = 'IFrame',
162
163
  SendMessage = '[SendMessage]',
@@ -174,6 +175,7 @@ export const LoggerMap = {
174
175
  [LoggerNames.HdBleSdk]: initLog(LoggerNames.HdBleSdk),
175
176
  [LoggerNames.HdTransportHttp]: initLog(LoggerNames.HdTransportHttp),
176
177
  [LoggerNames.HdBleTransport]: initLog(LoggerNames.HdBleTransport),
178
+ [LoggerNames.HdWebBleTransport]: initLog(LoggerNames.HdWebBleTransport),
177
179
  [LoggerNames.HdTransportLowLevel]: initLog(LoggerNames.HdTransportLowLevel),
178
180
  [LoggerNames.Connect]: initLog(LoggerNames.Connect),
179
181
  [LoggerNames.Iframe]: initLog(LoggerNames.Iframe),