ovr 6.2.5 → 7.0.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/app/index.d.ts +51 -7
- package/dist/app/index.d.ts.map +1 -1
- package/dist/app/index.js +163 -28
- package/dist/auth/auth-data.d.ts +26 -0
- package/dist/auth/auth-data.d.ts.map +1 -0
- package/dist/auth/auth-data.js +42 -0
- package/dist/auth/cbor.d.ts +50 -0
- package/dist/auth/cbor.d.ts.map +1 -0
- package/dist/auth/cbor.js +200 -0
- package/dist/auth/client-source.d.ts +3 -0
- package/dist/auth/client-source.d.ts.map +1 -0
- package/dist/auth/client-source.js +3 -0
- package/dist/auth/client.d.ts +3 -0
- package/dist/auth/client.d.ts.map +1 -0
- package/dist/auth/client.js +186 -0
- package/dist/auth/configure.d.ts +28 -0
- package/dist/auth/configure.d.ts.map +1 -0
- package/dist/auth/configure.js +228 -0
- package/dist/auth/der.d.ts +6 -0
- package/dist/auth/der.d.ts.map +1 -0
- package/dist/auth/der.js +36 -0
- package/dist/auth/index.d.ts +242 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +152 -0
- package/dist/auth/issue.d.ts +36 -0
- package/dist/auth/issue.d.ts.map +1 -0
- package/dist/auth/issue.js +47 -0
- package/dist/auth/metadata.d.ts +22 -0
- package/dist/auth/metadata.d.ts.map +1 -0
- package/dist/auth/metadata.js +134 -0
- package/dist/auth/oauth.d.ts +29 -0
- package/dist/auth/oauth.d.ts.map +1 -0
- package/dist/auth/oauth.js +724 -0
- package/dist/auth/passkey.d.ts +101 -0
- package/dist/auth/passkey.d.ts.map +1 -0
- package/dist/auth/passkey.js +393 -0
- package/dist/auth/state.d.ts +49 -0
- package/dist/auth/state.d.ts.map +1 -0
- package/dist/auth/state.js +184 -0
- package/dist/auth/storage.d.ts +193 -0
- package/dist/auth/storage.d.ts.map +1 -0
- package/dist/auth/storage.js +410 -0
- package/dist/auth/token.d.ts +12 -0
- package/dist/auth/token.d.ts.map +1 -0
- package/dist/auth/token.js +39 -0
- package/dist/context/index.d.ts +86 -16
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +166 -42
- package/dist/cookie/index.d.ts +3 -0
- package/dist/cookie/index.d.ts.map +1 -1
- package/dist/cookie/index.js +1 -0
- package/dist/database/index.d.ts +262 -0
- package/dist/database/index.d.ts.map +1 -0
- package/dist/database/index.js +807 -0
- package/dist/form/index.d.ts +699 -0
- package/dist/form/index.d.ts.map +1 -0
- package/dist/form/index.js +901 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -3
- package/dist/jsx/elements.d.ts +28 -2
- package/dist/jsx/elements.d.ts.map +1 -1
- package/dist/jsx/index.d.ts +20 -4
- package/dist/jsx/index.d.ts.map +1 -1
- package/dist/jsx/index.js +6 -65
- package/dist/limiter/index.d.ts +65 -0
- package/dist/limiter/index.d.ts.map +1 -0
- package/dist/limiter/index.js +157 -0
- package/dist/markdown/index.d.ts +61 -0
- package/dist/markdown/index.d.ts.map +1 -0
- package/dist/markdown/index.js +1160 -0
- package/dist/markup/index.d.ts +188 -0
- package/dist/markup/index.d.ts.map +1 -0
- package/dist/markup/index.js +718 -0
- package/dist/mcp/index.d.ts +73 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +1015 -0
- package/dist/middleware/index.d.ts +3 -4
- package/dist/middleware/index.d.ts.map +1 -1
- package/dist/multipart/index.d.ts +53 -7
- package/dist/multipart/index.d.ts.map +1 -1
- package/dist/multipart/index.js +289 -123
- package/dist/route/index.d.ts +226 -80
- package/dist/route/index.d.ts.map +1 -1
- package/dist/route/index.js +239 -99
- package/dist/schema/index.d.ts +307 -734
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +783 -1050
- package/dist/table/index.d.ts +132 -0
- package/dist/table/index.d.ts.map +1 -0
- package/dist/table/index.js +188 -0
- package/dist/trie/index.js +4 -4
- package/dist/util/index.d.ts +37 -5
- package/dist/util/index.d.ts.map +1 -1
- package/dist/util/index.js +156 -41
- package/package.json +11 -4
- package/src/app/index.ts +230 -42
- package/src/auth/auth-data.ts +56 -0
- package/src/auth/cbor.ts +231 -0
- package/src/auth/client-source.ts +3 -0
- package/src/auth/client.ts +205 -0
- package/src/auth/configure.ts +279 -0
- package/src/auth/der.ts +35 -0
- package/src/auth/index.ts +387 -0
- package/src/auth/issue.ts +52 -0
- package/src/auth/metadata.ts +149 -0
- package/src/auth/oauth.ts +882 -0
- package/src/auth/passkey.ts +556 -0
- package/src/auth/state.ts +213 -0
- package/src/auth/storage.ts +572 -0
- package/src/auth/token.ts +67 -0
- package/src/context/index.ts +240 -65
- package/src/cookie/index.ts +3 -0
- package/src/database/index.ts +1193 -0
- package/src/form/index.ts +1720 -0
- package/src/index.ts +10 -3
- package/src/jsx/elements.ts +45 -25
- package/src/jsx/index.ts +24 -69
- package/src/limiter/index.ts +221 -0
- package/src/markdown/index.ts +1322 -0
- package/src/markup/index.ts +853 -0
- package/src/mcp/conformance.2025-11-25.yml +39 -0
- package/src/mcp/conformance.2026-07-28.yml +56 -0
- package/src/mcp/index.ts +1293 -0
- package/src/middleware/index.ts +5 -6
- package/src/multipart/index.ts +360 -148
- package/src/route/index.ts +559 -278
- package/src/schema/index.ts +1542 -2256
- package/src/table/index.ts +387 -0
- package/src/trie/index.ts +4 -4
- package/src/util/index.ts +163 -49
- package/dist/render/index.d.ts +0 -79
- package/dist/render/index.d.ts.map +0 -1
- package/dist/render/index.js +0 -265
- package/src/render/index.ts +0 -318
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { Codec } from "../util/index.js";
|
|
2
|
+
import { Issue } from "./issue.js";
|
|
3
|
+
/** COSE (CBOR Object Signing and Encryption) key format utilities */
|
|
4
|
+
export class COSE {
|
|
5
|
+
/** Fixed SPKI header for an uncompressed P-256 point. */
|
|
6
|
+
static #prefix = new Uint8Array([
|
|
7
|
+
0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02,
|
|
8
|
+
0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03,
|
|
9
|
+
0x42, 0x00, 0x04,
|
|
10
|
+
]);
|
|
11
|
+
/**
|
|
12
|
+
* Convert COSE public key to SPKI format.
|
|
13
|
+
*
|
|
14
|
+
* Only EC2 keys with P-256 curve (ES256, alg -7) are supported. This is the standard modern algorithm
|
|
15
|
+
* supported by virtually all platform authenticators (https://www.rfc-editor.org/rfc/rfc8152#section-8.1).
|
|
16
|
+
*
|
|
17
|
+
* @param cose - COSE key map with type, curve, and coordinates
|
|
18
|
+
* @returns SPKI encoded public key as bytes
|
|
19
|
+
* @throws Issue if key type, curve, or coordinates are invalid
|
|
20
|
+
*/
|
|
21
|
+
static toSPKI(cose) {
|
|
22
|
+
if (cose.get(1) !== 2)
|
|
23
|
+
throw new Issue("COSE type");
|
|
24
|
+
if (cose.get(-1) !== 1)
|
|
25
|
+
throw new Issue("COSE curve");
|
|
26
|
+
if (cose.get(3) !== -7)
|
|
27
|
+
throw new Issue("COSE algorithm");
|
|
28
|
+
const x = cose.get(-2); // COSE label -2 = x coordinate
|
|
29
|
+
const y = cose.get(-3); // COSE label -3 = y coordinate
|
|
30
|
+
if (!(x instanceof Uint8Array) ||
|
|
31
|
+
!(y instanceof Uint8Array) ||
|
|
32
|
+
x.length !== 32 ||
|
|
33
|
+
y.length !== 32)
|
|
34
|
+
throw new Issue("COSE coordinates");
|
|
35
|
+
return new Uint8Array([...COSE.#prefix, ...x, ...y]);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** CBOR (Concise Binary Object Representation) decoder for WebAuthn data */
|
|
39
|
+
export class CBOR {
|
|
40
|
+
/** Encoded data to decode */
|
|
41
|
+
#data;
|
|
42
|
+
/** Current read position in data */
|
|
43
|
+
#offset = 0;
|
|
44
|
+
/**
|
|
45
|
+
* Create a new CBOR instance
|
|
46
|
+
*
|
|
47
|
+
* @param data WebAuthn data
|
|
48
|
+
*/
|
|
49
|
+
constructor(data) {
|
|
50
|
+
if (data.length > 65536)
|
|
51
|
+
throw new Issue("CBOR size");
|
|
52
|
+
this.#data = data;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Decode attestation object and extract authenticator data.
|
|
56
|
+
*
|
|
57
|
+
* Only supports fmt === "none", other formats may throw earlier depending on CBOR contents
|
|
58
|
+
*
|
|
59
|
+
* @returns Authenticator data bytes
|
|
60
|
+
* @throws Issue if CBOR structure is invalid
|
|
61
|
+
*/
|
|
62
|
+
decodeAttestation() {
|
|
63
|
+
const value = this.#parseNext();
|
|
64
|
+
if (value instanceof Map) {
|
|
65
|
+
const authData = value.get("authData");
|
|
66
|
+
const statement = value.get("attStmt");
|
|
67
|
+
if (value.get("fmt") === "none" &&
|
|
68
|
+
authData instanceof Uint8Array &&
|
|
69
|
+
statement instanceof Map &&
|
|
70
|
+
statement.size === 0 &&
|
|
71
|
+
this.#offset === this.#data.length) {
|
|
72
|
+
return authData;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
throw new Issue("credential");
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Decode COSE key from CBOR format.
|
|
79
|
+
*
|
|
80
|
+
* @returns COSE key map with numeric labels
|
|
81
|
+
* @throws Issue if CBOR structure is invalid
|
|
82
|
+
*/
|
|
83
|
+
decodeCOSEKey() {
|
|
84
|
+
const value = this.#parseNext();
|
|
85
|
+
if (!(value instanceof Map)) {
|
|
86
|
+
throw new Issue("CBOR map");
|
|
87
|
+
}
|
|
88
|
+
const result = new Map();
|
|
89
|
+
for (const [k, v] of value) {
|
|
90
|
+
if (typeof k !== "number") {
|
|
91
|
+
throw new Issue("COSE labels");
|
|
92
|
+
}
|
|
93
|
+
if (typeof v !== "number" && !(v instanceof Uint8Array)) {
|
|
94
|
+
throw new Issue("COSE value");
|
|
95
|
+
}
|
|
96
|
+
result.set(k, v);
|
|
97
|
+
}
|
|
98
|
+
return result;
|
|
99
|
+
}
|
|
100
|
+
/** Bytes consumed by the last decoded value. */
|
|
101
|
+
get offset() {
|
|
102
|
+
return this.#offset;
|
|
103
|
+
}
|
|
104
|
+
/** Decode authenticator extensions as a CBOR map. */
|
|
105
|
+
decodeExtensions() {
|
|
106
|
+
const value = this.#parseNext();
|
|
107
|
+
if (!(value instanceof Map) ||
|
|
108
|
+
[...value.keys()].some((key) => typeof key !== "string"))
|
|
109
|
+
throw new Issue("CBOR extensions");
|
|
110
|
+
return value;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Read n bytes and advance offset.
|
|
114
|
+
*
|
|
115
|
+
* @param n - Number of bytes to read
|
|
116
|
+
* @returns Subarray of data
|
|
117
|
+
*/
|
|
118
|
+
#read(n) {
|
|
119
|
+
const end = this.#offset + n;
|
|
120
|
+
if (end > this.#data.length) {
|
|
121
|
+
throw new Issue("CBOR stream");
|
|
122
|
+
}
|
|
123
|
+
return this.#data.subarray(this.#offset, (this.#offset = end));
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Read a big-endian unsigned integer from n bytes.
|
|
127
|
+
*
|
|
128
|
+
* @param bytes - Number of bytes to read (1, 2, or 4)
|
|
129
|
+
* @returns Decoded unsigned integer
|
|
130
|
+
* @throws Issue if the stream ends first
|
|
131
|
+
*/
|
|
132
|
+
#readUint(bytes) {
|
|
133
|
+
let value = 0;
|
|
134
|
+
for (const byte of this.#read(bytes))
|
|
135
|
+
value = value * 256 + byte;
|
|
136
|
+
return value;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Parse next CBOR value from stream.
|
|
140
|
+
*
|
|
141
|
+
* @returns Decoded value (primitives, Uint8Array, or Map)
|
|
142
|
+
* @throws Issue if stream is malformed
|
|
143
|
+
*/
|
|
144
|
+
#parseNext(depth = 0) {
|
|
145
|
+
if (depth > 8)
|
|
146
|
+
throw new Issue("CBOR depth");
|
|
147
|
+
const initial = this.#read(1)[0];
|
|
148
|
+
const major = initial >> 5;
|
|
149
|
+
const minor = initial & 0x1f;
|
|
150
|
+
if (major === 7 && minor === 20)
|
|
151
|
+
return false;
|
|
152
|
+
if (major === 7 && minor === 21)
|
|
153
|
+
return true;
|
|
154
|
+
if (major === 7 && minor === 22)
|
|
155
|
+
return null;
|
|
156
|
+
let length;
|
|
157
|
+
if (minor < 24) {
|
|
158
|
+
length = minor;
|
|
159
|
+
}
|
|
160
|
+
else if (minor < 27) {
|
|
161
|
+
// 24, 25 and 26 are followed by 1, 2 and 4 bytes
|
|
162
|
+
length = this.#readUint(2 ** (minor - 24));
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
throw new Issue("CBOR length");
|
|
166
|
+
}
|
|
167
|
+
if (major === 0)
|
|
168
|
+
return length;
|
|
169
|
+
if (major === 1)
|
|
170
|
+
return -1 - length;
|
|
171
|
+
if (major === 2)
|
|
172
|
+
return this.#read(length);
|
|
173
|
+
if (major === 3) {
|
|
174
|
+
try {
|
|
175
|
+
return Codec.decode(this.#read(length));
|
|
176
|
+
}
|
|
177
|
+
catch {
|
|
178
|
+
throw new Issue("CBOR text");
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if ((major === 4 || major === 5) && length > 128)
|
|
182
|
+
throw new Issue("CBOR entries");
|
|
183
|
+
if (major === 4)
|
|
184
|
+
return Array.from({ length }, () => this.#parseNext(depth + 1));
|
|
185
|
+
if (major === 5) {
|
|
186
|
+
const map = new Map();
|
|
187
|
+
for (let i = 0; i < length; i++) {
|
|
188
|
+
const k = this.#parseNext(depth + 1);
|
|
189
|
+
if (typeof k !== "number" && typeof k !== "string") {
|
|
190
|
+
throw new Issue("CBOR key");
|
|
191
|
+
}
|
|
192
|
+
if (map.has(k))
|
|
193
|
+
throw new Issue("CBOR duplicate key");
|
|
194
|
+
map.set(k, this.#parseNext(depth + 1));
|
|
195
|
+
}
|
|
196
|
+
return map;
|
|
197
|
+
}
|
|
198
|
+
throw new Issue(`CBOR type ${major}`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const source = "export function listen(e,t,n,r){let i=document.getElementById(e),a=i?.closest(`form`),o=i?.previousElementSibling,s=a?.querySelector(`[data-passkey-error]:not([data-passkey-fallback])`)??o;if(!(a instanceof HTMLFormElement)||!(s instanceof HTMLElement))return;s!==o&&o instanceof HTMLElement&&(o.hidden=!0);let c=e=>{let t=a.elements.namedItem(e);if(t instanceof HTMLInputElement)return t;let n=document.createElement(`input`);return n.type=`hidden`,n.name=e,a.append(n),n},l=c(`credential`),u=c(`ceremony`),d=!1,f=!1,p=!1,m,h=0,g,_=()=>`Too many requests. Try again in ${Math.ceil((h-Date.now())/1e3)} seconds.`,v=()=>{clearTimeout(g),g=void 0,d=f=p=!1,m=void 0,l.value=u.value=``,a.removeAttribute(`aria-busy`)},y=(e,t)=>{e instanceof HTMLElement&&`setCustomValidity`in e&&typeof e.setCustomValidity==`function`&&e.setCustomValidity(t)},b=e=>y(e.target,``);return a.addEventListener(`input`,b),a.addEventListener(`change`,b),a.addEventListener(`submit`,async e=>{if(!e.submitter?.hasAttribute(`formaction`)){if(f){p?m=e:e.preventDefault();return}if(e.preventDefault(),!d){if(h>Date.now()){s.textContent=_();return}d=!0,s.textContent=``,a.setAttribute(`aria-busy`,`true`);try{if(!window.PublicKeyCredential?.parseCreationOptionsFromJSON||!PublicKeyCredential.parseRequestOptionsFromJSON||!navigator.credentials)throw Error(`Passkeys are unavailable in this browser.`);let i=new FormData(a);i.delete(`credential`),i.delete(`ceremony`),i.set(`bootstrap`,t);let o=await fetch(n,{method:`POST`,body:i,credentials:`same-origin`,cache:`no-store`});if(o.status===429){let e=Date.now(),t=o.headers.get(`retry-after`)??`60`,n=/^\\d+$/.test(t)?e+Number(t)*1e3:Date.parse(t);throw h=Number.isNaN(n)?e+6e4:Math.min(e+36e5,Math.max(e+1e3,n)),Error(_())}if(o.status===422){let e=await o.json();if(Array.isArray(e.fields))for(let t of e.fields)typeof t==`string`&&y(a.elements.namedItem(t),`Check this field.`);throw a.reportValidity(),Error(`Check your registration details and try again.`)}if(o.status===410)throw Error(`This page has expired. Reload and try again.`);if(!o.ok)throw Error(`Could not start the passkey request. Try again.`);let c=await o.json();u.value=c.ceremony;let d=await(r===`register`?navigator.credentials.create({publicKey:PublicKeyCredential.parseCreationOptionsFromJSON(c.options)}):navigator.credentials.get({publicKey:PublicKeyCredential.parseRequestOptionsFromJSON(c.options)}));if(!(d instanceof PublicKeyCredential))throw Error(`No passkey was returned. Try again.`);l.value=JSON.stringify(d),f=!0,p=!0,m=void 0,HTMLFormElement.prototype.requestSubmit.call(a,e.submitter??void 0),p=!1,f=!!(m&&!m.defaultPrevented),f&&(g=setTimeout(()=>{v(),s.textContent=r===`register`?`If registration already completed, sign in; otherwise try again.`:`If sign-in did not finish, try again.`},12e4))}catch(e){v(),s.textContent=e instanceof DOMException&&e.name===`NotAllowedError`?`Passkey request canceled. Try again.`:e instanceof Error?e.message:`Could not complete the passkey request. Try again.`}finally{d=!1,p=!1,f||a.removeAttribute(`aria-busy`)}}}}),v}const t=new WeakMap,n=()=>document.querySelectorAll(`script[data-passkey]`),r=()=>{for(let r of n()){if(t.has(r))continue;let n=r.dataset.passkey;if(n===`register`||n===`login`){let i=listen(r.id,r.dataset.bootstrap??``,r.dataset.endpoint??``,n);i&&t.set(r,i)}}};typeof document<`u`&&(window.addEventListener(`pageshow`,e=>{if(e.persisted)for(let e of n())t.get(e)?.()}),r(),new MutationObserver(r).observe(document.documentElement,{childList:!0,subtree:!0}));";
|
|
2
|
+
export declare const etag = "W/\"c904f3541cdce47df6c6e44e6ae8fddaa56155055b2b65bc580de00ff3741e7b\"";
|
|
3
|
+
//# sourceMappingURL=client-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-source.d.ts","sourceRoot":"","sources":["../../src/auth/client-source.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,MAAM,y8GAAy8G,CAAC;AAC79G,eAAO,MAAM,IAAI,2EAA2E,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// Generated by scripts/client.js; edit client.ts instead.
|
|
2
|
+
export const source = "export function listen(e,t,n,r){let i=document.getElementById(e),a=i?.closest(`form`),o=i?.previousElementSibling,s=a?.querySelector(`[data-passkey-error]:not([data-passkey-fallback])`)??o;if(!(a instanceof HTMLFormElement)||!(s instanceof HTMLElement))return;s!==o&&o instanceof HTMLElement&&(o.hidden=!0);let c=e=>{let t=a.elements.namedItem(e);if(t instanceof HTMLInputElement)return t;let n=document.createElement(`input`);return n.type=`hidden`,n.name=e,a.append(n),n},l=c(`credential`),u=c(`ceremony`),d=!1,f=!1,p=!1,m,h=0,g,_=()=>`Too many requests. Try again in ${Math.ceil((h-Date.now())/1e3)} seconds.`,v=()=>{clearTimeout(g),g=void 0,d=f=p=!1,m=void 0,l.value=u.value=``,a.removeAttribute(`aria-busy`)},y=(e,t)=>{e instanceof HTMLElement&&`setCustomValidity`in e&&typeof e.setCustomValidity==`function`&&e.setCustomValidity(t)},b=e=>y(e.target,``);return a.addEventListener(`input`,b),a.addEventListener(`change`,b),a.addEventListener(`submit`,async e=>{if(!e.submitter?.hasAttribute(`formaction`)){if(f){p?m=e:e.preventDefault();return}if(e.preventDefault(),!d){if(h>Date.now()){s.textContent=_();return}d=!0,s.textContent=``,a.setAttribute(`aria-busy`,`true`);try{if(!window.PublicKeyCredential?.parseCreationOptionsFromJSON||!PublicKeyCredential.parseRequestOptionsFromJSON||!navigator.credentials)throw Error(`Passkeys are unavailable in this browser.`);let i=new FormData(a);i.delete(`credential`),i.delete(`ceremony`),i.set(`bootstrap`,t);let o=await fetch(n,{method:`POST`,body:i,credentials:`same-origin`,cache:`no-store`});if(o.status===429){let e=Date.now(),t=o.headers.get(`retry-after`)??`60`,n=/^\\d+$/.test(t)?e+Number(t)*1e3:Date.parse(t);throw h=Number.isNaN(n)?e+6e4:Math.min(e+36e5,Math.max(e+1e3,n)),Error(_())}if(o.status===422){let e=await o.json();if(Array.isArray(e.fields))for(let t of e.fields)typeof t==`string`&&y(a.elements.namedItem(t),`Check this field.`);throw a.reportValidity(),Error(`Check your registration details and try again.`)}if(o.status===410)throw Error(`This page has expired. Reload and try again.`);if(!o.ok)throw Error(`Could not start the passkey request. Try again.`);let c=await o.json();u.value=c.ceremony;let d=await(r===`register`?navigator.credentials.create({publicKey:PublicKeyCredential.parseCreationOptionsFromJSON(c.options)}):navigator.credentials.get({publicKey:PublicKeyCredential.parseRequestOptionsFromJSON(c.options)}));if(!(d instanceof PublicKeyCredential))throw Error(`No passkey was returned. Try again.`);l.value=JSON.stringify(d),f=!0,p=!0,m=void 0,HTMLFormElement.prototype.requestSubmit.call(a,e.submitter??void 0),p=!1,f=!!(m&&!m.defaultPrevented),f&&(g=setTimeout(()=>{v(),s.textContent=r===`register`?`If registration already completed, sign in; otherwise try again.`:`If sign-in did not finish, try again.`},12e4))}catch(e){v(),s.textContent=e instanceof DOMException&&e.name===`NotAllowedError`?`Passkey request canceled. Try again.`:e instanceof Error?e.message:`Could not complete the passkey request. Try again.`}finally{d=!1,p=!1,f||a.removeAttribute(`aria-busy`)}}}}),v}const t=new WeakMap,n=()=>document.querySelectorAll(`script[data-passkey]`),r=()=>{for(let r of n()){if(t.has(r))continue;let n=r.dataset.passkey;if(n===`register`||n===`login`){let i=listen(r.id,r.dataset.bootstrap??``,r.dataset.endpoint??``,n);i&&t.set(r,i)}}};typeof document<`u`&&(window.addEventListener(`pageshow`,e=>{if(e.persisted)for(let e of n())t.get(e)?.()}),r(),new MutationObserver(r).observe(document.documentElement,{childList:!0,subtree:!0}));";
|
|
3
|
+
export const etag = "W/\"c904f3541cdce47df6c6e44e6ae8fddaa56155055b2b65bc580de00ff3741e7b\"";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/auth/client.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,wBAAgB,MAAM,CACrB,EAAE,EAAE,MAAM,EACV,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,UAAU,GAAG,OAAO,4BAyK5B"}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/** Attach the passkey protocol to one form. Served as a normal browser module. */
|
|
2
|
+
export function listen(id, bootstrap, endpoint, method) {
|
|
3
|
+
const script = document.getElementById(id);
|
|
4
|
+
const form = script?.closest("form");
|
|
5
|
+
// the accessible error component the form renders before the script
|
|
6
|
+
const fallback = script?.previousElementSibling;
|
|
7
|
+
const status = form?.querySelector("[data-passkey-error]:not([data-passkey-fallback])") ??
|
|
8
|
+
fallback;
|
|
9
|
+
if (!(form instanceof HTMLFormElement) || !(status instanceof HTMLElement))
|
|
10
|
+
return;
|
|
11
|
+
if (status !== fallback && fallback instanceof HTMLElement)
|
|
12
|
+
fallback.hidden = true;
|
|
13
|
+
const hidden = (name) => {
|
|
14
|
+
const field = form.elements.namedItem(name);
|
|
15
|
+
if (field instanceof HTMLInputElement)
|
|
16
|
+
return field;
|
|
17
|
+
const input = document.createElement("input");
|
|
18
|
+
input.type = "hidden";
|
|
19
|
+
input.name = name;
|
|
20
|
+
form.append(input);
|
|
21
|
+
return input;
|
|
22
|
+
};
|
|
23
|
+
const credential = hidden("credential");
|
|
24
|
+
const ceremony = hidden("ceremony");
|
|
25
|
+
let loading = false;
|
|
26
|
+
let submitting = false;
|
|
27
|
+
let finalizing = false;
|
|
28
|
+
let submitted;
|
|
29
|
+
let retry = 0;
|
|
30
|
+
let timer;
|
|
31
|
+
const limited = () => `Too many requests. Try again in ${Math.ceil((retry - Date.now()) / 1000)} seconds.`;
|
|
32
|
+
const reset = () => {
|
|
33
|
+
clearTimeout(timer);
|
|
34
|
+
timer = undefined;
|
|
35
|
+
loading = submitting = finalizing = false;
|
|
36
|
+
submitted = undefined;
|
|
37
|
+
credential.value = ceremony.value = "";
|
|
38
|
+
form.removeAttribute("aria-busy");
|
|
39
|
+
};
|
|
40
|
+
/** Mark a form field invalid, or valid again with an empty message */
|
|
41
|
+
const validity = (field, message) => {
|
|
42
|
+
if (field instanceof HTMLElement &&
|
|
43
|
+
"setCustomValidity" in field &&
|
|
44
|
+
typeof field.setCustomValidity === "function")
|
|
45
|
+
field.setCustomValidity(message);
|
|
46
|
+
};
|
|
47
|
+
const clear = (e) => validity(e.target, "");
|
|
48
|
+
form.addEventListener("input", clear);
|
|
49
|
+
form.addEventListener("change", clear);
|
|
50
|
+
form.addEventListener("submit", async (e) => {
|
|
51
|
+
// a button that submits elsewhere, such as Deny, needs no passkey
|
|
52
|
+
if (e.submitter?.hasAttribute("formaction"))
|
|
53
|
+
return;
|
|
54
|
+
if (submitting) {
|
|
55
|
+
if (finalizing)
|
|
56
|
+
submitted = e;
|
|
57
|
+
else
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
e.preventDefault();
|
|
62
|
+
if (loading)
|
|
63
|
+
return;
|
|
64
|
+
if (retry > Date.now()) {
|
|
65
|
+
status.textContent = limited();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
loading = true;
|
|
69
|
+
status.textContent = "";
|
|
70
|
+
form.setAttribute("aria-busy", "true");
|
|
71
|
+
try {
|
|
72
|
+
// checked before asking for options, which would spend a challenge
|
|
73
|
+
if (!window.PublicKeyCredential?.parseCreationOptionsFromJSON ||
|
|
74
|
+
!PublicKeyCredential.parseRequestOptionsFromJSON ||
|
|
75
|
+
!navigator.credentials)
|
|
76
|
+
throw new Error("Passkeys are unavailable in this browser.");
|
|
77
|
+
const data = new FormData(form);
|
|
78
|
+
data.delete("credential");
|
|
79
|
+
data.delete("ceremony");
|
|
80
|
+
data.set("bootstrap", bootstrap);
|
|
81
|
+
const res = await fetch(endpoint, {
|
|
82
|
+
method: "POST",
|
|
83
|
+
body: data,
|
|
84
|
+
credentials: "same-origin",
|
|
85
|
+
cache: "no-store",
|
|
86
|
+
});
|
|
87
|
+
if (res.status === 429) {
|
|
88
|
+
const now = Date.now();
|
|
89
|
+
const header = res.headers.get("retry-after") ?? "60";
|
|
90
|
+
const deadline = /^\d+$/.test(header)
|
|
91
|
+
? now + Number(header) * 1000
|
|
92
|
+
: Date.parse(header);
|
|
93
|
+
retry = Number.isNaN(deadline)
|
|
94
|
+
? now + 60000
|
|
95
|
+
: Math.min(now + 3600000, Math.max(now + 1000, deadline));
|
|
96
|
+
throw new Error(limited());
|
|
97
|
+
}
|
|
98
|
+
if (res.status === 422) {
|
|
99
|
+
const result = await res.json();
|
|
100
|
+
if (Array.isArray(result.fields))
|
|
101
|
+
for (const name of result.fields)
|
|
102
|
+
if (typeof name === "string")
|
|
103
|
+
validity(form.elements.namedItem(name), "Check this field.");
|
|
104
|
+
form.reportValidity();
|
|
105
|
+
throw new Error("Check your registration details and try again.");
|
|
106
|
+
}
|
|
107
|
+
if (res.status === 410)
|
|
108
|
+
throw new Error("This page has expired. Reload and try again.");
|
|
109
|
+
if (!res.ok)
|
|
110
|
+
throw new Error("Could not start the passkey request. Try again.");
|
|
111
|
+
// creation options for a registration, request options for a login
|
|
112
|
+
const json = await res.json();
|
|
113
|
+
ceremony.value = json.ceremony;
|
|
114
|
+
const result = await (method === "register"
|
|
115
|
+
? navigator.credentials.create({
|
|
116
|
+
publicKey: PublicKeyCredential.parseCreationOptionsFromJSON(json.options),
|
|
117
|
+
})
|
|
118
|
+
: navigator.credentials.get({
|
|
119
|
+
publicKey: PublicKeyCredential.parseRequestOptionsFromJSON(json.options),
|
|
120
|
+
}));
|
|
121
|
+
if (!(result instanceof PublicKeyCredential))
|
|
122
|
+
throw new Error("No passkey was returned. Try again.");
|
|
123
|
+
credential.value = JSON.stringify(result);
|
|
124
|
+
submitting = true;
|
|
125
|
+
finalizing = true;
|
|
126
|
+
submitted = undefined;
|
|
127
|
+
// Preserve native validation, submit events, and the original submitter.
|
|
128
|
+
HTMLFormElement.prototype.requestSubmit.call(form, e.submitter ?? undefined);
|
|
129
|
+
finalizing = false;
|
|
130
|
+
// requestSubmit synchronously re-enters this listener; TypeScript cannot see that assignment.
|
|
131
|
+
// Validation may prevent the final event; another listener may cancel it.
|
|
132
|
+
submitting = Boolean(submitted && !submitted.defaultPrevented);
|
|
133
|
+
if (submitting)
|
|
134
|
+
timer = setTimeout(() => {
|
|
135
|
+
reset();
|
|
136
|
+
status.textContent =
|
|
137
|
+
method === "register"
|
|
138
|
+
? "If registration already completed, sign in; otherwise try again."
|
|
139
|
+
: "If sign-in did not finish, try again.";
|
|
140
|
+
}, 120000);
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
reset();
|
|
144
|
+
status.textContent =
|
|
145
|
+
error instanceof DOMException && error.name === "NotAllowedError"
|
|
146
|
+
? "Passkey request canceled. Try again."
|
|
147
|
+
: error instanceof Error
|
|
148
|
+
? error.message
|
|
149
|
+
: "Could not complete the passkey request. Try again.";
|
|
150
|
+
}
|
|
151
|
+
finally {
|
|
152
|
+
loading = false;
|
|
153
|
+
finalizing = false;
|
|
154
|
+
if (!submitting)
|
|
155
|
+
form.removeAttribute("aria-busy");
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
return reset;
|
|
159
|
+
}
|
|
160
|
+
// Modules execute once per document. Observe streamed HTML and subsequent fragment navigation too.
|
|
161
|
+
const attached = new WeakMap();
|
|
162
|
+
const scripts = () => document.querySelectorAll("script[data-passkey]");
|
|
163
|
+
const scan = () => {
|
|
164
|
+
for (const script of scripts()) {
|
|
165
|
+
if (attached.has(script))
|
|
166
|
+
continue;
|
|
167
|
+
const method = script.dataset.passkey;
|
|
168
|
+
if (method === "register" || method === "login") {
|
|
169
|
+
const reset = listen(script.id, script.dataset.bootstrap ?? "", script.dataset.endpoint ?? "", method);
|
|
170
|
+
if (reset)
|
|
171
|
+
attached.set(script, reset);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
if (typeof document !== "undefined") {
|
|
176
|
+
window.addEventListener("pageshow", (e) => {
|
|
177
|
+
if (e.persisted)
|
|
178
|
+
for (const script of scripts())
|
|
179
|
+
attached.get(script)?.();
|
|
180
|
+
});
|
|
181
|
+
scan();
|
|
182
|
+
new MutationObserver(scan).observe(document.documentElement, {
|
|
183
|
+
childList: true,
|
|
184
|
+
subtree: true,
|
|
185
|
+
});
|
|
186
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Field } from "../form/index.js";
|
|
2
|
+
import { Route } from "../route/index.js";
|
|
3
|
+
import type { Auth } from "./index.js";
|
|
4
|
+
import type { State } from "./state.js";
|
|
5
|
+
import type { Storage } from "./storage.js";
|
|
6
|
+
/**
|
|
7
|
+
* Construct startup-complete handlers and request-scoped UI components.
|
|
8
|
+
*
|
|
9
|
+
* @template U Users table
|
|
10
|
+
*/
|
|
11
|
+
export declare function configure<U extends Auth.Users>(options: Auth.Options<U>, storage: Storage, state: (c: State.Context) => State): {
|
|
12
|
+
routes: (Route.Used<Route.Get<"/_passkey/client.js", {}, Field.Shape>> | Route.Used<Route.Post<"/_passkey/options/login", {}, {
|
|
13
|
+
bootstrap: Field.Instance<string, "input", "hidden", undefined, undefined>;
|
|
14
|
+
}>> | Route.Used<Route.Post<"/_passkey/options/register", {}, {
|
|
15
|
+
bootstrap: Field.Instance<string, "input", "hidden", undefined, undefined>;
|
|
16
|
+
}>> | Route.Used<Route.Post<"/auth/login", {}, {
|
|
17
|
+
credential: Field.Instance<unknown, "input", "hidden", undefined, undefined>;
|
|
18
|
+
ceremony: Field.Instance<string, "input", "hidden", undefined, undefined>;
|
|
19
|
+
}>> | Route.Used<Route.Post<"/auth/logout", {}, Field.Shape>> | Route.Used<Route.Post<"/auth/register", {}, {
|
|
20
|
+
credential: Field.Instance<unknown, "input", "hidden", undefined, undefined>;
|
|
21
|
+
ceremony: Field.Instance<string, "input", "hidden", undefined, undefined>;
|
|
22
|
+
}>>)[];
|
|
23
|
+
/** Create forms in the handler before returning JSX, so ovr can set the binding cookie. */
|
|
24
|
+
forms(c: Auth.Context, props?: {
|
|
25
|
+
nonce?: string;
|
|
26
|
+
}): Auth.Forms<Auth.Fields<U>>;
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=configure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../../src/auth/configure.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAe,MAAM,kBAAkB,CAAC;AAItD,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAGvC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,IAAI,CAAC,KAAK,EAC7C,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EACxB,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,OAAO,KAAK,KAAK;;;;;;;;;;;;IA6MjC,2FAA2F;aAEvF,IAAI,CAAC,OAAO,UACR;QAAE,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GACvB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;EA+C9B"}
|