Skip to content

Commit a225511

Browse files
committed
chore: update types
1 parent c1e694b commit a225511

2 files changed

Lines changed: 31 additions & 73 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"clean": "expo-module clean",
1010
"lint": "expo-module lint",
1111
"test": "expo-module test",
12+
"preinstall": "npx only-allow pnpm",
1213
"prepare": "expo-module prepare",
1314
"expo-module": "expo-module",
1415
"open:ios": "open -a \"Xcode\" example/ios",

src/ReactNativePasskeys.types.ts

Lines changed: 30 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
export type Base64URLString = string
77

88
/**
9-
* A variant of PublicKeyCredentialCreationOptions suitable for JSON transmission to the browser to
10-
* (eventually) get passed into navigator.credentials.create(...) in the browser.
9+
* A variant of PublicKeyCredentialCreationOptions suitable for JSON transmission
1110
*
1211
* This should eventually get replaced with official TypeScript DOM types when WebAuthn L3 types
1312
* eventually make it into the language:
1413
*
15-
* https://w3c.github.io/webauthn/#dictdef-publickeycredentialcreationoptionsjson
14+
* - Specification reference: https://w3c.github.io/webauthn/#dictdef-publickeycredentialcreationoptionsjson
1615
*/
1716
export interface PublicKeyCredentialCreationOptionsJSON {
1817
rp: PublicKeyCredentialRpEntity
@@ -27,8 +26,7 @@ export interface PublicKeyCredentialCreationOptionsJSON {
2726
}
2827

2928
/**
30-
* A variant of PublicKeyCredentialRequestOptions suitable for JSON transmission to the browser to
31-
* (eventually) get passed into navigator.credentials.get(...) in the browser.
29+
* A variant of PublicKeyCredentialRequestOptions suitable for JSON transmission
3230
*/
3331
export interface PublicKeyCredentialRequestOptionsJSON {
3432
challenge: Base64URLString
@@ -40,7 +38,7 @@ export interface PublicKeyCredentialRequestOptionsJSON {
4038
}
4139

4240
/**
43-
* https://w3c.github.io/webauthn/#dictdef-publickeycredentialdescriptorjson
41+
* - Specification reference: https://w3c.github.io/webauthn/#dictdef-publickeycredentialdescriptorjson
4442
*/
4543
export interface PublicKeyCredentialDescriptorJSON {
4644
id: Base64URLString
@@ -49,26 +47,19 @@ export interface PublicKeyCredentialDescriptorJSON {
4947
}
5048

5149
/**
52-
* https://w3c.github.io/webauthn/#dictdef-publickeycredentialuserentityjson
50+
* - Specification reference: https://w3c.github.io/webauthn/#dictdef-publickeycredentialuserentityjson
5351
*/
5452
export interface PublicKeyCredentialUserEntityJSON {
5553
id: string
5654
name: string
5755
displayName: string
5856
}
5957

60-
/**
61-
* The value returned from navigator.credentials.create()
62-
*/
63-
export interface RegistrationCredential extends PublicKeyCredentialFuture {
64-
response: AuthenticatorAttestationResponseFuture
65-
}
66-
6758
/**
6859
* A slightly-modified RegistrationCredential to simplify working with ArrayBuffers that
69-
* are Base64URL-encoded in the browser so that they can be sent as JSON to the server.
60+
* are Base64URL-encoded so that they can be sent as JSON.
7061
*
71-
* https://w3c.github.io/webauthn/#dictdef-registrationresponsejson
62+
* - Specification reference: https://w3c.github.io/webauthn/#dictdef-registrationresponsejson
7263
*/
7364
export interface RegistrationResponseJSON {
7465
id: Base64URLString
@@ -79,18 +70,11 @@ export interface RegistrationResponseJSON {
7970
type: PublicKeyCredentialType
8071
}
8172

82-
/**
83-
* The value returned from navigator.credentials.get()
84-
*/
85-
export interface AuthenticationCredential extends PublicKeyCredentialFuture {
86-
response: AuthenticatorAssertionResponse
87-
}
88-
8973
/**
9074
* A slightly-modified AuthenticationCredential to simplify working with ArrayBuffers that
91-
* are Base64URL-encoded in the browser so that they can be sent as JSON to the server.
75+
* are Base64URL-encoded so that they can be sent as JSON.
9276
*
93-
* https://w3c.github.io/webauthn/#dictdef-authenticationresponsejson
77+
* - Specification reference: https://w3c.github.io/webauthn/#dictdef-authenticationresponsejson
9478
*/
9579
export interface AuthenticationResponseJSON {
9680
id: Base64URLString
@@ -103,9 +87,9 @@ export interface AuthenticationResponseJSON {
10387

10488
/**
10589
* A slightly-modified AuthenticatorAttestationResponse to simplify working with ArrayBuffers that
106-
* are Base64URL-encoded in the browser so that they can be sent as JSON to the server.
90+
* are Base64URL-encoded so that they can be sent as JSON.
10791
*
108-
* https://w3c.github.io/webauthn/#dictdef-authenticatorattestationresponsejson
92+
* - Specification reference: https://w3c.github.io/webauthn/#dictdef-authenticatorattestationresponsejson
10993
*/
11094
export interface AuthenticatorAttestationResponseJSON {
11195
clientDataJSON: Base64URLString
@@ -121,9 +105,9 @@ export interface AuthenticatorAttestationResponseJSON {
121105

122106
/**
123107
* A slightly-modified AuthenticatorAssertionResponse to simplify working with ArrayBuffers that
124-
* are Base64URL-encoded in the browser so that they can be sent as JSON to the server.
108+
* are Base64URL-encoded so that they can be sent as JSON.
125109
*
126-
* https://w3c.github.io/webauthn/#dictdef-authenticatorassertionresponsejson
110+
* - Specification reference: https://w3c.github.io/webauthn/#dictdef-authenticatorassertionresponsejson
127111
*/
128112
export interface AuthenticatorAssertionResponseJSON {
129113
clientDataJSON: Base64URLString
@@ -144,82 +128,53 @@ export type AuthenticatorDevice = {
144128
transports?: AuthenticatorTransportFuture[]
145129
}
146130

147-
/**
148-
* AuthenticatorAttestationResponse in TypeScript's DOM lib is outdated (up through v3.9.7).
149-
* Maintain an augmented version here so we can implement additional properties as the WebAuthn
150-
* spec evolves.
151-
*
152-
* See https://www.w3.org/TR/webauthn-2/#iface-authenticatorattestationresponse
153-
*
154-
* Properties marked optional are not supported in all browsers.
155-
*/
156-
export interface AuthenticatorAttestationResponseFuture extends AuthenticatorAttestationResponse {
157-
getTransports(): AuthenticatorTransportFuture[]
158-
}
159-
160131
/**
161132
* A super class of TypeScript's `AuthenticatorTransport` that includes support for the latest
162133
* transports. Should eventually be replaced by TypeScript's when TypeScript gets updated to
163-
* know about it (sometime after 4.6.3)
134+
* know about it (sometime after 5.3)
164135
*/
165136
export type AuthenticatorTransportFuture =
166137
| 'ble'
167-
// | 'cable'
138+
| 'cable'
168139
| 'hybrid'
169140
| 'internal'
170141
| 'nfc'
171-
// | 'smart-card'
142+
| 'smart-card'
172143
| 'usb'
173144

174145
/**
175146
* A super class of TypeScript's `PublicKeyCredentialDescriptor` that knows about the latest
176147
* transports. Should eventually be replaced by TypeScript's when TypeScript gets updated to
177-
* know about it (sometime after 4.6.3)
148+
* know about it (sometime after 5.3)
178149
*/
179150
export interface PublicKeyCredentialDescriptorFuture
180151
extends Omit<PublicKeyCredentialDescriptor, 'transports'> {
181152
transports?: AuthenticatorTransportFuture[]
182153
}
183154

184-
/** */
155+
/**
156+
* - Specification reference: https://w3c.github.io/webauthn/#typedefdef-publickeycredentialjson
157+
*/
185158
export type PublicKeyCredentialJSON = RegistrationResponseJSON | AuthenticationResponseJSON
186159

187160
/**
188-
* A super class of TypeScript's `PublicKeyCredential` that knows about upcoming WebAuthn features
161+
* TypeScript's types are behind the latest extensions spec, so we define them here.
162+
* Should eventually be replaced by TypeScript's when TypeScript gets updated to
163+
* know about it (sometime after 5.3)
189164
*/
190-
export interface PublicKeyCredentialFuture extends PublicKeyCredential {
191-
type: PublicKeyCredentialType
192-
// See https://github.com/w3c/webauthn/issues/1745
193-
isConditionalMediationAvailable?(): Promise<boolean>
194-
// See https://w3c.github.io/webauthn/#sctn-parseCreationOptionsFromJSON
195-
parseCreationOptionsFromJSON?(
196-
options: PublicKeyCredentialCreationOptionsJSON,
197-
): PublicKeyCredentialCreationOptions
198-
// See https://w3c.github.io/webauthn/#sctn-parseRequestOptionsFromJSON
199-
parseRequestOptionsFromJSON?(
200-
options: PublicKeyCredentialRequestOptionsJSON,
201-
): PublicKeyCredentialRequestOptions
202-
// See https://w3c.github.io/webauthn/#dom-publickeycredential-tojson
203-
toJSON?(): PublicKeyCredentialJSON
204-
}
205165

206166
/**
207-
* The two types of credentials as defined by bit 3 ("Backup Eligibility") in authenticator data:
208-
* - `"singleDevice"` credentials will never be backed up
209-
* - `"multiDevice"` credentials can be backed up
167+
* - Specification reference: https://w3c.github.io/webauthn/#dictdef-authenticationextensionsclientinputs
210168
*/
211-
export type CredentialDeviceType = 'singleDevice' | 'multiDevice'
212-
213-
// - Extensions
214-
215-
// - Specification reference: https://w3c.github.io/webauthn/#dictdef-authenticationextensionsclientinputs
216169
export interface AuthenticationExtensionsClientInputs {
217170
largeBlob?: AuthenticationExtensionsLargeBlobInputs
218171
}
219172

220173
export type LargeBlobSupport = 'preferred' | 'required'
221174

222-
// - Specification reference: https://w3c.github.io/webauthn/#dictdef-authenticationextensionslargeblobinputs
175+
/**
176+
* - Specification reference: https://w3c.github.io/webauthn/#dictdef-authenticationextensionslargeblobinputs
177+
*/
223178
export interface AuthenticationExtensionsLargeBlobInputs {
224179
// - Only valid during registration.
225180
support?: LargeBlobSupport
@@ -237,7 +192,9 @@ export interface AuthenticationExtensionsClientOutputs {
237192
largeBlob?: AuthenticationExtensionsLargeBlobOutputs
238193
}
239194

240-
// - Specification reference: https://w3c.github.io/webauthn/#dictdef-authenticationextensionslargebloboutputs
195+
/**
196+
* - Specification reference: https://w3c.github.io/webauthn/#dictdef-authenticationextensionslargebloboutputs
197+
*/
241198
export interface AuthenticationExtensionsLargeBlobOutputs {
242199
// - true if, and only if, the created credential supports storing large blobs. Only present in registration outputs.
243200
supported?: boolean

0 commit comments

Comments
 (0)