@lucid-evolution/utils 0.1.45 → 0.1.47

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
@@ -67,6 +67,7 @@ __export(src_exports, {
67
67
  scriptHashToCredential: () => scriptHashToCredential,
68
68
  selectUTxOs: () => selectUTxOs,
69
69
  slotToUnixTime: () => slotToUnixTime,
70
+ sortCanonical: () => sortCanonical,
70
71
  sortUTxOs: () => sortUTxOs,
71
72
  stakeCredentialOf: () => stakeCredentialOf,
72
73
  stringify: () => stringify,
@@ -1286,6 +1287,7 @@ function slotToUnixTime(network, slot) {
1286
1287
 
1287
1288
  // src/value.ts
1288
1289
  var import_core_utils4 = require("@lucid-evolution/core-utils");
1290
+ var import_effect = require("effect");
1289
1291
  function valueToAssets(value) {
1290
1292
  const assets = {};
1291
1293
  assets["lovelace"] = value.coin();
@@ -1370,6 +1372,23 @@ async function getUniqueTokenName(utxo) {
1370
1372
  const hash = new Uint8Array(await crypto.subtle.digest("SHA3-256", data));
1371
1373
  return (0, import_core_utils4.toHex)(hash);
1372
1374
  }
1375
+ var sortCanonical = (assets) => (0, import_effect.pipe)(
1376
+ Object.entries(assets).sort(([aUnit], [bUnit]) => {
1377
+ const a = fromUnit(aUnit);
1378
+ const b = fromUnit(bUnit);
1379
+ if (a.policyId.length !== b.policyId.length)
1380
+ return a.policyId.length - b.policyId.length;
1381
+ if (a.policyId === b.policyId) {
1382
+ const aAssetName = a.assetName || "";
1383
+ const bAssetName = b.assetName || "";
1384
+ if (aAssetName.length !== bAssetName.length)
1385
+ return aAssetName.length - bAssetName.length;
1386
+ return aAssetName.localeCompare(bAssetName);
1387
+ }
1388
+ return a.policyId.localeCompare(b.policyId);
1389
+ }),
1390
+ Object.fromEntries
1391
+ );
1373
1392
 
1374
1393
  // src/utxo.ts
1375
1394
  var utxoToTransactionOutput = (utxo) => {
@@ -1582,6 +1601,7 @@ var stringify = (data) => JSON.stringify(
1582
1601
  scriptHashToCredential,
1583
1602
  selectUTxOs,
1584
1603
  slotToUnixTime,
1604
+ sortCanonical,
1585
1605
  sortUTxOs,
1586
1606
  stakeCredentialOf,
1587
1607
  stringify,
package/dist/index.d.cts CHANGED
@@ -182,7 +182,12 @@ declare function addAssets(...assets: Assets[]): Assets;
182
182
  * @param utxo UTxO whose OutRef will be used
183
183
  */
184
184
  declare function getUniqueTokenName(utxo: UTxO): Promise<string>;
185
+ /**
186
+ *
187
+ * Sort Assets following [RFC 7049 Section 3.9](https://datatracker.ietf.org/doc/html/rfc7049#section-3.9) sorting rules
188
+ */
189
+ declare const sortCanonical: (assets: Assets) => Assets;
185
190
 
186
191
  declare const stringify: (data: any) => string;
187
192
 
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 };
193
+ 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, sortCanonical, sortUTxOs, stakeCredentialOf, stringify, toCMLNativeScript, toLabel, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
package/dist/index.d.ts CHANGED
@@ -182,7 +182,12 @@ declare function addAssets(...assets: Assets[]): Assets;
182
182
  * @param utxo UTxO whose OutRef will be used
183
183
  */
184
184
  declare function getUniqueTokenName(utxo: UTxO): Promise<string>;
185
+ /**
186
+ *
187
+ * Sort Assets following [RFC 7049 Section 3.9](https://datatracker.ietf.org/doc/html/rfc7049#section-3.9) sorting rules
188
+ */
189
+ declare const sortCanonical: (assets: Assets) => Assets;
185
190
 
186
191
  declare const stringify: (data: any) => string;
187
192
 
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 };
193
+ 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, sortCanonical, sortUTxOs, stakeCredentialOf, stringify, toCMLNativeScript, toLabel, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
package/dist/index.js CHANGED
@@ -1207,6 +1207,7 @@ function slotToUnixTime(network, slot) {
1207
1207
 
1208
1208
  // src/value.ts
1209
1209
  import { fromHex as fromHex4, toHex as toHex3 } from "@lucid-evolution/core-utils";
1210
+ import { pipe } from "effect";
1210
1211
  function valueToAssets(value) {
1211
1212
  const assets = {};
1212
1213
  assets["lovelace"] = value.coin();
@@ -1291,6 +1292,23 @@ async function getUniqueTokenName(utxo) {
1291
1292
  const hash = new Uint8Array(await crypto.subtle.digest("SHA3-256", data));
1292
1293
  return toHex3(hash);
1293
1294
  }
1295
+ var sortCanonical = (assets) => pipe(
1296
+ Object.entries(assets).sort(([aUnit], [bUnit]) => {
1297
+ const a = fromUnit(aUnit);
1298
+ const b = fromUnit(bUnit);
1299
+ if (a.policyId.length !== b.policyId.length)
1300
+ return a.policyId.length - b.policyId.length;
1301
+ if (a.policyId === b.policyId) {
1302
+ const aAssetName = a.assetName || "";
1303
+ const bAssetName = b.assetName || "";
1304
+ if (aAssetName.length !== bAssetName.length)
1305
+ return aAssetName.length - bAssetName.length;
1306
+ return aAssetName.localeCompare(bAssetName);
1307
+ }
1308
+ return a.policyId.localeCompare(b.policyId);
1309
+ }),
1310
+ Object.fromEntries
1311
+ );
1294
1312
 
1295
1313
  // src/utxo.ts
1296
1314
  var utxoToTransactionOutput = (utxo) => {
@@ -1502,6 +1520,7 @@ export {
1502
1520
  scriptHashToCredential,
1503
1521
  selectUTxOs,
1504
1522
  slotToUnixTime,
1523
+ sortCanonical,
1505
1524
  sortUTxOs,
1506
1525
  stakeCredentialOf,
1507
1526
  stringify,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lucid-evolution/utils",
3
- "version": "0.1.45",
3
+ "version": "0.1.47",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -38,7 +38,7 @@
38
38
  "@lucid-evolution/core-utils": "0.1.16",
39
39
  "@lucid-evolution/crc8": "0.1.8",
40
40
  "@lucid-evolution/plutus": "0.1.26",
41
- "@lucid-evolution/uplc": "0.2.13"
41
+ "@lucid-evolution/uplc": "0.2.14"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/node": "^20.12.8",