feat(otp): yeah used packet.............
This commit is contained in:
parent
a16852c1b9
commit
c545499c73
4 changed files with 18 additions and 38 deletions
|
|
@ -16,6 +16,8 @@
|
||||||
"fastify": "^5.0.0",
|
"fastify": "^5.0.0",
|
||||||
"fastify-plugin": "^5.0.1",
|
"fastify-plugin": "^5.0.1",
|
||||||
"joi": "^18.0.0",
|
"joi": "^18.0.0",
|
||||||
|
"otp": "^1.1.2",
|
||||||
|
"rfc4648": "^1.5.4",
|
||||||
"uuidv7": "^1.0.2"
|
"uuidv7": "^1.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
||||||
|
|
@ -2,42 +2,15 @@
|
||||||
//!
|
//!
|
||||||
//! This file is here because it is easier to share code in here.
|
//! This file is here because it is easier to share code in here.
|
||||||
|
|
||||||
import { FastifyInstance } from "fastify";
|
import type { Database } from "@shared/database";
|
||||||
import type { Database } from "@shared/database"
|
import type { UserId } from "../database/mixin/user";
|
||||||
import { UserId } from "../database/mixin/user";
|
import OTP, * as OtpModules from "otp";
|
||||||
|
|
||||||
export default {};
|
let secret = "JKZSGXRCBP3UHOFVDVLYQ3W43IZH3D76";
|
||||||
|
let otp = new OTP({ secret, name: "test" });
|
||||||
|
|
||||||
|
console.log(`${otp.totpURL}`);
|
||||||
class OTP {
|
console.log(new URL(otp.totpURL));
|
||||||
private db: Database;
|
setInterval(() => {
|
||||||
private static EPOCH: number = 0;
|
console.log(`${otp.totp(Date.now())}`);
|
||||||
private static KEY_SIZE: number = 64;
|
}, 999);
|
||||||
private static TIME_STEP: number = 30;
|
|
||||||
|
|
||||||
constructor(db: Database) {
|
|
||||||
this.db = db;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Now(): number {
|
|
||||||
return Math.floor(Date.now() / 1000)
|
|
||||||
}
|
|
||||||
|
|
||||||
private static getT(): number {
|
|
||||||
return Math.floor((OTP.Now() - this.EPOCH) / this.TIME_STEP)
|
|
||||||
}
|
|
||||||
|
|
||||||
public verify(userid: UserId, code: string): boolean {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public newUser(userid: UserId): string {
|
|
||||||
return "super topt secret";
|
|
||||||
}
|
|
||||||
|
|
||||||
public generate(userid: UserId): string | null {
|
|
||||||
let secret = this.db.getUserOTPSecret(userid);
|
|
||||||
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,10 @@ import fastifyJwt from "@fastify/jwt";
|
||||||
import { FastifyPluginAsync } from "fastify";
|
import { FastifyPluginAsync } from "fastify";
|
||||||
import fp from 'fastify-plugin'
|
import fp from 'fastify-plugin'
|
||||||
import { user } from "@shared/database"
|
import { user } from "@shared/database"
|
||||||
|
import OTP from "otp";
|
||||||
|
|
||||||
|
|
||||||
|
export const Otp = OTP;
|
||||||
export const jwtPlugin = fp<FastifyPluginAsync>(async (fastify, _opts) => {
|
export const jwtPlugin = fp<FastifyPluginAsync>(async (fastify, _opts) => {
|
||||||
let env = process.env.JWT_SECRET;
|
let env = process.env.JWT_SECRET;
|
||||||
if (env === undefined || env === null)
|
if (env === undefined || env === null)
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,10 @@
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"lib": ["ESNext"],
|
"lib": ["ESNext"],
|
||||||
"paths": {
|
"paths": {
|
||||||
|
"@shared/auth": ["@shared/src/auth"],
|
||||||
|
"@shared/auth/*": ["@shared/src/auth/*"],
|
||||||
"@shared/database": ["@shared/src/database"],
|
"@shared/database": ["@shared/src/database"],
|
||||||
"@shared/auth": ["@shared/src/auth"]
|
"@shared/database/*": ["@shared/src/database/*"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue