From a789a54fbbb8f7d4c60eb4932d2cfec6ba9c2b99 Mon Sep 17 00:00:00 2001 From: Moon Man Date: Mon, 1 Jan 2024 07:44:58 -0500 Subject: [PATCH] actor type, manually set id for user --- src/user.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/user.ts b/src/user.ts index 541c826..6d35b0d 100644 --- a/src/user.ts +++ b/src/user.ts @@ -59,8 +59,8 @@ export const getId = async (nickname: string): Promise => .then((rec) => !!rec ? rec.id : null) ; -export const newUser = async (nickname: string, name: string, bio: string): Promise => { - const { pub, priv } = await (new Promise((resolve, reject) => { +export const newUser = async (nickname: string, name: string, bio: string, actorType = "Person", id?: number): Promise => { + const { public_key, private_key } = await (new Promise((resolve, reject) => { generateKeyPair("rsa", { modulusLength: 2048, publicKeyEncoding: { @@ -71,19 +71,21 @@ export const newUser = async (nickname: string, name: string, bio: string): Prom type: "pkcs8", format: "pem" } - }, (err, pub, priv) => { + }, (err, public_key, private_key) => { if (err) reject(err); - else resolve({ pub, priv }); + else resolve({ public_key, private_key }); }) - }) as Promise<{ pub: string, priv: string }>); + }) as Promise<{ public_key: string, private_key: string }>); return db("users") .insert({ + ...(typeof id === "undefined" ? {} : { id }), + actor_type: actorType, name, nickname, bio, - public_key: pub, - private_key: priv, + public_key, + private_key, deleted: false, created_at: new Date() })