
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
@avaprotocol/sdk-js
Advanced tools
A JavaScript/TypeScript SDK designed to simplify integration with Ava Protocol's AVS
@avaprotocol/sdk-js
is a simple, type-safe wrapper around gRPC designed to simplify integration with Ava Protocol’s AVS. It enables developers to interact with Ava Protocol efficiently, whether on the client-side or server-side, and provides full TypeScript support for a seamless development experience.
To install @avaprotocol/sdk-js
, run the following command:
npm install @avaprotocol/sdk-js
Or with Yarn:
yarn add @avaprotocol/sdk-js
Here’s a quick example of how to use the SDK to get started with Ava Protocol:
import { Client } from "@avaprotocol/sdk-js";
import { getServerSession } from "next-auth";
import { isAuthKeyValid } from "./utils";
import { authOptions } from "./auth/[...nextauth]/route";
let avaClient: Client | null = null;
const EXPIRED_AT = Math.floor(Date.now() / 1000) + 24 * 60 * 60; // 24 hours from now
async function initializeClient() {
if (avaClient) return avaClient;
if (!process.env.AVS_ENDPOINT) {
throw new Error("AVS_ENDPOINT is not set in environment variables.");
}
avaClient = new Client({
endpoint: process.env.AVS_ENDPOINT,
});
return avaClient;
}
/**
* Get the client instance, lazy initialize it if it's not initialized yet
* @returns
*/
export async function getClient() {
if (avaClient) {
return avaClient;
}
return await initializeClient();
}
/**
* Get the auth key using authWithAPIKey() for a wallet address before user signs in with a wallet signature
* @param walletAddress
* @returns
*/
async function getPresignAuthKey(walletAddress: string): Promise<string> {
const client = await getClient();
// Since we almost certainly need this env variable, we throw an error if it's not set
if (!process.env.AVS_API_KEY) {
throw new Error("AVS_API_KEY is not set in environment variables.");
}
const resp = await client.authWithAPIKey(
walletAddress,
process.env.AVS_API_KEY,
EXPIRED_AT
);
return resp.authKey;
}
/**
* Get the auth key for a wallet address
* First checks if the current session contains a valid auth key
* If not, it will get the auth key using authWithAPIKey() for the wallet address
* @param walletAddress
* @returns
*/
export async function getAuthKey(
walletAddress: string | undefined
): Promise<string | undefined> {
const session = await getServerSession(authOptions);
if (session?.user?.authKey) {
if (isAuthKeyValid(session?.user?.authKey)) {
return session?.user?.authKey;
} else {
console.warn(
`AuthKey is found for ${session?.user?.walletAddress} in session, but expired. Atempting to use authWithAPIKey`
);
}
}
if (walletAddress) {
return await getPresignAuthKey(walletAddress);
}
return undefined;
}
We welcome contributions! Feel free to submit pull requests or open issues for any bugs or feature requests.
This project is licensed under the Apache 2.0 License. See the LICENSE file for more details.
FAQs
A JavaScript/TypeScript SDK designed to simplify integration with Ava Protocol's AVS
The npm package @avaprotocol/sdk-js receives a total of 90 weekly downloads. As such, @avaprotocol/sdk-js popularity was classified as not popular.
We found that @avaprotocol/sdk-js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.