@lucid-evolution/utils 0.1.5 → 0.1.7
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 +97 -151
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +97 -151
- package/package.json +11 -11
package/dist/index.cjs
CHANGED
|
@@ -78,8 +78,10 @@ __export(src_exports, {
|
|
|
78
78
|
});
|
|
79
79
|
module.exports = __toCommonJS(src_exports);
|
|
80
80
|
|
|
81
|
-
// src/
|
|
81
|
+
// src/core.ts
|
|
82
82
|
var CML = __toESM(require("@dcspark/cardano-multiplatform-lib-nodejs"), 1);
|
|
83
|
+
|
|
84
|
+
// src/native.ts
|
|
83
85
|
var toNativeScript = (native) => {
|
|
84
86
|
switch (native.type) {
|
|
85
87
|
case "sig":
|
|
@@ -117,9 +119,6 @@ var nativeJSFromJson = (native) => {
|
|
|
117
119
|
};
|
|
118
120
|
};
|
|
119
121
|
|
|
120
|
-
// src/address.ts
|
|
121
|
-
var CML3 = __toESM(require("@dcspark/cardano-multiplatform-lib-nodejs"), 1);
|
|
122
|
-
|
|
123
122
|
// src/network.ts
|
|
124
123
|
function networkToId(network) {
|
|
125
124
|
switch (network) {
|
|
@@ -136,9 +135,6 @@ function networkToId(network) {
|
|
|
136
135
|
}
|
|
137
136
|
}
|
|
138
137
|
|
|
139
|
-
// src/scripts.ts
|
|
140
|
-
var CML2 = __toESM(require("@dcspark/cardano-multiplatform-lib-nodejs"), 1);
|
|
141
|
-
|
|
142
138
|
// src/cbor.ts
|
|
143
139
|
var import_core_utils = require("@lucid-evolution/core-utils");
|
|
144
140
|
var import_cborg = require("cborg");
|
|
@@ -155,35 +151,35 @@ var applyDoubleCborEncoding = (script) => {
|
|
|
155
151
|
function validatorToAddress(network, validator, stakeCredential) {
|
|
156
152
|
const validatorHash = validatorToScriptHash(validator);
|
|
157
153
|
if (stakeCredential) {
|
|
158
|
-
return
|
|
154
|
+
return CML.BaseAddress.new(
|
|
159
155
|
networkToId(network),
|
|
160
|
-
|
|
161
|
-
stakeCredential.type === "Key" ?
|
|
162
|
-
|
|
163
|
-
) :
|
|
164
|
-
|
|
156
|
+
CML.Credential.new_script(CML.ScriptHash.from_hex(validatorHash)),
|
|
157
|
+
stakeCredential.type === "Key" ? CML.Credential.new_pub_key(
|
|
158
|
+
CML.Ed25519KeyHash.from_hex(stakeCredential.hash)
|
|
159
|
+
) : CML.Credential.new_script(
|
|
160
|
+
CML.ScriptHash.from_hex(stakeCredential.hash)
|
|
165
161
|
)
|
|
166
162
|
).to_address().to_bech32(void 0);
|
|
167
163
|
} else {
|
|
168
|
-
return
|
|
164
|
+
return CML.EnterpriseAddress.new(
|
|
169
165
|
networkToId(network),
|
|
170
|
-
|
|
166
|
+
CML.Credential.new_script(CML.ScriptHash.from_hex(validatorHash))
|
|
171
167
|
).to_address().to_bech32(void 0);
|
|
172
168
|
}
|
|
173
169
|
}
|
|
174
170
|
function validatorToScriptHash(validator) {
|
|
175
171
|
switch (validator.type) {
|
|
176
172
|
case "Native":
|
|
177
|
-
return
|
|
173
|
+
return CML.NativeScript.from_cbor_hex(validator.script).hash().to_hex();
|
|
178
174
|
case "PlutusV1":
|
|
179
|
-
return
|
|
180
|
-
|
|
175
|
+
return CML.PlutusScript.from_v1(
|
|
176
|
+
CML.PlutusV1Script.from_cbor_hex(
|
|
181
177
|
applyDoubleCborEncoding(validator.script)
|
|
182
178
|
)
|
|
183
179
|
).hash().to_hex();
|
|
184
180
|
case "PlutusV2":
|
|
185
|
-
return
|
|
186
|
-
|
|
181
|
+
return CML.PlutusScript.from_v2(
|
|
182
|
+
CML.PlutusV2Script.from_cbor_hex(
|
|
187
183
|
applyDoubleCborEncoding(validator.script)
|
|
188
184
|
)
|
|
189
185
|
).hash().to_hex();
|
|
@@ -194,18 +190,18 @@ function validatorToScriptHash(validator) {
|
|
|
194
190
|
function toScriptRef(script) {
|
|
195
191
|
switch (script.type) {
|
|
196
192
|
case "Native":
|
|
197
|
-
return
|
|
198
|
-
|
|
193
|
+
return CML.Script.new_native(
|
|
194
|
+
CML.NativeScript.from_cbor_hex(script.script)
|
|
199
195
|
);
|
|
200
196
|
case "PlutusV1":
|
|
201
|
-
return
|
|
202
|
-
|
|
197
|
+
return CML.Script.new_plutus_v1(
|
|
198
|
+
CML.PlutusV1Script.from_cbor_hex(
|
|
203
199
|
applyDoubleCborEncoding(script.script)
|
|
204
200
|
)
|
|
205
201
|
);
|
|
206
202
|
case "PlutusV2":
|
|
207
|
-
return
|
|
208
|
-
|
|
203
|
+
return CML.Script.new_plutus_v2(
|
|
204
|
+
CML.PlutusV2Script.from_cbor_hex(
|
|
209
205
|
applyDoubleCborEncoding(script.script)
|
|
210
206
|
)
|
|
211
207
|
);
|
|
@@ -244,7 +240,7 @@ function nativeFromJson(nativeScript) {
|
|
|
244
240
|
function nativeScriptFromJson(nativeScript) {
|
|
245
241
|
return {
|
|
246
242
|
type: "Native",
|
|
247
|
-
script:
|
|
243
|
+
script: CML.NativeScript.from_json(
|
|
248
244
|
JSON.stringify(nativeScript)
|
|
249
245
|
).to_cbor_hex()
|
|
250
246
|
};
|
|
@@ -253,36 +249,36 @@ function nativeScriptFromJson(nativeScript) {
|
|
|
253
249
|
// src/address.ts
|
|
254
250
|
function addressFromHexOrBech32(address) {
|
|
255
251
|
try {
|
|
256
|
-
return
|
|
252
|
+
return CML.Address.from_hex(address);
|
|
257
253
|
} catch (_e) {
|
|
258
254
|
try {
|
|
259
|
-
return
|
|
255
|
+
return CML.Address.from_bech32(address);
|
|
260
256
|
} catch (_e2) {
|
|
261
257
|
throw new Error("Could not deserialize address.");
|
|
262
258
|
}
|
|
263
259
|
}
|
|
264
260
|
}
|
|
265
261
|
function credentialToRewardAddress(network, stakeCredential) {
|
|
266
|
-
return
|
|
262
|
+
return CML.RewardAddress.new(
|
|
267
263
|
networkToId(network),
|
|
268
|
-
stakeCredential.type === "Key" ?
|
|
269
|
-
|
|
270
|
-
) :
|
|
271
|
-
|
|
264
|
+
stakeCredential.type === "Key" ? CML.Credential.new_pub_key(
|
|
265
|
+
CML.Ed25519KeyHash.from_hex(stakeCredential.hash)
|
|
266
|
+
) : CML.Credential.new_script(
|
|
267
|
+
CML.ScriptHash.from_hex(stakeCredential.hash)
|
|
272
268
|
)
|
|
273
269
|
).to_address().to_bech32(void 0);
|
|
274
270
|
}
|
|
275
271
|
function validatorToRewardAddress(network, validator) {
|
|
276
272
|
const validatorHash = validatorToScriptHash(validator);
|
|
277
|
-
return
|
|
273
|
+
return CML.RewardAddress.new(
|
|
278
274
|
networkToId(network),
|
|
279
|
-
|
|
275
|
+
CML.Credential.new_script(CML.ScriptHash.from_hex(validatorHash))
|
|
280
276
|
).to_address().to_bech32(void 0);
|
|
281
277
|
}
|
|
282
278
|
function getAddressDetails(address) {
|
|
283
279
|
try {
|
|
284
|
-
const parsedAddress =
|
|
285
|
-
|
|
280
|
+
const parsedAddress = CML.BaseAddress.from_address(
|
|
281
|
+
CML.Address.from_bech32(address)
|
|
286
282
|
);
|
|
287
283
|
const paymentCredential = parsedAddress.payment().kind() === 0 ? {
|
|
288
284
|
type: "Key",
|
|
@@ -323,8 +319,8 @@ function getAddressDetails(address) {
|
|
|
323
319
|
} catch (_e) {
|
|
324
320
|
}
|
|
325
321
|
try {
|
|
326
|
-
const parsedAddress =
|
|
327
|
-
|
|
322
|
+
const parsedAddress = CML.EnterpriseAddress.from_address(
|
|
323
|
+
CML.Address.from_bech32(address)
|
|
328
324
|
);
|
|
329
325
|
const paymentCredential = parsedAddress.payment().kind() === 0 ? {
|
|
330
326
|
type: "Key",
|
|
@@ -349,8 +345,8 @@ function getAddressDetails(address) {
|
|
|
349
345
|
} catch (_e) {
|
|
350
346
|
}
|
|
351
347
|
try {
|
|
352
|
-
const parsedAddress =
|
|
353
|
-
|
|
348
|
+
const parsedAddress = CML.PointerAddress.from_address(
|
|
349
|
+
CML.Address.from_bech32(address)
|
|
354
350
|
);
|
|
355
351
|
const paymentCredential = parsedAddress?.payment().kind() === 0 ? {
|
|
356
352
|
type: "Key",
|
|
@@ -374,8 +370,8 @@ function getAddressDetails(address) {
|
|
|
374
370
|
} catch (_e) {
|
|
375
371
|
}
|
|
376
372
|
try {
|
|
377
|
-
const parsedAddress =
|
|
378
|
-
|
|
373
|
+
const parsedAddress = CML.RewardAddress.from_address(
|
|
374
|
+
CML.Address.from_bech32(address)
|
|
379
375
|
);
|
|
380
376
|
const stakeCredential = parsedAddress.payment().kind() === 0 ? {
|
|
381
377
|
type: "Key",
|
|
@@ -399,10 +395,10 @@ function getAddressDetails(address) {
|
|
|
399
395
|
try {
|
|
400
396
|
const parsedAddress = ((address2) => {
|
|
401
397
|
try {
|
|
402
|
-
return
|
|
398
|
+
return CML.ByronAddress.from_cbor_hex(address2);
|
|
403
399
|
} catch (_e) {
|
|
404
400
|
try {
|
|
405
|
-
return
|
|
401
|
+
return CML.ByronAddress.from_base58(address2);
|
|
406
402
|
} catch (_e2) {
|
|
407
403
|
throw new Error("Could not deserialize address.");
|
|
408
404
|
}
|
|
@@ -423,17 +419,16 @@ function getAddressDetails(address) {
|
|
|
423
419
|
}
|
|
424
420
|
|
|
425
421
|
// src/cost_model.ts
|
|
426
|
-
var CML4 = __toESM(require("@dcspark/cardano-multiplatform-lib-nodejs"), 1);
|
|
427
422
|
function createCostModels(costModels) {
|
|
428
|
-
const costmdls =
|
|
429
|
-
const costmdlV1 =
|
|
430
|
-
Object.values(costModels.
|
|
431
|
-
costmdlV1.add(
|
|
423
|
+
const costmdls = CML.CostModels.new();
|
|
424
|
+
const costmdlV1 = CML.IntList.new();
|
|
425
|
+
Object.values(costModels.PlutusV1).forEach((cost) => {
|
|
426
|
+
costmdlV1.add(CML.Int.new(BigInt(cost)));
|
|
432
427
|
});
|
|
433
428
|
costmdls.set_plutus_v1(costmdlV1);
|
|
434
|
-
const costmdlV2 =
|
|
429
|
+
const costmdlV2 = CML.IntList.new();
|
|
435
430
|
Object.values(costModels.PlutusV2).forEach((cost) => {
|
|
436
|
-
costmdlV2.add(
|
|
431
|
+
costmdlV2.add(CML.Int.new(BigInt(cost)));
|
|
437
432
|
});
|
|
438
433
|
costmdls.set_plutus_v2(costmdlV2);
|
|
439
434
|
return costmdls;
|
|
@@ -802,29 +797,28 @@ var PROTOCOL_PARAMETERS_DEFAULT = {
|
|
|
802
797
|
};
|
|
803
798
|
|
|
804
799
|
// src/credential.ts
|
|
805
|
-
var CML5 = __toESM(require("@dcspark/cardano-multiplatform-lib-nodejs"), 1);
|
|
806
800
|
function credentialToAddress(network, paymentCredential, stakeCredential) {
|
|
807
801
|
if (stakeCredential) {
|
|
808
|
-
return
|
|
802
|
+
return CML.BaseAddress.new(
|
|
809
803
|
networkToId(network),
|
|
810
|
-
paymentCredential.type === "Key" ?
|
|
811
|
-
|
|
812
|
-
) :
|
|
813
|
-
|
|
804
|
+
paymentCredential.type === "Key" ? CML.Credential.new_pub_key(
|
|
805
|
+
CML.Ed25519KeyHash.from_hex(paymentCredential.hash)
|
|
806
|
+
) : CML.Credential.new_script(
|
|
807
|
+
CML.ScriptHash.from_hex(paymentCredential.hash)
|
|
814
808
|
),
|
|
815
|
-
stakeCredential.type === "Key" ?
|
|
816
|
-
|
|
817
|
-
) :
|
|
818
|
-
|
|
809
|
+
stakeCredential.type === "Key" ? CML.Credential.new_pub_key(
|
|
810
|
+
CML.Ed25519KeyHash.from_hex(stakeCredential.hash)
|
|
811
|
+
) : CML.Credential.new_script(
|
|
812
|
+
CML.ScriptHash.from_hex(stakeCredential.hash)
|
|
819
813
|
)
|
|
820
814
|
).to_address().to_bech32(void 0);
|
|
821
815
|
} else {
|
|
822
|
-
return
|
|
816
|
+
return CML.EnterpriseAddress.new(
|
|
823
817
|
networkToId(network),
|
|
824
|
-
paymentCredential.type === "Key" ?
|
|
825
|
-
|
|
826
|
-
) :
|
|
827
|
-
|
|
818
|
+
paymentCredential.type === "Key" ? CML.Credential.new_pub_key(
|
|
819
|
+
CML.Ed25519KeyHash.from_hex(paymentCredential.hash)
|
|
820
|
+
) : CML.Credential.new_script(
|
|
821
|
+
CML.ScriptHash.from_hex(paymentCredential.hash)
|
|
828
822
|
)
|
|
829
823
|
).to_address().to_bech32(void 0);
|
|
830
824
|
}
|
|
@@ -861,22 +855,20 @@ function stakeCredentialOf(rewardAddress) {
|
|
|
861
855
|
}
|
|
862
856
|
|
|
863
857
|
// src/datum.ts
|
|
864
|
-
var CML6 = __toESM(require("@dcspark/cardano-multiplatform-lib-nodejs"), 1);
|
|
865
858
|
function datumToHash(datum) {
|
|
866
|
-
return
|
|
859
|
+
return CML.hash_plutus_data(CML.PlutusData.from_cbor_hex(datum)).to_hex();
|
|
867
860
|
}
|
|
868
861
|
|
|
869
862
|
// src/keys.ts
|
|
870
863
|
var import_bip39 = require("@lucid-evolution/bip39");
|
|
871
|
-
var CML7 = __toESM(require("@dcspark/cardano-multiplatform-lib-nodejs"), 1);
|
|
872
864
|
function generatePrivateKey() {
|
|
873
|
-
return
|
|
865
|
+
return CML.PrivateKey.generate_ed25519().to_bech32();
|
|
874
866
|
}
|
|
875
867
|
function generateSeedPhrase() {
|
|
876
868
|
return (0, import_bip39.generateMnemonic)(256);
|
|
877
869
|
}
|
|
878
870
|
function toPublicKey(privateKey) {
|
|
879
|
-
return
|
|
871
|
+
return CML.PrivateKey.from_bech32(privateKey).to_public().to_bech32();
|
|
880
872
|
}
|
|
881
873
|
|
|
882
874
|
// src/label.ts
|
|
@@ -913,12 +905,8 @@ function slotToUnixTime(network, slot) {
|
|
|
913
905
|
return (0, import_plutus.slotToBeginUnixTime)(slot, import_plutus.SLOT_CONFIG_NETWORK[network]);
|
|
914
906
|
}
|
|
915
907
|
|
|
916
|
-
// src/utxo.ts
|
|
917
|
-
var CML9 = __toESM(require("@dcspark/cardano-multiplatform-lib-nodejs"), 1);
|
|
918
|
-
|
|
919
908
|
// src/value.ts
|
|
920
909
|
var import_core_utils3 = require("@lucid-evolution/core-utils");
|
|
921
|
-
var CML8 = __toESM(require("@dcspark/cardano-multiplatform-lib-nodejs"), 1);
|
|
922
910
|
function valueToAssets(value) {
|
|
923
911
|
const assets = {};
|
|
924
912
|
assets["lovelace"] = value.coin();
|
|
@@ -940,7 +928,7 @@ function valueToAssets(value) {
|
|
|
940
928
|
return assets;
|
|
941
929
|
}
|
|
942
930
|
function assetsToValue(assets) {
|
|
943
|
-
const multiAsset =
|
|
931
|
+
const multiAsset = CML.MultiAsset.new();
|
|
944
932
|
const lovelace = assets["lovelace"];
|
|
945
933
|
const units = Object.keys(assets);
|
|
946
934
|
const policies = Array.from(
|
|
@@ -948,18 +936,18 @@ function assetsToValue(assets) {
|
|
|
948
936
|
units.filter((unit) => unit !== "lovelace").map((unit) => unit.slice(0, 56))
|
|
949
937
|
)
|
|
950
938
|
);
|
|
951
|
-
|
|
939
|
+
for (const policy of policies) {
|
|
952
940
|
const policyUnits = units.filter((unit) => unit.slice(0, 56) === policy);
|
|
953
|
-
const assetsValue =
|
|
954
|
-
|
|
941
|
+
const assetsValue = CML.MapAssetNameToCoin.new();
|
|
942
|
+
for (const unit of policyUnits) {
|
|
955
943
|
assetsValue.insert(
|
|
956
|
-
|
|
944
|
+
CML.AssetName.from_str((0, import_core_utils3.toText)(unit.slice(56))),
|
|
957
945
|
BigInt(assets[unit])
|
|
958
946
|
);
|
|
959
|
-
}
|
|
960
|
-
multiAsset.insert_assets(
|
|
961
|
-
}
|
|
962
|
-
return
|
|
947
|
+
}
|
|
948
|
+
multiAsset.insert_assets(CML.ScriptHash.from_hex(policy), assetsValue);
|
|
949
|
+
}
|
|
950
|
+
return CML.Value.new(lovelace, multiAsset);
|
|
963
951
|
}
|
|
964
952
|
function fromUnit(unit) {
|
|
965
953
|
const policyId = unit.slice(0, 56);
|
|
@@ -995,88 +983,46 @@ function addAssets(...assets) {
|
|
|
995
983
|
|
|
996
984
|
// src/utxo.ts
|
|
997
985
|
var utxoToTransactionOutput = (utxo) => {
|
|
998
|
-
const
|
|
999
|
-
|
|
1000
|
-
return
|
|
1001
|
-
|
|
1002
|
-
return
|
|
1003
|
-
|
|
1004
|
-
})();
|
|
1005
|
-
const datumOption = (() => {
|
|
1006
|
-
if (utxo.datumHash) {
|
|
1007
|
-
return CML9.DatumOption.new_hash(CML9.DatumHash.from_hex(utxo.datumHash));
|
|
1008
|
-
}
|
|
1009
|
-
if (!utxo.datumHash && utxo.datum) {
|
|
1010
|
-
return CML9.DatumOption.new_datum(
|
|
1011
|
-
CML9.PlutusData.from_cbor_hex(utxo.datum)
|
|
986
|
+
const datumOption = (utxo2) => {
|
|
987
|
+
if (utxo2.datumHash)
|
|
988
|
+
return CML.DatumOption.new_hash(CML.DatumHash.from_hex(utxo2.datumHash));
|
|
989
|
+
if (utxo2.datum)
|
|
990
|
+
return CML.DatumOption.new_datum(
|
|
991
|
+
CML.PlutusData.from_cbor_hex(utxo2.datum)
|
|
1012
992
|
);
|
|
1013
|
-
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
return toScriptRef(utxo.scriptRef);
|
|
1018
|
-
}
|
|
1019
|
-
})();
|
|
1020
|
-
return CML9.TransactionOutput.new(
|
|
1021
|
-
address,
|
|
993
|
+
return void 0;
|
|
994
|
+
};
|
|
995
|
+
return CML.TransactionOutput.new(
|
|
996
|
+
CML.Address.from_bech32(utxo.address),
|
|
1022
997
|
assetsToValue(utxo.assets),
|
|
1023
|
-
datumOption,
|
|
1024
|
-
scriptRef
|
|
998
|
+
datumOption(utxo),
|
|
999
|
+
utxo.scriptRef ? toScriptRef(utxo.scriptRef) : void 0
|
|
1025
1000
|
);
|
|
1026
1001
|
};
|
|
1027
1002
|
var utxoToTransactionInput = (utxo) => {
|
|
1028
|
-
return
|
|
1029
|
-
|
|
1003
|
+
return CML.TransactionInput.new(
|
|
1004
|
+
CML.TransactionHash.from_hex(utxo.txHash),
|
|
1030
1005
|
BigInt(utxo.outputIndex)
|
|
1031
1006
|
);
|
|
1032
1007
|
};
|
|
1033
1008
|
function utxoToCore(utxo) {
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
} catch (_e) {
|
|
1038
|
-
return CML9.ByronAddress.from_base58(utxo.address).to_address();
|
|
1039
|
-
}
|
|
1040
|
-
})();
|
|
1041
|
-
const datumOption = (() => {
|
|
1042
|
-
if (utxo.datumHash) {
|
|
1043
|
-
return CML9.DatumOption.new_hash(CML9.DatumHash.from_hex(utxo.datumHash));
|
|
1044
|
-
}
|
|
1045
|
-
if (!utxo.datumHash && utxo.datum) {
|
|
1046
|
-
return CML9.DatumOption.new_datum(
|
|
1047
|
-
CML9.PlutusData.from_cbor_hex(utxo.datum)
|
|
1048
|
-
);
|
|
1049
|
-
}
|
|
1050
|
-
})();
|
|
1051
|
-
const scriptRef = (() => {
|
|
1052
|
-
if (utxo.scriptRef) {
|
|
1053
|
-
return toScriptRef(utxo.scriptRef);
|
|
1054
|
-
}
|
|
1055
|
-
})();
|
|
1056
|
-
const output = CML9.TransactionOutput.new(
|
|
1057
|
-
address,
|
|
1058
|
-
assetsToValue(utxo.assets),
|
|
1059
|
-
datumOption,
|
|
1060
|
-
scriptRef
|
|
1061
|
-
);
|
|
1062
|
-
return CML9.TransactionUnspentOutput.new(
|
|
1063
|
-
CML9.TransactionInput.new(
|
|
1064
|
-
CML9.TransactionHash.from_hex(utxo.txHash),
|
|
1065
|
-
BigInt(utxo.outputIndex)
|
|
1066
|
-
),
|
|
1067
|
-
output
|
|
1009
|
+
return CML.TransactionUnspentOutput.new(
|
|
1010
|
+
utxoToTransactionInput(utxo),
|
|
1011
|
+
utxoToTransactionOutput(utxo)
|
|
1068
1012
|
);
|
|
1069
1013
|
}
|
|
1070
1014
|
function utxosToCores(utxos) {
|
|
1071
1015
|
const result = [];
|
|
1072
|
-
|
|
1016
|
+
for (const utxo of utxos) {
|
|
1017
|
+
result.push(utxoToCore(utxo));
|
|
1018
|
+
}
|
|
1073
1019
|
return result;
|
|
1074
1020
|
}
|
|
1075
1021
|
function coreToUtxo(coreUtxo) {
|
|
1076
1022
|
return {
|
|
1077
|
-
...coreToOutRef(
|
|
1023
|
+
...coreToOutRef(CML.TransactionInput.from_cbor_hex(coreUtxo.to_cbor_hex())),
|
|
1078
1024
|
...coreToTxOutput(
|
|
1079
|
-
|
|
1025
|
+
CML.TransactionOutput.from_cbor_hex(coreUtxo.to_cbor_hex())
|
|
1080
1026
|
)
|
|
1081
1027
|
};
|
|
1082
1028
|
}
|
|
@@ -1110,7 +1056,7 @@ function coreToTxOutput(output) {
|
|
|
1110
1056
|
};
|
|
1111
1057
|
}
|
|
1112
1058
|
function coresToTxOutputs(outputs) {
|
|
1113
|
-
|
|
1059
|
+
let result = [];
|
|
1114
1060
|
for (let i = 0; i < outputs.length; i++) {
|
|
1115
1061
|
result.push(coreToTxOutput(outputs[i]));
|
|
1116
1062
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -52,11 +52,11 @@ declare const utxoToTransactionInput: (utxo: UTxO) => CML.TransactionInput;
|
|
|
52
52
|
declare function utxoToCore(utxo: UTxO): CML.TransactionUnspentOutput;
|
|
53
53
|
declare function utxosToCores(utxos: UTxO[]): CML.TransactionUnspentOutput[];
|
|
54
54
|
declare function coreToUtxo(coreUtxo: CML.TransactionUnspentOutput): UTxO;
|
|
55
|
-
declare function coresToUtxos(utxos:
|
|
55
|
+
declare function coresToUtxos(utxos: CML.TransactionUnspentOutput[]): UTxO[];
|
|
56
56
|
declare function coreToOutRef(input: CML.TransactionInput): OutRef;
|
|
57
57
|
declare function coresToOutRefs(inputs: Array<CML.TransactionInput>): OutRef[];
|
|
58
58
|
declare function coreToTxOutput(output: CML.TransactionOutput): TxOutput;
|
|
59
|
-
declare function coresToTxOutputs(outputs:
|
|
59
|
+
declare function coresToTxOutputs(outputs: CML.TransactionOutput[]): TxOutput[];
|
|
60
60
|
|
|
61
61
|
declare function valueToAssets(value: CML.Value): Assets;
|
|
62
62
|
declare function assetsToValue(assets: Assets): CML.Value;
|
package/dist/index.d.ts
CHANGED
|
@@ -52,11 +52,11 @@ declare const utxoToTransactionInput: (utxo: UTxO) => CML.TransactionInput;
|
|
|
52
52
|
declare function utxoToCore(utxo: UTxO): CML.TransactionUnspentOutput;
|
|
53
53
|
declare function utxosToCores(utxos: UTxO[]): CML.TransactionUnspentOutput[];
|
|
54
54
|
declare function coreToUtxo(coreUtxo: CML.TransactionUnspentOutput): UTxO;
|
|
55
|
-
declare function coresToUtxos(utxos:
|
|
55
|
+
declare function coresToUtxos(utxos: CML.TransactionUnspentOutput[]): UTxO[];
|
|
56
56
|
declare function coreToOutRef(input: CML.TransactionInput): OutRef;
|
|
57
57
|
declare function coresToOutRefs(inputs: Array<CML.TransactionInput>): OutRef[];
|
|
58
58
|
declare function coreToTxOutput(output: CML.TransactionOutput): TxOutput;
|
|
59
|
-
declare function coresToTxOutputs(outputs:
|
|
59
|
+
declare function coresToTxOutputs(outputs: CML.TransactionOutput[]): TxOutput[];
|
|
60
60
|
|
|
61
61
|
declare function valueToAssets(value: CML.Value): Assets;
|
|
62
62
|
declare function assetsToValue(assets: Assets): CML.Value;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
// src/
|
|
1
|
+
// src/core.ts
|
|
2
2
|
import * as CML from "@dcspark/cardano-multiplatform-lib-nodejs";
|
|
3
|
+
|
|
4
|
+
// src/native.ts
|
|
3
5
|
var toNativeScript = (native) => {
|
|
4
6
|
switch (native.type) {
|
|
5
7
|
case "sig":
|
|
@@ -37,9 +39,6 @@ var nativeJSFromJson = (native) => {
|
|
|
37
39
|
};
|
|
38
40
|
};
|
|
39
41
|
|
|
40
|
-
// src/address.ts
|
|
41
|
-
import * as CML3 from "@dcspark/cardano-multiplatform-lib-nodejs";
|
|
42
|
-
|
|
43
42
|
// src/network.ts
|
|
44
43
|
function networkToId(network) {
|
|
45
44
|
switch (network) {
|
|
@@ -56,9 +55,6 @@ function networkToId(network) {
|
|
|
56
55
|
}
|
|
57
56
|
}
|
|
58
57
|
|
|
59
|
-
// src/scripts.ts
|
|
60
|
-
import * as CML2 from "@dcspark/cardano-multiplatform-lib-nodejs";
|
|
61
|
-
|
|
62
58
|
// src/cbor.ts
|
|
63
59
|
import { fromHex, toHex } from "@lucid-evolution/core-utils";
|
|
64
60
|
import { decode, encode } from "cborg";
|
|
@@ -75,35 +71,35 @@ var applyDoubleCborEncoding = (script) => {
|
|
|
75
71
|
function validatorToAddress(network, validator, stakeCredential) {
|
|
76
72
|
const validatorHash = validatorToScriptHash(validator);
|
|
77
73
|
if (stakeCredential) {
|
|
78
|
-
return
|
|
74
|
+
return CML.BaseAddress.new(
|
|
79
75
|
networkToId(network),
|
|
80
|
-
|
|
81
|
-
stakeCredential.type === "Key" ?
|
|
82
|
-
|
|
83
|
-
) :
|
|
84
|
-
|
|
76
|
+
CML.Credential.new_script(CML.ScriptHash.from_hex(validatorHash)),
|
|
77
|
+
stakeCredential.type === "Key" ? CML.Credential.new_pub_key(
|
|
78
|
+
CML.Ed25519KeyHash.from_hex(stakeCredential.hash)
|
|
79
|
+
) : CML.Credential.new_script(
|
|
80
|
+
CML.ScriptHash.from_hex(stakeCredential.hash)
|
|
85
81
|
)
|
|
86
82
|
).to_address().to_bech32(void 0);
|
|
87
83
|
} else {
|
|
88
|
-
return
|
|
84
|
+
return CML.EnterpriseAddress.new(
|
|
89
85
|
networkToId(network),
|
|
90
|
-
|
|
86
|
+
CML.Credential.new_script(CML.ScriptHash.from_hex(validatorHash))
|
|
91
87
|
).to_address().to_bech32(void 0);
|
|
92
88
|
}
|
|
93
89
|
}
|
|
94
90
|
function validatorToScriptHash(validator) {
|
|
95
91
|
switch (validator.type) {
|
|
96
92
|
case "Native":
|
|
97
|
-
return
|
|
93
|
+
return CML.NativeScript.from_cbor_hex(validator.script).hash().to_hex();
|
|
98
94
|
case "PlutusV1":
|
|
99
|
-
return
|
|
100
|
-
|
|
95
|
+
return CML.PlutusScript.from_v1(
|
|
96
|
+
CML.PlutusV1Script.from_cbor_hex(
|
|
101
97
|
applyDoubleCborEncoding(validator.script)
|
|
102
98
|
)
|
|
103
99
|
).hash().to_hex();
|
|
104
100
|
case "PlutusV2":
|
|
105
|
-
return
|
|
106
|
-
|
|
101
|
+
return CML.PlutusScript.from_v2(
|
|
102
|
+
CML.PlutusV2Script.from_cbor_hex(
|
|
107
103
|
applyDoubleCborEncoding(validator.script)
|
|
108
104
|
)
|
|
109
105
|
).hash().to_hex();
|
|
@@ -114,18 +110,18 @@ function validatorToScriptHash(validator) {
|
|
|
114
110
|
function toScriptRef(script) {
|
|
115
111
|
switch (script.type) {
|
|
116
112
|
case "Native":
|
|
117
|
-
return
|
|
118
|
-
|
|
113
|
+
return CML.Script.new_native(
|
|
114
|
+
CML.NativeScript.from_cbor_hex(script.script)
|
|
119
115
|
);
|
|
120
116
|
case "PlutusV1":
|
|
121
|
-
return
|
|
122
|
-
|
|
117
|
+
return CML.Script.new_plutus_v1(
|
|
118
|
+
CML.PlutusV1Script.from_cbor_hex(
|
|
123
119
|
applyDoubleCborEncoding(script.script)
|
|
124
120
|
)
|
|
125
121
|
);
|
|
126
122
|
case "PlutusV2":
|
|
127
|
-
return
|
|
128
|
-
|
|
123
|
+
return CML.Script.new_plutus_v2(
|
|
124
|
+
CML.PlutusV2Script.from_cbor_hex(
|
|
129
125
|
applyDoubleCborEncoding(script.script)
|
|
130
126
|
)
|
|
131
127
|
);
|
|
@@ -164,7 +160,7 @@ function nativeFromJson(nativeScript) {
|
|
|
164
160
|
function nativeScriptFromJson(nativeScript) {
|
|
165
161
|
return {
|
|
166
162
|
type: "Native",
|
|
167
|
-
script:
|
|
163
|
+
script: CML.NativeScript.from_json(
|
|
168
164
|
JSON.stringify(nativeScript)
|
|
169
165
|
).to_cbor_hex()
|
|
170
166
|
};
|
|
@@ -173,36 +169,36 @@ function nativeScriptFromJson(nativeScript) {
|
|
|
173
169
|
// src/address.ts
|
|
174
170
|
function addressFromHexOrBech32(address) {
|
|
175
171
|
try {
|
|
176
|
-
return
|
|
172
|
+
return CML.Address.from_hex(address);
|
|
177
173
|
} catch (_e) {
|
|
178
174
|
try {
|
|
179
|
-
return
|
|
175
|
+
return CML.Address.from_bech32(address);
|
|
180
176
|
} catch (_e2) {
|
|
181
177
|
throw new Error("Could not deserialize address.");
|
|
182
178
|
}
|
|
183
179
|
}
|
|
184
180
|
}
|
|
185
181
|
function credentialToRewardAddress(network, stakeCredential) {
|
|
186
|
-
return
|
|
182
|
+
return CML.RewardAddress.new(
|
|
187
183
|
networkToId(network),
|
|
188
|
-
stakeCredential.type === "Key" ?
|
|
189
|
-
|
|
190
|
-
) :
|
|
191
|
-
|
|
184
|
+
stakeCredential.type === "Key" ? CML.Credential.new_pub_key(
|
|
185
|
+
CML.Ed25519KeyHash.from_hex(stakeCredential.hash)
|
|
186
|
+
) : CML.Credential.new_script(
|
|
187
|
+
CML.ScriptHash.from_hex(stakeCredential.hash)
|
|
192
188
|
)
|
|
193
189
|
).to_address().to_bech32(void 0);
|
|
194
190
|
}
|
|
195
191
|
function validatorToRewardAddress(network, validator) {
|
|
196
192
|
const validatorHash = validatorToScriptHash(validator);
|
|
197
|
-
return
|
|
193
|
+
return CML.RewardAddress.new(
|
|
198
194
|
networkToId(network),
|
|
199
|
-
|
|
195
|
+
CML.Credential.new_script(CML.ScriptHash.from_hex(validatorHash))
|
|
200
196
|
).to_address().to_bech32(void 0);
|
|
201
197
|
}
|
|
202
198
|
function getAddressDetails(address) {
|
|
203
199
|
try {
|
|
204
|
-
const parsedAddress =
|
|
205
|
-
|
|
200
|
+
const parsedAddress = CML.BaseAddress.from_address(
|
|
201
|
+
CML.Address.from_bech32(address)
|
|
206
202
|
);
|
|
207
203
|
const paymentCredential = parsedAddress.payment().kind() === 0 ? {
|
|
208
204
|
type: "Key",
|
|
@@ -243,8 +239,8 @@ function getAddressDetails(address) {
|
|
|
243
239
|
} catch (_e) {
|
|
244
240
|
}
|
|
245
241
|
try {
|
|
246
|
-
const parsedAddress =
|
|
247
|
-
|
|
242
|
+
const parsedAddress = CML.EnterpriseAddress.from_address(
|
|
243
|
+
CML.Address.from_bech32(address)
|
|
248
244
|
);
|
|
249
245
|
const paymentCredential = parsedAddress.payment().kind() === 0 ? {
|
|
250
246
|
type: "Key",
|
|
@@ -269,8 +265,8 @@ function getAddressDetails(address) {
|
|
|
269
265
|
} catch (_e) {
|
|
270
266
|
}
|
|
271
267
|
try {
|
|
272
|
-
const parsedAddress =
|
|
273
|
-
|
|
268
|
+
const parsedAddress = CML.PointerAddress.from_address(
|
|
269
|
+
CML.Address.from_bech32(address)
|
|
274
270
|
);
|
|
275
271
|
const paymentCredential = parsedAddress?.payment().kind() === 0 ? {
|
|
276
272
|
type: "Key",
|
|
@@ -294,8 +290,8 @@ function getAddressDetails(address) {
|
|
|
294
290
|
} catch (_e) {
|
|
295
291
|
}
|
|
296
292
|
try {
|
|
297
|
-
const parsedAddress =
|
|
298
|
-
|
|
293
|
+
const parsedAddress = CML.RewardAddress.from_address(
|
|
294
|
+
CML.Address.from_bech32(address)
|
|
299
295
|
);
|
|
300
296
|
const stakeCredential = parsedAddress.payment().kind() === 0 ? {
|
|
301
297
|
type: "Key",
|
|
@@ -319,10 +315,10 @@ function getAddressDetails(address) {
|
|
|
319
315
|
try {
|
|
320
316
|
const parsedAddress = ((address2) => {
|
|
321
317
|
try {
|
|
322
|
-
return
|
|
318
|
+
return CML.ByronAddress.from_cbor_hex(address2);
|
|
323
319
|
} catch (_e) {
|
|
324
320
|
try {
|
|
325
|
-
return
|
|
321
|
+
return CML.ByronAddress.from_base58(address2);
|
|
326
322
|
} catch (_e2) {
|
|
327
323
|
throw new Error("Could not deserialize address.");
|
|
328
324
|
}
|
|
@@ -343,17 +339,16 @@ function getAddressDetails(address) {
|
|
|
343
339
|
}
|
|
344
340
|
|
|
345
341
|
// src/cost_model.ts
|
|
346
|
-
import * as CML4 from "@dcspark/cardano-multiplatform-lib-nodejs";
|
|
347
342
|
function createCostModels(costModels) {
|
|
348
|
-
const costmdls =
|
|
349
|
-
const costmdlV1 =
|
|
350
|
-
Object.values(costModels.
|
|
351
|
-
costmdlV1.add(
|
|
343
|
+
const costmdls = CML.CostModels.new();
|
|
344
|
+
const costmdlV1 = CML.IntList.new();
|
|
345
|
+
Object.values(costModels.PlutusV1).forEach((cost) => {
|
|
346
|
+
costmdlV1.add(CML.Int.new(BigInt(cost)));
|
|
352
347
|
});
|
|
353
348
|
costmdls.set_plutus_v1(costmdlV1);
|
|
354
|
-
const costmdlV2 =
|
|
349
|
+
const costmdlV2 = CML.IntList.new();
|
|
355
350
|
Object.values(costModels.PlutusV2).forEach((cost) => {
|
|
356
|
-
costmdlV2.add(
|
|
351
|
+
costmdlV2.add(CML.Int.new(BigInt(cost)));
|
|
357
352
|
});
|
|
358
353
|
costmdls.set_plutus_v2(costmdlV2);
|
|
359
354
|
return costmdls;
|
|
@@ -722,29 +717,28 @@ var PROTOCOL_PARAMETERS_DEFAULT = {
|
|
|
722
717
|
};
|
|
723
718
|
|
|
724
719
|
// src/credential.ts
|
|
725
|
-
import * as CML5 from "@dcspark/cardano-multiplatform-lib-nodejs";
|
|
726
720
|
function credentialToAddress(network, paymentCredential, stakeCredential) {
|
|
727
721
|
if (stakeCredential) {
|
|
728
|
-
return
|
|
722
|
+
return CML.BaseAddress.new(
|
|
729
723
|
networkToId(network),
|
|
730
|
-
paymentCredential.type === "Key" ?
|
|
731
|
-
|
|
732
|
-
) :
|
|
733
|
-
|
|
724
|
+
paymentCredential.type === "Key" ? CML.Credential.new_pub_key(
|
|
725
|
+
CML.Ed25519KeyHash.from_hex(paymentCredential.hash)
|
|
726
|
+
) : CML.Credential.new_script(
|
|
727
|
+
CML.ScriptHash.from_hex(paymentCredential.hash)
|
|
734
728
|
),
|
|
735
|
-
stakeCredential.type === "Key" ?
|
|
736
|
-
|
|
737
|
-
) :
|
|
738
|
-
|
|
729
|
+
stakeCredential.type === "Key" ? CML.Credential.new_pub_key(
|
|
730
|
+
CML.Ed25519KeyHash.from_hex(stakeCredential.hash)
|
|
731
|
+
) : CML.Credential.new_script(
|
|
732
|
+
CML.ScriptHash.from_hex(stakeCredential.hash)
|
|
739
733
|
)
|
|
740
734
|
).to_address().to_bech32(void 0);
|
|
741
735
|
} else {
|
|
742
|
-
return
|
|
736
|
+
return CML.EnterpriseAddress.new(
|
|
743
737
|
networkToId(network),
|
|
744
|
-
paymentCredential.type === "Key" ?
|
|
745
|
-
|
|
746
|
-
) :
|
|
747
|
-
|
|
738
|
+
paymentCredential.type === "Key" ? CML.Credential.new_pub_key(
|
|
739
|
+
CML.Ed25519KeyHash.from_hex(paymentCredential.hash)
|
|
740
|
+
) : CML.Credential.new_script(
|
|
741
|
+
CML.ScriptHash.from_hex(paymentCredential.hash)
|
|
748
742
|
)
|
|
749
743
|
).to_address().to_bech32(void 0);
|
|
750
744
|
}
|
|
@@ -781,22 +775,20 @@ function stakeCredentialOf(rewardAddress) {
|
|
|
781
775
|
}
|
|
782
776
|
|
|
783
777
|
// src/datum.ts
|
|
784
|
-
import * as CML6 from "@dcspark/cardano-multiplatform-lib-nodejs";
|
|
785
778
|
function datumToHash(datum) {
|
|
786
|
-
return
|
|
779
|
+
return CML.hash_plutus_data(CML.PlutusData.from_cbor_hex(datum)).to_hex();
|
|
787
780
|
}
|
|
788
781
|
|
|
789
782
|
// src/keys.ts
|
|
790
783
|
import { generateMnemonic } from "@lucid-evolution/bip39";
|
|
791
|
-
import * as CML7 from "@dcspark/cardano-multiplatform-lib-nodejs";
|
|
792
784
|
function generatePrivateKey() {
|
|
793
|
-
return
|
|
785
|
+
return CML.PrivateKey.generate_ed25519().to_bech32();
|
|
794
786
|
}
|
|
795
787
|
function generateSeedPhrase() {
|
|
796
788
|
return generateMnemonic(256);
|
|
797
789
|
}
|
|
798
790
|
function toPublicKey(privateKey) {
|
|
799
|
-
return
|
|
791
|
+
return CML.PrivateKey.from_bech32(privateKey).to_public().to_bech32();
|
|
800
792
|
}
|
|
801
793
|
|
|
802
794
|
// src/label.ts
|
|
@@ -837,12 +829,8 @@ function slotToUnixTime(network, slot) {
|
|
|
837
829
|
return slotToBeginUnixTime(slot, SLOT_CONFIG_NETWORK[network]);
|
|
838
830
|
}
|
|
839
831
|
|
|
840
|
-
// src/utxo.ts
|
|
841
|
-
import * as CML9 from "@dcspark/cardano-multiplatform-lib-nodejs";
|
|
842
|
-
|
|
843
832
|
// src/value.ts
|
|
844
833
|
import { toText } from "@lucid-evolution/core-utils";
|
|
845
|
-
import * as CML8 from "@dcspark/cardano-multiplatform-lib-nodejs";
|
|
846
834
|
function valueToAssets(value) {
|
|
847
835
|
const assets = {};
|
|
848
836
|
assets["lovelace"] = value.coin();
|
|
@@ -864,7 +852,7 @@ function valueToAssets(value) {
|
|
|
864
852
|
return assets;
|
|
865
853
|
}
|
|
866
854
|
function assetsToValue(assets) {
|
|
867
|
-
const multiAsset =
|
|
855
|
+
const multiAsset = CML.MultiAsset.new();
|
|
868
856
|
const lovelace = assets["lovelace"];
|
|
869
857
|
const units = Object.keys(assets);
|
|
870
858
|
const policies = Array.from(
|
|
@@ -872,18 +860,18 @@ function assetsToValue(assets) {
|
|
|
872
860
|
units.filter((unit) => unit !== "lovelace").map((unit) => unit.slice(0, 56))
|
|
873
861
|
)
|
|
874
862
|
);
|
|
875
|
-
|
|
863
|
+
for (const policy of policies) {
|
|
876
864
|
const policyUnits = units.filter((unit) => unit.slice(0, 56) === policy);
|
|
877
|
-
const assetsValue =
|
|
878
|
-
|
|
865
|
+
const assetsValue = CML.MapAssetNameToCoin.new();
|
|
866
|
+
for (const unit of policyUnits) {
|
|
879
867
|
assetsValue.insert(
|
|
880
|
-
|
|
868
|
+
CML.AssetName.from_str(toText(unit.slice(56))),
|
|
881
869
|
BigInt(assets[unit])
|
|
882
870
|
);
|
|
883
|
-
}
|
|
884
|
-
multiAsset.insert_assets(
|
|
885
|
-
}
|
|
886
|
-
return
|
|
871
|
+
}
|
|
872
|
+
multiAsset.insert_assets(CML.ScriptHash.from_hex(policy), assetsValue);
|
|
873
|
+
}
|
|
874
|
+
return CML.Value.new(lovelace, multiAsset);
|
|
887
875
|
}
|
|
888
876
|
function fromUnit(unit) {
|
|
889
877
|
const policyId = unit.slice(0, 56);
|
|
@@ -919,88 +907,46 @@ function addAssets(...assets) {
|
|
|
919
907
|
|
|
920
908
|
// src/utxo.ts
|
|
921
909
|
var utxoToTransactionOutput = (utxo) => {
|
|
922
|
-
const
|
|
923
|
-
|
|
924
|
-
return
|
|
925
|
-
|
|
926
|
-
return
|
|
927
|
-
|
|
928
|
-
})();
|
|
929
|
-
const datumOption = (() => {
|
|
930
|
-
if (utxo.datumHash) {
|
|
931
|
-
return CML9.DatumOption.new_hash(CML9.DatumHash.from_hex(utxo.datumHash));
|
|
932
|
-
}
|
|
933
|
-
if (!utxo.datumHash && utxo.datum) {
|
|
934
|
-
return CML9.DatumOption.new_datum(
|
|
935
|
-
CML9.PlutusData.from_cbor_hex(utxo.datum)
|
|
910
|
+
const datumOption = (utxo2) => {
|
|
911
|
+
if (utxo2.datumHash)
|
|
912
|
+
return CML.DatumOption.new_hash(CML.DatumHash.from_hex(utxo2.datumHash));
|
|
913
|
+
if (utxo2.datum)
|
|
914
|
+
return CML.DatumOption.new_datum(
|
|
915
|
+
CML.PlutusData.from_cbor_hex(utxo2.datum)
|
|
936
916
|
);
|
|
937
|
-
|
|
938
|
-
}
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
return toScriptRef(utxo.scriptRef);
|
|
942
|
-
}
|
|
943
|
-
})();
|
|
944
|
-
return CML9.TransactionOutput.new(
|
|
945
|
-
address,
|
|
917
|
+
return void 0;
|
|
918
|
+
};
|
|
919
|
+
return CML.TransactionOutput.new(
|
|
920
|
+
CML.Address.from_bech32(utxo.address),
|
|
946
921
|
assetsToValue(utxo.assets),
|
|
947
|
-
datumOption,
|
|
948
|
-
scriptRef
|
|
922
|
+
datumOption(utxo),
|
|
923
|
+
utxo.scriptRef ? toScriptRef(utxo.scriptRef) : void 0
|
|
949
924
|
);
|
|
950
925
|
};
|
|
951
926
|
var utxoToTransactionInput = (utxo) => {
|
|
952
|
-
return
|
|
953
|
-
|
|
927
|
+
return CML.TransactionInput.new(
|
|
928
|
+
CML.TransactionHash.from_hex(utxo.txHash),
|
|
954
929
|
BigInt(utxo.outputIndex)
|
|
955
930
|
);
|
|
956
931
|
};
|
|
957
932
|
function utxoToCore(utxo) {
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
} catch (_e) {
|
|
962
|
-
return CML9.ByronAddress.from_base58(utxo.address).to_address();
|
|
963
|
-
}
|
|
964
|
-
})();
|
|
965
|
-
const datumOption = (() => {
|
|
966
|
-
if (utxo.datumHash) {
|
|
967
|
-
return CML9.DatumOption.new_hash(CML9.DatumHash.from_hex(utxo.datumHash));
|
|
968
|
-
}
|
|
969
|
-
if (!utxo.datumHash && utxo.datum) {
|
|
970
|
-
return CML9.DatumOption.new_datum(
|
|
971
|
-
CML9.PlutusData.from_cbor_hex(utxo.datum)
|
|
972
|
-
);
|
|
973
|
-
}
|
|
974
|
-
})();
|
|
975
|
-
const scriptRef = (() => {
|
|
976
|
-
if (utxo.scriptRef) {
|
|
977
|
-
return toScriptRef(utxo.scriptRef);
|
|
978
|
-
}
|
|
979
|
-
})();
|
|
980
|
-
const output = CML9.TransactionOutput.new(
|
|
981
|
-
address,
|
|
982
|
-
assetsToValue(utxo.assets),
|
|
983
|
-
datumOption,
|
|
984
|
-
scriptRef
|
|
985
|
-
);
|
|
986
|
-
return CML9.TransactionUnspentOutput.new(
|
|
987
|
-
CML9.TransactionInput.new(
|
|
988
|
-
CML9.TransactionHash.from_hex(utxo.txHash),
|
|
989
|
-
BigInt(utxo.outputIndex)
|
|
990
|
-
),
|
|
991
|
-
output
|
|
933
|
+
return CML.TransactionUnspentOutput.new(
|
|
934
|
+
utxoToTransactionInput(utxo),
|
|
935
|
+
utxoToTransactionOutput(utxo)
|
|
992
936
|
);
|
|
993
937
|
}
|
|
994
938
|
function utxosToCores(utxos) {
|
|
995
939
|
const result = [];
|
|
996
|
-
|
|
940
|
+
for (const utxo of utxos) {
|
|
941
|
+
result.push(utxoToCore(utxo));
|
|
942
|
+
}
|
|
997
943
|
return result;
|
|
998
944
|
}
|
|
999
945
|
function coreToUtxo(coreUtxo) {
|
|
1000
946
|
return {
|
|
1001
|
-
...coreToOutRef(
|
|
947
|
+
...coreToOutRef(CML.TransactionInput.from_cbor_hex(coreUtxo.to_cbor_hex())),
|
|
1002
948
|
...coreToTxOutput(
|
|
1003
|
-
|
|
949
|
+
CML.TransactionOutput.from_cbor_hex(coreUtxo.to_cbor_hex())
|
|
1004
950
|
)
|
|
1005
951
|
};
|
|
1006
952
|
}
|
|
@@ -1034,7 +980,7 @@ function coreToTxOutput(output) {
|
|
|
1034
980
|
};
|
|
1035
981
|
}
|
|
1036
982
|
function coresToTxOutputs(outputs) {
|
|
1037
|
-
|
|
983
|
+
let result = [];
|
|
1038
984
|
for (let i = 0; i < outputs.length; i++) {
|
|
1039
985
|
result.push(coreToTxOutput(outputs[i]));
|
|
1040
986
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lucid-evolution/utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -22,19 +22,19 @@
|
|
|
22
22
|
"author": "",
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@dcspark/cardano-multiplatform-lib-nodejs": "^5.
|
|
26
|
-
"cborg": "^4.
|
|
27
|
-
"@lucid-evolution/bip39": "0.2.
|
|
28
|
-
"@lucid-evolution/core-types": "0.1.
|
|
29
|
-
"@lucid-evolution/core-utils": "0.1.
|
|
30
|
-
"@lucid-evolution/crc8": "0.1.
|
|
31
|
-
"@lucid-evolution/plutus": "0.1.
|
|
25
|
+
"@dcspark/cardano-multiplatform-lib-nodejs": "^5.3.0",
|
|
26
|
+
"cborg": "^4.2.0",
|
|
27
|
+
"@lucid-evolution/bip39": "0.2.6",
|
|
28
|
+
"@lucid-evolution/core-types": "0.1.5",
|
|
29
|
+
"@lucid-evolution/core-utils": "0.1.5",
|
|
30
|
+
"@lucid-evolution/crc8": "0.1.5",
|
|
31
|
+
"@lucid-evolution/plutus": "0.1.8"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@types/node": "^20.
|
|
34
|
+
"@types/node": "^20.12.8",
|
|
35
35
|
"tsup": "^8.0.2",
|
|
36
|
-
"typescript": "^5.
|
|
37
|
-
"vitest": "^1.
|
|
36
|
+
"typescript": "^5.4.5",
|
|
37
|
+
"vitest": "^1.6.0"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "tsup-node src/index.ts --format esm,cjs --dts --clean",
|