@meshsdk/common 1.9.0-beta.7 → 1.9.0-beta.71

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.js CHANGED
@@ -767,6 +767,12 @@ var CIP68_222 = (tokenNameHex) => {
767
767
  return `000de140${tokenNameHex}`;
768
768
  };
769
769
 
770
+ // src/interfaces/fetcher.ts
771
+ var DEFAULT_FETCHER_OPTIONS = {
772
+ maxPage: 20,
773
+ order: "desc"
774
+ };
775
+
770
776
  // src/types/asset.ts
771
777
  var mergeAssets = (assets) => {
772
778
  const merged = [];
@@ -854,6 +860,7 @@ var txInToUtxo = (txIn) => {
854
860
  var emptyTxBuilderBody = () => ({
855
861
  inputs: [],
856
862
  outputs: [],
863
+ fee: "0",
857
864
  extraInputs: [],
858
865
  collaterals: [],
859
866
  requiredSignatures: [],
@@ -873,14 +880,32 @@ var emptyTxBuilderBody = () => ({
873
880
  },
874
881
  chainedTxs: [],
875
882
  inputsForEvaluation: {},
876
- network: "mainnet"
883
+ network: "mainnet",
884
+ expectedNumberKeyWitnesses: 0,
885
+ expectedByronAddressWitnesses: []
877
886
  });
887
+ function cloneTxBuilderBody(body) {
888
+ const { extraInputs, ...otherProps } = body;
889
+ const cloned = structuredClone(otherProps);
890
+ cloned.extraInputs = extraInputs;
891
+ return cloned;
892
+ }
878
893
  var validityRangeToObj = (validityRange) => {
879
894
  return {
880
895
  invalidBefore: validityRange.invalidBefore ?? null,
881
896
  invalidHereafter: validityRange.invalidHereafter ?? null
882
897
  };
883
898
  };
899
+ var validityRangeFromObj = (obj) => {
900
+ const validityRange = {};
901
+ if (obj.invalidBefore !== null && obj.invalidBefore !== void 0) {
902
+ validityRange.invalidBefore = Number(obj.invalidBefore);
903
+ }
904
+ if (obj.invalidHereafter !== null && obj.invalidHereafter !== void 0) {
905
+ validityRange.invalidHereafter = Number(obj.invalidHereafter);
906
+ }
907
+ return validityRange;
908
+ };
884
909
 
885
910
  // src/data/mesh/constructors.ts
886
911
  var mConStr = (alternative, fields) => ({
@@ -930,7 +955,7 @@ var mTxOutRef = (txHash, index) => {
930
955
  }
931
956
  return mConStr0([mConStr0([txHash]), index]);
932
957
  };
933
- var mTuple = (key, value2) => [key, value2];
958
+ var mTuple = (...args) => args;
934
959
  var mOption = (value2) => {
935
960
  if (value2) {
936
961
  return mSome(value2);
@@ -941,14 +966,16 @@ var mSome = (value2) => mConStr0([value2]);
941
966
  var mNone = () => mConStr1([]);
942
967
 
943
968
  // src/data/mesh/credentials.ts
969
+ var mVerificationKey = (bytes) => mConStr0([bytes]);
970
+ var mScript = (bytes) => mConStr1([bytes]);
944
971
  var mMaybeStakingHash = (stakeCredential, isStakeScriptCredential = false) => {
945
972
  if (stakeCredential === "") {
946
973
  return mConStr1([]);
947
974
  }
948
975
  if (isStakeScriptCredential) {
949
- return mConStr0([mConStr0([mConStr1([stakeCredential])])]);
976
+ return mConStr0([mConStr0([mScript(stakeCredential)])]);
950
977
  }
951
- return mConStr0([mConStr0([mConStr0([stakeCredential])])]);
978
+ return mConStr0([mConStr0([mVerificationKey(stakeCredential)])]);
952
979
  };
953
980
  var mPubKeyAddress = (bytes, stakeCredential, isStakeScriptCredential = false) => mConStr0([
954
981
  { alternative: 0, fields: [bytes] },
@@ -958,6 +985,7 @@ var mScriptAddress = (bytes, stakeCredential, isStakeScriptCredential = false) =
958
985
  { alternative: 1, fields: [bytes] },
959
986
  mMaybeStakingHash(stakeCredential || "", isStakeScriptCredential)
960
987
  ]);
988
+ var mCredential = (hash, isScriptCredential = false) => isScriptCredential ? mScript(hash) : mVerificationKey(hash);
961
989
 
962
990
  // src/data/mesh/primitives.ts
963
991
  var mBool = (b) => b ? mConStr1([]) : mConStr0([]);
@@ -1045,11 +1073,25 @@ var assocMap = (mapItems, validation = true) => ({
1045
1073
  return { k, v };
1046
1074
  })
1047
1075
  });
1076
+ var pairs = (mapItems, validation = true) => ({
1077
+ map: mapItems.map(([k, v]) => {
1078
+ if (validation) {
1079
+ if (typeof k !== "object" || typeof v !== "object") {
1080
+ throw new Error(
1081
+ `Map item of JSON Cardano data type must be an object - ${k}, ${v}`
1082
+ );
1083
+ }
1084
+ }
1085
+ return { k, v };
1086
+ })
1087
+ });
1048
1088
 
1049
1089
  // src/data/json/aliases.ts
1050
1090
  var hashByteString = (bytes) => {
1051
1091
  if (bytes.length !== 56) {
1052
- throw new Error(`Invalid hash for [${bytes}] - should be 56 bytes long`);
1092
+ throw new Error(
1093
+ `Invalid hash for [${bytes}] - should be 28 bytes (56 hex length) long`
1094
+ );
1053
1095
  }
1054
1096
  return byteString(bytes);
1055
1097
  };
@@ -1058,7 +1100,7 @@ var pubKeyHash = (bytes) => hashByteString(bytes);
1058
1100
  var policyId = (bytes) => {
1059
1101
  if (bytes.length !== POLICY_ID_LENGTH && bytes !== "") {
1060
1102
  throw new Error(
1061
- `Invalid policy id for [${bytes}] - should be ${POLICY_ID_LENGTH} bytes long or empty string for lovelace`
1103
+ `Invalid policy id for [${bytes}] - should be ${POLICY_ID_LENGTH / 2} bytes (${POLICY_ID_LENGTH} hex length) long or empty string for lovelace`
1062
1104
  );
1063
1105
  }
1064
1106
  return byteString(bytes);
@@ -1090,7 +1132,9 @@ var posixTime = (int) => ({ int });
1090
1132
  var dict = (itemsMap) => ({
1091
1133
  map: itemsMap.map(([k, v]) => ({ k, v }))
1092
1134
  });
1093
- var tuple = (key, value2) => ({ list: [key, value2] });
1135
+ var tuple = (...args) => ({
1136
+ list: args
1137
+ });
1094
1138
  var option = (value2) => {
1095
1139
  if (!value2) {
1096
1140
  return none();
@@ -1101,32 +1145,62 @@ var some = (value2) => conStr0([value2]);
1101
1145
  var none = () => conStr1([]);
1102
1146
 
1103
1147
  // src/data/json/credentials.ts
1148
+ var verificationKey = (bytes) => conStr0([pubKeyHash(bytes)]);
1149
+ var script = (bytes) => conStr1([scriptHash(bytes)]);
1104
1150
  var maybeStakingHash = (stakeCredential, isStakeScriptCredential = false) => {
1105
1151
  if (stakeCredential === "") {
1106
1152
  return conStr1([]);
1107
1153
  }
1108
1154
  if (isStakeScriptCredential) {
1109
- return conStr0([
1110
- conStr0([conStr1([scriptHash(stakeCredential)])])
1111
- ]);
1155
+ return conStr0([conStr0([script(stakeCredential)])]);
1112
1156
  }
1113
- return conStr0([
1114
- conStr0([conStr0([pubKeyHash(stakeCredential)])])
1115
- ]);
1157
+ return conStr0([conStr0([verificationKey(stakeCredential)])]);
1116
1158
  };
1117
1159
  var pubKeyAddress = (bytes, stakeCredential, isStakeScriptCredential = false) => conStr0([
1118
1160
  conStr0([pubKeyHash(bytes)]),
1119
1161
  maybeStakingHash(stakeCredential || "", isStakeScriptCredential)
1120
1162
  ]);
1121
1163
  var scriptAddress = (bytes, stakeCredential, isStakeScriptCredential = false) => conStr0([
1122
- conStr1([scriptHash(bytes)]),
1164
+ script(bytes),
1123
1165
  maybeStakingHash(stakeCredential || "", isStakeScriptCredential)
1124
1166
  ]);
1167
+ var credential = (hash, isScriptCredential = false) => isScriptCredential ? script(hash) : verificationKey(hash);
1168
+
1169
+ // src/data/json/mpf.ts
1170
+ var jsonProofToPlutusData = (proof) => {
1171
+ const proofSteps = [];
1172
+ const proofJson = proof;
1173
+ proofJson.forEach((proof2) => {
1174
+ const skip = integer(proof2.skip);
1175
+ switch (proof2.type) {
1176
+ case "branch":
1177
+ proofSteps.push(
1178
+ conStr0([skip, byteString(proof2.neighbors.toString("hex"))])
1179
+ );
1180
+ break;
1181
+ case "fork":
1182
+ const { prefix, nibble, root } = proof2.neighbor;
1183
+ const neighbor = conStr0([
1184
+ integer(nibble),
1185
+ byteString(prefix.toString("hex")),
1186
+ byteString(root.toString("hex"))
1187
+ ]);
1188
+ proofSteps.push(conStr1([skip, neighbor]));
1189
+ break;
1190
+ case "leaf":
1191
+ const { key, value: value2 } = proof2.neighbor;
1192
+ proofSteps.push(conStr2([skip, byteString(key), byteString(value2)]));
1193
+ break;
1194
+ }
1195
+ });
1196
+ return proofSteps;
1197
+ };
1125
1198
 
1126
1199
  // src/data/parser.ts
1127
1200
  var bytesToHex = (bytes) => Buffer.from(bytes).toString("hex");
1128
1201
  var hexToBytes = (hex) => Buffer.from(hex, "hex");
1129
1202
  var stringToHex = (str) => Buffer.from(str, "utf8").toString("hex");
1203
+ var isHexString = (hex) => /^[0-9A-F]*$/i.test(hex);
1130
1204
  var hexToString = (hex) => Buffer.from(hex, "hex").toString("utf8");
1131
1205
  var toBytes = (hex) => {
1132
1206
  if (hex.length % 2 === 0 && /^[0-9A-F]*$/i.test(hex))
@@ -1305,10 +1379,10 @@ var BigNum = class _BigNum {
1305
1379
  };
1306
1380
 
1307
1381
  // src/utils/data-hash.ts
1308
- import { blake2bHex } from "blakejs";
1382
+ import { blake2b as blake2b2 } from "blakejs";
1309
1383
  var hashDrepAnchor = (jsonLD) => {
1310
- const jsonHash = blake2bHex(JSON.stringify(jsonLD, null, 2), void 0, 32);
1311
- return jsonHash;
1384
+ const jsonHash = blake2b2(JSON.stringify(jsonLD, null, 2), void 0, 32);
1385
+ return Buffer.from(jsonHash).toString("hex");
1312
1386
  };
1313
1387
 
1314
1388
  // src/utils/file.ts
@@ -1421,6 +1495,23 @@ var MeshValue = class _MeshValue {
1421
1495
  get = (unit) => {
1422
1496
  return this.value[unit] ? BigInt(this.value[unit]) : BigInt(0);
1423
1497
  };
1498
+ /**
1499
+ * Get all assets that belong to a specific policy ID
1500
+ * @param policyId The policy ID to filter by
1501
+ * @returns Array of assets that match the policy ID
1502
+ */
1503
+ getPolicyAssets = (policyId2) => {
1504
+ const assets = [];
1505
+ Object.entries(this.value).forEach(([unit, quantity]) => {
1506
+ if (unit.startsWith(policyId2)) {
1507
+ assets.push({
1508
+ unit,
1509
+ quantity: quantity.toString()
1510
+ });
1511
+ }
1512
+ });
1513
+ return assets;
1514
+ };
1424
1515
  /**
1425
1516
  * Get all asset units
1426
1517
  * @returns The asset units
@@ -1468,6 +1559,26 @@ var MeshValue = class _MeshValue {
1468
1559
  }
1469
1560
  return BigInt(this.value[unit]) <= BigInt(other.value[unit]);
1470
1561
  };
1562
+ /**
1563
+ * Check if the value is equal to another value
1564
+ * @param other - The value to compare against
1565
+ * @returns boolean
1566
+ */
1567
+ eq = (other) => {
1568
+ return Object.keys(this.value).every((key) => this.eqUnit(key, other));
1569
+ };
1570
+ /**
1571
+ * Check if the specific unit of value is equal to that unit of another value
1572
+ * @param unit - The unit to compare
1573
+ * @param other - The value to compare against
1574
+ * @returns boolean
1575
+ */
1576
+ eqUnit = (unit, other) => {
1577
+ if (this.value[unit] === void 0 || other.value[unit] === void 0) {
1578
+ return false;
1579
+ }
1580
+ return BigInt(this.value[unit]) === BigInt(other.value[unit]);
1581
+ };
1471
1582
  /**
1472
1583
  * Check if the value is empty
1473
1584
  * @returns boolean
@@ -1570,7 +1681,7 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
1570
1681
  const selectedInputs = /* @__PURE__ */ new Set();
1571
1682
  const onlyLovelace = /* @__PURE__ */ new Set();
1572
1683
  const singletons = /* @__PURE__ */ new Set();
1573
- const pairs = /* @__PURE__ */ new Set();
1684
+ const pairs2 = /* @__PURE__ */ new Set();
1574
1685
  const rest = /* @__PURE__ */ new Set();
1575
1686
  const collaterals = /* @__PURE__ */ new Set();
1576
1687
  for (let i = 0; i < inputs.length; i++) {
@@ -1589,7 +1700,7 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
1589
1700
  break;
1590
1701
  }
1591
1702
  case 3: {
1592
- pairs.add(i);
1703
+ pairs2.add(i);
1593
1704
  break;
1594
1705
  }
1595
1706
  default: {
@@ -1622,10 +1733,10 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
1622
1733
  if (!assetRequired || Number(assetRequired) <= 0) break;
1623
1734
  addUtxoWithAssetAmount(inputIndex, assetUnit, singletons);
1624
1735
  }
1625
- for (const inputIndex of pairs) {
1736
+ for (const inputIndex of pairs2) {
1626
1737
  const assetRequired = totalRequiredAssets.get(assetUnit);
1627
1738
  if (!assetRequired || Number(assetRequired) <= 0) break;
1628
- addUtxoWithAssetAmount(inputIndex, assetUnit, pairs);
1739
+ addUtxoWithAssetAmount(inputIndex, assetUnit, pairs2);
1629
1740
  }
1630
1741
  for (const inputIndex of rest) {
1631
1742
  const assetRequired = totalRequiredAssets.get(assetUnit);
@@ -1643,10 +1754,10 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
1643
1754
  if (!assetRequired || Number(assetRequired) <= 0) break;
1644
1755
  addUtxoWithAssetAmount(inputIndex, "lovelace", singletons);
1645
1756
  }
1646
- for (const inputIndex of pairs) {
1757
+ for (const inputIndex of pairs2) {
1647
1758
  const assetRequired = totalRequiredAssets.get("lovelace");
1648
1759
  if (!assetRequired || Number(assetRequired) <= 0) break;
1649
- addUtxoWithAssetAmount(inputIndex, "lovelace", pairs);
1760
+ addUtxoWithAssetAmount(inputIndex, "lovelace", pairs2);
1650
1761
  }
1651
1762
  for (const inputIndex of rest) {
1652
1763
  const assetRequired = totalRequiredAssets.get("lovelace");
@@ -1821,6 +1932,473 @@ var UtxoSelection = class {
1821
1932
  }
1822
1933
  };
1823
1934
 
1935
+ // src/tx-tester/index.ts
1936
+ var TxTester = class {
1937
+ txBody;
1938
+ inputsEvaluating;
1939
+ outputsEvaluating;
1940
+ traces;
1941
+ /**
1942
+ * Create a new TxTester instance
1943
+ * @param txBody The transaction builder body
1944
+ */
1945
+ constructor(txBody) {
1946
+ this.txBody = { ...txBody };
1947
+ this.inputsEvaluating = [];
1948
+ this.outputsEvaluating = [];
1949
+ this.traces = [];
1950
+ }
1951
+ /**
1952
+ * Add a trace to the TxTester
1953
+ * @param funcName The function name where the error occurred
1954
+ * @param message The error message
1955
+ */
1956
+ addTrace(funcName, message) {
1957
+ const msg = `[Error - ${funcName}]: ${message}`;
1958
+ this.traces.push(msg);
1959
+ }
1960
+ /**
1961
+ * Check if the transaction evaluation was successful
1962
+ * @returns true if there are no errors, false otherwise
1963
+ */
1964
+ success() {
1965
+ return this.traces.length === 0;
1966
+ }
1967
+ /**
1968
+ * Get the error messages if any
1969
+ * @returns A string representation of the errors or "No errors" if there are none
1970
+ */
1971
+ errors() {
1972
+ if (this.traces.length > 0) {
1973
+ return `${this.traces}`;
1974
+ } else {
1975
+ return "No errors";
1976
+ }
1977
+ }
1978
+ /**
1979
+ * Checks if the transaction is valid after a specified timestamp.
1980
+ * @param requiredTimestamp The timestamp after which the transaction should be valid
1981
+ * @returns The TxTester instance for chaining
1982
+ */
1983
+ validAfter = (requiredTimestamp) => {
1984
+ const invalidBefore = this.txBody.validityRange?.invalidHereafter ? this.txBody.validityRange.invalidHereafter : 9999999999999;
1985
+ const isValidAfter = this.txBody.validityRange?.invalidBefore ? this.txBody.validityRange.invalidBefore < requiredTimestamp : true;
1986
+ if (!isValidAfter) {
1987
+ this.addTrace(
1988
+ "validAfter",
1989
+ `tx invalid before ${invalidBefore}, with requiredTimestamp ${requiredTimestamp}`
1990
+ );
1991
+ }
1992
+ return this;
1993
+ };
1994
+ /**
1995
+ * Checks if the transaction is valid before a specified timestamp.
1996
+ * @param requiredTimestamp The timestamp before which the transaction should be valid
1997
+ * @returns The TxTester instance for chaining
1998
+ */
1999
+ validBefore = (requiredTimestamp) => {
2000
+ const invalidHereafter = this.txBody.validityRange?.invalidBefore ? this.txBody.validityRange.invalidBefore : 0;
2001
+ const isValidBefore = this.txBody.validityRange?.invalidHereafter ? this.txBody.validityRange.invalidHereafter > requiredTimestamp : true;
2002
+ if (!isValidBefore) {
2003
+ this.addTrace(
2004
+ "validBefore",
2005
+ `tx invalid after ${invalidHereafter}, with requiredTimestamp ${requiredTimestamp}`
2006
+ );
2007
+ }
2008
+ return this;
2009
+ };
2010
+ // Extra Signatories Methods
2011
+ /**
2012
+ * Checks if a specific key is signed in the transaction.
2013
+ * @param keyHash The key hash to check
2014
+ * @returns The TxTester instance for chaining
2015
+ */
2016
+ keySigned = (keyHash) => {
2017
+ const isKeySigned = keySignedLogic(this.txBody.requiredSignatures, keyHash);
2018
+ if (!isKeySigned) {
2019
+ this.addTrace("keySigned", `tx does not have key ${keyHash} signed`);
2020
+ }
2021
+ return this;
2022
+ };
2023
+ /**
2024
+ * Checks if any one of the specified keys is signed in the transaction.
2025
+ * @param keyHashes The array of key hashes to check
2026
+ * @returns The TxTester instance for chaining
2027
+ */
2028
+ oneOfKeysSigned = (keyHashes) => {
2029
+ const isOneOfKeysSigned = keyHashes.some(
2030
+ (keyHash) => keySignedLogic(this.txBody.requiredSignatures, keyHash)
2031
+ );
2032
+ if (!isOneOfKeysSigned) {
2033
+ this.addTrace(
2034
+ "oneOfKeysSigned",
2035
+ `tx does not have any of the keys signed: ${keyHashes.join(", ")}`
2036
+ );
2037
+ }
2038
+ return this;
2039
+ };
2040
+ /**
2041
+ * Checks if all specified keys are signed in the transaction.
2042
+ * @param keyHashes The array of key hashes to check
2043
+ * @returns The TxTester instance for chaining
2044
+ */
2045
+ allKeysSigned = (keyHashes) => {
2046
+ const missingKeys = [];
2047
+ const isAllKeysSigned = keyHashes.every((keyHash) => {
2048
+ const isKeySigned = keySignedLogic(
2049
+ this.txBody.requiredSignatures,
2050
+ keyHash
2051
+ );
2052
+ if (!isKeySigned) {
2053
+ missingKeys.push(keyHash);
2054
+ }
2055
+ return isKeySigned;
2056
+ });
2057
+ if (!isAllKeysSigned) {
2058
+ this.addTrace(
2059
+ "allKeysSigned",
2060
+ `tx does not have all keys signed: ${missingKeys.join(", ")}`
2061
+ );
2062
+ }
2063
+ return this;
2064
+ };
2065
+ /**
2066
+ * Checks if a specific token is minted in the transaction.
2067
+ * @param policyId The policy ID of the token
2068
+ * @param assetName The asset name of the token
2069
+ * @param quantity The quantity of the token
2070
+ * @returns The TxTester instance for chaining
2071
+ */
2072
+ tokenMinted = (policyId2, assetName2, quantity) => {
2073
+ const isTokenMinted = tokenMintedLogic(
2074
+ this.txBody.mints,
2075
+ policyId2,
2076
+ assetName2,
2077
+ quantity
2078
+ );
2079
+ if (!isTokenMinted) {
2080
+ this.addTrace(
2081
+ "tokenMinted",
2082
+ `Token with policy_id: ${policyId2}, asset_name: ${assetName2}, quantity: ${quantity} not found in mints.`
2083
+ );
2084
+ }
2085
+ return this;
2086
+ };
2087
+ /**
2088
+ * Checks if a specific token is minted in the transaction and that it is the only mint.
2089
+ * @param policyId The policy ID of the token
2090
+ * @param assetName The asset name of the token
2091
+ * @param quantity The quantity of the token
2092
+ * @returns The TxTester instance for chaining
2093
+ */
2094
+ onlyTokenMinted = (policyId2, assetName2, quantity) => {
2095
+ const isTokenMinted = tokenMintedLogic(
2096
+ this.txBody.mints,
2097
+ policyId2,
2098
+ assetName2,
2099
+ quantity
2100
+ );
2101
+ const isOnlyOneMint = this.txBody.mints?.length === 1;
2102
+ if (!isTokenMinted) {
2103
+ this.addTrace(
2104
+ "onlyTokenMinted",
2105
+ `Token with policy_id: ${policyId2}, asset_name: ${assetName2}, quantity: ${quantity} not found in mints`
2106
+ );
2107
+ }
2108
+ if (!isOnlyOneMint) {
2109
+ this.addTrace(
2110
+ "onlyTokenMinted",
2111
+ `Expected only one mint, but found ${this.txBody.mints?.length || 0} mints.`
2112
+ );
2113
+ }
2114
+ return this;
2115
+ };
2116
+ /**
2117
+ * Checks if a specific token is minted in the transaction, ensuring that it is the only mint for the given policy ID.
2118
+ * @param policyId The policy ID of the token
2119
+ * @param assetName The asset name of the token
2120
+ * @param quantity The quantity of the token
2121
+ * @returns The TxTester instance for chaining
2122
+ */
2123
+ policyOnlyMintedToken = (policyId2, assetName2, quantity) => {
2124
+ const filteredMints = this.txBody.mints?.filter((token) => {
2125
+ return token.policyId === policyId2;
2126
+ }) || [];
2127
+ const isTokenMinted = tokenMintedLogic(
2128
+ this.txBody.mints,
2129
+ policyId2,
2130
+ assetName2,
2131
+ quantity
2132
+ );
2133
+ const isOnlyOneMint = filteredMints.length === 1;
2134
+ if (!isOnlyOneMint) {
2135
+ this.addTrace(
2136
+ "policyOnlyMintedToken",
2137
+ `Expected only one mint for policy_id: ${policyId2}, but found ${filteredMints.length} mints.`
2138
+ );
2139
+ }
2140
+ if (!isTokenMinted) {
2141
+ this.addTrace(
2142
+ "policyOnlyMintedToken",
2143
+ `Token with policy_id: ${policyId2}, asset_name: ${assetName2}, quantity: ${quantity} not found in mints.`
2144
+ );
2145
+ }
2146
+ return this;
2147
+ };
2148
+ /**
2149
+ * Checks if a specific policy ID is burned in the transaction, ensuring that it is the only minting (i.e. burning item).
2150
+ * @param policyId The policy ID to check
2151
+ * @returns true if the policy is the only burn, false otherwise
2152
+ */
2153
+ checkPolicyOnlyBurn = (policyId2) => {
2154
+ const filteredMints = this.txBody.mints?.filter((token) => {
2155
+ return token.policyId === policyId2 && token.mintValue.findIndex((m) => BigInt(m.amount) > 0) >= 0;
2156
+ }) || [];
2157
+ return filteredMints.length === 0;
2158
+ };
2159
+ /**
2160
+ * Not apply filter to inputs
2161
+ * @returns The TxTester instance for chaining
2162
+ */
2163
+ allInputs = () => {
2164
+ this.inputsEvaluating = this.txBody.inputs?.slice() || [];
2165
+ return this;
2166
+ };
2167
+ /**
2168
+ * Filter inputs by address
2169
+ * @param address The address to filter by
2170
+ * @returns The TxTester instance for chaining
2171
+ */
2172
+ inputsAt = (address) => {
2173
+ this.inputsEvaluating = this.txBody.inputs?.filter(
2174
+ (input) => txInToUtxo(input.txIn).output.address === address
2175
+ ) || [];
2176
+ return this;
2177
+ };
2178
+ /**
2179
+ * Filter inputs by unit
2180
+ * @param unit The unit to filter by
2181
+ * @returns The TxTester instance for chaining
2182
+ */
2183
+ inputsWith = (unit) => {
2184
+ this.inputsEvaluating = this.txBody.inputs?.filter((input) => {
2185
+ const inputValue = MeshValue.fromAssets(
2186
+ txInToUtxo(input.txIn).output.amount
2187
+ );
2188
+ const quantity = inputValue.get(unit);
2189
+ return quantity > 0;
2190
+ }) || [];
2191
+ return this;
2192
+ };
2193
+ /**
2194
+ * Filter inputs by policy ID
2195
+ * @param policyId The policy ID to filter by
2196
+ * @returns The TxTester instance for chaining
2197
+ */
2198
+ inputsWithPolicy = (policyId2) => {
2199
+ this.inputsEvaluating = this.txBody.inputs?.filter((input) => {
2200
+ const inputValue = MeshValue.fromAssets(
2201
+ txInToUtxo(input.txIn).output.amount
2202
+ );
2203
+ const assets = inputValue.getPolicyAssets(policyId2);
2204
+ return assets.length > 0;
2205
+ }) || [];
2206
+ return this;
2207
+ };
2208
+ /**
2209
+ * Filter inputs by address and policy ID
2210
+ * @param address The address to filter by
2211
+ * @param policyId The policy ID to filter by
2212
+ * @returns The TxTester instance for chaining
2213
+ */
2214
+ inputsAtWithPolicy = (address, policyId2) => {
2215
+ this.inputsEvaluating = this.txBody.inputs?.filter((input) => {
2216
+ const utxo = txInToUtxo(input.txIn);
2217
+ const inputValue = MeshValue.fromAssets(utxo.output.amount);
2218
+ const assets = inputValue.getPolicyAssets(policyId2);
2219
+ return utxo.output.address === address && assets.length > 0;
2220
+ }) || [];
2221
+ return this;
2222
+ };
2223
+ /**
2224
+ * Filter inputs by address and unit
2225
+ * @param address The address to filter by
2226
+ * @param unit The unit to filter by
2227
+ * @returns The TxTester instance for chaining
2228
+ */
2229
+ inputsAtWith = (address, unit) => {
2230
+ this.inputsEvaluating = this.txBody.inputs?.filter((input) => {
2231
+ const utxo = txInToUtxo(input.txIn);
2232
+ const inputValue = MeshValue.fromAssets(utxo.output.amount);
2233
+ const quantity = inputValue.get(unit);
2234
+ return utxo.output.address === address && quantity > 0;
2235
+ }) || [];
2236
+ return this;
2237
+ };
2238
+ /**
2239
+ * Check if inputs contain the expected value.
2240
+ * *Reminder - It must be called after filtering methods for inputs*
2241
+ * @param expectedValue The expected value
2242
+ * @returns The TxTester instance for chaining
2243
+ */
2244
+ inputsValue = (expectedValue) => {
2245
+ let value2 = new MeshValue();
2246
+ this.inputsEvaluating.forEach((input) => {
2247
+ const utxo = txInToUtxo(input.txIn);
2248
+ value2.addAssets(utxo.output.amount);
2249
+ });
2250
+ const isValueCorrect = value2.eq(expectedValue);
2251
+ if (!isValueCorrect) {
2252
+ this.addTrace(
2253
+ "inputsValue",
2254
+ `inputs ${JSON.stringify(this.inputsEvaluating)} have value ${JSON.stringify(value2)}, expect ${JSON.stringify(expectedValue)}`
2255
+ );
2256
+ }
2257
+ return this;
2258
+ };
2259
+ // /**
2260
+ // * Check if inputs contain a specific inline datum.
2261
+ // * *Reminder - It must be called after filtering methods for inputs*
2262
+ // * @param datumCbor The datum CBOR to check
2263
+ // * @returns The TxTester instance for chaining
2264
+ // */
2265
+ // inputsInlineDatumExist = (datumCbor: string): this => {
2266
+ // const inputsWithInlineDatum = this.inputsEvaluating.filter((input) => {
2267
+ // const utxo = txInToUtxo(input.txIn);
2268
+ // return utxo.output.plutusData === datumCbor;
2269
+ // });
2270
+ // if (inputsWithInlineDatum.length === 0) {
2271
+ // this.addTrace(
2272
+ // "inputsInlineDatumExist",
2273
+ // `No inputs with inline datum matching: ${datumCbor}`,
2274
+ // );
2275
+ // }
2276
+ // return this;
2277
+ // };
2278
+ /**
2279
+ * Not apply filter to outputs
2280
+ * @returns The TxTester instance for chaining
2281
+ */
2282
+ allOutputs = () => {
2283
+ this.outputsEvaluating = this.txBody.outputs?.slice() || [];
2284
+ return this;
2285
+ };
2286
+ /**
2287
+ * Filter outputs by address
2288
+ * @param address The address to filter by
2289
+ * @returns The TxTester instance for chaining
2290
+ */
2291
+ outputsAt = (address) => {
2292
+ this.outputsEvaluating = this.txBody.outputs?.filter((output) => output.address === address) || [];
2293
+ return this;
2294
+ };
2295
+ /**
2296
+ * Filter outputs by unit
2297
+ * @param unit The unit to filter by
2298
+ * @returns The TxTester instance for chaining
2299
+ */
2300
+ outputsWith = (unit) => {
2301
+ this.outputsEvaluating = this.txBody.outputs?.filter((output) => {
2302
+ const outputValue = MeshValue.fromAssets(output.amount);
2303
+ const quantity = outputValue.get(unit);
2304
+ return quantity > 0;
2305
+ }) || [];
2306
+ return this;
2307
+ };
2308
+ /**
2309
+ * Filter outputs by policy ID
2310
+ * @param policyId The policy ID to filter by
2311
+ * @returns The TxTester instance for chaining
2312
+ */
2313
+ outputsWithPolicy = (policyId2) => {
2314
+ this.outputsEvaluating = this.txBody.outputs?.filter((output) => {
2315
+ const outputValue = MeshValue.fromAssets(output.amount);
2316
+ const assets = outputValue.getPolicyAssets(policyId2);
2317
+ return assets.length > 0;
2318
+ }) || [];
2319
+ return this;
2320
+ };
2321
+ /**
2322
+ * Filter outputs by address and policy ID
2323
+ * @param address The address to filter by
2324
+ * @param policyId The policy ID to filter by
2325
+ * @returns The TxTester instance for chaining
2326
+ */
2327
+ outputsAtWithPolicy = (address, policyId2) => {
2328
+ this.outputsEvaluating = this.txBody.outputs?.filter((output) => {
2329
+ const outputValue = MeshValue.fromAssets(output.amount);
2330
+ const assets = outputValue.getPolicyAssets(policyId2);
2331
+ return output.address === address && assets.length > 0;
2332
+ }) || [];
2333
+ return this;
2334
+ };
2335
+ /**
2336
+ * Filter outputs by address and unit
2337
+ * @param address The address to filter by
2338
+ * @param unit The unit to filter by
2339
+ * @returns The TxTester instance for chaining
2340
+ */
2341
+ outputsAtWith = (address, unit) => {
2342
+ this.outputsEvaluating = this.txBody.outputs?.filter((output) => {
2343
+ const outputValue = MeshValue.fromAssets(output.amount);
2344
+ const quantity = outputValue.get(unit);
2345
+ return output.address === address && quantity > 0;
2346
+ }) || [];
2347
+ return this;
2348
+ };
2349
+ /**
2350
+ * Check if outputs contain the expected value.
2351
+ * *Reminder - It must be called after filtering methods for outputs*
2352
+ * @param expectedValue The expected value
2353
+ * @returns The TxTester instance for chaining
2354
+ */
2355
+ outputsValue = (expectedValue) => {
2356
+ let value2 = new MeshValue();
2357
+ this.outputsEvaluating.forEach((output) => {
2358
+ value2.addAssets(output.amount);
2359
+ });
2360
+ const isValueCorrect = value2.eq(expectedValue);
2361
+ if (!isValueCorrect) {
2362
+ this.addTrace(
2363
+ "outputsValue",
2364
+ `tx outputs ${JSON.stringify(this.outputsEvaluating)} have value ${JSON.stringify(value2)}, expected ${JSON.stringify(expectedValue)}`
2365
+ );
2366
+ }
2367
+ return this;
2368
+ };
2369
+ /**
2370
+ * Check if outputs contain a specific inline datum.
2371
+ * *Reminder - It must be called after filtering methods for outputs*
2372
+ * @param datumCbor The datum CBOR to check
2373
+ * @returns The TxTester instance for chaining
2374
+ */
2375
+ outputsInlineDatumExist = (datumCbor) => {
2376
+ const outputsWithInlineDatum = this.outputsEvaluating.filter((output) => {
2377
+ if (output.datum && output.datum.type === "Inline") {
2378
+ return output.datum.data.content === datumCbor;
2379
+ }
2380
+ return false;
2381
+ });
2382
+ if (outputsWithInlineDatum.length === 0) {
2383
+ this.addTrace(
2384
+ "outputs_inline_datum_exist",
2385
+ `No outputs with inline datum matching: ${datumCbor}`
2386
+ );
2387
+ }
2388
+ return this;
2389
+ };
2390
+ };
2391
+ function keySignedLogic(requiredSignatures, keyHash) {
2392
+ return requiredSignatures?.some((signatory) => signatory === keyHash) || false;
2393
+ }
2394
+ function tokenMintedLogic(mints, policyId2, assetName2, quantity) {
2395
+ return mints?.some((token) => {
2396
+ return token.policyId === policyId2 && token.mintValue.findIndex(
2397
+ (m) => m.assetName === assetName2 && BigInt(m.amount) === BigInt(quantity)
2398
+ ) >= 0;
2399
+ }) || false;
2400
+ }
2401
+
1824
2402
  // src/index.ts
1825
2403
  import { generateMnemonic, mnemonicToEntropy } from "bip39";
1826
2404
  export {
@@ -1828,6 +2406,7 @@ export {
1828
2406
  BigNum,
1829
2407
  CIP68_100,
1830
2408
  CIP68_222,
2409
+ DEFAULT_FETCHER_OPTIONS,
1831
2410
  DEFAULT_PROTOCOL_PARAMETERS,
1832
2411
  DEFAULT_REDEEMER_BUDGET,
1833
2412
  DEFAULT_V1_COST_MODEL_LIST,
@@ -1845,6 +2424,7 @@ export {
1845
2424
  SUPPORTED_OGMIOS_LINKS,
1846
2425
  SUPPORTED_TOKENS,
1847
2426
  SUPPORTED_WALLETS,
2427
+ TxTester,
1848
2428
  UtxoSelection,
1849
2429
  assetClass,
1850
2430
  assetName,
@@ -1854,11 +2434,13 @@ export {
1854
2434
  byteString,
1855
2435
  bytesToHex,
1856
2436
  castProtocol,
2437
+ cloneTxBuilderBody,
1857
2438
  conStr,
1858
2439
  conStr0,
1859
2440
  conStr1,
1860
2441
  conStr2,
1861
2442
  conStr3,
2443
+ credential,
1862
2444
  currencySymbol,
1863
2445
  dict,
1864
2446
  emptyTxBuilderBody,
@@ -1872,8 +2454,11 @@ export {
1872
2454
  hexToBytes,
1873
2455
  hexToString,
1874
2456
  integer,
2457
+ isHexString,
1875
2458
  isNetwork,
2459
+ jsonProofToPlutusData,
1876
2460
  keepRelevant,
2461
+ keySignedLogic,
1877
2462
  largestFirst,
1878
2463
  largestFirstMultiAsset,
1879
2464
  list,
@@ -1884,18 +2469,21 @@ export {
1884
2469
  mConStr1,
1885
2470
  mConStr2,
1886
2471
  mConStr3,
2472
+ mCredential,
1887
2473
  mMaybeStakingHash,
1888
2474
  mNone,
1889
2475
  mOption,
1890
2476
  mOutputReference,
1891
2477
  mPlutusBSArrayToString,
1892
2478
  mPubKeyAddress,
2479
+ mScript,
1893
2480
  mScriptAddress,
1894
2481
  mSome,
1895
2482
  mStringToPlutusBSArray,
1896
2483
  mTuple,
1897
2484
  mTxOutRef,
1898
2485
  mValue,
2486
+ mVerificationKey,
1899
2487
  maybeStakingHash,
1900
2488
  mergeAssets,
1901
2489
  metadataStandardKeys,
@@ -1904,6 +2492,7 @@ export {
1904
2492
  none,
1905
2493
  option,
1906
2494
  outputReference,
2495
+ pairs,
1907
2496
  parseAssetUnit,
1908
2497
  plutusBSArrayToString,
1909
2498
  policyId,
@@ -1916,6 +2505,7 @@ export {
1916
2505
  resolveSlotNo,
1917
2506
  resolveTxFees,
1918
2507
  royaltiesStandardKeys,
2508
+ script,
1919
2509
  scriptAddress,
1920
2510
  scriptHash,
1921
2511
  slotToBeginUnixTime,
@@ -1924,11 +2514,14 @@ export {
1924
2514
  stringToHex,
1925
2515
  toBytes,
1926
2516
  toUTF8,
2517
+ tokenMintedLogic,
1927
2518
  tokenName,
1928
2519
  tuple,
1929
2520
  txInToUtxo,
1930
2521
  txOutRef,
1931
2522
  unixTimeToEnclosingSlot,
2523
+ validityRangeFromObj,
1932
2524
  validityRangeToObj,
1933
- value
2525
+ value,
2526
+ verificationKey
1934
2527
  };