jormungandr-bite/packages/backend/src/misc/keypair-store.ts

13 lines
440 B
TypeScript
Raw Normal View History

2023-01-12 21:40:33 -07:00
import { UserKeypairs } from "@/models/index.js";
import type { User } from "@/models/entities/user.js";
import type { UserKeypair } from "@/models/entities/user-keypair.js";
import { Cache } from "./cache.js";
2021-03-22 00:14:54 -06:00
const cache = new Cache<UserKeypair>(Infinity);
2023-01-12 21:40:33 -07:00
export async function getUserKeypair(userId: User["id"]): Promise<UserKeypair> {
return await cache.fetch(userId, () =>
UserKeypairs.findOneByOrFail({ userId: userId }),
);
2021-03-22 00:14:54 -06:00
}