| 1234567891011121314151617181920212223242526272829303132333435363738 |
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- import crypto from 'crypto';
- const RFC_4648 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
- export class TotpChecker {
- static ValidateTotp(_totpSecret, _code) {
- return __awaiter(this, void 0, void 0, function* () {
- 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
|