TBD54566975
      • 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
    • 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 No publishing access yet

      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.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      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
    • 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
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
  • 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 No publishing access yet

    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.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    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
    tbDEX Protocol === the tbDEX protocol is comprised of two elements: _resources_ and _messages_. [ToC] # Messages ## Example The following example is an RFQ ```json= { "metadata": { "from": "did:ex:alice", "to": "did:ex:pfi", "kind": "rfq", "id": "abcd123" "threadId": <RFQ_ID>, "parentId": null, "dateCreated": "ISO_8601" }, "data": { "offeringId": <OFFERING_ID>, "quoteAmountSubunits": "STR_VALUE", "credentials": <PRESENTATION_SUBMISSION_HASH>, "payinMethod": { "kind": "BTC_ADDRESS", "paymentDetails": <OBJ_HASH> }, "payoutMethod": { "kind": "MOMO_MPESA", "paymentDetails": <OBJ_HASH> } }, "signature": "COMPACT_JWS", "private": { "credentials": <PRESENTATION_SUBMISSION>, "payinMethod": { "paymentDetails": <OBJ> }, "payoutMethod": { "paymentDetails": <OBJ> } } } ``` ## Fields All tbdex messages are JSON objects which can include the following top-level properties: | Field | Required (Y/N) | Description | | ----------- | -------------- | --------------------------------------------------------------------- | | `metadata` | Y | An object containing fields _about_ the message | | `data` | Y | The actual message content | | `signature` | Y | signature that verifies the authenticity and integrity of the message | | `private` | N | An ephemeral JSON object used to transmit sensitive data (e.g. PII) | ### `metadata` The `metadata` object contains fields _about_ the message and is present in _every_ tbdex message. | Field | Required (Y/N) | Description | | ------------- | -------------- | ----------------------------------------------------------------------------------------- | | `from` | Y | The sender's DID | | `to` | Y | the recipient's DID | | `kind` | Y | e.g. `rfq`, `quote` etc. This defines the `data` property's _type_ | | `id` | Y | The message's ID | | `threadId` | Y | ID for a "thread" of messages between Alice <-> PFI. Set by the first message in a thread | | `parentId` | N | the ID of the most recent message in a thread | | `dateCreated` | Y | ISO 8601 | > :information_source: **TODO**: decide on what to do about `parentId` when the message is an rfq. set to `null`? remove it? ### `data` The actual message content. This will _always_ be a JSON object. ### `private` Often times, an RFQ will contain PII or PCI data either within the `credentials` being presented or within `paymentDetails` of `payinMethod` or `payoutMethod` (e.g. card details, phone numbers, full names etc). In order to prevent storing this sensitive data with the message itself, the value of a property containing sensitive data can be a [hash](#Hashing) of the sensitive data. The actual sensitive data itself is included in the `private` field. The `private` field is ephemeral and **MUST** only be present when the message is initially sent to the intended recipient The value of `private` **MUST** be a JSON object that matches the structure of `data`. The properties present within `private` **MUST** only be the properties of `data` that include the hash counterpart. > :information_source: Rationale behind the `private` JSON object matching the structure of `data` is to simplify programmatic hash evaluation using JSONPath to pluck the respective hash from `data`. **NOTE**: we should try this to make sure it's actually "easy" #### Example ```json= { "data": { "offeringId": <OFFERING_ID>, "quoteAmountSubunits": "STR_VALUE", "credentials": <PRESENTATION_SUBMISSION_HASH>, <---- hash "payinMethod": { "kind": "BTC_ADDRESS", "paymentDetails": <OBJ_HASH> <---- hash }, "payoutMethod": { "kind": "MOMO_MPESA", "paymentDetails": <OBJ_HASH> <---- hash } }, "private": { "credentials": <PRESENTATION_SUBMISSION>, <---- actual "payinMethod": { "paymentDetails": <OBJ> <---- actual }, "payoutMethod": { "paymentDetails": <OBJ> <---- actual } } } ``` ### `signature` The `signature` property's value is a compact [JWS](https://datatracker.ietf.org/doc/html/rfc7515) #### Header The JWS header **MUST** contain the following properties: | Field | Description | | ----- | ------------------------------------------------------------------------------ | | `alg` | [Reference](https://datatracker.ietf.org/doc/html/rfc7515#section-4.1.1) | | `kid` | the `id` of the DID Doc`verificationMethod` that can be used to verify the JWS | #### Payload The Payload is a JSON object and **MUST** contain the following: | Field | Description | | ---------- | ------------------------------ | | `metadata` | [Hash](#Hashing) of `metadata` | | `data` | [Hash](#Hashing) `data` | ## ID generation Currently, tbdex message IDs are [TypeIDs](https://github.com/jetpack-io/typeid) generated by the sender. The prefix for a given id **MUST** be the same as `metadata.kind` of the message > :information_source: TODO: Discuss using `prefix_$(sha256(cbor(message)))` as the ID as an alternative ## Hashing TL;DR: ``` base64Encode( sha256( cbor(json) ) ) ``` 1. **CBOR Encode the JSON Object**: take your JSON object and encode it using CBOR. This step produces a binary representation of your JSON object. 2. **SHA256 the Bytes**: Hash the CBOR-encoded byte sequence using SHA256. This produces a fixed-size (256-bit) hash. 3. **Base64 Encode the Hash**: Finally, to represent the hash in a text format (for easier sharing, storage, etc.), Base64 encode the SHA256 hash bytes. ### Rationale #### Why CBOR? Benefits: * **Deterministic Serialization**: JSON serialization libraries can sometimes produce non-deterministic results, especially when it comes to the ordering of keys in objects. This could result in the same logical object having different serialized representations. CBOR, by contrast, offers deterministic serialization, ensuring that the same logical object will always produce the same binary representation. * **Uniform Data Representation**: Some data types, such as floating-point numbers, can have multiple valid representations in JSON (e.g., 1.0 vs. 1). CBOR can offer a more consistent representation of these types. Trade-offs: * **Complexity**: Additional complexity & dependencies to encode CBOR * **Performance**: While CBOR might be more space-efficient, the act of converting JSON to CBOR introduces an additional computational step. For small objects or infrequent operations, this might be negligible, but for high-frequency operations, the conversion overhead could become noticeable. #### Why SHA256? * **Widely Recognized and Adopted**: SHA256, which is part of the SHA-2 (Secure Hash Algorithm 2) family, is widely recognized and adopted in various cryptographic applications and protocols. SHA256 is standardized by the National Institute of Standards and Technology (NIST) in the U.S. Being a standard means it has undergone extensive review and evaluation by experts in the field. * **Security**: As of today, SHA256 has no known vulnerability to collision attacks, preimage attacks, or second preimage attacks. * A collision attack is when two different inputs produce the same hash. * A preimage attack is when, given a hash, an attacker finds an input that hashes to it. * A second preimage attack is when, given an input and its hash, an attacker finds a different input that produces the same hash. * **Output Size**: SHA256 provides a fixed hash output of 256 bits (32 bytes). This size strikes a balance between efficiency and security #### Why Base64? When sending a SHA-256 hash (or any binary data) over the wire, it's common to use an encoding that translates the binary data into a set of characters that can be safely transmitted over systems that might not handle raw binary well. One of the most common encodings used for this purpose is Base64 encoding. Base64-encoded data is safe for transmission over most protocols and systems since it only uses printable ASCII characters. Base64 Encoding/Decoding is widely supported across several programming languages. > :information_source: it's worth noting that a raw SHA256 hash is 32 bytes. When base64 encoded it becomes a 44 byte string ## Encryption > :information_source: TODO: Fill out ## Compatibility: tbDEX <> Web5/DWeb Messages The tbDEX messaging format is designed to work with HTTP/REST implementations for PFIs, but can also work with Web5-DWeb messages and thus DWNs. This is important for self-custodial use cases and for transactional portability for end consumers to own their financial data and transaction history. This can be done by mechanically mapping as described below: DWN representation with comments indicating the equivalent tbdex field ```json= { "descriptor": { "recipient": "did:ex:pfi", // same as to "schema": "rfq", // same as kind "protocol": "tbdex", "protocolPath": "tbdex/rfq", "dataCid": <CID_OF_DATA_PROP>, "contextId": "abcd123", // same as threadId "parentId": null, "dateCreated": "ISO_8601" }, "data": { "offeringId": <OFFERING_ID>, "quoteAmountSubunits": "STR_VALUE", "credentials": <PRESENTATION_SUBMISSION_HASH>, "payinMethod": { "kind": "BTC_ADDRESS", "paymentDetails": <OBJ_HASH> }, "payoutMethod": { "kind": "MOMO_MPESA", "paymentDetails": <OBJ_HASH> } }, "authorization": ["COMPACT_JWS"], "private": { // needs work "credentials": <PRESENTATION_SUBMISSION>, "payinMethod": { "paymentDetails": <OBJ> }, "payoutMethod": { "paymentDetails": <OBJ> } } } ``` Current differences: The difference between tbDEX messages and DWN messages are minimal and reconcilable given the appropriate amount of time. The primary differences between the two formats are the following: * tbDEX messages contain an ephemeral `private` field that can be used to transport sensitive data without storing it. * DWeb Message IDs are IPLD CIDs, specifically `dag-cbor`. Support for this is not readily available in kotlin or swift. This difference can be reconciled in a number of ways. * DWeb Message descriptors contain `dataCid` which is an IPLD CID, specifically `dag-pb`. Support for this is not readily available in kotlin or swift. This difference can be reconciled in a number of ways. * The tbDEX message format's hash algorithm is similar to `dag-cbor` minus the `dag` aspect to ensure that implementations in other languages are relatively straightforward * DWeb messages make use of General JWS whereas tbDEX messages use compact JWS * The DWeb message `descriptor` property is roughly analagous to tbDEX message's `metadata` property * DWeb message `data` is returned as base64url encoded whereas tbDEX message `data` is returned as is Potential changes for DWeb messages: move away from IPLD CIDs, move to a simpler hash format that has broad lanhguage support. Support directly embedding of data in some scenarios (or optionally support inline data for small values). tbDEX will rename from metadata to descriptor. # Resources > :information_source: TODO: describe tbDEX Resources (e.g. `Offering`)

    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
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    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