@lit-protocol/aw-signer
The signer package is responsible for PKP (Programmable Key Pair) management, signing operations, and policy enforcement in the Lit Protocol Agent Wallet system. It provides two main roles: Admin and Delegatee.
Installation
pnpm add @lit-protocol/aw-signer
Core Features
- PKP Management: Mint and manage PKPs
- Policy Enforcement: Define and enforce tool execution policies
- Delegatee Management: Add and remove delegatees
- Tool Execution: Execute tools within policy constraints
- Network Support: Support for multiple Lit networks (datil-dev, datil-test, datil)
Execution Flow

Usage
As an Admin
The Admin role is responsible for managing PKPs, delegatees, and policies:
import { Admin } from '@lit-protocol/aw-signer';
import { AUTH_METHOD_SCOPE } from '@lit-protocol/constants';
const admin = await Admin.create(
{
type: 'eoa',
privateKey: 'your-private-key'
},
{
litNetwork: 'datil-dev'
}
);
const pkpTokenId = admin.pkpInfo.tokenId;
await admin.addDelegatee('delegatee-address');
await admin.permitTool({
ipfsCid: 'tool-ipfs-cid',
signingScopes: [AUTH_METHOD_SCOPE.SignAnything]
});
await admin.setToolPolicy(
pkpTokenId,
'tool-ipfs-cid',
policyData,
'v1'
);
const {
toolsWithPolicies,
toolsWithoutPolicies,
toolsUnknownWithPolicies,
toolsUnknownWithoutPolicies
} = await admin.getRegisteredToolsForPkp();
As a Delegatee
The Delegatee role executes tools within the constraints set by the Admin:
import { Delegatee } from '@lit-protocol/aw-signer';
const delegatee = await Delegatee.create(
'your-private-key',
{
litNetwork: 'datil-dev'
}
);
const pkps = await delegatee.getDelegatedPkps();
const pkpTokenId = pkps[0].tokenId;
const {
toolsWithPolicies,
toolsWithoutPolicies,
toolsUnknownWithPolicies,
toolsUnknownWithoutPolicies
} = await delegatee.getRegisteredToolsForPkp(pkpTokenId);
const selectedTool = toolsWithPolicies[0];
if (selectedTool) {
const policy = await delegatee.getToolPolicy(pkpTokenId, selectedTool.ipfsCid);
const decodedPolicy = selectedTool.policy.decode(policy.policy);
console.log('Tool Policy:', decodedPolicy);
}
await delegatee.executeTool({
ipfsId: selectedTool.ipfsCid,
jsParams: {
params: {
},
}
});
Intent-Based Tool Selection
The Delegatee can also select tools based on natural language intents:
const { tool, params } = await delegatee.getToolViaIntent(
pkpTokenId,
'Transfer 1 ETH to 0x123...',
intentMatcher
);
const policy = await delegatee.getToolPolicy(pkpTokenId, tool.ipfsCid);
if (policy) {
const decodedPolicy = tool.policy.decode(policy.policy);
console.log('Tool Policy:', decodedPolicy);
}
await delegatee.executeTool({
ipfsId: tool.ipfsCid,
jsParams: {
params,
}
});
Configuration
Admin Configuration
interface AdminConfig {
type: 'eoa';
privateKey?: string;
}
interface AgentConfig {
litNetwork?: LitNetwork;
debug?: boolean;
}
const admin = await Admin.create(
{ type: 'eoa', privateKey: 'your-private-key' },
{ litNetwork: 'datil-dev', debug: false }
);
Delegatee Configuration
const delegatee = await Delegatee.create(
'your-private-key',
{ litNetwork: 'datil-dev', debug: false }
);
Tool Policies
Policies define constraints for tool execution:
interface ERC20TransferPolicy {
maxAmount: string;
allowedTokens: string[];
allowedRecipients: string[];
}
await admin.setToolPolicy(
pkpTokenId,
toolIpfsCid,
{
maxAmount: '1000000000000000000',
allowedTokens: ['0x...'],
allowedRecipients: ['0x...']
},
'v1'
);
Error Handling
The package provides specific error types for better error handling:
import { AwSignerError, AwSignerErrorType } from '@lit-protocol/aw-signer';
try {
await admin.permitTool({ ipfsCid });
} catch (error) {
if (error instanceof AwSignerError) {
switch (error.type) {
case AwSignerErrorType.ADMIN_PERMIT_TOOL_FAILED:
console.error('Failed to permit tool:', error.message);
break;
case AwSignerErrorType.ADMIN_NOT_INITIALIZED:
console.error('Admin not initialized:', error.message);
break;
case AwSignerErrorType.ADMIN_MISSING_PRIVATE_KEY:
console.error('Admin private key missing:', error.message);
break;
case AwSignerErrorType.ADMIN_MISSING_LIT_NETWORK:
console.error('Lit network not specified:', error.message);
break;
case AwSignerErrorType.DELEGATEE_MISSING_PRIVATE_KEY:
console.error('Delegatee private key missing:', error.message);
break;
case AwSignerErrorType.DELEGATEE_MISSING_LIT_NETWORK:
console.error('Lit network not specified:', error.message);
break;
}
}
}
PKP Information
PKPs (Programmable Key Pairs) are represented as:
interface PkpInfo {
tokenId: string;
publicKey: string;
address: string;
}
Network Configuration
The package supports three Lit networks:
datil-dev: Development network
datil-test: Testing network
datil: Production network
Each network has its own configuration for contract addresses and RPC URLs.
Dependencies
This package depends on:
@lit-protocol/aw-tool: Core tool interfaces
@lit-protocol/aw-tool-registry: Tool management
@lit-protocol/auth-helpers: Authentication utilities
@lit-protocol/contracts-sdk: Smart contract interactions
@lit-protocol/lit-node-client-nodejs: Node.js Lit client
Credential Store
The Delegatee class implements a credential store for managing tool-specific credentials:
const { foundCredentials, missingCredentials } = await delegatee.getCredentials<T>(
['credential1', 'credential2']
);
await delegatee.setCredentials<T>({
credential1: 'value1',
credential2: 'value2'
});
The credential store is useful for tools that require persistent configuration or authentication details.
Need Help?