Skip to content

feat(totp): add format: "detailed" option to generate#799

Draft
yeojz wants to merge 9 commits intomainfrom
feat/return-generate-timestep
Draft

feat(totp): add format: "detailed" option to generate#799
yeojz wants to merge 9 commits intomainfrom
feat/return-generate-timestep

Conversation

@yeojz
Copy link
Copy Markdown
Owner

@yeojz yeojz commented Feb 15, 2026

Summary

  • Add format: "detailed" option to TOTP generate/generateSync that returns { token, timeStep, epoch } instead of a plain string
  • Enables replay protection (store timeStep, pass as afterTimeStep to verify) and time-window deduplication without separate utility calls
  • Fully backward compatible — omitting format or using "default" returns a plain string as before
  • TypeScript overloads provide exact return type narrowing across TOTP functions, TOTP class, and otplib wrappers

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 15, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 100% (🎯 100%) 1584 / 1584
🔵 Statements 100% (🎯 100%) 1605 / 1605
🔵 Functions 100% (🎯 100%) 341 / 341
🔵 Branches 100% (🎯 100%) 846 / 846
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/core/src/index.ts 0% 0% 0% 0%
packages/core/src/types.ts 0% 0% 0% 0%
packages/otplib/src/class.ts 100% 100% 100% 100%
packages/otplib/src/defaults.ts 100% 100% 100% 100%
packages/otplib/src/functional.ts 100% 100% 100% 100%
packages/otplib/src/index.ts 0% 0% 0% 0%
packages/otplib/src/types.ts 0% 0% 0% 0%
packages/totp/src/class.ts 100% 100% 100% 100%
packages/totp/src/index.ts 100% 100% 100% 100%
packages/totp/src/types.ts 0% 0% 0% 0%
Generated in workflow #359 for commit 6e4e1da by the Vitest Coverage Report Action

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 15, 2026

Bundle Report

Changes will increase total bundle size by 82.06kB (5.01%) ⬆️⚠️, exceeding the configured threshold of 5%.

Bundle name Size Change
@otplib/core 462.9kB 2.83kB (0.61%) ⬆️
otplib 581.88kB 66.99kB (13.01%) ⬆️⚠️
@otplib/totp 112.81kB 12.24kB (12.17%) ⬆️⚠️

Affected Assets, Files, and Routes:

view changes for bundle: otplib

Assets Changed:

Asset Name Size Change Total Size Change (%)
index.global.js.map 10.6kB 264.33kB 4.18%
index.js.map 7.29kB 36.4kB 25.05% ⚠️
index.cjs.map 7.29kB 36.25kB 25.18% ⚠️
index.global.js 1.38kB 36.05kB 3.98%
class.js.map 7.3kB 34.84kB 26.5% ⚠️
class.cjs.map 7.3kB 34.63kB 26.7% ⚠️
functional.js.map 5.07kB 21.98kB 30.0% ⚠️
functional.cjs.map 5.07kB 21.97kB 30.03% ⚠️
metafile-iife.json 1 bytes 9.79kB 0.01%
class.d.cts 1.68kB 9.55kB 21.36% ⚠️
class.d.ts 1.68kB 9.55kB 21.36% ⚠️
functional.d.cts 614 bytes 6.69kB 10.1% ⚠️
functional.d.ts 614 bytes 6.69kB 10.1% ⚠️
index.cjs 1.06kB 6.28kB 20.24% ⚠️
index.js 1.07kB 5.65kB 23.25% ⚠️
types-DO-3bmUY.d.cts (New) 5.59kB 5.59kB 100.0% 🚀
types-DO-3bmUY.d.ts (New) 5.59kB 5.59kB 100.0% 🚀
class.cjs 1.06kB 5.46kB 24.03% ⚠️
class.js 1.07kB 4.99kB 27.16% ⚠️
functional.cjs 1.06kB 4.77kB 28.53% ⚠️
metafile-esm.json 1 bytes 4.71kB 0.02%
metafile-cjs.json 1 bytes 4.32kB 0.02%
functional.js 1.07kB 4.22kB 34.0% ⚠️
index.d.cts 27 bytes 800 bytes 3.49%
index.d.ts 27 bytes 797 bytes 3.51%
types-BBT_82HF.d.cts (Deleted) -3.25kB 0 bytes -100.0% 🗑️
types-BBT_82HF.d.ts (Deleted) -3.25kB 0 bytes -100.0% 🗑️
view changes for bundle: @otplib/totp

Assets Changed:

Asset Name Size Change Total Size Change (%)
index.js.map 3.31kB 30.6kB 12.14% ⚠️
index.cjs.map 3.3kB 29.66kB 12.5% ⚠️
index.d.cts 2.52kB 20.33kB 14.15% ⚠️
index.d.ts 2.52kB 20.33kB 14.15% ⚠️
index.cjs 296 bytes 5.14kB 6.1% ⚠️
index.js 295 bytes 4.27kB 7.43% ⚠️
view changes for bundle: @otplib/core

Assets Changed:

Asset Name Size Change Total Size Change (%)
index.cjs.map 33 bytes 76.75kB 0.04%
index.d.cts 27 bytes 12.66kB 0.21%
index.d.ts 27 bytes 12.66kB 0.21%
types.cjs.map 794 bytes 7.6kB 11.66% ⚠️
types.d.cts 973 bytes 7.47kB 14.97% ⚠️
types.d.ts 973 bytes 7.47kB 14.97% ⚠️

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (bfe9d7a) to head (6e4e1da).
✅ All tests successful. No failed tests found.

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.
📢 Have feedback on the report? Share it here.

@yeojz yeojz requested a review from Copilot February 15, 2026 09:27
@yeojz yeojz marked this pull request as draft March 22, 2026 04:08
@yeojz yeojz force-pushed the feat/return-generate-timestep branch from a4fa39c to 3ba2d31 Compare March 22, 2026 04:18
yeojz added 4 commits March 22, 2026 12:20
…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.
yeojz added 5 commits March 22, 2026 15:02
- 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants