Skip to main content

Module community

Module community 

Source
Expand description

Vector Communities, on the Concord v2 (CORD) protocol in v2, plus the pieces every layer shares: ids, epochs, images, transport, roles and moderation.

Modules§

attachments
Community message attachments (NIP-92 imeta).
cache
Per-account RAM state for Community sync: the in-flight page claims. Keyed by this account’s channel ids, so it lives on the account’s session and goes when that does.
cipher
Raw-key NIP-44 v2 sealing with a nonce no call site can choose.
edition
Real-npub authority editions — the keyless model’s authorship + version carrier.
mentions
Role mentions (CORD-03 §3, CORD-04 §8): a ["role", "<role_id>"] tag beside an @Name in the text. The text stays readable on clients that don’t know the tag.
message_delete
Deleting what the local user sent to a Community, from its relays.
moderation
Moderation authority: who may remove whose message (CORD-04 §3/§5).
policy
The moderation policy engine (Phase 1).
raid
Raid assessment: which members read as people, and which read as spawned identities.
rank
Rank keys (CORD-04 §3): Role order as fractional keys over 0-9A-Za-z, compared byte by byte, 1 to 32 bytes and never ending in 0. Between any two keys another always exists, so moving a Role between two neighbours is one edition, on the moved Role alone. Channel and Category positions (CORD-03) use the same keys.
roles
Concord role graph (GROUP_PROTOCOL.md).
transport
Transport abstraction for Community events.
v2
Concord v2 (the upstream CORD specs — github.com/concord-protocol/concord).
version
Per-entity version chain for authority editions.

Structs§

ChannelId
A Channel’s stable identity within a Community. Same opaque-random rule as CommunityId; doubles as the addressable metadata d-tag.
ChannelKey
A 32-byte symmetric channel secret — the raw NIP-44 v2 ConversationKey material. Zeroized on drop; never logged.
CommunityId
A Community’s stable identity = a random 32-byte opaque id (NOT a timestamp-encoding snowflake, which would leak creation time).
CommunityImage
A reference to an encrypted image blob (community logo/banner), using the same technique as NIP-17 file attachments: a fresh random AES-GCM key+nonce encrypts the image, the ciphertext is uploaded to Blossom, and this reference travels inside ServerRoot-sealed metadata. So possession of the server-root key (every member) gates the image, and there is no key reuse across images.
Epoch
The epoch counter — the read-access clock (“two clocks”). Bumps only on a rekey; stamped explicitly even when it is 0, so multi-channel and rotation stay additive (forward-compat hook #1).

Constants§

CONTROL_PK_SCOPE
The epoch-key-archive scope for each epoch’s Control Plane address, kept so the Audit Log can read an epoch back after a Refounding has moved the plane on. Non-hex, like the above.
CONTROL_ROOT_SCOPE
The epoch-key-archive scope for a v2 control_root (CORD-02 §2): non-hex on purpose, so it collides with neither a channel id nor the root sentinel. Reserves the pair beside the root at mint (retry idempotency) and archives the secret per epoch.
MAX_COMMUNITY_RELAYS
Protocol cap on a Community’s relay set (§ transport). More relays are needless and amplify resource + metadata-exposure cost; 5 gives redundancy without centralisation. Enforced by truncate-on-read at every Community/CommunityInvite construction boundary, so a hostile or legacy bundle degrades to ≤5 distinct relays rather than being honored or rejected.
REALTIME_FRESH_WINDOW_MS
How fresh an inner send time must be to surface as a REALTIME event (ms). Generous against sender clock skew and relay push latency; tiny against the hours-to-months staleness of a relay-to-relay backfill replay.
SERVER_ROOT_SCOPE_HEX
The all-zero hex scope id for server-root-scoped epoch keys (RekeyScope::ServerRoot uses the all-zero id32 sentinel). A ChannelId is random-32, so it can never collide with this — letting one community_epoch_keys table hold both channel keys and the base/server-root key keyed by (scope_id, epoch).
SVG_REFUSED
Community icons and banners are raster only, sent and shown, like custom emoji.

Functions§

cap_relays
dispatch_inbound
Route an inbound Community event, live or a slow relay’s straggler.
holds_history_from_start
Whether this account holds the key a channel’s history began under. A member who joined after a rotation holds only the epochs since: what came before sits on the relays sealed under keys it never received, so the oldest message it can read is not the channel’s first.
inviter_npub
An invite’s creator as an npub: Joins name it in hex, older ones in bech32.
is_realtime_fresh
Whether an inner send time is fresh enough to surface as REALTIME. The live subscriptions are limit-0 (never history), but a relay backfilling from a peer ACCEPTS old events as new writes and pushes them to matching live subs — without this gate a month-old join or mention surfaces as if it just happened (bots welcome long-gone joiners, answer stale mentions). Gates only the “new” surfaces (is_new, bot events, pings); folding and persistence are NEVER gated on freshness.
reached_history_start
Dedupe (order-preserving) + truncate a relay set to MAX_COMMUNITY_RELAYS. Dedup first so the cap means “up to 5 DISTINCT relays” — a bundle padding one relay 5× can’t waste the budget. Whether an older page asked from before_secs reached the channel’s start: the relays answered, brought nothing this device lacked, left no cursor to go on from, and nothing held lies below the cursor. Relays serve the cursor’s own second again, so a page of only held messages can still be the end.