Data Model
The Polycentric Protocol is a binary protocol using
Protocol Buffers v3. The messages below are the v2
definitions from the protos/polycentric/v2 directory of the
Harbor code repository. RPC
request/response messages are covered in gRPC.
Keys and identity
KeyType
The only supported key type is Ed25519.
enum KeyType {
KEY_TYPE_UNSPECIFIED = 0;
KEY_TYPE_ED25519 = 1;
}
PublicKey
There is usually one public key per account, per device.
// PublicKeys signs all events on the polycentric network. There is usually one public key per account, per device.
message PublicKey {
// Type of key used. Defaults to ED25519.
KeyType key_type = 1;
// Value of the key
bytes key = 2;
}
Identity
The identity document. rotation_keys control the identity and can issue new keys;
signing_keys may sign events but not change the document; revocation_bounds
preserve the verifiability of events from a revoked key.
message Identity {
// List of the currently-active rotation keys.
// These keys can publish events, including identity events with updates made
// to the identity document.
repeated PublicKey rotation_keys = 1;
// List of keys that are allowed to sign events (but not change the identity content).
repeated PublicKey signing_keys = 2;
// In order to retain valid events from a revoked keypair, we store their last known
// signature for each collection the key participated in.
repeated RevocationBound revocation_bounds = 3;
// Preferred servers of this identity (where they push and pull from).
// Absent means the identity has not configured a server list yet and
// clients fall back to their defaults; present-but-empty is intentional.
ServerList servers = 4;
// Backup key for recovering an account with no active sessions.
// Its only use is for producing recovery signatures.
optional PublicKey recovery_key = 5;
// Signature from the recovery key in the preceding identity document.
// The content signed should be (identity_string, new_rotation_key).
optional bytes recovery_signature = 6;
}
message RevocationBound {
// Key that is revoked
PublicKey revoked_key = 1;
// One target per collection `revoked_key` wrote in, anchoring proof
// verification at that collection's head event.
repeated EventProofTarget targets = 2;
}
// Per-collection target for verifying an EventProof.
message EventProofTarget {
int32 collection = 1;
// Event's signature; matched by `EventProof.target_signature`.
bytes signature = 2;
// Event's `previous_root` — the Merkle root proofs verify against.
bytes root = 3;
// Leaf count of the tree at `root` (the number of events the head's
// signer was aware of when they signed it).
uint64 leaf_count = 4;
}
EventKey
The unique identifier of an event.
// EventKey's are the unique identitifiers of Events
message EventKey {
// Collection of the stream the event is connected with
// Reserved collections are:
// 1 -> Polycentric Identity
// 2 -> Polycentric feed
// 3 -> Polycentric profile
// 4 -> Polycentric interactions (likes etc)
// 5 -> Polycentric social graph (follows)
// 6 -> Polycentric reports
// 7 -> Polycentric labels
// 8 -> Polycentric verifications
// 9 -> Polycentric calendar (events and RSVPs)
int32 collection = 1;
// Identity Key (sha256 hash of the initial Identity content)
string identity = 2;
// Public key that signed the event
PublicKey signed_by = 3;
// Sequence number of the event in the collection (our logical clock)
uint64 sequence = 4;
}
Events
VectorClock
The sequence numbers (of the same collection) the signing key is aware of.
// Contains the sequences (of the same event collection) that the current KeyPair is aware of.
// The order of the sequences is determined by the keys listed in the relevant identity document:
// The rotation keys first and then the signing keys, with duplicates skipped when they appear again.
// Use `Identity::deduplicated_keys()` to get the keys in this order.
message VectorClock {
repeated uint64 sequence = 1;
}
Event
References, but does not contain, its content.
// Event messages reference, but do not include, content
message Event {
// Key for the event
EventKey key = 1;
// Reference to the sequence, of the Identity Collection (1), that holds the identity document
uint64 identity_sequence = 2;
// Vector clock
VectorClock vector_clock = 3;
// Signature of the previous event signed by the same key. Assists in creating
// immutable collections.
bytes previous_signature = 4;
// Digest of the content
ContentDigest content_digest = 6;
// Timestamp, in milliseconds, of when the event was created
uint64 created_at = 7;
// RFC 6962 Merkle root over this signer's prior signatures in this collection
// (leaf_count = key.sequence - 1). Lets later events attest to the writer's
// history; consumed by EventProof for membership verification.
bytes previous_root = 8;
// The application that created the event. Absent when unknown.
optional Application application = 9;
}
Application
The application that authored an event. It is signed as part of the event, so it is the author's own claim and cannot be changed afterwards.
// The application that authored an event.
message Application {
// Human-readable name, e.g. "Harbor".
string name = 1;
// Reverse-DNS package or bundle identifier, e.g. "org.futo.polycentric".
string id = 2;
// Version of the application, e.g. "1.2.0".
string version = 3;
// Website of the application, e.g. "https://harbor.social".
string url = 4;
}
Every application that writes events should set this on each one it creates. See Declaring Your Application for what to put in each field and how the SDKs stamp it for you.
SignedEvent
The signature is computed over event_bytes, not over a re-encoded Event. The bytes
are stored as-is so the signature stays verifiable.
message SignedEvent {
// Signature of events_bytes below (not the Event message)
bytes signature = 1;
// Serialized representation of the Event message that is signed against
bytes event_bytes = 2;
}
EventBundle
Bundles a SignedEvent with its serialized content and any inclusion proofs. The
content is carried as SerializedContent so its checksum can be verified against the
event's ContentDigest.
// Bundle of the SignedEvent and SerializedContent messages
// We use SerializedContent so that the checksum of the content
// can be verified
message EventBundle {
SignedEvent signed_event = 1;
optional SerializedContent serialized_content = 2;
repeated EventProof event_proofs = 3;
optional EventMetadata meta = 4;
}
EventProof
An RFC 6962 Merkle inclusion proof:
the bundle's SignedEvent is the leaf at leaf_index in the tree rooted at the
target identified by target_signature.
// Merkle inclusion proof: the SignedEvent in this bundle is the leaf at
// `leaf_index` in the tree rooted at the `EventProofTarget` identified by
// `target_signature`.
message EventProof {
bytes target_signature = 1;
// Canonical position of this event in the target's tree.
uint64 leaf_index = 2;
// RFC 6962 audit path: sibling hashes from leaf toward root.
repeated bytes audit_path = 3;
}
EventHint
Extra events a server may return to save the client a round trip — for example, the root and parent posts of a reply, plus the author's latest profile event.
// Hints are additional events that the server provides that may be
// useful to the client and avoid additional network requests.
// For example, a reply to post event could return the root/parent posts along with the
// most recent profile event
message EventHint {
EventBundle event_bundle = 1;
}
Content
ContentDigest
enum ContentDigestType {
CONTENT_DIGEST_TYPE_UNSPECIFIED = 0;
CONTENT_DIGEST_TYPE_SHA256 = 1;
}
message ContentDigest {
ContentDigestType type = 1;
// We hash the serialized bytes
bytes value = 2;
}
Content
The body of an event. Exactly one variant is set.
// Content of the event
message Content {
oneof content_body {
Post post = 2;
Delete delete = 3;
Follow follow = 4;
Block block = 5;
Reaction reaction = 6;
AttributedToReaction attributed_to_reaction = 15;
ProfileUpdate profile_update = 7;
Identity identity = 8;
Repost repost = 9;
Report report = 10;
Labels labels = 11;
// Verifications (see verifications.proto)
VerificationClaim verification_claim = 12;
VerificationVerify verification_verify = 13;
VerificationTarget verification_target = 14;
// Calendar events (see calendar.proto)
CalendarEvent calendar_event = 16;
CalendarEventRsvp calendar_event_rsvp = 17;
}
}
// Serialized content. This is what we do the ContentDigest / Checksum on.
message SerializedContent {
bytes content_bytes = 1;
}
Post, PostReply, Repost
message Post {
// Main text content of the post
string text = 1;
optional PostReply reply = 2;
// Multiple images
repeated ImageSet images = 3;
optional EventKey quote = 4;
// Link previews for URLs in the post text
repeated Link links = 5;
// Labels the creator / client applies themselves
repeated string labels = 6;
// If any, where the post is attributed to.
repeated AttributedTo attributed_to = 7;
}
message PostReply {
// Initial post in the reply chain.
EventKey root = 1;
// Post that is being replied to
EventKey parent = 2;
}
message Repost {
optional EventKey post = 1;
}
Link
message Link {
string title = 1;
optional string description = 2;
optional string image = 3;
string url = 4;
}
Delete
A Delete tells a server to forget the contents of a previous event. The server keeps
the data only if it is still referenced by another event.
// When processed by a server it should check if the data is referenced by any events
// If the Content is linked elswhere, the DELETE is ignored and the server should keep the data.
// If the Content is not linked elsewhere then it can be deleted / purged by the server.
// Essentially, a DELETE means; Ignore (or forget about) the contents of a previous event.
message Delete {
// Event key to be deleted
EventKey event_key = 1;
}
Follow, Block
message Follow {
string identity = 1;
}
message Block {
string identity = 1;
}
Reaction
message Reaction {
// Key of the event being reacted to
EventKey event_key = 1;
// Optional emoji
optional string emoji = 2;
// Upvote = true. Downvote = false.
bool positive = 3;
}
ProfileUpdate
message ProfileUpdate {
// A friendly display name for the user
optional string name = 1;
// Reference to the Blob for the avatar (support multiple different sizes)
optional ImageSet avatar = 2;
// Reference to the Blob of a banner (support multiple different sizes)
optional ImageSet banner = 3;
// Bio
optional string description = 4;
// A domain-based alias (e.g. user@domain.com) the profile claims for itself.
optional string alias = 5;
}
Report
A Report flags another event for a category of policy violation. Reports are
themselves signed events, so a server can record who reported what and respond
according to its own moderation policy (moderation is per-server). additional_info
carries optional free-text context.
message Report {
// Event that is being reported
EventKey event_key = 1;
ReportCategory category = 2;
string additional_info = 3;
}
enum ReportCategory {
// Report categories that have been retired are kept reserved
reserved 2, 4, 5;
reserved "REPORT_CATEGORY_ABUSE", "REPORT_CATEGORY_TERRORISM", "REPORT_CATEGORY_ILLEGAL";
REPORT_CATEGORY_UNSPECIFIED = 0;
REPORT_CATEGORY_SPAM = 1;
REPORT_CATEGORY_CHILD_SAFETY = 3;
REPORT_CATEGORY_COPYRIGHT = 6;
REPORT_CATEGORY_SERVER_POLICY = 7;
REPORT_CATEGORY_VIOLENCE = 8;
REPORT_CATEGORY_SELF_HARM = 9;
REPORT_CATEGORY_SEXUALLY_EXPLICIT = 10;
REPORT_CATEGORY_HATE = 11;
REPORT_CATEGORY_SEXUALLY_SUGGESTIVE = 12;
}
Labels
A Labels event records that a moderation service has classified content
against a set of label values. Labels are signed events in collection 7
(Labels). Like Report, labeling is per-server — a server indexes and
serves only labels from its configured trusted moderation service (set via
HARBOR_MODERATION_IDENTITY on the server side). Labels from any other identity
are stored and synced as normal events but are not indexed or served when
querying feeds.
The server returns matching Labels events as EventHint entries alongside
feed results; the client correlates each hint's event bundle to its target
by event key and renders it according to the user's preference
(Hide / Warn / Show). Because EventHint is a generic container, the client
differentiates label hints from identity/profile hints by checking whether the
event's collection is 7 (Labels).
message Labels {
// Event that is being labeled
EventKey event_key = 1;
repeated string label_values = 2;
}
Blob, Image, ImageSet
Media is stored as blobs in object storage and referenced by digest. Images may carry multiple size variants.
// If an uploaded Blob is uploaded to the servers Object Storage and not
// then attached added to the Content repository, the server will delete from Object Storage.
message Blob {
// Digest/Checksum of the blob
ContentDigest digest = 1;
string mime_type = 2;
int64 size = 3;
}
// Single image with reference to the blob
message Image {
Blob blob = 1;
int32 width = 2;
int32 height = 3;
}
// Collection of different variants of an image
message ImageSet {
repeated Image images = 1;
}