@bitgo/wasm-utxo 4.18.0 → 4.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.
Files changed (29) hide show
  1. package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.d.ts +4 -1
  2. package/dist/cjs/js/fixedScriptWallet/BitGoPsbt.js +5 -2
  3. package/dist/cjs/js/fixedScriptWallet/ZcashBitGoPsbt.d.ts +4 -1
  4. package/dist/cjs/js/fixedScriptWallet/ZcashBitGoPsbt.js +5 -2
  5. package/dist/cjs/js/fixedScriptWallet/index.d.ts +1 -0
  6. package/dist/cjs/js/fixedScriptWallet/index.js +4 -1
  7. package/dist/cjs/js/fixedScriptWallet/prevTx.d.ts +36 -0
  8. package/dist/cjs/js/fixedScriptWallet/prevTx.js +50 -0
  9. package/dist/cjs/js/index.d.ts +1 -0
  10. package/dist/cjs/js/index.js +3 -1
  11. package/dist/cjs/js/wasm/wasm_utxo.d.ts +4 -4
  12. package/dist/cjs/js/wasm/wasm_utxo.js +12 -8
  13. package/dist/cjs/js/wasm/wasm_utxo_bg.wasm +0 -0
  14. package/dist/cjs/js/wasm/wasm_utxo_bg.wasm.d.ts +4 -4
  15. package/dist/esm/js/fixedScriptWallet/BitGoPsbt.d.ts +4 -1
  16. package/dist/esm/js/fixedScriptWallet/BitGoPsbt.js +5 -2
  17. package/dist/esm/js/fixedScriptWallet/ZcashBitGoPsbt.d.ts +4 -1
  18. package/dist/esm/js/fixedScriptWallet/ZcashBitGoPsbt.js +5 -2
  19. package/dist/esm/js/fixedScriptWallet/index.d.ts +1 -0
  20. package/dist/esm/js/fixedScriptWallet/index.js +2 -0
  21. package/dist/esm/js/fixedScriptWallet/prevTx.d.ts +36 -0
  22. package/dist/esm/js/fixedScriptWallet/prevTx.js +47 -0
  23. package/dist/esm/js/index.d.ts +1 -0
  24. package/dist/esm/js/index.js +1 -0
  25. package/dist/esm/js/wasm/wasm_utxo.d.ts +4 -4
  26. package/dist/esm/js/wasm/wasm_utxo_bg.js +12 -8
  27. package/dist/esm/js/wasm/wasm_utxo_bg.wasm +0 -0
  28. package/dist/esm/js/wasm/wasm_utxo_bg.wasm.d.ts +4 -4
  29. package/package.json +1 -1
@@ -568,10 +568,13 @@ export declare class BitGoPsbt extends PsbtBase<WasmBitGoPsbt> implements IPsbtW
568
568
  /**
569
569
  * Extract the final transaction from a finalized PSBT
570
570
  *
571
+ * @param maxFeeRate Optional maximum fee rate in **sat/vB**. `Infinity` skips
572
+ * the absurd-fee check; `undefined` uses rust-bitcoin's default check.
573
+ * Callers holding sat/kB thresholds must divide by 1000 before passing.
571
574
  * @returns The extracted transaction instance
572
575
  * @throws Error if the PSBT is not fully finalized or extraction fails
573
576
  */
574
- extractTransaction(): ITransaction;
577
+ extractTransaction(maxFeeRate?: number): ITransaction;
575
578
  /**
576
579
  * Extract a half-signed transaction in legacy format for p2ms-based script types.
577
580
  *
@@ -569,12 +569,15 @@ class BitGoPsbt extends psbtBase_js_1.PsbtBase {
569
569
  /**
570
570
  * Extract the final transaction from a finalized PSBT
571
571
  *
572
+ * @param maxFeeRate Optional maximum fee rate in **sat/vB**. `Infinity` skips
573
+ * the absurd-fee check; `undefined` uses rust-bitcoin's default check.
574
+ * Callers holding sat/kB thresholds must divide by 1000 before passing.
572
575
  * @returns The extracted transaction instance
573
576
  * @throws Error if the PSBT is not fully finalized or extraction fails
574
577
  */
575
- extractTransaction() {
578
+ extractTransaction(maxFeeRate) {
576
579
  const networkType = this._wasm.get_network_type();
577
- const wasm = this._wasm.extract_transaction();
580
+ const wasm = this._wasm.extract_transaction(maxFeeRate);
578
581
  switch (networkType) {
579
582
  case "dash":
580
583
  return transaction_js_1.DashTransaction.fromWasm(wasm);
@@ -168,8 +168,11 @@ export declare class ZcashBitGoPsbt extends BitGoPsbt {
168
168
  /**
169
169
  * Extract the final Zcash transaction from a finalized PSBT
170
170
  *
171
+ * @param maxFeeRate Optional maximum fee rate in **sat/vB**. `Infinity` skips
172
+ * the absurd-fee check; `undefined` uses rust-bitcoin's default check.
173
+ * Callers holding sat/kB thresholds must divide by 1000 before passing.
171
174
  * @returns The extracted Zcash transaction instance
172
175
  * @throws Error if the PSBT is not fully finalized or extraction fails
173
176
  */
174
- extractTransaction(): ZcashTransaction;
177
+ extractTransaction(maxFeeRate?: number): ZcashTransaction;
175
178
  }
@@ -190,11 +190,14 @@ class ZcashBitGoPsbt extends BitGoPsbt_js_1.BitGoPsbt {
190
190
  /**
191
191
  * Extract the final Zcash transaction from a finalized PSBT
192
192
  *
193
+ * @param maxFeeRate Optional maximum fee rate in **sat/vB**. `Infinity` skips
194
+ * the absurd-fee check; `undefined` uses rust-bitcoin's default check.
195
+ * Callers holding sat/kB thresholds must divide by 1000 before passing.
193
196
  * @returns The extracted Zcash transaction instance
194
197
  * @throws Error if the PSBT is not fully finalized or extraction fails
195
198
  */
196
- extractTransaction() {
197
- return transaction_js_1.ZcashTransaction.fromWasm(this.wasm.extract_zcash_transaction());
199
+ extractTransaction(maxFeeRate) {
200
+ return transaction_js_1.ZcashTransaction.fromWasm(this.wasm.extract_zcash_transaction(maxFeeRate));
198
201
  }
199
202
  }
200
203
  exports.ZcashBitGoPsbt = ZcashBitGoPsbt;
@@ -5,6 +5,7 @@ export { outputScript, address } from "./address.js";
5
5
  export { Dimensions } from "./Dimensions.js";
6
6
  export { outputScriptTypes, inputScriptTypes, type OutputScriptType, type InputScriptType, type ScriptType, } from "./scriptType.js";
7
7
  export { ChainCode, chainCodes, assertChainCode, type Scope } from "./chains.js";
8
+ export { requiresPrevTxForP2sh } from "./prevTx.js";
8
9
  export { BitGoPsbt, getWalletKeysFromPsbt, type NetworkName, type ScriptId, type ParsedInput, type ParsedOutput, type ParsedTransaction, type SignPath, type CreateEmptyOptions, type AddInputOptions, type AddOutputOptions, type AddWalletInputOptions, type AddWalletOutputOptions, type ParseTransactionOptions, type ParseOutputsOptions, type HydrationUnspent, } from "./BitGoPsbt.js";
9
10
  export { BitGoKeySubtype, type PsbtKvKey } from "./BitGoKeySubtype.js";
10
11
  export { ZcashBitGoPsbt, type ZcashNetworkName, type CreateEmptyZcashOptions, } from "./ZcashBitGoPsbt.js";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ZcashBitGoPsbt = exports.BitGoKeySubtype = exports.getWalletKeysFromPsbt = exports.BitGoPsbt = exports.assertChainCode = exports.chainCodes = exports.ChainCode = exports.inputScriptTypes = exports.outputScriptTypes = exports.Dimensions = exports.address = exports.outputScript = exports.ReplayProtection = exports.RootWalletKeys = void 0;
3
+ exports.ZcashBitGoPsbt = exports.BitGoKeySubtype = exports.getWalletKeysFromPsbt = exports.BitGoPsbt = exports.requiresPrevTxForP2sh = exports.assertChainCode = exports.chainCodes = exports.ChainCode = exports.inputScriptTypes = exports.outputScriptTypes = exports.Dimensions = exports.address = exports.outputScript = exports.ReplayProtection = exports.RootWalletKeys = void 0;
4
4
  exports.supportsScriptType = supportsScriptType;
5
5
  exports.createOpReturnScript = createOpReturnScript;
6
6
  exports.p2shP2pkOutputScript = p2shP2pkOutputScript;
@@ -21,6 +21,9 @@ var chains_js_1 = require("./chains.js");
21
21
  Object.defineProperty(exports, "ChainCode", { enumerable: true, get: function () { return chains_js_1.ChainCode; } });
22
22
  Object.defineProperty(exports, "chainCodes", { enumerable: true, get: function () { return chains_js_1.chainCodes; } });
23
23
  Object.defineProperty(exports, "assertChainCode", { enumerable: true, get: function () { return chains_js_1.assertChainCode; } });
24
+ // Previous-transaction inclusion policy (pure JS, no WASM init)
25
+ var prevTx_js_1 = require("./prevTx.js");
26
+ Object.defineProperty(exports, "requiresPrevTxForP2sh", { enumerable: true, get: function () { return prevTx_js_1.requiresPrevTxForP2sh; } });
24
27
  // Bitcoin-like PSBT (for all non-Zcash networks)
25
28
  var BitGoPsbt_js_1 = require("./BitGoPsbt.js");
26
29
  Object.defineProperty(exports, "BitGoPsbt", { enumerable: true, get: function () { return BitGoPsbt_js_1.BitGoPsbt; } });
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Previous-transaction inclusion policy for fixed-script wallet PSBT inputs.
3
+ *
4
+ * Decides whether a p2sh input requires the full previous transaction
5
+ * (PSBT_IN_NON_WITNESS_UTXO) or can be signed from witness_utxo-only.
6
+ *
7
+ * This is a pure-JS module (no WASM initialization) so callers can evaluate
8
+ * the policy cheaply without loading the wasm-utxo module.
9
+ */
10
+ import { type CoinName } from "../coinName.js";
11
+ /**
12
+ * Whether a p2sh input requires the full previous transaction
13
+ * (PSBT_IN_NON_WITNESS_UTXO). Callers are expected to have already
14
+ * confirmed the input is p2sh (non-segwit) and that the tx format
15
+ * includes prevTx (e.g. "psbt", not "psbt-lite"); this predicate only
16
+ * answers the coin-level question.
17
+ *
18
+ * Returns false for value-committing coins whose sighash commits the
19
+ * input amount, making `non_witness_utxo` (full prevTx) cryptographically
20
+ * pointless for signing p2sh inputs — `witness_utxo` (value +
21
+ * scriptPubKey) suffices:
22
+ *
23
+ * - Zcash (`zec`/`tzec`): ZIP-243 transparent sighash commits the amount.
24
+ * Including prevTx also crashes wasm-utxo, whose consensus::deserialize
25
+ * rejects Zcash overwintered transactions.
26
+ * - BCH family (`bch`/`bcha`/`bsv`/`btg` + testnets): replay-protected
27
+ * BIP-143 sighash (SIGHASH_FORKID, the default for the whole family)
28
+ * commits the 8-byte value as preimage item #6. eCash is `bcha`/`tbcha`.
29
+ * For the BCH family, skipping prevTx is an optimization (no DB fetch)
30
+ * plus defense-in-depth, with the same fee-validation risk that the
31
+ * existing `psbt-lite` path already accepts for all coins.
32
+ *
33
+ * Testnets are normalized via `getMainnet` before the switch. True
34
+ * otherwise.
35
+ */
36
+ export declare function requiresPrevTxForP2sh(coinName: CoinName): boolean;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requiresPrevTxForP2sh = requiresPrevTxForP2sh;
4
+ /**
5
+ * Previous-transaction inclusion policy for fixed-script wallet PSBT inputs.
6
+ *
7
+ * Decides whether a p2sh input requires the full previous transaction
8
+ * (PSBT_IN_NON_WITNESS_UTXO) or can be signed from witness_utxo-only.
9
+ *
10
+ * This is a pure-JS module (no WASM initialization) so callers can evaluate
11
+ * the policy cheaply without loading the wasm-utxo module.
12
+ */
13
+ const coinName_js_1 = require("../coinName.js");
14
+ /**
15
+ * Whether a p2sh input requires the full previous transaction
16
+ * (PSBT_IN_NON_WITNESS_UTXO). Callers are expected to have already
17
+ * confirmed the input is p2sh (non-segwit) and that the tx format
18
+ * includes prevTx (e.g. "psbt", not "psbt-lite"); this predicate only
19
+ * answers the coin-level question.
20
+ *
21
+ * Returns false for value-committing coins whose sighash commits the
22
+ * input amount, making `non_witness_utxo` (full prevTx) cryptographically
23
+ * pointless for signing p2sh inputs — `witness_utxo` (value +
24
+ * scriptPubKey) suffices:
25
+ *
26
+ * - Zcash (`zec`/`tzec`): ZIP-243 transparent sighash commits the amount.
27
+ * Including prevTx also crashes wasm-utxo, whose consensus::deserialize
28
+ * rejects Zcash overwintered transactions.
29
+ * - BCH family (`bch`/`bcha`/`bsv`/`btg` + testnets): replay-protected
30
+ * BIP-143 sighash (SIGHASH_FORKID, the default for the whole family)
31
+ * commits the 8-byte value as preimage item #6. eCash is `bcha`/`tbcha`.
32
+ * For the BCH family, skipping prevTx is an optimization (no DB fetch)
33
+ * plus defense-in-depth, with the same fee-validation risk that the
34
+ * existing `psbt-lite` path already accepts for all coins.
35
+ *
36
+ * Testnets are normalized via `getMainnet` before the switch. True
37
+ * otherwise.
38
+ */
39
+ function requiresPrevTxForP2sh(coinName) {
40
+ switch ((0, coinName_js_1.getMainnet)(coinName)) {
41
+ case "zec": // Zcash (ZIP-243)
42
+ case "bch": // Bitcoin Cash (BIP-143/FORKID)
43
+ case "bcha": // eCash (BIP-143/FORKID)
44
+ case "bsv": // Bitcoin SV (BIP-143/FORKID)
45
+ case "btg": // Bitcoin Gold (BIP-143/FORKID)
46
+ return false;
47
+ default:
48
+ return true;
49
+ }
50
+ }
@@ -17,6 +17,7 @@ export type WasmUtxoVersionInfo = {
17
17
  };
18
18
  export declare function getWasmUtxoVersion(): WasmUtxoVersionInfo;
19
19
  export { type CoinName, getMainnet, isMainnet, isTestnet, isCoinName } from "./coinName.js";
20
+ export { requiresPrevTxForP2sh } from "./fixedScriptWallet/prevTx.js";
20
21
  export type { Triple } from "./triple.js";
21
22
  export type { AddressFormat } from "./address.js";
22
23
  export type { TapLeafScript, PreparedInscriptionRevealData } from "./inscriptions.js";
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.hasPsbtMagic = exports.ZcashTransaction = exports.Transaction = exports.DashTransaction = exports.Psbt = exports.Miniscript = exports.Descriptor = exports.isCoinName = exports.isTestnet = exports.isMainnet = exports.getMainnet = exports.Dimensions = exports.BIP32 = exports.ECPair = exports.ecpair = exports.bip32 = exports.descriptorWallet = exports.fixedScriptWallet = exports.utxolibCompat = exports.message = exports.inscriptions = exports.bip322 = exports.ast = exports.address = void 0;
36
+ exports.hasPsbtMagic = exports.ZcashTransaction = exports.Transaction = exports.DashTransaction = exports.Psbt = exports.Miniscript = exports.Descriptor = exports.requiresPrevTxForP2sh = exports.isCoinName = exports.isTestnet = exports.isMainnet = exports.getMainnet = exports.Dimensions = exports.BIP32 = exports.ECPair = exports.ecpair = exports.bip32 = exports.descriptorWallet = exports.fixedScriptWallet = exports.utxolibCompat = exports.message = exports.inscriptions = exports.bip322 = exports.ast = exports.address = void 0;
37
37
  exports.getWasmUtxoVersion = getWasmUtxoVersion;
38
38
  exports.isWasmUtxoError = isWasmUtxoError;
39
39
  const wasm = __importStar(require("./wasm/wasm_utxo.js"));
@@ -68,6 +68,8 @@ Object.defineProperty(exports, "getMainnet", { enumerable: true, get: function (
68
68
  Object.defineProperty(exports, "isMainnet", { enumerable: true, get: function () { return coinName_js_1.isMainnet; } });
69
69
  Object.defineProperty(exports, "isTestnet", { enumerable: true, get: function () { return coinName_js_1.isTestnet; } });
70
70
  Object.defineProperty(exports, "isCoinName", { enumerable: true, get: function () { return coinName_js_1.isCoinName; } });
71
+ var prevTx_js_1 = require("./fixedScriptWallet/prevTx.js");
72
+ Object.defineProperty(exports, "requiresPrevTxForP2sh", { enumerable: true, get: function () { return prevTx_js_1.requiresPrevTxForP2sh; } });
71
73
  const WASM_UTXO_ERROR_SYMBOL = Symbol.for("@bitgo/wasm-utxo/error");
72
74
  function isWasmUtxoError(e) {
73
75
  return (e instanceof Error &&
@@ -249,14 +249,14 @@ export class BitGoPsbt {
249
249
  * This avoids re-parsing bytes by returning the transaction directly.
250
250
  * Only valid for Bitcoin-like networks (not Dash or Zcash).
251
251
  */
252
- extract_bitcoin_transaction(): WasmTransaction;
252
+ extract_bitcoin_transaction(max_fee_rate_sat_per_vb?: number | null): WasmTransaction;
253
253
  /**
254
254
  * Extract the final transaction as a WasmDashTransaction (for Dash networks)
255
255
  *
256
256
  * This avoids re-parsing bytes by returning the transaction directly.
257
257
  * Only valid for Dash networks.
258
258
  */
259
- extract_dash_transaction(): WasmDashTransaction;
259
+ extract_dash_transaction(max_fee_rate_sat_per_vb?: number | null): WasmDashTransaction;
260
260
  /**
261
261
  * Extract a half-signed transaction in legacy format for p2ms-based script types.
262
262
  *
@@ -289,14 +289,14 @@ export class BitGoPsbt {
289
289
  * - `Ok(JsValue)` containing the WASM transaction instance
290
290
  * - `Err(WasmUtxoError)` if the PSBT is not fully finalized or extraction fails
291
291
  */
292
- extract_transaction(): any;
292
+ extract_transaction(max_fee_rate_sat_per_vb?: number | null): any;
293
293
  /**
294
294
  * Extract the final transaction as a WasmZcashTransaction (for Zcash networks)
295
295
  *
296
296
  * This avoids re-parsing bytes by returning the transaction directly.
297
297
  * Only valid for Zcash networks.
298
298
  */
299
- extract_zcash_transaction(): WasmZcashTransaction;
299
+ extract_zcash_transaction(max_fee_rate_sat_per_vb?: number | null): WasmZcashTransaction;
300
300
  /**
301
301
  * Finalize all inputs in the PSBT
302
302
  *
@@ -1017,12 +1017,13 @@ class BitGoPsbt {
1017
1017
  *
1018
1018
  * This avoids re-parsing bytes by returning the transaction directly.
1019
1019
  * Only valid for Bitcoin-like networks (not Dash or Zcash).
1020
+ * @param {number | null} [max_fee_rate_sat_per_vb]
1020
1021
  * @returns {WasmTransaction}
1021
1022
  */
1022
- extract_bitcoin_transaction() {
1023
+ extract_bitcoin_transaction(max_fee_rate_sat_per_vb) {
1023
1024
  try {
1024
1025
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1025
- wasm.bitgopsbt_extract_bitcoin_transaction(retptr, this.__wbg_ptr);
1026
+ wasm.bitgopsbt_extract_bitcoin_transaction(retptr, this.__wbg_ptr, !isLikeNone(max_fee_rate_sat_per_vb), isLikeNone(max_fee_rate_sat_per_vb) ? 0 : max_fee_rate_sat_per_vb);
1026
1027
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1027
1028
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1028
1029
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -1039,12 +1040,13 @@ class BitGoPsbt {
1039
1040
  *
1040
1041
  * This avoids re-parsing bytes by returning the transaction directly.
1041
1042
  * Only valid for Dash networks.
1043
+ * @param {number | null} [max_fee_rate_sat_per_vb]
1042
1044
  * @returns {WasmDashTransaction}
1043
1045
  */
1044
- extract_dash_transaction() {
1046
+ extract_dash_transaction(max_fee_rate_sat_per_vb) {
1045
1047
  try {
1046
1048
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1047
- wasm.bitgopsbt_extract_dash_transaction(retptr, this.__wbg_ptr);
1049
+ wasm.bitgopsbt_extract_dash_transaction(retptr, this.__wbg_ptr, !isLikeNone(max_fee_rate_sat_per_vb), isLikeNone(max_fee_rate_sat_per_vb) ? 0 : max_fee_rate_sat_per_vb);
1048
1050
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1049
1051
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1050
1052
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -1105,12 +1107,13 @@ class BitGoPsbt {
1105
1107
  * # Returns
1106
1108
  * - `Ok(JsValue)` containing the WASM transaction instance
1107
1109
  * - `Err(WasmUtxoError)` if the PSBT is not fully finalized or extraction fails
1110
+ * @param {number | null} [max_fee_rate_sat_per_vb]
1108
1111
  * @returns {any}
1109
1112
  */
1110
- extract_transaction() {
1113
+ extract_transaction(max_fee_rate_sat_per_vb) {
1111
1114
  try {
1112
1115
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1113
- wasm.bitgopsbt_extract_transaction(retptr, this.__wbg_ptr);
1116
+ wasm.bitgopsbt_extract_transaction(retptr, this.__wbg_ptr, !isLikeNone(max_fee_rate_sat_per_vb), isLikeNone(max_fee_rate_sat_per_vb) ? 0 : max_fee_rate_sat_per_vb);
1114
1117
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1115
1118
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1116
1119
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -1127,12 +1130,13 @@ class BitGoPsbt {
1127
1130
  *
1128
1131
  * This avoids re-parsing bytes by returning the transaction directly.
1129
1132
  * Only valid for Zcash networks.
1133
+ * @param {number | null} [max_fee_rate_sat_per_vb]
1130
1134
  * @returns {WasmZcashTransaction}
1131
1135
  */
1132
- extract_zcash_transaction() {
1136
+ extract_zcash_transaction(max_fee_rate_sat_per_vb) {
1133
1137
  try {
1134
1138
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1135
- wasm.bitgopsbt_extract_zcash_transaction(retptr, this.__wbg_ptr);
1139
+ wasm.bitgopsbt_extract_zcash_transaction(retptr, this.__wbg_ptr, !isLikeNone(max_fee_rate_sat_per_vb), isLikeNone(max_fee_rate_sat_per_vb) ? 0 : max_fee_rate_sat_per_vb);
1136
1140
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1137
1141
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1138
1142
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
Binary file
@@ -170,11 +170,11 @@ export const bitgopsbt_delete_input_kv: (a: number, b: number, c: number, d: num
170
170
  export const bitgopsbt_delete_kv: (a: number, b: number, c: number) => void;
171
171
  export const bitgopsbt_delete_output_kv: (a: number, b: number, c: number, d: number) => void;
172
172
  export const bitgopsbt_expiry_height: (a: number) => number;
173
- export const bitgopsbt_extract_bitcoin_transaction: (a: number, b: number) => void;
174
- export const bitgopsbt_extract_dash_transaction: (a: number, b: number) => void;
173
+ export const bitgopsbt_extract_bitcoin_transaction: (a: number, b: number, c: number, d: number) => void;
174
+ export const bitgopsbt_extract_dash_transaction: (a: number, b: number, c: number, d: number) => void;
175
175
  export const bitgopsbt_extract_half_signed_legacy_tx: (a: number, b: number) => void;
176
- export const bitgopsbt_extract_transaction: (a: number, b: number) => void;
177
- export const bitgopsbt_extract_zcash_transaction: (a: number, b: number) => void;
176
+ export const bitgopsbt_extract_transaction: (a: number, b: number, c: number, d: number) => void;
177
+ export const bitgopsbt_extract_zcash_transaction: (a: number, b: number, c: number, d: number) => void;
178
178
  export const bitgopsbt_finalize_all_inputs: (a: number, b: number) => void;
179
179
  export const bitgopsbt_from_bytes: (a: number, b: number, c: number, d: number, e: number) => void;
180
180
  export const bitgopsbt_from_half_signed_legacy_transaction: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
@@ -568,10 +568,13 @@ export declare class BitGoPsbt extends PsbtBase<WasmBitGoPsbt> implements IPsbtW
568
568
  /**
569
569
  * Extract the final transaction from a finalized PSBT
570
570
  *
571
+ * @param maxFeeRate Optional maximum fee rate in **sat/vB**. `Infinity` skips
572
+ * the absurd-fee check; `undefined` uses rust-bitcoin's default check.
573
+ * Callers holding sat/kB thresholds must divide by 1000 before passing.
571
574
  * @returns The extracted transaction instance
572
575
  * @throws Error if the PSBT is not fully finalized or extraction fails
573
576
  */
574
- extractTransaction(): ITransaction;
577
+ extractTransaction(maxFeeRate?: number): ITransaction;
575
578
  /**
576
579
  * Extract a half-signed transaction in legacy format for p2ms-based script types.
577
580
  *
@@ -565,12 +565,15 @@ export class BitGoPsbt extends PsbtBase {
565
565
  /**
566
566
  * Extract the final transaction from a finalized PSBT
567
567
  *
568
+ * @param maxFeeRate Optional maximum fee rate in **sat/vB**. `Infinity` skips
569
+ * the absurd-fee check; `undefined` uses rust-bitcoin's default check.
570
+ * Callers holding sat/kB thresholds must divide by 1000 before passing.
568
571
  * @returns The extracted transaction instance
569
572
  * @throws Error if the PSBT is not fully finalized or extraction fails
570
573
  */
571
- extractTransaction() {
574
+ extractTransaction(maxFeeRate) {
572
575
  const networkType = this._wasm.get_network_type();
573
- const wasm = this._wasm.extract_transaction();
576
+ const wasm = this._wasm.extract_transaction(maxFeeRate);
574
577
  switch (networkType) {
575
578
  case "dash":
576
579
  return DashTransaction.fromWasm(wasm);
@@ -168,8 +168,11 @@ export declare class ZcashBitGoPsbt extends BitGoPsbt {
168
168
  /**
169
169
  * Extract the final Zcash transaction from a finalized PSBT
170
170
  *
171
+ * @param maxFeeRate Optional maximum fee rate in **sat/vB**. `Infinity` skips
172
+ * the absurd-fee check; `undefined` uses rust-bitcoin's default check.
173
+ * Callers holding sat/kB thresholds must divide by 1000 before passing.
171
174
  * @returns The extracted Zcash transaction instance
172
175
  * @throws Error if the PSBT is not fully finalized or extraction fails
173
176
  */
174
- extractTransaction(): ZcashTransaction;
177
+ extractTransaction(maxFeeRate?: number): ZcashTransaction;
175
178
  }
@@ -187,10 +187,13 @@ export class ZcashBitGoPsbt extends BitGoPsbt {
187
187
  /**
188
188
  * Extract the final Zcash transaction from a finalized PSBT
189
189
  *
190
+ * @param maxFeeRate Optional maximum fee rate in **sat/vB**. `Infinity` skips
191
+ * the absurd-fee check; `undefined` uses rust-bitcoin's default check.
192
+ * Callers holding sat/kB thresholds must divide by 1000 before passing.
190
193
  * @returns The extracted Zcash transaction instance
191
194
  * @throws Error if the PSBT is not fully finalized or extraction fails
192
195
  */
193
- extractTransaction() {
194
- return ZcashTransaction.fromWasm(this.wasm.extract_zcash_transaction());
196
+ extractTransaction(maxFeeRate) {
197
+ return ZcashTransaction.fromWasm(this.wasm.extract_zcash_transaction(maxFeeRate));
195
198
  }
196
199
  }
@@ -5,6 +5,7 @@ export { outputScript, address } from "./address.js";
5
5
  export { Dimensions } from "./Dimensions.js";
6
6
  export { outputScriptTypes, inputScriptTypes, type OutputScriptType, type InputScriptType, type ScriptType, } from "./scriptType.js";
7
7
  export { ChainCode, chainCodes, assertChainCode, type Scope } from "./chains.js";
8
+ export { requiresPrevTxForP2sh } from "./prevTx.js";
8
9
  export { BitGoPsbt, getWalletKeysFromPsbt, type NetworkName, type ScriptId, type ParsedInput, type ParsedOutput, type ParsedTransaction, type SignPath, type CreateEmptyOptions, type AddInputOptions, type AddOutputOptions, type AddWalletInputOptions, type AddWalletOutputOptions, type ParseTransactionOptions, type ParseOutputsOptions, type HydrationUnspent, } from "./BitGoPsbt.js";
9
10
  export { BitGoKeySubtype, type PsbtKvKey } from "./BitGoKeySubtype.js";
10
11
  export { ZcashBitGoPsbt, type ZcashNetworkName, type CreateEmptyZcashOptions, } from "./ZcashBitGoPsbt.js";
@@ -5,6 +5,8 @@ export { outputScript, address } from "./address.js";
5
5
  export { Dimensions } from "./Dimensions.js";
6
6
  export { outputScriptTypes, inputScriptTypes, } from "./scriptType.js";
7
7
  export { ChainCode, chainCodes, assertChainCode } from "./chains.js";
8
+ // Previous-transaction inclusion policy (pure JS, no WASM init)
9
+ export { requiresPrevTxForP2sh } from "./prevTx.js";
8
10
  // Bitcoin-like PSBT (for all non-Zcash networks)
9
11
  export { BitGoPsbt, getWalletKeysFromPsbt, } from "./BitGoPsbt.js";
10
12
  export { BitGoKeySubtype } from "./BitGoKeySubtype.js";
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Previous-transaction inclusion policy for fixed-script wallet PSBT inputs.
3
+ *
4
+ * Decides whether a p2sh input requires the full previous transaction
5
+ * (PSBT_IN_NON_WITNESS_UTXO) or can be signed from witness_utxo-only.
6
+ *
7
+ * This is a pure-JS module (no WASM initialization) so callers can evaluate
8
+ * the policy cheaply without loading the wasm-utxo module.
9
+ */
10
+ import { type CoinName } from "../coinName.js";
11
+ /**
12
+ * Whether a p2sh input requires the full previous transaction
13
+ * (PSBT_IN_NON_WITNESS_UTXO). Callers are expected to have already
14
+ * confirmed the input is p2sh (non-segwit) and that the tx format
15
+ * includes prevTx (e.g. "psbt", not "psbt-lite"); this predicate only
16
+ * answers the coin-level question.
17
+ *
18
+ * Returns false for value-committing coins whose sighash commits the
19
+ * input amount, making `non_witness_utxo` (full prevTx) cryptographically
20
+ * pointless for signing p2sh inputs — `witness_utxo` (value +
21
+ * scriptPubKey) suffices:
22
+ *
23
+ * - Zcash (`zec`/`tzec`): ZIP-243 transparent sighash commits the amount.
24
+ * Including prevTx also crashes wasm-utxo, whose consensus::deserialize
25
+ * rejects Zcash overwintered transactions.
26
+ * - BCH family (`bch`/`bcha`/`bsv`/`btg` + testnets): replay-protected
27
+ * BIP-143 sighash (SIGHASH_FORKID, the default for the whole family)
28
+ * commits the 8-byte value as preimage item #6. eCash is `bcha`/`tbcha`.
29
+ * For the BCH family, skipping prevTx is an optimization (no DB fetch)
30
+ * plus defense-in-depth, with the same fee-validation risk that the
31
+ * existing `psbt-lite` path already accepts for all coins.
32
+ *
33
+ * Testnets are normalized via `getMainnet` before the switch. True
34
+ * otherwise.
35
+ */
36
+ export declare function requiresPrevTxForP2sh(coinName: CoinName): boolean;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Previous-transaction inclusion policy for fixed-script wallet PSBT inputs.
3
+ *
4
+ * Decides whether a p2sh input requires the full previous transaction
5
+ * (PSBT_IN_NON_WITNESS_UTXO) or can be signed from witness_utxo-only.
6
+ *
7
+ * This is a pure-JS module (no WASM initialization) so callers can evaluate
8
+ * the policy cheaply without loading the wasm-utxo module.
9
+ */
10
+ import { getMainnet } from "../coinName.js";
11
+ /**
12
+ * Whether a p2sh input requires the full previous transaction
13
+ * (PSBT_IN_NON_WITNESS_UTXO). Callers are expected to have already
14
+ * confirmed the input is p2sh (non-segwit) and that the tx format
15
+ * includes prevTx (e.g. "psbt", not "psbt-lite"); this predicate only
16
+ * answers the coin-level question.
17
+ *
18
+ * Returns false for value-committing coins whose sighash commits the
19
+ * input amount, making `non_witness_utxo` (full prevTx) cryptographically
20
+ * pointless for signing p2sh inputs — `witness_utxo` (value +
21
+ * scriptPubKey) suffices:
22
+ *
23
+ * - Zcash (`zec`/`tzec`): ZIP-243 transparent sighash commits the amount.
24
+ * Including prevTx also crashes wasm-utxo, whose consensus::deserialize
25
+ * rejects Zcash overwintered transactions.
26
+ * - BCH family (`bch`/`bcha`/`bsv`/`btg` + testnets): replay-protected
27
+ * BIP-143 sighash (SIGHASH_FORKID, the default for the whole family)
28
+ * commits the 8-byte value as preimage item #6. eCash is `bcha`/`tbcha`.
29
+ * For the BCH family, skipping prevTx is an optimization (no DB fetch)
30
+ * plus defense-in-depth, with the same fee-validation risk that the
31
+ * existing `psbt-lite` path already accepts for all coins.
32
+ *
33
+ * Testnets are normalized via `getMainnet` before the switch. True
34
+ * otherwise.
35
+ */
36
+ export function requiresPrevTxForP2sh(coinName) {
37
+ switch (getMainnet(coinName)) {
38
+ case "zec": // Zcash (ZIP-243)
39
+ case "bch": // Bitcoin Cash (BIP-143/FORKID)
40
+ case "bcha": // eCash (BIP-143/FORKID)
41
+ case "bsv": // Bitcoin SV (BIP-143/FORKID)
42
+ case "btg": // Bitcoin Gold (BIP-143/FORKID)
43
+ return false;
44
+ default:
45
+ return true;
46
+ }
47
+ }
@@ -17,6 +17,7 @@ export type WasmUtxoVersionInfo = {
17
17
  };
18
18
  export declare function getWasmUtxoVersion(): WasmUtxoVersionInfo;
19
19
  export { type CoinName, getMainnet, isMainnet, isTestnet, isCoinName } from "./coinName.js";
20
+ export { requiresPrevTxForP2sh } from "./fixedScriptWallet/prevTx.js";
20
21
  export type { Triple } from "./triple.js";
21
22
  export type { AddressFormat } from "./address.js";
22
23
  export type { TapLeafScript, PreparedInscriptionRevealData } from "./inscriptions.js";
@@ -23,6 +23,7 @@ export function getWasmUtxoVersion() {
23
23
  return WasmUtxoNamespace.get_wasm_utxo_version();
24
24
  }
25
25
  export { getMainnet, isMainnet, isTestnet, isCoinName } from "./coinName.js";
26
+ export { requiresPrevTxForP2sh } from "./fixedScriptWallet/prevTx.js";
26
27
  const WASM_UTXO_ERROR_SYMBOL = Symbol.for("@bitgo/wasm-utxo/error");
27
28
  export function isWasmUtxoError(e) {
28
29
  return (e instanceof Error &&
@@ -249,14 +249,14 @@ export class BitGoPsbt {
249
249
  * This avoids re-parsing bytes by returning the transaction directly.
250
250
  * Only valid for Bitcoin-like networks (not Dash or Zcash).
251
251
  */
252
- extract_bitcoin_transaction(): WasmTransaction;
252
+ extract_bitcoin_transaction(max_fee_rate_sat_per_vb?: number | null): WasmTransaction;
253
253
  /**
254
254
  * Extract the final transaction as a WasmDashTransaction (for Dash networks)
255
255
  *
256
256
  * This avoids re-parsing bytes by returning the transaction directly.
257
257
  * Only valid for Dash networks.
258
258
  */
259
- extract_dash_transaction(): WasmDashTransaction;
259
+ extract_dash_transaction(max_fee_rate_sat_per_vb?: number | null): WasmDashTransaction;
260
260
  /**
261
261
  * Extract a half-signed transaction in legacy format for p2ms-based script types.
262
262
  *
@@ -289,14 +289,14 @@ export class BitGoPsbt {
289
289
  * - `Ok(JsValue)` containing the WASM transaction instance
290
290
  * - `Err(WasmUtxoError)` if the PSBT is not fully finalized or extraction fails
291
291
  */
292
- extract_transaction(): any;
292
+ extract_transaction(max_fee_rate_sat_per_vb?: number | null): any;
293
293
  /**
294
294
  * Extract the final transaction as a WasmZcashTransaction (for Zcash networks)
295
295
  *
296
296
  * This avoids re-parsing bytes by returning the transaction directly.
297
297
  * Only valid for Zcash networks.
298
298
  */
299
- extract_zcash_transaction(): WasmZcashTransaction;
299
+ extract_zcash_transaction(max_fee_rate_sat_per_vb?: number | null): WasmZcashTransaction;
300
300
  /**
301
301
  * Finalize all inputs in the PSBT
302
302
  *
@@ -1013,12 +1013,13 @@ export class BitGoPsbt {
1013
1013
  *
1014
1014
  * This avoids re-parsing bytes by returning the transaction directly.
1015
1015
  * Only valid for Bitcoin-like networks (not Dash or Zcash).
1016
+ * @param {number | null} [max_fee_rate_sat_per_vb]
1016
1017
  * @returns {WasmTransaction}
1017
1018
  */
1018
- extract_bitcoin_transaction() {
1019
+ extract_bitcoin_transaction(max_fee_rate_sat_per_vb) {
1019
1020
  try {
1020
1021
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1021
- wasm.bitgopsbt_extract_bitcoin_transaction(retptr, this.__wbg_ptr);
1022
+ wasm.bitgopsbt_extract_bitcoin_transaction(retptr, this.__wbg_ptr, !isLikeNone(max_fee_rate_sat_per_vb), isLikeNone(max_fee_rate_sat_per_vb) ? 0 : max_fee_rate_sat_per_vb);
1022
1023
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1023
1024
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1024
1025
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -1035,12 +1036,13 @@ export class BitGoPsbt {
1035
1036
  *
1036
1037
  * This avoids re-parsing bytes by returning the transaction directly.
1037
1038
  * Only valid for Dash networks.
1039
+ * @param {number | null} [max_fee_rate_sat_per_vb]
1038
1040
  * @returns {WasmDashTransaction}
1039
1041
  */
1040
- extract_dash_transaction() {
1042
+ extract_dash_transaction(max_fee_rate_sat_per_vb) {
1041
1043
  try {
1042
1044
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1043
- wasm.bitgopsbt_extract_dash_transaction(retptr, this.__wbg_ptr);
1045
+ wasm.bitgopsbt_extract_dash_transaction(retptr, this.__wbg_ptr, !isLikeNone(max_fee_rate_sat_per_vb), isLikeNone(max_fee_rate_sat_per_vb) ? 0 : max_fee_rate_sat_per_vb);
1044
1046
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1045
1047
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1046
1048
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -1101,12 +1103,13 @@ export class BitGoPsbt {
1101
1103
  * # Returns
1102
1104
  * - `Ok(JsValue)` containing the WASM transaction instance
1103
1105
  * - `Err(WasmUtxoError)` if the PSBT is not fully finalized or extraction fails
1106
+ * @param {number | null} [max_fee_rate_sat_per_vb]
1104
1107
  * @returns {any}
1105
1108
  */
1106
- extract_transaction() {
1109
+ extract_transaction(max_fee_rate_sat_per_vb) {
1107
1110
  try {
1108
1111
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1109
- wasm.bitgopsbt_extract_transaction(retptr, this.__wbg_ptr);
1112
+ wasm.bitgopsbt_extract_transaction(retptr, this.__wbg_ptr, !isLikeNone(max_fee_rate_sat_per_vb), isLikeNone(max_fee_rate_sat_per_vb) ? 0 : max_fee_rate_sat_per_vb);
1110
1113
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1111
1114
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1112
1115
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -1123,12 +1126,13 @@ export class BitGoPsbt {
1123
1126
  *
1124
1127
  * This avoids re-parsing bytes by returning the transaction directly.
1125
1128
  * Only valid for Zcash networks.
1129
+ * @param {number | null} [max_fee_rate_sat_per_vb]
1126
1130
  * @returns {WasmZcashTransaction}
1127
1131
  */
1128
- extract_zcash_transaction() {
1132
+ extract_zcash_transaction(max_fee_rate_sat_per_vb) {
1129
1133
  try {
1130
1134
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
1131
- wasm.bitgopsbt_extract_zcash_transaction(retptr, this.__wbg_ptr);
1135
+ wasm.bitgopsbt_extract_zcash_transaction(retptr, this.__wbg_ptr, !isLikeNone(max_fee_rate_sat_per_vb), isLikeNone(max_fee_rate_sat_per_vb) ? 0 : max_fee_rate_sat_per_vb);
1132
1136
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
1133
1137
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
1134
1138
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
Binary file
@@ -170,11 +170,11 @@ export const bitgopsbt_delete_input_kv: (a: number, b: number, c: number, d: num
170
170
  export const bitgopsbt_delete_kv: (a: number, b: number, c: number) => void;
171
171
  export const bitgopsbt_delete_output_kv: (a: number, b: number, c: number, d: number) => void;
172
172
  export const bitgopsbt_expiry_height: (a: number) => number;
173
- export const bitgopsbt_extract_bitcoin_transaction: (a: number, b: number) => void;
174
- export const bitgopsbt_extract_dash_transaction: (a: number, b: number) => void;
173
+ export const bitgopsbt_extract_bitcoin_transaction: (a: number, b: number, c: number, d: number) => void;
174
+ export const bitgopsbt_extract_dash_transaction: (a: number, b: number, c: number, d: number) => void;
175
175
  export const bitgopsbt_extract_half_signed_legacy_tx: (a: number, b: number) => void;
176
- export const bitgopsbt_extract_transaction: (a: number, b: number) => void;
177
- export const bitgopsbt_extract_zcash_transaction: (a: number, b: number) => void;
176
+ export const bitgopsbt_extract_transaction: (a: number, b: number, c: number, d: number) => void;
177
+ export const bitgopsbt_extract_zcash_transaction: (a: number, b: number, c: number, d: number) => void;
178
178
  export const bitgopsbt_finalize_all_inputs: (a: number, b: number) => void;
179
179
  export const bitgopsbt_from_bytes: (a: number, b: number, c: number, d: number, e: number) => void;
180
180
  export const bitgopsbt_from_half_signed_legacy_transaction: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bitgo/wasm-utxo",
3
3
  "description": "WebAssembly wrapper for rust-bitcoin (beta)",
4
- "version": "4.18.0",
4
+ "version": "4.20.0",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",