plenipo 0.0.0-stage → 0.4.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.
Files changed (77) hide show
  1. package/LICENSE +201 -0
  2. package/NOTICE +8 -0
  3. package/README.md +205 -2
  4. package/dist/audit.d.ts +235 -0
  5. package/dist/audit.js +316 -0
  6. package/dist/delegate-sdjwt.d.ts +83 -0
  7. package/dist/delegate-sdjwt.js +306 -0
  8. package/dist/encoding.d.ts +8 -0
  9. package/dist/encoding.js +25 -0
  10. package/dist/experimental.d.ts +15 -0
  11. package/dist/experimental.js +17 -0
  12. package/dist/http/errors.d.ts +86 -0
  13. package/dist/http/errors.js +108 -0
  14. package/dist/http/gateway.d.ts +185 -0
  15. package/dist/http/gateway.js +607 -0
  16. package/dist/http/node.d.ts +66 -0
  17. package/dist/http/node.js +264 -0
  18. package/dist/http/status-service.d.ts +141 -0
  19. package/dist/http/status-service.js +330 -0
  20. package/dist/http/target.d.ts +15 -0
  21. package/dist/http/target.js +53 -0
  22. package/dist/http/transport.d.ts +45 -0
  23. package/dist/http/transport.js +107 -0
  24. package/dist/index.d.ts +33 -0
  25. package/dist/index.js +36 -0
  26. package/dist/invocation.d.ts +29 -0
  27. package/dist/invocation.js +39 -0
  28. package/dist/keys.d.ts +7 -0
  29. package/dist/keys.js +7 -0
  30. package/dist/legal.d.ts +128 -0
  31. package/dist/legal.js +293 -0
  32. package/dist/mandate.d.ts +55 -0
  33. package/dist/mandate.js +79 -0
  34. package/dist/mcp.d.ts +62 -0
  35. package/dist/mcp.js +139 -0
  36. package/dist/openid4vp.d.ts +108 -0
  37. package/dist/openid4vp.js +231 -0
  38. package/dist/policy-export.d.ts +130 -0
  39. package/dist/policy-export.js +180 -0
  40. package/dist/presentation.d.ts +56 -0
  41. package/dist/presentation.js +166 -0
  42. package/dist/principal.d.ts +52 -0
  43. package/dist/principal.js +76 -0
  44. package/dist/registry.d.ts +64 -0
  45. package/dist/registry.js +63 -0
  46. package/dist/root.d.ts +177 -0
  47. package/dist/root.js +481 -0
  48. package/dist/scope.d.ts +31 -0
  49. package/dist/scope.js +262 -0
  50. package/dist/signer.d.ts +42 -0
  51. package/dist/signer.js +99 -0
  52. package/dist/status.d.ts +125 -0
  53. package/dist/status.js +243 -0
  54. package/dist/stores/common.d.ts +113 -0
  55. package/dist/stores/common.js +234 -0
  56. package/dist/stores/index.d.ts +3 -0
  57. package/dist/stores/index.js +3 -0
  58. package/dist/stores/postgres.d.ts +160 -0
  59. package/dist/stores/postgres.js +521 -0
  60. package/dist/stores/redis.d.ts +132 -0
  61. package/dist/stores/redis.js +406 -0
  62. package/dist/testing.d.ts +266 -0
  63. package/dist/testing.js +614 -0
  64. package/dist/trust.d.ts +84 -0
  65. package/dist/trust.js +250 -0
  66. package/dist/trustlist.d.ts +162 -0
  67. package/dist/trustlist.js +433 -0
  68. package/dist/ts12.d.ts +126 -0
  69. package/dist/ts12.js +409 -0
  70. package/dist/types.d.ts +201 -0
  71. package/dist/types.js +9 -0
  72. package/dist/verify.d.ts +105 -0
  73. package/dist/verify.js +392 -0
  74. package/dist/x509-revocation.d.ts +139 -0
  75. package/dist/x509-revocation.js +692 -0
  76. package/package.json +98 -4
  77. package/src/stores/schema.sql +196 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Fabio Lalli
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,8 @@
1
+ Plenipo
2
+ Copyright 2026 Fabio Lalli and the Plenipo contributors
3
+
4
+ This product is licensed under the Apache License, Version 2.0 (see LICENSE).
5
+
6
+ It depends on third-party packages distributed through npm under their own licenses (MIT, ISC,
7
+ Apache-2.0, BSD-2-Clause, BSD-3-Clause, 0BSD, Zlib). Those packages are not included in this
8
+ repository or in the published package; they are installed separately by npm.
package/README.md CHANGED
@@ -1,3 +1,206 @@
1
- # Temporary Holding Version
1
+ # Plenipo
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![CI](https://github.com/plenipo-net/plenipo/actions/workflows/ci.yml/badge.svg)](https://github.com/plenipo-net/plenipo/actions/workflows/ci.yml)
4
+ [![npm](https://img.shields.io/npm/v/plenipo)](https://www.npmjs.com/package/plenipo)
5
+ [![License](https://img.shields.io/badge/license-Apache%202.0-blue)](LICENSE)
6
+
7
+ **Mandates, not full powers.** Plenipo lets a person authorise an AI agent from their
8
+ European Digital Identity Wallet, and lets any service check that authority before the
9
+ agent acts.
10
+
11
+ A plenipotentiary is an envoy who acts for someone and presents credentials to prove it.
12
+ Plenipo gives AI agents the same thing, with one difference: the powers are never full.
13
+ Every mandate has a scope, limits and an expiry, every sub-delegation can only narrow it,
14
+ and the person can revoke it at any time.
15
+
16
+ > Status: 0.4.0, experimental. The cryptography is real; wallets, PID providers and banks in
17
+ > the examples and the sandbox are test doubles. The code went through two rounds of security review
18
+ > by independent AI review agents, and their findings are fixed (see [CHANGELOG.md](CHANGELOG.md)); it
19
+ > has not yet been audited by an external security firm. Do not use it to protect real money or real
20
+ > data yet.
21
+
22
+ ## Why
23
+
24
+ AI agents are starting to book, buy and sign on our behalf. Card networks and US startups
25
+ are building their own agent registries, and they answer the question *which software
26
+ acted*. They do not answer *who stands behind it, and with what authority*.
27
+
28
+ In Europe that answer already exists: by the end of 2026 every Member State must offer an
29
+ EUDI Wallet holding a government-issued PID. Plenipo uses it as the root of trust, so a
30
+ mandate is signed by the same wallet that people use to identify themselves, with no new
31
+ identity and no new keys.
32
+
33
+ ## How it works
34
+
35
+ ```
36
+ Person's EUDI Wallet Agent Sub-agent Service (MCP tool)
37
+ ──────────────────── ───── ───────── ──────────────────
38
+ approves the mandate ──root──▶ holds mandate ──delegates──▶ narrower mandate
39
+ (PID + key binding over signs invocation ──▶ verifies chain,
40
+ the mandate hash) limits, revocation
41
+ ALLOW / DENY
42
+ ```
43
+
44
+ 1. **Root.** The agent platform asks the wallet for a PID presentation with the mandate as
45
+ OpenID4VP transaction data. The wallet shows the mandate; on approval its key binding
46
+ JWT carries the hash of exactly that mandate. Experimental extensions let the mandate travel
47
+ as the TS12 `urn:eudi:sca:emandate:1` type that certified EUDI wallets render, and let a
48
+ representative give a mandate on behalf of a company within the powers of their role.
49
+ 2. **Delegation.** An agent can pass a narrower mandate to a sub-agent, signed with its own
50
+ key. The verifier enforces that actions, counterparties, limits, validity and depth only
51
+ shrink.
52
+ 3. **Invocation.** The acting agent signs what it is about to do: action, counterparty,
53
+ amount, audience, nonce and a hash of the call arguments.
54
+ 4. **Verification.** The service gets ALLOW or DENY with a machine-readable code, the full
55
+ path of authority and only the PID claims the person chose to disclose.
56
+
57
+ The wire formats and verification rules are specified in [docs/spec.md](docs/spec.md), with
58
+ [test vectors](test-vectors/plenipo-0.1.json) for other implementations. The reasons behind them are
59
+ in [docs/design.md](docs/design.md).
60
+
61
+ ## Install
62
+
63
+ ```bash
64
+ npm install plenipo
65
+ ```
66
+
67
+ Node 22 or later. ES modules only.
68
+
69
+ ## Try it
70
+
71
+ From a clone of this repository:
72
+
73
+ ```bash
74
+ npm ci
75
+ npm test # forged delegations, x5c, CRL/OCSP, status lists, OpenID4VP, TS12, shared stores, test vectors
76
+ # (Postgres and Redis tests run when the servers are available, and skip otherwise)
77
+ npm run demo # OpenID4VP approval, agent, sub-agent, a rail operator's MCP server
78
+ npm run example:gateway # a bank's HTTP API behind the Plenipo gateway
79
+
80
+ cd sandbox && docker compose up --build # a bank, a wallet, an agent platform and a live dashboard
81
+ ```
82
+
83
+ The [sandbox](sandbox/README.md) also runs with Node, has 17 scripted scenarios and an MCP bridge
84
+ that lets Claude Desktop or Claude Code act as the agent. More in [examples/](examples/README.md).
85
+
86
+ The demo prints:
87
+
88
+ ```
89
+ Booking bot: Roma-Milano 18 Oct, 89.00 euro
90
+ rail.example: ALLOW, acting for Mario Rossi, chain depth 1
91
+ Booking bot: Milano-Roma 20 Oct, first class, 120.00 euro
92
+ rail.example: DENY LIMIT_PER_OPERATION, amount 12000 exceeds 10000 on mandate 1
93
+ ...
94
+ The person revokes the mandate; the platform flips its entry in the status list.
95
+ rail.example: DENY REVOKED, mandate 0 is revoked in its status list
96
+ ```
97
+
98
+ ## Use it
99
+
100
+ ```ts
101
+ import { createMandate, delegateMandate, createInvocation, verifyAuthorization, generateAgentKey } from 'plenipo';
102
+
103
+ const agent = await generateAgentKey();
104
+ const mandate = createMandate({
105
+ agentJwk: agent.publicJwk,
106
+ actions: ['travel.*'],
107
+ counterparties: ['*.rail.example'],
108
+ limits: { currency: 'EUR', per_operation: 15000, total: 30000 },
109
+ ttlSeconds: 7 * 24 * 3600,
110
+ maxDepth: 1,
111
+ });
112
+
113
+ // The wallet approves `encodeMandateTransactionData(mandate)` and returns the root.
114
+ const chain = { root, delegations: [] };
115
+
116
+ const invocation = await createInvocation(agent.privateKey, {
117
+ chain, // the invocation signs the hash of the chain it is presented with
118
+ mandateId: mandate.id, action: 'travel.book', counterparty: 'www.rail.example',
119
+ amount: { value: 8900, currency: 'EUR' }, aud: 'mcp://rail.example',
120
+ });
121
+
122
+ const decision = await verifyAuthorization(chain, invocation, {
123
+ trustAnchors, // CA certificates from the PID provider trusted lists
124
+ mandateStatusTrust, // who signs the mandate status lists
125
+ audience: 'mcp://rail.example',
126
+ nonces, // single-use nonce store, mandatory
127
+ ledger, // atomic spending reservations, needed for total limits
128
+ expected: { action: 'travel.book', counterparty: 'www.rail.example', amount: { value: 8900, currency: 'EUR' } },
129
+ });
130
+ // On ALLOW, commit decision.reservation after acting, or release it if you do not act.
131
+ ```
132
+
133
+ To get the root from a real wallet, `createMandateRequest` builds the OpenID4VP request
134
+ (DCQL for the PID, the mandate as transaction data, encrypted response) and
135
+ `handleMandateResponse` turns the wallet's answer into the root. See
136
+ [docs/interop.md](docs/interop.md) for what wallets need to support.
137
+
138
+ On an MCP server, wrap a tool with `guardTool` from `plenipo/mcp`. The client sends the chain
139
+ and the invocation in the request `_meta` under `plenipo/authorization`. The guard must say how
140
+ it reads the counterparty and the amount from the tool arguments, or pass `null` when the tool
141
+ has none; it never trusts what the agent declares on its own:
142
+
143
+ ```ts
144
+ const bookTrain = guardTool<{ route: string; price_cents: number }>(handler, {
145
+ action: 'travel.book',
146
+ counterparty: () => 'www.rail.example',
147
+ amount: (a) => ({ value: a.price_cents, currency: 'EUR' }),
148
+ trustAnchors, audience: 'mcp://rail.example', nonces, ledger,
149
+ });
150
+ ```
151
+
152
+ ## What is in the box
153
+
154
+ | Area | Module | Docs |
155
+ | --- | --- | --- |
156
+ | Mandates, delegation, invocations, verification | `plenipo` | [spec](docs/spec.md), [design](docs/design.md) |
157
+ | Wallet leg: OpenID4VP | `plenipo` | [interop](docs/interop.md) |
158
+ | Experimental: Delegate SD-JWT links, TS12 e-mandate roots, legal persons and roles | `plenipo/experimental` | [delegation](docs/delegation.md), [root](docs/root.md) |
159
+ | Trust: x5c chains, EU Lists of Trusted Entities (ETSI TS 119 602), CRL and OCSP | `plenipo` | [trust](docs/trust.md) |
160
+ | Keys in a KMS or HSM (`ExternalSigner`) | `plenipo` | this README |
161
+ | Shared stores on Postgres and Redis: ledger, nonces, sessions, revocation | `plenipo` | [stores](docs/stores.md) |
162
+ | Bank integration: HTTP gateway, problem+json errors, status list service, audit log, OPA and Cedar export | `plenipo` | [integration](docs/integration.md) |
163
+ | MCP guard | `plenipo/mcp` | [design](docs/design.md) |
164
+ | Test PID provider, wallet and CA (development only) | `plenipo/testing` | [examples](examples/README.md) |
165
+ | Sandbox and walt.id setup | `sandbox/` | [sandbox](docs/sandbox.md), [sandbox/README](sandbox/README.md) |
166
+
167
+ ## Where it sits
168
+
169
+ | Project | What it does | Difference |
170
+ | --- | --- | --- |
171
+ | IETF Delegate SD-JWT (Google draft) | delegation chains for SD-JWT | no attenuation, revocation or required expiry; Plenipo enforces all three |
172
+ | Mastercard Verifiable Intent | layered SD-JWT mandates for commerce | anchored to card issuers; Plenipo is anchored to the EUDI Wallet PID |
173
+ | KYA Brasil | agent mandates signed with ICP-Brasil certificates | same idea on Brazil's PKI; Plenipo targets eIDAS 2 |
174
+ | Wallet4Agent (Talao) | identity and credential wallet for agents | gives agents a wallet; Plenipo gives people a way to authorise agents |
175
+
176
+ Plenipo aims to stay compatible with these formats rather than add another one.
177
+
178
+ ## Roadmap
179
+
180
+ See [ROADMAP.md](ROADMAP.md). Changes by version are in [CHANGELOG.md](CHANGELOG.md).
181
+
182
+ ## Limits
183
+
184
+ - Nothing has run against a real wallet yet. walt.id accepts custom transaction data types by
185
+ configuration (setup in `sandbox/level2`); the EUDI reference wallet core declares accepted types
186
+ since release 0.31.0; IT-Wallet does not accept custom types.
187
+ - With TS12, the e-mandate is approved with a bank's SCA attestation, not the PID. Tying that
188
+ attestation to the PID holder needs the same holder key or identity claims the bank includes;
189
+ see [docs/root.md](docs/root.md).
190
+ - The legal-person model (role attestations from a register) is Plenipo's own, pending the
191
+ European Business Wallet implementing acts.
192
+ - Trusted lists: only the JSON (JAdES compact) binding of ETSI TS 119 602 is verified; XML lists
193
+ (the EU LOTL and national TSLs) are refused.
194
+ - Delegate SD-JWT follows individual draft -00, which expired on 23 October 2026 without a
195
+ successor; it is experimental and off by default.
196
+ - Status lists are cached up to a bounded age, which is the revocation latency verifiers accept.
197
+
198
+ ## Contributing and security
199
+
200
+ Contributions are welcome: read [CONTRIBUTING.md](CONTRIBUTING.md). Report vulnerabilities privately as
201
+ described in [SECURITY.md](SECURITY.md), not in public issues.
202
+
203
+ ## License
204
+
205
+ Apache 2.0, see [LICENSE](LICENSE) and [NOTICE](NOTICE). Copyright 2026 Fabio Lalli and the Plenipo
206
+ contributors.
@@ -0,0 +1,235 @@
1
+ /**
2
+ * Append-only, hash-chained audit log of authorization decisions, for disputes and supervisory audits.
3
+ *
4
+ * Every record carries the hash of the previous one, so editing, deleting or reordering a record breaks
5
+ * the chain. Records can be signed one by one or at checkpoints; a signature on record n vouches for every
6
+ * record up to n. Truncating the tail is only detectable against a head kept elsewhere (`expectedHead`):
7
+ * a log cut back to an earlier signed record still verifies, signatures included.
8
+ */
9
+ import { type SigningKey } from './signer.js';
10
+ import { type CryptoKey, type JWK } from 'jose';
11
+ import type { Decision, MandateChain } from './types.js';
12
+ export declare const AUDIT_RECORD_VERSION = 1;
13
+ export declare const AUDIT_SIGNATURE_TYP = "plenipo-audit+jwt";
14
+ /** `prev` of the first record of a log. */
15
+ export declare const AUDIT_GENESIS: string;
16
+ export type AuditEvent = 'decision' | 'settlement' | 'status_change' | 'checkpoint';
17
+ export interface AuditRecord {
18
+ v: typeof AUDIT_RECORD_VERSION;
19
+ seq: number;
20
+ /** ISO 8601 time the record was written. */
21
+ ts: string;
22
+ /** Hash of the previous record, or AUDIT_GENESIS. */
23
+ prev: string;
24
+ event: AuditEvent;
25
+ decision?: 'ALLOW' | 'DENY';
26
+ /** DenyCode from the verifier, when it produced the decision. */
27
+ code?: string;
28
+ /** Problem code sent to the caller, for denials. */
29
+ problem?: string;
30
+ /** Internal reason; never sent to callers, kept here for investigations. */
31
+ reason?: string;
32
+ /** Internal detail (network errors etc.), when `includeDetail` is on. */
33
+ detail?: string;
34
+ /** Mandate ids from the root (index 0) to the deepest mandate verified. */
35
+ mandate_ids?: string[];
36
+ /** SHA-256 (base64url) of the compact invocation JWS. */
37
+ invocation_hash?: string;
38
+ /** The verified invocation claims (ALLOW only). */
39
+ invocation?: Record<string, unknown>;
40
+ /**
41
+ * Minimised principal (ALLOW only): the kept PID claims for a natural person; for a legal person
42
+ * `{ type: 'legal_person', euid, legal_name?, role, representative: <kept PID claims> }`.
43
+ */
44
+ principal?: Record<string, unknown>;
45
+ /** Stable, non-readable identifier of the natural person who approved (see src/principal.ts). */
46
+ principal_id?: string;
47
+ pid_issuer?: string;
48
+ reservation?: string;
49
+ /**
50
+ * `commit` and `release` are final. `pending` means the outcome of the action is not known (API error,
51
+ * timeout, client gone): the reservation stays pending until it is reconciled or swept as spent.
52
+ */
53
+ settlement?: 'commit' | 'release' | 'pending';
54
+ http?: {
55
+ method?: string;
56
+ path?: string;
57
+ status?: number;
58
+ };
59
+ /** Free-form, JSON-serialisable context from the integrator. */
60
+ context?: Record<string, unknown>;
61
+ /** Evidence, when configured: the compact invocation and/or the full chain. */
62
+ evidence?: {
63
+ invocation?: string;
64
+ chain?: MandateChain;
65
+ };
66
+ /** SHA-256 (base64url) of the canonical record without `hash` and `sig`. */
67
+ hash: string;
68
+ /** Compact JWS over `{ seq, hash }`, present on signed records. */
69
+ sig?: string;
70
+ }
71
+ /** What callers provide; the log fills in v, seq, ts, prev, hash and sig. */
72
+ export type AuditEntry = Omit<AuditRecord, 'v' | 'seq' | 'ts' | 'prev' | 'hash' | 'sig'>;
73
+ /** Persistence for audit records. A store has exactly one writer: the AuditLog that owns it. */
74
+ export interface AuditStore {
75
+ /** The last record, so a restarted log continues the chain. */
76
+ last(): Promise<AuditRecord | undefined>;
77
+ /** Appends one record durably, after every record appended before it. */
78
+ append(record: AuditRecord): Promise<void>;
79
+ /** Every record, in order. */
80
+ readAll(): Promise<AuditRecord[]>;
81
+ }
82
+ export declare class InMemoryAuditStore implements AuditStore {
83
+ private readonly records;
84
+ last(): Promise<AuditRecord | undefined>;
85
+ append(record: AuditRecord): Promise<void>;
86
+ readAll(): Promise<AuditRecord[]>;
87
+ }
88
+ /**
89
+ * One JSON record per line. With `fsync` each append is flushed to stable storage before it resolves,
90
+ * which is what an audit trail used in disputes should have; without it a crash may lose the latest records.
91
+ */
92
+ export declare class JsonlFileAuditStore implements AuditStore {
93
+ readonly path: string;
94
+ private readonly opts;
95
+ constructor(path: string, opts?: {
96
+ fsync?: boolean;
97
+ });
98
+ private lines;
99
+ last(): Promise<AuditRecord | undefined>;
100
+ append(record: AuditRecord): Promise<void>;
101
+ readAll(): Promise<AuditRecord[]>;
102
+ }
103
+ export interface AuditRedaction {
104
+ /**
105
+ * PID claims kept in decision records. Default `['given_name', 'family_name']`. `'all'` keeps every
106
+ * disclosed claim; `[]` keeps none. The PID issuer is always kept.
107
+ */
108
+ principalClaims?: string[] | 'all';
109
+ /**
110
+ * Evidence kept with ALLOW decisions. `invocation` (default) keeps the compact invocation JWS, which holds
111
+ * no personal data and proves what the agent signed. `full` also keeps the mandate chain, including the PID
112
+ * presentation: use it only with a documented legal basis. `none` keeps only hashes.
113
+ */
114
+ evidence?: 'none' | 'invocation' | 'full';
115
+ /** Keep the verifier's internal `detail` (network and library errors). Default true, truncated to 512 characters. */
116
+ includeDetail?: boolean;
117
+ /** Claims that identify a person uniquely, for `principal_id`. Default `['personal_administrative_number']`. */
118
+ principalIdClaims?: string[];
119
+ }
120
+ export interface AuditSigner {
121
+ /** Private key or external signer (KMS, HSM); ES256 by default. */
122
+ key: SigningKey;
123
+ alg?: 'ES256' | 'ES384' | 'EdDSA';
124
+ kid?: string;
125
+ /** Sign every record (default), or only every n-th record. `checkpoint()` signs on demand. */
126
+ every?: number;
127
+ }
128
+ export interface AuditLogOptions {
129
+ store: AuditStore;
130
+ redaction?: AuditRedaction;
131
+ signer?: AuditSigner;
132
+ /** Clock, for tests. */
133
+ now?: () => Date;
134
+ }
135
+ export interface DecisionAuditInput {
136
+ /** The verifier's decision; absent when the request was refused before verification. */
137
+ decision?: Decision;
138
+ /** Problem code sent to the caller, for denials. */
139
+ problem?: string;
140
+ /** Internal reason when there is no decision (gateway refusals). */
141
+ reason?: string;
142
+ /** The compact invocation as presented, if any. */
143
+ invocation?: string;
144
+ chain?: MandateChain;
145
+ /** Mandate ids when there is no verifier decision to take them from. */
146
+ mandateIds?: string[];
147
+ http?: {
148
+ method?: string;
149
+ path?: string;
150
+ status?: number;
151
+ };
152
+ context?: Record<string, unknown>;
153
+ }
154
+ export declare function sanitizeForAudit(value: unknown, depth?: number): unknown;
155
+ /** The hash of a record: SHA-256 of its RFC 8785 canonical form without `hash` and `sig`. */
156
+ export declare function auditRecordHash(record: Omit<AuditRecord, 'hash' | 'sig'> & {
157
+ hash?: string;
158
+ sig?: string;
159
+ }): string;
160
+ /** Writes audit records. Appends are serialised, so concurrent requests cannot fork the chain. */
161
+ export declare class AuditLog {
162
+ private readonly opts;
163
+ private queue;
164
+ private head?;
165
+ constructor(opts: AuditLogOptions);
166
+ /** Appends a record. Rejects when the store fails. */
167
+ append(entry: AuditEntry, opts?: {
168
+ forceSign?: boolean;
169
+ }): Promise<AuditRecord>;
170
+ private write;
171
+ /** Appends a signed checkpoint record, e.g. on a timer or at shutdown. Needs a signer. */
172
+ checkpoint(context?: Record<string, unknown>): Promise<AuditRecord>;
173
+ /** Records a decision, applying the configured redaction. */
174
+ recordDecision(input: DecisionAuditInput): Promise<AuditRecord>;
175
+ /** Records whether a reservation was committed or released after the action. */
176
+ recordSettlement(input: {
177
+ reservation?: string;
178
+ settlement: 'commit' | 'release' | 'pending';
179
+ invocation?: string;
180
+ http?: {
181
+ method?: string;
182
+ path?: string;
183
+ status?: number;
184
+ };
185
+ reason?: string;
186
+ context?: Record<string, unknown>;
187
+ }): Promise<AuditRecord>;
188
+ private decisionEntry;
189
+ }
190
+ export interface AuditVerifyOptions {
191
+ /** Public key for record signatures. Without it signatures are not checked. */
192
+ key?: CryptoKey | JWK;
193
+ alg?: 'ES256' | 'ES384' | 'EdDSA';
194
+ /** The record just before the first one given, for a log that was rotated or pruned after retention. */
195
+ anchor?: {
196
+ seq: number;
197
+ hash: string;
198
+ };
199
+ /** The head kept elsewhere (a published checkpoint, a WORM store): detects truncation of the tail. */
200
+ expectedHead?: {
201
+ seq: number;
202
+ hash: string;
203
+ };
204
+ /**
205
+ * With a key, the default is `all`: every record must carry a valid signature, so a log rewritten without
206
+ * the key fails even if its hashes were recomputed. For logs written with `signer.every > 1` or
207
+ * checkpoints, use `head` after a checkpoint: the last record must be signed, and its signature covers
208
+ * every earlier record through the hash chain. `none` checks only the signatures present and reports in
209
+ * `unauthenticated` how many trailing records no signature covers. Without a key, signatures are not
210
+ * checked and `all`/`head` fail.
211
+ */
212
+ requireSignatures?: 'none' | 'all' | 'head';
213
+ }
214
+ export type AuditVerifyResult = {
215
+ valid: true;
216
+ count: number;
217
+ head?: {
218
+ seq: number;
219
+ hash: string;
220
+ };
221
+ signedThrough?: number;
222
+ /** With a key: trailing records that no valid signature covers. */
223
+ unauthenticated?: number;
224
+ } | {
225
+ valid: false;
226
+ index: number;
227
+ error: string;
228
+ };
229
+ /**
230
+ * Checks a sequence of records: version, consecutive sequence numbers, the hash link to the previous record,
231
+ * each record's own hash, and signatures when a key is given. Detects edits, deletions, insertions and
232
+ * reordering anywhere but at the tail. Removal of trailing records is detected only with `expectedHead`: a
233
+ * signed head proves the records up to it were written by the key holder, not that none followed.
234
+ */
235
+ export declare function verifyAuditLog(records: AuditRecord[], opts?: AuditVerifyOptions): Promise<AuditVerifyResult>;