feat(mwa-v2): rewrite adapter with full v2 session lifecycle#5
Open
Zurcusa wants to merge 6 commits into
Open
Conversation
41b02b1 to
974d62d
Compare
39baefc to
c22530d
Compare
974d62d to
21cacf8
Compare
c22530d to
83bc225
Compare
21cacf8 to
c55d626
Compare
3fc7019 to
7171262
Compare
cf349d8 to
650bfe6
Compare
7171262 to
3ea6cc9
Compare
650bfe6 to
83e8569
Compare
4707812 to
50ab718
Compare
83e8569 to
4753dff
Compare
50ab718 to
37fc64b
Compare
780f463 to
7912091
Compare
4753dff to
58bcdfd
Compare
de05078 to
8f9883c
Compare
- Guard null/empty address in PrimaryAccountPublicKeyBytes - Private constructors on DeauthorizeResult and ReconnectResult - Null-result check in JsonRpc20Client.ReceiverRaw - Cache auth token refresh in sign_and_send authorize action - LogoutSuppressed + OnWalletDisconnected on auth revocation paths - Fix base64 → base58 typo in method reference
58bcdfd to
6e74e5e
Compare
8f9883c to
fbbfc6c
Compare
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.
Problem
The existing
SolanaMobileWalletAdapterhas multiple gaps reported in #273:Logout()only clears local state — no way to revoke MWA authorization (MWA integration issues found on Solana Seeker with Seed Vault — Unity MWA Example App magicblock-labs/Solana.Unity-SDK#273 item 2)GetCapabilitiesnot exposed (MWA integration issues found on Solana Seeker with Seed Vault — Unity MWA Example App magicblock-labs/Solana.Unity-SDK#273 item 4)Solution
Complete rewrite of
SolanaMobileWalletAdapterwith:Auth cache integration (magicblock-labs#272, magicblock-labs#273 item 3): Constructor-injected
IAuthorizationCachewithPlayerPrefsAuthorizationCachedefault. Schema-versioned records with chain-aware validation. Legacy key migration from both pre-v2"pk"/"authToken"and PR#269"solana_sdk.mwa.*"keys.Session lifecycle (magicblock-labs#273 items 2, 4):
Disconnect(),Reconnect()(4-state result),Deauthorize()(tri-state),GetCapabilities(),[Obsolete] Logout()with migration path.Sign-In With Solana (#189):
LoginWithSignIn(SignInPayload)— single wallet round-trip that authorizes + signs a SIWS message. Falls back to authorize-then-sign for wallets without native SIWS support.Concurrency & reliability:
SemaphoreSlim(1,1)gate prevents overlapping wallet calls.SignAndSendTransactionsauto-populatesMinContextSlotfrom latest blockhash. Error code mapping updated for v2 spec.Silent-first login:
_Login()checks cached auth token first, attempts silent authorize, falls back to fresh authorize only on cache miss orauth_token_rejected.Shim removal: Removes
[Obsolete]Authorize/ReauthorizefromIAdapterOperationsandMobileWalletAdapterClient. Removes[Obsolete]PublicKey/AccountLabelfromAuthorizationResult.Tests: 5 new EditMode test suites in
Tests/EditMode/MwaAdapter/covering deauthorize, sign-and-send, concurrency, disconnect, and reconnect flows.Known Issue: Backpack
sign_and_send_transactionssign_and_send_transactionsfails with Backpack wallet. The transaction is successfully created, signed, and submitted on-chain — the issue is only in receiving the response back in the dApp. Backpack's WebSocket server crashes during the on-chain RPC submission phase (~23s into processing), corrupting the local association before the response can be delivered. The dApp's pending request hangs indefinitely. This is a Backpack-specific issue — Phantom and Solflare handle the same flow correctly, surviving 8–12 seconds of Android activity STOP without any WebSocket errors.sign_transactionsworks with all wallets including Backpack (no RPC submission required). Seedocs/sign-and-send-investigation.mdfor full analysis.Pre-existing
LocalAssociationScenarioIssuesThese issues exist in the upstream
LocalAssociationScenario.csand are outside the scope of this PR's adapter rewrite:returninExecuteNextAction(line 134-135): AfterCloseAssociation(response), execution falls through to_actions.Dequeue()on an empty queue, throwingInvalidOperationException.OnClosereconnect loop (line 46-50): Reconnects immediately with no delay, no retry limit, and no close-awareness. Creates a thread pool storm when the wallet server is gone.TimeSpan.FromSeconds(clientTimeoutMs)whereclientTimeoutMs=9000creates a 2.5-hour timeout instead of 9 seconds. Should beFromMilliseconds.scenarioResultaccess (line 449 in adapter):scenarioResult.WasSuccessfulthrowsNullReferenceExceptionif the scenario returns null.Pre-existing test limitations
5 tests that instantiate
SolanaMobileWalletAdaptervia reflection fail on non-Android platforms because the constructor throws"SolanaMobileWalletAdapter can only be used on Android". This is the same pre-existing limitation documented in upstream PR #276. These tests pass on Android devices.Deploy Notes
Breaking changes (relative to PR #4):
IAdapterOperations.Authorize()andReauthorize()removed — useAuthorizeAsync()AuthorizationResult.PublicKeyandAccountLabelremoved — useAuthorizationHelpers.PrimaryAccountPublicKeyBytes()andPrimaryAccount().LabelNew public API:
SolanaMobileWalletAdapter.Disconnect()SolanaMobileWalletAdapter.Reconnect()SolanaMobileWalletAdapter.Deauthorize()SolanaMobileWalletAdapter.LoginWithSignIn(SignInPayload)SolanaMobileWalletAdapter.GetCapabilities()SolanaMobileWalletAdapter.SignAndSendTransactions(Transaction[], SendOptions)Testing Matrix
Tested on Pixel 7 emulator and Solana Seeker (real device).
Wallets Tested
Functionality Coverage