This commit is contained in:
Manav Rathi 2024-05-23 13:19:05 +05:30
parent 41c87efc5a
commit 206be5c16f
No known key found for this signature in database
2 changed files with 9 additions and 2 deletions

View file

@ -176,7 +176,6 @@ const CodeDisplay: React.FC<CodeDisplay> = ({ codeInfo }) => {
try { try {
const currentTime = new Date().getTime(); const currentTime = new Date().getTime();
if (codeInfo.type.toLowerCase() === "totp") { if (codeInfo.type.toLowerCase() === "totp") {
console.log({ codeInfo });
const totp = new TOTP({ const totp = new TOTP({
secret: codeInfo.secret, secret: codeInfo.secret,
algorithm: codeInfo.algorithm, algorithm: codeInfo.algorithm,

View file

@ -19,7 +19,7 @@ export class Code {
constructor( constructor(
account: string, account: string,
issuer: string, issuer: string,
digits: number | undefined, digits: number,
period: number, period: number,
secret: string, secret: string,
algorithm: Algorithm, algorithm: Algorithm,
@ -39,6 +39,14 @@ export class Code {
} }
} }
/**
* Convert a "raw" OTP secret URL into its parse representation, a {@link Code}.
*
* An example {@link rawData}:
*
* otpauth://totp/account:user@example.org?algorithm=SHA1&digits=6&issuer=issuer&period=30&secret=ALPHANUM
*
*/
export const codeFromRawData = (id: string, rawData: string): Code => { export const codeFromRawData = (id: string, rawData: string): Code => {
let santizedRawData = rawData let santizedRawData = rawData
.replace(/\+/g, "%2B") .replace(/\+/g, "%2B")