first commit
Some checks failed
Publish / Publish Job (push) Failing after 37s

This commit is contained in:
Дмитрий
2026-03-27 10:38:23 +03:00
commit be1e21e699
21 changed files with 1002 additions and 0 deletions

17
lib/utils/base64.ts Normal file
View File

@@ -0,0 +1,17 @@
export function base64UrlEncode(buf: Buffer | string) {
const s = typeof buf === 'string' ? Buffer.from(buf) : buf
return s
.toString('base64')
.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=+$/, '')
}
export function base64UrlDecode(str: string) {
str = str.replace(/-/g, '+').replace(/_/g, '/')
while (str.length % 4) str += '='
return Buffer.from(str, 'base64').toString()
}

10
lib/utils/crypto.ts Normal file
View File

@@ -0,0 +1,10 @@
import { timingSafeEqual } from 'crypto'
export function constantTimeEqual(a: string, b: string) {
const bufA = Buffer.from(a)
const bufB = Buffer.from(b)
if (bufA.length !== bufB.length) return false
return timingSafeEqual(bufA, bufB)
}

2
lib/utils/index.ts Normal file
View File

@@ -0,0 +1,2 @@
export * from './base64'
export * from './crypto'