@meshsdk/common 1.9.0-beta.10 → 1.9.0-beta.101

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
@@ -1320,6 +1404,7 @@ function getFile(url) {
1320
1404
  }
1321
1405
 
1322
1406
  // src/data/value.ts
1407
+ var compareByteOrder = (a, b) => a < b ? -1 : a > b ? 1 : 0;
1323
1408
  var value = (assets) => {
1324
1409
  return MeshValue.fromAssets(assets).toJSON();
1325
1410
  };
@@ -1331,6 +1416,26 @@ var MeshValue = class _MeshValue {
1331
1416
  constructor(value2 = {}) {
1332
1417
  this.value = value2;
1333
1418
  }
1419
+ /**
1420
+ * Sort a Value (JSON representation) by policy ID then token name
1421
+ * @param plutusValue The Value to sort
1422
+ * @returns Sorted Value
1423
+ */
1424
+ static sortValue = (plutusValue) => {
1425
+ const sortedPolicies = [...plutusValue.map].sort(
1426
+ (a, b) => compareByteOrder(a.k.bytes, b.k.bytes)
1427
+ );
1428
+ const sortedMap = sortedPolicies.map((policyEntry) => {
1429
+ const sortedTokens = [...policyEntry.v.map].sort(
1430
+ (a, b) => compareByteOrder(a.k.bytes, b.k.bytes)
1431
+ );
1432
+ return {
1433
+ k: policyEntry.k,
1434
+ v: { map: sortedTokens }
1435
+ };
1436
+ });
1437
+ return { map: sortedMap };
1438
+ };
1334
1439
  /**
1335
1440
  * Converting assets into MeshValue
1336
1441
  * @param assets The assets to convert
@@ -1421,6 +1526,23 @@ var MeshValue = class _MeshValue {
1421
1526
  get = (unit) => {
1422
1527
  return this.value[unit] ? BigInt(this.value[unit]) : BigInt(0);
1423
1528
  };
1529
+ /**
1530
+ * Get all assets that belong to a specific policy ID
1531
+ * @param policyId The policy ID to filter by
1532
+ * @returns Array of assets that match the policy ID
1533
+ */
1534
+ getPolicyAssets = (policyId2) => {
1535
+ const assets = [];
1536
+ Object.entries(this.value).forEach(([unit, quantity]) => {
1537
+ if (unit.startsWith(policyId2)) {
1538
+ assets.push({
1539
+ unit,
1540
+ quantity: quantity.toString()
1541
+ });
1542
+ }
1543
+ });
1544
+ return assets;
1545
+ };
1424
1546
  /**
1425
1547
  * Get all asset units
1426
1548
  * @returns The asset units
@@ -1468,6 +1590,26 @@ var MeshValue = class _MeshValue {
1468
1590
  }
1469
1591
  return BigInt(this.value[unit]) <= BigInt(other.value[unit]);
1470
1592
  };
1593
+ /**
1594
+ * Check if the value is equal to another value
1595
+ * @param other - The value to compare against
1596
+ * @returns boolean
1597
+ */
1598
+ eq = (other) => {
1599
+ return Object.keys(this.value).every((key) => this.eqUnit(key, other));
1600
+ };
1601
+ /**
1602
+ * Check if the specific unit of value is equal to that unit of another value
1603
+ * @param unit - The unit to compare
1604
+ * @param other - The value to compare against
1605
+ * @returns boolean
1606
+ */
1607
+ eqUnit = (unit, other) => {
1608
+ if (this.value[unit] === void 0 || other.value[unit] === void 0) {
1609
+ return false;
1610
+ }
1611
+ return BigInt(this.value[unit]) === BigInt(other.value[unit]);
1612
+ };
1471
1613
  /**
1472
1614
  * Check if the value is empty
1473
1615
  * @returns boolean
@@ -1502,17 +1644,18 @@ var MeshValue = class _MeshValue {
1502
1644
  };
1503
1645
  /**
1504
1646
  * Convert the MeshValue object into Cardano data Value in Mesh Data type
1647
+ * Entries are sorted by byte ordering of policy ID, then token name
1505
1648
  */
1506
1649
  toData = () => {
1507
- const valueMap = /* @__PURE__ */ new Map();
1650
+ const unsortedMap = /* @__PURE__ */ new Map();
1508
1651
  this.toAssets().forEach((asset) => {
1509
1652
  const sanitizedName = asset.unit.replace("lovelace", "");
1510
1653
  const policy = sanitizedName.slice(0, 56) || "";
1511
1654
  const token = sanitizedName.slice(56) || "";
1512
- if (!valueMap.has(policy)) {
1513
- valueMap.set(policy, /* @__PURE__ */ new Map());
1655
+ if (!unsortedMap.has(policy)) {
1656
+ unsortedMap.set(policy, /* @__PURE__ */ new Map());
1514
1657
  }
1515
- const tokenMap = valueMap.get(policy);
1658
+ const tokenMap = unsortedMap.get(policy);
1516
1659
  const quantity = tokenMap?.get(token);
1517
1660
  if (!quantity) {
1518
1661
  tokenMap.set(token, BigInt(asset.quantity));
@@ -1520,10 +1663,24 @@ var MeshValue = class _MeshValue {
1520
1663
  tokenMap.set(token, quantity + BigInt(asset.quantity));
1521
1664
  }
1522
1665
  });
1666
+ const sortedPolicies = Array.from(unsortedMap.keys()).sort(compareByteOrder);
1667
+ const valueMap = /* @__PURE__ */ new Map();
1668
+ sortedPolicies.forEach((policy) => {
1669
+ const unsortedTokenMap = unsortedMap.get(policy);
1670
+ const sortedTokens = Array.from(unsortedTokenMap.keys()).sort(
1671
+ compareByteOrder
1672
+ );
1673
+ const sortedTokenMap = /* @__PURE__ */ new Map();
1674
+ sortedTokens.forEach((token) => {
1675
+ sortedTokenMap.set(token, unsortedTokenMap.get(token));
1676
+ });
1677
+ valueMap.set(policy, sortedTokenMap);
1678
+ });
1523
1679
  return valueMap;
1524
1680
  };
1525
1681
  /**
1526
1682
  * Convert the MeshValue object into a JSON representation of Cardano data Value
1683
+ * Entries are sorted by byte ordering of policy ID, then token name
1527
1684
  * @returns Cardano data Value in JSON
1528
1685
  */
1529
1686
  toJSON = () => {
@@ -1542,11 +1699,16 @@ var MeshValue = class _MeshValue {
1542
1699
  valueMap[policy][token] += Number(asset.quantity);
1543
1700
  }
1544
1701
  });
1545
- Object.keys(valueMap).forEach((policy) => {
1702
+ const sortedPolicies = Object.keys(valueMap).sort(compareByteOrder);
1703
+ sortedPolicies.forEach((policy) => {
1546
1704
  const policyByte = currencySymbol(policy);
1547
- const tokens = Object.keys(valueMap[policy]).map(
1548
- (name) => [tokenName(name), integer(valueMap[policy][name])]
1705
+ const sortedTokenNames = Object.keys(valueMap[policy]).sort(
1706
+ compareByteOrder
1549
1707
  );
1708
+ const tokens = sortedTokenNames.map((name) => [
1709
+ tokenName(name),
1710
+ integer(valueMap[policy][name])
1711
+ ]);
1550
1712
  const policyMap = assocMap(tokens);
1551
1713
  valueMapToParse.push([policyByte, policyMap]);
1552
1714
  });
@@ -1570,7 +1732,7 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
1570
1732
  const selectedInputs = /* @__PURE__ */ new Set();
1571
1733
  const onlyLovelace = /* @__PURE__ */ new Set();
1572
1734
  const singletons = /* @__PURE__ */ new Set();
1573
- const pairs = /* @__PURE__ */ new Set();
1735
+ const pairs2 = /* @__PURE__ */ new Set();
1574
1736
  const rest = /* @__PURE__ */ new Set();
1575
1737
  const collaterals = /* @__PURE__ */ new Set();
1576
1738
  for (let i = 0; i < inputs.length; i++) {
@@ -1589,7 +1751,7 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
1589
1751
  break;
1590
1752
  }
1591
1753
  case 3: {
1592
- pairs.add(i);
1754
+ pairs2.add(i);
1593
1755
  break;
1594
1756
  }
1595
1757
  default: {
@@ -1622,10 +1784,10 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
1622
1784
  if (!assetRequired || Number(assetRequired) <= 0) break;
1623
1785
  addUtxoWithAssetAmount(inputIndex, assetUnit, singletons);
1624
1786
  }
1625
- for (const inputIndex of pairs) {
1787
+ for (const inputIndex of pairs2) {
1626
1788
  const assetRequired = totalRequiredAssets.get(assetUnit);
1627
1789
  if (!assetRequired || Number(assetRequired) <= 0) break;
1628
- addUtxoWithAssetAmount(inputIndex, assetUnit, pairs);
1790
+ addUtxoWithAssetAmount(inputIndex, assetUnit, pairs2);
1629
1791
  }
1630
1792
  for (const inputIndex of rest) {
1631
1793
  const assetRequired = totalRequiredAssets.get(assetUnit);
@@ -1643,10 +1805,10 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
1643
1805
  if (!assetRequired || Number(assetRequired) <= 0) break;
1644
1806
  addUtxoWithAssetAmount(inputIndex, "lovelace", singletons);
1645
1807
  }
1646
- for (const inputIndex of pairs) {
1808
+ for (const inputIndex of pairs2) {
1647
1809
  const assetRequired = totalRequiredAssets.get("lovelace");
1648
1810
  if (!assetRequired || Number(assetRequired) <= 0) break;
1649
- addUtxoWithAssetAmount(inputIndex, "lovelace", pairs);
1811
+ addUtxoWithAssetAmount(inputIndex, "lovelace", pairs2);
1650
1812
  }
1651
1813
  for (const inputIndex of rest) {
1652
1814
  const assetRequired = totalRequiredAssets.get("lovelace");
@@ -1821,6 +1983,473 @@ var UtxoSelection = class {
1821
1983
  }
1822
1984
  };
1823
1985
 
1986
+ // src/tx-tester/index.ts
1987
+ var TxTester = class {
1988
+ txBody;
1989
+ inputsEvaluating;
1990
+ outputsEvaluating;
1991
+ traces;
1992
+ /**
1993
+ * Create a new TxTester instance
1994
+ * @param txBody The transaction builder body
1995
+ */
1996
+ constructor(txBody) {
1997
+ this.txBody = { ...txBody };
1998
+ this.inputsEvaluating = [];
1999
+ this.outputsEvaluating = [];
2000
+ this.traces = [];
2001
+ }
2002
+ /**
2003
+ * Add a trace to the TxTester
2004
+ * @param funcName The function name where the error occurred
2005
+ * @param message The error message
2006
+ */
2007
+ addTrace(funcName, message) {
2008
+ const msg = `[Error - ${funcName}]: ${message}`;
2009
+ this.traces.push(msg);
2010
+ }
2011
+ /**
2012
+ * Check if the transaction evaluation was successful
2013
+ * @returns true if there are no errors, false otherwise
2014
+ */
2015
+ success() {
2016
+ return this.traces.length === 0;
2017
+ }
2018
+ /**
2019
+ * Get the error messages if any
2020
+ * @returns A string representation of the errors or "No errors" if there are none
2021
+ */
2022
+ errors() {
2023
+ if (this.traces.length > 0) {
2024
+ return `${this.traces}`;
2025
+ } else {
2026
+ return "No errors";
2027
+ }
2028
+ }
2029
+ /**
2030
+ * Checks if the transaction is valid after a specified timestamp.
2031
+ * @param requiredTimestamp The timestamp after which the transaction should be valid
2032
+ * @returns The TxTester instance for chaining
2033
+ */
2034
+ validAfter = (requiredTimestamp) => {
2035
+ const invalidBefore = this.txBody.validityRange?.invalidHereafter ? this.txBody.validityRange.invalidHereafter : 9999999999999;
2036
+ const isValidAfter = this.txBody.validityRange?.invalidBefore ? this.txBody.validityRange.invalidBefore < requiredTimestamp : true;
2037
+ if (!isValidAfter) {
2038
+ this.addTrace(
2039
+ "validAfter",
2040
+ `tx invalid before ${invalidBefore}, with requiredTimestamp ${requiredTimestamp}`
2041
+ );
2042
+ }
2043
+ return this;
2044
+ };
2045
+ /**
2046
+ * Checks if the transaction is valid before a specified timestamp.
2047
+ * @param requiredTimestamp The timestamp before which the transaction should be valid
2048
+ * @returns The TxTester instance for chaining
2049
+ */
2050
+ validBefore = (requiredTimestamp) => {
2051
+ const invalidHereafter = this.txBody.validityRange?.invalidBefore ? this.txBody.validityRange.invalidBefore : 0;
2052
+ const isValidBefore = this.txBody.validityRange?.invalidHereafter ? this.txBody.validityRange.invalidHereafter > requiredTimestamp : true;
2053
+ if (!isValidBefore) {
2054
+ this.addTrace(
2055
+ "validBefore",
2056
+ `tx invalid after ${invalidHereafter}, with requiredTimestamp ${requiredTimestamp}`
2057
+ );
2058
+ }
2059
+ return this;
2060
+ };
2061
+ // Extra Signatories Methods
2062
+ /**
2063
+ * Checks if a specific key is signed in the transaction.
2064
+ * @param keyHash The key hash to check
2065
+ * @returns The TxTester instance for chaining
2066
+ */
2067
+ keySigned = (keyHash) => {
2068
+ const isKeySigned = keySignedLogic(this.txBody.requiredSignatures, keyHash);
2069
+ if (!isKeySigned) {
2070
+ this.addTrace("keySigned", `tx does not have key ${keyHash} signed`);
2071
+ }
2072
+ return this;
2073
+ };
2074
+ /**
2075
+ * Checks if any one of the specified keys is signed in the transaction.
2076
+ * @param keyHashes The array of key hashes to check
2077
+ * @returns The TxTester instance for chaining
2078
+ */
2079
+ oneOfKeysSigned = (keyHashes) => {
2080
+ const isOneOfKeysSigned = keyHashes.some(
2081
+ (keyHash) => keySignedLogic(this.txBody.requiredSignatures, keyHash)
2082
+ );
2083
+ if (!isOneOfKeysSigned) {
2084
+ this.addTrace(
2085
+ "oneOfKeysSigned",
2086
+ `tx does not have any of the keys signed: ${keyHashes.join(", ")}`
2087
+ );
2088
+ }
2089
+ return this;
2090
+ };
2091
+ /**
2092
+ * Checks if all specified keys are signed in the transaction.
2093
+ * @param keyHashes The array of key hashes to check
2094
+ * @returns The TxTester instance for chaining
2095
+ */
2096
+ allKeysSigned = (keyHashes) => {
2097
+ const missingKeys = [];
2098
+ const isAllKeysSigned = keyHashes.every((keyHash) => {
2099
+ const isKeySigned = keySignedLogic(
2100
+ this.txBody.requiredSignatures,
2101
+ keyHash
2102
+ );
2103
+ if (!isKeySigned) {
2104
+ missingKeys.push(keyHash);
2105
+ }
2106
+ return isKeySigned;
2107
+ });
2108
+ if (!isAllKeysSigned) {
2109
+ this.addTrace(
2110
+ "allKeysSigned",
2111
+ `tx does not have all keys signed: ${missingKeys.join(", ")}`
2112
+ );
2113
+ }
2114
+ return this;
2115
+ };
2116
+ /**
2117
+ * Checks if a specific token is minted in the transaction.
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
+ tokenMinted = (policyId2, assetName2, quantity) => {
2124
+ const isTokenMinted = tokenMintedLogic(
2125
+ this.txBody.mints,
2126
+ policyId2,
2127
+ assetName2,
2128
+ quantity
2129
+ );
2130
+ if (!isTokenMinted) {
2131
+ this.addTrace(
2132
+ "tokenMinted",
2133
+ `Token with policy_id: ${policyId2}, asset_name: ${assetName2}, quantity: ${quantity} not found in mints.`
2134
+ );
2135
+ }
2136
+ return this;
2137
+ };
2138
+ /**
2139
+ * Checks if a specific token is minted in the transaction and that it is the only mint.
2140
+ * @param policyId The policy ID of the token
2141
+ * @param assetName The asset name of the token
2142
+ * @param quantity The quantity of the token
2143
+ * @returns The TxTester instance for chaining
2144
+ */
2145
+ onlyTokenMinted = (policyId2, assetName2, quantity) => {
2146
+ const isTokenMinted = tokenMintedLogic(
2147
+ this.txBody.mints,
2148
+ policyId2,
2149
+ assetName2,
2150
+ quantity
2151
+ );
2152
+ const isOnlyOneMint = this.txBody.mints?.length === 1;
2153
+ if (!isTokenMinted) {
2154
+ this.addTrace(
2155
+ "onlyTokenMinted",
2156
+ `Token with policy_id: ${policyId2}, asset_name: ${assetName2}, quantity: ${quantity} not found in mints`
2157
+ );
2158
+ }
2159
+ if (!isOnlyOneMint) {
2160
+ this.addTrace(
2161
+ "onlyTokenMinted",
2162
+ `Expected only one mint, but found ${this.txBody.mints?.length || 0} mints.`
2163
+ );
2164
+ }
2165
+ return this;
2166
+ };
2167
+ /**
2168
+ * Checks if a specific token is minted in the transaction, ensuring that it is the only mint for the given policy ID.
2169
+ * @param policyId The policy ID of the token
2170
+ * @param assetName The asset name of the token
2171
+ * @param quantity The quantity of the token
2172
+ * @returns The TxTester instance for chaining
2173
+ */
2174
+ policyOnlyMintedToken = (policyId2, assetName2, quantity) => {
2175
+ const filteredMints = this.txBody.mints?.filter((token) => {
2176
+ return token.policyId === policyId2;
2177
+ }) || [];
2178
+ const isTokenMinted = tokenMintedLogic(
2179
+ this.txBody.mints,
2180
+ policyId2,
2181
+ assetName2,
2182
+ quantity
2183
+ );
2184
+ const isOnlyOneMint = filteredMints.length === 1;
2185
+ if (!isOnlyOneMint) {
2186
+ this.addTrace(
2187
+ "policyOnlyMintedToken",
2188
+ `Expected only one mint for policy_id: ${policyId2}, but found ${filteredMints.length} mints.`
2189
+ );
2190
+ }
2191
+ if (!isTokenMinted) {
2192
+ this.addTrace(
2193
+ "policyOnlyMintedToken",
2194
+ `Token with policy_id: ${policyId2}, asset_name: ${assetName2}, quantity: ${quantity} not found in mints.`
2195
+ );
2196
+ }
2197
+ return this;
2198
+ };
2199
+ /**
2200
+ * Checks if a specific policy ID is burned in the transaction, ensuring that it is the only minting (i.e. burning item).
2201
+ * @param policyId The policy ID to check
2202
+ * @returns true if the policy is the only burn, false otherwise
2203
+ */
2204
+ checkPolicyOnlyBurn = (policyId2) => {
2205
+ const filteredMints = this.txBody.mints?.filter((token) => {
2206
+ return token.policyId === policyId2 && token.mintValue.findIndex((m) => BigInt(m.amount) > 0) >= 0;
2207
+ }) || [];
2208
+ return filteredMints.length === 0;
2209
+ };
2210
+ /**
2211
+ * Not apply filter to inputs
2212
+ * @returns The TxTester instance for chaining
2213
+ */
2214
+ allInputs = () => {
2215
+ this.inputsEvaluating = this.txBody.inputs?.slice() || [];
2216
+ return this;
2217
+ };
2218
+ /**
2219
+ * Filter inputs by address
2220
+ * @param address The address to filter by
2221
+ * @returns The TxTester instance for chaining
2222
+ */
2223
+ inputsAt = (address) => {
2224
+ this.inputsEvaluating = this.txBody.inputs?.filter(
2225
+ (input) => txInToUtxo(input.txIn).output.address === address
2226
+ ) || [];
2227
+ return this;
2228
+ };
2229
+ /**
2230
+ * Filter inputs by unit
2231
+ * @param unit The unit to filter by
2232
+ * @returns The TxTester instance for chaining
2233
+ */
2234
+ inputsWith = (unit) => {
2235
+ this.inputsEvaluating = this.txBody.inputs?.filter((input) => {
2236
+ const inputValue = MeshValue.fromAssets(
2237
+ txInToUtxo(input.txIn).output.amount
2238
+ );
2239
+ const quantity = inputValue.get(unit);
2240
+ return quantity > 0;
2241
+ }) || [];
2242
+ return this;
2243
+ };
2244
+ /**
2245
+ * Filter inputs by policy ID
2246
+ * @param policyId The policy ID to filter by
2247
+ * @returns The TxTester instance for chaining
2248
+ */
2249
+ inputsWithPolicy = (policyId2) => {
2250
+ this.inputsEvaluating = this.txBody.inputs?.filter((input) => {
2251
+ const inputValue = MeshValue.fromAssets(
2252
+ txInToUtxo(input.txIn).output.amount
2253
+ );
2254
+ const assets = inputValue.getPolicyAssets(policyId2);
2255
+ return assets.length > 0;
2256
+ }) || [];
2257
+ return this;
2258
+ };
2259
+ /**
2260
+ * Filter inputs by address and policy ID
2261
+ * @param address The address to filter by
2262
+ * @param policyId The policy ID to filter by
2263
+ * @returns The TxTester instance for chaining
2264
+ */
2265
+ inputsAtWithPolicy = (address, policyId2) => {
2266
+ this.inputsEvaluating = this.txBody.inputs?.filter((input) => {
2267
+ const utxo = txInToUtxo(input.txIn);
2268
+ const inputValue = MeshValue.fromAssets(utxo.output.amount);
2269
+ const assets = inputValue.getPolicyAssets(policyId2);
2270
+ return utxo.output.address === address && assets.length > 0;
2271
+ }) || [];
2272
+ return this;
2273
+ };
2274
+ /**
2275
+ * Filter inputs by address and unit
2276
+ * @param address The address to filter by
2277
+ * @param unit The unit to filter by
2278
+ * @returns The TxTester instance for chaining
2279
+ */
2280
+ inputsAtWith = (address, unit) => {
2281
+ this.inputsEvaluating = this.txBody.inputs?.filter((input) => {
2282
+ const utxo = txInToUtxo(input.txIn);
2283
+ const inputValue = MeshValue.fromAssets(utxo.output.amount);
2284
+ const quantity = inputValue.get(unit);
2285
+ return utxo.output.address === address && quantity > 0;
2286
+ }) || [];
2287
+ return this;
2288
+ };
2289
+ /**
2290
+ * Check if inputs contain the expected value.
2291
+ * *Reminder - It must be called after filtering methods for inputs*
2292
+ * @param expectedValue The expected value
2293
+ * @returns The TxTester instance for chaining
2294
+ */
2295
+ inputsValue = (expectedValue) => {
2296
+ let value2 = new MeshValue();
2297
+ this.inputsEvaluating.forEach((input) => {
2298
+ const utxo = txInToUtxo(input.txIn);
2299
+ value2.addAssets(utxo.output.amount);
2300
+ });
2301
+ const isValueCorrect = value2.eq(expectedValue);
2302
+ if (!isValueCorrect) {
2303
+ this.addTrace(
2304
+ "inputsValue",
2305
+ `inputs ${JSON.stringify(this.inputsEvaluating)} have value ${JSON.stringify(value2)}, expect ${JSON.stringify(expectedValue)}`
2306
+ );
2307
+ }
2308
+ return this;
2309
+ };
2310
+ // /**
2311
+ // * Check if inputs contain a specific inline datum.
2312
+ // * *Reminder - It must be called after filtering methods for inputs*
2313
+ // * @param datumCbor The datum CBOR to check
2314
+ // * @returns The TxTester instance for chaining
2315
+ // */
2316
+ // inputsInlineDatumExist = (datumCbor: string): this => {
2317
+ // const inputsWithInlineDatum = this.inputsEvaluating.filter((input) => {
2318
+ // const utxo = txInToUtxo(input.txIn);
2319
+ // return utxo.output.plutusData === datumCbor;
2320
+ // });
2321
+ // if (inputsWithInlineDatum.length === 0) {
2322
+ // this.addTrace(
2323
+ // "inputsInlineDatumExist",
2324
+ // `No inputs with inline datum matching: ${datumCbor}`,
2325
+ // );
2326
+ // }
2327
+ // return this;
2328
+ // };
2329
+ /**
2330
+ * Not apply filter to outputs
2331
+ * @returns The TxTester instance for chaining
2332
+ */
2333
+ allOutputs = () => {
2334
+ this.outputsEvaluating = this.txBody.outputs?.slice() || [];
2335
+ return this;
2336
+ };
2337
+ /**
2338
+ * Filter outputs by address
2339
+ * @param address The address to filter by
2340
+ * @returns The TxTester instance for chaining
2341
+ */
2342
+ outputsAt = (address) => {
2343
+ this.outputsEvaluating = this.txBody.outputs?.filter((output) => output.address === address) || [];
2344
+ return this;
2345
+ };
2346
+ /**
2347
+ * Filter outputs by unit
2348
+ * @param unit The unit to filter by
2349
+ * @returns The TxTester instance for chaining
2350
+ */
2351
+ outputsWith = (unit) => {
2352
+ this.outputsEvaluating = this.txBody.outputs?.filter((output) => {
2353
+ const outputValue = MeshValue.fromAssets(output.amount);
2354
+ const quantity = outputValue.get(unit);
2355
+ return quantity > 0;
2356
+ }) || [];
2357
+ return this;
2358
+ };
2359
+ /**
2360
+ * Filter outputs by policy ID
2361
+ * @param policyId The policy ID to filter by
2362
+ * @returns The TxTester instance for chaining
2363
+ */
2364
+ outputsWithPolicy = (policyId2) => {
2365
+ this.outputsEvaluating = this.txBody.outputs?.filter((output) => {
2366
+ const outputValue = MeshValue.fromAssets(output.amount);
2367
+ const assets = outputValue.getPolicyAssets(policyId2);
2368
+ return assets.length > 0;
2369
+ }) || [];
2370
+ return this;
2371
+ };
2372
+ /**
2373
+ * Filter outputs by address and policy ID
2374
+ * @param address The address to filter by
2375
+ * @param policyId The policy ID to filter by
2376
+ * @returns The TxTester instance for chaining
2377
+ */
2378
+ outputsAtWithPolicy = (address, policyId2) => {
2379
+ this.outputsEvaluating = this.txBody.outputs?.filter((output) => {
2380
+ const outputValue = MeshValue.fromAssets(output.amount);
2381
+ const assets = outputValue.getPolicyAssets(policyId2);
2382
+ return output.address === address && assets.length > 0;
2383
+ }) || [];
2384
+ return this;
2385
+ };
2386
+ /**
2387
+ * Filter outputs by address and unit
2388
+ * @param address The address to filter by
2389
+ * @param unit The unit to filter by
2390
+ * @returns The TxTester instance for chaining
2391
+ */
2392
+ outputsAtWith = (address, unit) => {
2393
+ this.outputsEvaluating = this.txBody.outputs?.filter((output) => {
2394
+ const outputValue = MeshValue.fromAssets(output.amount);
2395
+ const quantity = outputValue.get(unit);
2396
+ return output.address === address && quantity > 0;
2397
+ }) || [];
2398
+ return this;
2399
+ };
2400
+ /**
2401
+ * Check if outputs contain the expected value.
2402
+ * *Reminder - It must be called after filtering methods for outputs*
2403
+ * @param expectedValue The expected value
2404
+ * @returns The TxTester instance for chaining
2405
+ */
2406
+ outputsValue = (expectedValue) => {
2407
+ let value2 = new MeshValue();
2408
+ this.outputsEvaluating.forEach((output) => {
2409
+ value2.addAssets(output.amount);
2410
+ });
2411
+ const isValueCorrect = value2.eq(expectedValue);
2412
+ if (!isValueCorrect) {
2413
+ this.addTrace(
2414
+ "outputsValue",
2415
+ `tx outputs ${JSON.stringify(this.outputsEvaluating)} have value ${JSON.stringify(value2)}, expected ${JSON.stringify(expectedValue)}`
2416
+ );
2417
+ }
2418
+ return this;
2419
+ };
2420
+ /**
2421
+ * Check if outputs contain a specific inline datum.
2422
+ * *Reminder - It must be called after filtering methods for outputs*
2423
+ * @param datumCbor The datum CBOR to check
2424
+ * @returns The TxTester instance for chaining
2425
+ */
2426
+ outputsInlineDatumExist = (datumCbor) => {
2427
+ const outputsWithInlineDatum = this.outputsEvaluating.filter((output) => {
2428
+ if (output.datum && output.datum.type === "Inline") {
2429
+ return output.datum.data.content === datumCbor;
2430
+ }
2431
+ return false;
2432
+ });
2433
+ if (outputsWithInlineDatum.length === 0) {
2434
+ this.addTrace(
2435
+ "outputs_inline_datum_exist",
2436
+ `No outputs with inline datum matching: ${datumCbor}`
2437
+ );
2438
+ }
2439
+ return this;
2440
+ };
2441
+ };
2442
+ function keySignedLogic(requiredSignatures, keyHash) {
2443
+ return requiredSignatures?.some((signatory) => signatory === keyHash) || false;
2444
+ }
2445
+ function tokenMintedLogic(mints, policyId2, assetName2, quantity) {
2446
+ return mints?.some((token) => {
2447
+ return token.policyId === policyId2 && token.mintValue.findIndex(
2448
+ (m) => m.assetName === assetName2 && BigInt(m.amount) === BigInt(quantity)
2449
+ ) >= 0;
2450
+ }) || false;
2451
+ }
2452
+
1824
2453
  // src/index.ts
1825
2454
  import { generateMnemonic, mnemonicToEntropy } from "bip39";
1826
2455
  export {
@@ -1828,12 +2457,14 @@ export {
1828
2457
  BigNum,
1829
2458
  CIP68_100,
1830
2459
  CIP68_222,
2460
+ DEFAULT_FETCHER_OPTIONS,
1831
2461
  DEFAULT_PROTOCOL_PARAMETERS,
1832
2462
  DEFAULT_REDEEMER_BUDGET,
1833
2463
  DEFAULT_V1_COST_MODEL_LIST,
1834
2464
  DEFAULT_V2_COST_MODEL_LIST,
1835
2465
  DEFAULT_V3_COST_MODEL_LIST,
1836
2466
  DREP_DEPOSIT,
2467
+ GovernanceActionKind,
1837
2468
  HARDENED_KEY_START,
1838
2469
  LANGUAGE_VERSIONS,
1839
2470
  MeshValue,
@@ -1845,7 +2476,9 @@ export {
1845
2476
  SUPPORTED_OGMIOS_LINKS,
1846
2477
  SUPPORTED_TOKENS,
1847
2478
  SUPPORTED_WALLETS,
2479
+ TxTester,
1848
2480
  UtxoSelection,
2481
+ VOTING_PROPOSAL_DEPOSIT,
1849
2482
  assetClass,
1850
2483
  assetName,
1851
2484
  assocMap,
@@ -1854,11 +2487,13 @@ export {
1854
2487
  byteString,
1855
2488
  bytesToHex,
1856
2489
  castProtocol,
2490
+ cloneTxBuilderBody,
1857
2491
  conStr,
1858
2492
  conStr0,
1859
2493
  conStr1,
1860
2494
  conStr2,
1861
2495
  conStr3,
2496
+ credential,
1862
2497
  currencySymbol,
1863
2498
  dict,
1864
2499
  emptyTxBuilderBody,
@@ -1872,8 +2507,11 @@ export {
1872
2507
  hexToBytes,
1873
2508
  hexToString,
1874
2509
  integer,
2510
+ isHexString,
1875
2511
  isNetwork,
2512
+ jsonProofToPlutusData,
1876
2513
  keepRelevant,
2514
+ keySignedLogic,
1877
2515
  largestFirst,
1878
2516
  largestFirstMultiAsset,
1879
2517
  list,
@@ -1884,18 +2522,21 @@ export {
1884
2522
  mConStr1,
1885
2523
  mConStr2,
1886
2524
  mConStr3,
2525
+ mCredential,
1887
2526
  mMaybeStakingHash,
1888
2527
  mNone,
1889
2528
  mOption,
1890
2529
  mOutputReference,
1891
2530
  mPlutusBSArrayToString,
1892
2531
  mPubKeyAddress,
2532
+ mScript,
1893
2533
  mScriptAddress,
1894
2534
  mSome,
1895
2535
  mStringToPlutusBSArray,
1896
2536
  mTuple,
1897
2537
  mTxOutRef,
1898
2538
  mValue,
2539
+ mVerificationKey,
1899
2540
  maybeStakingHash,
1900
2541
  mergeAssets,
1901
2542
  metadataStandardKeys,
@@ -1904,6 +2545,7 @@ export {
1904
2545
  none,
1905
2546
  option,
1906
2547
  outputReference,
2548
+ pairs,
1907
2549
  parseAssetUnit,
1908
2550
  plutusBSArrayToString,
1909
2551
  policyId,
@@ -1916,6 +2558,7 @@ export {
1916
2558
  resolveSlotNo,
1917
2559
  resolveTxFees,
1918
2560
  royaltiesStandardKeys,
2561
+ script,
1919
2562
  scriptAddress,
1920
2563
  scriptHash,
1921
2564
  slotToBeginUnixTime,
@@ -1924,11 +2567,14 @@ export {
1924
2567
  stringToHex,
1925
2568
  toBytes,
1926
2569
  toUTF8,
2570
+ tokenMintedLogic,
1927
2571
  tokenName,
1928
2572
  tuple,
1929
2573
  txInToUtxo,
1930
2574
  txOutRef,
1931
2575
  unixTimeToEnclosingSlot,
2576
+ validityRangeFromObj,
1932
2577
  validityRangeToObj,
1933
- value
2578
+ value,
2579
+ verificationKey
1934
2580
  };