@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
@@ -0,0 +1,23 @@
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("./address"), exports);
18
+ __exportStar(require("./datum"), exports);
19
+ __exportStar(require("./scripts"), exports);
20
+ __exportStar(require("./credentials"), exports);
21
+ __exportStar(require("./staking"), exports);
22
+ __exportStar(require("./transaction"), exports);
23
+ __exportStar(require("./aiken"), exports);
@@ -0,0 +1 @@
1
+ export declare const getV2ScriptHash: (script: string) => string;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getV2ScriptHash = void 0;
4
+ const deser_1 = require("../deser");
5
+ const getV2ScriptHash = (script) => deser_1.csl.get_v2_script_hash(script);
6
+ exports.getV2ScriptHash = getV2ScriptHash;
@@ -0,0 +1,4 @@
1
+ export declare const poolIdHexToBech32: (poolIdHash: string) => string;
2
+ export declare const poolIdBech32ToHex: (poolIdBech32: string) => string;
3
+ export declare const baseAddressToStakeAddress: (baseAddressBech32: string, network?: number) => string;
4
+ export declare const rewardAddressToKeyHash: (rewardBech32: string) => string | undefined;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rewardAddressToKeyHash = exports.baseAddressToStakeAddress = exports.poolIdBech32ToHex = exports.poolIdHexToBech32 = void 0;
4
+ const deser_1 = require("../deser");
5
+ const poolIdHexToBech32 = (poolIdHash) => {
6
+ const cslPoolIdHash = deser_1.csl.Ed25519KeyHash.from_hex(poolIdHash);
7
+ return cslPoolIdHash.to_bech32("pool");
8
+ };
9
+ exports.poolIdHexToBech32 = poolIdHexToBech32;
10
+ const poolIdBech32ToHex = (poolIdBech32) => {
11
+ const cslPoolIdHash = deser_1.csl.Ed25519KeyHash.from_bech32(poolIdBech32);
12
+ return Buffer.from(cslPoolIdHash.to_bytes()).toString("hex");
13
+ };
14
+ exports.poolIdBech32ToHex = poolIdBech32ToHex;
15
+ const baseAddressToStakeAddress = (baseAddressBech32, network = 1) => {
16
+ var _a;
17
+ const networkId = network === 1
18
+ ? deser_1.csl.NetworkId.mainnet().kind()
19
+ : deser_1.csl.NetworkId.testnet().kind();
20
+ const stakeCred = (_a = deser_1.csl.BaseAddress.from_address(deser_1.csl.Address.from_bech32(baseAddressBech32))) === null || _a === void 0 ? void 0 : _a.stake_cred();
21
+ if (stakeCred) {
22
+ const stakeAddress = deser_1.csl.RewardAddress.new(networkId, stakeCred)
23
+ .to_address()
24
+ .to_bech32();
25
+ return stakeAddress;
26
+ }
27
+ return "";
28
+ };
29
+ exports.baseAddressToStakeAddress = baseAddressToStakeAddress;
30
+ const rewardAddressToKeyHash = (rewardBech32) => {
31
+ var _a, _b;
32
+ return (_b = (_a = (0, deser_1.toRewardAddress)(rewardBech32)) === null || _a === void 0 ? void 0 : _a.payment_cred().to_keyhash()) === null || _b === void 0 ? void 0 : _b.to_hex();
33
+ };
34
+ exports.rewardAddressToKeyHash = rewardAddressToKeyHash;
@@ -0,0 +1,2 @@
1
+ export declare const calculateTxHash: (txHex: string) => string;
2
+ export declare const signTransaction: (txHex: string, signingKeys: string[]) => string;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.signTransaction = exports.calculateTxHash = void 0;
4
+ const deser_1 = require("../deser");
5
+ const calculateTxHash = (txHex) => deser_1.csl.calculate_tx_hash(txHex);
6
+ exports.calculateTxHash = calculateTxHash;
7
+ const signTransaction = (txHex, signingKeys) => {
8
+ const cslSigningKeys = deser_1.csl.JsVecString.new();
9
+ signingKeys.forEach((key) => {
10
+ cslSigningKeys.add(key);
11
+ });
12
+ const signedTx = deser_1.csl.sign_transaction(txHex, cslSigningKeys);
13
+ return signedTx;
14
+ };
15
+ exports.signTransaction = signTransaction;
@@ -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,16 @@
1
+ import { csl, toPlutusData } from "../../deser";
2
+ export const builderDataToCbor = ({ type, content }) => {
3
+ if (type === "Mesh") {
4
+ return toPlutusData(content).to_hex();
5
+ }
6
+ if (type === "CBOR") {
7
+ return csl.PlutusData.from_hex(content).to_hex();
8
+ }
9
+ return csl.PlutusData.from_json(content, csl.PlutusDatumSchema.DetailedSchema).to_hex();
10
+ };
11
+ export const redeemerToObj = (redeemer) => {
12
+ return {
13
+ data: builderDataToCbor(redeemer.data),
14
+ exUnits: redeemer.exUnits,
15
+ };
16
+ };
@@ -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,21 @@
1
+ import { certificateToObj, validityRangeToObj, } from "@meshsdk/common";
2
+ import { mintItemToObj } from "./mint";
3
+ import { outputToObj } from "./output";
4
+ import { collateralTxInToObj, txInToObj } from "./txIn";
5
+ import { withdrawalToObj } from "./withdrawal";
6
+ export const meshTxBuilderBodyToObj = ({ inputs, outputs, collaterals, requiredSignatures, referenceInputs, mints, changeAddress, metadata, validityRange, certificates, signingKey, withdrawals, }) => {
7
+ return {
8
+ inputs: inputs.map(txInToObj),
9
+ outputs: outputs.map(outputToObj),
10
+ collaterals: collaterals.map(collateralTxInToObj),
11
+ requiredSignatures,
12
+ referenceInputs: referenceInputs,
13
+ mints: mints.map((mint) => mintItemToObj(mint)),
14
+ changeAddress,
15
+ metadata: metadata,
16
+ validityRange: validityRangeToObj(validityRange),
17
+ certificates: certificates.map(certificateToObj),
18
+ signingKey: signingKey,
19
+ withdrawals: withdrawals.map(withdrawalToObj),
20
+ };
21
+ };
@@ -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,35 @@
1
+ import { redeemerToObj } from "./data";
2
+ import { scriptSourceToObj, simpleScriptSourceToObj } from "./script";
3
+ export const mintItemToObj = (mintItem) => {
4
+ switch (mintItem.type) {
5
+ case "Plutus":
6
+ return {
7
+ scriptMint: plutusMintItemToObj(mintItem),
8
+ };
9
+ case "Native":
10
+ return {
11
+ simpleScriptMint: nativeMintItemToObj(mintItem),
12
+ };
13
+ }
14
+ };
15
+ export const plutusMintItemToObj = (mintItem) => {
16
+ let scriptSource = scriptSourceToObj(mintItem.scriptSource);
17
+ return {
18
+ mint: mintParametersObj(mintItem),
19
+ redeemer: mintItem.redeemer ? redeemerToObj(mintItem.redeemer) : null,
20
+ scriptSource,
21
+ };
22
+ };
23
+ export const nativeMintItemToObj = (mintItem) => {
24
+ return {
25
+ mint: mintParametersObj(mintItem),
26
+ scriptSource: simpleScriptSourceToObj(mintItem.scriptSource),
27
+ };
28
+ };
29
+ export const mintParametersObj = (mintItem) => {
30
+ return {
31
+ policyId: mintItem.policyId,
32
+ assetName: mintItem.assetName,
33
+ amount: BigInt(mintItem.amount),
34
+ };
35
+ };
@@ -0,0 +1,2 @@
1
+ import { Output } from "@meshsdk/common";
2
+ export declare const outputToObj: (output: Output) => object;
@@ -0,0 +1,29 @@
1
+ import { builderDataToCbor } from "./data";
2
+ export const outputToObj = (output) => {
3
+ let datum = null;
4
+ if (output.datum) {
5
+ switch (output.datum.type) {
6
+ case "Inline":
7
+ datum = { inline: builderDataToCbor(output.datum.data) };
8
+ break;
9
+ case "Hash":
10
+ datum = { hash: builderDataToCbor(output.datum.data) };
11
+ break;
12
+ }
13
+ }
14
+ // TODO: add native script
15
+ const refScript = output.referenceScript;
16
+ return {
17
+ address: output.address,
18
+ amount: output.amount,
19
+ datum,
20
+ referenceScript: output.referenceScript
21
+ ? {
22
+ providedScriptSource: {
23
+ scriptCbor: refScript.code,
24
+ languageVersion: refScript.version.toLocaleLowerCase(),
25
+ },
26
+ }
27
+ : null,
28
+ };
29
+ };
@@ -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,39 @@
1
+ export const scriptSourceToObj = (scriptSource) => {
2
+ if (scriptSource.type === "Provided") {
3
+ return {
4
+ providedScriptSource: {
5
+ scriptCbor: scriptSource.script.code,
6
+ languageVersion: scriptSource.script.version.toLocaleLowerCase(),
7
+ },
8
+ };
9
+ }
10
+ return {
11
+ inlineScriptSource: {
12
+ refTxIn: {
13
+ txHash: scriptSource.txHash,
14
+ txIndex: scriptSource.txIndex,
15
+ },
16
+ spendingScriptHash: scriptSource.scriptHash ?? "",
17
+ languageVersion: scriptSource.version.toLocaleLowerCase(),
18
+ scriptSize: BigInt(scriptSource.scriptSize ?? "0"),
19
+ },
20
+ };
21
+ };
22
+ export const simpleScriptSourceToObj = (scriptSource) => {
23
+ if (scriptSource.type === "Provided") {
24
+ return {
25
+ providedSimpleScriptSource: {
26
+ scriptCbor: scriptSource.scriptCode,
27
+ },
28
+ };
29
+ }
30
+ return {
31
+ inlineSimpleScriptSource: {
32
+ refTxIn: {
33
+ txHash: scriptSource.txHash,
34
+ txIndex: scriptSource.txIndex,
35
+ },
36
+ simpleScriptHash: scriptSource.simpleScriptHash ?? "",
37
+ },
38
+ };
39
+ };
@@ -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,68 @@
1
+ import { builderDataToCbor, redeemerToObj } from "./data";
2
+ import { scriptSourceToObj } from "./script";
3
+ export const txInToObj = (txIn) => {
4
+ switch (txIn.type) {
5
+ case "PubKey":
6
+ return {
7
+ pubKeyTxIn: {
8
+ txIn: txInParameterToObj(txIn.txIn),
9
+ },
10
+ };
11
+ case "Script":
12
+ return {
13
+ scriptTxIn: {
14
+ txIn: txInParameterToObj(txIn.txIn),
15
+ scriptTxIn: scriptTxInParameterToObj(txIn.scriptTxIn),
16
+ },
17
+ };
18
+ case "SimpleScript":
19
+ // Not implemented
20
+ return {};
21
+ }
22
+ };
23
+ export const collateralTxInToObj = (txIn) => {
24
+ return {
25
+ txIn: txInParameterToObj(txIn.txIn),
26
+ };
27
+ };
28
+ export const txInParameterToObj = (txInParameter) => {
29
+ return {
30
+ txHash: txInParameter.txHash,
31
+ txIndex: txInParameter.txIndex,
32
+ amount: txInParameter.amount ?? null,
33
+ address: txInParameter.address ?? null,
34
+ };
35
+ };
36
+ export const scriptTxInParameterToObj = (scriptTxInParameter) => {
37
+ let scriptSource = null;
38
+ let datumSource = null;
39
+ if (scriptTxInParameter.scriptSource) {
40
+ scriptSource = scriptSourceToObj(scriptTxInParameter.scriptSource);
41
+ }
42
+ if (scriptTxInParameter.datumSource) {
43
+ switch (scriptTxInParameter.datumSource.type) {
44
+ case "Provided":
45
+ datumSource = {
46
+ providedDatumSource: {
47
+ data: builderDataToCbor(scriptTxInParameter.datumSource.data),
48
+ },
49
+ };
50
+ break;
51
+ case "Inline":
52
+ datumSource = {
53
+ inlineDatumSource: {
54
+ txHash: scriptTxInParameter.datumSource.txHash,
55
+ txIndex: scriptTxInParameter.datumSource.txIndex,
56
+ },
57
+ };
58
+ break;
59
+ }
60
+ }
61
+ return {
62
+ scriptSource,
63
+ datumSource,
64
+ redeemer: scriptTxInParameter.redeemer
65
+ ? redeemerToObj(scriptTxInParameter.redeemer)
66
+ : null,
67
+ };
68
+ };
@@ -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,16 @@
1
+ export const utxoToObj = ({ input: { outputIndex, txHash }, output: { address, amount, dataHash, plutusData, scriptRef, scriptHash }, }) => {
2
+ return {
3
+ input: {
4
+ outputIndex,
5
+ txHash,
6
+ },
7
+ output: {
8
+ address,
9
+ amount,
10
+ dataHash: dataHash ?? null,
11
+ plutusData: plutusData ?? null,
12
+ scriptRef: scriptRef ?? null,
13
+ scriptHash: scriptHash ?? null,
14
+ },
15
+ };
16
+ };
@@ -0,0 +1,2 @@
1
+ import { Withdrawal } from "@meshsdk/common";
2
+ export declare const withdrawalToObj: (withdrawal: Withdrawal) => object;
@@ -0,0 +1,26 @@
1
+ import { redeemerToObj } from "./data";
2
+ import { scriptSourceToObj } from "./script";
3
+ export const withdrawalToObj = (withdrawal) => {
4
+ if ("pubKeyWithdrawal" in withdrawal) {
5
+ return {
6
+ pubKeyWithdrawal: {
7
+ address: withdrawal.pubKeyWithdrawal.address,
8
+ coin: BigInt(withdrawal.pubKeyWithdrawal.coin),
9
+ },
10
+ };
11
+ }
12
+ if (!withdrawal.plutusScriptWithdrawal.scriptSource) {
13
+ throw new Error("withdrawalToObj: missing scriptSource in plutusScriptWithdrawal.");
14
+ }
15
+ if (!withdrawal.plutusScriptWithdrawal.redeemer) {
16
+ throw new Error("withdrawalToObj: missing redeemer in plutusScriptWithdrawal.");
17
+ }
18
+ return {
19
+ plutusScriptWithdrawal: {
20
+ address: withdrawal.plutusScriptWithdrawal.address,
21
+ coin: BigInt(withdrawal.plutusScriptWithdrawal.coin),
22
+ scriptSource: scriptSourceToObj(withdrawal.plutusScriptWithdrawal.scriptSource),
23
+ redeemer: redeemerToObj(withdrawal.plutusScriptWithdrawal.redeemer),
24
+ },
25
+ };
26
+ };
@@ -0,0 +1 @@
1
+ export * from "./serializer";
@@ -0,0 +1 @@
1
+ export * from "./serializer";
@@ -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,105 @@
1
+ /* eslint-disable default-case */
2
+ /* eslint-disable class-methods-use-this */
3
+ /* eslint-disable radix */
4
+ import JSONbig from "json-bigint";
5
+ import { DEFAULT_PROTOCOL_PARAMETERS, emptyTxBuilderBody, } from "@meshsdk/common";
6
+ import { csl, deserializePlutusScript, resolveDataHash, resolveEd25519KeyHash, resolvePoolId, resolvePrivateKey, resolveRewardAddress, resolveScriptRef, toNativeScript, } from "../deser";
7
+ import { calculateTxHash, deserializeBech32Address, rewardAddressToKeyHash, serialzeAddress, signTransaction, } from "../utils";
8
+ import { meshTxBuilderBodyToObj } from "./adaptor";
9
+ import { builderDataToCbor } from "./adaptor/data";
10
+ export class CSLSerializer {
11
+ protocolParams;
12
+ meshTxBuilderBody = emptyTxBuilderBody();
13
+ constructor(protocolParams) {
14
+ this.protocolParams = protocolParams || DEFAULT_PROTOCOL_PARAMETERS;
15
+ }
16
+ serializeTxBody(txBody, protocolParams) {
17
+ const txBodyJson = JSONbig.stringify(meshTxBuilderBodyToObj(txBody));
18
+ const params = JSONbig.stringify(protocolParams || this.protocolParams);
19
+ console.log("txBodyJson", txBodyJson);
20
+ const txBuildResult = csl.js_serialize_tx_body(txBodyJson, params);
21
+ if (txBuildResult.get_status() !== "success") {
22
+ throw new Error(txBuildResult.get_data());
23
+ }
24
+ return txBuildResult.get_data();
25
+ }
26
+ addSigningKeys(txHex, signingKeys) {
27
+ if (signingKeys.length > 0) {
28
+ return signTransaction(txHex, signingKeys);
29
+ }
30
+ return txHex;
31
+ }
32
+ serializeData(data) {
33
+ return builderDataToCbor(data);
34
+ }
35
+ serializeAddress(address, networkId) {
36
+ return serialzeAddress(address, networkId);
37
+ }
38
+ deserializer = {
39
+ key: {
40
+ deserializeAddress: function (bech32) {
41
+ return deserializeBech32Address(bech32);
42
+ },
43
+ },
44
+ script: {
45
+ deserializeNativeScript: function (script) {
46
+ const nativeScript = toNativeScript(script);
47
+ const scriptCbor = nativeScript.to_hex();
48
+ const scriptHash = nativeScript.hash().to_hex();
49
+ return {
50
+ scriptHash,
51
+ scriptCbor,
52
+ };
53
+ },
54
+ deserializePlutusScript: function (script) {
55
+ const scriptHash = deserializePlutusScript(script.code, script.version)
56
+ .hash()
57
+ .to_hex();
58
+ return { scriptHash, scriptCbor: script.code };
59
+ },
60
+ },
61
+ };
62
+ resolver = {
63
+ keys: {
64
+ resolveStakeKeyHash: function (bech32) {
65
+ return (rewardAddressToKeyHash(bech32) ||
66
+ deserializeBech32Address(bech32).stakeCredentialHash);
67
+ },
68
+ // resolveStakeScriptHash: function (bech32: string): string {
69
+ // return (
70
+ // rewardAddressToKeyHash(bech32) ||
71
+ // serializeBech32Address(bech32).stakeScriptCredentialHash
72
+ // );
73
+ // },
74
+ resolvePrivateKey: function (words) {
75
+ return resolvePrivateKey(words);
76
+ },
77
+ resolveRewardAddress: function (bech32) {
78
+ return resolveRewardAddress(bech32);
79
+ },
80
+ resolveEd25519KeyHash: function (bech32) {
81
+ return resolveEd25519KeyHash(bech32);
82
+ },
83
+ },
84
+ tx: {
85
+ resolveTxHash: function (txHex) {
86
+ return calculateTxHash(txHex);
87
+ },
88
+ },
89
+ data: {
90
+ resolveDataHash: function (data) {
91
+ return resolveDataHash(data);
92
+ },
93
+ },
94
+ script: {
95
+ resolveScriptRef: function (script) {
96
+ return resolveScriptRef(script);
97
+ },
98
+ },
99
+ pool: {
100
+ resolvePoolId: function (hash) {
101
+ return resolvePoolId(hash);
102
+ },
103
+ },
104
+ };
105
+ }
@@ -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,13 @@
1
+ import { csl } from "./csl";
2
+ export const LANGUAGE_VERSIONS = {
3
+ V1: csl.Language.new_plutus_v1(),
4
+ V2: csl.Language.new_plutus_v2(),
5
+ V3: csl.Language.new_plutus_v3(),
6
+ };
7
+ export const REDEEMER_TAGS = {
8
+ CERT: csl.RedeemerTag.new_cert(),
9
+ MINT: csl.RedeemerTag.new_mint(),
10
+ REWARD: csl.RedeemerTag.new_reward(),
11
+ SPEND: csl.RedeemerTag.new_spend(),
12
+ };
13
+ export const 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;