/*
Maintains packages/os/site-kernel-integrity/src/signing.ts as an authored site-kernel-integrity authored module so agents can evolve it without rediscovering local boundaries.
- Do not handle non-cryptographic signing methods.
- Avoid managing non-build related artifacts.
- RFC-0931: add signBuildIdentity, writeReleasePublicKey, verifyBuildIdentitySignature for Ed25519 signing of build-identity.json in deploy pipeline.
- RFC-1097: step 6 — compass.migrate codemod run
Mechanical v1 to v2 header migration across the workspace: 942 files rewritten — CHANGE_SUMMARY windows collapsed into history, forbidden v1 blocks stripped, KEY_DECISIONS seeded from @ai-invariant comments (5 files) or TODO placeholders (103 files), blocks reordered to canonical order.
- RFC-1097: sweep — werkstatt-engine clean
Sweep batch 4: 73 Compass headers on headerless engine files (certification, component-runtime, isolation, evolution, testing), real KEY_DECISIONS on 75 files (kernel, cache, dht, swim, gitmesh, runtime), ~80 purpose expansions (CONTRACT-02/PURPOSE-02), non-goals on 13 CONTRACT-03 files, CS-07 history literal fix repo-wide (253 files). Policy: .template.ts/.template.astro excludedPaths. werkstatt-engine now 0 diagnostics.
- RFC-1149: migrate ambient filesystem and process IO to the WorkspaceIO port across engine and shared
- RFC-1188: fo-review fix — resolvePassportSigningKey single-sources the .env-authoritative + ambient-fallback chain both the WBA resolver and agent-shared used to inline
RFC-0921
/**
* Ed25519 cryptographic signing for build artifacts.
* Provides key generation, payload signing, signature verification, and manifest handling.
*/
import path from "node:path";
import { byteHash } from "@warpgogol/werkstatt-engine/fingerprint";
import {
generateKeyPair as signingGenerateKeyPair,
toPem as signingToPem,
toHex as signingToHex,
getPublicKey as signingGetPublicKey,
privateKeyPemToBytes,
publicKeyPemToBytes,
sign as signingSign,
verify as signingVerify,
canonicalBytes as signingCanonicalBytes,
fromHex as signingFromHex,
} from "@warpgogol/werkstatt-engine/signing";
import { atomicWriteFile } from "../werkstatt/atomic.ts";
import { ensureDir, pathExists, readBuffer, readText, writeText } from "./fs.ts";
import { createDefaultIO, type WorkspaceIO } from "@warpgogol/werkstatt-shared/kernel/workspace-io";
import { readJsonFile, stableStringify } from "./json.ts";
import {
buildLatestDir,
outputsPath,
provenancePath,
signedManifestPath,
signatureBinaryPath,
signatureHexPath,
} from "./paths.ts";
import type { BuildProvenance, OutputsFile, SignablePayload, SignedManifest } from "./types.ts";
let dotEnvLoadedForCwd: string | undefined;
export interface SigningKeyPairPem {
privateKeyPem: string;
publicKeyPem: string;
}
export interface ReleaseSignatureArtifacts {
outputs: OutputsFile;
provenance: BuildProvenance;
payload: SignablePayload;
payloadBytes: Buffer;
signatureBuffer: Buffer;
signatureHex: string;
signedManifest: SignedManifest;
reusedExistingSignature: boolean;
}
function pemFromBase64(label: "PRIVATE KEY" | "PUBLIC KEY", base64Value: string): string {
const normalized = base64Value.replace(/\s+/g, "");
const lines = normalized.match(/.{1,64}/g) ?? [normalized];
return `-----BEGIN ${label}-----\n${lines.join("\n")}\n-----END ${label}-----\n`;
}
function normalizePemLikeValue(value: string, label: "PRIVATE KEY" | "PUBLIC KEY"): string {
const trimmed = value.trim();
if (trimmed.includes("-----BEGIN")) {
return trimmed.endsWith("\n") ? trimmed : `${trimmed}\n`;
}
return pemFromBase64(label, trimmed);
}
async function parseDotEnvFile(cwd: string): Promise