@vbyte/btc-dev 1.1.7 → 2.0.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/CHANGELOG.md +94 -0
- package/README.md +260 -3
- package/dist/const.d.ts +3 -0
- package/dist/const.js +23 -22
- package/dist/index.d.ts +11 -11
- package/dist/index.js +10 -10
- package/dist/lib/address/api.d.ts +2 -2
- package/dist/lib/address/api.js +12 -12
- package/dist/lib/address/encode.d.ts +1 -1
- package/dist/lib/address/encode.js +24 -24
- package/dist/lib/address/index.d.ts +6 -6
- package/dist/lib/address/index.js +6 -6
- package/dist/lib/address/p2pkh.d.ts +2 -2
- package/dist/lib/address/p2pkh.js +14 -14
- package/dist/lib/address/p2sh.d.ts +2 -2
- package/dist/lib/address/p2sh.js +13 -13
- package/dist/lib/address/p2tr.d.ts +2 -2
- package/dist/lib/address/p2tr.js +13 -13
- package/dist/lib/address/p2wpkh.d.ts +2 -2
- package/dist/lib/address/p2wpkh.js +14 -14
- package/dist/lib/address/p2wsh.d.ts +2 -2
- package/dist/lib/address/p2wsh.js +13 -13
- package/dist/lib/address/script.d.ts +1 -1
- package/dist/lib/address/script.js +16 -16
- package/dist/lib/address/util.d.ts +1 -1
- package/dist/lib/address/util.js +22 -22
- package/dist/lib/meta/index.d.ts +4 -4
- package/dist/lib/meta/index.js +4 -4
- package/dist/lib/meta/locktime.d.ts +1 -1
- package/dist/lib/meta/locktime.js +12 -12
- package/dist/lib/meta/ref.js +9 -6
- package/dist/lib/meta/scribe.d.ts +2 -2
- package/dist/lib/meta/scribe.js +48 -53
- package/dist/lib/meta/sequence.d.ts +1 -1
- package/dist/lib/meta/sequence.js +16 -15
- package/dist/lib/script/decode.d.ts +2 -2
- package/dist/lib/script/decode.js +50 -15
- package/dist/lib/script/encode.d.ts +1 -1
- package/dist/lib/script/encode.js +20 -16
- package/dist/lib/script/index.d.ts +5 -13
- package/dist/lib/script/index.js +5 -14
- package/dist/lib/script/lock.d.ts +2 -2
- package/dist/lib/script/lock.js +15 -12
- package/dist/lib/script/util.js +4 -4
- package/dist/lib/script/words.js +129 -129
- package/dist/lib/sighash/index.d.ts +3 -3
- package/dist/lib/sighash/index.js +3 -3
- package/dist/lib/sighash/segwit.d.ts +2 -2
- package/dist/lib/sighash/segwit.js +15 -14
- package/dist/lib/sighash/taproot.d.ts +2 -2
- package/dist/lib/sighash/taproot.js +24 -23
- package/dist/lib/sighash/util.d.ts +2 -2
- package/dist/lib/sighash/util.js +7 -7
- package/dist/lib/signer/index.d.ts +2 -2
- package/dist/lib/signer/index.js +2 -2
- package/dist/lib/signer/sign.d.ts +1 -1
- package/dist/lib/signer/sign.js +42 -7
- package/dist/lib/signer/verify.d.ts +17 -3
- package/dist/lib/signer/verify.js +233 -3
- package/dist/lib/taproot/cblock.d.ts +1 -1
- package/dist/lib/taproot/cblock.js +14 -16
- package/dist/lib/taproot/encode.d.ts +1 -1
- package/dist/lib/taproot/encode.js +7 -7
- package/dist/lib/taproot/index.d.ts +4 -4
- package/dist/lib/taproot/index.js +4 -4
- package/dist/lib/taproot/parse.d.ts +1 -1
- package/dist/lib/taproot/parse.js +12 -14
- package/dist/lib/taproot/tree.d.ts +2 -2
- package/dist/lib/taproot/tree.js +11 -7
- package/dist/lib/tx/create.d.ts +1 -1
- package/dist/lib/tx/create.js +28 -12
- package/dist/lib/tx/decode.d.ts +2 -2
- package/dist/lib/tx/decode.js +50 -17
- package/dist/lib/tx/encode.d.ts +2 -2
- package/dist/lib/tx/encode.js +13 -16
- package/dist/lib/tx/index.d.ts +7 -7
- package/dist/lib/tx/index.js +7 -7
- package/dist/lib/tx/parse.d.ts +1 -1
- package/dist/lib/tx/parse.js +9 -9
- package/dist/lib/tx/size.d.ts +2 -2
- package/dist/lib/tx/size.js +9 -9
- package/dist/lib/tx/util.d.ts +2 -2
- package/dist/lib/tx/util.js +23 -22
- package/dist/lib/tx/validate.d.ts +1 -1
- package/dist/lib/tx/validate.js +3 -3
- package/dist/lib/witness/index.d.ts +2 -2
- package/dist/lib/witness/index.js +2 -2
- package/dist/lib/witness/parse.d.ts +2 -2
- package/dist/lib/witness/parse.js +24 -23
- package/dist/lib/witness/util.d.ts +2 -2
- package/dist/lib/witness/util.js +5 -5
- package/dist/main.cjs +2308 -1007
- package/dist/main.cjs.map +1 -1
- package/dist/module.mjs +2308 -1007
- package/dist/module.mjs.map +1 -1
- package/dist/package.json +20 -17
- package/dist/schema/base.d.ts +1 -1
- package/dist/schema/base.js +17 -13
- package/dist/schema/index.d.ts +2 -2
- package/dist/schema/index.js +2 -2
- package/dist/schema/taproot.d.ts +1 -1
- package/dist/schema/taproot.js +2 -2
- package/dist/schema/tx.d.ts +1 -1
- package/dist/schema/tx.js +4 -4
- package/dist/script.js +8 -8
- package/dist/script.js.map +1 -1
- package/dist/types/address.d.ts +4 -4
- package/dist/types/index.d.ts +8 -8
- package/dist/types/index.js +8 -8
- package/dist/types/meta.d.ts +4 -4
- package/dist/types/psbt.d.ts +2 -2
- package/dist/types/script.d.ts +2 -2
- package/dist/types/sighash.d.ts +2 -2
- package/dist/types/witness.d.ts +5 -5
- package/package.json +20 -17
- package/src/const.ts +0 -61
- package/src/index.ts +0 -13
- package/src/lib/address/api.ts +0 -50
- package/src/lib/address/encode.ts +0 -183
- package/src/lib/address/index.ts +0 -7
- package/src/lib/address/p2pkh.ts +0 -94
- package/src/lib/address/p2sh.ts +0 -96
- package/src/lib/address/p2tr.ts +0 -91
- package/src/lib/address/p2wpkh.ts +0 -94
- package/src/lib/address/p2wsh.ts +0 -92
- package/src/lib/address/script.ts +0 -63
- package/src/lib/address/util.ts +0 -87
- package/src/lib/meta/index.ts +0 -4
- package/src/lib/meta/locktime.ts +0 -57
- package/src/lib/meta/ref.ts +0 -107
- package/src/lib/meta/scribe.ts +0 -256
- package/src/lib/meta/sequence.ts +0 -146
- package/src/lib/script/decode.ts +0 -85
- package/src/lib/script/encode.ts +0 -129
- package/src/lib/script/index.ts +0 -20
- package/src/lib/script/lock.ts +0 -73
- package/src/lib/script/util.ts +0 -78
- package/src/lib/script/words.ts +0 -182
- package/src/lib/sighash/index.ts +0 -3
- package/src/lib/sighash/segwit.ts +0 -152
- package/src/lib/sighash/taproot.ts +0 -206
- package/src/lib/sighash/util.ts +0 -51
- package/src/lib/signer/index.ts +0 -2
- package/src/lib/signer/sign.ts +0 -39
- package/src/lib/signer/verify.ts +0 -88
- package/src/lib/taproot/cblock.ts +0 -96
- package/src/lib/taproot/encode.ts +0 -49
- package/src/lib/taproot/index.ts +0 -4
- package/src/lib/taproot/parse.ts +0 -65
- package/src/lib/taproot/tree.ts +0 -94
- package/src/lib/tx/create.ts +0 -90
- package/src/lib/tx/decode.ts +0 -123
- package/src/lib/tx/encode.ts +0 -155
- package/src/lib/tx/index.ts +0 -7
- package/src/lib/tx/parse.ts +0 -69
- package/src/lib/tx/size.ts +0 -68
- package/src/lib/tx/util.ts +0 -113
- package/src/lib/tx/validate.ts +0 -49
- package/src/lib/witness/index.ts +0 -2
- package/src/lib/witness/parse.ts +0 -127
- package/src/lib/witness/util.ts +0 -18
- package/src/schema/base.ts +0 -57
- package/src/schema/index.ts +0 -2
- package/src/schema/taproot.ts +0 -12
- package/src/schema/tx.ts +0 -48
- package/src/types/address.ts +0 -35
- package/src/types/index.ts +0 -8
- package/src/types/meta.ts +0 -48
- package/src/types/psbt.ts +0 -15
- package/src/types/script.ts +0 -18
- package/src/types/sighash.ts +0 -16
- package/src/types/taproot.ts +0 -41
- package/src/types/txdata.ts +0 -85
- package/src/types/witness.ts +0 -42
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export
|
|
1
|
+
export * from "./api.js";
|
|
2
|
+
export { P2PKH } from "./p2pkh.js";
|
|
3
|
+
export { P2SH } from "./p2sh.js";
|
|
4
|
+
export { P2TR } from "./p2tr.js";
|
|
5
|
+
export { P2WPKH } from "./p2wpkh.js";
|
|
6
|
+
export { P2WSH } from "./p2wsh.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Buff, Bytes } from
|
|
2
|
-
import type { AddressInfo, ChainNetwork } from
|
|
1
|
+
import { Buff, type Bytes } from "@vbyte/buff";
|
|
2
|
+
import type { AddressInfo, ChainNetwork } from "../../types/index.js";
|
|
3
3
|
export declare namespace P2PKH {
|
|
4
4
|
const create_address: typeof create_p2pkh_address;
|
|
5
5
|
const create_script: typeof create_p2pkh_script;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Buff } from
|
|
2
|
-
import { Assert } from
|
|
3
|
-
import { hash160 } from
|
|
4
|
-
import {
|
|
5
|
-
import { is_p2pkh_script } from
|
|
6
|
-
import {
|
|
7
|
-
import { get_address_config, get_address_info } from
|
|
1
|
+
import { Buff } from "@vbyte/buff";
|
|
2
|
+
import { Assert } from "@vbyte/micro-lib";
|
|
3
|
+
import { hash160 } from "@vbyte/micro-lib/hash";
|
|
4
|
+
import { LOCK_SCRIPT_TYPE } from "../../const.js";
|
|
5
|
+
import { is_p2pkh_script } from "../../lib/script/lock.js";
|
|
6
|
+
import { encode_address } from "./encode.js";
|
|
7
|
+
import { get_address_config, get_address_info } from "./util.js";
|
|
8
8
|
const ADDRESS_TYPE = LOCK_SCRIPT_TYPE.P2PKH;
|
|
9
9
|
export var P2PKH;
|
|
10
10
|
(function (P2PKH) {
|
|
@@ -15,33 +15,33 @@ export var P2PKH;
|
|
|
15
15
|
P2PKH.decode_address = decode_p2pkh_address;
|
|
16
16
|
P2PKH.decode_script = decode_p2pkh_script;
|
|
17
17
|
})(P2PKH || (P2PKH = {}));
|
|
18
|
-
function create_p2pkh_address(pubkey, network =
|
|
18
|
+
function create_p2pkh_address(pubkey, network = "main") {
|
|
19
19
|
const script = create_p2pkh_script(pubkey);
|
|
20
20
|
return encode_p2pkh_address(script, network);
|
|
21
21
|
}
|
|
22
22
|
function create_p2pkh_script(pubkey) {
|
|
23
23
|
const bytes = Buff.bytes(pubkey);
|
|
24
|
-
Assert.size(bytes, 33,
|
|
24
|
+
Assert.size(bytes, 33, "invalid pubkey size");
|
|
25
25
|
const hash = hash160(bytes);
|
|
26
26
|
return encode_p2pkh_script(hash);
|
|
27
27
|
}
|
|
28
28
|
function encode_p2pkh_script(pk_hash) {
|
|
29
|
-
return Buff.join([
|
|
29
|
+
return Buff.join(["76a914", pk_hash, "88ac"]);
|
|
30
30
|
}
|
|
31
|
-
function encode_p2pkh_address(script, network =
|
|
31
|
+
function encode_p2pkh_address(script, network = "main") {
|
|
32
32
|
const pk_hash = decode_p2pkh_script(script);
|
|
33
33
|
const config = get_address_config(network, ADDRESS_TYPE);
|
|
34
34
|
Assert.exists(config, `unrecognized address config: ${ADDRESS_TYPE} on ${network}`);
|
|
35
35
|
Assert.size(pk_hash, config.size, `invalid payload size: ${pk_hash.length} !== ${config.size}`);
|
|
36
36
|
return encode_address({
|
|
37
37
|
data: pk_hash,
|
|
38
|
-
format:
|
|
39
|
-
version: config.version
|
|
38
|
+
format: "base58",
|
|
39
|
+
version: config.version,
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
function decode_p2pkh_address(address) {
|
|
43
43
|
const parsed = get_address_info(address);
|
|
44
|
-
Assert.ok(parsed.type ===
|
|
44
|
+
Assert.ok(parsed.type === "p2pkh", `address type mismatch: ${parsed.type} !== ${ADDRESS_TYPE}`);
|
|
45
45
|
return parsed;
|
|
46
46
|
}
|
|
47
47
|
function decode_p2pkh_script(script) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Buff, Bytes } from
|
|
2
|
-
import type { AddressInfo, ChainNetwork } from
|
|
1
|
+
import { Buff, type Bytes } from "@vbyte/buff";
|
|
2
|
+
import type { AddressInfo, ChainNetwork } from "../../types/index.js";
|
|
3
3
|
export declare namespace P2SH {
|
|
4
4
|
const create_address: typeof create_p2sh_address;
|
|
5
5
|
const create_script: typeof create_p2sh_script;
|
package/dist/lib/address/p2sh.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Buff } from
|
|
2
|
-
import { Assert } from
|
|
3
|
-
import { hash160 } from
|
|
4
|
-
import {
|
|
5
|
-
import { is_p2sh_script } from
|
|
6
|
-
import {
|
|
7
|
-
import { get_address_config, get_address_info } from
|
|
1
|
+
import { Buff } from "@vbyte/buff";
|
|
2
|
+
import { Assert } from "@vbyte/micro-lib";
|
|
3
|
+
import { hash160 } from "@vbyte/micro-lib/hash";
|
|
4
|
+
import { LOCK_SCRIPT_TYPE } from "../../const.js";
|
|
5
|
+
import { is_p2sh_script } from "../../lib/script/lock.js";
|
|
6
|
+
import { encode_address } from "./encode.js";
|
|
7
|
+
import { get_address_config, get_address_info } from "./util.js";
|
|
8
8
|
const ADDRESS_TYPE = LOCK_SCRIPT_TYPE.P2SH;
|
|
9
9
|
export var P2SH;
|
|
10
10
|
(function (P2SH) {
|
|
@@ -15,7 +15,7 @@ export var P2SH;
|
|
|
15
15
|
P2SH.decode_address = decode_p2sh_address;
|
|
16
16
|
P2SH.decode_script = decode_p2sh_script;
|
|
17
17
|
})(P2SH || (P2SH = {}));
|
|
18
|
-
function create_p2sh_address(script, network =
|
|
18
|
+
function create_p2sh_address(script, network = "main") {
|
|
19
19
|
const bytes = Buff.bytes(script);
|
|
20
20
|
const hash = hash160(bytes);
|
|
21
21
|
const p2sh_script = encode_p2sh_script(hash);
|
|
@@ -27,22 +27,22 @@ function create_p2sh_script(script) {
|
|
|
27
27
|
return encode_p2sh_script(hash);
|
|
28
28
|
}
|
|
29
29
|
function encode_p2sh_script(script_hash) {
|
|
30
|
-
return Buff.join([
|
|
30
|
+
return Buff.join(["a914", script_hash, "87"]);
|
|
31
31
|
}
|
|
32
|
-
function encode_p2sh_address(script_pk, network =
|
|
32
|
+
function encode_p2sh_address(script_pk, network = "main") {
|
|
33
33
|
const script_hash = decode_p2sh_script(script_pk);
|
|
34
34
|
const config = get_address_config(network, ADDRESS_TYPE);
|
|
35
35
|
Assert.exists(config, `unrecognized address config: ${ADDRESS_TYPE} on ${network}`);
|
|
36
36
|
Assert.size(script_hash, config.size, `invalid payload size: ${script_hash.length} !== ${config.size}`);
|
|
37
37
|
return encode_address({
|
|
38
38
|
data: script_hash,
|
|
39
|
-
format:
|
|
40
|
-
version: config.version
|
|
39
|
+
format: "base58",
|
|
40
|
+
version: config.version,
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
43
|
function decode_p2sh_address(address) {
|
|
44
44
|
const parsed = get_address_info(address);
|
|
45
|
-
Assert.ok(parsed.type ===
|
|
45
|
+
Assert.ok(parsed.type === "p2sh", `address type mismatch: ${parsed.type} !== ${ADDRESS_TYPE}`);
|
|
46
46
|
return parsed;
|
|
47
47
|
}
|
|
48
48
|
function decode_p2sh_script(script) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Buff, Bytes } from
|
|
2
|
-
import type { AddressInfo, ChainNetwork } from
|
|
1
|
+
import { Buff, type Bytes } from "@vbyte/buff";
|
|
2
|
+
import type { AddressInfo, ChainNetwork } from "../../types/index.js";
|
|
3
3
|
export declare namespace P2TR {
|
|
4
4
|
const create_address: typeof create_p2tr_address;
|
|
5
5
|
const create_script: typeof create_p2tr_script;
|
package/dist/lib/address/p2tr.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Buff } from
|
|
2
|
-
import { Assert } from
|
|
3
|
-
import {
|
|
4
|
-
import { is_p2tr_script } from
|
|
5
|
-
import {
|
|
6
|
-
import { get_address_config, get_address_info } from
|
|
1
|
+
import { Buff } from "@vbyte/buff";
|
|
2
|
+
import { Assert } from "@vbyte/micro-lib";
|
|
3
|
+
import { LOCK_SCRIPT_TYPE } from "../../const.js";
|
|
4
|
+
import { is_p2tr_script } from "../../lib/script/lock.js";
|
|
5
|
+
import { encode_address } from "./encode.js";
|
|
6
|
+
import { get_address_config, get_address_info } from "./util.js";
|
|
7
7
|
const ADDRESS_TYPE = LOCK_SCRIPT_TYPE.P2TR;
|
|
8
8
|
export var P2TR;
|
|
9
9
|
(function (P2TR) {
|
|
@@ -14,32 +14,32 @@ export var P2TR;
|
|
|
14
14
|
P2TR.decode_address = decode_p2tr_address;
|
|
15
15
|
P2TR.decode_script = decode_p2tr_script;
|
|
16
16
|
})(P2TR || (P2TR = {}));
|
|
17
|
-
function create_p2tr_address(pubkey, network =
|
|
17
|
+
function create_p2tr_address(pubkey, network = "main") {
|
|
18
18
|
const script = create_p2tr_script(pubkey);
|
|
19
19
|
return encode_p2tr_address(script, network);
|
|
20
20
|
}
|
|
21
21
|
function create_p2tr_script(pubkey) {
|
|
22
22
|
const bytes = Buff.bytes(pubkey);
|
|
23
|
-
Assert.size(bytes, 32,
|
|
23
|
+
Assert.size(bytes, 32, "invalid pubkey size");
|
|
24
24
|
return encode_p2tr_script(bytes);
|
|
25
25
|
}
|
|
26
26
|
function encode_p2tr_script(pubkey) {
|
|
27
|
-
return Buff.join([
|
|
27
|
+
return Buff.join(["5120", pubkey]);
|
|
28
28
|
}
|
|
29
|
-
function encode_p2tr_address(script_pk, network =
|
|
29
|
+
function encode_p2tr_address(script_pk, network = "main") {
|
|
30
30
|
const pubkey = decode_p2tr_script(script_pk);
|
|
31
31
|
const config = get_address_config(network, ADDRESS_TYPE);
|
|
32
32
|
Assert.exists(config, `unrecognized address config: ${ADDRESS_TYPE} on ${network}`);
|
|
33
33
|
Assert.size(pubkey, config.size, `invalid payload size: ${pubkey.length} !== ${config.size}`);
|
|
34
34
|
return encode_address({
|
|
35
35
|
data: pubkey,
|
|
36
|
-
format:
|
|
37
|
-
prefix: config.prefix
|
|
36
|
+
format: "bech32m",
|
|
37
|
+
prefix: config.prefix,
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
function decode_p2tr_address(address) {
|
|
41
41
|
const parsed = get_address_info(address);
|
|
42
|
-
Assert.ok(parsed.type ===
|
|
42
|
+
Assert.ok(parsed.type === "p2tr", `address type mismatch: ${parsed.type} !== ${ADDRESS_TYPE}`);
|
|
43
43
|
return parsed;
|
|
44
44
|
}
|
|
45
45
|
function decode_p2tr_script(script) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Buff, Bytes } from
|
|
2
|
-
import type { AddressInfo, ChainNetwork } from
|
|
1
|
+
import { Buff, type Bytes } from "@vbyte/buff";
|
|
2
|
+
import type { AddressInfo, ChainNetwork } from "../../types/index.js";
|
|
3
3
|
export declare namespace P2WPKH {
|
|
4
4
|
const create_address: typeof create_p2wpkh_address;
|
|
5
5
|
const create_script: typeof create_p2wpkh_script;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Buff } from
|
|
2
|
-
import { Assert } from
|
|
3
|
-
import { hash160 } from
|
|
4
|
-
import {
|
|
5
|
-
import { is_p2wpkh_script } from
|
|
6
|
-
import {
|
|
7
|
-
import { get_address_config, get_address_info } from
|
|
1
|
+
import { Buff } from "@vbyte/buff";
|
|
2
|
+
import { Assert } from "@vbyte/micro-lib";
|
|
3
|
+
import { hash160 } from "@vbyte/micro-lib/hash";
|
|
4
|
+
import { LOCK_SCRIPT_TYPE } from "../../const.js";
|
|
5
|
+
import { is_p2wpkh_script } from "../../lib/script/lock.js";
|
|
6
|
+
import { encode_address } from "./encode.js";
|
|
7
|
+
import { get_address_config, get_address_info } from "./util.js";
|
|
8
8
|
const ADDRESS_TYPE = LOCK_SCRIPT_TYPE.P2WPKH;
|
|
9
9
|
export var P2WPKH;
|
|
10
10
|
(function (P2WPKH) {
|
|
@@ -15,33 +15,33 @@ export var P2WPKH;
|
|
|
15
15
|
P2WPKH.decode_address = decode_p2wpkh_address;
|
|
16
16
|
P2WPKH.decode_script = decode_p2wpkh_script;
|
|
17
17
|
})(P2WPKH || (P2WPKH = {}));
|
|
18
|
-
function create_p2wpkh_address(pubkey, network =
|
|
18
|
+
function create_p2wpkh_address(pubkey, network = "main") {
|
|
19
19
|
const script = create_p2wpkh_script(pubkey);
|
|
20
20
|
return encode_p2wpkh_address(script, network);
|
|
21
21
|
}
|
|
22
22
|
function create_p2wpkh_script(pubkey) {
|
|
23
23
|
const bytes = Buff.bytes(pubkey);
|
|
24
|
-
Assert.size(bytes, 33,
|
|
24
|
+
Assert.size(bytes, 33, "invalid pubkey size");
|
|
25
25
|
const hash = hash160(bytes);
|
|
26
26
|
return encode_p2wpkh_script(hash);
|
|
27
27
|
}
|
|
28
28
|
function encode_p2wpkh_script(pk_hash) {
|
|
29
|
-
return Buff.join([
|
|
29
|
+
return Buff.join(["0014", pk_hash]);
|
|
30
30
|
}
|
|
31
|
-
function encode_p2wpkh_address(script_pk, network =
|
|
31
|
+
function encode_p2wpkh_address(script_pk, network = "main") {
|
|
32
32
|
const pk_hash = decode_p2wpkh_script(script_pk);
|
|
33
33
|
const config = get_address_config(network, ADDRESS_TYPE);
|
|
34
34
|
Assert.exists(config, `unrecognized address config: ${ADDRESS_TYPE} on ${network}`);
|
|
35
35
|
Assert.size(pk_hash, config.size, `invalid payload size: ${pk_hash.length} !== ${config.size}`);
|
|
36
36
|
return encode_address({
|
|
37
37
|
data: pk_hash,
|
|
38
|
-
format:
|
|
39
|
-
prefix: config.prefix
|
|
38
|
+
format: "bech32",
|
|
39
|
+
prefix: config.prefix,
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
function decode_p2wpkh_address(address) {
|
|
43
43
|
const parsed = get_address_info(address);
|
|
44
|
-
Assert.ok(parsed.type ===
|
|
44
|
+
Assert.ok(parsed.type === "p2wpkh", `address type mismatch: ${parsed.type} !== ${ADDRESS_TYPE}`);
|
|
45
45
|
return parsed;
|
|
46
46
|
}
|
|
47
47
|
function decode_p2wpkh_script(script) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Buff, Bytes } from
|
|
2
|
-
import type { AddressInfo, ChainNetwork } from
|
|
1
|
+
import { Buff, type Bytes } from "@vbyte/buff";
|
|
2
|
+
import type { AddressInfo, ChainNetwork } from "../../types/index.js";
|
|
3
3
|
export declare namespace P2WSH {
|
|
4
4
|
const create_address: typeof create_p2wsh_address;
|
|
5
5
|
const create_script: typeof create_p2wsh_script;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { Buff } from
|
|
2
|
-
import { Assert } from
|
|
3
|
-
import { sha256 } from
|
|
4
|
-
import {
|
|
5
|
-
import { is_p2wsh_script } from
|
|
6
|
-
import {
|
|
7
|
-
import { get_address_config, get_address_info } from
|
|
1
|
+
import { Buff } from "@vbyte/buff";
|
|
2
|
+
import { Assert } from "@vbyte/micro-lib";
|
|
3
|
+
import { sha256 } from "@vbyte/micro-lib/hash";
|
|
4
|
+
import { LOCK_SCRIPT_TYPE } from "../../const.js";
|
|
5
|
+
import { is_p2wsh_script } from "../../lib/script/lock.js";
|
|
6
|
+
import { encode_address } from "./encode.js";
|
|
7
|
+
import { get_address_config, get_address_info } from "./util.js";
|
|
8
8
|
const ADDRESS_TYPE = LOCK_SCRIPT_TYPE.P2WSH;
|
|
9
9
|
export var P2WSH;
|
|
10
10
|
(function (P2WSH) {
|
|
@@ -15,7 +15,7 @@ export var P2WSH;
|
|
|
15
15
|
P2WSH.decode_address = decode_p2wsh_address;
|
|
16
16
|
P2WSH.decode_script = decode_p2wsh_script;
|
|
17
17
|
})(P2WSH || (P2WSH = {}));
|
|
18
|
-
function create_p2wsh_address(script, network =
|
|
18
|
+
function create_p2wsh_address(script, network = "main") {
|
|
19
19
|
const wsh_script = create_p2wsh_script(script);
|
|
20
20
|
return encode_p2wsh_address(wsh_script, network);
|
|
21
21
|
}
|
|
@@ -25,22 +25,22 @@ function create_p2wsh_script(script) {
|
|
|
25
25
|
return encode_p2wsh_script(hash);
|
|
26
26
|
}
|
|
27
27
|
function encode_p2wsh_script(script_hash) {
|
|
28
|
-
return Buff.join([
|
|
28
|
+
return Buff.join(["0020", script_hash]);
|
|
29
29
|
}
|
|
30
|
-
function encode_p2wsh_address(script_pk, network =
|
|
30
|
+
function encode_p2wsh_address(script_pk, network = "main") {
|
|
31
31
|
const script_hash = decode_p2wsh_script(script_pk);
|
|
32
32
|
const config = get_address_config(network, ADDRESS_TYPE);
|
|
33
33
|
Assert.exists(config, `unrecognized address config: ${ADDRESS_TYPE} on ${network}`);
|
|
34
34
|
Assert.size(script_hash, config.size, `invalid payload size: ${script_hash.length} !== ${config.size}`);
|
|
35
35
|
return encode_address({
|
|
36
36
|
data: script_hash,
|
|
37
|
-
format:
|
|
38
|
-
prefix: config.prefix
|
|
37
|
+
format: "bech32",
|
|
38
|
+
prefix: config.prefix,
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
function decode_p2wsh_address(address) {
|
|
42
42
|
const parsed = get_address_info(address);
|
|
43
|
-
Assert.ok(parsed.type ===
|
|
43
|
+
Assert.ok(parsed.type === "p2wsh", `address type mismatch: ${parsed.type} !== ${ADDRESS_TYPE}`);
|
|
44
44
|
return parsed;
|
|
45
45
|
}
|
|
46
46
|
function decode_p2wsh_script(script) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { AddressType, ScriptInfo } from
|
|
1
|
+
import type { AddressType, ScriptInfo } from "../../types/index.js";
|
|
2
2
|
export declare function get_address_script(script_key: string, script_type: AddressType): ScriptInfo;
|
|
@@ -1,46 +1,46 @@
|
|
|
1
1
|
export function get_address_script(script_key, script_type) {
|
|
2
2
|
switch (script_type) {
|
|
3
|
-
case
|
|
3
|
+
case "p2pkh":
|
|
4
4
|
return get_p2pkh_script(script_key);
|
|
5
|
-
case
|
|
5
|
+
case "p2sh":
|
|
6
6
|
return get_p2sh_script(script_key);
|
|
7
|
-
case
|
|
7
|
+
case "p2wpkh":
|
|
8
8
|
return get_p2w_pkh_script(script_key);
|
|
9
|
-
case
|
|
9
|
+
case "p2wsh":
|
|
10
10
|
return get_p2w_sh_script(script_key);
|
|
11
|
-
case
|
|
11
|
+
case "p2tr":
|
|
12
12
|
return get_p2tr_script(script_key);
|
|
13
13
|
default:
|
|
14
|
-
throw new Error(
|
|
14
|
+
throw new Error(`unrecognized script type: ${script_type}`);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
function get_p2pkh_script(script_key) {
|
|
18
18
|
return {
|
|
19
|
-
hex:
|
|
20
|
-
asm: [
|
|
19
|
+
hex: `76a914${script_key}88ac`,
|
|
20
|
+
asm: ["OP_DUP", "OP_HASH160", script_key, "OP_EQUALVERIFY", "OP_CHECKSIG"],
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
function get_p2sh_script(script_key) {
|
|
24
24
|
return {
|
|
25
|
-
hex:
|
|
26
|
-
asm: [
|
|
25
|
+
hex: `a914${script_key}87`,
|
|
26
|
+
asm: ["OP_HASH160", script_key, "OP_EQUAL"],
|
|
27
27
|
};
|
|
28
28
|
}
|
|
29
29
|
function get_p2w_pkh_script(script_key) {
|
|
30
30
|
return {
|
|
31
|
-
hex:
|
|
32
|
-
asm: [
|
|
31
|
+
hex: `0014${script_key}`,
|
|
32
|
+
asm: ["OP_0", script_key],
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
function get_p2w_sh_script(script_key) {
|
|
36
36
|
return {
|
|
37
|
-
hex:
|
|
38
|
-
asm: [
|
|
37
|
+
hex: `0020${script_key}`,
|
|
38
|
+
asm: ["OP_0", script_key],
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
function get_p2tr_script(script_key) {
|
|
42
42
|
return {
|
|
43
|
-
hex:
|
|
44
|
-
asm: [
|
|
43
|
+
hex: `5120${script_key}`,
|
|
44
|
+
asm: ["OP_1", script_key],
|
|
45
45
|
};
|
|
46
46
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { AddressConfig, AddressInfo, ChainNetwork, LockScriptType } from
|
|
1
|
+
import type { AddressConfig, AddressInfo, ChainNetwork, LockScriptType } from "../../types/index.js";
|
|
2
2
|
export declare function get_address_config(address_network: ChainNetwork, address_type: LockScriptType): AddressConfig | null;
|
|
3
3
|
export declare function get_address_info(address: string): AddressInfo;
|
package/dist/lib/address/util.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { Buff } from
|
|
2
|
-
import { decode_address } from
|
|
3
|
-
import { get_address_script } from
|
|
1
|
+
import { Buff } from "@vbyte/buff";
|
|
2
|
+
import { decode_address } from "./encode.js";
|
|
3
|
+
import { get_address_script } from "./script.js";
|
|
4
4
|
const CONFIG_TABLE = [
|
|
5
|
-
[
|
|
6
|
-
[
|
|
7
|
-
[
|
|
8
|
-
[
|
|
9
|
-
[
|
|
10
|
-
[
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
[
|
|
16
|
-
[
|
|
17
|
-
[
|
|
18
|
-
[
|
|
19
|
-
[
|
|
20
|
-
[
|
|
21
|
-
[
|
|
5
|
+
["1", "p2pkh", "main", 20, "base58", 0x00],
|
|
6
|
+
["3", "p2sh", "main", 20, "base58", 0x05],
|
|
7
|
+
["m", "p2pkh", "testnet", 20, "base58", 0x6f],
|
|
8
|
+
["n", "p2pkh", "testnet", 20, "base58", 0x6f],
|
|
9
|
+
["2", "p2sh", "testnet", 20, "base58", 0xc4],
|
|
10
|
+
["m", "p2pkh", "regtest", 20, "base58", 0x6f],
|
|
11
|
+
["n", "p2pkh", "regtest", 20, "base58", 0x6f],
|
|
12
|
+
["2", "p2sh", "regtest", 20, "base58", 0xc4],
|
|
13
|
+
["bc", "p2wpkh", "main", 20, "bech32", 0],
|
|
14
|
+
["tb", "p2wpkh", "testnet", 20, "bech32", 0],
|
|
15
|
+
["bcrt", "p2wpkh", "regtest", 20, "bech32", 0],
|
|
16
|
+
["bc", "p2wsh", "main", 32, "bech32", 0],
|
|
17
|
+
["tb", "p2wsh", "testnet", 32, "bech32", 0],
|
|
18
|
+
["bcrt", "p2wsh", "regtest", 32, "bech32", 0],
|
|
19
|
+
["bc", "p2tr", "main", 32, "bech32m", 1],
|
|
20
|
+
["tb", "p2tr", "testnet", 32, "bech32m", 1],
|
|
21
|
+
["bcrt", "p2tr", "regtest", 32, "bech32m", 1],
|
|
22
22
|
];
|
|
23
23
|
export function get_address_config(address_network, address_type) {
|
|
24
24
|
for (const [prefix, type, network, size, format, version] of CONFIG_TABLE) {
|
|
@@ -45,9 +45,9 @@ export function get_address_info(address) {
|
|
|
45
45
|
if (!address.startsWith(prefix))
|
|
46
46
|
continue;
|
|
47
47
|
}
|
|
48
|
-
const data = Buff.
|
|
48
|
+
const data = Buff.bytes(dec.data).hex;
|
|
49
49
|
const script = get_address_script(data, type);
|
|
50
50
|
return { data, script, type, prefix, network, size, format, version };
|
|
51
51
|
}
|
|
52
|
-
throw new Error(
|
|
52
|
+
throw new Error("address configuration is invalid");
|
|
53
53
|
}
|
package/dist/lib/meta/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
1
|
+
export * from "./locktime.js";
|
|
2
|
+
export * from "./ref.js";
|
|
3
|
+
export * from "./scribe.js";
|
|
4
|
+
export * from "./sequence.js";
|
package/dist/lib/meta/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
1
|
+
export * from "./locktime.js";
|
|
2
|
+
export * from "./ref.js";
|
|
3
|
+
export * from "./scribe.js";
|
|
4
|
+
export * from "./sequence.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Assert } from
|
|
1
|
+
import { Assert } from "@vbyte/micro-lib";
|
|
2
2
|
const LOCKTIME_THRESHOLD = 500000000;
|
|
3
3
|
export var LocktimeField;
|
|
4
4
|
(function (LocktimeField) {
|
|
@@ -7,31 +7,31 @@ export var LocktimeField;
|
|
|
7
7
|
})(LocktimeField || (LocktimeField = {}));
|
|
8
8
|
export function encode_locktime(locktime) {
|
|
9
9
|
switch (locktime.type) {
|
|
10
|
-
case
|
|
11
|
-
Assert.ok(locktime.stamp >= LOCKTIME_THRESHOLD,
|
|
10
|
+
case "timelock":
|
|
11
|
+
Assert.ok(locktime.stamp >= LOCKTIME_THRESHOLD, "Invalid timestamp");
|
|
12
12
|
return locktime.stamp;
|
|
13
|
-
case
|
|
14
|
-
Assert.ok(locktime.height > 0,
|
|
15
|
-
Assert.ok(locktime.height < LOCKTIME_THRESHOLD,
|
|
13
|
+
case "heightlock":
|
|
14
|
+
Assert.ok(locktime.height > 0, "height must be greater than 0");
|
|
15
|
+
Assert.ok(locktime.height < LOCKTIME_THRESHOLD, "invalid block height");
|
|
16
16
|
return locktime.height;
|
|
17
17
|
default:
|
|
18
|
-
throw new Error(
|
|
18
|
+
throw new Error("Invalid locktime type");
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
export function decode_locktime(locktime) {
|
|
22
|
-
if (isNaN(locktime) || locktime <= 0) {
|
|
22
|
+
if (Number.isNaN(locktime) || locktime <= 0) {
|
|
23
23
|
return null;
|
|
24
24
|
}
|
|
25
25
|
if (locktime < LOCKTIME_THRESHOLD) {
|
|
26
26
|
return {
|
|
27
|
-
type:
|
|
28
|
-
height: locktime
|
|
27
|
+
type: "heightlock",
|
|
28
|
+
height: locktime,
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
else {
|
|
32
32
|
return {
|
|
33
|
-
type:
|
|
34
|
-
stamp: locktime
|
|
33
|
+
type: "timelock",
|
|
34
|
+
stamp: locktime,
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
}
|
package/dist/lib/meta/ref.js
CHANGED
|
@@ -24,8 +24,8 @@ function encode_inscription_id(txid, order = 0) {
|
|
|
24
24
|
}
|
|
25
25
|
function decode_inscription_id(inscription_id) {
|
|
26
26
|
assert_inscription_id(inscription_id);
|
|
27
|
-
const [txid, order] = inscription_id.split(
|
|
28
|
-
return { txid, order: parseInt(order) };
|
|
27
|
+
const [txid, order] = inscription_id.split("i");
|
|
28
|
+
return { txid, order: parseInt(order, 10) };
|
|
29
29
|
}
|
|
30
30
|
function verify_inscription_id(inscription_id) {
|
|
31
31
|
return inscription_id.match(/^[a-f0-9]{64}i\d+$/) !== null;
|
|
@@ -40,8 +40,11 @@ function encode_rune_id(block_height, block_index) {
|
|
|
40
40
|
}
|
|
41
41
|
function decode_rune_id(rune_id) {
|
|
42
42
|
assert_rune_id(rune_id);
|
|
43
|
-
const [block_height, block_index] = rune_id.split(
|
|
44
|
-
return {
|
|
43
|
+
const [block_height, block_index] = rune_id.split(":");
|
|
44
|
+
return {
|
|
45
|
+
block_height: parseInt(block_height, 10),
|
|
46
|
+
block_index: parseInt(block_index, 10),
|
|
47
|
+
};
|
|
45
48
|
}
|
|
46
49
|
function verify_rune_id(rune_id) {
|
|
47
50
|
return rune_id.match(/^\d+:\d+$/) !== null;
|
|
@@ -56,8 +59,8 @@ function encode_outpoint(txid, vout) {
|
|
|
56
59
|
}
|
|
57
60
|
function decode_outpoint(outpoint) {
|
|
58
61
|
assert_outpoint(outpoint);
|
|
59
|
-
const [txid, vout] = outpoint.split(
|
|
60
|
-
return { txid, vout: parseInt(vout) };
|
|
62
|
+
const [txid, vout] = outpoint.split(":");
|
|
63
|
+
return { txid, vout: parseInt(vout, 10) };
|
|
61
64
|
}
|
|
62
65
|
function verify_outpoint(outpoint) {
|
|
63
66
|
return outpoint.match(/^[a-f0-9]{64}:[0-9]+$/) !== null;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Buff, Bytes } from
|
|
2
|
-
import type { InscriptionData } from
|
|
1
|
+
import { Buff, type Bytes } from "@vbyte/buff";
|
|
2
|
+
import type { InscriptionData } from "../../types/index.js";
|
|
3
3
|
export declare namespace InscriptionUtil {
|
|
4
4
|
type Type = InscriptionData;
|
|
5
5
|
const encode: typeof encode_inscription;
|