@lucid-evolution/utils 0.1.9 → 0.1.11
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 +19 -8
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +13 -3
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -34,6 +34,7 @@ __export(src_exports, {
|
|
|
34
34
|
addAssets: () => addAssets,
|
|
35
35
|
addressFromHexOrBech32: () => addressFromHexOrBech32,
|
|
36
36
|
applyDoubleCborEncoding: () => applyDoubleCborEncoding,
|
|
37
|
+
applyParamsToScript: () => applyParamsToScript,
|
|
37
38
|
assetsToValue: () => assetsToValue,
|
|
38
39
|
coreToOutRef: () => coreToOutRef,
|
|
39
40
|
coreToTxOutput: () => coreToTxOutput,
|
|
@@ -148,6 +149,9 @@ var applyDoubleCborEncoding = (script) => {
|
|
|
148
149
|
};
|
|
149
150
|
|
|
150
151
|
// src/scripts.ts
|
|
152
|
+
var import_plutus = require("@lucid-evolution/plutus");
|
|
153
|
+
var UPLC = __toESM(require("@lucid-evolution/uplc"), 1);
|
|
154
|
+
var import_core_utils2 = require("@lucid-evolution/core-utils");
|
|
151
155
|
function validatorToAddress(network, validator, stakeCredential) {
|
|
152
156
|
const validatorHash = validatorToScriptHash(validator);
|
|
153
157
|
if (stakeCredential) {
|
|
@@ -245,6 +249,12 @@ function nativeScriptFromJson(nativeScript) {
|
|
|
245
249
|
).to_cbor_hex()
|
|
246
250
|
};
|
|
247
251
|
}
|
|
252
|
+
function applyParamsToScript(plutusScript, params, type) {
|
|
253
|
+
const p = type ? import_plutus.Data.castTo(params, type) : params;
|
|
254
|
+
return (0, import_core_utils2.toHex)(
|
|
255
|
+
UPLC.apply_params_to_script((0, import_core_utils2.fromHex)(import_plutus.Data.to(p)), (0, import_core_utils2.fromHex)(plutusScript))
|
|
256
|
+
);
|
|
257
|
+
}
|
|
248
258
|
|
|
249
259
|
// src/address.ts
|
|
250
260
|
function addressFromHexOrBech32(address) {
|
|
@@ -878,7 +888,7 @@ function toPublicKey(privateKey) {
|
|
|
878
888
|
}
|
|
879
889
|
|
|
880
890
|
// src/label.ts
|
|
881
|
-
var
|
|
891
|
+
var import_core_utils3 = require("@lucid-evolution/core-utils");
|
|
882
892
|
var import_crc8 = require("@lucid-evolution/crc8");
|
|
883
893
|
function toLabel(num) {
|
|
884
894
|
if (num < 0 || num > 65535) {
|
|
@@ -899,20 +909,20 @@ function fromLabel(label) {
|
|
|
899
909
|
return check === checksum(numHex) ? num : null;
|
|
900
910
|
}
|
|
901
911
|
function checksum(num) {
|
|
902
|
-
return (0, import_crc8.crc8)((0,
|
|
912
|
+
return (0, import_crc8.crc8)((0, import_core_utils3.fromHex)(num)).toString(16).padStart(2, "0");
|
|
903
913
|
}
|
|
904
914
|
|
|
905
915
|
// src/time.ts
|
|
906
|
-
var
|
|
916
|
+
var import_plutus2 = require("@lucid-evolution/plutus");
|
|
907
917
|
function unixTimeToSlot(network, unixTime) {
|
|
908
|
-
return (0,
|
|
918
|
+
return (0, import_plutus2.unixTimeToEnclosingSlot)(unixTime, import_plutus2.SLOT_CONFIG_NETWORK[network]);
|
|
909
919
|
}
|
|
910
920
|
function slotToUnixTime(network, slot) {
|
|
911
|
-
return (0,
|
|
921
|
+
return (0, import_plutus2.slotToBeginUnixTime)(slot, import_plutus2.SLOT_CONFIG_NETWORK[network]);
|
|
912
922
|
}
|
|
913
923
|
|
|
914
924
|
// src/value.ts
|
|
915
|
-
var
|
|
925
|
+
var import_core_utils4 = require("@lucid-evolution/core-utils");
|
|
916
926
|
function valueToAssets(value) {
|
|
917
927
|
const assets = {};
|
|
918
928
|
assets["lovelace"] = value.coin();
|
|
@@ -935,7 +945,7 @@ function valueToAssets(value) {
|
|
|
935
945
|
}
|
|
936
946
|
function assetsToValue(assets) {
|
|
937
947
|
const multiAsset = CML.MultiAsset.new();
|
|
938
|
-
const lovelace = assets["lovelace"];
|
|
948
|
+
const lovelace = assets["lovelace"] ? assets["lovelace"] : 0n;
|
|
939
949
|
const units = Object.keys(assets);
|
|
940
950
|
const policies = Array.from(
|
|
941
951
|
new Set(
|
|
@@ -947,7 +957,7 @@ function assetsToValue(assets) {
|
|
|
947
957
|
const assetsValue = CML.MapAssetNameToCoin.new();
|
|
948
958
|
for (const unit of policyUnits) {
|
|
949
959
|
assetsValue.insert(
|
|
950
|
-
CML.AssetName.from_str((0,
|
|
960
|
+
CML.AssetName.from_str((0, import_core_utils4.toText)(unit.slice(56))),
|
|
951
961
|
BigInt(assets[unit])
|
|
952
962
|
);
|
|
953
963
|
}
|
|
@@ -1080,6 +1090,7 @@ function coresToTxOutputs(outputs) {
|
|
|
1080
1090
|
addAssets,
|
|
1081
1091
|
addressFromHexOrBech32,
|
|
1082
1092
|
applyDoubleCborEncoding,
|
|
1093
|
+
applyParamsToScript,
|
|
1083
1094
|
assetsToValue,
|
|
1084
1095
|
coreToOutRef,
|
|
1085
1096
|
coreToTxOutput,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Native, Script, Network, Credential, RewardAddress, CertificateValidator, WithdrawalValidator, AddressDetails, CostModels, ProtocolParameters, Address, ScriptHash, KeyHash, Datum, DatumHash, PrivateKey, PublicKey, SpendingValidator, Validator, MintingPolicy, PolicyId, NativeScript, UnixTime, Slot, UTxO, OutRef, TxOutput, Assets, Unit } from '@lucid-evolution/core-types';
|
|
1
|
+
import { Native, Script, Network, Credential, RewardAddress, CertificateValidator, WithdrawalValidator, AddressDetails, CostModels, ProtocolParameters, Address, ScriptHash, KeyHash, Datum, DatumHash, PrivateKey, PublicKey, SpendingValidator, Validator, MintingPolicy, PolicyId, NativeScript, Exact, UnixTime, Slot, UTxO, OutRef, TxOutput, Assets, Unit } from '@lucid-evolution/core-types';
|
|
2
2
|
import * as CML from '@dcspark/cardano-multiplatform-lib-nodejs';
|
|
3
|
+
import { Data } from '@lucid-evolution/plutus';
|
|
3
4
|
|
|
4
5
|
declare const toNativeScript: (native: Native) => CML.NativeScript;
|
|
5
6
|
declare const nativeJSFromJson: (native: Native) => Script;
|
|
@@ -43,6 +44,7 @@ declare function nativeFromJson(nativeScript: Native): Script;
|
|
|
43
44
|
* It follows this Json format: https://github.com/input-output-hk/cardano-node/blob/master/doc/reference/simple-scripts.md
|
|
44
45
|
*/
|
|
45
46
|
declare function nativeScriptFromJson(nativeScript: NativeScript): Script;
|
|
47
|
+
declare function applyParamsToScript<T extends unknown[] = Data[]>(plutusScript: string, params: Exact<[...T]>, type?: T): string;
|
|
46
48
|
|
|
47
49
|
declare function unixTimeToSlot(network: Network, unixTime: UnixTime): Slot;
|
|
48
50
|
declare function slotToUnixTime(network: Network, slot: Slot): UnixTime;
|
|
@@ -76,4 +78,4 @@ declare function fromUnit(unit: Unit): {
|
|
|
76
78
|
declare function toUnit(policyId: PolicyId, name?: string | null, label?: number | null): Unit;
|
|
77
79
|
declare function addAssets(...assets: Assets[]): Assets;
|
|
78
80
|
|
|
79
|
-
export { PROTOCOL_PARAMETERS_DEFAULT, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, assetsToValue, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumToHash, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, keyHashToCredential, mintingPolicyToId, nativeFromJson, nativeJSFromJson, nativeScriptFromJson, networkToId, paymentCredentialOf, scriptHashToCredential, slotToUnixTime, stakeCredentialOf, toLabel, toNativeScript, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
|
|
81
|
+
export { PROTOCOL_PARAMETERS_DEFAULT, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, assetsToValue, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumToHash, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, keyHashToCredential, mintingPolicyToId, nativeFromJson, nativeJSFromJson, nativeScriptFromJson, networkToId, paymentCredentialOf, scriptHashToCredential, slotToUnixTime, stakeCredentialOf, toLabel, toNativeScript, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Native, Script, Network, Credential, RewardAddress, CertificateValidator, WithdrawalValidator, AddressDetails, CostModels, ProtocolParameters, Address, ScriptHash, KeyHash, Datum, DatumHash, PrivateKey, PublicKey, SpendingValidator, Validator, MintingPolicy, PolicyId, NativeScript, UnixTime, Slot, UTxO, OutRef, TxOutput, Assets, Unit } from '@lucid-evolution/core-types';
|
|
1
|
+
import { Native, Script, Network, Credential, RewardAddress, CertificateValidator, WithdrawalValidator, AddressDetails, CostModels, ProtocolParameters, Address, ScriptHash, KeyHash, Datum, DatumHash, PrivateKey, PublicKey, SpendingValidator, Validator, MintingPolicy, PolicyId, NativeScript, Exact, UnixTime, Slot, UTxO, OutRef, TxOutput, Assets, Unit } from '@lucid-evolution/core-types';
|
|
2
2
|
import * as CML from '@dcspark/cardano-multiplatform-lib-nodejs';
|
|
3
|
+
import { Data } from '@lucid-evolution/plutus';
|
|
3
4
|
|
|
4
5
|
declare const toNativeScript: (native: Native) => CML.NativeScript;
|
|
5
6
|
declare const nativeJSFromJson: (native: Native) => Script;
|
|
@@ -43,6 +44,7 @@ declare function nativeFromJson(nativeScript: Native): Script;
|
|
|
43
44
|
* It follows this Json format: https://github.com/input-output-hk/cardano-node/blob/master/doc/reference/simple-scripts.md
|
|
44
45
|
*/
|
|
45
46
|
declare function nativeScriptFromJson(nativeScript: NativeScript): Script;
|
|
47
|
+
declare function applyParamsToScript<T extends unknown[] = Data[]>(plutusScript: string, params: Exact<[...T]>, type?: T): string;
|
|
46
48
|
|
|
47
49
|
declare function unixTimeToSlot(network: Network, unixTime: UnixTime): Slot;
|
|
48
50
|
declare function slotToUnixTime(network: Network, slot: Slot): UnixTime;
|
|
@@ -76,4 +78,4 @@ declare function fromUnit(unit: Unit): {
|
|
|
76
78
|
declare function toUnit(policyId: PolicyId, name?: string | null, label?: number | null): Unit;
|
|
77
79
|
declare function addAssets(...assets: Assets[]): Assets;
|
|
78
80
|
|
|
79
|
-
export { PROTOCOL_PARAMETERS_DEFAULT, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, assetsToValue, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumToHash, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, keyHashToCredential, mintingPolicyToId, nativeFromJson, nativeJSFromJson, nativeScriptFromJson, networkToId, paymentCredentialOf, scriptHashToCredential, slotToUnixTime, stakeCredentialOf, toLabel, toNativeScript, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
|
|
81
|
+
export { PROTOCOL_PARAMETERS_DEFAULT, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, assetsToValue, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumToHash, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, keyHashToCredential, mintingPolicyToId, nativeFromJson, nativeJSFromJson, nativeScriptFromJson, networkToId, paymentCredentialOf, scriptHashToCredential, slotToUnixTime, stakeCredentialOf, toLabel, toNativeScript, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
|
package/dist/index.js
CHANGED
|
@@ -68,6 +68,9 @@ var applyDoubleCborEncoding = (script) => {
|
|
|
68
68
|
};
|
|
69
69
|
|
|
70
70
|
// src/scripts.ts
|
|
71
|
+
import { Data } from "@lucid-evolution/plutus";
|
|
72
|
+
import * as UPLC from "@lucid-evolution/uplc";
|
|
73
|
+
import { fromHex as fromHex2, toHex as toHex2 } from "@lucid-evolution/core-utils";
|
|
71
74
|
function validatorToAddress(network, validator, stakeCredential) {
|
|
72
75
|
const validatorHash = validatorToScriptHash(validator);
|
|
73
76
|
if (stakeCredential) {
|
|
@@ -165,6 +168,12 @@ function nativeScriptFromJson(nativeScript) {
|
|
|
165
168
|
).to_cbor_hex()
|
|
166
169
|
};
|
|
167
170
|
}
|
|
171
|
+
function applyParamsToScript(plutusScript, params, type) {
|
|
172
|
+
const p = type ? Data.castTo(params, type) : params;
|
|
173
|
+
return toHex2(
|
|
174
|
+
UPLC.apply_params_to_script(fromHex2(Data.to(p)), fromHex2(plutusScript))
|
|
175
|
+
);
|
|
176
|
+
}
|
|
168
177
|
|
|
169
178
|
// src/address.ts
|
|
170
179
|
function addressFromHexOrBech32(address) {
|
|
@@ -798,7 +807,7 @@ function toPublicKey(privateKey) {
|
|
|
798
807
|
}
|
|
799
808
|
|
|
800
809
|
// src/label.ts
|
|
801
|
-
import { fromHex as
|
|
810
|
+
import { fromHex as fromHex3 } from "@lucid-evolution/core-utils";
|
|
802
811
|
import { crc8 } from "@lucid-evolution/crc8";
|
|
803
812
|
function toLabel(num) {
|
|
804
813
|
if (num < 0 || num > 65535) {
|
|
@@ -819,7 +828,7 @@ function fromLabel(label) {
|
|
|
819
828
|
return check === checksum(numHex) ? num : null;
|
|
820
829
|
}
|
|
821
830
|
function checksum(num) {
|
|
822
|
-
return crc8(
|
|
831
|
+
return crc8(fromHex3(num)).toString(16).padStart(2, "0");
|
|
823
832
|
}
|
|
824
833
|
|
|
825
834
|
// src/time.ts
|
|
@@ -859,7 +868,7 @@ function valueToAssets(value) {
|
|
|
859
868
|
}
|
|
860
869
|
function assetsToValue(assets) {
|
|
861
870
|
const multiAsset = CML.MultiAsset.new();
|
|
862
|
-
const lovelace = assets["lovelace"];
|
|
871
|
+
const lovelace = assets["lovelace"] ? assets["lovelace"] : 0n;
|
|
863
872
|
const units = Object.keys(assets);
|
|
864
873
|
const policies = Array.from(
|
|
865
874
|
new Set(
|
|
@@ -1003,6 +1012,7 @@ export {
|
|
|
1003
1012
|
addAssets,
|
|
1004
1013
|
addressFromHexOrBech32,
|
|
1005
1014
|
applyDoubleCborEncoding,
|
|
1015
|
+
applyParamsToScript,
|
|
1006
1016
|
assetsToValue,
|
|
1007
1017
|
coreToOutRef,
|
|
1008
1018
|
coreToTxOutput,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lucid-evolution/utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -32,7 +32,8 @@
|
|
|
32
32
|
"@lucid-evolution/core-types": "0.1.6",
|
|
33
33
|
"@lucid-evolution/core-utils": "0.1.6",
|
|
34
34
|
"@lucid-evolution/crc8": "0.1.6",
|
|
35
|
-
"@lucid-evolution/plutus": "0.1.9"
|
|
35
|
+
"@lucid-evolution/plutus": "0.1.9",
|
|
36
|
+
"@lucid-evolution/uplc": "0.2.5"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
39
|
"@types/node": "^20.12.8",
|