@lucid-evolution/utils 0.1.75 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -32,6 +32,7 @@ var index_exports = {};
32
32
  __export(index_exports, {
33
33
  CBOREncodingLevel: () => CBOREncodingLevel,
34
34
  PROTOCOL_PARAMETERS_DEFAULT: () => PROTOCOL_PARAMETERS_DEFAULT,
35
+ ScriptCache: () => ScriptCache,
35
36
  addAssets: () => addAssets,
36
37
  addressFromHexOrBech32: () => addressFromHexOrBech32,
37
38
  applyDoubleCborEncoding: () => applyDoubleCborEncoding,
@@ -66,6 +67,7 @@ __export(index_exports, {
66
67
  networkToId: () => networkToId,
67
68
  parseCMLNative: () => parseCMLNative,
68
69
  paymentCredentialOf: () => paymentCredentialOf,
70
+ scriptCborBytes: () => scriptCborBytes,
69
71
  scriptFromCMLNative: () => scriptFromCMLNative,
70
72
  scriptFromNative: () => scriptFromNative,
71
73
  scriptHashToCredential: () => scriptHashToCredential,
@@ -97,7 +99,7 @@ module.exports = __toCommonJS(index_exports);
97
99
  var S = __toESM(require("@effect/schema/Schema"), 1);
98
100
 
99
101
  // src/core.ts
100
- var CML = __toESM(require("@anastasia-labs/cardano-multiplatform-lib-nodejs"), 1);
102
+ var CML = __toESM(require("@lucid-evolution/cml"), 1);
101
103
 
102
104
  // src/native.ts
103
105
  var toCMLNativeScript = (native) => {
@@ -199,7 +201,107 @@ function networkToId(network) {
199
201
  // src/cbor.ts
200
202
  var import_core_utils = require("@lucid-evolution/core-utils");
201
203
  var import_cbor_x = require("cbor-x");
204
+
205
+ // src/script-cache.ts
206
+ var SHORT_SCRIPT_LENGTH = 1024;
207
+ var SAMPLE_COUNT = 32;
208
+ var SAMPLE_WIDTH = 16;
209
+ var TAIL_WIDTH = 512;
210
+ var MAX_CHAIN = 4;
211
+ var fingerprint = (namespace, script) => {
212
+ const length = script.length;
213
+ if (length <= SHORT_SCRIPT_LENGTH) return namespace + ":" + script;
214
+ const stride = Math.floor((length - TAIL_WIDTH) / SAMPLE_COUNT);
215
+ let key = namespace + ":" + length + ":";
216
+ for (let offset = 0; offset < SAMPLE_COUNT; offset++) {
217
+ const start = offset * stride;
218
+ key += script.slice(start, start + SAMPLE_WIDTH);
219
+ }
220
+ return key + script.slice(length - TAIL_WIDTH);
221
+ };
222
+ var ScriptCache = class {
223
+ /**
224
+ * @param capacity maximum number of entries
225
+ * @param maxWeight maximum total weight, see `weigh`
226
+ * @param weigh approximate retained bytes of an entry besides its key
227
+ */
228
+ constructor(capacity, maxWeight, weigh = () => 0) {
229
+ this.capacity = capacity;
230
+ this.maxWeight = maxWeight;
231
+ this.weigh = weigh;
232
+ }
233
+ buckets = /* @__PURE__ */ new Map();
234
+ /** Insertion order, for first-in first-out eviction. */
235
+ order = /* @__PURE__ */ new Set();
236
+ totalWeight = 0;
237
+ get size() {
238
+ return this.order.size;
239
+ }
240
+ get(namespace, script) {
241
+ const bucket = this.buckets.get(fingerprint(namespace, script));
242
+ if (bucket === void 0) return void 0;
243
+ for (const entry of bucket) {
244
+ if (entry.script === script) return entry.value;
245
+ }
246
+ return void 0;
247
+ }
248
+ set(namespace, script, value) {
249
+ const weight = script.length + this.weigh(value);
250
+ if (weight > this.maxWeight) return;
251
+ const key = fingerprint(namespace, script);
252
+ const previous = this.buckets.get(key);
253
+ if (previous !== void 0) {
254
+ const existing = previous.find((entry2) => entry2.script === script);
255
+ if (existing !== void 0) this.remove(existing);
256
+ if (previous.length >= MAX_CHAIN) this.remove(previous[0]);
257
+ }
258
+ const entry = { key, script, value, weight };
259
+ const bucket = this.buckets.get(key);
260
+ if (bucket === void 0) this.buckets.set(key, [entry]);
261
+ else bucket.push(entry);
262
+ this.order.add(entry);
263
+ this.totalWeight += weight;
264
+ while (this.order.size > this.capacity || this.totalWeight > this.maxWeight) {
265
+ this.remove(this.order.values().next().value);
266
+ }
267
+ }
268
+ clear() {
269
+ this.buckets.clear();
270
+ this.order.clear();
271
+ this.totalWeight = 0;
272
+ }
273
+ remove(entry) {
274
+ const bucket = this.buckets.get(entry.key);
275
+ if (bucket !== void 0) {
276
+ const index = bucket.indexOf(entry);
277
+ if (index !== -1) bucket.splice(index, 1);
278
+ if (bucket.length === 0) this.buckets.delete(entry.key);
279
+ }
280
+ if (this.order.delete(entry)) this.totalWeight -= entry.weight;
281
+ }
282
+ /**
283
+ * Returns the cached value, or computes, stores and returns it. A `compute`
284
+ * that throws stores nothing.
285
+ */
286
+ getOrCompute(namespace, script, compute) {
287
+ const cached = this.get(namespace, script);
288
+ if (cached !== void 0) return cached;
289
+ const value = compute();
290
+ this.set(namespace, script, value);
291
+ return value;
292
+ }
293
+ };
294
+
295
+ // src/cbor.ts
202
296
  var applyDoubleCborEncoding = (script) => {
297
+ if (typeof script !== "string") return decodingDoubleCborEncoding(script);
298
+ const cached = doubleCborCache.get("", script);
299
+ if (cached !== void 0) return cached;
300
+ const encoded = doubleCborEncoding(script);
301
+ doubleCborCache.set("", script, encoded);
302
+ return encoded;
303
+ };
304
+ var decodingDoubleCborEncoding = (script) => {
203
305
  try {
204
306
  (0, import_cbor_x.decode)((0, import_cbor_x.decode)((0, import_core_utils.fromHex)(script)));
205
307
  return script;
@@ -212,6 +314,75 @@ var applyDoubleCborEncoding = (script) => {
212
314
  }
213
315
  }
214
316
  };
317
+ var doubleCborEncoding = (script) => {
318
+ const layers = bytestringLayers(script);
319
+ switch (layers) {
320
+ case 2:
321
+ return script;
322
+ case 1:
323
+ return bytestringHeaderHex(script.length / 2) + script.toLowerCase();
324
+ case 0: {
325
+ const inner = bytestringHeaderHex(script.length / 2);
326
+ const innerLength = script.length / 2 + inner.length / 2;
327
+ return bytestringHeaderHex(innerLength) + inner + script.toLowerCase();
328
+ }
329
+ default:
330
+ return decodingDoubleCborEncoding(script);
331
+ }
332
+ };
333
+ var doubleCborCache = new ScriptCache(
334
+ 4096,
335
+ 64 * 1024 * 1024,
336
+ // Overcounts a script that is already double encoded, whose result is the
337
+ // key itself.
338
+ (encoded) => encoded.length
339
+ );
340
+ var NON_HEX = /[^0-9a-fA-F]/;
341
+ var hexByte = (hex, index) => parseInt(hex.slice(index * 2, index * 2 + 2), 16);
342
+ var itemHeader = (hex, offset, end) => {
343
+ if (offset >= end) return void 0;
344
+ const token = hexByte(hex, offset);
345
+ const major = token >> 5;
346
+ if (major > 2) return void 0;
347
+ const info = token & 31;
348
+ let argument;
349
+ let headerLength;
350
+ if (info < 24) {
351
+ argument = info;
352
+ headerLength = 1;
353
+ } else if (info <= 26) {
354
+ headerLength = 1 + (1 << info - 24);
355
+ if (offset + headerLength > end) return void 0;
356
+ argument = 0;
357
+ for (let index = offset + 1; index < offset + headerLength; index++) {
358
+ argument = argument * 256 + hexByte(hex, index);
359
+ }
360
+ } else {
361
+ return void 0;
362
+ }
363
+ const payload = major === 2 ? argument : 0;
364
+ return { major, span: headerLength + payload, headerLength };
365
+ };
366
+ var bytestringLayers = (script) => {
367
+ if (script.length === 0 || script.length % 2 !== 0) return void 0;
368
+ if (NON_HEX.test(script)) return void 0;
369
+ const length = script.length / 2;
370
+ const outer = itemHeader(script, 0, length);
371
+ if (outer === void 0) return void 0;
372
+ if (outer.span !== length) return 0;
373
+ if (outer.major !== 2) return 1;
374
+ if (outer.headerLength === length) return void 0;
375
+ const inner = itemHeader(script, outer.headerLength, length);
376
+ if (inner === void 0) return void 0;
377
+ return inner.span === length - outer.headerLength ? 2 : 1;
378
+ };
379
+ var bytestringHeaderHex = (length) => {
380
+ if (length < 24) return byteHex(64 + length);
381
+ if (length < 256) return "58" + byteHex(length);
382
+ if (length < 65536) return "59" + length.toString(16).padStart(4, "0");
383
+ return "5a" + length.toString(16).padStart(8, "0");
384
+ };
385
+ var byteHex = (byte) => byte.toString(16).padStart(2, "0");
215
386
  var applySingleCborEncoding = (script) => {
216
387
  try {
217
388
  (0, import_cbor_x.decode)((0, import_cbor_x.decode)((0, import_core_utils.fromHex)(script)));
@@ -314,77 +485,165 @@ function validatorToAddress(network, validator, stakeCredential) {
314
485
  });
315
486
  }
316
487
  function validatorToScriptHash(validator) {
317
- return (0, import_core_utils2.withCMLScope)((own) => {
318
- switch (validator.type) {
319
- case "Native":
320
- return own(
321
- own(CML.NativeScript.from_cbor_hex(validator.script)).hash()
322
- ).to_hex();
323
- case "PlutusV1": {
324
- const script = own(
325
- CML.PlutusV1Script.from_cbor_hex(
326
- applyDoubleCborEncoding(validator.script)
327
- )
328
- );
329
- return own(own(CML.PlutusScript.from_v1(script)).hash()).to_hex();
330
- }
331
- case "PlutusV2": {
332
- const script = own(
333
- CML.PlutusV2Script.from_cbor_hex(
334
- applyDoubleCborEncoding(validator.script)
335
- )
336
- );
337
- return own(own(CML.PlutusScript.from_v2(script)).hash()).to_hex();
338
- }
339
- case "PlutusV3": {
340
- const script = own(
341
- CML.PlutusV3Script.from_cbor_hex(
342
- applyDoubleCborEncoding(validator.script)
343
- )
344
- );
345
- return own(own(CML.PlutusScript.from_v3(script)).hash()).to_hex();
346
- }
347
- default:
348
- throw new Error("No variant matched");
349
- }
350
- });
488
+ const info = tryScriptInfo(validator);
489
+ return info === void 0 ? decodingValidatorToScriptHash(validator) : info.hash;
490
+ }
491
+ function scriptCborBytes(script) {
492
+ return scriptInfo(script).bytes.slice();
351
493
  }
352
494
  function toScriptRef(script) {
495
+ const info = tryScriptInfo(script);
496
+ if (info === void 0) return decodingToScriptRef(script);
497
+ const { bytes } = info;
353
498
  return (0, import_core_utils2.withCMLScope)((own) => {
354
499
  switch (script.type) {
355
500
  case "Native":
356
501
  return CML.Script.new_native(
357
- own(CML.NativeScript.from_cbor_hex(script.script))
502
+ own(CML.NativeScript.from_cbor_bytes(bytes))
358
503
  );
359
504
  case "PlutusV1":
360
505
  return CML.Script.new_plutus_v1(
361
- own(
362
- CML.PlutusV1Script.from_cbor_hex(
363
- applyDoubleCborEncoding(script.script)
364
- )
365
- )
506
+ own(CML.PlutusV1Script.from_cbor_bytes(bytes))
366
507
  );
367
508
  case "PlutusV2":
368
509
  return CML.Script.new_plutus_v2(
369
- own(
370
- CML.PlutusV2Script.from_cbor_hex(
371
- applyDoubleCborEncoding(script.script)
372
- )
373
- )
510
+ own(CML.PlutusV2Script.from_cbor_bytes(bytes))
374
511
  );
375
512
  case "PlutusV3":
376
513
  return CML.Script.new_plutus_v3(
377
- own(
378
- CML.PlutusV3Script.from_cbor_hex(
379
- applyDoubleCborEncoding(script.script)
380
- )
381
- )
514
+ own(CML.PlutusV3Script.from_cbor_bytes(bytes))
382
515
  );
383
516
  default:
384
517
  throw new Error("No variant matched.");
385
518
  }
386
519
  });
387
520
  }
521
+ var scriptInfoCache = new ScriptCache(
522
+ 4096,
523
+ 64 * 1024 * 1024,
524
+ (info) => info.bytes.length + info.hash.length
525
+ );
526
+ var scriptInfo = (script) => scriptInfoCache.getOrCompute(
527
+ script.type,
528
+ script.script,
529
+ () => computeScriptInfo(script)
530
+ );
531
+ var tryScriptInfo = (script) => {
532
+ try {
533
+ if (typeof script.script !== "string") return void 0;
534
+ return scriptInfo(script);
535
+ } catch {
536
+ return void 0;
537
+ }
538
+ };
539
+ var computeScriptInfo = ({ type, script }) => (0, import_core_utils2.withCMLScope)((own) => {
540
+ switch (type) {
541
+ case "Native": {
542
+ const bytes = (0, import_core_utils2.fromHex)(script);
543
+ const hash = own(
544
+ own(CML.NativeScript.from_cbor_bytes(bytes)).hash()
545
+ ).to_hex();
546
+ return { hash, bytes };
547
+ }
548
+ case "PlutusV1": {
549
+ const bytes = (0, import_core_utils2.fromHex)(applyDoubleCborEncoding(script));
550
+ const plutus = own(
551
+ CML.PlutusScript.from_v1(
552
+ own(CML.PlutusV1Script.from_cbor_bytes(bytes))
553
+ )
554
+ );
555
+ return { hash: own(plutus.hash()).to_hex(), bytes };
556
+ }
557
+ case "PlutusV2": {
558
+ const bytes = (0, import_core_utils2.fromHex)(applyDoubleCborEncoding(script));
559
+ const plutus = own(
560
+ CML.PlutusScript.from_v2(
561
+ own(CML.PlutusV2Script.from_cbor_bytes(bytes))
562
+ )
563
+ );
564
+ return { hash: own(plutus.hash()).to_hex(), bytes };
565
+ }
566
+ case "PlutusV3": {
567
+ const bytes = (0, import_core_utils2.fromHex)(applyDoubleCborEncoding(script));
568
+ const plutus = own(
569
+ CML.PlutusScript.from_v3(
570
+ own(CML.PlutusV3Script.from_cbor_bytes(bytes))
571
+ )
572
+ );
573
+ return { hash: own(plutus.hash()).to_hex(), bytes };
574
+ }
575
+ default:
576
+ throw new Error("No variant matched");
577
+ }
578
+ });
579
+ var decodingValidatorToScriptHash = (validator) => (0, import_core_utils2.withCMLScope)((own) => {
580
+ switch (validator.type) {
581
+ case "Native":
582
+ return own(
583
+ own(CML.NativeScript.from_cbor_hex(validator.script)).hash()
584
+ ).to_hex();
585
+ case "PlutusV1": {
586
+ const script = own(
587
+ CML.PlutusV1Script.from_cbor_hex(
588
+ applyDoubleCborEncoding(validator.script)
589
+ )
590
+ );
591
+ return own(own(CML.PlutusScript.from_v1(script)).hash()).to_hex();
592
+ }
593
+ case "PlutusV2": {
594
+ const script = own(
595
+ CML.PlutusV2Script.from_cbor_hex(
596
+ applyDoubleCborEncoding(validator.script)
597
+ )
598
+ );
599
+ return own(own(CML.PlutusScript.from_v2(script)).hash()).to_hex();
600
+ }
601
+ case "PlutusV3": {
602
+ const script = own(
603
+ CML.PlutusV3Script.from_cbor_hex(
604
+ applyDoubleCborEncoding(validator.script)
605
+ )
606
+ );
607
+ return own(own(CML.PlutusScript.from_v3(script)).hash()).to_hex();
608
+ }
609
+ default:
610
+ throw new Error("No variant matched");
611
+ }
612
+ });
613
+ var decodingToScriptRef = (script) => (0, import_core_utils2.withCMLScope)((own) => {
614
+ switch (script.type) {
615
+ case "Native":
616
+ return CML.Script.new_native(
617
+ own(CML.NativeScript.from_cbor_hex(script.script))
618
+ );
619
+ case "PlutusV1":
620
+ return CML.Script.new_plutus_v1(
621
+ own(
622
+ CML.PlutusV1Script.from_cbor_hex(
623
+ applyDoubleCborEncoding(script.script)
624
+ )
625
+ )
626
+ );
627
+ case "PlutusV2":
628
+ return CML.Script.new_plutus_v2(
629
+ own(
630
+ CML.PlutusV2Script.from_cbor_hex(
631
+ applyDoubleCborEncoding(script.script)
632
+ )
633
+ )
634
+ );
635
+ case "PlutusV3":
636
+ return CML.Script.new_plutus_v3(
637
+ own(
638
+ CML.PlutusV3Script.from_cbor_hex(
639
+ applyDoubleCborEncoding(script.script)
640
+ )
641
+ )
642
+ );
643
+ default:
644
+ throw new Error("No variant matched.");
645
+ }
646
+ });
388
647
  function fromScriptRef(scriptRef) {
389
648
  return (0, import_core_utils2.withCMLScope)((own) => {
390
649
  const kind = scriptRef.kind();
@@ -482,12 +741,24 @@ var addressDetails = (address) => ({
482
741
  bech32: address.to_bech32(void 0),
483
742
  hex: address.to_hex()
484
743
  });
485
- function getAddressDetails(address) {
744
+ var HEX_PATTERN = /^[0-9a-fA-F]*$/;
745
+ var parseShelleyAddress = (address) => {
746
+ if (HEX_PATTERN.test(address)) {
747
+ try {
748
+ return CML.Address.from_hex(address);
749
+ } catch (_e) {
750
+ }
751
+ }
486
752
  try {
487
- return (0, import_core_utils3.withCMLScope)((own) => {
488
- const parsedAddress = own(
489
- CML.BaseAddress.from_address(own(addressFromHexOrBech32(address)))
490
- );
753
+ return CML.Address.from_bech32(address);
754
+ } catch (_e) {
755
+ return void 0;
756
+ }
757
+ };
758
+ var shelleyAddressDetails = (address, own) => {
759
+ switch (address.kind()) {
760
+ case CML.AddressKind.Base: {
761
+ const parsedAddress = own(CML.BaseAddress.from_address(address));
491
762
  const paymentCredential = credentialDetails(
492
763
  own(parsedAddress.payment()),
493
764
  own
@@ -506,16 +777,9 @@ function getAddressDetails(address) {
506
777
  paymentCredential,
507
778
  stakeCredential
508
779
  };
509
- });
510
- } catch (_e) {
511
- }
512
- try {
513
- return (0, import_core_utils3.withCMLScope)((own) => {
514
- const parsedAddress = own(
515
- CML.EnterpriseAddress.from_address(
516
- own(addressFromHexOrBech32(address))
517
- )
518
- );
780
+ }
781
+ case CML.AddressKind.Enterprise: {
782
+ const parsedAddress = own(CML.EnterpriseAddress.from_address(address));
519
783
  const paymentCredential = credentialDetails(
520
784
  own(parsedAddress.payment()),
521
785
  own
@@ -529,14 +793,9 @@ function getAddressDetails(address) {
529
793
  address: details,
530
794
  paymentCredential
531
795
  };
532
- });
533
- } catch (_e) {
534
- }
535
- try {
536
- return (0, import_core_utils3.withCMLScope)((own) => {
537
- const parsedAddress = own(
538
- CML.PointerAddress.from_address(own(addressFromHexOrBech32(address)))
539
- );
796
+ }
797
+ case CML.AddressKind.Ptr: {
798
+ const parsedAddress = own(CML.PointerAddress.from_address(address));
540
799
  const paymentCredential = credentialDetails(
541
800
  own(parsedAddress.payment()),
542
801
  own
@@ -550,14 +809,9 @@ function getAddressDetails(address) {
550
809
  address: details,
551
810
  paymentCredential
552
811
  };
553
- });
554
- } catch (_e) {
555
- }
556
- try {
557
- return (0, import_core_utils3.withCMLScope)((own) => {
558
- const parsedAddress = own(
559
- CML.RewardAddress.from_address(own(addressFromHexOrBech32(address)))
560
- );
812
+ }
813
+ case CML.AddressKind.Reward: {
814
+ const parsedAddress = own(CML.RewardAddress.from_address(address));
561
815
  const stakeCredential = credentialDetails(
562
816
  own(parsedAddress.payment()),
563
817
  own
@@ -566,36 +820,83 @@ function getAddressDetails(address) {
566
820
  own(parsedAddress.to_address())
567
821
  );
568
822
  return { type: "Reward", networkId, address: details, stakeCredential };
823
+ }
824
+ default:
825
+ return void 0;
826
+ }
827
+ };
828
+ var byronAddressDetails = (address) => (0, import_core_utils3.withCMLScope)((own) => {
829
+ const parsedAddress = own(
830
+ ((address2) => {
831
+ if (HEX_PATTERN.test(address2)) {
832
+ try {
833
+ return CML.ByronAddress.from_cbor_hex(address2);
834
+ } catch (_e) {
835
+ }
836
+ }
837
+ try {
838
+ return CML.ByronAddress.from_base58(address2);
839
+ } catch (_e) {
840
+ return void 0;
841
+ }
842
+ })(address)
843
+ );
844
+ if (!parsedAddress) return void 0;
845
+ return {
846
+ type: "Byron",
847
+ networkId: own(parsedAddress.content()).network_id(),
848
+ address: {
849
+ bech32: "",
850
+ hex: own(parsedAddress.to_address()).to_hex()
851
+ }
852
+ };
853
+ });
854
+ var parseAddressDetails = (address) => {
855
+ try {
856
+ const details = (0, import_core_utils3.withCMLScope)((own) => {
857
+ const parsedAddress = own(parseShelleyAddress(address));
858
+ return parsedAddress && shelleyAddressDetails(parsedAddress, own);
569
859
  });
860
+ if (details) return details;
570
861
  } catch (_e) {
571
862
  }
572
863
  try {
573
- return (0, import_core_utils3.withCMLScope)((own) => {
574
- const parsedAddress = own(
575
- ((address2) => {
576
- try {
577
- return CML.ByronAddress.from_cbor_hex(address2);
578
- } catch (_e) {
579
- try {
580
- return CML.ByronAddress.from_base58(address2);
581
- } catch (_e2) {
582
- throw new Error("Could not deserialize address.");
583
- }
584
- }
585
- })(address)
586
- );
587
- return {
588
- type: "Byron",
589
- networkId: own(parsedAddress.content()).network_id(),
590
- address: {
591
- bech32: "",
592
- hex: own(parsedAddress.to_address()).to_hex()
593
- }
594
- };
595
- });
864
+ const details = byronAddressDetails(address);
865
+ if (details) return details;
596
866
  } catch (_e) {
597
867
  }
598
868
  throw new Error("No address type matched for: " + address);
869
+ };
870
+ var ADDRESS_DETAILS_CACHE_CAPACITY = 1e4;
871
+ var addressDetailsCache = /* @__PURE__ */ new Map();
872
+ var copyCredential = (credential) => ({
873
+ type: credential.type,
874
+ hash: credential.hash
875
+ });
876
+ var copyAddressDetails = (details) => {
877
+ const copy = {
878
+ type: details.type,
879
+ networkId: details.networkId,
880
+ address: { bech32: details.address.bech32, hex: details.address.hex }
881
+ };
882
+ if (details.paymentCredential) {
883
+ copy.paymentCredential = copyCredential(details.paymentCredential);
884
+ }
885
+ if (details.stakeCredential) {
886
+ copy.stakeCredential = copyCredential(details.stakeCredential);
887
+ }
888
+ return copy;
889
+ };
890
+ function getAddressDetails(address) {
891
+ let details = addressDetailsCache.get(address);
892
+ if (!details) {
893
+ details = parseAddressDetails(address);
894
+ if (addressDetailsCache.size >= ADDRESS_DETAILS_CACHE_CAPACITY) {
895
+ addressDetailsCache.delete(addressDetailsCache.keys().next().value);
896
+ }
897
+ addressDetailsCache.set(address, details);
898
+ }
899
+ return copyAddressDetails(details);
599
900
  }
600
901
 
601
902
  // src/cost_model.ts
@@ -1519,9 +1820,13 @@ var sortCanonical = (assets) => (0, import_effect.pipe)(
1519
1820
 
1520
1821
  // src/utxo.ts
1521
1822
  var utxoToTransactionOutput = (utxo) => (0, import_core_utils6.withCMLScope)((own) => {
1823
+ const address = own(CML.Address.from_bech32(utxo.address));
1522
1824
  const value = own(assetsToValue(utxo.assets));
1523
- const builder = own(buildOutput(utxo, own).with_value(value));
1524
- return own(builder.build()).output();
1825
+ const datum = utxo.datum ? own(CML.PlutusData.from_cbor_hex(utxo.datum)) : void 0;
1826
+ const datumHash = datum && utxo.datumHash ? own(CML.hash_plutus_data(datum)) : void 0;
1827
+ const scriptRef = utxo.scriptRef ? toScriptRef(utxo.scriptRef) : void 0;
1828
+ const datumOption = datumHash ? CML.DatumOption.new_hash(datumHash) : datum ? CML.DatumOption.new_datum(datum) : void 0;
1829
+ return CML.TransactionOutput.new(address, value, datumOption, scriptRef);
1525
1830
  });
1526
1831
  var utxoToTransactionInput = (utxo) => (0, import_core_utils6.withCMLScope)(
1527
1832
  (own) => CML.TransactionInput.new(
@@ -1745,6 +2050,7 @@ var fromCMLRedeemerTag = (tag) => {
1745
2050
  0 && (module.exports = {
1746
2051
  CBOREncodingLevel,
1747
2052
  PROTOCOL_PARAMETERS_DEFAULT,
2053
+ ScriptCache,
1748
2054
  addAssets,
1749
2055
  addressFromHexOrBech32,
1750
2056
  applyDoubleCborEncoding,
@@ -1779,6 +2085,7 @@ var fromCMLRedeemerTag = (tag) => {
1779
2085
  networkToId,
1780
2086
  parseCMLNative,
1781
2087
  paymentCredentialOf,
2088
+ scriptCborBytes,
1782
2089
  scriptFromCMLNative,
1783
2090
  scriptFromNative,
1784
2091
  scriptHashToCredential,