@bitgo/wasm-utxo 1.14.1 → 1.16.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 +10 -1
- package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.d.ts +210 -2
- package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.js +180 -0
- package/dist/cjs/js/fixedScriptWallet/ZcashBitGoPsbt.d.ts +113 -0
- package/dist/cjs/js/fixedScriptWallet/ZcashBitGoPsbt.js +114 -0
- package/dist/cjs/js/fixedScriptWallet/index.d.ts +2 -1
- package/dist/cjs/js/fixedScriptWallet/index.js +5 -1
- package/dist/cjs/js/wasm/wasm_utxo.d.ts +141 -0
- package/dist/cjs/js/wasm/wasm_utxo.js +352 -0
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm.d.ts +53 -41
- package/dist/esm/js/fixedScriptWallet/BitGoPsbt.d.ts +210 -2
- package/dist/esm/js/fixedScriptWallet/BitGoPsbt.js +180 -0
- package/dist/esm/js/fixedScriptWallet/ZcashBitGoPsbt.d.ts +113 -0
- package/dist/esm/js/fixedScriptWallet/ZcashBitGoPsbt.js +110 -0
- package/dist/esm/js/fixedScriptWallet/index.d.ts +2 -1
- package/dist/esm/js/fixedScriptWallet/index.js +3 -0
- package/dist/esm/js/wasm/wasm_utxo.d.ts +141 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.js +352 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm.d.ts +53 -41
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,7 +20,16 @@ This project is under active development.
|
|
|
20
20
|
| Descriptor Wallet: Address Support | ✅ Complete | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 |
|
|
21
21
|
| Descriptor Wallet: Transaction Support | ✅ Complete | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 | 🚫 |
|
|
22
22
|
| FixedScript Wallet: Address Generation | ✅ Complete | ✅ Complete | ✅ Complete | ✅ Complete | ✅ Complete | ✅ Complete | ✅ Complete |
|
|
23
|
-
| FixedScript Wallet: Transaction Support | ✅ Complete | ✅ Complete | ✅ Complete | ⏳ TODO | ⏳ TODO | ✅ Complete |
|
|
23
|
+
| FixedScript Wallet: Transaction Support | ✅ Complete | ✅ Complete | ✅ Complete | ⏳ TODO | ⏳ TODO | ✅ Complete | ✅ Complete |
|
|
24
|
+
|
|
25
|
+
### Zcash Features
|
|
26
|
+
|
|
27
|
+
Zcash support includes:
|
|
28
|
+
|
|
29
|
+
- **Network Upgrade Awareness**: Automatic consensus branch ID determination based on block height
|
|
30
|
+
- **All Network Upgrades**: Support for Overwinter, Sapling, Blossom, Heartwood, Canopy, Nu5, Nu6, and Nu6_1
|
|
31
|
+
- **Height-Based API**: Preferred `createEmpty()` method automatically selects correct consensus rules
|
|
32
|
+
- **Parity Testing**: Validated against `zebra-chain` for accuracy across all network upgrades
|
|
24
33
|
|
|
25
34
|
## Building
|
|
26
35
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BitGoPsbt as WasmBitGoPsbt } from "../wasm/wasm_utxo.js";
|
|
1
2
|
import { type WalletKeysArg } from "./RootWalletKeys.js";
|
|
2
3
|
import { type ReplayProtectionArg } from "./ReplayProtection.js";
|
|
3
4
|
import { type BIP32Arg } from "../bip32.js";
|
|
@@ -21,6 +22,7 @@ export type ParsedInput = {
|
|
|
21
22
|
value: bigint;
|
|
22
23
|
scriptId: ScriptId | null;
|
|
23
24
|
scriptType: InputScriptType;
|
|
25
|
+
sequence: number;
|
|
24
26
|
};
|
|
25
27
|
export type ParsedOutput = {
|
|
26
28
|
address: string | null;
|
|
@@ -36,9 +38,79 @@ export type ParsedTransaction = {
|
|
|
36
38
|
minerFee: bigint;
|
|
37
39
|
virtualSize: number;
|
|
38
40
|
};
|
|
41
|
+
export type CreateEmptyOptions = {
|
|
42
|
+
/** Transaction version (default: 2) */
|
|
43
|
+
version?: number;
|
|
44
|
+
/** Lock time (default: 0) */
|
|
45
|
+
lockTime?: number;
|
|
46
|
+
};
|
|
47
|
+
export type AddInputOptions = {
|
|
48
|
+
/** Previous transaction ID (hex string) */
|
|
49
|
+
txid: string;
|
|
50
|
+
/** Output index being spent */
|
|
51
|
+
vout: number;
|
|
52
|
+
/** Value in satoshis (for witness_utxo) */
|
|
53
|
+
value: bigint;
|
|
54
|
+
/** Sequence number (default: 0xFFFFFFFE for RBF) */
|
|
55
|
+
sequence?: number;
|
|
56
|
+
/** Full previous transaction (for non-segwit strict compliance) */
|
|
57
|
+
prevTx?: Uint8Array;
|
|
58
|
+
};
|
|
59
|
+
export type AddOutputOptions = {
|
|
60
|
+
/** Output script (scriptPubKey) */
|
|
61
|
+
script: Uint8Array;
|
|
62
|
+
/** Value in satoshis */
|
|
63
|
+
value: bigint;
|
|
64
|
+
};
|
|
65
|
+
/** Key identifier for signing ("user", "backup", or "bitgo") */
|
|
66
|
+
export type SignerKey = "user" | "backup" | "bitgo";
|
|
67
|
+
/** Specifies signer and cosigner for Taproot inputs */
|
|
68
|
+
export type SignPath = {
|
|
69
|
+
/** Key that will sign */
|
|
70
|
+
signer: SignerKey;
|
|
71
|
+
/** Key that will co-sign */
|
|
72
|
+
cosigner: SignerKey;
|
|
73
|
+
};
|
|
74
|
+
export type AddWalletInputOptions = {
|
|
75
|
+
/** Script location in wallet (chain + index) */
|
|
76
|
+
scriptId: ScriptId;
|
|
77
|
+
/** Sign path - required for p2tr/p2trMusig2 (chains 30-41) */
|
|
78
|
+
signPath?: SignPath;
|
|
79
|
+
};
|
|
80
|
+
export type AddWalletOutputOptions = {
|
|
81
|
+
/** Chain code (0/1=p2sh, 10/11=p2shP2wsh, 20/21=p2wsh, 30/31=p2tr, 40/41=p2trMusig2) */
|
|
82
|
+
chain: number;
|
|
83
|
+
/** Derivation index */
|
|
84
|
+
index: number;
|
|
85
|
+
/** Value in satoshis */
|
|
86
|
+
value: bigint;
|
|
87
|
+
};
|
|
39
88
|
export declare class BitGoPsbt {
|
|
40
|
-
|
|
41
|
-
|
|
89
|
+
protected wasm: WasmBitGoPsbt;
|
|
90
|
+
protected constructor(wasm: WasmBitGoPsbt);
|
|
91
|
+
/**
|
|
92
|
+
* Create an empty PSBT for the given network with wallet keys
|
|
93
|
+
*
|
|
94
|
+
* The wallet keys are used to set global xpubs in the PSBT, which identifies
|
|
95
|
+
* the keys that will be used for signing.
|
|
96
|
+
*
|
|
97
|
+
* For Zcash networks, use ZcashBitGoPsbt.createEmpty() instead.
|
|
98
|
+
*
|
|
99
|
+
* @param network - Network name (utxolib name like "bitcoin" or coin name like "btc")
|
|
100
|
+
* @param walletKeys - The wallet's root keys (sets global xpubs in the PSBT)
|
|
101
|
+
* @param options - Optional transaction parameters (version, lockTime)
|
|
102
|
+
* @returns A new empty BitGoPsbt instance
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* // Create empty PSBT with wallet keys
|
|
107
|
+
* const psbt = BitGoPsbt.createEmpty("bitcoin", walletKeys);
|
|
108
|
+
*
|
|
109
|
+
* // Create with custom version and lockTime
|
|
110
|
+
* const psbt = BitGoPsbt.createEmpty("bitcoin", walletKeys, { version: 1, lockTime: 500000 });
|
|
111
|
+
* ```
|
|
112
|
+
*/
|
|
113
|
+
static createEmpty(network: NetworkName, walletKeys: WalletKeysArg, options?: CreateEmptyOptions): BitGoPsbt;
|
|
42
114
|
/**
|
|
43
115
|
* Deserialize a PSBT from bytes
|
|
44
116
|
* @param bytes - The PSBT bytes
|
|
@@ -46,11 +118,147 @@ export declare class BitGoPsbt {
|
|
|
46
118
|
* @returns A BitGoPsbt instance
|
|
47
119
|
*/
|
|
48
120
|
static fromBytes(bytes: Uint8Array, network: NetworkName): BitGoPsbt;
|
|
121
|
+
/**
|
|
122
|
+
* Add an input to the PSBT
|
|
123
|
+
*
|
|
124
|
+
* This adds a transaction input and corresponding PSBT input metadata.
|
|
125
|
+
* The witness_utxo is automatically populated for modern signing compatibility.
|
|
126
|
+
*
|
|
127
|
+
* @param options - Input options (txid, vout, value, sequence)
|
|
128
|
+
* @param script - Output script of the UTXO being spent
|
|
129
|
+
* @returns The index of the newly added input
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* const inputIndex = psbt.addInput({
|
|
134
|
+
* txid: "abc123...",
|
|
135
|
+
* vout: 0,
|
|
136
|
+
* value: 100000n,
|
|
137
|
+
* }, outputScript);
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
addInput(options: AddInputOptions, script: Uint8Array): number;
|
|
141
|
+
/**
|
|
142
|
+
* Add an output to the PSBT
|
|
143
|
+
*
|
|
144
|
+
* @param options - Output options (script, value)
|
|
145
|
+
* @returns The index of the newly added output
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* const outputIndex = psbt.addOutput({
|
|
150
|
+
* script: outputScript,
|
|
151
|
+
* value: 50000n,
|
|
152
|
+
* });
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
addOutput(options: AddOutputOptions): number;
|
|
156
|
+
/**
|
|
157
|
+
* Add a wallet input with full PSBT metadata
|
|
158
|
+
*
|
|
159
|
+
* This is a higher-level method that adds an input and populates all required
|
|
160
|
+
* PSBT fields (scripts, derivation info, etc.) based on the wallet's chain type.
|
|
161
|
+
*
|
|
162
|
+
* For p2sh/p2shP2wsh/p2wsh: Sets bip32Derivation, witnessScript, redeemScript (signPath not needed)
|
|
163
|
+
* For p2tr/p2trMusig2 script path: Sets tapLeafScript, tapBip32Derivation (signPath required)
|
|
164
|
+
* For p2trMusig2 key path: Sets tapInternalKey, tapMerkleRoot, tapBip32Derivation, musig2 participants (signPath required)
|
|
165
|
+
*
|
|
166
|
+
* @param inputOptions - Common input options (txid, vout, value, sequence)
|
|
167
|
+
* @param walletKeys - The wallet's root keys
|
|
168
|
+
* @param walletOptions - Wallet-specific options (scriptId, signPath, prevTx)
|
|
169
|
+
* @returns The index of the newly added input
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* // Add a p2shP2wsh input (signPath not needed)
|
|
174
|
+
* const inputIndex = psbt.addWalletInput(
|
|
175
|
+
* { txid: "abc123...", vout: 0, value: 100000n },
|
|
176
|
+
* walletKeys,
|
|
177
|
+
* { scriptId: { chain: 10, index: 0 } }, // p2shP2wsh external
|
|
178
|
+
* );
|
|
179
|
+
*
|
|
180
|
+
* // Add a p2trMusig2 key path input (signPath required)
|
|
181
|
+
* const inputIndex = psbt.addWalletInput(
|
|
182
|
+
* { txid: "def456...", vout: 1, value: 50000n },
|
|
183
|
+
* walletKeys,
|
|
184
|
+
* { scriptId: { chain: 40, index: 5 }, signPath: { signer: "user", cosigner: "bitgo" } },
|
|
185
|
+
* );
|
|
186
|
+
*
|
|
187
|
+
* // Add p2trMusig2 with backup key (script path spend)
|
|
188
|
+
* const inputIndex = psbt.addWalletInput(
|
|
189
|
+
* { txid: "ghi789...", vout: 0, value: 75000n },
|
|
190
|
+
* walletKeys,
|
|
191
|
+
* { scriptId: { chain: 40, index: 3 }, signPath: { signer: "user", cosigner: "backup" } },
|
|
192
|
+
* );
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
addWalletInput(inputOptions: AddInputOptions, walletKeys: WalletKeysArg, walletOptions: AddWalletInputOptions): number;
|
|
196
|
+
/**
|
|
197
|
+
* Add a wallet output with full PSBT metadata
|
|
198
|
+
*
|
|
199
|
+
* This creates a verifiable wallet output (typically for change) with all required
|
|
200
|
+
* PSBT fields (scripts, derivation info) based on the wallet's chain type.
|
|
201
|
+
*
|
|
202
|
+
* For p2sh/p2shP2wsh/p2wsh: Sets bip32Derivation, witnessScript, redeemScript
|
|
203
|
+
* For p2tr/p2trMusig2: Sets tapInternalKey, tapBip32Derivation
|
|
204
|
+
*
|
|
205
|
+
* @param walletKeys - The wallet's root keys
|
|
206
|
+
* @param options - Output options including chain, index, and value
|
|
207
|
+
* @returns The index of the newly added output
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* // Add a p2shP2wsh change output
|
|
212
|
+
* const outputIndex = psbt.addWalletOutput(walletKeys, {
|
|
213
|
+
* chain: 11, // p2shP2wsh internal (change)
|
|
214
|
+
* index: 0,
|
|
215
|
+
* value: 50000n,
|
|
216
|
+
* });
|
|
217
|
+
*
|
|
218
|
+
* // Add a p2trMusig2 change output
|
|
219
|
+
* const outputIndex = psbt.addWalletOutput(walletKeys, {
|
|
220
|
+
* chain: 41, // p2trMusig2 internal (change)
|
|
221
|
+
* index: 5,
|
|
222
|
+
* value: 25000n,
|
|
223
|
+
* });
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
addWalletOutput(walletKeys: WalletKeysArg, options: AddWalletOutputOptions): number;
|
|
227
|
+
/**
|
|
228
|
+
* Add a replay protection input to the PSBT
|
|
229
|
+
*
|
|
230
|
+
* Replay protection inputs are P2SH-P2PK inputs used on forked networks to prevent
|
|
231
|
+
* transaction replay attacks. They use a simple pubkey script without wallet derivation.
|
|
232
|
+
*
|
|
233
|
+
* @param inputOptions - Common input options (txid, vout, value, sequence)
|
|
234
|
+
* @param key - ECPair containing the public key for the replay protection input
|
|
235
|
+
* @returns The index of the newly added input
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```typescript
|
|
239
|
+
* // Add a replay protection input using ECPair
|
|
240
|
+
* const inputIndex = psbt.addReplayProtectionInput(
|
|
241
|
+
* { txid: "abc123...", vout: 0, value: 1000n },
|
|
242
|
+
* replayProtectionKey,
|
|
243
|
+
* );
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
addReplayProtectionInput(inputOptions: AddInputOptions, key: ECPairArg): number;
|
|
49
247
|
/**
|
|
50
248
|
* Get the unsigned transaction ID
|
|
51
249
|
* @returns The unsigned transaction ID
|
|
52
250
|
*/
|
|
53
251
|
unsignedTxid(): string;
|
|
252
|
+
/**
|
|
253
|
+
* Get the transaction version
|
|
254
|
+
* @returns The transaction version number
|
|
255
|
+
*/
|
|
256
|
+
get version(): number;
|
|
257
|
+
/**
|
|
258
|
+
* Get the transaction lock time
|
|
259
|
+
* @returns The transaction lock time
|
|
260
|
+
*/
|
|
261
|
+
get lockTime(): number;
|
|
54
262
|
/**
|
|
55
263
|
* Parse transaction with wallet keys to identify wallet inputs/outputs
|
|
56
264
|
* @param walletKeys - The wallet keys to use for identification
|
|
@@ -11,6 +11,33 @@ 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
|
+
* For Zcash networks, use ZcashBitGoPsbt.createEmpty() instead.
|
|
21
|
+
*
|
|
22
|
+
* @param network - Network name (utxolib name like "bitcoin" or coin name like "btc")
|
|
23
|
+
* @param walletKeys - The wallet's root keys (sets global xpubs in the PSBT)
|
|
24
|
+
* @param options - Optional transaction parameters (version, lockTime)
|
|
25
|
+
* @returns A new empty BitGoPsbt instance
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```typescript
|
|
29
|
+
* // Create empty PSBT with wallet keys
|
|
30
|
+
* const psbt = BitGoPsbt.createEmpty("bitcoin", walletKeys);
|
|
31
|
+
*
|
|
32
|
+
* // Create with custom version and lockTime
|
|
33
|
+
* const psbt = BitGoPsbt.createEmpty("bitcoin", walletKeys, { version: 1, lockTime: 500000 });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
static createEmpty(network, walletKeys, options) {
|
|
37
|
+
const keys = RootWalletKeys_js_1.RootWalletKeys.from(walletKeys);
|
|
38
|
+
const wasm = wasm_utxo_js_1.BitGoPsbt.create_empty(network, keys.wasm, options?.version, options?.lockTime);
|
|
39
|
+
return new BitGoPsbt(wasm);
|
|
40
|
+
}
|
|
14
41
|
/**
|
|
15
42
|
* Deserialize a PSBT from bytes
|
|
16
43
|
* @param bytes - The PSBT bytes
|
|
@@ -21,6 +48,145 @@ class BitGoPsbt {
|
|
|
21
48
|
const wasm = wasm_utxo_js_1.BitGoPsbt.from_bytes(bytes, network);
|
|
22
49
|
return new BitGoPsbt(wasm);
|
|
23
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Add an input to the PSBT
|
|
53
|
+
*
|
|
54
|
+
* This adds a transaction input and corresponding PSBT input metadata.
|
|
55
|
+
* The witness_utxo is automatically populated for modern signing compatibility.
|
|
56
|
+
*
|
|
57
|
+
* @param options - Input options (txid, vout, value, sequence)
|
|
58
|
+
* @param script - Output script of the UTXO being spent
|
|
59
|
+
* @returns The index of the newly added input
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const inputIndex = psbt.addInput({
|
|
64
|
+
* txid: "abc123...",
|
|
65
|
+
* vout: 0,
|
|
66
|
+
* value: 100000n,
|
|
67
|
+
* }, outputScript);
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
addInput(options, script) {
|
|
71
|
+
return this.wasm.add_input(options.txid, options.vout, options.value, script, options.sequence, options.prevTx);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Add an output to the PSBT
|
|
75
|
+
*
|
|
76
|
+
* @param options - Output options (script, value)
|
|
77
|
+
* @returns The index of the newly added output
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* const outputIndex = psbt.addOutput({
|
|
82
|
+
* script: outputScript,
|
|
83
|
+
* value: 50000n,
|
|
84
|
+
* });
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
addOutput(options) {
|
|
88
|
+
return this.wasm.add_output(options.script, options.value);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Add a wallet input with full PSBT metadata
|
|
92
|
+
*
|
|
93
|
+
* This is a higher-level method that adds an input and populates all required
|
|
94
|
+
* PSBT fields (scripts, derivation info, etc.) based on the wallet's chain type.
|
|
95
|
+
*
|
|
96
|
+
* For p2sh/p2shP2wsh/p2wsh: Sets bip32Derivation, witnessScript, redeemScript (signPath not needed)
|
|
97
|
+
* For p2tr/p2trMusig2 script path: Sets tapLeafScript, tapBip32Derivation (signPath required)
|
|
98
|
+
* For p2trMusig2 key path: Sets tapInternalKey, tapMerkleRoot, tapBip32Derivation, musig2 participants (signPath required)
|
|
99
|
+
*
|
|
100
|
+
* @param inputOptions - Common input options (txid, vout, value, sequence)
|
|
101
|
+
* @param walletKeys - The wallet's root keys
|
|
102
|
+
* @param walletOptions - Wallet-specific options (scriptId, signPath, prevTx)
|
|
103
|
+
* @returns The index of the newly added input
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* // Add a p2shP2wsh input (signPath not needed)
|
|
108
|
+
* const inputIndex = psbt.addWalletInput(
|
|
109
|
+
* { txid: "abc123...", vout: 0, value: 100000n },
|
|
110
|
+
* walletKeys,
|
|
111
|
+
* { scriptId: { chain: 10, index: 0 } }, // p2shP2wsh external
|
|
112
|
+
* );
|
|
113
|
+
*
|
|
114
|
+
* // Add a p2trMusig2 key path input (signPath required)
|
|
115
|
+
* const inputIndex = psbt.addWalletInput(
|
|
116
|
+
* { txid: "def456...", vout: 1, value: 50000n },
|
|
117
|
+
* walletKeys,
|
|
118
|
+
* { scriptId: { chain: 40, index: 5 }, signPath: { signer: "user", cosigner: "bitgo" } },
|
|
119
|
+
* );
|
|
120
|
+
*
|
|
121
|
+
* // Add p2trMusig2 with backup key (script path spend)
|
|
122
|
+
* const inputIndex = psbt.addWalletInput(
|
|
123
|
+
* { txid: "ghi789...", vout: 0, value: 75000n },
|
|
124
|
+
* walletKeys,
|
|
125
|
+
* { scriptId: { chain: 40, index: 3 }, signPath: { signer: "user", cosigner: "backup" } },
|
|
126
|
+
* );
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
addWalletInput(inputOptions, walletKeys, walletOptions) {
|
|
130
|
+
const keys = RootWalletKeys_js_1.RootWalletKeys.from(walletKeys);
|
|
131
|
+
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);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Add a wallet output with full PSBT metadata
|
|
135
|
+
*
|
|
136
|
+
* This creates a verifiable wallet output (typically for change) with all required
|
|
137
|
+
* PSBT fields (scripts, derivation info) based on the wallet's chain type.
|
|
138
|
+
*
|
|
139
|
+
* For p2sh/p2shP2wsh/p2wsh: Sets bip32Derivation, witnessScript, redeemScript
|
|
140
|
+
* For p2tr/p2trMusig2: Sets tapInternalKey, tapBip32Derivation
|
|
141
|
+
*
|
|
142
|
+
* @param walletKeys - The wallet's root keys
|
|
143
|
+
* @param options - Output options including chain, index, and value
|
|
144
|
+
* @returns The index of the newly added output
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* // Add a p2shP2wsh change output
|
|
149
|
+
* const outputIndex = psbt.addWalletOutput(walletKeys, {
|
|
150
|
+
* chain: 11, // p2shP2wsh internal (change)
|
|
151
|
+
* index: 0,
|
|
152
|
+
* value: 50000n,
|
|
153
|
+
* });
|
|
154
|
+
*
|
|
155
|
+
* // Add a p2trMusig2 change output
|
|
156
|
+
* const outputIndex = psbt.addWalletOutput(walletKeys, {
|
|
157
|
+
* chain: 41, // p2trMusig2 internal (change)
|
|
158
|
+
* index: 5,
|
|
159
|
+
* value: 25000n,
|
|
160
|
+
* });
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
addWalletOutput(walletKeys, options) {
|
|
164
|
+
const keys = RootWalletKeys_js_1.RootWalletKeys.from(walletKeys);
|
|
165
|
+
return this.wasm.add_wallet_output(options.chain, options.index, options.value, keys.wasm);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Add a replay protection input to the PSBT
|
|
169
|
+
*
|
|
170
|
+
* Replay protection inputs are P2SH-P2PK inputs used on forked networks to prevent
|
|
171
|
+
* transaction replay attacks. They use a simple pubkey script without wallet derivation.
|
|
172
|
+
*
|
|
173
|
+
* @param inputOptions - Common input options (txid, vout, value, sequence)
|
|
174
|
+
* @param key - ECPair containing the public key for the replay protection input
|
|
175
|
+
* @returns The index of the newly added input
|
|
176
|
+
*
|
|
177
|
+
* @example
|
|
178
|
+
* ```typescript
|
|
179
|
+
* // Add a replay protection input using ECPair
|
|
180
|
+
* const inputIndex = psbt.addReplayProtectionInput(
|
|
181
|
+
* { txid: "abc123...", vout: 0, value: 1000n },
|
|
182
|
+
* replayProtectionKey,
|
|
183
|
+
* );
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
addReplayProtectionInput(inputOptions, key) {
|
|
187
|
+
const ecpair = ecpair_js_1.ECPair.from(key);
|
|
188
|
+
return this.wasm.add_replay_protection_input(ecpair.wasm, inputOptions.txid, inputOptions.vout, inputOptions.value, inputOptions.sequence);
|
|
189
|
+
}
|
|
24
190
|
/**
|
|
25
191
|
* Get the unsigned transaction ID
|
|
26
192
|
* @returns The unsigned transaction ID
|
|
@@ -28,6 +194,20 @@ class BitGoPsbt {
|
|
|
28
194
|
unsignedTxid() {
|
|
29
195
|
return this.wasm.unsigned_txid();
|
|
30
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* Get the transaction version
|
|
199
|
+
* @returns The transaction version number
|
|
200
|
+
*/
|
|
201
|
+
get version() {
|
|
202
|
+
return this.wasm.version();
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Get the transaction lock time
|
|
206
|
+
* @returns The transaction lock time
|
|
207
|
+
*/
|
|
208
|
+
get lockTime() {
|
|
209
|
+
return this.wasm.lock_time();
|
|
210
|
+
}
|
|
31
211
|
/**
|
|
32
212
|
* Parse transaction with wallet keys to identify wallet inputs/outputs
|
|
33
213
|
* @param walletKeys - The wallet keys to use for identification
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { type WalletKeysArg } from "./RootWalletKeys.js";
|
|
2
|
+
import { BitGoPsbt, type CreateEmptyOptions } from "./BitGoPsbt.js";
|
|
3
|
+
/** Zcash network names */
|
|
4
|
+
export type ZcashNetworkName = "zcash" | "zcashTest" | "zec" | "tzec";
|
|
5
|
+
/** Options for creating an empty Zcash PSBT (preferred method using block height) */
|
|
6
|
+
export type CreateEmptyZcashOptions = CreateEmptyOptions & {
|
|
7
|
+
/** Block height to determine consensus branch ID automatically */
|
|
8
|
+
blockHeight: number;
|
|
9
|
+
/** Zcash version group ID (defaults to Sapling: 0x892F2085) */
|
|
10
|
+
versionGroupId?: number;
|
|
11
|
+
/** Zcash transaction expiry height */
|
|
12
|
+
expiryHeight?: number;
|
|
13
|
+
};
|
|
14
|
+
/** Options for creating an empty Zcash PSBT with explicit consensus branch ID (advanced use) */
|
|
15
|
+
export type CreateEmptyZcashWithConsensusBranchIdOptions = CreateEmptyOptions & {
|
|
16
|
+
/** Zcash consensus branch ID (required, e.g., 0xC2D6D0B4 for NU5, 0x76B809BB for Sapling) */
|
|
17
|
+
consensusBranchId: number;
|
|
18
|
+
/** Zcash version group ID (defaults to Sapling: 0x892F2085) */
|
|
19
|
+
versionGroupId?: number;
|
|
20
|
+
/** Zcash transaction expiry height */
|
|
21
|
+
expiryHeight?: number;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Zcash-specific PSBT implementation
|
|
25
|
+
*
|
|
26
|
+
* This class extends BitGoPsbt with Zcash-specific functionality:
|
|
27
|
+
* - Required consensus branch ID for sighash computation
|
|
28
|
+
* - Version group ID for Zcash transaction format
|
|
29
|
+
* - Expiry height for transaction validity
|
|
30
|
+
*
|
|
31
|
+
* All Zcash-specific getters return non-optional types since they're
|
|
32
|
+
* guaranteed to be present for Zcash PSBTs.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* // Create a new Zcash PSBT
|
|
37
|
+
* const psbt = ZcashBitGoPsbt.createEmpty("zcash", walletKeys, {
|
|
38
|
+
* consensusBranchId: 0x76B809BB, // Sapling
|
|
39
|
+
* });
|
|
40
|
+
*
|
|
41
|
+
* // Deserialize from bytes
|
|
42
|
+
* const psbt = ZcashBitGoPsbt.fromBytes(bytes, "zcash");
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare class ZcashBitGoPsbt extends BitGoPsbt {
|
|
46
|
+
/**
|
|
47
|
+
* Create an empty Zcash PSBT with consensus branch ID determined from block height
|
|
48
|
+
*
|
|
49
|
+
* **This is the preferred method for creating Zcash PSBTs.** It automatically determines
|
|
50
|
+
* the correct consensus branch ID based on the network and block height using Zcash
|
|
51
|
+
* network upgrade activation heights, eliminating the need to manually look up branch IDs.
|
|
52
|
+
*
|
|
53
|
+
* @param network - Zcash network name ("zcash", "zcashTest", "zec", "tzec")
|
|
54
|
+
* @param walletKeys - The wallet's root keys (sets global xpubs in the PSBT)
|
|
55
|
+
* @param options - Options including blockHeight to determine consensus rules
|
|
56
|
+
* @returns A new ZcashBitGoPsbt instance
|
|
57
|
+
* @throws Error if block height is before Overwinter activation
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* // Create PSBT for a specific block height (recommended)
|
|
62
|
+
* const psbt = ZcashBitGoPsbt.createEmpty("zcash", walletKeys, {
|
|
63
|
+
* blockHeight: 1687104, // Automatically uses Nu5 branch ID
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* // Create PSBT for current block height
|
|
67
|
+
* const currentHeight = await getBlockHeight();
|
|
68
|
+
* const psbt = ZcashBitGoPsbt.createEmpty("zcash", walletKeys, {
|
|
69
|
+
* blockHeight: currentHeight,
|
|
70
|
+
* });
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
static createEmpty(network: ZcashNetworkName, walletKeys: WalletKeysArg, options: CreateEmptyZcashOptions): ZcashBitGoPsbt;
|
|
74
|
+
/**
|
|
75
|
+
* Create an empty Zcash PSBT with explicit consensus branch ID
|
|
76
|
+
*
|
|
77
|
+
* **Advanced use only.** This method requires manually specifying the consensus branch ID.
|
|
78
|
+
* In most cases, you should use `createEmpty()` instead, which automatically determines
|
|
79
|
+
* the correct branch ID from the block height.
|
|
80
|
+
*
|
|
81
|
+
* @param network - Zcash network name ("zcash", "zcashTest", "zec", "tzec")
|
|
82
|
+
* @param walletKeys - The wallet's root keys (sets global xpubs in the PSBT)
|
|
83
|
+
* @param options - Zcash-specific options including required consensusBranchId
|
|
84
|
+
* @returns A new ZcashBitGoPsbt instance
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* // Only use this if you need explicit control over the branch ID
|
|
89
|
+
* const psbt = ZcashBitGoPsbt.createEmptyWithConsensusBranchId("zcash", walletKeys, {
|
|
90
|
+
* consensusBranchId: 0xC2D6D0B4, // Nu5 branch ID
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
static createEmptyWithConsensusBranchId(network: ZcashNetworkName, walletKeys: WalletKeysArg, options: CreateEmptyZcashWithConsensusBranchIdOptions): ZcashBitGoPsbt;
|
|
95
|
+
/**
|
|
96
|
+
* Deserialize a Zcash PSBT from bytes
|
|
97
|
+
*
|
|
98
|
+
* @param bytes - The PSBT bytes
|
|
99
|
+
* @param network - Zcash network name ("zcash", "zcashTest", "zec", "tzec")
|
|
100
|
+
* @returns A ZcashBitGoPsbt instance
|
|
101
|
+
*/
|
|
102
|
+
static fromBytes(bytes: Uint8Array, network: ZcashNetworkName): ZcashBitGoPsbt;
|
|
103
|
+
/**
|
|
104
|
+
* Get the Zcash version group ID
|
|
105
|
+
* @returns The version group ID (e.g., 0x892F2085 for Sapling)
|
|
106
|
+
*/
|
|
107
|
+
get versionGroupId(): number;
|
|
108
|
+
/**
|
|
109
|
+
* Get the Zcash expiry height
|
|
110
|
+
* @returns The expiry height (0 if not set)
|
|
111
|
+
*/
|
|
112
|
+
get expiryHeight(): number;
|
|
113
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ZcashBitGoPsbt = void 0;
|
|
4
|
+
const wasm_utxo_js_1 = require("../wasm/wasm_utxo.js");
|
|
5
|
+
const RootWalletKeys_js_1 = require("./RootWalletKeys.js");
|
|
6
|
+
const BitGoPsbt_js_1 = require("./BitGoPsbt.js");
|
|
7
|
+
/**
|
|
8
|
+
* Zcash-specific PSBT implementation
|
|
9
|
+
*
|
|
10
|
+
* This class extends BitGoPsbt with Zcash-specific functionality:
|
|
11
|
+
* - Required consensus branch ID for sighash computation
|
|
12
|
+
* - Version group ID for Zcash transaction format
|
|
13
|
+
* - Expiry height for transaction validity
|
|
14
|
+
*
|
|
15
|
+
* All Zcash-specific getters return non-optional types since they're
|
|
16
|
+
* guaranteed to be present for Zcash PSBTs.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* // Create a new Zcash PSBT
|
|
21
|
+
* const psbt = ZcashBitGoPsbt.createEmpty("zcash", walletKeys, {
|
|
22
|
+
* consensusBranchId: 0x76B809BB, // Sapling
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* // Deserialize from bytes
|
|
26
|
+
* const psbt = ZcashBitGoPsbt.fromBytes(bytes, "zcash");
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
class ZcashBitGoPsbt extends BitGoPsbt_js_1.BitGoPsbt {
|
|
30
|
+
/**
|
|
31
|
+
* Create an empty Zcash PSBT with consensus branch ID determined from block height
|
|
32
|
+
*
|
|
33
|
+
* **This is the preferred method for creating Zcash PSBTs.** It automatically determines
|
|
34
|
+
* the correct consensus branch ID based on the network and block height using Zcash
|
|
35
|
+
* network upgrade activation heights, eliminating the need to manually look up branch IDs.
|
|
36
|
+
*
|
|
37
|
+
* @param network - Zcash network name ("zcash", "zcashTest", "zec", "tzec")
|
|
38
|
+
* @param walletKeys - The wallet's root keys (sets global xpubs in the PSBT)
|
|
39
|
+
* @param options - Options including blockHeight to determine consensus rules
|
|
40
|
+
* @returns A new ZcashBitGoPsbt instance
|
|
41
|
+
* @throws Error if block height is before Overwinter activation
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* // Create PSBT for a specific block height (recommended)
|
|
46
|
+
* const psbt = ZcashBitGoPsbt.createEmpty("zcash", walletKeys, {
|
|
47
|
+
* blockHeight: 1687104, // Automatically uses Nu5 branch ID
|
|
48
|
+
* });
|
|
49
|
+
*
|
|
50
|
+
* // Create PSBT for current block height
|
|
51
|
+
* const currentHeight = await getBlockHeight();
|
|
52
|
+
* const psbt = ZcashBitGoPsbt.createEmpty("zcash", walletKeys, {
|
|
53
|
+
* blockHeight: currentHeight,
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
static createEmpty(network, walletKeys, options) {
|
|
58
|
+
const keys = RootWalletKeys_js_1.RootWalletKeys.from(walletKeys);
|
|
59
|
+
const wasm = wasm_utxo_js_1.BitGoPsbt.create_empty_zcash_at_height(network, keys.wasm, options.blockHeight, options.version, options.lockTime, options.versionGroupId, options.expiryHeight);
|
|
60
|
+
return new ZcashBitGoPsbt(wasm);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Create an empty Zcash PSBT with explicit consensus branch ID
|
|
64
|
+
*
|
|
65
|
+
* **Advanced use only.** This method requires manually specifying the consensus branch ID.
|
|
66
|
+
* In most cases, you should use `createEmpty()` instead, which automatically determines
|
|
67
|
+
* the correct branch ID from the block height.
|
|
68
|
+
*
|
|
69
|
+
* @param network - Zcash network name ("zcash", "zcashTest", "zec", "tzec")
|
|
70
|
+
* @param walletKeys - The wallet's root keys (sets global xpubs in the PSBT)
|
|
71
|
+
* @param options - Zcash-specific options including required consensusBranchId
|
|
72
|
+
* @returns A new ZcashBitGoPsbt instance
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* // Only use this if you need explicit control over the branch ID
|
|
77
|
+
* const psbt = ZcashBitGoPsbt.createEmptyWithConsensusBranchId("zcash", walletKeys, {
|
|
78
|
+
* consensusBranchId: 0xC2D6D0B4, // Nu5 branch ID
|
|
79
|
+
* });
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
static createEmptyWithConsensusBranchId(network, walletKeys, options) {
|
|
83
|
+
const keys = RootWalletKeys_js_1.RootWalletKeys.from(walletKeys);
|
|
84
|
+
const wasm = wasm_utxo_js_1.BitGoPsbt.create_empty_zcash(network, keys.wasm, options.consensusBranchId, options.version, options.lockTime, options.versionGroupId, options.expiryHeight);
|
|
85
|
+
return new ZcashBitGoPsbt(wasm);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Deserialize a Zcash PSBT from bytes
|
|
89
|
+
*
|
|
90
|
+
* @param bytes - The PSBT bytes
|
|
91
|
+
* @param network - Zcash network name ("zcash", "zcashTest", "zec", "tzec")
|
|
92
|
+
* @returns A ZcashBitGoPsbt instance
|
|
93
|
+
*/
|
|
94
|
+
static fromBytes(bytes, network) {
|
|
95
|
+
const wasm = wasm_utxo_js_1.BitGoPsbt.from_bytes(bytes, network);
|
|
96
|
+
return new ZcashBitGoPsbt(wasm);
|
|
97
|
+
}
|
|
98
|
+
// --- Zcash-specific getters ---
|
|
99
|
+
/**
|
|
100
|
+
* Get the Zcash version group ID
|
|
101
|
+
* @returns The version group ID (e.g., 0x892F2085 for Sapling)
|
|
102
|
+
*/
|
|
103
|
+
get versionGroupId() {
|
|
104
|
+
return this.wasm.version_group_id();
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get the Zcash expiry height
|
|
108
|
+
* @returns The expiry height (0 if not set)
|
|
109
|
+
*/
|
|
110
|
+
get expiryHeight() {
|
|
111
|
+
return this.wasm.expiry_height();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.ZcashBitGoPsbt = ZcashBitGoPsbt;
|