summaryrefslogtreecommitdiff
path: root/node_modules/node-2fa/dist
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/node-2fa/dist')
-rw-r--r--node_modules/node-2fa/dist/index.d.ts11
-rw-r--r--node_modules/node-2fa/dist/index.js51
-rw-r--r--node_modules/node-2fa/dist/interfaces.d.ts4
-rw-r--r--node_modules/node-2fa/dist/interfaces.js2
4 files changed, 68 insertions, 0 deletions
diff --git a/node_modules/node-2fa/dist/index.d.ts b/node_modules/node-2fa/dist/index.d.ts
new file mode 100644
index 0000000..c0db623
--- /dev/null
+++ b/node_modules/node-2fa/dist/index.d.ts
@@ -0,0 +1,11 @@
+import notp from "notp";
+import { Options } from "./interfaces";
+export declare function generateSecret(options?: Options): {
+ secret: string;
+ uri: string;
+ qr: string;
+};
+export declare function generateToken(secret: string): {
+ token: string;
+} | null;
+export declare function verifyToken(secret: string, token?: string, window?: number): notp.VerifyResult | null;
diff --git a/node_modules/node-2fa/dist/index.js b/node_modules/node-2fa/dist/index.js
new file mode 100644
index 0000000..2086ab2
--- /dev/null
+++ b/node_modules/node-2fa/dist/index.js
@@ -0,0 +1,51 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.verifyToken = exports.generateToken = exports.generateSecret = void 0;
+const tslib_1 = require("tslib");
+const notp_1 = tslib_1.__importDefault(require("notp"));
+const crypto_1 = tslib_1.__importDefault(require("crypto"));
+const thirty_two_1 = tslib_1.__importDefault(require("thirty-two"));
+function generateSecret(options) {
+ var _a;
+ const config = {
+ name: encodeURIComponent((_a = options === null || options === void 0 ? void 0 : options.name) !== null && _a !== void 0 ? _a : "App"),
+ account: encodeURIComponent((options === null || options === void 0 ? void 0 : options.account) ? `:${options.account}` : ""),
+ };
+ const bin = crypto_1.default.randomBytes(20);
+ const base32 = thirty_two_1.default.encode(bin).toString("utf8").replace(/=/g, "");
+ const secret = base32
+ .toLowerCase()
+ .replace(/(\w{4})/g, "$1 ")
+ .trim()
+ .split(" ")
+ .join("")
+ .toUpperCase();
+ const query = `?secret=${secret}&issuer=${config.name}`;
+ const encodedQuery = query.replace('?', '%3F').replace('&', '%26');
+ const uri = `otpauth://totp/${config.name}${config.account}`;
+ return {
+ secret,
+ uri: `${uri}${query}`,
+ qr: `https://chart.googleapis.com/chart?chs=166x166&chld=L|0&cht=qr&chl=${uri}${encodedQuery}`
+ };
+}
+exports.generateSecret = generateSecret;
+function generateToken(secret) {
+ if (!secret || !secret.length)
+ return null;
+ const unformatted = secret.replace(/\W+/g, "").toUpperCase();
+ const bin = thirty_two_1.default.decode(unformatted);
+ return { token: notp_1.default.totp.gen(bin) };
+}
+exports.generateToken = generateToken;
+function verifyToken(secret, token, window = 4) {
+ if (!token || !token.length)
+ return null;
+ const unformatted = secret.replace(/\W+/g, "").toUpperCase();
+ const bin = thirty_two_1.default.decode(unformatted);
+ return notp_1.default.totp.verify(token.replace(/\W+/g, ""), bin, {
+ window,
+ time: 30,
+ });
+}
+exports.verifyToken = verifyToken;
diff --git a/node_modules/node-2fa/dist/interfaces.d.ts b/node_modules/node-2fa/dist/interfaces.d.ts
new file mode 100644
index 0000000..6fe394d
--- /dev/null
+++ b/node_modules/node-2fa/dist/interfaces.d.ts
@@ -0,0 +1,4 @@
+export interface Options {
+ name: string;
+ account: string;
+}
diff --git a/node_modules/node-2fa/dist/interfaces.js b/node_modules/node-2fa/dist/interfaces.js
new file mode 100644
index 0000000..c8ad2e5
--- /dev/null
+++ b/node_modules/node-2fa/dist/interfaces.js
@@ -0,0 +1,2 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });