Repository navigation
fix(auth): unify nonce implementations, add consume path, eviction, and bounded store - #1758
Merged
Merged
Conversation
…nd bounded store Closes Remitwise-Org#1751 ## Summary Consolidates three diverged nonce implementations into a single core in lib/auth/nonce.ts with a thin HTTP adapter in app/api/auth/nonce/route.ts. ## Changes - Refactored lib/auth/nonce.ts to support per-address supersede, O(1) consume, lazy purge on access, and bounded store with LRU eviction - Rewrote app/api/auth/nonce/route.ts as a thin adapter over the core, preserving the public GET contract (validation codes, headers, response shape) - Deleted lib/auth-cache.ts (unused third implementation) - Deleted app/api/auth/nonce/route.test.ts (tested POST handler and resolveAddressFromRequest that never existed in the live route) - Added tests for all acceptance criteria: single-use, supersede, expiry, bounded store, TTL clamping ## Three implementations resolved 1. app/api/auth/nonce/route.ts (live GET route) → now thin adapter 2. lib/auth/nonce.ts (failure boundary core) → now the single source of truth 3. lib/auth-cache.ts (third store with sweeper) → deleted ## Eviction policy - Lazy purge on access (get/findByNonce) removes expired/consumed entries - Background sweep every 60s (unref'd) for passive cleanup - LRU eviction when store exceeds NONCE_STORE_MAX (default 50,000) - TTL clamped to 30s–10min everywhere ## Test expectations changed - route.test.ts deleted: tested non-existent POST/resolveAddressFromRequest - auth-nonce.test.ts: updated TTL tests to account for 30s minimum clamp - nonce.test.ts: added supersede, expiry, bounded store tests
12 tasks
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.
Closes #1751
Summary
Consolidates three diverged nonce implementations into a single core in lib/auth/nonce.ts with a thin HTTP adapter in app/api/auth/nonce/route.ts.
Changes
Three implementations resolved
Eviction policy
Test expectations changed