@meshsdk/core-csl 1.6.0-alpha.1 → 1.6.0-alpha.11
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/README.md +3 -7
- package/jest.config.js +5 -0
- package/package.json +40 -51
- package/src/core/adaptor/data.ts +23 -0
- package/src/core/adaptor/index.ts +40 -0
- package/src/core/adaptor/mint.ts +54 -0
- package/src/core/adaptor/output.ts +34 -0
- package/src/core/adaptor/script.ts +52 -0
- package/src/core/adaptor/txIn.ts +81 -0
- package/src/core/adaptor/utxo.ts +21 -0
- package/src/core/adaptor/withdrawal.ts +37 -0
- package/src/core/index.ts +1 -0
- package/src/core/serializer.ts +162 -0
- package/src/deser/constants.ts +16 -0
- package/src/deser/converter.ts +260 -0
- package/src/deser/csl.ts +1 -0
- package/src/deser/deserializer.ts +63 -0
- package/src/deser/index.ts +5 -0
- package/src/deser/resolver.ts +135 -0
- package/src/index.ts +3 -0
- package/src/utils/address.ts +115 -0
- package/src/utils/aiken.ts +62 -0
- package/src/utils/credentials.ts +7 -0
- package/src/utils/datum.ts +17 -0
- package/src/utils/index.ts +7 -0
- package/src/utils/scripts.ts +4 -0
- package/src/utils/staking.ts +35 -0
- package/src/utils/transaction.ts +12 -0
- package/test/core/builder.test.ts +97 -0
- package/test/deser/converter.test.ts.bak +19 -0
- package/test/utils/address.test.ts +74 -0
- package/test/utils/aiken.test.ts +41 -0
- package/test/utils/scripts.test.ts +29 -0
- package/test/utils/transaction.test.ts +18 -0
- package/tsconfig-cjs.json +11 -0
- package/tsconfig.json +18 -0
- package/dist/cjs/core/builder.d.ts +0 -38
- package/dist/cjs/core/builder.js +0 -389
- package/dist/cjs/core/index.d.ts +0 -1
- package/dist/cjs/core/index.js +0 -17
- package/dist/cjs/deser/builder.d.ts +0 -18
- package/dist/cjs/deser/builder.js +0 -130
- package/dist/cjs/deser/constants.d.ts +0 -12
- package/dist/cjs/deser/constants.js +0 -15
- package/dist/cjs/deser/converter.d.ts +0 -27
- package/dist/cjs/deser/converter.js +0 -352
- package/dist/cjs/deser/csl.d.ts +0 -1
- package/dist/cjs/deser/csl.js +0 -27
- package/dist/cjs/deser/deserializer.d.ts +0 -19
- package/dist/cjs/deser/deserializer.js +0 -40
- package/dist/cjs/deser/index.d.ts +0 -6
- package/dist/cjs/deser/index.js +0 -22
- package/dist/cjs/deser/types.d.ts +0 -146
- package/dist/cjs/deser/types.js +0 -2
- package/dist/cjs/index.d.ts +0 -3
- package/dist/cjs/index.js +0 -19
- package/dist/cjs/utils/address.d.ts +0 -12
- package/dist/cjs/utils/address.js +0 -60
- package/dist/cjs/utils/aiken.d.ts +0 -2
- package/dist/cjs/utils/aiken.js +0 -20
- package/dist/cjs/utils/credentials.d.ts +0 -1
- package/dist/cjs/utils/credentials.js +0 -10
- package/dist/cjs/utils/datum.d.ts +0 -4
- package/dist/cjs/utils/datum.js +0 -18
- package/dist/cjs/utils/index.d.ts +0 -7
- package/dist/cjs/utils/index.js +0 -23
- package/dist/cjs/utils/scripts.d.ts +0 -1
- package/dist/cjs/utils/scripts.js +0 -6
- package/dist/cjs/utils/staking.d.ts +0 -3
- package/dist/cjs/utils/staking.js +0 -25
- package/dist/cjs/utils/transaction.d.ts +0 -2
- package/dist/cjs/utils/transaction.js +0 -15
- package/dist/mjs/core/builder.d.ts +0 -38
- package/dist/mjs/core/builder.js +0 -380
- package/dist/mjs/core/index.d.ts +0 -1
- package/dist/mjs/core/index.js +0 -1
- package/dist/mjs/deser/builder.d.ts +0 -18
- package/dist/mjs/deser/builder.js +0 -118
- package/dist/mjs/deser/constants.d.ts +0 -12
- package/dist/mjs/deser/constants.js +0 -12
- package/dist/mjs/deser/converter.d.ts +0 -27
- package/dist/mjs/deser/converter.js +0 -321
- package/dist/mjs/deser/csl.d.ts +0 -1
- package/dist/mjs/deser/csl.js +0 -1
- package/dist/mjs/deser/deserializer.d.ts +0 -19
- package/dist/mjs/deser/deserializer.js +0 -20
- package/dist/mjs/deser/index.d.ts +0 -6
- package/dist/mjs/deser/index.js +0 -6
- package/dist/mjs/deser/types.d.ts +0 -146
- package/dist/mjs/deser/types.js +0 -1
- package/dist/mjs/index.d.ts +0 -3
- package/dist/mjs/index.js +0 -3
- package/dist/mjs/utils/address.d.ts +0 -12
- package/dist/mjs/utils/address.js +0 -50
- package/dist/mjs/utils/aiken.d.ts +0 -2
- package/dist/mjs/utils/aiken.js +0 -15
- package/dist/mjs/utils/credentials.d.ts +0 -1
- package/dist/mjs/utils/credentials.js +0 -6
- package/dist/mjs/utils/datum.d.ts +0 -4
- package/dist/mjs/utils/datum.js +0 -13
- package/dist/mjs/utils/index.d.ts +0 -7
- package/dist/mjs/utils/index.js +0 -7
- package/dist/mjs/utils/scripts.d.ts +0 -1
- package/dist/mjs/utils/scripts.js +0 -2
- package/dist/mjs/utils/staking.d.ts +0 -3
- package/dist/mjs/utils/staking.js +0 -18
- package/dist/mjs/utils/transaction.d.ts +0 -2
- package/dist/mjs/utils/transaction.js +0 -10
package/README.md
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
# mesh-csl
|
|
1
|
+
# mesh-core-csl
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Types and utilities functions between Mesh and [cardano-serialization-lib](https://github.com/Emurgo/cardano-serialization-lib)
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
```sh
|
|
8
|
-
yarn add @meshsdk/mesh-csl
|
|
9
|
-
```
|
|
5
|
+
[meshjs.dev](https://meshjs.dev/)
|
package/jest.config.js
ADDED
package/package.json
CHANGED
|
@@ -1,53 +1,42 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
},
|
|
14
|
-
"homepage": "https://github.com/MeshJS/mesh-core",
|
|
15
|
-
"author": {
|
|
16
|
-
"name": "SIDAN Lab",
|
|
17
|
-
"email": "contact@sidan.io"
|
|
18
|
-
},
|
|
19
|
-
"repository": {
|
|
20
|
-
"type": "git",
|
|
21
|
-
"url": "https://github.com/MeshJS/mesh-core.git"
|
|
22
|
-
},
|
|
23
|
-
"files": [
|
|
24
|
-
"dist"
|
|
25
|
-
],
|
|
26
|
-
"keywords": [
|
|
27
|
-
"blockchain",
|
|
28
|
-
"cardano",
|
|
29
|
-
"plutus",
|
|
30
|
-
"cardano-serialization-lib"
|
|
31
|
-
],
|
|
32
|
-
"scripts": {
|
|
33
|
-
"prepare": "cp ../tsconfig-base.json ./ && cp ../tsconfig-cjs.json ./ && cp ../tsconfig.json ./",
|
|
34
|
-
"build": "rm -fr dist/* && tsc -p ./tsconfig.json && tsc -p ./tsconfig-cjs.json",
|
|
35
|
-
"ci": "yarn && yarn build"
|
|
36
|
-
},
|
|
37
|
-
"browser": {
|
|
38
|
-
"@sidan-lab/sidan-csl-rs-nodejs": "@sidan-lab/sidan-csl-rs-browser"
|
|
39
|
-
},
|
|
40
|
-
"dependencies": {
|
|
41
|
-
"@meshsdk/common": "^1.0.0-alpha.3",
|
|
42
|
-
"@sidan-lab/sidan-csl-rs-browser": "^0.3.6",
|
|
43
|
-
"@sidan-lab/sidan-csl-rs-nodejs": "^0.3.6",
|
|
44
|
-
"blakejs": "^1.2.1",
|
|
45
|
-
"json-bigint": "^1.0.0"
|
|
46
|
-
},
|
|
47
|
-
"devDependencies": {
|
|
48
|
-
"@types/json-bigint": "^1.0.4",
|
|
49
|
-
"@types/node": "^18.16.3",
|
|
50
|
-
"ts-node": "^10.9.2",
|
|
51
|
-
"typescript": "^5.0.4"
|
|
2
|
+
"name": "@meshsdk/core-csl",
|
|
3
|
+
"version": "1.6.0-alpha.11",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/mjs/index.js",
|
|
11
|
+
"require": "./dist/cjs/index.js"
|
|
52
12
|
}
|
|
53
|
-
}
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build:mesh": "rm -fr dist/* && tsc -p ./tsconfig.json && tsc -p ./tsconfig-cjs.json",
|
|
16
|
+
"dev": "tsup src/index.ts --format esm,cjs --watch --dts",
|
|
17
|
+
"lint": "eslint",
|
|
18
|
+
"test": "jest --verbose",
|
|
19
|
+
"clean": "rm -rf .turbo && rm -rf dist && rm -rf node_modules",
|
|
20
|
+
"format": "prettier --check . --ignore-path ../../.gitignore",
|
|
21
|
+
"build:docs": "typedoc src/index.ts --json ../../apps/docs/src/data/mesh-core-csl.json"
|
|
22
|
+
},
|
|
23
|
+
"browser": {
|
|
24
|
+
"@sidan-lab/sidan-csl-rs-nodejs": "@sidan-lab/sidan-csl-rs-browser"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@meshsdk/eslint-config": "*",
|
|
28
|
+
"@meshsdk/typescript-config": "*",
|
|
29
|
+
"@types/json-bigint": "^1.0.4",
|
|
30
|
+
"eslint": "^8.57.0",
|
|
31
|
+
"ts-jest": "^29.1.4",
|
|
32
|
+
"tsup": "^8.0.2",
|
|
33
|
+
"typescript": "^5.3.3"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@meshsdk/common": "*",
|
|
37
|
+
"@sidan-lab/sidan-csl-rs-browser": "^0.6.13",
|
|
38
|
+
"@sidan-lab/sidan-csl-rs-nodejs": "^0.6.13",
|
|
39
|
+
"json-bigint": "^1.0.0"
|
|
40
|
+
},
|
|
41
|
+
"prettier": "@meshsdk/prettier-config"
|
|
42
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BuilderData, Redeemer } from "@meshsdk/common";
|
|
2
|
+
|
|
3
|
+
import { csl, toPlutusData } from "../../deser";
|
|
4
|
+
|
|
5
|
+
export const builderDataToCbor = ({ type, content }: BuilderData): string => {
|
|
6
|
+
if (type === "Mesh") {
|
|
7
|
+
return toPlutusData(content).to_hex();
|
|
8
|
+
}
|
|
9
|
+
if (type === "CBOR") {
|
|
10
|
+
return csl.PlutusData.from_hex(content as string).to_hex();
|
|
11
|
+
}
|
|
12
|
+
return csl.PlutusData.from_json(
|
|
13
|
+
content as string,
|
|
14
|
+
csl.PlutusDatumSchema.DetailedSchema,
|
|
15
|
+
).to_hex();
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const redeemerToObj = (redeemer: Redeemer): object => {
|
|
19
|
+
return {
|
|
20
|
+
data: builderDataToCbor(redeemer.data),
|
|
21
|
+
exUnits: redeemer.exUnits,
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
certificateToObj,
|
|
3
|
+
MeshTxBuilderBody,
|
|
4
|
+
validityRangeToObj,
|
|
5
|
+
} from "@meshsdk/common";
|
|
6
|
+
|
|
7
|
+
import { mintItemToObj } from "./mint";
|
|
8
|
+
import { outputToObj } from "./output";
|
|
9
|
+
import { collateralTxInToObj, txInToObj } from "./txIn";
|
|
10
|
+
import { withdrawalToObj } from "./withdrawal";
|
|
11
|
+
|
|
12
|
+
export const meshTxBuilderBodyToObj = ({
|
|
13
|
+
inputs,
|
|
14
|
+
outputs,
|
|
15
|
+
collaterals,
|
|
16
|
+
requiredSignatures,
|
|
17
|
+
referenceInputs,
|
|
18
|
+
mints,
|
|
19
|
+
changeAddress,
|
|
20
|
+
metadata,
|
|
21
|
+
validityRange,
|
|
22
|
+
certificates,
|
|
23
|
+
signingKey,
|
|
24
|
+
withdrawals,
|
|
25
|
+
}: MeshTxBuilderBody) => {
|
|
26
|
+
return {
|
|
27
|
+
inputs: inputs.map(txInToObj),
|
|
28
|
+
outputs: outputs.map(outputToObj),
|
|
29
|
+
collaterals: collaterals.map(collateralTxInToObj),
|
|
30
|
+
requiredSignatures,
|
|
31
|
+
referenceInputs: referenceInputs,
|
|
32
|
+
mints: mints.map((mint) => mintItemToObj(mint)),
|
|
33
|
+
changeAddress,
|
|
34
|
+
metadata: metadata,
|
|
35
|
+
validityRange: validityRangeToObj(validityRange),
|
|
36
|
+
certificates: certificates.map(certificateToObj),
|
|
37
|
+
signingKey: signingKey,
|
|
38
|
+
withdrawals: withdrawals.map(withdrawalToObj),
|
|
39
|
+
};
|
|
40
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MintItem,
|
|
3
|
+
ScriptSource,
|
|
4
|
+
SimpleScriptSourceInfo,
|
|
5
|
+
} from "@meshsdk/common";
|
|
6
|
+
|
|
7
|
+
import { redeemerToObj } from "./data";
|
|
8
|
+
import { scriptSourceToObj, simpleScriptSourceToObj } from "./script";
|
|
9
|
+
|
|
10
|
+
export const mintItemToObj = (mintItem: MintItem): object => {
|
|
11
|
+
switch (mintItem.type) {
|
|
12
|
+
case "Plutus":
|
|
13
|
+
return {
|
|
14
|
+
scriptMint: plutusMintItemToObj(mintItem as Required<MintItem>),
|
|
15
|
+
};
|
|
16
|
+
case "Native":
|
|
17
|
+
return {
|
|
18
|
+
simpleScriptMint: nativeMintItemToObj(
|
|
19
|
+
mintItem as Omit<Required<MintItem>, "redeemer">,
|
|
20
|
+
),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const plutusMintItemToObj = (mintItem: Required<MintItem>): object => {
|
|
26
|
+
let scriptSource: object = scriptSourceToObj(
|
|
27
|
+
mintItem.scriptSource as ScriptSource,
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
mint: mintParametersObj(mintItem),
|
|
32
|
+
redeemer: mintItem.redeemer ? redeemerToObj(mintItem.redeemer) : null,
|
|
33
|
+
scriptSource,
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const nativeMintItemToObj = (
|
|
38
|
+
mintItem: Omit<Required<MintItem>, "redeemer">,
|
|
39
|
+
): object => {
|
|
40
|
+
return {
|
|
41
|
+
mint: mintParametersObj(mintItem),
|
|
42
|
+
scriptSource: simpleScriptSourceToObj(
|
|
43
|
+
mintItem.scriptSource as SimpleScriptSourceInfo,
|
|
44
|
+
),
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const mintParametersObj = (mintItem: MintItem): object => {
|
|
49
|
+
return {
|
|
50
|
+
policyId: mintItem.policyId,
|
|
51
|
+
assetName: mintItem.assetName,
|
|
52
|
+
amount: BigInt(mintItem.amount),
|
|
53
|
+
};
|
|
54
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Output, PlutusScript } from "@meshsdk/common";
|
|
2
|
+
|
|
3
|
+
import { builderDataToCbor } from "./data";
|
|
4
|
+
|
|
5
|
+
export const outputToObj = (output: Output): object => {
|
|
6
|
+
let datum: object | null = null;
|
|
7
|
+
if (output.datum) {
|
|
8
|
+
switch (output.datum.type) {
|
|
9
|
+
case "Inline":
|
|
10
|
+
datum = { inline: builderDataToCbor(output.datum.data) };
|
|
11
|
+
break;
|
|
12
|
+
case "Hash":
|
|
13
|
+
datum = { hash: builderDataToCbor(output.datum.data) };
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// TODO: add native script
|
|
19
|
+
const refScript = output.referenceScript as PlutusScript;
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
address: output.address,
|
|
23
|
+
amount: output.amount,
|
|
24
|
+
datum,
|
|
25
|
+
referenceScript: output.referenceScript
|
|
26
|
+
? {
|
|
27
|
+
providedScriptSource: {
|
|
28
|
+
scriptCbor: refScript.code,
|
|
29
|
+
languageVersion: refScript.version.toLocaleLowerCase(),
|
|
30
|
+
},
|
|
31
|
+
}
|
|
32
|
+
: null,
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PlutusScript,
|
|
3
|
+
ScriptSource,
|
|
4
|
+
SimpleScriptSourceInfo,
|
|
5
|
+
} from "@meshsdk/common";
|
|
6
|
+
|
|
7
|
+
export const scriptSourceToObj = (scriptSource: ScriptSource): object => {
|
|
8
|
+
if (scriptSource.type === "Provided") {
|
|
9
|
+
return {
|
|
10
|
+
providedScriptSource: {
|
|
11
|
+
scriptCbor: scriptSource.script.code,
|
|
12
|
+
languageVersion: (
|
|
13
|
+
scriptSource.script as PlutusScript
|
|
14
|
+
).version!.toLocaleLowerCase(),
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
inlineScriptSource: {
|
|
21
|
+
refTxIn: {
|
|
22
|
+
txHash: scriptSource.txHash,
|
|
23
|
+
txIndex: scriptSource.txIndex,
|
|
24
|
+
},
|
|
25
|
+
spendingScriptHash: scriptSource.scriptHash ?? "",
|
|
26
|
+
languageVersion: scriptSource.version!.toLocaleLowerCase(),
|
|
27
|
+
scriptSize: BigInt(scriptSource.scriptSize ?? "0"),
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const simpleScriptSourceToObj = (
|
|
33
|
+
scriptSource: SimpleScriptSourceInfo,
|
|
34
|
+
): object => {
|
|
35
|
+
if (scriptSource.type === "Provided") {
|
|
36
|
+
return {
|
|
37
|
+
providedSimpleScriptSource: {
|
|
38
|
+
scriptCbor: scriptSource.scriptCode,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
inlineSimpleScriptSource: {
|
|
45
|
+
refTxIn: {
|
|
46
|
+
txHash: scriptSource.txHash,
|
|
47
|
+
txIndex: scriptSource.txIndex,
|
|
48
|
+
},
|
|
49
|
+
simpleScriptHash: scriptSource.simpleScriptHash ?? "",
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { ScriptTxInParameter, TxIn, TxInParameter } from "@meshsdk/common";
|
|
2
|
+
|
|
3
|
+
import { builderDataToCbor, redeemerToObj } from "./data";
|
|
4
|
+
import { scriptSourceToObj } from "./script";
|
|
5
|
+
|
|
6
|
+
export const txInToObj = (txIn: TxIn): object => {
|
|
7
|
+
switch (txIn.type) {
|
|
8
|
+
case "PubKey":
|
|
9
|
+
return {
|
|
10
|
+
pubKeyTxIn: {
|
|
11
|
+
txIn: txInParameterToObj(txIn.txIn),
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
case "Script":
|
|
16
|
+
return {
|
|
17
|
+
scriptTxIn: {
|
|
18
|
+
txIn: txInParameterToObj(txIn.txIn),
|
|
19
|
+
scriptTxIn: scriptTxInParameterToObj(txIn.scriptTxIn),
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
case "SimpleScript":
|
|
24
|
+
// Not implemented
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const collateralTxInToObj = (txIn: TxIn): object => {
|
|
30
|
+
return {
|
|
31
|
+
txIn: txInParameterToObj(txIn.txIn),
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const txInParameterToObj = (txInParameter: TxInParameter): object => {
|
|
36
|
+
return {
|
|
37
|
+
txHash: txInParameter.txHash,
|
|
38
|
+
txIndex: txInParameter.txIndex,
|
|
39
|
+
amount: txInParameter.amount ?? null,
|
|
40
|
+
address: txInParameter.address ?? null,
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export const scriptTxInParameterToObj = (
|
|
45
|
+
scriptTxInParameter: ScriptTxInParameter,
|
|
46
|
+
): object => {
|
|
47
|
+
let scriptSource: object | null = null;
|
|
48
|
+
let datumSource: object | null = null;
|
|
49
|
+
|
|
50
|
+
if (scriptTxInParameter.scriptSource) {
|
|
51
|
+
scriptSource = scriptSourceToObj(scriptTxInParameter.scriptSource);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (scriptTxInParameter.datumSource) {
|
|
55
|
+
switch (scriptTxInParameter.datumSource.type) {
|
|
56
|
+
case "Provided":
|
|
57
|
+
datumSource = {
|
|
58
|
+
providedDatumSource: {
|
|
59
|
+
data: builderDataToCbor(scriptTxInParameter.datumSource.data),
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
break;
|
|
63
|
+
case "Inline":
|
|
64
|
+
datumSource = {
|
|
65
|
+
inlineDatumSource: {
|
|
66
|
+
txHash: scriptTxInParameter.datumSource.txHash,
|
|
67
|
+
txIndex: scriptTxInParameter.datumSource.txIndex,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
scriptSource,
|
|
76
|
+
datumSource,
|
|
77
|
+
redeemer: scriptTxInParameter.redeemer
|
|
78
|
+
? redeemerToObj(scriptTxInParameter.redeemer)
|
|
79
|
+
: null,
|
|
80
|
+
};
|
|
81
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { UTxO } from "@meshsdk/common";
|
|
2
|
+
|
|
3
|
+
export const utxoToObj = ({
|
|
4
|
+
input: { outputIndex, txHash },
|
|
5
|
+
output: { address, amount, dataHash, plutusData, scriptRef, scriptHash },
|
|
6
|
+
}: UTxO): object => {
|
|
7
|
+
return {
|
|
8
|
+
input: {
|
|
9
|
+
outputIndex,
|
|
10
|
+
txHash,
|
|
11
|
+
},
|
|
12
|
+
output: {
|
|
13
|
+
address,
|
|
14
|
+
amount,
|
|
15
|
+
dataHash: dataHash ?? null,
|
|
16
|
+
plutusData: plutusData ?? null,
|
|
17
|
+
scriptRef: scriptRef ?? null,
|
|
18
|
+
scriptHash: scriptHash ?? null,
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Withdrawal } from "@meshsdk/common";
|
|
2
|
+
|
|
3
|
+
import { redeemerToObj } from "./data";
|
|
4
|
+
import { scriptSourceToObj } from "./script";
|
|
5
|
+
|
|
6
|
+
export const withdrawalToObj = (withdrawal: Withdrawal): object => {
|
|
7
|
+
if ("pubKeyWithdrawal" in withdrawal) {
|
|
8
|
+
return {
|
|
9
|
+
pubKeyWithdrawal: {
|
|
10
|
+
address: withdrawal.pubKeyWithdrawal.address,
|
|
11
|
+
coin: BigInt(withdrawal.pubKeyWithdrawal.coin),
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (!withdrawal.plutusScriptWithdrawal.scriptSource) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
"withdrawalToObj: missing scriptSource in plutusScriptWithdrawal.",
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
if (!withdrawal.plutusScriptWithdrawal.redeemer) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
"withdrawalToObj: missing redeemer in plutusScriptWithdrawal.",
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
plutusScriptWithdrawal: {
|
|
29
|
+
address: withdrawal.plutusScriptWithdrawal.address,
|
|
30
|
+
coin: BigInt(withdrawal.plutusScriptWithdrawal.coin),
|
|
31
|
+
scriptSource: scriptSourceToObj(
|
|
32
|
+
withdrawal.plutusScriptWithdrawal.scriptSource,
|
|
33
|
+
),
|
|
34
|
+
redeemer: redeemerToObj(withdrawal.plutusScriptWithdrawal.redeemer),
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./serializer";
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/* eslint-disable default-case */
|
|
2
|
+
/* eslint-disable class-methods-use-this */
|
|
3
|
+
/* eslint-disable radix */
|
|
4
|
+
import JSONbig from "json-bigint";
|
|
5
|
+
|
|
6
|
+
import type {
|
|
7
|
+
BuilderData,
|
|
8
|
+
Data,
|
|
9
|
+
DeserializedAddress,
|
|
10
|
+
DeserializedScript,
|
|
11
|
+
IDeserializer,
|
|
12
|
+
IMeshTxSerializer,
|
|
13
|
+
IResolver,
|
|
14
|
+
MeshTxBuilderBody,
|
|
15
|
+
NativeScript,
|
|
16
|
+
PlutusScript,
|
|
17
|
+
Protocol,
|
|
18
|
+
} from "@meshsdk/common";
|
|
19
|
+
import {
|
|
20
|
+
DEFAULT_PROTOCOL_PARAMETERS,
|
|
21
|
+
emptyTxBuilderBody,
|
|
22
|
+
} from "@meshsdk/common";
|
|
23
|
+
|
|
24
|
+
import {
|
|
25
|
+
csl,
|
|
26
|
+
deserializePlutusScript,
|
|
27
|
+
resolveDataHash,
|
|
28
|
+
resolveEd25519KeyHash,
|
|
29
|
+
resolvePoolId,
|
|
30
|
+
resolvePrivateKey,
|
|
31
|
+
resolveRewardAddress,
|
|
32
|
+
resolveScriptRef,
|
|
33
|
+
toNativeScript,
|
|
34
|
+
} from "../deser";
|
|
35
|
+
import {
|
|
36
|
+
calculateTxHash,
|
|
37
|
+
deserializeBech32Address,
|
|
38
|
+
rewardAddressToKeyHash,
|
|
39
|
+
serialzeAddress,
|
|
40
|
+
signTransaction,
|
|
41
|
+
} from "../utils";
|
|
42
|
+
import { meshTxBuilderBodyToObj } from "./adaptor";
|
|
43
|
+
import { builderDataToCbor } from "./adaptor/data";
|
|
44
|
+
|
|
45
|
+
export class CSLSerializer implements IMeshTxSerializer {
|
|
46
|
+
protocolParams: Protocol;
|
|
47
|
+
|
|
48
|
+
meshTxBuilderBody: MeshTxBuilderBody = emptyTxBuilderBody();
|
|
49
|
+
|
|
50
|
+
constructor(protocolParams?: Protocol) {
|
|
51
|
+
this.protocolParams = protocolParams || DEFAULT_PROTOCOL_PARAMETERS;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
serializeTxBody(
|
|
55
|
+
txBody: MeshTxBuilderBody,
|
|
56
|
+
protocolParams?: Protocol,
|
|
57
|
+
): string {
|
|
58
|
+
const txBodyJson = JSONbig.stringify(meshTxBuilderBodyToObj(txBody));
|
|
59
|
+
|
|
60
|
+
const params = JSONbig.stringify(protocolParams || this.protocolParams);
|
|
61
|
+
|
|
62
|
+
console.log("txBodyJson", txBodyJson);
|
|
63
|
+
const txBuildResult = csl.js_serialize_tx_body(txBodyJson, params);
|
|
64
|
+
if (txBuildResult.get_status() !== "success") {
|
|
65
|
+
throw new Error(txBuildResult.get_data());
|
|
66
|
+
}
|
|
67
|
+
return txBuildResult.get_data();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
addSigningKeys(txHex: string, signingKeys: string[]): string {
|
|
71
|
+
if (signingKeys.length > 0) {
|
|
72
|
+
return signTransaction(txHex, signingKeys);
|
|
73
|
+
}
|
|
74
|
+
return txHex;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
serializeData(data: BuilderData): string {
|
|
78
|
+
return builderDataToCbor(data);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
serializeAddress(
|
|
82
|
+
address: Partial<DeserializedAddress>,
|
|
83
|
+
networkId?: number,
|
|
84
|
+
): string {
|
|
85
|
+
return serialzeAddress(address, networkId);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
deserializer: IDeserializer = {
|
|
89
|
+
key: {
|
|
90
|
+
deserializeAddress: function (bech32: string): DeserializedAddress {
|
|
91
|
+
return deserializeBech32Address(bech32);
|
|
92
|
+
},
|
|
93
|
+
},
|
|
94
|
+
script: {
|
|
95
|
+
deserializeNativeScript: function (
|
|
96
|
+
script: NativeScript,
|
|
97
|
+
): DeserializedScript {
|
|
98
|
+
const nativeScript = toNativeScript(script);
|
|
99
|
+
const scriptCbor = nativeScript.to_hex();
|
|
100
|
+
const scriptHash = nativeScript.hash().to_hex();
|
|
101
|
+
return {
|
|
102
|
+
scriptHash,
|
|
103
|
+
scriptCbor,
|
|
104
|
+
};
|
|
105
|
+
},
|
|
106
|
+
deserializePlutusScript: function (
|
|
107
|
+
script: PlutusScript,
|
|
108
|
+
): DeserializedScript {
|
|
109
|
+
const scriptHash = deserializePlutusScript(script.code, script.version)
|
|
110
|
+
.hash()
|
|
111
|
+
.to_hex();
|
|
112
|
+
return { scriptHash, scriptCbor: script.code };
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
resolver: IResolver = {
|
|
118
|
+
keys: {
|
|
119
|
+
resolveStakeKeyHash: function (bech32: string): string {
|
|
120
|
+
return (
|
|
121
|
+
rewardAddressToKeyHash(bech32) ||
|
|
122
|
+
deserializeBech32Address(bech32).stakeCredentialHash
|
|
123
|
+
);
|
|
124
|
+
},
|
|
125
|
+
// resolveStakeScriptHash: function (bech32: string): string {
|
|
126
|
+
// return (
|
|
127
|
+
// rewardAddressToKeyHash(bech32) ||
|
|
128
|
+
// serializeBech32Address(bech32).stakeScriptCredentialHash
|
|
129
|
+
// );
|
|
130
|
+
// },
|
|
131
|
+
resolvePrivateKey: function (words: string[]): string {
|
|
132
|
+
return resolvePrivateKey(words);
|
|
133
|
+
},
|
|
134
|
+
resolveRewardAddress: function (bech32: string): string {
|
|
135
|
+
return resolveRewardAddress(bech32);
|
|
136
|
+
},
|
|
137
|
+
resolveEd25519KeyHash: function (bech32: string): string {
|
|
138
|
+
return resolveEd25519KeyHash(bech32);
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
tx: {
|
|
142
|
+
resolveTxHash: function (txHex: string): string {
|
|
143
|
+
return calculateTxHash(txHex);
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
data: {
|
|
147
|
+
resolveDataHash: function (data: Data): string {
|
|
148
|
+
return resolveDataHash(data);
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
script: {
|
|
152
|
+
resolveScriptRef: function (script: PlutusScript | NativeScript): string {
|
|
153
|
+
return resolveScriptRef(script);
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
pool: {
|
|
157
|
+
resolvePoolId: function (hash: string): string {
|
|
158
|
+
return resolvePoolId(hash);
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { csl } from "./csl";
|
|
2
|
+
|
|
3
|
+
export const LANGUAGE_VERSIONS = {
|
|
4
|
+
V1: csl.Language.new_plutus_v1(),
|
|
5
|
+
V2: csl.Language.new_plutus_v2(),
|
|
6
|
+
V3: csl.Language.new_plutus_v3(),
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const REDEEMER_TAGS = {
|
|
10
|
+
CERT: csl.RedeemerTag.new_cert(),
|
|
11
|
+
MINT: csl.RedeemerTag.new_mint(),
|
|
12
|
+
REWARD: csl.RedeemerTag.new_reward(),
|
|
13
|
+
SPEND: csl.RedeemerTag.new_spend(),
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const POLICY_ID_LENGTH = 56;
|