Public code lab · 01TypeScript policy · Ed25519 verification · Executable tests

A release should earnthe right to advance.

Change the evidence below and inspect every invariant. The gate has no warning state and no optimistic fallback. A candidate is ready only when identity, region, integrity, compatibility, runtime, tests, budget, and rollback all pass.

Sanitized reference implementation

This is newly written portfolio code that demonstrates the decision model and cryptographic verification. It contains no GolfJoy source, secrets, signing keys, proprietary schemas, or production endpoints. A separate adapter verifies signed bytes; runtime, storage, smoke-test and rollback observations remain release-pipeline responsibilities.

From file bytes to trusted evidence

Verify the artifact.
Then decide whether to release.

This Node.js adapter checks a real Ed25519 signature and SHA-256 digest before producing evidence for the decision core. Change one byte, the signer, or the signed metadata and the tests demonstrate rejection.

A valid signature proves neither a safe rollout nor the right deployment target. Separate policy checks still enforce region, freshness, smoke tests, and rollback readiness.

See the architecture and tradeoff
  1. Trust the configured signer

    The public key comes from trusted configuration, never from the candidate artifact.

  2. Authenticate the exact manifest bytes

    Ed25519 binds the metadata and artifact digest to that signer.

  3. Match the artifact to its signed digest

    SHA-256 detects content changes; schema and size checks reject malformed input.

  4. Evaluate release policy separately

    Verified evidence enters the same deterministic gate used by the simulator.

Reproduce it locally

Download these three files into one folder. Use Node.js 22.18 or newer; no additional packages are needed.

Run the cryptographic and policy integration tests

node --test release-artifact.test.mjs

Tests generate temporary signing keys in memory and exercise real artifact bytes. They do not deploy anything.

Inspect the complete verification adapter
/**
 * Independent reference adapter, not GolfJoy source or a deployment service.
 *
 * Input: bounded Uint8Array/Buffer manifest and artifact bytes, a raw 64-byte
 * Ed25519 signature, and a public KeyObject loaded from trusted configuration.
 * Sign SIGNING_DOMAIN (UTF-8) || the EXACT manifest bytes, not reserialized JSON.
 * The candidate cannot supply a key. No private keys are stored in this module.
 *
 * Success returns a frozen manifest and only the evidence established here.
 * The expected candidateRevision must come from the trusted build request.
 * Smoke tests and rollback availability must come from separate trusted checks.
 * This verifies in-memory snapshots; it does not establish runtime, deployment,
 * or business results. A publisher must deploy the same verified artifact,
 * not re-read an untrusted path after checking it.
 */
import { createHash, KeyObject, timingSafeEqual, verify } from "node:crypto";

export const SIGNING_DOMAIN = "yuanzhou.dev/release-artifact/v1\0";
export const LIMITS = Object.freeze({
  manifestBytes: 16 * 1024,
  artifactBytes: 8 * 1024 * 1024,
});

const fields = [
  "revision", "buildId", "region", "schemaVersion", "createdAt",
  "runtimeProofs", "dependencyBytes", "artifactSha256",
];
const reject = (code) => Object.freeze({ ok: false, code });
const identity = (value) => typeof value === "string" &&
  value.length > 0 && value.length <= 128 && value.trim() === value;

function validManifest(value) {
  if (!value || typeof value !== "object" || Array.isArray(value)) return false;
  if (Object.keys(value).length !== fields.length ||
      !fields.every((field) => Object.hasOwn(value, field))) return false;
  if (![value.revision, value.buildId, value.region].every(identity)) return false;
  if (!Number.isSafeInteger(value.schemaVersion) || value.schemaVersion < 1 ||
      !Number.isSafeInteger(value.dependencyBytes) || value.dependencyBytes < 0) return false;
  if (!Array.isArray(value.runtimeProofs) || value.runtimeProofs.length > 16 ||
      !value.runtimeProofs.every(identity) ||
      new Set(value.runtimeProofs).size !== value.runtimeProofs.length) return false;
  if (typeof value.artifactSha256 !== "string" ||
      !/^[a-f0-9]{64}$/.test(value.artifactSha256)) return false;
  if (typeof value.createdAt !== "string" ||
      !/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(value.createdAt)) return false;
  const timestamp = Date.parse(value.createdAt);
  return Number.isFinite(timestamp) && new Date(timestamp).toISOString() === value.createdAt;
}

/**
 * On rejection there is no usable manifest or verification evidence.
 * On success, combine evidence with the independently expected revision and
 * real smoke/rollback observations before calling
 * evaluateRelease(manifest, evidence, policy, nowMs).
 */
export function verifyReleaseArtifact(input) {
  try {
    const { manifestBytes, artifactBytes, signature, trustedPublicKey } = input;
    if (!(manifestBytes instanceof Uint8Array) || !(artifactBytes instanceof Uint8Array)) {
      return reject("invalid_input");
    }
    if (manifestBytes.byteLength === 0 || manifestBytes.byteLength > LIMITS.manifestBytes ||
        artifactBytes.byteLength > LIMITS.artifactBytes) return reject("size_limit");
    if (!(signature instanceof Uint8Array) || signature.byteLength !== 64) {
      return reject("invalid_signature");
    }
    if (!(trustedPublicKey instanceof KeyObject) || trustedPublicKey.type !== "public" ||
        trustedPublicKey.asymmetricKeyType !== "ed25519") return reject("untrusted_key");

    // Copy bounded input so parsing and hashing use the bytes verified here.
    const manifestBuffer = Buffer.from(manifestBytes);
    const artifactBuffer = Buffer.from(artifactBytes);
    const signedBytes = Buffer.concat([Buffer.from(SIGNING_DOMAIN, "utf8"), manifestBuffer]);
    if (!verify(null, signedBytes, trustedPublicKey, Buffer.from(signature))) {
      return reject("invalid_signature");
    }

    let candidate;
    try {
      candidate = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(manifestBuffer));
    } catch {
      return reject("invalid_manifest");
    }
    if (!validManifest(candidate)) return reject("invalid_manifest");
    const digest = createHash("sha256").update(artifactBuffer).digest();
    if (!timingSafeEqual(digest, Buffer.from(candidate.artifactSha256, "hex"))) {
      return reject("artifact_mismatch");
    }

    // Select fields explicitly; never return the parsed candidate object.
    const manifest = Object.freeze({
      revision: candidate.revision,
      buildId: candidate.buildId,
      region: candidate.region,
      schemaVersion: candidate.schemaVersion,
      createdAt: candidate.createdAt,
      runtimeProofs: Object.freeze([...candidate.runtimeProofs]),
      dependencyBytes: candidate.dependencyBytes,
      artifactSha256: candidate.artifactSha256,
    });
    const evidence = Object.freeze({
      signatureValid: true,
      hashMatches: true,
    });
    return Object.freeze({ ok: true, manifest, evidence });
  } catch {
    return reject("invalid_input");
  }
}

01 · Boundary design

Keep side effects outside the decision.

Adapters gather cryptographic, storage, runtime, and smoke-test evidence. The core remains a deterministic function, so the same inputs always produce the same decision and failure list.

01

Adapters

Crypto, storage, runtime, smoke tests

02

Pure gate

Manifest + evidence + policy + clock

03

Controller

Advance only on an explicit ready

02 · Interactive release gate

Break an invariant. Watch it fail closed.

Choose a preset or toggle individual evidence. The result is calculated in your browser by the downloadable TypeScript source shown below.

Policy simulation / decision trace

Every boundary has evidence.

  1. 01IdentityChecks pass
  2. 02ArtifactChecks pass
  3. 03Content & runtimeChecks pass
  4. 04RolloutChecks pass

All checks are evaluated immediately. The trace stops at the first failing group. Signature inputs here are simulated evidence flags; actual byte verification is separate.

Simulated policy inputs

Preset scenario

10/10 flags enabled
1 / Candidate & policy

Which revision, region, schema and time window are being considered?

2 / Simulated verification flags

These switches stand in for adapter evidence. Real byte verification is separate.

3 / Runtime & rollout readiness

Runtime, dependency budget, smoke tests and the rollback target remain independent requirements.

Inspect exact inputs & fixed clock

These values enter the downloadable evaluator. Signature and hash flags here are simulated; this panel does not verify bytes.

{
  "evaluationTime": "2026-08-18T18:00:00.000Z",
  "manifest": {
    "revision": "rev-7f3a2c",
    "buildId": "build-2026-08-18.1",
    "region": "cn-prod",
    "schemaVersion": 3,
    "createdAt": "2026-08-18T17:40:00.000Z",
    "runtimeProofs": [
      "linux-x64-node22"
    ],
    "dependencyBytes": 7800000
  },
  "evidence": {
    "candidateRevision": "rev-7f3a2c",
    "signatureValid": true,
    "hashMatches": true,
    "smokeTests": [
      {
        "name": "health",
        "passed": true
      },
      {
        "name": "content",
        "passed": true
      },
      {
        "name": "route-policy",
        "passed": true
      }
    ],
    "rollbackTargetAvailable": true
  },
  "policy": {
    "expectedRegion": "cn-prod",
    "allowedSchemaVersions": [
      3
    ],
    "maxContentAgeMs": 3600000,
    "requiredRuntime": "linux-x64-node22",
    "dependencyBudgetBytes": 8500000,
    "requireRollbackTarget": true
  }
}

All policy checks passed for this simulated input.

Policy simulation result

READY

Every required invariant has evidence.

10/10

checks passed

Policy evidence is not artifact verification.

This decision uses the ten switches beside it. The downloaded Node adapter above checks actual Ed25519 signatures and SHA-256 bytes.

Inspect actual byte verification ↑

Candidate identity

manifest rev-7f3a2c / evidence rev-7f3a2c

Target region

cn-prod must equal cn-prod

Artifact signature

cryptographic adapter reported a valid signature

Artifact hash

candidate bytes match the signed manifest

Content schema

schema v3; allowed: 3

Content age

20 minutes old; limit 60

Runtime proof

linux-x64-node22 proof must be present

Dependency budget

7.4 MB / 8.1 MB

Candidate smoke tests

3/3 checks passed

Rollback target

previous verified artifact is available

03 · Inspect the implementation

The demo and the download use the same source.

The decision core is small on purpose. Its job is to make every invariant explicit, preserve all failure reasons, reject empty evidence, and stay deterministic under test.

public/samples/release-gate.ts
/**
 * Sanitized reference implementation of a fail-closed release gate.
 *
 * This module contains no customer source, secrets, signing keys, proprietary
 * schemas, or production endpoints. I/O and cryptographic verification belong
 * in adapters. The gate consumes their evidence and makes one deterministic
 * decision: a candidate is ready, or it is rejected with explicit reasons.
 */

export type ReleaseStatus = "ready" | "rejected";

export type CheckCode =
  | "candidate_identity"
  | "target_region"
  | "artifact_signature"
  | "artifact_hash"
  | "content_schema"
  | "content_age"
  | "runtime_proof"
  | "dependency_budget"
  | "smoke_tests"
  | "rollback_target";

export type ReleaseManifest = {
  revision: string;
  buildId: string;
  region: string;
  schemaVersion: number;
  createdAt: string;
  runtimeProofs: readonly string[];
  dependencyBytes: number;
};

export type VerificationEvidence = {
  candidateRevision: string;
  signatureValid: boolean;
  hashMatches: boolean;
  smokeTests: readonly {
    name: string;
    passed: boolean;
  }[];
  rollbackTargetAvailable: boolean;
};

export type ReleasePolicy = {
  expectedRegion: string;
  allowedSchemaVersions: readonly number[];
  maxContentAgeMs: number;
  requiredRuntime: string;
  dependencyBudgetBytes: number;
  requireRollbackTarget: boolean;
};

export type ReleaseCheck = {
  code: CheckCode;
  label: string;
  passed: boolean;
  detail: string;
};

export type ReleaseDecision = {
  status: ReleaseStatus;
  checks: readonly ReleaseCheck[];
  failedCodes: readonly CheckCode[];
  evaluatedAt: string;
};

function check(
  code: CheckCode,
  label: string,
  passed: boolean,
  detail: string,
): ReleaseCheck {
  return { code, label, passed, detail };
}

function formatBytes(bytes: number): string {
  return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
}

export function evaluateRelease(
  manifest: ReleaseManifest,
  evidence: VerificationEvidence,
  policy: ReleasePolicy,
  nowMs: number,
): ReleaseDecision {
  const createdAtMs = Date.parse(manifest.createdAt);
  const contentAgeMs = nowMs - createdAtMs;
  const hasValidTimestamp = Number.isFinite(createdAtMs);
  const contentAgeIsValid =
    hasValidTimestamp &&
    contentAgeMs >= 0 &&
    contentAgeMs <= policy.maxContentAgeMs;
  const allSmokeTestsPass =
    evidence.smokeTests.length > 0 &&
    evidence.smokeTests.every((test) => test.passed);

  const checks: readonly ReleaseCheck[] = [
    check(
      "candidate_identity",
      "Candidate identity",
      manifest.revision.length > 0 &&
        manifest.buildId.length > 0 &&
        manifest.revision === evidence.candidateRevision,
      `manifest ${manifest.revision || "missing"} / evidence ${
        evidence.candidateRevision || "missing"
      }`,
    ),
    check(
      "target_region",
      "Target region",
      manifest.region === policy.expectedRegion,
      `${manifest.region} must equal ${policy.expectedRegion}`,
    ),
    check(
      "artifact_signature",
      "Artifact signature",
      evidence.signatureValid,
      evidence.signatureValid
        ? "cryptographic adapter reported a valid signature"
        : "signature evidence is missing or invalid",
    ),
    check(
      "artifact_hash",
      "Artifact hash",
      evidence.hashMatches,
      evidence.hashMatches
        ? "candidate bytes match the signed manifest"
        : "candidate bytes do not match the signed manifest",
    ),
    check(
      "content_schema",
      "Content schema",
      policy.allowedSchemaVersions.includes(manifest.schemaVersion),
      `schema v${manifest.schemaVersion}; allowed: ${policy.allowedSchemaVersions.join(
        ", ",
      )}`,
    ),
    check(
      "content_age",
      "Content age",
      contentAgeIsValid,
      hasValidTimestamp
        ? `${Math.max(0, Math.round(contentAgeMs / 60_000))} minutes old; limit ${Math.round(
            policy.maxContentAgeMs / 60_000,
          )}`
        : "manifest timestamp is invalid",
    ),
    check(
      "runtime_proof",
      "Runtime proof",
      manifest.runtimeProofs.includes(policy.requiredRuntime),
      `${policy.requiredRuntime} proof must be present`,
    ),
    check(
      "dependency_budget",
      "Dependency budget",
      manifest.dependencyBytes <= policy.dependencyBudgetBytes,
      `${formatBytes(manifest.dependencyBytes)} / ${formatBytes(
        policy.dependencyBudgetBytes,
      )}`,
    ),
    check(
      "smoke_tests",
      "Candidate smoke tests",
      allSmokeTestsPass,
      `${evidence.smokeTests.filter((test) => test.passed).length}/${
        evidence.smokeTests.length
      } checks passed`,
    ),
    check(
      "rollback_target",
      "Rollback target",
      !policy.requireRollbackTarget || evidence.rollbackTargetAvailable,
      evidence.rollbackTargetAvailable
        ? "previous verified artifact is available"
        : "no verified rollback target is available",
    ),
  ];

  const failedCodes = checks
    .filter((item) => !item.passed)
    .map((item) => item.code);

  return {
    status: failedCodes.length === 0 ? "ready" : "rejected",
    checks,
    failedCodes,
    evaluatedAt: new Date(nowMs).toISOString(),
  };
}

Deterministic

Clock is injected. No hidden I/O or mutable global state.

Fail-closed

Missing, empty, stale, or mismatched evidence rejects the candidate.

Auditable

Every invariant returns a stable code, label, result, and detail.

From design judgment to working code

This is how I turn a reliability requirement into explicit, testable behavior.

Yuan Zhou · Public engineering code labSanitized · Deterministic · Tested