@capgo/capacitor-passkey 8.2.0
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/CapgoCapacitorPasskey.podspec +17 -0
- package/LICENSE +373 -0
- package/Package.swift +28 -0
- package/README.md +692 -0
- package/android/build.gradle +61 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/app/capgo/passkey/CapacitorPasskey.java +21 -0
- package/android/src/main/java/app/capgo/passkey/CapacitorPasskeyPlugin.java +299 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +1034 -0
- package/dist/esm/definitions.d.ts +531 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +87 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/internal.d.ts +14 -0
- package/dist/esm/internal.js +2 -0
- package/dist/esm/internal.js.map +1 -0
- package/dist/esm/shim.d.ts +8 -0
- package/dist/esm/shim.js +108 -0
- package/dist/esm/shim.js.map +1 -0
- package/dist/esm/web.d.ts +12 -0
- package/dist/esm/web.js +69 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/esm/webauthn.d.ts +23 -0
- package/dist/esm/webauthn.js +440 -0
- package/dist/esm/webauthn.js.map +1 -0
- package/dist/plugin.cjs.js +707 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +710 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/CapacitorPasskeyPlugin/CapacitorPasskey.swift +39 -0
- package/ios/Sources/CapacitorPasskeyPlugin/CapacitorPasskeyPlugin.swift +388 -0
- package/ios/Tests/CapacitorPasskeyPluginTests/CapacitorPasskeyPluginTests.swift +17 -0
- package/package.json +105 -0
- package/scripts/configure-native.js +263 -0
|
@@ -0,0 +1,531 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supported authenticator attachment values.
|
|
3
|
+
*
|
|
4
|
+
* @since 1.0.0
|
|
5
|
+
*/
|
|
6
|
+
export type PasskeyAuthenticatorAttachment = 'platform' | 'cross-platform';
|
|
7
|
+
/**
|
|
8
|
+
* Supported WebAuthn credential type.
|
|
9
|
+
*
|
|
10
|
+
* @since 1.0.0
|
|
11
|
+
*/
|
|
12
|
+
export type PasskeyCredentialType = 'public-key';
|
|
13
|
+
/**
|
|
14
|
+
* Supported user verification preferences.
|
|
15
|
+
*
|
|
16
|
+
* @since 1.0.0
|
|
17
|
+
*/
|
|
18
|
+
export type PasskeyUserVerification = 'discouraged' | 'preferred' | 'required';
|
|
19
|
+
/**
|
|
20
|
+
* Supported attestation preferences.
|
|
21
|
+
*
|
|
22
|
+
* @since 1.0.0
|
|
23
|
+
*/
|
|
24
|
+
export type PasskeyAttestation = 'none' | 'indirect' | 'direct' | 'enterprise';
|
|
25
|
+
/**
|
|
26
|
+
* Supported resident key preferences.
|
|
27
|
+
*
|
|
28
|
+
* @since 1.0.0
|
|
29
|
+
*/
|
|
30
|
+
export type PasskeyResidentKey = 'discouraged' | 'preferred' | 'required';
|
|
31
|
+
/**
|
|
32
|
+
* Options used when installing the browser-style shim.
|
|
33
|
+
*
|
|
34
|
+
* @since 1.0.0
|
|
35
|
+
*/
|
|
36
|
+
export interface ShimWebAuthnOptions {
|
|
37
|
+
/**
|
|
38
|
+
* Optional HTTPS origin to encode into iOS 17.4+ clientDataJSON.
|
|
39
|
+
*
|
|
40
|
+
* Use this when your Capacitor app runs from `capacitor://localhost`
|
|
41
|
+
* but your relying party expects `https://signin.example.com`.
|
|
42
|
+
*/
|
|
43
|
+
origin?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Force the shim even if the runtime already exposes `navigator.credentials`.
|
|
46
|
+
*
|
|
47
|
+
* Defaults to `false`.
|
|
48
|
+
*/
|
|
49
|
+
force?: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Runtime configuration loaded from the host app's Capacitor config.
|
|
53
|
+
*
|
|
54
|
+
* This is the shape returned by `getConfiguration()`.
|
|
55
|
+
*
|
|
56
|
+
* @since 1.1.0
|
|
57
|
+
*/
|
|
58
|
+
export interface PasskeyRuntimeConfiguration {
|
|
59
|
+
/**
|
|
60
|
+
* Whether the `/auto` entrypoint should install the shim automatically.
|
|
61
|
+
*
|
|
62
|
+
* Defaults to `true`.
|
|
63
|
+
*/
|
|
64
|
+
autoShim: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Optional HTTPS origin used by the auto-shim.
|
|
67
|
+
*
|
|
68
|
+
* On iOS 17.4+ this origin is encoded into `clientDataJSON`.
|
|
69
|
+
*/
|
|
70
|
+
origin?: string;
|
|
71
|
+
/**
|
|
72
|
+
* Domains associated with the app for passkey usage.
|
|
73
|
+
*
|
|
74
|
+
* These come from `domains` in Capacitor config plus the hostname derived
|
|
75
|
+
* from `origin` when available.
|
|
76
|
+
*/
|
|
77
|
+
domains: string[];
|
|
78
|
+
/**
|
|
79
|
+
* Current runtime platform.
|
|
80
|
+
*/
|
|
81
|
+
platform: 'ios' | 'android' | 'web';
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* JSON-safe representation of a public key credential descriptor.
|
|
85
|
+
*
|
|
86
|
+
* Binary identifiers must be base64url encoded.
|
|
87
|
+
*
|
|
88
|
+
* @since 1.0.0
|
|
89
|
+
*/
|
|
90
|
+
export interface PasskeyCredentialDescriptor {
|
|
91
|
+
/**
|
|
92
|
+
* Base64url-encoded credential identifier.
|
|
93
|
+
*/
|
|
94
|
+
id: string;
|
|
95
|
+
/**
|
|
96
|
+
* Credential type. Only `public-key` is supported.
|
|
97
|
+
*/
|
|
98
|
+
type?: PasskeyCredentialType;
|
|
99
|
+
/**
|
|
100
|
+
* Optional transport hints copied from WebAuthn.
|
|
101
|
+
*/
|
|
102
|
+
transports?: string[];
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* JSON-safe relying party information.
|
|
106
|
+
*
|
|
107
|
+
* @since 1.0.0
|
|
108
|
+
*/
|
|
109
|
+
export interface PasskeyRelyingParty {
|
|
110
|
+
/**
|
|
111
|
+
* Relying party identifier.
|
|
112
|
+
*
|
|
113
|
+
* If omitted, the shim derives it from the configured origin when possible.
|
|
114
|
+
*/
|
|
115
|
+
id?: string;
|
|
116
|
+
/**
|
|
117
|
+
* Human-readable relying party name.
|
|
118
|
+
*/
|
|
119
|
+
name: string;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* JSON-safe WebAuthn user entity.
|
|
123
|
+
*
|
|
124
|
+
* Binary identifiers must be base64url encoded.
|
|
125
|
+
*
|
|
126
|
+
* @since 1.0.0
|
|
127
|
+
*/
|
|
128
|
+
export interface PasskeyUserEntity {
|
|
129
|
+
/**
|
|
130
|
+
* Base64url-encoded user handle.
|
|
131
|
+
*/
|
|
132
|
+
id: string;
|
|
133
|
+
/**
|
|
134
|
+
* User name shown by the authenticator.
|
|
135
|
+
*/
|
|
136
|
+
name: string;
|
|
137
|
+
/**
|
|
138
|
+
* Optional display name shown by the authenticator.
|
|
139
|
+
*/
|
|
140
|
+
displayName?: string;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* JSON-safe credential parameter entry.
|
|
144
|
+
*
|
|
145
|
+
* @since 1.0.0
|
|
146
|
+
*/
|
|
147
|
+
export interface PasskeyCredentialParameter {
|
|
148
|
+
/**
|
|
149
|
+
* Credential type. Only `public-key` is supported.
|
|
150
|
+
*/
|
|
151
|
+
type: PasskeyCredentialType;
|
|
152
|
+
/**
|
|
153
|
+
* COSE algorithm identifier.
|
|
154
|
+
*/
|
|
155
|
+
alg: number;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* JSON-safe authenticator selection options.
|
|
159
|
+
*
|
|
160
|
+
* @since 1.0.0
|
|
161
|
+
*/
|
|
162
|
+
export interface PasskeyAuthenticatorSelection {
|
|
163
|
+
/**
|
|
164
|
+
* Optional authenticator attachment hint.
|
|
165
|
+
*/
|
|
166
|
+
authenticatorAttachment?: PasskeyAuthenticatorAttachment;
|
|
167
|
+
/**
|
|
168
|
+
* Optional resident key preference.
|
|
169
|
+
*/
|
|
170
|
+
residentKey?: PasskeyResidentKey;
|
|
171
|
+
/**
|
|
172
|
+
* Legacy resident key requirement flag.
|
|
173
|
+
*/
|
|
174
|
+
requireResidentKey?: boolean;
|
|
175
|
+
/**
|
|
176
|
+
* Optional user verification preference.
|
|
177
|
+
*/
|
|
178
|
+
userVerification?: PasskeyUserVerification;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* JSON-safe registration request options.
|
|
182
|
+
*
|
|
183
|
+
* All binary fields must be base64url encoded.
|
|
184
|
+
*
|
|
185
|
+
* @since 1.0.0
|
|
186
|
+
*/
|
|
187
|
+
export interface PasskeyPublicKeyCredentialCreationOptionsJSON {
|
|
188
|
+
/**
|
|
189
|
+
* Base64url-encoded challenge.
|
|
190
|
+
*/
|
|
191
|
+
challenge: string;
|
|
192
|
+
/**
|
|
193
|
+
* Relying party information.
|
|
194
|
+
*/
|
|
195
|
+
rp: PasskeyRelyingParty;
|
|
196
|
+
/**
|
|
197
|
+
* User information.
|
|
198
|
+
*/
|
|
199
|
+
user: PasskeyUserEntity;
|
|
200
|
+
/**
|
|
201
|
+
* Supported credential algorithms.
|
|
202
|
+
*/
|
|
203
|
+
pubKeyCredParams: PasskeyCredentialParameter[];
|
|
204
|
+
/**
|
|
205
|
+
* Optional timeout hint in milliseconds.
|
|
206
|
+
*/
|
|
207
|
+
timeout?: number;
|
|
208
|
+
/**
|
|
209
|
+
* Optional credentials that must be excluded during registration.
|
|
210
|
+
*/
|
|
211
|
+
excludeCredentials?: PasskeyCredentialDescriptor[];
|
|
212
|
+
/**
|
|
213
|
+
* Optional authenticator preferences.
|
|
214
|
+
*/
|
|
215
|
+
authenticatorSelection?: PasskeyAuthenticatorSelection;
|
|
216
|
+
/**
|
|
217
|
+
* Optional attestation preference.
|
|
218
|
+
*/
|
|
219
|
+
attestation?: PasskeyAttestation;
|
|
220
|
+
/**
|
|
221
|
+
* Optional hints copied from the JSON form used by modern WebAuthn toolkits.
|
|
222
|
+
*/
|
|
223
|
+
hints?: string[];
|
|
224
|
+
/**
|
|
225
|
+
* Optional extensions copied as-is into the request JSON.
|
|
226
|
+
*/
|
|
227
|
+
extensions?: Record<string, unknown>;
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Direct registration request for the plugin transport.
|
|
231
|
+
*
|
|
232
|
+
* @since 1.0.0
|
|
233
|
+
*/
|
|
234
|
+
export interface CreateCredentialOptions {
|
|
235
|
+
/**
|
|
236
|
+
* JSON-safe registration request.
|
|
237
|
+
*/
|
|
238
|
+
publicKey: PasskeyPublicKeyCredentialCreationOptionsJSON;
|
|
239
|
+
/**
|
|
240
|
+
* Optional HTTPS origin to use for iOS 17.4+ browser-style clientDataJSON.
|
|
241
|
+
*/
|
|
242
|
+
origin?: string;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* JSON-safe authentication request options.
|
|
246
|
+
*
|
|
247
|
+
* All binary fields must be base64url encoded.
|
|
248
|
+
*
|
|
249
|
+
* @since 1.0.0
|
|
250
|
+
*/
|
|
251
|
+
export interface PasskeyPublicKeyCredentialRequestOptionsJSON {
|
|
252
|
+
/**
|
|
253
|
+
* Base64url-encoded challenge.
|
|
254
|
+
*/
|
|
255
|
+
challenge: string;
|
|
256
|
+
/**
|
|
257
|
+
* Optional timeout hint in milliseconds.
|
|
258
|
+
*/
|
|
259
|
+
timeout?: number;
|
|
260
|
+
/**
|
|
261
|
+
* Optional relying party identifier.
|
|
262
|
+
*
|
|
263
|
+
* If omitted, the shim derives it from the configured origin when possible.
|
|
264
|
+
*/
|
|
265
|
+
rpId?: string;
|
|
266
|
+
/**
|
|
267
|
+
* Optional allow list copied from WebAuthn.
|
|
268
|
+
*/
|
|
269
|
+
allowCredentials?: PasskeyCredentialDescriptor[];
|
|
270
|
+
/**
|
|
271
|
+
* Optional user verification preference.
|
|
272
|
+
*/
|
|
273
|
+
userVerification?: PasskeyUserVerification;
|
|
274
|
+
/**
|
|
275
|
+
* Optional hints copied from the JSON form used by modern WebAuthn toolkits.
|
|
276
|
+
*/
|
|
277
|
+
hints?: string[];
|
|
278
|
+
/**
|
|
279
|
+
* Optional extensions copied as-is into the request JSON.
|
|
280
|
+
*/
|
|
281
|
+
extensions?: Record<string, unknown>;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Direct authentication request for the plugin transport.
|
|
285
|
+
*
|
|
286
|
+
* @since 1.0.0
|
|
287
|
+
*/
|
|
288
|
+
export interface GetCredentialOptions {
|
|
289
|
+
/**
|
|
290
|
+
* JSON-safe authentication request.
|
|
291
|
+
*/
|
|
292
|
+
publicKey: PasskeyPublicKeyCredentialRequestOptionsJSON;
|
|
293
|
+
/**
|
|
294
|
+
* Optional mediation hint. `conditional` currently falls back to an explicit prompt.
|
|
295
|
+
*/
|
|
296
|
+
mediation?: string;
|
|
297
|
+
/**
|
|
298
|
+
* Optional HTTPS origin to use for iOS 17.4+ browser-style clientDataJSON.
|
|
299
|
+
*/
|
|
300
|
+
origin?: string;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* JSON-safe attestation response payload.
|
|
304
|
+
*
|
|
305
|
+
* All binary fields are base64url encoded.
|
|
306
|
+
*
|
|
307
|
+
* @since 1.0.0
|
|
308
|
+
*/
|
|
309
|
+
export interface PasskeyAuthenticatorAttestationResponseJSON {
|
|
310
|
+
/**
|
|
311
|
+
* Base64url-encoded clientDataJSON.
|
|
312
|
+
*/
|
|
313
|
+
clientDataJSON: string;
|
|
314
|
+
/**
|
|
315
|
+
* Base64url-encoded attestation object.
|
|
316
|
+
*/
|
|
317
|
+
attestationObject: string;
|
|
318
|
+
/**
|
|
319
|
+
* Optional base64url-encoded public key when provided by the platform.
|
|
320
|
+
*/
|
|
321
|
+
publicKey?: string;
|
|
322
|
+
/**
|
|
323
|
+
* Optional public key algorithm when provided by the platform.
|
|
324
|
+
*/
|
|
325
|
+
publicKeyAlgorithm?: number;
|
|
326
|
+
/**
|
|
327
|
+
* Optional transport list when provided by the platform.
|
|
328
|
+
*/
|
|
329
|
+
transports?: string[];
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* JSON-safe assertion response payload.
|
|
333
|
+
*
|
|
334
|
+
* All binary fields are base64url encoded.
|
|
335
|
+
*
|
|
336
|
+
* @since 1.0.0
|
|
337
|
+
*/
|
|
338
|
+
export interface PasskeyAuthenticatorAssertionResponseJSON {
|
|
339
|
+
/**
|
|
340
|
+
* Base64url-encoded clientDataJSON.
|
|
341
|
+
*/
|
|
342
|
+
clientDataJSON: string;
|
|
343
|
+
/**
|
|
344
|
+
* Base64url-encoded authenticator data.
|
|
345
|
+
*/
|
|
346
|
+
authenticatorData: string;
|
|
347
|
+
/**
|
|
348
|
+
* Base64url-encoded signature.
|
|
349
|
+
*/
|
|
350
|
+
signature: string;
|
|
351
|
+
/**
|
|
352
|
+
* Optional base64url-encoded user handle.
|
|
353
|
+
*/
|
|
354
|
+
userHandle?: string | null;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* JSON-safe registration credential returned by the plugin.
|
|
358
|
+
*
|
|
359
|
+
* @since 1.0.0
|
|
360
|
+
*/
|
|
361
|
+
export interface PasskeyRegistrationCredential {
|
|
362
|
+
/**
|
|
363
|
+
* Base64url-encoded credential identifier.
|
|
364
|
+
*/
|
|
365
|
+
id: string;
|
|
366
|
+
/**
|
|
367
|
+
* Base64url-encoded raw credential identifier.
|
|
368
|
+
*/
|
|
369
|
+
rawId: string;
|
|
370
|
+
/**
|
|
371
|
+
* Credential type. Always `public-key`.
|
|
372
|
+
*/
|
|
373
|
+
type: PasskeyCredentialType;
|
|
374
|
+
/**
|
|
375
|
+
* Optional authenticator attachment reported by the platform.
|
|
376
|
+
*/
|
|
377
|
+
authenticatorAttachment?: PasskeyAuthenticatorAttachment;
|
|
378
|
+
/**
|
|
379
|
+
* Client extension results returned by the platform.
|
|
380
|
+
*/
|
|
381
|
+
clientExtensionResults: Record<string, unknown>;
|
|
382
|
+
/**
|
|
383
|
+
* Registration response payload.
|
|
384
|
+
*/
|
|
385
|
+
response: PasskeyAuthenticatorAttestationResponseJSON;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* JSON-safe authentication credential returned by the plugin.
|
|
389
|
+
*
|
|
390
|
+
* @since 1.0.0
|
|
391
|
+
*/
|
|
392
|
+
export interface PasskeyAuthenticationCredential {
|
|
393
|
+
/**
|
|
394
|
+
* Base64url-encoded credential identifier.
|
|
395
|
+
*/
|
|
396
|
+
id: string;
|
|
397
|
+
/**
|
|
398
|
+
* Base64url-encoded raw credential identifier.
|
|
399
|
+
*/
|
|
400
|
+
rawId: string;
|
|
401
|
+
/**
|
|
402
|
+
* Credential type. Always `public-key`.
|
|
403
|
+
*/
|
|
404
|
+
type: PasskeyCredentialType;
|
|
405
|
+
/**
|
|
406
|
+
* Optional authenticator attachment reported by the platform.
|
|
407
|
+
*/
|
|
408
|
+
authenticatorAttachment?: PasskeyAuthenticatorAttachment;
|
|
409
|
+
/**
|
|
410
|
+
* Client extension results returned by the platform.
|
|
411
|
+
*/
|
|
412
|
+
clientExtensionResults: Record<string, unknown>;
|
|
413
|
+
/**
|
|
414
|
+
* Assertion response payload.
|
|
415
|
+
*/
|
|
416
|
+
response: PasskeyAuthenticatorAssertionResponseJSON;
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Plugin version payload.
|
|
420
|
+
*
|
|
421
|
+
* @since 1.0.0
|
|
422
|
+
*/
|
|
423
|
+
export interface PluginVersionResult {
|
|
424
|
+
/**
|
|
425
|
+
* Version identifier reported by the current platform implementation.
|
|
426
|
+
*/
|
|
427
|
+
version: string;
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* Passkey support status for the current runtime.
|
|
431
|
+
*
|
|
432
|
+
* @since 1.0.0
|
|
433
|
+
*/
|
|
434
|
+
export interface PasskeySupportResult {
|
|
435
|
+
/**
|
|
436
|
+
* Whether passkeys are available on the current runtime.
|
|
437
|
+
*/
|
|
438
|
+
available: boolean;
|
|
439
|
+
/**
|
|
440
|
+
* Whether conditional mediation is available.
|
|
441
|
+
*/
|
|
442
|
+
conditionalMediation: boolean;
|
|
443
|
+
/**
|
|
444
|
+
* Current platform identifier.
|
|
445
|
+
*/
|
|
446
|
+
platform: 'ios' | 'android' | 'web';
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Capacitor Passkey plugin.
|
|
450
|
+
*
|
|
451
|
+
* Use `autoShimWebAuthn()` or import `@capgo/capacitor-passkey/auto`
|
|
452
|
+
* to keep existing `navigator.credentials.create/get` code working
|
|
453
|
+
* inside a Capacitor app.
|
|
454
|
+
*
|
|
455
|
+
* @since 1.0.0
|
|
456
|
+
*/
|
|
457
|
+
export interface CapacitorPasskeyPlugin {
|
|
458
|
+
/**
|
|
459
|
+
* Install a browser-style WebAuthn shim on top of the native plugin.
|
|
460
|
+
*
|
|
461
|
+
* The shim patches `navigator.credentials.create/get` for `publicKey`
|
|
462
|
+
* requests and returns browser-like credential objects.
|
|
463
|
+
*
|
|
464
|
+
* Use this when you want to override the auto-loaded config manually.
|
|
465
|
+
*
|
|
466
|
+
* @since 1.0.0
|
|
467
|
+
* @example
|
|
468
|
+
* ```typescript
|
|
469
|
+
* import { CapacitorPasskey } from '@capgo/capacitor-passkey';
|
|
470
|
+
*
|
|
471
|
+
* CapacitorPasskey.shimWebAuthn({
|
|
472
|
+
* origin: 'https://signin.example.com',
|
|
473
|
+
* });
|
|
474
|
+
* ```
|
|
475
|
+
*/
|
|
476
|
+
shimWebAuthn(options?: ShimWebAuthnOptions): void;
|
|
477
|
+
/**
|
|
478
|
+
* Load plugin configuration from the host Capacitor app.
|
|
479
|
+
*
|
|
480
|
+
* This reads `plugins.CapacitorPasskey` from `capacitor.config.*`.
|
|
481
|
+
*
|
|
482
|
+
* @since 1.1.0
|
|
483
|
+
*/
|
|
484
|
+
getConfiguration(): Promise<PasskeyRuntimeConfiguration>;
|
|
485
|
+
/**
|
|
486
|
+
* Install the browser-style shim using host app configuration.
|
|
487
|
+
*
|
|
488
|
+
* This is the easiest way to keep existing browser WebAuthn code working:
|
|
489
|
+
* configure the plugin in `capacitor.config.*`, then call this once during
|
|
490
|
+
* app bootstrap or use the `/auto` entrypoint.
|
|
491
|
+
*
|
|
492
|
+
* @since 1.1.0
|
|
493
|
+
* @example
|
|
494
|
+
* ```typescript
|
|
495
|
+
* import { CapacitorPasskey } from '@capgo/capacitor-passkey';
|
|
496
|
+
*
|
|
497
|
+
* await CapacitorPasskey.autoShimWebAuthn();
|
|
498
|
+
* ```
|
|
499
|
+
*/
|
|
500
|
+
autoShimWebAuthn(options?: ShimWebAuthnOptions): Promise<PasskeyRuntimeConfiguration>;
|
|
501
|
+
/**
|
|
502
|
+
* Register a passkey from a JSON-safe WebAuthn request.
|
|
503
|
+
*
|
|
504
|
+
* This method is useful when your backend already returns the
|
|
505
|
+
* `PublicKeyCredentialCreationOptionsJSON` form.
|
|
506
|
+
*
|
|
507
|
+
* @since 1.0.0
|
|
508
|
+
*/
|
|
509
|
+
createCredential(options: CreateCredentialOptions): Promise<PasskeyRegistrationCredential>;
|
|
510
|
+
/**
|
|
511
|
+
* Authenticate with an existing passkey from a JSON-safe WebAuthn request.
|
|
512
|
+
*
|
|
513
|
+
* This method is useful when your backend already returns the
|
|
514
|
+
* `PublicKeyCredentialRequestOptionsJSON` form.
|
|
515
|
+
*
|
|
516
|
+
* @since 1.0.0
|
|
517
|
+
*/
|
|
518
|
+
getCredential(options: GetCredentialOptions): Promise<PasskeyAuthenticationCredential>;
|
|
519
|
+
/**
|
|
520
|
+
* Report whether passkeys are available in the current runtime.
|
|
521
|
+
*
|
|
522
|
+
* @since 1.0.0
|
|
523
|
+
*/
|
|
524
|
+
isSupported(): Promise<PasskeySupportResult>;
|
|
525
|
+
/**
|
|
526
|
+
* Returns the current platform implementation version marker.
|
|
527
|
+
*
|
|
528
|
+
* @since 1.0.0
|
|
529
|
+
*/
|
|
530
|
+
getPluginVersion(): Promise<PluginVersionResult>;
|
|
531
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Supported authenticator attachment values.\n *\n * @since 1.0.0\n */\nexport type PasskeyAuthenticatorAttachment = 'platform' | 'cross-platform';\n\n/**\n * Supported WebAuthn credential type.\n *\n * @since 1.0.0\n */\nexport type PasskeyCredentialType = 'public-key';\n\n/**\n * Supported user verification preferences.\n *\n * @since 1.0.0\n */\nexport type PasskeyUserVerification = 'discouraged' | 'preferred' | 'required';\n\n/**\n * Supported attestation preferences.\n *\n * @since 1.0.0\n */\nexport type PasskeyAttestation = 'none' | 'indirect' | 'direct' | 'enterprise';\n\n/**\n * Supported resident key preferences.\n *\n * @since 1.0.0\n */\nexport type PasskeyResidentKey = 'discouraged' | 'preferred' | 'required';\n\n/**\n * Options used when installing the browser-style shim.\n *\n * @since 1.0.0\n */\nexport interface ShimWebAuthnOptions {\n /**\n * Optional HTTPS origin to encode into iOS 17.4+ clientDataJSON.\n *\n * Use this when your Capacitor app runs from `capacitor://localhost`\n * but your relying party expects `https://signin.example.com`.\n */\n origin?: string;\n\n /**\n * Force the shim even if the runtime already exposes `navigator.credentials`.\n *\n * Defaults to `false`.\n */\n force?: boolean;\n}\n\n/**\n * Runtime configuration loaded from the host app's Capacitor config.\n *\n * This is the shape returned by `getConfiguration()`.\n *\n * @since 1.1.0\n */\nexport interface PasskeyRuntimeConfiguration {\n /**\n * Whether the `/auto` entrypoint should install the shim automatically.\n *\n * Defaults to `true`.\n */\n autoShim: boolean;\n\n /**\n * Optional HTTPS origin used by the auto-shim.\n *\n * On iOS 17.4+ this origin is encoded into `clientDataJSON`.\n */\n origin?: string;\n\n /**\n * Domains associated with the app for passkey usage.\n *\n * These come from `domains` in Capacitor config plus the hostname derived\n * from `origin` when available.\n */\n domains: string[];\n\n /**\n * Current runtime platform.\n */\n platform: 'ios' | 'android' | 'web';\n}\n\n/**\n * JSON-safe representation of a public key credential descriptor.\n *\n * Binary identifiers must be base64url encoded.\n *\n * @since 1.0.0\n */\nexport interface PasskeyCredentialDescriptor {\n /**\n * Base64url-encoded credential identifier.\n */\n id: string;\n\n /**\n * Credential type. Only `public-key` is supported.\n */\n type?: PasskeyCredentialType;\n\n /**\n * Optional transport hints copied from WebAuthn.\n */\n transports?: string[];\n}\n\n/**\n * JSON-safe relying party information.\n *\n * @since 1.0.0\n */\nexport interface PasskeyRelyingParty {\n /**\n * Relying party identifier.\n *\n * If omitted, the shim derives it from the configured origin when possible.\n */\n id?: string;\n\n /**\n * Human-readable relying party name.\n */\n name: string;\n}\n\n/**\n * JSON-safe WebAuthn user entity.\n *\n * Binary identifiers must be base64url encoded.\n *\n * @since 1.0.0\n */\nexport interface PasskeyUserEntity {\n /**\n * Base64url-encoded user handle.\n */\n id: string;\n\n /**\n * User name shown by the authenticator.\n */\n name: string;\n\n /**\n * Optional display name shown by the authenticator.\n */\n displayName?: string;\n}\n\n/**\n * JSON-safe credential parameter entry.\n *\n * @since 1.0.0\n */\nexport interface PasskeyCredentialParameter {\n /**\n * Credential type. Only `public-key` is supported.\n */\n type: PasskeyCredentialType;\n\n /**\n * COSE algorithm identifier.\n */\n alg: number;\n}\n\n/**\n * JSON-safe authenticator selection options.\n *\n * @since 1.0.0\n */\nexport interface PasskeyAuthenticatorSelection {\n /**\n * Optional authenticator attachment hint.\n */\n authenticatorAttachment?: PasskeyAuthenticatorAttachment;\n\n /**\n * Optional resident key preference.\n */\n residentKey?: PasskeyResidentKey;\n\n /**\n * Legacy resident key requirement flag.\n */\n requireResidentKey?: boolean;\n\n /**\n * Optional user verification preference.\n */\n userVerification?: PasskeyUserVerification;\n}\n\n/**\n * JSON-safe registration request options.\n *\n * All binary fields must be base64url encoded.\n *\n * @since 1.0.0\n */\nexport interface PasskeyPublicKeyCredentialCreationOptionsJSON {\n /**\n * Base64url-encoded challenge.\n */\n challenge: string;\n\n /**\n * Relying party information.\n */\n rp: PasskeyRelyingParty;\n\n /**\n * User information.\n */\n user: PasskeyUserEntity;\n\n /**\n * Supported credential algorithms.\n */\n pubKeyCredParams: PasskeyCredentialParameter[];\n\n /**\n * Optional timeout hint in milliseconds.\n */\n timeout?: number;\n\n /**\n * Optional credentials that must be excluded during registration.\n */\n excludeCredentials?: PasskeyCredentialDescriptor[];\n\n /**\n * Optional authenticator preferences.\n */\n authenticatorSelection?: PasskeyAuthenticatorSelection;\n\n /**\n * Optional attestation preference.\n */\n attestation?: PasskeyAttestation;\n\n /**\n * Optional hints copied from the JSON form used by modern WebAuthn toolkits.\n */\n hints?: string[];\n\n /**\n * Optional extensions copied as-is into the request JSON.\n */\n extensions?: Record<string, unknown>;\n}\n\n/**\n * Direct registration request for the plugin transport.\n *\n * @since 1.0.0\n */\nexport interface CreateCredentialOptions {\n /**\n * JSON-safe registration request.\n */\n publicKey: PasskeyPublicKeyCredentialCreationOptionsJSON;\n\n /**\n * Optional HTTPS origin to use for iOS 17.4+ browser-style clientDataJSON.\n */\n origin?: string;\n}\n\n/**\n * JSON-safe authentication request options.\n *\n * All binary fields must be base64url encoded.\n *\n * @since 1.0.0\n */\nexport interface PasskeyPublicKeyCredentialRequestOptionsJSON {\n /**\n * Base64url-encoded challenge.\n */\n challenge: string;\n\n /**\n * Optional timeout hint in milliseconds.\n */\n timeout?: number;\n\n /**\n * Optional relying party identifier.\n *\n * If omitted, the shim derives it from the configured origin when possible.\n */\n rpId?: string;\n\n /**\n * Optional allow list copied from WebAuthn.\n */\n allowCredentials?: PasskeyCredentialDescriptor[];\n\n /**\n * Optional user verification preference.\n */\n userVerification?: PasskeyUserVerification;\n\n /**\n * Optional hints copied from the JSON form used by modern WebAuthn toolkits.\n */\n hints?: string[];\n\n /**\n * Optional extensions copied as-is into the request JSON.\n */\n extensions?: Record<string, unknown>;\n}\n\n/**\n * Direct authentication request for the plugin transport.\n *\n * @since 1.0.0\n */\nexport interface GetCredentialOptions {\n /**\n * JSON-safe authentication request.\n */\n publicKey: PasskeyPublicKeyCredentialRequestOptionsJSON;\n\n /**\n * Optional mediation hint. `conditional` currently falls back to an explicit prompt.\n */\n mediation?: string;\n\n /**\n * Optional HTTPS origin to use for iOS 17.4+ browser-style clientDataJSON.\n */\n origin?: string;\n}\n\n/**\n * JSON-safe attestation response payload.\n *\n * All binary fields are base64url encoded.\n *\n * @since 1.0.0\n */\nexport interface PasskeyAuthenticatorAttestationResponseJSON {\n /**\n * Base64url-encoded clientDataJSON.\n */\n clientDataJSON: string;\n\n /**\n * Base64url-encoded attestation object.\n */\n attestationObject: string;\n\n /**\n * Optional base64url-encoded public key when provided by the platform.\n */\n publicKey?: string;\n\n /**\n * Optional public key algorithm when provided by the platform.\n */\n publicKeyAlgorithm?: number;\n\n /**\n * Optional transport list when provided by the platform.\n */\n transports?: string[];\n}\n\n/**\n * JSON-safe assertion response payload.\n *\n * All binary fields are base64url encoded.\n *\n * @since 1.0.0\n */\nexport interface PasskeyAuthenticatorAssertionResponseJSON {\n /**\n * Base64url-encoded clientDataJSON.\n */\n clientDataJSON: string;\n\n /**\n * Base64url-encoded authenticator data.\n */\n authenticatorData: string;\n\n /**\n * Base64url-encoded signature.\n */\n signature: string;\n\n /**\n * Optional base64url-encoded user handle.\n */\n userHandle?: string | null;\n}\n\n/**\n * JSON-safe registration credential returned by the plugin.\n *\n * @since 1.0.0\n */\nexport interface PasskeyRegistrationCredential {\n /**\n * Base64url-encoded credential identifier.\n */\n id: string;\n\n /**\n * Base64url-encoded raw credential identifier.\n */\n rawId: string;\n\n /**\n * Credential type. Always `public-key`.\n */\n type: PasskeyCredentialType;\n\n /**\n * Optional authenticator attachment reported by the platform.\n */\n authenticatorAttachment?: PasskeyAuthenticatorAttachment;\n\n /**\n * Client extension results returned by the platform.\n */\n clientExtensionResults: Record<string, unknown>;\n\n /**\n * Registration response payload.\n */\n response: PasskeyAuthenticatorAttestationResponseJSON;\n}\n\n/**\n * JSON-safe authentication credential returned by the plugin.\n *\n * @since 1.0.0\n */\nexport interface PasskeyAuthenticationCredential {\n /**\n * Base64url-encoded credential identifier.\n */\n id: string;\n\n /**\n * Base64url-encoded raw credential identifier.\n */\n rawId: string;\n\n /**\n * Credential type. Always `public-key`.\n */\n type: PasskeyCredentialType;\n\n /**\n * Optional authenticator attachment reported by the platform.\n */\n authenticatorAttachment?: PasskeyAuthenticatorAttachment;\n\n /**\n * Client extension results returned by the platform.\n */\n clientExtensionResults: Record<string, unknown>;\n\n /**\n * Assertion response payload.\n */\n response: PasskeyAuthenticatorAssertionResponseJSON;\n}\n\n/**\n * Plugin version payload.\n *\n * @since 1.0.0\n */\nexport interface PluginVersionResult {\n /**\n * Version identifier reported by the current platform implementation.\n */\n version: string;\n}\n\n/**\n * Passkey support status for the current runtime.\n *\n * @since 1.0.0\n */\nexport interface PasskeySupportResult {\n /**\n * Whether passkeys are available on the current runtime.\n */\n available: boolean;\n\n /**\n * Whether conditional mediation is available.\n */\n conditionalMediation: boolean;\n\n /**\n * Current platform identifier.\n */\n platform: 'ios' | 'android' | 'web';\n}\n\n/**\n * Capacitor Passkey plugin.\n *\n * Use `autoShimWebAuthn()` or import `@capgo/capacitor-passkey/auto`\n * to keep existing `navigator.credentials.create/get` code working\n * inside a Capacitor app.\n *\n * @since 1.0.0\n */\nexport interface CapacitorPasskeyPlugin {\n /**\n * Install a browser-style WebAuthn shim on top of the native plugin.\n *\n * The shim patches `navigator.credentials.create/get` for `publicKey`\n * requests and returns browser-like credential objects.\n *\n * Use this when you want to override the auto-loaded config manually.\n *\n * @since 1.0.0\n * @example\n * ```typescript\n * import { CapacitorPasskey } from '@capgo/capacitor-passkey';\n *\n * CapacitorPasskey.shimWebAuthn({\n * origin: 'https://signin.example.com',\n * });\n * ```\n */\n shimWebAuthn(options?: ShimWebAuthnOptions): void;\n\n /**\n * Load plugin configuration from the host Capacitor app.\n *\n * This reads `plugins.CapacitorPasskey` from `capacitor.config.*`.\n *\n * @since 1.1.0\n */\n getConfiguration(): Promise<PasskeyRuntimeConfiguration>;\n\n /**\n * Install the browser-style shim using host app configuration.\n *\n * This is the easiest way to keep existing browser WebAuthn code working:\n * configure the plugin in `capacitor.config.*`, then call this once during\n * app bootstrap or use the `/auto` entrypoint.\n *\n * @since 1.1.0\n * @example\n * ```typescript\n * import { CapacitorPasskey } from '@capgo/capacitor-passkey';\n *\n * await CapacitorPasskey.autoShimWebAuthn();\n * ```\n */\n autoShimWebAuthn(options?: ShimWebAuthnOptions): Promise<PasskeyRuntimeConfiguration>;\n\n /**\n * Register a passkey from a JSON-safe WebAuthn request.\n *\n * This method is useful when your backend already returns the\n * `PublicKeyCredentialCreationOptionsJSON` form.\n *\n * @since 1.0.0\n */\n createCredential(options: CreateCredentialOptions): Promise<PasskeyRegistrationCredential>;\n\n /**\n * Authenticate with an existing passkey from a JSON-safe WebAuthn request.\n *\n * This method is useful when your backend already returns the\n * `PublicKeyCredentialRequestOptionsJSON` form.\n *\n * @since 1.0.0\n */\n getCredential(options: GetCredentialOptions): Promise<PasskeyAuthenticationCredential>;\n\n /**\n * Report whether passkeys are available in the current runtime.\n *\n * @since 1.0.0\n */\n isSupported(): Promise<PasskeySupportResult>;\n\n /**\n * Returns the current platform implementation version marker.\n *\n * @since 1.0.0\n */\n getPluginVersion(): Promise<PluginVersionResult>;\n}\n"]}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { registerPlugin } from '@capacitor/core';
|
|
2
|
+
import { installWebAuthnShim } from './shim';
|
|
3
|
+
import { createNativeRequest } from './webauthn';
|
|
4
|
+
const NativeCapacitorPasskey = registerPlugin('CapacitorPasskey', {
|
|
5
|
+
web: () => import('./web').then((module) => new module.CapacitorPasskeyWeb()),
|
|
6
|
+
});
|
|
7
|
+
let configurationPromise;
|
|
8
|
+
let cachedConfiguration;
|
|
9
|
+
function mergeShimOptions(configuration, options) {
|
|
10
|
+
var _a;
|
|
11
|
+
const origin = (_a = options === null || options === void 0 ? void 0 : options.origin) !== null && _a !== void 0 ? _a : configuration === null || configuration === void 0 ? void 0 : configuration.origin;
|
|
12
|
+
const force = options === null || options === void 0 ? void 0 : options.force;
|
|
13
|
+
if (!origin && force === undefined) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
force,
|
|
18
|
+
origin,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function mergeRuntimeConfiguration(configuration, options) {
|
|
22
|
+
var _a;
|
|
23
|
+
const origin = (_a = options === null || options === void 0 ? void 0 : options.origin) !== null && _a !== void 0 ? _a : configuration.origin;
|
|
24
|
+
const domains = new Set(configuration.domains);
|
|
25
|
+
if (origin) {
|
|
26
|
+
try {
|
|
27
|
+
domains.add(new URL(origin).hostname);
|
|
28
|
+
}
|
|
29
|
+
catch (_b) {
|
|
30
|
+
// Ignore invalid override values here and let native APIs validate later.
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return Object.assign(Object.assign({}, configuration), { domains: [...domains], origin });
|
|
34
|
+
}
|
|
35
|
+
async function loadConfiguration() {
|
|
36
|
+
try {
|
|
37
|
+
const configuration = await NativeCapacitorPasskey.getConfiguration();
|
|
38
|
+
cachedConfiguration = configuration;
|
|
39
|
+
return configuration;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
configurationPromise = undefined;
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const CapacitorPasskey = {
|
|
47
|
+
async autoShimWebAuthn(options) {
|
|
48
|
+
const configuration = await CapacitorPasskey.getConfiguration();
|
|
49
|
+
if (!configuration.autoShim && !(options === null || options === void 0 ? void 0 : options.force)) {
|
|
50
|
+
return configuration;
|
|
51
|
+
}
|
|
52
|
+
const effectiveConfiguration = mergeRuntimeConfiguration(configuration, options);
|
|
53
|
+
cachedConfiguration = effectiveConfiguration;
|
|
54
|
+
installWebAuthnShim({
|
|
55
|
+
options: mergeShimOptions(effectiveConfiguration, options),
|
|
56
|
+
plugin: CapacitorPasskey,
|
|
57
|
+
});
|
|
58
|
+
return effectiveConfiguration;
|
|
59
|
+
},
|
|
60
|
+
async createCredential(options) {
|
|
61
|
+
return NativeCapacitorPasskey.createCredential(createNativeRequest(options));
|
|
62
|
+
},
|
|
63
|
+
async getConfiguration() {
|
|
64
|
+
if (!configurationPromise) {
|
|
65
|
+
configurationPromise = loadConfiguration();
|
|
66
|
+
}
|
|
67
|
+
return configurationPromise;
|
|
68
|
+
},
|
|
69
|
+
async getCredential(options) {
|
|
70
|
+
return NativeCapacitorPasskey.getCredential(createNativeRequest(options));
|
|
71
|
+
},
|
|
72
|
+
async getPluginVersion() {
|
|
73
|
+
return NativeCapacitorPasskey.getPluginVersion();
|
|
74
|
+
},
|
|
75
|
+
async isSupported() {
|
|
76
|
+
return NativeCapacitorPasskey.isSupported();
|
|
77
|
+
},
|
|
78
|
+
shimWebAuthn(options) {
|
|
79
|
+
installWebAuthnShim({
|
|
80
|
+
options: mergeShimOptions(cachedConfiguration, options),
|
|
81
|
+
plugin: CapacitorPasskey,
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
export * from './definitions';
|
|
86
|
+
export { CapacitorPasskey };
|
|
87
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"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","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { CapacitorPasskeyPlugin, PasskeyRuntimeConfiguration, ShimWebAuthnOptions } from './definitions';\nimport type { NativeCapacitorPasskeyPlugin } from './internal';\nimport { installWebAuthnShim } from './shim';\nimport { createNativeRequest } from './webauthn';\n\nconst NativeCapacitorPasskey = registerPlugin<NativeCapacitorPasskeyPlugin>('CapacitorPasskey', {\n web: () => import('./web').then((module) => new module.CapacitorPasskeyWeb()),\n});\n\nlet configurationPromise: Promise<PasskeyRuntimeConfiguration> | undefined;\nlet cachedConfiguration: PasskeyRuntimeConfiguration | undefined;\n\nfunction mergeShimOptions(\n configuration: PasskeyRuntimeConfiguration | undefined,\n options: ShimWebAuthnOptions | undefined,\n): ShimWebAuthnOptions | undefined {\n const origin = options?.origin ?? configuration?.origin;\n const force = options?.force;\n\n if (!origin && force === undefined) {\n return undefined;\n }\n\n return {\n force,\n origin,\n };\n}\n\nfunction mergeRuntimeConfiguration(\n configuration: PasskeyRuntimeConfiguration,\n options: ShimWebAuthnOptions | undefined,\n): PasskeyRuntimeConfiguration {\n const origin = options?.origin ?? configuration.origin;\n const domains = new Set(configuration.domains);\n\n if (origin) {\n try {\n domains.add(new URL(origin).hostname);\n } catch {\n // Ignore invalid override values here and let native APIs validate later.\n }\n }\n\n return {\n ...configuration,\n domains: [...domains],\n origin,\n };\n}\n\nasync function loadConfiguration(): Promise<PasskeyRuntimeConfiguration> {\n try {\n const configuration = await NativeCapacitorPasskey.getConfiguration();\n cachedConfiguration = configuration;\n return configuration;\n } catch (error) {\n configurationPromise = undefined;\n throw error;\n }\n}\n\nconst CapacitorPasskey: CapacitorPasskeyPlugin = {\n async autoShimWebAuthn(options) {\n const configuration = await CapacitorPasskey.getConfiguration();\n if (!configuration.autoShim && !options?.force) {\n return configuration;\n }\n\n const effectiveConfiguration = mergeRuntimeConfiguration(configuration, options);\n cachedConfiguration = effectiveConfiguration;\n\n installWebAuthnShim({\n options: mergeShimOptions(effectiveConfiguration, options),\n plugin: CapacitorPasskey,\n });\n\n return effectiveConfiguration;\n },\n async createCredential(options) {\n return NativeCapacitorPasskey.createCredential(createNativeRequest(options));\n },\n async getConfiguration() {\n if (!configurationPromise) {\n configurationPromise = loadConfiguration();\n }\n\n return configurationPromise;\n },\n async getCredential(options) {\n return NativeCapacitorPasskey.getCredential(createNativeRequest(options));\n },\n async getPluginVersion() {\n return NativeCapacitorPasskey.getPluginVersion();\n },\n async isSupported() {\n return NativeCapacitorPasskey.isSupported();\n },\n shimWebAuthn(options) {\n installWebAuthnShim({\n options: mergeShimOptions(cachedConfiguration, options),\n plugin: CapacitorPasskey,\n });\n },\n};\n\nexport * from './definitions';\nexport { CapacitorPasskey };\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PasskeyAuthenticationCredential, PasskeyRuntimeConfiguration, PasskeyRegistrationCredential, PasskeySupportResult } from './definitions';
|
|
2
|
+
export interface NativePasskeyRequest {
|
|
3
|
+
requestJson: string;
|
|
4
|
+
origin?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface NativeCapacitorPasskeyPlugin {
|
|
7
|
+
createCredential(options: NativePasskeyRequest): Promise<PasskeyRegistrationCredential>;
|
|
8
|
+
getCredential(options: NativePasskeyRequest): Promise<PasskeyAuthenticationCredential>;
|
|
9
|
+
getConfiguration(): Promise<PasskeyRuntimeConfiguration>;
|
|
10
|
+
isSupported(): Promise<PasskeySupportResult>;
|
|
11
|
+
getPluginVersion(): Promise<{
|
|
12
|
+
version: string;
|
|
13
|
+
}>;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../src/internal.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n PasskeyAuthenticationCredential,\n PasskeyRuntimeConfiguration,\n PasskeyRegistrationCredential,\n PasskeySupportResult,\n} from './definitions';\n\nexport interface NativePasskeyRequest {\n requestJson: string;\n origin?: string;\n}\n\nexport interface NativeCapacitorPasskeyPlugin {\n createCredential(options: NativePasskeyRequest): Promise<PasskeyRegistrationCredential>;\n getCredential(options: NativePasskeyRequest): Promise<PasskeyAuthenticationCredential>;\n getConfiguration(): Promise<PasskeyRuntimeConfiguration>;\n isSupported(): Promise<PasskeySupportResult>;\n getPluginVersion(): Promise<{ version: string }>;\n}\n"]}
|