@bitgo/wasm-utxo 1.18.0 → 1.20.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/dist/cjs/js/fixedScriptWallet/BitGoPsbt.d.ts +45 -4
- package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.js +52 -43
- package/dist/cjs/js/fixedScriptWallet/Dimensions.d.ts +65 -0
- package/dist/cjs/js/fixedScriptWallet/Dimensions.js +83 -0
- package/dist/cjs/js/fixedScriptWallet/index.d.ts +1 -0
- package/dist/cjs/js/fixedScriptWallet/index.js +3 -1
- package/dist/cjs/js/index.d.ts +1 -0
- package/dist/cjs/js/index.js +3 -1
- package/dist/cjs/js/transaction.d.ts +8 -0
- package/dist/cjs/js/transaction.js +10 -0
- package/dist/cjs/js/wasm/wasm_utxo.d.ts +82 -0
- package/dist/cjs/js/wasm/wasm_utxo.js +223 -0
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/cjs/js/wasm/wasm_utxo_bg.wasm.d.ts +38 -26
- package/dist/esm/js/fixedScriptWallet/BitGoPsbt.d.ts +45 -4
- package/dist/esm/js/fixedScriptWallet/BitGoPsbt.js +52 -43
- package/dist/esm/js/fixedScriptWallet/Dimensions.d.ts +65 -0
- package/dist/esm/js/fixedScriptWallet/Dimensions.js +79 -0
- package/dist/esm/js/fixedScriptWallet/index.d.ts +1 -0
- package/dist/esm/js/fixedScriptWallet/index.js +1 -0
- package/dist/esm/js/index.d.ts +1 -0
- package/dist/esm/js/index.js +1 -0
- package/dist/esm/js/transaction.d.ts +8 -0
- package/dist/esm/js/transaction.js +10 -0
- package/dist/esm/js/wasm/wasm_utxo.d.ts +82 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.js +222 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm +0 -0
- package/dist/esm/js/wasm/wasm_utxo_bg.wasm.d.ts +38 -26
- package/package.json +1 -1
|
@@ -4,9 +4,16 @@ import { ReplayProtection } from "./ReplayProtection.js";
|
|
|
4
4
|
import { BIP32 } from "../bip32.js";
|
|
5
5
|
import { ECPair } from "../ecpair.js";
|
|
6
6
|
export class BitGoPsbt {
|
|
7
|
-
|
|
8
|
-
constructor(
|
|
9
|
-
this.
|
|
7
|
+
_wasm;
|
|
8
|
+
constructor(_wasm) {
|
|
9
|
+
this._wasm = _wasm;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Get the underlying WASM instance
|
|
13
|
+
* @internal - for use by other wasm-utxo modules
|
|
14
|
+
*/
|
|
15
|
+
get wasm() {
|
|
16
|
+
return this._wasm;
|
|
10
17
|
}
|
|
11
18
|
/**
|
|
12
19
|
* Create an empty PSBT for the given network with wallet keys
|
|
@@ -32,8 +39,8 @@ export class BitGoPsbt {
|
|
|
32
39
|
*/
|
|
33
40
|
static createEmpty(network, walletKeys, options) {
|
|
34
41
|
const keys = RootWalletKeys.from(walletKeys);
|
|
35
|
-
const
|
|
36
|
-
return new BitGoPsbt(
|
|
42
|
+
const wasmPsbt = WasmBitGoPsbt.create_empty(network, keys.wasm, options?.version, options?.lockTime);
|
|
43
|
+
return new BitGoPsbt(wasmPsbt);
|
|
37
44
|
}
|
|
38
45
|
/**
|
|
39
46
|
* Deserialize a PSBT from bytes
|
|
@@ -65,24 +72,26 @@ export class BitGoPsbt {
|
|
|
65
72
|
* ```
|
|
66
73
|
*/
|
|
67
74
|
addInput(options, script) {
|
|
68
|
-
return this.
|
|
75
|
+
return this._wasm.add_input(options.txid, options.vout, options.value, script, options.sequence, options.prevTx);
|
|
69
76
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
77
|
+
addOutput(scriptOrOptions, value) {
|
|
78
|
+
if (scriptOrOptions instanceof Uint8Array || typeof scriptOrOptions === "string") {
|
|
79
|
+
if (value === undefined) {
|
|
80
|
+
throw new Error("Value is required when passing a script or address");
|
|
81
|
+
}
|
|
82
|
+
if (scriptOrOptions instanceof Uint8Array) {
|
|
83
|
+
return this._wasm.add_output(scriptOrOptions, value);
|
|
84
|
+
}
|
|
85
|
+
return this._wasm.add_output_with_address(scriptOrOptions, value);
|
|
86
|
+
}
|
|
87
|
+
const options = scriptOrOptions;
|
|
88
|
+
if ("script" in options) {
|
|
89
|
+
return this._wasm.add_output(options.script, options.value);
|
|
90
|
+
}
|
|
91
|
+
if ("address" in options) {
|
|
92
|
+
return this._wasm.add_output_with_address(options.address, options.value);
|
|
93
|
+
}
|
|
94
|
+
throw new Error("Invalid output options");
|
|
86
95
|
}
|
|
87
96
|
/**
|
|
88
97
|
* Add a wallet input with full PSBT metadata
|
|
@@ -125,7 +134,7 @@ export class BitGoPsbt {
|
|
|
125
134
|
*/
|
|
126
135
|
addWalletInput(inputOptions, walletKeys, walletOptions) {
|
|
127
136
|
const keys = RootWalletKeys.from(walletKeys);
|
|
128
|
-
return this.
|
|
137
|
+
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);
|
|
129
138
|
}
|
|
130
139
|
/**
|
|
131
140
|
* Add a wallet output with full PSBT metadata
|
|
@@ -159,7 +168,7 @@ export class BitGoPsbt {
|
|
|
159
168
|
*/
|
|
160
169
|
addWalletOutput(walletKeys, options) {
|
|
161
170
|
const keys = RootWalletKeys.from(walletKeys);
|
|
162
|
-
return this.
|
|
171
|
+
return this._wasm.add_wallet_output(options.chain, options.index, options.value, keys.wasm);
|
|
163
172
|
}
|
|
164
173
|
/**
|
|
165
174
|
* Add a replay protection input to the PSBT
|
|
@@ -182,28 +191,28 @@ export class BitGoPsbt {
|
|
|
182
191
|
*/
|
|
183
192
|
addReplayProtectionInput(inputOptions, key) {
|
|
184
193
|
const ecpair = ECPair.from(key);
|
|
185
|
-
return this.
|
|
194
|
+
return this._wasm.add_replay_protection_input(ecpair.wasm, inputOptions.txid, inputOptions.vout, inputOptions.value, inputOptions.sequence);
|
|
186
195
|
}
|
|
187
196
|
/**
|
|
188
197
|
* Get the unsigned transaction ID
|
|
189
198
|
* @returns The unsigned transaction ID
|
|
190
199
|
*/
|
|
191
200
|
unsignedTxid() {
|
|
192
|
-
return this.
|
|
201
|
+
return this._wasm.unsigned_txid();
|
|
193
202
|
}
|
|
194
203
|
/**
|
|
195
204
|
* Get the transaction version
|
|
196
205
|
* @returns The transaction version number
|
|
197
206
|
*/
|
|
198
207
|
get version() {
|
|
199
|
-
return this.
|
|
208
|
+
return this._wasm.version();
|
|
200
209
|
}
|
|
201
210
|
/**
|
|
202
211
|
* Get the transaction lock time
|
|
203
212
|
* @returns The transaction lock time
|
|
204
213
|
*/
|
|
205
214
|
get lockTime() {
|
|
206
|
-
return this.
|
|
215
|
+
return this._wasm.lock_time();
|
|
207
216
|
}
|
|
208
217
|
/**
|
|
209
218
|
* Parse transaction with wallet keys to identify wallet inputs/outputs
|
|
@@ -214,9 +223,9 @@ export class BitGoPsbt {
|
|
|
214
223
|
*/
|
|
215
224
|
parseTransactionWithWalletKeys(walletKeys, replayProtection, payGoPubkeys) {
|
|
216
225
|
const keys = RootWalletKeys.from(walletKeys);
|
|
217
|
-
const rp = ReplayProtection.from(replayProtection, this.
|
|
226
|
+
const rp = ReplayProtection.from(replayProtection, this._wasm.network());
|
|
218
227
|
const pubkeys = payGoPubkeys?.map((arg) => ECPair.from(arg).wasm);
|
|
219
|
-
return this.
|
|
228
|
+
return this._wasm.parse_transaction_with_wallet_keys(keys.wasm, rp.wasm, pubkeys);
|
|
220
229
|
}
|
|
221
230
|
/**
|
|
222
231
|
* Parse outputs with wallet keys to identify which outputs belong to a wallet
|
|
@@ -233,7 +242,7 @@ export class BitGoPsbt {
|
|
|
233
242
|
parseOutputsWithWalletKeys(walletKeys, payGoPubkeys) {
|
|
234
243
|
const keys = RootWalletKeys.from(walletKeys);
|
|
235
244
|
const pubkeys = payGoPubkeys?.map((arg) => ECPair.from(arg).wasm);
|
|
236
|
-
return this.
|
|
245
|
+
return this._wasm.parse_outputs_with_wallet_keys(keys.wasm, pubkeys);
|
|
237
246
|
}
|
|
238
247
|
/**
|
|
239
248
|
* Add a PayGo attestation to a PSBT output
|
|
@@ -247,7 +256,7 @@ export class BitGoPsbt {
|
|
|
247
256
|
* @throws Error if output index is out of bounds or entropy is not 64 bytes
|
|
248
257
|
*/
|
|
249
258
|
addPayGoAttestation(outputIndex, entropy, signature) {
|
|
250
|
-
this.
|
|
259
|
+
this._wasm.add_paygo_attestation(outputIndex, entropy, signature);
|
|
251
260
|
}
|
|
252
261
|
/**
|
|
253
262
|
* Verify if a valid signature exists for a given key at the specified input index.
|
|
@@ -288,11 +297,11 @@ export class BitGoPsbt {
|
|
|
288
297
|
// Try to parse as BIP32Arg first (string or BIP32 instance)
|
|
289
298
|
if (typeof key === "string" || ("derive" in key && typeof key.derive === "function")) {
|
|
290
299
|
const wasmKey = BIP32.from(key).wasm;
|
|
291
|
-
return this.
|
|
300
|
+
return this._wasm.verify_signature_with_xpub(inputIndex, wasmKey);
|
|
292
301
|
}
|
|
293
302
|
// Otherwise it's an ECPairArg (Uint8Array, ECPair, or WasmECPair)
|
|
294
303
|
const wasmECPair = ECPair.from(key).wasm;
|
|
295
|
-
return this.
|
|
304
|
+
return this._wasm.verify_signature_with_pub(inputIndex, wasmECPair);
|
|
296
305
|
}
|
|
297
306
|
/**
|
|
298
307
|
* Sign a single input with a private key
|
|
@@ -344,12 +353,12 @@ export class BitGoPsbt {
|
|
|
344
353
|
typeof key.derive === "function")) {
|
|
345
354
|
// It's a BIP32Arg
|
|
346
355
|
const wasmKey = BIP32.from(key);
|
|
347
|
-
this.
|
|
356
|
+
this._wasm.sign_with_xpriv(inputIndex, wasmKey.wasm);
|
|
348
357
|
}
|
|
349
358
|
else {
|
|
350
359
|
// It's an ECPairArg
|
|
351
360
|
const wasmKey = ECPair.from(key);
|
|
352
|
-
this.
|
|
361
|
+
this._wasm.sign_with_privkey(inputIndex, wasmKey.wasm);
|
|
353
362
|
}
|
|
354
363
|
}
|
|
355
364
|
/**
|
|
@@ -373,8 +382,8 @@ export class BitGoPsbt {
|
|
|
373
382
|
* @throws Error if the input is not a replay protection input, index is out of bounds, or scripts are invalid
|
|
374
383
|
*/
|
|
375
384
|
verifyReplayProtectionSignature(inputIndex, replayProtection) {
|
|
376
|
-
const rp = ReplayProtection.from(replayProtection, this.
|
|
377
|
-
return this.
|
|
385
|
+
const rp = ReplayProtection.from(replayProtection, this._wasm.network());
|
|
386
|
+
return this._wasm.verify_replay_protection_signature(inputIndex, rp.wasm);
|
|
378
387
|
}
|
|
379
388
|
/**
|
|
380
389
|
* Serialize the PSBT to bytes
|
|
@@ -382,7 +391,7 @@ export class BitGoPsbt {
|
|
|
382
391
|
* @returns The serialized PSBT as a byte array
|
|
383
392
|
*/
|
|
384
393
|
serialize() {
|
|
385
|
-
return this.
|
|
394
|
+
return this._wasm.serialize();
|
|
386
395
|
}
|
|
387
396
|
/**
|
|
388
397
|
* Generate and store MuSig2 nonces for all MuSig2 inputs
|
|
@@ -424,7 +433,7 @@ export class BitGoPsbt {
|
|
|
424
433
|
*/
|
|
425
434
|
generateMusig2Nonces(key, sessionId) {
|
|
426
435
|
const wasmKey = BIP32.from(key);
|
|
427
|
-
this.
|
|
436
|
+
this._wasm.generate_musig2_nonces(wasmKey.wasm, sessionId);
|
|
428
437
|
}
|
|
429
438
|
/**
|
|
430
439
|
* Combine/merge data from another PSBT into this one
|
|
@@ -446,7 +455,7 @@ export class BitGoPsbt {
|
|
|
446
455
|
* ```
|
|
447
456
|
*/
|
|
448
457
|
combineMusig2Nonces(sourcePsbt) {
|
|
449
|
-
this.
|
|
458
|
+
this._wasm.combine_musig2_nonces(sourcePsbt.wasm);
|
|
450
459
|
}
|
|
451
460
|
/**
|
|
452
461
|
* Finalize all inputs in the PSBT
|
|
@@ -454,7 +463,7 @@ export class BitGoPsbt {
|
|
|
454
463
|
* @throws Error if any input failed to finalize
|
|
455
464
|
*/
|
|
456
465
|
finalizeAllInputs() {
|
|
457
|
-
this.
|
|
466
|
+
this._wasm.finalize_all_inputs();
|
|
458
467
|
}
|
|
459
468
|
/**
|
|
460
469
|
* Extract the final transaction from a finalized PSBT
|
|
@@ -463,6 +472,6 @@ export class BitGoPsbt {
|
|
|
463
472
|
* @throws Error if the PSBT is not fully finalized or extraction fails
|
|
464
473
|
*/
|
|
465
474
|
extractTransaction() {
|
|
466
|
-
return this.
|
|
475
|
+
return this._wasm.extract_transaction();
|
|
467
476
|
}
|
|
468
477
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { BitGoPsbt, InputScriptType, SignPath } from "./BitGoPsbt.js";
|
|
2
|
+
import type { CoinName } from "../coinName.js";
|
|
3
|
+
type FromInputParams = {
|
|
4
|
+
chain: number;
|
|
5
|
+
signPath?: SignPath;
|
|
6
|
+
} | {
|
|
7
|
+
scriptType: InputScriptType;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Dimensions class for estimating transaction virtual size.
|
|
11
|
+
*
|
|
12
|
+
* Tracks weight internally with min/max bounds to handle ECDSA signature variance.
|
|
13
|
+
* Schnorr signatures have no variance (always 64 bytes).
|
|
14
|
+
*
|
|
15
|
+
* This is a thin wrapper over the WASM implementation.
|
|
16
|
+
*/
|
|
17
|
+
export declare class Dimensions {
|
|
18
|
+
private _wasm;
|
|
19
|
+
private constructor();
|
|
20
|
+
/**
|
|
21
|
+
* Create empty dimensions (zero weight)
|
|
22
|
+
*/
|
|
23
|
+
static empty(): Dimensions;
|
|
24
|
+
/**
|
|
25
|
+
* Create dimensions from a BitGoPsbt
|
|
26
|
+
*
|
|
27
|
+
* Parses PSBT inputs and outputs to compute weight bounds without
|
|
28
|
+
* requiring wallet keys. Input types are detected from BIP32 derivation
|
|
29
|
+
* paths stored in the PSBT.
|
|
30
|
+
*/
|
|
31
|
+
static fromPsbt(psbt: BitGoPsbt): Dimensions;
|
|
32
|
+
/**
|
|
33
|
+
* Create dimensions for a single input
|
|
34
|
+
*
|
|
35
|
+
* @param params - Either `{ chain, signPath? }` or `{ scriptType }`
|
|
36
|
+
*/
|
|
37
|
+
static fromInput(params: FromInputParams): Dimensions;
|
|
38
|
+
/**
|
|
39
|
+
* Create dimensions for a single output from script bytes
|
|
40
|
+
*/
|
|
41
|
+
static fromOutput(script: Uint8Array): Dimensions;
|
|
42
|
+
/**
|
|
43
|
+
* Create dimensions for a single output from an address
|
|
44
|
+
*/
|
|
45
|
+
static fromOutput(address: string, network: CoinName): Dimensions;
|
|
46
|
+
/**
|
|
47
|
+
* Combine with another Dimensions instance
|
|
48
|
+
*/
|
|
49
|
+
plus(other: Dimensions): Dimensions;
|
|
50
|
+
/**
|
|
51
|
+
* Whether any inputs are segwit (affects overhead calculation)
|
|
52
|
+
*/
|
|
53
|
+
get hasSegwit(): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Get total weight (min or max)
|
|
56
|
+
* @param size - "min" or "max", defaults to "max"
|
|
57
|
+
*/
|
|
58
|
+
getWeight(size?: "min" | "max"): number;
|
|
59
|
+
/**
|
|
60
|
+
* Get virtual size (min or max)
|
|
61
|
+
* @param size - "min" or "max", defaults to "max"
|
|
62
|
+
*/
|
|
63
|
+
getVSize(size?: "min" | "max"): number;
|
|
64
|
+
}
|
|
65
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { WasmDimensions } from "../wasm/wasm_utxo.js";
|
|
2
|
+
import { toOutputScriptWithCoin } from "../address.js";
|
|
3
|
+
/**
|
|
4
|
+
* Dimensions class for estimating transaction virtual size.
|
|
5
|
+
*
|
|
6
|
+
* Tracks weight internally with min/max bounds to handle ECDSA signature variance.
|
|
7
|
+
* Schnorr signatures have no variance (always 64 bytes).
|
|
8
|
+
*
|
|
9
|
+
* This is a thin wrapper over the WASM implementation.
|
|
10
|
+
*/
|
|
11
|
+
export class Dimensions {
|
|
12
|
+
_wasm;
|
|
13
|
+
constructor(_wasm) {
|
|
14
|
+
this._wasm = _wasm;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Create empty dimensions (zero weight)
|
|
18
|
+
*/
|
|
19
|
+
static empty() {
|
|
20
|
+
return new Dimensions(WasmDimensions.empty());
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Create dimensions from a BitGoPsbt
|
|
24
|
+
*
|
|
25
|
+
* Parses PSBT inputs and outputs to compute weight bounds without
|
|
26
|
+
* requiring wallet keys. Input types are detected from BIP32 derivation
|
|
27
|
+
* paths stored in the PSBT.
|
|
28
|
+
*/
|
|
29
|
+
static fromPsbt(psbt) {
|
|
30
|
+
return new Dimensions(WasmDimensions.from_psbt(psbt.wasm));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Create dimensions for a single input
|
|
34
|
+
*
|
|
35
|
+
* @param params - Either `{ chain, signPath? }` or `{ scriptType }`
|
|
36
|
+
*/
|
|
37
|
+
static fromInput(params) {
|
|
38
|
+
if ("scriptType" in params) {
|
|
39
|
+
return new Dimensions(WasmDimensions.from_input_script_type(params.scriptType));
|
|
40
|
+
}
|
|
41
|
+
return new Dimensions(WasmDimensions.from_input(params.chain, params.signPath?.signer, params.signPath?.cosigner));
|
|
42
|
+
}
|
|
43
|
+
static fromOutput(scriptOrAddress, network) {
|
|
44
|
+
if (typeof scriptOrAddress === "string") {
|
|
45
|
+
if (network === undefined) {
|
|
46
|
+
throw new Error("network is required when passing an address string");
|
|
47
|
+
}
|
|
48
|
+
const script = toOutputScriptWithCoin(scriptOrAddress, network);
|
|
49
|
+
return new Dimensions(WasmDimensions.from_output_script(script));
|
|
50
|
+
}
|
|
51
|
+
return new Dimensions(WasmDimensions.from_output_script(scriptOrAddress));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Combine with another Dimensions instance
|
|
55
|
+
*/
|
|
56
|
+
plus(other) {
|
|
57
|
+
return new Dimensions(this._wasm.plus(other._wasm));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Whether any inputs are segwit (affects overhead calculation)
|
|
61
|
+
*/
|
|
62
|
+
get hasSegwit() {
|
|
63
|
+
return this._wasm.has_segwit();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get total weight (min or max)
|
|
67
|
+
* @param size - "min" or "max", defaults to "max"
|
|
68
|
+
*/
|
|
69
|
+
getWeight(size = "max") {
|
|
70
|
+
return this._wasm.get_weight(size);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get virtual size (min or max)
|
|
74
|
+
* @param size - "min" or "max", defaults to "max"
|
|
75
|
+
*/
|
|
76
|
+
getVSize(size = "max") {
|
|
77
|
+
return this._wasm.get_vsize(size);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
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 { Dimensions } from "./Dimensions.js";
|
|
4
5
|
export { BitGoPsbt, type NetworkName, type ScriptId, type InputScriptType, type ParsedInput, type ParsedOutput, type ParsedTransaction, type SignPath, type CreateEmptyOptions, type AddInputOptions, type AddOutputOptions, type AddWalletInputOptions, type AddWalletOutputOptions, } from "./BitGoPsbt.js";
|
|
5
6
|
export { ZcashBitGoPsbt, type ZcashNetworkName, type CreateEmptyZcashOptions, } from "./ZcashBitGoPsbt.js";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { RootWalletKeys } from "./RootWalletKeys.js";
|
|
2
2
|
export { ReplayProtection } from "./ReplayProtection.js";
|
|
3
3
|
export { outputScript, address } from "./address.js";
|
|
4
|
+
export { Dimensions } from "./Dimensions.js";
|
|
4
5
|
// Bitcoin-like PSBT (for all non-Zcash networks)
|
|
5
6
|
export { BitGoPsbt, } from "./BitGoPsbt.js";
|
|
6
7
|
// Zcash-specific PSBT subclass
|
package/dist/esm/js/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export * as bip32 from "./bip32.js";
|
|
|
6
6
|
export * as ecpair from "./ecpair.js";
|
|
7
7
|
export { ECPair } from "./ecpair.js";
|
|
8
8
|
export { BIP32 } from "./bip32.js";
|
|
9
|
+
export { Dimensions } from "./fixedScriptWallet/Dimensions.js";
|
|
9
10
|
export type { CoinName } from "./coinName.js";
|
|
10
11
|
export type { Triple } from "./triple.js";
|
|
11
12
|
export type { AddressFormat } from "./address.js";
|
package/dist/esm/js/index.js
CHANGED
|
@@ -13,6 +13,7 @@ export * as ecpair from "./ecpair.js";
|
|
|
13
13
|
// Only the most commonly used classes and types are exported at the top level for convenience
|
|
14
14
|
export { ECPair } from "./ecpair.js";
|
|
15
15
|
export { BIP32 } from "./bip32.js";
|
|
16
|
+
export { Dimensions } from "./fixedScriptWallet/Dimensions.js";
|
|
16
17
|
export { WrapDescriptor as Descriptor } from "./wasm/wasm_utxo.js";
|
|
17
18
|
export { WrapMiniscript as Miniscript } from "./wasm/wasm_utxo.js";
|
|
18
19
|
export { WrapPsbt as Psbt } from "./wasm/wasm_utxo.js";
|
|
@@ -9,6 +9,14 @@ export declare class Transaction {
|
|
|
9
9
|
private constructor();
|
|
10
10
|
static fromBytes(bytes: Uint8Array): Transaction;
|
|
11
11
|
toBytes(): Uint8Array;
|
|
12
|
+
/**
|
|
13
|
+
* Get the virtual size of the transaction
|
|
14
|
+
*
|
|
15
|
+
* Virtual size accounts for the segwit discount on witness data.
|
|
16
|
+
*
|
|
17
|
+
* @returns The virtual size in virtual bytes (vbytes)
|
|
18
|
+
*/
|
|
19
|
+
getVSize(): number;
|
|
12
20
|
/**
|
|
13
21
|
* @internal
|
|
14
22
|
*/
|
|
@@ -15,6 +15,16 @@ export class Transaction {
|
|
|
15
15
|
toBytes() {
|
|
16
16
|
return this._wasm.to_bytes();
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Get the virtual size of the transaction
|
|
20
|
+
*
|
|
21
|
+
* Virtual size accounts for the segwit discount on witness data.
|
|
22
|
+
*
|
|
23
|
+
* @returns The virtual size in virtual bytes (vbytes)
|
|
24
|
+
*/
|
|
25
|
+
getVSize() {
|
|
26
|
+
return this._wasm.get_vsize();
|
|
27
|
+
}
|
|
18
28
|
/**
|
|
19
29
|
* @internal
|
|
20
30
|
*/
|
|
@@ -225,6 +225,17 @@ export class BitGoPsbt {
|
|
|
225
225
|
* generated for security. Custom session_id is only allowed on testnets for testing purposes.
|
|
226
226
|
*/
|
|
227
227
|
generate_musig2_nonces(xpriv: WasmBIP32, session_id_bytes?: Uint8Array | null): void;
|
|
228
|
+
/**
|
|
229
|
+
* Add an output to the PSBT by address
|
|
230
|
+
*
|
|
231
|
+
* # Arguments
|
|
232
|
+
* * `address` - The destination address
|
|
233
|
+
* * `value` - The value in satoshis
|
|
234
|
+
*
|
|
235
|
+
* # Returns
|
|
236
|
+
* The index of the newly added output
|
|
237
|
+
*/
|
|
238
|
+
add_output_with_address(address: string, value: bigint): number;
|
|
228
239
|
/**
|
|
229
240
|
* Verify if a valid signature exists for a given ECPair key at the specified input index
|
|
230
241
|
*
|
|
@@ -502,6 +513,67 @@ export class WasmDashTransaction {
|
|
|
502
513
|
to_bytes(): Uint8Array;
|
|
503
514
|
}
|
|
504
515
|
|
|
516
|
+
export class WasmDimensions {
|
|
517
|
+
private constructor();
|
|
518
|
+
free(): void;
|
|
519
|
+
[Symbol.dispose](): void;
|
|
520
|
+
/**
|
|
521
|
+
* Create dimensions for a single input from chain code
|
|
522
|
+
*
|
|
523
|
+
* # Arguments
|
|
524
|
+
* * `chain` - Chain code (0/1=p2sh, 10/11=p2shP2wsh, 20/21=p2wsh, 30/31=p2tr, 40/41=p2trMusig2)
|
|
525
|
+
* * `signer` - Optional signer key ("user", "backup", "bitgo")
|
|
526
|
+
* * `cosigner` - Optional cosigner key ("user", "backup", "bitgo")
|
|
527
|
+
*/
|
|
528
|
+
static from_input(chain: number, signer?: string | null, cosigner?: string | null): WasmDimensions;
|
|
529
|
+
/**
|
|
530
|
+
* Get total weight (min or max)
|
|
531
|
+
*
|
|
532
|
+
* # Arguments
|
|
533
|
+
* * `size` - "min" or "max", defaults to "max"
|
|
534
|
+
*/
|
|
535
|
+
get_weight(size?: string | null): number;
|
|
536
|
+
/**
|
|
537
|
+
* Whether any inputs are segwit (affects overhead calculation)
|
|
538
|
+
*/
|
|
539
|
+
has_segwit(): boolean;
|
|
540
|
+
/**
|
|
541
|
+
* Create dimensions for a single output from script bytes
|
|
542
|
+
*/
|
|
543
|
+
static from_output_script(script: Uint8Array): WasmDimensions;
|
|
544
|
+
/**
|
|
545
|
+
* Create dimensions for a single input from script type string
|
|
546
|
+
*
|
|
547
|
+
* # Arguments
|
|
548
|
+
* * `script_type` - One of: "p2sh", "p2shP2wsh", "p2wsh", "p2trLegacy",
|
|
549
|
+
* "p2trMusig2KeyPath", "p2trMusig2ScriptPath", "p2shP2pk"
|
|
550
|
+
*/
|
|
551
|
+
static from_input_script_type(script_type: string): WasmDimensions;
|
|
552
|
+
/**
|
|
553
|
+
* Combine with another Dimensions instance
|
|
554
|
+
*/
|
|
555
|
+
plus(other: WasmDimensions): WasmDimensions;
|
|
556
|
+
/**
|
|
557
|
+
* Create empty dimensions (zero weight)
|
|
558
|
+
*/
|
|
559
|
+
static empty(): WasmDimensions;
|
|
560
|
+
/**
|
|
561
|
+
* Create dimensions from a BitGoPsbt
|
|
562
|
+
*
|
|
563
|
+
* Parses PSBT inputs and outputs to compute weight bounds without
|
|
564
|
+
* requiring wallet keys. Input types are detected from BIP32 derivation
|
|
565
|
+
* paths stored in the PSBT.
|
|
566
|
+
*/
|
|
567
|
+
static from_psbt(psbt: BitGoPsbt): WasmDimensions;
|
|
568
|
+
/**
|
|
569
|
+
* Get virtual size (min or max)
|
|
570
|
+
*
|
|
571
|
+
* # Arguments
|
|
572
|
+
* * `size` - "min" or "max", defaults to "max"
|
|
573
|
+
*/
|
|
574
|
+
get_vsize(size?: string | null): number;
|
|
575
|
+
}
|
|
576
|
+
|
|
505
577
|
export class WasmECPair {
|
|
506
578
|
private constructor();
|
|
507
579
|
free(): void;
|
|
@@ -629,6 +701,16 @@ export class WasmTransaction {
|
|
|
629
701
|
* The serialized transaction bytes
|
|
630
702
|
*/
|
|
631
703
|
to_bytes(): Uint8Array;
|
|
704
|
+
/**
|
|
705
|
+
* Get the virtual size of the transaction
|
|
706
|
+
*
|
|
707
|
+
* Virtual size is calculated as ceil(weight / 4), where weight accounts
|
|
708
|
+
* for the segwit discount on witness data.
|
|
709
|
+
*
|
|
710
|
+
* # Returns
|
|
711
|
+
* The virtual size in virtual bytes (vbytes)
|
|
712
|
+
*/
|
|
713
|
+
get_vsize(): number;
|
|
632
714
|
}
|
|
633
715
|
|
|
634
716
|
export class WasmZcashTransaction {
|