Skip to content

Commit 52ec13e

Browse files
committedOct 7, 2024
Update docs
1 parent 65bc2c4 commit 52ec13e

File tree

2 files changed

+84
-1
lines changed

2 files changed

+84
-1
lines changed
 

‎README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
Cardano Data Lite (CDL) aims to be a drop in replacement for Cardano Serialization Library (CSL).
44
CDL is written in Typescript and compiled to Javascript with minimal dependencies. There are no WASM blobs resulting in much smaller bundle size. CDL is also easier to integrate with various bundlers which lack the ability to load WASM, like ESBuild where top-level await is not available.
55

6+
## Documentation
7+
8+
[See here](docs.md)
9+
610
# Development
711

812
Due to the size of CSL and also the fact that CSL was undergoing constant updates while we were developing CDL, we designed a small DSL to describe the behaviour of CSL types and used that to dynamically generate a Typescript port of CSL.
@@ -12,7 +16,7 @@ The DSL can be found at `/conway-cddl/yaml` and the code that interprets it can
1216

1317
To measure the progress of implementation, we use automated test suite that parses the type definitions of both CSL and CDL and compares them for compatibility.
1418

15-
To run these, run:
19+
To run these, run the following from the project root directory:
1620

1721
```
1822
npm run test-api

‎docs.md

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
### Documentation
2+
3+
Cardano Data Lite aims to be as API compatible with Cardano Serialization Library as possible.
4+
5+
So the original documentation for CSL can be used as-is:
6+
https://developers.cardano.org/docs/get-started/cardano-serialization-lib/overview/
7+
8+
There are some rare cases where we had to differ from CSL API. Documentation for those parts and the motivation for the differences are noted below.
9+
10+
## Changes from from CSL
11+
12+
The following sections outline key differences in the API between the Cardano Data Lite (CDL) and the Cardano Serialization Library (CSL).
13+
14+
### `Certificate.Kind`:
15+
16+
CSL crams the `RegCert` and `StakeRegistration` functionalities into a single class `StakeRegistration`.
17+
Same for `UnregCert` and `StakeDeregistration`.
18+
The API to construct the `Certificate` type still has separate constructor for
19+
these, so users who construct, deconstruct and otherwise interact with the
20+
`Certificate` type is unaffected.
21+
But users who inspect the value of `Certificate.kind()` will see that CSL doesn't have an entry for the `RegCert` or `UnregCert` variant, while CDL does.
22+
23+
We decided to do it this way because they are distinct types in conway.cddl and it's easier to think of them as separate types.
24+
25+
Regardless, we are API compatible with CSL except for the `kind()` method.
26+
27+
### `PointerAddress`:
28+
29+
We have removed support for `PointerAddress` because CTL doesn't use them and
30+
generally it's rarely used. We will add this later if needed.
31+
32+
### `PlutusScripts`:
33+
34+
We differ from CSL API where CSL has:
35+
36+
```
37+
TransactionWitnessSet:
38+
- plutus_scripts: PlutusScripts
39+
PlutusScripts: Array of PlutusScript
40+
PlutusScript:
41+
language_version: number
42+
bytes: Uint8Array
43+
```
44+
45+
The issue here is that the following assertion doesn't hold:
46+
47+
```
48+
let plutus_scripts_a = ...;
49+
let plutus_scripts_b = PlutusScripts.from_hex(plutus_scripts.to_hex());
50+
51+
assert(plutus_scripts_a.to_hex() == plutus_scripts_b.to_hex())
52+
```
53+
54+
The `to_hex()` method has no way of encoding language version because the Conway CDDL spec doesn't have a field for encoding language version.
55+
56+
Instead, the Conway CDDL spec has:
57+
58+
```
59+
transaction_witness_set =
60+
{ ..
61+
, ? 3: nonempty_set<plutus_v1_script>
62+
, ? 6: nonempty_set<plutus_v2_script>
63+
, ? 7: nonempty_set<plutus_v3_script>
64+
}
65+
```
66+
67+
A script is considered v1 or v2 depending on which field it's put in.
68+
69+
We adapted the API to more closely follow the Conway CDDL spec.
70+
71+
```
72+
TransactionWitnessSet:
73+
- plutus_script_v1: PlutusScripts
74+
- plutus_script_v2: PlutusScripts
75+
- plutus_script_v3: PlutusScripts
76+
PlutusScripts: Array of Uint8Array
77+
```
78+
79+
Here the previous assertion holds. We uphold the contract that `Foo.from_hex(foo.to_hex())` and `Foo.from_bytes(foo.to_bytes())` are identical to `foo`.

0 commit comments

Comments
 (0)
Please sign in to comment.