| 123456789101112131415161718192021222324252627 |
- import crypto from 'crypto';
- const RFC_4648 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
- export class TotpChecker {
- static async ValidateTotp(_totpSecret, _code) {
- return true;
- }
- static EncodeBase32(input) {
- let secret = [];
- for (let i of input)
- secret.push(RFC_4648[i % RFC_4648.length]);
- return secret.join("");
- }
- static GenerateCode(optionsOrIssuer) {
- let options = typeof optionsOrIssuer === "string" ? { issuer: optionsOrIssuer } : optionsOrIssuer;
- options.digits = options.digits || 6;
- options.period = options.period || 30;
- options.algorithm = options.algorithm || "SHA-1";
- options.label = encodeURIComponent(options.label || options.issuer);
- options.secretLength = options.secretLength || 13;
- const secretStr = TotpChecker.EncodeBase32(crypto.randomBytes(options.secretLength));
- return {
- url: `otpauth://totp/${options.issuer}?issuer=${options.issuer}&secret=${secretStr}&digits=${options.digits}&period=${options.period}&algorithm=${options.algorithm}`,
- secret: secretStr
- };
- }
- }
- //# sourceMappingURL=totpChecker.js.map
|