open-index/open-npm huggingface dataset:
npm package: @lit-protocol/aw-contracts-sdk
Description: This package contains the contracts and some utility functions for interacting with the `PkpToolRegistry` contracts.
Latest version: 0.1.0-23

# aw-contracts-sdk

This package contains the contracts and some utility functions for interacting with the `PkpToolRegistry` contracts.

The Ethers.js human-readable ABI is located in [`src/lib/human-readable-abi.ts`](src/lib/human-readable-abi.ts), and can be imported from this package as `PKP_TOOL_REGISTRY_ABI`.

You can also import `getPkpToolRegistryContract` function and call it to get an ether.js contract instance of `PkpToolRegistry`.

`DEFAULT_REGISTRY_CONFIG` is also exported and contains the `PkpToolRegistry` contract addresses for the different Lit networks.
npm package: @lit-protocol/aw-subagent-openai
Description: Subagent is a utility that uses OpenAI to parse user intents and match them to the appropriate tools. It’s designed to simplify the process of understanding user requests and mapping them to the correct tools in a web3 environment.
Latest version: 0.1.0-23

# Subagent: Intent Parsing and Tool Matching

Subagent is a utility that uses OpenAI to parse user intents and match them to the appropriate tools. It’s designed to simplify the process of understanding user requests and mapping them to the correct tools in a web3 environment.

## How It Works

1. **Intent Matching**: Subagent analyzes a user’s intent (e.g., "I want to mint an NFT") and matches it to a registered tool.
2. **Parameter Parsing**: If a tool is matched, Subagent extracts and validates the required parameters from the user’s intent.
3. **OpenAI Integration**: It uses OpenAI’s API to perform intent analysis and parameter extraction.

## Example Usage

```typescript
import { OpenAiIntentMatcher } from './agent';
import type { AwTool } from '@lit-protocol/aw-tool';

// Initialize Subagent
const apiKey = 'your-openai-api-key';
const intentMatcher = new OpenAiIntentMatcher(apiKey);

// Register tools
const registeredTools: AwTool<any, any>[] = [
  {
    name: 'MintNFT',
    description: 'Mint a new NFT',
    ipfsCid: 'QmExampleCID1',
    parameters: {
      descriptions: {
        tokenId: 'The ID of the token to mint',
        recipient: 'The address of the recipient',
      },
      schema: {}, // Zod schema for validation
      validate: (params) => true, // Validation logic
    },
  },
  // Add more tools as needed
];

// Analyze user intent
const userIntent = "I want to mint an NFT with token ID 123 to address 0x123...";
const result = await intentMatcher.analyzeIntentAndMatchTool(userIntent, registeredTools);

// Check results
if (result.matchedTool) {
  console.log('Matched Tool:', result.matchedTool.name);
  console.log('Found Parameters:', result.params.foundParams);
  console.log('Missing Parameters:', result.params.missingParams);
} else {
  console.log('No matching tool found.');
}
```

Key Features

    Intent Matching: Matches user intents to registered tools.

    Parameter Extraction: Parses and validates parameters from the user’s intent.

    OpenAI Integration: Uses OpenAI for accurate intent analysis.

Conclusion

Subagent makes it easy to parse user intents and match them to the right tools, ensuring seamless execution in web3 workflows.
npm package: @lit-protocol/aw-tool
Description: This guide will walk you through the process of creating a new Agent Wallet tool package for the Lit Agent Wallet system.
Latest version: 0.1.0-23

# Creating a New Agent Wallet Tool Package

This guide will walk you through the process of creating a new Agent Wallet tool package for the Lit Agent Wallet system.

## Initial Setup

1. Generate the package scaffold using Nx:
```bash
npx nx g @nx/js:lib packages/aw-tool-TOOL_NAME --publishable --importPath=@lit-protocol/aw-tool-TOOL_NAME
```

2. When prompted for project configuration options, select:
   - TypeScript for the compiler
   - ESLint for linting
   - Jest for testing

## Copy Required Configuration Files

Copy the following files from an existing tool package (e.g., aw-tool-sign-ecdsa) to your new package:

1. Configuration files:
   - `tsconfig.lib.json`
   - `tsconfig.json`
   - `package.json` (remember to update the tool name)
   - `jest.config.ts`
   - `eslint.config.js`
   - `.gitignore`

2. Copy the entire `tools` directory

3. Source files:
   - `src/lib/ipfs.ts`

## Implement Tool Logic

### Source Files Structure

Your tool package should have the following structure in the `src` directory:

```
src/
├── index.ts
└── lib/
    ├── ipfs.ts
    ├── lit-action.ts
    ├── policy.ts
    └── tool.ts
```

### Required Modifications

1. `src/lib/lit-action.ts`:
   - Write your custom Lit Action code that will run on Lit nodes
   - This is where your tool's core validation and execution logic goes
   - Examples can be found in the other tool packages

2. `src/lib/policy.ts`:
   - Define your tool's conditions for when execution should be allowed
   - Implement the validation functions for your conditions
   - Examples can be found in the other tool packages

3. `src/lib/tool.ts`:
   - This file needs to be almost completely rewritten for your tool
   - Implement your tool's specific functionality and logic
   - Examples can be found in the other tool packages

4. `src/index.ts`:
   - Edit this file to export your tool
   - Examples can be found in the other tool packages

## Register Your Tool

In the `aw-tool-registry` package:
1. Import your tool in `registry.ts` and call `registerTool` with your tool name and class
2. Add your tool package as a dependency in `package.json` using the workspace syntax
npm package: @lit-protocol/aw-tool-enso
Description: The `aw-tool-enso` package provides utilities for performing onchain actions, such as swap, deposit, lend, borrow, etc. across 180+ protocols.
Latest version: 0.1.0-23

# AW-Tool Enso Documentation

The `aw-tool-enso` package provides utilities for performing onchain actions, such as swap, deposit, lend, borrow, etc. across 180+ protocols.

---

## Files Overview (in src/lib)

### 1. **`ipfs.ts`**

Handles IPFS CIDs for different environments (development, testing, production). Falls back to default CIDs if the build output is not found.

#### Key Features

- **Default CIDs**: Predefined CIDs for `datil-dev`, `datil-test`, and `datil` environments
- **Dynamic CID Loading**: Attempts to load CIDs from `dist/ipfs.json` at runtime
- **Fallback Mechanism**: Uses default CIDs if the file is missing or unreadable

---

### 2. **`lit-action.ts`**

Contains the main logic for executing a Lit Action to perform an Enso route.

#### Key Features

- **PKP Info Retrieval**: Fetches PKP details (token ID, Ethereum address, public key) from the PubkeyRouter contract.
- **Input Validation**: Validates inputs against the policy defined in the PKP Tool Registry.
- **Find the best route between 2 tokens**: Returns the best possible route between two tokens on specified chain.
- **Gas Estimation**: Estimates gas limits and fees for the transaction.
- **Transaction Creation**: Creates and signs the transaction using the PKP public key.
- **Broadcasting**: Sends the signed transaction to the network.

---

### 3. **`policy.ts`**

Defines and validates the Enso policy schema using Zod.

#### Key Features

- **Policy Schema**: Validates policy fields:
  - `type`: Must be 'SignEcdsa'
  - `version`: Policy version string
  - `allowedPrefixes`: Array of allowed message prefixes
- **Encoding/Decoding**: Converts policies to and from ABI-encoded strings using ethers
- **Type Safety**: Uses Zod for schema validation and TypeScript type inference

---

### 4. **`tool.ts`**

Configures the Enso route for different Lit networks.

#### Key Features

- **Parameter Schema**: Validates required parameters:
  - `tokenIn`
  - `tokenOut`
  - `amountIn`
  - `chainId`
- **Network Configuration**: Creates network-specific tools for each supported Lit network
- **Policy Integartion**: Integrates with the `EnsoRoutePolicy`
npm package: @lit-protocol/aw-tool-erc20-transfer
Description: The `aw-tool-erc20-transfer` folder contains utilities for interacting with erc20 transfers using Lit Protocol and Ethereum.
Latest version: 0.1.0-23

# AW-Tool ERC-20 Transfer Documentation

The `aw-tool-erc20-transfer` folder contains utilities for interacting with erc20 transfers using Lit Protocol and Ethereum.

---

## Files Overview (in src/lib)

### 1. **`ipfs.ts`**
Handles IPFS CIDs for different environments (development, testing, production). Falls back to default CIDs if the build output is not found.

#### Key Features:
- **Default CIDs**: Predefined CIDs for `datil-dev`, `datil-test`, and `datil` environments.
- **Dynamic CID Loading**: Attempts to load CIDs from `dist/ipfs.json` at runtime.
- **Fallback Mechanism**: Uses default CIDs if the file is missing or unreadable.

---

### 2. **`lit-action.ts`**
Contains the main logic for executing a Lit Action to perform an ERC20 token transfer.

#### Key Features:
- **PKP Info Retrieval**: Fetches PKP details (token ID, Ethereum address, public key) from the PubkeyRouter contract.
- **Input Validation**: Validates inputs against the policy defined in the PKP Tool Registry.
- **Gas Estimation**: Estimates gas limits and fees for the transaction.
- **Transaction Creation**: Creates and signs the transaction using the PKP public key.
- **Broadcasting**: Sends the signed transaction to the network.

---

### 3. **`policy.ts`**
Defines and validates the ERC20 transfer policy schema using Zod.

#### Key Features:
- **Policy Schema**: Validates policy fields like `erc20Decimals`, `maxAmount`, `allowedTokens`, and `allowedRecipients`.
- **Encoding/Decoding**: Converts policies to and from ABI-encoded strings.
- **Type Safety**: Uses Zod for robust validation and TypeScript for type inference.

---

### 4. **`tool.ts`**
Configures the ERC20 transfer tool for different Lit networks.

#### Key Features:
- **Parameter Validation**: Validates inputs like `pkpEthAddress`, `tokenIn`, `recipientAddress`, and `amountIn`.
- **Network-Specific Tools**: Creates tools for `datil-dev`, `datil-test`, and `datil` environments.
- **Policy Integration**: Integrates with the `ERC20TransferPolicy` for policy handling.
npm package: @lit-protocol/aw-tool-sign-ecdsa
Description: The `aw-tool-sign-ecdsa` package provides functionality for performing ECDSA signing operations using Lit Protocol's PKPs (Programmable Key Pairs). This tool enables secure signing of arbitrary messages or transactions while enforcing policy-based control
Latest version: 0.1.0-23

# AW-Tool Sign ECDSA Documentation

The `aw-tool-sign-ecdsa` package provides functionality for performing ECDSA signing operations using Lit Protocol's PKPs (Programmable Key Pairs). This tool enables secure signing of arbitrary messages or transactions while enforcing policy-based controls.

---

## Files Overview (in src/lib)

### 1. **`ipfs.ts`**
Handles IPFS CIDs for different environments (development, testing, production). Falls back to default CIDs if the build output is not found.

#### Key Features:
- **Default CIDs**: Predefined CIDs for `datil-dev`, `datil-test`, and `datil` environments
- **Dynamic CID Loading**: Attempts to load CIDs from `dist/ipfs.json` at runtime
- **Fallback Mechanism**: Uses default CIDs if the file is missing or unreadable

---

### 2. **`lit-action.ts`**
Contains the main logic for executing a Lit Action to perform ECDSA signing operations.

#### Key Features:
- **PKP Info Retrieval**: Fetches PKP details (token ID, Ethereum address, public key) from the PubkeyRouter contract
- **Delegatee Validation**: Verifies that the session signer is a valid delegatee for the PKP
- **Policy Enforcement**: Validates message prefixes against the allowed prefixes in the policy
- **Message Signing**: Signs messages using the PKP's public key via Lit Actions
- **Error Handling**: Comprehensive error handling and response formatting

---

### 3. **`policy.ts`**
Defines and validates the ECDSA signing policy schema using Zod.

#### Key Features:
- **Policy Schema**: Validates policy fields:
  - `type`: Must be 'SignEcdsa'
  - `version`: Policy version string
  - `allowedPrefixes`: Array of allowed message prefixes
- **Encoding/Decoding**: Converts policies to and from ABI-encoded strings using ethers
- **Type Safety**: Uses Zod for schema validation and TypeScript type inference

---

### 4. **`tool.ts`**
Configures the ECDSA signing tool for different Lit networks.

#### Key Features:
- **Parameter Schema**: Validates required parameters:
  - `pkpEthAddress`: The Ethereum address of the PKP
  - `message`: The message to be signed
- **Network Configuration**: Creates network-specific tools for each supported Lit network
- **Tool Definition**: Implements the `AwTool` interface with:
  - Name and description
  - Parameter validation and descriptions
  - Policy integration with `SignEcdsaPolicy`
npm package: @lit-protocol/aw-tool-sign-eddsa
Description: The `aw-tool-sign-eddsa` package provides functionality for performing EdDSA signing operations using Lit Protocol's PKPs (Programmable Key Pairs). This tool enables secure signing of arbitrary messages while enforcing policy-based controls.
Latest version: 0.1.0-23

# AW-Tool Sign EdDSA Documentation

The `aw-tool-sign-eddsa` package provides functionality for performing EdDSA signing operations using Lit Protocol's PKPs (Programmable Key Pairs). This tool enables secure signing of arbitrary messages while enforcing policy-based controls.

---

## Files Overview (in src/lib)

### 1. **`lit-actions/tool.ts`**
Contains the main logic for executing a Lit Action to perform EdDSA signing operations.

#### Key Features:
- **PKP Info Retrieval**: Fetches PKP details and validates the tool policy
- **Policy Validation**: Checks if a policy exists and executes it if present
- **Message Signing**: Signs messages using EdDSA (Ed25519) via Lit Actions
- **Error Handling**: Comprehensive error handling with detailed responses

---

### 2. **`lit-actions/policy.ts`**
Defines and validates the EdDSA signing policy.

#### Key Features:
- **Policy Validation**: Validates policy parameters including:
  - Allowed message prefixes
  - Message size limits
- **Message Validation**: Ensures messages match allowed patterns
- **Type Safety**: Uses strong typing for policy parameters

---

### 3. **`lit-actions/utils/`**
Collection of utility functions for the signing process:

#### Key Components:
- **`solana-keypair.ts`**: Handles Solana keypair creation and management
- **`sign-message.ts`**: Core message signing functionality
- **`index.ts`**: Exports utility functions

---

## Usage

The tool requires the following parameters:
```typescript
{
  pkpEthAddress: string;    // PKP's Ethereum address
  message: string;         // Message to be signed
  ciphertext: string;      // Encrypted private key data
  dataToEncryptHash: string; // Hash of the encrypted data
}
```

### Policy Parameters

The tool supports policy restrictions on:
- Allowed message prefixes
- Message content validation
- Signing frequency limits

### Response Format

Success Response:
```typescript
{
  status: 'success',
  signature: string,     // Base64-encoded signature
  publicKey: string     // Base58-encoded public key
}
```

Error Response:
```typescript
{
  status: 'error',
  error: string,
  details: {
    message: string,
    type: string,
    stack?: string
  }
}
```

---

## Security Features

1. **Policy Enforcement**: Validates all signing operations against defined policies
2. **Access Control**: Uses Lit Protocol's access control conditions
3. **Secure Key Management**: Handles private keys securely through encryption
4. **Message Validation**: Enforces message format and content restrictions

---

## Dependencies

- `@solana/web3.js`: Solana blockchain interaction
- `@lit-protocol/aw-tool`: Core Agent Wallet tooling
- `tweetnacl`: For Ed25519 signature verification
npm package: @lit-protocol/aw-tool-uniswap-swap
Description: The `aw-tool-uniswap-swap` folder contains utilities for performing Uniswap swaps using Lit Protocol and Ethereum.
Latest version: 0.1.0-23

# AW-Tool Uniswap Swap Documentation

The `aw-tool-uniswap-swap` folder contains utilities for performing Uniswap swaps using Lit Protocol and Ethereum.

---

## Files Overview (in src/lib)

### 1. **`ipfs.ts`**
Handles IPFS CIDs for different environments (development, testing, production). Falls back to default CIDs if the build output is not found.

#### Key Features:
- **Default CIDs**: Predefined CIDs for `datil-dev`, `datil-test`, and `datil` environments.
- **Dynamic CID Loading**: Attempts to load CIDs from `dist/ipfs.json` at runtime.
- **Fallback Mechanism**: Uses default CIDs if the file is missing or unreadable.

---

### 2. **`lit-action.ts`**
Contains the main logic for executing a Lit Action to perform a Uniswap swap.

#### Key Features:
- **PKP Info Retrieval**: Fetches PKP details (token ID, Ethereum address, public key) from the PubkeyRouter contract.
- **Input Validation**: Validates inputs against the policy defined in the PKP Tool Registry.
- **Gas Estimation**: Estimates gas limits and fees for the transaction.
- **Transaction Creation**: Creates and signs the transaction using the PKP public key.
- **Broadcasting**: Sends the signed transaction to the network.

---

### 3. **`policy.ts`**
Defines and validates the Uniswap swap policy schema using Zod.

#### Key Features:
- **Policy Schema**: Validates policy fields like `maxAmount` and `allowedTokens`.
- **Encoding/Decoding**: Converts policies to and from ABI-encoded strings.
- **Type Safety**: Uses Zod for robust validation and TypeScript for type inference.

---

### 4. **`tool.ts`**
Configures the Uniswap swap tool for different Lit networks.

#### Key Features:
- **Parameter Validation**: Validates inputs like `tokenIn`, `tokenOut`, `amountIn`, and `chainId`.
- **Network-Specific Tools**: Creates tools for `datil-dev`, `datil-test`, and `datil` environments.
- **Policy Integration**: Integrates with the `UniswapSwapPolicy` for policy handling.