Skip to content

Add more React Native polyfills and Solana setup into the SDK - #142

Open
yashovardhan wants to merge 5 commits into
masterfrom
feat/shims
Open

Add more React Native polyfills and Solana setup into the SDK#142
yashovardhan wants to merge 5 commits into
masterfrom
feat/shims

Conversation

@yashovardhan

@yashovardhan yashovardhan commented Aug 18, 2026

Copy link
Copy Markdown
Member

Motivation and Context

After the v10 upgrade, React Native apps integrating Web3Auth (especially Solana) needed a growing set of app-level workarounds: separate react-native-url-polyfill imports, custom Metro aliases for @web3auth/auth, local polyfills.js, and shims/ directories. These duplicated what the SDK should own and made examples harder to follow.

This change moves genuinely SDK-owned runtime and Metro compatibility code into @web3auth/react-native-sdk, so consumers can rely on:

  • import "@web3auth/react-native-sdk/setup" for EVM/core apps (URL, crypto, Buffer)
  • import "@web3auth/react-native-sdk/setup-solana" for Solana apps (core setup + Solana runtime polyfills)
  • Plain withWeb3Auth(getDefaultConfig(...)) Metro config without custom resolver branches

Jira Link:

Description

Core URL compatibility

  • src/metro/setup.js loads react-native-url-polyfill/auto before SDK/auth code runs.
  • src/metro/shims/url-shim.js imports URL / URLSearchParams from react-native-url-polyfill instead of incomplete React Native globals.
  • Apps no longer need a separate react-native-url-polyfill entry import.

Solana ED25519 key normalization

  • Adds src/wallets/ed25519Key.ts to normalize hex private keys:
    • 32-byte seeds → delegated to @web3auth/auth getED25519Key
    • 64-byte seed || publicKey secrets → accepted directly
    • Other lengths → rejected explicitly
  • nativeSolanaWallet.ts uses this utility, removing the need for app-level @web3auth/auth Metro shims.

Solana setup export

  • Adds @web3auth/react-native-sdk/setup-solana — chains core setup with Solana-only runtime polyfills:
    • @solana/webcrypto-ed25519-polyfill
    • AbortSignal.timeout (when absent)
    • Minimal window event listener stubs (when absent)
  • Adds @solana/webcrypto-ed25519-polyfill as an SDK dependency.
  • Marks /setup and /setup-solana as sideEffects so bundlers cannot tree-shake them.

Metro resolver

  • No new default resolver branches added. SDK demos work with plain withWeb3Auth; version-sensitive Expo overrides (quick-base64, tslib, es-toolkit) were not reproduced in SDK demos and remain app-level workarounds when needed.

Demos & documentation

  • All 8 existing demos simplified to plain withWeb3Auth(config) Metro configs.
  • Adds demo/rn-bare-solana-example using only setup-solana (no polyfills.js, no shims/).
  • README updated with /setup vs /setup-solana guidance and Solana demo reference.

How has this been tested?

Environment: macOS, Node 22+, local SDK repo

Automated:

  • npm test — 73 tests passing, including:
    • setup.test.ts — core setup structure / URL polyfill wiring
    • setup-solana.test.ts — Solana polyfill behavior and setup chaining
    • ed25519Key.test.ts — 32-byte seed delegation, 64-byte secrets, invalid lengths
    • nativeSolanaWallet.test.ts — wallet creation, account derivation, signing (32-byte and 64-byte keys)
  • npm run lint:ts — 0 errors
  • npm run build — successful
  • Package export resolution verified for /setup, /setup-solana, /solana, /metro-config

Manual (pending / recommended before merge):

  • demo/rn-bare-example — login, EVM calls with plain withWeb3Auth
  • demo/rn-expo-hooks-example — Wagmi integration with plain withWeb3Auth
  • demo/rn-bare-solana-example — login, address, balance, sign message via setup-solana

Screenshots (if appropriate):

N/A — infrastructure / polyfill changes, no UI changes.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project. (run lint)
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My code requires a db migration.

Note

Cursor Bugbot is generating a summary for commit 4f69cb7. Configure here.

@yashovardhan
yashovardhan requested a review from tuna1207 August 18, 2026 21:30

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4f69cb7. Configure here.

// IMP END - Allowlist bundle ID
network: WEB3AUTH_NETWORK.SAPPHIRE_DEVNET,
// IMP START - Chain Config
defaultChainId: "0x66",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Wrong Solana Devnet chain ID

Medium Severity

defaultChainId is set to 0x66, and the demo README calls that Devnet. Elsewhere in this SDK, 0x66 is Testnet and 0x67 is Devnet. Apps that whitelist Devnet on the dashboard while using this config will request the wrong chain at init.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4f69cb7. Configure here.

const [output, setOutput] = useState("");
const log = (...args: unknown[]) => setOutput(JSON.stringify(args, null, 2));

const solanaAddress = accounts![0]!;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unsafe accounts access on render

Medium Severity

HomeView reads accounts![0]! during render. useSolanaWallet types accounts as string[] | null and can return null even when the user is connected, so the logged-in screen can throw before any button is pressed.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4f69cb7. Configure here.

Comment thread src/wallets/ed25519Key.ts
}

return authGetED25519Key(privateKey);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Invalid key lengths not rejected

Medium Severity

getED25519Key only special-cases 64-byte secrets and otherwise forwards every other length to @web3auth/auth. The PR intent was to accept 32-byte seeds and 64-byte secrets and reject all other lengths explicitly, so malformed key material can still reach auth instead of failing fast.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4f69cb7. Configure here.

@chaitanyapotti chaitanyapotti left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we should instead set min supported version of react native instead.
Our sdk min is node 22 and hence RN should be 0.84+
This would mean we wouldn't need url polyfill and we should edit examples to be above 0.84+ on RN or expo 55

Reference:
https://github.com/reactwg/react-native-releases/blob/main/docs/support.md
https://reactnative.dev/blog/2026/02/11/react-native-0.84#url-api-improvements

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