@agledger/cli 0.5.1 → 0.5.3
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/LICENSE +115 -22
- package/README.md +2 -1
- package/SKILL.md +14 -1
- package/dist/api-client.js +1 -1
- package/dist/commands/list-commands.d.ts.map +1 -1
- package/dist/commands/list-commands.js +1 -0
- package/dist/commands/list-commands.js.map +1 -1
- package/dist/commands/verify.d.ts +23 -0
- package/dist/commands/verify.d.ts.map +1 -0
- package/dist/commands/verify.js +81 -0
- package/dist/commands/verify.js.map +1 -0
- package/dist/verify/verify-export.d.ts +70 -0
- package/dist/verify/verify-export.d.ts.map +1 -0
- package/dist/verify/verify-export.js +188 -0
- package/dist/verify/verify-export.js.map +1 -0
- package/oclif.manifest.json +583 -508
- package/package.json +1 -1
package/LICENSE
CHANGED
|
@@ -2,33 +2,126 @@ Copyright (c) 2026 AGLedger LLC. All rights reserved.
|
|
|
2
2
|
|
|
3
3
|
PROPRIETARY SOFTWARE LICENSE
|
|
4
4
|
|
|
5
|
-
This software
|
|
6
|
-
proprietary property of AGLedger LLC. The Software is
|
|
7
|
-
|
|
5
|
+
This software, together with its associated documentation files (the "Software"),
|
|
6
|
+
is the proprietary property of AGLedger LLC ("Licensor"). The Software is
|
|
7
|
+
licensed, not sold. Your right to use the Software is limited as set out below.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
BY DOWNLOADING, INSTALLING, COPYING, OR OTHERWISE USING THE SOFTWARE (INCLUDING
|
|
10
|
+
VIA `npm install`, `pip install`, OR ANY EQUIVALENT PACKAGE-MANAGER COMMAND),
|
|
11
|
+
YOU AGREE TO THE TERMS OF THIS LICENSE. IF YOU DO NOT AGREE, DO NOT DOWNLOAD,
|
|
12
|
+
INSTALL, OR USE THE SOFTWARE.
|
|
12
13
|
|
|
13
|
-
1.
|
|
14
|
-
copies of the Software, except as required to use it with the AGLedger API.
|
|
14
|
+
1. GRANT OF USE
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
Licensor grants you a limited, non-exclusive, non-transferable, revocable
|
|
17
|
+
license to install and use the Software solely for the purpose of integrating
|
|
18
|
+
with a self-hosted AGLedger deployment operated by you or your organization, or
|
|
19
|
+
by a third party on your behalf with your authorization. The Software is not
|
|
20
|
+
designed for, and is not licensed for use with, any AGLedger-hosted service.
|
|
21
|
+
AGLedger operates the AGLedger software on a self-hosted model; there is no
|
|
22
|
+
hosted AGLedger API.
|
|
17
23
|
|
|
18
|
-
|
|
19
|
-
except to the extent permitted by applicable law.
|
|
24
|
+
2. RESTRICTIONS
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
https://agledger.ai/terms.
|
|
26
|
+
You may not:
|
|
23
27
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
(a) copy, modify, merge, publish, distribute, sublicense, sell, rent, lease,
|
|
29
|
+
or transfer copies of the Software, except as strictly required to use
|
|
30
|
+
the Software for its intended integration purpose;
|
|
31
|
+
(b) offer the Software, or the functionality enabled by the Software, as a
|
|
32
|
+
hosted or managed service to third parties, whether as a standalone
|
|
33
|
+
offering or embedded within a larger service;
|
|
34
|
+
(c) use the Software to build, train, or benchmark a product or service that
|
|
35
|
+
competes with AGLedger;
|
|
36
|
+
(d) reverse engineer, decompile, or disassemble the Software, except to the
|
|
37
|
+
extent expressly permitted by applicable law that cannot be waived by
|
|
38
|
+
contract;
|
|
39
|
+
(e) circumvent, disable, or tamper with any authentication, license, or usage-
|
|
40
|
+
enforcement mechanism of the Software or of any AGLedger deployment;
|
|
41
|
+
(f) remove, alter, or obscure any copyright, trademark, patent, or other
|
|
42
|
+
proprietary notice in the Software;
|
|
43
|
+
(g) use the Software in violation of U.S. Export Administration Regulations,
|
|
44
|
+
economic sanctions, or other applicable export and trade-control laws.
|
|
30
45
|
|
|
31
|
-
|
|
46
|
+
3. OPEN SOURCE COMPONENTS
|
|
32
47
|
|
|
33
|
-
|
|
34
|
-
|
|
48
|
+
The Software may include third-party open-source components, each subject to
|
|
49
|
+
its own license terms. A list of such components and their licenses is included
|
|
50
|
+
with or referenced from the Software. In the event of a conflict between this
|
|
51
|
+
License and an open-source license, the open-source license governs solely with
|
|
52
|
+
respect to that component.
|
|
53
|
+
|
|
54
|
+
4. NO WARRANTY
|
|
55
|
+
|
|
56
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND "AS AVAILABLE", WITHOUT WARRANTY OF ANY
|
|
57
|
+
KIND, EXPRESS, IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TO THE
|
|
58
|
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND
|
|
59
|
+
NONINFRINGEMENT. AGLEDGER LLC DOES NOT WARRANT THAT THE SOFTWARE WILL BE ERROR-
|
|
60
|
+
FREE, SECURE, OR UNINTERRUPTED.
|
|
61
|
+
|
|
62
|
+
5. LIMITATION OF LIABILITY
|
|
63
|
+
|
|
64
|
+
The limitations in this Section 5 are a material inducement to AGLedger LLC to
|
|
65
|
+
make the Software publicly available at no charge, and they apply notwithstanding
|
|
66
|
+
any failure of essential purpose of any limited remedy and regardless of the
|
|
67
|
+
theory of liability (contract, tort, strict liability, statute, or otherwise).
|
|
68
|
+
|
|
69
|
+
TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL AGLEDGER
|
|
70
|
+
LLC BE LIABLE FOR ANY INDIRECT, INCIDENTAL, SPECIAL, CONSEQUENTIAL, EXEMPLARY,
|
|
71
|
+
OR PUNITIVE DAMAGES, OR FOR LOSS OF PROFITS, REVENUE, DATA, USE, GOODWILL, OR
|
|
72
|
+
BUSINESS OPPORTUNITY, ARISING FROM OR RELATED TO THE SOFTWARE, EVEN IF ADVISED
|
|
73
|
+
OF THE POSSIBILITY OF SUCH DAMAGES. AGLEDGER LLC'S TOTAL AGGREGATE LIABILITY
|
|
74
|
+
FOR ALL CLAIMS RELATED TO THE SOFTWARE SHALL NOT EXCEED ONE HUNDRED U.S.
|
|
75
|
+
DOLLARS ($100.00). Any claim must be commenced within one (1) year after the
|
|
76
|
+
cause of action accrues, to the maximum extent permitted by applicable law.
|
|
77
|
+
|
|
78
|
+
6. EXPORT COMPLIANCE
|
|
79
|
+
|
|
80
|
+
The Software may include cryptographic functionality (including Ed25519, AES-
|
|
81
|
+
256-GCM, SHA-256, and X25519). AGLedger LLC classifies the Software under
|
|
82
|
+
ECCN 5D002 in good faith. To the extent AGLedger LLC makes the source code of
|
|
83
|
+
the Software publicly available through a public repository, that source code
|
|
84
|
+
is subject to the treatment afforded under 15 CFR § 742.15(b) of the U.S.
|
|
85
|
+
Export Administration Regulations. Binary and object-code distributions are
|
|
86
|
+
subject to License Exception ENC under 15 CFR § 740.17, subject to the one-
|
|
87
|
+
time notification and any required Encryption Registration to the U.S. Bureau
|
|
88
|
+
of Industry and Security (BIS) and the NSA ENC Encryption Request Coordinator.
|
|
89
|
+
This statement is not a warranty; you are responsible for independently
|
|
90
|
+
confirming the correct classification and license authority for your use,
|
|
91
|
+
destination, and end-user. You shall not export or re-export the Software to
|
|
92
|
+
any destination, entity, or end-use prohibited by applicable export, sanctions,
|
|
93
|
+
or trade-control laws.
|
|
94
|
+
|
|
95
|
+
7. TRADEMARKS
|
|
96
|
+
|
|
97
|
+
AGLedger, Agentic Ledger, Settlement Signal, and Agentic Operations and
|
|
98
|
+
Accountability Protocol (AOAP) are trademarks of AGLedger LLC. All other
|
|
99
|
+
trademarks are the property of their respective owners.
|
|
100
|
+
|
|
101
|
+
8. PATENTS
|
|
102
|
+
|
|
103
|
+
The Software is covered by one or more U.S. patent applications pending before
|
|
104
|
+
the U.S. Patent and Trademark Office in AGLedger LLC's patent portfolio.
|
|
105
|
+
|
|
106
|
+
9. RELATIONSHIP TO OTHER AGLEDGER AGREEMENTS
|
|
107
|
+
|
|
108
|
+
If you are also a Licensee under an AGLedger Software License Agreement
|
|
109
|
+
executed with an Order Form, that Software License Agreement governs your
|
|
110
|
+
organization's use of the Licensed Software (including the Software distributed
|
|
111
|
+
under this License) and supersedes this License to the extent of any conflict.
|
|
112
|
+
Absent such an agreement, this License is the exclusive and entire license
|
|
113
|
+
between you and AGLedger LLC for the Software.
|
|
114
|
+
|
|
115
|
+
10. GOVERNING LAW
|
|
116
|
+
|
|
117
|
+
This License is governed by the laws of the State of Idaho, without regard to
|
|
118
|
+
its conflict-of-laws provisions. Any dispute arising out of or related to this
|
|
119
|
+
License shall first be subject to good-faith negotiation for thirty (30) days,
|
|
120
|
+
and then, at AGLedger LLC's option, to binding arbitration under the rules of
|
|
121
|
+
the American Arbitration Association in Ada County, Idaho, or to the state or
|
|
122
|
+
federal courts located in Ada County, Idaho. You consent to the personal
|
|
123
|
+
jurisdiction and venue of those forums.
|
|
124
|
+
|
|
125
|
+
11. CONTACT
|
|
126
|
+
|
|
127
|
+
For licensing inquiries, contact: legal@agledger.ai
|
package/README.md
CHANGED
|
@@ -73,7 +73,7 @@ Merging order (low → high): `--data` → `--input` → `-F` → `--query`. Lat
|
|
|
73
73
|
## Discovery
|
|
74
74
|
|
|
75
75
|
```bash
|
|
76
|
-
agledger list-commands --json #
|
|
76
|
+
agledger list-commands --json # 9 CLI-local commands
|
|
77
77
|
agledger help-json api --json # Schema for `api` (args + flags)
|
|
78
78
|
agledger discover # Health + identity + quickstart
|
|
79
79
|
agledger api GET /openapi.json # Full API route catalog
|
|
@@ -89,6 +89,7 @@ agledger api GET /openapi.json # Full API route catalog
|
|
|
89
89
|
| `logout` | Remove profile(s) |
|
|
90
90
|
| `auth` | Check current login state (exit 0 either way) |
|
|
91
91
|
| `config` | `list` / `get` / `use <profile>` / `path` |
|
|
92
|
+
| `verify` | Offline audit export verification (hash chain + Ed25519, no network) |
|
|
92
93
|
| `list-commands` | Inventory (this list) |
|
|
93
94
|
| `help-json` | Per-command schema |
|
|
94
95
|
|
package/SKILL.md
CHANGED
|
@@ -27,10 +27,23 @@ agledger api <METHOD> <PATH> [--data JSON | --input FILE | -F key=value ...]
|
|
|
27
27
|
- `-F key=value` — repeatable; types parsed (`true`/`false`/`null`/numbers); nested via `a.b=v`; arrays via `arr[]=v`
|
|
28
28
|
|
|
29
29
|
## Discovery commands
|
|
30
|
-
- `agledger list-commands --json` — full CLI inventory (
|
|
30
|
+
- `agledger list-commands --json` — full CLI inventory (9 commands)
|
|
31
31
|
- `agledger help-json <command> --json` — per-command schema with args and flags
|
|
32
32
|
- `agledger api GET /openapi.json` — full API route catalog
|
|
33
33
|
|
|
34
|
+
## Offline audit verification
|
|
35
|
+
- `agledger verify <audit-export.json>` — verify a mandate audit export offline (RFC 8785 hash chain + Ed25519). No network, no API key. Exit 0 if valid, 1 if broken; `--json` for structured output; `--keys <file>` overrides embedded keys; `--require-key-id <id>` for high-assurance flows.
|
|
36
|
+
|
|
37
|
+
**What verification proves:**
|
|
38
|
+
- Every entry was signed by a key listed in the export (or supplied via `--keys`) at the moment the vault wrote it.
|
|
39
|
+
- Payloads have not been altered since signing (SHA-256 recomputation matches stored `payloadHash`).
|
|
40
|
+
- The hash chain is contiguous — no entries were inserted, removed, or reordered between positions.
|
|
41
|
+
|
|
42
|
+
**What verification does NOT prove:**
|
|
43
|
+
- That the signing key is *legitimate* — verify the key against `/.well-known/agledger-vault-keys.json` on the issuing instance (or the `/v1/verification-keys` API) out-of-band.
|
|
44
|
+
- That the export is *complete* — a vault operator can still truncate the export at either end.
|
|
45
|
+
- That the *content* the payload describes actually happened. Payloads record what the agent reported (declared intent); the verifier does not cross-check against external systems.
|
|
46
|
+
|
|
34
47
|
## Agent-native patterns
|
|
35
48
|
- `--json` on every command (auto when piped)
|
|
36
49
|
- `--quiet` for exit-code-only operation
|
package/dist/api-client.js
CHANGED
|
@@ -19,7 +19,7 @@ export class ApiClient {
|
|
|
19
19
|
const headers = {
|
|
20
20
|
Authorization: `Bearer ${this.apiKey}`,
|
|
21
21
|
Accept: 'application/json',
|
|
22
|
-
'User-Agent': 'agledger-cli/0.5.
|
|
22
|
+
'User-Agent': 'agledger-cli/0.5.3',
|
|
23
23
|
};
|
|
24
24
|
if (options?.body !== undefined) {
|
|
25
25
|
headers['Content-Type'] = 'application/json';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-commands.d.ts","sourceRoot":"","sources":["../../src/commands/list-commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,WAAW;IACnD,OAAgB,WAAW,SAA6F;IAExH,OAAgB,KAAK;;;;;MAAgC;IAE/C,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"list-commands.d.ts","sourceRoot":"","sources":["../../src/commands/list-commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,WAAW;IACnD,OAAgB,WAAW,SAA6F;IAExH,OAAgB,KAAK;;;;;MAAgC;IAE/C,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAkB3B"}
|
|
@@ -19,6 +19,7 @@ export default class ListCommands extends BaseCommand {
|
|
|
19
19
|
{ name: 'logout', description: 'Remove a stored profile.' },
|
|
20
20
|
{ name: 'auth', description: 'Check current authentication status (exit 0 whether logged in or not).' },
|
|
21
21
|
{ name: 'config', description: 'Inspect or switch between stored profiles (list, get, use, path).' },
|
|
22
|
+
{ name: 'verify', description: 'Verify an audit export offline (hash chain + Ed25519 signatures).' },
|
|
22
23
|
{ name: 'list-commands', description: 'List all CLI commands (this).' },
|
|
23
24
|
{ name: 'help-json', description: 'Get JSON schema for a specific CLI command.' },
|
|
24
25
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-commands.js","sourceRoot":"","sources":["../../src/commands/list-commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,WAAW;IACnD,MAAM,CAAU,WAAW,GAAG,yFAAyF,CAAC;IAExH,MAAM,CAAU,KAAK,GAAG,EAAE,GAAG,WAAW,CAAC,SAAS,EAAE,CAAC;IAErD,KAAK,CAAC,GAAG;QACP,MAAM,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QAC/B,MAAM,QAAQ,GAAG;YACf,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,iEAAiE,EAAE;YAC/F,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,sEAAsE,EAAE;YACzG,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,mEAAmE,EAAE;YACnG,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,0BAA0B,EAAE;YAC3D,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,wEAAwE,EAAE;YACvG,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,mEAAmE,EAAE;YACpG,EAAE,IAAI,EAAE,eAAe,EAAE,WAAW,EAAE,+BAA+B,EAAE;YACvE,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,6CAA6C,EAAE;SAClF,CAAC;QACF,IAAI,CAAC,MAAM,CAAC;YACV,QAAQ;YACR,IAAI,EAAE,iJAAiJ;SACxJ,CAAC,CAAC;IACL,CAAC"}
|
|
1
|
+
{"version":3,"file":"list-commands.js","sourceRoot":"","sources":["../../src/commands/list-commands.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,WAAW;IACnD,MAAM,CAAU,WAAW,GAAG,yFAAyF,CAAC;IAExH,MAAM,CAAU,KAAK,GAAG,EAAE,GAAG,WAAW,CAAC,SAAS,EAAE,CAAC;IAErD,KAAK,CAAC,GAAG;QACP,MAAM,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QAC/B,MAAM,QAAQ,GAAG;YACf,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE,iEAAiE,EAAE;YAC/F,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,sEAAsE,EAAE;YACzG,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,EAAE,mEAAmE,EAAE;YACnG,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,0BAA0B,EAAE;YAC3D,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,wEAAwE,EAAE;YACvG,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,mEAAmE,EAAE;YACpG,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,mEAAmE,EAAE;YACpG,EAAE,IAAI,EAAE,eAAe,EAAE,WAAW,EAAE,+BAA+B,EAAE;YACvE,EAAE,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,6CAA6C,EAAE;SAClF,CAAC;QACF,IAAI,CAAC,MAAM,CAAC;YACV,QAAQ;YACR,IAAI,EAAE,iJAAiJ;SACxJ,CAAC,CAAC;IACL,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BaseCommand } from '../base.js';
|
|
2
|
+
/**
|
|
3
|
+
* Offline verification of a mandate audit export. Runs entirely offline — no
|
|
4
|
+
* network calls, no API key required. Keeps the CLI free of any @agledger/sdk
|
|
5
|
+
* dependency by duplicating the verifier from the TS SDK; parity with the SDK
|
|
6
|
+
* and Python port is enforced via shared test vectors under testdata/verifier/.
|
|
7
|
+
*/
|
|
8
|
+
export default class Verify extends BaseCommand {
|
|
9
|
+
static description: string;
|
|
10
|
+
static examples: string[];
|
|
11
|
+
static args: {
|
|
12
|
+
file: import("@oclif/core/interfaces").Arg<string, Record<string, unknown>>;
|
|
13
|
+
};
|
|
14
|
+
static flags: {
|
|
15
|
+
json: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
16
|
+
quiet: import("@oclif/core/interfaces").BooleanFlag<boolean>;
|
|
17
|
+
keys: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
18
|
+
'require-key-id': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
19
|
+
};
|
|
20
|
+
run(): Promise<void>;
|
|
21
|
+
private renderHuman;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=verify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../src/commands/verify.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAuB,MAAM,YAAY,CAAC;AAE9D;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,MAAO,SAAQ,WAAW;IAC7C,OAAgB,WAAW,SAC4D;IAEvF,OAAgB,QAAQ,WAKtB;IAEF,OAAgB,IAAI;;MAKlB;IAEF,OAAgB,KAAK;;;;;MAanB;IAEI,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;IA+B1B,OAAO,CAAC,WAAW;CA2BpB"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Args, Flags } from '@oclif/core';
|
|
2
|
+
import { verifyExport } from '../verify/verify-export.js';
|
|
3
|
+
import { BaseCommand, ErrorCode, ExitCode } from '../base.js';
|
|
4
|
+
/**
|
|
5
|
+
* Offline verification of a mandate audit export. Runs entirely offline — no
|
|
6
|
+
* network calls, no API key required. Keeps the CLI free of any @agledger/sdk
|
|
7
|
+
* dependency by duplicating the verifier from the TS SDK; parity with the SDK
|
|
8
|
+
* and Python port is enforced via shared test vectors under testdata/verifier/.
|
|
9
|
+
*/
|
|
10
|
+
export default class Verify extends BaseCommand {
|
|
11
|
+
static description = 'Verify a mandate audit export offline (hash chain + Ed25519 signatures, RFC 8785).';
|
|
12
|
+
static examples = [
|
|
13
|
+
'<%= config.bin %> verify audit-export.json',
|
|
14
|
+
'<%= config.bin %> verify audit-export.json --keys vault-keys.json',
|
|
15
|
+
'<%= config.bin %> verify audit-export.json --json',
|
|
16
|
+
'cat audit-export.json | <%= config.bin %> verify -',
|
|
17
|
+
];
|
|
18
|
+
static args = {
|
|
19
|
+
file: Args.string({
|
|
20
|
+
description: 'Path to the audit export JSON file (or "-" for stdin).',
|
|
21
|
+
required: true,
|
|
22
|
+
}),
|
|
23
|
+
};
|
|
24
|
+
static flags = {
|
|
25
|
+
json: BaseCommand.baseFlags.json,
|
|
26
|
+
quiet: BaseCommand.baseFlags.quiet,
|
|
27
|
+
keys: Flags.string({
|
|
28
|
+
description: 'Path to a JSON file mapping signingKeyId → SPKI DER base64 public key. ' +
|
|
29
|
+
'Merged over any keys embedded in the export.',
|
|
30
|
+
}),
|
|
31
|
+
'require-key-id': Flags.string({
|
|
32
|
+
description: 'Require every entry to reference this keyId. Rejects otherwise-valid exports ' +
|
|
33
|
+
'signed by a retired or unexpected key.',
|
|
34
|
+
}),
|
|
35
|
+
};
|
|
36
|
+
async run() {
|
|
37
|
+
const { args, flags } = await this.parse(Verify);
|
|
38
|
+
const exportData = this.readJsonSource(args.file, 'audit export');
|
|
39
|
+
if (!exportData || typeof exportData !== 'object' || !('entries' in exportData)) {
|
|
40
|
+
this.failWith(ErrorCode.INVALID_JSON_INPUT, 'File is not a valid audit export (expected exportMetadata + entries).', ExitCode.USAGE_ERROR, 'Use `agledger api GET /v1/mandates/{id}/audit-export` to obtain a valid export.');
|
|
41
|
+
}
|
|
42
|
+
const publicKeys = flags.keys
|
|
43
|
+
? this.readJsonSource(flags.keys, 'public keys')
|
|
44
|
+
: undefined;
|
|
45
|
+
const result = verifyExport(exportData, {
|
|
46
|
+
publicKeys,
|
|
47
|
+
requireKeyId: flags['require-key-id'],
|
|
48
|
+
});
|
|
49
|
+
if (this.isJson) {
|
|
50
|
+
this.output(result);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
this.renderHuman(result);
|
|
54
|
+
}
|
|
55
|
+
if (!result.valid)
|
|
56
|
+
this.exit(ExitCode.GENERAL_ERROR);
|
|
57
|
+
}
|
|
58
|
+
renderHuman(result) {
|
|
59
|
+
if (this.isQuiet)
|
|
60
|
+
return;
|
|
61
|
+
const out = process.stdout;
|
|
62
|
+
const icon = result.valid ? 'PASS' : 'FAIL';
|
|
63
|
+
out.write(`${icon} Mandate: ${result.mandateId}\n`);
|
|
64
|
+
out.write(` Entries: ${result.verifiedEntries}/${result.totalEntries} verified\n`);
|
|
65
|
+
if (result.valid) {
|
|
66
|
+
out.write(' Hash chain contiguous, every signature verified.\n');
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (result.brokenAt) {
|
|
70
|
+
out.write(` Broken at position ${result.brokenAt.position}: ${result.brokenAt.reason}\n`);
|
|
71
|
+
if (result.brokenAt.detail) {
|
|
72
|
+
out.write(` Detail: ${result.brokenAt.detail}\n`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const failures = result.entries.filter((e) => !e.valid);
|
|
76
|
+
if (failures.length > 1) {
|
|
77
|
+
out.write(` ${failures.length} entries failed verification.\n`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=verify.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify.js","sourceRoot":"","sources":["../../src/commands/verify.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAoD,MAAM,4BAA4B,CAAC;AAC5G,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE9D;;;;;GAKG;AACH,MAAM,CAAC,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,CAAC,MAAM,IAAI,CAAC,CAAC;YAC1D,CAAC;QACH,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;QACxD,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxB,GAAG,CAAC,KAAK,CAAC,UAAU,QAAQ,CAAC,MAAM,iCAAiC,CAAC,CAAC;QACxE,CAAC;IACH,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Offline verification of an AGLedger audit export.
|
|
3
|
+
*
|
|
4
|
+
* Re-implements the vault's per-entry integrity check (RFC 8785 JCS → SHA-256
|
|
5
|
+
* → Ed25519 over `{position}:{payloadHash}:{previousHash}`) and walks the hash
|
|
6
|
+
* chain. Makes no network calls.
|
|
7
|
+
*
|
|
8
|
+
* Duplicated in each shipping surface (TS SDK, CLI, MCP server) on purpose —
|
|
9
|
+
* see feedback_mcp_no_sdk.md. The CLI/MCP are not allowed to depend on
|
|
10
|
+
* @agledger/sdk even for offline crypto. Three independent copies in this
|
|
11
|
+
* repo, plus an independent Python port, also serves as a cross-implementation
|
|
12
|
+
* correctness check via the shared test vectors at testdata/verifier/.
|
|
13
|
+
*/
|
|
14
|
+
export interface AuditExportEntry {
|
|
15
|
+
position: number;
|
|
16
|
+
timestamp: string;
|
|
17
|
+
entryType: string;
|
|
18
|
+
description: string;
|
|
19
|
+
payload: Record<string, unknown>;
|
|
20
|
+
integrity: {
|
|
21
|
+
payloadHash: string;
|
|
22
|
+
hashAlg?: string;
|
|
23
|
+
previousHash: string | null;
|
|
24
|
+
signature: string | null;
|
|
25
|
+
signatureAlg?: string;
|
|
26
|
+
signingKeyId: string | null;
|
|
27
|
+
valid: boolean;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export interface MandateAuditExport {
|
|
31
|
+
exportMetadata: {
|
|
32
|
+
mandateId: string;
|
|
33
|
+
enterpriseId: string | null;
|
|
34
|
+
contractType: string;
|
|
35
|
+
exportDate: string;
|
|
36
|
+
totalEntries: number;
|
|
37
|
+
chainIntegrity: boolean;
|
|
38
|
+
exportFormatVersion: string;
|
|
39
|
+
canonicalization: string;
|
|
40
|
+
signingPublicKey: string | null;
|
|
41
|
+
signingPublicKeys?: Record<string, string>;
|
|
42
|
+
};
|
|
43
|
+
entries: AuditExportEntry[];
|
|
44
|
+
}
|
|
45
|
+
export interface EntryVerificationResult {
|
|
46
|
+
position: number;
|
|
47
|
+
valid: boolean;
|
|
48
|
+
reason?: EntryFailureReason;
|
|
49
|
+
detail?: string;
|
|
50
|
+
}
|
|
51
|
+
export type EntryFailureReason = 'payload_hash_mismatch' | 'chain_break' | 'position_gap' | 'signature_invalid' | 'unknown_key' | 'malformed_entry' | 'unsupported_algorithm';
|
|
52
|
+
export interface VerifyExportResult {
|
|
53
|
+
valid: boolean;
|
|
54
|
+
totalEntries: number;
|
|
55
|
+
verifiedEntries: number;
|
|
56
|
+
brokenAt?: {
|
|
57
|
+
position: number;
|
|
58
|
+
reason: EntryFailureReason;
|
|
59
|
+
detail?: string;
|
|
60
|
+
};
|
|
61
|
+
entries: EntryVerificationResult[];
|
|
62
|
+
mandateId: string;
|
|
63
|
+
}
|
|
64
|
+
export interface VerifyExportOptions {
|
|
65
|
+
publicKeys?: Record<string, string>;
|
|
66
|
+
requireKeyId?: string;
|
|
67
|
+
}
|
|
68
|
+
export declare function verifyExport(exportData: MandateAuditExport, options?: VerifyExportOptions): VerifyExportResult;
|
|
69
|
+
export declare function canonicalize(value: unknown): string;
|
|
70
|
+
//# sourceMappingURL=verify-export.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-export.d.ts","sourceRoot":"","sources":["../../src/verify/verify-export.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,gBAAgB;IAC/B,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;AAE5B,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,OAAO,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE;QACT,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,kBAAkB,CAAC;QAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,OAAO,EAAE,uBAAuB,EAAE,CAAC;IACnC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,mBAAmB;IAClC,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAMD,wBAAgB,YAAY,CAC1B,UAAU,EAAE,kBAAkB,EAC9B,OAAO,GAAE,mBAAwB,GAChC,kBAAkB,CA+CpB;AAoID,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAkBnD"}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { createHash, createPublicKey, verify as cryptoVerify } from 'node:crypto';
|
|
2
|
+
const RFC8785 = 'RFC8785';
|
|
3
|
+
const SUPPORTED_HASH = new Set(['SHA-256', 'sha-256', 'sha256']);
|
|
4
|
+
const SUPPORTED_SIG = new Set(['Ed25519', 'ed25519']);
|
|
5
|
+
export function verifyExport(exportData, options = {}) {
|
|
6
|
+
const meta = exportData.exportMetadata;
|
|
7
|
+
const entries = exportData.entries ?? [];
|
|
8
|
+
const keys = new KeyCache(resolveKeys(exportData, options));
|
|
9
|
+
const entryResults = [];
|
|
10
|
+
let verifiedEntries = 0;
|
|
11
|
+
let brokenAt;
|
|
12
|
+
if (meta.canonicalization && meta.canonicalization !== RFC8785) {
|
|
13
|
+
const detail = `Unsupported canonicalization: ${meta.canonicalization} (only RFC8785 supported)`;
|
|
14
|
+
const result = {
|
|
15
|
+
position: 0,
|
|
16
|
+
valid: false,
|
|
17
|
+
reason: 'unsupported_algorithm',
|
|
18
|
+
detail,
|
|
19
|
+
};
|
|
20
|
+
return {
|
|
21
|
+
valid: false,
|
|
22
|
+
totalEntries: entries.length,
|
|
23
|
+
verifiedEntries: 0,
|
|
24
|
+
brokenAt: { position: 0, reason: 'unsupported_algorithm', detail },
|
|
25
|
+
entries: [result],
|
|
26
|
+
mandateId: meta.mandateId,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
let prevPayloadHash = null;
|
|
30
|
+
for (let i = 0; i < entries.length; i++) {
|
|
31
|
+
const entry = entries[i];
|
|
32
|
+
const result = verifyEntry(entry, i + 1, prevPayloadHash, keys, options.requireKeyId);
|
|
33
|
+
entryResults.push(result);
|
|
34
|
+
if (result.valid) {
|
|
35
|
+
verifiedEntries++;
|
|
36
|
+
}
|
|
37
|
+
else if (!brokenAt && result.reason) {
|
|
38
|
+
brokenAt = { position: result.position, reason: result.reason, detail: result.detail };
|
|
39
|
+
}
|
|
40
|
+
prevPayloadHash = entry.integrity.payloadHash;
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
valid: verifiedEntries === entries.length && entries.length > 0,
|
|
44
|
+
totalEntries: entries.length,
|
|
45
|
+
verifiedEntries,
|
|
46
|
+
brokenAt,
|
|
47
|
+
entries: entryResults,
|
|
48
|
+
mandateId: meta.mandateId,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function resolveKeys(exportData, options) {
|
|
52
|
+
const meta = exportData.exportMetadata;
|
|
53
|
+
const merged = {};
|
|
54
|
+
if (meta.signingPublicKeys) {
|
|
55
|
+
for (const [k, v] of Object.entries(meta.signingPublicKeys))
|
|
56
|
+
merged[k] = v;
|
|
57
|
+
}
|
|
58
|
+
if (options.publicKeys) {
|
|
59
|
+
for (const [k, v] of Object.entries(options.publicKeys))
|
|
60
|
+
merged[k] = v;
|
|
61
|
+
}
|
|
62
|
+
return merged;
|
|
63
|
+
}
|
|
64
|
+
class KeyCache {
|
|
65
|
+
spki;
|
|
66
|
+
cache = new Map();
|
|
67
|
+
constructor(spki) {
|
|
68
|
+
this.spki = spki;
|
|
69
|
+
}
|
|
70
|
+
get(keyId) {
|
|
71
|
+
const existing = this.cache.get(keyId);
|
|
72
|
+
if (existing)
|
|
73
|
+
return existing;
|
|
74
|
+
const raw = this.spki[keyId];
|
|
75
|
+
if (!raw)
|
|
76
|
+
return undefined;
|
|
77
|
+
const key = createPublicKey({ key: Buffer.from(raw, 'base64'), format: 'der', type: 'spki' });
|
|
78
|
+
this.cache.set(keyId, key);
|
|
79
|
+
return key;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function verifyEntry(entry, expectedPosition, expectedPrevHash, keys, requireKeyId) {
|
|
83
|
+
const position = entry.position;
|
|
84
|
+
if (entry.position !== expectedPosition) {
|
|
85
|
+
return {
|
|
86
|
+
position,
|
|
87
|
+
valid: false,
|
|
88
|
+
reason: 'position_gap',
|
|
89
|
+
detail: `Expected position ${expectedPosition}, got ${entry.position}`,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const { payloadHash, previousHash, signature, signingKeyId, hashAlg, signatureAlg } = entry.integrity;
|
|
93
|
+
if (hashAlg && !SUPPORTED_HASH.has(hashAlg)) {
|
|
94
|
+
return { position, valid: false, reason: 'unsupported_algorithm', detail: `hashAlg=${hashAlg}` };
|
|
95
|
+
}
|
|
96
|
+
if (signatureAlg && !SUPPORTED_SIG.has(signatureAlg)) {
|
|
97
|
+
return {
|
|
98
|
+
position,
|
|
99
|
+
valid: false,
|
|
100
|
+
reason: 'unsupported_algorithm',
|
|
101
|
+
detail: `signatureAlg=${signatureAlg}`,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
if (previousHash !== expectedPrevHash) {
|
|
105
|
+
return {
|
|
106
|
+
position,
|
|
107
|
+
valid: false,
|
|
108
|
+
reason: 'chain_break',
|
|
109
|
+
detail: `Expected previousHash=${expectedPrevHash ?? 'null'}, got ${previousHash ?? 'null'}`,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
const recomputed = sha256Hex(canonicalize(entry.payload));
|
|
113
|
+
if (recomputed !== payloadHash) {
|
|
114
|
+
return {
|
|
115
|
+
position,
|
|
116
|
+
valid: false,
|
|
117
|
+
reason: 'payload_hash_mismatch',
|
|
118
|
+
detail: `Recomputed ${recomputed.slice(0, 16)}…, stored ${payloadHash.slice(0, 16)}…`,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
if (!signature || !signingKeyId) {
|
|
122
|
+
return {
|
|
123
|
+
position,
|
|
124
|
+
valid: false,
|
|
125
|
+
reason: 'malformed_entry',
|
|
126
|
+
detail: 'Missing signature or signingKeyId',
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
if (requireKeyId && signingKeyId !== requireKeyId) {
|
|
130
|
+
return {
|
|
131
|
+
position,
|
|
132
|
+
valid: false,
|
|
133
|
+
reason: 'unknown_key',
|
|
134
|
+
detail: `Entry keyId=${signingKeyId} does not match requireKeyId=${requireKeyId}`,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
const publicKey = keys.get(signingKeyId);
|
|
138
|
+
if (!publicKey) {
|
|
139
|
+
return {
|
|
140
|
+
position,
|
|
141
|
+
valid: false,
|
|
142
|
+
reason: 'unknown_key',
|
|
143
|
+
detail: `No public key for keyId=${signingKeyId}`,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
const signInput = `${position}:${payloadHash}:${previousHash ?? 'null'}`;
|
|
147
|
+
let sigValid = false;
|
|
148
|
+
try {
|
|
149
|
+
sigValid = verifyEd25519(publicKey, signInput, signature);
|
|
150
|
+
}
|
|
151
|
+
catch (err) {
|
|
152
|
+
return {
|
|
153
|
+
position,
|
|
154
|
+
valid: false,
|
|
155
|
+
reason: 'signature_invalid',
|
|
156
|
+
detail: `Signature verification threw: ${err.message}`,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
if (!sigValid) {
|
|
160
|
+
return { position, valid: false, reason: 'signature_invalid' };
|
|
161
|
+
}
|
|
162
|
+
return { position, valid: true };
|
|
163
|
+
}
|
|
164
|
+
export function canonicalize(value) {
|
|
165
|
+
if (value === null || value === undefined)
|
|
166
|
+
return 'null';
|
|
167
|
+
if (typeof value === 'boolean' || typeof value === 'number' || typeof value === 'string') {
|
|
168
|
+
return JSON.stringify(value);
|
|
169
|
+
}
|
|
170
|
+
if (Array.isArray(value)) {
|
|
171
|
+
return '[' + value.map(canonicalize).join(',') + ']';
|
|
172
|
+
}
|
|
173
|
+
if (typeof value === 'object') {
|
|
174
|
+
const obj = value;
|
|
175
|
+
const keys = Object.keys(obj).sort();
|
|
176
|
+
return ('{' +
|
|
177
|
+
keys.map((k) => JSON.stringify(k) + ':' + canonicalize(obj[k])).join(',') +
|
|
178
|
+
'}');
|
|
179
|
+
}
|
|
180
|
+
return 'null';
|
|
181
|
+
}
|
|
182
|
+
function sha256Hex(data) {
|
|
183
|
+
return createHash('sha256').update(data).digest('hex');
|
|
184
|
+
}
|
|
185
|
+
function verifyEd25519(publicKey, message, signatureHex) {
|
|
186
|
+
return cryptoVerify(null, Buffer.from(message), publicKey, Buffer.from(signatureHex, 'hex'));
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=verify-export.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-export.js","sourceRoot":"","sources":["../../src/verify/verify-export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,IAAI,YAAY,EAAkB,MAAM,aAAa,CAAC;AAmFlG,MAAM,OAAO,GAAG,SAAS,CAAC;AAC1B,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC,CAAC;AACjE,MAAM,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;AAEtD,MAAM,UAAU,YAAY,CAC1B,UA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