From e35cf325760d9ee903d3ac87cfe5ceee43f339e0 Mon Sep 17 00:00:00 2001 From: Patrick Schmitt <45056826+patschmittdev@users.noreply.github.com> Date: Fri, 20 Nov 2026 11:13:55 -0500 Subject: [PATCH] Add a reference external signer and guides for signing and agents Readers could not see a page reach Gold: the runtime verifies receipts but nothing produced one. examples/external-signer is a standalone Node signer, independent of src/, meant to run outside the vault. It shows every signed field and the numbered body with controls made visible, asks for the digest prefix on a terminal, and refuses keys inside a vault. The two new guides walk from a fresh checkout to a Gold query result and its failure cases, and set out what a proposing model, a reading agent and an operating agent may reach. Claims that the project ships no signer are scoped to the runtime (CLI, MCP server and src/), the walkthrough strings no longer say admission is human-only, and the threat model records rollback to an earlier signed page. --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- .gitignore | 3 + README.md | 4 +- SECURITY.md | 4 +- docs/authorization-protocol.md | 9 +- docs/external-signing-interop.md | 11 +- examples/external-signer/README.md | 28 + examples/external-signer/package-lock.json | 31 + examples/external-signer/package.json | 1 + examples/external-signer/signer.mjs | 441 ++++++++++++++ site/astro.config.mjs | 2 + site/src/components/AdmissionFigure.astro | 2 +- .../docs/concepts/human-authority-boundary.md | 10 +- .../getting-started/garden-walkthrough.md | 2 +- .../content/docs/guides/agents-and-models.md | 94 +++ .../content/docs/guides/external-signing.md | 135 +++++ .../guides/human-review-and-authorization.md | 9 +- site/src/content/docs/reference/cli.md | 2 +- site/src/content/docs/security/guarantees.md | 4 +- .../src/content/docs/security/threat-model.md | 6 +- site/src/pages/index.astro | 2 +- site/tests/visual.spec.ts | 4 +- src/walkthrough/garden.ts | 4 +- test/external-signer.test.ts | 554 ++++++++++++++++++ test/walkthrough.test.ts | 2 +- 25 files changed, 1333 insertions(+), 33 deletions(-) create mode 100644 examples/external-signer/README.md create mode 100644 examples/external-signer/package-lock.json create mode 100644 examples/external-signer/package.json create mode 100644 examples/external-signer/signer.mjs create mode 100644 site/src/content/docs/guides/agents-and-models.md create mode 100644 site/src/content/docs/guides/external-signing.md create mode 100644 test/external-signer.test.ts diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 41c1945..62f0bc3 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -16,7 +16,7 @@ List the targeted checks you ran. - [ ] Behavior changes include tests that use real temporary files. - [ ] Model pathways still cannot write Bronze, knowledge, trust, receipts, reviewed metadata, or indexes. -- [ ] No signer, apply, approve, promote command, or `--promote` flag was added. +- [ ] No signing, apply, approve, or promote path was added to the Ziggurat runtime (CLI, MCP server and `src/`); no `--promote` flag was added. - [ ] Retrieved content remains reference-only with `instruction_authority: none`. - [ ] Documentation and compatibility notes match the implementation. - [ ] `npm run check` passes. diff --git a/.gitignore b/.gitignore index 176992a..8532acb 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ debug-output.txt # Local model evaluation artifacts .model-runs/ + +*.pem +examples/external-signer/node_modules/ diff --git a/README.md b/README.md index c8bc56e..fe3c55c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Ziggurat -Ziggurat is a local TypeScript reference implementation of a write gate for AI memory. A model can propose what an AI system should remember, with exact citations to stored evidence. Nothing becomes durable context, which Ziggurat calls Gold, until a key listed in `config/trust.yaml` signs a detached Ed25519 receipt for that exact page. Ziggurat assumes the operator keeps that key outside model-accessible processes; it does not enforce where the key lives. Ziggurat ships no promote, approve, apply, or signer command. `ingest` is the only writer of evidence (Bronze), and `refine` writes only proposals (Silver). +Ziggurat is a local TypeScript reference implementation of a write gate for AI memory. A model can propose what an AI system should remember, with exact citations to stored evidence. Nothing becomes durable context, which Ziggurat calls Gold, until a key listed in `config/trust.yaml` signs a detached Ed25519 receipt for that exact page. Ziggurat assumes the operator keeps that key outside model-accessible processes; it does not enforce where the key lives. The Ziggurat runtime (CLI, MCP server and `src/`) has no signing, approval, apply or promotion command. The repository also contains a standalone reference signer in `examples/external-signer/`, meant to run outside the vault under the key holder's control. Tests sign only with disposable keys they generate. `ingest` is the only writer of evidence (Bronze), and `refine` writes only proposals (Silver). Documentation: [patschmittdev.github.io/Ziggurat](https://patschmittdev.github.io/Ziggurat/). @@ -60,7 +60,7 @@ node dist/src/cli/main.js query --root ./my-vault --query garden Gold is empty because no page has external authorization. Ingest creates and verifies a new Bronze record before deleting the inbox source; a duplicate leaves its source untouched. Fresh captures are restricted and PII-unknown, so default model access excludes them. -Continue with [your first vault](site/src/content/docs/getting-started/first-vault.md) and [ingest and refine](site/src/content/docs/guides/ingest-and-refine.md). +Continue with [Sign a page and reach Gold](site/src/content/docs/guides/external-signing.md), [Run Ziggurat with models and agents](site/src/content/docs/guides/agents-and-models.md), [your first vault](site/src/content/docs/getting-started/first-vault.md) and [ingest and refine](site/src/content/docs/guides/ingest-and-refine.md). ## How it works diff --git a/SECURITY.md b/SECURITY.md index 9d50cd5..a758ad0 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -14,8 +14,10 @@ The latest commit on the default branch receives security fixes. There are no ta ## Scope +Defects in `examples/external-signer/` are in scope, including showing different content than it signs, mishandling keys, or defective location checks. + In scope: bypasses of receipt admission, citation or index integrity, vault path boundaries, privacy filtering, and model transport restrictions in shipped code. -Out of scope: operator-controlled filesystem or trust-policy replacement, external signer compromise, and factual truth or human attention that the implementation does not establish. Report implementation failures that cross the documented boundary even when they start with hostile source content. +Out of scope: operator-controlled filesystem or trust-policy replacement, compromise of the signing environment itself, and factual truth or human attention that the implementation does not establish. Report implementation failures that cross the documented boundary even when they start with hostile source content. Read the [threat model](site/src/content/docs/security/threat-model.md) for assumptions, controls, and residual risks, and [guarantees](site/src/content/docs/security/guarantees.md) for enforced boundaries. diff --git a/docs/authorization-protocol.md b/docs/authorization-protocol.md index 846fe6f..e62b952 100644 --- a/docs/authorization-protocol.md +++ b/docs/authorization-protocol.md @@ -7,8 +7,10 @@ project is pre-release, so future versions may introduce a new receipt or canonicalization version rather than changing version 1 in place. The protocol lets an external human-controlled signer authorize one exact knowledge -page for Gold admission. Ziggurat verifies signatures but intentionally ships no -signing, approval, apply, or promotion command. +page for Gold admission. The Ziggurat runtime (CLI, MCP server and `src/`) verifies signatures and has no +signing, approval, apply or promotion command. The repository also contains a +standalone reference signer in `examples/external-signer/`, meant to run outside +the vault under the key holder's control. Tests sign only with disposable keys they generate. ## Trust model @@ -171,8 +173,7 @@ is a deterministic vector file for independent signer implementations. It contai - `cases[]`, each with a page body, a receipt, the trust policy to load, and the expected `{ valid, reasons }` verification result -No private key material is published. Verification, which is the only operation -Ziggurat performs, needs only the public key. A signer implementation is conformant +No private key material is published. Verification in the Ziggurat runtime needs only the public key. A signer implementation is conformant when it reproduces `canonical_page_content`, `content_sha256`, and `signing_payload` byte for byte from the frontmatter and body alone, and verifies the supplied signature against the published public key. A new signature made with an diff --git a/docs/external-signing-interop.md b/docs/external-signing-interop.md index a8f56f3..ba2bb3f 100644 --- a/docs/external-signing-interop.md +++ b/docs/external-signing-interop.md @@ -1,6 +1,6 @@ # External signing interoperability -Ziggurat verifies receipts. It does not provide a signing command, obtain a private +The Ziggurat runtime verifies receipts. It has no signing command and does not obtain a private key, establish human attention, or turn a review checklist into authorization. The separately controlled signing environment must belong to the reviewer and must not be exposed through model tools, MCP, or the vault's automation. @@ -24,7 +24,8 @@ npm run test:interop `ZIGGURAT_INTEROP_PYTHON` can select a separate Python executable. Missing Python or the package fails this explicit test rather than becoming a passing skip. -The default core test command does not install or invoke an external signer. +The default core test command invokes the standalone Node reference signer with +disposable keys. It does not install signer dependencies. The harness uses only published vectors and disposable test keys; it is not a command for authorizing real pages. @@ -57,9 +58,9 @@ payload defined by receipt v1. 7. Rebuild and inspect eligibility reasons. Changing the page after signing, using a removed key, or leaving another admission rule unsatisfied must not admit it. -This is an interoperability procedure, not a shipped signer or a key-custody -service. Choose or maintain the external approval interface under the reviewer's -control, and test it against the public vectors before using a real key. +The repository includes a standalone reference signer in `examples/external-signer/` +for use outside the vault. It is not a key-custody service. Keep its interface under +the intended key holder's control and test it against the public vectors. ## Capability checks diff --git a/examples/external-signer/README.md b/examples/external-signer/README.md new file mode 100644 index 0000000..1571525 --- /dev/null +++ b/examples/external-signer/README.md @@ -0,0 +1,28 @@ +# Standalone external signer + +Copy this directory to a separate signing environment outside the vault. Use +Node 22 or newer and `npm ci --ignore-scripts` there (requires registry access). The only dependency +is the exact `yaml` version in package.json. There are no package scripts. + +See the repository guide at +`site/src/content/docs/guides/external-signing.md` for the full workflow. +Run `node signer.mjs keygen --private-key ~/ziggurat-reviewer/reviewer-a.pem --reviewer-id reviewer-a --key-id reviewer-a-2026`. +Run `node signer.mjs sign --vault /vault --page /vault/knowledge/garden.md --private-key ~/ziggurat-reviewer/reviewer-a.pem --key-id reviewer-a-2026 --out receipt.json`. + +The key must resolve outside the vault. Location checks guard against mistakes and are not a security boundary. Key generation uses exclusive creation +and mode 0600 where supported. On Windows mode bits are not applied; restrict the key file ACL to the key holder. Configure OS permissions separately. Never expose +the key or signing environment holding it to a model, agent, MCP server, or vault automation. The digest +prompt requires interactive stdin; it does not prove human attention. Review data +and diagnostics go to stderr. Receipt JSON goes to stdout or the requested new +output file. Transfer only that receipt to the vault's indicated authorization path. + +Exports are `parsePage`, `validatePage`, `canonicalBytes`, `digest`, +`unsignedReceipt`, `signingPayload`, and `signPage`. `signPage` takes an Ed25519 +private KeyObject as its last argument. These exports never prompt or write files. +The example does not import the Ziggurat runtime. Build and read verification +remain the authority on admission, including every other Gold eligibility rule. + +The async runSign(options, io) and runKeygen(options, io) exports take stdout and +stderr callbacks and an async confirm(prompt) callback. The CLI supplies the TTY +prompt; signPage remains pure. The display shows every signed field and defaults, +then target path, key ID, full digest and numbered body. diff --git a/examples/external-signer/package-lock.json b/examples/external-signer/package-lock.json new file mode 100644 index 0000000..4bbdc53 --- /dev/null +++ b/examples/external-signer/package-lock.json @@ -0,0 +1,31 @@ +{ + "name": "ziggurat-reference-external-signer", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "ziggurat-reference-external-signer", + "dependencies": { + "yaml": "2.9.0" + }, + "engines": { + "node": ">=22" + } + }, + "node_modules/yaml": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.9.0.tgz", + "integrity": "sha512-2AvhNX3mb8zd6Zy7INTtSpl1F15HW6Wnqj0srWlkKLcpYl/gMIMJiyuGq2KeI2YFxUPjdlB+3Lc10seMLtL4cA==", + "license": "ISC", + "bin": { + "yaml": "bin.mjs" + }, + "engines": { + "node": ">= 14.6" + }, + "funding": { + "url": "https://github.com/sponsors/eemeli" + } + } + } +} diff --git a/examples/external-signer/package.json b/examples/external-signer/package.json new file mode 100644 index 0000000..ff3b0bd --- /dev/null +++ b/examples/external-signer/package.json @@ -0,0 +1 @@ +{"name":"ziggurat-reference-external-signer","private":true,"type":"module","engines":{"node":">=22"},"dependencies":{"yaml":"2.9.0"}} diff --git a/examples/external-signer/signer.mjs b/examples/external-signer/signer.mjs new file mode 100644 index 0000000..3c39388 --- /dev/null +++ b/examples/external-signer/signer.mjs @@ -0,0 +1,441 @@ +import { + createHash, + generateKeyPairSync, + createPrivateKey, + sign as cryptoSign, +} from 'node:crypto'; +import { readFile, writeFile, realpath, stat } from 'node:fs/promises'; +import { + resolve, + dirname, + basename, + relative, + isAbsolute, + sep, +} from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { createInterface } from 'node:readline/promises'; +import { parse as parseYaml, stringify } from 'yaml'; + +const fields = [ + 'schema_version', + 'title', + 'type', + 'sources', + 'confidence', + 'status', + 'retrieval_eligible', + 'pii', + 'sensitivity', + 'visibility', + 'egress', + 'reviewed_by', + 'reviewed_at', + 'last_verified', + 'review_after', + 'resolved_proposals', +]; +function requireValue(ok, message) { + if (!ok) throw new Error(message); +} +function timestamp(value) { + const match = + /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.\d+)?Z$/.exec( + value, + ); + if (!match) return false; + const [year, month, day, hour, minute, second] = match.slice(1).map(Number); + const date = new Date(0); + date.setUTCFullYear(year, month - 1, day); + date.setUTCHours(hour, minute, second, 0); + return ( + date.getUTCFullYear() === year && + date.getUTCMonth() === month - 1 && + date.getUTCDate() === day && + date.getUTCHours() === hour && + date.getUTCMinutes() === minute && + date.getUTCSeconds() === second + ); +} +export function validatePage(input) { + requireValue( + input && typeof input === 'object' && !Array.isArray(input), + 'frontmatter must be an object', + ); + requireValue( + Object.keys(input).every((field) => fields.includes(field)), + 'unknown frontmatter field', + ); + const page = { ...input }; + if (page.egress === undefined) page.egress = 'local-only'; + requireValue(page.schema_version === 1, 'schema_version must be 1'); + for (const field of ['title', 'type', 'visibility']) + requireValue( + typeof page[field] === 'string' && page[field].length > 0, + `invalid ${field}`, + ); + requireValue( + Array.isArray(page.sources) && + page.sources.every((value) => typeof value === 'string'), + 'invalid sources', + ); + for (const [field, values] of Object.entries({ + confidence: ['high', 'medium', 'low'], + status: ['draft', 'in-review', 'reviewed'], + pii: ['true', 'false', 'unknown'], + sensitivity: ['public', 'internal', 'restricted'], + egress: ['local-only', 'approved-cloud'], + })) + requireValue(values.includes(page[field]), `invalid ${field}`); + requireValue( + typeof page.retrieval_eligible === 'boolean', + 'invalid retrieval_eligible', + ); + if (page.reviewed_by !== undefined) + requireValue(typeof page.reviewed_by === 'string', 'invalid reviewed_by'); + for (const field of ['reviewed_at', 'last_verified', 'review_after']) + if (page[field] !== undefined) + requireValue( + typeof page[field] === 'string' && timestamp(page[field]), + `invalid ${field}`, + ); + if (page.resolved_proposals !== undefined) + requireValue( + Array.isArray(page.resolved_proposals) && + page.resolved_proposals.every( + (value) => + typeof value === 'string' && + /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/.test( + value, + ), + ), + 'invalid resolved_proposals', + ); + if (page.status === 'reviewed') + requireValue( + page.sources.length && + page.reviewed_by?.length && + page.reviewed_at && + page.last_verified, + 'reviewed pages require sources and review and verification metadata', + ); + return page; +} +export function parsePage(raw) { + const text = raw.replace(/\r\n/g, '\n'); + const close = text.startsWith('---\n') ? text.indexOf('\n---\n', 4) : -1; + requireValue(close !== -1, 'missing closed frontmatter'); + // Default YAML 1.2 options match the vault parser. Timestamps remain strings. + let parsed; + try { + parsed = parseYaml(text.slice(4, close)); + } catch (error) { + const start = error?.linePos?.[0]; + const location = + Number.isInteger(start?.line) && Number.isInteger(start?.col) + ? ' at line ' + start.line + ', column ' + start.col + : ''; + throw new Error('frontmatter is not valid YAML' + location); + } + return { page: validatePage(parsed), body: text.slice(close + 5) }; +} +function target(path) { + requireValue( + /^knowledge\/[a-z0-9][a-z0-9._-]*\.md$/.test(path), + 'invalid target path', + ); + const name = path.slice(10, -3); + requireValue( + !name.endsWith('.') && + !/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/.test(name.split('.')[0]), + 'invalid target filename', + ); +} +export function canonicalBytes(path, input, body) { + target(path); + const validated = validatePage(input); + const page = Object.fromEntries( + fields.map((field) => [ + field, + validated[field] ?? (field === 'resolved_proposals' ? [] : null), + ]), + ); + return Buffer.from( + JSON.stringify({ + domain: 'ziggurat-curated-page-v1', + target_path: path, + page, + body: body.replace(/\r\n?/g, '\n'), + }), + 'utf8', + ); +} +export function digest(path, page, body) { + return createHash('sha256') + .update(canonicalBytes(path, page, body)) + .digest('hex'); +} +export function unsignedReceipt(path, page, body, keyId) { + requireValue( + typeof page.reviewed_by === 'string' && + page.reviewed_by.length && + page.reviewed_at, + 'reviewed_by and reviewed_at are required', + ); + requireValue(typeof keyId === 'string' && keyId.length, 'key ID is required'); + return { + schema_version: 1, + decision: 'admit', + target_path: path, + content_sha256: digest(path, page, body), + reviewer_id: page.reviewed_by, + reviewed_at: page.reviewed_at, + key_id: keyId, + algorithm: 'ed25519', + }; +} +export function signingPayload(receipt) { + return Buffer.from( + JSON.stringify({ + domain: 'ziggurat-authorization-receipt-v1', + schema_version: receipt.schema_version, + decision: receipt.decision, + target_path: receipt.target_path, + content_sha256: receipt.content_sha256, + reviewer_id: receipt.reviewer_id, + reviewed_at: receipt.reviewed_at, + key_id: receipt.key_id, + algorithm: receipt.algorithm, + }), + 'utf8', + ); +} +export function signPage(path, page, body, keyId, key) { + requireValue( + key.type === 'private' && key.asymmetricKeyType === 'ed25519', + 'Ed25519 private key required', + ); + const receipt = unsignedReceipt(path, page, body, keyId); + return { + ...receipt, + signature: cryptoSign(null, signingPayload(receipt), key).toString( + 'base64', + ), + }; +} +function inert(value) { + return value.replace( + /[\p{Cf}\p{Default_Ignorable_Code_Point}\x00-\x08\x0a-\x1f\x7f-\x9f\u00ad\u034f\u061c\u180e\u200b-\u200f\u2028-\u202e\u2060-\u206f\ufeff]/gu, + (character) => + '\\u{' + + character.codePointAt(0).toString(16).toUpperCase().padStart(4, '0') + + '}', + ); +} +function visibleJson(value) { + return JSON.stringify(value, (name, item) => + typeof item === 'string' ? inert(item) : item, + ).replaceAll('\\\\u{', '\\u{'); +} +function inside(root, file) { + const rel = relative(root, file); + return !isAbsolute(rel) && rel !== '..' && !rel.startsWith('..' + sep); +} +async function looksLikeVault(root) { + try { + return ( + (await stat(resolve(root, 'config/trust.yaml'))).isFile() && + (await stat(resolve(root, 'knowledge'))).isDirectory() + ); + } catch { + return false; + } +} +async function refuseVaultAncestors(keyPath) { + let directory = resolve(keyPath); + while (true) { + requireValue( + !(await looksLikeVault(directory)), + 'key path or ancestor looks like a vault; key must be outside the vault', + ); + const parent = dirname(directory); + if (parent === directory) break; + directory = parent; + } +} +async function checkKeyPath(keyPath) { + // Check addressed and resolved paths to catch accidental vault placement. + await refuseVaultAncestors(keyPath); + await refuseVaultAncestors( + resolve(await realpath(dirname(resolve(keyPath))), basename(keyPath)), + ); +} +export async function runKeygen(options, io) { + await checkKeyPath(options['private-key']); + const { privateKey, publicKey } = generateKeyPairSync('ed25519'); + await writeFile( + options['private-key'], + privateKey.export({ type: 'pkcs8', format: 'pem' }), + { flag: 'wx', mode: 0o600 }, + ); + io.stdout( + stringify({ + trust: { + reviewers: [ + { + reviewer_id: options['reviewer-id'], + key_id: options['key-id'], + algorithm: 'ed25519', + public_key_pem: publicKey.export({ type: 'spki', format: 'pem' }), + }, + ], + }, + }), + ); +} +function displayPage(path, page, body, keyId, receipt, io) { + // Show the canonical object, including all defaults, before confirmation. + const canonical = JSON.parse( + canonicalBytes(path, page, body).toString('utf8'), + ); + for (const [name, value] of Object.entries(canonical.page)) { + io.stderr(name + ': ' + visibleJson(value) + '\n'); + } + io.stderr( + 'target_path: ' + + inert(path) + + '\nkey_id: ' + + inert(keyId) + + '\ncanonical_digest: ' + + receipt.content_sha256 + + '\n', + ); + canonical.body + .split('\n') + .forEach((line, index) => io.stderr(index + 1 + ': ' + inert(line) + '\n')); + for (const [bad, message] of [ + [page.status !== 'reviewed', 'status is not reviewed'], + [!page.retrieval_eligible, 'retrieval_eligible is false'], + [page.egress === 'local-only', 'egress is local-only'], + [page.pii !== 'false', 'pii is not false'], + [page.sensitivity === 'restricted', 'sensitivity is restricted'], + ]) { + if (bad) io.stderr('Warning: Gold will reject: ' + message + '\n'); + } +} +export async function runSign(options, io) { + requireValue(options.vault, '--vault required'); + const root = await realpath(options.vault); + requireValue( + await looksLikeVault(root), + 'vault requires config/trust.yaml and knowledge/', + ); + const knowledge = await realpath(resolve(root, 'knowledge')); + // These checks prevent mistakes; they do not isolate the signing environment. + requireValue(inside(root, knowledge), 'knowledge resolves outside the vault'); + const pageFile = await realpath(options.page); + requireValue( + dirname(pageFile) === knowledge, + 'page must be directly under vault knowledge/', + ); + await refuseVaultAncestors(options['private-key']); + const keyFile = await realpath(options['private-key']); + requireValue( + !inside(root, keyFile), + 'private key resolves inside the vault; keep it outside', + ); + await refuseVaultAncestors(keyFile); + requireValue( + (await stat(keyFile)).nlink <= 1, + 'private key has multiple hard links', + ); + const path = 'knowledge/' + basename(pageFile); + // One snapshot supplies both the display and signature. + const { page, body } = parsePage(await readFile(pageFile, 'utf8')); + const receipt = unsignedReceipt(path, page, body, options['key-id']); + displayPage(path, page, body, options['key-id'], receipt, io); + const answer = await io.confirm( + 'Type ' + receipt.content_sha256.slice(0, 12) + ' to sign: ', + ); + requireValue( + typeof answer === 'string' && answer.length > 0, + 'confirmation ended without an answer', + ); + requireValue( + answer === receipt.content_sha256.slice(0, 12), + 'digest confirmation did not match', + ); + // Read key bytes only after confirmation; output only the receipt. + const key = createPrivateKey(await readFile(keyFile)); + const output = + JSON.stringify( + signPage(path, page, body, options['key-id'], key), + null, + 2, + ) + '\n'; + if (options.out) await writeFile(options.out, output, { flag: 'wx' }); + else io.stdout(output); + io.stderr( + 'Receipt belongs at authorizations/' + + basename(pageFile) + + '.authorization.json\n', + ); +} +async function confirm(prompt) { + requireValue( + process.stdin.isTTY, + 'an interactive terminal is required; this is a speed bump, not proof of review', + ); + const rl = createInterface({ input: process.stdin, output: process.stderr }); + try { + return await Promise.race([ + rl.question(prompt), + new Promise((resolveAnswer) => + rl.once('close', () => resolveAnswer(undefined)), + ), + ]); + } finally { + rl.close(); + } +} +async function main() { + const [command, ...args] = process.argv.slice(2); + const options = {}; + const allowed = + command === 'keygen' + ? ['private-key', 'reviewer-id', 'key-id'] + : command === 'sign' + ? ['vault', 'page', 'private-key', 'key-id', 'out'] + : []; + requireValue(allowed.length, 'expected keygen or sign'); + for (let index = 0; index < args.length; index += 2) { + const name = args[index].slice(2); + requireValue( + args[index].startsWith('--') && + allowed.includes(name) && + args[index + 1] && + !options[name], + 'invalid or duplicate option', + ); + options[name] = args[index + 1]; + } + for (const name of allowed.filter((name) => name !== 'out')) { + requireValue(options[name], '--' + name + ' required'); + } + const io = { + stdout: (text) => process.stdout.write(text), + stderr: (text) => process.stderr.write(text), + confirm, + }; + if (command === 'keygen') await runKeygen(options, io); + else await runSign(options, io); +} +if ( + process.argv[1] && + resolve(process.argv[1]) === fileURLToPath(import.meta.url) +) { + main().catch((error) => { + process.stderr.write(inert(error.message) + '\n'); + process.exitCode = 1; + }); +} diff --git a/site/astro.config.mjs b/site/astro.config.mjs index c9049f0..de43191 100644 --- a/site/astro.config.mjs +++ b/site/astro.config.mjs @@ -65,6 +65,8 @@ export default defineConfig({ items: [ { slug: 'guides/ingest-and-refine' }, { slug: 'guides/human-review-and-authorization' }, + { slug: 'guides/external-signing' }, + { slug: 'guides/agents-and-models' }, { slug: 'guides/mcp-gold' }, { slug: 'guides/integrity-and-recovery' }, ], diff --git a/site/src/components/AdmissionFigure.astro b/site/src/components/AdmissionFigure.astro index c3c2932..22fe418 100644 --- a/site/src/components/AdmissionFigure.astro +++ b/site/src/components/AdmissionFigure.astro @@ -24,7 +24,7 @@ const stages = [ ))}
Gold MCP Read-only reference data
-Figure 1. The review hand-off is external. No shipped path signs or approves a page.
+Figure 1. The review hand-off is external. The Ziggurat runtime (CLI, MCP server and src/) has no signing or approval command.