JuliusBrussee/caveman · error

--pubkey JSON must contain public_key or public_keys

Error message

--pubkey JSON must contain public_key or public_keys

What it means

A JSON --pubkey file must contain at least one trusted key under `public_keys` (array) or `public_key` (single object). If neither field yields any keys, there is nothing to pin, so the CLI rejects the file.

Solutions

  1. Add `public_key` or a non-empty `public_keys` array to the JSON file
  2. Export the keyring again with the publisher tooling
  3. Pin the raw single key string instead of a JSON file

Example fix

// before
{"note":"rotation keys TBU"}
// after
{"public_key":{"key_id":"k1","key":"AAA"}}
Defensive patterns

Strategy: type-guard

Validate before calling

const j = JSON.parse(src);
if (!(Array.isArray(j.public_keys) && j.public_keys.length > 0) && !j.public_key) throw new Error('no pinned keys');

Type guard

const hasPinnedKeys = (v: unknown): v is { public_key?: ReceiptPublicKey; public_keys?: ReceiptPublicKey[] } =>
  typeof v === 'object' && v !== null &&
  (Array.isArray((v as any).public_keys) && (v as any).public_keys.length > 0 || (v as any).public_key != null);

Try / catch

try { await verify(argv) } catch (e) { if (e.message.includes('--pubkey JSON must contain')) { console.error('Keyring file has no key fields; re-export it'); process.exit(1); } throw e }

Prevention

When it happens

Trigger: `caveman receipts verify bundle.json --pubkey keys.json` where keys.json is valid JSON like `{}`, `{"other":...}`, or `public_keys: []` with no `public_key`.

Common situations: Exporting the wrong metadata file as a keyring, a publisher publishing a placeholder JSON, or deleting the key fields during sanitization.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/a2bbfb1856bfa431. Report an issue: GitHub.

Appendix: source

Thrown at packages/cli/src/index.ts:17891

  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"); }
  const infos = Array.isArray(parsed.public_keys) ? parsed.public_keys : parsed.public_key ? [parsed.public_key] : [];
  if (infos.length === 0) throw new Error("--pubkey JSON must contain public_key or public_keys");
  const keys = decodeUniqueKeyring(infos, "--pubkey public_keys");
  const pinnedCurrent = keys.get(current.info.key_id);
  if (!pinnedCurrent || !pinnedCurrent.raw.equals(current.raw)) throw new Error("trusted --pubkey keyring does not contain the bundle public key");
  return { keys, trust: "pinned_keyring" };
}

// receiptsVerify validates a signed receipt bundle offline (no network). A raw
// --pubkey pins the current key; JSON may independently pin a full rotation
// keyring. Without either, embedded keys prove self-consistency, not publisher
// authenticity. Exits non-zero on any included content, signature, or
// scope-chain break. Tail/scope omission needs separately trusted head manifest;
// bundle output states completeness is not attested.
//   caveman receipts verify <bundle.json> [--pubkey <file>]
async function receiptsVerify(argv: string[]) {
  const file = positionalAfterOptions(argv.slice(1), new Set(["--pubkey"]));
  if (!file) throw new Error(`usage: ${invokedCommand("receipts")} verify <bundle.json> [--pubkey <file>]`);
  let bundle: ReceiptBundle;
  try { bundle = JSON.parse(await readFile(file, "utf8")) as ReceiptBundle; } catch (e) { return fail(`invalid bundle JSON: ${(e as Error).message}`); }

View on GitHub (pinned to 3ee70a1026)