✳ Lambatoken / Mobile DocsAUTH 0.7.0 · WALLET 0.2.0
Authentication / 07

MFA enrollment, login and step-up

Separate enrollment, login challenge, recent assurance and transaction-specific approval.

1. Detect enrollment

Fetch actual server status after login or when entering security settings. Do not infer enrollment from local settings.

typescript
const enrollmentStatus = await auth.mfa.enrollmentStatus();
if (!enrollmentStatus.enrolled) { /* show setup */ }

2. Enroll authenticator

Collect primary credential. Display the otpauthUri as a QR code or secret for manual entry only on the setup screen. Clear it after confirmation, cancellation or expiry.

typescript
const enrollment = await auth.mfa.enrollStart(currentPassword);
// Display enrollment.otpauthUri or enrollment.secret securely.
await auth.mfa.enrollConfirm(code);
// On cancellation: await auth.mfa.cancelEnrollment();

3. Login with TOTP

A password or social login may return authenticated:false and mfaRequired:true. Keep challengeId in current flow state; complete only that challenge.

typescript
await auth.completeMfa(challengeId, code);

4. Recent MFA assurance

If a resource service requires step-up, check assurance and create a challenge. A satisfied advisory check is not a substitute for server enforcement. After confirmation resume only an explicitly authorized, safe operation.

typescript
const assurance = await auth.mfa.assuranceStatus(300);
if (!assurance.satisfied) {
  const challenge = await auth.mfa.stepUpStart();
  // Prompt user for code before continuing.
  await auth.mfa.stepUp(challenge.challengeId, code);
}

5. Remove or cancel

Require primary credential and authenticator code for removal. After security mutations refresh security status; the SDK invalidates affected token caches.

typescript
await auth.mfa.remove(currentPassword, code);
// For an abandoned step-up:
// await auth.mfa.cancelStepUp(challengeId);

6. Transaction-bound MFA

The resource service must initiate the binding and consume the approval. Pass its exact fields, not a client-invented hash. Approval is neither a signed wallet transfer nor a final execution receipt.

typescript
const approval = await auth.mfa.confirmTransaction({
  authorizationId: challenge.authorizationId,
  audience: challenge.audience,
  action: challenge.action,
  resourceId: challenge.resourceId,
  requestHash: challenge.requestHash,
  code,
});

Wallet API integration for challenge initiation and consumption is not yet validated. Do not enable production financial mutations on the basis of this example.