-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
176 lines (166 loc) · 6.65 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/**
* @module webauthn4js
* @packageDocumentation
*/
import { TypedEmitter } from 'tiny-typed-emitter';
import {
Authenticator,
Config,
User,
Credential,
CredentialCreation,
PublicKeyCredentialCreationOptions,
CredentialCreationResponse,
CredentialAssertion,
PublicKeyCredentialRequestOptions,
CredentialAssertionResponse,
SessionData
} from './typescript/webauthn';
/**
* Events emitted by {@link WebAuthn4JS} instances.
*/
interface WebAuthn4JSEvents {
/**
* Emitted if an error occurs.
*
* @param err The error that occurred.
*/
error: (err : Error) => void;
/**
* Emitted if the Web Assembly library used by {@link WebAuthn4JS} exits.
* After this event has been emitted, the {@link WebAuthn4JS} instance which
* emitted it must no longer be used.
*
* @param code Status code the Web Assembly exited with.
*/
exit: (code : number) => void;
}
/**
* Implements [Web Authentication](https://w3c.github.io/webauthn/) for
* applications. Uses the [Go WebAuthn library](https://github.com/go-webauthn/webauthn),
* compiled to Web Assembly, to do the heavy lifting.
*
* Note that WebAuthn4JS doesn't store any data itself. Users and credentials are left for
* the application to store, for example in a database.
*
* @noInheritDoc
*/
interface WebAuthn4JS extends TypedEmitter<WebAuthn4JSEvents> {
/**
* Generate a new set of registration data (including attestation challenge) to be sent to the
* browser.
*
* @param user User to start registering.
* @param opts A list of functions which can modify the options that will be sent to the
* browser for it to call
* [`navigator.credentials.create()`](https://developer.mozilla.org/en-US/docs/Web/API/CredentialsContainer/create).
*
* @returns A promise which resolves to the options which the browser should pass to
* `navigator.credentials.create()` and session data which the caller should store
* securely for the duration of the registration ceremony.
*/
beginRegistration(
user : User,
...opts : ((cco : PublicKeyCredentialCreationOptions) => PublicKeyCredentialCreationOptions)[]
) : Promise<{
options : CredentialCreation,
sessionData : SessionData
}>;
/**
* Take the response from the browser and verify the credential against the registration
* ceremony's session data.
*
* @param user User to register.
* @param sessionData Session data that was returned by a previous call to
* {@link beginRegistration}.
* @param response Result from calling `navigator.credentials.create()` in the browser.
*
* @returns Credential that was verified (against the challenge in the session data).
* <p>Note that the caller is responsible for associating this credential with the
* user (for example in a database) and for checking the same credential isn't
* registered to another user.
*/
finishRegistration(
user : User,
sessionData : SessionData,
response : CredentialCreationResponse
) : Promise<Credential>;
/**
* Generate a new set of login data (including assertion challenge) to be sent to the browser.
*
* @param user User to start logging in.
* @param opts A list of functions which can modify the options that will be sent to the
* browser for it to call
* [`navigator.credentials.get()`](https://developer.mozilla.org/en-US/docs/Web/API/CredentialsContainer/get).
*
* @returns A promise which resolves to the options which the browser should pass to
* `navigator.credentials.get()` and session data which the caller should store
* securely for the duration of the registration ceremony.
*/
beginLogin(
user : User,
...opts : ((cro : PublicKeyCredentialRequestOptions) => PublicKeyCredentialRequestOptions)[]
) : Promise<{
options : CredentialAssertion,
sessionData : SessionData
}>;
/**
* Take the response from the browser and validate it against the user's credentials and the
* login ceremony's session data.
*
* @param user User to login.
* @param sessionData Session data that was returned by a previous call to
* {@link beginLogin}.
* @param response Result from calling `navigator.credentials.get()` in the browser.
*
* @returns Credential that was verified (against the challenge in the session data).
* <p>It's also checked to belong to the user's existing credentials.
* <p>Note that the caller is responsible for checking the
* {@link Authenticator.cloneWarning} property, indicating the credential has
* been cloned, and treating it as an error.
* <p>The caller should also use the {@link Authenticator.signCount} property to
* update the sign count it holds on record (for example in a database) for
* this credential. It can use the {@link Credential.id} property to identify
* credentials.
*/
finishLogin(
user : User,
sessionData : SessionData,
response : CredentialAssertionResponse
) : Promise<Credential>;
/**
* Tell the Web Assembly code which is running the Go WebAuthn library for this
* instance to stop.
*
* Don't call any more methods after you call this.
*
* @param code Optional code to stop the Web Assembly with.
* <p>A {@link WebAuthn4JSEvents.exit} event will be fired once the Web Assembly
* code exits.
* <p>If this parameter is non-zero (the default is zero), then a
* {@link WebAuthn4JSEvents.error} event will be fired before the
* {@link WebAuthn4JSEvents.exit} event.
*/
exit(code? : number) : void;
}
declare const makeWebAuthn : {
/**
* [JSON Schemas](https://json-schema.org/) for the types in `webauthn4js`.
* These can be useful for validating data you exchange with browsers, for example.
*/
schemas : any;
/**
* Creates a {@link WebAuthn4JS} instance from a given {@link Config}.
*
* @param config Configuration for the instance.
*
* @returns A new configured instance.
*/
(config : Config) : Promise<WebAuthn4JS>;
}
export default makeWebAuthn;
export {
WebAuthn4JSEvents,
WebAuthn4JS
};
export * from './typescript/webauthn';