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-plugin": "^5.0.1",
|
||||
"joi": "^18.0.0",
|
||||
"otp": "^1.1.2",
|
||||
"rfc4648": "^1.5.4",
|
||||
"uuidv7": "^1.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
|||
|
|
@ -2,42 +2,15 @@
|
|||
//!
|
||||
//! This file is here because it is easier to share code in here.
|
||||
|
||||
import { FastifyInstance } from "fastify";
|
||||
import type { Database } from "@shared/database"
|
||||
import { UserId } from "../database/mixin/user";
|
||||
import type { Database } from "@shared/database";
|
||||
import type { UserId } from "../database/mixin/user";
|
||||
import OTP, * as OtpModules from "otp";
|
||||
|
||||
export default {};
|
||||
let secret = "JKZSGXRCBP3UHOFVDVLYQ3W43IZH3D76";
|
||||
let otp = new OTP({ secret, name: "test" });
|
||||
|
||||
|
||||
class OTP {
|
||||
private db: Database;
|
||||
private static EPOCH: number = 0;
|
||||
private static KEY_SIZE: number = 64;
|
||||
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
|
||||
}
|
||||
}
|
||||
console.log(`${otp.totpURL}`);
|
||||
console.log(new URL(otp.totpURL));
|
||||
setInterval(() => {
|
||||
console.log(`${otp.totp(Date.now())}`);
|
||||
}, 999);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,10 @@ import fastifyJwt from "@fastify/jwt";
|
|||
import { FastifyPluginAsync } from "fastify";
|
||||
import fp from 'fastify-plugin'
|
||||
import { user } from "@shared/database"
|
||||
import OTP from "otp";
|
||||
|
||||
|
||||
export const Otp = OTP;
|
||||
export const jwtPlugin = fp<FastifyPluginAsync>(async (fastify, _opts) => {
|
||||
let env = process.env.JWT_SECRET;
|
||||
if (env === undefined || env === null)
|
||||
|
|
|
|||
|
|
@ -22,8 +22,10 @@
|
|||
"skipLibCheck": true,
|
||||
"lib": ["ESNext"],
|
||||
"paths": {
|
||||
"@shared/auth": ["@shared/src/auth"],
|
||||
"@shared/auth/*": ["@shared/src/auth/*"],
|
||||
"@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