@vbyte/btc-dev 1.1.4 → 1.1.6
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/lib/address/api.d.ts +1 -1
- package/dist/lib/address/api.js +8 -8
- package/dist/lib/script/index.d.ts +1 -115
- package/dist/lib/script/index.js +1 -5
- package/dist/main.cjs +41 -12
- package/dist/main.cjs.map +1 -1
- package/dist/module.mjs +41 -12
- package/dist/module.mjs.map +1 -1
- package/dist/package.json +1 -1
- package/dist/script.js +8 -8
- package/dist/script.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/address/api.ts +13 -13
- package/src/lib/script/index.ts +5 -13
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Bytes } from '@vbyte/buff';
|
|
2
2
|
import type { AddressInfo, ChainNetwork } from '../../types/index.js';
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function get_address(script: Bytes, network?: ChainNetwork): string;
|
|
4
4
|
export declare function parse_address(address: string): AddressInfo;
|
package/dist/lib/address/api.js
CHANGED
|
@@ -7,24 +7,24 @@ import { P2SH } from './p2sh.js';
|
|
|
7
7
|
import { P2TR } from './p2tr.js';
|
|
8
8
|
import { P2WPKH } from './p2wpkh.js';
|
|
9
9
|
import { P2WSH } from './p2wsh.js';
|
|
10
|
-
export function
|
|
10
|
+
export function get_address(script, network = 'main') {
|
|
11
11
|
const bytes = Buff.bytes(script);
|
|
12
12
|
const type = get_lock_script_type(bytes);
|
|
13
13
|
if (type === null)
|
|
14
|
-
throw new Error('
|
|
14
|
+
throw new Error('unknown locking script: ' + bytes.hex);
|
|
15
15
|
switch (type) {
|
|
16
16
|
case LOCK_SCRIPT_TYPE.P2PKH:
|
|
17
|
-
return P2PKH.
|
|
17
|
+
return P2PKH.encode_address(script, network);
|
|
18
18
|
case LOCK_SCRIPT_TYPE.P2SH:
|
|
19
|
-
return P2SH.
|
|
19
|
+
return P2SH.encode_address(script, network);
|
|
20
20
|
case LOCK_SCRIPT_TYPE.P2WPKH:
|
|
21
|
-
return P2WPKH.
|
|
21
|
+
return P2WPKH.encode_address(script, network);
|
|
22
22
|
case LOCK_SCRIPT_TYPE.P2WSH:
|
|
23
|
-
return P2WSH.
|
|
23
|
+
return P2WSH.encode_address(script, network);
|
|
24
24
|
case LOCK_SCRIPT_TYPE.P2TR:
|
|
25
|
-
return P2TR.
|
|
25
|
+
return P2TR.encode_address(script, network);
|
|
26
26
|
default:
|
|
27
|
-
throw new Error('
|
|
27
|
+
throw new Error('unknown script type: ' + type);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
export function parse_address(address) {
|
|
@@ -1,127 +1,13 @@
|
|
|
1
1
|
import { encode_script } from './encode.js';
|
|
2
2
|
import { decode_script, is_valid_script, parse_script } from './decode.js';
|
|
3
|
-
import { parse_script_pubkeys, prefix_script_size } from './util.js';
|
|
4
3
|
export * from './decode.js';
|
|
5
4
|
export * from './encode.js';
|
|
5
|
+
export * from './lock.js';
|
|
6
6
|
export * from './util.js';
|
|
7
7
|
export * from './words.js';
|
|
8
8
|
export declare namespace ScriptUtil {
|
|
9
|
-
const prefix_size: typeof prefix_script_size;
|
|
10
9
|
const parse: typeof parse_script;
|
|
11
10
|
const decode: typeof decode_script;
|
|
12
11
|
const encode: typeof encode_script;
|
|
13
12
|
const is_valid: typeof is_valid_script;
|
|
14
|
-
const get_pubkeys: typeof parse_script_pubkeys;
|
|
15
|
-
const OPCODES: {
|
|
16
|
-
OP_0: number;
|
|
17
|
-
OP_PUSHDATA1: number;
|
|
18
|
-
OP_PUSHDATA2: number;
|
|
19
|
-
OP_PUSHDATA4: number;
|
|
20
|
-
OP_1NEGATE: number;
|
|
21
|
-
OP_SUCCESS80: number;
|
|
22
|
-
OP_1: number;
|
|
23
|
-
OP_2: number;
|
|
24
|
-
OP_3: number;
|
|
25
|
-
OP_4: number;
|
|
26
|
-
OP_5: number;
|
|
27
|
-
OP_6: number;
|
|
28
|
-
OP_7: number;
|
|
29
|
-
OP_8: number;
|
|
30
|
-
OP_9: number;
|
|
31
|
-
OP_10: number;
|
|
32
|
-
OP_11: number;
|
|
33
|
-
OP_12: number;
|
|
34
|
-
OP_13: number;
|
|
35
|
-
OP_14: number;
|
|
36
|
-
OP_15: number;
|
|
37
|
-
OP_16: number;
|
|
38
|
-
OP_NOP: number;
|
|
39
|
-
OP_SUCCESS98: number;
|
|
40
|
-
OP_IF: number;
|
|
41
|
-
OP_NOTIF: number;
|
|
42
|
-
OP_ELSE: number;
|
|
43
|
-
OP_ENDIF: number;
|
|
44
|
-
OP_VERIFY: number;
|
|
45
|
-
OP_RETURN: number;
|
|
46
|
-
OP_TOALTSTACK: number;
|
|
47
|
-
OP_FROMALTSTACK: number;
|
|
48
|
-
OP_2DROP: number;
|
|
49
|
-
OP_2DUP: number;
|
|
50
|
-
OP_3DUP: number;
|
|
51
|
-
OP_2OVER: number;
|
|
52
|
-
OP_2ROT: number;
|
|
53
|
-
OP_2SWAP: number;
|
|
54
|
-
OP_IFDUP: number;
|
|
55
|
-
OP_DEPTH: number;
|
|
56
|
-
OP_DROP: number;
|
|
57
|
-
OP_DUP: number;
|
|
58
|
-
OP_NIP: number;
|
|
59
|
-
OP_OVER: number;
|
|
60
|
-
OP_PICK: number;
|
|
61
|
-
OP_ROLL: number;
|
|
62
|
-
OP_ROT: number;
|
|
63
|
-
OP_SWAP: number;
|
|
64
|
-
OP_TUCK: number;
|
|
65
|
-
OP_SUCCESS126: number;
|
|
66
|
-
OP_SUCCESS127: number;
|
|
67
|
-
OP_SUCCESS128: number;
|
|
68
|
-
OP_SUCCESS129: number;
|
|
69
|
-
OP_SIZE: number;
|
|
70
|
-
OP_SUCCESS131: number;
|
|
71
|
-
OP_SUCCESS132: number;
|
|
72
|
-
OP_SUCCESS133: number;
|
|
73
|
-
OP_SUCCESS134: number;
|
|
74
|
-
OP_EQUAL: number;
|
|
75
|
-
OP_EQUALVERIFY: number;
|
|
76
|
-
OP_SUCCESS137: number;
|
|
77
|
-
OP_SUCCESS138: number;
|
|
78
|
-
OP_1ADD: number;
|
|
79
|
-
OP_1SUB: number;
|
|
80
|
-
OP_SUCCESS141: number;
|
|
81
|
-
OP_SUCCESS142: number;
|
|
82
|
-
OP_NEGATE: number;
|
|
83
|
-
OP_ABS: number;
|
|
84
|
-
OP_NOT: number;
|
|
85
|
-
OP_0NOTEQUAL: number;
|
|
86
|
-
OP_ADD: number;
|
|
87
|
-
OP_SUB: number;
|
|
88
|
-
OP_SUCCESS149: number;
|
|
89
|
-
OP_SUCCESS150: number;
|
|
90
|
-
OP_SUCCESS151: number;
|
|
91
|
-
OP_SUCCESS152: number;
|
|
92
|
-
OP_SUCCESS153: number;
|
|
93
|
-
OP_BOOLAND: number;
|
|
94
|
-
OP_BOOLOR: number;
|
|
95
|
-
OP_NUMEQUAL: number;
|
|
96
|
-
OP_NUMEQUALVERIFY: number;
|
|
97
|
-
OP_NUMNOTEQUAL: number;
|
|
98
|
-
OP_LESSTHAN: number;
|
|
99
|
-
OP_GREATERTHAN: number;
|
|
100
|
-
OP_LESSTHANOREQUAL: number;
|
|
101
|
-
OP_GREATERTHANOREQUAL: number;
|
|
102
|
-
OP_MIN: number;
|
|
103
|
-
OP_MAX: number;
|
|
104
|
-
OP_WITHIN: number;
|
|
105
|
-
OP_RIPEMD160: number;
|
|
106
|
-
OP_SHA1: number;
|
|
107
|
-
OP_SHA256: number;
|
|
108
|
-
OP_HASH160: number;
|
|
109
|
-
OP_HASH256: number;
|
|
110
|
-
OP_CODESEPARATOR: number;
|
|
111
|
-
OP_CHECKSIG: number;
|
|
112
|
-
OP_CHECKSIGVERIFY: number;
|
|
113
|
-
OP_CHECKMULTISIG: number;
|
|
114
|
-
OP_CHECKMULTISIGVERIFY: number;
|
|
115
|
-
OP_NOP1: number;
|
|
116
|
-
OP_CHECKLOCKTIMEVERIFY: number;
|
|
117
|
-
OP_CHECKSEQUENCEVERIFY: number;
|
|
118
|
-
OP_NOP4: number;
|
|
119
|
-
OP_NOP5: number;
|
|
120
|
-
OP_NOP6: number;
|
|
121
|
-
OP_NOP7: number;
|
|
122
|
-
OP_NOP8: number;
|
|
123
|
-
OP_NOP9: number;
|
|
124
|
-
OP_NOP10: number;
|
|
125
|
-
OP_CHECKSIGADD: number;
|
|
126
|
-
};
|
|
127
13
|
}
|
package/dist/lib/script/index.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import { OPCODE_MAP } from './words.js';
|
|
2
1
|
import { encode_script } from './encode.js';
|
|
3
2
|
import { decode_script, is_valid_script, parse_script } from './decode.js';
|
|
4
|
-
import { parse_script_pubkeys, prefix_script_size } from './util.js';
|
|
5
3
|
export * from './decode.js';
|
|
6
4
|
export * from './encode.js';
|
|
5
|
+
export * from './lock.js';
|
|
7
6
|
export * from './util.js';
|
|
8
7
|
export * from './words.js';
|
|
9
8
|
export var ScriptUtil;
|
|
10
9
|
(function (ScriptUtil) {
|
|
11
|
-
ScriptUtil.prefix_size = prefix_script_size;
|
|
12
10
|
ScriptUtil.parse = parse_script;
|
|
13
11
|
ScriptUtil.decode = decode_script;
|
|
14
12
|
ScriptUtil.encode = encode_script;
|
|
15
13
|
ScriptUtil.is_valid = is_valid_script;
|
|
16
|
-
ScriptUtil.get_pubkeys = parse_script_pubkeys;
|
|
17
|
-
ScriptUtil.OPCODES = OPCODE_MAP;
|
|
18
14
|
})(ScriptUtil || (ScriptUtil = {}));
|
package/dist/main.cjs
CHANGED
|
@@ -8313,6 +8313,16 @@ var _const = /*#__PURE__*/Object.freeze({
|
|
|
8313
8313
|
TX_SIZE: TX_SIZE
|
|
8314
8314
|
});
|
|
8315
8315
|
|
|
8316
|
+
function is_return_script(script) {
|
|
8317
|
+
const bytes = Buff.bytes(script);
|
|
8318
|
+
return bytes.at(0) === 0x6a;
|
|
8319
|
+
}
|
|
8320
|
+
function get_lock_script_info(script) {
|
|
8321
|
+
return {
|
|
8322
|
+
type: get_lock_script_type(script),
|
|
8323
|
+
version: get_lock_script_version(script)
|
|
8324
|
+
};
|
|
8325
|
+
}
|
|
8316
8326
|
function get_lock_script_type(script) {
|
|
8317
8327
|
const hex = Buff.bytes(script).hex;
|
|
8318
8328
|
for (const [type, regex] of Object.entries(LOCK_SCRIPT_REGEX)) {
|
|
@@ -8321,6 +8331,14 @@ function get_lock_script_type(script) {
|
|
|
8321
8331
|
}
|
|
8322
8332
|
return null;
|
|
8323
8333
|
}
|
|
8334
|
+
function get_lock_script_version(script) {
|
|
8335
|
+
const version = Buff.bytes(script);
|
|
8336
|
+
switch (version.at(0)) {
|
|
8337
|
+
case 0x00: return 0;
|
|
8338
|
+
case 0x51: return 1;
|
|
8339
|
+
default: return null;
|
|
8340
|
+
}
|
|
8341
|
+
}
|
|
8324
8342
|
function is_p2pkh_script(script) {
|
|
8325
8343
|
const hex = Buff.bytes(script).hex;
|
|
8326
8344
|
return LOCK_SCRIPT_REGEX['p2pkh'].test(hex);
|
|
@@ -8341,6 +8359,10 @@ function is_p2tr_script(script) {
|
|
|
8341
8359
|
const hex = Buff.bytes(script).hex;
|
|
8342
8360
|
return LOCK_SCRIPT_REGEX['p2tr'].test(hex);
|
|
8343
8361
|
}
|
|
8362
|
+
function is_opreturn_script(script) {
|
|
8363
|
+
const hex = Buff.bytes(script).hex;
|
|
8364
|
+
return LOCK_SCRIPT_REGEX['opreturn'].test(hex);
|
|
8365
|
+
}
|
|
8344
8366
|
|
|
8345
8367
|
function get_address_script(script_key, script_type) {
|
|
8346
8368
|
switch (script_type) {
|
|
@@ -8664,24 +8686,24 @@ function decode_p2tr_script(script) {
|
|
|
8664
8686
|
return bytes.slice(2, 34);
|
|
8665
8687
|
}
|
|
8666
8688
|
|
|
8667
|
-
function
|
|
8689
|
+
function get_address(script, network = 'main') {
|
|
8668
8690
|
const bytes = Buff.bytes(script);
|
|
8669
8691
|
const type = get_lock_script_type(bytes);
|
|
8670
8692
|
if (type === null)
|
|
8671
|
-
throw new Error('
|
|
8693
|
+
throw new Error('unknown locking script: ' + bytes.hex);
|
|
8672
8694
|
switch (type) {
|
|
8673
8695
|
case LOCK_SCRIPT_TYPE.P2PKH:
|
|
8674
|
-
return P2PKH.
|
|
8696
|
+
return P2PKH.encode_address(script, network);
|
|
8675
8697
|
case LOCK_SCRIPT_TYPE.P2SH:
|
|
8676
|
-
return P2SH.
|
|
8698
|
+
return P2SH.encode_address(script, network);
|
|
8677
8699
|
case LOCK_SCRIPT_TYPE.P2WPKH:
|
|
8678
|
-
return P2WPKH.
|
|
8700
|
+
return P2WPKH.encode_address(script, network);
|
|
8679
8701
|
case LOCK_SCRIPT_TYPE.P2WSH:
|
|
8680
|
-
return P2WSH.
|
|
8702
|
+
return P2WSH.encode_address(script, network);
|
|
8681
8703
|
case LOCK_SCRIPT_TYPE.P2TR:
|
|
8682
|
-
return P2TR.
|
|
8704
|
+
return P2TR.encode_address(script, network);
|
|
8683
8705
|
default:
|
|
8684
|
-
throw new Error('
|
|
8706
|
+
throw new Error('unknown script type: ' + type);
|
|
8685
8707
|
}
|
|
8686
8708
|
}
|
|
8687
8709
|
function parse_address(address) {
|
|
@@ -8695,7 +8717,7 @@ var index$8 = /*#__PURE__*/Object.freeze({
|
|
|
8695
8717
|
get P2TR () { return P2TR; },
|
|
8696
8718
|
get P2WPKH () { return P2WPKH; },
|
|
8697
8719
|
get P2WSH () { return P2WSH; },
|
|
8698
|
-
|
|
8720
|
+
get_address: get_address,
|
|
8699
8721
|
parse_address: parse_address
|
|
8700
8722
|
});
|
|
8701
8723
|
|
|
@@ -9395,13 +9417,10 @@ function parse_script_pubkeys(script) {
|
|
|
9395
9417
|
|
|
9396
9418
|
var ScriptUtil;
|
|
9397
9419
|
(function (ScriptUtil) {
|
|
9398
|
-
ScriptUtil.prefix_size = prefix_script_size;
|
|
9399
9420
|
ScriptUtil.parse = parse_script;
|
|
9400
9421
|
ScriptUtil.decode = decode_script;
|
|
9401
9422
|
ScriptUtil.encode = encode_script;
|
|
9402
9423
|
ScriptUtil.is_valid = is_valid_script;
|
|
9403
|
-
ScriptUtil.get_pubkeys = parse_script_pubkeys;
|
|
9404
|
-
ScriptUtil.OPCODES = OPCODE_MAP;
|
|
9405
9424
|
})(ScriptUtil || (ScriptUtil = {}));
|
|
9406
9425
|
|
|
9407
9426
|
var index$6 = /*#__PURE__*/Object.freeze({
|
|
@@ -9412,9 +9431,19 @@ var index$6 = /*#__PURE__*/Object.freeze({
|
|
|
9412
9431
|
encode_script: encode_script,
|
|
9413
9432
|
encode_script_word: encode_script_word,
|
|
9414
9433
|
get_asm_code: get_asm_code,
|
|
9434
|
+
get_lock_script_info: get_lock_script_info,
|
|
9435
|
+
get_lock_script_type: get_lock_script_type,
|
|
9436
|
+
get_lock_script_version: get_lock_script_version,
|
|
9415
9437
|
get_op_code: get_op_code,
|
|
9416
9438
|
get_op_type: get_op_type,
|
|
9417
9439
|
get_size_varint: get_size_varint,
|
|
9440
|
+
is_opreturn_script: is_opreturn_script,
|
|
9441
|
+
is_p2pkh_script: is_p2pkh_script,
|
|
9442
|
+
is_p2sh_script: is_p2sh_script,
|
|
9443
|
+
is_p2tr_script: is_p2tr_script,
|
|
9444
|
+
is_p2wpkh_script: is_p2wpkh_script,
|
|
9445
|
+
is_p2wsh_script: is_p2wsh_script,
|
|
9446
|
+
is_return_script: is_return_script,
|
|
9418
9447
|
is_valid_op: is_valid_op,
|
|
9419
9448
|
is_valid_script: is_valid_script,
|
|
9420
9449
|
parse_script: parse_script,
|