|
| 1 | +--- |
| 2 | +CIP: /? |
| 3 | +Title: CBOR Tag definition for CIP-0003 ED25519-BIP32 Keys |
| 4 | +Category: MetaData |
| 5 | +Status: Proposed |
| 6 | +Authors: |
| 7 | + - Steven Johnson<[email protected]> |
| 8 | +Implementors: [] |
| 9 | +Discussions: |
| 10 | + - https://github.com/cardano-foundation/cips/pulls/? |
| 11 | +Created: 2024-1-19 |
| 12 | +License: CC-BY-4.0 |
| 13 | +--- |
| 14 | + |
| 15 | +<!-- cspell: words secp --> |
| 16 | + |
| 17 | +<!-- markdownlint-disable MD025--> |
| 18 | +# [CBOR] Tag definition for [CIP-0003] [ED25519-BIP32] Keys |
| 19 | + |
| 20 | +## Abstract |
| 21 | + |
| 22 | +[CIP-0003] defines [ED25519-BIP32] Keys, Key derivation and a signature scheme. |
| 23 | + |
| 24 | +These elements are commonly found in [CBOR] data structures within metadata on Cardano. |
| 25 | +[CBOR] allows the definition of Tags to unambiguously define data structures encoded in [CBOR]. |
| 26 | +IANA maintains the registry of these Tags as the [IANA CBOR Tag Registry]. |
| 27 | +This CIP simply defines Tags to be registered with IANA and standardizes encoding of these data structures when the Tags are used. |
| 28 | + |
| 29 | +While use of these tags would be recommended, they would not be mandatory. |
| 30 | + |
| 31 | +## Motivation: why is this CIP necessary? |
| 32 | + |
| 33 | +Tags are a useful addition to [CBOR] encoding which allows encoded data to be unambiguously identified. |
| 34 | +Judicious use of tags in [CDDL] Specs and [CBOR] encoding can ease forward compatibility. |
| 35 | +The Tag on an encoded field can be used to identify what is contained in a particular field. |
| 36 | + |
| 37 | +For example, without this Tag definition, a metadata CIP which uses [ED25519-BIP32] public keys: |
| 38 | + |
| 39 | +1. Is likely to just encode public keys as a byte string of 32 bytes; and |
| 40 | +2. Needs to redundantly define how the keys are encoded in the byte string. |
| 41 | +3. Different metadata may encode these keys differently which can lead to confusion and potential error. |
| 42 | + |
| 43 | +However, [BIP32] defines secp256k1 keys and derivation, which are also 32 bytes long. |
| 44 | +There is no standard compliant way for a metadata CIP currently to clearly define which particular key is being encoded. |
| 45 | +While bespoke schemes could be utilized, it is generally better to utilize pre-existing industry standards. |
| 46 | +Bespoke schemes are also likely to vary from Metadata CIP to metadata CIP causing a lack of uniformity and greater chance of error. |
| 47 | +Using the Tags system built into [CBOR] allows for uniformity of specification and encoding. |
| 48 | +Not using Tags makes Metadata CIPs either more complex or limits their flexibility and constrains forward compatibility. |
| 49 | + |
| 50 | +Bitcoin defines CBOR Tags at: [BCR-2020-006] |
| 51 | + |
| 52 | +## Specification |
| 53 | + |
| 54 | +| Type | [CBOR] Tag | IANA Registered | |
| 55 | +| -- | -- | -- | |
| 56 | +| [ED25519-BIP32 Private Key](#ed25519-bip32-private-key) | 32771 | :heavy_multiplication_x: | |
| 57 | +| [ED25519-BIP32 Extended Private Key](#ed25519-bip32-extended-private-key) | 32772 | :heavy_multiplication_x: | |
| 58 | +| [ED25519-BIP32 Public Key](#ed25519-bip32-public-key) | 32773 | :heavy_multiplication_x: | |
| 59 | +| [ED25519-BIP32 Derivation Path](#ed25519-bip32-derivation-path) | 32774 | :heavy_multiplication_x: | |
| 60 | +| [ED25519-BIP32 Private Key](#ed25519-bip32-signature) | 32775 | :heavy_multiplication_x: | |
| 61 | + |
| 62 | +### ED25519-BIP32 Private Key |
| 63 | + |
| 64 | +This key is defined in [ED25519-BIP32]. |
| 65 | + |
| 66 | +This is encoded as a byte string of size 32 bytes. |
| 67 | + |
| 68 | +#### CDDL |
| 69 | + |
| 70 | +```cddl |
| 71 | +ed25519_private_key = #6.32771(bstr .size 32) |
| 72 | +``` |
| 73 | + |
| 74 | +Data for the key inside the byte string is encoded in [network byte order]. |
| 75 | + |
| 76 | +### ED25519-BIP32 Extended Private Key |
| 77 | + |
| 78 | +This key is defined in [ED25519-BIP32]. |
| 79 | + |
| 80 | +This is encoded as a byte string of size 64 bytes. |
| 81 | + |
| 82 | +#### CDDL |
| 83 | + |
| 84 | +```cddl |
| 85 | +ed25519_extended_private_key = #6.32772(bstr .size 64) |
| 86 | +``` |
| 87 | + |
| 88 | +Data for the key inside the byte string is encoded in [network byte order]. |
| 89 | + |
| 90 | +### ED25519-BIP32 Public Key |
| 91 | + |
| 92 | +This key is defined in [ED25519-BIP32]. |
| 93 | + |
| 94 | +This is encoded as a byte string of size 32 bytes. |
| 95 | + |
| 96 | +#### CDDL |
| 97 | + |
| 98 | +```cddl |
| 99 | +ed25519_public_key = #6.32773(bstr .size 32) |
| 100 | +``` |
| 101 | + |
| 102 | +Data for the key inside the byte string is encoded in [network byte order]. |
| 103 | + |
| 104 | +### ED25519-BIP32 Derivation Path |
| 105 | + |
| 106 | +[ED25519-BIP32] defines that the derivation path is composed of 32 bit integers. |
| 107 | +Where the most significant bit defines if the derivation is hardened or not. |
| 108 | + |
| 109 | +This is encoded as a CBOR Array, where each element is the component of the path. |
| 110 | +There can be as many elements to the path as required. |
| 111 | +Each element must be no larger than a 32 bit integer. |
| 112 | + |
| 113 | +For example the path `m / 1852' / 1815' / 0' / 23 / 45` would be encoded as: |
| 114 | + |
| 115 | +```cbor |
| 116 | +[0x8000073c, 0x80000717, 0x80000000, 0x17, 0x2d] |
| 117 | +``` |
| 118 | + |
| 119 | +#### CDDL |
| 120 | + |
| 121 | +```cddl |
| 122 | +ed25519_derivation_path = #6.32774([* path_element]) |
| 123 | +path_element = uint .le 0xffffffff |
| 124 | +``` |
| 125 | + |
| 126 | +### ED25519-BIP32 Signature |
| 127 | + |
| 128 | +[ED25519-BIP32] defines how signatures can be generated from private keys. |
| 129 | +These signatures are defined to be 64 bytes long. |
| 130 | + |
| 131 | +Signatures are encoded as a byte string of size 64 bytes. |
| 132 | + |
| 133 | +#### CDDL |
| 134 | + |
| 135 | +```cddl |
| 136 | +ed25519_bip32_signature = #6.32775(bstr .size 64) |
| 137 | +``` |
| 138 | + |
| 139 | +Data for the signature inside the byte string is encoded in [network byte order]. |
| 140 | + |
| 141 | +## Rationale: how does this CIP achieve its goals? |
| 142 | + |
| 143 | +By defining concrete CBOR tags, it is possible for metadata to unambiguously mark the kind of data encoded. |
| 144 | +This is conformant with the intent of Tags in [CBOR], and aligns with prior use in [BCR-2020-006]. |
| 145 | +An official published spec is required to register these Tags with IANA and so this document also serves that purpose. |
| 146 | + |
| 147 | +## Path to Active |
| 148 | + |
| 149 | +### Acceptance Criteria |
| 150 | + |
| 151 | +* At least 1 Metadata CIP uses at least 1 of the tags defined in this CIP. |
| 152 | +* IANA register the Tags as defined. |
| 153 | + |
| 154 | +### Implementation Plan |
| 155 | + |
| 156 | +* Some of these Tags will be used by Project Catalyst in their new metadata CIPs. |
| 157 | +* Project Catalyst will also make the application to IANA to register the Tags when appropriate. |
| 158 | + |
| 159 | +## Copyright |
| 160 | + |
| 161 | +This CIP is licensed under [CC-BY-4.0] |
| 162 | + |
| 163 | +Code samples and reference material are licensed under [Apache 2.0] |
| 164 | + |
| 165 | +[CC-BY-4.0]: https://creativecommons.org/licenses/by/4.0/legalcode |
| 166 | +[Apache 2.0]: https://www.apache.org/licenses/LICENSE-2.0.html |
| 167 | +[CBOR]: https://www.rfc-editor.org/rfc/rfc8949.html |
| 168 | +[CDDL]: https://www.rfc-editor.org/rfc/rfc8610 |
| 169 | +[CIP-0003]: https://cips.cardano.org/cip/CIP-0003 |
| 170 | +[BIP32]: https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki |
| 171 | +[BCR-2020-006]: https://github.com/BlockchainCommons/Research/blob/master/papers/bcr-2020-006-urtypes.md |
| 172 | +[IANA CBOR Tag Registry]: https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml |
| 173 | +[network byte order]: https://datatracker.ietf.org/doc/html/rfc1700 |
| 174 | +[ED25519-BIP32]: https://github.com/input-output-hk/adrestia/raw/bdf00e4e7791d610d273d227be877bc6dd0dbcfb/user-guide/static/Ed25519_BIP.pdf |
0 commit comments