@onekeyfe/hd-core 1.2.0-alpha.12 → 1.2.0-alpha.13

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 (42) hide show
  1. package/__tests__/protocol-v2-bootloader-mode.test.ts +37 -0
  2. package/__tests__/protocol-v2.test.ts +126 -52
  3. package/__tests__/protocolV2FileWrite.test.ts +12 -0
  4. package/dist/api/FirmwareUpdateV4.d.ts +2 -0
  5. package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
  6. package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
  7. package/dist/api/index.d.ts +0 -1
  8. package/dist/api/index.d.ts.map +1 -1
  9. package/dist/api/protocol-v2/DeviceUploadWallpaper.d.ts.map +1 -1
  10. package/dist/api/protocol-v2/helpers.d.ts.map +1 -1
  11. package/dist/device/Device.d.ts.map +1 -1
  12. package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
  13. package/dist/index.d.ts +4 -8
  14. package/dist/index.js +481 -145
  15. package/dist/inject.d.ts.map +1 -1
  16. package/dist/types/api/index.d.ts +1 -2
  17. package/dist/types/api/index.d.ts.map +1 -1
  18. package/dist/types/api/protocolV2.d.ts +0 -4
  19. package/dist/types/api/protocolV2.d.ts.map +1 -1
  20. package/dist/types/device.d.ts +2 -1
  21. package/dist/types/device.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/FirmwareUpdateV4.ts +46 -6
  26. package/src/api/cardano/CardanoSignMessage.ts +1 -1
  27. package/src/api/cardano/CardanoSignTransaction.ts +1 -1
  28. package/src/api/helpers/protocolV2FileWrite.ts +10 -6
  29. package/src/api/index.ts +0 -1
  30. package/src/api/protocol-v2/DeviceUploadWallpaper.ts +9 -3
  31. package/src/api/protocol-v2/helpers.ts +0 -3
  32. package/src/data/messages/messages-protocol-v2.json +422 -16
  33. package/src/data/messages/messages.json +0 -8
  34. package/src/device/Device.ts +7 -17
  35. package/src/deviceProfile/buildDeviceFeatures.ts +8 -0
  36. package/src/inject.ts +0 -2
  37. package/src/types/api/index.ts +0 -2
  38. package/src/types/api/protocolV2.ts +0 -6
  39. package/src/types/device.ts +5 -1
  40. package/dist/api/protocol-v2/FilesystemDiskControl.d.ts +0 -13
  41. package/dist/api/protocol-v2/FilesystemDiskControl.d.ts.map +0 -1
  42. package/src/api/protocol-v2/FilesystemDiskControl.ts +0 -50
@@ -7784,14 +7784,6 @@
7784
7784
  "passphrase_state": {
7785
7785
  "type": "string",
7786
7786
  "id": 1
7787
- },
7788
- "_only_main_pin": {
7789
- "type": "bool",
7790
- "id": 2
7791
- },
7792
- "allow_create_attach_pin": {
7793
- "type": "bool",
7794
- "id": 3
7795
7787
  }
7796
7788
  }
7797
7789
  },
@@ -67,7 +67,6 @@ import type { PassphrasePromptResponse } from './DeviceCommands';
67
67
  import type { Deferred, HardwareConnectProtocol } from '@onekeyfe/hd-shared';
68
68
  import type {
69
69
  OneKeyDeviceInfo as DeviceDescriptor,
70
- DeviceSessionPinResult,
71
70
  DeviceStatus,
72
71
  ProtocolV2DeviceInfo,
73
72
  Success,
@@ -1139,7 +1138,7 @@ export class Device extends EventEmitter {
1139
1138
  // both allow and require cases might generate single unexpected mode
1140
1139
  if (!this.isUnacquired()) {
1141
1140
  // allow cases
1142
- if (this.isBootloader() && !allow.includes(UI_REQUEST.BOOTLOADER)) {
1141
+ if (this.isBootloader() && !this.isProtocolV2() && !allow.includes(UI_REQUEST.BOOTLOADER)) {
1143
1142
  return UI_REQUEST.BOOTLOADER;
1144
1143
  }
1145
1144
  if (!this.isInitialized() && !allow.includes(UI_REQUEST.NOT_INITIALIZE)) {
@@ -1190,12 +1189,8 @@ export class Device extends EventEmitter {
1190
1189
 
1191
1190
  async unlockDevice() {
1192
1191
  if (this.isProtocolV2()) {
1193
- let pinResult: DeviceSessionPinResult;
1194
1192
  try {
1195
- ({ message: pinResult } = await this.commands.typedCall(
1196
- 'DeviceSessionAskPin',
1197
- 'DeviceSessionPinResult'
1198
- ));
1193
+ await this.commands.typedCall('DeviceSessionAskPin', 'Success');
1199
1194
  } catch (error) {
1200
1195
  const errorText =
1201
1196
  error instanceof Error
@@ -1207,16 +1202,11 @@ export class Device extends EventEmitter {
1207
1202
  throw error;
1208
1203
  }
1209
1204
 
1210
- const status: DeviceStatus = {};
1211
- if (pinResult.unlocked != null) {
1212
- status.unlocked = pinResult.unlocked;
1213
- }
1214
- if (pinResult.unlocked_attach_pin != null) {
1215
- status.unlocked_by_attach_to_pin = pinResult.unlocked_attach_pin;
1216
- }
1217
- if (pinResult.passphrase_protection != null) {
1218
- status.passphrase_enabled = pinResult.passphrase_protection;
1219
- }
1205
+ const { message: status } = await this.commands.typedCall(
1206
+ 'DeviceStatusGet',
1207
+ 'DeviceStatus',
1208
+ {}
1209
+ );
1220
1210
  return this.updateProtocolV2Status(status);
1221
1211
  }
1222
1212
 
@@ -135,6 +135,7 @@ export const buildProtocolV1FeaturesPayload = (
135
135
  const sessionId = features.session_id ?? previous?.sessionId ?? null;
136
136
 
137
137
  return {
138
+ ...features,
138
139
  protocol: 'V1',
139
140
  protocolVersion: features.protocol_version ?? previous?.protocolVersion ?? 1,
140
141
  deviceType,
@@ -207,6 +208,7 @@ export const buildProtocolV1FeaturesPayload = (
207
208
  se04BootHash: features.onekey_se04_boot_hash,
208
209
  },
209
210
  sessionId,
211
+ session_id: sessionId ?? undefined,
210
212
  raw: {
211
213
  protocolV1Features,
212
214
  },
@@ -364,6 +366,12 @@ export const buildProtocolV2FeaturesPayload = (
364
366
  se04BootHash: getImageHash(info?.se4?.bootloader) ?? previous?.verify?.se04BootHash,
365
367
  },
366
368
  sessionId: previous?.sessionId ?? null,
369
+ device_id: deviceId ?? undefined,
370
+ session_id: previous?.sessionId ?? undefined,
371
+ ble_name: bleName ?? undefined,
372
+ onekey_device_type: 'PRO2',
373
+ passphrase_protection: passphraseProtection ?? undefined,
374
+ bootloader_mode: bootloaderMode,
367
375
  passphraseState: previous?.passphraseState,
368
376
  unlockedAttachPin,
369
377
  raw: {
package/src/inject.ts CHANGED
@@ -207,8 +207,6 @@ export const createCoreApi = (
207
207
  filesystemPathInfoQuery: (connectId, params) =>
208
208
  call({ ...params, connectId, method: 'filesystemPathInfoQuery' }),
209
209
  filesystemFormat: connectId => call({ connectId, method: 'filesystemFormat' }),
210
- filesystemDiskControl: (connectId, params) =>
211
- call({ ...params, connectId, method: 'filesystemDiskControl' }),
212
210
  deviceRecovery: (connectId, params) => call({ ...params, connectId, method: 'deviceRecovery' }),
213
211
  deviceReset: (connectId, params) => call({ ...params, connectId, method: 'deviceReset' }),
214
212
  deviceSettings: (connectId, params) => call({ ...params, connectId, method: 'deviceSettings' }),
@@ -21,7 +21,6 @@ import type {
21
21
  filesystemDirList,
22
22
  filesystemDirMake,
23
23
  filesystemDirRemove,
24
- filesystemDiskControl,
25
24
  filesystemFileDelete,
26
25
  filesystemFileRead,
27
26
  filesystemFileWrite,
@@ -294,7 +293,6 @@ export type CoreApi = {
294
293
  filesystemDirRemove: typeof filesystemDirRemove;
295
294
  filesystemPathInfoQuery: typeof filesystemPathInfoQuery;
296
295
  filesystemFormat: typeof filesystemFormat;
297
- filesystemDiskControl: typeof filesystemDiskControl;
298
296
 
299
297
  /**
300
298
  * All network function
@@ -237,9 +237,3 @@ export declare const filesystemDirRemove: typeof dirRemove;
237
237
  export declare const filesystemPathInfoQuery: typeof pathInfo;
238
238
 
239
239
  export declare function filesystemFormat(connectId: string): Response<Success>;
240
-
241
- export declare function filesystemDiskControl(
242
- connectId: string,
243
- // enable 收紧为 boolean | 0 | 1(兼容历史的 '0' / '1' 字符串输入,内部归一化为 0/1)
244
- params: CommonParams & { enable: boolean | 0 | 1; timeoutMs?: number | string }
245
- ): Response<Success>;
@@ -129,7 +129,7 @@ export type DeviceFeaturesRaw = {
129
129
  protocolV2DeviceInfo?: ProtocolV2DeviceInfo;
130
130
  };
131
131
 
132
- export type Features = {
132
+ export type NormalizedFeatures = {
133
133
  protocol: DeviceFeaturesProtocol;
134
134
  protocolVersion?: number | null;
135
135
  deviceType: IDeviceType;
@@ -183,6 +183,10 @@ export type Features = {
183
183
  raw?: DeviceFeaturesRaw;
184
184
  };
185
185
 
186
+ export type Features = NormalizedFeatures &
187
+ Partial<Omit<PROTO.Features, keyof NormalizedFeatures>> &
188
+ Partial<Omit<PROTO.OnekeyFeatures, keyof NormalizedFeatures | keyof PROTO.Features>>;
189
+
186
190
  export type OnekeyFeatures = PROTO.OnekeyFeatures;
187
191
 
188
192
  export type IDeviceType =
@@ -1,13 +0,0 @@
1
- import { BaseMethod } from '../BaseMethod';
2
- export type FilesystemDiskControlParams = {
3
- enable?: boolean | 0 | 1;
4
- timeoutMs?: number | string;
5
- };
6
- export default class FilesystemDiskControl extends BaseMethod<{
7
- enable: 0 | 1;
8
- timeoutMs?: number;
9
- }> {
10
- init(): void;
11
- run(): Promise<any>;
12
- }
13
- //# sourceMappingURL=FilesystemDiskControl.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FilesystemDiskControl.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/FilesystemDiskControl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAM3C,MAAM,MAAM,2BAA2B,GAAG;IAExC,MAAM,CAAC,EAAE,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC7B,CAAC;AAUF,MAAM,CAAC,OAAO,OAAO,qBAAsB,SAAQ,UAAU,CAAC;IAC5D,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;IACA,IAAI;IAWE,GAAG;CAcV"}
@@ -1,50 +0,0 @@
1
- import { BaseMethod } from '../BaseMethod';
2
- import {
3
- invalidParameter,
4
- validateOptionalNonNegativeInteger,
5
- } from '../helpers/filesystemValidation';
6
-
7
- export type FilesystemDiskControlParams = {
8
- // 收紧为 boolean | 0 | 1;'0' / '1' 字符串仅作为历史输入向后兼容,内部归一化为 0/1
9
- enable?: boolean | 0 | 1;
10
- timeoutMs?: number | string;
11
- };
12
-
13
- function normalizeDiskControlEnable(value: unknown): 0 | 1 {
14
- if (value === undefined || value === null) return 0;
15
- if (typeof value === 'boolean') return value ? 1 : 0;
16
- if (value === 0 || value === '0') return 0;
17
- if (value === 1 || value === '1') return 1;
18
- throw invalidParameter('Parameter [enable] must be a boolean or 0 | 1.');
19
- }
20
-
21
- export default class FilesystemDiskControl extends BaseMethod<{
22
- enable: 0 | 1;
23
- timeoutMs?: number;
24
- }> {
25
- init() {
26
- // Protocol V2 (Pro2) 专属方法,core 调度层统一做非 V2 设备守卫
27
- this.requireProtocolV2 = true;
28
- this.skipForceUpdateCheck = true;
29
- this.useDevicePassphraseState = false;
30
- this.params = {
31
- enable: normalizeDiskControlEnable(this.payload.enable),
32
- timeoutMs: validateOptionalNonNegativeInteger(this.payload.timeoutMs, 'timeoutMs'),
33
- };
34
- }
35
-
36
- async run() {
37
- const typedCall = this.device.commands.typedCall as any;
38
- const res = await typedCall(
39
- 'FilesystemDiskControl',
40
- 'Success',
41
- {
42
- enable: this.params.enable,
43
- },
44
- {
45
- timeoutMs: this.params.timeoutMs,
46
- }
47
- );
48
- return Promise.resolve(res.message);
49
- }
50
- }