ngx-webauthn 0.0.2 → 0.2.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.
- package/README.md +922 -412
- package/fesm2022/ngx-webauthn.mjs +1117 -190
- package/fesm2022/ngx-webauthn.mjs.map +1 -1
- package/index.d.ts +841 -165
- package/package.json +2 -1
package/index.d.ts
CHANGED
|
@@ -2,6 +2,99 @@ import { Observable } from 'rxjs';
|
|
|
2
2
|
import * as i0 from '@angular/core';
|
|
3
3
|
import { InjectionToken, Provider } from '@angular/core';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Service-level configuration for WebAuthn operations
|
|
7
|
+
*
|
|
8
|
+
* These interfaces define the global configuration that affects the entire WebAuthn service,
|
|
9
|
+
* including relying party information and default settings.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Required relying party configuration
|
|
14
|
+
*/
|
|
15
|
+
interface RelyingPartyConfig {
|
|
16
|
+
/**
|
|
17
|
+
* Human-readable identifier for the Relying Party
|
|
18
|
+
* @example "ACME Corporation"
|
|
19
|
+
*/
|
|
20
|
+
name: string;
|
|
21
|
+
/**
|
|
22
|
+
* A valid domain string that identifies the Relying Party on whose behalf a given registration or authentication ceremony is being performed
|
|
23
|
+
* @example "login.example.com" or "example.com"
|
|
24
|
+
*/
|
|
25
|
+
id?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Configuration interface for WebAuthn service
|
|
29
|
+
* Now includes required relying party information and advanced options
|
|
30
|
+
*/
|
|
31
|
+
interface WebAuthnConfig {
|
|
32
|
+
/**
|
|
33
|
+
* Required relying party information for WebAuthn operations
|
|
34
|
+
* This is critical for security - must be configured properly for production use
|
|
35
|
+
*/
|
|
36
|
+
relyingParty: RelyingPartyConfig;
|
|
37
|
+
/**
|
|
38
|
+
* Default timeout for WebAuthn operations in milliseconds
|
|
39
|
+
* @default 60000
|
|
40
|
+
*/
|
|
41
|
+
defaultTimeout?: number;
|
|
42
|
+
/**
|
|
43
|
+
* Default public key credential algorithms in order of preference
|
|
44
|
+
* @default [ES256, RS256]
|
|
45
|
+
*/
|
|
46
|
+
defaultAlgorithms?: PublicKeyCredentialParameters[];
|
|
47
|
+
/**
|
|
48
|
+
* Whether to enforce user verification by default
|
|
49
|
+
* @default false
|
|
50
|
+
*/
|
|
51
|
+
enforceUserVerification?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Default attestation conveyance preference
|
|
54
|
+
* @default "none"
|
|
55
|
+
*/
|
|
56
|
+
defaultAttestation?: AttestationConveyancePreference;
|
|
57
|
+
/**
|
|
58
|
+
* Default authenticator selection criteria
|
|
59
|
+
*/
|
|
60
|
+
defaultAuthenticatorSelection?: AuthenticatorSelectionCriteria;
|
|
61
|
+
/**
|
|
62
|
+
* Optional remote endpoints for fetching WebAuthn options from server
|
|
63
|
+
*/
|
|
64
|
+
remoteEndpoints?: {
|
|
65
|
+
/**
|
|
66
|
+
* Absolute URL for fetching PublicKeyCredentialCreationOptionsJSON
|
|
67
|
+
* @example "https://api.example.com/webauthn/registration/options"
|
|
68
|
+
*/
|
|
69
|
+
registration?: string;
|
|
70
|
+
/**
|
|
71
|
+
* Absolute URL for fetching PublicKeyCredentialRequestOptionsJSON
|
|
72
|
+
* @example "https://api.example.com/webauthn/authentication/options"
|
|
73
|
+
*/
|
|
74
|
+
authentication?: string;
|
|
75
|
+
/** HTTP request configuration */
|
|
76
|
+
requestOptions?: {
|
|
77
|
+
/** Network timeout in milliseconds (separate from WebAuthn timeout) */
|
|
78
|
+
timeout?: number;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Default configuration for WebAuthn service
|
|
84
|
+
* Note: relyingParty must be provided by the application
|
|
85
|
+
*/
|
|
86
|
+
declare const DEFAULT_WEBAUTHN_CONFIG: Omit<WebAuthnConfig, 'relyingParty'>;
|
|
87
|
+
/**
|
|
88
|
+
* Injection token for WebAuthn configuration
|
|
89
|
+
*/
|
|
90
|
+
declare const WEBAUTHN_CONFIG: InjectionToken<WebAuthnConfig>;
|
|
91
|
+
/**
|
|
92
|
+
* Creates a complete WebAuthn configuration with required relying party information
|
|
93
|
+
* @param relyingParty Required relying party configuration
|
|
94
|
+
* @param overrides Optional configuration overrides
|
|
95
|
+
*/
|
|
96
|
+
declare function createWebAuthnConfig(relyingParty: RelyingPartyConfig, overrides?: Partial<Omit<WebAuthnConfig, 'relyingParty'>>): WebAuthnConfig;
|
|
97
|
+
|
|
5
98
|
/**
|
|
6
99
|
* Preset for modern, passwordless, cross-device credentials.
|
|
7
100
|
*
|
|
@@ -28,7 +121,7 @@ declare const PASSKEY_PRESET: {
|
|
|
28
121
|
}];
|
|
29
122
|
};
|
|
30
123
|
/**
|
|
31
|
-
* Preset for using
|
|
124
|
+
* Preset for using an external security key as a second factor after a password.
|
|
32
125
|
*
|
|
33
126
|
* Best for: Traditional 2FA scenarios where users already have a password
|
|
34
127
|
* and want to add hardware security key as a second factor.
|
|
@@ -39,7 +132,7 @@ declare const PASSKEY_PRESET: {
|
|
|
39
132
|
* - Favors cross-platform authenticators (USB/NFC security keys)
|
|
40
133
|
* - Credentials typically not synced between devices
|
|
41
134
|
*/
|
|
42
|
-
declare const
|
|
135
|
+
declare const EXTERNAL_SECURITY_KEY_PRESET: {
|
|
43
136
|
readonly authenticatorSelection: {
|
|
44
137
|
readonly residentKey: "discouraged";
|
|
45
138
|
readonly userVerification: "preferred";
|
|
@@ -54,10 +147,10 @@ declare const SECOND_FACTOR_PRESET: {
|
|
|
54
147
|
}];
|
|
55
148
|
};
|
|
56
149
|
/**
|
|
57
|
-
* Preset for high-security, non-synced,
|
|
150
|
+
* Preset for high-security, non-synced, platform authenticator credentials.
|
|
58
151
|
*
|
|
59
152
|
* Best for: High-security scenarios where credentials must stay on a single
|
|
60
|
-
* device and user verification is mandatory.
|
|
153
|
+
* device and user verification is mandatory using built-in platform authenticators.
|
|
61
154
|
*
|
|
62
155
|
* Features:
|
|
63
156
|
* - Requires platform authenticators (built-in biometrics/PIN)
|
|
@@ -65,7 +158,7 @@ declare const SECOND_FACTOR_PRESET: {
|
|
|
65
158
|
* - Requires user verification (biometric/PIN)
|
|
66
159
|
* - Credentials bound to specific device (no syncing)
|
|
67
160
|
*/
|
|
68
|
-
declare const
|
|
161
|
+
declare const PLATFORM_AUTHENTICATOR_PRESET: {
|
|
69
162
|
readonly authenticatorSelection: {
|
|
70
163
|
readonly authenticatorAttachment: "platform";
|
|
71
164
|
readonly residentKey: "required";
|
|
@@ -97,7 +190,7 @@ declare const PRESET_MAP: {
|
|
|
97
190
|
readonly alg: -257;
|
|
98
191
|
}];
|
|
99
192
|
};
|
|
100
|
-
readonly
|
|
193
|
+
readonly externalSecurityKey: {
|
|
101
194
|
readonly authenticatorSelection: {
|
|
102
195
|
readonly residentKey: "discouraged";
|
|
103
196
|
readonly userVerification: "preferred";
|
|
@@ -111,7 +204,7 @@ declare const PRESET_MAP: {
|
|
|
111
204
|
readonly alg: -257;
|
|
112
205
|
}];
|
|
113
206
|
};
|
|
114
|
-
readonly
|
|
207
|
+
readonly platformAuthenticator: {
|
|
115
208
|
readonly authenticatorSelection: {
|
|
116
209
|
readonly authenticatorAttachment: "platform";
|
|
117
210
|
readonly residentKey: "required";
|
|
@@ -132,7 +225,7 @@ declare const PRESET_MAP: {
|
|
|
132
225
|
type PresetName = keyof typeof PRESET_MAP;
|
|
133
226
|
|
|
134
227
|
/**
|
|
135
|
-
*
|
|
228
|
+
* Operation-level configuration interfaces for WebAuthn operations
|
|
136
229
|
*
|
|
137
230
|
* These interfaces provide a convenient, preset-driven API while still allowing
|
|
138
231
|
* full customization through override properties. They derive from standard WebAuthn
|
|
@@ -174,8 +267,8 @@ interface RegisterConfig extends Partial<Pick<PublicKeyCredentialCreationOptions
|
|
|
174
267
|
/**
|
|
175
268
|
* Optional preset to use as base configuration
|
|
176
269
|
* - 'passkey': Modern passwordless, cross-device credentials
|
|
177
|
-
* - '
|
|
178
|
-
* - '
|
|
270
|
+
* - 'externalSecurityKey': External security key as second factor after password
|
|
271
|
+
* - 'platformAuthenticator': High-security, platform authenticator credentials
|
|
179
272
|
*/
|
|
180
273
|
preset?: PresetName;
|
|
181
274
|
/**
|
|
@@ -251,8 +344,66 @@ type RegisterInput = RegisterConfig | PublicKeyCredentialCreationOptions | Publi
|
|
|
251
344
|
type AuthenticateInput = AuthenticateConfig | PublicKeyCredentialRequestOptions | PublicKeyCredentialRequestOptionsJSON;
|
|
252
345
|
|
|
253
346
|
/**
|
|
254
|
-
*
|
|
255
|
-
*
|
|
347
|
+
* Remote configuration types for WebAuthn operations
|
|
348
|
+
*
|
|
349
|
+
* These types provide flexible, type-safe interfaces for communicating with
|
|
350
|
+
* remote servers that provide WebAuthn options. They use generics to allow
|
|
351
|
+
* any server payload structure while maintaining TypeScript safety.
|
|
352
|
+
*/
|
|
353
|
+
/**
|
|
354
|
+
* Request payload for remote registration endpoint.
|
|
355
|
+
*
|
|
356
|
+
* Can contain any data your server needs to generate WebAuthn creation options.
|
|
357
|
+
* Sent as JSON body via POST request.
|
|
358
|
+
*
|
|
359
|
+
* @template T The structure of data your server expects
|
|
360
|
+
*
|
|
361
|
+
* @example
|
|
362
|
+
* ```typescript
|
|
363
|
+
* // Simple usage
|
|
364
|
+
* webAuthnService.registerRemote({ username: 'user@example.com' });
|
|
365
|
+
*
|
|
366
|
+
* // Custom server payload
|
|
367
|
+
* interface MyPayload { tenantId: string; userId: number; }
|
|
368
|
+
* webAuthnService.registerRemote<MyPayload>({
|
|
369
|
+
* tenantId: 'acme',
|
|
370
|
+
* userId: 123
|
|
371
|
+
* });
|
|
372
|
+
* ```
|
|
373
|
+
*/
|
|
374
|
+
type RemoteRegistrationRequest<T extends Record<string, any> = Record<string, any>> = T;
|
|
375
|
+
/**
|
|
376
|
+
* Request payload for remote authentication endpoint.
|
|
377
|
+
*
|
|
378
|
+
* Can contain any data your server needs to generate WebAuthn request options.
|
|
379
|
+
* Sent as JSON body via POST request.
|
|
380
|
+
*
|
|
381
|
+
* @template T The structure of data your server expects
|
|
382
|
+
*
|
|
383
|
+
* @example
|
|
384
|
+
* ```typescript
|
|
385
|
+
* // Simple usage
|
|
386
|
+
* webAuthnService.authenticateRemote({ username: 'user@example.com' });
|
|
387
|
+
*
|
|
388
|
+
* // Custom server payload
|
|
389
|
+
* interface MyAuthPayload { sessionId: string; context: string; }
|
|
390
|
+
* webAuthnService.authenticateRemote<MyAuthPayload>({
|
|
391
|
+
* sessionId: 'abc123',
|
|
392
|
+
* context: 'mobile'
|
|
393
|
+
* });
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
type RemoteAuthenticationRequest<T extends Record<string, any> = Record<string, any>> = T;
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Response interfaces for WebAuthn operations
|
|
400
|
+
*
|
|
401
|
+
* This file contains both raw WebAuthn results (converted to Base64URL strings)
|
|
402
|
+
* and enhanced user-friendly response formats.
|
|
403
|
+
*/
|
|
404
|
+
/**
|
|
405
|
+
* Raw result of WebAuthn registration
|
|
406
|
+
* Simplified version with all ArrayBuffers converted to Base64URL strings for easier handling
|
|
256
407
|
*/
|
|
257
408
|
interface WebAuthnRegistrationResult {
|
|
258
409
|
credentialId: string;
|
|
@@ -262,8 +413,8 @@ interface WebAuthnRegistrationResult {
|
|
|
262
413
|
transports?: AuthenticatorTransport[];
|
|
263
414
|
}
|
|
264
415
|
/**
|
|
265
|
-
*
|
|
266
|
-
* Simplified version with all ArrayBuffers converted to Base64URL strings
|
|
416
|
+
* Raw result of WebAuthn authentication
|
|
417
|
+
* Simplified version with all ArrayBuffers converted to Base64URL strings for easier handling
|
|
267
418
|
*/
|
|
268
419
|
interface WebAuthnAuthenticationResult {
|
|
269
420
|
credentialId: string;
|
|
@@ -272,17 +423,9 @@ interface WebAuthnAuthenticationResult {
|
|
|
272
423
|
signature: string;
|
|
273
424
|
userHandle?: string;
|
|
274
425
|
}
|
|
275
|
-
/**
|
|
276
|
-
* Browser support information
|
|
277
|
-
*/
|
|
278
|
-
interface WebAuthnSupport {
|
|
279
|
-
isSupported: boolean;
|
|
280
|
-
isPlatformAuthenticatorAvailable: boolean;
|
|
281
|
-
supportedTransports: AuthenticatorTransport[];
|
|
282
|
-
}
|
|
283
426
|
/**
|
|
284
427
|
* Enhanced registration response with clean, developer-friendly format
|
|
285
|
-
* Used by the
|
|
428
|
+
* Used by the high-level register() method
|
|
286
429
|
*/
|
|
287
430
|
interface RegistrationResponse {
|
|
288
431
|
/**
|
|
@@ -303,14 +446,14 @@ interface RegistrationResponse {
|
|
|
303
446
|
*/
|
|
304
447
|
transports?: AuthenticatorTransport[];
|
|
305
448
|
/**
|
|
306
|
-
*
|
|
307
|
-
*
|
|
449
|
+
* Complete raw WebAuthn response for advanced use cases
|
|
450
|
+
* Provides access to all WebAuthn data including attestation objects, metadata, etc.
|
|
308
451
|
*/
|
|
309
452
|
rawResponse?: WebAuthnRegistrationResult;
|
|
310
453
|
}
|
|
311
454
|
/**
|
|
312
455
|
* Enhanced authentication response with clean, developer-friendly format
|
|
313
|
-
* Used by the
|
|
456
|
+
* Used by the high-level authenticate() method
|
|
314
457
|
*/
|
|
315
458
|
interface AuthenticationResponse {
|
|
316
459
|
/**
|
|
@@ -327,11 +470,19 @@ interface AuthenticationResponse {
|
|
|
327
470
|
*/
|
|
328
471
|
userHandle?: string;
|
|
329
472
|
/**
|
|
330
|
-
*
|
|
331
|
-
*
|
|
473
|
+
* Complete raw WebAuthn response for advanced use cases
|
|
474
|
+
* Provides access to all WebAuthn data including signatures, authenticator data, etc.
|
|
332
475
|
*/
|
|
333
476
|
rawResponse?: WebAuthnAuthenticationResult;
|
|
334
477
|
}
|
|
478
|
+
/**
|
|
479
|
+
* Browser support information
|
|
480
|
+
*/
|
|
481
|
+
interface WebAuthnSupport {
|
|
482
|
+
isSupported: boolean;
|
|
483
|
+
isPlatformAuthenticatorAvailable: boolean;
|
|
484
|
+
supportedTransports: AuthenticatorTransport[];
|
|
485
|
+
}
|
|
335
486
|
|
|
336
487
|
/**
|
|
337
488
|
* Enhanced Angular service for WebAuthn operations
|
|
@@ -340,186 +491,350 @@ interface AuthenticationResponse {
|
|
|
340
491
|
*/
|
|
341
492
|
declare class WebAuthnService {
|
|
342
493
|
private readonly config;
|
|
494
|
+
private readonly http;
|
|
343
495
|
/**
|
|
344
|
-
* Checks if WebAuthn is supported in the current browser
|
|
496
|
+
* Checks if WebAuthn is supported in the current browser environment.
|
|
497
|
+
*
|
|
498
|
+
* @returns True if WebAuthn is supported, false otherwise
|
|
499
|
+
* @example
|
|
500
|
+
* ```typescript
|
|
501
|
+
* if (this.webAuthnService.isSupported()) {
|
|
502
|
+
* // Proceed with WebAuthn operations
|
|
503
|
+
* } else {
|
|
504
|
+
* // Show fallback authentication method
|
|
505
|
+
* }
|
|
506
|
+
* ```
|
|
345
507
|
*/
|
|
346
508
|
isSupported(): boolean;
|
|
347
509
|
/**
|
|
348
|
-
* Gets
|
|
510
|
+
* Gets detailed WebAuthn support information for the current browser.
|
|
511
|
+
* Provides information about available authenticator types and capabilities.
|
|
512
|
+
*
|
|
513
|
+
* @returns Observable containing WebAuthn support details
|
|
514
|
+
* @example
|
|
515
|
+
* ```typescript
|
|
516
|
+
* this.webAuthnService.getSupport().subscribe(support => {
|
|
517
|
+
* console.log('Platform authenticator:', support.platformAuthenticator);
|
|
518
|
+
* console.log('Cross-platform authenticator:', support.crossPlatformAuthenticator);
|
|
519
|
+
* });
|
|
520
|
+
* ```
|
|
349
521
|
*/
|
|
350
522
|
getSupport(): Observable<WebAuthnSupport>;
|
|
351
523
|
/**
|
|
352
|
-
* Registers a new WebAuthn credential
|
|
524
|
+
* Registers a new WebAuthn credential for a user.
|
|
353
525
|
*
|
|
354
|
-
*
|
|
355
|
-
*
|
|
526
|
+
* Supports two input formats:
|
|
527
|
+
* 1. High-level RegisterConfig with preset support and automatic option building
|
|
528
|
+
* 2. Direct PublicKeyCredentialCreationOptions for full control
|
|
356
529
|
*
|
|
357
|
-
* @
|
|
358
|
-
*
|
|
359
|
-
* // Simple preset usage
|
|
360
|
-
* this.webAuthnService.register({ username: 'john.doe', preset: 'passkey' });
|
|
530
|
+
* @param input Either a RegisterConfig object or raw WebAuthn creation options
|
|
531
|
+
* @returns Observable containing the registration response with credential details
|
|
361
532
|
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
367
|
-
* }
|
|
533
|
+
* @throws {UnsupportedOperationError} When WebAuthn is not supported
|
|
534
|
+
* @throws {InvalidOptionsError} When provided options are invalid
|
|
535
|
+
* @throws {UserCancelledError} When user cancels the registration
|
|
536
|
+
* @throws {AuthenticatorError} When authenticator encounters an error
|
|
537
|
+
* @throws {TimeoutError} When the operation times out
|
|
538
|
+
* @throws {SecurityError} When a security violation occurs
|
|
368
539
|
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
* user: {
|
|
374
|
-
*
|
|
540
|
+
* @example Using high-level config:
|
|
541
|
+
* ```typescript
|
|
542
|
+
* const config: RegisterConfig = {
|
|
543
|
+
* preset: 'passkey',
|
|
544
|
+
* user: {
|
|
545
|
+
* id: 'user123',
|
|
546
|
+
* name: 'user@example.com',
|
|
547
|
+
* displayName: 'John Doe'
|
|
548
|
+
* },
|
|
549
|
+
* challenge: 'random-challenge'
|
|
375
550
|
* };
|
|
376
|
-
* this.webAuthnService.register(nativeOptions);
|
|
377
551
|
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
552
|
+
* this.webAuthnService.register(config).subscribe({
|
|
553
|
+
* next: (response) => {
|
|
554
|
+
* console.log('Registration successful:', response.credential.id);
|
|
555
|
+
* },
|
|
556
|
+
* error: (error) => {
|
|
557
|
+
* if (error instanceof UserCancelledError) {
|
|
558
|
+
* console.log('User cancelled registration');
|
|
559
|
+
* }
|
|
560
|
+
* }
|
|
561
|
+
* });
|
|
562
|
+
* ```
|
|
563
|
+
*
|
|
564
|
+
* @example Using direct options:
|
|
565
|
+
* ```typescript
|
|
566
|
+
* const options: PublicKeyCredentialCreationOptions = {
|
|
567
|
+
* rp: { name: "Example Corp" },
|
|
568
|
+
* user: { id: new Uint8Array([1,2,3]), name: "user@example.com", displayName: "User" },
|
|
569
|
+
* challenge: new Uint8Array([4,5,6]),
|
|
383
570
|
* pubKeyCredParams: [{ type: "public-key", alg: -7 }]
|
|
384
571
|
* };
|
|
385
|
-
* this.webAuthnService.register(
|
|
572
|
+
* this.webAuthnService.register(options).subscribe(response => {
|
|
573
|
+
* // Handle response
|
|
574
|
+
* });
|
|
386
575
|
* ```
|
|
387
576
|
*/
|
|
388
577
|
register(input: RegisterInput): Observable<RegistrationResponse>;
|
|
389
578
|
/**
|
|
390
|
-
* Authenticates using an existing WebAuthn credential
|
|
579
|
+
* Authenticates a user using an existing WebAuthn credential.
|
|
391
580
|
*
|
|
392
|
-
*
|
|
393
|
-
*
|
|
581
|
+
* Supports two input formats:
|
|
582
|
+
* 1. High-level AuthenticateConfig with preset support and automatic option building
|
|
583
|
+
* 2. Direct PublicKeyCredentialRequestOptions for full control
|
|
394
584
|
*
|
|
395
|
-
* @
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
585
|
+
* @param input Either an AuthenticateConfig object or raw WebAuthn request options
|
|
586
|
+
* @returns Observable containing the authentication response with assertion details
|
|
587
|
+
*
|
|
588
|
+
* @throws {UnsupportedOperationError} When WebAuthn is not supported
|
|
589
|
+
* @throws {InvalidOptionsError} When provided options are invalid
|
|
590
|
+
* @throws {UserCancelledError} When user cancels the authentication
|
|
591
|
+
* @throws {AuthenticatorError} When authenticator encounters an error
|
|
592
|
+
* @throws {TimeoutError} When the operation times out
|
|
593
|
+
* @throws {SecurityError} When a security violation occurs
|
|
399
594
|
*
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
* preset: '
|
|
595
|
+
* @example Using high-level config:
|
|
596
|
+
* ```typescript
|
|
597
|
+
* const config: AuthenticateConfig = {
|
|
598
|
+
* preset: 'passkey',
|
|
599
|
+
* challenge: 'auth-challenge',
|
|
404
600
|
* allowCredentials: ['credential-id-1', 'credential-id-2']
|
|
601
|
+
* };
|
|
602
|
+
*
|
|
603
|
+
* this.webAuthnService.authenticate(config).subscribe({
|
|
604
|
+
* next: (response) => {
|
|
605
|
+
* console.log('Authentication successful:', response.credential.id);
|
|
606
|
+
* },
|
|
607
|
+
* error: (error) => {
|
|
608
|
+
* if (error instanceof UserCancelledError) {
|
|
609
|
+
* console.log('User cancelled authentication');
|
|
610
|
+
* }
|
|
611
|
+
* }
|
|
405
612
|
* });
|
|
613
|
+
* ```
|
|
406
614
|
*
|
|
407
|
-
*
|
|
408
|
-
*
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
* id: "Y3JlZElk"
|
|
413
|
-
* }]
|
|
414
|
-
* };
|
|
415
|
-
* this.webAuthnService.authenticate(jsonOptions);
|
|
416
|
-
*
|
|
417
|
-
* // Direct WebAuthn options (native)
|
|
418
|
-
* const nativeOptions: PublicKeyCredentialRequestOptions = {
|
|
419
|
-
* challenge: new Uint8Array([...]),
|
|
420
|
-
* allowCredentials: [{
|
|
421
|
-
* type: "public-key",
|
|
422
|
-
* id: new Uint8Array([...])
|
|
423
|
-
* }]
|
|
615
|
+
* @example Using direct options:
|
|
616
|
+
* ```typescript
|
|
617
|
+
* const options: PublicKeyCredentialRequestOptions = {
|
|
618
|
+
* challenge: new Uint8Array([1,2,3]),
|
|
619
|
+
* allowCredentials: [{ type: 'public-key', id: new Uint8Array([4,5,6]) }]
|
|
424
620
|
* };
|
|
425
|
-
* this.webAuthnService.authenticate(
|
|
621
|
+
* this.webAuthnService.authenticate(options).subscribe(response => {
|
|
622
|
+
* // Handle response
|
|
623
|
+
* });
|
|
426
624
|
* ```
|
|
427
625
|
*/
|
|
428
626
|
authenticate(input: AuthenticateInput): Observable<AuthenticationResponse>;
|
|
429
627
|
/**
|
|
430
|
-
*
|
|
628
|
+
* Registers a new WebAuthn credential using options fetched from a remote server.
|
|
629
|
+
*
|
|
630
|
+
* Sends request data via POST to the configured registration endpoint,
|
|
631
|
+
* receives PublicKeyCredentialCreationOptionsJSON, then proceeds with
|
|
632
|
+
* standard WebAuthn registration flow.
|
|
633
|
+
*
|
|
634
|
+
* @param request Data to send to server (can be any object your server expects)
|
|
635
|
+
* @template T Type constraint for the request payload
|
|
636
|
+
* @returns Observable containing the registration response
|
|
637
|
+
*
|
|
638
|
+
* @throws {InvalidOptionsError} When remote registration endpoint is not configured
|
|
639
|
+
* @throws {RemoteEndpointError} When server request fails
|
|
640
|
+
* @throws {InvalidRemoteOptionsError} When server returns invalid options
|
|
641
|
+
*
|
|
642
|
+
* @example
|
|
643
|
+
* ```typescript
|
|
644
|
+
* // Simple request
|
|
645
|
+
* this.webAuthnService.registerRemote({
|
|
646
|
+
* username: 'john.doe@example.com'
|
|
647
|
+
* }).subscribe(response => console.log('Success:', response));
|
|
648
|
+
*
|
|
649
|
+
* // Typed request with additional context
|
|
650
|
+
* interface ServerPayload {
|
|
651
|
+
* tenantId: string;
|
|
652
|
+
* department: string;
|
|
653
|
+
* }
|
|
654
|
+
*
|
|
655
|
+
* this.webAuthnService.registerRemote<ServerPayload>({
|
|
656
|
+
* tenantId: 'acme-corp',
|
|
657
|
+
* department: 'engineering'
|
|
658
|
+
* }).subscribe(response => console.log('Success:', response));
|
|
659
|
+
* ```
|
|
660
|
+
*/
|
|
661
|
+
registerRemote<T extends Record<string, any> = Record<string, any>>(request: RemoteRegistrationRequest<T>): Observable<RegistrationResponse>;
|
|
662
|
+
/**
|
|
663
|
+
* Authenticates using WebAuthn with options fetched from a remote server.
|
|
664
|
+
*
|
|
665
|
+
* Sends request data via POST to the configured authentication endpoint,
|
|
666
|
+
* receives PublicKeyCredentialRequestOptionsJSON, then proceeds with
|
|
667
|
+
* standard WebAuthn authentication flow.
|
|
668
|
+
*
|
|
669
|
+
* @param request Optional data to send to server (defaults to empty object)
|
|
670
|
+
* @template T Type constraint for the request payload
|
|
671
|
+
* @returns Observable containing the authentication response
|
|
672
|
+
*
|
|
673
|
+
* @throws {InvalidOptionsError} When remote authentication endpoint is not configured
|
|
674
|
+
* @throws {RemoteEndpointError} When server request fails
|
|
675
|
+
* @throws {InvalidRemoteOptionsError} When server returns invalid options
|
|
676
|
+
*
|
|
677
|
+
* @example
|
|
678
|
+
* ```typescript
|
|
679
|
+
* // Simple request
|
|
680
|
+
* this.webAuthnService.authenticateRemote({
|
|
681
|
+
* username: 'john.doe@example.com'
|
|
682
|
+
* }).subscribe(response => console.log('Success:', response));
|
|
683
|
+
*
|
|
684
|
+
* // Request with no payload (server uses session/context)
|
|
685
|
+
* this.webAuthnService.authenticateRemote()
|
|
686
|
+
* .subscribe(response => console.log('Success:', response));
|
|
687
|
+
* ```
|
|
688
|
+
*/
|
|
689
|
+
authenticateRemote<T extends Record<string, any> = Record<string, any>>(request?: RemoteAuthenticationRequest<T>): Observable<AuthenticationResponse>;
|
|
690
|
+
/**
|
|
691
|
+
* Validates that remote registration endpoint is configured
|
|
692
|
+
* @private
|
|
693
|
+
*/
|
|
694
|
+
private validateRemoteRegistrationConfig;
|
|
695
|
+
/**
|
|
696
|
+
* Validates that remote authentication endpoint is configured
|
|
697
|
+
* @private
|
|
698
|
+
*/
|
|
699
|
+
private validateRemoteAuthenticationConfig;
|
|
700
|
+
/**
|
|
701
|
+
* Handles errors from remote HTTP requests
|
|
702
|
+
* @private
|
|
703
|
+
*/
|
|
704
|
+
private handleRemoteError;
|
|
705
|
+
/**
|
|
706
|
+
* Parses and normalizes registration options from either native or JSON format.
|
|
707
|
+
* Converts base64url-encoded strings to Uint8Array where necessary.
|
|
708
|
+
*
|
|
709
|
+
* @param options Registration options in either native or JSON format
|
|
710
|
+
* @returns Normalized PublicKeyCredentialCreationOptions for browser API
|
|
711
|
+
* @private
|
|
431
712
|
*/
|
|
432
713
|
private parseRegistrationOptions;
|
|
433
714
|
/**
|
|
434
|
-
* Parses authentication options
|
|
715
|
+
* Parses and normalizes authentication options from either native or JSON format.
|
|
716
|
+
* Converts base64url-encoded strings to Uint8Array where necessary.
|
|
717
|
+
*
|
|
718
|
+
* @param options Authentication options in either native or JSON format
|
|
719
|
+
* @returns Normalized PublicKeyCredentialRequestOptions for browser API
|
|
720
|
+
* @private
|
|
435
721
|
*/
|
|
436
722
|
private parseAuthenticationOptions;
|
|
437
723
|
/**
|
|
438
|
-
*
|
|
724
|
+
* Validates that the credential is a valid PublicKeyCredential.
|
|
725
|
+
*
|
|
726
|
+
* @param credential Raw credential from navigator.credentials.create()
|
|
727
|
+
* @returns Validated PublicKeyCredential
|
|
728
|
+
* @throws {AuthenticatorError} When credential is invalid or null
|
|
729
|
+
* @private
|
|
439
730
|
*/
|
|
440
|
-
private
|
|
731
|
+
private validateRegistrationCredential;
|
|
441
732
|
/**
|
|
442
|
-
*
|
|
733
|
+
* Extracts basic credential information (ID and transports).
|
|
734
|
+
*
|
|
735
|
+
* @param credential Validated PublicKeyCredential
|
|
736
|
+
* @returns Object containing credential ID and supported transports
|
|
737
|
+
* @private
|
|
443
738
|
*/
|
|
444
|
-
private
|
|
739
|
+
private extractCredentialInfo;
|
|
445
740
|
/**
|
|
446
|
-
*
|
|
741
|
+
* Safely extracts the public key with proper error handling.
|
|
742
|
+
*
|
|
743
|
+
* @param response AuthenticatorAttestationResponse
|
|
744
|
+
* @returns Public key as base64url string, or undefined if extraction fails
|
|
745
|
+
* @private
|
|
447
746
|
*/
|
|
448
|
-
private
|
|
449
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<WebAuthnService, never>;
|
|
450
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<WebAuthnService>;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
/**
|
|
454
|
-
* WebAuthn Configuration
|
|
455
|
-
* Provides configuration interfaces and injection token for WebAuthn service
|
|
456
|
-
*/
|
|
457
|
-
|
|
458
|
-
/**
|
|
459
|
-
* Required relying party configuration
|
|
460
|
-
*/
|
|
461
|
-
interface RelyingPartyConfig {
|
|
747
|
+
private extractPublicKey;
|
|
462
748
|
/**
|
|
463
|
-
*
|
|
464
|
-
*
|
|
749
|
+
* Creates the complete raw WebAuthn response for advanced use cases.
|
|
750
|
+
* Provides access to all WebAuthn data including attestation objects and metadata.
|
|
751
|
+
*
|
|
752
|
+
* @param credential Validated PublicKeyCredential
|
|
753
|
+
* @param credentialId Already extracted credential ID
|
|
754
|
+
* @param publicKey Extracted public key (may be undefined)
|
|
755
|
+
* @returns Complete WebAuthnRegistrationResult with all WebAuthn data
|
|
756
|
+
* @private
|
|
465
757
|
*/
|
|
466
|
-
|
|
758
|
+
private createRawRegistrationResponse;
|
|
467
759
|
/**
|
|
468
|
-
*
|
|
469
|
-
*
|
|
760
|
+
* Assembles the final registration response.
|
|
761
|
+
* Combines all extracted data into the final response format.
|
|
762
|
+
*
|
|
763
|
+
* @param credentialInfo Basic credential information
|
|
764
|
+
* @param publicKey Extracted public key
|
|
765
|
+
* @param rawResponse Raw WebAuthn response
|
|
766
|
+
* @returns Complete RegistrationResponse
|
|
767
|
+
* @private
|
|
470
768
|
*/
|
|
471
|
-
|
|
472
|
-
}
|
|
473
|
-
/**
|
|
474
|
-
* Configuration interface for WebAuthn service
|
|
475
|
-
* Now includes required relying party information and advanced options
|
|
476
|
-
*/
|
|
477
|
-
interface WebAuthnConfig {
|
|
769
|
+
private assembleRegistrationResponse;
|
|
478
770
|
/**
|
|
479
|
-
*
|
|
480
|
-
*
|
|
771
|
+
* Processes the result of a WebAuthn registration operation.
|
|
772
|
+
* Converts the browser credential response into a structured RegistrationResponse.
|
|
773
|
+
*
|
|
774
|
+
* @param credential The credential returned by navigator.credentials.create()
|
|
775
|
+
* @returns Structured registration response with parsed credential data
|
|
776
|
+
* @throws {AuthenticatorError} When credential creation fails or returns null
|
|
777
|
+
* @private
|
|
481
778
|
*/
|
|
482
|
-
|
|
779
|
+
private processRegistrationResult;
|
|
483
780
|
/**
|
|
484
|
-
*
|
|
485
|
-
*
|
|
781
|
+
* Processes the result of a WebAuthn authentication operation.
|
|
782
|
+
* Converts the browser credential response into a structured AuthenticationResponse.
|
|
783
|
+
*
|
|
784
|
+
* @param credential The credential returned by navigator.credentials.get()
|
|
785
|
+
* @returns Structured authentication response with parsed assertion data
|
|
786
|
+
* @throws {AuthenticatorError} When authentication fails or returns null
|
|
787
|
+
* @private
|
|
486
788
|
*/
|
|
487
|
-
|
|
789
|
+
private processAuthenticationResult;
|
|
488
790
|
/**
|
|
489
|
-
*
|
|
490
|
-
*
|
|
791
|
+
* Central error handling dispatcher for WebAuthn operations.
|
|
792
|
+
* Routes different error types to specialized handlers for proper error classification.
|
|
793
|
+
*
|
|
794
|
+
* @param error The error to handle (can be DOMException, TypeError, or any other error)
|
|
795
|
+
* @returns Observable that throws an appropriate WebAuthnError subclass
|
|
796
|
+
* @private
|
|
491
797
|
*/
|
|
492
|
-
|
|
798
|
+
private handleWebAuthnError;
|
|
493
799
|
/**
|
|
494
|
-
*
|
|
495
|
-
*
|
|
800
|
+
* Handles DOMExceptions from the WebAuthn API using a mapping approach.
|
|
801
|
+
* Maps specific DOMException names to appropriate WebAuthnError subclasses.
|
|
802
|
+
*
|
|
803
|
+
* @param error The DOMException thrown by the WebAuthn API
|
|
804
|
+
* @returns Observable that throws an appropriate WebAuthnError subclass
|
|
805
|
+
* @private
|
|
496
806
|
*/
|
|
497
|
-
|
|
807
|
+
private handleDOMException;
|
|
498
808
|
/**
|
|
499
|
-
*
|
|
500
|
-
*
|
|
809
|
+
* Determines if an error is related to JSON parsing issues.
|
|
810
|
+
* Specifically checks for TypeError messages indicating JSON parsing failures.
|
|
811
|
+
*
|
|
812
|
+
* @param error The error to check
|
|
813
|
+
* @returns True if the error is a JSON parsing error, false otherwise
|
|
814
|
+
* @private
|
|
501
815
|
*/
|
|
502
|
-
|
|
816
|
+
private isJSONParsingError;
|
|
503
817
|
/**
|
|
504
|
-
*
|
|
818
|
+
* Handles JSON parsing errors specifically.
|
|
819
|
+
* These errors occur when invalid JSON format options are provided.
|
|
820
|
+
*
|
|
821
|
+
* @param error The TypeError from JSON parsing
|
|
822
|
+
* @returns Observable that throws an InvalidOptionsError
|
|
823
|
+
* @private
|
|
505
824
|
*/
|
|
506
|
-
|
|
825
|
+
private handleJSONParsingError;
|
|
826
|
+
/**
|
|
827
|
+
* Handles any unexpected errors that don't fall into other categories.
|
|
828
|
+
* Provides a fallback for errors that aren't DOMExceptions or JSON parsing errors.
|
|
829
|
+
*
|
|
830
|
+
* @param error The unexpected error
|
|
831
|
+
* @returns Observable that throws a generic WebAuthnError
|
|
832
|
+
* @private
|
|
833
|
+
*/
|
|
834
|
+
private handleUnknownError;
|
|
835
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<WebAuthnService, never>;
|
|
836
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<WebAuthnService>;
|
|
507
837
|
}
|
|
508
|
-
/**
|
|
509
|
-
* Default configuration for WebAuthn service
|
|
510
|
-
* Note: relyingParty must be provided by the application
|
|
511
|
-
*/
|
|
512
|
-
declare const DEFAULT_WEBAUTHN_CONFIG: Omit<WebAuthnConfig, 'relyingParty'>;
|
|
513
|
-
/**
|
|
514
|
-
* Injection token for WebAuthn configuration
|
|
515
|
-
*/
|
|
516
|
-
declare const WEBAUTHN_CONFIG: InjectionToken<WebAuthnConfig>;
|
|
517
|
-
/**
|
|
518
|
-
* Creates a complete WebAuthn configuration with required relying party information
|
|
519
|
-
* @param relyingParty Required relying party configuration
|
|
520
|
-
* @param overrides Optional configuration overrides
|
|
521
|
-
*/
|
|
522
|
-
declare function createWebAuthnConfig(relyingParty: RelyingPartyConfig, overrides?: Partial<Omit<WebAuthnConfig, 'relyingParty'>>): WebAuthnConfig;
|
|
523
838
|
|
|
524
839
|
/**
|
|
525
840
|
* WebAuthn Providers
|
|
@@ -547,16 +862,15 @@ declare function createWebAuthnConfig(relyingParty: RelyingPartyConfig, override
|
|
|
547
862
|
* ```
|
|
548
863
|
*/
|
|
549
864
|
declare function provideWebAuthn(relyingParty: RelyingPartyConfig, config?: Partial<Omit<WebAuthnConfig, 'relyingParty'>>): Provider[];
|
|
550
|
-
/**
|
|
551
|
-
* @deprecated Use provideWebAuthn(relyingParty, config) instead.
|
|
552
|
-
* This version is kept for backward compatibility but requires relying party information.
|
|
553
|
-
*/
|
|
554
|
-
declare function provideWebAuthnLegacy(config: WebAuthnConfig): Provider[];
|
|
555
865
|
|
|
556
866
|
/**
|
|
557
867
|
* Enhanced WebAuthn Error Classes
|
|
558
868
|
* Provides specific, actionable error types for better developer experience
|
|
559
869
|
*/
|
|
870
|
+
/**
|
|
871
|
+
* Enumeration of WebAuthn error types for categorizing different failure scenarios.
|
|
872
|
+
* Provides semantic error classification for better error handling and user experience.
|
|
873
|
+
*/
|
|
560
874
|
declare enum WebAuthnErrorType {
|
|
561
875
|
NOT_SUPPORTED = "NOT_SUPPORTED",
|
|
562
876
|
USER_CANCELLED = "USER_CANCELLED",
|
|
@@ -566,58 +880,292 @@ declare enum WebAuthnErrorType {
|
|
|
566
880
|
NETWORK_ERROR = "NETWORK_ERROR",
|
|
567
881
|
SECURITY_ERROR = "SECURITY_ERROR",
|
|
568
882
|
TIMEOUT_ERROR = "TIMEOUT_ERROR",
|
|
883
|
+
REMOTE_ENDPOINT_ERROR = "REMOTE_ENDPOINT_ERROR",
|
|
884
|
+
INVALID_REMOTE_OPTIONS = "INVALID_REMOTE_OPTIONS",
|
|
569
885
|
UNKNOWN = "UNKNOWN"
|
|
570
886
|
}
|
|
571
887
|
/**
|
|
572
|
-
* Base WebAuthn error class
|
|
888
|
+
* Base WebAuthn error class that provides enhanced error information.
|
|
889
|
+
* All WebAuthn-specific errors extend from this class for consistent error handling.
|
|
890
|
+
*
|
|
891
|
+
* @example
|
|
892
|
+
* ```typescript
|
|
893
|
+
* try {
|
|
894
|
+
* await webAuthnService.register(config);
|
|
895
|
+
* } catch (error) {
|
|
896
|
+
* if (error instanceof WebAuthnError) {
|
|
897
|
+
* console.log('Error type:', error.type);
|
|
898
|
+
* console.log('Original error:', error.originalError);
|
|
899
|
+
* }
|
|
900
|
+
* }
|
|
901
|
+
* ```
|
|
573
902
|
*/
|
|
574
903
|
declare class WebAuthnError extends Error {
|
|
575
904
|
readonly type: WebAuthnErrorType;
|
|
576
905
|
readonly originalError?: Error | undefined;
|
|
906
|
+
/**
|
|
907
|
+
* Creates a new WebAuthnError instance.
|
|
908
|
+
*
|
|
909
|
+
* @param type The semantic error type
|
|
910
|
+
* @param message Human-readable error message
|
|
911
|
+
* @param originalError The original error that caused this WebAuthn error (optional)
|
|
912
|
+
*/
|
|
577
913
|
constructor(type: WebAuthnErrorType, message: string, originalError?: Error | undefined);
|
|
914
|
+
/**
|
|
915
|
+
* Factory method to create WebAuthnError from DOMException.
|
|
916
|
+
* Maps browser DOMException types to semantic WebAuthn error types.
|
|
917
|
+
*
|
|
918
|
+
* @param error The DOMException thrown by WebAuthn API
|
|
919
|
+
* @returns Appropriate WebAuthnError subclass based on the DOMException type
|
|
920
|
+
*/
|
|
578
921
|
static fromDOMException(error: DOMException): WebAuthnError;
|
|
922
|
+
/**
|
|
923
|
+
* Maps DOMException names to WebAuthn error types.
|
|
924
|
+
* Provides semantic classification of browser-level errors.
|
|
925
|
+
*
|
|
926
|
+
* @param name The DOMException name
|
|
927
|
+
* @returns Corresponding WebAuthnErrorType
|
|
928
|
+
* @private
|
|
929
|
+
*/
|
|
579
930
|
private static mapDOMExceptionToType;
|
|
580
931
|
}
|
|
581
932
|
/**
|
|
582
|
-
* Error thrown when user cancels
|
|
933
|
+
* Error thrown when the user cancels a WebAuthn operation.
|
|
934
|
+
* This is the most common error and typically requires no action from the developer.
|
|
935
|
+
*
|
|
936
|
+
* @example
|
|
937
|
+
* ```typescript
|
|
938
|
+
* try {
|
|
939
|
+
* await webAuthnService.register(config);
|
|
940
|
+
* } catch (error) {
|
|
941
|
+
* if (error instanceof UserCancelledError) {
|
|
942
|
+
* // User chose not to proceed - this is normal behavior
|
|
943
|
+
* console.log('User cancelled the operation');
|
|
944
|
+
* }
|
|
945
|
+
* }
|
|
946
|
+
* ```
|
|
583
947
|
*/
|
|
584
948
|
declare class UserCancelledError extends WebAuthnError {
|
|
949
|
+
/**
|
|
950
|
+
* Creates a new UserCancelledError.
|
|
951
|
+
*
|
|
952
|
+
* @param originalError The original DOMException that triggered this error (optional)
|
|
953
|
+
*/
|
|
585
954
|
constructor(originalError?: Error);
|
|
586
955
|
}
|
|
587
956
|
/**
|
|
588
|
-
* Error thrown when there's an issue with the authenticator
|
|
957
|
+
* Error thrown when there's an issue with the authenticator device.
|
|
958
|
+
* This could indicate hardware problems, invalid state, or other device-specific issues.
|
|
959
|
+
*
|
|
960
|
+
* @example
|
|
961
|
+
* ```typescript
|
|
962
|
+
* try {
|
|
963
|
+
* await webAuthnService.authenticate(config);
|
|
964
|
+
* } catch (error) {
|
|
965
|
+
* if (error instanceof AuthenticatorError) {
|
|
966
|
+
* // Show user-friendly message about trying again or using different authenticator
|
|
967
|
+
* console.log('Authenticator issue:', error.message);
|
|
968
|
+
* }
|
|
969
|
+
* }
|
|
970
|
+
* ```
|
|
589
971
|
*/
|
|
590
972
|
declare class AuthenticatorError extends WebAuthnError {
|
|
973
|
+
/**
|
|
974
|
+
* Creates a new AuthenticatorError.
|
|
975
|
+
*
|
|
976
|
+
* @param message Descriptive error message
|
|
977
|
+
* @param originalError The original error that caused this authenticator error (optional)
|
|
978
|
+
*/
|
|
591
979
|
constructor(message: string, originalError?: Error);
|
|
592
980
|
}
|
|
593
981
|
/**
|
|
594
|
-
* Error thrown when the provided options are invalid
|
|
982
|
+
* Error thrown when the provided WebAuthn options are invalid or malformed.
|
|
983
|
+
* This typically indicates a programming error in option construction.
|
|
984
|
+
*
|
|
985
|
+
* @example
|
|
986
|
+
* ```typescript
|
|
987
|
+
* try {
|
|
988
|
+
* await webAuthnService.register(invalidConfig);
|
|
989
|
+
* } catch (error) {
|
|
990
|
+
* if (error instanceof InvalidOptionsError) {
|
|
991
|
+
* // Check your configuration and options
|
|
992
|
+
* console.error('Invalid options provided:', error.message);
|
|
993
|
+
* }
|
|
994
|
+
* }
|
|
995
|
+
* ```
|
|
595
996
|
*/
|
|
596
997
|
declare class InvalidOptionsError extends WebAuthnError {
|
|
998
|
+
/**
|
|
999
|
+
* Creates a new InvalidOptionsError.
|
|
1000
|
+
*
|
|
1001
|
+
* @param message Descriptive error message explaining what's invalid
|
|
1002
|
+
* @param originalError The original error that revealed the invalid options (optional)
|
|
1003
|
+
*/
|
|
597
1004
|
constructor(message: string, originalError?: Error);
|
|
598
1005
|
}
|
|
599
1006
|
/**
|
|
600
|
-
* Error thrown when
|
|
1007
|
+
* Error thrown when a WebAuthn operation is not supported in the current environment.
|
|
1008
|
+
* This could be due to browser limitations or missing hardware capabilities.
|
|
1009
|
+
*
|
|
1010
|
+
* @example
|
|
1011
|
+
* ```typescript
|
|
1012
|
+
* if (!webAuthnService.isSupported()) {
|
|
1013
|
+
* // Handle unsupported environment
|
|
1014
|
+
* }
|
|
1015
|
+
*
|
|
1016
|
+
* try {
|
|
1017
|
+
* await webAuthnService.register(config);
|
|
1018
|
+
* } catch (error) {
|
|
1019
|
+
* if (error instanceof UnsupportedOperationError) {
|
|
1020
|
+
* // Show fallback authentication method
|
|
1021
|
+
* console.log('WebAuthn not supported, using fallback');
|
|
1022
|
+
* }
|
|
1023
|
+
* }
|
|
1024
|
+
* ```
|
|
601
1025
|
*/
|
|
602
1026
|
declare class UnsupportedOperationError extends WebAuthnError {
|
|
1027
|
+
/**
|
|
1028
|
+
* Creates a new UnsupportedOperationError.
|
|
1029
|
+
*
|
|
1030
|
+
* @param message Descriptive error message explaining what's not supported
|
|
1031
|
+
* @param originalError The original error that indicated lack of support (optional)
|
|
1032
|
+
*/
|
|
603
1033
|
constructor(message: string, originalError?: Error);
|
|
604
1034
|
}
|
|
605
1035
|
/**
|
|
606
|
-
* Error thrown when there's a network-related issue
|
|
1036
|
+
* Error thrown when there's a network-related issue during WebAuthn operations.
|
|
1037
|
+
* This is rare but can occur in certain network conditions.
|
|
1038
|
+
*
|
|
1039
|
+
* @example
|
|
1040
|
+
* ```typescript
|
|
1041
|
+
* try {
|
|
1042
|
+
* await webAuthnService.authenticate(config);
|
|
1043
|
+
* } catch (error) {
|
|
1044
|
+
* if (error instanceof NetworkError) {
|
|
1045
|
+
* // Suggest user check connection and retry
|
|
1046
|
+
* console.log('Network issue during authentication:', error.message);
|
|
1047
|
+
* }
|
|
1048
|
+
* }
|
|
1049
|
+
* ```
|
|
607
1050
|
*/
|
|
608
1051
|
declare class NetworkError extends WebAuthnError {
|
|
1052
|
+
/**
|
|
1053
|
+
* Creates a new NetworkError.
|
|
1054
|
+
*
|
|
1055
|
+
* @param message Descriptive error message about the network issue
|
|
1056
|
+
* @param originalError The original network-related error (optional)
|
|
1057
|
+
*/
|
|
609
1058
|
constructor(message: string, originalError?: Error);
|
|
610
1059
|
}
|
|
611
1060
|
/**
|
|
612
|
-
* Error thrown when
|
|
1061
|
+
* Error thrown when a security violation occurs during WebAuthn operations.
|
|
1062
|
+
* This typically indicates issues with origin validation or other security checks.
|
|
1063
|
+
*
|
|
1064
|
+
* @example
|
|
1065
|
+
* ```typescript
|
|
1066
|
+
* try {
|
|
1067
|
+
* await webAuthnService.register(config);
|
|
1068
|
+
* } catch (error) {
|
|
1069
|
+
* if (error instanceof SecurityError) {
|
|
1070
|
+
* // Security issue - check origin, HTTPS, etc.
|
|
1071
|
+
* console.error('Security violation:', error.message);
|
|
1072
|
+
* }
|
|
1073
|
+
* }
|
|
1074
|
+
* ```
|
|
613
1075
|
*/
|
|
614
1076
|
declare class SecurityError extends WebAuthnError {
|
|
1077
|
+
/**
|
|
1078
|
+
* Creates a new SecurityError.
|
|
1079
|
+
*
|
|
1080
|
+
* @param message Descriptive error message about the security issue
|
|
1081
|
+
* @param originalError The original security-related error (optional)
|
|
1082
|
+
*/
|
|
615
1083
|
constructor(message: string, originalError?: Error);
|
|
616
1084
|
}
|
|
617
1085
|
/**
|
|
618
|
-
* Error thrown when
|
|
1086
|
+
* Error thrown when a WebAuthn operation times out.
|
|
1087
|
+
* This can happen when the user takes too long to interact with their authenticator.
|
|
1088
|
+
*
|
|
1089
|
+
* @example
|
|
1090
|
+
* ```typescript
|
|
1091
|
+
* try {
|
|
1092
|
+
* await webAuthnService.register(config);
|
|
1093
|
+
* } catch (error) {
|
|
1094
|
+
* if (error instanceof TimeoutError) {
|
|
1095
|
+
* // Suggest user try again and respond more quickly
|
|
1096
|
+
* console.log('Operation timed out - please try again');
|
|
1097
|
+
* }
|
|
1098
|
+
* }
|
|
1099
|
+
* ```
|
|
619
1100
|
*/
|
|
620
1101
|
declare class TimeoutError extends WebAuthnError {
|
|
1102
|
+
/**
|
|
1103
|
+
* Creates a new TimeoutError.
|
|
1104
|
+
*
|
|
1105
|
+
* @param message Descriptive error message about the timeout
|
|
1106
|
+
* @param originalError The original timeout-related error (optional)
|
|
1107
|
+
*/
|
|
1108
|
+
constructor(message: string, originalError?: Error);
|
|
1109
|
+
}
|
|
1110
|
+
/**
|
|
1111
|
+
* Context information for remote endpoint errors (security-conscious)
|
|
1112
|
+
*/
|
|
1113
|
+
interface RemoteErrorContext {
|
|
1114
|
+
readonly url: string;
|
|
1115
|
+
readonly method: string;
|
|
1116
|
+
readonly operation: 'registration' | 'authentication';
|
|
1117
|
+
readonly status?: number;
|
|
1118
|
+
readonly statusText?: string;
|
|
1119
|
+
}
|
|
1120
|
+
/**
|
|
1121
|
+
* Error thrown when remote endpoint request fails.
|
|
1122
|
+
* Includes network errors, HTTP errors, and timeout errors.
|
|
1123
|
+
*
|
|
1124
|
+
* @example
|
|
1125
|
+
* ```typescript
|
|
1126
|
+
* try {
|
|
1127
|
+
* await webAuthnService.registerRemote(request);
|
|
1128
|
+
* } catch (error) {
|
|
1129
|
+
* if (error instanceof RemoteEndpointError) {
|
|
1130
|
+
* console.log('Endpoint:', error.context.url);
|
|
1131
|
+
* console.log('Status:', error.context.status);
|
|
1132
|
+
* }
|
|
1133
|
+
* }
|
|
1134
|
+
* ```
|
|
1135
|
+
*/
|
|
1136
|
+
declare class RemoteEndpointError extends WebAuthnError {
|
|
1137
|
+
readonly context: RemoteErrorContext;
|
|
1138
|
+
/**
|
|
1139
|
+
* Creates a new RemoteEndpointError.
|
|
1140
|
+
*
|
|
1141
|
+
* @param message Descriptive error message about the remote endpoint failure
|
|
1142
|
+
* @param context Contextual information about the failed request
|
|
1143
|
+
* @param originalError The original error that caused this remote endpoint error (optional)
|
|
1144
|
+
*/
|
|
1145
|
+
constructor(message: string, context: RemoteErrorContext, originalError?: Error);
|
|
1146
|
+
}
|
|
1147
|
+
/**
|
|
1148
|
+
* Error thrown when remote server returns invalid WebAuthn options.
|
|
1149
|
+
* This indicates the server response doesn't match expected WebAuthn option format.
|
|
1150
|
+
*
|
|
1151
|
+
* @example
|
|
1152
|
+
* ```typescript
|
|
1153
|
+
* try {
|
|
1154
|
+
* await webAuthnService.registerRemote(request);
|
|
1155
|
+
* } catch (error) {
|
|
1156
|
+
* if (error instanceof InvalidRemoteOptionsError) {
|
|
1157
|
+
* console.log('Invalid server response:', error.message);
|
|
1158
|
+
* }
|
|
1159
|
+
* }
|
|
1160
|
+
* ```
|
|
1161
|
+
*/
|
|
1162
|
+
declare class InvalidRemoteOptionsError extends WebAuthnError {
|
|
1163
|
+
/**
|
|
1164
|
+
* Creates a new InvalidRemoteOptionsError.
|
|
1165
|
+
*
|
|
1166
|
+
* @param message Descriptive error message about the invalid remote options
|
|
1167
|
+
* @param originalError The original error that revealed the invalid options (optional)
|
|
1168
|
+
*/
|
|
621
1169
|
constructor(message: string, originalError?: Error);
|
|
622
1170
|
}
|
|
623
1171
|
|
|
@@ -698,5 +1246,133 @@ declare function isJSONOptions(options: any): boolean;
|
|
|
698
1246
|
*/
|
|
699
1247
|
declare function isPublicKeyCredential(credential: Credential | null): credential is PublicKeyCredential;
|
|
700
1248
|
|
|
701
|
-
|
|
702
|
-
|
|
1249
|
+
/**
|
|
1250
|
+
* Utility functions for remote WebAuthn option validation
|
|
1251
|
+
*
|
|
1252
|
+
* These utilities provide comprehensive validation of server responses
|
|
1253
|
+
* to ensure they contain valid WebAuthn options before processing.
|
|
1254
|
+
* All validation is done without external dependencies for minimal
|
|
1255
|
+
* bundle size impact.
|
|
1256
|
+
*/
|
|
1257
|
+
/**
|
|
1258
|
+
* Validates that server response contains valid WebAuthn creation options.
|
|
1259
|
+
* Performs essential validation without external dependencies.
|
|
1260
|
+
*
|
|
1261
|
+
* @param options Response from registration endpoint
|
|
1262
|
+
* @throws {InvalidRemoteOptionsError} When options are invalid or incomplete
|
|
1263
|
+
*
|
|
1264
|
+
* @example
|
|
1265
|
+
* ```typescript
|
|
1266
|
+
* try {
|
|
1267
|
+
* validateRemoteCreationOptions(serverResponse);
|
|
1268
|
+
* // Options are valid, proceed with registration
|
|
1269
|
+
* } catch (error) {
|
|
1270
|
+
* console.error('Invalid server response:', error.message);
|
|
1271
|
+
* }
|
|
1272
|
+
* ```
|
|
1273
|
+
*/
|
|
1274
|
+
declare function validateRemoteCreationOptions(options: unknown): asserts options is PublicKeyCredentialCreationOptionsJSON;
|
|
1275
|
+
/**
|
|
1276
|
+
* Validates that server response contains valid WebAuthn request options.
|
|
1277
|
+
* Performs essential validation without external dependencies.
|
|
1278
|
+
*
|
|
1279
|
+
* @param options Response from authentication endpoint
|
|
1280
|
+
* @throws {InvalidRemoteOptionsError} When options are invalid or incomplete
|
|
1281
|
+
*
|
|
1282
|
+
* @example
|
|
1283
|
+
* ```typescript
|
|
1284
|
+
* try {
|
|
1285
|
+
* validateRemoteRequestOptions(serverResponse);
|
|
1286
|
+
* // Options are valid, proceed with authentication
|
|
1287
|
+
* } catch (error) {
|
|
1288
|
+
* console.error('Invalid server response:', error.message);
|
|
1289
|
+
* }
|
|
1290
|
+
* ```
|
|
1291
|
+
*/
|
|
1292
|
+
declare function validateRemoteRequestOptions(options: unknown): asserts options is PublicKeyCredentialRequestOptionsJSON;
|
|
1293
|
+
|
|
1294
|
+
/**
|
|
1295
|
+
* Type guard utilities for WebAuthn operations
|
|
1296
|
+
*
|
|
1297
|
+
* These functions help determine the type of input provided to WebAuthn operations,
|
|
1298
|
+
* enabling proper handling of different input formats (high-level configs vs native WebAuthn options).
|
|
1299
|
+
*/
|
|
1300
|
+
|
|
1301
|
+
/**
|
|
1302
|
+
* Type guard to determine if input is a high-level RegisterConfig object.
|
|
1303
|
+
* Distinguishes between RegisterConfig and direct WebAuthn creation options.
|
|
1304
|
+
*
|
|
1305
|
+
* @param input The input to check
|
|
1306
|
+
* @returns True if the input is a RegisterConfig, false otherwise
|
|
1307
|
+
*
|
|
1308
|
+
* @example
|
|
1309
|
+
* ```typescript
|
|
1310
|
+
* if (isRegisterConfig(input)) {
|
|
1311
|
+
* // Handle high-level config with preset support
|
|
1312
|
+
* const options = buildCreationOptionsFromConfig(input, config);
|
|
1313
|
+
* } else {
|
|
1314
|
+
* // Handle direct WebAuthn options
|
|
1315
|
+
* const options = parseRegistrationOptions(input);
|
|
1316
|
+
* }
|
|
1317
|
+
* ```
|
|
1318
|
+
*/
|
|
1319
|
+
declare function isRegisterConfig(input: unknown): input is RegisterConfig;
|
|
1320
|
+
/**
|
|
1321
|
+
* Type guard to determine if input is a high-level AuthenticateConfig object.
|
|
1322
|
+
* Distinguishes between AuthenticateConfig and direct WebAuthn request options.
|
|
1323
|
+
*
|
|
1324
|
+
* Uses the presence of 'username' or 'preset' fields and absence of WebAuthn-specific
|
|
1325
|
+
* fields ('rp', 'user') to identify AuthenticateConfig objects.
|
|
1326
|
+
*
|
|
1327
|
+
* @param input The input to check
|
|
1328
|
+
* @returns True if the input is an AuthenticateConfig, false otherwise
|
|
1329
|
+
*
|
|
1330
|
+
* @example
|
|
1331
|
+
* ```typescript
|
|
1332
|
+
* if (isAuthenticateConfig(input)) {
|
|
1333
|
+
* // Handle high-level config with preset support
|
|
1334
|
+
* const options = buildRequestOptionsFromConfig(input, config);
|
|
1335
|
+
* } else {
|
|
1336
|
+
* // Handle direct WebAuthn options
|
|
1337
|
+
* const options = parseAuthenticationOptions(input);
|
|
1338
|
+
* }
|
|
1339
|
+
* ```
|
|
1340
|
+
*/
|
|
1341
|
+
declare function isAuthenticateConfig(input: unknown): input is AuthenticateConfig;
|
|
1342
|
+
/**
|
|
1343
|
+
* Type guard to check if input contains WebAuthn creation options.
|
|
1344
|
+
* Identifies objects that have the structure of PublicKeyCredentialCreationOptions
|
|
1345
|
+
* by checking for required fields like 'rp' and 'user'.
|
|
1346
|
+
*
|
|
1347
|
+
* @param input The input to check
|
|
1348
|
+
* @returns True if the input has creation options structure, false otherwise
|
|
1349
|
+
*
|
|
1350
|
+
* @example
|
|
1351
|
+
* ```typescript
|
|
1352
|
+
* if (isCreationOptions(input)) {
|
|
1353
|
+
* // Input is already in WebAuthn format
|
|
1354
|
+
* return navigator.credentials.create({ publicKey: input });
|
|
1355
|
+
* }
|
|
1356
|
+
* ```
|
|
1357
|
+
*/
|
|
1358
|
+
declare function isCreationOptions(input: unknown): input is PublicKeyCredentialCreationOptions | PublicKeyCredentialCreationOptionsJSON;
|
|
1359
|
+
/**
|
|
1360
|
+
* Type guard to check if input contains WebAuthn request options.
|
|
1361
|
+
* Identifies objects that have the structure of PublicKeyCredentialRequestOptions
|
|
1362
|
+
* by checking for the required 'challenge' field.
|
|
1363
|
+
*
|
|
1364
|
+
* @param input The input to check
|
|
1365
|
+
* @returns True if the input has request options structure, false otherwise
|
|
1366
|
+
*
|
|
1367
|
+
* @example
|
|
1368
|
+
* ```typescript
|
|
1369
|
+
* if (isRequestOptions(input)) {
|
|
1370
|
+
* // Input is already in WebAuthn format
|
|
1371
|
+
* return navigator.credentials.get({ publicKey: input });
|
|
1372
|
+
* }
|
|
1373
|
+
* ```
|
|
1374
|
+
*/
|
|
1375
|
+
declare function isRequestOptions(input: unknown): input is PublicKeyCredentialRequestOptions | PublicKeyCredentialRequestOptionsJSON;
|
|
1376
|
+
|
|
1377
|
+
export { AuthenticatorError, DEFAULT_WEBAUTHN_CONFIG, EXTERNAL_SECURITY_KEY_PRESET, InvalidOptionsError, InvalidRemoteOptionsError, NetworkError, PASSKEY_PRESET, PLATFORM_AUTHENTICATOR_PRESET, PRESET_MAP, RemoteEndpointError, SecurityError, TimeoutError, UnsupportedOperationError, UserCancelledError, WEBAUTHN_CONFIG, WebAuthnError, WebAuthnErrorType, WebAuthnService, arrayBufferToBase64, arrayBufferToBase64url, arrayBufferToCredentialId, arrayBufferToString, base64ToArrayBuffer, base64urlToArrayBuffer, createWebAuthnConfig, credentialIdToArrayBuffer, generateChallenge, generateUserId, getDefaultPubKeyCredParams, getSupportedTransports, isAuthenticateConfig, isCreationOptions, isJSONOptions, isPlatformAuthenticatorAvailable, isPublicKeyCredential, isRegisterConfig, isRequestOptions, isWebAuthnSupported, provideWebAuthn, stringToArrayBuffer, validateRegistrationOptions, validateRemoteCreationOptions, validateRemoteRequestOptions };
|
|
1378
|
+
export type { AuthenticateConfig, AuthenticateInput, AuthenticationResponse, EnhancedRelyingParty, FlexibleChallenge, FlexibleCredentialDescriptors, FlexibleUserId, PresetName, RegisterConfig, RegisterInput, RegistrationResponse, RelyingPartyConfig, RemoteAuthenticationRequest, RemoteErrorContext, RemoteRegistrationRequest, WebAuthnAuthenticationResult, WebAuthnConfig, WebAuthnRegistrationResult, WebAuthnSupport };
|