-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.ts
54 lines (52 loc) · 1.52 KB
/
mod.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* # **OTP**
* ### Collection of one-time password algorithms
*
* - {@link https://datatracker.ietf.org/doc/html/rfc4226 HOTP}
* - {@link https://datatracker.ietf.org/doc/html/rfc6238 TOTP}
* - SteamTOTP
*
* @example Generate `TOTP`
* ```ts
* import {otpauth, totp, totpValidate} from '@maks11060/otp'
*
* const secret = crypto.getRandomValues(new Uint8Array(20))
* const code = await totp({secret}) // 123456
*
* // 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
* ```
*
* @example Generate `HOTP`
* ```ts
* import {hotp} from '@maks11060/otp'
*
* const secret = crypto.getRandomValues(new Uint8Array(20))
* const code = await hotp({secret, counter: 1})
* ```
*
* @example Generate `SteamTOTP`
* ```ts
* import {decodeBase64} from '@std/encoding/base64'
* import {generateKey, getTimeCounter, steamTotp} from '@maks11060/otp'
*
* const steamKey = decodeBase64('STEAM_SHARED_SECRET') // Decode key to ArrayBuffer
* steamTotp(await generateKey(steamKey, getTimeCounter())) // VWFH3
* ```
*
* @module
*/
export {generateKey, hotp, type HotpOptions} from './src/hotp.ts'
export {otpauth, type OtpAuthUriOptions} from './src/otpauth.ts'
export {steamTotp, type SteamTotpOptions} from './src/steamTotp.ts'
export {
getTimeCounter,
totp,
totpValidate,
type TotpOptions,
type TotpValidateOptions
} from './src/totp.ts'