@agledger/cli 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  The official CLI for the [AGLedger](https://agledger.ai) API: change control for AI agents. Agent memory, approvals, audit trail, and notifications: one API, one signed ledger, self-hosted.
4
4
 
5
+ Requires an AGLedger Server 2.0 or later. For a 1.x Server, use `npm i -g @agledger/cli@1.5.0`, the last release that supports it.
6
+
5
7
  A **thin cover** over the API. The CLI passes your request straight through to the API and forwards the response: no hand-coded per-endpoint wrappers, no flag-to-body translation, no drift. Every AGLedger API route is reachable via `agledger api <METHOD> <path>`.
6
8
 
7
9
  **Learn more**
@@ -94,7 +96,7 @@ agledger api POST /v1/records -F type=notarize-generic-v1 -F criteria.summary=x
94
96
  Reach for `-f` rather than quoting. Shell quotes that survive into the value
95
97
  (`-F externalTaskId='"4821"'`) reach the Server as a string with the quote
96
98
  characters inside it, and the Server accepts that: the Record is notarized,
97
- signed and immutable, with an identifier no other system will match.
99
+ signed and tamper-evident, with an identifier no other system will match.
98
100
 
99
101
  ## Verifying an export offline
100
102
 
@@ -154,9 +156,17 @@ with its operator before passing that entry. Findings and notes name the flags
154
156
  in human and `--json` output alike. `--keys <file>` supplies
155
157
  keys (a saved `GET /v1/verification-keys` response works as is, and its
156
158
  statements are walked too), `--require-supplied-keys` refuses the export's
157
- embedded keys, and `--agent-keys <file>` re-verifies the agent signatures an
158
- OIDC cert sealed on the chain. `--trust-anchor` and `--distrusted-key` are
159
- given once per key. A malformed value, a distrusted key named twice,
159
+ embedded keys, `--agent-keys <file>` re-verifies the agent signatures an
160
+ OIDC cert sealed on the chain, and `--federation-key <hubId>=<key>` re-verifies
161
+ the messages a federated peer signed and this Server sealed on its
162
+ `FEDERATION_*` entries (`payload.wire`), under the peer's federation key as its
163
+ operator gives it; a sealed message that does not hold fails
164
+ `CHAIN_FEDERATION_WIRE_INVALID`. After a peer changes its federation key,
165
+ `--federation-key-history <file>` (the JSON its
166
+ `GET /.well-known/agledger-federation-keys.json` serves) beside the
167
+ `--federation-key` for that hub trusts every key the history links to yours, so
168
+ the entries sealed before the change verify too. `--trust-anchor`, `--distrusted-key` and
169
+ `--federation-key` are given once per key. A malformed value, a distrusted key named twice,
160
170
  `--distrusted-key` without `--trust-anchor`, a pinned key distrusted with no
161
171
  instant (the Server refuses to start with that pair), and a
162
172
  file that does not exist are each a usage error (exit 2), refused before the
package/dist/base.d.ts CHANGED
@@ -110,6 +110,16 @@ export declare abstract class BaseCommand extends Command {
110
110
  };
111
111
  protected get isJson(): boolean;
112
112
  protected get isQuiet(): boolean;
113
+ /**
114
+ * oclif's own refusals (an unknown flag, a missing argument, a bad enum
115
+ * value) reach here before any command code runs. Under --quiet they exit
116
+ * as a usage error with nothing written, as every other error does; an
117
+ * explicit `this.exit(code)` passes through untouched, since it already
118
+ * carries the code the command chose.
119
+ */
120
+ protected catch(err: Error & {
121
+ exitCode?: number;
122
+ }): Promise<unknown>;
113
123
  /** Write one diagnostic line to stderr under --verbose. Callers pass no secrets. */
114
124
  protected verboseLog(flags: {
115
125
  verbose?: boolean;
@@ -201,6 +211,12 @@ export declare abstract class BaseCommand extends Command {
201
211
  /** Read and parse a JSON file with structured errors. `-` reads from stdin. */
202
212
  protected readJsonSource(path: string, fieldName: string, suggestion?: string): unknown;
203
213
  protected failWith(code: string, message: string, exitCode: number, suggestion?: string, extra?: Record<string, unknown>): never;
214
+ /**
215
+ * The one place a structured error leaves the process. Under --quiet it
216
+ * leaves nothing: the flag promises exit code only, and a caller that
217
+ * asked for that reads the code, not a body it told the CLI not to write.
218
+ */
219
+ private writeError;
204
220
  /**
205
221
  * Forward the full API error body to stderr verbatim. The API owns error
206
222
  * guidance (code, message, suggestion, validationErrors, nextSteps); the CLI
package/dist/base.js CHANGED
@@ -9,7 +9,7 @@
9
9
  * honors NO_COLOR via chalk's built-in detection, so no explicit check needed.
10
10
  */
11
11
  import { readFileSync } from 'node:fs';
12
- import { Command, Flags } from '@oclif/core';
12
+ import { Command, Errors, Flags } from '@oclif/core';
13
13
  import { ApiClient } from './api-client.js';
14
14
  import { DelegationToken, OIDC_ENV, ON_BEHALF_OF_ENV, OidcCertCredential, OidcExchangeError, OidcTokenSourceError, } from './oidc.js';
15
15
  import { readConfig } from './util/config.js';
@@ -185,6 +185,20 @@ export class BaseCommand extends Command {
185
185
  get isQuiet() {
186
186
  return process.argv.includes('--quiet');
187
187
  }
188
+ /**
189
+ * oclif's own refusals (an unknown flag, a missing argument, a bad enum
190
+ * value) reach here before any command code runs. Under --quiet they exit
191
+ * as a usage error with nothing written, as every other error does; an
192
+ * explicit `this.exit(code)` passes through untouched, since it already
193
+ * carries the code the command chose.
194
+ */
195
+ async catch(err) {
196
+ if (this.isQuiet && !(err instanceof Errors.ExitError)) {
197
+ const exit = err.oclif?.exit;
198
+ this.exit(typeof exit === 'number' ? exit : ExitCode.GENERAL_ERROR);
199
+ }
200
+ return super.catch(err);
201
+ }
188
202
  /** Write one diagnostic line to stderr under --verbose. Callers pass no secrets. */
189
203
  verboseLog(flags, event) {
190
204
  if (flags.verbose)
@@ -477,10 +491,20 @@ export class BaseCommand extends Command {
477
491
  error.suggestion = suggestion;
478
492
  if (extra)
479
493
  Object.assign(error, extra);
480
- process.stderr.write(JSON.stringify(error) + '\n');
494
+ this.writeError(error);
481
495
  this.exit(exitCode);
482
496
  throw new Error('unreachable');
483
497
  }
498
+ /**
499
+ * The one place a structured error leaves the process. Under --quiet it
500
+ * leaves nothing: the flag promises exit code only, and a caller that
501
+ * asked for that reads the code, not a body it told the CLI not to write.
502
+ */
503
+ writeError(error) {
504
+ if (this.isQuiet)
505
+ return;
506
+ process.stderr.write(JSON.stringify(error) + '\n');
507
+ }
484
508
  /**
485
509
  * Forward the full API error body to stderr verbatim. The API owns error
486
510
  * guidance (code, message, suggestion, validationErrors, nextSteps); the CLI
@@ -490,7 +514,7 @@ export class BaseCommand extends Command {
490
514
  const body = (response.body ?? {});
491
515
  const exitCode = this.statusToExitCode(response.status);
492
516
  const error = { error: true, ...body };
493
- process.stderr.write(JSON.stringify(error) + '\n');
517
+ this.writeError(error);
494
518
  this.exit(exitCode);
495
519
  throw new Error('unreachable');
496
520
  }
@@ -513,7 +537,7 @@ export class BaseCommand extends Command {
513
537
  source: err.origin,
514
538
  apiError: err.body,
515
539
  };
516
- process.stderr.write(JSON.stringify(error) + '\n');
540
+ this.writeError(error);
517
541
  this.exit(this.statusToExitCode(err.status));
518
542
  throw new Error('unreachable');
519
543
  }
@@ -29,6 +29,8 @@ export default class Verify extends BaseCommand {
29
29
  'trust-anchor': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
30
30
  'distrusted-key': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
31
31
  'agent-keys': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
32
+ 'federation-key': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
33
+ 'federation-key-history': import("@oclif/core/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/interfaces").CustomOptions>;
32
34
  'require-key-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
33
35
  'distrusted-keys': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
34
36
  'require-out-of-band-keys': import("@oclif/core/interfaces").BooleanFlag<boolean>;
@@ -49,6 +51,40 @@ export default class Verify extends BaseCommand {
49
51
  * entry that wraps its key as `{ publicKeyJwk: {...} }` (how an agent records
50
52
  * the key it sent at cert exchange) is unwrapped. verify-core validates each.
51
53
  */
54
+ /**
55
+ * `--federation-key` values into the `[{ hubId, publicKey }]` list
56
+ * verify-core takes, each checked here so a bad key is a usage error, not a
57
+ * verdict. A hub named twice pins two keys.
58
+ */
59
+ private parseFederationKeys;
60
+ /**
61
+ * Each `--federation-key-history` file attached to the `--federation-key`
62
+ * entry for the hub it names, or undefined when neither flag was given. A
63
+ * history needs a key for its hub: alone it is the peer's word.
64
+ */
65
+ private attachFederationKeyHistories;
52
66
  private unwrapAgentKeys;
53
67
  private renderHuman;
54
68
  }
69
+ /**
70
+ * The human line on the evidence bodies an `?evidence=true` export inlines,
71
+ * or null when it carries none. Each is hashed against the evidenceHash or
72
+ * payloadHash its entry signs; an encrypted-mode completion cannot be.
73
+ */
74
+ export declare function evidenceBodiesLine(counts: {
75
+ present: number;
76
+ verified: number;
77
+ clientHashed: number;
78
+ failed: number;
79
+ }): string | null;
80
+ /**
81
+ * The human line on the sealed federation messages, or null when the chain
82
+ * carries none. `failed` messages failed a check and are reported as
83
+ * failures; the rest of the unverified ones came from a hub with no key.
84
+ */
85
+ export declare function peerMessagesLine(wire: {
86
+ present: number;
87
+ verified: number;
88
+ failed: number;
89
+ afterRetirement: number;
90
+ }, federationKeysGiven: boolean): string | null;
@@ -1,6 +1,6 @@
1
- import { existsSync } from 'node:fs';
1
+ import { existsSync, readFileSync } from 'node:fs';
2
2
  import { Args, Flags } from '@oclif/core';
3
- import { assertNotPinnedAndDistrusted, parseDistrustedKeys, parseTrustAnchors, verifyAuditExport, } from '@agledger/verify-core';
3
+ import { assertNotPinnedAndDistrusted, parseDistrustedKeys, parseTrustAnchors, verifyAuditExport, normalizeFederationKey, } from '@agledger/verify-core';
4
4
  import { BaseCommand, ErrorCode, ExitCode } from '../base.js';
5
5
  /**
6
6
  * verify-core words a finding, note or failure for a library caller, so its
@@ -18,6 +18,9 @@ const OPTION_FLAGS = [
18
18
  [/\brequireSuppliedKeys\b/g, '--require-supplied-keys'],
19
19
  [/\brequireKeyId\b/g, '--require-key-id'],
20
20
  [/\bagentKeys\b/g, '--agent-keys'],
21
+ [/\bfederationKeys\[\d+\]\.history\b/g, '--federation-key-history'],
22
+ [/\bfederationKeys\[\d+\]/g, '--federation-key'],
23
+ [/\bfederationKeys\b/g, '--federation-key'],
21
24
  ];
22
25
  /** One prose string from a result, its option names given as this command's flags. */
23
26
  export function flagWording(text) {
@@ -59,6 +62,7 @@ export default class Verify extends BaseCommand {
59
62
  '<%= config.bin %> verify audit-export.json',
60
63
  '<%= config.bin %> verify audit-export.json --keys vault-keys.json',
61
64
  '<%= config.bin %> verify audit-export.json --agent-keys agent-jwks.json',
65
+ '<%= config.bin %> verify audit-export.json --federation-key hub-b=MCowBQYDK2VwAyEA...',
62
66
  '<%= config.bin %> verify audit-export.json --json',
63
67
  'cat audit-export.json | <%= config.bin %> verify -',
64
68
  ];
@@ -66,7 +70,7 @@ export default class Verify extends BaseCommand {
66
70
  // missing-arg error tells the caller to put arguments before every
67
71
  // repeatable flag, which is not true of non-greedy ones, and lists hidden
68
72
  // flags with them.
69
- static usage = 'verify FILE [--trust-anchor <value>...] [--distrusted-key <value>...] [--keys <value>] [--agent-keys <value>] [--require-key-id <value>] [--require-supplied-keys] [--json] [--quiet]';
73
+ static usage = 'verify FILE [--trust-anchor <value>...] [--distrusted-key <value>...] [--keys <value>] [--agent-keys <value>] [--federation-key <value>...] [--require-key-id <value>] [--require-supplied-keys] [--json] [--quiet]';
70
74
  static args = {
71
75
  file: Args.string({
72
76
  description: 'Path to the audit export JSON file (or "-" for stdin).',
@@ -111,6 +115,27 @@ export default class Verify extends BaseCommand {
111
115
  'of them by thumbprint has that signature re-verified offline, and fails ' +
112
116
  'CHAIN_AGENT_SIGNATURE_INVALID if it does not verify.',
113
117
  }),
118
+ 'federation-key': Flags.string({
119
+ multiple: true,
120
+ multipleNonGreedy: true,
121
+ description: '<hubId>=<key>: a peer Server\'s Ed25519 federation key as its operator gives it (base64 SPKI DER, ' +
122
+ 'or base64 of the raw 32 bytes the handshake registered). A receiving Server seals each peer message ' +
123
+ 'it accepts on the chain entry it writes (payload.wire), as the peer signed it. Every sealed message is ' +
124
+ 'held to its body hash and to its entry; one from a hub given here also has its signature re-verified ' +
125
+ 'under that key, which proves what the peer asserted from this export alone. A failure is ' +
126
+ 'CHAIN_FEDERATION_WIRE_INVALID. Repeatable, once per peer; name a hub twice to pin a second key ' +
127
+ 'no succession links to the first: one its history lists linked: false, or one it does not list at all.',
128
+ }),
129
+ 'federation-key-history': Flags.string({
130
+ multiple: true,
131
+ multipleNonGreedy: true,
132
+ description: 'Path to a peer\'s federation key history, the JSON its GET /.well-known/agledger-federation-keys.json serves ' +
133
+ '(no auth). Needs a --federation-key for the same hub: every key the history links to that key through ' +
134
+ 'successions both keys signed is trusted inside its window, so entries sealed before the peer changed its ' +
135
+ 'federation key verify. Each message is placed by its signed wire.timestamp, never by the unsigned ' +
136
+ 'createdAt: one signed under a key before the key\'s activation fails; one signed after its retirement is ' +
137
+ 'reported as after retirement. Repeatable.',
138
+ }),
114
139
  'require-key-id': Flags.string({
115
140
  description: 'Require every entry to reference this keyId. Rejects otherwise-valid exports ' +
116
141
  'signed by a retired or unexpected key.',
@@ -178,6 +203,7 @@ export default class Verify extends BaseCommand {
178
203
  const agentKeys = flags['agent-keys']
179
204
  ? this.unwrapAgentKeys(this.readJsonSource(flags['agent-keys'], 'agent keys', 'The --agent-keys file must be an Ed25519 JWK, a list of them, or a {keys:[...]} JWK Set.'))
180
205
  : undefined;
206
+ const federationKeys = this.attachFederationKeyHistories(this.parseFederationKeys(flags['federation-key'] ?? []), flags['federation-key-history'] ?? []);
181
207
  const exportData = this.readJsonSource(args.file, 'audit export', 'Pass the path to an audit-export JSON file, or `-` to read it from stdin. ' +
182
208
  'Obtain one with `agledger api GET /v1/records/{id}/audit-export`.');
183
209
  if (!exportData || typeof exportData !== 'object' || !('entries' in exportData)) {
@@ -201,13 +227,15 @@ export default class Verify extends BaseCommand {
201
227
  requireSuppliedKeys: flags['require-supplied-keys'],
202
228
  ...(trustAnchors.length > 0 ? { trustAnchors, distrustedKeys } : {}),
203
229
  agentKeys,
230
+ federationKeys,
204
231
  });
205
232
  }
206
233
  catch (err) {
207
234
  if (err instanceof TypeError) {
208
- this.failWith(ErrorCode.INVALID_FIELD, err.message, ExitCode.USAGE_ERROR, 'The --keys file must be a {keyId: SPKI-DER-base64} map or a list of ' +
235
+ this.failWith(ErrorCode.INVALID_FIELD, flagWording(err.message), ExitCode.USAGE_ERROR, 'The --keys file must be a {keyId: SPKI-DER-base64} map or a list of ' +
209
236
  '{keyId, publicKey, activatedAt?, retiredAt?} entries with RFC 3339 windows (the /v1/verification-keys body works as is); ' +
210
- 'the --agent-keys file must hold Ed25519 JWKs ({"kty":"OKP","crv":"Ed25519","x":"..."}).');
237
+ 'the --agent-keys file must hold Ed25519 JWKs ({"kty":"OKP","crv":"Ed25519","x":"..."}); ' +
238
+ 'a --federation-key-history file must be the peer\'s served document, unaltered, and reach the --federation-key given for its hub.');
211
239
  }
212
240
  throw err;
213
241
  }
@@ -220,7 +248,7 @@ export default class Verify extends BaseCommand {
220
248
  this.output({ verdict, ...rest });
221
249
  }
222
250
  else {
223
- this.renderHuman(result, agentKeys !== undefined);
251
+ this.renderHuman(result, agentKeys !== undefined, federationKeys !== undefined);
224
252
  }
225
253
  if (!result.valid)
226
254
  this.exit(ExitCode.GENERAL_ERROR);
@@ -247,6 +275,60 @@ export default class Verify extends BaseCommand {
247
275
  * entry that wraps its key as `{ publicKeyJwk: {...} }` (how an agent records
248
276
  * the key it sent at cert exchange) is unwrapped. verify-core validates each.
249
277
  */
278
+ /**
279
+ * `--federation-key` values into the `[{ hubId, publicKey }]` list
280
+ * verify-core takes, each checked here so a bad key is a usage error, not a
281
+ * verdict. A hub named twice pins two keys.
282
+ */
283
+ parseFederationKeys(values) {
284
+ const out = [];
285
+ const shape = 'Each --federation-key is <hubId>=<key>: the peer\'s hub id, then its Ed25519 federation key as base64 SPKI DER or base64 of the raw 32 bytes, as its operator gives it.';
286
+ for (const value of values) {
287
+ const at = value.indexOf('=');
288
+ const hubId = at === -1 ? '' : value.slice(0, at).trim();
289
+ const key = at === -1 ? '' : value.slice(at + 1).trim();
290
+ if (hubId === '' || key === '') {
291
+ this.failWith(ErrorCode.INVALID_FIELD, `Invalid --federation-key ${JSON.stringify(value)}.`, ExitCode.USAGE_ERROR, shape);
292
+ }
293
+ if (normalizeFederationKey(key) === null) {
294
+ this.failWith(ErrorCode.INVALID_FIELD, `Invalid --federation-key for hub ${hubId}: the key is not an Ed25519 public key.`, ExitCode.USAGE_ERROR, shape);
295
+ }
296
+ out.push({ hubId, publicKey: key });
297
+ }
298
+ return out;
299
+ }
300
+ /**
301
+ * Each `--federation-key-history` file attached to the `--federation-key`
302
+ * entry for the hub it names, or undefined when neither flag was given. A
303
+ * history needs a key for its hub: alone it is the peer's word.
304
+ */
305
+ attachFederationKeyHistories(keys, paths) {
306
+ if (keys.length === 0 && paths.length === 0)
307
+ return undefined;
308
+ const out = keys.map((k) => ({ ...k }));
309
+ for (const path of paths) {
310
+ let doc;
311
+ try {
312
+ doc = JSON.parse(readFileSync(path, 'utf8'));
313
+ }
314
+ catch (err) {
315
+ this.failWith(ErrorCode.INVALID_FIELD, `Cannot read --federation-key-history ${path}: ${err.message}`, ExitCode.USAGE_ERROR, 'Pass the JSON the peer serves at GET /.well-known/agledger-federation-keys.json.');
316
+ }
317
+ const hubId = doc !== null && typeof doc === 'object' ? doc.hubId : undefined;
318
+ if (typeof hubId !== 'string' || hubId === '') {
319
+ this.failWith(ErrorCode.INVALID_FIELD, `--federation-key-history ${path} is not a key-history document naming its hub.`, ExitCode.USAGE_ERROR, 'Pass the JSON the peer serves at GET /.well-known/agledger-federation-keys.json, with federation configured on the peer.');
320
+ }
321
+ const entry = out.find((k) => k.hubId === hubId && k.history === undefined) ?? out.find((k) => k.hubId === hubId);
322
+ if (entry === undefined) {
323
+ this.failWith(ErrorCode.INVALID_FIELD, `--federation-key-history ${path} is hub ${hubId}'s, and no --federation-key names that hub.`, ExitCode.USAGE_ERROR, 'Give the key you hold for it with --federation-key <hubId>=<key> (the signingPublicKey your peer row holds, or one its operator confirmed): the history is trusted only from a key you pinned.');
324
+ }
325
+ if (entry.history !== undefined)
326
+ out.push({ hubId, publicKey: entry.publicKey, history: doc });
327
+ else
328
+ entry.history = doc;
329
+ }
330
+ return out;
331
+ }
250
332
  unwrapAgentKeys(raw) {
251
333
  const list = Array.isArray(raw)
252
334
  ? raw
@@ -257,7 +339,7 @@ export default class Verify extends BaseCommand {
257
339
  ? entry.publicKeyJwk
258
340
  : entry);
259
341
  }
260
- renderHuman(result, agentKeysGiven) {
342
+ renderHuman(result, agentKeysGiven, federationKeysGiven) {
261
343
  if (this.isQuiet)
262
344
  return;
263
345
  const out = process.stdout;
@@ -307,6 +389,12 @@ export default class Verify extends BaseCommand {
307
389
  // Agent signatures are checked only against keys the caller supplies, so
308
390
  // the lines below say exactly how many were, and the PASS line speaks for
309
391
  // the Server's signatures alone.
392
+ const peerLine = peerMessagesLine(result.federationWire, federationKeysGiven);
393
+ if (peerLine)
394
+ out.write(` ${peerLine}\n`);
395
+ const evidenceLine = evidenceBodiesLine(result.evidenceBinding);
396
+ if (evidenceLine)
397
+ out.write(` ${evidenceLine}\n`);
310
398
  const { present, verified } = result.agentSignatures;
311
399
  const unchecked = present - verified;
312
400
  if (present > 0 && unchecked === 0) {
@@ -342,3 +430,47 @@ export default class Verify extends BaseCommand {
342
430
  }
343
431
  }
344
432
  }
433
+ /**
434
+ * The human line on the evidence bodies an `?evidence=true` export inlines,
435
+ * or null when it carries none. Each is hashed against the evidenceHash or
436
+ * payloadHash its entry signs; an encrypted-mode completion cannot be.
437
+ */
438
+ export function evidenceBodiesLine(counts) {
439
+ if (counts.present === 0)
440
+ return null;
441
+ const parts = [`${counts.verified}/${counts.present} inlined evidence bodies hash (RFC 8785, SHA-256) to the hash their entry signs`];
442
+ if (counts.failed > 0)
443
+ parts.push(`${counts.failed} failed CHAIN_EVIDENCE_BINDING_MISMATCH`);
444
+ if (counts.clientHashed > 0) {
445
+ parts.push(`${counts.clientHashed} on an encrypted-mode completion, whose signed hash covers a cleartext the export does not carry, so not re-bound`);
446
+ }
447
+ return `Evidence: ${parts.join('; ')}.`;
448
+ }
449
+ /**
450
+ * The human line on the sealed federation messages, or null when the chain
451
+ * carries none. `failed` messages failed a check and are reported as
452
+ * failures; the rest of the unverified ones came from a hub with no key.
453
+ */
454
+ export function peerMessagesLine(wire, federationKeysGiven) {
455
+ if (wire.present === 0)
456
+ return null;
457
+ const retired = wire.afterRetirement > 0
458
+ ? ` ${wire.afterRetirement} of them signed by the peer under a key it had already retired: in order when the receiver's federation.peer_revoked row for the peer comes after them.`
459
+ : '';
460
+ if (wire.present === wire.verified) {
461
+ return `Peer messages: ${wire.verified}/${wire.present} sealed federation messages re-verified under --federation-key.${retired}`;
462
+ }
463
+ if (!federationKeysGiven && wire.failed === 0) {
464
+ return `Peer messages: ${wire.present} sealed on the chain, hashed and matched to their entry; the peer signatures were not checked. Pass --federation-key <hubId>=<key> for each peer to re-verify them.`;
465
+ }
466
+ const noKey = wire.present - wire.verified - wire.failed;
467
+ const parts = [`${wire.verified}/${wire.present} re-verified`];
468
+ if (wire.failed > 0)
469
+ parts.push(`${wire.failed} failed CHAIN_FEDERATION_WIRE_INVALID`);
470
+ if (noKey > 0) {
471
+ parts.push(federationKeysGiven
472
+ ? `${noKey} come from a hub with no --federation-key and were hashed and matched to their entry only`
473
+ : `${noKey} were hashed and matched to their entry only; pass --federation-key <hubId>=<key> for each peer to re-verify them`);
474
+ }
475
+ return `Peer messages: ${parts.join('; ')}.${retired}`;
476
+ }
@@ -736,6 +736,7 @@
736
736
  "<%= config.bin %> verify audit-export.json",
737
737
  "<%= config.bin %> verify audit-export.json --keys vault-keys.json",
738
738
  "<%= config.bin %> verify audit-export.json --agent-keys agent-jwks.json",
739
+ "<%= config.bin %> verify audit-export.json --federation-key hub-b=MCowBQYDK2VwAyEA...",
739
740
  "<%= config.bin %> verify audit-export.json --json",
740
741
  "cat audit-export.json | <%= config.bin %> verify -"
741
742
  ],
@@ -809,6 +810,20 @@
809
810
  "multiple": false,
810
811
  "type": "option"
811
812
  },
813
+ "federation-key": {
814
+ "description": "<hubId>=<key>: a peer Server's Ed25519 federation key as its operator gives it (base64 SPKI DER, or base64 of the raw 32 bytes the handshake registered). A receiving Server seals each peer message it accepts on the chain entry it writes (payload.wire), as the peer signed it. Every sealed message is held to its body hash and to its entry; one from a hub given here also has its signature re-verified under that key, which proves what the peer asserted from this export alone. A failure is CHAIN_FEDERATION_WIRE_INVALID. Repeatable, once per peer; name a hub twice to pin a second key no succession links to the first: one its history lists linked: false, or one it does not list at all.",
815
+ "name": "federation-key",
816
+ "hasDynamicHelp": false,
817
+ "multiple": true,
818
+ "type": "option"
819
+ },
820
+ "federation-key-history": {
821
+ "description": "Path to a peer's federation key history, the JSON its GET /.well-known/agledger-federation-keys.json serves (no auth). Needs a --federation-key for the same hub: every key the history links to that key through successions both keys signed is trusted inside its window, so entries sealed before the peer changed its federation key verify. Each message is placed by its signed wire.timestamp, never by the unsigned createdAt: one signed under a key before the key's activation fails; one signed after its retirement is reported as after retirement. Repeatable.",
822
+ "name": "federation-key-history",
823
+ "hasDynamicHelp": false,
824
+ "multiple": true,
825
+ "type": "option"
826
+ },
812
827
  "require-key-id": {
813
828
  "description": "Require every entry to reference this keyId. Rejects otherwise-valid exports signed by a retired or unexpected key.",
814
829
  "name": "require-key-id",
@@ -843,7 +858,7 @@
843
858
  "pluginName": "@agledger/cli",
844
859
  "pluginType": "core",
845
860
  "strict": true,
846
- "usage": "verify FILE [--trust-anchor <value>...] [--distrusted-key <value>...] [--keys <value>] [--agent-keys <value>] [--require-key-id <value>] [--require-supplied-keys] [--json] [--quiet]",
861
+ "usage": "verify FILE [--trust-anchor <value>...] [--distrusted-key <value>...] [--keys <value>] [--agent-keys <value>] [--federation-key <value>...] [--require-key-id <value>] [--require-supplied-keys] [--json] [--quiet]",
847
862
  "enableJsonFlag": false,
848
863
  "isESM": true,
849
864
  "relativePath": [
@@ -853,5 +868,5 @@
853
868
  ]
854
869
  }
855
870
  },
856
- "version": "2.0.0"
871
+ "version": "2.1.0"
857
872
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agledger/cli",
3
- "version": "2.0.0",
4
- "description": "AGLedger CLI: developer and agent interface for AGLedger",
3
+ "version": "2.1.0",
4
+ "description": "AGLedger CLI: the AGLedger API from the command line, for developers and agents. Self-hosted, signed, hash-chained.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "type": "module",
7
7
  "bin": {
@@ -31,13 +31,13 @@
31
31
  "prepublishOnly": "npm run build && npm run lint:pkg"
32
32
  },
33
33
  "dependencies": {
34
- "@agledger/verify-core": "^2.0.0",
34
+ "@agledger/verify-core": "^2.1.0",
35
35
  "@oclif/core": "^5.0.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@arethetypeswrong/cli": "^0.18.3",
39
39
  "@types/node": "^24.0.0",
40
- "oclif": "^5.0.1",
40
+ "oclif": "^6.0.8",
41
41
  "publint": "^0.3.21",
42
42
  "typescript": "^7.0.2",
43
43
  "vitest": "^5.0.0"