ngx-webauthn 0.0.2
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 +412 -0
- package/fesm2022/ngx-webauthn.mjs +1058 -0
- package/fesm2022/ngx-webauthn.mjs.map +1 -0
- package/index.d.ts +702 -0
- package/package.json +23 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,702 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import * as i0 from '@angular/core';
|
|
3
|
+
import { InjectionToken, Provider } from '@angular/core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Preset for modern, passwordless, cross-device credentials.
|
|
7
|
+
*
|
|
8
|
+
* Best for: Passkey-based authentication where users can sync credentials
|
|
9
|
+
* across devices and use them for passwordless login.
|
|
10
|
+
*
|
|
11
|
+
* Features:
|
|
12
|
+
* - Requires resident keys (discoverable credentials)
|
|
13
|
+
* - Prefers user verification but doesn't require it
|
|
14
|
+
* - Works with both platform and cross-platform authenticators
|
|
15
|
+
* - Supports credential syncing across devices
|
|
16
|
+
*/
|
|
17
|
+
declare const PASSKEY_PRESET: {
|
|
18
|
+
readonly authenticatorSelection: {
|
|
19
|
+
readonly residentKey: "required";
|
|
20
|
+
readonly userVerification: "preferred";
|
|
21
|
+
};
|
|
22
|
+
readonly pubKeyCredParams: readonly [{
|
|
23
|
+
readonly type: "public-key";
|
|
24
|
+
readonly alg: -7;
|
|
25
|
+
}, {
|
|
26
|
+
readonly type: "public-key";
|
|
27
|
+
readonly alg: -257;
|
|
28
|
+
}];
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Preset for using a security key as a second factor after a password.
|
|
32
|
+
*
|
|
33
|
+
* Best for: Traditional 2FA scenarios where users already have a password
|
|
34
|
+
* and want to add hardware security key as a second factor.
|
|
35
|
+
*
|
|
36
|
+
* Features:
|
|
37
|
+
* - Discourages resident keys (server-side credential storage)
|
|
38
|
+
* - Prefers user verification
|
|
39
|
+
* - Favors cross-platform authenticators (USB/NFC security keys)
|
|
40
|
+
* - Credentials typically not synced between devices
|
|
41
|
+
*/
|
|
42
|
+
declare const SECOND_FACTOR_PRESET: {
|
|
43
|
+
readonly authenticatorSelection: {
|
|
44
|
+
readonly residentKey: "discouraged";
|
|
45
|
+
readonly userVerification: "preferred";
|
|
46
|
+
readonly authenticatorAttachment: "cross-platform";
|
|
47
|
+
};
|
|
48
|
+
readonly pubKeyCredParams: readonly [{
|
|
49
|
+
readonly type: "public-key";
|
|
50
|
+
readonly alg: -7;
|
|
51
|
+
}, {
|
|
52
|
+
readonly type: "public-key";
|
|
53
|
+
readonly alg: -257;
|
|
54
|
+
}];
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Preset for high-security, non-synced, single-device credentials.
|
|
58
|
+
*
|
|
59
|
+
* Best for: High-security scenarios where credentials must stay on a single
|
|
60
|
+
* device and user verification is mandatory.
|
|
61
|
+
*
|
|
62
|
+
* Features:
|
|
63
|
+
* - Requires platform authenticators (built-in biometrics/PIN)
|
|
64
|
+
* - Requires resident keys for discoverability
|
|
65
|
+
* - Requires user verification (biometric/PIN)
|
|
66
|
+
* - Credentials bound to specific device (no syncing)
|
|
67
|
+
*/
|
|
68
|
+
declare const DEVICE_BOUND_PRESET: {
|
|
69
|
+
readonly authenticatorSelection: {
|
|
70
|
+
readonly authenticatorAttachment: "platform";
|
|
71
|
+
readonly residentKey: "required";
|
|
72
|
+
readonly userVerification: "required";
|
|
73
|
+
};
|
|
74
|
+
readonly pubKeyCredParams: readonly [{
|
|
75
|
+
readonly type: "public-key";
|
|
76
|
+
readonly alg: -7;
|
|
77
|
+
}, {
|
|
78
|
+
readonly type: "public-key";
|
|
79
|
+
readonly alg: -257;
|
|
80
|
+
}];
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* Map of preset names to their configurations
|
|
84
|
+
* Used internally for preset resolution
|
|
85
|
+
*/
|
|
86
|
+
declare const PRESET_MAP: {
|
|
87
|
+
readonly passkey: {
|
|
88
|
+
readonly authenticatorSelection: {
|
|
89
|
+
readonly residentKey: "required";
|
|
90
|
+
readonly userVerification: "preferred";
|
|
91
|
+
};
|
|
92
|
+
readonly pubKeyCredParams: readonly [{
|
|
93
|
+
readonly type: "public-key";
|
|
94
|
+
readonly alg: -7;
|
|
95
|
+
}, {
|
|
96
|
+
readonly type: "public-key";
|
|
97
|
+
readonly alg: -257;
|
|
98
|
+
}];
|
|
99
|
+
};
|
|
100
|
+
readonly secondFactor: {
|
|
101
|
+
readonly authenticatorSelection: {
|
|
102
|
+
readonly residentKey: "discouraged";
|
|
103
|
+
readonly userVerification: "preferred";
|
|
104
|
+
readonly authenticatorAttachment: "cross-platform";
|
|
105
|
+
};
|
|
106
|
+
readonly pubKeyCredParams: readonly [{
|
|
107
|
+
readonly type: "public-key";
|
|
108
|
+
readonly alg: -7;
|
|
109
|
+
}, {
|
|
110
|
+
readonly type: "public-key";
|
|
111
|
+
readonly alg: -257;
|
|
112
|
+
}];
|
|
113
|
+
};
|
|
114
|
+
readonly deviceBound: {
|
|
115
|
+
readonly authenticatorSelection: {
|
|
116
|
+
readonly authenticatorAttachment: "platform";
|
|
117
|
+
readonly residentKey: "required";
|
|
118
|
+
readonly userVerification: "required";
|
|
119
|
+
};
|
|
120
|
+
readonly pubKeyCredParams: readonly [{
|
|
121
|
+
readonly type: "public-key";
|
|
122
|
+
readonly alg: -7;
|
|
123
|
+
}, {
|
|
124
|
+
readonly type: "public-key";
|
|
125
|
+
readonly alg: -257;
|
|
126
|
+
}];
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* Available preset names as a union type
|
|
131
|
+
*/
|
|
132
|
+
type PresetName = keyof typeof PRESET_MAP;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* High-level configuration interfaces for WebAuthn operations
|
|
136
|
+
*
|
|
137
|
+
* These interfaces provide a convenient, preset-driven API while still allowing
|
|
138
|
+
* full customization through override properties. They derive from standard WebAuthn
|
|
139
|
+
* types where possible to reduce duplication and ensure compatibility.
|
|
140
|
+
*/
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Relying party configuration using standard WebAuthn type
|
|
144
|
+
* No duplication needed - uses PublicKeyCredentialRpEntity directly
|
|
145
|
+
*/
|
|
146
|
+
type EnhancedRelyingParty = PublicKeyCredentialRpEntity;
|
|
147
|
+
/**
|
|
148
|
+
* Flexible user identifier that can be a string or Uint8Array
|
|
149
|
+
* Provides better DX while maintaining compatibility with WebAuthn standards
|
|
150
|
+
*/
|
|
151
|
+
type FlexibleUserId = string | Uint8Array;
|
|
152
|
+
/**
|
|
153
|
+
* Flexible challenge that can be a string or Uint8Array
|
|
154
|
+
* Provides better DX while maintaining compatibility with WebAuthn standards
|
|
155
|
+
*/
|
|
156
|
+
type FlexibleChallenge = string | Uint8Array;
|
|
157
|
+
/**
|
|
158
|
+
* Flexible credential descriptors that can be either full descriptors or just ID strings
|
|
159
|
+
* Provides better DX for common use cases while maintaining full flexibility
|
|
160
|
+
*/
|
|
161
|
+
type FlexibleCredentialDescriptors = PublicKeyCredentialDescriptor[] | string[];
|
|
162
|
+
/**
|
|
163
|
+
* Configuration for WebAuthn credential registration
|
|
164
|
+
*
|
|
165
|
+
* This interface extends standard WebAuthn types with preset support and enhanced UX.
|
|
166
|
+
* It derives from PublicKeyCredentialCreationOptions where possible to avoid duplication.
|
|
167
|
+
*/
|
|
168
|
+
interface RegisterConfig extends Partial<Pick<PublicKeyCredentialCreationOptions, 'timeout' | 'attestation' | 'authenticatorSelection' | 'pubKeyCredParams' | 'extensions'>> {
|
|
169
|
+
/**
|
|
170
|
+
* Username for the credential
|
|
171
|
+
* This is used to generate the user.name and user.id if not explicitly provided
|
|
172
|
+
*/
|
|
173
|
+
username: string;
|
|
174
|
+
/**
|
|
175
|
+
* Optional preset to use as base configuration
|
|
176
|
+
* - 'passkey': Modern passwordless, cross-device credentials
|
|
177
|
+
* - 'secondFactor': Security key as second factor after password
|
|
178
|
+
* - 'deviceBound': High-security, device-bound credentials
|
|
179
|
+
*/
|
|
180
|
+
preset?: PresetName;
|
|
181
|
+
/**
|
|
182
|
+
* Display name for the user (optional override)
|
|
183
|
+
* If not provided, defaults to the username
|
|
184
|
+
*/
|
|
185
|
+
displayName?: string;
|
|
186
|
+
/**
|
|
187
|
+
* Relying Party configuration (optional override)
|
|
188
|
+
* If not provided, will need to be set by the application or service
|
|
189
|
+
* Uses standard PublicKeyCredentialRpEntity structure
|
|
190
|
+
*/
|
|
191
|
+
rp?: EnhancedRelyingParty;
|
|
192
|
+
/**
|
|
193
|
+
* Challenge for the registration (optional override)
|
|
194
|
+
* If not provided, a secure random challenge will be generated
|
|
195
|
+
* Can be either base64url string or Uint8Array for better DX
|
|
196
|
+
*/
|
|
197
|
+
challenge?: FlexibleChallenge;
|
|
198
|
+
/**
|
|
199
|
+
* Credentials to exclude from registration (optional override)
|
|
200
|
+
* Can be an array of credential IDs (base64url strings) or full descriptors
|
|
201
|
+
* Enhanced to accept simple string arrays for better DX
|
|
202
|
+
*/
|
|
203
|
+
excludeCredentials?: FlexibleCredentialDescriptors;
|
|
204
|
+
/**
|
|
205
|
+
* User ID override (optional)
|
|
206
|
+
* If not provided, a user ID will be generated from the username
|
|
207
|
+
* Can be either base64url string or Uint8Array for better DX
|
|
208
|
+
*/
|
|
209
|
+
userId?: FlexibleUserId;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Configuration for WebAuthn authentication
|
|
213
|
+
*
|
|
214
|
+
* This interface extends standard WebAuthn types with preset support and enhanced UX.
|
|
215
|
+
* It derives from PublicKeyCredentialRequestOptions where possible to avoid duplication.
|
|
216
|
+
*/
|
|
217
|
+
interface AuthenticateConfig extends Partial<Pick<PublicKeyCredentialRequestOptions, 'timeout' | 'userVerification' | 'extensions'>> {
|
|
218
|
+
/**
|
|
219
|
+
* Optional username hint for discoverable credentials
|
|
220
|
+
* Not required for authentication, but can be used for user experience
|
|
221
|
+
*/
|
|
222
|
+
username?: string;
|
|
223
|
+
/**
|
|
224
|
+
* Optional preset to use as base configuration
|
|
225
|
+
* Affects user verification and other authentication parameters
|
|
226
|
+
*/
|
|
227
|
+
preset?: PresetName;
|
|
228
|
+
/**
|
|
229
|
+
* Challenge for the authentication (optional override)
|
|
230
|
+
* If not provided, a secure random challenge will be generated
|
|
231
|
+
* Can be either base64url string or Uint8Array for better DX
|
|
232
|
+
*/
|
|
233
|
+
challenge?: FlexibleChallenge;
|
|
234
|
+
/**
|
|
235
|
+
* Specific credentials to allow for authentication (optional override)
|
|
236
|
+
* Can be an array of credential IDs (base64url strings) or full descriptors
|
|
237
|
+
* If not provided, allows any credential (discoverable credential flow)
|
|
238
|
+
* Enhanced to accept simple string arrays for better DX
|
|
239
|
+
*/
|
|
240
|
+
allowCredentials?: FlexibleCredentialDescriptors;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Union type for all possible register inputs
|
|
244
|
+
* Supports both high-level config and direct WebAuthn options
|
|
245
|
+
*/
|
|
246
|
+
type RegisterInput = RegisterConfig | PublicKeyCredentialCreationOptions | PublicKeyCredentialCreationOptionsJSON;
|
|
247
|
+
/**
|
|
248
|
+
* Union type for all possible authenticate inputs
|
|
249
|
+
* Supports both high-level config and direct WebAuthn options
|
|
250
|
+
*/
|
|
251
|
+
type AuthenticateInput = AuthenticateConfig | PublicKeyCredentialRequestOptions | PublicKeyCredentialRequestOptionsJSON;
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Result of WebAuthn registration
|
|
255
|
+
* Simplified version with all ArrayBuffers converted to Base64URL strings
|
|
256
|
+
*/
|
|
257
|
+
interface WebAuthnRegistrationResult {
|
|
258
|
+
credentialId: string;
|
|
259
|
+
publicKey: string;
|
|
260
|
+
attestationObject: string;
|
|
261
|
+
clientDataJSON: string;
|
|
262
|
+
transports?: AuthenticatorTransport[];
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Result of WebAuthn authentication
|
|
266
|
+
* Simplified version with all ArrayBuffers converted to Base64URL strings
|
|
267
|
+
*/
|
|
268
|
+
interface WebAuthnAuthenticationResult {
|
|
269
|
+
credentialId: string;
|
|
270
|
+
authenticatorData: string;
|
|
271
|
+
clientDataJSON: string;
|
|
272
|
+
signature: string;
|
|
273
|
+
userHandle?: string;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Browser support information
|
|
277
|
+
*/
|
|
278
|
+
interface WebAuthnSupport {
|
|
279
|
+
isSupported: boolean;
|
|
280
|
+
isPlatformAuthenticatorAvailable: boolean;
|
|
281
|
+
supportedTransports: AuthenticatorTransport[];
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Enhanced registration response with clean, developer-friendly format
|
|
285
|
+
* Used by the new high-level register() method
|
|
286
|
+
*/
|
|
287
|
+
interface RegistrationResponse {
|
|
288
|
+
/**
|
|
289
|
+
* Whether the registration was successful
|
|
290
|
+
*/
|
|
291
|
+
success: boolean;
|
|
292
|
+
/**
|
|
293
|
+
* The credential ID as a base64url string
|
|
294
|
+
*/
|
|
295
|
+
credentialId: string;
|
|
296
|
+
/**
|
|
297
|
+
* The public key as a base64url string (if available)
|
|
298
|
+
* May be undefined if the algorithm is not supported by the user agent
|
|
299
|
+
*/
|
|
300
|
+
publicKey?: string;
|
|
301
|
+
/**
|
|
302
|
+
* Available transport methods for this credential
|
|
303
|
+
*/
|
|
304
|
+
transports?: AuthenticatorTransport[];
|
|
305
|
+
/**
|
|
306
|
+
* Raw WebAuthn response for advanced users who need access to all data
|
|
307
|
+
* This preserves backward compatibility and provides access to attestation objects, etc.
|
|
308
|
+
*/
|
|
309
|
+
rawResponse?: WebAuthnRegistrationResult;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Enhanced authentication response with clean, developer-friendly format
|
|
313
|
+
* Used by the new high-level authenticate() method
|
|
314
|
+
*/
|
|
315
|
+
interface AuthenticationResponse {
|
|
316
|
+
/**
|
|
317
|
+
* Whether the authentication was successful
|
|
318
|
+
*/
|
|
319
|
+
success: boolean;
|
|
320
|
+
/**
|
|
321
|
+
* The credential ID that was used for authentication
|
|
322
|
+
*/
|
|
323
|
+
credentialId: string;
|
|
324
|
+
/**
|
|
325
|
+
* The user handle associated with this credential (if available)
|
|
326
|
+
* This is useful for identifying the user in discoverable credential scenarios
|
|
327
|
+
*/
|
|
328
|
+
userHandle?: string;
|
|
329
|
+
/**
|
|
330
|
+
* Raw WebAuthn response for advanced users who need access to all data
|
|
331
|
+
* This preserves backward compatibility and provides access to signatures, etc.
|
|
332
|
+
*/
|
|
333
|
+
rawResponse?: WebAuthnAuthenticationResult;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Enhanced Angular service for WebAuthn operations
|
|
338
|
+
* Provides a clean abstraction over the WebAuthn API with RxJS observables
|
|
339
|
+
* and enhanced error handling
|
|
340
|
+
*/
|
|
341
|
+
declare class WebAuthnService {
|
|
342
|
+
private readonly config;
|
|
343
|
+
/**
|
|
344
|
+
* Checks if WebAuthn is supported in the current browser
|
|
345
|
+
*/
|
|
346
|
+
isSupported(): boolean;
|
|
347
|
+
/**
|
|
348
|
+
* Gets comprehensive WebAuthn support information
|
|
349
|
+
*/
|
|
350
|
+
getSupport(): Observable<WebAuthnSupport>;
|
|
351
|
+
/**
|
|
352
|
+
* Registers a new WebAuthn credential with flexible configuration support
|
|
353
|
+
*
|
|
354
|
+
* @param input Either a high-level RegisterConfig with presets, or direct WebAuthn creation options
|
|
355
|
+
* @returns Observable of RegistrationResponse with clean, developer-friendly format
|
|
356
|
+
*
|
|
357
|
+
* @example
|
|
358
|
+
* ```typescript
|
|
359
|
+
* // Simple preset usage
|
|
360
|
+
* this.webAuthnService.register({ username: 'john.doe', preset: 'passkey' });
|
|
361
|
+
*
|
|
362
|
+
* // Preset with overrides
|
|
363
|
+
* this.webAuthnService.register({
|
|
364
|
+
* username: 'john.doe',
|
|
365
|
+
* preset: 'passkey',
|
|
366
|
+
* authenticatorSelection: { userVerification: 'required' }
|
|
367
|
+
* });
|
|
368
|
+
*
|
|
369
|
+
* // Direct WebAuthn options (native)
|
|
370
|
+
* const nativeOptions: PublicKeyCredentialCreationOptions = {
|
|
371
|
+
* challenge: new Uint8Array([...]),
|
|
372
|
+
* rp: { name: "My App" },
|
|
373
|
+
* user: { id: new Uint8Array([...]), name: "user@example.com", displayName: "User" },
|
|
374
|
+
* pubKeyCredParams: [{ type: "public-key", alg: -7 }]
|
|
375
|
+
* };
|
|
376
|
+
* this.webAuthnService.register(nativeOptions);
|
|
377
|
+
*
|
|
378
|
+
* // Direct WebAuthn options (JSON)
|
|
379
|
+
* const jsonOptions: PublicKeyCredentialCreationOptionsJSON = {
|
|
380
|
+
* challenge: "Y2hhbGxlbmdl",
|
|
381
|
+
* rp: { name: "My App" },
|
|
382
|
+
* user: { id: "dXNlcklk", name: "user@example.com", displayName: "User" },
|
|
383
|
+
* pubKeyCredParams: [{ type: "public-key", alg: -7 }]
|
|
384
|
+
* };
|
|
385
|
+
* this.webAuthnService.register(jsonOptions);
|
|
386
|
+
* ```
|
|
387
|
+
*/
|
|
388
|
+
register(input: RegisterInput): Observable<RegistrationResponse>;
|
|
389
|
+
/**
|
|
390
|
+
* Authenticates using an existing WebAuthn credential with flexible configuration support
|
|
391
|
+
*
|
|
392
|
+
* @param input Either a high-level AuthenticateConfig with presets, or direct WebAuthn request options
|
|
393
|
+
* @returns Observable of AuthenticationResponse with clean, developer-friendly format
|
|
394
|
+
*
|
|
395
|
+
* @example
|
|
396
|
+
* ```typescript
|
|
397
|
+
* // Simple preset usage
|
|
398
|
+
* this.webAuthnService.authenticate({ preset: 'passkey' });
|
|
399
|
+
*
|
|
400
|
+
* // Config with credential filtering
|
|
401
|
+
* this.webAuthnService.authenticate({
|
|
402
|
+
* username: 'john.doe',
|
|
403
|
+
* preset: 'secondFactor',
|
|
404
|
+
* allowCredentials: ['credential-id-1', 'credential-id-2']
|
|
405
|
+
* });
|
|
406
|
+
*
|
|
407
|
+
* // Direct WebAuthn options (JSON)
|
|
408
|
+
* const jsonOptions: PublicKeyCredentialRequestOptionsJSON = {
|
|
409
|
+
* challenge: "Y2hhbGxlbmdl",
|
|
410
|
+
* allowCredentials: [{
|
|
411
|
+
* type: "public-key",
|
|
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
|
+
* }]
|
|
424
|
+
* };
|
|
425
|
+
* this.webAuthnService.authenticate(nativeOptions);
|
|
426
|
+
* ```
|
|
427
|
+
*/
|
|
428
|
+
authenticate(input: AuthenticateInput): Observable<AuthenticationResponse>;
|
|
429
|
+
/**
|
|
430
|
+
* Parses registration options, handling both JSON and native formats
|
|
431
|
+
*/
|
|
432
|
+
private parseRegistrationOptions;
|
|
433
|
+
/**
|
|
434
|
+
* Parses authentication options, handling both JSON and native formats
|
|
435
|
+
*/
|
|
436
|
+
private parseAuthenticationOptions;
|
|
437
|
+
/**
|
|
438
|
+
* Processes the raw credential result into a clean RegistrationResponse
|
|
439
|
+
*/
|
|
440
|
+
private processRegistrationResult;
|
|
441
|
+
/**
|
|
442
|
+
* Processes the raw credential result into a clean AuthenticationResponse
|
|
443
|
+
*/
|
|
444
|
+
private processAuthenticationResult;
|
|
445
|
+
/**
|
|
446
|
+
* Enhanced error handling that maps DOMExceptions to specific error types
|
|
447
|
+
*/
|
|
448
|
+
private handleWebAuthnError;
|
|
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 {
|
|
462
|
+
/**
|
|
463
|
+
* Human-readable identifier for the Relying Party
|
|
464
|
+
* @example "ACME Corporation"
|
|
465
|
+
*/
|
|
466
|
+
name: string;
|
|
467
|
+
/**
|
|
468
|
+
* A valid domain string that identifies the Relying Party on whose behalf a given registration or authentication ceremony is being performed
|
|
469
|
+
* @example "login.example.com" or "example.com"
|
|
470
|
+
*/
|
|
471
|
+
id?: string;
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Configuration interface for WebAuthn service
|
|
475
|
+
* Now includes required relying party information and advanced options
|
|
476
|
+
*/
|
|
477
|
+
interface WebAuthnConfig {
|
|
478
|
+
/**
|
|
479
|
+
* Required relying party information for WebAuthn operations
|
|
480
|
+
* This is critical for security - must be configured properly for production use
|
|
481
|
+
*/
|
|
482
|
+
relyingParty: RelyingPartyConfig;
|
|
483
|
+
/**
|
|
484
|
+
* Default timeout for WebAuthn operations in milliseconds
|
|
485
|
+
* @default 60000
|
|
486
|
+
*/
|
|
487
|
+
defaultTimeout?: number;
|
|
488
|
+
/**
|
|
489
|
+
* Default public key credential algorithms in order of preference
|
|
490
|
+
* @default [ES256, RS256]
|
|
491
|
+
*/
|
|
492
|
+
defaultAlgorithms?: PublicKeyCredentialParameters[];
|
|
493
|
+
/**
|
|
494
|
+
* Whether to enforce user verification by default
|
|
495
|
+
* @default false
|
|
496
|
+
*/
|
|
497
|
+
enforceUserVerification?: boolean;
|
|
498
|
+
/**
|
|
499
|
+
* Default attestation conveyance preference
|
|
500
|
+
* @default "none"
|
|
501
|
+
*/
|
|
502
|
+
defaultAttestation?: AttestationConveyancePreference;
|
|
503
|
+
/**
|
|
504
|
+
* Default authenticator selection criteria
|
|
505
|
+
*/
|
|
506
|
+
defaultAuthenticatorSelection?: AuthenticatorSelectionCriteria;
|
|
507
|
+
}
|
|
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
|
+
|
|
524
|
+
/**
|
|
525
|
+
* WebAuthn Providers
|
|
526
|
+
* Modern Angular standalone provider function for WebAuthn service
|
|
527
|
+
*/
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Provides WebAuthn service with required relying party configuration
|
|
531
|
+
*
|
|
532
|
+
* @param relyingParty Required relying party configuration
|
|
533
|
+
* @param config Optional configuration overrides
|
|
534
|
+
* @returns Array of providers for WebAuthn functionality
|
|
535
|
+
*
|
|
536
|
+
* @example
|
|
537
|
+
* ```typescript
|
|
538
|
+
* // main.ts
|
|
539
|
+
* bootstrapApplication(AppComponent, {
|
|
540
|
+
* providers: [
|
|
541
|
+
* provideWebAuthn(
|
|
542
|
+
* { name: 'My App', id: 'myapp.com' },
|
|
543
|
+
* { defaultTimeout: 30000 }
|
|
544
|
+
* )
|
|
545
|
+
* ]
|
|
546
|
+
* });
|
|
547
|
+
* ```
|
|
548
|
+
*/
|
|
549
|
+
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
|
+
|
|
556
|
+
/**
|
|
557
|
+
* Enhanced WebAuthn Error Classes
|
|
558
|
+
* Provides specific, actionable error types for better developer experience
|
|
559
|
+
*/
|
|
560
|
+
declare enum WebAuthnErrorType {
|
|
561
|
+
NOT_SUPPORTED = "NOT_SUPPORTED",
|
|
562
|
+
USER_CANCELLED = "USER_CANCELLED",
|
|
563
|
+
AUTHENTICATOR_ERROR = "AUTHENTICATOR_ERROR",
|
|
564
|
+
INVALID_OPTIONS = "INVALID_OPTIONS",
|
|
565
|
+
UNSUPPORTED_OPERATION = "UNSUPPORTED_OPERATION",
|
|
566
|
+
NETWORK_ERROR = "NETWORK_ERROR",
|
|
567
|
+
SECURITY_ERROR = "SECURITY_ERROR",
|
|
568
|
+
TIMEOUT_ERROR = "TIMEOUT_ERROR",
|
|
569
|
+
UNKNOWN = "UNKNOWN"
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* Base WebAuthn error class with additional context
|
|
573
|
+
*/
|
|
574
|
+
declare class WebAuthnError extends Error {
|
|
575
|
+
readonly type: WebAuthnErrorType;
|
|
576
|
+
readonly originalError?: Error | undefined;
|
|
577
|
+
constructor(type: WebAuthnErrorType, message: string, originalError?: Error | undefined);
|
|
578
|
+
static fromDOMException(error: DOMException): WebAuthnError;
|
|
579
|
+
private static mapDOMExceptionToType;
|
|
580
|
+
}
|
|
581
|
+
/**
|
|
582
|
+
* Error thrown when user cancels the WebAuthn operation
|
|
583
|
+
*/
|
|
584
|
+
declare class UserCancelledError extends WebAuthnError {
|
|
585
|
+
constructor(originalError?: Error);
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Error thrown when there's an issue with the authenticator
|
|
589
|
+
*/
|
|
590
|
+
declare class AuthenticatorError extends WebAuthnError {
|
|
591
|
+
constructor(message: string, originalError?: Error);
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Error thrown when the provided options are invalid
|
|
595
|
+
*/
|
|
596
|
+
declare class InvalidOptionsError extends WebAuthnError {
|
|
597
|
+
constructor(message: string, originalError?: Error);
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Error thrown when the requested operation is not supported
|
|
601
|
+
*/
|
|
602
|
+
declare class UnsupportedOperationError extends WebAuthnError {
|
|
603
|
+
constructor(message: string, originalError?: Error);
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* Error thrown when there's a network-related issue
|
|
607
|
+
*/
|
|
608
|
+
declare class NetworkError extends WebAuthnError {
|
|
609
|
+
constructor(message: string, originalError?: Error);
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* Error thrown when there's a security-related issue
|
|
613
|
+
*/
|
|
614
|
+
declare class SecurityError extends WebAuthnError {
|
|
615
|
+
constructor(message: string, originalError?: Error);
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Error thrown when the operation times out
|
|
619
|
+
*/
|
|
620
|
+
declare class TimeoutError extends WebAuthnError {
|
|
621
|
+
constructor(message: string, originalError?: Error);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
/**
|
|
625
|
+
* WebAuthn Utility Functions
|
|
626
|
+
* Centralized utilities for ArrayBuffer conversions and WebAuthn-specific operations
|
|
627
|
+
* This is the single source of truth for data transformation functions
|
|
628
|
+
*/
|
|
629
|
+
/**
|
|
630
|
+
* Converts a string to ArrayBuffer
|
|
631
|
+
*/
|
|
632
|
+
declare function stringToArrayBuffer(str: string): ArrayBuffer;
|
|
633
|
+
/**
|
|
634
|
+
* Converts ArrayBuffer to string
|
|
635
|
+
*/
|
|
636
|
+
declare function arrayBufferToString(buffer: ArrayBuffer): string;
|
|
637
|
+
/**
|
|
638
|
+
* Converts ArrayBuffer to base64 string
|
|
639
|
+
*/
|
|
640
|
+
declare function arrayBufferToBase64(buffer: ArrayBuffer): string;
|
|
641
|
+
/**
|
|
642
|
+
* Converts base64 string to ArrayBuffer
|
|
643
|
+
*/
|
|
644
|
+
declare function base64ToArrayBuffer(base64: string): ArrayBuffer;
|
|
645
|
+
/**
|
|
646
|
+
* Converts base64url string to ArrayBuffer
|
|
647
|
+
*/
|
|
648
|
+
declare function base64urlToArrayBuffer(base64url: string): ArrayBuffer;
|
|
649
|
+
/**
|
|
650
|
+
* Converts ArrayBuffer to base64url string
|
|
651
|
+
* This is the canonical implementation used throughout the library
|
|
652
|
+
*/
|
|
653
|
+
declare function arrayBufferToBase64url(buffer: ArrayBuffer): string;
|
|
654
|
+
/**
|
|
655
|
+
* Generates a random challenge as ArrayBuffer
|
|
656
|
+
*/
|
|
657
|
+
declare function generateChallenge(length?: number): ArrayBuffer;
|
|
658
|
+
/**
|
|
659
|
+
* Generates a random user ID as ArrayBuffer
|
|
660
|
+
*/
|
|
661
|
+
declare function generateUserId(length?: number): ArrayBuffer;
|
|
662
|
+
/**
|
|
663
|
+
* Converts credential ID string to ArrayBuffer for WebAuthn API
|
|
664
|
+
*/
|
|
665
|
+
declare function credentialIdToArrayBuffer(credentialId: string): ArrayBuffer;
|
|
666
|
+
/**
|
|
667
|
+
* Converts ArrayBuffer credential ID to string
|
|
668
|
+
*/
|
|
669
|
+
declare function arrayBufferToCredentialId(buffer: ArrayBuffer): string;
|
|
670
|
+
/**
|
|
671
|
+
* Checks if the current environment supports WebAuthn
|
|
672
|
+
*/
|
|
673
|
+
declare function isWebAuthnSupported(): boolean;
|
|
674
|
+
/**
|
|
675
|
+
* Checks if platform authenticator is available
|
|
676
|
+
*/
|
|
677
|
+
declare function isPlatformAuthenticatorAvailable(): Promise<boolean>;
|
|
678
|
+
/**
|
|
679
|
+
* Gets supported authenticator transports for this platform
|
|
680
|
+
* Enhanced detection with better browser compatibility
|
|
681
|
+
*/
|
|
682
|
+
declare function getSupportedTransports(): AuthenticatorTransport[];
|
|
683
|
+
/**
|
|
684
|
+
* Validates that required WebAuthn options are present
|
|
685
|
+
*/
|
|
686
|
+
declare function validateRegistrationOptions(options: any): void;
|
|
687
|
+
/**
|
|
688
|
+
* Creates default public key credential parameters
|
|
689
|
+
*/
|
|
690
|
+
declare function getDefaultPubKeyCredParams(): PublicKeyCredentialParameters[];
|
|
691
|
+
/**
|
|
692
|
+
* Enhanced type guard to detect JSON-formatted WebAuthn options
|
|
693
|
+
* More robust than simple challenge type checking
|
|
694
|
+
*/
|
|
695
|
+
declare function isJSONOptions(options: any): boolean;
|
|
696
|
+
/**
|
|
697
|
+
* Type guard to check if input is a PublicKeyCredential
|
|
698
|
+
*/
|
|
699
|
+
declare function isPublicKeyCredential(credential: Credential | null): credential is PublicKeyCredential;
|
|
700
|
+
|
|
701
|
+
export { AuthenticatorError, DEFAULT_WEBAUTHN_CONFIG, DEVICE_BOUND_PRESET, InvalidOptionsError, NetworkError, PASSKEY_PRESET, PRESET_MAP, SECOND_FACTOR_PRESET, SecurityError, TimeoutError, UnsupportedOperationError, UserCancelledError, WEBAUTHN_CONFIG, WebAuthnError, WebAuthnErrorType, WebAuthnService, arrayBufferToBase64, arrayBufferToBase64url, arrayBufferToCredentialId, arrayBufferToString, base64ToArrayBuffer, base64urlToArrayBuffer, createWebAuthnConfig, credentialIdToArrayBuffer, generateChallenge, generateUserId, getDefaultPubKeyCredParams, getSupportedTransports, isJSONOptions, isPlatformAuthenticatorAvailable, isPublicKeyCredential, isWebAuthnSupported, provideWebAuthn, provideWebAuthnLegacy, stringToArrayBuffer, validateRegistrationOptions };
|
|
702
|
+
export type { AuthenticateConfig, AuthenticateConfig as AuthenticateConfigModel, AuthenticateInput, AuthenticationResponse, PresetName, RegisterConfig, RegisterConfig as RegisterConfigModel, RegisterInput, RegistrationResponse, RelyingPartyConfig, WebAuthnAuthenticationResult, WebAuthnConfig, WebAuthnRegistrationResult, WebAuthnSupport };
|