refactor(push): simplify internal notification stack

Signed-off-by: Tom Brow <tomb@block.xyz>
Co-authored-by: Codex <noreply@openai.com>
Ai-assisted: true
This commit is contained in:
Tom Brow
2026-08-24 20:25:40 -07:00
parent aca13021d6
commit 3b3e536bd2
59 changed files with 488 additions and 2869 deletions

View File

@@ -17,7 +17,7 @@ Push Leases
## Abstract
This NIP defines the **push lease**: a stored, installation-scoped, expiring authorization asking a **push executor** (usually the user's relay) to keep a constrained Nostr filter active after the client's socket closes, and to *wake* a specific application installation through a platform push transport (APNs, FCM, optionally UnifiedPush) when the filter matches.
This NIP defines the **push lease**: a stored, installation-scoped, expiring authorization asking a **push executor** (usually the user's relay) to keep a constrained Nostr filter active after the client's socket closes, and to *wake* a specific application installation through a platform push transport (APNs or FCM) when the filter matches.
The push payload is a **wake signal** authored entirely by the configured transport service: a fixed reconnect instruction, never relay-supplied bytes, event ids, event content, URLs, ciphertext, or extensible custom data. On wake, the client reconnects and fetches authoritative events over normal `REQ`. Push delivery is lossy and best-effort — duplicates and omissions are both possible; the relay remains the single source of truth. Platform transports are execution profiles for the lease, not the protocol's content plane.
@@ -51,8 +51,8 @@ This document uses MUST, MUST NOT, SHOULD, SHOULD NOT, MAY, and RECOMMENDED as d
- **origin**: the canonical origin identifier the descriptor advertises for a relay/community; the tenant key (see Acceptance and Origin Binding).
- **wake signal**: the fixed, transport-authored reconnect payload defined in Wake Delivery. It contains no relay-supplied application data.
- **subscription**: one `{filter, class, ignore?, suppress?}` entry inside a lease.
- **priority class**: one of `silent`, `default`, `time_sensitive`, `urgent`.
- **transport profile**: the APNs/FCM/UnifiedPush-specific execution rules for a lease.
- **priority class**: `default` in this profile.
- **transport profile**: the APNs/FCM-specific execution rules for a lease.
## The Lease Event
@@ -73,7 +73,7 @@ This document uses MUST, MUST NOT, SHOULD, SHOULD NOT, MAY, and RECOMMENDED as d
}
```
- `d` MUST be generated from at least 128 bits of randomness by the installation, and MUST be distinct per origin — cross-origin unlinkability is a guarantee of this NIP, not a nicety. It MUST NOT contain or be derived from a hardware identifier, advertising identifier, APNs token, FCM registration token, UnifiedPush endpoint, or other transport identifier. Reinstalling the application MUST create a new `d`; transport-token rotation within the same installation MUST retain `d` and replace the existing lease.
- `d` MUST be generated from at least 128 bits of randomness by the installation, and MUST be distinct per origin — cross-origin unlinkability is a guarantee of this NIP, not a nicety. It MUST NOT contain or be derived from a hardware identifier, advertising identifier, APNs token, FCM registration token, or other transport identifier. Reinstalling the application MUST create a new `d`; transport-token rotation within the same installation MUST retain `d` and replace the existing lease.
- `expiration` (NIP-40) is REQUIRED and MUST satisfy `now − allowed_skew < expiration ≤ now + max_lease_ttl` at acceptance (`invalid: lease ttl too long` / `invalid: lease already expired`; `max_lease_ttl` descriptor-advertised, default 30 days; RECOMMENDED `allowed_skew` 15 minutes). The executor MUST stop matching once it passes. Inactive (tombstone) replacements carry a public `expiration` under the same bound; it dates the tombstone, not any matching. Expiry is the self-healing backstop for every abuse and leak below.
- `exec` names the descriptor encryption key the content was produced for (see Executor Discovery).
- Public tags are exactly one `d`, one `expiration`, one `exec`, and at most one `alt`, each with exactly one value; duplicated tags, extra tags, or extra tag values MUST be rejected. The executor MUST reject a lease carrying filter, kind, author, endpoint, or platform data in public tags.
@@ -87,12 +87,12 @@ This document uses MUST, MUST NOT, SHOULD, SHOULD NOT, MAY, and RECOMMENDED as d
"v": 1,
"origin": "<origin id, byte-for-byte from the descriptor>", // tenant binding, verified — never routed on
"app_profile": "com.example.app/ios", // selects transport credentials
"transport": "apns", // "apns" | "fcm" | "unifiedpush"
"endpoint": "<opaque transport endpoint>", // APNs token / FCM token / UP URL
"transport": "apns", // "apns" | "fcm"
"endpoint": "<opaque transport endpoint>", // APNs or FCM token/capability
"generation": 3, // strictly increasing per lease address
"active": true, // false = revocation tombstone
"subscriptions": [
{ "filter": { "kinds": [9], "#p": ["<self>"] }, "class": "time_sensitive" },
{ "filter": { "kinds": [9], "#p": ["<self>"] }, "class": "default" },
{ "filter": { "kinds": [9], "#h": ["<channel-uuid>"] }, "class": "default",
"ignore": [ { "kinds": [9], "authors": ["<noisy-bot>"], "#h": ["<channel-uuid>"] } ],
"suppress": { "p_tags_max": 20 } }
@@ -146,16 +146,9 @@ Each subscription carries exactly one `class`:
| Class | Meaning | APNs `interruption-level` | Android importance |
|---|---|---|---|
| `silent` | Sync-only wake, no alert | not user-visible; see APNs profile | `IMPORTANCE_MIN` |
| `default` | Standard notification | `active` | `IMPORTANCE_DEFAULT` |
| `time_sensitive` | Breaks through Focus/DND within OS policy | `time-sensitive` | `IMPORTANCE_HIGH` |
| `urgent` | Reserved: approval gates | `critical` if entitled, else `time-sensitive` | `IMPORTANCE_HIGH` + full-screen intent where policy allows |
Classes are strictly ordered: `silent` < `default` < `time_sensitive` < `urgent`. When one deduplicated wake covers matches from multiple subscriptions or leases targeting the same endpoint (see Coalescing), the wake's effective class is the highest eligible class among those matches. The descriptor's `class_support` is authoritative: a lease naming a class unsupported for its transport MUST be rejected at acceptance (`invalid: class not supported`), never silently downgraded.
The executor MUST restrict `urgent` to the descriptor-advertised allow-list of approval-request kinds whose eligibility is decidable from the public event envelope (`invalid: class not permitted for kind`). Urgent DMs are explicitly out of scope for v1: gift-wrapped DM content is opaque to the executor, so no privacy-safe urgency marker exists yet; a future revision may add one.
`silent` remains a matching preference only. The public Buzz APNs profile sends the one fixed reconnect alert and does not expose relay-selected notification classes to the transport boundary.
The descriptor's `class_support` is authoritative: a lease naming an unsupported class MUST be rejected at acceptance (`invalid: class not supported`), never silently downgraded. The public Buzz APNs profile sends the one fixed reconnect alert and does not expose relay-selected notification classes to the transport boundary.
Clients MUST NOT register any lease or subscription as a side effect of joining a channel or surface — absent explicit user opt-in the notifiable set is empty.
@@ -176,10 +169,8 @@ Until this draft has an upstream NIP number, executors MUST NOT advertise it in
"app_profiles": [ { "id": "com.example.app/ios", "transport": "apns" },
{ "id": "com.example.app/android", "transport": "fcm" } ],
"push_kinds": [9, 1059, 40007, 46010, 7],
"urgent_kinds": [46010],
"h_grammar": "uuid-v4-lowercase",
"class_support": { "apns": ["silent","default","time_sensitive","urgent"],
"fcm": ["silent","default","time_sensitive","urgent"] },
"class_support": { "apns": ["default"], "fcm": ["default"] },
"limitation": {
"max_lease_ttl": 2592000,
"max_leases_per_pubkey": 16,
@@ -192,9 +183,9 @@ Until this draft has an upstream NIP number, executors MUST NOT advertise it in
}
```
A descriptor is valid only if: exactly one key is marked `current` and key ids are unique; app-profile ids are unique; `endpoint` is an `https://` URL; `urgent_kinds ⊆ push_kinds`; and every `class_support` value comes from the class registry in this NIP. Clients MUST treat a descriptor failing these checks as absence of push support.
A descriptor is valid only if: exactly one key is marked `current` and key ids are unique; app-profile ids are unique; `endpoint` is an `https://` URL; and every `class_support` value comes from the class registry in this NIP. Clients MUST treat a descriptor failing these checks as absence of push support.
The executor URL and credentials come from the descriptor, never from the lease. A lease cannot point the executor at an arbitrary HTTP endpoint; this removes the callback-amplification class of attack entirely. Executors MUST NOT dereference a client-supplied `endpoint` URL except as the selected transport profile explicitly defines (UnifiedPush is the only profile whose endpoint is a URL, and it is validated per that profile before use).
The executor URL and credentials come from the descriptor, never from the lease. A lease cannot point the executor at an arbitrary HTTP endpoint; this removes the callback-amplification class of attack entirely.
Leases MUST be author-only reads, as specified in Acceptance and Origin Binding, following the NIP-ER access pattern.
@@ -230,10 +221,6 @@ The APNs application body is the exact UTF-8 byte constant `{"aps":{"alert":{"bo
A future FCM profile MUST define one gateway-owned constant data message with identical noninterference semantics. Until that constant and its wire tests are registered, FCM is not a conforming v1 public-gateway profile.
### UnifiedPush (optional)
UnifiedPush is not a conforming public-gateway profile in v1 because arbitrary distributor endpoints and message bodies do not meet the fixed-payload authority boundary. A future profile requires a separately registered constant body and hostile-endpoint analysis.
## Lease and Key Lifecycle
A lease is identified by `(author, kind, d)`. A replacement supersedes the prior lease at the same address only by passing the full acceptance sequence, including winning both NIP-01 addressable ordering and the strictly-increasing generation watermark (check 8). Any rejected replacement — stale by either ordering, or invalid for any other reason — MUST leave the stored event, effective push state, and watermark unchanged.
@@ -264,15 +251,12 @@ This section registers the public last-hop profile served at `https://push.buzz.
### Registered values and lease mapping
The registered `app_profile` values are `buzz-ios-dogfood` and
`buzz-ios-app-store`. They identify closed Buzz application identities, not APNs
transport environments. The canonical gateway owns the mapping from each
profile to one exact App Attest application identifier, APNs topic,
certificate-backed connection pool, and APNs environment. A client profile
selector chooses only a candidate entry; enrollment succeeds only when App
Attest cryptographically verifies the configured application identifier. A
gateway deployment MUST enable only profiles whose full mapping is configured
consistently, and MUST NOT accept an APNs topic from a client. The APNs token
The registered `app_profile` value is `buzz-ios-dogfood`. It identifies the
closed Buzz dogfood application identity, not an APNs transport environment.
The canonical gateway owns its exact App Attest application identifier, APNs
topic, certificate-backed connection pool, and APNs environment. Enrollment
succeeds only when App Attest cryptographically verifies the configured
application identifier. The gateway MUST NOT accept an APNs topic from a client. The APNs token
registered with the gateway is called the **installation endpoint** and never
leaves gateway custody after enrollment.
@@ -449,6 +433,6 @@ Zombie leases (e.g. `#h` after leaving a channel) are neutralized by match-time
- `kind:30350`: push lease (addressable)
- `exec` tag: executor encryption-key identifier for `kind:30350`
- NIP-11 `supported_extensions`: contains `"nip-pl"` pre-numbering; descriptor object `push` as specified in Executor Discovery
- Classes: `silent`, `default`, `time_sensitive`, `urgent`
- Classes: `default`
- `h_grammar` values: `"uuid-v4-lowercase"` (initial entry; origins may register additional grammars with this NIP)
- Public APNs gateway profile: base URL `https://push.buzz.xyz`; app profiles `buzz-ios-dogfood`, `buzz-ios-app-store`; wire version `1`
- Public APNs gateway profile: base URL `https://push.buzz.xyz`; app profile `buzz-ios-dogfood`; wire version `1`

View File

@@ -16,25 +16,20 @@
| `BUZZ_PUSH_PUBLIC_DELIVERY_URL` | Exact externally signed URL, normally `https://push.buzz.xyz/v1/deliveries/apns`. |
| `BUZZ_PUSH_MAX_GRANT_LIFETIME_SECONDS` | Maximum delegation capability lifetime (`1..=31536000`). |
| `BUZZ_PUSH_MAX_INSTALLATION_LIFETIME_SECONDS` | Maximum encrypted-token installation lifetime (default 90 days, max one year). Clients must renew before expiry. |
| `BUZZ_PUSH_ENABLED_PROFILES` | Comma-separated closed application profiles: `buzz-ios-dogfood` and/or `buzz-ios-app-store`. Dogfood is the only enabled MVP profile. |
| `BUZZ_PUSH_APP_ATTEST_ROOT_CERT_PATH` | Read-only mounted Apple App Attest root certificate PEM. |
| `BUZZ_PUSH_{DOGFOOD,APP_STORE}_APP_ATTEST_APP_ID` | Exact server-owned Apple App Attest application identifier (`TEAMID.bundle-id`) for each closed profile. |
| `BUZZ_PUSH_{DOGFOOD,APP_STORE}_APNS_TOPIC` | Server-owned APNs topic for each profile. Never accepted from a client. |
| `BUZZ_PUSH_{DOGFOOD,APP_STORE}_APNS_ENVIRONMENT` | `production` or `sandbox`, selected per profile by deployment configuration. |
| `BUZZ_PUSH_{DOGFOOD,APP_STORE}_APNS_CERT_PATH` | Read-only certificate/private-key PEM for an enabled profile. A dormant profile may omit it. |
| `BUZZ_PUSH_DOGFOOD_APP_ATTEST_APP_ID` | Exact server-owned Apple App Attest application identifier (`TEAMID.bundle-id`). |
| `BUZZ_PUSH_DOGFOOD_APNS_TOPIC` | Server-owned APNs topic. Never accepted from a client. |
| `BUZZ_PUSH_DOGFOOD_APNS_ENVIRONMENT` | `production` or `sandbox`, selected by deployment configuration. |
| `BUZZ_PUSH_DOGFOOD_APNS_CERT_PATH` | Read-only certificate/private-key PEM. |
| `BUZZ_PUSH_GRANT_KEYS` | Capability AEAD keyring, `id:base64-32-bytes[,predecessor...]`; current key first. |
| `BUZZ_PUSH_TOKEN_KEYS` | Independent token-custody AEAD keyring in the same format. Never reuse grant keys. |
The single canonical `push.buzz.xyz` deployment owns a closed profile registry
for both dogfood (`xyz.block.buzz.dogfood.mobile`) and App Store
(`xyz.block.buzz.mobile`) application identities. Enrollment's profile selector
only chooses a candidate entry: the corresponding App Attest verifier must
cryptographically validate that entry's configured application ID before the
profile is stored with the installation. Assertions and delivery subsequently
select App Attest policy, APNs topic, certificate-backed connection pool, and
environment from that stored profile. No client request or relay grant can
supply or override an APNs topic. The MVP enables and credentials dogfood only;
the App Store entry remains registered but dormant until a later rollout.
The canonical `push.buzz.xyz` MVP serves the dogfood application identity
(`xyz.block.buzz.dogfood.mobile`). App Attest must cryptographically validate
the configured application ID before enrollment. Assertions and delivery use
the server-owned APNs topic, certificate-backed connection pool, and
environment. No client request or relay grant can supply or override an APNs
topic.
Optional endpoint quota policy variables are `BUZZ_PUSH_ENDPOINT_QUOTA_WINDOW_SECONDS` (default `10`, max `86400`) and `BUZZ_PUSH_ENDPOINT_QUOTA_MAX_DELIVERIES` (default `10`, max `10000`). These are Buzz policy hypotheses, not Apple-published limits; tune under load while retaining a hard ceiling.
@@ -73,7 +68,7 @@ Alerting rules ship as an opt-in prometheus-operator `PrometheusRule` (`promethe
| Alert | Fires when | Severity | Action |
|---|---|---|---|
| `PushGatewayConfigurationFault` | any `configuration_fault` outcomes for 10m | critical | The enabled profile's APNs certificate/topic/environment is unhealthy. Check the matching `BUZZ_PUSH_{DOGFOOD,APP_STORE}_APNS_*` configuration. No endpoints are being invalidated. |
| `PushGatewayConfigurationFault` | any `configuration_fault` outcomes for 10m | critical | The APNs certificate/topic/environment is unhealthy. Check `BUZZ_PUSH_DOGFOOD_APNS_*` configuration. No endpoints are being invalidated. |
| `PushGatewayAdmissionUnavailable` | any admission `unavailable` for 5m | critical | PostgreSQL authority store is unreachable. Check DB connectivity and the pod's `postgresEgressCidrs` NetworkPolicy. |
| `PushGatewayReadinessAuthorityFailing` | readiness `authority` failures for 5m | warning | Replicas are being pulled from the Service on DB check failure. Fix DB health before capacity drops below the PodDisruptionBudget. |
| `PushGatewayReaperFailing` | reaper failed ≥2 times within 30m (runs every 5m) | warning | Expired reservations aren't being swept, growing the bounded-until-expiry window. Check DB write availability. |