@lucid-evolution/utils 0.1.18 → 0.1.20

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
@@ -52,6 +52,7 @@ __export(src_exports, {
52
52
  generatePrivateKey: () => generatePrivateKey,
53
53
  generateSeedPhrase: () => generateSeedPhrase,
54
54
  getAddressDetails: () => getAddressDetails,
55
+ getUniqueTokenName: () => getUniqueTokenName,
55
56
  isEqualUTxO: () => isEqualUTxO,
56
57
  keyHashToCredential: () => keyHashToCredential,
57
58
  mintingPolicyToId: () => mintingPolicyToId,
@@ -84,7 +85,7 @@ __export(src_exports, {
84
85
  module.exports = __toCommonJS(src_exports);
85
86
 
86
87
  // src/core.ts
87
- var CML = __toESM(require("@dcspark/cardano-multiplatform-lib-nodejs"), 1);
88
+ var CML = __toESM(require("@anastasia-labs/cardano-multiplatform-lib-nodejs"), 1);
88
89
 
89
90
  // src/native.ts
90
91
  var toNativeScript = (native) => {
@@ -940,7 +941,7 @@ function valueToAssets(value) {
940
941
  for (let k = 0; k < assetNames.len(); k++) {
941
942
  const policyAsset = assetNames.get(k);
942
943
  const quantity = policyAssets.get(policyAsset);
943
- const unit = policy.to_hex() + (0, import_core_utils4.fromText)(policyAsset.to_str());
944
+ const unit = policy.to_hex() + policyAsset.to_js_value();
944
945
  assets[unit] = quantity;
945
946
  }
946
947
  }
@@ -1000,6 +1001,12 @@ function addAssets(...assets) {
1000
1001
  return a;
1001
1002
  }, {});
1002
1003
  }
1004
+ async function getUniqueTokenName(utxo) {
1005
+ const id = (0, import_core_utils4.fromHex)(utxo.txHash);
1006
+ const data = new Uint8Array([utxo.outputIndex, ...id]);
1007
+ const hash = new Uint8Array(await crypto.subtle.digest("SHA3-256", data));
1008
+ return (0, import_core_utils4.toHex)(hash);
1009
+ }
1003
1010
 
1004
1011
  // src/utxo.ts
1005
1012
  var utxoToTransactionOutput = (utxo) => {
@@ -1111,8 +1118,7 @@ var selectUTxOs = (utxos, totalAssets) => {
1111
1118
  break;
1112
1119
  }
1113
1120
  }
1114
- if (assetsRequired.size > 0)
1115
- return [];
1121
+ if (assetsRequired.size > 0) return [];
1116
1122
  return selectedUtxos;
1117
1123
  };
1118
1124
  var sortUTxOs = (utxos, order = "LargestFirst") => {
@@ -1171,6 +1177,7 @@ var stringify = (data) => JSON.stringify(
1171
1177
  generatePrivateKey,
1172
1178
  generateSeedPhrase,
1173
1179
  getAddressDetails,
1180
+ getUniqueTokenName,
1174
1181
  isEqualUTxO,
1175
1182
  keyHashToCredential,
1176
1183
  mintingPolicyToId,
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
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
- import * as CML from '@dcspark/cardano-multiplatform-lib-nodejs';
2
+ import * as CML from '@anastasia-labs/cardano-multiplatform-lib-nodejs';
3
3
  import { Data } from '@lucid-evolution/plutus';
4
4
 
5
5
  declare const toNativeScript: (native: Native) => CML.NativeScript;
@@ -100,7 +100,12 @@ declare function fromUnit(unit: Unit): {
100
100
  */
101
101
  declare function toUnit(policyId: PolicyId, name?: string | null, label?: number | null): Unit;
102
102
  declare function addAssets(...assets: Assets[]): Assets;
103
+ /**
104
+ * Returns a unique token name which is SHA3-256 hash of UTxO's txid and idx
105
+ * @param utxo UTxO whose OutRef will be used
106
+ */
107
+ declare function getUniqueTokenName(utxo: UTxO): Promise<string>;
103
108
 
104
109
  declare const stringify: (data: any) => string;
105
110
 
106
- export { PROTOCOL_PARAMETERS_DEFAULT, type SortOrder, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, assetsToValue, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumToHash, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, isEqualUTxO, keyHashToCredential, mintingPolicyToId, nativeFromJson, nativeJSFromJson, nativeScriptFromJson, networkToId, paymentCredentialOf, scriptHashToCredential, selectUTxOs, slotToUnixTime, sortUTxOs, stakeCredentialOf, stringify, toLabel, toNativeScript, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
111
+ export { PROTOCOL_PARAMETERS_DEFAULT, type SortOrder, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, assetsToValue, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumToHash, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, getUniqueTokenName, isEqualUTxO, keyHashToCredential, mintingPolicyToId, nativeFromJson, nativeJSFromJson, nativeScriptFromJson, networkToId, paymentCredentialOf, scriptHashToCredential, selectUTxOs, slotToUnixTime, sortUTxOs, stakeCredentialOf, stringify, toLabel, toNativeScript, 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 { 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
- import * as CML from '@dcspark/cardano-multiplatform-lib-nodejs';
2
+ import * as CML from '@anastasia-labs/cardano-multiplatform-lib-nodejs';
3
3
  import { Data } from '@lucid-evolution/plutus';
4
4
 
5
5
  declare const toNativeScript: (native: Native) => CML.NativeScript;
@@ -100,7 +100,12 @@ declare function fromUnit(unit: Unit): {
100
100
  */
101
101
  declare function toUnit(policyId: PolicyId, name?: string | null, label?: number | null): Unit;
102
102
  declare function addAssets(...assets: Assets[]): Assets;
103
+ /**
104
+ * Returns a unique token name which is SHA3-256 hash of UTxO's txid and idx
105
+ * @param utxo UTxO whose OutRef will be used
106
+ */
107
+ declare function getUniqueTokenName(utxo: UTxO): Promise<string>;
103
108
 
104
109
  declare const stringify: (data: any) => string;
105
110
 
106
- export { PROTOCOL_PARAMETERS_DEFAULT, type SortOrder, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, assetsToValue, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumToHash, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, isEqualUTxO, keyHashToCredential, mintingPolicyToId, nativeFromJson, nativeJSFromJson, nativeScriptFromJson, networkToId, paymentCredentialOf, scriptHashToCredential, selectUTxOs, slotToUnixTime, sortUTxOs, stakeCredentialOf, stringify, toLabel, toNativeScript, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
111
+ export { PROTOCOL_PARAMETERS_DEFAULT, type SortOrder, addAssets, addressFromHexOrBech32, applyDoubleCborEncoding, applyParamsToScript, assetsToValue, coreToOutRef, coreToTxOutput, coreToUtxo, coresToOutRefs, coresToTxOutputs, coresToUtxos, createCostModels, credentialToAddress, credentialToRewardAddress, datumToHash, fromLabel, fromScriptRef, fromUnit, generatePrivateKey, generateSeedPhrase, getAddressDetails, getUniqueTokenName, isEqualUTxO, keyHashToCredential, mintingPolicyToId, nativeFromJson, nativeJSFromJson, nativeScriptFromJson, networkToId, paymentCredentialOf, scriptHashToCredential, selectUTxOs, slotToUnixTime, sortUTxOs, stakeCredentialOf, stringify, toLabel, toNativeScript, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/core.ts
2
- import * as CML from "@dcspark/cardano-multiplatform-lib-nodejs";
2
+ import * as CML from "@anastasia-labs/cardano-multiplatform-lib-nodejs";
3
3
 
4
4
  // src/native.ts
5
5
  var toNativeScript = (native) => {
@@ -845,7 +845,7 @@ function slotToUnixTime(network, slot) {
845
845
  }
846
846
 
847
847
  // src/value.ts
848
- import { fromHex as fromHex4, fromText } from "@lucid-evolution/core-utils";
848
+ import { fromHex as fromHex4, toHex as toHex3 } from "@lucid-evolution/core-utils";
849
849
  function valueToAssets(value) {
850
850
  const assets = {};
851
851
  assets["lovelace"] = value.coin();
@@ -859,7 +859,7 @@ function valueToAssets(value) {
859
859
  for (let k = 0; k < assetNames.len(); k++) {
860
860
  const policyAsset = assetNames.get(k);
861
861
  const quantity = policyAssets.get(policyAsset);
862
- const unit = policy.to_hex() + fromText(policyAsset.to_str());
862
+ const unit = policy.to_hex() + policyAsset.to_js_value();
863
863
  assets[unit] = quantity;
864
864
  }
865
865
  }
@@ -919,6 +919,12 @@ function addAssets(...assets) {
919
919
  return a;
920
920
  }, {});
921
921
  }
922
+ async function getUniqueTokenName(utxo) {
923
+ const id = fromHex4(utxo.txHash);
924
+ const data = new Uint8Array([utxo.outputIndex, ...id]);
925
+ const hash = new Uint8Array(await crypto.subtle.digest("SHA3-256", data));
926
+ return toHex3(hash);
927
+ }
922
928
 
923
929
  // src/utxo.ts
924
930
  var utxoToTransactionOutput = (utxo) => {
@@ -1030,8 +1036,7 @@ var selectUTxOs = (utxos, totalAssets) => {
1030
1036
  break;
1031
1037
  }
1032
1038
  }
1033
- if (assetsRequired.size > 0)
1034
- return [];
1039
+ if (assetsRequired.size > 0) return [];
1035
1040
  return selectedUtxos;
1036
1041
  };
1037
1042
  var sortUTxOs = (utxos, order = "LargestFirst") => {
@@ -1089,6 +1094,7 @@ export {
1089
1094
  generatePrivateKey,
1090
1095
  generateSeedPhrase,
1091
1096
  getAddressDetails,
1097
+ getUniqueTokenName,
1092
1098
  isEqualUTxO,
1093
1099
  keyHashToCredential,
1094
1100
  mintingPolicyToId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lucid-evolution/utils",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -22,18 +22,18 @@
22
22
  "author": "",
23
23
  "license": "MIT",
24
24
  "browser": {
25
- "@dcspark/cardano-multiplatform-lib-nodejs": "@dcspark/cardano-multiplatform-lib-browser"
25
+ "@anastasia-labs/cardano-multiplatform-lib-nodejs": "@anastasia-labs/cardano-multiplatform-lib-browser"
26
26
  },
27
27
  "dependencies": {
28
- "@dcspark/cardano-multiplatform-lib-nodejs": "^5.3.0",
29
- "@dcspark/cardano-multiplatform-lib-browser": "^5.3.0",
28
+ "@anastasia-labs/cardano-multiplatform-lib-nodejs": "^5.3.1-2",
29
+ "@anastasia-labs/cardano-multiplatform-lib-browser": "^5.3.1-2",
30
30
  "cborg": "^4.2.0",
31
- "@lucid-evolution/bip39": "0.2.7",
32
- "@lucid-evolution/core-types": "0.1.7",
33
- "@lucid-evolution/core-utils": "0.1.6",
34
- "@lucid-evolution/crc8": "0.1.6",
35
- "@lucid-evolution/plutus": "0.1.10",
36
- "@lucid-evolution/uplc": "0.2.6"
31
+ "@lucid-evolution/bip39": "0.2.8",
32
+ "@lucid-evolution/core-types": "0.1.8",
33
+ "@lucid-evolution/core-utils": "0.1.7",
34
+ "@lucid-evolution/crc8": "0.1.7",
35
+ "@lucid-evolution/plutus": "0.1.11",
36
+ "@lucid-evolution/uplc": "0.2.7"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/node": "^20.12.8",