@lucid-evolution/utils 0.1.36 → 0.1.38
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 +44 -0
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +43 -0
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -46,6 +46,7 @@ __export(src_exports, {
|
|
|
46
46
|
createCostModels: () => createCostModels,
|
|
47
47
|
credentialToAddress: () => credentialToAddress,
|
|
48
48
|
credentialToRewardAddress: () => credentialToRewardAddress,
|
|
49
|
+
datumJsonToCbor: () => datumJsonToCbor,
|
|
49
50
|
datumToHash: () => datumToHash,
|
|
50
51
|
fromLabel: () => fromLabel,
|
|
51
52
|
fromScriptRef: () => fromScriptRef,
|
|
@@ -197,6 +198,47 @@ var applyDoubleCborEncoding = (script) => {
|
|
|
197
198
|
return (0, import_core_utils.toHex)((0, import_cborg.encode)((0, import_core_utils.fromHex)(script)));
|
|
198
199
|
}
|
|
199
200
|
};
|
|
201
|
+
function datumJsonToCbor(json) {
|
|
202
|
+
const convert = (json2) => {
|
|
203
|
+
if (!isNaN(json2.int)) {
|
|
204
|
+
const plutusBigInt = CML.BigInteger.from_str(json2.int.toString());
|
|
205
|
+
return CML.PlutusData.new_integer(plutusBigInt);
|
|
206
|
+
} else if (json2.bytes || !isNaN(Number(json2.bytes))) {
|
|
207
|
+
return CML.PlutusData.new_bytes((0, import_core_utils.fromHex)(json2.bytes));
|
|
208
|
+
} else if (json2.list) {
|
|
209
|
+
const l = CML.PlutusDataList.new();
|
|
210
|
+
json2.list.forEach((v) => {
|
|
211
|
+
l.add(convert(v));
|
|
212
|
+
});
|
|
213
|
+
return CML.PlutusData.new_list(l);
|
|
214
|
+
} else if (json2.map && json2.map.length > 0 && typeof json2.map[0] === "object") {
|
|
215
|
+
const m = CML.PlutusMap.new();
|
|
216
|
+
json2.map.forEach(({ k, v }) => {
|
|
217
|
+
m.set(convert(k), convert(v));
|
|
218
|
+
});
|
|
219
|
+
return CML.PlutusData.new_map(m);
|
|
220
|
+
} else if (json2.map && typeof json2.map === "function") {
|
|
221
|
+
const l = CML.PlutusDataList.new();
|
|
222
|
+
Object.values(json2).forEach((value) => {
|
|
223
|
+
l.add(convert(value));
|
|
224
|
+
});
|
|
225
|
+
return CML.PlutusData.new_list(l);
|
|
226
|
+
} else if (!isNaN(json2.constructor)) {
|
|
227
|
+
const l = CML.PlutusDataList.new();
|
|
228
|
+
json2.fields.forEach((v) => {
|
|
229
|
+
l.add(convert(v));
|
|
230
|
+
});
|
|
231
|
+
const bigInt = CML.BigInteger.from_str(
|
|
232
|
+
json2.constructor.toString()
|
|
233
|
+
).as_u64();
|
|
234
|
+
return CML.PlutusData.new_constr_plutus_data(
|
|
235
|
+
CML.ConstrPlutusData.new(bigInt, l)
|
|
236
|
+
);
|
|
237
|
+
}
|
|
238
|
+
throw new Error("Unsupported type");
|
|
239
|
+
};
|
|
240
|
+
return convert(json).to_cbor_hex();
|
|
241
|
+
}
|
|
200
242
|
|
|
201
243
|
// src/scripts.ts
|
|
202
244
|
var import_plutus = require("@lucid-evolution/plutus");
|
|
@@ -513,6 +555,7 @@ var PROTOCOL_PARAMETERS_DEFAULT = {
|
|
|
513
555
|
coinsPerUtxoByte: 4310n,
|
|
514
556
|
collateralPercentage: 150,
|
|
515
557
|
maxCollateralInputs: 3,
|
|
558
|
+
minFeeRefScriptCostPerByte: 15,
|
|
516
559
|
costModels: {
|
|
517
560
|
PlutusV1: {
|
|
518
561
|
"0": 100788,
|
|
@@ -1506,6 +1549,7 @@ var stringify = (data) => JSON.stringify(
|
|
|
1506
1549
|
createCostModels,
|
|
1507
1550
|
credentialToAddress,
|
|
1508
1551
|
credentialToRewardAddress,
|
|
1552
|
+
datumJsonToCbor,
|
|
1509
1553
|
datumToHash,
|
|
1510
1554
|
fromLabel,
|
|
1511
1555
|
fromScriptRef,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _effect_schema_AST from '@effect/schema/AST';
|
|
2
|
-
import { Native, Script, Network, Credential, RewardAddress, CertificateValidator, WithdrawalValidator, AddressDetails, CostModels, ProtocolParameters, Address, ScriptHash, KeyHash,
|
|
2
|
+
import { Native, Script, Network, Credential, RewardAddress, CertificateValidator, WithdrawalValidator, AddressDetails, DatumJson, Datum, CostModels, ProtocolParameters, Address, ScriptHash, KeyHash, DatumHash, PrivateKey, PublicKey, SpendingValidator, Validator, MintingPolicy, PolicyId, Exact, UnixTime, Slot, UTxO, OutRef, TxOutput, Assets, Unit } from '@lucid-evolution/core-types';
|
|
3
3
|
import * as CML from '@anastasia-labs/cardano-multiplatform-lib-nodejs';
|
|
4
4
|
import { Data } from '@lucid-evolution/plutus';
|
|
5
5
|
|
|
@@ -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 function datumJsonToCbor(json: DatumJson): Datum;
|
|
69
70
|
|
|
70
71
|
declare function createCostModels(costModels: CostModels): CML.CostModels;
|
|
71
72
|
declare const PROTOCOL_PARAMETERS_DEFAULT: ProtocolParameters;
|
|
@@ -184,4 +185,4 @@ declare function getUniqueTokenName(utxo: UTxO): Promise<string>;
|
|
|
184
185
|
|
|
185
186
|
declare const stringify: (data: any) => string;
|
|
186
187
|
|
|
187
|
-
export { type CMLNative, PROTOCOL_PARAMETERS_DEFAULT, type SortOrder, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, assetsToValue, calculateMinLovelaceFromUTxO, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumToHash, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, getInputIndices, getUniqueTokenName, isEqualUTxO, keyHashToCredential, mintingPolicyToId, networkToId, parseCMLNative, paymentCredentialOf, scriptFromCMLNative, scriptFromNative, scriptHashToCredential, selectUTxOs, slotToUnixTime, sortUTxOs, stakeCredentialOf, stringify, toCMLNativeScript, toLabel, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
|
|
188
|
+
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, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, getInputIndices, getUniqueTokenName, isEqualUTxO, keyHashToCredential, mintingPolicyToId, networkToId, parseCMLNative, paymentCredentialOf, scriptFromCMLNative, scriptFromNative, scriptHashToCredential, selectUTxOs, slotToUnixTime, sortUTxOs, stakeCredentialOf, stringify, toCMLNativeScript, toLabel, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as _effect_schema_AST from '@effect/schema/AST';
|
|
2
|
-
import { Native, Script, Network, Credential, RewardAddress, CertificateValidator, WithdrawalValidator, AddressDetails, CostModels, ProtocolParameters, Address, ScriptHash, KeyHash,
|
|
2
|
+
import { Native, Script, Network, Credential, RewardAddress, CertificateValidator, WithdrawalValidator, AddressDetails, DatumJson, Datum, CostModels, ProtocolParameters, Address, ScriptHash, KeyHash, DatumHash, PrivateKey, PublicKey, SpendingValidator, Validator, MintingPolicy, PolicyId, Exact, UnixTime, Slot, UTxO, OutRef, TxOutput, Assets, Unit } from '@lucid-evolution/core-types';
|
|
3
3
|
import * as CML from '@anastasia-labs/cardano-multiplatform-lib-nodejs';
|
|
4
4
|
import { Data } from '@lucid-evolution/plutus';
|
|
5
5
|
|
|
@@ -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 function datumJsonToCbor(json: DatumJson): Datum;
|
|
69
70
|
|
|
70
71
|
declare function createCostModels(costModels: CostModels): CML.CostModels;
|
|
71
72
|
declare const PROTOCOL_PARAMETERS_DEFAULT: ProtocolParameters;
|
|
@@ -184,4 +185,4 @@ declare function getUniqueTokenName(utxo: UTxO): Promise<string>;
|
|
|
184
185
|
|
|
185
186
|
declare const stringify: (data: any) => string;
|
|
186
187
|
|
|
187
|
-
export { type CMLNative, PROTOCOL_PARAMETERS_DEFAULT, type SortOrder, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, assetsToValue, calculateMinLovelaceFromUTxO, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumToHash, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, getInputIndices, getUniqueTokenName, isEqualUTxO, keyHashToCredential, mintingPolicyToId, networkToId, parseCMLNative, paymentCredentialOf, scriptFromCMLNative, scriptFromNative, scriptHashToCredential, selectUTxOs, slotToUnixTime, sortUTxOs, stakeCredentialOf, stringify, toCMLNativeScript, toLabel, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
|
|
188
|
+
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, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, getInputIndices, getUniqueTokenName, isEqualUTxO, keyHashToCredential, mintingPolicyToId, networkToId, parseCMLNative, paymentCredentialOf, scriptFromCMLNative, scriptFromNative, scriptHashToCredential, selectUTxOs, slotToUnixTime, sortUTxOs, stakeCredentialOf, stringify, toCMLNativeScript, toLabel, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
|
package/dist/index.js
CHANGED
|
@@ -109,6 +109,47 @@ var applyDoubleCborEncoding = (script) => {
|
|
|
109
109
|
return toHex(encode(fromHex(script)));
|
|
110
110
|
}
|
|
111
111
|
};
|
|
112
|
+
function datumJsonToCbor(json) {
|
|
113
|
+
const convert = (json2) => {
|
|
114
|
+
if (!isNaN(json2.int)) {
|
|
115
|
+
const plutusBigInt = CML.BigInteger.from_str(json2.int.toString());
|
|
116
|
+
return CML.PlutusData.new_integer(plutusBigInt);
|
|
117
|
+
} else if (json2.bytes || !isNaN(Number(json2.bytes))) {
|
|
118
|
+
return CML.PlutusData.new_bytes(fromHex(json2.bytes));
|
|
119
|
+
} else if (json2.list) {
|
|
120
|
+
const l = CML.PlutusDataList.new();
|
|
121
|
+
json2.list.forEach((v) => {
|
|
122
|
+
l.add(convert(v));
|
|
123
|
+
});
|
|
124
|
+
return CML.PlutusData.new_list(l);
|
|
125
|
+
} else if (json2.map && json2.map.length > 0 && typeof json2.map[0] === "object") {
|
|
126
|
+
const m = CML.PlutusMap.new();
|
|
127
|
+
json2.map.forEach(({ k, v }) => {
|
|
128
|
+
m.set(convert(k), convert(v));
|
|
129
|
+
});
|
|
130
|
+
return CML.PlutusData.new_map(m);
|
|
131
|
+
} else if (json2.map && typeof json2.map === "function") {
|
|
132
|
+
const l = CML.PlutusDataList.new();
|
|
133
|
+
Object.values(json2).forEach((value) => {
|
|
134
|
+
l.add(convert(value));
|
|
135
|
+
});
|
|
136
|
+
return CML.PlutusData.new_list(l);
|
|
137
|
+
} else if (!isNaN(json2.constructor)) {
|
|
138
|
+
const l = CML.PlutusDataList.new();
|
|
139
|
+
json2.fields.forEach((v) => {
|
|
140
|
+
l.add(convert(v));
|
|
141
|
+
});
|
|
142
|
+
const bigInt = CML.BigInteger.from_str(
|
|
143
|
+
json2.constructor.toString()
|
|
144
|
+
).as_u64();
|
|
145
|
+
return CML.PlutusData.new_constr_plutus_data(
|
|
146
|
+
CML.ConstrPlutusData.new(bigInt, l)
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
throw new Error("Unsupported type");
|
|
150
|
+
};
|
|
151
|
+
return convert(json).to_cbor_hex();
|
|
152
|
+
}
|
|
112
153
|
|
|
113
154
|
// src/scripts.ts
|
|
114
155
|
import { Data } from "@lucid-evolution/plutus";
|
|
@@ -431,6 +472,7 @@ var PROTOCOL_PARAMETERS_DEFAULT = {
|
|
|
431
472
|
coinsPerUtxoByte: 4310n,
|
|
432
473
|
collateralPercentage: 150,
|
|
433
474
|
maxCollateralInputs: 3,
|
|
475
|
+
minFeeRefScriptCostPerByte: 15,
|
|
434
476
|
costModels: {
|
|
435
477
|
PlutusV1: {
|
|
436
478
|
"0": 100788,
|
|
@@ -1427,6 +1469,7 @@ export {
|
|
|
1427
1469
|
createCostModels,
|
|
1428
1470
|
credentialToAddress,
|
|
1429
1471
|
credentialToRewardAddress,
|
|
1472
|
+
datumJsonToCbor,
|
|
1430
1473
|
datumToHash,
|
|
1431
1474
|
fromLabel,
|
|
1432
1475
|
fromScriptRef,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lucid-evolution/utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.38",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"@emurgo/cardano-serialization-lib-nodejs": "@emurgo/cardano-serialization-lib-browser"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@anastasia-labs/cardano-multiplatform-lib-browser": "^
|
|
30
|
-
"@anastasia-labs/cardano-multiplatform-lib-nodejs": "^
|
|
29
|
+
"@anastasia-labs/cardano-multiplatform-lib-browser": "^6.0.1-2",
|
|
30
|
+
"@anastasia-labs/cardano-multiplatform-lib-nodejs": "^6.0.1-2",
|
|
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",
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
"bip39": "^3.1.0",
|
|
37
37
|
"cborg": "^4.2.0",
|
|
38
38
|
"effect": "^3.1.2",
|
|
39
|
-
"@lucid-evolution/core-types": "0.1.
|
|
40
|
-
"@lucid-evolution/core-utils": "0.1.
|
|
39
|
+
"@lucid-evolution/core-types": "0.1.16",
|
|
40
|
+
"@lucid-evolution/core-utils": "0.1.14",
|
|
41
41
|
"@lucid-evolution/crc8": "0.1.8",
|
|
42
|
-
"@lucid-evolution/plutus": "0.1.
|
|
42
|
+
"@lucid-evolution/plutus": "0.1.22",
|
|
43
43
|
"@lucid-evolution/uplc": "0.2.11"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|