@meshsdk/core-cst 1.8.14 → 1.9.0-beta.1

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
@@ -551,7 +551,7 @@ var require_blake2b = __commonJS({
551
551
  }
552
552
  return out;
553
553
  }
554
- function blake2b5(input, key, outlen, salt, personal) {
554
+ function blake2b7(input, key, outlen, salt, personal) {
555
555
  outlen = outlen || 64;
556
556
  input = util.normalizeInput(input);
557
557
  if (salt) {
@@ -565,11 +565,11 @@ var require_blake2b = __commonJS({
565
565
  return blake2bFinal(ctx);
566
566
  }
567
567
  function blake2bHex(input, key, outlen, salt, personal) {
568
- const output = blake2b5(input, key, outlen, salt, personal);
568
+ const output = blake2b7(input, key, outlen, salt, personal);
569
569
  return util.toHex(output);
570
570
  }
571
571
  module2.exports = {
572
- blake2b: blake2b5,
572
+ blake2b: blake2b7,
573
573
  blake2bHex,
574
574
  blake2bInit,
575
575
  blake2bUpdate,
@@ -900,15 +900,17 @@ __export(index_exports, {
900
900
  AssetFingerprint: () => AssetFingerprint,
901
901
  AssetId: () => AssetId,
902
902
  AssetName: () => AssetName,
903
+ AuxilliaryData: () => AuxilliaryData,
903
904
  BaseAddress: () => BaseAddress,
904
905
  Bip32PrivateKey: () => Bip32PrivateKey2,
905
906
  Bip32PrivateKeyHex: () => Bip32PrivateKeyHex2,
906
- Cardano: () => import_core7.Cardano,
907
+ Cardano: () => import_core8.Cardano,
907
908
  CardanoSDK: () => CardanoSDK,
908
909
  CardanoSDKSerializer: () => CardanoSDKSerializer,
909
910
  CardanoSDKUtil: () => CardanoSDKUtil,
910
911
  CborSet: () => CborSet,
911
912
  CborWriter: () => CborWriter,
913
+ CertIndex: () => CertIndex,
912
914
  Certificate: () => Certificate,
913
915
  CertificateType: () => CertificateType,
914
916
  ConstrPlutusData: () => ConstrPlutusData,
@@ -917,7 +919,7 @@ __export(index_exports, {
917
919
  Costmdls: () => Costmdls,
918
920
  Credential: () => Credential,
919
921
  CredentialType: () => CredentialType,
920
- Crypto: () => Crypto3,
922
+ Crypto: () => Crypto2,
921
923
  DRep: () => DRep,
922
924
  DRepID: () => DRepID,
923
925
  Datum: () => Datum,
@@ -936,16 +938,20 @@ __export(index_exports, {
936
938
  Hash: () => Hash,
937
939
  Hash28ByteBase16: () => Hash28ByteBase162,
938
940
  Hash32ByteBase16: () => Hash32ByteBase162,
941
+ MetadatumList: () => MetadatumList,
942
+ MetadatumMap: () => MetadatumMap,
939
943
  NativeScript: () => NativeScript,
940
944
  NetworkId: () => NetworkId,
941
945
  PaymentAddress: () => PaymentAddress,
942
946
  PlutusData: () => PlutusData,
947
+ PlutusDataKind: () => PlutusDataKind,
943
948
  PlutusLanguageVersion: () => PlutusLanguageVersion,
944
949
  PlutusList: () => PlutusList,
945
950
  PlutusMap: () => PlutusMap,
946
951
  PlutusV1Script: () => PlutusV1Script,
947
952
  PlutusV2Script: () => PlutusV2Script,
948
953
  PlutusV3Script: () => PlutusV3Script,
954
+ PointerAddress: () => PointerAddress,
949
955
  PolicyId: () => PolicyId,
950
956
  PoolId: () => PoolId,
951
957
  Redeemer: () => Redeemer,
@@ -963,7 +969,7 @@ __export(index_exports, {
963
969
  Script: () => Script,
964
970
  ScriptHash: () => ScriptHash,
965
971
  ScriptPubkey: () => ScriptPubkey,
966
- Serialization: () => import_core7.Serialization,
972
+ Serialization: () => import_core8.Serialization,
967
973
  Slot: () => Slot,
968
974
  StakeCredentialStatus: () => StakeCredentialStatus,
969
975
  StakeDelegation: () => StakeDelegation,
@@ -982,14 +988,21 @@ __export(index_exports, {
982
988
  TransactionBody: () => TransactionBody,
983
989
  TransactionId: () => TransactionId,
984
990
  TransactionInput: () => TransactionInput,
991
+ TransactionMetadatum: () => TransactionMetadatum,
985
992
  TransactionOutput: () => TransactionOutput,
986
993
  TransactionUnspentOutput: () => TransactionUnspentOutput,
987
994
  TransactionWitnessSet: () => TransactionWitnessSet,
995
+ TxIndex: () => TxIndex,
988
996
  Value: () => Value,
989
997
  VkeyWitness: () => VkeyWitness,
990
998
  VrfVkBech32: () => VrfVkBech32,
999
+ addrBech32ToPlutusDataHex: () => addrBech32ToPlutusDataHex,
1000
+ addrBech32ToPlutusDataObj: () => addrBech32ToPlutusDataObj,
991
1001
  addressToBech32: () => addressToBech32,
1002
+ applyEncoding: () => applyEncoding,
1003
+ applyParamsToScript: () => applyParamsToScript,
992
1004
  assetTypes: () => assetTypes,
1005
+ blake2b: () => blake2b2,
993
1006
  buildBaseAddress: () => buildBaseAddress,
994
1007
  buildBip32PrivateKey: () => buildBip32PrivateKey,
995
1008
  buildDRepID: () => buildDRepID,
@@ -997,8 +1010,11 @@ __export(index_exports, {
997
1010
  buildKeys: () => buildKeys,
998
1011
  buildRewardAddress: () => buildRewardAddress,
999
1012
  buildScriptPubkey: () => buildScriptPubkey,
1013
+ bytesToHex: () => bytesToHex,
1000
1014
  checkSignature: () => checkSignature,
1015
+ computeAuxiliaryDataHash: () => computeAuxiliaryDataHash,
1001
1016
  deserializeAddress: () => deserializeAddress,
1017
+ deserializeBech32Address: () => deserializeBech32Address,
1002
1018
  deserializeDataHash: () => deserializeDataHash,
1003
1019
  deserializeEd25519KeyHash: () => deserializeEd25519KeyHash,
1004
1020
  deserializeNativeScript: () => deserializeNativeScript,
@@ -1011,18 +1027,28 @@ __export(index_exports, {
1011
1027
  deserializeTxUnspentOutput: () => deserializeTxUnspentOutput,
1012
1028
  deserializeValue: () => deserializeValue,
1013
1029
  empty: () => empty,
1030
+ fromBuilderToPlutusData: () => fromBuilderToPlutusData,
1031
+ fromJsonToPlutusData: () => fromJsonToPlutusData,
1014
1032
  fromNativeScript: () => fromNativeScript,
1033
+ fromPlutusDataToJson: () => fromPlutusDataToJson,
1015
1034
  fromScriptRef: () => fromScriptRef,
1016
1035
  fromTxUnspentOutput: () => fromTxUnspentOutput,
1017
1036
  fromValue: () => fromValue,
1018
1037
  generateNonce: () => generateNonce,
1019
1038
  getCoseKeyFromPublicKey: () => getCoseKeyFromPublicKey,
1039
+ getDRepIds: () => getDRepIds,
1020
1040
  getPublicKeyFromCoseKey: () => getPublicKeyFromCoseKey,
1041
+ hexToBech32: () => hexToBech32,
1042
+ hexToBytes: () => hexToBytes,
1043
+ keyHashToRewardAddress: () => keyHashToRewardAddress,
1021
1044
  mergeValue: () => mergeValue,
1022
1045
  negateValue: () => negateValue,
1023
1046
  negatives: () => negatives,
1024
1047
  normalizePlutusScript: () => normalizePlutusScript,
1048
+ parseDatumCbor: () => parseDatumCbor,
1049
+ parseInlineDatum: () => parseInlineDatum,
1025
1050
  resolveDataHash: () => resolveDataHash,
1051
+ resolveEd25519KeyHash: () => resolveEd25519KeyHash,
1026
1052
  resolveNativeScriptAddress: () => resolveNativeScriptAddress,
1027
1053
  resolveNativeScriptHash: () => resolveNativeScriptHash,
1028
1054
  resolvePaymentKeyHash: () => resolvePaymentKeyHash,
@@ -1031,23 +1057,34 @@ __export(index_exports, {
1031
1057
  resolvePoolId: () => resolvePoolId,
1032
1058
  resolvePrivateKey: () => resolvePrivateKey,
1033
1059
  resolveRewardAddress: () => resolveRewardAddress,
1060
+ resolveScriptHashDRepId: () => resolveScriptHashDRepId,
1034
1061
  resolveScriptRef: () => resolveScriptRef,
1035
1062
  resolveStakeKeyHash: () => resolveStakeKeyHash,
1036
1063
  resolveTxHash: () => resolveTxHash,
1064
+ scriptHashToBech32: () => scriptHashToBech32,
1065
+ scriptHashToRewardAddress: () => scriptHashToRewardAddress,
1066
+ serializeAddressObj: () => serializeAddressObj,
1067
+ serializePlutusAddressToBech32: () => serializePlutusAddressToBech32,
1068
+ serialzeAddress: () => serialzeAddress,
1037
1069
  signData: () => signData,
1038
1070
  subValue: () => subValue,
1039
1071
  toAddress: () => toAddress,
1040
1072
  toBaseAddress: () => toBaseAddress,
1073
+ toCardanoAddress: () => toCardanoAddress,
1074
+ toDRep: () => toDRep,
1041
1075
  toEnterpriseAddress: () => toEnterpriseAddress,
1042
1076
  toNativeScript: () => toNativeScript,
1043
1077
  toPlutusData: () => toPlutusData,
1044
1078
  toRewardAddress: () => toRewardAddress,
1045
1079
  toScriptRef: () => toScriptRef,
1046
1080
  toTxUnspentOutput: () => toTxUnspentOutput,
1047
- toValue: () => toValue
1081
+ toValue: () => toValue,
1082
+ utf8ToBytes: () => utf8ToBytes,
1083
+ utf8ToHex: () => utf8ToHex,
1084
+ v2ScriptToBech32: () => v2ScriptToBech32
1048
1085
  });
1049
1086
  module.exports = __toCommonJS(index_exports);
1050
- var import_core7 = require("@cardano-sdk/core");
1087
+ var import_core8 = require("@cardano-sdk/core");
1051
1088
 
1052
1089
  // src/types/cardano-sdk.ts
1053
1090
  var import_core = require("@cardano-sdk/core");
@@ -1059,6 +1096,10 @@ var Transaction = import_core.Serialization.Transaction;
1059
1096
  var TransactionId = import_core.Cardano.TransactionId;
1060
1097
  var TransactionBody = import_core.Serialization.TransactionBody;
1061
1098
  var TransactionWitnessSet = import_core.Serialization.TransactionWitnessSet;
1099
+ var AuxilliaryData = import_core.Serialization.AuxiliaryData;
1100
+ var TransactionMetadatum = import_core.Serialization.TransactionMetadatum;
1101
+ var MetadatumMap = import_core.Serialization.MetadatumMap;
1102
+ var MetadatumList = import_core.Serialization.MetadatumList;
1062
1103
  var TransactionUnspentOutput = import_core.Serialization.TransactionUnspentOutput;
1063
1104
  var TransactionInput = import_core.Serialization.TransactionInput;
1064
1105
  var TransactionOutput = import_core.Serialization.TransactionOutput;
@@ -1106,6 +1147,10 @@ var NativeScript = import_core.Serialization.NativeScript;
1106
1147
  var PlutusV1Script = import_core.Serialization.PlutusV1Script;
1107
1148
  var PlutusV2Script = import_core.Serialization.PlutusV2Script;
1108
1149
  var PlutusV3Script = import_core.Serialization.PlutusV3Script;
1150
+ var PlutusDataKind = import_core.Serialization.PlutusDataKind;
1151
+ var PointerAddress = import_core.Cardano.PointerAddress;
1152
+ var CertIndex = import_core.Cardano.CertIndex;
1153
+ var TxIndex = import_core.Cardano.TxIndex;
1109
1154
  var Costmdls = import_core.Serialization.Costmdls;
1110
1155
  var CostModel = import_core.Serialization.CostModel;
1111
1156
  var CborWriter = import_core.Serialization.CborWriter;
@@ -1129,6 +1174,8 @@ var ScriptPubkey = import_core.Serialization.ScriptPubkey;
1129
1174
  var DRepID = import_core.Cardano.DRepID;
1130
1175
  var DRep = import_core.Serialization.DRep;
1131
1176
  var StakeCredentialStatus = import_core.Cardano.StakeCredentialStatus;
1177
+ var computeAuxiliaryDataHash = import_core.Cardano.computeAuxiliaryDataHash;
1178
+ var blake2b2 = Crypto.blake2b;
1132
1179
 
1133
1180
  // src/stricahq/bip32ed25519/wrapper.ts
1134
1181
  var cjsBip32ed25519 = __toESM(require("@stricahq/bip32ed25519"), 1);
@@ -1417,7 +1464,10 @@ var signData = (data, signer) => {
1417
1464
  // src/resolvers/index.ts
1418
1465
  var import_core4 = require("@cardano-sdk/core");
1419
1466
  var import_crypto5 = require("@cardano-sdk/crypto");
1420
- var import_util5 = require("@cardano-sdk/util");
1467
+ var import_util7 = require("@cardano-sdk/util");
1468
+ var import_base32_encoding3 = __toESM(require("base32-encoding"), 1);
1469
+ var import_bech323 = require("bech32");
1470
+ var import_common7 = require("@meshsdk/common");
1421
1471
 
1422
1472
  // src/utils/builder.ts
1423
1473
  var import_crypto2 = require("@cardano-sdk/crypto");
@@ -1516,51 +1566,261 @@ var buildDRepID = (dRepKey, networkId = NetworkId.Testnet, addressType = Address
1516
1566
  // src/utils/converter.ts
1517
1567
  var import_core3 = require("@cardano-sdk/core");
1518
1568
  var import_crypto4 = require("@cardano-sdk/crypto");
1519
- var import_util4 = require("@cardano-sdk/util");
1520
- var import_common4 = require("@meshsdk/common");
1569
+ var import_util5 = require("@cardano-sdk/util");
1570
+ var import_base32_encoding = __toESM(require("base32-encoding"), 1);
1571
+ var import_bech32 = require("bech32");
1572
+ var import_common5 = require("@meshsdk/common");
1521
1573
 
1522
- // src/utils/deserializer.ts
1523
- var import_core2 = require("@cardano-sdk/core");
1524
- var import_crypto3 = require("@cardano-sdk/crypto");
1574
+ // src/utils/data.ts
1525
1575
  var import_util3 = require("@cardano-sdk/util");
1526
1576
  var import_common3 = require("@meshsdk/common");
1527
- var deserializeAddress = (address) => {
1528
- const _address = Address.fromString(address);
1529
- if (_address === null) throw new Error("Invalid address");
1530
- return _address;
1577
+ var toPlutusData = (data) => {
1578
+ const toPlutusList = (data2) => {
1579
+ const plutusList = new PlutusList();
1580
+ data2.forEach((element) => {
1581
+ plutusList.add(toPlutusData(element));
1582
+ });
1583
+ return plutusList;
1584
+ };
1585
+ switch (typeof data) {
1586
+ case "string":
1587
+ return PlutusData.newBytes((0, import_common3.toBytes)(data));
1588
+ case "number":
1589
+ return PlutusData.newInteger(BigInt(data));
1590
+ case "bigint":
1591
+ return PlutusData.newInteger(BigInt(data));
1592
+ case "object":
1593
+ if (data instanceof Array) {
1594
+ const plutusList = toPlutusList(data);
1595
+ return PlutusData.newList(plutusList);
1596
+ } else if (data instanceof Map) {
1597
+ const plutusMap = new PlutusMap();
1598
+ data.forEach((value, key) => {
1599
+ plutusMap.insert(toPlutusData(key), toPlutusData(value));
1600
+ });
1601
+ return PlutusData.newMap(plutusMap);
1602
+ } else {
1603
+ return PlutusData.newConstrPlutusData(
1604
+ new ConstrPlutusData(
1605
+ BigInt(data.alternative),
1606
+ toPlutusList(data.fields)
1607
+ )
1608
+ );
1609
+ }
1610
+ }
1611
+ };
1612
+ var isConstrPlutusDataJson = (data) => {
1613
+ return typeof data === "object" && "constructor" in data && (typeof data.constructor === "number" || typeof data.constructor === "bigint" || typeof data.constructor === "string") && "fields" in data && Array.isArray(data.fields);
1614
+ };
1615
+ function isMapPlutusDataJson(data) {
1616
+ return typeof data === "object" && Array.isArray(data);
1617
+ }
1618
+ function isKeyValuePlutusDataJson(data) {
1619
+ return typeof data === "object" && "k" in data && typeof data.k === "object" && "v" in data && typeof data.v === "object";
1620
+ }
1621
+ var fromJsonToPlutusData = (data) => {
1622
+ if (isConstrPlutusDataJson(data)) {
1623
+ const plutusList = new PlutusList();
1624
+ data.fields.map((val) => {
1625
+ plutusList.add(fromJsonToPlutusData(val));
1626
+ });
1627
+ const plutusConstrData = new ConstrPlutusData(
1628
+ BigInt(data.constructor),
1629
+ plutusList
1630
+ );
1631
+ return PlutusData.newConstrPlutusData(plutusConstrData);
1632
+ } else if ("int" in data && Object.keys(data).length === 1) {
1633
+ if (typeof data.int === "bigint" || typeof data.int === "number" || typeof data.int === "string") {
1634
+ return PlutusData.newInteger(BigInt(data.int));
1635
+ } else {
1636
+ throw new Error(
1637
+ "Malformed int field in Plutus data, expected one of bigint, number or string"
1638
+ );
1639
+ }
1640
+ } else if ("bytes" in data && Object.keys(data).length === 1) {
1641
+ if (typeof data.bytes === "string") {
1642
+ return PlutusData.newBytes(Buffer.from(data.bytes, "hex"));
1643
+ } else {
1644
+ throw new Error("Malformed bytes field in Plutus data, expected string");
1645
+ }
1646
+ } else if ("list" in data && Object.keys(data).length === 1) {
1647
+ if (Array.isArray(data.list)) {
1648
+ const plutusList = new PlutusList();
1649
+ data.list.map((val) => {
1650
+ plutusList.add(fromJsonToPlutusData(val));
1651
+ });
1652
+ return PlutusData.newList(plutusList);
1653
+ } else {
1654
+ throw new Error("Malformed list field in Plutus data, expected list");
1655
+ }
1656
+ } else if ("map" in data && Object.keys(data).length === 1) {
1657
+ if (isMapPlutusDataJson(data.map)) {
1658
+ const plutusMap = new PlutusMap();
1659
+ data.map.forEach((val) => {
1660
+ if (isKeyValuePlutusDataJson(val)) {
1661
+ plutusMap.insert(
1662
+ fromJsonToPlutusData(val.k),
1663
+ fromJsonToPlutusData(val.v)
1664
+ );
1665
+ } else {
1666
+ throw new Error("Malformed key value pair in Plutus data map");
1667
+ }
1668
+ });
1669
+ return PlutusData.newMap(plutusMap);
1670
+ } else {
1671
+ console.log(data);
1672
+ throw new Error("Malformed map field in Plutus data");
1673
+ }
1674
+ } else {
1675
+ throw new Error("Malformed Plutus data json");
1676
+ }
1677
+ };
1678
+ var fromBuilderToPlutusData = (data) => {
1679
+ if (data.type === "Mesh") {
1680
+ return toPlutusData(data.content);
1681
+ } else if (data.type === "CBOR") {
1682
+ return PlutusData.fromCbor((0, import_util3.HexBlob)(data.content));
1683
+ } else if (data.type === "JSON") {
1684
+ let content;
1685
+ if (typeof data.content === "string") {
1686
+ content = JSON.parse(data.content);
1687
+ } else {
1688
+ content = data.content;
1689
+ }
1690
+ return fromJsonToPlutusData(content);
1691
+ } else {
1692
+ throw new Error(
1693
+ "Malformed builder data, expected types of, Mesh, CBOR or JSON"
1694
+ );
1695
+ }
1696
+ };
1697
+ var fromPlutusDataToJson = (data) => {
1698
+ if (data.getKind() === PlutusDataKind.ConstrPlutusData) {
1699
+ const plutusData = data.asConstrPlutusData();
1700
+ if (plutusData) {
1701
+ const fields = plutusData.getData();
1702
+ return {
1703
+ constructor: plutusData.getAlternative(),
1704
+ fields: fromPlutusDataToJson(PlutusData.newList(fields))
1705
+ };
1706
+ } else {
1707
+ throw new Error("Invalid constructor data found");
1708
+ }
1709
+ } else if (data.getKind() === PlutusDataKind.Map) {
1710
+ const plutusMap = data.asMap();
1711
+ const mapList = [];
1712
+ if (plutusMap) {
1713
+ const keys = plutusMap.getKeys();
1714
+ for (let i = 0; i < keys.getLength(); i++) {
1715
+ const key = keys.get(i);
1716
+ const value = plutusMap.get(key);
1717
+ if (value) {
1718
+ mapList.push({
1719
+ k: fromPlutusDataToJson(key),
1720
+ v: fromPlutusDataToJson(value)
1721
+ });
1722
+ }
1723
+ }
1724
+ return {
1725
+ map: mapList
1726
+ };
1727
+ } else {
1728
+ throw new Error("Invalid map data found");
1729
+ }
1730
+ } else if (data.getKind() === PlutusDataKind.List) {
1731
+ const plutusList = data.asList();
1732
+ if (plutusList) {
1733
+ const list = [];
1734
+ for (let i = 0; i < plutusList.getLength(); i++) {
1735
+ const element = plutusList.get(i);
1736
+ list.push(fromPlutusDataToJson(element));
1737
+ }
1738
+ return list;
1739
+ } else {
1740
+ throw new Error("Invalid list data found");
1741
+ }
1742
+ } else if (data.getKind() === PlutusDataKind.Integer) {
1743
+ const plutusInt = data.asInteger();
1744
+ if (plutusInt) {
1745
+ return {
1746
+ int: BigInt(plutusInt.toString())
1747
+ };
1748
+ } else {
1749
+ throw new Error("Invalid integer data found");
1750
+ }
1751
+ } else if (data.getKind() === PlutusDataKind.Bytes) {
1752
+ const plutusBytes = data.asBoundedBytes();
1753
+ if (plutusBytes) {
1754
+ return {
1755
+ bytes: Buffer.from(plutusBytes).toString("hex")
1756
+ };
1757
+ } else {
1758
+ throw new Error("Invalid bytes data found");
1759
+ }
1760
+ } else {
1761
+ throw new Error("Invalid Plutus data found");
1762
+ }
1763
+ };
1764
+ var datumCborToJson = (datumCbor) => {
1765
+ const parsedDatum = PlutusData.fromCbor((0, import_util3.HexBlob)(datumCbor));
1766
+ return fromPlutusDataToJson(parsedDatum);
1767
+ };
1768
+ var parseDatumCbor = (datumCbor) => {
1769
+ return datumCborToJson(datumCbor);
1770
+ };
1771
+ var parseInlineDatum = (utxo) => {
1772
+ const datumCbor = utxo.inline_datum || "";
1773
+ return datumCborToJson(datumCbor);
1531
1774
  };
1532
- var deserializeEd25519KeyHash = (ed25519KeyHash) => Ed25519KeyHash2.fromBytes((0, import_common3.toBytes)(ed25519KeyHash));
1533
1775
  var deserializeDataHash = (dataHash) => DatumHash.fromHexBlob((0, import_util3.HexBlob)(dataHash));
1534
1776
  var deserializePlutusData = (plutusData) => PlutusData.fromCbor((0, import_util3.HexBlob)(plutusData));
1777
+
1778
+ // src/utils/deserializer.ts
1779
+ var import_core2 = require("@cardano-sdk/core");
1780
+ var import_crypto3 = require("@cardano-sdk/crypto");
1781
+ var import_util4 = require("@cardano-sdk/util");
1782
+ var import_common4 = require("@meshsdk/common");
1783
+ var deserializeEd25519KeyHash = (ed25519KeyHash) => Ed25519KeyHash2.fromBytes((0, import_common4.toBytes)(ed25519KeyHash));
1535
1784
  var deserializePlutusScript = (plutusScript, version) => {
1536
1785
  switch (version) {
1537
1786
  case "V1":
1538
- return PlutusV1Script.fromCbor((0, import_util3.HexBlob)(plutusScript));
1787
+ return PlutusV1Script.fromCbor((0, import_util4.HexBlob)(plutusScript));
1539
1788
  case "V2":
1540
- return PlutusV2Script.fromCbor((0, import_util3.HexBlob)(plutusScript));
1789
+ return PlutusV2Script.fromCbor((0, import_util4.HexBlob)(plutusScript));
1541
1790
  case "V3":
1542
- return PlutusV3Script.fromCbor((0, import_util3.HexBlob)(plutusScript));
1791
+ return PlutusV3Script.fromCbor((0, import_util4.HexBlob)(plutusScript));
1543
1792
  default:
1544
1793
  throw new Error("Invalid Plutus script version");
1545
1794
  }
1546
1795
  };
1547
- var deserializeNativeScript = (nativeScript) => NativeScript.fromCbor((0, import_util3.HexBlob)(nativeScript));
1796
+ var deserializeNativeScript = (nativeScript) => NativeScript.fromCbor((0, import_util4.HexBlob)(nativeScript));
1548
1797
  var deserializeScriptHash = (scriptHash) => ScriptHash.fromEd25519KeyHashHex((0, import_crypto3.Ed25519KeyHashHex)(scriptHash));
1549
- var deserializeScriptRef = (scriptRef) => Script.fromCbor((0, import_util3.HexBlob)(scriptRef));
1550
- var deserializeTxUnspentOutput = (txUnspentOutput) => TransactionUnspentOutput.fromCbor((0, import_util3.HexBlob)(txUnspentOutput));
1551
- var deserializeValue = (value) => Value.fromCbor((0, import_util3.HexBlob)(value));
1552
- var deserializeTx = (tx) => Transaction.fromCbor((0, import_core2.TxCBOR)(tx));
1553
- var deserializeTxHash = (txHash) => TransactionId.fromHexBlob((0, import_util3.HexBlob)(txHash));
1798
+ var deserializeScriptRef = (scriptRef) => Script.fromCbor((0, import_util4.HexBlob)(scriptRef));
1799
+ var deserializeTxUnspentOutput = (txUnspentOutput) => TransactionUnspentOutput.fromCbor((0, import_util4.HexBlob)(txUnspentOutput));
1800
+ var deserializeValue = (value) => Value.fromCbor((0, import_util4.HexBlob)(value));
1801
+ var deserializeTx = (tx) => Transaction.fromCbor(import_core2.Serialization.TxCBOR(tx));
1802
+ var deserializeTxHash = (txHash) => TransactionId.fromHexBlob((0, import_util4.HexBlob)(txHash));
1554
1803
 
1555
1804
  // src/utils/converter.ts
1556
- var toAddress = (bech32) => Address.fromBech32(bech32);
1557
- var toBaseAddress = (bech32) => {
1558
- return BaseAddress.fromAddress(toAddress(bech32));
1805
+ var toAddress = (bech325) => Address.fromBech32(bech325);
1806
+ var toCardanoAddress = (address) => {
1807
+ try {
1808
+ return Address.fromBech32(address);
1809
+ } catch {
1810
+ try {
1811
+ return Address.fromBase58(address);
1812
+ } catch {
1813
+ throw new Error("Invalid address format");
1814
+ }
1815
+ }
1816
+ };
1817
+ var toBaseAddress = (bech325) => {
1818
+ return BaseAddress.fromAddress(toAddress(bech325));
1559
1819
  };
1560
- var toEnterpriseAddress = (bech32) => {
1561
- return EnterpriseAddress.fromAddress(toAddress(bech32));
1820
+ var toEnterpriseAddress = (bech325) => {
1821
+ return EnterpriseAddress.fromAddress(toAddress(bech325));
1562
1822
  };
1563
- var toRewardAddress = (bech32) => RewardAddress.fromAddress(toAddress(bech32));
1823
+ var toRewardAddress = (bech325) => RewardAddress.fromAddress(toAddress(bech325));
1564
1824
  var fromTxUnspentOutput = (txUnspentOutput) => {
1565
1825
  const dataHash = txUnspentOutput.output().datum() ? txUnspentOutput.output().datum()?.toCbor().toString() : void 0;
1566
1826
  const scriptRef = txUnspentOutput.output().scriptRef() ? txUnspentOutput.output().scriptRef()?.toCbor().toString() : void 0;
@@ -1644,7 +1904,7 @@ var toScriptRef = (script) => {
1644
1904
  return Script.newNativeScript(toNativeScript(script));
1645
1905
  };
1646
1906
  var fromScriptRef = (scriptRef) => {
1647
- const script = Script.fromCbor((0, import_util4.HexBlob)(scriptRef));
1907
+ const script = Script.fromCbor((0, import_util5.HexBlob)(scriptRef));
1648
1908
  const plutusScriptCodeV3 = script.asPlutusV3()?.toCbor().toString();
1649
1909
  if (plutusScriptCodeV3) {
1650
1910
  return {
@@ -1766,46 +2026,11 @@ var toNativeScript = (script) => {
1766
2026
  case "sig":
1767
2027
  return NativeScript.newScriptPubkey(
1768
2028
  new import_core3.Serialization.ScriptPubkey(
1769
- import_crypto4.Ed25519KeyHash.fromBytes((0, import_common4.toBytes)(script.keyHash)).hex()
2029
+ import_crypto4.Ed25519KeyHash.fromBytes((0, import_common5.toBytes)(script.keyHash)).hex()
1770
2030
  )
1771
2031
  );
1772
2032
  }
1773
2033
  };
1774
- var toPlutusData = (data) => {
1775
- const toPlutusList = (data2) => {
1776
- const plutusList = new PlutusList();
1777
- data2.forEach((element) => {
1778
- plutusList.add(toPlutusData(element));
1779
- });
1780
- return plutusList;
1781
- };
1782
- switch (typeof data) {
1783
- case "string":
1784
- return PlutusData.newBytes((0, import_common4.toBytes)(data));
1785
- case "number":
1786
- return PlutusData.newInteger(BigInt(data));
1787
- case "bigint":
1788
- return PlutusData.newInteger(BigInt(data));
1789
- case "object":
1790
- if (data instanceof Array) {
1791
- const plutusList = toPlutusList(data);
1792
- return PlutusData.newList(plutusList);
1793
- } else if (data instanceof Map) {
1794
- const plutusMap = new PlutusMap();
1795
- data.forEach((value, key) => {
1796
- plutusMap.insert(toPlutusData(key), toPlutusData(value));
1797
- });
1798
- return PlutusData.newMap(plutusMap);
1799
- } else {
1800
- return PlutusData.newConstrPlutusData(
1801
- new ConstrPlutusData(
1802
- BigInt(data.alternative),
1803
- toPlutusList(data.fields)
1804
- )
1805
- );
1806
- }
1807
- }
1808
- };
1809
2034
  var toValue = (assets) => {
1810
2035
  const multiAsset = /* @__PURE__ */ new Map();
1811
2036
  assets.filter((asset) => asset.unit !== "lovelace").forEach((asset) => {
@@ -1818,6 +2043,102 @@ var toValue = (assets) => {
1818
2043
  }
1819
2044
  return value;
1820
2045
  };
2046
+ var toDRep = (dRepId) => {
2047
+ if (dRepId.length === 58) {
2048
+ const { prefix, words } = import_bech32.bech32.decode(dRepId);
2049
+ if (prefix !== "drep") {
2050
+ throw new Error("Invalid DRepId prefix");
2051
+ }
2052
+ const bytes = import_base32_encoding.default.decode(new Uint8Array(words));
2053
+ if (bytes[0] === 34) {
2054
+ return import_core3.Serialization.DRep.newKeyHash(
2055
+ Ed25519KeyHashHex2(bytes.subarray(1).toString("hex"))
2056
+ );
2057
+ } else if (bytes[0] === 35) {
2058
+ return import_core3.Serialization.DRep.newScriptHash(
2059
+ Hash28ByteBase162(bytes.subarray(1).toString("hex"))
2060
+ );
2061
+ } else {
2062
+ throw new Error("Malformed CIP129 DRepId");
2063
+ }
2064
+ } else {
2065
+ const { prefix, words } = import_bech32.bech32.decode(dRepId);
2066
+ switch (prefix) {
2067
+ case "drep": {
2068
+ return import_core3.Serialization.DRep.newKeyHash(
2069
+ Ed25519KeyHashHex2(
2070
+ import_base32_encoding.default.decode(new Uint8Array(words)).toString("hex")
2071
+ )
2072
+ );
2073
+ }
2074
+ case "drep_script": {
2075
+ return import_core3.Serialization.DRep.newScriptHash(
2076
+ Hash28ByteBase162(
2077
+ import_base32_encoding.default.decode(new Uint8Array(words)).toString("hex")
2078
+ )
2079
+ );
2080
+ }
2081
+ default: {
2082
+ throw new Error("Malformed DRepId prefix");
2083
+ }
2084
+ }
2085
+ }
2086
+ };
2087
+ var getDRepIds = (dRepId) => {
2088
+ let result = {
2089
+ cip105: "",
2090
+ cip129: ""
2091
+ };
2092
+ if (dRepId.length === 58) {
2093
+ result.cip129 = dRepId;
2094
+ const { prefix, words } = import_bech32.bech32.decode(dRepId);
2095
+ if (prefix !== "drep") {
2096
+ throw new Error("Malformed CIP129 DRepId");
2097
+ }
2098
+ const bytes = import_base32_encoding.default.decode(new Uint8Array(words));
2099
+ if (bytes[0] === 34) {
2100
+ result.cip105 = import_bech32.bech32.encode("drep", import_base32_encoding.default.encode(bytes.subarray(1)));
2101
+ } else if (bytes[0] === 35) {
2102
+ result.cip105 = import_bech32.bech32.encode(
2103
+ "drep_script",
2104
+ import_base32_encoding.default.encode(bytes.subarray(1))
2105
+ );
2106
+ } else {
2107
+ throw new Error("Malformed CIP129 DRepId");
2108
+ }
2109
+ } else {
2110
+ result.cip105 = dRepId;
2111
+ try {
2112
+ const { prefix, words } = import_bech32.bech32.decode(dRepId);
2113
+ let rawBytes = import_base32_encoding.default.decode(new Uint8Array(words));
2114
+ if (prefix === "drep") {
2115
+ if (!rawBytes) {
2116
+ throw new Error("Malformed key hash in DRepId");
2117
+ }
2118
+ let rawBytesWithPrefix = new Uint8Array(rawBytes.length + 1);
2119
+ rawBytesWithPrefix.set([34]);
2120
+ rawBytesWithPrefix.set(rawBytes, 1);
2121
+ let base32RawBytes = import_base32_encoding.default.encode(rawBytesWithPrefix);
2122
+ result.cip129 = import_bech32.bech32.encode("drep", base32RawBytes);
2123
+ } else if (prefix === "drep_script") {
2124
+ if (!rawBytes) {
2125
+ throw new Error("Malformed script hash in DRepId");
2126
+ }
2127
+ let rawBytesWithPrefix = new Uint8Array(rawBytes.length + 1);
2128
+ rawBytesWithPrefix.set([35]);
2129
+ rawBytesWithPrefix.set(rawBytes, 1);
2130
+ let base32RawBytes = import_base32_encoding.default.encode(rawBytesWithPrefix);
2131
+ result.cip129 = import_bech32.bech32.encode("drep", base32RawBytes);
2132
+ } else {
2133
+ throw new Error("Can only calculate DRepIds for script/key DReps");
2134
+ }
2135
+ } catch (e) {
2136
+ console.error(e);
2137
+ throw new Error("Malformed DRepId");
2138
+ }
2139
+ }
2140
+ return result;
2141
+ };
1821
2142
 
1822
2143
  // src/utils/value.ts
1823
2144
  function mergeValue(a, b) {
@@ -1875,112 +2196,889 @@ function empty(v) {
1875
2196
  return assetTypes(v) == 0;
1876
2197
  }
1877
2198
 
1878
- // src/utils/encoding.ts
1879
- var hexToBytes = (hex) => Buffer.from(hex, "hex");
1880
-
1881
- // src/resolvers/index.ts
1882
- var resolveDataHash = (data) => {
1883
- const plutusData = toPlutusData(data);
1884
- return plutusData.hash().toString();
1885
- };
1886
- var resolveNativeScriptAddress = (script, networkId = 0) => {
1887
- const nativeScript = toNativeScript(script);
1888
- const enterpriseAddress = EnterpriseAddress.fromCredentials(networkId, {
1889
- hash: nativeScript.hash(),
1890
- type: import_core4.Cardano.CredentialType.ScriptHash
1891
- });
1892
- return enterpriseAddress.toAddress().toBech32();
1893
- };
1894
- var resolveNativeScriptHash = (script) => {
1895
- return toNativeScript(script).hash().toString();
1896
- };
1897
- var resolvePaymentKeyHash = (bech32) => {
1898
- try {
1899
- const paymentKeyHash = [
1900
- toBaseAddress(bech32)?.getPaymentCredential().hash,
1901
- toEnterpriseAddress(bech32)?.getPaymentCredential().hash
1902
- ].find((kh) => kh !== void 0);
1903
- if (paymentKeyHash !== void 0) return paymentKeyHash.toString();
2199
+ // src/utils/address.ts
2200
+ var import_util6 = require("@cardano-sdk/util");
2201
+ var import_common6 = require("@meshsdk/common");
2202
+ var serialzeAddress = (deserializedAddress, networkId = 0) => {
2203
+ const {
2204
+ pubKeyHash,
2205
+ scriptHash,
2206
+ stakeCredentialHash,
2207
+ stakeScriptCredentialHash
2208
+ } = deserializedAddress;
2209
+ const isPaymentScript = !pubKeyHash;
2210
+ const isStakeScript = !stakeCredentialHash;
2211
+ const paymentHash = isPaymentScript ? scriptHash : pubKeyHash;
2212
+ const stakeHash = isStakeScript ? stakeScriptCredentialHash : stakeCredentialHash;
2213
+ if (!paymentHash)
1904
2214
  throw new Error(
1905
- `Couldn't resolve payment key hash from address: ${bech32}`
2215
+ "Error: serializeAddress: Address must contain a payment part"
1906
2216
  );
1907
- } catch (error) {
2217
+ const addressObj = isPaymentScript ? (0, import_common6.scriptAddress)(paymentHash, stakeHash, isStakeScript) : (0, import_common6.pubKeyAddress)(paymentHash, stakeHash, isStakeScript);
2218
+ return serializeAddressObj(addressObj, networkId);
2219
+ };
2220
+ var addrBech32ToPlutusData = (bech325) => {
2221
+ const cardanoAddress = Address.fromBech32(bech325);
2222
+ const cardanoAddressProps = cardanoAddress.getProps();
2223
+ const paymentPartList = new PlutusList();
2224
+ if (!cardanoAddressProps.paymentPart) {
1908
2225
  throw new Error(
1909
- `An error occurred during resolvePaymentKeyHash: ${error}.`
2226
+ "Error: addrBech32ToPlutusDataHex: Address must contain a payment part"
1910
2227
  );
1911
2228
  }
1912
- };
1913
- var resolvePlutusScriptAddress = (script, networkId = 0) => {
1914
- const plutusScript = deserializePlutusScript(script.code, script.version);
1915
- const enterpriseAddress = EnterpriseAddress.fromCredentials(networkId, {
1916
- hash: plutusScript.hash(),
1917
- type: import_core4.Cardano.CredentialType.ScriptHash
1918
- });
1919
- return enterpriseAddress.toAddress().toBech32();
1920
- };
1921
- var resolvePlutusScriptHash = (bech32) => {
1922
- try {
1923
- const enterpriseAddress = toEnterpriseAddress(bech32);
1924
- const scriptHash = enterpriseAddress?.getPaymentCredential().hash;
1925
- if (scriptHash !== void 0) return scriptHash.toString();
1926
- throw new Error(`Couldn't resolve script hash from address: ${bech32}`);
1927
- } catch (error) {
1928
- throw new Error(`An error occurred during resolveScriptHash: ${error}.`);
2229
+ paymentPartList.add(
2230
+ PlutusData.newBytes(
2231
+ Buffer.from(cardanoAddressProps.paymentPart.hash, "hex")
2232
+ )
2233
+ );
2234
+ const paymentPart = PlutusData.newConstrPlutusData(
2235
+ new ConstrPlutusData(
2236
+ BigInt(cardanoAddressProps.paymentPart.type),
2237
+ paymentPartList
2238
+ )
2239
+ );
2240
+ const delegationPartList = new PlutusList();
2241
+ let delegationPart;
2242
+ if (cardanoAddressProps.delegationPart) {
2243
+ delegationPartList.add(
2244
+ PlutusData.newBytes(
2245
+ Buffer.from(cardanoAddressProps.delegationPart.hash, "hex")
2246
+ )
2247
+ );
2248
+ const inlineDelegationPart = PlutusData.newConstrPlutusData(
2249
+ new ConstrPlutusData(BigInt(0), delegationPartList)
2250
+ );
2251
+ const someList = new PlutusList();
2252
+ someList.add(inlineDelegationPart);
2253
+ delegationPart = PlutusData.newConstrPlutusData(
2254
+ new ConstrPlutusData(BigInt(0), someList)
2255
+ );
2256
+ } else if (cardanoAddressProps.pointer) {
2257
+ const pointerList = new PlutusList();
2258
+ pointerList.add(
2259
+ PlutusData.newInteger(BigInt(cardanoAddressProps.pointer.slot))
2260
+ );
2261
+ pointerList.add(
2262
+ PlutusData.newInteger(BigInt(cardanoAddressProps.pointer.txIndex))
2263
+ );
2264
+ pointerList.add(
2265
+ PlutusData.newInteger(BigInt(cardanoAddressProps.pointer.certIndex))
2266
+ );
2267
+ const pointer = PlutusData.newConstrPlutusData(
2268
+ new ConstrPlutusData(BigInt(1), pointerList)
2269
+ );
2270
+ const someList = new PlutusList();
2271
+ someList.add(pointer);
2272
+ delegationPart = PlutusData.newConstrPlutusData(
2273
+ new ConstrPlutusData(BigInt(0), someList)
2274
+ );
2275
+ } else {
2276
+ delegationPart = PlutusData.newConstrPlutusData(
2277
+ new ConstrPlutusData(BigInt(1), new PlutusList())
2278
+ );
1929
2279
  }
2280
+ const addressList = new PlutusList();
2281
+ addressList.add(paymentPart);
2282
+ addressList.add(delegationPart);
2283
+ return PlutusData.newConstrPlutusData(
2284
+ new ConstrPlutusData(BigInt(0), addressList)
2285
+ );
1930
2286
  };
1931
- var resolvePoolId = (hash) => {
1932
- return Ed25519KeyHashHex2(hash).toString();
1933
- };
1934
- var resolvePrivateKey = (words) => {
1935
- return "not implemented";
2287
+ var addrBech32ToPlutusDataHex = (bech325) => {
2288
+ return addrBech32ToPlutusData(bech325).toCbor();
1936
2289
  };
1937
- var resolveScriptRef = (script) => {
1938
- return toScriptRef(script).toCbor().toString();
2290
+ var addrBech32ToPlutusDataObj = (bech325) => {
2291
+ return fromPlutusDataToJson(addrBech32ToPlutusData(bech325));
1939
2292
  };
1940
- var resolveRewardAddress = (bech32) => {
1941
- try {
1942
- const address = toAddress(bech32);
1943
- const baseAddress = toBaseAddress(bech32);
1944
- const stakeKeyHash = baseAddress?.getStakeCredential().hash;
1945
- if (stakeKeyHash !== void 0)
1946
- return buildRewardAddress(address.getNetworkId(), stakeKeyHash).toAddress().toBech32();
1947
- throw new Error(`Couldn't resolve reward address from address: ${bech32}`);
1948
- } catch (error) {
1949
- throw new Error(`An error occurred during resolveRewardAddress: ${error}.`);
2293
+ var plutusDataToAddrBech32 = (plutusData, networkId = 0) => {
2294
+ const constrPlutusData = plutusData.asConstrPlutusData();
2295
+ if (!constrPlutusData || constrPlutusData.getAlternative() !== BigInt(0)) {
2296
+ throw new Error(
2297
+ "Error: serializeAddressObj: Address must contain a constructor 0"
2298
+ );
1950
2299
  }
1951
- };
1952
- var resolveStakeKeyHash = (bech32) => {
1953
- try {
1954
- const stakeKeyHash = [
1955
- toBaseAddress(bech32)?.getStakeCredential().hash,
1956
- toRewardAddress(bech32)?.getPaymentCredential().hash
1957
- ].find((kh) => kh !== void 0);
1958
- if (stakeKeyHash !== void 0) return stakeKeyHash.toString();
1959
- throw new Error(`Couldn't resolve stake key hash from address: ${bech32}`);
1960
- } catch (error) {
1961
- throw new Error(`An error occurred during resolveStakeKeyHash: ${error}.`);
2300
+ const plutusDataList = constrPlutusData.getData();
2301
+ if (plutusDataList.getLength() !== 2) {
2302
+ throw new Error("Error: serializeAddressObj: Address must contain 2 parts");
1962
2303
  }
1963
- };
1964
- var resolveTxHash = (txHex) => {
2304
+ const paymentData = plutusDataList.get(0);
2305
+ const paymentConstrData = paymentData.asConstrPlutusData();
2306
+ if (!paymentConstrData) {
2307
+ throw new Error(
2308
+ "Error: serializeAddressObj: Payment part must be a constructor"
2309
+ );
2310
+ }
2311
+ const paymentConstrDataList = paymentConstrData.getData();
2312
+ if (paymentConstrDataList.getLength() !== 1) {
2313
+ throw new Error(
2314
+ "Error: serializeAddressObj: Payment part must contain 1 element"
2315
+ );
2316
+ }
2317
+ const paymentBytes = paymentConstrDataList.get(0).asBoundedBytes();
2318
+ if (!paymentBytes) {
2319
+ throw new Error(
2320
+ "Error: serializeAddressObj: Payment inner part must be bytes"
2321
+ );
2322
+ }
2323
+ if (paymentConstrData.getAlternative() !== BigInt(0) && paymentConstrData.getAlternative() !== BigInt(1)) {
2324
+ throw new Error(
2325
+ "Error: serializeAddressObj: Payment part must be alternative 0 or 1"
2326
+ );
2327
+ }
2328
+ const cardanoPaymentCredential = {
2329
+ hash: Hash28ByteBase162(Buffer.from(paymentBytes).toString("hex")),
2330
+ type: paymentConstrData.getAlternative() === BigInt(0) ? 0 : 1
2331
+ };
2332
+ const delegationData = plutusDataList.get(1);
2333
+ const delegationConstrData = delegationData.asConstrPlutusData();
2334
+ if (!delegationConstrData) {
2335
+ throw new Error(
2336
+ "Error: serializeAddressObj: Delegation part must be a constructor"
2337
+ );
2338
+ }
2339
+ if (delegationConstrData.getAlternative() === BigInt(1)) {
2340
+ return EnterpriseAddress.fromCredentials(
2341
+ networkId,
2342
+ cardanoPaymentCredential
2343
+ ).toAddress().toBech32();
2344
+ } else if (delegationConstrData.getAlternative() === BigInt(0)) {
2345
+ const delegationDataList = delegationConstrData.getData();
2346
+ if (delegationDataList.getLength() !== 1) {
2347
+ throw new Error(
2348
+ "Error: serializeAddressObj: Delegation part must contain 1 element"
2349
+ );
2350
+ }
2351
+ const delegationDataInner = delegationDataList.get(0);
2352
+ const delegationDataInnerConstrData = delegationDataInner.asConstrPlutusData();
2353
+ if (!delegationDataInnerConstrData) {
2354
+ throw new Error(
2355
+ "Error: serializeAddressObj: Delegation inner part must be a constructor"
2356
+ );
2357
+ }
2358
+ if (delegationDataInnerConstrData.getAlternative() === BigInt(0)) {
2359
+ const delegationDataInnerList = delegationDataInnerConstrData.getData();
2360
+ if (delegationDataInnerList.getLength() !== 1) {
2361
+ throw new Error(
2362
+ "Error: serializeAddressObj: Delegation inner part must contain 1 element"
2363
+ );
2364
+ }
2365
+ const delegationBytes = delegationDataInnerList.get(0).asBoundedBytes();
2366
+ if (!delegationBytes) {
2367
+ throw new Error(
2368
+ "Error: serializeAddressObj: Delegation inner part must be bytes"
2369
+ );
2370
+ }
2371
+ const cardanoStakeCredential = {
2372
+ hash: Hash28ByteBase162(Buffer.from(delegationBytes).toString("hex")),
2373
+ type: delegationDataInnerConstrData.getAlternative() === BigInt(0) ? 0 : 1
2374
+ };
2375
+ return BaseAddress.fromCredentials(
2376
+ networkId,
2377
+ cardanoPaymentCredential,
2378
+ cardanoStakeCredential
2379
+ ).toAddress().toBech32();
2380
+ } else if (delegationDataInnerConstrData.getAlternative() === BigInt(1)) {
2381
+ const delegationDataInnerList = delegationDataInnerConstrData.getData();
2382
+ if (delegationDataInnerList.getLength() !== 3) {
2383
+ throw new Error(
2384
+ "Error: serializeAddressObj: Delegation inner part must contain 3 elements"
2385
+ );
2386
+ }
2387
+ const slot = delegationDataInnerList.get(0).asInteger();
2388
+ if (!slot) {
2389
+ throw new Error(
2390
+ "Error: serializeAddressObj: Delegation inner part slot must be integer"
2391
+ );
2392
+ }
2393
+ const txIndex = delegationDataInnerList.get(1).asInteger();
2394
+ if (!txIndex) {
2395
+ throw new Error(
2396
+ "Error: serializeAddressObj: Delegation inner part txIndex must be integer"
2397
+ );
2398
+ }
2399
+ const certIndex = delegationDataInnerList.get(2).asInteger();
2400
+ if (!certIndex) {
2401
+ throw new Error(
2402
+ "Error: serializeAddressObj: Delegation inner part certIndex must be integer"
2403
+ );
2404
+ }
2405
+ const cardanoPointer = {
2406
+ slot,
2407
+ txIndex: TxIndex(Number(txIndex)),
2408
+ certIndex: CertIndex(Number(certIndex))
2409
+ };
2410
+ return PointerAddress.fromCredentials(
2411
+ networkId,
2412
+ cardanoPaymentCredential,
2413
+ cardanoPointer
2414
+ ).toAddress().toBech32();
2415
+ } else {
2416
+ throw new Error(
2417
+ "Error: serializeAddressObj: Delegation inner part must be alternative 0 or 1"
2418
+ );
2419
+ }
2420
+ } else {
2421
+ throw new Error(
2422
+ "Error: serializeAddressObj: Delegation part must be alternative 0 or 1"
2423
+ );
2424
+ }
2425
+ };
2426
+ var serializeAddressObj = (plutusDataAddressObject, networkId = 0) => {
2427
+ const cardanoPlutusData = fromJsonToPlutusData(plutusDataAddressObject);
2428
+ return plutusDataToAddrBech32(cardanoPlutusData, networkId);
2429
+ };
2430
+ var serializePlutusAddressToBech32 = (plutusHex, networkId = 0) => {
2431
+ const cardanoPlutusData = PlutusData.fromCbor((0, import_util6.HexBlob)(plutusHex));
2432
+ return plutusDataToAddrBech32(cardanoPlutusData, networkId);
2433
+ };
2434
+ var deserializeBech32Address = (bech32Addr) => {
2435
+ const deserializedAddress = Address.fromBech32(bech32Addr).getProps();
2436
+ return {
2437
+ pubKeyHash: deserializedAddress.paymentPart?.type === CredentialType.KeyHash ? deserializedAddress.paymentPart?.hash : "",
2438
+ scriptHash: deserializedAddress.paymentPart?.type === CredentialType.ScriptHash ? deserializedAddress.paymentPart?.hash : "",
2439
+ stakeCredentialHash: deserializedAddress.delegationPart?.type === CredentialType.KeyHash ? deserializedAddress.delegationPart?.hash : "",
2440
+ stakeScriptCredentialHash: deserializedAddress.delegationPart?.type === CredentialType.ScriptHash ? deserializedAddress.delegationPart?.hash : ""
2441
+ };
2442
+ };
2443
+ var deserializeAddress = (address) => {
2444
+ const _address = Address.fromString(address);
2445
+ if (_address === null) throw new Error("Invalid address");
2446
+ return _address;
2447
+ };
2448
+ var scriptHashToBech32 = (scriptHash, stakeCredentialHash, networkId = 0, isScriptStakeCredentialHash = false) => {
2449
+ if (stakeCredentialHash) {
2450
+ return BaseAddress.fromCredentials(
2451
+ networkId,
2452
+ { hash: Hash28ByteBase162(scriptHash), type: CredentialType.ScriptHash },
2453
+ {
2454
+ hash: Hash28ByteBase162(stakeCredentialHash),
2455
+ type: isScriptStakeCredentialHash ? CredentialType.ScriptHash : CredentialType.KeyHash
2456
+ }
2457
+ ).toAddress().toBech32().toString();
2458
+ } else {
2459
+ return EnterpriseAddress.fromCredentials(networkId, {
2460
+ hash: Hash28ByteBase162(scriptHash),
2461
+ type: CredentialType.ScriptHash
2462
+ }).toAddress().toBech32().toString();
2463
+ }
2464
+ };
2465
+ var v2ScriptToBech32 = (scriptCbor, stakeCredential, networkId = 0, isScriptStakeCredential = false) => scriptHashToBech32(
2466
+ Script.fromCbor((0, import_util6.HexBlob)(scriptCbor)).hash().toString(),
2467
+ stakeCredential,
2468
+ networkId,
2469
+ isScriptStakeCredential
2470
+ );
2471
+ var scriptHashToRewardAddress = (hash, networkId = 0) => {
2472
+ return RewardAddress.fromCredentials(networkId, {
2473
+ hash: Hash28ByteBase162(hash),
2474
+ type: CredentialType.ScriptHash
2475
+ }).toAddress().toBech32().toString();
2476
+ };
2477
+ var keyHashToRewardAddress = (hash, networkId = 0) => {
2478
+ return RewardAddress.fromCredentials(networkId, {
2479
+ hash: Hash28ByteBase162(hash),
2480
+ type: CredentialType.KeyHash
2481
+ }).toAddress().toBech32().toString();
2482
+ };
2483
+
2484
+ // src/utils/encoding.ts
2485
+ var import_base32_encoding2 = __toESM(require("base32-encoding"), 1);
2486
+ var import_bech322 = require("bech32");
2487
+ var bytesToHex = (bytes) => Buffer.from(bytes).toString("hex");
2488
+ var hexToBytes = (hex) => Buffer.from(hex, "hex");
2489
+ var utf8ToBytes = (str) => Buffer.from(str, "utf8");
2490
+ var utf8ToHex = (str) => Buffer.from(str, "utf8").toString("hex");
2491
+ var hexToBech32 = (prefix, hex) => {
2492
+ const buf = Buffer.from(hex, "hex");
2493
+ const base32RawBytes = import_base32_encoding2.default.encode(buf);
2494
+ return import_bech322.bech32.encode(prefix, base32RawBytes);
2495
+ };
2496
+
2497
+ // src/resolvers/index.ts
2498
+ var resolveDataHash = (data) => {
2499
+ const plutusData = toPlutusData(data);
2500
+ return plutusData.hash().toString();
2501
+ };
2502
+ var resolveNativeScriptAddress = (script, networkId = 0) => {
2503
+ const nativeScript = toNativeScript(script);
2504
+ const enterpriseAddress = EnterpriseAddress.fromCredentials(networkId, {
2505
+ hash: nativeScript.hash(),
2506
+ type: import_core4.Cardano.CredentialType.ScriptHash
2507
+ });
2508
+ return enterpriseAddress.toAddress().toBech32().toString();
2509
+ };
2510
+ var resolveNativeScriptHash = (script) => {
2511
+ return toNativeScript(script).hash().toString();
2512
+ };
2513
+ var resolvePaymentKeyHash = (bech325) => {
2514
+ try {
2515
+ const paymentKeyHash = [
2516
+ toBaseAddress(bech325)?.getPaymentCredential().hash,
2517
+ toEnterpriseAddress(bech325)?.getPaymentCredential().hash
2518
+ ].find((kh) => kh !== void 0);
2519
+ if (paymentKeyHash !== void 0) return paymentKeyHash.toString();
2520
+ throw new Error(
2521
+ `Couldn't resolve payment key hash from address: ${bech325}`
2522
+ );
2523
+ } catch (error) {
2524
+ throw new Error(
2525
+ `An error occurred during resolvePaymentKeyHash: ${error}.`
2526
+ );
2527
+ }
2528
+ };
2529
+ var resolvePlutusScriptAddress = (script, networkId = 0) => {
2530
+ const plutusScript = deserializePlutusScript(script.code, script.version);
2531
+ const enterpriseAddress = EnterpriseAddress.fromCredentials(networkId, {
2532
+ hash: plutusScript.hash(),
2533
+ type: import_core4.Cardano.CredentialType.ScriptHash
2534
+ });
2535
+ return enterpriseAddress.toAddress().toBech32().toString();
2536
+ };
2537
+ var resolvePlutusScriptHash = (bech325) => {
2538
+ try {
2539
+ const enterpriseAddress = toEnterpriseAddress(bech325);
2540
+ const scriptHash = enterpriseAddress?.getPaymentCredential().hash;
2541
+ if (scriptHash !== void 0) return scriptHash.toString();
2542
+ throw new Error(`Couldn't resolve script hash from address: ${bech325}`);
2543
+ } catch (error) {
2544
+ throw new Error(`An error occurred during resolveScriptHash: ${error}.`);
2545
+ }
2546
+ };
2547
+ var resolvePoolId = (hash) => {
2548
+ return PoolId.fromKeyHash(Ed25519KeyHashHex2(hash)).toString();
2549
+ };
2550
+ var resolvePrivateKey = (words) => {
2551
+ const buildBip32PrivateKey2 = (entropy2, password = "") => {
2552
+ return Bip32PrivateKey2.fromBip39Entropy(
2553
+ Buffer.from((0, import_common7.toBytes)(entropy2)),
2554
+ (0, import_common7.fromUTF8)(password)
2555
+ );
2556
+ };
2557
+ const entropy = (0, import_common7.mnemonicToEntropy)(words.join(" "));
2558
+ const bip32PrivateKey = buildBip32PrivateKey2(entropy);
2559
+ const bytes = import_base32_encoding3.default.encode(bip32PrivateKey.bytes());
2560
+ const bech32PrivateKey = import_bech323.bech32.encode("xprv", bytes, 1023);
2561
+ return bech32PrivateKey;
2562
+ };
2563
+ var resolveScriptRef = (script) => {
2564
+ return toScriptRef(script).toCbor().toString();
2565
+ };
2566
+ var resolveRewardAddress = (bech325) => {
2567
+ try {
2568
+ const address = toAddress(bech325);
2569
+ const baseAddress = toBaseAddress(bech325);
2570
+ const stakeKeyHash = baseAddress?.getStakeCredential().hash;
2571
+ if (stakeKeyHash !== void 0)
2572
+ return buildRewardAddress(address.getNetworkId(), stakeKeyHash).toAddress().toBech32().toString();
2573
+ throw new Error(`Couldn't resolve reward address from address: ${bech325}`);
2574
+ } catch (error) {
2575
+ throw new Error(`An error occurred during resolveRewardAddress: ${error}.`);
2576
+ }
2577
+ };
2578
+ var resolveStakeKeyHash = (bech325) => {
2579
+ try {
2580
+ const stakeKeyHash = [
2581
+ toBaseAddress(bech325)?.getStakeCredential().hash,
2582
+ toRewardAddress(bech325)?.getPaymentCredential().hash
2583
+ ].find((kh) => kh !== void 0);
2584
+ if (stakeKeyHash !== void 0) return stakeKeyHash.toString();
2585
+ throw new Error(`Couldn't resolve stake key hash from address: ${bech325}`);
2586
+ } catch (error) {
2587
+ throw new Error(`An error occurred during resolveStakeKeyHash: ${error}.`);
2588
+ }
2589
+ };
2590
+ var resolveTxHash = (txHex) => {
1965
2591
  const txBody = deserializeTx(txHex).body();
1966
2592
  const hash = (0, import_crypto5.blake2b)(import_crypto5.blake2b.BYTES).update(hexToBytes(txBody.toCbor())).digest();
1967
- return import_core4.Cardano.TransactionId.fromHexBlob(import_util5.HexBlob.fromBytes(hash));
2593
+ return import_core4.Cardano.TransactionId.fromHexBlob(import_util7.HexBlob.fromBytes(hash)).toString();
2594
+ };
2595
+ var resolveScriptHashDRepId = (scriptHash) => {
2596
+ return DRepID.cip129FromCredential({
2597
+ type: import_core4.Cardano.CredentialType.ScriptHash,
2598
+ hash: Hash28ByteBase162(scriptHash)
2599
+ }).toString();
2600
+ };
2601
+ var resolveEd25519KeyHash = (bech325) => {
2602
+ try {
2603
+ const keyHash = [
2604
+ toBaseAddress(bech325)?.getPaymentCredential().hash,
2605
+ toEnterpriseAddress(bech325)?.getPaymentCredential().hash
2606
+ ].find((kh) => kh !== void 0);
2607
+ if (keyHash !== void 0) return keyHash.toString();
2608
+ throw new Error(`Couldn't resolve key hash from address: ${bech325}`);
2609
+ } catch (error) {
2610
+ throw new Error(
2611
+ `An error occurred during resolveEd25519KeyHash: ${error}.`
2612
+ );
2613
+ }
1968
2614
  };
1969
2615
 
1970
2616
  // src/serializer/index.ts
1971
- var import_core6 = require("@cardano-sdk/core");
1972
- var import_util7 = require("@cardano-sdk/util");
1973
- var import_common5 = require("@meshsdk/common");
2617
+ var import_core7 = require("@cardano-sdk/core");
2618
+ var import_util9 = require("@cardano-sdk/util");
2619
+ var import_cbor = require("@harmoniclabs/cbor");
2620
+ var import_base32_encoding4 = __toESM(require("base32-encoding"), 1);
2621
+ var import_bech324 = require("bech32");
2622
+ var import_common8 = require("@meshsdk/common");
1974
2623
 
1975
- // src/utils/script-data-hash.ts
2624
+ // src/utils/certificate.ts
1976
2625
  var import_core5 = require("@cardano-sdk/core");
1977
- var Crypto2 = __toESM(require("@cardano-sdk/crypto"), 1);
2626
+ var toCardanoCert = (cert) => {
2627
+ switch (cert.type) {
2628
+ case "RegisterPool": {
2629
+ let relays = [];
2630
+ for (const relay of cert.poolParams.relays) {
2631
+ switch (relay.type) {
2632
+ case "SingleHostAddr": {
2633
+ relays.push(
2634
+ import_core5.Serialization.Relay.newSingleHostAddr(
2635
+ new import_core5.Serialization.SingleHostAddr(
2636
+ relay.port,
2637
+ relay.IPV4,
2638
+ relay.IPV6
2639
+ )
2640
+ )
2641
+ );
2642
+ break;
2643
+ }
2644
+ case "SingleHostName": {
2645
+ relays.push(
2646
+ import_core5.Serialization.Relay.newSingleHostName(
2647
+ new import_core5.Serialization.SingleHostName(relay.domainName, relay.port)
2648
+ )
2649
+ );
2650
+ break;
2651
+ }
2652
+ case "MultiHostName": {
2653
+ relays.push(
2654
+ import_core5.Serialization.Relay.newMultiHostName(
2655
+ new import_core5.Serialization.MultiHostName(relay.domainName)
2656
+ )
2657
+ );
2658
+ break;
2659
+ }
2660
+ }
2661
+ }
2662
+ let poolOwners = import_core5.Serialization.CborSet.fromCore([], import_core5.Serialization.Hash.fromCore);
2663
+ let poolOwnersValues = [...poolOwners.values()];
2664
+ for (const poolOwner of cert.poolParams.owners) {
2665
+ poolOwnersValues.push(
2666
+ import_core5.Serialization.Hash.fromCore(Ed25519KeyHashHex2(poolOwner))
2667
+ );
2668
+ }
2669
+ poolOwners.setValues(poolOwnersValues);
2670
+ const rewardAddress = import_core5.Cardano.RewardAddress.fromAddress(
2671
+ import_core5.Cardano.Address.fromBech32(cert.poolParams.rewardAddress)
2672
+ );
2673
+ if (rewardAddress === void 0) {
2674
+ throw new Error(
2675
+ "Error parsing reward address, it is expected to be in bech32 format"
2676
+ );
2677
+ }
2678
+ const metadata = cert.poolParams.metadata ? new import_core5.Serialization.PoolMetadata(
2679
+ cert.poolParams.metadata.URL,
2680
+ Crypto2.Hash32ByteBase16(cert.poolParams.metadata.hash)
2681
+ ) : void 0;
2682
+ return Certificate.newPoolRegistration(
2683
+ new import_core5.Serialization.PoolRegistration(
2684
+ new import_core5.Serialization.PoolParams(
2685
+ Ed25519KeyHashHex2(cert.poolParams.operator),
2686
+ import_core5.Cardano.VrfVkHex(cert.poolParams.vrfKeyHash),
2687
+ BigInt(cert.poolParams.pledge),
2688
+ BigInt(cert.poolParams.cost),
2689
+ new import_core5.Serialization.UnitInterval(
2690
+ BigInt(cert.poolParams.margin[0]),
2691
+ BigInt(cert.poolParams.margin[1])
2692
+ ),
2693
+ rewardAddress,
2694
+ poolOwners,
2695
+ relays,
2696
+ metadata
2697
+ )
2698
+ )
2699
+ );
2700
+ }
2701
+ case "RegisterStake": {
2702
+ const rewardAddress = import_core5.Cardano.RewardAddress.fromAddress(
2703
+ import_core5.Cardano.Address.fromBech32(cert.stakeKeyAddress)
2704
+ );
2705
+ if (rewardAddress === void 0) {
2706
+ throw new Error(
2707
+ "Error parsing reward address, it is expected to be in bech32 format"
2708
+ );
2709
+ }
2710
+ return Certificate.newStakeRegistration(
2711
+ new import_core5.Serialization.StakeRegistration(
2712
+ rewardAddress.getPaymentCredential()
2713
+ )
2714
+ );
2715
+ }
2716
+ case "DelegateStake": {
2717
+ const rewardAddress = import_core5.Cardano.RewardAddress.fromAddress(
2718
+ import_core5.Cardano.Address.fromBech32(cert.stakeKeyAddress)
2719
+ );
2720
+ if (rewardAddress === void 0) {
2721
+ throw new Error(
2722
+ "Error parsing reward address, it is expected to be in bech32 format"
2723
+ );
2724
+ }
2725
+ return Certificate.newStakeDelegation(
2726
+ new import_core5.Serialization.StakeDelegation(
2727
+ rewardAddress.getPaymentCredential(),
2728
+ Ed25519KeyHashHex2(cert.poolId)
2729
+ )
2730
+ );
2731
+ }
2732
+ case "DeregisterStake": {
2733
+ const rewardAddress = import_core5.Cardano.RewardAddress.fromAddress(
2734
+ import_core5.Cardano.Address.fromBech32(cert.stakeKeyAddress)
2735
+ );
2736
+ if (rewardAddress === void 0) {
2737
+ throw new Error(
2738
+ "Error parsing reward address, it is expected to be in bech32 format"
2739
+ );
2740
+ }
2741
+ return Certificate.newStakeDeregistration(
2742
+ new import_core5.Serialization.StakeDeregistration(
2743
+ rewardAddress.getPaymentCredential()
2744
+ )
2745
+ );
2746
+ }
2747
+ case "RetirePool": {
2748
+ return Certificate.newPoolRetirement(
2749
+ new import_core5.Serialization.PoolRetirement(
2750
+ Ed25519KeyHashHex2(cert.poolId),
2751
+ import_core5.Cardano.EpochNo(cert.epoch)
2752
+ )
2753
+ );
2754
+ }
2755
+ case "VoteDelegation": {
2756
+ const rewardAddress = import_core5.Cardano.RewardAddress.fromAddress(
2757
+ import_core5.Cardano.Address.fromBech32(cert.stakeKeyAddress)
2758
+ );
2759
+ if (rewardAddress === void 0) {
2760
+ throw new Error(
2761
+ "Error parsing reward address, it is expected to be in bech32 format"
2762
+ );
2763
+ }
2764
+ if (cert.drep.dRepId !== void 0) {
2765
+ return Certificate.newVoteDelegationCert(
2766
+ new import_core5.Serialization.VoteDelegation(
2767
+ rewardAddress.getPaymentCredential(),
2768
+ toDRep(cert.drep.dRepId)
2769
+ )
2770
+ );
2771
+ } else if (cert.drep.alwaysAbstain !== void 0) {
2772
+ return Certificate.newVoteDelegationCert(
2773
+ new import_core5.Serialization.VoteDelegation(
2774
+ rewardAddress.getPaymentCredential(),
2775
+ import_core5.Serialization.DRep.newAlwaysAbstain()
2776
+ )
2777
+ );
2778
+ } else if (cert.drep.alwaysNoConfidence !== void 0) {
2779
+ return Certificate.newVoteDelegationCert(
2780
+ new import_core5.Serialization.VoteDelegation(
2781
+ rewardAddress.getPaymentCredential(),
2782
+ import_core5.Serialization.DRep.newAlwaysNoConfidence()
2783
+ )
2784
+ );
2785
+ } else {
2786
+ throw new Error("Malformed DRep type");
2787
+ }
2788
+ }
2789
+ case "StakeAndVoteDelegation": {
2790
+ const rewardAddress = import_core5.Cardano.RewardAddress.fromAddress(
2791
+ import_core5.Cardano.Address.fromBech32(cert.stakeKeyAddress)
2792
+ );
2793
+ if (rewardAddress === void 0) {
2794
+ throw new Error(
2795
+ "Error parsing reward address, it is expected to be in bech32 format"
2796
+ );
2797
+ }
2798
+ if (cert.drep.dRepId !== void 0) {
2799
+ return Certificate.newStakeVoteDelegationCert(
2800
+ new import_core5.Serialization.StakeVoteDelegation(
2801
+ rewardAddress.getPaymentCredential(),
2802
+ toDRep(cert.drep.dRepId),
2803
+ Ed25519KeyHashHex2(cert.poolKeyHash)
2804
+ )
2805
+ );
2806
+ } else if (cert.drep.alwaysAbstain !== void 0) {
2807
+ return Certificate.newStakeVoteDelegationCert(
2808
+ new import_core5.Serialization.StakeVoteDelegation(
2809
+ rewardAddress.getPaymentCredential(),
2810
+ import_core5.Serialization.DRep.newAlwaysAbstain(),
2811
+ Ed25519KeyHashHex2(cert.poolKeyHash)
2812
+ )
2813
+ );
2814
+ } else if (cert.drep.alwaysNoConfidence !== void 0) {
2815
+ return Certificate.newStakeVoteDelegationCert(
2816
+ new import_core5.Serialization.StakeVoteDelegation(
2817
+ rewardAddress.getPaymentCredential(),
2818
+ import_core5.Serialization.DRep.newAlwaysNoConfidence(),
2819
+ Ed25519KeyHashHex2(cert.poolKeyHash)
2820
+ )
2821
+ );
2822
+ } else {
2823
+ throw new Error("Malformed DRep type");
2824
+ }
2825
+ }
2826
+ case "StakeRegistrationAndDelegation": {
2827
+ const rewardAddress = import_core5.Cardano.RewardAddress.fromAddress(
2828
+ import_core5.Cardano.Address.fromBech32(cert.stakeKeyAddress)
2829
+ );
2830
+ if (rewardAddress === void 0) {
2831
+ throw new Error(
2832
+ "Error parsing reward address, it is expected to be in bech32 format"
2833
+ );
2834
+ }
2835
+ return Certificate.newStakeRegistrationDelegationCert(
2836
+ new import_core5.Serialization.StakeRegistrationDelegation(
2837
+ rewardAddress.getPaymentCredential(),
2838
+ BigInt(cert.coin),
2839
+ Ed25519KeyHashHex2(cert.poolKeyHash)
2840
+ )
2841
+ );
2842
+ }
2843
+ case "VoteRegistrationAndDelegation": {
2844
+ const rewardAddress = import_core5.Cardano.RewardAddress.fromAddress(
2845
+ import_core5.Cardano.Address.fromBech32(cert.stakeKeyAddress)
2846
+ );
2847
+ if (rewardAddress === void 0) {
2848
+ throw new Error(
2849
+ "Error parsing reward address, it is expected to be in bech32 format"
2850
+ );
2851
+ }
2852
+ if (cert.drep.dRepId !== void 0) {
2853
+ return Certificate.newVoteRegistrationDelegationCert(
2854
+ new import_core5.Serialization.VoteRegistrationDelegation(
2855
+ rewardAddress.getPaymentCredential(),
2856
+ BigInt(cert.coin),
2857
+ toDRep(cert.drep.dRepId)
2858
+ )
2859
+ );
2860
+ } else if (cert.drep.alwaysAbstain !== void 0) {
2861
+ return Certificate.newVoteRegistrationDelegationCert(
2862
+ new import_core5.Serialization.VoteRegistrationDelegation(
2863
+ rewardAddress.getPaymentCredential(),
2864
+ BigInt(cert.coin),
2865
+ import_core5.Serialization.DRep.newAlwaysAbstain()
2866
+ )
2867
+ );
2868
+ } else if (cert.drep.alwaysNoConfidence !== void 0) {
2869
+ return Certificate.newVoteRegistrationDelegationCert(
2870
+ new import_core5.Serialization.VoteRegistrationDelegation(
2871
+ rewardAddress.getPaymentCredential(),
2872
+ BigInt(cert.coin),
2873
+ import_core5.Serialization.DRep.newAlwaysNoConfidence()
2874
+ )
2875
+ );
2876
+ } else {
2877
+ throw new Error("Malformed DRep type");
2878
+ }
2879
+ }
2880
+ case "StakeVoteRegistrationAndDelegation": {
2881
+ const rewardAddress = import_core5.Cardano.RewardAddress.fromAddress(
2882
+ import_core5.Cardano.Address.fromBech32(cert.stakeKeyAddress)
2883
+ );
2884
+ if (rewardAddress === void 0) {
2885
+ throw new Error(
2886
+ "Error parsing reward address, it is expected to be in bech32 format"
2887
+ );
2888
+ }
2889
+ if (cert.drep.dRepId !== void 0) {
2890
+ return Certificate.newStakeVoteDelegationCert(
2891
+ new import_core5.Serialization.StakeVoteDelegation(
2892
+ rewardAddress.getPaymentCredential(),
2893
+ toDRep(cert.drep.dRepId),
2894
+ Ed25519KeyHashHex2(cert.poolKeyHash)
2895
+ )
2896
+ );
2897
+ } else if (cert.drep.alwaysAbstain !== void 0) {
2898
+ return Certificate.newStakeVoteDelegationCert(
2899
+ new import_core5.Serialization.StakeVoteDelegation(
2900
+ rewardAddress.getPaymentCredential(),
2901
+ import_core5.Serialization.DRep.newAlwaysAbstain(),
2902
+ Ed25519KeyHashHex2(cert.poolKeyHash)
2903
+ )
2904
+ );
2905
+ } else if (cert.drep.alwaysNoConfidence !== void 0) {
2906
+ return Certificate.newStakeVoteDelegationCert(
2907
+ new import_core5.Serialization.StakeVoteDelegation(
2908
+ rewardAddress.getPaymentCredential(),
2909
+ import_core5.Serialization.DRep.newAlwaysNoConfidence(),
2910
+ Ed25519KeyHashHex2(cert.poolKeyHash)
2911
+ )
2912
+ );
2913
+ } else {
2914
+ throw new Error("Malformed DRep type");
2915
+ }
2916
+ }
2917
+ case "CommitteeHotAuth": {
2918
+ const hotCred = import_core5.Cardano.Address.fromBech32(
2919
+ cert.committeeHotKeyAddress
2920
+ ).getProps().paymentPart;
2921
+ const coldCred = import_core5.Cardano.Address.fromBech32(
2922
+ cert.committeeColdKeyAddress
2923
+ ).getProps().paymentPart;
2924
+ if (!hotCred || !coldCred) {
2925
+ throw new Error("Malformed hot/cold credential");
2926
+ }
2927
+ return Certificate.newAuthCommitteeHotCert(
2928
+ new import_core5.Serialization.AuthCommitteeHot(coldCred, hotCred)
2929
+ );
2930
+ }
2931
+ case "CommitteeColdResign": {
2932
+ const coldCred = import_core5.Cardano.Address.fromBech32(
2933
+ cert.committeeColdKeyAddress
2934
+ ).getProps().paymentPart;
2935
+ if (!coldCred) {
2936
+ throw new Error("Malformed hot/cold credential");
2937
+ }
2938
+ let anchor = void 0;
2939
+ if (cert.anchor) {
2940
+ anchor = new import_core5.Serialization.Anchor(
2941
+ cert.anchor.anchorUrl,
2942
+ Hash32ByteBase162(cert.anchor.anchorDataHash)
2943
+ );
2944
+ }
2945
+ return Certificate.newResignCommitteeColdCert(
2946
+ new import_core5.Serialization.ResignCommitteeCold(coldCred, anchor)
2947
+ );
2948
+ }
2949
+ case "DRepRegistration": {
2950
+ let anchor = void 0;
2951
+ if (cert.anchor) {
2952
+ anchor = new import_core5.Serialization.Anchor(
2953
+ cert.anchor.anchorUrl,
2954
+ Hash32ByteBase162(cert.anchor.anchorDataHash)
2955
+ );
2956
+ }
2957
+ const coreDRep = toDRep(cert.drepId).toCore();
2958
+ if (import_core5.Cardano.isDRepCredential(coreDRep)) {
2959
+ return Certificate.newRegisterDelegateRepresentativeCert(
2960
+ new import_core5.Serialization.RegisterDelegateRepresentative(
2961
+ coreDRep,
2962
+ BigInt(cert.coin),
2963
+ anchor
2964
+ )
2965
+ );
2966
+ } else {
2967
+ throw new Error("DRepId must be a Credential");
2968
+ }
2969
+ }
2970
+ case "DRepDeregistration": {
2971
+ const coreDRep = toDRep(cert.drepId).toCore();
2972
+ if (import_core5.Cardano.isDRepCredential(coreDRep)) {
2973
+ return Certificate.newUnregisterDelegateRepresentativeCert(
2974
+ new import_core5.Serialization.UnregisterDelegateRepresentative(
2975
+ coreDRep,
2976
+ BigInt(cert.coin)
2977
+ )
2978
+ );
2979
+ } else {
2980
+ throw new Error("DRepId must be a Credential");
2981
+ }
2982
+ }
2983
+ case "DRepUpdate": {
2984
+ let anchor = void 0;
2985
+ if (cert.anchor) {
2986
+ anchor = new import_core5.Serialization.Anchor(
2987
+ cert.anchor.anchorUrl,
2988
+ Hash32ByteBase162(cert.anchor.anchorDataHash)
2989
+ );
2990
+ }
2991
+ const coreDRep = toDRep(cert.drepId).toCore();
2992
+ if (import_core5.Cardano.isDRepCredential(coreDRep)) {
2993
+ return Certificate.newUpdateDelegateRepresentativeCert(
2994
+ new import_core5.Serialization.UpdateDelegateRepresentative(coreDRep, anchor)
2995
+ );
2996
+ } else {
2997
+ throw new Error("DRepId must be a Credential");
2998
+ }
2999
+ }
3000
+ }
3001
+ };
3002
+
3003
+ // src/utils/fee.ts
3004
+ var calculateFees = (minFeeA, minFeeB, minFeeRefScriptCostPerByte, priceMem, priceStep, tx, refScriptSize) => {
3005
+ let fee = minFeeB + tx.toCbor().length / 2 * minFeeA;
3006
+ const tierSize = 25600;
3007
+ let currentRefScriptSize = refScriptSize;
3008
+ let multiplier = 1.2;
3009
+ while (currentRefScriptSize >= tierSize) {
3010
+ fee += tierSize * multiplier * minFeeRefScriptCostPerByte;
3011
+ currentRefScriptSize -= tierSize;
3012
+ multiplier *= multiplier;
3013
+ }
3014
+ if (currentRefScriptSize > 0) {
3015
+ fee += currentRefScriptSize * multiplier * minFeeRefScriptCostPerByte;
3016
+ }
3017
+ let scriptFee = BigInt(0);
3018
+ let priceMemNumerator = priceMem;
3019
+ let priceMemDenominator = 1;
3020
+ while (priceMemNumerator % 1) {
3021
+ priceMemNumerator *= 10;
3022
+ priceMemDenominator *= 10;
3023
+ }
3024
+ let priceStepNumerator = priceStep;
3025
+ let priceStepDenominator = 1;
3026
+ while (priceStepNumerator % 1) {
3027
+ priceStepNumerator *= 10;
3028
+ priceStepDenominator *= 10;
3029
+ }
3030
+ if (tx.witnessSet().redeemers()) {
3031
+ for (const redeemer of tx.witnessSet().redeemers().values()) {
3032
+ scriptFee += redeemer.exUnits().mem() * BigInt(priceMemNumerator.toString()) / BigInt(priceMemDenominator.toString()) + BigInt(1);
3033
+ scriptFee += redeemer.exUnits().steps() * BigInt(priceStepNumerator.toString()) / BigInt(priceStepDenominator.toString()) + BigInt(1);
3034
+ }
3035
+ }
3036
+ return BigInt(fee) + scriptFee;
3037
+ };
3038
+
3039
+ // src/utils/metadata.ts
3040
+ var toCardanoMetadataMap = (metadata) => {
3041
+ let cardanoMetadataMap = /* @__PURE__ */ new Map();
3042
+ metadata.forEach((val, key) => {
3043
+ cardanoMetadataMap.set(key, toCardanoMetadatum(val));
3044
+ });
3045
+ return cardanoMetadataMap;
3046
+ };
3047
+ var toCardanoMetadatum = (metadatum) => {
3048
+ if (typeof metadatum === "number") {
3049
+ return TransactionMetadatum.newInteger(BigInt(metadatum));
3050
+ } else if (typeof metadatum === "string") {
3051
+ return TransactionMetadatum.newText(metadatum);
3052
+ } else if (typeof metadatum === "bigint") {
3053
+ return TransactionMetadatum.newInteger(metadatum);
3054
+ } else if (metadatum instanceof Uint8Array) {
3055
+ return TransactionMetadatum.newBytes(metadatum);
3056
+ } else if (metadatum instanceof Map) {
3057
+ const result = new MetadatumMap();
3058
+ metadatum.forEach((value, key) => {
3059
+ result.insert(toCardanoMetadatum(key), toCardanoMetadatum(value));
3060
+ });
3061
+ return TransactionMetadatum.newMap(result);
3062
+ } else if (Array.isArray(metadatum)) {
3063
+ const result = new MetadatumList();
3064
+ metadatum.forEach((val) => {
3065
+ result.add(toCardanoMetadatum(val));
3066
+ });
3067
+ return TransactionMetadatum.newList(result);
3068
+ } else {
3069
+ throw new Error("metadatumToObj: Unsupported Metadatum type");
3070
+ }
3071
+ };
3072
+
3073
+ // src/utils/script-data-hash.ts
3074
+ var import_core6 = require("@cardano-sdk/core");
3075
+ var Crypto3 = __toESM(require("@cardano-sdk/crypto"), 1);
1978
3076
  var import_crypto6 = require("@cardano-sdk/crypto");
1979
- var import_util6 = require("@cardano-sdk/util");
3077
+ var import_util8 = require("@cardano-sdk/util");
1980
3078
  var CBOR_EMPTY_LIST = new Uint8Array([128]);
1981
3079
  var CBOR_EMPTY_MAP = new Uint8Array([160]);
1982
3080
  var getCborEncodedArray = (items) => {
1983
- const writer = new import_core5.Serialization.CborWriter();
3081
+ const writer = new import_core6.Serialization.CborWriter();
1984
3082
  writer.writeStartArray(items.length);
1985
3083
  for (const item of items) {
1986
3084
  writer.writeEncodedValue(Buffer.from(item.toCbor(), "hex"));
@@ -1988,7 +3086,7 @@ var getCborEncodedArray = (items) => {
1988
3086
  return writer.encode();
1989
3087
  };
1990
3088
  var hashScriptData = (costModels, redemeers, datums) => {
1991
- const writer = new import_core5.Serialization.CborWriter();
3089
+ const writer = new import_core6.Serialization.CborWriter();
1992
3090
  if (datums && datums.length > 0 && (!redemeers || redemeers.length === 0)) {
1993
3091
  writer.writeEncodedValue(CBOR_EMPTY_LIST);
1994
3092
  writer.writeEncodedValue(getCborEncodedArray(datums));
@@ -2003,8 +3101,8 @@ var hashScriptData = (costModels, redemeers, datums) => {
2003
3101
  );
2004
3102
  }
2005
3103
  return import_crypto6.Hash32ByteBase16.fromHexBlob(
2006
- import_util6.HexBlob.fromBytes(
2007
- Crypto2.blake2b(Crypto2.blake2b.BYTES).update(writer.encode()).digest()
3104
+ import_util8.HexBlob.fromBytes(
3105
+ Crypto3.blake2b(Crypto3.blake2b.BYTES).update(writer.encode()).digest()
2008
3106
  )
2009
3107
  );
2010
3108
  };
@@ -2012,148 +3110,253 @@ var hashScriptData = (costModels, redemeers, datums) => {
2012
3110
  // src/serializer/index.ts
2013
3111
  var CardanoSDKSerializer = class {
2014
3112
  verbose;
2015
- txBody;
2016
- txWitnessSet;
2017
- utxoContext = /* @__PURE__ */ new Map();
2018
- redeemerContext = /* @__PURE__ */ new Map();
2019
- scriptsProvided = /* @__PURE__ */ new Set();
2020
- datumsProvided = /* @__PURE__ */ new Set();
2021
- usedLanguages = {
2022
- [0]: false,
2023
- [1]: false,
2024
- [2]: false
2025
- };
2026
- constructor(verbose = false) {
3113
+ protocolParams;
3114
+ constructor(protocolParams, verbose = false) {
3115
+ this.protocolParams = protocolParams || import_common8.DEFAULT_PROTOCOL_PARAMETERS;
2027
3116
  this.verbose = verbose;
2028
- this.txBody = new TransactionBody(
2029
- import_core6.Serialization.CborSet.fromCore([], TransactionInput.fromCore),
2030
- [],
2031
- BigInt(0),
2032
- void 0
2033
- );
2034
- this.txWitnessSet = new TransactionWitnessSet();
2035
3117
  }
2036
3118
  serializeRewardAddress(stakeKeyHash, isScriptHash, network_id) {
2037
- throw new Error("Method not implemented.");
3119
+ return RewardAddress.fromCredentials(network_id ?? 0, {
3120
+ type: isScriptHash ? CredentialType.ScriptHash : CredentialType.KeyHash,
3121
+ hash: Hash28ByteBase162(stakeKeyHash)
3122
+ }).toAddress().toBech32();
2038
3123
  }
2039
3124
  serializePoolId(hash) {
2040
- throw new Error("Method not implemented.");
3125
+ return PoolId.fromKeyHash(Ed25519KeyHashHex2(hash)).toString();
2041
3126
  }
2042
3127
  serializeAddress(address, networkId) {
2043
- throw new Error("Method not implemented.");
3128
+ let paymentCred = void 0;
3129
+ let stakeCred;
3130
+ if (address.pubKeyHash && address.pubKeyHash !== "") {
3131
+ paymentCred = {
3132
+ type: CredentialType.KeyHash,
3133
+ hash: Hash28ByteBase162(address.pubKeyHash)
3134
+ };
3135
+ } else if (address.scriptHash && address.scriptHash !== "") {
3136
+ paymentCred = {
3137
+ type: CredentialType.ScriptHash,
3138
+ hash: Hash28ByteBase162(address.scriptHash)
3139
+ };
3140
+ }
3141
+ if (address.stakeCredentialHash && address.stakeCredentialHash !== "") {
3142
+ stakeCred = {
3143
+ type: CredentialType.KeyHash,
3144
+ hash: Hash28ByteBase162(address.stakeCredentialHash)
3145
+ };
3146
+ } else if (address.stakeScriptCredentialHash) {
3147
+ stakeCred = {
3148
+ type: CredentialType.ScriptHash,
3149
+ hash: Hash28ByteBase162(address.stakeScriptCredentialHash)
3150
+ };
3151
+ }
3152
+ let type = AddressType.BasePaymentKeyStakeKey;
3153
+ if (paymentCred && stakeCred) {
3154
+ if (paymentCred.type === CredentialType.KeyHash && stakeCred.type === CredentialType.KeyHash) {
3155
+ type = AddressType.BasePaymentKeyStakeKey;
3156
+ } else if (paymentCred.type === CredentialType.KeyHash && stakeCred.type === CredentialType.ScriptHash) {
3157
+ type = AddressType.BasePaymentKeyStakeScript;
3158
+ } else if (paymentCred.type === CredentialType.ScriptHash && stakeCred.type === CredentialType.KeyHash) {
3159
+ type = AddressType.BasePaymentScriptStakeKey;
3160
+ } else if (paymentCred.type === CredentialType.ScriptHash && stakeCred.type === CredentialType.ScriptHash) {
3161
+ type = AddressType.BasePaymentScriptStakeScript;
3162
+ }
3163
+ } else if (paymentCred) {
3164
+ if (paymentCred.type === CredentialType.KeyHash) {
3165
+ type = AddressType.EnterpriseKey;
3166
+ } else if (paymentCred.type === CredentialType.ScriptHash) {
3167
+ type = AddressType.EnterpriseScript;
3168
+ }
3169
+ } else if (stakeCred) {
3170
+ if (stakeCred.type === CredentialType.KeyHash) {
3171
+ type = AddressType.RewardKey;
3172
+ } else if (stakeCred.type === CredentialType.ScriptHash) {
3173
+ type = AddressType.RewardScript;
3174
+ }
3175
+ }
3176
+ return new Address({
3177
+ type,
3178
+ networkId: networkId ?? 0,
3179
+ paymentPart: paymentCred,
3180
+ delegationPart: stakeCred
3181
+ }).toBech32();
2044
3182
  }
2045
3183
  serializeData(data) {
2046
- throw new Error("Method not implemented.");
3184
+ const plutusData = fromBuilderToPlutusData(data);
3185
+ return plutusData.toCbor().toString();
2047
3186
  }
2048
3187
  deserializer = {
2049
3188
  key: {
2050
- deserializeAddress: function(bech32) {
2051
- throw new Error("Function not implemented.");
3189
+ deserializeAddress: function(bech325) {
3190
+ const address = Address.fromBech32(bech325);
3191
+ const addressProps = address.getProps();
3192
+ return {
3193
+ pubKeyHash: addressProps.paymentPart?.type === CredentialType.KeyHash ? addressProps.paymentPart?.hash ?? "" : "",
3194
+ scriptHash: addressProps.paymentPart?.type === CredentialType.ScriptHash ? addressProps.paymentPart?.hash ?? "" : "",
3195
+ stakeCredentialHash: addressProps.delegationPart?.type === CredentialType.KeyHash ? addressProps.paymentPart?.hash ?? "" : "",
3196
+ stakeScriptCredentialHash: addressProps.delegationPart?.type === CredentialType.ScriptHash ? addressProps.paymentPart?.hash ?? "" : ""
3197
+ };
2052
3198
  }
2053
3199
  },
2054
3200
  script: {
2055
3201
  deserializeNativeScript: function(script) {
2056
- throw new Error("Function not implemented.");
3202
+ const cardanoNativeScript = toNativeScript(script);
3203
+ return {
3204
+ scriptHash: cardanoNativeScript.hash().toString(),
3205
+ scriptCbor: cardanoNativeScript.toCbor().toString()
3206
+ };
2057
3207
  },
2058
3208
  deserializePlutusScript: function(script) {
2059
- throw new Error("Function not implemented.");
3209
+ let cardanoPlutusScript;
3210
+ switch (script.version) {
3211
+ case "V1": {
3212
+ cardanoPlutusScript = new PlutusV1Script((0, import_util9.HexBlob)(script.code));
3213
+ break;
3214
+ }
3215
+ case "V2": {
3216
+ cardanoPlutusScript = new PlutusV2Script((0, import_util9.HexBlob)(script.code));
3217
+ break;
3218
+ }
3219
+ case "V3": {
3220
+ cardanoPlutusScript = new PlutusV3Script((0, import_util9.HexBlob)(script.code));
3221
+ break;
3222
+ }
3223
+ }
3224
+ return {
3225
+ scriptHash: cardanoPlutusScript.hash().toString(),
3226
+ scriptCbor: cardanoPlutusScript.toCbor().toString()
3227
+ };
2060
3228
  }
2061
3229
  },
2062
3230
  cert: {
2063
3231
  deserializePoolId: function(poolId) {
2064
- throw new Error("Function not implemented.");
3232
+ const cardanoPoolId = PoolId(poolId);
3233
+ return PoolId.toKeyHash(cardanoPoolId).toString();
2065
3234
  }
2066
3235
  }
2067
3236
  };
2068
3237
  resolver = {
2069
3238
  keys: {
2070
- // resolvePaymentKeyHash: function (bech32: string): string {
2071
- // const cardanoAddress = toAddress(bech32);
2072
- // return cardanoAddress.asEnterprise()?.getPaymentCredential().type ===
2073
- // CredentialType.KeyHash
2074
- // ? cardanoAddress.asEnterprise()!.getPaymentCredential().hash
2075
- // : "";
2076
- // },
2077
- // resolvePlutusScriptHash: function (bech32: string): string {
2078
- // const cardanoAddress = toAddress(bech32);
2079
- // return cardanoAddress.asEnterprise()?.getPaymentCredential().type ===
2080
- // CredentialType.ScriptHash
2081
- // ? cardanoAddress.asEnterprise()!.getPaymentCredential().hash
2082
- // : "";
2083
- // },
2084
- resolveStakeKeyHash: function(bech32) {
2085
- const cardanoAddress = toAddress(bech32);
3239
+ resolveStakeKeyHash: function(bech325) {
3240
+ const cardanoAddress = toAddress(bech325);
2086
3241
  return cardanoAddress.asReward()?.getPaymentCredential().type === CredentialType.KeyHash ? cardanoAddress.asReward().getPaymentCredential().hash : "";
2087
3242
  },
2088
- // resolveStakeScriptHash(bech32: string): string {
2089
- // const cardanoAddress = toAddress(bech32);
2090
- // return cardanoAddress.asReward()?.getPaymentCredential().type ===
2091
- // CredentialType.ScriptHash
2092
- // ? cardanoAddress.asReward()!.getPaymentCredential().hash
2093
- // : "";
2094
- // },
2095
3243
  resolvePrivateKey: function(words) {
2096
- throw new Error("Function not implemented.");
3244
+ const buildBip32PrivateKey2 = (entropy2, password = "") => {
3245
+ return Bip32PrivateKey2.fromBip39Entropy(
3246
+ Buffer.from((0, import_common8.toBytes)(entropy2)),
3247
+ (0, import_common8.fromUTF8)(password)
3248
+ );
3249
+ };
3250
+ const entropy = (0, import_common8.mnemonicToEntropy)(words.join(" "));
3251
+ const bip32PrivateKey = buildBip32PrivateKey2(entropy);
3252
+ const bytes = import_base32_encoding4.default.encode(bip32PrivateKey.bytes());
3253
+ const bech32PrivateKey = import_bech324.bech32.encode("xprv", bytes, 1023);
3254
+ return bech32PrivateKey;
2097
3255
  },
2098
- resolveRewardAddress: function(bech32) {
2099
- throw new Error("Function not implemented.");
3256
+ resolveRewardAddress: function(bech325) {
3257
+ const cardanoAddress = toAddress(bech325);
3258
+ const addressProps = cardanoAddress.getProps();
3259
+ if (!addressProps.delegationPart) {
3260
+ return "";
3261
+ }
3262
+ return RewardAddress.fromCredentials(
3263
+ cardanoAddress.getNetworkId(),
3264
+ addressProps.delegationPart
3265
+ ).toAddress().toBech32() ?? "";
2100
3266
  },
2101
- resolveEd25519KeyHash: function(bech32) {
2102
- throw new Error("Function not implemented.");
3267
+ resolveEd25519KeyHash: function(bech325) {
3268
+ const cardanoAddress = toAddress(bech325);
3269
+ const addressProps = cardanoAddress.getProps();
3270
+ if (!addressProps.paymentPart) {
3271
+ return "";
3272
+ }
3273
+ return addressProps.paymentPart.hash.toString();
2103
3274
  }
2104
3275
  },
2105
3276
  tx: {
2106
3277
  resolveTxHash: function(txHex) {
2107
- return Transaction.fromCbor((0, import_core6.TxCBOR)(txHex)).getId();
3278
+ return Transaction.fromCbor(import_core7.Serialization.TxCBOR(txHex)).getId();
2108
3279
  }
2109
3280
  },
2110
3281
  data: {
2111
3282
  resolveDataHash: function(data) {
2112
- throw new Error("Function not implemented.");
3283
+ return fromBuilderToPlutusData({ type: "Mesh", content: data }).hash();
2113
3284
  }
2114
3285
  },
2115
3286
  script: {
2116
- // resolveNativeScript: function (script: CommonNativeScript): string {
2117
- // return toNativeScript(script).toCbor();
2118
- // },
2119
3287
  resolveScriptRef: function(script) {
2120
- throw new Error("Function not implemented.");
3288
+ if ("code" in script) {
3289
+ let versionByte;
3290
+ switch (script.version) {
3291
+ case "V1": {
3292
+ versionByte = 1;
3293
+ break;
3294
+ }
3295
+ case "V2": {
3296
+ versionByte = 2;
3297
+ break;
3298
+ }
3299
+ case "V3": {
3300
+ versionByte = 3;
3301
+ break;
3302
+ }
3303
+ }
3304
+ let taggedScript = new import_cbor.CborTag(
3305
+ 24,
3306
+ import_cbor.Cbor.parse(
3307
+ import_cbor.CborString.fromCborObj(
3308
+ new import_cbor.CborBytes(
3309
+ import_cbor.Cbor.encode(
3310
+ new import_cbor.CborArray([
3311
+ new import_cbor.CborUInt(versionByte),
3312
+ new import_cbor.CborString(script.code).toCborObj()
3313
+ ])
3314
+ ).toBuffer()
3315
+ )
3316
+ )
3317
+ )
3318
+ );
3319
+ return import_cbor.Cbor.encode(taggedScript).toString();
3320
+ } else {
3321
+ const nativeScript = toNativeScript(script);
3322
+ let taggedScript = new import_cbor.CborTag(
3323
+ 24,
3324
+ import_cbor.Cbor.parse(
3325
+ import_cbor.CborString.fromCborObj(
3326
+ new import_cbor.CborBytes(
3327
+ import_cbor.Cbor.encode(
3328
+ new import_cbor.CborArray([
3329
+ new import_cbor.CborUInt(0),
3330
+ new import_cbor.CborString(nativeScript.toCbor()).toCborObj()
3331
+ ])
3332
+ ).toBuffer()
3333
+ )
3334
+ )
3335
+ )
3336
+ );
3337
+ return import_cbor.Cbor.encode(taggedScript).toString();
3338
+ }
2121
3339
  }
2122
3340
  }
2123
3341
  };
2124
3342
  serializeTxBody = (txBuilderBody, protocolParams) => {
2125
- const {
2126
- inputs,
2127
- outputs,
2128
- collaterals,
2129
- referenceInputs,
2130
- mints,
2131
- changeAddress,
2132
- // certificates,
2133
- validityRange,
2134
- requiredSignatures
2135
- // metadata,
2136
- } = txBuilderBody;
2137
- mints.sort((a, b) => a.policyId.localeCompare(b.policyId));
2138
- inputs.sort((a, b) => {
2139
- if (a.txIn.txHash === b.txIn.txHash) {
2140
- return a.txIn.txIndex - b.txIn.txIndex;
2141
- } else {
2142
- return a.txIn.txHash.localeCompare(b.txIn.txHash);
2143
- }
2144
- });
2145
- this.addAllInputs(inputs);
2146
- this.addAllOutputs(outputs);
2147
- this.addAllMints(mints);
2148
- this.addAllCollateralInputs(collaterals);
2149
- this.addAllReferenceInputs(referenceInputs);
2150
- this.setValidityInterval(validityRange);
2151
- this.buildWitnessSet();
2152
- this.balanceTx(changeAddress, requiredSignatures.length, protocolParams);
2153
- return new Transaction(this.txBody, this.txWitnessSet).toCbor();
3343
+ if (this.verbose) {
3344
+ console.log(
3345
+ "txBodyJson",
3346
+ JSON.stringify(txBuilderBody, (key, val) => {
3347
+ if (key === "extraInputs") return void 0;
3348
+ if (key === "selectionConfig") return void 0;
3349
+ return val;
3350
+ })
3351
+ );
3352
+ }
3353
+ const serializerCore = new CardanoSDKSerializerCore(
3354
+ protocolParams ?? this.protocolParams
3355
+ );
3356
+ return serializerCore.coreSerializeTxBody(txBuilderBody);
2154
3357
  };
2155
3358
  addSigningKeys = (txHex, signingKeys) => {
2156
- let cardanoTx = Transaction.fromCbor((0, import_core6.TxCBOR)(txHex));
3359
+ let cardanoTx = Transaction.fromCbor(import_core7.Serialization.TxCBOR(txHex));
2157
3360
  let currentWitnessSet = cardanoTx.witnessSet();
2158
3361
  let currentWitnessSetVkeys = currentWitnessSet.vkeys();
2159
3362
  let currentWitnessSetVkeysValues = currentWitnessSetVkeys ? [...currentWitnessSetVkeys.values()] : [];
@@ -2180,7 +3383,7 @@ var CardanoSDKSerializer = class {
2180
3383
  }
2181
3384
  }
2182
3385
  currentWitnessSet.setVkeys(
2183
- import_core6.Serialization.CborSet.fromCore(
3386
+ import_core7.Serialization.CborSet.fromCore(
2184
3387
  currentWitnessSetVkeysValues.map((vkw) => vkw.toCore()),
2185
3388
  VkeyWitness.fromCore
2186
3389
  )
@@ -2188,6 +3391,103 @@ var CardanoSDKSerializer = class {
2188
3391
  cardanoTx.setWitnessSet(currentWitnessSet);
2189
3392
  return cardanoTx.toCbor();
2190
3393
  };
3394
+ };
3395
+ var CardanoSDKSerializerCore = class {
3396
+ txBody;
3397
+ txWitnessSet;
3398
+ txAuxilliaryData;
3399
+ utxoContext = /* @__PURE__ */ new Map();
3400
+ mintRedeemers = /* @__PURE__ */ new Map();
3401
+ scriptsProvided = /* @__PURE__ */ new Set();
3402
+ datumsProvided = /* @__PURE__ */ new Set();
3403
+ usedLanguages = {
3404
+ [0]: false,
3405
+ [1]: false,
3406
+ [2]: false
3407
+ };
3408
+ protocolParams;
3409
+ refScriptSize;
3410
+ constructor(protocolParams) {
3411
+ this.protocolParams = protocolParams || import_common8.DEFAULT_PROTOCOL_PARAMETERS;
3412
+ this.txBody = new TransactionBody(
3413
+ import_core7.Serialization.CborSet.fromCore([], TransactionInput.fromCore),
3414
+ [],
3415
+ BigInt(0),
3416
+ void 0
3417
+ );
3418
+ this.refScriptSize = 0;
3419
+ this.txWitnessSet = new TransactionWitnessSet();
3420
+ this.txAuxilliaryData = new AuxilliaryData();
3421
+ }
3422
+ coreSerializeTxBody = (txBuilderBody) => {
3423
+ const {
3424
+ inputs,
3425
+ outputs,
3426
+ collaterals,
3427
+ requiredSignatures,
3428
+ referenceInputs,
3429
+ mints,
3430
+ changeAddress,
3431
+ metadata,
3432
+ validityRange,
3433
+ certificates,
3434
+ withdrawals
3435
+ } = txBuilderBody;
3436
+ this.addAllInputs(inputs);
3437
+ this.addAllOutputs(this.sanitizeOutputs(outputs));
3438
+ this.addAllMints(mints);
3439
+ this.addAllCerts(certificates);
3440
+ this.addAllWithdrawals(withdrawals);
3441
+ this.addAllCollateralInputs(collaterals);
3442
+ this.addAllReferenceInputs(referenceInputs);
3443
+ this.removeInputRefInputOverlap();
3444
+ this.setValidityInterval(validityRange);
3445
+ this.addAllRequiredSignatures(requiredSignatures);
3446
+ if (metadata.size > 0) {
3447
+ this.addMetadata(metadata);
3448
+ }
3449
+ this.buildWitnessSet();
3450
+ this.balanceTx(changeAddress);
3451
+ return new Transaction(
3452
+ this.txBody,
3453
+ this.txWitnessSet,
3454
+ this.txAuxilliaryData
3455
+ ).toCbor();
3456
+ };
3457
+ sanitizeOutputs = (outputs) => {
3458
+ for (let i = 0; i < outputs.length; i++) {
3459
+ let currentOutput = outputs[i];
3460
+ let lovelaceFound = false;
3461
+ for (let j = 0; j < currentOutput.amount.length; j++) {
3462
+ let outputAmount = currentOutput.amount[j];
3463
+ if (outputAmount?.unit == "" || outputAmount?.unit == "lovelace") {
3464
+ lovelaceFound = true;
3465
+ if (outputAmount?.quantity == "0" || outputAmount?.quantity == "") {
3466
+ outputAmount.unit = "lovelace";
3467
+ outputAmount.quantity = "10000000";
3468
+ let dummyCardanoOutput = this.toCardanoOutput(
3469
+ currentOutput
3470
+ );
3471
+ let minUtxoValue = (160 + dummyCardanoOutput.toCbor().length / 2 + 1) * this.protocolParams.coinsPerUtxoSize;
3472
+ outputAmount.quantity = minUtxoValue.toString();
3473
+ }
3474
+ }
3475
+ if (!lovelaceFound) {
3476
+ let currentAmount = {
3477
+ unit: "lovelace",
3478
+ quantity: "10000000"
3479
+ };
3480
+ currentOutput.amount.push(currentAmount);
3481
+ let dummyCardanoOutput = this.toCardanoOutput(
3482
+ currentOutput
3483
+ );
3484
+ let minUtxoValue = (160 + dummyCardanoOutput.toCbor().length / 2 + 1) * this.protocolParams.coinsPerUtxoSize;
3485
+ currentAmount.quantity = minUtxoValue.toString();
3486
+ }
3487
+ }
3488
+ }
3489
+ return outputs;
3490
+ };
2191
3491
  addAllInputs = (inputs) => {
2192
3492
  for (let i = 0; i < inputs.length; i += 1) {
2193
3493
  const currentTxIn = inputs[i];
@@ -2198,7 +3498,8 @@ var CardanoSDKSerializer = class {
2198
3498
  break;
2199
3499
  case "Script":
2200
3500
  this.addScriptTxIn(
2201
- currentTxIn
3501
+ currentTxIn,
3502
+ i
2202
3503
  );
2203
3504
  break;
2204
3505
  case "SimpleScript":
@@ -2223,13 +3524,13 @@ var CardanoSDKSerializer = class {
2223
3524
  txInputsList.push(cardanoTxIn);
2224
3525
  inputs.setValues(txInputsList);
2225
3526
  const cardanoTxOut = new TransactionOutput(
2226
- Address.fromBech32(currentTxIn.txIn.address),
3527
+ toCardanoAddress(currentTxIn.txIn.address),
2227
3528
  toValue(currentTxIn.txIn.amount)
2228
3529
  );
2229
3530
  this.utxoContext.set(cardanoTxIn, cardanoTxOut);
2230
3531
  this.txBody.setInputs(inputs);
2231
3532
  };
2232
- addScriptTxIn = (currentTxIn) => {
3533
+ addScriptTxIn = (currentTxIn, index) => {
2233
3534
  this.addTxIn({
2234
3535
  type: "PubKey",
2235
3536
  txIn: currentTxIn.txIn
@@ -2244,74 +3545,16 @@ var CardanoSDKSerializer = class {
2244
3545
  throw new Error("A script input had no redeemer");
2245
3546
  }
2246
3547
  if (currentTxIn.scriptTxIn.scriptSource.type === "Provided") {
2247
- switch (currentTxIn.scriptTxIn.scriptSource.script.version) {
2248
- case "V1": {
2249
- this.scriptsProvided.add(
2250
- Script.newPlutusV1Script(
2251
- PlutusV1Script.fromCbor(
2252
- (0, import_util7.HexBlob)(currentTxIn.scriptTxIn.scriptSource.script.code)
2253
- )
2254
- )
2255
- );
2256
- this.usedLanguages[PlutusLanguageVersion.V1] = true;
2257
- break;
2258
- }
2259
- case "V2": {
2260
- this.scriptsProvided.add(
2261
- Script.newPlutusV2Script(
2262
- PlutusV2Script.fromCbor(
2263
- (0, import_util7.HexBlob)(currentTxIn.scriptTxIn.scriptSource.script.code)
2264
- )
2265
- )
2266
- );
2267
- this.usedLanguages[PlutusLanguageVersion.V2] = true;
2268
- break;
2269
- }
2270
- case "V3": {
2271
- this.scriptsProvided.add(
2272
- Script.newPlutusV3Script(
2273
- PlutusV3Script.fromCbor(
2274
- (0, import_util7.HexBlob)(currentTxIn.scriptTxIn.scriptSource.script.code)
2275
- )
2276
- )
2277
- );
2278
- this.usedLanguages[PlutusLanguageVersion.V3] = true;
2279
- break;
2280
- }
2281
- }
3548
+ this.addProvidedPlutusScript(currentTxIn.scriptTxIn.scriptSource.script);
2282
3549
  } else if (currentTxIn.scriptTxIn.scriptSource.type === "Inline") {
2283
- let referenceInputs = this.txBody.referenceInputs() ?? import_core6.Serialization.CborSet.fromCore([], TransactionInput.fromCore);
2284
- let referenceInputsList = [...referenceInputs.values()];
2285
- referenceInputsList.push(
2286
- new TransactionInput(
2287
- TransactionId(currentTxIn.scriptTxIn.scriptSource.txHash),
2288
- BigInt(currentTxIn.scriptTxIn.scriptSource.txIndex)
2289
- )
2290
- );
2291
- referenceInputs.setValues(referenceInputsList);
2292
- this.txBody.setReferenceInputs(referenceInputs);
2293
- switch (currentTxIn.scriptTxIn.scriptSource.version) {
2294
- case "V1": {
2295
- this.usedLanguages[PlutusLanguageVersion.V1] = true;
2296
- break;
2297
- }
2298
- case "V2": {
2299
- this.usedLanguages[PlutusLanguageVersion.V2] = true;
2300
- break;
2301
- }
2302
- case "V3": {
2303
- this.usedLanguages[PlutusLanguageVersion.V3] = true;
2304
- break;
2305
- }
2306
- }
3550
+ this.addScriptRef(currentTxIn.scriptTxIn.scriptSource);
2307
3551
  }
2308
3552
  if (currentTxIn.scriptTxIn.datumSource.type === "Provided") {
2309
3553
  this.datumsProvided.add(
2310
- toPlutusData(currentTxIn.scriptTxIn.datumSource.data.content)
2311
- // TODO: handle json / raw datum
3554
+ fromBuilderToPlutusData(currentTxIn.scriptTxIn.datumSource.data)
2312
3555
  );
2313
3556
  } else if (currentTxIn.scriptTxIn.datumSource.type === "Inline") {
2314
- let referenceInputs = this.txBody.referenceInputs() ?? import_core6.Serialization.CborSet.fromCore([], TransactionInput.fromCore);
3557
+ let referenceInputs = this.txBody.referenceInputs() ?? import_core7.Serialization.CborSet.fromCore([], TransactionInput.fromCore);
2315
3558
  let referenceInputsList = [...referenceInputs.values()];
2316
3559
  referenceInputsList.push(
2317
3560
  new TransactionInput(
@@ -2322,21 +3565,19 @@ var CardanoSDKSerializer = class {
2322
3565
  referenceInputs.setValues(referenceInputsList);
2323
3566
  this.txBody.setReferenceInputs(referenceInputs);
2324
3567
  }
2325
- let cardanoTxIn = new TransactionInput(
2326
- TransactionId(currentTxIn.txIn.txHash),
2327
- BigInt(currentTxIn.txIn.txIndex)
2328
- );
2329
3568
  let exUnits = currentTxIn.scriptTxIn.redeemer.exUnits;
2330
- this.redeemerContext.set(
2331
- cardanoTxIn,
3569
+ let redeemers = this.txWitnessSet.redeemers() ?? Redeemers.fromCore([]);
3570
+ let redeemersList = [...redeemers.values()];
3571
+ redeemersList.push(
2332
3572
  new Redeemer(
2333
3573
  RedeemerTag.Spend,
2334
- BigInt(0),
2335
- toPlutusData(currentTxIn.scriptTxIn.redeemer.data.content),
2336
- // TODO: handle json / raw datum
3574
+ BigInt(index),
3575
+ fromBuilderToPlutusData(currentTxIn.scriptTxIn.redeemer.data),
2337
3576
  new ExUnits(BigInt(exUnits.mem), BigInt(exUnits.steps))
2338
3577
  )
2339
3578
  );
3579
+ redeemers.setValues(redeemersList);
3580
+ this.txWitnessSet.setRedeemers(redeemers);
2340
3581
  };
2341
3582
  addSimpleScriptTxIn = (currentTxIn) => {
2342
3583
  this.addTxIn({
@@ -2350,21 +3591,12 @@ var CardanoSDKSerializer = class {
2350
3591
  this.scriptsProvided.add(
2351
3592
  Script.newNativeScript(
2352
3593
  NativeScript.fromCbor(
2353
- (0, import_util7.HexBlob)(currentTxIn.simpleScriptTxIn.scriptSource.scriptCode)
3594
+ (0, import_util9.HexBlob)(currentTxIn.simpleScriptTxIn.scriptSource.scriptCode)
2354
3595
  )
2355
- )
3596
+ ).toCbor()
2356
3597
  );
2357
3598
  } else if (currentTxIn.simpleScriptTxIn.scriptSource.type === "Inline") {
2358
- let referenceInputs = this.txBody.referenceInputs() ?? import_core6.Serialization.CborSet.fromCore([], TransactionInput.fromCore);
2359
- let referenceInputsList = [...referenceInputs.values()];
2360
- referenceInputsList.push(
2361
- new TransactionInput(
2362
- TransactionId(currentTxIn.simpleScriptTxIn.scriptSource.txHash),
2363
- BigInt(currentTxIn.simpleScriptTxIn.scriptSource.txIndex)
2364
- )
2365
- );
2366
- referenceInputs.setValues(referenceInputsList);
2367
- this.txBody.setReferenceInputs(referenceInputs);
3599
+ this.addSimpleScriptRef(currentTxIn.simpleScriptTxIn.scriptSource);
2368
3600
  }
2369
3601
  };
2370
3602
  addAllOutputs = (outputs) => {
@@ -2374,32 +3606,41 @@ var CardanoSDKSerializer = class {
2374
3606
  };
2375
3607
  addOutput = (output) => {
2376
3608
  const currentOutputs = this.txBody.outputs();
2377
- const cardanoOutput = new TransactionOutput(
2378
- Address.fromBech32(output.address),
3609
+ currentOutputs.push(this.toCardanoOutput(output));
3610
+ this.txBody.setOutputs(currentOutputs);
3611
+ };
3612
+ toCardanoOutput = (output) => {
3613
+ let cardanoOutput = new TransactionOutput(
3614
+ toCardanoAddress(output.address),
2379
3615
  toValue(output.amount)
2380
3616
  );
2381
3617
  if (output.datum?.type === "Hash") {
2382
3618
  cardanoOutput.setDatum(
2383
3619
  Datum.newDataHash(
2384
3620
  DatumHash.fromHexBlob(
2385
- (0, import_util7.HexBlob)(toPlutusData(output.datum.data.content).hash())
3621
+ (0, import_util9.HexBlob)(fromBuilderToPlutusData(output.datum.data).hash())
2386
3622
  )
2387
3623
  )
2388
3624
  );
2389
3625
  } else if (output.datum?.type === "Inline") {
2390
3626
  cardanoOutput.setDatum(
2391
- Datum.newInlineData(
2392
- toPlutusData(output.datum.data.content)
2393
- // TODO: handle json / raw datum
2394
- )
3627
+ Datum.newInlineData(fromBuilderToPlutusData(output.datum.data))
2395
3628
  );
3629
+ } else if (output.datum?.type === "Embedded") {
3630
+ const currentWitnessDatum = this.txWitnessSet.plutusData() ?? import_core7.Serialization.CborSet.fromCore([], import_core7.Serialization.PlutusData.fromCore);
3631
+ const currentWitnessDatumValues = [...currentWitnessDatum.values()];
3632
+ currentWitnessDatumValues.push(
3633
+ fromBuilderToPlutusData(output.datum.data)
3634
+ );
3635
+ currentWitnessDatum.setValues(currentWitnessDatumValues);
3636
+ this.txWitnessSet.setPlutusData(currentWitnessDatum);
2396
3637
  }
2397
3638
  if (output.referenceScript) {
2398
3639
  switch (output.referenceScript.version) {
2399
3640
  case "V1": {
2400
3641
  cardanoOutput.setScriptRef(
2401
3642
  Script.newPlutusV1Script(
2402
- PlutusV1Script.fromCbor((0, import_util7.HexBlob)(output.referenceScript.code))
3643
+ PlutusV1Script.fromCbor((0, import_util9.HexBlob)(output.referenceScript.code))
2403
3644
  )
2404
3645
  );
2405
3646
  break;
@@ -2407,7 +3648,7 @@ var CardanoSDKSerializer = class {
2407
3648
  case "V2": {
2408
3649
  cardanoOutput.setScriptRef(
2409
3650
  Script.newPlutusV2Script(
2410
- PlutusV2Script.fromCbor((0, import_util7.HexBlob)(output.referenceScript.code))
3651
+ PlutusV2Script.fromCbor((0, import_util9.HexBlob)(output.referenceScript.code))
2411
3652
  )
2412
3653
  );
2413
3654
  break;
@@ -2415,27 +3656,26 @@ var CardanoSDKSerializer = class {
2415
3656
  case "V3": {
2416
3657
  cardanoOutput.setScriptRef(
2417
3658
  Script.newPlutusV3Script(
2418
- PlutusV3Script.fromCbor((0, import_util7.HexBlob)(output.referenceScript.code))
3659
+ PlutusV3Script.fromCbor((0, import_util9.HexBlob)(output.referenceScript.code))
2419
3660
  )
2420
3661
  );
2421
3662
  break;
2422
3663
  }
2423
3664
  }
2424
3665
  }
2425
- currentOutputs.push(cardanoOutput);
2426
- this.txBody.setOutputs(currentOutputs);
3666
+ return cardanoOutput;
2427
3667
  };
2428
3668
  addAllReferenceInputs = (refInputs) => {
2429
3669
  for (let i = 0; i < refInputs.length; i++) {
2430
- this.addReferenceIput(refInputs[i]);
3670
+ this.addReferenceInput(refInputs[i]);
2431
3671
  }
2432
3672
  };
2433
- addReferenceIput = (refInput) => {
2434
- let referenceInputs = this.txBody.referenceInputs() ?? import_core6.Serialization.CborSet.fromCore([], TransactionInput.fromCore);
3673
+ addReferenceInput = (refInput) => {
3674
+ let referenceInputs = this.txBody.referenceInputs() ?? import_core7.Serialization.CborSet.fromCore([], TransactionInput.fromCore);
2435
3675
  let referenceInputsList = [...referenceInputs.values()];
2436
3676
  referenceInputsList.push(
2437
3677
  new TransactionInput(
2438
- TransactionId.fromHexBlob((0, import_util7.HexBlob)(refInput.txHash)),
3678
+ TransactionId.fromHexBlob((0, import_util9.HexBlob)(refInput.txHash)),
2439
3679
  BigInt(refInput.txIndex)
2440
3680
  )
2441
3681
  );
@@ -2443,9 +3683,24 @@ var CardanoSDKSerializer = class {
2443
3683
  this.txBody.setReferenceInputs(referenceInputs);
2444
3684
  };
2445
3685
  addAllMints = (mints) => {
2446
- for (let i = 0; i < mints.length; i++) {
2447
- this.addMint(mints[i]);
3686
+ for (let i2 = 0; i2 < mints.length; i2++) {
3687
+ this.addMint(mints[i2]);
2448
3688
  }
3689
+ let redeemers = this.txWitnessSet.redeemers() ?? Redeemers.fromCore([]);
3690
+ let redeemersList = [...redeemers.values()];
3691
+ let i = 0;
3692
+ this.mintRedeemers.forEach((redeemer) => {
3693
+ const newRedeemer = new Redeemer(
3694
+ redeemer.tag(),
3695
+ BigInt(i),
3696
+ redeemer.data(),
3697
+ redeemer.exUnits()
3698
+ );
3699
+ redeemersList.push(newRedeemer);
3700
+ redeemers.setValues(redeemersList);
3701
+ i++;
3702
+ });
3703
+ this.txWitnessSet.setRedeemers(redeemers);
2449
3704
  };
2450
3705
  addMint = (mint) => {
2451
3706
  const currentMint = this.txBody.mint() ?? /* @__PURE__ */ new Map();
@@ -2455,15 +3710,153 @@ var CardanoSDKSerializer = class {
2455
3710
  throw new Error("The same asset is already in the mint field");
2456
3711
  }
2457
3712
  }
2458
- currentMint.set(
2459
- AssetId.fromParts(PolicyId(mint.policyId), AssetName(mint.assetName)),
2460
- BigInt(mint.amount)
3713
+ currentMint.set(
3714
+ AssetId.fromParts(PolicyId(mint.policyId), AssetName(mint.assetName)),
3715
+ BigInt(mint.amount)
3716
+ );
3717
+ this.txBody.setMint(currentMint);
3718
+ if (mint.type === "Native") {
3719
+ if (!mint.scriptSource)
3720
+ throw new Error("Script source not provided for native script mint");
3721
+ const nativeScriptSource = mint.scriptSource;
3722
+ if (!nativeScriptSource)
3723
+ throw new Error(
3724
+ "A script source for a native script was not a native script somehow"
3725
+ );
3726
+ if (nativeScriptSource.type === "Provided") {
3727
+ this.scriptsProvided.add(
3728
+ Script.newNativeScript(
3729
+ NativeScript.fromCbor((0, import_util9.HexBlob)(nativeScriptSource.scriptCode))
3730
+ ).toCbor()
3731
+ );
3732
+ } else if (nativeScriptSource.type === "Inline") {
3733
+ this.addSimpleScriptRef(nativeScriptSource);
3734
+ }
3735
+ } else if (mint.type === "Plutus") {
3736
+ if (!mint.scriptSource)
3737
+ throw new Error("Script source not provided for plutus script mint");
3738
+ const plutusScriptSource = mint.scriptSource;
3739
+ if (!plutusScriptSource) {
3740
+ throw new Error(
3741
+ "A script source for a plutus mint was not plutus script somehow"
3742
+ );
3743
+ }
3744
+ if (!mint.redeemer) {
3745
+ throw new Error("A redeemer was not provided for a plutus mint");
3746
+ }
3747
+ const currentRedeemer = new Redeemer(
3748
+ RedeemerTag.Mint,
3749
+ BigInt(0),
3750
+ fromBuilderToPlutusData(mint.redeemer.data),
3751
+ new ExUnits(
3752
+ BigInt(mint.redeemer.exUnits.mem),
3753
+ BigInt(mint.redeemer.exUnits.steps)
3754
+ )
3755
+ );
3756
+ if (this.mintRedeemers.has(mint.policyId)) {
3757
+ if (this.mintRedeemers.get(mint.policyId)?.toCbor() !== currentRedeemer.toCbor()) {
3758
+ throw new Error(
3759
+ "The same minting policy must have the same redeemer"
3760
+ );
3761
+ }
3762
+ } else {
3763
+ this.mintRedeemers.set(mint.policyId, currentRedeemer);
3764
+ }
3765
+ if (plutusScriptSource.type === "Provided") {
3766
+ this.addProvidedPlutusScript(plutusScriptSource.script);
3767
+ } else if (plutusScriptSource.type === "Inline") {
3768
+ this.addScriptRef(plutusScriptSource);
3769
+ }
3770
+ }
3771
+ };
3772
+ addAllCerts = (certs) => {
3773
+ for (let i = 0; i < certs.length; i++) {
3774
+ this.addCert(certs[i], i);
3775
+ }
3776
+ };
3777
+ addCert = (cert, index) => {
3778
+ const currentCerts = this.txBody.certs() ?? import_core7.Serialization.CborSet.fromCore([], import_core7.Serialization.Certificate.fromCore);
3779
+ let currentCertsValues = [...currentCerts.values()];
3780
+ currentCertsValues.push(toCardanoCert(cert.certType));
3781
+ currentCerts.setValues(currentCertsValues);
3782
+ this.txBody.setCerts(currentCerts);
3783
+ if (cert.type === "SimpleScriptCertificate") {
3784
+ if (!cert.simpleScriptSource)
3785
+ throw new Error("Script source not provided for native script cert");
3786
+ const nativeScriptSource = cert.simpleScriptSource;
3787
+ if (!nativeScriptSource)
3788
+ throw new Error(
3789
+ "A script source for a native script was not a native script somehow"
3790
+ );
3791
+ if (nativeScriptSource.type === "Provided") {
3792
+ this.scriptsProvided.add(
3793
+ Script.newNativeScript(
3794
+ NativeScript.fromCbor((0, import_util9.HexBlob)(nativeScriptSource.scriptCode))
3795
+ ).toCbor()
3796
+ );
3797
+ } else if (nativeScriptSource.type === "Inline") {
3798
+ this.addSimpleScriptRef(nativeScriptSource);
3799
+ }
3800
+ } else if (cert.type === "ScriptCertificate") {
3801
+ if (!cert.scriptSource)
3802
+ throw new Error(
3803
+ "Script source not provided for plutus script certificate"
3804
+ );
3805
+ const plutusScriptSource = cert.scriptSource;
3806
+ if (!plutusScriptSource) {
3807
+ throw new Error(
3808
+ "A script source for a plutus certificate was not plutus script somehow"
3809
+ );
3810
+ }
3811
+ if (!cert.redeemer) {
3812
+ throw new Error("A redeemer was not provided for a plutus certificate");
3813
+ }
3814
+ let redeemers = this.txWitnessSet.redeemers() ?? Redeemers.fromCore([]);
3815
+ let redeemersList = [...redeemers.values()];
3816
+ redeemersList.push(
3817
+ new Redeemer(
3818
+ RedeemerTag.Cert,
3819
+ BigInt(index),
3820
+ fromBuilderToPlutusData(cert.redeemer.data),
3821
+ new ExUnits(
3822
+ BigInt(cert.redeemer.exUnits.mem),
3823
+ BigInt(cert.redeemer.exUnits.steps)
3824
+ )
3825
+ )
3826
+ );
3827
+ redeemers.setValues(redeemersList);
3828
+ this.txWitnessSet.setRedeemers(redeemers);
3829
+ if (plutusScriptSource.type === "Provided") {
3830
+ this.addProvidedPlutusScript(plutusScriptSource.script);
3831
+ } else if (plutusScriptSource.type === "Inline") {
3832
+ this.addScriptRef(plutusScriptSource);
3833
+ }
3834
+ }
3835
+ };
3836
+ addAllWithdrawals = (withdrawals) => {
3837
+ for (let i = 0; i < withdrawals.length; i++) {
3838
+ this.addWithdrawal(withdrawals[i], i);
3839
+ }
3840
+ };
3841
+ addWithdrawal = (withdrawal, index) => {
3842
+ const currentWithdrawals = this.txBody.withdrawals() ?? /* @__PURE__ */ new Map();
3843
+ const address = toCardanoAddress(withdrawal.address);
3844
+ const rewardAddress = address.asReward();
3845
+ if (!rewardAddress) {
3846
+ throw new Error("Failed to parse reward address for withdrawal");
3847
+ }
3848
+ currentWithdrawals.set(
3849
+ RewardAccount.fromCredential(
3850
+ rewardAddress.getPaymentCredential(),
3851
+ address.getNetworkId()
3852
+ ),
3853
+ BigInt(withdrawal.coin)
2461
3854
  );
2462
- this.txBody.setMint(currentMint);
2463
- if (mint.type === "Native") {
2464
- if (!mint.scriptSource)
2465
- throw new Error("Script source not provided for native script mint");
2466
- const nativeScriptSource = mint.scriptSource;
3855
+ this.txBody.setWithdrawals(currentWithdrawals);
3856
+ if (withdrawal.type === "SimpleScriptWithdrawal") {
3857
+ if (!withdrawal.scriptSource)
3858
+ throw new Error("Script source not provided for native script cert");
3859
+ const nativeScriptSource = withdrawal.scriptSource;
2467
3860
  if (!nativeScriptSource)
2468
3861
  throw new Error(
2469
3862
  "A script source for a native script was not a native script somehow"
@@ -2471,85 +3864,45 @@ var CardanoSDKSerializer = class {
2471
3864
  if (nativeScriptSource.type === "Provided") {
2472
3865
  this.scriptsProvided.add(
2473
3866
  Script.newNativeScript(
2474
- NativeScript.fromCbor((0, import_util7.HexBlob)(nativeScriptSource.scriptCode))
2475
- )
3867
+ NativeScript.fromCbor((0, import_util9.HexBlob)(nativeScriptSource.scriptCode))
3868
+ ).toCbor()
2476
3869
  );
2477
3870
  } else if (nativeScriptSource.type === "Inline") {
2478
- let referenceInputs = this.txBody.referenceInputs() ?? import_core6.Serialization.CborSet.fromCore([], TransactionInput.fromCore);
2479
- let referenceInputsList = [...referenceInputs.values()];
2480
- referenceInputsList.push(
2481
- new TransactionInput(
2482
- TransactionId(nativeScriptSource.txHash),
2483
- BigInt(nativeScriptSource.txIndex)
2484
- )
2485
- );
2486
- referenceInputs.setValues(referenceInputsList);
2487
- this.txBody.setReferenceInputs(referenceInputs);
3871
+ this.addSimpleScriptRef(nativeScriptSource);
2488
3872
  }
2489
- } else if (mint.type === "Plutus") {
2490
- if (!mint.scriptSource)
2491
- throw new Error("Script source not provided for plutus script mint");
2492
- const plutusScriptSource = mint.scriptSource;
3873
+ } else if (withdrawal.type === "ScriptWithdrawal") {
3874
+ if (!withdrawal.scriptSource)
3875
+ throw new Error(
3876
+ "Script source not provided for plutus script certificate"
3877
+ );
3878
+ const plutusScriptSource = withdrawal.scriptSource;
2493
3879
  if (!plutusScriptSource) {
2494
3880
  throw new Error(
2495
- "A script source for a plutus mint was not plutus script somehow"
3881
+ "A script source for a plutus certificate was not plutus script somehow"
2496
3882
  );
2497
3883
  }
3884
+ if (!withdrawal.redeemer) {
3885
+ throw new Error("A redeemer was not provided for a plutus certificate");
3886
+ }
3887
+ let redeemers = this.txWitnessSet.redeemers() ?? Redeemers.fromCore([]);
3888
+ let redeemersList = [...redeemers.values()];
3889
+ redeemersList.push(
3890
+ new Redeemer(
3891
+ RedeemerTag.Reward,
3892
+ BigInt(index),
3893
+ fromBuilderToPlutusData(withdrawal.redeemer.data),
3894
+ new ExUnits(
3895
+ BigInt(withdrawal.redeemer.exUnits.mem),
3896
+ BigInt(withdrawal.redeemer.exUnits.steps)
3897
+ )
3898
+ )
3899
+ );
3900
+ redeemers.setValues(redeemersList);
3901
+ this.txWitnessSet.setRedeemers(redeemers);
2498
3902
  if (plutusScriptSource.type === "Provided") {
2499
- switch (plutusScriptSource.script.version) {
2500
- case "V1":
2501
- this.scriptsProvided.add(
2502
- Script.newPlutusV1Script(
2503
- PlutusV1Script.fromCbor(
2504
- (0, import_util7.HexBlob)(plutusScriptSource.script.code)
2505
- )
2506
- )
2507
- );
2508
- break;
2509
- case "V2":
2510
- this.scriptsProvided.add(
2511
- Script.newPlutusV2Script(
2512
- PlutusV2Script.fromCbor(
2513
- (0, import_util7.HexBlob)(plutusScriptSource.script.code)
2514
- )
2515
- )
2516
- );
2517
- break;
2518
- case "V3":
2519
- this.scriptsProvided.add(
2520
- Script.newPlutusV3Script(
2521
- PlutusV3Script.fromCbor(
2522
- (0, import_util7.HexBlob)(plutusScriptSource.script.code)
2523
- )
2524
- )
2525
- );
2526
- break;
2527
- }
3903
+ this.addProvidedPlutusScript(plutusScriptSource.script);
2528
3904
  } else if (plutusScriptSource.type === "Inline") {
2529
- let referenceInputs = this.txBody.referenceInputs() ?? import_core6.Serialization.CborSet.fromCore([], TransactionInput.fromCore);
2530
- let referenceInputsList = [...referenceInputs.values()];
2531
- referenceInputsList.push(
2532
- new TransactionInput(
2533
- TransactionId(plutusScriptSource.txHash),
2534
- BigInt(plutusScriptSource.txIndex)
2535
- )
2536
- );
2537
- referenceInputs.setValues(referenceInputsList);
2538
- this.txBody.setReferenceInputs(referenceInputs);
2539
- switch (plutusScriptSource.version) {
2540
- case "V1": {
2541
- this.usedLanguages[PlutusLanguageVersion.V1] = true;
2542
- break;
2543
- }
2544
- case "V2": {
2545
- this.usedLanguages[PlutusLanguageVersion.V2] = true;
2546
- break;
2547
- }
2548
- case "V3": {
2549
- this.usedLanguages[PlutusLanguageVersion.V3] = true;
2550
- break;
2551
- }
2552
- }
3905
+ this.addScriptRef(plutusScriptSource);
2553
3906
  }
2554
3907
  }
2555
3908
  };
@@ -2565,7 +3918,7 @@ var CardanoSDKSerializer = class {
2565
3918
  TransactionId(collateral.txIn.txHash),
2566
3919
  BigInt(collateral.txIn.txIndex)
2567
3920
  );
2568
- const collateralInputs = this.txBody.collateral() ?? import_core6.Serialization.CborSet.fromCore([], TransactionInput.fromCore);
3921
+ const collateralInputs = this.txBody.collateral() ?? import_core7.Serialization.CborSet.fromCore([], TransactionInput.fromCore);
2569
3922
  const collateralInputsList = [
2570
3923
  ...collateralInputs.values()
2571
3924
  ];
@@ -2577,7 +3930,7 @@ var CardanoSDKSerializer = class {
2577
3930
  collateralInputsList.push(cardanoTxIn);
2578
3931
  collateralInputs.setValues(collateralInputsList);
2579
3932
  const cardanoTxOut = new TransactionOutput(
2580
- Address.fromBech32(collateral.txIn.address),
3933
+ toCardanoAddress(collateral.txIn.address),
2581
3934
  toValue(collateral.txIn.amount)
2582
3935
  );
2583
3936
  this.utxoContext.set(cardanoTxIn, cardanoTxOut);
@@ -2591,29 +3944,31 @@ var CardanoSDKSerializer = class {
2591
3944
  this.txBody.setTtl(Slot(validity.invalidHereafter));
2592
3945
  }
2593
3946
  };
2594
- buildWitnessSet = () => {
2595
- const inputs = this.txBody.inputs();
2596
- for (let i = 0; i < inputs.size(); i += 1) {
2597
- const input = inputs.values().at(i);
2598
- if (input) {
2599
- let redeemer = this.redeemerContext.get(input);
2600
- if (redeemer) {
2601
- redeemer.setIndex(BigInt(i));
2602
- }
2603
- }
3947
+ addAllRequiredSignatures = (requiredSignatures) => {
3948
+ const requiredSigners = this.txBody.requiredSigners() ?? import_core7.Serialization.CborSet.fromCore([], import_core7.Serialization.Hash.fromCore);
3949
+ let requiredSignerValues = [...requiredSigners.values()];
3950
+ for (const requiredSigner of requiredSignatures) {
3951
+ requiredSignerValues.push(
3952
+ import_core7.Serialization.Hash.fromCore(Ed25519KeyHashHex2(requiredSigner))
3953
+ );
2604
3954
  }
2605
- let redeemers = this.txWitnessSet.redeemers() ?? Redeemers.fromCore([]);
2606
- let redeemersList = [...redeemers.values()];
2607
- this.redeemerContext.forEach((redeemer) => {
2608
- redeemersList.push(redeemer);
2609
- });
2610
- redeemers.setValues(redeemersList);
2611
- this.txWitnessSet.setRedeemers(redeemers);
2612
- let nativeScripts = this.txWitnessSet.nativeScripts() ?? import_core6.Serialization.CborSet.fromCore([], NativeScript.fromCore);
2613
- let v1Scripts = this.txWitnessSet.plutusV1Scripts() ?? import_core6.Serialization.CborSet.fromCore([], PlutusV1Script.fromCore);
2614
- let v2Scripts = this.txWitnessSet.plutusV2Scripts() ?? import_core6.Serialization.CborSet.fromCore([], PlutusV2Script.fromCore);
2615
- let v3Scripts = this.txWitnessSet.plutusV3Scripts() ?? import_core6.Serialization.CborSet.fromCore([], PlutusV3Script.fromCore);
2616
- this.scriptsProvided.forEach((script) => {
3955
+ requiredSigners.setValues(requiredSignerValues);
3956
+ this.txBody.setRequiredSigners(requiredSigners);
3957
+ };
3958
+ addMetadata = (metadata) => {
3959
+ this.txAuxilliaryData.setMetadata(
3960
+ new import_core7.Serialization.GeneralTransactionMetadata(
3961
+ toCardanoMetadataMap(metadata)
3962
+ )
3963
+ );
3964
+ };
3965
+ buildWitnessSet = () => {
3966
+ let nativeScripts = this.txWitnessSet.nativeScripts() ?? import_core7.Serialization.CborSet.fromCore([], NativeScript.fromCore);
3967
+ let v1Scripts = this.txWitnessSet.plutusV1Scripts() ?? import_core7.Serialization.CborSet.fromCore([], PlutusV1Script.fromCore);
3968
+ let v2Scripts = this.txWitnessSet.plutusV2Scripts() ?? import_core7.Serialization.CborSet.fromCore([], PlutusV2Script.fromCore);
3969
+ let v3Scripts = this.txWitnessSet.plutusV3Scripts() ?? import_core7.Serialization.CborSet.fromCore([], PlutusV3Script.fromCore);
3970
+ this.scriptsProvided.forEach((scriptHex) => {
3971
+ const script = Script.fromCbor((0, import_util9.HexBlob)(scriptHex));
2617
3972
  if (script.asNative() !== void 0) {
2618
3973
  let nativeScriptsList = [...nativeScripts.values()];
2619
3974
  nativeScriptsList.push(script.asNative());
@@ -2636,20 +3991,23 @@ var CardanoSDKSerializer = class {
2636
3991
  this.txWitnessSet.setPlutusV2Scripts(v2Scripts);
2637
3992
  this.txWitnessSet.setPlutusV3Scripts(v3Scripts);
2638
3993
  });
2639
- let datums = this.txWitnessSet.plutusData() ?? import_core6.Serialization.CborSet.fromCore([], PlutusData.fromCore);
3994
+ let datums = this.txWitnessSet.plutusData() ?? import_core7.Serialization.CborSet.fromCore([], PlutusData.fromCore);
3995
+ let datumsList = [...datums.values()];
2640
3996
  this.datumsProvided.forEach((datum) => {
2641
- let datumsList = [...datums.values()];
2642
3997
  datumsList.push(datum);
2643
- datums.setValues(datumsList);
2644
3998
  });
3999
+ datums.setValues(datumsList);
2645
4000
  this.txWitnessSet.setPlutusData(datums);
2646
- let costModelV1 = import_core6.Serialization.CostModel.newPlutusV1(
2647
- import_common5.DEFAULT_V1_COST_MODEL_LIST
4001
+ let costModelV1 = import_core7.Serialization.CostModel.newPlutusV1(
4002
+ import_common8.DEFAULT_V1_COST_MODEL_LIST
4003
+ );
4004
+ let costModelV2 = import_core7.Serialization.CostModel.newPlutusV2(
4005
+ import_common8.DEFAULT_V2_COST_MODEL_LIST
2648
4006
  );
2649
- let costModelV2 = import_core6.Serialization.CostModel.newPlutusV2(
2650
- import_common5.DEFAULT_V2_COST_MODEL_LIST
4007
+ let costModelV3 = import_core7.Serialization.CostModel.newPlutusV3(
4008
+ import_common8.DEFAULT_V3_COST_MODEL_LIST
2651
4009
  );
2652
- let costModels = new import_core6.Serialization.Costmdls();
4010
+ let costModels = new import_core7.Serialization.Costmdls();
2653
4011
  if (this.usedLanguages[PlutusLanguageVersion.V1]) {
2654
4012
  costModels.insert(costModelV1);
2655
4013
  }
@@ -2657,7 +4015,9 @@ var CardanoSDKSerializer = class {
2657
4015
  costModels.insert(costModelV2);
2658
4016
  }
2659
4017
  if (this.usedLanguages[PlutusLanguageVersion.V3]) {
4018
+ costModels.insert(costModelV3);
2660
4019
  }
4020
+ const redeemers = this.txWitnessSet.redeemers() ?? Redeemers.fromCore([]);
2661
4021
  let scriptDataHash = hashScriptData(
2662
4022
  costModels,
2663
4023
  redeemers.size() > 0 ? [...redeemers.values()] : void 0,
@@ -2666,8 +4026,38 @@ var CardanoSDKSerializer = class {
2666
4026
  if (scriptDataHash) {
2667
4027
  this.txBody.setScriptDataHash(scriptDataHash);
2668
4028
  }
4029
+ let auxiliaryDataHash = computeAuxiliaryDataHash(
4030
+ this.txAuxilliaryData.toCore()
4031
+ );
4032
+ if (auxiliaryDataHash) {
4033
+ this.txBody.setAuxiliaryDataHash(auxiliaryDataHash);
4034
+ }
4035
+ };
4036
+ removeInputRefInputOverlap = () => {
4037
+ let refInputsValues = [];
4038
+ const inputs = this.txBody.inputs()?.values();
4039
+ if (this.txBody.referenceInputs()) {
4040
+ const currentRefInputValues = this.txBody.referenceInputs().values();
4041
+ currentRefInputValues.forEach((refInput) => {
4042
+ let found = false;
4043
+ for (let i = 0; i < inputs.length; i++) {
4044
+ if (refInput.toCbor() === inputs[i].toCbor()) {
4045
+ found = true;
4046
+ }
4047
+ }
4048
+ if (!found) {
4049
+ refInputsValues.push(refInput);
4050
+ }
4051
+ });
4052
+ this.txBody.setReferenceInputs(
4053
+ import_core7.Serialization.CborSet.fromCore(
4054
+ refInputsValues.map((input) => input.toCore()),
4055
+ TransactionInput.fromCore
4056
+ )
4057
+ );
4058
+ }
2669
4059
  };
2670
- balanceTx = (changeAddress, numberOfRequiredWitnesses, protocolParams) => {
4060
+ balanceTx = (changeAddress) => {
2671
4061
  if (changeAddress === "") {
2672
4062
  throw new Error("Can't balance tx without a change address");
2673
4063
  }
@@ -2701,47 +4091,415 @@ var CardanoSDKSerializer = class {
2701
4091
  remainingValue = subValue(remainingValue, output.amount());
2702
4092
  }
2703
4093
  }
4094
+ const certs = this.txBody.certs();
4095
+ if (certs) {
4096
+ certs.values().forEach((cert) => {
4097
+ switch (cert.toCore().__typename) {
4098
+ case CertificateType.StakeRegistration: {
4099
+ remainingValue = subValue(
4100
+ remainingValue,
4101
+ new Value(BigInt(this.protocolParams.keyDeposit))
4102
+ );
4103
+ break;
4104
+ }
4105
+ case CertificateType.StakeDeregistration: {
4106
+ remainingValue = mergeValue(
4107
+ remainingValue,
4108
+ new Value(BigInt(this.protocolParams.keyDeposit))
4109
+ );
4110
+ break;
4111
+ }
4112
+ case CertificateType.Registration: {
4113
+ remainingValue = subValue(
4114
+ remainingValue,
4115
+ new Value(BigInt(cert.asRegistrationCert()?.deposit() ?? 0))
4116
+ );
4117
+ break;
4118
+ }
4119
+ case CertificateType.Unregistration: {
4120
+ remainingValue = mergeValue(
4121
+ remainingValue,
4122
+ new Value(BigInt(cert.asUnregistrationCert()?.deposit() ?? 0))
4123
+ );
4124
+ break;
4125
+ }
4126
+ case CertificateType.PoolRegistration: {
4127
+ remainingValue = subValue(
4128
+ remainingValue,
4129
+ new Value(BigInt(this.protocolParams.poolDeposit))
4130
+ );
4131
+ break;
4132
+ }
4133
+ case CertificateType.PoolRetirement: {
4134
+ remainingValue = mergeValue(
4135
+ remainingValue,
4136
+ new Value(BigInt(this.protocolParams.poolDeposit))
4137
+ );
4138
+ break;
4139
+ }
4140
+ case CertificateType.RegisterDelegateRepresentative: {
4141
+ remainingValue = subValue(
4142
+ remainingValue,
4143
+ new Value(
4144
+ BigInt(
4145
+ cert.asRegisterDelegateRepresentativeCert()?.deposit() ?? 0
4146
+ )
4147
+ )
4148
+ );
4149
+ break;
4150
+ }
4151
+ case CertificateType.UnregisterDelegateRepresentative: {
4152
+ remainingValue = mergeValue(
4153
+ remainingValue,
4154
+ new Value(
4155
+ BigInt(
4156
+ cert.asUnregisterDelegateRepresentativeCert()?.deposit() ?? 0
4157
+ )
4158
+ )
4159
+ );
4160
+ break;
4161
+ }
4162
+ case CertificateType.StakeRegistrationDelegation: {
4163
+ remainingValue = subValue(
4164
+ remainingValue,
4165
+ new Value(
4166
+ BigInt(
4167
+ cert.asStakeRegistrationDelegationCert()?.deposit() ?? 0
4168
+ )
4169
+ )
4170
+ );
4171
+ break;
4172
+ }
4173
+ case CertificateType.StakeVoteRegistrationDelegation: {
4174
+ remainingValue = subValue(
4175
+ remainingValue,
4176
+ new Value(
4177
+ BigInt(
4178
+ cert.asStakeVoteRegistrationDelegationCert()?.deposit() ?? 0
4179
+ )
4180
+ )
4181
+ );
4182
+ break;
4183
+ }
4184
+ }
4185
+ });
4186
+ }
2704
4187
  if (remainingValue.coin() < 0 || !empty(negatives(remainingValue))) {
2705
4188
  throw new Error(`Not enough funds to satisfy outputs`);
2706
4189
  }
2707
4190
  currentOutputs.push(
2708
- new TransactionOutput(Address.fromBech32(changeAddress), remainingValue)
4191
+ new TransactionOutput(toCardanoAddress(changeAddress), remainingValue)
2709
4192
  );
2710
4193
  this.txBody.setOutputs(currentOutputs);
2711
4194
  this.txBody.setFee(BigInt("10000000"));
4195
+ const numberOfRequiredWitnesses = this.countNumberOfRequiredWitnesses();
2712
4196
  const dummyTx = this.createDummyTx(numberOfRequiredWitnesses);
2713
- const fee = protocolParams.minFeeB + dummyTx.toCbor().length / 2 * Number(protocolParams.coinsPerUtxoSize);
2714
- this.txBody.setFee(BigInt(fee));
4197
+ const fee = calculateFees(
4198
+ this.protocolParams.minFeeA,
4199
+ this.protocolParams.minFeeB,
4200
+ this.protocolParams.minFeeRefScriptCostPerByte,
4201
+ this.protocolParams.priceMem,
4202
+ this.protocolParams.priceStep,
4203
+ dummyTx,
4204
+ this.refScriptSize
4205
+ );
4206
+ this.txBody.setFee(fee);
2715
4207
  const changeOutput = currentOutputs.pop();
2716
4208
  if (!changeOutput) {
2717
4209
  throw new Error(
2718
4210
  "Somehow the output length was 0 after attempting to calculate fees"
2719
4211
  );
2720
4212
  }
2721
- changeOutput.amount().setCoin(changeOutput.amount().coin() - BigInt(fee));
2722
- currentOutputs.push(changeOutput);
4213
+ if (changeOutput.amount().coin() - fee > 0) {
4214
+ changeOutput.amount().setCoin(changeOutput.amount().coin() - fee);
4215
+ currentOutputs.push(changeOutput);
4216
+ } else if (changeOutput.amount().coin() - fee < 0) {
4217
+ throw new Error(
4218
+ "There was enough inputs to cover outputs, but not enough to cover fees"
4219
+ );
4220
+ }
2723
4221
  this.txBody.setOutputs(currentOutputs);
2724
4222
  };
2725
4223
  createDummyTx = (numberOfRequiredWitnesses) => {
2726
- let dummyWitnessSet = new TransactionWitnessSet();
4224
+ let dummyWitnessSet = TransactionWitnessSet.fromCbor(
4225
+ (0, import_util9.HexBlob)(this.txWitnessSet.toCbor())
4226
+ );
2727
4227
  const dummyVkeyWitnesses = [];
2728
4228
  for (let i = 0; i < numberOfRequiredWitnesses; i++) {
2729
4229
  dummyVkeyWitnesses.push([
2730
- Ed25519PublicKeyHex2("0".repeat(64)),
2731
- Ed25519SignatureHex2("0".repeat(128))
4230
+ Ed25519PublicKeyHex2(String(i).repeat(64)),
4231
+ Ed25519SignatureHex2(String(i).repeat(128))
2732
4232
  ]);
2733
4233
  }
2734
4234
  dummyWitnessSet.setVkeys(
2735
- import_core6.Serialization.CborSet.fromCore(dummyVkeyWitnesses, VkeyWitness.fromCore)
4235
+ import_core7.Serialization.CborSet.fromCore(dummyVkeyWitnesses, VkeyWitness.fromCore)
4236
+ );
4237
+ return new Transaction(this.txBody, dummyWitnessSet, this.txAuxilliaryData);
4238
+ };
4239
+ addScriptRef = (scriptSource) => {
4240
+ if (scriptSource.type !== "Inline") {
4241
+ return;
4242
+ }
4243
+ let referenceInputs = this.txBody.referenceInputs() ?? import_core7.Serialization.CborSet.fromCore([], TransactionInput.fromCore);
4244
+ let referenceInputsList = [...referenceInputs.values()];
4245
+ referenceInputsList.push(
4246
+ new TransactionInput(
4247
+ TransactionId(scriptSource.txHash),
4248
+ BigInt(scriptSource.txIndex)
4249
+ )
4250
+ );
4251
+ referenceInputs.setValues(referenceInputsList);
4252
+ this.txBody.setReferenceInputs(referenceInputs);
4253
+ switch (scriptSource.version) {
4254
+ case "V1": {
4255
+ this.usedLanguages[PlutusLanguageVersion.V1] = true;
4256
+ break;
4257
+ }
4258
+ case "V2": {
4259
+ this.usedLanguages[PlutusLanguageVersion.V2] = true;
4260
+ break;
4261
+ }
4262
+ case "V3": {
4263
+ this.usedLanguages[PlutusLanguageVersion.V3] = true;
4264
+ break;
4265
+ }
4266
+ }
4267
+ if (scriptSource.scriptSize) {
4268
+ this.refScriptSize += Number(scriptSource.scriptSize);
4269
+ } else {
4270
+ throw new Error(
4271
+ "A reference script was used without providing its size, this must be provided as fee calculations are based on it"
4272
+ );
4273
+ }
4274
+ };
4275
+ addSimpleScriptRef = (simpleScriptSource) => {
4276
+ if (simpleScriptSource.type !== "Inline") {
4277
+ return;
4278
+ }
4279
+ let referenceInputs = this.txBody.referenceInputs() ?? import_core7.Serialization.CborSet.fromCore([], TransactionInput.fromCore);
4280
+ let referenceInputsList = [...referenceInputs.values()];
4281
+ referenceInputsList.push(
4282
+ new TransactionInput(
4283
+ TransactionId(simpleScriptSource.txHash),
4284
+ BigInt(simpleScriptSource.txIndex)
4285
+ )
2736
4286
  );
2737
- return new Transaction(this.txBody, dummyWitnessSet);
4287
+ if (simpleScriptSource.scriptSize) {
4288
+ this.refScriptSize += Number(simpleScriptSource.scriptSize);
4289
+ } else {
4290
+ throw new Error(
4291
+ "A reference script was used without providing its size, this must be provided as fee calculations are based on it"
4292
+ );
4293
+ }
4294
+ referenceInputs.setValues(referenceInputsList);
4295
+ this.txBody.setReferenceInputs(referenceInputs);
4296
+ };
4297
+ countNumberOfRequiredWitnesses() {
4298
+ let requiredWitnesses = /* @__PURE__ */ new Set();
4299
+ const inputs = this.txBody.inputs().values();
4300
+ for (let i = 0; i < inputs.length; i++) {
4301
+ const input = inputs[i];
4302
+ const addressPaymentPart = this.utxoContext.get(input)?.address().getProps().paymentPart;
4303
+ if (addressPaymentPart?.type === 0) {
4304
+ requiredWitnesses.add(addressPaymentPart.hash);
4305
+ }
4306
+ }
4307
+ const collateralInputs = this.txBody.collateral()?.values();
4308
+ if (collateralInputs) {
4309
+ for (let i = 0; i < collateralInputs?.length; i++) {
4310
+ const collateralInput = collateralInputs[i];
4311
+ const addressPaymentPart = this.utxoContext.get(collateralInput)?.address().getProps().paymentPart;
4312
+ if (addressPaymentPart?.type === 0) {
4313
+ requiredWitnesses.add(addressPaymentPart.hash);
4314
+ }
4315
+ }
4316
+ }
4317
+ const withdrawalKeys = this.txBody.withdrawals()?.keys();
4318
+ if (withdrawalKeys) {
4319
+ for (let withdrawalKey of withdrawalKeys) {
4320
+ requiredWitnesses.add(RewardAccount.toHash(withdrawalKey));
4321
+ }
4322
+ }
4323
+ const certs = this.txBody.certs()?.values();
4324
+ if (certs) {
4325
+ for (let cert of certs) {
4326
+ const coreCert = cert.toCore();
4327
+ switch (coreCert.__typename) {
4328
+ case CertificateType.StakeRegistration: {
4329
+ requiredWitnesses.add(coreCert.stakeCredential.hash);
4330
+ break;
4331
+ }
4332
+ case CertificateType.StakeDeregistration: {
4333
+ requiredWitnesses.add(coreCert.stakeCredential.hash);
4334
+ break;
4335
+ }
4336
+ case CertificateType.PoolRegistration: {
4337
+ for (let owner of coreCert.poolParameters.owners) {
4338
+ requiredWitnesses.add(RewardAccount.toHash(owner));
4339
+ }
4340
+ requiredWitnesses.add(PoolId.toKeyHash(coreCert.poolParameters.id));
4341
+ break;
4342
+ }
4343
+ case CertificateType.PoolRetirement: {
4344
+ requiredWitnesses.add(PoolId.toKeyHash(coreCert.poolId));
4345
+ break;
4346
+ }
4347
+ case CertificateType.StakeDelegation: {
4348
+ requiredWitnesses.add(coreCert.stakeCredential.hash);
4349
+ break;
4350
+ }
4351
+ case CertificateType.MIR:
4352
+ break;
4353
+ case CertificateType.GenesisKeyDelegation: {
4354
+ requiredWitnesses.add(coreCert.genesisDelegateHash);
4355
+ break;
4356
+ }
4357
+ case CertificateType.Registration: {
4358
+ requiredWitnesses.add(coreCert.stakeCredential.hash);
4359
+ break;
4360
+ }
4361
+ case CertificateType.Unregistration: {
4362
+ requiredWitnesses.add(coreCert.stakeCredential.hash);
4363
+ break;
4364
+ }
4365
+ case CertificateType.VoteDelegation: {
4366
+ requiredWitnesses.add(coreCert.stakeCredential.hash);
4367
+ break;
4368
+ }
4369
+ case CertificateType.StakeVoteDelegation: {
4370
+ requiredWitnesses.add(coreCert.stakeCredential.hash);
4371
+ break;
4372
+ }
4373
+ case CertificateType.StakeRegistrationDelegation: {
4374
+ requiredWitnesses.add(coreCert.stakeCredential.hash);
4375
+ break;
4376
+ }
4377
+ case CertificateType.VoteRegistrationDelegation: {
4378
+ requiredWitnesses.add(coreCert.stakeCredential.hash);
4379
+ break;
4380
+ }
4381
+ case CertificateType.StakeVoteRegistrationDelegation: {
4382
+ requiredWitnesses.add(coreCert.stakeCredential.hash);
4383
+ break;
4384
+ }
4385
+ case CertificateType.AuthorizeCommitteeHot: {
4386
+ requiredWitnesses.add(coreCert.hotCredential.hash);
4387
+ break;
4388
+ }
4389
+ case CertificateType.ResignCommitteeCold: {
4390
+ requiredWitnesses.add(coreCert.coldCredential.hash);
4391
+ break;
4392
+ }
4393
+ case CertificateType.RegisterDelegateRepresentative: {
4394
+ requiredWitnesses.add(coreCert.dRepCredential.hash);
4395
+ break;
4396
+ }
4397
+ case CertificateType.UnregisterDelegateRepresentative: {
4398
+ requiredWitnesses.add(coreCert.dRepCredential.hash);
4399
+ break;
4400
+ }
4401
+ case CertificateType.UpdateDelegateRepresentative: {
4402
+ requiredWitnesses.add(coreCert.dRepCredential.hash);
4403
+ break;
4404
+ }
4405
+ }
4406
+ }
4407
+ }
4408
+ for (const scriptHex of this.scriptsProvided) {
4409
+ const script = Script.fromCbor((0, import_util9.HexBlob)(scriptHex));
4410
+ let nativeScript = script.asNative();
4411
+ if (nativeScript) {
4412
+ this.addKeyHashesFromNativeScript(nativeScript, requiredWitnesses);
4413
+ }
4414
+ }
4415
+ const requiredSigners = this.txBody.requiredSigners()?.values();
4416
+ if (requiredSigners) {
4417
+ for (let i = 0; i < requiredSigners.length; i++) {
4418
+ requiredWitnesses.add(requiredSigners[i].toCbor());
4419
+ }
4420
+ }
4421
+ return requiredWitnesses.size;
4422
+ }
4423
+ addKeyHashesFromNativeScript(script, keyHashes) {
4424
+ const scriptCore = script.toCore();
4425
+ switch (scriptCore.kind) {
4426
+ case RequireSignature: {
4427
+ keyHashes.add(scriptCore.keyHash);
4428
+ break;
4429
+ }
4430
+ case RequireTimeAfter: {
4431
+ break;
4432
+ }
4433
+ case RequireTimeBefore: {
4434
+ break;
4435
+ }
4436
+ case RequireAllOf: {
4437
+ for (const innerScript of scriptCore.scripts) {
4438
+ this.addKeyHashesFromNativeScript(
4439
+ NativeScript.fromCore(innerScript),
4440
+ keyHashes
4441
+ );
4442
+ }
4443
+ break;
4444
+ }
4445
+ case RequireAnyOf: {
4446
+ for (const innerScript of scriptCore.scripts) {
4447
+ this.addKeyHashesFromNativeScript(
4448
+ NativeScript.fromCore(innerScript),
4449
+ keyHashes
4450
+ );
4451
+ }
4452
+ break;
4453
+ }
4454
+ case RequireNOf: {
4455
+ for (const innerScript of scriptCore.scripts) {
4456
+ this.addKeyHashesFromNativeScript(
4457
+ NativeScript.fromCore(innerScript),
4458
+ keyHashes
4459
+ );
4460
+ }
4461
+ break;
4462
+ }
4463
+ }
4464
+ return keyHashes;
4465
+ }
4466
+ addProvidedPlutusScript = (script) => {
4467
+ switch (script.version) {
4468
+ case "V1": {
4469
+ this.scriptsProvided.add(
4470
+ Script.newPlutusV1Script(
4471
+ PlutusV1Script.fromCbor((0, import_util9.HexBlob)(script.code))
4472
+ ).toCbor()
4473
+ );
4474
+ this.usedLanguages[PlutusLanguageVersion.V1] = true;
4475
+ break;
4476
+ }
4477
+ case "V2": {
4478
+ this.scriptsProvided.add(
4479
+ Script.newPlutusV2Script(
4480
+ PlutusV2Script.fromCbor((0, import_util9.HexBlob)(script.code))
4481
+ ).toCbor()
4482
+ );
4483
+ this.usedLanguages[PlutusLanguageVersion.V2] = true;
4484
+ break;
4485
+ }
4486
+ case "V3": {
4487
+ this.scriptsProvided.add(
4488
+ Script.newPlutusV3Script(
4489
+ PlutusV3Script.fromCbor((0, import_util9.HexBlob)(script.code))
4490
+ ).toCbor()
4491
+ );
4492
+ this.usedLanguages[PlutusLanguageVersion.V3] = true;
4493
+ break;
4494
+ }
4495
+ }
2738
4496
  };
2739
4497
  };
2740
4498
 
2741
4499
  // src/plutus-tools/index.ts
4500
+ var import_cbor2 = require("@harmoniclabs/cbor");
2742
4501
  var import_plutus_data = require("@harmoniclabs/plutus-data");
2743
4502
  var import_uplc = require("@harmoniclabs/uplc");
2744
- var import_cbor = require("@harmoniclabs/cbor");
2745
4503
  var supportedPlutusCoreVersions = [
2746
4504
  {
2747
4505
  version: [1, 0, 0],
@@ -2752,6 +4510,19 @@ var supportedPlutusCoreVersions = [
2752
4510
  language: "Plutus V3"
2753
4511
  }
2754
4512
  ];
4513
+ var applyArgsToPlutusScript = (args, program, outputEncoding) => {
4514
+ const purePlutusBytes = getPurePlutusBytes(program);
4515
+ const parsedProgram = (0, import_uplc.parseUPLC)(purePlutusBytes, "flat");
4516
+ const decodedArgs = args.map((arg) => (0, import_plutus_data.dataFromCbor)(arg));
4517
+ let body = parsedProgram.body;
4518
+ for (const plutusData of decodedArgs) {
4519
+ const argTerm = import_uplc.UPLCConst.data(plutusData);
4520
+ body = new import_uplc.Application(body, argTerm);
4521
+ }
4522
+ const encodedProgram = new import_uplc.UPLCProgram(parsedProgram.version, body);
4523
+ const newPlutusScriptBytes = (0, import_uplc.encodeUPLC)(encodedProgram).toBuffer().buffer;
4524
+ return applyEncoding(newPlutusScriptBytes, outputEncoding);
4525
+ };
2755
4526
  var normalizePlutusScript = (plutusScript, encoding) => {
2756
4527
  const bytes = Buffer.from(plutusScript, "hex");
2757
4528
  const purePlutusBytes = getPurePlutusBytes(bytes);
@@ -2776,8 +4547,8 @@ var getPurePlutusBytes = (plutusScript) => {
2776
4547
  if (hasSupportedPlutusVersion(unwrappedScript)) {
2777
4548
  return unwrappedScript;
2778
4549
  }
2779
- const cbor = import_cbor.Cbor.parse(unwrappedScript);
2780
- if (cbor instanceof import_cbor.CborBytes) {
4550
+ const cbor = import_cbor2.Cbor.parse(unwrappedScript);
4551
+ if (cbor instanceof import_cbor2.CborBytes) {
2781
4552
  unwrappedScript = cbor.bytes;
2782
4553
  } else {
2783
4554
  break;
@@ -2792,7 +4563,7 @@ var getPurePlutusBytes = (plutusScript) => {
2792
4563
  throw new Error("Unsupported Plutus version or invalid Plutus script bytes");
2793
4564
  };
2794
4565
  var applyCborEncoding = (plutusScript) => {
2795
- return import_cbor.Cbor.encode(new import_cbor.CborBytes(plutusScript)).toBuffer();
4566
+ return import_cbor2.Cbor.encode(new import_cbor2.CborBytes(plutusScript)).toBuffer();
2796
4567
  };
2797
4568
  var applyEncoding = (plutusScript, outputEncoding) => {
2798
4569
  switch (outputEncoding) {
@@ -2806,10 +4577,56 @@ var applyEncoding = (plutusScript, outputEncoding) => {
2806
4577
  return applyCborEncoding(plutusScript);
2807
4578
  }
2808
4579
  };
4580
+ var applyParamsToScript = (rawScript, params, type = "Mesh") => {
4581
+ let plutusParams = [];
4582
+ switch (type) {
4583
+ case "JSON":
4584
+ params.forEach((param) => {
4585
+ plutusParams.push(
4586
+ fromBuilderToPlutusData({
4587
+ type: "JSON",
4588
+ content: param
4589
+ })
4590
+ );
4591
+ });
4592
+ break;
4593
+ case "CBOR":
4594
+ params.forEach((param) => {
4595
+ plutusParams.push(
4596
+ fromBuilderToPlutusData({
4597
+ type: "CBOR",
4598
+ content: param
4599
+ })
4600
+ );
4601
+ });
4602
+ break;
4603
+ case "Mesh":
4604
+ params.forEach((param) => {
4605
+ plutusParams.push(
4606
+ fromBuilderToPlutusData({
4607
+ type: "Mesh",
4608
+ content: param
4609
+ })
4610
+ );
4611
+ });
4612
+ break;
4613
+ }
4614
+ const byteParams = plutusParams.map((param) => {
4615
+ return Buffer.from(param.toCbor(), "hex");
4616
+ });
4617
+ const scriptHex = Buffer.from(
4618
+ applyArgsToPlutusScript(
4619
+ byteParams,
4620
+ Buffer.from(rawScript, "hex"),
4621
+ "DoubleCBOR"
4622
+ )
4623
+ ).toString("hex");
4624
+ return scriptHex;
4625
+ };
2809
4626
 
2810
4627
  // src/index.ts
2811
4628
  var CardanoSDKUtil = __toESM(require("@cardano-sdk/util"), 1);
2812
- var Crypto3 = __toESM(require("@cardano-sdk/crypto"), 1);
4629
+ var Crypto2 = __toESM(require("@cardano-sdk/crypto"), 1);
2813
4630
  var CardanoSDK = __toESM(require("@cardano-sdk/core"), 1);
2814
4631
  // Annotate the CommonJS export names for ESM import in node:
2815
4632
  0 && (module.exports = {
@@ -2818,6 +4635,7 @@ var CardanoSDK = __toESM(require("@cardano-sdk/core"), 1);
2818
4635
  AssetFingerprint,
2819
4636
  AssetId,
2820
4637
  AssetName,
4638
+ AuxilliaryData,
2821
4639
  BaseAddress,
2822
4640
  Bip32PrivateKey,
2823
4641
  Bip32PrivateKeyHex,
@@ -2827,6 +4645,7 @@ var CardanoSDK = __toESM(require("@cardano-sdk/core"), 1);
2827
4645
  CardanoSDKUtil,
2828
4646
  CborSet,
2829
4647
  CborWriter,
4648
+ CertIndex,
2830
4649
  Certificate,
2831
4650
  CertificateType,
2832
4651
  ConstrPlutusData,
@@ -2854,16 +4673,20 @@ var CardanoSDK = __toESM(require("@cardano-sdk/core"), 1);
2854
4673
  Hash,
2855
4674
  Hash28ByteBase16,
2856
4675
  Hash32ByteBase16,
4676
+ MetadatumList,
4677
+ MetadatumMap,
2857
4678
  NativeScript,
2858
4679
  NetworkId,
2859
4680
  PaymentAddress,
2860
4681
  PlutusData,
4682
+ PlutusDataKind,
2861
4683
  PlutusLanguageVersion,
2862
4684
  PlutusList,
2863
4685
  PlutusMap,
2864
4686
  PlutusV1Script,
2865
4687
  PlutusV2Script,
2866
4688
  PlutusV3Script,
4689
+ PointerAddress,
2867
4690
  PolicyId,
2868
4691
  PoolId,
2869
4692
  Redeemer,
@@ -2900,14 +4723,21 @@ var CardanoSDK = __toESM(require("@cardano-sdk/core"), 1);
2900
4723
  TransactionBody,
2901
4724
  TransactionId,
2902
4725
  TransactionInput,
4726
+ TransactionMetadatum,
2903
4727
  TransactionOutput,
2904
4728
  TransactionUnspentOutput,
2905
4729
  TransactionWitnessSet,
4730
+ TxIndex,
2906
4731
  Value,
2907
4732
  VkeyWitness,
2908
4733
  VrfVkBech32,
4734
+ addrBech32ToPlutusDataHex,
4735
+ addrBech32ToPlutusDataObj,
2909
4736
  addressToBech32,
4737
+ applyEncoding,
4738
+ applyParamsToScript,
2910
4739
  assetTypes,
4740
+ blake2b,
2911
4741
  buildBaseAddress,
2912
4742
  buildBip32PrivateKey,
2913
4743
  buildDRepID,
@@ -2915,8 +4745,11 @@ var CardanoSDK = __toESM(require("@cardano-sdk/core"), 1);
2915
4745
  buildKeys,
2916
4746
  buildRewardAddress,
2917
4747
  buildScriptPubkey,
4748
+ bytesToHex,
2918
4749
  checkSignature,
4750
+ computeAuxiliaryDataHash,
2919
4751
  deserializeAddress,
4752
+ deserializeBech32Address,
2920
4753
  deserializeDataHash,
2921
4754
  deserializeEd25519KeyHash,
2922
4755
  deserializeNativeScript,
@@ -2929,18 +4762,28 @@ var CardanoSDK = __toESM(require("@cardano-sdk/core"), 1);
2929
4762
  deserializeTxUnspentOutput,
2930
4763
  deserializeValue,
2931
4764
  empty,
4765
+ fromBuilderToPlutusData,
4766
+ fromJsonToPlutusData,
2932
4767
  fromNativeScript,
4768
+ fromPlutusDataToJson,
2933
4769
  fromScriptRef,
2934
4770
  fromTxUnspentOutput,
2935
4771
  fromValue,
2936
4772
  generateNonce,
2937
4773
  getCoseKeyFromPublicKey,
4774
+ getDRepIds,
2938
4775
  getPublicKeyFromCoseKey,
4776
+ hexToBech32,
4777
+ hexToBytes,
4778
+ keyHashToRewardAddress,
2939
4779
  mergeValue,
2940
4780
  negateValue,
2941
4781
  negatives,
2942
4782
  normalizePlutusScript,
4783
+ parseDatumCbor,
4784
+ parseInlineDatum,
2943
4785
  resolveDataHash,
4786
+ resolveEd25519KeyHash,
2944
4787
  resolveNativeScriptAddress,
2945
4788
  resolveNativeScriptHash,
2946
4789
  resolvePaymentKeyHash,
@@ -2949,18 +4792,29 @@ var CardanoSDK = __toESM(require("@cardano-sdk/core"), 1);
2949
4792
  resolvePoolId,
2950
4793
  resolvePrivateKey,
2951
4794
  resolveRewardAddress,
4795
+ resolveScriptHashDRepId,
2952
4796
  resolveScriptRef,
2953
4797
  resolveStakeKeyHash,
2954
4798
  resolveTxHash,
4799
+ scriptHashToBech32,
4800
+ scriptHashToRewardAddress,
4801
+ serializeAddressObj,
4802
+ serializePlutusAddressToBech32,
4803
+ serialzeAddress,
2955
4804
  signData,
2956
4805
  subValue,
2957
4806
  toAddress,
2958
4807
  toBaseAddress,
4808
+ toCardanoAddress,
4809
+ toDRep,
2959
4810
  toEnterpriseAddress,
2960
4811
  toNativeScript,
2961
4812
  toPlutusData,
2962
4813
  toRewardAddress,
2963
4814
  toScriptRef,
2964
4815
  toTxUnspentOutput,
2965
- toValue
4816
+ toValue,
4817
+ utf8ToBytes,
4818
+ utf8ToHex,
4819
+ v2ScriptToBech32
2966
4820
  });