Download packages/kap-server/src/services/auth/credentials.ts from SaylorTwift/kimi-code: direct link, hf CLI and curl.
- Browser
- Download file 762 Bytes
-
https://huggingface.co/SaylorTwift/kimi-code/resolve/main/packages/kap-server/src/services/auth/credentials.ts
- Command line
-
hf download hf://SaylorTwift/kimi-code/packages/kap-server/src/services/auth/credentials.ts
-
curl -L -o credentials.ts https://huggingface.co/SaylorTwift/kimi-code/resolve/main/packages/kap-server/src/services/auth/credentials.ts
762 Bytes
| import { timingSafeEqual } from 'node:crypto'; | |
| import type { IAuthTokenService } from './authTokenService'; | |
| export type CredentialValidator = (candidate: string) => Promise<boolean>; | |
| function timingSafeMatch(candidate: string, expected: string): boolean { | |
| const a = Buffer.from(candidate); | |
| const b = Buffer.from(expected); | |
| return a.length === b.length && timingSafeEqual(a, b); | |
| } | |
| export function createCredentialValidator( | |
| authTokenService: IAuthTokenService, | |
| rpcToken?: string, | |
| ): CredentialValidator { | |
| return async (candidate) => { | |
| if (await authTokenService.isValid(candidate)) return true; | |
| if (rpcToken !== undefined && candidate.length > 0 && timingSafeMatch(candidate, rpcToken)) { | |
| return true; | |
| } | |
| return false; | |
| }; | |
| } | |