plenipo 0.4.1 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -11
- package/dist/http/errors.d.ts +2 -2
- package/dist/http/errors.js +7 -2
- package/dist/http/gateway.d.ts +36 -4
- package/dist/http/gateway.js +201 -11
- package/dist/http/status-service.d.ts +6 -1
- package/dist/http/status-service.js +2 -2
- package/dist/idempotency.d.ts +128 -0
- package/dist/idempotency.js +227 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/invocation.d.ts +5 -0
- package/dist/invocation.js +9 -0
- package/dist/mcp.d.ts +15 -0
- package/dist/mcp.js +78 -6
- package/dist/root.d.ts +3 -0
- package/dist/root.js +8 -1
- package/dist/scope.js +14 -0
- package/dist/status.d.ts +23 -4
- package/dist/status.js +34 -10
- package/dist/stores/index.d.ts +2 -2
- package/dist/stores/index.js +2 -2
- package/dist/stores/postgres.d.ts +28 -1
- package/dist/stores/postgres.js +143 -2
- package/dist/stores/redis.d.ts +25 -0
- package/dist/stores/redis.js +181 -0
- package/dist/testing.js +6 -2
- package/dist/types.d.ts +26 -0
- package/dist/verify.d.ts +14 -0
- package/dist/verify.js +110 -21
- package/dist/x509-revocation.js +7 -2
- package/package.json +8 -8
- package/src/stores/schema.sql +22 -2
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Idempotency keys for invocations.
|
|
3
|
+
*
|
|
4
|
+
* An agent that does not learn the outcome of a call (a timeout, a crash of its host) cannot reuse the
|
|
5
|
+
* signed invocation: its nonce is single use and it goes stale after `maxInvocationAgeSeconds`. Without a
|
|
6
|
+
* key, the retry is a new invocation and the service runs the action twice. With a key, the agent puts the
|
|
7
|
+
* same `idem` in every attempt of one intention, each attempt still with its own nonce and `iat`, and the
|
|
8
|
+
* verifier lets at most one attempt reach the action:
|
|
9
|
+
*
|
|
10
|
+
* - the key is free: the attempt claims it and proceeds;
|
|
11
|
+
* - the key was used for a different request: `IDEMPOTENCY_CONFLICT`;
|
|
12
|
+
* - an attempt holding the key is still running: `IDEMPOTENCY_IN_PROGRESS`;
|
|
13
|
+
* - an attempt ended with an unknown outcome, or was abandoned: `IDEMPOTENCY_UNRESOLVED`, until a
|
|
14
|
+
* reconciliation (of the attempt, or of its ledger reservation) says whether it ran;
|
|
15
|
+
* - an attempt executed: `ALREADY_EXECUTED`, with the stored result when the service kept one.
|
|
16
|
+
*
|
|
17
|
+
* The key is signed inside the invocation, so nobody between the agent and the service can change it, and
|
|
18
|
+
* it is scoped to the service audience and the mandate chain, so two agents cannot collide or block each
|
|
19
|
+
* other's keys.
|
|
20
|
+
*/
|
|
21
|
+
import { randomUUID } from 'node:crypto';
|
|
22
|
+
import { canonicalize, sha256 } from './encoding.js';
|
|
23
|
+
/** Syntax of an idempotency key: 16 to 128 characters of the base64url alphabet. A UUID without dashes fits. */
|
|
24
|
+
export const IDEMPOTENCY_KEY_RE = /^[A-Za-z0-9_-]{16,128}$/;
|
|
25
|
+
/** Default bound on a stored result, in bytes of its UTF-8 text. Larger results are not kept for replay. */
|
|
26
|
+
export const DEFAULT_MAX_REPLAY_BYTES = 64 * 1024;
|
|
27
|
+
/** Hard bound a store accepts for a stored result, whatever the caller asks. */
|
|
28
|
+
export const MAX_STORED_RESULT_BYTES = 256 * 1024;
|
|
29
|
+
/**
|
|
30
|
+
* The key under which a service stores an invocation's `idem`: bound to the service audience and to the
|
|
31
|
+
* whole mandate chain, so keys of different agents, people or services never meet.
|
|
32
|
+
*/
|
|
33
|
+
export function idempotencyScope(audience, chainHashValue, idem) {
|
|
34
|
+
return sha256(canonicalize({ typ: 'plenipo-idempotency', aud: audience, chain: chainHashValue, idem }));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* What an attempt does, for comparing attempts that share a key: action, counterparty, amount and the
|
|
38
|
+
* argument hash. Nonce and `iat` are left out, since every attempt has its own.
|
|
39
|
+
*/
|
|
40
|
+
export function requestFingerprint(inv) {
|
|
41
|
+
return sha256(canonicalize({
|
|
42
|
+
action: inv.action,
|
|
43
|
+
...(inv.counterparty !== undefined ? { counterparty: inv.counterparty } : {}),
|
|
44
|
+
...(inv.amount !== undefined ? { amount: { value: inv.amount.value, currency: inv.amount.currency } } : {}),
|
|
45
|
+
...(inv.args_hash !== undefined ? { args_hash: inv.args_hash } : {}),
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
/** A fresh idempotency key for one intention of an agent: 32 characters, from a random UUID. */
|
|
49
|
+
export function newIdempotencyKey() {
|
|
50
|
+
return randomUUID().replaceAll('-', '');
|
|
51
|
+
}
|
|
52
|
+
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
53
|
+
const MAX_KEY_LENGTH = 256;
|
|
54
|
+
/** One year: a longer duration is almost certainly a unit mistake. */
|
|
55
|
+
const MAX_DURATION_SECONDS = 366 * 24 * 3600;
|
|
56
|
+
/** Input checks shared by every store: values may come from anywhere. */
|
|
57
|
+
export function validateIdempotencyKey(key) {
|
|
58
|
+
if (typeof key !== 'string' || key.length === 0 || key.length > MAX_KEY_LENGTH) {
|
|
59
|
+
throw new RangeError(`idempotency key must be a string of 1 to ${MAX_KEY_LENGTH} characters`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export function validateFingerprint(fp) {
|
|
63
|
+
if (typeof fp !== 'string' || fp.length === 0 || fp.length > MAX_KEY_LENGTH) {
|
|
64
|
+
throw new RangeError(`fingerprint must be a string of 1 to ${MAX_KEY_LENGTH} characters`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export function isAttemptId(x) {
|
|
68
|
+
return typeof x === 'string' && UUID_RE.test(x);
|
|
69
|
+
}
|
|
70
|
+
export function validateOutcome(o) {
|
|
71
|
+
if (o !== 'executed' && o !== 'not_executed' && o !== 'unknown')
|
|
72
|
+
throw new RangeError('outcome must be executed, not_executed or unknown');
|
|
73
|
+
}
|
|
74
|
+
export function validateResult(result) {
|
|
75
|
+
if (result === undefined)
|
|
76
|
+
return;
|
|
77
|
+
if (typeof result !== 'string')
|
|
78
|
+
throw new TypeError('result must be a string');
|
|
79
|
+
if (Buffer.byteLength(result, 'utf8') > MAX_STORED_RESULT_BYTES)
|
|
80
|
+
throw new RangeError(`result exceeds ${MAX_STORED_RESULT_BYTES} bytes`);
|
|
81
|
+
}
|
|
82
|
+
export function idempotencyDuration(name, value, fallback) {
|
|
83
|
+
const v = value ?? fallback;
|
|
84
|
+
if (typeof v !== 'number' || !Number.isFinite(v) || v <= 0 || v > MAX_DURATION_SECONDS) {
|
|
85
|
+
throw new RangeError(`${name} must be a number of seconds between 0 (excluded) and ${MAX_DURATION_SECONDS}`);
|
|
86
|
+
}
|
|
87
|
+
return v;
|
|
88
|
+
}
|
|
89
|
+
/** The in-memory store sweeps expired records at most this often, in milliseconds (or each retention period). */
|
|
90
|
+
const SWEEP_INTERVAL_MS = 60_000;
|
|
91
|
+
/**
|
|
92
|
+
* In-memory store for development, tests and single-process services. Operations are synchronous inside,
|
|
93
|
+
* so they are atomic within one Node.js process.
|
|
94
|
+
*/
|
|
95
|
+
export class InMemoryIdempotencyStore {
|
|
96
|
+
retentionSeconds;
|
|
97
|
+
leaseSeconds;
|
|
98
|
+
entries = new Map();
|
|
99
|
+
clock;
|
|
100
|
+
nextSweep = 0;
|
|
101
|
+
constructor(opts = {}) {
|
|
102
|
+
this.retentionSeconds = idempotencyDuration('retentionSeconds', opts.retentionSeconds, 24 * 3600);
|
|
103
|
+
this.leaseSeconds = idempotencyDuration('leaseSeconds', opts.leaseSeconds, 300);
|
|
104
|
+
this.clock = opts.now ?? Date.now;
|
|
105
|
+
}
|
|
106
|
+
/** Deletes executed and free records past their retention. Returns how many were deleted. */
|
|
107
|
+
sweep() {
|
|
108
|
+
const now = this.clock();
|
|
109
|
+
let n = 0;
|
|
110
|
+
for (const [k, e] of this.entries) {
|
|
111
|
+
if ((e.state === 'executed' || e.state === 'free') && e.until <= now) {
|
|
112
|
+
this.entries.delete(k);
|
|
113
|
+
n++;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return n;
|
|
117
|
+
}
|
|
118
|
+
/** The entry with time applied: expired records dropped, abandoned attempts turned unknown. */
|
|
119
|
+
current(key) {
|
|
120
|
+
// Amortised: records nobody touches again would otherwise stay forever.
|
|
121
|
+
const t = this.clock();
|
|
122
|
+
if (t >= this.nextSweep) {
|
|
123
|
+
this.nextSweep = t + Math.min(SWEEP_INTERVAL_MS, this.retentionSeconds * 1000);
|
|
124
|
+
this.sweep();
|
|
125
|
+
}
|
|
126
|
+
const e = this.entries.get(key);
|
|
127
|
+
if (!e)
|
|
128
|
+
return undefined;
|
|
129
|
+
const now = this.clock();
|
|
130
|
+
if ((e.state === 'executed' || e.state === 'free') && e.until <= now) {
|
|
131
|
+
this.entries.delete(key);
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
if (e.state === 'in_progress' && e.until <= now)
|
|
135
|
+
e.state = 'unknown';
|
|
136
|
+
return e;
|
|
137
|
+
}
|
|
138
|
+
view(key, e) {
|
|
139
|
+
return {
|
|
140
|
+
key,
|
|
141
|
+
fingerprint: e.fingerprint,
|
|
142
|
+
state: e.state,
|
|
143
|
+
attempt: e.attempt,
|
|
144
|
+
...(e.reservation !== undefined ? { reservation: e.reservation } : {}),
|
|
145
|
+
...(e.result !== undefined ? { result: e.result } : {}),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
async claim(key, fingerprint) {
|
|
149
|
+
validateIdempotencyKey(key);
|
|
150
|
+
validateFingerprint(fingerprint);
|
|
151
|
+
const held = this.current(key);
|
|
152
|
+
if (held && held.state !== 'free')
|
|
153
|
+
return { claimed: false, record: this.view(key, held) };
|
|
154
|
+
const attempt = randomUUID();
|
|
155
|
+
this.entries.set(key, { fingerprint, state: 'in_progress', attempt, until: this.clock() + this.leaseSeconds * 1000 });
|
|
156
|
+
return { claimed: true, attempt };
|
|
157
|
+
}
|
|
158
|
+
async attach(key, attempt, reservation) {
|
|
159
|
+
validateIdempotencyKey(key);
|
|
160
|
+
if (!isAttemptId(attempt) || typeof reservation !== 'string' || reservation.length === 0 || reservation.length > MAX_KEY_LENGTH)
|
|
161
|
+
return;
|
|
162
|
+
const e = this.current(key);
|
|
163
|
+
if (e && e.attempt === attempt && (e.state === 'in_progress' || e.state === 'unknown'))
|
|
164
|
+
e.reservation = reservation;
|
|
165
|
+
}
|
|
166
|
+
async finish(key, attempt, outcome, result) {
|
|
167
|
+
validateIdempotencyKey(key);
|
|
168
|
+
validateOutcome(outcome);
|
|
169
|
+
validateResult(result);
|
|
170
|
+
if (!isAttemptId(attempt))
|
|
171
|
+
return;
|
|
172
|
+
const e = this.current(key);
|
|
173
|
+
if (!e || e.attempt !== attempt || e.state === 'executed')
|
|
174
|
+
return;
|
|
175
|
+
const now = this.clock();
|
|
176
|
+
if (outcome === 'executed') {
|
|
177
|
+
// Also from `free`: proof that the action ran wins over an earlier "did not run".
|
|
178
|
+
e.state = 'executed';
|
|
179
|
+
if (result !== undefined)
|
|
180
|
+
e.result = result;
|
|
181
|
+
e.until = now + this.retentionSeconds * 1000;
|
|
182
|
+
}
|
|
183
|
+
else if (e.state === 'free') {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
else if (outcome === 'not_executed') {
|
|
187
|
+
e.state = 'free';
|
|
188
|
+
delete e.result;
|
|
189
|
+
e.until = now + this.retentionSeconds * 1000;
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
e.state = 'unknown';
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
async resolve(key, outcome, attempt) {
|
|
196
|
+
validateIdempotencyKey(key);
|
|
197
|
+
if (outcome !== 'executed' && outcome !== 'not_executed')
|
|
198
|
+
throw new RangeError('outcome must be executed or not_executed');
|
|
199
|
+
if (!isAttemptId(attempt))
|
|
200
|
+
throw new RangeError('resolve needs the attempt that holds the key');
|
|
201
|
+
const e = this.current(key);
|
|
202
|
+
if (!e || e.attempt !== attempt || (e.state !== 'in_progress' && e.state !== 'unknown'))
|
|
203
|
+
return false;
|
|
204
|
+
e.state = outcome === 'executed' ? 'executed' : 'free';
|
|
205
|
+
e.until = this.clock() + this.retentionSeconds * 1000;
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
async get(key) {
|
|
209
|
+
validateIdempotencyKey(key);
|
|
210
|
+
const e = this.current(key);
|
|
211
|
+
return e && e.state !== 'free' ? this.view(key, e) : undefined;
|
|
212
|
+
}
|
|
213
|
+
async unresolved(opts = {}) {
|
|
214
|
+
const limit = opts.limit ?? 100;
|
|
215
|
+
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 10_000)
|
|
216
|
+
throw new RangeError('limit must be an integer between 1 and 10000');
|
|
217
|
+
const out = [];
|
|
218
|
+
for (const key of [...this.entries.keys()]) {
|
|
219
|
+
if (out.length >= limit)
|
|
220
|
+
break;
|
|
221
|
+
const e = this.current(key);
|
|
222
|
+
if (e?.state === 'unknown')
|
|
223
|
+
out.push(this.view(key, e));
|
|
224
|
+
}
|
|
225
|
+
return out;
|
|
226
|
+
}
|
|
227
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './types.js';
|
|
2
2
|
export { createMandate, delegateMandate, encodeMandateTransactionData, nowSeconds, type MandateInput } from './mandate.js';
|
|
3
3
|
export { createInvocation, argsHash, type InvocationInput } from './invocation.js';
|
|
4
|
+
export { InMemoryIdempotencyStore, idempotencyScope, requestFingerprint, newIdempotencyKey, IDEMPOTENCY_KEY_RE, DEFAULT_MAX_REPLAY_BYTES, MAX_STORED_RESULT_BYTES, type IdempotencyStore, type IdempotencyStoreOptions, type IdempotencyRecord, type IdempotencyClaim, type IdempotencyState, type AttemptOutcome, } from './idempotency.js';
|
|
4
5
|
export { verifyAuthorization, peekInvocation, type VerifyOptions } from './verify.js';
|
|
5
6
|
export { verifyRoot, RootError, type RootResult } from './root.js';
|
|
6
7
|
export { generateAgentKey, type AgentKey } from './keys.js';
|
|
@@ -8,7 +9,7 @@ export { actionCovers, hostCovers, attenuationViolations, validateMandate, allow
|
|
|
8
9
|
export { InMemoryNonceStore, InMemoryRevocationRegistry, InMemorySpendingLedger, type NonceStore, type RevocationRegistry, type SpendingLedger, } from './registry.js';
|
|
9
10
|
export { canonicalize, mandateHash, sha256 } from './encoding.js';
|
|
10
11
|
export { resolveSigningKey, verifyX5c, TrustError, type TrustConfig, type ResolvedKey } from './trust.js';
|
|
11
|
-
export { checkStatus, StatusUnavailableError, defaultStatusFetcher, StatusListCache, StatusListPublisher, STATUS_INVALID, STATUS_SUSPENDED, STATUS_VALID, type StatusFetcher, type StatusReference, } from './status.js';
|
|
12
|
+
export { checkStatus, StatusUnavailableError, defaultStatusFetcher, StatusListCache, StatusListPublisher, DEFAULT_STATUS_TTL_SECONDS, STATUS_INVALID, STATUS_SUSPENDED, STATUS_VALID, type StatusFetcher, type StatusReference, } from './status.js';
|
|
12
13
|
export { createMandateRequest, handleMandateResponse, authorizationRequestUrl, PID_QUERY_ID, type MandateRequest, type MandateRequestOptions, type MandateRequestSession, type MandateResponseOptions, type MandateResponseResult, } from './openid4vp.js';
|
|
13
14
|
export { checkPidStatus, decodeMandateTransactionData, type RootOptions } from './root.js';
|
|
14
15
|
export { httpsOrigin, isStatusReference } from './status.js';
|
|
@@ -17,7 +18,7 @@ export * from './stores/index.js';
|
|
|
17
18
|
export { urlFromRawTarget, pathProblem, TargetError } from './http/target.js';
|
|
18
19
|
export { DENY_PROBLEMS, GATEWAY_PROBLEMS, PROBLEM_TYPE_BASE, PROBLEM_CONTENT_TYPE, problemForDecision, problemSpecForDecision, problemFromSpec, problemResponse, isDenyCode, type ProblemDetails, type ProblemSpec, type ProblemKind, type GatewayProblemCode, type ProblemResponseOptions, } from './http/errors.js';
|
|
19
20
|
export { CHAIN_HEADER, INVOCATION_HEADER, DEFAULT_MAX_CHAIN_HEADER_BYTES, DEFAULT_MAX_INVOCATION_HEADER_BYTES, authorizationHeaders, encodeChainHeader, parseAuthorizationHeaders, asMandateChain, type HeaderLimits, type ParsedAuthorization, } from './http/transport.js';
|
|
20
|
-
export { createGateway, defaultRequestArgs, jsonMediaType, hasDuplicateJsonKeys, outcomeFromHeader, OUTCOME_HEADER, DEFAULT_MAX_BODY_BYTES, type SettlementOutcome, type Gateway, type GatewayOptions, type GatewayRoute, type GatewayEvent, type GatewayRequestInfo, type RouteContext, type Downstream, type PolicyHook, type AuthorizeResult, type SettleInput, type AllowDecision, type DenyDecision, } from './http/gateway.js';
|
|
21
|
+
export { createGateway, defaultRequestArgs, jsonMediaType, hasDuplicateJsonKeys, outcomeFromHeader, OUTCOME_HEADER, REPLAY_HEADER, MAX_REPLAY_BODY_BYTES, DEFAULT_MAX_BODY_BYTES, type SettlementOutcome, type Gateway, type GatewayOptions, type GatewayRoute, type GatewayEvent, type GatewayRequestInfo, type RouteContext, type Downstream, type PolicyHook, type AuthorizeResult, type SettleInput, type ReplayResponse, type AllowDecision, type DenyDecision, } from './http/gateway.js';
|
|
21
22
|
export { toNodeListener, expressMiddleware, plenipoRoute, toFetchRequest, writeFetchResponse, type NodeAdapterOptions, type ExpressLikeRequest, type ExpressLikeNext, type ExpressLikeMiddleware, type PlenipoRequestContext, } from './http/node.js';
|
|
22
23
|
export { createStatusService, ManagedStatusList, InMemoryStatusListStore, publisherSource, STATUS_LIST_CONTENT_TYPE, type StatusService, type StatusServiceOptions, type StatusListSource, type StatusListStore, type StatusListState, type StatusValue, type StatusOperation, type SetStatusResult, type AdminOperation, type AdminAuthorizer, type ManagedStatusListOptions, } from './http/status-service.js';
|
|
23
24
|
export { AuditLog, InMemoryAuditStore, JsonlFileAuditStore, verifyAuditLog, auditRecordHash, sanitizeForAudit, AUDIT_GENESIS, AUDIT_RECORD_VERSION, AUDIT_SIGNATURE_TYP, type AuditRecord, type AuditEntry, type AuditEvent, type AuditStore, type AuditRedaction, type AuditSigner, type AuditLogOptions, type DecisionAuditInput, type AuditVerifyOptions, type AuditVerifyResult, } from './audit.js';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './types.js';
|
|
2
2
|
export { createMandate, delegateMandate, encodeMandateTransactionData, nowSeconds } from './mandate.js';
|
|
3
3
|
export { createInvocation, argsHash } from './invocation.js';
|
|
4
|
+
export { InMemoryIdempotencyStore, idempotencyScope, requestFingerprint, newIdempotencyKey, IDEMPOTENCY_KEY_RE, DEFAULT_MAX_REPLAY_BYTES, MAX_STORED_RESULT_BYTES, } from './idempotency.js';
|
|
4
5
|
export { verifyAuthorization, peekInvocation } from './verify.js';
|
|
5
6
|
export { verifyRoot, RootError } from './root.js';
|
|
6
7
|
export { generateAgentKey } from './keys.js';
|
|
@@ -8,7 +9,7 @@ export { actionCovers, hostCovers, attenuationViolations, validateMandate, allow
|
|
|
8
9
|
export { InMemoryNonceStore, InMemoryRevocationRegistry, InMemorySpendingLedger, } from './registry.js';
|
|
9
10
|
export { canonicalize, mandateHash, sha256 } from './encoding.js';
|
|
10
11
|
export { resolveSigningKey, verifyX5c, TrustError } from './trust.js';
|
|
11
|
-
export { checkStatus, StatusUnavailableError, defaultStatusFetcher, StatusListCache, StatusListPublisher, STATUS_INVALID, STATUS_SUSPENDED, STATUS_VALID, } from './status.js';
|
|
12
|
+
export { checkStatus, StatusUnavailableError, defaultStatusFetcher, StatusListCache, StatusListPublisher, DEFAULT_STATUS_TTL_SECONDS, STATUS_INVALID, STATUS_SUSPENDED, STATUS_VALID, } from './status.js';
|
|
12
13
|
export { createMandateRequest, handleMandateResponse, authorizationRequestUrl, PID_QUERY_ID, } from './openid4vp.js';
|
|
13
14
|
export { checkPidStatus, decodeMandateTransactionData } from './root.js';
|
|
14
15
|
export { httpsOrigin, isStatusReference } from './status.js';
|
|
@@ -18,7 +19,7 @@ export * from './stores/index.js';
|
|
|
18
19
|
export { urlFromRawTarget, pathProblem, TargetError } from './http/target.js';
|
|
19
20
|
export { DENY_PROBLEMS, GATEWAY_PROBLEMS, PROBLEM_TYPE_BASE, PROBLEM_CONTENT_TYPE, problemForDecision, problemSpecForDecision, problemFromSpec, problemResponse, isDenyCode, } from './http/errors.js';
|
|
20
21
|
export { CHAIN_HEADER, INVOCATION_HEADER, DEFAULT_MAX_CHAIN_HEADER_BYTES, DEFAULT_MAX_INVOCATION_HEADER_BYTES, authorizationHeaders, encodeChainHeader, parseAuthorizationHeaders, asMandateChain, } from './http/transport.js';
|
|
21
|
-
export { createGateway, defaultRequestArgs, jsonMediaType, hasDuplicateJsonKeys, outcomeFromHeader, OUTCOME_HEADER, DEFAULT_MAX_BODY_BYTES, } from './http/gateway.js';
|
|
22
|
+
export { createGateway, defaultRequestArgs, jsonMediaType, hasDuplicateJsonKeys, outcomeFromHeader, OUTCOME_HEADER, REPLAY_HEADER, MAX_REPLAY_BODY_BYTES, DEFAULT_MAX_BODY_BYTES, } from './http/gateway.js';
|
|
22
23
|
export { toNodeListener, expressMiddleware, plenipoRoute, toFetchRequest, writeFetchResponse, } from './http/node.js';
|
|
23
24
|
export { createStatusService, ManagedStatusList, InMemoryStatusListStore, publisherSource, STATUS_LIST_CONTENT_TYPE, } from './http/status-service.js';
|
|
24
25
|
export { AuditLog, InMemoryAuditStore, JsonlFileAuditStore, verifyAuditLog, auditRecordHash, sanitizeForAudit, AUDIT_GENESIS, AUDIT_RECORD_VERSION, AUDIT_SIGNATURE_TYP, } from './audit.js';
|
package/dist/invocation.d.ts
CHANGED
|
@@ -17,6 +17,11 @@ export interface InvocationInput {
|
|
|
17
17
|
* cannot be replayed with another chain that happens to end in a mandate with the same id.
|
|
18
18
|
*/
|
|
19
19
|
chain: MandateChain;
|
|
20
|
+
/**
|
|
21
|
+
* Idempotency key: the same value for every attempt of one intention (a retry after a timeout, a restart).
|
|
22
|
+
* Requires `args`. Only send it to a service that keeps idempotency keys: one that does not refuses it.
|
|
23
|
+
*/
|
|
24
|
+
idempotencyKey?: string;
|
|
20
25
|
}
|
|
21
26
|
export declare function argsHash(args: unknown): string;
|
|
22
27
|
/**
|
package/dist/invocation.js
CHANGED
|
@@ -3,6 +3,7 @@ import { signCompactJwt } from './signer.js';
|
|
|
3
3
|
import { canonicalize, sha256 } from './encoding.js';
|
|
4
4
|
import { INVOCATION_TYP } from './types.js';
|
|
5
5
|
import { nowSeconds } from './mandate.js';
|
|
6
|
+
import { IDEMPOTENCY_KEY_RE } from './idempotency.js';
|
|
6
7
|
export function argsHash(args) {
|
|
7
8
|
return sha256(canonicalize(args ?? {}));
|
|
8
9
|
}
|
|
@@ -24,6 +25,13 @@ export function chainHash(chain) {
|
|
|
24
25
|
export async function createInvocation(agentKey, input) {
|
|
25
26
|
if (!input.chain || typeof input.chain !== 'object')
|
|
26
27
|
throw new Error('createInvocation needs the chain it is presented with');
|
|
28
|
+
if (input.idempotencyKey !== undefined) {
|
|
29
|
+
if (typeof input.idempotencyKey !== 'string' || !IDEMPOTENCY_KEY_RE.test(input.idempotencyKey)) {
|
|
30
|
+
throw new Error('idempotencyKey must be 16 to 128 base64url characters');
|
|
31
|
+
}
|
|
32
|
+
if (input.args === undefined)
|
|
33
|
+
throw new Error('idempotencyKey requires args, so that the key covers the operation');
|
|
34
|
+
}
|
|
27
35
|
const payload = {
|
|
28
36
|
mandate: input.mandateId,
|
|
29
37
|
action: input.action,
|
|
@@ -34,6 +42,7 @@ export async function createInvocation(agentKey, input) {
|
|
|
34
42
|
iat: nowSeconds(),
|
|
35
43
|
...(input.args !== undefined ? { args_hash: argsHash(input.args) } : {}),
|
|
36
44
|
chain_hash: chainHash(input.chain),
|
|
45
|
+
...(input.idempotencyKey !== undefined ? { idem: input.idempotencyKey } : {}),
|
|
37
46
|
};
|
|
38
47
|
return signCompactJwt(payload, { alg: 'ES256', typ: INVOCATION_TYP }, agentKey);
|
|
39
48
|
}
|
package/dist/mcp.d.ts
CHANGED
|
@@ -9,6 +9,11 @@ export declare const META_KEY = "plenipo/authorization";
|
|
|
9
9
|
*/
|
|
10
10
|
export declare const OUTCOME_META_KEY = "plenipo/outcome";
|
|
11
11
|
export type ToolOutcome = 'executed' | 'not-executed' | 'unknown';
|
|
12
|
+
/**
|
|
13
|
+
* Key set to `true` in the `_meta` of a result that is the stored answer of an earlier attempt with the same
|
|
14
|
+
* idempotency key, returned instead of running the tool again.
|
|
15
|
+
*/
|
|
16
|
+
export declare const REPLAY_META_KEY = "plenipo/replay";
|
|
12
17
|
export interface PlenipoMeta {
|
|
13
18
|
chain: MandateChain;
|
|
14
19
|
invocation: string;
|
|
@@ -32,6 +37,12 @@ export interface GuardOptions<Args> extends Omit<VerifyOptions, 'expected' | 'no
|
|
|
32
37
|
* released: an action whose authorization could not be recorded does not run.
|
|
33
38
|
*/
|
|
34
39
|
onDecision?: (decision: Decision, args: Args) => void;
|
|
40
|
+
/**
|
|
41
|
+
* Largest result kept for idempotent replays, in bytes of its JSON text. Default 65536. A larger result
|
|
42
|
+
* is not kept: a retry then learns that the call already executed, without its result. `0` keeps none.
|
|
43
|
+
* Stored results live in the idempotency store; keep personal data out of tool results you would not store.
|
|
44
|
+
*/
|
|
45
|
+
maxReplayBytes?: number;
|
|
35
46
|
}
|
|
36
47
|
type ToolResult = {
|
|
37
48
|
content: Array<{
|
|
@@ -57,6 +68,10 @@ type Handler<Args> = (args: Args, extra: Extra, decision: AllowDecision) => Tool
|
|
|
57
68
|
* `_meta['plenipo/outcome']`: committed when `executed`, released when `not-executed`, left pending when
|
|
58
69
|
* `unknown`. Without a stated outcome a success commits and an `isError` result stays pending, because an
|
|
59
70
|
* error reported after the action ran must not give the amount back. A throw also leaves it pending.
|
|
71
|
+
*
|
|
72
|
+
* With an idempotency store in the options, an invocation that carries `idem` runs at most once per key: a
|
|
73
|
+
* retry of an executed call gets that call's stored result (marked with `_meta['plenipo/replay']`), and a
|
|
74
|
+
* retry while the first outcome is unknown is refused until the service reconciles it.
|
|
60
75
|
*/
|
|
61
76
|
export declare function guardTool<Args>(handler: Handler<Args>, opts: GuardOptions<Args>): (args: Args, extra: Extra) => Promise<ToolResult>;
|
|
62
77
|
export { argsHash };
|
package/dist/mcp.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { argsHash } from './invocation.js';
|
|
2
|
+
import { DEFAULT_MAX_REPLAY_BYTES, MAX_STORED_RESULT_BYTES } from './idempotency.js';
|
|
2
3
|
import { verifyAuthorization } from './verify.js';
|
|
3
4
|
/** Key under which a client puts the authorization in the MCP request `_meta`. */
|
|
4
5
|
export const META_KEY = 'plenipo/authorization';
|
|
@@ -7,6 +8,11 @@ export const META_KEY = 'plenipo/authorization';
|
|
|
7
8
|
* `not-executed` or `unknown`. The guard settles the reservation from it and strips it from the result.
|
|
8
9
|
*/
|
|
9
10
|
export const OUTCOME_META_KEY = 'plenipo/outcome';
|
|
11
|
+
/**
|
|
12
|
+
* Key set to `true` in the `_meta` of a result that is the stored answer of an earlier attempt with the same
|
|
13
|
+
* idempotency key, returned instead of running the tool again.
|
|
14
|
+
*/
|
|
15
|
+
export const REPLAY_META_KEY = 'plenipo/replay';
|
|
10
16
|
function denied(code, reason) {
|
|
11
17
|
return {
|
|
12
18
|
isError: true,
|
|
@@ -14,6 +20,32 @@ function denied(code, reason) {
|
|
|
14
20
|
structuredContent: { plenipo: { decision: 'DENY', code, reason } },
|
|
15
21
|
};
|
|
16
22
|
}
|
|
23
|
+
/** The stored result of an earlier attempt, or a plain notice when none was kept. */
|
|
24
|
+
function replayed(replay) {
|
|
25
|
+
if (replay?.result !== undefined) {
|
|
26
|
+
try {
|
|
27
|
+
const r = JSON.parse(replay.result);
|
|
28
|
+
if (r && typeof r === 'object' && Array.isArray(r.content))
|
|
29
|
+
return { ...r, _meta: { ...(r._meta ?? {}), [REPLAY_META_KEY]: true } };
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
/* not a stored tool result: fall through */
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return denied('ALREADY_EXECUTED', 'an earlier attempt with this idempotency key already executed; its result was not kept');
|
|
36
|
+
}
|
|
37
|
+
function storedResult(result, max) {
|
|
38
|
+
if (max <= 0)
|
|
39
|
+
return undefined;
|
|
40
|
+
try {
|
|
41
|
+
const text = JSON.stringify(result);
|
|
42
|
+
return text !== undefined && Buffer.byteLength(text, 'utf8') <= max ? text : undefined;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const ATTEMPT_OUTCOME = { executed: 'executed', 'not-executed': 'not_executed', unknown: 'unknown' };
|
|
17
49
|
function validAmount(a) {
|
|
18
50
|
if (typeof a !== 'object' || a === null)
|
|
19
51
|
return false;
|
|
@@ -57,9 +89,13 @@ function deriveExpected(opts, args) {
|
|
|
57
89
|
* `_meta['plenipo/outcome']`: committed when `executed`, released when `not-executed`, left pending when
|
|
58
90
|
* `unknown`. Without a stated outcome a success commits and an `isError` result stays pending, because an
|
|
59
91
|
* error reported after the action ran must not give the amount back. A throw also leaves it pending.
|
|
92
|
+
*
|
|
93
|
+
* With an idempotency store in the options, an invocation that carries `idem` runs at most once per key: a
|
|
94
|
+
* retry of an executed call gets that call's stored result (marked with `_meta['plenipo/replay']`), and a
|
|
95
|
+
* retry while the first outcome is unknown is refused until the service reconciles it.
|
|
60
96
|
*/
|
|
61
97
|
export function guardTool(handler, opts) {
|
|
62
|
-
const { action, counterparty, amount, onDecision, now: clock, ...verifyOpts } = opts;
|
|
98
|
+
const { action, counterparty, amount, onDecision, now: clock, maxReplayBytes, ...verifyOpts } = opts;
|
|
63
99
|
// Fail at wiring time: a guard that forgot to say how it reads the counterparty or amount would
|
|
64
100
|
// otherwise trust whatever the agent declares.
|
|
65
101
|
if (counterparty === undefined || amount === undefined) {
|
|
@@ -68,10 +104,32 @@ export function guardTool(handler, opts) {
|
|
|
68
104
|
if ((counterparty !== null && typeof counterparty !== 'function') || (amount !== null && typeof amount !== 'function')) {
|
|
69
105
|
throw new Error('guardTool counterparty and amount must be functions or null');
|
|
70
106
|
}
|
|
107
|
+
const maxReplay = maxReplayBytes ?? DEFAULT_MAX_REPLAY_BYTES;
|
|
108
|
+
if (!Number.isSafeInteger(maxReplay) || maxReplay < 0 || maxReplay > MAX_STORED_RESULT_BYTES) {
|
|
109
|
+
throw new Error(`guardTool maxReplayBytes must be an integer from 0 to ${MAX_STORED_RESULT_BYTES}, what a store accepts`);
|
|
110
|
+
}
|
|
71
111
|
const ledger = verifyOpts.ledger;
|
|
72
|
-
const
|
|
112
|
+
const store = verifyOpts.idempotency;
|
|
113
|
+
/** Ends the attempt holding the idempotency key. A store that fails leaves it in progress, then unresolved: safe side. */
|
|
114
|
+
const finish = async (decision, outcome, result) => {
|
|
115
|
+
if (decision.decision !== 'ALLOW' || !decision.idempotency || !store)
|
|
116
|
+
return;
|
|
117
|
+
const { key, attempt } = decision.idempotency;
|
|
118
|
+
try {
|
|
119
|
+
await store.finish(key, attempt, outcome, result);
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
// A store that refuses the result (too large for it) must still learn that the call ran.
|
|
123
|
+
if (result !== undefined)
|
|
124
|
+
await store.finish(key, attempt, outcome).catch(() => undefined);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
/** Before the handler runs, the action certainly has not happened: give back the reservation and the key. */
|
|
128
|
+
const abandon = async (decision) => {
|
|
129
|
+
const reservation = decision.decision === 'ALLOW' ? decision.reservation : undefined;
|
|
73
130
|
if (reservation && ledger)
|
|
74
131
|
await ledger.release(reservation);
|
|
132
|
+
await finish(decision, 'not_executed');
|
|
75
133
|
};
|
|
76
134
|
return async (args, extra) => {
|
|
77
135
|
const meta = (extra?._meta ?? {})[META_KEY];
|
|
@@ -92,22 +150,36 @@ export function guardTool(handler, opts) {
|
|
|
92
150
|
onDecision?.(decision, args);
|
|
93
151
|
}
|
|
94
152
|
catch {
|
|
95
|
-
await
|
|
153
|
+
await abandon(decision);
|
|
96
154
|
return denied('INTERNAL', 'the decision could not be recorded');
|
|
97
155
|
}
|
|
98
|
-
if (decision.decision === 'DENY')
|
|
156
|
+
if (decision.decision === 'DENY') {
|
|
157
|
+
// A retry of a call that already ran gets the stored answer of that call, and the tool does not run.
|
|
158
|
+
if (decision.code === 'ALREADY_EXECUTED')
|
|
159
|
+
return replayed(decision.replay);
|
|
99
160
|
return denied(decision.code, decision.reason);
|
|
161
|
+
}
|
|
100
162
|
// A tool without a counterparty or amount must not run an invocation that names one: the mandate
|
|
101
163
|
// would have been checked against a value the call does not carry.
|
|
102
164
|
if ((counterparty === null && decision.invocation.counterparty !== undefined) || (amount === null && decision.invocation.amount !== undefined)) {
|
|
103
|
-
await
|
|
165
|
+
await abandon(decision);
|
|
104
166
|
return denied('INVOCATION_MISMATCH', 'invocation declares a counterparty or amount that this tool does not carry');
|
|
105
167
|
}
|
|
106
168
|
// Settlement: release only when the tool states the action certainly did not run. A pending reservation
|
|
107
169
|
// counts as spent in a shared ledger's sweep until it is reconciled, so limits fail safe. A throw is an
|
|
108
170
|
// unknown outcome and leaves the reservation pending.
|
|
109
|
-
|
|
171
|
+
// The idempotency key follows the same rule: a throw is an unknown outcome and blocks the key until
|
|
172
|
+
// reconciled, so a retry cannot run the action a second time.
|
|
173
|
+
let raw;
|
|
174
|
+
try {
|
|
175
|
+
raw = await handler(args, extra, decision);
|
|
176
|
+
}
|
|
177
|
+
catch (e) {
|
|
178
|
+
await finish(decision, 'unknown');
|
|
179
|
+
throw e;
|
|
180
|
+
}
|
|
110
181
|
const { result, outcome } = takeOutcome(raw);
|
|
182
|
+
await finish(decision, ATTEMPT_OUTCOME[outcome], outcome === 'executed' ? storedResult(result, maxReplay) : undefined);
|
|
111
183
|
if (reservation && ledger) {
|
|
112
184
|
if (outcome === 'executed')
|
|
113
185
|
await ledger.commit(reservation);
|
package/dist/root.d.ts
CHANGED
|
@@ -137,6 +137,8 @@ export interface RootOptions extends TrustConfig {
|
|
|
137
137
|
pidStatusTrust?: TrustConfig;
|
|
138
138
|
statusFetcher?: StatusFetcher;
|
|
139
139
|
statusCache?: StatusListCache;
|
|
140
|
+
/** Maximum age of a cached status list for this verification; see `VerifyOptions.maxStatusAgeSeconds`. */
|
|
141
|
+
maxStatusAgeSeconds?: number;
|
|
140
142
|
/** How TS12 e-mandate roots are accepted. */
|
|
141
143
|
emandate?: EmandateVerifyOptions;
|
|
142
144
|
/** How representation attestations are accepted; required for mandates on behalf of a legal person. */
|
|
@@ -172,6 +174,7 @@ export declare function checkAttestationStatus(d: DeferredStatus, opts: {
|
|
|
172
174
|
now: number;
|
|
173
175
|
statusFetcher?: StatusFetcher;
|
|
174
176
|
statusCache?: StatusListCache;
|
|
177
|
+
maxStatusAgeSeconds?: number;
|
|
175
178
|
}): Promise<void>;
|
|
176
179
|
/** Checks the status of a PID issued by `pidIss`. Throws RootError PID_REVOKED unless it is valid. */
|
|
177
180
|
export declare function checkPidStatus(ref: StatusReference, pidIss: string, opts: RootOptions): Promise<void>;
|
package/dist/root.js
CHANGED
|
@@ -443,6 +443,7 @@ export async function checkAttestationStatus(d, opts) {
|
|
|
443
443
|
fetcher: opts.statusFetcher,
|
|
444
444
|
now: opts.now,
|
|
445
445
|
cache: opts.statusCache,
|
|
446
|
+
...(opts.maxStatusAgeSeconds !== undefined ? { maxAgeSeconds: opts.maxStatusAgeSeconds } : {}),
|
|
446
447
|
});
|
|
447
448
|
}
|
|
448
449
|
catch (e) {
|
|
@@ -471,7 +472,13 @@ export async function checkPidStatus(ref, pidIss, opts) {
|
|
|
471
472
|
: { trust: opts, signer: pidIss, allowedOrigins: [httpsOrigin(pidIss)].filter((o) => !!o) };
|
|
472
473
|
let status;
|
|
473
474
|
try {
|
|
474
|
-
status = await checkStatus(ref, {
|
|
475
|
+
status = await checkStatus(ref, {
|
|
476
|
+
...check,
|
|
477
|
+
fetcher: opts.statusFetcher,
|
|
478
|
+
now: opts.now,
|
|
479
|
+
cache: opts.statusCache,
|
|
480
|
+
...(opts.maxStatusAgeSeconds !== undefined ? { maxAgeSeconds: opts.maxStatusAgeSeconds } : {}),
|
|
481
|
+
});
|
|
475
482
|
}
|
|
476
483
|
catch (e) {
|
|
477
484
|
throw new RootError(e instanceof StatusUnavailableError ? 'STATUS_UNAVAILABLE' : 'PID_REVOKED', 'PID status could not be verified', e.message);
|
package/dist/scope.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { MANDATE_VERSION } from './types.js';
|
|
2
2
|
import { isStatusReference } from './status.js';
|
|
3
|
+
import { IDEMPOTENCY_KEY_RE } from './idempotency.js';
|
|
3
4
|
const ACTION_RE = /^(\*|[a-z0-9_-]+(\.[a-z0-9_-]+)*(\.\*)?)$/;
|
|
4
5
|
const CONCRETE_ACTION_RE = /^[a-z0-9_-]+(\.[a-z0-9_-]+)*$/;
|
|
5
6
|
const HOST_RE = /^(\*\.)?([a-z0-9-]+\.)*[a-z0-9-]+$/;
|
|
@@ -154,8 +155,21 @@ export function validateInvocationPayload(p) {
|
|
|
154
155
|
e.push('iat must be an integer');
|
|
155
156
|
if (x.args_hash !== undefined && typeof x.args_hash !== 'string')
|
|
156
157
|
e.push('args_hash must be a string');
|
|
158
|
+
if (x.idem !== undefined) {
|
|
159
|
+
if (typeof x.idem !== 'string' || !IDEMPOTENCY_KEY_RE.test(x.idem))
|
|
160
|
+
e.push('idem must be 16 to 128 base64url characters');
|
|
161
|
+
// A key that does not cover the arguments could pair a retry with a different operation.
|
|
162
|
+
if (x.args_hash === undefined)
|
|
163
|
+
e.push('idem requires args_hash');
|
|
164
|
+
}
|
|
165
|
+
// As for mandates and delegations: a member this verifier does not know could be a constraint it would ignore.
|
|
166
|
+
const extra = Object.keys(x).filter((k) => !INVOCATION_MEMBERS.has(k));
|
|
167
|
+
if (extra.length)
|
|
168
|
+
e.push(`unknown member ${extra.join(', ')}`);
|
|
157
169
|
return e;
|
|
158
170
|
}
|
|
171
|
+
/** Members an invocation may carry. */
|
|
172
|
+
const INVOCATION_MEMBERS = new Set(['mandate', 'action', 'counterparty', 'amount', 'aud', 'nonce', 'iat', 'args_hash', 'chain_hash', 'idem']);
|
|
159
173
|
function validateLimits(l) {
|
|
160
174
|
const e = [];
|
|
161
175
|
if (typeof l !== 'object' || l === null)
|
package/dist/status.d.ts
CHANGED
|
@@ -14,9 +14,19 @@ export interface StatusReference {
|
|
|
14
14
|
/**
|
|
15
15
|
* Fetches a status list token. The default fetcher uses HTTPS only, refuses redirects, stops after
|
|
16
16
|
* 5 seconds and reads at most 1 MB. A custom fetcher must keep the same guarantees.
|
|
17
|
+
*
|
|
18
|
+
* `maxAgeSeconds` is set when the caller needs a list no older than that (see `VerifyOptions.maxStatusAgeSeconds`):
|
|
19
|
+
* the default fetcher sends it as `Cache-Control: max-age`, so HTTP caches on the way revalidate older copies.
|
|
17
20
|
*/
|
|
18
|
-
export type StatusFetcher = (uri: string
|
|
21
|
+
export type StatusFetcher = (uri: string, opts?: {
|
|
22
|
+
maxAgeSeconds?: number;
|
|
23
|
+
}) => Promise<string>;
|
|
19
24
|
export declare const defaultStatusFetcher: StatusFetcher;
|
|
25
|
+
/**
|
|
26
|
+
* Default `ttl` of the status lists this library publishes, in seconds. Verifiers and HTTP caches may keep a
|
|
27
|
+
* list that long, so it is how long a revocation can go unnoticed; it matches the default `StatusListCache`.
|
|
28
|
+
*/
|
|
29
|
+
export declare const DEFAULT_STATUS_TTL_SECONDS = 60;
|
|
20
30
|
export declare const STATUS_VALID = 0;
|
|
21
31
|
export declare const STATUS_INVALID = 1;
|
|
22
32
|
export declare const STATUS_SUSPENDED = 2;
|
|
@@ -36,6 +46,11 @@ export interface StatusCheckOptions {
|
|
|
36
46
|
now: number;
|
|
37
47
|
/** Optional cache shared across verifications. */
|
|
38
48
|
cache?: StatusListCache;
|
|
49
|
+
/**
|
|
50
|
+
* When set, a cached list obtained more than this many seconds ago is not used, and the fetcher is asked
|
|
51
|
+
* for a copy no older than that. `0` always fetches.
|
|
52
|
+
*/
|
|
53
|
+
maxAgeSeconds?: number;
|
|
39
54
|
/**
|
|
40
55
|
* Largest status list accepted once inflated, in bytes. Default `DEFAULT_MAX_STATUS_LIST_BYTES` (1 MiB:
|
|
41
56
|
* 4 194 304 entries at 2 bits, 8 388 608 at 1 bit). A token is at most 1 MB, but DEFLATE compresses a
|
|
@@ -69,8 +84,12 @@ export declare class StatusListCache {
|
|
|
69
84
|
private readonly maxAgeSeconds;
|
|
70
85
|
private readonly entries;
|
|
71
86
|
constructor(maxAgeSeconds?: number);
|
|
72
|
-
|
|
73
|
-
|
|
87
|
+
/**
|
|
88
|
+
* The cached list, unless it expired or, with `maxAgeSeconds`, was obtained more than that many seconds
|
|
89
|
+
* before `now`. This is what bounds how long a revocation can go unnoticed.
|
|
90
|
+
*/
|
|
91
|
+
get(key: string, now: number, maxAgeSeconds?: number): DecodedStatusList | undefined;
|
|
92
|
+
set(key: string, list: DecodedStatusList, until: number, fetchedAt?: number): void;
|
|
74
93
|
get maxAge(): number;
|
|
75
94
|
}
|
|
76
95
|
/** The origin of an https URL, or undefined. */
|
|
@@ -107,7 +126,7 @@ export declare class StatusListPublisher {
|
|
|
107
126
|
x5c?: string[];
|
|
108
127
|
/** Token lifetime in seconds. Default 1 hour. */
|
|
109
128
|
lifetimeSeconds?: number;
|
|
110
|
-
/** Hint for verifier caches, in seconds. Default
|
|
129
|
+
/** Hint for verifier and HTTP caches, in seconds: how long a revocation may go unnoticed. Default 60. */
|
|
111
130
|
ttlSeconds?: number;
|
|
112
131
|
});
|
|
113
132
|
get uri(): string;
|