mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-23 08:45:50 +00:00
style: 完成所有文件的lint
This commit is contained in:
@@ -1,54 +1,60 @@
|
||||
import { createHash, timingSafeEqual } from "node:crypto";
|
||||
import { createHash, timingSafeEqual } from 'node:crypto'
|
||||
|
||||
const WS_AUTH_PROTOCOL_PREFIX = "rcs.auth.";
|
||||
const WS_AUTH_PROTOCOL_PREFIX = 'rcs.auth.'
|
||||
|
||||
function sha256(value: string): Buffer {
|
||||
return createHash("sha256").update(value).digest();
|
||||
return createHash('sha256').update(value).digest()
|
||||
}
|
||||
|
||||
export function encodeWebSocketAuthProtocol(token: string): string {
|
||||
return `${WS_AUTH_PROTOCOL_PREFIX}${Buffer.from(token, "utf8").toString("base64url")}`;
|
||||
return `${WS_AUTH_PROTOCOL_PREFIX}${Buffer.from(token, 'utf8').toString('base64url')}`
|
||||
}
|
||||
|
||||
export function decodeWebSocketAuthProtocol(protocolHeader: string | undefined): string | undefined {
|
||||
export function decodeWebSocketAuthProtocol(
|
||||
protocolHeader: string | undefined,
|
||||
): string | undefined {
|
||||
if (!protocolHeader) {
|
||||
return undefined;
|
||||
return undefined
|
||||
}
|
||||
|
||||
for (const protocol of protocolHeader.split(",")) {
|
||||
const trimmed = protocol.trim();
|
||||
for (const protocol of protocolHeader.split(',')) {
|
||||
const trimmed = protocol.trim()
|
||||
if (!trimmed.startsWith(WS_AUTH_PROTOCOL_PREFIX)) {
|
||||
continue;
|
||||
continue
|
||||
}
|
||||
|
||||
const encoded = trimmed.slice(WS_AUTH_PROTOCOL_PREFIX.length);
|
||||
const encoded = trimmed.slice(WS_AUTH_PROTOCOL_PREFIX.length)
|
||||
if (!encoded) {
|
||||
return undefined;
|
||||
return undefined
|
||||
}
|
||||
|
||||
try {
|
||||
const token = Buffer.from(encoded, "base64url").toString("utf8");
|
||||
return token.length > 0 ? token : undefined;
|
||||
const token = Buffer.from(encoded, 'base64url').toString('utf8')
|
||||
return token.length > 0 ? token : undefined
|
||||
} catch {
|
||||
return undefined;
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
return undefined
|
||||
}
|
||||
|
||||
export function extractBearerToken(authorizationHeader: string | undefined): string | undefined {
|
||||
return authorizationHeader?.startsWith("Bearer ")
|
||||
? authorizationHeader.slice("Bearer ".length)
|
||||
: undefined;
|
||||
export function extractBearerToken(
|
||||
authorizationHeader: string | undefined,
|
||||
): string | undefined {
|
||||
return authorizationHeader?.startsWith('Bearer ')
|
||||
? authorizationHeader.slice('Bearer '.length)
|
||||
: undefined
|
||||
}
|
||||
|
||||
export function extractWebSocketAuthToken(headers: {
|
||||
authorization?: string;
|
||||
protocol?: string;
|
||||
authorization?: string
|
||||
protocol?: string
|
||||
}): string | undefined {
|
||||
return extractBearerToken(headers.authorization) ??
|
||||
decodeWebSocketAuthProtocol(headers.protocol);
|
||||
return (
|
||||
extractBearerToken(headers.authorization) ??
|
||||
decodeWebSocketAuthProtocol(headers.protocol)
|
||||
)
|
||||
}
|
||||
|
||||
export function authTokensEqual(
|
||||
@@ -56,7 +62,7 @@ export function authTokensEqual(
|
||||
expectedToken: string | undefined,
|
||||
): boolean {
|
||||
if (!providedToken || !expectedToken) {
|
||||
return false;
|
||||
return false
|
||||
}
|
||||
return timingSafeEqual(sha256(providedToken), sha256(expectedToken));
|
||||
return timingSafeEqual(sha256(providedToken), sha256(expectedToken))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user