|
| 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