feat: enhance ox optional dependency with proper error handling and utility functions #450
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR enhances the existing optional
ox
dependency implementation by adding proper error handling, centralized utility functions, and improved documentation. Whileox
is already marked as optional inpackage.json
, the code still directly imports it without graceful fallbacks.Current State
The main repository already has
ox
marked as an optional peer dependency:However, the codebase still directly imports
ox
in multiple files, which causes runtime errors when the package is not installed.Problem
Even though
ox
is marked as optional, users still encounter confusing errors when trying to use WebAuthn functionality without havingox
installed. The current implementation lacks:ox
packageox
is requiredSolution
packages/permissionless/utils/ox.ts
) to handle optional imports with proper error handlingox
to use the new utility with clear error messagesChanges Made
New Files
packages/permissionless/utils/ox.ts
- Centralized utility for optional ox imports with comprehensive error handlingEnhanced Files
packages/permissionless/README.md
- Added "Optional Dependencies" section with clear installation instructionspackages/permissionless/utils/index.ts
- Exported new ox utility functionsUpdated Files Using ox (now with proper error handling)
packages/permissionless/accounts/kernel/toKernelSmartAccount.ts
- WebAuthn account creationpackages/permissionless/accounts/kernel/utils/signMessage.ts
- WebAuthn signature handlingpackages/permissionless/accounts/safe/toSafeSmartAccount.ts
- WebAuthn public key handlingpackages/permissionless/accounts/safe/signUserOperation.ts
- WebAuthn signature handlingpackages/permissionless/actions/passkeyServer/startAuthentication.ts
- WebAuthn authenticationpackages/permissionless/actions/passkeyServer/startRegistration.ts
- WebAuthn registrationpackages/permissionless/actions/passkeyServer/verifyAuthentication.ts
- WebAuthn verificationpackages/permissionless/actions/passkeyServer/verifyRegistration.ts
- WebAuthn verificationpackages/wagmi-demo/src/PasskeyServerDemo.tsx
- Demo componentBuild Script Fix
package.json
(root) - Fixed Windows compatibility by replacingprintf
withecho
in build scriptsBenefits
ox
is missingox
for non-WebAuthn use casesBefore vs After
Before (Current State)
After (Our Enhancement)
Testing
ox
is missingox
is installedUsage Examples
Without WebAuthn (works fine)
npm install permissionless # ✅ No errors, library works for basic functionality
With WebAuthn (clear guidance)
This enhancement makes the existing optional dependency implementation much more robust and user-friendly.
Closes #399