This commit is contained in:
Flam3rboy
2021-08-12 20:09:35 +02:00
parent a1c85f0b16
commit 08e837bf55
233 changed files with 0 additions and 0 deletions
+37
View File
@@ -0,0 +1,37 @@
const jwa = require("jwa");
var STR64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_".split("");
function base64url(string: string, encoding: string) {
// @ts-ignore
return Buffer.from(string, encoding).toString("base64").replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
}
function to64String(input: number, current = ""): string {
if (input < 0 && current.length == 0) {
input = input * -1;
}
var modify = input % 64;
var remain = Math.floor(input / 64);
var result = STR64[modify] + current;
return remain <= 0 ? result : to64String(remain, result);
}
function to64Parse(input: string) {
var result = 0;
var toProc = input.split("");
var e;
for (e in toProc) {
result = result * 64 + STR64.indexOf(toProc[e]);
}
return result;
}
// @ts-ignore
const start = `${base64url("311129357362135041")}.${to64String(Date.now())}`;
const signature = jwa("HS256").sign(start, `test`);
const token = `${start}.${signature}`;
console.log(token);
// MzExMTI5MzU3MzYyMTM1MDQx.XdQb_rA.907VgF60kocnOTl32MSUWGSSzbAytQ0jbt36KjLaxuY
// MzExMTI5MzU3MzYyMTM1MDQx.XdQbaPy.4vGx4L7IuFJGsRe6IL3BeybLIvbx4Vauvx12pwNsy2U
+13
View File
@@ -0,0 +1,13 @@
import jwt from "jsonwebtoken";
const algorithm = "HS256";
const iat = Math.floor(Date.now() / 1000);
// @ts-ignore
const token = jwt.sign({ id: "311129357362135041" }, "secret", {
algorithm,
});
console.log(token);
const decoded = jwt.verify(token, "secret", { algorithms: [algorithm] });
console.log(decoded);
+40
View File
@@ -0,0 +1,40 @@
import mongoose, { Schema, Types } from "mongoose";
require("mongoose-long")(mongoose);
const userSchema = new Schema({
id: String,
});
const messageSchema = new Schema({
id: String,
content: String,
});
const message = mongoose.model("message", messageSchema, "messages");
const user = mongoose.model("user", userSchema, "users");
messageSchema.virtual("u", {
ref: user,
localField: "id",
foreignField: "id",
justOne: true,
});
messageSchema.set("toObject", { virtuals: true });
messageSchema.set("toJSON", { virtuals: true });
async function main() {
const conn = await mongoose.connect("mongodb://localhost:27017/lambert?readPreference=secondaryPreferred", {
useNewUrlParser: true,
useUnifiedTopology: false,
});
console.log("connected");
// const u = await new user({ name: "test" }).save();
// await new message({ user: u._id, content: "test" }).save();
const test = await message.findOne({}).populate("u").exec();
// @ts-ignore
console.log(test?.toJSON());
}
main();
+12
View File
@@ -0,0 +1,12 @@
import { check } from "./../util/passwordStrength";
console.log(check("123456789012345"));
// -> 0.25
console.log(check("ABCDEFGHIJKLMOPQ"));
// -> 0.25
console.log(check("ABC123___...123"));
// ->
console.log(check(""));
// ->
// console.log(check(""));
// // ->
+39
View File
@@ -0,0 +1,39 @@
// @ts-nocheck
import "missing-native-js-functions";
import { config } from "dotenv";
config();
import { DiscordServer } from "../Server";
import fetch from "node-fetch";
import { promises } from "fs";
const count = 100;
async function main() {
const server = new DiscordServer({ port: 3000 });
await server.start();
const tasks = [];
for (let i = 0; i < count; i++) {
tasks.push(test());
}
await Promise.all(tasks);
console.log("logging in 5secs");
setTimeout(async () => {
await test();
process.exit();
}, 5000);
}
main();
async function test() {
const res = await fetch("http://localhost:3000/api/v8/guilds/813524615463698433/members/813524464300982272", {
headers: {
authorization:
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjgxMzUyNDQ2NDMwMDk4MjI3MiIsImlhdCI6MTYxNDAyOTc0Nn0.6WQiU4D5HHRi3sliHOQe1hsW-hZTEttvdtZuNIdviNI",
},
});
return await res.text();
}
+3
View File
@@ -0,0 +1,3 @@
import { Snowflake } from "@fosscord/server-util";
console.log(Snowflake.deconstruct("0"));