# Memeplex reference: formats and implementation (#1436)

Status: design; not implemented. Read the [protocol core](memeplex-1436.md) first.
This companion holds the field definitions, schemas, examples and operational
detail. Object formats and rendering requirements apply to
Memeplex implementations; the Memepool section records choices of one client.
The core is the single definition of attribution and publication state.

## Object format

An object is an asset with a `memeplex` member in `didDocumentData`. The five
[kinds](memeplex-1436.md#a-small-vocabulary) share one attribution rule. Responses
use the [version-pinned references](memeplex-1436.md#references-remember-what-was-read)
defined in the core. Examples below show asset data with abbreviated identifiers.

### Fields

| Field | Type | Kinds |
|---|---|---|
| `v` | integer, `1` | all; required |
| `kind` | string | all; required |
| `author` | DID | all; required |
| `grant` | DID | all; required |
| `text` | string, at most 10,000 code points | post, reply |
| `content` | `{ cid, type, bytes }` | post, paper, reply |
| `target`, `targetVersion` | DID, `versionId` | post, optional; reply, rating, tag, required |
| `tags` | 1–20 strings, each 1–64 code points (see Tags and reactions) | post, paper, reply |
| `title` | string, at most 300 code points | post, optional; paper, required |
| `subtitle` | string, at most 300 code points: one line shown under the title | post with a `title`; paper |
| `summary` | string, at most 5,000 code points: an article's summary or a paper's abstract | post with a `title`; paper, required |
| `authors` | 1–100 distinct DIDs, including `author` | paper; required |
| `source` | `{ cid, type, bytes }` | paper |
| `pdf` | `{ cid, type, bytes }` | paper |
| `firstPublished` | date, `YYYY-MM-DD`: when the work first appeared, for work that appeared before it was published here | post, paper |
| `original` | `https` URL, at most 2,000 characters: where the work first appeared | post, paper |
| `verdict` | string, at most 300 code points | reply |
| `rating`, `min`, `max` | integers from −100 to 100 (see Ratings) | rating; required |
| `tag` | string, 1–64 code points (see Tags and reactions) | tag; required |
| `image` | version-pinned DID URL of an image asset (see Custom emoji) | tag |

- **Body.** `text` and `content` are mutually exclusive. A reply has one of them; a
  paper has `content`; a post has `text` or `content`, or neither when it has a
  `target` (a plain boost).
- **References.** `cid` is an IPFS CID string, `bytes` a nonnegative integer, and
  `type` the media type Text formatting allows for that field. A `targetVersion` is a
  canonical operation CID.
- **Strictness.** A field from this table on a kind that does not list it makes the
  object invalid, as does a missing required field. A field not in the table is
  ignored. New fields arrive only with a new `v` (see Schemas: Evolution).
- **Lengths** count Unicode code points. The whole operation must still fit
  Gatekeeper's 64 Ki limit.

`firstPublished` and `original` are for work that appeared somewhere else first: an
article brought over from a blog, a paper from a journal or a preprint server. Both
are the author's claim, as a paper's `authors` are, and nothing checks either. They
are shown as such, beside the time the version was anchored and never in its place:
that time is the only one established. No order follows `firstPublished`; a timeline
is ordered by anchoring, which an author cannot choose. `original` is an address a
stranger wrote: a reader follows it only as a link in text is followed (see Text
formatting).

A verdict is free text so that venues can use their own wording ("accept", "minor
revisions"). A venue that needs a fixed vocabulary defines an extension kind.

### Schemas

Every kind, the grant and the grant request has a **schema**: a JSON Schema (draft
2020-12), in the spirit of AT Protocol's Lexicon. The schema text below is normative.
Each schema is also published as an Archon schema asset (`createSchema`), standing
alone: the text below with `$schema` and the common `$defs` it refers to. Those
files are in `share/schema/memeplex/v1`, and in
[archetech/schemas](https://github.com/archetech/schemas/tree/main/memeplex/v1),
which records each one's DID once it is published. The protocol pins each DID and
`versionId`; none is published yet. A schema validates the `memeplex` member (or
`memeplexGrant`, `memeplexGrantRequest`), not the whole `didDocumentData`.

`tests/fixtures/memeplex-v1-vectors.json` holds signed operations creating objects
and grants, valid and invalid, each with the outcome these rules give it.

- **Validation.** Verifiers and indexers validate each object against its kind's
  schema. A version that fails is not attributed; earlier attributed versions still
  determine publication state. Rules a schema cannot express are part of the kind's definition
  and are checked alongside (see Checks beyond the schemas).
- **An object says which rules apply to it.** `v` chooses the rules and `kind` the
  schema, so both are read before anything else:
  - a `v` that is absent, or is not an integer, makes the object invalid. So does a
    `kind` that is absent, is not a string, or is a bare name other than the five
    core kinds;
  - a `v` that is an integer a verifier does not support is not invalid there but
    unsupported (see Evolution), whatever its `kind`: the kind cannot be judged
    under rules the verifier does not have.

  The same holds for the `v` of a grant and of a grant request.
- **Core kinds have bare names** (`post`, `reply`, `rating`, …).
- **Extension kinds are named by their schema DID:** `"kind": "did:cid:…schema?versionId=…"`.
  That gives namespacing without a registry or DNS. A client that does not know an
  extension kind can fetch its schema, and may show the object generically or ignore
  it.
- **Evolution.** The schemas and the checks beyond them for a given `v` never
  change. Any change to what is valid, including a new optional field (an unknown
  field that was ignored would now be checked), publishes new schemas under a new
  `v`. Validity never depends on Unicode data, so a new Unicode release needs no new
  `v`.
  Each object is validated by the rules of its own `v`, so a verifier that supports
  `v: 2` still validates `v: 1` objects by `v: 1` rules, and every verifier that
  supports a `v` reaches the same result for it. A verifier that does not support an
  object's `v` neither attributes nor rejects it: the object is unsupported there.

### Schema text

**Common definitions**, shared as `$defs` by every schema:

```json
{
  "did": {"type": "string", "pattern": "^did:[a-z0-9]+:[A-Za-z0-9._:%-]+$"},
  "versionId": {"type": "string", "pattern": "^b[a-z2-7]{20,}$"},
  "cid": {
    "type": "string",
    "pattern": "^(b[a-z2-7]{20,}|Qm[1-9A-HJ-NP-Za-km-z]{44})$"
  },
  "pinnedDidUrl": {
    "type": "string",
    "pattern": "^did:[a-z0-9]+:[A-Za-z0-9._:%-]+\\?versionId=b[a-z2-7]{20,}$"
  },
  "bytes": {"type": "integer", "minimum": 0},
  "markdown": {
    "type": "object",
    "required": ["cid", "type", "bytes"],
    "properties": {
      "cid": {"$ref": "#/$defs/cid"},
      "type": {"const": "text/markdown"},
      "bytes": {"$ref": "#/$defs/bytes"}
    }
  },
  "pdf": {
    "type": "object",
    "required": ["cid", "type", "bytes"],
    "properties": {
      "cid": {"$ref": "#/$defs/cid"},
      "type": {"const": "application/pdf"},
      "bytes": {"$ref": "#/$defs/bytes"}
    }
  },
  "source": {
    "type": "object",
    "required": ["cid", "type", "bytes"],
    "properties": {
      "cid": {"$ref": "#/$defs/cid"},
      "type": {"enum": ["application/x-tex", "application/gzip"]},
      "bytes": {"$ref": "#/$defs/bytes"}
    }
  },
  "tagValue": {"type": "string", "minLength": 1, "maxLength": 64},
  "tags": {"type": "array", "minItems": 1, "maxItems": 20, "items": {"$ref": "#/$defs/tagValue"}},
  "text": {"type": "string", "maxLength": 10000},
  "date": {"type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"},
  "link": {"type": "string", "maxLength": 2000, "pattern": "^https://[^\\s]+$"},
  "action": {
    "anyOf": [
      {"enum": ["memeplex:post", "memeplex:reply", "memeplex:rate", "memeplex:tag"]},
      {"$ref": "#/$defs/pinnedDidUrl"}
    ]
  },
  "actions": {"type": "array", "minItems": 1, "uniqueItems": true, "items": {"$ref": "#/$defs/action"}},
  "expiresAt": {
    "type": "string",
    "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(\\.[0-9]+)?Z$"
  }
}
```

Every schema sets `"$schema": "https://json-schema.org/draft/2020-12/schema"`, omitted
below. Each kind's schema lists every field the field table defines: the fields the
kind allows with their types, and the rest as `false`, so a field from another kind
makes the object invalid. Other properties are unconstrained, so unknown fields are
ignored, as the strictness rule requires.

**post**

```json
{
  "title": "Memeplex post",
  "type": "object",
  "properties": {
    "v": {"const": 1},
    "author": {"$ref": "#/$defs/did"},
    "grant": {"$ref": "#/$defs/did"},
    "kind": {"const": "post"},
    "text": {"$ref": "#/$defs/text"},
    "content": {"$ref": "#/$defs/markdown"},
    "target": {"$ref": "#/$defs/did"},
    "targetVersion": {"$ref": "#/$defs/versionId"},
    "tags": {"$ref": "#/$defs/tags"},
    "title": {"type": "string", "maxLength": 300},
    "subtitle": {"type": "string", "maxLength": 300},
    "summary": {"type": "string", "maxLength": 5000},
    "firstPublished": {"$ref": "#/$defs/date"},
    "original": {"$ref": "#/$defs/link"},
    "authors": false, "source": false, "pdf": false, "verdict": false,
    "rating": false, "min": false, "max": false, "tag": false, "image": false
  },
  "required": ["v", "kind", "author", "grant"],
  "dependentRequired": {
    "target": ["targetVersion"],
    "targetVersion": ["target"],
    "subtitle": ["title"],
    "summary": ["title"]
  },
  "allOf": [
    {"not": {"required": ["text", "content"]}},
    {
      "anyOf": [
        {"required": ["text"]},
        {"required": ["content"]},
        {"required": ["target"]}
      ]
    }
  ]
}
```

**paper**

```json
{
  "title": "Memeplex paper",
  "type": "object",
  "properties": {
    "v": {"const": 1},
    "author": {"$ref": "#/$defs/did"},
    "grant": {"$ref": "#/$defs/did"},
    "kind": {"const": "paper"},
    "content": {"$ref": "#/$defs/markdown"},
    "tags": {"$ref": "#/$defs/tags"},
    "title": {"type": "string", "maxLength": 300},
    "subtitle": {"type": "string", "maxLength": 300},
    "summary": {"type": "string", "maxLength": 5000},
    "authors": {
      "type": "array",
      "minItems": 1,
      "maxItems": 100,
      "uniqueItems": true,
      "items": {"$ref": "#/$defs/did"}
    },
    "source": {"$ref": "#/$defs/source"},
    "pdf": {"$ref": "#/$defs/pdf"},
    "firstPublished": {"$ref": "#/$defs/date"},
    "original": {"$ref": "#/$defs/link"},
    "text": false, "target": false, "targetVersion": false, "verdict": false,
    "rating": false, "min": false, "max": false, "tag": false, "image": false
  },
  "required": ["v", "kind", "author", "grant", "title", "summary", "authors", "content"]
}
```

**reply**

```json
{
  "title": "Memeplex reply",
  "type": "object",
  "properties": {
    "v": {"const": 1},
    "author": {"$ref": "#/$defs/did"},
    "grant": {"$ref": "#/$defs/did"},
    "kind": {"const": "reply"},
    "text": {"$ref": "#/$defs/text"},
    "content": {"$ref": "#/$defs/markdown"},
    "target": {"$ref": "#/$defs/did"},
    "targetVersion": {"$ref": "#/$defs/versionId"},
    "tags": {"$ref": "#/$defs/tags"},
    "verdict": {"type": "string", "maxLength": 300},
    "title": false, "subtitle": false, "summary": false, "authors": false,
    "firstPublished": false, "original": false,
    "source": false, "pdf": false, "rating": false, "min": false, "max": false,
    "tag": false, "image": false
  },
  "required": ["v", "kind", "author", "grant", "target", "targetVersion"],
  "allOf": [
    {"not": {"required": ["text", "content"]}},
    {
      "anyOf": [
        {"required": ["text"]},
        {"required": ["content"]}
      ]
    }
  ]
}
```

**rating**

```json
{
  "title": "Memeplex rating",
  "type": "object",
  "properties": {
    "v": {"const": 1},
    "author": {"$ref": "#/$defs/did"},
    "grant": {"$ref": "#/$defs/did"},
    "kind": {"const": "rating"},
    "target": {"$ref": "#/$defs/did"},
    "targetVersion": {"$ref": "#/$defs/versionId"},
    "rating": {"type": "integer", "minimum": -100, "maximum": 100},
    "min": {"type": "integer", "minimum": -100, "maximum": 100},
    "max": {"type": "integer", "minimum": -100, "maximum": 100},
    "text": false, "content": false, "tags": false, "title": false,
    "subtitle": false, "summary": false, "authors": false, "source": false,
    "firstPublished": false, "original": false,
    "pdf": false, "verdict": false, "tag": false, "image": false
  },
  "required": ["v", "kind", "author", "grant", "target", "targetVersion", "rating", "min", "max"]
}
```

**tag**

```json
{
  "title": "Memeplex tag",
  "type": "object",
  "properties": {
    "v": {"const": 1},
    "author": {"$ref": "#/$defs/did"},
    "grant": {"$ref": "#/$defs/did"},
    "kind": {"const": "tag"},
    "target": {"$ref": "#/$defs/did"},
    "targetVersion": {"$ref": "#/$defs/versionId"},
    "tag": {"type": "string", "minLength": 1, "maxLength": 64},
    "image": {"$ref": "#/$defs/pinnedDidUrl"},
    "text": false, "content": false, "tags": false, "title": false,
    "subtitle": false, "summary": false, "authors": false, "source": false,
    "firstPublished": false, "original": false,
    "pdf": false, "verdict": false, "rating": false, "min": false, "max": false
  },
  "required": ["v", "kind", "author", "grant", "target", "targetVersion", "tag"]
}
```

**grant** (`memeplexGrant`)

```json
{
  "title": "Memeplex grant",
  "type": "object",
  "required": ["v", "client"],
  "properties": {
    "v": {"const": 1},
    "client": {"$ref": "#/$defs/did"},
    "request": {"$ref": "#/$defs/did"},
    "actions": {"$ref": "#/$defs/actions"},
    "expiresAt": {"$ref": "#/$defs/expiresAt"}
  }
}
```

**grant request** (`memeplexGrantRequest`)

```json
{
  "title": "Memeplex grant request",
  "type": "object",
  "required": ["v", "name", "registries"],
  "properties": {
    "v": {"const": 1},
    "name": {"type": "string", "minLength": 1, "maxLength": 100},
    "actions": {"$ref": "#/$defs/actions"},
    "expiresAt": {"$ref": "#/$defs/expiresAt"},
    "registries": {"type": "array", "minItems": 1, "uniqueItems": true,
                   "items": {"enum": ["BTC:mainnet", "ZEC:mainnet", "ETH:mainnet", "SOL:mainnet-beta"]}}
  }
}
```

JSON Schema counts string length in code points, matching the field table.

### Checks beyond the schemas

These rules cannot be expressed in JSON Schema. Validators apply them alongside the
schema, and a version that fails one is invalid in the same way.

1. **Rating bounds:** `min < max` and `min ≤ rating ≤ max`.
2. **Paper authors:** `authors` includes `author`.
3. **Expiry instant:** a grant's or grant request's `expiresAt` is a valid ISO 8601
   date-time in UTC, such as `2026-12-31T00:00:00Z`. The schema's pattern checks only
   the shape; a value that is not a real instant is invalid.

4. **First publication date:** a `firstPublished` is a real calendar date, such as
   `2019-03-12`. The schema's pattern checks only the shape.

No check depends on Unicode data: tag values are validated structurally, and how
they are normalized and classified is up to readers (see Tags and reactions).

### Examples

One object of each kind and common variant, showing `didDocumentData`. Each names
its [grant](memeplex-1436.md#one-grant-one-client-one-chain): the reply comes from
Bob's Memepool client, and the paper from a client Alice runs herself. DIDs are
shortened.

**post**

```jsonc
{ "memeplex": { "v": 1, "kind": "post", "author": "did:cid:…alice",
                "grant": "did:cid:…alice-memepool",
                "text": "Every post on Memepool is a DID. So is this photo.\n\n![A canvas tent full of people facing a projector screen](did:cid:…photo?versionId=bafyreiimg…)",
                "tags": ["archon", "memeplex"] } }
```

**post with a title (an article)**: the body lives on IPFS

```jsonc
{ "memeplex": { "v": 1, "kind": "post", "author": "did:cid:…alice",
                "grant": "did:cid:…alice-memepool",
                "title": "Why every post should be a DID",
                "subtitle": "Objects as identifiers, not rows in someone's database",
                "summary": "Permalinks, edit history and provable timestamps for free.",
                "content": { "cid": "bafkrei…", "type": "text/markdown", "bytes": 48213 },
                "tags": ["archon", "publishing"] } }
```

**paper**: revised in place; each revision is a version of the same DID

```jsonc
{ "memeplex": { "v": 1, "kind": "paper", "author": "did:cid:…alice",
                "grant": "did:cid:…alice-own-client",
                "title": "Convergent Replay of Signed DID Histories",
                "summary": "We show that nodes receiving the same signed operations …",
                "authors": ["did:cid:…alice", "did:cid:…bob"],
                "content": { "cid": "bafkrei…", "type": "text/markdown", "bytes": 61207 },
                "pdf": { "cid": "bafybei…", "type": "application/pdf", "bytes": 912340 },
                "source": { "cid": "bafybei…", "type": "application/x-tex", "bytes": 84112 },
                "tags": ["distributed-systems", "did"] } }
```

**reply**: published by Bob's client under his grant, quoting another post inline

```jsonc
{ "memeplex": { "v": 1, "kind": "reply", "author": "did:cid:…bob",
                "grant": "did:cid:…bobs-grant",
                "target": "did:cid:…alice-post", "targetVersion": "bafyreipost…",
                "text": "Including the reactions? Carol measured them:\n\n![Carol's benchmark post](did:cid:…carol-post?versionId=bafyreicarol…)" } }
```

**post with a target**: a quote post; without `text` it would be a plain boost

```jsonc
{ "memeplex": { "v": 1, "kind": "post", "author": "did:cid:…erin",
                "grant": "did:cid:…erin-grant",
                "target": "did:cid:…alice-post", "targetVersion": "bafyreipost…",
                "text": "This is the clearest explanation of the idea so far." } }
```

**reply with a verdict (a review)**: pins the revision it assessed

```jsonc
{ "memeplex": { "v": 1, "kind": "reply", "author": "did:cid:…carol",
                "grant": "did:cid:…carol-grant",
                "target": "did:cid:…paper", "targetVersion": "bafyreirev2…",
                "verdict": "minor revisions",
                "text": "The convergence argument holds, but section 4 assumes …" } }
```

**tag with an emoji (a reaction)**

```jsonc
{ "memeplex": { "v": 1, "kind": "tag", "author": "did:cid:…dave",
                "grant": "did:cid:…dave-grant",
                "target": "did:cid:…alice-post", "targetVersion": "bafyreipost…",
                "tag": "❤️" } }
```

**rating**: three stars out of five

```jsonc
{ "memeplex": { "v": 1, "kind": "rating", "author": "did:cid:…carol",
                "grant": "did:cid:…carol-grant",
                "target": "did:cid:…paper", "targetVersion": "bafyreirev2…",
                "rating": 3, "min": 1, "max": 5 } }
```

**tag**: a community labeller marking a post

```jsonc
{ "memeplex": { "v": 1, "kind": "tag", "author": "did:cid:…spamwatch",
                "grant": "did:cid:…spamwatch-grant",
                "target": "did:cid:…some-post", "targetVersion": "bafyreispam…",
                "tag": "spam" } }
```

### Articles

A post with a `title` is an article: clients give it a long-form layout, with the
optional `subtitle` and `summary` on its card. Its body is usually `content` on IPFS.
Articles need no separate kind because nothing about them differs except the fields
they carry.

### Boosts and quote posts

A boost (repost) is a `post` whose `target` is the original:

- A **plain boost** has no `text` or `content`. Clients show the original as "Alice
  boosted".
- A **quote post** has a body, shown above the original.

`kind`, not `target`, decides thread membership: a thread shows `reply` objects, and
counts posts, ratings and tags that target it without listing them in it.
A boost shares the original with the booster's own audience. Its `target` lets
queries discover it alongside other responses, subject to the current-data limits
under Discovery queries. Boosting needs the `memeplex:post` action.

Quoting inside other text is an embed (see Text formatting): an essay that discusses
three posts embeds each where it discusses it. Embeds are not indexed by Gatekeeper, so
counting them needs an indexer.

### Ratings

A rating states its own scale, so clients can use 5 stars, 0–100 or thumbs up and
down, and ratings stay comparable:

```jsonc
{ "memeplex": { "v": 1, "kind": "rating", "author": "did:cid:…user",
                "grant": "did:cid:…grant",
                "target": "did:cid:…paper", "targetVersion": "bafyreirev2…",
                "rating": 3, "min": 1, "max": 5 } }
```

- `rating`, `min` and `max` are integers from −100 to 100, with `min < max` and
  `min ≤ rating ≤ max`. That covers stars, percentages, thumbs and centred scales,
  and keeps a rating's arithmetic exact.
- The comparable value is `(rating − min) / (max − min)`, from 0 (worst) to 1 (best).
  Three stars on a 1–5 scale is 0.5; 80 on 0–100 is 0.8; a thumbs up `(1, 0, 1)` is 1.
  Centred scales work too: `(0, −2, 2)` is 0.5.
- Four stars out of five, `(4, 1, 5)`, is **0.75, not 0.8**: it is three steps up a
  four-step scale. Clients that display normalized values should not present them as
  "n out of max".
- An author has one rating per target. Changing it is an edit, so the history stays
  visible; aggregators count each author's current attributed version once. Two
  clients can still each create a rating for the same author and target. So that
  independent indexers agree, first derive each object's publication state and
  exclude withdrawn objects. Select the remaining rating whose publication version
  was anchored latest, by its anchoring block's time, with
  ties broken by the smallest canonical `versionId`. Block times are set by the chain,
  not the signer, and stay comparable when the ratings were published under grants on
  different registries. An attributed deletion makes the next one by the same
  rule current; with none left, the author has no rating. Rating a
  new revision of the target is also an edit, which updates `targetVersion`; the
  earlier rating and the revision it rated remain in the history.
- Equal values are not equally precise: a 5-point scale and a 100-point scale cluster
  differently. Aggregators that care can group by `max − min`.

A like is a reaction ("I appreciate this"); a `rating` judges quality.

### Reviews

A reply with a `verdict` is a review. It sits in the thread like any reply, so it can
be answered there, and clients may also list a target's reviews separately. A
reviewer who also wants to score publishes a separate `rating`.

### Tags and reactions

An object's author describes it with the `tags` field inside the object. Anyone else
labels it, or reacts to it, with a `tag` object whose `target` is the object:

```jsonc
{ "memeplex": { "v": 1, "kind": "tag", "author": "did:cid:…labeller",
                "grant": "did:cid:…grant",
                "target": "did:cid:…post", "targetVersion": "bafyrei…",
                "tag": "cryptography" } }
```

A tag value is any string of 1–64 code points. Validity stops there: whether a value
is well formed is a matter of presentation, not authorship, so it never depends on a
verifier's Unicode data.

- **Publishers normalize.** Clients publish a **word** as lower-case NFC with internal
  whitespace collapsed to a single hyphen, so one tag does not splinter across
  spellings, and a **reaction** as exactly one fully-qualified emoji from Unicode's
  recommended (RGI) set, as listed in `emoji-test.txt` (`❤️`, not `❤`). The `tags`
  field takes words.
- **Readers classify and group.** An indexer or client decides whether a value is a
  reaction (one emoji) or a label (anything else), and normalizes values when
  counting, using the Unicode data it has. A value it cannot classify, such as an
  emoji newer than its data, shows as text. How to group skin-tone variants is also
  the reader's choice (see Memepool for its choice).
- **Counted once per author.** An author can apply several values to one object, but
  each value, as the reader normalizes it, counts at most once per author and object,
  even if two clients each published it.

Indexers on different Unicode releases may count a brand-new emoji differently;
authorship is the same everywhere.

#### Custom emoji

A tag with an `image` is a **custom emoji** reaction, like Slack's `:catjam:` or
Nostr's NIP-30 emoji:

```jsonc
{ "memeplex": { "v": 1, "kind": "tag", "author": "did:cid:…dave",
                "grant": "did:cid:…dave-grant",
                "target": "did:cid:…post", "targetVersion": "bafyrei…",
                "tag": ":catjam:",
                "image": "did:cid:…catjam?versionId=bafyrei…" } }
```

- **`tag` carries the shortcode,** by convention `:name:`. A client without custom
  emoji support shows it as text, which still reads.
- **`image` is a version-pinned image asset,** so the picture cannot change after
  the fact and is fetched from IPFS, not from a host that would learn who is reading.
- **Readers group custom emoji by image, not shortcode.** There is no global
  namespace: two communities' `:catjam:` can be different pictures, and one picture
  can have two names.
- **Custom emoji have tighter rendering limits** than other images (see Text
  formatting: Rendering budgets).

Shared emoji packs, which map a community's shortcodes to images so users can pick
from a set, are a client feature built on `image`; they need no protocol change.

Word tags are signed, attributed judgments like any other object, so their
weight depends on who applied them. Moderation labels are tags too (see Memepool:
Moderation).

### Content and size

Inline `text` is for content that fits comfortably inside one operation. Larger
Markdown bodies go to IPFS and are referenced from `content`; binary data uses image
assets or the paper's download fields. Updating the
content of an article is a normal update that replaces the reference; the old
reference stays in the previous version.

### Coauthors

Attribution covers only `author`, the DID that published the paper. The other DIDs in
`authors` are the publisher's **claim**. A listed coauthor confirms it by publishing a
`tag` with the value `coauthor` on the paper, with `targetVersion` set to the revision
they stand behind. Clients show a listed coauthor as confirmed for a revision only
when such an attributed tag pins that exact revision. A tag on an earlier revision is
shown as such ("confirmed v2"), never as confirmation of a later one, because the
publisher can change the paper while keeping the coauthor listed. Otherwise the
coauthor is shown as "listed by the publisher". An attributed deletion withdraws
the tag; an attributed edit can move its confirmation to a new revision. Read the
tag's publication state in both cases.

### Text formatting

Every client renders the same text the same way:

- **`text`, and `content` of type `text/markdown`,** are GitHub Flavored Markdown
  (GFM): CommonMark plus tables, strikethrough, task lists and autolinked URLs, all
  precisely specified.
- **Math** uses the dollar convention shared by Pandoc, Jupyter and GitHub. Inline math
  is `$…$`, display math is `$$…$$`, and longer equations go in a fenced ```` ```math ````
  block. An opening `$` must be followed immediately by a non-space character, and a
  closing `$` must be preceded immediately by a non-space character and not followed by
  a digit, so "it costs $5 and $10" stays text. The math itself is LaTeX, rendered by
  the client (for example with KaTeX or MathJax).
- **No raw HTML.** HTML inside Markdown is displayed as text, never rendered.
- **Safe links only.** Links use `https:` or `did:`. Other schemes, including
  `javascript:` and `data:`, are not followed.
- **Embeds use Markdown image syntax,** in any kind: `![alt text](did:cid:…?versionId=…)`.
  There is no separate attachment or quote field. What a client shows depends on the
  DID:
  - an **image asset** is shown as the image (rules below); a client may lay out a
    short post's images as a gallery;
  - a **Memeplex object** is shown as a card with that version's content, marked if
    it is unattributed or no longer in the history;
  - anything else, or a DID URL without `versionId`, is shown as a link with the alt
    text.

  Only version-pinned `did:` URLs embed. Other sources are not loaded: an `https:`
  image would be fetched by every reader's client, telling the host who is reading,
  and could change after publication. A plain Markdown link, `[text](did:…)`, stays
  a link.
- **Images** are Archon image assets, created with `createImage`, whose data gives
  the IPFS CID, type, size, width and height.
  - **Types:** `image/png`, `image/jpeg`, `image/webp` and `image/gif`. No SVG, which can
    carry script. `createImage` records JPEG files as `image/jpg`; renderers read that
    as `image/jpeg` before applying this list, without changing the signed asset.
  - **Size:** at most 10 MB per image. The asset's `bytes` is the publisher's claim,
    so clients use it only to reject early, count bytes while downloading, and abort
    past the limit before buffering or decoding the whole image.
  - **Alt text** is expected to be non-empty. Clients may flag images without it.
- **Rendering budgets.** Every object is untrusted input, so clients bound the work
  before fetching or rendering, and fall back to a link or a truncated view with a
  "show more" link when a budget is exceeded:
  - **Body:** a `content` body is fetched only if its declared `bytes` is at most
    1 MB, counted while downloading and aborted past that.
  - **Embeds:** at most 20 embeds per object are expanded; the rest show as links.
    An embedded object's card shows its own text with its embeds as links, so
    expansion is one level deep and cannot recurse.
  - **Images:** besides the 10 MB download limit, the asset's declared width × height
    is at most 40 megapixels and is checked against the decoded header before full
    decoding; animated images are limited to 100 frames.
  - **Custom emoji:** an `image` on a tag is at most 256 KB and 128 × 128 pixels,
    checked the same way; animation is allowed within the frame limit.
  - **Aggregate:** at most 50 MB fetched to render one object and its embeds.
- **Math renders untrusted.** Renderers disable trusted commands (KaTeX's `trust`
  option, which enables `\href`, `\url`, `\includegraphics` and HTML-class commands).
- **Graceful fallback.** A client may show any `text` as plain text, and math as its
  LaTeX source; both stay readable.

`content.type` is always `text/markdown`, for every kind, papers included: one body
format means one renderer, and every body reflows on small screens, works with screen
readers, can be searched, and can embed figures and other objects. A paper may also
carry two downloads, which clients offer but never render:

- **`pdf`** (`application/pdf`): the typeset version of record, for readers who want
  the author's exact layout and for printing. Clients do not embed a PDF viewer, which
  would be a large attack surface for untrusted files.
- **`source`**: LaTeX (`application/x-tex`) or a source archive (`application/gzip`),
  as arXiv accepts.

Pandoc converts most LaTeX papers to Markdown with math well enough; the PDF covers
what the conversion loses (custom macros, complex tables, exact figure placement).

## Archon mapping

These primitives exist in `packages/keymaster/src/keymaster.ts` and the
Gatekeeper API. The Memeplex verifier and client are still to be implemented.

| Need | Primitive |
|---|---|
| Create a grant or publication | `createAsset(data, { registry, controller })`; create on the grant's chain registry. |
| Edit | `updateDID` / `mergeData`; each operation produces another version. |
| Withdraw or revoke | `revokeDID`; Memeplex interprets the deletion through its attribution rule. |
| Read history | `POST /api/v1/dids/versions` for every version of a DID as resolved; `resolveDID` with `versionId` for one. Earlier versions remain resolvable while accepted. |
| Store content | IPFS through the Gatekeeper data API; `createFile` stores `{ cid, filename, type, bytes }`. |
| Store an image | `createImage`; the asset has `file` and `image` data. |
| Publish a schema | `createSchema`; the protocol pins its schema DID and version. |
| Discover activity | `GET /api/v1/changes`, after reading every DID once; read them all again when its epoch changes. |
| Query current data | `POST /api/v1/query`; a discovery shortcut, not a complete publication index. |

Archon also supports `transferAsset` and `changeRegistry`. Using either on a
publication ends attribution for that version and its successors. They are not
Memeplex migration mechanisms. Attribution never uses `versionTime` as a grant
cutoff, even though Archon supports historical resolution by time.

## Grant request flow

1. The client creates its agent DID and a **grant request**: an asset, as a
   challenge is an asset, whose data is the request.

   ```jsonc
   { "memeplexGrantRequest": { "v": 1,
                               "name": "Memepool",
                               "actions": ["memeplex:post", "memeplex:reply", "memeplex:tag"],
                               "registries": ["BTC:mainnet", "ZEC:mainnet"] } }
   ```

   Nothing in the request names the client: **the client is the request's
   controller**, which created and signed it. A request is not a publication, so it
   is made where a challenge is, on `hyperswarm`, and may carry `validUntil`; the
   reference client's lasts an hour.

   `registries` lists the permitted registries the client can publish on: those its
   own node supports. A client publishes every object on its grant's registry, so a
   grant on a registry the client cannot reach is a grant it cannot use, and the user
   would have paid to anchor it. Every request lists at least one: a client that can
   publish on all four says so.

   The client presents the request as a **grant link**: an auth link, as the one
   that presents a challenge is (`archon://auth?challenge=<DID>`), with the
   request's DID as its `grant`:

   ```text
   archon://auth?grant=<DID of the request>
   ```

   A challenge and a grant request are both a DID that a service made and a wallet
   answers, and the parameter says which the DID is. A wallet goes by what the DID
   holds all the same: it answers no challenge from a `grant` link and makes no
   grant from a `challenge` link, and says so. A wallet that opens a grant link, or
   scans it, shows the request for review and creates nothing until the user
   approves.

   - The client shows the link as a QR code for a wallet on another device, as a
     clickable link for a wallet on the same device (the browser extension or the
     mobile app), and as copyable text that the wallet accepts when pasted. A wallet
     also accepts the DID alone.
   - The wallet sends nothing back: the client finds the grant by query (step 3).
2. The wallet resolves the request and reads who is asking from it. It creates no
   grant, and says why, when the request cannot be resolved, is deleted, is not an
   asset, does not match the grant request schema, or **is not at its first
   version**. Only the first version is the one its controller signed with these
   contents: an asset's owner can replace its contents and transfer it to an identity
   that signed nothing, so the controller of a later version is not evidence of who
   asked.

   The wallet shows the client DID, the claimed `name` (labelled as the client's own
   claim) and the requested scope: the listed actions, or every core kind when the
   request has no `actions`. The user approves it or a narrower subset and picks a
   registry from those the request lists that the wallet's own node supports. With
   none of those, the wallet creates no grant and says why. Otherwise it creates the
   grant there with that scope, the request's controller as `client` and the
   request's DID as `request`. The grant does not carry `registries`.
3. The client finds the grant with a query for `memeplexGrant.client` (see
   Discovery queries), keeps the one whose `request` is its request, waits until it
   is anchored, and checks the grant against the core authorization rules. The
   grant's creator is the user. Anyone who saw the request could create a grant
   naming it from a different DID, so the client shows the user's identity and asks
   for confirmation before publishing. A client that knows its user, because the
   user signed in to it, finds that user's grants by who created them.
4. The client names the grant's DID as `memeplex.grant` in every object it publishes
   for that user, and creates each object on the grant's registry. Its Gatekeeper
   must support that registry.

A client may hold grants from several users (a shared device, or a service publishing
for many people); the `author` and `grant` fields keep them apart.

## Discovery queries

Gatekeeper keeps an in-memory index of every DID's `didDocumentData`, and
`POST /api/v1/query` matches a path against a list of values. That index does not
cover the controller, which is why objects carry `author` in their data.

| Question | Query |
|---|---|
| Everything by a user | `{ "where": { "memeplex.author": { "$in": ["did:cid:…user"] } } }` |
| Every response to an object | `{ "where": { "memeplex.target": { "$in": ["did:cid:…"] } } }` |
| Objects under one grant | `{ "where": { "memeplex.grant": { "$in": ["did:cid:…grant"] } } }` |
| Grants naming a client | `{ "where": { "memeplexGrant.client": { "$in": ["did:cid:…client"] } } }` |
| Objects an author tagged | `{ "where": { "memeplex.tags[*]": { "$in": ["cryptography"] } } }` |
| Tags others applied (their `target`s are the tagged objects) | `{ "where": { "memeplex.tag": { "$in": ["cryptography"] } } }` |

A thread is loaded by repeating the `target` query one level at a time, keeping
`reply` objects (subject to the limit below); an indexer builds complete thread trees
directly. Objects carry no separate thread-root field to keep consistent.

Only one condition and only `$in` are supported, so a client separates boosts
(posts), replies, ratings and tags by `kind` after the query, and reviews and
reactions by their fields. Results are unsorted and unpaged, and they are not
attributions: the matches still have to pass the attribution check, because anyone
can write any `author` into an object they publish.

These queries match **current** data, so they are incomplete. An object whose latest
version is an unattributed deletion or edit (by a revoked client, for example) may
no longer match, even though its publication state is its last attributed version. A
thread or timeline built from queries can therefore miss such objects. Complete
results need history-based discovery, as the indexer does.

## Memepool

Memepool is the first client and indexer. These choices do not bind other clients.

### Reactions

Memepool offers no skin-tone picker, and counts and renders every reaction as its base
emoji: the fully-qualified RGI emoji that Unicode's `emoji-test.txt` lists as the
untoned form of the reaction's `tag`. Removing the modifier code points is not
enough: ☝🏽 without its modifier is the unqualified `☝`, whose base is `☝️`, and a toned
multi-person sequence can have a different base (👩🏽‍🤝‍👩🏻's base is 👭). The mapping is
derived from `emoji-test.txt`, which lists each toned emoji with its base.

### Follows

Memepool keeps follows **private**: on the device, or in a vault the user owns so that
several clients share them. Follows are never published, so the network does not learn
whom anyone follows. A hosted indexer that builds a reader's timeline does learn the set
of authors it is asked about, and computing the timeline locally does not by itself
avoid this: per-author queries go to a Gatekeeper over HTTP, so a remote Gatekeeper sees
the same author set. Readers who want their follows private from every service query a
Gatekeeper and indexer they run or trust. This is closer to Substack's reading privacy
than to Twitter's public graph.

A public social graph (follower counts, graph-based discovery) can be added later if
something needs it. The candidates are a `follows` list in the user's own DID data,
written by the wallet, or a single per-user state asset kept apart from publications.
Neither is part of v1.

### Indexer

Memepool follows the core's
[history-based discovery and publication rule](memeplex-1436.md#a-graph-anyone-can-reconstruct).
It builds timelines, thread trees, search, counts and per-tag feeds, and serves
those views over HTTP behind Drawbridge. Other indexers may rank them differently.

### Moderation

There is no central moderator. Viewers choose which judgments to apply:

- **Labels are tags.** A community labels an object ("spam", "misleading",
  "nsfw") by publishing a `tag` object from its own DID. A client applies the tags
  from the labellers its reader trusts and ignores the rest, so moderation needs no
  separate mechanism. Block lists of DIDs remain credentials issued by those
  communities (as in #937).
- **Reviews** are replies, so a review's own reputation is visible: who wrote it, who
  replied, whether it was retracted.
- **Unattributed versions** are hidden or marked separately; an earlier attributed
  version remains the publication. A failed creation yields no publication.

### Wallet

The wallets have grants in their Auth tab, beside signing in, and so do the
standalone clients (`keymaster-client`, `gatekeeper-client`), which show the same view. A grant request
reaches it pasted, as a link or a DID, or by opening or scanning a grant link
(`archon://auth?grant=<DID>`), and is shown for review: nothing is created until the
user approves.

A wallet knows no app, Memeplex included: it reads a request and a grant by the
rules Keymaster uses for any app's (`@didcid/keymaster/grant`), and the Memeplex
rules are the verifier's. So it:

- shows the client's DID, the app, and the client's name as the client's own claim;
- shows the actions a request lists as the request names them (`memeplex:post`), and
  for a request that lists none says that the grant allows whatever the app allows;
- grants what the request asks, including any requested `expiresAt`, unless the user
  leaves out some of the actions it lists or changes the expiry;
- offers the registries the request lists that its node supports, and creates
  nothing when there are none;
- lists the identity's grants, of any app, with their actions, expiry and registry;
- changes a grant's actions or expiry in place with a scope update. It can leave out
  an action the grant lists and cannot add one, since it does not know what else the
  app has: a wider grant is a new grant, or a change made with `update-grant`;
- makes revoking a grant a single action.

It shows a revocation in three states: **requested** (signed by the wallet),
**submitted** (accepted by a node for anchoring) and **effective** (the deletion is
anchored). Until it is effective, the wallet warns the user that the client can
still act under the grant.

## Content availability

IPFS content is available only while someone pins it.
`ARCHON_GATEKEEPER_REGISTRIES_PIN` pins operation JSON, not the article, PDF or
image bytes referenced by an operation. Those are pinned separately, and **the
client that publishes an object pins the content the object references**: it put
the bytes on IPFS, for a user who has no node of their own to keep them. Memepool
pins what it publishes, and how long it keeps them is that service's to say and to
tell its users. An indexer or a pinning service may pin the same bytes as well. A
reviewer who needs the assessed content to survive retains its CID and pins it.

A valid publication can exceed a renderer's automatic-fetch budget or have missing
content. Show an appropriate link or placeholder; neither condition grants or
removes authorship. Rendering untrusted material must follow the budgets and
safe-format rules above.

## Design choices

V1 uses public grant assets because third parties can read the user's signed
scope directly. Archon credentials are encrypted to their subjects and would
need an additional public representation for this purpose.

ZCAP and UCAN were considered. V1 needs one level of delegation, with evidence
resolved through Archon; it does not need delegation chains or an additional
capability proof format. The grant is already signed, versioned and revocable.

A revocation snapshot was also considered: the wallet could record the exact
versions it accepts when revoking, instead of requiring chain ordering. That
requires a complete inventory, including deleted objects, and durable availability
of the snapshot. Chain-based authority avoids that inventory at the cost of
anchoring latency. An indexer's first-seen time can inform its own heuristics but
cannot serve as independently verifiable authority.

Spam controls remain a client or service concern. A batch transaction spreads
anchoring cost over many objects; anchoring alone is not an effective rate limit.
Hosted publishing can impose costs or limits, and indexers can rank by trust.

## Scale

Every object, of every kind, is a DID; no kind is batched or stored differently. Each
object goes through Gatekeeper gossip, replay and the in-memory search index on every
node. CPU, memory, startup time and durable storage all grow with the workload.
Optimizations will come as volume requires them, as they have for startup replay.

A sizing benchmark establishes the starting point, on an isolated node with production-like Redis
persistence, in both Gatekeeper ports:

- create 1, 5 and 10 million Memeplex objects with a realistic mix (mostly short posts,
  reactions, ratings and tags, some replies, few articles), across a realistic number of
  authors;
- measure creation throughput, Hyperswarm propagation to a second node, mediator
  batch anchoring throughput on a chain registry, startup replay
  time, resolve latency, `query` latency for `author` and `target`, the memory
  used by the search index, and storage;
- compare startup against the current production dataset to separate per-object cost
  from fixed cost;
- run the application workload too: per-version attribution, re-verification after
  grant changes, rebuilding a fresh indexer from scratch, and
  publication churn (edits, deletions and revocations at a realistic rate).

Acceptance targets for each measurement (latency, memory, rebuild time) are set before
the benchmark runs. The results size node hardware and show where optimization will be
needed first.

A first, smaller run was made on 2026-11-16 to find out what those volumes need: up to
300,000 objects on one node with the Rust Gatekeeper. Its figures are in
`tests/scale/memeplex/README.md`. It found three things in the way, all since fixed:
the Gatekeeper's memory for each DID (#1642), queries that read every DID on the node
(#1643), and a Hyperswarm mediator that ran out of memory under the load (#1644).

| Rust Gatekeeper | First run | After the fixes |
|---|---|---|
| Memory at 300,000 objects | 11.1 GB | 0.83 GB |
| Memory at 1 million | about 36 GB, projected | 2.8 GB, measured |
| Restart until ready at 1 million | about 7 minutes, projected | 373 s, with a peak of 14.2 GB |

What limits a node now is importing: about 2.3 ms for each operation it receives in
the Rust Gatekeeper and about 8 ms in the TypeScript one (#1651), so a node takes in
a few hundred objects a second at most.

The benchmark at 1, 5 and 10 million objects is deferred. The first run answered
whether every object can be a DID. The application workload cannot be measured
until the verifier exists.

## Milestones

1. **Benchmark** objects-as-DIDs (Scale). A sizing run to 300,000 objects is done,
   and one node has held a million. The full volumes are deferred.
2. **Schemas:** JSON Schemas for every core kind and the grant, published as schema
   assets, with signed fixtures. The schemas and fixtures are written. Publishing
   them, and pinning their DIDs here, follows the verifier: publication fixes the
   schemas of `v: 1`, so they are exercised first.
3. **Verifier library:** the attribution rules, in a package of its own, used by the indexer and, for validity and their own grant, by clients, with
   cross-checks against real signed objects, including revoked and forged grants,
   transferred objects, backdated siblings, and unattributed edits and deletions after
   revocation (of ratings and coauthor confirmations in particular), and a fresh index
   rebuild that must match a continuously running one.
4. **CLI client:** create an agent DID as the client, grant it from the user's
   identity, then create, edit, delete and query objects on the grant's registry from
   the existing CLI and SDKs; this works with today's asset commands.
5. **Delegation:** wallet UI to create, list and revoke grants on a permitted registry. The wallets (`packages/wallet-ui`) have grants in their Auth tab, beside signing in: it takes a pasted grant link, resolves the request it names and reads it with Keymaster's `grantRequestOf` (`@didcid/keymaster/grant`), as it would any app's. The wallet knows no app, so it shows a request's actions as the request names them and can narrow a grant's actions but not add one. An agent, which acts through the CLI and the MCP tools and cannot paste a link into a wallet, uses Keymaster's grants: `create-grant <request>`, `list-grants`, `update-grant <id>` and `revoke-grant <id>` in the three CLIs (`scripts/archon-cli.js`, the TypeScript and the Python Keymaster CLI), the MCP tools `archon_create_grant` and the rest, and `/grants` on the Keymaster service. Those grants are not Memeplex's alone. Keymaster knows no app: a client of any app asks with a grant request, an asset it creates holding `<app>GrantRequest`, and Keymaster answers with an asset holding `<app>Grant`, to the identity that created the request (`packages/keymaster/README.md`, "Grants"). Memeplex is the app `memeplex`. Keymaster checks only the shape every request has, so a grant it makes is not thereby valid under these rules: the verifier says. `tests/keymaster/grant.test.ts` has the verifier read the grants Keymaster makes for a `memeplexGrantRequest`. Still to do:
   - A wallet shows a revocation's state only until it is closed.
6. **Indexer.** The `memeplex-indexer` service, enabled by the `memeplex` profile and offered through Drawbridge at `/memeplex`; see `docs/services/memeplex-indexer/README.md`.
7. **Memepool client.** Its library is `@didcid/memeplex/client`: `MemeplexClient` asks for a grant, finds it and publishes under it through a Keymaster and a Gatekeeper it is handed, and `IndexerClient` reads an indexer's views. `tests/memeplex/client.test.ts` runs the whole flow, from a grant link to a thread read over HTTP, with the test anchoring as a mediator does. The service that holds Memepool's key and publishes for the users who sign in to it is `services/memepool` (`docs/services/memepool/README.md`). It is deployed by the `memepool` profile and offered through Drawbridge at `/memepool`. Its pages are `apps/memepool`: sign-in, the grant, a timeline of the authors a reader follows, posts, replies and threads. The Memepool service serves them, at `<node>/memepool/` through Drawbridge. The service stores the body of an article on its node's IPFS, which pins it, and publishes the reference; it takes no reference to content it has not stored, and reads back the body of what it published (see Content availability). The pages write, show and edit an article. The pages render text as GitHub Flavored Markdown under the rules of Text formatting for HTML, links and images loaded from elsewhere. They show an embed as what its DID is: an object as a card with what that version said, read from the indexer at that version, and an image asset as the image, which the service serves under the limits above without decoding it. They render math with KaTeX, under the dollar rule above and with its trusted commands off. The service stores an image a user chooses and makes an asset of it, on `hyperswarm`, for text to embed. Still to do there: a paper's PDF and source, which are files, and coauthors.
8. **Moderation:** block lists and labels.
9. **Zaps:** Lightning payments to an author for something they published, as Nostr
   has. Later; not designed.

## References

- ZCAP: [Authorization Capabilities v0.4.0](https://w3c-ccg.github.io/zcap-spec/) and
  UCAN: [specification](https://github.com/ucan-wg/spec), considered and not adopted
- #937: thin agent marketplace (attestations, opt-in block lists)
- #1044: encrypted messageboard where each post is a DID owned by its author
- #1299: historical verification of credential responses
- #1462 / #1463: Gatekeeper resolution by `versionId`
