@lucid-evolution/utils 0.1.2 → 0.1.4

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
@@ -33,7 +33,7 @@ __export(src_exports, {
33
33
  PROTOCOL_PARAMETERS_DEFAULT: () => PROTOCOL_PARAMETERS_DEFAULT,
34
34
  addAssets: () => addAssets,
35
35
  addressFromHexOrBech32: () => addressFromHexOrBech32,
36
- applyDoubleCborEncoding: () => import_lucid_cardano.applyDoubleCborEncoding,
36
+ applyDoubleCborEncoding: () => applyDoubleCborEncoding,
37
37
  assetsToValue: () => assetsToValue,
38
38
  coreToOutRef: () => coreToOutRef,
39
39
  coreToTxOutput: () => coreToTxOutput,
@@ -61,7 +61,6 @@ __export(src_exports, {
61
61
  scriptHashToCredential: () => scriptHashToCredential,
62
62
  slotToUnixTime: () => slotToUnixTime,
63
63
  stakeCredentialOf: () => stakeCredentialOf,
64
- toCMLTransactionHash: () => toCMLTransactionHash,
65
64
  toLabel: () => toLabel,
66
65
  toNativeScript: () => toNativeScript,
67
66
  toPublicKey: () => toPublicKey,
@@ -141,7 +140,16 @@ function networkToId(network) {
141
140
  var CML2 = __toESM(require("@dcspark/cardano-multiplatform-lib-nodejs"), 1);
142
141
 
143
142
  // src/cbor.ts
144
- var import_lucid_cardano = require("lucid-cardano");
143
+ var import_core_utils = require("@lucid-evolution/core-utils");
144
+ var import_cborg = require("cborg");
145
+ var applyDoubleCborEncoding = (script) => {
146
+ try {
147
+ (0, import_cborg.decode)((0, import_cborg.decode)((0, import_core_utils.fromHex)(script)));
148
+ return script;
149
+ } catch (error) {
150
+ return (0, import_core_utils.toHex)((0, import_cborg.encode)((0, import_core_utils.fromHex)(script)));
151
+ }
152
+ };
145
153
 
146
154
  // src/scripts.ts
147
155
  function validatorToAddress(network, validator, stakeCredential) {
@@ -170,13 +178,13 @@ function validatorToScriptHash(validator) {
170
178
  case "PlutusV1":
171
179
  return CML2.PlutusScript.from_v1(
172
180
  CML2.PlutusV1Script.from_cbor_hex(
173
- (0, import_lucid_cardano.applyDoubleCborEncoding)(validator.script)
181
+ applyDoubleCborEncoding(validator.script)
174
182
  )
175
183
  ).hash().to_hex();
176
184
  case "PlutusV2":
177
185
  return CML2.PlutusScript.from_v2(
178
186
  CML2.PlutusV2Script.from_cbor_hex(
179
- (0, import_lucid_cardano.applyDoubleCborEncoding)(validator.script)
187
+ applyDoubleCborEncoding(validator.script)
180
188
  )
181
189
  ).hash().to_hex();
182
190
  default:
@@ -192,13 +200,13 @@ function toScriptRef(script) {
192
200
  case "PlutusV1":
193
201
  return CML2.Script.new_plutus_v1(
194
202
  CML2.PlutusV1Script.from_cbor_hex(
195
- (0, import_lucid_cardano.applyDoubleCborEncoding)(script.script)
203
+ applyDoubleCborEncoding(script.script)
196
204
  )
197
205
  );
198
206
  case "PlutusV2":
199
207
  return CML2.Script.new_plutus_v2(
200
208
  CML2.PlutusV2Script.from_cbor_hex(
201
- (0, import_lucid_cardano.applyDoubleCborEncoding)(script.script)
209
+ applyDoubleCborEncoding(script.script)
202
210
  )
203
211
  );
204
212
  default:
@@ -872,7 +880,7 @@ function toPublicKey(privateKey) {
872
880
  }
873
881
 
874
882
  // src/label.ts
875
- var import_core_utils = require("@lucid-evolution/core-utils");
883
+ var import_core_utils2 = require("@lucid-evolution/core-utils");
876
884
  var import_crc8 = require("@lucid-evolution/crc8");
877
885
  function toLabel(num) {
878
886
  if (num < 0 || num > 65535) {
@@ -893,7 +901,7 @@ function fromLabel(label) {
893
901
  return check === checksum(numHex) ? num : null;
894
902
  }
895
903
  function checksum(num) {
896
- return (0, import_crc8.crc8)((0, import_core_utils.fromHex)(num)).toString(16).padStart(2, "0");
904
+ return (0, import_crc8.crc8)((0, import_core_utils2.fromHex)(num)).toString(16).padStart(2, "0");
897
905
  }
898
906
 
899
907
  // src/time.ts
@@ -909,7 +917,7 @@ function slotToUnixTime(network, slot) {
909
917
  var CML9 = __toESM(require("@dcspark/cardano-multiplatform-lib-nodejs"), 1);
910
918
 
911
919
  // src/value.ts
912
- var import_core_utils2 = require("@lucid-evolution/core-utils");
920
+ var import_core_utils3 = require("@lucid-evolution/core-utils");
913
921
  var CML8 = __toESM(require("@dcspark/cardano-multiplatform-lib-nodejs"), 1);
914
922
  function valueToAssets(value) {
915
923
  const assets = {};
@@ -945,7 +953,7 @@ function assetsToValue(assets) {
945
953
  const assetsValue = CML8.MapAssetNameToCoin.new();
946
954
  policyUnits.forEach((unit) => {
947
955
  assetsValue.insert(
948
- CML8.AssetName.from_str((0, import_core_utils2.toText)(unit.slice(56))),
956
+ CML8.AssetName.from_str((0, import_core_utils3.toText)(unit.slice(56))),
949
957
  BigInt(assets[unit])
950
958
  );
951
959
  });
@@ -1108,17 +1116,6 @@ function coresToTxOutputs(outputs) {
1108
1116
  }
1109
1117
  return result;
1110
1118
  }
1111
-
1112
- // src/tx.ts
1113
- var CML10 = __toESM(require("@dcspark/cardano-multiplatform-lib-nodejs"), 1);
1114
- var import_core_utils3 = require("@lucid-evolution/core-utils");
1115
- var import_lucid_cardano2 = require("lucid-cardano");
1116
- function toCMLTransactionHash(body) {
1117
- const TransactionHash3 = import_lucid_cardano2.C.hash_transaction(
1118
- import_lucid_cardano2.C.TransactionBody.from_bytes((0, import_core_utils3.fromHex)(body.to_cbor_hex()))
1119
- );
1120
- return CML10.TransactionHash.from_hex(TransactionHash3.to_hex());
1121
- }
1122
1119
  // Annotate the CommonJS export names for ESM import in node:
1123
1120
  0 && (module.exports = {
1124
1121
  PROTOCOL_PARAMETERS_DEFAULT,
@@ -1152,7 +1149,6 @@ function toCMLTransactionHash(body) {
1152
1149
  scriptHashToCredential,
1153
1150
  slotToUnixTime,
1154
1151
  stakeCredentialOf,
1155
- toCMLTransactionHash,
1156
1152
  toLabel,
1157
1153
  toNativeScript,
1158
1154
  toPublicKey,
package/dist/index.d.cts CHANGED
@@ -1,6 +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, UnixTime, Slot, UTxO, OutRef, TxOutput, Assets, Unit } from '@lucid-evolution/core-types';
2
2
  import * as CML from '@dcspark/cardano-multiplatform-lib-nodejs';
3
- export { applyDoubleCborEncoding } from 'lucid-cardano';
4
3
 
5
4
  declare const toNativeScript: (native: Native) => CML.NativeScript;
6
5
  declare const nativeJSFromJson: (native: Native) => Script;
@@ -11,6 +10,8 @@ declare function validatorToRewardAddress(network: Network, validator: Certifica
11
10
  /** Address can be in Bech32 or Hex. */
12
11
  declare function getAddressDetails(address: string): AddressDetails;
13
12
 
13
+ declare const applyDoubleCborEncoding: (script: string) => string;
14
+
14
15
  declare function createCostModels(costModels: CostModels): CML.CostModels;
15
16
  declare const PROTOCOL_PARAMETERS_DEFAULT: ProtocolParameters;
16
17
 
@@ -75,6 +76,4 @@ declare function fromUnit(unit: Unit): {
75
76
  declare function toUnit(policyId: PolicyId, name?: string | null, label?: number | null): Unit;
76
77
  declare function addAssets(...assets: Assets[]): Assets;
77
78
 
78
- declare function toCMLTransactionHash(body: CML.TransactionBody): CML.TransactionHash;
79
-
80
- export { PROTOCOL_PARAMETERS_DEFAULT, addAssets, addressFromHexOrBech32, 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, toCMLTransactionHash, toLabel, toNativeScript, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
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 };
package/dist/index.d.ts CHANGED
@@ -1,6 +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, UnixTime, Slot, UTxO, OutRef, TxOutput, Assets, Unit } from '@lucid-evolution/core-types';
2
2
  import * as CML from '@dcspark/cardano-multiplatform-lib-nodejs';
3
- export { applyDoubleCborEncoding } from 'lucid-cardano';
4
3
 
5
4
  declare const toNativeScript: (native: Native) => CML.NativeScript;
6
5
  declare const nativeJSFromJson: (native: Native) => Script;
@@ -11,6 +10,8 @@ declare function validatorToRewardAddress(network: Network, validator: Certifica
11
10
  /** Address can be in Bech32 or Hex. */
12
11
  declare function getAddressDetails(address: string): AddressDetails;
13
12
 
13
+ declare const applyDoubleCborEncoding: (script: string) => string;
14
+
14
15
  declare function createCostModels(costModels: CostModels): CML.CostModels;
15
16
  declare const PROTOCOL_PARAMETERS_DEFAULT: ProtocolParameters;
16
17
 
@@ -75,6 +76,4 @@ declare function fromUnit(unit: Unit): {
75
76
  declare function toUnit(policyId: PolicyId, name?: string | null, label?: number | null): Unit;
76
77
  declare function addAssets(...assets: Assets[]): Assets;
77
78
 
78
- declare function toCMLTransactionHash(body: CML.TransactionBody): CML.TransactionHash;
79
-
80
- export { PROTOCOL_PARAMETERS_DEFAULT, addAssets, addressFromHexOrBech32, 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, toCMLTransactionHash, toLabel, toNativeScript, toPublicKey, toScriptRef, toUnit, unixTimeToSlot, utxoToCore, utxoToTransactionInput, utxoToTransactionOutput, utxosToCores, validatorToAddress, validatorToRewardAddress, validatorToScriptHash, valueToAssets };
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 };
package/dist/index.js CHANGED
@@ -60,7 +60,16 @@ function networkToId(network) {
60
60
  import * as CML2 from "@dcspark/cardano-multiplatform-lib-nodejs";
61
61
 
62
62
  // src/cbor.ts
63
- import { applyDoubleCborEncoding } from "lucid-cardano";
63
+ import { fromHex, toHex } from "@lucid-evolution/core-utils";
64
+ import { decode, encode } from "cborg";
65
+ var applyDoubleCborEncoding = (script) => {
66
+ try {
67
+ decode(decode(fromHex(script)));
68
+ return script;
69
+ } catch (error) {
70
+ return toHex(encode(fromHex(script)));
71
+ }
72
+ };
64
73
 
65
74
  // src/scripts.ts
66
75
  function validatorToAddress(network, validator, stakeCredential) {
@@ -791,7 +800,7 @@ function toPublicKey(privateKey) {
791
800
  }
792
801
 
793
802
  // src/label.ts
794
- import { fromHex } from "@lucid-evolution/core-utils";
803
+ import { fromHex as fromHex2 } from "@lucid-evolution/core-utils";
795
804
  import { crc8 } from "@lucid-evolution/crc8";
796
805
  function toLabel(num) {
797
806
  if (num < 0 || num > 65535) {
@@ -812,7 +821,7 @@ function fromLabel(label) {
812
821
  return check === checksum(numHex) ? num : null;
813
822
  }
814
823
  function checksum(num) {
815
- return crc8(fromHex(num)).toString(16).padStart(2, "0");
824
+ return crc8(fromHex2(num)).toString(16).padStart(2, "0");
816
825
  }
817
826
 
818
827
  // src/time.ts
@@ -1031,17 +1040,6 @@ function coresToTxOutputs(outputs) {
1031
1040
  }
1032
1041
  return result;
1033
1042
  }
1034
-
1035
- // src/tx.ts
1036
- import * as CML10 from "@dcspark/cardano-multiplatform-lib-nodejs";
1037
- import { fromHex as fromHex2 } from "@lucid-evolution/core-utils";
1038
- import { C } from "lucid-cardano";
1039
- function toCMLTransactionHash(body) {
1040
- const TransactionHash3 = C.hash_transaction(
1041
- C.TransactionBody.from_bytes(fromHex2(body.to_cbor_hex()))
1042
- );
1043
- return CML10.TransactionHash.from_hex(TransactionHash3.to_hex());
1044
- }
1045
1043
  export {
1046
1044
  PROTOCOL_PARAMETERS_DEFAULT,
1047
1045
  addAssets,
@@ -1074,7 +1072,6 @@ export {
1074
1072
  scriptHashToCredential,
1075
1073
  slotToUnixTime,
1076
1074
  stakeCredentialOf,
1077
- toCMLTransactionHash,
1078
1075
  toLabel,
1079
1076
  toNativeScript,
1080
1077
  toPublicKey,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lucid-evolution/utils",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -22,22 +22,23 @@
22
22
  "author": "",
23
23
  "license": "MIT",
24
24
  "dependencies": {
25
- "@dcspark/cardano-multiplatform-lib-nodejs": "^5.1.0",
26
- "lucid-cardano": "^0.10.7",
27
- "@lucid-evolution/bip39": "0.2.2",
28
- "@lucid-evolution/core-types": "0.1.2",
29
- "@lucid-evolution/core-utils": "0.1.2",
30
- "@lucid-evolution/crc8": "0.1.2",
31
- "@lucid-evolution/plutus": "0.1.5"
25
+ "@dcspark/cardano-multiplatform-lib-nodejs": "^5.2.0",
26
+ "cborg": "^4.1.4",
27
+ "@lucid-evolution/bip39": "0.2.3",
28
+ "@lucid-evolution/core-types": "0.1.3",
29
+ "@lucid-evolution/core-utils": "0.1.3",
30
+ "@lucid-evolution/crc8": "0.1.3",
31
+ "@lucid-evolution/plutus": "0.1.6"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/node": "^20.11.24",
35
- "cborg": "^4.1.4",
36
35
  "tsup": "^8.0.2",
37
- "typescript": "^5.3.3"
36
+ "typescript": "^5.3.3",
37
+ "vitest": "^1.4.0"
38
38
  },
39
39
  "scripts": {
40
40
  "build": "tsup-node src/index.ts --format esm,cjs --dts --clean",
41
- "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
41
+ "clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
42
+ "test": "vitest run"
42
43
  }
43
44
  }