@simplewebauthn/browser 11.0.0 → 13.0.0-alpha1
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 +33 -23
- package/dist/bundle/index.es5.umd.min.js +2 -2
- package/dist/bundle/index.umd.min.js +2 -2
- package/esm/helpers/base64URLStringToBuffer.d.ts +9 -0
- package/esm/helpers/base64URLStringToBuffer.d.ts.map +1 -0
- package/esm/helpers/base64URLStringToBuffer.js +29 -0
- package/esm/helpers/browserSupportsWebAuthn.d.ts +12 -0
- package/esm/helpers/browserSupportsWebAuthn.d.ts.map +1 -0
- package/esm/helpers/browserSupportsWebAuthn.js +14 -0
- package/esm/helpers/browserSupportsWebAuthnAutofill.d.ts +9 -0
- package/esm/helpers/browserSupportsWebAuthnAutofill.d.ts.map +1 -0
- package/esm/helpers/browserSupportsWebAuthnAutofill.js +26 -0
- package/esm/helpers/bufferToBase64URLString.d.ts +8 -0
- package/esm/helpers/bufferToBase64URLString.d.ts.map +1 -0
- package/esm/helpers/bufferToBase64URLString.js +15 -0
- package/esm/helpers/identifyAuthenticationError.d.ts +9 -0
- package/esm/helpers/identifyAuthenticationError.d.ts.map +1 -0
- package/esm/helpers/identifyAuthenticationError.js +61 -0
- package/esm/helpers/identifyRegistrationError.d.ts +9 -0
- package/esm/helpers/identifyRegistrationError.d.ts.map +1 -0
- package/esm/helpers/identifyRegistrationError.js +126 -0
- package/esm/helpers/isValidDomain.d.ts +10 -0
- package/esm/helpers/isValidDomain.d.ts.map +1 -0
- package/esm/helpers/isValidDomain.js +14 -0
- package/esm/helpers/platformAuthenticatorIsAvailable.d.ts +8 -0
- package/esm/helpers/platformAuthenticatorIsAvailable.d.ts.map +1 -0
- package/esm/helpers/platformAuthenticatorIsAvailable.js +13 -0
- package/esm/helpers/toAuthenticatorAttachment.d.ts +6 -0
- package/esm/helpers/toAuthenticatorAttachment.d.ts.map +1 -0
- package/esm/helpers/toAuthenticatorAttachment.js +13 -0
- package/esm/helpers/toPublicKeyCredentialDescriptor.d.ts +3 -0
- package/esm/helpers/toPublicKeyCredentialDescriptor.d.ts.map +1 -0
- package/esm/helpers/toPublicKeyCredentialDescriptor.js +14 -0
- package/esm/helpers/webAuthnAbortService.d.ts +22 -0
- package/esm/helpers/webAuthnAbortService.d.ts.map +1 -0
- package/esm/helpers/webAuthnAbortService.js +37 -0
- package/{dist/types → esm}/helpers/webAuthnError.d.ts +18 -0
- package/esm/helpers/webAuthnError.d.ts.map +1 -0
- package/esm/helpers/webAuthnError.js +31 -0
- package/esm/index.d.ts +11 -0
- package/esm/index.d.ts.map +1 -0
- package/esm/index.js +10 -0
- package/esm/methods/startAuthentication.d.ts +15 -0
- package/esm/methods/startAuthentication.d.ts.map +1 -0
- package/esm/methods/startAuthentication.js +89 -0
- package/esm/methods/startRegistration.d.ts +13 -0
- package/esm/methods/startRegistration.d.ts.map +1 -0
- package/esm/methods/startRegistration.js +115 -0
- package/esm/package.json +3 -0
- package/esm/types/dom.d.ts +329 -0
- package/esm/types/dom.d.ts.map +1 -0
- package/esm/types/dom.js +1 -0
- package/esm/types/index.d.ts +205 -0
- package/esm/types/index.d.ts.map +1 -0
- package/esm/types/index.js +1 -0
- package/package.json +25 -31
- package/script/helpers/base64URLStringToBuffer.d.ts +9 -0
- package/script/helpers/base64URLStringToBuffer.d.ts.map +1 -0
- package/script/helpers/base64URLStringToBuffer.js +32 -0
- package/script/helpers/browserSupportsWebAuthn.d.ts +12 -0
- package/script/helpers/browserSupportsWebAuthn.d.ts.map +1 -0
- package/script/helpers/browserSupportsWebAuthn.js +18 -0
- package/script/helpers/browserSupportsWebAuthnAutofill.d.ts +9 -0
- package/script/helpers/browserSupportsWebAuthnAutofill.d.ts.map +1 -0
- package/script/helpers/browserSupportsWebAuthnAutofill.js +30 -0
- package/script/helpers/bufferToBase64URLString.d.ts +8 -0
- package/script/helpers/bufferToBase64URLString.d.ts.map +1 -0
- package/script/helpers/bufferToBase64URLString.js +18 -0
- package/script/helpers/identifyAuthenticationError.d.ts +9 -0
- package/script/helpers/identifyAuthenticationError.d.ts.map +1 -0
- package/script/helpers/identifyAuthenticationError.js +64 -0
- package/script/helpers/identifyRegistrationError.d.ts +9 -0
- package/script/helpers/identifyRegistrationError.d.ts.map +1 -0
- package/script/helpers/identifyRegistrationError.js +129 -0
- package/script/helpers/isValidDomain.d.ts +10 -0
- package/script/helpers/isValidDomain.d.ts.map +1 -0
- package/script/helpers/isValidDomain.js +17 -0
- package/script/helpers/platformAuthenticatorIsAvailable.d.ts +8 -0
- package/script/helpers/platformAuthenticatorIsAvailable.d.ts.map +1 -0
- package/script/helpers/platformAuthenticatorIsAvailable.js +16 -0
- package/script/helpers/toAuthenticatorAttachment.d.ts +6 -0
- package/script/helpers/toAuthenticatorAttachment.d.ts.map +1 -0
- package/script/helpers/toAuthenticatorAttachment.js +16 -0
- package/script/helpers/toPublicKeyCredentialDescriptor.d.ts +3 -0
- package/script/helpers/toPublicKeyCredentialDescriptor.d.ts.map +1 -0
- package/script/helpers/toPublicKeyCredentialDescriptor.js +17 -0
- package/script/helpers/webAuthnAbortService.d.ts +22 -0
- package/script/helpers/webAuthnAbortService.d.ts.map +1 -0
- package/script/helpers/webAuthnAbortService.js +40 -0
- package/script/helpers/webAuthnError.d.ts +28 -0
- package/script/helpers/webAuthnError.d.ts.map +1 -0
- package/script/helpers/webAuthnError.js +35 -0
- package/script/index.d.ts +11 -0
- package/script/index.d.ts.map +1 -0
- package/script/index.js +26 -0
- package/script/methods/startAuthentication.d.ts +15 -0
- package/script/methods/startAuthentication.d.ts.map +1 -0
- package/script/methods/startAuthentication.js +92 -0
- package/script/methods/startRegistration.d.ts +13 -0
- package/script/methods/startRegistration.d.ts.map +1 -0
- package/script/methods/startRegistration.js +118 -0
- package/script/package.json +3 -0
- package/script/types/dom.d.ts +329 -0
- package/script/types/dom.d.ts.map +1 -0
- package/script/types/dom.js +2 -0
- package/script/types/index.d.ts +205 -0
- package/script/types/index.d.ts.map +1 -0
- package/script/types/index.js +2 -0
- package/dist/bundle/index.js +0 -398
- package/dist/types/helpers/base64URLStringToBuffer.d.ts +0 -1
- package/dist/types/helpers/browserSupportsWebAuthn.d.ts +0 -1
- package/dist/types/helpers/browserSupportsWebAuthnAutofill.d.ts +0 -1
- package/dist/types/helpers/bufferToBase64URLString.d.ts +0 -1
- package/dist/types/helpers/identifyAuthenticationError.d.ts +0 -5
- package/dist/types/helpers/identifyRegistrationError.d.ts +0 -5
- package/dist/types/helpers/isValidDomain.d.ts +0 -1
- package/dist/types/helpers/platformAuthenticatorIsAvailable.d.ts +0 -1
- package/dist/types/helpers/toAuthenticatorAttachment.d.ts +0 -2
- package/dist/types/helpers/toPublicKeyCredentialDescriptor.d.ts +0 -2
- package/dist/types/helpers/webAuthnAbortService.d.ts +0 -7
- package/dist/types/index.d.ts +0 -11
- package/dist/types/methods/startAuthentication.d.ts +0 -7
- package/dist/types/methods/startRegistration.d.ts +0 -6
- package/jest-environment.js +0 -29
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DO NOT MODIFY THESE FILES!
|
|
3
|
+
*
|
|
4
|
+
* These files were copied from the **types** package. To update this file, make changes to those
|
|
5
|
+
* files instead and then run the following command from the monorepo root folder:
|
|
6
|
+
*
|
|
7
|
+
* deno task codegen:types
|
|
8
|
+
*/
|
|
9
|
+
import type { AttestationConveyancePreference, AuthenticationExtensionsClientInputs, AuthenticationExtensionsClientOutputs, AuthenticatorAssertionResponse, AuthenticatorAttachment, AuthenticatorAttestationResponse, AuthenticatorSelectionCriteria, COSEAlgorithmIdentifier, PublicKeyCredential, PublicKeyCredentialCreationOptions, PublicKeyCredentialDescriptor, PublicKeyCredentialParameters, PublicKeyCredentialRequestOptions, PublicKeyCredentialRpEntity, PublicKeyCredentialType, UserVerificationRequirement } from './dom.js';
|
|
10
|
+
export type { AttestationConveyancePreference, AuthenticationExtensionsClientInputs, AuthenticationExtensionsClientOutputs, AuthenticatorAssertionResponse, AuthenticatorAttachment, AuthenticatorAttestationResponse, AuthenticatorSelectionCriteria, AuthenticatorTransport, COSEAlgorithmIdentifier, Crypto, PublicKeyCredential, PublicKeyCredentialCreationOptions, PublicKeyCredentialDescriptor, PublicKeyCredentialParameters, PublicKeyCredentialRequestOptions, PublicKeyCredentialRpEntity, PublicKeyCredentialType, PublicKeyCredentialUserEntity, UserVerificationRequirement, } from './dom.js';
|
|
11
|
+
/**
|
|
12
|
+
* A variant of PublicKeyCredentialCreationOptions suitable for JSON transmission to the browser to
|
|
13
|
+
* (eventually) get passed into navigator.credentials.create(...) in the browser.
|
|
14
|
+
*
|
|
15
|
+
* This should eventually get replaced with official TypeScript DOM types when WebAuthn L3 types
|
|
16
|
+
* eventually make it into the language:
|
|
17
|
+
*
|
|
18
|
+
* https://w3c.github.io/webauthn/#dictdef-publickeycredentialcreationoptionsjson
|
|
19
|
+
*/
|
|
20
|
+
export interface PublicKeyCredentialCreationOptionsJSON {
|
|
21
|
+
rp: PublicKeyCredentialRpEntity;
|
|
22
|
+
user: PublicKeyCredentialUserEntityJSON;
|
|
23
|
+
challenge: Base64URLString;
|
|
24
|
+
pubKeyCredParams: PublicKeyCredentialParameters[];
|
|
25
|
+
timeout?: number;
|
|
26
|
+
excludeCredentials?: PublicKeyCredentialDescriptorJSON[];
|
|
27
|
+
authenticatorSelection?: AuthenticatorSelectionCriteria;
|
|
28
|
+
hints?: PublicKeyCredentialHint[];
|
|
29
|
+
attestation?: AttestationConveyancePreference;
|
|
30
|
+
attestationFormats?: AttestationFormat[];
|
|
31
|
+
extensions?: AuthenticationExtensionsClientInputs;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A variant of PublicKeyCredentialRequestOptions suitable for JSON transmission to the browser to
|
|
35
|
+
* (eventually) get passed into navigator.credentials.get(...) in the browser.
|
|
36
|
+
*/
|
|
37
|
+
export interface PublicKeyCredentialRequestOptionsJSON {
|
|
38
|
+
challenge: Base64URLString;
|
|
39
|
+
timeout?: number;
|
|
40
|
+
rpId?: string;
|
|
41
|
+
allowCredentials?: PublicKeyCredentialDescriptorJSON[];
|
|
42
|
+
userVerification?: UserVerificationRequirement;
|
|
43
|
+
hints?: PublicKeyCredentialHint[];
|
|
44
|
+
extensions?: AuthenticationExtensionsClientInputs;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* https://w3c.github.io/webauthn/#dictdef-publickeycredentialdescriptorjson
|
|
48
|
+
*/
|
|
49
|
+
export interface PublicKeyCredentialDescriptorJSON {
|
|
50
|
+
id: Base64URLString;
|
|
51
|
+
type: PublicKeyCredentialType;
|
|
52
|
+
transports?: AuthenticatorTransportFuture[];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* https://w3c.github.io/webauthn/#dictdef-publickeycredentialuserentityjson
|
|
56
|
+
*/
|
|
57
|
+
export interface PublicKeyCredentialUserEntityJSON {
|
|
58
|
+
id: string;
|
|
59
|
+
name: string;
|
|
60
|
+
displayName: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* The value returned from navigator.credentials.create()
|
|
64
|
+
*/
|
|
65
|
+
export interface RegistrationCredential extends PublicKeyCredentialFuture {
|
|
66
|
+
response: AuthenticatorAttestationResponseFuture;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A slightly-modified RegistrationCredential to simplify working with ArrayBuffers that
|
|
70
|
+
* are Base64URL-encoded in the browser so that they can be sent as JSON to the server.
|
|
71
|
+
*
|
|
72
|
+
* https://w3c.github.io/webauthn/#dictdef-registrationresponsejson
|
|
73
|
+
*/
|
|
74
|
+
export interface RegistrationResponseJSON {
|
|
75
|
+
id: Base64URLString;
|
|
76
|
+
rawId: Base64URLString;
|
|
77
|
+
response: AuthenticatorAttestationResponseJSON;
|
|
78
|
+
authenticatorAttachment?: AuthenticatorAttachment;
|
|
79
|
+
clientExtensionResults: AuthenticationExtensionsClientOutputs;
|
|
80
|
+
type: PublicKeyCredentialType;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The value returned from navigator.credentials.get()
|
|
84
|
+
*/
|
|
85
|
+
export interface AuthenticationCredential extends PublicKeyCredentialFuture {
|
|
86
|
+
response: AuthenticatorAssertionResponse;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* A slightly-modified AuthenticationCredential to simplify working with ArrayBuffers that
|
|
90
|
+
* are Base64URL-encoded in the browser so that they can be sent as JSON to the server.
|
|
91
|
+
*
|
|
92
|
+
* https://w3c.github.io/webauthn/#dictdef-authenticationresponsejson
|
|
93
|
+
*/
|
|
94
|
+
export interface AuthenticationResponseJSON {
|
|
95
|
+
id: Base64URLString;
|
|
96
|
+
rawId: Base64URLString;
|
|
97
|
+
response: AuthenticatorAssertionResponseJSON;
|
|
98
|
+
authenticatorAttachment?: AuthenticatorAttachment;
|
|
99
|
+
clientExtensionResults: AuthenticationExtensionsClientOutputs;
|
|
100
|
+
type: PublicKeyCredentialType;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* A slightly-modified AuthenticatorAttestationResponse to simplify working with ArrayBuffers that
|
|
104
|
+
* are Base64URL-encoded in the browser so that they can be sent as JSON to the server.
|
|
105
|
+
*
|
|
106
|
+
* https://w3c.github.io/webauthn/#dictdef-authenticatorattestationresponsejson
|
|
107
|
+
*/
|
|
108
|
+
export interface AuthenticatorAttestationResponseJSON {
|
|
109
|
+
clientDataJSON: Base64URLString;
|
|
110
|
+
attestationObject: Base64URLString;
|
|
111
|
+
authenticatorData?: Base64URLString;
|
|
112
|
+
transports?: AuthenticatorTransportFuture[];
|
|
113
|
+
publicKeyAlgorithm?: COSEAlgorithmIdentifier;
|
|
114
|
+
publicKey?: Base64URLString;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* A slightly-modified AuthenticatorAssertionResponse to simplify working with ArrayBuffers that
|
|
118
|
+
* are Base64URL-encoded in the browser so that they can be sent as JSON to the server.
|
|
119
|
+
*
|
|
120
|
+
* https://w3c.github.io/webauthn/#dictdef-authenticatorassertionresponsejson
|
|
121
|
+
*/
|
|
122
|
+
export interface AuthenticatorAssertionResponseJSON {
|
|
123
|
+
clientDataJSON: Base64URLString;
|
|
124
|
+
authenticatorData: Base64URLString;
|
|
125
|
+
signature: Base64URLString;
|
|
126
|
+
userHandle?: Base64URLString;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Public key credential information needed to verify authentication responses
|
|
130
|
+
*/
|
|
131
|
+
export type WebAuthnCredential = {
|
|
132
|
+
id: Base64URLString;
|
|
133
|
+
publicKey: Uint8Array;
|
|
134
|
+
counter: number;
|
|
135
|
+
transports?: AuthenticatorTransportFuture[];
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* An attempt to communicate that this isn't just any string, but a Base64URL-encoded string
|
|
139
|
+
*/
|
|
140
|
+
export type Base64URLString = string;
|
|
141
|
+
/**
|
|
142
|
+
* AuthenticatorAttestationResponse in TypeScript's DOM lib is outdated (up through v3.9.7).
|
|
143
|
+
* Maintain an augmented version here so we can implement additional properties as the WebAuthn
|
|
144
|
+
* spec evolves.
|
|
145
|
+
*
|
|
146
|
+
* See https://www.w3.org/TR/webauthn-2/#iface-authenticatorattestationresponse
|
|
147
|
+
*
|
|
148
|
+
* Properties marked optional are not supported in all browsers.
|
|
149
|
+
*/
|
|
150
|
+
export interface AuthenticatorAttestationResponseFuture extends AuthenticatorAttestationResponse {
|
|
151
|
+
getTransports(): AuthenticatorTransportFuture[];
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* A super class of TypeScript's `AuthenticatorTransport` that includes support for the latest
|
|
155
|
+
* transports. Should eventually be replaced by TypeScript's when TypeScript gets updated to
|
|
156
|
+
* know about it (sometime after 4.6.3)
|
|
157
|
+
*/
|
|
158
|
+
export type AuthenticatorTransportFuture = 'ble' | 'cable' | 'hybrid' | 'internal' | 'nfc' | 'smart-card' | 'usb';
|
|
159
|
+
/**
|
|
160
|
+
* A super class of TypeScript's `PublicKeyCredentialDescriptor` that knows about the latest
|
|
161
|
+
* transports. Should eventually be replaced by TypeScript's when TypeScript gets updated to
|
|
162
|
+
* know about it (sometime after 4.6.3)
|
|
163
|
+
*/
|
|
164
|
+
export interface PublicKeyCredentialDescriptorFuture extends Omit<PublicKeyCredentialDescriptor, 'transports'> {
|
|
165
|
+
transports?: AuthenticatorTransportFuture[];
|
|
166
|
+
}
|
|
167
|
+
/** */
|
|
168
|
+
export type PublicKeyCredentialJSON = RegistrationResponseJSON | AuthenticationResponseJSON;
|
|
169
|
+
/**
|
|
170
|
+
* A super class of TypeScript's `PublicKeyCredential` that knows about upcoming WebAuthn features
|
|
171
|
+
*/
|
|
172
|
+
export interface PublicKeyCredentialFuture extends PublicKeyCredential {
|
|
173
|
+
type: PublicKeyCredentialType;
|
|
174
|
+
isConditionalMediationAvailable?(): Promise<boolean>;
|
|
175
|
+
parseCreationOptionsFromJSON?(options: PublicKeyCredentialCreationOptionsJSON): PublicKeyCredentialCreationOptions;
|
|
176
|
+
parseRequestOptionsFromJSON?(options: PublicKeyCredentialRequestOptionsJSON): PublicKeyCredentialRequestOptions;
|
|
177
|
+
toJSON?(): PublicKeyCredentialJSON;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* The two types of credentials as defined by bit 3 ("Backup Eligibility") in authenticator data:
|
|
181
|
+
* - `"singleDevice"` credentials will never be backed up
|
|
182
|
+
* - `"multiDevice"` credentials can be backed up
|
|
183
|
+
*/
|
|
184
|
+
export type CredentialDeviceType = 'singleDevice' | 'multiDevice';
|
|
185
|
+
/**
|
|
186
|
+
* Categories of authenticators that Relying Parties can pass along to browsers during
|
|
187
|
+
* registration. Browsers that understand these values can optimize their modal experience to
|
|
188
|
+
* start the user off in a particular registration flow:
|
|
189
|
+
*
|
|
190
|
+
* - `hybrid`: A platform authenticator on a mobile device
|
|
191
|
+
* - `security-key`: A portable FIDO2 authenticator capable of being used on multiple devices via a USB or NFC connection
|
|
192
|
+
* - `client-device`: The device that WebAuthn is being called on. Typically synonymous with platform authenticators
|
|
193
|
+
*
|
|
194
|
+
* See https://w3c.github.io/webauthn/#enumdef-publickeycredentialhint
|
|
195
|
+
*
|
|
196
|
+
* These values are less strict than `authenticatorAttachment`
|
|
197
|
+
*/
|
|
198
|
+
export type PublicKeyCredentialHint = 'hybrid' | 'security-key' | 'client-device';
|
|
199
|
+
/**
|
|
200
|
+
* Values for an attestation object's `fmt`
|
|
201
|
+
*
|
|
202
|
+
* See https://www.iana.org/assignments/webauthn/webauthn.xhtml#webauthn-attestation-statement-format-ids
|
|
203
|
+
*/
|
|
204
|
+
export type AttestationFormat = 'fido-u2f' | 'packed' | 'android-safetynet' | 'android-key' | 'tpm' | 'apple' | 'none';
|
|
205
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"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"}
|
package/dist/bundle/index.js
DELETED
|
@@ -1,398 +0,0 @@
|
|
|
1
|
-
/* [@simplewebauthn/browser@11.0.0] */
|
|
2
|
-
function bufferToBase64URLString(buffer) {
|
|
3
|
-
const bytes = new Uint8Array(buffer);
|
|
4
|
-
let str = '';
|
|
5
|
-
for (const charCode of bytes) {
|
|
6
|
-
str += String.fromCharCode(charCode);
|
|
7
|
-
}
|
|
8
|
-
const base64String = btoa(str);
|
|
9
|
-
return base64String.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
function base64URLStringToBuffer(base64URLString) {
|
|
13
|
-
const base64 = base64URLString.replace(/-/g, '+').replace(/_/g, '/');
|
|
14
|
-
const padLength = (4 - (base64.length % 4)) % 4;
|
|
15
|
-
const padded = base64.padEnd(base64.length + padLength, '=');
|
|
16
|
-
const binary = atob(padded);
|
|
17
|
-
const buffer = new ArrayBuffer(binary.length);
|
|
18
|
-
const bytes = new Uint8Array(buffer);
|
|
19
|
-
for (let i = 0; i < binary.length; i++) {
|
|
20
|
-
bytes[i] = binary.charCodeAt(i);
|
|
21
|
-
}
|
|
22
|
-
return buffer;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function browserSupportsWebAuthn() {
|
|
26
|
-
return (window?.PublicKeyCredential !== undefined &&
|
|
27
|
-
typeof window.PublicKeyCredential === 'function');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function toPublicKeyCredentialDescriptor(descriptor) {
|
|
31
|
-
const { id } = descriptor;
|
|
32
|
-
return {
|
|
33
|
-
...descriptor,
|
|
34
|
-
id: base64URLStringToBuffer(id),
|
|
35
|
-
transports: descriptor.transports,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function isValidDomain(hostname) {
|
|
40
|
-
return (hostname === 'localhost' ||
|
|
41
|
-
/^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(hostname));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
class WebAuthnError extends Error {
|
|
45
|
-
constructor({ message, code, cause, name, }) {
|
|
46
|
-
super(message, { cause });
|
|
47
|
-
this.name = name ?? cause.name;
|
|
48
|
-
this.code = code;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function identifyRegistrationError({ error, options, }) {
|
|
53
|
-
const { publicKey } = options;
|
|
54
|
-
if (!publicKey) {
|
|
55
|
-
throw Error('options was missing required publicKey property');
|
|
56
|
-
}
|
|
57
|
-
if (error.name === 'AbortError') {
|
|
58
|
-
if (options.signal instanceof AbortSignal) {
|
|
59
|
-
return new WebAuthnError({
|
|
60
|
-
message: 'Registration ceremony was sent an abort signal',
|
|
61
|
-
code: 'ERROR_CEREMONY_ABORTED',
|
|
62
|
-
cause: error,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
else if (error.name === 'ConstraintError') {
|
|
67
|
-
if (publicKey.authenticatorSelection?.requireResidentKey === true) {
|
|
68
|
-
return new WebAuthnError({
|
|
69
|
-
message: 'Discoverable credentials were required but no available authenticator supported it',
|
|
70
|
-
code: 'ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT',
|
|
71
|
-
cause: error,
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
else if (options.mediation === 'conditional' &&
|
|
75
|
-
publicKey.authenticatorSelection?.userVerification === 'required') {
|
|
76
|
-
return new WebAuthnError({
|
|
77
|
-
message: 'User verification was required during automatic registration but it could not be performed',
|
|
78
|
-
code: 'ERROR_AUTO_REGISTER_USER_VERIFICATION_FAILURE',
|
|
79
|
-
cause: error,
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
else if (publicKey.authenticatorSelection?.userVerification === 'required') {
|
|
83
|
-
return new WebAuthnError({
|
|
84
|
-
message: 'User verification was required but no available authenticator supported it',
|
|
85
|
-
code: 'ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT',
|
|
86
|
-
cause: error,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
else if (error.name === 'InvalidStateError') {
|
|
91
|
-
return new WebAuthnError({
|
|
92
|
-
message: 'The authenticator was previously registered',
|
|
93
|
-
code: 'ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED',
|
|
94
|
-
cause: error,
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
else if (error.name === 'NotAllowedError') {
|
|
98
|
-
return new WebAuthnError({
|
|
99
|
-
message: error.message,
|
|
100
|
-
code: 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY',
|
|
101
|
-
cause: error,
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
else if (error.name === 'NotSupportedError') {
|
|
105
|
-
const validPubKeyCredParams = publicKey.pubKeyCredParams.filter((param) => param.type === 'public-key');
|
|
106
|
-
if (validPubKeyCredParams.length === 0) {
|
|
107
|
-
return new WebAuthnError({
|
|
108
|
-
message: 'No entry in pubKeyCredParams was of type "public-key"',
|
|
109
|
-
code: 'ERROR_MALFORMED_PUBKEYCREDPARAMS',
|
|
110
|
-
cause: error,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
return new WebAuthnError({
|
|
114
|
-
message: 'No available authenticator supported any of the specified pubKeyCredParams algorithms',
|
|
115
|
-
code: 'ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG',
|
|
116
|
-
cause: error,
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
else if (error.name === 'SecurityError') {
|
|
120
|
-
const effectiveDomain = window.location.hostname;
|
|
121
|
-
if (!isValidDomain(effectiveDomain)) {
|
|
122
|
-
return new WebAuthnError({
|
|
123
|
-
message: `${window.location.hostname} is an invalid domain`,
|
|
124
|
-
code: 'ERROR_INVALID_DOMAIN',
|
|
125
|
-
cause: error,
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
else if (publicKey.rp.id !== effectiveDomain) {
|
|
129
|
-
return new WebAuthnError({
|
|
130
|
-
message: `The RP ID "${publicKey.rp.id}" is invalid for this domain`,
|
|
131
|
-
code: 'ERROR_INVALID_RP_ID',
|
|
132
|
-
cause: error,
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
else if (error.name === 'TypeError') {
|
|
137
|
-
if (publicKey.user.id.byteLength < 1 || publicKey.user.id.byteLength > 64) {
|
|
138
|
-
return new WebAuthnError({
|
|
139
|
-
message: 'User ID was not between 1 and 64 characters',
|
|
140
|
-
code: 'ERROR_INVALID_USER_ID_LENGTH',
|
|
141
|
-
cause: error,
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
else if (error.name === 'UnknownError') {
|
|
146
|
-
return new WebAuthnError({
|
|
147
|
-
message: 'The authenticator was unable to process the specified options, or could not create a new credential',
|
|
148
|
-
code: 'ERROR_AUTHENTICATOR_GENERAL_ERROR',
|
|
149
|
-
cause: error,
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
return error;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
class BaseWebAuthnAbortService {
|
|
156
|
-
createNewAbortSignal() {
|
|
157
|
-
if (this.controller) {
|
|
158
|
-
const abortError = new Error('Cancelling existing WebAuthn API call for new one');
|
|
159
|
-
abortError.name = 'AbortError';
|
|
160
|
-
this.controller.abort(abortError);
|
|
161
|
-
}
|
|
162
|
-
const newController = new AbortController();
|
|
163
|
-
this.controller = newController;
|
|
164
|
-
return newController.signal;
|
|
165
|
-
}
|
|
166
|
-
cancelCeremony() {
|
|
167
|
-
if (this.controller) {
|
|
168
|
-
const abortError = new Error('Manually cancelling existing WebAuthn API call');
|
|
169
|
-
abortError.name = 'AbortError';
|
|
170
|
-
this.controller.abort(abortError);
|
|
171
|
-
this.controller = undefined;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
const WebAuthnAbortService = new BaseWebAuthnAbortService();
|
|
176
|
-
|
|
177
|
-
const attachments = ['cross-platform', 'platform'];
|
|
178
|
-
function toAuthenticatorAttachment(attachment) {
|
|
179
|
-
if (!attachment) {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
if (attachments.indexOf(attachment) < 0) {
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
return attachment;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
async function startRegistration(options) {
|
|
189
|
-
const { optionsJSON, useAutoRegister = false } = options;
|
|
190
|
-
if (!browserSupportsWebAuthn()) {
|
|
191
|
-
throw new Error('WebAuthn is not supported in this browser');
|
|
192
|
-
}
|
|
193
|
-
const publicKey = {
|
|
194
|
-
...optionsJSON,
|
|
195
|
-
challenge: base64URLStringToBuffer(optionsJSON.challenge),
|
|
196
|
-
user: {
|
|
197
|
-
...optionsJSON.user,
|
|
198
|
-
id: base64URLStringToBuffer(optionsJSON.user.id),
|
|
199
|
-
},
|
|
200
|
-
excludeCredentials: optionsJSON.excludeCredentials?.map(toPublicKeyCredentialDescriptor),
|
|
201
|
-
};
|
|
202
|
-
const createOptions = {};
|
|
203
|
-
if (useAutoRegister) {
|
|
204
|
-
createOptions.mediation = 'conditional';
|
|
205
|
-
}
|
|
206
|
-
createOptions.publicKey = publicKey;
|
|
207
|
-
createOptions.signal = WebAuthnAbortService.createNewAbortSignal();
|
|
208
|
-
let credential;
|
|
209
|
-
try {
|
|
210
|
-
credential = (await navigator.credentials.create(createOptions));
|
|
211
|
-
}
|
|
212
|
-
catch (err) {
|
|
213
|
-
throw identifyRegistrationError({ error: err, options: createOptions });
|
|
214
|
-
}
|
|
215
|
-
if (!credential) {
|
|
216
|
-
throw new Error('Registration was not completed');
|
|
217
|
-
}
|
|
218
|
-
const { id, rawId, response, type } = credential;
|
|
219
|
-
let transports = undefined;
|
|
220
|
-
if (typeof response.getTransports === 'function') {
|
|
221
|
-
transports = response.getTransports();
|
|
222
|
-
}
|
|
223
|
-
let responsePublicKeyAlgorithm = undefined;
|
|
224
|
-
if (typeof response.getPublicKeyAlgorithm === 'function') {
|
|
225
|
-
try {
|
|
226
|
-
responsePublicKeyAlgorithm = response.getPublicKeyAlgorithm();
|
|
227
|
-
}
|
|
228
|
-
catch (error) {
|
|
229
|
-
warnOnBrokenImplementation('getPublicKeyAlgorithm()', error);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
let responsePublicKey = undefined;
|
|
233
|
-
if (typeof response.getPublicKey === 'function') {
|
|
234
|
-
try {
|
|
235
|
-
const _publicKey = response.getPublicKey();
|
|
236
|
-
if (_publicKey !== null) {
|
|
237
|
-
responsePublicKey = bufferToBase64URLString(_publicKey);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
catch (error) {
|
|
241
|
-
warnOnBrokenImplementation('getPublicKey()', error);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
let responseAuthenticatorData;
|
|
245
|
-
if (typeof response.getAuthenticatorData === 'function') {
|
|
246
|
-
try {
|
|
247
|
-
responseAuthenticatorData = bufferToBase64URLString(response.getAuthenticatorData());
|
|
248
|
-
}
|
|
249
|
-
catch (error) {
|
|
250
|
-
warnOnBrokenImplementation('getAuthenticatorData()', error);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
return {
|
|
254
|
-
id,
|
|
255
|
-
rawId: bufferToBase64URLString(rawId),
|
|
256
|
-
response: {
|
|
257
|
-
attestationObject: bufferToBase64URLString(response.attestationObject),
|
|
258
|
-
clientDataJSON: bufferToBase64URLString(response.clientDataJSON),
|
|
259
|
-
transports,
|
|
260
|
-
publicKeyAlgorithm: responsePublicKeyAlgorithm,
|
|
261
|
-
publicKey: responsePublicKey,
|
|
262
|
-
authenticatorData: responseAuthenticatorData,
|
|
263
|
-
},
|
|
264
|
-
type,
|
|
265
|
-
clientExtensionResults: credential.getClientExtensionResults(),
|
|
266
|
-
authenticatorAttachment: toAuthenticatorAttachment(credential.authenticatorAttachment),
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
function warnOnBrokenImplementation(methodName, cause) {
|
|
270
|
-
console.warn(`The browser extension that intercepted this WebAuthn API call incorrectly implemented ${methodName}. You should report this error to them.\n`, cause);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
function browserSupportsWebAuthnAutofill() {
|
|
274
|
-
if (!browserSupportsWebAuthn()) {
|
|
275
|
-
return new Promise((resolve) => resolve(false));
|
|
276
|
-
}
|
|
277
|
-
const globalPublicKeyCredential = window
|
|
278
|
-
.PublicKeyCredential;
|
|
279
|
-
if (globalPublicKeyCredential.isConditionalMediationAvailable === undefined) {
|
|
280
|
-
return new Promise((resolve) => resolve(false));
|
|
281
|
-
}
|
|
282
|
-
return globalPublicKeyCredential.isConditionalMediationAvailable();
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
function identifyAuthenticationError({ error, options, }) {
|
|
286
|
-
const { publicKey } = options;
|
|
287
|
-
if (!publicKey) {
|
|
288
|
-
throw Error('options was missing required publicKey property');
|
|
289
|
-
}
|
|
290
|
-
if (error.name === 'AbortError') {
|
|
291
|
-
if (options.signal instanceof AbortSignal) {
|
|
292
|
-
return new WebAuthnError({
|
|
293
|
-
message: 'Authentication ceremony was sent an abort signal',
|
|
294
|
-
code: 'ERROR_CEREMONY_ABORTED',
|
|
295
|
-
cause: error,
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
else if (error.name === 'NotAllowedError') {
|
|
300
|
-
return new WebAuthnError({
|
|
301
|
-
message: error.message,
|
|
302
|
-
code: 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY',
|
|
303
|
-
cause: error,
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
else if (error.name === 'SecurityError') {
|
|
307
|
-
const effectiveDomain = window.location.hostname;
|
|
308
|
-
if (!isValidDomain(effectiveDomain)) {
|
|
309
|
-
return new WebAuthnError({
|
|
310
|
-
message: `${window.location.hostname} is an invalid domain`,
|
|
311
|
-
code: 'ERROR_INVALID_DOMAIN',
|
|
312
|
-
cause: error,
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
else if (publicKey.rpId !== effectiveDomain) {
|
|
316
|
-
return new WebAuthnError({
|
|
317
|
-
message: `The RP ID "${publicKey.rpId}" is invalid for this domain`,
|
|
318
|
-
code: 'ERROR_INVALID_RP_ID',
|
|
319
|
-
cause: error,
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
else if (error.name === 'UnknownError') {
|
|
324
|
-
return new WebAuthnError({
|
|
325
|
-
message: 'The authenticator was unable to process the specified options, or could not create a new assertion signature',
|
|
326
|
-
code: 'ERROR_AUTHENTICATOR_GENERAL_ERROR',
|
|
327
|
-
cause: error,
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
return error;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
async function startAuthentication(options) {
|
|
334
|
-
const { optionsJSON, useBrowserAutofill = false, verifyBrowserAutofillInput = true, } = options;
|
|
335
|
-
if (!browserSupportsWebAuthn()) {
|
|
336
|
-
throw new Error('WebAuthn is not supported in this browser');
|
|
337
|
-
}
|
|
338
|
-
let allowCredentials;
|
|
339
|
-
if (optionsJSON.allowCredentials?.length !== 0) {
|
|
340
|
-
allowCredentials = optionsJSON.allowCredentials?.map(toPublicKeyCredentialDescriptor);
|
|
341
|
-
}
|
|
342
|
-
const publicKey = {
|
|
343
|
-
...optionsJSON,
|
|
344
|
-
challenge: base64URLStringToBuffer(optionsJSON.challenge),
|
|
345
|
-
allowCredentials,
|
|
346
|
-
};
|
|
347
|
-
const getOptions = {};
|
|
348
|
-
if (useBrowserAutofill) {
|
|
349
|
-
if (!(await browserSupportsWebAuthnAutofill())) {
|
|
350
|
-
throw Error('Browser does not support WebAuthn autofill');
|
|
351
|
-
}
|
|
352
|
-
const eligibleInputs = document.querySelectorAll("input[autocomplete$='webauthn']");
|
|
353
|
-
if (eligibleInputs.length < 1 && verifyBrowserAutofillInput) {
|
|
354
|
-
throw Error('No <input> with "webauthn" as the only or last value in its `autocomplete` attribute was detected');
|
|
355
|
-
}
|
|
356
|
-
getOptions.mediation = 'conditional';
|
|
357
|
-
publicKey.allowCredentials = [];
|
|
358
|
-
}
|
|
359
|
-
getOptions.publicKey = publicKey;
|
|
360
|
-
getOptions.signal = WebAuthnAbortService.createNewAbortSignal();
|
|
361
|
-
let credential;
|
|
362
|
-
try {
|
|
363
|
-
credential = (await navigator.credentials.get(getOptions));
|
|
364
|
-
}
|
|
365
|
-
catch (err) {
|
|
366
|
-
throw identifyAuthenticationError({ error: err, options: getOptions });
|
|
367
|
-
}
|
|
368
|
-
if (!credential) {
|
|
369
|
-
throw new Error('Authentication was not completed');
|
|
370
|
-
}
|
|
371
|
-
const { id, rawId, response, type } = credential;
|
|
372
|
-
let userHandle = undefined;
|
|
373
|
-
if (response.userHandle) {
|
|
374
|
-
userHandle = bufferToBase64URLString(response.userHandle);
|
|
375
|
-
}
|
|
376
|
-
return {
|
|
377
|
-
id,
|
|
378
|
-
rawId: bufferToBase64URLString(rawId),
|
|
379
|
-
response: {
|
|
380
|
-
authenticatorData: bufferToBase64URLString(response.authenticatorData),
|
|
381
|
-
clientDataJSON: bufferToBase64URLString(response.clientDataJSON),
|
|
382
|
-
signature: bufferToBase64URLString(response.signature),
|
|
383
|
-
userHandle,
|
|
384
|
-
},
|
|
385
|
-
type,
|
|
386
|
-
clientExtensionResults: credential.getClientExtensionResults(),
|
|
387
|
-
authenticatorAttachment: toAuthenticatorAttachment(credential.authenticatorAttachment),
|
|
388
|
-
};
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
function platformAuthenticatorIsAvailable() {
|
|
392
|
-
if (!browserSupportsWebAuthn()) {
|
|
393
|
-
return new Promise((resolve) => resolve(false));
|
|
394
|
-
}
|
|
395
|
-
return PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable();
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
export { WebAuthnAbortService, WebAuthnError, base64URLStringToBuffer, browserSupportsWebAuthn, browserSupportsWebAuthnAutofill, bufferToBase64URLString, platformAuthenticatorIsAvailable, startAuthentication, startRegistration };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function base64URLStringToBuffer(base64URLString: string): ArrayBuffer;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function browserSupportsWebAuthn(): boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function browserSupportsWebAuthnAutofill(): Promise<boolean>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function bufferToBase64URLString(buffer: ArrayBuffer): string;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function isValidDomain(hostname: string): boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function platformAuthenticatorIsAvailable(): Promise<boolean>;
|
package/dist/types/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { startRegistration } from './methods/startRegistration';
|
|
2
|
-
import { startAuthentication } from './methods/startAuthentication';
|
|
3
|
-
import { browserSupportsWebAuthn } from './helpers/browserSupportsWebAuthn';
|
|
4
|
-
import { platformAuthenticatorIsAvailable } from './helpers/platformAuthenticatorIsAvailable';
|
|
5
|
-
import { browserSupportsWebAuthnAutofill } from './helpers/browserSupportsWebAuthnAutofill';
|
|
6
|
-
import { base64URLStringToBuffer } from './helpers/base64URLStringToBuffer';
|
|
7
|
-
import { bufferToBase64URLString } from './helpers/bufferToBase64URLString';
|
|
8
|
-
import { WebAuthnAbortService } from './helpers/webAuthnAbortService';
|
|
9
|
-
import { WebAuthnError } from './helpers/webAuthnError';
|
|
10
|
-
export { base64URLStringToBuffer, browserSupportsWebAuthn, browserSupportsWebAuthnAutofill, bufferToBase64URLString, platformAuthenticatorIsAvailable, startAuthentication, startRegistration, WebAuthnAbortService, WebAuthnError, };
|
|
11
|
-
export type { WebAuthnErrorCode } from './helpers/webAuthnError';
|