-
-
Notifications
You must be signed in to change notification settings - Fork 4
feat: switch to cryptographic api provided by @better-auth/utils
#3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe PR converts Telegram and Mini App verification functions from synchronous to asynchronous implementations, integrating an external utility library (@better-auth/utils) for HMAC operations, and adds authentication timestamp freshness validation via a maxAge parameter. Changes
Sequence DiagramsequenceDiagram
participant Client
participant Endpoint
participant VerifyFn
participant UtilsLib
Client->>Endpoint: POST /signIn (Telegram/MiniApp data)
Endpoint->>VerifyFn: await verifyTelegramAuth(data, token, maxAge)
VerifyFn->>UtilsLib: importKey(secret)
UtilsLib-->>VerifyFn: crypto key
VerifyFn->>UtilsLib: sign(key, data)
UtilsLib-->>VerifyFn: calculatedHash
alt Hash matches & auth valid
VerifyFn-->>Endpoint: Promise<true>
Endpoint->>Endpoint: Process authentication
Endpoint-->>Client: 200 + session token
else Hash mismatch or expired
VerifyFn-->>Endpoint: Promise<false>
Endpoint-->>Client: 401 Unauthorized
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (4)
🧰 Additional context used🧬 Code graph analysis (3)src/verify.ts (1)
src/verify.test.ts (1)
src/index.ts (1)
🔇 Additional comments (10)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Description
Switches cryptographic api from
node:cryptoto the one provided by@better-auth/utils.Impact
Simplifies integration of this plugin in runtimes that don't fully support
node:cryptoAPI, such as Convex.Type of change
Checklist
I have added tests that prove my fix is effective or that my feature works(no new tests needed)npm run type-checkand it passesnpx ultracite checkand it passesTesting
Since
verifyTelegramAuthandverifyMiniAppInitDataare now async, but preserve the same signature, I modified the current tests to work with async function calls.Summary by CodeRabbit
Bug Fixes
Chores