@meshsdk/core-csl 1.5.28

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.
Files changed (102) hide show
  1. package/README.md +5 -0
  2. package/dist/cjs/core/adaptor/data.d.ts +3 -0
  3. package/dist/cjs/core/adaptor/data.js +21 -0
  4. package/dist/cjs/core/adaptor/index.d.ts +15 -0
  5. package/dist/cjs/core/adaptor/index.js +25 -0
  6. package/dist/cjs/core/adaptor/mint.d.ts +5 -0
  7. package/dist/cjs/core/adaptor/mint.js +42 -0
  8. package/dist/cjs/core/adaptor/output.d.ts +2 -0
  9. package/dist/cjs/core/adaptor/output.js +33 -0
  10. package/dist/cjs/core/adaptor/script.d.ts +3 -0
  11. package/dist/cjs/core/adaptor/script.js +46 -0
  12. package/dist/cjs/core/adaptor/txIn.d.ts +5 -0
  13. package/dist/cjs/core/adaptor/txIn.js +76 -0
  14. package/dist/cjs/core/adaptor/utxo.d.ts +2 -0
  15. package/dist/cjs/core/adaptor/utxo.js +20 -0
  16. package/dist/cjs/core/adaptor/withdrawal.d.ts +2 -0
  17. package/dist/cjs/core/adaptor/withdrawal.js +30 -0
  18. package/dist/cjs/core/index.d.ts +1 -0
  19. package/dist/cjs/core/index.js +17 -0
  20. package/dist/cjs/core/serializer.d.ts +12 -0
  21. package/dist/cjs/core/serializer.js +111 -0
  22. package/dist/cjs/deser/constants.d.ts +13 -0
  23. package/dist/cjs/deser/constants.js +16 -0
  24. package/dist/cjs/deser/converter.d.ts +17 -0
  25. package/dist/cjs/deser/converter.js +203 -0
  26. package/dist/cjs/deser/csl.d.ts +1 -0
  27. package/dist/cjs/deser/csl.js +27 -0
  28. package/dist/cjs/deser/deserializer.d.ts +19 -0
  29. package/dist/cjs/deser/deserializer.js +40 -0
  30. package/dist/cjs/deser/index.d.ts +5 -0
  31. package/dist/cjs/deser/index.js +21 -0
  32. package/dist/cjs/deser/resolver.d.ts +12 -0
  33. package/dist/cjs/deser/resolver.js +90 -0
  34. package/dist/cjs/index.d.ts +3 -0
  35. package/dist/cjs/index.js +19 -0
  36. package/dist/cjs/utils/address.d.ts +9 -0
  37. package/dist/cjs/utils/address.js +61 -0
  38. package/dist/cjs/utils/aiken.d.ts +17 -0
  39. package/dist/cjs/utils/aiken.js +52 -0
  40. package/dist/cjs/utils/credentials.d.ts +1 -0
  41. package/dist/cjs/utils/credentials.js +10 -0
  42. package/dist/cjs/utils/datum.d.ts +4 -0
  43. package/dist/cjs/utils/datum.js +18 -0
  44. package/dist/cjs/utils/index.d.ts +7 -0
  45. package/dist/cjs/utils/index.js +23 -0
  46. package/dist/cjs/utils/scripts.d.ts +1 -0
  47. package/dist/cjs/utils/scripts.js +6 -0
  48. package/dist/cjs/utils/staking.d.ts +4 -0
  49. package/dist/cjs/utils/staking.js +34 -0
  50. package/dist/cjs/utils/transaction.d.ts +2 -0
  51. package/dist/cjs/utils/transaction.js +15 -0
  52. package/dist/mjs/core/adaptor/data.d.ts +3 -0
  53. package/dist/mjs/core/adaptor/data.js +16 -0
  54. package/dist/mjs/core/adaptor/index.d.ts +15 -0
  55. package/dist/mjs/core/adaptor/index.js +21 -0
  56. package/dist/mjs/core/adaptor/mint.d.ts +5 -0
  57. package/dist/mjs/core/adaptor/mint.js +35 -0
  58. package/dist/mjs/core/adaptor/output.d.ts +2 -0
  59. package/dist/mjs/core/adaptor/output.js +29 -0
  60. package/dist/mjs/core/adaptor/script.d.ts +3 -0
  61. package/dist/mjs/core/adaptor/script.js +39 -0
  62. package/dist/mjs/core/adaptor/txIn.d.ts +5 -0
  63. package/dist/mjs/core/adaptor/txIn.js +68 -0
  64. package/dist/mjs/core/adaptor/utxo.d.ts +2 -0
  65. package/dist/mjs/core/adaptor/utxo.js +16 -0
  66. package/dist/mjs/core/adaptor/withdrawal.d.ts +2 -0
  67. package/dist/mjs/core/adaptor/withdrawal.js +26 -0
  68. package/dist/mjs/core/index.d.ts +1 -0
  69. package/dist/mjs/core/index.js +1 -0
  70. package/dist/mjs/core/serializer.d.ts +12 -0
  71. package/dist/mjs/core/serializer.js +105 -0
  72. package/dist/mjs/deser/constants.d.ts +13 -0
  73. package/dist/mjs/deser/constants.js +13 -0
  74. package/dist/mjs/deser/converter.d.ts +17 -0
  75. package/dist/mjs/deser/converter.js +184 -0
  76. package/dist/mjs/deser/csl.d.ts +1 -0
  77. package/dist/mjs/deser/csl.js +1 -0
  78. package/dist/mjs/deser/deserializer.d.ts +19 -0
  79. package/dist/mjs/deser/deserializer.js +20 -0
  80. package/dist/mjs/deser/index.d.ts +5 -0
  81. package/dist/mjs/deser/index.js +5 -0
  82. package/dist/mjs/deser/resolver.d.ts +12 -0
  83. package/dist/mjs/deser/resolver.js +75 -0
  84. package/dist/mjs/index.d.ts +3 -0
  85. package/dist/mjs/index.js +3 -0
  86. package/dist/mjs/utils/address.d.ts +9 -0
  87. package/dist/mjs/utils/address.js +50 -0
  88. package/dist/mjs/utils/aiken.d.ts +17 -0
  89. package/dist/mjs/utils/aiken.js +47 -0
  90. package/dist/mjs/utils/credentials.d.ts +1 -0
  91. package/dist/mjs/utils/credentials.js +6 -0
  92. package/dist/mjs/utils/datum.d.ts +4 -0
  93. package/dist/mjs/utils/datum.js +13 -0
  94. package/dist/mjs/utils/index.d.ts +7 -0
  95. package/dist/mjs/utils/index.js +7 -0
  96. package/dist/mjs/utils/scripts.d.ts +1 -0
  97. package/dist/mjs/utils/scripts.js +2 -0
  98. package/dist/mjs/utils/staking.d.ts +4 -0
  99. package/dist/mjs/utils/staking.js +25 -0
  100. package/dist/mjs/utils/transaction.d.ts +2 -0
  101. package/dist/mjs/utils/transaction.js +10 -0
  102. package/package.json +45 -0
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # mesh-core-csl
2
+
3
+ Types and utilities functions between Mesh and [cardano-serialization-lib](https://github.com/Emurgo/cardano-serialization-lib)
4
+
5
+ [meshjs.dev](https://meshjs.dev/)
@@ -0,0 +1,3 @@
1
+ import { BuilderData, Redeemer } from "@meshsdk/common";
2
+ export declare const builderDataToCbor: ({ type, content }: BuilderData) => string;
3
+ export declare const redeemerToObj: (redeemer: Redeemer) => object;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.redeemerToObj = exports.builderDataToCbor = void 0;
4
+ const deser_1 = require("../../deser");
5
+ const builderDataToCbor = ({ type, content }) => {
6
+ if (type === "Mesh") {
7
+ return (0, deser_1.toPlutusData)(content).to_hex();
8
+ }
9
+ if (type === "CBOR") {
10
+ return deser_1.csl.PlutusData.from_hex(content).to_hex();
11
+ }
12
+ return deser_1.csl.PlutusData.from_json(content, deser_1.csl.PlutusDatumSchema.DetailedSchema).to_hex();
13
+ };
14
+ exports.builderDataToCbor = builderDataToCbor;
15
+ const redeemerToObj = (redeemer) => {
16
+ return {
17
+ data: (0, exports.builderDataToCbor)(redeemer.data),
18
+ exUnits: redeemer.exUnits,
19
+ };
20
+ };
21
+ exports.redeemerToObj = redeemerToObj;
@@ -0,0 +1,15 @@
1
+ import { MeshTxBuilderBody } from "@meshsdk/common";
2
+ export declare const meshTxBuilderBodyToObj: ({ inputs, outputs, collaterals, requiredSignatures, referenceInputs, mints, changeAddress, metadata, validityRange, certificates, signingKey, withdrawals, }: MeshTxBuilderBody) => {
3
+ inputs: object[];
4
+ outputs: object[];
5
+ collaterals: object[];
6
+ requiredSignatures: string[];
7
+ referenceInputs: import("@meshsdk/common").RefTxIn[];
8
+ mints: object[];
9
+ changeAddress: string;
10
+ metadata: import("@meshsdk/common").Metadata[];
11
+ validityRange: object;
12
+ certificates: object[];
13
+ signingKey: string[];
14
+ withdrawals: object[];
15
+ };
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.meshTxBuilderBodyToObj = void 0;
4
+ const common_1 = require("@meshsdk/common");
5
+ const mint_1 = require("./mint");
6
+ const output_1 = require("./output");
7
+ const txIn_1 = require("./txIn");
8
+ const withdrawal_1 = require("./withdrawal");
9
+ const meshTxBuilderBodyToObj = ({ inputs, outputs, collaterals, requiredSignatures, referenceInputs, mints, changeAddress, metadata, validityRange, certificates, signingKey, withdrawals, }) => {
10
+ return {
11
+ inputs: inputs.map(txIn_1.txInToObj),
12
+ outputs: outputs.map(output_1.outputToObj),
13
+ collaterals: collaterals.map(txIn_1.collateralTxInToObj),
14
+ requiredSignatures,
15
+ referenceInputs: referenceInputs,
16
+ mints: mints.map((mint) => (0, mint_1.mintItemToObj)(mint)),
17
+ changeAddress,
18
+ metadata: metadata,
19
+ validityRange: (0, common_1.validityRangeToObj)(validityRange),
20
+ certificates: certificates.map(common_1.certificateToObj),
21
+ signingKey: signingKey,
22
+ withdrawals: withdrawals.map(withdrawal_1.withdrawalToObj),
23
+ };
24
+ };
25
+ exports.meshTxBuilderBodyToObj = meshTxBuilderBodyToObj;
@@ -0,0 +1,5 @@
1
+ import { MintItem } from "@meshsdk/common";
2
+ export declare const mintItemToObj: (mintItem: MintItem) => object;
3
+ export declare const plutusMintItemToObj: (mintItem: Required<MintItem>) => object;
4
+ export declare const nativeMintItemToObj: (mintItem: Omit<Required<MintItem>, "redeemer">) => object;
5
+ export declare const mintParametersObj: (mintItem: MintItem) => object;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mintParametersObj = exports.nativeMintItemToObj = exports.plutusMintItemToObj = exports.mintItemToObj = void 0;
4
+ const data_1 = require("./data");
5
+ const script_1 = require("./script");
6
+ const mintItemToObj = (mintItem) => {
7
+ switch (mintItem.type) {
8
+ case "Plutus":
9
+ return {
10
+ scriptMint: (0, exports.plutusMintItemToObj)(mintItem),
11
+ };
12
+ case "Native":
13
+ return {
14
+ simpleScriptMint: (0, exports.nativeMintItemToObj)(mintItem),
15
+ };
16
+ }
17
+ };
18
+ exports.mintItemToObj = mintItemToObj;
19
+ const plutusMintItemToObj = (mintItem) => {
20
+ let scriptSource = (0, script_1.scriptSourceToObj)(mintItem.scriptSource);
21
+ return {
22
+ mint: (0, exports.mintParametersObj)(mintItem),
23
+ redeemer: mintItem.redeemer ? (0, data_1.redeemerToObj)(mintItem.redeemer) : null,
24
+ scriptSource,
25
+ };
26
+ };
27
+ exports.plutusMintItemToObj = plutusMintItemToObj;
28
+ const nativeMintItemToObj = (mintItem) => {
29
+ return {
30
+ mint: (0, exports.mintParametersObj)(mintItem),
31
+ scriptSource: (0, script_1.simpleScriptSourceToObj)(mintItem.scriptSource),
32
+ };
33
+ };
34
+ exports.nativeMintItemToObj = nativeMintItemToObj;
35
+ const mintParametersObj = (mintItem) => {
36
+ return {
37
+ policyId: mintItem.policyId,
38
+ assetName: mintItem.assetName,
39
+ amount: BigInt(mintItem.amount),
40
+ };
41
+ };
42
+ exports.mintParametersObj = mintParametersObj;
@@ -0,0 +1,2 @@
1
+ import { Output } from "@meshsdk/common";
2
+ export declare const outputToObj: (output: Output) => object;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.outputToObj = void 0;
4
+ const data_1 = require("./data");
5
+ const outputToObj = (output) => {
6
+ let datum = null;
7
+ if (output.datum) {
8
+ switch (output.datum.type) {
9
+ case "Inline":
10
+ datum = { inline: (0, data_1.builderDataToCbor)(output.datum.data) };
11
+ break;
12
+ case "Hash":
13
+ datum = { hash: (0, data_1.builderDataToCbor)(output.datum.data) };
14
+ break;
15
+ }
16
+ }
17
+ // TODO: add native script
18
+ const refScript = output.referenceScript;
19
+ return {
20
+ address: output.address,
21
+ amount: output.amount,
22
+ datum,
23
+ referenceScript: output.referenceScript
24
+ ? {
25
+ providedScriptSource: {
26
+ scriptCbor: refScript.code,
27
+ languageVersion: refScript.version.toLocaleLowerCase(),
28
+ },
29
+ }
30
+ : null,
31
+ };
32
+ };
33
+ exports.outputToObj = outputToObj;
@@ -0,0 +1,3 @@
1
+ import { ScriptSource, SimpleScriptSourceInfo } from "@meshsdk/common";
2
+ export declare const scriptSourceToObj: (scriptSource: ScriptSource) => object;
3
+ export declare const simpleScriptSourceToObj: (scriptSource: SimpleScriptSourceInfo) => object;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.simpleScriptSourceToObj = exports.scriptSourceToObj = void 0;
4
+ const scriptSourceToObj = (scriptSource) => {
5
+ var _a, _b;
6
+ if (scriptSource.type === "Provided") {
7
+ return {
8
+ providedScriptSource: {
9
+ scriptCbor: scriptSource.script.code,
10
+ languageVersion: scriptSource.script.version.toLocaleLowerCase(),
11
+ },
12
+ };
13
+ }
14
+ return {
15
+ inlineScriptSource: {
16
+ refTxIn: {
17
+ txHash: scriptSource.txHash,
18
+ txIndex: scriptSource.txIndex,
19
+ },
20
+ spendingScriptHash: (_a = scriptSource.scriptHash) !== null && _a !== void 0 ? _a : "",
21
+ languageVersion: scriptSource.version.toLocaleLowerCase(),
22
+ scriptSize: BigInt((_b = scriptSource.scriptSize) !== null && _b !== void 0 ? _b : "0"),
23
+ },
24
+ };
25
+ };
26
+ exports.scriptSourceToObj = scriptSourceToObj;
27
+ const simpleScriptSourceToObj = (scriptSource) => {
28
+ var _a;
29
+ if (scriptSource.type === "Provided") {
30
+ return {
31
+ providedSimpleScriptSource: {
32
+ scriptCbor: scriptSource.scriptCode,
33
+ },
34
+ };
35
+ }
36
+ return {
37
+ inlineSimpleScriptSource: {
38
+ refTxIn: {
39
+ txHash: scriptSource.txHash,
40
+ txIndex: scriptSource.txIndex,
41
+ },
42
+ simpleScriptHash: (_a = scriptSource.simpleScriptHash) !== null && _a !== void 0 ? _a : "",
43
+ },
44
+ };
45
+ };
46
+ exports.simpleScriptSourceToObj = simpleScriptSourceToObj;
@@ -0,0 +1,5 @@
1
+ import { ScriptTxInParameter, TxIn, TxInParameter } from "@meshsdk/common";
2
+ export declare const txInToObj: (txIn: TxIn) => object;
3
+ export declare const collateralTxInToObj: (txIn: TxIn) => object;
4
+ export declare const txInParameterToObj: (txInParameter: TxInParameter) => object;
5
+ export declare const scriptTxInParameterToObj: (scriptTxInParameter: ScriptTxInParameter) => object;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.scriptTxInParameterToObj = exports.txInParameterToObj = exports.collateralTxInToObj = exports.txInToObj = void 0;
4
+ const data_1 = require("./data");
5
+ const script_1 = require("./script");
6
+ const txInToObj = (txIn) => {
7
+ switch (txIn.type) {
8
+ case "PubKey":
9
+ return {
10
+ pubKeyTxIn: {
11
+ txIn: (0, exports.txInParameterToObj)(txIn.txIn),
12
+ },
13
+ };
14
+ case "Script":
15
+ return {
16
+ scriptTxIn: {
17
+ txIn: (0, exports.txInParameterToObj)(txIn.txIn),
18
+ scriptTxIn: (0, exports.scriptTxInParameterToObj)(txIn.scriptTxIn),
19
+ },
20
+ };
21
+ case "SimpleScript":
22
+ // Not implemented
23
+ return {};
24
+ }
25
+ };
26
+ exports.txInToObj = txInToObj;
27
+ const collateralTxInToObj = (txIn) => {
28
+ return {
29
+ txIn: (0, exports.txInParameterToObj)(txIn.txIn),
30
+ };
31
+ };
32
+ exports.collateralTxInToObj = collateralTxInToObj;
33
+ const txInParameterToObj = (txInParameter) => {
34
+ var _a, _b;
35
+ return {
36
+ txHash: txInParameter.txHash,
37
+ txIndex: txInParameter.txIndex,
38
+ amount: (_a = txInParameter.amount) !== null && _a !== void 0 ? _a : null,
39
+ address: (_b = txInParameter.address) !== null && _b !== void 0 ? _b : null,
40
+ };
41
+ };
42
+ exports.txInParameterToObj = txInParameterToObj;
43
+ const scriptTxInParameterToObj = (scriptTxInParameter) => {
44
+ let scriptSource = null;
45
+ let datumSource = null;
46
+ if (scriptTxInParameter.scriptSource) {
47
+ scriptSource = (0, script_1.scriptSourceToObj)(scriptTxInParameter.scriptSource);
48
+ }
49
+ if (scriptTxInParameter.datumSource) {
50
+ switch (scriptTxInParameter.datumSource.type) {
51
+ case "Provided":
52
+ datumSource = {
53
+ providedDatumSource: {
54
+ data: (0, data_1.builderDataToCbor)(scriptTxInParameter.datumSource.data),
55
+ },
56
+ };
57
+ break;
58
+ case "Inline":
59
+ datumSource = {
60
+ inlineDatumSource: {
61
+ txHash: scriptTxInParameter.datumSource.txHash,
62
+ txIndex: scriptTxInParameter.datumSource.txIndex,
63
+ },
64
+ };
65
+ break;
66
+ }
67
+ }
68
+ return {
69
+ scriptSource,
70
+ datumSource,
71
+ redeemer: scriptTxInParameter.redeemer
72
+ ? (0, data_1.redeemerToObj)(scriptTxInParameter.redeemer)
73
+ : null,
74
+ };
75
+ };
76
+ exports.scriptTxInParameterToObj = scriptTxInParameterToObj;
@@ -0,0 +1,2 @@
1
+ import { UTxO } from "@meshsdk/common";
2
+ export declare const utxoToObj: ({ input: { outputIndex, txHash }, output: { address, amount, dataHash, plutusData, scriptRef, scriptHash }, }: UTxO) => object;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.utxoToObj = void 0;
4
+ const utxoToObj = ({ input: { outputIndex, txHash }, output: { address, amount, dataHash, plutusData, scriptRef, scriptHash }, }) => {
5
+ return {
6
+ input: {
7
+ outputIndex,
8
+ txHash,
9
+ },
10
+ output: {
11
+ address,
12
+ amount,
13
+ dataHash: dataHash !== null && dataHash !== void 0 ? dataHash : null,
14
+ plutusData: plutusData !== null && plutusData !== void 0 ? plutusData : null,
15
+ scriptRef: scriptRef !== null && scriptRef !== void 0 ? scriptRef : null,
16
+ scriptHash: scriptHash !== null && scriptHash !== void 0 ? scriptHash : null,
17
+ },
18
+ };
19
+ };
20
+ exports.utxoToObj = utxoToObj;
@@ -0,0 +1,2 @@
1
+ import { Withdrawal } from "@meshsdk/common";
2
+ export declare const withdrawalToObj: (withdrawal: Withdrawal) => object;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withdrawalToObj = void 0;
4
+ const data_1 = require("./data");
5
+ const script_1 = require("./script");
6
+ const withdrawalToObj = (withdrawal) => {
7
+ if ("pubKeyWithdrawal" in withdrawal) {
8
+ return {
9
+ pubKeyWithdrawal: {
10
+ address: withdrawal.pubKeyWithdrawal.address,
11
+ coin: BigInt(withdrawal.pubKeyWithdrawal.coin),
12
+ },
13
+ };
14
+ }
15
+ if (!withdrawal.plutusScriptWithdrawal.scriptSource) {
16
+ throw new Error("withdrawalToObj: missing scriptSource in plutusScriptWithdrawal.");
17
+ }
18
+ if (!withdrawal.plutusScriptWithdrawal.redeemer) {
19
+ throw new Error("withdrawalToObj: missing redeemer in plutusScriptWithdrawal.");
20
+ }
21
+ return {
22
+ plutusScriptWithdrawal: {
23
+ address: withdrawal.plutusScriptWithdrawal.address,
24
+ coin: BigInt(withdrawal.plutusScriptWithdrawal.coin),
25
+ scriptSource: (0, script_1.scriptSourceToObj)(withdrawal.plutusScriptWithdrawal.scriptSource),
26
+ redeemer: (0, data_1.redeemerToObj)(withdrawal.plutusScriptWithdrawal.redeemer),
27
+ },
28
+ };
29
+ };
30
+ exports.withdrawalToObj = withdrawalToObj;
@@ -0,0 +1 @@
1
+ export * from "./serializer";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./serializer"), exports);
@@ -0,0 +1,12 @@
1
+ import type { BuilderData, DeserializedAddress, IDeserializer, IMeshTxSerializer, IResolver, MeshTxBuilderBody, Protocol } from "@meshsdk/common";
2
+ export declare class CSLSerializer implements IMeshTxSerializer {
3
+ protocolParams: Protocol;
4
+ meshTxBuilderBody: MeshTxBuilderBody;
5
+ constructor(protocolParams?: Protocol);
6
+ serializeTxBody(txBody: MeshTxBuilderBody, protocolParams?: Protocol): string;
7
+ addSigningKeys(txHex: string, signingKeys: string[]): string;
8
+ serializeData(data: BuilderData): string;
9
+ serializeAddress(address: Partial<DeserializedAddress>, networkId?: number): string;
10
+ deserializer: IDeserializer;
11
+ resolver: IResolver;
12
+ }
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CSLSerializer = void 0;
7
+ /* eslint-disable default-case */
8
+ /* eslint-disable class-methods-use-this */
9
+ /* eslint-disable radix */
10
+ const json_bigint_1 = __importDefault(require("json-bigint"));
11
+ const common_1 = require("@meshsdk/common");
12
+ const deser_1 = require("../deser");
13
+ const utils_1 = require("../utils");
14
+ const adaptor_1 = require("./adaptor");
15
+ const data_1 = require("./adaptor/data");
16
+ class CSLSerializer {
17
+ constructor(protocolParams) {
18
+ this.meshTxBuilderBody = (0, common_1.emptyTxBuilderBody)();
19
+ this.deserializer = {
20
+ key: {
21
+ deserializeAddress: function (bech32) {
22
+ return (0, utils_1.deserializeBech32Address)(bech32);
23
+ },
24
+ },
25
+ script: {
26
+ deserializeNativeScript: function (script) {
27
+ const nativeScript = (0, deser_1.toNativeScript)(script);
28
+ const scriptCbor = nativeScript.to_hex();
29
+ const scriptHash = nativeScript.hash().to_hex();
30
+ return {
31
+ scriptHash,
32
+ scriptCbor,
33
+ };
34
+ },
35
+ deserializePlutusScript: function (script) {
36
+ const scriptHash = (0, deser_1.deserializePlutusScript)(script.code, script.version)
37
+ .hash()
38
+ .to_hex();
39
+ return { scriptHash, scriptCbor: script.code };
40
+ },
41
+ },
42
+ };
43
+ this.resolver = {
44
+ keys: {
45
+ resolveStakeKeyHash: function (bech32) {
46
+ return ((0, utils_1.rewardAddressToKeyHash)(bech32) ||
47
+ (0, utils_1.deserializeBech32Address)(bech32).stakeCredentialHash);
48
+ },
49
+ // resolveStakeScriptHash: function (bech32: string): string {
50
+ // return (
51
+ // rewardAddressToKeyHash(bech32) ||
52
+ // serializeBech32Address(bech32).stakeScriptCredentialHash
53
+ // );
54
+ // },
55
+ resolvePrivateKey: function (words) {
56
+ return (0, deser_1.resolvePrivateKey)(words);
57
+ },
58
+ resolveRewardAddress: function (bech32) {
59
+ return (0, deser_1.resolveRewardAddress)(bech32);
60
+ },
61
+ resolveEd25519KeyHash: function (bech32) {
62
+ return (0, deser_1.resolveEd25519KeyHash)(bech32);
63
+ },
64
+ },
65
+ tx: {
66
+ resolveTxHash: function (txHex) {
67
+ return (0, utils_1.calculateTxHash)(txHex);
68
+ },
69
+ },
70
+ data: {
71
+ resolveDataHash: function (data) {
72
+ return (0, deser_1.resolveDataHash)(data);
73
+ },
74
+ },
75
+ script: {
76
+ resolveScriptRef: function (script) {
77
+ return (0, deser_1.resolveScriptRef)(script);
78
+ },
79
+ },
80
+ pool: {
81
+ resolvePoolId: function (hash) {
82
+ return (0, deser_1.resolvePoolId)(hash);
83
+ },
84
+ },
85
+ };
86
+ this.protocolParams = protocolParams || common_1.DEFAULT_PROTOCOL_PARAMETERS;
87
+ }
88
+ serializeTxBody(txBody, protocolParams) {
89
+ const txBodyJson = json_bigint_1.default.stringify((0, adaptor_1.meshTxBuilderBodyToObj)(txBody));
90
+ const params = json_bigint_1.default.stringify(protocolParams || this.protocolParams);
91
+ console.log("txBodyJson", txBodyJson);
92
+ const txBuildResult = deser_1.csl.js_serialize_tx_body(txBodyJson, params);
93
+ if (txBuildResult.get_status() !== "success") {
94
+ throw new Error(txBuildResult.get_data());
95
+ }
96
+ return txBuildResult.get_data();
97
+ }
98
+ addSigningKeys(txHex, signingKeys) {
99
+ if (signingKeys.length > 0) {
100
+ return (0, utils_1.signTransaction)(txHex, signingKeys);
101
+ }
102
+ return txHex;
103
+ }
104
+ serializeData(data) {
105
+ return (0, data_1.builderDataToCbor)(data);
106
+ }
107
+ serializeAddress(address, networkId) {
108
+ return (0, utils_1.serialzeAddress)(address, networkId);
109
+ }
110
+ }
111
+ exports.CSLSerializer = CSLSerializer;
@@ -0,0 +1,13 @@
1
+ import { csl } from "./csl";
2
+ export declare const LANGUAGE_VERSIONS: {
3
+ V1: csl.Language;
4
+ V2: csl.Language;
5
+ V3: csl.Language;
6
+ };
7
+ export declare const REDEEMER_TAGS: {
8
+ CERT: csl.RedeemerTag;
9
+ MINT: csl.RedeemerTag;
10
+ REWARD: csl.RedeemerTag;
11
+ SPEND: csl.RedeemerTag;
12
+ };
13
+ export declare const POLICY_ID_LENGTH = 56;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.POLICY_ID_LENGTH = exports.REDEEMER_TAGS = exports.LANGUAGE_VERSIONS = void 0;
4
+ const csl_1 = require("./csl");
5
+ exports.LANGUAGE_VERSIONS = {
6
+ V1: csl_1.csl.Language.new_plutus_v1(),
7
+ V2: csl_1.csl.Language.new_plutus_v2(),
8
+ V3: csl_1.csl.Language.new_plutus_v3(),
9
+ };
10
+ exports.REDEEMER_TAGS = {
11
+ CERT: csl_1.csl.RedeemerTag.new_cert(),
12
+ MINT: csl_1.csl.RedeemerTag.new_mint(),
13
+ REWARD: csl_1.csl.RedeemerTag.new_reward(),
14
+ SPEND: csl_1.csl.RedeemerTag.new_spend(),
15
+ };
16
+ exports.POLICY_ID_LENGTH = 56;
@@ -0,0 +1,17 @@
1
+ import type { BuilderData, Data, NativeScript, PlutusScript } from "@meshsdk/common";
2
+ import { csl } from "./csl";
3
+ export declare const toAddress: (bech32: string) => csl.Address;
4
+ export declare const toBaseAddress: (bech32: string) => csl.BaseAddress | undefined;
5
+ export declare const toEnterpriseAddress: (bech32: string) => csl.EnterpriseAddress | undefined;
6
+ export declare const toRewardAddress: (bech32: string) => csl.RewardAddress | undefined;
7
+ export declare const fromBytes: (bytes: Uint8Array) => string;
8
+ export declare const toBytes: (hex: string) => Uint8Array;
9
+ export declare const fromUTF8: (utf8: string) => string;
10
+ export declare const toUTF8: (hex: string) => string;
11
+ export declare const fromLovelace: (lovelace: number) => number;
12
+ export declare const toLovelace: (ada: number) => number;
13
+ export declare const toScriptRef: (script: PlutusScript | NativeScript) => csl.ScriptRef;
14
+ export declare const toPlutusData: (data: Data) => csl.PlutusData;
15
+ export declare const castRawDataToJsonString: (rawData: object | string) => string;
16
+ export declare const castDataToPlutusData: ({ type, content, }: BuilderData) => csl.PlutusData;
17
+ export declare const toNativeScript: (script: NativeScript) => csl.NativeScript;