@meshsdk/core-csl 1.9.0-beta.54 → 1.9.0-beta.56
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 +831 -25
- package/dist/index.d.cts +112 -2
- package/dist/index.d.ts +112 -2
- package/dist/index.js +799 -19
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -40,14 +40,19 @@ __export(index_exports, {
|
|
|
40
40
|
applyCborEncoding: () => applyCborEncoding,
|
|
41
41
|
applyParamsToScript: () => applyParamsToScript,
|
|
42
42
|
baseAddressToStakeAddress: () => baseAddressToStakeAddress,
|
|
43
|
+
baseCertFromObj: () => baseCertFromObj,
|
|
43
44
|
baseCertToObj: () => baseCertToObj,
|
|
44
45
|
builderDataToCbor: () => builderDataToCbor,
|
|
45
46
|
calculateTxHash: () => calculateTxHash,
|
|
46
47
|
castDataToPlutusData: () => castDataToPlutusData,
|
|
47
48
|
castRawDataToJsonString: () => castRawDataToJsonString,
|
|
49
|
+
cborToBuilderData: () => cborToBuilderData,
|
|
50
|
+
certificateFromObj: () => certificateFromObj,
|
|
48
51
|
certificateToObj: () => certificateToObj,
|
|
52
|
+
collateralTxInFromObj: () => collateralTxInFromObj,
|
|
49
53
|
collateralTxInToObj: () => collateralTxInToObj,
|
|
50
54
|
csl: () => csl,
|
|
55
|
+
dataFromObj: () => dataFromObj,
|
|
51
56
|
deserializeAddress: () => deserializeAddress,
|
|
52
57
|
deserializeBech32Address: () => deserializeBech32Address,
|
|
53
58
|
deserializeBip32PrivateKey: () => deserializeBip32PrivateKey,
|
|
@@ -71,23 +76,36 @@ __export(index_exports, {
|
|
|
71
76
|
fromLovelace: () => fromLovelace,
|
|
72
77
|
fromUTF8: () => fromUTF8,
|
|
73
78
|
getDRepIds: () => getDRepIds,
|
|
79
|
+
getRequiredInputs: () => getRequiredInputs,
|
|
74
80
|
getTransactionInputs: () => getTransactionInputs,
|
|
75
81
|
getTransactionOutputs: () => getTransactionOutputs,
|
|
76
82
|
getV2ScriptHash: () => getV2ScriptHash,
|
|
77
83
|
keyHashToRewardAddress: () => keyHashToRewardAddress,
|
|
78
84
|
meshTxBuilderBodyToObj: () => meshTxBuilderBodyToObj,
|
|
85
|
+
metadataFromObj: () => metadataFromObj,
|
|
86
|
+
mintItemFromObj: () => mintItemFromObj,
|
|
79
87
|
mintItemToObj: () => mintItemToObj,
|
|
88
|
+
mintParametersFromObj: () => mintParametersFromObj,
|
|
80
89
|
mintParametersObj: () => mintParametersObj,
|
|
90
|
+
nativeMintItemFromObj: () => nativeMintItemFromObj,
|
|
81
91
|
nativeMintItemToObj: () => nativeMintItemToObj,
|
|
92
|
+
networkFromObj: () => networkFromObj,
|
|
93
|
+
networkToObj: () => networkToObj,
|
|
94
|
+
outputFromObj: () => outputFromObj,
|
|
82
95
|
outputToObj: () => outputToObj,
|
|
83
96
|
parseDatumCbor: () => parseDatumCbor,
|
|
84
97
|
parseInlineDatum: () => parseInlineDatum,
|
|
98
|
+
plutusMintItemFromObj: () => plutusMintItemFromObj,
|
|
85
99
|
plutusMintItemToObj: () => plutusMintItemToObj,
|
|
86
100
|
poolIdBech32ToHex: () => poolIdBech32ToHex,
|
|
87
101
|
poolIdHexToBech32: () => poolIdHexToBech32,
|
|
102
|
+
poolMetadataFromObj: () => poolMetadataFromObj,
|
|
88
103
|
poolMetadataToObj: () => poolMetadataToObj,
|
|
104
|
+
poolParamsFromObj: () => poolParamsFromObj,
|
|
89
105
|
poolParamsToObj: () => poolParamsToObj,
|
|
106
|
+
redeemerFromObj: () => redeemerFromObj,
|
|
90
107
|
redeemerToObj: () => redeemerToObj,
|
|
108
|
+
relayFromObj: () => relayFromObj,
|
|
91
109
|
relayToObj: () => relayToObj,
|
|
92
110
|
resolveDataHash: () => resolveDataHash,
|
|
93
111
|
resolveEd25519KeyHash: () => resolveEd25519KeyHash,
|
|
@@ -103,14 +121,18 @@ __export(index_exports, {
|
|
|
103
121
|
rewardAddressToKeyHash: () => rewardAddressToKeyHash,
|
|
104
122
|
scriptHashToBech32: () => scriptHashToBech32,
|
|
105
123
|
scriptHashToRewardAddress: () => scriptHashToRewardAddress,
|
|
124
|
+
scriptSourceFromObj: () => scriptSourceFromObj,
|
|
106
125
|
scriptSourceToObj: () => scriptSourceToObj,
|
|
126
|
+
scriptTxInParameterFromObj: () => scriptTxInParameterFromObj,
|
|
107
127
|
scriptTxInParameterToObj: () => scriptTxInParameterToObj,
|
|
108
128
|
serializeAddressObj: () => serializeAddressObj,
|
|
109
129
|
serializePlutusAddressToBech32: () => serializePlutusAddressToBech32,
|
|
110
130
|
serializePoolId: () => serializePoolId,
|
|
111
131
|
serialzeAddress: () => serialzeAddress,
|
|
112
132
|
signTransaction: () => signTransaction,
|
|
133
|
+
simpleScriptSourceFromObj: () => simpleScriptSourceFromObj,
|
|
113
134
|
simpleScriptSourceToObj: () => simpleScriptSourceToObj,
|
|
135
|
+
simpleScriptTxInParameterFromObj: () => simpleScriptTxInParameterFromObj,
|
|
114
136
|
simpleScriptTxInParameterToObj: () => simpleScriptTxInParameterToObj,
|
|
115
137
|
skeyToPubKeyHash: () => skeyToPubKeyHash,
|
|
116
138
|
toAddress: () => toAddress,
|
|
@@ -124,10 +146,18 @@ __export(index_exports, {
|
|
|
124
146
|
toRewardAddress: () => toRewardAddress,
|
|
125
147
|
toScriptRef: () => toScriptRef,
|
|
126
148
|
toUTF8: () => toUTF8,
|
|
149
|
+
txBuilderBodyFromObj: () => txBuilderBodyFromObj,
|
|
150
|
+
txInFromObj: () => txInFromObj,
|
|
151
|
+
txInParameterFromObj: () => txInParameterFromObj,
|
|
127
152
|
txInParameterToObj: () => txInParameterToObj,
|
|
128
153
|
txInToObj: () => txInToObj,
|
|
154
|
+
txMetadataToObj: () => txMetadataToObj,
|
|
155
|
+
utxoFromObj: () => utxoFromObj,
|
|
129
156
|
utxoToObj: () => utxoToObj,
|
|
130
157
|
v2ScriptToBech32: () => v2ScriptToBech32,
|
|
158
|
+
voteFromObj: () => voteFromObj,
|
|
159
|
+
voteToObj: () => voteToObj,
|
|
160
|
+
withdrawalFromObj: () => withdrawalFromObj,
|
|
131
161
|
withdrawalToObj: () => withdrawalToObj
|
|
132
162
|
});
|
|
133
163
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -541,7 +571,7 @@ var import_whisky_js_nodejs = require("@sidan-lab/whisky-js-nodejs");
|
|
|
541
571
|
// src/wasm.ts
|
|
542
572
|
var parseWasmResult = (result) => {
|
|
543
573
|
if (result.get_status() !== "success") {
|
|
544
|
-
throw new Error(result.
|
|
574
|
+
throw new Error(result.get_error());
|
|
545
575
|
}
|
|
546
576
|
return result.get_data();
|
|
547
577
|
};
|
|
@@ -717,14 +747,68 @@ var getDRepIds = (dRepId) => {
|
|
|
717
747
|
return result;
|
|
718
748
|
};
|
|
719
749
|
|
|
750
|
+
// src/utils/transaction-parser.ts
|
|
751
|
+
var import_whisky_js_nodejs2 = require("@sidan-lab/whisky-js-nodejs");
|
|
752
|
+
var getRequiredInputs = (transactionHex) => {
|
|
753
|
+
const result = (0, import_whisky_js_nodejs2.js_get_required_inputs_to_resolve)(transactionHex);
|
|
754
|
+
if (result.get_status() !== "success") {
|
|
755
|
+
throw new Error(`Failed to get required inputs: ${result.get_error()}`);
|
|
756
|
+
}
|
|
757
|
+
const utxosStr = JSON.parse(result.get_data());
|
|
758
|
+
return utxosStr.map((utxoStr) => {
|
|
759
|
+
const parts = utxoStr.split("#");
|
|
760
|
+
if (parts.length !== 2) {
|
|
761
|
+
throw new Error(`Invalid UTxO format: ${utxoStr}`);
|
|
762
|
+
}
|
|
763
|
+
const [txHash, outputIndex] = parts;
|
|
764
|
+
if (!txHash || !outputIndex) {
|
|
765
|
+
throw new Error(
|
|
766
|
+
`Invalid UTxO format: ${utxoStr}. Expected format is txHash#outputIndex`
|
|
767
|
+
);
|
|
768
|
+
}
|
|
769
|
+
return {
|
|
770
|
+
txHash,
|
|
771
|
+
outputIndex: parseInt(outputIndex)
|
|
772
|
+
};
|
|
773
|
+
});
|
|
774
|
+
};
|
|
775
|
+
|
|
720
776
|
// src/core/serializer.ts
|
|
721
|
-
var
|
|
722
|
-
var
|
|
777
|
+
var import_json_bigint4 = __toESM(require("json-bigint"), 1);
|
|
778
|
+
var import_common6 = require("@meshsdk/common");
|
|
723
779
|
|
|
724
|
-
// src/
|
|
780
|
+
// src/parser/index.ts
|
|
781
|
+
var import_whisky_js_nodejs3 = require("@sidan-lab/whisky-js-nodejs");
|
|
725
782
|
var import_common3 = require("@meshsdk/common");
|
|
783
|
+
var CSLParser = class {
|
|
784
|
+
resolvedUtxos;
|
|
785
|
+
txBuilderBody = (0, import_common3.emptyTxBuilderBody)();
|
|
786
|
+
txHex = "";
|
|
787
|
+
txHash = "";
|
|
788
|
+
constructor(txHex, resolvedUtxos = []) {
|
|
789
|
+
this.txHex = txHex;
|
|
790
|
+
this.txHash = calculateTxHash(txHex);
|
|
791
|
+
this.resolvedUtxos = resolvedUtxos;
|
|
792
|
+
const jsUtxos = import_whisky_js_nodejs3.JsVecString.new();
|
|
793
|
+
for (const utxo of resolvedUtxos) {
|
|
794
|
+
jsUtxos.add(JSON.stringify(utxo));
|
|
795
|
+
}
|
|
796
|
+
const wasmResult = (0, import_whisky_js_nodejs3.js_parse_tx_body)(txHex, jsUtxos);
|
|
797
|
+
if (wasmResult.get_status() !== "success") {
|
|
798
|
+
throw new Error(`CSLParser parse error: ${wasmResult.get_error()}`);
|
|
799
|
+
}
|
|
800
|
+
const txBodyJson = wasmResult.get_data();
|
|
801
|
+
console.log("txBodyJson", txBodyJson);
|
|
802
|
+
const txBodyObj = txBuilderBodyFromObj(txBodyJson);
|
|
803
|
+
console.log("txBodyObj", txBodyObj);
|
|
804
|
+
this.txBuilderBody = txBuilderBodyFromObj(txBodyJson);
|
|
805
|
+
}
|
|
806
|
+
};
|
|
807
|
+
|
|
808
|
+
// src/core/adaptor/toObj/index.ts
|
|
809
|
+
var import_common4 = require("@meshsdk/common");
|
|
726
810
|
|
|
727
|
-
// src/core/adaptor/data.ts
|
|
811
|
+
// src/core/adaptor/toObj/data.ts
|
|
728
812
|
var builderDataToCbor = ({ type, content }) => {
|
|
729
813
|
if (type === "Mesh") {
|
|
730
814
|
return toPlutusData(content).to_hex();
|
|
@@ -744,7 +828,7 @@ var redeemerToObj = (redeemer) => {
|
|
|
744
828
|
};
|
|
745
829
|
};
|
|
746
830
|
|
|
747
|
-
// src/core/adaptor/script.ts
|
|
831
|
+
// src/core/adaptor/toObj/script.ts
|
|
748
832
|
var scriptSourceToObj = (scriptSource) => {
|
|
749
833
|
if (scriptSource.type === "Provided") {
|
|
750
834
|
return {
|
|
@@ -785,7 +869,7 @@ var simpleScriptSourceToObj = (scriptSource) => {
|
|
|
785
869
|
};
|
|
786
870
|
};
|
|
787
871
|
|
|
788
|
-
// src/core/adaptor/certificate.ts
|
|
872
|
+
// src/core/adaptor/toObj/certificate.ts
|
|
789
873
|
var certificateToObj = (certificate) => {
|
|
790
874
|
const baseCert = certificate.certType;
|
|
791
875
|
switch (certificate.type) {
|
|
@@ -969,7 +1053,7 @@ var relayToObj = (relay) => {
|
|
|
969
1053
|
}
|
|
970
1054
|
};
|
|
971
1055
|
|
|
972
|
-
// src/core/adaptor/metadata.ts
|
|
1056
|
+
// src/core/adaptor/toObj/metadata.ts
|
|
973
1057
|
var import_json_bigint2 = __toESM(require("json-bigint"), 1);
|
|
974
1058
|
var txMetadataToObj = (metadata) => {
|
|
975
1059
|
const result = [];
|
|
@@ -1004,7 +1088,7 @@ var uint8ArrayToHex = (bytes) => {
|
|
|
1004
1088
|
return Array.from(bytes).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
1005
1089
|
};
|
|
1006
1090
|
|
|
1007
|
-
// src/core/adaptor/mint.ts
|
|
1091
|
+
// src/core/adaptor/toObj/mint.ts
|
|
1008
1092
|
var mintItemToObj = (mintItem) => {
|
|
1009
1093
|
switch (mintItem.type) {
|
|
1010
1094
|
case "Plutus":
|
|
@@ -1045,7 +1129,7 @@ var mintParametersObj = (mintItem) => {
|
|
|
1045
1129
|
};
|
|
1046
1130
|
};
|
|
1047
1131
|
|
|
1048
|
-
// src/core/adaptor/network.ts
|
|
1132
|
+
// src/core/adaptor/toObj/network.ts
|
|
1049
1133
|
var networkToObj = (network) => {
|
|
1050
1134
|
if (typeof network === "string") {
|
|
1051
1135
|
return network;
|
|
@@ -1056,7 +1140,7 @@ var networkToObj = (network) => {
|
|
|
1056
1140
|
}
|
|
1057
1141
|
};
|
|
1058
1142
|
|
|
1059
|
-
// src/core/adaptor/output.ts
|
|
1143
|
+
// src/core/adaptor/toObj/output.ts
|
|
1060
1144
|
var outputToObj = (output) => {
|
|
1061
1145
|
let datum = null;
|
|
1062
1146
|
if (output.datum) {
|
|
@@ -1086,7 +1170,7 @@ var outputToObj = (output) => {
|
|
|
1086
1170
|
};
|
|
1087
1171
|
};
|
|
1088
1172
|
|
|
1089
|
-
// src/core/adaptor/txIn.ts
|
|
1173
|
+
// src/core/adaptor/toObj/txIn.ts
|
|
1090
1174
|
var txInToObj = (txIn) => {
|
|
1091
1175
|
switch (txIn.type) {
|
|
1092
1176
|
case "PubKey":
|
|
@@ -1187,7 +1271,7 @@ var simpleScriptTxInParameterToObj = (simpleScriptTxInParameter) => {
|
|
|
1187
1271
|
}
|
|
1188
1272
|
};
|
|
1189
1273
|
|
|
1190
|
-
// src/core/adaptor/vote.ts
|
|
1274
|
+
// src/core/adaptor/toObj/vote.ts
|
|
1191
1275
|
var voteToObj = (vote) => {
|
|
1192
1276
|
if (vote.type === "BasicVote") {
|
|
1193
1277
|
return {
|
|
@@ -1287,7 +1371,7 @@ var voteTypeToObj = (voteType) => {
|
|
|
1287
1371
|
};
|
|
1288
1372
|
};
|
|
1289
1373
|
|
|
1290
|
-
// src/core/adaptor/withdrawal.ts
|
|
1374
|
+
// src/core/adaptor/toObj/withdrawal.ts
|
|
1291
1375
|
var withdrawalToObj = (withdrawal) => {
|
|
1292
1376
|
if (withdrawal.type === "PubKeyWithdrawal") {
|
|
1293
1377
|
return {
|
|
@@ -1331,7 +1415,7 @@ var withdrawalToObj = (withdrawal) => {
|
|
|
1331
1415
|
}
|
|
1332
1416
|
};
|
|
1333
1417
|
|
|
1334
|
-
// src/core/adaptor/utxo.ts
|
|
1418
|
+
// src/core/adaptor/toObj/utxo.ts
|
|
1335
1419
|
var utxoToObj = ({
|
|
1336
1420
|
input: { outputIndex, txHash },
|
|
1337
1421
|
output: { address, amount, dataHash, plutusData, scriptRef, scriptHash }
|
|
@@ -1352,7 +1436,7 @@ var utxoToObj = ({
|
|
|
1352
1436
|
};
|
|
1353
1437
|
};
|
|
1354
1438
|
|
|
1355
|
-
// src/core/adaptor/index.ts
|
|
1439
|
+
// src/core/adaptor/toObj/index.ts
|
|
1356
1440
|
var meshTxBuilderBodyToObj = ({
|
|
1357
1441
|
inputs,
|
|
1358
1442
|
outputs,
|
|
@@ -1394,7 +1478,7 @@ var meshTxBuilderBodyToObj = ({
|
|
|
1394
1478
|
mints: mintsObj,
|
|
1395
1479
|
changeAddress,
|
|
1396
1480
|
metadata: txMetadataToObj(metadata),
|
|
1397
|
-
validityRange: (0,
|
|
1481
|
+
validityRange: (0, import_common4.validityRangeToObj)(validityRange),
|
|
1398
1482
|
certificates: certificates.map(certificateToObj),
|
|
1399
1483
|
signingKey,
|
|
1400
1484
|
withdrawals: withdrawals.map(withdrawalToObj),
|
|
@@ -1404,6 +1488,677 @@ var meshTxBuilderBodyToObj = ({
|
|
|
1404
1488
|
};
|
|
1405
1489
|
};
|
|
1406
1490
|
|
|
1491
|
+
// src/core/adaptor/fromObj/index.ts
|
|
1492
|
+
var import_common5 = require("@meshsdk/common");
|
|
1493
|
+
|
|
1494
|
+
// src/core/adaptor/fromObj/data.ts
|
|
1495
|
+
var cborToBuilderData = (cborHex) => {
|
|
1496
|
+
return {
|
|
1497
|
+
type: "CBOR",
|
|
1498
|
+
content: cborHex
|
|
1499
|
+
};
|
|
1500
|
+
};
|
|
1501
|
+
var redeemerFromObj = (obj) => {
|
|
1502
|
+
return {
|
|
1503
|
+
data: cborToBuilderData(obj.data),
|
|
1504
|
+
exUnits: obj.exUnits
|
|
1505
|
+
};
|
|
1506
|
+
};
|
|
1507
|
+
var dataFromObj = (obj) => {
|
|
1508
|
+
if (obj === null) {
|
|
1509
|
+
return null;
|
|
1510
|
+
}
|
|
1511
|
+
if (typeof obj === "object") {
|
|
1512
|
+
if (Array.isArray(obj)) {
|
|
1513
|
+
return obj.map((item) => dataFromObj(item));
|
|
1514
|
+
} else if ("map" in obj) {
|
|
1515
|
+
return Object.fromEntries(
|
|
1516
|
+
obj.map.map((entry) => [
|
|
1517
|
+
dataFromObj(entry.k),
|
|
1518
|
+
dataFromObj(entry.v)
|
|
1519
|
+
])
|
|
1520
|
+
);
|
|
1521
|
+
} else if ("list" in obj) {
|
|
1522
|
+
return obj.list.map((item) => dataFromObj(item));
|
|
1523
|
+
} else if ("int" in obj) {
|
|
1524
|
+
return BigInt(obj.int);
|
|
1525
|
+
} else if ("bytes" in obj) {
|
|
1526
|
+
return obj.bytes;
|
|
1527
|
+
} else if ("constructor" in obj) {
|
|
1528
|
+
return {
|
|
1529
|
+
constructor: obj.constructor,
|
|
1530
|
+
fields: obj.fields.map((field) => dataFromObj(field))
|
|
1531
|
+
};
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
return obj;
|
|
1535
|
+
};
|
|
1536
|
+
|
|
1537
|
+
// src/core/adaptor/fromObj/script.ts
|
|
1538
|
+
var scriptSourceFromObj = (obj) => {
|
|
1539
|
+
if ("providedScriptSource" in obj) {
|
|
1540
|
+
return {
|
|
1541
|
+
type: "Provided",
|
|
1542
|
+
script: {
|
|
1543
|
+
code: obj.providedScriptSource.scriptCbor,
|
|
1544
|
+
version: obj.providedScriptSource.languageVersion.toUpperCase()
|
|
1545
|
+
}
|
|
1546
|
+
};
|
|
1547
|
+
}
|
|
1548
|
+
if ("inlineScriptSource" in obj) {
|
|
1549
|
+
return {
|
|
1550
|
+
type: "Inline",
|
|
1551
|
+
txHash: obj.inlineScriptSource.refTxIn.txHash,
|
|
1552
|
+
txIndex: obj.inlineScriptSource.refTxIn.txIndex,
|
|
1553
|
+
scriptHash: obj.inlineScriptSource.scriptHash || void 0,
|
|
1554
|
+
version: obj.inlineScriptSource.languageVersion.toUpperCase(),
|
|
1555
|
+
scriptSize: obj.inlineScriptSource.scriptSize.toString()
|
|
1556
|
+
};
|
|
1557
|
+
}
|
|
1558
|
+
throw new Error(
|
|
1559
|
+
`scriptSourceFromObj: Unknown script source format: ${JSON.stringify(obj)}`
|
|
1560
|
+
);
|
|
1561
|
+
};
|
|
1562
|
+
var simpleScriptSourceFromObj = (obj) => {
|
|
1563
|
+
if ("providedSimpleScriptSource" in obj) {
|
|
1564
|
+
return {
|
|
1565
|
+
type: "Provided",
|
|
1566
|
+
scriptCode: obj.providedSimpleScriptSource.scriptCbor
|
|
1567
|
+
};
|
|
1568
|
+
}
|
|
1569
|
+
if ("inlineSimpleScriptSource" in obj) {
|
|
1570
|
+
return {
|
|
1571
|
+
type: "Inline",
|
|
1572
|
+
txHash: obj.inlineSimpleScriptSource.refTxIn.txHash,
|
|
1573
|
+
txIndex: obj.inlineSimpleScriptSource.refTxIn.txIndex,
|
|
1574
|
+
simpleScriptHash: obj.inlineSimpleScriptSource.simpleScriptHash || void 0
|
|
1575
|
+
};
|
|
1576
|
+
}
|
|
1577
|
+
throw new Error(
|
|
1578
|
+
`simpleScriptSourceFromObj: Unknown simple script source format: ${JSON.stringify(obj)}`
|
|
1579
|
+
);
|
|
1580
|
+
};
|
|
1581
|
+
|
|
1582
|
+
// src/core/adaptor/fromObj/certificate.ts
|
|
1583
|
+
var certificateFromObj = (obj) => {
|
|
1584
|
+
if ("basicCertificate" in obj) {
|
|
1585
|
+
return {
|
|
1586
|
+
type: "BasicCertificate",
|
|
1587
|
+
certType: baseCertFromObj(obj.basicCertificate)
|
|
1588
|
+
};
|
|
1589
|
+
} else if ("scriptCertificate" in obj) {
|
|
1590
|
+
const certificate = {
|
|
1591
|
+
type: "ScriptCertificate",
|
|
1592
|
+
certType: baseCertFromObj(obj.scriptCertificate.cert)
|
|
1593
|
+
};
|
|
1594
|
+
if (obj.scriptCertificate.redeemer) {
|
|
1595
|
+
certificate.redeemer = redeemerFromObj(obj.scriptCertificate.redeemer);
|
|
1596
|
+
}
|
|
1597
|
+
if (obj.scriptCertificate.scriptSource) {
|
|
1598
|
+
certificate.scriptSource = scriptSourceFromObj(
|
|
1599
|
+
obj.scriptCertificate.scriptSource
|
|
1600
|
+
);
|
|
1601
|
+
}
|
|
1602
|
+
return certificate;
|
|
1603
|
+
} else if ("simpleScriptCertificate" in obj) {
|
|
1604
|
+
const certificate = {
|
|
1605
|
+
type: "SimpleScriptCertificate",
|
|
1606
|
+
certType: baseCertFromObj(obj.simpleScriptCertificate.cert)
|
|
1607
|
+
};
|
|
1608
|
+
if (obj.simpleScriptCertificate.simpleScriptSource) {
|
|
1609
|
+
certificate.simpleScriptSource = simpleScriptSourceFromObj(
|
|
1610
|
+
obj.simpleScriptCertificate.simpleScriptSource
|
|
1611
|
+
);
|
|
1612
|
+
}
|
|
1613
|
+
return certificate;
|
|
1614
|
+
}
|
|
1615
|
+
throw new Error(
|
|
1616
|
+
`certificateFromObj: Unknown certificate type in object: ${JSON.stringify(obj)}`
|
|
1617
|
+
);
|
|
1618
|
+
};
|
|
1619
|
+
var baseCertFromObj = (obj) => {
|
|
1620
|
+
if ("registerPool" in obj) {
|
|
1621
|
+
return {
|
|
1622
|
+
type: "RegisterPool",
|
|
1623
|
+
poolParams: poolParamsFromObj(obj.registerPool.poolParams)
|
|
1624
|
+
};
|
|
1625
|
+
} else if ("registerStake" in obj) {
|
|
1626
|
+
return {
|
|
1627
|
+
type: "RegisterStake",
|
|
1628
|
+
stakeKeyAddress: obj.registerStake.stakeKeyAddress
|
|
1629
|
+
};
|
|
1630
|
+
} else if ("delegateStake" in obj) {
|
|
1631
|
+
return {
|
|
1632
|
+
type: "DelegateStake",
|
|
1633
|
+
stakeKeyAddress: obj.delegateStake.stakeKeyAddress,
|
|
1634
|
+
poolId: obj.delegateStake.poolId
|
|
1635
|
+
};
|
|
1636
|
+
} else if ("deregisterStake" in obj) {
|
|
1637
|
+
return {
|
|
1638
|
+
type: "DeregisterStake",
|
|
1639
|
+
stakeKeyAddress: obj.deregisterStake.stakeKeyAddress
|
|
1640
|
+
};
|
|
1641
|
+
} else if ("retirePool" in obj) {
|
|
1642
|
+
return {
|
|
1643
|
+
type: "RetirePool",
|
|
1644
|
+
poolId: obj.retirePool.poolId,
|
|
1645
|
+
epoch: obj.retirePool.epoch
|
|
1646
|
+
};
|
|
1647
|
+
} else if ("voteDelegation" in obj) {
|
|
1648
|
+
return {
|
|
1649
|
+
type: "VoteDelegation",
|
|
1650
|
+
stakeKeyAddress: obj.voteDelegation.stakeKeyAddress,
|
|
1651
|
+
drep: obj.voteDelegation.drep
|
|
1652
|
+
};
|
|
1653
|
+
} else if ("stakeAndVoteDelegation" in obj) {
|
|
1654
|
+
return {
|
|
1655
|
+
type: "StakeAndVoteDelegation",
|
|
1656
|
+
stakeKeyAddress: obj.stakeAndVoteDelegation.stakeKeyAddress,
|
|
1657
|
+
poolKeyHash: obj.stakeAndVoteDelegation.poolKeyHash,
|
|
1658
|
+
drep: obj.stakeAndVoteDelegation.drep
|
|
1659
|
+
};
|
|
1660
|
+
} else if ("stakeRegistrationAndDelegation" in obj) {
|
|
1661
|
+
return {
|
|
1662
|
+
type: "StakeRegistrationAndDelegation",
|
|
1663
|
+
stakeKeyAddress: obj.stakeRegistrationAndDelegation.stakeKeyAddress,
|
|
1664
|
+
poolKeyHash: obj.stakeRegistrationAndDelegation.poolKeyHash,
|
|
1665
|
+
coin: obj.stakeRegistrationAndDelegation.coin
|
|
1666
|
+
};
|
|
1667
|
+
} else if ("voteRegistrationAndDelegation" in obj) {
|
|
1668
|
+
return {
|
|
1669
|
+
type: "VoteRegistrationAndDelegation",
|
|
1670
|
+
stakeKeyAddress: obj.voteRegistrationAndDelegation.stakeKeyAddress,
|
|
1671
|
+
drep: obj.voteRegistrationAndDelegation.drep,
|
|
1672
|
+
coin: obj.voteRegistrationAndDelegation.coin
|
|
1673
|
+
};
|
|
1674
|
+
} else if ("stakeVoteRegistrationAndDelegation" in obj) {
|
|
1675
|
+
return {
|
|
1676
|
+
type: "StakeVoteRegistrationAndDelegation",
|
|
1677
|
+
stakeKeyAddress: obj.stakeVoteRegistrationAndDelegation.stakeKeyAddress,
|
|
1678
|
+
poolKeyHash: obj.stakeVoteRegistrationAndDelegation.poolKeyHash,
|
|
1679
|
+
drep: obj.stakeVoteRegistrationAndDelegation.drep,
|
|
1680
|
+
coin: obj.stakeVoteRegistrationAndDelegation.coin
|
|
1681
|
+
};
|
|
1682
|
+
} else if ("committeeHotAuth" in obj) {
|
|
1683
|
+
return {
|
|
1684
|
+
type: "CommitteeHotAuth",
|
|
1685
|
+
committeeColdKeyAddress: obj.committeeHotAuth.committeeColdKeyAddress,
|
|
1686
|
+
committeeHotKeyAddress: obj.committeeHotAuth.committeeHotKeyAddress
|
|
1687
|
+
};
|
|
1688
|
+
} else if ("committeeColdResign" in obj) {
|
|
1689
|
+
return {
|
|
1690
|
+
type: "CommitteeColdResign",
|
|
1691
|
+
committeeColdKeyAddress: obj.committeeColdResign.committeeColdKeyAddress,
|
|
1692
|
+
anchor: obj.committeeColdResign.anchor || void 0
|
|
1693
|
+
};
|
|
1694
|
+
} else if ("dRepRegistration" in obj) {
|
|
1695
|
+
return {
|
|
1696
|
+
type: "DRepRegistration",
|
|
1697
|
+
drepId: obj.dRepRegistration.drepId,
|
|
1698
|
+
coin: obj.dRepRegistration.coin,
|
|
1699
|
+
anchor: obj.dRepRegistration.anchor || void 0
|
|
1700
|
+
};
|
|
1701
|
+
} else if ("dRepDeregistration" in obj) {
|
|
1702
|
+
return {
|
|
1703
|
+
type: "DRepDeregistration",
|
|
1704
|
+
drepId: obj.dRepDeregistration.drepId,
|
|
1705
|
+
coin: obj.dRepDeregistration.coin
|
|
1706
|
+
};
|
|
1707
|
+
} else if ("dRepUpdate" in obj) {
|
|
1708
|
+
return {
|
|
1709
|
+
type: "DRepUpdate",
|
|
1710
|
+
drepId: obj.dRepUpdate.drepId,
|
|
1711
|
+
anchor: obj.dRepUpdate.anchor
|
|
1712
|
+
};
|
|
1713
|
+
}
|
|
1714
|
+
throw new Error(
|
|
1715
|
+
`baseCertFromObj: Unknown certificate type in object: ${JSON.stringify(obj)}`
|
|
1716
|
+
);
|
|
1717
|
+
};
|
|
1718
|
+
var poolParamsFromObj = (obj) => {
|
|
1719
|
+
return {
|
|
1720
|
+
vrfKeyHash: obj.vrfKeyHash,
|
|
1721
|
+
operator: obj.operator,
|
|
1722
|
+
pledge: obj.pledge,
|
|
1723
|
+
cost: obj.cost,
|
|
1724
|
+
margin: obj.margin,
|
|
1725
|
+
relays: obj.relays.map((relay) => relayFromObj(relay)),
|
|
1726
|
+
owners: obj.owners,
|
|
1727
|
+
rewardAddress: obj.rewardAddress,
|
|
1728
|
+
metadata: obj.metadata ? poolMetadataFromObj(obj.metadata) : void 0
|
|
1729
|
+
};
|
|
1730
|
+
};
|
|
1731
|
+
var poolMetadataFromObj = (obj) => {
|
|
1732
|
+
return {
|
|
1733
|
+
URL: obj.url,
|
|
1734
|
+
hash: obj.metadata
|
|
1735
|
+
};
|
|
1736
|
+
};
|
|
1737
|
+
var relayFromObj = (obj) => {
|
|
1738
|
+
if ("singleHostAddr" in obj) {
|
|
1739
|
+
return {
|
|
1740
|
+
type: "SingleHostAddr",
|
|
1741
|
+
IPV4: obj.singleHostAddr.ipv4,
|
|
1742
|
+
IPV6: obj.singleHostAddr.ipv6,
|
|
1743
|
+
port: obj.singleHostAddr.port
|
|
1744
|
+
};
|
|
1745
|
+
} else if ("singleHostName" in obj) {
|
|
1746
|
+
return {
|
|
1747
|
+
type: "SingleHostName",
|
|
1748
|
+
domainName: obj.singleHostName.hostname,
|
|
1749
|
+
port: obj.singleHostName.port
|
|
1750
|
+
};
|
|
1751
|
+
} else if ("multiHostName" in obj) {
|
|
1752
|
+
return {
|
|
1753
|
+
type: "MultiHostName",
|
|
1754
|
+
domainName: obj.multiHostName.dnsName
|
|
1755
|
+
};
|
|
1756
|
+
}
|
|
1757
|
+
throw new Error(
|
|
1758
|
+
`relayFromObj: Unknown relay type in object: ${JSON.stringify(obj)}`
|
|
1759
|
+
);
|
|
1760
|
+
};
|
|
1761
|
+
|
|
1762
|
+
// src/core/adaptor/fromObj/metadata.ts
|
|
1763
|
+
var import_json_bigint3 = __toESM(require("json-bigint"), 1);
|
|
1764
|
+
var JSONBigParser = (0, import_json_bigint3.default)({
|
|
1765
|
+
storeAsString: false,
|
|
1766
|
+
useNativeBigInt: true,
|
|
1767
|
+
alwaysParseAsBig: false
|
|
1768
|
+
});
|
|
1769
|
+
var metadataFromObj = (metadataArray) => {
|
|
1770
|
+
const result = /* @__PURE__ */ new Map();
|
|
1771
|
+
metadataArray.forEach((metadata) => {
|
|
1772
|
+
const key = BigInt(metadata.tag);
|
|
1773
|
+
const value = objToMetadatum(JSONBigParser.parse(metadata.metadata));
|
|
1774
|
+
result.set(key, value);
|
|
1775
|
+
});
|
|
1776
|
+
return result;
|
|
1777
|
+
};
|
|
1778
|
+
var objToMetadatum = (obj) => {
|
|
1779
|
+
if (typeof obj === "number") {
|
|
1780
|
+
return obj;
|
|
1781
|
+
} else if (typeof obj === "string") {
|
|
1782
|
+
if (/^\d+$/.test(obj)) {
|
|
1783
|
+
return BigInt(obj);
|
|
1784
|
+
}
|
|
1785
|
+
if (/^-?\d+$/.test(obj)) {
|
|
1786
|
+
return BigInt(obj);
|
|
1787
|
+
}
|
|
1788
|
+
return obj;
|
|
1789
|
+
} else if (typeof obj === "bigint") {
|
|
1790
|
+
return obj;
|
|
1791
|
+
} else if (typeof obj === "object" && obj !== null) {
|
|
1792
|
+
if (Array.isArray(obj)) {
|
|
1793
|
+
return obj.map(objToMetadatum);
|
|
1794
|
+
} else {
|
|
1795
|
+
const result = /* @__PURE__ */ new Map();
|
|
1796
|
+
Object.entries(obj).forEach(([key, value]) => {
|
|
1797
|
+
let convertedKey = objToMetadatum(key);
|
|
1798
|
+
result.set(convertedKey, objToMetadatum(value));
|
|
1799
|
+
});
|
|
1800
|
+
return result;
|
|
1801
|
+
}
|
|
1802
|
+
} else {
|
|
1803
|
+
throw new Error("objToMetadatum: Unsupported object type");
|
|
1804
|
+
}
|
|
1805
|
+
};
|
|
1806
|
+
|
|
1807
|
+
// src/core/adaptor/fromObj/mint.ts
|
|
1808
|
+
var mintItemFromObj = (obj) => {
|
|
1809
|
+
if ("scriptMint" in obj) {
|
|
1810
|
+
return plutusMintItemFromObj(obj.scriptMint);
|
|
1811
|
+
}
|
|
1812
|
+
if ("simpleScriptMint" in obj) {
|
|
1813
|
+
return nativeMintItemFromObj(obj.simpleScriptMint);
|
|
1814
|
+
}
|
|
1815
|
+
throw new Error(
|
|
1816
|
+
`mintItemFromObj: Unknown mint item format: ${JSON.stringify(obj)}`
|
|
1817
|
+
);
|
|
1818
|
+
};
|
|
1819
|
+
var plutusMintItemFromObj = (obj) => {
|
|
1820
|
+
const mintParams = mintParametersFromObj(obj.mint);
|
|
1821
|
+
return {
|
|
1822
|
+
...mintParams,
|
|
1823
|
+
type: "Plutus",
|
|
1824
|
+
scriptSource: scriptSourceFromObj(obj.scriptSource),
|
|
1825
|
+
redeemer: obj.redeemer ? redeemerFromObj(obj.redeemer) : void 0
|
|
1826
|
+
};
|
|
1827
|
+
};
|
|
1828
|
+
var nativeMintItemFromObj = (obj) => {
|
|
1829
|
+
const mintParams = mintParametersFromObj(obj.mint);
|
|
1830
|
+
return {
|
|
1831
|
+
...mintParams,
|
|
1832
|
+
type: "Native",
|
|
1833
|
+
scriptSource: simpleScriptSourceFromObj(obj.scriptSource)
|
|
1834
|
+
};
|
|
1835
|
+
};
|
|
1836
|
+
var mintParametersFromObj = (obj) => {
|
|
1837
|
+
return {
|
|
1838
|
+
policyId: obj.policyId,
|
|
1839
|
+
assetName: obj.assetName,
|
|
1840
|
+
amount: obj.amount.toString()
|
|
1841
|
+
};
|
|
1842
|
+
};
|
|
1843
|
+
|
|
1844
|
+
// src/core/adaptor/fromObj/network.ts
|
|
1845
|
+
var networkFromObj = (obj) => {
|
|
1846
|
+
if (typeof obj === "string") {
|
|
1847
|
+
return obj;
|
|
1848
|
+
} else if (obj && typeof obj === "object" && "custom" in obj) {
|
|
1849
|
+
return obj.custom;
|
|
1850
|
+
}
|
|
1851
|
+
throw new Error(
|
|
1852
|
+
`networkFromObj: Unknown network type in object: ${JSON.stringify(obj)}`
|
|
1853
|
+
);
|
|
1854
|
+
};
|
|
1855
|
+
|
|
1856
|
+
// src/core/adaptor/fromObj/output.ts
|
|
1857
|
+
var outputFromObj = (obj) => {
|
|
1858
|
+
const output = {
|
|
1859
|
+
address: obj.address,
|
|
1860
|
+
amount: obj.amount
|
|
1861
|
+
};
|
|
1862
|
+
if (obj.datum) {
|
|
1863
|
+
if ("inline" in obj.datum) {
|
|
1864
|
+
output.datum = {
|
|
1865
|
+
type: "Inline",
|
|
1866
|
+
data: cborToBuilderData(obj.datum.inline)
|
|
1867
|
+
};
|
|
1868
|
+
} else if ("hash" in obj.datum) {
|
|
1869
|
+
output.datum = {
|
|
1870
|
+
type: "Hash",
|
|
1871
|
+
data: cborToBuilderData(obj.datum.hash)
|
|
1872
|
+
};
|
|
1873
|
+
} else if ("embedded" in obj.datum) {
|
|
1874
|
+
output.datum = {
|
|
1875
|
+
type: "Embedded",
|
|
1876
|
+
data: cborToBuilderData(obj.datum.embedded)
|
|
1877
|
+
};
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
if (obj.referenceScript) {
|
|
1881
|
+
const scriptSource = obj.referenceScript.providedScriptSource;
|
|
1882
|
+
output.referenceScript = {
|
|
1883
|
+
code: scriptSource.scriptCbor,
|
|
1884
|
+
version: scriptSource.languageVersion.toUpperCase()
|
|
1885
|
+
};
|
|
1886
|
+
}
|
|
1887
|
+
return output;
|
|
1888
|
+
};
|
|
1889
|
+
|
|
1890
|
+
// src/core/adaptor/fromObj/txIn.ts
|
|
1891
|
+
var txInFromObj = (obj) => {
|
|
1892
|
+
if ("pubKeyTxIn" in obj) {
|
|
1893
|
+
return {
|
|
1894
|
+
type: "PubKey",
|
|
1895
|
+
txIn: txInParameterFromObj(obj.pubKeyTxIn.txIn)
|
|
1896
|
+
};
|
|
1897
|
+
}
|
|
1898
|
+
if ("scriptTxIn" in obj) {
|
|
1899
|
+
return {
|
|
1900
|
+
type: "Script",
|
|
1901
|
+
txIn: txInParameterFromObj(obj.scriptTxIn.txIn),
|
|
1902
|
+
scriptTxIn: scriptTxInParameterFromObj(obj.scriptTxIn.scriptTxIn)
|
|
1903
|
+
};
|
|
1904
|
+
}
|
|
1905
|
+
if ("simpleScriptTxIn" in obj) {
|
|
1906
|
+
return {
|
|
1907
|
+
type: "SimpleScript",
|
|
1908
|
+
txIn: txInParameterFromObj(obj.simpleScriptTxIn.txIn),
|
|
1909
|
+
simpleScriptTxIn: simpleScriptTxInParameterFromObj(
|
|
1910
|
+
obj.simpleScriptTxIn.simpleScriptTxIn
|
|
1911
|
+
)
|
|
1912
|
+
};
|
|
1913
|
+
}
|
|
1914
|
+
throw new Error("Invalid transaction input object format");
|
|
1915
|
+
};
|
|
1916
|
+
var txInParameterFromObj = (obj) => {
|
|
1917
|
+
return {
|
|
1918
|
+
txHash: obj.txHash,
|
|
1919
|
+
txIndex: obj.txIndex,
|
|
1920
|
+
amount: obj.amount ?? void 0,
|
|
1921
|
+
address: obj.address ?? void 0
|
|
1922
|
+
};
|
|
1923
|
+
};
|
|
1924
|
+
var scriptTxInParameterFromObj = (obj) => {
|
|
1925
|
+
const result = {};
|
|
1926
|
+
if (obj.scriptSource) {
|
|
1927
|
+
result.scriptSource = scriptSourceFromObj(obj.scriptSource);
|
|
1928
|
+
}
|
|
1929
|
+
if (obj.datumSource) {
|
|
1930
|
+
if ("providedDatumSource" in obj.datumSource) {
|
|
1931
|
+
result.datumSource = {
|
|
1932
|
+
type: "Provided",
|
|
1933
|
+
data: cborToBuilderData(obj.datumSource.providedDatumSource.data)
|
|
1934
|
+
};
|
|
1935
|
+
} else if ("inlineDatumSource" in obj.datumSource) {
|
|
1936
|
+
result.datumSource = {
|
|
1937
|
+
type: "Inline",
|
|
1938
|
+
txHash: obj.datumSource.inlineDatumSource.txHash,
|
|
1939
|
+
txIndex: obj.datumSource.inlineDatumSource.txIndex
|
|
1940
|
+
};
|
|
1941
|
+
}
|
|
1942
|
+
}
|
|
1943
|
+
if (obj.redeemer) {
|
|
1944
|
+
result.redeemer = redeemerFromObj(obj.redeemer);
|
|
1945
|
+
}
|
|
1946
|
+
return result;
|
|
1947
|
+
};
|
|
1948
|
+
var simpleScriptTxInParameterFromObj = (obj) => {
|
|
1949
|
+
const result = {};
|
|
1950
|
+
if ("inlineSimpleScriptSource" in obj) {
|
|
1951
|
+
result.scriptSource = {
|
|
1952
|
+
type: "Inline",
|
|
1953
|
+
txHash: obj.inlineSimpleScriptSource.refTxIn.txHash,
|
|
1954
|
+
txIndex: obj.inlineSimpleScriptSource.refTxIn.txIndex,
|
|
1955
|
+
simpleScriptHash: obj.inlineSimpleScriptSource.simpleScriptHash,
|
|
1956
|
+
scriptSize: obj.inlineSimpleScriptSource.scriptSize.toString()
|
|
1957
|
+
};
|
|
1958
|
+
} else if ("providedSimpleScriptSource" in obj) {
|
|
1959
|
+
result.scriptSource = {
|
|
1960
|
+
type: "Provided",
|
|
1961
|
+
scriptCode: obj.providedSimpleScriptSource.scriptCbor
|
|
1962
|
+
};
|
|
1963
|
+
}
|
|
1964
|
+
return result;
|
|
1965
|
+
};
|
|
1966
|
+
var collateralTxInFromObj = (obj) => {
|
|
1967
|
+
return {
|
|
1968
|
+
type: "PubKey",
|
|
1969
|
+
txIn: txInParameterFromObj(obj.txIn)
|
|
1970
|
+
};
|
|
1971
|
+
};
|
|
1972
|
+
|
|
1973
|
+
// src/core/adaptor/fromObj/vote.ts
|
|
1974
|
+
var voteFromObj = (obj) => {
|
|
1975
|
+
if ("basicVote" in obj) {
|
|
1976
|
+
return {
|
|
1977
|
+
type: "BasicVote",
|
|
1978
|
+
vote: voteTypeFromObj(obj.basicVote)
|
|
1979
|
+
};
|
|
1980
|
+
} else if ("scriptVote" in obj) {
|
|
1981
|
+
return {
|
|
1982
|
+
type: "ScriptVote",
|
|
1983
|
+
vote: voteTypeFromObj(obj.scriptVote.vote),
|
|
1984
|
+
redeemer: redeemerFromObj(obj.scriptVote.redeemer),
|
|
1985
|
+
scriptSource: scriptSourceFromObj(obj.scriptVote.scriptSource)
|
|
1986
|
+
};
|
|
1987
|
+
} else if ("simpleScriptVote" in obj) {
|
|
1988
|
+
return {
|
|
1989
|
+
type: "SimpleScriptVote",
|
|
1990
|
+
vote: voteTypeFromObj(obj.simpleScriptVote.vote),
|
|
1991
|
+
simpleScriptSource: simpleScriptSourceFromObj(
|
|
1992
|
+
obj.simpleScriptVote.simpleScriptSource
|
|
1993
|
+
)
|
|
1994
|
+
};
|
|
1995
|
+
}
|
|
1996
|
+
throw new Error("Invalid vote object structure");
|
|
1997
|
+
};
|
|
1998
|
+
var voteTypeFromObj = (obj) => {
|
|
1999
|
+
const voter = voterFromObj(obj);
|
|
2000
|
+
const votingProcedure = {
|
|
2001
|
+
voteKind: voteKindFromObj(obj.votingProcedure.voteKind),
|
|
2002
|
+
anchor: obj.votingProcedure.anchor === null ? void 0 : obj.votingProcedure.anchor
|
|
2003
|
+
};
|
|
2004
|
+
return {
|
|
2005
|
+
voter,
|
|
2006
|
+
votingProcedure,
|
|
2007
|
+
govActionId: obj.govActionId
|
|
2008
|
+
};
|
|
2009
|
+
};
|
|
2010
|
+
var voterFromObj = (obj) => {
|
|
2011
|
+
if ("constitutionalCommitteeHotCred" in obj.voter) {
|
|
2012
|
+
const cred = obj.voter.constitutionalCommitteeHotCred;
|
|
2013
|
+
return {
|
|
2014
|
+
type: "ConstitutionalCommittee",
|
|
2015
|
+
hotCred: "keyHash" in cred ? { type: "KeyHash", keyHash: cred.keyHash } : { type: "ScriptHash", scriptHash: cred.scriptHash }
|
|
2016
|
+
};
|
|
2017
|
+
} else if ("dRepId" in obj.voter) {
|
|
2018
|
+
return {
|
|
2019
|
+
type: "DRep",
|
|
2020
|
+
drepId: obj.voter.dRepId
|
|
2021
|
+
};
|
|
2022
|
+
} else if ("stakingPoolKeyHash" in obj.voter) {
|
|
2023
|
+
return {
|
|
2024
|
+
type: "StakingPool",
|
|
2025
|
+
keyHash: obj.voter.stakingPoolKeyHash
|
|
2026
|
+
};
|
|
2027
|
+
}
|
|
2028
|
+
throw new Error("Invalid voter object structure");
|
|
2029
|
+
};
|
|
2030
|
+
var voteKindFromObj = (voteKind) => {
|
|
2031
|
+
switch (voteKind.toLowerCase()) {
|
|
2032
|
+
case "yes":
|
|
2033
|
+
return "Yes";
|
|
2034
|
+
case "no":
|
|
2035
|
+
return "No";
|
|
2036
|
+
case "abstain":
|
|
2037
|
+
return "Abstain";
|
|
2038
|
+
default:
|
|
2039
|
+
throw new Error("Invalid vote kind");
|
|
2040
|
+
}
|
|
2041
|
+
};
|
|
2042
|
+
|
|
2043
|
+
// src/core/adaptor/fromObj/withdrawal.ts
|
|
2044
|
+
var withdrawalFromObj = (obj) => {
|
|
2045
|
+
if ("pubKeyWithdrawal" in obj) {
|
|
2046
|
+
return {
|
|
2047
|
+
type: "PubKeyWithdrawal",
|
|
2048
|
+
address: obj.pubKeyWithdrawal.address,
|
|
2049
|
+
coin: obj.pubKeyWithdrawal.coin.toString()
|
|
2050
|
+
};
|
|
2051
|
+
} else if ("plutusScriptWithdrawal" in obj) {
|
|
2052
|
+
return {
|
|
2053
|
+
type: "ScriptWithdrawal",
|
|
2054
|
+
address: obj.plutusScriptWithdrawal.address,
|
|
2055
|
+
coin: obj.plutusScriptWithdrawal.coin.toString(),
|
|
2056
|
+
scriptSource: obj.plutusScriptWithdrawal.scriptSource ? scriptSourceFromObj(obj.plutusScriptWithdrawal.scriptSource) : void 0,
|
|
2057
|
+
redeemer: obj.plutusScriptWithdrawal.redeemer ? redeemerFromObj(obj.plutusScriptWithdrawal.redeemer) : void 0
|
|
2058
|
+
};
|
|
2059
|
+
} else if ("simpleScriptWithdrawal" in obj) {
|
|
2060
|
+
return {
|
|
2061
|
+
type: "SimpleScriptWithdrawal",
|
|
2062
|
+
address: obj.simpleScriptWithdrawal.address,
|
|
2063
|
+
coin: obj.simpleScriptWithdrawal.coin.toString(),
|
|
2064
|
+
scriptSource: obj.simpleScriptWithdrawal.scriptSource ? simpleScriptSourceFromObj(obj.simpleScriptWithdrawal.scriptSource) : void 0
|
|
2065
|
+
};
|
|
2066
|
+
}
|
|
2067
|
+
throw new Error("withdrawalFromObj: Invalid withdrawal object format");
|
|
2068
|
+
};
|
|
2069
|
+
|
|
2070
|
+
// src/core/adaptor/fromObj/utxo.ts
|
|
2071
|
+
var utxoFromObj = (obj) => {
|
|
2072
|
+
return {
|
|
2073
|
+
input: {
|
|
2074
|
+
outputIndex: obj.input.outputIndex,
|
|
2075
|
+
txHash: obj.input.txHash
|
|
2076
|
+
},
|
|
2077
|
+
output: {
|
|
2078
|
+
address: obj.output.address,
|
|
2079
|
+
amount: obj.output.amount,
|
|
2080
|
+
dataHash: obj.output.dataHash ?? void 0,
|
|
2081
|
+
plutusData: obj.output.plutusData ?? void 0,
|
|
2082
|
+
scriptRef: obj.output.scriptRef ?? void 0,
|
|
2083
|
+
scriptHash: obj.output.scriptHash ?? void 0
|
|
2084
|
+
}
|
|
2085
|
+
};
|
|
2086
|
+
};
|
|
2087
|
+
|
|
2088
|
+
// src/core/adaptor/fromObj/index.ts
|
|
2089
|
+
var txBuilderBodyFromObj = (objJson) => {
|
|
2090
|
+
const txBuilderBody = (0, import_common5.emptyTxBuilderBody)();
|
|
2091
|
+
const obj = JSON.parse(objJson);
|
|
2092
|
+
if (obj.inputs && Array.isArray(obj.inputs)) {
|
|
2093
|
+
txBuilderBody.inputs = obj.inputs.map(txInFromObj);
|
|
2094
|
+
}
|
|
2095
|
+
if (obj.outputs && Array.isArray(obj.outputs)) {
|
|
2096
|
+
txBuilderBody.outputs = obj.outputs.map(outputFromObj);
|
|
2097
|
+
}
|
|
2098
|
+
if (obj.fee) {
|
|
2099
|
+
txBuilderBody.fee = obj.fee.toString();
|
|
2100
|
+
}
|
|
2101
|
+
if (obj.mints && Array.isArray(obj.mints)) {
|
|
2102
|
+
const mintItems = obj.mints.map(mintItemFromObj);
|
|
2103
|
+
const visitedPolicyId = /* @__PURE__ */ new Set();
|
|
2104
|
+
const mintParams = {};
|
|
2105
|
+
mintItems.forEach((mintItem) => {
|
|
2106
|
+
const mintValueItem = {
|
|
2107
|
+
assetName: mintItem.assetName,
|
|
2108
|
+
amount: mintItem.amount
|
|
2109
|
+
};
|
|
2110
|
+
if (!visitedPolicyId.has(mintItem.policyId)) {
|
|
2111
|
+
const mintParam2 = {
|
|
2112
|
+
type: mintItem.type,
|
|
2113
|
+
policyId: mintItem.policyId,
|
|
2114
|
+
mintValue: [],
|
|
2115
|
+
redeemer: mintItem.redeemer,
|
|
2116
|
+
scriptSource: mintItem.scriptSource
|
|
2117
|
+
};
|
|
2118
|
+
mintParams[mintItem.policyId] = mintParam2;
|
|
2119
|
+
}
|
|
2120
|
+
const mintParam = mintParams[mintItem.policyId];
|
|
2121
|
+
mintParam.mintValue.push(mintValueItem);
|
|
2122
|
+
visitedPolicyId.add(mintItem.policyId);
|
|
2123
|
+
});
|
|
2124
|
+
txBuilderBody.mints = Object.values(mintParams);
|
|
2125
|
+
}
|
|
2126
|
+
if (obj.withdrawals && Array.isArray(obj.withdrawals)) {
|
|
2127
|
+
txBuilderBody.withdrawals = obj.withdrawals.map(withdrawalFromObj);
|
|
2128
|
+
}
|
|
2129
|
+
if (obj.certificates && Array.isArray(obj.certificates)) {
|
|
2130
|
+
txBuilderBody.certificates = obj.certificates.map(certificateFromObj);
|
|
2131
|
+
}
|
|
2132
|
+
if (obj.votes && Array.isArray(obj.votes)) {
|
|
2133
|
+
txBuilderBody.votes = obj.votes.map(voteFromObj);
|
|
2134
|
+
}
|
|
2135
|
+
if (obj.validityRange) {
|
|
2136
|
+
txBuilderBody.validityRange = (0, import_common5.validityRangeFromObj)(obj.validityRange);
|
|
2137
|
+
}
|
|
2138
|
+
if (obj.metadata) {
|
|
2139
|
+
txBuilderBody.metadata = metadataFromObj(obj.metadata);
|
|
2140
|
+
}
|
|
2141
|
+
if (obj.requiredSignatures && Array.isArray(obj.requiredSignatures)) {
|
|
2142
|
+
txBuilderBody.requiredSignatures = [...obj.requiredSignatures];
|
|
2143
|
+
}
|
|
2144
|
+
if (obj.referenceInputs && Array.isArray(obj.referenceInputs)) {
|
|
2145
|
+
txBuilderBody.referenceInputs = [...obj.referenceInputs];
|
|
2146
|
+
}
|
|
2147
|
+
if (obj.collaterals && Array.isArray(obj.collaterals)) {
|
|
2148
|
+
txBuilderBody.collaterals = obj.collaterals.map(collateralTxInFromObj);
|
|
2149
|
+
}
|
|
2150
|
+
if (obj.changeAddress) {
|
|
2151
|
+
txBuilderBody.changeAddress = obj.changeAddress;
|
|
2152
|
+
}
|
|
2153
|
+
if (obj.signingKey && Array.isArray(obj.signingKey)) {
|
|
2154
|
+
txBuilderBody.signingKey = [...obj.signingKey];
|
|
2155
|
+
}
|
|
2156
|
+
if (obj.network) {
|
|
2157
|
+
txBuilderBody.network = networkFromObj(obj.network);
|
|
2158
|
+
}
|
|
2159
|
+
return txBuilderBody;
|
|
2160
|
+
};
|
|
2161
|
+
|
|
1407
2162
|
// src/core/serializer.ts
|
|
1408
2163
|
var VKEY_PUBKEY_SIZE_BYTES = 32;
|
|
1409
2164
|
var VKEY_SIGNATURE_SIZE_BYTES = 64;
|
|
@@ -1413,13 +2168,14 @@ var CSLSerializer = class {
|
|
|
1413
2168
|
* Set to true to enable verbose logging for the txBodyJson prior going into build
|
|
1414
2169
|
*/
|
|
1415
2170
|
protocolParams;
|
|
1416
|
-
meshTxBuilderBody = (0,
|
|
2171
|
+
meshTxBuilderBody = (0, import_common6.emptyTxBuilderBody)();
|
|
2172
|
+
parserTxBody = (0, import_common6.emptyTxBuilderBody)();
|
|
1417
2173
|
constructor(protocolParams) {
|
|
1418
|
-
this.protocolParams = protocolParams ||
|
|
2174
|
+
this.protocolParams = protocolParams || import_common6.DEFAULT_PROTOCOL_PARAMETERS;
|
|
1419
2175
|
}
|
|
1420
2176
|
serializeTxBody(txBody, protocolParams) {
|
|
1421
|
-
const txBodyJson =
|
|
1422
|
-
const params =
|
|
2177
|
+
const txBodyJson = import_json_bigint4.default.stringify(meshTxBuilderBodyToObj(txBody));
|
|
2178
|
+
const params = import_json_bigint4.default.stringify(protocolParams || this.protocolParams);
|
|
1423
2179
|
const txBuildResult = csl.js_serialize_tx_body(txBodyJson, params);
|
|
1424
2180
|
if (txBuildResult.get_status() !== "success") {
|
|
1425
2181
|
throw new Error(`txBuildResult error: ${txBuildResult.get_error()}`);
|
|
@@ -1609,6 +2365,26 @@ var CSLSerializer = class {
|
|
|
1609
2365
|
serializeValue(value) {
|
|
1610
2366
|
return toCslValue(value).to_hex();
|
|
1611
2367
|
}
|
|
2368
|
+
parser = {
|
|
2369
|
+
getRequiredInputs: function(txHex) {
|
|
2370
|
+
return getRequiredInputs(txHex);
|
|
2371
|
+
},
|
|
2372
|
+
parse: (txHex, resolvedUtxos = []) => {
|
|
2373
|
+
const parser = new CSLParser(txHex, resolvedUtxos);
|
|
2374
|
+
this.parserTxBody = parser.txBuilderBody;
|
|
2375
|
+
},
|
|
2376
|
+
toTester: () => {
|
|
2377
|
+
return new import_common6.TxTester(this.parserTxBody);
|
|
2378
|
+
},
|
|
2379
|
+
getBuilderBody: () => {
|
|
2380
|
+
return this.parserTxBody;
|
|
2381
|
+
},
|
|
2382
|
+
getBuilderBodyWithoutChange: () => {
|
|
2383
|
+
const txBuilderBody = { ...this.parserTxBody };
|
|
2384
|
+
txBuilderBody.inputs = txBuilderBody.inputs.slice(0, -1);
|
|
2385
|
+
return txBuilderBody;
|
|
2386
|
+
}
|
|
2387
|
+
};
|
|
1612
2388
|
mockPubkey(numberInHex) {
|
|
1613
2389
|
return "0".repeat(VKEY_PUBKEY_SIZE_BYTES * 2 - numberInHex.length).concat(numberInHex);
|
|
1614
2390
|
}
|
|
@@ -1624,7 +2400,7 @@ var CSLSerializer = class {
|
|
|
1624
2400
|
};
|
|
1625
2401
|
|
|
1626
2402
|
// src/offline-providers/offline-evaluator.ts
|
|
1627
|
-
var
|
|
2403
|
+
var import_common7 = require("@meshsdk/common");
|
|
1628
2404
|
var OfflineEvaluator = class {
|
|
1629
2405
|
fetcher;
|
|
1630
2406
|
network;
|
|
@@ -1639,9 +2415,9 @@ var OfflineEvaluator = class {
|
|
|
1639
2415
|
this.fetcher = fetcher;
|
|
1640
2416
|
this.network = network;
|
|
1641
2417
|
this.slotConfig = slotConfig ?? {
|
|
1642
|
-
slotLength:
|
|
1643
|
-
zeroSlot:
|
|
1644
|
-
zeroTime:
|
|
2418
|
+
slotLength: import_common7.SLOT_CONFIG_NETWORK[network].slotLength,
|
|
2419
|
+
zeroSlot: import_common7.SLOT_CONFIG_NETWORK[network].zeroSlot,
|
|
2420
|
+
zeroTime: import_common7.SLOT_CONFIG_NETWORK[network].zeroTime
|
|
1645
2421
|
};
|
|
1646
2422
|
}
|
|
1647
2423
|
/**
|
|
@@ -1718,14 +2494,19 @@ var OfflineEvaluator = class {
|
|
|
1718
2494
|
applyCborEncoding,
|
|
1719
2495
|
applyParamsToScript,
|
|
1720
2496
|
baseAddressToStakeAddress,
|
|
2497
|
+
baseCertFromObj,
|
|
1721
2498
|
baseCertToObj,
|
|
1722
2499
|
builderDataToCbor,
|
|
1723
2500
|
calculateTxHash,
|
|
1724
2501
|
castDataToPlutusData,
|
|
1725
2502
|
castRawDataToJsonString,
|
|
2503
|
+
cborToBuilderData,
|
|
2504
|
+
certificateFromObj,
|
|
1726
2505
|
certificateToObj,
|
|
2506
|
+
collateralTxInFromObj,
|
|
1727
2507
|
collateralTxInToObj,
|
|
1728
2508
|
csl,
|
|
2509
|
+
dataFromObj,
|
|
1729
2510
|
deserializeAddress,
|
|
1730
2511
|
deserializeBech32Address,
|
|
1731
2512
|
deserializeBip32PrivateKey,
|
|
@@ -1749,23 +2530,36 @@ var OfflineEvaluator = class {
|
|
|
1749
2530
|
fromLovelace,
|
|
1750
2531
|
fromUTF8,
|
|
1751
2532
|
getDRepIds,
|
|
2533
|
+
getRequiredInputs,
|
|
1752
2534
|
getTransactionInputs,
|
|
1753
2535
|
getTransactionOutputs,
|
|
1754
2536
|
getV2ScriptHash,
|
|
1755
2537
|
keyHashToRewardAddress,
|
|
1756
2538
|
meshTxBuilderBodyToObj,
|
|
2539
|
+
metadataFromObj,
|
|
2540
|
+
mintItemFromObj,
|
|
1757
2541
|
mintItemToObj,
|
|
2542
|
+
mintParametersFromObj,
|
|
1758
2543
|
mintParametersObj,
|
|
2544
|
+
nativeMintItemFromObj,
|
|
1759
2545
|
nativeMintItemToObj,
|
|
2546
|
+
networkFromObj,
|
|
2547
|
+
networkToObj,
|
|
2548
|
+
outputFromObj,
|
|
1760
2549
|
outputToObj,
|
|
1761
2550
|
parseDatumCbor,
|
|
1762
2551
|
parseInlineDatum,
|
|
2552
|
+
plutusMintItemFromObj,
|
|
1763
2553
|
plutusMintItemToObj,
|
|
1764
2554
|
poolIdBech32ToHex,
|
|
1765
2555
|
poolIdHexToBech32,
|
|
2556
|
+
poolMetadataFromObj,
|
|
1766
2557
|
poolMetadataToObj,
|
|
2558
|
+
poolParamsFromObj,
|
|
1767
2559
|
poolParamsToObj,
|
|
2560
|
+
redeemerFromObj,
|
|
1768
2561
|
redeemerToObj,
|
|
2562
|
+
relayFromObj,
|
|
1769
2563
|
relayToObj,
|
|
1770
2564
|
resolveDataHash,
|
|
1771
2565
|
resolveEd25519KeyHash,
|
|
@@ -1781,14 +2575,18 @@ var OfflineEvaluator = class {
|
|
|
1781
2575
|
rewardAddressToKeyHash,
|
|
1782
2576
|
scriptHashToBech32,
|
|
1783
2577
|
scriptHashToRewardAddress,
|
|
2578
|
+
scriptSourceFromObj,
|
|
1784
2579
|
scriptSourceToObj,
|
|
2580
|
+
scriptTxInParameterFromObj,
|
|
1785
2581
|
scriptTxInParameterToObj,
|
|
1786
2582
|
serializeAddressObj,
|
|
1787
2583
|
serializePlutusAddressToBech32,
|
|
1788
2584
|
serializePoolId,
|
|
1789
2585
|
serialzeAddress,
|
|
1790
2586
|
signTransaction,
|
|
2587
|
+
simpleScriptSourceFromObj,
|
|
1791
2588
|
simpleScriptSourceToObj,
|
|
2589
|
+
simpleScriptTxInParameterFromObj,
|
|
1792
2590
|
simpleScriptTxInParameterToObj,
|
|
1793
2591
|
skeyToPubKeyHash,
|
|
1794
2592
|
toAddress,
|
|
@@ -1802,9 +2600,17 @@ var OfflineEvaluator = class {
|
|
|
1802
2600
|
toRewardAddress,
|
|
1803
2601
|
toScriptRef,
|
|
1804
2602
|
toUTF8,
|
|
2603
|
+
txBuilderBodyFromObj,
|
|
2604
|
+
txInFromObj,
|
|
2605
|
+
txInParameterFromObj,
|
|
1805
2606
|
txInParameterToObj,
|
|
1806
2607
|
txInToObj,
|
|
2608
|
+
txMetadataToObj,
|
|
2609
|
+
utxoFromObj,
|
|
1807
2610
|
utxoToObj,
|
|
1808
2611
|
v2ScriptToBech32,
|
|
2612
|
+
voteFromObj,
|
|
2613
|
+
voteToObj,
|
|
2614
|
+
withdrawalFromObj,
|
|
1809
2615
|
withdrawalToObj
|
|
1810
2616
|
});
|