@meshsdk/common 1.9.0-beta.5 → 1.9.0-beta.52

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,6 +34,7 @@ __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,
@@ -60,11 +61,13 @@ __export(index_exports, {
60
61
  byteString: () => byteString,
61
62
  bytesToHex: () => bytesToHex,
62
63
  castProtocol: () => castProtocol,
64
+ cloneTxBuilderBody: () => cloneTxBuilderBody,
63
65
  conStr: () => conStr,
64
66
  conStr0: () => conStr0,
65
67
  conStr1: () => conStr1,
66
68
  conStr2: () => conStr2,
67
69
  conStr3: () => conStr3,
70
+ credential: () => credential,
68
71
  currencySymbol: () => currencySymbol,
69
72
  dict: () => dict,
70
73
  emptyTxBuilderBody: () => emptyTxBuilderBody,
@@ -79,6 +82,7 @@ __export(index_exports, {
79
82
  hexToString: () => hexToString,
80
83
  integer: () => integer,
81
84
  isNetwork: () => isNetwork,
85
+ jsonProofToPlutusData: () => jsonProofToPlutusData,
82
86
  keepRelevant: () => keepRelevant,
83
87
  largestFirst: () => largestFirst,
84
88
  largestFirstMultiAsset: () => largestFirstMultiAsset,
@@ -90,18 +94,21 @@ __export(index_exports, {
90
94
  mConStr1: () => mConStr1,
91
95
  mConStr2: () => mConStr2,
92
96
  mConStr3: () => mConStr3,
97
+ mCredential: () => mCredential,
93
98
  mMaybeStakingHash: () => mMaybeStakingHash,
94
99
  mNone: () => mNone,
95
100
  mOption: () => mOption,
96
101
  mOutputReference: () => mOutputReference,
97
102
  mPlutusBSArrayToString: () => mPlutusBSArrayToString,
98
103
  mPubKeyAddress: () => mPubKeyAddress,
104
+ mScript: () => mScript,
99
105
  mScriptAddress: () => mScriptAddress,
100
106
  mSome: () => mSome,
101
107
  mStringToPlutusBSArray: () => mStringToPlutusBSArray,
102
108
  mTuple: () => mTuple,
103
109
  mTxOutRef: () => mTxOutRef,
104
110
  mValue: () => mValue,
111
+ mVerificationKey: () => mVerificationKey,
105
112
  maybeStakingHash: () => maybeStakingHash,
106
113
  mergeAssets: () => mergeAssets,
107
114
  metadataStandardKeys: () => metadataStandardKeys,
@@ -110,6 +117,7 @@ __export(index_exports, {
110
117
  none: () => none,
111
118
  option: () => option,
112
119
  outputReference: () => outputReference,
120
+ pairs: () => pairs,
113
121
  parseAssetUnit: () => parseAssetUnit,
114
122
  plutusBSArrayToString: () => plutusBSArrayToString,
115
123
  policyId: () => policyId,
@@ -122,6 +130,7 @@ __export(index_exports, {
122
130
  resolveSlotNo: () => resolveSlotNo,
123
131
  resolveTxFees: () => resolveTxFees,
124
132
  royaltiesStandardKeys: () => royaltiesStandardKeys,
133
+ script: () => script,
125
134
  scriptAddress: () => scriptAddress,
126
135
  scriptHash: () => scriptHash,
127
136
  slotToBeginUnixTime: () => slotToBeginUnixTime,
@@ -136,7 +145,8 @@ __export(index_exports, {
136
145
  txOutRef: () => txOutRef,
137
146
  unixTimeToEnclosingSlot: () => unixTimeToEnclosingSlot,
138
147
  validityRangeToObj: () => validityRangeToObj,
139
- value: () => value
148
+ value: () => value,
149
+ verificationKey: () => verificationKey
140
150
  });
141
151
  module.exports = __toCommonJS(index_exports);
142
152
 
@@ -909,6 +919,12 @@ var CIP68_222 = (tokenNameHex) => {
909
919
  return `000de140${tokenNameHex}`;
910
920
  };
911
921
 
922
+ // src/interfaces/fetcher.ts
923
+ var DEFAULT_FETCHER_OPTIONS = {
924
+ maxPage: 20,
925
+ order: "desc"
926
+ };
927
+
912
928
  // src/types/asset.ts
913
929
  var mergeAssets = (assets) => {
914
930
  const merged = [];
@@ -996,6 +1012,7 @@ var txInToUtxo = (txIn) => {
996
1012
  var emptyTxBuilderBody = () => ({
997
1013
  inputs: [],
998
1014
  outputs: [],
1015
+ fee: "0",
999
1016
  extraInputs: [],
1000
1017
  collaterals: [],
1001
1018
  requiredSignatures: [],
@@ -1015,8 +1032,16 @@ var emptyTxBuilderBody = () => ({
1015
1032
  },
1016
1033
  chainedTxs: [],
1017
1034
  inputsForEvaluation: {},
1018
- network: "mainnet"
1035
+ network: "mainnet",
1036
+ expectedNumberKeyWitnesses: 0,
1037
+ expectedByronAddressWitnesses: []
1019
1038
  });
1039
+ function cloneTxBuilderBody(body) {
1040
+ const { extraInputs, ...otherProps } = body;
1041
+ const cloned = structuredClone(otherProps);
1042
+ cloned.extraInputs = extraInputs;
1043
+ return cloned;
1044
+ }
1020
1045
  var validityRangeToObj = (validityRange) => {
1021
1046
  return {
1022
1047
  invalidBefore: validityRange.invalidBefore ?? null,
@@ -1072,7 +1097,7 @@ var mTxOutRef = (txHash, index) => {
1072
1097
  }
1073
1098
  return mConStr0([mConStr0([txHash]), index]);
1074
1099
  };
1075
- var mTuple = (key, value2) => [key, value2];
1100
+ var mTuple = (...args) => args;
1076
1101
  var mOption = (value2) => {
1077
1102
  if (value2) {
1078
1103
  return mSome(value2);
@@ -1083,14 +1108,16 @@ var mSome = (value2) => mConStr0([value2]);
1083
1108
  var mNone = () => mConStr1([]);
1084
1109
 
1085
1110
  // src/data/mesh/credentials.ts
1111
+ var mVerificationKey = (bytes) => mConStr0([bytes]);
1112
+ var mScript = (bytes) => mConStr1([bytes]);
1086
1113
  var mMaybeStakingHash = (stakeCredential, isStakeScriptCredential = false) => {
1087
1114
  if (stakeCredential === "") {
1088
1115
  return mConStr1([]);
1089
1116
  }
1090
1117
  if (isStakeScriptCredential) {
1091
- return mConStr0([mConStr0([mConStr1([stakeCredential])])]);
1118
+ return mConStr0([mConStr0([mScript(stakeCredential)])]);
1092
1119
  }
1093
- return mConStr0([mConStr0([mConStr0([stakeCredential])])]);
1120
+ return mConStr0([mConStr0([mVerificationKey(stakeCredential)])]);
1094
1121
  };
1095
1122
  var mPubKeyAddress = (bytes, stakeCredential, isStakeScriptCredential = false) => mConStr0([
1096
1123
  { alternative: 0, fields: [bytes] },
@@ -1100,6 +1127,7 @@ var mScriptAddress = (bytes, stakeCredential, isStakeScriptCredential = false) =
1100
1127
  { alternative: 1, fields: [bytes] },
1101
1128
  mMaybeStakingHash(stakeCredential || "", isStakeScriptCredential)
1102
1129
  ]);
1130
+ var mCredential = (hash, isScriptCredential = false) => isScriptCredential ? mScript(hash) : mVerificationKey(hash);
1103
1131
 
1104
1132
  // src/data/mesh/primitives.ts
1105
1133
  var mBool = (b) => b ? mConStr1([]) : mConStr0([]);
@@ -1187,11 +1215,25 @@ var assocMap = (mapItems, validation = true) => ({
1187
1215
  return { k, v };
1188
1216
  })
1189
1217
  });
1218
+ var pairs = (mapItems, validation = true) => ({
1219
+ map: mapItems.map(([k, v]) => {
1220
+ if (validation) {
1221
+ if (typeof k !== "object" || typeof v !== "object") {
1222
+ throw new Error(
1223
+ `Map item of JSON Cardano data type must be an object - ${k}, ${v}`
1224
+ );
1225
+ }
1226
+ }
1227
+ return { k, v };
1228
+ })
1229
+ });
1190
1230
 
1191
1231
  // src/data/json/aliases.ts
1192
1232
  var hashByteString = (bytes) => {
1193
1233
  if (bytes.length !== 56) {
1194
- throw new Error(`Invalid hash for [${bytes}] - should be 56 bytes long`);
1234
+ throw new Error(
1235
+ `Invalid hash for [${bytes}] - should be 28 bytes (56 hex length) long`
1236
+ );
1195
1237
  }
1196
1238
  return byteString(bytes);
1197
1239
  };
@@ -1200,7 +1242,7 @@ var pubKeyHash = (bytes) => hashByteString(bytes);
1200
1242
  var policyId = (bytes) => {
1201
1243
  if (bytes.length !== POLICY_ID_LENGTH && bytes !== "") {
1202
1244
  throw new Error(
1203
- `Invalid policy id for [${bytes}] - should be ${POLICY_ID_LENGTH} bytes long or empty string for lovelace`
1245
+ `Invalid policy id for [${bytes}] - should be ${POLICY_ID_LENGTH / 2} bytes (${POLICY_ID_LENGTH} hex length) long or empty string for lovelace`
1204
1246
  );
1205
1247
  }
1206
1248
  return byteString(bytes);
@@ -1232,7 +1274,9 @@ var posixTime = (int) => ({ int });
1232
1274
  var dict = (itemsMap) => ({
1233
1275
  map: itemsMap.map(([k, v]) => ({ k, v }))
1234
1276
  });
1235
- var tuple = (key, value2) => ({ list: [key, value2] });
1277
+ var tuple = (...args) => ({
1278
+ list: args
1279
+ });
1236
1280
  var option = (value2) => {
1237
1281
  if (!value2) {
1238
1282
  return none();
@@ -1243,27 +1287,56 @@ var some = (value2) => conStr0([value2]);
1243
1287
  var none = () => conStr1([]);
1244
1288
 
1245
1289
  // src/data/json/credentials.ts
1290
+ var verificationKey = (bytes) => conStr0([pubKeyHash(bytes)]);
1291
+ var script = (bytes) => conStr1([scriptHash(bytes)]);
1246
1292
  var maybeStakingHash = (stakeCredential, isStakeScriptCredential = false) => {
1247
1293
  if (stakeCredential === "") {
1248
1294
  return conStr1([]);
1249
1295
  }
1250
1296
  if (isStakeScriptCredential) {
1251
- return conStr0([
1252
- conStr0([conStr1([scriptHash(stakeCredential)])])
1253
- ]);
1297
+ return conStr0([conStr0([script(stakeCredential)])]);
1254
1298
  }
1255
- return conStr0([
1256
- conStr0([conStr0([pubKeyHash(stakeCredential)])])
1257
- ]);
1299
+ return conStr0([conStr0([verificationKey(stakeCredential)])]);
1258
1300
  };
1259
1301
  var pubKeyAddress = (bytes, stakeCredential, isStakeScriptCredential = false) => conStr0([
1260
1302
  conStr0([pubKeyHash(bytes)]),
1261
1303
  maybeStakingHash(stakeCredential || "", isStakeScriptCredential)
1262
1304
  ]);
1263
1305
  var scriptAddress = (bytes, stakeCredential, isStakeScriptCredential = false) => conStr0([
1264
- conStr1([scriptHash(bytes)]),
1306
+ script(bytes),
1265
1307
  maybeStakingHash(stakeCredential || "", isStakeScriptCredential)
1266
1308
  ]);
1309
+ var credential = (hash, isScriptCredential = false) => isScriptCredential ? script(hash) : verificationKey(hash);
1310
+
1311
+ // src/data/json/mpf.ts
1312
+ var jsonProofToPlutusData = (proof) => {
1313
+ const proofSteps = [];
1314
+ const proofJson = proof;
1315
+ proofJson.forEach((proof2) => {
1316
+ const skip = integer(proof2.skip);
1317
+ switch (proof2.type) {
1318
+ case "branch":
1319
+ proofSteps.push(
1320
+ conStr0([skip, byteString(proof2.neighbors.toString("hex"))])
1321
+ );
1322
+ break;
1323
+ case "fork":
1324
+ const { prefix, nibble, root } = proof2.neighbor;
1325
+ const neighbor = conStr0([
1326
+ integer(nibble),
1327
+ byteString(prefix.toString("hex")),
1328
+ byteString(root.toString("hex"))
1329
+ ]);
1330
+ proofSteps.push(conStr1([skip, neighbor]));
1331
+ break;
1332
+ case "leaf":
1333
+ const { key, value: value2 } = proof2.neighbor;
1334
+ proofSteps.push(conStr2([skip, byteString(key), byteString(value2)]));
1335
+ break;
1336
+ }
1337
+ });
1338
+ return proofSteps;
1339
+ };
1267
1340
 
1268
1341
  // src/data/parser.ts
1269
1342
  var bytesToHex = (bytes) => Buffer.from(bytes).toString("hex");
@@ -1449,8 +1522,8 @@ var BigNum = class _BigNum {
1449
1522
  // src/utils/data-hash.ts
1450
1523
  var import_blakejs = require("blakejs");
1451
1524
  var hashDrepAnchor = (jsonLD) => {
1452
- const jsonHash = (0, import_blakejs.blake2bHex)(JSON.stringify(jsonLD, null, 2), void 0, 32);
1453
- return jsonHash;
1525
+ const jsonHash = (0, import_blakejs.blake2b)(JSON.stringify(jsonLD, null, 2), void 0, 32);
1526
+ return Buffer.from(jsonHash).toString("hex");
1454
1527
  };
1455
1528
 
1456
1529
  // src/utils/file.ts
@@ -1610,6 +1683,26 @@ var MeshValue = class _MeshValue {
1610
1683
  }
1611
1684
  return BigInt(this.value[unit]) <= BigInt(other.value[unit]);
1612
1685
  };
1686
+ /**
1687
+ * Check if the value is equal to another value
1688
+ * @param other - The value to compare against
1689
+ * @returns boolean
1690
+ */
1691
+ eq = (other) => {
1692
+ return Object.keys(this.value).every((key) => this.eqUnit(key, other));
1693
+ };
1694
+ /**
1695
+ * Check if the specific unit of value is equal to that unit of another value
1696
+ * @param unit - The unit to compare
1697
+ * @param other - The value to compare against
1698
+ * @returns boolean
1699
+ */
1700
+ eqUnit = (unit, other) => {
1701
+ if (this.value[unit] === void 0 || other.value[unit] === void 0) {
1702
+ return false;
1703
+ }
1704
+ return BigInt(this.value[unit]) === BigInt(other.value[unit]);
1705
+ };
1613
1706
  /**
1614
1707
  * Check if the value is empty
1615
1708
  * @returns boolean
@@ -1712,7 +1805,7 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
1712
1805
  const selectedInputs = /* @__PURE__ */ new Set();
1713
1806
  const onlyLovelace = /* @__PURE__ */ new Set();
1714
1807
  const singletons = /* @__PURE__ */ new Set();
1715
- const pairs = /* @__PURE__ */ new Set();
1808
+ const pairs2 = /* @__PURE__ */ new Set();
1716
1809
  const rest = /* @__PURE__ */ new Set();
1717
1810
  const collaterals = /* @__PURE__ */ new Set();
1718
1811
  for (let i = 0; i < inputs.length; i++) {
@@ -1731,7 +1824,7 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
1731
1824
  break;
1732
1825
  }
1733
1826
  case 3: {
1734
- pairs.add(i);
1827
+ pairs2.add(i);
1735
1828
  break;
1736
1829
  }
1737
1830
  default: {
@@ -1764,10 +1857,10 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
1764
1857
  if (!assetRequired || Number(assetRequired) <= 0) break;
1765
1858
  addUtxoWithAssetAmount(inputIndex, assetUnit, singletons);
1766
1859
  }
1767
- for (const inputIndex of pairs) {
1860
+ for (const inputIndex of pairs2) {
1768
1861
  const assetRequired = totalRequiredAssets.get(assetUnit);
1769
1862
  if (!assetRequired || Number(assetRequired) <= 0) break;
1770
- addUtxoWithAssetAmount(inputIndex, assetUnit, pairs);
1863
+ addUtxoWithAssetAmount(inputIndex, assetUnit, pairs2);
1771
1864
  }
1772
1865
  for (const inputIndex of rest) {
1773
1866
  const assetRequired = totalRequiredAssets.get(assetUnit);
@@ -1785,10 +1878,10 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
1785
1878
  if (!assetRequired || Number(assetRequired) <= 0) break;
1786
1879
  addUtxoWithAssetAmount(inputIndex, "lovelace", singletons);
1787
1880
  }
1788
- for (const inputIndex of pairs) {
1881
+ for (const inputIndex of pairs2) {
1789
1882
  const assetRequired = totalRequiredAssets.get("lovelace");
1790
1883
  if (!assetRequired || Number(assetRequired) <= 0) break;
1791
- addUtxoWithAssetAmount(inputIndex, "lovelace", pairs);
1884
+ addUtxoWithAssetAmount(inputIndex, "lovelace", pairs2);
1792
1885
  }
1793
1886
  for (const inputIndex of rest) {
1794
1887
  const assetRequired = totalRequiredAssets.get("lovelace");
@@ -1971,6 +2064,7 @@ var import_bip39 = require("bip39");
1971
2064
  BigNum,
1972
2065
  CIP68_100,
1973
2066
  CIP68_222,
2067
+ DEFAULT_FETCHER_OPTIONS,
1974
2068
  DEFAULT_PROTOCOL_PARAMETERS,
1975
2069
  DEFAULT_REDEEMER_BUDGET,
1976
2070
  DEFAULT_V1_COST_MODEL_LIST,
@@ -1997,11 +2091,13 @@ var import_bip39 = require("bip39");
1997
2091
  byteString,
1998
2092
  bytesToHex,
1999
2093
  castProtocol,
2094
+ cloneTxBuilderBody,
2000
2095
  conStr,
2001
2096
  conStr0,
2002
2097
  conStr1,
2003
2098
  conStr2,
2004
2099
  conStr3,
2100
+ credential,
2005
2101
  currencySymbol,
2006
2102
  dict,
2007
2103
  emptyTxBuilderBody,
@@ -2016,6 +2112,7 @@ var import_bip39 = require("bip39");
2016
2112
  hexToString,
2017
2113
  integer,
2018
2114
  isNetwork,
2115
+ jsonProofToPlutusData,
2019
2116
  keepRelevant,
2020
2117
  largestFirst,
2021
2118
  largestFirstMultiAsset,
@@ -2027,18 +2124,21 @@ var import_bip39 = require("bip39");
2027
2124
  mConStr1,
2028
2125
  mConStr2,
2029
2126
  mConStr3,
2127
+ mCredential,
2030
2128
  mMaybeStakingHash,
2031
2129
  mNone,
2032
2130
  mOption,
2033
2131
  mOutputReference,
2034
2132
  mPlutusBSArrayToString,
2035
2133
  mPubKeyAddress,
2134
+ mScript,
2036
2135
  mScriptAddress,
2037
2136
  mSome,
2038
2137
  mStringToPlutusBSArray,
2039
2138
  mTuple,
2040
2139
  mTxOutRef,
2041
2140
  mValue,
2141
+ mVerificationKey,
2042
2142
  maybeStakingHash,
2043
2143
  mergeAssets,
2044
2144
  metadataStandardKeys,
@@ -2047,6 +2147,7 @@ var import_bip39 = require("bip39");
2047
2147
  none,
2048
2148
  option,
2049
2149
  outputReference,
2150
+ pairs,
2050
2151
  parseAssetUnit,
2051
2152
  plutusBSArrayToString,
2052
2153
  policyId,
@@ -2059,6 +2160,7 @@ var import_bip39 = require("bip39");
2059
2160
  resolveSlotNo,
2060
2161
  resolveTxFees,
2061
2162
  royaltiesStandardKeys,
2163
+ script,
2062
2164
  scriptAddress,
2063
2165
  scriptHash,
2064
2166
  slotToBeginUnixTime,
@@ -2073,5 +2175,6 @@ var import_bip39 = require("bip39");
2073
2175
  txOutRef,
2074
2176
  unixTimeToEnclosingSlot,
2075
2177
  validityRangeToObj,
2076
- value
2178
+ value,
2179
+ verificationKey
2077
2180
  });