Skip to content

feat(synapse): add requiredPermissions option to SynapseOptions#806

Open
juliangruber wants to merge 2 commits into
masterfrom
julian/synapse-options-required-permissions
Open

feat(synapse): add requiredPermissions option to SynapseOptions#806
juliangruber wants to merge 2 commits into
masterfrom
julian/synapse-options-required-permissions

Conversation

@juliangruber
Copy link
Copy Markdown
Member

Summary

Implements SgtPooki's suggestion on #695: add a requiredPermissions?: Permission[] option on SynapseOptions, defaulting to SessionKey.DefaultFwssPermissions, so least-privilege session keys can stay on the Synapse.create happy path.

Why

Apps like filecoin-pin-website intentionally scope their session key to a subset of FWSS permissions (e.g. CreateDataSet + AddPieces). Today Synapse.create always checks the full DefaultFwssPermissions set, so those apps have to bypass Synapse.create and use the public Synapse constructor through @filoz/synapse-core directly, which means re-implementing the viem createClient + custom-transport setup that Synapse.create provides for free.

What changed

  • packages/synapse-sdk/src/types.ts — new requiredPermissions?: Permission[] field on SynapseOptions, with a docstring explaining that it gates construction (not per-operation), defaults to SessionKey.DefaultFwssPermissions, and that operations whose permissions are not listed will still revert on-chain if attempted.
  • packages/synapse-sdk/src/synapse.ts:61Synapse.create reads options.requiredPermissions ?? SessionKey.DefaultFwssPermissions instead of the hard-coded DefaultFwssPermissions. No other behavior change.
  • docs/src/content/docs/developer-guides/session-keys.mdx — new "Narrowing the required scope" subsection under "Use with the Synapse class" with example usage and a callout that the SDK still does not enforce per-operation checks.
  • packages/synapse-sdk/src/test/session-keys.test.ts — three new tests:
    • narrower required scope succeeds when only those permissions are authorized
    • still throws when one of the required permissions is missing even if other permissions are valid
    • defaults to DefaultFwssPermissions when requiredPermissions is omitted (regression guard)

Backwards compatibility

requiredPermissions is optional and defaults to the previous behavior, so existing callers are unaffected.

Per-operation checks

Deliberately not adding per-operation permission enforcement here — that was discussed previously as out of scope for GA, and SgtPooki's suggestion was specifically a construction-time knob. Callers must still only invoke SDK methods whose permissions they have authorized; otherwise the call will revert on-chain. The docs call this out explicitly.

Relation to #805

#805 handles the other half of #695 (better error message + docs philosophy). This PR is independent: it only changes the validation input, not the message. Both PRs touch Synapse.create and will produce a small merge conflict whichever lands second; resolution is trivial (apply both: read requiredPermissions from options and itemize the missing ones in the error).

Test plan

  • pnpm run build clean
  • pnpm run lint clean
  • All 255 node tests in @filoz/synapse-sdk pass, including the three new ones above

🤖 Generated with Claude Code

Synapse.create previously hard-coded its session key check to
DefaultFwssPermissions (all four FWSS permissions). Apps with a
least-privilege session key (for example an upload-only client scoped to
CreateDataSet + AddPieces) had to bypass Synapse.create and use the
@filoz/synapse-core constructor directly, which meant re-implementing
the viem client + transport defaults that Synapse.create provides.

Add an optional requiredPermissions?: Permission[] field on
SynapseOptions, defaulting to SessionKey.DefaultFwssPermissions. Callers
that need a narrower scope can pass it directly:

    Synapse.create({
      ...,
      sessionKey,
      requiredPermissions: [
        SessionKey.CreateDataSetPermission,
        SessionKey.AddPiecesPermission,
      ],
    })

The SDK still does not enforce per-operation permission checks --
calling an SDK method whose permission is not in requiredPermissions
will go through and revert on-chain if the session key is not
authorized. requiredPermissions only gates Synapse.create.

Existing callers see no behavior change.

Per #695 (comment).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-project-automation github-project-automation Bot moved this to 📌 Triage in FOC May 28, 2026
@juliangruber juliangruber self-assigned this May 28, 2026
@juliangruber juliangruber moved this from 📌 Triage to 🔎 Awaiting review in FOC May 28, 2026
@juliangruber juliangruber added this to the M4.2: mainnet GA milestone May 28, 2026
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 28, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
synapse-dev 8d8b407 Commit Preview URL

Branch Preview URL
May 29 2026, 02:14 PM

Copy link
Copy Markdown
Collaborator

@rvagg rvagg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm but you're going to have to reconcile impl and docs between this and #805 before merging them

@github-project-automation github-project-automation Bot moved this from 🔎 Awaiting review to ✔️ Approved by reviewer in FOC May 29, 2026
…ons-required-permissions

# Conflicts:
#	docs/src/content/docs/developer-guides/session-keys.mdx
#	packages/synapse-sdk/src/synapse.ts
#	packages/synapse-sdk/src/test/session-keys.test.ts
@juliangruber juliangruber requested a review from rvagg May 29, 2026 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✔️ Approved by reviewer

Development

Successfully merging this pull request may close these issues.

2 participants