Skip to main content

apps/gateway/src/services/audit.ts

Metadata

Indexed Symbols

  • buildAuditCredential (line 5, function) - Implements build audit credential for service-layer operations.

Markdown Headings (if applicable)

No markdown headings detected.

Source Preview

import { createHash, createHmac, randomUUID } from "node:crypto";
import type { AuditCredential } from "@anchor/contracts";
import { env } from "../config/env.js";

export function buildAuditCredential(
workspaceId: string,
executionId: string,
correlationId: string,
payload: unknown
): AuditCredential {
const serialized = JSON.stringify(payload);
const hash = createHash("sha256").update(serialized).digest("hex");
const signature = createHmac("sha256", env.auditSigningSecret).update(`${env.auditSigningKeyId}:${hash}`).digest("hex");

return {
id: randomUUID(),
workspaceId,
executionId,
correlationId,
algorithm: "hmac-sha256",
keyId: env.auditSigningKeyId,
hash,
signature,
issuedAt: new Date().toISOString()
};