One time password

TOTP implementation (incomplete. Token is generated, but not verified.)
This commit is contained in:
Rodrigo Pinto 2024-11-24 01:23:54 -03:00
commit ec1ed9e487
9 changed files with 307 additions and 60 deletions

17
packages/src/lib/utils.js Normal file
View file

@ -0,0 +1,17 @@
import * as OTPAuth from 'otpauth'
export const totp = () => {
let totp = new OTPAuth.TOTP({
issuer: 'Private data',
label: 'otp',
algorithm: 'SHA1',
digits: 6,
period: 300,
})
let token = totp.generate()
let seconds = totp.period - (Math.floor(Date.now() / 1000) % totp.period)
let uri = totp.toString()
return { token, seconds, uri }
}