@onekeyfe/hd-core 0.2.34 → 0.2.36
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.
- package/dist/api/btc/BTCGetPublicKey.d.ts +1 -0
- package/dist/api/btc/BTCGetPublicKey.d.ts.map +1 -1
- package/dist/api/helpers/pathUtils.d.ts +1 -0
- package/dist/api/helpers/pathUtils.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +28 -8
- package/dist/types/api/btcGetPublicKey.d.ts +1 -0
- package/dist/types/api/btcGetPublicKey.d.ts.map +1 -1
- package/dist/types/params.d.ts +1 -0
- package/dist/types/params.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/btc/BTCGetPublicKey.ts +19 -3
- package/src/api/helpers/pathUtils.ts +10 -0
- package/src/core/index.ts +16 -7
- package/src/types/api/btcGetPublicKey.ts +1 -0
- package/src/types/params.ts +4 -0
|
@@ -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;
|
|
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,
|
|
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"}
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -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,
|
|
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
|
@@ -688,6 +688,7 @@ const getHDPath = (path) => {
|
|
|
688
688
|
};
|
|
689
689
|
const isMultisigPath = (path) => Array.isArray(path) && path[0] === toHardened(48);
|
|
690
690
|
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));
|
|
691
692
|
const getScriptType = (path) => {
|
|
692
693
|
if (!Array.isArray(path) || path.length < 1)
|
|
693
694
|
return 'SPENDADDRESS';
|
|
@@ -699,6 +700,9 @@ const getScriptType = (path) => {
|
|
|
699
700
|
return 'SPENDP2SHWITNESS';
|
|
700
701
|
case 84:
|
|
701
702
|
return 'SPENDWITNESS';
|
|
703
|
+
case 86:
|
|
704
|
+
case 10025:
|
|
705
|
+
return 'SPENDTAPROOT';
|
|
702
706
|
default:
|
|
703
707
|
return 'SPENDADDRESS';
|
|
704
708
|
}
|
|
@@ -717,6 +721,9 @@ const getOutputScriptType = (path) => {
|
|
|
717
721
|
return 'PAYTOP2SHWITNESS';
|
|
718
722
|
case 84:
|
|
719
723
|
return 'PAYTOWITNESS';
|
|
724
|
+
case 86:
|
|
725
|
+
case 10025:
|
|
726
|
+
return 'PAYTOTAPROOT';
|
|
720
727
|
default:
|
|
721
728
|
return 'PAYTOADDRESS';
|
|
722
729
|
}
|
|
@@ -14173,13 +14180,24 @@ class BTCGetPublicKey extends BaseMethod {
|
|
|
14173
14180
|
});
|
|
14174
14181
|
});
|
|
14175
14182
|
}
|
|
14183
|
+
isBtcNetwork(param) {
|
|
14184
|
+
return param.coin_name === 'Testnet' || param.coin_name === 'Bitcoin';
|
|
14185
|
+
}
|
|
14176
14186
|
run() {
|
|
14177
14187
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14178
14188
|
const responses = [];
|
|
14179
14189
|
for (let i = 0; i < this.params.length; i++) {
|
|
14180
14190
|
const param = this.params[i];
|
|
14181
14191
|
const res = yield this.device.commands.typedCall('GetPublicKey', 'PublicKey', Object.assign({}, param));
|
|
14182
|
-
|
|
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);
|
|
14183
14201
|
}
|
|
14184
14202
|
return Promise.resolve(this.hasBundle ? responses : responses[0]);
|
|
14185
14203
|
});
|
|
@@ -18426,7 +18444,7 @@ const callAPI = (message) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
18426
18444
|
(_a = method.setDevice) === null || _a === void 0 ? void 0 : _a.call(method, device);
|
|
18427
18445
|
device.on(DEVICE.PIN, onDevicePinHandler);
|
|
18428
18446
|
device.on(DEVICE.BUTTON, onDeviceButtonHandler);
|
|
18429
|
-
device.on(DEVICE.PASSPHRASE, onDevicePassphraseHandler);
|
|
18447
|
+
device.on(DEVICE.PASSPHRASE, message.payload.useEmptyPassphrase ? onEmptyPassphraseHandler : onDevicePassphraseHandler);
|
|
18430
18448
|
device.on(DEVICE.PASSPHRASE_ON_DEVICE, onEnterPassphraseOnDeviceHandler);
|
|
18431
18449
|
device.on(DEVICE.FEATURES, onDeviceFeaturesHandler);
|
|
18432
18450
|
try {
|
|
@@ -18730,7 +18748,9 @@ const cancel = (connectId) => {
|
|
|
18730
18748
|
const checkPassphraseSafety = (method, features) => {
|
|
18731
18749
|
if (!method.useDevicePassphraseState)
|
|
18732
18750
|
return;
|
|
18733
|
-
if ((features === null || features === void 0 ? void 0 : features.passphrase_protection) === true &&
|
|
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) {
|
|
18734
18754
|
DevicePool.clearDeviceCache(method.payload.connectId);
|
|
18735
18755
|
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.DeviceOpenedPassphrase);
|
|
18736
18756
|
}
|
|
@@ -18744,11 +18764,7 @@ const cleanup = () => {
|
|
|
18744
18764
|
Log.debug('Cleanup...');
|
|
18745
18765
|
};
|
|
18746
18766
|
const removeDeviceListener = (device) => {
|
|
18747
|
-
device.
|
|
18748
|
-
device.removeListener(DEVICE.BUTTON, onDeviceButtonHandler);
|
|
18749
|
-
device.removeListener(DEVICE.PASSPHRASE, onDevicePassphraseHandler);
|
|
18750
|
-
device.removeListener(DEVICE.PASSPHRASE_ON_DEVICE, onEnterPassphraseOnDeviceHandler);
|
|
18751
|
-
device.removeListener(DEVICE.FEATURES, onDeviceFeaturesHandler);
|
|
18767
|
+
device.removeAllListeners();
|
|
18752
18768
|
DevicePool.emitter.removeListener(DEVICE.CONNECT, onDeviceConnectHandler);
|
|
18753
18769
|
};
|
|
18754
18770
|
const closePopup = () => {
|
|
@@ -18804,6 +18820,10 @@ const onDevicePassphraseHandler = (...[device, callback]) => __awaiter(void 0, v
|
|
|
18804
18820
|
cache: save,
|
|
18805
18821
|
});
|
|
18806
18822
|
});
|
|
18823
|
+
const onEmptyPassphraseHandler = (...[_, callback]) => {
|
|
18824
|
+
Log.debug('onEmptyPassphraseHandler');
|
|
18825
|
+
callback({ passphrase: '' });
|
|
18826
|
+
};
|
|
18807
18827
|
const onEnterPassphraseOnDeviceHandler = (...[device]) => {
|
|
18808
18828
|
postMessage(createUiMessage(UI_REQUEST$1.REQUEST_PASSPHRASE_ON_DEVICE, {
|
|
18809
18829
|
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;
|
|
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"}
|
package/dist/types/params.d.ts
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "0.2.36",
|
|
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.36",
|
|
28
|
+
"@onekeyfe/hd-transport": "^0.2.36",
|
|
29
29
|
"axios": "^0.27.2",
|
|
30
30
|
"bignumber.js": "^9.0.2",
|
|
31
31
|
"jszip": "^3.10.1",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"@types/semver": "^7.3.9",
|
|
43
43
|
"ripple-keypairs": "^1.1.4"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "53dfab54b8e9f221b4b855e5f36f2b618ebfcdd9"
|
|
46
46
|
}
|
|
@@ -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
|
-
|
|
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(
|
|
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 (
|
|
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.
|
|
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
|
) => {
|