Passkey Integration with Swig Wallet
This documentation covers how to integrate WebAuthn passkeys with Swig Wallet for secure, passwordless authentication on Solana.Reference Implementations
This guide references two key examples from the Swig TypeScript SDK:- secp256r1 Transfer Example - Complete implementation using secp256r1 keys for transfers with LiteSVM testing
- Interactive Passkey UI - Full UI demonstration with passkey helper functions and user authentication flows. Key files:
passkey.ts- Core PasskeyManager implementationpasskey.tsx- React hooks for passkey integration
Overview
Swig Wallet supports WebAuthn passkeys through the secp256r1 elliptic curve, enabling users to authenticate using biometrics, security keys, or platform authenticators without requiring passwords or seed phrases.Key Components
PasskeyManager Class
ThePasskeyManager class provides a complete interface for creating, storing, and using passkeys:
PasskeyManager implementation (create, sign, and stored credential helpers):
Core Features
- Passkey Creation: Generate new WebAuthn credentials
- Secure Storage: Store credentials in browser localStorage
- Message Signing: Sign transactions using passkeys
- Browser Support Detection: Check WebAuthn compatibility
Usage Guide
1. Check Browser Support
Before implementing passkeys, verify browser support:2. Create a Passkey
Create a new passkey credential for a user:createPasskey method:
- Uses ES256 algorithm (secp256r1 with SHA-256)
- Requires platform authenticator (built-in biometrics)
- Sets 60-second timeout
- Automatically stores the credential
3. Sign Messages with Passkeys
Use the stored passkey to sign transaction messages:4. Retrieve Stored Credentials
Access previously created passkey credentials:5. Clear Stored Credentials
Remove passkey data from storage:Advanced Integration
Custom Signing Function
Create a reusable signing function for your application:Direct WebAuthn Integration
For advanced use cases, use the low-level WebAuthn functions:Raw secp256r1 Keys (Testing & Development)
For testing without WebAuthn or when you need direct cryptographic control, use raw secp256r1 private keys:- Testing and development environments
- Server-side applications
- When WebAuthn is not available
- Automated scripts and tooling
- Non-browser environments
Technical Details
Public Key Format
Passkeys use compressed secp256r1 public keys (33 bytes):- 1 byte prefix (0x02 or 0x03)
- 32 bytes X-coordinate
PasskeyManager automatically converts SPKI format to compressed format.
Signature Format
WebAuthn signatures are:- Raw 64-byte format (not DER encoded)
- Normalized S values (canonical signatures)
- Generated from
hash(authenticatorData + SHA256(clientDataJSON))
Authentication Data
The WebAuthn prefix includes:- Authentication type identifier
- Authenticator data
- Client data field order
- Huffman-compressed origin URL
- Additional WebAuthn metadata
Security Considerations
Best Practices
- Verify Origin: Passkeys are bound to your domain origin
- Timeout Handling: Set appropriate timeouts for user experience
- Error Handling: Gracefully handle user cancellation
- Fallback Options: Provide alternative auth methods
- Secure Storage: Credentials in localStorage are domain-isolated
Browser Requirements
- Chrome 67+ / Safari 14+ / Firefox 60+
- HTTPS required (except localhost)
- Platform authenticator support varies by device
Example Implementation
WebAuthn Passkey Example
Here’s a complete example integrating passkeys with Swig Wallet:Raw secp256r1 Key Example (LiteSVM Testing)
For testing with LiteSVM or other development scenarios:Examples
Check out these working implementations:secp256r1 Transfer Example
Complete example using secp256r1 keys for transfers with LiteSVM testing
Passkey UI Example
Interactive UI demonstrating passkey integration with helper functions
Troubleshooting
Common Issues
- “WebAuthn not supported”: Browser lacks WebAuthn API
- “No authenticator available”: Device lacks biometric/security key
- “User cancelled”: User declined authentication prompt
- “Invalid domain”: Origin mismatch or non-HTTPS context
Debug Tips
- Test on multiple devices and browsers
- Check browser console for detailed WebAuthn errors
- Verify HTTPS in production environments
- Test with different authenticator types
Resources
- Swig secp256r1 Authority Documentation
- Swig Passkey UI Example - Interactive UI implementation with passkey helpers

