Skip to main content

Dapp share in React Native SDK

Background

As described in the Embedded Wallets infrastructure, the user's private key is split into multiple shares to achieve non-custody:

  1. Share A — Managed by the login service across node operators and returned after authentication.
  2. Share B — Stored on the user's device.
  3. Share C — A recovery share held by the user (for MFA-enabled accounts).

On mobile devices, Share B is typically stored in an in-app browser context. Because users can accidentally clear browser data without realizing the browser was used for authentication, this can break future logins. The dapp share solves this by letting your app store its own backup of a key share directly in app storage.

What is a dapp share?

After a successful login on an MFA-enabled account, Web3Auth returns a dappShare — a 24-word seed phrase that represents half the private key. Your app can store this in its own secure storage (for example, react-native-encrypted-storage) and pass it back to the SDK on subsequent logins, eliminating reliance on the browser context.

note

Dapp share is only returned for custom verifiers (not default Web3Auth verifiers) and only when MFA is enabled for the user's account.

Passing dapp share at login

Pass the stored dapp share as the dappShare parameter to connectTo:

import { AUTH_CONNECTION, useWeb3AuthConnect } from '@web3auth/react-native-sdk'
import EncryptedStorage from 'react-native-encrypted-storage'

async function loginWithDappShare() {
const { connectTo } = useWeb3AuthConnect()
const storedDappShare = await EncryptedStorage.getItem('dapp_share')

await connectTo({
authConnection: AUTH_CONNECTION.GOOGLE,
authConnectionId: 'my-google-connection',
mfaLevel: 'mandatory',
dappShare: storedDappShare ?? undefined,
})
}

Storing the dapp share after login

After a successful login, the user info returned by useWeb3AuthUser() contains the dappShare field for MFA-enabled accounts. Store it securely after the first successful login:

import { useWeb3AuthUser } from '@web3auth/react-native-sdk'
import EncryptedStorage from 'react-native-encrypted-storage'
import { useEffect } from 'react'

function usePersistDappShare() {
const { userInfo } = useWeb3AuthUser()

useEffect(() => {
if (userInfo?.dappShare) {
EncryptedStorage.setItem('dapp_share', userInfo.dappShare)
}
}, [userInfo?.dappShare])
}