Skip to content

Ad/rebase tamas singleton poc#171

Closed
adonesky1 wants to merge 7 commits intomainfrom
ad/rebase-tamas-singleton-poc
Closed

Ad/rebase tamas singleton poc#171
adonesky1 wants to merge 7 commits intomainfrom
ad/rebase-tamas-singleton-poc

Conversation

@adonesky1
Copy link
Copy Markdown
Contributor

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 7 commits February 4, 2026 11:48
- Add PrefixedStoreAdapter to prefix all storage keys with instanceId
- Add createIsolatedStorage utility for consistent storage creation
- Add generateInstanceId for deterministic instance IDs
- Add instanceId option to MultichainOptions for explicit control
- Fix beforeunload listener bug (was using different function references)
- Update tests to use instanceId: '' for backwards compatibility

This enables multiple SDK clients to coexist without storage collisions.
Each client instance gets its own storage namespace based on dapp.name
and SDK type (e.g., 'mydapp-multichain:', 'mydapp-evm:').
- Add sdkType option to MultichainOptions for proper isolation
- Fix EVM client to pass sdkType: 'evm' to multichain core
- Increment IndexedDB version to force schema upgrade
- Add experiments pages to browser playground for testing isolation
- Add StateVisualizer component for inspecting storage state
- 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>
@adonesky1 adonesky1 closed this Feb 18, 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.

2 participants