Files
ruflo/v3/@claude-flow/guidance/src/crypto-utils.ts
T
rUvandClaude Opus 4.5 28b5bdd247 Checkpoint: File edits
Automatic checkpoint created by Claude Code
- Branch: claude/guidance-control-plane-uhmR3
- Timestamp: 2026-02-02T03:47:11Z
- Changes: 3 file(s)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-02 03:47:11 +00:00

27 lines
846 B
TypeScript

/**
* Shared Cryptographic Utilities
*
* Centralises timing-safe comparison so every module that verifies
* HMAC signatures uses the same constant-time implementation.
*
* @module @claude-flow/guidance/crypto-utils
*/
import { timingSafeEqual as nodeTimingSafeEqual } from 'node:crypto';
/**
* Constant-time string comparison to prevent timing attacks on HMAC signatures.
*
* Delegates to Node.js `crypto.timingSafeEqual` via `Buffer.from` for
* encoding-safe comparison. Falls back to a manual XOR loop when the
* buffers have different byte lengths (which the native function rejects).
*/
export function timingSafeEqual(a: string, b: string): boolean {
const bufA = Buffer.from(a, 'utf-8');
const bufB = Buffer.from(b, 'utf-8');
if (bufA.length !== bufB.length) return false;
return nodeTimingSafeEqual(bufA, bufB);
}