@btc-vision/transaction 1.8.0 → 1.8.2

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 (35) hide show
  1. package/browser/_version.d.ts +1 -1
  2. package/browser/btc-vision-bitcoin.js +5000 -8302
  3. package/browser/generators/builders/HashCommitmentGenerator.d.ts.map +1 -1
  4. package/browser/index.js +4760 -8702
  5. package/browser/noble-curves.js +1842 -1010
  6. package/browser/noble-hashes.js +854 -1512
  7. package/browser/rolldown-runtime.js +27 -0
  8. package/browser/transaction/builders/DeploymentTransaction.d.ts.map +1 -1
  9. package/browser/transaction/builders/FundingTransaction.d.ts.map +1 -1
  10. package/browser/transaction/builders/SharedInteractionTransaction.d.ts.map +1 -1
  11. package/browser/vendors.js +7359 -9101
  12. package/build/_version.d.ts +1 -1
  13. package/build/_version.js +1 -1
  14. package/build/generators/builders/HashCommitmentGenerator.d.ts.map +1 -1
  15. package/build/generators/builders/HashCommitmentGenerator.js.map +1 -1
  16. package/build/transaction/TransactionFactory.js +1 -1
  17. package/build/transaction/TransactionFactory.js.map +1 -1
  18. package/build/transaction/builders/DeploymentTransaction.d.ts.map +1 -1
  19. package/build/transaction/builders/DeploymentTransaction.js +1 -1
  20. package/build/transaction/builders/DeploymentTransaction.js.map +1 -1
  21. package/build/transaction/builders/FundingTransaction.d.ts.map +1 -1
  22. package/build/transaction/builders/FundingTransaction.js +30 -18
  23. package/build/transaction/builders/FundingTransaction.js.map +1 -1
  24. package/build/transaction/builders/SharedInteractionTransaction.d.ts.map +1 -1
  25. package/build/transaction/builders/SharedInteractionTransaction.js +1 -1
  26. package/build/transaction/builders/SharedInteractionTransaction.js.map +1 -1
  27. package/build/tsconfig.build.tsbuildinfo +1 -1
  28. package/package.json +15 -9
  29. package/src/_version.ts +1 -1
  30. package/src/generators/builders/HashCommitmentGenerator.ts +8 -0
  31. package/src/transaction/TransactionFactory.ts +1 -1
  32. package/src/transaction/builders/DeploymentTransaction.ts +1 -1
  33. package/src/transaction/builders/FundingTransaction.ts +32 -18
  34. package/src/transaction/builders/SharedInteractionTransaction.ts +1 -1
  35. package/test/split-fee-bug.test.ts +827 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@btc-vision/transaction",
3
3
  "type": "module",
4
- "version": "1.8.0",
4
+ "version": "1.8.2",
5
5
  "author": "BlobMaster41",
6
6
  "description": "OPNet transaction library allows you to create and sign transactions for the OPNet network.",
7
7
  "engines": {
@@ -145,11 +145,11 @@
145
145
  "prebuild": "npm run check:circular"
146
146
  },
147
147
  "devDependencies": {
148
- "@types/node": "^25.3.5",
148
+ "@types/node": "^25.5.0",
149
149
  "@types/sha.js": "^2.4.4",
150
- "@vitest/browser": "^4.0.18",
151
- "@vitest/browser-playwright": "^4.0.18",
152
- "@vitest/ui": "^4.0.18",
150
+ "@vitest/browser": "^4.1.0",
151
+ "@vitest/browser-playwright": "^4.1.0",
152
+ "@vitest/ui": "^4.1.0",
153
153
  "browserify-zlib": "^0.2.0",
154
154
  "buffer": "^6.0.3",
155
155
  "eslint": "^10.0.3",
@@ -159,16 +159,16 @@
159
159
  "process": "^0.11.10",
160
160
  "stream-browserify": "^3.0.0",
161
161
  "typedoc": "^0.28.17",
162
- "typescript-eslint": "^8.56.1",
163
- "vite": "^7.3.1",
162
+ "typescript-eslint": "^8.57.0",
163
+ "vite": "^8.0.0",
164
164
  "vite-plugin-dts": "^4.5.4",
165
165
  "vite-plugin-node-polyfills": "^0.25.0",
166
- "vitest": "^4.0.18"
166
+ "vitest": "^4.1.0"
167
167
  },
168
168
  "dependencies": {
169
169
  "@btc-vision/bip32": "^7.1.2",
170
170
  "@btc-vision/bitcoin": "^7.0.0",
171
- "@btc-vision/bitcoin-rpc": "^1.1.0",
171
+ "@btc-vision/bitcoin-rpc": "^1.1.2",
172
172
  "@btc-vision/ecpair": "^4.0.5",
173
173
  "@btc-vision/logger": "^1.0.8",
174
174
  "@eslint/js": "^10.0.1",
@@ -177,8 +177,14 @@
177
177
  "bech32": "^2.0.0",
178
178
  "bip174": "^3.0.0",
179
179
  "bip39": "^3.1.0",
180
+ "esbuild": "^0.27.4",
180
181
  "pako": "^2.1.0",
181
182
  "sha.js": "^2.4.12",
182
183
  "typescript": "^5.9.3"
184
+ },
185
+ "overrides": {
186
+ "vite-plugin-node-polyfills": {
187
+ "vite": "$vite"
188
+ }
183
189
  }
184
190
  }
package/src/_version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '1.8.0';
1
+ export const version = '1.8.2';
@@ -35,13 +35,16 @@ export class HashCommitmentGenerator extends Logger {
35
35
 
36
36
  /** Maximum weight per standard transaction */
37
37
  public static readonly MAX_STANDARD_WEIGHT: number = 400000;
38
+
38
39
  /** Minimum satoshis per output (dust limit) */
39
40
  public static readonly MIN_OUTPUT_VALUE: bigint = 330n;
41
+
40
42
  /**
41
43
  * Bytes per hash commitment in witness script.
42
44
  * OP_HASH160 (1) + push (1) + hash (20) + OP_EQUALVERIFY (1) = 23 bytes
43
45
  */
44
46
  private static readonly BYTES_PER_COMMITMENT: number = 23;
47
+
45
48
  /**
46
49
  * Fixed overhead in witness serialization:
47
50
  * - Stack item count: 1 byte
@@ -50,6 +53,7 @@ export class HashCommitmentGenerator extends Logger {
50
53
  * - Script base (pubkey + checksig): 35 bytes
51
54
  */
52
55
  private static readonly WITNESS_FIXED_OVERHEAD: number = 1 + 73 + 3 + 35;
56
+
53
57
  /**
54
58
  * Per-chunk overhead in witness:
55
59
  * - Data: 81 bytes (80 + 1 length prefix)
@@ -58,6 +62,7 @@ export class HashCommitmentGenerator extends Logger {
58
62
  */
59
63
  private static readonly WITNESS_PER_CHUNK_OVERHEAD: number =
60
64
  HashCommitmentGenerator.MAX_CHUNK_SIZE + 1 + HashCommitmentGenerator.BYTES_PER_COMMITMENT;
65
+
61
66
  /**
62
67
  * Maximum data chunks per P2WSH output.
63
68
  * Limited by total witness size: (1650 - 112) / 104 = 14 chunks
@@ -67,6 +72,7 @@ export class HashCommitmentGenerator extends Logger {
67
72
  HashCommitmentGenerator.WITNESS_FIXED_OVERHEAD) /
68
73
  HashCommitmentGenerator.WITNESS_PER_CHUNK_OVERHEAD,
69
74
  );
75
+
70
76
  /** Base weight per input (non-witness): 41 bytes * 4 = 164 */
71
77
  private static readonly INPUT_BASE_WEIGHT: number = 164;
72
78
 
@@ -82,7 +88,9 @@ export class HashCommitmentGenerator extends Logger {
82
88
  public static readonly WEIGHT_PER_INPUT: number =
83
89
  HashCommitmentGenerator.INPUT_BASE_WEIGHT +
84
90
  HashCommitmentGenerator.INPUT_WITNESS_WEIGHT_MAX;
91
+
85
92
  public override readonly logColor: string = '#4a90d9';
93
+
86
94
  private readonly publicKey: Uint8Array;
87
95
  private readonly network: Network;
88
96
 
@@ -345,7 +345,7 @@ export class TransactionFactory {
345
345
  1,
346
346
  ),
347
347
  challenge: challenge.toRaw(),
348
- fundingUTXOs: fundingUTXO,
348
+ fundingUTXOs: [...fundingUTXO, ...inputs],
349
349
  fundingInputUtxos: interactionParameters.utxos,
350
350
  compiledTargetScript: toHex(interactionTx.exportCompiledTargetScript()),
351
351
  };
@@ -38,7 +38,7 @@ import { type Feature, FeaturePriority, Features } from '../../generators/Featur
38
38
  import type { IP2WSHAddress } from '../mineable/IP2WSHAddress.js';
39
39
 
40
40
  export class DeploymentTransaction extends TransactionBuilder<TransactionType.DEPLOYMENT> {
41
- public static readonly MAXIMUM_CONTRACT_SIZE = 128 * 1024;
41
+ public static readonly MAXIMUM_CONTRACT_SIZE = 1536 * 1024;
42
42
 
43
43
  public type: TransactionType.DEPLOYMENT = TransactionType.DEPLOYMENT;
44
44
 
@@ -34,29 +34,43 @@ export class FundingTransaction extends TransactionBuilder<TransactionType.FUNDI
34
34
  // When autoAdjustAmount is enabled and the amount would leave no room for fees,
35
35
  // estimate the fee first and reduce the output amount accordingly.
36
36
  if (this.autoAdjustAmount && this.amount >= this.totalInputAmount) {
37
- // Add a temporary output at full amount to get an accurate fee estimate
38
- if (this.isPubKeyDestination) {
39
- const toHexClean = this.to.startsWith('0x') ? this.to.slice(2) : this.to;
40
- const pubKeyScript: Script = script.compile([
41
- fromHex(toHexClean),
42
- opcodes.OP_CHECKSIG,
43
- ]);
37
+ // Add temporary outputs matching the ACTUAL final transaction shape
38
+ // so the fee estimate accounts for the real vsize.
39
+ const numOutputs = this.splitInputsInto > 1 ? this.splitInputsInto : 1;
40
+ const perOutputAmount = this.amount / BigInt(numOutputs);
41
+
42
+ for (let i = 0; i < numOutputs; i++) {
43
+ if (this.isPubKeyDestination) {
44
+ const toHexClean = this.to.startsWith('0x') ? this.to.slice(2) : this.to;
45
+ const pubKeyScript: Script = script.compile([
46
+ fromHex(toHexClean),
47
+ opcodes.OP_CHECKSIG,
48
+ ]);
49
+
50
+ this.addOutput({
51
+ value: toSatoshi(perOutputAmount),
52
+ script: pubKeyScript,
53
+ });
54
+ } else {
55
+ this.addOutput({
56
+ value: toSatoshi(perOutputAmount),
57
+ address: this.to,
58
+ });
59
+ }
60
+ }
44
61
 
45
- this.addOutput({
46
- value: toSatoshi(this.amount),
47
- script: pubKeyScript,
48
- });
49
- } else {
50
- this.addOutput({
51
- value: toSatoshi(this.amount),
52
- address: this.to,
53
- });
62
+ // If a note is present, add a temporary OP_RETURN since it affects vsize.
63
+ if (this.note) {
64
+ this.addOPReturn(this.note);
54
65
  }
55
66
 
56
67
  const estimatedFee = await this.estimateTransactionFees();
57
68
 
58
- // Remove the temporary output
59
- this.outputs.pop();
69
+ // Remove all temporary outputs.
70
+ const tempCount = numOutputs + (this.note ? 1 : 0);
71
+ for (let i = 0; i < tempCount; i++) {
72
+ this.outputs.pop();
73
+ }
60
74
 
61
75
  const adjustedAmount = this.totalInputAmount - estimatedFee;
62
76
  if (adjustedAmount < TransactionBuilder.MINIMUM_DUST) {
@@ -33,7 +33,7 @@ import type { IP2WSHAddress } from '../mineable/IP2WSHAddress.js';
33
33
  export abstract class SharedInteractionTransaction<
34
34
  T extends TransactionType,
35
35
  > extends TransactionBuilder<T> {
36
- public static readonly MAXIMUM_CALLDATA_SIZE = 1024 * 1024; // 1MB
36
+ public static readonly MAXIMUM_CALLDATA_SIZE = 380 * 1024; // 1MB
37
37
 
38
38
  /**
39
39
  * Random salt for the interaction