Skip to content

feat: Session Key Registry - #209

Merged
hugomrdias merged 49 commits into
masterfrom
session-key-registry
Oct 8, 2025
Merged

hugomrdias merged 49 commits into
masterfrom
session-key-registry

Conversation

@wjmelements

@wjmelements wjmelements commented Sep 10, 2025 •

Copy link
Copy Markdown
Contributor

Reviewer @rvagg
Closes #186

Changes

  • create SessionKey
  • synapse.setSession
  • synapse.getClient
  • test storage.createContext with session key
  • document usage
  • verify works with curio via utils/example-storage-e2e.js

@wjmelements
wjmelements requested a review from rvagg September 10, 2025 00:44
@wjmelements wjmelements linked an issue Sep 10, 2025 that may be closed by this pull request
@github-project-automation github-project-automation Bot moved this to 📌 Triage in FOC Sep 10, 2025
@wjmelements wjmelements added the enhancement New feature or request label Sep 10, 2025
@wjmelements wjmelements changed the title Session Key Registry feat: Session Key Registry Sep 10, 2025
Comment thread src/session/key.ts Outdated
import { ethers } from 'ethers'
import { CONTRACT_ABIS, CONTRACT_ADDRESSES, getFilecoinNetworkType } from '../utils/index.ts'

export const CREATE_DATA_SET_TYPEHASH = ethers.id(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we could lift up EIP712_TYPES in pdp/auth.ts into types.ts and reconstruct these strings using that data so we don't have to repeat ourselves?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think there's an ethers util to make typehash from eth_signTypedData_v4 types. I can move the code though.

@wjmelements

Copy link
Copy Markdown
Contributor Author

test:node passes but test:browser fails:

Error: NetworkUtils getFilecoinNetworkType failed: Failed to detect network: Unexpected URL: https://api.calibration.node.glif.io/rpc/v1

I'll look into this tomorrow.

Comment thread src/test/synapse.test.ts Outdated
Comment on lines +294 to +296
const synapse = await Synapse.create({ signer })
const sessionKeySigner = new ethers.Wallet(PRIVATE_KEYS.key2, provider)
const sessionKey = synapse.setSession(sessionKeySigner)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Am I right in assuming that setSession() is something we expose for advanced and internal use and not something we expect the user to do manually in the normal case and that we'd be able to handle the dirty work of generating a temporary key for some period while the SDK is active? Or do you think we need to make this the user's responsibility to set this up and make it work, we'll just deal with it if they have gone to the trouble?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't want the sdk to be opinionated on how the key is generated or stored.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

OK, as long as we have really good docs about how to make the most of this - one of the goals of the SDK is to make the golden path very easy, with sensible default and sensible opinions, but also provide ways to take over and do what you want with it. We can't expect our users to want to think too deeply about what we're offering so the more we can give them the better.

@rjan90 rjan90 moved this from 📌 Triage to ⌨️ In Progress in FOC Sep 10, 2025
@wjmelements

Copy link
Copy Markdown
Contributor Author

test:node passes but test:browser fails:

Error: NetworkUtils getFilecoinNetworkType failed: Failed to detect network: Unexpected URL: https://api.calibration.node.glif.io/rpc/v1

I am unsure why server.use doesn't cover this. The failure happens during Synapse.create and seems to happen because ethers.Provider.getNetwork makes a GET request (rather than a POST request):

[MSW] Warning: intercepted a request without a matching request handler:

  • GET https://api.calibration.node.glif.io/rpc/v1

I will look into ethers to see why it does that. Here is the trace up to that get request:

      at _FetchRequest.getUrl2 (/Users/will/projects/synapse-sdk/node_modules/ethers/src.ts/utils/geturl-browser.ts:48:26)
      at _FetchRequest.#send (/Users/will/projects/synapse-sdk/node_modules/ethers/src.ts/utils/fetch.ts:539:33)
      at _FetchRequest.send (/Users/will/projects/synapse-sdk/node_modules/ethers/src.ts/utils/fetch.ts:594:21)
      at JsonRpcProvider._send (/Users/will/projects/synapse-sdk/node_modules/ethers/src.ts/providers/provider-jsonrpc.ts:1271:40)
      at /Users/will/projects/synapse-sdk/node_modules/ethers/src.ts/providers/provider-jsonrpc.ts:734:38
      at JsonRpcProvider._detectNetwork (/Users/will/projects/synapse-sdk/node_modules/ethers/src.ts/providers/provider-jsonrpc.ts:749:9)
      at /Users/will/projects/synapse-sdk/node_modules/ethers/src.ts/providers/abstract-provider.ts:878:48
      at JsonRpcProvider.getNetwork (/Users/will/projects/synapse-sdk/node_modules/ethers/src.ts/providers/abstract-provider.ts:887:13)
      at getFilecoinNetworkType (/Users/will/projects/synapse-sdk/src/utils/network.ts:21:34)

@wjmelements

Copy link
Copy Markdown
Contributor Author

I am unsure why server.use doesn't cover this. The failure happens during Synapse.create and seems to happen because ethers.Provider.getNetwork makes a GET request (rather than a POST request):

[MSW] Warning: intercepted a request without a matching request handler:

  • GET https://api.calibration.node.glif.io/rpc/v1

I will look into ethers to see why it does that. Here is the trace up to that get request:

via npm link, I have verified that ethers does window.fetch with a RequestInit that has method "POST". I also verified that the RequestInit body is not falsy. This helped me deduce that the reason it failed was that I was overriding global fetch without preserving the RequestInit options.

@socket-security

socket-security Bot commented Oct 7, 2025 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedox@​0.9.6 ⏵ 0.9.9100 +1100100 +2100 +4100

View full report

@rvagg

rvagg commented Oct 8, 2025

Copy link
Copy Markdown
Collaborator

@hugomrdias this has become a blocker for the Filecoin Pin demo site — current plan is to deploy a site that uses a shared wallet, but not wanting to do it by embedding the private key in the site. So instead, we use session keys to set up a long-expiry key with a wallet for the demo, give it perms to create data set and add roots, then run the whole thing in that mode. We'd need to instantiate Synapse with a private-key-less wallet (I'm guessing we might have to implement a custom ether.js Wallet that throws on signMessage() and sendTransaction() but can at least getAddress()), but give it the session key which can be embedded in the page safely.

I know you want to try and come up with a better API for this, but do you mind if we merge this, or some form of it ASAP, and mutate it later just to get something released and usable by filecoin-pin? I'm fine with breaking and improving this if we come up with a better approach later, I just don't want that to be a blocker.

@hugomrdias

Copy link
Copy Markdown
Member

sure, does this have the fix for create dataset it needs the owner address in the extra data and not the session key address, cant seem to find it here

@rjan90

rjan90 commented Oct 8, 2025

Copy link
Copy Markdown
Collaborator

We will merge this as is, after getting in the owner address fix

@wjmelements

Copy link
Copy Markdown
Contributor Author

investigating this error

❌ Error: Failed to create data set: 500 Internal Server Error - Failed to send transaction: failed to estimate gas: message execution failed (exit=[33], revert reason=[message failed with backtrace:
00: f0169791 (method 3844450837) -- contract reverted at 75 (33)
01: f0169791 (method 6) -- contract reverted at 4535 (33)
02: f0169800 (method 3844450837) -- contract reverted at 75 (33)
03: f0169800 (method 6) -- contract reverted at 10988 (33)
04: f0169792 (method 3844450837) -- contract reverted at 9618 (33)
 (RetCode=33)], vm error=[0xeef23db600000000000000000000000048884f0e81006cf3a3997dc8b39e6632e70b247600000000000000000000000080617b65fd2eea1d7fde2b4f85977670690ed348])

Comment thread packages/synapse-sdk/src/storage/context.ts
@wjmelements

Copy link
Copy Markdown
Contributor Author

investigating this error

❌ Error: Failed to create data set: 500 Internal Server Error - Failed to send transaction: failed to estimate gas: message execution failed (exit=[33], revert reason=[message failed with backtrace:
00: f0169791 (method 3844450837) -- contract reverted at 75 (33)
01: f0169791 (method 6) -- contract reverted at 4535 (33)
02: f0169800 (method 3844450837) -- contract reverted at 75 (33)
03: f0169800 (method 6) -- contract reverted at 10988 (33)
04: f0169792 (method 3844450837) -- contract reverted at 9618 (33)
 (RetCode=33)], vm error=[0xeef23db600000000000000000000000048884f0e81006cf3a3997dc8b39e6632e70b247600000000000000000000000080617b65fd2eea1d7fde2b4f85977670690ed348])

It's OperatorNotApproved(address,address). So probably there is disagreement between client and server about which is the current warm storage contract.

This reverts commit 069c60b.
@wjmelements
wjmelements requested a review from hugomrdias October 8, 2025 18:04
@wjmelements

Copy link
Copy Markdown
Contributor Author

investigating this error

❌ Error: Failed to create data set: 500 Internal Server Error - Failed to send transaction: failed to estimate gas: message execution failed (exit=[33], revert reason=[message failed with backtrace:
00: f0169791 (method 3844450837) -- contract reverted at 75 (33)
01: f0169791 (method 6) -- contract reverted at 4535 (33)
02: f0169800 (method 3844450837) -- contract reverted at 75 (33)
03: f0169800 (method 6) -- contract reverted at 10988 (33)
04: f0169792 (method 3844450837) -- contract reverted at 9618 (33)
 (RetCode=33)], vm error=[0xeef23db600000000000000000000000048884f0e81006cf3a3997dc8b39e6632e70b247600000000000000000000000080617b65fd2eea1d7fde2b4f85977670690ed348])

It's OperatorNotApproved(address,address). So probably there is disagreement between client and server about which is the current warm storage contract.

This error happens after verifyCreateDataSetSignature which is suspicious because a create data signature for one should not be replayable for another. I will check what else may be causing this.

@github-project-automation github-project-automation Bot moved this from ⌨️ In Progress to ✔️ Approved by reviewer in FOC Oct 8, 2025
@hugomrdias
hugomrdias merged commit 0b0c983 into master Oct 8, 2025
10 checks passed
@hugomrdias
hugomrdias deleted the session-key-registry branch October 8, 2025 18:10
@github-project-automation github-project-automation Bot moved this from ✔️ Approved by reviewer to 🎉 Done in FOC Oct 8, 2025
@wjmelements

Copy link
Copy Markdown
Contributor Author

I will check what else may be causing this.

I might have skipped utils/post-deploy-setup.js

@rvagg

rvagg commented Oct 9, 2025

Copy link
Copy Markdown
Collaborator

@wjmelements FYI post-deploy-setup.js can now be replaced with npx filecoin-pin payments setup which does a nicer job of getting your wallet set up as a client. On the SP side, if you're running a test miner, sp-tool.js does that stuff, although it is a bit manual.

rvagg added a commit that referenced this pull request Oct 14, 2025
Co-authored-by: William Morriss <wjmelements@gmail.com>
Co-authored-by: Rod Vagg <rod@vagg.org>
lordshashank pushed a commit to lordshashank/synapse-sdk that referenced this pull request Mar 9, 2026
Co-authored-by: William Morriss <wjmelements@gmail.com>
Co-authored-by: Rod Vagg <rod@vagg.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: 🎉 Done

Development

Successfully merging this pull request may close these issues.

Support SessionKeyRegistry

4 participants