@meshsdk/core-csl 1.9.0-beta.7 → 1.9.0-beta.70
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 +1044 -83
- package/dist/index.d.cts +125 -8
- package/dist/index.d.ts +125 -8
- package/dist/index.js +1013 -77
- package/package.json +7 -7
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,19 +121,24 @@ __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,
|
|
117
139
|
toBaseAddress: () => toBaseAddress,
|
|
118
140
|
toBytes: () => toBytes,
|
|
141
|
+
toCslValue: () => toCslValue,
|
|
119
142
|
toEnterpriseAddress: () => toEnterpriseAddress,
|
|
120
143
|
toLovelace: () => toLovelace,
|
|
121
144
|
toNativeScript: () => toNativeScript,
|
|
@@ -123,10 +146,18 @@ __export(index_exports, {
|
|
|
123
146
|
toRewardAddress: () => toRewardAddress,
|
|
124
147
|
toScriptRef: () => toScriptRef,
|
|
125
148
|
toUTF8: () => toUTF8,
|
|
149
|
+
txBuilderBodyFromObj: () => txBuilderBodyFromObj,
|
|
150
|
+
txInFromObj: () => txInFromObj,
|
|
151
|
+
txInParameterFromObj: () => txInParameterFromObj,
|
|
126
152
|
txInParameterToObj: () => txInParameterToObj,
|
|
127
153
|
txInToObj: () => txInToObj,
|
|
154
|
+
txMetadataToObj: () => txMetadataToObj,
|
|
155
|
+
utxoFromObj: () => utxoFromObj,
|
|
128
156
|
utxoToObj: () => utxoToObj,
|
|
129
157
|
v2ScriptToBech32: () => v2ScriptToBech32,
|
|
158
|
+
voteFromObj: () => voteFromObj,
|
|
159
|
+
voteToObj: () => voteToObj,
|
|
160
|
+
withdrawalFromObj: () => withdrawalFromObj,
|
|
130
161
|
withdrawalToObj: () => withdrawalToObj
|
|
131
162
|
});
|
|
132
163
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -135,7 +166,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
135
166
|
var import_common2 = require("@meshsdk/common");
|
|
136
167
|
|
|
137
168
|
// src/deser/csl.ts
|
|
138
|
-
var csl = __toESM(require("@sidan-lab/
|
|
169
|
+
var csl = __toESM(require("@sidan-lab/whisky-js-nodejs"), 1);
|
|
139
170
|
|
|
140
171
|
// src/deser/constants.ts
|
|
141
172
|
var LANGUAGE_VERSIONS = {
|
|
@@ -231,7 +262,7 @@ var castDataToPlutusData = ({
|
|
|
231
262
|
return csl.PlutusData.from_hex(content);
|
|
232
263
|
}
|
|
233
264
|
return csl.PlutusData.from_json(
|
|
234
|
-
content,
|
|
265
|
+
castRawDataToJsonString(content),
|
|
235
266
|
csl.PlutusDatumSchema.DetailedSchema
|
|
236
267
|
);
|
|
237
268
|
};
|
|
@@ -270,6 +301,29 @@ var toNativeScript = (script) => {
|
|
|
270
301
|
);
|
|
271
302
|
}
|
|
272
303
|
};
|
|
304
|
+
var toCslValue = (assets) => {
|
|
305
|
+
let cslValue = void 0;
|
|
306
|
+
let multiAsset = csl.MultiAsset.new();
|
|
307
|
+
for (const asset of assets) {
|
|
308
|
+
if (asset.unit === "lovelace" || asset.unit === "") {
|
|
309
|
+
cslValue = csl.Value.new(csl.BigNum.from_str(asset.quantity));
|
|
310
|
+
} else {
|
|
311
|
+
const policyId = csl.ScriptHash.from_hex(asset.unit.slice(0, 56));
|
|
312
|
+
const assetName = csl.AssetName.new(
|
|
313
|
+
Buffer.from(asset.unit.slice(56), "hex")
|
|
314
|
+
);
|
|
315
|
+
const quantity = csl.BigNum.from_str(asset.quantity);
|
|
316
|
+
multiAsset.set_asset(policyId, assetName, quantity);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (cslValue !== void 0) {
|
|
320
|
+
cslValue.set_multiasset(multiAsset);
|
|
321
|
+
} else {
|
|
322
|
+
cslValue = csl.Value.new(csl.BigNum.from_str("0"));
|
|
323
|
+
cslValue.set_multiasset(multiAsset);
|
|
324
|
+
}
|
|
325
|
+
return cslValue;
|
|
326
|
+
};
|
|
273
327
|
|
|
274
328
|
// src/deser/deserializer.ts
|
|
275
329
|
var deserializeAddress = (address) => csl.Address.from_bytes(toBytes(address));
|
|
@@ -362,8 +416,11 @@ var resolveRewardAddress = (bech32) => {
|
|
|
362
416
|
throw new Error(`An error occurred during resolveRewardAddress: ${error}.`);
|
|
363
417
|
}
|
|
364
418
|
};
|
|
365
|
-
var resolveDataHash = (
|
|
366
|
-
const plutusData =
|
|
419
|
+
var resolveDataHash = (rawData, type = "Mesh") => {
|
|
420
|
+
const plutusData = castDataToPlutusData({
|
|
421
|
+
content: rawData,
|
|
422
|
+
type
|
|
423
|
+
});
|
|
367
424
|
const dataHash = csl.hash_plutus_data(plutusData);
|
|
368
425
|
return dataHash.to_hex();
|
|
369
426
|
};
|
|
@@ -509,12 +566,12 @@ var keyHashToRewardAddress = (keyHashHex, network = 1) => {
|
|
|
509
566
|
};
|
|
510
567
|
|
|
511
568
|
// src/utils/transaction.ts
|
|
512
|
-
var
|
|
569
|
+
var import_whisky_js_nodejs = require("@sidan-lab/whisky-js-nodejs");
|
|
513
570
|
|
|
514
571
|
// src/wasm.ts
|
|
515
572
|
var parseWasmResult = (result) => {
|
|
516
573
|
if (result.get_status() !== "success") {
|
|
517
|
-
throw new Error(result.
|
|
574
|
+
throw new Error(result.get_error());
|
|
518
575
|
}
|
|
519
576
|
return result.get_data();
|
|
520
577
|
};
|
|
@@ -638,7 +695,7 @@ var getTransactionInputs = (txHex) => {
|
|
|
638
695
|
return inputs;
|
|
639
696
|
};
|
|
640
697
|
var getTransactionOutputs = (txHex) => {
|
|
641
|
-
const outputs = (0,
|
|
698
|
+
const outputs = (0, import_whisky_js_nodejs.js_get_tx_outs_utxo)(txHex).get_data();
|
|
642
699
|
const utxos = JSON.parse(outputs);
|
|
643
700
|
return utxos;
|
|
644
701
|
};
|
|
@@ -646,10 +703,10 @@ var getTransactionOutputs = (txHex) => {
|
|
|
646
703
|
// src/utils/aiken.ts
|
|
647
704
|
var applyParamsToScript = (rawScript, params, type = "Mesh") => {
|
|
648
705
|
const cslParams = csl.JsVecString.new();
|
|
649
|
-
let paramType =
|
|
706
|
+
let paramType = "cbor";
|
|
650
707
|
switch (type) {
|
|
651
708
|
case "JSON":
|
|
652
|
-
paramType =
|
|
709
|
+
paramType = "json";
|
|
653
710
|
params.forEach((param) => {
|
|
654
711
|
if (typeof param === "object") {
|
|
655
712
|
cslParams.add(JSON.stringify(param));
|
|
@@ -676,7 +733,7 @@ var applyCborEncoding = (rawScript) => {
|
|
|
676
733
|
return csl.js_apply_params_to_script(
|
|
677
734
|
rawScript,
|
|
678
735
|
csl.JsVecString.new(),
|
|
679
|
-
|
|
736
|
+
"cbor"
|
|
680
737
|
);
|
|
681
738
|
};
|
|
682
739
|
|
|
@@ -690,14 +747,68 @@ var getDRepIds = (dRepId) => {
|
|
|
690
747
|
return result;
|
|
691
748
|
};
|
|
692
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
|
+
|
|
693
776
|
// src/core/serializer.ts
|
|
694
|
-
var
|
|
695
|
-
var
|
|
777
|
+
var import_json_bigint4 = __toESM(require("json-bigint"), 1);
|
|
778
|
+
var import_common6 = require("@meshsdk/common");
|
|
696
779
|
|
|
697
|
-
// src/
|
|
780
|
+
// src/parser/index.ts
|
|
781
|
+
var import_whisky_js_nodejs3 = require("@sidan-lab/whisky-js-nodejs");
|
|
698
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");
|
|
699
810
|
|
|
700
|
-
// src/core/adaptor/data.ts
|
|
811
|
+
// src/core/adaptor/toObj/data.ts
|
|
701
812
|
var builderDataToCbor = ({ type, content }) => {
|
|
702
813
|
if (type === "Mesh") {
|
|
703
814
|
return toPlutusData(content).to_hex();
|
|
@@ -717,7 +828,7 @@ var redeemerToObj = (redeemer) => {
|
|
|
717
828
|
};
|
|
718
829
|
};
|
|
719
830
|
|
|
720
|
-
// src/core/adaptor/script.ts
|
|
831
|
+
// src/core/adaptor/toObj/script.ts
|
|
721
832
|
var scriptSourceToObj = (scriptSource) => {
|
|
722
833
|
if (scriptSource.type === "Provided") {
|
|
723
834
|
return {
|
|
@@ -758,7 +869,7 @@ var simpleScriptSourceToObj = (scriptSource) => {
|
|
|
758
869
|
};
|
|
759
870
|
};
|
|
760
871
|
|
|
761
|
-
// src/core/adaptor/certificate.ts
|
|
872
|
+
// src/core/adaptor/toObj/certificate.ts
|
|
762
873
|
var certificateToObj = (certificate) => {
|
|
763
874
|
const baseCert = certificate.certType;
|
|
764
875
|
switch (certificate.type) {
|
|
@@ -942,7 +1053,42 @@ var relayToObj = (relay) => {
|
|
|
942
1053
|
}
|
|
943
1054
|
};
|
|
944
1055
|
|
|
945
|
-
// src/core/adaptor/
|
|
1056
|
+
// src/core/adaptor/toObj/metadata.ts
|
|
1057
|
+
var import_json_bigint2 = __toESM(require("json-bigint"), 1);
|
|
1058
|
+
var txMetadataToObj = (metadata) => {
|
|
1059
|
+
const result = [];
|
|
1060
|
+
metadata.forEach((value, key) => {
|
|
1061
|
+
result.push({
|
|
1062
|
+
tag: key.toString(),
|
|
1063
|
+
metadata: import_json_bigint2.default.stringify(metadatumToObj(value))
|
|
1064
|
+
});
|
|
1065
|
+
});
|
|
1066
|
+
return result;
|
|
1067
|
+
};
|
|
1068
|
+
var metadatumToObj = (metadatum) => {
|
|
1069
|
+
if (typeof metadatum === "number" || typeof metadatum === "string") {
|
|
1070
|
+
return metadatum;
|
|
1071
|
+
} else if (typeof metadatum === "bigint") {
|
|
1072
|
+
return metadatum.toString();
|
|
1073
|
+
} else if (metadatum instanceof Uint8Array) {
|
|
1074
|
+
return uint8ArrayToHex(metadatum);
|
|
1075
|
+
} else if (metadatum instanceof Map) {
|
|
1076
|
+
const result = {};
|
|
1077
|
+
metadatum.forEach((value, key) => {
|
|
1078
|
+
result[metadatumToObj(key)] = metadatumToObj(value);
|
|
1079
|
+
});
|
|
1080
|
+
return result;
|
|
1081
|
+
} else if (Array.isArray(metadatum)) {
|
|
1082
|
+
return metadatum.map(metadatumToObj);
|
|
1083
|
+
} else {
|
|
1084
|
+
throw new Error("metadatumToObj: Unsupported Metadatum type");
|
|
1085
|
+
}
|
|
1086
|
+
};
|
|
1087
|
+
var uint8ArrayToHex = (bytes) => {
|
|
1088
|
+
return Array.from(bytes).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
1089
|
+
};
|
|
1090
|
+
|
|
1091
|
+
// src/core/adaptor/toObj/mint.ts
|
|
946
1092
|
var mintItemToObj = (mintItem) => {
|
|
947
1093
|
switch (mintItem.type) {
|
|
948
1094
|
case "Plutus":
|
|
@@ -983,7 +1129,7 @@ var mintParametersObj = (mintItem) => {
|
|
|
983
1129
|
};
|
|
984
1130
|
};
|
|
985
1131
|
|
|
986
|
-
// src/core/adaptor/network.ts
|
|
1132
|
+
// src/core/adaptor/toObj/network.ts
|
|
987
1133
|
var networkToObj = (network) => {
|
|
988
1134
|
if (typeof network === "string") {
|
|
989
1135
|
return network;
|
|
@@ -994,7 +1140,7 @@ var networkToObj = (network) => {
|
|
|
994
1140
|
}
|
|
995
1141
|
};
|
|
996
1142
|
|
|
997
|
-
// src/core/adaptor/output.ts
|
|
1143
|
+
// src/core/adaptor/toObj/output.ts
|
|
998
1144
|
var outputToObj = (output) => {
|
|
999
1145
|
let datum = null;
|
|
1000
1146
|
if (output.datum) {
|
|
@@ -1024,42 +1170,7 @@ var outputToObj = (output) => {
|
|
|
1024
1170
|
};
|
|
1025
1171
|
};
|
|
1026
1172
|
|
|
1027
|
-
// src/core/adaptor/
|
|
1028
|
-
var import_json_bigint2 = __toESM(require("json-bigint"), 1);
|
|
1029
|
-
var txMetadataToObj = (metadata) => {
|
|
1030
|
-
const result = [];
|
|
1031
|
-
metadata.forEach((value, key) => {
|
|
1032
|
-
result.push({
|
|
1033
|
-
tag: key.toString(),
|
|
1034
|
-
metadata: import_json_bigint2.default.stringify(metadatumToObj(value))
|
|
1035
|
-
});
|
|
1036
|
-
});
|
|
1037
|
-
return result;
|
|
1038
|
-
};
|
|
1039
|
-
var metadatumToObj = (metadatum) => {
|
|
1040
|
-
if (typeof metadatum === "number" || typeof metadatum === "string") {
|
|
1041
|
-
return metadatum;
|
|
1042
|
-
} else if (typeof metadatum === "bigint") {
|
|
1043
|
-
return metadatum.toString();
|
|
1044
|
-
} else if (metadatum instanceof Uint8Array) {
|
|
1045
|
-
return uint8ArrayToHex(metadatum);
|
|
1046
|
-
} else if (metadatum instanceof Map) {
|
|
1047
|
-
const result = {};
|
|
1048
|
-
metadatum.forEach((value, key) => {
|
|
1049
|
-
result[metadatumToObj(key)] = metadatumToObj(value);
|
|
1050
|
-
});
|
|
1051
|
-
return result;
|
|
1052
|
-
} else if (Array.isArray(metadatum)) {
|
|
1053
|
-
return metadatum.map(metadatumToObj);
|
|
1054
|
-
} else {
|
|
1055
|
-
throw new Error("metadatumToObj: Unsupported Metadatum type");
|
|
1056
|
-
}
|
|
1057
|
-
};
|
|
1058
|
-
var uint8ArrayToHex = (bytes) => {
|
|
1059
|
-
return Array.from(bytes).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
1060
|
-
};
|
|
1061
|
-
|
|
1062
|
-
// src/core/adaptor/txIn.ts
|
|
1173
|
+
// src/core/adaptor/toObj/txIn.ts
|
|
1063
1174
|
var txInToObj = (txIn) => {
|
|
1064
1175
|
switch (txIn.type) {
|
|
1065
1176
|
case "PubKey":
|
|
@@ -1160,7 +1271,7 @@ var simpleScriptTxInParameterToObj = (simpleScriptTxInParameter) => {
|
|
|
1160
1271
|
}
|
|
1161
1272
|
};
|
|
1162
1273
|
|
|
1163
|
-
// src/core/adaptor/vote.ts
|
|
1274
|
+
// src/core/adaptor/toObj/vote.ts
|
|
1164
1275
|
var voteToObj = (vote) => {
|
|
1165
1276
|
if (vote.type === "BasicVote") {
|
|
1166
1277
|
return {
|
|
@@ -1260,7 +1371,7 @@ var voteTypeToObj = (voteType) => {
|
|
|
1260
1371
|
};
|
|
1261
1372
|
};
|
|
1262
1373
|
|
|
1263
|
-
// src/core/adaptor/withdrawal.ts
|
|
1374
|
+
// src/core/adaptor/toObj/withdrawal.ts
|
|
1264
1375
|
var withdrawalToObj = (withdrawal) => {
|
|
1265
1376
|
if (withdrawal.type === "PubKeyWithdrawal") {
|
|
1266
1377
|
return {
|
|
@@ -1304,7 +1415,7 @@ var withdrawalToObj = (withdrawal) => {
|
|
|
1304
1415
|
}
|
|
1305
1416
|
};
|
|
1306
1417
|
|
|
1307
|
-
// src/core/adaptor/utxo.ts
|
|
1418
|
+
// src/core/adaptor/toObj/utxo.ts
|
|
1308
1419
|
var utxoToObj = ({
|
|
1309
1420
|
input: { outputIndex, txHash },
|
|
1310
1421
|
output: { address, amount, dataHash, plutusData, scriptRef, scriptHash }
|
|
@@ -1325,7 +1436,7 @@ var utxoToObj = ({
|
|
|
1325
1436
|
};
|
|
1326
1437
|
};
|
|
1327
1438
|
|
|
1328
|
-
// src/core/adaptor/index.ts
|
|
1439
|
+
// src/core/adaptor/toObj/index.ts
|
|
1329
1440
|
var meshTxBuilderBodyToObj = ({
|
|
1330
1441
|
inputs,
|
|
1331
1442
|
outputs,
|
|
@@ -1343,16 +1454,31 @@ var meshTxBuilderBodyToObj = ({
|
|
|
1343
1454
|
fee,
|
|
1344
1455
|
network
|
|
1345
1456
|
}) => {
|
|
1457
|
+
let mintsObj = [];
|
|
1458
|
+
mints.forEach((mint) => {
|
|
1459
|
+
mint.mintValue.forEach((mintValue) => {
|
|
1460
|
+
mintsObj.push(
|
|
1461
|
+
mintItemToObj({
|
|
1462
|
+
type: mint.type,
|
|
1463
|
+
policyId: mint.policyId,
|
|
1464
|
+
assetName: mintValue.assetName,
|
|
1465
|
+
amount: mintValue.amount,
|
|
1466
|
+
scriptSource: mint.scriptSource,
|
|
1467
|
+
redeemer: mint.redeemer
|
|
1468
|
+
})
|
|
1469
|
+
);
|
|
1470
|
+
});
|
|
1471
|
+
});
|
|
1346
1472
|
return {
|
|
1347
1473
|
inputs: inputs.map(txInToObj),
|
|
1348
1474
|
outputs: outputs.map(outputToObj),
|
|
1349
1475
|
collaterals: collaterals.map(collateralTxInToObj),
|
|
1350
1476
|
requiredSignatures,
|
|
1351
1477
|
referenceInputs,
|
|
1352
|
-
mints:
|
|
1478
|
+
mints: mintsObj,
|
|
1353
1479
|
changeAddress,
|
|
1354
1480
|
metadata: txMetadataToObj(metadata),
|
|
1355
|
-
validityRange: (0,
|
|
1481
|
+
validityRange: (0, import_common4.validityRangeToObj)(validityRange),
|
|
1356
1482
|
certificates: certificates.map(certificateToObj),
|
|
1357
1483
|
signingKey,
|
|
1358
1484
|
withdrawals: withdrawals.map(withdrawalToObj),
|
|
@@ -1362,29 +1488,694 @@ var meshTxBuilderBodyToObj = ({
|
|
|
1362
1488
|
};
|
|
1363
1489
|
};
|
|
1364
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
|
+
|
|
1365
2162
|
// src/core/serializer.ts
|
|
2163
|
+
var VKEY_PUBKEY_SIZE_BYTES = 32;
|
|
2164
|
+
var VKEY_SIGNATURE_SIZE_BYTES = 64;
|
|
2165
|
+
var CHAIN_CODE_SIZE_BYTES = 32;
|
|
1366
2166
|
var CSLSerializer = class {
|
|
1367
2167
|
/**
|
|
1368
2168
|
* Set to true to enable verbose logging for the txBodyJson prior going into build
|
|
1369
2169
|
*/
|
|
1370
|
-
verbose;
|
|
1371
2170
|
protocolParams;
|
|
1372
|
-
meshTxBuilderBody = (0,
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
this.
|
|
2171
|
+
meshTxBuilderBody = (0, import_common6.emptyTxBuilderBody)();
|
|
2172
|
+
parserTxBody = (0, import_common6.emptyTxBuilderBody)();
|
|
2173
|
+
constructor(protocolParams) {
|
|
2174
|
+
this.protocolParams = protocolParams || import_common6.DEFAULT_PROTOCOL_PARAMETERS;
|
|
1376
2175
|
}
|
|
1377
|
-
serializeTxBody(txBody, protocolParams
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
"Unbalanced transactions are not supported with CSL serializer"
|
|
1381
|
-
);
|
|
1382
|
-
}
|
|
1383
|
-
const txBodyJson = import_json_bigint3.default.stringify(meshTxBuilderBodyToObj(txBody));
|
|
1384
|
-
const params = import_json_bigint3.default.stringify(protocolParams || this.protocolParams);
|
|
1385
|
-
if (this.verbose) {
|
|
1386
|
-
console.log("txBodyJson", txBodyJson);
|
|
1387
|
-
}
|
|
2176
|
+
serializeTxBody(txBody, protocolParams) {
|
|
2177
|
+
const txBodyJson = import_json_bigint4.default.stringify(meshTxBuilderBodyToObj(txBody));
|
|
2178
|
+
const params = import_json_bigint4.default.stringify(protocolParams || this.protocolParams);
|
|
1388
2179
|
const txBuildResult = csl.js_serialize_tx_body(txBodyJson, params);
|
|
1389
2180
|
if (txBuildResult.get_status() !== "success") {
|
|
1390
2181
|
throw new Error(`txBuildResult error: ${txBuildResult.get_error()}`);
|
|
@@ -1457,8 +2248,8 @@ var CSLSerializer = class {
|
|
|
1457
2248
|
}
|
|
1458
2249
|
},
|
|
1459
2250
|
data: {
|
|
1460
|
-
resolveDataHash: function(
|
|
1461
|
-
return resolveDataHash(
|
|
2251
|
+
resolveDataHash: function(rawData, type = "Mesh") {
|
|
2252
|
+
return resolveDataHash(rawData, type);
|
|
1462
2253
|
}
|
|
1463
2254
|
},
|
|
1464
2255
|
script: {
|
|
@@ -1467,10 +2258,149 @@ var CSLSerializer = class {
|
|
|
1467
2258
|
}
|
|
1468
2259
|
}
|
|
1469
2260
|
};
|
|
2261
|
+
serializeOutput(output) {
|
|
2262
|
+
let cslOutputBuilder = csl.TransactionOutputBuilder.new().with_address(
|
|
2263
|
+
csl.Address.from_bech32(output.address)
|
|
2264
|
+
);
|
|
2265
|
+
if (output.datum?.type === "Hash") {
|
|
2266
|
+
cslOutputBuilder.with_data_hash(
|
|
2267
|
+
csl.hash_plutus_data(castDataToPlutusData(output.datum.data))
|
|
2268
|
+
);
|
|
2269
|
+
} else if (output.datum?.type === "Inline") {
|
|
2270
|
+
cslOutputBuilder.with_plutus_data(
|
|
2271
|
+
castDataToPlutusData(output.datum.data)
|
|
2272
|
+
);
|
|
2273
|
+
} else if (output.datum?.type === "Embedded") {
|
|
2274
|
+
throw new Error("Embedded datum not supported");
|
|
2275
|
+
}
|
|
2276
|
+
if (output.referenceScript) {
|
|
2277
|
+
switch (output.referenceScript.version) {
|
|
2278
|
+
case "V1": {
|
|
2279
|
+
cslOutputBuilder.with_script_ref(
|
|
2280
|
+
csl.ScriptRef.new_plutus_script(
|
|
2281
|
+
csl.PlutusScript.from_hex_with_version(
|
|
2282
|
+
output.referenceScript.code,
|
|
2283
|
+
csl.Language.new_plutus_v1()
|
|
2284
|
+
)
|
|
2285
|
+
)
|
|
2286
|
+
);
|
|
2287
|
+
break;
|
|
2288
|
+
}
|
|
2289
|
+
case "V2": {
|
|
2290
|
+
cslOutputBuilder.with_script_ref(
|
|
2291
|
+
csl.ScriptRef.new_plutus_script(
|
|
2292
|
+
csl.PlutusScript.from_hex_with_version(
|
|
2293
|
+
output.referenceScript.code,
|
|
2294
|
+
csl.Language.new_plutus_v2()
|
|
2295
|
+
)
|
|
2296
|
+
)
|
|
2297
|
+
);
|
|
2298
|
+
break;
|
|
2299
|
+
}
|
|
2300
|
+
case "V3": {
|
|
2301
|
+
cslOutputBuilder.with_script_ref(
|
|
2302
|
+
csl.ScriptRef.new_plutus_script(
|
|
2303
|
+
csl.PlutusScript.from_hex_with_version(
|
|
2304
|
+
output.referenceScript.code,
|
|
2305
|
+
csl.Language.new_plutus_v3()
|
|
2306
|
+
)
|
|
2307
|
+
)
|
|
2308
|
+
);
|
|
2309
|
+
break;
|
|
2310
|
+
}
|
|
2311
|
+
default: {
|
|
2312
|
+
cslOutputBuilder.with_script_ref(
|
|
2313
|
+
csl.ScriptRef.new_native_script(
|
|
2314
|
+
csl.NativeScript.from_hex(output.referenceScript.code)
|
|
2315
|
+
)
|
|
2316
|
+
);
|
|
2317
|
+
break;
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
}
|
|
2321
|
+
return cslOutputBuilder.next().with_value(toCslValue(output.amount)).build().to_hex();
|
|
2322
|
+
}
|
|
2323
|
+
serializeTxBodyWithMockSignatures(txBuilderBody, protocolParams) {
|
|
2324
|
+
const txHex = this.serializeTxBody(txBuilderBody, protocolParams);
|
|
2325
|
+
const cslTx = csl.Transaction.from_hex(txHex);
|
|
2326
|
+
const mockWitnessSet = cslTx.witness_set();
|
|
2327
|
+
const mockVkeyWitnesses = mockWitnessSet.vkeys() ?? csl.Vkeywitnesses.new();
|
|
2328
|
+
const mockBootstrapWitnesses = mockWitnessSet.bootstraps() ?? csl.BootstrapWitnesses.new();
|
|
2329
|
+
for (let i = 0; i < txBuilderBody.expectedNumberKeyWitnesses; i++) {
|
|
2330
|
+
const numberInHex = this.numberToIntegerHex(i);
|
|
2331
|
+
const mockVkey = csl.Vkey.new(
|
|
2332
|
+
csl.PublicKey.from_hex(this.mockPubkey(numberInHex))
|
|
2333
|
+
);
|
|
2334
|
+
const mockSignature = csl.Ed25519Signature.from_hex(
|
|
2335
|
+
this.mockSignature(numberInHex)
|
|
2336
|
+
);
|
|
2337
|
+
mockVkeyWitnesses.add(csl.Vkeywitness.new(mockVkey, mockSignature));
|
|
2338
|
+
}
|
|
2339
|
+
this.meshTxBuilderBody.expectedByronAddressWitnesses.forEach(
|
|
2340
|
+
(bootstrapWitness, i) => {
|
|
2341
|
+
const address = csl.ByronAddress.from_base58(bootstrapWitness);
|
|
2342
|
+
const numberInHex = this.numberToIntegerHex(i);
|
|
2343
|
+
const pubKeyHex = this.mockPubkey(numberInHex);
|
|
2344
|
+
const mockVkey = csl.Vkey.new(csl.PublicKey.from_hex(pubKeyHex));
|
|
2345
|
+
const signature = this.mockSignature(numberInHex);
|
|
2346
|
+
const chainCode = this.mockChainCode(numberInHex);
|
|
2347
|
+
mockBootstrapWitnesses.add(
|
|
2348
|
+
csl.BootstrapWitness.new(
|
|
2349
|
+
mockVkey,
|
|
2350
|
+
csl.Ed25519Signature.from_hex(signature),
|
|
2351
|
+
Buffer.from(chainCode, "hex"),
|
|
2352
|
+
address.attributes()
|
|
2353
|
+
)
|
|
2354
|
+
);
|
|
2355
|
+
}
|
|
2356
|
+
);
|
|
2357
|
+
mockWitnessSet.set_vkeys(mockVkeyWitnesses);
|
|
2358
|
+
mockWitnessSet.set_bootstraps(mockBootstrapWitnesses);
|
|
2359
|
+
return csl.Transaction.new(
|
|
2360
|
+
cslTx.body(),
|
|
2361
|
+
mockWitnessSet,
|
|
2362
|
+
cslTx.auxiliary_data()
|
|
2363
|
+
).to_hex();
|
|
2364
|
+
}
|
|
2365
|
+
serializeValue(value) {
|
|
2366
|
+
return toCslValue(value).to_hex();
|
|
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.outputs = txBuilderBody.outputs.slice(0, -1);
|
|
2385
|
+
return txBuilderBody;
|
|
2386
|
+
}
|
|
2387
|
+
};
|
|
2388
|
+
mockPubkey(numberInHex) {
|
|
2389
|
+
return "0".repeat(VKEY_PUBKEY_SIZE_BYTES * 2 - numberInHex.length).concat(numberInHex);
|
|
2390
|
+
}
|
|
2391
|
+
mockSignature(numberInHex) {
|
|
2392
|
+
return "0".repeat(VKEY_SIGNATURE_SIZE_BYTES * 2 - numberInHex.length).concat(numberInHex);
|
|
2393
|
+
}
|
|
2394
|
+
mockChainCode = (numberInHex) => {
|
|
2395
|
+
return "0".repeat(CHAIN_CODE_SIZE_BYTES * 2 - numberInHex.length).concat(numberInHex);
|
|
2396
|
+
};
|
|
2397
|
+
numberToIntegerHex = (number) => {
|
|
2398
|
+
return BigInt(number).toString(16);
|
|
2399
|
+
};
|
|
1470
2400
|
};
|
|
1471
2401
|
|
|
1472
2402
|
// src/offline-providers/offline-evaluator.ts
|
|
1473
|
-
var
|
|
2403
|
+
var import_common7 = require("@meshsdk/common");
|
|
1474
2404
|
var OfflineEvaluator = class {
|
|
1475
2405
|
fetcher;
|
|
1476
2406
|
network;
|
|
@@ -1485,9 +2415,9 @@ var OfflineEvaluator = class {
|
|
|
1485
2415
|
this.fetcher = fetcher;
|
|
1486
2416
|
this.network = network;
|
|
1487
2417
|
this.slotConfig = slotConfig ?? {
|
|
1488
|
-
slotLength:
|
|
1489
|
-
zeroSlot:
|
|
1490
|
-
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
|
|
1491
2421
|
};
|
|
1492
2422
|
}
|
|
1493
2423
|
/**
|
|
@@ -1564,14 +2494,19 @@ var OfflineEvaluator = class {
|
|
|
1564
2494
|
applyCborEncoding,
|
|
1565
2495
|
applyParamsToScript,
|
|
1566
2496
|
baseAddressToStakeAddress,
|
|
2497
|
+
baseCertFromObj,
|
|
1567
2498
|
baseCertToObj,
|
|
1568
2499
|
builderDataToCbor,
|
|
1569
2500
|
calculateTxHash,
|
|
1570
2501
|
castDataToPlutusData,
|
|
1571
2502
|
castRawDataToJsonString,
|
|
2503
|
+
cborToBuilderData,
|
|
2504
|
+
certificateFromObj,
|
|
1572
2505
|
certificateToObj,
|
|
2506
|
+
collateralTxInFromObj,
|
|
1573
2507
|
collateralTxInToObj,
|
|
1574
2508
|
csl,
|
|
2509
|
+
dataFromObj,
|
|
1575
2510
|
deserializeAddress,
|
|
1576
2511
|
deserializeBech32Address,
|
|
1577
2512
|
deserializeBip32PrivateKey,
|
|
@@ -1595,23 +2530,36 @@ var OfflineEvaluator = class {
|
|
|
1595
2530
|
fromLovelace,
|
|
1596
2531
|
fromUTF8,
|
|
1597
2532
|
getDRepIds,
|
|
2533
|
+
getRequiredInputs,
|
|
1598
2534
|
getTransactionInputs,
|
|
1599
2535
|
getTransactionOutputs,
|
|
1600
2536
|
getV2ScriptHash,
|
|
1601
2537
|
keyHashToRewardAddress,
|
|
1602
2538
|
meshTxBuilderBodyToObj,
|
|
2539
|
+
metadataFromObj,
|
|
2540
|
+
mintItemFromObj,
|
|
1603
2541
|
mintItemToObj,
|
|
2542
|
+
mintParametersFromObj,
|
|
1604
2543
|
mintParametersObj,
|
|
2544
|
+
nativeMintItemFromObj,
|
|
1605
2545
|
nativeMintItemToObj,
|
|
2546
|
+
networkFromObj,
|
|
2547
|
+
networkToObj,
|
|
2548
|
+
outputFromObj,
|
|
1606
2549
|
outputToObj,
|
|
1607
2550
|
parseDatumCbor,
|
|
1608
2551
|
parseInlineDatum,
|
|
2552
|
+
plutusMintItemFromObj,
|
|
1609
2553
|
plutusMintItemToObj,
|
|
1610
2554
|
poolIdBech32ToHex,
|
|
1611
2555
|
poolIdHexToBech32,
|
|
2556
|
+
poolMetadataFromObj,
|
|
1612
2557
|
poolMetadataToObj,
|
|
2558
|
+
poolParamsFromObj,
|
|
1613
2559
|
poolParamsToObj,
|
|
2560
|
+
redeemerFromObj,
|
|
1614
2561
|
redeemerToObj,
|
|
2562
|
+
relayFromObj,
|
|
1615
2563
|
relayToObj,
|
|
1616
2564
|
resolveDataHash,
|
|
1617
2565
|
resolveEd25519KeyHash,
|
|
@@ -1627,19 +2575,24 @@ var OfflineEvaluator = class {
|
|
|
1627
2575
|
rewardAddressToKeyHash,
|
|
1628
2576
|
scriptHashToBech32,
|
|
1629
2577
|
scriptHashToRewardAddress,
|
|
2578
|
+
scriptSourceFromObj,
|
|
1630
2579
|
scriptSourceToObj,
|
|
2580
|
+
scriptTxInParameterFromObj,
|
|
1631
2581
|
scriptTxInParameterToObj,
|
|
1632
2582
|
serializeAddressObj,
|
|
1633
2583
|
serializePlutusAddressToBech32,
|
|
1634
2584
|
serializePoolId,
|
|
1635
2585
|
serialzeAddress,
|
|
1636
2586
|
signTransaction,
|
|
2587
|
+
simpleScriptSourceFromObj,
|
|
1637
2588
|
simpleScriptSourceToObj,
|
|
2589
|
+
simpleScriptTxInParameterFromObj,
|
|
1638
2590
|
simpleScriptTxInParameterToObj,
|
|
1639
2591
|
skeyToPubKeyHash,
|
|
1640
2592
|
toAddress,
|
|
1641
2593
|
toBaseAddress,
|
|
1642
2594
|
toBytes,
|
|
2595
|
+
toCslValue,
|
|
1643
2596
|
toEnterpriseAddress,
|
|
1644
2597
|
toLovelace,
|
|
1645
2598
|
toNativeScript,
|
|
@@ -1647,9 +2600,17 @@ var OfflineEvaluator = class {
|
|
|
1647
2600
|
toRewardAddress,
|
|
1648
2601
|
toScriptRef,
|
|
1649
2602
|
toUTF8,
|
|
2603
|
+
txBuilderBodyFromObj,
|
|
2604
|
+
txInFromObj,
|
|
2605
|
+
txInParameterFromObj,
|
|
1650
2606
|
txInParameterToObj,
|
|
1651
2607
|
txInToObj,
|
|
2608
|
+
txMetadataToObj,
|
|
2609
|
+
utxoFromObj,
|
|
1652
2610
|
utxoToObj,
|
|
1653
2611
|
v2ScriptToBech32,
|
|
2612
|
+
voteFromObj,
|
|
2613
|
+
voteToObj,
|
|
2614
|
+
withdrawalFromObj,
|
|
1654
2615
|
withdrawalToObj
|
|
1655
2616
|
});
|