@lucid-evolution/utils 0.1.54 → 0.1.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
+ CBOREncodingLevel: () => CBOREncodingLevel,
33
34
  PROTOCOL_PARAMETERS_DEFAULT: () => PROTOCOL_PARAMETERS_DEFAULT,
34
35
  addAssets: () => addAssets,
35
36
  addressFromHexOrBech32: () => addressFromHexOrBech32,
@@ -192,14 +193,31 @@ function networkToId(network) {
192
193
 
193
194
  // src/cbor.ts
194
195
  var import_core_utils = require("@lucid-evolution/core-utils");
195
- var cbors = __toESM(require("@stricahq/cbors"), 1);
196
- var { Decoder, Encoder } = cbors;
196
+ var import_cbor_x = require("cbor-x");
197
197
  var applyDoubleCborEncoding = (script) => {
198
198
  try {
199
- Decoder.decode(Decoder.decode(Buffer.from((0, import_core_utils.fromHex)(script))).value);
199
+ (0, import_cbor_x.decode)((0, import_cbor_x.decode)((0, import_core_utils.fromHex)(script)));
200
200
  return script;
201
201
  } catch (error) {
202
- return (0, import_core_utils.toHex)(Encoder.encode((0, import_core_utils.fromHex)(script)));
202
+ try {
203
+ (0, import_cbor_x.decode)((0, import_core_utils.fromHex)(script));
204
+ return (0, import_core_utils.toHex)(Uint8Array.from((0, import_cbor_x.encode)((0, import_core_utils.fromHex)(script).buffer)));
205
+ } catch (error2) {
206
+ return (0, import_core_utils.toHex)(Uint8Array.from((0, import_cbor_x.encode)((0, import_cbor_x.encode)((0, import_core_utils.fromHex)(script).buffer))));
207
+ }
208
+ }
209
+ };
210
+ var CBOREncodingLevel = (script) => {
211
+ try {
212
+ (0, import_cbor_x.decode)((0, import_cbor_x.decode)((0, import_core_utils.fromHex)(script)));
213
+ return "double";
214
+ } catch (error) {
215
+ try {
216
+ (0, import_cbor_x.decode)((0, import_core_utils.fromHex)(script));
217
+ return "single";
218
+ } catch (error2) {
219
+ throw new Error("Script is not CBOR-encoded or invalid format.");
220
+ }
203
221
  }
204
222
  };
205
223
  function datumJsonToCbor(json) {
@@ -248,9 +266,8 @@ function datumJsonToCbor(json) {
248
266
  var import_plutus = require("@lucid-evolution/plutus");
249
267
  var import_uplc = require("@harmoniclabs/uplc");
250
268
  var import_core_utils2 = require("@lucid-evolution/core-utils");
251
- var cbors2 = __toESM(require("@stricahq/cbors"), 1);
269
+ var import_cbor_x2 = require("cbor-x");
252
270
  var import_plutus_data = require("@harmoniclabs/plutus-data");
253
- var { Encoder: Encoder2, Decoder: Decoder2 } = cbors2;
254
271
  function validatorToAddress(network, validator, stakeCredential) {
255
272
  const validatorHash = validatorToScriptHash(validator);
256
273
  if (stakeCredential) {
@@ -276,21 +293,15 @@ function validatorToScriptHash(validator) {
276
293
  return CML.NativeScript.from_cbor_hex(validator.script).hash().to_hex();
277
294
  case "PlutusV1":
278
295
  return CML.PlutusScript.from_v1(
279
- CML.PlutusV1Script.from_cbor_hex(
280
- applyDoubleCborEncoding(validator.script)
281
- )
296
+ CML.PlutusV1Script.from_cbor_hex(validator.script)
282
297
  ).hash().to_hex();
283
298
  case "PlutusV2":
284
299
  return CML.PlutusScript.from_v2(
285
- CML.PlutusV2Script.from_cbor_hex(
286
- applyDoubleCborEncoding(validator.script)
287
- )
300
+ CML.PlutusV2Script.from_cbor_hex(validator.script)
288
301
  ).hash().to_hex();
289
302
  case "PlutusV3":
290
303
  return CML.PlutusScript.from_v3(
291
- CML.PlutusV3Script.from_cbor_hex(
292
- applyDoubleCborEncoding(validator.script)
293
- )
304
+ CML.PlutusV3Script.from_cbor_hex(validator.script)
294
305
  ).hash().to_hex();
295
306
  default:
296
307
  throw new Error("No variant matched");
@@ -304,21 +315,15 @@ function toScriptRef(script) {
304
315
  );
305
316
  case "PlutusV1":
306
317
  return CML.Script.new_plutus_v1(
307
- CML.PlutusV1Script.from_cbor_hex(
308
- applyDoubleCborEncoding(script.script)
309
- )
318
+ CML.PlutusV1Script.from_cbor_hex(script.script)
310
319
  );
311
320
  case "PlutusV2":
312
321
  return CML.Script.new_plutus_v2(
313
- CML.PlutusV2Script.from_cbor_hex(
314
- applyDoubleCborEncoding(script.script)
315
- )
322
+ CML.PlutusV2Script.from_cbor_hex(script.script)
316
323
  );
317
324
  case "PlutusV3":
318
325
  return CML.Script.new_plutus_v3(
319
- CML.PlutusV3Script.from_cbor_hex(
320
- applyDoubleCborEncoding(script.script)
321
- )
326
+ CML.PlutusV3Script.from_cbor_hex(script.script)
322
327
  );
323
328
  default:
324
329
  throw new Error("No variant matched.");
@@ -355,27 +360,26 @@ function mintingPolicyToId(mintingPolicy) {
355
360
  return validatorToScriptHash(mintingPolicy);
356
361
  }
357
362
  function applyParamsToScript(plutusScript, params, type) {
358
- const program = (0, import_uplc.parseUPLC)(
359
- Decoder2.decode(
360
- Decoder2.decode(
361
- Buffer.from((0, import_core_utils2.fromHex)(applyDoubleCborEncoding(plutusScript)))
362
- ).value
363
- ).value,
364
- "flat"
365
- );
363
+ const encodingLevel = CBOREncodingLevel(plutusScript);
364
+ const program = encodingLevel === "double" ? (0, import_uplc.parseUPLC)((0, import_cbor_x2.decode)((0, import_cbor_x2.decode)((0, import_core_utils2.fromHex)(plutusScript))), "flat") : (0, import_uplc.parseUPLC)((0, import_cbor_x2.decode)((0, import_core_utils2.fromHex)(plutusScript)), "flat");
366
365
  const parameters = type ? import_plutus.Data.castTo(params, type) : params;
367
- const appliedProgram = parameters.reduce((body, currentParameter) => {
368
- const data = import_uplc.UPLCConst.data((0, import_plutus_data.dataFromCbor)(import_plutus.Data.to(currentParameter)));
369
- const appliedParameter = new import_uplc.Application(body, data);
370
- return appliedParameter;
371
- }, program.body);
372
- return (0, import_core_utils2.toHex)(
373
- Encoder2.encode(
374
- Encoder2.encode(
375
- (0, import_uplc.encodeUPLC)(new import_uplc.UPLCProgram(program.version, appliedProgram)).toBuffer().buffer
376
- )
377
- )
366
+ const appliedProgram = parameters.reduce(
367
+ (body, currentParameter) => {
368
+ const data = import_uplc.UPLCConst.data((0, import_plutus_data.dataFromCbor)(import_plutus.Data.to(currentParameter)));
369
+ const appliedParameter = new import_uplc.Application(body, data);
370
+ return appliedParameter;
371
+ },
372
+ program.body
378
373
  );
374
+ const compiledUPLC = (0, import_uplc.encodeUPLC)(
375
+ new import_uplc.UPLCProgram(program.version, appliedProgram)
376
+ ).toBuffer().buffer.buffer;
377
+ switch (encodingLevel) {
378
+ case "double":
379
+ return (0, import_core_utils2.toHex)((0, import_cbor_x2.encode)((0, import_cbor_x2.encode)(compiledUPLC)));
380
+ case "single":
381
+ return (0, import_core_utils2.toHex)((0, import_cbor_x2.encode)(compiledUPLC));
382
+ }
379
383
  }
380
384
 
381
385
  // src/address.ts
@@ -1182,7 +1186,53 @@ var PROTOCOL_PARAMETERS_DEFAULT = {
1182
1186
  "247": 43623,
1183
1187
  "248": 251,
1184
1188
  "249": 0,
1185
- "250": 1
1189
+ "250": 1,
1190
+ "251": 100181,
1191
+ "252": 726,
1192
+ "253": 719,
1193
+ "254": 0,
1194
+ "255": 1,
1195
+ "256": 100181,
1196
+ "257": 726,
1197
+ "258": 719,
1198
+ "259": 0,
1199
+ "260": 1,
1200
+ "261": 100181,
1201
+ "262": 726,
1202
+ "263": 719,
1203
+ "264": 0,
1204
+ "265": 1,
1205
+ "266": 107878,
1206
+ "267": 680,
1207
+ "268": 0,
1208
+ "269": 1,
1209
+ "270": 95336,
1210
+ "271": 1,
1211
+ "272": 281145,
1212
+ "273": 18848,
1213
+ "274": 0,
1214
+ "275": 1,
1215
+ "276": 180194,
1216
+ "277": 159,
1217
+ "278": 1,
1218
+ "279": 1,
1219
+ "280": 158519,
1220
+ "281": 8942,
1221
+ "282": 0,
1222
+ "283": 1,
1223
+ "284": 159378,
1224
+ "285": 8813,
1225
+ "286": 0,
1226
+ "287": 1,
1227
+ "288": 107490,
1228
+ "289": 3298,
1229
+ "290": 1,
1230
+ "291": 106057,
1231
+ "292": 655,
1232
+ "293": 1,
1233
+ "294": 1964219,
1234
+ "295": 24520,
1235
+ "296": 3
1186
1236
  }
1187
1237
  }
1188
1238
  };
@@ -1321,7 +1371,7 @@ function valueToAssets(value) {
1321
1371
  }
1322
1372
  function assetsToValue(assets) {
1323
1373
  const multiAsset = CML.MultiAsset.new();
1324
- const lovelace = assets["lovelace"] ? assets["lovelace"] : 0n;
1374
+ const lovelace = assets["lovelace"] ? BigInt(assets["lovelace"]) : 0n;
1325
1375
  const units = Object.keys(assets);
1326
1376
  const policies = Array.from(
1327
1377
  new Set(
@@ -1613,6 +1663,7 @@ var fromCMLRedeemerTag = (tag) => {
1613
1663
  };
1614
1664
  // Annotate the CommonJS export names for ESM import in node:
1615
1665
  0 && (module.exports = {
1666
+ CBOREncodingLevel,
1616
1667
  PROTOCOL_PARAMETERS_DEFAULT,
1617
1668
  addAssets,
1618
1669
  addressFromHexOrBech32,
package/dist/index.d.cts CHANGED
@@ -66,6 +66,7 @@ declare function validatorToRewardAddress(network: Network, validator: Certifica
66
66
  declare function getAddressDetails(address: string): AddressDetails;
67
67
 
68
68
  declare const applyDoubleCborEncoding: (script: string) => string;
69
+ declare const CBOREncodingLevel: (script: string) => "double" | "single";
69
70
  declare function datumJsonToCbor(json: DatumJson): Datum;
70
71
 
71
72
  declare function createCostModels(costModels: CostModels): CML.CostModels;
@@ -95,8 +96,6 @@ declare function fromScriptRef(scriptRef: CML.Script): Script;
95
96
  declare function mintingPolicyToId(mintingPolicy: MintingPolicy): PolicyId;
96
97
  /**
97
98
  * Applies a list of parameters, in the form of the `Data` type, to a CBOR encoded script.
98
- *
99
- * The `plutusScript` must be double CBOR encoded(bytes). Ensure to use the `applyDoubleCborEncoding` function.
100
99
  */
101
100
  declare function applyParamsToScript<T extends unknown[] = Data[]>(plutusScript: string, params: Exact<[...T]>, type?: T): string;
102
101
 
@@ -193,4 +192,4 @@ declare const stringify: (data: any) => string;
193
192
  declare const toCMLRedeemerTag: (tag: string) => CML.RedeemerTag;
194
193
  declare const fromCMLRedeemerTag: (tag: CML.RedeemerTag) => RedeemerTag;
195
194
 
196
- export { type CMLNative, PROTOCOL_PARAMETERS_DEFAULT, type SortOrder, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, assetsToValue, calculateMinLovelaceFromUTxO, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumJsonToCbor, datumToHash, fromCMLRedeemerTag, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, getInputIndices, getUniqueTokenName, isEqualUTxO, keyHashToCredential, mintingPolicyToId, networkToId, parseCMLNative, paymentCredentialOf, scriptFromCMLNative, scriptFromNative, scriptHashToCredential, selectUTxOs, slotToUnixTime, sortCanonical, sortUTxOs, stakeCredentialOf, stringify, toCMLNativeScript, toCMLRedeemerTag, toLabel, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
195
+ export { CBOREncodingLevel, type CMLNative, PROTOCOL_PARAMETERS_DEFAULT, type SortOrder, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, assetsToValue, calculateMinLovelaceFromUTxO, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumJsonToCbor, datumToHash, fromCMLRedeemerTag, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, getInputIndices, getUniqueTokenName, isEqualUTxO, keyHashToCredential, mintingPolicyToId, networkToId, parseCMLNative, paymentCredentialOf, scriptFromCMLNative, scriptFromNative, scriptHashToCredential, selectUTxOs, slotToUnixTime, sortCanonical, sortUTxOs, stakeCredentialOf, stringify, toCMLNativeScript, toCMLRedeemerTag, toLabel, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
package/dist/index.d.ts CHANGED
@@ -66,6 +66,7 @@ declare function validatorToRewardAddress(network: Network, validator: Certifica
66
66
  declare function getAddressDetails(address: string): AddressDetails;
67
67
 
68
68
  declare const applyDoubleCborEncoding: (script: string) => string;
69
+ declare const CBOREncodingLevel: (script: string) => "double" | "single";
69
70
  declare function datumJsonToCbor(json: DatumJson): Datum;
70
71
 
71
72
  declare function createCostModels(costModels: CostModels): CML.CostModels;
@@ -95,8 +96,6 @@ declare function fromScriptRef(scriptRef: CML.Script): Script;
95
96
  declare function mintingPolicyToId(mintingPolicy: MintingPolicy): PolicyId;
96
97
  /**
97
98
  * Applies a list of parameters, in the form of the `Data` type, to a CBOR encoded script.
98
- *
99
- * The `plutusScript` must be double CBOR encoded(bytes). Ensure to use the `applyDoubleCborEncoding` function.
100
99
  */
101
100
  declare function applyParamsToScript<T extends unknown[] = Data[]>(plutusScript: string, params: Exact<[...T]>, type?: T): string;
102
101
 
@@ -193,4 +192,4 @@ declare const stringify: (data: any) => string;
193
192
  declare const toCMLRedeemerTag: (tag: string) => CML.RedeemerTag;
194
193
  declare const fromCMLRedeemerTag: (tag: CML.RedeemerTag) => RedeemerTag;
195
194
 
196
- export { type CMLNative, PROTOCOL_PARAMETERS_DEFAULT, type SortOrder, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, assetsToValue, calculateMinLovelaceFromUTxO, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumJsonToCbor, datumToHash, fromCMLRedeemerTag, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, getInputIndices, getUniqueTokenName, isEqualUTxO, keyHashToCredential, mintingPolicyToId, networkToId, parseCMLNative, paymentCredentialOf, scriptFromCMLNative, scriptFromNative, scriptHashToCredential, selectUTxOs, slotToUnixTime, sortCanonical, sortUTxOs, stakeCredentialOf, stringify, toCMLNativeScript, toCMLRedeemerTag, toLabel, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
195
+ export { CBOREncodingLevel, type CMLNative, PROTOCOL_PARAMETERS_DEFAULT, type SortOrder, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, assetsToValue, calculateMinLovelaceFromUTxO, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumJsonToCbor, datumToHash, fromCMLRedeemerTag, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, getInputIndices, getUniqueTokenName, isEqualUTxO, keyHashToCredential, mintingPolicyToId, networkToId, parseCMLNative, paymentCredentialOf, scriptFromCMLNative, scriptFromNative, scriptHashToCredential, selectUTxOs, slotToUnixTime, sortCanonical, sortUTxOs, stakeCredentialOf, stringify, toCMLNativeScript, toCMLRedeemerTag, toLabel, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
package/dist/index.js CHANGED
@@ -100,14 +100,31 @@ function networkToId(network) {
100
100
 
101
101
  // src/cbor.ts
102
102
  import { fromHex, toHex } from "@lucid-evolution/core-utils";
103
- import * as cbors from "@stricahq/cbors";
104
- var { Decoder, Encoder } = cbors;
103
+ import { decode, encode } from "cbor-x";
105
104
  var applyDoubleCborEncoding = (script) => {
106
105
  try {
107
- Decoder.decode(Decoder.decode(Buffer.from(fromHex(script))).value);
106
+ decode(decode(fromHex(script)));
108
107
  return script;
109
108
  } catch (error) {
110
- return toHex(Encoder.encode(fromHex(script)));
109
+ try {
110
+ decode(fromHex(script));
111
+ return toHex(Uint8Array.from(encode(fromHex(script).buffer)));
112
+ } catch (error2) {
113
+ return toHex(Uint8Array.from(encode(encode(fromHex(script).buffer))));
114
+ }
115
+ }
116
+ };
117
+ var CBOREncodingLevel = (script) => {
118
+ try {
119
+ decode(decode(fromHex(script)));
120
+ return "double";
121
+ } catch (error) {
122
+ try {
123
+ decode(fromHex(script));
124
+ return "single";
125
+ } catch (error2) {
126
+ throw new Error("Script is not CBOR-encoded or invalid format.");
127
+ }
111
128
  }
112
129
  };
113
130
  function datumJsonToCbor(json) {
@@ -162,9 +179,8 @@ import {
162
179
  UPLCProgram
163
180
  } from "@harmoniclabs/uplc";
164
181
  import { fromHex as fromHex2, toHex as toHex2 } from "@lucid-evolution/core-utils";
165
- import * as cbors2 from "@stricahq/cbors";
182
+ import { decode as decode2, encode as encode2 } from "cbor-x";
166
183
  import { dataFromCbor } from "@harmoniclabs/plutus-data";
167
- var { Encoder: Encoder2, Decoder: Decoder2 } = cbors2;
168
184
  function validatorToAddress(network, validator, stakeCredential) {
169
185
  const validatorHash = validatorToScriptHash(validator);
170
186
  if (stakeCredential) {
@@ -190,21 +206,15 @@ function validatorToScriptHash(validator) {
190
206
  return CML.NativeScript.from_cbor_hex(validator.script).hash().to_hex();
191
207
  case "PlutusV1":
192
208
  return CML.PlutusScript.from_v1(
193
- CML.PlutusV1Script.from_cbor_hex(
194
- applyDoubleCborEncoding(validator.script)
195
- )
209
+ CML.PlutusV1Script.from_cbor_hex(validator.script)
196
210
  ).hash().to_hex();
197
211
  case "PlutusV2":
198
212
  return CML.PlutusScript.from_v2(
199
- CML.PlutusV2Script.from_cbor_hex(
200
- applyDoubleCborEncoding(validator.script)
201
- )
213
+ CML.PlutusV2Script.from_cbor_hex(validator.script)
202
214
  ).hash().to_hex();
203
215
  case "PlutusV3":
204
216
  return CML.PlutusScript.from_v3(
205
- CML.PlutusV3Script.from_cbor_hex(
206
- applyDoubleCborEncoding(validator.script)
207
- )
217
+ CML.PlutusV3Script.from_cbor_hex(validator.script)
208
218
  ).hash().to_hex();
209
219
  default:
210
220
  throw new Error("No variant matched");
@@ -218,21 +228,15 @@ function toScriptRef(script) {
218
228
  );
219
229
  case "PlutusV1":
220
230
  return CML.Script.new_plutus_v1(
221
- CML.PlutusV1Script.from_cbor_hex(
222
- applyDoubleCborEncoding(script.script)
223
- )
231
+ CML.PlutusV1Script.from_cbor_hex(script.script)
224
232
  );
225
233
  case "PlutusV2":
226
234
  return CML.Script.new_plutus_v2(
227
- CML.PlutusV2Script.from_cbor_hex(
228
- applyDoubleCborEncoding(script.script)
229
- )
235
+ CML.PlutusV2Script.from_cbor_hex(script.script)
230
236
  );
231
237
  case "PlutusV3":
232
238
  return CML.Script.new_plutus_v3(
233
- CML.PlutusV3Script.from_cbor_hex(
234
- applyDoubleCborEncoding(script.script)
235
- )
239
+ CML.PlutusV3Script.from_cbor_hex(script.script)
236
240
  );
237
241
  default:
238
242
  throw new Error("No variant matched.");
@@ -269,27 +273,26 @@ function mintingPolicyToId(mintingPolicy) {
269
273
  return validatorToScriptHash(mintingPolicy);
270
274
  }
271
275
  function applyParamsToScript(plutusScript, params, type) {
272
- const program = parseUPLC(
273
- Decoder2.decode(
274
- Decoder2.decode(
275
- Buffer.from(fromHex2(applyDoubleCborEncoding(plutusScript)))
276
- ).value
277
- ).value,
278
- "flat"
279
- );
276
+ const encodingLevel = CBOREncodingLevel(plutusScript);
277
+ const program = encodingLevel === "double" ? parseUPLC(decode2(decode2(fromHex2(plutusScript))), "flat") : parseUPLC(decode2(fromHex2(plutusScript)), "flat");
280
278
  const parameters = type ? Data.castTo(params, type) : params;
281
- const appliedProgram = parameters.reduce((body, currentParameter) => {
282
- const data = UPLCConst.data(dataFromCbor(Data.to(currentParameter)));
283
- const appliedParameter = new Application(body, data);
284
- return appliedParameter;
285
- }, program.body);
286
- return toHex2(
287
- Encoder2.encode(
288
- Encoder2.encode(
289
- encodeUPLC(new UPLCProgram(program.version, appliedProgram)).toBuffer().buffer
290
- )
291
- )
279
+ const appliedProgram = parameters.reduce(
280
+ (body, currentParameter) => {
281
+ const data = UPLCConst.data(dataFromCbor(Data.to(currentParameter)));
282
+ const appliedParameter = new Application(body, data);
283
+ return appliedParameter;
284
+ },
285
+ program.body
292
286
  );
287
+ const compiledUPLC = encodeUPLC(
288
+ new UPLCProgram(program.version, appliedProgram)
289
+ ).toBuffer().buffer.buffer;
290
+ switch (encodingLevel) {
291
+ case "double":
292
+ return toHex2(encode2(encode2(compiledUPLC)));
293
+ case "single":
294
+ return toHex2(encode2(compiledUPLC));
295
+ }
293
296
  }
294
297
 
295
298
  // src/address.ts
@@ -1096,7 +1099,53 @@ var PROTOCOL_PARAMETERS_DEFAULT = {
1096
1099
  "247": 43623,
1097
1100
  "248": 251,
1098
1101
  "249": 0,
1099
- "250": 1
1102
+ "250": 1,
1103
+ "251": 100181,
1104
+ "252": 726,
1105
+ "253": 719,
1106
+ "254": 0,
1107
+ "255": 1,
1108
+ "256": 100181,
1109
+ "257": 726,
1110
+ "258": 719,
1111
+ "259": 0,
1112
+ "260": 1,
1113
+ "261": 100181,
1114
+ "262": 726,
1115
+ "263": 719,
1116
+ "264": 0,
1117
+ "265": 1,
1118
+ "266": 107878,
1119
+ "267": 680,
1120
+ "268": 0,
1121
+ "269": 1,
1122
+ "270": 95336,
1123
+ "271": 1,
1124
+ "272": 281145,
1125
+ "273": 18848,
1126
+ "274": 0,
1127
+ "275": 1,
1128
+ "276": 180194,
1129
+ "277": 159,
1130
+ "278": 1,
1131
+ "279": 1,
1132
+ "280": 158519,
1133
+ "281": 8942,
1134
+ "282": 0,
1135
+ "283": 1,
1136
+ "284": 159378,
1137
+ "285": 8813,
1138
+ "286": 0,
1139
+ "287": 1,
1140
+ "288": 107490,
1141
+ "289": 3298,
1142
+ "290": 1,
1143
+ "291": 106057,
1144
+ "292": 655,
1145
+ "293": 1,
1146
+ "294": 1964219,
1147
+ "295": 24520,
1148
+ "296": 3
1100
1149
  }
1101
1150
  }
1102
1151
  };
@@ -1239,7 +1288,7 @@ function valueToAssets(value) {
1239
1288
  }
1240
1289
  function assetsToValue(assets) {
1241
1290
  const multiAsset = CML.MultiAsset.new();
1242
- const lovelace = assets["lovelace"] ? assets["lovelace"] : 0n;
1291
+ const lovelace = assets["lovelace"] ? BigInt(assets["lovelace"]) : 0n;
1243
1292
  const units = Object.keys(assets);
1244
1293
  const policies = Array.from(
1245
1294
  new Set(
@@ -1530,6 +1579,7 @@ var fromCMLRedeemerTag = (tag) => {
1530
1579
  }
1531
1580
  };
1532
1581
  export {
1582
+ CBOREncodingLevel,
1533
1583
  PROTOCOL_PARAMETERS_DEFAULT,
1534
1584
  addAssets,
1535
1585
  addressFromHexOrBech32,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lucid-evolution/utils",
3
- "version": "0.1.54",
3
+ "version": "0.1.56",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -26,13 +26,13 @@
26
26
  "@emurgo/cardano-serialization-lib-nodejs": "@emurgo/cardano-serialization-lib-browser"
27
27
  },
28
28
  "dependencies": {
29
- "@anastasia-labs/cardano-multiplatform-lib-browser": "6.0.2-2",
30
- "@anastasia-labs/cardano-multiplatform-lib-nodejs": "6.0.2-2",
29
+ "@anastasia-labs/cardano-multiplatform-lib-browser": "6.0.2-3",
30
+ "@anastasia-labs/cardano-multiplatform-lib-nodejs": "6.0.2-3",
31
31
  "@effect/schema": "^0.68.16",
32
32
  "@harmoniclabs/plutus-data": "^1.2.4",
33
33
  "@harmoniclabs/uplc": "^1.2.4",
34
- "@stricahq/cbors": "^1.0.3",
35
34
  "bip39": "^3.1.0",
35
+ "cbor-x": "^1.6.0",
36
36
  "effect": "^3.10.4",
37
37
  "@lucid-evolution/core-types": "0.1.21",
38
38
  "@lucid-evolution/core-utils": "0.1.16",
@@ -47,7 +47,7 @@
47
47
  "vitest": "^1.6.0"
48
48
  },
49
49
  "scripts": {
50
- "build": "tsup src/index.ts --format esm,cjs --dts --clean",
50
+ "build": "tsup src/index.ts",
51
51
  "lint": "tsc --noEmit",
52
52
  "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
53
53
  "test": "vitest run"