@flun/webauthn-browser 2.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.
@@ -0,0 +1,238 @@
1
+ /**
2
+ * 请勿修改这些文件!
3
+ *
4
+ * 这些文件是从 **types** 包复制而来的;要更新此文件,请修改相应包中的文件,
5
+ * 然后从 monorepo 根目录运行命令: deno task codegen:types
6
+ */
7
+ import type {
8
+ AttestationConveyancePreference, AuthenticationExtensionsClientInputs, AuthenticationExtensionsClientOutputs,
9
+ AuthenticatorAssertionResponse, AuthenticatorAttachment, AuthenticatorAttestationResponse, AuthenticatorSelectionCriteria,
10
+ COSEAlgorithmIdentifier, PublicKeyCredential, PublicKeyCredentialCreationOptions, PublicKeyCredentialDescriptor,
11
+ PublicKeyCredentialParameters, PublicKeyCredentialRequestOptions, PublicKeyCredentialRpEntity, PublicKeyCredentialType,
12
+ UserVerificationRequirement
13
+ } from './dom.js';
14
+ export type {
15
+ AttestationConveyancePreference, AuthenticationExtensionsClientInputs, AuthenticationExtensionsClientOutputs,
16
+ AuthenticatorAssertionResponse, AuthenticatorAttachment, AuthenticatorAttestationResponse, AuthenticatorSelectionCriteria,
17
+ AuthenticatorTransport, COSEAlgorithmIdentifier, Crypto, PublicKeyCredential, PublicKeyCredentialCreationOptions,
18
+ PublicKeyCredentialDescriptor, PublicKeyCredentialParameters, PublicKeyCredentialRequestOptions, PublicKeyCredentialRpEntity,
19
+ PublicKeyCredentialType, PublicKeyCredentialUserEntity, ResidentKeyRequirement, UserVerificationRequirement,
20
+ } from './dom.js';
21
+
22
+ /**
23
+ * 适用于 JSON 传输到浏览器的 PublicKeyCredentialCreationOptions 变体,
24
+ * (最终)将传递给浏览器中的 navigator.credentials.create(...);
25
+ *
26
+ * 当 WebAuthn L3 类型最终进入语言标准时,应被官方的 TypeScript DOM 类型取代:
27
+ *
28
+ * https://w3c.github.io/webauthn/#dictdef-publickeycredentialcreationoptionsjson
29
+ */
30
+ export interface PublicKeyCredentialCreationOptionsJSON {
31
+ rp: PublicKeyCredentialRpEntity;
32
+ user: PublicKeyCredentialUserEntityJSON;
33
+ challenge: Base64URLString;
34
+ pubKeyCredParams: PublicKeyCredentialParameters[];
35
+ timeout?: number;
36
+ excludeCredentials?: PublicKeyCredentialDescriptorJSON[];
37
+ authenticatorSelection?: AuthenticatorSelectionCriteria;
38
+ hints?: PublicKeyCredentialHint[];
39
+ attestation?: AttestationConveyancePreference;
40
+ attestationFormats?: AttestationFormat[];
41
+ extensions?: AuthenticationExtensionsClientInputs;
42
+ }
43
+
44
+ /**
45
+ * 适用于 JSON 传输到浏览器的 PublicKeyCredentialRequestOptions 变体,
46
+ * (最终)将传递给浏览器中的 navigator.credentials.get(...)。
47
+ */
48
+ export interface PublicKeyCredentialRequestOptionsJSON {
49
+ challenge: Base64URLString;
50
+ timeout?: number;
51
+ rpId?: string;
52
+ allowCredentials?: PublicKeyCredentialDescriptorJSON[];
53
+ userVerification?: UserVerificationRequirement;
54
+ hints?: PublicKeyCredentialHint[];
55
+ extensions?: AuthenticationExtensionsClientInputs;
56
+ }
57
+
58
+ /**
59
+ * https://w3c.github.io/webauthn/#dictdef-publickeycredentialdescriptorjson
60
+ */
61
+ export interface PublicKeyCredentialDescriptorJSON {
62
+ id: Base64URLString, type: PublicKeyCredentialType;
63
+ transports?: AuthenticatorTransportFuture[];
64
+ }
65
+
66
+ /**
67
+ * https://w3c.github.io/webauthn/#dictdef-publickeycredentialuserentityjson
68
+ */
69
+ export interface PublicKeyCredentialUserEntityJSON {
70
+ id: string, name: string, displayName: string;
71
+ }
72
+
73
+ /**
74
+ * navigator.credentials.create() 返回的值
75
+ */
76
+ export interface RegistrationCredential extends PublicKeyCredentialFuture {
77
+ response: AuthenticatorAttestationResponseFuture;
78
+ }
79
+
80
+ /**
81
+ * 略微修改的 RegistrationCredential,用于简化处理浏览器中经过 Base64URL 编码的 ArrayBuffer,
82
+ * 以便它们可以作为 JSON 发送到服务器;
83
+ *
84
+ * https://w3c.github.io/webauthn/#dictdef-registrationresponsejson
85
+ */
86
+ export interface RegistrationResponseJSON {
87
+ id: Base64URLString;
88
+ rawId: Base64URLString;
89
+ response: AuthenticatorAttestationResponseJSON;
90
+ authenticatorAttachment?: AuthenticatorAttachment;
91
+ clientExtensionResults: AuthenticationExtensionsClientOutputs;
92
+ type: PublicKeyCredentialType;
93
+ }
94
+
95
+ /**
96
+ * navigator.credentials.get() 返回的值
97
+ */
98
+ export interface AuthenticationCredential extends PublicKeyCredentialFuture {
99
+ response: AuthenticatorAssertionResponse;
100
+ }
101
+
102
+ /**
103
+ * 略微修改的 AuthenticationCredential,用于简化处理浏览器中经过 Base64URL 编码的 ArrayBuffer,
104
+ * 以便它们可以作为 JSON 发送到服务器。
105
+ *
106
+ * https://w3c.github.io/webauthn/#dictdef-authenticationresponsejson
107
+ */
108
+ export interface AuthenticationResponseJSON {
109
+ id: Base64URLString;
110
+ rawId: Base64URLString;
111
+ response: AuthenticatorAssertionResponseJSON;
112
+ authenticatorAttachment?: AuthenticatorAttachment;
113
+ clientExtensionResults: AuthenticationExtensionsClientOutputs;
114
+ type: PublicKeyCredentialType;
115
+ }
116
+
117
+ /**
118
+ * 略微修改的 AuthenticatorAttestationResponse,用于简化处理浏览器中经过 Base64URL 编码的 ArrayBuffer,
119
+ * 以便它们可以作为 JSON 发送到服务器。
120
+ *
121
+ * https://w3c.github.io/webauthn/#dictdef-authenticatorattestationresponsejson
122
+ */
123
+ export interface AuthenticatorAttestationResponseJSON {
124
+ clientDataJSON: Base64URLString;
125
+ attestationObject: Base64URLString;
126
+ authenticatorData?: Base64URLString;
127
+ transports?: AuthenticatorTransportFuture[];
128
+ publicKeyAlgorithm?: COSEAlgorithmIdentifier;
129
+ publicKey?: Base64URLString;
130
+ }
131
+
132
+ /**
133
+ * 略微修改的 AuthenticatorAssertionResponse,用于简化处理浏览器中经过 Base64URL 编码的 ArrayBuffer,
134
+ * 以便它们可以作为 JSON 发送到服务器。
135
+ *
136
+ * https://w3c.github.io/webauthn/#dictdef-authenticatorassertionresponsejson
137
+ */
138
+ export interface AuthenticatorAssertionResponseJSON {
139
+ clientDataJSON: Base64URLString;
140
+ authenticatorData: Base64URLString;
141
+ signature: Base64URLString;
142
+ userHandle?: Base64URLString;
143
+ }
144
+
145
+ /**
146
+ * 用于验证认证响应的公钥凭证信息
147
+ */
148
+ export type WebAuthnCredential = {
149
+ id: Base64URLString, publicKey: Uint8Array_;
150
+ counter: number, transports?: AuthenticatorTransportFuture[];
151
+ };
152
+
153
+ /**
154
+ * 表示这不只是一个普通字符串,而是一个 Base64URL 编码的字符串
155
+ */
156
+ export type Base64URLString = string;
157
+
158
+ /**
159
+ * TypeScript DOM 库中的 AuthenticatorAttestationResponse 已过时(最高到 v3.9.7)。
160
+ * 此处维护一个增强版本,以便随着 WebAuthn 规范的演进实现额外的属性;
161
+ *
162
+ * 参见 https://www.w3.org/TR/webauthn-2/#iface-authenticatorattestationresponse
163
+ *
164
+ * 标记为可选的属性并非在所有浏览器中都受支持;
165
+ */
166
+ export interface AuthenticatorAttestationResponseFuture extends AuthenticatorAttestationResponse {
167
+ getTransports(): AuthenticatorTransportFuture[];
168
+ }
169
+
170
+ /**
171
+ * TypeScript 的 `AuthenticatorTransport` 的超集,包含对最新传输方式的支持;
172
+ * 当 TypeScript 更新到知晓这些传输方式后(大约在 4.6.3 之后),应最终被 TypeScript 的类型取代;
173
+ */
174
+ export type AuthenticatorTransportFuture = 'ble' | 'cable' | 'hybrid' | 'internal' | 'nfc' | 'smart-card' | 'usb';
175
+
176
+ /**
177
+ * TypeScript 的 `PublicKeyCredentialDescriptor` 的超集,知晓最新的传输方式;
178
+ * 当 TypeScript 更新到知晓这些传输方式后(大约在 4.6.3 之后),应最终被 TypeScript 的类型取代;
179
+ */
180
+ export interface PublicKeyCredentialDescriptorFuture extends Omit<PublicKeyCredentialDescriptor, 'transports'> {
181
+ transports?: AuthenticatorTransportFuture[];
182
+ }
183
+
184
+ /** */
185
+ export type PublicKeyCredentialJSON = RegistrationResponseJSON | AuthenticationResponseJSON;
186
+
187
+ /**
188
+ * TypeScript 的 `PublicKeyCredential` 的超集,知晓即将推出的 WebAuthn 特性
189
+ */
190
+ export interface PublicKeyCredentialFuture extends PublicKeyCredential {
191
+ type: PublicKeyCredentialType;
192
+ isConditionalMediationAvailable?(): Promise<boolean>;
193
+ parseCreationOptionsFromJSON?(options: PublicKeyCredentialCreationOptionsJSON): PublicKeyCredentialCreationOptions;
194
+ parseRequestOptionsFromJSON?(options: PublicKeyCredentialRequestOptionsJSON): PublicKeyCredentialRequestOptions;
195
+ toJSON?(): PublicKeyCredentialJSON;
196
+ }
197
+
198
+ /**
199
+ * 由认证器数据中的第 3 位(“备份资格”)定义的两种凭证类型:
200
+ * - `"singleDevice"` 凭证永远不会被备份
201
+ * - `"multiDevice"` 凭证可以被备份
202
+ */
203
+ export type CredentialDeviceType = 'singleDevice' | 'multiDevice';
204
+
205
+ /**
206
+ * 依赖方可以在注册时传递给浏览器的认证器类别,能够理解这些值的浏览器可以优化其模态体验,
207
+ * 将用户引导至特定的注册流程:
208
+ *
209
+ * - `hybrid`: 移动设备上的平台认证器
210
+ * - `security-key`: 可通过 USB 或 NFC 连接在多个设备上使用的便携式 FIDO2 认证器
211
+ * - `client-device`: 正在调用 WebAuthn 的设备,通常与平台认证器同义
212
+ *
213
+ * 参见 https://w3c.github.io/webauthn/#enumdef-publickeycredentialhint
214
+ *
215
+ * 这些值比 `authenticatorAttachment` 更宽松
216
+ */
217
+ export type PublicKeyCredentialHint = 'hybrid' | 'security-key' | 'client-device';
218
+
219
+ /**
220
+ * 证明对象的 `fmt` 的值
221
+ *
222
+ * 参见 https://www.iana.org/assignments/webauthn/webauthn.xhtml#webauthn-attestation-statement-format-ids
223
+ */
224
+ export type AttestationFormat = 'fido-u2f' | 'packed' | 'android-safetynet' | 'android-key' | 'tpm' | 'apple' | 'none';
225
+
226
+ /**
227
+ * 在 TypeScript 5.7 之前等同于 `Uint8Array`,在 TypeScript 5.7 及更高版本中等同于 `Uint8Array<ArrayBuffer>`;
228
+ *
229
+ * **背景**
230
+ *
231
+ * `Uint8Array` 在TypeScript 5.7中成为泛型类型,要求从Deno 2.2开始将简单定义为 `Uint8Array` 的类型重构为 `Uint8Array<ArrayBuffer>`;
232
+ * 然而,在 Deno 2.1.x 及更早版本中 `Uint8Array` 不是泛型,因此此类型有助于弥合这一差距。
233
+ *
234
+ * 灵感来自 Deno 的标准库:
235
+ *
236
+ * https://github.com/denoland/std/blob/b5a5fe4f96b91c1fe8dba5cc0270092dd11d3287/bytes/_types.ts#L11
237
+ */
238
+ export type Uint8Array_ = ReturnType<Uint8Array['slice']>;