@onekeyfe/hd-core 0.2.41 → 0.2.42

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.
@@ -19,6 +19,7 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
19
19
  min: string;
20
20
  };
21
21
  };
22
+ hasNestedArrays(item: any): boolean;
22
23
  supportSignTyped(): boolean;
23
24
  run(): Promise<import("@onekeyfe/hd-transport").EthereumMessageSignature>;
24
25
  }
@@ -1 +1 @@
1
- {"version":3,"file":"EVMSignTypedData.d.ts","sourceRoot":"","sources":["../../../src/api/evm/EVMSignTypedData.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAK3C,OAAO,KAAK,EACV,4BAA4B,EAC5B,0BAA0B,EAC3B,MAAM,kCAAkC,CAAC;AAE1C,oBAAY,sBAAsB,GAAG;IACnC,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,IAAI,EAAE,4BAA4B,CAAC,0BAA0B,CAAC,CAAC;IAC/D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,UAAU,CAAC,sBAAsB,CAAC;IAC9E,IAAI;IAqCE,aAAa;;;;IAmHnB,eAAe;;;;;IAQf,gBAAgB;IAcV,GAAG;CAkDV"}
1
+ {"version":3,"file":"EVMSignTypedData.d.ts","sourceRoot":"","sources":["../../../src/api/evm/EVMSignTypedData.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAK3C,OAAO,KAAK,EACV,4BAA4B,EAC5B,0BAA0B,EAC3B,MAAM,kCAAkC,CAAC;AAE1C,oBAAY,sBAAsB,GAAG;IACnC,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,IAAI,EAAE,4BAA4B,CAAC,0BAA0B,CAAC,CAAC;IAC/D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,UAAU,CAAC,sBAAsB,CAAC;IAC9E,IAAI;IAqCE,aAAa;;;;IAmHnB,eAAe;;;;;IAQf,eAAe,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO;IA8BnC,gBAAgB;IAcV,GAAG;CAqFV"}
package/dist/index.js CHANGED
@@ -15408,6 +15408,30 @@ class EVMSignTypedData extends BaseMethod {
15408
15408
  },
15409
15409
  };
15410
15410
  }
15411
+ hasNestedArrays(item) {
15412
+ if (!item)
15413
+ return false;
15414
+ if (Array.isArray(item)) {
15415
+ for (const element of item) {
15416
+ if (Array.isArray(element)) {
15417
+ return true;
15418
+ }
15419
+ if (typeof element === 'object' && element !== null) {
15420
+ if (this.hasNestedArrays(element)) {
15421
+ return true;
15422
+ }
15423
+ }
15424
+ }
15425
+ }
15426
+ else if (typeof item === 'object' && item !== null) {
15427
+ for (const property in item) {
15428
+ if (this.hasNestedArrays(item[property])) {
15429
+ return true;
15430
+ }
15431
+ }
15432
+ }
15433
+ return false;
15434
+ }
15411
15435
  supportSignTyped() {
15412
15436
  const deviceType = getDeviceType(this.device.features);
15413
15437
  if (deviceType === 'classic' || deviceType === 'mini') {
@@ -15450,6 +15474,25 @@ class EVMSignTypedData extends BaseMethod {
15450
15474
  }
15451
15475
  return Promise.resolve(response.message);
15452
15476
  }
15477
+ const currentVersion = getDeviceFirmwareVersion(this.device.features).join('.');
15478
+ if (this.hasNestedArrays(this.params.data)) {
15479
+ const supportNestedArraysSignVersion = '4.2.0';
15480
+ if (semver__default["default"].gte(currentVersion, supportNestedArraysSignVersion)) {
15481
+ validateParams(this.params, [
15482
+ { name: 'domainHash', type: 'hexString', required: true },
15483
+ { name: 'messageHash', type: 'hexString', required: true },
15484
+ ]);
15485
+ const { domainHash, messageHash } = this.params;
15486
+ const response = yield this.device.commands.typedCall('EthereumSignTypedHash', 'EthereumTypedDataSignature', {
15487
+ address_n: addressN,
15488
+ domain_separator_hash: domainHash !== null && domainHash !== void 0 ? domainHash : '',
15489
+ message_hash: messageHash,
15490
+ chain_id: chainId,
15491
+ });
15492
+ return Promise.resolve(response.message);
15493
+ }
15494
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodNeedUpgradeFirmware, `Device firmware version is too low, please update to ${supportNestedArraysSignVersion}`, { current: currentVersion, require: supportNestedArraysSignVersion });
15495
+ }
15453
15496
  return this.signTypedData();
15454
15497
  });
15455
15498
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "0.2.41",
3
+ "version": "0.2.42",
4
4
  "description": "> TODO: description",
5
5
  "author": "OneKey",
6
6
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
@@ -24,8 +24,8 @@
24
24
  "url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
25
25
  },
26
26
  "dependencies": {
27
- "@onekeyfe/hd-shared": "^0.2.41",
28
- "@onekeyfe/hd-transport": "^0.2.41",
27
+ "@onekeyfe/hd-shared": "^0.2.42",
28
+ "@onekeyfe/hd-transport": "^0.2.42",
29
29
  "axios": "^0.27.2",
30
30
  "bignumber.js": "^9.0.2",
31
31
  "bytebuffer": "^5.0.1",
@@ -43,5 +43,5 @@
43
43
  "@types/semver": "^7.3.9",
44
44
  "ripple-keypairs": "^1.1.4"
45
45
  },
46
- "gitHead": "9ca2163be245dda2432f1c6c44a30fb612b7e1d5"
46
+ "gitHead": "2d770a3d42548e8e3f78aedc87582a1369c0ca59"
47
47
  }
@@ -186,6 +186,36 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
186
186
  };
187
187
  }
188
188
 
189
+ hasNestedArrays(item: any): boolean {
190
+ if (!item) return false;
191
+
192
+ if (Array.isArray(item)) {
193
+ // item is an array
194
+ for (const element of item) {
195
+ if (Array.isArray(element)) {
196
+ // element is a nested array
197
+ return true;
198
+ }
199
+ if (typeof element === 'object' && element !== null) {
200
+ // element is an object, so check its properties recursively
201
+ if (this.hasNestedArrays(element)) {
202
+ return true;
203
+ }
204
+ }
205
+ }
206
+ } else if (typeof item === 'object' && item !== null) {
207
+ // item is an object, so check its properties recursively
208
+ // eslint-disable-next-line no-restricted-syntax
209
+ for (const property in item) {
210
+ if (this.hasNestedArrays(item[property])) {
211
+ return true;
212
+ }
213
+ }
214
+ }
215
+ // no nested arrays found
216
+ return false;
217
+ }
218
+
189
219
  supportSignTyped() {
190
220
  const deviceType = getDeviceType(this.device.features);
191
221
  if (deviceType === 'classic' || deviceType === 'mini') {
@@ -247,6 +277,41 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
247
277
  return Promise.resolve(response.message);
248
278
  }
249
279
 
280
+ // Touch Pro Sign NestedArrays
281
+ const currentVersion = getDeviceFirmwareVersion(this.device.features).join('.');
282
+ if (this.hasNestedArrays(this.params.data)) {
283
+ const supportNestedArraysSignVersion = '4.2.0';
284
+
285
+ // 4.2.0 is the first version that supports nested arrays in signTypedData
286
+ if (semver.gte(currentVersion, supportNestedArraysSignVersion)) {
287
+ validateParams(this.params, [
288
+ { name: 'domainHash', type: 'hexString', required: true },
289
+ { name: 'messageHash', type: 'hexString', required: true },
290
+ ]);
291
+
292
+ const { domainHash, messageHash } = this.params;
293
+
294
+ const response = await this.device.commands.typedCall(
295
+ 'EthereumSignTypedHash',
296
+ 'EthereumTypedDataSignature',
297
+ {
298
+ address_n: addressN,
299
+ domain_separator_hash: domainHash ?? '',
300
+ message_hash: messageHash,
301
+ chain_id: chainId,
302
+ }
303
+ );
304
+
305
+ return Promise.resolve(response.message);
306
+ }
307
+
308
+ throw ERRORS.TypedError(
309
+ HardwareErrorCode.CallMethodNeedUpgradeFirmware,
310
+ `Device firmware version is too low, please update to ${supportNestedArraysSignVersion}`,
311
+ { current: currentVersion, require: supportNestedArraysSignVersion }
312
+ );
313
+ }
314
+
250
315
  // For Touch、Pro we use EthereumSignTypedData
251
316
  return this.signTypedData();
252
317
  }