Conversation
|
@KingYuss Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR adds optional TOTP-based two-factor authentication as an additive second factor on top of the existing wallet-signature auth. Users can enroll an authenticator app, confirm enrollment with a code before it activates, and are then required to supply a valid TOTP code (or a one-time backup code) after wallet-signature verification to complete login. Disabling 2FA requires a fresh wallet-signature challenge, and enrollment/verification/disable events are audit-logged.
Related Issue
Changes
🔐 TOTP Credential Model
prisma/migrations/20260928200000_add_totp_credentials/migration.sqlTotpCredentialtable:userId,secretEncrypted,verifiedAt,lastAcceptedStep, hashed recovery codes.prisma/migrations/20260928200000_add_totp_credentials/rollback.sqlTotpCredentialtable.prisma/schema.prismaTotpCredentialmodel with encrypted secret,verifiedAt,lastAcceptedStep(replay protection), and hashed backup codes.🔑 Secret Encryption
src/keys/registry.tssecretEncryptedand backup codes are encrypted/hashed at rest and never re-exposed after issuance.🧩 Auth Flow Integration
src/controllers/auth-controller.tsotpauth://URI;verify-enrollmentconfirms with a code before activation (unverified secrets expire and are never enforced).TotpCredentialexists,verifyreturns arequiresTotpchallenge instead of a session; a valid TOTP code (or one-time backup code) completes login.lastAcceptedSteprejects replay of a used code.🛣️ Routes
src/routes/sessions.tsPOST /api/v1/2fa/enroll,POST /api/v1/2fa/verify-enrollment,POST /api/v1/auth/2fa/verify,POST /api/v1/2fa/disable, and backup-code regeneration.📚 Docs
docs/2FA.mddocs/openapi.yamlrequiresTotpchallenge schema.Verification Results
TotpCredentialrequires valid TOTP after wallet-signature verification, ±1 step tolerance, replay protectiondocs/2FA.md+docs/openapi.yamladded; unit + integration tests greenCloses #545