React Hooks Reference

Hooks and provider API for the HyperAuth React components.

React Hooks Reference

Package: @hyperauth/react


HyperAuthProvider

import { HyperAuthProvider } from '@hyperauth/react'

Context provider that initializes HyperAuthClient and makes it available to the component tree via useHyperAuth.

Props

interface HyperAuthProviderProps {
  config?: ClientConfig;
  children: React.ReactNode;
}
PropTypeDescription
configClientConfigPassed directly to createClient. All fields are optional; see SDK Client Reference.
childrenReact.ReactNodeComponent subtree

Behavior

  • Calls createClient(config) once on mount inside a useEffect.
  • Sets status to 'initializing' during setup, 'ready' on success, 'error' on failure.
  • Calls client.close() on unmount.
  • Uses a useRef guard to prevent double-initialization in React Strict Mode.

useHyperAuth

import { useHyperAuth } from '@hyperauth/react'

Returns the current HyperAuthContext value. Throws ClientStateError if called outside HyperAuthProvider.

Signature

function useHyperAuth(): HyperAuthContextValue

Return type

interface HyperAuthContextValue {
  client: HyperAuthClient | null;
  status: HyperAuthStatus;
  error: Error | null;
  isReady: boolean;
}
FieldTypeDescription
clientHyperAuthClient | nullInitialized client instance. null while initializing or on error.
statusHyperAuthStatusCurrent initialization state
errorError | nullError object if status === 'error', otherwise null
isReadybooleantrue when status === 'ready' and client !== null

HyperAuthStatus

type HyperAuthStatus = 'initializing' | 'ready' | 'error'
ValueDescription
'initializing'createClient is running
'ready'Client initialized successfully
'error'Client initialization failed

useRegistration

import { useRegistration } from '@hyperauth/react'

Manages the full 12-step registration pipeline: alias availability check, passkey creation, identity generation, account prediction, fee sponsorship, UserOp signing, submission, and session persistence.

Signature

function useRegistration(): UseRegistrationReturn

Return type

interface UseRegistrationReturn {
  phase: RegistrationPhase;
  steps: RegistrationStep[];
  identity: IdentityState | null;
  result: RegistrationOutcome | null;
  error: string | null;
  isRegistering: boolean;
  register: (alias: string) => Promise<void>;
  reset: () => void;
}
FieldTypeDescription
phaseRegistrationPhaseCurrent phase of the registration pipeline
stepsRegistrationStep[]Array of 12 step objects with status
identityIdentityState | nullPopulated after identity generation (step 2). Available before registration completes.
resultRegistrationOutcome | nullPopulated on successful completion
errorstring | nullError message if phase === 'error', otherwise null
isRegisteringbooleantrue while register is running
register(alias: string) => Promise<void>Starts the registration pipeline. No-ops if already registering.
reset() => voidResets all state to initial values

RegistrationPhase

type RegistrationPhase =
  | 'idle'
  | 'checking-alias'
  | 'creating-passkey'
  | 'generating-identity'
  | 'predicting-account'
  | 'fetching-account-state'
  | 'creating-registration'
  | 'sponsoring'
  | 'authorizing'
  | 'signing'
  | 'submitting'
  | 'confirming'
  | 'storing-session'
  | 'complete'
  | 'error'
ValueCorresponding step
'idle'No registration in progress
'checking-alias'Step 0: alias availability
'creating-passkey'Step 1: WebAuthn ceremony
'generating-identity'Step 2: MPC key generation
'predicting-account'Step 3: smart account address derivation
'fetching-account-state'Step 4: on-chain nonce and active status
'creating-registration'Step 5: UserOp construction
'sponsoring'Step 6: paymaster sponsorship
'authorizing'Step 7: authorization gate
'signing'Step 8: UserOp signature
'submitting'Step 9: bundler submission
'confirming'Step 10: receipt polling
'storing-session'Step 11: session persistence
'complete'Pipeline finished successfully
'error'Pipeline failed

RegistrationStep

interface RegistrationStep {
  label: string;
  status: 'pending' | 'active' | 'done' | 'error';
  detail?: string;
}
FieldTypeDescription
labelstringHuman-readable step description
status'pending' | 'active' | 'done' | 'error'Current step state
detailstringOptional status detail (e.g. 'Available', 'Confirmed')

The 12 step labels, in order:

IndexLabel
0'Checking availability'
1'Creating passkey'
2'Generating identity'
3'Predicting account'
4'Checking account state'
5'Preparing registration'
6'Covering fees'
7'Granting permissions'
8'Signing securely'
9'Submitting registration'
10'Waiting for confirmation'
11'Saving session'

IdentityState

Populated after step 2 ('generating-identity'). Available via identity before result is set.

interface IdentityState {
  did: string;
  enclaveId: string;
  publicKey: string;
  publicKeyHex?: string;
  pubkeyX: string;
  pubkeyY: string;
  ethAddress: string;
  smartAccountAddress: string;
  credentialId: string;
  encryptedShares?: EncryptedShares;
}
FieldTypeDescription
didstringDecentralized identifier string
enclaveIdstringMPC enclave instance ID
publicKeystringBase64 public key
publicKeyHexstringHex-encoded public key
pubkeyXstringP-256 public key X coordinate (hex)
pubkeyYstringP-256 public key Y coordinate (hex)
ethAddressstringDerived Ethereum address
smartAccountAddressstringPredicted ERC-4337 smart account address
credentialIdstringWebAuthn credential ID
encryptedSharesEncryptedSharesMPC encrypted key shares from generate

RegistrationOutcome

Populated on successful completion (phase === 'complete').

interface RegistrationOutcome {
  did: string;
  txHash: string;
  blockNumber: number | null;
  smartAccount: string;
}
FieldTypeDescription
didstringRegistered DID string
txHashstringTransaction hash of the confirmed UserOperation
blockNumbernumber | nullBlock number of confirmation; null if not parseable
smartAccountstringDeployed smart account address

On this page