@meshsdk/core-csl 1.8.13 → 1.9.0-beta-38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +284 -151
- package/dist/index.d.cts +20 -12
- package/dist/index.d.ts +20 -12
- package/dist/index.js +283 -150
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
} from "@meshsdk/common";
|
|
6
6
|
|
|
7
7
|
// src/deser/csl.ts
|
|
8
|
-
import * as csl from "@sidan-lab/
|
|
8
|
+
import * as csl from "@sidan-lab/whisky-js-nodejs";
|
|
9
9
|
|
|
10
10
|
// src/deser/constants.ts
|
|
11
11
|
var LANGUAGE_VERSIONS = {
|
|
@@ -23,10 +23,10 @@ var POLICY_ID_LENGTH = 56;
|
|
|
23
23
|
|
|
24
24
|
// src/deser/converter.ts
|
|
25
25
|
import JSONbig from "json-bigint";
|
|
26
|
-
var toAddress = (
|
|
27
|
-
var toBaseAddress = (
|
|
28
|
-
var toEnterpriseAddress = (
|
|
29
|
-
var toRewardAddress = (
|
|
26
|
+
var toAddress = (bech32) => csl.Address.from_bech32(bech32);
|
|
27
|
+
var toBaseAddress = (bech32) => csl.BaseAddress.from_address(toAddress(bech32));
|
|
28
|
+
var toEnterpriseAddress = (bech32) => csl.EnterpriseAddress.from_address(toAddress(bech32));
|
|
29
|
+
var toRewardAddress = (bech32) => csl.RewardAddress.from_address(toAddress(bech32));
|
|
30
30
|
var fromBytes = (bytes) => Buffer.from(bytes).toString("hex");
|
|
31
31
|
var toBytes = (hex) => {
|
|
32
32
|
if (hex.length % 2 === 0 && /^[0-9A-F]*$/i.test(hex))
|
|
@@ -101,7 +101,7 @@ var castDataToPlutusData = ({
|
|
|
101
101
|
return csl.PlutusData.from_hex(content);
|
|
102
102
|
}
|
|
103
103
|
return csl.PlutusData.from_json(
|
|
104
|
-
content,
|
|
104
|
+
castRawDataToJsonString(content),
|
|
105
105
|
csl.PlutusDatumSchema.DetailedSchema
|
|
106
106
|
);
|
|
107
107
|
};
|
|
@@ -140,6 +140,29 @@ var toNativeScript = (script) => {
|
|
|
140
140
|
);
|
|
141
141
|
}
|
|
142
142
|
};
|
|
143
|
+
var toCslValue = (assets) => {
|
|
144
|
+
let cslValue = void 0;
|
|
145
|
+
let multiAsset = csl.MultiAsset.new();
|
|
146
|
+
for (const asset of assets) {
|
|
147
|
+
if (asset.unit === "lovelace" || asset.unit === "") {
|
|
148
|
+
cslValue = csl.Value.new(csl.BigNum.from_str(asset.quantity));
|
|
149
|
+
} else {
|
|
150
|
+
const policyId = csl.ScriptHash.from_hex(asset.unit.slice(0, 56));
|
|
151
|
+
const assetName = csl.AssetName.new(
|
|
152
|
+
Buffer.from(asset.unit.slice(56), "hex")
|
|
153
|
+
);
|
|
154
|
+
const quantity = csl.BigNum.from_str(asset.quantity);
|
|
155
|
+
multiAsset.set_asset(policyId, assetName, quantity);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (cslValue !== void 0) {
|
|
159
|
+
cslValue.set_multiasset(multiAsset);
|
|
160
|
+
} else {
|
|
161
|
+
cslValue = csl.Value.new(csl.BigNum.from_str("0"));
|
|
162
|
+
cslValue.set_multiasset(multiAsset);
|
|
163
|
+
}
|
|
164
|
+
return cslValue;
|
|
165
|
+
};
|
|
143
166
|
|
|
144
167
|
// src/deser/deserializer.ts
|
|
145
168
|
var deserializeAddress = (address) => csl.Address.from_bytes(toBytes(address));
|
|
@@ -167,14 +190,14 @@ var deserializeValue = (value) => csl.Value.from_bytes(toBytes(value));
|
|
|
167
190
|
import {
|
|
168
191
|
mnemonicToEntropy
|
|
169
192
|
} from "@meshsdk/common";
|
|
170
|
-
var resolveStakeKeyHash = (
|
|
193
|
+
var resolveStakeKeyHash = (bech32) => {
|
|
171
194
|
try {
|
|
172
195
|
const stakeKeyHash = [
|
|
173
|
-
toBaseAddress(
|
|
174
|
-
toRewardAddress(
|
|
196
|
+
toBaseAddress(bech32)?.stake_cred().to_keyhash(),
|
|
197
|
+
toRewardAddress(bech32)?.payment_cred().to_keyhash()
|
|
175
198
|
].find((kh) => kh !== void 0);
|
|
176
199
|
if (stakeKeyHash !== void 0) return stakeKeyHash.to_hex();
|
|
177
|
-
throw new Error(`Couldn't resolve stake key hash from address: ${
|
|
200
|
+
throw new Error(`Couldn't resolve stake key hash from address: ${bech32}`);
|
|
178
201
|
} catch (error) {
|
|
179
202
|
throw new Error(`An error occurred during resolveStakeKeyHash: ${error}.`);
|
|
180
203
|
}
|
|
@@ -214,9 +237,9 @@ var resolveNativeScriptHash = (script) => {
|
|
|
214
237
|
var resolveScriptHashDRepId = (scriptHash) => {
|
|
215
238
|
return csl.DRep.new_script_hash(
|
|
216
239
|
csl.ScriptHash.from_hex(scriptHash)
|
|
217
|
-
).to_bech32();
|
|
240
|
+
).to_bech32(true);
|
|
218
241
|
};
|
|
219
|
-
var resolveRewardAddress = (
|
|
242
|
+
var resolveRewardAddress = (bech32) => {
|
|
220
243
|
const buildRewardAddress = (networkId, stakeKeyHash) => {
|
|
221
244
|
return csl.RewardAddress.new(
|
|
222
245
|
networkId,
|
|
@@ -224,18 +247,21 @@ var resolveRewardAddress = (bech322) => {
|
|
|
224
247
|
);
|
|
225
248
|
};
|
|
226
249
|
try {
|
|
227
|
-
const address = toAddress(
|
|
228
|
-
const baseAddress = toBaseAddress(
|
|
250
|
+
const address = toAddress(bech32);
|
|
251
|
+
const baseAddress = toBaseAddress(bech32);
|
|
229
252
|
const stakeKeyHash = baseAddress?.stake_cred().to_keyhash();
|
|
230
253
|
if (stakeKeyHash !== void 0)
|
|
231
254
|
return buildRewardAddress(address.network_id(), stakeKeyHash).to_address().to_bech32();
|
|
232
|
-
throw new Error(`Couldn't resolve reward address from address: ${
|
|
255
|
+
throw new Error(`Couldn't resolve reward address from address: ${bech32}`);
|
|
233
256
|
} catch (error) {
|
|
234
257
|
throw new Error(`An error occurred during resolveRewardAddress: ${error}.`);
|
|
235
258
|
}
|
|
236
259
|
};
|
|
237
|
-
var resolveDataHash = (
|
|
238
|
-
const plutusData =
|
|
260
|
+
var resolveDataHash = (rawData, type = "Mesh") => {
|
|
261
|
+
const plutusData = castDataToPlutusData({
|
|
262
|
+
content: rawData,
|
|
263
|
+
type
|
|
264
|
+
});
|
|
239
265
|
const dataHash = csl.hash_plutus_data(plutusData);
|
|
240
266
|
return dataHash.to_hex();
|
|
241
267
|
};
|
|
@@ -248,8 +274,8 @@ var serializePoolId = (hash) => {
|
|
|
248
274
|
var resolveScriptRef = (script) => {
|
|
249
275
|
return toScriptRef(script).to_hex();
|
|
250
276
|
};
|
|
251
|
-
var resolveEd25519KeyHash = (
|
|
252
|
-
return csl.Ed25519KeyHash.from_bech32(
|
|
277
|
+
var resolveEd25519KeyHash = (bech32) => {
|
|
278
|
+
return csl.Ed25519KeyHash.from_bech32(bech32).to_hex();
|
|
253
279
|
};
|
|
254
280
|
|
|
255
281
|
// src/utils/scripts.ts
|
|
@@ -274,14 +300,14 @@ var serialzeAddress = (deserializedAddress, networkId = 0) => {
|
|
|
274
300
|
const addressObj = isPaymentScript ? scriptAddress(paymentHash, stakeHash, isStakeScript) : pubKeyAddress(paymentHash, stakeHash, isStakeScript);
|
|
275
301
|
return serializeAddressObj(addressObj, networkId);
|
|
276
302
|
};
|
|
277
|
-
var
|
|
278
|
-
const hexAddress = csl.Address.from_bech32(
|
|
303
|
+
var addrBech32ToPlutusDataHex = (bech32) => {
|
|
304
|
+
const hexAddress = csl.Address.from_bech32(bech32).to_hex();
|
|
279
305
|
const cslAddress = csl.Address.from_hex(hexAddress);
|
|
280
306
|
const hex = csl.PlutusData.from_address(cslAddress).to_hex();
|
|
281
307
|
return hex;
|
|
282
308
|
};
|
|
283
|
-
var
|
|
284
|
-
const hexAddress = csl.Address.from_bech32(
|
|
309
|
+
var addrBech32ToPlutusDataObj = (bech32) => {
|
|
310
|
+
const hexAddress = csl.Address.from_bech32(bech32).to_hex();
|
|
285
311
|
const cslAddress = csl.Address.from_hex(hexAddress);
|
|
286
312
|
const json = JSON.parse(csl.PlutusData.from_address(cslAddress).to_json(1));
|
|
287
313
|
return json;
|
|
@@ -380,6 +406,9 @@ var keyHashToRewardAddress = (keyHashHex, network = 1) => {
|
|
|
380
406
|
return rewardAddress;
|
|
381
407
|
};
|
|
382
408
|
|
|
409
|
+
// src/utils/transaction.ts
|
|
410
|
+
import { js_get_tx_outs_utxo } from "@sidan-lab/whisky-js-nodejs";
|
|
411
|
+
|
|
383
412
|
// src/wasm.ts
|
|
384
413
|
var parseWasmResult = (result) => {
|
|
385
414
|
if (result.get_status() !== "success") {
|
|
@@ -407,13 +436,16 @@ var signTransaction = (txHex, signingKeys) => {
|
|
|
407
436
|
const result = csl.js_sign_transaction(txHex, cslSigningKeys);
|
|
408
437
|
return parseWasmResult(result);
|
|
409
438
|
};
|
|
410
|
-
var evaluateTransaction = (txHex, resolvedUtxos, network, slotConfig) => {
|
|
439
|
+
var evaluateTransaction = (txHex, resolvedUtxos, chainedTxs, network, slotConfig) => {
|
|
411
440
|
const additionalTxs = csl.JsVecString.new();
|
|
441
|
+
for (const tx of chainedTxs) {
|
|
442
|
+
additionalTxs.add(tx);
|
|
443
|
+
}
|
|
412
444
|
const mappedUtxos = csl.JsVecString.new();
|
|
413
445
|
for (const utxo of resolvedUtxos) {
|
|
414
446
|
mappedUtxos.add(JSON.stringify(utxo));
|
|
415
447
|
}
|
|
416
|
-
const result = csl.
|
|
448
|
+
const result = csl.js_evaluate_tx_scripts(
|
|
417
449
|
txHex,
|
|
418
450
|
mappedUtxos,
|
|
419
451
|
additionalTxs,
|
|
@@ -478,7 +510,7 @@ var getTransactionInputs = (txHex) => {
|
|
|
478
510
|
const input = cslInputs.get(i);
|
|
479
511
|
inputs.push({
|
|
480
512
|
txHash: input.transaction_id().to_hex(),
|
|
481
|
-
|
|
513
|
+
outputIndex: input.index()
|
|
482
514
|
});
|
|
483
515
|
}
|
|
484
516
|
const cslCollaterals = body.collateral();
|
|
@@ -487,7 +519,7 @@ var getTransactionInputs = (txHex) => {
|
|
|
487
519
|
const collateral = cslCollaterals.get(i);
|
|
488
520
|
inputs.push({
|
|
489
521
|
txHash: collateral.transaction_id().to_hex(),
|
|
490
|
-
|
|
522
|
+
outputIndex: collateral.index()
|
|
491
523
|
});
|
|
492
524
|
}
|
|
493
525
|
}
|
|
@@ -497,20 +529,25 @@ var getTransactionInputs = (txHex) => {
|
|
|
497
529
|
const refInput = cslRefInputs.get(i);
|
|
498
530
|
inputs.push({
|
|
499
531
|
txHash: refInput.transaction_id().to_hex(),
|
|
500
|
-
|
|
532
|
+
outputIndex: refInput.index()
|
|
501
533
|
});
|
|
502
534
|
}
|
|
503
535
|
}
|
|
504
536
|
return inputs;
|
|
505
537
|
};
|
|
538
|
+
var getTransactionOutputs = (txHex) => {
|
|
539
|
+
const outputs = js_get_tx_outs_utxo(txHex).get_data();
|
|
540
|
+
const utxos = JSON.parse(outputs);
|
|
541
|
+
return utxos;
|
|
542
|
+
};
|
|
506
543
|
|
|
507
544
|
// src/utils/aiken.ts
|
|
508
545
|
var applyParamsToScript = (rawScript, params, type = "Mesh") => {
|
|
509
546
|
const cslParams = csl.JsVecString.new();
|
|
510
|
-
let paramType =
|
|
547
|
+
let paramType = "cbor";
|
|
511
548
|
switch (type) {
|
|
512
549
|
case "JSON":
|
|
513
|
-
paramType =
|
|
550
|
+
paramType = "json";
|
|
514
551
|
params.forEach((param) => {
|
|
515
552
|
if (typeof param === "object") {
|
|
516
553
|
cslParams.add(JSON.stringify(param));
|
|
@@ -537,68 +574,17 @@ var applyCborEncoding = (rawScript) => {
|
|
|
537
574
|
return csl.js_apply_params_to_script(
|
|
538
575
|
rawScript,
|
|
539
576
|
csl.JsVecString.new(),
|
|
540
|
-
|
|
577
|
+
"cbor"
|
|
541
578
|
);
|
|
542
579
|
};
|
|
543
580
|
|
|
544
581
|
// src/utils/drep.ts
|
|
545
|
-
import base32 from "base32-encoding";
|
|
546
|
-
import { bech32 } from "bech32";
|
|
547
582
|
var getDRepIds = (dRepId) => {
|
|
583
|
+
const cslDrep = csl.DRep.from_bech32(dRepId);
|
|
548
584
|
let result = {
|
|
549
|
-
cip105:
|
|
550
|
-
cip129:
|
|
585
|
+
cip105: cslDrep.to_bech32(false),
|
|
586
|
+
cip129: cslDrep.to_bech32(true)
|
|
551
587
|
};
|
|
552
|
-
if (dRepId.length === 58) {
|
|
553
|
-
result.cip129 = dRepId;
|
|
554
|
-
const { prefix, words } = bech32.decode(dRepId);
|
|
555
|
-
if (prefix !== "drep") {
|
|
556
|
-
throw new Error("Malformed CIP129 DRepId");
|
|
557
|
-
}
|
|
558
|
-
const bytes = base32.decode(new Uint8Array(words));
|
|
559
|
-
if (bytes[0] === 34) {
|
|
560
|
-
result.cip105 = csl.DRep.new_key_hash(
|
|
561
|
-
csl.Ed25519KeyHash.from_hex(bytes.subarray(1).toString("hex"))
|
|
562
|
-
).to_bech32();
|
|
563
|
-
} else if (bytes[0] === 35) {
|
|
564
|
-
result.cip105 = csl.DRep.new_script_hash(
|
|
565
|
-
csl.ScriptHash.from_hex(bytes.subarray(1).toString("hex"))
|
|
566
|
-
).to_bech32();
|
|
567
|
-
} else {
|
|
568
|
-
throw new Error("Malformed CIP129 DRepId");
|
|
569
|
-
}
|
|
570
|
-
} else {
|
|
571
|
-
result.cip105 = dRepId;
|
|
572
|
-
try {
|
|
573
|
-
const cslDRep = csl.DRep.from_bech32(dRepId);
|
|
574
|
-
if (cslDRep.kind() === csl.DRepKind.KeyHash) {
|
|
575
|
-
let rawBytes = cslDRep.to_key_hash()?.to_bytes();
|
|
576
|
-
if (!rawBytes) {
|
|
577
|
-
throw new Error("Malformed key hash in DRepId");
|
|
578
|
-
}
|
|
579
|
-
let rawBytesWithPrefix = new Uint8Array(rawBytes.length + 1);
|
|
580
|
-
rawBytesWithPrefix.set([34]);
|
|
581
|
-
rawBytesWithPrefix.set(rawBytes, 1);
|
|
582
|
-
let base32RawBytes = base32.encode(rawBytesWithPrefix);
|
|
583
|
-
result.cip129 = bech32.encode("drep", base32RawBytes);
|
|
584
|
-
} else if (cslDRep.kind() === csl.DRepKind.ScriptHash) {
|
|
585
|
-
let rawBytes = cslDRep.to_script_hash()?.to_bytes();
|
|
586
|
-
if (!rawBytes) {
|
|
587
|
-
throw new Error("Malformed script hash in DRepId");
|
|
588
|
-
}
|
|
589
|
-
let rawBytesWithPrefix = new Uint8Array(rawBytes.length + 1);
|
|
590
|
-
rawBytesWithPrefix.set([35]);
|
|
591
|
-
rawBytesWithPrefix.set(rawBytes, 1);
|
|
592
|
-
let base32RawBytes = base32.encode(rawBytesWithPrefix);
|
|
593
|
-
result.cip129 = bech32.encode("drep", base32RawBytes);
|
|
594
|
-
} else {
|
|
595
|
-
throw new Error("Can only calculate DRepIds for script/key DReps");
|
|
596
|
-
}
|
|
597
|
-
} catch (e) {
|
|
598
|
-
console.error(e);
|
|
599
|
-
throw new Error("Malformed DRepId");
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
588
|
return result;
|
|
603
589
|
};
|
|
604
590
|
|
|
@@ -610,7 +596,9 @@ import {
|
|
|
610
596
|
} from "@meshsdk/common";
|
|
611
597
|
|
|
612
598
|
// src/core/adaptor/index.ts
|
|
613
|
-
import {
|
|
599
|
+
import {
|
|
600
|
+
validityRangeToObj
|
|
601
|
+
} from "@meshsdk/common";
|
|
614
602
|
|
|
615
603
|
// src/core/adaptor/data.ts
|
|
616
604
|
var builderDataToCbor = ({ type, content }) => {
|
|
@@ -857,6 +845,41 @@ var relayToObj = (relay) => {
|
|
|
857
845
|
}
|
|
858
846
|
};
|
|
859
847
|
|
|
848
|
+
// src/core/adaptor/metadata.ts
|
|
849
|
+
import JSONbig2 from "json-bigint";
|
|
850
|
+
var txMetadataToObj = (metadata) => {
|
|
851
|
+
const result = [];
|
|
852
|
+
metadata.forEach((value, key) => {
|
|
853
|
+
result.push({
|
|
854
|
+
tag: key.toString(),
|
|
855
|
+
metadata: JSONbig2.stringify(metadatumToObj(value))
|
|
856
|
+
});
|
|
857
|
+
});
|
|
858
|
+
return result;
|
|
859
|
+
};
|
|
860
|
+
var metadatumToObj = (metadatum) => {
|
|
861
|
+
if (typeof metadatum === "number" || typeof metadatum === "string") {
|
|
862
|
+
return metadatum;
|
|
863
|
+
} else if (typeof metadatum === "bigint") {
|
|
864
|
+
return metadatum.toString();
|
|
865
|
+
} else if (metadatum instanceof Uint8Array) {
|
|
866
|
+
return uint8ArrayToHex(metadatum);
|
|
867
|
+
} else if (metadatum instanceof Map) {
|
|
868
|
+
const result = {};
|
|
869
|
+
metadatum.forEach((value, key) => {
|
|
870
|
+
result[metadatumToObj(key)] = metadatumToObj(value);
|
|
871
|
+
});
|
|
872
|
+
return result;
|
|
873
|
+
} else if (Array.isArray(metadatum)) {
|
|
874
|
+
return metadatum.map(metadatumToObj);
|
|
875
|
+
} else {
|
|
876
|
+
throw new Error("metadatumToObj: Unsupported Metadatum type");
|
|
877
|
+
}
|
|
878
|
+
};
|
|
879
|
+
var uint8ArrayToHex = (bytes) => {
|
|
880
|
+
return Array.from(bytes).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
881
|
+
};
|
|
882
|
+
|
|
860
883
|
// src/core/adaptor/mint.ts
|
|
861
884
|
var mintItemToObj = (mintItem) => {
|
|
862
885
|
switch (mintItem.type) {
|
|
@@ -939,41 +962,6 @@ var outputToObj = (output) => {
|
|
|
939
962
|
};
|
|
940
963
|
};
|
|
941
964
|
|
|
942
|
-
// src/core/adaptor/metadata.ts
|
|
943
|
-
import JSONbig2 from "json-bigint";
|
|
944
|
-
var txMetadataToObj = (metadata) => {
|
|
945
|
-
const result = [];
|
|
946
|
-
metadata.forEach((value, key) => {
|
|
947
|
-
result.push({
|
|
948
|
-
tag: key.toString(),
|
|
949
|
-
metadata: JSONbig2.stringify(metadatumToObj(value))
|
|
950
|
-
});
|
|
951
|
-
});
|
|
952
|
-
return result;
|
|
953
|
-
};
|
|
954
|
-
var metadatumToObj = (metadatum) => {
|
|
955
|
-
if (typeof metadatum === "number" || typeof metadatum === "string") {
|
|
956
|
-
return metadatum;
|
|
957
|
-
} else if (typeof metadatum === "bigint") {
|
|
958
|
-
return metadatum.toString();
|
|
959
|
-
} else if (metadatum instanceof Uint8Array) {
|
|
960
|
-
return uint8ArrayToHex(metadatum);
|
|
961
|
-
} else if (metadatum instanceof Map) {
|
|
962
|
-
const result = {};
|
|
963
|
-
metadatum.forEach((value, key) => {
|
|
964
|
-
result[metadatumToObj(key)] = metadatumToObj(value);
|
|
965
|
-
});
|
|
966
|
-
return result;
|
|
967
|
-
} else if (Array.isArray(metadatum)) {
|
|
968
|
-
return metadatum.map(metadatumToObj);
|
|
969
|
-
} else {
|
|
970
|
-
throw new Error("metadatumToObj: Unsupported Metadatum type");
|
|
971
|
-
}
|
|
972
|
-
};
|
|
973
|
-
var uint8ArrayToHex = (bytes) => {
|
|
974
|
-
return Array.from(bytes).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
975
|
-
};
|
|
976
|
-
|
|
977
965
|
// src/core/adaptor/txIn.ts
|
|
978
966
|
var txInToObj = (txIn) => {
|
|
979
967
|
switch (txIn.type) {
|
|
@@ -1258,13 +1246,28 @@ var meshTxBuilderBodyToObj = ({
|
|
|
1258
1246
|
fee,
|
|
1259
1247
|
network
|
|
1260
1248
|
}) => {
|
|
1249
|
+
let mintsObj = [];
|
|
1250
|
+
mints.forEach((mint) => {
|
|
1251
|
+
mint.mintValue.forEach((mintValue) => {
|
|
1252
|
+
mintsObj.push(
|
|
1253
|
+
mintItemToObj({
|
|
1254
|
+
type: mint.type,
|
|
1255
|
+
policyId: mint.policyId,
|
|
1256
|
+
assetName: mintValue.assetName,
|
|
1257
|
+
amount: mintValue.amount,
|
|
1258
|
+
scriptSource: mint.scriptSource,
|
|
1259
|
+
redeemer: mint.redeemer
|
|
1260
|
+
})
|
|
1261
|
+
);
|
|
1262
|
+
});
|
|
1263
|
+
});
|
|
1261
1264
|
return {
|
|
1262
1265
|
inputs: inputs.map(txInToObj),
|
|
1263
1266
|
outputs: outputs.map(outputToObj),
|
|
1264
1267
|
collaterals: collaterals.map(collateralTxInToObj),
|
|
1265
1268
|
requiredSignatures,
|
|
1266
1269
|
referenceInputs,
|
|
1267
|
-
mints:
|
|
1270
|
+
mints: mintsObj,
|
|
1268
1271
|
changeAddress,
|
|
1269
1272
|
metadata: txMetadataToObj(metadata),
|
|
1270
1273
|
validityRange: validityRangeToObj(validityRange),
|
|
@@ -1278,23 +1281,21 @@ var meshTxBuilderBodyToObj = ({
|
|
|
1278
1281
|
};
|
|
1279
1282
|
|
|
1280
1283
|
// src/core/serializer.ts
|
|
1284
|
+
var VKEY_PUBKEY_SIZE_BYTES = 32;
|
|
1285
|
+
var VKEY_SIGNATURE_SIZE_BYTES = 64;
|
|
1286
|
+
var CHAIN_CODE_SIZE_BYTES = 32;
|
|
1281
1287
|
var CSLSerializer = class {
|
|
1282
1288
|
/**
|
|
1283
1289
|
* Set to true to enable verbose logging for the txBodyJson prior going into build
|
|
1284
1290
|
*/
|
|
1285
|
-
verbose;
|
|
1286
1291
|
protocolParams;
|
|
1287
1292
|
meshTxBuilderBody = emptyTxBuilderBody();
|
|
1288
|
-
constructor(protocolParams
|
|
1293
|
+
constructor(protocolParams) {
|
|
1289
1294
|
this.protocolParams = protocolParams || DEFAULT_PROTOCOL_PARAMETERS;
|
|
1290
|
-
this.verbose = verbose;
|
|
1291
1295
|
}
|
|
1292
1296
|
serializeTxBody(txBody, protocolParams) {
|
|
1293
1297
|
const txBodyJson = JSONbig3.stringify(meshTxBuilderBodyToObj(txBody));
|
|
1294
1298
|
const params = JSONbig3.stringify(protocolParams || this.protocolParams);
|
|
1295
|
-
if (this.verbose) {
|
|
1296
|
-
console.log("txBodyJson", txBodyJson);
|
|
1297
|
-
}
|
|
1298
1299
|
const txBuildResult = csl.js_serialize_tx_body(txBodyJson, params);
|
|
1299
1300
|
if (txBuildResult.get_status() !== "success") {
|
|
1300
1301
|
throw new Error(`txBuildResult error: ${txBuildResult.get_error()}`);
|
|
@@ -1321,8 +1322,8 @@ var CSLSerializer = class {
|
|
|
1321
1322
|
}
|
|
1322
1323
|
deserializer = {
|
|
1323
1324
|
key: {
|
|
1324
|
-
deserializeAddress: function(
|
|
1325
|
-
return deserializeBech32Address(
|
|
1325
|
+
deserializeAddress: function(bech32) {
|
|
1326
|
+
return deserializeBech32Address(bech32);
|
|
1326
1327
|
}
|
|
1327
1328
|
},
|
|
1328
1329
|
script: {
|
|
@@ -1348,17 +1349,17 @@ var CSLSerializer = class {
|
|
|
1348
1349
|
};
|
|
1349
1350
|
resolver = {
|
|
1350
1351
|
keys: {
|
|
1351
|
-
resolveStakeKeyHash: function(
|
|
1352
|
-
return rewardAddressToKeyHash(
|
|
1352
|
+
resolveStakeKeyHash: function(bech32) {
|
|
1353
|
+
return rewardAddressToKeyHash(bech32) || deserializeBech32Address(bech32).stakeCredentialHash;
|
|
1353
1354
|
},
|
|
1354
1355
|
resolvePrivateKey: function(words) {
|
|
1355
1356
|
return resolvePrivateKey(words);
|
|
1356
1357
|
},
|
|
1357
|
-
resolveRewardAddress: function(
|
|
1358
|
-
return resolveRewardAddress(
|
|
1358
|
+
resolveRewardAddress: function(bech32) {
|
|
1359
|
+
return resolveRewardAddress(bech32);
|
|
1359
1360
|
},
|
|
1360
|
-
resolveEd25519KeyHash: function(
|
|
1361
|
-
return resolveEd25519KeyHash(
|
|
1361
|
+
resolveEd25519KeyHash: function(bech32) {
|
|
1362
|
+
return resolveEd25519KeyHash(bech32);
|
|
1362
1363
|
}
|
|
1363
1364
|
},
|
|
1364
1365
|
tx: {
|
|
@@ -1367,8 +1368,8 @@ var CSLSerializer = class {
|
|
|
1367
1368
|
}
|
|
1368
1369
|
},
|
|
1369
1370
|
data: {
|
|
1370
|
-
resolveDataHash: function(
|
|
1371
|
-
return resolveDataHash(
|
|
1371
|
+
resolveDataHash: function(rawData, type = "Mesh") {
|
|
1372
|
+
return resolveDataHash(rawData, type);
|
|
1372
1373
|
}
|
|
1373
1374
|
},
|
|
1374
1375
|
script: {
|
|
@@ -1377,6 +1378,125 @@ var CSLSerializer = class {
|
|
|
1377
1378
|
}
|
|
1378
1379
|
}
|
|
1379
1380
|
};
|
|
1381
|
+
serializeOutput(output) {
|
|
1382
|
+
let cslOutputBuilder = csl.TransactionOutputBuilder.new().with_address(
|
|
1383
|
+
csl.Address.from_bech32(output.address)
|
|
1384
|
+
);
|
|
1385
|
+
if (output.datum?.type === "Hash") {
|
|
1386
|
+
cslOutputBuilder.with_data_hash(
|
|
1387
|
+
csl.hash_plutus_data(castDataToPlutusData(output.datum.data))
|
|
1388
|
+
);
|
|
1389
|
+
} else if (output.datum?.type === "Inline") {
|
|
1390
|
+
cslOutputBuilder.with_plutus_data(
|
|
1391
|
+
castDataToPlutusData(output.datum.data)
|
|
1392
|
+
);
|
|
1393
|
+
} else if (output.datum?.type === "Embedded") {
|
|
1394
|
+
throw new Error("Embedded datum not supported");
|
|
1395
|
+
}
|
|
1396
|
+
if (output.referenceScript) {
|
|
1397
|
+
switch (output.referenceScript.version) {
|
|
1398
|
+
case "V1": {
|
|
1399
|
+
cslOutputBuilder.with_script_ref(
|
|
1400
|
+
csl.ScriptRef.new_plutus_script(
|
|
1401
|
+
csl.PlutusScript.from_hex_with_version(
|
|
1402
|
+
output.referenceScript.code,
|
|
1403
|
+
csl.Language.new_plutus_v1()
|
|
1404
|
+
)
|
|
1405
|
+
)
|
|
1406
|
+
);
|
|
1407
|
+
break;
|
|
1408
|
+
}
|
|
1409
|
+
case "V2": {
|
|
1410
|
+
cslOutputBuilder.with_script_ref(
|
|
1411
|
+
csl.ScriptRef.new_plutus_script(
|
|
1412
|
+
csl.PlutusScript.from_hex_with_version(
|
|
1413
|
+
output.referenceScript.code,
|
|
1414
|
+
csl.Language.new_plutus_v2()
|
|
1415
|
+
)
|
|
1416
|
+
)
|
|
1417
|
+
);
|
|
1418
|
+
break;
|
|
1419
|
+
}
|
|
1420
|
+
case "V3": {
|
|
1421
|
+
cslOutputBuilder.with_script_ref(
|
|
1422
|
+
csl.ScriptRef.new_plutus_script(
|
|
1423
|
+
csl.PlutusScript.from_hex_with_version(
|
|
1424
|
+
output.referenceScript.code,
|
|
1425
|
+
csl.Language.new_plutus_v3()
|
|
1426
|
+
)
|
|
1427
|
+
)
|
|
1428
|
+
);
|
|
1429
|
+
break;
|
|
1430
|
+
}
|
|
1431
|
+
default: {
|
|
1432
|
+
cslOutputBuilder.with_script_ref(
|
|
1433
|
+
csl.ScriptRef.new_native_script(
|
|
1434
|
+
csl.NativeScript.from_hex(output.referenceScript.code)
|
|
1435
|
+
)
|
|
1436
|
+
);
|
|
1437
|
+
break;
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
return cslOutputBuilder.next().with_value(toCslValue(output.amount)).build().to_hex();
|
|
1442
|
+
}
|
|
1443
|
+
serializeTxBodyWithMockSignatures(txBuilderBody, protocolParams) {
|
|
1444
|
+
const txHex = this.serializeTxBody(txBuilderBody, protocolParams);
|
|
1445
|
+
const cslTx = csl.Transaction.from_hex(txHex);
|
|
1446
|
+
const mockWitnessSet = cslTx.witness_set();
|
|
1447
|
+
const mockVkeyWitnesses = mockWitnessSet.vkeys() ?? csl.Vkeywitnesses.new();
|
|
1448
|
+
const mockBootstrapWitnesses = mockWitnessSet.bootstraps() ?? csl.BootstrapWitnesses.new();
|
|
1449
|
+
for (let i = 0; i < txBuilderBody.expectedNumberKeyWitnesses; i++) {
|
|
1450
|
+
const numberInHex = this.numberToIntegerHex(i);
|
|
1451
|
+
const mockVkey = csl.Vkey.new(
|
|
1452
|
+
csl.PublicKey.from_hex(this.mockPubkey(numberInHex))
|
|
1453
|
+
);
|
|
1454
|
+
const mockSignature = csl.Ed25519Signature.from_hex(
|
|
1455
|
+
this.mockSignature(numberInHex)
|
|
1456
|
+
);
|
|
1457
|
+
mockVkeyWitnesses.add(csl.Vkeywitness.new(mockVkey, mockSignature));
|
|
1458
|
+
}
|
|
1459
|
+
this.meshTxBuilderBody.expectedByronAddressWitnesses.forEach(
|
|
1460
|
+
(bootstrapWitness, i) => {
|
|
1461
|
+
const address = csl.ByronAddress.from_base58(bootstrapWitness);
|
|
1462
|
+
const numberInHex = this.numberToIntegerHex(i);
|
|
1463
|
+
const pubKeyHex = this.mockPubkey(numberInHex);
|
|
1464
|
+
const mockVkey = csl.Vkey.new(csl.PublicKey.from_hex(pubKeyHex));
|
|
1465
|
+
const signature = this.mockSignature(numberInHex);
|
|
1466
|
+
const chainCode = this.mockChainCode(numberInHex);
|
|
1467
|
+
mockBootstrapWitnesses.add(
|
|
1468
|
+
csl.BootstrapWitness.new(
|
|
1469
|
+
mockVkey,
|
|
1470
|
+
csl.Ed25519Signature.from_hex(signature),
|
|
1471
|
+
Buffer.from(chainCode, "hex"),
|
|
1472
|
+
address.attributes()
|
|
1473
|
+
)
|
|
1474
|
+
);
|
|
1475
|
+
}
|
|
1476
|
+
);
|
|
1477
|
+
mockWitnessSet.set_vkeys(mockVkeyWitnesses);
|
|
1478
|
+
mockWitnessSet.set_bootstraps(mockBootstrapWitnesses);
|
|
1479
|
+
return csl.Transaction.new(
|
|
1480
|
+
cslTx.body(),
|
|
1481
|
+
mockWitnessSet,
|
|
1482
|
+
cslTx.auxiliary_data()
|
|
1483
|
+
).to_hex();
|
|
1484
|
+
}
|
|
1485
|
+
serializeValue(value) {
|
|
1486
|
+
return toCslValue(value).to_hex();
|
|
1487
|
+
}
|
|
1488
|
+
mockPubkey(numberInHex) {
|
|
1489
|
+
return "0".repeat(VKEY_PUBKEY_SIZE_BYTES * 2 - numberInHex.length).concat(numberInHex);
|
|
1490
|
+
}
|
|
1491
|
+
mockSignature(numberInHex) {
|
|
1492
|
+
return "0".repeat(VKEY_SIGNATURE_SIZE_BYTES * 2 - numberInHex.length).concat(numberInHex);
|
|
1493
|
+
}
|
|
1494
|
+
mockChainCode = (numberInHex) => {
|
|
1495
|
+
return "0".repeat(CHAIN_CODE_SIZE_BYTES * 2 - numberInHex.length).concat(numberInHex);
|
|
1496
|
+
};
|
|
1497
|
+
numberToIntegerHex = (number) => {
|
|
1498
|
+
return BigInt(number).toString(16);
|
|
1499
|
+
};
|
|
1380
1500
|
};
|
|
1381
1501
|
|
|
1382
1502
|
// src/offline-providers/offline-evaluator.ts
|
|
@@ -1418,36 +1538,47 @@ var OfflineEvaluator = class {
|
|
|
1418
1538
|
* - budget: Memory units and CPU steps required
|
|
1419
1539
|
* @throws Error if any required UTXOs cannot be resolved or if script evaluation fails
|
|
1420
1540
|
*/
|
|
1421
|
-
async evaluateTx(tx) {
|
|
1422
|
-
const
|
|
1541
|
+
async evaluateTx(tx, additionalUtxos, additionalTxs) {
|
|
1542
|
+
const foundUtxos = /* @__PURE__ */ new Set();
|
|
1543
|
+
for (const utxo of additionalUtxos) {
|
|
1544
|
+
foundUtxos.add(`${utxo.input.txHash}:${utxo.input.outputIndex}`);
|
|
1545
|
+
}
|
|
1546
|
+
for (const tx2 of additionalTxs) {
|
|
1547
|
+
const outputs = getTransactionOutputs(tx2);
|
|
1548
|
+
for (const output of outputs) {
|
|
1549
|
+
foundUtxos.add(`${output.input.txHash}:${output.input.outputIndex}`);
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
const inputsToResolve = getTransactionInputs(tx).filter(
|
|
1553
|
+
(input) => !foundUtxos.has(`${input.txHash}:${input.outputIndex}`)
|
|
1554
|
+
);
|
|
1423
1555
|
const txHashesSet = new Set(inputsToResolve.map((input) => input.txHash));
|
|
1424
|
-
const resolvedUTXOs = [];
|
|
1425
1556
|
for (const txHash of txHashesSet) {
|
|
1426
1557
|
const utxos = await this.fetcher.fetchUTxOs(txHash);
|
|
1427
1558
|
for (const utxo of utxos) {
|
|
1428
1559
|
if (utxo) {
|
|
1429
1560
|
if (inputsToResolve.find(
|
|
1430
|
-
(input) => input.txHash === txHash && input.
|
|
1561
|
+
(input) => input.txHash === txHash && input.outputIndex === utxo.input.outputIndex
|
|
1431
1562
|
)) {
|
|
1432
|
-
|
|
1563
|
+
additionalUtxos.push(utxo);
|
|
1564
|
+
foundUtxos.add(`${utxo.input.txHash}:${utxo.input.outputIndex}`);
|
|
1433
1565
|
}
|
|
1434
1566
|
}
|
|
1435
1567
|
}
|
|
1436
1568
|
}
|
|
1437
1569
|
const missing = inputsToResolve.filter(
|
|
1438
|
-
(input) => !
|
|
1439
|
-
(utxo) => utxo.input.txHash === input.txHash && utxo.input.outputIndex === input.index
|
|
1440
|
-
)
|
|
1570
|
+
(input) => !foundUtxos.has(`${input.txHash}:${input.outputIndex}`)
|
|
1441
1571
|
);
|
|
1442
1572
|
if (missing.length > 0) {
|
|
1443
|
-
const missingList = missing.map((m) => `${m.txHash}:${m.
|
|
1573
|
+
const missingList = missing.map((m) => `${m.txHash}:${m.outputIndex}`).join(", ");
|
|
1444
1574
|
throw new Error(
|
|
1445
1575
|
`Can't resolve these UTXOs to execute plutus scripts: ${missingList}`
|
|
1446
1576
|
);
|
|
1447
1577
|
}
|
|
1448
1578
|
return evaluateTransaction(
|
|
1449
1579
|
tx,
|
|
1450
|
-
|
|
1580
|
+
additionalUtxos,
|
|
1581
|
+
additionalTxs,
|
|
1451
1582
|
this.network,
|
|
1452
1583
|
this.slotConfig
|
|
1453
1584
|
);
|
|
@@ -1459,8 +1590,8 @@ export {
|
|
|
1459
1590
|
OfflineEvaluator,
|
|
1460
1591
|
POLICY_ID_LENGTH,
|
|
1461
1592
|
REDEEMER_TAGS,
|
|
1462
|
-
|
|
1463
|
-
|
|
1593
|
+
addrBech32ToPlutusDataHex,
|
|
1594
|
+
addrBech32ToPlutusDataObj,
|
|
1464
1595
|
applyCborEncoding,
|
|
1465
1596
|
applyParamsToScript,
|
|
1466
1597
|
baseAddressToStakeAddress,
|
|
@@ -1496,6 +1627,7 @@ export {
|
|
|
1496
1627
|
fromUTF8,
|
|
1497
1628
|
getDRepIds,
|
|
1498
1629
|
getTransactionInputs,
|
|
1630
|
+
getTransactionOutputs,
|
|
1499
1631
|
getV2ScriptHash,
|
|
1500
1632
|
keyHashToRewardAddress,
|
|
1501
1633
|
meshTxBuilderBodyToObj,
|
|
@@ -1539,6 +1671,7 @@ export {
|
|
|
1539
1671
|
toAddress,
|
|
1540
1672
|
toBaseAddress,
|
|
1541
1673
|
toBytes,
|
|
1674
|
+
toCslValue,
|
|
1542
1675
|
toEnterpriseAddress,
|
|
1543
1676
|
toLovelace,
|
|
1544
1677
|
toNativeScript,
|