@meshsdk/transaction 1.7.13 → 1.7.15

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.cjs CHANGED
@@ -71,9 +71,10 @@ var MeshTxBuilderCore = class {
71
71
  * @param txIndex The transaction index of the input UTxO
72
72
  * @param amount The asset amount of index of the input UTxO
73
73
  * @param address The address of the input UTxO
74
+ * @param scriptSize The size of the ref script at this input (if there isn't one, explicitly put 0 as scriptSize for offline tx building)
74
75
  * @returns The MeshTxBuilder instance
75
76
  */
76
- txIn = (txHash, txIndex, amount, address) => {
77
+ txIn = (txHash, txIndex, amount, address, scriptSize) => {
77
78
  if (this.txInQueueItem) {
78
79
  this.queueInput();
79
80
  }
@@ -84,7 +85,8 @@ var MeshTxBuilderCore = class {
84
85
  txHash,
85
86
  txIndex,
86
87
  amount,
87
- address
88
+ address,
89
+ scriptSize
88
90
  }
89
91
  };
90
92
  } else {
@@ -94,7 +96,8 @@ var MeshTxBuilderCore = class {
94
96
  txHash,
95
97
  txIndex,
96
98
  amount,
97
- address
99
+ address,
100
+ scriptSize
98
101
  },
99
102
  scriptTxIn: {}
100
103
  };
@@ -1651,32 +1654,15 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1651
1654
  this.queueAllLastItem();
1652
1655
  }
1653
1656
  this.removeDuplicateInputs();
1657
+ for (let collateral of this.meshTxBuilderBody.collaterals) {
1658
+ collateral.txIn.scriptSize = 0;
1659
+ }
1654
1660
  const { inputs, collaterals, mints } = this.meshTxBuilderBody;
1655
- const incompleteTxIns = [...inputs, ...collaterals];
1661
+ const incompleteTxIns = [...inputs, ...collaterals].filter(
1662
+ (txIn) => !this.isInputComplete(txIn)
1663
+ );
1656
1664
  const incompleteMints = mints.filter((mint) => !this.isMintComplete(mint));
1657
1665
  await this.queryAllTxInfo(incompleteTxIns, incompleteMints);
1658
- Object.values(this.queriedUTxOs).forEach((utxos) => {
1659
- for (let utxo of utxos) {
1660
- if (utxo.output.scriptRef !== void 0) {
1661
- this.utxosWithRefScripts.push(utxo);
1662
- }
1663
- }
1664
- });
1665
- const missingRefInput = this.utxosWithRefScripts.filter((utxo) => {
1666
- this.meshTxBuilderBody.referenceInputs.forEach((refInput) => {
1667
- if (refInput.txHash === utxo.input.txHash && refInput.txIndex === utxo.input.outputIndex) {
1668
- return false;
1669
- }
1670
- });
1671
- return true;
1672
- });
1673
- missingRefInput.forEach((utxo) => {
1674
- this.meshTxBuilderBody.referenceInputs.push({
1675
- txHash: utxo.input.txHash,
1676
- txIndex: utxo.input.outputIndex,
1677
- scriptSize: utxo.output.scriptRef.length / 2
1678
- });
1679
- });
1680
1666
  incompleteTxIns.forEach((txIn) => {
1681
1667
  this.completeTxInformation(txIn);
1682
1668
  });
@@ -1690,6 +1676,19 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1690
1676
  this.completeSimpleScriptInfo(scriptSource);
1691
1677
  }
1692
1678
  });
1679
+ this.meshTxBuilderBody.inputs.forEach((input) => {
1680
+ if (input.txIn.scriptSize && input.txIn.scriptSize > 0) {
1681
+ if (this.meshTxBuilderBody.referenceInputs.find((refTxIn) => {
1682
+ refTxIn.txHash === input.txIn.txHash && refTxIn.txIndex === input.txIn.txIndex;
1683
+ }) === void 0) {
1684
+ this.meshTxBuilderBody.referenceInputs.push({
1685
+ txHash: input.txIn.txHash,
1686
+ txIndex: input.txIn.txIndex,
1687
+ scriptSize: input.txIn.scriptSize
1688
+ });
1689
+ }
1690
+ }
1691
+ });
1693
1692
  this.addUtxosFromSelection();
1694
1693
  let txHex = this.serializer.serializeTxBody(
1695
1694
  this.meshTxBuilderBody,
@@ -1817,6 +1816,11 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1817
1816
  );
1818
1817
  input.txIn.address = address;
1819
1818
  }
1819
+ if (utxo?.output.scriptRef) {
1820
+ input.txIn.scriptSize = utxo.output.scriptRef.length / 2;
1821
+ } else {
1822
+ input.txIn.scriptSize = 0;
1823
+ }
1820
1824
  };
1821
1825
  completeScriptInfo = (scriptSource) => {
1822
1826
  if (scriptSource?.type != "Inline") return;
@@ -1852,8 +1856,8 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1852
1856
  return true;
1853
1857
  };
1854
1858
  isInputInfoComplete = (txIn) => {
1855
- const { amount, address } = txIn.txIn;
1856
- if (!amount || !address) return false;
1859
+ const { amount, address, scriptSize } = txIn.txIn;
1860
+ if (!amount || !address || scriptSize === void 0) return false;
1857
1861
  return true;
1858
1862
  };
1859
1863
  isMintComplete = (mint) => {
@@ -1939,7 +1943,9 @@ var Transaction = class {
1939
1943
  const tx = (0, import_core_cst2.deserializeTx)(cborTx);
1940
1944
  const txAuxData = tx.auxiliaryData() ?? new import_core_cst2.Serialization.AuxiliaryData();
1941
1945
  txAuxData.setMetadata(
1942
- import_core_cst2.Serialization.GeneralTransactionMetadata.fromCbor(import_core_cst2.CardanoSDKUtil.HexBlob(cborTxMetadata))
1946
+ import_core_cst2.Serialization.GeneralTransactionMetadata.fromCbor(
1947
+ import_core_cst2.CardanoSDKUtil.HexBlob(cborTxMetadata)
1948
+ )
1943
1949
  );
1944
1950
  if (import_core_cst2.Cardano.computeAuxiliaryDataHash(txAuxData.toCore())?.toString() !== tx.body().auxiliaryDataHash()?.toString()) {
1945
1951
  throw new Error(
@@ -1957,7 +1963,9 @@ var Transaction = class {
1957
1963
  const txMetadata = tx.auxiliaryData()?.metadata();
1958
1964
  if (txMetadata !== void 0) {
1959
1965
  const mockMetadata = /* @__PURE__ */ new Map();
1960
- txMetadata.metadata()?.forEach((metadatum, label) => mockMetadata.set(label, mask(metadatum)));
1966
+ txMetadata.metadata()?.forEach(
1967
+ (metadatum, label) => mockMetadata.set(label, mask(metadatum))
1968
+ );
1961
1969
  const txAuxData = tx.auxiliaryData();
1962
1970
  txMetadata.setMetadata(mockMetadata);
1963
1971
  txAuxData?.setMetadata(txMetadata);
@@ -1973,7 +1981,9 @@ var Transaction = class {
1973
1981
  const tx = (0, import_core_cst2.deserializeTx)(cborTx);
1974
1982
  const txAuxData = tx.auxiliaryData() ?? new import_core_cst2.Serialization.AuxiliaryData();
1975
1983
  txAuxData.setMetadata(
1976
- import_core_cst2.Serialization.GeneralTransactionMetadata.fromCbor(import_core_cst2.CardanoSDKUtil.HexBlob(cborTxMetadata))
1984
+ import_core_cst2.Serialization.GeneralTransactionMetadata.fromCbor(
1985
+ import_core_cst2.CardanoSDKUtil.HexBlob(cborTxMetadata)
1986
+ )
1977
1987
  );
1978
1988
  return new import_core_cst2.Transaction(tx.body(), tx.witnessSet(), txAuxData).toCbor().toString();
1979
1989
  }
@@ -2076,7 +2086,8 @@ var Transaction = class {
2076
2086
  input.input.txHash,
2077
2087
  input.input.outputIndex,
2078
2088
  input.output.amount,
2079
- input.output.address
2089
+ input.output.address,
2090
+ input.output.scriptRef ? input.output.scriptRef.length / 2 : 0
2080
2091
  );
2081
2092
  });
2082
2093
  return this;
@@ -2465,7 +2476,9 @@ var Transaction = class {
2465
2476
  function mask(metadatum) {
2466
2477
  switch (metadatum.getKind()) {
2467
2478
  case import_core_cst2.Serialization.TransactionMetadatumKind.Text:
2468
- return import_core_cst2.Serialization.TransactionMetadatum.newText("0".repeat(metadatum.asText()?.length ?? 0));
2479
+ return import_core_cst2.Serialization.TransactionMetadatum.newText(
2480
+ "0".repeat(metadatum.asText()?.length ?? 0)
2481
+ );
2469
2482
  case import_core_cst2.Serialization.TransactionMetadatumKind.Bytes:
2470
2483
  case import_core_cst2.Serialization.TransactionMetadatumKind.Integer:
2471
2484
  return metadatum;
package/dist/index.d.cts CHANGED
@@ -26,9 +26,10 @@ declare class MeshTxBuilderCore {
26
26
  * @param txIndex The transaction index of the input UTxO
27
27
  * @param amount The asset amount of index of the input UTxO
28
28
  * @param address The address of the input UTxO
29
+ * @param scriptSize The size of the ref script at this input (if there isn't one, explicitly put 0 as scriptSize for offline tx building)
29
30
  * @returns The MeshTxBuilder instance
30
31
  */
31
- txIn: (txHash: string, txIndex: number, amount?: Asset[], address?: string) => this;
32
+ txIn: (txHash: string, txIndex: number, amount?: Asset[], address?: string, scriptSize?: number) => this;
32
33
  /**
33
34
  * Set the script for transaction input
34
35
  * @param {string} scriptCbor The CborHex of the script
package/dist/index.d.ts CHANGED
@@ -26,9 +26,10 @@ declare class MeshTxBuilderCore {
26
26
  * @param txIndex The transaction index of the input UTxO
27
27
  * @param amount The asset amount of index of the input UTxO
28
28
  * @param address The address of the input UTxO
29
+ * @param scriptSize The size of the ref script at this input (if there isn't one, explicitly put 0 as scriptSize for offline tx building)
29
30
  * @returns The MeshTxBuilder instance
30
31
  */
31
- txIn: (txHash: string, txIndex: number, amount?: Asset[], address?: string) => this;
32
+ txIn: (txHash: string, txIndex: number, amount?: Asset[], address?: string, scriptSize?: number) => this;
32
33
  /**
33
34
  * Set the script for transaction input
34
35
  * @param {string} scriptCbor The CborHex of the script
package/dist/index.js CHANGED
@@ -38,9 +38,10 @@ var MeshTxBuilderCore = class {
38
38
  * @param txIndex The transaction index of the input UTxO
39
39
  * @param amount The asset amount of index of the input UTxO
40
40
  * @param address The address of the input UTxO
41
+ * @param scriptSize The size of the ref script at this input (if there isn't one, explicitly put 0 as scriptSize for offline tx building)
41
42
  * @returns The MeshTxBuilder instance
42
43
  */
43
- txIn = (txHash, txIndex, amount, address) => {
44
+ txIn = (txHash, txIndex, amount, address, scriptSize) => {
44
45
  if (this.txInQueueItem) {
45
46
  this.queueInput();
46
47
  }
@@ -51,7 +52,8 @@ var MeshTxBuilderCore = class {
51
52
  txHash,
52
53
  txIndex,
53
54
  amount,
54
- address
55
+ address,
56
+ scriptSize
55
57
  }
56
58
  };
57
59
  } else {
@@ -61,7 +63,8 @@ var MeshTxBuilderCore = class {
61
63
  txHash,
62
64
  txIndex,
63
65
  amount,
64
- address
66
+ address,
67
+ scriptSize
65
68
  },
66
69
  scriptTxIn: {}
67
70
  };
@@ -1618,32 +1621,15 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1618
1621
  this.queueAllLastItem();
1619
1622
  }
1620
1623
  this.removeDuplicateInputs();
1624
+ for (let collateral of this.meshTxBuilderBody.collaterals) {
1625
+ collateral.txIn.scriptSize = 0;
1626
+ }
1621
1627
  const { inputs, collaterals, mints } = this.meshTxBuilderBody;
1622
- const incompleteTxIns = [...inputs, ...collaterals];
1628
+ const incompleteTxIns = [...inputs, ...collaterals].filter(
1629
+ (txIn) => !this.isInputComplete(txIn)
1630
+ );
1623
1631
  const incompleteMints = mints.filter((mint) => !this.isMintComplete(mint));
1624
1632
  await this.queryAllTxInfo(incompleteTxIns, incompleteMints);
1625
- Object.values(this.queriedUTxOs).forEach((utxos) => {
1626
- for (let utxo of utxos) {
1627
- if (utxo.output.scriptRef !== void 0) {
1628
- this.utxosWithRefScripts.push(utxo);
1629
- }
1630
- }
1631
- });
1632
- const missingRefInput = this.utxosWithRefScripts.filter((utxo) => {
1633
- this.meshTxBuilderBody.referenceInputs.forEach((refInput) => {
1634
- if (refInput.txHash === utxo.input.txHash && refInput.txIndex === utxo.input.outputIndex) {
1635
- return false;
1636
- }
1637
- });
1638
- return true;
1639
- });
1640
- missingRefInput.forEach((utxo) => {
1641
- this.meshTxBuilderBody.referenceInputs.push({
1642
- txHash: utxo.input.txHash,
1643
- txIndex: utxo.input.outputIndex,
1644
- scriptSize: utxo.output.scriptRef.length / 2
1645
- });
1646
- });
1647
1633
  incompleteTxIns.forEach((txIn) => {
1648
1634
  this.completeTxInformation(txIn);
1649
1635
  });
@@ -1657,6 +1643,19 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1657
1643
  this.completeSimpleScriptInfo(scriptSource);
1658
1644
  }
1659
1645
  });
1646
+ this.meshTxBuilderBody.inputs.forEach((input) => {
1647
+ if (input.txIn.scriptSize && input.txIn.scriptSize > 0) {
1648
+ if (this.meshTxBuilderBody.referenceInputs.find((refTxIn) => {
1649
+ refTxIn.txHash === input.txIn.txHash && refTxIn.txIndex === input.txIn.txIndex;
1650
+ }) === void 0) {
1651
+ this.meshTxBuilderBody.referenceInputs.push({
1652
+ txHash: input.txIn.txHash,
1653
+ txIndex: input.txIn.txIndex,
1654
+ scriptSize: input.txIn.scriptSize
1655
+ });
1656
+ }
1657
+ }
1658
+ });
1660
1659
  this.addUtxosFromSelection();
1661
1660
  let txHex = this.serializer.serializeTxBody(
1662
1661
  this.meshTxBuilderBody,
@@ -1784,6 +1783,11 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1784
1783
  );
1785
1784
  input.txIn.address = address;
1786
1785
  }
1786
+ if (utxo?.output.scriptRef) {
1787
+ input.txIn.scriptSize = utxo.output.scriptRef.length / 2;
1788
+ } else {
1789
+ input.txIn.scriptSize = 0;
1790
+ }
1787
1791
  };
1788
1792
  completeScriptInfo = (scriptSource) => {
1789
1793
  if (scriptSource?.type != "Inline") return;
@@ -1819,8 +1823,8 @@ var MeshTxBuilder = class extends MeshTxBuilderCore {
1819
1823
  return true;
1820
1824
  };
1821
1825
  isInputInfoComplete = (txIn) => {
1822
- const { amount, address } = txIn.txIn;
1823
- if (!amount || !address) return false;
1826
+ const { amount, address, scriptSize } = txIn.txIn;
1827
+ if (!amount || !address || scriptSize === void 0) return false;
1824
1828
  return true;
1825
1829
  };
1826
1830
  isMintComplete = (mint) => {
@@ -1910,9 +1914,9 @@ import {
1910
1914
  import {
1911
1915
  Cardano,
1912
1916
  CardanoSDKUtil,
1913
- deserializeTx,
1914
1917
  deserializeNativeScript,
1915
1918
  deserializePlutusScript,
1919
+ deserializeTx,
1916
1920
  fromScriptRef,
1917
1921
  Serialization,
1918
1922
  Transaction as Tx
@@ -1929,7 +1933,9 @@ var Transaction = class {
1929
1933
  const tx = deserializeTx(cborTx);
1930
1934
  const txAuxData = tx.auxiliaryData() ?? new Serialization.AuxiliaryData();
1931
1935
  txAuxData.setMetadata(
1932
- Serialization.GeneralTransactionMetadata.fromCbor(CardanoSDKUtil.HexBlob(cborTxMetadata))
1936
+ Serialization.GeneralTransactionMetadata.fromCbor(
1937
+ CardanoSDKUtil.HexBlob(cborTxMetadata)
1938
+ )
1933
1939
  );
1934
1940
  if (Cardano.computeAuxiliaryDataHash(txAuxData.toCore())?.toString() !== tx.body().auxiliaryDataHash()?.toString()) {
1935
1941
  throw new Error(
@@ -1947,7 +1953,9 @@ var Transaction = class {
1947
1953
  const txMetadata = tx.auxiliaryData()?.metadata();
1948
1954
  if (txMetadata !== void 0) {
1949
1955
  const mockMetadata = /* @__PURE__ */ new Map();
1950
- txMetadata.metadata()?.forEach((metadatum, label) => mockMetadata.set(label, mask(metadatum)));
1956
+ txMetadata.metadata()?.forEach(
1957
+ (metadatum, label) => mockMetadata.set(label, mask(metadatum))
1958
+ );
1951
1959
  const txAuxData = tx.auxiliaryData();
1952
1960
  txMetadata.setMetadata(mockMetadata);
1953
1961
  txAuxData?.setMetadata(txMetadata);
@@ -1963,7 +1971,9 @@ var Transaction = class {
1963
1971
  const tx = deserializeTx(cborTx);
1964
1972
  const txAuxData = tx.auxiliaryData() ?? new Serialization.AuxiliaryData();
1965
1973
  txAuxData.setMetadata(
1966
- Serialization.GeneralTransactionMetadata.fromCbor(CardanoSDKUtil.HexBlob(cborTxMetadata))
1974
+ Serialization.GeneralTransactionMetadata.fromCbor(
1975
+ CardanoSDKUtil.HexBlob(cborTxMetadata)
1976
+ )
1967
1977
  );
1968
1978
  return new Tx(tx.body(), tx.witnessSet(), txAuxData).toCbor().toString();
1969
1979
  }
@@ -2066,7 +2076,8 @@ var Transaction = class {
2066
2076
  input.input.txHash,
2067
2077
  input.input.outputIndex,
2068
2078
  input.output.amount,
2069
- input.output.address
2079
+ input.output.address,
2080
+ input.output.scriptRef ? input.output.scriptRef.length / 2 : 0
2070
2081
  );
2071
2082
  });
2072
2083
  return this;
@@ -2455,7 +2466,9 @@ var Transaction = class {
2455
2466
  function mask(metadatum) {
2456
2467
  switch (metadatum.getKind()) {
2457
2468
  case Serialization.TransactionMetadatumKind.Text:
2458
- return Serialization.TransactionMetadatum.newText("0".repeat(metadatum.asText()?.length ?? 0));
2469
+ return Serialization.TransactionMetadatum.newText(
2470
+ "0".repeat(metadatum.asText()?.length ?? 0)
2471
+ );
2459
2472
  case Serialization.TransactionMetadatumKind.Bytes:
2460
2473
  case Serialization.TransactionMetadatumKind.Integer:
2461
2474
  return metadatum;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meshsdk/transaction",
3
- "version": "1.7.13",
3
+ "version": "1.7.15",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "browser": "./dist/index.js",
@@ -35,9 +35,9 @@
35
35
  "typescript": "^5.3.3"
36
36
  },
37
37
  "dependencies": {
38
- "@meshsdk/common": "1.7.13",
39
- "@meshsdk/core-csl": "1.7.13",
40
- "@meshsdk/core-cst": "1.7.13",
38
+ "@meshsdk/common": "1.7.15",
39
+ "@meshsdk/core-csl": "1.7.15",
40
+ "@meshsdk/core-cst": "1.7.15",
41
41
  "json-bigint": "^1.0.0"
42
42
  },
43
43
  "prettier": "@meshsdk/configs/prettier",