@onekeyfe/hd-core 1.2.0-alpha.20 → 1.2.0-alpha.21

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 (94) hide show
  1. package/__tests__/device-lifecycle-events.test.ts +1 -1
  2. package/__tests__/device-settings.test.ts +110 -5
  3. package/__tests__/device-state-events.test.ts +3 -3
  4. package/__tests__/device-state-mapper.test.ts +15 -3
  5. package/__tests__/device-state-store.test.ts +1 -1
  6. package/__tests__/deviceSettings.test.ts +55 -15
  7. package/__tests__/evmLedgerLegacySafety.test.ts +6 -5
  8. package/__tests__/get-device-state.test.ts +7 -0
  9. package/__tests__/protocol-v2.test.ts +40 -153
  10. package/__tests__/public-device-state-api.test.ts +19 -15
  11. package/__tests__/public-pro2-api-boundary.test.ts +20 -1
  12. package/dist/api/BaseMethod.d.ts +0 -3
  13. package/dist/api/BaseMethod.d.ts.map +1 -1
  14. package/dist/api/UploadPortfolio.d.ts +0 -1
  15. package/dist/api/UploadPortfolio.d.ts.map +1 -1
  16. package/dist/api/device/DeviceSettings.d.ts.map +1 -1
  17. package/dist/api/device/DeviceUnlock.d.ts +1 -1
  18. package/dist/api/device/DeviceUnlock.d.ts.map +1 -1
  19. package/dist/api/index.d.ts +0 -3
  20. package/dist/api/index.d.ts.map +1 -1
  21. package/dist/core/RequestQueue.d.ts +1 -19
  22. package/dist/core/RequestQueue.d.ts.map +1 -1
  23. package/dist/core/index.d.ts +0 -1
  24. package/dist/core/index.d.ts.map +1 -1
  25. package/dist/device/Device.d.ts +1 -1
  26. package/dist/device/DeviceFeaturesState.d.ts +0 -1
  27. package/dist/device/DeviceFeaturesState.d.ts.map +1 -1
  28. package/dist/device/DeviceStateMapper.d.ts.map +1 -1
  29. package/dist/deviceProfile/buildDeviceFeatures.d.ts.map +1 -1
  30. package/dist/events/call.d.ts +0 -7
  31. package/dist/events/call.d.ts.map +1 -1
  32. package/dist/events/core.d.ts +2 -2
  33. package/dist/events/core.d.ts.map +1 -1
  34. package/dist/events/iframe.d.ts +0 -1
  35. package/dist/events/iframe.d.ts.map +1 -1
  36. package/dist/index.d.ts +59 -55
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +169 -310
  39. package/dist/inject.d.ts +2 -3
  40. package/dist/inject.d.ts.map +1 -1
  41. package/dist/lowLevelInject.d.ts +1 -2
  42. package/dist/lowLevelInject.d.ts.map +1 -1
  43. package/dist/topLevelInject.d.ts.map +1 -1
  44. package/dist/types/api/deviceSettings.d.ts +2 -2
  45. package/dist/types/api/deviceSettings.d.ts.map +1 -1
  46. package/dist/types/api/deviceUnlock.d.ts +2 -2
  47. package/dist/types/api/deviceUnlock.d.ts.map +1 -1
  48. package/dist/types/api/index.d.ts +1 -5
  49. package/dist/types/api/index.d.ts.map +1 -1
  50. package/dist/types/api/protocolV2.d.ts +1 -9
  51. package/dist/types/api/protocolV2.d.ts.map +1 -1
  52. package/dist/types/device.d.ts +4 -4
  53. package/dist/types/device.d.ts.map +1 -1
  54. package/dist/utils/deviceSettings.d.ts +36 -7
  55. package/dist/utils/deviceSettings.d.ts.map +1 -1
  56. package/dist/utils/index.d.ts +2 -1
  57. package/dist/utils/index.d.ts.map +1 -1
  58. package/package.json +4 -4
  59. package/src/api/BaseMethod.ts +3 -9
  60. package/src/api/UploadPortfolio.ts +2 -12
  61. package/src/api/device/DeviceSettings.ts +66 -5
  62. package/src/api/device/DeviceUnlock.ts +2 -1
  63. package/src/api/index.ts +0 -3
  64. package/src/core/RequestQueue.ts +4 -123
  65. package/src/core/index.ts +25 -31
  66. package/src/device/Device.ts +1 -1
  67. package/src/device/DeviceFeaturesState.ts +0 -9
  68. package/src/device/DeviceStateMapper.ts +8 -7
  69. package/src/deviceProfile/buildDeviceFeatures.ts +2 -1
  70. package/src/events/call.ts +0 -6
  71. package/src/events/core.ts +0 -2
  72. package/src/events/iframe.ts +0 -1
  73. package/src/index.ts +0 -4
  74. package/src/inject.ts +0 -10
  75. package/src/lowLevelInject.ts +0 -3
  76. package/src/topLevelInject.ts +0 -2
  77. package/src/types/api/deviceSettings.ts +17 -2
  78. package/src/types/api/deviceUnlock.ts +5 -2
  79. package/src/types/api/index.ts +0 -7
  80. package/src/types/api/protocolV2.ts +0 -31
  81. package/src/types/device.ts +5 -3
  82. package/src/utils/deviceSettings.ts +130 -56
  83. package/src/utils/index.ts +18 -1
  84. package/__tests__/RequestQueue.test.ts +0 -140
  85. package/__tests__/UploadPortfolio.test.ts +0 -46
  86. package/dist/api/protocol-v2/DeviceSettingsGet.d.ts +0 -6
  87. package/dist/api/protocol-v2/DeviceSettingsGet.d.ts.map +0 -1
  88. package/dist/api/protocol-v2/DeviceSettingsPageShow.d.ts +0 -16
  89. package/dist/api/protocol-v2/DeviceSettingsPageShow.d.ts.map +0 -1
  90. package/dist/api/protocol-v2/DeviceSettingsSet.d.ts +0 -12
  91. package/dist/api/protocol-v2/DeviceSettingsSet.d.ts.map +0 -1
  92. package/src/api/protocol-v2/DeviceSettingsGet.ts +0 -18
  93. package/src/api/protocol-v2/DeviceSettingsPageShow.ts +0 -70
  94. package/src/api/protocol-v2/DeviceSettingsSet.ts +0 -44
@@ -1,12 +0,0 @@
1
- import { BaseMethod } from '../BaseMethod';
2
- import type { DeviceSettings } from '@onekeyfe/hd-transport';
3
- export type DeviceSettingsSetParams = {
4
- settings?: Omit<DeviceSettings, 'passphrase_enable' | 'airgap_mode'>;
5
- };
6
- export default class DeviceSettingsSet extends BaseMethod<{
7
- settings: Omit<DeviceSettings, 'passphrase_enable' | 'airgap_mode'>;
8
- }> {
9
- init(): void;
10
- run(): Promise<import("@onekeyfe/hd-transport").Success>;
11
- }
12
- //# sourceMappingURL=DeviceSettingsSet.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DeviceSettingsSet.d.ts","sourceRoot":"","sources":["../../../src/api/protocol-v2/DeviceSettingsSet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAK3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE7D,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,EAAE,IAAI,CAAC,cAAc,EAAE,mBAAmB,GAAG,aAAa,CAAC,CAAC;CACtE,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,UAAU,CAAC;IACxD,QAAQ,EAAE,IAAI,CAAC,cAAc,EAAE,mBAAmB,GAAG,aAAa,CAAC,CAAC;CACrE,CAAC;IACA,IAAI;IAwBE,GAAG;CAKV"}
@@ -1,18 +0,0 @@
1
- import { BaseMethod } from '../BaseMethod';
2
- import { mapDeviceSettingsToState } from '../../device/DeviceStateMapper';
3
-
4
- export default class DeviceSettingsGet extends BaseMethod {
5
- init() {
6
- this.requireProtocolV2 = true;
7
- this.unlockPolicy = 'none';
8
- this.skipForceUpdateCheck = true;
9
- this.useDevicePassphraseState = false;
10
- this.params = undefined;
11
- }
12
-
13
- async run() {
14
- const res = await this.device.commands.typedCall('DeviceSettingsGet', 'DeviceSettings', {});
15
- this.device.updateState(mapDeviceSettingsToState(res.message), 'apply-settings');
16
- return Promise.resolve(res.message);
17
- }
18
- }
@@ -1,70 +0,0 @@
1
- import { DeviceSettingsPage } from '@onekeyfe/hd-transport';
2
-
3
- import { BaseMethod } from '../BaseMethod';
4
- import { invalidParameter } from '../helpers/filesystemValidation';
5
- import { getProtocolV2SettingsBehavior } from '../../protocols/protocol-v2/settingsUnlockPolicy';
6
-
7
- export type SupportedDeviceSettingsPage = DeviceSettingsPage;
8
-
9
- export type DeviceSettingsPageShowParams = {
10
- page?:
11
- | SupportedDeviceSettingsPage
12
- | 'DeviceReset'
13
- | 'DevicePinChange'
14
- | 'DevicePassphrase'
15
- | 'DeviceAirgap';
16
- fieldName?: string;
17
- field_name?: string;
18
- };
19
-
20
- const SUPPORTED_PAGES = new Set<number>([
21
- DeviceSettingsPage.DeviceReset,
22
- DeviceSettingsPage.DevicePinChange,
23
- DeviceSettingsPage.DevicePassphrase,
24
- DeviceSettingsPage.DeviceAirgap,
25
- ]);
26
-
27
- function normalizePage(value: DeviceSettingsPageShowParams['page']): SupportedDeviceSettingsPage {
28
- const page = typeof value === 'string' ? DeviceSettingsPage[value] : value;
29
- if (page !== undefined && SUPPORTED_PAGES.has(page)) {
30
- return page;
31
- }
32
- throw invalidParameter(
33
- 'Parameter [page] must be DeviceReset, DevicePinChange, DevicePassphrase, or DeviceAirgap.'
34
- );
35
- }
36
-
37
- export default class DeviceSettingsPageShow extends BaseMethod<{
38
- page: SupportedDeviceSettingsPage;
39
- field_name?: string;
40
- }> {
41
- init() {
42
- this.requireProtocolV2 = true;
43
- this.skipForceUpdateCheck = true;
44
- this.useDevicePassphraseState = false;
45
- this.params = {
46
- page: normalizePage(this.payload.page),
47
- field_name: this.payload.field_name ?? this.payload.fieldName,
48
- };
49
- const behavior = getProtocolV2SettingsBehavior({
50
- kind: 'page',
51
- page: this.params.page,
52
- });
53
- this.unlockPolicy = behavior.unlockPolicy;
54
- this.protocolV2UiInteraction = behavior.uiInteraction;
55
- }
56
-
57
- async run() {
58
- const res = await this.device.commands.typedCall(
59
- 'DeviceSettingsPageShow',
60
- 'Success',
61
- this.params
62
- );
63
- if (this.params.page === DeviceSettingsPage.DevicePassphrase) {
64
- await this.device.getDeviceState({ refreshSections: ['status'] });
65
- } else if (this.params.page === DeviceSettingsPage.DeviceAirgap) {
66
- await this.device.getDeviceState({ refreshSections: ['settings'] });
67
- }
68
- return Promise.resolve(res.message);
69
- }
70
- }
@@ -1,44 +0,0 @@
1
- import { BaseMethod } from '../BaseMethod';
2
- import { mapDeviceSettingsToState } from '../../device/DeviceStateMapper';
3
- import { getProtocolV2SettingsBehavior } from '../../protocols/protocol-v2/settingsUnlockPolicy';
4
- import { invalidParameter } from '../helpers/filesystemValidation';
5
-
6
- import type { DeviceSettings } from '@onekeyfe/hd-transport';
7
-
8
- export type DeviceSettingsSetParams = {
9
- settings?: Omit<DeviceSettings, 'passphrase_enable' | 'airgap_mode'>;
10
- };
11
-
12
- export default class DeviceSettingsSet extends BaseMethod<{
13
- settings: Omit<DeviceSettings, 'passphrase_enable' | 'airgap_mode'>;
14
- }> {
15
- init() {
16
- const { settings } = this.payload;
17
- if (!settings || typeof settings !== 'object' || Array.isArray(settings)) {
18
- throw invalidParameter('Parameter [settings] must be an object.');
19
- }
20
-
21
- const {
22
- passphrase_enable: _passphraseEnable,
23
- airgap_mode: _airgapMode,
24
- ...supported
25
- } = settings as DeviceSettings;
26
- if (Object.keys(supported).length === 0) {
27
- throw invalidParameter('Parameter [settings] must contain at least one supported setting.');
28
- }
29
-
30
- this.requireProtocolV2 = true;
31
- const behavior = getProtocolV2SettingsBehavior({ kind: 'direct', settings: supported });
32
- this.unlockPolicy = behavior.unlockPolicy;
33
- this.skipForceUpdateCheck = true;
34
- this.useDevicePassphraseState = false;
35
- this.params = { settings: supported };
36
- this.protocolV2UiInteraction = behavior.uiInteraction;
37
- }
38
-
39
- async run() {
40
- const res = await this.device.commands.typedCall('DeviceSettingsSet', 'Success', this.params);
41
- this.device.updateState(mapDeviceSettingsToState(this.params.settings), 'apply-settings');
42
- return Promise.resolve(res.message);
43
- }
44
- }