This page documents the authentication mechanisms in the AVA SDK JS, explaining how to authenticate with the Ava Protocol's AVS.
This page documents the authentication mechanisms in the AVA SDK JS, explaining how to authenticate with the Ava Protocol's Actively Validated Service (AVS) to access workflow management features. For information about the Client interface that uses these authentication methods, see Client Interface.
The AVA SDK requires authentication to interact with AVS services. All operations except the initial authentication calls require a valid authentication key (auth key). The SDK supports two authentication methods:
Sources:
Signature-based authentication uses a cryptographic signature from an EOA wallet to verify identity. This is the most common authentication method for blockchain applications.
The signature is created by signing a message containing the authentication parameters with the private key of the wallet. The AVS service verifies the signature against the provided address.
Sources:
API key authentication provides a way to authenticate without requiring an EOA signature, useful for server-side applications or automated processes.
The API key must be previously provisioned through the Ava Protocol service.
Sources:
Both authentication methods share similar parameters:
| Parameter | Type | Description |
|---|---|---|
chainId | number | The blockchain network ID |
address | string | The EOA wallet address |
issuedAt | Date | When the authentication request was created |
expiredAt | Date | When the authentication request should expire |
signature/apiKey | string | The signature or API key for authentication |
Sources:
Sources:
The auth key returned by the authentication methods is a JWT (JSON Web Token) with the following structure:
Header: Contains the algorithm and token type
Payload: Contains claims about the identity and token validity
iss: Issuer ("AvaProtocol")sub: Subject (EOA address for signature auth)exp: Expiration timestampSignature: Cryptographic signature from the AVS
Sources:
After successful authentication, you can store the auth key in the client for subsequent requests:
Sources:
You can also provide an auth key for individual requests through the options parameter:
This is useful when you need to use different auth keys for different operations or when you don't want to store the auth key in the client.
Sources:
The SDK includes a method to check if an auth key is valid by decoding the JWT token and checking the expiration time:
This method does not verify the signature of the JWT, only checks if the token has expired.
Sources:
Unauthenticated requests will fail with an error message containing "unauthenticated". This happens when:
Sources:
Sources:
Here's a complete example showing how to authenticate with a signature and make an authenticated request:
Sources: