HORIZON HASKELLDocslts/ghc-9.14.xd82dee82026-10-12Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · d82dee8 · 2026-10-12

Modulecardano-addresses-4.0.2Haskell2010

Cardano.Codec.Cbor

These are (partial) CBOR decoders for Byron binary types. Note that we ignore most of the block's and header's content and only retrieve the pieces of information relevant to us, wallet (we do assume a trusted node and therefore, we needn't to care about verifying signatures and blocks themselves).

  • 15 values

Encoders

4 declarations
valueencodeAddress :: XPub -> [Encoding] -> Encoding
#
                       Byron Address Binary Format


In the composition of a Cardano address, the following functions concern the
"Derivation Path" box.

+-------------------------------------------------------------------------------+
|                                                                               |
|                        CBOR-Serialized Object with CRC¹                       |
|                                                                               |
+-------------------------------------------------------------------------------+
                                        |
                                        |
                                        v
+-------------------------------------------------------------------------------+
|     Address Root    |     Address Attributes    |           AddrType          |
|                     |                           |                             |
|   Hash (224 bits)   |  Der. Path² + Stake + NM  |  PubKey | (Script) | Redeem |
|                     |    (open for extension)   |     (open for extension)    |
+-------------------------------------------------------------------------------+
             |                 |
             |                 |     +----------------------------------+
             v                 |     |        Derivation Path           |
+---------------------------+  |---->|                                  |
| SHA3-256                  |  |     | ChaChaPoly⁴ AccountIx/AddressIx  |
|   |> Blake2b 224          |  |     +----------------------------------+
|   |> CBOR                 |  |
|                           |  |
|  -AddrType                |  |     +----------------------------------+
|  -ASD³ (~AddrType+PubKey) |  |     |       Stake Distribution         |
|  -Address Attributes      |  |     |                                  |
+---------------------------+  |---->|  BootstrapEra | (Single | Multi) |
                               |     +----------------------------------+
                               |
                               |
                               |     +----------------------------------+
                               |     |          Network Magic           |
                               |---->|                                  |
                                     | Addr Discr: MainNet vs TestNet   |
                                     +----------------------------------+

Encode a public key to a corresponding Cardano Address. The encoding of the attributes part of an address is left out to the caller; This allows for distinguishing between Sequential and Random addresses (the former doesn't have any attributes to encode).

-- Old / Random Addresses
let encodeAddrAttributes = mempty
     <> CBOR.encodeMapLen 1
     <> CBOR.encodeWord8 1
     <> encodeDerivationPath (hdPassphrase rootXPub) accIx addrIx
let addr = encodeAddress xpub encodeAddrAttributes

-- New / Sequential Addresses
let encodeAddrAttributes = mempty <> CBOR.encodeMapLen 0
let addr = encodeAddress xpub encodeAddrAttributes

Note that we are passing the behavior to encode attributes as a parameter here and do not handle multiple cases in encodeAddress itself for multiple reasons:

  • Inversion of control gives us a nicer implementation overall

  • Encoding attributes for Random addresses requires more context than just the public key (like the wallet root id and some extra logic for encoding passphrases). This is just scheme-specific and is better left out of this particular function

Decoders

8 declarations

The attributes are pairs of numeric tags and bytes, where the bytes will be CBOR-encoded stuff. This decoder does not enforce "canonicity" of entries.

Re-exports from CBOR

3 declarations