opnet 1.8.3 → 1.8.5

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "opnet",
3
3
  "type": "module",
4
- "version": "1.8.3",
4
+ "version": "1.8.5",
5
5
  "author": "OP_NET",
6
6
  "description": "The perfect library for building Bitcoin-based applications.",
7
7
  "engines": {
@@ -104,22 +104,23 @@
104
104
  "@babel/preset-env": "^7.29.0",
105
105
  "@babel/preset-typescript": "^7.28.5",
106
106
  "@eslint/js": "^10.0.1",
107
- "@microsoft/api-extractor": "7.57.6",
108
- "@types/node": "^25.3.5",
109
- "@vitest/browser": "^4.0.18",
110
- "@vitest/browser-playwright": "^4.0.18",
111
- "@vitest/ui": "^4.0.18",
107
+ "@microsoft/api-extractor": "7.57.7",
108
+ "@types/node": "^25.5.0",
109
+ "@vitest/browser": "^4.1.0",
110
+ "@vitest/browser-playwright": "^4.1.0",
111
+ "@vitest/ui": "^4.1.0",
112
+ "esbuild": "^0.27.4",
112
113
  "eslint": "^10.0.3",
113
114
  "madge": "^8.0.0",
114
115
  "playwright": "^1.58.2",
115
116
  "stream-browserify": "^3.0.0",
116
117
  "typedoc": "^0.28.17",
117
118
  "typescript": "^5.9.3",
118
- "typescript-eslint": "^8.56.1",
119
- "vite": "^7.3.1",
119
+ "typescript-eslint": "^8.57.0",
120
+ "vite": "^8.0.0",
120
121
  "vite-plugin-dts": "4.5.4",
121
122
  "vite-plugin-node-polyfills": "^0.25.0",
122
- "vitest": "^4.0.18"
123
+ "vitest": "^4.1.0"
123
124
  },
124
125
  "peerDependencies": {
125
126
  "react-native-worklets": ">=0.7.0"
@@ -135,13 +136,18 @@
135
136
  "@btc-vision/bitcoin-rpc": "^1.1.2",
136
137
  "@btc-vision/ecpair": "^4.0.5",
137
138
  "@btc-vision/logger": "^1.0.8",
138
- "@btc-vision/transaction": "^1.8.0",
139
+ "@btc-vision/transaction": "^1.8.2",
139
140
  "@noble/hashes": "^2.0.1",
140
141
  "bignumber.js": "^10.0.2",
141
142
  "long": "^5.3.2",
142
143
  "p-limit": "^7.3.0",
143
144
  "pako": "^2.1.0",
144
145
  "protobufjs": "^8.0.0",
145
- "undici": "^7.22.0"
146
+ "undici": "^7.24.0"
147
+ },
148
+ "overrides": {
149
+ "vite-plugin-node-polyfills": {
150
+ "vite": "$vite"
151
+ }
146
152
  }
147
153
  }
package/src/_version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '1.8.3';
1
+ export const version = '1.8.5';
@@ -804,6 +804,38 @@ export class CallResult<
804
804
  }
805
805
  }
806
806
 
807
+ private max(a: bigint, b: bigint): bigint {
808
+ return a > b ? a : b;
809
+ }
810
+
811
+ private ensureUTXOsAvailable(
812
+ utxos: UTXO[] | undefined | null,
813
+ ): asserts utxos is UTXO[] & { length: number } {
814
+ if (!utxos || utxos.length === 0) {
815
+ throw new Error(
816
+ 'Wallet optimization required. No UTXOs available. You may need to split your wallet UTXOs so at ' +
817
+ 'least one non-extra-input UTXO is available for the funding transaction.',
818
+ );
819
+ }
820
+ }
821
+
822
+ private computeRequiredAmount(
823
+ gasFee: bigint,
824
+ priority: bigint,
825
+ amountAddition: bigint,
826
+ totalOuts: bigint,
827
+ extraInputValue: bigint,
828
+ miningCost: bigint = 0n,
829
+ maximumAllowedSatToSpend: bigint = 0n,
830
+ ): bigint {
831
+ const gross = this.max(
832
+ gasFee + priority + amountAddition + totalOuts + miningCost,
833
+ maximumAllowedSatToSpend,
834
+ );
835
+
836
+ return gross > extraInputValue ? gross - extraInputValue : 1n;
837
+ }
838
+
807
839
  /**
808
840
  * Acquire UTXOs for the transaction.
809
841
  * @param {TransactionParameters} interactionParams - The transaction parameters.
@@ -829,15 +861,25 @@ export class CallResult<
829
861
 
830
862
  const gasFee = this.bigintMax(this.estimatedSatGas, interactionParams.minGas ?? 0n);
831
863
 
832
- const preWant =
833
- gasFee +
834
- priority +
835
- amountAddition +
836
- totalOuts +
837
- interactionParams.maximumAllowedSatToSpend;
864
+ const extraInputValue = (interactionParams.extraInputs ?? []).reduce(
865
+ (s, u) => s + u.value,
866
+ 0n,
867
+ );
868
+
869
+ const preWant = this.computeRequiredAmount(
870
+ gasFee,
871
+ priority,
872
+ amountAddition,
873
+ totalOuts,
874
+ extraInputValue,
875
+ 0n,
876
+ interactionParams.maximumAllowedSatToSpend,
877
+ );
838
878
 
839
879
  let utxos = interactionParams.utxos ?? (await this.#fetchUTXOs(preWant, interactionParams));
840
880
 
881
+ this.ensureUTXOsAvailable(utxos);
882
+
841
883
  let refetched = false;
842
884
  while (true) {
843
885
  const miningCost = TransactionHelper.estimateMiningCost(
@@ -848,13 +890,15 @@ export class CallResult<
848
890
  feeRate,
849
891
  );
850
892
 
851
- const want =
852
- gasFee +
853
- priority +
854
- amountAddition +
855
- totalOuts +
856
- miningCost +
857
- interactionParams.maximumAllowedSatToSpend;
893
+ const want = this.computeRequiredAmount(
894
+ gasFee,
895
+ priority,
896
+ amountAddition,
897
+ totalOuts,
898
+ extraInputValue,
899
+ miningCost,
900
+ interactionParams.maximumAllowedSatToSpend,
901
+ );
858
902
 
859
903
  const have = utxos.reduce((s, u) => s + u.value, 0n);
860
904
  if (have >= want) break;
@@ -866,6 +910,8 @@ export class CallResult<
866
910
  utxos = await this.#fetchUTXOs(want, interactionParams);
867
911
  refetched = true;
868
912
 
913
+ this.ensureUTXOsAvailable(utxos);
914
+
869
915
  const haveAfter = utxos.reduce((s, u) => s + u.value, 0n);
870
916
  if (haveAfter === have) {
871
917
  throw new Error('Not enough sat to complete transaction');