@bitgo/wasm-utxo 1.14.0 → 1.15.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/README.md +12 -2
- package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.d.ts +205 -0
- package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.js +178 -0
- package/dist/cjs/js/fixedScriptWallet/index.d.ts +1 -1
- package/dist/cjs/js/wasm/wasm_utxo.d.ts +98 -0
- package/dist/cjs/js/wasm/wasm_utxo.js +251 -0
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm.d.ts +58 -50
- package/dist/esm/js/fixedScriptWallet/BitGoPsbt.d.ts +205 -0
- package/dist/esm/js/fixedScriptWallet/BitGoPsbt.js +178 -0
- package/dist/esm/js/fixedScriptWallet/index.d.ts +1 -1
- package/dist/esm/js/wasm/wasm_utxo.d.ts +98 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.js +251 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm.d.ts +58 -50
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -24,10 +24,20 @@ This project is under active development.
|
|
|
24
24
|
|
|
25
25
|
## Building
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
### Mac
|
|
28
|
+
|
|
29
|
+
Requires Homebrew LLVM (Apple's Clang doesn't support WASM targets):
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
brew install llvm
|
|
33
|
+
npm run build
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Docker (optional)
|
|
37
|
+
|
|
38
|
+
If you prefer a containerized build environment:
|
|
28
39
|
|
|
29
40
|
```bash
|
|
30
|
-
cd packages/wasm-utxo
|
|
31
41
|
make -f Container.mk build-image
|
|
32
42
|
make -f Container.mk build-wasm
|
|
33
43
|
```
|
|
@@ -21,6 +21,7 @@ export type ParsedInput = {
|
|
|
21
21
|
value: bigint;
|
|
22
22
|
scriptId: ScriptId | null;
|
|
23
23
|
scriptType: InputScriptType;
|
|
24
|
+
sequence: number;
|
|
24
25
|
};
|
|
25
26
|
export type ParsedOutput = {
|
|
26
27
|
address: string | null;
|
|
@@ -36,9 +37,77 @@ export type ParsedTransaction = {
|
|
|
36
37
|
minerFee: bigint;
|
|
37
38
|
virtualSize: number;
|
|
38
39
|
};
|
|
40
|
+
export type CreateEmptyOptions = {
|
|
41
|
+
/** Transaction version (default: 2) */
|
|
42
|
+
version?: number;
|
|
43
|
+
/** Lock time (default: 0) */
|
|
44
|
+
lockTime?: number;
|
|
45
|
+
};
|
|
46
|
+
export type AddInputOptions = {
|
|
47
|
+
/** Previous transaction ID (hex string) */
|
|
48
|
+
txid: string;
|
|
49
|
+
/** Output index being spent */
|
|
50
|
+
vout: number;
|
|
51
|
+
/** Value in satoshis (for witness_utxo) */
|
|
52
|
+
value: bigint;
|
|
53
|
+
/** Sequence number (default: 0xFFFFFFFE for RBF) */
|
|
54
|
+
sequence?: number;
|
|
55
|
+
/** Full previous transaction (for non-segwit strict compliance) */
|
|
56
|
+
prevTx?: Uint8Array;
|
|
57
|
+
};
|
|
58
|
+
export type AddOutputOptions = {
|
|
59
|
+
/** Output script (scriptPubKey) */
|
|
60
|
+
script: Uint8Array;
|
|
61
|
+
/** Value in satoshis */
|
|
62
|
+
value: bigint;
|
|
63
|
+
};
|
|
64
|
+
/** Key identifier for signing ("user", "backup", or "bitgo") */
|
|
65
|
+
export type SignerKey = "user" | "backup" | "bitgo";
|
|
66
|
+
/** Specifies signer and cosigner for Taproot inputs */
|
|
67
|
+
export type SignPath = {
|
|
68
|
+
/** Key that will sign */
|
|
69
|
+
signer: SignerKey;
|
|
70
|
+
/** Key that will co-sign */
|
|
71
|
+
cosigner: SignerKey;
|
|
72
|
+
};
|
|
73
|
+
export type AddWalletInputOptions = {
|
|
74
|
+
/** Script location in wallet (chain + index) */
|
|
75
|
+
scriptId: ScriptId;
|
|
76
|
+
/** Sign path - required for p2tr/p2trMusig2 (chains 30-41) */
|
|
77
|
+
signPath?: SignPath;
|
|
78
|
+
};
|
|
79
|
+
export type AddWalletOutputOptions = {
|
|
80
|
+
/** Chain code (0/1=p2sh, 10/11=p2shP2wsh, 20/21=p2wsh, 30/31=p2tr, 40/41=p2trMusig2) */
|
|
81
|
+
chain: number;
|
|
82
|
+
/** Derivation index */
|
|
83
|
+
index: number;
|
|
84
|
+
/** Value in satoshis */
|
|
85
|
+
value: bigint;
|
|
86
|
+
};
|
|
39
87
|
export declare class BitGoPsbt {
|
|
40
88
|
private wasm;
|
|
41
89
|
private constructor();
|
|
90
|
+
/**
|
|
91
|
+
* Create an empty PSBT for the given network with wallet keys
|
|
92
|
+
*
|
|
93
|
+
* The wallet keys are used to set global xpubs in the PSBT, which identifies
|
|
94
|
+
* the keys that will be used for signing.
|
|
95
|
+
*
|
|
96
|
+
* @param network - Network name (utxolib name like "bitcoin" or coin name like "btc")
|
|
97
|
+
* @param walletKeys - The wallet's root keys (sets global xpubs in the PSBT)
|
|
98
|
+
* @param options - Optional transaction parameters (version, lockTime)
|
|
99
|
+
* @returns A new empty BitGoPsbt instance
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* // Create empty PSBT with wallet keys
|
|
104
|
+
* const psbt = BitGoPsbt.createEmpty("bitcoin", walletKeys);
|
|
105
|
+
*
|
|
106
|
+
* // Create with custom version and lockTime
|
|
107
|
+
* const psbt = BitGoPsbt.createEmpty("bitcoin", walletKeys, { version: 1, lockTime: 500000 });
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
static createEmpty(network: NetworkName, walletKeys: WalletKeysArg, options?: CreateEmptyOptions): BitGoPsbt;
|
|
42
111
|
/**
|
|
43
112
|
* Deserialize a PSBT from bytes
|
|
44
113
|
* @param bytes - The PSBT bytes
|
|
@@ -46,11 +115,147 @@ export declare class BitGoPsbt {
|
|
|
46
115
|
* @returns A BitGoPsbt instance
|
|
47
116
|
*/
|
|
48
117
|
static fromBytes(bytes: Uint8Array, network: NetworkName): BitGoPsbt;
|
|
118
|
+
/**
|
|
119
|
+
* Add an input to the PSBT
|
|
120
|
+
*
|
|
121
|
+
* This adds a transaction input and corresponding PSBT input metadata.
|
|
122
|
+
* The witness_utxo is automatically populated for modern signing compatibility.
|
|
123
|
+
*
|
|
124
|
+
* @param options - Input options (txid, vout, value, sequence)
|
|
125
|
+
* @param script - Output script of the UTXO being spent
|
|
126
|
+
* @returns The index of the newly added input
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* const inputIndex = psbt.addInput({
|
|
131
|
+
* txid: "abc123...",
|
|
132
|
+
* vout: 0,
|
|
133
|
+
* value: 100000n,
|
|
134
|
+
* }, outputScript);
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
addInput(options: AddInputOptions, script: Uint8Array): number;
|
|
138
|
+
/**
|
|
139
|
+
* Add an output to the PSBT
|
|
140
|
+
*
|
|
141
|
+
* @param options - Output options (script, value)
|
|
142
|
+
* @returns The index of the newly added output
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* const outputIndex = psbt.addOutput({
|
|
147
|
+
* script: outputScript,
|
|
148
|
+
* value: 50000n,
|
|
149
|
+
* });
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
addOutput(options: AddOutputOptions): number;
|
|
153
|
+
/**
|
|
154
|
+
* Add a wallet input with full PSBT metadata
|
|
155
|
+
*
|
|
156
|
+
* This is a higher-level method that adds an input and populates all required
|
|
157
|
+
* PSBT fields (scripts, derivation info, etc.) based on the wallet's chain type.
|
|
158
|
+
*
|
|
159
|
+
* For p2sh/p2shP2wsh/p2wsh: Sets bip32Derivation, witnessScript, redeemScript (signPath not needed)
|
|
160
|
+
* For p2tr/p2trMusig2 script path: Sets tapLeafScript, tapBip32Derivation (signPath required)
|
|
161
|
+
* For p2trMusig2 key path: Sets tapInternalKey, tapMerkleRoot, tapBip32Derivation, musig2 participants (signPath required)
|
|
162
|
+
*
|
|
163
|
+
* @param inputOptions - Common input options (txid, vout, value, sequence)
|
|
164
|
+
* @param walletKeys - The wallet's root keys
|
|
165
|
+
* @param walletOptions - Wallet-specific options (scriptId, signPath, prevTx)
|
|
166
|
+
* @returns The index of the newly added input
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```typescript
|
|
170
|
+
* // Add a p2shP2wsh input (signPath not needed)
|
|
171
|
+
* const inputIndex = psbt.addWalletInput(
|
|
172
|
+
* { txid: "abc123...", vout: 0, value: 100000n },
|
|
173
|
+
* walletKeys,
|
|
174
|
+
* { scriptId: { chain: 10, index: 0 } }, // p2shP2wsh external
|
|
175
|
+
* );
|
|
176
|
+
*
|
|
177
|
+
* // Add a p2trMusig2 key path input (signPath required)
|
|
178
|
+
* const inputIndex = psbt.addWalletInput(
|
|
179
|
+
* { txid: "def456...", vout: 1, value: 50000n },
|
|
180
|
+
* walletKeys,
|
|
181
|
+
* { scriptId: { chain: 40, index: 5 }, signPath: { signer: "user", cosigner: "bitgo" } },
|
|
182
|
+
* );
|
|
183
|
+
*
|
|
184
|
+
* // Add p2trMusig2 with backup key (script path spend)
|
|
185
|
+
* const inputIndex = psbt.addWalletInput(
|
|
186
|
+
* { txid: "ghi789...", vout: 0, value: 75000n },
|
|
187
|
+
* walletKeys,
|
|
188
|
+
* { scriptId: { chain: 40, index: 3 }, signPath: { signer: "user", cosigner: "backup" } },
|
|
189
|
+
* );
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
addWalletInput(inputOptions: AddInputOptions, walletKeys: WalletKeysArg, walletOptions: AddWalletInputOptions): number;
|
|
193
|
+
/**
|
|
194
|
+
* Add a wallet output with full PSBT metadata
|
|
195
|
+
*
|
|
196
|
+
* This creates a verifiable wallet output (typically for change) with all required
|
|
197
|
+
* PSBT fields (scripts, derivation info) based on the wallet's chain type.
|
|
198
|
+
*
|
|
199
|
+
* For p2sh/p2shP2wsh/p2wsh: Sets bip32Derivation, witnessScript, redeemScript
|
|
200
|
+
* For p2tr/p2trMusig2: Sets tapInternalKey, tapBip32Derivation
|
|
201
|
+
*
|
|
202
|
+
* @param walletKeys - The wallet's root keys
|
|
203
|
+
* @param options - Output options including chain, index, and value
|
|
204
|
+
* @returns The index of the newly added output
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* // Add a p2shP2wsh change output
|
|
209
|
+
* const outputIndex = psbt.addWalletOutput(walletKeys, {
|
|
210
|
+
* chain: 11, // p2shP2wsh internal (change)
|
|
211
|
+
* index: 0,
|
|
212
|
+
* value: 50000n,
|
|
213
|
+
* });
|
|
214
|
+
*
|
|
215
|
+
* // Add a p2trMusig2 change output
|
|
216
|
+
* const outputIndex = psbt.addWalletOutput(walletKeys, {
|
|
217
|
+
* chain: 41, // p2trMusig2 internal (change)
|
|
218
|
+
* index: 5,
|
|
219
|
+
* value: 25000n,
|
|
220
|
+
* });
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
addWalletOutput(walletKeys: WalletKeysArg, options: AddWalletOutputOptions): number;
|
|
224
|
+
/**
|
|
225
|
+
* Add a replay protection input to the PSBT
|
|
226
|
+
*
|
|
227
|
+
* Replay protection inputs are P2SH-P2PK inputs used on forked networks to prevent
|
|
228
|
+
* transaction replay attacks. They use a simple pubkey script without wallet derivation.
|
|
229
|
+
*
|
|
230
|
+
* @param inputOptions - Common input options (txid, vout, value, sequence)
|
|
231
|
+
* @param key - ECPair containing the public key for the replay protection input
|
|
232
|
+
* @returns The index of the newly added input
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* ```typescript
|
|
236
|
+
* // Add a replay protection input using ECPair
|
|
237
|
+
* const inputIndex = psbt.addReplayProtectionInput(
|
|
238
|
+
* { txid: "abc123...", vout: 0, value: 1000n },
|
|
239
|
+
* replayProtectionKey,
|
|
240
|
+
* );
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
addReplayProtectionInput(inputOptions: AddInputOptions, key: ECPairArg): number;
|
|
49
244
|
/**
|
|
50
245
|
* Get the unsigned transaction ID
|
|
51
246
|
* @returns The unsigned transaction ID
|
|
52
247
|
*/
|
|
53
248
|
unsignedTxid(): string;
|
|
249
|
+
/**
|
|
250
|
+
* Get the transaction version
|
|
251
|
+
* @returns The transaction version number
|
|
252
|
+
*/
|
|
253
|
+
get version(): number;
|
|
254
|
+
/**
|
|
255
|
+
* Get the transaction lock time
|
|
256
|
+
* @returns The transaction lock time
|
|
257
|
+
*/
|
|
258
|
+
get lockTime(): number;
|
|
54
259
|
/**
|
|
55
260
|
* Parse transaction with wallet keys to identify wallet inputs/outputs
|
|
56
261
|
* @param walletKeys - The wallet keys to use for identification
|
|
@@ -11,6 +11,31 @@ class BitGoPsbt {
|
|
|
11
11
|
constructor(wasm) {
|
|
12
12
|
this.wasm = wasm;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Create an empty PSBT for the given network with wallet keys
|
|
16
|
+
*
|
|
17
|
+
* The wallet keys are used to set global xpubs in the PSBT, which identifies
|
|
18
|
+
* the keys that will be used for signing.
|
|
19
|
+
*
|
|
20
|
+
* @param network - Network name (utxolib name like "bitcoin" or coin name like "btc")
|
|
21
|
+
* @param walletKeys - The wallet's root keys (sets global xpubs in the PSBT)
|
|
22
|
+
* @param options - Optional transaction parameters (version, lockTime)
|
|
23
|
+
* @returns A new empty BitGoPsbt instance
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* // Create empty PSBT with wallet keys
|
|
28
|
+
* const psbt = BitGoPsbt.createEmpty("bitcoin", walletKeys);
|
|
29
|
+
*
|
|
30
|
+
* // Create with custom version and lockTime
|
|
31
|
+
* const psbt = BitGoPsbt.createEmpty("bitcoin", walletKeys, { version: 1, lockTime: 500000 });
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
static createEmpty(network, walletKeys, options) {
|
|
35
|
+
const keys = RootWalletKeys_js_1.RootWalletKeys.from(walletKeys);
|
|
36
|
+
const wasm = wasm_utxo_js_1.BitGoPsbt.create_empty(network, keys.wasm, options?.version, options?.lockTime);
|
|
37
|
+
return new BitGoPsbt(wasm);
|
|
38
|
+
}
|
|
14
39
|
/**
|
|
15
40
|
* Deserialize a PSBT from bytes
|
|
16
41
|
* @param bytes - The PSBT bytes
|
|
@@ -21,6 +46,145 @@ class BitGoPsbt {
|
|
|
21
46
|
const wasm = wasm_utxo_js_1.BitGoPsbt.from_bytes(bytes, network);
|
|
22
47
|
return new BitGoPsbt(wasm);
|
|
23
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Add an input to the PSBT
|
|
51
|
+
*
|
|
52
|
+
* This adds a transaction input and corresponding PSBT input metadata.
|
|
53
|
+
* The witness_utxo is automatically populated for modern signing compatibility.
|
|
54
|
+
*
|
|
55
|
+
* @param options - Input options (txid, vout, value, sequence)
|
|
56
|
+
* @param script - Output script of the UTXO being spent
|
|
57
|
+
* @returns The index of the newly added input
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const inputIndex = psbt.addInput({
|
|
62
|
+
* txid: "abc123...",
|
|
63
|
+
* vout: 0,
|
|
64
|
+
* value: 100000n,
|
|
65
|
+
* }, outputScript);
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
addInput(options, script) {
|
|
69
|
+
return this.wasm.add_input(options.txid, options.vout, options.value, script, options.sequence, options.prevTx);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Add an output to the PSBT
|
|
73
|
+
*
|
|
74
|
+
* @param options - Output options (script, value)
|
|
75
|
+
* @returns The index of the newly added output
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const outputIndex = psbt.addOutput({
|
|
80
|
+
* script: outputScript,
|
|
81
|
+
* value: 50000n,
|
|
82
|
+
* });
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
addOutput(options) {
|
|
86
|
+
return this.wasm.add_output(options.script, options.value);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Add a wallet input with full PSBT metadata
|
|
90
|
+
*
|
|
91
|
+
* This is a higher-level method that adds an input and populates all required
|
|
92
|
+
* PSBT fields (scripts, derivation info, etc.) based on the wallet's chain type.
|
|
93
|
+
*
|
|
94
|
+
* For p2sh/p2shP2wsh/p2wsh: Sets bip32Derivation, witnessScript, redeemScript (signPath not needed)
|
|
95
|
+
* For p2tr/p2trMusig2 script path: Sets tapLeafScript, tapBip32Derivation (signPath required)
|
|
96
|
+
* For p2trMusig2 key path: Sets tapInternalKey, tapMerkleRoot, tapBip32Derivation, musig2 participants (signPath required)
|
|
97
|
+
*
|
|
98
|
+
* @param inputOptions - Common input options (txid, vout, value, sequence)
|
|
99
|
+
* @param walletKeys - The wallet's root keys
|
|
100
|
+
* @param walletOptions - Wallet-specific options (scriptId, signPath, prevTx)
|
|
101
|
+
* @returns The index of the newly added input
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```typescript
|
|
105
|
+
* // Add a p2shP2wsh input (signPath not needed)
|
|
106
|
+
* const inputIndex = psbt.addWalletInput(
|
|
107
|
+
* { txid: "abc123...", vout: 0, value: 100000n },
|
|
108
|
+
* walletKeys,
|
|
109
|
+
* { scriptId: { chain: 10, index: 0 } }, // p2shP2wsh external
|
|
110
|
+
* );
|
|
111
|
+
*
|
|
112
|
+
* // Add a p2trMusig2 key path input (signPath required)
|
|
113
|
+
* const inputIndex = psbt.addWalletInput(
|
|
114
|
+
* { txid: "def456...", vout: 1, value: 50000n },
|
|
115
|
+
* walletKeys,
|
|
116
|
+
* { scriptId: { chain: 40, index: 5 }, signPath: { signer: "user", cosigner: "bitgo" } },
|
|
117
|
+
* );
|
|
118
|
+
*
|
|
119
|
+
* // Add p2trMusig2 with backup key (script path spend)
|
|
120
|
+
* const inputIndex = psbt.addWalletInput(
|
|
121
|
+
* { txid: "ghi789...", vout: 0, value: 75000n },
|
|
122
|
+
* walletKeys,
|
|
123
|
+
* { scriptId: { chain: 40, index: 3 }, signPath: { signer: "user", cosigner: "backup" } },
|
|
124
|
+
* );
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
addWalletInput(inputOptions, walletKeys, walletOptions) {
|
|
128
|
+
const keys = RootWalletKeys_js_1.RootWalletKeys.from(walletKeys);
|
|
129
|
+
return this.wasm.add_wallet_input(inputOptions.txid, inputOptions.vout, inputOptions.value, keys.wasm, walletOptions.scriptId.chain, walletOptions.scriptId.index, walletOptions.signPath?.signer, walletOptions.signPath?.cosigner, inputOptions.sequence, inputOptions.prevTx);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Add a wallet output with full PSBT metadata
|
|
133
|
+
*
|
|
134
|
+
* This creates a verifiable wallet output (typically for change) with all required
|
|
135
|
+
* PSBT fields (scripts, derivation info) based on the wallet's chain type.
|
|
136
|
+
*
|
|
137
|
+
* For p2sh/p2shP2wsh/p2wsh: Sets bip32Derivation, witnessScript, redeemScript
|
|
138
|
+
* For p2tr/p2trMusig2: Sets tapInternalKey, tapBip32Derivation
|
|
139
|
+
*
|
|
140
|
+
* @param walletKeys - The wallet's root keys
|
|
141
|
+
* @param options - Output options including chain, index, and value
|
|
142
|
+
* @returns The index of the newly added output
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* // Add a p2shP2wsh change output
|
|
147
|
+
* const outputIndex = psbt.addWalletOutput(walletKeys, {
|
|
148
|
+
* chain: 11, // p2shP2wsh internal (change)
|
|
149
|
+
* index: 0,
|
|
150
|
+
* value: 50000n,
|
|
151
|
+
* });
|
|
152
|
+
*
|
|
153
|
+
* // Add a p2trMusig2 change output
|
|
154
|
+
* const outputIndex = psbt.addWalletOutput(walletKeys, {
|
|
155
|
+
* chain: 41, // p2trMusig2 internal (change)
|
|
156
|
+
* index: 5,
|
|
157
|
+
* value: 25000n,
|
|
158
|
+
* });
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
addWalletOutput(walletKeys, options) {
|
|
162
|
+
const keys = RootWalletKeys_js_1.RootWalletKeys.from(walletKeys);
|
|
163
|
+
return this.wasm.add_wallet_output(options.chain, options.index, options.value, keys.wasm);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Add a replay protection input to the PSBT
|
|
167
|
+
*
|
|
168
|
+
* Replay protection inputs are P2SH-P2PK inputs used on forked networks to prevent
|
|
169
|
+
* transaction replay attacks. They use a simple pubkey script without wallet derivation.
|
|
170
|
+
*
|
|
171
|
+
* @param inputOptions - Common input options (txid, vout, value, sequence)
|
|
172
|
+
* @param key - ECPair containing the public key for the replay protection input
|
|
173
|
+
* @returns The index of the newly added input
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```typescript
|
|
177
|
+
* // Add a replay protection input using ECPair
|
|
178
|
+
* const inputIndex = psbt.addReplayProtectionInput(
|
|
179
|
+
* { txid: "abc123...", vout: 0, value: 1000n },
|
|
180
|
+
* replayProtectionKey,
|
|
181
|
+
* );
|
|
182
|
+
* ```
|
|
183
|
+
*/
|
|
184
|
+
addReplayProtectionInput(inputOptions, key) {
|
|
185
|
+
const ecpair = ecpair_js_1.ECPair.from(key);
|
|
186
|
+
return this.wasm.add_replay_protection_input(ecpair.wasm, inputOptions.txid, inputOptions.vout, inputOptions.value, inputOptions.sequence);
|
|
187
|
+
}
|
|
24
188
|
/**
|
|
25
189
|
* Get the unsigned transaction ID
|
|
26
190
|
* @returns The unsigned transaction ID
|
|
@@ -28,6 +192,20 @@ class BitGoPsbt {
|
|
|
28
192
|
unsignedTxid() {
|
|
29
193
|
return this.wasm.unsigned_txid();
|
|
30
194
|
}
|
|
195
|
+
/**
|
|
196
|
+
* Get the transaction version
|
|
197
|
+
* @returns The transaction version number
|
|
198
|
+
*/
|
|
199
|
+
get version() {
|
|
200
|
+
return this.wasm.version();
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Get the transaction lock time
|
|
204
|
+
* @returns The transaction lock time
|
|
205
|
+
*/
|
|
206
|
+
get lockTime() {
|
|
207
|
+
return this.wasm.lock_time();
|
|
208
|
+
}
|
|
31
209
|
/**
|
|
32
210
|
* Parse transaction with wallet keys to identify wallet inputs/outputs
|
|
33
211
|
* @param walletKeys - The wallet keys to use for identification
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { RootWalletKeys, type WalletKeysArg, type IWalletKeys } from "./RootWalletKeys.js";
|
|
2
2
|
export { ReplayProtection, type ReplayProtectionArg } from "./ReplayProtection.js";
|
|
3
3
|
export { outputScript, address } from "./address.js";
|
|
4
|
-
export { BitGoPsbt, type NetworkName, type ScriptId, type InputScriptType, type ParsedInput, type ParsedOutput, type ParsedTransaction, } from "./BitGoPsbt.js";
|
|
4
|
+
export { BitGoPsbt, type NetworkName, type ScriptId, type InputScriptType, type ParsedInput, type ParsedOutput, type ParsedTransaction, type SignPath, } from "./BitGoPsbt.js";
|
|
@@ -13,10 +13,31 @@ export class BitGoPsbt {
|
|
|
13
13
|
private constructor();
|
|
14
14
|
free(): void;
|
|
15
15
|
[Symbol.dispose](): void;
|
|
16
|
+
/**
|
|
17
|
+
* Add an output to the PSBT
|
|
18
|
+
*
|
|
19
|
+
* # Arguments
|
|
20
|
+
* * `script` - The output script (scriptPubKey)
|
|
21
|
+
* * `value` - The value in satoshis
|
|
22
|
+
*
|
|
23
|
+
* # Returns
|
|
24
|
+
* The index of the newly added output
|
|
25
|
+
*/
|
|
26
|
+
add_output(script: Uint8Array, value: bigint): number;
|
|
16
27
|
/**
|
|
17
28
|
* Deserialize a PSBT from bytes with network-specific logic
|
|
18
29
|
*/
|
|
19
30
|
static from_bytes(bytes: Uint8Array, network: string): BitGoPsbt;
|
|
31
|
+
/**
|
|
32
|
+
* Create an empty PSBT for the given network with wallet keys
|
|
33
|
+
*
|
|
34
|
+
* # Arguments
|
|
35
|
+
* * `network` - Network name (utxolib or coin name)
|
|
36
|
+
* * `wallet_keys` - The wallet's root keys (used to set global xpubs)
|
|
37
|
+
* * `version` - Optional transaction version (default: 2)
|
|
38
|
+
* * `lock_time` - Optional lock time (default: 0)
|
|
39
|
+
*/
|
|
40
|
+
static create_empty(network: string, wallet_keys: WasmRootWalletKeys, version?: number | null, lock_time?: number | null): BitGoPsbt;
|
|
20
41
|
/**
|
|
21
42
|
* Get the unsigned transaction ID
|
|
22
43
|
*/
|
|
@@ -41,6 +62,44 @@ export class BitGoPsbt {
|
|
|
41
62
|
* - `Err(WasmUtxoError)` if signing fails
|
|
42
63
|
*/
|
|
43
64
|
sign_with_xpriv(input_index: number, xpriv: WasmBIP32): void;
|
|
65
|
+
/**
|
|
66
|
+
* Add a wallet input with full PSBT metadata
|
|
67
|
+
*
|
|
68
|
+
* This is a higher-level method that adds an input and populates all required
|
|
69
|
+
* PSBT fields (scripts, derivation info, etc.) based on the wallet's chain type.
|
|
70
|
+
*
|
|
71
|
+
* # Arguments
|
|
72
|
+
* * `txid` - The transaction ID (hex string)
|
|
73
|
+
* * `vout` - The output index being spent
|
|
74
|
+
* * `value` - The value in satoshis
|
|
75
|
+
* * `chain` - The chain code (0/1=p2sh, 10/11=p2shP2wsh, 20/21=p2wsh, 30/31=p2tr, 40/41=p2trMusig2)
|
|
76
|
+
* * `index` - The derivation index
|
|
77
|
+
* * `wallet_keys` - The root wallet keys
|
|
78
|
+
* * `signer` - The key that will sign ("user", "backup", or "bitgo") - required for p2tr/p2trMusig2
|
|
79
|
+
* * `cosigner` - The key that will co-sign - required for p2tr/p2trMusig2
|
|
80
|
+
* * `sequence` - Optional sequence number (default: 0xFFFFFFFE for RBF)
|
|
81
|
+
* * `prev_tx` - Optional full previous transaction bytes (for non-segwit)
|
|
82
|
+
*
|
|
83
|
+
* # Returns
|
|
84
|
+
* The index of the newly added input
|
|
85
|
+
*/
|
|
86
|
+
add_wallet_input(txid: string, vout: number, value: bigint, wallet_keys: WasmRootWalletKeys, chain: number, index: number, signer?: string | null, cosigner?: string | null, sequence?: number | null, prev_tx?: Uint8Array | null): number;
|
|
87
|
+
/**
|
|
88
|
+
* Add a wallet output with full PSBT metadata
|
|
89
|
+
*
|
|
90
|
+
* This creates a verifiable wallet output (typically for change) with all required
|
|
91
|
+
* PSBT fields (scripts, derivation info) based on the wallet's chain type.
|
|
92
|
+
*
|
|
93
|
+
* # Arguments
|
|
94
|
+
* * `chain` - The chain code (0/1=p2sh, 10/11=p2shP2wsh, 20/21=p2wsh, 30/31=p2tr, 40/41=p2trMusig2)
|
|
95
|
+
* * `index` - The derivation index
|
|
96
|
+
* * `value` - The value in satoshis
|
|
97
|
+
* * `wallet_keys` - The root wallet keys
|
|
98
|
+
*
|
|
99
|
+
* # Returns
|
|
100
|
+
* The index of the newly added output
|
|
101
|
+
*/
|
|
102
|
+
add_wallet_output(chain: number, index: number, value: bigint, wallet_keys: WasmRootWalletKeys): number;
|
|
44
103
|
/**
|
|
45
104
|
* Sign a single input with a raw private key
|
|
46
105
|
*
|
|
@@ -181,6 +240,23 @@ export class BitGoPsbt {
|
|
|
181
240
|
* - `Err(WasmUtxoError)` if the input index is out of bounds, derivation fails, or verification fails
|
|
182
241
|
*/
|
|
183
242
|
verify_signature_with_xpub(input_index: number, xpub: WasmBIP32): boolean;
|
|
243
|
+
/**
|
|
244
|
+
* Add a replay protection input to the PSBT
|
|
245
|
+
*
|
|
246
|
+
* Replay protection inputs are P2SH-P2PK inputs used on forked networks to prevent
|
|
247
|
+
* transaction replay attacks. They use a simple pubkey script without wallet derivation.
|
|
248
|
+
*
|
|
249
|
+
* # Arguments
|
|
250
|
+
* * `ecpair` - The ECPair containing the public key for the replay protection input
|
|
251
|
+
* * `txid` - The transaction ID (hex string) of the output being spent
|
|
252
|
+
* * `vout` - The output index being spent
|
|
253
|
+
* * `value` - The value in satoshis
|
|
254
|
+
* * `sequence` - Optional sequence number (default: 0xFFFFFFFE for RBF)
|
|
255
|
+
*
|
|
256
|
+
* # Returns
|
|
257
|
+
* The index of the newly added input
|
|
258
|
+
*/
|
|
259
|
+
add_replay_protection_input(ecpair: WasmECPair, txid: string, vout: number, value: bigint, sequence?: number | null): number;
|
|
184
260
|
/**
|
|
185
261
|
* Parse outputs with wallet keys to identify which outputs belong to a wallet
|
|
186
262
|
*
|
|
@@ -213,6 +289,28 @@ export class BitGoPsbt {
|
|
|
213
289
|
* Get the network of the PSBT
|
|
214
290
|
*/
|
|
215
291
|
network(): string;
|
|
292
|
+
/**
|
|
293
|
+
* Get the transaction version
|
|
294
|
+
*/
|
|
295
|
+
version(): number;
|
|
296
|
+
/**
|
|
297
|
+
* Add an input to the PSBT
|
|
298
|
+
*
|
|
299
|
+
* # Arguments
|
|
300
|
+
* * `txid` - The transaction ID (hex string) of the output being spent
|
|
301
|
+
* * `vout` - The output index being spent
|
|
302
|
+
* * `value` - The value in satoshis of the output being spent
|
|
303
|
+
* * `script` - The output script (scriptPubKey) of the output being spent
|
|
304
|
+
* * `sequence` - Optional sequence number (default: 0xFFFFFFFE for RBF)
|
|
305
|
+
*
|
|
306
|
+
* # Returns
|
|
307
|
+
* The index of the newly added input
|
|
308
|
+
*/
|
|
309
|
+
add_input(txid: string, vout: number, value: bigint, script: Uint8Array, sequence?: number | null, prev_tx?: Uint8Array | null): number;
|
|
310
|
+
/**
|
|
311
|
+
* Get the transaction lock time
|
|
312
|
+
*/
|
|
313
|
+
lock_time(): number;
|
|
216
314
|
/**
|
|
217
315
|
* Serialize the PSBT to bytes
|
|
218
316
|
*
|