@onekeyfe/hd-core 0.2.37 → 0.2.38

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,6 +4,7 @@ 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;
7
8
  run(): Promise<BTCPublicKey | BTCPublicKey[]>;
8
9
  }
9
10
  //# 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;IA4CE,GAAG;CAkBV"}
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"}
@@ -5,6 +5,7 @@ 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;
8
9
  export declare const getScriptType: (path: Array<number>) => InputScriptType;
9
10
  export declare const getOutputScriptType: (path?: number[] | undefined) => ChangeOutputScriptType;
10
11
  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,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
+ {"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,MAA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AAM,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,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"}
package/dist/index.d.ts CHANGED
@@ -10,6 +10,7 @@ interface CommonParams {
10
10
  pollIntervalTime?: number;
11
11
  timeout?: number;
12
12
  passphraseState?: string;
13
+ useEmptyPassphrase?: boolean;
13
14
  initSession?: boolean;
14
15
  }
15
16
  declare type Params<T> = CommonParams & T & {
@@ -541,6 +542,7 @@ declare function btcGetAddress(connectId: string, deviceId: string, params: Comm
541
542
 
542
543
  declare type BTCPublicKey = {
543
544
  path: string;
545
+ xpubSegwit?: string;
544
546
  } & PublicKey;
545
547
  declare type BTCGetPublicKeyParams = {
546
548
  path: string | number[];
package/dist/index.js CHANGED
@@ -690,6 +690,7 @@ const getHDPath = (path) => {
690
690
  };
691
691
  const isMultisigPath = (path) => Array.isArray(path) && path[0] === toHardened(48);
692
692
  const isSegwitPath = (path) => Array.isArray(path) && path[0] === toHardened(49);
693
+ const isTaprootPath = (path) => Array.isArray(path) && (path[0] === toHardened(86) || path[0] === toHardened(10025));
693
694
  const getScriptType = (path) => {
694
695
  if (!Array.isArray(path) || path.length < 1)
695
696
  return 'SPENDADDRESS';
@@ -701,6 +702,9 @@ const getScriptType = (path) => {
701
702
  return 'SPENDP2SHWITNESS';
702
703
  case 84:
703
704
  return 'SPENDWITNESS';
705
+ case 86:
706
+ case 10025:
707
+ return 'SPENDTAPROOT';
704
708
  default:
705
709
  return 'SPENDADDRESS';
706
710
  }
@@ -719,6 +723,9 @@ const getOutputScriptType = (path) => {
719
723
  return 'PAYTOP2SHWITNESS';
720
724
  case 84:
721
725
  return 'PAYTOWITNESS';
726
+ case 86:
727
+ case 10025:
728
+ return 'PAYTOTAPROOT';
722
729
  default:
723
730
  return 'PAYTOADDRESS';
724
731
  }
@@ -14193,13 +14200,24 @@ class BTCGetPublicKey extends BaseMethod {
14193
14200
  });
14194
14201
  });
14195
14202
  }
14203
+ isBtcNetwork(param) {
14204
+ return param.coin_name === 'Testnet' || param.coin_name === 'Bitcoin';
14205
+ }
14196
14206
  run() {
14197
14207
  return __awaiter(this, void 0, void 0, function* () {
14198
14208
  const responses = [];
14199
14209
  for (let i = 0; i < this.params.length; i++) {
14200
14210
  const param = this.params[i];
14201
14211
  const res = yield this.device.commands.typedCall('GetPublicKey', 'PublicKey', Object.assign({}, param));
14202
- responses.push(Object.assign({ path: serializedPath(param.address_n) }, res.message));
14212
+ const response = Object.assign(Object.assign({ path: serializedPath(param.address_n) }, res.message), { xpubSegwit: res.message.xpub });
14213
+ if (this.isBtcNetwork(param) && isTaprootPath(param.address_n)) {
14214
+ const fingerprint = Number(response.root_fingerprint || 0)
14215
+ .toString(16)
14216
+ .padStart(8, '0');
14217
+ const descriptorPath = `${fingerprint}${response.path.substring(1)}`;
14218
+ response.xpubSegwit = `tr([${descriptorPath}]${response.xpub}/<0;1>/*)`;
14219
+ }
14220
+ responses.push(response);
14203
14221
  }
14204
14222
  return Promise.resolve(this.hasBundle ? responses : responses[0]);
14205
14223
  });
@@ -18446,7 +18464,7 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
18446
18464
  (_a = method.setDevice) === null || _a === void 0 ? void 0 : _a.call(method, device);
18447
18465
  device.on(DEVICE.PIN, onDevicePinHandler);
18448
18466
  device.on(DEVICE.BUTTON, onDeviceButtonHandler);
18449
- device.on(DEVICE.PASSPHRASE, onDevicePassphraseHandler);
18467
+ device.on(DEVICE.PASSPHRASE, message.payload.useEmptyPassphrase ? onEmptyPassphraseHandler : onDevicePassphraseHandler);
18450
18468
  device.on(DEVICE.PASSPHRASE_ON_DEVICE, onEnterPassphraseOnDeviceHandler);
18451
18469
  device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
18452
18470
  try {
@@ -18750,7 +18768,9 @@ const cancel = (connectId) => {
18750
18768
  const checkPassphraseSafety = (method, features) => {
18751
18769
  if (!method.useDevicePassphraseState)
18752
18770
  return;
18753
- if ((features === null || features === void 0 ? void 0 : features.passphrase_protection) === true && !method.payload.passphraseState) {
18771
+ if ((features === null || features === void 0 ? void 0 : features.passphrase_protection) === true &&
18772
+ (method.payload.passphraseState == null || method.payload.passphraseState === '') &&
18773
+ !method.payload.useEmptyPassphrase) {
18754
18774
  DevicePool.clearDeviceCache(method.payload.connectId);
18755
18775
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceOpenedPassphrase);
18756
18776
  }
@@ -18764,11 +18784,7 @@ const cleanup = () => {
18764
18784
  Log.debug('Cleanup...');
18765
18785
  };
18766
18786
  const removeDeviceListener = (device) => {
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);
18787
+ device.removeAllListeners();
18772
18788
  DevicePool.emitter.removeListener(DEVICE.CONNECT, onDeviceConnectHandler);
18773
18789
  };
18774
18790
  const closePopup = () => {
@@ -18824,6 +18840,10 @@ const onDevicePassphraseHandler = (...[device, callback]) => __awaiter(void 0, v
18824
18840
  cache: save,
18825
18841
  });
18826
18842
  });
18843
+ const onEmptyPassphraseHandler = (...[_, callback]) => {
18844
+ Log.debug('onEmptyPassphraseHandler');
18845
+ callback({ passphrase: '' });
18846
+ };
18827
18847
  const onEnterPassphraseOnDeviceHandler = (...[device]) => {
18828
18848
  postMessage(createUiMessage(UI_REQUEST$1.REQUEST_PASSPHRASE_ON_DEVICE, {
18829
18849
  device: device.toMessageObject(),
@@ -2,6 +2,7 @@ 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;
5
6
  } & PublicKey;
6
7
  export declare type BTCGetPublicKeyParams = {
7
8
  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;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,MA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@ export interface CommonParams {
4
4
  pollIntervalTime?: number;
5
5
  timeout?: number;
6
6
  passphraseState?: string;
7
+ useEmptyPassphrase?: boolean;
7
8
  initSession?: boolean;
8
9
  }
9
10
  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,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,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "0.2.37",
3
+ "version": "0.2.38",
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.37",
28
- "@onekeyfe/hd-transport": "^0.2.37",
27
+ "@onekeyfe/hd-shared": "^0.2.38",
28
+ "@onekeyfe/hd-transport": "^0.2.38",
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": "5d80d2bdb1f7e5863286c3e59064c858b245b3ca"
46
+ "gitHead": "5c0a8dd681f9b2ae38b0555a86020b0a28ac3910"
47
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, serializedPath, validatePath } from '../helpers/pathUtils';
3
+ import { getScriptType, isTaprootPath, 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,6 +54,10 @@ 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
+
57
61
  async run() {
58
62
  const responses: BTCPublicKey[] = [];
59
63
 
@@ -64,10 +68,22 @@ export default class BTCGetPublicKey extends BaseMethod<GetPublicKey[]> {
64
68
  ...param,
65
69
  });
66
70
 
67
- responses.push({
71
+ const response = {
68
72
  path: serializedPath(param.address_n),
69
73
  ...res.message,
70
- });
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);
71
87
  }
72
88
 
73
89
  return Promise.resolve(this.hasBundle ? responses : responses[0]);
@@ -50,6 +50,9 @@ 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
+
53
56
  export const getScriptType = (path: Array<number>): InputScriptType => {
54
57
  if (!Array.isArray(path) || path.length < 1) return 'SPENDADDRESS';
55
58
 
@@ -61,6 +64,9 @@ export const getScriptType = (path: Array<number>): InputScriptType => {
61
64
  return 'SPENDP2SHWITNESS';
62
65
  case 84:
63
66
  return 'SPENDWITNESS';
67
+ case 86:
68
+ case 10025:
69
+ return 'SPENDTAPROOT';
64
70
  default:
65
71
  return 'SPENDADDRESS';
66
72
  }
@@ -82,6 +88,10 @@ export const getOutputScriptType = (path?: number[]): ChangeOutputScriptType =>
82
88
  return 'PAYTOP2SHWITNESS';
83
89
  case 84:
84
90
  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';
85
95
  default:
86
96
  return 'PAYTOADDRESS';
87
97
  }
package/src/core/index.ts CHANGED
@@ -133,7 +133,10 @@ 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(DEVICE.PASSPHRASE, onDevicePassphraseHandler);
136
+ device.on(
137
+ DEVICE.PASSPHRASE,
138
+ message.payload.useEmptyPassphrase ? onEmptyPassphraseHandler : onDevicePassphraseHandler
139
+ );
137
140
  device.on(DEVICE.PASSPHRASE_ON_DEVICE, onEnterPassphraseOnDeviceHandler);
138
141
  device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
139
142
 
@@ -540,7 +543,11 @@ export const cancel = (connectId?: string) => {
540
543
  const checkPassphraseSafety = (method: BaseMethod, features?: Features) => {
541
544
  if (!method.useDevicePassphraseState) return;
542
545
 
543
- if (features?.passphrase_protection === true && !method.payload.passphraseState) {
546
+ if (
547
+ features?.passphrase_protection === true &&
548
+ (method.payload.passphraseState == null || method.payload.passphraseState === '') &&
549
+ !method.payload.useEmptyPassphrase
550
+ ) {
544
551
  DevicePool.clearDeviceCache(method.payload.connectId);
545
552
  throw ERRORS.TypedError(HardwareErrorCode.DeviceOpenedPassphrase);
546
553
  }
@@ -557,11 +564,7 @@ const cleanup = () => {
557
564
  };
558
565
 
559
566
  const removeDeviceListener = (device: Device) => {
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);
567
+ device.removeAllListeners();
565
568
  DevicePool.emitter.removeListener(DEVICE.CONNECT, onDeviceConnectHandler);
566
569
  // DevicePool.emitter.removeListener(DEVICE.DISCONNECT, onDeviceDisconnectHandler);
567
570
  };
@@ -641,6 +644,12 @@ const onDevicePassphraseHandler = async (...[device, callback]: DeviceEvents['pa
641
644
  });
642
645
  };
643
646
 
647
+ const onEmptyPassphraseHandler = (...[_, callback]: DeviceEvents['passphrase']) => {
648
+ Log.debug('onEmptyPassphraseHandler');
649
+ // send as PassphrasePromptResponse
650
+ callback({ passphrase: '' });
651
+ };
652
+
644
653
  const onEnterPassphraseOnDeviceHandler = (
645
654
  ...[device]: [...DeviceEvents['passphrase_on_device']]
646
655
  ) => {
@@ -3,6 +3,7 @@ import type { CommonParams, Response } from '../params';
3
3
 
4
4
  export type BTCPublicKey = {
5
5
  path: string;
6
+ xpubSegwit?: string;
6
7
  } & PublicKey;
7
8
 
8
9
  export type BTCGetPublicKeyParams = {
@@ -16,6 +16,10 @@ export interface CommonParams {
16
16
  * passphrase state
17
17
  */
18
18
  passphraseState?: string;
19
+ /**
20
+ * Use empty passphrase
21
+ */
22
+ useEmptyPassphrase?: boolean;
19
23
  /**
20
24
  * Every init session
21
25
  */