@meshsdk/core-csl 1.9.0-beta.5 → 1.9.0-beta.52
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 +214 -59
- package/dist/index.d.cts +15 -8
- package/dist/index.d.ts +15 -8
- package/dist/index.js +215 -59
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -116,6 +116,7 @@ __export(index_exports, {
|
|
|
116
116
|
toAddress: () => toAddress,
|
|
117
117
|
toBaseAddress: () => toBaseAddress,
|
|
118
118
|
toBytes: () => toBytes,
|
|
119
|
+
toCslValue: () => toCslValue,
|
|
119
120
|
toEnterpriseAddress: () => toEnterpriseAddress,
|
|
120
121
|
toLovelace: () => toLovelace,
|
|
121
122
|
toNativeScript: () => toNativeScript,
|
|
@@ -135,7 +136,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
135
136
|
var import_common2 = require("@meshsdk/common");
|
|
136
137
|
|
|
137
138
|
// src/deser/csl.ts
|
|
138
|
-
var csl = __toESM(require("@sidan-lab/
|
|
139
|
+
var csl = __toESM(require("@sidan-lab/whisky-js-nodejs"), 1);
|
|
139
140
|
|
|
140
141
|
// src/deser/constants.ts
|
|
141
142
|
var LANGUAGE_VERSIONS = {
|
|
@@ -231,7 +232,7 @@ var castDataToPlutusData = ({
|
|
|
231
232
|
return csl.PlutusData.from_hex(content);
|
|
232
233
|
}
|
|
233
234
|
return csl.PlutusData.from_json(
|
|
234
|
-
content,
|
|
235
|
+
castRawDataToJsonString(content),
|
|
235
236
|
csl.PlutusDatumSchema.DetailedSchema
|
|
236
237
|
);
|
|
237
238
|
};
|
|
@@ -270,6 +271,29 @@ var toNativeScript = (script) => {
|
|
|
270
271
|
);
|
|
271
272
|
}
|
|
272
273
|
};
|
|
274
|
+
var toCslValue = (assets) => {
|
|
275
|
+
let cslValue = void 0;
|
|
276
|
+
let multiAsset = csl.MultiAsset.new();
|
|
277
|
+
for (const asset of assets) {
|
|
278
|
+
if (asset.unit === "lovelace" || asset.unit === "") {
|
|
279
|
+
cslValue = csl.Value.new(csl.BigNum.from_str(asset.quantity));
|
|
280
|
+
} else {
|
|
281
|
+
const policyId = csl.ScriptHash.from_hex(asset.unit.slice(0, 56));
|
|
282
|
+
const assetName = csl.AssetName.new(
|
|
283
|
+
Buffer.from(asset.unit.slice(56), "hex")
|
|
284
|
+
);
|
|
285
|
+
const quantity = csl.BigNum.from_str(asset.quantity);
|
|
286
|
+
multiAsset.set_asset(policyId, assetName, quantity);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (cslValue !== void 0) {
|
|
290
|
+
cslValue.set_multiasset(multiAsset);
|
|
291
|
+
} else {
|
|
292
|
+
cslValue = csl.Value.new(csl.BigNum.from_str("0"));
|
|
293
|
+
cslValue.set_multiasset(multiAsset);
|
|
294
|
+
}
|
|
295
|
+
return cslValue;
|
|
296
|
+
};
|
|
273
297
|
|
|
274
298
|
// src/deser/deserializer.ts
|
|
275
299
|
var deserializeAddress = (address) => csl.Address.from_bytes(toBytes(address));
|
|
@@ -362,8 +386,11 @@ var resolveRewardAddress = (bech32) => {
|
|
|
362
386
|
throw new Error(`An error occurred during resolveRewardAddress: ${error}.`);
|
|
363
387
|
}
|
|
364
388
|
};
|
|
365
|
-
var resolveDataHash = (
|
|
366
|
-
const plutusData =
|
|
389
|
+
var resolveDataHash = (rawData, type = "Mesh") => {
|
|
390
|
+
const plutusData = castDataToPlutusData({
|
|
391
|
+
content: rawData,
|
|
392
|
+
type
|
|
393
|
+
});
|
|
367
394
|
const dataHash = csl.hash_plutus_data(plutusData);
|
|
368
395
|
return dataHash.to_hex();
|
|
369
396
|
};
|
|
@@ -509,7 +536,7 @@ var keyHashToRewardAddress = (keyHashHex, network = 1) => {
|
|
|
509
536
|
};
|
|
510
537
|
|
|
511
538
|
// src/utils/transaction.ts
|
|
512
|
-
var
|
|
539
|
+
var import_whisky_js_nodejs = require("@sidan-lab/whisky-js-nodejs");
|
|
513
540
|
|
|
514
541
|
// src/wasm.ts
|
|
515
542
|
var parseWasmResult = (result) => {
|
|
@@ -638,7 +665,7 @@ var getTransactionInputs = (txHex) => {
|
|
|
638
665
|
return inputs;
|
|
639
666
|
};
|
|
640
667
|
var getTransactionOutputs = (txHex) => {
|
|
641
|
-
const outputs = (0,
|
|
668
|
+
const outputs = (0, import_whisky_js_nodejs.js_get_tx_outs_utxo)(txHex).get_data();
|
|
642
669
|
const utxos = JSON.parse(outputs);
|
|
643
670
|
return utxos;
|
|
644
671
|
};
|
|
@@ -646,10 +673,10 @@ var getTransactionOutputs = (txHex) => {
|
|
|
646
673
|
// src/utils/aiken.ts
|
|
647
674
|
var applyParamsToScript = (rawScript, params, type = "Mesh") => {
|
|
648
675
|
const cslParams = csl.JsVecString.new();
|
|
649
|
-
let paramType =
|
|
676
|
+
let paramType = "cbor";
|
|
650
677
|
switch (type) {
|
|
651
678
|
case "JSON":
|
|
652
|
-
paramType =
|
|
679
|
+
paramType = "json";
|
|
653
680
|
params.forEach((param) => {
|
|
654
681
|
if (typeof param === "object") {
|
|
655
682
|
cslParams.add(JSON.stringify(param));
|
|
@@ -676,7 +703,7 @@ var applyCborEncoding = (rawScript) => {
|
|
|
676
703
|
return csl.js_apply_params_to_script(
|
|
677
704
|
rawScript,
|
|
678
705
|
csl.JsVecString.new(),
|
|
679
|
-
|
|
706
|
+
"cbor"
|
|
680
707
|
);
|
|
681
708
|
};
|
|
682
709
|
|
|
@@ -942,6 +969,41 @@ var relayToObj = (relay) => {
|
|
|
942
969
|
}
|
|
943
970
|
};
|
|
944
971
|
|
|
972
|
+
// src/core/adaptor/metadata.ts
|
|
973
|
+
var import_json_bigint2 = __toESM(require("json-bigint"), 1);
|
|
974
|
+
var txMetadataToObj = (metadata) => {
|
|
975
|
+
const result = [];
|
|
976
|
+
metadata.forEach((value, key) => {
|
|
977
|
+
result.push({
|
|
978
|
+
tag: key.toString(),
|
|
979
|
+
metadata: import_json_bigint2.default.stringify(metadatumToObj(value))
|
|
980
|
+
});
|
|
981
|
+
});
|
|
982
|
+
return result;
|
|
983
|
+
};
|
|
984
|
+
var metadatumToObj = (metadatum) => {
|
|
985
|
+
if (typeof metadatum === "number" || typeof metadatum === "string") {
|
|
986
|
+
return metadatum;
|
|
987
|
+
} else if (typeof metadatum === "bigint") {
|
|
988
|
+
return metadatum.toString();
|
|
989
|
+
} else if (metadatum instanceof Uint8Array) {
|
|
990
|
+
return uint8ArrayToHex(metadatum);
|
|
991
|
+
} else if (metadatum instanceof Map) {
|
|
992
|
+
const result = {};
|
|
993
|
+
metadatum.forEach((value, key) => {
|
|
994
|
+
result[metadatumToObj(key)] = metadatumToObj(value);
|
|
995
|
+
});
|
|
996
|
+
return result;
|
|
997
|
+
} else if (Array.isArray(metadatum)) {
|
|
998
|
+
return metadatum.map(metadatumToObj);
|
|
999
|
+
} else {
|
|
1000
|
+
throw new Error("metadatumToObj: Unsupported Metadatum type");
|
|
1001
|
+
}
|
|
1002
|
+
};
|
|
1003
|
+
var uint8ArrayToHex = (bytes) => {
|
|
1004
|
+
return Array.from(bytes).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
1005
|
+
};
|
|
1006
|
+
|
|
945
1007
|
// src/core/adaptor/mint.ts
|
|
946
1008
|
var mintItemToObj = (mintItem) => {
|
|
947
1009
|
switch (mintItem.type) {
|
|
@@ -1024,41 +1086,6 @@ var outputToObj = (output) => {
|
|
|
1024
1086
|
};
|
|
1025
1087
|
};
|
|
1026
1088
|
|
|
1027
|
-
// src/core/adaptor/metadata.ts
|
|
1028
|
-
var import_json_bigint2 = __toESM(require("json-bigint"), 1);
|
|
1029
|
-
var txMetadataToObj = (metadata) => {
|
|
1030
|
-
const result = [];
|
|
1031
|
-
metadata.forEach((value, key) => {
|
|
1032
|
-
result.push({
|
|
1033
|
-
tag: key.toString(),
|
|
1034
|
-
metadata: import_json_bigint2.default.stringify(metadatumToObj(value))
|
|
1035
|
-
});
|
|
1036
|
-
});
|
|
1037
|
-
return result;
|
|
1038
|
-
};
|
|
1039
|
-
var metadatumToObj = (metadatum) => {
|
|
1040
|
-
if (typeof metadatum === "number" || typeof metadatum === "string") {
|
|
1041
|
-
return metadatum;
|
|
1042
|
-
} else if (typeof metadatum === "bigint") {
|
|
1043
|
-
return metadatum.toString();
|
|
1044
|
-
} else if (metadatum instanceof Uint8Array) {
|
|
1045
|
-
return uint8ArrayToHex(metadatum);
|
|
1046
|
-
} else if (metadatum instanceof Map) {
|
|
1047
|
-
const result = {};
|
|
1048
|
-
metadatum.forEach((value, key) => {
|
|
1049
|
-
result[metadatumToObj(key)] = metadatumToObj(value);
|
|
1050
|
-
});
|
|
1051
|
-
return result;
|
|
1052
|
-
} else if (Array.isArray(metadatum)) {
|
|
1053
|
-
return metadatum.map(metadatumToObj);
|
|
1054
|
-
} else {
|
|
1055
|
-
throw new Error("metadatumToObj: Unsupported Metadatum type");
|
|
1056
|
-
}
|
|
1057
|
-
};
|
|
1058
|
-
var uint8ArrayToHex = (bytes) => {
|
|
1059
|
-
return Array.from(bytes).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
1060
|
-
};
|
|
1061
|
-
|
|
1062
1089
|
// src/core/adaptor/txIn.ts
|
|
1063
1090
|
var txInToObj = (txIn) => {
|
|
1064
1091
|
switch (txIn.type) {
|
|
@@ -1343,13 +1370,28 @@ var meshTxBuilderBodyToObj = ({
|
|
|
1343
1370
|
fee,
|
|
1344
1371
|
network
|
|
1345
1372
|
}) => {
|
|
1373
|
+
let mintsObj = [];
|
|
1374
|
+
mints.forEach((mint) => {
|
|
1375
|
+
mint.mintValue.forEach((mintValue) => {
|
|
1376
|
+
mintsObj.push(
|
|
1377
|
+
mintItemToObj({
|
|
1378
|
+
type: mint.type,
|
|
1379
|
+
policyId: mint.policyId,
|
|
1380
|
+
assetName: mintValue.assetName,
|
|
1381
|
+
amount: mintValue.amount,
|
|
1382
|
+
scriptSource: mint.scriptSource,
|
|
1383
|
+
redeemer: mint.redeemer
|
|
1384
|
+
})
|
|
1385
|
+
);
|
|
1386
|
+
});
|
|
1387
|
+
});
|
|
1346
1388
|
return {
|
|
1347
1389
|
inputs: inputs.map(txInToObj),
|
|
1348
1390
|
outputs: outputs.map(outputToObj),
|
|
1349
1391
|
collaterals: collaterals.map(collateralTxInToObj),
|
|
1350
1392
|
requiredSignatures,
|
|
1351
1393
|
referenceInputs,
|
|
1352
|
-
mints:
|
|
1394
|
+
mints: mintsObj,
|
|
1353
1395
|
changeAddress,
|
|
1354
1396
|
metadata: txMetadataToObj(metadata),
|
|
1355
1397
|
validityRange: (0, import_common3.validityRangeToObj)(validityRange),
|
|
@@ -1363,28 +1405,21 @@ var meshTxBuilderBodyToObj = ({
|
|
|
1363
1405
|
};
|
|
1364
1406
|
|
|
1365
1407
|
// src/core/serializer.ts
|
|
1408
|
+
var VKEY_PUBKEY_SIZE_BYTES = 32;
|
|
1409
|
+
var VKEY_SIGNATURE_SIZE_BYTES = 64;
|
|
1410
|
+
var CHAIN_CODE_SIZE_BYTES = 32;
|
|
1366
1411
|
var CSLSerializer = class {
|
|
1367
1412
|
/**
|
|
1368
1413
|
* Set to true to enable verbose logging for the txBodyJson prior going into build
|
|
1369
1414
|
*/
|
|
1370
|
-
verbose;
|
|
1371
1415
|
protocolParams;
|
|
1372
1416
|
meshTxBuilderBody = (0, import_common4.emptyTxBuilderBody)();
|
|
1373
|
-
constructor(protocolParams
|
|
1417
|
+
constructor(protocolParams) {
|
|
1374
1418
|
this.protocolParams = protocolParams || import_common4.DEFAULT_PROTOCOL_PARAMETERS;
|
|
1375
|
-
this.verbose = verbose;
|
|
1376
1419
|
}
|
|
1377
|
-
serializeTxBody(txBody, protocolParams
|
|
1378
|
-
if (!balanced) {
|
|
1379
|
-
throw new Error(
|
|
1380
|
-
"Unbalanced transactions are not supported with CSL serializer"
|
|
1381
|
-
);
|
|
1382
|
-
}
|
|
1420
|
+
serializeTxBody(txBody, protocolParams) {
|
|
1383
1421
|
const txBodyJson = import_json_bigint3.default.stringify(meshTxBuilderBodyToObj(txBody));
|
|
1384
1422
|
const params = import_json_bigint3.default.stringify(protocolParams || this.protocolParams);
|
|
1385
|
-
if (this.verbose) {
|
|
1386
|
-
console.log("txBodyJson", txBodyJson);
|
|
1387
|
-
}
|
|
1388
1423
|
const txBuildResult = csl.js_serialize_tx_body(txBodyJson, params);
|
|
1389
1424
|
if (txBuildResult.get_status() !== "success") {
|
|
1390
1425
|
throw new Error(`txBuildResult error: ${txBuildResult.get_error()}`);
|
|
@@ -1457,8 +1492,8 @@ var CSLSerializer = class {
|
|
|
1457
1492
|
}
|
|
1458
1493
|
},
|
|
1459
1494
|
data: {
|
|
1460
|
-
resolveDataHash: function(
|
|
1461
|
-
return resolveDataHash(
|
|
1495
|
+
resolveDataHash: function(rawData, type = "Mesh") {
|
|
1496
|
+
return resolveDataHash(rawData, type);
|
|
1462
1497
|
}
|
|
1463
1498
|
},
|
|
1464
1499
|
script: {
|
|
@@ -1467,6 +1502,125 @@ var CSLSerializer = class {
|
|
|
1467
1502
|
}
|
|
1468
1503
|
}
|
|
1469
1504
|
};
|
|
1505
|
+
serializeOutput(output) {
|
|
1506
|
+
let cslOutputBuilder = csl.TransactionOutputBuilder.new().with_address(
|
|
1507
|
+
csl.Address.from_bech32(output.address)
|
|
1508
|
+
);
|
|
1509
|
+
if (output.datum?.type === "Hash") {
|
|
1510
|
+
cslOutputBuilder.with_data_hash(
|
|
1511
|
+
csl.hash_plutus_data(castDataToPlutusData(output.datum.data))
|
|
1512
|
+
);
|
|
1513
|
+
} else if (output.datum?.type === "Inline") {
|
|
1514
|
+
cslOutputBuilder.with_plutus_data(
|
|
1515
|
+
castDataToPlutusData(output.datum.data)
|
|
1516
|
+
);
|
|
1517
|
+
} else if (output.datum?.type === "Embedded") {
|
|
1518
|
+
throw new Error("Embedded datum not supported");
|
|
1519
|
+
}
|
|
1520
|
+
if (output.referenceScript) {
|
|
1521
|
+
switch (output.referenceScript.version) {
|
|
1522
|
+
case "V1": {
|
|
1523
|
+
cslOutputBuilder.with_script_ref(
|
|
1524
|
+
csl.ScriptRef.new_plutus_script(
|
|
1525
|
+
csl.PlutusScript.from_hex_with_version(
|
|
1526
|
+
output.referenceScript.code,
|
|
1527
|
+
csl.Language.new_plutus_v1()
|
|
1528
|
+
)
|
|
1529
|
+
)
|
|
1530
|
+
);
|
|
1531
|
+
break;
|
|
1532
|
+
}
|
|
1533
|
+
case "V2": {
|
|
1534
|
+
cslOutputBuilder.with_script_ref(
|
|
1535
|
+
csl.ScriptRef.new_plutus_script(
|
|
1536
|
+
csl.PlutusScript.from_hex_with_version(
|
|
1537
|
+
output.referenceScript.code,
|
|
1538
|
+
csl.Language.new_plutus_v2()
|
|
1539
|
+
)
|
|
1540
|
+
)
|
|
1541
|
+
);
|
|
1542
|
+
break;
|
|
1543
|
+
}
|
|
1544
|
+
case "V3": {
|
|
1545
|
+
cslOutputBuilder.with_script_ref(
|
|
1546
|
+
csl.ScriptRef.new_plutus_script(
|
|
1547
|
+
csl.PlutusScript.from_hex_with_version(
|
|
1548
|
+
output.referenceScript.code,
|
|
1549
|
+
csl.Language.new_plutus_v3()
|
|
1550
|
+
)
|
|
1551
|
+
)
|
|
1552
|
+
);
|
|
1553
|
+
break;
|
|
1554
|
+
}
|
|
1555
|
+
default: {
|
|
1556
|
+
cslOutputBuilder.with_script_ref(
|
|
1557
|
+
csl.ScriptRef.new_native_script(
|
|
1558
|
+
csl.NativeScript.from_hex(output.referenceScript.code)
|
|
1559
|
+
)
|
|
1560
|
+
);
|
|
1561
|
+
break;
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
}
|
|
1565
|
+
return cslOutputBuilder.next().with_value(toCslValue(output.amount)).build().to_hex();
|
|
1566
|
+
}
|
|
1567
|
+
serializeTxBodyWithMockSignatures(txBuilderBody, protocolParams) {
|
|
1568
|
+
const txHex = this.serializeTxBody(txBuilderBody, protocolParams);
|
|
1569
|
+
const cslTx = csl.Transaction.from_hex(txHex);
|
|
1570
|
+
const mockWitnessSet = cslTx.witness_set();
|
|
1571
|
+
const mockVkeyWitnesses = mockWitnessSet.vkeys() ?? csl.Vkeywitnesses.new();
|
|
1572
|
+
const mockBootstrapWitnesses = mockWitnessSet.bootstraps() ?? csl.BootstrapWitnesses.new();
|
|
1573
|
+
for (let i = 0; i < txBuilderBody.expectedNumberKeyWitnesses; i++) {
|
|
1574
|
+
const numberInHex = this.numberToIntegerHex(i);
|
|
1575
|
+
const mockVkey = csl.Vkey.new(
|
|
1576
|
+
csl.PublicKey.from_hex(this.mockPubkey(numberInHex))
|
|
1577
|
+
);
|
|
1578
|
+
const mockSignature = csl.Ed25519Signature.from_hex(
|
|
1579
|
+
this.mockSignature(numberInHex)
|
|
1580
|
+
);
|
|
1581
|
+
mockVkeyWitnesses.add(csl.Vkeywitness.new(mockVkey, mockSignature));
|
|
1582
|
+
}
|
|
1583
|
+
this.meshTxBuilderBody.expectedByronAddressWitnesses.forEach(
|
|
1584
|
+
(bootstrapWitness, i) => {
|
|
1585
|
+
const address = csl.ByronAddress.from_base58(bootstrapWitness);
|
|
1586
|
+
const numberInHex = this.numberToIntegerHex(i);
|
|
1587
|
+
const pubKeyHex = this.mockPubkey(numberInHex);
|
|
1588
|
+
const mockVkey = csl.Vkey.new(csl.PublicKey.from_hex(pubKeyHex));
|
|
1589
|
+
const signature = this.mockSignature(numberInHex);
|
|
1590
|
+
const chainCode = this.mockChainCode(numberInHex);
|
|
1591
|
+
mockBootstrapWitnesses.add(
|
|
1592
|
+
csl.BootstrapWitness.new(
|
|
1593
|
+
mockVkey,
|
|
1594
|
+
csl.Ed25519Signature.from_hex(signature),
|
|
1595
|
+
Buffer.from(chainCode, "hex"),
|
|
1596
|
+
address.attributes()
|
|
1597
|
+
)
|
|
1598
|
+
);
|
|
1599
|
+
}
|
|
1600
|
+
);
|
|
1601
|
+
mockWitnessSet.set_vkeys(mockVkeyWitnesses);
|
|
1602
|
+
mockWitnessSet.set_bootstraps(mockBootstrapWitnesses);
|
|
1603
|
+
return csl.Transaction.new(
|
|
1604
|
+
cslTx.body(),
|
|
1605
|
+
mockWitnessSet,
|
|
1606
|
+
cslTx.auxiliary_data()
|
|
1607
|
+
).to_hex();
|
|
1608
|
+
}
|
|
1609
|
+
serializeValue(value) {
|
|
1610
|
+
return toCslValue(value).to_hex();
|
|
1611
|
+
}
|
|
1612
|
+
mockPubkey(numberInHex) {
|
|
1613
|
+
return "0".repeat(VKEY_PUBKEY_SIZE_BYTES * 2 - numberInHex.length).concat(numberInHex);
|
|
1614
|
+
}
|
|
1615
|
+
mockSignature(numberInHex) {
|
|
1616
|
+
return "0".repeat(VKEY_SIGNATURE_SIZE_BYTES * 2 - numberInHex.length).concat(numberInHex);
|
|
1617
|
+
}
|
|
1618
|
+
mockChainCode = (numberInHex) => {
|
|
1619
|
+
return "0".repeat(CHAIN_CODE_SIZE_BYTES * 2 - numberInHex.length).concat(numberInHex);
|
|
1620
|
+
};
|
|
1621
|
+
numberToIntegerHex = (number) => {
|
|
1622
|
+
return BigInt(number).toString(16);
|
|
1623
|
+
};
|
|
1470
1624
|
};
|
|
1471
1625
|
|
|
1472
1626
|
// src/offline-providers/offline-evaluator.ts
|
|
@@ -1640,6 +1794,7 @@ var OfflineEvaluator = class {
|
|
|
1640
1794
|
toAddress,
|
|
1641
1795
|
toBaseAddress,
|
|
1642
1796
|
toBytes,
|
|
1797
|
+
toCslValue,
|
|
1643
1798
|
toEnterpriseAddress,
|
|
1644
1799
|
toLovelace,
|
|
1645
1800
|
toNativeScript,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _meshsdk_common from '@meshsdk/common';
|
|
2
|
-
import { DeserializedAddress, PubKeyAddress, ScriptAddress, UTxO, Network, SlotConfig, Action, Data, PlutusDataType, IMeshTxSerializer, Protocol, MeshTxBuilderBody, BuilderData, IDeserializer, IResolver, Certificate, CertificateType, PoolParams, PoolMetadata, Relay, Redeemer, MintItem,
|
|
3
|
-
import * as csl from '@sidan-lab/
|
|
2
|
+
import { DeserializedAddress, PubKeyAddress, ScriptAddress, UTxO, Network, SlotConfig, Action, Data, PlutusDataType, IMeshTxSerializer, Protocol, MeshTxBuilderBody, BuilderData, IDeserializer, IResolver, Output, Asset, Certificate, CertificateType, PoolParams, PoolMetadata, Relay, Redeemer, MintItem, ScriptSource, SimpleScriptSourceInfo, TxIn, TxInParameter, ScriptTxInParameter, SimpleScriptTxInParameter, Withdrawal, LanguageVersion, PlutusScript, NativeScript, IEvaluator, IFetcher } from '@meshsdk/common';
|
|
3
|
+
import * as csl from '@sidan-lab/whisky-js-nodejs';
|
|
4
4
|
export { csl };
|
|
5
5
|
|
|
6
6
|
declare const serialzeAddress: (deserializedAddress: Partial<DeserializedAddress>, networkId?: number) => string;
|
|
@@ -63,11 +63,10 @@ declare class CSLSerializer implements IMeshTxSerializer {
|
|
|
63
63
|
/**
|
|
64
64
|
* Set to true to enable verbose logging for the txBodyJson prior going into build
|
|
65
65
|
*/
|
|
66
|
-
verbose: boolean;
|
|
67
66
|
protocolParams: Protocol;
|
|
68
67
|
meshTxBuilderBody: MeshTxBuilderBody;
|
|
69
|
-
constructor(protocolParams?: Protocol
|
|
70
|
-
serializeTxBody(txBody: MeshTxBuilderBody, protocolParams?: Protocol
|
|
68
|
+
constructor(protocolParams?: Protocol);
|
|
69
|
+
serializeTxBody(txBody: MeshTxBuilderBody, protocolParams?: Protocol): string;
|
|
71
70
|
addSigningKeys(txHex: string, signingKeys: string[]): string;
|
|
72
71
|
serializeData(data: BuilderData): string;
|
|
73
72
|
serializeAddress(address: Partial<DeserializedAddress>, networkId?: number): string;
|
|
@@ -75,6 +74,13 @@ declare class CSLSerializer implements IMeshTxSerializer {
|
|
|
75
74
|
serializeRewardAddress(stakeKeyHash: string, isScriptHash?: boolean, network_id?: 0 | 1): string;
|
|
76
75
|
deserializer: IDeserializer;
|
|
77
76
|
resolver: IResolver;
|
|
77
|
+
serializeOutput(output: Output): string;
|
|
78
|
+
serializeTxBodyWithMockSignatures(txBuilderBody: MeshTxBuilderBody, protocolParams: Protocol): string;
|
|
79
|
+
serializeValue(value: Asset[]): string;
|
|
80
|
+
private mockPubkey;
|
|
81
|
+
private mockSignature;
|
|
82
|
+
private mockChainCode;
|
|
83
|
+
private numberToIntegerHex;
|
|
78
84
|
}
|
|
79
85
|
|
|
80
86
|
declare const certificateToObj: (certificate: Certificate) => object;
|
|
@@ -120,7 +126,7 @@ declare const meshTxBuilderBodyToObj: ({ inputs, outputs, collaterals, requiredS
|
|
|
120
126
|
signingKey: string[];
|
|
121
127
|
withdrawals: object[];
|
|
122
128
|
votes: object[];
|
|
123
|
-
fee: string
|
|
129
|
+
fee: string;
|
|
124
130
|
network: "testnet" | "preview" | "preprod" | "mainnet" | number[][] | {
|
|
125
131
|
custom: "testnet" | "preview" | "preprod" | "mainnet" | number[][];
|
|
126
132
|
};
|
|
@@ -159,6 +165,7 @@ declare const toPlutusData: (data: Data) => csl.PlutusData;
|
|
|
159
165
|
declare const castRawDataToJsonString: (rawData: object | string) => string;
|
|
160
166
|
declare const castDataToPlutusData: ({ type, content, }: BuilderData) => csl.PlutusData;
|
|
161
167
|
declare const toNativeScript: (script: NativeScript) => csl.NativeScript;
|
|
168
|
+
declare const toCslValue: (assets: Asset[]) => csl.Value;
|
|
162
169
|
|
|
163
170
|
declare const LANGUAGE_VERSIONS: {
|
|
164
171
|
V1: csl.Language;
|
|
@@ -180,7 +187,7 @@ declare const resolvePlutusScriptAddress: (script: PlutusScript, networkId?: num
|
|
|
180
187
|
declare const resolveNativeScriptHash: (script: NativeScript) => string;
|
|
181
188
|
declare const resolveScriptHashDRepId: (scriptHash: string) => string;
|
|
182
189
|
declare const resolveRewardAddress: (bech32: string) => string;
|
|
183
|
-
declare const resolveDataHash: (
|
|
190
|
+
declare const resolveDataHash: (rawData: BuilderData["content"], type?: PlutusDataType) => string;
|
|
184
191
|
declare const resolveNativeScriptHex: (script: NativeScript) => string;
|
|
185
192
|
declare const serializePoolId: (hash: string) => string;
|
|
186
193
|
declare const resolveScriptRef: (script: PlutusScript | NativeScript) => string;
|
|
@@ -268,4 +275,4 @@ declare class OfflineEvaluator implements IEvaluator {
|
|
|
268
275
|
evaluateTx(tx: string, additionalUtxos: UTxO[], additionalTxs: string[]): Promise<Omit<Action, "data">[]>;
|
|
269
276
|
}
|
|
270
277
|
|
|
271
|
-
export { CSLSerializer, LANGUAGE_VERSIONS, OfflineEvaluator, POLICY_ID_LENGTH, REDEEMER_TAGS, addrBech32ToPlutusDataHex, addrBech32ToPlutusDataObj, applyCborEncoding, applyParamsToScript, baseAddressToStakeAddress, baseCertToObj, builderDataToCbor, calculateTxHash, castDataToPlutusData, castRawDataToJsonString, certificateToObj, collateralTxInToObj, deserializeAddress, deserializeBech32Address, deserializeBip32PrivateKey, deserializeDataHash, deserializeEd25519KeyHash, deserializeEd25519Signature, deserializeNativeScript, deserializePlutusData, deserializePlutusScript, deserializePublicKey, deserializeScriptHash, deserializeScriptRef, deserializeTx, deserializeTxBody, deserializeTxHash, deserializeTxUnspentOutput, deserializeTxWitnessSet, deserializeValue, evaluateTransaction, fromBytes, fromLovelace, fromUTF8, getDRepIds, getTransactionInputs, getTransactionOutputs, getV2ScriptHash, keyHashToRewardAddress, meshTxBuilderBodyToObj, mintItemToObj, mintParametersObj, nativeMintItemToObj, outputToObj, parseDatumCbor, parseInlineDatum, plutusMintItemToObj, poolIdBech32ToHex, poolIdHexToBech32, poolMetadataToObj, poolParamsToObj, redeemerToObj, relayToObj, resolveDataHash, resolveEd25519KeyHash, resolveNativeScriptAddress, resolveNativeScriptHash, resolveNativeScriptHex, resolvePlutusScriptAddress, resolvePrivateKey, resolveRewardAddress, resolveScriptHashDRepId, resolveScriptRef, resolveStakeKeyHash, rewardAddressToKeyHash, scriptHashToBech32, scriptHashToRewardAddress, scriptSourceToObj, scriptTxInParameterToObj, serializeAddressObj, serializePlutusAddressToBech32, serializePoolId, serialzeAddress, signTransaction, simpleScriptSourceToObj, simpleScriptTxInParameterToObj, skeyToPubKeyHash, toAddress, toBaseAddress, toBytes, toEnterpriseAddress, toLovelace, toNativeScript, toPlutusData, toRewardAddress, toScriptRef, toUTF8, txInParameterToObj, txInToObj, utxoToObj, v2ScriptToBech32, withdrawalToObj };
|
|
278
|
+
export { CSLSerializer, LANGUAGE_VERSIONS, OfflineEvaluator, POLICY_ID_LENGTH, REDEEMER_TAGS, addrBech32ToPlutusDataHex, addrBech32ToPlutusDataObj, applyCborEncoding, applyParamsToScript, baseAddressToStakeAddress, baseCertToObj, builderDataToCbor, calculateTxHash, castDataToPlutusData, castRawDataToJsonString, certificateToObj, collateralTxInToObj, deserializeAddress, deserializeBech32Address, deserializeBip32PrivateKey, deserializeDataHash, deserializeEd25519KeyHash, deserializeEd25519Signature, deserializeNativeScript, deserializePlutusData, deserializePlutusScript, deserializePublicKey, deserializeScriptHash, deserializeScriptRef, deserializeTx, deserializeTxBody, deserializeTxHash, deserializeTxUnspentOutput, deserializeTxWitnessSet, deserializeValue, evaluateTransaction, fromBytes, fromLovelace, fromUTF8, getDRepIds, getTransactionInputs, getTransactionOutputs, getV2ScriptHash, keyHashToRewardAddress, meshTxBuilderBodyToObj, mintItemToObj, mintParametersObj, nativeMintItemToObj, outputToObj, parseDatumCbor, parseInlineDatum, plutusMintItemToObj, poolIdBech32ToHex, poolIdHexToBech32, poolMetadataToObj, poolParamsToObj, redeemerToObj, relayToObj, resolveDataHash, resolveEd25519KeyHash, resolveNativeScriptAddress, resolveNativeScriptHash, resolveNativeScriptHex, resolvePlutusScriptAddress, resolvePrivateKey, resolveRewardAddress, resolveScriptHashDRepId, resolveScriptRef, resolveStakeKeyHash, rewardAddressToKeyHash, scriptHashToBech32, scriptHashToRewardAddress, scriptSourceToObj, scriptTxInParameterToObj, serializeAddressObj, serializePlutusAddressToBech32, serializePoolId, serialzeAddress, signTransaction, simpleScriptSourceToObj, simpleScriptTxInParameterToObj, skeyToPubKeyHash, toAddress, toBaseAddress, toBytes, toCslValue, toEnterpriseAddress, toLovelace, toNativeScript, toPlutusData, toRewardAddress, toScriptRef, toUTF8, txInParameterToObj, txInToObj, utxoToObj, v2ScriptToBech32, withdrawalToObj };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _meshsdk_common from '@meshsdk/common';
|
|
2
|
-
import { DeserializedAddress, PubKeyAddress, ScriptAddress, UTxO, Network, SlotConfig, Action, Data, PlutusDataType, IMeshTxSerializer, Protocol, MeshTxBuilderBody, BuilderData, IDeserializer, IResolver, Certificate, CertificateType, PoolParams, PoolMetadata, Relay, Redeemer, MintItem,
|
|
3
|
-
import * as csl from '@sidan-lab/
|
|
2
|
+
import { DeserializedAddress, PubKeyAddress, ScriptAddress, UTxO, Network, SlotConfig, Action, Data, PlutusDataType, IMeshTxSerializer, Protocol, MeshTxBuilderBody, BuilderData, IDeserializer, IResolver, Output, Asset, Certificate, CertificateType, PoolParams, PoolMetadata, Relay, Redeemer, MintItem, ScriptSource, SimpleScriptSourceInfo, TxIn, TxInParameter, ScriptTxInParameter, SimpleScriptTxInParameter, Withdrawal, LanguageVersion, PlutusScript, NativeScript, IEvaluator, IFetcher } from '@meshsdk/common';
|
|
3
|
+
import * as csl from '@sidan-lab/whisky-js-nodejs';
|
|
4
4
|
export { csl };
|
|
5
5
|
|
|
6
6
|
declare const serialzeAddress: (deserializedAddress: Partial<DeserializedAddress>, networkId?: number) => string;
|
|
@@ -63,11 +63,10 @@ declare class CSLSerializer implements IMeshTxSerializer {
|
|
|
63
63
|
/**
|
|
64
64
|
* Set to true to enable verbose logging for the txBodyJson prior going into build
|
|
65
65
|
*/
|
|
66
|
-
verbose: boolean;
|
|
67
66
|
protocolParams: Protocol;
|
|
68
67
|
meshTxBuilderBody: MeshTxBuilderBody;
|
|
69
|
-
constructor(protocolParams?: Protocol
|
|
70
|
-
serializeTxBody(txBody: MeshTxBuilderBody, protocolParams?: Protocol
|
|
68
|
+
constructor(protocolParams?: Protocol);
|
|
69
|
+
serializeTxBody(txBody: MeshTxBuilderBody, protocolParams?: Protocol): string;
|
|
71
70
|
addSigningKeys(txHex: string, signingKeys: string[]): string;
|
|
72
71
|
serializeData(data: BuilderData): string;
|
|
73
72
|
serializeAddress(address: Partial<DeserializedAddress>, networkId?: number): string;
|
|
@@ -75,6 +74,13 @@ declare class CSLSerializer implements IMeshTxSerializer {
|
|
|
75
74
|
serializeRewardAddress(stakeKeyHash: string, isScriptHash?: boolean, network_id?: 0 | 1): string;
|
|
76
75
|
deserializer: IDeserializer;
|
|
77
76
|
resolver: IResolver;
|
|
77
|
+
serializeOutput(output: Output): string;
|
|
78
|
+
serializeTxBodyWithMockSignatures(txBuilderBody: MeshTxBuilderBody, protocolParams: Protocol): string;
|
|
79
|
+
serializeValue(value: Asset[]): string;
|
|
80
|
+
private mockPubkey;
|
|
81
|
+
private mockSignature;
|
|
82
|
+
private mockChainCode;
|
|
83
|
+
private numberToIntegerHex;
|
|
78
84
|
}
|
|
79
85
|
|
|
80
86
|
declare const certificateToObj: (certificate: Certificate) => object;
|
|
@@ -120,7 +126,7 @@ declare const meshTxBuilderBodyToObj: ({ inputs, outputs, collaterals, requiredS
|
|
|
120
126
|
signingKey: string[];
|
|
121
127
|
withdrawals: object[];
|
|
122
128
|
votes: object[];
|
|
123
|
-
fee: string
|
|
129
|
+
fee: string;
|
|
124
130
|
network: "testnet" | "preview" | "preprod" | "mainnet" | number[][] | {
|
|
125
131
|
custom: "testnet" | "preview" | "preprod" | "mainnet" | number[][];
|
|
126
132
|
};
|
|
@@ -159,6 +165,7 @@ declare const toPlutusData: (data: Data) => csl.PlutusData;
|
|
|
159
165
|
declare const castRawDataToJsonString: (rawData: object | string) => string;
|
|
160
166
|
declare const castDataToPlutusData: ({ type, content, }: BuilderData) => csl.PlutusData;
|
|
161
167
|
declare const toNativeScript: (script: NativeScript) => csl.NativeScript;
|
|
168
|
+
declare const toCslValue: (assets: Asset[]) => csl.Value;
|
|
162
169
|
|
|
163
170
|
declare const LANGUAGE_VERSIONS: {
|
|
164
171
|
V1: csl.Language;
|
|
@@ -180,7 +187,7 @@ declare const resolvePlutusScriptAddress: (script: PlutusScript, networkId?: num
|
|
|
180
187
|
declare const resolveNativeScriptHash: (script: NativeScript) => string;
|
|
181
188
|
declare const resolveScriptHashDRepId: (scriptHash: string) => string;
|
|
182
189
|
declare const resolveRewardAddress: (bech32: string) => string;
|
|
183
|
-
declare const resolveDataHash: (
|
|
190
|
+
declare const resolveDataHash: (rawData: BuilderData["content"], type?: PlutusDataType) => string;
|
|
184
191
|
declare const resolveNativeScriptHex: (script: NativeScript) => string;
|
|
185
192
|
declare const serializePoolId: (hash: string) => string;
|
|
186
193
|
declare const resolveScriptRef: (script: PlutusScript | NativeScript) => string;
|
|
@@ -268,4 +275,4 @@ declare class OfflineEvaluator implements IEvaluator {
|
|
|
268
275
|
evaluateTx(tx: string, additionalUtxos: UTxO[], additionalTxs: string[]): Promise<Omit<Action, "data">[]>;
|
|
269
276
|
}
|
|
270
277
|
|
|
271
|
-
export { CSLSerializer, LANGUAGE_VERSIONS, OfflineEvaluator, POLICY_ID_LENGTH, REDEEMER_TAGS, addrBech32ToPlutusDataHex, addrBech32ToPlutusDataObj, applyCborEncoding, applyParamsToScript, baseAddressToStakeAddress, baseCertToObj, builderDataToCbor, calculateTxHash, castDataToPlutusData, castRawDataToJsonString, certificateToObj, collateralTxInToObj, deserializeAddress, deserializeBech32Address, deserializeBip32PrivateKey, deserializeDataHash, deserializeEd25519KeyHash, deserializeEd25519Signature, deserializeNativeScript, deserializePlutusData, deserializePlutusScript, deserializePublicKey, deserializeScriptHash, deserializeScriptRef, deserializeTx, deserializeTxBody, deserializeTxHash, deserializeTxUnspentOutput, deserializeTxWitnessSet, deserializeValue, evaluateTransaction, fromBytes, fromLovelace, fromUTF8, getDRepIds, getTransactionInputs, getTransactionOutputs, getV2ScriptHash, keyHashToRewardAddress, meshTxBuilderBodyToObj, mintItemToObj, mintParametersObj, nativeMintItemToObj, outputToObj, parseDatumCbor, parseInlineDatum, plutusMintItemToObj, poolIdBech32ToHex, poolIdHexToBech32, poolMetadataToObj, poolParamsToObj, redeemerToObj, relayToObj, resolveDataHash, resolveEd25519KeyHash, resolveNativeScriptAddress, resolveNativeScriptHash, resolveNativeScriptHex, resolvePlutusScriptAddress, resolvePrivateKey, resolveRewardAddress, resolveScriptHashDRepId, resolveScriptRef, resolveStakeKeyHash, rewardAddressToKeyHash, scriptHashToBech32, scriptHashToRewardAddress, scriptSourceToObj, scriptTxInParameterToObj, serializeAddressObj, serializePlutusAddressToBech32, serializePoolId, serialzeAddress, signTransaction, simpleScriptSourceToObj, simpleScriptTxInParameterToObj, skeyToPubKeyHash, toAddress, toBaseAddress, toBytes, toEnterpriseAddress, toLovelace, toNativeScript, toPlutusData, toRewardAddress, toScriptRef, toUTF8, txInParameterToObj, txInToObj, utxoToObj, v2ScriptToBech32, withdrawalToObj };
|
|
278
|
+
export { CSLSerializer, LANGUAGE_VERSIONS, OfflineEvaluator, POLICY_ID_LENGTH, REDEEMER_TAGS, addrBech32ToPlutusDataHex, addrBech32ToPlutusDataObj, applyCborEncoding, applyParamsToScript, baseAddressToStakeAddress, baseCertToObj, builderDataToCbor, calculateTxHash, castDataToPlutusData, castRawDataToJsonString, certificateToObj, collateralTxInToObj, deserializeAddress, deserializeBech32Address, deserializeBip32PrivateKey, deserializeDataHash, deserializeEd25519KeyHash, deserializeEd25519Signature, deserializeNativeScript, deserializePlutusData, deserializePlutusScript, deserializePublicKey, deserializeScriptHash, deserializeScriptRef, deserializeTx, deserializeTxBody, deserializeTxHash, deserializeTxUnspentOutput, deserializeTxWitnessSet, deserializeValue, evaluateTransaction, fromBytes, fromLovelace, fromUTF8, getDRepIds, getTransactionInputs, getTransactionOutputs, getV2ScriptHash, keyHashToRewardAddress, meshTxBuilderBodyToObj, mintItemToObj, mintParametersObj, nativeMintItemToObj, outputToObj, parseDatumCbor, parseInlineDatum, plutusMintItemToObj, poolIdBech32ToHex, poolIdHexToBech32, poolMetadataToObj, poolParamsToObj, redeemerToObj, relayToObj, resolveDataHash, resolveEd25519KeyHash, resolveNativeScriptAddress, resolveNativeScriptHash, resolveNativeScriptHex, resolvePlutusScriptAddress, resolvePrivateKey, resolveRewardAddress, resolveScriptHashDRepId, resolveScriptRef, resolveStakeKeyHash, rewardAddressToKeyHash, scriptHashToBech32, scriptHashToRewardAddress, scriptSourceToObj, scriptTxInParameterToObj, serializeAddressObj, serializePlutusAddressToBech32, serializePoolId, serialzeAddress, signTransaction, simpleScriptSourceToObj, simpleScriptTxInParameterToObj, skeyToPubKeyHash, toAddress, toBaseAddress, toBytes, toCslValue, toEnterpriseAddress, toLovelace, toNativeScript, toPlutusData, toRewardAddress, toScriptRef, toUTF8, txInParameterToObj, txInToObj, utxoToObj, v2ScriptToBech32, withdrawalToObj };
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
} from "@meshsdk/common";
|
|
6
6
|
|
|
7
7
|
// src/deser/csl.ts
|
|
8
|
-
import * as csl from "@sidan-lab/
|
|
8
|
+
import * as csl from "@sidan-lab/whisky-js-nodejs";
|
|
9
9
|
|
|
10
10
|
// src/deser/constants.ts
|
|
11
11
|
var LANGUAGE_VERSIONS = {
|
|
@@ -101,7 +101,7 @@ var castDataToPlutusData = ({
|
|
|
101
101
|
return csl.PlutusData.from_hex(content);
|
|
102
102
|
}
|
|
103
103
|
return csl.PlutusData.from_json(
|
|
104
|
-
content,
|
|
104
|
+
castRawDataToJsonString(content),
|
|
105
105
|
csl.PlutusDatumSchema.DetailedSchema
|
|
106
106
|
);
|
|
107
107
|
};
|
|
@@ -140,6 +140,29 @@ var toNativeScript = (script) => {
|
|
|
140
140
|
);
|
|
141
141
|
}
|
|
142
142
|
};
|
|
143
|
+
var toCslValue = (assets) => {
|
|
144
|
+
let cslValue = void 0;
|
|
145
|
+
let multiAsset = csl.MultiAsset.new();
|
|
146
|
+
for (const asset of assets) {
|
|
147
|
+
if (asset.unit === "lovelace" || asset.unit === "") {
|
|
148
|
+
cslValue = csl.Value.new(csl.BigNum.from_str(asset.quantity));
|
|
149
|
+
} else {
|
|
150
|
+
const policyId = csl.ScriptHash.from_hex(asset.unit.slice(0, 56));
|
|
151
|
+
const assetName = csl.AssetName.new(
|
|
152
|
+
Buffer.from(asset.unit.slice(56), "hex")
|
|
153
|
+
);
|
|
154
|
+
const quantity = csl.BigNum.from_str(asset.quantity);
|
|
155
|
+
multiAsset.set_asset(policyId, assetName, quantity);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (cslValue !== void 0) {
|
|
159
|
+
cslValue.set_multiasset(multiAsset);
|
|
160
|
+
} else {
|
|
161
|
+
cslValue = csl.Value.new(csl.BigNum.from_str("0"));
|
|
162
|
+
cslValue.set_multiasset(multiAsset);
|
|
163
|
+
}
|
|
164
|
+
return cslValue;
|
|
165
|
+
};
|
|
143
166
|
|
|
144
167
|
// src/deser/deserializer.ts
|
|
145
168
|
var deserializeAddress = (address) => csl.Address.from_bytes(toBytes(address));
|
|
@@ -234,8 +257,11 @@ var resolveRewardAddress = (bech32) => {
|
|
|
234
257
|
throw new Error(`An error occurred during resolveRewardAddress: ${error}.`);
|
|
235
258
|
}
|
|
236
259
|
};
|
|
237
|
-
var resolveDataHash = (
|
|
238
|
-
const plutusData =
|
|
260
|
+
var resolveDataHash = (rawData, type = "Mesh") => {
|
|
261
|
+
const plutusData = castDataToPlutusData({
|
|
262
|
+
content: rawData,
|
|
263
|
+
type
|
|
264
|
+
});
|
|
239
265
|
const dataHash = csl.hash_plutus_data(plutusData);
|
|
240
266
|
return dataHash.to_hex();
|
|
241
267
|
};
|
|
@@ -381,7 +407,7 @@ var keyHashToRewardAddress = (keyHashHex, network = 1) => {
|
|
|
381
407
|
};
|
|
382
408
|
|
|
383
409
|
// src/utils/transaction.ts
|
|
384
|
-
import { js_get_tx_outs_utxo } from "@sidan-lab/
|
|
410
|
+
import { js_get_tx_outs_utxo } from "@sidan-lab/whisky-js-nodejs";
|
|
385
411
|
|
|
386
412
|
// src/wasm.ts
|
|
387
413
|
var parseWasmResult = (result) => {
|
|
@@ -518,10 +544,10 @@ var getTransactionOutputs = (txHex) => {
|
|
|
518
544
|
// src/utils/aiken.ts
|
|
519
545
|
var applyParamsToScript = (rawScript, params, type = "Mesh") => {
|
|
520
546
|
const cslParams = csl.JsVecString.new();
|
|
521
|
-
let paramType =
|
|
547
|
+
let paramType = "cbor";
|
|
522
548
|
switch (type) {
|
|
523
549
|
case "JSON":
|
|
524
|
-
paramType =
|
|
550
|
+
paramType = "json";
|
|
525
551
|
params.forEach((param) => {
|
|
526
552
|
if (typeof param === "object") {
|
|
527
553
|
cslParams.add(JSON.stringify(param));
|
|
@@ -548,7 +574,7 @@ var applyCborEncoding = (rawScript) => {
|
|
|
548
574
|
return csl.js_apply_params_to_script(
|
|
549
575
|
rawScript,
|
|
550
576
|
csl.JsVecString.new(),
|
|
551
|
-
|
|
577
|
+
"cbor"
|
|
552
578
|
);
|
|
553
579
|
};
|
|
554
580
|
|
|
@@ -570,7 +596,9 @@ import {
|
|
|
570
596
|
} from "@meshsdk/common";
|
|
571
597
|
|
|
572
598
|
// src/core/adaptor/index.ts
|
|
573
|
-
import {
|
|
599
|
+
import {
|
|
600
|
+
validityRangeToObj
|
|
601
|
+
} from "@meshsdk/common";
|
|
574
602
|
|
|
575
603
|
// src/core/adaptor/data.ts
|
|
576
604
|
var builderDataToCbor = ({ type, content }) => {
|
|
@@ -817,6 +845,41 @@ var relayToObj = (relay) => {
|
|
|
817
845
|
}
|
|
818
846
|
};
|
|
819
847
|
|
|
848
|
+
// src/core/adaptor/metadata.ts
|
|
849
|
+
import JSONbig2 from "json-bigint";
|
|
850
|
+
var txMetadataToObj = (metadata) => {
|
|
851
|
+
const result = [];
|
|
852
|
+
metadata.forEach((value, key) => {
|
|
853
|
+
result.push({
|
|
854
|
+
tag: key.toString(),
|
|
855
|
+
metadata: JSONbig2.stringify(metadatumToObj(value))
|
|
856
|
+
});
|
|
857
|
+
});
|
|
858
|
+
return result;
|
|
859
|
+
};
|
|
860
|
+
var metadatumToObj = (metadatum) => {
|
|
861
|
+
if (typeof metadatum === "number" || typeof metadatum === "string") {
|
|
862
|
+
return metadatum;
|
|
863
|
+
} else if (typeof metadatum === "bigint") {
|
|
864
|
+
return metadatum.toString();
|
|
865
|
+
} else if (metadatum instanceof Uint8Array) {
|
|
866
|
+
return uint8ArrayToHex(metadatum);
|
|
867
|
+
} else if (metadatum instanceof Map) {
|
|
868
|
+
const result = {};
|
|
869
|
+
metadatum.forEach((value, key) => {
|
|
870
|
+
result[metadatumToObj(key)] = metadatumToObj(value);
|
|
871
|
+
});
|
|
872
|
+
return result;
|
|
873
|
+
} else if (Array.isArray(metadatum)) {
|
|
874
|
+
return metadatum.map(metadatumToObj);
|
|
875
|
+
} else {
|
|
876
|
+
throw new Error("metadatumToObj: Unsupported Metadatum type");
|
|
877
|
+
}
|
|
878
|
+
};
|
|
879
|
+
var uint8ArrayToHex = (bytes) => {
|
|
880
|
+
return Array.from(bytes).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
881
|
+
};
|
|
882
|
+
|
|
820
883
|
// src/core/adaptor/mint.ts
|
|
821
884
|
var mintItemToObj = (mintItem) => {
|
|
822
885
|
switch (mintItem.type) {
|
|
@@ -899,41 +962,6 @@ var outputToObj = (output) => {
|
|
|
899
962
|
};
|
|
900
963
|
};
|
|
901
964
|
|
|
902
|
-
// src/core/adaptor/metadata.ts
|
|
903
|
-
import JSONbig2 from "json-bigint";
|
|
904
|
-
var txMetadataToObj = (metadata) => {
|
|
905
|
-
const result = [];
|
|
906
|
-
metadata.forEach((value, key) => {
|
|
907
|
-
result.push({
|
|
908
|
-
tag: key.toString(),
|
|
909
|
-
metadata: JSONbig2.stringify(metadatumToObj(value))
|
|
910
|
-
});
|
|
911
|
-
});
|
|
912
|
-
return result;
|
|
913
|
-
};
|
|
914
|
-
var metadatumToObj = (metadatum) => {
|
|
915
|
-
if (typeof metadatum === "number" || typeof metadatum === "string") {
|
|
916
|
-
return metadatum;
|
|
917
|
-
} else if (typeof metadatum === "bigint") {
|
|
918
|
-
return metadatum.toString();
|
|
919
|
-
} else if (metadatum instanceof Uint8Array) {
|
|
920
|
-
return uint8ArrayToHex(metadatum);
|
|
921
|
-
} else if (metadatum instanceof Map) {
|
|
922
|
-
const result = {};
|
|
923
|
-
metadatum.forEach((value, key) => {
|
|
924
|
-
result[metadatumToObj(key)] = metadatumToObj(value);
|
|
925
|
-
});
|
|
926
|
-
return result;
|
|
927
|
-
} else if (Array.isArray(metadatum)) {
|
|
928
|
-
return metadatum.map(metadatumToObj);
|
|
929
|
-
} else {
|
|
930
|
-
throw new Error("metadatumToObj: Unsupported Metadatum type");
|
|
931
|
-
}
|
|
932
|
-
};
|
|
933
|
-
var uint8ArrayToHex = (bytes) => {
|
|
934
|
-
return Array.from(bytes).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
935
|
-
};
|
|
936
|
-
|
|
937
965
|
// src/core/adaptor/txIn.ts
|
|
938
966
|
var txInToObj = (txIn) => {
|
|
939
967
|
switch (txIn.type) {
|
|
@@ -1218,13 +1246,28 @@ var meshTxBuilderBodyToObj = ({
|
|
|
1218
1246
|
fee,
|
|
1219
1247
|
network
|
|
1220
1248
|
}) => {
|
|
1249
|
+
let mintsObj = [];
|
|
1250
|
+
mints.forEach((mint) => {
|
|
1251
|
+
mint.mintValue.forEach((mintValue) => {
|
|
1252
|
+
mintsObj.push(
|
|
1253
|
+
mintItemToObj({
|
|
1254
|
+
type: mint.type,
|
|
1255
|
+
policyId: mint.policyId,
|
|
1256
|
+
assetName: mintValue.assetName,
|
|
1257
|
+
amount: mintValue.amount,
|
|
1258
|
+
scriptSource: mint.scriptSource,
|
|
1259
|
+
redeemer: mint.redeemer
|
|
1260
|
+
})
|
|
1261
|
+
);
|
|
1262
|
+
});
|
|
1263
|
+
});
|
|
1221
1264
|
return {
|
|
1222
1265
|
inputs: inputs.map(txInToObj),
|
|
1223
1266
|
outputs: outputs.map(outputToObj),
|
|
1224
1267
|
collaterals: collaterals.map(collateralTxInToObj),
|
|
1225
1268
|
requiredSignatures,
|
|
1226
1269
|
referenceInputs,
|
|
1227
|
-
mints:
|
|
1270
|
+
mints: mintsObj,
|
|
1228
1271
|
changeAddress,
|
|
1229
1272
|
metadata: txMetadataToObj(metadata),
|
|
1230
1273
|
validityRange: validityRangeToObj(validityRange),
|
|
@@ -1238,28 +1281,21 @@ var meshTxBuilderBodyToObj = ({
|
|
|
1238
1281
|
};
|
|
1239
1282
|
|
|
1240
1283
|
// src/core/serializer.ts
|
|
1284
|
+
var VKEY_PUBKEY_SIZE_BYTES = 32;
|
|
1285
|
+
var VKEY_SIGNATURE_SIZE_BYTES = 64;
|
|
1286
|
+
var CHAIN_CODE_SIZE_BYTES = 32;
|
|
1241
1287
|
var CSLSerializer = class {
|
|
1242
1288
|
/**
|
|
1243
1289
|
* Set to true to enable verbose logging for the txBodyJson prior going into build
|
|
1244
1290
|
*/
|
|
1245
|
-
verbose;
|
|
1246
1291
|
protocolParams;
|
|
1247
1292
|
meshTxBuilderBody = emptyTxBuilderBody();
|
|
1248
|
-
constructor(protocolParams
|
|
1293
|
+
constructor(protocolParams) {
|
|
1249
1294
|
this.protocolParams = protocolParams || DEFAULT_PROTOCOL_PARAMETERS;
|
|
1250
|
-
this.verbose = verbose;
|
|
1251
1295
|
}
|
|
1252
|
-
serializeTxBody(txBody, protocolParams
|
|
1253
|
-
if (!balanced) {
|
|
1254
|
-
throw new Error(
|
|
1255
|
-
"Unbalanced transactions are not supported with CSL serializer"
|
|
1256
|
-
);
|
|
1257
|
-
}
|
|
1296
|
+
serializeTxBody(txBody, protocolParams) {
|
|
1258
1297
|
const txBodyJson = JSONbig3.stringify(meshTxBuilderBodyToObj(txBody));
|
|
1259
1298
|
const params = JSONbig3.stringify(protocolParams || this.protocolParams);
|
|
1260
|
-
if (this.verbose) {
|
|
1261
|
-
console.log("txBodyJson", txBodyJson);
|
|
1262
|
-
}
|
|
1263
1299
|
const txBuildResult = csl.js_serialize_tx_body(txBodyJson, params);
|
|
1264
1300
|
if (txBuildResult.get_status() !== "success") {
|
|
1265
1301
|
throw new Error(`txBuildResult error: ${txBuildResult.get_error()}`);
|
|
@@ -1332,8 +1368,8 @@ var CSLSerializer = class {
|
|
|
1332
1368
|
}
|
|
1333
1369
|
},
|
|
1334
1370
|
data: {
|
|
1335
|
-
resolveDataHash: function(
|
|
1336
|
-
return resolveDataHash(
|
|
1371
|
+
resolveDataHash: function(rawData, type = "Mesh") {
|
|
1372
|
+
return resolveDataHash(rawData, type);
|
|
1337
1373
|
}
|
|
1338
1374
|
},
|
|
1339
1375
|
script: {
|
|
@@ -1342,6 +1378,125 @@ var CSLSerializer = class {
|
|
|
1342
1378
|
}
|
|
1343
1379
|
}
|
|
1344
1380
|
};
|
|
1381
|
+
serializeOutput(output) {
|
|
1382
|
+
let cslOutputBuilder = csl.TransactionOutputBuilder.new().with_address(
|
|
1383
|
+
csl.Address.from_bech32(output.address)
|
|
1384
|
+
);
|
|
1385
|
+
if (output.datum?.type === "Hash") {
|
|
1386
|
+
cslOutputBuilder.with_data_hash(
|
|
1387
|
+
csl.hash_plutus_data(castDataToPlutusData(output.datum.data))
|
|
1388
|
+
);
|
|
1389
|
+
} else if (output.datum?.type === "Inline") {
|
|
1390
|
+
cslOutputBuilder.with_plutus_data(
|
|
1391
|
+
castDataToPlutusData(output.datum.data)
|
|
1392
|
+
);
|
|
1393
|
+
} else if (output.datum?.type === "Embedded") {
|
|
1394
|
+
throw new Error("Embedded datum not supported");
|
|
1395
|
+
}
|
|
1396
|
+
if (output.referenceScript) {
|
|
1397
|
+
switch (output.referenceScript.version) {
|
|
1398
|
+
case "V1": {
|
|
1399
|
+
cslOutputBuilder.with_script_ref(
|
|
1400
|
+
csl.ScriptRef.new_plutus_script(
|
|
1401
|
+
csl.PlutusScript.from_hex_with_version(
|
|
1402
|
+
output.referenceScript.code,
|
|
1403
|
+
csl.Language.new_plutus_v1()
|
|
1404
|
+
)
|
|
1405
|
+
)
|
|
1406
|
+
);
|
|
1407
|
+
break;
|
|
1408
|
+
}
|
|
1409
|
+
case "V2": {
|
|
1410
|
+
cslOutputBuilder.with_script_ref(
|
|
1411
|
+
csl.ScriptRef.new_plutus_script(
|
|
1412
|
+
csl.PlutusScript.from_hex_with_version(
|
|
1413
|
+
output.referenceScript.code,
|
|
1414
|
+
csl.Language.new_plutus_v2()
|
|
1415
|
+
)
|
|
1416
|
+
)
|
|
1417
|
+
);
|
|
1418
|
+
break;
|
|
1419
|
+
}
|
|
1420
|
+
case "V3": {
|
|
1421
|
+
cslOutputBuilder.with_script_ref(
|
|
1422
|
+
csl.ScriptRef.new_plutus_script(
|
|
1423
|
+
csl.PlutusScript.from_hex_with_version(
|
|
1424
|
+
output.referenceScript.code,
|
|
1425
|
+
csl.Language.new_plutus_v3()
|
|
1426
|
+
)
|
|
1427
|
+
)
|
|
1428
|
+
);
|
|
1429
|
+
break;
|
|
1430
|
+
}
|
|
1431
|
+
default: {
|
|
1432
|
+
cslOutputBuilder.with_script_ref(
|
|
1433
|
+
csl.ScriptRef.new_native_script(
|
|
1434
|
+
csl.NativeScript.from_hex(output.referenceScript.code)
|
|
1435
|
+
)
|
|
1436
|
+
);
|
|
1437
|
+
break;
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
return cslOutputBuilder.next().with_value(toCslValue(output.amount)).build().to_hex();
|
|
1442
|
+
}
|
|
1443
|
+
serializeTxBodyWithMockSignatures(txBuilderBody, protocolParams) {
|
|
1444
|
+
const txHex = this.serializeTxBody(txBuilderBody, protocolParams);
|
|
1445
|
+
const cslTx = csl.Transaction.from_hex(txHex);
|
|
1446
|
+
const mockWitnessSet = cslTx.witness_set();
|
|
1447
|
+
const mockVkeyWitnesses = mockWitnessSet.vkeys() ?? csl.Vkeywitnesses.new();
|
|
1448
|
+
const mockBootstrapWitnesses = mockWitnessSet.bootstraps() ?? csl.BootstrapWitnesses.new();
|
|
1449
|
+
for (let i = 0; i < txBuilderBody.expectedNumberKeyWitnesses; i++) {
|
|
1450
|
+
const numberInHex = this.numberToIntegerHex(i);
|
|
1451
|
+
const mockVkey = csl.Vkey.new(
|
|
1452
|
+
csl.PublicKey.from_hex(this.mockPubkey(numberInHex))
|
|
1453
|
+
);
|
|
1454
|
+
const mockSignature = csl.Ed25519Signature.from_hex(
|
|
1455
|
+
this.mockSignature(numberInHex)
|
|
1456
|
+
);
|
|
1457
|
+
mockVkeyWitnesses.add(csl.Vkeywitness.new(mockVkey, mockSignature));
|
|
1458
|
+
}
|
|
1459
|
+
this.meshTxBuilderBody.expectedByronAddressWitnesses.forEach(
|
|
1460
|
+
(bootstrapWitness, i) => {
|
|
1461
|
+
const address = csl.ByronAddress.from_base58(bootstrapWitness);
|
|
1462
|
+
const numberInHex = this.numberToIntegerHex(i);
|
|
1463
|
+
const pubKeyHex = this.mockPubkey(numberInHex);
|
|
1464
|
+
const mockVkey = csl.Vkey.new(csl.PublicKey.from_hex(pubKeyHex));
|
|
1465
|
+
const signature = this.mockSignature(numberInHex);
|
|
1466
|
+
const chainCode = this.mockChainCode(numberInHex);
|
|
1467
|
+
mockBootstrapWitnesses.add(
|
|
1468
|
+
csl.BootstrapWitness.new(
|
|
1469
|
+
mockVkey,
|
|
1470
|
+
csl.Ed25519Signature.from_hex(signature),
|
|
1471
|
+
Buffer.from(chainCode, "hex"),
|
|
1472
|
+
address.attributes()
|
|
1473
|
+
)
|
|
1474
|
+
);
|
|
1475
|
+
}
|
|
1476
|
+
);
|
|
1477
|
+
mockWitnessSet.set_vkeys(mockVkeyWitnesses);
|
|
1478
|
+
mockWitnessSet.set_bootstraps(mockBootstrapWitnesses);
|
|
1479
|
+
return csl.Transaction.new(
|
|
1480
|
+
cslTx.body(),
|
|
1481
|
+
mockWitnessSet,
|
|
1482
|
+
cslTx.auxiliary_data()
|
|
1483
|
+
).to_hex();
|
|
1484
|
+
}
|
|
1485
|
+
serializeValue(value) {
|
|
1486
|
+
return toCslValue(value).to_hex();
|
|
1487
|
+
}
|
|
1488
|
+
mockPubkey(numberInHex) {
|
|
1489
|
+
return "0".repeat(VKEY_PUBKEY_SIZE_BYTES * 2 - numberInHex.length).concat(numberInHex);
|
|
1490
|
+
}
|
|
1491
|
+
mockSignature(numberInHex) {
|
|
1492
|
+
return "0".repeat(VKEY_SIGNATURE_SIZE_BYTES * 2 - numberInHex.length).concat(numberInHex);
|
|
1493
|
+
}
|
|
1494
|
+
mockChainCode = (numberInHex) => {
|
|
1495
|
+
return "0".repeat(CHAIN_CODE_SIZE_BYTES * 2 - numberInHex.length).concat(numberInHex);
|
|
1496
|
+
};
|
|
1497
|
+
numberToIntegerHex = (number) => {
|
|
1498
|
+
return BigInt(number).toString(16);
|
|
1499
|
+
};
|
|
1345
1500
|
};
|
|
1346
1501
|
|
|
1347
1502
|
// src/offline-providers/offline-evaluator.ts
|
|
@@ -1516,6 +1671,7 @@ export {
|
|
|
1516
1671
|
toAddress,
|
|
1517
1672
|
toBaseAddress,
|
|
1518
1673
|
toBytes,
|
|
1674
|
+
toCslValue,
|
|
1519
1675
|
toEnterpriseAddress,
|
|
1520
1676
|
toLovelace,
|
|
1521
1677
|
toNativeScript,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshsdk/core-csl",
|
|
3
|
-
"version": "1.9.0-beta.
|
|
3
|
+
"version": "1.9.0-beta.52",
|
|
4
4
|
"description": "Types and utilities functions between Mesh and cardano-serialization-lib",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"test": "jest"
|
|
28
28
|
},
|
|
29
29
|
"browser": {
|
|
30
|
-
"@sidan-lab/
|
|
30
|
+
"@sidan-lab/whisky-js-nodejs": "@sidan-lab/whisky-js-browser"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@meshsdk/configs": "*",
|
|
34
|
-
"@meshsdk/provider": "1.9.0-beta.
|
|
34
|
+
"@meshsdk/provider": "1.9.0-beta.52",
|
|
35
35
|
"@types/json-bigint": "^1.0.4",
|
|
36
36
|
"eslint": "^8.57.0",
|
|
37
37
|
"ts-jest": "^29.1.4",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
"typescript": "^5.3.3"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@meshsdk/common": "1.9.0-beta.
|
|
43
|
-
"@sidan-lab/
|
|
44
|
-
"@sidan-lab/
|
|
42
|
+
"@meshsdk/common": "1.9.0-beta.52",
|
|
43
|
+
"@sidan-lab/whisky-js-browser": "^1.0.1",
|
|
44
|
+
"@sidan-lab/whisky-js-nodejs": "^1.0.1",
|
|
45
45
|
"@types/base32-encoding": "^1.0.2",
|
|
46
46
|
"base32-encoding": "^1.0.0",
|
|
47
47
|
"bech32": "^2.0.0",
|