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

Feat/web3auth wallet #1679

Draft
wants to merge 1 commit into
base: feat/atlas-siwe
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@
"@supabase/supabase-js": "^2.39.3",
"@tanstack/react-query": "^5.40.1",
"@types/react-modal": "^3.16.3",
"@web3auth/ethereum-provider": "^8.12.4",
"@web3auth/modal": "^8.12.6",
"@web3auth/web3auth-wagmi-connector": "^6.0.0",
"@web3modal/wagmi": "^4.1.10",
"@yornaath/batshit": "^0.9.0",
"amqplib": "^0.10.3",
Expand Down
9 changes: 7 additions & 2 deletions web/src/context/Web3Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import React from "react";
import { createWeb3Modal } from "@web3modal/wagmi/react";
import { type Chain } from "viem";
import { createConfig, fallback, http, WagmiProvider, webSocket } from "wagmi";
import { mainnet, arbitrumSepolia, arbitrum, gnosisChiado, gnosis, sepolia } from "wagmi/chains";
import { arbitrum, arbitrumSepolia, gnosis, gnosisChiado, mainnet, sepolia } from "wagmi/chains";
import { walletConnect } from "wagmi/connectors";

import { ALL_CHAINS, DEFAULT_CHAIN } from "consts/chains";
import { isProductionDeployment } from "consts/index";

import { lightTheme } from "styles/themes";
import { Web3AuthConnectorInstance, Web3AuthInstance } from "~src/utils/Web3AuthInstance";

const alchemyApiKey = import.meta.env.ALCHEMY_API_KEY ?? "";
const isProduction = isProductionDeployment();
Expand Down Expand Up @@ -56,10 +57,14 @@ export const getTransports = () => {
const chains = ALL_CHAINS as [Chain, ...Chain[]];
const transports = getTransports();
const projectId = import.meta.env.WALLETCONNECT_PROJECT_ID ?? "";

// Create Web3Auth Instance
const web3AuthInstance = Web3AuthInstance(chains, "Kleros-V2");

const wagmiConfig = createConfig({
chains,
transports,
connectors: [walletConnect({ projectId })],
connectors: [walletConnect({ projectId }), Web3AuthConnectorInstance(web3AuthInstance)],
});

createWeb3Modal({
Expand Down
75 changes: 75 additions & 0 deletions web/src/utils/Web3AuthInstance.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Web3Auth Libraries
import { CHAIN_NAMESPACES, WALLET_ADAPTERS, WEB3AUTH_NETWORK } from "@web3auth/base";
import { EthereumPrivateKeyProvider } from "@web3auth/ethereum-provider";
import { Web3Auth } from "@web3auth/modal";
import { Web3AuthConnector } from "@web3auth/web3auth-wagmi-connector";
import { Chain } from "wagmi/chains";

// Create Web3AuthConnector Instance
export function Web3AuthConnectorInstance(web3AuthInstance: Web3Auth) {
const modalConfig = {
[WALLET_ADAPTERS.OPENLOGIN]: {
label: "openlogin",
loginMethods: {
facebook: {
// it will hide the facebook option from the Web3Auth modal.
name: "facebook login",
showOnModal: false,
},
},
// setting it to false will hide all social login methods from modal.
showOnModal: true,
},
};

return Web3AuthConnector({
web3AuthInstance,
modalConfig,
});
}

export function Web3AuthInstance(chains: Chain[], appName: string) {
// Create Web3Auth Instance
const name = appName;
console.log(chains[0].id);
const chainConfig = {
chainNamespace: CHAIN_NAMESPACES.EIP155,
chainId: "0x" + chains[0].id.toString(16),
rpcTarget: chains[0].rpcUrls.default.http[0], // This is the public RPC we have added, please pass on your own endpoint while creating an app
displayName: chains[0].name,
tickerName: chains[0].nativeCurrency?.name,
ticker: chains[0].nativeCurrency?.symbol,
blockExplorerUrl: chains[0].blockExplorers?.default.url[0] as string,
};

const privateKeyProvider = new EthereumPrivateKeyProvider({ config: { chainConfig } });

const web3AuthInstance = new Web3Auth({
clientId: "BL8AeNAyRT1eZuwyXy3DimD4Ez4Bedcx2f7BxgQQdMVRE5fnlqtQp__XK-rGec1C5vbdQCTIxvtb7nPtgrpmjHQ",
Copy link
Contributor

Choose a reason for hiding this comment

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

Do not hardcode sensitive information in the source code.

The client ID string is a sensitive piece of information that should not be hardcoded in the source code. Hardcoding sensitive information in the source code is a security risk, as it can be easily exposed if the source code is compromised.

Store the client ID string in a secure location, such as an environment variable or a secrets management system, and access it at runtime. For example:

-const web3AuthInstance = new Web3Auth({
-  clientId: "BL8AeNAyRT1eZuwyXy3DimD4Ez4Bedcx2f7BxgQQdMVRE5fnlqtQp__XK-rGec1C5vbdQCTIxvtb7nPtgrpmjHQ",
-  chainConfig,
-  privateKeyProvider,
-  uiConfig: {
-    appName: name,
-    loginMethodsOrder: ["github", "google"],
-    defaultLanguage: "en",
-    modalZIndex: "2147483647",
-    logoLight: "https://web3auth.io/images/web3authlog.png",
-    logoDark: "https://web3auth.io/images/web3authlogodark.png",
-    uxMode: "popup",
-    mode: "light",
-  },
-  web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_DEVNET,
-  enableLogging: true,
-});
+const web3AuthInstance = new Web3Auth({
+  clientId: process.env.WEB3AUTH_CLIENT_ID,
+  chainConfig,
+  privateKeyProvider,
+  uiConfig: {
+    appName: name,
+    loginMethodsOrder: ["github", "google"],
+    defaultLanguage: "en",
+    modalZIndex: "2147483647",
+    logoLight: "https://web3auth.io/images/web3authlog.png",
+    logoDark: "https://web3auth.io/images/web3authlogodark.png",
+    uxMode: "popup",
+    mode: "light",
+  },
+  web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_DEVNET,
+  enableLogging: true,
+});
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
clientId: "BL8AeNAyRT1eZuwyXy3DimD4Ez4Bedcx2f7BxgQQdMVRE5fnlqtQp__XK-rGec1C5vbdQCTIxvtb7nPtgrpmjHQ",
clientId: process.env.WEB3AUTH_CLIENT_ID,
Tools
Gitleaks

48-48: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

chainConfig,
privateKeyProvider,
uiConfig: {
appName: name,
loginMethodsOrder: ["github", "google"],
defaultLanguage: "en",
modalZIndex: "2147483647",
logoLight: "https://web3auth.io/images/web3authlog.png",
logoDark: "https://web3auth.io/images/web3authlogodark.png",
uxMode: "popup",
mode: "light",
},
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_DEVNET,
enableLogging: true,
});

/* const walletServicesPlugin = new WalletServicesPlugin({
walletInitOptions: {
whiteLabel: {
showWidgetButton: true,
}
}
});
web3AuthInstance.addPlugin(walletServicesPlugin); */

return web3AuthInstance;
}
Loading
Loading