@capgo/capacitor-passkey 8.4.0 → 8.5.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.
@@ -424,6 +424,61 @@ export interface PasskeyAuthenticationCredential {
424
424
  */
425
425
  response: PasskeyAuthenticatorAssertionResponseJSON;
426
426
  }
427
+ /**
428
+ * Shape of the `data` object on a rejected passkey call.
429
+ *
430
+ * Capacitor surfaces this as `error.data` on the rejected promise.
431
+ * `code` / `name` on the error stay WebAuthn-style (`NotAllowedError`, etc.);
432
+ * platform diagnostics live under `native` when available.
433
+ *
434
+ * @since 8.5.0
435
+ */
436
+ export interface PasskeyErrorData {
437
+ /**
438
+ * WebAuthn-style error name. Same value as the Capacitor error code.
439
+ */
440
+ name: string;
441
+ /**
442
+ * Platform error details, for diagnostics.
443
+ *
444
+ * Omitted when the plugin itself raised the failure (for example invalid
445
+ * request JSON) rather than the native credential API.
446
+ */
447
+ native?: PasskeyNativeErrorDetails;
448
+ }
449
+ /**
450
+ * Platform-native error details attached to a rejected passkey call.
451
+ *
452
+ * Nested and platform-neutral so Android can report the same shape later.
453
+ *
454
+ * @since 8.5.0
455
+ */
456
+ export interface PasskeyNativeErrorDetails {
457
+ /**
458
+ * Platform that produced the native error.
459
+ */
460
+ platform: 'ios' | 'android';
461
+ /**
462
+ * Platform error code.
463
+ *
464
+ * On iOS this is the `ASAuthorizationError` code (for example `1004` when
465
+ * the webcredentials association cannot be verified).
466
+ */
467
+ code: number | string;
468
+ /**
469
+ * Platform error domain.
470
+ *
471
+ * On iOS this is the `NSError` domain (for example
472
+ * `com.apple.AuthenticationServices.AuthorizationError`).
473
+ */
474
+ domain?: string;
475
+ /**
476
+ * Platform-provided failure reason, when available.
477
+ *
478
+ * On iOS this comes from `NSLocalizedFailureReasonErrorKey`.
479
+ */
480
+ failureReason?: string;
481
+ }
427
482
  /**
428
483
  * Plugin version payload.
429
484
  *
@@ -1 +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 native `cap sync/update` hook should wire host projects automatically.\n *\n * Defaults to `true`.\n */\n autoShim: boolean;\n\n /**\n * Optional HTTPS origin used by the config-driven shim install.\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 * Prefer passkeys stored on the local device, skipping the hybrid/nearby-device picker.\n * Fails with `NotAllowedError` when no local credential exists. Ignored on web and iOS 15.\n */\n preferImmediatelyAvailableCredentials?: boolean;\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 * Optional base64url-encoded authenticator data.\n */\n authenticatorData?: 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()` to keep existing `navigator.credentials.create/get`\n * code working 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.\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"]}
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 native `cap sync/update` hook should wire host projects automatically.\n *\n * Defaults to `true`.\n */\n autoShim: boolean;\n\n /**\n * Optional HTTPS origin used by the config-driven shim install.\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 * Prefer passkeys stored on the local device, skipping the hybrid/nearby-device picker.\n * Fails with `NotAllowedError` when no local credential exists. Ignored on web and iOS 15.\n */\n preferImmediatelyAvailableCredentials?: boolean;\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 * Optional base64url-encoded authenticator data.\n */\n authenticatorData?: 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 * Shape of the `data` object on a rejected passkey call.\n *\n * Capacitor surfaces this as `error.data` on the rejected promise.\n * `code` / `name` on the error stay WebAuthn-style (`NotAllowedError`, etc.);\n * platform diagnostics live under `native` when available.\n *\n * @since 8.5.0\n */\nexport interface PasskeyErrorData {\n /**\n * WebAuthn-style error name. Same value as the Capacitor error code.\n */\n name: string;\n\n /**\n * Platform error details, for diagnostics.\n *\n * Omitted when the plugin itself raised the failure (for example invalid\n * request JSON) rather than the native credential API.\n */\n native?: PasskeyNativeErrorDetails;\n}\n\n/**\n * Platform-native error details attached to a rejected passkey call.\n *\n * Nested and platform-neutral so Android can report the same shape later.\n *\n * @since 8.5.0\n */\nexport interface PasskeyNativeErrorDetails {\n /**\n * Platform that produced the native error.\n */\n platform: 'ios' | 'android';\n\n /**\n * Platform error code.\n *\n * On iOS this is the `ASAuthorizationError` code (for example `1004` when\n * the webcredentials association cannot be verified).\n */\n code: number | string;\n\n /**\n * Platform error domain.\n *\n * On iOS this is the `NSError` domain (for example\n * `com.apple.AuthenticationServices.AuthorizationError`).\n */\n domain?: string;\n\n /**\n * Platform-provided failure reason, when available.\n *\n * On iOS this comes from `NSLocalizedFailureReasonErrorKey`.\n */\n failureReason?: string;\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()` to keep existing `navigator.credentials.create/get`\n * code working 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.\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"]}
@@ -1,3 +1,5 @@
1
+ import AuthenticationServices
2
+ import Capacitor
1
3
  import Foundation
2
4
 
3
5
  @objc public class CapacitorPasskey: NSObject {
@@ -31,6 +33,36 @@ import Foundation
31
33
 
32
34
  return data
33
35
  }
36
+
37
+ static func errorName(for code: ASAuthorizationError.Code) -> String {
38
+ switch code {
39
+ case .canceled, .failed, .notHandled:
40
+ return "NotAllowedError"
41
+ case .matchedExcludedCredential:
42
+ return "InvalidStateError"
43
+ default:
44
+ return "UnknownError"
45
+ }
46
+ }
47
+
48
+ static func nativeErrorDetails(from error: Error) -> JSObject? {
49
+ guard let authorizationError = error as? ASAuthorizationError else {
50
+ return nil
51
+ }
52
+
53
+ let nsError = error as NSError
54
+ var details: JSObject = [
55
+ "platform": "ios",
56
+ "code": authorizationError.code.rawValue,
57
+ "domain": nsError.domain
58
+ ]
59
+
60
+ if let reason = nsError.userInfo[NSLocalizedFailureReasonErrorKey] as? String {
61
+ details["failureReason"] = reason
62
+ }
63
+
64
+ return details
65
+ }
34
66
  }
35
67
 
36
68
  struct PasskeyPluginError: Error {
@@ -119,9 +119,9 @@ private func normalizeDomain(_ value: String?) -> String? {
119
119
 
120
120
  @objc(CapacitorPasskeyPlugin)
121
121
  public class CapacitorPasskeyPlugin: CAPPlugin,
122
- CAPBridgedPlugin,
123
- ASAuthorizationControllerDelegate,
124
- ASAuthorizationControllerPresentationContextProviding {
122
+ CAPBridgedPlugin,
123
+ ASAuthorizationControllerDelegate,
124
+ ASAuthorizationControllerPresentationContextProviding {
125
125
  public let identifier = "CapacitorPasskeyPlugin"
126
126
  public let jsName = "CapacitorPasskey"
127
127
  public let pluginMethods: [CAPPluginMethod] = [
@@ -242,14 +242,17 @@ public class CapacitorPasskeyPlugin: CAPPlugin,
242
242
 
243
243
  clearPendingRequest()
244
244
  if let authorizationError = error as? ASAuthorizationError {
245
- switch authorizationError.code {
246
- case .canceled, .failed, .notHandled:
247
- reject(call, name: "NotAllowedError", message: authorizationError.localizedDescription, error: error)
248
- case .matchedExcludedCredential:
249
- reject(call, name: "InvalidStateError", message: authorizationError.localizedDescription, error: error)
250
- default:
251
- reject(call, name: "UnknownError", message: authorizationError.localizedDescription, error: error)
245
+ var data: JSObject = [:]
246
+ if let native = CapacitorPasskey.nativeErrorDetails(from: error) {
247
+ data["native"] = native
252
248
  }
249
+ reject(
250
+ call,
251
+ name: CapacitorPasskey.errorName(for: authorizationError.code),
252
+ message: authorizationError.localizedDescription,
253
+ error: error,
254
+ data: data
255
+ )
253
256
  return
254
257
  }
255
258
 
@@ -395,8 +398,15 @@ public class CapacitorPasskeyPlugin: CAPPlugin,
395
398
  reject(call, name: error.name, message: error.message)
396
399
  }
397
400
 
398
- private func reject(_ call: CAPPluginCall, name: String, message: String, error: Error? = nil) {
399
- let data: JSObject = ["name": name]
400
- call.reject(message, name, error, data)
401
+ private func reject(
402
+ _ call: CAPPluginCall,
403
+ name: String,
404
+ message: String,
405
+ error: Error? = nil,
406
+ data: JSObject = [:]
407
+ ) {
408
+ var payload = data
409
+ payload["name"] = name
410
+ call.reject(message, name, error, payload)
401
411
  }
402
412
  }
@@ -1,3 +1,4 @@
1
+ import AuthenticationServices
1
2
  import XCTest
2
3
  @testable import CapacitorPasskeyPlugin
3
4
 
@@ -14,4 +15,56 @@ class CapacitorPasskeyPluginTests: XCTestCase {
14
15
 
15
16
  XCTAssertEqual(input, decoded)
16
17
  }
18
+
19
+ func testErrorNameMatrix() {
20
+ let cases: [(ASAuthorizationError.Code, String)] = [
21
+ (.canceled, "NotAllowedError"),
22
+ (.failed, "NotAllowedError"),
23
+ (.notHandled, "NotAllowedError"),
24
+ ]
25
+
26
+ for (code, expected) in cases {
27
+ XCTAssertEqual(
28
+ CapacitorPasskey.errorName(for: code),
29
+ expected,
30
+ "ASAuthorizationError.Code rawValue \(code.rawValue)"
31
+ )
32
+ }
33
+
34
+ if #available(iOS 18.0, *) {
35
+ XCTAssertEqual(
36
+ CapacitorPasskey.errorName(for: .matchedExcludedCredential),
37
+ "InvalidStateError"
38
+ )
39
+ }
40
+ }
41
+
42
+ func testNativeErrorDetailsMatrix() throws {
43
+ let associationFailure = NSError(
44
+ domain: ASAuthorizationError.errorDomain,
45
+ code: ASAuthorizationError.Code.failed.rawValue,
46
+ userInfo: [NSLocalizedFailureReasonErrorKey: "Unable to verify webcredentials association"]
47
+ )
48
+ let associationDetails = try XCTUnwrap(CapacitorPasskey.nativeErrorDetails(from: associationFailure))
49
+ XCTAssertEqual(associationDetails["code"] as? Int, 1004)
50
+ XCTAssertEqual(associationDetails["platform"] as? String, "ios")
51
+ XCTAssertEqual(associationDetails["domain"] as? String, ASAuthorizationError.errorDomain)
52
+ XCTAssertEqual(
53
+ associationDetails["failureReason"] as? String,
54
+ "Unable to verify webcredentials association"
55
+ )
56
+
57
+ let canceled = NSError(
58
+ domain: ASAuthorizationError.errorDomain,
59
+ code: ASAuthorizationError.Code.canceled.rawValue,
60
+ userInfo: [:]
61
+ )
62
+ let canceledDetails = try XCTUnwrap(CapacitorPasskey.nativeErrorDetails(from: canceled))
63
+ XCTAssertEqual(canceledDetails["code"] as? Int, 1001)
64
+ XCTAssertEqual(canceledDetails["platform"] as? String, "ios")
65
+ XCTAssertNil(canceledDetails["failureReason"])
66
+
67
+ let unrelated = NSError(domain: NSURLErrorDomain, code: NSURLErrorTimedOut, userInfo: nil)
68
+ XCTAssertNil(CapacitorPasskey.nativeErrorDetails(from: unrelated))
69
+ }
17
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-passkey",
3
- "version": "8.4.0",
3
+ "version": "8.5.2",
4
4
  "description": "Capacitor passkey plugin with a WebAuthn-style shim for Capacitor apps.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -51,6 +51,7 @@
51
51
  "watch": "tsc --watch",
52
52
  "prepublishOnly": "bun run build",
53
53
  "check:wiring": "node scripts/check-capacitor-plugin-wiring.mjs",
54
+ "check:cap9-deprecated": "node scripts/check-cap9-deprecated.mjs",
54
55
  "example:install": "cd example-app && bun install --frozen-lockfile",
55
56
  "example:build": "bun run build && cd example-app && bun install --frozen-lockfile && bun run build",
56
57
  "changelog:ai": "node scripts/generate-ai-changelog.mjs"