Repository navigation
feat(relay): let plugins keep NIP-AR community-scoped artifacts - #3827
Closed
LordMelkor wants to merge 9 commits into
Closed
LordMelkor wants to merge 9 commits into
LordMelkor wants to merge 9 commits into
Conversation
Add the dependency-free NIP-AR community-scope helpers that the desktop
host, the browser broker and the session share: NIP-11
`artifacts.community_scope` discovery, the exact kind-9034 type policy
command and its validator, the policy read filter and response parser,
and the relay's artifact type grammar.
Artifact sync now accepts a community filter (`"scope": "community"`
with exactly one `#type` and no `#h`); channel filters are unchanged.
A socket `conflict:` refusal of a 9034 command counts as proven
non-delivery, like other compare-and-set refusals.
The browser transport exposes `artifactCommunity` and
`artifactTypePolicy` when the broker reports a canonical community id:
the read posts `{type}` to `artifact-type-policy`, and the writer uses
the `artifact-type-policy-sign` and `-publish` routes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
The desktop transport reads NIP-11 `artifacts.community_scope` (only when the relay lists `nip-ar`) and, for such a relay, offers `artifactCommunity` with `artifactTypePolicy`: a signed `/query` read of the community's per-type write policy, and a writer for the kind-9034 command bound to this community. Kind 9034 goes only through the purpose-bound `relay_channel_sign` and `relay_channel_publish` route `artifact-type-policy`, which accepts exactly the four tags in order (a canonical non-nil community, the relay's namespaced type grammar, `everyone` or `admins`, and `prev` of "0" or a lowercase event id) with empty content. The generic `relay_sign` keeps refusing 9034, so the artifact signer cannot set a policy, and raw `/events` posts now refuse it like the other typed-route kinds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: LordMelkor <kray@squareup.com>
The browser host's relay broker now reads NIP-11
`artifacts.community_scope` (only with `nip-ar` listed) and reports the
community as `artifactCommunity` in the session, so the browser
transport can offer community-scoped artifacts.
Kind-9034 type policy commands get their own `artifact-type-policy-sign`
and `-publish` routes, like identity archive requests: each accepts only
the exact command for the relay's advertised community, and the generic
sign and publish routes still refuse it. The `artifact-type-policy` read
accepts exactly `{type}` and sends the relay its own policy filter.
A socket publication refused with `restricted:`, `blocked:` or
`auth-required:` is now answered 403 with the relay's text, as the
relay's HTTP API does, instead of 503 unsent, so writers show it as a
refusal. Community artifact sync passes through the broker unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
…ession `session.artifacts.communityId` is the community id the relay advertises in NIP-11 `artifacts.community_scope`, and `session.artifacts.typePolicy` reads and sets a type's write policy (NIP-AR kind 9034). Both are present only when the transport provides the community and its policy route, so a plugin can detect community artifacts synchronously. `typePolicy.set` builds the exact 9034 command for the session's own community, signs it once as the viewer and publishes it once. It resolves with the command id and the relay's answer: the relay's refusal text when the host keeps it, or an empty message after a transport failure. It rejects only on a malformed change, a signing failure or an aborted signal. The artifact sync guide describes the community sync filter, both fields and their boundary: the policy capability acts with the viewer's authority, like the session's other administrative writers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: LordMelkor <kray@squareup.com>
A community sync filter with one `#type` outside the NIP-AR type grammar passed `artifactSyncFilter` and reached the relay, which closes the REQ as `invalid:`. The view then ended in status `error` instead of the call throwing, while the policy helpers refused the same type at the call site. The community branch now checks the value with `artifactTypeName`, the grammar the policy helpers already share, so every host refuses it before the REQ. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: LordMelkor <kray@squareup.com>
The desktop type policy route was tested with types made only of lowercase letters, and its refusals all failed on a segment's first character. Dropping the digit, `_` or `-` arm of the per-byte check, or widening it to accept uppercase inside a segment, still passed. The test now accepts types with digits, `_` and `-` (including a hyphenated middle segment) and refuses uppercase or punctuation inside a segment and a leading or trailing dot, matching the shared TypeScript grammar's table. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: LordMelkor <kray@squareup.com>
The broker answers a proven socket refusal starting with `restricted:`, `blocked:` or `auth-required:` with 403, so the writer sees the relay's refusal instead of an unconfirmed publication. Only the first two prefixes were tested, so dropping `auth-required` from the mapping still passed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: LordMelkor <kray@squareup.com>
Make the transport's artifactTypePolicy the plugin-facing read/set access and build it in one helper shared by the native and broker transports, so the session only passes it through. Move the set behavior tests to the helper's own test file. No behavior change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: LordMelkor <kray@squareup.com>
The Rust shape test named a feature in its sample type; it now uses com.example.settings.item, as the other tests do. Two refusal cases repeated checks that have one owner elsewhere: - The broker route test sent three malformed policy commands. Wrong tag order and an extra tag are covered by artifact-community.test.ts and the Rust shape test, so it keeps only the other-community command, which proves the route binds to its relay's community. - The access test rejected three malformed relay reads. The parser's own table covers them, so one row is kept to prove read uses it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: LordMelkor <kray@squareup.com>
Contributor
Author
|
🤖 Moved to #3838, so that the branch is in this repository. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This lets a plugin keep community-wide artifacts under NIP-AR community scope (spec; relay: draft block/buzz#9646). A relay that advertises NIP-11
artifacts.community_scopeversion 1 keeps kind-45010 revisions that carry acommunitytag and noh. It also keeps a per-type write policy, set with kind 9034. Today a plugin can't do either:session.artifacts.syncthrows on a filter without#h.The app gains three things:
session.artifacts.sync({ artifact: "current", scope: "community", "#type": [type] })takes exactly one#typeand no#h. It has the same statuses as a channel sync.session.artifacts.communityId. It is present only when the relay advertises community scope, so a plugin can check it synchronously before it shows anything that needs community artifacts.session.artifacts.typePolicy. It is{ read, set }for this community:read(type, signal)returns{ policy, revision }.set({ type, policy, prev }, signal)signs one kind-9034 command as the viewer and publishes it once. It resolves{ id, ok, message }, with the relay's answer when the host keeps it.Kind-45010 community records need no new writer.
configArtifactWriteralready signs anh-less 45010, andsnapshotReadalready reads a head.A plugin owns every feature built on this. A shared mention-groups plugin, in a separate repository, is the first consumer.
Why each change is in core, and why it is this small
The rule for each row: a change belongs in the app only if no plugin can do it with today's API, and then only in the smallest general form, one that names NIP-AR concepts and no feature.
artifact-community.ts(new): wire helpers for community id, type name grammar, 9034 template and validation, policy filter and parserartifact-sync-filter.ts.artifact-sync-filter.ts: acceptscope: "community"with one#type#hon both hosts (artifact-sync.ts,relay-broker.mjs).native.ts,transport.ts,relay-broker.mjs: readartifacts.community_scopeat connecttransport.scopeis the relay origin, not the community UUID.artifact-type-policy.ts(new) plus one route each innative.ts,transport.tsandrelay-broker.mjs: a typed 9034 sign, publish and policy readconfigArtifactsrefuses any kind but 45010, andrelay_signrefuses 9034. The broker's/signdoesn't handle it. The policy answer is a JSON object, whichparseEventsrefuses.channel_writes.rs,relay.rs: the native shape check for the 9034 route, and 9034 added to the/eventsrefusal listrelay_signkeeps refusing 9034.socket-requests.ts: treat a 9034conflict:like the existing 40100 and 45010 compare-and-set refusalsprevis reported as an unconfirmed publish instead of the relay's refusal.session.ts:communityIdandtypePolicyonsession.artifactsmatch(observation, context)gets onlycontext.session, so the community gate has to live there.docs/artifact-sync.md: one sectionBoundary.
typePolicyacts with the viewer's authority, like the session's other administrative writers (memberAdministration,channelLifecycle): any plugin in an admin's session can change any type's write policy. The relay accepts the command only from a direct owner or admin. A per-plugin gated service would add a new service, a registration and a naming rule. That rule would block any plugin that governs several types, for no protection beyond what the relay already enforces.Size
Measured against
main(46a09dbfd) withgit diff --numstat:The two largest pieces are
artifact-community.ts(+145, the shared NIP-AR wire helpers) and the broker routes (+61).FOUNDATION files touched:
src/features/relay/session.ts, +11/-1: the two pass-through fields and one comment line. No other edited file carries the marker.Testing
All runs were on a separate Linux machine at
b2f6be14f:bin/node scripts/check-push.mjs(types and related tests)check-push.mjs --designcheck-push.mjs --clippycargo test relay::(atfce1bf43a; no Rust file changed after it)New tests cover:
prevandcreated_atbounds.setoutcomes (accepted, rejected with the relay's reason, not sent, unconfirmed).readrefusing a malformed relay answer.Not yet run: end to end against a relay that advertises community scope. The relay side is draft block/buzz#9646. This PR stays a draft until that test passes with the consuming plugin.
Merge order
This PR shares no files with #3726 or #2878. It is meant to land after them, with the plugin PR after it.
🤖 Generated with Claude Code