Skip to content

Commit c2c11a4

Browse files
kalvinnchauclaude
andauthored
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>
1 parent e9fdd1a commit c2c11a4

2 files changed

Lines changed: 385 additions & 3 deletions

File tree

‎docs/nips/NIP-FI.md‎

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ of possession of that key. No relay-side identity state is required. The
2020
relay verifies the assertion offline against configured per-issuer JWKS
2121
snapshots and enforces the resolved community's audience and issuer
2222
authorization policy; other identity decisions remain the assertion issuer's
23-
responsibility.
23+
responsibility. A relay that executes deferred actions also keeps durable
24+
disconnect records (see Deferred actions).
2425

2526
This NIP defines the assertion contract, the offline verification procedure,
2627
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
520521
restart. A success response from the receiving process does not imply
521522
cluster-wide application.
522523

524+
### Deferred actions
525+
526+
A **deferred action** is something a relay accepts from an admitted session or
527+
request and carries out later, when the acting key may have no session at all.
528+
A pending send (NIP-SL) is one. Closing sessions and denying admission do not
529+
stop it. So a relay with deferred actions also records each disconnect in the
530+
durable storage that holds those actions, which all of its processes share.
531+
The deny set itself is unchanged.
532+
533+
A relay that executes deferred actions MUST apply this section. It MUST NOT
534+
accept a deferred action while a process that answers disconnect commands for
535+
the same storage does not apply it: that process would answer `200` and cancel
536+
nothing. Before such a process runs again, as in a rollback, the operator
537+
MUST end every pending deferred action.
538+
539+
With each deferred action it accepts, the relay MUST store the issuer, the
540+
owner, if any, and the verified `iat` of the admission that carried it, so that
541+
a disconnect command can match on them in its atomic change.
542+
543+
A **disconnect record** holds a command's `iss`, `target_pubkey`, `until` and
544+
scope (see Deny scope), and `recorded_at`, the time the relay wrote it. The
545+
record **fences** an admission when all of these hold:
546+
547+
- The record's issuer made the admission.
548+
- The admission's proven key or recorded owner is the record's target pubkey.
549+
- The record's scope covers the admitting assertion.
550+
- The admission happened at or before `recorded_at`, or before `until`.
551+
The relay MUST read both admission times and `recorded_at` from one clock,
552+
that of the durable storage, so that skew between processes cannot leave an
553+
admission unfenced. A pending action was stored before `recorded_at`, so
554+
this holds for it without a stored admission time.
555+
556+
When a command passes step 7 of `VerifyCommandJwt`, the relay MUST commit one
557+
atomic change to that storage before it closes a connection or answers `200`.
558+
The change:
559+
560+
1. Writes the command's disconnect record.
561+
2. Cancels every pending deferred action, in every community, whose admission
562+
the record fences.
563+
564+
If the change does not commit, or would exceed a bound below, the relay MUST
565+
reject the command `503` and close no session. An issuer that gets this `503`,
566+
or no answer, retries with a freshly signed command (new `jti`), because the
567+
`jti` and the deny entry of step 7 may already be recorded. The retry is a
568+
command like any other and writes its own record, with its own `recorded_at`.
569+
A command has taken full effect only when the relay answers `200`.
570+
571+
The relay MUST bound the disconnect records it keeps per issuer, independently
572+
of the deny set bound and of other issuers. With a maximum connection lifetime
573+
`L`, it MUST keep a record until `max(recorded_at, until) + L`, unless a
574+
record it keeps fences every admission this one fences.
575+
576+
While it keeps a record, the relay MUST refuse a deferred action from an
577+
admission the record fences with `authorization_denied`. Every relay process
578+
MUST make that decision against the durable records, in the same atomic change
579+
that stores the action, and MUST serialize that change against the change of
580+
every disconnect command whose record fences the admission. An acceptance
581+
therefore either commits first, and the command cancels it, or commits second,
582+
and finds the record.
583+
584+
A cancelled deferred action stays cancelled: a later assertion for the same key
585+
does not restore it. [FI-TRACE-DEFERRED-ACTIONS]
586+
523587
### Transport
524588

525589
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):
635699
```
636700

637701
Any failure at any step is fail-closed: no sessions are closed and the relay
638-
returns the appropriate error. Only an unknown shared-storage outcome, described below, can leave state behind.
702+
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.
639703

640704
### Request
641705

@@ -653,7 +717,10 @@ performs all pure authorization checks and then, as its single atomic admission
653717
mutation (step 7), simultaneously reserves the `(iss, jti)` replay identity and
654718
inserts the deny entry — both or neither. A capacity failure at that step rejects
655719
`503`; neither the jti nor the deny entry is recorded, and the caller may safely
656-
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
720+
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.
721+
After step 7 succeeds, a relay that executes deferred actions commits the
722+
change "Deferred actions" specifies before it closes any connection. On
723+
success, the relay MUST close every live connection
657724
registered under the command's issuer (`claims.iss`) whose proven key equals
658725
`CommandResult.target_pubkey` or whose recorded owner equals
659726
`CommandResult.target_pubkey`, and whose admitting assertion falls in the
@@ -679,6 +746,7 @@ under the merge rule.
679746
| Malformed request body or `until` exceeds ceiling | `400` | `bad request\n` |
680747
| Deny set at capacity | `503` | `deny set full\n` |
681748
| Shared deny storage outcome unknown | `503` | `authorization unavailable\n` |
749+
| Disconnect record not committed or at capacity (Deferred actions) | `503` | `disconnect not recorded\n` |
682750

683751
## HTTP ingress
684752

@@ -1020,6 +1088,7 @@ deployment-local identifiers. [FI-TRACE-DISCOVERY-PRIVATE]
10201088
| `FI-TRACE-DEPENDENCY-FAIL-CLOSED` | An unreadable JWKS snapshot denies `authorization_unavailable`; no degraded Nostr-only access. |
10211089
| `FI-TRACE-LEASE-BOUND` | A session closes at its earliest deadline; equality at any deadline is expired. |
10221090
| `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. |
1091+
| `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. |
10231092
| `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. |
10241093
| `FI-TRACE-DENIAL-ORACLE` | Each public-class row produces its exact fixed bytes; all private-state rows compare byte-identical. |
10251094
| `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
10811150
continues issuing or re-push does not complete in time, that formula does
10821151
not apply and access may continue beyond it.
10831152

1153+
**Deferred actions.** A deferred action executes with no live session, so
1154+
session expiry never stops it. Under this NIP only a disconnect command does:
1155+
the durable record cancels the matching actions and fences the admissions the
1156+
command covers, in every relay process and across restarts. An issuer that
1157+
only stops issuing assertions leaves every accepted deferred action in place
1158+
for as long as it can stay pending. A deployment that enables deferred actions
1159+
in a community that requires NIP-FI MUST have each authorized issuer send a
1160+
disconnect command when an identity loses access. A community ban of the key
1161+
remains available to the relay operator.
1162+
10841163
**HTTP ingress bypass.** Without the pairing rule, a principal holding an
10851164
active key can mint fresh NIP-98 events indefinitely and retain HTTP access
10861165
for as long as the key remains accepted — the assertion TTL provides no

0 commit comments

Comments
 (0)