useWallet hook/composable/primitive provides a signData method for implementing ARC-60 authentication with the Lute wallet provider. This guide demonstrates how to implement Sign-In with Algorand (SIWA) using Lute wallet.
Implementation
Here’s how to implement ARC-60 authentication:How it works
Create SIWA request
The code creates a Sign-In with Algorand (SIWA) request object containing:Required properties
domain- The current hostchain_id- The Algorand network ID (283 for MainNet)account_address- The user’s wallet addresstype- The signature type (ed25519)uri- The origin URLversion- The SIWA version
statement- A human-readable statement about the purpose of the sign-innonce- A unique value to prevent replay attacksissued-at- The timestamp when the request was createdexpiration-time- When the request should expirenot-before- The earliest time the request should be considered validrequest-id- A unique identifier for the requestresources- An array of URIs the user is requesting access to
Sign data
The request is converted to base64 and signed using the
signData method with:scope- Set to ‘auth’ for authenticationencoding- Set to ‘base64’ for the data format
Signature verificationWhile this example demonstrates signature verification in the front-end for simplicity, in a production environment, it’s generally better to perform signature verification on the backend. This approach provides better security and allows for proper session management and authentication state persistence.
Error handling
The implementation includes error handling for:- Missing active account
- Unsupported wallet provider
- Failed signature verification
- General signing errors
Best practices
- Always verify the signature before accepting the authentication
- Store the authentication result securely
- Implement proper error handling and user feedback
- Use HTTPS for secure communication
- Consider implementing session management
Resources
- CAIP-122 specification - Chain-agnostic sign-in standard
- ARC-60 specification - Algorand implementation of CAIP-122 (Draft)