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.
- package/LICENSE +201 -0
- package/NOTICE +8 -0
- package/README.md +205 -2
- package/dist/audit.d.ts +235 -0
- package/dist/audit.js +316 -0
- package/dist/delegate-sdjwt.d.ts +83 -0
- package/dist/delegate-sdjwt.js +306 -0
- package/dist/encoding.d.ts +8 -0
- package/dist/encoding.js +25 -0
- package/dist/experimental.d.ts +15 -0
- package/dist/experimental.js +17 -0
- package/dist/http/errors.d.ts +86 -0
- package/dist/http/errors.js +108 -0
- package/dist/http/gateway.d.ts +185 -0
- package/dist/http/gateway.js +607 -0
- package/dist/http/node.d.ts +66 -0
- package/dist/http/node.js +264 -0
- package/dist/http/status-service.d.ts +141 -0
- package/dist/http/status-service.js +330 -0
- package/dist/http/target.d.ts +15 -0
- package/dist/http/target.js +53 -0
- package/dist/http/transport.d.ts +45 -0
- package/dist/http/transport.js +107 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +36 -0
- package/dist/invocation.d.ts +29 -0
- package/dist/invocation.js +39 -0
- package/dist/keys.d.ts +7 -0
- package/dist/keys.js +7 -0
- package/dist/legal.d.ts +128 -0
- package/dist/legal.js +293 -0
- package/dist/mandate.d.ts +55 -0
- package/dist/mandate.js +79 -0
- package/dist/mcp.d.ts +62 -0
- package/dist/mcp.js +139 -0
- package/dist/openid4vp.d.ts +108 -0
- package/dist/openid4vp.js +231 -0
- package/dist/policy-export.d.ts +130 -0
- package/dist/policy-export.js +180 -0
- package/dist/presentation.d.ts +56 -0
- package/dist/presentation.js +166 -0
- package/dist/principal.d.ts +52 -0
- package/dist/principal.js +76 -0
- package/dist/registry.d.ts +64 -0
- package/dist/registry.js +63 -0
- package/dist/root.d.ts +177 -0
- package/dist/root.js +481 -0
- package/dist/scope.d.ts +31 -0
- package/dist/scope.js +262 -0
- package/dist/signer.d.ts +42 -0
- package/dist/signer.js +99 -0
- package/dist/status.d.ts +125 -0
- package/dist/status.js +243 -0
- package/dist/stores/common.d.ts +113 -0
- package/dist/stores/common.js +234 -0
- package/dist/stores/index.d.ts +3 -0
- package/dist/stores/index.js +3 -0
- package/dist/stores/postgres.d.ts +160 -0
- package/dist/stores/postgres.js +521 -0
- package/dist/stores/redis.d.ts +132 -0
- package/dist/stores/redis.js +406 -0
- package/dist/testing.d.ts +266 -0
- package/dist/testing.js +614 -0
- package/dist/trust.d.ts +84 -0
- package/dist/trust.js +250 -0
- package/dist/trustlist.d.ts +162 -0
- package/dist/trustlist.js +433 -0
- package/dist/ts12.d.ts +126 -0
- package/dist/ts12.js +409 -0
- package/dist/types.d.ts +201 -0
- package/dist/types.js +9 -0
- package/dist/verify.d.ts +105 -0
- package/dist/verify.js +392 -0
- package/dist/x509-revocation.d.ts +139 -0
- package/dist/x509-revocation.js +692 -0
- package/package.json +98 -4
- package/src/stores/schema.sql +196 -0
package/dist/audit.js
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
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 { signCompactJwt } from './signer.js';
|
|
10
|
+
import { open, readFile } from 'node:fs/promises';
|
|
11
|
+
import { importJWK, jwtVerify } from 'jose';
|
|
12
|
+
import { canonicalize, sha256 } from './encoding.js';
|
|
13
|
+
import { principalIdentity } from './principal.js';
|
|
14
|
+
export const AUDIT_RECORD_VERSION = 1;
|
|
15
|
+
export const AUDIT_SIGNATURE_TYP = 'plenipo-audit+jwt';
|
|
16
|
+
/** `prev` of the first record of a log. */
|
|
17
|
+
export const AUDIT_GENESIS = 'A'.repeat(43);
|
|
18
|
+
export class InMemoryAuditStore {
|
|
19
|
+
records = [];
|
|
20
|
+
async last() {
|
|
21
|
+
return this.records[this.records.length - 1];
|
|
22
|
+
}
|
|
23
|
+
async append(record) {
|
|
24
|
+
this.records.push(structuredClone(record));
|
|
25
|
+
}
|
|
26
|
+
async readAll() {
|
|
27
|
+
return structuredClone(this.records);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* One JSON record per line. With `fsync` each append is flushed to stable storage before it resolves,
|
|
32
|
+
* which is what an audit trail used in disputes should have; without it a crash may lose the latest records.
|
|
33
|
+
*/
|
|
34
|
+
export class JsonlFileAuditStore {
|
|
35
|
+
path;
|
|
36
|
+
opts;
|
|
37
|
+
constructor(path, opts = {}) {
|
|
38
|
+
this.path = path;
|
|
39
|
+
this.opts = opts;
|
|
40
|
+
}
|
|
41
|
+
async lines() {
|
|
42
|
+
let text;
|
|
43
|
+
try {
|
|
44
|
+
text = await readFile(this.path, 'utf8');
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
if (e.code === 'ENOENT')
|
|
48
|
+
return [];
|
|
49
|
+
throw e;
|
|
50
|
+
}
|
|
51
|
+
const lines = text.split('\n');
|
|
52
|
+
// A file written by this store ends with a newline; anything after the last one is a torn write.
|
|
53
|
+
if (lines[lines.length - 1] !== '')
|
|
54
|
+
throw new Error('audit file ends with an incomplete record');
|
|
55
|
+
lines.pop();
|
|
56
|
+
return lines;
|
|
57
|
+
}
|
|
58
|
+
async last() {
|
|
59
|
+
const lines = await this.lines();
|
|
60
|
+
return lines.length ? JSON.parse(lines[lines.length - 1]) : undefined;
|
|
61
|
+
}
|
|
62
|
+
async append(record) {
|
|
63
|
+
const fh = await open(this.path, 'a', 0o600);
|
|
64
|
+
try {
|
|
65
|
+
await fh.appendFile(JSON.stringify(record) + '\n', 'utf8');
|
|
66
|
+
if (this.opts.fsync)
|
|
67
|
+
await fh.sync();
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
await fh.close();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async readAll() {
|
|
74
|
+
return (await this.lines()).map((l) => JSON.parse(l));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const DEFAULT_PRINCIPAL_CLAIMS = ['given_name', 'family_name'];
|
|
78
|
+
const MAX_DETAIL = 512;
|
|
79
|
+
const MAX_STRING = 64 * 1024;
|
|
80
|
+
/** Invocation claims kept in ALLOW records; anything else the agent put in the payload is left out. */
|
|
81
|
+
const INVOCATION_CLAIMS = ['mandate', 'action', 'counterparty', 'amount', 'aud', 'nonce', 'iat', 'args_hash', 'chain_hash'];
|
|
82
|
+
function knownInvocationClaims(inv) {
|
|
83
|
+
const out = {};
|
|
84
|
+
for (const k of INVOCATION_CLAIMS) {
|
|
85
|
+
const v = inv[k];
|
|
86
|
+
if (v === undefined)
|
|
87
|
+
continue;
|
|
88
|
+
if (k === 'amount') {
|
|
89
|
+
const a = v;
|
|
90
|
+
if (a && typeof a === 'object')
|
|
91
|
+
out.amount = { value: a.value, currency: a.currency };
|
|
92
|
+
}
|
|
93
|
+
else if (typeof v === 'string' || typeof v === 'number')
|
|
94
|
+
out[k] = v;
|
|
95
|
+
}
|
|
96
|
+
return out;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Makes a value safe for RFC 8785 canonicalisation and bounded in size: lone surrogates become U+FFFD,
|
|
100
|
+
* long strings are cut, non-finite numbers become null, and anything that is not JSON is dropped.
|
|
101
|
+
*/
|
|
102
|
+
const LONE_SURROGATE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g;
|
|
103
|
+
const wellFormed = (s) => s.replace(LONE_SURROGATE, '\uFFFD');
|
|
104
|
+
export function sanitizeForAudit(value, depth = 0) {
|
|
105
|
+
if (depth > 16)
|
|
106
|
+
return null;
|
|
107
|
+
if (typeof value === 'string') {
|
|
108
|
+
const s = value.length > MAX_STRING ? value.slice(0, MAX_STRING) : value;
|
|
109
|
+
return wellFormed(s);
|
|
110
|
+
}
|
|
111
|
+
if (typeof value === 'number')
|
|
112
|
+
return Number.isFinite(value) ? value : null;
|
|
113
|
+
if (typeof value === 'boolean' || value === null)
|
|
114
|
+
return value;
|
|
115
|
+
if (Array.isArray(value))
|
|
116
|
+
return value.map((v) => (v === undefined ? null : sanitizeForAudit(v, depth + 1)));
|
|
117
|
+
if (typeof value === 'object') {
|
|
118
|
+
const out = {};
|
|
119
|
+
for (const [k, v] of Object.entries(value)) {
|
|
120
|
+
if (v === undefined || typeof v === 'function' || typeof v === 'symbol' || typeof v === 'bigint')
|
|
121
|
+
continue;
|
|
122
|
+
out[wellFormed(k)] = sanitizeForAudit(v, depth + 1);
|
|
123
|
+
}
|
|
124
|
+
return out;
|
|
125
|
+
}
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
128
|
+
function stripUndefined(o) {
|
|
129
|
+
return Object.fromEntries(Object.entries(o).filter(([, v]) => v !== undefined));
|
|
130
|
+
}
|
|
131
|
+
/** The hash of a record: SHA-256 of its RFC 8785 canonical form without `hash` and `sig`. */
|
|
132
|
+
export function auditRecordHash(record) {
|
|
133
|
+
const { hash: _h, sig: _s, ...rest } = record;
|
|
134
|
+
return sha256(canonicalize(rest));
|
|
135
|
+
}
|
|
136
|
+
/** Writes audit records. Appends are serialised, so concurrent requests cannot fork the chain. */
|
|
137
|
+
export class AuditLog {
|
|
138
|
+
opts;
|
|
139
|
+
queue = Promise.resolve();
|
|
140
|
+
head;
|
|
141
|
+
constructor(opts) {
|
|
142
|
+
this.opts = opts;
|
|
143
|
+
if (!opts?.store)
|
|
144
|
+
throw new Error('AuditLog needs a store');
|
|
145
|
+
const every = opts.signer?.every;
|
|
146
|
+
if (every !== undefined && (!Number.isSafeInteger(every) || every < 1))
|
|
147
|
+
throw new Error('signer.every must be a positive integer');
|
|
148
|
+
}
|
|
149
|
+
/** Appends a record. Rejects when the store fails. */
|
|
150
|
+
append(entry, opts = {}) {
|
|
151
|
+
const run = this.queue.then(() => this.write(entry, opts.forceSign ?? false));
|
|
152
|
+
this.queue = run.catch(() => undefined);
|
|
153
|
+
return run;
|
|
154
|
+
}
|
|
155
|
+
async write(entry, forceSign) {
|
|
156
|
+
try {
|
|
157
|
+
if (!this.head) {
|
|
158
|
+
const last = await this.opts.store.last();
|
|
159
|
+
this.head = last ? { seq: last.seq, hash: last.hash } : { seq: -1, hash: AUDIT_GENESIS };
|
|
160
|
+
}
|
|
161
|
+
// Every value is made canonicalisable first: an agent-chosen string with a lone surrogate, or a
|
|
162
|
+
// non-finite number, must not make a decision unrecordable.
|
|
163
|
+
const body = stripUndefined({
|
|
164
|
+
...sanitizeForAudit(entry),
|
|
165
|
+
v: AUDIT_RECORD_VERSION,
|
|
166
|
+
seq: this.head.seq + 1,
|
|
167
|
+
ts: (this.opts.now?.() ?? new Date()).toISOString(),
|
|
168
|
+
prev: this.head.hash,
|
|
169
|
+
});
|
|
170
|
+
const hash = auditRecordHash(body);
|
|
171
|
+
const record = { ...body, hash };
|
|
172
|
+
const s = this.opts.signer;
|
|
173
|
+
if (s && (forceSign || (record.seq + 1) % (s.every ?? 1) === 0)) {
|
|
174
|
+
record.sig = await signCompactJwt({ seq: record.seq, hash }, { alg: s.alg ?? 'ES256', typ: AUDIT_SIGNATURE_TYP, ...(s.kid ? { kid: s.kid } : {}) }, s.key);
|
|
175
|
+
}
|
|
176
|
+
await this.opts.store.append(record);
|
|
177
|
+
this.head = { seq: record.seq, hash };
|
|
178
|
+
return record;
|
|
179
|
+
}
|
|
180
|
+
catch (e) {
|
|
181
|
+
// The store may or may not hold the record now; re-read its head before the next append, so the chain
|
|
182
|
+
// never forks. A torn JSONL line makes `last()` throw, and the log stays closed until it is repaired.
|
|
183
|
+
this.head = undefined;
|
|
184
|
+
throw e;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/** Appends a signed checkpoint record, e.g. on a timer or at shutdown. Needs a signer. */
|
|
188
|
+
checkpoint(context) {
|
|
189
|
+
if (!this.opts.signer)
|
|
190
|
+
return Promise.reject(new Error('checkpoints need a signer'));
|
|
191
|
+
return this.append({ event: 'checkpoint', ...(context ? { context } : {}) }, { forceSign: true });
|
|
192
|
+
}
|
|
193
|
+
/** Records a decision, applying the configured redaction. */
|
|
194
|
+
recordDecision(input) {
|
|
195
|
+
return this.append(this.decisionEntry(input));
|
|
196
|
+
}
|
|
197
|
+
/** Records whether a reservation was committed or released after the action. */
|
|
198
|
+
recordSettlement(input) {
|
|
199
|
+
return this.append({
|
|
200
|
+
event: 'settlement',
|
|
201
|
+
settlement: input.settlement,
|
|
202
|
+
reservation: input.reservation,
|
|
203
|
+
invocation_hash: input.invocation ? sha256(input.invocation) : undefined,
|
|
204
|
+
http: input.http,
|
|
205
|
+
reason: input.reason,
|
|
206
|
+
context: input.context,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
decisionEntry(input) {
|
|
210
|
+
const r = this.opts.redaction ?? {};
|
|
211
|
+
const d = input.decision;
|
|
212
|
+
const evidence = r.evidence ?? 'invocation';
|
|
213
|
+
const base = {
|
|
214
|
+
event: 'decision',
|
|
215
|
+
decision: d?.decision ?? 'DENY',
|
|
216
|
+
problem: input.problem,
|
|
217
|
+
invocation_hash: input.invocation ? sha256(input.invocation) : undefined,
|
|
218
|
+
mandate_ids: d ? d.path.map((p) => p.mandate_id) : input.mandateIds,
|
|
219
|
+
http: input.http,
|
|
220
|
+
context: input.context,
|
|
221
|
+
};
|
|
222
|
+
if (!d || d.decision === 'DENY') {
|
|
223
|
+
const detail = d?.decision === 'DENY' && (r.includeDetail ?? true) && d.detail !== undefined ? d.detail.slice(0, MAX_DETAIL) : undefined;
|
|
224
|
+
return stripUndefined({ ...base, code: d?.code, reason: d?.reason ?? input.reason, detail });
|
|
225
|
+
}
|
|
226
|
+
const keep = r.principalClaims ?? DEFAULT_PRINCIPAL_CLAIMS;
|
|
227
|
+
const identity = principalIdentity(d, { principalClaims: keep, idClaims: r.principalIdClaims });
|
|
228
|
+
// A legal person is recorded by its EUID, name and role, and the representative by the kept PID claims.
|
|
229
|
+
const principal = identity.type === 'legal_person'
|
|
230
|
+
? {
|
|
231
|
+
type: 'legal_person',
|
|
232
|
+
euid: identity.euid,
|
|
233
|
+
...(identity.legal_name !== null ? { legal_name: identity.legal_name } : {}),
|
|
234
|
+
role: identity.role,
|
|
235
|
+
representative: identity.representative.claims,
|
|
236
|
+
}
|
|
237
|
+
: identity.claims;
|
|
238
|
+
const ev = evidence === 'none' || !input.invocation
|
|
239
|
+
? undefined
|
|
240
|
+
: { invocation: input.invocation, ...(evidence === 'full' && input.chain ? { chain: input.chain } : {}) };
|
|
241
|
+
return stripUndefined({
|
|
242
|
+
...base,
|
|
243
|
+
invocation: knownInvocationClaims(d.invocation),
|
|
244
|
+
principal,
|
|
245
|
+
principal_id: identity.type === 'legal_person' ? identity.representative.id : identity.id,
|
|
246
|
+
pid_issuer: d.pid_issuer,
|
|
247
|
+
reservation: d.reservation,
|
|
248
|
+
evidence: ev,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Checks a sequence of records: version, consecutive sequence numbers, the hash link to the previous record,
|
|
254
|
+
* each record's own hash, and signatures when a key is given. Detects edits, deletions, insertions and
|
|
255
|
+
* reordering anywhere but at the tail. Removal of trailing records is detected only with `expectedHead`: a
|
|
256
|
+
* signed head proves the records up to it were written by the key holder, not that none followed.
|
|
257
|
+
*/
|
|
258
|
+
export async function verifyAuditLog(records, opts = {}) {
|
|
259
|
+
const require = opts.requireSignatures ?? (opts.key ? 'all' : 'none');
|
|
260
|
+
if (require !== 'none' && !opts.key)
|
|
261
|
+
return { valid: false, index: -1, error: 'signatures are required but no key was given' };
|
|
262
|
+
const key = opts.key && 'kty' in opts.key ? await importJWK(opts.key, opts.alg ?? 'ES256') : opts.key;
|
|
263
|
+
let prevSeq = opts.anchor ? opts.anchor.seq : -1;
|
|
264
|
+
let prevHash = opts.anchor ? opts.anchor.hash : AUDIT_GENESIS;
|
|
265
|
+
let signedThrough;
|
|
266
|
+
for (let i = 0; i < records.length; i++) {
|
|
267
|
+
const r = records[i];
|
|
268
|
+
const bad = (error) => ({ valid: false, index: i, error });
|
|
269
|
+
if (typeof r !== 'object' || r === null || r.v !== AUDIT_RECORD_VERSION)
|
|
270
|
+
return bad('unknown record version');
|
|
271
|
+
if (!Number.isSafeInteger(r.seq) || typeof r.hash !== 'string' || typeof r.prev !== 'string')
|
|
272
|
+
return bad('record is malformed');
|
|
273
|
+
if (r.seq !== prevSeq + 1)
|
|
274
|
+
return bad(`sequence ${r.seq} follows ${prevSeq}: records are missing or out of order`);
|
|
275
|
+
if (r.prev !== prevHash)
|
|
276
|
+
return bad('record does not link to the previous record');
|
|
277
|
+
let recomputed;
|
|
278
|
+
try {
|
|
279
|
+
recomputed = auditRecordHash(r);
|
|
280
|
+
}
|
|
281
|
+
catch {
|
|
282
|
+
return bad('record cannot be canonicalised');
|
|
283
|
+
}
|
|
284
|
+
if (recomputed !== r.hash)
|
|
285
|
+
return bad('record hash does not match its content');
|
|
286
|
+
if (r.sig !== undefined && key) {
|
|
287
|
+
try {
|
|
288
|
+
const { payload } = await jwtVerify(r.sig, key, { typ: AUDIT_SIGNATURE_TYP, algorithms: [opts.alg ?? 'ES256'] });
|
|
289
|
+
if (payload.seq !== r.seq || payload.hash !== r.hash)
|
|
290
|
+
return bad('signature covers another record');
|
|
291
|
+
}
|
|
292
|
+
catch {
|
|
293
|
+
return bad('record signature is not valid');
|
|
294
|
+
}
|
|
295
|
+
signedThrough = r.seq;
|
|
296
|
+
}
|
|
297
|
+
else if (require === 'all') {
|
|
298
|
+
return bad('record is not signed');
|
|
299
|
+
}
|
|
300
|
+
prevSeq = r.seq;
|
|
301
|
+
prevHash = r.hash;
|
|
302
|
+
}
|
|
303
|
+
if (require === 'head' && records.length && signedThrough !== records[records.length - 1].seq) {
|
|
304
|
+
return { valid: false, index: records.length - 1, error: 'the last record is not signed' };
|
|
305
|
+
}
|
|
306
|
+
if (opts.expectedHead && (opts.expectedHead.seq !== prevSeq || opts.expectedHead.hash !== prevHash)) {
|
|
307
|
+
return { valid: false, index: records.length, error: 'the log does not end at the expected head: records were removed or added' };
|
|
308
|
+
}
|
|
309
|
+
return {
|
|
310
|
+
valid: true,
|
|
311
|
+
count: records.length,
|
|
312
|
+
...(records.length || opts.anchor ? { head: { seq: prevSeq, hash: prevHash } } : {}),
|
|
313
|
+
...(signedThrough !== undefined ? { signedThrough } : {}),
|
|
314
|
+
...(key ? { unauthenticated: signedThrough === undefined ? records.length : prevSeq - signedThrough } : {}),
|
|
315
|
+
};
|
|
316
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sub-delegations in the Delegate SD-JWT format (draft-gco-oauth-delegate-sd-jwt-00), in a strict
|
|
3
|
+
* Plenipo profile. See docs/delegation.md for the wire format, the deviations from the draft and why
|
|
4
|
+
* selective disclosure is refused inside a delegation.
|
|
5
|
+
*/
|
|
6
|
+
import { type SigningKey } from './signer.js';
|
|
7
|
+
import { type JWK } from 'jose';
|
|
8
|
+
import type { DelegationPayload } from './types.js';
|
|
9
|
+
/** `typ` of a KB-SD-JWT+KB as registered in the draft's IANA section (A.2) and used in its section 5.1.4. */
|
|
10
|
+
export declare const DELEGATE_SDJWT_TYP = "kb+sd-jwt+kb";
|
|
11
|
+
/** Claim of the Delegate Payload that carries the child mandate, as a visible claim (draft section 8.2). */
|
|
12
|
+
export declare const PLENIPO_MANDATE_CLAIM = "plenipo_mandate";
|
|
13
|
+
/** OpenID4VP transaction data type defined in the draft's section 7.1. */
|
|
14
|
+
export declare const DELEGATE_TX_DATA_TYPE = "delegate";
|
|
15
|
+
/** Upper bound on an SD-JWT delegation, checked before any parsing. A mandate is a few hundred bytes. */
|
|
16
|
+
export declare const MAX_DELEGATION_LENGTH: number;
|
|
17
|
+
export type DelegationFormat = 'jws' | 'sd-jwt';
|
|
18
|
+
/**
|
|
19
|
+
* Raised when an SD-JWT delegation fails. The code is the DenyCode the verifier reports; `message`
|
|
20
|
+
* is safe to return to a caller, `detail` may contain library messages and is for logs only.
|
|
21
|
+
*/
|
|
22
|
+
export declare class DelegationError extends Error {
|
|
23
|
+
readonly code: 'DELEGATION_SIGNATURE_INVALID' | 'MALFORMED';
|
|
24
|
+
readonly detail?: string | undefined;
|
|
25
|
+
constructor(code: 'DELEGATION_SIGNATURE_INVALID' | 'MALFORMED', message: string, detail?: string | undefined);
|
|
26
|
+
}
|
|
27
|
+
/** A delegation decoded without verification. */
|
|
28
|
+
export interface ParsedDelegation {
|
|
29
|
+
format: DelegationFormat;
|
|
30
|
+
header: Record<string, unknown>;
|
|
31
|
+
/** The delegation in the common shape, whatever the wire format. Unverified. */
|
|
32
|
+
payload: DelegationPayload;
|
|
33
|
+
/** Present for the SD-JWT format: the key the Delegate Payload binds. */
|
|
34
|
+
cnf?: unknown;
|
|
35
|
+
}
|
|
36
|
+
/** True when the token uses the Delegate SD-JWT serialization. A compact JWS never contains `~`. */
|
|
37
|
+
export declare function isSdJwtDelegation(token: unknown): token is string;
|
|
38
|
+
/**
|
|
39
|
+
* Verifies an SD-JWT delegation against the parent agent key and returns its payload. It checks the
|
|
40
|
+
* signature, the disclosure digest and the profile; parent binding, attenuation and depth are left to
|
|
41
|
+
* `verifyAuthorization`, exactly as for JWS delegations. Throws DelegationError.
|
|
42
|
+
*/
|
|
43
|
+
export declare function verifyDelegateSdJwt(token: string, parentAgentJwk: JWK): Promise<DelegationPayload>;
|
|
44
|
+
/**
|
|
45
|
+
* Detects the format of a delegation and decodes it WITHOUT verifying it, for logging and routing.
|
|
46
|
+
* Never base an authorization decision on the result. Throws on input that cannot be decoded.
|
|
47
|
+
*/
|
|
48
|
+
export declare function parseDelegation(token: string): ParsedDelegation;
|
|
49
|
+
/**
|
|
50
|
+
* Signs a delegation payload as a Delegate SD-JWT without any authority check. Callers must have
|
|
51
|
+
* validated the child against the parent; `delegateMandateSdJwt` does that and is the public entry point.
|
|
52
|
+
*/
|
|
53
|
+
export declare function issueDelegateSdJwt(payload: DelegationPayload, parentAgentKey: SigningKey): Promise<string>;
|
|
54
|
+
/** The OpenID4VP transaction data object of type `delegate` (draft section 7.1). */
|
|
55
|
+
export interface DelegateTransactionData {
|
|
56
|
+
type: typeof DELEGATE_TX_DATA_TYPE;
|
|
57
|
+
credential_ids: string[];
|
|
58
|
+
format: 'dSD-JWT' | 'dSD-JWT+KB';
|
|
59
|
+
/** Array Disclosure `[salt, Delegate Payload]`, base64url. */
|
|
60
|
+
delegate_payload_disclosure: string;
|
|
61
|
+
/** Disclosures of selectively disclosable claims inside the Delegate Payload. */
|
|
62
|
+
delegate_disclosures?: string[];
|
|
63
|
+
}
|
|
64
|
+
export interface DelegateTransactionDataInput {
|
|
65
|
+
/** DCQL credential query ids the delegation applies to. */
|
|
66
|
+
credentialIds: string[];
|
|
67
|
+
/** Claims of the Delegate Payload the wallet is asked to issue. */
|
|
68
|
+
delegatePayload: Record<string, unknown>;
|
|
69
|
+
/** Default `dSD-JWT+KB`: the delegate holds a key and proves possession. */
|
|
70
|
+
format?: 'dSD-JWT' | 'dSD-JWT+KB';
|
|
71
|
+
delegateDisclosures?: string[];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Builds the `delegate` transaction data of draft section 7.1, for a verifier that asks a wallet to issue
|
|
75
|
+
* a delegation inside an OpenID4VP presentation. Helper only: Plenipo roots still use `plenipo_mandate`.
|
|
76
|
+
* Returns the object, its base64url encoding for the request, and the digest the wallet is expected to
|
|
77
|
+
* put in the `delegate_payload` claim of its KB-SD-JWT.
|
|
78
|
+
*/
|
|
79
|
+
export declare function createDelegateTransactionData(input: DelegateTransactionDataInput): {
|
|
80
|
+
transactionData: DelegateTransactionData;
|
|
81
|
+
encoded: string;
|
|
82
|
+
delegatePayloadDigest: string;
|
|
83
|
+
};
|