@onekeyfe/hd-core 0.2.36 → 0.2.37

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.
@@ -4,7 +4,6 @@ import { BTCPublicKey } from '../../types/api/btcGetPublicKey';
4
4
  export default class BTCGetPublicKey extends BaseMethod<GetPublicKey[]> {
5
5
  hasBundle: boolean;
6
6
  init(): void;
7
- private isBtcNetwork;
8
7
  run(): Promise<BTCPublicKey | BTCPublicKey[]>;
9
8
  }
10
9
  //# sourceMappingURL=BTCGetPublicKey.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"BTCGetPublicKey.d.ts","sourceRoot":"","sources":["../../../src/api/btc/BTCGetPublicKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAGtD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAI3C,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAE/D,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,UAAU,CAAC,YAAY,EAAE,CAAC;IACrE,SAAS,UAAS;IAElB,IAAI;IA4CJ,OAAO,CAAC,YAAY;IAId,GAAG;CA8BV"}
1
+ {"version":3,"file":"BTCGetPublicKey.d.ts","sourceRoot":"","sources":["../../../src/api/btc/BTCGetPublicKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAGtD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAI3C,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAE/D,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,UAAU,CAAC,YAAY,EAAE,CAAC;IACrE,SAAS,UAAS;IAElB,IAAI;IA4CE,GAAG;CAkBV"}
@@ -1 +1 @@
1
- {"version":3,"file":"DeviceUpdateBootloader.d.ts","sourceRoot":"","sources":["../../../src/api/device/DeviceUpdateBootloader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAQ3C,MAAM,CAAC,OAAO,OAAO,sBAAuB,SAAQ,UAAU;IAC5D,YAAY,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAQ;IAE1C,IAAI;IAMJ,cAAc,YAAa,MAAM,UAS/B;IAEI,GAAG;CA4BV"}
1
+ {"version":3,"file":"DeviceUpdateBootloader.d.ts","sourceRoot":"","sources":["../../../src/api/device/DeviceUpdateBootloader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA6B,MAAM,qBAAqB,CAAC;AAE1E,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAQ3C,MAAM,CAAC,OAAO,OAAO,sBAAuB,SAAQ,UAAU;IAC5D,YAAY,EAAE,QAAQ,CAAC,GAAG,CAAC,GAAG,IAAI,CAAQ;IAE1C,IAAI;IAMJ,cAAc,YAAa,MAAM,UAS/B;IAEI,GAAG;CA+BV"}
@@ -1,3 +1,4 @@
1
1
  import { Features } from '../../types';
2
2
  export declare function checkNeedUpdateBoot(features: Features): boolean;
3
+ export declare function checkBootloaderLength(data: ArrayBuffer): boolean;
3
4
  //# sourceMappingURL=updateBootloader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"updateBootloader.d.ts","sourceRoot":"","sources":["../../../src/api/firmware/updateBootloader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAQvC,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,WAgBrD"}
1
+ {"version":3,"file":"updateBootloader.d.ts","sourceRoot":"","sources":["../../../src/api/firmware/updateBootloader.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAQvC,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,WAgBrD;AAGD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,WAAW,WAiBtD"}
@@ -5,7 +5,6 @@ export declare const getHDPath: (path: string) => Array<number>;
5
5
  export declare const isMultisigPath: (path: Array<number>) => boolean;
6
6
  export declare const isSegwitPath: (path: Array<number>) => boolean;
7
7
  export declare const isBech32Path: (path: Array<number>) => boolean;
8
- export declare const isTaprootPath: (path: number[] | undefined) => boolean;
9
8
  export declare const getScriptType: (path: Array<number>) => InputScriptType;
10
9
  export declare const getOutputScriptType: (path?: number[] | undefined) => ChangeOutputScriptType;
11
10
  export declare const serializedPath: (path: Array<number>) => string;
@@ -1 +1 @@
1
- {"version":3,"file":"pathUtils.d.ts","sourceRoot":"","sources":["../../../src/api/helpers/pathUtils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAIjF,eAAO,MAAM,UAAU,MAAO,MAAM,KAAG,MAAiC,CAAC;AACzE,eAAO,MAAM,YAAY,MAAO,MAAM,KAAG,MAAkC,CAAC;AAW5E,eAAO,MAAM,SAAS,SAAU,MAAM,KAAG,MAAM,MAAM,CAuBpD,CAAC;AAEF,eAAO,MAAM,cAAc,SAAU,MAAM,MAAM,CAAC,KAAG,OACF,CAAC;AAEpD,eAAO,MAAM,YAAY,SAAU,MAAM,MAAM,CAAC,KAAG,OACA,CAAC;AAEpD,eAAO,MAAM,YAAY,SAAU,MAAM,MAAM,CAAC,KAAG,OACA,CAAC;AAEpD,eAAO,MAAM,aAAa,SAAU,MAAM,EAAE,GAAG,SAAS,YAC8B,CAAC;AAEvF,eAAO,MAAM,aAAa,SAAU,MAAM,MAAM,CAAC,KAAG,eAiBnD,CAAC;AAEF,eAAO,MAAM,mBAAmB,mCAAsB,sBAuBrD,CAAC;AAEF,eAAO,MAAM,cAAc,SAAU,MAAM,MAAM,CAAC,KAAG,MAWpD,CAAC;AAEF,eAAO,MAAM,YAAY,SACjB,MAAM,GAAG,MAAM,MAAM,CAAC,sCAG3B,MAAM,MAAM,CAoBd,CAAC"}
1
+ {"version":3,"file":"pathUtils.d.ts","sourceRoot":"","sources":["../../../src/api/helpers/pathUtils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAIjF,eAAO,MAAM,UAAU,MAAO,MAAM,KAAG,MAAiC,CAAC;AACzE,eAAO,MAAM,YAAY,MAAO,MAAM,KAAG,MAAkC,CAAC;AAW5E,eAAO,MAAM,SAAS,SAAU,MAAM,KAAG,MAAM,MAAM,CAuBpD,CAAC;AAEF,eAAO,MAAM,cAAc,SAAU,MAAM,MAAM,CAAC,KAAG,OACF,CAAC;AAEpD,eAAO,MAAM,YAAY,SAAU,MAAM,MAAM,CAAC,KAAG,OACA,CAAC;AAEpD,eAAO,MAAM,YAAY,SAAU,MAAM,MAAM,CAAC,KAAG,OACA,CAAC;AAEpD,eAAO,MAAM,aAAa,SAAU,MAAM,MAAM,CAAC,KAAG,eAcnD,CAAC;AAEF,eAAO,MAAM,mBAAmB,mCAAsB,sBAmBrD,CAAC;AAEF,eAAO,MAAM,cAAc,SAAU,MAAM,MAAM,CAAC,KAAG,MAWpD,CAAC;AAEF,eAAO,MAAM,YAAY,SACjB,MAAM,GAAG,MAAM,MAAM,CAAC,sCAG3B,MAAM,MAAM,CAoBd,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AACA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAqBlC,OAAO,EACL,WAAW,EAYZ,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,UAAU,CAAC;AAE7D,OAAO,eAAe,MAAM,2BAA2B,CAAC;AA4BxD,eAAO,MAAM,OAAO,YAAmB,WAAW,iBAkQjD,CAAC;AAqMF,eAAO,MAAM,MAAM,0CAkBlB,CAAC;AAoJF,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,YAAY;IACtC,aAAa,CAAC,OAAO,EAAE,WAAW;IA8CxC,OAAO;CAGR;AAED,eAAO,MAAM,QAAQ,YAGpB,CAAC;AAEF,eAAO,MAAM,aAAa,uBAIzB,CAAC;AAMF,eAAO,MAAM,IAAI,aAAoB,eAAe,aAAa,GAAG,8BAmBnE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AACA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAqBlC,OAAO,EACL,WAAW,EAYZ,MAAM,WAAW,CAAC;AAEnB,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,UAAU,CAAC;AAE7D,OAAO,eAAe,MAAM,2BAA2B,CAAC;AA4BxD,eAAO,MAAM,OAAO,YAAmB,WAAW,iBA+PjD,CAAC;AAqMF,eAAO,MAAM,MAAM,0CAkBlB,CAAC;AA8IF,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,YAAY;IACtC,aAAa,CAAC,OAAO,EAAE,WAAW;IA8CxC,OAAO;CAGR;AAED,eAAO,MAAM,QAAQ,YAGpB,CAAC;AAEF,eAAO,MAAM,aAAa,uBAIzB,CAAC;AAMF,eAAO,MAAM,IAAI,aAAoB,eAAe,aAAa,GAAG,8BAmBnE,CAAC"}
package/dist/index.d.ts CHANGED
@@ -10,7 +10,6 @@ interface CommonParams {
10
10
  pollIntervalTime?: number;
11
11
  timeout?: number;
12
12
  passphraseState?: string;
13
- useEmptyPassphrase?: boolean;
14
13
  initSession?: boolean;
15
14
  }
16
15
  declare type Params<T> = CommonParams & T & {
@@ -542,7 +541,6 @@ declare function btcGetAddress(connectId: string, deviceId: string, params: Comm
542
541
 
543
542
  declare type BTCPublicKey = {
544
543
  path: string;
545
- xpubSegwit?: string;
546
544
  } & PublicKey;
547
545
  declare type BTCGetPublicKeyParams = {
548
546
  path: string | number[];
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var semver = require('semver');
6
6
  var hdShared = require('@onekeyfe/hd-shared');
7
7
  var axios = require('axios');
8
+ var ByteBuffer = require('bytebuffer');
8
9
  var BigNumber = require('bignumber.js');
9
10
  var utils = require('@noble/hashes/utils');
10
11
  var blake2s = require('@noble/hashes/blake2s');
@@ -18,6 +19,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
18
19
 
19
20
  var semver__default = /*#__PURE__*/_interopDefaultLegacy(semver);
20
21
  var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
22
+ var ByteBuffer__default = /*#__PURE__*/_interopDefaultLegacy(ByteBuffer);
21
23
  var BigNumber__default = /*#__PURE__*/_interopDefaultLegacy(BigNumber);
22
24
  var JSZip__default = /*#__PURE__*/_interopDefaultLegacy(JSZip);
23
25
 
@@ -688,7 +690,6 @@ const getHDPath = (path) => {
688
690
  };
689
691
  const isMultisigPath = (path) => Array.isArray(path) && path[0] === toHardened(48);
690
692
  const isSegwitPath = (path) => Array.isArray(path) && path[0] === toHardened(49);
691
- const isTaprootPath = (path) => Array.isArray(path) && (path[0] === toHardened(86) || path[0] === toHardened(10025));
692
693
  const getScriptType = (path) => {
693
694
  if (!Array.isArray(path) || path.length < 1)
694
695
  return 'SPENDADDRESS';
@@ -700,9 +701,6 @@ const getScriptType = (path) => {
700
701
  return 'SPENDP2SHWITNESS';
701
702
  case 84:
702
703
  return 'SPENDWITNESS';
703
- case 86:
704
- case 10025:
705
- return 'SPENDTAPROOT';
706
704
  default:
707
705
  return 'SPENDADDRESS';
708
706
  }
@@ -721,9 +719,6 @@ const getOutputScriptType = (path) => {
721
719
  return 'PAYTOP2SHWITNESS';
722
720
  case 84:
723
721
  return 'PAYTOWITNESS';
724
- case 86:
725
- case 10025:
726
- return 'PAYTOTAPROOT';
727
722
  default:
728
723
  return 'PAYTOADDRESS';
729
724
  }
@@ -10849,6 +10844,21 @@ function checkNeedUpdateBoot(features) {
10849
10844
  semver__default["default"].gte(currentVersion, '4.1.0') &&
10850
10845
  semver__default["default"].lte(bootloaderVersion, targetBootloaderVersion.join('.')));
10851
10846
  }
10847
+ const INIT_DATA_CHUNK_SIZE$1 = 16 * 1024;
10848
+ function checkBootloaderLength(data) {
10849
+ const chunk = new Uint8Array(data.slice(0, Math.min(INIT_DATA_CHUNK_SIZE$1, data.byteLength)));
10850
+ const buffer = ByteBuffer__default["default"].wrap(chunk, undefined, undefined, true);
10851
+ buffer.LE();
10852
+ buffer.readByte();
10853
+ buffer.readByte();
10854
+ buffer.readByte();
10855
+ buffer.readByte();
10856
+ const hdrlen = buffer.readUint32();
10857
+ buffer.readUint32();
10858
+ const codelen = buffer.readUint32();
10859
+ const bootloaderLength = hdrlen + codelen;
10860
+ return bootloaderLength === data.byteLength;
10861
+ }
10852
10862
 
10853
10863
  const LOG_EVENT = 'LOG_EVENT';
10854
10864
  const LOG = {
@@ -13513,6 +13523,9 @@ class DeviceUpdateBootloader extends BaseMethod {
13513
13523
  const resource = yield getSysResourceBinary(resourceUrl);
13514
13524
  this.postTipMessage('DownloadLatestBootloaderResourceSuccess');
13515
13525
  if (resource) {
13526
+ if (!checkBootloaderLength(resource.binary)) {
13527
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CheckDownloadFileError);
13528
+ }
13516
13529
  yield updateBootloader(this.device.getCommands().typedCall.bind(this.device.getCommands()), this.postMessage, device, resource.binary);
13517
13530
  return Promise.resolve(true);
13518
13531
  }
@@ -14180,24 +14193,13 @@ class BTCGetPublicKey extends BaseMethod {
14180
14193
  });
14181
14194
  });
14182
14195
  }
14183
- isBtcNetwork(param) {
14184
- return param.coin_name === 'Testnet' || param.coin_name === 'Bitcoin';
14185
- }
14186
14196
  run() {
14187
14197
  return __awaiter(this, void 0, void 0, function* () {
14188
14198
  const responses = [];
14189
14199
  for (let i = 0; i < this.params.length; i++) {
14190
14200
  const param = this.params[i];
14191
14201
  const res = yield this.device.commands.typedCall('GetPublicKey', 'PublicKey', Object.assign({}, param));
14192
- const response = Object.assign(Object.assign({ path: serializedPath(param.address_n) }, res.message), { xpubSegwit: res.message.xpub });
14193
- if (this.isBtcNetwork(param) && isTaprootPath(param.address_n)) {
14194
- const fingerprint = Number(response.root_fingerprint || 0)
14195
- .toString(16)
14196
- .padStart(8, '0');
14197
- const descriptorPath = `${fingerprint}${response.path.substring(1)}`;
14198
- response.xpubSegwit = `tr([${descriptorPath}]${response.xpub}/<0;1>/*)`;
14199
- }
14200
- responses.push(response);
14202
+ responses.push(Object.assign({ path: serializedPath(param.address_n) }, res.message));
14201
14203
  }
14202
14204
  return Promise.resolve(this.hasBundle ? responses : responses[0]);
14203
14205
  });
@@ -18444,7 +18446,7 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
18444
18446
  (_a = method.setDevice) === null || _a === void 0 ? void 0 : _a.call(method, device);
18445
18447
  device.on(DEVICE.PIN, onDevicePinHandler);
18446
18448
  device.on(DEVICE.BUTTON, onDeviceButtonHandler);
18447
- device.on(DEVICE.PASSPHRASE, message.payload.useEmptyPassphrase ? onEmptyPassphraseHandler : onDevicePassphraseHandler);
18449
+ device.on(DEVICE.PASSPHRASE, onDevicePassphraseHandler);
18448
18450
  device.on(DEVICE.PASSPHRASE_ON_DEVICE, onEnterPassphraseOnDeviceHandler);
18449
18451
  device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
18450
18452
  try {
@@ -18748,9 +18750,7 @@ const cancel = (connectId) => {
18748
18750
  const checkPassphraseSafety = (method, features) => {
18749
18751
  if (!method.useDevicePassphraseState)
18750
18752
  return;
18751
- if ((features === null || features === void 0 ? void 0 : features.passphrase_protection) === true &&
18752
- (method.payload.passphraseState == null || method.payload.passphraseState === '') &&
18753
- !method.payload.useEmptyPassphrase) {
18753
+ if ((features === null || features === void 0 ? void 0 : features.passphrase_protection) === true && !method.payload.passphraseState) {
18754
18754
  DevicePool.clearDeviceCache(method.payload.connectId);
18755
18755
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceOpenedPassphrase);
18756
18756
  }
@@ -18764,7 +18764,11 @@ const cleanup = () => {
18764
18764
  Log.debug('Cleanup...');
18765
18765
  };
18766
18766
  const removeDeviceListener = (device) => {
18767
- device.removeAllListeners();
18767
+ device.removeListener(DEVICE.PIN, onDevicePinHandler);
18768
+ device.removeListener(DEVICE.BUTTON, onDeviceButtonHandler);
18769
+ device.removeListener(DEVICE.PASSPHRASE, onDevicePassphraseHandler);
18770
+ device.removeListener(DEVICE.PASSPHRASE_ON_DEVICE, onEnterPassphraseOnDeviceHandler);
18771
+ device.removeListener(DEVICE.FEATURES, onDeviceFeaturesHandler);
18768
18772
  DevicePool.emitter.removeListener(DEVICE.CONNECT, onDeviceConnectHandler);
18769
18773
  };
18770
18774
  const closePopup = () => {
@@ -18820,10 +18824,6 @@ const onDevicePassphraseHandler = (...[device, callback]) => __awaiter(void 0, v
18820
18824
  cache: save,
18821
18825
  });
18822
18826
  });
18823
- const onEmptyPassphraseHandler = (...[_, callback]) => {
18824
- Log.debug('onEmptyPassphraseHandler');
18825
- callback({ passphrase: '' });
18826
- };
18827
18827
  const onEnterPassphraseOnDeviceHandler = (...[device]) => {
18828
18828
  postMessage(createUiMessage(UI_REQUEST$1.REQUEST_PASSPHRASE_ON_DEVICE, {
18829
18829
  device: device.toMessageObject(),
@@ -2,7 +2,6 @@ import { InputScriptType, PublicKey } from '@onekeyfe/hd-transport';
2
2
  import type { CommonParams, Response } from '../params';
3
3
  export declare type BTCPublicKey = {
4
4
  path: string;
5
- xpubSegwit?: string;
6
5
  } & PublicKey;
7
6
  export declare type BTCGetPublicKeyParams = {
8
7
  path: string | number[];
@@ -1 +1 @@
1
- {"version":3,"file":"btcGetPublicKey.d.ts","sourceRoot":"","sources":["../../../src/types/api/btcGetPublicKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAExD,oBAAY,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GAAG,SAAS,CAAC;AAEd,oBAAY,qBAAqB,GAAG;IAClC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,UAAU,CAAC,EAAE,eAAe,CAAC;CAC9B,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,YAAY,GAAG,qBAAqB,GAC3C,QAAQ,CAAC,YAAY,CAAC,CAAC;AAE1B,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,YAAY,GAAG;IAAE,MAAM,CAAC,EAAE,qBAAqB,EAAE,CAAA;CAAE,GAC1D,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC"}
1
+ {"version":3,"file":"btcGetPublicKey.d.ts","sourceRoot":"","sources":["../../../src/types/api/btcGetPublicKey.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAExD,oBAAY,YAAY,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC;CACd,GAAG,SAAS,CAAC;AAEd,oBAAY,qBAAqB,GAAG;IAClC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,UAAU,CAAC,EAAE,eAAe,CAAC;CAC9B,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,YAAY,GAAG,qBAAqB,GAC3C,QAAQ,CAAC,YAAY,CAAC,CAAC;AAE1B,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,YAAY,GAAG;IAAE,MAAM,CAAC,EAAE,qBAAqB,EAAE,CAAA;CAAE,GAC1D,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC"}
@@ -4,7 +4,6 @@ export interface CommonParams {
4
4
  pollIntervalTime?: number;
5
5
  timeout?: number;
6
6
  passphraseState?: string;
7
- useEmptyPassphrase?: boolean;
8
7
  initSession?: boolean;
9
8
  }
10
9
  export declare type Params<T> = CommonParams & T & {
@@ -1 +1 @@
1
- {"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../../src/types/params.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,WAAW,CAAC,EAAE,OAAO,CAAC;IAItB,UAAU,CAAC,EAAE,MAAM,CAAC;IAIpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAI1B,OAAO,CAAC,EAAE,MAAM,CAAC;IAIjB,eAAe,CAAC,EAAE,MAAM,CAAC;IAIzB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAI7B,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,oBAAY,MAAM,CAAC,CAAC,IAAI,YAAY,GAAG,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,SAAS,CAAA;CAAE,CAAC;AAElE,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,KAAK,CAAC;IACf,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CACpD;AAED,MAAM,WAAW,OAAO,CAAC,CAAC;IACxB,OAAO,EAAE,IAAI,CAAC;IACd,OAAO,EAAE,CAAC,CAAC;CACZ;AAED,oBAAY,QAAQ,CAAC,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC"}
1
+ {"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../../src/types/params.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,WAAW,CAAC,EAAE,OAAO,CAAC;IAItB,UAAU,CAAC,EAAE,MAAM,CAAC;IAIpB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAI1B,OAAO,CAAC,EAAE,MAAM,CAAC;IAIjB,eAAe,CAAC,EAAE,MAAM,CAAC;IAIzB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,oBAAY,MAAM,CAAC,CAAC,IAAI,YAAY,GAAG,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,SAAS,CAAA;CAAE,CAAC;AAElE,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,KAAK,CAAC;IACf,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CACpD;AAED,MAAM,WAAW,OAAO,CAAC,CAAC;IACxB,OAAO,EAAE,IAAI,CAAC;IACd,OAAO,EAAE,CAAC,CAAC;CACZ;AAED,oBAAY,QAAQ,CAAC,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "0.2.36",
3
+ "version": "0.2.37",
4
4
  "description": "> TODO: description",
5
5
  "author": "OneKey",
6
6
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
@@ -24,10 +24,11 @@
24
24
  "url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
25
25
  },
26
26
  "dependencies": {
27
- "@onekeyfe/hd-shared": "^0.2.36",
28
- "@onekeyfe/hd-transport": "^0.2.36",
27
+ "@onekeyfe/hd-shared": "^0.2.37",
28
+ "@onekeyfe/hd-transport": "^0.2.37",
29
29
  "axios": "^0.27.2",
30
30
  "bignumber.js": "^9.0.2",
31
+ "bytebuffer": "^5.0.1",
31
32
  "jszip": "^3.10.1",
32
33
  "parse-uri": "^1.0.7",
33
34
  "semver": "^7.3.7"
@@ -42,5 +43,5 @@
42
43
  "@types/semver": "^7.3.9",
43
44
  "ripple-keypairs": "^1.1.4"
44
45
  },
45
- "gitHead": "53dfab54b8e9f221b4b855e5f36f2b618ebfcdd9"
46
+ "gitHead": "5d80d2bdb1f7e5863286c3e59064c858b245b3ca"
46
47
  }
@@ -1,6 +1,6 @@
1
1
  import { GetPublicKey } from '@onekeyfe/hd-transport';
2
2
  import { UI_REQUEST } from '../../constants/ui-request';
3
- import { getScriptType, isTaprootPath, serializedPath, validatePath } from '../helpers/pathUtils';
3
+ import { getScriptType, serializedPath, validatePath } from '../helpers/pathUtils';
4
4
  import { BaseMethod } from '../BaseMethod';
5
5
  import { validateParams } from '../helpers/paramsValidator';
6
6
  import { BTCGetAddressParams } from '../../types/api/btcGetAddress';
@@ -54,10 +54,6 @@ export default class BTCGetPublicKey extends BaseMethod<GetPublicKey[]> {
54
54
  });
55
55
  }
56
56
 
57
- private isBtcNetwork(param: GetPublicKey) {
58
- return param.coin_name === 'Testnet' || param.coin_name === 'Bitcoin';
59
- }
60
-
61
57
  async run() {
62
58
  const responses: BTCPublicKey[] = [];
63
59
 
@@ -68,22 +64,10 @@ export default class BTCGetPublicKey extends BaseMethod<GetPublicKey[]> {
68
64
  ...param,
69
65
  });
70
66
 
71
- const response = {
67
+ responses.push({
72
68
  path: serializedPath(param.address_n),
73
69
  ...res.message,
74
- xpubSegwit: res.message.xpub,
75
- };
76
-
77
- if (this.isBtcNetwork(param) && isTaprootPath(param.address_n)) {
78
- // wrap regular xpub into bitcoind native descriptor
79
- const fingerprint = Number(response.root_fingerprint || 0)
80
- .toString(16)
81
- .padStart(8, '0');
82
- const descriptorPath = `${fingerprint}${response.path.substring(1)}`;
83
- response.xpubSegwit = `tr([${descriptorPath}]${response.xpub}/<0;1>/*)`;
84
- }
85
-
86
- responses.push(response);
70
+ });
87
71
  }
88
72
 
89
73
  return Promise.resolve(this.hasBundle ? responses : responses[0]);
@@ -1,4 +1,4 @@
1
- import { Deferred } from '@onekeyfe/hd-shared';
1
+ import { Deferred, ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
2
2
  import { UI_REQUEST } from '../../constants/ui-request';
3
3
  import { BaseMethod } from '../BaseMethod';
4
4
  import { getSysResourceBinary } from '../firmware/getBinary';
@@ -6,7 +6,7 @@ import { updateBootloader } from '../firmware/uploadFirmware';
6
6
  import { createUiMessage } from '../../events/ui-request';
7
7
  import type { KnownDevice } from '../../types';
8
8
  import { DataManager } from '../../data-manager';
9
- import { checkNeedUpdateBoot } from '../firmware/updateBootloader';
9
+ import { checkBootloaderLength, checkNeedUpdateBoot } from '../firmware/updateBootloader';
10
10
 
11
11
  export default class DeviceUpdateBootloader extends BaseMethod {
12
12
  checkPromise: Deferred<any> | null = null;
@@ -42,6 +42,9 @@ export default class DeviceUpdateBootloader extends BaseMethod {
42
42
  const resource = await getSysResourceBinary(resourceUrl);
43
43
  this.postTipMessage('DownloadLatestBootloaderResourceSuccess');
44
44
  if (resource) {
45
+ if (!checkBootloaderLength(resource.binary)) {
46
+ throw ERRORS.TypedError(HardwareErrorCode.CheckDownloadFileError);
47
+ }
45
48
  await updateBootloader(
46
49
  this.device.getCommands().typedCall.bind(this.device.getCommands()),
47
50
  this.postMessage,
@@ -1,3 +1,4 @@
1
+ import ByteBuffer from 'bytebuffer';
1
2
  import semver from 'semver';
2
3
  import { Features } from '../../types';
3
4
  import { getDeviceType } from '../../utils';
@@ -24,3 +25,23 @@ export function checkNeedUpdateBoot(features: Features) {
24
25
  semver.lte(bootloaderVersion, targetBootloaderVersion.join('.'))
25
26
  );
26
27
  }
28
+
29
+ const INIT_DATA_CHUNK_SIZE = 16 * 1024;
30
+ export function checkBootloaderLength(data: ArrayBuffer) {
31
+ const chunk = new Uint8Array(data.slice(0, Math.min(INIT_DATA_CHUNK_SIZE, data.byteLength)));
32
+ const buffer = ByteBuffer.wrap(chunk, undefined, undefined, true);
33
+ buffer.LE();
34
+ // byte 'O', 'K', 'T', 'B'
35
+ buffer.readByte();
36
+ buffer.readByte();
37
+ buffer.readByte();
38
+ buffer.readByte();
39
+ // g_header_end - g_header
40
+ const hdrlen = buffer.readUint32();
41
+ // word 0
42
+ buffer.readUint32();
43
+ // codelen
44
+ const codelen = buffer.readUint32();
45
+ const bootloaderLength = hdrlen + codelen;
46
+ return bootloaderLength === data.byteLength;
47
+ }
@@ -50,9 +50,6 @@ export const isSegwitPath = (path: Array<number>): boolean =>
50
50
  export const isBech32Path = (path: Array<number>): boolean =>
51
51
  Array.isArray(path) && path[0] === toHardened(84);
52
52
 
53
- export const isTaprootPath = (path: number[] | undefined) =>
54
- Array.isArray(path) && (path[0] === toHardened(86) || path[0] === toHardened(10025));
55
-
56
53
  export const getScriptType = (path: Array<number>): InputScriptType => {
57
54
  if (!Array.isArray(path) || path.length < 1) return 'SPENDADDRESS';
58
55
 
@@ -64,9 +61,6 @@ export const getScriptType = (path: Array<number>): InputScriptType => {
64
61
  return 'SPENDP2SHWITNESS';
65
62
  case 84:
66
63
  return 'SPENDWITNESS';
67
- case 86:
68
- case 10025:
69
- return 'SPENDTAPROOT';
70
64
  default:
71
65
  return 'SPENDADDRESS';
72
66
  }
@@ -88,10 +82,6 @@ export const getOutputScriptType = (path?: number[]): ChangeOutputScriptType =>
88
82
  return 'PAYTOP2SHWITNESS';
89
83
  case 84:
90
84
  return 'PAYTOWITNESS';
91
- // 10025 - SLIP-25 https://github.com/satoshilabs/slips/blob/master/slip-0025.md#public-key-derivation
92
- case 86:
93
- case 10025:
94
- return 'PAYTOTAPROOT';
95
85
  default:
96
86
  return 'PAYTOADDRESS';
97
87
  }
package/src/core/index.ts CHANGED
@@ -133,10 +133,7 @@ export const callAPI = async (message: CoreMessage) => {
133
133
 
134
134
  device.on(DEVICE.PIN, onDevicePinHandler);
135
135
  device.on(DEVICE.BUTTON, onDeviceButtonHandler);
136
- device.on(
137
- DEVICE.PASSPHRASE,
138
- message.payload.useEmptyPassphrase ? onEmptyPassphraseHandler : onDevicePassphraseHandler
139
- );
136
+ device.on(DEVICE.PASSPHRASE, onDevicePassphraseHandler);
140
137
  device.on(DEVICE.PASSPHRASE_ON_DEVICE, onEnterPassphraseOnDeviceHandler);
141
138
  device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
142
139
 
@@ -543,11 +540,7 @@ export const cancel = (connectId?: string) => {
543
540
  const checkPassphraseSafety = (method: BaseMethod, features?: Features) => {
544
541
  if (!method.useDevicePassphraseState) return;
545
542
 
546
- if (
547
- features?.passphrase_protection === true &&
548
- (method.payload.passphraseState == null || method.payload.passphraseState === '') &&
549
- !method.payload.useEmptyPassphrase
550
- ) {
543
+ if (features?.passphrase_protection === true && !method.payload.passphraseState) {
551
544
  DevicePool.clearDeviceCache(method.payload.connectId);
552
545
  throw ERRORS.TypedError(HardwareErrorCode.DeviceOpenedPassphrase);
553
546
  }
@@ -564,7 +557,11 @@ const cleanup = () => {
564
557
  };
565
558
 
566
559
  const removeDeviceListener = (device: Device) => {
567
- device.removeAllListeners();
560
+ device.removeListener(DEVICE.PIN, onDevicePinHandler);
561
+ device.removeListener(DEVICE.BUTTON, onDeviceButtonHandler);
562
+ device.removeListener(DEVICE.PASSPHRASE, onDevicePassphraseHandler);
563
+ device.removeListener(DEVICE.PASSPHRASE_ON_DEVICE, onEnterPassphraseOnDeviceHandler);
564
+ device.removeListener(DEVICE.FEATURES, onDeviceFeaturesHandler);
568
565
  DevicePool.emitter.removeListener(DEVICE.CONNECT, onDeviceConnectHandler);
569
566
  // DevicePool.emitter.removeListener(DEVICE.DISCONNECT, onDeviceDisconnectHandler);
570
567
  };
@@ -644,12 +641,6 @@ const onDevicePassphraseHandler = async (...[device, callback]: DeviceEvents['pa
644
641
  });
645
642
  };
646
643
 
647
- const onEmptyPassphraseHandler = (...[_, callback]: DeviceEvents['passphrase']) => {
648
- Log.debug('onEmptyPassphraseHandler');
649
- // send as PassphrasePromptResponse
650
- callback({ passphrase: '' });
651
- };
652
-
653
644
  const onEnterPassphraseOnDeviceHandler = (
654
645
  ...[device]: [...DeviceEvents['passphrase_on_device']]
655
646
  ) => {
@@ -3,7 +3,6 @@ import type { CommonParams, Response } from '../params';
3
3
 
4
4
  export type BTCPublicKey = {
5
5
  path: string;
6
- xpubSegwit?: string;
7
6
  } & PublicKey;
8
7
 
9
8
  export type BTCGetPublicKeyParams = {
@@ -16,10 +16,6 @@ export interface CommonParams {
16
16
  * passphrase state
17
17
  */
18
18
  passphraseState?: string;
19
- /**
20
- * Use empty passphrase
21
- */
22
- useEmptyPassphrase?: boolean;
23
19
  /**
24
20
  * Every init session
25
21
  */