@caravan/psbt 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/.eslintrc.cjs +6 -0
- package/.prettierrc +4 -0
- package/.turbo/turbo-build.log +20 -0
- package/.turbo/turbo-ci.log +258 -0
- package/.turbo/turbo-lint.log +49 -0
- package/.turbo/turbo-test$colon$watch.log +223 -0
- package/.turbo/turbo-test.log +196 -0
- package/CHANGELOG.md +10 -0
- package/README.md +197 -0
- package/dist/index.d.mts +150 -0
- package/dist/index.d.ts +150 -0
- package/dist/index.js +949 -0
- package/dist/index.mjs +924 -0
- package/jest.config.js +4 -0
- package/package.json +49 -0
- package/src/index.ts +2 -0
- package/src/psbt.test.ts +338 -0
- package/src/psbt.ts +440 -0
- package/src/psbtv2.test.ts +1241 -0
- package/src/psbtv2.ts +1352 -0
- package/tsconfig.json +3 -0
- package/tsup.config.ts +6 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The PsbtV2 class is intended to represent an easily modifiable and
|
|
3
|
+
* serializable psbt of version 2 conforming to BIP0174. Getters exist for all
|
|
4
|
+
* BIP-defined keytypes. Very few setters and modifier methods exist. As they
|
|
5
|
+
* are added, they should enforce implied and documented rules and limitations.
|
|
6
|
+
*
|
|
7
|
+
* Defining BIPs:
|
|
8
|
+
* https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki
|
|
9
|
+
* https://github.com/bitcoin/bips/blob/master/bip-0370.mediawiki
|
|
10
|
+
*/
|
|
11
|
+
type Key = string;
|
|
12
|
+
type Value = Buffer;
|
|
13
|
+
type NonUniqueKeyTypeValue = {
|
|
14
|
+
key: string;
|
|
15
|
+
value: string | null;
|
|
16
|
+
};
|
|
17
|
+
declare enum PsbtGlobalTxModifiableBits {
|
|
18
|
+
INPUTS = "INPUTS",// 0b00000001
|
|
19
|
+
OUTPUTS = "OUTPUTS",// 0b00000010
|
|
20
|
+
SIGHASH_SINGLE = "SIGHASH_SINGLE"
|
|
21
|
+
}
|
|
22
|
+
declare abstract class PsbtV2Maps {
|
|
23
|
+
protected globalMap: Map<Key, Value>;
|
|
24
|
+
protected inputMaps: Map<Key, Value>[];
|
|
25
|
+
protected outputMaps: Map<Key, Value>[];
|
|
26
|
+
constructor(psbt?: Buffer | string);
|
|
27
|
+
serialize(format?: "base64" | "hex"): string;
|
|
28
|
+
copy(to: PsbtV2): void;
|
|
29
|
+
private copyMaps;
|
|
30
|
+
private copyMap;
|
|
31
|
+
}
|
|
32
|
+
declare class PsbtV2 extends PsbtV2Maps {
|
|
33
|
+
constructor(psbt?: Buffer | string);
|
|
34
|
+
/**
|
|
35
|
+
* Globals Getters/Setters
|
|
36
|
+
*/
|
|
37
|
+
get PSBT_GLOBAL_XPUB(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
|
|
38
|
+
get PSBT_GLOBAL_TX_VERSION(): number;
|
|
39
|
+
set PSBT_GLOBAL_TX_VERSION(version: number);
|
|
40
|
+
get PSBT_GLOBAL_FALLBACK_LOCKTIME(): number | null;
|
|
41
|
+
set PSBT_GLOBAL_FALLBACK_LOCKTIME(locktime: number | null);
|
|
42
|
+
get PSBT_GLOBAL_INPUT_COUNT(): number;
|
|
43
|
+
set PSBT_GLOBAL_INPUT_COUNT(count: number);
|
|
44
|
+
get PSBT_GLOBAL_OUTPUT_COUNT(): number;
|
|
45
|
+
set PSBT_GLOBAL_OUTPUT_COUNT(count: number);
|
|
46
|
+
get PSBT_GLOBAL_TX_MODIFIABLE(): PsbtGlobalTxModifiableBits[];
|
|
47
|
+
set PSBT_GLOBAL_TX_MODIFIABLE(modifiable: PsbtGlobalTxModifiableBits[]);
|
|
48
|
+
get PSBT_GLOBAL_VERSION(): number;
|
|
49
|
+
set PSBT_GLOBAL_VERSION(version: number);
|
|
50
|
+
get PSBT_GLOBAL_PROPRIETARY(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
|
|
51
|
+
/**
|
|
52
|
+
* Input Getters/Setters
|
|
53
|
+
*/
|
|
54
|
+
get PSBT_IN_NON_WITNESS_UTXO(): (string | null)[];
|
|
55
|
+
get PSBT_IN_WITNESS_UTXO(): (string | null)[];
|
|
56
|
+
get PSBT_IN_PARTIAL_SIG(): NonUniqueKeyTypeValue[][];
|
|
57
|
+
get PSBT_IN_SIGHASH_TYPE(): (number | null)[];
|
|
58
|
+
get PSBT_IN_REDEEM_SCRIPT(): (string | null)[];
|
|
59
|
+
get PSBT_IN_WITNESS_SCRIPT(): (string | null)[];
|
|
60
|
+
get PSBT_IN_BIP32_DERIVATION(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
|
|
61
|
+
get PSBT_IN_FINAL_SCRIPTSIG(): (string | null)[];
|
|
62
|
+
get PSBT_IN_FINAL_SCRIPTWITNESS(): (string | null)[];
|
|
63
|
+
get PSBT_IN_POR_COMMITMENT(): (string | null)[];
|
|
64
|
+
get PSBT_IN_RIPEMD160(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
|
|
65
|
+
get PSBT_IN_SHA256(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
|
|
66
|
+
get PSBT_IN_HASH160(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
|
|
67
|
+
get PSBT_IN_HASH256(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
|
|
68
|
+
get PSBT_IN_PREVIOUS_TXID(): string[];
|
|
69
|
+
get PSBT_IN_OUTPUT_INDEX(): number[];
|
|
70
|
+
get PSBT_IN_SEQUENCE(): (number | null)[];
|
|
71
|
+
get PSBT_IN_REQUIRED_TIME_LOCKTIME(): (number | null)[];
|
|
72
|
+
get PSBT_IN_REQUIRED_HEIGHT_LOCKTIME(): (number | null)[];
|
|
73
|
+
get PSBT_IN_TAP_KEY_SIG(): (string | null)[];
|
|
74
|
+
get PSBT_IN_TAP_SCRIPT_SIG(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
|
|
75
|
+
get PSBT_IN_TAP_LEAF_SCRIPT(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
|
|
76
|
+
get PSBT_IN_TAP_BIP32_DERIVATION(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
|
|
77
|
+
get PSBT_IN_TAP_INTERNAL_KEY(): (string | null)[];
|
|
78
|
+
get PSBT_IN_TAP_MERKLE_ROOT(): (string | null)[];
|
|
79
|
+
get PSBT_IN_PROPRIETARY(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
|
|
80
|
+
/**
|
|
81
|
+
* Output Getters/Setters
|
|
82
|
+
*/
|
|
83
|
+
get PSBT_OUT_REDEEM_SCRIPT(): (string | null)[];
|
|
84
|
+
get PSBT_OUT_WITNESS_SCRIPT(): (string | null)[];
|
|
85
|
+
get PSBT_OUT_BIP32_DERIVATION(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
|
|
86
|
+
get PSBT_OUT_AMOUNT(): bigint[];
|
|
87
|
+
get PSBT_OUT_SCRIPT(): string[];
|
|
88
|
+
get PSBT_OUT_TAP_INTERNAL_KEY(): (string | null)[];
|
|
89
|
+
get PSBT_OUT_TAP_TREE(): (string | null)[];
|
|
90
|
+
get PSBT_OUT_TAP_BIP32_DERIVATION(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
|
|
91
|
+
get PSBT_OUT_PROPRIETARY(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
|
|
92
|
+
/**
|
|
93
|
+
* Other Getters/Setters
|
|
94
|
+
*/
|
|
95
|
+
get nLockTime(): number | null;
|
|
96
|
+
/**
|
|
97
|
+
* Creator/Constructor Methods
|
|
98
|
+
*/
|
|
99
|
+
private create;
|
|
100
|
+
private validate;
|
|
101
|
+
dangerouslySetGlobalTxVersion1(): void;
|
|
102
|
+
addGlobalXpub(xpub: Buffer, fingerprint: Buffer, path: string): void;
|
|
103
|
+
addInput({ previousTxId, outputIndex, sequence, nonWitnessUtxo, witnessUtxo, redeemScript, witnessScript, bip32Derivation, }: {
|
|
104
|
+
previousTxId: Buffer | string;
|
|
105
|
+
outputIndex: number;
|
|
106
|
+
sequence?: number;
|
|
107
|
+
nonWitnessUtxo?: Buffer;
|
|
108
|
+
witnessUtxo?: {
|
|
109
|
+
amount: number;
|
|
110
|
+
script: Buffer;
|
|
111
|
+
};
|
|
112
|
+
redeemScript?: Buffer;
|
|
113
|
+
witnessScript?: Buffer;
|
|
114
|
+
bip32Derivation?: {
|
|
115
|
+
pubkey: Buffer;
|
|
116
|
+
masterFingerprint: Buffer;
|
|
117
|
+
path: string;
|
|
118
|
+
}[];
|
|
119
|
+
}): void;
|
|
120
|
+
addOutput({ amount, script, redeemScript, witnessScript, bip32Derivation, }: {
|
|
121
|
+
amount: number;
|
|
122
|
+
script: Buffer;
|
|
123
|
+
redeemScript?: Buffer;
|
|
124
|
+
witnessScript?: Buffer;
|
|
125
|
+
bip32Derivation?: {
|
|
126
|
+
pubkey: Buffer;
|
|
127
|
+
masterFingerprint: Buffer;
|
|
128
|
+
path: string;
|
|
129
|
+
}[];
|
|
130
|
+
}): void;
|
|
131
|
+
/**
|
|
132
|
+
* Updater/Signer Methods
|
|
133
|
+
*/
|
|
134
|
+
deleteInput(index: number): void;
|
|
135
|
+
deleteOutput(index: number): void;
|
|
136
|
+
private isModifiable;
|
|
137
|
+
addPartialSig(inputIndex: number, pubkey: Buffer, sig: Buffer): void;
|
|
138
|
+
removePartialSig(inputIndex: number, pubkey?: Buffer): void;
|
|
139
|
+
private handleSighashType;
|
|
140
|
+
static FromV0(psbt: string | Buffer, allowTxnVersion1?: boolean): PsbtV2;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Attempts to extract the version number as uint32LE from raw psbt regardless
|
|
144
|
+
* of psbt validity.
|
|
145
|
+
* @param {string | Buffer} psbt - hex, base64 or buffer of psbt
|
|
146
|
+
* @returns {number} version number
|
|
147
|
+
*/
|
|
148
|
+
declare function getPsbtVersionNumber(psbt: string | Buffer): number;
|
|
149
|
+
|
|
150
|
+
export { PsbtV2, getPsbtVersionNumber };
|