archon

Memepool service

Memepool is a Memeplex client: an agent DID that publishes for the users who grant it. This service holds that DID’s key. A user’s own key stays in their wallet.

A user does two things with a wallet, once each:

  1. Signs in. The service issues a challenge, the wallet answers it, and the service knows which DID it is talking to.
  2. Grants the service. The service creates a grant request, an asset of its own as a challenge is, and shows a grant link naming it (archon://auth?grant=<DID>), which a wallet opens, scans or is given pasted; the wallet resolves the request, reads from it that the service is asking, and creates the grant from the user’s identity. A session is shown one request, which lasts an hour, and a new one when that nears its end.

The request lists the registries the service can publish on: the permitted ones its node supports. A wallet offers the user those, so the grant is one the service can use, and the service does not take a grant on any other as one to publish under. On a node that supports none of them the service asks for no grant, and GET /me says why in unavailable.

From then on the service publishes what the user writes, as objects it creates on the grant’s registry, naming the user as author. The user ends this at any time by revoking the grant in the wallet.

The service also serves Memepool’s pages, as files, beside its API. Reading is not this service’s job. Timelines and threads come from the indexer.

The rules are in the Memeplex plan and its reference.

API

All routes are under /api/v1. Those after the sign-in routes need a session.

Route Answer
GET /ready true
GET /version The service’s version and commit
GET /config The service’s name and its DID, which is the client a grant names
GET /challenge A challenge, and the archon://auth?challenge=… link that hands it to a wallet
POST /callback Where a wallet sends { "response": "did:cid:…" }, its answer, when the challenge names this as its callback. Signs nobody in: the answer is kept for the browser that asked
POST /login Signs in the browser that asked for the challenge. With { "response": "did:cid:…" } it takes the answer directly. With no body it asks whether a wallet has sent an answer to the callback: 202 with { "waiting": true } until one has, then { "answered": "did:cid:…" }, which is who answered and not yet a session. With { "confirm": "did:cid:…" } naming that identity it signs the browser in. Sets the session cookie and returns the DID signed in
POST /logout Ends the session
GET /me The DID signed in, with its grant and registry, any others in force, the actions those grants allow between them when every one of them is narrowed, and each grant in force as held (its did, its registry, its own actions and expiresAt where it has them, and as narrowed the actions an earlier anchored scope of it allowed and it no longer does, where there are any); or with the grant link to show and any grants still pending; or, on a node with no registry a grant may be on, with unavailable saying so in place of a link. With no grant in force, ended names the reader’s grant that ended last, as { did, registry, how, at }, where how is expired (at its expiry) or ended (at the block of the anchored version, not a scope update, that ended it); a grant deleted in the wallet is not found, and is not named
POST /objects Publishes an object. Takes its fields, with kind, and for an article its body; returns its did
PUT /objects/:did Replaces one of the user’s objects with another version
DELETE /objects/:did Withdraws one of the user’s objects
GET /objects/:did/state Where an object the user published through this service stands: { state, registry? }, with pending while it waits to be anchored and none when it never will be
GET /identities/:did What an identity says of itself: { did, name?, address? }, with the address only when its domain confirms it
POST /images Stores an image the user means to embed, sent as application/octet-stream, and makes an image asset of it; returns its did, versionId, type, bytes, width and height
POST /files?kind=pdf\|source Stores a paper’s PDF or its source, sent as application/octet-stream, 10 MB at most, and returns the reference { cid, type, bytes } that a paper of the user’s may carry within the hour. What it is comes from its bytes: a PDF, a gzip archive, or LaTeX as text. Counted with the user’s images in the hour
GET /images/:did?versionId= An image asset at a version, as the image it is, for text that embeds it; 404 for anything else
GET /avatars/:did An identity’s avatar, as the image it is, or 404 when it has none the service serves

The service states an object’s v, author and grant itself, from the session and the grant, whatever the request carries.

Names and addresses

An identity’s document may carry a name and an address, which is where a wallet puts them. GET /identities/:did passes them on, so that the pages can say who an author is beside the DID.

Avatars

An identity’s avatar is the image asset its document names as avatar, which is where a wallet puts one. GET /avatars/:did serves it, so that the pages can show an author’s beside what the author wrote, from their own origin.

It is whatever the identity’s owner chose, and the service did not store it:

Anything else is a 404, and the pages show a figure in the avatar’s place.

Storing an image

The client that publishes an object pins what the object embeds, so the service stores an image a user means to embed, as it stores an article’s body. POST /images takes the bytes and makes an image asset of them, which the node’s IPFS pins, and answers with the DID and version that an embed names.

The service does not count an animation’s frames.

Embedded images

Text may embed an image asset at a version, ![words](did:cid:…?versionId=…), and the pages show it from GET /images/:did?versionId=, on their own origin. It is served under the rules Text formatting gives for images:

The service does not decode an image, so it does not check its pixels against the image’s own header or count an animation’s frames: a browser does the decoding.

Content

The client that publishes an object pins the content the object refers to, so this service stores the content of what it publishes and takes none on trust.

A paper’s PDF and source are files, which the service does not take yet.

Status Meaning
400 The object is not valid, an edit would change what the object is, or the object was not published under a grant of the user’s that is in force
401 Not signed in, or the answer is not one this service takes (see Sessions)
409 More than one identity answered the challenge
403 The user has no grant to publish under (none, one not yet anchored, or one revoked or expired), or none that allows this kind of object
429 The service has issued as many challenges this minute as it is set to
502 The node did not accept the operation

Sessions

A session is a random token in a cookie that scripts cannot read and that is sent only on requests from the service’s own pages (HttpOnly, SameSite=Strict).

An answer signs a browser in when all of these hold:

A wallet that sends its answer to the callback is not the browser, so the callback signs nobody in. It keeps the answer, and the browser that asked for that challenge collects the sign-in.

A challenge is an asset anyone on the network can see, and anyone can answer one. So an answer at the callback does not sign the browser in by itself:

Someone who answers a user’s challenge before the user does can therefore stop that sign-in, and cannot become the user or put the user in their own account unnoticed. The other way round, someone who asks for a challenge and persuades a user to answer it is signed in as that user, as with any sign-in by a link. A wallet shows the challenge’s callback before it answers, and that is where the user sees whose challenge it is.

The callback answers a wallet running in a browser on another origin. It is the only route that does, and it allows no credentials.

Each challenge is an asset the node stores and gossips, and anyone can ask for one, so the service issues a limited number a minute (60 unless set otherwise). Sessions and challenges are held in memory: a restart signs everyone out, and nobody loses anything but the session.

The service keeps no record of its users or their grants. A user’s grants are found on the node, by who made them, each time they are needed. With more than one in force, a new object goes under the earliest, and a change to an object goes under the grant the object was published under: under any other it would not be attributed.

What publishing means

An object is a publication once the chain anchors it, and what the grant allowed at that position decides whether it is attributed. The service refuses what it can tell is wrong before creating anything: an object that is not valid, and one of a kind the user’s grants do not allow, which would be created and never attributed. With several grants in force, a new object goes under the earliest whose scope allows its kind.

Running it

Add memepool to COMPOSE_PROFILES, and memeplex for the indexer its readers use, and set ARCHON_MEMEPOOL_WALLET_PASSPHRASE. The service listens on port 4237, on the host’s loopback address unless ARCHON_MEMEPOOL_HOST_BIND says otherwise.

Setting Default Meaning
ARCHON_MEMEPOOL_WALLET_PASSPHRASE none Encrypts the service’s wallet. The service does not start without it
ARCHON_MEMEPOOL_PUBLIC_URL none Where users reach the service, such as https://node.example/memepool. With it, a challenge names the service’s callback and a wallet sends its answer straight back. Without it, a user copies the answer from the wallet to the page
ARCHON_MEMEPOOL_WALLET_URL none The web wallet the site sends its users to, such as https://wallet.example. The service names it in the head of every page it serves, and the pages list it among the kinds of wallet on their page on getting one (wallet, beside the pages’ own address) and offer a challenge and a grant request at it as ?challenge= and ?grant=. An http or https address: the service does not start with another. Without it, the pages name no wallet
ARCHON_MEMEPOOL_FEATURED none The authors whose posts the landing page shows, as DIDs separated by commas, such as did:cid:…,did:cid:…: the site’s front page, which is its operator’s choice. The service names them in the head of every page it serves, and the pages show those authors’ posts, articles and papers to a visitor at the landing address, read from the indexer as any timeline is. At most 1000, which is what the indexer’s timeline takes: the service does not start with more, with an entry that is no DID, or with one DID twice. Without it, the landing page shows no publications
ARCHON_MEMEPLEX_INDEXER_URL (from the profile) The node’s Memeplex indexer. With it, the page at the address of a publication or an author says what is there, for whatever shows a link to it. The page names its own address and an image only where ARCHON_MEMEPOOL_PUBLIC_URL is set
ARCHON_MEMEPOOL_PAGES_DIR public The built pages, which the service serves beside its API. The image carries them. Empty serves none
ARCHON_MEMEPOOL_NAME memepool The name of the service’s identity, and the name it gives in a grant request
ARCHON_MEMEPOOL_REGISTRY hyperswarm The registry the service’s own identity is created on. Not local: the service does not start with that setting, or with a wallet whose identity is on local, since such an identity can publish only on local
ARCHON_MEMEPOOL_PORT 4237 The host port
ARCHON_MEMEPOOL_HOST_BIND 127.0.0.1 The host address the port is bound to
ARCHON_MEMEPOOL_CHALLENGES_PER_MINUTE 60 Challenges issued in a minute
ARCHON_MEMEPOOL_SESSION_HOURS 24 How long a session lasts
ARCHON_MEMEPOOL_TRUSTED_PROXIES 0 Proxies in front of the service. With one or more, cookies are marked for HTTPS only when the last proxy says the request arrived over HTTPS

The service’s key

The service is the DID in its wallet, data/memepool/wallet.json. The repository carries data/memepool, so that the directory belongs to whoever checked it out and the service, which runs as that user, can write to it. If it is missing when the container starts, Docker creates it as root and the service cannot make its wallet: create it first, owned by ARCHON_UID. Every grant a user has made names that DID. On a first start the service makes the wallet and the identity, and says so in its log.

Back the wallet up, with its passphrase. A service started without them is a new client, with a new DID, that nobody has granted: what it published before stays attributed, and every user has to grant it again before it can publish for them.

Through Drawbridge

With the memepool profile, Drawbridge offers the service at <node>/memepool: its pages are at <node>/memepool/ and its API at <node>/memepool/api/v1. Drawbridge sets the service’s cookies for /memepool, so a browser sends them to Memepool and to nothing else on the node’s host, and it limits how often one source reads and writes (see the Drawbridge rate limits).

When the node is served over HTTPS, by a proxy that ends TLS in front of Drawbridge and sends X-Forwarded-Proto, set ARCHON_MEMEPOOL_TRUSTED_PROXIES=1. The service then marks its cookies Secure, so that a browser never sends them over plain HTTP.