Skip to content

Commit b4e9f05

Browse files
committed
feat(WIP->network&LitChainClient): copy/paste from https://github.com/LIT-Protocol/pkp-auth-service/tree/feat/naga
1 parent 235535d commit b4e9f05

File tree

70 files changed

+4883
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+4883
-0
lines changed
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import {
2+
NagaLocalDevelopNetworkContext,
3+
nagaLocalDevelopNetworkContext,
4+
} from "../../local-develop/networkContext";
5+
6+
/**
7+
* Due to the usage of arbitrum stylus contracts,
8+
* the gas limit is increased by 10% to avoid reverts due to out of gas errors
9+
*/
10+
const GAS_LIMIT_INCREASE_PERCENTAGE = 10;
11+
export const GAS_LIMIT_ADJUSTMENT = BigInt(100 + GAS_LIMIT_INCREASE_PERCENTAGE);
12+
13+
export const LIT_CONTRACT_NAME = {
14+
PubkeyRouter: "PubkeyRouter",
15+
PKPNFT: "PKPNFT",
16+
PKPHelper: "PKPHelper",
17+
PKPPermissions: "PKPPermissions",
18+
Staking: "Staking",
19+
} as const;
20+
21+
export const networkContext = nagaLocalDevelopNetworkContext; // we shall change this later
22+
export type NetworkContext = NagaLocalDevelopNetworkContext;

0 commit comments

Comments
 (0)