@onekeyfe/hd-core 0.2.41 → 0.2.43
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;
|
|
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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;IAwB/C,iBAAiB;CA2BlB;AAED,oBAAY,SAAS,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -11902,7 +11902,7 @@ class DeviceCommands {
|
|
|
11902
11902
|
});
|
|
11903
11903
|
}
|
|
11904
11904
|
call(type, msg = {}) {
|
|
11905
|
-
var _a, _b, _c, _d, _e;
|
|
11905
|
+
var _a, _b, _c, _d, _e, _f;
|
|
11906
11906
|
return __awaiter(this, void 0, void 0, function* () {
|
|
11907
11907
|
Log$6.debug('[DeviceCommands] [call] Sending', type);
|
|
11908
11908
|
try {
|
|
@@ -11914,10 +11914,13 @@ class DeviceCommands {
|
|
|
11914
11914
|
}
|
|
11915
11915
|
catch (error) {
|
|
11916
11916
|
Log$6.debug('[DeviceCommands] [call] Received error', error);
|
|
11917
|
-
if ((
|
|
11917
|
+
if ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) {
|
|
11918
|
+
Log$6.debug('error response', error === null || error === void 0 ? void 0 : error.response.data);
|
|
11919
|
+
}
|
|
11920
|
+
if (((_c = (_b = error === null || error === void 0 ? void 0 : error.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.error) === 'device disconnected during action') {
|
|
11918
11921
|
return { type: 'BridgeNetworkError', message: {} };
|
|
11919
11922
|
}
|
|
11920
|
-
if (((
|
|
11923
|
+
if (((_f = (_e = (_d = error === null || error === void 0 ? void 0 : error.response) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.error) === null || _f === void 0 ? void 0 : _f.indexOf('Request failed with status code')) !== -1) {
|
|
11921
11924
|
return { type: 'CallMethodError', message: {} };
|
|
11922
11925
|
}
|
|
11923
11926
|
throw error;
|
|
@@ -11989,8 +11992,13 @@ class DeviceCommands {
|
|
|
11989
11992
|
error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.FileAlreadyExists);
|
|
11990
11993
|
}
|
|
11991
11994
|
}
|
|
11992
|
-
if (code === 'Failure_UnexpectedMessage'
|
|
11993
|
-
|
|
11995
|
+
if (code === 'Failure_UnexpectedMessage') {
|
|
11996
|
+
if (callType === 'PassphraseAck') {
|
|
11997
|
+
error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.UnexpectPassphrase);
|
|
11998
|
+
}
|
|
11999
|
+
if (message === 'Not in Signing mode') {
|
|
12000
|
+
error = hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.NotInSigningMode);
|
|
12001
|
+
}
|
|
11994
12002
|
}
|
|
11995
12003
|
if (error) {
|
|
11996
12004
|
return Promise.reject(error);
|
|
@@ -15408,6 +15416,30 @@ class EVMSignTypedData extends BaseMethod {
|
|
|
15408
15416
|
},
|
|
15409
15417
|
};
|
|
15410
15418
|
}
|
|
15419
|
+
hasNestedArrays(item) {
|
|
15420
|
+
if (!item)
|
|
15421
|
+
return false;
|
|
15422
|
+
if (Array.isArray(item)) {
|
|
15423
|
+
for (const element of item) {
|
|
15424
|
+
if (Array.isArray(element)) {
|
|
15425
|
+
return true;
|
|
15426
|
+
}
|
|
15427
|
+
if (typeof element === 'object' && element !== null) {
|
|
15428
|
+
if (this.hasNestedArrays(element)) {
|
|
15429
|
+
return true;
|
|
15430
|
+
}
|
|
15431
|
+
}
|
|
15432
|
+
}
|
|
15433
|
+
}
|
|
15434
|
+
else if (typeof item === 'object' && item !== null) {
|
|
15435
|
+
for (const property in item) {
|
|
15436
|
+
if (this.hasNestedArrays(item[property])) {
|
|
15437
|
+
return true;
|
|
15438
|
+
}
|
|
15439
|
+
}
|
|
15440
|
+
}
|
|
15441
|
+
return false;
|
|
15442
|
+
}
|
|
15411
15443
|
supportSignTyped() {
|
|
15412
15444
|
const deviceType = getDeviceType(this.device.features);
|
|
15413
15445
|
if (deviceType === 'classic' || deviceType === 'mini') {
|
|
@@ -15450,6 +15482,25 @@ class EVMSignTypedData extends BaseMethod {
|
|
|
15450
15482
|
}
|
|
15451
15483
|
return Promise.resolve(response.message);
|
|
15452
15484
|
}
|
|
15485
|
+
const currentVersion = getDeviceFirmwareVersion(this.device.features).join('.');
|
|
15486
|
+
if (this.hasNestedArrays(this.params.data)) {
|
|
15487
|
+
const supportNestedArraysSignVersion = '4.2.0';
|
|
15488
|
+
if (semver__default["default"].gte(currentVersion, supportNestedArraysSignVersion)) {
|
|
15489
|
+
validateParams(this.params, [
|
|
15490
|
+
{ name: 'domainHash', type: 'hexString', required: true },
|
|
15491
|
+
{ name: 'messageHash', type: 'hexString', required: true },
|
|
15492
|
+
]);
|
|
15493
|
+
const { domainHash, messageHash } = this.params;
|
|
15494
|
+
const response = yield this.device.commands.typedCall('EthereumSignTypedHash', 'EthereumTypedDataSignature', {
|
|
15495
|
+
address_n: addressN,
|
|
15496
|
+
domain_separator_hash: domainHash !== null && domainHash !== void 0 ? domainHash : '',
|
|
15497
|
+
message_hash: messageHash,
|
|
15498
|
+
chain_id: chainId,
|
|
15499
|
+
});
|
|
15500
|
+
return Promise.resolve(response.message);
|
|
15501
|
+
}
|
|
15502
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodNeedUpgradeFirmware, `Device firmware version is too low, please update to ${supportNestedArraysSignVersion}`, { current: currentVersion, require: supportNestedArraysSignVersion });
|
|
15503
|
+
}
|
|
15453
15504
|
return this.signTypedData();
|
|
15454
15505
|
});
|
|
15455
15506
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.43",
|
|
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.
|
|
28
|
-
"@onekeyfe/hd-transport": "^0.2.
|
|
27
|
+
"@onekeyfe/hd-shared": "^0.2.43",
|
|
28
|
+
"@onekeyfe/hd-transport": "^0.2.43",
|
|
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": "
|
|
46
|
+
"gitHead": "7ba97c0f3dbf636ebb46928cc4c07c208eaf03e7"
|
|
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
|
}
|
|
@@ -79,6 +79,9 @@ export class DeviceCommands {
|
|
|
79
79
|
return res;
|
|
80
80
|
} catch (error) {
|
|
81
81
|
Log.debug('[DeviceCommands] [call] Received error', error);
|
|
82
|
+
if (error.response?.data) {
|
|
83
|
+
Log.debug('error response', error?.response.data);
|
|
84
|
+
}
|
|
82
85
|
if (error?.response?.data?.error === 'device disconnected during action') {
|
|
83
86
|
return { type: 'BridgeNetworkError', message: {} } as any;
|
|
84
87
|
}
|
|
@@ -189,8 +192,13 @@ export class DeviceCommands {
|
|
|
189
192
|
}
|
|
190
193
|
}
|
|
191
194
|
|
|
192
|
-
if (code === 'Failure_UnexpectedMessage'
|
|
193
|
-
|
|
195
|
+
if (code === 'Failure_UnexpectedMessage') {
|
|
196
|
+
if (callType === 'PassphraseAck') {
|
|
197
|
+
error = ERRORS.TypedError(HardwareErrorCode.UnexpectPassphrase);
|
|
198
|
+
}
|
|
199
|
+
if (message === 'Not in Signing mode') {
|
|
200
|
+
error = ERRORS.TypedError(HardwareErrorCode.NotInSigningMode);
|
|
201
|
+
}
|
|
194
202
|
}
|
|
195
203
|
|
|
196
204
|
if (error) {
|