@meshsdk/common 1.9.0-beta.6 → 1.9.0-beta.60
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 +632 -24
- package/dist/index.d.cts +421 -43
- package/dist/index.d.ts +421 -43
- package/dist/index.js +617 -24
- package/package.json +2 -2
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,
|
|
@@ -51,6 +52,7 @@ __export(index_exports, {
|
|
|
51
52
|
SUPPORTED_OGMIOS_LINKS: () => SUPPORTED_OGMIOS_LINKS,
|
|
52
53
|
SUPPORTED_TOKENS: () => SUPPORTED_TOKENS,
|
|
53
54
|
SUPPORTED_WALLETS: () => SUPPORTED_WALLETS,
|
|
55
|
+
TxTester: () => TxTester,
|
|
54
56
|
UtxoSelection: () => UtxoSelection,
|
|
55
57
|
assetClass: () => assetClass,
|
|
56
58
|
assetName: () => assetName,
|
|
@@ -60,11 +62,13 @@ __export(index_exports, {
|
|
|
60
62
|
byteString: () => byteString,
|
|
61
63
|
bytesToHex: () => bytesToHex,
|
|
62
64
|
castProtocol: () => castProtocol,
|
|
65
|
+
cloneTxBuilderBody: () => cloneTxBuilderBody,
|
|
63
66
|
conStr: () => conStr,
|
|
64
67
|
conStr0: () => conStr0,
|
|
65
68
|
conStr1: () => conStr1,
|
|
66
69
|
conStr2: () => conStr2,
|
|
67
70
|
conStr3: () => conStr3,
|
|
71
|
+
credential: () => credential,
|
|
68
72
|
currencySymbol: () => currencySymbol,
|
|
69
73
|
dict: () => dict,
|
|
70
74
|
emptyTxBuilderBody: () => emptyTxBuilderBody,
|
|
@@ -78,8 +82,11 @@ __export(index_exports, {
|
|
|
78
82
|
hexToBytes: () => hexToBytes,
|
|
79
83
|
hexToString: () => hexToString,
|
|
80
84
|
integer: () => integer,
|
|
85
|
+
isHexString: () => isHexString,
|
|
81
86
|
isNetwork: () => isNetwork,
|
|
87
|
+
jsonProofToPlutusData: () => jsonProofToPlutusData,
|
|
82
88
|
keepRelevant: () => keepRelevant,
|
|
89
|
+
keySignedLogic: () => keySignedLogic,
|
|
83
90
|
largestFirst: () => largestFirst,
|
|
84
91
|
largestFirstMultiAsset: () => largestFirstMultiAsset,
|
|
85
92
|
list: () => list,
|
|
@@ -90,18 +97,21 @@ __export(index_exports, {
|
|
|
90
97
|
mConStr1: () => mConStr1,
|
|
91
98
|
mConStr2: () => mConStr2,
|
|
92
99
|
mConStr3: () => mConStr3,
|
|
100
|
+
mCredential: () => mCredential,
|
|
93
101
|
mMaybeStakingHash: () => mMaybeStakingHash,
|
|
94
102
|
mNone: () => mNone,
|
|
95
103
|
mOption: () => mOption,
|
|
96
104
|
mOutputReference: () => mOutputReference,
|
|
97
105
|
mPlutusBSArrayToString: () => mPlutusBSArrayToString,
|
|
98
106
|
mPubKeyAddress: () => mPubKeyAddress,
|
|
107
|
+
mScript: () => mScript,
|
|
99
108
|
mScriptAddress: () => mScriptAddress,
|
|
100
109
|
mSome: () => mSome,
|
|
101
110
|
mStringToPlutusBSArray: () => mStringToPlutusBSArray,
|
|
102
111
|
mTuple: () => mTuple,
|
|
103
112
|
mTxOutRef: () => mTxOutRef,
|
|
104
113
|
mValue: () => mValue,
|
|
114
|
+
mVerificationKey: () => mVerificationKey,
|
|
105
115
|
maybeStakingHash: () => maybeStakingHash,
|
|
106
116
|
mergeAssets: () => mergeAssets,
|
|
107
117
|
metadataStandardKeys: () => metadataStandardKeys,
|
|
@@ -110,6 +120,7 @@ __export(index_exports, {
|
|
|
110
120
|
none: () => none,
|
|
111
121
|
option: () => option,
|
|
112
122
|
outputReference: () => outputReference,
|
|
123
|
+
pairs: () => pairs,
|
|
113
124
|
parseAssetUnit: () => parseAssetUnit,
|
|
114
125
|
plutusBSArrayToString: () => plutusBSArrayToString,
|
|
115
126
|
policyId: () => policyId,
|
|
@@ -122,6 +133,7 @@ __export(index_exports, {
|
|
|
122
133
|
resolveSlotNo: () => resolveSlotNo,
|
|
123
134
|
resolveTxFees: () => resolveTxFees,
|
|
124
135
|
royaltiesStandardKeys: () => royaltiesStandardKeys,
|
|
136
|
+
script: () => script,
|
|
125
137
|
scriptAddress: () => scriptAddress,
|
|
126
138
|
scriptHash: () => scriptHash,
|
|
127
139
|
slotToBeginUnixTime: () => slotToBeginUnixTime,
|
|
@@ -130,13 +142,16 @@ __export(index_exports, {
|
|
|
130
142
|
stringToHex: () => stringToHex,
|
|
131
143
|
toBytes: () => toBytes,
|
|
132
144
|
toUTF8: () => toUTF8,
|
|
145
|
+
tokenMintedLogic: () => tokenMintedLogic,
|
|
133
146
|
tokenName: () => tokenName,
|
|
134
147
|
tuple: () => tuple,
|
|
135
148
|
txInToUtxo: () => txInToUtxo,
|
|
136
149
|
txOutRef: () => txOutRef,
|
|
137
150
|
unixTimeToEnclosingSlot: () => unixTimeToEnclosingSlot,
|
|
151
|
+
validityRangeFromObj: () => validityRangeFromObj,
|
|
138
152
|
validityRangeToObj: () => validityRangeToObj,
|
|
139
|
-
value: () => value
|
|
153
|
+
value: () => value,
|
|
154
|
+
verificationKey: () => verificationKey
|
|
140
155
|
});
|
|
141
156
|
module.exports = __toCommonJS(index_exports);
|
|
142
157
|
|
|
@@ -909,6 +924,12 @@ var CIP68_222 = (tokenNameHex) => {
|
|
|
909
924
|
return `000de140${tokenNameHex}`;
|
|
910
925
|
};
|
|
911
926
|
|
|
927
|
+
// src/interfaces/fetcher.ts
|
|
928
|
+
var DEFAULT_FETCHER_OPTIONS = {
|
|
929
|
+
maxPage: 20,
|
|
930
|
+
order: "desc"
|
|
931
|
+
};
|
|
932
|
+
|
|
912
933
|
// src/types/asset.ts
|
|
913
934
|
var mergeAssets = (assets) => {
|
|
914
935
|
const merged = [];
|
|
@@ -996,6 +1017,7 @@ var txInToUtxo = (txIn) => {
|
|
|
996
1017
|
var emptyTxBuilderBody = () => ({
|
|
997
1018
|
inputs: [],
|
|
998
1019
|
outputs: [],
|
|
1020
|
+
fee: "0",
|
|
999
1021
|
extraInputs: [],
|
|
1000
1022
|
collaterals: [],
|
|
1001
1023
|
requiredSignatures: [],
|
|
@@ -1015,14 +1037,32 @@ var emptyTxBuilderBody = () => ({
|
|
|
1015
1037
|
},
|
|
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
|
+
};
|
|
1026
1066
|
|
|
1027
1067
|
// src/data/mesh/constructors.ts
|
|
1028
1068
|
var mConStr = (alternative, fields) => ({
|
|
@@ -1072,7 +1112,7 @@ var mTxOutRef = (txHash, index) => {
|
|
|
1072
1112
|
}
|
|
1073
1113
|
return mConStr0([mConStr0([txHash]), index]);
|
|
1074
1114
|
};
|
|
1075
|
-
var mTuple = (
|
|
1115
|
+
var mTuple = (...args) => args;
|
|
1076
1116
|
var mOption = (value2) => {
|
|
1077
1117
|
if (value2) {
|
|
1078
1118
|
return mSome(value2);
|
|
@@ -1083,14 +1123,16 @@ var mSome = (value2) => mConStr0([value2]);
|
|
|
1083
1123
|
var mNone = () => mConStr1([]);
|
|
1084
1124
|
|
|
1085
1125
|
// src/data/mesh/credentials.ts
|
|
1126
|
+
var mVerificationKey = (bytes) => mConStr0([bytes]);
|
|
1127
|
+
var mScript = (bytes) => mConStr1([bytes]);
|
|
1086
1128
|
var mMaybeStakingHash = (stakeCredential, isStakeScriptCredential = false) => {
|
|
1087
1129
|
if (stakeCredential === "") {
|
|
1088
1130
|
return mConStr1([]);
|
|
1089
1131
|
}
|
|
1090
1132
|
if (isStakeScriptCredential) {
|
|
1091
|
-
return mConStr0([mConStr0([
|
|
1133
|
+
return mConStr0([mConStr0([mScript(stakeCredential)])]);
|
|
1092
1134
|
}
|
|
1093
|
-
return mConStr0([mConStr0([
|
|
1135
|
+
return mConStr0([mConStr0([mVerificationKey(stakeCredential)])]);
|
|
1094
1136
|
};
|
|
1095
1137
|
var mPubKeyAddress = (bytes, stakeCredential, isStakeScriptCredential = false) => mConStr0([
|
|
1096
1138
|
{ alternative: 0, fields: [bytes] },
|
|
@@ -1100,6 +1142,7 @@ var mScriptAddress = (bytes, stakeCredential, isStakeScriptCredential = false) =
|
|
|
1100
1142
|
{ alternative: 1, fields: [bytes] },
|
|
1101
1143
|
mMaybeStakingHash(stakeCredential || "", isStakeScriptCredential)
|
|
1102
1144
|
]);
|
|
1145
|
+
var mCredential = (hash, isScriptCredential = false) => isScriptCredential ? mScript(hash) : mVerificationKey(hash);
|
|
1103
1146
|
|
|
1104
1147
|
// src/data/mesh/primitives.ts
|
|
1105
1148
|
var mBool = (b) => b ? mConStr1([]) : mConStr0([]);
|
|
@@ -1187,11 +1230,25 @@ var assocMap = (mapItems, validation = true) => ({
|
|
|
1187
1230
|
return { k, v };
|
|
1188
1231
|
})
|
|
1189
1232
|
});
|
|
1233
|
+
var pairs = (mapItems, validation = true) => ({
|
|
1234
|
+
map: mapItems.map(([k, v]) => {
|
|
1235
|
+
if (validation) {
|
|
1236
|
+
if (typeof k !== "object" || typeof v !== "object") {
|
|
1237
|
+
throw new Error(
|
|
1238
|
+
`Map item of JSON Cardano data type must be an object - ${k}, ${v}`
|
|
1239
|
+
);
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
return { k, v };
|
|
1243
|
+
})
|
|
1244
|
+
});
|
|
1190
1245
|
|
|
1191
1246
|
// src/data/json/aliases.ts
|
|
1192
1247
|
var hashByteString = (bytes) => {
|
|
1193
1248
|
if (bytes.length !== 56) {
|
|
1194
|
-
throw new Error(
|
|
1249
|
+
throw new Error(
|
|
1250
|
+
`Invalid hash for [${bytes}] - should be 28 bytes (56 hex length) long`
|
|
1251
|
+
);
|
|
1195
1252
|
}
|
|
1196
1253
|
return byteString(bytes);
|
|
1197
1254
|
};
|
|
@@ -1200,7 +1257,7 @@ var pubKeyHash = (bytes) => hashByteString(bytes);
|
|
|
1200
1257
|
var policyId = (bytes) => {
|
|
1201
1258
|
if (bytes.length !== POLICY_ID_LENGTH && bytes !== "") {
|
|
1202
1259
|
throw new Error(
|
|
1203
|
-
`Invalid policy id for [${bytes}] - should be ${POLICY_ID_LENGTH} bytes long or empty string for lovelace`
|
|
1260
|
+
`Invalid policy id for [${bytes}] - should be ${POLICY_ID_LENGTH / 2} bytes (${POLICY_ID_LENGTH} hex length) long or empty string for lovelace`
|
|
1204
1261
|
);
|
|
1205
1262
|
}
|
|
1206
1263
|
return byteString(bytes);
|
|
@@ -1232,7 +1289,9 @@ var posixTime = (int) => ({ int });
|
|
|
1232
1289
|
var dict = (itemsMap) => ({
|
|
1233
1290
|
map: itemsMap.map(([k, v]) => ({ k, v }))
|
|
1234
1291
|
});
|
|
1235
|
-
var tuple = (
|
|
1292
|
+
var tuple = (...args) => ({
|
|
1293
|
+
list: args
|
|
1294
|
+
});
|
|
1236
1295
|
var option = (value2) => {
|
|
1237
1296
|
if (!value2) {
|
|
1238
1297
|
return none();
|
|
@@ -1243,32 +1302,62 @@ var some = (value2) => conStr0([value2]);
|
|
|
1243
1302
|
var none = () => conStr1([]);
|
|
1244
1303
|
|
|
1245
1304
|
// src/data/json/credentials.ts
|
|
1305
|
+
var verificationKey = (bytes) => conStr0([pubKeyHash(bytes)]);
|
|
1306
|
+
var script = (bytes) => conStr1([scriptHash(bytes)]);
|
|
1246
1307
|
var maybeStakingHash = (stakeCredential, isStakeScriptCredential = false) => {
|
|
1247
1308
|
if (stakeCredential === "") {
|
|
1248
1309
|
return conStr1([]);
|
|
1249
1310
|
}
|
|
1250
1311
|
if (isStakeScriptCredential) {
|
|
1251
|
-
return conStr0([
|
|
1252
|
-
conStr0([conStr1([scriptHash(stakeCredential)])])
|
|
1253
|
-
]);
|
|
1312
|
+
return conStr0([conStr0([script(stakeCredential)])]);
|
|
1254
1313
|
}
|
|
1255
|
-
return conStr0([
|
|
1256
|
-
conStr0([conStr0([pubKeyHash(stakeCredential)])])
|
|
1257
|
-
]);
|
|
1314
|
+
return conStr0([conStr0([verificationKey(stakeCredential)])]);
|
|
1258
1315
|
};
|
|
1259
1316
|
var pubKeyAddress = (bytes, stakeCredential, isStakeScriptCredential = false) => conStr0([
|
|
1260
1317
|
conStr0([pubKeyHash(bytes)]),
|
|
1261
1318
|
maybeStakingHash(stakeCredential || "", isStakeScriptCredential)
|
|
1262
1319
|
]);
|
|
1263
1320
|
var scriptAddress = (bytes, stakeCredential, isStakeScriptCredential = false) => conStr0([
|
|
1264
|
-
|
|
1321
|
+
script(bytes),
|
|
1265
1322
|
maybeStakingHash(stakeCredential || "", isStakeScriptCredential)
|
|
1266
1323
|
]);
|
|
1324
|
+
var credential = (hash, isScriptCredential = false) => isScriptCredential ? script(hash) : verificationKey(hash);
|
|
1325
|
+
|
|
1326
|
+
// src/data/json/mpf.ts
|
|
1327
|
+
var jsonProofToPlutusData = (proof) => {
|
|
1328
|
+
const proofSteps = [];
|
|
1329
|
+
const proofJson = proof;
|
|
1330
|
+
proofJson.forEach((proof2) => {
|
|
1331
|
+
const skip = integer(proof2.skip);
|
|
1332
|
+
switch (proof2.type) {
|
|
1333
|
+
case "branch":
|
|
1334
|
+
proofSteps.push(
|
|
1335
|
+
conStr0([skip, byteString(proof2.neighbors.toString("hex"))])
|
|
1336
|
+
);
|
|
1337
|
+
break;
|
|
1338
|
+
case "fork":
|
|
1339
|
+
const { prefix, nibble, root } = proof2.neighbor;
|
|
1340
|
+
const neighbor = conStr0([
|
|
1341
|
+
integer(nibble),
|
|
1342
|
+
byteString(prefix.toString("hex")),
|
|
1343
|
+
byteString(root.toString("hex"))
|
|
1344
|
+
]);
|
|
1345
|
+
proofSteps.push(conStr1([skip, neighbor]));
|
|
1346
|
+
break;
|
|
1347
|
+
case "leaf":
|
|
1348
|
+
const { key, value: value2 } = proof2.neighbor;
|
|
1349
|
+
proofSteps.push(conStr2([skip, byteString(key), byteString(value2)]));
|
|
1350
|
+
break;
|
|
1351
|
+
}
|
|
1352
|
+
});
|
|
1353
|
+
return proofSteps;
|
|
1354
|
+
};
|
|
1267
1355
|
|
|
1268
1356
|
// src/data/parser.ts
|
|
1269
1357
|
var bytesToHex = (bytes) => Buffer.from(bytes).toString("hex");
|
|
1270
1358
|
var hexToBytes = (hex) => Buffer.from(hex, "hex");
|
|
1271
1359
|
var stringToHex = (str) => Buffer.from(str, "utf8").toString("hex");
|
|
1360
|
+
var isHexString = (hex) => /^[0-9A-F]*$/i.test(hex);
|
|
1272
1361
|
var hexToString = (hex) => Buffer.from(hex, "hex").toString("utf8");
|
|
1273
1362
|
var toBytes = (hex) => {
|
|
1274
1363
|
if (hex.length % 2 === 0 && /^[0-9A-F]*$/i.test(hex))
|
|
@@ -1449,8 +1538,8 @@ var BigNum = class _BigNum {
|
|
|
1449
1538
|
// src/utils/data-hash.ts
|
|
1450
1539
|
var import_blakejs = require("blakejs");
|
|
1451
1540
|
var hashDrepAnchor = (jsonLD) => {
|
|
1452
|
-
const jsonHash = (0, import_blakejs.
|
|
1453
|
-
return jsonHash;
|
|
1541
|
+
const jsonHash = (0, import_blakejs.blake2b)(JSON.stringify(jsonLD, null, 2), void 0, 32);
|
|
1542
|
+
return Buffer.from(jsonHash).toString("hex");
|
|
1454
1543
|
};
|
|
1455
1544
|
|
|
1456
1545
|
// src/utils/file.ts
|
|
@@ -1563,6 +1652,23 @@ var MeshValue = class _MeshValue {
|
|
|
1563
1652
|
get = (unit) => {
|
|
1564
1653
|
return this.value[unit] ? BigInt(this.value[unit]) : BigInt(0);
|
|
1565
1654
|
};
|
|
1655
|
+
/**
|
|
1656
|
+
* Get all assets that belong to a specific policy ID
|
|
1657
|
+
* @param policyId The policy ID to filter by
|
|
1658
|
+
* @returns Array of assets that match the policy ID
|
|
1659
|
+
*/
|
|
1660
|
+
getPolicyAssets = (policyId2) => {
|
|
1661
|
+
const assets = [];
|
|
1662
|
+
Object.entries(this.value).forEach(([unit, quantity]) => {
|
|
1663
|
+
if (unit.startsWith(policyId2)) {
|
|
1664
|
+
assets.push({
|
|
1665
|
+
unit,
|
|
1666
|
+
quantity: quantity.toString()
|
|
1667
|
+
});
|
|
1668
|
+
}
|
|
1669
|
+
});
|
|
1670
|
+
return assets;
|
|
1671
|
+
};
|
|
1566
1672
|
/**
|
|
1567
1673
|
* Get all asset units
|
|
1568
1674
|
* @returns The asset units
|
|
@@ -1610,6 +1716,26 @@ var MeshValue = class _MeshValue {
|
|
|
1610
1716
|
}
|
|
1611
1717
|
return BigInt(this.value[unit]) <= BigInt(other.value[unit]);
|
|
1612
1718
|
};
|
|
1719
|
+
/**
|
|
1720
|
+
* Check if the value is equal to another value
|
|
1721
|
+
* @param other - The value to compare against
|
|
1722
|
+
* @returns boolean
|
|
1723
|
+
*/
|
|
1724
|
+
eq = (other) => {
|
|
1725
|
+
return Object.keys(this.value).every((key) => this.eqUnit(key, other));
|
|
1726
|
+
};
|
|
1727
|
+
/**
|
|
1728
|
+
* Check if the specific unit of value is equal to that unit of another value
|
|
1729
|
+
* @param unit - The unit to compare
|
|
1730
|
+
* @param other - The value to compare against
|
|
1731
|
+
* @returns boolean
|
|
1732
|
+
*/
|
|
1733
|
+
eqUnit = (unit, other) => {
|
|
1734
|
+
if (this.value[unit] === void 0 || other.value[unit] === void 0) {
|
|
1735
|
+
return false;
|
|
1736
|
+
}
|
|
1737
|
+
return BigInt(this.value[unit]) === BigInt(other.value[unit]);
|
|
1738
|
+
};
|
|
1613
1739
|
/**
|
|
1614
1740
|
* Check if the value is empty
|
|
1615
1741
|
* @returns boolean
|
|
@@ -1712,7 +1838,7 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
|
|
|
1712
1838
|
const selectedInputs = /* @__PURE__ */ new Set();
|
|
1713
1839
|
const onlyLovelace = /* @__PURE__ */ new Set();
|
|
1714
1840
|
const singletons = /* @__PURE__ */ new Set();
|
|
1715
|
-
const
|
|
1841
|
+
const pairs2 = /* @__PURE__ */ new Set();
|
|
1716
1842
|
const rest = /* @__PURE__ */ new Set();
|
|
1717
1843
|
const collaterals = /* @__PURE__ */ new Set();
|
|
1718
1844
|
for (let i = 0; i < inputs.length; i++) {
|
|
@@ -1731,7 +1857,7 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
|
|
|
1731
1857
|
break;
|
|
1732
1858
|
}
|
|
1733
1859
|
case 3: {
|
|
1734
|
-
|
|
1860
|
+
pairs2.add(i);
|
|
1735
1861
|
break;
|
|
1736
1862
|
}
|
|
1737
1863
|
default: {
|
|
@@ -1764,10 +1890,10 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
|
|
|
1764
1890
|
if (!assetRequired || Number(assetRequired) <= 0) break;
|
|
1765
1891
|
addUtxoWithAssetAmount(inputIndex, assetUnit, singletons);
|
|
1766
1892
|
}
|
|
1767
|
-
for (const inputIndex of
|
|
1893
|
+
for (const inputIndex of pairs2) {
|
|
1768
1894
|
const assetRequired = totalRequiredAssets.get(assetUnit);
|
|
1769
1895
|
if (!assetRequired || Number(assetRequired) <= 0) break;
|
|
1770
|
-
addUtxoWithAssetAmount(inputIndex, assetUnit,
|
|
1896
|
+
addUtxoWithAssetAmount(inputIndex, assetUnit, pairs2);
|
|
1771
1897
|
}
|
|
1772
1898
|
for (const inputIndex of rest) {
|
|
1773
1899
|
const assetRequired = totalRequiredAssets.get(assetUnit);
|
|
@@ -1785,10 +1911,10 @@ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
|
|
|
1785
1911
|
if (!assetRequired || Number(assetRequired) <= 0) break;
|
|
1786
1912
|
addUtxoWithAssetAmount(inputIndex, "lovelace", singletons);
|
|
1787
1913
|
}
|
|
1788
|
-
for (const inputIndex of
|
|
1914
|
+
for (const inputIndex of pairs2) {
|
|
1789
1915
|
const assetRequired = totalRequiredAssets.get("lovelace");
|
|
1790
1916
|
if (!assetRequired || Number(assetRequired) <= 0) break;
|
|
1791
|
-
addUtxoWithAssetAmount(inputIndex, "lovelace",
|
|
1917
|
+
addUtxoWithAssetAmount(inputIndex, "lovelace", pairs2);
|
|
1792
1918
|
}
|
|
1793
1919
|
for (const inputIndex of rest) {
|
|
1794
1920
|
const assetRequired = totalRequiredAssets.get("lovelace");
|
|
@@ -1963,6 +2089,473 @@ var UtxoSelection = class {
|
|
|
1963
2089
|
}
|
|
1964
2090
|
};
|
|
1965
2091
|
|
|
2092
|
+
// src/tx-tester/index.ts
|
|
2093
|
+
var TxTester = class {
|
|
2094
|
+
txBody;
|
|
2095
|
+
inputsEvaluating;
|
|
2096
|
+
outputsEvaluating;
|
|
2097
|
+
traces;
|
|
2098
|
+
/**
|
|
2099
|
+
* Create a new TxTester instance
|
|
2100
|
+
* @param txBody The transaction builder body
|
|
2101
|
+
*/
|
|
2102
|
+
constructor(txBody) {
|
|
2103
|
+
this.txBody = { ...txBody };
|
|
2104
|
+
this.inputsEvaluating = [];
|
|
2105
|
+
this.outputsEvaluating = [];
|
|
2106
|
+
this.traces = [];
|
|
2107
|
+
}
|
|
2108
|
+
/**
|
|
2109
|
+
* Add a trace to the TxTester
|
|
2110
|
+
* @param funcName The function name where the error occurred
|
|
2111
|
+
* @param message The error message
|
|
2112
|
+
*/
|
|
2113
|
+
addTrace(funcName, message) {
|
|
2114
|
+
const msg = `[Error - ${funcName}]: ${message}`;
|
|
2115
|
+
this.traces.push(msg);
|
|
2116
|
+
}
|
|
2117
|
+
/**
|
|
2118
|
+
* Check if the transaction evaluation was successful
|
|
2119
|
+
* @returns true if there are no errors, false otherwise
|
|
2120
|
+
*/
|
|
2121
|
+
success() {
|
|
2122
|
+
return this.traces.length === 0;
|
|
2123
|
+
}
|
|
2124
|
+
/**
|
|
2125
|
+
* Get the error messages if any
|
|
2126
|
+
* @returns A string representation of the errors or "No errors" if there are none
|
|
2127
|
+
*/
|
|
2128
|
+
errors() {
|
|
2129
|
+
if (this.traces.length > 0) {
|
|
2130
|
+
return `${this.traces}`;
|
|
2131
|
+
} else {
|
|
2132
|
+
return "No errors";
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
2135
|
+
/**
|
|
2136
|
+
* Checks if the transaction is valid after a specified timestamp.
|
|
2137
|
+
* @param requiredTimestamp The timestamp after which the transaction should be valid
|
|
2138
|
+
* @returns The TxTester instance for chaining
|
|
2139
|
+
*/
|
|
2140
|
+
validAfter = (requiredTimestamp) => {
|
|
2141
|
+
const invalidBefore = this.txBody.validityRange?.invalidHereafter ? this.txBody.validityRange.invalidHereafter : 9999999999999;
|
|
2142
|
+
const isValidAfter = this.txBody.validityRange?.invalidBefore ? this.txBody.validityRange.invalidBefore < requiredTimestamp : true;
|
|
2143
|
+
if (!isValidAfter) {
|
|
2144
|
+
this.addTrace(
|
|
2145
|
+
"validAfter",
|
|
2146
|
+
`tx invalid before ${invalidBefore}, with requiredTimestamp ${requiredTimestamp}`
|
|
2147
|
+
);
|
|
2148
|
+
}
|
|
2149
|
+
return this;
|
|
2150
|
+
};
|
|
2151
|
+
/**
|
|
2152
|
+
* Checks if the transaction is valid before a specified timestamp.
|
|
2153
|
+
* @param requiredTimestamp The timestamp before which the transaction should be valid
|
|
2154
|
+
* @returns The TxTester instance for chaining
|
|
2155
|
+
*/
|
|
2156
|
+
validBefore = (requiredTimestamp) => {
|
|
2157
|
+
const invalidHereafter = this.txBody.validityRange?.invalidBefore ? this.txBody.validityRange.invalidBefore : 0;
|
|
2158
|
+
const isValidBefore = this.txBody.validityRange?.invalidHereafter ? this.txBody.validityRange.invalidHereafter > requiredTimestamp : true;
|
|
2159
|
+
if (!isValidBefore) {
|
|
2160
|
+
this.addTrace(
|
|
2161
|
+
"validBefore",
|
|
2162
|
+
`tx invalid after ${invalidHereafter}, with requiredTimestamp ${requiredTimestamp}`
|
|
2163
|
+
);
|
|
2164
|
+
}
|
|
2165
|
+
return this;
|
|
2166
|
+
};
|
|
2167
|
+
// Extra Signatories Methods
|
|
2168
|
+
/**
|
|
2169
|
+
* Checks if a specific key is signed in the transaction.
|
|
2170
|
+
* @param keyHash The key hash to check
|
|
2171
|
+
* @returns The TxTester instance for chaining
|
|
2172
|
+
*/
|
|
2173
|
+
keySigned = (keyHash) => {
|
|
2174
|
+
const isKeySigned = keySignedLogic(this.txBody.requiredSignatures, keyHash);
|
|
2175
|
+
if (!isKeySigned) {
|
|
2176
|
+
this.addTrace("keySigned", `tx does not have key ${keyHash} signed`);
|
|
2177
|
+
}
|
|
2178
|
+
return this;
|
|
2179
|
+
};
|
|
2180
|
+
/**
|
|
2181
|
+
* Checks if any one of the specified keys is signed in the transaction.
|
|
2182
|
+
* @param keyHashes The array of key hashes to check
|
|
2183
|
+
* @returns The TxTester instance for chaining
|
|
2184
|
+
*/
|
|
2185
|
+
oneOfKeysSigned = (keyHashes) => {
|
|
2186
|
+
const isOneOfKeysSigned = keyHashes.some(
|
|
2187
|
+
(keyHash) => keySignedLogic(this.txBody.requiredSignatures, keyHash)
|
|
2188
|
+
);
|
|
2189
|
+
if (!isOneOfKeysSigned) {
|
|
2190
|
+
this.addTrace(
|
|
2191
|
+
"oneOfKeysSigned",
|
|
2192
|
+
`tx does not have any of the keys signed: ${keyHashes.join(", ")}`
|
|
2193
|
+
);
|
|
2194
|
+
}
|
|
2195
|
+
return this;
|
|
2196
|
+
};
|
|
2197
|
+
/**
|
|
2198
|
+
* Checks if all specified keys are signed in the transaction.
|
|
2199
|
+
* @param keyHashes The array of key hashes to check
|
|
2200
|
+
* @returns The TxTester instance for chaining
|
|
2201
|
+
*/
|
|
2202
|
+
allKeysSigned = (keyHashes) => {
|
|
2203
|
+
const missingKeys = [];
|
|
2204
|
+
const isAllKeysSigned = keyHashes.every((keyHash) => {
|
|
2205
|
+
const isKeySigned = keySignedLogic(
|
|
2206
|
+
this.txBody.requiredSignatures,
|
|
2207
|
+
keyHash
|
|
2208
|
+
);
|
|
2209
|
+
if (!isKeySigned) {
|
|
2210
|
+
missingKeys.push(keyHash);
|
|
2211
|
+
}
|
|
2212
|
+
return isKeySigned;
|
|
2213
|
+
});
|
|
2214
|
+
if (!isAllKeysSigned) {
|
|
2215
|
+
this.addTrace(
|
|
2216
|
+
"allKeysSigned",
|
|
2217
|
+
`tx does not have all keys signed: ${missingKeys.join(", ")}`
|
|
2218
|
+
);
|
|
2219
|
+
}
|
|
2220
|
+
return this;
|
|
2221
|
+
};
|
|
2222
|
+
/**
|
|
2223
|
+
* Checks if a specific token is minted in the transaction.
|
|
2224
|
+
* @param policyId The policy ID of the token
|
|
2225
|
+
* @param assetName The asset name of the token
|
|
2226
|
+
* @param quantity The quantity of the token
|
|
2227
|
+
* @returns The TxTester instance for chaining
|
|
2228
|
+
*/
|
|
2229
|
+
tokenMinted = (policyId2, assetName2, quantity) => {
|
|
2230
|
+
const isTokenMinted = tokenMintedLogic(
|
|
2231
|
+
this.txBody.mints,
|
|
2232
|
+
policyId2,
|
|
2233
|
+
assetName2,
|
|
2234
|
+
quantity
|
|
2235
|
+
);
|
|
2236
|
+
if (!isTokenMinted) {
|
|
2237
|
+
this.addTrace(
|
|
2238
|
+
"tokenMinted",
|
|
2239
|
+
`Token with policy_id: ${policyId2}, asset_name: ${assetName2}, quantity: ${quantity} not found in mints.`
|
|
2240
|
+
);
|
|
2241
|
+
}
|
|
2242
|
+
return this;
|
|
2243
|
+
};
|
|
2244
|
+
/**
|
|
2245
|
+
* Checks if a specific token is minted in the transaction and that it is the only mint.
|
|
2246
|
+
* @param policyId The policy ID of the token
|
|
2247
|
+
* @param assetName The asset name of the token
|
|
2248
|
+
* @param quantity The quantity of the token
|
|
2249
|
+
* @returns The TxTester instance for chaining
|
|
2250
|
+
*/
|
|
2251
|
+
onlyTokenMinted = (policyId2, assetName2, quantity) => {
|
|
2252
|
+
const isTokenMinted = tokenMintedLogic(
|
|
2253
|
+
this.txBody.mints,
|
|
2254
|
+
policyId2,
|
|
2255
|
+
assetName2,
|
|
2256
|
+
quantity
|
|
2257
|
+
);
|
|
2258
|
+
const isOnlyOneMint = this.txBody.mints?.length === 1;
|
|
2259
|
+
if (!isTokenMinted) {
|
|
2260
|
+
this.addTrace(
|
|
2261
|
+
"onlyTokenMinted",
|
|
2262
|
+
`Token with policy_id: ${policyId2}, asset_name: ${assetName2}, quantity: ${quantity} not found in mints`
|
|
2263
|
+
);
|
|
2264
|
+
}
|
|
2265
|
+
if (!isOnlyOneMint) {
|
|
2266
|
+
this.addTrace(
|
|
2267
|
+
"onlyTokenMinted",
|
|
2268
|
+
`Expected only one mint, but found ${this.txBody.mints?.length || 0} mints.`
|
|
2269
|
+
);
|
|
2270
|
+
}
|
|
2271
|
+
return this;
|
|
2272
|
+
};
|
|
2273
|
+
/**
|
|
2274
|
+
* Checks if a specific token is minted in the transaction, ensuring that it is the only mint for the given policy ID.
|
|
2275
|
+
* @param policyId The policy ID of the token
|
|
2276
|
+
* @param assetName The asset name of the token
|
|
2277
|
+
* @param quantity The quantity of the token
|
|
2278
|
+
* @returns The TxTester instance for chaining
|
|
2279
|
+
*/
|
|
2280
|
+
policyOnlyMintedToken = (policyId2, assetName2, quantity) => {
|
|
2281
|
+
const filteredMints = this.txBody.mints?.filter((token) => {
|
|
2282
|
+
return token.policyId === policyId2;
|
|
2283
|
+
}) || [];
|
|
2284
|
+
const isTokenMinted = tokenMintedLogic(
|
|
2285
|
+
this.txBody.mints,
|
|
2286
|
+
policyId2,
|
|
2287
|
+
assetName2,
|
|
2288
|
+
quantity
|
|
2289
|
+
);
|
|
2290
|
+
const isOnlyOneMint = filteredMints.length === 1;
|
|
2291
|
+
if (!isOnlyOneMint) {
|
|
2292
|
+
this.addTrace(
|
|
2293
|
+
"policyOnlyMintedToken",
|
|
2294
|
+
`Expected only one mint for policy_id: ${policyId2}, but found ${filteredMints.length} mints.`
|
|
2295
|
+
);
|
|
2296
|
+
}
|
|
2297
|
+
if (!isTokenMinted) {
|
|
2298
|
+
this.addTrace(
|
|
2299
|
+
"policyOnlyMintedToken",
|
|
2300
|
+
`Token with policy_id: ${policyId2}, asset_name: ${assetName2}, quantity: ${quantity} not found in mints.`
|
|
2301
|
+
);
|
|
2302
|
+
}
|
|
2303
|
+
return this;
|
|
2304
|
+
};
|
|
2305
|
+
/**
|
|
2306
|
+
* Checks if a specific policy ID is burned in the transaction, ensuring that it is the only minting (i.e. burning item).
|
|
2307
|
+
* @param policyId The policy ID to check
|
|
2308
|
+
* @returns true if the policy is the only burn, false otherwise
|
|
2309
|
+
*/
|
|
2310
|
+
checkPolicyOnlyBurn = (policyId2) => {
|
|
2311
|
+
const filteredMints = this.txBody.mints?.filter((token) => {
|
|
2312
|
+
return token.policyId === policyId2 && token.mintValue.findIndex((m) => BigInt(m.amount) > 0) >= 0;
|
|
2313
|
+
}) || [];
|
|
2314
|
+
return filteredMints.length === 0;
|
|
2315
|
+
};
|
|
2316
|
+
/**
|
|
2317
|
+
* Not apply filter to inputs
|
|
2318
|
+
* @returns The TxTester instance for chaining
|
|
2319
|
+
*/
|
|
2320
|
+
allInputs = () => {
|
|
2321
|
+
this.inputsEvaluating = this.txBody.inputs?.slice() || [];
|
|
2322
|
+
return this;
|
|
2323
|
+
};
|
|
2324
|
+
/**
|
|
2325
|
+
* Filter inputs by address
|
|
2326
|
+
* @param address The address to filter by
|
|
2327
|
+
* @returns The TxTester instance for chaining
|
|
2328
|
+
*/
|
|
2329
|
+
inputsAt = (address) => {
|
|
2330
|
+
this.inputsEvaluating = this.txBody.inputs?.filter(
|
|
2331
|
+
(input) => txInToUtxo(input.txIn).output.address === address
|
|
2332
|
+
) || [];
|
|
2333
|
+
return this;
|
|
2334
|
+
};
|
|
2335
|
+
/**
|
|
2336
|
+
* Filter inputs by unit
|
|
2337
|
+
* @param unit The unit to filter by
|
|
2338
|
+
* @returns The TxTester instance for chaining
|
|
2339
|
+
*/
|
|
2340
|
+
inputsWith = (unit) => {
|
|
2341
|
+
this.inputsEvaluating = this.txBody.inputs?.filter((input) => {
|
|
2342
|
+
const inputValue = MeshValue.fromAssets(
|
|
2343
|
+
txInToUtxo(input.txIn).output.amount
|
|
2344
|
+
);
|
|
2345
|
+
const quantity = inputValue.get(unit);
|
|
2346
|
+
return quantity > 0;
|
|
2347
|
+
}) || [];
|
|
2348
|
+
return this;
|
|
2349
|
+
};
|
|
2350
|
+
/**
|
|
2351
|
+
* Filter inputs by policy ID
|
|
2352
|
+
* @param policyId The policy ID to filter by
|
|
2353
|
+
* @returns The TxTester instance for chaining
|
|
2354
|
+
*/
|
|
2355
|
+
inputsWithPolicy = (policyId2) => {
|
|
2356
|
+
this.inputsEvaluating = this.txBody.inputs?.filter((input) => {
|
|
2357
|
+
const inputValue = MeshValue.fromAssets(
|
|
2358
|
+
txInToUtxo(input.txIn).output.amount
|
|
2359
|
+
);
|
|
2360
|
+
const assets = inputValue.getPolicyAssets(policyId2);
|
|
2361
|
+
return assets.length > 0;
|
|
2362
|
+
}) || [];
|
|
2363
|
+
return this;
|
|
2364
|
+
};
|
|
2365
|
+
/**
|
|
2366
|
+
* Filter inputs by address and policy ID
|
|
2367
|
+
* @param address The address to filter by
|
|
2368
|
+
* @param policyId The policy ID to filter by
|
|
2369
|
+
* @returns The TxTester instance for chaining
|
|
2370
|
+
*/
|
|
2371
|
+
inputsAtWithPolicy = (address, policyId2) => {
|
|
2372
|
+
this.inputsEvaluating = this.txBody.inputs?.filter((input) => {
|
|
2373
|
+
const utxo = txInToUtxo(input.txIn);
|
|
2374
|
+
const inputValue = MeshValue.fromAssets(utxo.output.amount);
|
|
2375
|
+
const assets = inputValue.getPolicyAssets(policyId2);
|
|
2376
|
+
return utxo.output.address === address && assets.length > 0;
|
|
2377
|
+
}) || [];
|
|
2378
|
+
return this;
|
|
2379
|
+
};
|
|
2380
|
+
/**
|
|
2381
|
+
* Filter inputs by address and unit
|
|
2382
|
+
* @param address The address to filter by
|
|
2383
|
+
* @param unit The unit to filter by
|
|
2384
|
+
* @returns The TxTester instance for chaining
|
|
2385
|
+
*/
|
|
2386
|
+
inputsAtWith = (address, unit) => {
|
|
2387
|
+
this.inputsEvaluating = this.txBody.inputs?.filter((input) => {
|
|
2388
|
+
const utxo = txInToUtxo(input.txIn);
|
|
2389
|
+
const inputValue = MeshValue.fromAssets(utxo.output.amount);
|
|
2390
|
+
const quantity = inputValue.get(unit);
|
|
2391
|
+
return utxo.output.address === address && quantity > 0;
|
|
2392
|
+
}) || [];
|
|
2393
|
+
return this;
|
|
2394
|
+
};
|
|
2395
|
+
/**
|
|
2396
|
+
* Check if inputs contain the expected value.
|
|
2397
|
+
* *Reminder - It must be called after filtering methods for inputs*
|
|
2398
|
+
* @param expectedValue The expected value
|
|
2399
|
+
* @returns The TxTester instance for chaining
|
|
2400
|
+
*/
|
|
2401
|
+
inputsValue = (expectedValue) => {
|
|
2402
|
+
let value2 = new MeshValue();
|
|
2403
|
+
this.inputsEvaluating.forEach((input) => {
|
|
2404
|
+
const utxo = txInToUtxo(input.txIn);
|
|
2405
|
+
value2.addAssets(utxo.output.amount);
|
|
2406
|
+
});
|
|
2407
|
+
const isValueCorrect = value2.eq(expectedValue);
|
|
2408
|
+
if (!isValueCorrect) {
|
|
2409
|
+
this.addTrace(
|
|
2410
|
+
"inputsValue",
|
|
2411
|
+
`inputs ${JSON.stringify(this.inputsEvaluating)} have value ${JSON.stringify(value2)}, expect ${JSON.stringify(expectedValue)}`
|
|
2412
|
+
);
|
|
2413
|
+
}
|
|
2414
|
+
return this;
|
|
2415
|
+
};
|
|
2416
|
+
// /**
|
|
2417
|
+
// * Check if inputs contain a specific inline datum.
|
|
2418
|
+
// * *Reminder - It must be called after filtering methods for inputs*
|
|
2419
|
+
// * @param datumCbor The datum CBOR to check
|
|
2420
|
+
// * @returns The TxTester instance for chaining
|
|
2421
|
+
// */
|
|
2422
|
+
// inputsInlineDatumExist = (datumCbor: string): this => {
|
|
2423
|
+
// const inputsWithInlineDatum = this.inputsEvaluating.filter((input) => {
|
|
2424
|
+
// const utxo = txInToUtxo(input.txIn);
|
|
2425
|
+
// return utxo.output.plutusData === datumCbor;
|
|
2426
|
+
// });
|
|
2427
|
+
// if (inputsWithInlineDatum.length === 0) {
|
|
2428
|
+
// this.addTrace(
|
|
2429
|
+
// "inputsInlineDatumExist",
|
|
2430
|
+
// `No inputs with inline datum matching: ${datumCbor}`,
|
|
2431
|
+
// );
|
|
2432
|
+
// }
|
|
2433
|
+
// return this;
|
|
2434
|
+
// };
|
|
2435
|
+
/**
|
|
2436
|
+
* Not apply filter to outputs
|
|
2437
|
+
* @returns The TxTester instance for chaining
|
|
2438
|
+
*/
|
|
2439
|
+
allOutputs = () => {
|
|
2440
|
+
this.outputsEvaluating = this.txBody.outputs?.slice() || [];
|
|
2441
|
+
return this;
|
|
2442
|
+
};
|
|
2443
|
+
/**
|
|
2444
|
+
* Filter outputs by address
|
|
2445
|
+
* @param address The address to filter by
|
|
2446
|
+
* @returns The TxTester instance for chaining
|
|
2447
|
+
*/
|
|
2448
|
+
outputsAt = (address) => {
|
|
2449
|
+
this.outputsEvaluating = this.txBody.outputs?.filter((output) => output.address === address) || [];
|
|
2450
|
+
return this;
|
|
2451
|
+
};
|
|
2452
|
+
/**
|
|
2453
|
+
* Filter outputs by unit
|
|
2454
|
+
* @param unit The unit to filter by
|
|
2455
|
+
* @returns The TxTester instance for chaining
|
|
2456
|
+
*/
|
|
2457
|
+
outputsWith = (unit) => {
|
|
2458
|
+
this.outputsEvaluating = this.txBody.outputs?.filter((output) => {
|
|
2459
|
+
const outputValue = MeshValue.fromAssets(output.amount);
|
|
2460
|
+
const quantity = outputValue.get(unit);
|
|
2461
|
+
return quantity > 0;
|
|
2462
|
+
}) || [];
|
|
2463
|
+
return this;
|
|
2464
|
+
};
|
|
2465
|
+
/**
|
|
2466
|
+
* Filter outputs by policy ID
|
|
2467
|
+
* @param policyId The policy ID to filter by
|
|
2468
|
+
* @returns The TxTester instance for chaining
|
|
2469
|
+
*/
|
|
2470
|
+
outputsWithPolicy = (policyId2) => {
|
|
2471
|
+
this.outputsEvaluating = this.txBody.outputs?.filter((output) => {
|
|
2472
|
+
const outputValue = MeshValue.fromAssets(output.amount);
|
|
2473
|
+
const assets = outputValue.getPolicyAssets(policyId2);
|
|
2474
|
+
return assets.length > 0;
|
|
2475
|
+
}) || [];
|
|
2476
|
+
return this;
|
|
2477
|
+
};
|
|
2478
|
+
/**
|
|
2479
|
+
* Filter outputs by address and policy ID
|
|
2480
|
+
* @param address The address to filter by
|
|
2481
|
+
* @param policyId The policy ID to filter by
|
|
2482
|
+
* @returns The TxTester instance for chaining
|
|
2483
|
+
*/
|
|
2484
|
+
outputsAtWithPolicy = (address, policyId2) => {
|
|
2485
|
+
this.outputsEvaluating = this.txBody.outputs?.filter((output) => {
|
|
2486
|
+
const outputValue = MeshValue.fromAssets(output.amount);
|
|
2487
|
+
const assets = outputValue.getPolicyAssets(policyId2);
|
|
2488
|
+
return output.address === address && assets.length > 0;
|
|
2489
|
+
}) || [];
|
|
2490
|
+
return this;
|
|
2491
|
+
};
|
|
2492
|
+
/**
|
|
2493
|
+
* Filter outputs by address and unit
|
|
2494
|
+
* @param address The address to filter by
|
|
2495
|
+
* @param unit The unit to filter by
|
|
2496
|
+
* @returns The TxTester instance for chaining
|
|
2497
|
+
*/
|
|
2498
|
+
outputsAtWith = (address, unit) => {
|
|
2499
|
+
this.outputsEvaluating = this.txBody.outputs?.filter((output) => {
|
|
2500
|
+
const outputValue = MeshValue.fromAssets(output.amount);
|
|
2501
|
+
const quantity = outputValue.get(unit);
|
|
2502
|
+
return output.address === address && quantity > 0;
|
|
2503
|
+
}) || [];
|
|
2504
|
+
return this;
|
|
2505
|
+
};
|
|
2506
|
+
/**
|
|
2507
|
+
* Check if outputs contain the expected value.
|
|
2508
|
+
* *Reminder - It must be called after filtering methods for outputs*
|
|
2509
|
+
* @param expectedValue The expected value
|
|
2510
|
+
* @returns The TxTester instance for chaining
|
|
2511
|
+
*/
|
|
2512
|
+
outputsValue = (expectedValue) => {
|
|
2513
|
+
let value2 = new MeshValue();
|
|
2514
|
+
this.outputsEvaluating.forEach((output) => {
|
|
2515
|
+
value2.addAssets(output.amount);
|
|
2516
|
+
});
|
|
2517
|
+
const isValueCorrect = value2.eq(expectedValue);
|
|
2518
|
+
if (!isValueCorrect) {
|
|
2519
|
+
this.addTrace(
|
|
2520
|
+
"outputsValue",
|
|
2521
|
+
`tx outputs ${JSON.stringify(this.outputsEvaluating)} have value ${JSON.stringify(value2)}, expected ${JSON.stringify(expectedValue)}`
|
|
2522
|
+
);
|
|
2523
|
+
}
|
|
2524
|
+
return this;
|
|
2525
|
+
};
|
|
2526
|
+
/**
|
|
2527
|
+
* Check if outputs contain a specific inline datum.
|
|
2528
|
+
* *Reminder - It must be called after filtering methods for outputs*
|
|
2529
|
+
* @param datumCbor The datum CBOR to check
|
|
2530
|
+
* @returns The TxTester instance for chaining
|
|
2531
|
+
*/
|
|
2532
|
+
outputsInlineDatumExist = (datumCbor) => {
|
|
2533
|
+
const outputsWithInlineDatum = this.outputsEvaluating.filter((output) => {
|
|
2534
|
+
if (output.datum && output.datum.type === "Inline") {
|
|
2535
|
+
return output.datum.data.content === datumCbor;
|
|
2536
|
+
}
|
|
2537
|
+
return false;
|
|
2538
|
+
});
|
|
2539
|
+
if (outputsWithInlineDatum.length === 0) {
|
|
2540
|
+
this.addTrace(
|
|
2541
|
+
"outputs_inline_datum_exist",
|
|
2542
|
+
`No outputs with inline datum matching: ${datumCbor}`
|
|
2543
|
+
);
|
|
2544
|
+
}
|
|
2545
|
+
return this;
|
|
2546
|
+
};
|
|
2547
|
+
};
|
|
2548
|
+
function keySignedLogic(requiredSignatures, keyHash) {
|
|
2549
|
+
return requiredSignatures?.some((signatory) => signatory === keyHash) || false;
|
|
2550
|
+
}
|
|
2551
|
+
function tokenMintedLogic(mints, policyId2, assetName2, quantity) {
|
|
2552
|
+
return mints?.some((token) => {
|
|
2553
|
+
return token.policyId === policyId2 && token.mintValue.findIndex(
|
|
2554
|
+
(m) => m.assetName === assetName2 && BigInt(m.amount) === BigInt(quantity)
|
|
2555
|
+
) >= 0;
|
|
2556
|
+
}) || false;
|
|
2557
|
+
}
|
|
2558
|
+
|
|
1966
2559
|
// src/index.ts
|
|
1967
2560
|
var import_bip39 = require("bip39");
|
|
1968
2561
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1971,6 +2564,7 @@ var import_bip39 = require("bip39");
|
|
|
1971
2564
|
BigNum,
|
|
1972
2565
|
CIP68_100,
|
|
1973
2566
|
CIP68_222,
|
|
2567
|
+
DEFAULT_FETCHER_OPTIONS,
|
|
1974
2568
|
DEFAULT_PROTOCOL_PARAMETERS,
|
|
1975
2569
|
DEFAULT_REDEEMER_BUDGET,
|
|
1976
2570
|
DEFAULT_V1_COST_MODEL_LIST,
|
|
@@ -1988,6 +2582,7 @@ var import_bip39 = require("bip39");
|
|
|
1988
2582
|
SUPPORTED_OGMIOS_LINKS,
|
|
1989
2583
|
SUPPORTED_TOKENS,
|
|
1990
2584
|
SUPPORTED_WALLETS,
|
|
2585
|
+
TxTester,
|
|
1991
2586
|
UtxoSelection,
|
|
1992
2587
|
assetClass,
|
|
1993
2588
|
assetName,
|
|
@@ -1997,11 +2592,13 @@ var import_bip39 = require("bip39");
|
|
|
1997
2592
|
byteString,
|
|
1998
2593
|
bytesToHex,
|
|
1999
2594
|
castProtocol,
|
|
2595
|
+
cloneTxBuilderBody,
|
|
2000
2596
|
conStr,
|
|
2001
2597
|
conStr0,
|
|
2002
2598
|
conStr1,
|
|
2003
2599
|
conStr2,
|
|
2004
2600
|
conStr3,
|
|
2601
|
+
credential,
|
|
2005
2602
|
currencySymbol,
|
|
2006
2603
|
dict,
|
|
2007
2604
|
emptyTxBuilderBody,
|
|
@@ -2015,8 +2612,11 @@ var import_bip39 = require("bip39");
|
|
|
2015
2612
|
hexToBytes,
|
|
2016
2613
|
hexToString,
|
|
2017
2614
|
integer,
|
|
2615
|
+
isHexString,
|
|
2018
2616
|
isNetwork,
|
|
2617
|
+
jsonProofToPlutusData,
|
|
2019
2618
|
keepRelevant,
|
|
2619
|
+
keySignedLogic,
|
|
2020
2620
|
largestFirst,
|
|
2021
2621
|
largestFirstMultiAsset,
|
|
2022
2622
|
list,
|
|
@@ -2027,18 +2627,21 @@ var import_bip39 = require("bip39");
|
|
|
2027
2627
|
mConStr1,
|
|
2028
2628
|
mConStr2,
|
|
2029
2629
|
mConStr3,
|
|
2630
|
+
mCredential,
|
|
2030
2631
|
mMaybeStakingHash,
|
|
2031
2632
|
mNone,
|
|
2032
2633
|
mOption,
|
|
2033
2634
|
mOutputReference,
|
|
2034
2635
|
mPlutusBSArrayToString,
|
|
2035
2636
|
mPubKeyAddress,
|
|
2637
|
+
mScript,
|
|
2036
2638
|
mScriptAddress,
|
|
2037
2639
|
mSome,
|
|
2038
2640
|
mStringToPlutusBSArray,
|
|
2039
2641
|
mTuple,
|
|
2040
2642
|
mTxOutRef,
|
|
2041
2643
|
mValue,
|
|
2644
|
+
mVerificationKey,
|
|
2042
2645
|
maybeStakingHash,
|
|
2043
2646
|
mergeAssets,
|
|
2044
2647
|
metadataStandardKeys,
|
|
@@ -2047,6 +2650,7 @@ var import_bip39 = require("bip39");
|
|
|
2047
2650
|
none,
|
|
2048
2651
|
option,
|
|
2049
2652
|
outputReference,
|
|
2653
|
+
pairs,
|
|
2050
2654
|
parseAssetUnit,
|
|
2051
2655
|
plutusBSArrayToString,
|
|
2052
2656
|
policyId,
|
|
@@ -2059,6 +2663,7 @@ var import_bip39 = require("bip39");
|
|
|
2059
2663
|
resolveSlotNo,
|
|
2060
2664
|
resolveTxFees,
|
|
2061
2665
|
royaltiesStandardKeys,
|
|
2666
|
+
script,
|
|
2062
2667
|
scriptAddress,
|
|
2063
2668
|
scriptHash,
|
|
2064
2669
|
slotToBeginUnixTime,
|
|
@@ -2067,11 +2672,14 @@ var import_bip39 = require("bip39");
|
|
|
2067
2672
|
stringToHex,
|
|
2068
2673
|
toBytes,
|
|
2069
2674
|
toUTF8,
|
|
2675
|
+
tokenMintedLogic,
|
|
2070
2676
|
tokenName,
|
|
2071
2677
|
tuple,
|
|
2072
2678
|
txInToUtxo,
|
|
2073
2679
|
txOutRef,
|
|
2074
2680
|
unixTimeToEnclosingSlot,
|
|
2681
|
+
validityRangeFromObj,
|
|
2075
2682
|
validityRangeToObj,
|
|
2076
|
-
value
|
|
2683
|
+
value,
|
|
2684
|
+
verificationKey
|
|
2077
2685
|
});
|