Twetch Developer

Twetch Developer

    ›Encryption

    Protocol

    • Introduction
    • Posting
    • Likes
    • Follows
    • Votes
    • Purchases
    • Feature requests
    • Authentication
    • Twetch API

    twetch-js

    • Overview
    • Library
    • Storage
    • Wallet
    • CLI

    Twetch Pay

    • Overview

    Encryption

    • Overview
    • Create a conversation
    • Send a message
    • Read messages

    Send a message

    To send a message in a conversation, follow these steps:

    1. Extract the private key tied to the m/0/0 path of your Twetch 12-word seed.

    A JavaScript example can be found here.

    1. Fetch the encrypted key generated from Step 3 of Initiating a Chat.

    HTTP POST request:

    URL: https://api.twetch.app/v1/graphql

    Headers: {
        Authorization: ‘Bearer <twetch_authorization_token>’
    }
    Body: {
        query:  `{
            conversationById(id: "${convId}") {
              id
              createdAt
              me {
                encryptedKey
              }
            }
        }`
    }
    

    Response:

    {
      "data": {
        conversationById: {
            id: 'c5ef415a-5753-430d-a57c-dca1ff40a5e8',
            createdAt: '2020-10-19T20:14:57.036066+02:00',
            me: {
                encryptedKey: 'QklFMQIvWga0Ndyv0ru8dL+W/Cvk6pAu9T9v79ARua7IGT2XGewBpmTIsViEG73yCSu9+lbOsdG/iWnLIy19if7PfUW2I2UaD9n8gaOb2ad/P5qnr3HUiJMpMDPwC4j+cxHbUmvGeAHEK4E3eyzLxthkNyB0'
            }
        }
      }
    }
    
    1. ECIES decrypt the encrypted key from Step 3.

    A JavaScript example can be found here.

    1. AES encrypt the message being sent to the decrypted ECIES key from Step 3.

    A JavaScript example can be found here.

    1. Create a JSON payload:
    {
        conversationId: <conversation_id>
        userId: <from_user_id>
        description: <encrypted_message_generated_in_Step_4>
    }
    
    1. Post the payload from Step 5 to the graphql endpoint:

    HTTP POST request:

    URL: https://api.twetch.app/v1/graphql

    Headers: {
        Authorization: ‘Bearer <twetch_authorization_token>’
    }
    Body: {
        query:  `mutation createMessage($payload: MessageInput!) {
            createMessage(input: { message: $payload }) {
                message {
                    description
                    id
                }
            }
        }`, { <payload_generated_in_Step_5> }
    }
    

    Response:

    {
      "data": {
        createMessage: {
            message: {
                description: 'eeaaf4cd',
                id: '1fb19cd0-8267-4070-b6f4-11e7dc31df35'
            }
        }
      }
    }
    
    ← Create a conversationRead messages →