@lucid-evolution/utils 0.1.6 → 0.1.8
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 +119 -161
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +119 -161
- 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,19 +419,24 @@ 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
|
-
|
|
432
|
-
|
|
423
|
+
const costmdls = CML.CostModels.new();
|
|
424
|
+
const costmdlV1 = CML.IntList.new();
|
|
425
|
+
for (const cost of Object.values(costModels.PlutusV1)) {
|
|
426
|
+
const int = CML.Int.from_str(cost.toString());
|
|
427
|
+
costmdlV1.add(int);
|
|
428
|
+
int.free();
|
|
429
|
+
}
|
|
433
430
|
costmdls.set_plutus_v1(costmdlV1);
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
431
|
+
costmdlV1.free();
|
|
432
|
+
const costmdlV2 = CML.IntList.new();
|
|
433
|
+
for (const cost of Object.values(costModels.PlutusV2)) {
|
|
434
|
+
const int = CML.Int.from_str(cost.toString());
|
|
435
|
+
costmdlV2.add(int);
|
|
436
|
+
int.free();
|
|
437
|
+
}
|
|
438
438
|
costmdls.set_plutus_v2(costmdlV2);
|
|
439
|
+
costmdlV2.free();
|
|
439
440
|
return costmdls;
|
|
440
441
|
}
|
|
441
442
|
var PROTOCOL_PARAMETERS_DEFAULT = {
|
|
@@ -802,29 +803,28 @@ var PROTOCOL_PARAMETERS_DEFAULT = {
|
|
|
802
803
|
};
|
|
803
804
|
|
|
804
805
|
// src/credential.ts
|
|
805
|
-
var CML5 = __toESM(require("@dcspark/cardano-multiplatform-lib-nodejs"), 1);
|
|
806
806
|
function credentialToAddress(network, paymentCredential, stakeCredential) {
|
|
807
807
|
if (stakeCredential) {
|
|
808
|
-
return
|
|
808
|
+
return CML.BaseAddress.new(
|
|
809
809
|
networkToId(network),
|
|
810
|
-
paymentCredential.type === "Key" ?
|
|
811
|
-
|
|
812
|
-
) :
|
|
813
|
-
|
|
810
|
+
paymentCredential.type === "Key" ? CML.Credential.new_pub_key(
|
|
811
|
+
CML.Ed25519KeyHash.from_hex(paymentCredential.hash)
|
|
812
|
+
) : CML.Credential.new_script(
|
|
813
|
+
CML.ScriptHash.from_hex(paymentCredential.hash)
|
|
814
814
|
),
|
|
815
|
-
stakeCredential.type === "Key" ?
|
|
816
|
-
|
|
817
|
-
) :
|
|
818
|
-
|
|
815
|
+
stakeCredential.type === "Key" ? CML.Credential.new_pub_key(
|
|
816
|
+
CML.Ed25519KeyHash.from_hex(stakeCredential.hash)
|
|
817
|
+
) : CML.Credential.new_script(
|
|
818
|
+
CML.ScriptHash.from_hex(stakeCredential.hash)
|
|
819
819
|
)
|
|
820
820
|
).to_address().to_bech32(void 0);
|
|
821
821
|
} else {
|
|
822
|
-
return
|
|
822
|
+
return CML.EnterpriseAddress.new(
|
|
823
823
|
networkToId(network),
|
|
824
|
-
paymentCredential.type === "Key" ?
|
|
825
|
-
|
|
826
|
-
) :
|
|
827
|
-
|
|
824
|
+
paymentCredential.type === "Key" ? CML.Credential.new_pub_key(
|
|
825
|
+
CML.Ed25519KeyHash.from_hex(paymentCredential.hash)
|
|
826
|
+
) : CML.Credential.new_script(
|
|
827
|
+
CML.ScriptHash.from_hex(paymentCredential.hash)
|
|
828
828
|
)
|
|
829
829
|
).to_address().to_bech32(void 0);
|
|
830
830
|
}
|
|
@@ -861,22 +861,20 @@ function stakeCredentialOf(rewardAddress) {
|
|
|
861
861
|
}
|
|
862
862
|
|
|
863
863
|
// src/datum.ts
|
|
864
|
-
var CML6 = __toESM(require("@dcspark/cardano-multiplatform-lib-nodejs"), 1);
|
|
865
864
|
function datumToHash(datum) {
|
|
866
|
-
return
|
|
865
|
+
return CML.hash_plutus_data(CML.PlutusData.from_cbor_hex(datum)).to_hex();
|
|
867
866
|
}
|
|
868
867
|
|
|
869
868
|
// src/keys.ts
|
|
870
869
|
var import_bip39 = require("@lucid-evolution/bip39");
|
|
871
|
-
var CML7 = __toESM(require("@dcspark/cardano-multiplatform-lib-nodejs"), 1);
|
|
872
870
|
function generatePrivateKey() {
|
|
873
|
-
return
|
|
871
|
+
return CML.PrivateKey.generate_ed25519().to_bech32();
|
|
874
872
|
}
|
|
875
873
|
function generateSeedPhrase() {
|
|
876
874
|
return (0, import_bip39.generateMnemonic)(256);
|
|
877
875
|
}
|
|
878
876
|
function toPublicKey(privateKey) {
|
|
879
|
-
return
|
|
877
|
+
return CML.PrivateKey.from_bech32(privateKey).to_public().to_bech32();
|
|
880
878
|
}
|
|
881
879
|
|
|
882
880
|
// src/label.ts
|
|
@@ -913,12 +911,8 @@ function slotToUnixTime(network, slot) {
|
|
|
913
911
|
return (0, import_plutus.slotToBeginUnixTime)(slot, import_plutus.SLOT_CONFIG_NETWORK[network]);
|
|
914
912
|
}
|
|
915
913
|
|
|
916
|
-
// src/utxo.ts
|
|
917
|
-
var CML9 = __toESM(require("@dcspark/cardano-multiplatform-lib-nodejs"), 1);
|
|
918
|
-
|
|
919
914
|
// src/value.ts
|
|
920
915
|
var import_core_utils3 = require("@lucid-evolution/core-utils");
|
|
921
|
-
var CML8 = __toESM(require("@dcspark/cardano-multiplatform-lib-nodejs"), 1);
|
|
922
916
|
function valueToAssets(value) {
|
|
923
917
|
const assets = {};
|
|
924
918
|
assets["lovelace"] = value.coin();
|
|
@@ -940,7 +934,7 @@ function valueToAssets(value) {
|
|
|
940
934
|
return assets;
|
|
941
935
|
}
|
|
942
936
|
function assetsToValue(assets) {
|
|
943
|
-
const multiAsset =
|
|
937
|
+
const multiAsset = CML.MultiAsset.new();
|
|
944
938
|
const lovelace = assets["lovelace"];
|
|
945
939
|
const units = Object.keys(assets);
|
|
946
940
|
const policies = Array.from(
|
|
@@ -948,18 +942,18 @@ function assetsToValue(assets) {
|
|
|
948
942
|
units.filter((unit) => unit !== "lovelace").map((unit) => unit.slice(0, 56))
|
|
949
943
|
)
|
|
950
944
|
);
|
|
951
|
-
|
|
945
|
+
for (const policy of policies) {
|
|
952
946
|
const policyUnits = units.filter((unit) => unit.slice(0, 56) === policy);
|
|
953
|
-
const assetsValue =
|
|
954
|
-
|
|
947
|
+
const assetsValue = CML.MapAssetNameToCoin.new();
|
|
948
|
+
for (const unit of policyUnits) {
|
|
955
949
|
assetsValue.insert(
|
|
956
|
-
|
|
950
|
+
CML.AssetName.from_str((0, import_core_utils3.toText)(unit.slice(56))),
|
|
957
951
|
BigInt(assets[unit])
|
|
958
952
|
);
|
|
959
|
-
}
|
|
960
|
-
multiAsset.insert_assets(
|
|
961
|
-
}
|
|
962
|
-
return
|
|
953
|
+
}
|
|
954
|
+
multiAsset.insert_assets(CML.ScriptHash.from_hex(policy), assetsValue);
|
|
955
|
+
}
|
|
956
|
+
return CML.Value.new(lovelace, multiAsset);
|
|
963
957
|
}
|
|
964
958
|
function fromUnit(unit) {
|
|
965
959
|
const policyId = unit.slice(0, 56);
|
|
@@ -995,90 +989,54 @@ function addAssets(...assets) {
|
|
|
995
989
|
|
|
996
990
|
// src/utxo.ts
|
|
997
991
|
var utxoToTransactionOutput = (utxo) => {
|
|
998
|
-
const
|
|
999
|
-
|
|
1000
|
-
return
|
|
1001
|
-
|
|
1002
|
-
return CML9.ByronAddress.from_base58(utxo.address).to_address();
|
|
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)
|
|
992
|
+
const buildDatum = (utxo2, builder) => {
|
|
993
|
+
if (utxo2.datumHash)
|
|
994
|
+
return builder.with_data(
|
|
995
|
+
CML.DatumOption.new_hash(CML.DatumHash.from_hex(utxo2.datumHash))
|
|
1012
996
|
);
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
);
|
|
997
|
+
if (utxo2.datum)
|
|
998
|
+
return builder.with_data(
|
|
999
|
+
CML.DatumOption.new_datum(CML.PlutusData.from_cbor_hex(utxo2.datum))
|
|
1000
|
+
);
|
|
1001
|
+
return builder;
|
|
1002
|
+
};
|
|
1003
|
+
const buildOutput = (utxo2) => {
|
|
1004
|
+
const builder = CML.TransactionOutputBuilder.new().with_address(
|
|
1005
|
+
CML.Address.from_bech32(utxo2.address)
|
|
1006
|
+
);
|
|
1007
|
+
return utxo2.scriptRef ? buildDatum(utxo2, builder).with_reference_script(toScriptRef(utxo2.scriptRef)).next() : buildDatum(utxo2, builder).next();
|
|
1008
|
+
};
|
|
1009
|
+
return buildOutput(utxo).with_value(assetsToValue(utxo.assets)).build().output();
|
|
1026
1010
|
};
|
|
1027
1011
|
var utxoToTransactionInput = (utxo) => {
|
|
1028
|
-
return
|
|
1029
|
-
|
|
1012
|
+
return CML.TransactionInput.new(
|
|
1013
|
+
CML.TransactionHash.from_hex(utxo.txHash),
|
|
1030
1014
|
BigInt(utxo.outputIndex)
|
|
1031
1015
|
);
|
|
1032
1016
|
};
|
|
1033
|
-
|
|
1034
|
-
const
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
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
|
|
1017
|
+
var utxoToCore = (utxo) => {
|
|
1018
|
+
const out = utxoToTransactionOutput(utxo);
|
|
1019
|
+
const utxoCore = CML.TransactionUnspentOutput.new(
|
|
1020
|
+
utxoToTransactionInput(utxo),
|
|
1021
|
+
out
|
|
1061
1022
|
);
|
|
1062
|
-
return
|
|
1063
|
-
|
|
1064
|
-
CML9.TransactionHash.from_hex(utxo.txHash),
|
|
1065
|
-
BigInt(utxo.outputIndex)
|
|
1066
|
-
),
|
|
1067
|
-
output
|
|
1068
|
-
);
|
|
1069
|
-
}
|
|
1023
|
+
return utxoCore;
|
|
1024
|
+
};
|
|
1070
1025
|
function utxosToCores(utxos) {
|
|
1071
1026
|
const result = [];
|
|
1072
|
-
|
|
1027
|
+
for (const utxo of utxos) {
|
|
1028
|
+
result.push(utxoToCore(utxo));
|
|
1029
|
+
}
|
|
1073
1030
|
return result;
|
|
1074
1031
|
}
|
|
1075
1032
|
function coreToUtxo(coreUtxo) {
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
...
|
|
1079
|
-
|
|
1080
|
-
)
|
|
1033
|
+
const out = CML.TransactionOutput.from_cbor_hex(coreUtxo.to_cbor_hex());
|
|
1034
|
+
const utxo = {
|
|
1035
|
+
...coreToOutRef(CML.TransactionInput.from_cbor_hex(coreUtxo.to_cbor_hex())),
|
|
1036
|
+
...coreToTxOutput(out)
|
|
1081
1037
|
};
|
|
1038
|
+
out.free();
|
|
1039
|
+
return utxo;
|
|
1082
1040
|
}
|
|
1083
1041
|
function coresToUtxos(utxos) {
|
|
1084
1042
|
const result = [];
|
|
@@ -1110,7 +1068,7 @@ function coreToTxOutput(output) {
|
|
|
1110
1068
|
};
|
|
1111
1069
|
}
|
|
1112
1070
|
function coresToTxOutputs(outputs) {
|
|
1113
|
-
|
|
1071
|
+
let result = [];
|
|
1114
1072
|
for (let i = 0; i < outputs.length; i++) {
|
|
1115
1073
|
result.push(coreToTxOutput(outputs[i]));
|
|
1116
1074
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -49,14 +49,14 @@ declare function slotToUnixTime(network: Network, slot: Slot): UnixTime;
|
|
|
49
49
|
|
|
50
50
|
declare const utxoToTransactionOutput: (utxo: UTxO) => CML.TransactionOutput;
|
|
51
51
|
declare const utxoToTransactionInput: (utxo: UTxO) => CML.TransactionInput;
|
|
52
|
-
declare
|
|
52
|
+
declare const 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
|
@@ -49,14 +49,14 @@ declare function slotToUnixTime(network: Network, slot: Slot): UnixTime;
|
|
|
49
49
|
|
|
50
50
|
declare const utxoToTransactionOutput: (utxo: UTxO) => CML.TransactionOutput;
|
|
51
51
|
declare const utxoToTransactionInput: (utxo: UTxO) => CML.TransactionInput;
|
|
52
|
-
declare
|
|
52
|
+
declare const 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,19 +339,24 @@ 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
|
-
|
|
352
|
-
|
|
343
|
+
const costmdls = CML.CostModels.new();
|
|
344
|
+
const costmdlV1 = CML.IntList.new();
|
|
345
|
+
for (const cost of Object.values(costModels.PlutusV1)) {
|
|
346
|
+
const int = CML.Int.from_str(cost.toString());
|
|
347
|
+
costmdlV1.add(int);
|
|
348
|
+
int.free();
|
|
349
|
+
}
|
|
353
350
|
costmdls.set_plutus_v1(costmdlV1);
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
351
|
+
costmdlV1.free();
|
|
352
|
+
const costmdlV2 = CML.IntList.new();
|
|
353
|
+
for (const cost of Object.values(costModels.PlutusV2)) {
|
|
354
|
+
const int = CML.Int.from_str(cost.toString());
|
|
355
|
+
costmdlV2.add(int);
|
|
356
|
+
int.free();
|
|
357
|
+
}
|
|
358
358
|
costmdls.set_plutus_v2(costmdlV2);
|
|
359
|
+
costmdlV2.free();
|
|
359
360
|
return costmdls;
|
|
360
361
|
}
|
|
361
362
|
var PROTOCOL_PARAMETERS_DEFAULT = {
|
|
@@ -722,29 +723,28 @@ var PROTOCOL_PARAMETERS_DEFAULT = {
|
|
|
722
723
|
};
|
|
723
724
|
|
|
724
725
|
// src/credential.ts
|
|
725
|
-
import * as CML5 from "@dcspark/cardano-multiplatform-lib-nodejs";
|
|
726
726
|
function credentialToAddress(network, paymentCredential, stakeCredential) {
|
|
727
727
|
if (stakeCredential) {
|
|
728
|
-
return
|
|
728
|
+
return CML.BaseAddress.new(
|
|
729
729
|
networkToId(network),
|
|
730
|
-
paymentCredential.type === "Key" ?
|
|
731
|
-
|
|
732
|
-
) :
|
|
733
|
-
|
|
730
|
+
paymentCredential.type === "Key" ? CML.Credential.new_pub_key(
|
|
731
|
+
CML.Ed25519KeyHash.from_hex(paymentCredential.hash)
|
|
732
|
+
) : CML.Credential.new_script(
|
|
733
|
+
CML.ScriptHash.from_hex(paymentCredential.hash)
|
|
734
734
|
),
|
|
735
|
-
stakeCredential.type === "Key" ?
|
|
736
|
-
|
|
737
|
-
) :
|
|
738
|
-
|
|
735
|
+
stakeCredential.type === "Key" ? CML.Credential.new_pub_key(
|
|
736
|
+
CML.Ed25519KeyHash.from_hex(stakeCredential.hash)
|
|
737
|
+
) : CML.Credential.new_script(
|
|
738
|
+
CML.ScriptHash.from_hex(stakeCredential.hash)
|
|
739
739
|
)
|
|
740
740
|
).to_address().to_bech32(void 0);
|
|
741
741
|
} else {
|
|
742
|
-
return
|
|
742
|
+
return CML.EnterpriseAddress.new(
|
|
743
743
|
networkToId(network),
|
|
744
|
-
paymentCredential.type === "Key" ?
|
|
745
|
-
|
|
746
|
-
) :
|
|
747
|
-
|
|
744
|
+
paymentCredential.type === "Key" ? CML.Credential.new_pub_key(
|
|
745
|
+
CML.Ed25519KeyHash.from_hex(paymentCredential.hash)
|
|
746
|
+
) : CML.Credential.new_script(
|
|
747
|
+
CML.ScriptHash.from_hex(paymentCredential.hash)
|
|
748
748
|
)
|
|
749
749
|
).to_address().to_bech32(void 0);
|
|
750
750
|
}
|
|
@@ -781,22 +781,20 @@ function stakeCredentialOf(rewardAddress) {
|
|
|
781
781
|
}
|
|
782
782
|
|
|
783
783
|
// src/datum.ts
|
|
784
|
-
import * as CML6 from "@dcspark/cardano-multiplatform-lib-nodejs";
|
|
785
784
|
function datumToHash(datum) {
|
|
786
|
-
return
|
|
785
|
+
return CML.hash_plutus_data(CML.PlutusData.from_cbor_hex(datum)).to_hex();
|
|
787
786
|
}
|
|
788
787
|
|
|
789
788
|
// src/keys.ts
|
|
790
789
|
import { generateMnemonic } from "@lucid-evolution/bip39";
|
|
791
|
-
import * as CML7 from "@dcspark/cardano-multiplatform-lib-nodejs";
|
|
792
790
|
function generatePrivateKey() {
|
|
793
|
-
return
|
|
791
|
+
return CML.PrivateKey.generate_ed25519().to_bech32();
|
|
794
792
|
}
|
|
795
793
|
function generateSeedPhrase() {
|
|
796
794
|
return generateMnemonic(256);
|
|
797
795
|
}
|
|
798
796
|
function toPublicKey(privateKey) {
|
|
799
|
-
return
|
|
797
|
+
return CML.PrivateKey.from_bech32(privateKey).to_public().to_bech32();
|
|
800
798
|
}
|
|
801
799
|
|
|
802
800
|
// src/label.ts
|
|
@@ -837,12 +835,8 @@ function slotToUnixTime(network, slot) {
|
|
|
837
835
|
return slotToBeginUnixTime(slot, SLOT_CONFIG_NETWORK[network]);
|
|
838
836
|
}
|
|
839
837
|
|
|
840
|
-
// src/utxo.ts
|
|
841
|
-
import * as CML9 from "@dcspark/cardano-multiplatform-lib-nodejs";
|
|
842
|
-
|
|
843
838
|
// src/value.ts
|
|
844
839
|
import { toText } from "@lucid-evolution/core-utils";
|
|
845
|
-
import * as CML8 from "@dcspark/cardano-multiplatform-lib-nodejs";
|
|
846
840
|
function valueToAssets(value) {
|
|
847
841
|
const assets = {};
|
|
848
842
|
assets["lovelace"] = value.coin();
|
|
@@ -864,7 +858,7 @@ function valueToAssets(value) {
|
|
|
864
858
|
return assets;
|
|
865
859
|
}
|
|
866
860
|
function assetsToValue(assets) {
|
|
867
|
-
const multiAsset =
|
|
861
|
+
const multiAsset = CML.MultiAsset.new();
|
|
868
862
|
const lovelace = assets["lovelace"];
|
|
869
863
|
const units = Object.keys(assets);
|
|
870
864
|
const policies = Array.from(
|
|
@@ -872,18 +866,18 @@ function assetsToValue(assets) {
|
|
|
872
866
|
units.filter((unit) => unit !== "lovelace").map((unit) => unit.slice(0, 56))
|
|
873
867
|
)
|
|
874
868
|
);
|
|
875
|
-
|
|
869
|
+
for (const policy of policies) {
|
|
876
870
|
const policyUnits = units.filter((unit) => unit.slice(0, 56) === policy);
|
|
877
|
-
const assetsValue =
|
|
878
|
-
|
|
871
|
+
const assetsValue = CML.MapAssetNameToCoin.new();
|
|
872
|
+
for (const unit of policyUnits) {
|
|
879
873
|
assetsValue.insert(
|
|
880
|
-
|
|
874
|
+
CML.AssetName.from_str(toText(unit.slice(56))),
|
|
881
875
|
BigInt(assets[unit])
|
|
882
876
|
);
|
|
883
|
-
}
|
|
884
|
-
multiAsset.insert_assets(
|
|
885
|
-
}
|
|
886
|
-
return
|
|
877
|
+
}
|
|
878
|
+
multiAsset.insert_assets(CML.ScriptHash.from_hex(policy), assetsValue);
|
|
879
|
+
}
|
|
880
|
+
return CML.Value.new(lovelace, multiAsset);
|
|
887
881
|
}
|
|
888
882
|
function fromUnit(unit) {
|
|
889
883
|
const policyId = unit.slice(0, 56);
|
|
@@ -919,90 +913,54 @@ function addAssets(...assets) {
|
|
|
919
913
|
|
|
920
914
|
// src/utxo.ts
|
|
921
915
|
var utxoToTransactionOutput = (utxo) => {
|
|
922
|
-
const
|
|
923
|
-
|
|
924
|
-
return
|
|
925
|
-
|
|
926
|
-
return CML9.ByronAddress.from_base58(utxo.address).to_address();
|
|
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)
|
|
916
|
+
const buildDatum = (utxo2, builder) => {
|
|
917
|
+
if (utxo2.datumHash)
|
|
918
|
+
return builder.with_data(
|
|
919
|
+
CML.DatumOption.new_hash(CML.DatumHash.from_hex(utxo2.datumHash))
|
|
936
920
|
);
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
);
|
|
921
|
+
if (utxo2.datum)
|
|
922
|
+
return builder.with_data(
|
|
923
|
+
CML.DatumOption.new_datum(CML.PlutusData.from_cbor_hex(utxo2.datum))
|
|
924
|
+
);
|
|
925
|
+
return builder;
|
|
926
|
+
};
|
|
927
|
+
const buildOutput = (utxo2) => {
|
|
928
|
+
const builder = CML.TransactionOutputBuilder.new().with_address(
|
|
929
|
+
CML.Address.from_bech32(utxo2.address)
|
|
930
|
+
);
|
|
931
|
+
return utxo2.scriptRef ? buildDatum(utxo2, builder).with_reference_script(toScriptRef(utxo2.scriptRef)).next() : buildDatum(utxo2, builder).next();
|
|
932
|
+
};
|
|
933
|
+
return buildOutput(utxo).with_value(assetsToValue(utxo.assets)).build().output();
|
|
950
934
|
};
|
|
951
935
|
var utxoToTransactionInput = (utxo) => {
|
|
952
|
-
return
|
|
953
|
-
|
|
936
|
+
return CML.TransactionInput.new(
|
|
937
|
+
CML.TransactionHash.from_hex(utxo.txHash),
|
|
954
938
|
BigInt(utxo.outputIndex)
|
|
955
939
|
);
|
|
956
940
|
};
|
|
957
|
-
|
|
958
|
-
const
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
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
|
|
941
|
+
var utxoToCore = (utxo) => {
|
|
942
|
+
const out = utxoToTransactionOutput(utxo);
|
|
943
|
+
const utxoCore = CML.TransactionUnspentOutput.new(
|
|
944
|
+
utxoToTransactionInput(utxo),
|
|
945
|
+
out
|
|
985
946
|
);
|
|
986
|
-
return
|
|
987
|
-
|
|
988
|
-
CML9.TransactionHash.from_hex(utxo.txHash),
|
|
989
|
-
BigInt(utxo.outputIndex)
|
|
990
|
-
),
|
|
991
|
-
output
|
|
992
|
-
);
|
|
993
|
-
}
|
|
947
|
+
return utxoCore;
|
|
948
|
+
};
|
|
994
949
|
function utxosToCores(utxos) {
|
|
995
950
|
const result = [];
|
|
996
|
-
|
|
951
|
+
for (const utxo of utxos) {
|
|
952
|
+
result.push(utxoToCore(utxo));
|
|
953
|
+
}
|
|
997
954
|
return result;
|
|
998
955
|
}
|
|
999
956
|
function coreToUtxo(coreUtxo) {
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
...
|
|
1003
|
-
|
|
1004
|
-
)
|
|
957
|
+
const out = CML.TransactionOutput.from_cbor_hex(coreUtxo.to_cbor_hex());
|
|
958
|
+
const utxo = {
|
|
959
|
+
...coreToOutRef(CML.TransactionInput.from_cbor_hex(coreUtxo.to_cbor_hex())),
|
|
960
|
+
...coreToTxOutput(out)
|
|
1005
961
|
};
|
|
962
|
+
out.free();
|
|
963
|
+
return utxo;
|
|
1006
964
|
}
|
|
1007
965
|
function coresToUtxos(utxos) {
|
|
1008
966
|
const result = [];
|
|
@@ -1034,7 +992,7 @@ function coreToTxOutput(output) {
|
|
|
1034
992
|
};
|
|
1035
993
|
}
|
|
1036
994
|
function coresToTxOutputs(outputs) {
|
|
1037
|
-
|
|
995
|
+
let result = [];
|
|
1038
996
|
for (let i = 0; i < outputs.length; i++) {
|
|
1039
997
|
result.push(coreToTxOutput(outputs[i]));
|
|
1040
998
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lucid-evolution/utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
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",
|