{"record":{"id":"1e7189238849e97e","repo":"JuliusBrussee/caveman","slug":"v2-bundle-requires-public-keys","errorCode":null,"errorMessage":"v2 bundle requires public_keys","messagePattern":"v2 bundle requires public_keys","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":17416,"sourceCode":"}\n\nfunction decodeUniqueKeyring(infos: ReceiptPublicKey[], label: string): Map<string, DecodedReceiptKey> {\n  const keys = new Map<string, DecodedReceiptKey>();\n  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] : [];","sourceCodeStart":17398,"sourceCodeEnd":17434,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/5184b3d11ac6a1acb7d44b9bfaa31698157cff97/packages/cli/src/index.ts#L17398-L17434","documentation":"Schema \"caveman.receipt-bundle.v2\" requires a non-empty public_keys array (the rotation keyring). A v2 bundle with public_keys absent, not an array, or an empty array is rejected before any key is decoded.","triggerScenarios":"A producer emits a v1-shaped bundle (only the top-level public_key) but labels it schema v2; or the keyring was emptied during editing before export.","commonSituations":"Bumping the schema string to v2 without updating export code to emit the keyring; hand-editing the schema field; test fixtures copied from v1 bundles.","solutions":["Include a non-empty public_keys array containing at least the current signing key","Or export as schema \"caveman.receipt-bundle.v1\" if you have a single key and no rotation keyring","Regenerate with the current producer version so v2 exports always carry the keyring"],"exampleFix":"// before\n{ \"schema\": \"caveman.receipt-bundle.v2\", \"public_key\": {...} }\n\n// after\n{ \"schema\": \"caveman.receipt-bundle.v2\", \"public_key\": {...}, \"public_keys\": [ {...current key...} ] }","handlingStrategy":"validation","validationCode":"if (bundle.schema === \"caveman.receipt-bundle.v2\") {\n  if (!Array.isArray(bundle.public_keys) || bundle.public_keys.length === 0) {\n    throw new Error(\"v2 bundle needs a non-empty public_keys keyring\");\n  }\n}","typeGuard":"function isCompleteV2Bundle(b: { schema?: unknown; public_keys?: unknown }): boolean {\n  return b.schema !== \"caveman.receipt-bundle.v2\" || (Array.isArray(b.public_keys) && b.public_keys.length > 0);\n}","tryCatchPattern":"try { execSync(`caveman receipts verify ${bundle}`); }\ncatch (e) {\n  if (/v2 bundle requires public_keys/.test(String((e as Error).message))) fail(\"re-export: v2 needs the keyring\");\n  throw e;\n}","preventionTips":["When bumping schema to v2, update the exporter to emit public_keys in the same change","Validate v2 exports in producer tests: keyring present and non-empty","Use v1 only when you genuinely have a single non-rotating key"],"tags":["receipts","keyring","schema-v2","validation"],"backgroundTag":"missing-required-argument","analyzedSha":"5184b3d11ac6a1acb7d44b9bfaa31698157cff97","analyzedAt":"2026-08-18T03:14:35.516Z","contentChangedAt":"2026-08-18T03:14:35.516Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}