SWIP-XXXX: Swarm Provider API (window.swarm)#94
Conversation
…provements Add Security Considerations section (origin trust, resource exhaustion, iframe behavior, feed key material, temp artifacts). Add Future Extensions section (swarm_listFeeds, capabilitiesChanged, preferredIdentityMode, specVersion promotion path). Promote convenience methods and re-prompting from SHOULD to MUST. Add specVersion (SHOULD) to swarm_getCapabilities. Document UTF-8 string encoding, session-scoped tag ownership, feed update failure semantics, and bzz:// URI scheme status. Add edge-case test cases. Fix stale branch links. Rename file to match repo conventions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…eedEntry Two coordinated updates reflecting the implemented behavior in Freedom Browser (PR ethersphere#19): 1. New method: swarm_listFeeds() - Origin-scoped introspection returning the calling origin's previously created feed records — name, topic, owner, manifestReference, bzzUrl, createdAt, lastUpdated, lastReference. - No permission required: feed coordinates are deterministic given (origin, name) and the metadata persists across permission revocation by design, so gating it would be friction without security benefit. - Returns [] for origins with no feeds (never an error). - Removed from the Future Extensions list since it now ships in 1.0. 2. Permission correction for swarm_readFeedEntry - The 1.0 draft previously required connection permission. That was wrong — feeds are public Swarm data readable from any Bee gateway without auth, and forcing requestAccess broke passive use cases like profile pages displaying on-chain-discovered activity feeds. - Method now requires NO permission grant. Updated description, errors (4100 removed), behavior bullets, permission lifecycle item 4, and the corresponding test case ("Without Feed Grant" → "Without Any Permission" with stronger assertions). - Permission lifecycle item 5 (disconnection) clarified that permission-free reads MUST continue to function after revocation. Other touches: - Method count in the abstract bumped from "nine" to "ten". - Convenience method list extended with window.swarm.listFeeds(). - Implementation reference updated: removed the broken docs/swarm-provider-test link (the file moved to research/ and is no longer tracked); Swarmit's method usage list extended to include writeFeedEntry / readFeedEntry / listFeeds. Net diff: +83 / -14 lines. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Reflects implementation findings from the iOS Freedom Browser provider:
- USTAR tar's 100-byte name field caps file paths far below the prior
256-char wording. Replace the hardcoded limit with a capability-advertised
maxPathBytes (normative floor of 100, recommended default 100 UTF-8 bytes)
so future PAX-supporting implementations can advertise more.
- Bee's GET /feeds/{owner}/{topic}?index=N is at-or-before, not exact-match,
which silently breaks writeFeedEntry's overwrite protection on sparse
writes and corrupts readFeedEntry's explicit-index contract. Add normative
exact-match requirements on both methods plus an informative section
documenting the SOC-address derivation (GET /chunks/{socAddress}) and the
big-endian/little-endian endianness trap.
- Clarify that the 4 KB SOC body limit is internal to the storage envelope,
not a writeFeedEntry payload cap; the dApp-visible cap is maxDataBytes.
|
It would be good if chunk level operations were supported in the API, because with those every higher level Swarm APIs can be implemented (feeds, manifest, ACT etc.), even ones that are not supported at the moment by Bee (e.g. epoch feeds). The API could be Similarly there would be a There are also Single-Owner Chunks. Currently Swarm does not have a way to distinguish different chunk types, and it does it with heuristics, but there are documented issues and discrepancies about it.
If this could be fixed at the Swarm level, then |
…ission model In response to PR review (agazso, ethersphere#94): - New low-level chunk methods: swarm_publishChunk, swarm_readChunk, swarm_writeSingleOwnerChunk, swarm_readSingleOwnerChunk. Type is declared by method name to sidestep Bee's CAC/SOC heuristic (SWIP-67, bee#5445). Reads MUST validate by recomputing the type-specific address; mismatch returns chunk_type_mismatch. - New swarm_getSigningIdentity for pre-write SOC address derivation; also serves as feed-permission bootstrap path. - Permission model: prompt-rejection is 4001 across both publish and feed tiers; 4100 reserved for missing connection or un-promptable contexts. 4100 description broadened to match. - Permission-free reads (readFeedEntry, readChunk, readSingleOwnerChunk, listFeeds) now MUST be per-origin rate/bandwidth limited; new rate_limited reason and dedicated security section. - span widened to number | bigint for u64 safety. - Capability advertises maxChunkPayloadBytes = 4096. - Design Goal scoped to writes/signing/resource-consuming ops to match the permission-free read tier. - Implementation section honestly scopes Freedom/Swarmit coverage to the original high-level surface. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Thanks @agazso — this ended up being very useful feedback. The latest push ( Chunk methods added: Type validation on reads: providers must verify returned bytes against the requested chunk type: BMT/address validation for CACs, and SOC signature recovery plus Signing identity discovery: added
SOC mutability wording corrected: same A few related changes fell out of this: permission-free reads now have mandatory per-origin rate/bandwidth limits with a I also looked at SwarmID while shaping this. My current read is that Reference implementations for the new chunk tier and |
Summary
This PR proposes a new draft SWIP defining a standard JavaScript provider API —
window.swarm— that lets web pages request access to a user's Swarm (Bee) node for publishing data, uploading files, managing mutable feeds, reading and writing indexed feed entries, and introspecting their own feed records. It follows the request/response pattern established by EIP-1193 for Ethereum providers, adapted for Swarm's publishing and feed primitives.The draft lives at
SWIPs/swip-draft_provider_api.mdand will be renamed toswip-XXXX.mdonce a number is assigned.Motivation
Today, publishing to Swarm from a web app requires either:
localhost, orNeither is acceptable for a user-sovereign web. Users need a way to grant web apps controlled, permissioned access to Swarm publishing — the way
window.ethereumlets pages interact with a wallet without exposing private keys. Without a standard, every Swarm-enabled browser or extension will invent its own API, fragmenting the ecosystem.What the SWIP specifies
window.swarm) injected beforeDOMContentLoaded, withrequest(), convenience wrappers, and an event interface.swarm_requestAccess), capability discovery (swarm_getCapabilities), publishing (swarm_publishData,swarm_publishFiles,swarm_getUploadStatus), mutable feeds (swarm_createFeed,swarm_updateFeed), indexed feed entries (swarm_writeFeedEntry,swarm_readFeedEntry), and origin-scoped feed introspection (swarm_listFeeds).127.0.0.1doesn't collapse into one permission scope), and app-scoped feed identities (each origin's feeds signed by a per-origin derived key, so dApps can't impersonate the user's main wallet).GET /feeds/{owner}/{topic}at-or-before semantics and the SOC-address fallback) so overwrite protection and explicit-index reads are safe.maxDataBytes,maxPathBytes) so future implementations supporting PAX tar can advertise larger paths without breaking the spec.capabilitiesChangedevent,preferredIdentityMode, encoding parameter for reads, promotion path forspecVersion).Reference implementations
This is not a paper spec — both sides of the API are already implemented and exercise the full surface:
window.swarminto webview contexts, with main-process IPC enforcement, origin normalization, app-scoped feed keys, and per-origin permissions.swarm_requestAccess,swarm_publishData,swarm_createFeed,swarm_writeFeedEntry,swarm_readFeedEntry, andswarm_listFeedsfor its full publishing and profile-discovery pipeline.The implementation work surfaced several spec issues that have already been folded back into this draft (USTAR tar's 100-byte path limit, Bee's at-or-before feed lookup semantics, the SOC-address endianness trap, permission gating for public reads).
Status
swip-draft_provider_api.mdtoswip-XXXX.mdonce a number is assigned.