Collection of one-time password algorithms
Generate HOTP ,
TOTP , SteamTOTP
Validate TOTP with the time offset
Create TOTP Iterator
Create otpauth uri
import { otpauth , readableTotp , totp , totpValidate } from '@maks11060/otp'
const secret = crypto . getRandomValues ( new Uint8Array ( 20 ) )
// Get code
const code = await totp ( { secret} ) // 380577
// Codes iterator
for await ( const { code, timeLeft} of readableTotp ( totp , { secret} ) ) {
console . log ( { code, timeLeft} ) // { code: "380577", timeLeft: 15 }
}
// Create otpauth uri
otpauth ( { secret, issuer : 'App name' , label : '@username' } ) . toString ( )
// otpauth://totp/lable?secret=00&algorithm=SHA1&issuer=App+name
// Validate totp with time window
await totpValidate ( { secret, code} ) // true
import { hotp , readableTotp } from '@maks11060/otp'
const secret = crypto . getRandomValues ( new Uint8Array ( 20 ) )
const code = await hotp ( { secret, counter : 1 } )
import { readableTotp , steamTotp } from '@maks11060/otp'
import { decodeBase64 } from '@std/encoding/base64'
const secret = decodeBase64 ( 'STEAM_SHARED_SECRET' ) // Decode key to ArrayBuffer
// Get code
const code = await steamTotp ( { secret} )
console . log ( code ) // "KQXVF"
// Codes iterator
for await ( const { code, timeLeft} of readableTotp ( steamTotp , { secret} ) ) {
console . log ( { code, timeLeft} ) // { code: "KQXVF", timeLeft: 25 }
}
Apps
Algs
Period
Digits
Google Authenticator
SHA1
30
6
Microsoft Authenticator
SHA1
30
6