@meshsdk/core-csl 1.8.13 → 1.9.0-beta-38
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 +284 -151
- package/dist/index.d.cts +20 -12
- package/dist/index.d.ts +20 -12
- package/dist/index.js +283 -150
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -35,8 +35,8 @@ __export(index_exports, {
|
|
|
35
35
|
OfflineEvaluator: () => OfflineEvaluator,
|
|
36
36
|
POLICY_ID_LENGTH: () => POLICY_ID_LENGTH,
|
|
37
37
|
REDEEMER_TAGS: () => REDEEMER_TAGS,
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
addrBech32ToPlutusDataHex: () => addrBech32ToPlutusDataHex,
|
|
39
|
+
addrBech32ToPlutusDataObj: () => addrBech32ToPlutusDataObj,
|
|
40
40
|
applyCborEncoding: () => applyCborEncoding,
|
|
41
41
|
applyParamsToScript: () => applyParamsToScript,
|
|
42
42
|
baseAddressToStakeAddress: () => baseAddressToStakeAddress,
|
|
@@ -72,6 +72,7 @@ __export(index_exports, {
|
|
|
72
72
|
fromUTF8: () => fromUTF8,
|
|
73
73
|
getDRepIds: () => getDRepIds,
|
|
74
74
|
getTransactionInputs: () => getTransactionInputs,
|
|
75
|
+
getTransactionOutputs: () => getTransactionOutputs,
|
|
75
76
|
getV2ScriptHash: () => getV2ScriptHash,
|
|
76
77
|
keyHashToRewardAddress: () => keyHashToRewardAddress,
|
|
77
78
|
meshTxBuilderBodyToObj: () => meshTxBuilderBodyToObj,
|
|
@@ -115,6 +116,7 @@ __export(index_exports, {
|
|
|
115
116
|
toAddress: () => toAddress,
|
|
116
117
|
toBaseAddress: () => toBaseAddress,
|
|
117
118
|
toBytes: () => toBytes,
|
|
119
|
+
toCslValue: () => toCslValue,
|
|
118
120
|
toEnterpriseAddress: () => toEnterpriseAddress,
|
|
119
121
|
toLovelace: () => toLovelace,
|
|
120
122
|
toNativeScript: () => toNativeScript,
|
|
@@ -134,7 +136,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
134
136
|
var import_common2 = require("@meshsdk/common");
|
|
135
137
|
|
|
136
138
|
// src/deser/csl.ts
|
|
137
|
-
var csl = __toESM(require("@sidan-lab/
|
|
139
|
+
var csl = __toESM(require("@sidan-lab/whisky-js-nodejs"), 1);
|
|
138
140
|
|
|
139
141
|
// src/deser/constants.ts
|
|
140
142
|
var LANGUAGE_VERSIONS = {
|
|
@@ -152,10 +154,10 @@ var POLICY_ID_LENGTH = 56;
|
|
|
152
154
|
|
|
153
155
|
// src/deser/converter.ts
|
|
154
156
|
var import_json_bigint = __toESM(require("json-bigint"), 1);
|
|
155
|
-
var toAddress = (
|
|
156
|
-
var toBaseAddress = (
|
|
157
|
-
var toEnterpriseAddress = (
|
|
158
|
-
var toRewardAddress = (
|
|
157
|
+
var toAddress = (bech32) => csl.Address.from_bech32(bech32);
|
|
158
|
+
var toBaseAddress = (bech32) => csl.BaseAddress.from_address(toAddress(bech32));
|
|
159
|
+
var toEnterpriseAddress = (bech32) => csl.EnterpriseAddress.from_address(toAddress(bech32));
|
|
160
|
+
var toRewardAddress = (bech32) => csl.RewardAddress.from_address(toAddress(bech32));
|
|
159
161
|
var fromBytes = (bytes) => Buffer.from(bytes).toString("hex");
|
|
160
162
|
var toBytes = (hex) => {
|
|
161
163
|
if (hex.length % 2 === 0 && /^[0-9A-F]*$/i.test(hex))
|
|
@@ -230,7 +232,7 @@ var castDataToPlutusData = ({
|
|
|
230
232
|
return csl.PlutusData.from_hex(content);
|
|
231
233
|
}
|
|
232
234
|
return csl.PlutusData.from_json(
|
|
233
|
-
content,
|
|
235
|
+
castRawDataToJsonString(content),
|
|
234
236
|
csl.PlutusDatumSchema.DetailedSchema
|
|
235
237
|
);
|
|
236
238
|
};
|
|
@@ -269,6 +271,29 @@ var toNativeScript = (script) => {
|
|
|
269
271
|
);
|
|
270
272
|
}
|
|
271
273
|
};
|
|
274
|
+
var toCslValue = (assets) => {
|
|
275
|
+
let cslValue = void 0;
|
|
276
|
+
let multiAsset = csl.MultiAsset.new();
|
|
277
|
+
for (const asset of assets) {
|
|
278
|
+
if (asset.unit === "lovelace" || asset.unit === "") {
|
|
279
|
+
cslValue = csl.Value.new(csl.BigNum.from_str(asset.quantity));
|
|
280
|
+
} else {
|
|
281
|
+
const policyId = csl.ScriptHash.from_hex(asset.unit.slice(0, 56));
|
|
282
|
+
const assetName = csl.AssetName.new(
|
|
283
|
+
Buffer.from(asset.unit.slice(56), "hex")
|
|
284
|
+
);
|
|
285
|
+
const quantity = csl.BigNum.from_str(asset.quantity);
|
|
286
|
+
multiAsset.set_asset(policyId, assetName, quantity);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (cslValue !== void 0) {
|
|
290
|
+
cslValue.set_multiasset(multiAsset);
|
|
291
|
+
} else {
|
|
292
|
+
cslValue = csl.Value.new(csl.BigNum.from_str("0"));
|
|
293
|
+
cslValue.set_multiasset(multiAsset);
|
|
294
|
+
}
|
|
295
|
+
return cslValue;
|
|
296
|
+
};
|
|
272
297
|
|
|
273
298
|
// src/deser/deserializer.ts
|
|
274
299
|
var deserializeAddress = (address) => csl.Address.from_bytes(toBytes(address));
|
|
@@ -294,14 +319,14 @@ var deserializeValue = (value) => csl.Value.from_bytes(toBytes(value));
|
|
|
294
319
|
|
|
295
320
|
// src/deser/resolver.ts
|
|
296
321
|
var import_common = require("@meshsdk/common");
|
|
297
|
-
var resolveStakeKeyHash = (
|
|
322
|
+
var resolveStakeKeyHash = (bech32) => {
|
|
298
323
|
try {
|
|
299
324
|
const stakeKeyHash = [
|
|
300
|
-
toBaseAddress(
|
|
301
|
-
toRewardAddress(
|
|
325
|
+
toBaseAddress(bech32)?.stake_cred().to_keyhash(),
|
|
326
|
+
toRewardAddress(bech32)?.payment_cred().to_keyhash()
|
|
302
327
|
].find((kh) => kh !== void 0);
|
|
303
328
|
if (stakeKeyHash !== void 0) return stakeKeyHash.to_hex();
|
|
304
|
-
throw new Error(`Couldn't resolve stake key hash from address: ${
|
|
329
|
+
throw new Error(`Couldn't resolve stake key hash from address: ${bech32}`);
|
|
305
330
|
} catch (error) {
|
|
306
331
|
throw new Error(`An error occurred during resolveStakeKeyHash: ${error}.`);
|
|
307
332
|
}
|
|
@@ -341,9 +366,9 @@ var resolveNativeScriptHash = (script) => {
|
|
|
341
366
|
var resolveScriptHashDRepId = (scriptHash) => {
|
|
342
367
|
return csl.DRep.new_script_hash(
|
|
343
368
|
csl.ScriptHash.from_hex(scriptHash)
|
|
344
|
-
).to_bech32();
|
|
369
|
+
).to_bech32(true);
|
|
345
370
|
};
|
|
346
|
-
var resolveRewardAddress = (
|
|
371
|
+
var resolveRewardAddress = (bech32) => {
|
|
347
372
|
const buildRewardAddress = (networkId, stakeKeyHash) => {
|
|
348
373
|
return csl.RewardAddress.new(
|
|
349
374
|
networkId,
|
|
@@ -351,18 +376,21 @@ var resolveRewardAddress = (bech322) => {
|
|
|
351
376
|
);
|
|
352
377
|
};
|
|
353
378
|
try {
|
|
354
|
-
const address = toAddress(
|
|
355
|
-
const baseAddress = toBaseAddress(
|
|
379
|
+
const address = toAddress(bech32);
|
|
380
|
+
const baseAddress = toBaseAddress(bech32);
|
|
356
381
|
const stakeKeyHash = baseAddress?.stake_cred().to_keyhash();
|
|
357
382
|
if (stakeKeyHash !== void 0)
|
|
358
383
|
return buildRewardAddress(address.network_id(), stakeKeyHash).to_address().to_bech32();
|
|
359
|
-
throw new Error(`Couldn't resolve reward address from address: ${
|
|
384
|
+
throw new Error(`Couldn't resolve reward address from address: ${bech32}`);
|
|
360
385
|
} catch (error) {
|
|
361
386
|
throw new Error(`An error occurred during resolveRewardAddress: ${error}.`);
|
|
362
387
|
}
|
|
363
388
|
};
|
|
364
|
-
var resolveDataHash = (
|
|
365
|
-
const plutusData =
|
|
389
|
+
var resolveDataHash = (rawData, type = "Mesh") => {
|
|
390
|
+
const plutusData = castDataToPlutusData({
|
|
391
|
+
content: rawData,
|
|
392
|
+
type
|
|
393
|
+
});
|
|
366
394
|
const dataHash = csl.hash_plutus_data(plutusData);
|
|
367
395
|
return dataHash.to_hex();
|
|
368
396
|
};
|
|
@@ -375,8 +403,8 @@ var serializePoolId = (hash) => {
|
|
|
375
403
|
var resolveScriptRef = (script) => {
|
|
376
404
|
return toScriptRef(script).to_hex();
|
|
377
405
|
};
|
|
378
|
-
var resolveEd25519KeyHash = (
|
|
379
|
-
return csl.Ed25519KeyHash.from_bech32(
|
|
406
|
+
var resolveEd25519KeyHash = (bech32) => {
|
|
407
|
+
return csl.Ed25519KeyHash.from_bech32(bech32).to_hex();
|
|
380
408
|
};
|
|
381
409
|
|
|
382
410
|
// src/utils/scripts.ts
|
|
@@ -401,14 +429,14 @@ var serialzeAddress = (deserializedAddress, networkId = 0) => {
|
|
|
401
429
|
const addressObj = isPaymentScript ? (0, import_common2.scriptAddress)(paymentHash, stakeHash, isStakeScript) : (0, import_common2.pubKeyAddress)(paymentHash, stakeHash, isStakeScript);
|
|
402
430
|
return serializeAddressObj(addressObj, networkId);
|
|
403
431
|
};
|
|
404
|
-
var
|
|
405
|
-
const hexAddress = csl.Address.from_bech32(
|
|
432
|
+
var addrBech32ToPlutusDataHex = (bech32) => {
|
|
433
|
+
const hexAddress = csl.Address.from_bech32(bech32).to_hex();
|
|
406
434
|
const cslAddress = csl.Address.from_hex(hexAddress);
|
|
407
435
|
const hex = csl.PlutusData.from_address(cslAddress).to_hex();
|
|
408
436
|
return hex;
|
|
409
437
|
};
|
|
410
|
-
var
|
|
411
|
-
const hexAddress = csl.Address.from_bech32(
|
|
438
|
+
var addrBech32ToPlutusDataObj = (bech32) => {
|
|
439
|
+
const hexAddress = csl.Address.from_bech32(bech32).to_hex();
|
|
412
440
|
const cslAddress = csl.Address.from_hex(hexAddress);
|
|
413
441
|
const json = JSON.parse(csl.PlutusData.from_address(cslAddress).to_json(1));
|
|
414
442
|
return json;
|
|
@@ -507,6 +535,9 @@ var keyHashToRewardAddress = (keyHashHex, network = 1) => {
|
|
|
507
535
|
return rewardAddress;
|
|
508
536
|
};
|
|
509
537
|
|
|
538
|
+
// src/utils/transaction.ts
|
|
539
|
+
var import_whisky_js_nodejs = require("@sidan-lab/whisky-js-nodejs");
|
|
540
|
+
|
|
510
541
|
// src/wasm.ts
|
|
511
542
|
var parseWasmResult = (result) => {
|
|
512
543
|
if (result.get_status() !== "success") {
|
|
@@ -534,13 +565,16 @@ var signTransaction = (txHex, signingKeys) => {
|
|
|
534
565
|
const result = csl.js_sign_transaction(txHex, cslSigningKeys);
|
|
535
566
|
return parseWasmResult(result);
|
|
536
567
|
};
|
|
537
|
-
var evaluateTransaction = (txHex, resolvedUtxos, network, slotConfig) => {
|
|
568
|
+
var evaluateTransaction = (txHex, resolvedUtxos, chainedTxs, network, slotConfig) => {
|
|
538
569
|
const additionalTxs = csl.JsVecString.new();
|
|
570
|
+
for (const tx of chainedTxs) {
|
|
571
|
+
additionalTxs.add(tx);
|
|
572
|
+
}
|
|
539
573
|
const mappedUtxos = csl.JsVecString.new();
|
|
540
574
|
for (const utxo of resolvedUtxos) {
|
|
541
575
|
mappedUtxos.add(JSON.stringify(utxo));
|
|
542
576
|
}
|
|
543
|
-
const result = csl.
|
|
577
|
+
const result = csl.js_evaluate_tx_scripts(
|
|
544
578
|
txHex,
|
|
545
579
|
mappedUtxos,
|
|
546
580
|
additionalTxs,
|
|
@@ -605,7 +639,7 @@ var getTransactionInputs = (txHex) => {
|
|
|
605
639
|
const input = cslInputs.get(i);
|
|
606
640
|
inputs.push({
|
|
607
641
|
txHash: input.transaction_id().to_hex(),
|
|
608
|
-
|
|
642
|
+
outputIndex: input.index()
|
|
609
643
|
});
|
|
610
644
|
}
|
|
611
645
|
const cslCollaterals = body.collateral();
|
|
@@ -614,7 +648,7 @@ var getTransactionInputs = (txHex) => {
|
|
|
614
648
|
const collateral = cslCollaterals.get(i);
|
|
615
649
|
inputs.push({
|
|
616
650
|
txHash: collateral.transaction_id().to_hex(),
|
|
617
|
-
|
|
651
|
+
outputIndex: collateral.index()
|
|
618
652
|
});
|
|
619
653
|
}
|
|
620
654
|
}
|
|
@@ -624,20 +658,25 @@ var getTransactionInputs = (txHex) => {
|
|
|
624
658
|
const refInput = cslRefInputs.get(i);
|
|
625
659
|
inputs.push({
|
|
626
660
|
txHash: refInput.transaction_id().to_hex(),
|
|
627
|
-
|
|
661
|
+
outputIndex: refInput.index()
|
|
628
662
|
});
|
|
629
663
|
}
|
|
630
664
|
}
|
|
631
665
|
return inputs;
|
|
632
666
|
};
|
|
667
|
+
var getTransactionOutputs = (txHex) => {
|
|
668
|
+
const outputs = (0, import_whisky_js_nodejs.js_get_tx_outs_utxo)(txHex).get_data();
|
|
669
|
+
const utxos = JSON.parse(outputs);
|
|
670
|
+
return utxos;
|
|
671
|
+
};
|
|
633
672
|
|
|
634
673
|
// src/utils/aiken.ts
|
|
635
674
|
var applyParamsToScript = (rawScript, params, type = "Mesh") => {
|
|
636
675
|
const cslParams = csl.JsVecString.new();
|
|
637
|
-
let paramType =
|
|
676
|
+
let paramType = "cbor";
|
|
638
677
|
switch (type) {
|
|
639
678
|
case "JSON":
|
|
640
|
-
paramType =
|
|
679
|
+
paramType = "json";
|
|
641
680
|
params.forEach((param) => {
|
|
642
681
|
if (typeof param === "object") {
|
|
643
682
|
cslParams.add(JSON.stringify(param));
|
|
@@ -664,68 +703,17 @@ var applyCborEncoding = (rawScript) => {
|
|
|
664
703
|
return csl.js_apply_params_to_script(
|
|
665
704
|
rawScript,
|
|
666
705
|
csl.JsVecString.new(),
|
|
667
|
-
|
|
706
|
+
"cbor"
|
|
668
707
|
);
|
|
669
708
|
};
|
|
670
709
|
|
|
671
710
|
// src/utils/drep.ts
|
|
672
|
-
var import_base32_encoding = __toESM(require("base32-encoding"), 1);
|
|
673
|
-
var import_bech32 = require("bech32");
|
|
674
711
|
var getDRepIds = (dRepId) => {
|
|
712
|
+
const cslDrep = csl.DRep.from_bech32(dRepId);
|
|
675
713
|
let result = {
|
|
676
|
-
cip105:
|
|
677
|
-
cip129:
|
|
714
|
+
cip105: cslDrep.to_bech32(false),
|
|
715
|
+
cip129: cslDrep.to_bech32(true)
|
|
678
716
|
};
|
|
679
|
-
if (dRepId.length === 58) {
|
|
680
|
-
result.cip129 = dRepId;
|
|
681
|
-
const { prefix, words } = import_bech32.bech32.decode(dRepId);
|
|
682
|
-
if (prefix !== "drep") {
|
|
683
|
-
throw new Error("Malformed CIP129 DRepId");
|
|
684
|
-
}
|
|
685
|
-
const bytes = import_base32_encoding.default.decode(new Uint8Array(words));
|
|
686
|
-
if (bytes[0] === 34) {
|
|
687
|
-
result.cip105 = csl.DRep.new_key_hash(
|
|
688
|
-
csl.Ed25519KeyHash.from_hex(bytes.subarray(1).toString("hex"))
|
|
689
|
-
).to_bech32();
|
|
690
|
-
} else if (bytes[0] === 35) {
|
|
691
|
-
result.cip105 = csl.DRep.new_script_hash(
|
|
692
|
-
csl.ScriptHash.from_hex(bytes.subarray(1).toString("hex"))
|
|
693
|
-
).to_bech32();
|
|
694
|
-
} else {
|
|
695
|
-
throw new Error("Malformed CIP129 DRepId");
|
|
696
|
-
}
|
|
697
|
-
} else {
|
|
698
|
-
result.cip105 = dRepId;
|
|
699
|
-
try {
|
|
700
|
-
const cslDRep = csl.DRep.from_bech32(dRepId);
|
|
701
|
-
if (cslDRep.kind() === csl.DRepKind.KeyHash) {
|
|
702
|
-
let rawBytes = cslDRep.to_key_hash()?.to_bytes();
|
|
703
|
-
if (!rawBytes) {
|
|
704
|
-
throw new Error("Malformed key hash in DRepId");
|
|
705
|
-
}
|
|
706
|
-
let rawBytesWithPrefix = new Uint8Array(rawBytes.length + 1);
|
|
707
|
-
rawBytesWithPrefix.set([34]);
|
|
708
|
-
rawBytesWithPrefix.set(rawBytes, 1);
|
|
709
|
-
let base32RawBytes = import_base32_encoding.default.encode(rawBytesWithPrefix);
|
|
710
|
-
result.cip129 = import_bech32.bech32.encode("drep", base32RawBytes);
|
|
711
|
-
} else if (cslDRep.kind() === csl.DRepKind.ScriptHash) {
|
|
712
|
-
let rawBytes = cslDRep.to_script_hash()?.to_bytes();
|
|
713
|
-
if (!rawBytes) {
|
|
714
|
-
throw new Error("Malformed script hash in DRepId");
|
|
715
|
-
}
|
|
716
|
-
let rawBytesWithPrefix = new Uint8Array(rawBytes.length + 1);
|
|
717
|
-
rawBytesWithPrefix.set([35]);
|
|
718
|
-
rawBytesWithPrefix.set(rawBytes, 1);
|
|
719
|
-
let base32RawBytes = import_base32_encoding.default.encode(rawBytesWithPrefix);
|
|
720
|
-
result.cip129 = import_bech32.bech32.encode("drep", base32RawBytes);
|
|
721
|
-
} else {
|
|
722
|
-
throw new Error("Can only calculate DRepIds for script/key DReps");
|
|
723
|
-
}
|
|
724
|
-
} catch (e) {
|
|
725
|
-
console.error(e);
|
|
726
|
-
throw new Error("Malformed DRepId");
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
717
|
return result;
|
|
730
718
|
};
|
|
731
719
|
|
|
@@ -981,6 +969,41 @@ var relayToObj = (relay) => {
|
|
|
981
969
|
}
|
|
982
970
|
};
|
|
983
971
|
|
|
972
|
+
// src/core/adaptor/metadata.ts
|
|
973
|
+
var import_json_bigint2 = __toESM(require("json-bigint"), 1);
|
|
974
|
+
var txMetadataToObj = (metadata) => {
|
|
975
|
+
const result = [];
|
|
976
|
+
metadata.forEach((value, key) => {
|
|
977
|
+
result.push({
|
|
978
|
+
tag: key.toString(),
|
|
979
|
+
metadata: import_json_bigint2.default.stringify(metadatumToObj(value))
|
|
980
|
+
});
|
|
981
|
+
});
|
|
982
|
+
return result;
|
|
983
|
+
};
|
|
984
|
+
var metadatumToObj = (metadatum) => {
|
|
985
|
+
if (typeof metadatum === "number" || typeof metadatum === "string") {
|
|
986
|
+
return metadatum;
|
|
987
|
+
} else if (typeof metadatum === "bigint") {
|
|
988
|
+
return metadatum.toString();
|
|
989
|
+
} else if (metadatum instanceof Uint8Array) {
|
|
990
|
+
return uint8ArrayToHex(metadatum);
|
|
991
|
+
} else if (metadatum instanceof Map) {
|
|
992
|
+
const result = {};
|
|
993
|
+
metadatum.forEach((value, key) => {
|
|
994
|
+
result[metadatumToObj(key)] = metadatumToObj(value);
|
|
995
|
+
});
|
|
996
|
+
return result;
|
|
997
|
+
} else if (Array.isArray(metadatum)) {
|
|
998
|
+
return metadatum.map(metadatumToObj);
|
|
999
|
+
} else {
|
|
1000
|
+
throw new Error("metadatumToObj: Unsupported Metadatum type");
|
|
1001
|
+
}
|
|
1002
|
+
};
|
|
1003
|
+
var uint8ArrayToHex = (bytes) => {
|
|
1004
|
+
return Array.from(bytes).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
1005
|
+
};
|
|
1006
|
+
|
|
984
1007
|
// src/core/adaptor/mint.ts
|
|
985
1008
|
var mintItemToObj = (mintItem) => {
|
|
986
1009
|
switch (mintItem.type) {
|
|
@@ -1063,41 +1086,6 @@ var outputToObj = (output) => {
|
|
|
1063
1086
|
};
|
|
1064
1087
|
};
|
|
1065
1088
|
|
|
1066
|
-
// src/core/adaptor/metadata.ts
|
|
1067
|
-
var import_json_bigint2 = __toESM(require("json-bigint"), 1);
|
|
1068
|
-
var txMetadataToObj = (metadata) => {
|
|
1069
|
-
const result = [];
|
|
1070
|
-
metadata.forEach((value, key) => {
|
|
1071
|
-
result.push({
|
|
1072
|
-
tag: key.toString(),
|
|
1073
|
-
metadata: import_json_bigint2.default.stringify(metadatumToObj(value))
|
|
1074
|
-
});
|
|
1075
|
-
});
|
|
1076
|
-
return result;
|
|
1077
|
-
};
|
|
1078
|
-
var metadatumToObj = (metadatum) => {
|
|
1079
|
-
if (typeof metadatum === "number" || typeof metadatum === "string") {
|
|
1080
|
-
return metadatum;
|
|
1081
|
-
} else if (typeof metadatum === "bigint") {
|
|
1082
|
-
return metadatum.toString();
|
|
1083
|
-
} else if (metadatum instanceof Uint8Array) {
|
|
1084
|
-
return uint8ArrayToHex(metadatum);
|
|
1085
|
-
} else if (metadatum instanceof Map) {
|
|
1086
|
-
const result = {};
|
|
1087
|
-
metadatum.forEach((value, key) => {
|
|
1088
|
-
result[metadatumToObj(key)] = metadatumToObj(value);
|
|
1089
|
-
});
|
|
1090
|
-
return result;
|
|
1091
|
-
} else if (Array.isArray(metadatum)) {
|
|
1092
|
-
return metadatum.map(metadatumToObj);
|
|
1093
|
-
} else {
|
|
1094
|
-
throw new Error("metadatumToObj: Unsupported Metadatum type");
|
|
1095
|
-
}
|
|
1096
|
-
};
|
|
1097
|
-
var uint8ArrayToHex = (bytes) => {
|
|
1098
|
-
return Array.from(bytes).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
1099
|
-
};
|
|
1100
|
-
|
|
1101
1089
|
// src/core/adaptor/txIn.ts
|
|
1102
1090
|
var txInToObj = (txIn) => {
|
|
1103
1091
|
switch (txIn.type) {
|
|
@@ -1382,13 +1370,28 @@ var meshTxBuilderBodyToObj = ({
|
|
|
1382
1370
|
fee,
|
|
1383
1371
|
network
|
|
1384
1372
|
}) => {
|
|
1373
|
+
let mintsObj = [];
|
|
1374
|
+
mints.forEach((mint) => {
|
|
1375
|
+
mint.mintValue.forEach((mintValue) => {
|
|
1376
|
+
mintsObj.push(
|
|
1377
|
+
mintItemToObj({
|
|
1378
|
+
type: mint.type,
|
|
1379
|
+
policyId: mint.policyId,
|
|
1380
|
+
assetName: mintValue.assetName,
|
|
1381
|
+
amount: mintValue.amount,
|
|
1382
|
+
scriptSource: mint.scriptSource,
|
|
1383
|
+
redeemer: mint.redeemer
|
|
1384
|
+
})
|
|
1385
|
+
);
|
|
1386
|
+
});
|
|
1387
|
+
});
|
|
1385
1388
|
return {
|
|
1386
1389
|
inputs: inputs.map(txInToObj),
|
|
1387
1390
|
outputs: outputs.map(outputToObj),
|
|
1388
1391
|
collaterals: collaterals.map(collateralTxInToObj),
|
|
1389
1392
|
requiredSignatures,
|
|
1390
1393
|
referenceInputs,
|
|
1391
|
-
mints:
|
|
1394
|
+
mints: mintsObj,
|
|
1392
1395
|
changeAddress,
|
|
1393
1396
|
metadata: txMetadataToObj(metadata),
|
|
1394
1397
|
validityRange: (0, import_common3.validityRangeToObj)(validityRange),
|
|
@@ -1402,23 +1405,21 @@ var meshTxBuilderBodyToObj = ({
|
|
|
1402
1405
|
};
|
|
1403
1406
|
|
|
1404
1407
|
// src/core/serializer.ts
|
|
1408
|
+
var VKEY_PUBKEY_SIZE_BYTES = 32;
|
|
1409
|
+
var VKEY_SIGNATURE_SIZE_BYTES = 64;
|
|
1410
|
+
var CHAIN_CODE_SIZE_BYTES = 32;
|
|
1405
1411
|
var CSLSerializer = class {
|
|
1406
1412
|
/**
|
|
1407
1413
|
* Set to true to enable verbose logging for the txBodyJson prior going into build
|
|
1408
1414
|
*/
|
|
1409
|
-
verbose;
|
|
1410
1415
|
protocolParams;
|
|
1411
1416
|
meshTxBuilderBody = (0, import_common4.emptyTxBuilderBody)();
|
|
1412
|
-
constructor(protocolParams
|
|
1417
|
+
constructor(protocolParams) {
|
|
1413
1418
|
this.protocolParams = protocolParams || import_common4.DEFAULT_PROTOCOL_PARAMETERS;
|
|
1414
|
-
this.verbose = verbose;
|
|
1415
1419
|
}
|
|
1416
1420
|
serializeTxBody(txBody, protocolParams) {
|
|
1417
1421
|
const txBodyJson = import_json_bigint3.default.stringify(meshTxBuilderBodyToObj(txBody));
|
|
1418
1422
|
const params = import_json_bigint3.default.stringify(protocolParams || this.protocolParams);
|
|
1419
|
-
if (this.verbose) {
|
|
1420
|
-
console.log("txBodyJson", txBodyJson);
|
|
1421
|
-
}
|
|
1422
1423
|
const txBuildResult = csl.js_serialize_tx_body(txBodyJson, params);
|
|
1423
1424
|
if (txBuildResult.get_status() !== "success") {
|
|
1424
1425
|
throw new Error(`txBuildResult error: ${txBuildResult.get_error()}`);
|
|
@@ -1445,8 +1446,8 @@ var CSLSerializer = class {
|
|
|
1445
1446
|
}
|
|
1446
1447
|
deserializer = {
|
|
1447
1448
|
key: {
|
|
1448
|
-
deserializeAddress: function(
|
|
1449
|
-
return deserializeBech32Address(
|
|
1449
|
+
deserializeAddress: function(bech32) {
|
|
1450
|
+
return deserializeBech32Address(bech32);
|
|
1450
1451
|
}
|
|
1451
1452
|
},
|
|
1452
1453
|
script: {
|
|
@@ -1472,17 +1473,17 @@ var CSLSerializer = class {
|
|
|
1472
1473
|
};
|
|
1473
1474
|
resolver = {
|
|
1474
1475
|
keys: {
|
|
1475
|
-
resolveStakeKeyHash: function(
|
|
1476
|
-
return rewardAddressToKeyHash(
|
|
1476
|
+
resolveStakeKeyHash: function(bech32) {
|
|
1477
|
+
return rewardAddressToKeyHash(bech32) || deserializeBech32Address(bech32).stakeCredentialHash;
|
|
1477
1478
|
},
|
|
1478
1479
|
resolvePrivateKey: function(words) {
|
|
1479
1480
|
return resolvePrivateKey(words);
|
|
1480
1481
|
},
|
|
1481
|
-
resolveRewardAddress: function(
|
|
1482
|
-
return resolveRewardAddress(
|
|
1482
|
+
resolveRewardAddress: function(bech32) {
|
|
1483
|
+
return resolveRewardAddress(bech32);
|
|
1483
1484
|
},
|
|
1484
|
-
resolveEd25519KeyHash: function(
|
|
1485
|
-
return resolveEd25519KeyHash(
|
|
1485
|
+
resolveEd25519KeyHash: function(bech32) {
|
|
1486
|
+
return resolveEd25519KeyHash(bech32);
|
|
1486
1487
|
}
|
|
1487
1488
|
},
|
|
1488
1489
|
tx: {
|
|
@@ -1491,8 +1492,8 @@ var CSLSerializer = class {
|
|
|
1491
1492
|
}
|
|
1492
1493
|
},
|
|
1493
1494
|
data: {
|
|
1494
|
-
resolveDataHash: function(
|
|
1495
|
-
return resolveDataHash(
|
|
1495
|
+
resolveDataHash: function(rawData, type = "Mesh") {
|
|
1496
|
+
return resolveDataHash(rawData, type);
|
|
1496
1497
|
}
|
|
1497
1498
|
},
|
|
1498
1499
|
script: {
|
|
@@ -1501,6 +1502,125 @@ var CSLSerializer = class {
|
|
|
1501
1502
|
}
|
|
1502
1503
|
}
|
|
1503
1504
|
};
|
|
1505
|
+
serializeOutput(output) {
|
|
1506
|
+
let cslOutputBuilder = csl.TransactionOutputBuilder.new().with_address(
|
|
1507
|
+
csl.Address.from_bech32(output.address)
|
|
1508
|
+
);
|
|
1509
|
+
if (output.datum?.type === "Hash") {
|
|
1510
|
+
cslOutputBuilder.with_data_hash(
|
|
1511
|
+
csl.hash_plutus_data(castDataToPlutusData(output.datum.data))
|
|
1512
|
+
);
|
|
1513
|
+
} else if (output.datum?.type === "Inline") {
|
|
1514
|
+
cslOutputBuilder.with_plutus_data(
|
|
1515
|
+
castDataToPlutusData(output.datum.data)
|
|
1516
|
+
);
|
|
1517
|
+
} else if (output.datum?.type === "Embedded") {
|
|
1518
|
+
throw new Error("Embedded datum not supported");
|
|
1519
|
+
}
|
|
1520
|
+
if (output.referenceScript) {
|
|
1521
|
+
switch (output.referenceScript.version) {
|
|
1522
|
+
case "V1": {
|
|
1523
|
+
cslOutputBuilder.with_script_ref(
|
|
1524
|
+
csl.ScriptRef.new_plutus_script(
|
|
1525
|
+
csl.PlutusScript.from_hex_with_version(
|
|
1526
|
+
output.referenceScript.code,
|
|
1527
|
+
csl.Language.new_plutus_v1()
|
|
1528
|
+
)
|
|
1529
|
+
)
|
|
1530
|
+
);
|
|
1531
|
+
break;
|
|
1532
|
+
}
|
|
1533
|
+
case "V2": {
|
|
1534
|
+
cslOutputBuilder.with_script_ref(
|
|
1535
|
+
csl.ScriptRef.new_plutus_script(
|
|
1536
|
+
csl.PlutusScript.from_hex_with_version(
|
|
1537
|
+
output.referenceScript.code,
|
|
1538
|
+
csl.Language.new_plutus_v2()
|
|
1539
|
+
)
|
|
1540
|
+
)
|
|
1541
|
+
);
|
|
1542
|
+
break;
|
|
1543
|
+
}
|
|
1544
|
+
case "V3": {
|
|
1545
|
+
cslOutputBuilder.with_script_ref(
|
|
1546
|
+
csl.ScriptRef.new_plutus_script(
|
|
1547
|
+
csl.PlutusScript.from_hex_with_version(
|
|
1548
|
+
output.referenceScript.code,
|
|
1549
|
+
csl.Language.new_plutus_v3()
|
|
1550
|
+
)
|
|
1551
|
+
)
|
|
1552
|
+
);
|
|
1553
|
+
break;
|
|
1554
|
+
}
|
|
1555
|
+
default: {
|
|
1556
|
+
cslOutputBuilder.with_script_ref(
|
|
1557
|
+
csl.ScriptRef.new_native_script(
|
|
1558
|
+
csl.NativeScript.from_hex(output.referenceScript.code)
|
|
1559
|
+
)
|
|
1560
|
+
);
|
|
1561
|
+
break;
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
return cslOutputBuilder.next().with_value(toCslValue(output.amount)).build().to_hex();
|
|
1566
|
+
}
|
|
1567
|
+
serializeTxBodyWithMockSignatures(txBuilderBody, protocolParams) {
|
|
1568
|
+
const txHex = this.serializeTxBody(txBuilderBody, protocolParams);
|
|
1569
|
+
const cslTx = csl.Transaction.from_hex(txHex);
|
|
1570
|
+
const mockWitnessSet = cslTx.witness_set();
|
|
1571
|
+
const mockVkeyWitnesses = mockWitnessSet.vkeys() ?? csl.Vkeywitnesses.new();
|
|
1572
|
+
const mockBootstrapWitnesses = mockWitnessSet.bootstraps() ?? csl.BootstrapWitnesses.new();
|
|
1573
|
+
for (let i = 0; i < txBuilderBody.expectedNumberKeyWitnesses; i++) {
|
|
1574
|
+
const numberInHex = this.numberToIntegerHex(i);
|
|
1575
|
+
const mockVkey = csl.Vkey.new(
|
|
1576
|
+
csl.PublicKey.from_hex(this.mockPubkey(numberInHex))
|
|
1577
|
+
);
|
|
1578
|
+
const mockSignature = csl.Ed25519Signature.from_hex(
|
|
1579
|
+
this.mockSignature(numberInHex)
|
|
1580
|
+
);
|
|
1581
|
+
mockVkeyWitnesses.add(csl.Vkeywitness.new(mockVkey, mockSignature));
|
|
1582
|
+
}
|
|
1583
|
+
this.meshTxBuilderBody.expectedByronAddressWitnesses.forEach(
|
|
1584
|
+
(bootstrapWitness, i) => {
|
|
1585
|
+
const address = csl.ByronAddress.from_base58(bootstrapWitness);
|
|
1586
|
+
const numberInHex = this.numberToIntegerHex(i);
|
|
1587
|
+
const pubKeyHex = this.mockPubkey(numberInHex);
|
|
1588
|
+
const mockVkey = csl.Vkey.new(csl.PublicKey.from_hex(pubKeyHex));
|
|
1589
|
+
const signature = this.mockSignature(numberInHex);
|
|
1590
|
+
const chainCode = this.mockChainCode(numberInHex);
|
|
1591
|
+
mockBootstrapWitnesses.add(
|
|
1592
|
+
csl.BootstrapWitness.new(
|
|
1593
|
+
mockVkey,
|
|
1594
|
+
csl.Ed25519Signature.from_hex(signature),
|
|
1595
|
+
Buffer.from(chainCode, "hex"),
|
|
1596
|
+
address.attributes()
|
|
1597
|
+
)
|
|
1598
|
+
);
|
|
1599
|
+
}
|
|
1600
|
+
);
|
|
1601
|
+
mockWitnessSet.set_vkeys(mockVkeyWitnesses);
|
|
1602
|
+
mockWitnessSet.set_bootstraps(mockBootstrapWitnesses);
|
|
1603
|
+
return csl.Transaction.new(
|
|
1604
|
+
cslTx.body(),
|
|
1605
|
+
mockWitnessSet,
|
|
1606
|
+
cslTx.auxiliary_data()
|
|
1607
|
+
).to_hex();
|
|
1608
|
+
}
|
|
1609
|
+
serializeValue(value) {
|
|
1610
|
+
return toCslValue(value).to_hex();
|
|
1611
|
+
}
|
|
1612
|
+
mockPubkey(numberInHex) {
|
|
1613
|
+
return "0".repeat(VKEY_PUBKEY_SIZE_BYTES * 2 - numberInHex.length).concat(numberInHex);
|
|
1614
|
+
}
|
|
1615
|
+
mockSignature(numberInHex) {
|
|
1616
|
+
return "0".repeat(VKEY_SIGNATURE_SIZE_BYTES * 2 - numberInHex.length).concat(numberInHex);
|
|
1617
|
+
}
|
|
1618
|
+
mockChainCode = (numberInHex) => {
|
|
1619
|
+
return "0".repeat(CHAIN_CODE_SIZE_BYTES * 2 - numberInHex.length).concat(numberInHex);
|
|
1620
|
+
};
|
|
1621
|
+
numberToIntegerHex = (number) => {
|
|
1622
|
+
return BigInt(number).toString(16);
|
|
1623
|
+
};
|
|
1504
1624
|
};
|
|
1505
1625
|
|
|
1506
1626
|
// src/offline-providers/offline-evaluator.ts
|
|
@@ -1540,36 +1660,47 @@ var OfflineEvaluator = class {
|
|
|
1540
1660
|
* - budget: Memory units and CPU steps required
|
|
1541
1661
|
* @throws Error if any required UTXOs cannot be resolved or if script evaluation fails
|
|
1542
1662
|
*/
|
|
1543
|
-
async evaluateTx(tx) {
|
|
1544
|
-
const
|
|
1663
|
+
async evaluateTx(tx, additionalUtxos, additionalTxs) {
|
|
1664
|
+
const foundUtxos = /* @__PURE__ */ new Set();
|
|
1665
|
+
for (const utxo of additionalUtxos) {
|
|
1666
|
+
foundUtxos.add(`${utxo.input.txHash}:${utxo.input.outputIndex}`);
|
|
1667
|
+
}
|
|
1668
|
+
for (const tx2 of additionalTxs) {
|
|
1669
|
+
const outputs = getTransactionOutputs(tx2);
|
|
1670
|
+
for (const output of outputs) {
|
|
1671
|
+
foundUtxos.add(`${output.input.txHash}:${output.input.outputIndex}`);
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
const inputsToResolve = getTransactionInputs(tx).filter(
|
|
1675
|
+
(input) => !foundUtxos.has(`${input.txHash}:${input.outputIndex}`)
|
|
1676
|
+
);
|
|
1545
1677
|
const txHashesSet = new Set(inputsToResolve.map((input) => input.txHash));
|
|
1546
|
-
const resolvedUTXOs = [];
|
|
1547
1678
|
for (const txHash of txHashesSet) {
|
|
1548
1679
|
const utxos = await this.fetcher.fetchUTxOs(txHash);
|
|
1549
1680
|
for (const utxo of utxos) {
|
|
1550
1681
|
if (utxo) {
|
|
1551
1682
|
if (inputsToResolve.find(
|
|
1552
|
-
(input) => input.txHash === txHash && input.
|
|
1683
|
+
(input) => input.txHash === txHash && input.outputIndex === utxo.input.outputIndex
|
|
1553
1684
|
)) {
|
|
1554
|
-
|
|
1685
|
+
additionalUtxos.push(utxo);
|
|
1686
|
+
foundUtxos.add(`${utxo.input.txHash}:${utxo.input.outputIndex}`);
|
|
1555
1687
|
}
|
|
1556
1688
|
}
|
|
1557
1689
|
}
|
|
1558
1690
|
}
|
|
1559
1691
|
const missing = inputsToResolve.filter(
|
|
1560
|
-
(input) => !
|
|
1561
|
-
(utxo) => utxo.input.txHash === input.txHash && utxo.input.outputIndex === input.index
|
|
1562
|
-
)
|
|
1692
|
+
(input) => !foundUtxos.has(`${input.txHash}:${input.outputIndex}`)
|
|
1563
1693
|
);
|
|
1564
1694
|
if (missing.length > 0) {
|
|
1565
|
-
const missingList = missing.map((m) => `${m.txHash}:${m.
|
|
1695
|
+
const missingList = missing.map((m) => `${m.txHash}:${m.outputIndex}`).join(", ");
|
|
1566
1696
|
throw new Error(
|
|
1567
1697
|
`Can't resolve these UTXOs to execute plutus scripts: ${missingList}`
|
|
1568
1698
|
);
|
|
1569
1699
|
}
|
|
1570
1700
|
return evaluateTransaction(
|
|
1571
1701
|
tx,
|
|
1572
|
-
|
|
1702
|
+
additionalUtxos,
|
|
1703
|
+
additionalTxs,
|
|
1573
1704
|
this.network,
|
|
1574
1705
|
this.slotConfig
|
|
1575
1706
|
);
|
|
@@ -1582,8 +1713,8 @@ var OfflineEvaluator = class {
|
|
|
1582
1713
|
OfflineEvaluator,
|
|
1583
1714
|
POLICY_ID_LENGTH,
|
|
1584
1715
|
REDEEMER_TAGS,
|
|
1585
|
-
|
|
1586
|
-
|
|
1716
|
+
addrBech32ToPlutusDataHex,
|
|
1717
|
+
addrBech32ToPlutusDataObj,
|
|
1587
1718
|
applyCborEncoding,
|
|
1588
1719
|
applyParamsToScript,
|
|
1589
1720
|
baseAddressToStakeAddress,
|
|
@@ -1619,6 +1750,7 @@ var OfflineEvaluator = class {
|
|
|
1619
1750
|
fromUTF8,
|
|
1620
1751
|
getDRepIds,
|
|
1621
1752
|
getTransactionInputs,
|
|
1753
|
+
getTransactionOutputs,
|
|
1622
1754
|
getV2ScriptHash,
|
|
1623
1755
|
keyHashToRewardAddress,
|
|
1624
1756
|
meshTxBuilderBodyToObj,
|
|
@@ -1662,6 +1794,7 @@ var OfflineEvaluator = class {
|
|
|
1662
1794
|
toAddress,
|
|
1663
1795
|
toBaseAddress,
|
|
1664
1796
|
toBytes,
|
|
1797
|
+
toCslValue,
|
|
1665
1798
|
toEnterpriseAddress,
|
|
1666
1799
|
toLovelace,
|
|
1667
1800
|
toNativeScript,
|