feat(totp): add format: "detailed" option to generate#799
Draft
feat(totp): add format: "detailed" option to generate#799
Conversation
Contributor
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Bundle ReportChanges will increase total bundle size by 82.06kB (5.01%) ⬆️
Affected Assets, Files, and Routes:view changes for bundle: otplibAssets Changed:
view changes for bundle: @otplib/totpAssets Changed:
view changes for bundle: @otplib/coreAssets Changed:
|
1e643c5 to
8617337
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #799 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 59 59
Lines 1996 2027 +31
Branches 404 437 +33
=========================================
+ Hits 1996 2027 +31 ☔ View full report in Codecov by Sentry. |
a4fa39c to
3ba2d31
Compare
…d results
Allow TOTP generate/generateSync to return `{ token, timeStep, epoch }`
when `format: "detailed"` is specified, enabling replay protection and
time-window deduplication without separate utility calls. Backward
compatible — omitting `format` or using `"default"` returns a plain string.
TypeScript overloads provide exact return type narrowing based on the
`format` value across TOTP functions, TOTP class, and otplib wrappers.
…urn types Move `format` from `TOTPOptions` (constructor-level) to `TOTPGenerateOptions` (call-site only) so the TOTP class reads it from the call-site argument rather than the merged constructor options. This ensures TypeScript overload resolution accurately reflects the return type. Widen OTP class generate/generateSync overloads to return `string | TOTPGenerateResult` when `format: "detailed"` is used, since HOTP strategy ignores `format` and always returns a string. Add tests for HOTP-strategy format behaviour and TOTP class per-call semantics. Update docs with detailed generate usage and replay-protection examples.
3ba2d31 to
a217324
Compare
- Change OTPFormat from "default" | "detailed" to "default" | "plain" | "full" - Rename TOTPGenerateResult to GenerateResult for broader applicability - Update JSDoc to reflect new semantics covering both generate and verify
- Rename "detailed" to "full" in generate/generateSync overloads
- Replace TOTPGenerateResult with GenerateResult throughout
- Add format overloads to verify/verifySync ("plain" returns boolean,
"default"/"full" returns VerifyResult)
- Add format field to TOTPVerifyOptions type with JSDoc
- Update TOTP class verify method with format overloads
- Update tests to use new format names
Update generate overloads from "detailed" to "full" and rename TOTPGenerateResult to GenerateResult. Add verify format overloads with "plain" returning boolean and pass format through to TOTP verify.
- Add format: "plain" generate tests for totp - Add verify format tests (plain/full/default) for totp async and sync - Replace "detailed" with "full" in otplib tests and add verify format tests - Add verify format tests to TOTP class tests
Replace expect.any() and toHaveProperty() with explicit type assertions compatible with the shared test helper types.
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.
Summary
format: "detailed"option to TOTPgenerate/generateSyncthat returns{ token, timeStep, epoch }instead of a plain stringtimeStep, pass asafterTimeStepto verify) and time-window deduplication without separate utility callsformator using"default"returns a plain string as before