JuliusBrussee/caveman · error
public_keys must be an array
Error message
public_keys must be an array
What it means
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".
Source
Thrown at packages/cli/src/index.ts:17415
return { info, raw, key: ed25519PublicKey(raw) };
}
function decodeUniqueKeyring(infos: ReceiptPublicKey[], label: string): Map<string, DecodedReceiptKey> {
const keys = new Map<string, DecodedReceiptKey>();
for (const [index, info] of infos.entries()) {
const decoded = decodeReceiptKey(info, `${label}[${index}]`);
if (keys.has(decoded.info.key_id)) throw new Error(`${label} contains duplicate key_id ${decoded.info.key_id}`);
keys.set(decoded.info.key_id, decoded);
}
return keys;
}
function embeddedReceiptKeys(bundle: ReceiptBundle): { current: DecodedReceiptKey; keys: Map<string, DecodedReceiptKey> } {
if (bundle.schema !== RECEIPT_BUNDLE_V1 && bundle.schema !== RECEIPT_BUNDLE_V2) throw new Error(`unsupported bundle schema ${String(bundle.schema)}`);
if (bundle.verification_coverage !== undefined && bundle.verification_coverage !== INCLUDED_RECEIPTS_ONLY) throw new Error(`unsupported unsigned verification coverage ${String(bundle.verification_coverage)}`);
if (bundle.completeness_attested === true) throw new Error("bundle completeness cannot be attested by unsigned export metadata");
const current = decodeReceiptKey(bundle.public_key, "public_key");
if (bundle.public_keys !== undefined && !Array.isArray(bundle.public_keys)) throw new Error("public_keys must be an array");
if (bundle.schema === RECEIPT_BUNDLE_V2 && (!Array.isArray(bundle.public_keys) || bundle.public_keys.length === 0)) throw new Error("v2 bundle requires public_keys");
const keys = decodeUniqueKeyring(bundle.public_keys ?? [], "public_keys");
const currentInRing = keys.get(current.info.key_id);
if (currentInRing && !currentInRing.raw.equals(current.raw)) throw new Error(`public_key conflicts with public_keys entry ${current.info.key_id}`);
if (bundle.schema === RECEIPT_BUNDLE_V2 && !currentInRing) throw new Error("v2 public_keys must include public_key");
if (!currentInRing) keys.set(current.info.key_id, current);
return { current, keys };
}
async function pinnedReceiptKeys(file: string, current: DecodedReceiptKey): Promise<{ keys: Map<string, DecodedReceiptKey>; trust: string }> {
const source = (await readFile(file, "utf8")).trim();
if (!source.startsWith("{")) {
const pinned = decodeReceiptKey({ ...current.info, key: source }, "--pubkey");
if (!pinned.raw.equals(current.raw)) throw new Error("bundle public key does not match the published --pubkey");
return { keys: new Map([[current.info.key_id, pinned]]), trust: "pinned_public_key" };
}
let parsed: { public_key?: ReceiptPublicKey; public_keys?: ReceiptPublicKey[] };
try { parsed = JSON.parse(source); } catch { throw new Error("--pubkey JSON is malformed"); }View on GitHub (pinned to 5184b3d11a)
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
Example fix
// before
"public_keys": { "k1": { "alg": "Ed25519", "key": "AAA..." } }
// after
"public_keys": [ { "key_id": "k1", "alg": "Ed25519", "key": "AAA..." } ] Defensive patterns
Strategy: type-guard
Validate before calling
if (bundle.public_keys !== undefined && !Array.isArray(bundle.public_keys)) {
throw new Error("public_keys must be an array of key objects");
} Type guard
function isKeyringArray(v: unknown): v is { key_id: string; alg: string; key: string }[] {
return Array.isArray(v) && v.every((k) =>
!!k && typeof k === "object" && typeof (k as any).key_id === "string" && typeof (k as any).key === "string");
} Try / catch
try { execSync(`caveman receipts verify ${bundle}`); }
catch (e) {
if (/public_keys must be an array/.test(String((e as Error).message))) fail("bundle keyring is not a JSON array");
throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: A custom serializer emits maps instead of lists; hand-merged JSON reshapes the array into an object; converting between YAML anchor styles and JSON.
Related errors
- ${label} key_id is required
- ${label} key is required
- ${label} contains duplicate key_id ${decoded.info.key_id}
- v2 bundle requires public_keys
- v2 public_keys must include public_key
AI-assisted analysis of JuliusBrussee/caveman@5184b3d11a (2026-08-18).
Data as JSON: /api/errors/c05d8b15c253a967.
Report an issue: GitHub.