{"record":{"id":"c8ceaf0eed09a3d9","repo":"JuliusBrussee/caveman","slug":"label-key-is-required","errorCode":null,"errorMessage":"${label} key is required","messagePattern":"(.+?) key is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":17850,"sourceCode":"  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> } {\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)}`);","sourceCodeStart":17832,"sourceCodeEnd":17868,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L17832-L17868","documentation":"Thrown by decodeReceiptKey when the ReceiptPublicKey's key field is missing, not a string, or an empty/whitespace-only string. Without the base64 key material, the verifier cannot construct a KeyObject and verify receipt signatures.","triggerScenarios":"Verifying a bundle whose public key entry omits the key field or sets it to \"\", null, or a non-string value — e.g. hand-edited JSON or a bundle produced with key material stripped.","commonSituations":"Redacting keys before sharing a bundle and accidentally removing the key field entirely; JSON template placeholders like \"<key>\" replaced with empty string; a truncated export.","solutions":["Provide the base64-encoded 32-byte Ed25519 public key in the key field.","Regenerate the bundle with the official export command.","Validate bundle JSON against the receipt bundle schema before verification."],"exampleFix":"// before\n{\"key_id\": \"k1\", \"alg\": \"Ed25519\", \"key\": \"\"}\n// after\n{\"key_id\": \"k1\", \"alg\": \"Ed25519\", \"key\": \"MCowBQYDK2VwAyEA...\"}","handlingStrategy":"validation","validationCode":"if (typeof info.key !== 'string' || !info.key.trim()) throw new Error('key material required');","typeGuard":"function hasKeyMaterial(info: unknown): info is { key: string } {\n  return typeof info === 'object' && info !== null && typeof (info as any).key === 'string' && (info as any).key.trim() !== '';\n}","tryCatchPattern":"try {\n  verifyBundle(bundle);\n} catch (e) {\n  if ((e as Error).message.includes('key is required')) console.error('bundle key entry has no key material');\n  throw e;\n}","preventionTips":["Validate bundles against the schema before sharing/verifying.","Never redact by deleting fields; use a tool that preserves structure.","Check exported JSON contains no empty-string placeholders."],"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"}