@onekeyfe/hd-core 0.2.35 → 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/index.d.ts +1 -0
- package/dist/index.js +19 -1
- package/dist/types/api/btcGetPublicKey.d.ts +1 -0
- package/dist/types/api/btcGetPublicKey.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/types/api/btcGetPublicKey.ts +1 -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/index.d.ts
CHANGED
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
|
});
|
|
@@ -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/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
|
}
|