|
| 1 | +# LitChainClient |
| 2 | + |
| 3 | +A TypeScript client for interacting with Lit Protocol's blockchain contracts. This client provides a type-safe interface for minting and managing Programmable Key Pairs (PKPs). |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +LitChainClient abstracts blockchain interactions with Lit Protocol's smart contracts, offering both raw contract APIs and higher-level convenience functions. |
| 8 | + |
| 9 | +## Available APIs |
| 10 | + |
| 11 | +The client provides three main API objects: |
| 12 | + |
| 13 | +### LitChainClientAPI (High-Level APIs) |
| 14 | + |
| 15 | +**PKP Management:** |
| 16 | + |
| 17 | +- `mintPKP` - Simplified interface for minting a new PKP |
| 18 | + |
| 19 | +**Permissions Management:** |
| 20 | + |
| 21 | +- `PKPPermissionsManager` - Class for managing permissions for PKPs |
| 22 | + - Provides methods for managing permissions using PKP identifiers (tokenId, pubkey, or address) |
| 23 | + |
| 24 | +### LitChainClientRawAPI (Low-Level APIs / Direct Contract calls) |
| 25 | + |
| 26 | +**PKP (Programmable Key Pair) Operations:** |
| 27 | + |
| 28 | +- `pkp.read.tokenOfOwnerByIndex` - Get PKP token by owner and index |
| 29 | +- `pkp.write.mintNextAndAddAuthMethods` - Mint a new PKP and add authentication methods |
| 30 | +- `pkp.write.claimAndMintNextAndAddAuthMethodsWithTypes` - Claim, mint a PKP, and add auth methods with types |
| 31 | + |
| 32 | +**Permission Operations:** |
| 33 | + |
| 34 | +- `permission.read.getPermittedAddresses` - Get addresses with permissions for a PKP |
| 35 | +- `permission.read.getPermittedActions` - Get permitted actions for a PKP |
| 36 | +- `permission.read.isPermittedAddress` - Check if an address has permission |
| 37 | +- `permission.read.isPermittedAction` - Check if an action is permitted |
| 38 | +- `permission.write.addPermittedAction` - Add a permitted action |
| 39 | +- `permission.write.removePermittedAction` - Remove a permitted action |
| 40 | +- `permission.write.addPermittedAddress` - Add a permitted address |
| 41 | +- `permission.write.removePermittedAddress` - Remove a permitted address |
| 42 | + |
| 43 | +### LitChainClientUtils |
| 44 | + |
| 45 | +**Utility Functions:** |
| 46 | + |
| 47 | +- `createLitContracts` - Create contract instances for interacting with Lit Protocol |
| 48 | + |
| 49 | +## Usage Examples |
| 50 | + |
| 51 | +### Using High-Level API |
| 52 | + |
| 53 | +```typescript |
| 54 | +import { LitChainClientAPI } from "../LitChainClient/apis"; |
| 55 | + |
| 56 | +// Minting a PKP with simplified API |
| 57 | +const result = await LitChainClientAPI.mintPKP( |
| 58 | + { |
| 59 | + authMethod: { |
| 60 | + authMethodType: 1, |
| 61 | + id: "example-id", |
| 62 | + pubkey: "0x...", // webAuthn only |
| 63 | + }, |
| 64 | + }, |
| 65 | + networkContext |
| 66 | +); |
| 67 | + |
| 68 | +// Using PKP Permissions Manager |
| 69 | +const permissionsManager = new LitChainClientAPI.PKPPermissionsManager( |
| 70 | + networkContext |
| 71 | +); |
| 72 | +await permissionsManager.addPermittedAction(tokenId, actionId); |
| 73 | +``` |
| 74 | + |
| 75 | +### Using Raw API |
| 76 | + |
| 77 | +```typescript |
| 78 | +import { LitChainClientRawAPI } from "../LitChainClient/apis"; |
| 79 | + |
| 80 | +// Using the raw API |
| 81 | +const result = await LitChainClientRawAPI.pkp.write.mintNextAndAddAuthMethods( |
| 82 | + { |
| 83 | + keyType: 2, |
| 84 | + permittedAuthMethodTypes: [1], |
| 85 | + permittedAuthMethodIds: ["example-id"], |
| 86 | + permittedAuthMethodPubkeys: ["0x..."], |
| 87 | + permittedAuthMethodScopes: [[1, 2, 3]], |
| 88 | + addPkpEthAddressAsPermittedAddress: true, |
| 89 | + sendPkpToItself: false, |
| 90 | + }, |
| 91 | + networkContext |
| 92 | +); |
| 93 | + |
| 94 | +// Using permission APIs |
| 95 | +const isPermitted = |
| 96 | + await LitChainClientRawAPI.permission.read.isPermittedAddress( |
| 97 | + tokenId, |
| 98 | + address |
| 99 | + ); |
| 100 | +``` |
| 101 | + |
| 102 | +### Using Utilities |
| 103 | + |
| 104 | +```typescript |
| 105 | +import { LitChainClientUtils } from "../LitChainClient/apis"; |
| 106 | + |
| 107 | +// Create contract instances |
| 108 | +const contracts = LitChainClientUtils.createLitContracts(networkContext); |
| 109 | +``` |
| 110 | + |
| 111 | +## Configuration |
| 112 | + |
| 113 | +The client is pre-configured for the Chronicle Yellowstone testnet. Configuration options are in `_config.ts`. |
| 114 | + |
| 115 | +## API Structure |
| 116 | + |
| 117 | +- **Raw Contract APIs** (`apis/rawContractApis/`): |
| 118 | + |
| 119 | + - `pkp/` - PKP contract functions |
| 120 | + - `read/` - Read-only functions |
| 121 | + - `write/` - State-changing functions |
| 122 | + - `permission/` - Permission functions |
| 123 | + - `read/` - Permission queries |
| 124 | + - `write/` - Permission modifications |
| 125 | + |
| 126 | +- **High-Level APIs** (`apis/highLevelApis/`): |
| 127 | + |
| 128 | + - `mintPKP/` - Simplified PKP minting functions |
| 129 | + - `PKPPermissionsManager/` - Enhanced permission management |
| 130 | + |
| 131 | +- **Utilities** (`apis/utils/`): |
| 132 | + - Helper functions for contract interactions |
0 commit comments