{"record":{"id":"80448eed77627972","repo":"JuliusBrussee/caveman","slug":"v2-public-keys-must-include-public-key","errorCode":null,"errorMessage":"v2 public_keys must include public_key","messagePattern":"v2 public_keys must include public_key","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":17420,"sourceCode":"  for (const [index, info] of infos.entries()) {\n    const decoded = decodeReceiptKey(info, `${label}[${index}]`);\n    if (keys.has(decoded.info.key_id)) throw new Error(`${label} contains duplicate key_id ${decoded.info.key_id}`);\n    keys.set(decoded.info.key_id, decoded);\n  }\n  return keys;\n}\n\nfunction embeddedReceiptKeys(bundle: ReceiptBundle): { current: DecodedReceiptKey; keys: Map<string, DecodedReceiptKey> } {\n  if (bundle.schema !== RECEIPT_BUNDLE_V1 && bundle.schema !== RECEIPT_BUNDLE_V2) throw new Error(`unsupported bundle schema ${String(bundle.schema)}`);\n  if (bundle.verification_coverage !== undefined && bundle.verification_coverage !== INCLUDED_RECEIPTS_ONLY) throw new Error(`unsupported unsigned verification coverage ${String(bundle.verification_coverage)}`);\n  if (bundle.completeness_attested === true) throw new Error(\"bundle completeness cannot be attested by unsigned export metadata\");\n  const current = decodeReceiptKey(bundle.public_key, \"public_key\");\n  if (bundle.public_keys !== undefined && !Array.isArray(bundle.public_keys)) throw new Error(\"public_keys must be an array\");\n  if (bundle.schema === RECEIPT_BUNDLE_V2 && (!Array.isArray(bundle.public_keys) || bundle.public_keys.length === 0)) throw new Error(\"v2 bundle requires public_keys\");\n  const keys = decodeUniqueKeyring(bundle.public_keys ?? [], \"public_keys\");\n  const currentInRing = keys.get(current.info.key_id);\n  if (currentInRing && !currentInRing.raw.equals(current.raw)) throw new Error(`public_key conflicts with public_keys entry ${current.info.key_id}`);\n  if (bundle.schema === RECEIPT_BUNDLE_V2 && !currentInRing) throw new Error(\"v2 public_keys must include public_key\");\n  if (!currentInRing) keys.set(current.info.key_id, current);\n  return { current, keys };\n}\n\nasync function pinnedReceiptKeys(file: string, current: DecodedReceiptKey): Promise<{ keys: Map<string, DecodedReceiptKey>; trust: string }> {\n  const source = (await readFile(file, \"utf8\")).trim();\n  if (!source.startsWith(\"{\")) {\n    const pinned = decodeReceiptKey({ ...current.info, key: source }, \"--pubkey\");\n    if (!pinned.raw.equals(current.raw)) throw new Error(\"bundle public key does not match the published --pubkey\");\n    return { keys: new Map([[current.info.key_id, pinned]]), trust: \"pinned_public_key\" };\n  }\n  let parsed: { public_key?: ReceiptPublicKey; public_keys?: ReceiptPublicKey[] };\n  try { parsed = JSON.parse(source); } catch { throw new Error(\"--pubkey JSON is malformed\"); }\n  const infos = Array.isArray(parsed.public_keys) ? parsed.public_keys : parsed.public_key ? [parsed.public_key] : [];\n  if (infos.length === 0) throw new Error(\"--pubkey JSON must contain public_key or public_keys\");\n  const keys = decodeUniqueKeyring(infos, \"--pubkey public_keys\");\n  const pinnedCurrent = keys.get(current.info.key_id);\n  if (!pinnedCurrent || !pinnedCurrent.raw.equals(current.raw)) throw new Error(\"trusted --pubkey keyring does not contain the bundle public key\");","sourceCodeStart":17402,"sourceCodeEnd":17438,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/5184b3d11ac6a1acb7d44b9bfaa31698157cff97/packages/cli/src/index.ts#L17402-L17438","documentation":"In a v2 bundle the public_keys keyring is authoritative, so the top-level public_key (the current signing key) must appear inside it. If no public_keys entry has the current key's key_id, verification throws \"v2 public_keys must include public_key\".","triggerScenarios":"A v2 bundle where public_keys exists but was exported without the current signing key (e.g. only historical rotation keys), or the keyring was hand-pruned.","commonSituations":"Export filters the keyring to rotated-out keys; a producer bug lists only past keys; manual removal of the current key while trimming.","solutions":["Add the current signing key (same key_id and bytes as public_key) to public_keys and re-export","Regenerate the bundle with current producer code, which always includes the active key","Treat a v2 export missing its active key as producer output you should not trust"],"exampleFix":"// before\n\"public_keys\": [ { \"key_id\": \"k1\", ... } ]  // current key is k2\n\n// after\n\"public_keys\": [ { \"key_id\": \"k1\", ... }, { \"key_id\": \"k2\", ... } ]  // includes current key","handlingStrategy":"validation","validationCode":"if (bundle.schema === \"caveman.receipt-bundle.v2\") {\n  const included = (bundle.public_keys ?? []).some((k) => k.key_id === bundle.public_key.key_id);\n  if (!included) throw new Error(\"v2 keyring must contain the current signing key\");\n}","typeGuard":"function v2KeyringCoversCurrentKey(b: { schema?: unknown; public_key?: { key_id?: unknown }; public_keys?: { key_id?: unknown }[] }): boolean {\n  if (b.schema !== \"caveman.receipt-bundle.v2\") return true;\n  return (b.public_keys ?? []).some((k) => k?.key_id === b.public_key?.key_id);\n}","tryCatchPattern":"try { execSync(`caveman receipts verify ${bundle}`); }\ncatch (e) {\n  if (/v2 public_keys must include public_key/.test(String((e as Error).message))) fail(\"producer bug: active key missing from keyring\");\n  throw e;\n}","preventionTips":["Make export always append the active key to the keyring","Never prune the current key when trimming keyrings","Test v2 exports with a rotation history so omission is caught early"],"tags":["receipts","keyring","schema-v2","validation"],"backgroundTag":"keyring-missing-current-key","analyzedSha":"5184b3d11ac6a1acb7d44b9bfaa31698157cff97","analyzedAt":"2026-08-18T03:14:35.516Z","contentChangedAt":"2026-08-18T03:14:35.516Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}