Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update MPC Core Kit Expo App to new SDK #711

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,7 @@ tests/cases/user/prettier/prettier
build
single-factor-auth-web/sfa-web-ton-telegram-example/src/.env
single-factor-auth-web/sfa-web-ton-telegram-example/src/.env
Pods/
.gradle/
.xcode.env.local
expo-env.d.ts
53 changes: 28 additions & 25 deletions mpc-core-kit-react-native/mpc-core-kit-rn-expo-auth0/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import "./globals";
import "@ethersproject/shims";

import { Bridge, tssLib } from "@toruslabs/react-native-tss-lib-bridge";
import { CHAIN_NAMESPACES } from "@web3auth/base";
import { EthereumSigningProvider } from "@web3auth/ethereum-mpc-provider";
// IMP START - Quick Start
Expand All @@ -15,8 +14,8 @@ import {
parseToken,
TssShareType,
WEB3AUTH_NETWORK,
Web3AuthMPCCoreKit,
} from "@web3auth/mpc-core-kit";
import { Bridge, mpclib, TssDklsLib } from "@web3auth/react-native-mpc-core-kit";
// IMP END - Quick Start
import { BN } from "bn.js";
import { ethers } from "ethers";
Expand Down Expand Up @@ -47,7 +46,6 @@ const chainConfig = {
tickerName: "Ethereum",
};

const tsslibInstance = tssLib;
// setup async storage for react native
const asyncStorageKey = {
getItem: async (key: string) => {
Expand All @@ -58,12 +56,12 @@ const asyncStorageKey = {
},
};

const coreKitInstance = new Web3AuthMPCCoreKit({
const coreKitInstance = new mpclib.Web3AuthMPCCoreKitRN({
web3AuthClientId,
web3AuthNetwork: WEB3AUTH_NETWORK.MAINNET,
// setupProviderOnInit: false, // needed to skip the provider setup
uxMode: "react-native",
tssLib: tsslibInstance, // tss lib bridge for react native
tssLib: TssDklsLib, // tss lib bridge for react native
manualSync: true, // This is the recommended approach
storage: asyncStorageKey, // Add the storage property
});
Expand All @@ -75,25 +73,28 @@ evmProvider.setupProvider(makeEthereumSigner(coreKitInstance));

function Home() {
const [loading, setLoading] = useState<boolean>(false);
const [bridgeReady, setBridgeReady] = useState<boolean>(false);
const [consoleUI, setConsoleUI] = useState<string>("");
const [coreKitStatus, setCoreKitStatus] = useState<COREKIT_STATUS>(COREKIT_STATUS.NOT_INITIALIZED);
const [backupFactorKey, setBackupFactorKey] = useState<string>("");
const [mnemonicFactor, setMnemonicFactor] = useState<string>("");

useEffect(() => {
const init = async () => {
try {
// IMP START - SDK Initialization
await coreKitInstance.init();
// IMP END - SDK Initialization
} catch (error: any) {
uiConsole(error.message, "mounted caught");
}
setCoreKitStatus(coreKitInstance.status);
};
init();
if (bridgeReady) {
const init = async () => {
try {
// IMP START - SDK Initialization
await coreKitInstance.init();
// IMP END - SDK Initialization
} catch (error: any) {
uiConsole(error.message, "mounted caught");
}
setCoreKitStatus(coreKitInstance.status);
};
init();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [bridgeReady]);

const { authorize, getCredentials } = useAuth0();

Expand Down Expand Up @@ -194,12 +195,12 @@ function Home() {
try {
setConsoleUI("Enabling MFA, please wait");

const factorKey = await coreKitInstance.enableMFA({});
const factorKey = await coreKitInstance.enableMFA({}, false);
const factorKeyMnemonic = keyToMnemonic(factorKey);

uiConsole("MFA enabled, device factor stored in local store, deleted hashed cloud key, your backup factor key: ", factorKeyMnemonic);
} catch (error: any) {
uiConsole(error.message);
uiConsole("Error", error);
}
setLoading(false);

Expand All @@ -213,7 +214,7 @@ function Home() {
if (!coreKitInstance) {
throw new Error("coreKitInstance not found");
}
uiConsole(coreKitInstance.getKeyDetails());
uiConsole(await coreKitInstance.getKeyDetails());
};

const getDeviceFactor = async () => {
Expand Down Expand Up @@ -420,10 +421,7 @@ function Home() {
// if (selectedNetwork === WEB3AUTH_NETWORK.MAINNET) {
// throw new Error("reset account is not recommended on mainnet");
// }
await coreKitInstance.tKey.storageLayer.setMetadata({
privKey: new BN(coreKitInstance.state.postBoxKey!, "hex"),
input: { message: "KEY_NOT_FOUND" },
});
await coreKitInstance._UNSAFE_resetAccount();
uiConsole("reset");
if (coreKitInstance.status === COREKIT_STATUS.LOGGED_IN) {
await coreKitInstance.commitChanges();
Expand Down Expand Up @@ -489,6 +487,12 @@ function Home() {
<Text>{consoleUI}</Text>
</ScrollView>
</View>
<Bridge
logLevel={"DEBUG"}
resolveReady={(ready) => {
setBridgeReady(ready);
}}
/>
</View>
);
}
Expand All @@ -499,7 +503,6 @@ export default function App() {
<Auth0Provider domain={"https://web3auth.au.auth0.com"} clientId={"hUVVf4SEsZT7syOiL0gLU9hFEtm2gQ6O"}>
<Home />
</Auth0Provider>
<Bridge logLevel={"debug"} />
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const { nodeModulesPolyfillPlugin } = require("esbuild-plugins-node-modules-polyfill");
const reactNativeReactBridgeTransformer = require("react-native-react-bridge/lib/plugin");
const esbuildOptions = {
plugins: [
nodeModulesPolyfillPlugin({
globals: {
Buffer: true,
crypto: true,
},
// modules: {
// Buffer : true,
// }
}),
],
};
module.exports.transform = function ({ src, filename, options }) {
const transform = reactNativeReactBridgeTransformer.createTransformer(esbuildOptions);
return transform({ src, filename, options });
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
import { install } from "react-native-quick-crypto";

install();
global.Buffer = require('buffer').Buffer;
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ PODS:
- DoubleConversion (1.1.6)
- EXConstants (16.0.2):
- ExpoModulesCore
- Expo (51.0.34):
- Expo (51.0.39):
- ExpoModulesCore
- ExpoAsset (10.0.10):
- ExpoModulesCore
Expand All @@ -21,7 +21,7 @@ PODS:
- ExpoModulesCore
- ExpoKeepAwake (13.0.2):
- ExpoModulesCore
- ExpoModulesCore (1.12.24):
- ExpoModulesCore (1.12.26):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -53,7 +53,6 @@ PODS:
- hermes-engine/Pre-built (= 0.74.5)
- hermes-engine/Pre-built (0.74.5)
- JWTDecode (3.1.0)
- OpenSSL-Universal (3.3.2000)
- RCT-Folly (2024.01.01.00):
- boost
- DoubleConversion
Expand Down Expand Up @@ -982,30 +981,7 @@ PODS:
- React-Mapbuffer (0.74.5):
- glog
- React-debug
- react-native-quick-crypto (0.7.5):
- DoubleConversion
- glog
- hermes-engine
- OpenSSL-Universal
- RCT-Folly (= 2024.01.01.00)
- RCTRequired
- RCTTypeSafety
- React
- React-Codegen
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-ImageManager
- React-NativeModulesApple
- React-RCTFabric
- React-rendererdebug
- React-utils
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- Yoga
- react-native-webview (13.8.6):
- react-native-webview (13.12.5):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -1301,7 +1277,6 @@ DEPENDENCIES:
- React-jsitracing (from `../node_modules/react-native/ReactCommon/hermes/executor/`)
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
- React-Mapbuffer (from `../node_modules/react-native/ReactCommon`)
- react-native-quick-crypto (from `../node_modules/react-native-quick-crypto`)
- react-native-webview (from `../node_modules/react-native-webview`)
- React-nativeconfig (from `../node_modules/react-native/ReactCommon`)
- React-NativeModulesApple (from `../node_modules/react-native/ReactCommon/react/nativemodule/core/platform/ios`)
Expand Down Expand Up @@ -1332,7 +1307,6 @@ SPEC REPOS:
trunk:
- Auth0
- JWTDecode
- OpenSSL-Universal
- SimpleKeychain
- SocketRocket

Expand Down Expand Up @@ -1416,8 +1390,6 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/logger"
React-Mapbuffer:
:path: "../node_modules/react-native/ReactCommon"
react-native-quick-crypto:
:path: "../node_modules/react-native-quick-crypto"
react-native-webview:
:path: "../node_modules/react-native-webview"
React-nativeconfig:
Expand Down Expand Up @@ -1475,19 +1447,18 @@ SPEC CHECKSUMS:
boost: d3f49c53809116a5d38da093a8aa78bf551aed09
DoubleConversion: 76ab83afb40bddeeee456813d9c04f67f78771b5
EXConstants: 409690fbfd5afea964e5e9d6c4eb2c2b59222c59
Expo: 963ef4ae102e4f4ac114a8510d70127c44adffbf
Expo: 8c995afb875c15bf8439af0b20bcb9ed8f90d0bd
ExpoAsset: 323700f291684f110fb55f0d4022a3362ea9f875
ExpoFileSystem: 80bfe850b1f9922c16905822ecbf97acd711dc51
ExpoFont: 00756e6c796d8f7ee8d211e29c8b619e75cbf238
ExpoKeepAwake: 3b8815d9dd1d419ee474df004021c69fdd316d08
ExpoModulesCore: f30a203ff1863bab3dd9f4421e7fc1564797f18a
ExpoModulesCore: 831ece8311a489418746925820bbffdda587d6f4
ExpoSecureStore: 060cebcb956b80ddae09821610ac1aa9e1ac74cd
FBLazyVector: ac12dc084d1c8ec4cc4d7b3cf1b0ebda6dab85af
fmt: 4c2741a687cc09f0634a2e2c72a838b99f1ff120
glog: fdfdfe5479092de0c4bdbebedd9056951f092c4f
hermes-engine: 8c1577f3fdb849cbe7729c2e7b5abc4b845e88f8
JWTDecode: 3eaab1e06b6f4dcbdd6716aff09ba4c2104ca8b7
OpenSSL-Universal: b60a3702c9fea8b3145549d421fdb018e53ab7b4
RCT-Folly: 02617c592a293bd6d418e0a88ff4ee1f88329b47
RCTDeprecation: 3afceddffa65aee666dafd6f0116f1d975db1584
RCTRequired: ec1239bc9d8bf63e10fb92bd8b26171a9258e0c1
Expand All @@ -1512,8 +1483,7 @@ SPEC CHECKSUMS:
React-jsitracing: 3b6060bbf5317663667e1dd93560c7943ab86ccc
React-logger: 257858bd55f3a4e1bc0cf07ddc8fb9faba6f8c7c
React-Mapbuffer: 6c1cacdbf40b531f549eba249e531a7d0bfd8e7f
react-native-quick-crypto: 7085e4e4607e7e8fa57f4193f994d5262d351e45
react-native-webview: 05bae3a03a1e4f59568dfc05286c0ebf8954106c
react-native-webview: 66f10ef00efe847017fc1c809a84c412712bbef6
React-nativeconfig: ba9a2e54e2f0882cf7882698825052793ed4c851
React-NativeModulesApple: 8d11ff8955181540585c944cf48e9e7236952697
React-perflogger: ed4e0c65781521e0424f2e5e40b40cc7879d737e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,10 @@
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-mpccorekitexpoauth0/Pods-mpccorekitexpoauth0-frameworks.sh",
"${PODS_XCFRAMEWORKS_BUILD_DIR}/OpenSSL-Universal/OpenSSL.framework/OpenSSL",
"${PODS_XCFRAMEWORKS_BUILD_DIR}/hermes-engine/Pre-built/hermes.framework/hermes",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/OpenSSL.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/hermes.framework",
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { getDefaultConfig } = require("expo/metro-config");
/** @type {import('expo/metro-config').MetroConfig} */
const config = getDefaultConfig(__dirname);

config.transformer.babelTransformerPath = require.resolve("react-native-react-bridge/lib/plugin");
config.transformer.babelTransformerPath = require.resolve('./customTransformer.js')
config.resolver.extraNodeModules = {
...config.resolver.extraNodeModules,

Expand Down
Loading
Loading