@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.cjs CHANGED
@@ -34,12 +34,14 @@ __export(index_exports, {
34
34
  BigNum: () => BigNum,
35
35
  CIP68_100: () => CIP68_100,
36
36
  CIP68_222: () => CIP68_222,
37
+ DEFAULT_FETCHER_OPTIONS: () => DEFAULT_FETCHER_OPTIONS,
37
38
  DEFAULT_PROTOCOL_PARAMETERS: () => DEFAULT_PROTOCOL_PARAMETERS,
38
39
  DEFAULT_REDEEMER_BUDGET: () => DEFAULT_REDEEMER_BUDGET,
39
40
  DEFAULT_V1_COST_MODEL_LIST: () => DEFAULT_V1_COST_MODEL_LIST,
40
41
  DEFAULT_V2_COST_MODEL_LIST: () => DEFAULT_V2_COST_MODEL_LIST,
41
42
  DEFAULT_V3_COST_MODEL_LIST: () => DEFAULT_V3_COST_MODEL_LIST,
42
43
  DREP_DEPOSIT: () => DREP_DEPOSIT,
44
+ GovernanceActionKind: () => GovernanceActionKind,
43
45
  HARDENED_KEY_START: () => HARDENED_KEY_START,
44
46
  LANGUAGE_VERSIONS: () => LANGUAGE_VERSIONS,
45
47
  MeshValue: () => MeshValue,
@@ -51,7 +53,9 @@ __export(index_exports, {
51
53
  SUPPORTED_OGMIOS_LINKS: () => SUPPORTED_OGMIOS_LINKS,
52
54
  SUPPORTED_TOKENS: () => SUPPORTED_TOKENS,
53
55
  SUPPORTED_WALLETS: () => SUPPORTED_WALLETS,
56
+ TxTester: () => TxTester,
54
57
  UtxoSelection: () => UtxoSelection,
58
+ VOTING_PROPOSAL_DEPOSIT: () => VOTING_PROPOSAL_DEPOSIT,
55
59
  assetClass: () => assetClass,
56
60
  assetName: () => assetName,
57
61
  assocMap: () => assocMap,
@@ -60,11 +64,13 @@ __export(index_exports, {
60
64
  byteString: () => byteString,
61
65
  bytesToHex: () => bytesToHex,
62
66
  castProtocol: () => castProtocol,
67
+ cloneTxBuilderBody: () => cloneTxBuilderBody,
63
68
  conStr: () => conStr,
64
69
  conStr0: () => conStr0,
65
70
  conStr1: () => conStr1,
66
71
  conStr2: () => conStr2,
67
72
  conStr3: () => conStr3,
73
+ credential: () => credential,
68
74
  currencySymbol: () => currencySymbol,
69
75
  dict: () => dict,
70
76
  emptyTxBuilderBody: () => emptyTxBuilderBody,
@@ -78,8 +84,11 @@ __export(index_exports, {
78
84
  hexToBytes: () => hexToBytes,
79
85
  hexToString: () => hexToString,
80
86
  integer: () => integer,
87
+ isHexString: () => isHexString,
81
88
  isNetwork: () => isNetwork,
89
+ jsonProofToPlutusData: () => jsonProofToPlutusData,
82
90
  keepRelevant: () => keepRelevant,
91
+ keySignedLogic: () => keySignedLogic,
83
92
  largestFirst: () => largestFirst,
84
93
  largestFirstMultiAsset: () => largestFirstMultiAsset,
85
94
  list: () => list,
@@ -90,18 +99,21 @@ __export(index_exports, {
90
99
  mConStr1: () => mConStr1,
91
100
  mConStr2: () => mConStr2,
92
101
  mConStr3: () => mConStr3,
102
+ mCredential: () => mCredential,
93
103
  mMaybeStakingHash: () => mMaybeStakingHash,
94
104
  mNone: () => mNone,
95
105
  mOption: () => mOption,
96
106
  mOutputReference: () => mOutputReference,
97
107
  mPlutusBSArrayToString: () => mPlutusBSArrayToString,
98
108
  mPubKeyAddress: () => mPubKeyAddress,
109
+ mScript: () => mScript,
99
110
  mScriptAddress: () => mScriptAddress,
100
111
  mSome: () => mSome,
101
112
  mStringToPlutusBSArray: () => mStringToPlutusBSArray,
102
113
  mTuple: () => mTuple,
103
114
  mTxOutRef: () => mTxOutRef,
104
115
  mValue: () => mValue,
116
+ mVerificationKey: () => mVerificationKey,
105
117
  maybeStakingHash: () => maybeStakingHash,
106
118
  mergeAssets: () => mergeAssets,
107
119
  metadataStandardKeys: () => metadataStandardKeys,
@@ -110,6 +122,7 @@ __export(index_exports, {
110
122
  none: () => none,
111
123
  option: () => option,
112
124
  outputReference: () => outputReference,
125
+ pairs: () => pairs,
113
126
  parseAssetUnit: () => parseAssetUnit,
114
127
  plutusBSArrayToString: () => plutusBSArrayToString,
115
128
  policyId: () => policyId,
@@ -122,6 +135,7 @@ __export(index_exports, {
122
135
  resolveSlotNo: () => resolveSlotNo,
123
136
  resolveTxFees: () => resolveTxFees,
124
137
  royaltiesStandardKeys: () => royaltiesStandardKeys,
138
+ script: () => script,
125
139
  scriptAddress: () => scriptAddress,
126
140
  scriptHash: () => scriptHash,
127
141
  slotToBeginUnixTime: () => slotToBeginUnixTime,
@@ -130,13 +144,16 @@ __export(index_exports, {
130
144
  stringToHex: () => stringToHex,
131
145
  toBytes: () => toBytes,
132
146
  toUTF8: () => toUTF8,
147
+ tokenMintedLogic: () => tokenMintedLogic,
133
148
  tokenName: () => tokenName,
134
149
  tuple: () => tuple,
135
150
  txInToUtxo: () => txInToUtxo,
136
151
  txOutRef: () => txOutRef,
137
152
  unixTimeToEnclosingSlot: () => unixTimeToEnclosingSlot,
153
+ validityRangeFromObj: () => validityRangeFromObj,
138
154
  validityRangeToObj: () => validityRangeToObj,
139
- value: () => value
155
+ value: () => value,
156
+ verificationKey: () => verificationKey
140
157
  });
141
158
  module.exports = __toCommonJS(index_exports);
142
159
 
@@ -165,6 +182,7 @@ var DEFAULT_PROTOCOL_PARAMETERS = {
165
182
  minFeeRefScriptCostPerByte: 15
166
183
  };
167
184
  var DREP_DEPOSIT = "500000000";
185
+ var VOTING_PROPOSAL_DEPOSIT = "100000000000";
168
186
  var resolveTxFees = (txSize, minFeeA = DEFAULT_PROTOCOL_PARAMETERS.minFeeA, minFeeB = DEFAULT_PROTOCOL_PARAMETERS.minFeeB) => {
169
187
  const fees = BigInt(minFeeA) * BigInt(txSize) + BigInt(minFeeB);
170
188
  return fees.toString();
@@ -909,6 +927,12 @@ var CIP68_222 = (tokenNameHex) => {
909
927
  return `000de140${tokenNameHex}`;
910
928
  };
911
929
 
930
+ // src/interfaces/fetcher.ts
931
+ var DEFAULT_FETCHER_OPTIONS = {
932
+ maxPage: 20,
933
+ order: "desc"
934
+ };
935
+
912
936
  // src/types/asset.ts
913
937
  var mergeAssets = (assets) => {
914
938
  const merged = [];
@@ -996,6 +1020,7 @@ var txInToUtxo = (txIn) => {
996
1020
  var emptyTxBuilderBody = () => ({
997
1021
  inputs: [],
998
1022
  outputs: [],
1023
+ fee: "0",
999
1024
  extraInputs: [],
1000
1025
  collaterals: [],
1001
1026
  requiredSignatures: [],
@@ -1003,26 +1028,53 @@ var emptyTxBuilderBody = () => ({
1003
1028
  mints: [],
1004
1029
  changeAddress: "",
1005
1030
  metadata: /* @__PURE__ */ new Map(),
1031
+ scriptMetadata: [],
1006
1032
  validityRange: {},
1007
1033
  certificates: [],
1008
1034
  withdrawals: [],
1009
1035
  votes: [],
1036
+ proposals: [],
1010
1037
  signingKey: [],
1011
- selectionConfig: {
1012
- threshold: "0",
1013
- strategy: "experimental",
1014
- includeTxFees: true
1015
- },
1016
1038
  chainedTxs: [],
1017
1039
  inputsForEvaluation: {},
1018
- network: "mainnet"
1040
+ network: "mainnet",
1041
+ expectedNumberKeyWitnesses: 0,
1042
+ expectedByronAddressWitnesses: []
1019
1043
  });
1044
+ function cloneTxBuilderBody(body) {
1045
+ const { extraInputs, ...otherProps } = body;
1046
+ const cloned = structuredClone(otherProps);
1047
+ cloned.extraInputs = extraInputs;
1048
+ return cloned;
1049
+ }
1020
1050
  var validityRangeToObj = (validityRange) => {
1021
1051
  return {
1022
1052
  invalidBefore: validityRange.invalidBefore ?? null,
1023
1053
  invalidHereafter: validityRange.invalidHereafter ?? null
1024
1054
  };
1025
1055
  };
1056
+ var validityRangeFromObj = (obj) => {
1057
+ const validityRange = {};
1058
+ if (obj.invalidBefore !== null && obj.invalidBefore !== void 0) {
1059
+ validityRange.invalidBefore = Number(obj.invalidBefore);
1060
+ }
1061
+ if (obj.invalidHereafter !== null && obj.invalidHereafter !== void 0) {
1062
+ validityRange.invalidHereafter = Number(obj.invalidHereafter);
1063
+ }
1064
+ return validityRange;
1065
+ };
1066
+
1067
+ // src/types/governance.ts
1068
+ var GovernanceActionKind = /* @__PURE__ */ ((GovernanceActionKind2) => {
1069
+ GovernanceActionKind2["ParameterChangeAction"] = "ParameterChangeAction";
1070
+ GovernanceActionKind2["HardForkInitiationAction"] = "HardForkInitiationAction";
1071
+ GovernanceActionKind2["TreasuryWithdrawalsAction"] = "TreasuryWithdrawalsAction";
1072
+ GovernanceActionKind2["NoConfidenceAction"] = "NoConfidenceAction";
1073
+ GovernanceActionKind2["UpdateCommitteeAction"] = "UpdateCommitteeAction";
1074
+ GovernanceActionKind2["NewConstitutionAction"] = "NewConstitutionAction";
1075
+ GovernanceActionKind2["InfoAction"] = "InfoAction";
1076
+ return GovernanceActionKind2;
1077
+ })(GovernanceActionKind || {});
1026
1078
 
1027
1079
  // src/data/mesh/constructors.ts
1028
1080
  var mConStr = (alternative, fields) => ({
@@ -1072,7 +1124,7 @@ var mTxOutRef = (txHash, index) => {
1072
1124
  }
1073
1125
  return mConStr0([mConStr0([txHash]), index]);
1074
1126
  };
1075
- var mTuple = (key, value2) => [key, value2];
1127
+ var mTuple = (...args) => args;
1076
1128
  var mOption = (value2) => {
1077
1129
  if (value2) {
1078
1130
  return mSome(value2);
@@ -1083,14 +1135,16 @@ var mSome = (value2) => mConStr0([value2]);
1083
1135
  var mNone = () => mConStr1([]);
1084
1136
 
1085
1137
  // src/data/mesh/credentials.ts
1138
+ var mVerificationKey = (bytes) => mConStr0([bytes]);
1139
+ var mScript = (bytes) => mConStr1([bytes]);
1086
1140
  var mMaybeStakingHash = (stakeCredential, isStakeScriptCredential = false) => {
1087
1141
  if (stakeCredential === "") {
1088
1142
  return mConStr1([]);
1089
1143
  }
1090
1144
  if (isStakeScriptCredential) {
1091
- return mConStr0([mConStr0([mConStr1([stakeCredential])])]);
1145
+ return mConStr0([mConStr0([mScript(stakeCredential)])]);
1092
1146
  }
1093
- return mConStr0([mConStr0([mConStr0([stakeCredential])])]);
1147
+ return mConStr0([mConStr0([mVerificationKey(stakeCredential)])]);
1094
1148
  };
1095
1149
  var mPubKeyAddress = (bytes, stakeCredential, isStakeScriptCredential = false) => mConStr0([
1096
1150
  { alternative: 0, fields: [bytes] },
@@ -1100,6 +1154,7 @@ var mScriptAddress = (bytes, stakeCredential, isStakeScriptCredential = false) =
1100
1154
  { alternative: 1, fields: [bytes] },
1101
1155
  mMaybeStakingHash(stakeCredential || "", isStakeScriptCredential)
1102
1156
  ]);
1157
+ var mCredential = (hash, isScriptCredential = false) => isScriptCredential ? mScript(hash) : mVerificationKey(hash);
1103
1158
 
1104
1159
  // src/data/mesh/primitives.ts
1105
1160
  var mBool = (b) => b ? mConStr1([]) : mConStr0([]);
@@ -1187,11 +1242,25 @@ var assocMap = (mapItems, validation = true) => ({
1187
1242
  return { k, v };
1188
1243
  })
1189
1244
  });
1245
+ var pairs = (mapItems, validation = true) => ({
1246
+ map: mapItems.map(([k, v]) => {
1247
+ if (validation) {
1248
+ if (typeof k !== "object" || typeof v !== "object") {
1249
+ throw new Error(
1250
+ `Map item of JSON Cardano data type must be an object - ${k}, ${v}`
1251
+ );
1252
+ }
1253
+ }
1254
+ return { k, v };
1255
+ })
1256
+ });
1190
1257
 
1191
1258
  // src/data/json/aliases.ts
1192
1259
  var hashByteString = (bytes) => {
1193
1260
  if (bytes.length !== 56) {
1194
- throw new Error(`Invalid hash for [${bytes}] - should be 56 bytes long`);
1261
+ throw new Error(
1262
+ `Invalid hash for [${bytes}] - should be 28 bytes (56 hex length) long`
1263
+ );
1195
1264
  }
1196
1265
  return byteString(bytes);
1197
1266
  };
@@ -1200,7 +1269,7 @@ var pubKeyHash = (bytes) => hashByteString(bytes);
1200
1269
  var policyId = (bytes) => {
1201
1270
  if (bytes.length !== POLICY_ID_LENGTH && bytes !== "") {
1202
1271
  throw new Error(
1203
- `Invalid policy id for [${bytes}] - should be ${POLICY_ID_LENGTH} bytes long or empty string for lovelace`
1272
+ `Invalid policy id for [${bytes}] - should be ${POLICY_ID_LENGTH / 2} bytes (${POLICY_ID_LENGTH} hex length) long or empty string for lovelace`
1204
1273
  );
1205
1274
  }
1206
1275
  return byteString(bytes);
@@ -1232,7 +1301,9 @@ var posixTime = (int) => ({ int });
1232
1301
  var dict = (itemsMap) => ({
1233
1302
  map: itemsMap.map(([k, v]) => ({ k, v }))
1234
1303
  });
1235
- var tuple = (key, value2) => ({ list: [key, value2] });
1304
+ var tuple = (...args) => ({
1305
+ list: args
1306
+ });
1236
1307
  var option = (value2) => {
1237
1308
  if (!value2) {
1238
1309
  return none();
@@ -1243,32 +1314,62 @@ var some = (value2) => conStr0([value2]);
1243
1314
  var none = () => conStr1([]);
1244
1315
 
1245
1316
  // src/data/json/credentials.ts
1317
+ var verificationKey = (bytes) => conStr0([pubKeyHash(bytes)]);
1318
+ var script = (bytes) => conStr1([scriptHash(bytes)]);
1246
1319
  var maybeStakingHash = (stakeCredential, isStakeScriptCredential = false) => {
1247
1320
  if (stakeCredential === "") {
1248
1321
  return conStr1([]);
1249
1322
  }
1250
1323
  if (isStakeScriptCredential) {
1251
- return conStr0([
1252
- conStr0([conStr1([scriptHash(stakeCredential)])])
1253
- ]);
1324
+ return conStr0([conStr0([script(stakeCredential)])]);
1254
1325
  }
1255
- return conStr0([
1256
- conStr0([conStr0([pubKeyHash(stakeCredential)])])
1257
- ]);
1326
+ return conStr0([conStr0([verificationKey(stakeCredential)])]);
1258
1327
  };
1259
1328
  var pubKeyAddress = (bytes, stakeCredential, isStakeScriptCredential = false) => conStr0([
1260
1329
  conStr0([pubKeyHash(bytes)]),
1261
1330
  maybeStakingHash(stakeCredential || "", isStakeScriptCredential)
1262
1331
  ]);
1263
1332
  var scriptAddress = (bytes, stakeCredential, isStakeScriptCredential = false) => conStr0([
1264
- conStr1([scriptHash(bytes)]),
1333
+ script(bytes),
1265
1334
  maybeStakingHash(stakeCredential || "", isStakeScriptCredential)
1266
1335
  ]);
1336
+ var credential = (hash, isScriptCredential = false) => isScriptCredential ? script(hash) : verificationKey(hash);
1337
+
1338
+ // src/data/json/mpf.ts
1339
+ var jsonProofToPlutusData = (proof) => {
1340
+ const proofSteps = [];
1341
+ const proofJson = proof;
1342
+ proofJson.forEach((proof2) => {
1343
+ const skip = integer(proof2.skip);
1344
+ switch (proof2.type) {
1345
+ case "branch":
1346
+ proofSteps.push(
1347
+ conStr0([skip, byteString(proof2.neighbors.toString("hex"))])
1348
+ );
1349
+ break;
1350
+ case "fork":
1351
+ const { prefix, nibble, root } = proof2.neighbor;
1352
+ const neighbor = conStr0([
1353
+ integer(nibble),
1354
+ byteString(prefix.toString("hex")),
1355
+ byteString(root.toString("hex"))
1356
+ ]);
1357
+ proofSteps.push(conStr1([skip, neighbor]));
1358
+ break;
1359
+ case "leaf":
1360
+ const { key, value: value2 } = proof2.neighbor;
1361
+ proofSteps.push(conStr2([skip, byteString(key), byteString(value2)]));
1362
+ break;
1363
+ }
1364
+ });
1365
+ return proofSteps;
1366
+ };
1267
1367
 
1268
1368
  // src/data/parser.ts
1269
1369
  var bytesToHex = (bytes) => Buffer.from(bytes).toString("hex");
1270
1370
  var hexToBytes = (hex) => Buffer.from(hex, "hex");
1271
1371
  var stringToHex = (str) => Buffer.from(str, "utf8").toString("hex");
1372
+ var isHexString = (hex) => /^[0-9A-F]*$/i.test(hex);
1272
1373
  var hexToString = (hex) => Buffer.from(hex, "hex").toString("utf8");
1273
1374
  var toBytes = (hex) => {
1274
1375
  if (hex.length % 2 === 0 && /^[0-9A-F]*$/i.test(hex))
@@ -1449,8 +1550,8 @@ var BigNum = class _BigNum {
1449
1550
  // src/utils/data-hash.ts
1450
1551
  var import_blakejs = require("blakejs");
1451
1552
  var hashDrepAnchor = (jsonLD) => {
1452
- const jsonHash = (0, import_blakejs.blake2bHex)(JSON.stringify(jsonLD, null, 2), void 0, 32);
1453
- return jsonHash;
1553
+ const jsonHash = (0, import_blakejs.blake2b)(JSON.stringify(jsonLD, null, 2), void 0, 32);
1554
+ return Buffer.from(jsonHash).toString("hex");
1454
1555
  };
1455
1556
 
1456
1557
  // src/utils/file.ts
@@ -1563,6 +1664,23 @@ var MeshValue = class _MeshValue {
1563
1664
  get = (unit) => {
1564
1665
  return this.value[unit] ? BigInt(this.value[unit]) : BigInt(0);
1565
1666
  };
1667
+ /**
1668
+ * Get all assets that belong to a specific policy ID
1669
+ * @param policyId The policy ID to filter by
1670
+ * @returns Array of assets that match the policy ID
1671
+ */
1672
+ getPolicyAssets = (policyId2) => {
1673
+ const assets = [];
1674
+ Object.entries(this.value).forEach(([unit, quantity]) => {
1675
+ if (unit.startsWith(policyId2)) {
1676
+ assets.push({
1677
+ unit,
1678
+ quantity: quantity.toString()
1679
+ });
1680
+ }
1681
+ });
1682
+ return assets;
1683
+ };
1566
1684
  /**
1567
1685
  * Get all asset units
1568
1686
  * @returns The asset units
@@ -1610,6 +1728,26 @@ var MeshValue = class _MeshValue {
1610
1728
  }
1611
1729
  return BigInt(this.value[unit]) <= BigInt(other.value[unit]);
1612
1730
  };
1731
+ /**
1732
+ * Check if the value is equal to another value
1733
+ * @param other - The value to compare against
1734
+ * @returns boolean
1735
+ */
1736
+ eq = (other) => {
1737
+ return Object.keys(this.value).every((key) => this.eqUnit(key, other));
1738
+ };
1739
+ /**
1740
+ * Check if the specific unit of value is equal to that unit of another value
1741
+ * @param unit - The unit to compare
1742
+ * @param other - The value to compare against
1743
+ * @returns boolean
1744
+ */
1745
+ eqUnit = (unit, other) => {
1746
+ if (this.value[unit] === void 0 || other.value[unit] === void 0) {
1747
+ return false;
1748
+ }
1749
+ return BigInt(this.value[unit]) === BigInt(other.value[unit]);
1750
+ };
1613
1751
  /**
1614
1752
  * Check if the value is empty
1615
1753
  * @returns boolean
@@ -1712,7 +1850,7 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
1712
1850
  const selectedInputs = /* @__PURE__ */ new Set();
1713
1851
  const onlyLovelace = /* @__PURE__ */ new Set();
1714
1852
  const singletons = /* @__PURE__ */ new Set();
1715
- const pairs = /* @__PURE__ */ new Set();
1853
+ const pairs2 = /* @__PURE__ */ new Set();
1716
1854
  const rest = /* @__PURE__ */ new Set();
1717
1855
  const collaterals = /* @__PURE__ */ new Set();
1718
1856
  for (let i = 0; i < inputs.length; i++) {
@@ -1731,7 +1869,7 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
1731
1869
  break;
1732
1870
  }
1733
1871
  case 3: {
1734
- pairs.add(i);
1872
+ pairs2.add(i);
1735
1873
  break;
1736
1874
  }
1737
1875
  default: {
@@ -1764,10 +1902,10 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
1764
1902
  if (!assetRequired || Number(assetRequired) <= 0) break;
1765
1903
  addUtxoWithAssetAmount(inputIndex, assetUnit, singletons);
1766
1904
  }
1767
- for (const inputIndex of pairs) {
1905
+ for (const inputIndex of pairs2) {
1768
1906
  const assetRequired = totalRequiredAssets.get(assetUnit);
1769
1907
  if (!assetRequired || Number(assetRequired) <= 0) break;
1770
- addUtxoWithAssetAmount(inputIndex, assetUnit, pairs);
1908
+ addUtxoWithAssetAmount(inputIndex, assetUnit, pairs2);
1771
1909
  }
1772
1910
  for (const inputIndex of rest) {
1773
1911
  const assetRequired = totalRequiredAssets.get(assetUnit);
@@ -1785,10 +1923,10 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
1785
1923
  if (!assetRequired || Number(assetRequired) <= 0) break;
1786
1924
  addUtxoWithAssetAmount(inputIndex, "lovelace", singletons);
1787
1925
  }
1788
- for (const inputIndex of pairs) {
1926
+ for (const inputIndex of pairs2) {
1789
1927
  const assetRequired = totalRequiredAssets.get("lovelace");
1790
1928
  if (!assetRequired || Number(assetRequired) <= 0) break;
1791
- addUtxoWithAssetAmount(inputIndex, "lovelace", pairs);
1929
+ addUtxoWithAssetAmount(inputIndex, "lovelace", pairs2);
1792
1930
  }
1793
1931
  for (const inputIndex of rest) {
1794
1932
  const assetRequired = totalRequiredAssets.get("lovelace");
@@ -1963,6 +2101,473 @@ var UtxoSelection = class {
1963
2101
  }
1964
2102
  };
1965
2103
 
2104
+ // src/tx-tester/index.ts
2105
+ var TxTester = class {
2106
+ txBody;
2107
+ inputsEvaluating;
2108
+ outputsEvaluating;
2109
+ traces;
2110
+ /**
2111
+ * Create a new TxTester instance
2112
+ * @param txBody The transaction builder body
2113
+ */
2114
+ constructor(txBody) {
2115
+ this.txBody = { ...txBody };
2116
+ this.inputsEvaluating = [];
2117
+ this.outputsEvaluating = [];
2118
+ this.traces = [];
2119
+ }
2120
+ /**
2121
+ * Add a trace to the TxTester
2122
+ * @param funcName The function name where the error occurred
2123
+ * @param message The error message
2124
+ */
2125
+ addTrace(funcName, message) {
2126
+ const msg = `[Error - ${funcName}]: ${message}`;
2127
+ this.traces.push(msg);
2128
+ }
2129
+ /**
2130
+ * Check if the transaction evaluation was successful
2131
+ * @returns true if there are no errors, false otherwise
2132
+ */
2133
+ success() {
2134
+ return this.traces.length === 0;
2135
+ }
2136
+ /**
2137
+ * Get the error messages if any
2138
+ * @returns A string representation of the errors or "No errors" if there are none
2139
+ */
2140
+ errors() {
2141
+ if (this.traces.length > 0) {
2142
+ return `${this.traces}`;
2143
+ } else {
2144
+ return "No errors";
2145
+ }
2146
+ }
2147
+ /**
2148
+ * Checks if the transaction is valid after a specified timestamp.
2149
+ * @param requiredTimestamp The timestamp after which the transaction should be valid
2150
+ * @returns The TxTester instance for chaining
2151
+ */
2152
+ validAfter = (requiredTimestamp) => {
2153
+ const invalidBefore = this.txBody.validityRange?.invalidHereafter ? this.txBody.validityRange.invalidHereafter : 9999999999999;
2154
+ const isValidAfter = this.txBody.validityRange?.invalidBefore ? this.txBody.validityRange.invalidBefore < requiredTimestamp : true;
2155
+ if (!isValidAfter) {
2156
+ this.addTrace(
2157
+ "validAfter",
2158
+ `tx invalid before ${invalidBefore}, with requiredTimestamp ${requiredTimestamp}`
2159
+ );
2160
+ }
2161
+ return this;
2162
+ };
2163
+ /**
2164
+ * Checks if the transaction is valid before a specified timestamp.
2165
+ * @param requiredTimestamp The timestamp before which the transaction should be valid
2166
+ * @returns The TxTester instance for chaining
2167
+ */
2168
+ validBefore = (requiredTimestamp) => {
2169
+ const invalidHereafter = this.txBody.validityRange?.invalidBefore ? this.txBody.validityRange.invalidBefore : 0;
2170
+ const isValidBefore = this.txBody.validityRange?.invalidHereafter ? this.txBody.validityRange.invalidHereafter > requiredTimestamp : true;
2171
+ if (!isValidBefore) {
2172
+ this.addTrace(
2173
+ "validBefore",
2174
+ `tx invalid after ${invalidHereafter}, with requiredTimestamp ${requiredTimestamp}`
2175
+ );
2176
+ }
2177
+ return this;
2178
+ };
2179
+ // Extra Signatories Methods
2180
+ /**
2181
+ * Checks if a specific key is signed in the transaction.
2182
+ * @param keyHash The key hash to check
2183
+ * @returns The TxTester instance for chaining
2184
+ */
2185
+ keySigned = (keyHash) => {
2186
+ const isKeySigned = keySignedLogic(this.txBody.requiredSignatures, keyHash);
2187
+ if (!isKeySigned) {
2188
+ this.addTrace("keySigned", `tx does not have key ${keyHash} signed`);
2189
+ }
2190
+ return this;
2191
+ };
2192
+ /**
2193
+ * Checks if any one of the specified keys is signed in the transaction.
2194
+ * @param keyHashes The array of key hashes to check
2195
+ * @returns The TxTester instance for chaining
2196
+ */
2197
+ oneOfKeysSigned = (keyHashes) => {
2198
+ const isOneOfKeysSigned = keyHashes.some(
2199
+ (keyHash) => keySignedLogic(this.txBody.requiredSignatures, keyHash)
2200
+ );
2201
+ if (!isOneOfKeysSigned) {
2202
+ this.addTrace(
2203
+ "oneOfKeysSigned",
2204
+ `tx does not have any of the keys signed: ${keyHashes.join(", ")}`
2205
+ );
2206
+ }
2207
+ return this;
2208
+ };
2209
+ /**
2210
+ * Checks if all specified keys are signed in the transaction.
2211
+ * @param keyHashes The array of key hashes to check
2212
+ * @returns The TxTester instance for chaining
2213
+ */
2214
+ allKeysSigned = (keyHashes) => {
2215
+ const missingKeys = [];
2216
+ const isAllKeysSigned = keyHashes.every((keyHash) => {
2217
+ const isKeySigned = keySignedLogic(
2218
+ this.txBody.requiredSignatures,
2219
+ keyHash
2220
+ );
2221
+ if (!isKeySigned) {
2222
+ missingKeys.push(keyHash);
2223
+ }
2224
+ return isKeySigned;
2225
+ });
2226
+ if (!isAllKeysSigned) {
2227
+ this.addTrace(
2228
+ "allKeysSigned",
2229
+ `tx does not have all keys signed: ${missingKeys.join(", ")}`
2230
+ );
2231
+ }
2232
+ return this;
2233
+ };
2234
+ /**
2235
+ * Checks if a specific token is minted in the transaction.
2236
+ * @param policyId The policy ID of the token
2237
+ * @param assetName The asset name of the token
2238
+ * @param quantity The quantity of the token
2239
+ * @returns The TxTester instance for chaining
2240
+ */
2241
+ tokenMinted = (policyId2, assetName2, quantity) => {
2242
+ const isTokenMinted = tokenMintedLogic(
2243
+ this.txBody.mints,
2244
+ policyId2,
2245
+ assetName2,
2246
+ quantity
2247
+ );
2248
+ if (!isTokenMinted) {
2249
+ this.addTrace(
2250
+ "tokenMinted",
2251
+ `Token with policy_id: ${policyId2}, asset_name: ${assetName2}, quantity: ${quantity} not found in mints.`
2252
+ );
2253
+ }
2254
+ return this;
2255
+ };
2256
+ /**
2257
+ * Checks if a specific token is minted in the transaction and that it is the only mint.
2258
+ * @param policyId The policy ID of the token
2259
+ * @param assetName The asset name of the token
2260
+ * @param quantity The quantity of the token
2261
+ * @returns The TxTester instance for chaining
2262
+ */
2263
+ onlyTokenMinted = (policyId2, assetName2, quantity) => {
2264
+ const isTokenMinted = tokenMintedLogic(
2265
+ this.txBody.mints,
2266
+ policyId2,
2267
+ assetName2,
2268
+ quantity
2269
+ );
2270
+ const isOnlyOneMint = this.txBody.mints?.length === 1;
2271
+ if (!isTokenMinted) {
2272
+ this.addTrace(
2273
+ "onlyTokenMinted",
2274
+ `Token with policy_id: ${policyId2}, asset_name: ${assetName2}, quantity: ${quantity} not found in mints`
2275
+ );
2276
+ }
2277
+ if (!isOnlyOneMint) {
2278
+ this.addTrace(
2279
+ "onlyTokenMinted",
2280
+ `Expected only one mint, but found ${this.txBody.mints?.length || 0} mints.`
2281
+ );
2282
+ }
2283
+ return this;
2284
+ };
2285
+ /**
2286
+ * Checks if a specific token is minted in the transaction, ensuring that it is the only mint for the given policy ID.
2287
+ * @param policyId The policy ID of the token
2288
+ * @param assetName The asset name of the token
2289
+ * @param quantity The quantity of the token
2290
+ * @returns The TxTester instance for chaining
2291
+ */
2292
+ policyOnlyMintedToken = (policyId2, assetName2, quantity) => {
2293
+ const filteredMints = this.txBody.mints?.filter((token) => {
2294
+ return token.policyId === policyId2;
2295
+ }) || [];
2296
+ const isTokenMinted = tokenMintedLogic(
2297
+ this.txBody.mints,
2298
+ policyId2,
2299
+ assetName2,
2300
+ quantity
2301
+ );
2302
+ const isOnlyOneMint = filteredMints.length === 1;
2303
+ if (!isOnlyOneMint) {
2304
+ this.addTrace(
2305
+ "policyOnlyMintedToken",
2306
+ `Expected only one mint for policy_id: ${policyId2}, but found ${filteredMints.length} mints.`
2307
+ );
2308
+ }
2309
+ if (!isTokenMinted) {
2310
+ this.addTrace(
2311
+ "policyOnlyMintedToken",
2312
+ `Token with policy_id: ${policyId2}, asset_name: ${assetName2}, quantity: ${quantity} not found in mints.`
2313
+ );
2314
+ }
2315
+ return this;
2316
+ };
2317
+ /**
2318
+ * Checks if a specific policy ID is burned in the transaction, ensuring that it is the only minting (i.e. burning item).
2319
+ * @param policyId The policy ID to check
2320
+ * @returns true if the policy is the only burn, false otherwise
2321
+ */
2322
+ checkPolicyOnlyBurn = (policyId2) => {
2323
+ const filteredMints = this.txBody.mints?.filter((token) => {
2324
+ return token.policyId === policyId2 && token.mintValue.findIndex((m) => BigInt(m.amount) > 0) >= 0;
2325
+ }) || [];
2326
+ return filteredMints.length === 0;
2327
+ };
2328
+ /**
2329
+ * Not apply filter to inputs
2330
+ * @returns The TxTester instance for chaining
2331
+ */
2332
+ allInputs = () => {
2333
+ this.inputsEvaluating = this.txBody.inputs?.slice() || [];
2334
+ return this;
2335
+ };
2336
+ /**
2337
+ * Filter inputs by address
2338
+ * @param address The address to filter by
2339
+ * @returns The TxTester instance for chaining
2340
+ */
2341
+ inputsAt = (address) => {
2342
+ this.inputsEvaluating = this.txBody.inputs?.filter(
2343
+ (input) => txInToUtxo(input.txIn).output.address === address
2344
+ ) || [];
2345
+ return this;
2346
+ };
2347
+ /**
2348
+ * Filter inputs by unit
2349
+ * @param unit The unit to filter by
2350
+ * @returns The TxTester instance for chaining
2351
+ */
2352
+ inputsWith = (unit) => {
2353
+ this.inputsEvaluating = this.txBody.inputs?.filter((input) => {
2354
+ const inputValue = MeshValue.fromAssets(
2355
+ txInToUtxo(input.txIn).output.amount
2356
+ );
2357
+ const quantity = inputValue.get(unit);
2358
+ return quantity > 0;
2359
+ }) || [];
2360
+ return this;
2361
+ };
2362
+ /**
2363
+ * Filter inputs by policy ID
2364
+ * @param policyId The policy ID to filter by
2365
+ * @returns The TxTester instance for chaining
2366
+ */
2367
+ inputsWithPolicy = (policyId2) => {
2368
+ this.inputsEvaluating = this.txBody.inputs?.filter((input) => {
2369
+ const inputValue = MeshValue.fromAssets(
2370
+ txInToUtxo(input.txIn).output.amount
2371
+ );
2372
+ const assets = inputValue.getPolicyAssets(policyId2);
2373
+ return assets.length > 0;
2374
+ }) || [];
2375
+ return this;
2376
+ };
2377
+ /**
2378
+ * Filter inputs by address and policy ID
2379
+ * @param address The address to filter by
2380
+ * @param policyId The policy ID to filter by
2381
+ * @returns The TxTester instance for chaining
2382
+ */
2383
+ inputsAtWithPolicy = (address, policyId2) => {
2384
+ this.inputsEvaluating = this.txBody.inputs?.filter((input) => {
2385
+ const utxo = txInToUtxo(input.txIn);
2386
+ const inputValue = MeshValue.fromAssets(utxo.output.amount);
2387
+ const assets = inputValue.getPolicyAssets(policyId2);
2388
+ return utxo.output.address === address && assets.length > 0;
2389
+ }) || [];
2390
+ return this;
2391
+ };
2392
+ /**
2393
+ * Filter inputs by address and unit
2394
+ * @param address The address to filter by
2395
+ * @param unit The unit to filter by
2396
+ * @returns The TxTester instance for chaining
2397
+ */
2398
+ inputsAtWith = (address, unit) => {
2399
+ this.inputsEvaluating = this.txBody.inputs?.filter((input) => {
2400
+ const utxo = txInToUtxo(input.txIn);
2401
+ const inputValue = MeshValue.fromAssets(utxo.output.amount);
2402
+ const quantity = inputValue.get(unit);
2403
+ return utxo.output.address === address && quantity > 0;
2404
+ }) || [];
2405
+ return this;
2406
+ };
2407
+ /**
2408
+ * Check if inputs contain the expected value.
2409
+ * *Reminder - It must be called after filtering methods for inputs*
2410
+ * @param expectedValue The expected value
2411
+ * @returns The TxTester instance for chaining
2412
+ */
2413
+ inputsValue = (expectedValue) => {
2414
+ let value2 = new MeshValue();
2415
+ this.inputsEvaluating.forEach((input) => {
2416
+ const utxo = txInToUtxo(input.txIn);
2417
+ value2.addAssets(utxo.output.amount);
2418
+ });
2419
+ const isValueCorrect = value2.eq(expectedValue);
2420
+ if (!isValueCorrect) {
2421
+ this.addTrace(
2422
+ "inputsValue",
2423
+ `inputs ${JSON.stringify(this.inputsEvaluating)} have value ${JSON.stringify(value2)}, expect ${JSON.stringify(expectedValue)}`
2424
+ );
2425
+ }
2426
+ return this;
2427
+ };
2428
+ // /**
2429
+ // * Check if inputs contain a specific inline datum.
2430
+ // * *Reminder - It must be called after filtering methods for inputs*
2431
+ // * @param datumCbor The datum CBOR to check
2432
+ // * @returns The TxTester instance for chaining
2433
+ // */
2434
+ // inputsInlineDatumExist = (datumCbor: string): this => {
2435
+ // const inputsWithInlineDatum = this.inputsEvaluating.filter((input) => {
2436
+ // const utxo = txInToUtxo(input.txIn);
2437
+ // return utxo.output.plutusData === datumCbor;
2438
+ // });
2439
+ // if (inputsWithInlineDatum.length === 0) {
2440
+ // this.addTrace(
2441
+ // "inputsInlineDatumExist",
2442
+ // `No inputs with inline datum matching: ${datumCbor}`,
2443
+ // );
2444
+ // }
2445
+ // return this;
2446
+ // };
2447
+ /**
2448
+ * Not apply filter to outputs
2449
+ * @returns The TxTester instance for chaining
2450
+ */
2451
+ allOutputs = () => {
2452
+ this.outputsEvaluating = this.txBody.outputs?.slice() || [];
2453
+ return this;
2454
+ };
2455
+ /**
2456
+ * Filter outputs by address
2457
+ * @param address The address to filter by
2458
+ * @returns The TxTester instance for chaining
2459
+ */
2460
+ outputsAt = (address) => {
2461
+ this.outputsEvaluating = this.txBody.outputs?.filter((output) => output.address === address) || [];
2462
+ return this;
2463
+ };
2464
+ /**
2465
+ * Filter outputs by unit
2466
+ * @param unit The unit to filter by
2467
+ * @returns The TxTester instance for chaining
2468
+ */
2469
+ outputsWith = (unit) => {
2470
+ this.outputsEvaluating = this.txBody.outputs?.filter((output) => {
2471
+ const outputValue = MeshValue.fromAssets(output.amount);
2472
+ const quantity = outputValue.get(unit);
2473
+ return quantity > 0;
2474
+ }) || [];
2475
+ return this;
2476
+ };
2477
+ /**
2478
+ * Filter outputs by policy ID
2479
+ * @param policyId The policy ID to filter by
2480
+ * @returns The TxTester instance for chaining
2481
+ */
2482
+ outputsWithPolicy = (policyId2) => {
2483
+ this.outputsEvaluating = this.txBody.outputs?.filter((output) => {
2484
+ const outputValue = MeshValue.fromAssets(output.amount);
2485
+ const assets = outputValue.getPolicyAssets(policyId2);
2486
+ return assets.length > 0;
2487
+ }) || [];
2488
+ return this;
2489
+ };
2490
+ /**
2491
+ * Filter outputs by address and policy ID
2492
+ * @param address The address to filter by
2493
+ * @param policyId The policy ID to filter by
2494
+ * @returns The TxTester instance for chaining
2495
+ */
2496
+ outputsAtWithPolicy = (address, policyId2) => {
2497
+ this.outputsEvaluating = this.txBody.outputs?.filter((output) => {
2498
+ const outputValue = MeshValue.fromAssets(output.amount);
2499
+ const assets = outputValue.getPolicyAssets(policyId2);
2500
+ return output.address === address && assets.length > 0;
2501
+ }) || [];
2502
+ return this;
2503
+ };
2504
+ /**
2505
+ * Filter outputs by address and unit
2506
+ * @param address The address to filter by
2507
+ * @param unit The unit to filter by
2508
+ * @returns The TxTester instance for chaining
2509
+ */
2510
+ outputsAtWith = (address, unit) => {
2511
+ this.outputsEvaluating = this.txBody.outputs?.filter((output) => {
2512
+ const outputValue = MeshValue.fromAssets(output.amount);
2513
+ const quantity = outputValue.get(unit);
2514
+ return output.address === address && quantity > 0;
2515
+ }) || [];
2516
+ return this;
2517
+ };
2518
+ /**
2519
+ * Check if outputs contain the expected value.
2520
+ * *Reminder - It must be called after filtering methods for outputs*
2521
+ * @param expectedValue The expected value
2522
+ * @returns The TxTester instance for chaining
2523
+ */
2524
+ outputsValue = (expectedValue) => {
2525
+ let value2 = new MeshValue();
2526
+ this.outputsEvaluating.forEach((output) => {
2527
+ value2.addAssets(output.amount);
2528
+ });
2529
+ const isValueCorrect = value2.eq(expectedValue);
2530
+ if (!isValueCorrect) {
2531
+ this.addTrace(
2532
+ "outputsValue",
2533
+ `tx outputs ${JSON.stringify(this.outputsEvaluating)} have value ${JSON.stringify(value2)}, expected ${JSON.stringify(expectedValue)}`
2534
+ );
2535
+ }
2536
+ return this;
2537
+ };
2538
+ /**
2539
+ * Check if outputs contain a specific inline datum.
2540
+ * *Reminder - It must be called after filtering methods for outputs*
2541
+ * @param datumCbor The datum CBOR to check
2542
+ * @returns The TxTester instance for chaining
2543
+ */
2544
+ outputsInlineDatumExist = (datumCbor) => {
2545
+ const outputsWithInlineDatum = this.outputsEvaluating.filter((output) => {
2546
+ if (output.datum && output.datum.type === "Inline") {
2547
+ return output.datum.data.content === datumCbor;
2548
+ }
2549
+ return false;
2550
+ });
2551
+ if (outputsWithInlineDatum.length === 0) {
2552
+ this.addTrace(
2553
+ "outputs_inline_datum_exist",
2554
+ `No outputs with inline datum matching: ${datumCbor}`
2555
+ );
2556
+ }
2557
+ return this;
2558
+ };
2559
+ };
2560
+ function keySignedLogic(requiredSignatures, keyHash) {
2561
+ return requiredSignatures?.some((signatory) => signatory === keyHash) || false;
2562
+ }
2563
+ function tokenMintedLogic(mints, policyId2, assetName2, quantity) {
2564
+ return mints?.some((token) => {
2565
+ return token.policyId === policyId2 && token.mintValue.findIndex(
2566
+ (m) => m.assetName === assetName2 && BigInt(m.amount) === BigInt(quantity)
2567
+ ) >= 0;
2568
+ }) || false;
2569
+ }
2570
+
1966
2571
  // src/index.ts
1967
2572
  var import_bip39 = require("bip39");
1968
2573
  // Annotate the CommonJS export names for ESM import in node:
@@ -1971,12 +2576,14 @@ var import_bip39 = require("bip39");
1971
2576
  BigNum,
1972
2577
  CIP68_100,
1973
2578
  CIP68_222,
2579
+ DEFAULT_FETCHER_OPTIONS,
1974
2580
  DEFAULT_PROTOCOL_PARAMETERS,
1975
2581
  DEFAULT_REDEEMER_BUDGET,
1976
2582
  DEFAULT_V1_COST_MODEL_LIST,
1977
2583
  DEFAULT_V2_COST_MODEL_LIST,
1978
2584
  DEFAULT_V3_COST_MODEL_LIST,
1979
2585
  DREP_DEPOSIT,
2586
+ GovernanceActionKind,
1980
2587
  HARDENED_KEY_START,
1981
2588
  LANGUAGE_VERSIONS,
1982
2589
  MeshValue,
@@ -1988,7 +2595,9 @@ var import_bip39 = require("bip39");
1988
2595
  SUPPORTED_OGMIOS_LINKS,
1989
2596
  SUPPORTED_TOKENS,
1990
2597
  SUPPORTED_WALLETS,
2598
+ TxTester,
1991
2599
  UtxoSelection,
2600
+ VOTING_PROPOSAL_DEPOSIT,
1992
2601
  assetClass,
1993
2602
  assetName,
1994
2603
  assocMap,
@@ -1997,11 +2606,13 @@ var import_bip39 = require("bip39");
1997
2606
  byteString,
1998
2607
  bytesToHex,
1999
2608
  castProtocol,
2609
+ cloneTxBuilderBody,
2000
2610
  conStr,
2001
2611
  conStr0,
2002
2612
  conStr1,
2003
2613
  conStr2,
2004
2614
  conStr3,
2615
+ credential,
2005
2616
  currencySymbol,
2006
2617
  dict,
2007
2618
  emptyTxBuilderBody,
@@ -2015,8 +2626,11 @@ var import_bip39 = require("bip39");
2015
2626
  hexToBytes,
2016
2627
  hexToString,
2017
2628
  integer,
2629
+ isHexString,
2018
2630
  isNetwork,
2631
+ jsonProofToPlutusData,
2019
2632
  keepRelevant,
2633
+ keySignedLogic,
2020
2634
  largestFirst,
2021
2635
  largestFirstMultiAsset,
2022
2636
  list,
@@ -2027,18 +2641,21 @@ var import_bip39 = require("bip39");
2027
2641
  mConStr1,
2028
2642
  mConStr2,
2029
2643
  mConStr3,
2644
+ mCredential,
2030
2645
  mMaybeStakingHash,
2031
2646
  mNone,
2032
2647
  mOption,
2033
2648
  mOutputReference,
2034
2649
  mPlutusBSArrayToString,
2035
2650
  mPubKeyAddress,
2651
+ mScript,
2036
2652
  mScriptAddress,
2037
2653
  mSome,
2038
2654
  mStringToPlutusBSArray,
2039
2655
  mTuple,
2040
2656
  mTxOutRef,
2041
2657
  mValue,
2658
+ mVerificationKey,
2042
2659
  maybeStakingHash,
2043
2660
  mergeAssets,
2044
2661
  metadataStandardKeys,
@@ -2047,6 +2664,7 @@ var import_bip39 = require("bip39");
2047
2664
  none,
2048
2665
  option,
2049
2666
  outputReference,
2667
+ pairs,
2050
2668
  parseAssetUnit,
2051
2669
  plutusBSArrayToString,
2052
2670
  policyId,
@@ -2059,6 +2677,7 @@ var import_bip39 = require("bip39");
2059
2677
  resolveSlotNo,
2060
2678
  resolveTxFees,
2061
2679
  royaltiesStandardKeys,
2680
+ script,
2062
2681
  scriptAddress,
2063
2682
  scriptHash,
2064
2683
  slotToBeginUnixTime,
@@ -2067,11 +2686,14 @@ var import_bip39 = require("bip39");
2067
2686
  stringToHex,
2068
2687
  toBytes,
2069
2688
  toUTF8,
2689
+ tokenMintedLogic,
2070
2690
  tokenName,
2071
2691
  tuple,
2072
2692
  txInToUtxo,
2073
2693
  txOutRef,
2074
2694
  unixTimeToEnclosingSlot,
2695
+ validityRangeFromObj,
2075
2696
  validityRangeToObj,
2076
- value
2697
+ value,
2698
+ verificationKey
2077
2699
  });