Keri notes
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # A cat named CESR – an extraordinary introduction to CESR ## Introduction In the first post of the series, we introduce the [CESR (Composable Event Streaming Representation)](https://weboftrust.github.io/ietf-cesr/draft-ssmith-cesr.html) protocol, primarily invented by Dr. Sam Smith to enable effective data streaming in the [KERI](https://weboftrust.github.io/ietf-keri/draft-ssmith-keri.html) protocol. One of its unique features, novel in the industry, is the ability to switch between text and binary representations, enabling easier adoption and debugging with text and, when ready, going production with binary. Thus, the consumer benefits from both worlds: the compactness and efficiency of binary representation and the readability and ease of use with a text representation. For a higher-level overview of the protocol, we also recommend looking at [this article](https://medium.com/happy-blockchains/cesr-one-of-sam-smiths-inventions-is-as-controversial-as-genius-d757f36b88f8). In this post, we demystify CESR using some fanciful information to better understand the underlying protocol mechanics. ## CESR building blocks CESR uses other encoding formats internally, such as JSON, CBOR, and MessagePack, to serialize data structures using field maps. We will call those building block payloads. They are interleaved with CESR-specific elements. The second building block, which is CESR-specific, is attachment. It is a combination of codes, primitives, and groups, which we will discuss in more detail in the following sections. Thanks to attachments, we can enrich data with extra information and context while maintaining the payload's integrity. Together, payloads and attachments form a CESR stream or datagram. Below is an example of the stream using the KERI protocol in CESR. Payloads are in green, and attachments are in yellow. ![](https://i.imgur.com/8IHxvPk.png) ### Protocols (Code Tables) Although CESR primarily emerged to support KERI events with efficient transmission of cryptographic material, it enables support for any other protocol. CESR is all about the metadata that describes underlying data structures (payloads). Thus, anything that benefits from CESR properties might establish a new protocol. ### Primitives The most basic CESR element is primitive. It represents a single piece of data with a text code and raw bytes of its value. The code specifies the data type and length. For example, let us say we have a code, `M,` representing a two-byte binary number. Assume we have a number `255` that we want to encode in CESR. Thus it is `MAD_` in the text domain or `[48, 0, 255]` in the binary (more will follow). ### Groups Groups are primary aggregators, enabling the creation of more complex data structures. They can contain not only primitives but also other groups, which can be nested to create a hierarchical structure. They are represented by codes that indicate the types of elements that will appear next in the stream and count them. ### Pipelining CESR provides special codes for pipelining the attachments. They are similar to group codes, but instead of a count of groups, it contains the total length of attached data. Thanks to that, the attachment length is known after parsing the code. We can cut it from a stream and process it independently. It is not possible in the case of group codes because we know the count of attached groups, not the exact attachment length. ### Representation domains CESR elements can be represented in one of three domains: as bytes (B domain), as text (T domain), and as a tuple of text code and value bytes (R domain). CESR provides transformations between each of those domains, denoted as `T(B)`,`T(R)`, `B(T)`, `B(R)`, `R(B)`, `R(T)`. ![](https://i.imgur.com/Lz1BCzR.png) Here is how we can represent primitive from the above example in each domain: ![](https://i.imgur.com/LJ8HoQR.png) ## Example Let us demonstrate CESR's fundamental features by introducing an arbitrary, custom-defined protocol. The protocol is about a `cat` and its sophisticated characteristics. We define it solely for teaching purposes to explain protocol mechanics. ### Cat's color Let us introduce a CESR primitive for that. Color is represented in [RGB](https://en.wikipedia.org/wiki/RGB_color_model). In the RGB color model, primary colors - red, green, and blue - can be combined in various proportions to create a wide range of other colors. Each primary color is represented by a number ranging from 0 to 255, with 0 representing the absence of that color and 255 representing its maximum intensity. For example, `[255, 0, 0]` is red, `[0, 0, 0]` - black and `[255, 255, 255]` - white. We need three bytes to encode color. Let us define the code and value length for our primitive: | code | description | value length (in bytes) | value length (in chars)| |----------|:-------------:|------:|---:| | 1COL | color in RGB | 3 | 4| **Note** Codes are not random. Their length depends on the length of data that they are encoding. Primitive here has a fixed size, and code length is the same as the count of base64 padding characters after encoding those values, or four if there is no padding. The first characters of the code are specified in CESR documentation and let parsers choose the proper code table. For further explanation, look into [CESR RFC](https://weboftrust.github.io/ietf-cesr/draft-ssmith-cesr.html#section-3.1). Examples of color primitives in each domain: ![](https://i.imgur.com/ch8DLgu.png) ### Multicolor cat Cats often have more than one color, so how can we express that? Let's create additional code, that will represent a group. | code | description | |----------|:-------------:| | -C## | group of cat colors | **Note** Hash symbols in this table represents a count of elements in that group. It is encoded in [positional notation](https://en.wikipedia.org/wiki/Positional_notation) with 64 as a base and base64-url safe alphabet letters as digits. Here are some examples: `AA -> 0`, `AB -> 1`, `AC -> 2`, `A_ -> 63`, `BA -> 64`. For example, `-CAC` means, that two colors will appear next in the stream. Because the code for each primitive specifies its value size, CESR "knows" where each primitive ends. It doesn't require additional delimiting characters to separate primitives. So having the following stream, we're now able to interpret its contents: ![](https://i.imgur.com/CPfbNnE.png) ### Cat's life number Since cats have nine lives, assume that in each of them they can have another color. Can we attach this information using CESR? Yes, we can! Let's add new codes for that: one for the order number of cat's life, and a second for group, that will gather life and colors. Because one byte is enough to encode the order number of cat's life, we can use two character code. (That's because base64 encoded one-byte value has two padding characters) | code | description | value length (in bytes) | value length (in chars) | |----------|:-------------:|------:|----:| | 0L | order number of cat's life | 1 | 2 | Here are examples of cat life number primitive in each domain: ![](https://i.imgur.com/BnDhs75.png) And here is a group code for gathering life and color: | code | description | |----------|:-------------:| | -G## | group of cat's life number and colors | Now, let's join all of this together in the attachment, which tells us what color our cat has in which life. ![](https://i.imgur.com/IDqnbO0.png) ### Pipelining In the example, we will use `-V` code from the specification : | code | description | |----------|:-------------:| | -V## | Count of total attached grouped material qualified Base64 4 char quadlets | As mentioned before, this code lets us pack attachments in a block, that can be cut from the stream and processed separately. For example, let's look at the stream: `-VAL-GAC0LAE-CAC1COLAAAA1COL____0LAF-CAB1COL5ng8` Code `-VAL` means, that 11 four characters quadlets contain one block of attachments. 44 characters should be parsed to get it. ### Final protocol codes table Codes specify groups and primitives that appear in the stream. When we collect all our codes in one table, we get CESR Master Codes Table for the cat use case: | code | description | value length (in bytes) | value length (in chars) | |----------|:-------------:|------:|----:| | | **Basic Two Character Codes** | | | | 0L | number of cat's life | 1 | 2 | | | **Basic Four Character Codes** | | | 1COL | color in RGB | 3 | 4 | | | **Group codes** | | | | -C## | group of cat colors | | | -G## | group of cat's life number and colors | | | | **Framing codes** | | | | -V## | Count of total attached grouped material qualified Base64 4 char quadlets | ### To sum it up With all this in mind, we can interpret the stream from the beginning of this blog post: ``` {"message": "Let the cat out of the bag"}-VAL-GAC0LAE- CAC1COLAAAA1COL____0LAF-CAB1COL5ng8{"message": "Curiosity killed the cat"} -VAR-GAD0LAB-CAB1COLZGRk0LAC-CAD1COL5ng81COL____1COLZGRk0LAD-CAB1COLAAAA {"message": "A cat always lands on its feet"}-VAc-GAD0LAB-CAB1COLZGRk0LAC -CAD1COL5ng81COL____1COLZGRk0LAD-CAB1COLAAAA-GAC0LAE-CAC1COLAAAA1COL____0LAF -CAB1COL5ng8 ``` See the following picture for a profound explanation of our custom protocol, defined using CESR's fundamental building blocks: ![](https://i.imgur.com/FQiXQz9.png) # Summary We have introduced CESR fundamentals and demonstrated an arbitrary CESR protocol. It inherently showcases CESR is about metadata, represented using its mechanics via groups and primitives. CESR protocol, while primarily invented for streaming cryptographic material along with the KERI messages, enables a stream of any metadata related to the payload. In other words, any metadata-rich case is CESR-compliant. If furthermore compactness and robustness are also significant factors, CESR is an excellent fit.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully