@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.
Files changed (174) hide show
  1. package/CHANGELOG.md +94 -0
  2. package/README.md +260 -3
  3. package/dist/const.d.ts +3 -0
  4. package/dist/const.js +23 -22
  5. package/dist/index.d.ts +11 -11
  6. package/dist/index.js +10 -10
  7. package/dist/lib/address/api.d.ts +2 -2
  8. package/dist/lib/address/api.js +12 -12
  9. package/dist/lib/address/encode.d.ts +1 -1
  10. package/dist/lib/address/encode.js +24 -24
  11. package/dist/lib/address/index.d.ts +6 -6
  12. package/dist/lib/address/index.js +6 -6
  13. package/dist/lib/address/p2pkh.d.ts +2 -2
  14. package/dist/lib/address/p2pkh.js +14 -14
  15. package/dist/lib/address/p2sh.d.ts +2 -2
  16. package/dist/lib/address/p2sh.js +13 -13
  17. package/dist/lib/address/p2tr.d.ts +2 -2
  18. package/dist/lib/address/p2tr.js +13 -13
  19. package/dist/lib/address/p2wpkh.d.ts +2 -2
  20. package/dist/lib/address/p2wpkh.js +14 -14
  21. package/dist/lib/address/p2wsh.d.ts +2 -2
  22. package/dist/lib/address/p2wsh.js +13 -13
  23. package/dist/lib/address/script.d.ts +1 -1
  24. package/dist/lib/address/script.js +16 -16
  25. package/dist/lib/address/util.d.ts +1 -1
  26. package/dist/lib/address/util.js +22 -22
  27. package/dist/lib/meta/index.d.ts +4 -4
  28. package/dist/lib/meta/index.js +4 -4
  29. package/dist/lib/meta/locktime.d.ts +1 -1
  30. package/dist/lib/meta/locktime.js +12 -12
  31. package/dist/lib/meta/ref.js +9 -6
  32. package/dist/lib/meta/scribe.d.ts +2 -2
  33. package/dist/lib/meta/scribe.js +48 -53
  34. package/dist/lib/meta/sequence.d.ts +1 -1
  35. package/dist/lib/meta/sequence.js +16 -15
  36. package/dist/lib/script/decode.d.ts +2 -2
  37. package/dist/lib/script/decode.js +50 -15
  38. package/dist/lib/script/encode.d.ts +1 -1
  39. package/dist/lib/script/encode.js +20 -16
  40. package/dist/lib/script/index.d.ts +5 -13
  41. package/dist/lib/script/index.js +5 -14
  42. package/dist/lib/script/lock.d.ts +2 -2
  43. package/dist/lib/script/lock.js +15 -12
  44. package/dist/lib/script/util.js +4 -4
  45. package/dist/lib/script/words.js +129 -129
  46. package/dist/lib/sighash/index.d.ts +3 -3
  47. package/dist/lib/sighash/index.js +3 -3
  48. package/dist/lib/sighash/segwit.d.ts +2 -2
  49. package/dist/lib/sighash/segwit.js +15 -14
  50. package/dist/lib/sighash/taproot.d.ts +2 -2
  51. package/dist/lib/sighash/taproot.js +24 -23
  52. package/dist/lib/sighash/util.d.ts +2 -2
  53. package/dist/lib/sighash/util.js +7 -7
  54. package/dist/lib/signer/index.d.ts +2 -2
  55. package/dist/lib/signer/index.js +2 -2
  56. package/dist/lib/signer/sign.d.ts +1 -1
  57. package/dist/lib/signer/sign.js +42 -7
  58. package/dist/lib/signer/verify.d.ts +17 -3
  59. package/dist/lib/signer/verify.js +233 -3
  60. package/dist/lib/taproot/cblock.d.ts +1 -1
  61. package/dist/lib/taproot/cblock.js +14 -16
  62. package/dist/lib/taproot/encode.d.ts +1 -1
  63. package/dist/lib/taproot/encode.js +7 -7
  64. package/dist/lib/taproot/index.d.ts +4 -4
  65. package/dist/lib/taproot/index.js +4 -4
  66. package/dist/lib/taproot/parse.d.ts +1 -1
  67. package/dist/lib/taproot/parse.js +12 -14
  68. package/dist/lib/taproot/tree.d.ts +2 -2
  69. package/dist/lib/taproot/tree.js +11 -7
  70. package/dist/lib/tx/create.d.ts +1 -1
  71. package/dist/lib/tx/create.js +28 -12
  72. package/dist/lib/tx/decode.d.ts +2 -2
  73. package/dist/lib/tx/decode.js +50 -17
  74. package/dist/lib/tx/encode.d.ts +2 -2
  75. package/dist/lib/tx/encode.js +13 -16
  76. package/dist/lib/tx/index.d.ts +7 -7
  77. package/dist/lib/tx/index.js +7 -7
  78. package/dist/lib/tx/parse.d.ts +1 -1
  79. package/dist/lib/tx/parse.js +9 -9
  80. package/dist/lib/tx/size.d.ts +2 -2
  81. package/dist/lib/tx/size.js +9 -9
  82. package/dist/lib/tx/util.d.ts +2 -2
  83. package/dist/lib/tx/util.js +23 -22
  84. package/dist/lib/tx/validate.d.ts +1 -1
  85. package/dist/lib/tx/validate.js +3 -3
  86. package/dist/lib/witness/index.d.ts +2 -2
  87. package/dist/lib/witness/index.js +2 -2
  88. package/dist/lib/witness/parse.d.ts +2 -2
  89. package/dist/lib/witness/parse.js +24 -23
  90. package/dist/lib/witness/util.d.ts +2 -2
  91. package/dist/lib/witness/util.js +5 -5
  92. package/dist/main.cjs +2308 -1007
  93. package/dist/main.cjs.map +1 -1
  94. package/dist/module.mjs +2308 -1007
  95. package/dist/module.mjs.map +1 -1
  96. package/dist/package.json +20 -17
  97. package/dist/schema/base.d.ts +1 -1
  98. package/dist/schema/base.js +17 -13
  99. package/dist/schema/index.d.ts +2 -2
  100. package/dist/schema/index.js +2 -2
  101. package/dist/schema/taproot.d.ts +1 -1
  102. package/dist/schema/taproot.js +2 -2
  103. package/dist/schema/tx.d.ts +1 -1
  104. package/dist/schema/tx.js +4 -4
  105. package/dist/script.js +8 -8
  106. package/dist/script.js.map +1 -1
  107. package/dist/types/address.d.ts +4 -4
  108. package/dist/types/index.d.ts +8 -8
  109. package/dist/types/index.js +8 -8
  110. package/dist/types/meta.d.ts +4 -4
  111. package/dist/types/psbt.d.ts +2 -2
  112. package/dist/types/script.d.ts +2 -2
  113. package/dist/types/sighash.d.ts +2 -2
  114. package/dist/types/witness.d.ts +5 -5
  115. package/package.json +20 -17
  116. package/src/const.ts +0 -61
  117. package/src/index.ts +0 -13
  118. package/src/lib/address/api.ts +0 -50
  119. package/src/lib/address/encode.ts +0 -183
  120. package/src/lib/address/index.ts +0 -7
  121. package/src/lib/address/p2pkh.ts +0 -94
  122. package/src/lib/address/p2sh.ts +0 -96
  123. package/src/lib/address/p2tr.ts +0 -91
  124. package/src/lib/address/p2wpkh.ts +0 -94
  125. package/src/lib/address/p2wsh.ts +0 -92
  126. package/src/lib/address/script.ts +0 -63
  127. package/src/lib/address/util.ts +0 -87
  128. package/src/lib/meta/index.ts +0 -4
  129. package/src/lib/meta/locktime.ts +0 -57
  130. package/src/lib/meta/ref.ts +0 -107
  131. package/src/lib/meta/scribe.ts +0 -256
  132. package/src/lib/meta/sequence.ts +0 -146
  133. package/src/lib/script/decode.ts +0 -85
  134. package/src/lib/script/encode.ts +0 -129
  135. package/src/lib/script/index.ts +0 -20
  136. package/src/lib/script/lock.ts +0 -73
  137. package/src/lib/script/util.ts +0 -78
  138. package/src/lib/script/words.ts +0 -182
  139. package/src/lib/sighash/index.ts +0 -3
  140. package/src/lib/sighash/segwit.ts +0 -152
  141. package/src/lib/sighash/taproot.ts +0 -206
  142. package/src/lib/sighash/util.ts +0 -51
  143. package/src/lib/signer/index.ts +0 -2
  144. package/src/lib/signer/sign.ts +0 -39
  145. package/src/lib/signer/verify.ts +0 -88
  146. package/src/lib/taproot/cblock.ts +0 -96
  147. package/src/lib/taproot/encode.ts +0 -49
  148. package/src/lib/taproot/index.ts +0 -4
  149. package/src/lib/taproot/parse.ts +0 -65
  150. package/src/lib/taproot/tree.ts +0 -94
  151. package/src/lib/tx/create.ts +0 -90
  152. package/src/lib/tx/decode.ts +0 -123
  153. package/src/lib/tx/encode.ts +0 -155
  154. package/src/lib/tx/index.ts +0 -7
  155. package/src/lib/tx/parse.ts +0 -69
  156. package/src/lib/tx/size.ts +0 -68
  157. package/src/lib/tx/util.ts +0 -113
  158. package/src/lib/tx/validate.ts +0 -49
  159. package/src/lib/witness/index.ts +0 -2
  160. package/src/lib/witness/parse.ts +0 -127
  161. package/src/lib/witness/util.ts +0 -18
  162. package/src/schema/base.ts +0 -57
  163. package/src/schema/index.ts +0 -2
  164. package/src/schema/taproot.ts +0 -12
  165. package/src/schema/tx.ts +0 -48
  166. package/src/types/address.ts +0 -35
  167. package/src/types/index.ts +0 -8
  168. package/src/types/meta.ts +0 -48
  169. package/src/types/psbt.ts +0 -15
  170. package/src/types/script.ts +0 -18
  171. package/src/types/sighash.ts +0 -16
  172. package/src/types/taproot.ts +0 -41
  173. package/src/types/txdata.ts +0 -85
  174. package/src/types/witness.ts +0 -42
@@ -1,6 +1,6 @@
1
- export { P2PKH } from './p2pkh.js';
2
- export { P2SH } from './p2sh.js';
3
- export { P2WPKH } from './p2wpkh.js';
4
- export { P2WSH } from './p2wsh.js';
5
- export { P2TR } from './p2tr.js';
6
- export * from './api.js';
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 '@vbyte/buff';
2
- import type { AddressInfo, ChainNetwork } from '../../types/index.js';
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 '@vbyte/buff';
2
- import { Assert } from '@vbyte/micro-lib';
3
- import { hash160 } from '@vbyte/micro-lib/hash';
4
- import { encode_address } from './encode.js';
5
- import { is_p2pkh_script } from '../../lib/script/lock.js';
6
- import { LOCK_SCRIPT_TYPE } from '../../const.js';
7
- import { get_address_config, get_address_info } from './util.js';
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 = 'main') {
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, 'invalid pubkey size');
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(['76a914', pk_hash, '88ac']);
29
+ return Buff.join(["76a914", pk_hash, "88ac"]);
30
30
  }
31
- function encode_p2pkh_address(script, network = 'main') {
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: 'base58',
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 === 'p2pkh', `address type mismatch: ${parsed.type} !== ${ADDRESS_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 '@vbyte/buff';
2
- import type { AddressInfo, ChainNetwork } from '../../types/index.js';
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;
@@ -1,10 +1,10 @@
1
- import { Buff } from '@vbyte/buff';
2
- import { Assert } from '@vbyte/micro-lib';
3
- import { hash160 } from '@vbyte/micro-lib/hash';
4
- import { encode_address } from './encode.js';
5
- import { is_p2sh_script } from '../../lib/script/lock.js';
6
- import { LOCK_SCRIPT_TYPE } from '../../const.js';
7
- import { get_address_config, get_address_info } from './util.js';
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 = 'main') {
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(['a914', script_hash, '87']);
30
+ return Buff.join(["a914", script_hash, "87"]);
31
31
  }
32
- function encode_p2sh_address(script_pk, network = 'main') {
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: 'base58',
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 === 'p2sh', `address type mismatch: ${parsed.type} !== ${ADDRESS_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 '@vbyte/buff';
2
- import type { AddressInfo, ChainNetwork } from '../../types/index.js';
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;
@@ -1,9 +1,9 @@
1
- import { Buff } from '@vbyte/buff';
2
- import { Assert } from '@vbyte/micro-lib';
3
- import { encode_address } from './encode.js';
4
- import { is_p2tr_script } from '../../lib/script/lock.js';
5
- import { LOCK_SCRIPT_TYPE } from '../../const.js';
6
- import { get_address_config, get_address_info } from './util.js';
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 = 'main') {
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, 'invalid pubkey size');
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(['5120', pubkey]);
27
+ return Buff.join(["5120", pubkey]);
28
28
  }
29
- function encode_p2tr_address(script_pk, network = 'main') {
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: 'bech32m',
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 === 'p2tr', `address type mismatch: ${parsed.type} !== ${ADDRESS_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 '@vbyte/buff';
2
- import type { AddressInfo, ChainNetwork } from '../../types/index.js';
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 '@vbyte/buff';
2
- import { Assert } from '@vbyte/micro-lib';
3
- import { hash160 } from '@vbyte/micro-lib/hash';
4
- import { encode_address } from './encode.js';
5
- import { is_p2wpkh_script } from '../../lib/script/lock.js';
6
- import { LOCK_SCRIPT_TYPE } from '../../const.js';
7
- import { get_address_config, get_address_info } from './util.js';
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 = 'main') {
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, 'invalid pubkey size');
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(['0014', pk_hash]);
29
+ return Buff.join(["0014", pk_hash]);
30
30
  }
31
- function encode_p2wpkh_address(script_pk, network = 'main') {
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: 'bech32',
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 === 'p2wpkh', `address type mismatch: ${parsed.type} !== ${ADDRESS_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 '@vbyte/buff';
2
- import type { AddressInfo, ChainNetwork } from '../../types/index.js';
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 '@vbyte/buff';
2
- import { Assert } from '@vbyte/micro-lib';
3
- import { sha256 } from '@vbyte/micro-lib/hash';
4
- import { encode_address } from './encode.js';
5
- import { is_p2wsh_script } from '../../lib/script/lock.js';
6
- import { LOCK_SCRIPT_TYPE } from '../../const.js';
7
- import { get_address_config, get_address_info } from './util.js';
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 = 'main') {
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(['0020', script_hash]);
28
+ return Buff.join(["0020", script_hash]);
29
29
  }
30
- function encode_p2wsh_address(script_pk, network = 'main') {
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: 'bech32',
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 === 'p2wsh', `address type mismatch: ${parsed.type} !== ${ADDRESS_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 '../../types/index.js';
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 'p2pkh':
3
+ case "p2pkh":
4
4
  return get_p2pkh_script(script_key);
5
- case 'p2sh':
5
+ case "p2sh":
6
6
  return get_p2sh_script(script_key);
7
- case 'p2wpkh':
7
+ case "p2wpkh":
8
8
  return get_p2w_pkh_script(script_key);
9
- case 'p2wsh':
9
+ case "p2wsh":
10
10
  return get_p2w_sh_script(script_key);
11
- case 'p2tr':
11
+ case "p2tr":
12
12
  return get_p2tr_script(script_key);
13
13
  default:
14
- throw new Error('unrecognized script type: ' + script_type);
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: '76a914' + script_key + '88ac',
20
- asm: ['OP_DUP', 'OP_HASH160', script_key, 'OP_EQUALVERIFY', 'OP_CHECKSIG']
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: 'a914' + script_key + '87',
26
- asm: ['OP_HASH160', script_key, 'OP_EQUAL']
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: '0014' + script_key,
32
- asm: ['OP_0', script_key]
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: '0020' + script_key,
38
- asm: ['OP_0', script_key]
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: '5120' + script_key,
44
- asm: ['OP_1', script_key]
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 '../../types/index.js';
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;
@@ -1,24 +1,24 @@
1
- import { Buff } from '@vbyte/buff';
2
- import { decode_address } from './encode.js';
3
- import { get_address_script } from './script.js';
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
- ['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]
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.uint(dec.data).hex;
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('address configuration is invalid');
52
+ throw new Error("address configuration is invalid");
53
53
  }
@@ -1,4 +1,4 @@
1
- export * from './locktime.js';
2
- export * from './ref.js';
3
- export * from './scribe.js';
4
- export * from './sequence.js';
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
- export * from './locktime.js';
2
- export * from './ref.js';
3
- export * from './scribe.js';
4
- export * from './sequence.js';
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 type { LocktimeData } from '../../types/index.js';
1
+ import type { LocktimeData } from "../../types/index.js";
2
2
  export declare namespace LocktimeField {
3
3
  const encode: typeof encode_locktime;
4
4
  const decode: typeof decode_locktime;
@@ -1,4 +1,4 @@
1
- import { Assert } from '@vbyte/micro-lib';
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 'timelock':
11
- Assert.ok(locktime.stamp >= LOCKTIME_THRESHOLD, 'Invalid timestamp');
10
+ case "timelock":
11
+ Assert.ok(locktime.stamp >= LOCKTIME_THRESHOLD, "Invalid timestamp");
12
12
  return locktime.stamp;
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');
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('Invalid locktime type');
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: 'heightlock',
28
- height: locktime
27
+ type: "heightlock",
28
+ height: locktime,
29
29
  };
30
30
  }
31
31
  else {
32
32
  return {
33
- type: 'timelock',
34
- stamp: locktime
33
+ type: "timelock",
34
+ stamp: locktime,
35
35
  };
36
36
  }
37
37
  }
@@ -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('i');
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 { block_height: parseInt(block_height), block_index: parseInt(block_index) };
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 '@vbyte/buff';
2
- import type { InscriptionData } from '../../types/index.js';
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;