Skip to content

feat(totp): add timeStep to generate() return value#750

Draft
yeojz wants to merge 3 commits intomainfrom
feature/generate-timestep
Draft

feat(totp): add timeStep to generate() return value#750
yeojz wants to merge 3 commits intomainfrom
feature/generate-timestep

Conversation

@yeojz
Copy link
Owner

@yeojz yeojz commented Jan 14, 2026

Summary

  • Add timeStep to TOTP generation function return values
  • Change generate() and generateSync() to return { token, timeStep } instead of string
  • Update TOTP class methods to return { token, timeStep }
  • Maintain backward compatibility in v11/v12 adapters and functional API
  • Add comprehensive documentation for timeStep per RFC 6238

Breaking Changes

Direct TOTP API usage:

  • Before: const token = await generate({ secret, crypto })
  • After: const { token, timeStep } = await generate({ secret, crypto })

Backward compatible APIs (no breaking changes):

  • v11/v12 adapters still return strings
  • otplib functional API still returns strings

@yeojz yeojz added feature version-major Highlights that this will be a major change labels Jan 14, 2026
@github-actions
Copy link
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 100% (🎯 100%) 821 / 821
🔵 Statements 100% (🎯 100%) 826 / 826
🔵 Functions 100% (🎯 100%) 237 / 237
🔵 Branches 100% (🎯 100%) 395 / 395
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/otplib/src/functional.ts 100% 100% 100% 100%
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%
packages/v11-adapter/src/authenticator.ts 100% 100% 100% 100%
packages/v11-adapter/src/totp.ts 100% 100% 100% 100%
packages/v12-adapter/src/authenticator.ts 100% 100% 100% 100%
packages/v12-adapter/src/totp.ts 100% 100% 100% 100%
Generated in workflow #97 for commit 4314597 by the Vitest Coverage Report Action

@codecov
Copy link

codecov bot commented Jan 14, 2026

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #750   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           29        29           
  Lines         1109      1119   +10     
  Branches       220       199   -21     
=========================================
+ Hits          1109      1119   +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codecov
Copy link

codecov bot commented Jan 14, 2026

Bundle Report

Changes will increase total bundle size by 5.81kB (0.54%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
@otplib/preset-v11 82.52kB 353 bytes (0.43%) ⬆️
@otplib/totp 90.57kB 3.61kB (4.15%) ⬆️
@otplib/v12-adapter 129.77kB 352 bytes (0.27%) ⬆️
otplib 205.63kB 1.5kB (0.73%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: @otplib/preset-v11

Assets Changed:

Asset Name Size Change Total Size Change (%)
index.cjs.map 110 bytes 22.72kB 0.49%
index.js.map 110 bytes 22.67kB 0.49%
index.cjs 66 bytes 11.34kB 0.59%
index.js 66 bytes 10.08kB 0.66%
metafile-esm.json 1 bytes 3.33kB 0.03%
view changes for bundle: otplib

Assets Changed:

Asset Name Size Change Total Size Change (%)
index.js.map 225 bytes 27.55kB 0.82%
index.cjs.map 225 bytes 27.46kB 0.83%
class.js.map 225 bytes 25.98kB 0.87%
class.cjs.map 225 bytes 25.81kB 0.88%
functional.js.map 225 bytes 16.99kB 1.34%
functional.cjs.map 225 bytes 16.96kB 1.34%
index.cjs 24 bytes 4.89kB 0.49%
metafile-esm.json 1 bytes 4.83kB 0.02%
metafile-cjs.json 1 bytes 4.45kB 0.02%
index.js 25 bytes 4.28kB 0.59%
class.cjs 24 bytes 4.1kB 0.59%
class.js 25 bytes 3.64kB 0.69%
functional.cjs 24 bytes 3.63kB 0.66%
functional.js 25 bytes 3.09kB 0.82%
view changes for bundle: @otplib/totp

Assets Changed:

Asset Name Size Change Total Size Change (%)
index.js.map 484 bytes 24.48kB 2.02%
index.cjs.map 484 bytes 23.77kB 2.08%
index.d.cts 1.25kB 15.91kB 8.5% ⚠️
index.d.ts 1.25kB 15.91kB 8.5% ⚠️
index.cjs 73 bytes 4.48kB 1.66%
index.js 72 bytes 3.54kB 2.08%
view changes for bundle: @otplib/v12-adapter

Assets Changed:

Asset Name Size Change Total Size Change (%)
index.cjs.map 110 bytes 34.04kB 0.32%
index.js.map 110 bytes 33.98kB 0.32%
index.cjs 66 bytes 15.18kB 0.44%
index.js 66 bytes 13.77kB 0.48%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature version-major Highlights that this will be a major change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant