diff options
| author | JustZvan <justzvan@justzvan.xyz> | 2026-04-08 19:22:29 +0200 |
|---|---|---|
| committer | JustZvan <justzvan@justzvan.xyz> | 2026-04-08 19:22:29 +0200 |
| commit | 12a1e744f90fe7f39808caa3f97d6885a883f34a (patch) | |
| tree | 67f5b9c0bd72858dccf2d06b1b4bc7ba6ad417e0 /src/account | |
| parent | 6a5a165a035459af601006286e4a6e46ded1487c (diff) | |
feat: use otp for kid linkmain
Diffstat (limited to 'src/account')
| -rw-r--r-- | src/account/kid_link_code.ts | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/account/kid_link_code.ts b/src/account/kid_link_code.ts new file mode 100644 index 0000000..a9d3c63 --- /dev/null +++ b/src/account/kid_link_code.ts @@ -0,0 +1,23 @@ +import { randomInt } from "node:crypto"; + +const KID_LINK_CODE_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + +export const KID_LINK_CODE_TTL_SECONDS = 5 * 60; +export const KID_LINK_CODE_REGEX = /^[A-Z0-9]{3}-[A-Z0-9]{3}$/; + +export function generateKidLinkCode(): string { + const rawCode = Array.from({ length: 6 }, () => { + const index = randomInt(0, KID_LINK_CODE_CHARACTERS.length); + return KID_LINK_CODE_CHARACTERS[index]!; + }).join(""); + + return `${rawCode.slice(0, 3)}-${rawCode.slice(3)}`; +} + +export function normalizeKidLinkCode(value: string): string { + return value.trim().toUpperCase(); +} + +export function getKidLinkCodeRedisKey(code: string): string { + return `kid-link-code:${code}`; +} |