NeroMpcSDK Class
Complete API reference for the main SDK class -- constructor, methods, properties, and events
NeroMpcSDK
The NeroMpcSDK class is the primary entry point for the NERO MPC SDK. It orchestrates all subsystems including APIClient for HTTP communication, ClientKeyManager for key storage, protocol-specific clients (DKLSClient or DKGClient), and ChainManager for blockchain configuration.
Constructor
new NeroMpcSDK(config: SDKConfig)Applies defaults:
chainId: 689storagePrefix:"nero"autoConnect: trueprotocol:"dkls"
Instantiates APIClient, ChainManager, and optionally WebSocketClient (when wsUrl is provided for Pedersen protocol).
Factory Function
createNeroSDK(config: SDKConfig): NeroMpcSDKFunctionally identical to new NeroMpcSDK(config).
Public Properties
| Property | Type | Description |
|---|---|---|
isAuthenticated | boolean | Returns true when user and valid tokens exist |
hasWallet | boolean | Protocol-aware check (DKLS: _dklsWalletAddress !== null, Pedersen: _wallet !== null) |
connected | boolean | Checks EIP-1193 provider connection status |
status | ConnectionStatus | Current connection state: "disconnected", "connecting", "connected", "reconnecting" |
user | User | null | Current authenticated user; null if not logged in |
wallet | SmartWallet | null | Wallet instance (Pedersen only) |
chainId | number | Active chain ID; mutable via switchChain() |
provider | NeroProvider | null | EIP-1193 provider instance |
state | NeroSDKState | Snapshot containing all key state properties |
Methods
Initialization
initialize(): Promise<void>
Loads device key, restores session, and initializes wallet. Call this after constructing the SDK.
Authentication
getOAuthUrl(provider: string, redirectUri: string): Promise<{ url: string }>
Returns the OAuth URL and state for the specified provider. Redirect the user to the returned URL.
handleOAuthCallback(provider: string, code: string, state: string): Promise<{ user: User; requiresDKG: boolean }>
Processes the OAuth redirect callback. Returns the authenticated user and whether key generation is needed.
loginWithEmail(email: string): Promise<void>
Sends an OTP or magic link to the specified email address.
verifyEmailLogin(email: string, code: string): Promise<SocialLoginResponse>
Completes email verification with the OTP code.
Wallet Operations
generateWallet(): Promise<WalletInfo>
Triggers the MPC key generation protocol (DKG or DKLS keygen depending on configured protocol). Requires authentication.
getWallets(): Promise<WalletInfo[]>
Retrieves wallet metadata from the backend.
Signing
signMessage(message: string): Promise<string>
Signs a raw message using EIP-191 personal signing prefix.
signTransaction(txParams: TransactionRequest): Promise<string>
Signs a transaction object using the MPC protocol.
signTypedData(domain: object, types: object, value: object): Promise<string>
Signs EIP-712 typed data.
Provider
connect(): Promise<NeroProvider>
Initializes the EIP-1193 provider and transitions to connected state. Returns the provider instance.
disconnect(): Promise<void>
Disconnects the provider and logs out.
getProvider(): NeroProvider
Returns the current EIP-1193 provider instance.
Chain Management
switchChain(chainId: number): Promise<void>
Updates the SDK's active chain. Validates the chain is either built-in or previously added via addChain. Calls notifyListeners to trigger UI updates or provider reconfigurations.
addChain(config: ChainConfig): void
Registers custom networks not included in SDK defaults.
Event System
Methods
| Method | Description |
|---|---|
on(event, listener) | Register event listener |
off(event, listener) | Unregister event listener |
once(event, listener) | Register one-time listener |
Events
| Event | Description |
|---|---|
"initialized" | After initialization completion |
"login" | After successful authentication |
"logout" | After session clearance |
"connected" | When EIP-1193 provider is ready |
"disconnected" | When provider disconnects |
sdk.on("login", ({ user }) => {
console.log(`User logged in: ${user.id}`);
});
sdk.on("connected", ({ chainId }) => {
console.log(`Connected to chain ${chainId}`);
});
sdk.once("initialized", () => {
console.log("SDK ready");
});Dual Protocol Architecture
| Protocol | Mode | Key Property | Use Case |
|---|---|---|---|
| DKLS (default) | 2-party threshold ECDSA | Multiplicative secret sharing | Direct EOA wallet, efficient signing |
| Pedersen DKG | Distributed key generation | Verifiable secret sharing | Smart account (ERC-4337), multi-party |
Protocol selection via config.protocol determines key generation algorithm, signature computation method, and wallet type.
Package Module Structure
| Export Path | Entry File | Purpose |
|---|---|---|
@nerochain/mpc-sdk | src/index.ts | Core SDK class and base types |
@nerochain/mpc-sdk/react | src/react/index.ts | React context provider and hooks |
@nerochain/mpc-sdk/chains | src/chains/index.ts | Chain configurations and ChainManager |
@nerochain/mpc-sdk/modal | src/modal/index.ts | Pre-built UI components |
@nerochain/mpc-sdk/no-modal | src/no-modal/index.ts | Headless SDK for custom UI |
@nerochain/mpc-sdk/aa | src/aa/index.ts | ERC-4337 Smart Account support |
Peer Dependencies
Required:
@noble/curves^1.4.0@noble/hashes^1.4.0
Optional:
react^18.0.0 (for React entry points)ethers^6.0.0 (for Account Abstraction)@metamask/sdk^0.20.0 (for MetaMask adapter)