Skip to content

feat(mwa-v2): refactor wire protocol, client, and cache for MWA v2#4

Open
Zurcusa wants to merge 3 commits into
pr/3-mwa-v2-typesfrom
pr/4-wire-client-cache
Open

feat(mwa-v2): refactor wire protocol, client, and cache for MWA v2#4
Zurcusa wants to merge 3 commits into
pr/3-mwa-v2-typesfrom
pr/4-wire-client-cache

Conversation

@Zurcusa
Copy link
Copy Markdown
Owner

@Zurcusa Zurcusa commented May 4, 2026

⚠️ NOTE: This is PR 2 of 3 in the MWA v2 stack. Targets pr/3-mwa-v2-types. This refactors the client layer while preserving backward compatibility via [Obsolete] shims (removed in PR #5).

Status Type ⚠️ Core Change Issue
Ready Feature Yes Closes #272, partial for #273

Problem

The current MobileWalletAdapterClient uses the v1 MWA wire protocol with flat cluster strings and a simple AuthorizationResultAccounts response shape. It lacks:

  • CAIP-2 chain identifier support (#273 item 4)
  • Per-account metadata (icon, chains, features, display address)
  • Permissive response parsing with size caps for untrusted wallet data
  • Authorization caching abstraction (#272)
  • DeauthorizeAsync and SignAndSendTransactionsAsync wire methods
  • Sign-In With Solana (SIWS) payload support

Solution

Wire protocol (JsonRequest.cs): Add chain, cluster (backward compat), features, sign_in_payload, and sendOptions fields.

Client (MobileWalletAdapterClient.cs): Rewrite with:

  • AuthorizeAsync(chain, authToken, features, addresses, signInPayload, ct) — v2 authorize with SIWS
  • DeauthorizeAsync(authToken, ct) — async deauthorize with cancellation
  • SignAndSendTransactionsAsync(payloads, options, ct) — batch sign-and-send
  • CloneAuthorizationAsync(authToken, ct) — clone authorization for multi-session
  • Old Authorize/Reauthorize preserved as [Obsolete] shims

Response model (AuthorizationResult.cs): Refactored to v2 shape with List<AccountInfo>, WalletIcon, SignInResult. Shim PublicKey/AccountLabel properties preserved as [Obsolete].

Parser (AuthorizationResponseParser.cs): Permissive parser with size caps (64KB icons, 128-char display addresses, 32 chains max, 16 accounts max) and structured logging gated by LogVerbosity.

Cache (PlayerPrefsAuthorizationCache.cs): Default IAuthorizationCache backed by Unity PlayerPrefs with scoped key support, corrupt-JSON recovery, and legacy key cleanup. Closes #272.

Tests: 9 new EditMode test suites added to Tests/EditMode/ (MwaParser/, MwaCache/, MwaClient/) with 10 JSON fixtures. Updated existing MobileWalletAdapterClientTests for the new API. Added Solana.Unity.Wallet.dll and Solana.Unity.Rpc.dll to the test assembly definition.

Other changes

  • Removed XML doc comments from existing test files (cleanup)
  • Updated CapabilitiesResult with additional capability fields

Deploy Notes

Backward compatibility: The old Authorize/Reauthorize methods and PublicKey/AccountLabel properties are preserved as [Obsolete] shims. Existing code compiles with deprecation warnings. These shims are removed in PR #5 when the adapter is rewritten.

Testing Matrix

Tested on Pixel 7 emulator and Solana Seeker (real device).

Wallets Tested

Wallet Networks
Seed Vault (Solana Phone) DevNet, MainNet
Phantom DevNet, MainNet
Solflare DevNet, MainNet
Backpack MainNet
Jupiter MainNet

Functionality Coverage

Feature Emulator (Pixel 7) Solana Seeker
Login Passed Passed
Disconnect Passed Passed
Reconnect Passed Passed
Deauthorize Passed Passed
Sign Transaction Passed Passed
Sign All Transactions Passed Passed
Sign Message Passed Passed
Sign and Send ⚠️ Backpack fails (see PR #5 Known Issue) ⚠️ Backpack fails (see PR #5 Known Issue)
Get Capabilities Passed Passed
Sign-In With Solana (SIWS) Passed Passed

@Zurcusa Zurcusa force-pushed the pr/3-mwa-v2-types branch from 74f57aa to 314f641 Compare May 11, 2026 13:51
@Zurcusa Zurcusa force-pushed the pr/4-wire-client-cache branch from 58bcdfd to 6e74e5e Compare May 11, 2026 13:51
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