@onekeyfe/hd-core 1.2.0-alpha.6 → 1.2.0-alpha.8

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.
@@ -0,0 +1,19 @@
1
+ import { parseConnectSettings } from '../src/data-manager/connectSettings';
2
+
3
+ jest.mock('../src/data/config', () => ({
4
+ getSDKVersion: jest.fn(() => '1.0.0'),
5
+ DEFAULT_DOMAIN: 'https://jssdk.onekey.so/1.0.0/',
6
+ }));
7
+
8
+ describe('parseConnectSettings', () => {
9
+ it('keeps custom configFetcher in parsed settings', () => {
10
+ const configFetcher = jest.fn();
11
+
12
+ const settings = parseConnectSettings({
13
+ fetchConfig: true,
14
+ configFetcher,
15
+ });
16
+
17
+ expect(settings.configFetcher).toBe(configFetcher);
18
+ });
19
+ });
@@ -2288,11 +2288,10 @@ describe('Protocol V2 firmware update targets', () => {
2288
2288
  'vol1:se01.bin',
2289
2289
  'vol1:application_p1.bin',
2290
2290
  ]);
2291
- expect((method as any).protocolV2StartFirmwareUpdate).toHaveBeenNthCalledWith(1, {
2292
- targets: [{ target_id: 1, path: 'vol1:resource.bin' }],
2293
- });
2294
- expect((method as any).protocolV2StartFirmwareUpdate).toHaveBeenNthCalledWith(2, {
2291
+ expect((method as any).protocolV2StartFirmwareUpdate).toHaveBeenCalledTimes(1);
2292
+ expect((method as any).protocolV2StartFirmwareUpdate).toHaveBeenCalledWith({
2295
2293
  targets: [
2294
+ { target_id: 1, path: 'vol1:resource.bin' },
2296
2295
  { target_id: 3, path: 'vol1:bootloader.bin' },
2297
2296
  { target_id: 6, path: 'vol1:coprocessor.bin' },
2298
2297
  { target_id: 7, path: 'vol1:se01.bin' },
@@ -2659,7 +2658,7 @@ describe('Protocol V2 firmware update targets', () => {
2659
2658
 
2660
2659
  expect(remoteBinaries.resourceBinaryMap).toEqual([
2661
2660
  {
2662
- fileName: 'resource-resource.bin',
2661
+ fileName: 'resource.bin',
2663
2662
  binary: resourceBinary,
2664
2663
  targetId: 1,
2665
2664
  },
@@ -2716,7 +2715,7 @@ describe('Protocol V2 firmware update targets', () => {
2716
2715
  expect(remoteBinaries).toEqual({
2717
2716
  resourceBinaryMap: [
2718
2717
  {
2719
- fileName: 'resource-resource.bin',
2718
+ fileName: 'resource.bin',
2720
2719
  binary: resourceBinary,
2721
2720
  targetId: 1,
2722
2721
  },
@@ -2725,7 +2724,7 @@ describe('Protocol V2 firmware update targets', () => {
2725
2724
  fwBinaryMap: [],
2726
2725
  installItems: [
2727
2726
  {
2728
- fileName: 'resource-resource.bin',
2727
+ fileName: 'resource.bin',
2729
2728
  binary: resourceBinary,
2730
2729
  targetId: 1,
2731
2730
  kind: 'resource',
@@ -2846,78 +2845,7 @@ describe('Protocol V2 firmware update targets', () => {
2846
2845
  getFirmwareLatestReleaseSpy.mockRestore();
2847
2846
  });
2848
2847
 
2849
- test('installs multiple Pro2 resource crates as separate update requests', async () => {
2850
- const method = new FirmwareUpdateV4({
2851
- id: 1,
2852
- payload: {
2853
- method: 'firmwareUpdateV4',
2854
- },
2855
- });
2856
-
2857
- const operations: string[] = [];
2858
- method.postTipMessage = jest.fn();
2859
- method.postProgressMessage = jest.fn();
2860
- (method as any).protocolV2CommonUpdateProcess = jest
2861
- .fn()
2862
- .mockImplementation(params => {
2863
- operations.push(`write:${params.filePath}`);
2864
- return Promise.resolve(
2865
- Number(params.processedSize ?? 0) + Number(params.payload.byteLength)
2866
- );
2867
- });
2868
- (method as any).protocolV2StartFirmwareUpdate = jest.fn().mockImplementation(({ targets }) => {
2869
- operations.push(
2870
- `install:${targets.map((target: { path: string }) => target.path).join(',')}`
2871
- );
2872
- return Promise.resolve(undefined);
2873
- });
2874
- (method as any).waitForProtocolV2FirmwareUpdateComplete = jest
2875
- .fn()
2876
- .mockResolvedValue(undefined);
2877
-
2878
- await (method as any).executeProtocolV2Update({
2879
- resourceBinaryMap: [
2880
- {
2881
- fileName: 'resource-images.bin',
2882
- binary: new Uint8Array([1]).buffer,
2883
- targetId: 1,
2884
- },
2885
- {
2886
- fileName: 'resource-fonts.bin',
2887
- binary: new Uint8Array([2]).buffer,
2888
- targetId: 1,
2889
- },
2890
- ],
2891
- bootloaderBinary: null,
2892
- fwBinaryMap: [
2893
- {
2894
- fileName: 'application_p1.bin',
2895
- binary: new Uint8Array([3]).buffer,
2896
- targetId: 4,
2897
- },
2898
- ],
2899
- });
2900
-
2901
- expect((method as any).protocolV2StartFirmwareUpdate).toHaveBeenNthCalledWith(1, {
2902
- targets: [{ target_id: 1, path: 'vol1:resource-images.bin' }],
2903
- });
2904
- expect((method as any).protocolV2StartFirmwareUpdate).toHaveBeenNthCalledWith(2, {
2905
- targets: [{ target_id: 1, path: 'vol1:resource-fonts.bin' }],
2906
- });
2907
- expect((method as any).protocolV2StartFirmwareUpdate).toHaveBeenNthCalledWith(3, {
2908
- targets: [{ target_id: 4, path: 'vol1:application_p1.bin' }],
2909
- });
2910
- expect(operations).toEqual([
2911
- 'write:vol1:resource-images.bin',
2912
- 'write:vol1:resource-fonts.bin',
2913
- 'write:vol1:application_p1.bin',
2914
- 'install:vol1:resource-images.bin',
2915
- 'install:vol1:resource-fonts.bin',
2916
- 'install:vol1:application_p1.bin',
2917
- ]);
2918
- });
2919
-
2920
- test('installs merged Pro2 resource crate as one CRATE request before firmware targets', async () => {
2848
+ test('installs merged Pro2 resource crate and firmware targets in one update request', async () => {
2921
2849
  const method = new FirmwareUpdateV4({
2922
2850
  id: 1,
2923
2851
  payload: {
@@ -2949,7 +2877,7 @@ describe('Protocol V2 firmware update targets', () => {
2949
2877
  await (method as any).executeProtocolV2Update({
2950
2878
  resourceBinaryMap: [
2951
2879
  {
2952
- fileName: 'resource-resource.bin',
2880
+ fileName: 'resource.bin',
2953
2881
  binary: new Uint8Array([1, 2]).buffer,
2954
2882
  targetId: 1,
2955
2883
  },
@@ -2964,17 +2892,17 @@ describe('Protocol V2 firmware update targets', () => {
2964
2892
  ],
2965
2893
  });
2966
2894
 
2967
- expect((method as any).protocolV2StartFirmwareUpdate).toHaveBeenNthCalledWith(1, {
2968
- targets: [{ target_id: 1, path: 'vol1:resource-resource.bin' }],
2969
- });
2970
- expect((method as any).protocolV2StartFirmwareUpdate).toHaveBeenNthCalledWith(2, {
2971
- targets: [{ target_id: 4, path: 'vol1:application_p1.bin' }],
2895
+ expect((method as any).protocolV2StartFirmwareUpdate).toHaveBeenCalledTimes(1);
2896
+ expect((method as any).protocolV2StartFirmwareUpdate).toHaveBeenCalledWith({
2897
+ targets: [
2898
+ { target_id: 1, path: 'vol1:resource.bin' },
2899
+ { target_id: 4, path: 'vol1:application_p1.bin' },
2900
+ ],
2972
2901
  });
2973
2902
  expect(operations).toEqual([
2974
- 'write:vol1:resource-resource.bin',
2903
+ 'write:vol1:resource.bin',
2975
2904
  'write:vol1:application_p1.bin',
2976
- 'install:vol1:resource-resource.bin',
2977
- 'install:vol1:application_p1.bin',
2905
+ 'install:vol1:resource.bin,vol1:application_p1.bin',
2978
2906
  ]);
2979
2907
  });
2980
2908
 
@@ -1 +1 @@
1
- {"version":3,"file":"FirmwareUpdateV4.d.ts","sourceRoot":"","sources":["../../src/api/FirmwareUpdateV4.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAa/E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAmV1E,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,wBAAwB,CAAC,sBAAsB,CAAC;IAC5F,IAAI;IAwDJ,OAAO,CAAC,8BAA8B;IAgBhC,GAAG;;;;;YAYK,aAAa;YAsDb,2BAA2B;YAW3B,uBAAuB;IAqCrC,OAAO,CAAC,uBAAuB;IAI/B,OAAO,CAAC,4BAA4B;IAQpC,OAAO,CAAC,2BAA2B;IA2BnC,OAAO,CAAC,yBAAyB;IAiBjC,OAAO,CAAC,wBAAwB;IAkBhC,OAAO,CAAC,mCAAmC;IAkB3C,OAAO,CAAC,oCAAoC;I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3,"file":"connectSettings.d.ts","sourceRoot":"","sources":["../../src/data-manager/connectSettings.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAEhD,eAAO,MAAM,gBAAgB,IAAI,CAAC;AAGlC,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,kBAAkB,EAAE,MAAM,CAAC;CAChC;AAmBD,eAAO,MAAM,MAAM,4DAqBlB,CAAC;AAEF,eAAO,MAAM,aAAa,SAAU,MAAM,uBAKzC,CAAC;AAEF,eAAO,MAAM,oBAAoB,WAAW,QAAQ,eAAe,CAAC,oBA6DnE,CAAC;AAEF,OAAO,EAAE,aAAa,EAAE,CAAC"}
package/dist/index.js CHANGED
@@ -38916,6 +38916,9 @@ const parseConnectSettings = (input = {}) => {
38916
38916
  if (input.fetchConfig) {
38917
38917
  settings.fetchConfig = input.fetchConfig;
38918
38918
  }
38919
+ if (input.configFetcher) {
38920
+ settings.configFetcher = input.configFetcher;
38921
+ }
38919
38922
  return settings;
38920
38923
  };
38921
38924
 
@@ -46068,6 +46071,9 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46068
46071
  }
46069
46072
  getProtocolV2ResourceComponentFileName(key) {
46070
46073
  const safeKey = key.replace(/[^a-z0-9_-]/gi, '_') || 'resource';
46074
+ if (safeKey === 'resource') {
46075
+ return PROTOCOL_V2_REMOTE_COMPONENT_TARGETS.CRATE.fileName;
46076
+ }
46071
46077
  return `resource-${safeKey}.bin`;
46072
46078
  }
46073
46079
  shouldInstallRemoteProtocolV2Component(release, key, component, target, features) {
@@ -46280,34 +46286,13 @@ class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod {
46280
46286
  throw error;
46281
46287
  }
46282
46288
  this.postTipMessage(exports.FirmwareUpdateTipMessage.ConfirmOnDevice);
46283
- const firmwareTargets = [];
46284
- const flushFirmwareTargets = () => __awaiter(this, void 0, void 0, function* () {
46285
- if (firmwareTargets.length === 0)
46286
- return;
46287
- const targets = firmwareTargets.splice(0, firmwareTargets.length);
46288
- Log$4.log(`[FirmwareUpdateV4] DeviceFirmwareUpdateRequest targets=${JSON.stringify(targets)}`);
46289
- const startResponse = yield this.protocolV2StartFirmwareUpdate({ targets });
46290
- yield this.waitForProtocolV2FirmwareUpdateComplete(targets, startResponse);
46291
- });
46292
- for (const item of stagedInstallTargets) {
46293
- const target = {
46294
- target_id: item.targetId,
46295
- path: item.path,
46296
- };
46297
- if (item.kind === 'resource') {
46298
- yield flushFirmwareTargets();
46299
- const resourceTargets = [target];
46300
- Log$4.log(`[FirmwareUpdateV4] DeviceFirmwareUpdateRequest resources=${JSON.stringify(resourceTargets)}`);
46301
- const startResponse = yield this.protocolV2StartFirmwareUpdate({
46302
- targets: resourceTargets,
46303
- });
46304
- yield this.waitForProtocolV2FirmwareUpdateComplete(resourceTargets, startResponse);
46305
- }
46306
- else {
46307
- firmwareTargets.push(target);
46308
- }
46309
- }
46310
- yield flushFirmwareTargets();
46289
+ const allTargets = stagedInstallTargets.map(item => ({
46290
+ target_id: item.targetId,
46291
+ path: item.path,
46292
+ }));
46293
+ Log$4.log(`[FirmwareUpdateV4] DeviceFirmwareUpdateRequest targets=${JSON.stringify(allTargets)}`);
46294
+ const startResponse = yield this.protocolV2StartFirmwareUpdate({ targets: allTargets });
46295
+ yield this.waitForProtocolV2FirmwareUpdateComplete(allTargets, startResponse);
46311
46296
  });
46312
46297
  }
46313
46298
  getProtocolV2InstallItemStagingPath(item) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "1.2.0-alpha.6",
3
+ "version": "1.2.0-alpha.8",
4
4
  "description": "Core processes and APIs for communicating with OneKey hardware devices.",
5
5
  "author": "OneKey",
6
6
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
@@ -25,8 +25,8 @@
25
25
  "url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
26
26
  },
27
27
  "dependencies": {
28
- "@onekeyfe/hd-shared": "1.2.0-alpha.6",
29
- "@onekeyfe/hd-transport": "1.2.0-alpha.6",
28
+ "@onekeyfe/hd-shared": "1.2.0-alpha.8",
29
+ "@onekeyfe/hd-transport": "1.2.0-alpha.8",
30
30
  "axios": "1.15.2",
31
31
  "bignumber.js": "^9.0.2",
32
32
  "bytebuffer": "^5.0.1",
@@ -44,5 +44,5 @@
44
44
  "@types/w3c-web-usb": "^1.0.10",
45
45
  "@types/web-bluetooth": "^0.0.21"
46
46
  },
47
- "gitHead": "b0a8d032546250b02bc737d72ac23932bdc07a61"
47
+ "gitHead": "d2b1323e5ad9c373e72d4d092f35c9f274c1fd74"
48
48
  }
@@ -788,6 +788,9 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
788
788
 
789
789
  private getProtocolV2ResourceComponentFileName(key: string) {
790
790
  const safeKey = key.replace(/[^a-z0-9_-]/gi, '_') || 'resource';
791
+ if (safeKey === 'resource') {
792
+ return PROTOCOL_V2_REMOTE_COMPONENT_TARGETS.CRATE.fileName;
793
+ }
791
794
  return `resource-${safeKey}.bin`;
792
795
  }
793
796
 
@@ -1093,38 +1096,13 @@ export default class FirmwareUpdateV4 extends FirmwareUpdateBaseMethod<FirmwareU
1093
1096
 
1094
1097
  this.postTipMessage(FirmwareUpdateTipMessage.ConfirmOnDevice);
1095
1098
 
1096
- const firmwareTargets: Array<{ target_id: number; path: string }> = [];
1097
- const flushFirmwareTargets = async () => {
1098
- if (firmwareTargets.length === 0) return;
1099
- const targets = firmwareTargets.splice(0, firmwareTargets.length);
1100
- Log.log(`[FirmwareUpdateV4] DeviceFirmwareUpdateRequest targets=${JSON.stringify(targets)}`);
1101
- const startResponse = await this.protocolV2StartFirmwareUpdate({ targets });
1102
- await this.waitForProtocolV2FirmwareUpdateComplete(targets, startResponse);
1103
- };
1104
-
1105
- for (const item of stagedInstallTargets) {
1106
- const target = {
1107
- target_id: item.targetId,
1108
- path: item.path,
1109
- };
1110
- if (item.kind === 'resource') {
1111
- await flushFirmwareTargets();
1112
- const resourceTargets = [target];
1113
- Log.log(
1114
- `[FirmwareUpdateV4] DeviceFirmwareUpdateRequest resources=${JSON.stringify(
1115
- resourceTargets
1116
- )}`
1117
- );
1118
- const startResponse = await this.protocolV2StartFirmwareUpdate({
1119
- targets: resourceTargets,
1120
- });
1121
- await this.waitForProtocolV2FirmwareUpdateComplete(resourceTargets, startResponse);
1122
- } else {
1123
- firmwareTargets.push(target);
1124
- }
1125
- }
1126
-
1127
- await flushFirmwareTargets();
1099
+ const allTargets = stagedInstallTargets.map(item => ({
1100
+ target_id: item.targetId,
1101
+ path: item.path,
1102
+ }));
1103
+ Log.log(`[FirmwareUpdateV4] DeviceFirmwareUpdateRequest targets=${JSON.stringify(allTargets)}`);
1104
+ const startResponse = await this.protocolV2StartFirmwareUpdate({ targets: allTargets });
1105
+ await this.waitForProtocolV2FirmwareUpdateComplete(allTargets, startResponse);
1128
1106
  }
1129
1107
 
1130
1108
  private getProtocolV2InstallItemStagingPath(item: ProtocolV2InstallItem) {
@@ -115,6 +115,10 @@ export const parseConnectSettings = (input: Partial<ConnectSettings> = {}) => {
115
115
  settings.fetchConfig = input.fetchConfig;
116
116
  }
117
117
 
118
+ if (input.configFetcher) {
119
+ settings.configFetcher = input.configFetcher;
120
+ }
121
+
118
122
  return settings;
119
123
  };
120
124