@onekeyfe/hd-shared 1.1.4-alpha.2 → 1.1.5

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.
@@ -55,7 +55,8 @@ export declare const HardwareErrorCode: {
55
55
  readonly NewFirmwareForceUpdate: 414;
56
56
  readonly DeviceNotSupportMethod: 415;
57
57
  readonly ForbiddenKeyPath: 416;
58
- readonly DefectiveFirmware: 417;
58
+ readonly RepeatUnlocking: 417;
59
+ readonly DefectiveFirmware: 418;
59
60
  readonly NetworkError: 500;
60
61
  readonly TransportNotConfigured: 600;
61
62
  readonly TransportCallInProgress: 601;
@@ -114,7 +115,7 @@ export declare const serializeError: (payload: any) => any;
114
115
  export declare const CreateErrorByMessage: (message: string) => HardwareError;
115
116
  declare const createNewFirmwareUnReleaseHardwareError: (currentVersion: string, requireVersion: string, methodName?: string) => HardwareError;
116
117
  declare const createNeedUpgradeFirmwareHardwareError: (currentVersion: string, requireVersion: string, methodName?: string) => HardwareError;
117
- declare const createNewFirmwareForceUpdateHardwareError: (connectId: string | undefined, deviceId: string | undefined, versionType?: 'firmware' | 'ble' | 'both', currentVersions?: {
118
+ declare const createNewFirmwareForceUpdateHardwareError: (connectId: string | undefined, deviceId: string | undefined, versionTypes?: ('firmware' | 'ble')[], currentVersions?: {
118
119
  firmware?: string;
119
120
  ble?: string;
120
121
  }) => HardwareError;
@@ -1 +1 @@
1
- {"version":3,"file":"HardwareError.d.ts","sourceRoot":"","sources":["../src/HardwareError.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,OAAO,CAAC,OAAO,iBAAiB,CAAC,CAAC;IAC7C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,GAAG,CAAC;CACd;AAED,KAAK,OAAO,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;AAE5C,KAAK,+BAA+B,GAAG;KAAG,C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,mBAC1B,MAAM,kBACN,MAAM,eACT,MAAM,kBAQpB,CAAC;AAEF,QAAA,MAAM,yCAAyC,cAClC,MAAM,GAAG,SAAS,YACnB,MAAM,GAAG,SAAS,iBACb,CAAC,UAAU,GAAG,KAAK,CAAC,EAAE,oBACnB;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,kBAsBF,CAAC;AAEF,QAAA,MAAM,6BAA6B,mBACjB,MAAM,qBACH,MAAM,eACZ,MAAM,kBAQpB,CAAC;AAEF,QAAA,MAAM,4BAA4B,aACtB,MAAM,aACL,MAAM,cACL,MAAM,cACN,MAAM,aACP,MAAM,kBAWlB,CAAC;AAEF,OAAO,EACL,uCAAuC,EACvC,sCAAsC,EACtC,yCAAyC,EACzC,6BAA6B,EAC7B,4BAA4B,GAC7B,CAAC"}
package/dist/index.d.ts CHANGED
@@ -97,7 +97,8 @@ declare const HardwareErrorCode: {
97
97
  readonly NewFirmwareForceUpdate: 414;
98
98
  readonly DeviceNotSupportMethod: 415;
99
99
  readonly ForbiddenKeyPath: 416;
100
- readonly DefectiveFirmware: 417;
100
+ readonly RepeatUnlocking: 417;
101
+ readonly DefectiveFirmware: 418;
101
102
  readonly NetworkError: 500;
102
103
  readonly TransportNotConfigured: 600;
103
104
  readonly TransportCallInProgress: 601;
@@ -156,7 +157,7 @@ declare const serializeError: (payload: any) => any;
156
157
  declare const CreateErrorByMessage: (message: string) => HardwareError;
157
158
  declare const createNewFirmwareUnReleaseHardwareError: (currentVersion: string, requireVersion: string, methodName?: string) => HardwareError;
158
159
  declare const createNeedUpgradeFirmwareHardwareError: (currentVersion: string, requireVersion: string, methodName?: string) => HardwareError;
159
- declare const createNewFirmwareForceUpdateHardwareError: (connectId: string | undefined, deviceId: string | undefined, versionType?: 'firmware' | 'ble' | 'both', currentVersions?: {
160
+ declare const createNewFirmwareForceUpdateHardwareError: (connectId: string | undefined, deviceId: string | undefined, versionTypes?: ('firmware' | 'ble')[], currentVersions?: {
160
161
  firmware?: string;
161
162
  ble?: string;
162
163
  }) => HardwareError;
package/dist/index.js CHANGED
@@ -120,7 +120,34 @@ function createDeferred(arg, data) {
120
120
  function fillStringWithArguments(value, object) {
121
121
  if (typeof value !== 'string')
122
122
  return value;
123
- return value.replace(/\{([^}]+)\}/g, (_, arg) => object[arg] || '?');
123
+ if (value.indexOf('{') === -1)
124
+ return value;
125
+ let result = '';
126
+ let i = 0;
127
+ const dict = object;
128
+ while (i < value.length) {
129
+ const open = value.indexOf('{', i);
130
+ if (open === -1) {
131
+ result += value.slice(i);
132
+ break;
133
+ }
134
+ const close = value.indexOf('}', open + 1);
135
+ if (close === -1) {
136
+ result += value.slice(i);
137
+ break;
138
+ }
139
+ result += value.slice(i, open);
140
+ const key = value.slice(open + 1, close);
141
+ if (key.length === 0) {
142
+ result += '{}';
143
+ }
144
+ else {
145
+ const replacement = dict[key];
146
+ result += replacement ? String(replacement) : '?';
147
+ }
148
+ i = close + 1;
149
+ }
150
+ return result;
124
151
  }
125
152
  class HardwareError extends Error {
126
153
  constructor(hardwareError) {
@@ -187,7 +214,8 @@ const HardwareErrorCode = {
187
214
  NewFirmwareForceUpdate: 414,
188
215
  DeviceNotSupportMethod: 415,
189
216
  ForbiddenKeyPath: 416,
190
- DefectiveFirmware: 417,
217
+ RepeatUnlocking: 417,
218
+ DefectiveFirmware: 418,
191
219
  NetworkError: 500,
192
220
  TransportNotConfigured: 600,
193
221
  TransportCallInProgress: 601,
@@ -281,6 +309,7 @@ const HardwareErrorCodeMessage = {
281
309
  [HardwareErrorCode.UseDesktopToUpdateFirmware]: 'Please use OneKey desktop client to update the firmware',
282
310
  [HardwareErrorCode.DeviceNotSupportMethod]: 'Device not support this method',
283
311
  [HardwareErrorCode.ForbiddenKeyPath]: 'Forbidden key path',
312
+ [HardwareErrorCode.RepeatUnlocking]: 'Repeat unlocking',
284
313
  [HardwareErrorCode.DefectiveFirmware]: 'Device firmware is defective, please update immediately',
285
314
  [HardwareErrorCode.NetworkError]: 'Network request error',
286
315
  [HardwareErrorCode.TransportNotConfigured]: 'Transport not configured',
@@ -372,42 +401,24 @@ const createNeedUpgradeFirmwareHardwareError = (currentVersion, requireVersion,
372
401
  const methodInfo = methodName ? ` for method '${methodName}'` : '';
373
402
  return TypedError(HardwareErrorCode.CallMethodNeedUpgradeFirmware, `Device firmware version is too low${methodInfo}, please update to ${requireVersion}`, { current: currentVersion, require: requireVersion, method: methodName });
374
403
  };
375
- const createNewFirmwareForceUpdateHardwareError = (connectId, deviceId, versionType, currentVersions) => {
376
- let message = 'Device firmware version is too low, please update to the latest version';
377
- if (versionType === 'firmware') {
378
- const currentFirmware = (currentVersions === null || currentVersions === void 0 ? void 0 : currentVersions.firmware)
379
- ? ` (current: ${currentVersions.firmware})`
380
- : '';
381
- message = `Device firmware version is too low${currentFirmware}, please update the firmware to the latest version`;
382
- }
383
- else if (versionType === 'ble') {
384
- const currentBle = (currentVersions === null || currentVersions === void 0 ? void 0 : currentVersions.ble) ? ` (current: ${currentVersions.ble})` : '';
385
- message = `Device BLE firmware version is too low${currentBle}, please update the BLE firmware to the latest version`;
386
- }
387
- else if (versionType === 'both') {
388
- const currentFirmware = (currentVersions === null || currentVersions === void 0 ? void 0 : currentVersions.firmware)
389
- ? ` firmware: ${currentVersions.firmware}`
390
- : '';
391
- const currentBle = (currentVersions === null || currentVersions === void 0 ? void 0 : currentVersions.ble) ? ` BLE: ${currentVersions.ble}` : '';
392
- const currentInfo = currentFirmware || currentBle
393
- ? ` (current -${currentFirmware}${currentFirmware && currentBle ? ',' : ''}${currentBle})`
394
- : '';
395
- message = `Device firmware and BLE firmware versions are too low${currentInfo}, please update both to the latest versions`;
396
- }
397
- else if ((currentVersions === null || currentVersions === void 0 ? void 0 : currentVersions.firmware) || (currentVersions === null || currentVersions === void 0 ? void 0 : currentVersions.ble)) {
398
- const currentFirmware = (currentVersions === null || currentVersions === void 0 ? void 0 : currentVersions.firmware)
399
- ? ` firmware: ${currentVersions.firmware}`
400
- : '';
401
- const currentBle = (currentVersions === null || currentVersions === void 0 ? void 0 : currentVersions.ble) ? ` BLE: ${currentVersions.ble}` : '';
402
- const currentInfo = currentFirmware || currentBle
403
- ? ` (current -${currentFirmware}${currentFirmware && currentBle ? ',' : ''}${currentBle})`
404
- : '';
405
- message = `Device firmware version is too low${currentInfo}, please update to the latest version`;
406
- }
404
+ const createNewFirmwareForceUpdateHardwareError = (connectId, deviceId, versionTypes, currentVersions) => {
405
+ const types = versionTypes || [];
406
+ const typeMap = { firmware: 'firmware', ble: 'BLE firmware' };
407
+ const requiredTypes = types.filter(type => type in typeMap);
408
+ const getVersionInfo = () => {
409
+ const versions = [];
410
+ if (currentVersions === null || currentVersions === void 0 ? void 0 : currentVersions.firmware)
411
+ versions.push(`firmware version: ${currentVersions.firmware}`);
412
+ if (currentVersions === null || currentVersions === void 0 ? void 0 : currentVersions.ble)
413
+ versions.push(`BLE version: ${currentVersions.ble}`);
414
+ return versions.length > 0 ? ` (${versions.join(', ')})` : '';
415
+ };
416
+ const getTypeDescription = () => requiredTypes.map(type => typeMap[type]).join(' and ');
417
+ const message = `Device ${getTypeDescription()} version is too low. ${getVersionInfo()}`;
407
418
  return TypedError(HardwareErrorCode.NewFirmwareForceUpdate, message, {
408
419
  connectId,
409
420
  deviceId,
410
- versionType,
421
+ versionTypes,
411
422
  currentVersions,
412
423
  });
413
424
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-shared",
3
- "version": "1.1.4-alpha.2",
3
+ "version": "1.1.5",
4
4
  "description": "Hardware SDK's shared tool library",
5
5
  "keywords": [
6
6
  "Hardware-SDK",
@@ -25,5 +25,5 @@
25
25
  "lint": "eslint .",
26
26
  "lint:fix": "eslint . --fix"
27
27
  },
28
- "gitHead": "90589e2c51eb9bd54651d77da60695f4e5a2aa50"
28
+ "gitHead": "dbf5d2955b81184336bbb85cf7f8314192d16b8b"
29
29
  }
@@ -12,7 +12,38 @@ type ErrorCodeUnion = ValueOf<typeof HardwareErrorCode>;
12
12
 
13
13
  function fillStringWithArguments(value: string, object: object) {
14
14
  if (typeof value !== 'string') return value;
15
- return value.replace(/\{([^}]+)\}/g, (_, arg: string) => (object as unknown as any)[arg] || '?');
15
+ // Avoid regex with potential catastrophic backtracking by parsing manually in linear time
16
+ if (value.indexOf('{') === -1) return value;
17
+ let result = '';
18
+ let i = 0;
19
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
+ const dict = object as any;
21
+ while (i < value.length) {
22
+ const open = value.indexOf('{', i);
23
+ if (open === -1) {
24
+ result += value.slice(i);
25
+ break;
26
+ }
27
+ const close = value.indexOf('}', open + 1);
28
+ if (close === -1) {
29
+ // No matching closing brace; append the rest as-is
30
+ result += value.slice(i);
31
+ break;
32
+ }
33
+ // Append text before the placeholder
34
+ result += value.slice(i, open);
35
+ const key = value.slice(open + 1, close);
36
+ if (key.length === 0) {
37
+ // Keep '{}' unchanged to match original regex behavior
38
+ result += '{}';
39
+ } else {
40
+ const replacement = dict[key];
41
+ // Preserve original semantics: falsy values fallback to '?'
42
+ result += replacement ? String(replacement) : '?';
43
+ }
44
+ i = close + 1;
45
+ }
46
+ return result;
16
47
  }
17
48
 
18
49
  export class HardwareError extends Error {
@@ -250,11 +281,16 @@ export const HardwareErrorCode = {
250
281
  */
251
282
  ForbiddenKeyPath: 416,
252
283
 
284
+ /**
285
+ * Repeat unlocking
286
+ * all network get address by loop need repeat unlocking
287
+ */
288
+ RepeatUnlocking: 417,
289
+
253
290
  /**
254
291
  * Defective firmware detected
255
- * @params:{ serialNo: string?, seVersion: string?, deviceType: string? }
256
292
  */
257
- DefectiveFirmware: 417,
293
+ DefectiveFirmware: 418,
258
294
 
259
295
  /**
260
296
  * Netword request error
@@ -480,6 +516,7 @@ export const HardwareErrorCodeMessage: HardwareErrorCodeMessageMapping = {
480
516
  'Please use OneKey desktop client to update the firmware',
481
517
  [HardwareErrorCode.DeviceNotSupportMethod]: 'Device not support this method',
482
518
  [HardwareErrorCode.ForbiddenKeyPath]: 'Forbidden key path',
519
+ [HardwareErrorCode.RepeatUnlocking]: 'Repeat unlocking',
483
520
  [HardwareErrorCode.DefectiveFirmware]: 'Device firmware is defective, please update immediately',
484
521
 
485
522
  /**
@@ -623,48 +660,30 @@ const createNeedUpgradeFirmwareHardwareError = (
623
660
  const createNewFirmwareForceUpdateHardwareError = (
624
661
  connectId: string | undefined,
625
662
  deviceId: string | undefined,
626
- versionType?: 'firmware' | 'ble' | 'both',
663
+ versionTypes?: ('firmware' | 'ble')[],
627
664
  currentVersions?: {
628
665
  firmware?: string;
629
666
  ble?: string;
630
667
  }
631
668
  ) => {
632
- let message = 'Device firmware version is too low, please update to the latest version';
633
-
634
- if (versionType === 'firmware') {
635
- const currentFirmware = currentVersions?.firmware
636
- ? ` (current: ${currentVersions.firmware})`
637
- : '';
638
- message = `Device firmware version is too low${currentFirmware}, please update the firmware to the latest version`;
639
- } else if (versionType === 'ble') {
640
- const currentBle = currentVersions?.ble ? ` (current: ${currentVersions.ble})` : '';
641
- message = `Device BLE firmware version is too low${currentBle}, please update the BLE firmware to the latest version`;
642
- } else if (versionType === 'both') {
643
- const currentFirmware = currentVersions?.firmware
644
- ? ` firmware: ${currentVersions.firmware}`
645
- : '';
646
- const currentBle = currentVersions?.ble ? ` BLE: ${currentVersions.ble}` : '';
647
- const currentInfo =
648
- currentFirmware || currentBle
649
- ? ` (current -${currentFirmware}${currentFirmware && currentBle ? ',' : ''}${currentBle})`
650
- : '';
651
- message = `Device firmware and BLE firmware versions are too low${currentInfo}, please update both to the latest versions`;
652
- } else if (currentVersions?.firmware || currentVersions?.ble) {
653
- const currentFirmware = currentVersions?.firmware
654
- ? ` firmware: ${currentVersions.firmware}`
655
- : '';
656
- const currentBle = currentVersions?.ble ? ` BLE: ${currentVersions.ble}` : '';
657
- const currentInfo =
658
- currentFirmware || currentBle
659
- ? ` (current -${currentFirmware}${currentFirmware && currentBle ? ',' : ''}${currentBle})`
660
- : '';
661
- message = `Device firmware version is too low${currentInfo}, please update to the latest version`;
662
- }
669
+ const types = versionTypes || [];
670
+ const typeMap = { firmware: 'firmware', ble: 'BLE firmware' };
671
+ const requiredTypes = types.filter(type => type in typeMap);
672
+
673
+ const getVersionInfo = () => {
674
+ const versions = [];
675
+ if (currentVersions?.firmware) versions.push(`firmware version: ${currentVersions.firmware}`);
676
+ if (currentVersions?.ble) versions.push(`BLE version: ${currentVersions.ble}`);
677
+ return versions.length > 0 ? ` (${versions.join(', ')})` : '';
678
+ };
679
+
680
+ const getTypeDescription = () => requiredTypes.map(type => typeMap[type]).join(' and ');
681
+ const message = `Device ${getTypeDescription()} version is too low. ${getVersionInfo()}`;
663
682
 
664
683
  return TypedError(HardwareErrorCode.NewFirmwareForceUpdate, message, {
665
684
  connectId,
666
685
  deviceId,
667
- versionType,
686
+ versionTypes,
668
687
  currentVersions,
669
688
  });
670
689
  };