-
Notifications
You must be signed in to change notification settings - Fork 26
Add support for parseCreationOptionsFromJSON and parseRequestOptionsFromJSON (issue #39) #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…N conversion - Removed unused imports and consolidated extension handling by utilizing new JSON conversion functions. - Updated credential creation and retrieval methods to parse options directly from JSON, enhancing code clarity and maintainability. - Simplified client extension results processing to align with the latest WebAuthn specifications.
WalkthroughThe changes add cross-platform JSON parsing utilities for WebAuthn, expose parseCreationOptionsFromJSON and parseRequestOptionsFromJSON, introduce isJSONFormat detection, and refactor the web module to use native PublicKeyCredential.parseCreationOptionsFromJSON/parseRequestOptionsFromJSON while centralizing extension-warning logic. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant WebModule
participant BrowserWebAuthn
participant JSONUtils
rect rgb(220,240,255)
Note over Client,WebModule: Before (manual parsing)
Client->>WebModule: send JSON request
WebModule->>WebModule: manually convert fields (base64, descriptors, user)
WebModule->>BrowserWebAuthn: navigator.credentials.create({ publicKey })
BrowserWebAuthn-->>WebModule: credential + extensions
end
rect rgb(220,255,220)
Note over Client,BrowserWebAuthn: After (native parse)
Client->>WebModule: send JSON request
WebModule->>BrowserWebAuthn: PublicKeyCredential.parseCreationOptionsFromJSON(request)
BrowserWebAuthn-->>WebModule: Parsed PublicKeyCredentialCreationOptions
WebModule->>BrowserWebAuthn: navigator.credentials.create(options)
BrowserWebAuthn-->>WebModule: credential + extensions
end
rect rgb(255,245,200)
Note over WebModule,JSONUtils: Extension conversion
WebModule->>JSONUtils: authenticationExtensionsClientOutputsToJSON(extensions)
JSONUtils-->>WebModule: clientExtensionResults (JSON)
WebModule-->>Client: AuthenticationResponseJSON
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
🔇 Additional comments (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
.changeset/feat-parse-json-options-39.md(1 hunks)src/ReactNativePasskeysModule.web.ts(5 hunks)src/utils/is-json-format.ts(1 hunks)src/utils/json.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/ReactNativePasskeysModule.web.ts (3)
src/utils/json.ts (1)
authenticationExtensionsClientOutputsToJSON(218-267)src/ReactNativePasskeys.types.ts (2)
AuthenticationExtensionsClientOutputs(168-180)AuthenticationResponseJSON(96-103)src/utils/warn-user-of-missing-webauthn-extensions.ts (1)
warnUserOfMissingWebauthnExtensions(9-22)
src/utils/json.ts (3)
src/ReactNativePasskeys.types.ts (15)
Base64URLString(35-35)PublicKeyCredentialUserEntityJSON(39-39)PublicKeyCredentialUserEntity(29-29)PublicKeyCredentialDescriptorJSON(38-38)PublicKeyCredentialDescriptor(24-24)AuthenticationExtensionsPRFValuesJSON(226-229)AuthenticationExtensionsClientInputs(142-146)AuthenticationExtensionsLargeBlobInputs(153-163)AuthenticationExtensionsPRFInputs(121-133)AuthenticationExtensionsClientOutputs(168-180)AuthenticationExtensionsClientOutputsJSON(182-191)PublicKeyCredentialCreationOptionsJSON(51-61)PublicKeyCredentialCreationOptions(23-23)PublicKeyCredentialRequestOptionsJSON(66-73)PublicKeyCredentialRequestOptions(26-26)src/utils/base64.ts (1)
base64URLStringToBuffer(9-34)android/src/main/java/expo/modules/passkeys/PasskeyOptions.kt (1)
challenge(69-88)
…JSON These functions allow users to convert JSON credential options to the format expected by the WebAuthn API, enabling cross-platform usage. - parseCreationOptionsFromJSON: converts PublicKeyCredentialCreationOptionsJSON - parseRequestOptionsFromJSON: converts PublicKeyCredentialRequestOptionsJSON Both functions handle base64url decoding and ArrayBuffer conversions following the WebAuthn Level 3 specification.
Summary
Fixes #39 - Support new static methods
parseCreationOptionsFromJSON&parseRequestOptionsFromJSONThis PR implements comprehensive support for the browser's native
parseCreationOptionsFromJSONandparseRequestOptionsFromJSONstatic methods introduced in WebAuthn Level 3, enabling seamless JSON-to-WebAuthn conversion on the web platform.Changes
New JSON Conversion Utilities (
src/utils/json.ts)publicKeyCredentialCreationOptionsFromJSONandpublicKeyCredentialRequestOptionsFromJSONfor internal useWeb Module Refactor (
src/ReactNativePasskeysModule.web.ts)PublicKeyCredential.parseCreationOptionsFromJSONandparseRequestOptionsFromJSON(~10 lines)authenticationExtensionsClientOutputsToJSONfor cleaner extension result handlingAdditional Utilities
isJSONFormatutility (src/utils/is-json-format.ts) to detect JSON vs binary formatwarnUserOfMissingWebauthnExtensionsto separate file for better organizationBenefits
Testing
The changes maintain backward compatibility while enabling the new JSON parsing methods. All existing functionality continues to work as expected.
Files Changed
src/utils/json.ts- New comprehensive JSON conversion utilities (354 lines)src/utils/is-json-format.ts- New utility to detect JSON format (34 lines)src/ReactNativePasskeysModule.web.ts- Refactored to use native parsing methods (-100 lines)src/utils/warn-user-of-missing-webauthn-extensions.ts- Extracted extension warning logic🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Refactor