@caravan/psbt 1.7.1 → 1.9.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
@@ -736,9 +736,6 @@ var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
736
736
  * set).
737
737
  */
738
738
  get isReadyForConstructor() {
739
- if (this.PSBT_GLOBAL_FALLBACK_LOCKTIME === null) {
740
- return false;
741
- }
742
739
  if (!this.isModifiable(["INPUTS" /* INPUTS */]) && !this.isModifiable(["OUTPUTS" /* OUTPUTS */])) {
743
740
  return false;
744
741
  }
@@ -880,12 +877,14 @@ var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
880
877
  * constructed with a psbt, this method acts outside of the Creator role to
881
878
  * validate the current state of the psbt.
882
879
  */
883
- validate() {
880
+ validate(allowTxnVersion1) {
884
881
  if (this.PSBT_GLOBAL_VERSION < 2) {
885
882
  throw Error("PsbtV2 has a version field set less than 2");
886
883
  }
887
- if (this.PSBT_GLOBAL_TX_VERSION < 2) {
884
+ if (!allowTxnVersion1 && this.PSBT_GLOBAL_TX_VERSION < 2) {
888
885
  throw Error("PsbtV2 has a tx version field set less than 2");
886
+ } else if (allowTxnVersion1 && this.PSBT_GLOBAL_TX_VERSION < 2) {
887
+ console.warn("Dangerously setting PsbtV2.PSBT_GLOBAL_TX_VERSION to 1!");
889
888
  }
890
889
  for (const prevInTxid of this.PSBT_IN_PREVIOUS_TXID) {
891
890
  if (!prevInTxid) {
@@ -898,7 +897,7 @@ var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
898
897
  }
899
898
  }
900
899
  for (const amount of this.PSBT_OUT_AMOUNT) {
901
- if (!amount) {
900
+ if (amount === void 0 || amount === null) {
902
901
  throw Error("PsbtV2 input is missing PSBT_OUT_AMOUNT");
903
902
  }
904
903
  }
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
@@ -695,9 +695,6 @@ var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
695
695
  * set).
696
696
  */
697
697
  get isReadyForConstructor() {
698
- if (this.PSBT_GLOBAL_FALLBACK_LOCKTIME === null) {
699
- return false;
700
- }
701
698
  if (!this.isModifiable(["INPUTS" /* INPUTS */]) && !this.isModifiable(["OUTPUTS" /* OUTPUTS */])) {
702
699
  return false;
703
700
  }
@@ -839,12 +836,14 @@ var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
839
836
  * constructed with a psbt, this method acts outside of the Creator role to
840
837
  * validate the current state of the psbt.
841
838
  */
842
- validate() {
839
+ validate(allowTxnVersion1) {
843
840
  if (this.PSBT_GLOBAL_VERSION < 2) {
844
841
  throw Error("PsbtV2 has a version field set less than 2");
845
842
  }
846
- if (this.PSBT_GLOBAL_TX_VERSION < 2) {
843
+ if (!allowTxnVersion1 && this.PSBT_GLOBAL_TX_VERSION < 2) {
847
844
  throw Error("PsbtV2 has a tx version field set less than 2");
845
+ } else if (allowTxnVersion1 && this.PSBT_GLOBAL_TX_VERSION < 2) {
846
+ console.warn("Dangerously setting PsbtV2.PSBT_GLOBAL_TX_VERSION to 1!");
848
847
  }
849
848
  for (const prevInTxid of this.PSBT_IN_PREVIOUS_TXID) {
850
849
  if (!prevInTxid) {
@@ -857,7 +856,7 @@ var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
857
856
  }
858
857
  }
859
858
  for (const amount of this.PSBT_OUT_AMOUNT) {
860
- if (!amount) {
859
+ if (amount === void 0 || amount === null) {
861
860
  throw Error("PsbtV2 input is missing PSBT_OUT_AMOUNT");
862
861
  }
863
862
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caravan/psbt",
3
- "version": "1.7.1",
3
+ "version": "1.9.0",
4
4
  "description": "typescript library for working with PSBTs",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",