isundil 1 month ago
parent
commit
2fc5fb3bec

+ 14 - 61
dist/index.d.ts

@@ -1,64 +1,17 @@
-declare module "totpChecker" {
-    export interface ToTpGeneratorOptions {
-        digits?: number;
-        period?: number;
-        algorithm?: "SHA-1" | "SHA-256" | "SHA-512";
-        label?: string;
-        secretLength?: number;
-        issuer: string;
-    }
-    export interface ToTpSecretAndUrl {
-        url: string;
-        secret: string;
-    }
-    export class TotpChecker {
-        static ValidateTotp(_totpSecret: string, _code: string): Promise<boolean>;
-        static EncodeBase32(input: Buffer): string;
-        static GenerateCode(optionsOrIssuer: ToTpGeneratorOptions | string): ToTpSecretAndUrl;
-    }
+export interface IAuthenticationHandler {
+    tryLogin(username: string, password: string, totp?: string): Promise<boolean | null>;
+    needTotp(username: string): Promise<boolean | null>;
 }
-declare module "yesManAuthenticationHandler" {
-    import { IAuthenticationHandler } from "index";
-    export class YesManAuthenticationHandler implements IAuthenticationHandler {
-        private useTotp;
-        constructor(useTotp: boolean);
-        tryLogin(username: string, password: string, totp?: string): Promise<boolean | null>;
-        needTotp(username: string): Promise<boolean | null>;
-    }
-}
-declare module "sqliteAuthenticationHandler" {
-    import { IAuthenticationHandler } from "index";
-    export interface AccountInformation {
-        username: string;
-        passwordEncoded: string;
-        totpSecret: string | null;
-    }
-    export type GetAccountInformationFunction = ((username: string) => Promise<AccountInformation | null>);
-    export type EncodePasswordFunction = ((password: string) => string);
-    export class SqliteAuthenticationHandler implements IAuthenticationHandler {
-        passwordEncoder: EncodePasswordFunction;
-        getAccountInformation: GetAccountInformationFunction;
-        constructor(getAccountInformationFunction: GetAccountInformationFunction, passwordEncoder: EncodePasswordFunction);
-        needTotp(username: string): Promise<boolean | null>;
-        tryLogin(username: string, password: string, totp?: string): Promise<boolean | null>;
-    }
-}
-declare module "index" {
-    export interface IAuthenticationHandler {
-        tryLogin(username: string, password: string, totp?: string): Promise<boolean | null>;
-        needTotp(username: string): Promise<boolean | null>;
-    }
-    export class AuthenticationLoader {
-        private handlers;
-        addAuthenticationHandler(authenticationHandler: IAuthenticationHandler): void;
-        tryLogin(username: string, password: string, totpCode?: string): Promise<boolean>;
-        needTotp(username: string): Promise<boolean>;
-    }
-    import { YesManAuthenticationHandler } from "yesManAuthenticationHandler";
-    export { YesManAuthenticationHandler };
-    import { TotpChecker, ToTpGeneratorOptions, ToTpSecretAndUrl } from "totpChecker";
-    export { TotpChecker, ToTpGeneratorOptions, ToTpSecretAndUrl };
-    import { AccountInformation, EncodePasswordFunction, GetAccountInformationFunction, SqliteAuthenticationHandler } from "sqliteAuthenticationHandler";
-    export { AccountInformation, EncodePasswordFunction, GetAccountInformationFunction, SqliteAuthenticationHandler };
+export declare class AuthenticationLoader {
+    private handlers;
+    addAuthenticationHandler(authenticationHandler: IAuthenticationHandler): void;
+    tryLogin(username: string, password: string, totpCode?: string): Promise<boolean>;
+    needTotp(username: string): Promise<boolean>;
 }
+import { YesManAuthenticationHandler } from './yesManAuthenticationHandler.js';
+export { YesManAuthenticationHandler };
+import { TotpChecker, ToTpGeneratorOptions, ToTpSecretAndUrl } from './totpChecker.js';
+export { TotpChecker, ToTpGeneratorOptions, ToTpSecretAndUrl };
+import { AccountInformation, EncodePasswordFunction, GetAccountInformationFunction, SqliteAuthenticationHandler } from './sqliteAuthenticationHandler.js';
+export { AccountInformation, EncodePasswordFunction, GetAccountInformationFunction, SqliteAuthenticationHandler };
 //# sourceMappingURL=index.d.ts.map

File diff suppressed because it is too large
+ 0 - 0
dist/index.d.ts.map


+ 26 - 179
dist/index.js

@@ -1,182 +1,29 @@
-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());
-    });
-};
-System.register("totpChecker", ["crypto"], function (exports_1, context_1) {
-    "use strict";
-    var crypto_1, RFC_4648, TotpChecker;
-    var __moduleName = context_1 && context_1.id;
-    return {
-        setters: [
-            function (crypto_1_1) {
-                crypto_1 = crypto_1_1;
-            }
-        ],
-        execute: function () {
-            RFC_4648 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
-            TotpChecker = 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_1.default.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
-                    };
-                }
-            };
-            exports_1("TotpChecker", TotpChecker);
+export class AuthenticationLoader {
+    handlers = [];
+    addAuthenticationHandler(authenticationHandler) {
+        this.handlers.push(authenticationHandler);
+    }
+    async tryLogin(username, password, totpCode) {
+        for (let i of this.handlers) {
+            const result = await i.tryLogin(username, password, totpCode);
+            if (result !== null)
+                return result;
         }
-    };
-});
-System.register("yesManAuthenticationHandler", ["totpChecker"], function (exports_2, context_2) {
-    "use strict";
-    var totpChecker_1, YesManAuthenticationHandler;
-    var __moduleName = context_2 && context_2.id;
-    return {
-        setters: [
-            function (totpChecker_1_1) {
-                totpChecker_1 = totpChecker_1_1;
-            }
-        ],
-        execute: function () {
-            YesManAuthenticationHandler = class YesManAuthenticationHandler {
-                constructor(useTotp) {
-                    this.useTotp = useTotp;
-                }
-                tryLogin(username, password, totp) {
-                    if (!username)
-                        return Promise.resolve(null);
-                    if (!password)
-                        return Promise.resolve(false);
-                    if ((this.useTotp && !totp) || (!this.useTotp && totp))
-                        return Promise.resolve(false);
-                    if (!totp)
-                        return Promise.resolve(true);
-                    return totpChecker_1.TotpChecker.ValidateTotp(totpChecker_1.TotpChecker.EncodeBase32(Buffer.from(username)), totp);
-                }
-                needTotp(username) {
-                    return Promise.resolve(username ? this.useTotp : null);
-                }
-            };
-            exports_2("YesManAuthenticationHandler", YesManAuthenticationHandler);
+        return false;
+    }
+    async needTotp(username) {
+        for (let i of this.handlers) {
+            const result = await i.needTotp(username);
+            if (result !== null)
+                return result;
         }
-    };
-});
-System.register("sqliteAuthenticationHandler", ["totpChecker"], function (exports_3, context_3) {
-    "use strict";
-    var totpChecker_2, SqliteAuthenticationHandler;
-    var __moduleName = context_3 && context_3.id;
-    return {
-        setters: [
-            function (totpChecker_2_1) {
-                totpChecker_2 = totpChecker_2_1;
-            }
-        ],
-        execute: function () {
-            SqliteAuthenticationHandler = class SqliteAuthenticationHandler {
-                constructor(getAccountInformationFunction, passwordEncoder) {
-                    this.passwordEncoder = passwordEncoder;
-                    this.getAccountInformation = getAccountInformationFunction;
-                }
-                needTotp(username) {
-                    return __awaiter(this, void 0, void 0, function* () {
-                        const accountInformation = yield this.getAccountInformation(username);
-                        if (!accountInformation)
-                            return null;
-                        return !!accountInformation.totpSecret;
-                    });
-                }
-                tryLogin(username, password, totp) {
-                    return __awaiter(this, void 0, void 0, function* () {
-                        const accountInformation = yield this.getAccountInformation(username);
-                        if (!accountInformation)
-                            return null;
-                        password = this.passwordEncoder(password);
-                        if (accountInformation.passwordEncoded !== password ||
-                            (accountInformation.totpSecret && !totp) ||
-                            (!accountInformation.totpSecret && totp))
-                            return false;
-                        if (!accountInformation.totpSecret && !totp)
-                            return true;
-                        return totpChecker_2.TotpChecker.ValidateTotp(accountInformation.totpSecret, totp);
-                    });
-                }
-            };
-            exports_3("SqliteAuthenticationHandler", SqliteAuthenticationHandler);
-        }
-    };
-});
-System.register("index", ["yesManAuthenticationHandler", "totpChecker", "sqliteAuthenticationHandler"], function (exports_4, context_4) {
-    "use strict";
-    var AuthenticationLoader, yesManAuthenticationHandler_1, totpChecker_3, sqliteAuthenticationHandler_1;
-    var __moduleName = context_4 && context_4.id;
-    return {
-        setters: [
-            function (yesManAuthenticationHandler_1_1) {
-                yesManAuthenticationHandler_1 = yesManAuthenticationHandler_1_1;
-            },
-            function (totpChecker_3_1) {
-                totpChecker_3 = totpChecker_3_1;
-            },
-            function (sqliteAuthenticationHandler_1_1) {
-                sqliteAuthenticationHandler_1 = sqliteAuthenticationHandler_1_1;
-            }
-        ],
-        execute: function () {
-            AuthenticationLoader = class AuthenticationLoader {
-                constructor() {
-                    this.handlers = [];
-                }
-                addAuthenticationHandler(authenticationHandler) {
-                    this.handlers.push(authenticationHandler);
-                }
-                tryLogin(username, password, totpCode) {
-                    return __awaiter(this, void 0, void 0, function* () {
-                        for (let i of this.handlers) {
-                            const result = yield i.tryLogin(username, password, totpCode);
-                            if (result !== null)
-                                return result;
-                        }
-                        return false;
-                    });
-                }
-                needTotp(username) {
-                    return __awaiter(this, void 0, void 0, function* () {
-                        for (let i of this.handlers) {
-                            const result = yield i.needTotp(username);
-                            if (result !== null)
-                                return result;
-                        }
-                        return false;
-                    });
-                }
-            };
-            exports_4("AuthenticationLoader", AuthenticationLoader);
-            exports_4("YesManAuthenticationHandler", yesManAuthenticationHandler_1.YesManAuthenticationHandler);
-            exports_4("TotpChecker", totpChecker_3.TotpChecker);
-            exports_4("SqliteAuthenticationHandler", sqliteAuthenticationHandler_1.SqliteAuthenticationHandler);
-        }
-    };
-});
+        return false;
+    }
+}
+import { YesManAuthenticationHandler } from './yesManAuthenticationHandler.js';
+export { YesManAuthenticationHandler };
+import { TotpChecker } from './totpChecker.js';
+export { TotpChecker };
+import { SqliteAuthenticationHandler } from './sqliteAuthenticationHandler.js';
+export { SqliteAuthenticationHandler };
 //# sourceMappingURL=index.js.map

File diff suppressed because it is too large
+ 0 - 0
dist/index.js.map


+ 16 - 0
dist/sqliteAuthenticationHandler.d.ts

@@ -0,0 +1,16 @@
+import { IAuthenticationHandler } from "./index.js";
+export interface AccountInformation {
+    username: string;
+    passwordEncoded: string;
+    totpSecret: string | null;
+}
+export type GetAccountInformationFunction = ((username: string) => Promise<AccountInformation | null>);
+export type EncodePasswordFunction = ((password: string) => string);
+export declare class SqliteAuthenticationHandler implements IAuthenticationHandler {
+    passwordEncoder: EncodePasswordFunction;
+    getAccountInformation: GetAccountInformationFunction;
+    constructor(getAccountInformationFunction: GetAccountInformationFunction, passwordEncoder: EncodePasswordFunction);
+    needTotp(username: string): Promise<boolean | null>;
+    tryLogin(username: string, password: string, totp?: string): Promise<boolean | null>;
+}
+//# sourceMappingURL=sqliteAuthenticationHandler.d.ts.map

+ 1 - 0
dist/sqliteAuthenticationHandler.d.ts.map

@@ -0,0 +1 @@
+{"version":3,"file":"sqliteAuthenticationHandler.d.ts","sourceRoot":"","sources":["../src/sqliteAuthenticationHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAGpD,MAAM,WAAW,kBAAkB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,GAAC,IAAI,CAAC;CAC3B;AAED,MAAM,MAAM,6BAA6B,GAAG,CAAC,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,kBAAkB,GAAC,IAAI,CAAC,CAAC,CAAC;AACrG,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC;AAEpE,qBAAa,2BAA4B,YAAW,sBAAsB;IACtE,eAAe,EAAE,sBAAsB,CAAC;IACxC,qBAAqB,EAAE,6BAA6B,CAAC;gBAElC,6BAA6B,EAAE,6BAA6B,EAAE,eAAe,EAAE,sBAAsB;IAK3G,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAOnD,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;CAapG"}

+ 29 - 0
dist/sqliteAuthenticationHandler.js

@@ -0,0 +1,29 @@
+import { TotpChecker } from "./totpChecker.js";
+export class SqliteAuthenticationHandler {
+    passwordEncoder;
+    getAccountInformation;
+    constructor(getAccountInformationFunction, passwordEncoder) {
+        this.passwordEncoder = passwordEncoder;
+        this.getAccountInformation = getAccountInformationFunction;
+    }
+    async needTotp(username) {
+        const accountInformation = await this.getAccountInformation(username);
+        if (!accountInformation)
+            return null;
+        return !!accountInformation.totpSecret;
+    }
+    async tryLogin(username, password, totp) {
+        const accountInformation = await this.getAccountInformation(username);
+        if (!accountInformation)
+            return null;
+        password = this.passwordEncoder(password);
+        if (accountInformation.passwordEncoded !== password ||
+            (accountInformation.totpSecret && !totp) ||
+            (!accountInformation.totpSecret && totp))
+            return false;
+        if (!accountInformation.totpSecret && !totp)
+            return true;
+        return TotpChecker.ValidateTotp(accountInformation.totpSecret, totp);
+    }
+}
+//# sourceMappingURL=sqliteAuthenticationHandler.js.map

+ 1 - 0
dist/sqliteAuthenticationHandler.js.map

@@ -0,0 +1 @@
+{"version":3,"file":"sqliteAuthenticationHandler.js","sourceRoot":"","sources":["../src/sqliteAuthenticationHandler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAW/C,MAAM,OAAO,2BAA2B;IACpC,eAAe,CAAyB;IACxC,qBAAqB,CAAgC;IAErD,YAAmB,6BAA4D,EAAE,eAAuC;QACpH,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,qBAAqB,GAAG,6BAA6B,CAAC;IAC/D,CAAC;IAEM,KAAK,CAAC,QAAQ,CAAC,QAAgB;QAClC,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC;QACtE,IAAI,CAAC,kBAAkB;YACnB,OAAO,IAAI,CAAC;QAChB,OAAO,CAAC,CAAC,kBAAkB,CAAC,UAAU,CAAC;IAC3C,CAAC;IAEM,KAAK,CAAC,QAAQ,CAAC,QAAgB,EAAE,QAAgB,EAAE,IAAa;QACnE,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC;QACtE,IAAI,CAAC,kBAAkB;YACnB,OAAO,IAAI,CAAC;QAChB,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;QAC1C,IAAI,kBAAkB,CAAC,eAAe,KAAK,QAAQ;YAC/C,CAAC,kBAAkB,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC;YACxC,CAAC,CAAC,kBAAkB,CAAC,UAAU,IAAI,IAAI,CAAC;YACxC,OAAO,KAAK,CAAC;QACjB,IAAI,CAAC,kBAAkB,CAAC,UAAU,IAAI,CAAC,IAAI;YACvC,OAAO,IAAI,CAAC;QAChB,OAAO,WAAW,CAAC,YAAY,CAAC,kBAAkB,CAAC,UAAW,EAAE,IAAK,CAAC,CAAC;IAC3E,CAAC;CACJ"}

+ 18 - 0
dist/totpChecker.d.ts

@@ -0,0 +1,18 @@
+export interface ToTpGeneratorOptions {
+    digits?: number;
+    period?: number;
+    algorithm?: "SHA-1" | "SHA-256" | "SHA-512";
+    label?: string;
+    secretLength?: number;
+    issuer: string;
+}
+export interface ToTpSecretAndUrl {
+    url: string;
+    secret: string;
+}
+export declare class TotpChecker {
+    static ValidateTotp(_totpSecret: string, _code: string): Promise<boolean>;
+    static EncodeBase32(input: Buffer): string;
+    static GenerateCode(optionsOrIssuer: ToTpGeneratorOptions | string): ToTpSecretAndUrl;
+}
+//# sourceMappingURL=totpChecker.d.ts.map

+ 1 - 0
dist/totpChecker.d.ts.map

@@ -0,0 +1 @@
+{"version":3,"file":"totpChecker.d.ts","sourceRoot":"","sources":["../src/totpChecker.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,oBAAoB;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,GAAC,SAAS,GAAC,SAAS,CAAA;IACvC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;CAClB;AAID,qBAAa,WAAW;WACA,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;WAIxE,YAAY,CAAC,KAAK,EAAE,MAAM;WAO1B,YAAY,CAAC,eAAe,EAAE,oBAAoB,GAAC,MAAM,GAAG,gBAAgB;CAa7F"}

+ 27 - 0
dist/totpChecker.js

@@ -0,0 +1,27 @@
+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

+ 1 - 0
dist/totpChecker.js.map

@@ -0,0 +1 @@
+{"version":3,"file":"totpChecker.js","sourceRoot":"","sources":["../src/totpChecker.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAgB5B,MAAM,QAAQ,GAAG,kCAAkC,CAAC;AAEpD,MAAM,OAAO,WAAW;IACb,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,WAAmB,EAAE,KAAa;QAC/D,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,MAAM,CAAC,YAAY,CAAC,KAAa;QACpC,IAAI,MAAM,GAAG,EAAE,CAAC;QAChB,KAAK,IAAI,CAAC,IAAI,KAAK;YACf,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;QAC/C,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC3B,CAAC;IAEM,MAAM,CAAC,YAAY,CAAC,eAA4C;QACnE,IAAI,OAAO,GAAyB,OAAO,eAAe,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAC,MAAM,EAAE,eAAe,EAAC,CAAC,CAAC,CAAC,eAAe,CAAC;QACtH,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,CAAC;QACrC,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC;QACtC,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC;QACjD,OAAO,CAAC,KAAK,GAAG,kBAAkB,CAAC,OAAO,CAAC,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;QACpE,OAAO,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,EAAE,CAAC;QAClD,MAAM,SAAS,GAAG,WAAW,CAAC,YAAY,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC;QACrF,OAAO;YACH,GAAG,EAAE,kBAAkB,OAAO,CAAC,MAAM,WAAW,OAAO,CAAC,MAAM,WAAW,SAAS,WAAW,OAAO,CAAC,MAAM,WAAW,OAAO,CAAC,MAAM,cAAc,OAAO,CAAC,SAAS,EAAE;YACrK,MAAM,EAAE,SAAS;SACpB,CAAC;IACN,CAAC;CACJ"}

+ 8 - 0
dist/yesManAuthenticationHandler.d.ts

@@ -0,0 +1,8 @@
+import { IAuthenticationHandler } from "./index.js";
+export declare class YesManAuthenticationHandler implements IAuthenticationHandler {
+    private useTotp;
+    constructor(useTotp: boolean);
+    tryLogin(username: string, password: string, totp?: string): Promise<boolean | null>;
+    needTotp(username: string): Promise<boolean | null>;
+}
+//# sourceMappingURL=yesManAuthenticationHandler.d.ts.map

+ 1 - 0
dist/yesManAuthenticationHandler.d.ts.map

@@ -0,0 +1 @@
+{"version":3,"file":"yesManAuthenticationHandler.d.ts","sourceRoot":"","sources":["../src/yesManAuthenticationHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAGpD,qBAAa,2BAA4B,YAAW,sBAAsB;IACtE,OAAO,CAAC,OAAO,CAAU;gBAEN,OAAO,EAAE,OAAO;IAG5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAWpF,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;CAG7D"}

+ 22 - 0
dist/yesManAuthenticationHandler.js

@@ -0,0 +1,22 @@
+import { TotpChecker } from "./totpChecker.js";
+export class YesManAuthenticationHandler {
+    useTotp;
+    constructor(useTotp) {
+        this.useTotp = useTotp;
+    }
+    tryLogin(username, password, totp) {
+        if (!username)
+            return Promise.resolve(null);
+        if (!password)
+            return Promise.resolve(false);
+        if ((this.useTotp && !totp) || (!this.useTotp && totp))
+            return Promise.resolve(false);
+        if (!totp)
+            return Promise.resolve(true);
+        return TotpChecker.ValidateTotp(TotpChecker.EncodeBase32(Buffer.from(username)), totp);
+    }
+    needTotp(username) {
+        return Promise.resolve(username ? this.useTotp : null);
+    }
+}
+//# sourceMappingURL=yesManAuthenticationHandler.js.map

+ 1 - 0
dist/yesManAuthenticationHandler.js.map

@@ -0,0 +1 @@
+{"version":3,"file":"yesManAuthenticationHandler.js","sourceRoot":"","sources":["../src/yesManAuthenticationHandler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,OAAO,2BAA2B;IAC5B,OAAO,CAAU;IAEzB,YAAmB,OAAgB;QAC/B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IACM,QAAQ,CAAC,QAAgB,EAAE,QAAgB,EAAE,IAAa;QAC7D,IAAI,CAAC,QAAQ;YACT,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACjC,IAAI,CAAC,QAAQ;YACT,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAClC,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC;YAClD,OAAO,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAClC,IAAI,CAAC,IAAI;YACL,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACjC,OAAO,WAAW,CAAC,YAAY,CAAC,WAAW,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IAC3F,CAAC;IACM,QAAQ,CAAC,QAAgB;QAC5B,OAAO,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAC3D,CAAC;CACJ"}

+ 3 - 1
package.json

@@ -5,7 +5,9 @@
   "license": "ISC",
   "author": "isundil",
   "type": "module",
-  "main": "index.js",
+  "main": "dist/index.js",
+  "types": "dist/index.d.ts",
+  "build": "tsc",
   "scripts": {
     "test": "echo \"Error: no test specified\" && exit 1",
     "build": "npx tsc"

+ 4 - 3
src/index.ts

@@ -30,9 +30,10 @@ export class AuthenticationLoader {
     }
 }
 
-import { YesManAuthenticationHandler }from './yesManAuthenticationHandler';
+import { YesManAuthenticationHandler }from './yesManAuthenticationHandler.js';
 export { YesManAuthenticationHandler };
-import { TotpChecker, ToTpGeneratorOptions, ToTpSecretAndUrl } from './totpChecker';
+import { TotpChecker, ToTpGeneratorOptions, ToTpSecretAndUrl } from './totpChecker.js';
 export { TotpChecker, ToTpGeneratorOptions, ToTpSecretAndUrl };
-import { AccountInformation, EncodePasswordFunction, GetAccountInformationFunction, SqliteAuthenticationHandler } from './sqliteAuthenticationHandler'
+import { AccountInformation, EncodePasswordFunction, GetAccountInformationFunction, SqliteAuthenticationHandler } from './sqliteAuthenticationHandler.js'
 export { AccountInformation, EncodePasswordFunction, GetAccountInformationFunction, SqliteAuthenticationHandler };
+

+ 2 - 2
src/sqliteAuthenticationHandler.ts

@@ -1,5 +1,5 @@
-import { IAuthenticationHandler } from ".";
-import { TotpChecker } from "./totpChecker";
+import { IAuthenticationHandler } from "./index.js";
+import { TotpChecker } from "./totpChecker.js";
 
 export interface AccountInformation {
     username: string;

+ 2 - 2
src/yesManAuthenticationHandler.ts

@@ -1,5 +1,5 @@
-import { IAuthenticationHandler } from ".";
-import { TotpChecker } from "./totpChecker";
+import { IAuthenticationHandler } from "./index.js";
+import { TotpChecker } from "./totpChecker.js";
 
 export class YesManAuthenticationHandler implements IAuthenticationHandler {
     private useTotp: boolean;

+ 8 - 5
tsconfig.json

@@ -1,21 +1,24 @@
 {
+  "type": "module",
   "compilerOptions": {
     "skipLibCheck": true,
-    "target": "es6",
-    "module": "system",
+    "target": "esnext",
+    "module": "nodenext",
+    "moduleResolution": "nodenext",
     "lib": ["es6", "dom"],
     "jsx": "react",
     "declaration": true,
     "declarationMap": true,
     "sourceMap": true,
     "outDir": "dist",
-    "outFile": "dist/index.js",
     "rootDirs": ["src"],
     "strict": true,
-    "moduleResolution": "node",
     "esModuleInterop": true,
-    "forceConsistentCasingInFileNames": true
+    "forceConsistentCasingInFileNames": true,
   },
+  "include": [
+    "src/**/*"
+  ],
   "exclude": [
     "./test.ts",
     "./dist"

Some files were not shown because too many files changed in this diff