{"record":{"id":"c05d8b15c253a967","repo":"JuliusBrussee/caveman","slug":"public-keys-must-be-an-array","errorCode":null,"errorMessage":"public_keys must be an array","messagePattern":"public_keys must be an array","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":17415,"sourceCode":"  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)}`);\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\"); }","sourceCodeStart":17397,"sourceCodeEnd":17433,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/5184b3d11ac6a1acb7d44b9bfaa31698157cff97/packages/cli/src/index.ts#L17397-L17433","documentation":"When public_keys is present on a bundle it must be an array of key objects. decodeUniqueKeyring iterates it with .entries(), so an object, string, or number throws immediately with \"public_keys must be an array\".","triggerScenarios":"bundle.public_keys is a dictionary keyed by key_id (e.g. {\"k1\": {...}}), a comma-separated string, or null-ish non-array, and the bundle reaches embeddedReceiptKeys.","commonSituations":"A custom serializer emits maps instead of lists; hand-merged JSON reshapes the array into an object; converting between YAML anchor styles and JSON.","solutions":["Make public_keys an array of {key_id, alg, key} objects","Regenerate the bundle with the official export command rather than transforming it by hand","Validate the shape with Array.isArray before verifying"],"exampleFix":"// before\n\"public_keys\": { \"k1\": { \"alg\": \"Ed25519\", \"key\": \"AAA...\" } }\n\n// after\n\"public_keys\": [ { \"key_id\": \"k1\", \"alg\": \"Ed25519\", \"key\": \"AAA...\" } ]","handlingStrategy":"type-guard","validationCode":"if (bundle.public_keys !== undefined && !Array.isArray(bundle.public_keys)) {\n  throw new Error(\"public_keys must be an array of key objects\");\n}","typeGuard":"function isKeyringArray(v: unknown): v is { key_id: string; alg: string; key: string }[] {\n  return Array.isArray(v) && v.every((k) =>\n    !!k && typeof k === \"object\" && typeof (k as any).key_id === \"string\" && typeof (k as any).key === \"string\");\n}","tryCatchPattern":"try { execSync(`caveman receipts verify ${bundle}`); }\ncatch (e) {\n  if (/public_keys must be an array/.test(String((e as Error).message))) fail(\"bundle keyring is not a JSON array\");\n  throw e;\n}","preventionTips":["Never reshape public_keys into an object/dictionary when post-processing bundles","Run Array.isArray(bundle.public_keys) in pipeline preflight","Produce bundles with the official export command only"],"tags":["receipts","keyring","json-shape","validation"],"backgroundTag":"field-type-mismatch","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"}