React SDKHooks
useNeroRecovery
Recovery methods, self-custody recovery, backup export/import, and factor management
useNeroRecovery
The Nero MPC SDK provides three React hooks for managing recovery and backup functionality: useNeroRecovery, useNeroBackup, and useNeroFactors.
Hook Responsibility Division
| Hook | Responsibility |
|---|---|
useNeroRecovery | Recovery method lifecycle, self-custody recovery setup, offline key reconstruction |
useNeroBackup | V2 backup export/import operations and status information |
useNeroFactors | Factor registration, listing, deletion, and share recovery |
useNeroRecovery
Return Value
| Member | Type | Description |
|---|---|---|
setup | (methodType, config, encryptedData?) => Promise<...> | Register a new recovery method via the SDK |
listMethods | (includeInactive?) => Promise<{methods, count}> | List recovery methods and update state |
deleteMethod | (methodId) => Promise<{deleted: true}> | Remove a recovery method |
initiate | (methodId) => Promise<RecoveryAttempt> | Start a recovery attempt for a specified method |
verify | (attemptId, verificationCode) => Promise<...> | Submit verification code for an active attempt |
complete | (attemptId) => Promise<{recoveredData}> | Finalize a verified recovery attempt |
cancel | (attemptId) => Promise<{cancelled: true}> | Abort an in-progress recovery attempt |
setupSelfCustody | (password) => Promise<{factorId}> | Configure self-custody recovery with a password |
offlineRecover | (compositeJson, password, expectedAddress?) => Promise<{privateKey, walletAddress}> | Reconstruct full private key offline |
methods | RecoveryMethod[] | Cached list from last listMethods() call |
isLoading | boolean | true while an async operation is in flight |
error | Error | null | Last caught error, cleared on next operation |
Self-Custody Recovery Setup
const { setupSelfCustody, offlineRecover } = useNeroRecovery();
const { factorId } = await setupSelfCustody('user-password-123');Offline Key Reconstruction
The offlineRecover function does not require the SDK instance or network access. It calls offlineReconstructKey from src/core/self-custody-recovery.ts directly and operates entirely on the client side.
Key properties:
- No SDK initialization required
- Can be called before login
- Function reference remains stable across renders (empty dependency array)
- Performs purely client-side cryptographic mathematics
const { offlineRecover } = useNeroRecovery();
const { privateKey, walletAddress } = await offlineRecover(
compositeJsonString,
'user-password-123',
'0xExpectedAddress'
);useNeroBackup
Return Value
| Member | Type | Description |
|---|---|---|
exportBackup | (password) => Promise<BackupExportResponse> | Delegates to SDK's exportBackupV2() |
importBackup | (backup: BackupData, password) => Promise<BackupImportResponse> | Delegates to SDK's importBackupV2() |
getInfo | () => Promise<BackupInfo> | Gets backup status, updates info state |
info | BackupInfo | null | Cached result from last getInfo() call |
isLoading | boolean | true while an async operation is in flight |
error | Error | null | Last caught error |
Backup Export/Import Example
const { exportBackup, importBackup, getInfo } = useNeroBackup();
const info = await getInfo();
const backup = await exportBackup('backup-password');
await importBackup(backup, 'backup-password');useNeroFactors
Return Value
| Member | Type | Description |
|---|---|---|
addFactor | (factorType, encryptedShare, options?) => Promise<{factor, factorKey?}> | Register a new factor via the SDK |
listFactors | () => Promise<{factors, count}> | List all factors, updates factors state |
deleteFactor | (id) => Promise<{deleted: true}> | Remove a factor |
recoverShare | (factorId, verificationCode) => Promise<{recoveredShare}> | Retrieve encrypted share using a factor |
factors | Factor[] | Cached list from last listFactors() call |
isLoading | boolean | true while an async operation is in flight |
error | Error | null | Last caught error |
Factor Management Example
const { addFactor, listFactors, recoverShare } = useNeroFactors();
const { factor } = await addFactor('security-key', encryptedShare);
const { factors } = await listFactors();
const { recoveredShare } = await recoverShare(factor.id, verificationCode);Import
import { useNeroRecovery, useNeroBackup, useNeroFactors } from "@nerochain/mpc-sdk/react";