Introduction
Twetch is a decentralized social network where users own their data and earn money through interactions.
Each Twetch interaction is recorded on the Bitcoin ledger, enabling users and developers to access, monetize and own their content without relying on a trusted 3rd party to do so.
Twetch Protocol
This document serves to walkthrough each of the interaction types on Twetch, documenting their on-chain protocols with the intention of promoting development and innovation from any programming language.
Background
Various protocols have been created to structure how data is published on-chain in so-called OP_RETURN outputs, where the OP_RETURN opcode represents the return function in the Bitcoin script programming language. Since nodes do not process data after the return function, arbitrary data can be added afterwards such that it will be stored on the Bitcoin ledger. Read more about this here.
Bitcom is the widely adopted convention for declaring on-chain protocols, where a public key hash or address is used as the first field to establish uniqueness, and ownership over the protocol.
The Twetch protocol implements three Bitcom protocols concatenated together:
B:\ - for uploading files to the ledger
MAP – for associating key, value pairs
AIP – for signing arbitrary OP_RETURN data
| or pipe characters delineate boundaries between different protocols used in the same OP_RETURN output.
ABI Schema
The Twetch ABI (Application Binary Interface) Schema contains defines the following:
- Each Twetch action
- How to construct actions for the OP_RETURN output
- Each fields' data type
- Which fields should be signed
- Any fields' default values
The current Twetch ABI can be found here.
The BSVABI JS library can be found here.
Any Twetch action can be constructed by interpreting the ABI. The primary actions of the ABI will be functionally documented below.
Signing Twetches
To sign Twetch data, inspect the ABI for the fields messageStartIndex
and messageEndIndex
.
The fields in those positions must be signed and placed in the mySignature
field.
Steps:
- Populate an array with the values specified for the ABI action
- Convert the array to a Buffer
- Perform a SHA-256 hash on the buffer
- Sign the hash with the private key tied to the address in the
myAddress
field of the ABI action