Reference Implementation
Every activity performed by a user can be described as a message with the follow schema:
Message
{
id: STRING[255],
type: STRING[15],
subtype: STRING[15],
creator: STRING[65535],
createdAt: UINT64,
payload: OBJECT, // Depends on message type
}
Message ID
We should hex-encode the message based on the following pseudo code in order to create a deterministic SHA256 hash.
const type = hexString(message.type.toUpperCase()); // e.g. "POST" -> 504f5354
const subtype = hexString(message.subtype.toUpperCase());
const creator = hexString(message.creator); // ETH address
const createdAt = hexUint32(message.createdAt); // e.g. 1624773198 -> 60D8124E
const payload = hex(message.payload); // hex order based on message types
const encode = [
uint8len(hash), hash, // "POST" -> 504f5354 -> 8504f5354
uint8len(subtype), subtype, // "" -> "" -> 0
uint16len(creator), creator, // "bob.eth" -> 626f622e657468 -> 000e626f622e657468
createdAt, // 1624780498 -> 0000000060d82ed2
payload
].join('');
const messageHash = crypto.createHash('sha256').update(encode).digest('hex');
const messageId = creator + '/' + messageHash; // e.g. 0x1234...7890/42740f20aed483b69701a55ab295a2ed
A message can be used to described user activities such as a post, comment, likes, and follow.
Profile Message
The PROFILE type is used to support adding profile data to a name.
{
type: "PROFILE",
subtype: "NICKNAME" | "BIO" | "PROFILE_IMAGE",
payload: {
value: STRING[255],
}
}
{
type: "PROFILE",
subtype: "CUSTOM",
payload: {
key: STRING[255],
value: STRING[16777215]
}
}
Post Message
The POST type is used to support posts (similar to tweets, status update, etc), comments, and reposts.
{
type: "POST",
subtype: "" | "REPLY" | "REPOST",
payload: {
topic: STRING[255],
title: STRING[255],
content: STRING[16777215],
reference: STRING[255],
attachment: STRING[255]
}
}
File Message
The File type is used to support adding file to a name
{
type: "FILE",
subtype: "TORRENT",
payload: {
name: STRING[255],
mimeType: STRING[255],
data: STRING[16777215]
}
}
{
type: "FILE",
subtype: "IPFS",
payload: {
name: STRING[255],
mimeType: STRING[255],
data: STRING[16777215]
}
}
Moderation Message
The MODERATION type is used to support moderation activities, such as a LIKE, UPVOTE, DOWNVOTE, BAN, etc.
{
type: "MODERATION",
subtype: "LIKE" | "BLOCK",
payload: {
reference: STRING[255]
}
}
Connection Message
The CONNECTION type is used to support follows and other types of links between names.
{
type: "CONNECTION",
subtype: "FOLLOW" | "BLOCK",
payload: {
name: STRING[65535]
}
}