Skip to content

Commit e5645d0

Browse files
committed
fix: normalize algorithm name for TOTP Auth URI generation
Ensure the algorithm name is compatible with the otpauth URI specification by removing dashes from the algorithm name. BREAKING CHANGE: Technically, we are changing the algorithm param that is returned from getTOTPAuthUri and that could be a breaking change for some people, but it shouldn't be a breaking change for most (any). So go ahead and update this without concern.
1 parent adc780e commit e5645d0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ export async function generateTOTP({
165165
* @param {Object} options Configuration options for the TOTP Auth URI.
166166
* @param {number} options.period The number of seconds for the OTP to be valid.
167167
* @param {number} options.digits The length of the OTP.
168-
* @param {HashAlgorithm} options.algorithm The algorithm to use.
168+
* @param {HashAlgorithm} options.algorithm The algorithm to use. (Note, we
169+
* automatically remove the dashes from the algorithm name because the otpauth
170+
* URI spec requires it.)
169171
* @param {string} options.secret The secret to use for the TOTP Auth URI.
170172
* @param {string} options.accountName A way to uniquely identify this Auth URI
171173
* (in case they have multiple of these).
@@ -184,7 +186,7 @@ export function getTOTPAuthUri({
184186
const params = new URLSearchParams({
185187
secret,
186188
issuer,
187-
algorithm,
189+
algorithm: algorithm.algorithm.replaceAll('-', ''),
188190
digits: digits.toString(),
189191
period: period.toString(),
190192
})

0 commit comments

Comments
 (0)