{"record":{"id":"679d6c85ae14d141","repo":"JuliusBrussee/caveman","slug":"label-key-id-is-required","errorCode":null,"errorMessage":"${label} key_id is required","messagePattern":"(.+?) key_id is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":17848,"sourceCode":"  const sorted = [...receipts].sort((a, b) => a.seq - b.seq);\n  let prev: Receipt | undefined;\n  for (const r of sorted) {\n    const decoded = keys.get(r.signature?.key_id);\n    if (!decoded) return `seq ${r.seq}: no trusted public key for key_id ${String(r.signature?.key_id)}`;\n    const err = verifyReceipt(r, decoded.key, decoded.info.key_id);\n    if (err) return err;\n    if (prev) {\n      if (r.seq !== prev.seq + 1) return `seq ${r.seq}: not strictly after ${prev.seq}`;\n      if (r.prev_receipt_hash !== prev.receipt_hash) return `seq ${r.seq}: prev_receipt_hash does not link to seq ${prev.seq}`;\n      if (r.day <= prev.day) return `seq ${r.seq}: day ${r.day} does not follow ${prev.day}`;\n    }\n    prev = r;\n  }\n  return null;\n}\n\nfunction decodeReceiptKey(info: ReceiptPublicKey, label: string): DecodedReceiptKey {\n  if (!info || typeof info.key_id !== \"string\" || !info.key_id.trim()) throw new Error(`${label} key_id is required`);\n  if (info.alg !== \"Ed25519\") throw new Error(`${label} has unsupported algorithm ${String(info.alg)}`);\n  if (typeof info.key !== \"string\" || !info.key.trim()) throw new Error(`${label} key is required`);\n  const raw = Buffer.from(info.key, \"base64\");\n  if (raw.length !== 32 || raw.toString(\"base64\") !== info.key) throw new Error(`${label} must be a canonical base64 Ed25519 public key`);\n  return { info, raw, key: ed25519PublicKey(raw) };\n}\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> } {","sourceCodeStart":17830,"sourceCodeEnd":17866,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L17830-L17866","documentation":"Thrown by decodeReceiptKey while validating a receipt public key entry under a label such as 'public_key' or 'public_keys[0]'. The key_id field is either missing, not a string, or an empty/whitespace-only string. key_id identifies which key in the keyring signed a receipt, so a bundle without it cannot be verified.","triggerScenarios":"Verifying a receipt bundle whose ReceiptPublicKey object lacks key_id, contains key_id: \"\" or \"  \", or where key_id is a non-string (number/null) — typically from hand-constructed JSON or a bundle produced by an incompatible exporter.","commonSituations":"Hand-writing bundle JSON for testing and omitting key_id; a schema change in the producing tool dropped the field; copy/paste losing the key_id line; deserializing an older bundle format.","solutions":["Add a non-empty string key_id to the public key entry in the bundle.","Regenerate the bundle with the official export command so all key metadata is included.","If the bundle is from another tool, check its schema/version and upgrade the exporter."],"exampleFix":"// before\n{\"public_key\": {\"alg\": \"Ed25519\", \"key\": \"...\"}}\n// after\n{\"public_key\": {\"key_id\": \"2026-q3\", \"alg\": \"Ed25519\", \"key\": \"...\"}}","handlingStrategy":"validation","validationCode":"function validateKeyInfo(info: any) {\n  if (!info || typeof info.key_id !== 'string' || !info.key_id.trim()) throw new Error('key_id required');\n}","typeGuard":"function hasKeyId(info: unknown): info is { key_id: string } {\n  return typeof info === 'object' && info !== null && typeof (info as any).key_id === 'string' && (info as any).key_id.trim() !== '';\n}","tryCatchPattern":"try {\n  verifyBundle(bundle);\n} catch (e) {\n  if ((e as Error).message.includes('key_id is required')) console.error('bundle key entry missing key_id');\n  throw e;\n}","preventionTips":["Validate bundle JSON against the receipt schema before verification.","Never hand-strip fields when redacting bundles; use the official redaction tool.","Always generate bundles via the official export command."],"tags":["validation","crypto","schema"],"backgroundTag":"empty-required-field","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}