@lucid-evolution/utils 0.1.33 → 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 +17 -4
- package/dist/index.d.cts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +23 -4
- package/package.json +3 -1
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
|
|
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
|
|
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
|
-
|
|
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
|
|
|
@@ -1114,11 +1126,12 @@ function coresToTxOutputs(outputs) {
|
|
|
1114
1126
|
}
|
|
1115
1127
|
return result;
|
|
1116
1128
|
}
|
|
1117
|
-
var selectUTxOs = (utxos, totalAssets) => {
|
|
1129
|
+
var selectUTxOs = (utxos, totalAssets, includeUTxOsWithScriptRef = false) => {
|
|
1118
1130
|
const selectedUtxos = [];
|
|
1119
1131
|
let isSelected = false;
|
|
1120
1132
|
const assetsRequired = new Map(Object.entries(totalAssets));
|
|
1121
1133
|
for (const utxo of utxos) {
|
|
1134
|
+
if (!includeUTxOsWithScriptRef && utxo.scriptRef) continue;
|
|
1122
1135
|
isSelected = false;
|
|
1123
1136
|
for (const [unit, amount] of assetsRequired) {
|
|
1124
1137
|
if (Object.hasOwn(utxo.assets, unit)) {
|
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;
|
|
@@ -107,7 +112,13 @@ declare function coreToOutRef(input: CML.TransactionInput): OutRef;
|
|
|
107
112
|
declare function coresToOutRefs(inputs: CML.TransactionInput[]): OutRef[];
|
|
108
113
|
declare function coreToTxOutput(output: CML.TransactionOutput): TxOutput;
|
|
109
114
|
declare function coresToTxOutputs(outputs: CML.TransactionOutput[]): TxOutput[];
|
|
110
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Returns a list of UTxOs whose total assets are equal to or greater than the asset value provided
|
|
117
|
+
* @param utxos list of available utxos
|
|
118
|
+
* @param totalAssets minimum total assets required
|
|
119
|
+
* @param includeUTxOsWithScriptRef Whether to include UTxOs with scriptRef or not. default = false
|
|
120
|
+
*/
|
|
121
|
+
declare const selectUTxOs: (utxos: UTxO[], totalAssets: Assets, includeUTxOsWithScriptRef?: boolean) => UTxO[];
|
|
111
122
|
/**
|
|
112
123
|
* Union type for specifying sorting order in function "sortUTxOs"
|
|
113
124
|
*/
|
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;
|
|
@@ -107,7 +112,13 @@ declare function coreToOutRef(input: CML.TransactionInput): OutRef;
|
|
|
107
112
|
declare function coresToOutRefs(inputs: CML.TransactionInput[]): OutRef[];
|
|
108
113
|
declare function coreToTxOutput(output: CML.TransactionOutput): TxOutput;
|
|
109
114
|
declare function coresToTxOutputs(outputs: CML.TransactionOutput[]): TxOutput[];
|
|
110
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Returns a list of UTxOs whose total assets are equal to or greater than the asset value provided
|
|
117
|
+
* @param utxos list of available utxos
|
|
118
|
+
* @param totalAssets minimum total assets required
|
|
119
|
+
* @param includeUTxOsWithScriptRef Whether to include UTxOs with scriptRef or not. default = false
|
|
120
|
+
*/
|
|
121
|
+
declare const selectUTxOs: (utxos: UTxO[], totalAssets: Assets, includeUTxOsWithScriptRef?: boolean) => UTxO[];
|
|
111
122
|
/**
|
|
112
123
|
* Union type for specifying sorting order in function "sortUTxOs"
|
|
113
124
|
*/
|
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
|
|
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
|
|
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
|
-
|
|
220
|
+
encode2(
|
|
221
|
+
encode2(
|
|
222
|
+
encodeUPLC(new UPLCProgram(program.version, appliedProgram)).toBuffer().buffer
|
|
223
|
+
)
|
|
224
|
+
)
|
|
207
225
|
);
|
|
208
226
|
}
|
|
209
227
|
|
|
@@ -1030,11 +1048,12 @@ function coresToTxOutputs(outputs) {
|
|
|
1030
1048
|
}
|
|
1031
1049
|
return result;
|
|
1032
1050
|
}
|
|
1033
|
-
var selectUTxOs = (utxos, totalAssets) => {
|
|
1051
|
+
var selectUTxOs = (utxos, totalAssets, includeUTxOsWithScriptRef = false) => {
|
|
1034
1052
|
const selectedUtxos = [];
|
|
1035
1053
|
let isSelected = false;
|
|
1036
1054
|
const assetsRequired = new Map(Object.entries(totalAssets));
|
|
1037
1055
|
for (const utxo of utxos) {
|
|
1056
|
+
if (!includeUTxOsWithScriptRef && utxo.scriptRef) continue;
|
|
1038
1057
|
isSelected = false;
|
|
1039
1058
|
for (const [unit, amount] of assetsRequired) {
|
|
1040
1059
|
if (Object.hasOwn(utxo.assets, unit)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lucid-evolution/utils",
|
|
3
|
-
"version": "0.1.
|
|
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",
|