@codemem/core 0.48.1 → 0.49.0-beta.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/dist/coordinator-account-connection-schema.d.ts +1 -1
- package/dist/{coordinator-runtime-DjVICtRs.js → coordinator-runtime-Bdad5KeL.js} +164 -163
- package/dist/{coordinator-runtime-DjVICtRs.js.map → coordinator-runtime-Bdad5KeL.js.map} +1 -1
- package/dist/db.d.ts.map +1 -1
- package/dist/feed-contract.d.ts +59 -0
- package/dist/feed-contract.d.ts.map +1 -0
- package/dist/feed-contract.js +187 -0
- package/dist/feed-contract.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6553 -6534
- package/dist/index.js.map +1 -1
- package/dist/internal/cloudflare-coordinator.js +1015 -1014
- package/dist/internal/cloudflare-coordinator.js.map +1 -1
- package/dist/internal/relay-runtime.js +36 -36
- package/dist/{owner-enrollment-start-DFVkODlJ.js → owner-enrollment-start-DgToUaFZ.js} +884 -884
- package/dist/{owner-enrollment-start-DFVkODlJ.js.map → owner-enrollment-start-DgToUaFZ.js.map} +1 -1
- package/dist/raw-event-ingest.d.ts.map +1 -1
- package/dist/{relay-health-DhxMrW_S.js → relay-health-zrKtNQLQ.js} +16 -16
- package/dist/{relay-health-DhxMrW_S.js.map → relay-health-zrKtNQLQ.js.map} +1 -1
- package/dist/{relay-peer-client-CpY-lVbi.js → relay-peer-client-DdhDwDFz.js} +4437 -1978
- package/dist/relay-peer-client-DdhDwDFz.js.map +1 -0
- package/dist/schema-bootstrap.d.ts.map +1 -1
- package/dist/scope-membership-cache-read-B6z47l2W.js +4114 -0
- package/dist/scope-membership-cache-read-B6z47l2W.js.map +1 -0
- package/dist/scope-membership-cache-read.d.ts +60 -0
- package/dist/scope-membership-cache-read.d.ts.map +1 -0
- package/dist/scope-membership-cache.d.ts +2 -57
- package/dist/scope-membership-cache.d.ts.map +1 -1
- package/dist/scope-membership-semantics-B8qXaMqx.js +205 -0
- package/dist/scope-membership-semantics-B8qXaMqx.js.map +1 -0
- package/dist/semantic-worker-entry.js +1 -1
- package/dist/{semantic-worker-job-BmwXMG7v.js → semantic-worker-job-CMjFE5cp.js} +3 -3
- package/dist/{semantic-worker-job-BmwXMG7v.js.map → semantic-worker-job-CMjFE5cp.js.map} +1 -1
- package/dist/{semantic-worker-ranking-D31rfYAT.js → semantic-worker-ranking-it8Zs3qb.js} +18 -18
- package/dist/{semantic-worker-ranking-D31rfYAT.js.map → semantic-worker-ranking-it8Zs3qb.js.map} +1 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/{sync-auth-constants-Cb8-a8lE.js → sync-auth-constants-WKqJ9CX5.js} +2387 -2514
- package/dist/sync-auth-constants-WKqJ9CX5.js.map +1 -0
- package/dist/sync-reachability-pass-CQe7nZnN.js +2 -0
- package/dist/{sync-reachability-pass-EOj3hEau.js → sync-reachability-pass-CSg85Qmd.js} +2466 -2565
- package/dist/sync-reachability-pass-CSg85Qmd.js.map +1 -0
- package/dist/sync-status-indexes.d.ts +4 -0
- package/dist/sync-status-indexes.d.ts.map +1 -0
- package/dist/{validated-vector-index-audit-OuQct6jU.js → validated-vector-index-audit-B64yhEBF.js} +50 -50
- package/dist/validated-vector-index-audit-B64yhEBF.js.map +1 -0
- package/dist/vector-backfill-queue.d.ts +6 -0
- package/dist/vector-backfill-queue.d.ts.map +1 -1
- package/dist/vector-cutover-validation.d.ts +1 -0
- package/dist/vector-cutover-validation.d.ts.map +1 -1
- package/dist/vector-migration.d.ts +1 -0
- package/dist/vector-migration.d.ts.map +1 -1
- package/dist/vectors.d.ts +8 -2
- package/dist/vectors.d.ts.map +1 -1
- package/package.json +9 -4
- package/dist/relay-admission-proof-DjvC-e6G.js +0 -78
- package/dist/relay-admission-proof-DjvC-e6G.js.map +0 -1
- package/dist/relay-peer-client-CpY-lVbi.js.map +0 -1
- package/dist/scope-membership-cache-ByHJl5gt.js +0 -6549
- package/dist/scope-membership-cache-ByHJl5gt.js.map +0 -1
- package/dist/sync-auth-constants-Cb8-a8lE.js.map +0 -1
- package/dist/sync-reachability-pass-C6SYfltg.js +0 -2
- package/dist/sync-reachability-pass-EOj3hEau.js.map +0 -1
- package/dist/validated-vector-index-audit-OuQct6jU.js.map +0 -1
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { $ as
|
|
3
|
-
import { n as
|
|
4
|
-
import {
|
|
1
|
+
import { a as e, c as t, d as n, f as r, i, l as a, m as o, o as s, p as c, s as l, u } from "../scope-membership-semantics-B8qXaMqx.js";
|
|
2
|
+
import { $ as d, $r as f, $t as p, Ai as m, An as h, B as g, Br as _, Bt as ee, Ci as te, Cn as ne, Cr as v, Ct as re, Di as ie, Dn as y, Ei as ae, En as b, Et as oe, F as se, Fr as ce, G as le, Gr as ue, Gt as de, H as fe, Hr as pe, Ht as me, I as he, Ir as ge, Jn as _e, Jr as ve, K as ye, Kt as be, L as xe, Ln as Se, M as Ce, Mn as we, Mt as Te, N as Ee, Nn as De, Nr as Oe, O as ke, Ot as Ae, Pr as je, Pt as Me, Q as Ne, Qr as Pe, Qt as Fe, R as Ie, Rr as Le, Rt as Re, Si as ze, Sn as Be, St as Ve, Ti as He, Tn as Ue, Tt as We, U as Ge, Un as Ke, Ur as qe, Ut as Je, V as Ye, Vr as Xe, Vt as Ze, Wr as Qe, Wt as $e, X as et, Xn as tt, Xr as nt, Y as rt, Yr as it, Yt as at, Z as ot, Zr as st, Zt as ct, _i as lt, _n as ut, _t as dt, a as ft, ai as pt, ar as mt, at as ht, bi as gt, bn as x, bt as _t, c as vt, ci as yt, cn as S, cr as bt, ct as xt, d as St, di as Ct, dn as wt, dr as Tt, dt as Et, ei as Dt, en as Ot, et as kt, f as At, fn as jt, fr as Mt, ft as Nt, gi as Pt, gn as Ft, gt as It, hi as Lt, hn as Rt, ht as zt, i as Bt, ii as C, in as w, it as Vt, j as Ht, jn as Ut, jt as Wt, ki as Gt, kn as Kt, kt as qt, l as Jt, ln as Yt, lt as Xt, mn as Zt, mt as Qt, ni as $t, nn as en, nt as tn, o as nn, oi as rn, or as an, ot as on, p as sn, pn as cn, pr as ln, pt as un, q as dn, qn as fn, qr as pn, qt as mn, r as T, rn as hn, rr as gn, rt as _n, s as vn, sn as yn, sr as bn, st as xn, t as Sn, ti as Cn, tn as wn, tr as Tn, tt as En, u as Dn, un as On, ur as kn, ut as An, vi as jn, vn as Mn, vt as Nn, wn as E, wt as Pn, xi as Fn, xn as In, xr as Ln, xt as Rn, yi as zn, yr as Bn, yt as Vn, z as Hn, zr as Un, zt as Wn } from "../sync-auth-constants-WKqJ9CX5.js";
|
|
3
|
+
import { $ as Gn, B as Kn, C as qn, G as D, J as Jn, K as Yn, Q as Xn, R as Zn, W as O, X as Qn, Y as k, Z as $n, _ as er, a as tr, b as nr, c as rr, d as ir, et as ar, f as or, g as A, h as sr, i as cr, l as lr, m as ur, n as dr, nt as fr, o as pr, p as mr, q as hr, rt as gr, s as _r, st as vr, t as yr, tt as br, u as xr, x as Sr, y as Cr, z as wr } from "../owner-enrollment-start-DgToUaFZ.js";
|
|
4
|
+
import { n as Tr, t as Er } from "../relay-health-zrKtNQLQ.js";
|
|
5
|
+
import { i as Dr, n as Or, s as kr } from "../relay-quota-sqlite-C1th1yVy.js";
|
|
5
6
|
//#region src/coordinator-account-change-browser.ts
|
|
6
|
-
var
|
|
7
|
+
var Ar = Object.freeze({
|
|
7
8
|
start: "/auth/account/change/start",
|
|
8
9
|
confirm: "/auth/account/change/confirm"
|
|
9
10
|
});
|
|
10
|
-
function
|
|
11
|
+
function jr(e, t = 200) {
|
|
11
12
|
return new Response(e.body, {
|
|
12
13
|
status: t,
|
|
13
14
|
headers: e.headers
|
|
14
15
|
});
|
|
15
16
|
}
|
|
16
|
-
function
|
|
17
|
+
function Mr(e) {
|
|
17
18
|
return e.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll("\"", """).replaceAll("'", "'");
|
|
18
19
|
}
|
|
19
|
-
async function
|
|
20
|
+
async function j(e = 403) {
|
|
20
21
|
try {
|
|
21
|
-
return
|
|
22
|
+
return jr(await S("auth_unavailable"), e);
|
|
22
23
|
} catch {
|
|
23
24
|
return new Response("Account change unavailable. Return to your terminal and try again.", {
|
|
24
25
|
status: 503,
|
|
@@ -30,30 +31,30 @@ async function M(e = 403) {
|
|
|
30
31
|
});
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
|
-
async function
|
|
34
|
-
let i = (await
|
|
34
|
+
async function Nr(e, t, n, r = "") {
|
|
35
|
+
let i = (await S("auth_unavailable")).headers;
|
|
35
36
|
i["Referrer-Policy"] = "same-origin";
|
|
36
|
-
let a = Object.entries(n).map(([e, t]) => `<input type="hidden" name="${
|
|
37
|
-
return new Response(`<!doctype html><html lang="en"><meta charset="utf-8"><meta name="referrer" content="same-origin"><title>${
|
|
37
|
+
let a = Object.entries(n).map(([e, t]) => `<input type="hidden" name="${Mr(e)}" value="${Mr(t)}">`).join("");
|
|
38
|
+
return new Response(`<!doctype html><html lang="en"><meta charset="utf-8"><meta name="referrer" content="same-origin"><title>${Mr(e)}</title><main><h1>${Mr(e)}</h1><p>${Mr(r)}</p><form method="post" action="${t}">${a}<button type="submit">${Mr(e)}</button></form></main></html>`, { headers: i });
|
|
38
39
|
}
|
|
39
|
-
async function
|
|
40
|
+
async function Pr(e) {
|
|
40
41
|
let t = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(e));
|
|
41
42
|
return Array.from(new Uint8Array(t), (e) => e.toString(16).padStart(2, "0")).join("");
|
|
42
43
|
}
|
|
43
|
-
function
|
|
44
|
+
function Fr(e, t) {
|
|
44
45
|
if (e.length > 8192 || e.includes("#")) return null;
|
|
45
46
|
let n = new URL(e);
|
|
46
47
|
if (n.href !== e || `${n.origin}${n.pathname}` !== t || n.username || n.password || [...n.searchParams].length !== 2 || n.searchParams.getAll("attempt_id").length !== 1 || n.searchParams.getAll("start_code").length !== 1) return null;
|
|
47
48
|
let r = n.searchParams.get("attempt_id"), i = n.searchParams.get("start_code");
|
|
48
|
-
return !C(r) || !i || !
|
|
49
|
+
return !C(r) || !i || !je(i) ? null : {
|
|
49
50
|
attemptId: r,
|
|
50
51
|
startCode: i
|
|
51
52
|
};
|
|
52
53
|
}
|
|
53
|
-
async function
|
|
54
|
-
let i =
|
|
54
|
+
async function Ir(e, t, n, r) {
|
|
55
|
+
let i = je(n);
|
|
55
56
|
if (!i) return null;
|
|
56
|
-
let a = await
|
|
57
|
+
let a = await ge(i), o = await e.readStart({
|
|
57
58
|
attemptId: t,
|
|
58
59
|
browserStartHash: a
|
|
59
60
|
}, r);
|
|
@@ -62,51 +63,51 @@ async function Fr(e, t, n, r) {
|
|
|
62
63
|
intent: o.intent
|
|
63
64
|
};
|
|
64
65
|
}
|
|
65
|
-
async function
|
|
66
|
-
let r = await
|
|
66
|
+
async function Lr(e, t, n) {
|
|
67
|
+
let r = await O(e, t.existing, n);
|
|
67
68
|
if (r === "invalid" || r === "active") return !1;
|
|
68
|
-
let i = await
|
|
69
|
+
let i = await b(e, "transaction");
|
|
69
70
|
return i.kind === "absent" || i.kind === "present" && (await t.readers.readManagementActivity({ binderHash: i.cookieHash }, n)).kind === "inactive";
|
|
70
71
|
}
|
|
71
|
-
async function
|
|
72
|
-
return
|
|
72
|
+
async function Rr(e, t) {
|
|
73
|
+
return jr(await Yt({
|
|
73
74
|
destination: e.loopbackRedirect,
|
|
74
75
|
attemptId: e.attemptId,
|
|
75
76
|
completionSecret: t
|
|
76
77
|
}));
|
|
77
78
|
}
|
|
78
|
-
async function
|
|
79
|
-
let t = await
|
|
80
|
-
return t.kind === "invalid" ? null : t.kind === "present" ? t :
|
|
79
|
+
async function zr(e) {
|
|
80
|
+
let t = await b(e, "start");
|
|
81
|
+
return t.kind === "invalid" ? null : t.kind === "present" ? t : Ue("start");
|
|
81
82
|
}
|
|
82
|
-
async function
|
|
83
|
+
async function Br(e, t) {
|
|
83
84
|
let { input: n, config: r, scope: i, startUrl: a } = e;
|
|
84
85
|
try {
|
|
85
|
-
let e =
|
|
86
|
-
if (e.method !== "GET") return
|
|
87
|
-
let o =
|
|
88
|
-
if (!o) return
|
|
89
|
-
if (!await
|
|
90
|
-
if (!await
|
|
91
|
-
let s = await
|
|
92
|
-
if (!s) return
|
|
93
|
-
let c = await
|
|
86
|
+
let e = D(t);
|
|
87
|
+
if (e.method !== "GET") return j(405);
|
|
88
|
+
let o = Fr(e.url, a);
|
|
89
|
+
if (!o) return j(400);
|
|
90
|
+
if (!await Ir(n.readers, o.attemptId, o.startCode, r)) return j();
|
|
91
|
+
if (!await Lr(e.cookie, n, r)) return j(409);
|
|
92
|
+
let s = await zr(e.cookie);
|
|
93
|
+
if (!s) return j(400);
|
|
94
|
+
let c = await x(n.csrfKey, s.secret, "start", i), l = await Nr("Continue with Google", Ar.start, {
|
|
94
95
|
attempt_id: o.attemptId,
|
|
95
96
|
start_code: o.startCode,
|
|
96
97
|
csrf: c
|
|
97
98
|
});
|
|
98
99
|
return "setCookie" in s && l.headers.append("Set-Cookie", s.setCookie), l;
|
|
99
100
|
} catch {
|
|
100
|
-
return
|
|
101
|
+
return j(503);
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
|
-
async function
|
|
104
|
+
async function Vr(e, t, n) {
|
|
104
105
|
let { input: r, config: i, scope: a, startUrl: o } = e;
|
|
105
106
|
try {
|
|
106
|
-
let s =
|
|
107
|
-
if (s.method !== "POST") return
|
|
108
|
-
if (s.url !== o) return
|
|
109
|
-
let c = await
|
|
107
|
+
let s = D(t);
|
|
108
|
+
if (s.method !== "POST") return j(405);
|
|
109
|
+
if (s.url !== o) return j(404);
|
|
110
|
+
let c = await k({
|
|
110
111
|
request: t,
|
|
111
112
|
clientKey: n,
|
|
112
113
|
scope: a,
|
|
@@ -114,44 +115,44 @@ async function Br(e, t, n) {
|
|
|
114
115
|
limiter: r.limiter,
|
|
115
116
|
action: "link_start"
|
|
116
117
|
});
|
|
117
|
-
return c.ok ? c.action === "link_start" ? await
|
|
118
|
+
return c.ok ? c.action === "link_start" ? await Lr(s.cookie, r, i) ? await Hr(e, s.cookie, c) : j(409) : j() : j(c.error === "rate_limited" ? 429 : 403);
|
|
118
119
|
} catch {
|
|
119
|
-
return
|
|
120
|
+
return j(503);
|
|
120
121
|
}
|
|
121
122
|
}
|
|
122
|
-
async function
|
|
123
|
-
let { input: r, config: i, client: a } = e, o = await
|
|
124
|
-
if (!o || s.kind !== "present" || s.cookieHash !== n.cookieHash) return
|
|
125
|
-
let c = await a.createAuthorizationRequest(), l =
|
|
123
|
+
async function Hr(e, t, n) {
|
|
124
|
+
let { input: r, config: i, client: a } = e, o = await Ir(r.readers, n.attemptId, n.startCode, i), s = await b(t, "start");
|
|
125
|
+
if (!o || s.kind !== "present" || s.cookieHash !== n.cookieHash) return j();
|
|
126
|
+
let c = await a.createAuthorizationRequest(), l = jr(await cn({ authorizationUrl: c.authorizationUrl }));
|
|
126
127
|
return await r.operations.claimBrowser({
|
|
127
128
|
attemptId: n.attemptId,
|
|
128
129
|
browserStartHash: o.browserStartHash,
|
|
129
|
-
stateHash: await
|
|
130
|
+
stateHash: await Pr(c.material.state),
|
|
130
131
|
binderHash: n.cookieHash,
|
|
131
132
|
nonce: c.material.nonce,
|
|
132
133
|
pkceVerifier: c.material.pkceVerifier
|
|
133
|
-
}, i) ? (l.headers.append("Set-Cookie",
|
|
134
|
+
}, i) ? (l.headers.append("Set-Cookie", y(s.secret)), l.headers.append("Set-Cookie", E("start")), l) : j(409);
|
|
134
135
|
}
|
|
135
|
-
async function
|
|
136
|
-
let { config: n } = e, r =
|
|
136
|
+
async function Ur(e, t) {
|
|
137
|
+
let { config: n } = e, r = D(t);
|
|
137
138
|
if (r.method !== "GET" || r.url.length > 8192 || r.url.includes("#")) return null;
|
|
138
139
|
let i = new URL(r.url), a = new URL(n.redirectUri);
|
|
139
140
|
if (i.origin !== a.origin || i.pathname !== a.pathname || i.username || i.password || i.searchParams.getAll("state").length !== 1) return null;
|
|
140
141
|
let o = i.searchParams.get("state");
|
|
141
142
|
if (!o || !/^[A-Za-z0-9._~-]{43,128}$/.test(o)) return null;
|
|
142
|
-
let s = await
|
|
143
|
+
let s = await b(r.cookie, "transaction");
|
|
143
144
|
return s.kind === "present" ? {
|
|
144
145
|
state: o,
|
|
145
|
-
stateHash: await
|
|
146
|
+
stateHash: await Pr(o),
|
|
146
147
|
binderHash: s.cookieHash,
|
|
147
148
|
cookie: s,
|
|
148
149
|
callbackUrl: r.url
|
|
149
150
|
} : null;
|
|
150
151
|
}
|
|
151
|
-
async function
|
|
152
|
+
async function Wr(e, t) {
|
|
152
153
|
let { input: n, config: r } = e;
|
|
153
154
|
try {
|
|
154
|
-
let i = await
|
|
155
|
+
let i = await Ur(e, t);
|
|
155
156
|
return !!i && await n.operations.hasPendingCallback({
|
|
156
157
|
stateHash: i.stateHash,
|
|
157
158
|
binderHash: i.binderHash
|
|
@@ -160,18 +161,18 @@ async function Ur(e, t) {
|
|
|
160
161
|
return !1;
|
|
161
162
|
}
|
|
162
163
|
}
|
|
163
|
-
async function
|
|
164
|
+
async function Gr(e, t, n, r, i) {
|
|
164
165
|
let { input: a, config: o, scope: s } = e, c = await a.operations.readCallbackView(t, o);
|
|
165
166
|
if (!c || c.attemptId !== t.attemptId) throw Error("callback_unavailable");
|
|
166
|
-
if (c.intent === "refresh") return
|
|
167
|
+
if (c.intent === "refresh") return Rr(c, n);
|
|
167
168
|
if (c.intent !== "disconnect") throw Error("callback_unavailable");
|
|
168
|
-
let l = await
|
|
169
|
-
return
|
|
169
|
+
let l = await x(a.csrfKey, r.secret, "transaction", s), u = yn(i, o.issuer);
|
|
170
|
+
return Nr("Disconnect Google account", Ar.confirm, {
|
|
170
171
|
attempt_id: t.attemptId,
|
|
171
172
|
csrf: l
|
|
172
173
|
}, `${u.email ?? u.title}. Disconnecting ends browser sessions for this connection and removes its display profile. Identity, device keys, history, membership, and access grants stay unchanged.`);
|
|
173
174
|
}
|
|
174
|
-
async function
|
|
175
|
+
async function Kr(e, t) {
|
|
175
176
|
let { input: n, config: r } = e, i = await n.readers.readBrowserBinding(t, r);
|
|
176
177
|
if (!i || !/^[a-f0-9]{64}$/.test(i.stateHash)) return null;
|
|
177
178
|
let a = await n.operations.readBrowserView({
|
|
@@ -183,32 +184,32 @@ async function Gr(e, t) {
|
|
|
183
184
|
stateHash: i.stateHash
|
|
184
185
|
} : null;
|
|
185
186
|
}
|
|
186
|
-
async function
|
|
187
|
+
async function qr(e, t, n) {
|
|
187
188
|
let { input: r, config: i } = e;
|
|
188
189
|
try {
|
|
189
|
-
if (!C(n)) return
|
|
190
|
-
if (!
|
|
190
|
+
if (!C(n)) return j(503);
|
|
191
|
+
if (!Jn(t, r.limiter, JSON.stringify([
|
|
191
192
|
"browser-callback",
|
|
192
193
|
i.coordinatorId,
|
|
193
194
|
n
|
|
194
|
-
]), 20).allowed) return
|
|
195
|
-
let a = await
|
|
196
|
-
if (!a) return
|
|
195
|
+
]), 20).allowed) return j(429);
|
|
196
|
+
let a = await Ur(e, t);
|
|
197
|
+
if (!a) return j();
|
|
197
198
|
let o = {
|
|
198
199
|
stateHash: a.stateHash,
|
|
199
200
|
binderHash: a.binderHash
|
|
200
201
|
};
|
|
201
|
-
if (await r.existing.readAuthBrowserTransactionPurpose(o, i)) return
|
|
202
|
+
if (await r.existing.readAuthBrowserTransactionPurpose(o, i)) return j();
|
|
202
203
|
let s = await r.operations.consumeCallback(o, i);
|
|
203
|
-
return s ? await
|
|
204
|
+
return s ? await Jr(e, a, s, {
|
|
204
205
|
...o,
|
|
205
206
|
attemptId: s.attemptId
|
|
206
|
-
}) :
|
|
207
|
+
}) : j();
|
|
207
208
|
} catch {
|
|
208
|
-
return
|
|
209
|
+
return j(503);
|
|
209
210
|
}
|
|
210
211
|
}
|
|
211
|
-
async function
|
|
212
|
+
async function Jr(e, t, n, r) {
|
|
212
213
|
let { input: i, config: a, client: o } = e;
|
|
213
214
|
try {
|
|
214
215
|
if (!n.nonce || !n.pkceVerifier) throw Error("missing_material");
|
|
@@ -221,26 +222,26 @@ async function qr(e, t, n, r) {
|
|
|
221
222
|
}
|
|
222
223
|
});
|
|
223
224
|
if (!s.ok) throw Error("provider_rejected");
|
|
224
|
-
let c = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32)), l = await
|
|
225
|
+
let c = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32)), l = await Gr(e, r, ce(c), t.cookie, s.profile);
|
|
225
226
|
if (!await i.operations.recordVerifiedCallback({
|
|
226
227
|
...r,
|
|
227
228
|
issuer: s.account.issuer,
|
|
228
229
|
subject: s.account.subject,
|
|
229
230
|
profile: s.profile,
|
|
230
|
-
completionSecretHash: await
|
|
231
|
+
completionSecretHash: await ge(c)
|
|
231
232
|
}, a)) throw Error("account_rejected");
|
|
232
233
|
return l;
|
|
233
234
|
} catch {
|
|
234
|
-
return await i.operations.failConsumed(r, a),
|
|
235
|
+
return await i.operations.failConsumed(r, a), j();
|
|
235
236
|
}
|
|
236
237
|
}
|
|
237
|
-
async function
|
|
238
|
+
async function Yr(e, t, n) {
|
|
238
239
|
let { input: r, config: i, scope: a, confirmUrl: o } = e;
|
|
239
240
|
try {
|
|
240
|
-
let s =
|
|
241
|
-
if (s.method !== "POST") return
|
|
242
|
-
if (s.url !== o) return
|
|
243
|
-
let c = await
|
|
241
|
+
let s = D(t);
|
|
242
|
+
if (s.method !== "POST") return j(405);
|
|
243
|
+
if (s.url !== o) return j(404);
|
|
244
|
+
let c = await k({
|
|
244
245
|
request: t,
|
|
245
246
|
clientKey: n,
|
|
246
247
|
scope: a,
|
|
@@ -248,34 +249,34 @@ async function Jr(e, t, n) {
|
|
|
248
249
|
limiter: r.limiter,
|
|
249
250
|
action: "transaction_attempt"
|
|
250
251
|
});
|
|
251
|
-
if (!c.ok) return
|
|
252
|
-
if (c.action !== "transaction_attempt") return
|
|
253
|
-
let l = await
|
|
252
|
+
if (!c.ok) return j(c.error === "rate_limited" ? 429 : 403);
|
|
253
|
+
if (c.action !== "transaction_attempt") return j();
|
|
254
|
+
let l = await Kr(e, {
|
|
254
255
|
attemptId: c.attemptId,
|
|
255
256
|
binderHash: c.cookieHash
|
|
256
257
|
});
|
|
257
|
-
if (!l || !
|
|
258
|
-
let u = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32)), d = await
|
|
258
|
+
if (!l || !Xr(l, c)) return j();
|
|
259
|
+
let u = crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32)), d = await Rr(l, ce(u));
|
|
259
260
|
return await r.operations.confirmDisconnect({
|
|
260
261
|
attemptId: l.attemptId,
|
|
261
262
|
stateHash: l.stateHash,
|
|
262
263
|
binderHash: c.cookieHash,
|
|
263
|
-
completionSecretHash: await
|
|
264
|
-
}, i) ? d :
|
|
264
|
+
completionSecretHash: await ge(u)
|
|
265
|
+
}, i) ? d : j();
|
|
265
266
|
} catch {
|
|
266
|
-
return
|
|
267
|
+
return j(503);
|
|
267
268
|
}
|
|
268
269
|
}
|
|
269
|
-
function
|
|
270
|
+
function Xr(e, t) {
|
|
270
271
|
return e.attemptId === t.attemptId && e.intent === "disconnect" && e.state === "verified";
|
|
271
272
|
}
|
|
272
|
-
async function
|
|
273
|
-
let t =
|
|
273
|
+
async function Zr(e) {
|
|
274
|
+
let t = A(e.config);
|
|
274
275
|
if (t.kind !== "enabled") return {
|
|
275
276
|
ok: !1,
|
|
276
277
|
error: "browser_auth_unavailable"
|
|
277
278
|
};
|
|
278
|
-
if (!
|
|
279
|
+
if (!Mn(e.csrfKey) || !e.readers || [
|
|
279
280
|
"readStart",
|
|
280
281
|
"readManagementActivity",
|
|
281
282
|
"readBrowserBinding"
|
|
@@ -283,7 +284,7 @@ async function Xr(e) {
|
|
|
283
284
|
ok: !1,
|
|
284
285
|
error: "private_reader_required"
|
|
285
286
|
};
|
|
286
|
-
let n = await
|
|
287
|
+
let n = await sr(t.oidc, e.oidcOptions);
|
|
287
288
|
if (!n.ok) return n;
|
|
288
289
|
let r = {
|
|
289
290
|
input: e,
|
|
@@ -293,38 +294,38 @@ async function Xr(e) {
|
|
|
293
294
|
publicOrigin: t.publicOrigin,
|
|
294
295
|
store: t.store
|
|
295
296
|
},
|
|
296
|
-
startUrl: `${t.publicOrigin}${
|
|
297
|
-
confirmUrl: `${t.publicOrigin}${
|
|
297
|
+
startUrl: `${t.publicOrigin}${Ar.start}`,
|
|
298
|
+
confirmUrl: `${t.publicOrigin}${Ar.confirm}`
|
|
298
299
|
};
|
|
299
300
|
return {
|
|
300
301
|
ok: !0,
|
|
301
302
|
handlers: Object.freeze({
|
|
302
|
-
startPage: (e) =>
|
|
303
|
-
start: (e, t) =>
|
|
304
|
-
matchesCallback: (e) =>
|
|
305
|
-
callback: (e, t) =>
|
|
306
|
-
confirm: (e, t) =>
|
|
303
|
+
startPage: (e) => Br(r, e),
|
|
304
|
+
start: (e, t) => Vr(r, e, t),
|
|
305
|
+
matchesCallback: (e) => Wr(r, e),
|
|
306
|
+
callback: (e, t) => qr(r, e, t),
|
|
307
|
+
confirm: (e, t) => Yr(r, e, t)
|
|
307
308
|
})
|
|
308
309
|
};
|
|
309
310
|
}
|
|
310
311
|
//#endregion
|
|
311
312
|
//#region src/coordinator-browser-account.ts
|
|
312
|
-
function
|
|
313
|
+
function Qr(e) {
|
|
313
314
|
if (typeof e != "object" || !e || Array.isArray(e)) throw Error();
|
|
314
315
|
}
|
|
315
|
-
function
|
|
316
|
-
|
|
316
|
+
function $r(e) {
|
|
317
|
+
Qr(e);
|
|
317
318
|
let t = Object.getPrototypeOf(e);
|
|
318
319
|
if (t !== Object.prototype && t !== null) throw Error();
|
|
319
320
|
}
|
|
320
|
-
function
|
|
321
|
-
|
|
321
|
+
function M(e, t) {
|
|
322
|
+
Qr(e);
|
|
322
323
|
let n = Object.getOwnPropertyDescriptor(e, t);
|
|
323
324
|
if (!n || !Object.hasOwn(n, "value")) throw Error();
|
|
324
325
|
return n.value;
|
|
325
326
|
}
|
|
326
|
-
function
|
|
327
|
-
|
|
327
|
+
function ei(e, t) {
|
|
328
|
+
Qr(e);
|
|
328
329
|
let n = /* @__PURE__ */ new Set(), r = e;
|
|
329
330
|
for (; r !== null;) {
|
|
330
331
|
if (n.has(r)) throw Error();
|
|
@@ -338,13 +339,13 @@ function $r(e, t) {
|
|
|
338
339
|
}
|
|
339
340
|
throw Error();
|
|
340
341
|
}
|
|
341
|
-
function
|
|
342
|
+
function ti(e, t) {
|
|
342
343
|
return Object.freeze({
|
|
343
344
|
response: e,
|
|
344
345
|
outcome: t
|
|
345
346
|
});
|
|
346
347
|
}
|
|
347
|
-
function
|
|
348
|
+
function ni(e, t = 200, n) {
|
|
348
349
|
let r = new Headers(e.headers);
|
|
349
350
|
return r.set("Cache-Control", "no-store"), n && new Headers(n).forEach((e, t) => {
|
|
350
351
|
r.set(t, e);
|
|
@@ -353,8 +354,8 @@ function ti(e, t = 200, n) {
|
|
|
353
354
|
headers: r
|
|
354
355
|
});
|
|
355
356
|
}
|
|
356
|
-
function
|
|
357
|
-
return
|
|
357
|
+
function ri() {
|
|
358
|
+
return ti(new Response("Account unavailable. Try again.", {
|
|
358
359
|
status: 503,
|
|
359
360
|
headers: {
|
|
360
361
|
"Content-Type": "text/plain;charset=utf-8",
|
|
@@ -364,74 +365,74 @@ function ni() {
|
|
|
364
365
|
}
|
|
365
366
|
}), "internal_error");
|
|
366
367
|
}
|
|
367
|
-
async function
|
|
368
|
+
async function N(e, t, n) {
|
|
368
369
|
try {
|
|
369
|
-
return
|
|
370
|
+
return ti(ni(await S(e === 200 ? "signed_out" : "auth_unavailable"), e, n), t);
|
|
370
371
|
} catch {
|
|
371
|
-
return
|
|
372
|
+
return ri();
|
|
372
373
|
}
|
|
373
374
|
}
|
|
374
|
-
function
|
|
375
|
-
return e.method === n ? e.url === t ? null :
|
|
375
|
+
function ii(e, t, n) {
|
|
376
|
+
return e.method === n ? e.url === t ? null : N(404, "not_found") : N(405, "method_not_allowed", { Allow: n });
|
|
376
377
|
}
|
|
377
|
-
function
|
|
378
|
-
|
|
379
|
-
let n =
|
|
380
|
-
|
|
381
|
-
let r =
|
|
378
|
+
function ai(e, t) {
|
|
379
|
+
$r(e);
|
|
380
|
+
let n = M(e, "account");
|
|
381
|
+
$r(n);
|
|
382
|
+
let r = M(n, "issuer"), i = M(e, "identityId");
|
|
382
383
|
if (r !== t.storeConfig.issuer || !C(i)) throw Error();
|
|
383
384
|
return i;
|
|
384
385
|
}
|
|
385
|
-
async function
|
|
386
|
+
async function oi(e, t) {
|
|
386
387
|
try {
|
|
387
|
-
let n =
|
|
388
|
+
let n = D(t), r = ii(n, `${e.publicOrigin}/auth/account`, "GET");
|
|
388
389
|
if (r) return await r;
|
|
389
|
-
let i = await
|
|
390
|
-
if (i.kind === "invalid") return await
|
|
391
|
-
if (i.kind === "absent") return await
|
|
390
|
+
let i = await b(n.cookie, "session");
|
|
391
|
+
if (i.kind === "invalid") return await N(200, "cookie_invalid");
|
|
392
|
+
if (i.kind === "absent") return await N(200, "signed_out");
|
|
392
393
|
let a = await e.store.readAuthSessionAccount(i.cookieHash, e.storeConfig);
|
|
393
|
-
if (a === null) return await
|
|
394
|
-
|
|
395
|
-
let o =
|
|
396
|
-
return
|
|
394
|
+
if (a === null) return await N(200, "signed_out");
|
|
395
|
+
$r(a);
|
|
396
|
+
let o = ai(M(a, "session"), e), s = M(a, "profile"), c = await x(e.csrfKey, i.secret, "session", e.scope);
|
|
397
|
+
return ti(ni(await Rt({
|
|
397
398
|
profile: s,
|
|
398
399
|
issuer: e.storeConfig.issuer,
|
|
399
400
|
identity: { id: o },
|
|
400
401
|
csrfToken: c
|
|
401
402
|
})), "account_page");
|
|
402
403
|
} catch {
|
|
403
|
-
return await
|
|
404
|
+
return await N(503, "internal_error");
|
|
404
405
|
}
|
|
405
406
|
}
|
|
406
|
-
function
|
|
407
|
+
function si(e) {
|
|
407
408
|
switch (e.error) {
|
|
408
|
-
case "origin_rejected": return
|
|
409
|
-
case "rate_limited": return
|
|
410
|
-
case "cookie_missing": return
|
|
411
|
-
case "unsupported_media_type": return
|
|
412
|
-
case "body_too_large": return
|
|
413
|
-
case "form_invalid": return
|
|
409
|
+
case "origin_rejected": return N(403, e.error);
|
|
410
|
+
case "rate_limited": return N(429, e.error, { "Retry-After": String(e.retryAfterS) });
|
|
411
|
+
case "cookie_missing": return N(200, "signed_out");
|
|
412
|
+
case "unsupported_media_type": return N(415, e.error);
|
|
413
|
+
case "body_too_large": return N(413, e.error);
|
|
414
|
+
case "form_invalid": return N(400, e.error);
|
|
414
415
|
case "cookie_invalid":
|
|
415
|
-
case "csrf_invalid": return
|
|
416
|
-
default: return
|
|
416
|
+
case "csrf_invalid": return N(403, e.error);
|
|
417
|
+
default: return N(503, "internal_error");
|
|
417
418
|
}
|
|
418
419
|
}
|
|
419
|
-
async function
|
|
420
|
-
let n =
|
|
421
|
-
n.headers.append("Set-Cookie",
|
|
420
|
+
async function ci(e, t) {
|
|
421
|
+
let n = ni(await S("signed_out"));
|
|
422
|
+
n.headers.append("Set-Cookie", E("session"));
|
|
422
423
|
let r = await e.store.readAuthSession(t, e.storeConfig);
|
|
423
|
-
if (r === null) return
|
|
424
|
-
|
|
424
|
+
if (r === null) return ti(n, "already_signed_out");
|
|
425
|
+
ai(r, e);
|
|
425
426
|
let i = await e.store.signOutAuthSession(t, e.signoutScope);
|
|
426
|
-
if (
|
|
427
|
+
if ($r(i), M(i, "kind") !== "signed_out") return N(503, "internal_error");
|
|
427
428
|
let a = await e.store.readAuthSession(t, e.storeConfig);
|
|
428
|
-
return a === null ?
|
|
429
|
+
return a === null ? ti(n, "signed_out") : (ai(a, e), N(503, "signout_unconfirmed"));
|
|
429
430
|
}
|
|
430
|
-
async function
|
|
431
|
+
async function li(e, t, n) {
|
|
431
432
|
try {
|
|
432
|
-
let r =
|
|
433
|
+
let r = D(t), i = ii(r, `${e.publicOrigin}${en.signOut}`, "POST");
|
|
433
434
|
if (i) return await i;
|
|
434
|
-
let a = await
|
|
435
|
+
let a = await k({
|
|
435
436
|
request: t,
|
|
436
437
|
scope: e.scope,
|
|
437
438
|
csrfKey: e.csrfKey,
|
|
@@ -439,25 +440,25 @@ async function ci(e, t, n) {
|
|
|
439
440
|
limiter: e.limiter,
|
|
440
441
|
clientKey: n
|
|
441
442
|
});
|
|
442
|
-
if (!a.ok) return await
|
|
443
|
-
if (a.action !== "session_logout") return await
|
|
444
|
-
let o = await
|
|
445
|
-
return o.kind !== "present" || o.cookieHash !== a.cookieHash ? await
|
|
443
|
+
if (!a.ok) return await si(a);
|
|
444
|
+
if (a.action !== "session_logout") return await N(503, "internal_error");
|
|
445
|
+
let o = await b(r.cookie, "session");
|
|
446
|
+
return o.kind !== "present" || o.cookieHash !== a.cookieHash ? await N(503, "internal_error") : await ci(e, o.cookieHash);
|
|
446
447
|
} catch {
|
|
447
|
-
return await
|
|
448
|
+
return await N(503, "internal_error");
|
|
448
449
|
}
|
|
449
450
|
}
|
|
450
|
-
function
|
|
451
|
-
let t =
|
|
451
|
+
function ui(e) {
|
|
452
|
+
let t = ei(e, "readAuthSessionAccount"), n = ei(e, "readAuthSession"), r = ei(e, "signOutAuthSession");
|
|
452
453
|
return Object.freeze({
|
|
453
454
|
readAuthSessionAccount: t.bind(e),
|
|
454
455
|
readAuthSession: n.bind(e),
|
|
455
456
|
signOutAuthSession: r.bind(e)
|
|
456
457
|
});
|
|
457
458
|
}
|
|
458
|
-
async function
|
|
459
|
+
async function di(e) {
|
|
459
460
|
try {
|
|
460
|
-
let t =
|
|
461
|
+
let t = M(e, "config"), n = A(t);
|
|
461
462
|
if (n.kind === "disabled") return Object.freeze({
|
|
462
463
|
ok: !1,
|
|
463
464
|
error: "browser_auth_disabled"
|
|
@@ -467,10 +468,10 @@ async function ui(e) {
|
|
|
467
468
|
error: "browser_auth_config_invalid",
|
|
468
469
|
field: n.field
|
|
469
470
|
});
|
|
470
|
-
let r =
|
|
471
|
-
|
|
472
|
-
let i =
|
|
473
|
-
|
|
471
|
+
let r = M(e, "csrfKey");
|
|
472
|
+
Qr(r);
|
|
473
|
+
let i = ui(M(e, "store")), a = M(e, "limiter");
|
|
474
|
+
ei(a, "check");
|
|
474
475
|
let o = Object.freeze({
|
|
475
476
|
storeConfig: n.store,
|
|
476
477
|
publicOrigin: n.publicOrigin,
|
|
@@ -486,8 +487,8 @@ async function ui(e) {
|
|
|
486
487
|
return Object.freeze({
|
|
487
488
|
ok: !0,
|
|
488
489
|
handlers: Object.freeze({
|
|
489
|
-
account: (e) =>
|
|
490
|
-
logout: (e, t) =>
|
|
490
|
+
account: (e) => oi(o, e),
|
|
491
|
+
logout: (e, t) => li(o, e, t)
|
|
491
492
|
})
|
|
492
493
|
});
|
|
493
494
|
} catch {
|
|
@@ -499,13 +500,13 @@ async function ui(e) {
|
|
|
499
500
|
}
|
|
500
501
|
//#endregion
|
|
501
502
|
//#region src/coordinator-browser-auth-callback.ts
|
|
502
|
-
function
|
|
503
|
+
function P(e, t) {
|
|
503
504
|
if (typeof e != "object" || !e || Array.isArray(e)) throw Error();
|
|
504
505
|
let n = Object.getOwnPropertyDescriptor(e, t);
|
|
505
506
|
if (n && !Object.hasOwn(n, "value")) throw Error();
|
|
506
507
|
return n?.value;
|
|
507
508
|
}
|
|
508
|
-
function
|
|
509
|
+
function fi(e, t) {
|
|
509
510
|
if (typeof e != "object" || !e || Array.isArray(e)) throw Error();
|
|
510
511
|
let n = /* @__PURE__ */ new Set(), r = e;
|
|
511
512
|
for (; r !== null;) {
|
|
@@ -520,8 +521,8 @@ function di(e, t) {
|
|
|
520
521
|
}
|
|
521
522
|
throw Error();
|
|
522
523
|
}
|
|
523
|
-
function
|
|
524
|
-
let t =
|
|
524
|
+
function pi(e) {
|
|
525
|
+
let t = fi(e, "consumeAuthBrowserTransaction"), n = fi(e, "readAuthSession"), r = fi(e, "signInWithConsumedBrowserTransaction"), i = fi(e, "recordAuthAccountProfile");
|
|
525
526
|
return Object.freeze({
|
|
526
527
|
consumeAuthBrowserTransaction: (...n) => Reflect.apply(t, e, n),
|
|
527
528
|
readAuthSession: (...t) => Reflect.apply(n, e, t),
|
|
@@ -529,16 +530,16 @@ function fi(e) {
|
|
|
529
530
|
recordAuthAccountProfile: (...t) => Reflect.apply(i, e, t)
|
|
530
531
|
});
|
|
531
532
|
}
|
|
532
|
-
function
|
|
533
|
-
let t =
|
|
533
|
+
function mi(e) {
|
|
534
|
+
let t = P(e, "oidcOptions");
|
|
534
535
|
if (t === void 0) return;
|
|
535
|
-
let n =
|
|
536
|
+
let n = P(t, "fetch"), r = P(t, "timeoutSeconds");
|
|
536
537
|
return Object.freeze({
|
|
537
538
|
fetch: n,
|
|
538
539
|
timeoutSeconds: r
|
|
539
540
|
});
|
|
540
541
|
}
|
|
541
|
-
function
|
|
542
|
+
function hi(e, t) {
|
|
542
543
|
let n = e;
|
|
543
544
|
for (; n !== null;) {
|
|
544
545
|
let e = Object.getOwnPropertyDescriptor(n, t);
|
|
@@ -546,30 +547,30 @@ function mi(e, t) {
|
|
|
546
547
|
n = Object.getPrototypeOf(n);
|
|
547
548
|
}
|
|
548
549
|
}
|
|
549
|
-
var
|
|
550
|
-
method:
|
|
551
|
-
url:
|
|
552
|
-
headers:
|
|
553
|
-
}),
|
|
554
|
-
function
|
|
555
|
-
let t =
|
|
550
|
+
var gi = Object.freeze({
|
|
551
|
+
method: hi(Request.prototype, "method"),
|
|
552
|
+
url: hi(Request.prototype, "url"),
|
|
553
|
+
headers: hi(Request.prototype, "headers")
|
|
554
|
+
}), _i = Headers.prototype.get, vi = hi(Response.prototype, "status");
|
|
555
|
+
function yi(e) {
|
|
556
|
+
let t = gi.method?.call(e), n = gi.url?.call(e), r = gi.headers?.call(e);
|
|
556
557
|
if (typeof t != "string" || typeof n != "string") throw Error();
|
|
557
558
|
return Object.freeze({
|
|
558
559
|
method: t,
|
|
559
560
|
url: n,
|
|
560
|
-
cookie:
|
|
561
|
+
cookie: _i.call(r, "cookie")
|
|
561
562
|
});
|
|
562
563
|
}
|
|
563
|
-
function
|
|
564
|
+
function F(e, t) {
|
|
564
565
|
return Object.freeze({
|
|
565
566
|
response: e,
|
|
566
567
|
outcome: t
|
|
567
568
|
});
|
|
568
569
|
}
|
|
569
|
-
async function
|
|
570
|
+
async function I(e, t, n = {}) {
|
|
570
571
|
try {
|
|
571
|
-
let r = await
|
|
572
|
-
return n.allow && i.set("Allow", n.allow),
|
|
572
|
+
let r = await S("auth_unavailable"), i = new Headers(r.headers);
|
|
573
|
+
return n.allow && i.set("Allow", n.allow), F(new Response(r.body, {
|
|
573
574
|
status: e,
|
|
574
575
|
headers: i
|
|
575
576
|
}), t);
|
|
@@ -580,13 +581,13 @@ async function L(e, t, n = {}) {
|
|
|
580
581
|
"Referrer-Policy": "no-referrer",
|
|
581
582
|
"X-Content-Type-Options": "nosniff"
|
|
582
583
|
});
|
|
583
|
-
return n.allow && e.set("Allow", n.allow),
|
|
584
|
+
return n.allow && e.set("Allow", n.allow), F(new Response("Sign-in or linking unavailable. Return to the flow you started and try again.", {
|
|
584
585
|
status: 503,
|
|
585
586
|
headers: e
|
|
586
587
|
}), "internal_error");
|
|
587
588
|
}
|
|
588
589
|
}
|
|
589
|
-
function
|
|
590
|
+
function bi(e, t) {
|
|
590
591
|
let n = new Headers({
|
|
591
592
|
Location: new URL("/auth/account", e.publicOrigin).href,
|
|
592
593
|
"Cache-Control": "no-store",
|
|
@@ -597,7 +598,7 @@ function yi(e, t) {
|
|
|
597
598
|
headers: n
|
|
598
599
|
});
|
|
599
600
|
}
|
|
600
|
-
function
|
|
601
|
+
function xi(e, t) {
|
|
601
602
|
if (t.url.length > 8192 || t.url.includes("#")) return { error: "callback_invalid" };
|
|
602
603
|
let n;
|
|
603
604
|
try {
|
|
@@ -610,11 +611,11 @@ function bi(e, t) {
|
|
|
610
611
|
let i = n.searchParams.getAll("state"), a = i[0];
|
|
611
612
|
return i.length !== 1 || typeof a != "string" || a.length < 43 || a.length > 128 || !/^[A-Za-z0-9._~-]+$/.test(a) ? { error: "state_invalid" } : { state: a };
|
|
612
613
|
}
|
|
613
|
-
async function
|
|
614
|
+
async function Si(e) {
|
|
614
615
|
let t = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(e));
|
|
615
616
|
return Array.from(new Uint8Array(t), (e) => e.toString(16).padStart(2, "0")).join("");
|
|
616
617
|
}
|
|
617
|
-
async function
|
|
618
|
+
async function Ci(e, t, n, r) {
|
|
618
619
|
try {
|
|
619
620
|
let i = await e.client.verifyCallback({
|
|
620
621
|
callbackUrl: t.url,
|
|
@@ -641,7 +642,7 @@ async function Si(e, t, n, r) {
|
|
|
641
642
|
});
|
|
642
643
|
}
|
|
643
644
|
}
|
|
644
|
-
async function
|
|
645
|
+
async function wi(e, t, n, r) {
|
|
645
646
|
try {
|
|
646
647
|
let i = await e.completeLink(Object.freeze({
|
|
647
648
|
attemptId: t.attemptId,
|
|
@@ -650,70 +651,70 @@ async function Ci(e, t, n, r) {
|
|
|
650
651
|
transactionCookieHash: n.cookieHash,
|
|
651
652
|
verification: r
|
|
652
653
|
}));
|
|
653
|
-
if (!
|
|
654
|
-
return
|
|
654
|
+
if (!vi || typeof Reflect.apply(vi, i, []) != "number") throw Error();
|
|
655
|
+
return F(i, "link_dispatched");
|
|
655
656
|
} catch {
|
|
656
|
-
return
|
|
657
|
+
return I(503, "link_continuation_failed");
|
|
657
658
|
}
|
|
658
659
|
}
|
|
659
|
-
async function
|
|
660
|
+
async function Ti(e, t, n, r) {
|
|
660
661
|
try {
|
|
661
662
|
if ((await e.store.recordAuthAccountProfile({
|
|
662
663
|
credentialHash: t,
|
|
663
664
|
profile: n.profile
|
|
664
|
-
}, e.storeConfig)).kind === "recorded") return
|
|
665
|
+
}, e.storeConfig)).kind === "recorded") return F(r, "signed_in");
|
|
665
666
|
} catch {}
|
|
666
|
-
return
|
|
667
|
+
return F(r, "signed_in_profile_not_recorded");
|
|
667
668
|
}
|
|
668
|
-
async function
|
|
669
|
-
if (!r.ok) return
|
|
670
|
-
let i = await
|
|
669
|
+
async function Ei(e, t, n, r) {
|
|
670
|
+
if (!r.ok) return I(403, "verification_failed");
|
|
671
|
+
let i = await b(t.cookie, "session");
|
|
671
672
|
if (i.kind === "invalid") throw Error();
|
|
672
|
-
if (i.kind === "present" && await e.store.readAuthSession(i.cookieHash, e.storeConfig)) return
|
|
673
|
-
let a = await
|
|
673
|
+
if (i.kind === "present" && await e.store.readAuthSession(i.cookieHash, e.storeConfig)) return F(bi(e), "session_live");
|
|
674
|
+
let a = await Ue("session"), o = bi(e, a.setCookie);
|
|
674
675
|
return (await e.store.signInWithConsumedBrowserTransaction({
|
|
675
676
|
browserTransactionHash: n.browserTransactionHash,
|
|
676
677
|
account: r.account,
|
|
677
678
|
credentialHash: a.cookieHash
|
|
678
|
-
}, e.storeConfig)).kind === "issued" ?
|
|
679
|
+
}, e.storeConfig)).kind === "issued" ? Ti(e, a.cookieHash, r, o) : I(403, "signin_rejected");
|
|
679
680
|
}
|
|
680
|
-
async function
|
|
681
|
+
async function Di(e, t, n, r, i) {
|
|
681
682
|
if (!e.readPurpose) return null;
|
|
682
683
|
let a = await e.readPurpose({
|
|
683
684
|
stateHash: r,
|
|
684
685
|
binderHash: i
|
|
685
686
|
}, e.storeConfig), o = a === "owner_enroll" ? await e.deviceRebindCallback?.(t) : null;
|
|
686
|
-
return o ?
|
|
687
|
+
return o ? F(o, "device_rebind_dispatched") : a === "owner_enroll" && e.ownerCallback ? F(await e.ownerCallback(t, n), "owner_dispatched") : a === "signin" || a === "link" ? null : I(403, "transaction_unavailable");
|
|
687
688
|
}
|
|
688
|
-
async function
|
|
689
|
+
async function Oi(e, t, n) {
|
|
689
690
|
try {
|
|
690
|
-
let r =
|
|
691
|
-
if (r.method !== "GET") return await
|
|
692
|
-
let i =
|
|
693
|
-
if ("error" in i) return await
|
|
694
|
-
let a = await
|
|
695
|
-
if (a.kind === "invalid") return await
|
|
696
|
-
if (a.kind === "absent") return await
|
|
697
|
-
let o = await
|
|
698
|
-
if (s) return
|
|
699
|
-
let c = await
|
|
691
|
+
let r = yi(t);
|
|
692
|
+
if (r.method !== "GET") return await I(405, "method_not_allowed", { allow: "GET" });
|
|
693
|
+
let i = xi(e, r);
|
|
694
|
+
if ("error" in i) return await I(i.error === "not_found" ? 404 : 400, i.error);
|
|
695
|
+
let a = await b(r.cookie, "transaction");
|
|
696
|
+
if (a.kind === "invalid") return await I(400, "cookie_invalid");
|
|
697
|
+
if (a.kind === "absent") return await I(403, "cookie_missing");
|
|
698
|
+
let o = await Si(i.state), s = await e.accountChangeCallback?.(t, n ?? "", a.cookieHash);
|
|
699
|
+
if (s) return F(s, "account_change_dispatched");
|
|
700
|
+
let c = await Di(e, t, n, o, a.cookieHash);
|
|
700
701
|
if (c) return c;
|
|
701
702
|
let l = await e.store.consumeAuthBrowserTransaction({
|
|
702
703
|
stateHash: o,
|
|
703
704
|
binderHash: a.cookieHash
|
|
704
705
|
}, e.storeConfig);
|
|
705
|
-
if (l.kind !== "consumed") return await
|
|
706
|
-
let u = await
|
|
707
|
-
if (l.purpose === "link") return await
|
|
706
|
+
if (l.kind !== "consumed") return await I(403, "transaction_unavailable");
|
|
707
|
+
let u = await Ci(e, r, i.state, l);
|
|
708
|
+
if (l.purpose === "link") return await wi(e, l, a, u);
|
|
708
709
|
if (l.purpose !== "signin") throw Error();
|
|
709
|
-
return await
|
|
710
|
+
return await Ei(e, r, l, u);
|
|
710
711
|
} catch {
|
|
711
|
-
return
|
|
712
|
+
return I(503, "internal_error");
|
|
712
713
|
}
|
|
713
714
|
}
|
|
714
|
-
async function
|
|
715
|
+
async function ki(e) {
|
|
715
716
|
try {
|
|
716
|
-
let t =
|
|
717
|
+
let t = A(P(e, "config"));
|
|
717
718
|
if (t.kind === "disabled") return Object.freeze({
|
|
718
719
|
ok: !1,
|
|
719
720
|
error: "browser_auth_disabled"
|
|
@@ -723,19 +724,19 @@ async function Oi(e) {
|
|
|
723
724
|
error: "browser_auth_config_invalid",
|
|
724
725
|
field: t.field
|
|
725
726
|
});
|
|
726
|
-
let n =
|
|
727
|
+
let n = P(e, "completeLink");
|
|
727
728
|
if (typeof n != "function") throw Error();
|
|
728
|
-
let r =
|
|
729
|
+
let r = pi(P(e, "store")), i = P(e, "ownerCallback"), a = P(e, "accountChangeCallback");
|
|
729
730
|
if (a !== void 0 && typeof a != "function") throw Error();
|
|
730
|
-
let o =
|
|
731
|
+
let o = P(e, "deviceRebindCallback");
|
|
731
732
|
if (o !== void 0 && typeof o != "function") throw Error();
|
|
732
733
|
let s;
|
|
733
734
|
if (i !== void 0 && typeof i != "function") throw Error();
|
|
734
735
|
if (i !== void 0 || o !== void 0) {
|
|
735
|
-
let t =
|
|
736
|
+
let t = P(e, "purposeStore"), n = fi(t, "readAuthBrowserTransactionPurpose");
|
|
736
737
|
s = (...e) => Reflect.apply(n, t, e);
|
|
737
738
|
}
|
|
738
|
-
let c =
|
|
739
|
+
let c = mi(e), l = await sr(t.oidc, c);
|
|
739
740
|
if (!l.ok) return Object.freeze({
|
|
740
741
|
ok: !1,
|
|
741
742
|
error: l.error
|
|
@@ -754,7 +755,7 @@ async function Oi(e) {
|
|
|
754
755
|
});
|
|
755
756
|
return Object.freeze({
|
|
756
757
|
ok: !0,
|
|
757
|
-
handlers: Object.freeze({ callback: (e, t = "") =>
|
|
758
|
+
handlers: Object.freeze({ callback: (e, t = "") => Oi(u, e, t) })
|
|
758
759
|
});
|
|
759
760
|
} catch {
|
|
760
761
|
return Object.freeze({
|
|
@@ -765,34 +766,34 @@ async function Oi(e) {
|
|
|
765
766
|
}
|
|
766
767
|
//#endregion
|
|
767
768
|
//#region src/coordinator-auth-headless-code-limits.ts
|
|
768
|
-
var
|
|
769
|
-
async function
|
|
770
|
-
if (typeof t != "string" || t.length === 0 || t.length >
|
|
769
|
+
var Ai = 9e5, ji = 256, Mi = 1024, Ni = /^[0-9a-f]{64}$/;
|
|
770
|
+
async function Pi(e, t) {
|
|
771
|
+
if (typeof t != "string" || t.length === 0 || t.length > Mi) throw Error("headless_code_entry_invalid_input");
|
|
771
772
|
let n = await globalThis.crypto.subtle.sign("HMAC", e, new TextEncoder().encode(t));
|
|
772
773
|
return Array.from(new Uint8Array(n), (e) => e.toString(16).padStart(2, "0")).join("");
|
|
773
774
|
}
|
|
774
|
-
function
|
|
775
|
+
function Fi(e) {
|
|
775
776
|
let { coordinatorId: t, clientKeyHash: n, nowMs: r } = e;
|
|
776
|
-
if (typeof t != "string" || t.length === 0 || t.length >
|
|
777
|
+
if (typeof t != "string" || t.length === 0 || t.length > ji || typeof n != "string" || !Ni.test(n) || !Number.isSafeInteger(r) || r < 0) throw Error("headless_code_entry_invalid_input");
|
|
777
778
|
return {
|
|
778
779
|
coordinatorId: t,
|
|
779
780
|
clientKeyHash: n,
|
|
780
781
|
nowMs: r
|
|
781
782
|
};
|
|
782
783
|
}
|
|
783
|
-
var
|
|
784
|
+
var Ii = `INSERT INTO ${Ke} (coordinator_id, scope, key_hash, window_start_ms, failures)
|
|
784
785
|
VALUES (?, ?, ?, ?, 1)
|
|
785
786
|
ON CONFLICT (coordinator_id, scope, key_hash) DO UPDATE SET
|
|
786
|
-
failures = CASE WHEN window_start_ms + ${
|
|
787
|
+
failures = CASE WHEN window_start_ms + ${Ai} <= excluded.window_start_ms
|
|
787
788
|
THEN 1 ELSE failures + 1 END,
|
|
788
|
-
window_start_ms = CASE WHEN window_start_ms + ${
|
|
789
|
+
window_start_ms = CASE WHEN window_start_ms + ${Ai} <= excluded.window_start_ms
|
|
789
790
|
THEN excluded.window_start_ms ELSE window_start_ms END
|
|
790
|
-
RETURNING failures, window_start_ms`,
|
|
791
|
-
SELECT coordinator_id, scope, key_hash FROM ${
|
|
792
|
-
WHERE window_start_ms + ${
|
|
793
|
-
async function
|
|
791
|
+
RETURNING failures, window_start_ms`, Li = `DELETE FROM ${Ke} WHERE (coordinator_id, scope, key_hash) IN (
|
|
792
|
+
SELECT coordinator_id, scope, key_hash FROM ${Ke}
|
|
793
|
+
WHERE window_start_ms + ${Ai} <= ? LIMIT 32)`;
|
|
794
|
+
async function Ri(e, t, n) {
|
|
794
795
|
let r = n === "client" ? t.clientKeyHash : "", i = await e.first({
|
|
795
|
-
sql:
|
|
796
|
+
sql: Ii,
|
|
796
797
|
values: [
|
|
797
798
|
t.coordinatorId,
|
|
798
799
|
n,
|
|
@@ -803,116 +804,116 @@ async function Li(e, t, n) {
|
|
|
803
804
|
if (!i || !Number.isSafeInteger(i.failures) || !Number.isSafeInteger(i.window_start_ms)) throw Error("headless_code_entry_unavailable");
|
|
804
805
|
return i;
|
|
805
806
|
}
|
|
806
|
-
function
|
|
807
|
-
let n = e.window_start_ms +
|
|
807
|
+
function zi(e, t) {
|
|
808
|
+
let n = e.window_start_ms + Ai - t;
|
|
808
809
|
return {
|
|
809
810
|
allowed: !1,
|
|
810
|
-
retryAfterMs: Math.min(Math.max(n, 1),
|
|
811
|
+
retryAfterMs: Math.min(Math.max(n, 1), Ai)
|
|
811
812
|
};
|
|
812
813
|
}
|
|
813
|
-
async function
|
|
814
|
-
let n =
|
|
814
|
+
async function Bi(e, t) {
|
|
815
|
+
let n = Fi(t);
|
|
815
816
|
await e.run({
|
|
816
|
-
sql:
|
|
817
|
+
sql: Li,
|
|
817
818
|
values: [n.nowMs]
|
|
818
819
|
});
|
|
819
|
-
let r = await
|
|
820
|
-
if (r.failures > 10) return
|
|
821
|
-
let i = await
|
|
822
|
-
return i.failures > 200 ?
|
|
820
|
+
let r = await Ri(e, n, "client");
|
|
821
|
+
if (r.failures > 10) return zi(r, n.nowMs);
|
|
822
|
+
let i = await Ri(e, n, "coordinator");
|
|
823
|
+
return i.failures > 200 ? zi(i, n.nowMs) : { allowed: !0 };
|
|
823
824
|
}
|
|
824
825
|
//#endregion
|
|
825
826
|
//#region src/coordinator-browser-headless-link.ts
|
|
826
|
-
var
|
|
827
|
-
function
|
|
827
|
+
var Vi = "codemem-headless-code-entry-client-v1", Hi = 400, Ui = Headers.prototype.get, Wi = Object.getOwnPropertyDescriptor(Request.prototype, "headers")?.get;
|
|
828
|
+
function Gi(e, t = 200) {
|
|
828
829
|
return new Response(e.body, {
|
|
829
830
|
status: t,
|
|
830
831
|
headers: e.headers
|
|
831
832
|
});
|
|
832
833
|
}
|
|
833
|
-
async function
|
|
834
|
-
let n =
|
|
834
|
+
async function L(e, t = {}) {
|
|
835
|
+
let n = Gi(await S("unavailable"), e);
|
|
835
836
|
for (let [e, r] of Object.entries(t)) n.headers.set(e, r);
|
|
836
837
|
return n;
|
|
837
838
|
}
|
|
838
|
-
async function
|
|
839
|
-
let r = await
|
|
840
|
-
if (r === "invalid") return
|
|
841
|
-
if (r === "active") return
|
|
842
|
-
let i = await
|
|
843
|
-
if (i.kind === "invalid") return
|
|
844
|
-
let a = i.kind === "present" ? i : await
|
|
839
|
+
async function Ki(e, t, n) {
|
|
840
|
+
let r = await O(t, e.store, e.storeConfig);
|
|
841
|
+
if (r === "invalid") return L(400);
|
|
842
|
+
if (r === "active") return L(409);
|
|
843
|
+
let i = await b(t, "start");
|
|
844
|
+
if (i.kind === "invalid") return L(400);
|
|
845
|
+
let a = i.kind === "present" ? i : await Ue("start"), o = await x(e.csrfKey, a.secret, "start", e.scope), s = n.rejected ? Hi : 200, c = Gi(await ar({
|
|
845
846
|
csrfToken: o,
|
|
846
847
|
rejected: n.rejected
|
|
847
848
|
}), s);
|
|
848
849
|
return "setCookie" in a && c.headers.append("Set-Cookie", a.setCookie), c;
|
|
849
850
|
}
|
|
850
|
-
async function
|
|
851
|
+
async function qi(e, t) {
|
|
851
852
|
try {
|
|
852
|
-
let n =
|
|
853
|
-
if (n.method !== "GET") return await
|
|
853
|
+
let n = Yn(t);
|
|
854
|
+
if (n.method !== "GET") return await L(405, { Allow: "GET" });
|
|
854
855
|
let r = new URL(n.url);
|
|
855
|
-
return `${r.origin}${r.pathname}` === e.pageUrl ? n.url === e.pageUrl ? await
|
|
856
|
+
return `${r.origin}${r.pathname}` === e.pageUrl ? n.url === e.pageUrl ? await Ki(e, D(t).cookie, { rejected: !1 }) : await L(400) : await L(404);
|
|
856
857
|
} catch {
|
|
857
|
-
return await
|
|
858
|
+
return await L(503);
|
|
858
859
|
}
|
|
859
860
|
}
|
|
860
|
-
function
|
|
861
|
+
function Ji(e) {
|
|
861
862
|
switch (e.error) {
|
|
862
|
-
case "origin_rejected": return
|
|
863
|
-
case "rate_limited": return
|
|
864
|
-
case "unsupported_media_type": return
|
|
865
|
-
case "body_too_large": return
|
|
866
|
-
case "form_invalid": return
|
|
863
|
+
case "origin_rejected": return L(403);
|
|
864
|
+
case "rate_limited": return L(429, { "Retry-After": String(e.retryAfterS) });
|
|
865
|
+
case "unsupported_media_type": return L(415);
|
|
866
|
+
case "body_too_large": return L(413);
|
|
867
|
+
case "form_invalid": return L(400);
|
|
867
868
|
case "cookie_invalid":
|
|
868
869
|
case "cookie_missing":
|
|
869
|
-
case "csrf_invalid": return
|
|
870
|
-
default: return
|
|
870
|
+
case "csrf_invalid": return L(403);
|
|
871
|
+
default: return L(503);
|
|
871
872
|
}
|
|
872
873
|
}
|
|
873
|
-
async function
|
|
874
|
+
async function Yi(e) {
|
|
874
875
|
let t = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(e));
|
|
875
876
|
return Array.from(new Uint8Array(t), (e) => e.toString(16).padStart(2, "0")).join("");
|
|
876
877
|
}
|
|
877
|
-
async function
|
|
878
|
-
let r = await
|
|
879
|
-
if (r.kind !== "present" || r.cookieHash !== n.cookieHash) return
|
|
880
|
-
let i =
|
|
878
|
+
async function Xi(e, t, n) {
|
|
879
|
+
let r = await b(t.cookie, "start");
|
|
880
|
+
if (r.kind !== "present" || r.cookieHash !== n.cookieHash) return L(503);
|
|
881
|
+
let i = gn(n.userCode);
|
|
881
882
|
if (i === null) return null;
|
|
882
|
-
let a = await
|
|
883
|
+
let a = await Tn(i), o;
|
|
883
884
|
try {
|
|
884
885
|
o = await e.client.createAuthorizationRequest();
|
|
885
886
|
} catch {
|
|
886
|
-
return
|
|
887
|
+
return L(503);
|
|
887
888
|
}
|
|
888
|
-
let s =
|
|
889
|
-
return s.headers.append("Set-Cookie",
|
|
889
|
+
let s = Gi(await cn({ authorizationUrl: o.authorizationUrl }));
|
|
890
|
+
return s.headers.append("Set-Cookie", y(r.secret)), s.headers.append("Set-Cookie", E("start")), (await e.store.startHeadlessAuthLinkBrowserTransaction({
|
|
890
891
|
userCodeHash: a,
|
|
891
|
-
stateHash: await
|
|
892
|
+
stateHash: await Yi(o.material.state),
|
|
892
893
|
binderHash: n.cookieHash,
|
|
893
894
|
nonce: o.material.nonce,
|
|
894
895
|
pkceVerifier: o.material.pkceVerifier
|
|
895
896
|
}, e.storeConfig)).kind === "started" ? s : null;
|
|
896
897
|
}
|
|
897
|
-
async function
|
|
898
|
-
let n = await
|
|
898
|
+
async function Zi(e, t) {
|
|
899
|
+
let n = await Bi(e.limits, {
|
|
899
900
|
coordinatorId: e.storeConfig.coordinatorId,
|
|
900
|
-
clientKeyHash: await
|
|
901
|
+
clientKeyHash: await Pi(e.clientHashKey, t),
|
|
901
902
|
nowMs: Date.now()
|
|
902
903
|
});
|
|
903
904
|
if (n.allowed) return null;
|
|
904
|
-
let r =
|
|
905
|
+
let r = Gi(await Gn(), 429);
|
|
905
906
|
return r.headers.set("Retry-After", String(Math.ceil(n.retryAfterMs / 1e3))), r;
|
|
906
907
|
}
|
|
907
|
-
async function
|
|
908
|
+
async function Qi(e, t, n, r) {
|
|
908
909
|
try {
|
|
909
|
-
let i =
|
|
910
|
-
if (i.method !== "POST") return await
|
|
911
|
-
let a =
|
|
912
|
-
if (new URL(i.url).origin !== e.scope.publicOrigin ||
|
|
913
|
-
if (i.url !== e.pageUrl) return await
|
|
914
|
-
if (!r) return await
|
|
915
|
-
let o =
|
|
910
|
+
let i = Yn(t);
|
|
911
|
+
if (i.method !== "POST") return await L(405, { Allow: "POST" });
|
|
912
|
+
let a = Wi?.call(t);
|
|
913
|
+
if (new URL(i.url).origin !== e.scope.publicOrigin || Ui.call(a, "origin") !== e.scope.publicOrigin) return await L(403);
|
|
914
|
+
if (i.url !== e.pageUrl) return await L(404);
|
|
915
|
+
if (!r) return await L(503);
|
|
916
|
+
let o = D(t), s = await k({
|
|
916
917
|
request: t,
|
|
917
918
|
scope: e.scope,
|
|
918
919
|
csrfKey: e.csrfKey,
|
|
@@ -920,21 +921,21 @@ async function Zi(e, t, n, r) {
|
|
|
920
921
|
limiter: e.limiter,
|
|
921
922
|
clientKey: n
|
|
922
923
|
});
|
|
923
|
-
if (!s.ok) return await
|
|
924
|
-
if (s.action !== "headless_code") return await
|
|
925
|
-
let c = await
|
|
926
|
-
return c === "invalid" ? await
|
|
924
|
+
if (!s.ok) return await Ji(s);
|
|
925
|
+
if (s.action !== "headless_code") return await L(503);
|
|
926
|
+
let c = await O(o.cookie, e.store, e.storeConfig);
|
|
927
|
+
return c === "invalid" ? await L(400) : c === "active" ? await L(409) : await Zi(e, r) || (await Xi(e, o, s) ?? await Ki(e, o.cookie, { rejected: !0 }));
|
|
927
928
|
} catch {
|
|
928
|
-
return await
|
|
929
|
+
return await L(503);
|
|
929
930
|
}
|
|
930
931
|
}
|
|
931
|
-
async function
|
|
932
|
-
let t =
|
|
932
|
+
async function $i(e) {
|
|
933
|
+
let t = A(e.config);
|
|
933
934
|
if (t.kind !== "enabled") return Object.freeze({
|
|
934
935
|
ok: !1,
|
|
935
936
|
error: t.kind
|
|
936
937
|
});
|
|
937
|
-
let n = await
|
|
938
|
+
let n = await sr(t.oidc, e.oidcOptions);
|
|
938
939
|
if (!n.ok) return Object.freeze({
|
|
939
940
|
ok: !1,
|
|
940
941
|
error: n.error
|
|
@@ -950,26 +951,26 @@ async function Qi(e) {
|
|
|
950
951
|
limits: e.limits,
|
|
951
952
|
limiter: e.limiter,
|
|
952
953
|
client: n.client,
|
|
953
|
-
clientHashKey: await
|
|
954
|
-
pageUrl: new URL(
|
|
954
|
+
clientHashKey: await Ft(e.csrfKey, Vi),
|
|
955
|
+
pageUrl: new URL(Xn.code, t.publicOrigin).href
|
|
955
956
|
});
|
|
956
957
|
return Object.freeze({
|
|
957
958
|
ok: !0,
|
|
958
959
|
handlers: Object.freeze({
|
|
959
|
-
codePage: (e) =>
|
|
960
|
-
codeStart: (e, t, n) =>
|
|
960
|
+
codePage: (e) => qi(r, e),
|
|
961
|
+
codeStart: (e, t, n) => Qi(r, e, t, n)
|
|
961
962
|
})
|
|
962
963
|
});
|
|
963
964
|
}
|
|
964
965
|
//#endregion
|
|
965
966
|
//#region src/coordinator-browser-link.ts
|
|
966
|
-
function
|
|
967
|
+
function ea(e, t) {
|
|
967
968
|
return Object.freeze({
|
|
968
969
|
response: e,
|
|
969
970
|
outcome: t
|
|
970
971
|
});
|
|
971
972
|
}
|
|
972
|
-
function
|
|
973
|
+
function ta(e, t = 200, n) {
|
|
973
974
|
let r = new Headers(e.headers);
|
|
974
975
|
return r.set("Cache-Control", "no-store"), n && new Headers(n).forEach((e, t) => {
|
|
975
976
|
r.set(t, e);
|
|
@@ -978,8 +979,8 @@ function ea(e, t = 200, n) {
|
|
|
978
979
|
headers: r
|
|
979
980
|
});
|
|
980
981
|
}
|
|
981
|
-
function
|
|
982
|
-
return
|
|
982
|
+
function na() {
|
|
983
|
+
return ea(new Response("Account linking unavailable. Try again.", {
|
|
983
984
|
status: 503,
|
|
984
985
|
headers: {
|
|
985
986
|
"Content-Type": "text/plain;charset=utf-8",
|
|
@@ -989,28 +990,28 @@ function ta() {
|
|
|
989
990
|
}
|
|
990
991
|
}), "internal_error");
|
|
991
992
|
}
|
|
992
|
-
async function
|
|
993
|
+
async function R(e, t, n) {
|
|
993
994
|
try {
|
|
994
|
-
return
|
|
995
|
+
return ea(ta(await S("auth_unavailable"), e, n), t);
|
|
995
996
|
} catch {
|
|
996
|
-
return
|
|
997
|
+
return na();
|
|
997
998
|
}
|
|
998
999
|
}
|
|
999
|
-
function
|
|
1000
|
+
function ra(e) {
|
|
1000
1001
|
switch (e.error) {
|
|
1001
|
-
case "rate_limited": return
|
|
1002
|
-
case "unsupported_media_type": return
|
|
1003
|
-
case "body_too_large": return
|
|
1004
|
-
case "form_invalid": return
|
|
1002
|
+
case "rate_limited": return R(429, e.error, { "Retry-After": String(e.retryAfterS) });
|
|
1003
|
+
case "unsupported_media_type": return R(415, e.error);
|
|
1004
|
+
case "body_too_large": return R(413, e.error);
|
|
1005
|
+
case "form_invalid": return R(400, e.error);
|
|
1005
1006
|
case "origin_rejected":
|
|
1006
1007
|
case "cookie_missing":
|
|
1007
1008
|
case "cookie_invalid":
|
|
1008
|
-
case "csrf_invalid": return
|
|
1009
|
-
default: return
|
|
1009
|
+
case "csrf_invalid": return R(403, e.error);
|
|
1010
|
+
default: return R(503, "internal_error");
|
|
1010
1011
|
}
|
|
1011
1012
|
}
|
|
1012
|
-
async function
|
|
1013
|
-
let i =
|
|
1013
|
+
async function ia(e, t, n, r) {
|
|
1014
|
+
let i = ta(await S(r === "cancelled" ? "link_cancelled" : "auth_unavailable"), r === "cancelled" ? 200 : 403), a = await e.store.failAuthLinkAttempt({
|
|
1014
1015
|
attemptId: t,
|
|
1015
1016
|
requester: {
|
|
1016
1017
|
kind: "browser",
|
|
@@ -1018,45 +1019,45 @@ async function ra(e, t, n, r) {
|
|
|
1018
1019
|
},
|
|
1019
1020
|
reason: r
|
|
1020
1021
|
}, e.config);
|
|
1021
|
-
if (a.kind !== "applied" && a.kind !== "existing" || a.status.state !== "failed") return
|
|
1022
|
+
if (a.kind !== "applied" && a.kind !== "existing" || a.status.state !== "failed") return R(403, "link_rejected");
|
|
1022
1023
|
let o = await e.store.retireAuthBrowserTransactions(e.config, { attemptId: t });
|
|
1023
|
-
return o.kind !== "retired" || o.more ?
|
|
1024
|
+
return o.kind !== "retired" || o.more ? R(503, "internal_error") : r === "cancelled" ? ea(i, "link_cancelled") : ea(i, "link_rejected");
|
|
1024
1025
|
}
|
|
1025
|
-
async function
|
|
1026
|
+
async function aa(e, t) {
|
|
1026
1027
|
try {
|
|
1027
|
-
let n =
|
|
1028
|
-
if (n === null) return (await
|
|
1029
|
-
let r = await
|
|
1030
|
-
if (r.kind !== "present" || r.cookieHash !== t.transactionCookieHash) return (await
|
|
1028
|
+
let n = ca(t);
|
|
1029
|
+
if (n === null) return (await R(403, "link_rejected")).response;
|
|
1030
|
+
let r = await b(`${Be.transaction}=${n}`, "transaction");
|
|
1031
|
+
if (r.kind !== "present" || r.cookieHash !== t.transactionCookieHash) return (await R(403, "link_rejected")).response;
|
|
1031
1032
|
let i = await e.store.resolveAuthLinkBrowserTransaction({
|
|
1032
1033
|
attemptId: t.attemptId,
|
|
1033
1034
|
binderHash: r.cookieHash
|
|
1034
1035
|
}, e.config);
|
|
1035
|
-
if (!i || i.browserTransactionHash !== t.browserTransactionHash) return (await
|
|
1036
|
-
if (!t.verification.ok) return (await
|
|
1037
|
-
if (t.verification.account.issuer !== e.config.issuer) return (await
|
|
1036
|
+
if (!i || i.browserTransactionHash !== t.browserTransactionHash) return (await R(403, "link_rejected")).response;
|
|
1037
|
+
if (!t.verification.ok) return (await ia(e, t.attemptId, i.browserTransactionHash, "provider_failure")).response;
|
|
1038
|
+
if (t.verification.account.issuer !== e.config.issuer) return (await R(403, "link_rejected")).response;
|
|
1038
1039
|
let a = await e.store.recordAuthLinkOidcVerified({
|
|
1039
1040
|
attemptId: t.attemptId,
|
|
1040
1041
|
browserTransactionHash: i.browserTransactionHash,
|
|
1041
1042
|
account: t.verification.account,
|
|
1042
1043
|
profile: t.verification.profile
|
|
1043
1044
|
}, e.config);
|
|
1044
|
-
return a.kind === "applied" ? await
|
|
1045
|
+
return a.kind === "applied" ? await oa(e, {
|
|
1045
1046
|
...t,
|
|
1046
1047
|
browserTransactionHash: i.browserTransactionHash
|
|
1047
|
-
}, r.secret, a.target) : (await
|
|
1048
|
+
}, r.secret, a.target) : (await R(403, "link_rejected")).response;
|
|
1048
1049
|
} catch {
|
|
1049
|
-
return (await
|
|
1050
|
+
return (await R(503, "internal_error")).response;
|
|
1050
1051
|
}
|
|
1051
1052
|
}
|
|
1052
|
-
async function
|
|
1053
|
+
async function oa(e, t, n, r) {
|
|
1053
1054
|
let i = t.verification.ok ? t.verification.profile : void 0, { headless: a, ...o } = r;
|
|
1054
|
-
if (!a) return
|
|
1055
|
+
if (!a) return sa(e, t.attemptId, n, i, o);
|
|
1055
1056
|
let s = await e.store.readHeadlessAuthLinkDeviceName?.({
|
|
1056
1057
|
attemptId: t.attemptId,
|
|
1057
1058
|
browserTransactionHash: t.browserTransactionHash
|
|
1058
|
-
}, e.config) ?? null, c = await
|
|
1059
|
-
return
|
|
1059
|
+
}, e.config) ?? null, c = await x(e.csrfKey, n, "transaction", e.scope);
|
|
1060
|
+
return ta(await fr({
|
|
1060
1061
|
profile: i,
|
|
1061
1062
|
issuer: e.config.issuer,
|
|
1062
1063
|
...o,
|
|
@@ -1065,9 +1066,9 @@ async function aa(e, t, n, r) {
|
|
|
1065
1066
|
csrfToken: c
|
|
1066
1067
|
}));
|
|
1067
1068
|
}
|
|
1068
|
-
async function
|
|
1069
|
-
let a = await
|
|
1070
|
-
return
|
|
1069
|
+
async function sa(e, t, n, r, i) {
|
|
1070
|
+
let a = await x(e.csrfKey, n, "transaction", e.scope);
|
|
1071
|
+
return ta(await wt({
|
|
1071
1072
|
profile: r,
|
|
1072
1073
|
issuer: e.config.issuer,
|
|
1073
1074
|
identity: { id: i.identityId },
|
|
@@ -1077,20 +1078,20 @@ async function oa(e, t, n, r, i) {
|
|
|
1077
1078
|
csrfToken: a
|
|
1078
1079
|
}));
|
|
1079
1080
|
}
|
|
1080
|
-
function
|
|
1081
|
+
function ca(e) {
|
|
1081
1082
|
try {
|
|
1082
|
-
return
|
|
1083
|
+
return ne(e.transactionCookie, "transaction");
|
|
1083
1084
|
} catch {
|
|
1084
1085
|
return null;
|
|
1085
1086
|
}
|
|
1086
1087
|
}
|
|
1087
|
-
async function
|
|
1088
|
+
async function la(e, t, n) {
|
|
1088
1089
|
let r = await e.store.readAuthLinkCompletionDestination({
|
|
1089
1090
|
attemptId: t,
|
|
1090
1091
|
browserTransactionHash: n
|
|
1091
1092
|
}, e.config);
|
|
1092
|
-
if (!r) return
|
|
1093
|
-
let i = globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32)), a = btoa(String.fromCharCode(...i)).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, ""), o = await globalThis.crypto.subtle.digest("SHA-256", i), s = Array.from(new Uint8Array(o), (e) => e.toString(16).padStart(2, "0")).join(""), c =
|
|
1093
|
+
if (!r) return da(e, t, n);
|
|
1094
|
+
let i = globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32)), a = btoa(String.fromCharCode(...i)).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, ""), o = await globalThis.crypto.subtle.digest("SHA-256", i), s = Array.from(new Uint8Array(o), (e) => e.toString(16).padStart(2, "0")).join(""), c = ta(await Yt({
|
|
1094
1095
|
destination: r.destination,
|
|
1095
1096
|
attemptId: t,
|
|
1096
1097
|
completionSecret: a
|
|
@@ -1099,36 +1100,36 @@ async function ca(e, t, n) {
|
|
|
1099
1100
|
attemptId: t,
|
|
1100
1101
|
browserTransactionHash: n,
|
|
1101
1102
|
completionSecretHash: s
|
|
1102
|
-
}, e.config)).kind === "applied" ?
|
|
1103
|
+
}, e.config)).kind === "applied" ? ea(c, "link_confirmed") : R(403, "link_rejected");
|
|
1103
1104
|
}
|
|
1104
|
-
var
|
|
1105
|
-
confirmLink:
|
|
1106
|
-
cancelLink:
|
|
1107
|
-
confirmHeadless:
|
|
1105
|
+
var ua = Object.freeze({
|
|
1106
|
+
confirmLink: en.confirmLink,
|
|
1107
|
+
cancelLink: en.cancelLink,
|
|
1108
|
+
confirmHeadless: Xn.confirm
|
|
1108
1109
|
});
|
|
1109
|
-
async function
|
|
1110
|
+
async function da(e, t, n) {
|
|
1110
1111
|
let r = await e.store.getAuthLinkBrowserAttemptStatus?.({
|
|
1111
1112
|
attemptId: t,
|
|
1112
1113
|
browserTransactionHash: n
|
|
1113
1114
|
}, e.config);
|
|
1114
|
-
return r?.headless && r.status.state === "oidc_verified" ?
|
|
1115
|
+
return r?.headless && r.status.state === "oidc_verified" ? ea(ta(await br(), 409), "link_rejected") : R(403, "link_rejected");
|
|
1115
1116
|
}
|
|
1116
|
-
async function
|
|
1117
|
-
if (t === "confirmLink") return
|
|
1117
|
+
async function fa(e, t, n, r) {
|
|
1118
|
+
if (t === "confirmLink") return la(e, n, r);
|
|
1118
1119
|
let i = e.store.confirmHeadlessAuthLinkAttempt;
|
|
1119
|
-
if (!i) return
|
|
1120
|
-
let a =
|
|
1120
|
+
if (!i) return R(403, "link_rejected");
|
|
1121
|
+
let a = ta(await gr());
|
|
1121
1122
|
return (await i({
|
|
1122
1123
|
attemptId: n,
|
|
1123
1124
|
browserTransactionHash: r
|
|
1124
|
-
}, e.config)).kind === "applied" ?
|
|
1125
|
+
}, e.config)).kind === "applied" ? ea(a, "link_confirmed") : R(403, "link_rejected");
|
|
1125
1126
|
}
|
|
1126
|
-
async function
|
|
1127
|
+
async function pa(e, t, n, r) {
|
|
1127
1128
|
try {
|
|
1128
|
-
let i =
|
|
1129
|
-
if (i.method !== "POST") return await
|
|
1130
|
-
if (i.url !== `${e.scope.publicOrigin}${
|
|
1131
|
-
let a = await
|
|
1129
|
+
let i = D(t);
|
|
1130
|
+
if (i.method !== "POST") return await R(405, "method_not_allowed", { Allow: "POST" });
|
|
1131
|
+
if (i.url !== `${e.scope.publicOrigin}${ua[r]}`) return await R(404, "not_found");
|
|
1132
|
+
let a = await k({
|
|
1132
1133
|
request: t,
|
|
1133
1134
|
clientKey: n,
|
|
1134
1135
|
scope: e.scope,
|
|
@@ -1136,20 +1137,20 @@ async function fa(e, t, n, r) {
|
|
|
1136
1137
|
limiter: e.limiter,
|
|
1137
1138
|
action: "transaction_attempt"
|
|
1138
1139
|
});
|
|
1139
|
-
if (!a.ok) return await
|
|
1140
|
-
if (a.action !== "transaction_attempt") return await
|
|
1141
|
-
let o = await
|
|
1142
|
-
if (o.kind !== "present" || o.cookieHash !== a.cookieHash) return await
|
|
1140
|
+
if (!a.ok) return await ra(a);
|
|
1141
|
+
if (a.action !== "transaction_attempt") return await R(503, "internal_error");
|
|
1142
|
+
let o = await b(i.cookie, "transaction");
|
|
1143
|
+
if (o.kind !== "present" || o.cookieHash !== a.cookieHash) return await R(403, "link_rejected");
|
|
1143
1144
|
let s = await e.store.resolveAuthLinkBrowserTransaction({
|
|
1144
1145
|
attemptId: a.attemptId,
|
|
1145
1146
|
binderHash: a.cookieHash
|
|
1146
1147
|
}, e.config);
|
|
1147
|
-
return s ? r === "cancelLink" ? await
|
|
1148
|
+
return s ? r === "cancelLink" ? await ia(e, a.attemptId, s.browserTransactionHash, "cancelled") : await fa(e, r, a.attemptId, s.browserTransactionHash) : await R(403, "link_rejected");
|
|
1148
1149
|
} catch {
|
|
1149
|
-
return await
|
|
1150
|
+
return await R(503, "internal_error");
|
|
1150
1151
|
}
|
|
1151
1152
|
}
|
|
1152
|
-
function
|
|
1153
|
+
function ma(e) {
|
|
1153
1154
|
let t = Object.freeze({
|
|
1154
1155
|
coordinatorId: e.config.coordinatorId,
|
|
1155
1156
|
issuer: e.config.issuer,
|
|
@@ -1184,22 +1185,22 @@ function pa(e) {
|
|
|
1184
1185
|
return Object.freeze({
|
|
1185
1186
|
ok: !0,
|
|
1186
1187
|
handlers: Object.freeze({
|
|
1187
|
-
completeLink: (e) =>
|
|
1188
|
-
confirm: (e, t) =>
|
|
1189
|
-
cancel: (e, t) =>
|
|
1190
|
-
confirmHeadless: (e, t) =>
|
|
1188
|
+
completeLink: (e) => aa(a, e),
|
|
1189
|
+
confirm: (e, t) => pa(a, e, t, "confirmLink"),
|
|
1190
|
+
cancel: (e, t) => pa(a, e, t, "cancelLink"),
|
|
1191
|
+
confirmHeadless: (e, t) => pa(a, e, t, "confirmHeadless")
|
|
1191
1192
|
})
|
|
1192
1193
|
});
|
|
1193
1194
|
}
|
|
1194
1195
|
//#endregion
|
|
1195
1196
|
//#region src/coordinator-browser-link-completion.ts
|
|
1196
|
-
function
|
|
1197
|
+
function ha(e, t) {
|
|
1197
1198
|
return Object.freeze({
|
|
1198
1199
|
response: e,
|
|
1199
1200
|
outcome: t
|
|
1200
1201
|
});
|
|
1201
1202
|
}
|
|
1202
|
-
function
|
|
1203
|
+
function ga(e, t = 200, n) {
|
|
1203
1204
|
let r = new Headers(e.headers);
|
|
1204
1205
|
return n && new Headers(n).forEach((e, t) => {
|
|
1205
1206
|
r.set(t, e);
|
|
@@ -1208,11 +1209,11 @@ function ha(e, t = 200, n) {
|
|
|
1208
1209
|
headers: r
|
|
1209
1210
|
});
|
|
1210
1211
|
}
|
|
1211
|
-
async function
|
|
1212
|
+
async function z(e, t, n) {
|
|
1212
1213
|
try {
|
|
1213
|
-
return
|
|
1214
|
+
return ha(ga(await S("auth_unavailable"), e, n), t);
|
|
1214
1215
|
} catch {
|
|
1215
|
-
return
|
|
1216
|
+
return ha(new Response("Linking unavailable. Try again.", {
|
|
1216
1217
|
status: 503,
|
|
1217
1218
|
headers: {
|
|
1218
1219
|
"Content-Type": "text/plain;charset=utf-8",
|
|
@@ -1223,18 +1224,18 @@ async function B(e, t, n) {
|
|
|
1223
1224
|
}), "internal_error");
|
|
1224
1225
|
}
|
|
1225
1226
|
}
|
|
1226
|
-
var
|
|
1227
|
+
var _a = /* @__PURE__ */ new Set([
|
|
1227
1228
|
"confirmed",
|
|
1228
1229
|
"finalized",
|
|
1229
1230
|
"session_redeemed"
|
|
1230
1231
|
]);
|
|
1231
|
-
function
|
|
1232
|
+
function va(e) {
|
|
1232
1233
|
let t = [...e.searchParams], n = t[0];
|
|
1233
1234
|
if (t.length !== 1 || !n || n[0] !== "attempt_id") return null;
|
|
1234
1235
|
let r = n[1];
|
|
1235
1236
|
return C(r) ? r : null;
|
|
1236
1237
|
}
|
|
1237
|
-
async function
|
|
1238
|
+
async function ya(e, t, n) {
|
|
1238
1239
|
let r = await e.store.resolveAuthLinkBrowserTransaction({
|
|
1239
1240
|
attemptId: t,
|
|
1240
1241
|
binderHash: n
|
|
@@ -1262,49 +1263,49 @@ async function va(e, t, n) {
|
|
|
1262
1263
|
headless: !1
|
|
1263
1264
|
};
|
|
1264
1265
|
}
|
|
1265
|
-
async function
|
|
1266
|
+
async function ba(e, t) {
|
|
1266
1267
|
try {
|
|
1267
|
-
let n =
|
|
1268
|
-
if (n.method !== "GET") return await
|
|
1269
|
-
if (n.url.length > 8192) return await
|
|
1268
|
+
let n = D(t);
|
|
1269
|
+
if (n.method !== "GET") return await z(405, "method_not_allowed", { Allow: "GET" });
|
|
1270
|
+
if (n.url.length > 8192) return await z(400, "query_invalid");
|
|
1270
1271
|
let r = new URL(n.url);
|
|
1271
|
-
if (n.url.includes("#") || `${r.origin}${r.pathname}` != `${e.publicOrigin}${
|
|
1272
|
-
let i =
|
|
1273
|
-
if (i === null) return await
|
|
1274
|
-
let a = await
|
|
1275
|
-
if (a.kind !== "present") return await
|
|
1276
|
-
let o = await
|
|
1277
|
-
if (o?.headless) return
|
|
1278
|
-
if (o?.state === "confirmed") return
|
|
1272
|
+
if (n.url.includes("#") || `${r.origin}${r.pathname}` != `${e.publicOrigin}${en.completeLink}` || r.username || r.password) return await z(404, "not_found");
|
|
1273
|
+
let i = va(r);
|
|
1274
|
+
if (i === null) return await z(400, "query_invalid");
|
|
1275
|
+
let a = await b(n.cookie, "transaction");
|
|
1276
|
+
if (a.kind !== "present") return await z(403, "cookie_invalid");
|
|
1277
|
+
let o = await ya(e, i, a.cookieHash);
|
|
1278
|
+
if (o?.headless) return _a.has(o.state) ? ha(ga(await gr()), "waiting") : await z(403, "completion_rejected");
|
|
1279
|
+
if (o?.state === "confirmed") return ha(ga(await On({
|
|
1279
1280
|
attemptId: i,
|
|
1280
1281
|
state: "waiting"
|
|
1281
1282
|
})), "waiting");
|
|
1282
|
-
if (o?.state !== "finalized") return await
|
|
1283
|
-
let s = await
|
|
1284
|
-
return
|
|
1283
|
+
if (o?.state !== "finalized") return await z(403, "completion_rejected");
|
|
1284
|
+
let s = await x(e.csrfKey, a.secret, "transaction", e.scope);
|
|
1285
|
+
return ha(ga(await On({
|
|
1285
1286
|
attemptId: i,
|
|
1286
1287
|
state: "ready",
|
|
1287
1288
|
csrfToken: s
|
|
1288
1289
|
})), "ready");
|
|
1289
1290
|
} catch {
|
|
1290
|
-
return await
|
|
1291
|
+
return await z(503, "internal_error");
|
|
1291
1292
|
}
|
|
1292
1293
|
}
|
|
1293
|
-
function
|
|
1294
|
+
function xa(e) {
|
|
1294
1295
|
switch (e.error) {
|
|
1295
1296
|
case "origin_rejected":
|
|
1296
1297
|
case "cookie_invalid":
|
|
1297
|
-
case "csrf_invalid": return
|
|
1298
|
-
case "cookie_missing": return
|
|
1299
|
-
case "client_unidentified": return
|
|
1300
|
-
case "rate_limited": return
|
|
1301
|
-
case "unsupported_media_type": return
|
|
1302
|
-
case "body_too_large": return
|
|
1303
|
-
case "form_invalid": return
|
|
1304
|
-
default: return
|
|
1298
|
+
case "csrf_invalid": return z(403, e.error);
|
|
1299
|
+
case "cookie_missing": return z(403, "cookie_invalid");
|
|
1300
|
+
case "client_unidentified": return z(503, "internal_error");
|
|
1301
|
+
case "rate_limited": return z(429, e.error, { "Retry-After": String(e.retryAfterS) });
|
|
1302
|
+
case "unsupported_media_type": return z(415, e.error);
|
|
1303
|
+
case "body_too_large": return z(413, e.error);
|
|
1304
|
+
case "form_invalid": return z(400, e.error);
|
|
1305
|
+
default: return z(503, "internal_error");
|
|
1305
1306
|
}
|
|
1306
1307
|
}
|
|
1307
|
-
function
|
|
1308
|
+
function Sa(e, t) {
|
|
1308
1309
|
let n = new Headers({
|
|
1309
1310
|
Location: `${e.publicOrigin}/auth/account`,
|
|
1310
1311
|
"Cache-Control": "no-store",
|
|
@@ -1315,32 +1316,32 @@ function xa(e, t) {
|
|
|
1315
1316
|
headers: n
|
|
1316
1317
|
});
|
|
1317
1318
|
}
|
|
1318
|
-
async function
|
|
1319
|
-
let a = await
|
|
1320
|
-
if (a.kind === "invalid") return
|
|
1319
|
+
async function Ca(e, t, n, r, i) {
|
|
1320
|
+
let a = await b(t, "session");
|
|
1321
|
+
if (a.kind === "invalid") return z(403, "cookie_invalid");
|
|
1321
1322
|
if (a.kind === "present" && await e.store.readAuthSession(a.cookieHash, e.config) !== null) {
|
|
1322
|
-
let t =
|
|
1323
|
+
let t = Sa(e);
|
|
1323
1324
|
return (await e.store.preserveAuthLinkSessionCompletion({
|
|
1324
1325
|
attemptId: n,
|
|
1325
1326
|
browserTransactionHash: i,
|
|
1326
1327
|
binderHash: r,
|
|
1327
1328
|
credentialHash: a.cookieHash
|
|
1328
|
-
}, e.config)).kind === "preserved" ?
|
|
1329
|
+
}, e.config)).kind === "preserved" ? ha(t, "session_preserved") : z(403, "completion_rejected");
|
|
1329
1330
|
}
|
|
1330
|
-
let o = await
|
|
1331
|
+
let o = await Ue("session"), s = Sa(e, o.setCookie);
|
|
1331
1332
|
return (await e.store.redeemAuthLinkSessionWithBrowserTransaction({
|
|
1332
1333
|
attemptId: n,
|
|
1333
1334
|
browserTransactionHash: i,
|
|
1334
1335
|
binderHash: r,
|
|
1335
1336
|
credentialHash: o.cookieHash
|
|
1336
|
-
}, e.config)).kind === "issued" ?
|
|
1337
|
+
}, e.config)).kind === "issued" ? ha(s, "session_issued") : z(403, "completion_rejected");
|
|
1337
1338
|
}
|
|
1338
|
-
async function
|
|
1339
|
+
async function wa(e, t, n) {
|
|
1339
1340
|
try {
|
|
1340
|
-
let r =
|
|
1341
|
-
if (r.method !== "POST") return await
|
|
1342
|
-
if (r.url !== `${e.publicOrigin}${
|
|
1343
|
-
let i = await
|
|
1341
|
+
let r = D(t);
|
|
1342
|
+
if (r.method !== "POST") return await z(405, "method_not_allowed", { Allow: "POST" });
|
|
1343
|
+
if (r.url !== `${e.publicOrigin}${en.completeLink}`) return await z(404, "not_found");
|
|
1344
|
+
let i = await k({
|
|
1344
1345
|
request: t,
|
|
1345
1346
|
scope: e.scope,
|
|
1346
1347
|
csrfKey: e.csrfKey,
|
|
@@ -1348,17 +1349,17 @@ async function Ca(e, t, n) {
|
|
|
1348
1349
|
limiter: e.limiter,
|
|
1349
1350
|
clientKey: n
|
|
1350
1351
|
});
|
|
1351
|
-
if (!i.ok) return await
|
|
1352
|
-
if (i.action !== "transaction_attempt") return await
|
|
1353
|
-
let a = await
|
|
1354
|
-
if (a.kind !== "present" || a.cookieHash !== i.cookieHash) return await
|
|
1355
|
-
let o = await
|
|
1356
|
-
return o?.state !== "finalized" || o.headless ? await
|
|
1352
|
+
if (!i.ok) return await xa(i);
|
|
1353
|
+
if (i.action !== "transaction_attempt") return await z(503, "internal_error");
|
|
1354
|
+
let a = await b(r.cookie, "transaction");
|
|
1355
|
+
if (a.kind !== "present" || a.cookieHash !== i.cookieHash) return await z(403, "cookie_invalid");
|
|
1356
|
+
let o = await ya(e, i.attemptId, i.cookieHash);
|
|
1357
|
+
return o?.state !== "finalized" || o.headless ? await z(403, "completion_rejected") : await Ca(e, r.cookie, i.attemptId, i.cookieHash, o.browserTransactionHash);
|
|
1357
1358
|
} catch {
|
|
1358
|
-
return await
|
|
1359
|
+
return await z(503, "internal_error");
|
|
1359
1360
|
}
|
|
1360
1361
|
}
|
|
1361
|
-
function
|
|
1362
|
+
function Ta(e) {
|
|
1362
1363
|
if (!e.config?.enabled) return Object.freeze({
|
|
1363
1364
|
ok: !1,
|
|
1364
1365
|
error: "browser_auth_disabled"
|
|
@@ -1390,21 +1391,21 @@ function wa(e) {
|
|
|
1390
1391
|
return Object.freeze({
|
|
1391
1392
|
ok: !0,
|
|
1392
1393
|
handlers: Object.freeze({
|
|
1393
|
-
page: (e) =>
|
|
1394
|
-
complete: (e, t) =>
|
|
1394
|
+
page: (e) => ba(a, e),
|
|
1395
|
+
complete: (e, t) => wa(a, e, t)
|
|
1395
1396
|
})
|
|
1396
1397
|
});
|
|
1397
1398
|
}
|
|
1398
1399
|
//#endregion
|
|
1399
1400
|
//#region src/coordinator-browser-link-start.ts
|
|
1400
|
-
var
|
|
1401
|
-
function
|
|
1401
|
+
var Ea = Object.getOwnPropertyDescriptor(Request.prototype, "headers")?.get, Da = Headers.prototype.get, Oa = 8192;
|
|
1402
|
+
function ka(e, t) {
|
|
1402
1403
|
if (typeof e != "object" || !e || Array.isArray(e)) throw Error();
|
|
1403
1404
|
let n = Object.getOwnPropertyDescriptor(e, t);
|
|
1404
1405
|
if (n && !Object.hasOwn(n, "value")) throw Error();
|
|
1405
1406
|
return n?.value;
|
|
1406
1407
|
}
|
|
1407
|
-
function
|
|
1408
|
+
function Aa(e, t) {
|
|
1408
1409
|
if (typeof e != "object" || !e || Array.isArray(e)) throw Error();
|
|
1409
1410
|
let n = /* @__PURE__ */ new Set(), r = e;
|
|
1410
1411
|
for (; r !== null;) {
|
|
@@ -1419,13 +1420,13 @@ function ka(e, t) {
|
|
|
1419
1420
|
}
|
|
1420
1421
|
throw Error();
|
|
1421
1422
|
}
|
|
1422
|
-
function
|
|
1423
|
+
function ja(e, t) {
|
|
1423
1424
|
return Object.freeze({
|
|
1424
1425
|
response: e,
|
|
1425
1426
|
outcome: t
|
|
1426
1427
|
});
|
|
1427
1428
|
}
|
|
1428
|
-
function
|
|
1429
|
+
function Ma(e, t = 200, n) {
|
|
1429
1430
|
let r = new Headers(e.headers);
|
|
1430
1431
|
return n && new Headers(n).forEach((e, t) => {
|
|
1431
1432
|
r.set(t, e);
|
|
@@ -1434,11 +1435,11 @@ function ja(e, t = 200, n) {
|
|
|
1434
1435
|
headers: r
|
|
1435
1436
|
});
|
|
1436
1437
|
}
|
|
1437
|
-
async function
|
|
1438
|
+
async function B(e, t, n) {
|
|
1438
1439
|
try {
|
|
1439
|
-
return
|
|
1440
|
+
return ja(Ma(await S("unavailable"), e, n), t);
|
|
1440
1441
|
} catch {
|
|
1441
|
-
return
|
|
1442
|
+
return ja(new Response("Account linking unavailable. Return to your terminal and try again.", {
|
|
1442
1443
|
status: 503,
|
|
1443
1444
|
headers: {
|
|
1444
1445
|
"Content-Type": "text/plain;charset=utf-8",
|
|
@@ -1449,65 +1450,65 @@ async function V(e, t, n) {
|
|
|
1449
1450
|
}), "internal_error");
|
|
1450
1451
|
}
|
|
1451
1452
|
}
|
|
1452
|
-
function
|
|
1453
|
+
function Na(e, t) {
|
|
1453
1454
|
let n = new URL(t);
|
|
1454
1455
|
if (t.includes("#") || n.href !== t || `${n.origin}${n.pathname}` !== e.startUrl || n.username || n.password || [...n.searchParams].length !== 2 || n.searchParams.getAll("attempt_id").length !== 1 || n.searchParams.getAll("start_code").length !== 1) return null;
|
|
1455
1456
|
let r = n.searchParams.get("attempt_id"), i = n.searchParams.get("start_code");
|
|
1456
|
-
return !C(r) || typeof i != "string" || !
|
|
1457
|
+
return !C(r) || typeof i != "string" || !je(i) ? null : Object.freeze({
|
|
1457
1458
|
attemptId: r,
|
|
1458
1459
|
startCode: i
|
|
1459
1460
|
});
|
|
1460
1461
|
}
|
|
1461
|
-
async function
|
|
1462
|
+
async function Pa(e, t) {
|
|
1462
1463
|
try {
|
|
1463
|
-
let n =
|
|
1464
|
-
if (n.method !== "GET") return await
|
|
1465
|
-
if (n.url.length >
|
|
1464
|
+
let n = Yn(t);
|
|
1465
|
+
if (n.method !== "GET") return await B(405, "method_not_allowed", { Allow: "GET" });
|
|
1466
|
+
if (n.url.length > Oa) return await B(400, "form_invalid");
|
|
1466
1467
|
let r = new URL(n.url);
|
|
1467
|
-
if (`${r.origin}${r.pathname}` !== e.startUrl || r.username || r.password) return await
|
|
1468
|
-
let i =
|
|
1469
|
-
if (!i) return await
|
|
1470
|
-
let a =
|
|
1471
|
-
if (o === "invalid") return await
|
|
1472
|
-
if (o === "active") return await
|
|
1473
|
-
let s = await
|
|
1474
|
-
if (s.kind === "invalid") return await
|
|
1475
|
-
let c = s.kind === "present" ? s : await
|
|
1468
|
+
if (`${r.origin}${r.pathname}` !== e.startUrl || r.username || r.password) return await B(404, "not_found");
|
|
1469
|
+
let i = Na(e, n.url);
|
|
1470
|
+
if (!i) return await B(400, "form_invalid");
|
|
1471
|
+
let a = D(t), o = await O(a.cookie, e.store, e.storeConfig);
|
|
1472
|
+
if (o === "invalid") return await B(400, "cookie_invalid");
|
|
1473
|
+
if (o === "active") return await B(409, "link_in_progress");
|
|
1474
|
+
let s = await b(a.cookie, "start");
|
|
1475
|
+
if (s.kind === "invalid") return await B(400, "cookie_invalid");
|
|
1476
|
+
let c = s.kind === "present" ? s : await Ue("start"), l = await x(e.csrfKey, c.secret, "start", e.scope), u = Ma(await jt({
|
|
1476
1477
|
...i,
|
|
1477
1478
|
csrfToken: l
|
|
1478
1479
|
}));
|
|
1479
|
-
return "setCookie" in c && u.headers.append("Set-Cookie", c.setCookie),
|
|
1480
|
+
return "setCookie" in c && u.headers.append("Set-Cookie", c.setCookie), ja(u, "link_start_page");
|
|
1480
1481
|
} catch {
|
|
1481
|
-
return await
|
|
1482
|
+
return await B(503, "internal_error");
|
|
1482
1483
|
}
|
|
1483
1484
|
}
|
|
1484
|
-
function Pa(e) {
|
|
1485
|
-
return e.ok ? null : e.error === "origin_rejected" ? V(403, "origin_rejected") : e.error === "rate_limited" ? V(429, "rate_limited", { "Retry-After": String(e.retryAfterS) }) : e.error === "client_unidentified" || e.error === "invalid_input" ? V(503, "internal_error") : null;
|
|
1486
|
-
}
|
|
1487
1485
|
function Fa(e) {
|
|
1486
|
+
return e.ok ? null : e.error === "origin_rejected" ? B(403, "origin_rejected") : e.error === "rate_limited" ? B(429, "rate_limited", { "Retry-After": String(e.retryAfterS) }) : e.error === "client_unidentified" || e.error === "invalid_input" ? B(503, "internal_error") : null;
|
|
1487
|
+
}
|
|
1488
|
+
function Ia(e) {
|
|
1488
1489
|
switch (e.error) {
|
|
1489
|
-
case "unsupported_media_type": return
|
|
1490
|
-
case "body_too_large": return
|
|
1491
|
-
case "form_invalid": return
|
|
1490
|
+
case "unsupported_media_type": return B(415, e.error);
|
|
1491
|
+
case "body_too_large": return B(413, e.error);
|
|
1492
|
+
case "form_invalid": return B(400, e.error);
|
|
1492
1493
|
case "cookie_invalid":
|
|
1493
1494
|
case "cookie_missing":
|
|
1494
|
-
case "csrf_invalid": return
|
|
1495
|
-
default: return
|
|
1495
|
+
case "csrf_invalid": return B(403, e.error);
|
|
1496
|
+
default: return B(503, "internal_error");
|
|
1496
1497
|
}
|
|
1497
1498
|
}
|
|
1498
|
-
async function
|
|
1499
|
-
let r = await
|
|
1500
|
-
if (r.kind !== "present" || r.cookieHash !== n.cookieHash) return
|
|
1501
|
-
let i =
|
|
1502
|
-
if (!i) return
|
|
1503
|
-
let a = await
|
|
1499
|
+
async function La(e, t, n) {
|
|
1500
|
+
let r = await b(t.cookie, "start");
|
|
1501
|
+
if (r.kind !== "present" || r.cookieHash !== n.cookieHash) return B(503, "internal_error");
|
|
1502
|
+
let i = je(n.startCode);
|
|
1503
|
+
if (!i) return B(400, "form_invalid");
|
|
1504
|
+
let a = await ge(i), o;
|
|
1504
1505
|
try {
|
|
1505
1506
|
o = await e.client.createAuthorizationRequest();
|
|
1506
1507
|
} catch {
|
|
1507
|
-
return
|
|
1508
|
+
return B(503, "provider_request_failed");
|
|
1508
1509
|
}
|
|
1509
|
-
let s = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(o.material.state)), c = Array.from(new Uint8Array(s), (e) => e.toString(16).padStart(2, "0")).join(""), l =
|
|
1510
|
-
l.headers.append("Set-Cookie",
|
|
1510
|
+
let s = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(o.material.state)), c = Array.from(new Uint8Array(s), (e) => e.toString(16).padStart(2, "0")).join(""), l = Ma(await cn({ authorizationUrl: o.authorizationUrl }));
|
|
1511
|
+
l.headers.append("Set-Cookie", y(r.secret)), l.headers.append("Set-Cookie", E("start"));
|
|
1511
1512
|
let u = await e.store.startAuthBrowserTransaction({
|
|
1512
1513
|
purpose: "link",
|
|
1513
1514
|
attemptId: n.attemptId,
|
|
@@ -1517,47 +1518,47 @@ async function Ia(e, t, n) {
|
|
|
1517
1518
|
nonce: o.material.nonce,
|
|
1518
1519
|
pkceVerifier: o.material.pkceVerifier
|
|
1519
1520
|
}, e.storeConfig);
|
|
1520
|
-
if (u.kind === "started") return
|
|
1521
|
+
if (u.kind === "started") return ja(l, "link_started");
|
|
1521
1522
|
if (u.kind === "rejected") {
|
|
1522
|
-
if (u.error === "attempt_unavailable" || u.error === "attempt_expired") return
|
|
1523
|
-
if (u.error === "transaction_conflict") return
|
|
1524
|
-
if (u.error === "transaction_limited" || u.error === "clock_retention_blocked") return
|
|
1523
|
+
if (u.error === "attempt_unavailable" || u.error === "attempt_expired") return B(409, "attempt_unavailable");
|
|
1524
|
+
if (u.error === "transaction_conflict") return B(409, "start_conflict");
|
|
1525
|
+
if (u.error === "transaction_limited" || u.error === "clock_retention_blocked") return B(503, "start_limited");
|
|
1525
1526
|
}
|
|
1526
|
-
return
|
|
1527
|
+
return B(503, "internal_error");
|
|
1527
1528
|
}
|
|
1528
|
-
async function
|
|
1529
|
+
async function Ra(e, t, n) {
|
|
1529
1530
|
try {
|
|
1530
|
-
let r =
|
|
1531
|
-
if (r.method !== "POST") return await
|
|
1532
|
-
if (r.url.length >
|
|
1533
|
-
let i =
|
|
1534
|
-
if (new URL(r.url).origin !== e.scope.publicOrigin ||
|
|
1535
|
-
if (r.url !== e.startUrl) return await
|
|
1536
|
-
let a =
|
|
1531
|
+
let r = Yn(t);
|
|
1532
|
+
if (r.method !== "POST") return await B(405, "method_not_allowed", { Allow: "POST" });
|
|
1533
|
+
if (r.url.length > Oa) return await B(400, "form_invalid");
|
|
1534
|
+
let i = Ea?.call(t);
|
|
1535
|
+
if (new URL(r.url).origin !== e.scope.publicOrigin || Da.call(i, "origin") !== e.scope.publicOrigin) return await B(403, "origin_rejected");
|
|
1536
|
+
if (r.url !== e.startUrl) return await B(404, "not_found");
|
|
1537
|
+
let a = D(t), o = await k({
|
|
1537
1538
|
request: t,
|
|
1538
1539
|
scope: e.scope,
|
|
1539
1540
|
csrfKey: e.csrfKey,
|
|
1540
1541
|
action: "link_start",
|
|
1541
1542
|
limiter: e.limiter,
|
|
1542
1543
|
clientKey: n
|
|
1543
|
-
}), s =
|
|
1544
|
+
}), s = Fa(o);
|
|
1544
1545
|
if (s) return await s;
|
|
1545
|
-
let c = await
|
|
1546
|
-
return c === "invalid" ? await
|
|
1546
|
+
let c = await O(a.cookie, e.store, e.storeConfig);
|
|
1547
|
+
return c === "invalid" ? await B(400, "cookie_invalid") : c === "active" ? await B(409, "link_in_progress") : o.ok ? o.action === "link_start" ? await La(e, a, o) : await B(503, "internal_error") : await Ia(o);
|
|
1547
1548
|
} catch {
|
|
1548
|
-
return await
|
|
1549
|
+
return await B(503, "internal_error");
|
|
1549
1550
|
}
|
|
1550
1551
|
}
|
|
1551
|
-
function
|
|
1552
|
-
let t =
|
|
1552
|
+
function za(e) {
|
|
1553
|
+
let t = ka(e, "oidcOptions");
|
|
1553
1554
|
if (t !== void 0) return Object.freeze({
|
|
1554
|
-
fetch:
|
|
1555
|
-
timeoutSeconds:
|
|
1555
|
+
fetch: ka(t, "fetch"),
|
|
1556
|
+
timeoutSeconds: ka(t, "timeoutSeconds")
|
|
1556
1557
|
});
|
|
1557
1558
|
}
|
|
1558
|
-
async function
|
|
1559
|
+
async function Ba(e) {
|
|
1559
1560
|
try {
|
|
1560
|
-
let t =
|
|
1561
|
+
let t = A(ka(e, "config"));
|
|
1561
1562
|
if (t.kind === "disabled") return Object.freeze({
|
|
1562
1563
|
ok: !1,
|
|
1563
1564
|
error: "browser_auth_disabled"
|
|
@@ -1567,15 +1568,15 @@ async function za(e) {
|
|
|
1567
1568
|
error: "browser_auth_config_invalid",
|
|
1568
1569
|
field: t.field
|
|
1569
1570
|
});
|
|
1570
|
-
let n =
|
|
1571
|
+
let n = ka(e, "csrfKey"), r = ka(e, "store"), i = Aa(r, "startAuthBrowserTransaction"), a = Aa(r, "readAuthBrowserTransactionActivity"), o = Object.freeze({
|
|
1571
1572
|
startAuthBrowserTransaction: i.bind(r),
|
|
1572
1573
|
readAuthBrowserTransactionActivity: a.bind(r)
|
|
1573
|
-
}), s =
|
|
1574
|
-
|
|
1575
|
-
let c =
|
|
1574
|
+
}), s = ka(e, "limiter");
|
|
1575
|
+
Aa(s, "check");
|
|
1576
|
+
let c = za(e), l = Object.freeze({
|
|
1576
1577
|
publicOrigin: t.publicOrigin,
|
|
1577
1578
|
store: t.store
|
|
1578
|
-
}), u = new URL("/auth/link/start", t.publicOrigin).href, d = await
|
|
1579
|
+
}), u = new URL("/auth/link/start", t.publicOrigin).href, d = await sr(t.oidc, c);
|
|
1579
1580
|
if (!d.ok) return Object.freeze({
|
|
1580
1581
|
ok: !1,
|
|
1581
1582
|
error: d.error
|
|
@@ -1592,8 +1593,8 @@ async function za(e) {
|
|
|
1592
1593
|
return Object.freeze({
|
|
1593
1594
|
ok: !0,
|
|
1594
1595
|
handlers: Object.freeze({
|
|
1595
|
-
linkStartPage: (e) =>
|
|
1596
|
-
linkStart: (e, t) =>
|
|
1596
|
+
linkStartPage: (e) => Pa(f, e),
|
|
1597
|
+
linkStart: (e, t) => Ra(f, e, t)
|
|
1597
1598
|
})
|
|
1598
1599
|
});
|
|
1599
1600
|
} catch {
|
|
@@ -1605,13 +1606,13 @@ async function za(e) {
|
|
|
1605
1606
|
}
|
|
1606
1607
|
//#endregion
|
|
1607
1608
|
//#region src/coordinator-browser-signin-start.ts
|
|
1608
|
-
function
|
|
1609
|
+
function Va(e, t) {
|
|
1609
1610
|
if (typeof e != "object" || !e || Array.isArray(e)) throw Error();
|
|
1610
1611
|
let n = Object.getOwnPropertyDescriptor(e, t);
|
|
1611
1612
|
if (n && !Object.hasOwn(n, "value")) throw Error();
|
|
1612
1613
|
return n?.value;
|
|
1613
1614
|
}
|
|
1614
|
-
function
|
|
1615
|
+
function Ha(e, t) {
|
|
1615
1616
|
if (typeof e != "object" || !e || Array.isArray(e)) throw Error();
|
|
1616
1617
|
let n = /* @__PURE__ */ new Set(), r = e;
|
|
1617
1618
|
for (; r !== null;) {
|
|
@@ -1626,7 +1627,7 @@ function Va(e, t) {
|
|
|
1626
1627
|
}
|
|
1627
1628
|
throw Error();
|
|
1628
1629
|
}
|
|
1629
|
-
function
|
|
1630
|
+
function Ua(e) {
|
|
1630
1631
|
let t = Request.prototype;
|
|
1631
1632
|
for (; t !== null;) {
|
|
1632
1633
|
let n = Object.getOwnPropertyDescriptor(t, e);
|
|
@@ -1634,27 +1635,27 @@ function Ha(e) {
|
|
|
1634
1635
|
t = Object.getPrototypeOf(t);
|
|
1635
1636
|
}
|
|
1636
1637
|
}
|
|
1637
|
-
var
|
|
1638
|
-
method:
|
|
1639
|
-
url:
|
|
1640
|
-
headers:
|
|
1641
|
-
}),
|
|
1642
|
-
function
|
|
1643
|
-
let t =
|
|
1638
|
+
var Wa = Object.freeze({
|
|
1639
|
+
method: Ua("method"),
|
|
1640
|
+
url: Ua("url"),
|
|
1641
|
+
headers: Ua("headers")
|
|
1642
|
+
}), Ga = Headers.prototype.get;
|
|
1643
|
+
function Ka(e) {
|
|
1644
|
+
let t = Wa.method?.call(e), n = Wa.url?.call(e), r = Wa.headers?.call(e);
|
|
1644
1645
|
if (typeof t != "string" || typeof n != "string") throw Error();
|
|
1645
1646
|
return Object.freeze({
|
|
1646
1647
|
method: t,
|
|
1647
1648
|
url: n,
|
|
1648
|
-
cookie:
|
|
1649
|
+
cookie: Ga.call(r, "cookie")
|
|
1649
1650
|
});
|
|
1650
1651
|
}
|
|
1651
|
-
function
|
|
1652
|
+
function qa(e, t) {
|
|
1652
1653
|
return Object.freeze({
|
|
1653
1654
|
response: e,
|
|
1654
1655
|
outcome: t
|
|
1655
1656
|
});
|
|
1656
1657
|
}
|
|
1657
|
-
function
|
|
1658
|
+
function Ja(e, t = 200, n) {
|
|
1658
1659
|
let r = new Headers(e.headers);
|
|
1659
1660
|
return r.set("Cache-Control", "no-store"), n && new Headers(n).forEach((e, t) => {
|
|
1660
1661
|
r.set(t, e);
|
|
@@ -1663,8 +1664,8 @@ function qa(e, t = 200, n) {
|
|
|
1663
1664
|
headers: r
|
|
1664
1665
|
});
|
|
1665
1666
|
}
|
|
1666
|
-
function
|
|
1667
|
-
return
|
|
1667
|
+
function Ya() {
|
|
1668
|
+
return qa(new Response("Sign-in unavailable. Try again.", {
|
|
1668
1669
|
status: 503,
|
|
1669
1670
|
headers: {
|
|
1670
1671
|
"Content-Type": "text/plain;charset=utf-8",
|
|
@@ -1674,15 +1675,15 @@ function Ja() {
|
|
|
1674
1675
|
}
|
|
1675
1676
|
}), "internal_error");
|
|
1676
1677
|
}
|
|
1677
|
-
async function
|
|
1678
|
+
async function V(e, t, n) {
|
|
1678
1679
|
try {
|
|
1679
|
-
return
|
|
1680
|
+
return qa(Ja(await S(t === "signin_in_progress" || t === "start_conflict" ? "signin_in_progress" : "signin_unavailable"), e, n), t);
|
|
1680
1681
|
} catch {
|
|
1681
|
-
return
|
|
1682
|
+
return Ya();
|
|
1682
1683
|
}
|
|
1683
1684
|
}
|
|
1684
|
-
function
|
|
1685
|
-
return
|
|
1685
|
+
function Xa(e) {
|
|
1686
|
+
return qa(new Response(null, {
|
|
1686
1687
|
status: 303,
|
|
1687
1688
|
headers: {
|
|
1688
1689
|
Location: e.accountUrl,
|
|
@@ -1691,55 +1692,55 @@ function Ya(e) {
|
|
|
1691
1692
|
}
|
|
1692
1693
|
}), "session_live");
|
|
1693
1694
|
}
|
|
1694
|
-
async function
|
|
1695
|
-
let n = await
|
|
1695
|
+
async function Za(e, t) {
|
|
1696
|
+
let n = await b(t.cookie, "session");
|
|
1696
1697
|
if (n.kind === "invalid") throw Error();
|
|
1697
1698
|
return n.kind !== "absent" && await e.store.readAuthSession(n.cookieHash, e.storeConfig) !== null;
|
|
1698
1699
|
}
|
|
1699
|
-
function
|
|
1700
|
-
return t.method === n ? t.url === e.signinUrl ? null :
|
|
1700
|
+
function Qa(e, t, n) {
|
|
1701
|
+
return t.method === n ? t.url === e.signinUrl ? null : V(404, "not_found") : V(405, "method_not_allowed", { Allow: n });
|
|
1701
1702
|
}
|
|
1702
|
-
async function
|
|
1703
|
+
async function $a(e, t) {
|
|
1703
1704
|
try {
|
|
1704
|
-
let n =
|
|
1705
|
+
let n = Ka(t), r = Qa(e, n, "GET");
|
|
1705
1706
|
if (r) return await r;
|
|
1706
|
-
let i = await
|
|
1707
|
-
if (i === "invalid") return await
|
|
1708
|
-
if (i === "active") return await
|
|
1709
|
-
if (await
|
|
1710
|
-
let a = await
|
|
1711
|
-
if (a.kind === "invalid") return await
|
|
1712
|
-
let o = a.kind === "present" ? a : await
|
|
1713
|
-
return "setCookie" in o && c.headers.append("Set-Cookie", o.setCookie),
|
|
1707
|
+
let i = await O(n.cookie, e.store, e.storeConfig);
|
|
1708
|
+
if (i === "invalid") return await V(400, "cookie_invalid");
|
|
1709
|
+
if (i === "active") return await V(409, "signin_in_progress");
|
|
1710
|
+
if (await Za(e, n)) return Xa(e);
|
|
1711
|
+
let a = await b(n.cookie, "start");
|
|
1712
|
+
if (a.kind === "invalid") return await V(400, "cookie_invalid");
|
|
1713
|
+
let o = a.kind === "present" ? a : await Ue("start"), s = await x(e.csrfKey, o.secret, "start", e.scope), c = Ja(await Zt({ csrfToken: s }));
|
|
1714
|
+
return "setCookie" in o && c.headers.append("Set-Cookie", o.setCookie), qa(c, "signin_page");
|
|
1714
1715
|
} catch {
|
|
1715
|
-
return await
|
|
1716
|
+
return await V(503, "internal_error");
|
|
1716
1717
|
}
|
|
1717
1718
|
}
|
|
1718
|
-
function $a(e) {
|
|
1719
|
-
return e.ok ? null : e.error === "origin_rejected" ? H(403, "origin_rejected") : e.error === "rate_limited" ? H(429, "rate_limited", { "Retry-After": String(e.retryAfterS) }) : e.error === "client_unidentified" || e.error === "invalid_input" ? H(503, "internal_error") : null;
|
|
1720
|
-
}
|
|
1721
1719
|
function eo(e) {
|
|
1720
|
+
return e.ok ? null : e.error === "origin_rejected" ? V(403, "origin_rejected") : e.error === "rate_limited" ? V(429, "rate_limited", { "Retry-After": String(e.retryAfterS) }) : e.error === "client_unidentified" || e.error === "invalid_input" ? V(503, "internal_error") : null;
|
|
1721
|
+
}
|
|
1722
|
+
function to(e) {
|
|
1722
1723
|
switch (e.error) {
|
|
1723
|
-
case "unsupported_media_type": return
|
|
1724
|
-
case "body_too_large": return
|
|
1725
|
-
case "form_invalid": return
|
|
1724
|
+
case "unsupported_media_type": return V(415, e.error);
|
|
1725
|
+
case "body_too_large": return V(413, e.error);
|
|
1726
|
+
case "form_invalid": return V(400, e.error);
|
|
1726
1727
|
case "cookie_invalid":
|
|
1727
1728
|
case "cookie_missing":
|
|
1728
|
-
case "csrf_invalid": return
|
|
1729
|
-
default: return
|
|
1729
|
+
case "csrf_invalid": return V(403, e.error);
|
|
1730
|
+
default: return V(503, "internal_error");
|
|
1730
1731
|
}
|
|
1731
1732
|
}
|
|
1732
|
-
async function
|
|
1733
|
-
let r = await
|
|
1734
|
-
if (r.kind !== "present" || r.cookieHash !== n) return
|
|
1733
|
+
async function no(e, t, n) {
|
|
1734
|
+
let r = await b(t.cookie, "start");
|
|
1735
|
+
if (r.kind !== "present" || r.cookieHash !== n) return V(503, "internal_error");
|
|
1735
1736
|
let i;
|
|
1736
1737
|
try {
|
|
1737
1738
|
i = await e.client.createAuthorizationRequest();
|
|
1738
1739
|
} catch {
|
|
1739
|
-
return
|
|
1740
|
+
return V(503, "provider_request_failed");
|
|
1740
1741
|
}
|
|
1741
|
-
let a = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(i.material.state)), o = Array.from(new Uint8Array(a), (e) => e.toString(16).padStart(2, "0")).join(""), s =
|
|
1742
|
-
s.headers.append("Set-Cookie",
|
|
1742
|
+
let a = await globalThis.crypto.subtle.digest("SHA-256", new TextEncoder().encode(i.material.state)), o = Array.from(new Uint8Array(a), (e) => e.toString(16).padStart(2, "0")).join(""), s = Ja(await cn({ authorizationUrl: i.authorizationUrl }));
|
|
1743
|
+
s.headers.append("Set-Cookie", y(r.secret)), s.headers.append("Set-Cookie", E("start"));
|
|
1743
1744
|
let c = await e.store.startAuthBrowserTransaction({
|
|
1744
1745
|
purpose: "signin",
|
|
1745
1746
|
stateHash: o,
|
|
@@ -1747,44 +1748,44 @@ async function to(e, t, n) {
|
|
|
1747
1748
|
nonce: i.material.nonce,
|
|
1748
1749
|
pkceVerifier: i.material.pkceVerifier
|
|
1749
1750
|
}, e.storeConfig);
|
|
1750
|
-
if (c.kind === "started") return
|
|
1751
|
+
if (c.kind === "started") return qa(s, "signin_started");
|
|
1751
1752
|
if (c.kind === "rejected") {
|
|
1752
|
-
if (c.error === "transaction_conflict") return
|
|
1753
|
-
if (c.error === "transaction_limited" || c.error === "clock_retention_blocked") return
|
|
1753
|
+
if (c.error === "transaction_conflict") return V(409, "start_conflict");
|
|
1754
|
+
if (c.error === "transaction_limited" || c.error === "clock_retention_blocked") return V(503, "start_limited");
|
|
1754
1755
|
}
|
|
1755
|
-
return
|
|
1756
|
+
return V(503, "internal_error");
|
|
1756
1757
|
}
|
|
1757
|
-
async function
|
|
1758
|
+
async function ro(e, t, n) {
|
|
1758
1759
|
try {
|
|
1759
|
-
let r =
|
|
1760
|
+
let r = Ka(t), i = Qa(e, r, "POST");
|
|
1760
1761
|
if (i) return await i;
|
|
1761
|
-
let a = await
|
|
1762
|
+
let a = await k({
|
|
1762
1763
|
request: t,
|
|
1763
1764
|
scope: e.scope,
|
|
1764
1765
|
csrfKey: e.csrfKey,
|
|
1765
1766
|
action: "signin_start",
|
|
1766
1767
|
limiter: e.limiter,
|
|
1767
1768
|
clientKey: n
|
|
1768
|
-
}), o =
|
|
1769
|
+
}), o = eo(a);
|
|
1769
1770
|
if (o) return await o;
|
|
1770
|
-
let s = await
|
|
1771
|
-
return s === "invalid" ? await
|
|
1771
|
+
let s = await O(r.cookie, e.store, e.storeConfig);
|
|
1772
|
+
return s === "invalid" ? await V(400, "cookie_invalid") : s === "active" ? await V(409, "signin_in_progress") : a.ok ? a.action === "signin_start" ? await Za(e, r) ? Xa(e) : await no(e, r, a.cookieHash) : await V(503, "internal_error") : await to(a);
|
|
1772
1773
|
} catch {
|
|
1773
|
-
return await
|
|
1774
|
+
return await V(503, "internal_error");
|
|
1774
1775
|
}
|
|
1775
1776
|
}
|
|
1776
|
-
function
|
|
1777
|
-
let t =
|
|
1777
|
+
function io(e) {
|
|
1778
|
+
let t = Va(e, "oidcOptions");
|
|
1778
1779
|
if (t === void 0) return;
|
|
1779
|
-
let n =
|
|
1780
|
+
let n = Va(t, "fetch"), r = Va(t, "timeoutSeconds");
|
|
1780
1781
|
return Object.freeze({
|
|
1781
1782
|
fetch: n,
|
|
1782
1783
|
timeoutSeconds: r
|
|
1783
1784
|
});
|
|
1784
1785
|
}
|
|
1785
|
-
async function
|
|
1786
|
+
async function ao(e) {
|
|
1786
1787
|
try {
|
|
1787
|
-
let t =
|
|
1788
|
+
let t = A(Va(e, "config"));
|
|
1788
1789
|
if (t.kind === "disabled") return Object.freeze({
|
|
1789
1790
|
ok: !1,
|
|
1790
1791
|
error: "browser_auth_disabled"
|
|
@@ -1794,16 +1795,16 @@ async function io(e) {
|
|
|
1794
1795
|
error: "browser_auth_config_invalid",
|
|
1795
1796
|
field: t.field
|
|
1796
1797
|
});
|
|
1797
|
-
let n =
|
|
1798
|
+
let n = Va(e, "csrfKey"), r = Va(e, "store"), i = Ha(r, "startAuthBrowserTransaction"), a = Ha(r, "readAuthSession"), o = Ha(r, "readAuthBrowserTransactionActivity"), s = Object.freeze({
|
|
1798
1799
|
startAuthBrowserTransaction: i.bind(r),
|
|
1799
1800
|
readAuthSession: a.bind(r),
|
|
1800
1801
|
readAuthBrowserTransactionActivity: o.bind(r)
|
|
1801
|
-
}), c =
|
|
1802
|
-
|
|
1803
|
-
let l =
|
|
1802
|
+
}), c = Va(e, "limiter");
|
|
1803
|
+
Ha(c, "check");
|
|
1804
|
+
let l = io(e), u = Object.freeze({
|
|
1804
1805
|
publicOrigin: t.publicOrigin,
|
|
1805
1806
|
store: t.store
|
|
1806
|
-
}), d = new URL("/auth/sign-in", t.publicOrigin).href, f = new URL("/auth/account", t.publicOrigin).href, p = await
|
|
1807
|
+
}), d = new URL("/auth/sign-in", t.publicOrigin).href, f = new URL("/auth/account", t.publicOrigin).href, p = await sr(t.oidc, l);
|
|
1807
1808
|
if (!p.ok) return Object.freeze({
|
|
1808
1809
|
ok: !1,
|
|
1809
1810
|
error: p.error
|
|
@@ -1821,8 +1822,8 @@ async function io(e) {
|
|
|
1821
1822
|
return Object.freeze({
|
|
1822
1823
|
ok: !0,
|
|
1823
1824
|
handlers: Object.freeze({
|
|
1824
|
-
signInPage: (e) =>
|
|
1825
|
-
signInStart: (e, t) =>
|
|
1825
|
+
signInPage: (e) => $a(m, e),
|
|
1826
|
+
signInStart: (e, t) => ro(m, e, t)
|
|
1826
1827
|
})
|
|
1827
1828
|
});
|
|
1828
1829
|
} catch {
|
|
@@ -1834,53 +1835,53 @@ async function io(e) {
|
|
|
1834
1835
|
}
|
|
1835
1836
|
//#endregion
|
|
1836
1837
|
//#region src/coordinator-device-rebind-view.ts
|
|
1837
|
-
var
|
|
1838
|
+
var H = Object.freeze({
|
|
1838
1839
|
start: "/auth/rebind/start",
|
|
1839
1840
|
confirm: "/auth/rebind/confirm"
|
|
1840
1841
|
});
|
|
1841
|
-
function
|
|
1842
|
+
function oo(e) {
|
|
1842
1843
|
return Object.entries(e).map(([e, t]) => `<input type="hidden" name="${w(e)}" value="${w(t)}">`).join("");
|
|
1843
1844
|
}
|
|
1844
|
-
function
|
|
1845
|
-
return `<form method="post" action="${e}">${
|
|
1845
|
+
function so(e, t, n) {
|
|
1846
|
+
return `<form method="post" action="${e}">${oo(t)}<button type="submit">${w(n)}</button></form>`;
|
|
1846
1847
|
}
|
|
1847
|
-
function
|
|
1848
|
+
function co(e) {
|
|
1848
1849
|
let t = {
|
|
1849
1850
|
csrf: e.csrf,
|
|
1850
1851
|
attempt_id: e.attemptId,
|
|
1851
1852
|
start_code: e.startCode
|
|
1852
1853
|
};
|
|
1853
|
-
return
|
|
1854
|
+
return hn("Sign in on this device", `<h1>Connecting to Google…</h1><p>You’ll choose an account and confirm before this device changes.</p><p class="note">If nothing happens, continue below. Do not share this page.</p><div class="actions">${so(H.start, t, "Continue with Google")}</div>`, void 0, {
|
|
1854
1855
|
referrerPolicy: "same-origin",
|
|
1855
1856
|
autoSubmit: !0
|
|
1856
1857
|
});
|
|
1857
1858
|
}
|
|
1858
|
-
function
|
|
1859
|
+
function U(e, t) {
|
|
1859
1860
|
return `<dt>${w(e)}</dt><dd><code>${w(t)}</code></dd>`;
|
|
1860
1861
|
}
|
|
1861
1862
|
function lo(e) {
|
|
1862
|
-
let t = e.confirmation, n =
|
|
1863
|
+
let t = e.confirmation, n = U("Device", t.deviceId) + U("Key fingerprint", t.fingerprint) + U("Identity", t.currentIdentityId), r = {
|
|
1863
1864
|
csrf: e.csrf,
|
|
1864
1865
|
attempt_id: t.attemptId,
|
|
1865
1866
|
confirmation_hash: t.confirmationHash
|
|
1866
1867
|
};
|
|
1867
|
-
return
|
|
1868
|
+
return hn("Use this account on this device", `<h1>Use this account on this device</h1><p>This Google account already belongs to this device’s Identity. Confirming lets this device refresh and unlink it too.</p><section aria-label="Device"><dl>${n}</dl></section><p>A device can do this only once.</p><div class="actions">${so(H.confirm, r, "Confirm")}</div>`, void 0, { referrerPolicy: "same-origin" });
|
|
1868
1869
|
}
|
|
1869
1870
|
function uo(e) {
|
|
1870
1871
|
let t = e.confirmation;
|
|
1871
1872
|
if (t.targetIdentityId === t.currentIdentityId) return lo(e);
|
|
1872
|
-
let n = t.groupsWithoutAccess.length ? t.groupsWithoutAccess.join(", ") : "None", r =
|
|
1873
|
+
let n = t.groupsWithoutAccess.length ? t.groupsWithoutAccess.join(", ") : "None", r = U("Device", t.deviceId) + U("Key fingerprint", t.fingerprint) + U("Current Identity", t.currentIdentityId) + U("New Identity", t.targetIdentityId) + U("Teams without access yet", n), i = {
|
|
1873
1874
|
csrf: e.csrf,
|
|
1874
1875
|
attempt_id: t.attemptId,
|
|
1875
1876
|
confirmation_hash: t.confirmationHash
|
|
1876
1877
|
};
|
|
1877
|
-
return
|
|
1878
|
+
return hn("Sign in on this device", `<h1>Sign in on this device</h1><p>This device will use the Identity of the Google account you chose. Its existing memories keep their author.</p><section aria-label="Change"><dl>${r}</dl></section><p>Teams the new Identity isn’t in won’t sync on this device until a Team admin adds it. A device can switch only once.</p><div class="actions">${so(H.confirm, i, "Switch this device")}</div>`, void 0, { referrerPolicy: "same-origin" });
|
|
1878
1879
|
}
|
|
1879
1880
|
function fo(e) {
|
|
1880
|
-
let t =
|
|
1881
|
+
let t = Se(e.loopbackRedirect);
|
|
1881
1882
|
if (!t.ok || !/^[A-Za-z0-9_-]{43}$/.test(e.completionSecret) || !/^[a-f0-9]{64}$/.test(e.confirmationHash)) throw Error("device_rebind_view_invalid_input");
|
|
1882
1883
|
let n = `${t.destination}?attempt_id=${encodeURIComponent(e.attemptId)}&completion=${e.completionSecret}&confirmation=${e.confirmationHash}`;
|
|
1883
|
-
return
|
|
1884
|
+
return hn("Finishing sign-in", `<h1>Finishing sign-in…</h1><p>Returning to Codemem on this computer. If nothing happens, continue below.</p><p class="note">Do not share this link.</p><div class="actions"><a class="link" href="${w(n)}" referrerpolicy="no-referrer" rel="noreferrer">Continue on this computer</a></div>`, void 0, { refreshUrl: n });
|
|
1884
1885
|
}
|
|
1885
1886
|
var po = {
|
|
1886
1887
|
rate_limited: ["Too many tries", "Wait a minute, then start again from Codemem on this device."],
|
|
@@ -1896,14 +1897,14 @@ var po = {
|
|
|
1896
1897
|
target_headless_linked: ["Link this account from a browser first", "This account was linked from a device without a browser. Link it once from a computer with a browser before moving other devices into it."]
|
|
1897
1898
|
};
|
|
1898
1899
|
function mo(e) {
|
|
1899
|
-
let t =
|
|
1900
|
+
let t = Se(e.loopbackRedirect);
|
|
1900
1901
|
if (!t.ok) throw Error("device_rebind_view_invalid_input");
|
|
1901
|
-
let [n, r] = po[e.reason], i = `${t.destination}?attempt_id=${encodeURIComponent(e.attemptId)}&refused=${
|
|
1902
|
-
return
|
|
1902
|
+
let [n, r] = po[e.reason], i = `${t.destination}?attempt_id=${encodeURIComponent(e.attemptId)}&refused=${Kn(e.reason)}`;
|
|
1903
|
+
return hn(n, `<h1>${w(n)}</h1><p>${w(r)}</p><p>Returning to Codemem on this computer.</p><div class="actions"><a class="link" href="${w(i)}" referrerpolicy="no-referrer" rel="noreferrer">Return to Codemem</a></div>`, void 0, { refreshUrl: i });
|
|
1903
1904
|
}
|
|
1904
1905
|
function ho(e) {
|
|
1905
1906
|
let [t, n] = po[e];
|
|
1906
|
-
return
|
|
1907
|
+
return hn(t, `<h1>${w(t)}</h1><p>${w(n)}</p>`);
|
|
1907
1908
|
}
|
|
1908
1909
|
//#endregion
|
|
1909
1910
|
//#region src/coordinator-device-rebind-browser.ts
|
|
@@ -1925,28 +1926,28 @@ function vo(e, t) {
|
|
|
1925
1926
|
let n = new URL(e);
|
|
1926
1927
|
if (`${n.origin}${n.pathname}` !== t || n.username || n.password) return null;
|
|
1927
1928
|
let r = n.searchParams.get("attempt_id"), i = n.searchParams.get("start_code");
|
|
1928
|
-
return [...n.searchParams].length !== 2 || !C(r) || !i || !
|
|
1929
|
+
return [...n.searchParams].length !== 2 || !C(r) || !i || !je(i) ? null : {
|
|
1929
1930
|
attemptId: r,
|
|
1930
1931
|
startCode: i
|
|
1931
1932
|
};
|
|
1932
1933
|
}
|
|
1933
1934
|
async function yo(e, t, n) {
|
|
1934
|
-
let r =
|
|
1935
|
-
if (!
|
|
1935
|
+
let r = D(t), i = JSON.stringify(["device-rebind-start-page", n]);
|
|
1936
|
+
if (!Jn(t, e.limiter, i, 30).allowed) return _o("rate_limited", 429);
|
|
1936
1937
|
let a = vo(r.url, e.startUrl);
|
|
1937
1938
|
if (!a) return W({
|
|
1938
1939
|
kind: "refused",
|
|
1939
1940
|
reason: "unavailable"
|
|
1940
1941
|
}, 400);
|
|
1941
|
-
let o = await
|
|
1942
|
+
let o = await O(r.cookie, e.transactions, e.scope.store), s = await b(r.cookie, "start");
|
|
1942
1943
|
if (o === "active") return _o("busy", 409);
|
|
1943
1944
|
if (o === "invalid" || s.kind === "invalid") return W({
|
|
1944
1945
|
kind: "refused",
|
|
1945
1946
|
reason: "unavailable"
|
|
1946
1947
|
}, 400);
|
|
1947
|
-
let c = s.kind === "absent" ? await
|
|
1948
|
+
let c = s.kind === "absent" ? await Ue("start") : null, l = s.kind === "present" ? s.secret : c?.secret;
|
|
1948
1949
|
if (!l) return W(null);
|
|
1949
|
-
let u = await
|
|
1950
|
+
let u = await x(e.csrfKey, l, "start", e.scope), d = go(await co({
|
|
1950
1951
|
...a,
|
|
1951
1952
|
csrf: u
|
|
1952
1953
|
}));
|
|
@@ -1955,13 +1956,13 @@ async function yo(e, t, n) {
|
|
|
1955
1956
|
async function bo(e, t, n) {
|
|
1956
1957
|
let r = await e.ceremony.claimBrowser(t, n);
|
|
1957
1958
|
if (r?.kind !== "browser_claimed") return W(r);
|
|
1958
|
-
let i = go(await
|
|
1959
|
+
let i = go(await cn({ authorizationUrl: r.authorizationUrl }));
|
|
1959
1960
|
for (let e of r.setCookies) i.headers.append("Set-Cookie", e);
|
|
1960
1961
|
return i;
|
|
1961
1962
|
}
|
|
1962
1963
|
async function xo(e, t) {
|
|
1963
1964
|
if (e.headers.get("origin") !== t || !/^application\/x-www-form-urlencoded(?:\s*;\s*charset=utf-8)?$/i.test(e.headers.get("content-type") ?? "")) return null;
|
|
1964
|
-
let n = e.clone(), r = await
|
|
1965
|
+
let n = e.clone(), r = await $n({
|
|
1965
1966
|
body: n.body,
|
|
1966
1967
|
contentLength: n.headers.get("content-length")
|
|
1967
1968
|
});
|
|
@@ -2000,7 +2001,7 @@ async function So(e, t, n) {
|
|
|
2000
2001
|
completionSecret: i.completionSecret,
|
|
2001
2002
|
confirmationHash: r.confirmationHash
|
|
2002
2003
|
}));
|
|
2003
|
-
return a.headers.append("Set-Cookie",
|
|
2004
|
+
return a.headers.append("Set-Cookie", E("transaction")), a;
|
|
2004
2005
|
}
|
|
2005
2006
|
async function Co(e, t) {
|
|
2006
2007
|
let n = await e.ceremony.verifyCallback(t);
|
|
@@ -2010,7 +2011,7 @@ async function Co(e, t) {
|
|
|
2010
2011
|
reason: n.reason,
|
|
2011
2012
|
...n.returnTo
|
|
2012
2013
|
})) : await W(n);
|
|
2013
|
-
return e.headers.append("Set-Cookie",
|
|
2014
|
+
return e.headers.append("Set-Cookie", E("transaction")), e;
|
|
2014
2015
|
}
|
|
2015
2016
|
return n.kind === "verified" ? go(await uo({
|
|
2016
2017
|
confirmation: n.confirmation,
|
|
@@ -2027,15 +2028,15 @@ function wo(e, t) {
|
|
|
2027
2028
|
};
|
|
2028
2029
|
}
|
|
2029
2030
|
async function To(e) {
|
|
2030
|
-
let t =
|
|
2031
|
+
let t = A(e.config);
|
|
2031
2032
|
if (t.kind !== "enabled") return { ok: !1 };
|
|
2032
2033
|
let n = e.now ?? (() => Date.now()), r, i = async () => {
|
|
2033
2034
|
if (r) return r;
|
|
2034
|
-
let n = await
|
|
2035
|
+
let n = await sr(t.oidc, e.oidcOptions);
|
|
2035
2036
|
if (!n.ok) throw Error("device_rebind_oidc_unavailable");
|
|
2036
2037
|
return r ??= n.client, r;
|
|
2037
2038
|
}, a = {
|
|
2038
|
-
ceremony:
|
|
2039
|
+
ceremony: wr({
|
|
2039
2040
|
backend: e.backend,
|
|
2040
2041
|
config: t.store,
|
|
2041
2042
|
publicOrigin: t.publicOrigin,
|
|
@@ -2053,8 +2054,8 @@ async function To(e) {
|
|
|
2053
2054
|
publicOrigin: t.publicOrigin,
|
|
2054
2055
|
store: t.store
|
|
2055
2056
|
},
|
|
2056
|
-
startUrl: `${t.publicOrigin}${
|
|
2057
|
-
transactions: new
|
|
2057
|
+
startUrl: `${t.publicOrigin}${H.start}`,
|
|
2058
|
+
transactions: new p(e.backend, n)
|
|
2058
2059
|
};
|
|
2059
2060
|
return {
|
|
2060
2061
|
ok: !0,
|
|
@@ -2122,17 +2123,17 @@ async function Lo(e, t) {
|
|
|
2122
2123
|
attempt_id: r ?? "",
|
|
2123
2124
|
start_code: i ?? ""
|
|
2124
2125
|
});
|
|
2125
|
-
return n.searchParams.size !== 2 || !
|
|
2126
|
+
return n.searchParams.size !== 2 || !Qn(new TextEncoder().encode(a.toString()), "link_start").ok ? G() : Ro(e, t, {
|
|
2126
2127
|
attemptId: r ?? "",
|
|
2127
2128
|
startCode: i ?? ""
|
|
2128
2129
|
});
|
|
2129
2130
|
}
|
|
2130
2131
|
async function Ro(e, t, n) {
|
|
2131
|
-
let { scope: r, key: i } = t, a = await t.transactionActivity(e.headers.get("cookie")), o = await
|
|
2132
|
+
let { scope: r, key: i } = t, a = await t.transactionActivity(e.headers.get("cookie")), o = await b(e.headers.get("cookie"), "start");
|
|
2132
2133
|
if (a === "active" || a === "invalid" || o.kind === "invalid") return G();
|
|
2133
|
-
let s = o.kind === "absent" ? await
|
|
2134
|
+
let s = o.kind === "absent" ? await Ue("start") : null, c = o.kind === "present" ? o.secret : s?.secret;
|
|
2134
2135
|
if (!c) return G();
|
|
2135
|
-
let l = await
|
|
2136
|
+
let l = await x(i, c, "start", r);
|
|
2136
2137
|
return Po(`<h1>Enroll owner device</h1>${n.deviceId && n.fingerprint ? `<p>Compare these details with your local device review before choosing an account.</p><dl><dt>Device ID</dt><dd>${jo(n.deviceId)}</dd><dt>Key fingerprint</dt><dd>${jo(n.fingerprint)}</dd></dl>` : ""}${No(Eo, {
|
|
2137
2138
|
csrf: l,
|
|
2138
2139
|
attempt_id: n.attemptId,
|
|
@@ -2158,8 +2159,8 @@ function Bo(e, t) {
|
|
|
2158
2159
|
return e.headers.get("origin") === t && /^application\/x-www-form-urlencoded(?:\s*;\s*charset=utf-8)?$/i.test(e.headers.get("content-type") ?? "");
|
|
2159
2160
|
}
|
|
2160
2161
|
async function Vo(e, t, n, r) {
|
|
2161
|
-
if (!Bo(e, r) || (await
|
|
2162
|
-
let i = e.clone(), a = await
|
|
2162
|
+
if (!Bo(e, r) || (await b(e.headers.get("cookie"), "transaction")).kind !== "present") return G();
|
|
2163
|
+
let i = e.clone(), a = await $n({
|
|
2163
2164
|
body: i.body,
|
|
2164
2165
|
contentLength: i.headers.get("content-length")
|
|
2165
2166
|
});
|
|
@@ -2173,7 +2174,7 @@ async function Vo(e, t, n, r) {
|
|
|
2173
2174
|
if (c.length !== 1 || !/^[a-f0-9]{64}$/.test(c[0] ?? "")) return G();
|
|
2174
2175
|
s.delete("confirmation_hash");
|
|
2175
2176
|
let l = s.toString();
|
|
2176
|
-
if (!
|
|
2177
|
+
if (!Qn(new TextEncoder().encode(l), "transaction_attempt").ok) return G();
|
|
2177
2178
|
let u = new Headers(e.headers);
|
|
2178
2179
|
u.delete("content-length");
|
|
2179
2180
|
let d = new Request(e.url, {
|
|
@@ -2182,14 +2183,14 @@ async function Vo(e, t, n, r) {
|
|
|
2182
2183
|
body: l
|
|
2183
2184
|
}), f = await t.confirm(d, n, c[0]);
|
|
2184
2185
|
if (f.kind !== "confirmed") return G();
|
|
2185
|
-
let p =
|
|
2186
|
+
let p = Se(f.loopbackRedirect);
|
|
2186
2187
|
if (!p.ok) return G();
|
|
2187
2188
|
let m = new URL(p.destination);
|
|
2188
|
-
return m.searchParams.set("attempt_id", f.confirmation.attemptId), m.searchParams.set("completion", f.completionSecret), m.searchParams.set("confirmation", f.confirmation.confirmationHash), Io(m.href, [
|
|
2189
|
+
return m.searchParams.set("attempt_id", f.confirmation.attemptId), m.searchParams.set("completion", f.completionSecret), m.searchParams.set("confirmation", f.confirmation.confirmationHash), Io(m.href, [E("transaction")]);
|
|
2189
2190
|
}
|
|
2190
2191
|
async function Ho(e, t, n) {
|
|
2191
2192
|
if (!/^application\/json(?:\s*;\s*charset=utf-8)?$/i.test(e.headers.get("content-type") ?? "")) return G(415);
|
|
2192
|
-
let r = await
|
|
2193
|
+
let r = await $n({
|
|
2193
2194
|
body: e.body,
|
|
2194
2195
|
contentLength: e.headers.get("content-length")
|
|
2195
2196
|
});
|
|
@@ -2246,7 +2247,7 @@ function Ko(e, t) {
|
|
|
2246
2247
|
}
|
|
2247
2248
|
async function qo(e, t, n) {
|
|
2248
2249
|
try {
|
|
2249
|
-
return Ko(e, n) || (!C(t) || t.length > 128 ? G() :
|
|
2250
|
+
return Ko(e, n) || (!C(t) || t.length > 128 ? G() : Jn(e, n.limiter, JSON.stringify([
|
|
2250
2251
|
"owner-http",
|
|
2251
2252
|
n.pin.coordinatorId,
|
|
2252
2253
|
t
|
|
@@ -2277,11 +2278,11 @@ function Jo(e, t, n, r) {
|
|
|
2277
2278
|
}
|
|
2278
2279
|
async function Yo(e) {
|
|
2279
2280
|
if (e.mode !== void 0 && e.mode !== "private" && e.mode !== "local_test" && e.mode !== "production") throw Error("owner_enrollment_http_unavailable");
|
|
2280
|
-
let t =
|
|
2281
|
+
let t = A(e.config);
|
|
2281
2282
|
if (t.kind !== "enabled") throw Error("owner_enrollment_http_unavailable");
|
|
2282
2283
|
let n = new URL(t.store.redirectUri).pathname;
|
|
2283
2284
|
if (Wo(n, "private") || Wo(n, "production")) throw Error("owner_enrollment_http_unavailable");
|
|
2284
|
-
let r = e.mode === "production", i = r ? e.csrfKey : await
|
|
2285
|
+
let r = e.mode === "production", i = r ? e.csrfKey : await ut(globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32))), a = r ? e.limiter : Zn({ now: e.clock }), o = Jo(e, i, a, { production: r }), s = await yr(o);
|
|
2285
2286
|
if (!s.ok) throw Error("owner_enrollment_http_unavailable");
|
|
2286
2287
|
let c = Object.freeze({
|
|
2287
2288
|
coordinatorId: t.store.coordinatorId,
|
|
@@ -2291,7 +2292,7 @@ async function Yo(e) {
|
|
|
2291
2292
|
}), l = {
|
|
2292
2293
|
publicOrigin: c.origin,
|
|
2293
2294
|
store: t.store
|
|
2294
|
-
}, u = r ? "/v1/auth/owner-config" : "/v1/auth/owner-pilot", d = new
|
|
2295
|
+
}, u = r ? "/v1/auth/owner-config" : "/v1/auth/owner-pilot", d = new p(o.backend, o.clock);
|
|
2295
2296
|
return Xo({
|
|
2296
2297
|
api: s.enrollment,
|
|
2297
2298
|
scope: l,
|
|
@@ -2300,7 +2301,7 @@ async function Yo(e) {
|
|
|
2300
2301
|
callback: n,
|
|
2301
2302
|
pinPath: u,
|
|
2302
2303
|
limiter: a,
|
|
2303
|
-
transactionActivity: (e) =>
|
|
2304
|
+
transactionActivity: (e) => O(e, d, t.store)
|
|
2304
2305
|
}, { production: r });
|
|
2305
2306
|
}
|
|
2306
2307
|
function Xo(e, t) {
|
|
@@ -2421,9 +2422,9 @@ function os(e, t) {
|
|
|
2421
2422
|
return e.url.length <= 8192 && n.origin === t && !n.username && !n.password && !n.search && !n.hash && (r === null || r === t) && (e.method !== "POST" || r === t);
|
|
2422
2423
|
}
|
|
2423
2424
|
function ss(e) {
|
|
2424
|
-
let t =
|
|
2425
|
+
let t = A(e.config);
|
|
2425
2426
|
if (t.kind === "enabled" && new URL(t.store.redirectUri).pathname === "/auth/owner/admit") throw Error("owner_admission_callback_collision");
|
|
2426
|
-
let n = e.enabled && t.kind === "enabled" &&
|
|
2427
|
+
let n = e.enabled && t.kind === "enabled" && Mn(e.csrfKey) && _r(e.admissionKey);
|
|
2427
2428
|
return async (r, i) => {
|
|
2428
2429
|
if (new URL(r.url).pathname !== "/auth/owner/admit") return null;
|
|
2429
2430
|
if (!n || t.kind !== "enabled") return K(404);
|
|
@@ -2442,21 +2443,21 @@ function cs(e, t, n, r) {
|
|
|
2442
2443
|
]), 20).allowed ? null : K(429) : K();
|
|
2443
2444
|
}
|
|
2444
2445
|
async function ls(e, t, n, r) {
|
|
2445
|
-
let i = new
|
|
2446
|
-
return o === "active" || o === "invalid" || (await
|
|
2446
|
+
let i = new p(t, r), a = (e) => O(e, i, n.store), o = await a(e.headers.get("cookie"));
|
|
2447
|
+
return o === "active" || o === "invalid" || (await b(e.headers.get("cookie"), "start")).kind === "invalid" ? null : a;
|
|
2447
2448
|
}
|
|
2448
2449
|
async function us(e, t, n, r) {
|
|
2449
2450
|
let { backend: i, csrfKey: a } = n;
|
|
2450
|
-
if (!await
|
|
2451
|
-
let o = await
|
|
2451
|
+
if (!await cr(i)) return K();
|
|
2452
|
+
let o = await b(e.headers.get("cookie"), "session");
|
|
2452
2453
|
if (o.kind !== "present") return K(403);
|
|
2453
2454
|
let s = await n.readSession(o.cookieHash, r.store);
|
|
2454
2455
|
if (!s) return K(403);
|
|
2455
|
-
let c = () =>
|
|
2456
|
+
let c = () => Ut(n.clock ?? Date.now), l = {
|
|
2456
2457
|
backend: i,
|
|
2457
2458
|
config: r.store,
|
|
2458
2459
|
sessionCookieHash: o.cookieHash
|
|
2459
|
-
}, u = await
|
|
2460
|
+
}, u = await tr({
|
|
2460
2461
|
...l,
|
|
2461
2462
|
time: c(),
|
|
2462
2463
|
deviceId: "",
|
|
@@ -2472,7 +2473,7 @@ async function us(e, t, n, r) {
|
|
|
2472
2473
|
publicOrigin: r.publicOrigin,
|
|
2473
2474
|
store: r.store
|
|
2474
2475
|
}, f = await ls(e, i, r, c);
|
|
2475
|
-
return f ? e.method === "GET" ? as(await
|
|
2476
|
+
return f ? e.method === "GET" ? as(await x(a, o.secret, "session", d)) : ds(e, t, n, r, {
|
|
2476
2477
|
cookie: o,
|
|
2477
2478
|
owner: u,
|
|
2478
2479
|
transactionActivity: f,
|
|
@@ -2484,8 +2485,8 @@ async function ds(e, t, n, r, i) {
|
|
|
2484
2485
|
publicOrigin: r.publicOrigin,
|
|
2485
2486
|
store: r.store
|
|
2486
2487
|
}, p = await ts(e);
|
|
2487
|
-
if (!p || !await
|
|
2488
|
-
let { start: m } = p, h = await
|
|
2488
|
+
if (!p || !await In(u, a.secret, "session", f, p.csrf)) return K();
|
|
2489
|
+
let { start: m } = p, h = await dr(m.publicKey), g = await tr({
|
|
2489
2490
|
backend: l,
|
|
2490
2491
|
config: r.store,
|
|
2491
2492
|
sessionCookieHash: a.cookieHash,
|
|
@@ -2494,18 +2495,18 @@ async function ds(e, t, n, r, i) {
|
|
|
2494
2495
|
fingerprint: h
|
|
2495
2496
|
});
|
|
2496
2497
|
if (!g || JSON.stringify(g) !== JSON.stringify(o)) return K(403);
|
|
2497
|
-
let
|
|
2498
|
+
let _ = {
|
|
2498
2499
|
coordinatorId: r.store.coordinatorId,
|
|
2499
2500
|
origin: r.publicOrigin,
|
|
2500
2501
|
issuer: r.store.issuer,
|
|
2501
2502
|
revision: r.store.revision
|
|
2502
|
-
},
|
|
2503
|
+
}, ee = await lr(d, _, m, {
|
|
2503
2504
|
resolvedOwner: g,
|
|
2504
2505
|
nowMs: c(),
|
|
2505
2506
|
ttlMs: 6e4
|
|
2506
2507
|
});
|
|
2507
2508
|
return (await (await n.getEnrollment()).startOwnerBound(m, t, {
|
|
2508
|
-
admissionToken:
|
|
2509
|
+
admissionToken: ee,
|
|
2509
2510
|
resolvedOwner: g,
|
|
2510
2511
|
sessionCookieHash: a.cookieHash
|
|
2511
2512
|
})).kind === "started" ? Ro(e, {
|
|
@@ -2533,10 +2534,10 @@ var fs = /* @__PURE__ */ new WeakMap(), ps = /* @__PURE__ */ new WeakMap(), ms =
|
|
|
2533
2534
|
"/auth/owner/confirm": ["POST"],
|
|
2534
2535
|
"/auth/account/change/start": ["GET", "POST"],
|
|
2535
2536
|
"/auth/account/change/confirm": ["POST"],
|
|
2536
|
-
[
|
|
2537
|
-
[
|
|
2538
|
-
[
|
|
2539
|
-
[
|
|
2537
|
+
[H.start]: ["GET", "POST"],
|
|
2538
|
+
[H.confirm]: ["POST"],
|
|
2539
|
+
[Xn.code]: ["GET", "POST"],
|
|
2540
|
+
[Xn.confirm]: ["POST"]
|
|
2540
2541
|
}, hs = [
|
|
2541
2542
|
"/auth/owner/start",
|
|
2542
2543
|
"/auth/owner/confirm",
|
|
@@ -2568,7 +2569,7 @@ function _s(e) {
|
|
|
2568
2569
|
}
|
|
2569
2570
|
function vs(e) {
|
|
2570
2571
|
try {
|
|
2571
|
-
let t = q(e, "config"), n =
|
|
2572
|
+
let t = q(e, "config"), n = A(t);
|
|
2572
2573
|
if (n.kind === "disabled") {
|
|
2573
2574
|
let e = Object.freeze({ kind: "disabled" }), n = t === void 0 ? void 0 : q(t, "coordinatorId");
|
|
2574
2575
|
return C(n) && ps.set(e, n), e;
|
|
@@ -2582,7 +2583,7 @@ function vs(e) {
|
|
|
2582
2583
|
} catch {
|
|
2583
2584
|
return gs("csrfKey");
|
|
2584
2585
|
}
|
|
2585
|
-
if (!
|
|
2586
|
+
if (!Mn(i)) return gs("csrfKey");
|
|
2586
2587
|
let a;
|
|
2587
2588
|
try {
|
|
2588
2589
|
a = _s(q(e, "oidcOptions"));
|
|
@@ -2638,7 +2639,7 @@ function xs(e, t, n, r) {
|
|
|
2638
2639
|
});
|
|
2639
2640
|
if (i) return i;
|
|
2640
2641
|
if (!C(r) || r.length > 128) return new Response("Invalid request.", { status: 400 });
|
|
2641
|
-
let a =
|
|
2642
|
+
let a = Jn(t, n, JSON.stringify([
|
|
2642
2643
|
"owner-http",
|
|
2643
2644
|
e.config.coordinatorId,
|
|
2644
2645
|
r
|
|
@@ -2651,8 +2652,8 @@ function xs(e, t, n, r) {
|
|
|
2651
2652
|
function Ss(e, t, n, r) {
|
|
2652
2653
|
if (t.method !== "POST") return !0;
|
|
2653
2654
|
let i = new URL(t.url), a = "transaction_attempt";
|
|
2654
|
-
i.pathname === "/auth/logout" && (a = "session_logout"), i.pathname === "/auth/sign-in" && (a = "signin_start"), i.pathname === "/auth/link/start" && (a = "link_start"), i.pathname ===
|
|
2655
|
-
let o =
|
|
2655
|
+
i.pathname === "/auth/logout" && (a = "session_logout"), i.pathname === "/auth/sign-in" && (a = "signin_start"), i.pathname === "/auth/link/start" && (a = "link_start"), i.pathname === Ar.start && (a = "link_start"), i.pathname === H.start && (a = "link_start"), i.pathname === Xn.code && (a = "headless_code");
|
|
2656
|
+
let o = hr({
|
|
2656
2657
|
request: t,
|
|
2657
2658
|
scope: e.settings,
|
|
2658
2659
|
csrfKey: e.csrfKey,
|
|
@@ -2709,7 +2710,7 @@ function Ts(e) {
|
|
|
2709
2710
|
}
|
|
2710
2711
|
function Es(e, t) {
|
|
2711
2712
|
let n = t.ownerCallback || t.deviceRebindCallback;
|
|
2712
|
-
return
|
|
2713
|
+
return ki({
|
|
2713
2714
|
...e,
|
|
2714
2715
|
...t,
|
|
2715
2716
|
purposeStore: n ? zs(e.store) : void 0
|
|
@@ -2741,10 +2742,10 @@ async function Ds(e, t, n) {
|
|
|
2741
2742
|
oidcOptions: r.oidcOptions,
|
|
2742
2743
|
store: t,
|
|
2743
2744
|
limiter: n
|
|
2744
|
-
}), s =
|
|
2745
|
+
}), s = ma({
|
|
2745
2746
|
...o,
|
|
2746
2747
|
config: r.settings.store
|
|
2747
|
-
}), c =
|
|
2748
|
+
}), c = Ta({
|
|
2748
2749
|
...o,
|
|
2749
2750
|
config: r.settings.store
|
|
2750
2751
|
});
|
|
@@ -2752,12 +2753,12 @@ async function Ds(e, t, n) {
|
|
|
2752
2753
|
ok: !1,
|
|
2753
2754
|
error: "browser_auth_setup_failed"
|
|
2754
2755
|
});
|
|
2755
|
-
let l = await
|
|
2756
|
+
let l = await ao(o), u = await Ba(o), d = await Is(r, n), f = await Os(r, t, n, i.operations), p = await Es(o, {
|
|
2756
2757
|
completeLink: s.handlers.completeLink,
|
|
2757
2758
|
ownerCallback: d?.handleCallback,
|
|
2758
2759
|
accountChangeCallback: f.callback,
|
|
2759
2760
|
deviceRebindCallback: a.callback
|
|
2760
|
-
}), m = await
|
|
2761
|
+
}), m = await di(o);
|
|
2761
2762
|
if (!l.ok || !u.ok || !p.ok || !m.ok) return Object.freeze({
|
|
2762
2763
|
ok: !1,
|
|
2763
2764
|
error: "browser_auth_setup_failed"
|
|
@@ -2813,7 +2814,7 @@ async function Os(e, t, n, r) {
|
|
|
2813
2814
|
enabled: !1,
|
|
2814
2815
|
routes: []
|
|
2815
2816
|
};
|
|
2816
|
-
let i = await
|
|
2817
|
+
let i = await Zr({
|
|
2817
2818
|
config: e.config,
|
|
2818
2819
|
csrfKey: e.csrfKey,
|
|
2819
2820
|
oidcOptions: e.oidcOptions,
|
|
@@ -2833,11 +2834,11 @@ async function Os(e, t, n, r) {
|
|
|
2833
2834
|
return {
|
|
2834
2835
|
enabled: !0,
|
|
2835
2836
|
routes: [{
|
|
2836
|
-
path:
|
|
2837
|
+
path: Ar.start,
|
|
2837
2838
|
get: async (e) => ({ response: await i.handlers.startPage(e) }),
|
|
2838
2839
|
post: async (e, t) => ({ response: await i.handlers.start(e, t) })
|
|
2839
2840
|
}, {
|
|
2840
|
-
path:
|
|
2841
|
+
path: Ar.confirm,
|
|
2841
2842
|
post: async (e, t) => ({ response: await i.handlers.confirm(e, t) })
|
|
2842
2843
|
}],
|
|
2843
2844
|
callback: async (t, n, a) => {
|
|
@@ -2867,11 +2868,11 @@ function ks(e, t, n) {
|
|
|
2867
2868
|
};
|
|
2868
2869
|
return {
|
|
2869
2870
|
routes: [{
|
|
2870
|
-
path:
|
|
2871
|
+
path: H.start,
|
|
2871
2872
|
get: o("startPage"),
|
|
2872
2873
|
post: o("start")
|
|
2873
2874
|
}, {
|
|
2874
|
-
path:
|
|
2875
|
+
path: H.confirm,
|
|
2875
2876
|
post: o("confirm")
|
|
2876
2877
|
}],
|
|
2877
2878
|
callback: async (e) => {
|
|
@@ -2893,7 +2894,7 @@ function As(e, t, n, r) {
|
|
|
2893
2894
|
let t = await i();
|
|
2894
2895
|
if (!t) return null;
|
|
2895
2896
|
if (s) return s;
|
|
2896
|
-
let r = await
|
|
2897
|
+
let r = await $i({
|
|
2897
2898
|
config: e.config,
|
|
2898
2899
|
csrfKey: e.csrfKey,
|
|
2899
2900
|
oidcOptions: e.oidcOptions,
|
|
@@ -2904,7 +2905,7 @@ function As(e, t, n, r) {
|
|
|
2904
2905
|
return r.ok ? (s ??= r.handlers, s) : null;
|
|
2905
2906
|
};
|
|
2906
2907
|
return [{
|
|
2907
|
-
path:
|
|
2908
|
+
path: Xn.code,
|
|
2908
2909
|
get: async (e) => {
|
|
2909
2910
|
let t = await c();
|
|
2910
2911
|
return { response: t ? await t.codePage(e) : js() };
|
|
@@ -2915,7 +2916,7 @@ function As(e, t, n, r) {
|
|
|
2915
2916
|
},
|
|
2916
2917
|
needsClientAddress: !0
|
|
2917
2918
|
}, {
|
|
2918
|
-
path:
|
|
2919
|
+
path: Xn.confirm,
|
|
2919
2920
|
post: async (e, t, n) => await c() ? r(e, t, n) : { response: js() },
|
|
2920
2921
|
needsClientAddress: !0
|
|
2921
2922
|
}];
|
|
@@ -2942,15 +2943,15 @@ function Ms(e, t, n) {
|
|
|
2942
2943
|
async function Ns(e) {
|
|
2943
2944
|
try {
|
|
2944
2945
|
let t = Ls(e, "readAccountChangeCapability");
|
|
2945
|
-
return t ? { operations: await t() } : (await
|
|
2946
|
+
return t ? { operations: await t() } : (await mt(e), { operations: await Rs(e) });
|
|
2946
2947
|
} catch (e) {
|
|
2947
|
-
return e instanceof
|
|
2948
|
+
return e instanceof Ln ? { error: Bn } : { error: "browser_auth_store_unavailable" };
|
|
2948
2949
|
}
|
|
2949
2950
|
}
|
|
2950
2951
|
function Ps(e) {
|
|
2951
|
-
return e instanceof
|
|
2952
|
+
return e instanceof Ln ? Object.freeze({
|
|
2952
2953
|
ok: !1,
|
|
2953
|
-
error:
|
|
2954
|
+
error: Bn
|
|
2954
2955
|
}) : Object.freeze({
|
|
2955
2956
|
ok: !1,
|
|
2956
2957
|
error: "browser_auth_setup_failed"
|
|
@@ -3002,7 +3003,7 @@ async function Rs(e) {
|
|
|
3002
3003
|
if (!n || !r) throw Error();
|
|
3003
3004
|
let i = await n();
|
|
3004
3005
|
if (i === "v2") return null;
|
|
3005
|
-
if (i !== "ready") throw new
|
|
3006
|
+
if (i !== "ready") throw new Ln();
|
|
3006
3007
|
return await r();
|
|
3007
3008
|
}
|
|
3008
3009
|
function zs(e) {
|
|
@@ -3174,14 +3175,14 @@ var Us = {
|
|
|
3174
3175
|
AND (a.enrollment_identity_id IS NULL OR a.enrollment_identity_id=a.identity_id)
|
|
3175
3176
|
AND (d.identity_id=a.identity_id AND d.group_id=a.group_id AND d.device_id=a.device_id
|
|
3176
3177
|
AND d.public_key=a.public_key AND d.fingerprint=a.fingerprint)
|
|
3177
|
-
AND (${
|
|
3178
|
+
AND (${ur({
|
|
3178
3179
|
link: "l",
|
|
3179
3180
|
connections: !0
|
|
3180
3181
|
})})
|
|
3181
|
-
AND (${
|
|
3182
|
+
AND (${yt({
|
|
3182
3183
|
link: "l",
|
|
3183
3184
|
connections: !0
|
|
3184
|
-
})})`, Ks = Object.entries(Us).map(([e, t]) => `${t} AS ${e}`).join(","), qs =
|
|
3185
|
+
})})`, Ks = Object.entries(Us).map(([e, t]) => `${t} AS ${e}`).join(","), qs = mr.map((e, t) => Oe(e.replace(/^(?:\s|--[^\n]*\n)*/u, "").replace(/;\s*$/u, ""), t === 0 ? { auxiliaryObjects: 5 } : void 0).matches).join(" AND ");
|
|
3185
3186
|
async function Js(e, t) {
|
|
3186
3187
|
let n = new TextEncoder().encode(JSON.stringify([
|
|
3187
3188
|
"codemem.owner-enrollment-qualification.preview.v1",
|
|
@@ -3215,10 +3216,10 @@ var Xs = () => ({
|
|
|
3215
3216
|
clock;
|
|
3216
3217
|
config;
|
|
3217
3218
|
constructor(e, t, n = Date.now) {
|
|
3218
|
-
this.backend = e, this.clock = n, this.config =
|
|
3219
|
+
this.backend = e, this.clock = n, this.config = Mt(t);
|
|
3219
3220
|
}
|
|
3220
3221
|
async schemaReady() {
|
|
3221
|
-
return await
|
|
3222
|
+
return await v(this.backend) === "ready" && (await this.backend.first({
|
|
3222
3223
|
sql: `SELECT (${qs}) AS ready`,
|
|
3223
3224
|
values: []
|
|
3224
3225
|
}))?.ready === 1;
|
|
@@ -3234,12 +3235,12 @@ var Xs = () => ({
|
|
|
3234
3235
|
n.issuer
|
|
3235
3236
|
]
|
|
3236
3237
|
});
|
|
3237
|
-
if (!r || !
|
|
3238
|
-
let i = await
|
|
3238
|
+
if (!r || !ln(r.evidence_digest)) return null;
|
|
3239
|
+
let i = await o(r.public_key);
|
|
3239
3240
|
if (!i || i !== r.key_id) return null;
|
|
3240
3241
|
let a = {
|
|
3241
3242
|
source: r,
|
|
3242
|
-
guard: await
|
|
3243
|
+
guard: await kn(this.backend, r.identity_id, {
|
|
3243
3244
|
groupId: r.source_group_id,
|
|
3244
3245
|
deviceId: r.device_id,
|
|
3245
3246
|
publicKey: r.public_key,
|
|
@@ -3276,13 +3277,13 @@ var Xs = () => ({
|
|
|
3276
3277
|
});
|
|
3277
3278
|
}
|
|
3278
3279
|
async preview(e) {
|
|
3279
|
-
let t =
|
|
3280
|
+
let t = Tt(e, ["attestationId"]);
|
|
3280
3281
|
if (!C(t?.attestationId)) return {
|
|
3281
3282
|
kind: "rejected",
|
|
3282
3283
|
error: "invalid_input"
|
|
3283
3284
|
};
|
|
3284
3285
|
try {
|
|
3285
|
-
let e = await this.prepare(t.attestationId,
|
|
3286
|
+
let e = await this.prepare(t.attestationId, Ut(this.clock));
|
|
3286
3287
|
if (!e) return Xs();
|
|
3287
3288
|
let n = await this.existing(e);
|
|
3288
3289
|
return n && !this.matches(n, e.source) ? {
|
|
@@ -3294,14 +3295,14 @@ var Xs = () => ({
|
|
|
3294
3295
|
}
|
|
3295
3296
|
}
|
|
3296
3297
|
async issue(e) {
|
|
3297
|
-
let t =
|
|
3298
|
-
if (!C(t?.attestationId) || !
|
|
3298
|
+
let t = Tt(e, ["attestationId", "expectedDigest"]);
|
|
3299
|
+
if (!C(t?.attestationId) || !ln(t?.expectedDigest)) return {
|
|
3299
3300
|
kind: "rejected",
|
|
3300
3301
|
error: "invalid_input"
|
|
3301
3302
|
};
|
|
3302
3303
|
let n = !1;
|
|
3303
3304
|
try {
|
|
3304
|
-
let e =
|
|
3305
|
+
let e = Ut(this.clock), r = await this.prepare(t.attestationId, e);
|
|
3305
3306
|
if (!r) return Xs();
|
|
3306
3307
|
if (r.digest !== t.expectedDigest) return {
|
|
3307
3308
|
kind: "rejected",
|
|
@@ -3335,14 +3336,14 @@ var Xs = () => ({
|
|
|
3335
3336
|
});
|
|
3336
3337
|
}
|
|
3337
3338
|
async revoke(e) {
|
|
3338
|
-
let t =
|
|
3339
|
+
let t = Tt(e, ["qualificationId", "linkId"]);
|
|
3339
3340
|
if (!C(t?.qualificationId) || !C(t?.linkId)) return {
|
|
3340
3341
|
kind: "rejected",
|
|
3341
3342
|
error: "invalid_input"
|
|
3342
3343
|
};
|
|
3343
3344
|
let n = !1;
|
|
3344
3345
|
try {
|
|
3345
|
-
let e = this.config, r =
|
|
3346
|
+
let e = this.config, r = Ut(this.clock);
|
|
3346
3347
|
if (!e?.enabled || !await this.schemaReady()) return Xs();
|
|
3347
3348
|
let i = [
|
|
3348
3349
|
e.coordinatorId,
|
|
@@ -3388,8 +3389,8 @@ var Xs = () => ({
|
|
|
3388
3389
|
error: "qualification_conflict"
|
|
3389
3390
|
};
|
|
3390
3391
|
}
|
|
3391
|
-
}, Qs = "CASE WHEN substr(sql, 1, 52) = 'CREATE TABLE \"coordinator_owner_enrollment_attempts\"'\n THEN 'CREATE TABLE coordinator_owner_enrollment_attempts' || substr(sql, 53) ELSE sql END", $s =
|
|
3392
|
-
let n =
|
|
3392
|
+
}, Qs = "CASE WHEN substr(sql, 1, 52) = 'CREATE TABLE \"coordinator_owner_enrollment_attempts\"'\n THEN 'CREATE TABLE coordinator_owner_enrollment_attempts' || substr(sql, 53) ELSE sql END", $s = ye.replace(/^--[^\n]*$/gm, "").trim().split(/\n(?=CREATE )/u).map((e, t) => {
|
|
3393
|
+
let n = Oe(e.trim().replace(/;$/u, ""), t === 0 ? { auxiliaryObjects: 13 } : void 0);
|
|
3393
3394
|
return t === 0 ? {
|
|
3394
3395
|
...n,
|
|
3395
3396
|
matches: n.matches.replace(/\bsql\b/u, Qs)
|
|
@@ -3404,7 +3405,7 @@ async function ec(e, t) {
|
|
|
3404
3405
|
return crypto.subtle.verify("HMAC", a, o, i);
|
|
3405
3406
|
}
|
|
3406
3407
|
function tc(e) {
|
|
3407
|
-
return !e || Object.keys(e).some((e) => !["attestation_id", "confirm_evidence_digest"].includes(e)) ||
|
|
3408
|
+
return !e || Object.keys(e).some((e) => !["attestation_id", "confirm_evidence_digest"].includes(e)) || !er(e.attestation_id) || Object.hasOwn(e, "confirm_evidence_digest") && !ln(e.confirm_evidence_digest) ? null : {
|
|
3408
3409
|
attestationId: e.attestation_id,
|
|
3409
3410
|
expectedDigest: e.confirm_evidence_digest
|
|
3410
3411
|
};
|
|
@@ -3458,7 +3459,7 @@ async function oc(e, t) {
|
|
|
3458
3459
|
}))?.ready === 1 && await t.schemaReady();
|
|
3459
3460
|
}
|
|
3460
3461
|
function sc(e) {
|
|
3461
|
-
let t =
|
|
3462
|
+
let t = Mt(e.config), n = { ...e }, r = n.backend, i = t && r ? new Zs(r, t) : null;
|
|
3462
3463
|
return async (e) => {
|
|
3463
3464
|
e.header("Cache-Control", "no-store"), e.header("Referrer-Policy", "no-referrer"), e.header("X-Content-Type-Options", "nosniff");
|
|
3464
3465
|
try {
|
|
@@ -3534,7 +3535,7 @@ function mc(e) {
|
|
|
3534
3535
|
let i = t.limiter.check(n, r ? 20 : 60);
|
|
3535
3536
|
return i.allowed ? !r || !t.config || !t.backend ? null : uc(e, t.origin) : (e.header("Retry-After", String(i.retryAfterS)), e.json({ error: "rate_limited" }, 429));
|
|
3536
3537
|
}
|
|
3537
|
-
}), r = new
|
|
3538
|
+
}), r = new vr();
|
|
3538
3539
|
return r.all(cc, n), { fetch: (e) => r.fetch(e) };
|
|
3539
3540
|
}
|
|
3540
3541
|
//#endregion
|
|
@@ -3609,7 +3610,7 @@ function Dc(e) {
|
|
|
3609
3610
|
return Number(e?.meta?.changes ?? 0);
|
|
3610
3611
|
}
|
|
3611
3612
|
function Oc(e, t = {}) {
|
|
3612
|
-
return
|
|
3613
|
+
return bt(kc(e), t);
|
|
3613
3614
|
}
|
|
3614
3615
|
function kc(e) {
|
|
3615
3616
|
return {
|
|
@@ -3641,8 +3642,8 @@ async function $(e) {
|
|
|
3641
3642
|
let t = await e.run();
|
|
3642
3643
|
return Number(t?.meta?.changes ?? 0);
|
|
3643
3644
|
}
|
|
3644
|
-
var jc = `${
|
|
3645
|
-
OR ${
|
|
3645
|
+
var jc = `${ct}
|
|
3646
|
+
OR ${ct}`, Mc = Et, Nc = `EXISTS (
|
|
3646
3647
|
SELECT 1 FROM coordinator_invites ri
|
|
3647
3648
|
JOIN groups rg ON rg.group_id = ri.group_id AND rg.archived_at IS NULL
|
|
3648
3649
|
WHERE ri.invite_id = ? AND ri.group_id = ? AND ri.revoked_at IS NULL
|
|
@@ -3735,22 +3736,22 @@ async function zc(e, t) {
|
|
|
3735
3736
|
}
|
|
3736
3737
|
}
|
|
3737
3738
|
async function Bc(e, t, n) {
|
|
3738
|
-
let r = await
|
|
3739
|
-
FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(t.group_id, t.inviter_device_id)) : null, a = i ? { ...i } : null,
|
|
3739
|
+
let r = await o(n.publicKey), i = t.inviter_device_id ? await Q(e.prepare(`SELECT ${bc}
|
|
3740
|
+
FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(t.group_id, t.inviter_device_id)) : null, a = i ? { ...i } : null, s = Rc(t, n, a, {
|
|
3740
3741
|
recipient: r,
|
|
3741
|
-
inviter: a ? await
|
|
3742
|
-
}),
|
|
3743
|
-
let a = i.requireBinding ? `${
|
|
3744
|
-
WHERE group_id = ? AND device_id = ? AND public_key = ? AND fingerprint = ? AND enabled = 1)` :
|
|
3745
|
-
...
|
|
3742
|
+
inviter: a ? await o(a.public_key) : null
|
|
3743
|
+
}), c = async (i) => {
|
|
3744
|
+
let a = i.requireBinding ? `${s.boundEligibilitySql} AND EXISTS (SELECT 1 FROM enrolled_devices
|
|
3745
|
+
WHERE group_id = ? AND device_id = ? AND public_key = ? AND fingerprint = ? AND enabled = 1)` : s.eligibilitySql, o = i.requireBinding ? [
|
|
3746
|
+
...s.boundEligibilityValues,
|
|
3746
3747
|
t.group_id,
|
|
3747
3748
|
n.deviceId,
|
|
3748
3749
|
n.publicKey,
|
|
3749
3750
|
n.fingerprint
|
|
3750
|
-
] :
|
|
3751
|
-
if ((await zc(() => e.prepare(`SELECT (${jc}) AS revoked`).bind(...
|
|
3751
|
+
] : s.eligibilityValues;
|
|
3752
|
+
if ((await zc(() => e.prepare(`SELECT (${jc}) AS revoked`).bind(...s.revocationValues), ["revoked"])).revoked === 1) throw Error("device_revoked");
|
|
3752
3753
|
let c = await zc(() => e.prepare(`SELECT (${jc}) AS revoked,
|
|
3753
|
-
(${Mc}) AS owned, (${a}) AS eligible`).bind(...
|
|
3754
|
+
(${Mc}) AS owned, (${a}) AS eligible`).bind(...s.revocationValues, ...s.ownershipValues, ...o), [
|
|
3754
3755
|
"revoked",
|
|
3755
3756
|
"owned",
|
|
3756
3757
|
"eligible"
|
|
@@ -3759,8 +3760,8 @@ async function Bc(e, t, n) {
|
|
|
3759
3760
|
c.eligible === 0 && await Gc(e, t, n, r, { owned: c.owned === 1 });
|
|
3760
3761
|
};
|
|
3761
3762
|
return {
|
|
3762
|
-
...
|
|
3763
|
-
assertEligible:
|
|
3763
|
+
...s,
|
|
3764
|
+
assertEligible: c
|
|
3764
3765
|
};
|
|
3765
3766
|
}
|
|
3766
3767
|
async function Vc(e, t, n) {
|
|
@@ -3773,15 +3774,15 @@ async function Vc(e, t, n) {
|
|
|
3773
3774
|
let i = await e.batch([...t, e.prepare(`WITH recipient_negative AS MATERIALIZED (${r.sql})
|
|
3774
3775
|
SELECT CASE WHEN (${n.sql}) AND (SELECT matches FROM recipient_negative)
|
|
3775
3776
|
THEN 1 ELSE json('recipient_invite_authorization_failed') END AS confirmed`).bind(...r.values, ...n.values)]), a = i[t.length];
|
|
3776
|
-
if (
|
|
3777
|
-
for (let e of i.slice(0, t.length))
|
|
3778
|
-
return
|
|
3777
|
+
if (Rn(a) !== 0 || a?.results?.[0]?.confirmed !== 1) throw Error("device_ownership_authorization_unavailable");
|
|
3778
|
+
for (let e of i.slice(0, t.length)) Rn(e);
|
|
3779
|
+
return Rn(i[0]);
|
|
3779
3780
|
} catch {
|
|
3780
3781
|
throw await n.assertEligible({ requireBinding: !1 }), Error("device_ownership_authorization_unavailable");
|
|
3781
3782
|
}
|
|
3782
3783
|
}
|
|
3783
3784
|
function Hc(e, t, n) {
|
|
3784
|
-
let r = e.prepare(n ?
|
|
3785
|
+
let r = e.prepare(n ? xe(t, n) : t);
|
|
3785
3786
|
return { bind: (...e) => r.bind(...n?.values ?? [], ...e) };
|
|
3786
3787
|
}
|
|
3787
3788
|
function Uc(e) {
|
|
@@ -3809,11 +3810,11 @@ async function Wc(e, t, n, r, i) {
|
|
|
3809
3810
|
}) === 1 ? i.consistency.retainedRecheck : a;
|
|
3810
3811
|
}
|
|
3811
3812
|
async function Gc(e, t, n, r, i = {}) {
|
|
3812
|
-
let a = await Q(e.prepare("SELECT public_key\n FROM enrolled_devices WHERE group_id = ? AND device_id = ?").bind(t.group_id, t.inviter_device_id)),
|
|
3813
|
+
let a = await Q(e.prepare("SELECT public_key\n FROM enrolled_devices WHERE group_id = ? AND device_id = ?").bind(t.group_id, t.inviter_device_id)), s = a ? await o(a.public_key) : null;
|
|
3813
3814
|
if (await Q(e.prepare(`SELECT 1 AS revoked
|
|
3814
|
-
WHERE ${jc}`).bind(n.deviceId, r, t.inviter_device_id,
|
|
3815
|
-
let
|
|
3816
|
-
throw !
|
|
3815
|
+
WHERE ${jc}`).bind(n.deviceId, r, t.inviter_device_id, s))) throw Error("device_revoked");
|
|
3816
|
+
let c = await Q(e.prepare("SELECT i.revoked_at, g.group_id AS current_group_id, g.archived_at,\n i.consumed_at, i.bound_device_id, i.bound_public_key, i.bound_fingerprint, i.recipient_actor_id\n FROM coordinator_invites i LEFT JOIN groups g ON g.group_id = i.group_id\n WHERE i.invite_id = ?").bind(t.invite_id));
|
|
3817
|
+
throw !c || c.revoked_at ? Error("invite_invalid") : c.current_group_id === null ? Error("group_not_found") : c.archived_at ? Error("group_archived") : i.owned ? Error("device_ownership_requires_verified_identity") : (Ic(c, n, { requireBinding: !1 }), Error("invite_acceptance_incomplete"));
|
|
3817
3818
|
}
|
|
3818
3819
|
function Kc(e, t, n, r, i) {
|
|
3819
3820
|
let a = i.requireBinding ? r.boundEligibilitySql : r.eligibilitySql, o = i.requireBinding ? r.boundEligibilityValues : r.eligibilityValues, s = t.consumed_at || i.requireBinding ? Zc : "1", c = s === "1" ? [] : [t.group_id, n.deviceId];
|
|
@@ -3824,25 +3825,25 @@ async function qc(e, t, n) {
|
|
|
3824
3825
|
let r = {
|
|
3825
3826
|
...n,
|
|
3826
3827
|
identityId: n.recipientActorId
|
|
3827
|
-
}, i = await Q(e.prepare(`SELECT ${bc} FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(t.group_id, n.deviceId)), a =
|
|
3828
|
-
FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(t.group_id, t.inviter_device_id)) : null,
|
|
3829
|
-
recipient:
|
|
3830
|
-
inviter:
|
|
3831
|
-
}),
|
|
3832
|
-
incoming:
|
|
3833
|
-
current:
|
|
3834
|
-
}),
|
|
3835
|
-
let a = await zc(() => Kc(e, t, n,
|
|
3828
|
+
}, i = await Q(e.prepare(`SELECT ${bc} FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(t.group_id, n.deviceId)), a = dt(i), s = i ? { ...i } : null, c = await o(n.publicKey), l = a === null ? null : await o(a), u = t.inviter_device_id ? await Q(e.prepare(`SELECT ${bc}
|
|
3829
|
+
FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(t.group_id, t.inviter_device_id)) : null, d = dt(u), f = u ? { ...u } : null, p = d === null ? null : await o(d), m = Hn(t, n, f, {
|
|
3830
|
+
recipient: c,
|
|
3831
|
+
inviter: p
|
|
3832
|
+
}), h = Ve(m, n.deviceId, {
|
|
3833
|
+
incoming: c,
|
|
3834
|
+
current: l
|
|
3835
|
+
}), g = async (i) => {
|
|
3836
|
+
let a = await zc(() => Kc(e, t, n, h, i), [
|
|
3836
3837
|
"revoked",
|
|
3837
3838
|
"owned",
|
|
3838
3839
|
"eligible"
|
|
3839
3840
|
]);
|
|
3840
3841
|
if (a.revoked === 1) throw Error("device_revoked");
|
|
3841
|
-
a.eligible === 0 && (a.owned === 0 && Fc(
|
|
3842
|
+
a.eligible === 0 && (a.owned === 0 && Fc(s, r), await Gc(e, t, r, c, { owned: a.owned === 1 }));
|
|
3842
3843
|
};
|
|
3843
|
-
return await
|
|
3844
|
-
...
|
|
3845
|
-
assertEligible:
|
|
3844
|
+
return await g({ requireBinding: !1 }), Fc(s, r), {
|
|
3845
|
+
...h,
|
|
3846
|
+
assertEligible: g
|
|
3846
3847
|
};
|
|
3847
3848
|
}
|
|
3848
3849
|
function Jc(e, t, n, r) {
|
|
@@ -3879,7 +3880,7 @@ var el = class {
|
|
|
3879
3880
|
db;
|
|
3880
3881
|
authLinks;
|
|
3881
3882
|
async assertAuthSchemaReady() {
|
|
3882
|
-
await
|
|
3883
|
+
await an({ first: ({ sql: e, values: t }) => this.db.prepare(e).bind(...t).first() });
|
|
3883
3884
|
}
|
|
3884
3885
|
accountLinkStatus;
|
|
3885
3886
|
accountOwnerTarget;
|
|
@@ -3888,7 +3889,7 @@ var el = class {
|
|
|
3888
3889
|
authAccountProfiles;
|
|
3889
3890
|
authBrowserTransactions;
|
|
3890
3891
|
constructor(e, t = {}) {
|
|
3891
|
-
this.db = e, this.deviceRevocations = new
|
|
3892
|
+
this.db = e, this.deviceRevocations = new Fe({
|
|
3892
3893
|
all: (t) => e.prepare(t.sql).bind(...t.values).all(),
|
|
3893
3894
|
batch: async (t) => {
|
|
3894
3895
|
if (!e.batch) throw Error("device_revocation_atomic_batch_required");
|
|
@@ -3896,13 +3897,13 @@ var el = class {
|
|
|
3896
3897
|
}
|
|
3897
3898
|
}, t.authClock);
|
|
3898
3899
|
let n = Oc(e);
|
|
3899
|
-
this.accountChangeBackend = Oc(e, { connections: !0 }), this.accountChangesCapability = new
|
|
3900
|
+
this.accountChangeBackend = Oc(e, { connections: !0 }), this.accountChangesCapability = new Kt(this.accountChangeBackend, t.authClock), this.authLinks = new h(n, t.authClock), this.accountLinkStatus = new wn(n, t.authClock), this.accountOwnerTarget = new Ot(n, this), this.authSessions = new tt(n, t.authClock), this.authAccountProfiles = new _e(n, t.authClock), this.authBrowserTransactions = new p(n, t.authClock);
|
|
3900
3901
|
}
|
|
3901
3902
|
readDeviceRebindBackend() {
|
|
3902
|
-
return
|
|
3903
|
+
return Me(kc(this.db));
|
|
3903
3904
|
}
|
|
3904
3905
|
readHeadlessLinkBackend() {
|
|
3905
|
-
return
|
|
3906
|
+
return fn(kc(this.db));
|
|
3906
3907
|
}
|
|
3907
3908
|
async getAccountChanges() {
|
|
3908
3909
|
return await this.accountChangeBackend.first({
|
|
@@ -3911,11 +3912,11 @@ var el = class {
|
|
|
3911
3912
|
}), this.accountChangesCapability;
|
|
3912
3913
|
}
|
|
3913
3914
|
readAccountConnectionSchemaState() {
|
|
3914
|
-
return
|
|
3915
|
+
return v({ first: ({ sql: e, values: t }) => this.db.prepare(e).bind(...t).first() });
|
|
3915
3916
|
}
|
|
3916
3917
|
async readAccountChangeCapability() {
|
|
3917
3918
|
let e = await this.readAccountConnectionSchemaState();
|
|
3918
|
-
if (e === "upgrade_required") throw new
|
|
3919
|
+
if (e === "upgrade_required") throw new Ln();
|
|
3919
3920
|
return e === "ready" ? this.accountChangesCapability : null;
|
|
3920
3921
|
}
|
|
3921
3922
|
async readAuthBrowserTransactionActivity(e, t) {
|
|
@@ -3997,7 +3998,7 @@ var el = class {
|
|
|
3997
3998
|
return this.accountOwnerTarget.readAccountOwnerTarget(...e);
|
|
3998
3999
|
}
|
|
3999
4000
|
readResolvedAccountOwnerStatus(...e) {
|
|
4000
|
-
return new
|
|
4001
|
+
return new Ee({
|
|
4001
4002
|
...this.accountChangeBackend,
|
|
4002
4003
|
all: async ({ sql: e, values: t }) => {
|
|
4003
4004
|
let n = await this.db.prepare(e).bind(...t).all();
|
|
@@ -4007,7 +4008,7 @@ var el = class {
|
|
|
4007
4008
|
}).readResolvedAccountOwnerStatus(...e);
|
|
4008
4009
|
}
|
|
4009
4010
|
ownerResolutionReviews() {
|
|
4010
|
-
return new
|
|
4011
|
+
return new le({
|
|
4011
4012
|
...Oc(this.db),
|
|
4012
4013
|
all: async ({ sql: e, values: t }) => {
|
|
4013
4014
|
let n = await this.db.prepare(e).bind(...t).all();
|
|
@@ -4069,13 +4070,13 @@ var el = class {
|
|
|
4069
4070
|
}
|
|
4070
4071
|
async close() {}
|
|
4071
4072
|
async issueIdentityGroupGrantFromControllerAttestation(e) {
|
|
4072
|
-
let t =
|
|
4073
|
+
let t = qt(e, ["coordinatorId", "attestationId"]);
|
|
4073
4074
|
if (!t) return {
|
|
4074
4075
|
kind: "rejected",
|
|
4075
4076
|
error: "invalid_grant_input"
|
|
4076
4077
|
};
|
|
4077
4078
|
try {
|
|
4078
|
-
let e = await Q(this.db.prepare(
|
|
4079
|
+
let e = await Q(this.db.prepare(Ae).bind(t.coordinatorId, t.attestationId));
|
|
4079
4080
|
if (!e) return {
|
|
4080
4081
|
kind: "rejected",
|
|
4081
4082
|
error: "grant_authority_unavailable"
|
|
@@ -4089,13 +4090,13 @@ var el = class {
|
|
|
4089
4090
|
e.fingerprint,
|
|
4090
4091
|
e.identity_id,
|
|
4091
4092
|
e.device_id,
|
|
4092
|
-
await
|
|
4093
|
-
], r = await Q(this.db.prepare(
|
|
4093
|
+
await o(e.public_key)
|
|
4094
|
+
], r = await Q(this.db.prepare(re).bind(Y(), ...n));
|
|
4094
4095
|
if (r) return {
|
|
4095
4096
|
kind: "created",
|
|
4096
4097
|
grant: r
|
|
4097
4098
|
};
|
|
4098
|
-
let i = await Q(this.db.prepare(
|
|
4099
|
+
let i = await Q(this.db.prepare(We).bind(...n));
|
|
4099
4100
|
return i ? {
|
|
4100
4101
|
kind: "existing",
|
|
4101
4102
|
grant: i
|
|
@@ -4108,58 +4109,58 @@ var el = class {
|
|
|
4108
4109
|
}
|
|
4109
4110
|
}
|
|
4110
4111
|
async listIdentityGroupGrantRevisions(e) {
|
|
4111
|
-
let t =
|
|
4112
|
+
let t = qt(e, ["coordinatorId", "identityId"]);
|
|
4112
4113
|
if (!t) throw Error("invalid_grant_input");
|
|
4113
|
-
let n = await this.db.prepare(
|
|
4114
|
+
let n = await this.db.prepare(Pn).bind(t.coordinatorId, t.identityId).all();
|
|
4114
4115
|
if (!Array.isArray(n?.results)) throw Error("identity_group_grant_read_incomplete");
|
|
4115
4116
|
return n.results;
|
|
4116
4117
|
}
|
|
4117
4118
|
async revokeIdentityGroupGrant(e) {
|
|
4118
|
-
let t =
|
|
4119
|
+
let t = qt(e, [
|
|
4119
4120
|
"coordinatorId",
|
|
4120
4121
|
"identityId",
|
|
4121
4122
|
"groupId",
|
|
4122
4123
|
"expectedRevision"
|
|
4123
4124
|
]);
|
|
4124
4125
|
if (!t) return !1;
|
|
4125
|
-
let n = (await this.db.prepare(
|
|
4126
|
+
let n = (await this.db.prepare(oe).bind(Y(), t.coordinatorId, t.identityId, t.groupId, t.expectedRevision).run())?.meta?.changes;
|
|
4126
4127
|
if (typeof n != "number" || !Number.isSafeInteger(n) || n < 0 || n > 1) throw Error("identity_group_grant_write_incomplete");
|
|
4127
4128
|
return n === 1;
|
|
4128
4129
|
}
|
|
4129
4130
|
async createAuthControllerAttestation(e) {
|
|
4130
|
-
let
|
|
4131
|
-
if (!
|
|
4131
|
+
let t = $t(e);
|
|
4132
|
+
if (!t) return {
|
|
4132
4133
|
kind: "rejected",
|
|
4133
4134
|
error: "invalid_review_input"
|
|
4134
4135
|
};
|
|
4135
|
-
let
|
|
4136
|
-
if (!
|
|
4137
|
-
let
|
|
4138
|
-
if (await Q(this.db.prepare(
|
|
4139
|
-
let
|
|
4140
|
-
if (!
|
|
4136
|
+
let n = await Q(this.db.prepare(Xe).bind(t.groupId, t.deviceId));
|
|
4137
|
+
if (!n) return Cn(t);
|
|
4138
|
+
let r = pn(n, await o(n.public_key));
|
|
4139
|
+
if (await Q(this.db.prepare(Un).bind(...ve(t)))) return this.resolveAuthControllerRetry(t, r);
|
|
4140
|
+
let i = await this.prepareAuthControllerConsistency(t);
|
|
4141
|
+
if (!i) return Cn(t);
|
|
4141
4142
|
try {
|
|
4142
|
-
let e =
|
|
4143
|
-
sql:
|
|
4144
|
-
values:
|
|
4145
|
-
},
|
|
4143
|
+
let e = De({
|
|
4144
|
+
sql: f(pe, t),
|
|
4145
|
+
values: it(t, Y(), r)
|
|
4146
|
+
}, i);
|
|
4146
4147
|
if (await $(this.db.prepare(e.sql).bind(...e.values)) === 0) {
|
|
4147
|
-
let e = await this.prepareAuthControllerConsistency(
|
|
4148
|
-
return e ? this.resolveAuthControllerRetry(
|
|
4148
|
+
let e = await this.prepareAuthControllerConsistency(t);
|
|
4149
|
+
return e ? this.resolveAuthControllerRetry(t, r, e) : Cn(t);
|
|
4149
4150
|
}
|
|
4150
4151
|
} catch (e) {
|
|
4151
|
-
if (!
|
|
4152
|
-
return this.resolveAuthControllerRetry(
|
|
4152
|
+
if (!pt(e)) throw e;
|
|
4153
|
+
return this.resolveAuthControllerRetry(t, r);
|
|
4153
4154
|
}
|
|
4154
|
-
let
|
|
4155
|
-
if (!
|
|
4155
|
+
let a = await Q(this.db.prepare(Le).bind(t.coordinatorId, t.attestationId, ...r));
|
|
4156
|
+
if (!a) throw Error("auth_controller_persistence_incomplete");
|
|
4156
4157
|
return {
|
|
4157
4158
|
kind: "created",
|
|
4158
|
-
attestation:
|
|
4159
|
+
attestation: a
|
|
4159
4160
|
};
|
|
4160
4161
|
}
|
|
4161
4162
|
prepareAuthControllerConsistency(e) {
|
|
4162
|
-
return
|
|
4163
|
+
return we({
|
|
4163
4164
|
first: ({ sql: e, values: t }) => this.db.prepare(e).bind(...t).first(),
|
|
4164
4165
|
all: async ({ sql: e, values: t }) => {
|
|
4165
4166
|
let n = await this.db.prepare(e).bind(...t).all();
|
|
@@ -4174,40 +4175,40 @@ var el = class {
|
|
|
4174
4175
|
});
|
|
4175
4176
|
}
|
|
4176
4177
|
async resolveAuthControllerRetry(e, t, n) {
|
|
4177
|
-
if (!await Q(this.db.prepare(
|
|
4178
|
-
let r = await Q(this.db.prepare(
|
|
4178
|
+
if (!await Q(this.db.prepare(f(Qe, e)).bind(...st(e, t)))) return Cn(e);
|
|
4179
|
+
let r = await Q(this.db.prepare(Un).bind(...ve(e))), i = Pe(e, r);
|
|
4179
4180
|
if (i.kind === "rejected") return i;
|
|
4180
4181
|
let a = {
|
|
4181
|
-
sql:
|
|
4182
|
-
values:
|
|
4182
|
+
sql: f(qe, e),
|
|
4183
|
+
values: nt(e, t)
|
|
4183
4184
|
};
|
|
4184
|
-
n && (a =
|
|
4185
|
+
n && (a = De(a, n));
|
|
4185
4186
|
let o = await Q(this.db.prepare(a.sql).bind(...a.values));
|
|
4186
|
-
return o ?
|
|
4187
|
+
return o ? Pe(e, o) : {
|
|
4187
4188
|
kind: "rejected",
|
|
4188
4189
|
error: e.verifiedSnapshot ? "review_stale" : "enrollment_mismatch"
|
|
4189
4190
|
};
|
|
4190
4191
|
}
|
|
4191
4192
|
async getActiveAuthControllerAttestation(e, t) {
|
|
4192
4193
|
if (!C(e) || !C(t)) return null;
|
|
4193
|
-
let n = await Q(this.db.prepare(
|
|
4194
|
+
let n = await Q(this.db.prepare(_).bind(e, t));
|
|
4194
4195
|
if (!n) return null;
|
|
4195
|
-
let r =
|
|
4196
|
-
return Q(this.db.prepare(
|
|
4196
|
+
let r = pn(n, await o(n.public_key));
|
|
4197
|
+
return Q(this.db.prepare(Le).bind(e, t, ...r));
|
|
4197
4198
|
}
|
|
4198
4199
|
async readAuthControllerAttestationForSnapshot(e) {
|
|
4199
|
-
let
|
|
4200
|
-
if (!
|
|
4201
|
-
let
|
|
4202
|
-
if (!
|
|
4203
|
-
let
|
|
4204
|
-
return Q(this.db.prepare(
|
|
4200
|
+
let t = $t(e);
|
|
4201
|
+
if (!t?.verifiedSnapshot?.accountOwnerTarget) return null;
|
|
4202
|
+
let n = await Q(this.db.prepare(Xe).bind(t.groupId, t.deviceId));
|
|
4203
|
+
if (!n) return null;
|
|
4204
|
+
let r = pn(n, await o(n.public_key));
|
|
4205
|
+
return Q(this.db.prepare(f(qe, t)).bind(...nt(t, r)));
|
|
4205
4206
|
}
|
|
4206
4207
|
async hasAuthControllerSubjectOwnerConflict(e) {
|
|
4207
|
-
return !!await Q(this.db.prepare(
|
|
4208
|
+
return !!await Q(this.db.prepare(rn).bind(...Dt(e)));
|
|
4208
4209
|
}
|
|
4209
4210
|
async revokeAuthControllerAttestation(e, t) {
|
|
4210
|
-
return !C(e) || !C(t) ? !1 : await $(this.db.prepare(
|
|
4211
|
+
return !C(e) || !C(t) ? !1 : await $(this.db.prepare(ue).bind(Y(), e, t)) > 0;
|
|
4211
4212
|
}
|
|
4212
4213
|
async createGroup(e, t) {
|
|
4213
4214
|
await this.db.prepare("INSERT OR IGNORE INTO groups(group_id, display_name, archived_at, created_at) VALUES (?, ?, NULL, ?)").bind(e, t ?? null, Y()).run();
|
|
@@ -4230,32 +4231,32 @@ var el = class {
|
|
|
4230
4231
|
return await $(this.db.prepare("UPDATE groups SET archived_at = NULL WHERE group_id = ? AND archived_at IS NOT NULL").bind(e)) > 0;
|
|
4231
4232
|
}
|
|
4232
4233
|
async enrollDevice(e, t) {
|
|
4233
|
-
let { deviceId: n, publicKey: r, fingerprint: i, identityId: a, displayName: s } =
|
|
4234
|
+
let { deviceId: n, publicKey: r, fingerprint: i, identityId: a, displayName: s } = It(e, t);
|
|
4234
4235
|
try {
|
|
4235
|
-
let t =
|
|
4236
|
+
let t = dt(await Q(this.db.prepare("SELECT public_key FROM enrolled_devices WHERE group_id = ? AND device_id = ?").bind(e, n))), c = await o(r), l = t === null ? null : await o(t), u = [
|
|
4236
4237
|
t,
|
|
4237
4238
|
e,
|
|
4238
4239
|
n,
|
|
4239
4240
|
e,
|
|
4240
4241
|
n,
|
|
4241
4242
|
t
|
|
4242
|
-
],
|
|
4243
|
-
if (
|
|
4244
|
-
let
|
|
4245
|
-
throw Error(
|
|
4243
|
+
], d = await this.db.prepare(Qt).bind(e, n, r, i, a ?? null, s ?? null, Y(), n, c, n, c, n, l, ...u, n, c, n, l, t).run();
|
|
4244
|
+
if (Rn(d) === 1) return;
|
|
4245
|
+
let f = await Q(this.db.prepare(un).bind(n, c, n, c, n, l, ...u));
|
|
4246
|
+
throw Error(_t(f));
|
|
4246
4247
|
} catch (e) {
|
|
4247
|
-
|
|
4248
|
+
Vn(e);
|
|
4248
4249
|
}
|
|
4249
4250
|
}
|
|
4250
4251
|
async listEnrolledDevices(e, t) {
|
|
4251
|
-
let n = t ? "" : "AND enrolled_devices.enabled = 1", r = (await Z(this.db.prepare(`SELECT ${xc}, ${
|
|
4252
|
+
let n = t ? "" : "AND enrolled_devices.enabled = 1", r = (await Z(this.db.prepare(`SELECT ${xc}, ${Wt}
|
|
4252
4253
|
FROM enrolled_devices
|
|
4253
4254
|
LEFT JOIN presence_records
|
|
4254
4255
|
ON presence_records.group_id = enrolled_devices.group_id
|
|
4255
4256
|
AND presence_records.device_id = enrolled_devices.device_id
|
|
4256
4257
|
WHERE enrolled_devices.group_id = ? ${n}
|
|
4257
4258
|
ORDER BY enrolled_devices.created_at ASC, enrolled_devices.device_id ASC`).bind(e))).map(hc);
|
|
4258
|
-
return
|
|
4259
|
+
return Te(r);
|
|
4259
4260
|
}
|
|
4260
4261
|
async getEnrollment(e, t, n = !1) {
|
|
4261
4262
|
let r = n ? "" : "AND enabled = 1", i = await Q(this.db.prepare(`SELECT ${bc}
|
|
@@ -4267,23 +4268,23 @@ var el = class {
|
|
|
4267
4268
|
return await $(this.db.prepare("UPDATE enrolled_devices SET display_name = ?\n WHERE group_id = ? AND device_id = ?").bind(n, e, t)) > 0;
|
|
4268
4269
|
}
|
|
4269
4270
|
async setDeviceEnabled(e, t, n) {
|
|
4270
|
-
if (
|
|
4271
|
+
if (zt(e, t), typeof n != "boolean") throw Error("invalid_input");
|
|
4271
4272
|
if (n) try {
|
|
4272
4273
|
let n = await Q(this.db.prepare("SELECT public_key FROM enrolled_devices WHERE group_id = ? AND device_id = ?").bind(e, t));
|
|
4273
4274
|
if (n === null) return !1;
|
|
4274
4275
|
if (!n) throw Error("device_ownership_authorization_unavailable");
|
|
4275
4276
|
let r = n.public_key;
|
|
4276
4277
|
if (typeof r != "string") throw Error("device_ownership_authorization_unavailable");
|
|
4277
|
-
let i = await
|
|
4278
|
+
let i = await o(r), a = await this.db.prepare(`UPDATE enrolled_devices SET enabled = 1
|
|
4278
4279
|
WHERE group_id = ? AND device_id = ? AND public_key = ?
|
|
4279
|
-
AND NOT ${
|
|
4280
|
-
AND NOT ${
|
|
4281
|
-
if (
|
|
4282
|
-
let
|
|
4283
|
-
if (
|
|
4280
|
+
AND NOT ${ct}
|
|
4281
|
+
AND NOT ${Et}`).bind(e, t, r, t, i, t, i).run();
|
|
4282
|
+
if (Rn(a) === 1) return !0;
|
|
4283
|
+
let s = _t(await Q(this.db.prepare(Nt).bind(t, i, t, i)));
|
|
4284
|
+
if (s === "device_ownership_requires_verified_identity") throw Error(s);
|
|
4284
4285
|
return !1;
|
|
4285
4286
|
} catch (e) {
|
|
4286
|
-
|
|
4287
|
+
Vn(e);
|
|
4287
4288
|
}
|
|
4288
4289
|
return await $(this.db.prepare("UPDATE enrolled_devices SET enabled = ?\n WHERE group_id = ? AND device_id = ?").bind(+!!n, e, t)) > 0;
|
|
4289
4290
|
}
|
|
@@ -4311,7 +4312,7 @@ var el = class {
|
|
|
4311
4312
|
return this.deviceRevocations.recordAuthorizedNonce(e);
|
|
4312
4313
|
}
|
|
4313
4314
|
async createInvite(e) {
|
|
4314
|
-
let t = Y(), n = X(12), r = X(24), i = await vc(r), a =
|
|
4315
|
+
let t = Y(), n = X(12), r = X(24), i = await vc(r), a = Ht(e.expiresAt), o = await this.getGroup(e.groupId), s = String(e.operationId ?? "").trim() || null, c = String(e.reviewedProjectSetDigest ?? "").trim() || null, l = await St(e), u = l.inviteKind === "team_member" ? `identity:${X(18)}` : null;
|
|
4315
4316
|
if (!!s != !!c) throw Error("operationId and reviewedProjectSetDigest must be provided together.");
|
|
4316
4317
|
let d = async () => {
|
|
4317
4318
|
if (!s) return null;
|
|
@@ -4362,10 +4363,10 @@ var el = class {
|
|
|
4362
4363
|
async inspectRecipientInvite(e) {
|
|
4363
4364
|
let t = await this.getInviteByTokenForInspection(e.token);
|
|
4364
4365
|
if (!t) return null;
|
|
4365
|
-
let n = await
|
|
4366
|
+
let n = await Bt(t);
|
|
4366
4367
|
if (!n) return null;
|
|
4367
4368
|
if (t.revoked_at) throw Error("invite_invalid");
|
|
4368
|
-
if (!t.consumed_at && new Date(t.expires_at) <= new Date(
|
|
4369
|
+
if (!t.consumed_at && new Date(t.expires_at) <= new Date(Ht(e.now))) throw Error("invite_expired");
|
|
4369
4370
|
let r = await this.getGroup(t.group_id);
|
|
4370
4371
|
if (!r) throw Error("group_not_found");
|
|
4371
4372
|
if (r.archived_at) throw Error("group_archived");
|
|
@@ -4393,27 +4394,27 @@ var el = class {
|
|
|
4393
4394
|
AND ${n.sql}`, n.negative).bind(n.consumedAt, e.invite_id, t.deviceId, ...n.values)], n);
|
|
4394
4395
|
}
|
|
4395
4396
|
async prepareEligibleRecipientOwner(e) {
|
|
4396
|
-
let t = Uc(this.db), n = await
|
|
4397
|
+
let t = Uc(this.db), n = await he(t, e);
|
|
4397
4398
|
if (!n) throw Error("device_ownership_authorization_unavailable");
|
|
4398
|
-
return await
|
|
4399
|
+
return await se(t, n), n;
|
|
4399
4400
|
}
|
|
4400
4401
|
async consumeRecipientInvite(e) {
|
|
4401
|
-
let t = { ...e }, n =
|
|
4402
|
-
|
|
4403
|
-
let a = await vc(t.token), o = structuredClone(await this.getInviteByTokenForInspection(t.token)), s = o ? await
|
|
4402
|
+
let t = { ...e }, n = Ht(t.now), r = t.recipientDisplayName ?? null, i = t.deviceDisplayName ?? null;
|
|
4403
|
+
Ie(t);
|
|
4404
|
+
let a = await vc(t.token), o = structuredClone(await this.getInviteByTokenForInspection(t.token)), s = o ? await Bt(o) : null;
|
|
4404
4405
|
if (!o || !s || s.kind !== t.inviteKind || o.revoked_at) throw Error("invite_invalid");
|
|
4405
|
-
let
|
|
4406
|
-
if (!
|
|
4407
|
-
if (
|
|
4406
|
+
let l = await this.getGroup(o.group_id);
|
|
4407
|
+
if (!l) throw Error("group_not_found");
|
|
4408
|
+
if (l.archived_at) throw Error("group_archived");
|
|
4408
4409
|
if (!o.consumed_at && new Date(o.expires_at) <= new Date(n)) throw Error("invite_expired");
|
|
4409
|
-
if (
|
|
4410
|
-
let
|
|
4411
|
-
if (
|
|
4410
|
+
if (c(t.publicKey) !== t.fingerprint) throw Error("fingerprint_mismatch");
|
|
4411
|
+
let u = Ce(s);
|
|
4412
|
+
if (u !== t.identityId) throw Error("invite_identity_conflict");
|
|
4412
4413
|
Ic(o, t, { requireBinding: !1 }), Fc(await Q(this.db.prepare(`SELECT ${bc}
|
|
4413
4414
|
FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(o.group_id, t.deviceId)), t);
|
|
4414
|
-
let { eligibilitySql:
|
|
4415
|
-
await
|
|
4416
|
-
let
|
|
4415
|
+
let { eligibilitySql: d, eligibilityValues: f, boundEligibilitySql: p, boundEligibilityValues: m, assertEligible: h } = await Bc(this.db, o, t);
|
|
4416
|
+
await h({ requireBinding: !!o.consumed_at });
|
|
4417
|
+
let g = await this.prepareEligibleRecipientOwner(t), _ = g.retainedRecheck, ee = 0, te = X(12);
|
|
4417
4418
|
if (!o.consumed_at) {
|
|
4418
4419
|
if (!this.db.batch) throw Error("D1 batch support is required for atomic invite consume.");
|
|
4419
4420
|
ee = await Vc(this.db, [
|
|
@@ -4434,7 +4435,7 @@ var el = class {
|
|
|
4434
4435
|
)
|
|
4435
4436
|
AND EXISTS (SELECT 1 FROM groups g WHERE g.group_id = coordinator_invites.group_id
|
|
4436
4437
|
AND g.archived_at IS NULL)
|
|
4437
|
-
AND ${
|
|
4438
|
+
AND ${d}`, g).bind(`consumed:${o.invite_id}`, n, t.deviceId, t.publicKey, t.fingerprint, u, r, i, a, t.token, o.invite_id, o.group_id, n, t.inviteKind, o.reviewed_intent_json, o.reviewed_preview_digest, u, u, t.deviceId, t.publicKey, t.fingerprint, u, ...f),
|
|
4438
4439
|
Hc(this.db, `INSERT INTO enrolled_devices(
|
|
4439
4440
|
group_id, device_id, public_key, fingerprint, identity_id, display_name, enabled, created_at
|
|
4440
4441
|
) SELECT i.group_id, i.bound_device_id, i.bound_public_key, i.bound_fingerprint,
|
|
@@ -4444,13 +4445,13 @@ var el = class {
|
|
|
4444
4445
|
AND i.invite_id = ? AND i.group_id = ? AND changes() = 1
|
|
4445
4446
|
AND i.bound_public_key = ? AND i.bound_fingerprint = ?
|
|
4446
4447
|
AND i.recipient_actor_id = ?
|
|
4447
|
-
AND ${
|
|
4448
|
+
AND ${p}
|
|
4448
4449
|
ON CONFLICT(group_id, device_id) DO UPDATE SET
|
|
4449
4450
|
identity_id = COALESCE(enrolled_devices.identity_id, excluded.identity_id),
|
|
4450
4451
|
display_name = COALESCE(enrolled_devices.display_name, excluded.display_name),
|
|
4451
4452
|
enabled = 1
|
|
4452
4453
|
WHERE enrolled_devices.identity_id IS NULL
|
|
4453
|
-
OR enrolled_devices.identity_id = excluded.identity_id`,
|
|
4454
|
+
OR enrolled_devices.identity_id = excluded.identity_id`, _).bind(n, a, t.token, t.deviceId, o.invite_id, o.group_id, t.publicKey, t.fingerprint, u, ...m),
|
|
4454
4455
|
Hc(this.db, `UPDATE coordinator_invites SET bootstrap_grant_id = ?,
|
|
4455
4456
|
trust_state = 'bootstrap_grant_created'
|
|
4456
4457
|
WHERE (token_digest = ? OR token = ?) AND invite_kind = 'add_device'
|
|
@@ -4460,7 +4461,7 @@ var el = class {
|
|
|
4460
4461
|
AND EXISTS (SELECT 1 FROM enrolled_devices e
|
|
4461
4462
|
WHERE e.group_id = coordinator_invites.group_id
|
|
4462
4463
|
AND e.device_id = coordinator_invites.inviter_device_id AND e.enabled = 1)
|
|
4463
|
-
AND changes() = 1 AND ${
|
|
4464
|
+
AND changes() = 1 AND ${p}`, _).bind(te, a, t.token, o.invite_id, o.group_id, n, ...m),
|
|
4464
4465
|
Hc(this.db, `INSERT OR IGNORE INTO coordinator_bootstrap_grants(
|
|
4465
4466
|
grant_id, group_id, seed_device_id, worker_device_id, expires_at,
|
|
4466
4467
|
created_at, created_by, revoked_at
|
|
@@ -4471,69 +4472,69 @@ var el = class {
|
|
|
4471
4472
|
WHERE (i.token_digest = ? OR i.token = ?) AND i.invite_kind = 'add_device'
|
|
4472
4473
|
AND i.invite_id = ? AND i.group_id = ?
|
|
4473
4474
|
AND i.bootstrap_grant_id IS NOT NULL AND i.bound_device_id = ?
|
|
4474
|
-
AND changes() = 1 AND ${
|
|
4475
|
+
AND changes() = 1 AND ${p}`, _).bind(n, a, t.token, o.invite_id, o.group_id, t.deviceId, ...m)
|
|
4475
4476
|
], {
|
|
4476
|
-
sql:
|
|
4477
|
-
values:
|
|
4478
|
-
assertEligible:
|
|
4479
|
-
negative:
|
|
4477
|
+
sql: d,
|
|
4478
|
+
values: f,
|
|
4479
|
+
assertEligible: h,
|
|
4480
|
+
negative: _
|
|
4480
4481
|
});
|
|
4481
4482
|
}
|
|
4482
|
-
await
|
|
4483
|
+
await h({ requireBinding: !1 });
|
|
4483
4484
|
let ne = await this.getGroup(o.group_id);
|
|
4484
4485
|
if (!ne) throw Error("group_not_found");
|
|
4485
4486
|
if (ne.archived_at) throw Error("group_archived");
|
|
4486
4487
|
Fc(await Q(this.db.prepare(`SELECT ${bc}
|
|
4487
4488
|
FROM enrolled_devices WHERE group_id = ? AND device_id = ?`).bind(o.group_id, t.deviceId)), t);
|
|
4488
|
-
let
|
|
4489
|
-
if (!
|
|
4490
|
-
let
|
|
4491
|
-
if (!
|
|
4492
|
-
if (
|
|
4493
|
-
let
|
|
4494
|
-
sql:
|
|
4495
|
-
values:
|
|
4496
|
-
assertEligible:
|
|
4497
|
-
negative:
|
|
4489
|
+
let v = await this.getInviteByTokenForInspection(t.token);
|
|
4490
|
+
if (!v || v.revoked_at || !v.consumed_at && new Date(v.expires_at) <= new Date(n)) throw Error("invite_invalid");
|
|
4491
|
+
let re = await Bt(v);
|
|
4492
|
+
if (!re || re.kind !== t.inviteKind) throw Error("invite_invalid");
|
|
4493
|
+
if (Ce(re) !== u) throw Error("invite_identity_conflict");
|
|
4494
|
+
let ie = await Wc(this.db, t, v, {
|
|
4495
|
+
sql: p,
|
|
4496
|
+
values: m,
|
|
4497
|
+
assertEligible: h,
|
|
4498
|
+
negative: _
|
|
4498
4499
|
}, {
|
|
4499
4500
|
winningChanges: ee,
|
|
4500
|
-
consistency:
|
|
4501
|
+
consistency: g
|
|
4501
4502
|
});
|
|
4502
|
-
await
|
|
4503
|
-
let y =
|
|
4504
|
-
if (
|
|
4505
|
-
await this.recoverRecipientInviteGrant(
|
|
4506
|
-
sql:
|
|
4507
|
-
values:
|
|
4503
|
+
await h({ requireBinding: !0 }), Lc(await this.getEnrollment(v.group_id, t.deviceId), t);
|
|
4504
|
+
let y = v;
|
|
4505
|
+
if (re.kind === "add_device" && v.inviter_device_id && !v.bootstrap_grant_id && new Date(v.expires_at) > new Date(n)) {
|
|
4506
|
+
await this.recoverRecipientInviteGrant(v, t, {
|
|
4507
|
+
sql: p,
|
|
4508
|
+
values: m,
|
|
4508
4509
|
consumedAt: n,
|
|
4509
|
-
assertEligible:
|
|
4510
|
-
negative:
|
|
4510
|
+
assertEligible: h,
|
|
4511
|
+
negative: ie
|
|
4511
4512
|
});
|
|
4512
4513
|
let e = await this.getInviteByTokenForInspection(t.token);
|
|
4513
4514
|
if (!e) throw Error("invite_invalid");
|
|
4514
4515
|
y = e;
|
|
4515
4516
|
}
|
|
4516
|
-
let
|
|
4517
|
-
return await
|
|
4517
|
+
let ae = y.bootstrap_grant_id ? await this.getBootstrapGrant(y.bootstrap_grant_id) : null;
|
|
4518
|
+
return await h({ requireBinding: !0 }), {
|
|
4518
4519
|
status: ee === 1 ? "accepted" : "existing",
|
|
4519
4520
|
invite: y,
|
|
4520
|
-
reviewed_intent:
|
|
4521
|
-
bootstrap_grant:
|
|
4521
|
+
reviewed_intent: re.reviewed_intent,
|
|
4522
|
+
bootstrap_grant: ae
|
|
4522
4523
|
};
|
|
4523
4524
|
}
|
|
4524
4525
|
async consumeProjectInvite(e) {
|
|
4525
|
-
let t =
|
|
4526
|
+
let t = Nn(e);
|
|
4526
4527
|
if (!this.db.batch) throw Error("D1 batch support is required for atomic invite consume.");
|
|
4527
|
-
let n =
|
|
4528
|
+
let n = Ht(t.now), r = await vc(t.token), i = await this.getInviteByTokenForInspection(t.token), a = i ? { ...i } : null;
|
|
4528
4529
|
if (!a?.operation_id || !a.project_intent_json || a.revoked_at) throw Error("invite_invalid");
|
|
4529
4530
|
let o = await this.getGroup(a.group_id);
|
|
4530
4531
|
if (!o) throw Error("group_not_found");
|
|
4531
4532
|
if (o.archived_at) throw Error("group_archived");
|
|
4532
4533
|
if (a.operation_id !== t.operationId) throw Error("invite_invalid");
|
|
4533
|
-
if (
|
|
4534
|
+
if (c(t.publicKey) !== t.fingerprint) throw Error("fingerprint_mismatch");
|
|
4534
4535
|
if (!a.consumed_at && new Date(a.expires_at) <= new Date(n)) throw Error("invite_expired");
|
|
4535
4536
|
a.consumed_at && Yc(a, t);
|
|
4536
|
-
let s = await qc(this.db, a, t),
|
|
4537
|
+
let s = await qc(this.db, a, t), l = X(12), u = Qc(a, t), d = [
|
|
4537
4538
|
this.db.prepare(`UPDATE coordinator_invites SET token = ?, consumed_at = ?, bound_device_id = ?,
|
|
4538
4539
|
bound_public_key = ?, bound_fingerprint = ?, recipient_actor_id = ?,
|
|
4539
4540
|
recipient_display_name = ?, recipient_device_display_name = ?,
|
|
@@ -4565,7 +4566,7 @@ var el = class {
|
|
|
4565
4566
|
AND expires_at > ?
|
|
4566
4567
|
AND EXISTS (SELECT 1 FROM enrolled_devices e WHERE e.group_id = coordinator_invites.group_id
|
|
4567
4568
|
AND e.device_id = coordinator_invites.inviter_device_id AND e.enabled = 1)
|
|
4568
|
-
AND ${s.boundEligibilitySql}`).bind(
|
|
4569
|
+
AND ${s.boundEligibilitySql}`).bind(l, r, t.token, t.deviceId, +!!a.consumed_at, ...u, n, ...s.boundEligibilityValues),
|
|
4569
4570
|
this.db.prepare(`INSERT OR IGNORE INTO coordinator_bootstrap_grants(
|
|
4570
4571
|
grant_id, group_id, seed_device_id, worker_device_id, expires_at, created_at,
|
|
4571
4572
|
created_by, revoked_at
|
|
@@ -4577,24 +4578,24 @@ var el = class {
|
|
|
4577
4578
|
AND ((i.bootstrap_grant_id = ? AND changes() = 1)
|
|
4578
4579
|
OR (i.bootstrap_grant_id = ? AND ? = 1))
|
|
4579
4580
|
AND i.bound_device_id = ? AND e.enabled = 1
|
|
4580
|
-
AND ${s.boundEligibilitySql} AND ${Xc}`).bind(n, r, t.token,
|
|
4581
|
-
],
|
|
4581
|
+
AND ${s.boundEligibilitySql} AND ${Xc}`).bind(n, r, t.token, l, a.bootstrap_grant_id ?? null, +!!a.consumed_at, t.deviceId, ...s.boundEligibilityValues, ...u)
|
|
4582
|
+
], f = await $c(this.db, d, a, t, s, u);
|
|
4582
4583
|
await s.assertEligible({ requireBinding: !1 });
|
|
4583
|
-
let
|
|
4584
|
-
if (!
|
|
4585
|
-
if (
|
|
4586
|
-
let
|
|
4587
|
-
if (!
|
|
4588
|
-
Yc(
|
|
4589
|
-
let
|
|
4590
|
-
if (await s.assertEligible({ requireBinding: !0 }), !
|
|
4591
|
-
if (
|
|
4584
|
+
let p = await this.getGroup(a.group_id);
|
|
4585
|
+
if (!p) throw Error("group_not_found");
|
|
4586
|
+
if (p.archived_at) throw Error("group_archived");
|
|
4587
|
+
let m = await this.getInviteByTokenForInspection(t.token);
|
|
4588
|
+
if (!m) throw Error("invite_invalid");
|
|
4589
|
+
Yc(m, t);
|
|
4590
|
+
let h = await this.getEnrollment(m.group_id, t.deviceId), g = m.inviter_device_id ? await this.getEnrollment(m.group_id, m.inviter_device_id) : null, _ = m.bootstrap_grant_id ? await this.getBootstrapGrant(m.bootstrap_grant_id) : null;
|
|
4591
|
+
if (await s.assertEligible({ requireBinding: !0 }), !h) throw Error("invite_acceptance_incomplete");
|
|
4592
|
+
if (h.identity_id !== t.recipientActorId) throw Error("invite_identity_conflict");
|
|
4592
4593
|
return {
|
|
4593
|
-
status:
|
|
4594
|
-
invite:
|
|
4595
|
-
enrollment:
|
|
4596
|
-
seed_enrollment:
|
|
4597
|
-
bootstrap_grant:
|
|
4594
|
+
status: f ? "accepted" : "existing",
|
|
4595
|
+
invite: m,
|
|
4596
|
+
enrollment: h,
|
|
4597
|
+
seed_enrollment: g,
|
|
4598
|
+
bootstrap_grant: _
|
|
4598
4599
|
};
|
|
4599
4600
|
}
|
|
4600
4601
|
async listInvites(e) {
|
|
@@ -4622,7 +4623,7 @@ var el = class {
|
|
|
4622
4623
|
...J(n),
|
|
4623
4624
|
_no_transition: !0
|
|
4624
4625
|
};
|
|
4625
|
-
let r =
|
|
4626
|
+
let r = vt(e.bootstrapGrant);
|
|
4626
4627
|
if (!e.approved) return this.denyJoinRequest(e);
|
|
4627
4628
|
if (!this.db.batch) throw Error("join_review_unavailable");
|
|
4628
4629
|
let i = Y(), { guard: a, bootstrapGrantInput: o } = await this.prepareJoinApproval(n, r), s = [this.db.prepare(`UPDATE coordinator_join_requests
|
|
@@ -4645,10 +4646,10 @@ var el = class {
|
|
|
4645
4646
|
workerDeviceId: e.device_id
|
|
4646
4647
|
};
|
|
4647
4648
|
}
|
|
4648
|
-
let i =
|
|
4649
|
-
recipient: await
|
|
4650
|
-
seed: r ? await
|
|
4651
|
-
current: i === null ? null : await
|
|
4649
|
+
let i = dt(await Q(this.db.prepare("SELECT public_key FROM enrolled_devices WHERE group_id = ? AND device_id = ?").bind(e.group_id, e.device_id))), a = Xt(e, r, {
|
|
4650
|
+
recipient: await o(e.public_key),
|
|
4651
|
+
seed: r ? await o(r.public_key) : null,
|
|
4652
|
+
current: i === null ? null : await o(i)
|
|
4652
4653
|
}, i);
|
|
4653
4654
|
return await this.assertJoinOwnershipAvailable(a), {
|
|
4654
4655
|
guard: a,
|
|
@@ -4676,19 +4677,19 @@ var el = class {
|
|
|
4676
4677
|
throw e?.status === "pending" && await this.assertJoinOwnershipAvailable(t.guard), Error("join_review_incomplete");
|
|
4677
4678
|
}
|
|
4678
4679
|
if (n.length !== e.length) throw Error("join_review_incomplete");
|
|
4679
|
-
|
|
4680
|
-
let r = n.slice(0, -1).map(
|
|
4680
|
+
xt(n.at(-1));
|
|
4681
|
+
let r = n.slice(0, -1).map(An), i = r[0];
|
|
4681
4682
|
if (i !== 0 && i !== 1 || r.some((e) => e !== i)) throw Error("join_review_incomplete");
|
|
4682
4683
|
return i === 1;
|
|
4683
4684
|
}
|
|
4684
4685
|
async denyJoinRequest(e) {
|
|
4685
|
-
let t = this.db.prepare("UPDATE coordinator_join_requests SET status = 'denied', reviewed_at = ?, reviewed_by = ?\n WHERE request_id = ? AND status = 'pending'").bind(Y(), e.reviewedBy ?? null, e.requestId), n = this.db.batch ?
|
|
4686
|
+
let t = this.db.prepare("UPDATE coordinator_join_requests SET status = 'denied', reviewed_at = ?, reviewed_by = ?\n WHERE request_id = ? AND status = 'pending'").bind(Y(), e.reviewedBy ?? null, e.requestId), n = this.db.batch ? An((await this.db.batch([t]))[0]) : await $(t);
|
|
4686
4687
|
if (n === 0) return this.classifyJoinReviewFailure(e.requestId, null);
|
|
4687
4688
|
if (n !== 1) throw Error("join_review_incomplete");
|
|
4688
4689
|
return this.readCompletedJoinReview(e.requestId, null);
|
|
4689
4690
|
}
|
|
4690
4691
|
async readCompletedJoinReview(e, t) {
|
|
4691
|
-
let n = await Q(this.db.prepare(`SELECT ${
|
|
4692
|
+
let n = await Q(this.db.prepare(`SELECT ${xn} FROM coordinator_join_requests WHERE request_id = ?`).bind(e));
|
|
4692
4693
|
if (!n) throw Error("join_review_incomplete");
|
|
4693
4694
|
let r = t ? await this.getBootstrapGrant(t) : null;
|
|
4694
4695
|
if (t && !r) throw Error("join_review_incomplete");
|
|
@@ -4735,7 +4736,7 @@ var el = class {
|
|
|
4735
4736
|
WHEN ${c} THEN 1 ELSE json('join_review_incomplete') END AS confirmed`).bind(e.request_id, t, n, ...r.eligibilityValues, ...a, s, s, e.group_id, o?.seedDeviceId ?? null, e.device_id, o?.expiresAt ?? null);
|
|
4736
4737
|
}
|
|
4737
4738
|
async classifyJoinReviewFailure(e, t) {
|
|
4738
|
-
let n = await Q(this.db.prepare(`SELECT ${
|
|
4739
|
+
let n = await Q(this.db.prepare(`SELECT ${xn} FROM coordinator_join_requests WHERE request_id = ?`).bind(e));
|
|
4739
4740
|
if (!n) return null;
|
|
4740
4741
|
if (n.status !== "pending") return {
|
|
4741
4742
|
...n,
|
|
@@ -4744,61 +4745,61 @@ var el = class {
|
|
|
4744
4745
|
throw t && await this.assertJoinOwnershipAvailable(t), Error("join_review_incomplete");
|
|
4745
4746
|
}
|
|
4746
4747
|
async createReciprocalApproval(e) {
|
|
4747
|
-
let t = e.groupId.trim(), n = e.requestingDeviceId.trim(),
|
|
4748
|
-
if (!t || !n || !
|
|
4749
|
-
if (n ===
|
|
4750
|
-
if (
|
|
4748
|
+
let t = e.groupId.trim(), n = e.requestingDeviceId.trim(), r = e.requestedDeviceId.trim(), i = e.expectedIncomingRequestId !== void 0, a = e.expectedIncomingRequestId?.trim() ?? "";
|
|
4749
|
+
if (!t || !n || !r) throw Error("groupId, requestingDeviceId, and requestedDeviceId are required.");
|
|
4750
|
+
if (n === r) throw Error("requesting and requested device ids must differ.");
|
|
4751
|
+
if (i) {
|
|
4751
4752
|
let e = Y();
|
|
4752
|
-
if (await $(this.db.prepare("UPDATE coordinator_reciprocal_approvals\n SET status = 'completed', resolved_at = ?\n WHERE request_id = ?\n AND group_id = ?\n AND requesting_device_id = ?\n AND requested_device_id = ?\n AND status = 'pending'").bind(e,
|
|
4753
|
-
return J(await Q(this.db.prepare("SELECT request_id, group_id, requesting_device_id, requested_device_id, status, created_at, resolved_at\n FROM coordinator_reciprocal_approvals WHERE request_id = ?").bind(
|
|
4753
|
+
if (await $(this.db.prepare("UPDATE coordinator_reciprocal_approvals\n SET status = 'completed', resolved_at = ?\n WHERE request_id = ?\n AND group_id = ?\n AND requesting_device_id = ?\n AND requested_device_id = ?\n AND status = 'pending'").bind(e, a, t, r, n)) !== 1) throw new ke();
|
|
4754
|
+
return J(await Q(this.db.prepare("SELECT request_id, group_id, requesting_device_id, requested_device_id, status, created_at, resolved_at\n FROM coordinator_reciprocal_approvals WHERE request_id = ?").bind(a)));
|
|
4754
4755
|
}
|
|
4755
|
-
let
|
|
4756
|
-
if (
|
|
4757
|
-
let
|
|
4758
|
-
if (
|
|
4756
|
+
let o = gc(n, r), s = await Q(this.db.prepare("SELECT request_id, group_id, requesting_device_id, requested_device_id, status, created_at, resolved_at\n FROM coordinator_reciprocal_approvals\n WHERE group_id = ? AND requesting_device_id = ? AND requested_device_id = ? AND status = 'pending'\n ORDER BY created_at DESC LIMIT 1").bind(t, n, r));
|
|
4757
|
+
if (s) return J(s);
|
|
4758
|
+
let c = await Q(this.db.prepare("SELECT request_id, group_id, requesting_device_id, requested_device_id, status, created_at, resolved_at\n FROM coordinator_reciprocal_approvals\n WHERE group_id = ? AND requesting_device_id = ? AND requested_device_id = ? AND status = 'pending'\n ORDER BY created_at DESC LIMIT 1").bind(t, r, n));
|
|
4759
|
+
if (c) {
|
|
4759
4760
|
let e = Y();
|
|
4760
|
-
return await this.db.prepare("UPDATE coordinator_reciprocal_approvals SET status = 'completed', resolved_at = ? WHERE request_id = ?").bind(e,
|
|
4761
|
+
return await this.db.prepare("UPDATE coordinator_reciprocal_approvals SET status = 'completed', resolved_at = ? WHERE request_id = ?").bind(e, c.request_id).run(), J(await Q(this.db.prepare("SELECT request_id, group_id, requesting_device_id, requested_device_id, status, created_at, resolved_at\n FROM coordinator_reciprocal_approvals WHERE request_id = ?").bind(c.request_id)));
|
|
4761
4762
|
}
|
|
4762
|
-
let
|
|
4763
|
+
let l = X(12), u = Y();
|
|
4763
4764
|
try {
|
|
4764
|
-
await this.db.prepare("INSERT INTO coordinator_reciprocal_approvals(\n request_id,\n group_id,\n requesting_device_id,\n requested_device_id,\n pending_pair_low_device_id,\n pending_pair_high_device_id,\n status,\n created_at,\n resolved_at\n ) VALUES (?, ?, ?, ?, ?, ?, 'pending', ?, NULL)").bind(
|
|
4765
|
+
await this.db.prepare("INSERT INTO coordinator_reciprocal_approvals(\n request_id,\n group_id,\n requesting_device_id,\n requested_device_id,\n pending_pair_low_device_id,\n pending_pair_high_device_id,\n status,\n created_at,\n resolved_at\n ) VALUES (?, ?, ?, ?, ?, ?, 'pending', ?, NULL)").bind(l, t, n, r, o.low, o.high, u).run();
|
|
4765
4766
|
} catch (e) {
|
|
4766
4767
|
if (!_c(e)) throw e;
|
|
4767
|
-
let
|
|
4768
|
-
if (
|
|
4769
|
-
let a = await Q(this.db.prepare("SELECT request_id, group_id, requesting_device_id, requested_device_id, status, created_at, resolved_at\n FROM coordinator_reciprocal_approvals\n WHERE group_id = ? AND requesting_device_id = ? AND requested_device_id = ? AND status = 'pending'\n ORDER BY created_at DESC LIMIT 1").bind(t,
|
|
4768
|
+
let i = await Q(this.db.prepare("SELECT request_id, group_id, requesting_device_id, requested_device_id, status, created_at, resolved_at\n FROM coordinator_reciprocal_approvals\n WHERE group_id = ? AND requesting_device_id = ? AND requested_device_id = ? AND status = 'pending'\n ORDER BY created_at DESC LIMIT 1").bind(t, n, r));
|
|
4769
|
+
if (i) return J(i);
|
|
4770
|
+
let a = await Q(this.db.prepare("SELECT request_id, group_id, requesting_device_id, requested_device_id, status, created_at, resolved_at\n FROM coordinator_reciprocal_approvals\n WHERE group_id = ? AND requesting_device_id = ? AND requested_device_id = ? AND status = 'pending'\n ORDER BY created_at DESC LIMIT 1").bind(t, r, n));
|
|
4770
4771
|
if (a) {
|
|
4771
4772
|
let e = Y();
|
|
4772
4773
|
return await this.db.prepare("UPDATE coordinator_reciprocal_approvals SET status = 'completed', resolved_at = ? WHERE request_id = ?").bind(e, a.request_id).run(), J(await Q(this.db.prepare("SELECT request_id, group_id, requesting_device_id, requested_device_id, status, created_at, resolved_at\n FROM coordinator_reciprocal_approvals WHERE request_id = ?").bind(a.request_id)));
|
|
4773
4774
|
}
|
|
4774
4775
|
throw e;
|
|
4775
4776
|
}
|
|
4776
|
-
return J(await Q(this.db.prepare("SELECT request_id, group_id, requesting_device_id, requested_device_id, status, created_at, resolved_at\n FROM coordinator_reciprocal_approvals WHERE request_id = ?").bind(
|
|
4777
|
+
return J(await Q(this.db.prepare("SELECT request_id, group_id, requesting_device_id, requested_device_id, status, created_at, resolved_at\n FROM coordinator_reciprocal_approvals WHERE request_id = ?").bind(l)));
|
|
4777
4778
|
}
|
|
4778
4779
|
async getBootstrapParticipantSource(e, t) {
|
|
4779
|
-
let
|
|
4780
|
-
return n
|
|
4780
|
+
let n = await Q(this.db.prepare(Wn).bind(e, t));
|
|
4781
|
+
return me(n);
|
|
4781
4782
|
}
|
|
4782
4783
|
async createBootstrapGrant(e) {
|
|
4783
|
-
let t =
|
|
4784
|
+
let t = vn(e);
|
|
4784
4785
|
try {
|
|
4785
|
-
let e = () => this.db.prepare(
|
|
4786
|
+
let e = () => this.db.prepare(Re);
|
|
4786
4787
|
if (await Q(e().bind(t.seedDeviceId, null, t.workerDeviceId, null))) throw Error("device_revoked");
|
|
4787
4788
|
let n = await this.getBootstrapParticipantSource(t.groupId, t.seedDeviceId), r = await this.getBootstrapParticipantSource(t.groupId, t.workerDeviceId), i = [
|
|
4788
4789
|
t.seedDeviceId,
|
|
4789
|
-
n ? await
|
|
4790
|
+
n ? await o(n.public_key) : null,
|
|
4790
4791
|
t.workerDeviceId,
|
|
4791
|
-
r ? await
|
|
4792
|
+
r ? await o(r.public_key) : null
|
|
4792
4793
|
];
|
|
4793
4794
|
if (await Q(e().bind(...i))) throw Error("device_revoked");
|
|
4794
|
-
let a =
|
|
4795
|
+
let a = Ze(t, {
|
|
4795
4796
|
grantId: X(12),
|
|
4796
4797
|
createdAt: Y()
|
|
4797
4798
|
}, {
|
|
4798
4799
|
seed: n,
|
|
4799
4800
|
worker: r
|
|
4800
|
-
}, i),
|
|
4801
|
-
if (
|
|
4801
|
+
}, i), s = await Q(this.db.prepare(ee).bind(...a));
|
|
4802
|
+
if (s) return J(s);
|
|
4802
4803
|
throw await Q(e().bind(...i)) ? Error("device_revoked") : Error("bootstrap_grant_write_incomplete");
|
|
4803
4804
|
} catch (e) {
|
|
4804
4805
|
throw e instanceof Error && e.message === "device_revoked" ? e : Error("bootstrap_grant_write_incomplete");
|
|
@@ -4813,7 +4814,7 @@ var el = class {
|
|
|
4813
4814
|
return n ? J(n) : null;
|
|
4814
4815
|
}
|
|
4815
4816
|
async createScope(e) {
|
|
4816
|
-
let t =
|
|
4817
|
+
let t = Jt(e);
|
|
4817
4818
|
if (await this.getScope(t.scopeId)) throw Error("scopeId already exists.");
|
|
4818
4819
|
let n = Y();
|
|
4819
4820
|
await this.db.prepare("INSERT INTO coordinator_scopes(\n scope_id, label, kind, authority_type, coordinator_id, group_id,\n manifest_issuer_device_id, membership_epoch, manifest_hash, status, created_at, updated_at\n ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)").bind(t.scopeId, t.label, t.kind, t.authorityType, t.coordinatorId, t.groupId, t.manifestIssuerDeviceId, t.membershipEpoch, t.manifestHash, t.status, n, n).run();
|
|
@@ -4822,13 +4823,13 @@ var el = class {
|
|
|
4822
4823
|
return r;
|
|
4823
4824
|
}
|
|
4824
4825
|
async updateScope(e) {
|
|
4825
|
-
let t =
|
|
4826
|
+
let t = T(e.scopeId), n = t ? await this.getScope(t) : null;
|
|
4826
4827
|
if (!n) return null;
|
|
4827
|
-
let r =
|
|
4828
|
+
let r = At(e, n);
|
|
4828
4829
|
return await this.db.prepare("UPDATE coordinator_scopes\n SET label = ?,\n kind = ?,\n authority_type = ?,\n coordinator_id = ?,\n group_id = ?,\n manifest_issuer_device_id = ?,\n membership_epoch = ?,\n manifest_hash = ?,\n status = ?,\n updated_at = ?\n WHERE scope_id = ?").bind(r.label, r.kind, r.authorityType, r.coordinatorId, r.groupId, r.manifestIssuerDeviceId, r.membershipEpoch, r.manifestHash, r.status, Y(), r.scopeId).run(), await this.getScope(r.scopeId);
|
|
4829
4830
|
}
|
|
4830
4831
|
async listScopes(e = {}) {
|
|
4831
|
-
let t = [], n = [], r =
|
|
4832
|
+
let t = [], n = [], r = T(e.coordinatorId), i = T(e.groupId), a = T(e.status);
|
|
4832
4833
|
r && (t.push("coordinator_id = ?"), n.push(r)), i && (t.push("group_id = ?"), n.push(i)), a ? (t.push("status = ?"), n.push(a)) : e.includeInactive || t.push("status = 'active'");
|
|
4833
4834
|
let o = t.length ? `WHERE ${t.join(" AND ")}` : "", s = this.db.prepare(`SELECT scope_id, label, kind, authority_type, coordinator_id, group_id,
|
|
4834
4835
|
manifest_issuer_device_id, membership_epoch, manifest_hash, status, created_at, updated_at
|
|
@@ -4838,36 +4839,36 @@ var el = class {
|
|
|
4838
4839
|
}
|
|
4839
4840
|
async getScopeAuthorization(e) {
|
|
4840
4841
|
try {
|
|
4841
|
-
let
|
|
4842
|
-
if (
|
|
4842
|
+
let i = t(e), a = await this.db.prepare(`SELECT ${l.join(", ")} FROM coordinator_scopes WHERE scope_id = ?`).bind(i.scopeId).first();
|
|
4843
|
+
if (a === null) return {
|
|
4843
4844
|
kind: "rejected",
|
|
4844
4845
|
error: "scope_not_found"
|
|
4845
4846
|
};
|
|
4846
|
-
|
|
4847
|
-
let
|
|
4848
|
-
if (
|
|
4849
|
-
let
|
|
4850
|
-
if (
|
|
4847
|
+
n(a, l);
|
|
4848
|
+
let o = { ...a };
|
|
4849
|
+
if (o.scope_id !== i.scopeId) throw Error("scope_authorization_unavailable");
|
|
4850
|
+
let c = r(o, i.groupId);
|
|
4851
|
+
if (c) return {
|
|
4851
4852
|
kind: "rejected",
|
|
4852
|
-
error:
|
|
4853
|
+
error: c
|
|
4853
4854
|
};
|
|
4854
|
-
let
|
|
4855
|
-
if (
|
|
4855
|
+
let d = await this.db.prepare("SELECT group_id, archived_at FROM groups WHERE group_id = ?").bind(i.groupId).first();
|
|
4856
|
+
if (d === null) return {
|
|
4856
4857
|
kind: "rejected",
|
|
4857
4858
|
error: "scope_source_mismatch"
|
|
4858
4859
|
};
|
|
4859
|
-
if (
|
|
4860
|
-
if (
|
|
4860
|
+
if (n(d, ["group_id"]), d.group_id !== i.groupId) throw Error("scope_authorization_unavailable");
|
|
4861
|
+
if (d.archived_at !== null) return n(d, ["archived_at"]), {
|
|
4861
4862
|
kind: "rejected",
|
|
4862
4863
|
error: "group_archived"
|
|
4863
4864
|
};
|
|
4864
|
-
let
|
|
4865
|
-
if (
|
|
4865
|
+
let f = await this.captureScopeAuthorizationMembers(o, i.groupId), p = await this.db.prepare(s).bind(JSON.stringify([o]), JSON.stringify(f)).first();
|
|
4866
|
+
if (n(p, l), !p || l.some((e) => p[e] !== o[e])) throw Error("scope_authorization_unavailable");
|
|
4866
4867
|
return {
|
|
4867
4868
|
kind: "authorized",
|
|
4868
4869
|
authorizationVersion: 1,
|
|
4869
|
-
scope:
|
|
4870
|
-
members:
|
|
4870
|
+
scope: o,
|
|
4871
|
+
members: u(p.members_json, f)
|
|
4871
4872
|
};
|
|
4872
4873
|
} catch {
|
|
4873
4874
|
return {
|
|
@@ -4876,42 +4877,42 @@ var el = class {
|
|
|
4876
4877
|
};
|
|
4877
4878
|
}
|
|
4878
4879
|
}
|
|
4879
|
-
async captureScopeAuthorizationMembers(
|
|
4880
|
-
let
|
|
4881
|
-
for (let e of
|
|
4882
|
-
let t =
|
|
4883
|
-
t?.enabled === 1 &&
|
|
4880
|
+
async captureScopeAuthorizationMembers(t, r) {
|
|
4881
|
+
let i = Ac(await this.db.prepare(`SELECT ${e.join(", ")} FROM coordinator_scope_memberships WHERE scope_id = ? ORDER BY device_id ASC`).bind(t.scope_id).all()).flatMap((r) => (n(r, ["status"]), r.status === "active" ? (n(r, e), a(t, r) ? [{ ...r }] : []) : [])), s = await this.captureScopeAuthorizationEnrollments(i, r), c = [];
|
|
4882
|
+
for (let e of i) {
|
|
4883
|
+
let t = s.get(e.device_id);
|
|
4884
|
+
t?.enabled === 1 && c.push({
|
|
4884
4885
|
membership: e,
|
|
4885
4886
|
enrollment: t
|
|
4886
4887
|
});
|
|
4887
4888
|
}
|
|
4888
|
-
let
|
|
4889
|
-
for (let e of
|
|
4890
|
-
let t = await
|
|
4891
|
-
t !== null &&
|
|
4889
|
+
let l = [];
|
|
4890
|
+
for (let e of c) {
|
|
4891
|
+
let t = await o(e.enrollment.public_key);
|
|
4892
|
+
t !== null && l.push({
|
|
4892
4893
|
...e,
|
|
4893
4894
|
keyId: t
|
|
4894
4895
|
});
|
|
4895
4896
|
}
|
|
4896
|
-
return
|
|
4897
|
+
return l;
|
|
4897
4898
|
}
|
|
4898
4899
|
async captureScopeAuthorizationEnrollments(e, t) {
|
|
4899
|
-
let
|
|
4900
|
-
AND device_id IN (SELECT value FROM json_each(?))`).bind(t, JSON.stringify([...
|
|
4901
|
-
for (let e of Ac(
|
|
4902
|
-
if (
|
|
4903
|
-
|
|
4900
|
+
let r = new Set(e.map((e) => e.device_id)), a = await this.db.prepare(`SELECT ${i.join(", ")} FROM enrolled_devices WHERE group_id = ?
|
|
4901
|
+
AND device_id IN (SELECT value FROM json_each(?))`).bind(t, JSON.stringify([...r])).all(), o = /* @__PURE__ */ new Map();
|
|
4902
|
+
for (let e of Ac(a)) {
|
|
4903
|
+
if (n(e, i), e.group_id !== t || !r.delete(e.device_id)) throw Error("scope_authorization_unavailable");
|
|
4904
|
+
o.set(e.device_id, { ...e });
|
|
4904
4905
|
}
|
|
4905
|
-
return
|
|
4906
|
+
return o;
|
|
4906
4907
|
}
|
|
4907
4908
|
async grantScopeMembership(e) {
|
|
4908
|
-
let t =
|
|
4909
|
-
if (r) return
|
|
4910
|
-
let i =
|
|
4911
|
-
if (!o) throw new
|
|
4912
|
-
if (o.status !== "active") throw new
|
|
4913
|
-
let s = i && a ? await this.getScopeMembership(i, a) : null, c =
|
|
4914
|
-
if (c.groupId && !await this.getEnrollment(c.groupId, c.deviceId)) throw new
|
|
4909
|
+
let t = Ne(e.effectId), n = et(e), r = await Cc(this.db, t);
|
|
4910
|
+
if (r) return rt(r, "grant", n), ot(r);
|
|
4911
|
+
let i = T(e.scopeId), a = T(e.deviceId), o = i ? await this.getScope(i) : null;
|
|
4912
|
+
if (!o) throw new dn("scope_not_found");
|
|
4913
|
+
if (o.status !== "active") throw new dn("scope_inactive");
|
|
4914
|
+
let s = i && a ? await this.getScopeMembership(i, a) : null, c = Dn(e, o, s);
|
|
4915
|
+
if (c.groupId && !await this.getEnrollment(c.groupId, c.deviceId)) throw new dn("device_not_enrolled");
|
|
4915
4916
|
let l = Y();
|
|
4916
4917
|
await Ec(this.db, [
|
|
4917
4918
|
this.db.prepare("INSERT INTO coordinator_scope_memberships(\n scope_id, device_id, role, status, membership_epoch, coordinator_id, group_id,\n manifest_issuer_device_id, manifest_hash, signed_manifest_json, updated_at\n ) SELECT ?, ?, ?, 'active', ?, ?, ?, ?, ?, ?, ?\n WHERE NOT EXISTS (\n SELECT 1 FROM coordinator_scope_membership_effect_receipts WHERE effect_id = ?\n )\n ON CONFLICT(scope_id, device_id) DO UPDATE SET\n role = excluded.role,\n status = 'active',\n membership_epoch = excluded.membership_epoch,\n coordinator_id = excluded.coordinator_id,\n group_id = excluded.group_id,\n manifest_issuer_device_id = excluded.manifest_issuer_device_id,\n manifest_hash = excluded.manifest_hash,\n signed_manifest_json = excluded.signed_manifest_json,\n updated_at = excluded.updated_at\n WHERE excluded.membership_epoch > coordinator_scope_memberships.membership_epoch\n OR (\n excluded.membership_epoch = coordinator_scope_memberships.membership_epoch\n AND coordinator_scope_memberships.status != 'revoked'\n )").bind(c.scopeId, c.deviceId, c.role, c.membershipEpoch, c.coordinatorId, c.groupId, c.manifestIssuerDeviceId, c.manifestHash, c.signedManifestJson, l, t),
|
|
@@ -4939,24 +4940,24 @@ var el = class {
|
|
|
4939
4940
|
]);
|
|
4940
4941
|
let u = await Cc(this.db, t);
|
|
4941
4942
|
if (!u) throw Error("scope membership grant was not applied.");
|
|
4942
|
-
return
|
|
4943
|
+
return rt(u, "grant", n), ot(u);
|
|
4943
4944
|
}
|
|
4944
4945
|
async revokeScopeMembership(e) {
|
|
4945
|
-
let t =
|
|
4946
|
+
let t = T(e.scopeId), n = T(e.deviceId);
|
|
4946
4947
|
if (!t || !n) throw Error("scopeId and deviceId are required.");
|
|
4947
|
-
let r =
|
|
4948
|
-
if (a) return
|
|
4949
|
-
let o = e.membershipEpoch == null ? null :
|
|
4950
|
-
if (s && s !== c?.group_id) throw new
|
|
4948
|
+
let r = Ne(e.effectId), i = d(e), a = await Cc(this.db, r);
|
|
4949
|
+
if (a) return rt(a, "revoke", i), a.outcome_applied === 1;
|
|
4950
|
+
let o = e.membershipEpoch == null ? null : sn(e.membershipEpoch), s = T(e.groupId), c = s ? await this.getScope(t) : null;
|
|
4951
|
+
if (s && s !== c?.group_id) throw new dn("scope_group_mismatch");
|
|
4951
4952
|
let l = await this.getScopeMembership(t, n);
|
|
4952
4953
|
if (o != null && l && o <= l.membership_epoch) throw Error("membershipEpoch must increase on revoke.");
|
|
4953
|
-
let u = Y(),
|
|
4954
|
+
let u = Y(), f = o ?? (l?.membership_epoch ?? -1) + 1, p = this.db.prepare("UPDATE coordinator_scope_memberships\n SET status = 'revoked',\n membership_epoch = CASE WHEN ? IS NULL THEN membership_epoch + 1 ELSE ? END,\n manifest_hash = COALESCE(?, manifest_hash),\n signed_manifest_json = COALESCE(?, signed_manifest_json),\n updated_at = ?\n WHERE scope_id = ? AND device_id = ? AND membership_epoch = ? AND status = ?\n AND NOT EXISTS (\n SELECT 1 FROM coordinator_scope_membership_effect_receipts WHERE effect_id = ?\n )").bind(o, o, T(e.manifestHash), T(e.signedManifestJson), u, t, n, l?.membership_epoch ?? -1, l?.status ?? "", r), m = Tc(this.db, {
|
|
4954
4955
|
effectId: r,
|
|
4955
4956
|
requestJson: i,
|
|
4956
4957
|
scopeId: t,
|
|
4957
4958
|
deviceId: n,
|
|
4958
4959
|
createdAt: u
|
|
4959
|
-
}),
|
|
4960
|
+
}), h = Sc(this.db, {
|
|
4960
4961
|
effectId: r,
|
|
4961
4962
|
requestJson: i,
|
|
4962
4963
|
action: "revoke",
|
|
@@ -4964,29 +4965,29 @@ var el = class {
|
|
|
4964
4965
|
scopeId: t,
|
|
4965
4966
|
deviceId: n,
|
|
4966
4967
|
status: "revoked",
|
|
4967
|
-
membershipEpoch:
|
|
4968
|
+
membershipEpoch: f,
|
|
4968
4969
|
updatedAt: u,
|
|
4969
|
-
actorType:
|
|
4970
|
-
actorId:
|
|
4970
|
+
actorType: T(e.actorType),
|
|
4971
|
+
actorId: T(e.actorId),
|
|
4971
4972
|
createdAt: u
|
|
4972
4973
|
});
|
|
4973
4974
|
try {
|
|
4974
4975
|
await Ec(this.db, [
|
|
4975
|
-
f,
|
|
4976
4976
|
p,
|
|
4977
|
-
m
|
|
4977
|
+
m,
|
|
4978
|
+
h
|
|
4978
4979
|
]);
|
|
4979
4980
|
} catch (e) {
|
|
4980
4981
|
let r = await this.getScopeMembership(t, n);
|
|
4981
4982
|
if (l && (!r || r.membership_epoch !== l.membership_epoch || r.status !== l.status)) return !1;
|
|
4982
4983
|
throw e;
|
|
4983
4984
|
}
|
|
4984
|
-
let
|
|
4985
|
-
if (!
|
|
4986
|
-
return
|
|
4985
|
+
let g = await Cc(this.db, r);
|
|
4986
|
+
if (!g) throw Error("scope membership revoke receipt was not persisted.");
|
|
4987
|
+
return rt(g, "revoke", i), g.outcome_applied === 1;
|
|
4987
4988
|
}
|
|
4988
4989
|
async listScopeMemberships(e, t = !1) {
|
|
4989
|
-
let n =
|
|
4990
|
+
let n = T(e);
|
|
4990
4991
|
if (!n) throw Error("scopeId is required.");
|
|
4991
4992
|
let r = t ? "" : "AND status = 'active'";
|
|
4992
4993
|
return (await Z(this.db.prepare(`SELECT scope_id, device_id, role, status, membership_epoch, coordinator_id, group_id,
|
|
@@ -4996,7 +4997,7 @@ var el = class {
|
|
|
4996
4997
|
ORDER BY device_id ASC`).bind(n))).map((e) => J(e));
|
|
4997
4998
|
}
|
|
4998
4999
|
async listDeviceScopeMemberships(e, t = !1) {
|
|
4999
|
-
let n =
|
|
5000
|
+
let n = T(e);
|
|
5000
5001
|
if (!n) throw Error("deviceId is required.");
|
|
5001
5002
|
let r = t ? "" : "AND status = 'active'";
|
|
5002
5003
|
return (await Z(this.db.prepare(`SELECT scope_id, device_id, role, status, membership_epoch, coordinator_id, group_id,
|
|
@@ -5006,9 +5007,9 @@ var el = class {
|
|
|
5006
5007
|
ORDER BY scope_id ASC`).bind(n))).map((e) => J(e));
|
|
5007
5008
|
}
|
|
5008
5009
|
async listScopeMembershipAuditEvents(e) {
|
|
5009
|
-
let t =
|
|
5010
|
+
let t = T(e.scopeId);
|
|
5010
5011
|
if (!t) throw Error("scopeId is required.");
|
|
5011
|
-
let n =
|
|
5012
|
+
let n = T(e.deviceId), r = nn(e.limit), i = n ? "scope_id = ? AND device_id = ?" : "scope_id = ?", a = n ? [
|
|
5012
5013
|
t,
|
|
5013
5014
|
n,
|
|
5014
5015
|
r
|
|
@@ -5027,16 +5028,16 @@ var el = class {
|
|
|
5027
5028
|
}
|
|
5028
5029
|
async getBootstrapGrantAuthorization(e) {
|
|
5029
5030
|
try {
|
|
5030
|
-
let t =
|
|
5031
|
-
if (r) return
|
|
5032
|
-
if (!n) return
|
|
5031
|
+
let t = mn(e), n = await Q(this.db.prepare(Je).bind(t.grantId)), r = be(t, n);
|
|
5032
|
+
if (r) return at(r);
|
|
5033
|
+
if (!n) return at("bootstrap_authorization_unavailable");
|
|
5033
5034
|
let i = { ...n }, a = {
|
|
5034
|
-
seed: i.seed_enrollment_public_key === null ? null : await
|
|
5035
|
-
worker: i.worker_enrollment_public_key === null ? null : await
|
|
5036
|
-
},
|
|
5037
|
-
return
|
|
5035
|
+
seed: i.seed_enrollment_public_key === null ? null : await o(i.seed_enrollment_public_key),
|
|
5036
|
+
worker: i.worker_enrollment_public_key === null ? null : await o(i.worker_enrollment_public_key)
|
|
5037
|
+
}, s = $e(t, i, a), c = await Q(this.db.prepare(s.sql).bind(...s.values));
|
|
5038
|
+
return de(c);
|
|
5038
5039
|
} catch {
|
|
5039
|
-
return
|
|
5040
|
+
return at("bootstrap_authorization_unavailable");
|
|
5040
5041
|
}
|
|
5041
5042
|
}
|
|
5042
5043
|
async listBootstrapGrants(e) {
|
|
@@ -5053,16 +5054,16 @@ var el = class {
|
|
|
5053
5054
|
ORDER BY created_at ASC, request_id ASC`).bind(e.groupId, e.deviceId, n))).map((e) => J(e));
|
|
5054
5055
|
}
|
|
5055
5056
|
async createLegacyTeamCompletion(e, t) {
|
|
5056
|
-
let [n] =
|
|
5057
|
+
let [n] = ae([e]);
|
|
5057
5058
|
if (!n) throw Error("completion_manifest_invalid");
|
|
5058
5059
|
let r = await this.getGroup(n);
|
|
5059
5060
|
if (!r) throw Error("group_not_found");
|
|
5060
5061
|
if (r.archived_at) throw Error("group_archived");
|
|
5061
|
-
let i =
|
|
5062
|
-
|
|
5062
|
+
let i = te(t), a = JSON.parse(i);
|
|
5063
|
+
m(a);
|
|
5063
5064
|
let o = await Q(this.db.prepare("SELECT manifest_json FROM coordinator_legacy_team_completions\n WHERE group_id = ? AND candidate_ref = ?").bind(n, a.candidate_ref));
|
|
5064
|
-
if (o) return
|
|
5065
|
-
let s = await this.requireLegacyTeamCompletionSources(n, a, i), c = await this.prepareLegacyTeamCompletionOwnerProof(n, i), l = await $(this.db.prepare(`${
|
|
5065
|
+
if (o) return ht(o.manifest_json, i, "existing");
|
|
5066
|
+
let s = await this.requireLegacyTeamCompletionSources(n, a, i), c = await this.prepareLegacyTeamCompletionOwnerProof(n, i), l = await $(this.db.prepare(`${tn}${c.ctes}
|
|
5066
5067
|
INSERT OR IGNORE INTO coordinator_legacy_team_completions(
|
|
5067
5068
|
group_id, candidate_ref, manifest_version, manifest_json, completed_at, created_at
|
|
5068
5069
|
) SELECT ?, ?, ?, ?, ?, ?
|
|
@@ -5099,13 +5100,13 @@ var el = class {
|
|
|
5099
5100
|
AND enrolled.fingerprint = json_extract(requested.value, '$.key_fingerprint')
|
|
5100
5101
|
AND enrolled.enabled = 1
|
|
5101
5102
|
)
|
|
5102
|
-
) AND ${
|
|
5103
|
+
) AND ${Vt}
|
|
5103
5104
|
AND (${c.currentSql}) AND (${c.compatibleSql})`).bind(...c.values, n, a.candidate_ref, a.version, i, a.completed_at, Y(), n, i, s, n, n, i, i, n)), u = await Q(this.db.prepare("SELECT manifest_json FROM coordinator_legacy_team_completions\n WHERE group_id = ? AND candidate_ref = ?").bind(n, a.candidate_ref));
|
|
5104
|
-
if (!u) throw await this.requireLegacyTeamCompletionSources(n, a, i), (await Q(this.db.prepare(c.denialSql).bind(...c.values)))?.denial === "completion_conflict" ? new
|
|
5105
|
-
return
|
|
5105
|
+
if (!u) throw await this.requireLegacyTeamCompletionSources(n, a, i), (await Q(this.db.prepare(c.denialSql).bind(...c.values)))?.denial === "completion_conflict" ? new ze() : Error("completion_manifest_unavailable");
|
|
5106
|
+
return ht(u.manifest_json, i, l === 1 ? "created" : "existing");
|
|
5106
5107
|
}
|
|
5107
5108
|
async prepareLegacyTeamCompletionOwnerProof(e, t) {
|
|
5108
|
-
let n = await
|
|
5109
|
+
let n = await on(await Z(this.db.prepare(_n).bind(t, e))), r = En(await kt({
|
|
5109
5110
|
backend: {
|
|
5110
5111
|
first: ({ sql: e, values: t }) => Q(this.db.prepare(e).bind(...t)),
|
|
5111
5112
|
all: ({ sql: e, values: t }) => Z(this.db.prepare(e).bind(...t))
|
|
@@ -5122,8 +5123,8 @@ var el = class {
|
|
|
5122
5123
|
n,
|
|
5123
5124
|
...r.values
|
|
5124
5125
|
],
|
|
5125
|
-
denialSql: `${
|
|
5126
|
-
SELECT CASE WHEN NOT (${
|
|
5126
|
+
denialSql: `${tn}${r.ctes}
|
|
5127
|
+
SELECT CASE WHEN NOT (${Vt}) OR NOT (${r.currentSql})
|
|
5127
5128
|
THEN 'completion_manifest_unavailable'
|
|
5128
5129
|
WHEN NOT (${r.compatibleSql}) THEN 'completion_conflict'
|
|
5129
5130
|
ELSE 'completion_manifest_unavailable' END AS denial`
|
|
@@ -5134,16 +5135,16 @@ var el = class {
|
|
|
5134
5135
|
if (!r) throw Error("group_not_found");
|
|
5135
5136
|
if (r.archived_at) throw Error("group_archived");
|
|
5136
5137
|
let i = await Z(this.db.prepare("SELECT DISTINCT requested.scope_id, scope.authority_type,\n scope.coordinator_id, scope.group_id, scope.status\n FROM (SELECT json_extract(value, '$.scope_id') AS scope_id\n FROM json_each(?, '$.project_mappings')) AS requested\n LEFT JOIN coordinator_scopes AS scope ON scope.scope_id = requested.scope_id").bind(n));
|
|
5137
|
-
return
|
|
5138
|
+
return Gt(t, e, i);
|
|
5138
5139
|
}
|
|
5139
5140
|
async getLegacyTeamCompletion(e, t) {
|
|
5140
|
-
let [n] =
|
|
5141
|
+
let [n] = ae([e]), r = He(t);
|
|
5141
5142
|
if (!n) throw Error("completion_manifest_invalid");
|
|
5142
5143
|
let i = await Q(this.db.prepare("SELECT manifest_json FROM coordinator_legacy_team_completions\n WHERE group_id = ? AND candidate_ref = ?").bind(n, r));
|
|
5143
|
-
return i ?
|
|
5144
|
+
return i ? ie(JSON.parse(i.manifest_json)) : null;
|
|
5144
5145
|
}
|
|
5145
5146
|
async listLegacyTeamCompletions(e) {
|
|
5146
|
-
let t =
|
|
5147
|
+
let t = ae(e);
|
|
5147
5148
|
if (t.length === 0) return [];
|
|
5148
5149
|
let n = t.map(() => "?").join(", "), r = await Q(this.db.prepare(`SELECT
|
|
5149
5150
|
COUNT(*) AS record_count,
|
|
@@ -5154,7 +5155,7 @@ var el = class {
|
|
|
5154
5155
|
FROM coordinator_legacy_team_completions
|
|
5155
5156
|
WHERE group_id IN (${n})`).bind(...t));
|
|
5156
5157
|
if (!r || r.record_count > 500 || r.batch_bytes > 375e5 || r.max_manifest_bytes > 15e5) throw Error("completion_results_too_large");
|
|
5157
|
-
let
|
|
5158
|
+
let i = await Z(this.db.prepare(`WITH completion_stats AS (
|
|
5158
5159
|
SELECT
|
|
5159
5160
|
COUNT(*) AS record_count,
|
|
5160
5161
|
COALESCE(SUM(
|
|
@@ -5169,23 +5170,23 @@ var el = class {
|
|
|
5169
5170
|
CROSS JOIN completion_stats
|
|
5170
5171
|
WHERE completions.group_id IN (${n})
|
|
5171
5172
|
AND completion_stats.record_count <= 500
|
|
5172
|
-
AND completion_stats.batch_bytes <= ${
|
|
5173
|
-
AND completion_stats.max_manifest_bytes <= ${
|
|
5174
|
-
AND LENGTH(completions.manifest_json) <= ${
|
|
5175
|
-
AND LENGTH(CAST(completions.manifest_json AS BLOB)) <= ${
|
|
5173
|
+
AND completion_stats.batch_bytes <= ${Pt}
|
|
5174
|
+
AND completion_stats.max_manifest_bytes <= ${jn}
|
|
5175
|
+
AND LENGTH(completions.manifest_json) <= ${jn}
|
|
5176
|
+
AND LENGTH(CAST(completions.manifest_json AS BLOB)) <= ${jn}
|
|
5176
5177
|
ORDER BY completions.group_id, completions.completed_at, completions.candidate_ref
|
|
5177
5178
|
LIMIT 501`).bind(...t, ...t));
|
|
5178
|
-
if (
|
|
5179
|
-
return
|
|
5179
|
+
if (i.length === 0 && r.record_count > 0 || i.length > 500 || i.reduce((e, t) => e + new TextEncoder().encode(t.group_id).byteLength + new TextEncoder().encode(t.manifest_json).byteLength, 0) > 375e5) throw Error("completion_results_too_large");
|
|
5180
|
+
return i.map((e) => ({
|
|
5180
5181
|
group_id: e.group_id,
|
|
5181
|
-
manifest:
|
|
5182
|
+
manifest: ie(JSON.parse(e.manifest_json))
|
|
5182
5183
|
}));
|
|
5183
5184
|
}
|
|
5184
5185
|
async captureAuthControllerLegacyHistory(e) {
|
|
5185
|
-
return
|
|
5186
|
+
return Ct(e, (e, t) => Z(this.db.prepare(e).bind(...t)));
|
|
5186
5187
|
}
|
|
5187
5188
|
async upsertPresence(e) {
|
|
5188
|
-
let t = /* @__PURE__ */ new Date(), n = new Date(t.getTime() + e.ttlS * 1e3).toISOString(), r =
|
|
5189
|
+
let t = /* @__PURE__ */ new Date(), n = new Date(t.getTime() + e.ttlS * 1e3).toISOString(), r = ft([], e.addresses);
|
|
5189
5190
|
return await this.db.prepare("INSERT INTO presence_records(group_id, device_id, addresses_json, last_seen_at, expires_at, capabilities_json)\n VALUES (?, ?, ?, ?, ?, ?)\n ON CONFLICT(group_id, device_id) DO UPDATE SET\n addresses_json = excluded.addresses_json,\n last_seen_at = excluded.last_seen_at,\n expires_at = excluded.expires_at,\n capabilities_json = excluded.capabilities_json").bind(e.groupId, e.deviceId, JSON.stringify(r), t.toISOString(), n, JSON.stringify(e.capabilities ?? {})).run(), {
|
|
5190
5191
|
group_id: e.groupId,
|
|
5191
5192
|
device_id: e.deviceId,
|
|
@@ -5200,21 +5201,21 @@ var el = class {
|
|
|
5200
5201
|
throw Error("peer_discovery_unavailable");
|
|
5201
5202
|
}
|
|
5202
5203
|
}
|
|
5203
|
-
async readGroupPeers(
|
|
5204
|
-
let
|
|
5205
|
-
if (!Array.isArray(
|
|
5206
|
-
let
|
|
5204
|
+
async readGroupPeers(e, t) {
|
|
5205
|
+
let n = Y(), r = await this.db.prepare(g).bind(e, t).all();
|
|
5206
|
+
if (!Array.isArray(r?.results) || r.success === !1) throw Error("peer_discovery_unavailable");
|
|
5207
|
+
let i = fe(r.results), a = await Promise.all(i.map(async (e) => ({
|
|
5207
5208
|
...e,
|
|
5208
|
-
keyId: await
|
|
5209
|
-
}))), s = await this.db.prepare(
|
|
5209
|
+
keyId: await o(e.public_key)
|
|
5210
|
+
}))), s = await this.db.prepare(Ye).bind(JSON.stringify(a), e, t).all();
|
|
5210
5211
|
if (s?.success === !1) throw Error("peer_discovery_unavailable");
|
|
5211
|
-
return
|
|
5212
|
-
let t = String(e.expires_at ?? "").trim(),
|
|
5212
|
+
return Ge(s?.results).map((e) => {
|
|
5213
|
+
let t = String(e.expires_at ?? "").trim(), r = !0;
|
|
5213
5214
|
if (t) {
|
|
5214
5215
|
let e = new Date(t);
|
|
5215
|
-
|
|
5216
|
+
r = Number.isNaN(e.getTime()) || e.toISOString() <= n;
|
|
5216
5217
|
}
|
|
5217
|
-
let i =
|
|
5218
|
+
let i = r ? [] : ft([], JSON.parse(String(e.addresses_json ?? "[]")));
|
|
5218
5219
|
return {
|
|
5219
5220
|
device_id: String(e.device_id ?? ""),
|
|
5220
5221
|
public_key: String(e.public_key ?? ""),
|
|
@@ -5223,7 +5224,7 @@ var el = class {
|
|
|
5223
5224
|
addresses: i,
|
|
5224
5225
|
last_seen_at: e.last_seen_at ?? null,
|
|
5225
5226
|
expires_at: e.expires_at ?? null,
|
|
5226
|
-
stale:
|
|
5227
|
+
stale: r,
|
|
5227
5228
|
capabilities: JSON.parse(String(e.capabilities_json ?? "{}"))
|
|
5228
5229
|
};
|
|
5229
5230
|
});
|
|
@@ -5236,7 +5237,7 @@ function tl(e) {
|
|
|
5236
5237
|
adminSecret: () => String(e.adminSecret ?? "").trim() || null,
|
|
5237
5238
|
now: e.now ?? (() => (/* @__PURE__ */ new Date()).toISOString())
|
|
5238
5239
|
};
|
|
5239
|
-
return
|
|
5240
|
+
return qn({
|
|
5240
5241
|
relayHealth: nl(e.relayHealth, t) ?? e.relayHealthInstrumentation,
|
|
5241
5242
|
storeFactory: () => new el(t),
|
|
5242
5243
|
deviceRevocation: e.deviceRevocation,
|
|
@@ -5262,13 +5263,13 @@ function tl(e) {
|
|
|
5262
5263
|
}
|
|
5263
5264
|
function nl(e, t) {
|
|
5264
5265
|
if (!e?.enabled) return;
|
|
5265
|
-
let n = new
|
|
5266
|
+
let n = new Tr({
|
|
5266
5267
|
...e,
|
|
5267
|
-
publish:
|
|
5268
|
+
publish: nr(t, e)
|
|
5268
5269
|
});
|
|
5269
5270
|
return e.onMonitor(n), n;
|
|
5270
5271
|
}
|
|
5271
5272
|
//#endregion
|
|
5272
|
-
export {
|
|
5273
|
+
export { wn as AccountLinkStatusOperations, tt as AuthSessionOperations, Lt as COORDINATOR_LEGACY_TEAM_COMPLETION_CONFLICT, Pt as COORDINATOR_LEGACY_TEAM_COMPLETION_MAX_BATCH_BYTES, lt as COORDINATOR_LEGACY_TEAM_COMPLETION_MAX_BATCH_RESPONSE_BYTES, jn as COORDINATOR_LEGACY_TEAM_COMPLETION_MAX_BYTES, zn as COORDINATOR_LEGACY_TEAM_COMPLETION_MAX_GROUPS, gt as COORDINATOR_LEGACY_TEAM_COMPLETION_MAX_RECORDS, Fn as COORDINATOR_LEGACY_TEAM_COMPLETION_VERSION, ze as CoordinatorLegacyTeamCompletionConflictError, el as D1CoordinatorStore, Sn as DEFAULT_TIME_WINDOW_S, ns as OWNER_BROWSER_ADMISSION_PATH, cc as OWNER_QUALIFICATION_PATH, Er as RelayHealthInstrumentation, Tr as RelayHealthMonitor, bs as admitCoordinatorBrowserAuthSetup, Cr as aggregateRelayHealthAuthority, bn as authSchemaUpgradeResponse, te as canonicalCoordinatorLegacyTeamCompletionManifestJson, A as captureCoordinatorBrowserAuthConfig, vs as captureCoordinatorBrowserAuthOptions, ys as coordinatorBrowserAuthDeviceRoutes, Cs as coordinatorBrowserAuthUnavailableResponse, qn as createCoordinatorApp, Ds as createCoordinatorBrowserAuth, Yo as createCoordinatorOwnerEnrollmentHttp, Oc as createD1AuthLinkBackend, tl as createD1CoordinatorApp, Or as createExclusiveWriterRelayQuota, Zn as createInMemoryRequestRateLimiter, ss as createOwnerBrowserAdmissionHandler, sc as createOwnerQualificationHandler, mc as createOwnerQualificationHttp, nr as d1RelayHealthPublisher, Sr as ensureD1RelayHealthRows, ut as importBrowserCsrfKey, pr as importOwnerEnrollmentAdmissionKey, Dr as initializeRelayQuotaSchema, _r as isOwnerEnrollmentAdmissionKey, rr as issueOwnerEnrollmentAdmission, lr as issueOwnerEnrollmentAdmissionV2, Bs as maintainCoordinatorBrowserAuth, Wo as matchesCoordinatorOwnerEnrollmentHttpPath, He as normalizeCoordinatorLegacyTeamCompletionCandidateRef, ae as normalizeCoordinatorLegacyTeamCompletionGroupIds, ie as normalizeCoordinatorLegacyTeamCompletionManifest, xr as ownerEnrollmentOwnerCommitment, kr as setRelayQuotaEnabled, ir as verifyOwnerEnrollmentAdmission, or as verifyOwnerEnrollmentAdmissionV2 };
|
|
5273
5274
|
|
|
5274
5275
|
//# sourceMappingURL=cloudflare-coordinator.js.map
|