@lucid-evolution/utils 0.1.58 → 0.1.60
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 +30 -0
- package/dist/index.d.cts +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +28 -0
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -30,11 +30,13 @@ 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,
|
|
36
37
|
applyDoubleCborEncoding: () => applyDoubleCborEncoding,
|
|
37
38
|
applyParamsToScript: () => applyParamsToScript,
|
|
39
|
+
applySingleCborEncoding: () => applySingleCborEncoding,
|
|
38
40
|
assetsToValue: () => assetsToValue,
|
|
39
41
|
calculateMinLovelaceFromUTxO: () => calculateMinLovelaceFromUTxO,
|
|
40
42
|
coreToOutRef: () => coreToOutRef,
|
|
@@ -206,6 +208,32 @@ var applyDoubleCborEncoding = (script) => {
|
|
|
206
208
|
}
|
|
207
209
|
}
|
|
208
210
|
};
|
|
211
|
+
var applySingleCborEncoding = (script) => {
|
|
212
|
+
try {
|
|
213
|
+
(0, import_cbor_x.decode)((0, import_cbor_x.decode)((0, import_core_utils.fromHex)(script)));
|
|
214
|
+
return (0, import_core_utils.toHex)((0, import_cbor_x.decode)((0, import_core_utils.fromHex)(script)));
|
|
215
|
+
} catch (error) {
|
|
216
|
+
try {
|
|
217
|
+
(0, import_cbor_x.decode)((0, import_core_utils.fromHex)(script));
|
|
218
|
+
return script;
|
|
219
|
+
} catch (error2) {
|
|
220
|
+
return (0, import_core_utils.toHex)(Uint8Array.from((0, import_cbor_x.encode)((0, import_core_utils.fromHex)(script).buffer)));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
var CBOREncodingLevel = (script) => {
|
|
225
|
+
try {
|
|
226
|
+
(0, import_cbor_x.decode)((0, import_cbor_x.decode)((0, import_core_utils.fromHex)(script)));
|
|
227
|
+
return "double";
|
|
228
|
+
} catch (error) {
|
|
229
|
+
try {
|
|
230
|
+
(0, import_cbor_x.decode)((0, import_core_utils.fromHex)(script));
|
|
231
|
+
return "single";
|
|
232
|
+
} catch (error2) {
|
|
233
|
+
throw new Error("Script is not CBOR-encoded or invalid format.");
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
};
|
|
209
237
|
function datumJsonToCbor(json) {
|
|
210
238
|
const convert = (json2) => {
|
|
211
239
|
if (!isNaN(json2.int)) {
|
|
@@ -1656,11 +1684,13 @@ var fromCMLRedeemerTag = (tag) => {
|
|
|
1656
1684
|
};
|
|
1657
1685
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1658
1686
|
0 && (module.exports = {
|
|
1687
|
+
CBOREncodingLevel,
|
|
1659
1688
|
PROTOCOL_PARAMETERS_DEFAULT,
|
|
1660
1689
|
addAssets,
|
|
1661
1690
|
addressFromHexOrBech32,
|
|
1662
1691
|
applyDoubleCborEncoding,
|
|
1663
1692
|
applyParamsToScript,
|
|
1693
|
+
applySingleCborEncoding,
|
|
1664
1694
|
assetsToValue,
|
|
1665
1695
|
calculateMinLovelaceFromUTxO,
|
|
1666
1696
|
coreToOutRef,
|
package/dist/index.d.cts
CHANGED
|
@@ -66,6 +66,8 @@ 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 applySingleCborEncoding: (script: string) => string;
|
|
70
|
+
declare const CBOREncodingLevel: (script: string) => "double" | "single";
|
|
69
71
|
declare function datumJsonToCbor(json: DatumJson): Datum;
|
|
70
72
|
|
|
71
73
|
declare function createCostModels(costModels: CostModels): CML.CostModels;
|
|
@@ -100,6 +102,15 @@ declare function mintingPolicyToId(mintingPolicy: MintingPolicy): PolicyId;
|
|
|
100
102
|
*/
|
|
101
103
|
declare function applyParamsToScript<T extends unknown[] = Data[]>(plutusScript: string, params: Exact<[...T]>, type?: T): string;
|
|
102
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Converts unix time to slot based on the network. For "Custom" network
|
|
107
|
+
* it is advisable use `unixTimeToSlot` method from `LucidEvolution`
|
|
108
|
+
* instance to avoid uninitialized `SLOT_CONFIG_NETWORK` issue. More details
|
|
109
|
+
* on the issue can be found here https://github.com/Anastasia-Labs/lucid-evolution/pull/443
|
|
110
|
+
* @param network
|
|
111
|
+
* @param unixTime
|
|
112
|
+
* @returns Slot
|
|
113
|
+
*/
|
|
103
114
|
declare function unixTimeToSlot(network: Network, unixTime: UnixTime): Slot;
|
|
104
115
|
declare function slotToUnixTime(network: Network, slot: Slot): UnixTime;
|
|
105
116
|
|
|
@@ -193,4 +204,4 @@ declare const stringify: (data: any) => string;
|
|
|
193
204
|
declare const toCMLRedeemerTag: (tag: string) => CML.RedeemerTag;
|
|
194
205
|
declare const fromCMLRedeemerTag: (tag: CML.RedeemerTag) => RedeemerTag;
|
|
195
206
|
|
|
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 };
|
|
207
|
+
export { CBOREncodingLevel, type CMLNative, PROTOCOL_PARAMETERS_DEFAULT, type SortOrder, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, applySingleCborEncoding, 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,8 @@ 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 applySingleCborEncoding: (script: string) => string;
|
|
70
|
+
declare const CBOREncodingLevel: (script: string) => "double" | "single";
|
|
69
71
|
declare function datumJsonToCbor(json: DatumJson): Datum;
|
|
70
72
|
|
|
71
73
|
declare function createCostModels(costModels: CostModels): CML.CostModels;
|
|
@@ -100,6 +102,15 @@ declare function mintingPolicyToId(mintingPolicy: MintingPolicy): PolicyId;
|
|
|
100
102
|
*/
|
|
101
103
|
declare function applyParamsToScript<T extends unknown[] = Data[]>(plutusScript: string, params: Exact<[...T]>, type?: T): string;
|
|
102
104
|
|
|
105
|
+
/**
|
|
106
|
+
* Converts unix time to slot based on the network. For "Custom" network
|
|
107
|
+
* it is advisable use `unixTimeToSlot` method from `LucidEvolution`
|
|
108
|
+
* instance to avoid uninitialized `SLOT_CONFIG_NETWORK` issue. More details
|
|
109
|
+
* on the issue can be found here https://github.com/Anastasia-Labs/lucid-evolution/pull/443
|
|
110
|
+
* @param network
|
|
111
|
+
* @param unixTime
|
|
112
|
+
* @returns Slot
|
|
113
|
+
*/
|
|
103
114
|
declare function unixTimeToSlot(network: Network, unixTime: UnixTime): Slot;
|
|
104
115
|
declare function slotToUnixTime(network: Network, slot: Slot): UnixTime;
|
|
105
116
|
|
|
@@ -193,4 +204,4 @@ declare const stringify: (data: any) => string;
|
|
|
193
204
|
declare const toCMLRedeemerTag: (tag: string) => CML.RedeemerTag;
|
|
194
205
|
declare const fromCMLRedeemerTag: (tag: CML.RedeemerTag) => RedeemerTag;
|
|
195
206
|
|
|
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 };
|
|
207
|
+
export { CBOREncodingLevel, type CMLNative, PROTOCOL_PARAMETERS_DEFAULT, type SortOrder, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, applySingleCborEncoding, 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
|
@@ -114,6 +114,32 @@ var applyDoubleCborEncoding = (script) => {
|
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
};
|
|
117
|
+
var applySingleCborEncoding = (script) => {
|
|
118
|
+
try {
|
|
119
|
+
decode(decode(fromHex(script)));
|
|
120
|
+
return toHex(decode(fromHex(script)));
|
|
121
|
+
} catch (error) {
|
|
122
|
+
try {
|
|
123
|
+
decode(fromHex(script));
|
|
124
|
+
return script;
|
|
125
|
+
} catch (error2) {
|
|
126
|
+
return toHex(Uint8Array.from(encode(fromHex(script).buffer)));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
var CBOREncodingLevel = (script) => {
|
|
131
|
+
try {
|
|
132
|
+
decode(decode(fromHex(script)));
|
|
133
|
+
return "double";
|
|
134
|
+
} catch (error) {
|
|
135
|
+
try {
|
|
136
|
+
decode(fromHex(script));
|
|
137
|
+
return "single";
|
|
138
|
+
} catch (error2) {
|
|
139
|
+
throw new Error("Script is not CBOR-encoded or invalid format.");
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
};
|
|
117
143
|
function datumJsonToCbor(json) {
|
|
118
144
|
const convert = (json2) => {
|
|
119
145
|
if (!isNaN(json2.int)) {
|
|
@@ -1573,11 +1599,13 @@ var fromCMLRedeemerTag = (tag) => {
|
|
|
1573
1599
|
}
|
|
1574
1600
|
};
|
|
1575
1601
|
export {
|
|
1602
|
+
CBOREncodingLevel,
|
|
1576
1603
|
PROTOCOL_PARAMETERS_DEFAULT,
|
|
1577
1604
|
addAssets,
|
|
1578
1605
|
addressFromHexOrBech32,
|
|
1579
1606
|
applyDoubleCborEncoding,
|
|
1580
1607
|
applyParamsToScript,
|
|
1608
|
+
applySingleCborEncoding,
|
|
1581
1609
|
assetsToValue,
|
|
1582
1610
|
calculateMinLovelaceFromUTxO,
|
|
1583
1611
|
coreToOutRef,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lucid-evolution/utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.60",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"effect": "^3.10.4",
|
|
37
37
|
"@lucid-evolution/core-types": "0.1.21",
|
|
38
38
|
"@lucid-evolution/core-utils": "0.1.16",
|
|
39
|
-
"@lucid-evolution/crc8": "0.1.8",
|
|
40
39
|
"@lucid-evolution/plutus": "0.1.28",
|
|
41
|
-
"@lucid-evolution/uplc": "0.2.
|
|
40
|
+
"@lucid-evolution/uplc": "0.2.18",
|
|
41
|
+
"@lucid-evolution/crc8": "0.1.8"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/node": "^20.12.8",
|