ukstv
    • Create new note
    • Create a note from template
      • 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
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me 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
    • Save as template
    • 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 Create Help
Create Create new note Create a note from template
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
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me 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
    # Size Comparison This document provides a size comparison between [dag-ucan](https://github.com/ipld/js-dag-ucan) IPLD serialization format and [UCAN-CACAO](https://hackmd.io/@ukstv/Hy9bQB-Hc) one. ## Context We would like to store UCAN on IPLD. As a side-effect that would provide uniform CID algorithm to reference UCAN in a capability chain. Here we are looking at two approaches for IPLD serialization of UCAN. The first is [dag-ucan](https://github.com/ipld/js-dag-ucan). It uses the following IPLD schema (shortened for brevity): ``` type UCAN struct { version String issuer Bytes audience Bytes signature Bytes capabilities [Capability] proofs [&UCAN] expiration Int facts [Fact] nonce optional String notBefore optional Int } representation map { field facts default [] field proofs default [] } type Capability struct { with String can String } type Fact { String: Any } ``` Proposed UCAN-CACAO serialization uses the following schema: ``` type CACAO struct { h Header p Payload // payload s Signature // signature, single } type Header struct { t String } type Signature struct { t String // "JWT" m optional SignatureMeta s Bytes } type SignatureMeta struct { alg String // = jwt alg field } type Payload { iss String aud String nbf optional Int exp Int nnc optional String fct [Fact] prf [&CACAO] att [Attenuation] } representation map { fields fct default [] } type Fact { String: Any } type Attenuation { with String can String } ``` ## Comparison Methodology To compare IPLD block size we use the same original UCAN: JWT form: ``` eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCIsInVjdiI6IjAuOC4xIn0.eyJhdHQiOlt7ImNhbiI6InN0b3JlL3B1dCIsIndpdGgiOiJkaWQ6a2V5Ono2TWtrODliQzNKclZxS2llNzFZRWNjNU0xU01WeHVDZ054NnpMWjhTWUpzeEFMaSJ9XSwiYXVkIjoiZGlkOmtleTp6Nk1razg5YkMzSnJWcUtpZTcxWUVjYzVNMVNNVnh1Q2dOeDZ6TFo4U1lKc3hBTGkiLCJleHAiOjE2NTI0NDk3MjksImlzcyI6ImRpZDprZXk6ejZNa2s4OWJDM0pyVnFLaWU3MVlFY2M1TTFTTVZ4dUNnTng2ekxaOFNZSnN4QUxpIiwicHJmIjpbXX0.nAVI5RjxBMjEyHgwiXztyzge2Jx7tgv2XGNT9L88qvneCsut2tppabdK-dKlWijzHvwSO_7kZ4Pb4LqBdEd1CA ``` Decoded: ```json= { "payload": { { "att": [ { "can": "store/put", "with": "did:key:z6Mkk89bC3JrVqKie71YEcc5M1SMVxuCgNx6zLZ8SYJsxALi" } ], "aud": "did:key:z6Mkk89bC3JrVqKie71YEcc5M1SMVxuCgNx6zLZ8SYJsxALi", "exp": 1652449729, "iss": "did:key:z6Mkk89bC3JrVqKie71YEcc5M1SMVxuCgNx6zLZ8SYJsxALi", "prf": [] } }, "signatures": [ { "protected": {"ucv":"0.8.1","alg":"EdDSA","typ":"JWT"}, "signature": "nAVI5RjxBMjEyHgwiXztyzge2Jx7tgv2XGNT9L88qvneCsut2tppabdK-dKlWijzHvwSO_7kZ4Pb4LqBdEd1CA" } ] } ``` Corresponding cacao: ``` { "h": { "t": "ucv@0.8.1" }, "p": { "att": [ { "can": "store/put", "with": "did:key:z6Mkk89bC3JrVqKie71YEcc5M1SMVxuCgNx6zLZ8SYJsxALi" } ], "aud": "did:key:z6Mkk89bC3JrVqKie71YEcc5M1SMVxuCgNx6zLZ8SYJsxALi", "exp": 1652449729, "iss": "did:key:z6Mkk89bC3JrVqKie71YEcc5M1SMVxuCgNx6zLZ8SYJsxALi", }, "s": { "t": "JWT", "m": { "alg": "EdDSA" }, "s": "nAVI5RjxBMjEyHgwiXztyzge2Jx7tgv2XGNT9L88qvneCsut2tppabdK-dKlWijzHvwSO_7kZ4Pb4LqBdEd1CA" // bytes encoded as base64url } } ``` **1. Vanilla @ipld/dag-ucan encoding** See `comparison-1.js` Using vanilla `@ipld/dag-ucan` package we have this IPLD block, encoded as base16: ``` a7666973737565725822ed015440c98c4bbaaae14853cca9f75fd363ff8c60af06be52a84c39ea382a2f09536670726f6f6673806776657273696f6e65302e382e316861756469656e63655822ed015440c98c4bbaaae14853cca9f75fd363ff8c60af06be52a84c39ea382a2f0953697369676e617475726558409c0548e518f104c8c4c87830897cedcb381ed89c7bb60bf65c6353f4bf3caaf9de0acbaddada6969b74af9d2a55a28f31efc123bfee46783dbe0ba81744775086a65787069726174696f6e1a627e61c16c6361706162696c697469657381a26363616e6973746f72652f707574647769746878386469643a6b65793a7a364d6b6b38396243334a7256714b6965373159456363354d31534d56787543674e78367a4c5a3853594a7378414c69 ``` Its length is 295 bytes. Corresponding cacao block is 325 bytes. Apart the format, the single major difference is DID representation. `@ipld/dag-ucan` represents `aud` and `iss` fields as public keys of corresponding `did:key` DIDs. CACAO though represents them as vanilla strings. We could change CACAO representation to use same binary public keys. This way we could reduce number of bytes to 281. **2. @ipld/dag-ucan encoding with DID as string** See `comparison-2.js` Based on [discussion](https://github.com/ipld/js-dag-ucan/issues/24), DIDs for `aud` and `iss` should better be represented as strings. Here we modify dag-ucan encoding to use DID strings. This leads to increase in size to 339 bytes. ## Shaving the bytes Let's see how we could reduce block size. First, for UCAN. UCAN ADL uses long field names: `expiration` instead of JWT `exp`, `version`. We could shorten these. Let's use single-letter fields for ancillary fields, like `version` and `signature`. Let JWT payload fields use three letters, as per original UCAN spec. Resulting payload is below: ```json= { { "s": "9C0548E518F104C8C4C87830897CEDCB381ED89C7BB60BF65C6353F4BF3CAAF9DE0ACBADDADA6969B74AF9D2A55A28F31EFC123BFEE46783DBE0BA8174477508", "v": "0.8.1", "att": [ { "can": "store/put", "with": "did:key:z6Mkk89bC3JrVqKie71YEcc5M1SMVxuCgNx6zLZ8SYJsxALi" } ], "aud": "did:key:z6Mkk89bC3JrVqKie71YEcc5M1SMVxuCgNx6zLZ8SYJsxALi", "exp": 1652449729, "iss": "did:key:z6Mkk89bC3JrVqKie71YEcc5M1SMVxuCgNx6zLZ8SYJsxALi", "prf": [] } ``` This requires 298 bytes when encoded in CBOR. We could do shaving for CACAO as well. It already uses compact field names. We know, that UCAN is generally limited to JWT-supported algorithms and `did:key`. We could deduce JWT `alg` field based on `did:key` the same way vanilla `@ipld/dag-cbor` does. We remove then signature metadata then. This results in the following CACAO payload: ```json= { "h": { "t": "ucv@0.8.1" }, "p": { "att": [ { "can": "store/put", "with": "did:key:z6Mkk89bC3JrVqKie71YEcc5M1SMVxuCgNx6zLZ8SYJsxALi" } ], "aud": "did:key:z6Mkk89bC3JrVqKie71YEcc5M1SMVxuCgNx6zLZ8SYJsxALi", "exp": 1652449729, "iss": "did:key:z6Mkk89bC3JrVqKie71YEcc5M1SMVxuCgNx6zLZ8SYJsxALi", "prf": [] }, "s": { "s": "9C0548E518F104C8C4C87830897CEDCB381ED89C7BB60BF65C6353F4BF3CAAF9DE0ACBADDADA6969B74AF9D2A55A28F31EFC123BFEE46783DBE0BA8174477508", "t": "JWT" } } ``` This requires 317 bytes. The difference in 19 bytes is because of CBOR encoding of nested fields and "ucv" string. It is pretty much constant. ## Conclusion Semantically dag-ucan and UCAN-CACAO encoding are the same. There is a small constant difference in size. Using the present code and specifications, for the same UCAN, we have 325 bytes for CACAO and 295 bytes for dag-ucan. If we modify dag-ucan to use `did:key` strings, we get 339 bytes. After modification of the format to further reduce number of bytes, we get 317 bytes for CACAO and 298 bytes for dag-ucan, with the constant difference between the formats. Overall, CACAO and dag-ucan are comparable in size, with constant difference due to richer format of CACAO metadata. In the world where JWT is the only option, it makes sense to go with dag-ucan. If we have interoperability in mind though, it makes sense to stick with CACAO.

    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