Skip to content

Comments

poc: implement SDK singleton#168

Draft
chakra-guy wants to merge 4 commits intopoc/sdk-client-isolationfrom
poc/sdk-singleton
Draft

poc: implement SDK singleton#168
chakra-guy wants to merge 4 commits intopoc/sdk-client-isolationfrom
poc/sdk-singleton

Conversation

@chakra-guy
Copy link
Contributor

@chakra-guy chakra-guy commented Feb 5, 2026

Explanation

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed, highlighting breaking changes as necessary
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

chakra-guy and others added 4 commits February 5, 2026 12:03
- Add singleton caching using globalThis.__metamaskCore
- Multiple SDK clients (Multichain, EVM, Solana) now share a single core instance
- Add getCachedCore(), hasCachedCore(), and _clearCoreForTesting() utilities
- Add Experiment7 for verifying core sharing behavior
- Add singleton.test.ts with comprehensive test coverage

This ensures that regardless of how many SDK clients are instantiated,
they all share the same underlying MultichainCore instance, preventing
state conflicts and resource duplication.

Co-authored-by: Cursor <cursoragent@cursor.com>
…e 2)

- Add registerClient/unregisterClient/getClientCount to MultichainCore
- EVM and Solana clients now register on connect, unregister on disconnect
- Disconnect only revokes session when the last client disconnects
- Add Experiment 8 to verify disconnect coordination behavior
- Fix experiment imports to use correct package names

This enables multiple SDK clients to share a session without tripping
over each other during disconnect operations.

Co-authored-by: Cursor <cursoragent@cursor.com>
- Add areScopesCovered() and mergeScopes() utility functions
- Track scopes per client in ClientInfo type
- Add getUnionScopes() method to MultichainCore
- Modify transport connect() to skip prompts when scopes already covered
- Merge scopes instead of revoking when expanding permissions
- Add loading state and spinner for QR code approval flow
- Create Experiment 9 to verify scope merging behavior
- Update tests to reflect new scope merging behavior

When a client reconnects and its requested scopes are already covered
by the existing session, no approval prompt is shown. New scopes are
merged with existing ones without revoking the session.

Co-authored-by: Cursor <cursoragent@cursor.com>
- Add updateSessionScopes abstract method to MultichainCore
- Implement updateSessionScopes in MetaMaskConnectMultichain
- Update connect-evm and connect-solana disconnect to call updateSessionScopes
- Add Experiment10 for testing partial disconnect behavior
- Document CAIP limitation: no standard for partial scope revocation
  (wallet retains all granted scopes, SDK tracks remaining client scopes)

Note: Per CAIP-25/285 research, wallet_createSession is additive only
and wallet_revokeSession is full session revocation. Partial scope
reduction is not supported by current CAIP standards.

Co-authored-by: Cursor <cursoragent@cursor.com>
@chakra-guy chakra-guy changed the title feat: implement SDK singleton pattern for core sharing feat: implement SDK singleton Feb 5, 2026
@chakra-guy chakra-guy changed the title feat: implement SDK singleton poc: implement SDK singleton Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant