@lucid-evolution/utils 0.1.34 → 0.1.35

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
@@ -200,8 +200,10 @@ var applyDoubleCborEncoding = (script) => {
200
200
 
201
201
  // src/scripts.ts
202
202
  var import_plutus = require("@lucid-evolution/plutus");
203
- var UPLC = __toESM(require("@lucid-evolution/uplc"), 1);
203
+ var import_uplc = require("@harmoniclabs/uplc");
204
204
  var import_core_utils2 = require("@lucid-evolution/core-utils");
205
+ var import_cborg2 = require("cborg");
206
+ var import_plutus_data = require("@harmoniclabs/plutus-data");
205
207
  function validatorToAddress(network, validator, stakeCredential) {
206
208
  const validatorHash = validatorToScriptHash(validator);
207
209
  if (stakeCredential) {
@@ -289,9 +291,19 @@ function mintingPolicyToId(mintingPolicy) {
289
291
  return validatorToScriptHash(mintingPolicy);
290
292
  }
291
293
  function applyParamsToScript(plutusScript, params, type) {
292
- const p = type ? import_plutus.Data.castTo(params, type) : params;
294
+ const program = (0, import_uplc.parseUPLC)((0, import_cborg2.decode)((0, import_cborg2.decode)((0, import_core_utils2.fromHex)(plutusScript))), "flat");
295
+ const parameters = type ? import_plutus.Data.castTo(params, type) : params;
296
+ const appliedProgram = parameters.reduce((body, currentParameter) => {
297
+ const data = import_uplc.UPLCConst.data((0, import_plutus_data.dataFromCbor)(import_plutus.Data.to(currentParameter)));
298
+ const appliedParameter = new import_uplc.Application(body, data);
299
+ return appliedParameter;
300
+ }, program.body);
293
301
  return (0, import_core_utils2.toHex)(
294
- UPLC.apply_params_to_script((0, import_core_utils2.fromHex)(import_plutus.Data.to(p)), (0, import_core_utils2.fromHex)(plutusScript))
302
+ (0, import_cborg2.encode)(
303
+ (0, import_cborg2.encode)(
304
+ (0, import_uplc.encodeUPLC)(new import_uplc.UPLCProgram(program.version, appliedProgram)).toBuffer().buffer
305
+ )
306
+ )
295
307
  );
296
308
  }
297
309
 
package/dist/index.d.cts CHANGED
@@ -92,6 +92,11 @@ declare function validatorToScriptHash(validator: Validator): ScriptHash;
92
92
  declare function toScriptRef(script: Script): CML.Script;
93
93
  declare function fromScriptRef(scriptRef: CML.Script): Script;
94
94
  declare function mintingPolicyToId(mintingPolicy: MintingPolicy): PolicyId;
95
+ /**
96
+ * Applies a list of parameters, in the form of the `Data` type, to a CBOR encoded script.
97
+ *
98
+ * The `plutusScript` must be double CBOR encoded(bytes). Ensure to use the `applyDoubleCborEncoding` function.
99
+ */
95
100
  declare function applyParamsToScript<T extends unknown[] = Data[]>(plutusScript: string, params: Exact<[...T]>, type?: T): string;
96
101
 
97
102
  declare function unixTimeToSlot(network: Network, unixTime: UnixTime): Slot;
package/dist/index.d.ts CHANGED
@@ -92,6 +92,11 @@ declare function validatorToScriptHash(validator: Validator): ScriptHash;
92
92
  declare function toScriptRef(script: Script): CML.Script;
93
93
  declare function fromScriptRef(scriptRef: CML.Script): Script;
94
94
  declare function mintingPolicyToId(mintingPolicy: MintingPolicy): PolicyId;
95
+ /**
96
+ * Applies a list of parameters, in the form of the `Data` type, to a CBOR encoded script.
97
+ *
98
+ * The `plutusScript` must be double CBOR encoded(bytes). Ensure to use the `applyDoubleCborEncoding` function.
99
+ */
95
100
  declare function applyParamsToScript<T extends unknown[] = Data[]>(plutusScript: string, params: Exact<[...T]>, type?: T): string;
96
101
 
97
102
  declare function unixTimeToSlot(network: Network, unixTime: UnixTime): Slot;
package/dist/index.js CHANGED
@@ -112,8 +112,16 @@ var applyDoubleCborEncoding = (script) => {
112
112
 
113
113
  // src/scripts.ts
114
114
  import { Data } from "@lucid-evolution/plutus";
115
- import * as UPLC from "@lucid-evolution/uplc";
115
+ import {
116
+ Application,
117
+ encodeUPLC,
118
+ parseUPLC,
119
+ UPLCConst,
120
+ UPLCProgram
121
+ } from "@harmoniclabs/uplc";
116
122
  import { fromHex as fromHex2, toHex as toHex2 } from "@lucid-evolution/core-utils";
123
+ import { decode as decode2, encode as encode2 } from "cborg";
124
+ import { dataFromCbor } from "@harmoniclabs/plutus-data";
117
125
  function validatorToAddress(network, validator, stakeCredential) {
118
126
  const validatorHash = validatorToScriptHash(validator);
119
127
  if (stakeCredential) {
@@ -201,9 +209,19 @@ function mintingPolicyToId(mintingPolicy) {
201
209
  return validatorToScriptHash(mintingPolicy);
202
210
  }
203
211
  function applyParamsToScript(plutusScript, params, type) {
204
- const p = type ? Data.castTo(params, type) : params;
212
+ const program = parseUPLC(decode2(decode2(fromHex2(plutusScript))), "flat");
213
+ const parameters = type ? Data.castTo(params, type) : params;
214
+ const appliedProgram = parameters.reduce((body, currentParameter) => {
215
+ const data = UPLCConst.data(dataFromCbor(Data.to(currentParameter)));
216
+ const appliedParameter = new Application(body, data);
217
+ return appliedParameter;
218
+ }, program.body);
205
219
  return toHex2(
206
- UPLC.apply_params_to_script(fromHex2(Data.to(p)), fromHex2(plutusScript))
220
+ encode2(
221
+ encode2(
222
+ encodeUPLC(new UPLCProgram(program.version, appliedProgram)).toBuffer().buffer
223
+ )
224
+ )
207
225
  );
208
226
  }
209
227
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lucid-evolution/utils",
3
- "version": "0.1.34",
3
+ "version": "0.1.35",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -31,6 +31,8 @@
31
31
  "@effect/schema": "^0.68.16",
32
32
  "@emurgo/cardano-serialization-lib-browser": "^11.5.0",
33
33
  "@emurgo/cardano-serialization-lib-nodejs": "^11.5.0",
34
+ "@harmoniclabs/plutus-data": "^1.2.4",
35
+ "@harmoniclabs/uplc": "^1.2.4",
34
36
  "bip39": "^3.1.0",
35
37
  "cborg": "^4.2.0",
36
38
  "effect": "^3.1.2",