How web3auth/mpc-core-kit works
Project type and purpose
• This is an open-source wrapper SDK (npm package) named “Web3Auth MPC Core Kit.”
• Its purpose is to expose a set of client-side functions that let developers integrate passwordless Web3 authentication (via MPC + OAuth or JWT) into their own front-end apps or wallets.
File structure
• Top-level config:
• .eslintrc.js, .prettierrc.yaml, tsconfig.json, webpack.config.js – linting, formatting, TypeScript compilation, bundling.
• package.json, package-lock.json – dependencies, build scripts.
• tests/ – unit tests for core functions (factors, session timing, import recovery, etc.).
• Core source (src/):
• mpcCoreKit.ts – main entry point exporting the Web3AuthMPCCoreKit class.
• constants.ts, interfaces.ts, helper/, utils.ts – supporting modules (browserStorage, factorSerialization, error handling, security question logic).
• index.ts – public API surface.
• Example/demo (demo/redirect-flow-example/): a standalone React/Vite app illustrating usage of the SDK.
README for additional insights
• Confirms the core responsibilities: initialize Web3Auth with chain config, call loginWithOAuth or loginWithJWT, obtain a provider for blockchain RPC calls.
• Mentions interaction with external Web3Auth Dashboard (client ID) and external blockchain RPC endpoints.
a. Main components
• Client Application (your UI code / demo app)
• Web3Auth MPC Core Kit SDK (library modules)
• Web3Auth MPC Network (Torus nodes / threshold key service)
• OAuth Identity Providers (Google, Twitter, Discord, etc.) and/or JWT IdP
• Blockchain RPC Node (Ethereum, etc.)
• Browser Storage (local/session storage for storing key shares)
b. Relationships and interactions
1. Client App imports and initializes the SDK with a web3AuthClientId and chainConfig.
2. Client App calls sdk.init() → SDK connects to Web3Auth network over HTTPS/WebSocket to fetch its key share.
3. User clicks “Login” → SDK triggers OAuth2 flow or JWT exchange with the external identity provider.
4. OAuth IdP redirects back to the Client App → SDK reconstructs the private key via MPC: combining the server share (Web3Auth nodes) and the client share (in browser storage).
5. SDK exposes a Web3 provider → Client App uses it to send RPC calls to the configured blockchain RPC node.
c. Architectural patterns and principles
• Facade/Wrapper: the SDK abstracts away complexity of MPC, OAuth, key management, exposing a simple API.
• Modular design: helper modules (serialization, storage, security questions) are decoupled.
• Clientside‐first: all cryptographic key operations happen in the browser, with no custodial exposure.
d. Key technologies and libraries
• TypeScript (src/, interfaces, tsconfig)
• Webpack (bundling for distribution)
• Jest/Mocha (tests/*.spec.ts)
• Vite/React (demo app)
• OAuth2 / JWT protocols
• JSON RPC (blockchain interactions)
Detail
• Initialization module (mpcCoreKit.init)
• OAuth/JWT handlers (loginWithOAuth, loginWithJWT)
• Storage & serialization helpers
• Provider factory for RPC calls
• Error handling paths (helper/errors.ts) and developer-configurable surfaces (constants.ts, interfaces.ts).