@onekeyfe/hd-core 1.0.34 → 1.0.36-alpha.0
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.map +1 -1
- package/dist/api/btc/helpers/xpubUtils.d.ts +1 -0
- package/dist/api/btc/helpers/xpubUtils.d.ts.map +1 -1
- package/dist/index.js +28 -12
- package/package.json +4 -4
- package/src/api/btc/BTCGetPublicKey.ts +10 -1
- package/src/api/btc/helpers/xpubUtils.ts +37 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BTCGetPublicKey.d.ts","sourceRoot":"","sources":["../../../src/api/btc/BTCGetPublicKey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAG3D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAI3C,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAK/D,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,UAAU,CAAC,YAAY,EAAE,CAAC;IACrE,SAAS,UAAS;IAElB,IAAI;IA4CJ,OAAO,CAAC,YAAY;IAIpB,eAAe;;;;;;;;;;;IAIT,GAAG;
|
|
1
|
+
{"version":3,"file":"BTCGetPublicKey.d.ts","sourceRoot":"","sources":["../../../src/api/btc/BTCGetPublicKey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAG3D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAI3C,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAK/D,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,UAAU,CAAC,YAAY,EAAE,CAAC;IACrE,SAAS,UAAS;IAElB,IAAI;IA4CJ,OAAO,CAAC,YAAY;IAIpB,eAAe;;;;;;;;;;;IAIT,GAAG;CA2FV"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { HDNodeType, InputScriptType } from '@onekeyfe/hd-transport';
|
|
2
|
+
export declare function getVersionBytes(coinName: string, scriptType?: InputScriptType): number | undefined;
|
|
2
3
|
export declare function createExtendedPublicKey(node: HDNodeType, coinName: string, scriptType?: InputScriptType): string;
|
|
3
4
|
//# sourceMappingURL=xpubUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xpubUtils.d.ts","sourceRoot":"","sources":["../../../../src/api/btc/helpers/xpubUtils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"xpubUtils.d.ts","sourceRoot":"","sources":["../../../../src/api/btc/helpers/xpubUtils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAY1E,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,eAAe,GAC3B,MAAM,GAAG,SAAS,CA6CpB;AAuDD,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,MAAM,EAChB,UAAU,CAAC,EAAE,eAAe,GAC3B,MAAM,CAUR"}
|
package/dist/index.js
CHANGED
|
@@ -30403,22 +30403,29 @@ function getVersionBytes(coinName, scriptType) {
|
|
|
30403
30403
|
return VERSION_BYTES.XPUB;
|
|
30404
30404
|
}
|
|
30405
30405
|
}
|
|
30406
|
-
else if (coinName.toLowerCase() === 'testnet') {
|
|
30407
|
-
return 0x043587cf;
|
|
30408
|
-
}
|
|
30409
|
-
else if (coinName.toLowerCase() === 'regtest') {
|
|
30410
|
-
return 0x043587cf;
|
|
30411
|
-
}
|
|
30412
30406
|
else if (coinName.toLowerCase() === 'litecoin') {
|
|
30413
|
-
|
|
30407
|
+
switch (scriptType) {
|
|
30408
|
+
case 'SPENDADDRESS':
|
|
30409
|
+
case 'SPENDMULTISIG':
|
|
30410
|
+
return 0x019da462;
|
|
30411
|
+
case 'SPENDP2SHWITNESS':
|
|
30412
|
+
return 0x01b26ef6;
|
|
30413
|
+
case 'SPENDWITNESS':
|
|
30414
|
+
return 0x04b24746;
|
|
30415
|
+
default:
|
|
30416
|
+
return undefined;
|
|
30417
|
+
}
|
|
30414
30418
|
}
|
|
30415
30419
|
else if (coinName.toLowerCase() === 'dogecoin') {
|
|
30416
|
-
|
|
30417
|
-
|
|
30418
|
-
|
|
30419
|
-
|
|
30420
|
+
if (scriptType === 'SPENDADDRESS') {
|
|
30421
|
+
return 0x02facafd;
|
|
30422
|
+
}
|
|
30423
|
+
if (scriptType === 'SPENDMULTISIG') {
|
|
30424
|
+
return 0x0488b21e;
|
|
30425
|
+
}
|
|
30426
|
+
return undefined;
|
|
30420
30427
|
}
|
|
30421
|
-
return
|
|
30428
|
+
return undefined;
|
|
30422
30429
|
}
|
|
30423
30430
|
function base58Check(data) {
|
|
30424
30431
|
const checksum = sha256.sha256(sha256.sha256(new Uint8Array(data))).slice(0, 4);
|
|
@@ -30444,6 +30451,9 @@ function base58Check(data) {
|
|
|
30444
30451
|
}
|
|
30445
30452
|
function generateExtendedPublicKey(coinName, depth, fingerprint, childNum, chainCode, publicKey, scriptType) {
|
|
30446
30453
|
const versionBytes = getVersionBytes(coinName, scriptType);
|
|
30454
|
+
if (!versionBytes) {
|
|
30455
|
+
throw new Error(`Invalid coinName, not support generate xpub for scriptType: ${scriptType}`);
|
|
30456
|
+
}
|
|
30447
30457
|
const buffer = Buffer.alloc(78);
|
|
30448
30458
|
buffer.writeUInt32BE(versionBytes, 0);
|
|
30449
30459
|
buffer.writeUInt8(depth, 4);
|
|
@@ -30510,6 +30520,12 @@ class BTCGetPublicKey extends BaseMethod {
|
|
|
30510
30520
|
if (existsShowDisplay || !this.hasBundle) {
|
|
30511
30521
|
throw new Error('Goto getPublickey');
|
|
30512
30522
|
}
|
|
30523
|
+
for (const param of this.params) {
|
|
30524
|
+
const versionBytes = getVersionBytes(param.coin_name, param.script_type);
|
|
30525
|
+
if (!versionBytes) {
|
|
30526
|
+
throw new Error(`Invalid coinName, not support generate xpub for scriptType: ${param.script_type}`);
|
|
30527
|
+
}
|
|
30528
|
+
}
|
|
30513
30529
|
const res = yield batchGetPublickeys(this.device, this.params, 'secp256k1', 0, {
|
|
30514
30530
|
includeNode: true,
|
|
30515
30531
|
ignoreCoinType: true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.36-alpha.0",
|
|
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.
|
|
29
|
-
"@onekeyfe/hd-transport": "^1.0.
|
|
28
|
+
"@onekeyfe/hd-shared": "^1.0.36-alpha.0",
|
|
29
|
+
"@onekeyfe/hd-transport": "^1.0.36-alpha.0",
|
|
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": "
|
|
49
|
+
"gitHead": "e22164ae7bccb8f7632a758401561b78ce5a3778"
|
|
50
50
|
}
|
|
@@ -8,7 +8,7 @@ import { getCoinInfo } from './helpers/btcParamsUtils';
|
|
|
8
8
|
import { BTCPublicKey } from '../../types/api/btcGetPublicKey';
|
|
9
9
|
import { getBitcoinForkVersionRange } from './helpers/versionLimit';
|
|
10
10
|
import { batchGetPublickeys } from '../helpers/batchGetPublickeys';
|
|
11
|
-
import { createExtendedPublicKey } from './helpers/xpubUtils';
|
|
11
|
+
import { createExtendedPublicKey, getVersionBytes } from './helpers/xpubUtils';
|
|
12
12
|
|
|
13
13
|
export default class BTCGetPublicKey extends BaseMethod<GetPublicKey[]> {
|
|
14
14
|
hasBundle = false;
|
|
@@ -74,6 +74,15 @@ export default class BTCGetPublicKey extends BaseMethod<GetPublicKey[]> {
|
|
|
74
74
|
throw new Error('Goto getPublickey');
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
for (const param of this.params) {
|
|
78
|
+
const versionBytes = getVersionBytes(param.coin_name, param.script_type);
|
|
79
|
+
if (!versionBytes) {
|
|
80
|
+
throw new Error(
|
|
81
|
+
`Invalid coinName, not support generate xpub for scriptType: ${param.script_type}`
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
77
86
|
const res = await batchGetPublickeys(this.device, this.params, 'secp256k1', 0, {
|
|
78
87
|
includeNode: true,
|
|
79
88
|
ignoreCoinType: true,
|
|
@@ -11,31 +11,54 @@ const VERSION_BYTES = {
|
|
|
11
11
|
ZPUB: 0x04b24746,
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
function getVersionBytes(
|
|
14
|
+
export function getVersionBytes(
|
|
15
|
+
coinName: string,
|
|
16
|
+
scriptType?: InputScriptType
|
|
17
|
+
): number | undefined {
|
|
15
18
|
if (coinName.toLowerCase() === 'bitcoin') {
|
|
16
19
|
switch (scriptType) {
|
|
17
20
|
case 'SPENDADDRESS':
|
|
18
21
|
case 'SPENDMULTISIG':
|
|
22
|
+
// 44、48
|
|
19
23
|
return VERSION_BYTES.XPUB;
|
|
20
24
|
case 'SPENDP2SHWITNESS':
|
|
25
|
+
// 49
|
|
21
26
|
return VERSION_BYTES.YPUB;
|
|
22
27
|
case 'SPENDWITNESS':
|
|
28
|
+
// 84
|
|
23
29
|
return VERSION_BYTES.ZPUB;
|
|
24
30
|
default:
|
|
31
|
+
// 86、10025
|
|
25
32
|
return VERSION_BYTES.XPUB;
|
|
26
33
|
}
|
|
27
|
-
} else if (coinName.toLowerCase() === 'testnet') {
|
|
28
|
-
return 0x043587cf;
|
|
29
|
-
} else if (coinName.toLowerCase() === 'regtest') {
|
|
30
|
-
return 0x043587cf;
|
|
31
34
|
} else if (coinName.toLowerCase() === 'litecoin') {
|
|
32
|
-
|
|
35
|
+
switch (scriptType) {
|
|
36
|
+
case 'SPENDADDRESS':
|
|
37
|
+
case 'SPENDMULTISIG':
|
|
38
|
+
// 44、48
|
|
39
|
+
return 0x019da462;
|
|
40
|
+
case 'SPENDP2SHWITNESS':
|
|
41
|
+
// 49
|
|
42
|
+
return 0x01b26ef6;
|
|
43
|
+
case 'SPENDWITNESS':
|
|
44
|
+
// 84
|
|
45
|
+
return 0x04b24746;
|
|
46
|
+
default:
|
|
47
|
+
// not support 86、10025 path
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
33
50
|
} else if (coinName.toLowerCase() === 'dogecoin') {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
51
|
+
if (scriptType === 'SPENDADDRESS') {
|
|
52
|
+
// 44
|
|
53
|
+
return 0x02facafd;
|
|
54
|
+
}
|
|
55
|
+
if (scriptType === 'SPENDMULTISIG') {
|
|
56
|
+
// 48
|
|
57
|
+
return 0x0488b21e;
|
|
58
|
+
}
|
|
59
|
+
return undefined;
|
|
37
60
|
}
|
|
38
|
-
return
|
|
61
|
+
return undefined;
|
|
39
62
|
}
|
|
40
63
|
|
|
41
64
|
function base58Check(data: Buffer): string {
|
|
@@ -76,6 +99,10 @@ function generateExtendedPublicKey(
|
|
|
76
99
|
): string {
|
|
77
100
|
const versionBytes = getVersionBytes(coinName, scriptType);
|
|
78
101
|
|
|
102
|
+
if (!versionBytes) {
|
|
103
|
+
throw new Error(`Invalid coinName, not support generate xpub for scriptType: ${scriptType}`);
|
|
104
|
+
}
|
|
105
|
+
|
|
79
106
|
const buffer = Buffer.alloc(78);
|
|
80
107
|
buffer.writeUInt32BE(versionBytes, 0);
|
|
81
108
|
buffer.writeUInt8(depth, 4);
|