@oatscenter/trellis 0.100.0-rc.53 → 0.100.0-rc.54
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/auth/authority.d.ts +14 -4
- package/auth/authority.js +50 -42
- package/auth/browser/oauth.d.ts +10 -2
- package/auth/browser/oauth.js +42 -10
- package/auth/browser/storage.d.ts +9 -1
- package/auth/browser/storage.js +14 -2
- package/auth/connection.js +22 -29
- package/auth/http_error.d.ts +9 -1
- package/auth/http_error.js +17 -3
- package/auth/message_digests.js +1 -0
- package/auth/protocol_wasm/client/trellis_protocol_wasm_bg.wasm +0 -0
- package/auth/protocol_wasm/provider/trellis_protocol_wasm_bg.wasm +0 -0
- package/auth/protocol_wasm.d.ts +3 -0
- package/client_connect.d.ts +8 -1
- package/client_connect.js +28 -2
- package/errors/ResourceExhaustedError.d.ts +61 -0
- package/errors/ResourceExhaustedError.js +109 -0
- package/errors/index.d.ts +1 -0
- package/errors/index.js +1 -0
- package/internal_sdk/generated/_internal/evidence.js +4 -4
- package/internal_sdk/generated/apis/auth/mod.d.ts +3 -3
- package/internal_sdk/generated/apis/auth/mod.js +1 -1
- package/internal_sdk/generated/apis/health/mod.d.ts +3 -2
- package/internal_sdk/generated/apis/health/mod.js +1 -1
- package/internal_sdk/generated/apis/state/mod.d.ts +16 -3
- package/internal_sdk/generated/apis/state/mod.js +32 -1
- package/internal_sdk/generated/apps/cli/mod.d.ts +30 -3
- package/internal_sdk/generated/apps/cli/mod.js +15 -1
- package/internal_sdk/generated/apps/console/mod.d.ts +5 -4
- package/internal_sdk/generated/package.json +2 -2
- package/internal_sdk/generated/participants/healthRuntime/mod.d.ts +3 -2
- package/internal_sdk/generated/participants/healthRuntime/mod.js +2 -2
- package/internal_sdk/generated/participants/platform/mod.d.ts +5 -5
- package/internal_sdk/generated/participants/platform/mod.js +2 -2
- package/internal_sdk/generated/types/_internal/p0.d.ts +131 -0
- package/internal_sdk/generated/types/_internal/p0.js +32 -1
- package/internal_sdk/generated/types/index.d.ts +10 -0
- package/internal_sdk/generated/types/index.js +5 -0
- package/kv.d.ts +11 -2
- package/kv.js +12 -4
- package/native/oauth.d.ts +14 -7
- package/native/oauth.js +21 -17
- package/own_authority.d.ts +6 -1
- package/own_authority.js +26 -6
- package/package.json +2 -2
- package/service/mod.d.ts +1 -1
- package/service/outbox_inbox.d.ts +2 -1
- package/service/runtime/core.js +44 -10
- package/service/runtime/service.d.ts +2 -1
- package/service/runtime/service.js +39 -6
- package/session/durable_events.d.ts +2 -0
- package/session/durable_events.js +14 -7
- package/session/facades.d.ts +3 -3
- package/session/handler_errors.d.ts +34 -0
- package/session/handler_errors.js +83 -1
- package/session/helpers.d.ts +12 -0
- package/session/helpers.js +28 -0
- package/session/local_authorization.js +8 -0
- package/session/state.js +10 -2
- package/session.d.ts +7 -5
- package/session.js +168 -56
- package/store.d.ts +11 -2
- package/store.js +12 -2
- package/tasks.js +2 -1
- package/transport/generations.d.ts +1 -1
- package/webhooks.d.ts +42 -5
- package/webhooks.js +80 -3
package/auth/authority.d.ts
CHANGED
|
@@ -88,12 +88,22 @@ export declare class SessionAuthorityOwner {
|
|
|
88
88
|
get trustSnapshot(): RuntimeAuthorizationTrust;
|
|
89
89
|
/** Obtain successor trust only from this owner's verified chain rooted at the exact retained credential pin. */
|
|
90
90
|
trustForCredential(anchor: RuntimeAuthorizationTrust): RuntimeAuthorizationTrust;
|
|
91
|
-
/**
|
|
91
|
+
/**
|
|
92
|
+
* Attach read-only public material and one snapshot-and-update mirror for all logical sessions.
|
|
93
|
+
*
|
|
94
|
+
* Resolves once material reads and issuer metadata use `nats`. The mirror
|
|
95
|
+
* then catches up in the background: `caughtUp` settles when its initial
|
|
96
|
+
* snapshot is applied, or rejects if the mirror fails first. Nothing waits
|
|
97
|
+
* for it: verification of other parties' messages uses the revocations
|
|
98
|
+
* observed so far, and own authority never depends on the mirror.
|
|
99
|
+
*/
|
|
92
100
|
attach(nats: NatsConnection, binding: AuthorityRegistryBinding, options?: {
|
|
93
101
|
signal?: AbortSignal;
|
|
94
102
|
timeoutMs?: number;
|
|
95
103
|
inboxPrefix?: string;
|
|
96
|
-
}): Promise<
|
|
104
|
+
}): Promise<{
|
|
105
|
+
readonly caughtUp: Promise<void>;
|
|
106
|
+
}>;
|
|
97
107
|
/** Verify an issuer-signed lookup reply against the actual pending ephemeral request. */
|
|
98
108
|
verifyAdmissionContext(bytes: Uint8Array, request: AdmissionGet, subject: string, reply: string): Promise<AdmissionContext>;
|
|
99
109
|
/** Clock and bounds shared by all request/event/provider verification. */
|
|
@@ -102,8 +112,8 @@ export declare class SessionAuthorityOwner {
|
|
|
102
112
|
get ownDigest(): string | undefined;
|
|
103
113
|
/** Whether a verified sticky retirement affects the installed own logical session, even while its live lease is unavailable. */
|
|
104
114
|
get ownRevoked(): boolean;
|
|
105
|
-
/**
|
|
106
|
-
get
|
|
115
|
+
/** The revocation mirror failed and needs reattaching; verification carries on with the revocations already observed. */
|
|
116
|
+
get mirrorFailed(): boolean;
|
|
107
117
|
/** Verified retirement observed by the runtime's single mirror. */
|
|
108
118
|
isRevoked(sessionId: string): boolean;
|
|
109
119
|
/** Observe promotion and sticky lifecycle changes, without a per-context subscription. */
|
package/auth/authority.js
CHANGED
|
@@ -211,7 +211,15 @@ export class SessionAuthorityOwner {
|
|
|
211
211
|
rotationSequence: this.#rotationSequence.toString(),
|
|
212
212
|
});
|
|
213
213
|
}
|
|
214
|
-
/**
|
|
214
|
+
/**
|
|
215
|
+
* Attach read-only public material and one snapshot-and-update mirror for all logical sessions.
|
|
216
|
+
*
|
|
217
|
+
* Resolves once material reads and issuer metadata use `nats`. The mirror
|
|
218
|
+
* then catches up in the background: `caughtUp` settles when its initial
|
|
219
|
+
* snapshot is applied, or rejects if the mirror fails first. Nothing waits
|
|
220
|
+
* for it: verification of other parties' messages uses the revocations
|
|
221
|
+
* observed so far, and own authority never depends on the mirror.
|
|
222
|
+
*/
|
|
215
223
|
async attach(nats, binding, options = {}) {
|
|
216
224
|
if (this.#stopped)
|
|
217
225
|
throw new Error("authority owner stopped");
|
|
@@ -227,8 +235,10 @@ export class SessionAuthorityOwner {
|
|
|
227
235
|
inboxPrefix: options.inboxPrefix ?? "_INBOX",
|
|
228
236
|
signal: options.signal,
|
|
229
237
|
};
|
|
230
|
-
|
|
231
|
-
|
|
238
|
+
// A new attachment serves metadata reads at once; the mirror it starts
|
|
239
|
+
// never gates them.
|
|
240
|
+
this.#metadataTransport = metadataTransport;
|
|
241
|
+
const bound = Promise.withResolvers();
|
|
232
242
|
const ready = Promise.withResolvers();
|
|
233
243
|
void ready.promise.catch(() => undefined);
|
|
234
244
|
let watch;
|
|
@@ -248,7 +258,12 @@ export class SessionAuthorityOwner {
|
|
|
248
258
|
if (ended)
|
|
249
259
|
return;
|
|
250
260
|
ended = true;
|
|
251
|
-
|
|
261
|
+
// A failed candidate with no current mirror to fall back on also needs
|
|
262
|
+
// recovery, like a promoted mirror that failed.
|
|
263
|
+
if ((promoted && epoch === this.#mirrorEpoch) ||
|
|
264
|
+
(!promoted &&
|
|
265
|
+
this.#mirrorPreparationStop === abort &&
|
|
266
|
+
!this.#mirrorCovered)) {
|
|
252
267
|
this.#mirrorCovered = false;
|
|
253
268
|
this.#mirrorFailed = !transportLost && !nats.isClosed();
|
|
254
269
|
for (const listener of this.#listeners) {
|
|
@@ -337,10 +352,10 @@ export class SessionAuthorityOwner {
|
|
|
337
352
|
bindOnly: true,
|
|
338
353
|
});
|
|
339
354
|
check();
|
|
340
|
-
|
|
341
|
-
this.#material = material;
|
|
355
|
+
this.#material = material;
|
|
342
356
|
await this.#advanceTrust(BigInt(binding.rotationSequence));
|
|
343
357
|
check();
|
|
358
|
+
bound.resolve();
|
|
344
359
|
const inbox = createInbox(options.inboxPrefix);
|
|
345
360
|
const prefix = `$KV.${binding.revocationBucket}.`;
|
|
346
361
|
const stream = `KV_${binding.revocationBucket}`;
|
|
@@ -449,15 +464,20 @@ export class SessionAuthorityOwner {
|
|
|
449
464
|
watch?.stop();
|
|
450
465
|
throw error;
|
|
451
466
|
});
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
467
|
+
const caughtUp = (async () => {
|
|
468
|
+
try {
|
|
469
|
+
await Promise.race([setup, ready.promise]);
|
|
470
|
+
check();
|
|
471
|
+
}
|
|
472
|
+
catch (error) {
|
|
473
|
+
fail(error instanceof Error ? error : new Error(String(error)));
|
|
474
|
+
watch?.stop();
|
|
475
|
+
throw error;
|
|
476
|
+
}
|
|
477
|
+
})();
|
|
478
|
+
void caughtUp.catch(() => undefined);
|
|
479
|
+
await Promise.race([bound.promise, caughtUp]);
|
|
480
|
+
return { caughtUp };
|
|
461
481
|
}
|
|
462
482
|
/** Verify an issuer-signed lookup reply against the actual pending ephemeral request. */
|
|
463
483
|
async verifyAdmissionContext(bytes, request, subject, reply) {
|
|
@@ -501,8 +521,8 @@ export class SessionAuthorityOwner {
|
|
|
501
521
|
return (this.#own !== undefined &&
|
|
502
522
|
this.isRevoked(this.#own.authority.authorizationSessionId));
|
|
503
523
|
}
|
|
504
|
-
/**
|
|
505
|
-
get
|
|
524
|
+
/** The revocation mirror failed and needs reattaching; verification carries on with the revocations already observed. */
|
|
525
|
+
get mirrorFailed() {
|
|
506
526
|
return this.#mirrorFailed;
|
|
507
527
|
}
|
|
508
528
|
/** Verified retirement observed by the runtime's single mirror. */
|
|
@@ -523,7 +543,6 @@ export class SessionAuthorityOwner {
|
|
|
523
543
|
/** Verify a private candidate; commit only at checked transport publication. */
|
|
524
544
|
async prepareOwn(bytes, expected) {
|
|
525
545
|
const epoch = ++this.#ownPreparationEpoch;
|
|
526
|
-
const mirrorEpoch = this.#mirrorEpoch;
|
|
527
546
|
const candidate = await this.#verify(bytes, "live");
|
|
528
547
|
candidate.unpublished = true;
|
|
529
548
|
try {
|
|
@@ -535,9 +554,7 @@ export class SessionAuthorityOwner {
|
|
|
535
554
|
this.assertCurrent(candidate);
|
|
536
555
|
let finished = false;
|
|
537
556
|
const assertPreparedCurrent = () => {
|
|
538
|
-
if (finished ||
|
|
539
|
-
epoch !== this.#ownPreparationEpoch ||
|
|
540
|
-
mirrorEpoch !== this.#mirrorEpoch)
|
|
557
|
+
if (finished || epoch !== this.#ownPreparationEpoch)
|
|
541
558
|
throw new Error("own authority candidate superseded");
|
|
542
559
|
this.assertCurrent(candidate);
|
|
543
560
|
};
|
|
@@ -759,7 +776,7 @@ export class SessionAuthorityOwner {
|
|
|
759
776
|
if (entry.digest !== event.authorityDigest)
|
|
760
777
|
throw new Error("event authority digest mismatch");
|
|
761
778
|
await this.authorize(entry, event.apiId, action, originalPublication !== null, {
|
|
762
|
-
at:
|
|
779
|
+
at: event.issuedAt,
|
|
763
780
|
...(originalPublication
|
|
764
781
|
? {
|
|
765
782
|
publishedAt: Math.floor(Date.parse(originalPublication.publishedAt) / 1000),
|
|
@@ -836,23 +853,19 @@ export class SessionAuthorityOwner {
|
|
|
836
853
|
}
|
|
837
854
|
}
|
|
838
855
|
async #settleMirrorUpdates() {
|
|
839
|
-
const epoch = this.#mirrorEpoch;
|
|
840
856
|
let updates;
|
|
841
857
|
do {
|
|
842
858
|
updates = this.#mirrorUpdates;
|
|
843
859
|
await updates;
|
|
844
|
-
if (epoch !== this.#mirrorEpoch)
|
|
845
|
-
throw new AuthorityUnavailableError("authority mirror superseded");
|
|
846
860
|
} while (updates !== this.#mirrorUpdates);
|
|
847
|
-
// This waits only for updates already received
|
|
848
|
-
// a replacement mirror. Callers
|
|
861
|
+
// This waits only for updates already received and being verified, never
|
|
862
|
+
// for a lost, lagging or replacement mirror. Callers then check what is
|
|
863
|
+
// known.
|
|
849
864
|
}
|
|
850
865
|
/** Recheck observed revocation and expiry after every cold asynchronous boundary. */
|
|
851
866
|
assertCurrent(entry) {
|
|
852
867
|
if (this.#stopped || this.#overloaded)
|
|
853
868
|
throw new Error("authority owner unavailable");
|
|
854
|
-
if (!this.#mirrorCovered)
|
|
855
|
-
throw new AuthorityUnavailableError("revocation mirror is not current");
|
|
856
869
|
const issuer = this.#liveIssuer(entry.authority.issuerKeyId);
|
|
857
870
|
if (issuer?.state !== "active")
|
|
858
871
|
throw new Error("issuer unavailable for live authority");
|
|
@@ -982,16 +995,13 @@ export class SessionAuthorityOwner {
|
|
|
982
995
|
}
|
|
983
996
|
/** Read public verification material using a fresh, pinned-issuer authenticated exchange. */
|
|
984
997
|
async readIssuerMetadata(query) {
|
|
985
|
-
return this.#readIssuerMetadata(query
|
|
998
|
+
return this.#readIssuerMetadata(query);
|
|
986
999
|
}
|
|
987
|
-
async #readIssuerMetadata(query
|
|
1000
|
+
async #readIssuerMetadata(query) {
|
|
988
1001
|
const transport = this.#metadataTransport;
|
|
989
|
-
const epoch = this.#mirrorEpoch;
|
|
990
1002
|
const assertCurrent = () => {
|
|
991
1003
|
if (!transport ||
|
|
992
1004
|
this.#stopped ||
|
|
993
|
-
(requireCoverage && !this.#mirrorCovered) ||
|
|
994
|
-
this.#mirrorEpoch !== epoch ||
|
|
995
1005
|
transport.nats.isClosed() ||
|
|
996
1006
|
transport.nats.isDraining())
|
|
997
1007
|
throw new Error("issuer metadata transport unavailable");
|
|
@@ -1043,9 +1053,7 @@ export class SessionAuthorityOwner {
|
|
|
1043
1053
|
if (status.authorizationSessionId !== query.authorizationSessionId)
|
|
1044
1054
|
throw new Error("issuer metadata status identity mismatch");
|
|
1045
1055
|
if (status.revocation)
|
|
1046
|
-
await this.observeRevocation(signedBytes(status.revocation), query.authorizationSessionId, () =>
|
|
1047
|
-
this.#mirrorCovered &&
|
|
1048
|
-
!this.#stopped);
|
|
1056
|
+
await this.observeRevocation(signedBytes(status.revocation), query.authorizationSessionId, () => !this.#stopped);
|
|
1049
1057
|
assertCurrent();
|
|
1050
1058
|
}
|
|
1051
1059
|
return response;
|
|
@@ -1088,7 +1096,7 @@ export class SessionAuthorityOwner {
|
|
|
1088
1096
|
continue;
|
|
1089
1097
|
}
|
|
1090
1098
|
// A failed read leaves the key to its signed deadline.
|
|
1091
|
-
await this.#readIssuerMetadata({ kind: "issuerKey", keyId }
|
|
1099
|
+
await this.#readIssuerMetadata({ kind: "issuerKey", keyId }).catch(() => undefined);
|
|
1092
1100
|
}
|
|
1093
1101
|
}
|
|
1094
1102
|
/**
|
|
@@ -1112,7 +1120,10 @@ export class SessionAuthorityOwner {
|
|
|
1112
1120
|
if (!issuer && (await this.#forwardIssuer(keyId)))
|
|
1113
1121
|
issuer = this.#liveIssuer(keyId);
|
|
1114
1122
|
if (!issuer) {
|
|
1115
|
-
const response = await this.#readIssuerMetadata({
|
|
1123
|
+
const response = await this.#readIssuerMetadata({
|
|
1124
|
+
kind: "issuerKey",
|
|
1125
|
+
keyId,
|
|
1126
|
+
});
|
|
1116
1127
|
if (response.result.kind !== "value")
|
|
1117
1128
|
throw new Error("historical authority issuer unavailable");
|
|
1118
1129
|
issuer = this.#liveIssuer(keyId);
|
|
@@ -1210,7 +1221,6 @@ export class SessionAuthorityOwner {
|
|
|
1210
1221
|
return value;
|
|
1211
1222
|
}
|
|
1212
1223
|
async #verify(bytes, purpose, historicalCutoff) {
|
|
1213
|
-
const mirrorEpoch = this.#mirrorEpoch;
|
|
1214
1224
|
const hints = this.#hints(bytes);
|
|
1215
1225
|
if (typeof hints.issuerKeyId !== "string")
|
|
1216
1226
|
throw new Error("missing issuer lookup identity");
|
|
@@ -1250,8 +1260,6 @@ export class SessionAuthorityOwner {
|
|
|
1250
1260
|
try {
|
|
1251
1261
|
if (purpose === "live") {
|
|
1252
1262
|
await this.#settleMirrorUpdates();
|
|
1253
|
-
if (mirrorEpoch !== this.#mirrorEpoch)
|
|
1254
|
-
throw new Error("authority verification coverage superseded");
|
|
1255
1263
|
this.assertCurrent(entry);
|
|
1256
1264
|
}
|
|
1257
1265
|
return entry;
|
package/auth/browser/oauth.d.ts
CHANGED
|
@@ -79,12 +79,20 @@ export declare class BrowserOAuthClient {
|
|
|
79
79
|
/**
|
|
80
80
|
* Build a PKCE authorization URL and retain only this tab's continuation.
|
|
81
81
|
* With `extendGrant`, approval widens that grant of this app instead of
|
|
82
|
-
* creating another, so its live session gains what the user approves.
|
|
82
|
+
* creating another, so its live session gains what the user approves. With
|
|
83
|
+
* `askAgain`, the approval page also asks about choices the user declined
|
|
84
|
+
* before, which sign-in otherwise leaves declined without asking.
|
|
83
85
|
*/
|
|
84
86
|
authorize(redirectUri: string, capabilities: BrowserCapabilityRequest, options?: {
|
|
85
87
|
extendGrant?: string;
|
|
88
|
+
askAgain?: boolean;
|
|
86
89
|
}): Promise<Result<string, AuthError>>;
|
|
87
|
-
/**
|
|
90
|
+
/**
|
|
91
|
+
* Consume this tab's exact callback once; install signed authority before
|
|
92
|
+
* remembering its grant. A callback for no sign-in this tab is waiting on,
|
|
93
|
+
* such as an old link opened again, fails with `OAuthCallbackNotPending`
|
|
94
|
+
* and leaves the tab's own continuation in place.
|
|
95
|
+
*/
|
|
88
96
|
complete(callback?: string): Promise<Result<{
|
|
89
97
|
value: BrowserOAuthAdmission;
|
|
90
98
|
refreshToken: string;
|
package/auth/browser/oauth.js
CHANGED
|
@@ -63,6 +63,9 @@ export class BrowserOAuthClient {
|
|
|
63
63
|
#nonce;
|
|
64
64
|
#runtime;
|
|
65
65
|
#owner;
|
|
66
|
+
// The user this document signed in as. Another tab can rebind a lapsed
|
|
67
|
+
// stored session to someone else; this document never follows it.
|
|
68
|
+
#principal;
|
|
66
69
|
// Discovery read while opening. The refresh a page load starts with
|
|
67
70
|
// authenticates it instead of reading the same document again.
|
|
68
71
|
#discovered;
|
|
@@ -158,7 +161,9 @@ export class BrowserOAuthClient {
|
|
|
158
161
|
/**
|
|
159
162
|
* Build a PKCE authorization URL and retain only this tab's continuation.
|
|
160
163
|
* With `extendGrant`, approval widens that grant of this app instead of
|
|
161
|
-
* creating another, so its live session gains what the user approves.
|
|
164
|
+
* creating another, so its live session gains what the user approves. With
|
|
165
|
+
* `askAgain`, the approval page also asks about choices the user declined
|
|
166
|
+
* before, which sign-in otherwise leaves declined without asking.
|
|
162
167
|
*/
|
|
163
168
|
async authorize(redirectUri, capabilities, options = {}) {
|
|
164
169
|
try {
|
|
@@ -200,6 +205,7 @@ export class BrowserOAuthClient {
|
|
|
200
205
|
},
|
|
201
206
|
]),
|
|
202
207
|
...(options.extendGrant ? { trellis_grant: options.extendGrant } : {}),
|
|
208
|
+
...(options.askAgain ? { prompt: "consent" } : {}),
|
|
203
209
|
}).toString();
|
|
204
210
|
return ok(url.href);
|
|
205
211
|
}
|
|
@@ -207,17 +213,22 @@ export class BrowserOAuthClient {
|
|
|
207
213
|
return err(new AuthError({ reason: "StorageUnavailable" }));
|
|
208
214
|
}
|
|
209
215
|
}
|
|
210
|
-
/**
|
|
216
|
+
/**
|
|
217
|
+
* Consume this tab's exact callback once; install signed authority before
|
|
218
|
+
* remembering its grant. A callback for no sign-in this tab is waiting on,
|
|
219
|
+
* such as an old link opened again, fails with `OAuthCallbackNotPending`
|
|
220
|
+
* and leaves the tab's own continuation in place.
|
|
221
|
+
*/
|
|
211
222
|
async complete(callback = location.href) {
|
|
212
223
|
// A later refresh renews a session, perhaps after the signer changed, so
|
|
213
224
|
// it discovers afresh.
|
|
214
225
|
this.#discovered = undefined;
|
|
215
226
|
try {
|
|
216
227
|
const raw = sessionStorage.getItem(this.#pendingKey());
|
|
217
|
-
if (!raw)
|
|
218
|
-
return err(new AuthError({ reason: "OAuthRecoveryRequired" }));
|
|
219
|
-
const pending = pendingSchema.parse(JSON.parse(raw));
|
|
220
228
|
const url = new URL(callback);
|
|
229
|
+
const pending = raw ? pendingSchema.parse(JSON.parse(raw)) : undefined;
|
|
230
|
+
if (!pending || url.searchParams.get("state") !== pending.state)
|
|
231
|
+
return err(new AuthError({ reason: "OAuthCallbackNotPending" }));
|
|
221
232
|
const redirect = new URL(pending.redirectUri);
|
|
222
233
|
if (pending.issuer !== this.scope.issuer ||
|
|
223
234
|
pending.clientId !== this.scope.clientId ||
|
|
@@ -374,12 +385,22 @@ export class BrowserOAuthClient {
|
|
|
374
385
|
if (response.nonce)
|
|
375
386
|
this.#nonce = response.nonce;
|
|
376
387
|
// Neither unsigned NATS errors nor transient HTTP failures delete the durable grant/key.
|
|
377
|
-
if (!response.ok)
|
|
388
|
+
if (!response.ok) {
|
|
389
|
+
const refused = z
|
|
390
|
+
.object({
|
|
391
|
+
error: z.string().optional(),
|
|
392
|
+
error_description: z.string().optional(),
|
|
393
|
+
})
|
|
394
|
+
.safeParse(response.data).data;
|
|
378
395
|
return err(new AuthError({
|
|
396
|
+
// A server failure's description names its reference.
|
|
397
|
+
message: refused?.error_description,
|
|
398
|
+
context: { status: response.status, error: refused?.error },
|
|
379
399
|
reason: response.status >= 500 || response.status === 429
|
|
380
400
|
? "OAuthUnavailable"
|
|
381
401
|
: "OAuthRecoveryRequired",
|
|
382
402
|
}));
|
|
403
|
+
}
|
|
383
404
|
const token = tokenSchema.parse(response.data);
|
|
384
405
|
if (form.get("grant_type") === "refresh_token") {
|
|
385
406
|
const saved = await this.store.retainRotatedToken(token.refresh_token, form.get("refresh_token") ?? "");
|
|
@@ -403,6 +424,7 @@ export class BrowserOAuthClient {
|
|
|
403
424
|
const body = verified.admission.credential;
|
|
404
425
|
const jkt = await dpopThumbprint(publicJwk);
|
|
405
426
|
const grant = this.store.grant;
|
|
427
|
+
const refresh = form.get("grant_type") === "refresh_token";
|
|
406
428
|
if ((this.#owner &&
|
|
407
429
|
this.#owner.trustSnapshot.issuer.keyId !== trust.issuer.keyId) ||
|
|
408
430
|
body.runtimeId !== runtimeId ||
|
|
@@ -411,12 +433,22 @@ export class BrowserOAuthClient {
|
|
|
411
433
|
body.binding.bindingKind !== "browser" ||
|
|
412
434
|
body.binding.browserOrigin !== location.origin ||
|
|
413
435
|
body.binding.browserOrigin !== this.scope.browserOrigin ||
|
|
414
|
-
(
|
|
436
|
+
(this.#principal !== undefined &&
|
|
437
|
+
body.principalId !== this.#principal) ||
|
|
438
|
+
(refresh &&
|
|
439
|
+
grant &&
|
|
415
440
|
(body.principalId !== grant.principalId ||
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
body.loginSessionId !== grant.loginSessionId)))))
|
|
441
|
+
body.oauthGrantId !== grant.oauthGrantId ||
|
|
442
|
+
body.loginSessionId !== grant.loginSessionId)))
|
|
419
443
|
return err(new AuthError({ reason: "OAuthRecoveryRequired" }));
|
|
444
|
+
// A new sign-in as someone else takes over a stored session only once
|
|
445
|
+
// that session can no longer renew; a live one stays its user's.
|
|
446
|
+
if (!refresh &&
|
|
447
|
+
grant &&
|
|
448
|
+
!this.store.lapsed &&
|
|
449
|
+
body.principalId !== grant.principalId)
|
|
450
|
+
return err(new AuthError({ reason: "OAuthAccountChanged" }));
|
|
451
|
+
this.#principal = body.principalId;
|
|
420
452
|
return ok({
|
|
421
453
|
value: {
|
|
422
454
|
auth,
|
|
@@ -46,11 +46,19 @@ export declare class BrowserSessionStore {
|
|
|
46
46
|
get trust(): RuntimeAuthorizationTrust;
|
|
47
47
|
/** Grant identity already committed under the credential's durable key. */
|
|
48
48
|
get grant(): Readonly<OAuthRecord["grant"]>;
|
|
49
|
+
/**
|
|
50
|
+
* Whether the stored session can no longer renew: its last refresh failed,
|
|
51
|
+
* or never answered, so its token is spent. Only a new sign-in restores it.
|
|
52
|
+
*/
|
|
53
|
+
get lapsed(): boolean;
|
|
49
54
|
/** Persist only a successor authenticated from this record's retained pin. */
|
|
50
55
|
retainTrust(owner: SessionAuthorityOwner): Promise<void>;
|
|
51
56
|
/** Decrypt this exact scope's refresh credential into transient SDK memory. */
|
|
52
57
|
refreshToken(): Promise<Result<string | undefined, AuthError>>;
|
|
53
|
-
/**
|
|
58
|
+
/**
|
|
59
|
+
* Bind an unused or lapsed credential handle to the verified user and
|
|
60
|
+
* initial family. A handle whose session still renews stays its user's.
|
|
61
|
+
*/
|
|
54
62
|
rememberGrant(grant: BrowserOAuthGrant): Promise<Result<void, AuthError>>;
|
|
55
63
|
/**
|
|
56
64
|
* One cross-tab owner rereads, exchanges, and commits a refresh. Mark recovery
|
package/auth/browser/storage.js
CHANGED
|
@@ -158,6 +158,13 @@ export class BrowserSessionStore {
|
|
|
158
158
|
get grant() {
|
|
159
159
|
return this.#record.grant && Object.freeze({ ...this.#record.grant });
|
|
160
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Whether the stored session can no longer renew: its last refresh failed,
|
|
163
|
+
* or never answered, so its token is spent. Only a new sign-in restores it.
|
|
164
|
+
*/
|
|
165
|
+
get lapsed() {
|
|
166
|
+
return this.#record.recoveryRequired === true;
|
|
167
|
+
}
|
|
161
168
|
/** Persist only a successor authenticated from this record's retained pin. */
|
|
162
169
|
async retainTrust(owner) {
|
|
163
170
|
const trust = SessionAuthorityOwner.prototype.trustForCredential.call(owner, this.trust);
|
|
@@ -244,7 +251,10 @@ export class BrowserSessionStore {
|
|
|
244
251
|
return err(new AuthError({ reason: "StorageUnavailable" }));
|
|
245
252
|
}
|
|
246
253
|
}
|
|
247
|
-
/**
|
|
254
|
+
/**
|
|
255
|
+
* Bind an unused or lapsed credential handle to the verified user and
|
|
256
|
+
* initial family. A handle whose session still renews stays its user's.
|
|
257
|
+
*/
|
|
248
258
|
async rememberGrant(grant) {
|
|
249
259
|
if (!grant.principalId ||
|
|
250
260
|
!grant.oauthGrantId ||
|
|
@@ -256,7 +266,9 @@ export class BrowserSessionStore {
|
|
|
256
266
|
return await navigator.locks.request(this.#scope, async () => {
|
|
257
267
|
const current = await recordTransaction(this.#database, "readonly", (store) => requestValue(store.get(this.#scope)));
|
|
258
268
|
if (!current ||
|
|
259
|
-
(current.grant &&
|
|
269
|
+
(current.grant &&
|
|
270
|
+
!current.recoveryRequired &&
|
|
271
|
+
current.grant.principalId !== grant.principalId)) {
|
|
260
272
|
return err(new AuthError({ reason: "Conflict" }));
|
|
261
273
|
}
|
|
262
274
|
this.#record = current;
|
package/auth/connection.js
CHANGED
|
@@ -365,6 +365,9 @@ export async function connectAdmitted(options) {
|
|
|
365
365
|
const value = candidates.get(generation.nc);
|
|
366
366
|
if (!value)
|
|
367
367
|
throw new Error("AdmissionUnavailable");
|
|
368
|
+
// The revocation mirror only informs verification of other parties'
|
|
369
|
+
// messages, so activation does not wait for its snapshot. A mirror that
|
|
370
|
+
// fails is recovered in the background.
|
|
368
371
|
await owner.attach(generation.nc, registrySchema.parse(value.context.registry), { signal: options.signal, timeoutMs: options.timeout, inboxPrefix });
|
|
369
372
|
if (!value.committed) {
|
|
370
373
|
value.candidate?.dispose();
|
|
@@ -450,8 +453,8 @@ export async function connectAdmitted(options) {
|
|
|
450
453
|
/** Revalidate current authority through the admitted runtime key without rotating OAuth custody or replacing an equal-policy attachment. */
|
|
451
454
|
const refreshAuthority = () => {
|
|
452
455
|
if (renewalTask) {
|
|
453
|
-
//
|
|
454
|
-
// bounded by their transport timeout. Join settlement, not its cancelled
|
|
456
|
+
// Transport loss cancels the attempt, but broker-info requests can only
|
|
457
|
+
// be bounded by their transport timeout. Join settlement, not its cancelled
|
|
455
458
|
// result, before the single renewal owner starts another exchange.
|
|
456
459
|
if (renewalAbort?.signal.aborted) {
|
|
457
460
|
return renewalTask
|
|
@@ -644,14 +647,13 @@ export async function connectAdmitted(options) {
|
|
|
644
647
|
options.signal?.removeEventListener("abort", abort);
|
|
645
648
|
unsubscribeOwner();
|
|
646
649
|
});
|
|
647
|
-
const
|
|
650
|
+
const onOwnerChange = () => {
|
|
648
651
|
if (manager.isClosed())
|
|
649
652
|
return;
|
|
650
|
-
if (owner.
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
renewalAbort?.abort();
|
|
653
|
+
if (owner.mirrorFailed) {
|
|
654
|
+
// Reattach the mirror in the background. Nothing waits for it:
|
|
655
|
+
// renewal and application work carry on with the revocations
|
|
656
|
+
// observed so far.
|
|
655
657
|
if (mirrorRecovery)
|
|
656
658
|
return;
|
|
657
659
|
const controller = new AbortController();
|
|
@@ -659,11 +661,9 @@ export async function connectAdmitted(options) {
|
|
|
659
661
|
const signal = options.signal
|
|
660
662
|
? AbortSignal.any([options.signal, controller.signal])
|
|
661
663
|
: controller.signal;
|
|
662
|
-
// Private maintenance may retain the physically published attachment
|
|
663
|
-
// while application authority stays fenced by the missing snapshot.
|
|
664
664
|
void (async () => {
|
|
665
665
|
let delay = 100;
|
|
666
|
-
while (!signal.aborted && !manager.isClosed() && owner.
|
|
666
|
+
while (!signal.aborted && !manager.isClosed() && owner.mirrorFailed) {
|
|
667
667
|
try {
|
|
668
668
|
const lease = await manager.acquirePublishedAttachment();
|
|
669
669
|
if (!lease)
|
|
@@ -672,32 +672,21 @@ export async function connectAdmitted(options) {
|
|
|
672
672
|
const value = candidates.get(lease.nc);
|
|
673
673
|
if (!value)
|
|
674
674
|
return;
|
|
675
|
-
await owner.attach(lease.nc, registrySchema.parse(value.context.registry), {
|
|
675
|
+
const { caughtUp } = await owner.attach(lease.nc, registrySchema.parse(value.context.registry), {
|
|
676
676
|
signal,
|
|
677
677
|
timeoutMs: options.timeout,
|
|
678
678
|
inboxPrefix,
|
|
679
679
|
});
|
|
680
|
+
await caughtUp;
|
|
680
681
|
}
|
|
681
682
|
finally {
|
|
682
683
|
lease.release();
|
|
683
684
|
}
|
|
684
|
-
if (!signal.aborted) {
|
|
685
|
-
if (installedAuthority &&
|
|
686
|
-
installedAuthority.expiresAt <= options.auth.currentIat()) {
|
|
687
|
-
// Snapshot recovery is not authority renewal. Admission is
|
|
688
|
-
// proved by the retained runtime key, not the expired context.
|
|
689
|
-
await refreshAuthority();
|
|
690
|
-
}
|
|
691
|
-
else {
|
|
692
|
-
manager.authorizationPromoted();
|
|
693
|
-
scheduleRenewal();
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
685
|
}
|
|
697
686
|
catch {
|
|
698
|
-
//
|
|
687
|
+
// A failed mirror never clears observed cutoffs.
|
|
699
688
|
}
|
|
700
|
-
if (!signal.aborted && owner.
|
|
689
|
+
if (!signal.aborted && owner.mirrorFailed) {
|
|
701
690
|
await new Promise((resolve) => {
|
|
702
691
|
const done = () => {
|
|
703
692
|
clearTimeout(timer);
|
|
@@ -732,11 +721,15 @@ export async function connectAdmitted(options) {
|
|
|
732
721
|
}
|
|
733
722
|
}
|
|
734
723
|
else {
|
|
735
|
-
//
|
|
736
|
-
//
|
|
724
|
+
// Promotion, retirement or a rotation can change what own authority
|
|
725
|
+
// permits without a transport change.
|
|
737
726
|
manager.applicationUsabilityChanged();
|
|
738
727
|
}
|
|
739
|
-
}
|
|
728
|
+
};
|
|
729
|
+
const unsubscribeOwner = owner.subscribeChanges(onOwnerChange);
|
|
730
|
+
// A mirror that already failed while connecting is recovered now.
|
|
731
|
+
if (owner.mirrorFailed)
|
|
732
|
+
onOwnerChange();
|
|
740
733
|
return {
|
|
741
734
|
manager,
|
|
742
735
|
owner,
|
package/auth/http_error.d.ts
CHANGED
|
@@ -6,7 +6,15 @@ export declare class TrellisHttpError extends Error {
|
|
|
6
6
|
readonly status: number;
|
|
7
7
|
/** Exact machine-readable Trellis error code. */
|
|
8
8
|
readonly code: string;
|
|
9
|
-
|
|
9
|
+
/** For a server failure, the reference its line in the Trellis log has. */
|
|
10
|
+
readonly reference?: string;
|
|
11
|
+
/**
|
|
12
|
+
* @param status HTTP status returned by Trellis.
|
|
13
|
+
* @param code Machine-readable Trellis error code.
|
|
14
|
+
* @param message Optional detail from the envelope.
|
|
15
|
+
* @param reference The server failure's reference, ending the message.
|
|
16
|
+
*/
|
|
17
|
+
constructor(status: number, code: string, message?: string, reference?: string);
|
|
10
18
|
}
|
|
11
19
|
/** Decode one authoritative Trellis HTTP error envelope. */
|
|
12
20
|
export declare function decodeTrellisHttpError(response: Response): Promise<TrellisHttpError>;
|
package/auth/http_error.js
CHANGED
|
@@ -6,17 +6,27 @@ export class TrellisHttpError extends Error {
|
|
|
6
6
|
status;
|
|
7
7
|
/** Exact machine-readable Trellis error code. */
|
|
8
8
|
code;
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
/** For a server failure, the reference its line in the Trellis log has. */
|
|
10
|
+
reference;
|
|
11
|
+
/**
|
|
12
|
+
* @param status HTTP status returned by Trellis.
|
|
13
|
+
* @param code Machine-readable Trellis error code.
|
|
14
|
+
* @param message Optional detail from the envelope.
|
|
15
|
+
* @param reference The server failure's reference, ending the message.
|
|
16
|
+
*/
|
|
17
|
+
constructor(status, code, message, reference) {
|
|
18
|
+
super(`Trellis HTTP ${status}: ${code}${message ? `: ${message}` : ""}${reference ? ` Reference: ${reference}` : ""}`);
|
|
11
19
|
this.name = "TrellisHttpError";
|
|
12
20
|
this.status = status;
|
|
13
21
|
this.code = code;
|
|
22
|
+
this.reference = reference;
|
|
14
23
|
}
|
|
15
24
|
}
|
|
16
25
|
/** Decode one authoritative Trellis HTTP error envelope. */
|
|
17
26
|
export async function decodeTrellisHttpError(response) {
|
|
18
27
|
let code = INVALID_HTTP_ERROR_ENVELOPE;
|
|
19
28
|
let message;
|
|
29
|
+
let reference;
|
|
20
30
|
try {
|
|
21
31
|
const body = await response.json();
|
|
22
32
|
if (typeof body === "object" &&
|
|
@@ -31,12 +41,16 @@ export async function decodeTrellisHttpError(response) {
|
|
|
31
41
|
if ("message" in body.error && typeof body.error.message === "string") {
|
|
32
42
|
message = body.error.message;
|
|
33
43
|
}
|
|
44
|
+
if ("reference" in body.error &&
|
|
45
|
+
typeof body.error.reference === "string") {
|
|
46
|
+
reference = body.error.reference;
|
|
47
|
+
}
|
|
34
48
|
}
|
|
35
49
|
}
|
|
36
50
|
catch {
|
|
37
51
|
// The local code keeps malformed responses distinct from server error codes.
|
|
38
52
|
}
|
|
39
|
-
return new TrellisHttpError(response.status, code, message);
|
|
53
|
+
return new TrellisHttpError(response.status, code, message, reference);
|
|
40
54
|
}
|
|
41
55
|
/**
|
|
42
56
|
* Authorization codes that report in-flight materialization rather than denial.
|
package/auth/message_digests.js
CHANGED
|
@@ -205,6 +205,7 @@ export async function sessionEventSigningDigest(event, payload) {
|
|
|
205
205
|
encoder.encode(event.subject),
|
|
206
206
|
encoder.encode(event.eventId),
|
|
207
207
|
encoder.encode(event.eventTime),
|
|
208
|
+
i64(event.issuedAt, "issuedAt"),
|
|
208
209
|
await sha256([payload]),
|
|
209
210
|
])),
|
|
210
211
|
]);
|
|
Binary file
|
|
Binary file
|
package/auth/protocol_wasm.d.ts
CHANGED
|
@@ -121,7 +121,10 @@ export type SessionEvent = {
|
|
|
121
121
|
action: string;
|
|
122
122
|
subject: string;
|
|
123
123
|
eventId: string;
|
|
124
|
+
/** When the publisher recorded the event; it can precede signing. */
|
|
124
125
|
eventTime: string;
|
|
126
|
+
/** Unix seconds when the publisher signed this publication. */
|
|
127
|
+
issuedAt: number;
|
|
125
128
|
};
|
|
126
129
|
/** Stable error categories returned by local authorization verification. */
|
|
127
130
|
export type AuthorizationVerificationErrorCode = "InvalidInput" | "SerializationError" | "InvalidFormat" | "UnsafeJsonInteger" | "InvalidEncoding" | "InvalidPublicKey" | "InvalidKeyId" | "InvalidSignature" | "UnknownCriticalExtension" | "NonCanonicalSet" | "InvalidValidityWindow" | "IssuerRevoked" | "IssuerRetired" | "HistoricalContext" | "ContextNotYetValid" | "ContextExpired" | "ContextLifetimeExceeded" | "InvalidSessionKey" | "PermissionDenied" | "ScopeMismatch" | "SessionRevoked" | "ContextTooLarge" | "ProofIatOutOfRange" | "InvalidRequestProof" | "InvalidResponseProof" | "ReplySubjectMismatch" | "InvalidEventTime" | "InvalidEventProof" | "EventRevoked";
|