@supabase/gotrue-js 2.73.0-rc.3 → 2.79.1-canary.0

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 (108) hide show
  1. package/README.md +96 -4
  2. package/dist/main/GoTrueAdminApi.js.map +1 -1
  3. package/dist/main/GoTrueClient.d.ts +21 -2
  4. package/dist/main/GoTrueClient.d.ts.map +1 -1
  5. package/dist/main/GoTrueClient.js +61 -37
  6. package/dist/main/GoTrueClient.js.map +1 -1
  7. package/dist/main/lib/base64url.d.ts +3 -2
  8. package/dist/main/lib/base64url.d.ts.map +1 -1
  9. package/dist/main/lib/base64url.js +10 -11
  10. package/dist/main/lib/base64url.js.map +1 -1
  11. package/dist/main/lib/error-codes.d.ts +1 -1
  12. package/dist/main/lib/error-codes.d.ts.map +1 -1
  13. package/dist/main/lib/errors.d.ts.map +1 -1
  14. package/dist/main/lib/errors.js +7 -7
  15. package/dist/main/lib/errors.js.map +1 -1
  16. package/dist/main/lib/fetch.d.ts +2 -2
  17. package/dist/main/lib/fetch.d.ts.map +1 -1
  18. package/dist/main/lib/fetch.js +8 -9
  19. package/dist/main/lib/fetch.js.map +1 -1
  20. package/dist/main/lib/helpers.d.ts +3 -2
  21. package/dist/main/lib/helpers.d.ts.map +1 -1
  22. package/dist/main/lib/helpers.js +34 -24
  23. package/dist/main/lib/helpers.js.map +1 -1
  24. package/dist/main/lib/local-storage.js +1 -2
  25. package/dist/main/lib/local-storage.js.map +1 -1
  26. package/dist/main/lib/locks.js +3 -3
  27. package/dist/main/lib/locks.js.map +1 -1
  28. package/dist/main/lib/polyfills.js +1 -2
  29. package/dist/main/lib/polyfills.js.map +1 -1
  30. package/dist/main/lib/types.d.ts +233 -112
  31. package/dist/main/lib/types.d.ts.map +1 -1
  32. package/dist/main/lib/types.js +3 -2
  33. package/dist/main/lib/types.js.map +1 -1
  34. package/dist/main/lib/version.d.ts +1 -1
  35. package/dist/main/lib/version.d.ts.map +1 -1
  36. package/dist/main/lib/version.js +7 -1
  37. package/dist/main/lib/version.js.map +1 -1
  38. package/dist/main/lib/web3/ethereum.d.ts +9 -9
  39. package/dist/main/lib/web3/ethereum.d.ts.map +1 -1
  40. package/dist/main/lib/web3/ethereum.js +4 -5
  41. package/dist/main/lib/web3/ethereum.js.map +1 -1
  42. package/dist/main/lib/web3/solana.d.ts +4 -4
  43. package/dist/main/lib/web3/solana.d.ts.map +1 -1
  44. package/dist/main/lib/webauthn.d.ts +274 -0
  45. package/dist/main/lib/webauthn.d.ts.map +1 -0
  46. package/dist/main/lib/webauthn.dom.d.ts +583 -0
  47. package/dist/main/lib/webauthn.dom.d.ts.map +1 -0
  48. package/dist/main/lib/webauthn.dom.js +4 -0
  49. package/dist/main/lib/webauthn.dom.js.map +1 -0
  50. package/dist/main/lib/webauthn.errors.d.ts +80 -0
  51. package/dist/main/lib/webauthn.errors.d.ts.map +1 -0
  52. package/dist/main/lib/webauthn.errors.js +265 -0
  53. package/dist/main/lib/webauthn.errors.js.map +1 -0
  54. package/dist/main/lib/webauthn.js +702 -0
  55. package/dist/main/lib/webauthn.js.map +1 -0
  56. package/dist/module/GoTrueAdminApi.js.map +1 -1
  57. package/dist/module/GoTrueClient.d.ts +21 -2
  58. package/dist/module/GoTrueClient.d.ts.map +1 -1
  59. package/dist/module/GoTrueClient.js +68 -43
  60. package/dist/module/GoTrueClient.js.map +1 -1
  61. package/dist/module/lib/base64url.d.ts +3 -2
  62. package/dist/module/lib/base64url.d.ts.map +1 -1
  63. package/dist/module/lib/base64url.js.map +1 -1
  64. package/dist/module/lib/error-codes.d.ts +1 -1
  65. package/dist/module/lib/error-codes.d.ts.map +1 -1
  66. package/dist/module/lib/errors.d.ts.map +1 -1
  67. package/dist/module/lib/fetch.d.ts +2 -2
  68. package/dist/module/lib/fetch.d.ts.map +1 -1
  69. package/dist/module/lib/fetch.js.map +1 -1
  70. package/dist/module/lib/helpers.d.ts +3 -2
  71. package/dist/module/lib/helpers.d.ts.map +1 -1
  72. package/dist/module/lib/helpers.js.map +1 -1
  73. package/dist/module/lib/locks.js.map +1 -1
  74. package/dist/module/lib/polyfills.js.map +1 -1
  75. package/dist/module/lib/types.d.ts +233 -112
  76. package/dist/module/lib/types.d.ts.map +1 -1
  77. package/dist/module/lib/types.js +2 -1
  78. package/dist/module/lib/types.js.map +1 -1
  79. package/dist/module/lib/version.d.ts +1 -1
  80. package/dist/module/lib/version.d.ts.map +1 -1
  81. package/dist/module/lib/version.js +7 -1
  82. package/dist/module/lib/version.js.map +1 -1
  83. package/dist/module/lib/web3/ethereum.d.ts +9 -9
  84. package/dist/module/lib/web3/ethereum.d.ts.map +1 -1
  85. package/dist/module/lib/web3/ethereum.js.map +1 -1
  86. package/dist/module/lib/web3/solana.d.ts +4 -4
  87. package/dist/module/lib/web3/solana.d.ts.map +1 -1
  88. package/dist/module/lib/webauthn.d.ts +274 -0
  89. package/dist/module/lib/webauthn.d.ts.map +1 -0
  90. package/dist/module/lib/webauthn.dom.d.ts +583 -0
  91. package/dist/module/lib/webauthn.dom.d.ts.map +1 -0
  92. package/dist/module/lib/webauthn.dom.js +3 -0
  93. package/dist/module/lib/webauthn.dom.js.map +1 -0
  94. package/dist/module/lib/webauthn.errors.d.ts +80 -0
  95. package/dist/module/lib/webauthn.errors.d.ts.map +1 -0
  96. package/dist/module/lib/webauthn.errors.js +257 -0
  97. package/dist/module/lib/webauthn.errors.js.map +1 -0
  98. package/dist/module/lib/webauthn.js +685 -0
  99. package/dist/module/lib/webauthn.js.map +1 -0
  100. package/package.json +13 -34
  101. package/src/GoTrueClient.ts +218 -69
  102. package/src/lib/base64url.ts +4 -2
  103. package/src/lib/helpers.ts +2 -1
  104. package/src/lib/types.ts +212 -33
  105. package/src/lib/version.ts +7 -1
  106. package/src/lib/webauthn.dom.ts +636 -0
  107. package/src/lib/webauthn.errors.ts +317 -0
  108. package/src/lib/webauthn.ts +929 -0
@@ -0,0 +1,80 @@
1
+ import { StrictOmit } from './types';
2
+ import { PublicKeyCredentialCreationOptionsFuture, PublicKeyCredentialRequestOptionsFuture } from './webauthn.dom';
3
+ /**
4
+ * A custom Error used to return a more nuanced error detailing _why_ one of the eight documented
5
+ * errors in the spec was raised after calling `navigator.credentials.create()` or
6
+ * `navigator.credentials.get()`:
7
+ *
8
+ * - `AbortError`
9
+ * - `ConstraintError`
10
+ * - `InvalidStateError`
11
+ * - `NotAllowedError`
12
+ * - `NotSupportedError`
13
+ * - `SecurityError`
14
+ * - `TypeError`
15
+ * - `UnknownError`
16
+ *
17
+ * Error messages were determined through investigation of the spec to determine under which
18
+ * scenarios a given error would be raised.
19
+ */
20
+ export declare class WebAuthnError extends Error {
21
+ code: WebAuthnErrorCode;
22
+ protected __isWebAuthnError: boolean;
23
+ constructor({ message, code, cause, name, }: {
24
+ message: string;
25
+ code: WebAuthnErrorCode;
26
+ cause?: Error | unknown;
27
+ name?: string;
28
+ });
29
+ }
30
+ /**
31
+ * Error class for unknown WebAuthn errors.
32
+ * Wraps unexpected errors that don't match known WebAuthn error conditions.
33
+ */
34
+ export declare class WebAuthnUnknownError extends WebAuthnError {
35
+ originalError: unknown;
36
+ constructor(message: string, originalError: unknown);
37
+ }
38
+ /**
39
+ * Type guard to check if an error is a WebAuthnError.
40
+ * @param {unknown} error - The error to check
41
+ * @returns {boolean} True if the error is a WebAuthnError
42
+ */
43
+ export declare function isWebAuthnError(error: unknown): error is WebAuthnError;
44
+ /**
45
+ * Error codes for WebAuthn operations.
46
+ * These codes provide specific information about why a WebAuthn ceremony failed.
47
+ * @see {@link https://w3c.github.io/webauthn/#sctn-defined-errors W3C WebAuthn Spec - Defined Errors}
48
+ */
49
+ export type WebAuthnErrorCode = 'ERROR_CEREMONY_ABORTED' | 'ERROR_INVALID_DOMAIN' | 'ERROR_INVALID_RP_ID' | 'ERROR_INVALID_USER_ID_LENGTH' | 'ERROR_MALFORMED_PUBKEYCREDPARAMS' | 'ERROR_AUTHENTICATOR_GENERAL_ERROR' | 'ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT' | 'ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT' | 'ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED' | 'ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG' | 'ERROR_AUTO_REGISTER_USER_VERIFICATION_FAILURE' | 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY';
50
+ /**
51
+ * Attempt to intuit _why_ an error was raised after calling `navigator.credentials.create()`.
52
+ * Maps browser errors to specific WebAuthn error codes for better debugging.
53
+ * @param {Object} params - Error identification parameters
54
+ * @param {Error} params.error - The error thrown by the browser
55
+ * @param {CredentialCreationOptions} params.options - The options passed to credentials.create()
56
+ * @returns {WebAuthnError} A WebAuthnError with a specific error code
57
+ * @see {@link https://w3c.github.io/webauthn/#sctn-createCredential W3C WebAuthn Spec - Create Credential}
58
+ */
59
+ export declare function identifyRegistrationError({ error, options, }: {
60
+ error: Error;
61
+ options: StrictOmit<CredentialCreationOptions, 'publicKey'> & {
62
+ publicKey: PublicKeyCredentialCreationOptionsFuture;
63
+ };
64
+ }): WebAuthnError;
65
+ /**
66
+ * Attempt to intuit _why_ an error was raised after calling `navigator.credentials.get()`.
67
+ * Maps browser errors to specific WebAuthn error codes for better debugging.
68
+ * @param {Object} params - Error identification parameters
69
+ * @param {Error} params.error - The error thrown by the browser
70
+ * @param {CredentialRequestOptions} params.options - The options passed to credentials.get()
71
+ * @returns {WebAuthnError} A WebAuthnError with a specific error code
72
+ * @see {@link https://w3c.github.io/webauthn/#sctn-getAssertion W3C WebAuthn Spec - Get Assertion}
73
+ */
74
+ export declare function identifyAuthenticationError({ error, options, }: {
75
+ error: Error;
76
+ options: StrictOmit<CredentialRequestOptions, 'publicKey'> & {
77
+ publicKey: PublicKeyCredentialRequestOptionsFuture;
78
+ };
79
+ }): WebAuthnError;
80
+ //# sourceMappingURL=webauthn.errors.d.ts.map
@@ -0,0 +1 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Aa,CA8HhB;AAED;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CAAC,EAC1C,KAAK,EACL,OAAO,GACR,EAAE;IACD,KAAK,EAAE,KAAK,CAAA;IACZ,OAAO,EAAE,UAAU,CAAC,wBAAwB,EAAE,WAAW,CAAC,GAAG;QAC3D,SAAS,EAAE,uCAAuC,CAAA;KACnD,CAAA;CACF,GAAG,aAAa,CA2DhB"}
@@ -0,0 +1,265 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.WebAuthnUnknownError = exports.WebAuthnError = void 0;
5
+ exports.isWebAuthnError = isWebAuthnError;
6
+ exports.identifyRegistrationError = identifyRegistrationError;
7
+ exports.identifyAuthenticationError = identifyAuthenticationError;
8
+ const webauthn_1 = require("./webauthn");
9
+ /**
10
+ * A custom Error used to return a more nuanced error detailing _why_ one of the eight documented
11
+ * errors in the spec was raised after calling `navigator.credentials.create()` or
12
+ * `navigator.credentials.get()`:
13
+ *
14
+ * - `AbortError`
15
+ * - `ConstraintError`
16
+ * - `InvalidStateError`
17
+ * - `NotAllowedError`
18
+ * - `NotSupportedError`
19
+ * - `SecurityError`
20
+ * - `TypeError`
21
+ * - `UnknownError`
22
+ *
23
+ * Error messages were determined through investigation of the spec to determine under which
24
+ * scenarios a given error would be raised.
25
+ */
26
+ class WebAuthnError extends Error {
27
+ constructor({ message, code, cause, name, }) {
28
+ var _a;
29
+ // @ts-ignore: help Rollup understand that `cause` is okay to set
30
+ super(message, { cause });
31
+ this.__isWebAuthnError = true;
32
+ this.name = (_a = name !== null && name !== void 0 ? name : (cause instanceof Error ? cause.name : undefined)) !== null && _a !== void 0 ? _a : 'Unknown Error';
33
+ this.code = code;
34
+ }
35
+ }
36
+ exports.WebAuthnError = WebAuthnError;
37
+ /**
38
+ * Error class for unknown WebAuthn errors.
39
+ * Wraps unexpected errors that don't match known WebAuthn error conditions.
40
+ */
41
+ class WebAuthnUnknownError extends WebAuthnError {
42
+ constructor(message, originalError) {
43
+ super({
44
+ code: 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY',
45
+ cause: originalError,
46
+ message,
47
+ });
48
+ this.name = 'WebAuthnUnknownError';
49
+ this.originalError = originalError;
50
+ }
51
+ }
52
+ exports.WebAuthnUnknownError = WebAuthnUnknownError;
53
+ /**
54
+ * Type guard to check if an error is a WebAuthnError.
55
+ * @param {unknown} error - The error to check
56
+ * @returns {boolean} True if the error is a WebAuthnError
57
+ */
58
+ function isWebAuthnError(error) {
59
+ return typeof error === 'object' && error !== null && '__isWebAuthnError' in error;
60
+ }
61
+ /**
62
+ * Attempt to intuit _why_ an error was raised after calling `navigator.credentials.create()`.
63
+ * Maps browser errors to specific WebAuthn error codes for better debugging.
64
+ * @param {Object} params - Error identification parameters
65
+ * @param {Error} params.error - The error thrown by the browser
66
+ * @param {CredentialCreationOptions} params.options - The options passed to credentials.create()
67
+ * @returns {WebAuthnError} A WebAuthnError with a specific error code
68
+ * @see {@link https://w3c.github.io/webauthn/#sctn-createCredential W3C WebAuthn Spec - Create Credential}
69
+ */
70
+ function identifyRegistrationError({ error, options, }) {
71
+ var _a, _b, _c;
72
+ const { publicKey } = options;
73
+ if (!publicKey) {
74
+ throw Error('options was missing required publicKey property');
75
+ }
76
+ if (error.name === 'AbortError') {
77
+ if (options.signal instanceof AbortSignal) {
78
+ // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 16)
79
+ return new WebAuthnError({
80
+ message: 'Registration ceremony was sent an abort signal',
81
+ code: 'ERROR_CEREMONY_ABORTED',
82
+ cause: error,
83
+ });
84
+ }
85
+ }
86
+ else if (error.name === 'ConstraintError') {
87
+ if (((_a = publicKey.authenticatorSelection) === null || _a === void 0 ? void 0 : _a.requireResidentKey) === true) {
88
+ // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 4)
89
+ return new WebAuthnError({
90
+ message: 'Discoverable credentials were required but no available authenticator supported it',
91
+ code: 'ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT',
92
+ cause: error,
93
+ });
94
+ }
95
+ else if (
96
+ // @ts-ignore: `mediation` doesn't yet exist on CredentialCreationOptions but it's possible as of Sept 2024
97
+ options.mediation === 'conditional' &&
98
+ ((_b = publicKey.authenticatorSelection) === null || _b === void 0 ? void 0 : _b.userVerification) === 'required') {
99
+ // https://w3c.github.io/webauthn/#sctn-createCredential (Step 22.4)
100
+ return new WebAuthnError({
101
+ message: 'User verification was required during automatic registration but it could not be performed',
102
+ code: 'ERROR_AUTO_REGISTER_USER_VERIFICATION_FAILURE',
103
+ cause: error,
104
+ });
105
+ }
106
+ else if (((_c = publicKey.authenticatorSelection) === null || _c === void 0 ? void 0 : _c.userVerification) === 'required') {
107
+ // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 5)
108
+ return new WebAuthnError({
109
+ message: 'User verification was required but no available authenticator supported it',
110
+ code: 'ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT',
111
+ cause: error,
112
+ });
113
+ }
114
+ }
115
+ else if (error.name === 'InvalidStateError') {
116
+ // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 20)
117
+ // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 3)
118
+ return new WebAuthnError({
119
+ message: 'The authenticator was previously registered',
120
+ code: 'ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED',
121
+ cause: error,
122
+ });
123
+ }
124
+ else if (error.name === 'NotAllowedError') {
125
+ /**
126
+ * Pass the error directly through. Platforms are overloading this error beyond what the spec
127
+ * defines and we don't want to overwrite potentially useful error messages.
128
+ */
129
+ return new WebAuthnError({
130
+ message: error.message,
131
+ code: 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY',
132
+ cause: error,
133
+ });
134
+ }
135
+ else if (error.name === 'NotSupportedError') {
136
+ const validPubKeyCredParams = publicKey.pubKeyCredParams.filter((param) => param.type === 'public-key');
137
+ if (validPubKeyCredParams.length === 0) {
138
+ // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 10)
139
+ return new WebAuthnError({
140
+ message: 'No entry in pubKeyCredParams was of type "public-key"',
141
+ code: 'ERROR_MALFORMED_PUBKEYCREDPARAMS',
142
+ cause: error,
143
+ });
144
+ }
145
+ // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 2)
146
+ return new WebAuthnError({
147
+ message: 'No available authenticator supported any of the specified pubKeyCredParams algorithms',
148
+ code: 'ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG',
149
+ cause: error,
150
+ });
151
+ }
152
+ else if (error.name === 'SecurityError') {
153
+ const effectiveDomain = window.location.hostname;
154
+ if (!(0, webauthn_1.isValidDomain)(effectiveDomain)) {
155
+ // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 7)
156
+ return new WebAuthnError({
157
+ message: `${window.location.hostname} is an invalid domain`,
158
+ code: 'ERROR_INVALID_DOMAIN',
159
+ cause: error,
160
+ });
161
+ }
162
+ else if (publicKey.rp.id !== effectiveDomain) {
163
+ // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 8)
164
+ return new WebAuthnError({
165
+ message: `The RP ID "${publicKey.rp.id}" is invalid for this domain`,
166
+ code: 'ERROR_INVALID_RP_ID',
167
+ cause: error,
168
+ });
169
+ }
170
+ }
171
+ else if (error.name === 'TypeError') {
172
+ if (publicKey.user.id.byteLength < 1 || publicKey.user.id.byteLength > 64) {
173
+ // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 5)
174
+ return new WebAuthnError({
175
+ message: 'User ID was not between 1 and 64 characters',
176
+ code: 'ERROR_INVALID_USER_ID_LENGTH',
177
+ cause: error,
178
+ });
179
+ }
180
+ }
181
+ else if (error.name === 'UnknownError') {
182
+ // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 1)
183
+ // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 8)
184
+ return new WebAuthnError({
185
+ message: 'The authenticator was unable to process the specified options, or could not create a new credential',
186
+ code: 'ERROR_AUTHENTICATOR_GENERAL_ERROR',
187
+ cause: error,
188
+ });
189
+ }
190
+ return new WebAuthnError({
191
+ message: 'a Non-Webauthn related error has occurred',
192
+ code: 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY',
193
+ cause: error,
194
+ });
195
+ }
196
+ /**
197
+ * Attempt to intuit _why_ an error was raised after calling `navigator.credentials.get()`.
198
+ * Maps browser errors to specific WebAuthn error codes for better debugging.
199
+ * @param {Object} params - Error identification parameters
200
+ * @param {Error} params.error - The error thrown by the browser
201
+ * @param {CredentialRequestOptions} params.options - The options passed to credentials.get()
202
+ * @returns {WebAuthnError} A WebAuthnError with a specific error code
203
+ * @see {@link https://w3c.github.io/webauthn/#sctn-getAssertion W3C WebAuthn Spec - Get Assertion}
204
+ */
205
+ function identifyAuthenticationError({ error, options, }) {
206
+ const { publicKey } = options;
207
+ if (!publicKey) {
208
+ throw Error('options was missing required publicKey property');
209
+ }
210
+ if (error.name === 'AbortError') {
211
+ if (options.signal instanceof AbortSignal) {
212
+ // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 16)
213
+ return new WebAuthnError({
214
+ message: 'Authentication ceremony was sent an abort signal',
215
+ code: 'ERROR_CEREMONY_ABORTED',
216
+ cause: error,
217
+ });
218
+ }
219
+ }
220
+ else if (error.name === 'NotAllowedError') {
221
+ /**
222
+ * Pass the error directly through. Platforms are overloading this error beyond what the spec
223
+ * defines and we don't want to overwrite potentially useful error messages.
224
+ */
225
+ return new WebAuthnError({
226
+ message: error.message,
227
+ code: 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY',
228
+ cause: error,
229
+ });
230
+ }
231
+ else if (error.name === 'SecurityError') {
232
+ const effectiveDomain = window.location.hostname;
233
+ if (!(0, webauthn_1.isValidDomain)(effectiveDomain)) {
234
+ // https://www.w3.org/TR/webauthn-2/#sctn-discover-from-external-source (Step 5)
235
+ return new WebAuthnError({
236
+ message: `${window.location.hostname} is an invalid domain`,
237
+ code: 'ERROR_INVALID_DOMAIN',
238
+ cause: error,
239
+ });
240
+ }
241
+ else if (publicKey.rpId !== effectiveDomain) {
242
+ // https://www.w3.org/TR/webauthn-2/#sctn-discover-from-external-source (Step 6)
243
+ return new WebAuthnError({
244
+ message: `The RP ID "${publicKey.rpId}" is invalid for this domain`,
245
+ code: 'ERROR_INVALID_RP_ID',
246
+ cause: error,
247
+ });
248
+ }
249
+ }
250
+ else if (error.name === 'UnknownError') {
251
+ // https://www.w3.org/TR/webauthn-2/#sctn-op-get-assertion (Step 1)
252
+ // https://www.w3.org/TR/webauthn-2/#sctn-op-get-assertion (Step 12)
253
+ return new WebAuthnError({
254
+ message: 'The authenticator was unable to process the specified options, or could not create a new assertion signature',
255
+ code: 'ERROR_AUTHENTICATOR_GENERAL_ERROR',
256
+ cause: error,
257
+ });
258
+ }
259
+ return new WebAuthnError({
260
+ message: 'a Non-Webauthn related error has occurred',
261
+ code: 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY',
262
+ cause: error,
263
+ });
264
+ }
265
+ //# sourceMappingURL=webauthn.errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webauthn.errors.js","sourceRoot":"","sources":["../../../src/lib/webauthn.errors.ts"],"names":[],"mappings":";AAAA,sDAAsD;;;AAwEtD,0CAEC;AA8BD,8DAsIC;AAWD,kEAmEC;AAzTD,yCAA0C;AAM1C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAa,aAAc,SAAQ,KAAK;IAKtC,YAAY,EACV,OAAO,EACP,IAAI,EACJ,KAAK,EACL,IAAI,GAML;;QACC,iEAAiE;QACjE,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;QAdjB,sBAAiB,GAAG,IAAI,CAAA;QAehC,IAAI,CAAC,IAAI,GAAG,MAAA,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,CAAC,KA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