|
1 | 1 | ---
|
2 | 2 | CIP: 29
|
3 | 3 | Title: Phase-1 Monetary Scripts Serialization Formats
|
4 |
| -Authors: Matthias Benkort <[email protected]> |
5 |
| -Comments-URI: https://github.com/cardano-foundation/CIPs/pulls/117 |
6 | 4 | Status: Active
|
7 |
| -Type: Standards |
| 5 | +Category: Tools |
| 6 | +Authors: |
| 7 | + - Matthias Benkort <[email protected]> |
| 8 | +Implementors: |
| 9 | + - IOG |
| 10 | +Discussions: |
| 11 | + - https://github.com/cardano-foundation/CIPs/pull/117 |
8 | 12 | Created: 2020-08-17
|
9 | 13 | License: CC-BY-4.0
|
10 | 14 | ---
|
11 | 15 |
|
12 |
| -# Abstract |
| 16 | +## Abstract |
13 | 17 |
|
14 |
| -This specification describes how to serialize Phase-1 monetary scripts (a.k.a. _"native scripts"_) to various formats (JSON, CBOR) to facilitate inter-operability between applications. |
| 18 | +This specification describes how to serialize Phase-1 monetary scripts (a.k.a. _"native scripts"_) to various formats (JSON, CBOR) to facilitate inter-operability between applications. |
15 | 19 |
|
16 |
| -# Motivation |
| 20 | +## Motivation: why is this CIP necessary? |
17 | 21 |
|
18 | 22 | While the existence of scripts is well-known, and have an unambiguous on-chain representation. There's no agreed upon format for off-chain or higher-level interfaces for which a binary string is a poor fit. This CIP regroups both the on-chain binary format and other, more verbose, formats like JSON.
|
19 | 23 |
|
20 |
| -# Specification |
| 24 | +## Specification |
21 | 25 |
|
22 |
| -This specification covers at present two serialization formats: JSON and CBOR. The CBOR matches exactly the on-chain representation and is extracted from the cardano-ledger-specs source code and put here as a convenient place to lookup while the source can change location over time. |
| 26 | +This specification covers at present two serialization formats: JSON and CBOR. The CBOR matches exactly the on-chain representation and is extracted from the cardano-ledger-specs source code and put here as a convenient place to lookup while the source can change location over time. |
23 | 27 |
|
24 |
| -## CBOR |
| 28 | +### CBOR |
25 | 29 |
|
26 |
| -The CBOR serialization format is given as a [CDDL specification in annexe](./phase-1-monetary-scripts.cddl). When a hash of the phase-1 monetary script is needed, it usually refers to a Blake2b-192 digest of the corresponding serialized script byte-string prefixed with a null byte: `\x00`. |
| 30 | +The CBOR serialization format is given as a [CDDL specification in annexe](./phase-1-monetary-scripts.cddl). When a hash of the phase-1 monetary script is needed, it usually refers to a Blake2b-192 digest of the corresponding serialized script byte-string prefixed with a null byte: `\x00`. |
27 | 31 |
|
28 |
| -## JSON |
| 32 | +### JSON |
29 | 33 |
|
30 |
| -The JSON format is given as a [JSON schema in annexe](./phase-1-monetary-scripts.json). It is preferred in user interfaces such as command-lines or APIs, where some level of human inspection may be required. |
| 34 | +The JSON format is given as a [JSON schema in annexe](./phase-1-monetary-scripts.json). It is preferred in user interfaces such as command-lines or APIs, where some level of human inspection may be required. |
31 | 35 |
|
32 |
| -## Notes |
| 36 | +### Notes |
33 | 37 |
|
34 | 38 | - Scripts may contain unbounded integers! Implementation parsing them, either from CBOR or JSON shall be prepared to handle possible big integers (>= 2^64).
|
35 | 39 |
|
36 |
| -# Rationale |
37 |
| - |
38 |
| -- The preimage for computing script hashes is prefixed with `\x00` to distinguish them from phase-2 monetary scripts (a.k.a Plutus Script) which are then prefixed with `\x01`. This is merely a discriminator tag. |
39 |
| - |
40 |
| -- The current JSON format is based off the cardano-cli's format which has been used widely for minting tokens and is likely the most widely accepted format at the moment. |
41 |
| - |
42 |
| -# Backward Compatibility |
43 |
| - |
44 |
| -N/A |
45 |
| - |
46 |
| -# Reference Implementation(s) |
47 |
| - |
48 |
| -- [cardano-cli](https://github.com/input-output-hk/cardano-node/tree/master/cardano-cli) & [cardano-api](https://github.com/input-output-hk/cardano-node/tree/master/cardano-api) |
49 |
| - |
50 |
| -## Test Vectors |
| 40 | +### Test Vectors |
51 | 41 |
|
52 | 42 | ```yaml
|
53 | 43 | - json:
|
54 | 44 | { "type": "sig"
|
55 | 45 | , "keyHash": "00000000000000000000000000000000000000000000000000000000"
|
56 | 46 | }
|
57 |
| - cbor: |
| 47 | + cbor: |
58 | 48 | "8200581c00000000000000000000000000000000000000000000000000000000"
|
59 | 49 |
|
60 | 50 | - json:
|
|
64 | 54 | , "keyHash": "00000000000000000000000000000000000000000000000000000000"
|
65 | 55 | }
|
66 | 56 | , { "type": "any"
|
67 |
| - , "scripts": |
| 57 | + , "scripts": |
68 | 58 | [ { "type": "after"
|
69 | 59 | , "slot": 42
|
70 | 60 | }
|
|
82 | 72 | { "type": "before"
|
83 | 73 | , "slot": 42
|
84 | 74 | }
|
85 |
| - cbor: |
| 75 | + cbor: |
86 | 76 | "8205182a"
|
87 | 77 |
|
88 | 78 | - json:
|
|
98 | 88 | "00830302838200581c000000000000000000000000000000000000000000000000000000008200581c000000000000000000000000000000000000000000000000000000018200581c00000000000000000000000000000000000000000000000000000002"
|
99 | 89 | ```
|
100 | 90 |
|
101 |
| -# Copyright |
| 91 | +## Rationale: how does this CIP achieve its goals? |
| 92 | +
|
| 93 | +- The preimage for computing script hashes is prefixed with `\x00` to distinguish them from phase-2 monetary scripts (a.k.a Plutus Script) which are then prefixed with `\x01`. This is merely a discriminator tag. |
| 94 | + |
| 95 | +- The current JSON format is based off the cardano-cli's format which has been used widely for minting tokens and is likely the most widely accepted format at the moment. |
| 96 | + |
| 97 | +## Path to Active |
| 98 | + |
| 99 | +### Acceptance Criteria |
| 100 | + |
| 101 | +- [x] There exist official software releases supporting this serialization format: |
| 102 | + - [x] [cardano-cli](https://github.com/IntersectMBO/cardano-cli) |
| 103 | + - [x] [cardano-api](https://github.com/IntersectMBO/cardano-api) |
| 104 | + |
| 105 | +### Implementation Plan |
| 106 | + |
| 107 | + - [x] Incorporating this serialization format into Cardano software libraries and command line tools. |
| 108 | + |
| 109 | +## Copyright |
102 | 110 |
|
103 |
| -CC-BY-4.0 |
| 111 | +This CIP is licensed under [CC-BY-4.0](https://creativecommons.org/licenses/by/4.0/legalcode). |
0 commit comments