@lucid-evolution/utils 0.1.39 → 0.1.41

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
@@ -309,6 +309,12 @@ function toScriptRef(script) {
309
309
  applyDoubleCborEncoding(script.script)
310
310
  )
311
311
  );
312
+ case "PlutusV3":
313
+ return CML.Script.new_plutus_v3(
314
+ CML.PlutusV3Script.from_cbor_hex(
315
+ applyDoubleCborEncoding(script.script)
316
+ )
317
+ );
312
318
  default:
313
319
  throw new Error("No variant matched.");
314
320
  }
@@ -545,6 +551,9 @@ function createCostModels(costModels) {
545
551
  for (const cost of Object.values(costModels.PlutusV2)) {
546
552
  costmodel[1]?.push(cost);
547
553
  }
554
+ for (const cost of Object.values(costModels.PlutusV3)) {
555
+ costmodel[2]?.push(cost);
556
+ }
548
557
  return CML.CostModels.from_json(JSON.stringify(costmodel));
549
558
  }
550
559
  var PROTOCOL_PARAMETERS_DEFAULT = {
@@ -1273,9 +1282,6 @@ function slotToUnixTime(network, slot) {
1273
1282
  return (0, import_plutus2.slotToBeginUnixTime)(slot, import_plutus2.SLOT_CONFIG_NETWORK[network]);
1274
1283
  }
1275
1284
 
1276
- // src/utxo.ts
1277
- var CSL = __toESM(require("@emurgo/cardano-serialization-lib-nodejs"), 1);
1278
-
1279
1285
  // src/value.ts
1280
1286
  var import_core_utils4 = require("@lucid-evolution/core-utils");
1281
1287
  function valueToAssets(value) {
@@ -1345,7 +1351,12 @@ function addAssets(...assets) {
1345
1351
  return assets.reduce((a, b) => {
1346
1352
  for (const k in b) {
1347
1353
  if (Object.hasOwn(b, k)) {
1348
- a[k] = (a[k] || 0n) + b[k];
1354
+ const sum = (a[k] || 0n) + b[k];
1355
+ if (sum === 0n) {
1356
+ delete a[k];
1357
+ } else {
1358
+ a[k] = sum;
1359
+ }
1349
1360
  }
1350
1361
  }
1351
1362
  return a;
@@ -1384,16 +1395,9 @@ function utxosToCores(utxos) {
1384
1395
  return result;
1385
1396
  }
1386
1397
  function coreToUtxo(coreUtxo) {
1387
- const utxoCore = CSL.TransactionUnspentOutput.from_bytes(
1388
- coreUtxo.to_cbor_bytes()
1389
- );
1390
1398
  const utxo = {
1391
- ...coreToOutRef(
1392
- CML.TransactionInput.from_cbor_bytes(utxoCore.input().to_bytes())
1393
- ),
1394
- ...coreToTxOutput(
1395
- CML.TransactionOutput.from_cbor_bytes(utxoCore.output().to_bytes())
1396
- )
1399
+ ...coreToOutRef(coreUtxo.input()),
1400
+ ...coreToTxOutput(coreUtxo.output())
1397
1401
  };
1398
1402
  return utxo;
1399
1403
  }
package/dist/index.js CHANGED
@@ -226,6 +226,12 @@ function toScriptRef(script) {
226
226
  applyDoubleCborEncoding(script.script)
227
227
  )
228
228
  );
229
+ case "PlutusV3":
230
+ return CML.Script.new_plutus_v3(
231
+ CML.PlutusV3Script.from_cbor_hex(
232
+ applyDoubleCborEncoding(script.script)
233
+ )
234
+ );
229
235
  default:
230
236
  throw new Error("No variant matched.");
231
237
  }
@@ -462,6 +468,9 @@ function createCostModels(costModels) {
462
468
  for (const cost of Object.values(costModels.PlutusV2)) {
463
469
  costmodel[1]?.push(cost);
464
470
  }
471
+ for (const cost of Object.values(costModels.PlutusV3)) {
472
+ costmodel[2]?.push(cost);
473
+ }
465
474
  return CML.CostModels.from_json(JSON.stringify(costmodel));
466
475
  }
467
476
  var PROTOCOL_PARAMETERS_DEFAULT = {
@@ -1194,9 +1203,6 @@ function slotToUnixTime(network, slot) {
1194
1203
  return slotToBeginUnixTime(slot, SLOT_CONFIG_NETWORK[network]);
1195
1204
  }
1196
1205
 
1197
- // src/utxo.ts
1198
- import * as CSL from "@emurgo/cardano-serialization-lib-nodejs";
1199
-
1200
1206
  // src/value.ts
1201
1207
  import { fromHex as fromHex4, toHex as toHex3 } from "@lucid-evolution/core-utils";
1202
1208
  function valueToAssets(value) {
@@ -1266,7 +1272,12 @@ function addAssets(...assets) {
1266
1272
  return assets.reduce((a, b) => {
1267
1273
  for (const k in b) {
1268
1274
  if (Object.hasOwn(b, k)) {
1269
- a[k] = (a[k] || 0n) + b[k];
1275
+ const sum = (a[k] || 0n) + b[k];
1276
+ if (sum === 0n) {
1277
+ delete a[k];
1278
+ } else {
1279
+ a[k] = sum;
1280
+ }
1270
1281
  }
1271
1282
  }
1272
1283
  return a;
@@ -1305,16 +1316,9 @@ function utxosToCores(utxos) {
1305
1316
  return result;
1306
1317
  }
1307
1318
  function coreToUtxo(coreUtxo) {
1308
- const utxoCore = CSL.TransactionUnspentOutput.from_bytes(
1309
- coreUtxo.to_cbor_bytes()
1310
- );
1311
1319
  const utxo = {
1312
- ...coreToOutRef(
1313
- CML.TransactionInput.from_cbor_bytes(utxoCore.input().to_bytes())
1314
- ),
1315
- ...coreToTxOutput(
1316
- CML.TransactionOutput.from_cbor_bytes(utxoCore.output().to_bytes())
1317
- )
1320
+ ...coreToOutRef(coreUtxo.input()),
1321
+ ...coreToTxOutput(coreUtxo.output())
1318
1322
  };
1319
1323
  return utxo;
1320
1324
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lucid-evolution/utils",
3
- "version": "0.1.39",
3
+ "version": "0.1.41",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -29,8 +29,6 @@
29
29
  "@anastasia-labs/cardano-multiplatform-lib-browser": "6.0.2-1",
30
30
  "@anastasia-labs/cardano-multiplatform-lib-nodejs": "6.0.2-1",
31
31
  "@effect/schema": "^0.68.16",
32
- "@emurgo/cardano-serialization-lib-browser": "^11.5.0",
33
- "@emurgo/cardano-serialization-lib-nodejs": "^11.5.0",
34
32
  "@harmoniclabs/plutus-data": "^1.2.4",
35
33
  "@harmoniclabs/uplc": "^1.2.4",
36
34
  "bip39": "^3.1.0",
@@ -40,7 +38,7 @@
40
38
  "@lucid-evolution/core-utils": "0.1.15",
41
39
  "@lucid-evolution/crc8": "0.1.8",
42
40
  "@lucid-evolution/plutus": "0.1.23",
43
- "@lucid-evolution/uplc": "0.2.11"
41
+ "@lucid-evolution/uplc": "0.2.12"
44
42
  },
45
43
  "devDependencies": {
46
44
  "@types/node": "^20.12.8",