@meshsdk/common 1.9.0-beta.9 → 1.9.0-beta.91

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