mirror of
https://github.com/block/buzz.git
synced 2026-11-30 21:21:48 +00:00
docs(nips): add nip-sl send later and nip-fi deferred actions (#9912)
## Summary Adds NIP-SL (Send Later) and a "Deferred actions" section to NIP-FI. This change is specification only: the relay, schema and clients are untouched. **NIP-SL** - An author signs an ordinary message dated for its release time `T` and submits it inside a private, author-signed instruction (`kind:30360`). The relay stores the message as an ordinary event between `T` and `T + release_window`, so the timestamp rule and the signer rule stay as they are. - The relay reports how the send ended in an author-only status (`kind:30361`) signed with its NIP-11 `self` key: `sent`, `failed`, `missed` or `cancelled`. - Edit, change the time, send now and cancel are replacements of the instruction under a generation compare-and-swap. Release and cancel are one conditional change, so a confirmed cancel is never followed by a post. - NIP-11 discovery through `supported_extensions` (`buzz-send-later`) and a `send_later` descriptor that carries the limits. Recommended limits: 120 days ahead, 100 pending per author per community, a 900 second release window, 7 days of text retention for failed or missed sends, 30 days of status retention. - The document also specifies the acceptance checks with their `OK` messages, the events that end a send early (ban, disconnect, channel deletion, operator withdrawal), retention, read access and the complete read a client derives state from. **NIP-FI** - A relay that stores actions it executes without a live session writes a disconnect record for each disconnect command and cancels the pending actions whose admission the record fences, in one atomic change, before it closes a connection or answers `200`. The record carries the command's scope, and each action stores the issuer, owner and verified `iat` of its admitting assertion, so a `revoke_through` cutoff applies to pending actions as it does to sessions. - A command answered `503`, or not answered, is retried with a freshly signed command. The deny set is unchanged. - A relay accepts no deferred action while a process that answers disconnect commands for the same storage does not apply the section. **Design choices worth a reviewer's eye** - Both kinds are readable only by the author. The owner of an agent cannot read the agent's instructions or statuses. A pending message is stored in the clear, as a posted one is. - Each send stores the owner verified at acceptance, and release uses it, because there is no request at release to take an owner from. - A relay keeps at most `max_pending` ended instructions per author, so the instruction read fits in one request. Past that bound, the text of a failed send or the record of an author's own cancel can be deleted before its retention period ends. - A disconnect covers the target key and every agent key it owns. Nothing else in NIP-FI ends an accepted send, and release does not evaluate issuer policy again. - A released message carries `created_at` `T` and can arrive up to `release_window` later. A reader whose read state is a `created_at` frontier displays it and counts it as read; the document states this limitation and what read state removes it. - Channels, threads and DMs of the listed kinds are in scope. Forum posts and recurring sends are left for later work. **Follow-up** - Relay implementation, including registration of kinds 30360 and 30361 in the kind registry and removal of the unused placeholder kinds 40006 and 40007 from ingest. - Client implementation. ### Related issue The "Deferred actions" section builds on the disconnect contract of #9860 (retry with a freshly signed command) and #9917 (`revoke_through` and "Deny scope"), both on main. ### Testing Documentation only. `git diff --check` passes, every section link in NIP-SL resolves to a heading, the link to "Deferred actions" in NIP-FI resolves, and kinds 30360 and 30361 are unused in `crates/buzz-core/src/kind.rs`. To review: read `docs/nips/NIP-SL.md` top to bottom, then the "Deferred actions" section of `docs/nips/NIP-FI.md`. --------- Signed-off-by: Kalvin Chau <kalvin@block.xyz> Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
@@ -20,7 +20,8 @@ of possession of that key. No relay-side identity state is required. The
|
||||
relay verifies the assertion offline against configured per-issuer JWKS
|
||||
snapshots and enforces the resolved community's audience and issuer
|
||||
authorization policy; other identity decisions remain the assertion issuer's
|
||||
responsibility.
|
||||
responsibility. A relay that executes deferred actions also keeps durable
|
||||
disconnect records (see Deferred actions).
|
||||
|
||||
This NIP defines the assertion contract, the offline verification procedure,
|
||||
session lifetime policy, and an authenticated issuer→relay disconnect API.
|
||||
@@ -520,6 +521,69 @@ specified below is the recovery path for lost propagation, exactly as for relay
|
||||
restart. A success response from the receiving process does not imply
|
||||
cluster-wide application.
|
||||
|
||||
### Deferred actions
|
||||
|
||||
A **deferred action** is something a relay accepts from an admitted session or
|
||||
request and carries out later, when the acting key may have no session at all.
|
||||
A pending send (NIP-SL) is one. Closing sessions and denying admission do not
|
||||
stop it. So a relay with deferred actions also records each disconnect in the
|
||||
durable storage that holds those actions, which all of its processes share.
|
||||
The deny set itself is unchanged.
|
||||
|
||||
A relay that executes deferred actions MUST apply this section. It MUST NOT
|
||||
accept a deferred action while a process that answers disconnect commands for
|
||||
the same storage does not apply it: that process would answer `200` and cancel
|
||||
nothing. Before such a process runs again, as in a rollback, the operator
|
||||
MUST end every pending deferred action.
|
||||
|
||||
With each deferred action it accepts, the relay MUST store the issuer, the
|
||||
owner, if any, and the verified `iat` of the admission that carried it, so that
|
||||
a disconnect command can match on them in its atomic change.
|
||||
|
||||
A **disconnect record** holds a command's `iss`, `target_pubkey`, `until` and
|
||||
scope (see Deny scope), and `recorded_at`, the time the relay wrote it. The
|
||||
record **fences** an admission when all of these hold:
|
||||
|
||||
- The record's issuer made the admission.
|
||||
- The admission's proven key or recorded owner is the record's target pubkey.
|
||||
- The record's scope covers the admitting assertion.
|
||||
- The admission happened at or before `recorded_at`, or before `until`.
|
||||
The relay MUST read both admission times and `recorded_at` from one clock,
|
||||
that of the durable storage, so that skew between processes cannot leave an
|
||||
admission unfenced. A pending action was stored before `recorded_at`, so
|
||||
this holds for it without a stored admission time.
|
||||
|
||||
When a command passes step 7 of `VerifyCommandJwt`, the relay MUST commit one
|
||||
atomic change to that storage before it closes a connection or answers `200`.
|
||||
The change:
|
||||
|
||||
1. Writes the command's disconnect record.
|
||||
2. Cancels every pending deferred action, in every community, whose admission
|
||||
the record fences.
|
||||
|
||||
If the change does not commit, or would exceed a bound below, the relay MUST
|
||||
reject the command `503` and close no session. An issuer that gets this `503`,
|
||||
or no answer, retries with a freshly signed command (new `jti`), because the
|
||||
`jti` and the deny entry of step 7 may already be recorded. The retry is a
|
||||
command like any other and writes its own record, with its own `recorded_at`.
|
||||
A command has taken full effect only when the relay answers `200`.
|
||||
|
||||
The relay MUST bound the disconnect records it keeps per issuer, independently
|
||||
of the deny set bound and of other issuers. With a maximum connection lifetime
|
||||
`L`, it MUST keep a record until `max(recorded_at, until) + L`, unless a
|
||||
record it keeps fences every admission this one fences.
|
||||
|
||||
While it keeps a record, the relay MUST refuse a deferred action from an
|
||||
admission the record fences with `authorization_denied`. Every relay process
|
||||
MUST make that decision against the durable records, in the same atomic change
|
||||
that stores the action, and MUST serialize that change against the change of
|
||||
every disconnect command whose record fences the admission. An acceptance
|
||||
therefore either commits first, and the command cancels it, or commits second,
|
||||
and finds the record.
|
||||
|
||||
A cancelled deferred action stays cancelled: a later assertion for the same key
|
||||
does not restore it. [FI-TRACE-DEFERRED-ACTIONS]
|
||||
|
||||
### Transport
|
||||
|
||||
The disconnect endpoint is an authenticated issuer→relay API, not a public
|
||||
@@ -635,7 +699,7 @@ VerifyCommandJwt(token, request_method, request_path, request_body_pubkey):
|
||||
```
|
||||
|
||||
Any failure at any step is fail-closed: no sessions are closed and the relay
|
||||
returns the appropriate error. Only an unknown shared-storage outcome, described below, can leave state behind.
|
||||
returns the appropriate error. Only an unknown shared-storage outcome, described below, or a disconnect record that does not commit (see Deferred actions) can leave state behind.
|
||||
|
||||
### Request
|
||||
|
||||
@@ -653,7 +717,10 @@ performs all pure authorization checks and then, as its single atomic admission
|
||||
mutation (step 7), simultaneously reserves the `(iss, jti)` replay identity and
|
||||
inserts the deny entry — both or neither. A capacity failure at that step rejects
|
||||
`503`; neither the jti nor the deny entry is recorded, and the caller may safely
|
||||
retry the same signed command. A relay that keeps the deny set in shared storage and cannot learn whether its write applied MUST reject `503` `authorization_unavailable` and close no sessions. The `jti` and deny entry may already be recorded, so the caller retries with a freshly signed command (new `jti`), not the same one. On success, the relay MUST close every live connection
|
||||
retry the same signed command. A relay that keeps the deny set in shared storage and cannot learn whether its write applied MUST reject `503` `authorization_unavailable` and close no sessions. The `jti` and deny entry may already be recorded, so the caller retries with a freshly signed command (new `jti`), not the same one.
|
||||
After step 7 succeeds, a relay that executes deferred actions commits the
|
||||
change "Deferred actions" specifies before it closes any connection. On
|
||||
success, the relay MUST close every live connection
|
||||
registered under the command's issuer (`claims.iss`) whose proven key equals
|
||||
`CommandResult.target_pubkey` or whose recorded owner equals
|
||||
`CommandResult.target_pubkey`, and whose admitting assertion falls in the
|
||||
@@ -679,6 +746,7 @@ under the merge rule.
|
||||
| Malformed request body or `until` exceeds ceiling | `400` | `bad request\n` |
|
||||
| Deny set at capacity | `503` | `deny set full\n` |
|
||||
| Shared deny storage outcome unknown | `503` | `authorization unavailable\n` |
|
||||
| Disconnect record not committed or at capacity (Deferred actions) | `503` | `disconnect not recorded\n` |
|
||||
|
||||
## HTTP ingress
|
||||
|
||||
@@ -1020,6 +1088,7 @@ deployment-local identifiers. [FI-TRACE-DISCOVERY-PRIVATE]
|
||||
| `FI-TRACE-DEPENDENCY-FAIL-CLOSED` | An unreadable JWKS snapshot denies `authorization_unavailable`; no degraded Nostr-only access. |
|
||||
| `FI-TRACE-LEASE-BOUND` | A session closes at its earliest deadline; equality at any deadline is expired. |
|
||||
| `FI-TRACE-DENY-SET` | A pubkey in the deny set is denied `authorization_denied` on admission until `now >= until` when the entry covers the assertion — a whole-key entry covers every assertion, a cutoff entry only those with verified `iat <= C`, so `iat = C` denies and `iat = C + 0.5` admits; an expired or absent entry does not deny; a disconnect with C closes only sessions with `iat <= C`, and a session with `iat > C` survives every redelivery unless a stronger active merged entry widens the close scope (see Deny scope); a whole-key entry beats a same-deadline cutoff and the later of two cutoffs wins, in either order; an entry that expires before a merge is applied contributes nothing to it; a past-`until` command performs its scoped close — absent an active same-key entry it creates no future denial, while an active entry remains unchanged under the merge rule; a deny-set-full command is rejected `503` without closing sessions and without removing any existing entry; capacity is evaluated per issuer — one issuer's capacity exhaustion MUST NOT reject another issuer's command; a connection within the effective close scope that passes the deny-set check before a concurrent deny-entry insertion but completes admission after MUST still be terminated (the session's proven `k` and admitting issuer are registered before the deny-set check, ensuring the close scan catches it); a registered-but-not-admitted connection caught by the close scan MUST be cancelled terminally and MUST NOT later be admitted; a disconnect command from one issuer MUST NOT close a same-key connection registered under a different issuer, whether or not admission has completed; two overlapping commands for the same `(iss, pubkey)` in either delivery order result in `until = max(until_A, until_B)` — delivery order does not shorten the longer deny; a past-`until` command arriving over an active entry leaves the active entry's `until` unchanged; a successful disconnect responds `{"disconnected": true}` regardless of how many sessions were closed; the deny entry applies across all communities served by the relay under that issuer. |
|
||||
| `FI-TRACE-DEFERRED-ACTIONS` | A relay that executes deferred actions commits a disconnect record and the cancellation of every pending deferred action whose admission the record fences, across all communities, before it closes a connection or answers `200`; a command whose change does not commit, or that would exceed the per-issuer bound on disconnect records, is rejected `503` with no connection closed and nothing cancelled, and a freshly signed command then succeeds; a freshly signed retry of a command whose change committed on a relay that stopped before its answer writes its own record, closes the matching connections and is answered `200`; a deferred action is not accepted while a process that answers disconnect commands for the same storage does not apply this section; admission times and `recorded_at` are read from the clock of the durable storage; a deferred action of an agent whose recorded owner is the target is cancelled; a deferred action accepted under another issuer is not cancelled; under a cutoff C, a deferred action whose admitting assertion has `iat = C` is cancelled and refused, and one with `iat = C + 0.5` is neither; a deferred action is refused `authorization_denied` when its admission is fenced, including on a process that never received the session close and after a relay restart; an admission after both `recorded_at` and `until` is not fenced; an acceptance that races a command is either cancelled by it or refused, never left pending; a record is retained until `max(recorded_at, until)` plus the maximum connection lifetime, unless a record the relay keeps fences every admission it fences; a cancelled deferred action is not restored by a later assertion. |
|
||||
| `FI-TRACE-HTTP-INGRESS` | A protected HTTP request with both valid headers and matching pubkeys is admitted; absent, mismatched, or invalid assertion or NIP-98 event denies; a request presenting only one of the two denies; an active deny-set entry that covers the assertion denies; a route that cannot be classified as exempt is treated as protected; repeated, comma-combined, wrong-scheme, or alternative-credential `Authorization` fields deny `evidence_rejected`; a missing `Authorization` field denies `missing_evidence`; an authorization-relevant body without exactly one matching `payload` tag denies; the NIP-FI administrative API is not a protected surface. For kind-24242 (Blossom) proofs on media routes: a `t=upload` proof with valid `x`, `server`, `expiration`, and freshness is admitted on `PUT /upload`; a `t=get` proof with valid `server`, `expiration`, and freshness is admitted on `GET\|HEAD /media/{hash…}`; a kind-24242 proof on any other route denies; an upload proof with absent or mismatched `server` tag denies; a read proof with absent or mismatched `server` tag denies; a proof with a duplicate, missing, or out-of-range `expiration` tag denies; a proof dated more than 120 seconds in the future denies; a proof older than 120 seconds denies; key mismatch between assertion `nostr_pubkey` and the kind-24242 event pubkey denies; an active deny-set entry that covers the assertion denies. |
|
||||
| `FI-TRACE-DENIAL-ORACLE` | Each public-class row produces its exact fixed bytes; all private-state rows compare byte-identical. |
|
||||
| `FI-TRACE-DISCOVERY-PRIVATE` | Complete discovery bytes do not expose issuer, audience, or deployment-private state. |
|
||||
@@ -1081,6 +1150,16 @@ attempt, the residual exposure after restart is bounded by
|
||||
continues issuing or re-push does not complete in time, that formula does
|
||||
not apply and access may continue beyond it.
|
||||
|
||||
**Deferred actions.** A deferred action executes with no live session, so
|
||||
session expiry never stops it. Under this NIP only a disconnect command does:
|
||||
the durable record cancels the matching actions and fences the admissions the
|
||||
command covers, in every relay process and across restarts. An issuer that
|
||||
only stops issuing assertions leaves every accepted deferred action in place
|
||||
for as long as it can stay pending. A deployment that enables deferred actions
|
||||
in a community that requires NIP-FI MUST have each authorized issuer send a
|
||||
disconnect command when an identity loses access. A community ban of the key
|
||||
remains available to the relay operator.
|
||||
|
||||
**HTTP ingress bypass.** Without the pairing rule, a principal holding an
|
||||
active key can mint fresh NIP-98 events indefinitely and retain HTTP access
|
||||
for as long as the key remains accepted — the assertion TTL provides no
|
||||
|
||||
303
docs/nips/NIP-SL.md
Normal file
303
docs/nips/NIP-SL.md
Normal file
@@ -0,0 +1,303 @@
|
||||
NIP-SL
|
||||
======
|
||||
|
||||
Send Later
|
||||
----------
|
||||
|
||||
`draft` `optional` `relay`
|
||||
|
||||
This NIP lets an author write a message now and have the relay post it later, while the author's devices are offline. The client signs the message ahead of time and dates it `T`, the moment it should post, then gives it to the relay inside a private instruction. At `T` the relay checks that the author may still post, stores the message like any other, and tells the author how the send ended.
|
||||
|
||||
The relay never holds the author's key. It posts the message inside the `created_at` window it already allows for any event, so the signing rule and the timestamp rule do not change. Readers get an ordinary event and cannot tell that it was sent later.
|
||||
|
||||
Recurring sends, forum posts and [NIP-17](17.md) gift wraps are out of scope. There is no time lock: the relay can read a message as soon as it accepts the instruction.
|
||||
|
||||
## Kinds
|
||||
|
||||
| Kind | Name | Signer | Purpose |
|
||||
|------|------|--------|---------|
|
||||
| `30360` | Instruction | author | Holds one message to post later, or cancels it |
|
||||
| `30361` | Status | relay | Tells the author how a send ended |
|
||||
|
||||
Both kinds are addressable, and only the author can read them. A **send** is one message waiting to be posted, and its address is `(author pubkey, 30360, d)`. A send is **pending** until it **ends** as sent, failed, missed or cancelled. Once it has ended it never becomes pending again.
|
||||
|
||||
## Instruction
|
||||
|
||||
```jsonc
|
||||
{
|
||||
"kind": 30360,
|
||||
"pubkey": "<author>",
|
||||
"created_at": 1769990000,
|
||||
"content": "<the signed message, as JSON>",
|
||||
"tags": [
|
||||
["d", "a3f8c2e1b4d79600e5d2f1a8c3b6094d"],
|
||||
["not_before", "1770000000"],
|
||||
["generation", "1"]
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
- `d` is the send id. It MUST be 16 bytes from a cryptographically secure random source, written as 32 lowercase hex characters. It MUST NOT be derived from the message, the channel or the time.
|
||||
- `not_before` is `T`, a Unix timestamp in the format [NIP-ER](NIP-ER.md) defines for this tag.
|
||||
- `generation` is the version of the send, in the same format. It starts at `1`.
|
||||
|
||||
An instruction MUST have each of these tags exactly once, with one value. It MAY also have one `alt` tag ([NIP-31](31.md)). Any other tag makes it malformed, so no channel, mention or thread query can match an instruction.
|
||||
|
||||
`content` MUST be the signed message: one JSON object with exactly the members `id`, `pubkey`, `created_at`, `kind`, `tags`, `content` and `sig`. A missing, extra or repeated member is invalid.
|
||||
|
||||
The message MUST pass all of these:
|
||||
|
||||
1. Its `id` and `sig` verify.
|
||||
2. Its `pubkey` is the instruction's `pubkey`.
|
||||
3. Its `created_at` equals `not_before` exactly.
|
||||
4. Its `kind` is one the relay lists ([Support](#support)).
|
||||
5. It has exactly one `h` tag, which names a channel of the community the instruction was sent to.
|
||||
|
||||
Apart from that it is an ordinary event of its kind. A thread reply, a message in a DM, a mention, an attachment and an agent's [NIP-OA](NIP-OA.md) `auth` tag all look as they would if the author posted the message live.
|
||||
|
||||
### Cancel
|
||||
|
||||
```jsonc
|
||||
{ "kind": 30360, "content": "", "tags": [["d", "<send id>"], ["generation", "3"]] }
|
||||
```
|
||||
|
||||
A cancel MUST have exactly one `d` and one `generation` tag, at most one `alt`, no other tag, and empty `content`.
|
||||
|
||||
## Changing a send
|
||||
|
||||
The first instruction at an address MUST hold a message and have `generation` `1`. Every later one MUST have the stored generation plus one. It MUST also win [NIP-01](01.md) ordering against the stored one: a greater `created_at`, or the same `created_at` and a lower `id`. If two devices change the same generation, only one succeeds. A client sets `created_at` to its current time, or to the stored `created_at` plus one if that is later.
|
||||
|
||||
A client changes a pending send by publishing the next generation:
|
||||
|
||||
- To edit it or change its time: a newly signed message.
|
||||
- To send it now: `not_before` set to the current time, and the message signed for that time.
|
||||
- To cancel it: a cancel, which ends the send.
|
||||
|
||||
A client MUST NOT publish the message directly while its send is pending.
|
||||
|
||||
Once a send has ended, its address is closed. The relay MUST refuse every later instruction there for at least `status_retention` after the send ended, and for as long as it stores a status or a cancel for the address. A new attempt uses a fresh `d`.
|
||||
|
||||
[NIP-09](09.md) does not apply to `kind:30360`. A relay MUST NOT delete an instruction or change a send because of a deletion request, and SHOULD reject a request that names a `kind:30360` event or address.
|
||||
|
||||
## Relay behavior
|
||||
|
||||
### Acceptance checks
|
||||
|
||||
The relay accepts an instruction wherever it authenticates the sender, such as a [NIP-42](42.md) session. It runs these checks in order, and the first one that fails decides the answer. A relay MAY add detail after the `OK` text shown, so clients match only up to the end of it.
|
||||
|
||||
| # | Check | `OK` when it fails |
|
||||
|---|-------|--------------------|
|
||||
| 1 | The sender is authenticated as the event's `pubkey`, and `id` and `sig` verify | as for any event |
|
||||
| 2 | The event is not the instruction already stored at its address | `true`, `duplicate: already have this event` |
|
||||
| 3 | `created_at` is within the relay's usual tolerance | as for any event |
|
||||
| 4 | The tags are those of an instruction or a cancel, and `content` is at most `max_content_len` bytes | `invalid: malformed not_before`, otherwise `invalid: malformed instruction` |
|
||||
| 5 | The address is not closed | `invalid: send ended` |
|
||||
| 6 | The generation and ordering rules hold, and a cancel names an existing send | `invalid: stale generation`, `invalid: stale replacement`, `invalid: no such send` |
|
||||
| 7 | A cancel that passes check 12 is accepted here. The remaining checks apply only to an instruction that holds a message | |
|
||||
| 8 | The relay is accepting instructions that hold a message: new sends and replacements | `restricted: send later disabled` |
|
||||
| 9 | `now - 60 <= T` and `T <= now + max_not_before_delta` | `invalid: not_before in the past`, `invalid: not_before too far` |
|
||||
| 10 | `content` and the message meet [Instruction](#instruction), and the message passes the relay's validity checks for an ordinary event of its kind, apart from the `created_at` tolerance | `invalid: message: <reason>` |
|
||||
| 11 | The author may post the message to its channel now: membership, permission to post, channel state, bans and timeouts | `restricted: message: <reason>` |
|
||||
| 12 | Under NIP-FI, no disconnect record fences the admission that carried the instruction ([Federated identity](#federated-identity)) | `restricted: authorization denied` |
|
||||
| 13 | For a new address, the author has fewer than `max_pending` pending sends in the community | `restricted: send later quota exceeded` |
|
||||
|
||||
A relay MUST NOT refuse a cancel because check 8, a timeout or a lost permission to post would refuse a message. `max_pending` is counted separately for each author key in each community, and an agent's sends count against the agent's own key.
|
||||
|
||||
The relay stores an accepted instruction, its generation and the state of the send in one atomic change, and checks 5, 6, 12 and 13 MUST run inside it. A refused instruction MUST change nothing. Once a generation is replaced, the relay MUST NOT release it or keep it readable.
|
||||
|
||||
With each generation the relay MUST also store the owner it verified for the author at acceptance, if any. There is no request at release to take an owner from, so release, the `banned` cancel and the timeout check use the stored one. A NIP-OA `auth` tag on the message MUST be valid with its `created_at` condition evaluated against `T`, at acceptance and again at release.
|
||||
|
||||
A relay that does not know whether it stored an instruction, as after a storage error, MUST answer `error:`. A client that gets `error:` or no `OK` MUST NOT assume either outcome, and sends the same event again. Only `OK true` settles an instruction as accepted. After any other answer the client makes a [complete read](#complete-read). Before it creates a new send to replace one that is not settled, it MUST check that the message is not readable in its channel.
|
||||
|
||||
### Release
|
||||
|
||||
1. The relay MUST NOT store, deliver or return the message before its clock reads `T`.
|
||||
2. At release it MUST apply every check it would apply if the author posted the message at that moment on an authenticated session: membership, permission to post, channel state, bans, timeouts, attachments, content rules and the author's rate limit. It skips only the proof of a live session, and takes the author's owner from the send.
|
||||
3. It MUST store the message and mark the send `sent` in one atomic change, and that change MUST apply only if the send is still pending at the generation being released. A replacement or a cancel therefore either commits first, and the old message is never posted, or is refused with `invalid: send ended`. A relay MUST NOT answer `OK true` to a cancel and then post the message.
|
||||
4. It then does everything it does for a message posted live: delivery, push, mentions, thread counters and search. The stored event is the author's signed event, unchanged.
|
||||
|
||||
A refusal listed under `failed` in [Status](#status) ends the send at once, even one that would clear inside the window, as a timeout can. The relay tries again only after a rate limit or a transient error. The relay MUST NOT release after `T + release_window`: a send that is still pending then ends as `missed`. If the message is already stored at release, the send ends as `sent` with that event's id.
|
||||
|
||||
A relay SHOULD release as soon after `T` as its checks allow. It MAY spread out sends that share one `T`, but SHOULD NOT use the rest of the window to delay a release it could make. Clients MUST NOT assume that a message posts at exactly `T`.
|
||||
|
||||
## Status
|
||||
|
||||
When a send ends, the relay publishes one status. The exception is the author's own cancel, where the cancel is the record.
|
||||
|
||||
```jsonc
|
||||
{
|
||||
"kind": 30361,
|
||||
"pubkey": "<relay key>",
|
||||
"created_at": 1770000004,
|
||||
"content": "",
|
||||
"tags": [
|
||||
["d", "<author pubkey>:<send id>"],
|
||||
["p", "<author pubkey>"],
|
||||
["status", "sent"],
|
||||
["generation", "2"],
|
||||
["e", "<message id>"],
|
||||
["expiration", "1772592004"]
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
- `d` is the author's pubkey in lowercase hex, a colon and the send id.
|
||||
- `generation` is the generation that ended.
|
||||
- `e` is present only for `sent`, and holds the id of the stored message.
|
||||
- `expiration` ([NIP-40](40.md)) is `created_at + status_retention`.
|
||||
- `created_at` is the relay's clock when it signs, never earlier than the end of the send.
|
||||
|
||||
| `status` | `reason` | The send ends this way when |
|
||||
|----------|----------|-----------------------------|
|
||||
| `sent` | | The message is stored |
|
||||
| `missed` | | It was not released by `T + release_window` |
|
||||
| `failed` | `not_permitted` | At release, the author is no longer in the channel or the community, or may not post to the channel |
|
||||
| `failed` | `restricted` | At release, the author or the author's owner is under a timeout in the community |
|
||||
| `failed` | `archived` | At release, the channel is archived |
|
||||
| `failed` | `attachment` | At release, an attachment is no longer available |
|
||||
| `failed` | `rejected` | Release is refused for good for any other reason |
|
||||
| `cancelled` | `banned` | The author or the author's owner is banned in the community |
|
||||
| `cancelled` | `disconnected` | A NIP-FI disconnect record fences the admission that carried the send ([Federated identity](#federated-identity)) |
|
||||
| `cancelled` | `channel_deleted` | The channel is deleted |
|
||||
| `cancelled` | `withdrawn` | The relay operator ends the send before a version change that could not keep it |
|
||||
|
||||
The relay cancels a send in the same atomic change that records the ban, the disconnect or the channel deletion. For a disconnect, that is before it answers the issuer. It MUST apply the `banned` and `channel_deleted` rows again at release, which catches an instruction that was being accepted while the ban or the deletion was recorded. An owner here is the owner stored with the send ([Acceptance checks](#acceptance-checks)).
|
||||
|
||||
A cancelled send stays cancelled: lifting a ban or restoring access MUST NOT make it pending again. Deleting an account or a community removes its sends along with the other data, and the relay publishes no status for them.
|
||||
|
||||
A relay SHOULD include `reason` for `failed` and `cancelled`, and MUST omit it otherwise. Clients MUST treat a code they do not know as no reason.
|
||||
|
||||
A send has at most one status, and the relay MUST NOT revise it. A relay SHOULD store the status in the atomic change that ends the send. If it stores the status afterwards, it MUST record the outcome durably in that change, MUST sign the status when it stores it, and MUST keep trying until the status is stored.
|
||||
|
||||
The relay signs a status with its [NIP-11](11.md) `self` key, and MUST reject a `kind:30361` event that a client submits. Clients MUST accept a status only when its `pubkey` is that key.
|
||||
|
||||
## Reading
|
||||
|
||||
A relay MUST NOT reveal the existence, count, tags, content, time or search matches of either kind to anyone but the author. This holds on every read path: `REQ`, `COUNT`, live subscriptions, lookups by id, search, HTTP bridges and push.
|
||||
|
||||
- `kind:30360` is readable only by a requester authenticated as the event's `pubkey`.
|
||||
- `kind:30361` is readable only by a requester authenticated as the pubkey in its `p` tag.
|
||||
- The owner of an agent cannot read the agent's instructions or statuses.
|
||||
- A relay SHOULD close an unauthenticated request that asks only for these kinds with `auth-required:`. When a filter mixes them with other kinds, it MUST omit what the requester may not read.
|
||||
|
||||
A client follows its sends with one live subscription. After its `EOSE`, the relay MUST deliver to it every instruction it accepts and every status it stores.
|
||||
|
||||
```jsonc
|
||||
["REQ", "send-later",
|
||||
{ "kinds": [30360], "authors": ["<own pubkey>"] },
|
||||
{ "kinds": [30361], "#p": ["<own pubkey>"] }]
|
||||
```
|
||||
|
||||
### Complete read
|
||||
|
||||
The relay's default limit can cut the stored events of that subscription short. An instruction also carries its author's clock, so a `since` cursor can miss an edit made on another device. A client therefore MUST NOT refresh `kind:30360` with `since`.
|
||||
|
||||
Instead it derives state from a complete read after each reconnect: two requests, made as the author, with no `since` or `until`. It sends them after the `EOSE` of the live subscription and keeps that subscription open.
|
||||
|
||||
1. Instructions: `{"kinds": [30360], "authors": ["<own pubkey>"], "limit": <max_limit>}`, with the relay's NIP-11 `max_limit`.
|
||||
2. Statuses: `{"kinds": [30361], "#p": ["<own pubkey>"], "#d": [<status d values>], "limit": <number of values>}`, split so that no request has more than `max_limit` values. The values name every send the client holds as pending or as ended with an unknown outcome, and every send for which request 1 returned an instruction that holds a message.
|
||||
|
||||
An event that arrives on the live subscription before the read ends counts as returned. Of two instructions for one address, the client keeps the one that wins NIP-01 ordering. Then, for each send that request 2 names or whose cancel request 1 returned, the first rule that applies gives its state:
|
||||
|
||||
1. A status was returned: the send ended as the status says.
|
||||
2. An instruction was returned: the send is pending if the instruction holds a message, and cancelled by the author if it is a cancel.
|
||||
3. Neither was returned: the send is not pending and its outcome is unknown. The client MUST NOT show it as sent or as cancelled. It MAY drop a send that has stayed under this rule for `status_retention`.
|
||||
|
||||
The relay MUST return every event that matches either request, without paging. [Retention](#retention) keeps request 1 within `max_limit`. The relay MUST answer each request from one consistent view of its storage, so that a replacement in progress cannot hide a pending send. Once a send has ended, the relay MUST NOT serve the instruction that holds its message unless the send's status is readable.
|
||||
|
||||
### Other reads
|
||||
|
||||
Any other read updates only the sends whose events it returns. A read that failed, was closed, came back incomplete or was not authenticated is not evidence of a state. Neither is a lost connection or a live update that never came. A client MUST NOT infer an outcome from any of them.
|
||||
|
||||
The relay deletes the instruction of a `sent` or relay-cancelled send without publishing an event, so a client's copy can be out of date until the status arrives. Before it does, `invalid: send ended` in answer to an edit or a cancel means that the send is not pending and its outcome is unknown, and the message being readable in its channel means `sent`. A client treats a send as cancelled only after it gets `OK true` for its cancel. On `invalid: stale generation` or `invalid: stale replacement`, another device has changed the send, so the client reads the address again.
|
||||
|
||||
## Retention
|
||||
|
||||
| Send ended as | Instruction | Status |
|
||||
|---------------|-------------|--------|
|
||||
| `sent`, or `cancelled` by the relay | Deleted when the send ends | Readable for `status_retention` |
|
||||
| `failed`, `missed` | Readable to the author for `text_retention` after the status is stored, then deleted | Readable for `status_retention` |
|
||||
| Cancelled by the author | The cancel replaces the instruction it cancels, which is deleted. The cancel is readable for `status_retention`, then deleted | none |
|
||||
|
||||
Deleting an instruction means that the relay no longer stores the message it held in any form.
|
||||
|
||||
A relay MUST keep at most `max_pending` ended instructions for one author in a community. Cancels and the instructions of `failed` and `missed` sends count together. When the end of a send would take the author past that number, the relay first deletes the ended instruction whose send ended earliest. Its address stays closed. If it held the text of a `failed` or `missed` send, the author loses that text early. If it was a cancel, a complete read then reports that send under rule 3.
|
||||
|
||||
So one request can return all of an author's instructions in a community: at most `max_pending` pending and as many ended. A relay MUST advertise a NIP-11 `max_limit` of at least twice `max_pending`, and MUST NOT change either limit in a way that lets those instructions exceed `max_limit`.
|
||||
|
||||
## Support
|
||||
|
||||
Until this draft has an upstream NIP number, relays MUST NOT list it in [NIP-11](11.md) `supported_nips`. A relay advertises send later for the community that a NIP-11 request resolves to, with `"buzz-send-later"` in `supported_extensions` and this descriptor:
|
||||
|
||||
```jsonc
|
||||
{
|
||||
"supported_extensions": ["buzz-send-later"],
|
||||
"send_later": {
|
||||
"v": 1,
|
||||
"accepting": true,
|
||||
"kinds": [9],
|
||||
"limitation": {
|
||||
"max_not_before_delta": 10368000,
|
||||
"max_pending": 100,
|
||||
"release_window": 900,
|
||||
"text_retention": 604800,
|
||||
"status_retention": 2592000,
|
||||
"max_content_len": 524288
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
| Member | Meaning |
|
||||
|--------|---------|
|
||||
| `v` | Version of this contract. This document defines `1` |
|
||||
| `accepting` | `true` when the relay accepts instructions that hold a message: new sends and replacements. When `false` it accepts only cancels and reads |
|
||||
| `kinds` | The kinds a message may have |
|
||||
| `limitation` | The limits in [Limits summary](#limits-summary), each a positive integer. A relay MUST enforce the limits it advertises |
|
||||
|
||||
A relay that hosts several communities MUST serve the descriptor only for a community in which send later is enabled.
|
||||
|
||||
A client MUST treat the descriptor as absent in any of these cases:
|
||||
|
||||
- `supported_extensions` does not contain `"buzz-send-later"`.
|
||||
- `v` is not `1`.
|
||||
- `v`, `accepting`, `kinds`, `limitation` or a limit in [Limits summary](#limits-summary) is missing or has the wrong type.
|
||||
|
||||
Without a valid descriptor a client MUST NOT publish `kind:30360` and MUST NOT offer send later. A relay that does not implement this NIP may store both kinds as ordinary events that any reader can query.
|
||||
|
||||
A client offers send later only while `accepting` is `true`, and keeps `T` and its number of pending sends inside the limits. If the relay stops serving a valid descriptor, the client treats the state of its pending sends as unknown and reads again when the descriptor returns.
|
||||
|
||||
## Late arrival
|
||||
|
||||
A released message carries `created_at` `T` but can reach readers up to `release_window` later. A reader that opens a live subscription or fetches new messages with `since` SHOULD therefore set it back by at least the relay's `created_at` tolerance, and discard by `id` the events it already holds.
|
||||
|
||||
That delivers a late message, but a reader that records a channel as read up to a `created_at` value still counts it as read. This NIP does not remove that limitation. The time or order in which one device received a message is not evidence that the message is unread, and a client MUST NOT substitute it. To count a late message as unread on every device of a user, those devices need shared read state that does not depend on `created_at`: an order that follows when the relay stored a message, or a complete record of the messages read by `id`. A client with such read state SHOULD count a late message as unread.
|
||||
|
||||
## Federated identity
|
||||
|
||||
In a community that requires NIP-FI, a send is a deferred action under [Deferred actions](NIP-FI.md#deferred-actions), because the relay releases it without a session. Each accepted generation is an acceptance of the deferred action, so the relay stores the admission that carried it. That section defines which sends a disconnect command cancels: those of the target key and of every key it owns, accepted under the command's issuer and within its scope, in every community. It also defines when check 12 refuses an instruction. A relay MUST NOT enable send later in such a community unless it implements that section.
|
||||
|
||||
Nothing else in NIP-FI ends an accepted send. At release the relay does not contact the issuer, require a recent assertion or evaluate the community's issuer policy again. An issuer that only stops issuing assertions does not stop a pending send.
|
||||
|
||||
## Security
|
||||
|
||||
The author trusts the relay with the signed message, which is a valid event from the moment it is signed. A relay that misbehaves can withhold it, or post it inside the timestamp window around `T` after a cancel. It cannot forge a message, change one, or post one at another time. Nothing revokes the signed message cryptographically, so a cancel holds only because the relay enforces it.
|
||||
|
||||
There is no session at release, so authority to post comes from the author's signatures. A `created_at` condition in an agent's NIP-OA `auth` tag is evaluated against `T`, so an owner's time bound on an agent also bounds how far ahead the agent can send. A [NIP-46](46.md) remote signer needs no delegation: it signs the message for `T` and signs the instruction. Signing takes time, so a client that sends now through a remote signer SHOULD expect `invalid: not_before in the past` and retry with a newly signed message.
|
||||
|
||||
A relay SHOULD count each instruction against the author's ordinary rate limit.
|
||||
|
||||
The relay stores a pending message in the clear, as it stores a posted one. Someone who can read the relay's storage can therefore read a send before it posts.
|
||||
|
||||
## Limits summary
|
||||
|
||||
The relay advertises these in `limitation` ([Support](#support)). Times are in seconds.
|
||||
|
||||
| Member | Limit | Recommended |
|
||||
|--------|-------|-------------|
|
||||
| `max_not_before_delta` | How far ahead `T` may be | 10368000 (120 days) |
|
||||
| `max_pending` | Pending sends for one author in a community, and ended instructions kept for that author | 100 |
|
||||
| `release_window` | How long after `T` the relay may still release. It MUST exceed 60 and MUST NOT exceed the relay's `created_at` tolerance for ordinary events | 900 |
|
||||
| `text_retention` | How long the instruction of a `failed` or `missed` send stays readable | 604800 (7 days) |
|
||||
| `status_retention` | How long a status stays readable. It MUST exceed `text_retention` | 2592000 (30 days) |
|
||||
| `max_content_len` | Maximum instruction `content`, in bytes. It SHOULD fit the largest message the relay accepts live | |
|
||||
Reference in New Issue
Block a user