@meshsdk/common 1.9.0-beta.5 → 1.9.0-beta.50
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 +127 -24
- package/dist/index.d.cts +196 -41
- package/dist/index.d.ts +196 -41
- package/dist/index.js +117 -24
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -767,6 +767,12 @@ var CIP68_222 = (tokenNameHex) => {
|
|
|
767
767
|
return `000de140${tokenNameHex}`;
|
|
768
768
|
};
|
|
769
769
|
|
|
770
|
+
// src/interfaces/fetcher.ts
|
|
771
|
+
var DEFAULT_FETCHER_OPTIONS = {
|
|
772
|
+
maxPage: 20,
|
|
773
|
+
order: "desc"
|
|
774
|
+
};
|
|
775
|
+
|
|
770
776
|
// src/types/asset.ts
|
|
771
777
|
var mergeAssets = (assets) => {
|
|
772
778
|
const merged = [];
|
|
@@ -854,6 +860,7 @@ var txInToUtxo = (txIn) => {
|
|
|
854
860
|
var emptyTxBuilderBody = () => ({
|
|
855
861
|
inputs: [],
|
|
856
862
|
outputs: [],
|
|
863
|
+
fee: "0",
|
|
857
864
|
extraInputs: [],
|
|
858
865
|
collaterals: [],
|
|
859
866
|
requiredSignatures: [],
|
|
@@ -873,8 +880,16 @@ var emptyTxBuilderBody = () => ({
|
|
|
873
880
|
},
|
|
874
881
|
chainedTxs: [],
|
|
875
882
|
inputsForEvaluation: {},
|
|
876
|
-
network: "mainnet"
|
|
883
|
+
network: "mainnet",
|
|
884
|
+
expectedNumberKeyWitnesses: 0,
|
|
885
|
+
expectedByronAddressWitnesses: []
|
|
877
886
|
});
|
|
887
|
+
function cloneTxBuilderBody(body) {
|
|
888
|
+
const { extraInputs, ...otherProps } = body;
|
|
889
|
+
const cloned = structuredClone(otherProps);
|
|
890
|
+
cloned.extraInputs = extraInputs;
|
|
891
|
+
return cloned;
|
|
892
|
+
}
|
|
878
893
|
var validityRangeToObj = (validityRange) => {
|
|
879
894
|
return {
|
|
880
895
|
invalidBefore: validityRange.invalidBefore ?? null,
|
|
@@ -930,7 +945,7 @@ var mTxOutRef = (txHash, index) => {
|
|
|
930
945
|
}
|
|
931
946
|
return mConStr0([mConStr0([txHash]), index]);
|
|
932
947
|
};
|
|
933
|
-
var mTuple = (
|
|
948
|
+
var mTuple = (...args) => args;
|
|
934
949
|
var mOption = (value2) => {
|
|
935
950
|
if (value2) {
|
|
936
951
|
return mSome(value2);
|
|
@@ -941,14 +956,16 @@ var mSome = (value2) => mConStr0([value2]);
|
|
|
941
956
|
var mNone = () => mConStr1([]);
|
|
942
957
|
|
|
943
958
|
// src/data/mesh/credentials.ts
|
|
959
|
+
var mVerificationKey = (bytes) => mConStr0([bytes]);
|
|
960
|
+
var mScript = (bytes) => mConStr1([bytes]);
|
|
944
961
|
var mMaybeStakingHash = (stakeCredential, isStakeScriptCredential = false) => {
|
|
945
962
|
if (stakeCredential === "") {
|
|
946
963
|
return mConStr1([]);
|
|
947
964
|
}
|
|
948
965
|
if (isStakeScriptCredential) {
|
|
949
|
-
return mConStr0([mConStr0([
|
|
966
|
+
return mConStr0([mConStr0([mScript(stakeCredential)])]);
|
|
950
967
|
}
|
|
951
|
-
return mConStr0([mConStr0([
|
|
968
|
+
return mConStr0([mConStr0([mVerificationKey(stakeCredential)])]);
|
|
952
969
|
};
|
|
953
970
|
var mPubKeyAddress = (bytes, stakeCredential, isStakeScriptCredential = false) => mConStr0([
|
|
954
971
|
{ alternative: 0, fields: [bytes] },
|
|
@@ -958,6 +975,7 @@ var mScriptAddress = (bytes, stakeCredential, isStakeScriptCredential = false) =
|
|
|
958
975
|
{ alternative: 1, fields: [bytes] },
|
|
959
976
|
mMaybeStakingHash(stakeCredential || "", isStakeScriptCredential)
|
|
960
977
|
]);
|
|
978
|
+
var mCredential = (hash, isScriptCredential = false) => isScriptCredential ? mScript(hash) : mVerificationKey(hash);
|
|
961
979
|
|
|
962
980
|
// src/data/mesh/primitives.ts
|
|
963
981
|
var mBool = (b) => b ? mConStr1([]) : mConStr0([]);
|
|
@@ -1045,11 +1063,25 @@ var assocMap = (mapItems, validation = true) => ({
|
|
|
1045
1063
|
return { k, v };
|
|
1046
1064
|
})
|
|
1047
1065
|
});
|
|
1066
|
+
var pairs = (mapItems, validation = true) => ({
|
|
1067
|
+
map: mapItems.map(([k, v]) => {
|
|
1068
|
+
if (validation) {
|
|
1069
|
+
if (typeof k !== "object" || typeof v !== "object") {
|
|
1070
|
+
throw new Error(
|
|
1071
|
+
`Map item of JSON Cardano data type must be an object - ${k}, ${v}`
|
|
1072
|
+
);
|
|
1073
|
+
}
|
|
1074
|
+
}
|
|
1075
|
+
return { k, v };
|
|
1076
|
+
})
|
|
1077
|
+
});
|
|
1048
1078
|
|
|
1049
1079
|
// src/data/json/aliases.ts
|
|
1050
1080
|
var hashByteString = (bytes) => {
|
|
1051
1081
|
if (bytes.length !== 56) {
|
|
1052
|
-
throw new Error(
|
|
1082
|
+
throw new Error(
|
|
1083
|
+
`Invalid hash for [${bytes}] - should be 28 bytes (56 hex length) long`
|
|
1084
|
+
);
|
|
1053
1085
|
}
|
|
1054
1086
|
return byteString(bytes);
|
|
1055
1087
|
};
|
|
@@ -1058,7 +1090,7 @@ var pubKeyHash = (bytes) => hashByteString(bytes);
|
|
|
1058
1090
|
var policyId = (bytes) => {
|
|
1059
1091
|
if (bytes.length !== POLICY_ID_LENGTH && bytes !== "") {
|
|
1060
1092
|
throw new Error(
|
|
1061
|
-
`Invalid policy id for [${bytes}] - should be ${POLICY_ID_LENGTH} bytes long or empty string for lovelace`
|
|
1093
|
+
`Invalid policy id for [${bytes}] - should be ${POLICY_ID_LENGTH / 2} bytes (${POLICY_ID_LENGTH} hex length) long or empty string for lovelace`
|
|
1062
1094
|
);
|
|
1063
1095
|
}
|
|
1064
1096
|
return byteString(bytes);
|
|
@@ -1090,7 +1122,9 @@ var posixTime = (int) => ({ int });
|
|
|
1090
1122
|
var dict = (itemsMap) => ({
|
|
1091
1123
|
map: itemsMap.map(([k, v]) => ({ k, v }))
|
|
1092
1124
|
});
|
|
1093
|
-
var tuple = (
|
|
1125
|
+
var tuple = (...args) => ({
|
|
1126
|
+
list: args
|
|
1127
|
+
});
|
|
1094
1128
|
var option = (value2) => {
|
|
1095
1129
|
if (!value2) {
|
|
1096
1130
|
return none();
|
|
@@ -1101,27 +1135,56 @@ var some = (value2) => conStr0([value2]);
|
|
|
1101
1135
|
var none = () => conStr1([]);
|
|
1102
1136
|
|
|
1103
1137
|
// src/data/json/credentials.ts
|
|
1138
|
+
var verificationKey = (bytes) => conStr0([pubKeyHash(bytes)]);
|
|
1139
|
+
var script = (bytes) => conStr1([scriptHash(bytes)]);
|
|
1104
1140
|
var maybeStakingHash = (stakeCredential, isStakeScriptCredential = false) => {
|
|
1105
1141
|
if (stakeCredential === "") {
|
|
1106
1142
|
return conStr1([]);
|
|
1107
1143
|
}
|
|
1108
1144
|
if (isStakeScriptCredential) {
|
|
1109
|
-
return conStr0([
|
|
1110
|
-
conStr0([conStr1([scriptHash(stakeCredential)])])
|
|
1111
|
-
]);
|
|
1145
|
+
return conStr0([conStr0([script(stakeCredential)])]);
|
|
1112
1146
|
}
|
|
1113
|
-
return conStr0([
|
|
1114
|
-
conStr0([conStr0([pubKeyHash(stakeCredential)])])
|
|
1115
|
-
]);
|
|
1147
|
+
return conStr0([conStr0([verificationKey(stakeCredential)])]);
|
|
1116
1148
|
};
|
|
1117
1149
|
var pubKeyAddress = (bytes, stakeCredential, isStakeScriptCredential = false) => conStr0([
|
|
1118
1150
|
conStr0([pubKeyHash(bytes)]),
|
|
1119
1151
|
maybeStakingHash(stakeCredential || "", isStakeScriptCredential)
|
|
1120
1152
|
]);
|
|
1121
1153
|
var scriptAddress = (bytes, stakeCredential, isStakeScriptCredential = false) => conStr0([
|
|
1122
|
-
|
|
1154
|
+
script(bytes),
|
|
1123
1155
|
maybeStakingHash(stakeCredential || "", isStakeScriptCredential)
|
|
1124
1156
|
]);
|
|
1157
|
+
var credential = (hash, isScriptCredential = false) => isScriptCredential ? script(hash) : verificationKey(hash);
|
|
1158
|
+
|
|
1159
|
+
// src/data/json/mpf.ts
|
|
1160
|
+
var jsonProofToPlutusData = (proof) => {
|
|
1161
|
+
const proofSteps = [];
|
|
1162
|
+
const proofJson = proof;
|
|
1163
|
+
proofJson.forEach((proof2) => {
|
|
1164
|
+
const skip = integer(proof2.skip);
|
|
1165
|
+
switch (proof2.type) {
|
|
1166
|
+
case "branch":
|
|
1167
|
+
proofSteps.push(
|
|
1168
|
+
conStr0([skip, byteString(proof2.neighbors.toString("hex"))])
|
|
1169
|
+
);
|
|
1170
|
+
break;
|
|
1171
|
+
case "fork":
|
|
1172
|
+
const { prefix, nibble, root } = proof2.neighbor;
|
|
1173
|
+
const neighbor = conStr0([
|
|
1174
|
+
integer(nibble),
|
|
1175
|
+
byteString(prefix.toString("hex")),
|
|
1176
|
+
byteString(root.toString("hex"))
|
|
1177
|
+
]);
|
|
1178
|
+
proofSteps.push(conStr1([skip, neighbor]));
|
|
1179
|
+
break;
|
|
1180
|
+
case "leaf":
|
|
1181
|
+
const { key, value: value2 } = proof2.neighbor;
|
|
1182
|
+
proofSteps.push(conStr2([skip, byteString(key), byteString(value2)]));
|
|
1183
|
+
break;
|
|
1184
|
+
}
|
|
1185
|
+
});
|
|
1186
|
+
return proofSteps;
|
|
1187
|
+
};
|
|
1125
1188
|
|
|
1126
1189
|
// src/data/parser.ts
|
|
1127
1190
|
var bytesToHex = (bytes) => Buffer.from(bytes).toString("hex");
|
|
@@ -1305,10 +1368,10 @@ var BigNum = class _BigNum {
|
|
|
1305
1368
|
};
|
|
1306
1369
|
|
|
1307
1370
|
// src/utils/data-hash.ts
|
|
1308
|
-
import {
|
|
1371
|
+
import { blake2b as blake2b2 } from "blakejs";
|
|
1309
1372
|
var hashDrepAnchor = (jsonLD) => {
|
|
1310
|
-
const jsonHash =
|
|
1311
|
-
return jsonHash;
|
|
1373
|
+
const jsonHash = blake2b2(JSON.stringify(jsonLD, null, 2), void 0, 32);
|
|
1374
|
+
return Buffer.from(jsonHash).toString("hex");
|
|
1312
1375
|
};
|
|
1313
1376
|
|
|
1314
1377
|
// src/utils/file.ts
|
|
@@ -1468,6 +1531,26 @@ var MeshValue = class _MeshValue {
|
|
|
1468
1531
|
}
|
|
1469
1532
|
return BigInt(this.value[unit]) <= BigInt(other.value[unit]);
|
|
1470
1533
|
};
|
|
1534
|
+
/**
|
|
1535
|
+
* Check if the value is equal to another value
|
|
1536
|
+
* @param other - The value to compare against
|
|
1537
|
+
* @returns boolean
|
|
1538
|
+
*/
|
|
1539
|
+
eq = (other) => {
|
|
1540
|
+
return Object.keys(this.value).every((key) => this.eqUnit(key, other));
|
|
1541
|
+
};
|
|
1542
|
+
/**
|
|
1543
|
+
* Check if the specific unit of value is equal to that unit of another value
|
|
1544
|
+
* @param unit - The unit to compare
|
|
1545
|
+
* @param other - The value to compare against
|
|
1546
|
+
* @returns boolean
|
|
1547
|
+
*/
|
|
1548
|
+
eqUnit = (unit, other) => {
|
|
1549
|
+
if (this.value[unit] === void 0 || other.value[unit] === void 0) {
|
|
1550
|
+
return false;
|
|
1551
|
+
}
|
|
1552
|
+
return BigInt(this.value[unit]) === BigInt(other.value[unit]);
|
|
1553
|
+
};
|
|
1471
1554
|
/**
|
|
1472
1555
|
* Check if the value is empty
|
|
1473
1556
|
* @returns boolean
|
|
@@ -1570,7 +1653,7 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
|
|
|
1570
1653
|
const selectedInputs = /* @__PURE__ */ new Set();
|
|
1571
1654
|
const onlyLovelace = /* @__PURE__ */ new Set();
|
|
1572
1655
|
const singletons = /* @__PURE__ */ new Set();
|
|
1573
|
-
const
|
|
1656
|
+
const pairs2 = /* @__PURE__ */ new Set();
|
|
1574
1657
|
const rest = /* @__PURE__ */ new Set();
|
|
1575
1658
|
const collaterals = /* @__PURE__ */ new Set();
|
|
1576
1659
|
for (let i = 0; i < inputs.length; i++) {
|
|
@@ -1589,7 +1672,7 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
|
|
|
1589
1672
|
break;
|
|
1590
1673
|
}
|
|
1591
1674
|
case 3: {
|
|
1592
|
-
|
|
1675
|
+
pairs2.add(i);
|
|
1593
1676
|
break;
|
|
1594
1677
|
}
|
|
1595
1678
|
default: {
|
|
@@ -1622,10 +1705,10 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
|
|
|
1622
1705
|
if (!assetRequired || Number(assetRequired) <= 0) break;
|
|
1623
1706
|
addUtxoWithAssetAmount(inputIndex, assetUnit, singletons);
|
|
1624
1707
|
}
|
|
1625
|
-
for (const inputIndex of
|
|
1708
|
+
for (const inputIndex of pairs2) {
|
|
1626
1709
|
const assetRequired = totalRequiredAssets.get(assetUnit);
|
|
1627
1710
|
if (!assetRequired || Number(assetRequired) <= 0) break;
|
|
1628
|
-
addUtxoWithAssetAmount(inputIndex, assetUnit,
|
|
1711
|
+
addUtxoWithAssetAmount(inputIndex, assetUnit, pairs2);
|
|
1629
1712
|
}
|
|
1630
1713
|
for (const inputIndex of rest) {
|
|
1631
1714
|
const assetRequired = totalRequiredAssets.get(assetUnit);
|
|
@@ -1643,10 +1726,10 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
|
|
|
1643
1726
|
if (!assetRequired || Number(assetRequired) <= 0) break;
|
|
1644
1727
|
addUtxoWithAssetAmount(inputIndex, "lovelace", singletons);
|
|
1645
1728
|
}
|
|
1646
|
-
for (const inputIndex of
|
|
1729
|
+
for (const inputIndex of pairs2) {
|
|
1647
1730
|
const assetRequired = totalRequiredAssets.get("lovelace");
|
|
1648
1731
|
if (!assetRequired || Number(assetRequired) <= 0) break;
|
|
1649
|
-
addUtxoWithAssetAmount(inputIndex, "lovelace",
|
|
1732
|
+
addUtxoWithAssetAmount(inputIndex, "lovelace", pairs2);
|
|
1650
1733
|
}
|
|
1651
1734
|
for (const inputIndex of rest) {
|
|
1652
1735
|
const assetRequired = totalRequiredAssets.get("lovelace");
|
|
@@ -1828,6 +1911,7 @@ export {
|
|
|
1828
1911
|
BigNum,
|
|
1829
1912
|
CIP68_100,
|
|
1830
1913
|
CIP68_222,
|
|
1914
|
+
DEFAULT_FETCHER_OPTIONS,
|
|
1831
1915
|
DEFAULT_PROTOCOL_PARAMETERS,
|
|
1832
1916
|
DEFAULT_REDEEMER_BUDGET,
|
|
1833
1917
|
DEFAULT_V1_COST_MODEL_LIST,
|
|
@@ -1854,11 +1938,13 @@ export {
|
|
|
1854
1938
|
byteString,
|
|
1855
1939
|
bytesToHex,
|
|
1856
1940
|
castProtocol,
|
|
1941
|
+
cloneTxBuilderBody,
|
|
1857
1942
|
conStr,
|
|
1858
1943
|
conStr0,
|
|
1859
1944
|
conStr1,
|
|
1860
1945
|
conStr2,
|
|
1861
1946
|
conStr3,
|
|
1947
|
+
credential,
|
|
1862
1948
|
currencySymbol,
|
|
1863
1949
|
dict,
|
|
1864
1950
|
emptyTxBuilderBody,
|
|
@@ -1873,6 +1959,7 @@ export {
|
|
|
1873
1959
|
hexToString,
|
|
1874
1960
|
integer,
|
|
1875
1961
|
isNetwork,
|
|
1962
|
+
jsonProofToPlutusData,
|
|
1876
1963
|
keepRelevant,
|
|
1877
1964
|
largestFirst,
|
|
1878
1965
|
largestFirstMultiAsset,
|
|
@@ -1884,18 +1971,21 @@ export {
|
|
|
1884
1971
|
mConStr1,
|
|
1885
1972
|
mConStr2,
|
|
1886
1973
|
mConStr3,
|
|
1974
|
+
mCredential,
|
|
1887
1975
|
mMaybeStakingHash,
|
|
1888
1976
|
mNone,
|
|
1889
1977
|
mOption,
|
|
1890
1978
|
mOutputReference,
|
|
1891
1979
|
mPlutusBSArrayToString,
|
|
1892
1980
|
mPubKeyAddress,
|
|
1981
|
+
mScript,
|
|
1893
1982
|
mScriptAddress,
|
|
1894
1983
|
mSome,
|
|
1895
1984
|
mStringToPlutusBSArray,
|
|
1896
1985
|
mTuple,
|
|
1897
1986
|
mTxOutRef,
|
|
1898
1987
|
mValue,
|
|
1988
|
+
mVerificationKey,
|
|
1899
1989
|
maybeStakingHash,
|
|
1900
1990
|
mergeAssets,
|
|
1901
1991
|
metadataStandardKeys,
|
|
@@ -1904,6 +1994,7 @@ export {
|
|
|
1904
1994
|
none,
|
|
1905
1995
|
option,
|
|
1906
1996
|
outputReference,
|
|
1997
|
+
pairs,
|
|
1907
1998
|
parseAssetUnit,
|
|
1908
1999
|
plutusBSArrayToString,
|
|
1909
2000
|
policyId,
|
|
@@ -1916,6 +2007,7 @@ export {
|
|
|
1916
2007
|
resolveSlotNo,
|
|
1917
2008
|
resolveTxFees,
|
|
1918
2009
|
royaltiesStandardKeys,
|
|
2010
|
+
script,
|
|
1919
2011
|
scriptAddress,
|
|
1920
2012
|
scriptHash,
|
|
1921
2013
|
slotToBeginUnixTime,
|
|
@@ -1930,5 +2022,6 @@ export {
|
|
|
1930
2022
|
txOutRef,
|
|
1931
2023
|
unixTimeToEnclosingSlot,
|
|
1932
2024
|
validityRangeToObj,
|
|
1933
|
-
value
|
|
2025
|
+
value,
|
|
2026
|
+
verificationKey
|
|
1934
2027
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshsdk/common",
|
|
3
|
-
"version": "1.9.0-beta.
|
|
3
|
+
"version": "1.9.0-beta.50",
|
|
4
4
|
"description": "Contains constants, types and interfaces used across the SDK and different serialization libraries",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"browser": "./dist/index.js",
|
|
@@ -52,4 +52,4 @@
|
|
|
52
52
|
"blockchain",
|
|
53
53
|
"sdk"
|
|
54
54
|
]
|
|
55
|
-
}
|
|
55
|
+
}
|