@vbyte/btc-dev 1.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 (205) hide show
  1. package/LICENSE +121 -0
  2. package/README.md +5 -0
  3. package/dist/class/index.d.ts +5 -0
  4. package/dist/class/index.js +5 -0
  5. package/dist/class/signer.d.ts +18 -0
  6. package/dist/class/signer.js +32 -0
  7. package/dist/class/tx.d.ts +38 -0
  8. package/dist/class/tx.js +73 -0
  9. package/dist/class/txin.d.ts +29 -0
  10. package/dist/class/txin.js +68 -0
  11. package/dist/class/txout.d.ts +18 -0
  12. package/dist/class/txout.js +38 -0
  13. package/dist/class/witness.d.ts +20 -0
  14. package/dist/class/witness.js +57 -0
  15. package/dist/const.d.ts +22 -0
  16. package/dist/const.js +36 -0
  17. package/dist/index.d.ts +11 -0
  18. package/dist/index.js +10 -0
  19. package/dist/lib/address/encode.d.ts +3 -0
  20. package/dist/lib/address/encode.js +79 -0
  21. package/dist/lib/address/index.d.ts +20 -0
  22. package/dist/lib/address/index.js +21 -0
  23. package/dist/lib/address/p2pkh.d.ts +10 -0
  24. package/dist/lib/address/p2pkh.js +33 -0
  25. package/dist/lib/address/p2sh.d.ts +10 -0
  26. package/dist/lib/address/p2sh.js +33 -0
  27. package/dist/lib/address/p2tr.d.ts +8 -0
  28. package/dist/lib/address/p2tr.js +26 -0
  29. package/dist/lib/address/p2wpkh.d.ts +10 -0
  30. package/dist/lib/address/p2wpkh.js +34 -0
  31. package/dist/lib/address/p2wsh.d.ts +10 -0
  32. package/dist/lib/address/p2wsh.js +33 -0
  33. package/dist/lib/address/script.d.ts +5 -0
  34. package/dist/lib/address/script.js +46 -0
  35. package/dist/lib/address/util.d.ts +4 -0
  36. package/dist/lib/address/util.js +57 -0
  37. package/dist/lib/meta/index.d.ts +2 -0
  38. package/dist/lib/meta/index.js +2 -0
  39. package/dist/lib/meta/pointer.d.ts +42 -0
  40. package/dist/lib/meta/pointer.js +69 -0
  41. package/dist/lib/meta/scribe.d.ts +7 -0
  42. package/dist/lib/meta/scribe.js +192 -0
  43. package/dist/lib/psbt/encoder.d.ts +5 -0
  44. package/dist/lib/psbt/encoder.js +21 -0
  45. package/dist/lib/psbt/index.d.ts +4 -0
  46. package/dist/lib/psbt/index.js +4 -0
  47. package/dist/lib/psbt/meta.d.ts +3 -0
  48. package/dist/lib/psbt/meta.js +11 -0
  49. package/dist/lib/psbt/util.d.ts +5 -0
  50. package/dist/lib/psbt/util.js +44 -0
  51. package/dist/lib/psbt/validate.d.ts +2 -0
  52. package/dist/lib/psbt/validate.js +11 -0
  53. package/dist/lib/script/decode.d.ts +2 -0
  54. package/dist/lib/script/decode.js +55 -0
  55. package/dist/lib/script/encode.d.ts +6 -0
  56. package/dist/lib/script/encode.js +80 -0
  57. package/dist/lib/script/index.d.ts +126 -0
  58. package/dist/lib/script/index.js +17 -0
  59. package/dist/lib/script/util.d.ts +2 -0
  60. package/dist/lib/script/util.js +10 -0
  61. package/dist/lib/script/words.d.ts +116 -0
  62. package/dist/lib/script/words.js +164 -0
  63. package/dist/lib/sighash/index.d.ts +5 -0
  64. package/dist/lib/sighash/index.js +5 -0
  65. package/dist/lib/sighash/segwit.d.ts +3 -0
  66. package/dist/lib/sighash/segwit.js +89 -0
  67. package/dist/lib/sighash/sign.d.ts +3 -0
  68. package/dist/lib/sighash/sign.js +20 -0
  69. package/dist/lib/sighash/taproot.d.ts +9 -0
  70. package/dist/lib/sighash/taproot.js +124 -0
  71. package/dist/lib/sighash/util.d.ts +3 -0
  72. package/dist/lib/sighash/util.js +16 -0
  73. package/dist/lib/sighash/verify.d.ts +1 -0
  74. package/dist/lib/sighash/verify.js +1 -0
  75. package/dist/lib/taproot/cblock.d.ts +3 -0
  76. package/dist/lib/taproot/cblock.js +55 -0
  77. package/dist/lib/taproot/encode.d.ts +6 -0
  78. package/dist/lib/taproot/encode.js +26 -0
  79. package/dist/lib/taproot/index.d.ts +4 -0
  80. package/dist/lib/taproot/index.js +4 -0
  81. package/dist/lib/taproot/parse.d.ts +11 -0
  82. package/dist/lib/taproot/parse.js +47 -0
  83. package/dist/lib/taproot/tree.d.ts +3 -0
  84. package/dist/lib/taproot/tree.js +49 -0
  85. package/dist/lib/tx/create.d.ts +6 -0
  86. package/dist/lib/tx/create.js +54 -0
  87. package/dist/lib/tx/decode.d.ts +9 -0
  88. package/dist/lib/tx/decode.js +109 -0
  89. package/dist/lib/tx/encode.d.ts +15 -0
  90. package/dist/lib/tx/encode.js +94 -0
  91. package/dist/lib/tx/index.d.ts +10 -0
  92. package/dist/lib/tx/index.js +10 -0
  93. package/dist/lib/tx/locktime.d.ts +7 -0
  94. package/dist/lib/tx/locktime.js +37 -0
  95. package/dist/lib/tx/meta.d.ts +8 -0
  96. package/dist/lib/tx/meta.js +48 -0
  97. package/dist/lib/tx/parse.d.ts +2 -0
  98. package/dist/lib/tx/parse.js +12 -0
  99. package/dist/lib/tx/sequence.d.ts +7 -0
  100. package/dist/lib/tx/sequence.js +65 -0
  101. package/dist/lib/tx/size.d.ts +10 -0
  102. package/dist/lib/tx/size.js +48 -0
  103. package/dist/lib/tx/validate.d.ts +7 -0
  104. package/dist/lib/tx/validate.js +21 -0
  105. package/dist/lib/tx/witness.d.ts +3 -0
  106. package/dist/lib/tx/witness.js +85 -0
  107. package/dist/main.cjs +14625 -0
  108. package/dist/main.cjs.map +1 -0
  109. package/dist/module.mjs +14610 -0
  110. package/dist/module.mjs.map +1 -0
  111. package/dist/package.json +106 -0
  112. package/dist/schema/index.d.ts +2 -0
  113. package/dist/schema/index.js +2 -0
  114. package/dist/schema/taproot.d.ts +18 -0
  115. package/dist/schema/taproot.js +9 -0
  116. package/dist/schema/tx.d.ts +278 -0
  117. package/dist/schema/tx.js +35 -0
  118. package/dist/script.js +15 -0
  119. package/dist/script.js.map +1 -0
  120. package/dist/types/address.d.ts +34 -0
  121. package/dist/types/address.js +1 -0
  122. package/dist/types/index.d.ts +9 -0
  123. package/dist/types/index.js +9 -0
  124. package/dist/types/meta.d.ts +10 -0
  125. package/dist/types/meta.js +1 -0
  126. package/dist/types/psbt.d.ts +9 -0
  127. package/dist/types/psbt.js +1 -0
  128. package/dist/types/sighash.d.ts +14 -0
  129. package/dist/types/sighash.js +1 -0
  130. package/dist/types/taproot.d.ts +35 -0
  131. package/dist/types/taproot.js +1 -0
  132. package/dist/types/transaction.d.ts +81 -0
  133. package/dist/types/transaction.js +1 -0
  134. package/dist/types/txdata.d.ts +45 -0
  135. package/dist/types/txdata.js +1 -0
  136. package/dist/types/txmeta.d.ts +19 -0
  137. package/dist/types/txmeta.js +1 -0
  138. package/dist/types/witness.d.ts +30 -0
  139. package/dist/types/witness.js +1 -0
  140. package/package.json +106 -0
  141. package/src/class/index.ts +5 -0
  142. package/src/class/signer.ts +47 -0
  143. package/src/class/tx.ts +118 -0
  144. package/src/class/txin.ts +95 -0
  145. package/src/class/txout.ts +57 -0
  146. package/src/class/witness.ts +85 -0
  147. package/src/const.ts +43 -0
  148. package/src/index.ts +14 -0
  149. package/src/lib/address/encode.ts +183 -0
  150. package/src/lib/address/index.ts +24 -0
  151. package/src/lib/address/p2pkh.ts +65 -0
  152. package/src/lib/address/p2sh.ts +65 -0
  153. package/src/lib/address/p2tr.ts +51 -0
  154. package/src/lib/address/p2wpkh.ts +67 -0
  155. package/src/lib/address/p2wsh.ts +65 -0
  156. package/src/lib/address/script.ts +63 -0
  157. package/src/lib/address/util.ts +102 -0
  158. package/src/lib/meta/index.ts +2 -0
  159. package/src/lib/meta/pointer.ts +107 -0
  160. package/src/lib/meta/scribe.ts +251 -0
  161. package/src/lib/psbt/encoder.ts +24 -0
  162. package/src/lib/psbt/index.ts +4 -0
  163. package/src/lib/psbt/meta.ts +15 -0
  164. package/src/lib/psbt/util.ts +62 -0
  165. package/src/lib/psbt/validate.ts +18 -0
  166. package/src/lib/script/decode.ts +75 -0
  167. package/src/lib/script/encode.ts +130 -0
  168. package/src/lib/script/index.ts +26 -0
  169. package/src/lib/script/util.ts +78 -0
  170. package/src/lib/script/words.ts +182 -0
  171. package/src/lib/sighash/index.ts +5 -0
  172. package/src/lib/sighash/segwit.ts +152 -0
  173. package/src/lib/sighash/sign.ts +35 -0
  174. package/src/lib/sighash/taproot.ts +236 -0
  175. package/src/lib/sighash/util.ts +29 -0
  176. package/src/lib/sighash/verify.ts +83 -0
  177. package/src/lib/taproot/cblock.ts +95 -0
  178. package/src/lib/taproot/encode.ts +49 -0
  179. package/src/lib/taproot/index.ts +4 -0
  180. package/src/lib/taproot/parse.ts +65 -0
  181. package/src/lib/taproot/tree.ts +94 -0
  182. package/src/lib/tx/create.ts +82 -0
  183. package/src/lib/tx/decode.ts +145 -0
  184. package/src/lib/tx/encode.ts +154 -0
  185. package/src/lib/tx/index.ts +10 -0
  186. package/src/lib/tx/locktime.ts +57 -0
  187. package/src/lib/tx/meta.ts +73 -0
  188. package/src/lib/tx/parse.ts +16 -0
  189. package/src/lib/tx/sequence.ts +146 -0
  190. package/src/lib/tx/size.ts +77 -0
  191. package/src/lib/tx/validate.ts +36 -0
  192. package/src/lib/tx/witness.ts +122 -0
  193. package/src/schema/index.ts +2 -0
  194. package/src/schema/taproot.ts +12 -0
  195. package/src/schema/tx.ts +42 -0
  196. package/src/types/address.ts +39 -0
  197. package/src/types/index.ts +9 -0
  198. package/src/types/meta.ts +10 -0
  199. package/src/types/psbt.ts +15 -0
  200. package/src/types/sighash.ts +16 -0
  201. package/src/types/taproot.ts +40 -0
  202. package/src/types/transaction.ts +98 -0
  203. package/src/types/txdata.ts +53 -0
  204. package/src/types/txmeta.ts +25 -0
  205. package/src/types/witness.ts +36 -0
@@ -0,0 +1,34 @@
1
+ export type AddressFormat = 'base58' | 'bech32' | 'bech32m';
2
+ export type AddressType = 'p2pkh' | 'p2sh' | 'p2w-pkh' | 'p2w-sh' | 'p2tr';
3
+ export type ChainNetwork = 'main' | 'testnet' | 'regtest';
4
+ export type AddressData = AddressContext & ScriptData;
5
+ export type AddressConfigEntry = [
6
+ prefix: string,
7
+ type: AddressType,
8
+ network: ChainNetwork,
9
+ size: number,
10
+ format: AddressFormat,
11
+ version: number
12
+ ];
13
+ export interface DecodedAddress {
14
+ format: AddressFormat;
15
+ data: Uint8Array;
16
+ prefix?: string;
17
+ version?: number;
18
+ }
19
+ export interface AddressConfig {
20
+ format: AddressFormat;
21
+ network: ChainNetwork;
22
+ prefix: string;
23
+ size: number;
24
+ type: AddressType;
25
+ version: number;
26
+ }
27
+ export interface AddressContext extends AddressConfig {
28
+ data: Uint8Array;
29
+ hex: string;
30
+ }
31
+ export interface ScriptData {
32
+ script_asm: string[];
33
+ script_hex: string;
34
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ export * from './address.js';
2
+ export * from './meta.js';
3
+ export * from './psbt.js';
4
+ export * from './sighash.js';
5
+ export * from './taproot.js';
6
+ export * from './transaction.js';
7
+ export * from './txdata.js';
8
+ export * from './txmeta.js';
9
+ export * from './witness.js';
@@ -0,0 +1,9 @@
1
+ export * from './address.js';
2
+ export * from './meta.js';
3
+ export * from './psbt.js';
4
+ export * from './sighash.js';
5
+ export * from './taproot.js';
6
+ export * from './transaction.js';
7
+ export * from './txdata.js';
8
+ export * from './txmeta.js';
9
+ export * from './witness.js';
@@ -0,0 +1,10 @@
1
+ export interface InscriptionData {
2
+ content?: string;
3
+ delegate?: string;
4
+ mimetype?: string;
5
+ opcode?: number;
6
+ parent?: string;
7
+ pointer?: number;
8
+ ref?: string;
9
+ rune?: string;
10
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { Transaction } from '@scure/btc-signer';
2
+ import type { TransactionInput, TransactionOutput } from '@scure/btc-signer/psbt';
3
+ export type PSBTData = Transaction;
4
+ export type PSBTInput = TransactionInput;
5
+ export type PSBTOutput = TransactionOutput;
6
+ export interface PSBTPrevouts {
7
+ amounts: bigint[];
8
+ scripts: Uint8Array[];
9
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ import { TxInput } from './txdata.js';
2
+ export type SigHashType = 'segwit' | 'taproot';
3
+ export interface SigHashOptions {
4
+ extension?: string;
5
+ extflag?: number;
6
+ txindex?: number;
7
+ key_version?: number;
8
+ pubkey?: string;
9
+ script?: string;
10
+ separator_pos?: number;
11
+ sigflag?: number;
12
+ throws?: boolean;
13
+ txinput?: TxInput;
14
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,35 @@
1
+ type Bytes = string | Uint8Array;
2
+ export type TapTree = Array<Bytes | Bytes[]>;
3
+ export type MerkleProof = [
4
+ root: string,
5
+ target: string | undefined,
6
+ path: string[]
7
+ ];
8
+ export interface TaprootConfig {
9
+ pubkey: Bytes;
10
+ leaves?: TapTree;
11
+ target?: Bytes;
12
+ version?: number;
13
+ }
14
+ export interface TaprootContext {
15
+ cblock: string;
16
+ int_key: string;
17
+ parity: number;
18
+ taproot: string | null;
19
+ tapkey: string;
20
+ taptweak: string;
21
+ }
22
+ export interface ControlBlock {
23
+ int_key: string;
24
+ parity: number;
25
+ path: string[];
26
+ version: number;
27
+ }
28
+ export interface ProofData {
29
+ cblock: ControlBlock;
30
+ params: string[];
31
+ script: string;
32
+ tapkey: string;
33
+ tweak: string;
34
+ }
35
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,81 @@
1
+ import { TxOutput } from './txdata.js';
2
+ import { LocktimeInfo, SequenceInfo } from './txmeta.js';
3
+ import type { WitnessType, WitnessVersion } from './witness.js';
4
+ export type TxOutputType = WitnessType | 'p2pkh' | 'p2sh' | 'opreturn';
5
+ export interface TxOutputInfo {
6
+ type: TxOutputType;
7
+ version: WitnessVersion;
8
+ }
9
+ export interface TxInputInfo {
10
+ type: WitnessType;
11
+ version: WitnessVersion;
12
+ }
13
+ export interface LocktimeField {
14
+ hex: string;
15
+ data: LocktimeInfo | null;
16
+ value: number;
17
+ }
18
+ export interface SequenceField {
19
+ hex: string;
20
+ data: SequenceInfo | null;
21
+ value: number;
22
+ }
23
+ export interface ScriptField {
24
+ asm: string[];
25
+ hex: string;
26
+ }
27
+ export interface TxSize {
28
+ base: number;
29
+ real: number;
30
+ weight: number;
31
+ vsize: number;
32
+ }
33
+ export interface TxValue {
34
+ fees: bigint;
35
+ vin: bigint;
36
+ vout: bigint;
37
+ }
38
+ export interface WitnessSize {
39
+ size: number;
40
+ vsize: number;
41
+ }
42
+ export interface TransactionData {
43
+ hash: string;
44
+ locktime: LocktimeField;
45
+ return: TxOutput | null;
46
+ size: TxSize;
47
+ spends: TxOutputField[];
48
+ txid: string;
49
+ value: TxValue;
50
+ version: number;
51
+ vin: TxInputField[];
52
+ vout: TxOutputField[];
53
+ }
54
+ export interface WitnessField {
55
+ annex: string | null;
56
+ cblock: string | null;
57
+ params: string[];
58
+ script: ScriptField | null;
59
+ size: number;
60
+ stack: string[];
61
+ type: WitnessType;
62
+ version: WitnessVersion;
63
+ vsize: number;
64
+ }
65
+ export interface TxInputField {
66
+ coinbase?: string | null;
67
+ prevout?: TxOutputField | null;
68
+ script_sig?: ScriptField | null;
69
+ sequence: SequenceField;
70
+ size: number;
71
+ txid: string;
72
+ vout: number;
73
+ witness?: WitnessField | null;
74
+ }
75
+ export interface TxOutputField {
76
+ script_pk: ScriptField;
77
+ size: number;
78
+ type: TxOutputType;
79
+ value: bigint;
80
+ version: WitnessVersion | null;
81
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,45 @@
1
+ export type TxInput = CoinbaseInput | SpendInput | VirtualInput;
2
+ export interface TxOutpoint {
3
+ txid: string;
4
+ vout: number;
5
+ }
6
+ export interface TxInputTemplate extends TxOutpoint {
7
+ coinbase?: string | null;
8
+ prevout?: TxOutput | null;
9
+ script_sig?: string | null;
10
+ sequence?: number;
11
+ witness?: string[];
12
+ }
13
+ export interface CoinbaseInput extends TxOutpoint {
14
+ coinbase: string;
15
+ prevout: null;
16
+ script_sig: null;
17
+ sequence: number;
18
+ witness: string[];
19
+ }
20
+ export interface VirtualInput extends TxOutpoint {
21
+ coinbase: null;
22
+ prevout: TxOutput | null;
23
+ script_sig: string | null;
24
+ sequence: number;
25
+ witness: string[];
26
+ }
27
+ export interface SpendInput extends VirtualInput {
28
+ prevout: TxOutput;
29
+ }
30
+ export interface TxOutput {
31
+ script_pk: string;
32
+ value: bigint;
33
+ }
34
+ export interface TxTemplate {
35
+ locktime?: number;
36
+ vin?: TxInputTemplate[];
37
+ vout?: TxOutput[];
38
+ version?: number;
39
+ }
40
+ export interface TxData {
41
+ locktime: number;
42
+ vin: TxInput[];
43
+ vout: TxOutput[];
44
+ version: number;
45
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ export type LocktimeInfo = LocktimeStamp | LocktimeHeight;
2
+ export type SequenceConfig = Partial<SequenceInfo>;
3
+ export type SequenceInfo = SequenceHeightLock | SequenceStampLock;
4
+ export interface LocktimeStamp {
5
+ type: 'timelock';
6
+ stamp: number;
7
+ }
8
+ export interface LocktimeHeight {
9
+ type: 'heightlock';
10
+ height: number;
11
+ }
12
+ export interface SequenceStampLock {
13
+ stamp: number;
14
+ mode: 'stamp';
15
+ }
16
+ export interface SequenceHeightLock {
17
+ height: number;
18
+ mode: 'height';
19
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,30 @@
1
+ export type WitnessContext = WitnessInfo | TaprootScript | SegwitScript | TaprootSpend | SegwitSpend;
2
+ export type WitnessVersion = number | null;
3
+ export type WitnessType = 'p2w-pkh' | 'p2w-sh' | 'p2tr-pk' | 'p2tr-ts' | 'unknown';
4
+ export interface WitnessInfo {
5
+ annex: string | null;
6
+ cblock: string | null;
7
+ params: string[];
8
+ script: string | null;
9
+ type: WitnessType;
10
+ version: WitnessVersion;
11
+ }
12
+ export interface TaprootScript extends WitnessInfo {
13
+ cblock: string;
14
+ script: string;
15
+ type: 'p2tr-ts';
16
+ version: 1;
17
+ }
18
+ export interface SegwitScript extends WitnessInfo {
19
+ script: string;
20
+ type: 'p2w-sh';
21
+ version: 0;
22
+ }
23
+ export interface TaprootSpend extends WitnessInfo {
24
+ type: 'p2tr-pk';
25
+ version: 1;
26
+ }
27
+ export interface SegwitSpend extends WitnessInfo {
28
+ type: 'p2w-pkh';
29
+ version: 0;
30
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,106 @@
1
+ {
2
+ "name": "@vbyte/btc-dev",
3
+ "version": "1.0.0",
4
+ "description": "Batteries-included toolset for plebian bitcoin development",
5
+ "type": "module",
6
+ "keywords": [
7
+ "bitcoin",
8
+ "blockchain",
9
+ "psbt",
10
+ "transaction",
11
+ "segwit",
12
+ "taproot"
13
+ ],
14
+ "author": "Christopher Scott",
15
+ "license": "CC-BY-1.0",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/cmdruid/btc-dev.git"
19
+ },
20
+ "publishConfig": {
21
+ "registry": "https://registry.npmjs.org",
22
+ "access": "public"
23
+ },
24
+ "files": [
25
+ "README.md",
26
+ "LICENSE",
27
+ "dist",
28
+ "src"
29
+ ],
30
+ "main": "./dist/main.cjs",
31
+ "module": "./dist/index.js",
32
+ "unpkg": "./dist/script.js",
33
+ "types": "./dist/types/index.d.ts",
34
+ "exports": {
35
+ ".": {
36
+ "types": "./dist/types/index.d.ts",
37
+ "import": "./dist/index.js",
38
+ "require": "./dist/main.cjs",
39
+ "default": "./dist/index.js"
40
+ },
41
+ "./address": {
42
+ "types": "./dist/lib/address/index.d.ts",
43
+ "import": "./dist/lib/address/index.js"
44
+ },
45
+ "./class": {
46
+ "types": "./dist/class/index.d.ts",
47
+ "import": "./dist/class/index.js"
48
+ },
49
+ "./meta": {
50
+ "types": "./dist/lib/meta.d.ts",
51
+ "import": "./dist/lib/meta.js"
52
+ },
53
+ "./psbt": {
54
+ "types": "./dist/lib/psbt/index.d.ts",
55
+ "import": "./dist/lib/psbt/index.js"
56
+ },
57
+ "./script": {
58
+ "types": "./dist/lib/script/index.d.ts",
59
+ "import": "./dist/lib/script/index.js"
60
+ },
61
+ "./sighash": {
62
+ "types": "./dist/lib/sighash/index.d.ts",
63
+ "import": "./dist/lib/sighash/index.js"
64
+ },
65
+ "./taproot": {
66
+ "types": "./dist/lib/taproot/index.d.ts",
67
+ "import": "./dist/lib/taproot/index.js"
68
+ },
69
+ "./tx": {
70
+ "types": "./dist/lib/tx/index.d.ts",
71
+ "import": "./dist/lib/tx/index.js"
72
+ }
73
+ },
74
+ "scripts": {
75
+ "build": "./scripts/build.sh",
76
+ "package": "npm test | faucet && npm run build",
77
+ "release": "./scripts/release.sh",
78
+ "scratch": "npm run script test/scratch.ts",
79
+ "script": "tsx --tsconfig ./test/tsconfig.json",
80
+ "test": "npm run script test/src/tape.ts"
81
+ },
82
+ "dependencies": {
83
+ "@noble/curves": "^1.9.2",
84
+ "@noble/hashes": "^1.8.0",
85
+ "@scure/btc-signer": "^1.8.1",
86
+ "@vbyte/buff": "^1.0.2",
87
+ "@vbyte/micro-lib": "^1.0.11",
88
+ "zod": "^3.25.69"
89
+ },
90
+ "devDependencies": {
91
+ "@cmdcode/core-cmd": "^1.6.5",
92
+ "@rollup/plugin-commonjs": "^28.0.6",
93
+ "@rollup/plugin-json": "^6.1.0",
94
+ "@rollup/plugin-node-resolve": "^16.0.1",
95
+ "@rollup/plugin-terser": "^0.4.4",
96
+ "@rollup/plugin-typescript": "^12.1.4",
97
+ "@types/node": "^24.0.10",
98
+ "@types/tape": "^5.8.1",
99
+ "faucet": "^0.0.4",
100
+ "rollup": "^4.44.1",
101
+ "tape": "^5.9.0",
102
+ "tslib": "^2.8.1",
103
+ "tsx": "^4.20.3",
104
+ "typescript": "^5.8.3"
105
+ }
106
+ }
@@ -0,0 +1,5 @@
1
+ export * from './signer.js'
2
+ export * from './tx.js'
3
+ export * from './txin.js'
4
+ export * from './txout.js'
5
+ export * from './witness.js'
@@ -0,0 +1,47 @@
1
+ import { Buff, Bytes } from '@vbyte/buff'
2
+ import { ECC } from '@vbyte/micro-lib'
3
+
4
+ import {
5
+ sign_segwit_tx,
6
+ sign_taproot_tx
7
+ } from '@/lib/sighash/sign.js'
8
+
9
+ import type {
10
+ SigHashOptions,
11
+ TxData
12
+ } from '@/types/index.js'
13
+
14
+ export class TxSigner {
15
+ private readonly _seckey : string
16
+
17
+ constructor (seckey : Bytes) {
18
+ this._seckey = Buff.bytes(seckey).hex
19
+ }
20
+
21
+ get pubkey () {
22
+ return {
23
+ segwit : ECC.get_pubkey(this._seckey, 'ecdsa'),
24
+ taproot : ECC.get_pubkey(this._seckey, 'bip340')
25
+ }
26
+ }
27
+
28
+ get sign_msg () {
29
+ return {
30
+ ecdsa : (msg : Bytes) => {
31
+ const bytes = Buff.bytes(msg)
32
+ return ECC.sign_ecdsa(this._seckey, bytes)
33
+ },
34
+ bip340 : (msg : Bytes) => {
35
+ const bytes = Buff.bytes(msg)
36
+ return ECC.sign_bip340(this._seckey, bytes)
37
+ }
38
+ }
39
+ }
40
+
41
+ get sign_tx () {
42
+ return {
43
+ segwit : (tx : TxData, options : SigHashOptions) => sign_segwit_tx(this._seckey, tx, options),
44
+ taproot : (tx : TxData, options : SigHashOptions) => sign_taproot_tx(this._seckey, tx, options)
45
+ }
46
+ }
47
+ }
@@ -0,0 +1,118 @@
1
+ import { TransactionInput } from './txin.js'
2
+ import { TransactionOutput } from './txout.js'
3
+
4
+ import {
5
+ decode_tx_data,
6
+ get_txid,
7
+ is_return_script,
8
+ parse_tx_data,
9
+ Locktime,
10
+ get_txsize,
11
+ get_tx_value,
12
+ get_txhash,
13
+ encode_tx_locktime,
14
+ } from '@/lib/tx/index.js'
15
+
16
+ import type {
17
+ TxData,
18
+ TxTemplate,
19
+ TxSize,
20
+ TxValue,
21
+ TransactionData
22
+ } from '@/types/index.js'
23
+
24
+ export class Transaction {
25
+
26
+ private readonly _size : TxSize
27
+ private readonly _tx : TxData
28
+ private readonly _hash : string
29
+ private readonly _value : TxValue
30
+ private readonly _vin : TransactionInput[]
31
+ private readonly _vout : TransactionOutput[]
32
+
33
+ constructor (txdata : string | TxData | TxTemplate) {
34
+ this._tx = (typeof txdata !== 'string')
35
+ ? parse_tx_data(txdata)
36
+ : decode_tx_data(txdata)
37
+
38
+ this._vin = this._tx.vin.map(txin => new TransactionInput(txin))
39
+ this._vout = this._tx.vout.map(txout => new TransactionOutput(txout))
40
+
41
+ this._size = get_txsize(this._tx)
42
+ this._hash = get_txhash(this._tx)
43
+ this._value = get_tx_value(this._tx)
44
+ }
45
+
46
+ get data () : TransactionData {
47
+ return {
48
+ hash : this.hash,
49
+ locktime : this.locktime,
50
+ return : this.return,
51
+ size : this.size,
52
+ spends : this.spends,
53
+ txid : this.txid,
54
+ value : this.value,
55
+ version : this.version,
56
+ vin : this.vin.map(txin => txin.data),
57
+ vout : this.vout.map(txout => txout.data)
58
+ }
59
+ }
60
+
61
+ get hash () : string {
62
+ return this._hash
63
+ }
64
+
65
+ get locktime () {
66
+ return {
67
+ hex : encode_tx_locktime(this._tx.locktime).hex,
68
+ data : Locktime.decode(this._tx.locktime),
69
+ value : this._tx.locktime
70
+ }
71
+ }
72
+
73
+ get return () {
74
+ return this._tx.vout.find(txout => is_return_script(txout.script_pk)) || null
75
+ }
76
+
77
+ get size () {
78
+ return {
79
+ ...this._size,
80
+ segwit : this._vin.reduce((acc, txin) => acc + (txin.witness?.vsize ?? 0), 0),
81
+ vin : this._vin.reduce((acc, txin) => acc + txin.size, 0),
82
+ vout : this._vout.reduce((acc, txout) => acc + txout.size, 0),
83
+ witness : this._vin.reduce((acc, txin) => acc + (txin.witness?.size ?? 0), 0)
84
+ }
85
+ }
86
+
87
+ get spends () : TransactionOutput[] {
88
+ return this._tx.vin
89
+ .filter(txin => txin.prevout !== null)
90
+ .map(txin => new TransactionOutput(txin.prevout!))
91
+ }
92
+
93
+ get txid () : string {
94
+ return get_txid(this._tx)
95
+ }
96
+
97
+ get value () {
98
+ return this._value
99
+ }
100
+
101
+ get version () : number {
102
+ return this._tx.version
103
+ }
104
+
105
+ get vin () : TransactionInput[] {
106
+ return this._vin
107
+ }
108
+
109
+ get vout () : TransactionOutput[] {
110
+ return this._vout
111
+ }
112
+
113
+ toJSON () { return this.data }
114
+ toString () { return JSON.stringify(this.data) }
115
+ }
116
+
117
+
118
+