Configuration
SDK configuration options, initialization flow, protocol selection, and storage setup
Configuration
SDKConfig
The NeroMpcSDK constructor accepts an SDKConfig object that controls all SDK behavior:
| Property | Type | Default | Description |
|---|---|---|---|
backendUrl | string | Required | Base URL for the NERO backend API |
apiKey | string | — | Project API key sent in X-API-Key header |
deviceId | string | — | Stable device identifier |
chainId | number | 689 | EVM chain ID (689 = NERO Testnet) |
protocol | "dkls" | "pedersen" | "dkls" | MPC protocol variant |
storagePrefix | string | "nero" | Namespace prefix for all storage keys |
autoConnect | boolean | true | Attempt session restoration on initialize() |
wsUrl | string | — | WebSocket URL for real-time MPC coordination (required for Pedersen) |
storage | StorageAdapter | createTokenStorage() | Custom storage implementation |
sessionTime | number | — | Session lifetime override in seconds |
uiConfig | UIConfig | — | Visual customization for modal components |
requestMiddleware | RequestMiddleware[] | — | Custom middleware for API requests |
retryConfig | RetryConfig | — | Custom retry configuration for API requests |
Initialization Flow
The SDK initializes in two distinct phases:
Phase 1 — Construction
When you call new NeroMpcSDK(config), the constructor creates core subsystems:
APIClientfor HTTP communicationChainManagerfor blockchain network managementStorageAdapterfor token persistence- Optional
WebSocketClientifwsUrlis provided
Phase 2 — initialize()
When you call await sdk.initialize(), the SDK performs asynchronous setup:
- Loads or generates a persistent
deviceKeyfrom storage viaClientKeyManager - Instantiates
ClientKeyManagerwith the device key - Attempts to restore an existing session using stored tokens
- If authentication tokens are found and valid, populates the user profile and wallet information
- Initializes protocol-specific wallet (
SmartWalletfor Pedersen,DKLSClientfor DKLS)
The SDK prefers IndexedDBStorage for device key storage and automatically migrates legacy keys from localStorage. The full device key loading sequence:
- Attempt to retrieve from IndexedDB
- Check for legacy key in localStorage
- Migrate if found in localStorage
- Generate a new cryptographically random key if not found
- Store using the best available mechanism (IndexedDB preferred, localStorage fallback)
After initialization completes, query the current state via the state getter:
const sdk = new NeroMpcSDK({
backendUrl: "https://your-api.example.com",
apiKey: "your-project-api-key",
});
await sdk.initialize();
console.log(sdk.state.isInitialized); // true
console.log(sdk.state.isAuthenticated); // true if session was restored
console.log(sdk.state.hasWallet); // true if wallet exists
console.log(sdk.state.isConnected); // true if provider is connectedThe SDK emits an "initialized" event when this phase completes, so you can react to completion without polling:
sdk.on("initialized", () => {
console.log("SDK ready:", sdk.state);
});Protocol Selection
The protocol field determines the key generation algorithm, signature computation method, and wallet type.
DKLS (Default)
| Property | Value |
|---|---|
| Protocol | 2-party DKLS threshold ECDSA |
| Wallet type | EOA (Externally Owned Account) |
| Transport | HTTP API requests |
| Client class | DKLSClient |
Best for most applications. Efficient signing with direct EOA wallets.
const sdk = new NeroMpcSDK({
backendUrl: "https://your-api.example.com",
apiKey: "your-project-api-key",
protocol: "dkls",
});Pedersen DKG
| Property | Value |
|---|---|
| Protocol | Pedersen DKG version 2 |
| Wallet type | Smart contract wallet (ERC-4337) |
| Transport | WebSocket for real-time round coordination |
| Client class | DKGClient |
Requires a WebSocket URL for real-time protocol coordination:
const sdk = new NeroMpcSDK({
backendUrl: "https://your-api.example.com",
apiKey: "your-project-api-key",
protocol: "pedersen",
wsUrl: "wss://your-ws.example.com",
});UIConfig
Customize the look of modal components via SDKConfig.uiConfig:
| Field | Type | Description |
|---|---|---|
appName | string | Application name displayed in modals |
logoLight | string | Light mode logo URL |
logoDark | string | Dark mode logo URL |
mode | "light" | "dark" | "auto" | Theme mode |
theme | object | CSS color overrides: primary, secondary, background, text, border |
Storage Configuration
The SDK uses multiple storage mechanisms depending on data type:
| Storage type | Managed by | Default backend | Purpose |
|---|---|---|---|
| Token storage | _tokenStorage | IndexedDBStorage | JWTs and session metadata |
| Key share storage | Protocol-dependent | IndexedDBStorage or MemoryStorage | Encrypted MPC key shares |
All storage keys use the storagePrefix (default "nero") to avoid collisions between SDK instances:
const sdk = new NeroMpcSDK({
backendUrl: "https://your-api.example.com",
storagePrefix: "my-app",
});Custom Storage Adapter
You can provide your own storage implementation via the storage field. It must satisfy the StorageAdapter interface:
export interface StorageAdapter {
get(key: string): Promise<string | null>;
set(key: string, value: string): Promise<void>;
delete(key: string): Promise<void>;
clear(): Promise<void>;
}Chain Configuration
Use the pre-defined chain configurations from the chains module:
import { NERO_TESTNET } from "@nerochain/mpc-sdk/chains";
const sdk = new NeroMpcSDK({
backendUrl: "https://your-api.example.com",
chainId: NERO_TESTNET.chainId,
});Switch chains at runtime using:
await sdk.switchChain(newChainId);Core Type Reference
User
Populated after successful login:
| Field | Type |
|---|---|
id | string |
email | string | undefined |
displayName | string | undefined |
walletAddress | string | undefined |
createdAt | Date |
AuthTokens
Token bundle used for API authorization:
| Field | Type | Description |
|---|---|---|
accessToken | string | Short-lived JWT for API requests |
refreshToken | string | Long-lived token for access token renewal |
expiresAt | number | Unix timestamp for access token expiration |
dappShare | string | undefined | Opaque session portability token |
WalletInfo
Describes the user's MPC wallet:
| Field | Type | Description |
|---|---|---|
eoaAddress | string | Ethereum address derived from public key |
smartWalletAddress | string | undefined | ERC-4337 smart account address |
publicKey | string | Hex-encoded public key |
Signature
Final assembled Ethereum-compatible signature:
| Field | Type |
|---|---|
r | string |
s | string |
v | number |
fullSignature | string |