@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.
- package/LICENSE +121 -0
- package/README.md +5 -0
- package/dist/class/index.d.ts +5 -0
- package/dist/class/index.js +5 -0
- package/dist/class/signer.d.ts +18 -0
- package/dist/class/signer.js +32 -0
- package/dist/class/tx.d.ts +38 -0
- package/dist/class/tx.js +73 -0
- package/dist/class/txin.d.ts +29 -0
- package/dist/class/txin.js +68 -0
- package/dist/class/txout.d.ts +18 -0
- package/dist/class/txout.js +38 -0
- package/dist/class/witness.d.ts +20 -0
- package/dist/class/witness.js +57 -0
- package/dist/const.d.ts +22 -0
- package/dist/const.js +36 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +10 -0
- package/dist/lib/address/encode.d.ts +3 -0
- package/dist/lib/address/encode.js +79 -0
- package/dist/lib/address/index.d.ts +20 -0
- package/dist/lib/address/index.js +21 -0
- package/dist/lib/address/p2pkh.d.ts +10 -0
- package/dist/lib/address/p2pkh.js +33 -0
- package/dist/lib/address/p2sh.d.ts +10 -0
- package/dist/lib/address/p2sh.js +33 -0
- package/dist/lib/address/p2tr.d.ts +8 -0
- package/dist/lib/address/p2tr.js +26 -0
- package/dist/lib/address/p2wpkh.d.ts +10 -0
- package/dist/lib/address/p2wpkh.js +34 -0
- package/dist/lib/address/p2wsh.d.ts +10 -0
- package/dist/lib/address/p2wsh.js +33 -0
- package/dist/lib/address/script.d.ts +5 -0
- package/dist/lib/address/script.js +46 -0
- package/dist/lib/address/util.d.ts +4 -0
- package/dist/lib/address/util.js +57 -0
- package/dist/lib/meta/index.d.ts +2 -0
- package/dist/lib/meta/index.js +2 -0
- package/dist/lib/meta/pointer.d.ts +42 -0
- package/dist/lib/meta/pointer.js +69 -0
- package/dist/lib/meta/scribe.d.ts +7 -0
- package/dist/lib/meta/scribe.js +192 -0
- package/dist/lib/psbt/encoder.d.ts +5 -0
- package/dist/lib/psbt/encoder.js +21 -0
- package/dist/lib/psbt/index.d.ts +4 -0
- package/dist/lib/psbt/index.js +4 -0
- package/dist/lib/psbt/meta.d.ts +3 -0
- package/dist/lib/psbt/meta.js +11 -0
- package/dist/lib/psbt/util.d.ts +5 -0
- package/dist/lib/psbt/util.js +44 -0
- package/dist/lib/psbt/validate.d.ts +2 -0
- package/dist/lib/psbt/validate.js +11 -0
- package/dist/lib/script/decode.d.ts +2 -0
- package/dist/lib/script/decode.js +55 -0
- package/dist/lib/script/encode.d.ts +6 -0
- package/dist/lib/script/encode.js +80 -0
- package/dist/lib/script/index.d.ts +126 -0
- package/dist/lib/script/index.js +17 -0
- package/dist/lib/script/util.d.ts +2 -0
- package/dist/lib/script/util.js +10 -0
- package/dist/lib/script/words.d.ts +116 -0
- package/dist/lib/script/words.js +164 -0
- package/dist/lib/sighash/index.d.ts +5 -0
- package/dist/lib/sighash/index.js +5 -0
- package/dist/lib/sighash/segwit.d.ts +3 -0
- package/dist/lib/sighash/segwit.js +89 -0
- package/dist/lib/sighash/sign.d.ts +3 -0
- package/dist/lib/sighash/sign.js +20 -0
- package/dist/lib/sighash/taproot.d.ts +9 -0
- package/dist/lib/sighash/taproot.js +124 -0
- package/dist/lib/sighash/util.d.ts +3 -0
- package/dist/lib/sighash/util.js +16 -0
- package/dist/lib/sighash/verify.d.ts +1 -0
- package/dist/lib/sighash/verify.js +1 -0
- package/dist/lib/taproot/cblock.d.ts +3 -0
- package/dist/lib/taproot/cblock.js +55 -0
- package/dist/lib/taproot/encode.d.ts +6 -0
- package/dist/lib/taproot/encode.js +26 -0
- package/dist/lib/taproot/index.d.ts +4 -0
- package/dist/lib/taproot/index.js +4 -0
- package/dist/lib/taproot/parse.d.ts +11 -0
- package/dist/lib/taproot/parse.js +47 -0
- package/dist/lib/taproot/tree.d.ts +3 -0
- package/dist/lib/taproot/tree.js +49 -0
- package/dist/lib/tx/create.d.ts +6 -0
- package/dist/lib/tx/create.js +54 -0
- package/dist/lib/tx/decode.d.ts +9 -0
- package/dist/lib/tx/decode.js +109 -0
- package/dist/lib/tx/encode.d.ts +15 -0
- package/dist/lib/tx/encode.js +94 -0
- package/dist/lib/tx/index.d.ts +10 -0
- package/dist/lib/tx/index.js +10 -0
- package/dist/lib/tx/locktime.d.ts +7 -0
- package/dist/lib/tx/locktime.js +37 -0
- package/dist/lib/tx/meta.d.ts +8 -0
- package/dist/lib/tx/meta.js +48 -0
- package/dist/lib/tx/parse.d.ts +2 -0
- package/dist/lib/tx/parse.js +12 -0
- package/dist/lib/tx/sequence.d.ts +7 -0
- package/dist/lib/tx/sequence.js +65 -0
- package/dist/lib/tx/size.d.ts +10 -0
- package/dist/lib/tx/size.js +48 -0
- package/dist/lib/tx/validate.d.ts +7 -0
- package/dist/lib/tx/validate.js +21 -0
- package/dist/lib/tx/witness.d.ts +3 -0
- package/dist/lib/tx/witness.js +85 -0
- package/dist/main.cjs +14625 -0
- package/dist/main.cjs.map +1 -0
- package/dist/module.mjs +14610 -0
- package/dist/module.mjs.map +1 -0
- package/dist/package.json +106 -0
- package/dist/schema/index.d.ts +2 -0
- package/dist/schema/index.js +2 -0
- package/dist/schema/taproot.d.ts +18 -0
- package/dist/schema/taproot.js +9 -0
- package/dist/schema/tx.d.ts +278 -0
- package/dist/schema/tx.js +35 -0
- package/dist/script.js +15 -0
- package/dist/script.js.map +1 -0
- package/dist/types/address.d.ts +34 -0
- package/dist/types/address.js +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.js +9 -0
- package/dist/types/meta.d.ts +10 -0
- package/dist/types/meta.js +1 -0
- package/dist/types/psbt.d.ts +9 -0
- package/dist/types/psbt.js +1 -0
- package/dist/types/sighash.d.ts +14 -0
- package/dist/types/sighash.js +1 -0
- package/dist/types/taproot.d.ts +35 -0
- package/dist/types/taproot.js +1 -0
- package/dist/types/transaction.d.ts +81 -0
- package/dist/types/transaction.js +1 -0
- package/dist/types/txdata.d.ts +45 -0
- package/dist/types/txdata.js +1 -0
- package/dist/types/txmeta.d.ts +19 -0
- package/dist/types/txmeta.js +1 -0
- package/dist/types/witness.d.ts +30 -0
- package/dist/types/witness.js +1 -0
- package/package.json +106 -0
- package/src/class/index.ts +5 -0
- package/src/class/signer.ts +47 -0
- package/src/class/tx.ts +118 -0
- package/src/class/txin.ts +95 -0
- package/src/class/txout.ts +57 -0
- package/src/class/witness.ts +85 -0
- package/src/const.ts +43 -0
- package/src/index.ts +14 -0
- package/src/lib/address/encode.ts +183 -0
- package/src/lib/address/index.ts +24 -0
- package/src/lib/address/p2pkh.ts +65 -0
- package/src/lib/address/p2sh.ts +65 -0
- package/src/lib/address/p2tr.ts +51 -0
- package/src/lib/address/p2wpkh.ts +67 -0
- package/src/lib/address/p2wsh.ts +65 -0
- package/src/lib/address/script.ts +63 -0
- package/src/lib/address/util.ts +102 -0
- package/src/lib/meta/index.ts +2 -0
- package/src/lib/meta/pointer.ts +107 -0
- package/src/lib/meta/scribe.ts +251 -0
- package/src/lib/psbt/encoder.ts +24 -0
- package/src/lib/psbt/index.ts +4 -0
- package/src/lib/psbt/meta.ts +15 -0
- package/src/lib/psbt/util.ts +62 -0
- package/src/lib/psbt/validate.ts +18 -0
- package/src/lib/script/decode.ts +75 -0
- package/src/lib/script/encode.ts +130 -0
- package/src/lib/script/index.ts +26 -0
- package/src/lib/script/util.ts +78 -0
- package/src/lib/script/words.ts +182 -0
- package/src/lib/sighash/index.ts +5 -0
- package/src/lib/sighash/segwit.ts +152 -0
- package/src/lib/sighash/sign.ts +35 -0
- package/src/lib/sighash/taproot.ts +236 -0
- package/src/lib/sighash/util.ts +29 -0
- package/src/lib/sighash/verify.ts +83 -0
- package/src/lib/taproot/cblock.ts +95 -0
- package/src/lib/taproot/encode.ts +49 -0
- package/src/lib/taproot/index.ts +4 -0
- package/src/lib/taproot/parse.ts +65 -0
- package/src/lib/taproot/tree.ts +94 -0
- package/src/lib/tx/create.ts +82 -0
- package/src/lib/tx/decode.ts +145 -0
- package/src/lib/tx/encode.ts +154 -0
- package/src/lib/tx/index.ts +10 -0
- package/src/lib/tx/locktime.ts +57 -0
- package/src/lib/tx/meta.ts +73 -0
- package/src/lib/tx/parse.ts +16 -0
- package/src/lib/tx/sequence.ts +146 -0
- package/src/lib/tx/size.ts +77 -0
- package/src/lib/tx/validate.ts +36 -0
- package/src/lib/tx/witness.ts +122 -0
- package/src/schema/index.ts +2 -0
- package/src/schema/taproot.ts +12 -0
- package/src/schema/tx.ts +42 -0
- package/src/types/address.ts +39 -0
- package/src/types/index.ts +9 -0
- package/src/types/meta.ts +10 -0
- package/src/types/psbt.ts +15 -0
- package/src/types/sighash.ts +16 -0
- package/src/types/taproot.ts +40 -0
- package/src/types/transaction.ts +98 -0
- package/src/types/txdata.ts +53 -0
- package/src/types/txmeta.ts +25 -0
- 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 @@
|
|
|
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,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
|
+
}
|
package/src/class/tx.ts
ADDED
|
@@ -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
|
+
|