Skip to content

Commit 9abfd8a

Browse files
committed
Update sdk reference for react native mpc core kit
1 parent fc9f9f1 commit 9abfd8a

File tree

11 files changed

+768
-1099
lines changed

11 files changed

+768
-1099
lines changed

docs/sdk/mpc-core-kit/mpc-core-kit-js/install.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ npm install @toruslabs/tss-dkls-lib
4242

4343
This package gives EIP1193 compatible Ethereum signing provider. This provider is used to make calls
4444
to the selected blockchain, and can be used with `web3.js`, `ethers.js`, or `viem` to make
45-
integration with Ethereum-compatible chains more easier.
45+
integration with EVM compatible chains easier.
4646

4747
```bash npm2yarn
4848
npm install @web3auth/ethereum-mpc-provider

docs/sdk/mpc-core-kit/mpc-core-kit-js/signing.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ const receipt = await web3.eth.sendTransaction({
136136

137137
### Others
138138

139-
The secp256k1 support is not limited to only Ethereum-compatible chains. You can use the SDK with
140-
any blockchain ecosystem that supports the secp256k1 curve.
139+
The secp256k1 support is not limited to only EVM compatible chains. You can use the SDK with any
140+
blockchain ecosystem that supports the secp256k1 curve.
141141

142142
#### Get PublicKey
143143

docs/sdk/mpc-core-kit/mpc-core-kit-react-native/authentication.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: "Web3Auth MPC Core Kit JS SDK - Authentication"
2+
title: "Web3Auth MPC Core Kit React Native SDK - Authentication"
33
sidebar_label: "Authentication"
4-
description: "Web3Auth MPC Core Kit JS SDK - Authentication | Documentation - Web3Auth"
4+
description: "Web3Auth MPC Core Kit React Native SDK - Authentication | Documentation - Web3Auth"
55
---
66

77
import TabItem from "@theme/TabItem";
@@ -185,7 +185,7 @@ await coreKitInstance.loginWithJWT(jwtLoginParams);
185185

186186
To verify the user in the backend, you can retrieve the user's signature from frontend, and validate
187187
it using the `SignatureValidator` from the
188-
[@toruslabs/signature-validator](https://www.npmjs.com/package/@toruslabs/signature-validator)
188+
[`@toruslabs/signature-validator`](https://www.npmjs.com/package/@toruslabs/signature-validator)
189189
package in the backend.
190190

191191
### Retrieve user's signature
@@ -201,8 +201,8 @@ const signatures = coreKitInstance.signatures;
201201
### Verify the signatures in backend
202202

203203
For verification you'll need to install couple of packages,
204-
[@toruslabs/signature-validator](https://www.npmjs.com/package/@toruslabs/signature-validator) and
205-
[@toruslabs/fnd-base](https://www.npmjs.com/package/@toruslabs/fnd-base), and use
204+
[`@toruslabs/signature-validator`](https://www.npmjs.com/package/@toruslabs/signature-validator) and
205+
[`@toruslabs/fnd-base`](https://www.npmjs.com/package/@toruslabs/fnd-base), and use
206206
`SignatureValidator` to validate the signatures.
207207

208208
```js

docs/sdk/mpc-core-kit/mpc-core-kit-react-native/examples.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: Examples - MPC Core Kot SDK
2+
title: Examples - MPC Core Kit React Native SDK
33
sidebar_label: Examples
4-
description: "@web3auth/mpc-core-kit Examples | Documentation - Web3Auth"
4+
description: "Examples for MPC Core Kit React Native SDK | Documentation - Web3Auth"
55
hide_table_of_contents: true
66
---
77

docs/sdk/mpc-core-kit/mpc-core-kit-react-native/initialize.mdx

Lines changed: 61 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: "Initializing MPC Core Kit JS SDK for React Native"
2+
title: "Initializing MPC Core Kit React Native SDK"
33
sidebar_label: "Initialize"
4-
description: "Web3Auth MPC Core Kit JS SDK - Initialize for React Native | Documentation - Web3Auth"
4+
description: "Web3Auth MPC Core Kit React Native SDK - Initialize | Documentation - Web3Auth"
55
---
66

77
import ChainConfig from "@site/src/common/sdk/pnp/web/_chain-config.mdx";
@@ -48,36 +48,22 @@ export default function App() {
4848
}
4949
```
5050

51-
### Check for the Bridge State before Initing
52-
53-
The new package of React Native exposes a `resolveReady` callback that notifies when the bridge is
54-
ready to be used. Use this to init the SDK after the bridge has been configured.
55-
56-
```js
57-
useEffect(() => {
58-
if (bridgeReady) {
59-
const init = async () => {
60-
try {
61-
await coreKitInstance.init();
62-
} catch (error: any) {
63-
uiConsole(error.message, "mounted caught");
64-
}
65-
setCoreKitStatus(coreKitInstance.status);
66-
};
67-
init();
68-
}
69-
}, [bridgeReady]);
70-
```
71-
7251
## Configure Instance
7352

7453
Please note that these are the most critical steps where you need to pass on different parameters
7554
according to the preference of your project.
7655

7756
### Parameters
7857

79-
The Web3AuthMPCCoreKit constructor takes an object with `Web3AuthOptions` as input which helps you
80-
configure the SDK.
58+
The `mpclib.Web3AuthMPCCoreKitRN` constructor takes an object with `Web3AuthOptions` as input which
59+
helps you configure the SDK.
60+
61+
:::note
62+
63+
Please, note we for the simplicity, we use the `coreKitInstance` to refer to the instance of
64+
`mpclib.Web3AuthMPCCoreKitRN`.
65+
66+
:::
8167

8268
<Tabs
8369
defaultValue="table"
@@ -271,13 +257,11 @@ export declare const UX_MODE: {
271257

272258
```javascript
273259
import {
274-
makeEthereumSigner,
275260
mpclib,
276261
TssDklsLib,
277262
WEB3AUTH_NETWORK,
278263
Web3AuthOptions,
279264
} from "@web3auth/react-native-mpc-core-kit";
280-
import { EthereumSigningProvider } from "@web3auth/ethereum-mpc-provider";
281265
import EncryptedStorage from "react-native-encrypted-storage"; // Used to store the session & device factor keys
282266

283267
// setup async storage for react native
@@ -301,21 +285,6 @@ const coreKitInstance = new mpclib.Web3AuthMPCCoreKitRN({
301285
storage: asyncStorageKey, // Add the storage property
302286
} as Web3AuthOptions);
303287
// focus-end
304-
305-
const chainConfig = {
306-
chainNamespace: CHAIN_NAMESPACES.EIP155,
307-
chainId: "0xaa36a7", // Please use 0x1 for Mainnet
308-
rpcTarget: "https://rpc.ankr.com/eth_sepolia",
309-
displayName: "Ethereum Sepolia Testnet",
310-
blockExplorerUrl: "https://sepolia.etherscan.io/",
311-
blockExplorer: "https://sepolia.etherscan.io/",
312-
ticker: "ETH",
313-
tickerName: "Ethereum",
314-
};
315-
316-
// Setup provider for EVM Chain
317-
const evmProvider = new EthereumSigningProvider({ config: { chainConfig } });
318-
evmProvider.setupProvider(makeEthereumSigner(coreKitInstance));
319288
```
320289

321290
</TabItem>
@@ -372,13 +341,11 @@ const coreKitInstance = new mpclib.Web3AuthMPCCoreKitRN({
372341

373342
```javascript
374343
import {
375-
makeEthereumSigner,
376344
mpclib,
377345
TssDklsLib,
378346
WEB3AUTH_NETWORK,
379347
Web3AuthOptions,
380348
} from "@web3auth/react-native-mpc-core-kit";
381-
import { EthereumSigningProvider } from "@web3auth/ethereum-mpc-provider";
382349
import * as SecureStore from "expo-secure-store"; // Used to store the session & device factor keys
383350

384351
// setup async storage for react native
@@ -402,21 +369,6 @@ const coreKitInstance = new mpclib.Web3AuthMPCCoreKitRN({
402369
storage: asyncStorageKey, // Add the storage property
403370
} as Web3AuthOptions);
404371
// focus-end
405-
406-
const chainConfig = {
407-
chainNamespace: CHAIN_NAMESPACES.EIP155,
408-
chainId: "0xaa36a7", // Please use 0x1 for Mainnet
409-
rpcTarget: "https://rpc.ankr.com/eth_sepolia",
410-
displayName: "Ethereum Sepolia Testnet",
411-
blockExplorerUrl: "https://sepolia.etherscan.io/",
412-
blockExplorer: "https://sepolia.etherscan.io/",
413-
ticker: "ETH",
414-
tickerName: "Ethereum",
415-
};
416-
417-
// Setup provider for EVM Chain
418-
const evmProvider = new EthereumSigningProvider({ config: { chainConfig } });
419-
evmProvider.setupProvider(makeEthereumSigner(coreKitInstance));
420372
```
421373

422374
</TabItem>
@@ -461,6 +413,35 @@ const coreKitInstance = new mpclib.Web3AuthMPCCoreKitRN({
461413

462414
</Tabs>
463415

416+
## Additional Configuration for EVM Chains
417+
418+
If you are using the SDK with EVM compatible chains, you can use the `EthereumSigningProvider` to
419+
setup the provider for the EVM chain. This provider is EIP1193 compatible and can be used with
420+
`web3.js`, `ethers.js`, or `viem` to make integration with EVM compatible chains easier.
421+
422+
You need to pass in the `chainConfig` object to the provider. The `chainConfig` object contains the
423+
basic details of the chain you are using.
424+
425+
```js
426+
import { makeEthereumSigner } from "@web3auth/react-native-mpc-core-kit";
427+
import { EthereumSigningProvider } from "@web3auth/ethereum-mpc-provider";
428+
429+
const chainConfig = {
430+
chainNamespace: CHAIN_NAMESPACES.EIP155,
431+
chainId: "0xaa36a7", // Please use 0x1 for Mainnet
432+
rpcTarget: "https://rpc.ankr.com/eth_sepolia",
433+
displayName: "Ethereum Sepolia Testnet",
434+
blockExplorerUrl: "https://sepolia.etherscan.io/",
435+
blockExplorer: "https://sepolia.etherscan.io/",
436+
ticker: "ETH",
437+
tickerName: "Ethereum",
438+
};
439+
440+
// Setup provider for EVM Chain
441+
const evmProvider = new EthereumSigningProvider({ config: { chainConfig } });
442+
evmProvider.setupProvider(makeEthereumSigner(coreKitInstance));
443+
```
444+
464445
## Initialize Web3AuthMPCCoreKit
465446

466447
To initialize the instance, you need to call the `init` method. The method also takes the
@@ -512,3 +493,24 @@ export interface InitParams {
512493
// Web3AuthMPCCoreKit instance from previous steps
513494
await coreKitInstance.init();
514495
```
496+
497+
### Check for the Bridge State before Initing
498+
499+
The `Bridge` exposes a `resolveReady` callback that notifies when the SDK's bridge is ready to be
500+
used. Use this to init the SDK after the bridge has been configured.
501+
502+
```js
503+
useEffect(() => {
504+
if (bridgeReady) {
505+
const init = async () => {
506+
try {
507+
await coreKitInstance.init();
508+
} catch (error: any) {
509+
uiConsole(error.message, "mounted caught");
510+
}
511+
setCoreKitStatus(coreKitInstance.status);
512+
};
513+
init();
514+
}
515+
}, [bridgeReady]);
516+
```

docs/sdk/mpc-core-kit/mpc-core-kit-react-native/install.mdx

Lines changed: 71 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
---
2-
title: "Installing MPC Core Kit JS SDK"
2+
title: "Installing MPC Core Kit React Native SDK"
33
sidebar_label: "Install"
4-
description: "Web3Auth MPC Core Kit JS SDK - Install | Documentation - Web3Auth"
4+
description: "Web3Auth MPC Core Kit React Native SDK - Install | Documentation - Web3Auth"
55
---
66

7-
The MPC Core Kit JS SDK contains multiple packages that are needed to enable different
8-
functionalities of the MPC Core Kit JS SDK. You can choose the packages you want to install
9-
according to the functionalities you want to enable in your application. In this doc we have
7+
import TabItem from "@theme/TabItem";
8+
import Tabs from "@theme/Tabs";
9+
10+
The MPC Core Kit React Native SDK contains multiple packages that are needed to enable different
11+
functionalities of the MPC Core Kit React Native SDK. You can choose the packages you want to
12+
install according to the functionalities you want to enable in your application. In this doc we have
1013
highlighted all of the packages and their functionalities.
1114

1215
## Base MPC Core Kit React Native Package
@@ -28,17 +31,24 @@ recommend using it while working with Typescript.
2831
npm install @web3auth/base
2932
```
3033

31-
## EthereumSigningProvider
34+
## Ethereum Signing Provider
3235

3336
This package gives EIP1193 compatible Ethereum signing provider. This provider is used to make calls
3437
to the selected blockchain, and can be used with `web3.js`, `ethers.js`, or `viem` to make
35-
integration with Ethereum-compatible chains more easier.
38+
integration with EVM compatible chains easier.
3639

3740
```bash npm2yarn
3841
npm install @web3auth/ethereum-mpc-provider
3942
```
4043

41-
## Additional Configuration for React Native
44+
## Additional Configuration
45+
46+
### Install the following packages
47+
48+
```bash npm2yarn
49+
npm install react-native-react-bridge react-native-webview
50+
npm install --save-dev esbuild-plugins-node-modules-polyfill ts-node empty-module @craftzdog/react-native-buffer
51+
```
4252

4353
### Add a Custom Transformer
4454

@@ -65,6 +75,56 @@ module.exports.transform = function ({ src, filename, options }) {
6575
};
6676
```
6777

78+
<Tabs
79+
defaultValue="bare"
80+
values={[
81+
{ label: "Bare React Native", value: "bare" },
82+
{ label: "Expo", value: "expo" },
83+
]}
84+
>
85+
86+
<TabItem value="bare">
87+
88+
```js title="metro.config.js"
89+
require("ts-node/register");
90+
const { getDefaultConfig, mergeConfig } = require("@react-native/metro-config");
91+
92+
const config = {
93+
resolver: {
94+
extraNodeModules: {
95+
assert: require.resolve("empty-module"), // assert can be polyfilled here if needed
96+
http: require.resolve("empty-module"), // stream-http can be polyfilled here if needed
97+
https: require.resolve("empty-module"), // https-browserify can be polyfilled here if needed
98+
os: require.resolve("empty-module"), // os-browserify can be polyfilled here if needed
99+
url: require.resolve("empty-module"), // url can be polyfilled here if needed
100+
zlib: require.resolve("empty-module"), // browserify-zlib can be polyfilled here if needed
101+
path: require.resolve("empty-module"),
102+
crypto: require.resolve("empty-module"),
103+
buffer: require.resolve("@craftzdog/react-native-buffer"),
104+
},
105+
106+
assetExts: ["svg", "png", "json"],
107+
sourceExts: ["js", "mjs", "cjs", "jsx", "ts", "tsx"],
108+
},
109+
transformer: {
110+
getTransformOptions: async () => ({
111+
transform: {
112+
experimentalImportSupport: true,
113+
inlineRequires: true,
114+
},
115+
}),
116+
// This detects entry points of React app and transforms them
117+
babelTransformerPath: require.resolve("./customTransformer.js"),
118+
},
119+
};
120+
121+
module.exports = mergeConfig(getDefaultConfig(__dirname), config);
122+
```
123+
124+
</TabItem>
125+
126+
<TabItem value="expo">
127+
68128
```js title="metro.config.js"
69129
const config = getDefaultConfig(__dirname);
70130

@@ -89,19 +149,13 @@ config.resolver.extraNodeModules = {
89149
module.exports = config;
90150
```
91151

152+
</TabItem>
153+
</Tabs>
154+
92155
### Add Buffer in your globals/ entry level file
93156

94157
No need for `react-native-quick-crypto` any longer, just polyfill buffer in your entry file.
95158

96159
```js title="globals.ts"
97160
global.Buffer = require("buffer").Buffer;
98161
```
99-
100-
## Troubleshooting
101-
102-
You might face issues mentioning that certain dependencies are missing within the browser
103-
environment. These are node dependencies that need to be polyfilled in your application, to enable
104-
Web3Auth functionalities. Furthermore, your bundler needs to be reconfigured to use them while
105-
building the app. We have created guides for different bundlers to help you with this issue:
106-
107-
- Please check out our **[React Native Troubleshooting Guide](/troubleshooting/metro-issues-mpc)**

docs/sdk/mpc-core-kit/mpc-core-kit-react-native/signing.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: "Signing in MPC Core Kit JS SDK"
2+
title: "Signing in MPC Core Kit React Native SDK"
33
sidebar_label: "Signing"
4-
description: "Web3Auth MPC Core Kit JS SDK - Signing | Documentation - Web3Auth"
4+
description: "Web3Auth MPC Core Kit React Native SDK - Signing | Documentation - Web3Auth"
55
---
66

77
import Ed25519Installation from "@site/src/common/sdk/mpc-core-kit/_solana-installation.mdx";
@@ -210,8 +210,8 @@ const receipt = await web3.eth.sendTransaction({
210210

211211
### Others
212212

213-
The secp256k1 support is not limited to only Ethereum-compatible chains. You can use the SDK with
214-
any blockchain ecosystem that supports the secp256k1 curve.
213+
The secp256k1 support is not limited to only EVM compatible chains. You can use the SDK with any
214+
blockchain ecosystem that supports the secp256k1 curve.
215215

216216
#### Get PublicKey
217217

0 commit comments

Comments
 (0)