@axium/server 0.19.7 → 0.19.9

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.
Files changed (171) hide show
  1. package/build/client/_app/immutable/assets/3.B53jfNY9.css +1 -0
  2. package/build/client/_app/immutable/assets/3.B53jfNY9.css.br +0 -0
  3. package/build/client/_app/immutable/assets/3.B53jfNY9.css.gz +0 -0
  4. package/build/client/_app/immutable/assets/_page.dJj6MsMM.css +1 -0
  5. package/build/client/_app/immutable/assets/_page.dJj6MsMM.css.br +0 -0
  6. package/build/client/_app/immutable/assets/_page.dJj6MsMM.css.gz +0 -0
  7. package/build/client/_app/immutable/chunks/BJss2F7v.js +31 -0
  8. package/build/client/_app/immutable/chunks/BJss2F7v.js.br +0 -0
  9. package/build/client/_app/immutable/chunks/BJss2F7v.js.gz +0 -0
  10. package/build/client/_app/immutable/chunks/{BYEtX5Az.js → BK1-xGGj.js} +1 -1
  11. package/build/client/_app/immutable/chunks/BK1-xGGj.js.br +0 -0
  12. package/build/client/_app/immutable/chunks/BK1-xGGj.js.gz +0 -0
  13. package/build/client/_app/immutable/chunks/{IgiyYk6u.js → BZOe2Jko.js} +1 -1
  14. package/build/client/_app/immutable/chunks/BZOe2Jko.js.br +0 -0
  15. package/build/client/_app/immutable/chunks/BZOe2Jko.js.gz +0 -0
  16. package/build/client/_app/immutable/chunks/{DY1x3fBx.js → DEcO6BQR.js} +1 -1
  17. package/build/client/_app/immutable/chunks/DEcO6BQR.js.br +5 -0
  18. package/build/client/_app/immutable/chunks/DEcO6BQR.js.gz +0 -0
  19. package/build/client/_app/immutable/chunks/{FWeOBoAM.js → DGhIdZ_j.js} +1 -1
  20. package/build/client/_app/immutable/chunks/DGhIdZ_j.js.br +0 -0
  21. package/build/client/_app/immutable/chunks/DGhIdZ_j.js.gz +0 -0
  22. package/build/client/_app/immutable/chunks/DQaZ7GJF.js +3 -0
  23. package/build/client/_app/immutable/chunks/DQaZ7GJF.js.br +0 -0
  24. package/build/client/_app/immutable/chunks/DQaZ7GJF.js.gz +0 -0
  25. package/build/client/_app/immutable/chunks/{p-F-zYzk.js → sfKJ2mhH.js} +1 -1
  26. package/build/client/_app/immutable/chunks/sfKJ2mhH.js.br +0 -0
  27. package/build/client/_app/immutable/chunks/sfKJ2mhH.js.gz +0 -0
  28. package/build/client/_app/immutable/chunks/uU8Mt6Mg.js +1 -0
  29. package/build/client/_app/immutable/chunks/uU8Mt6Mg.js.br +0 -0
  30. package/build/client/_app/immutable/chunks/uU8Mt6Mg.js.gz +0 -0
  31. package/build/client/_app/immutable/entry/{app.CAgyUG0l.js → app.CtLxdB3j.js} +2 -2
  32. package/build/client/_app/immutable/entry/app.CtLxdB3j.js.br +0 -0
  33. package/build/client/_app/immutable/entry/app.CtLxdB3j.js.gz +0 -0
  34. package/build/client/_app/immutable/entry/start.BHoGWGCr.js +1 -0
  35. package/build/client/_app/immutable/entry/start.BHoGWGCr.js.br +0 -0
  36. package/build/client/_app/immutable/entry/start.BHoGWGCr.js.gz +0 -0
  37. package/build/client/_app/immutable/nodes/{0.fU2Fkia3.js → 0.DuvLHQ5N.js} +1 -1
  38. package/build/client/_app/immutable/nodes/0.DuvLHQ5N.js.br +0 -0
  39. package/build/client/_app/immutable/nodes/0.DuvLHQ5N.js.gz +0 -0
  40. package/build/client/_app/immutable/nodes/{1.DuyZ1f2y.js → 1.wyN-TXT3.js} +1 -1
  41. package/build/client/_app/immutable/nodes/1.wyN-TXT3.js.br +0 -0
  42. package/build/client/_app/immutable/nodes/1.wyN-TXT3.js.gz +0 -0
  43. package/build/client/_app/immutable/nodes/{2.Cczp5_pl.js → 2.CiWhhaCq.js} +1 -1
  44. package/build/client/_app/immutable/nodes/2.CiWhhaCq.js.br +0 -0
  45. package/build/client/_app/immutable/nodes/2.CiWhhaCq.js.gz +0 -0
  46. package/build/client/_app/immutable/nodes/3.Cs-6XQLG.js +1 -0
  47. package/build/client/_app/immutable/nodes/3.Cs-6XQLG.js.br +0 -0
  48. package/build/client/_app/immutable/nodes/3.Cs-6XQLG.js.gz +0 -0
  49. package/build/client/_app/immutable/nodes/{4.DFZa97F0.js → 4.CYhOOrTZ.js} +1 -1
  50. package/build/client/_app/immutable/nodes/4.CYhOOrTZ.js.br +0 -0
  51. package/build/client/_app/immutable/nodes/4.CYhOOrTZ.js.gz +0 -0
  52. package/build/client/_app/immutable/nodes/5.CZtEsvvr.js +1 -0
  53. package/build/client/_app/immutable/nodes/5.CZtEsvvr.js.br +0 -0
  54. package/build/client/_app/immutable/nodes/5.CZtEsvvr.js.gz +0 -0
  55. package/build/client/_app/immutable/nodes/{6.ezb4muQm.js → 6.DpkTCLEe.js} +1 -1
  56. package/build/client/_app/immutable/nodes/6.DpkTCLEe.js.br +0 -0
  57. package/build/client/_app/immutable/nodes/6.DpkTCLEe.js.gz +0 -0
  58. package/build/client/_app/version.json +1 -1
  59. package/build/client/_app/version.json.br +0 -0
  60. package/build/client/_app/version.json.gz +0 -0
  61. package/build/server/chunks/{0-BwO1RCtn.js → 0-B8fDicB8.js} +2 -2
  62. package/build/server/chunks/{0-BwO1RCtn.js.map → 0-B8fDicB8.js.map} +1 -1
  63. package/build/server/chunks/1-CZaQz0kM.js +9 -0
  64. package/build/server/chunks/{1-CHeaiyyB.js.map → 1-CZaQz0kM.js.map} +1 -1
  65. package/build/server/chunks/{2-BwMXZ3uH.js → 2-CVTt4PZM.js} +2 -2
  66. package/build/server/chunks/{2-BwMXZ3uH.js.map → 2-CVTt4PZM.js.map} +1 -1
  67. package/build/server/chunks/3-CYzzOoBn.js +13 -0
  68. package/build/server/chunks/3-CYzzOoBn.js.map +1 -0
  69. package/build/server/chunks/4-jbfAhnSm.js +9 -0
  70. package/build/server/chunks/4-jbfAhnSm.js.map +1 -0
  71. package/build/server/chunks/5-CfXowMzQ.js +9 -0
  72. package/build/server/chunks/5-CfXowMzQ.js.map +1 -0
  73. package/build/server/chunks/6-BRekt1OA.js +9 -0
  74. package/build/server/chunks/6-BRekt1OA.js.map +1 -0
  75. package/build/server/chunks/{user-BxKya_IG.js → FormDialog-qGzPcWE3.js} +779 -806
  76. package/build/server/chunks/FormDialog-qGzPcWE3.js.map +1 -0
  77. package/build/server/chunks/{Logout-Bn4ION8s.js → Logout-DWwALPvt.js} +3 -3
  78. package/build/server/chunks/Logout-DWwALPvt.js.map +1 -0
  79. package/build/server/chunks/{_page.svelte-C5WDLp_N.js → _page.svelte-BypU2Yzj.js} +3 -3
  80. package/build/server/chunks/_page.svelte-BypU2Yzj.js.map +1 -0
  81. package/build/server/chunks/{_page.svelte-Cajk6qyo.js → _page.svelte-CYPwBw0g.js} +3 -3
  82. package/build/server/chunks/_page.svelte-CYPwBw0g.js.map +1 -0
  83. package/build/server/chunks/_page.svelte-Dz_KPYcN.js +299 -0
  84. package/build/server/chunks/_page.svelte-Dz_KPYcN.js.map +1 -0
  85. package/build/server/chunks/_page.svelte-Fe_xIcJF.js +11 -0
  86. package/build/server/chunks/{_page.svelte-DfGguJ-z.js.map → _page.svelte-Fe_xIcJF.js.map} +1 -1
  87. package/build/server/chunks/{error.svelte-DkJRpKga.js → error.svelte-CZg-BdYa.js} +3 -3
  88. package/build/server/chunks/error.svelte-CZg-BdYa.js.map +1 -0
  89. package/build/server/chunks/{exports-Cc9yggiy.js → exports-Cy4FWdYs.js} +27 -4
  90. package/build/server/chunks/exports-Cy4FWdYs.js.map +1 -0
  91. package/build/server/chunks/{hooks.server-B6C3vGPN.js → hooks.server-Cpa72VJw.js} +3 -3
  92. package/build/server/chunks/{hooks.server-B6C3vGPN.js.map → hooks.server-Cpa72VJw.js.map} +1 -1
  93. package/build/server/chunks/{index-CBVFb-Fk.js → index-CNBqpMEu.js} +4 -42
  94. package/build/server/chunks/index-CNBqpMEu.js.map +1 -0
  95. package/build/server/index.js +3206 -2745
  96. package/build/server/index.js.map +1 -1
  97. package/build/server/manifest.js +11 -8
  98. package/build/server/manifest.js.map +1 -1
  99. package/dist/requests.d.ts +1 -2
  100. package/package.json +1 -1
  101. package/routes/account/+page.svelte +156 -177
  102. package/routes/account/+page.ts +20 -0
  103. package/web/lib/WithContextMenu.svelte +56 -15
  104. package/build/client/_app/immutable/assets/3.C2J9FN5q.css +0 -1
  105. package/build/client/_app/immutable/assets/3.C2J9FN5q.css.br +0 -0
  106. package/build/client/_app/immutable/assets/3.C2J9FN5q.css.gz +0 -0
  107. package/build/client/_app/immutable/assets/_page.CAgJ6UBm.css +0 -1
  108. package/build/client/_app/immutable/assets/_page.CAgJ6UBm.css.br +0 -0
  109. package/build/client/_app/immutable/assets/_page.CAgJ6UBm.css.gz +0 -0
  110. package/build/client/_app/immutable/chunks/BYEtX5Az.js.br +0 -0
  111. package/build/client/_app/immutable/chunks/BYEtX5Az.js.gz +0 -0
  112. package/build/client/_app/immutable/chunks/D9BNd75C.js +0 -3
  113. package/build/client/_app/immutable/chunks/D9BNd75C.js.br +0 -0
  114. package/build/client/_app/immutable/chunks/D9BNd75C.js.gz +0 -0
  115. package/build/client/_app/immutable/chunks/DCUM25og.js +0 -1
  116. package/build/client/_app/immutable/chunks/DCUM25og.js.br +0 -0
  117. package/build/client/_app/immutable/chunks/DCUM25og.js.gz +0 -0
  118. package/build/client/_app/immutable/chunks/DY1x3fBx.js.br +0 -0
  119. package/build/client/_app/immutable/chunks/DY1x3fBx.js.gz +0 -0
  120. package/build/client/_app/immutable/chunks/DYZBB-Ix.js +0 -31
  121. package/build/client/_app/immutable/chunks/DYZBB-Ix.js.br +0 -0
  122. package/build/client/_app/immutable/chunks/DYZBB-Ix.js.gz +0 -0
  123. package/build/client/_app/immutable/chunks/FWeOBoAM.js.br +0 -0
  124. package/build/client/_app/immutable/chunks/FWeOBoAM.js.gz +0 -0
  125. package/build/client/_app/immutable/chunks/IgiyYk6u.js.br +0 -0
  126. package/build/client/_app/immutable/chunks/IgiyYk6u.js.gz +0 -0
  127. package/build/client/_app/immutable/chunks/p-F-zYzk.js.br +0 -0
  128. package/build/client/_app/immutable/chunks/p-F-zYzk.js.gz +0 -0
  129. package/build/client/_app/immutable/entry/app.CAgyUG0l.js.br +0 -0
  130. package/build/client/_app/immutable/entry/app.CAgyUG0l.js.gz +0 -0
  131. package/build/client/_app/immutable/entry/start.CxTr3r7v.js +0 -1
  132. package/build/client/_app/immutable/entry/start.CxTr3r7v.js.br +0 -2
  133. package/build/client/_app/immutable/entry/start.CxTr3r7v.js.gz +0 -0
  134. package/build/client/_app/immutable/nodes/0.fU2Fkia3.js.br +0 -0
  135. package/build/client/_app/immutable/nodes/0.fU2Fkia3.js.gz +0 -0
  136. package/build/client/_app/immutable/nodes/1.DuyZ1f2y.js.br +0 -0
  137. package/build/client/_app/immutable/nodes/1.DuyZ1f2y.js.gz +0 -0
  138. package/build/client/_app/immutable/nodes/2.Cczp5_pl.js.br +0 -0
  139. package/build/client/_app/immutable/nodes/2.Cczp5_pl.js.gz +0 -0
  140. package/build/client/_app/immutable/nodes/3.BwwptDiR.js +0 -1
  141. package/build/client/_app/immutable/nodes/3.BwwptDiR.js.br +0 -0
  142. package/build/client/_app/immutable/nodes/3.BwwptDiR.js.gz +0 -0
  143. package/build/client/_app/immutable/nodes/4.DFZa97F0.js.br +0 -0
  144. package/build/client/_app/immutable/nodes/4.DFZa97F0.js.gz +0 -0
  145. package/build/client/_app/immutable/nodes/5.CObFvODa.js +0 -1
  146. package/build/client/_app/immutable/nodes/5.CObFvODa.js.br +0 -0
  147. package/build/client/_app/immutable/nodes/5.CObFvODa.js.gz +0 -0
  148. package/build/client/_app/immutable/nodes/6.ezb4muQm.js.br +0 -0
  149. package/build/client/_app/immutable/nodes/6.ezb4muQm.js.gz +0 -0
  150. package/build/server/chunks/1-CHeaiyyB.js +0 -9
  151. package/build/server/chunks/3-BI9EEPQX.js +0 -9
  152. package/build/server/chunks/3-BI9EEPQX.js.map +0 -1
  153. package/build/server/chunks/4-B4PHWuxx.js +0 -9
  154. package/build/server/chunks/4-B4PHWuxx.js.map +0 -1
  155. package/build/server/chunks/5-CIWzJq4D.js +0 -9
  156. package/build/server/chunks/5-CIWzJq4D.js.map +0 -1
  157. package/build/server/chunks/6-BQsBMa_q.js +0 -9
  158. package/build/server/chunks/6-BQsBMa_q.js.map +0 -1
  159. package/build/server/chunks/Logout-Bn4ION8s.js.map +0 -1
  160. package/build/server/chunks/_page.svelte-C5WDLp_N.js.map +0 -1
  161. package/build/server/chunks/_page.svelte-Cajk6qyo.js.map +0 -1
  162. package/build/server/chunks/_page.svelte-DfGguJ-z.js +0 -11
  163. package/build/server/chunks/_page.svelte-WTcgrDKD.js +0 -312
  164. package/build/server/chunks/_page.svelte-WTcgrDKD.js.map +0 -1
  165. package/build/server/chunks/error.svelte-DkJRpKga.js.map +0 -1
  166. package/build/server/chunks/exports-Cc9yggiy.js.map +0 -1
  167. package/build/server/chunks/index-CBVFb-Fk.js.map +0 -1
  168. package/build/server/chunks/user-BxKya_IG.js.map +0 -1
  169. /package/build/client/_app/immutable/assets/{user.Cbakz6hh.css → FormDialog.Cbakz6hh.css} +0 -0
  170. /package/build/client/_app/immutable/assets/{user.Cbakz6hh.css.br → FormDialog.Cbakz6hh.css.br} +0 -0
  171. /package/build/client/_app/immutable/assets/{user.Cbakz6hh.css.gz → FormDialog.Cbakz6hh.css.gz} +0 -0
@@ -1,593 +1,5 @@
1
- import { P as push, Y as copy_payload, Z as assign_payload, a6 as bind_props, T as pop, a7 as spread_props, a5 as spread_attributes, a8 as attr_class, V as escape_html, a9 as clsx } from './index-CBVFb-Fk.js';
2
- import { u as uuid, t as prettifyError, l as literal, o as object, r as record, s as string, f as any, n as number, g as array, h as _enum, i as email, j as boolean, v as date, w as url } from './schemas-C2VqNPFY.js';
3
-
4
- /**
5
- * Convert the given array buffer into a Base64URL-encoded string. Ideal for converting various
6
- * credential response ArrayBuffers to string for sending back to the server as JSON.
7
- *
8
- * Helper method to compliment `base64URLStringToBuffer`
9
- */
10
- function bufferToBase64URLString(buffer) {
11
- const bytes = new Uint8Array(buffer);
12
- let str = '';
13
- for (const charCode of bytes) {
14
- str += String.fromCharCode(charCode);
15
- }
16
- const base64String = btoa(str);
17
- return base64String.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
18
- }
19
-
20
- /**
21
- * Convert from a Base64URL-encoded string to an Array Buffer. Best used when converting a
22
- * credential ID from a JSON string to an ArrayBuffer, like in allowCredentials or
23
- * excludeCredentials
24
- *
25
- * Helper method to compliment `bufferToBase64URLString`
26
- */
27
- function base64URLStringToBuffer(base64URLString) {
28
- // Convert from Base64URL to Base64
29
- const base64 = base64URLString.replace(/-/g, '+').replace(/_/g, '/');
30
- /**
31
- * Pad with '=' until it's a multiple of four
32
- * (4 - (85 % 4 = 1) = 3) % 4 = 3 padding
33
- * (4 - (86 % 4 = 2) = 2) % 4 = 2 padding
34
- * (4 - (87 % 4 = 3) = 1) % 4 = 1 padding
35
- * (4 - (88 % 4 = 0) = 4) % 4 = 0 padding
36
- */
37
- const padLength = (4 - (base64.length % 4)) % 4;
38
- const padded = base64.padEnd(base64.length + padLength, '=');
39
- // Convert to a binary string
40
- const binary = atob(padded);
41
- // Convert binary string to buffer
42
- const buffer = new ArrayBuffer(binary.length);
43
- const bytes = new Uint8Array(buffer);
44
- for (let i = 0; i < binary.length; i++) {
45
- bytes[i] = binary.charCodeAt(i);
46
- }
47
- return buffer;
48
- }
49
-
50
- /**
51
- * Determine if the browser is capable of Webauthn
52
- */
53
- function browserSupportsWebAuthn() {
54
- return _browserSupportsWebAuthnInternals.stubThis(globalThis?.PublicKeyCredential !== undefined &&
55
- typeof globalThis.PublicKeyCredential === 'function');
56
- }
57
- /**
58
- * Make it possible to stub the return value during testing
59
- * @ignore Don't include this in docs output
60
- */
61
- const _browserSupportsWebAuthnInternals = {
62
- stubThis: (value) => value,
63
- };
64
-
65
- function toPublicKeyCredentialDescriptor(descriptor) {
66
- const { id } = descriptor;
67
- return {
68
- ...descriptor,
69
- id: base64URLStringToBuffer(id),
70
- /**
71
- * `descriptor.transports` is an array of our `AuthenticatorTransportFuture` that includes newer
72
- * transports that TypeScript's DOM lib is ignorant of. Convince TS that our list of transports
73
- * are fine to pass to WebAuthn since browsers will recognize the new value.
74
- */
75
- transports: descriptor.transports,
76
- };
77
- }
78
-
79
- /**
80
- * A simple test to determine if a hostname is a properly-formatted domain name
81
- *
82
- * A "valid domain" is defined here: https://url.spec.whatwg.org/#valid-domain
83
- *
84
- * Regex sourced from here:
85
- * https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch08s15.html
86
- */
87
- function isValidDomain(hostname) {
88
- return (
89
- // Consider localhost valid as well since it's okay wrt Secure Contexts
90
- hostname === 'localhost' ||
91
- /^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(hostname));
92
- }
93
-
94
- /**
95
- * A custom Error used to return a more nuanced error detailing _why_ one of the eight documented
96
- * errors in the spec was raised after calling `navigator.credentials.create()` or
97
- * `navigator.credentials.get()`:
98
- *
99
- * - `AbortError`
100
- * - `ConstraintError`
101
- * - `InvalidStateError`
102
- * - `NotAllowedError`
103
- * - `NotSupportedError`
104
- * - `SecurityError`
105
- * - `TypeError`
106
- * - `UnknownError`
107
- *
108
- * Error messages were determined through investigation of the spec to determine under which
109
- * scenarios a given error would be raised.
110
- */
111
- class WebAuthnError extends Error {
112
- constructor({ message, code, cause, name, }) {
113
- // @ts-ignore: help Rollup understand that `cause` is okay to set
114
- super(message, { cause });
115
- Object.defineProperty(this, "code", {
116
- enumerable: true,
117
- configurable: true,
118
- writable: true,
119
- value: void 0
120
- });
121
- this.name = name ?? cause.name;
122
- this.code = code;
123
- }
124
- }
125
-
126
- /**
127
- * Attempt to intuit _why_ an error was raised after calling `navigator.credentials.create()`
128
- */
129
- function identifyRegistrationError({ error, options, }) {
130
- const { publicKey } = options;
131
- if (!publicKey) {
132
- throw Error('options was missing required publicKey property');
133
- }
134
- if (error.name === 'AbortError') {
135
- if (options.signal instanceof AbortSignal) {
136
- // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 16)
137
- return new WebAuthnError({
138
- message: 'Registration ceremony was sent an abort signal',
139
- code: 'ERROR_CEREMONY_ABORTED',
140
- cause: error,
141
- });
142
- }
143
- }
144
- else if (error.name === 'ConstraintError') {
145
- if (publicKey.authenticatorSelection?.requireResidentKey === true) {
146
- // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 4)
147
- return new WebAuthnError({
148
- message: 'Discoverable credentials were required but no available authenticator supported it',
149
- code: 'ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT',
150
- cause: error,
151
- });
152
- }
153
- else if (
154
- // @ts-ignore: `mediation` doesn't yet exist on CredentialCreationOptions but it's possible as of Sept 2024
155
- options.mediation === 'conditional' &&
156
- publicKey.authenticatorSelection?.userVerification === 'required') {
157
- // https://w3c.github.io/webauthn/#sctn-createCredential (Step 22.4)
158
- return new WebAuthnError({
159
- message: 'User verification was required during automatic registration but it could not be performed',
160
- code: 'ERROR_AUTO_REGISTER_USER_VERIFICATION_FAILURE',
161
- cause: error,
162
- });
163
- }
164
- else if (publicKey.authenticatorSelection?.userVerification === 'required') {
165
- // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 5)
166
- return new WebAuthnError({
167
- message: 'User verification was required but no available authenticator supported it',
168
- code: 'ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT',
169
- cause: error,
170
- });
171
- }
172
- }
173
- else if (error.name === 'InvalidStateError') {
174
- // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 20)
175
- // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 3)
176
- return new WebAuthnError({
177
- message: 'The authenticator was previously registered',
178
- code: 'ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED',
179
- cause: error,
180
- });
181
- }
182
- else if (error.name === 'NotAllowedError') {
183
- /**
184
- * Pass the error directly through. Platforms are overloading this error beyond what the spec
185
- * defines and we don't want to overwrite potentially useful error messages.
186
- */
187
- return new WebAuthnError({
188
- message: error.message,
189
- code: 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY',
190
- cause: error,
191
- });
192
- }
193
- else if (error.name === 'NotSupportedError') {
194
- const validPubKeyCredParams = publicKey.pubKeyCredParams.filter((param) => param.type === 'public-key');
195
- if (validPubKeyCredParams.length === 0) {
196
- // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 10)
197
- return new WebAuthnError({
198
- message: 'No entry in pubKeyCredParams was of type "public-key"',
199
- code: 'ERROR_MALFORMED_PUBKEYCREDPARAMS',
200
- cause: error,
201
- });
202
- }
203
- // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 2)
204
- return new WebAuthnError({
205
- message: 'No available authenticator supported any of the specified pubKeyCredParams algorithms',
206
- code: 'ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG',
207
- cause: error,
208
- });
209
- }
210
- else if (error.name === 'SecurityError') {
211
- const effectiveDomain = globalThis.location.hostname;
212
- if (!isValidDomain(effectiveDomain)) {
213
- // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 7)
214
- return new WebAuthnError({
215
- message: `${globalThis.location.hostname} is an invalid domain`,
216
- code: 'ERROR_INVALID_DOMAIN',
217
- cause: error,
218
- });
219
- }
220
- else if (publicKey.rp.id !== effectiveDomain) {
221
- // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 8)
222
- return new WebAuthnError({
223
- message: `The RP ID "${publicKey.rp.id}" is invalid for this domain`,
224
- code: 'ERROR_INVALID_RP_ID',
225
- cause: error,
226
- });
227
- }
228
- }
229
- else if (error.name === 'TypeError') {
230
- if (publicKey.user.id.byteLength < 1 || publicKey.user.id.byteLength > 64) {
231
- // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 5)
232
- return new WebAuthnError({
233
- message: 'User ID was not between 1 and 64 characters',
234
- code: 'ERROR_INVALID_USER_ID_LENGTH',
235
- cause: error,
236
- });
237
- }
238
- }
239
- else if (error.name === 'UnknownError') {
240
- // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 1)
241
- // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 8)
242
- return new WebAuthnError({
243
- message: 'The authenticator was unable to process the specified options, or could not create a new credential',
244
- code: 'ERROR_AUTHENTICATOR_GENERAL_ERROR',
245
- cause: error,
246
- });
247
- }
248
- return error;
249
- }
250
-
251
- class BaseWebAuthnAbortService {
252
- constructor() {
253
- Object.defineProperty(this, "controller", {
254
- enumerable: true,
255
- configurable: true,
256
- writable: true,
257
- value: void 0
258
- });
259
- }
260
- createNewAbortSignal() {
261
- // Abort any existing calls to navigator.credentials.create() or navigator.credentials.get()
262
- if (this.controller) {
263
- const abortError = new Error('Cancelling existing WebAuthn API call for new one');
264
- abortError.name = 'AbortError';
265
- this.controller.abort(abortError);
266
- }
267
- const newController = new AbortController();
268
- this.controller = newController;
269
- return newController.signal;
270
- }
271
- cancelCeremony() {
272
- if (this.controller) {
273
- const abortError = new Error('Manually cancelling existing WebAuthn API call');
274
- abortError.name = 'AbortError';
275
- this.controller.abort(abortError);
276
- this.controller = undefined;
277
- }
278
- }
279
- }
280
- /**
281
- * A service singleton to help ensure that only a single WebAuthn ceremony is active at a time.
282
- *
283
- * Users of **@simplewebauthn/browser** shouldn't typically need to use this, but it can help e.g.
284
- * developers building projects that use client-side routing to better control the behavior of
285
- * their UX in response to router navigation events.
286
- */
287
- const WebAuthnAbortService = new BaseWebAuthnAbortService();
288
-
289
- const attachments = ['cross-platform', 'platform'];
290
- /**
291
- * If possible coerce a `string` value into a known `AuthenticatorAttachment`
292
- */
293
- function toAuthenticatorAttachment(attachment) {
294
- if (!attachment) {
295
- return;
296
- }
297
- if (attachments.indexOf(attachment) < 0) {
298
- return;
299
- }
300
- return attachment;
301
- }
302
-
303
- /**
304
- * Begin authenticator "registration" via WebAuthn attestation
305
- *
306
- * @param optionsJSON Output from **@simplewebauthn/server**'s `generateRegistrationOptions()`
307
- * @param useAutoRegister (Optional) Try to silently create a passkey with the password manager that the user just signed in with. Defaults to `false`.
308
- */
309
- async function startRegistration(options) {
310
- // @ts-ignore: Intentionally check for old call structure to warn about improper API call
311
- if (!options.optionsJSON && options.challenge) {
312
- console.warn('startRegistration() was not called correctly. It will try to continue with the provided options, but this call should be refactored to use the expected call structure instead. See https://simplewebauthn.dev/docs/packages/browser#typeerror-cannot-read-properties-of-undefined-reading-challenge for more information.');
313
- // @ts-ignore: Reassign the options, passed in as a positional argument, to the expected variable
314
- options = { optionsJSON: options };
315
- }
316
- const { optionsJSON, useAutoRegister = false } = options;
317
- if (!browserSupportsWebAuthn()) {
318
- throw new Error('WebAuthn is not supported in this browser');
319
- }
320
- // We need to convert some values to Uint8Arrays before passing the credentials to the navigator
321
- const publicKey = {
322
- ...optionsJSON,
323
- challenge: base64URLStringToBuffer(optionsJSON.challenge),
324
- user: {
325
- ...optionsJSON.user,
326
- id: base64URLStringToBuffer(optionsJSON.user.id),
327
- },
328
- excludeCredentials: optionsJSON.excludeCredentials?.map(toPublicKeyCredentialDescriptor),
329
- };
330
- // Prepare options for `.create()`
331
- const createOptions = {};
332
- /**
333
- * Try to use conditional create to register a passkey for the user with the password manager
334
- * the user just used to authenticate with. The user won't be shown any prominent UI by the
335
- * browser.
336
- */
337
- if (useAutoRegister) {
338
- // @ts-ignore: `mediation` doesn't yet exist on CredentialCreationOptions but it's possible as of Sept 2024
339
- createOptions.mediation = 'conditional';
340
- }
341
- // Finalize options
342
- createOptions.publicKey = publicKey;
343
- // Set up the ability to cancel this request if the user attempts another
344
- createOptions.signal = WebAuthnAbortService.createNewAbortSignal();
345
- // Wait for the user to complete attestation
346
- let credential;
347
- try {
348
- credential = (await navigator.credentials.create(createOptions));
349
- }
350
- catch (err) {
351
- throw identifyRegistrationError({ error: err, options: createOptions });
352
- }
353
- if (!credential) {
354
- throw new Error('Registration was not completed');
355
- }
356
- const { id, rawId, response, type } = credential;
357
- // Continue to play it safe with `getTransports()` for now, even when L3 types say it's required
358
- let transports = undefined;
359
- if (typeof response.getTransports === 'function') {
360
- transports = response.getTransports();
361
- }
362
- // L3 says this is required, but browser and webview support are still not guaranteed.
363
- let responsePublicKeyAlgorithm = undefined;
364
- if (typeof response.getPublicKeyAlgorithm === 'function') {
365
- try {
366
- responsePublicKeyAlgorithm = response.getPublicKeyAlgorithm();
367
- }
368
- catch (error) {
369
- warnOnBrokenImplementation('getPublicKeyAlgorithm()', error);
370
- }
371
- }
372
- let responsePublicKey = undefined;
373
- if (typeof response.getPublicKey === 'function') {
374
- try {
375
- const _publicKey = response.getPublicKey();
376
- if (_publicKey !== null) {
377
- responsePublicKey = bufferToBase64URLString(_publicKey);
378
- }
379
- }
380
- catch (error) {
381
- warnOnBrokenImplementation('getPublicKey()', error);
382
- }
383
- }
384
- // L3 says this is required, but browser and webview support are still not guaranteed.
385
- let responseAuthenticatorData;
386
- if (typeof response.getAuthenticatorData === 'function') {
387
- try {
388
- responseAuthenticatorData = bufferToBase64URLString(response.getAuthenticatorData());
389
- }
390
- catch (error) {
391
- warnOnBrokenImplementation('getAuthenticatorData()', error);
392
- }
393
- }
394
- return {
395
- id,
396
- rawId: bufferToBase64URLString(rawId),
397
- response: {
398
- attestationObject: bufferToBase64URLString(response.attestationObject),
399
- clientDataJSON: bufferToBase64URLString(response.clientDataJSON),
400
- transports,
401
- publicKeyAlgorithm: responsePublicKeyAlgorithm,
402
- publicKey: responsePublicKey,
403
- authenticatorData: responseAuthenticatorData,
404
- },
405
- type,
406
- clientExtensionResults: credential.getClientExtensionResults(),
407
- authenticatorAttachment: toAuthenticatorAttachment(credential.authenticatorAttachment),
408
- };
409
- }
410
- /**
411
- * Visibly warn when we detect an issue related to a passkey provider intercepting WebAuthn API
412
- * calls
413
- */
414
- function warnOnBrokenImplementation(methodName, cause) {
415
- console.warn(`The browser extension that intercepted this WebAuthn API call incorrectly implemented ${methodName}. You should report this error to them.\n`, cause);
416
- }
417
-
418
- /**
419
- * Determine if the browser supports conditional UI, so that WebAuthn credentials can
420
- * be shown to the user in the browser's typical password autofill popup.
421
- */
422
- function browserSupportsWebAuthnAutofill() {
423
- if (!browserSupportsWebAuthn()) {
424
- return _browserSupportsWebAuthnAutofillInternals.stubThis(new Promise((resolve) => resolve(false)));
425
- }
426
- /**
427
- * I don't like the `as unknown` here but there's a `declare var PublicKeyCredential` in
428
- * TS' DOM lib that's making it difficult for me to just go `as PublicKeyCredentialFuture` as I
429
- * want. I think I'm fine with this for now since it's _supposed_ to be temporary, until TS types
430
- * have a chance to catch up.
431
- */
432
- const globalPublicKeyCredential = globalThis
433
- .PublicKeyCredential;
434
- if (globalPublicKeyCredential?.isConditionalMediationAvailable === undefined) {
435
- return _browserSupportsWebAuthnAutofillInternals.stubThis(new Promise((resolve) => resolve(false)));
436
- }
437
- return _browserSupportsWebAuthnAutofillInternals.stubThis(globalPublicKeyCredential.isConditionalMediationAvailable());
438
- }
439
- // Make it possible to stub the return value during testing
440
- const _browserSupportsWebAuthnAutofillInternals = {
441
- stubThis: (value) => value,
442
- };
443
-
444
- /**
445
- * Attempt to intuit _why_ an error was raised after calling `navigator.credentials.get()`
446
- */
447
- function identifyAuthenticationError({ error, options, }) {
448
- const { publicKey } = options;
449
- if (!publicKey) {
450
- throw Error('options was missing required publicKey property');
451
- }
452
- if (error.name === 'AbortError') {
453
- if (options.signal instanceof AbortSignal) {
454
- // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 16)
455
- return new WebAuthnError({
456
- message: 'Authentication ceremony was sent an abort signal',
457
- code: 'ERROR_CEREMONY_ABORTED',
458
- cause: error,
459
- });
460
- }
461
- }
462
- else if (error.name === 'NotAllowedError') {
463
- /**
464
- * Pass the error directly through. Platforms are overloading this error beyond what the spec
465
- * defines and we don't want to overwrite potentially useful error messages.
466
- */
467
- return new WebAuthnError({
468
- message: error.message,
469
- code: 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY',
470
- cause: error,
471
- });
472
- }
473
- else if (error.name === 'SecurityError') {
474
- const effectiveDomain = globalThis.location.hostname;
475
- if (!isValidDomain(effectiveDomain)) {
476
- // https://www.w3.org/TR/webauthn-2/#sctn-discover-from-external-source (Step 5)
477
- return new WebAuthnError({
478
- message: `${globalThis.location.hostname} is an invalid domain`,
479
- code: 'ERROR_INVALID_DOMAIN',
480
- cause: error,
481
- });
482
- }
483
- else if (publicKey.rpId !== effectiveDomain) {
484
- // https://www.w3.org/TR/webauthn-2/#sctn-discover-from-external-source (Step 6)
485
- return new WebAuthnError({
486
- message: `The RP ID "${publicKey.rpId}" is invalid for this domain`,
487
- code: 'ERROR_INVALID_RP_ID',
488
- cause: error,
489
- });
490
- }
491
- }
492
- else if (error.name === 'UnknownError') {
493
- // https://www.w3.org/TR/webauthn-2/#sctn-op-get-assertion (Step 1)
494
- // https://www.w3.org/TR/webauthn-2/#sctn-op-get-assertion (Step 12)
495
- return new WebAuthnError({
496
- message: 'The authenticator was unable to process the specified options, or could not create a new assertion signature',
497
- code: 'ERROR_AUTHENTICATOR_GENERAL_ERROR',
498
- cause: error,
499
- });
500
- }
501
- return error;
502
- }
503
-
504
- /**
505
- * Begin authenticator "login" via WebAuthn assertion
506
- *
507
- * @param optionsJSON Output from **@simplewebauthn/server**'s `generateAuthenticationOptions()`
508
- * @param useBrowserAutofill (Optional) Initialize conditional UI to enable logging in via browser autofill prompts. Defaults to `false`.
509
- * @param verifyBrowserAutofillInput (Optional) Ensure a suitable `<input>` element is present when `useBrowserAutofill` is `true`. Defaults to `true`.
510
- */
511
- async function startAuthentication(options) {
512
- // @ts-ignore: Intentionally check for old call structure to warn about improper API call
513
- if (!options.optionsJSON && options.challenge) {
514
- console.warn('startAuthentication() was not called correctly. It will try to continue with the provided options, but this call should be refactored to use the expected call structure instead. See https://simplewebauthn.dev/docs/packages/browser#typeerror-cannot-read-properties-of-undefined-reading-challenge for more information.');
515
- // @ts-ignore: Reassign the options, passed in as a positional argument, to the expected variable
516
- options = { optionsJSON: options };
517
- }
518
- const { optionsJSON, useBrowserAutofill = false, verifyBrowserAutofillInput = true, } = options;
519
- if (!browserSupportsWebAuthn()) {
520
- throw new Error('WebAuthn is not supported in this browser');
521
- }
522
- // We need to avoid passing empty array to avoid blocking retrieval
523
- // of public key
524
- let allowCredentials;
525
- if (optionsJSON.allowCredentials?.length !== 0) {
526
- allowCredentials = optionsJSON.allowCredentials?.map(toPublicKeyCredentialDescriptor);
527
- }
528
- // We need to convert some values to Uint8Arrays before passing the credentials to the navigator
529
- const publicKey = {
530
- ...optionsJSON,
531
- challenge: base64URLStringToBuffer(optionsJSON.challenge),
532
- allowCredentials,
533
- };
534
- // Prepare options for `.get()`
535
- const getOptions = {};
536
- /**
537
- * Set up the page to prompt the user to select a credential for authentication via the browser's
538
- * input autofill mechanism.
539
- */
540
- if (useBrowserAutofill) {
541
- if (!(await browserSupportsWebAuthnAutofill())) {
542
- throw Error('Browser does not support WebAuthn autofill');
543
- }
544
- // Check for an <input> with "webauthn" in its `autocomplete` attribute
545
- const eligibleInputs = document.querySelectorAll("input[autocomplete$='webauthn']");
546
- // WebAuthn autofill requires at least one valid input
547
- if (eligibleInputs.length < 1 && verifyBrowserAutofillInput) {
548
- throw Error('No <input> with "webauthn" as the only or last value in its `autocomplete` attribute was detected');
549
- }
550
- // `CredentialMediationRequirement` doesn't know about "conditional" yet as of
551
- // typescript@4.6.3
552
- getOptions.mediation = 'conditional';
553
- // Conditional UI requires an empty allow list
554
- publicKey.allowCredentials = [];
555
- }
556
- // Finalize options
557
- getOptions.publicKey = publicKey;
558
- // Set up the ability to cancel this request if the user attempts another
559
- getOptions.signal = WebAuthnAbortService.createNewAbortSignal();
560
- // Wait for the user to complete assertion
561
- let credential;
562
- try {
563
- credential = (await navigator.credentials.get(getOptions));
564
- }
565
- catch (err) {
566
- throw identifyAuthenticationError({ error: err, options: getOptions });
567
- }
568
- if (!credential) {
569
- throw new Error('Authentication was not completed');
570
- }
571
- const { id, rawId, response, type } = credential;
572
- let userHandle = undefined;
573
- if (response.userHandle) {
574
- userHandle = bufferToBase64URLString(response.userHandle);
575
- }
576
- // Convert values to base64 to make it easier to send back to the server
577
- return {
578
- id,
579
- rawId: bufferToBase64URLString(rawId),
580
- response: {
581
- authenticatorData: bufferToBase64URLString(response.authenticatorData),
582
- clientDataJSON: bufferToBase64URLString(response.clientDataJSON),
583
- signature: bufferToBase64URLString(response.signature),
584
- userHandle,
585
- },
586
- type,
587
- clientExtensionResults: credential.getClientExtensionResults(),
588
- authenticatorAttachment: toAuthenticatorAttachment(credential.authenticatorAttachment),
589
- };
590
- }
1
+ import { o as object, i as email, s as string, l as literal, r as record, f as any, n as number, g as array, h as _enum, u as uuid, j as boolean, v as date, w as url, t as prettifyError } from './schemas-C2VqNPFY.js';
2
+ import { v as push, F as copy_payload, G as assign_payload, V as bind_props, x as pop, W as spread_props, T as spread_attributes, X as attr_class, y as escape_html, Y as clsx } from './index-CNBqpMEu.js';
591
3
 
592
4
  const types$1 = {
593
5
  'application/prs.cww': ['cww'],
@@ -1673,209 +1085,680 @@ const types = {
1673
1085
  };
1674
1086
  Object.freeze(types);
1675
1087
 
1676
- var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
1677
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
1678
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
1679
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
1680
- };
1681
- var _Mime_extensionToType, _Mime_typeToExtension, _Mime_typeToExtensions;
1682
- class Mime {
1683
- constructor(...args) {
1684
- _Mime_extensionToType.set(this, new Map());
1685
- _Mime_typeToExtension.set(this, new Map());
1686
- _Mime_typeToExtensions.set(this, new Map());
1687
- for (const arg of args) {
1688
- this.define(arg);
1088
+ var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
1089
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
1090
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
1091
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
1092
+ };
1093
+ var _Mime_extensionToType, _Mime_typeToExtension, _Mime_typeToExtensions;
1094
+ class Mime {
1095
+ constructor(...args) {
1096
+ _Mime_extensionToType.set(this, new Map());
1097
+ _Mime_typeToExtension.set(this, new Map());
1098
+ _Mime_typeToExtensions.set(this, new Map());
1099
+ for (const arg of args) {
1100
+ this.define(arg);
1101
+ }
1102
+ }
1103
+ define(typeMap, force = false) {
1104
+ for (let [type, extensions] of Object.entries(typeMap)) {
1105
+ type = type.toLowerCase();
1106
+ extensions = extensions.map((ext) => ext.toLowerCase());
1107
+ if (!__classPrivateFieldGet(this, _Mime_typeToExtensions, "f").has(type)) {
1108
+ __classPrivateFieldGet(this, _Mime_typeToExtensions, "f").set(type, new Set());
1109
+ }
1110
+ const allExtensions = __classPrivateFieldGet(this, _Mime_typeToExtensions, "f").get(type);
1111
+ let first = true;
1112
+ for (let extension of extensions) {
1113
+ const starred = extension.startsWith('*');
1114
+ extension = starred ? extension.slice(1) : extension;
1115
+ allExtensions?.add(extension);
1116
+ if (first) {
1117
+ __classPrivateFieldGet(this, _Mime_typeToExtension, "f").set(type, extension);
1118
+ }
1119
+ first = false;
1120
+ if (starred)
1121
+ continue;
1122
+ const currentType = __classPrivateFieldGet(this, _Mime_extensionToType, "f").get(extension);
1123
+ if (currentType && currentType != type && !force) {
1124
+ throw new Error(`"${type} -> ${extension}" conflicts with "${currentType} -> ${extension}". Pass \`force=true\` to override this definition.`);
1125
+ }
1126
+ __classPrivateFieldGet(this, _Mime_extensionToType, "f").set(extension, type);
1127
+ }
1128
+ }
1129
+ return this;
1130
+ }
1131
+ getType(path) {
1132
+ if (typeof path !== 'string')
1133
+ return null;
1134
+ const last = path.replace(/^.*[/\\]/s, '').toLowerCase();
1135
+ const ext = last.replace(/^.*\./s, '').toLowerCase();
1136
+ const hasPath = last.length < path.length;
1137
+ const hasDot = ext.length < last.length - 1;
1138
+ if (!hasDot && hasPath)
1139
+ return null;
1140
+ return __classPrivateFieldGet(this, _Mime_extensionToType, "f").get(ext) ?? null;
1141
+ }
1142
+ getExtension(type) {
1143
+ if (typeof type !== 'string')
1144
+ return null;
1145
+ type = type?.split?.(';')[0];
1146
+ return ((type && __classPrivateFieldGet(this, _Mime_typeToExtension, "f").get(type.trim().toLowerCase())) ?? null);
1147
+ }
1148
+ getAllExtensions(type) {
1149
+ if (typeof type !== 'string')
1150
+ return null;
1151
+ return __classPrivateFieldGet(this, _Mime_typeToExtensions, "f").get(type.toLowerCase()) ?? null;
1152
+ }
1153
+ _freeze() {
1154
+ this.define = () => {
1155
+ throw new Error('define() not allowed for built-in Mime objects. See https://github.com/broofa/mime/blob/main/README.md#custom-mime-instances');
1156
+ };
1157
+ Object.freeze(this);
1158
+ for (const extensions of __classPrivateFieldGet(this, _Mime_typeToExtensions, "f").values()) {
1159
+ Object.freeze(extensions);
1160
+ }
1161
+ return this;
1162
+ }
1163
+ _getTestState() {
1164
+ return {
1165
+ types: __classPrivateFieldGet(this, _Mime_extensionToType, "f"),
1166
+ extensions: __classPrivateFieldGet(this, _Mime_typeToExtension, "f"),
1167
+ };
1168
+ }
1169
+ }
1170
+ _Mime_extensionToType = new WeakMap(), _Mime_typeToExtension = new WeakMap(), _Mime_typeToExtensions = new WeakMap();
1171
+
1172
+ new Mime(types, types$1)._freeze();
1173
+
1174
+ /**
1175
+ * Convert the given array buffer into a Base64URL-encoded string. Ideal for converting various
1176
+ * credential response ArrayBuffers to string for sending back to the server as JSON.
1177
+ *
1178
+ * Helper method to compliment `base64URLStringToBuffer`
1179
+ */
1180
+ function bufferToBase64URLString(buffer) {
1181
+ const bytes = new Uint8Array(buffer);
1182
+ let str = '';
1183
+ for (const charCode of bytes) {
1184
+ str += String.fromCharCode(charCode);
1185
+ }
1186
+ const base64String = btoa(str);
1187
+ return base64String.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
1188
+ }
1189
+
1190
+ /**
1191
+ * Convert from a Base64URL-encoded string to an Array Buffer. Best used when converting a
1192
+ * credential ID from a JSON string to an ArrayBuffer, like in allowCredentials or
1193
+ * excludeCredentials
1194
+ *
1195
+ * Helper method to compliment `bufferToBase64URLString`
1196
+ */
1197
+ function base64URLStringToBuffer(base64URLString) {
1198
+ // Convert from Base64URL to Base64
1199
+ const base64 = base64URLString.replace(/-/g, '+').replace(/_/g, '/');
1200
+ /**
1201
+ * Pad with '=' until it's a multiple of four
1202
+ * (4 - (85 % 4 = 1) = 3) % 4 = 3 padding
1203
+ * (4 - (86 % 4 = 2) = 2) % 4 = 2 padding
1204
+ * (4 - (87 % 4 = 3) = 1) % 4 = 1 padding
1205
+ * (4 - (88 % 4 = 0) = 4) % 4 = 0 padding
1206
+ */
1207
+ const padLength = (4 - (base64.length % 4)) % 4;
1208
+ const padded = base64.padEnd(base64.length + padLength, '=');
1209
+ // Convert to a binary string
1210
+ const binary = atob(padded);
1211
+ // Convert binary string to buffer
1212
+ const buffer = new ArrayBuffer(binary.length);
1213
+ const bytes = new Uint8Array(buffer);
1214
+ for (let i = 0; i < binary.length; i++) {
1215
+ bytes[i] = binary.charCodeAt(i);
1216
+ }
1217
+ return buffer;
1218
+ }
1219
+
1220
+ /**
1221
+ * Determine if the browser is capable of Webauthn
1222
+ */
1223
+ function browserSupportsWebAuthn() {
1224
+ return _browserSupportsWebAuthnInternals.stubThis(globalThis?.PublicKeyCredential !== undefined &&
1225
+ typeof globalThis.PublicKeyCredential === 'function');
1226
+ }
1227
+ /**
1228
+ * Make it possible to stub the return value during testing
1229
+ * @ignore Don't include this in docs output
1230
+ */
1231
+ const _browserSupportsWebAuthnInternals = {
1232
+ stubThis: (value) => value,
1233
+ };
1234
+
1235
+ function toPublicKeyCredentialDescriptor(descriptor) {
1236
+ const { id } = descriptor;
1237
+ return {
1238
+ ...descriptor,
1239
+ id: base64URLStringToBuffer(id),
1240
+ /**
1241
+ * `descriptor.transports` is an array of our `AuthenticatorTransportFuture` that includes newer
1242
+ * transports that TypeScript's DOM lib is ignorant of. Convince TS that our list of transports
1243
+ * are fine to pass to WebAuthn since browsers will recognize the new value.
1244
+ */
1245
+ transports: descriptor.transports,
1246
+ };
1247
+ }
1248
+
1249
+ /**
1250
+ * A simple test to determine if a hostname is a properly-formatted domain name
1251
+ *
1252
+ * A "valid domain" is defined here: https://url.spec.whatwg.org/#valid-domain
1253
+ *
1254
+ * Regex sourced from here:
1255
+ * https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch08s15.html
1256
+ */
1257
+ function isValidDomain(hostname) {
1258
+ return (
1259
+ // Consider localhost valid as well since it's okay wrt Secure Contexts
1260
+ hostname === 'localhost' ||
1261
+ /^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(hostname));
1262
+ }
1263
+
1264
+ /**
1265
+ * A custom Error used to return a more nuanced error detailing _why_ one of the eight documented
1266
+ * errors in the spec was raised after calling `navigator.credentials.create()` or
1267
+ * `navigator.credentials.get()`:
1268
+ *
1269
+ * - `AbortError`
1270
+ * - `ConstraintError`
1271
+ * - `InvalidStateError`
1272
+ * - `NotAllowedError`
1273
+ * - `NotSupportedError`
1274
+ * - `SecurityError`
1275
+ * - `TypeError`
1276
+ * - `UnknownError`
1277
+ *
1278
+ * Error messages were determined through investigation of the spec to determine under which
1279
+ * scenarios a given error would be raised.
1280
+ */
1281
+ class WebAuthnError extends Error {
1282
+ constructor({ message, code, cause, name, }) {
1283
+ // @ts-ignore: help Rollup understand that `cause` is okay to set
1284
+ super(message, { cause });
1285
+ Object.defineProperty(this, "code", {
1286
+ enumerable: true,
1287
+ configurable: true,
1288
+ writable: true,
1289
+ value: void 0
1290
+ });
1291
+ this.name = name ?? cause.name;
1292
+ this.code = code;
1293
+ }
1294
+ }
1295
+
1296
+ /**
1297
+ * Attempt to intuit _why_ an error was raised after calling `navigator.credentials.create()`
1298
+ */
1299
+ function identifyRegistrationError({ error, options, }) {
1300
+ const { publicKey } = options;
1301
+ if (!publicKey) {
1302
+ throw Error('options was missing required publicKey property');
1303
+ }
1304
+ if (error.name === 'AbortError') {
1305
+ if (options.signal instanceof AbortSignal) {
1306
+ // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 16)
1307
+ return new WebAuthnError({
1308
+ message: 'Registration ceremony was sent an abort signal',
1309
+ code: 'ERROR_CEREMONY_ABORTED',
1310
+ cause: error,
1311
+ });
1689
1312
  }
1690
1313
  }
1691
- define(typeMap, force = false) {
1692
- for (let [type, extensions] of Object.entries(typeMap)) {
1693
- type = type.toLowerCase();
1694
- extensions = extensions.map((ext) => ext.toLowerCase());
1695
- if (!__classPrivateFieldGet(this, _Mime_typeToExtensions, "f").has(type)) {
1696
- __classPrivateFieldGet(this, _Mime_typeToExtensions, "f").set(type, new Set());
1697
- }
1698
- const allExtensions = __classPrivateFieldGet(this, _Mime_typeToExtensions, "f").get(type);
1699
- let first = true;
1700
- for (let extension of extensions) {
1701
- const starred = extension.startsWith('*');
1702
- extension = starred ? extension.slice(1) : extension;
1703
- allExtensions?.add(extension);
1704
- if (first) {
1705
- __classPrivateFieldGet(this, _Mime_typeToExtension, "f").set(type, extension);
1706
- }
1707
- first = false;
1708
- if (starred)
1709
- continue;
1710
- const currentType = __classPrivateFieldGet(this, _Mime_extensionToType, "f").get(extension);
1711
- if (currentType && currentType != type && !force) {
1712
- throw new Error(`"${type} -> ${extension}" conflicts with "${currentType} -> ${extension}". Pass \`force=true\` to override this definition.`);
1713
- }
1714
- __classPrivateFieldGet(this, _Mime_extensionToType, "f").set(extension, type);
1715
- }
1314
+ else if (error.name === 'ConstraintError') {
1315
+ if (publicKey.authenticatorSelection?.requireResidentKey === true) {
1316
+ // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 4)
1317
+ return new WebAuthnError({
1318
+ message: 'Discoverable credentials were required but no available authenticator supported it',
1319
+ code: 'ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT',
1320
+ cause: error,
1321
+ });
1716
1322
  }
1717
- return this;
1323
+ else if (
1324
+ // @ts-ignore: `mediation` doesn't yet exist on CredentialCreationOptions but it's possible as of Sept 2024
1325
+ options.mediation === 'conditional' &&
1326
+ publicKey.authenticatorSelection?.userVerification === 'required') {
1327
+ // https://w3c.github.io/webauthn/#sctn-createCredential (Step 22.4)
1328
+ return new WebAuthnError({
1329
+ message: 'User verification was required during automatic registration but it could not be performed',
1330
+ code: 'ERROR_AUTO_REGISTER_USER_VERIFICATION_FAILURE',
1331
+ cause: error,
1332
+ });
1333
+ }
1334
+ else if (publicKey.authenticatorSelection?.userVerification === 'required') {
1335
+ // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 5)
1336
+ return new WebAuthnError({
1337
+ message: 'User verification was required but no available authenticator supported it',
1338
+ code: 'ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT',
1339
+ cause: error,
1340
+ });
1341
+ }
1342
+ }
1343
+ else if (error.name === 'InvalidStateError') {
1344
+ // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 20)
1345
+ // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 3)
1346
+ return new WebAuthnError({
1347
+ message: 'The authenticator was previously registered',
1348
+ code: 'ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED',
1349
+ cause: error,
1350
+ });
1351
+ }
1352
+ else if (error.name === 'NotAllowedError') {
1353
+ /**
1354
+ * Pass the error directly through. Platforms are overloading this error beyond what the spec
1355
+ * defines and we don't want to overwrite potentially useful error messages.
1356
+ */
1357
+ return new WebAuthnError({
1358
+ message: error.message,
1359
+ code: 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY',
1360
+ cause: error,
1361
+ });
1362
+ }
1363
+ else if (error.name === 'NotSupportedError') {
1364
+ const validPubKeyCredParams = publicKey.pubKeyCredParams.filter((param) => param.type === 'public-key');
1365
+ if (validPubKeyCredParams.length === 0) {
1366
+ // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 10)
1367
+ return new WebAuthnError({
1368
+ message: 'No entry in pubKeyCredParams was of type "public-key"',
1369
+ code: 'ERROR_MALFORMED_PUBKEYCREDPARAMS',
1370
+ cause: error,
1371
+ });
1372
+ }
1373
+ // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 2)
1374
+ return new WebAuthnError({
1375
+ message: 'No available authenticator supported any of the specified pubKeyCredParams algorithms',
1376
+ code: 'ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG',
1377
+ cause: error,
1378
+ });
1379
+ }
1380
+ else if (error.name === 'SecurityError') {
1381
+ const effectiveDomain = globalThis.location.hostname;
1382
+ if (!isValidDomain(effectiveDomain)) {
1383
+ // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 7)
1384
+ return new WebAuthnError({
1385
+ message: `${globalThis.location.hostname} is an invalid domain`,
1386
+ code: 'ERROR_INVALID_DOMAIN',
1387
+ cause: error,
1388
+ });
1389
+ }
1390
+ else if (publicKey.rp.id !== effectiveDomain) {
1391
+ // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 8)
1392
+ return new WebAuthnError({
1393
+ message: `The RP ID "${publicKey.rp.id}" is invalid for this domain`,
1394
+ code: 'ERROR_INVALID_RP_ID',
1395
+ cause: error,
1396
+ });
1397
+ }
1398
+ }
1399
+ else if (error.name === 'TypeError') {
1400
+ if (publicKey.user.id.byteLength < 1 || publicKey.user.id.byteLength > 64) {
1401
+ // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 5)
1402
+ return new WebAuthnError({
1403
+ message: 'User ID was not between 1 and 64 characters',
1404
+ code: 'ERROR_INVALID_USER_ID_LENGTH',
1405
+ cause: error,
1406
+ });
1407
+ }
1408
+ }
1409
+ else if (error.name === 'UnknownError') {
1410
+ // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 1)
1411
+ // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 8)
1412
+ return new WebAuthnError({
1413
+ message: 'The authenticator was unable to process the specified options, or could not create a new credential',
1414
+ code: 'ERROR_AUTHENTICATOR_GENERAL_ERROR',
1415
+ cause: error,
1416
+ });
1417
+ }
1418
+ return error;
1419
+ }
1420
+
1421
+ class BaseWebAuthnAbortService {
1422
+ constructor() {
1423
+ Object.defineProperty(this, "controller", {
1424
+ enumerable: true,
1425
+ configurable: true,
1426
+ writable: true,
1427
+ value: void 0
1428
+ });
1429
+ }
1430
+ createNewAbortSignal() {
1431
+ // Abort any existing calls to navigator.credentials.create() or navigator.credentials.get()
1432
+ if (this.controller) {
1433
+ const abortError = new Error('Cancelling existing WebAuthn API call for new one');
1434
+ abortError.name = 'AbortError';
1435
+ this.controller.abort(abortError);
1436
+ }
1437
+ const newController = new AbortController();
1438
+ this.controller = newController;
1439
+ return newController.signal;
1440
+ }
1441
+ cancelCeremony() {
1442
+ if (this.controller) {
1443
+ const abortError = new Error('Manually cancelling existing WebAuthn API call');
1444
+ abortError.name = 'AbortError';
1445
+ this.controller.abort(abortError);
1446
+ this.controller = undefined;
1447
+ }
1448
+ }
1449
+ }
1450
+ /**
1451
+ * A service singleton to help ensure that only a single WebAuthn ceremony is active at a time.
1452
+ *
1453
+ * Users of **@simplewebauthn/browser** shouldn't typically need to use this, but it can help e.g.
1454
+ * developers building projects that use client-side routing to better control the behavior of
1455
+ * their UX in response to router navigation events.
1456
+ */
1457
+ const WebAuthnAbortService = new BaseWebAuthnAbortService();
1458
+
1459
+ const attachments = ['cross-platform', 'platform'];
1460
+ /**
1461
+ * If possible coerce a `string` value into a known `AuthenticatorAttachment`
1462
+ */
1463
+ function toAuthenticatorAttachment(attachment) {
1464
+ if (!attachment) {
1465
+ return;
1466
+ }
1467
+ if (attachments.indexOf(attachment) < 0) {
1468
+ return;
1469
+ }
1470
+ return attachment;
1471
+ }
1472
+
1473
+ /**
1474
+ * Begin authenticator "registration" via WebAuthn attestation
1475
+ *
1476
+ * @param optionsJSON Output from **@simplewebauthn/server**'s `generateRegistrationOptions()`
1477
+ * @param useAutoRegister (Optional) Try to silently create a passkey with the password manager that the user just signed in with. Defaults to `false`.
1478
+ */
1479
+ async function startRegistration(options) {
1480
+ // @ts-ignore: Intentionally check for old call structure to warn about improper API call
1481
+ if (!options.optionsJSON && options.challenge) {
1482
+ console.warn('startRegistration() was not called correctly. It will try to continue with the provided options, but this call should be refactored to use the expected call structure instead. See https://simplewebauthn.dev/docs/packages/browser#typeerror-cannot-read-properties-of-undefined-reading-challenge for more information.');
1483
+ // @ts-ignore: Reassign the options, passed in as a positional argument, to the expected variable
1484
+ options = { optionsJSON: options };
1485
+ }
1486
+ const { optionsJSON, useAutoRegister = false } = options;
1487
+ if (!browserSupportsWebAuthn()) {
1488
+ throw new Error('WebAuthn is not supported in this browser');
1489
+ }
1490
+ // We need to convert some values to Uint8Arrays before passing the credentials to the navigator
1491
+ const publicKey = {
1492
+ ...optionsJSON,
1493
+ challenge: base64URLStringToBuffer(optionsJSON.challenge),
1494
+ user: {
1495
+ ...optionsJSON.user,
1496
+ id: base64URLStringToBuffer(optionsJSON.user.id),
1497
+ },
1498
+ excludeCredentials: optionsJSON.excludeCredentials?.map(toPublicKeyCredentialDescriptor),
1499
+ };
1500
+ // Prepare options for `.create()`
1501
+ const createOptions = {};
1502
+ /**
1503
+ * Try to use conditional create to register a passkey for the user with the password manager
1504
+ * the user just used to authenticate with. The user won't be shown any prominent UI by the
1505
+ * browser.
1506
+ */
1507
+ if (useAutoRegister) {
1508
+ // @ts-ignore: `mediation` doesn't yet exist on CredentialCreationOptions but it's possible as of Sept 2024
1509
+ createOptions.mediation = 'conditional';
1510
+ }
1511
+ // Finalize options
1512
+ createOptions.publicKey = publicKey;
1513
+ // Set up the ability to cancel this request if the user attempts another
1514
+ createOptions.signal = WebAuthnAbortService.createNewAbortSignal();
1515
+ // Wait for the user to complete attestation
1516
+ let credential;
1517
+ try {
1518
+ credential = (await navigator.credentials.create(createOptions));
1718
1519
  }
1719
- getType(path) {
1720
- if (typeof path !== 'string')
1721
- return null;
1722
- const last = path.replace(/^.*[/\\]/s, '').toLowerCase();
1723
- const ext = last.replace(/^.*\./s, '').toLowerCase();
1724
- const hasPath = last.length < path.length;
1725
- const hasDot = ext.length < last.length - 1;
1726
- if (!hasDot && hasPath)
1727
- return null;
1728
- return __classPrivateFieldGet(this, _Mime_extensionToType, "f").get(ext) ?? null;
1520
+ catch (err) {
1521
+ throw identifyRegistrationError({ error: err, options: createOptions });
1729
1522
  }
1730
- getExtension(type) {
1731
- if (typeof type !== 'string')
1732
- return null;
1733
- type = type?.split?.(';')[0];
1734
- return ((type && __classPrivateFieldGet(this, _Mime_typeToExtension, "f").get(type.trim().toLowerCase())) ?? null);
1523
+ if (!credential) {
1524
+ throw new Error('Registration was not completed');
1735
1525
  }
1736
- getAllExtensions(type) {
1737
- if (typeof type !== 'string')
1738
- return null;
1739
- return __classPrivateFieldGet(this, _Mime_typeToExtensions, "f").get(type.toLowerCase()) ?? null;
1526
+ const { id, rawId, response, type } = credential;
1527
+ // Continue to play it safe with `getTransports()` for now, even when L3 types say it's required
1528
+ let transports = undefined;
1529
+ if (typeof response.getTransports === 'function') {
1530
+ transports = response.getTransports();
1740
1531
  }
1741
- _freeze() {
1742
- this.define = () => {
1743
- throw new Error('define() not allowed for built-in Mime objects. See https://github.com/broofa/mime/blob/main/README.md#custom-mime-instances');
1744
- };
1745
- Object.freeze(this);
1746
- for (const extensions of __classPrivateFieldGet(this, _Mime_typeToExtensions, "f").values()) {
1747
- Object.freeze(extensions);
1532
+ // L3 says this is required, but browser and webview support are still not guaranteed.
1533
+ let responsePublicKeyAlgorithm = undefined;
1534
+ if (typeof response.getPublicKeyAlgorithm === 'function') {
1535
+ try {
1536
+ responsePublicKeyAlgorithm = response.getPublicKeyAlgorithm();
1537
+ }
1538
+ catch (error) {
1539
+ warnOnBrokenImplementation('getPublicKeyAlgorithm()', error);
1748
1540
  }
1749
- return this;
1750
1541
  }
1751
- _getTestState() {
1752
- return {
1753
- types: __classPrivateFieldGet(this, _Mime_extensionToType, "f"),
1754
- extensions: __classPrivateFieldGet(this, _Mime_typeToExtension, "f"),
1755
- };
1542
+ let responsePublicKey = undefined;
1543
+ if (typeof response.getPublicKey === 'function') {
1544
+ try {
1545
+ const _publicKey = response.getPublicKey();
1546
+ if (_publicKey !== null) {
1547
+ responsePublicKey = bufferToBase64URLString(_publicKey);
1548
+ }
1549
+ }
1550
+ catch (error) {
1551
+ warnOnBrokenImplementation('getPublicKey()', error);
1552
+ }
1553
+ }
1554
+ // L3 says this is required, but browser and webview support are still not guaranteed.
1555
+ let responseAuthenticatorData;
1556
+ if (typeof response.getAuthenticatorData === 'function') {
1557
+ try {
1558
+ responseAuthenticatorData = bufferToBase64URLString(response.getAuthenticatorData());
1559
+ }
1560
+ catch (error) {
1561
+ warnOnBrokenImplementation('getAuthenticatorData()', error);
1562
+ }
1756
1563
  }
1564
+ return {
1565
+ id,
1566
+ rawId: bufferToBase64URLString(rawId),
1567
+ response: {
1568
+ attestationObject: bufferToBase64URLString(response.attestationObject),
1569
+ clientDataJSON: bufferToBase64URLString(response.clientDataJSON),
1570
+ transports,
1571
+ publicKeyAlgorithm: responsePublicKeyAlgorithm,
1572
+ publicKey: responsePublicKey,
1573
+ authenticatorData: responseAuthenticatorData,
1574
+ },
1575
+ type,
1576
+ clientExtensionResults: credential.getClientExtensionResults(),
1577
+ authenticatorAttachment: toAuthenticatorAttachment(credential.authenticatorAttachment),
1578
+ };
1579
+ }
1580
+ /**
1581
+ * Visibly warn when we detect an issue related to a passkey provider intercepting WebAuthn API
1582
+ * calls
1583
+ */
1584
+ function warnOnBrokenImplementation(methodName, cause) {
1585
+ console.warn(`The browser extension that intercepted this WebAuthn API call incorrectly implemented ${methodName}. You should report this error to them.\n`, cause);
1757
1586
  }
1758
- _Mime_extensionToType = new WeakMap(), _Mime_typeToExtension = new WeakMap(), _Mime_typeToExtensions = new WeakMap();
1759
-
1760
- new Mime(types, types$1)._freeze();
1761
1587
 
1762
- function Dialog($$payload, $$props) {
1763
- push();
1764
- let { children, dialog = void 0, $$slots, $$events, ...rest } = $$props;
1765
- $$payload.out.push(`<dialog${spread_attributes({ ...rest }, "svelte-1yuzruq")}>`);
1766
- children($$payload);
1767
- $$payload.out.push(`<!----></dialog>`);
1768
- bind_props($$props, { dialog });
1769
- pop();
1588
+ /**
1589
+ * Determine if the browser supports conditional UI, so that WebAuthn credentials can
1590
+ * be shown to the user in the browser's typical password autofill popup.
1591
+ */
1592
+ function browserSupportsWebAuthnAutofill() {
1593
+ if (!browserSupportsWebAuthn()) {
1594
+ return _browserSupportsWebAuthnAutofillInternals.stubThis(new Promise((resolve) => resolve(false)));
1595
+ }
1596
+ /**
1597
+ * I don't like the `as unknown` here but there's a `declare var PublicKeyCredential` in
1598
+ * TS' DOM lib that's making it difficult for me to just go `as PublicKeyCredentialFuture` as I
1599
+ * want. I think I'm fine with this for now since it's _supposed_ to be temporary, until TS types
1600
+ * have a chance to catch up.
1601
+ */
1602
+ const globalPublicKeyCredential = globalThis
1603
+ .PublicKeyCredential;
1604
+ if (globalPublicKeyCredential?.isConditionalMediationAvailable === undefined) {
1605
+ return _browserSupportsWebAuthnAutofillInternals.stubThis(new Promise((resolve) => resolve(false)));
1606
+ }
1607
+ return _browserSupportsWebAuthnAutofillInternals.stubThis(globalPublicKeyCredential.isConditionalMediationAvailable());
1770
1608
  }
1771
- function FormDialog($$payload, $$props) {
1772
- push();
1773
- let {
1774
- children,
1775
- dialog = void 0,
1776
- submitText = "Submit",
1777
- cancel = () => {
1778
- },
1779
- submit = (data) => Promise.resolve(),
1780
- pageMode = false,
1781
- submitDanger = false,
1782
- header,
1783
- footer,
1784
- $$slots,
1785
- $$events,
1786
- ...rest
1787
- /** Change the text displayed for the submit button */
1788
- /** Basically a callback for when the dialog is canceled */
1789
- /** Called on submission, this should do the actual submission */
1790
- /** Whether to display the dialog as a full-page form */
1791
- } = $$props;
1792
- function onclose(e) {
1793
- e.preventDefault();
1794
- cancel();
1795
- }
1796
- function submitButton($$payload2) {
1797
- $$payload2.out.push(`<button type="submit"${attr_class(clsx(["submit", submitDanger && "danger"]))}>${escape_html(submitText)}</button>`);
1798
- }
1799
- let $$settled = true;
1800
- let $$inner_payload;
1801
- function $$render_inner($$payload2) {
1802
- Dialog($$payload2, spread_props([
1803
- { onclose },
1804
- rest,
1805
- {
1806
- get dialog() {
1807
- return dialog;
1808
- },
1809
- set dialog($$value) {
1810
- dialog = $$value;
1811
- $$settled = false;
1812
- },
1813
- children: ($$payload3) => {
1814
- header?.($$payload3);
1815
- $$payload3.out.push(`<!----> <form class="main" method="dialog">`);
1816
- {
1817
- $$payload3.out.push("<!--[!-->");
1818
- }
1819
- $$payload3.out.push(`<!--]--> `);
1820
- children($$payload3);
1821
- $$payload3.out.push(`<!----> `);
1822
- if (pageMode) {
1823
- $$payload3.out.push("<!--[-->");
1824
- submitButton($$payload3);
1825
- } else {
1826
- $$payload3.out.push("<!--[!-->");
1827
- $$payload3.out.push(`<div class="actions svelte-p6pltw"><button type="button">Cancel</button> `);
1828
- submitButton($$payload3);
1829
- $$payload3.out.push(`<!----></div>`);
1830
- }
1831
- $$payload3.out.push(`<!--]--></form> `);
1832
- footer?.($$payload3);
1833
- $$payload3.out.push(`<!---->`);
1834
- },
1835
- $$slots: { default: true }
1836
- }
1837
- ]));
1838
- }
1839
- do {
1840
- $$settled = true;
1841
- $$inner_payload = copy_payload($$payload);
1842
- $$render_inner($$inner_payload);
1843
- } while (!$$settled);
1844
- assign_payload($$payload, $$inner_payload);
1845
- bind_props($$props, { dialog });
1846
- pop();
1609
+ // Make it possible to stub the return value during testing
1610
+ const _browserSupportsWebAuthnAutofillInternals = {
1611
+ stubThis: (value) => value,
1612
+ };
1613
+
1614
+ /**
1615
+ * Attempt to intuit _why_ an error was raised after calling `navigator.credentials.get()`
1616
+ */
1617
+ function identifyAuthenticationError({ error, options, }) {
1618
+ const { publicKey } = options;
1619
+ if (!publicKey) {
1620
+ throw Error('options was missing required publicKey property');
1621
+ }
1622
+ if (error.name === 'AbortError') {
1623
+ if (options.signal instanceof AbortSignal) {
1624
+ // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 16)
1625
+ return new WebAuthnError({
1626
+ message: 'Authentication ceremony was sent an abort signal',
1627
+ code: 'ERROR_CEREMONY_ABORTED',
1628
+ cause: error,
1629
+ });
1630
+ }
1631
+ }
1632
+ else if (error.name === 'NotAllowedError') {
1633
+ /**
1634
+ * Pass the error directly through. Platforms are overloading this error beyond what the spec
1635
+ * defines and we don't want to overwrite potentially useful error messages.
1636
+ */
1637
+ return new WebAuthnError({
1638
+ message: error.message,
1639
+ code: 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY',
1640
+ cause: error,
1641
+ });
1642
+ }
1643
+ else if (error.name === 'SecurityError') {
1644
+ const effectiveDomain = globalThis.location.hostname;
1645
+ if (!isValidDomain(effectiveDomain)) {
1646
+ // https://www.w3.org/TR/webauthn-2/#sctn-discover-from-external-source (Step 5)
1647
+ return new WebAuthnError({
1648
+ message: `${globalThis.location.hostname} is an invalid domain`,
1649
+ code: 'ERROR_INVALID_DOMAIN',
1650
+ cause: error,
1651
+ });
1652
+ }
1653
+ else if (publicKey.rpId !== effectiveDomain) {
1654
+ // https://www.w3.org/TR/webauthn-2/#sctn-discover-from-external-source (Step 6)
1655
+ return new WebAuthnError({
1656
+ message: `The RP ID "${publicKey.rpId}" is invalid for this domain`,
1657
+ code: 'ERROR_INVALID_RP_ID',
1658
+ cause: error,
1659
+ });
1660
+ }
1661
+ }
1662
+ else if (error.name === 'UnknownError') {
1663
+ // https://www.w3.org/TR/webauthn-2/#sctn-op-get-assertion (Step 1)
1664
+ // https://www.w3.org/TR/webauthn-2/#sctn-op-get-assertion (Step 12)
1665
+ return new WebAuthnError({
1666
+ message: 'The authenticator was unable to process the specified options, or could not create a new assertion signature',
1667
+ code: 'ERROR_AUTHENTICATOR_GENERAL_ERROR',
1668
+ cause: error,
1669
+ });
1670
+ }
1671
+ return error;
1847
1672
  }
1848
- let prefix = "/api/";
1849
- async function fetchAPI(method, endpoint, data, ...params) {
1850
- const options = {
1851
- method,
1852
- headers: {
1853
- "Content-Type": "application/json",
1854
- Accept: "application/json"
1673
+
1674
+ /**
1675
+ * Begin authenticator "login" via WebAuthn assertion
1676
+ *
1677
+ * @param optionsJSON Output from **@simplewebauthn/server**'s `generateAuthenticationOptions()`
1678
+ * @param useBrowserAutofill (Optional) Initialize conditional UI to enable logging in via browser autofill prompts. Defaults to `false`.
1679
+ * @param verifyBrowserAutofillInput (Optional) Ensure a suitable `<input>` element is present when `useBrowserAutofill` is `true`. Defaults to `true`.
1680
+ */
1681
+ async function startAuthentication(options) {
1682
+ // @ts-ignore: Intentionally check for old call structure to warn about improper API call
1683
+ if (!options.optionsJSON && options.challenge) {
1684
+ console.warn('startAuthentication() was not called correctly. It will try to continue with the provided options, but this call should be refactored to use the expected call structure instead. See https://simplewebauthn.dev/docs/packages/browser#typeerror-cannot-read-properties-of-undefined-reading-challenge for more information.');
1685
+ // @ts-ignore: Reassign the options, passed in as a positional argument, to the expected variable
1686
+ options = { optionsJSON: options };
1855
1687
  }
1856
- };
1857
- if (method !== "GET" && method !== "HEAD")
1858
- options.body = JSON.stringify(data);
1859
- const parts = [];
1860
- for (const part of endpoint.split("/")) {
1861
- if (!part.startsWith(":")) {
1862
- parts.push(part);
1863
- continue;
1688
+ const { optionsJSON, useBrowserAutofill = false, verifyBrowserAutofillInput = true, } = options;
1689
+ if (!browserSupportsWebAuthn()) {
1690
+ throw new Error('WebAuthn is not supported in this browser');
1864
1691
  }
1865
- const value = params.shift();
1866
- if (!value)
1867
- throw new Error(`Missing parameter "${part.slice(1)}"`);
1868
- parts.push(value);
1869
- }
1870
- const response = await fetch(prefix + parts.join("/"), options);
1871
- if (!response.headers.get("Content-Type")?.includes("application/json")) {
1872
- throw new Error(`Unexpected response type: ${response.headers.get("Content-Type")}`);
1873
- }
1874
- const json = await response.json().catch(() => ({ message: "Unknown server error (invalid JSON response)" }));
1875
- if (!response.ok)
1876
- throw new Error(json.message);
1877
- return json;
1692
+ // We need to avoid passing empty array to avoid blocking retrieval
1693
+ // of public key
1694
+ let allowCredentials;
1695
+ if (optionsJSON.allowCredentials?.length !== 0) {
1696
+ allowCredentials = optionsJSON.allowCredentials?.map(toPublicKeyCredentialDescriptor);
1697
+ }
1698
+ // We need to convert some values to Uint8Arrays before passing the credentials to the navigator
1699
+ const publicKey = {
1700
+ ...optionsJSON,
1701
+ challenge: base64URLStringToBuffer(optionsJSON.challenge),
1702
+ allowCredentials,
1703
+ };
1704
+ // Prepare options for `.get()`
1705
+ const getOptions = {};
1706
+ /**
1707
+ * Set up the page to prompt the user to select a credential for authentication via the browser's
1708
+ * input autofill mechanism.
1709
+ */
1710
+ if (useBrowserAutofill) {
1711
+ if (!(await browserSupportsWebAuthnAutofill())) {
1712
+ throw Error('Browser does not support WebAuthn autofill');
1713
+ }
1714
+ // Check for an <input> with "webauthn" in its `autocomplete` attribute
1715
+ const eligibleInputs = document.querySelectorAll("input[autocomplete$='webauthn']");
1716
+ // WebAuthn autofill requires at least one valid input
1717
+ if (eligibleInputs.length < 1 && verifyBrowserAutofillInput) {
1718
+ throw Error('No <input> with "webauthn" as the only or last value in its `autocomplete` attribute was detected');
1719
+ }
1720
+ // `CredentialMediationRequirement` doesn't know about "conditional" yet as of
1721
+ // typescript@4.6.3
1722
+ getOptions.mediation = 'conditional';
1723
+ // Conditional UI requires an empty allow list
1724
+ publicKey.allowCredentials = [];
1725
+ }
1726
+ // Finalize options
1727
+ getOptions.publicKey = publicKey;
1728
+ // Set up the ability to cancel this request if the user attempts another
1729
+ getOptions.signal = WebAuthnAbortService.createNewAbortSignal();
1730
+ // Wait for the user to complete assertion
1731
+ let credential;
1732
+ try {
1733
+ credential = (await navigator.credentials.get(getOptions));
1734
+ }
1735
+ catch (err) {
1736
+ throw identifyAuthenticationError({ error: err, options: getOptions });
1737
+ }
1738
+ if (!credential) {
1739
+ throw new Error('Authentication was not completed');
1740
+ }
1741
+ const { id, rawId, response, type } = credential;
1742
+ let userHandle = undefined;
1743
+ if (response.userHandle) {
1744
+ userHandle = bufferToBase64URLString(response.userHandle);
1745
+ }
1746
+ // Convert values to base64 to make it easier to send back to the server
1747
+ return {
1748
+ id,
1749
+ rawId: bufferToBase64URLString(rawId),
1750
+ response: {
1751
+ authenticatorData: bufferToBase64URLString(response.authenticatorData),
1752
+ clientDataJSON: bufferToBase64URLString(response.clientDataJSON),
1753
+ signature: bufferToBase64URLString(response.signature),
1754
+ userHandle,
1755
+ },
1756
+ type,
1757
+ clientExtensionResults: credential.getClientExtensionResults(),
1758
+ authenticatorAttachment: toAuthenticatorAttachment(credential.authenticatorAttachment),
1759
+ };
1878
1760
  }
1761
+
1879
1762
  var Permission;
1880
1763
  (function(Permission2) {
1881
1764
  Permission2[Permission2["None"] = 0] = "None";
@@ -1965,6 +1848,37 @@ function getUserImage(user) {
1965
1848
  <text x="23" y="28" style="font-family:sans-serif;font-weight:bold;" fill="white">${user.name.replaceAll(/\W/g, "")[0]}</text>
1966
1849
  </svg>`.replaceAll(/[\t\n]/g, "");
1967
1850
  }
1851
+ let prefix = "/api/";
1852
+ async function fetchAPI(method, endpoint, data, ...params) {
1853
+ const options = {
1854
+ method,
1855
+ headers: {
1856
+ "Content-Type": "application/json",
1857
+ Accept: "application/json"
1858
+ }
1859
+ };
1860
+ if (method !== "GET" && method !== "HEAD")
1861
+ options.body = JSON.stringify(data);
1862
+ const parts = [];
1863
+ for (const part of endpoint.split("/")) {
1864
+ if (!part.startsWith(":")) {
1865
+ parts.push(part);
1866
+ continue;
1867
+ }
1868
+ const value = params.shift();
1869
+ if (!value)
1870
+ throw new Error(`Missing parameter "${part.slice(1)}"`);
1871
+ parts.push(value);
1872
+ }
1873
+ const response = await fetch(prefix + parts.join("/"), options);
1874
+ if (!response.headers.get("Content-Type")?.includes("application/json")) {
1875
+ throw new Error(`Unexpected response type: ${response.headers.get("Content-Type")}`);
1876
+ }
1877
+ const json = await response.json().catch(() => ({ message: "Unknown server error (invalid JSON response)" }));
1878
+ if (!response.ok)
1879
+ throw new Error(json.message);
1880
+ return json;
1881
+ }
1968
1882
  async function login(userId) {
1969
1883
  const options = await fetchAPI("OPTIONS", "users/:id/auth", { type: "login" }, userId);
1970
1884
  const response = await startAuthentication({ optionsJSON: options });
@@ -1982,21 +1896,6 @@ async function loginByEmail(email) {
1982
1896
  });
1983
1897
  return await login(userId);
1984
1898
  }
1985
- async function getCurrentSession() {
1986
- const result = await fetchAPI("GET", "session");
1987
- result.created = new Date(result.created);
1988
- result.expires = new Date(result.expires);
1989
- return result;
1990
- }
1991
- async function getSessions(userId) {
1992
- _checkId(userId);
1993
- const result = await fetchAPI("GET", "users/:id/sessions", {}, userId);
1994
- for (const session of result) {
1995
- session.created = new Date(session.created);
1996
- session.expires = new Date(session.expires);
1997
- }
1998
- return result;
1999
- }
2000
1899
  async function logout(userId, ...sessionId) {
2001
1900
  _checkId(userId);
2002
1901
  const result = await fetchAPI("DELETE", "users/:id/sessions", { id: sessionId }, userId);
@@ -2058,19 +1957,6 @@ async function deleteUser(userId) {
2058
1957
  result.emailVerified = new Date(result.emailVerified);
2059
1958
  return result;
2060
1959
  }
2061
- async function emailVerificationEnabled(userId) {
2062
- _checkId(userId);
2063
- const { enabled } = await fetchAPI("OPTIONS", "users/:id/verify_email", {}, userId);
2064
- return enabled;
2065
- }
2066
- async function getPasskeys(userId) {
2067
- _checkId(userId);
2068
- const result = await fetchAPI("GET", "users/:id/passkeys", {}, userId);
2069
- for (const passkey of result) {
2070
- passkey.createdAt = new Date(passkey.createdAt);
2071
- }
2072
- return result;
2073
- }
2074
1960
  async function updatePasskey(passkeyId, data) {
2075
1961
  return await fetchAPI("PATCH", "passkeys/:id", data, passkeyId);
2076
1962
  }
@@ -2078,5 +1964,92 @@ async function deletePasskey(passkeyId) {
2078
1964
  return await fetchAPI("DELETE", "passkeys/:id", {}, passkeyId);
2079
1965
  }
2080
1966
 
2081
- export { FormDialog as F, getPasskeys as a, getSessions as b, getUserImage as c, deleteUser as d, emailVerificationEnabled as e, deletePasskey as f, getCurrentSession as g, logoutAll as h, updateUser as i, loginByEmail as j, logoutCurrentSession as k, logout as l, register as r, updatePasskey as u };
2082
- //# sourceMappingURL=user-BxKya_IG.js.map
1967
+ function Dialog($$payload, $$props) {
1968
+ push();
1969
+ let { children, dialog = void 0, $$slots, $$events, ...rest } = $$props;
1970
+ $$payload.out.push(`<dialog${spread_attributes({ ...rest }, "svelte-1yuzruq")}>`);
1971
+ children($$payload);
1972
+ $$payload.out.push(`<!----></dialog>`);
1973
+ bind_props($$props, { dialog });
1974
+ pop();
1975
+ }
1976
+ function FormDialog($$payload, $$props) {
1977
+ push();
1978
+ let {
1979
+ children,
1980
+ dialog = void 0,
1981
+ submitText = "Submit",
1982
+ cancel = () => {
1983
+ },
1984
+ submit = (data) => Promise.resolve(),
1985
+ pageMode = false,
1986
+ submitDanger = false,
1987
+ header,
1988
+ footer,
1989
+ $$slots,
1990
+ $$events,
1991
+ ...rest
1992
+ /** Change the text displayed for the submit button */
1993
+ /** Basically a callback for when the dialog is canceled */
1994
+ /** Called on submission, this should do the actual submission */
1995
+ /** Whether to display the dialog as a full-page form */
1996
+ } = $$props;
1997
+ function onclose(e) {
1998
+ e.preventDefault();
1999
+ cancel();
2000
+ }
2001
+ function submitButton($$payload2) {
2002
+ $$payload2.out.push(`<button type="submit"${attr_class(clsx(["submit", submitDanger && "danger"]))}>${escape_html(submitText)}</button>`);
2003
+ }
2004
+ let $$settled = true;
2005
+ let $$inner_payload;
2006
+ function $$render_inner($$payload2) {
2007
+ Dialog($$payload2, spread_props([
2008
+ { onclose },
2009
+ rest,
2010
+ {
2011
+ get dialog() {
2012
+ return dialog;
2013
+ },
2014
+ set dialog($$value) {
2015
+ dialog = $$value;
2016
+ $$settled = false;
2017
+ },
2018
+ children: ($$payload3) => {
2019
+ header?.($$payload3);
2020
+ $$payload3.out.push(`<!----> <form class="main" method="dialog">`);
2021
+ {
2022
+ $$payload3.out.push("<!--[!-->");
2023
+ }
2024
+ $$payload3.out.push(`<!--]--> `);
2025
+ children($$payload3);
2026
+ $$payload3.out.push(`<!----> `);
2027
+ if (pageMode) {
2028
+ $$payload3.out.push("<!--[-->");
2029
+ submitButton($$payload3);
2030
+ } else {
2031
+ $$payload3.out.push("<!--[!-->");
2032
+ $$payload3.out.push(`<div class="actions svelte-p6pltw"><button type="button">Cancel</button> `);
2033
+ submitButton($$payload3);
2034
+ $$payload3.out.push(`<!----></div>`);
2035
+ }
2036
+ $$payload3.out.push(`<!--]--></form> `);
2037
+ footer?.($$payload3);
2038
+ $$payload3.out.push(`<!---->`);
2039
+ },
2040
+ $$slots: { default: true }
2041
+ }
2042
+ ]));
2043
+ }
2044
+ do {
2045
+ $$settled = true;
2046
+ $$inner_payload = copy_payload($$payload);
2047
+ $$render_inner($$inner_payload);
2048
+ } while (!$$settled);
2049
+ assign_payload($$payload, $$inner_payload);
2050
+ bind_props($$props, { dialog });
2051
+ pop();
2052
+ }
2053
+
2054
+ export { FormDialog as F, deletePasskey as a, logoutAll as b, updateUser as c, deleteUser as d, loginByEmail as e, logoutCurrentSession as f, getUserImage as g, logout as l, register as r, updatePasskey as u };
2055
+ //# sourceMappingURL=FormDialog-qGzPcWE3.js.map