@ndmspc/ndmspc-ui 0.0.1-rc.1 → 1.4.0-rc.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.
@@ -0,0 +1,239 @@
1
+ // node_modules/keycloak-js/lib/keycloak-dpop.js
2
+ var e = {
3
+ ES256: "ES256",
4
+ ES384: "ES384",
5
+ ES512: "ES512",
6
+ EdDSA: "EdDSA"
7
+ }, t = 1, n = "main", r = "dpopState", i = 512, a = /^[\x21-\x7E]+$/;
8
+ function o(e) {
9
+ return typeof e == "string" && e.length > 0 && e.length <= i && a.test(e);
10
+ }
11
+ function s(e) {
12
+ if (typeof e != "string" || e.length === 0) throw Error("DPoP nonce must be a non-empty string");
13
+ if (e.length > i) throw Error(`DPoP nonce exceeds maximum length of ${i} characters`);
14
+ if (!a.test(e)) throw Error("DPoP nonce contains invalid characters");
15
+ }
16
+ async function c(e) {
17
+ let t = new TextEncoder().encode(e), n = await crypto.subtle.digest("SHA-256", t);
18
+ return Array.from(new Uint8Array(n).slice(0, 8)).map((e) => e.toString(16).padStart(2, "0")).join("");
19
+ }
20
+ var l = {
21
+ ES256: {
22
+ name: "ECDSA",
23
+ namedCurve: "P-256"
24
+ },
25
+ ES384: {
26
+ name: "ECDSA",
27
+ namedCurve: "P-384"
28
+ },
29
+ ES512: {
30
+ name: "ECDSA",
31
+ namedCurve: "P-521"
32
+ },
33
+ EdDSA: { name: "Ed25519" }
34
+ }, u = {
35
+ ES256: {
36
+ name: "ECDSA",
37
+ hash: "SHA-256"
38
+ },
39
+ ES384: {
40
+ name: "ECDSA",
41
+ hash: "SHA-384"
42
+ },
43
+ ES512: {
44
+ name: "ECDSA",
45
+ hash: "SHA-512"
46
+ },
47
+ EdDSA: { name: "Ed25519" }
48
+ }, d = [
49
+ e.ES256,
50
+ e.ES384,
51
+ e.ES512
52
+ ];
53
+ async function f(e, t) {
54
+ let [n, r] = await Promise.all([c(e), c(t)]);
55
+ return `dpop:${n}:${r}`;
56
+ }
57
+ var p = class {
58
+ #e = "";
59
+ #t = null;
60
+ #n = !1;
61
+ #r = void 0;
62
+ #i;
63
+ #a;
64
+ #o;
65
+ constructor(e, t, n = !1) {
66
+ this.#i = e, this.#a = t, this.#o = n;
67
+ }
68
+ async init() {
69
+ if (this.#t || this.#n) return this;
70
+ try {
71
+ this.#e = await f(this.#i, this.#a), this.#t = await this.#s();
72
+ } catch (e) {
73
+ if (this.#o) throw Error("DPoP requires IndexedDB for secure key storage, but it is unavailable.", { cause: e });
74
+ console.warn("[KEYCLOAK] IndexedDB unavailable, falling back to in-memory storage:", e), this.#n = !0;
75
+ }
76
+ return this;
77
+ }
78
+ #s() {
79
+ return new Promise((e, r) => {
80
+ if (globalThis.indexedDB === void 0) {
81
+ r(/* @__PURE__ */ Error("IndexedDB is not available"));
82
+ return;
83
+ }
84
+ let i = globalThis.indexedDB.open(this.#e, t);
85
+ i.onerror = () => {
86
+ r(i.error);
87
+ }, i.onsuccess = () => {
88
+ e(i.result);
89
+ }, i.onupgradeneeded = (e) => {
90
+ let t = e.target.result;
91
+ e.oldVersion < 1 && t.createObjectStore(n);
92
+ };
93
+ });
94
+ }
95
+ async get() {
96
+ if (this.#n) return this.#r;
97
+ if (!this.#t) throw Error("DPoPStoreManager not initialized. Call init() first.");
98
+ return new Promise((e, t) => {
99
+ let i = this.#t.transaction(n, "readonly").objectStore(n).get(r);
100
+ i.onerror = () => {
101
+ t(i.error);
102
+ }, i.onsuccess = () => {
103
+ e(i.result);
104
+ };
105
+ });
106
+ }
107
+ async set(e) {
108
+ if (this.#n) this.#r = e;
109
+ else {
110
+ if (!this.#t) throw Error("DPoPStoreManager not initialized. Call init() first.");
111
+ return new Promise((t, i) => {
112
+ let a = this.#t.transaction(n, "readwrite").objectStore(n).put(e, r);
113
+ a.onerror = () => {
114
+ i(a.error);
115
+ }, a.onsuccess = () => {
116
+ t();
117
+ };
118
+ });
119
+ }
120
+ }
121
+ async flush() {
122
+ if (this.#n) this.#r = void 0;
123
+ else {
124
+ if (!this.#t) throw Error("DPoPStoreManager not initialized. Call init() first.");
125
+ return new Promise((e, t) => {
126
+ let i = this.#t.transaction(n, "readwrite").objectStore(n).delete(r);
127
+ i.onerror = () => {
128
+ t(i.error);
129
+ }, i.onsuccess = () => {
130
+ e();
131
+ };
132
+ });
133
+ }
134
+ }
135
+ async updateNonce(e) {
136
+ s(e);
137
+ let t = await this.get();
138
+ t && (t.nonce = e, await this.set(t));
139
+ }
140
+ close() {
141
+ this.#t &&= (this.#t.close(), null);
142
+ }
143
+ }, m = class {
144
+ #e;
145
+ #t;
146
+ #n;
147
+ #r = /* @__PURE__ */ new Map();
148
+ #i;
149
+ constructor(t) {
150
+ let { issuerUrl: n, clientId: r, serverSupportedAlgorithms: i, requestedAlgorithm: a, strictStorage: o = !1, getTimeSkew: s } = t;
151
+ if (this.#i = s, typeof crypto > "u" || !crypto.subtle) throw Error("DPoP requires Web Crypto API (crypto.subtle) which is not available in this environment.");
152
+ if (!n) throw Error("DPoP requires issuerUrl");
153
+ if (!r) throw Error("DPoP requires clientId");
154
+ if (!i || !Array.isArray(i)) throw Error("DPoP requires serverSupportedAlgorithms array");
155
+ this.#n = i;
156
+ let c = e.ES256;
157
+ if (a !== void 0) {
158
+ if (!this.#n.includes(a)) throw Error(`Requested algorithm '${a}' is not supported by the server. Server supports: ${this.#n.join(", ")}`);
159
+ c = a;
160
+ }
161
+ this.#e = c, this.#t = new p(n.toString(), r, o);
162
+ }
163
+ async init() {
164
+ await this.#t.init();
165
+ let e = await this.#t.get();
166
+ if (e) {
167
+ let t = l[this.#e], n = e.keys.publicKey.algorithm;
168
+ (n.name !== t.name || t.namedCurve && n.namedCurve !== t.namedCurve) && (console.warn("[KEYCLOAK] Stored DPoP key algorithm does not match requested algorithm, regenerating key pair."), await this.#t.flush(), e = void 0);
169
+ }
170
+ e || (e = { keys: await this.#a() }, await this.#t.set(e));
171
+ }
172
+ async #a() {
173
+ let t = l[this.#e];
174
+ if (!t) throw Error(`Unknown signature algorithm: ${this.#e}`);
175
+ try {
176
+ return await crypto.subtle.generateKey(t, !1, ["sign"]);
177
+ } catch (t) {
178
+ if (!(t instanceof DOMException && t.name === "NotSupportedError") || this.#e !== e.EdDSA) throw t;
179
+ let n = d.find((e) => this.#n.includes(e));
180
+ if (!n) throw Error("No supported algorithm available in this browser");
181
+ return this.#e = n, this.#a();
182
+ }
183
+ }
184
+ async #o(e, t) {
185
+ let n = u[this.#e];
186
+ if (!n) throw Error(`Unknown signature algorithm: ${this.#e}`);
187
+ return await crypto.subtle.sign(n, t, e);
188
+ }
189
+ async flush() {
190
+ await this.#t.flush();
191
+ }
192
+ async getAuthServerNonce() {
193
+ return (await this.#t.get())?.nonce;
194
+ }
195
+ async updateAuthServerNonce(e) {
196
+ await this.#t.updateNonce(e);
197
+ }
198
+ getResourceServerNonce(e) {
199
+ return this.#r.get(e);
200
+ }
201
+ updateResourceServerNonce(e, t) {
202
+ o(t) && this.#r.set(e, t);
203
+ }
204
+ async generateDPoPProof(e, t, n, r) {
205
+ let i = {
206
+ jti: crypto.randomUUID(),
207
+ htm: t,
208
+ htu: (() => {
209
+ let t = new URL(e);
210
+ return t.origin + t.pathname;
211
+ })(),
212
+ iat: Math.floor(Date.now() / 1e3) - (this.#i?.() ?? 0),
213
+ ...n !== void 0 && { ath: g(await h(n)) },
214
+ ...r !== void 0 && { nonce: r }
215
+ }, a = await this.#t.get();
216
+ if (a === void 0) throw Error("DPoP not initialized");
217
+ let o = await crypto.subtle.exportKey("jwk", a.keys.publicKey), s = {
218
+ alg: this.#e,
219
+ typ: "dpop+jwt",
220
+ jwk: {
221
+ crv: o.crv,
222
+ kty: o.kty,
223
+ x: o.x,
224
+ y: o.y
225
+ }
226
+ }, c = new TextEncoder(), l = `${g(c.encode(JSON.stringify(s)))}.${g(c.encode(JSON.stringify(i)))}`;
227
+ return `${l}.${g(await this.#o(c.encode(l), a.keys.privateKey))}`;
228
+ }
229
+ };
230
+ async function h(e) {
231
+ let t = new TextEncoder().encode(e);
232
+ if (typeof crypto > "u" || crypto.subtle === void 0) throw Error("Web Crypto API is not available.");
233
+ return await crypto.subtle.digest("SHA-256", t);
234
+ }
235
+ function g(e) {
236
+ let t = e instanceof Uint8Array ? e : new Uint8Array(e), n = String.fromCharCode(...t);
237
+ return btoa(n).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
238
+ }
239
+ export { e as BrowserSignatureAlgs, m as DPoPSignatureProvider };