@lucid-evolution/utils 0.1.3 → 0.1.5
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 -10
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +12 -3
- package/package.json +7 -6
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: () =>
|
|
36
|
+
applyDoubleCborEncoding: () => applyDoubleCborEncoding,
|
|
37
37
|
assetsToValue: () => assetsToValue,
|
|
38
38
|
coreToOutRef: () => coreToOutRef,
|
|
39
39
|
coreToTxOutput: () => coreToTxOutput,
|
|
@@ -140,7 +140,16 @@ function networkToId(network) {
|
|
|
140
140
|
var CML2 = __toESM(require("@dcspark/cardano-multiplatform-lib-nodejs"), 1);
|
|
141
141
|
|
|
142
142
|
// src/cbor.ts
|
|
143
|
-
var
|
|
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
|
+
};
|
|
144
153
|
|
|
145
154
|
// src/scripts.ts
|
|
146
155
|
function validatorToAddress(network, validator, stakeCredential) {
|
|
@@ -169,13 +178,13 @@ function validatorToScriptHash(validator) {
|
|
|
169
178
|
case "PlutusV1":
|
|
170
179
|
return CML2.PlutusScript.from_v1(
|
|
171
180
|
CML2.PlutusV1Script.from_cbor_hex(
|
|
172
|
-
|
|
181
|
+
applyDoubleCborEncoding(validator.script)
|
|
173
182
|
)
|
|
174
183
|
).hash().to_hex();
|
|
175
184
|
case "PlutusV2":
|
|
176
185
|
return CML2.PlutusScript.from_v2(
|
|
177
186
|
CML2.PlutusV2Script.from_cbor_hex(
|
|
178
|
-
|
|
187
|
+
applyDoubleCborEncoding(validator.script)
|
|
179
188
|
)
|
|
180
189
|
).hash().to_hex();
|
|
181
190
|
default:
|
|
@@ -191,13 +200,13 @@ function toScriptRef(script) {
|
|
|
191
200
|
case "PlutusV1":
|
|
192
201
|
return CML2.Script.new_plutus_v1(
|
|
193
202
|
CML2.PlutusV1Script.from_cbor_hex(
|
|
194
|
-
|
|
203
|
+
applyDoubleCborEncoding(script.script)
|
|
195
204
|
)
|
|
196
205
|
);
|
|
197
206
|
case "PlutusV2":
|
|
198
207
|
return CML2.Script.new_plutus_v2(
|
|
199
208
|
CML2.PlutusV2Script.from_cbor_hex(
|
|
200
|
-
|
|
209
|
+
applyDoubleCborEncoding(script.script)
|
|
201
210
|
)
|
|
202
211
|
);
|
|
203
212
|
default:
|
|
@@ -871,7 +880,7 @@ function toPublicKey(privateKey) {
|
|
|
871
880
|
}
|
|
872
881
|
|
|
873
882
|
// src/label.ts
|
|
874
|
-
var
|
|
883
|
+
var import_core_utils2 = require("@lucid-evolution/core-utils");
|
|
875
884
|
var import_crc8 = require("@lucid-evolution/crc8");
|
|
876
885
|
function toLabel(num) {
|
|
877
886
|
if (num < 0 || num > 65535) {
|
|
@@ -892,7 +901,7 @@ function fromLabel(label) {
|
|
|
892
901
|
return check === checksum(numHex) ? num : null;
|
|
893
902
|
}
|
|
894
903
|
function checksum(num) {
|
|
895
|
-
return (0, import_crc8.crc8)((0,
|
|
904
|
+
return (0, import_crc8.crc8)((0, import_core_utils2.fromHex)(num)).toString(16).padStart(2, "0");
|
|
896
905
|
}
|
|
897
906
|
|
|
898
907
|
// src/time.ts
|
|
@@ -908,7 +917,7 @@ function slotToUnixTime(network, slot) {
|
|
|
908
917
|
var CML9 = __toESM(require("@dcspark/cardano-multiplatform-lib-nodejs"), 1);
|
|
909
918
|
|
|
910
919
|
// src/value.ts
|
|
911
|
-
var
|
|
920
|
+
var import_core_utils3 = require("@lucid-evolution/core-utils");
|
|
912
921
|
var CML8 = __toESM(require("@dcspark/cardano-multiplatform-lib-nodejs"), 1);
|
|
913
922
|
function valueToAssets(value) {
|
|
914
923
|
const assets = {};
|
|
@@ -944,7 +953,7 @@ function assetsToValue(assets) {
|
|
|
944
953
|
const assetsValue = CML8.MapAssetNameToCoin.new();
|
|
945
954
|
policyUnits.forEach((unit) => {
|
|
946
955
|
assetsValue.insert(
|
|
947
|
-
CML8.AssetName.from_str((0,
|
|
956
|
+
CML8.AssetName.from_str((0, import_core_utils3.toText)(unit.slice(56))),
|
|
948
957
|
BigInt(assets[unit])
|
|
949
958
|
);
|
|
950
959
|
});
|
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,4 +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
|
-
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, 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,4 +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
|
-
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, 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 {
|
|
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(
|
|
824
|
+
return crc8(fromHex2(num)).toString(16).padStart(2, "0");
|
|
816
825
|
}
|
|
817
826
|
|
|
818
827
|
// src/time.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lucid-evolution/utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@dcspark/cardano-multiplatform-lib-nodejs": "^5.2.0",
|
|
26
|
-
"
|
|
27
|
-
"@lucid-evolution/bip39": "0.2.
|
|
26
|
+
"cborg": "^4.1.4",
|
|
27
|
+
"@lucid-evolution/bip39": "0.2.4",
|
|
28
28
|
"@lucid-evolution/core-types": "0.1.3",
|
|
29
29
|
"@lucid-evolution/core-utils": "0.1.3",
|
|
30
30
|
"@lucid-evolution/crc8": "0.1.3",
|
|
@@ -32,12 +32,13 @@
|
|
|
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
|
}
|