Hamid Alipour
    • 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
    • Engagement control
    • 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 Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Web3 Authentication (Design Draft): # Goal: Create a simple authentication token format to let users login to web2 applications using their web3 signer keys/wallets. # Stakeholders: * Users: * Wallet users (web3 account holders) * Application users * Builders: * Application developers (web2/web3 devs) * Wallet/dapp developers * Business stakeholders (Decision makers) * Application business stakeholders * Wallet business stakeholders * Security experts: * Protocol architects * Cryptographers * Adversarial systems/players: * Attackers/Hackers * Crypto crackers * Impersonators # Requirements: * Sign in: * Easy * Only using account keys * App users, Wallet users * Off-chain * keepAlive * Use for non-browser/non-web use cases * Support for proxies accounts (e.x. Anonymous proxies) * Effortless support/implementation * Extensible: * Multiple Chain * Multiple account * Multiple wallet * Signing Protocol upgradeability * Security * General security * Data theft resistant * Identity theft resistant * DDOS resistant * No User/Server Impersonation * No Signature forgery * No Private key recovery from signature # Token Design: ## Token Format Options: * #### [JSON](https://www.json.org/json-en.html): * pros: * Serialization/Deserialization is natively supported in most of the languages. * 1st class citizen in javascript as a most popular client side language * Can be minimized to be compact. * cons: * Might not be as human readable as the others, especially when it is minimized (curly and square brackets, if minimized everything will be in one long line). * #### [YAML](https://yaml.org/): * pros: * Human readable to be presented by wallets to the user when they are signing * cons: * Not natively supported in languages and needs third party libraries or to be implemented by developers. * The format is not very lenient and can get error prone ( e.x tabs are not allowed, indentations can get error prone,...) * Can not be minimized, since format relied on indentations and line breaks * #### [TOML](https://toml.io/en/): * pros: * Human readable to be presented by wallets to the user when they are signing. * cons: * Not natively supported in languages and needs third party libraries or to be implemented by developers. * Can not be minimized, since format relies on line breaks. * #### XML: Let’s don’t talk about it. The worst of all worlds! _Both **JSON** and **TOML** sound a good choice for token format. Unlike web2, since for web3 authentications the tokens are signed by humans(users) instead of machines(servers), TOML can be considered as a more human-friendly format choice._ ## Encoding: [Base64Url](https://datatracker.ietf.org/doc/html/rfc4648#section-5) makes sense for serialization for both at rest in-storage and in transit over-the-wire. # Token Proposals: ## JW3T (Json Web3 Token): Inspired by [Json Web Tokens](https://datatracker.ietf.org/doc/html/rfc7519), the idea of Json Web3 Token is to design a self-contained authentication token for web3 dapps, but unlike JWTs that are issued and signed by 3rd party identity providers, JW3Ts are issued and signed by the account holders, using their key-pairs. The token format would look like as: xxxxxx.yyyyyy.zzzzzz ```base64Url(header) + "." + base64Url(payload) + "." + base64Url(signature)``` where header and payload are formatted as json objects and the signature is generated by signing ```header + "." + payload```. ```signature = sign(header + "." + payload)``` ### Header: The fields in the header are explicitly specified and are used during token verification. * ```algorithm```: the signing algorithm that is used to sign the token. * ```address_type```: address type which specifies the derivation method to derive addresses from the public keys * ```token_type```: specifies the token type. The value is always set to “JW3T” for Json Web3 Tokens ### Payload: The fields in the payload are divided into two sets: #### Verification claims: The values of these claims are used in token verification. If the value of these claims result in an invalid token, the token should be deemed invalid and get rejected: * ```expires_at```: Specifies the expiration time of the token on or after which the token must not be considered valid * ```not_before```: Specifies the time before which the token must not be considered valid. * ```address```: Specifies the address of the account that has signed the token. It should be verified against the token signature to verify it is a valid address of the account that has signed the token. #### Information claims: The values of these claims are not used in token verification but might be used by the application developers for authentication or authorization purposes. some example claims: * ```audience```: Specifies the audience of the token whom the token is issued for. A dapp or website can use the value of this claim to verify the token is issued for them. * ```nonce```: an optional claim that contains a random arbitrary value to be used by the audience to mitigate the replay attack. It can be used to assign a token to a specific client session. The value is set by the service that sends the authentication request and is included in the token to be signed by the user. * ```on_behalf_of```: In scenarios where proxies are supported(either known or anonymous), this claim can be used by an account to specify the address of the primary account that the signing account acts as a proxy for. * ```proxy_type```: When the account acts as a proxy for another account this can be used to specify the proxy type which specifies the account permission level (e.x. any, governance, assets, …). ### Verification: In order to verify a token is valid, the following steps should be followed: * The signature should be verified to make sure it is valid. * The claimed address in the payload ```payload.address``` should be a valid address of an account based on the address type that is specified in the header ```header.address_type``` and match the address of the account that has signed the token. * The ```not_before``` and ```expires_at``` should be verified to make sure the token is not expired or used before it is valid. ### Example Scenario (JW3T): #### Scenario : A user wants to sign-in to a dapp using a proxy account. In this scenatio, the dapp need to know the signed-in account intends to sign-in and act as a proxy (known or anonymous) for another account, so the dapp can use the correct address and wrap the transaction in a proper proxy call for the proxy account to sign. #### Solution: The sign-in token can achieve this by including two claims: * ```on_behalf_of```: The on_behalf_of claim specifies the address of the primary account that the sign-in account acts as a proxy for. * ```proxy_type```: The proxy_type claim specifies what type of proxy the proxy account represents. #### Example JW3T: ``` { “algorithm”:”sr25519”, “address_type”:”ss58”, “token_type”:”JW3T” }. { “issued_at”:”1645921000”, “not_before”:”1645921200”, “expires_at”:”1645921525”, “address”: <signed-in account address>, “audience”:”example.dapp.io”, “on_behalf_of”: <primary account address>, “proxy_type”: “governance”, “nonce”: “f77b70” … } ``` After seeing these claims in a token the app will know that any call during this sign-in session is a proxy call of type of “governance” by “signed-in account” on behalf of the specified “primary account address”. One downside of using jw3t might be that they are not very human-friendly. Json format is machine-friendly and can be easily generated and read by machine, but might not be very human readable. ## TW3T (Toml Web3 Token): [TOML](https://toml.io/en/) is a human-friendly serialization format that is designed to be used as a minimal configuration format which is easy to read by humans. It is designed to be more human readable than JSON and simpler than YAML. It unambiguously maps to a hash table and Its simplicity and minimal format makes it a good option for Web3 Tokens that are read and signed by humans. A tw3t consists of a **_statement_** and a **_toml object_**, while the **_toml object_** consists of a **_token information_** section, and a **_signing specification_** section. During the signing process, a human-friendly message is generated by prepending the **_statement_** to the **_toml object_** separating them with two new line (LR) delimitters (/n/n). The token is then signed by the user according to the specified signing specification to generate a signature. ```signature = sign(statement + "\n\n" + toml_object)``` The final tw3t is generated from the concatenation of the base64Url encoding of the **_statement_**, base64Url encoding of the **_toml object_**, and base64Url encoding of the **_signature_**. The final signed token would look like as below: xxxxx.yyyyyy.zzzzzz ```base64Url(statement) + “.” +base64Url(toml_object) + “.” + base64Url(signature)``` ### Statement message: An optional message which can work as a greeting to the user. ### TOML Content: A toml table which consists of 2 sections: #### Claim information: The included claims will be similar to what was describe for JW3T payload. #### Signing Specification: The signing specification plays a similar role as JW3T header and is used in token signature verification. ### Verification: In order to verify a token is valid, the following steps should be followed: * The signature should be verified to make sure it is valid. * The claimed address in the content ```toml.information.address``` should be a valid address of an account based on the address type that is specified by the specification ```toml.specification.address_type``` and match the address of the account that has signed the token. * The ```not_before``` and ```expires_at``` should be verified to make sure the token is not expired or used before it is valid. ### Example Scenario (TW3T): #### Scenario : A user wants to sign-in to a dapp using a proxy account. The dapp needs to know that the signed-in account intends to sign-in and act as a proxy (known or anonymous) for another account, so the dapp can use the correct address and wrap the related transactions in a proper proxy call for the proxy account to sign. #### Solution: The sign-in token can achieve this by including two claims: ```on_behalf_of```: The on_behalf_of claim specifies the address of the primary account that the sign-in account acts as a proxy for. ```proxy_type```: The proxy_type claim specifies what type of proxy the proxy account represents. #### Example TW3T: ``` Welcome to example.dapp.io! Sign this message and accept the example.dapp.io Terms of Service: example.dapp.io/terms [information] issued_at = 2022-02-02 07:32:00Z not_before = 2022-02-03 07:32:00Z expires_at = 2022-02-02 07:32:00Z address = <signed-in account address> audience = “example.dapp.io” on_behalf_of = <primary account address> proxy_type = “governance” nonce = “f88b789” [specification] algorithm = ”sr25519” address_type = ”ss58” token_type = ”TW3T” ``` After seeing the above claim information in a token the app will know that any call during this sign-in session is a proxy call of type of “governance” by “signed-in account” on behalf of the specified “primary account address”. As you might have noticed, tw3t is more human readable and user-friendly than an equivalent jw3t. No curly brackets or commas! Toml also supports comments so a description can be added for each claim to let the users understand what they are signing. A possible downside might be that the Toml format is still relatively new and does not have built-in support in programming languages which causes the libraries to rely on 3rd party dependencies or implement the toml serialization functionality. ## Proof of concept libs: * [Json Web3 Token(JW3T)](https://github.com/hamidra/jw3t) * [Toml Web3 Token(TW3T)](https://github.com/hamidra/tw3t) ## Community initiative * [Login with Web3 Account](https://hackmd.io/xqF4Kb76TWK_2QndCqZQkQ?view)

    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