@spine-event-engine/auth 2.0.0-snapshot.10
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/README.md +71 -0
- package/REFERENCE.md +94 -0
- package/dist/gateway/dynamic-subscription-creator.d.ts +52 -0
- package/dist/gateway/dynamic-subscription-creator.d.ts.map +1 -0
- package/dist/gateway/dynamic-subscription-creator.js +71 -0
- package/dist/gateway/dynamic-subscription-creator.js.map +1 -0
- package/dist/gateway/dynamic-unary-forwarder.d.ts +130 -0
- package/dist/gateway/dynamic-unary-forwarder.d.ts.map +1 -0
- package/dist/gateway/dynamic-unary-forwarder.js +185 -0
- package/dist/gateway/dynamic-unary-forwarder.js.map +1 -0
- package/dist/gateway/index.d.ts +164 -0
- package/dist/gateway/index.d.ts.map +1 -0
- package/dist/gateway/index.js +195 -0
- package/dist/gateway/index.js.map +1 -0
- package/dist/index.d.ts +433 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/dist/native/index.d.ts +182 -0
- package/dist/native/index.d.ts.map +1 -0
- package/dist/native/index.js +463 -0
- package/dist/native/index.js.map +1 -0
- package/dist/oidc/contracts.d.ts +334 -0
- package/dist/oidc/contracts.d.ts.map +1 -0
- package/dist/oidc/contracts.js +15 -0
- package/dist/oidc/contracts.js.map +1 -0
- package/dist/oidc/index.d.ts +41 -0
- package/dist/oidc/index.d.ts.map +1 -0
- package/dist/oidc/index.js +825 -0
- package/dist/oidc/index.js.map +1 -0
- package/dist/providers/index.d.ts +154 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +574 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/request/index.d.ts +10 -0
- package/dist/request/index.d.ts.map +1 -0
- package/dist/request/index.js +81 -0
- package/dist/request/index.js.map +1 -0
- package/dist/sessions/cookies.d.ts +104 -0
- package/dist/sessions/cookies.d.ts.map +1 -0
- package/dist/sessions/cookies.js +295 -0
- package/dist/sessions/cookies.js.map +1 -0
- package/dist/sessions/opaque.d.ts +163 -0
- package/dist/sessions/opaque.d.ts.map +1 -0
- package/dist/sessions/opaque.js +268 -0
- package/dist/sessions/opaque.js.map +1 -0
- package/dist/sessions/signed.d.ts +245 -0
- package/dist/sessions/signed.d.ts.map +1 -0
- package/dist/sessions/signed.js +534 -0
- package/dist/sessions/signed.js.map +1 -0
- package/dist/subscriptions/index.d.ts +463 -0
- package/dist/subscriptions/index.d.ts.map +1 -0
- package/dist/subscriptions/index.js +814 -0
- package/dist/subscriptions/index.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +36 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opaque.d.ts","sourceRoot":"","sources":["../../src/sessions/opaque.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EACV,sBAAsB,EACtB,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,eAAe,EAChB,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAGjC;;;OAGG;IACH,GAAG,IAAI,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,UAAU,CAAC;AAEjE;;GAEG;AACH,MAAM,WAAW,qBAAqB;IAGpC;;OAEG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,kBAAkB,CAAC;IAEpC;;;;OAIG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,mBAAmB,CAAC;IAE3C;;OAEG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAElC;;OAEG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAE9B;;OAEG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;CACrC;AAED;;GAEG;AACH,MAAM,MAAM,yBAAyB,GACjC;IAGE;;O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qBAA0B;IAiB/C;;;;OAIG;IACH,MAAM,CAAC,SAAS,EAAE,sBAAsB,GAAG,OAAO,CAAC,yBAAyB,CAAC;IA8B7E;;;;OAIG;IACH,OAAO,CAAC,eAAe,EAAE,iBAAiB,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC;IAQjF;;;;OAIG;IACH,MAAM,CAAC,eAAe,EAAE,iBAAiB,GAAG,OAAO,CAAC,yBAAyB,CAAC;IAsC9E;;;;OAIG;IACH,MAAM,CAAC,eAAe,EAAE,iBAAiB,GAAG,OAAO,CAAC,yBAAyB,CAAC;IAM9E;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAOtB,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,MAAM;IASd,OAAO,CAAC,MAAM;IAmBd,OAAO,CAAC,IAAI;IAQZ,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,GAAG;IAYX,OAAO,CAAC,UAAU;CAInB"}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026, CodeMatters. All rights reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
|
5
|
+
* in compliance with the License. You may obtain a copy of the License at
|
|
6
|
+
*
|
|
7
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
*
|
|
9
|
+
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
10
|
+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
11
|
+
* or implied. See the License for the specific language governing permissions and limitations under
|
|
12
|
+
* the License.
|
|
13
|
+
*/
|
|
14
|
+
import { create } from "@bufbuild/protobuf";
|
|
15
|
+
import { TimestampSchema } from "@bufbuild/protobuf/wkt";
|
|
16
|
+
import { randomBytes as nodeRandomBytes } from "node:crypto";
|
|
17
|
+
/**
|
|
18
|
+
* A bounded, terminal in-memory store of random opaque application sessions.
|
|
19
|
+
*
|
|
20
|
+
* It is intentionally process-local: applications needing durable or shared
|
|
21
|
+
* sessions provide another `SessionResolver` implementation.
|
|
22
|
+
*/
|
|
23
|
+
export class OpaqueSessions {
|
|
24
|
+
records = new Map();
|
|
25
|
+
clock;
|
|
26
|
+
random;
|
|
27
|
+
ttlMilliseconds;
|
|
28
|
+
maxSessions;
|
|
29
|
+
collisionAttempts;
|
|
30
|
+
closed = false;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a bounded in-memory session store.
|
|
33
|
+
* @param options The optional clock, entropy, lifetime, and capacity settings.
|
|
34
|
+
*/
|
|
35
|
+
constructor(options = {}) {
|
|
36
|
+
this.clock = options.clock ?? { now: Date.now };
|
|
37
|
+
this.random = options.randomBytes ?? nodeRandomBytes;
|
|
38
|
+
this.ttlMilliseconds = OpaqueSessionValues.positiveSafeInteger(options.ttlMilliseconds ?? 8 * 60 * 60 * 1_000, "ttlMilliseconds");
|
|
39
|
+
this.maxSessions = OpaqueSessionValues.positiveSafeInteger(options.maxSessions ?? 10_000, "maxSessions");
|
|
40
|
+
this.collisionAttempts = OpaqueSessionValues.positiveSafeInteger(options.collisionAttempts ?? 3, "collisionAttempts");
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Creates a new session unless the terminal or bounded store state rejects it.
|
|
44
|
+
* @param principal The authenticated principal to retain.
|
|
45
|
+
* @returns The creation outcome and, when accepted, credential and session.
|
|
46
|
+
*/
|
|
47
|
+
create(principal) {
|
|
48
|
+
if (this.isClosed())
|
|
49
|
+
return Promise.resolve({ kind: "rejected", reason: "closed" });
|
|
50
|
+
const now = this.now();
|
|
51
|
+
if (now === undefined)
|
|
52
|
+
return Promise.resolve({ kind: "rejected", reason: "clock-failure" });
|
|
53
|
+
this.sweepExpired(now);
|
|
54
|
+
if (this.records.size >= this.maxSessions)
|
|
55
|
+
return Promise.resolve({ kind: "rejected", reason: "capacity-exceeded" });
|
|
56
|
+
const id = this.nextId();
|
|
57
|
+
if (id === undefined)
|
|
58
|
+
return Promise.resolve({ kind: "rejected", reason: "entropy-exhausted" });
|
|
59
|
+
const current = this.now();
|
|
60
|
+
if (current === undefined)
|
|
61
|
+
return Promise.resolve({ kind: "rejected", reason: "clock-failure" });
|
|
62
|
+
this.sweepExpired(current);
|
|
63
|
+
if (this.isClosed())
|
|
64
|
+
return Promise.resolve({ kind: "rejected", reason: "closed" });
|
|
65
|
+
if (this.records.size >= this.maxSessions) {
|
|
66
|
+
return Promise.resolve({ kind: "rejected", reason: "capacity-exceeded" });
|
|
67
|
+
}
|
|
68
|
+
if (this.records.has(id))
|
|
69
|
+
return Promise.resolve({ kind: "rejected", reason: "entropy-exhausted" });
|
|
70
|
+
const record = this.record(principal, current);
|
|
71
|
+
if (record === undefined)
|
|
72
|
+
return Promise.resolve({ kind: "rejected", reason: "clock-failure" });
|
|
73
|
+
if (this.isClosed())
|
|
74
|
+
return Promise.resolve({ kind: "rejected", reason: "closed" });
|
|
75
|
+
this.records.set(id, record);
|
|
76
|
+
return Promise.resolve({
|
|
77
|
+
kind: "created",
|
|
78
|
+
credential: OpaqueSessionValues.credential(id),
|
|
79
|
+
session: OpaqueSessionValues.resolved(record),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Resolves one currently live cookie credential as a defensive copy.
|
|
84
|
+
* @param credentialInput The credential to resolve.
|
|
85
|
+
* @returns The live session, or undefined when it is invalid or expired.
|
|
86
|
+
*/
|
|
87
|
+
resolve(credentialInput) {
|
|
88
|
+
if (this.closed || credentialInput.kind !== "cookie")
|
|
89
|
+
return Promise.resolve(undefined);
|
|
90
|
+
const now = this.now();
|
|
91
|
+
if (now === undefined)
|
|
92
|
+
return Promise.resolve(undefined);
|
|
93
|
+
const record = this.live(credentialInput.value, now);
|
|
94
|
+
return Promise.resolve(record === undefined ? undefined : OpaqueSessionValues.resolved(record));
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Updates a live opaque credential without ever retaining both values.
|
|
98
|
+
* @param credentialInput The credential to replace.
|
|
99
|
+
* @returns The rotation outcome and, when accepted, the replacement values.
|
|
100
|
+
*/
|
|
101
|
+
rotate(credentialInput) {
|
|
102
|
+
if (this.isClosed())
|
|
103
|
+
return Promise.resolve({ kind: "rejected", reason: "closed" });
|
|
104
|
+
if (credentialInput.kind !== "cookie")
|
|
105
|
+
return Promise.resolve({ kind: "rejected", reason: "unsupported-credential" });
|
|
106
|
+
const now = this.now();
|
|
107
|
+
if (now === undefined)
|
|
108
|
+
return Promise.resolve({ kind: "rejected", reason: "clock-failure" });
|
|
109
|
+
const previous = this.records.get(credentialInput.value);
|
|
110
|
+
if (previous === undefined)
|
|
111
|
+
return Promise.resolve({ kind: "rejected", reason: "not-found" });
|
|
112
|
+
if (this.expired(previous, now)) {
|
|
113
|
+
this.records.delete(credentialInput.value);
|
|
114
|
+
return Promise.resolve({ kind: "rejected", reason: "expired" });
|
|
115
|
+
}
|
|
116
|
+
const id = this.nextId();
|
|
117
|
+
if (id === undefined)
|
|
118
|
+
return Promise.resolve({ kind: "rejected", reason: "entropy-exhausted" });
|
|
119
|
+
const current = this.now();
|
|
120
|
+
if (current === undefined)
|
|
121
|
+
return Promise.resolve({ kind: "rejected", reason: "clock-failure" });
|
|
122
|
+
if (this.isClosed())
|
|
123
|
+
return Promise.resolve({ kind: "rejected", reason: "closed" });
|
|
124
|
+
if (this.records.get(credentialInput.value) !== previous) {
|
|
125
|
+
return Promise.resolve({ kind: "rejected", reason: "not-found" });
|
|
126
|
+
}
|
|
127
|
+
if (this.expired(previous, current)) {
|
|
128
|
+
this.records.delete(credentialInput.value);
|
|
129
|
+
return Promise.resolve({ kind: "rejected", reason: "expired" });
|
|
130
|
+
}
|
|
131
|
+
if (this.records.has(id))
|
|
132
|
+
return Promise.resolve({ kind: "rejected", reason: "entropy-exhausted" });
|
|
133
|
+
const record = this.record(previous.principal, current);
|
|
134
|
+
if (record === undefined)
|
|
135
|
+
return Promise.resolve({ kind: "rejected", reason: "clock-failure" });
|
|
136
|
+
this.records.delete(credentialInput.value);
|
|
137
|
+
this.records.set(id, record);
|
|
138
|
+
return Promise.resolve({
|
|
139
|
+
kind: "rotated",
|
|
140
|
+
credential: OpaqueSessionValues.credential(id),
|
|
141
|
+
session: OpaqueSessionValues.resolved(record),
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Deletes a cookie session when present without revealing whether it existed.
|
|
146
|
+
* @param credentialInput The credential to invalidate.
|
|
147
|
+
* @returns An enumeration-safe logout acknowledgement.
|
|
148
|
+
*/
|
|
149
|
+
logout(credentialInput) {
|
|
150
|
+
if (!this.closed && credentialInput.kind === "cookie")
|
|
151
|
+
this.records.delete(credentialInput.value);
|
|
152
|
+
return Promise.resolve({ kind: "logged-out" });
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Closes the store and drops retained session identity and record references.
|
|
156
|
+
* @returns Completes after retained records are dropped.
|
|
157
|
+
*/
|
|
158
|
+
close() {
|
|
159
|
+
if (this.closed)
|
|
160
|
+
return Promise.resolve();
|
|
161
|
+
this.closed = true;
|
|
162
|
+
this.records.clear();
|
|
163
|
+
return Promise.resolve();
|
|
164
|
+
}
|
|
165
|
+
isClosed() {
|
|
166
|
+
return this.closed;
|
|
167
|
+
}
|
|
168
|
+
record(principal, now) {
|
|
169
|
+
const expiresAt = now + this.ttlMilliseconds;
|
|
170
|
+
if (!Number.isSafeInteger(expiresAt) || !OpaqueSessionValues.timestampValid(expiresAt)) {
|
|
171
|
+
this.failClosed();
|
|
172
|
+
return undefined;
|
|
173
|
+
}
|
|
174
|
+
return { principal: OpaqueSessionValues.copyPrincipal(principal), expiresAt };
|
|
175
|
+
}
|
|
176
|
+
nextId() {
|
|
177
|
+
for (let attempt = 0; attempt < this.collisionAttempts; attempt += 1) {
|
|
178
|
+
let bytes;
|
|
179
|
+
try {
|
|
180
|
+
bytes = this.random(32);
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
try {
|
|
186
|
+
if (bytes.byteLength !== 32)
|
|
187
|
+
continue;
|
|
188
|
+
const id = Buffer.from(bytes).toString("base64url");
|
|
189
|
+
if (!this.records.has(id))
|
|
190
|
+
return id;
|
|
191
|
+
}
|
|
192
|
+
finally {
|
|
193
|
+
bytes.fill(0);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return undefined;
|
|
197
|
+
}
|
|
198
|
+
live(id, now) {
|
|
199
|
+
const record = this.records.get(id);
|
|
200
|
+
if (record === undefined)
|
|
201
|
+
return undefined;
|
|
202
|
+
if (!this.expired(record, now))
|
|
203
|
+
return record;
|
|
204
|
+
this.records.delete(id);
|
|
205
|
+
return undefined;
|
|
206
|
+
}
|
|
207
|
+
sweepExpired(now) {
|
|
208
|
+
for (const [id, record] of this.records)
|
|
209
|
+
if (this.expired(record, now))
|
|
210
|
+
this.records.delete(id);
|
|
211
|
+
}
|
|
212
|
+
expired(record, now) {
|
|
213
|
+
return now >= record.expiresAt;
|
|
214
|
+
}
|
|
215
|
+
now() {
|
|
216
|
+
try {
|
|
217
|
+
const value = this.clock.now();
|
|
218
|
+
if (!Number.isSafeInteger(value) || !OpaqueSessionValues.timestampValid(value))
|
|
219
|
+
throw new Error("invalid clock");
|
|
220
|
+
return value;
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
this.failClosed();
|
|
224
|
+
return undefined;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
failClosed() {
|
|
228
|
+
this.closed = true;
|
|
229
|
+
this.records.clear();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Validates opaque-session values and creates immutable credential data.
|
|
234
|
+
*/
|
|
235
|
+
const OpaqueSessionValues = Object.freeze({
|
|
236
|
+
positiveSafeInteger(value, name) {
|
|
237
|
+
if (!Number.isSafeInteger(value) || value <= 0)
|
|
238
|
+
throw new Error(`${name} must be a positive safe integer`);
|
|
239
|
+
return value;
|
|
240
|
+
},
|
|
241
|
+
credential(value) {
|
|
242
|
+
return Object.freeze({ kind: "cookie", value });
|
|
243
|
+
},
|
|
244
|
+
copyPrincipal(principal) {
|
|
245
|
+
if (typeof principal.id !== "string")
|
|
246
|
+
throw new Error("principal.id must be a string");
|
|
247
|
+
const attributes = principal.attributes === undefined ? undefined : Object.freeze({ ...principal.attributes });
|
|
248
|
+
return Object.freeze(attributes === undefined ? { id: principal.id } : { id: principal.id, attributes });
|
|
249
|
+
},
|
|
250
|
+
resolved(record) {
|
|
251
|
+
return Object.freeze({
|
|
252
|
+
principal: OpaqueSessionValues.copyPrincipal(record.principal),
|
|
253
|
+
expiresAt: OpaqueSessionValues.timestamp(record.expiresAt),
|
|
254
|
+
});
|
|
255
|
+
},
|
|
256
|
+
timestamp(milliseconds) {
|
|
257
|
+
const seconds = Math.floor(milliseconds / 1_000);
|
|
258
|
+
return create(TimestampSchema, {
|
|
259
|
+
seconds: BigInt(seconds),
|
|
260
|
+
nanos: (milliseconds - seconds * 1_000) * 1_000_000,
|
|
261
|
+
});
|
|
262
|
+
},
|
|
263
|
+
timestampValid(milliseconds) {
|
|
264
|
+
const seconds = Math.floor(milliseconds / 1_000);
|
|
265
|
+
return seconds >= -62_135_596_800 && seconds <= 253_402_300_799;
|
|
266
|
+
},
|
|
267
|
+
});
|
|
268
|
+
//# sourceMappingURL=opaque.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"opaque.js","sourceRoot":"","sources":["../../src/sessions/opaque.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAkB,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,WAAW,IAAI,eAAe,EAAE,MAAM,aAAa,CAAC;AA0J7D;;;;;GAKG;AACH,MAAM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EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,SAAS,CAAC,EAAE,EAAE,UAAU,EAAE,CACnF,CAAC;IACJ,CAAC;IAED,QAAQ,CAAC,MAAqB;QAC5B,OAAO,MAAM,CAAC,MAAM,CAAC;YACnB,SAAS,EAAE,mBAAmB,CAAC,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC;YAC9D,SAAS,EAAE,mBAAmB,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC;SAC3D,CAAC,CAAC;IACL,CAAC;IAED,SAAS,CAAC,YAAoB;QAC5B,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,KAAK,CAAC,CAAC;QACjD,OAAO,MAAM,CAAC,eAAe,EAAE;YAC7B,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC;YACxB,KAAK,EAAE,CAAC,YAAY,GAAG,OAAO,GAAG,KAAK,CAAC,GAAG,SAAS;SACpD,CAAC,CAAC;IACL,CAAC;IAED,cAAc,CAAC,YAAoB;QACjC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,KAAK,CAAC,CAAC;QACjD,OAAO,OAAO,IAAI,CAAC,cAAc,IAAI,OAAO,IAAI,eAAe,CAAC;IAClE,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { KeyObject } from "node:crypto";
|
|
2
|
+
import { type Timestamp } from "@bufbuild/protobuf/wkt";
|
|
3
|
+
import type { AuthenticatedPrincipal, BearerCredential, RequestCredential, ResolvedSession, SessionResolver } from "../index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Clock used by signed sessions; values are Unix epoch milliseconds.
|
|
6
|
+
*/
|
|
7
|
+
export interface SignedSessionClock {
|
|
8
|
+
/**
|
|
9
|
+
* Returns a safe Unix epoch millisecond in the Protobuf Timestamp range.
|
|
10
|
+
* Invalid values and exceptions fail closed.
|
|
11
|
+
* @returns The current milliseconds.
|
|
12
|
+
*/
|
|
13
|
+
now(): number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Creates 16 random bytes for a JWT ID.
|
|
17
|
+
* @param length The required 16-byte length.
|
|
18
|
+
* @returns The generated identifier bytes.
|
|
19
|
+
*/
|
|
20
|
+
export type SignedSessionRandom = (length: 16) => Uint8Array;
|
|
21
|
+
/**
|
|
22
|
+
* An active P-256 signing key.
|
|
23
|
+
*/
|
|
24
|
+
export interface SignedSessionSigningKey {
|
|
25
|
+
/**
|
|
26
|
+
* Non-empty local key ID of at most 256 characters.
|
|
27
|
+
*/
|
|
28
|
+
readonly kid: string;
|
|
29
|
+
/**
|
|
30
|
+
* Caller-owned P-256 private `KeyObject`; the strategy imports an owned copy.
|
|
31
|
+
*/
|
|
32
|
+
readonly privateKey: KeyObject;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A P-256 public key retained for tokens issued before rotation.
|
|
36
|
+
*/
|
|
37
|
+
export interface SignedSessionVerificationKey {
|
|
38
|
+
/**
|
|
39
|
+
* Non-empty local key ID of at most 256 characters.
|
|
40
|
+
*/
|
|
41
|
+
readonly kid: string;
|
|
42
|
+
/**
|
|
43
|
+
* Caller-owned P-256 public `KeyObject`; the strategy imports an owned copy.
|
|
44
|
+
*/
|
|
45
|
+
readonly publicKey: KeyObject;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Optional application-owned, durable token revocation capability.
|
|
49
|
+
*/
|
|
50
|
+
export interface SignedTokenRevocation {
|
|
51
|
+
/**
|
|
52
|
+
* Discriminator which makes immediate revocation support explicit.
|
|
53
|
+
*/
|
|
54
|
+
readonly kind: "supported";
|
|
55
|
+
/**
|
|
56
|
+
* Checks whether the exact 16-byte token ID is revoked.
|
|
57
|
+
* @param jti The token identifier to check.
|
|
58
|
+
* @returns Whether the token is revoked.
|
|
59
|
+
*/
|
|
60
|
+
isRevoked(jti: string): Promise<boolean>;
|
|
61
|
+
/**
|
|
62
|
+
* Stores the exact token ID through its Protobuf Timestamp expiry.
|
|
63
|
+
* The application owns persistence, cleanup, availability, and atomicity.
|
|
64
|
+
* @param jti The token identifier to retain.
|
|
65
|
+
* @param expiresAt The expiry after which retention may end.
|
|
66
|
+
* @returns Completes after the token ID is retained.
|
|
67
|
+
*/
|
|
68
|
+
revoke(jti: string, expiresAt: Timestamp): Promise<void>;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Finite configuration for locally-issued ES256 bearer sessions.
|
|
72
|
+
*/
|
|
73
|
+
export interface SignedSessionsOptions {
|
|
74
|
+
/**
|
|
75
|
+
* Exact non-empty token issuer, at most 256 characters.
|
|
76
|
+
*/
|
|
77
|
+
readonly issuer: string;
|
|
78
|
+
/**
|
|
79
|
+
* Exact non-empty single token audience, at most 256 characters.
|
|
80
|
+
*/
|
|
81
|
+
readonly audience: string;
|
|
82
|
+
/**
|
|
83
|
+
* Initial active P-256 signing key.
|
|
84
|
+
*/
|
|
85
|
+
readonly activeKey: SignedSessionSigningKey;
|
|
86
|
+
/**
|
|
87
|
+
* Initially retired P-256 verification keys; defaults to none.
|
|
88
|
+
* Each is retained for `ttlSeconds + clockSkewSeconds` after construction.
|
|
89
|
+
*/
|
|
90
|
+
readonly retiredKeys?: readonly SignedSessionVerificationKey[];
|
|
91
|
+
/**
|
|
92
|
+
* Optional application-owned immediate-revocation capability; defaults to expiry-only.
|
|
93
|
+
*/
|
|
94
|
+
readonly revocation?: SignedTokenRevocation;
|
|
95
|
+
/**
|
|
96
|
+
* Unix-millisecond clock; defaults to `Date.now`.
|
|
97
|
+
*/
|
|
98
|
+
readonly clock?: SignedSessionClock;
|
|
99
|
+
/**
|
|
100
|
+
* Random callback called with 16 and required to return 16 bytes; defaults to Node crypto.
|
|
101
|
+
*/
|
|
102
|
+
readonly randomBytes?: SignedSessionRandom;
|
|
103
|
+
/**
|
|
104
|
+
* Positive safe token lifetime in seconds; defaults to 28,800.
|
|
105
|
+
*/
|
|
106
|
+
readonly ttlSeconds?: number;
|
|
107
|
+
/**
|
|
108
|
+
* Non-negative safe temporal tolerance in seconds; defaults to 60.
|
|
109
|
+
*/
|
|
110
|
+
readonly clockSkewSeconds?: number;
|
|
111
|
+
/**
|
|
112
|
+
* Positive safe input and output token character bound; defaults to 8,192.
|
|
113
|
+
*/
|
|
114
|
+
readonly maxTokenCharacters?: number;
|
|
115
|
+
/**
|
|
116
|
+
* Positive safe active-plus-retired key bound; defaults to 16.
|
|
117
|
+
*/
|
|
118
|
+
readonly maxKeys?: number;
|
|
119
|
+
/**
|
|
120
|
+
* Positive safe principal-ID character bound; defaults to 256.
|
|
121
|
+
*/
|
|
122
|
+
readonly maxPrincipalIdCharacters?: number;
|
|
123
|
+
/**
|
|
124
|
+
* Non-negative safe attribute count bound; defaults to 32.
|
|
125
|
+
*/
|
|
126
|
+
readonly maxAttributes?: number;
|
|
127
|
+
/**
|
|
128
|
+
* Non-negative safe total attribute name/value character bound; defaults to 4,096.
|
|
129
|
+
*/
|
|
130
|
+
readonly maxAttributeCharacters?: number;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Result of issuing a signed session.
|
|
134
|
+
*
|
|
135
|
+
* Rejections distinguish terminal close, clock/entropy/signing failure, and
|
|
136
|
+
* a principal outside the configured finite bounds.
|
|
137
|
+
*/
|
|
138
|
+
export type SignedSessionIssueResult = {
|
|
139
|
+
/**
|
|
140
|
+
* Identifies successful token issuance.
|
|
141
|
+
*/
|
|
142
|
+
readonly kind: "issued";
|
|
143
|
+
/**
|
|
144
|
+
* Provides the issued bearer credential.
|
|
145
|
+
*/
|
|
146
|
+
readonly credential: BearerCredential;
|
|
147
|
+
/**
|
|
148
|
+
* Provides the session represented by the credential.
|
|
149
|
+
*/
|
|
150
|
+
readonly session: ResolvedSession;
|
|
151
|
+
} | {
|
|
152
|
+
/**
|
|
153
|
+
* Identifies rejected token issuance.
|
|
154
|
+
*/
|
|
155
|
+
readonly kind: "rejected";
|
|
156
|
+
/**
|
|
157
|
+
* Explains why token issuance was rejected.
|
|
158
|
+
*/
|
|
159
|
+
readonly reason: "closed" | "clock-failure" | "entropy-failure" | "principal-invalid" | "signing-failure";
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Result of atomically changing the active signing key.
|
|
163
|
+
*
|
|
164
|
+
* A rejection never changes the active key or verification ring.
|
|
165
|
+
*/
|
|
166
|
+
export type SignedSessionRotationResult = {
|
|
167
|
+
/**
|
|
168
|
+
* Identifies successful signing-key rotation.
|
|
169
|
+
*/
|
|
170
|
+
readonly kind: "rotated";
|
|
171
|
+
} | {
|
|
172
|
+
/**
|
|
173
|
+
* Identifies rejected signing-key rotation.
|
|
174
|
+
*/
|
|
175
|
+
readonly kind: "rejected";
|
|
176
|
+
/**
|
|
177
|
+
* Explains why signing-key rotation was rejected.
|
|
178
|
+
*/
|
|
179
|
+
readonly reason: "closed" | "clock-failure" | "invalid-key" | "duplicate-key" | "key-capacity-exceeded";
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* Enumeration-safe result of a signed-session logout.
|
|
183
|
+
*
|
|
184
|
+
* `expiryOnly` means no immediate revocation guarantee exists, while
|
|
185
|
+
* `unavailable` means the configured revocation store failed.
|
|
186
|
+
*/
|
|
187
|
+
export interface SignedSessionLogoutResult {
|
|
188
|
+
/**
|
|
189
|
+
* Reports the immediate-revocation outcome.
|
|
190
|
+
*/
|
|
191
|
+
readonly kind: "revoked" | "expiryOnly" | "unavailable";
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Finite, local ES256/JWT application sessions. This class has no remote key
|
|
195
|
+
* discovery, persistence, OIDC behavior, or authorization policy. It imports
|
|
196
|
+
* owned key copies, but Node does not expose explicit `KeyObject` zeroing.
|
|
197
|
+
*/
|
|
198
|
+
export declare class SignedSessions implements SessionResolver {
|
|
199
|
+
#private;
|
|
200
|
+
/**
|
|
201
|
+
* Creates signed sessions with copied finite configuration and P-256 keys.
|
|
202
|
+
* @param options The issuer, key ring, limits, clock, entropy, and revocation settings.
|
|
203
|
+
*/
|
|
204
|
+
constructor(options: SignedSessionsOptions);
|
|
205
|
+
/**
|
|
206
|
+
* Creates one compact ES256 bearer token inside configured identity bounds.
|
|
207
|
+
* @param principal The authenticated principal to encode.
|
|
208
|
+
* @returns The issuance outcome and, when accepted, credential and session.
|
|
209
|
+
*/
|
|
210
|
+
issue(principal: AuthenticatedPrincipal): Promise<SignedSessionIssueResult>;
|
|
211
|
+
/**
|
|
212
|
+
* Resolves one locally verifiable bearer credential.
|
|
213
|
+
*
|
|
214
|
+
* Cookie credentials and every malformed, invalid, expired, revoked, or
|
|
215
|
+
* unavailable-revocation result return `undefined`.
|
|
216
|
+
* @param credential The credential to resolve.
|
|
217
|
+
* @returns The verified session, or undefined when it cannot be trusted.
|
|
218
|
+
*/
|
|
219
|
+
resolve(credential: RequestCredential): Promise<ResolvedSession | undefined>;
|
|
220
|
+
/**
|
|
221
|
+
* Updates the active P-256 key atomically.
|
|
222
|
+
*
|
|
223
|
+
* The previous verifier remains through the configured token lifetime plus
|
|
224
|
+
* clock skew, subject to the finite key bound.
|
|
225
|
+
* @param next The next active signing key.
|
|
226
|
+
* @returns The rotation outcome.
|
|
227
|
+
*/
|
|
228
|
+
rotate(next: SignedSessionSigningKey): Promise<SignedSessionRotationResult>;
|
|
229
|
+
/**
|
|
230
|
+
* Sends a logout request without revealing invalid-token state.
|
|
231
|
+
*
|
|
232
|
+
* Immediate revocation requires `SignedTokenRevocation`; otherwise valid and
|
|
233
|
+
* invalid input both report `expiryOnly`.
|
|
234
|
+
* @param credential The credential to revoke when valid.
|
|
235
|
+
* @returns The enumeration-safe logout outcome.
|
|
236
|
+
*/
|
|
237
|
+
logout(credential: RequestCredential): Promise<SignedSessionLogoutResult>;
|
|
238
|
+
/**
|
|
239
|
+
* Closes the resolver and clears active, verification-key, and revocation references.
|
|
240
|
+
* Node `KeyObject` memory cannot be explicitly zeroed.
|
|
241
|
+
* @returns Completes after resolver references are cleared.
|
|
242
|
+
*/
|
|
243
|
+
close(): Promise<void>;
|
|
244
|
+
}
|
|
245
|
+
//# sourceMappingURL=signed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signed.d.ts","sourceRoot":"","sources":["../../src/sessions/signed.ts"],"names":[],"mappings":"AAeA,OAAO,EACL,SAAS,EAMV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAmB,KAAK,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEzE,OAAO,KAAK,EACV,sBAAsB,EACtB,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,eAAe,EAChB,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAGjC;;;;OAIG;IACH,GAAG,IAAI,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,CAAC,MAAM,EAAE,EAAE,KAAK,UAAU,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,uBAAuB;IAGtC;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,QAAQ,CAAC,UAAU,EAAE,SAAS,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAG3C;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IAGpC;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAE3B;;;;OAIG;IACH,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEzC;;;;;;OAMG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1D;AAED;;GAEG;AACH,MAAM,WAAW,q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