@caravan/psbt 1.7.1 → 1.8.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/index.d.ts CHANGED
@@ -77,12 +77,19 @@ declare abstract class PsbtV2Maps {
77
77
  * BIP-defined keytypes. Very few setters and modifier methods exist. As they
78
78
  * are added, they should enforce implied and documented rules and limitations.
79
79
  *
80
- * Defining BIPs:
81
- * https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki
80
+ * allowTxnVersion1: A Note
81
+ * A psbtv2 must have its transaction version GTE 2 to be bip370 compliant. If
82
+ * this class is instantiated with allowTxnVersion1 set to `true`, then a psbtv2
83
+ * which has had its txn version forceably set to 1 (for example with
84
+ * PsbtV2.dangerouslySetGlobalTxVersion1) can be instantiated. This has,
85
+ * possibly dangerous implications concerning how the locktime might be
86
+ * interpreted.
87
+ *
88
+ * Defining BIPs: https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki
82
89
  * https://github.com/bitcoin/bips/blob/master/bip-0370.mediawiki
83
90
  */
84
91
  declare class PsbtV2 extends PsbtV2Maps {
85
- constructor(psbt?: Buffer | string);
92
+ constructor(psbt?: Buffer | string, allowTxnVersion1?: boolean);
86
93
  /**
87
94
  * Globals Getters/Setters
88
95
  */
package/dist/index.js CHANGED
@@ -363,12 +363,12 @@ var PsbtConversionMaps = class extends PsbtV2Maps {
363
363
 
364
364
  // src/psbtv2/psbtv2.ts
365
365
  var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
366
- constructor(psbt) {
366
+ constructor(psbt, allowTxnVersion1 = false) {
367
367
  super(psbt);
368
368
  if (!psbt) {
369
369
  this.create();
370
370
  }
371
- this.validate();
371
+ this.validate(allowTxnVersion1);
372
372
  }
373
373
  /**
374
374
  * Globals Getters/Setters
@@ -880,12 +880,14 @@ var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
880
880
  * constructed with a psbt, this method acts outside of the Creator role to
881
881
  * validate the current state of the psbt.
882
882
  */
883
- validate() {
883
+ validate(allowTxnVersion1) {
884
884
  if (this.PSBT_GLOBAL_VERSION < 2) {
885
885
  throw Error("PsbtV2 has a version field set less than 2");
886
886
  }
887
- if (this.PSBT_GLOBAL_TX_VERSION < 2) {
887
+ if (!allowTxnVersion1 && this.PSBT_GLOBAL_TX_VERSION < 2) {
888
888
  throw Error("PsbtV2 has a tx version field set less than 2");
889
+ } else if (allowTxnVersion1 && this.PSBT_GLOBAL_TX_VERSION < 2) {
890
+ console.warn("Dangerously setting PsbtV2.PSBT_GLOBAL_TX_VERSION to 1!");
889
891
  }
890
892
  for (const prevInTxid of this.PSBT_IN_PREVIOUS_TXID) {
891
893
  if (!prevInTxid) {
@@ -898,7 +900,7 @@ var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
898
900
  }
899
901
  }
900
902
  for (const amount of this.PSBT_OUT_AMOUNT) {
901
- if (!amount) {
903
+ if (amount === void 0 || amount === null) {
902
904
  throw Error("PsbtV2 input is missing PSBT_OUT_AMOUNT");
903
905
  }
904
906
  }
package/dist/index.mjs CHANGED
@@ -322,12 +322,12 @@ var PsbtConversionMaps = class extends PsbtV2Maps {
322
322
 
323
323
  // src/psbtv2/psbtv2.ts
324
324
  var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
325
- constructor(psbt) {
325
+ constructor(psbt, allowTxnVersion1 = false) {
326
326
  super(psbt);
327
327
  if (!psbt) {
328
328
  this.create();
329
329
  }
330
- this.validate();
330
+ this.validate(allowTxnVersion1);
331
331
  }
332
332
  /**
333
333
  * Globals Getters/Setters
@@ -839,12 +839,14 @@ var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
839
839
  * constructed with a psbt, this method acts outside of the Creator role to
840
840
  * validate the current state of the psbt.
841
841
  */
842
- validate() {
842
+ validate(allowTxnVersion1) {
843
843
  if (this.PSBT_GLOBAL_VERSION < 2) {
844
844
  throw Error("PsbtV2 has a version field set less than 2");
845
845
  }
846
- if (this.PSBT_GLOBAL_TX_VERSION < 2) {
846
+ if (!allowTxnVersion1 && this.PSBT_GLOBAL_TX_VERSION < 2) {
847
847
  throw Error("PsbtV2 has a tx version field set less than 2");
848
+ } else if (allowTxnVersion1 && this.PSBT_GLOBAL_TX_VERSION < 2) {
849
+ console.warn("Dangerously setting PsbtV2.PSBT_GLOBAL_TX_VERSION to 1!");
848
850
  }
849
851
  for (const prevInTxid of this.PSBT_IN_PREVIOUS_TXID) {
850
852
  if (!prevInTxid) {
@@ -857,7 +859,7 @@ var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
857
859
  }
858
860
  }
859
861
  for (const amount of this.PSBT_OUT_AMOUNT) {
860
- if (!amount) {
862
+ if (amount === void 0 || amount === null) {
861
863
  throw Error("PsbtV2 input is missing PSBT_OUT_AMOUNT");
862
864
  }
863
865
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caravan/psbt",
3
- "version": "1.7.1",
3
+ "version": "1.8.0",
4
4
  "description": "typescript library for working with PSBTs",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",