poc: implement SDK singleton#168
Draft
chakra-guy wants to merge 4 commits intopoc/sdk-client-isolationfrom
Draft
poc: implement SDK singleton#168chakra-guy wants to merge 4 commits intopoc/sdk-client-isolationfrom
chakra-guy wants to merge 4 commits intopoc/sdk-client-isolationfrom
Conversation
- 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>
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.
Explanation
References
Checklist