Current Implementation
Currently, Swig uses the compressed public key format for authentication (not the Ethereum address). A future update will introduce anEvmAddress authority type that uses the hashed form of the public key (the standard Ethereum address).
Integration Examples
Viem Integration (Recommended)
The recommended approach for Ethereum wallet integration uses the Viem library. Here’s a complete example showing different signing methods:- Classic (SVM)
- Kit (Local)
Session-Based Authorization
For enhanced security and better UX, you can use session-based authorization with secp256k1 keys:- Classic
- Kit
Best Practices
-
Wallet Integration
- Use the Viem examples as your primary reference for Ethereum wallet integration
- Choose the appropriate signing method based on your wallet implementation:
- Direct keccak256: Signs raw message bytes directly
- Manual prefix: Adds
\x19Ethereum Signed Message:\n{length}prefix manually - Viem signMessage: Automatically adds Ethereum personal sign prefix
- Test all three signing methods for maximum wallet compatibility
-
API Differences
- Classic: Uses
getCreateSwigInstruction(),getSignInstructions(), andfetchSwig()from SVM context - Kit: Uses similar functions but with Solana Kit’s RPC and address types
- Both support the same signing methods and authority types
- Classic: Uses
-
Security Considerations
- Use session-based authorities for dApp integrations to limit exposure
- Keep session durations appropriate for your use case
- Remember that while using Ethereum keys, you still need a Solana account for transaction fees
-
Implementation Tips
- Use the provided helper functions like
createSecp256k1AuthorityInfo - Implement proper error handling for signing operations
- Use
findRolesBySecp256k1SignerAddress()to locate roles by Ethereum address
- Use the provided helper functions like
Future Developments
The upcomingEvmAddress authority type will allow using the standard Ethereum address format (the hashed form of the public key) instead of the current compressed public key format. This will make integration even more straightforward and familiar to Ethereum developers.
Additional Resources
For complete working examples, check out these files in the swig-ts repository: Classic Examples:examples/basic/classic/using-viem.ts- Viem integrationexamples/basic/classic/transfer-secp-session.ts- Session-based authorizationexamples/basic/classic/transfer-secp.ts- Basic secp256k1 usage
examples/basic/kit/using-viem.ts- Viem integration with Kitexamples/basic/kit/transfer-secp.ts- Secp256k1 example with Kit

