summaryrefslogtreecommitdiff
path: root/src/util/generator.ts
diff options
context:
space:
mode:
authorRaphael Kabo <raphaelkabo@hey.com>2023-10-07 18:28:57 +0100
committerRaphael Kabo <raphaelkabo@hey.com>2023-10-07 18:28:57 +0100
commit499da92303ff1ad66807f373b06ad3040c774eaa (patch)
treea137490ad8afd14e4682436b989825cc1e6769ef /src/util/generator.ts
parente9ee1fbb91447f27d1e74bdc12c247804d78be22 (diff)
Move nanoid generator to lib
Diffstat (limited to 'src/util/generator.ts')
-rw-r--r--src/util/generator.ts10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/util/generator.ts b/src/util/generator.ts
index c3712c1..882f114 100644
--- a/src/util/generator.ts
+++ b/src/util/generator.ts
@@ -1,5 +1,13 @@
import crypto from "crypto";
+import { customAlphabet } from "nanoid";
+// This alphabet (used to generate all event, group, etc. IDs) is missing '-'
+// because ActivityPub doesn't like it in IDs
+const nanoid = customAlphabet(
+ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_",
+ 21,
+);
+
const generateAlphanumericString = (length: number) => {
return Array(length)
.fill(0)
@@ -7,6 +15,8 @@ const generateAlphanumericString = (length: number) => {
.join("");
};
+export const generateEventID = () => nanoid();
+
export const generateEditToken = () => generateAlphanumericString(32);
export const generateRSAKeypair = () => {