Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,24 @@ module.exports = withWeb3Auth(config);

### Entry point setup

Import the setup module first in your root entry file (`index.js` / `index.ts`):
Import the setup module first in your root entry file (`index.js` / `index.ts`). The SDK setup entry installs URL, crypto, and Buffer polyfills — you do not need a separate `react-native-url-polyfill` import.

```js
import "@web3auth/react-native-sdk/setup";

// ... rest of your app entry
```

**Solana apps** should use the Solana setup entry instead. It loads core setup first, then installs the Ed25519 WebCrypto polyfill and minimal wallet-standard globals required by `@solana/react-hooks`:

```js
import "@web3auth/react-native-sdk/setup-solana";

// ... rest of your app entry
```

Do not import both `/setup` and `/setup-solana` — `/setup-solana` already chains core setup.

## 🌟 Configuration

### Configure your Web3Auth project
Expand Down Expand Up @@ -294,6 +304,8 @@ See `demo/rn-expo-hooks-example` for a complete Expo example.

Optional Solana Framework Kit integration is available from `@web3auth/react-native-sdk/solana`. It bridges the Auth Solana wallet into `@solana/react-hooks` through `SolanaProvider`.

Import `@web3auth/react-native-sdk/setup-solana` in your entry file (instead of `/setup`) before any other app code. It chains core setup with the Solana runtime polyfills required by `@solana/react-hooks`.

Install peers:

```sh
Expand All @@ -320,6 +332,8 @@ Notes:
- `SolanaProvider` also enables Framework Kit hooks from `@solana/react-hooks`.
- Client wiring is owned by the SDK (`walletPersistence: false`). Nest under `Web3AuthProvider`.

See `demo/rn-bare-solana-example` for a complete bare Solana example using `setup-solana` and plain `withWeb3Auth`.

## 💥 Initialization & Usage

Create a `Web3Auth` instance with your browser adapter, secure storage adapter, and project options. Call `init()` before `connectTo()`.
Expand Down
1 change: 1 addition & 0 deletions demo/rn-bare-aggregate-verifier-example/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Web3Auth setup - must be imported first before any other imports
// Includes URL, crypto, and Buffer polyfills via the SDK setup entry
import "@web3auth/react-native-sdk/setup";

import { AppRegistry } from "react-native";
Expand Down
9 changes: 1 addition & 8 deletions demo/rn-bare-aggregate-verifier-example/metro.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
const { getDefaultConfig } = require("@react-native/metro-config");
const { withWeb3Auth } = require("@web3auth/react-native-sdk/metro-config");

const defaultConfig = getDefaultConfig(__dirname);

// Wrap the config with Web3Auth's Metro configuration
// This automatically sets up all necessary polyfills and shims
module.exports = withWeb3Auth(defaultConfig, {
// Optional: Add additional packages that need .js extension fix
// additionalPackagesForJsExtFix: ['some-other-package'],
});
module.exports = withWeb3Auth(getDefaultConfig(__dirname));
1 change: 1 addition & 0 deletions demo/rn-bare-aggregate-verifier-hooks-example/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Web3Auth setup - must be imported first before any other imports
// Includes URL, crypto, and Buffer polyfills via the SDK setup entry
import "@web3auth/react-native-sdk/setup";

import { AppRegistry } from "react-native";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
const { getDefaultConfig } = require("@react-native/metro-config");
const { withWeb3Auth } = require("@web3auth/react-native-sdk/metro-config");

const defaultConfig = getDefaultConfig(__dirname);

// Wrap the config with Web3Auth's Metro configuration
// This automatically sets up all necessary polyfills and shims
module.exports = withWeb3Auth(defaultConfig, {
// Optional: Add additional packages that need .js extension fix
// additionalPackagesForJsExtFix: ['some-other-package'],
});
module.exports = withWeb3Auth(getDefaultConfig(__dirname));
1 change: 1 addition & 0 deletions demo/rn-bare-example/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Web3Auth setup - must be imported first before any other imports
// Includes URL, crypto, and Buffer polyfills via the SDK setup entry
import "@web3auth/react-native-sdk/setup";

import { AppRegistry } from "react-native";
Expand Down
9 changes: 1 addition & 8 deletions demo/rn-bare-example/metro.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
const { getDefaultConfig } = require("@react-native/metro-config");
const { withWeb3Auth } = require("@web3auth/react-native-sdk/metro-config");

const config = getDefaultConfig(__dirname);

// Wrap the config with Web3Auth's Metro configuration
// This automatically sets up all necessary polyfills and shims
module.exports = withWeb3Auth(config, {
// Optional: Add additional packages that need .js extension fix
// additionalPackagesForJsExtFix: ['some-other-package'],
});
module.exports = withWeb3Auth(getDefaultConfig(__dirname));
1 change: 1 addition & 0 deletions demo/rn-bare-firebase-example/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Web3Auth setup - must be imported first before any other imports
// Includes URL, crypto, and Buffer polyfills via the SDK setup entry
import "@web3auth/react-native-sdk/setup";

import { AppRegistry } from "react-native";
Expand Down
9 changes: 1 addition & 8 deletions demo/rn-bare-firebase-example/metro.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
const { getDefaultConfig } = require("@react-native/metro-config");
const { withWeb3Auth } = require("@web3auth/react-native-sdk/metro-config");

const defaultConfig = getDefaultConfig(__dirname);

// Wrap the config with Web3Auth's Metro configuration
// This automatically sets up all necessary polyfills and shims
module.exports = withWeb3Auth(defaultConfig, {
// Optional: Add additional packages that need .js extension fix
// additionalPackagesForJsExtFix: ['some-other-package'],
});
module.exports = withWeb3Auth(getDefaultConfig(__dirname));
1 change: 1 addition & 0 deletions demo/rn-bare-firebase-hooks-example/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Web3Auth setup - must be imported first before any other imports
// Includes URL, crypto, and Buffer polyfills via the SDK setup entry
import "@web3auth/react-native-sdk/setup";

import { AppRegistry } from "react-native";
Expand Down
9 changes: 1 addition & 8 deletions demo/rn-bare-firebase-hooks-example/metro.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
const { getDefaultConfig } = require("@react-native/metro-config");
const { withWeb3Auth } = require("@web3auth/react-native-sdk/metro-config");

const defaultConfig = getDefaultConfig(__dirname);

// Wrap the config with Web3Auth's Metro configuration
// This automatically sets up all necessary polyfills and shims
module.exports = withWeb3Auth(defaultConfig, {
// Optional: Add additional packages that need .js extension fix
// additionalPackagesForJsExtFix: ['some-other-package'],
});
module.exports = withWeb3Auth(getDefaultConfig(__dirname));
1 change: 1 addition & 0 deletions demo/rn-bare-hooks-example/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Web3Auth setup - must be imported first before any other imports
// Includes URL, crypto, and Buffer polyfills via the SDK setup entry
import "@web3auth/react-native-sdk/setup";

import * as WebBrowser from "@toruslabs/react-native-web-browser";
Expand Down
1 change: 1 addition & 0 deletions demo/rn-bare-hooks-example/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Web3Auth setup - must be imported first before any other imports
// Includes URL, crypto, and Buffer polyfills via the SDK setup entry
import "@web3auth/react-native-sdk/setup";

import { AppRegistry } from "react-native";
Expand Down
9 changes: 1 addition & 8 deletions demo/rn-bare-hooks-example/metro.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
const { getDefaultConfig } = require("@react-native/metro-config");
const { withWeb3Auth } = require("@web3auth/react-native-sdk/metro-config");

const config = getDefaultConfig(__dirname);

// Wrap the config with Web3Auth's Metro configuration
// This automatically sets up all necessary polyfills and shims
module.exports = withWeb3Auth(config, {
// Optional: Add additional packages that need .js extension fix
// additionalPackagesForJsExtFix: ['some-other-package'],
});
module.exports = withWeb3Auth(getDefaultConfig(__dirname));
2 changes: 2 additions & 0 deletions demo/rn-bare-solana-example/.bundle/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BUNDLE_PATH: "vendor/bundle"
BUNDLE_FORCE_RUBY_PLATFORM: 1
70 changes: 70 additions & 0 deletions demo/rn-bare-solana-example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# OSX
#
.DS_Store

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
**/.xcode.env.local

# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml
*.hprof
.cxx/
*.keystore
!debug.keystore
.kotlin/

# node.js
#
node_modules/
npm-debug.log
yarn-error.log

# fastlane
#
**/fastlane/report.xml
**/fastlane/Preview.html
**/fastlane/screenshots
**/fastlane/test_output

# Bundle artifact
*.jsbundle

# Ruby / CocoaPods
**/Pods/
/vendor/bundle/

# Temporary files created by Metro to check the health of the file watcher
.metro-health-check*

# testing
/coverage

# Yarn
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
1 change: 1 addition & 0 deletions demo/rn-bare-solana-example/.watchmanconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
86 changes: 86 additions & 0 deletions demo/rn-bare-solana-example/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* Solana example — demonstrates the built-in Solana wallet in the RN SDK.
*
* The SDK derives an ed25519 keypair from the user's key shares and exposes it
* as a wallet-standard `Wallet` via `connection.solanaWallet`. Wrap the app in
* `SolanaProvider` from `@web3auth/react-native-sdk/solana` to use the signing hooks.
*
* Chain configuration is fetched from the Web3Auth Dashboard at init time.
* `web3authConfig.ts` only sets client ID, redirect URL, network, and optional `defaultChainId`.
*/
import * as WebBrowser from "@toruslabs/react-native-web-browser";
import { useWeb3Auth, Web3AuthProvider } from "@web3auth/react-native-sdk";
import { SolanaProvider } from "@web3auth/react-native-sdk/solana";
import React from "react";
import { ActivityIndicator, StyleSheet, Text, View } from "react-native";
// Storage for encrypted session data. On Expo, use `expo-secure-store` instead.
import EncryptedStorage from "react-native-encrypted-storage";
import { SafeAreaProvider } from "react-native-safe-area-context";

import { HomeView } from "./components/HomeView";
import { LoginView } from "./components/LoginView";
import web3AuthConfig from "./web3authConfig";

// ─── Inner screen (must be a child of Web3AuthProvider) ───────────────────────
// IMP START - SDK Initialization
function Screen() {
const { isConnected, isInitializing, initError } = useWeb3Auth();
// IMP END - SDK Initialization

if (isInitializing) {
return (
<View style={styles.centered}>
<ActivityIndicator />
<Text style={styles.initText}>Initializing…</Text>
</View>
);
}

if (initError) {
return (
<View style={styles.centered}>
<Text style={styles.errorText}>Failed to initialize Web3Auth</Text>
<Text style={styles.errorDetail}>{String(initError)}</Text>
</View>
);
}

return isConnected ? <HomeView /> : <LoginView />;
}

// ─── Root ─────────────────────────────────────────────────────────────────────
export default function App() {
return (
// IMP START - Setup Web3Auth Provider
<Web3AuthProvider webBrowser={WebBrowser} storage={EncryptedStorage} config={web3AuthConfig}>
<SolanaProvider>
<SafeAreaProvider>
<Screen />
</SafeAreaProvider>
</SolanaProvider>
</Web3AuthProvider>
// IMP END - Setup Web3Auth Provider
);
}

const styles = StyleSheet.create({
centered: {
flex: 1,
alignItems: "center",
justifyContent: "center",
},
initText: {
marginTop: 12,
color: "#666",
},
errorText: {
fontWeight: "600",
color: "#c00",
marginBottom: 8,
},
errorDetail: {
color: "#666",
paddingHorizontal: 24,
textAlign: "center",
},
});
9 changes: 9 additions & 0 deletions demo/rn-bare-solana-example/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
source 'https://rubygems.org'

# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
ruby ">= 2.6.10"

# Cocoapods 1.15 introduced a bug which break the build. We will remove the upper
# bound in the template on Cocoapods with next React Native release.
gem 'cocoapods', '>= 1.13', '< 1.15'
gem 'activesupport', '>= 6.1.7.5', '< 7.1.0'
Loading