Skip to content

perf(walletconnect): sign relay auth JWTs with native ed25519 - #38839

Merged
tommasini merged 4 commits into
mainfrom
perf/walletconnect-native-ed25519
Nov 9, 2026
Merged

tommasini merged 4 commits into
mainfrom
perf/walletconnect-native-ed25519

Conversation

@tommasini

@tommasini tommasini commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Description

Problem. WalletConnect signs a relay auth JWT every time its relayer connects. That happens in core.crypto.signJWT, called from relayer.createProvider at unlock, on foreground and on network changes. It also derives the client's public key in getClientId. Both go through @walletconnect/relay-auth, which bundles a pure-JS ed25519 (@noble/curves). On Hermes the first call in a process costs about half a second of JS thread: it builds precompute tables, then runs two scalar multiplications.

Who pays it: every wallet with a WalletConnect pairing or session. Relayer.init() in @walletconnect/core 2.23.4 ends with this.transportOpen() → createProvider() → core.crypto.signJWT(). transportOpen() returns early when the subscriber has no topics ("Starting WS connection skipped because the client has no topics to work with."), so the relay connect and its JWT only happen for wallets that have one. WC2Manager.init runs at every unlock (initializeSDKServices, app/store/sagas/index.ts:83), so those wallets pay the ~500 ms on the JS thread at every unlock, and again when the network comes back (subscribeToNetworkChange → transportOpen). A wallet that has never connected to a dApp skips the relay connect at unlock. Whether it still derives the client key at unlock (getClientId → generateKeyPair) is not established: the app builds the core with new Core(), and Core.init() is what calls getClientId.

Evidence. From the always-on perf session (#38554) on a Galaxy Z Fold4 at 120 Hz, exp build 8.19.0 (4532), right after unlock: JS lag was 928 ms with the JS thread at 85.7%. The Hermes profile covering that moment (symbolicated with the build's source map) has this hottest path:

@walletconnect/core → relay-auth generateKeyPair/signJWT → multiply → wNAF → wNAFCached → getPrecomputes
506 ms total (relay-auth `i`: 387 ms self)

Fix. Metro resolves @walletconnect/relay-auth to app/shims/walletconnect-relay-auth.ts. That shim re-exports the package unchanged and replaces only two functions, generateKeyPair and signJWT, with native libraries the app already ships:

  • Public key: getPublicKeyEd25519(seed) from @metamask/native-utils, the same synchronous Nitro library shimPerf.js already uses for secp256k1 (see docs/performance/native-crypto.md).
  • Signature: new Ed('ed25519').signSync(data, seed) from react-native-quick-crypto (OpenSSL). @metamask/native-utils 0.8.0 has no ed25519 signing. If it gains one, this can move there too.
  • Fallback: each native call falls back to the original JS on its own for the rest of the session if it throws or returns a malformed result. A failure in one library doesn't turn off the other. The first fallback of each call is reported once through Logger.error (Sentry, tag operation:relay_auth_native_ed25519) with the call name only, so a broken native library shows up instead of silently costing the ~500 ms again. A secret key of the wrong length goes to JS without turning native signing off.

The JWT header, payload and encoding still come from relay-auth's own helpers (encodeIss, encodeData, encodeJWT). ed25519 is deterministic, so keys and JWTs are byte-identical to the JS implementation.

Why a Metro shim and not a patch, or a shimPerf.js-style mutation. relay-auth pins @noble/curves 1.8.0 exactly, while the app uses 1.9.7. So mutating the app's @noble/curves the way shimPerf.js does would never reach relay-auth's copy: that's the single-copy invariant in docs/performance/native-crypto.md. relay-auth's dist is also a minified bundle that inlines noble, so patching it would be fragile. The redirect follows the existing react-native-safe-area-context shim pattern in metro.config.js. The shim imports the copy of relay-auth that core resolves, so it follows core's version. Jest doesn't remap the package, so unit tests keep using the real JS implementation.

Risks.

  • Crypto correctness. Equivalence tests compare the shim with the JS implementation for fixed seeds and inputs: public key, secret key, the full JWT string, and verifyJWT on the shim's output. They back quick-crypto with Node's OpenSSL ed25519.
  • Native availability. If a native call throws or returns a key or signature of the wrong length, the shim switches the native path off for the session and uses the JS implementation, so the behaviour is the same as today, and reports it once to Sentry. EdKeyPair and KeyObjectHandle are registered on both iOS and Android (OpenSSL 3.6.2 on both).
  • Key material. The seed is WalletConnect's client identity key. It is passed to the native module in memory only, exactly as it is passed to the JS curve today. It is never logged or stored.

Follow-up, not in this PR. Defer WC2Manager.init (app/store/sagas/index.ts:83, initializeSDKServices) until after the homepage's first content. The relayer connect would then leave the unlock path entirely.

Changelog

CHANGELOG entry: Improved app responsiveness right after unlock by signing WalletConnect relay authentication natively

Related issues

Refs: #38554 (perf session that found it)

Manual testing steps

Feature: WalletConnect relay auth with native ed25519

  Scenario: user unlocks with existing WalletConnect sessions
    Given the wallet has an active WalletConnect v2 session with a dapp
    When user kills the app, reopens it and unlocks
    Then the relayer connects (the dapp session stays active and requests arrive)
    And no "falling back" behaviour is needed (signing requests from the dapp work)

  Scenario: user pairs a new dapp
    Given the wallet is unlocked
    When user scans a WalletConnect v2 pairing QR code from a dapp
    Then the pairing and session proposal complete as before

Verification: before/after over cold unlocks on a device is in the PR comments: relay-auth JS time went from a median of 505 ms to 0 ms. A run with only this change applied is in progress.

Manual test evidence on an iOS simulator and a Galaxy Z Fold4 (pairing, signing requests, kill + reopen + unlock with a saved session, on-device equivalence and cold timings: 559 ms JS vs 8 ms native on the Fold4): #38839 (comment)

Screenshots/Recordings

N/A: no UI change. The before/after Hermes profiles will be attached in the verification comment.

Before

N/A

After

N/A

Pre-merge author checklist

Performance checks (if applicable)

  • I've tested on Android (pending: perf-session before/after on a Galaxy Z Fold4)
    • Ideally on a mid-range device; emulator is acceptable
  • I've tested with a power user scenario
    • Use these power-user SRPs to import wallets with many accounts and tokens
  • I've instrumented key operations with Sentry traces for production performance metrics

For performance guidelines and tooling, see the Performance Guide.

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

🤖 Generated with Claude Code


Note

Medium Risk
Touches cryptographic signing for WalletConnect relayers; correctness and native dependency availability need vigilance though JS fallbacks exist.

Overview
Adds a Metro redirect so WalletConnect loads app/shims/walletconnect-relay-auth.ts, which wraps @walletconnect/relay-auth to derive keys and sign relay-auth JWTs with @metamask/native-utils and react-native-quick-crypto, falling back to the bundled JS implementation per native call on error while re-exporting the rest of relay-auth.

The companion Jest suite asserts byte-for-byte parity with the JS path, exercises every fallback scenario, and guards that only one lockfile copy exists; .depcheckrc.yml now whitelists @walletconnect/relay-auth because the shim imports that transitive package directly.

Reviewed by Cursor Bugbot for commit 9375cbd. Bugbot is set up for automated code reviews on this repo. Configure here.

WalletConnect signs a relay auth JWT on every relayer connect (unlock,
foreground, network changes) and derives its client public key with
@walletconnect/relay-auth's bundled pure-JS ed25519. A Hermes profile right
after unlock on a Galaxy Z Fold4 showed 506 ms of JS thread in that code
(precompute tables and scalar multiplication), inside a 928 ms JS lag.

Metro now resolves @walletconnect/relay-auth to a shim that re-exports the
package and replaces generateKeyPair and signJWT with react-native-quick-crypto
(OpenSSL) calls. ed25519 is deterministic, so keys and JWTs are byte-identical
(covered by equivalence tests against the JS implementation); on any native
failure the shim falls back to the JS implementation for the session.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamask-ci

metamask-ci Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

PR template — items to address before "Ready for review"

Warnings — informational, address before merging:

  • Pre-merge author checklist has unchecked items (e.g. "I've applied the right labels on the PR (see labeling guidelines). Not required for external contributors."). Every box must be consciously checked — see docs/readme/ready-for-review.md.

See docs/readme/ready-for-review.md for the full Definition of Ready for Review.

@github-actions github-actions Bot added the size-M label Nov 4, 2026
@metamask-ci metamask-ci Bot added the team-mobile-platform Mobile Platform team label Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Smart E2E Test Selection

Selected E2E tags

SmokeMMConnect
SmokeMultiChainAPI
SmokeNetworkAbstractions
SmokeNetworkExpansion

AI Confidence: 78

E2E reasoning

Expand to read

This PR introduces a new WalletConnect relay-auth shim (app/shims/walletconnect-relay-auth.ts) that intercepts ALL @walletconnect/relay-auth module resolution via a new metro.config.js resolveRequest handler. The shim replaces the pure-JS Ed25519 implementation with native implementations from @metamask/native-utils and react-native-quick-crypto, with a JS fallback on failure.

Why these tags:

  • SmokeMMConnect: Directly tests MetaMask Connect flows via the local Browser Playground dApp, which uses WalletConnect/relay-auth for connection establishment. The relay-auth shim intercepts the cryptographic key generation and JWT signing used in WalletConnect relay connections — any regression here would break dApp connections.
  • SmokeMultiChainAPI: Tests CAIP-25 multi-chain session API which relies on WalletConnect infrastructure for session management. The relay-auth path is used during session establishment.
  • SmokeNetworkAbstractions: Required dependent tag per SmokeMultiChainAPI description (permission UI layer).
  • SmokeNetworkExpansion: Required dependent tag per SmokeMultiChainAPI description (multi-chain provider). Also tests multi-chain provider architecture that may use WalletConnect relay connections.

Why not ALL tags: The shim is specifically scoped to WalletConnect relay authentication (key generation and JWT signing for relay connections). It has a JS fallback, making it unlikely to break non-WalletConnect flows. The change doesn't touch transaction signing, account management, swap/bridge, staking, or other wallet flows.

Risk assessment: Medium — the change intercepts a critical cryptographic path at the Metro bundler level (affecting all WalletConnect relay auth calls), but includes a robust JS fallback mechanism. The metro.config.js change is critical infrastructure but the resolver logic is well-scoped to only @walletconnect/relay-auth imports.

View run

@tommasini

Copy link
Copy Markdown
Contributor Author

Before/after on a device

Measured with the internal perf session (in-app sampler with Hermes sampling profiles at about 100 Hz, symbolicated with the build's source map). Device: Galaxy Z Fold4 (SM-F936B, 120 Hz), main-exp 8.19.0 (4532), same wallet. Each run was a cold start, then a biometric unlock, then 20 s on WalletView.

JS time in @walletconnect/relay-auth (ed25519 wNAF / getPrecomputes / multiply) Before After
Per unlock 505, 450, 425, 530, 526 ms 0, 0, 0, 0 ms
Median 505 ms 0 ms
  • WalletConnect still runs after unlock in the after-fix profiles (@walletconnect/core frames such as confirmOnlineStateOrThrow). So relay auth didn't stop running; the signing moved to native code, and it finishes in less than one 10 ms sample.
  • The native path didn't fall back to JS on this device: there are no relay-auth frames at all.

Caveat: total JS-thread busy time over the 10 s after unlock is noisy run to run (before 3.38–3.66 s, after 2.67–3.81 s). With this sample size it can't confirm the ~0.5 s saving at the thread level; the function-level profile above is the reliable signal. The worst JS lag after unlock is unchanged (median 568 ms), because other startup work (lazy module loads, Perps and Predict preloads) now accounts for it. That work is a separate follow-up.

🤖 Generated with Claude Code

@tommasini

Copy link
Copy Markdown
Contributor Author

With only this PR applied

Same device and method as above: Galaxy Z Fold4, main-exp, cold start, then biometric unlock, then 20 s on WalletView. This time the build is the perf-session branch plus only this PR's commit (poc/perf-verify-wc, run 41836379965, built normally with the TapAndPay SDK).

Baseline (5 unlocks) This PR only (4 valid unlocks)
JS time in @walletconnect/relay-auth (ed25519) 505, 450, 425, 530, 526 ms (median 505 ms) 0, 0, 0, 0 ms (median 0 ms)
Main-thread stalls from the Lighter WebView (control, fixed separately in #38837) median 323 ms 392, 488, 0, 510 ms
  • The test wallet has no WalletConnect dApp connected. The cost was there at every unlock anyway, because Relayer.init() always opens the transport and signs the JWT (see the description).
  • What the new code costs on the JS thread: across all 10 profiles in this run, quick-crypto and WalletConnect frames take at most ~22 ms per 10 s window, about 2 samples. The native path never fell back to JS.
  • Worst JS lag: it was higher in this run (median 1,287 ms vs 568 ms). In those windows the time went to JSON.parse / JSON.stringify, young-generation GC, superstruct's run (Perps snapshot validation) and lazy module loads, not to anything this PR touches. That startup work varies from run to run.

🤖 Generated with Claude Code

Use @metamask/native-utils getPublicKeyEd25519, the same synchronous
native library shimPerf.js uses for secp256k1, for the public key.
Signing stays on react-native-quick-crypto because native-utils has no
ed25519 signing. Each native call now falls back to JS on its own, so a
failure in one library doesn't turn off the other.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tommasini

Copy link
Copy Markdown
Contributor Author

After moving the public key to @metamask/native-utils (4c9a07c)

Same device and method: Galaxy Z Fold4, main-exp, cold start, then biometric unlock, then 20 s on WalletView, test wallet with no WalletConnect dApp connected. The build is the perf-session branch plus both commits of this PR (poc/perf-verify-wc-native-utils, run 41873566402).

Baseline This PR, quick-crypto only (run 41836379965) This PR, native-utils key + quick-crypto signature
JS time in relay-auth's ed25519 (wNAF / getPrecomputes / multiply) median 505 ms 0 ms (4 of 4 unlocks) 0 ms (4 of 4 unlocks)
  • No curve frames from relay-auth in any profile.
  • The one relay-auth sample seen (11 ms, once) is ht, an encoding helper the shim reuses on purpose for the JWT format.
  • @metamask/native-utils doesn't show up at all, because its call finishes faster than one 10 ms sample.
  • WalletConnect core still runs (@walletconnect/core frames), so the native path ran and didn't fall back to JS. A fallback would cost the ~250 ms precompute again.

🤖 Generated with Claude Code

weitingsun pushed a commit to Poovarasan-Sandhanam/metamask-mobile that referenced this pull request Nov 6, 2026
…ask#38837)

## **Description**

<!-- mms-check: type=text required=true -->

**Problem.** Every unlock blocks the Android main thread for about 400
ms, even for users who never use Lighter. `LighterSignerWebView` mounts
as soon as the wallet unlocks and passes `wasm-wrapper.standalone.html`
(10.3 MB, the Go/WASM signer as base64) as `source.html`.

**Evidence.** An always-on perf session ran on a Galaxy Z Fold4 with the
exp build 8.19.0 (4532). About 2.5 s after `WalletView` first appeared,
it recorded two UI-thread stalls, both inside
`RNCWebViewManager.onAfterUpdateTransaction` ←
`ViewManager.createViewInstance` (Fabric `preallocateView` /
`createView`):
- 145 ms in `ReadableNativeMap.importValues`: copying the 10 MB prop
across JNI.
- 259 ms in `WebView.loadDataWithBaseURL`: loading the inline document
on the main thread.

The only other inline-HTML WebView in `Root` is `SnapsExecutionWebView`,
and it mounts before Engine init, not at unlock.

**Fix.** Mount the signer page only when a Lighter call needs it:
- `lighterSignerBridge` now records a request (`requestLighterSigner`)
when client setup starts or a WASM call is made. `LighterSignerWebView`
subscribes to it with `useSyncExternalStore`, and mounts only when the
wallet is unlocked **and** a request exists.
- Callers already wait behind the bridge's readiness promise (90 s
deadline), so the first call queues until the page reports `ready`.
Client setup requests the page before reading the keychain, so both
happen in parallel.
- Key discovery (`getStoredKeyIndices`, `getRecoverableKeyIndices`)
doesn't need the page, so it doesn't trigger a load.
- Locking still unmounts the page, and now also forgets the request. The
next unlock waits for the next call.

The security properties are unchanged: same `https://localhost` origin,
navigation filter, file-access flags, message validation and lock
lifecycle. Only the moment the page mounts changes.

**Risk.** The first Lighter call in a session waits for the page to load
(hundreds of ms to a few seconds on low-end devices), which used to
happen at unlock. Users who never use Lighter never pay it.

**Follow-up (not in this PR).** The 10 MB document is still inlined into
the JS bundle and copied over JNI when it does mount. Shipping it as a
native asset and loading it by URL would remove both the copy and the
bundle weight. That needs care with the origin and
`onShouldStartLoadWithRequest`, so it's left for a separate change.

**Verification.** Measured with the perf session on a Galaxy Z Fold4
over 4–5 cold unlocks per build. Main-thread stalls with the Lighter
WebView on the stack went from a median of 323 ms per unlock to 0 ms,
both [with
MetaMask#38839](MetaMask#38837 (comment))
and [with only this PR
applied](MetaMask#38837 (comment)).
The test wallet uses Hyperliquid, so for Lighter users the cost moves to
their first trading action rather than disappearing.

## **Changelog**

<!-- mms-check: type=changelog required=true blocking=true -->

CHANGELOG entry: Improved unlock responsiveness on Android by loading
the Lighter signer only when it is needed

## **Related issues**

<!-- mms-check: type=issue-link required=true -->

Refs: MetaMask#38554 (perf session POC that found this)

## **Manual testing steps**

<!-- mms-check: type=manual-testing required=true -->

```gherkin
Feature: Lighter signer loads on demand

  Scenario: unlock without using Lighter
    Given a build with MM_PERPS_LIGHTER_PROVIDER_ENABLED=true
    When user unlocks the wallet and stays on the wallet home
    Then no hidden Lighter WebView is created (no lighter-signer-webview in the view tree)
    And no loadDataWithBaseURL stall appears at unlock

  Scenario: first Lighter action
    Given the wallet is unlocked and Lighter has not been used yet
    When user starts a Lighter flow that needs the signer (client setup / placing an order)
    Then the signer page loads and the action completes

  Scenario: lock and unlock
    Given the signer page is loaded
    When user locks and unlocks the wallet
    Then the page is gone after lock and only loads again on the next Lighter action
```

## **Screenshots/Recordings**

<!-- mms-check: type=screenshot required=true -->

### **Before**

N/A (no UI change). Perf-session evidence above; before/after numbers
are in the comments linked under Verification.

### **After**

N/A (no UI change).

## **Pre-merge author checklist**

<!-- mms-check: type=checklist required=true -->

- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I've included tests if applicable
- [x] I've documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I've applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

#### Performance checks (if applicable)

- [x] I've tested on Android
  - Ideally on a mid-range device; emulator is acceptable
- [ ] I've tested with a power user scenario
- Use these [power-user
SRPs](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/edit-v2/401401446401?draftShareId=9d77e1e1-4bdc-4be1-9ebb-ccd916988d93)
to import wallets with many accounts and tokens
- [ ] I've instrumented key operations with Sentry traces for production
performance metrics
- See [`trace()`](/app/util/trace.ts) for usage and
[`addToken`](/app/components/Views/AddAsset/components/AddCustomToken/AddCustomToken.tsx#L274)
for an example

For performance guidelines and tooling, see the [Performance
Guide](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/400085549067/Performance+Guide+for+Engineers).

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Changes wallet-lock coordination and when the key-holding WebView
mounts, but signing semantics and isolation are unchanged; the main
product risk is first-use latency for Lighter users.
> 
> **Overview**
> **Defers loading the ~10 MB Lighter WASM WebView** so it no longer
mounts on every wallet unlock (which blocked the Android main thread for
hundreds of ms). The hidden signer page now mounts only when the wallet
is unlocked **and** a bridge call actually needs it.
> 
> The bridge gains a small **demand signal** (`requestLighterSigner` /
`clearLighterSignerRequest` + `useSyncExternalStore` in
`LighterSignerWebView`). **`createClient`** and **`execute`** set the
request before keychain read / WASM work; **key discovery** does not.
Pending calls still wait on the existing readiness promise, so the first
Lighter action pays the load cost instead of unlock.
> 
> **Lock handling** moves partly to the always-mounted host: on
`KeyringController:lock` it clears the demand flag and marks the bridge
unavailable even when no WebView is mounted; on unlock it revives the
bridge without reloading until the next request. Tests add a **lazy
mounting** suite and adjust lock/unlock expectations (e.g. batched
lock+unlock no longer auto-remounts the page).
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
91feb61. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@tommasini

Copy link
Copy Markdown
Contributor Author

Manual test evidence: iOS simulator + Galaxy Z Fold4

Tested head 4c9a07c on 2026-11-06. No failures. The shim is wired into every WalletConnect caller, gives byte-identical keys and JWTs on Hermes, and the relay accepts its JWTs. Pairing, signing requests and a real kill, reopen and unlock all work.

Result
Unit tests (walletconnect-relay-auth.test.ts) 13 / 13 pass
iOS 27 simulator (skulk report, checker passed) 5 PASS · 0 FAIL · 2 UNVERIFIED (harness limits, covered on Android)
Android, Galaxy Z Fold4 SM-F936B (physical) 6 / 6 pass

Cold first call: relay-auth JS vs native shim (generateKeyPair + signJWT)

Device relay-auth JS Native shim Same JWT
Fold4, fresh process before unlock 559.2 ms (550.6 + 8.6) 8.1 ms (0.7 + 7.4) yes
iOS simulator, same process 329.3 ms (320.2 + 9.1) 96.6 ms (6.9 + 89.7) yes

Steady state on the Fold4: native signJWT ≈ 0.9 ms vs ≈ 7 ms warm JS; native generateKeyPair ≈ 0.1 ms.

The JS curve is never touched on unlock. After unlocking with saved WalletConnect sessions (WC init, getClientId and a relay connect with signJWT all done), the first call into relay-auth's JS generateKeyPair still paid the full precompute: 447 ms then 2.4 ms on the Fold4 after a real kill and reopen, and 310.7 ms then 1.7 ms on iOS after a JS reload.

iOS checks (skulk session 20261106-164654-868c)

Check Verdict Evidence
Shim bundled, native path active PASS Metro's module table: the shim (7846) next to the real relay-auth (7847). Every importer (@walletconnect/core, utils, and the copies nested under @reown/walletkit) depends on the shim; only the shim imports the real package.
Native output byte-identical to JS on device PASS 5 fixed seeds: public key, secret key and full JWT identical; verifyJWT accepts each native JWT. Real OpenSSL and native-utils, not Jest mocks.
Pair a new dApp over WC v2 PASS The app opened wss://relay.walletconnect.org?auth=<JWT> and the relay accepted it; the dApp got session.approved.
Signing request reaches the wallet PASS The personal_sign sheet showed the exact message; Cancel sent 4001 User rejected the request. back to the dApp.
Kill + relaunch + unlock keeps the session UNVERIFIED skulk's relaunch deletes persistStore, mmkv and AsyncStorage before launch (fresh fixture wallet), so the harness wiped the session. Covered on Android.
JS reload with a saved session: requests reach the UI UNVERIFIED The relay reconnected and both requests reached WalletKit, but the reload re-read skulk's fixture state, which dropped the dApp's permission. Harness, not the PR. Covered on Android.
Unlock with saved sessions reconnects using native only PASS A new relay socket was accepted after unlock, sessions were restored, the native flag stayed on, the JS curve was still cold, and a dApp request arrived.

Android checks (Fold4, Metro from the PR branch)

MetaMask sets FLAG_SECURE on Android, so screenshots are blocked. Evidence is the app's own state read over Metro's CDP inspector, plus the test dApp's log.

Check Result Evidence
Shim wired into every caller PASS All four WC importers resolve to the shim; native flag on.
Pair a new dApp PASS wallet_requestPermissions approval shown; after Connect the dApp got session.approved; relay connected.
Signing request reaches the wallet PASS A personal_sign approval appeared; Cancel sent 4001 back to the dApp.
Kill, reopen, unlock with a saved session PASS am force-stop, cold launch (new pid), WC not initialized before unlock. After unlock: relay reconnected in 6.7 s, session restored, native flag on, JS curve still cold (447 ms → 2.4 ms).
Requests still arrive after reopen PASS A new personal_sign surfaced as an approval; Cancel sent 4001 back.
Native output byte-identical to JS PASS 5 seeds identical; verifyJWT true.

The test dApp was a Node script using @walletconnect/sign-client on the public relay. Every signature was rejected, never approved.

Notes for the author

  • "Every user pays it, with or without a WalletConnect connection" doesn't seem to hold for signJWT on core 2.23.4. Relayer.transportOpen() returns early with "Starting WS connection skipped because the client has no topics to work with." On a wallet with no pairings, WalletConnect was initialized after unlock with connected: false, 0 topics and no relay socket. So signJWT at unlock only runs for wallets with a pairing or session. I didn't establish whether getClientId (→ generateKeyPair) still runs at unlock without topics: the app builds the core with new Core(), not Core.init(), which is what calls getClientId. Worth tightening the description, or confirming with a profile on a wallet with no sessions.
  • No fallback seen. isNativeEd25519ActiveForTests() stayed true on both platforms through every pairing, signature and reconnect.
  • quick-crypto first-call cost. The first native signJWT in a process took 89.7 ms on the iOS simulator and 7.4 ms on the Fold4; later calls take under 1 ms. Still a clear net win, but worth checking on real iOS hardware.

Caveats

  • Both platforms ran CI's dev client from main (run 42229069816) with this PR's JS from Metro. The PR has no native changes, and the native libraries it calls already ship in that client.
  • The Android bundle came from a local worktree whose node_modules belongs to another checkout. The packages this change touches match the PR's lockfile: @walletconnect/core 2.23.4, relay-auth 1.1.0, @metamask/native-utils 0.8.0, react-native-quick-crypto 1.1.9. The iOS bundle used skulk's own clean install of the PR (bundle 6f610e4c…).
  • In-app reads used eval / CDP Runtime.evaluate; skulk's ledger records them (20 evals, no mock rules or flag overrides).

tommasini and others added 2 commits November 6, 2026 17:31
…shim

The shim and its test import the copy of relay-auth that
@walletconnect/core resolves, on purpose, so the shim follows core's
version. Declaring it as a direct dependency could pin a different copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…gning key

- Report the first fallback of each native call through Logger.error
  (Sentry), so a broken native library doesn't silently bring back the
  ~500 ms of JS ed25519. The report carries the call name only, no key
  material.
- Send a secret key of the wrong length to the JS implementation without
  turning native signing off for the session, like generateKeyPair already
  does for the seed.
- Test that the lockfile holds a single @walletconnect/relay-auth, which is
  what lets the shim wrap the same copy @walletconnect/core uses, and
  reword the comment that claimed it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

sonarqubecloud Bot commented Nov 6, 2026

Copy link
Copy Markdown

@tommasini
tommasini marked this pull request as ready for review November 6, 2026 23:08

@Cal-L Cal-L left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tommasini
tommasini added this pull request to the merge queue Nov 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 9, 2026
@tommasini
tommasini added this pull request to the merge queue Nov 9, 2026
Merged via the queue into main with commit da8d4a3 Nov 9, 2026
209 of 211 checks passed
@tommasini
tommasini deleted the perf/walletconnect-native-ed25519 branch November 9, 2026 19:00
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 9, 2026
@metamask-ci metamask-ci Bot added the release-8.21.0 Issue or pull request that will be included in release 8.21.0 label Nov 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-8.21.0 Issue or pull request that will be included in release 8.21.0 size-M team-mobile-platform Mobile Platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants