@onekeyfe/hd-core 1.0.30 → 1.0.31

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.
@@ -1 +1 @@
1
- {"version":3,"file":"AptosGetPublicKey.d.ts","sourceRoot":"","sources":["../../../src/api/aptos/AptosGetPublicKey.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAyB,cAAc,EAAE,MAAM,aAAa,CAAC;AAGpE,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,UAAU,CAAC,GAAG,CAAC;IAC5D,SAAS,UAAS;IAElB,IAAI;IA6BJ,eAAe;;;;;IAQT,GAAG;CAiBV"}
1
+ {"version":3,"file":"AptosGetPublicKey.d.ts","sourceRoot":"","sources":["../../../src/api/aptos/AptosGetPublicKey.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAyB,cAAc,EAAE,MAAM,aAAa,CAAC;AAGpE,MAAM,CAAC,OAAO,OAAO,iBAAkB,SAAQ,UAAU,CAAC,GAAG,CAAC;IAC5D,SAAS,UAAS;IAElB,IAAI;IA6BJ,eAAe;;;;;IAQT,GAAG;CAeV"}
@@ -1 +1 @@
1
- {"version":3,"file":"CosmosGetPublicKey.d.ts","sourceRoot":"","sources":["../../../src/api/cosmos/CosmosGetPublicKey.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,aAAa,EAA4B,MAAM,aAAa,CAAC;AAGtE,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,UAAU,CAAC,GAAG,CAAC;IAC7D,SAAS,UAAS;IAElB,IAAI;IAwCJ,eAAe;;;;;;;;IAWT,GAAG;CAgBV"}
1
+ {"version":3,"file":"CosmosGetPublicKey.d.ts","sourceRoot":"","sources":["../../../src/api/cosmos/CosmosGetPublicKey.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,aAAa,EAA4B,MAAM,aAAa,CAAC;AAGtE,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,UAAU,CAAC,GAAG,CAAC;IAC7D,SAAS,UAAS;IAElB,IAAI;IAwCJ,eAAe;;;;;;;;IAWT,GAAG;CAcV"}
@@ -1 +1 @@
1
- {"version":3,"file":"EVMGetPublicKey.d.ts","sourceRoot":"","sources":["../../../src/api/evm/EVMGetPublicKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AAG1F,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAyB,YAAY,EAAE,MAAM,aAAa,CAAC;AAMlE,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,UAAU,CAAC,0BAA0B,EAAE,CAAC;IACnF,SAAS,UAAS;IAElB,QAAQ,UAAS;IAEjB,IAAI;IAkCJ,eAAe,CAAC,KAAK,EAAE,oBAAoB;IAcrC,GAAG;;;;;CAuCV"}
1
+ {"version":3,"file":"EVMGetPublicKey.d.ts","sourceRoot":"","sources":["../../../src/api/evm/EVMGetPublicKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AAG1F,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAyB,YAAY,EAAE,MAAM,aAAa,CAAC;AAOlE,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,UAAU,CAAC,0BAA0B,EAAE,CAAC;IACnF,SAAS,UAAS;IAElB,QAAQ,UAAS;IAEjB,IAAI;IAkCJ,eAAe,CAAC,KAAK,EAAE,oBAAoB;IAcrC,GAAG;;;;;CA2CV"}
@@ -1,7 +1,7 @@
1
- import { Path } from '@onekeyfe/hd-transport';
1
+ import { EcdsaPublicKeys, Path } from '@onekeyfe/hd-transport';
2
2
  import { Device } from '../../device/Device';
3
3
  export declare function batchGetPublickeys(device: Device, paths: Path[], ecdsaCurveName: string, coinType: number, options?: {
4
4
  includeNode?: boolean;
5
5
  ignoreCoinType?: boolean;
6
- }): Promise<import("../../device/DeviceCommands").TypedResponseMessage<"EcdsaPublicKeys">>;
6
+ }): Promise<EcdsaPublicKeys>;
7
7
  //# sourceMappingURL=batchGetPublickeys.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"batchGetPublickeys.d.ts","sourceRoot":"","sources":["../../../src/api/helpers/batchGetPublickeys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAG9C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAI7C,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,IAAI,EAAE,EACb,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;IACR,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,0FAsBF"}
1
+ {"version":3,"file":"batchGetPublickeys.d.ts","sourceRoot":"","sources":["../../../src/api/helpers/batchGetPublickeys.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAG/D,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAO7C,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,IAAI,EAAE,EACb,cAAc,EAAE,MAAM,EACtB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;IACR,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,4BAyDF"}
@@ -1 +1 @@
1
- {"version":3,"file":"SuiGetPublicKey.d.ts","sourceRoot":"","sources":["../../../src/api/sui/SuiGetPublicKey.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAuB,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhE,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,UAAU,CAAC,GAAG,CAAC;IAC1D,SAAS,UAAS;IAElB,IAAI;IA6BJ,eAAe;;;;;;;;IAWT,GAAG;CAgBV"}
1
+ {"version":3,"file":"SuiGetPublicKey.d.ts","sourceRoot":"","sources":["../../../src/api/sui/SuiGetPublicKey.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAuB,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhE,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,UAAU,CAAC,GAAG,CAAC;IAC1D,SAAS,UAAS;IAElB,IAAI;IA6BJ,eAAe;;;;;;;;IAWT,GAAG;CAcV"}
package/dist/index.js CHANGED
@@ -30302,24 +30302,64 @@ class BTCGetAddress extends BaseMethod {
30302
30302
  }
30303
30303
  }
30304
30304
 
30305
+ function splitArray(array, size) {
30306
+ const result = [];
30307
+ for (let i = 0; i < array.length; i += size) {
30308
+ result.push(array.slice(i, i + size));
30309
+ }
30310
+ return result;
30311
+ }
30312
+
30305
30313
  function batchGetPublickeys(device, paths, ecdsaCurveName, coinType, options) {
30306
30314
  var _a;
30307
- const existsPathNotValid = paths.find(p => p.address_n.length < 3);
30308
- if (existsPathNotValid) {
30309
- throw hdShared.TypedError(hdShared.HardwareErrorCode.ForbiddenKeyPath, 'Path length must be greater than 3');
30310
- }
30311
- const supportsBatchPublicKey = supportBatchPublicKey(device.features, options);
30312
- if (!supportsBatchPublicKey) {
30313
- throw hdShared.TypedError(hdShared.HardwareErrorCode.DeviceNotSupportMethod);
30314
- }
30315
- const existsPathNotEqualCoinType = paths.find(p => !isEqualBip44CoinType(p.address_n, coinType));
30316
- if ((options === null || options === void 0 ? void 0 : options.ignoreCoinType) === false && existsPathNotEqualCoinType) {
30317
- throw hdShared.TypedError(hdShared.HardwareErrorCode.ForbiddenKeyPath);
30318
- }
30319
- return device.commands.typedCall('BatchGetPublickeys', 'EcdsaPublicKeys', {
30320
- paths,
30321
- ecdsa_curve_name: ecdsaCurveName,
30322
- include_node: (_a = options === null || options === void 0 ? void 0 : options.includeNode) !== null && _a !== void 0 ? _a : false,
30315
+ return __awaiter(this, void 0, void 0, function* () {
30316
+ const existsPathNotValid = paths.find(p => p.address_n.length < 3);
30317
+ if (existsPathNotValid) {
30318
+ throw hdShared.TypedError(hdShared.HardwareErrorCode.ForbiddenKeyPath, 'Path length must be greater than 3');
30319
+ }
30320
+ const supportsBatchPublicKey = supportBatchPublicKey(device.features, options);
30321
+ if (!supportsBatchPublicKey) {
30322
+ throw hdShared.TypedError(hdShared.HardwareErrorCode.DeviceNotSupportMethod);
30323
+ }
30324
+ const existsPathNotEqualCoinType = paths.find(p => !isEqualBip44CoinType(p.address_n, coinType));
30325
+ if ((options === null || options === void 0 ? void 0 : options.ignoreCoinType) === false && existsPathNotEqualCoinType) {
30326
+ throw hdShared.TypedError(hdShared.HardwareErrorCode.ForbiddenKeyPath);
30327
+ }
30328
+ let batchSize = 10;
30329
+ const deviceType = getDeviceType(device.features);
30330
+ if (DeviceModelToTypes.model_mini.includes(deviceType)) {
30331
+ batchSize = 10;
30332
+ }
30333
+ else if (DeviceModelToTypes.model_touch.includes(deviceType)) {
30334
+ batchSize = 20;
30335
+ }
30336
+ const result = {
30337
+ public_keys: [],
30338
+ hd_nodes: [],
30339
+ };
30340
+ const splitPaths = splitArray(paths, batchSize);
30341
+ for (const paths of splitPaths) {
30342
+ const res = yield device.commands.typedCall('BatchGetPublickeys', 'EcdsaPublicKeys', {
30343
+ paths,
30344
+ ecdsa_curve_name: ecdsaCurveName,
30345
+ include_node: (_a = options === null || options === void 0 ? void 0 : options.includeNode) !== null && _a !== void 0 ? _a : false,
30346
+ });
30347
+ if (res.type !== 'EcdsaPublicKeys') {
30348
+ throw hdShared.TypedError(hdShared.HardwareErrorCode.DeviceNotSupportMethod, 'BatchGetPublickeys failed');
30349
+ }
30350
+ else {
30351
+ result.root_fingerprint = res.message.root_fingerprint;
30352
+ result.public_keys.push(...res.message.public_keys);
30353
+ result.hd_nodes.push(...res.message.hd_nodes);
30354
+ }
30355
+ }
30356
+ if (result.hd_nodes.length !== paths.length && (options === null || options === void 0 ? void 0 : options.includeNode)) {
30357
+ throw hdShared.TypedError(hdShared.HardwareErrorCode.CallMethodError, 'BatchGetPublickeys failed, hd_nodes length not match');
30358
+ }
30359
+ if (result.public_keys.length !== paths.length && !(options === null || options === void 0 ? void 0 : options.includeNode)) {
30360
+ throw hdShared.TypedError(hdShared.HardwareErrorCode.CallMethodError, 'BatchGetPublickeys failed, public_keys length not match');
30361
+ }
30362
+ return result;
30323
30363
  });
30324
30364
  }
30325
30365
 
@@ -30442,7 +30482,6 @@ class BTCGetPublicKey extends BaseMethod {
30442
30482
  return getBitcoinForkVersionRange(this.params.map(param => param.coin_name));
30443
30483
  }
30444
30484
  run() {
30445
- var _a;
30446
30485
  return __awaiter(this, void 0, void 0, function* () {
30447
30486
  let responses = [];
30448
30487
  try {
@@ -30454,15 +30493,15 @@ class BTCGetPublicKey extends BaseMethod {
30454
30493
  includeNode: true,
30455
30494
  ignoreCoinType: true,
30456
30495
  });
30457
- if (!((_a = res.message) === null || _a === void 0 ? void 0 : _a.hd_nodes) || this.params.length !== res.message.hd_nodes.length) {
30496
+ if (!(res === null || res === void 0 ? void 0 : res.hd_nodes) || this.params.length !== res.hd_nodes.length) {
30458
30497
  throw new Error('Invalid response from Publickeys');
30459
30498
  }
30460
30499
  for (let i = 0; i < this.params.length; i++) {
30461
30500
  const param = this.params[i];
30462
- const node = res.message.hd_nodes[i];
30501
+ const node = res.hd_nodes[i];
30463
30502
  const path = serializedPath(param.address_n);
30464
30503
  const xpub = createExtendedPublicKey(node, param.coin_name, param.script_type);
30465
- const rootFingerprint = res.message.root_fingerprint;
30504
+ const rootFingerprint = res.root_fingerprint;
30466
30505
  let xpubSegwit = xpub;
30467
30506
  if (this.isBtcNetwork(param) && isTaprootPath(param.address_n)) {
30468
30507
  const fingerprint = Number(rootFingerprint || 0)
@@ -31364,19 +31403,23 @@ class EVMGetPublicKey extends BaseMethod {
31364
31403
  return __awaiter(this, void 0, void 0, function* () {
31365
31404
  const responses = [];
31366
31405
  if (this.useBatch && this.hasBundle && supportBatchPublicKey((_a = this.device) === null || _a === void 0 ? void 0 : _a.features)) {
31367
- const res = yield this.device.commands.typedCall('BatchGetPublickeys', 'EcdsaPublicKeys', {
31368
- paths: this.params,
31369
- ecdsa_curve_name: 'secp256k1',
31370
- });
31371
- const result = res.message.public_keys.map((publicKey, index) => ({
31372
- path: serializedPath(this.params[index].address_n),
31373
- pub: publicKey,
31374
- publicKey,
31375
- }));
31376
- validateResult(result, ['pub'], {
31377
- expectedLength: this.params.length,
31378
- });
31379
- return Promise.resolve(result);
31406
+ try {
31407
+ const res = yield batchGetPublickeys(this.device, this.params, 'secp256k1', 60, {
31408
+ includeNode: false,
31409
+ ignoreCoinType: true,
31410
+ });
31411
+ const result = res.public_keys.map((publicKey, index) => ({
31412
+ path: serializedPath(this.params[index].address_n),
31413
+ pub: publicKey,
31414
+ publicKey,
31415
+ }));
31416
+ validateResult(result, ['pub'], {
31417
+ expectedLength: this.params.length,
31418
+ });
31419
+ return yield Promise.resolve(result);
31420
+ }
31421
+ catch (e) {
31422
+ }
31380
31423
  }
31381
31424
  for (let i = 0; i < this.params.length; i++) {
31382
31425
  const param = this.params[i];
@@ -33416,7 +33459,7 @@ class AptosGetAddress extends BaseMethod {
33416
33459
  const publicKeyRes = yield batchGetPublickeys(this.device, this.params, 'ed25519', 637);
33417
33460
  for (let i = 0; i < this.params.length; i++) {
33418
33461
  const param = this.params[i];
33419
- const publicKey = publicKeyRes.message.public_keys[i];
33462
+ const publicKey = publicKeyRes.public_keys[i];
33420
33463
  let address;
33421
33464
  if (this.shouldConfirm) {
33422
33465
  const addressRes = yield this.device.commands.typedCall('AptosGetAddress', 'AptosAddress', param);
@@ -33496,7 +33539,7 @@ class AptosGetPublicKey extends BaseMethod {
33496
33539
  run() {
33497
33540
  return __awaiter(this, void 0, void 0, function* () {
33498
33541
  const res = yield batchGetPublickeys(this.device, this.params, 'ed25519', 637);
33499
- const responses = res.message.public_keys.map((publicKey, index) => ({
33542
+ const responses = res.public_keys.map((publicKey, index) => ({
33500
33543
  path: serializedPath(this.params[index].address_n),
33501
33544
  pub: publicKey,
33502
33545
  publicKey,
@@ -33825,7 +33868,7 @@ class CosmosGetPublicKey extends BaseMethod {
33825
33868
  run() {
33826
33869
  return __awaiter(this, void 0, void 0, function* () {
33827
33870
  const res = yield batchGetPublickeys(this.device, this.params, this.params[0].curve, 118);
33828
- const responses = res.message.public_keys.map((publicKey, index) => ({
33871
+ const responses = res.public_keys.map((publicKey, index) => ({
33829
33872
  path: serializedPath(this.params[index].address_n),
33830
33873
  pub: publicKey,
33831
33874
  publicKey,
@@ -33922,7 +33965,7 @@ class XrpGetAddress$1 extends BaseMethod {
33922
33965
  return __awaiter(this, void 0, void 0, function* () {
33923
33966
  if (this.hasBundle && supportBatchPublicKey((_a = this.device) === null || _a === void 0 ? void 0 : _a.features) && !this.shouldConfirm) {
33924
33967
  const res = yield batchGetPublickeys(this.device, this.params, 'secp256k1', 144);
33925
- const result = res.message.public_keys.map((publicKey, index) => ({
33968
+ const result = res.public_keys.map((publicKey, index) => ({
33926
33969
  path: serializedPath(this.params[index].address_n),
33927
33970
  address: rippleKeypairs.deriveAddress(publicKey),
33928
33971
  publicKey,
@@ -34090,7 +34133,7 @@ class SuiGetAddress extends BaseMethod {
34090
34133
  const publicKeyRes = yield batchGetPublickeys(this.device, this.params, 'ed25519', 784);
34091
34134
  for (let i = 0; i < this.params.length; i++) {
34092
34135
  const param = this.params[i];
34093
- const publicKey = publicKeyRes.message.public_keys[i];
34136
+ const publicKey = publicKeyRes.public_keys[i];
34094
34137
  let address;
34095
34138
  if (this.shouldConfirm) {
34096
34139
  const addressRes = yield this.device.commands.typedCall('SuiGetAddress', 'SuiAddress', param);
@@ -34173,7 +34216,7 @@ class SuiGetPublicKey extends BaseMethod {
34173
34216
  run() {
34174
34217
  return __awaiter(this, void 0, void 0, function* () {
34175
34218
  const res = yield batchGetPublickeys(this.device, this.params, 'ed25519', 784);
34176
- const responses = res.message.public_keys.map((publicKey, index) => ({
34219
+ const responses = res.public_keys.map((publicKey, index) => ({
34177
34220
  path: serializedPath(this.params[index].address_n),
34178
34221
  publicKey,
34179
34222
  pub: publicKey,
@@ -37455,7 +37498,7 @@ class BenfenGetAddress extends BaseMethod {
37455
37498
  const publicKeyRes = yield batchGetPublickeys(this.device, this.params, 'ed25519', 728);
37456
37499
  for (let i = 0; i < this.params.length; i++) {
37457
37500
  const param = this.params[i];
37458
- const publicKey = publicKeyRes.message.public_keys[i];
37501
+ const publicKey = publicKeyRes.public_keys[i];
37459
37502
  let address;
37460
37503
  if (this.shouldConfirm) {
37461
37504
  const addressRes = yield this.device.commands.typedCall('BenfenGetAddress', 'BenfenAddress', param);
@@ -37537,7 +37580,7 @@ class BenfenGetPublicKey extends BaseMethod {
37537
37580
  run() {
37538
37581
  return __awaiter(this, void 0, void 0, function* () {
37539
37582
  const res = yield batchGetPublickeys(this.device, this.params, 'ed25519', 728);
37540
- const responses = res.message.public_keys.map((publicKey, index) => ({
37583
+ const responses = res.public_keys.map((publicKey, index) => ({
37541
37584
  path: serializedPath(this.params[index].address_n),
37542
37585
  pub: publicKey,
37543
37586
  }));
@@ -0,0 +1,2 @@
1
+ export declare function splitArray<T>(array: T[], size: number): T[][];
2
+ //# sourceMappingURL=arrayUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"arrayUtils.d.ts","sourceRoot":"","sources":["../../src/utils/arrayUtils.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,EAAE,EAAE,CAM7D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "1.0.30",
3
+ "version": "1.0.31",
4
4
  "description": "> TODO: description",
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.0.30",
29
- "@onekeyfe/hd-transport": "^1.0.30",
28
+ "@onekeyfe/hd-shared": "^1.0.31",
29
+ "@onekeyfe/hd-transport": "^1.0.31",
30
30
  "axios": "^0.27.2",
31
31
  "bignumber.js": "^9.0.2",
32
32
  "bytebuffer": "^5.0.1",
@@ -46,5 +46,5 @@
46
46
  "@types/web-bluetooth": "^0.0.21",
47
47
  "ripple-keypairs": "^1.1.4"
48
48
  },
49
- "gitHead": "e7d0b547c42856f3bf4801ede2cadb593e1cbf8e"
49
+ "gitHead": "3e31186a4c2969d666a6ea124209075ab7a8e7aa"
50
50
  }
@@ -72,7 +72,7 @@ export default class AptosGetAddress extends BaseMethod<HardwareAptosGetAddress[
72
72
 
73
73
  for (let i = 0; i < this.params.length; i++) {
74
74
  const param = this.params[i];
75
- const publicKey = publicKeyRes.message.public_keys[i];
75
+ const publicKey = publicKeyRes.public_keys[i];
76
76
  let address: string;
77
77
 
78
78
  if (this.shouldConfirm) {
@@ -48,13 +48,11 @@ export default class AptosGetPublicKey extends BaseMethod<any> {
48
48
  async run() {
49
49
  const res = await batchGetPublickeys(this.device, this.params, 'ed25519', 637);
50
50
 
51
- const responses: AptosPublicKey[] = res.message.public_keys.map(
52
- (publicKey: string, index: number) => ({
53
- path: serializedPath((this.params as unknown as any[])[index].address_n),
54
- pub: publicKey,
55
- publicKey,
56
- })
57
- );
51
+ const responses: AptosPublicKey[] = res.public_keys.map((publicKey: string, index: number) => ({
52
+ path: serializedPath((this.params as unknown as any[])[index].address_n),
53
+ pub: publicKey,
54
+ publicKey,
55
+ }));
58
56
 
59
57
  validateResult(responses, ['pub'], {
60
58
  expectedLength: this.params.length,
@@ -66,7 +66,7 @@ export default class BenfenGetAddress extends BaseMethod<HardwareBenfenGetAddres
66
66
  const publicKeyRes = await batchGetPublickeys(this.device, this.params, 'ed25519', 728);
67
67
  for (let i = 0; i < this.params.length; i++) {
68
68
  const param = this.params[i];
69
- const publicKey = publicKeyRes.message.public_keys[i];
69
+ const publicKey = publicKeyRes.public_keys[i];
70
70
  let address: string;
71
71
 
72
72
  if (this.shouldConfirm) {
@@ -51,7 +51,7 @@ export default class BenfenGetPublicKey extends BaseMethod<any> {
51
51
  async run() {
52
52
  const res = await batchGetPublickeys(this.device, this.params, 'ed25519', 728);
53
53
 
54
- const responses: BenfenPublicKey[] = res.message.public_keys.map(
54
+ const responses: BenfenPublicKey[] = res.public_keys.map(
55
55
  (publicKey: string, index: number) => ({
56
56
  path: serializedPath((this.params as any[])[index].address_n),
57
57
  pub: publicKey,
@@ -79,19 +79,19 @@ export default class BTCGetPublicKey extends BaseMethod<GetPublicKey[]> {
79
79
  ignoreCoinType: true,
80
80
  });
81
81
 
82
- if (!res.message?.hd_nodes || this.params.length !== res.message.hd_nodes.length) {
82
+ if (!res?.hd_nodes || this.params.length !== res.hd_nodes.length) {
83
83
  throw new Error('Invalid response from Publickeys');
84
84
  }
85
85
 
86
86
  for (let i = 0; i < this.params.length; i++) {
87
87
  const param = this.params[i];
88
- const node = res.message.hd_nodes[i];
88
+ const node = res.hd_nodes[i];
89
89
 
90
90
  const path = serializedPath(param.address_n);
91
91
 
92
92
  const xpub = createExtendedPublicKey(node, param.coin_name, param.script_type);
93
93
 
94
- const rootFingerprint = res.message.root_fingerprint;
94
+ const rootFingerprint = res.root_fingerprint;
95
95
 
96
96
  let xpubSegwit = xpub;
97
97
  if (this.isBtcNetwork(param) && isTaprootPath(param.address_n)) {
@@ -61,13 +61,11 @@ export default class CosmosGetPublicKey extends BaseMethod<any> {
61
61
 
62
62
  async run() {
63
63
  const res = await batchGetPublickeys(this.device, this.params, this.params[0].curve, 118);
64
- const responses: CosmosAddress[] = res.message.public_keys.map(
65
- (publicKey: string, index: number) => ({
66
- path: serializedPath((this.params as unknown as any[])[index].address_n),
67
- pub: publicKey,
68
- publicKey,
69
- })
70
- );
64
+ const responses: CosmosAddress[] = res.public_keys.map((publicKey: string, index: number) => ({
65
+ path: serializedPath((this.params as unknown as any[])[index].address_n),
66
+ pub: publicKey,
67
+ publicKey,
68
+ }));
71
69
 
72
70
  validateResult(responses, ['pub'], {
73
71
  expectedLength: this.params.length,
@@ -8,6 +8,7 @@ import { supportBatchPublicKey } from '../../utils/deviceFeaturesUtils';
8
8
  import TransportManager from '../../data-manager/TransportManager';
9
9
  import getPublicKey from './latest/getPublicKey';
10
10
  import getPublicKeyLegacyV1 from './legacyV1/getPublicKey';
11
+ import { batchGetPublickeys } from '../helpers/batchGetPublickeys';
11
12
 
12
13
  export default class EVMGetPublicKey extends BaseMethod<EthereumGetPublicKeyOneKey[]> {
13
14
  hasBundle = false;
@@ -66,20 +67,24 @@ export default class EVMGetPublicKey extends BaseMethod<EthereumGetPublicKeyOneK
66
67
  const responses: EVMPublicKey[] = [];
67
68
 
68
69
  if (this.useBatch && this.hasBundle && supportBatchPublicKey(this.device?.features)) {
69
- const res = await this.device.commands.typedCall('BatchGetPublickeys', 'EcdsaPublicKeys', {
70
- paths: this.params,
71
- ecdsa_curve_name: 'secp256k1',
72
- });
73
- const result = res.message.public_keys.map((publicKey: string, index: number) => ({
74
- path: serializedPath((this.params as unknown as any[])[index].address_n),
75
- pub: publicKey,
76
- publicKey,
77
- }));
78
-
79
- validateResult(result, ['pub'], {
80
- expectedLength: this.params.length,
81
- });
82
- return Promise.resolve(result);
70
+ try {
71
+ const res = await batchGetPublickeys(this.device, this.params, 'secp256k1', 60, {
72
+ includeNode: false,
73
+ ignoreCoinType: true,
74
+ });
75
+ const result = res.public_keys.map((publicKey: string, index: number) => ({
76
+ path: serializedPath((this.params as unknown as any[])[index].address_n),
77
+ pub: publicKey,
78
+ publicKey,
79
+ }));
80
+
81
+ validateResult(result, ['pub'], {
82
+ expectedLength: this.params.length,
83
+ });
84
+ return await Promise.resolve(result);
85
+ } catch (e) {
86
+ // ignore error, fallback to single get public key
87
+ }
83
88
  }
84
89
 
85
90
  for (let i = 0; i < this.params.length; i++) {
@@ -1,11 +1,14 @@
1
- import { Path } from '@onekeyfe/hd-transport';
1
+ import { EcdsaPublicKeys, Path } from '@onekeyfe/hd-transport';
2
2
 
3
3
  import { TypedError, HardwareErrorCode } from '@onekeyfe/hd-shared';
4
4
  import { Device } from '../../device/Device';
5
5
  import { supportBatchPublicKey } from '../../utils/deviceFeaturesUtils';
6
6
  import { isEqualBip44CoinType } from './pathUtils';
7
+ import { splitArray } from '../../utils/arrayUtils';
8
+ import { getDeviceType } from '../../utils';
9
+ import { DeviceModelToTypes } from '../../types';
7
10
 
8
- export function batchGetPublickeys(
11
+ export async function batchGetPublickeys(
9
12
  device: Device,
10
13
  paths: Path[],
11
14
  ecdsaCurveName: string,
@@ -30,9 +33,44 @@ export function batchGetPublickeys(
30
33
  throw TypedError(HardwareErrorCode.ForbiddenKeyPath);
31
34
  }
32
35
 
33
- return device.commands.typedCall('BatchGetPublickeys', 'EcdsaPublicKeys', {
34
- paths,
35
- ecdsa_curve_name: ecdsaCurveName,
36
- include_node: options?.includeNode ?? false,
37
- });
36
+ let batchSize = 10;
37
+ const deviceType = getDeviceType(device.features);
38
+ if (DeviceModelToTypes.model_mini.includes(deviceType)) {
39
+ batchSize = 10;
40
+ } else if (DeviceModelToTypes.model_touch.includes(deviceType)) {
41
+ batchSize = 20;
42
+ }
43
+
44
+ const result: EcdsaPublicKeys = {
45
+ public_keys: [],
46
+ hd_nodes: [],
47
+ };
48
+ const splitPaths = splitArray(paths, batchSize);
49
+ for (const paths of splitPaths) {
50
+ const res = await device.commands.typedCall('BatchGetPublickeys', 'EcdsaPublicKeys', {
51
+ paths,
52
+ ecdsa_curve_name: ecdsaCurveName,
53
+ include_node: options?.includeNode ?? false,
54
+ });
55
+ if (res.type !== 'EcdsaPublicKeys') {
56
+ throw TypedError(HardwareErrorCode.DeviceNotSupportMethod, 'BatchGetPublickeys failed');
57
+ } else {
58
+ result.root_fingerprint = res.message.root_fingerprint;
59
+ result.public_keys.push(...res.message.public_keys);
60
+ result.hd_nodes.push(...res.message.hd_nodes);
61
+ }
62
+ }
63
+ if (result.hd_nodes.length !== paths.length && options?.includeNode) {
64
+ throw TypedError(
65
+ HardwareErrorCode.CallMethodError,
66
+ 'BatchGetPublickeys failed, hd_nodes length not match'
67
+ );
68
+ }
69
+ if (result.public_keys.length !== paths.length && !options?.includeNode) {
70
+ throw TypedError(
71
+ HardwareErrorCode.CallMethodError,
72
+ 'BatchGetPublickeys failed, public_keys length not match'
73
+ );
74
+ }
75
+ return result;
38
76
  }
@@ -65,7 +65,7 @@ export default class SuiGetAddress extends BaseMethod<HardwareSuiGetAddress[]> {
65
65
  const publicKeyRes = await batchGetPublickeys(this.device, this.params, 'ed25519', 784);
66
66
  for (let i = 0; i < this.params.length; i++) {
67
67
  const param = this.params[i];
68
- const publicKey = publicKeyRes.message.public_keys[i];
68
+ const publicKey = publicKeyRes.public_keys[i];
69
69
  let address: string | undefined;
70
70
 
71
71
  if (this.shouldConfirm) {
@@ -50,13 +50,11 @@ export default class SuiGetPublicKey extends BaseMethod<any> {
50
50
 
51
51
  async run() {
52
52
  const res = await batchGetPublickeys(this.device, this.params, 'ed25519', 784);
53
- const responses: SuiPublicKey[] = res.message.public_keys.map(
54
- (publicKey: string, index: number) => ({
55
- path: serializedPath((this.params as unknown as any[])[index].address_n),
56
- publicKey,
57
- pub: publicKey,
58
- })
59
- );
53
+ const responses: SuiPublicKey[] = res.public_keys.map((publicKey: string, index: number) => ({
54
+ path: serializedPath((this.params as unknown as any[])[index].address_n),
55
+ publicKey,
56
+ pub: publicKey,
57
+ }));
60
58
 
61
59
  validateResult(responses, ['pub'], {
62
60
  expectedLength: this.params.length,
@@ -59,7 +59,7 @@ export default class XrpGetAddress extends BaseMethod<
59
59
  async run() {
60
60
  if (this.hasBundle && supportBatchPublicKey(this.device?.features) && !this.shouldConfirm) {
61
61
  const res = await batchGetPublickeys(this.device, this.params, 'secp256k1', 144);
62
- const result = res.message.public_keys.map((publicKey: string, index: number) => ({
62
+ const result = res.public_keys.map((publicKey: string, index: number) => ({
63
63
  path: serializedPath((this.params as unknown as any[])[index].address_n),
64
64
  address: deriveAddress(publicKey),
65
65
  publicKey,
@@ -0,0 +1,7 @@
1
+ export function splitArray<T>(array: T[], size: number): T[][] {
2
+ const result = [];
3
+ for (let i = 0; i < array.length; i += size) {
4
+ result.push(array.slice(i, i + size));
5
+ }
6
+ return result;
7
+ }