1.0.4 • Published 8 months ago

@radiustechsystems/ai-agent-plugin-crypto v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Radius AI Agent Toolkit - Crypto Plugin

This plugin provides AI agents with cryptographic utilities for working with Radius, including address validation and hash generation capabilities.

This package is part of the Radius AI Agent Toolkit, which provides tools for integrating AI agents with the Radius platform.

Installation

# Install this specific package
npm install @radiustechsystems/ai-agent-plugin-crypto

# Required peer dependencies
npm install @radiustechsystems/ai-agent-core
npm install @radiustechsystems/ai-agent-wallet
npm install @radiustechsystems/sdk

Prerequisites

  • Node.js >=20.12.2 <23

Usage

import { crypto } from "@radiustechsystems/ai-agent-plugin-crypto";
import { createRadiusWallet } from "@radiustechsystems/ai-agent-wallet";
import { getOnChainTools } from "@radiustechsystems/ai-agent-adapter-vercel-ai";

// Create a Radius wallet
const wallet = await createRadiusWallet({
  rpcUrl: process.env.RPC_PROVIDER_URL,
  privateKey: process.env.WALLET_PRIVATE_KEY
});

// Initialize the Crypto plugin
const cryptoPlugin = crypto();

// Create AI agent tools with the Crypto plugin
const tools = await getOnChainTools({
  wallet,
  plugins: [cryptoPlugin]
});

Example: Using Crypto Tools

// Example of using the crypto plugin through an AI agent
const result = await generateText({
  model: openai("gpt-4o"),
  tools,
  maxSteps: 10,
  prompt: `Validate if 0x1234abcd... is a valid Ethereum address and generate a Keccak-256 hash of the text "Hello Radius"`,
});

// The AI will use the validate_address and hash_data tools

API Reference

crypto()

Creates a new Crypto plugin instance.

Returns:

  • A CryptoPlugin instance that can be used with AI agent frameworks

Provided Tools

The Crypto plugin provides the following AI agent tools:

validate_address

Validates if an address is properly formatted and checksummed for Radius.

Parameters:

  • address (string): The address to validate

Example:

try {
  const validationResult = await validateAddressTool.execute({
    address: "0xefbf7a6fa61a1602eb7630c92e79e5b6e63909e1"
  });
  console.log(`Is valid address: ${validationResult.isValid}`);
  console.log(`Checksummed address: ${validationResult.address}`);
} catch (error) {
  console.error(`Validation failed: ${error.message}`);
}

hash_data

Generates a Keccak-256 hash of input data with support for different encodings.

Parameters:

  • data (string): The data to hash
  • encoding (string, optional): The encoding to use ("utf8" or "hex", defaults to "utf8")

Example:

try {
  // Hash UTF-8 string
  const hashResult = await hashDataTool.execute({
    data: "Hello, Radius!",
    encoding: "utf8"
  });
  console.log(`Hash: ${hashResult.hash}`);
  
  // Hash hex data
  const hexHashResult = await hashDataTool.execute({
    data: "0x1234567890abcdef",
    encoding: "hex"
  });
  console.log(`Hash of hex: ${hexHashResult.hash}`);
} catch (error) {
  console.error(`Hashing failed: ${error.message}`);
}

Note on Tool Naming: The tool names in this documentation (validate_address, hash_data) match the actual names used at runtime. The @Tool decorator in the implementation automatically converts camelCase method names to snake_case for the final tool names.

Integration Examples

For a complete example integrating this plugin with AI frameworks, see:

Related Packages

Resources

Contributing

Please see the Contributing Guide for detailed information about contributing to this toolkit.

License

This project is licensed under the MIT License.