npm package: @gvnrdao/dh-lit-ops
Description: Diamond Hands Protocol - LIT Protocol Operations Package
Author: Diamond Hands Protocol
Latest version: 0.0.203

# LIT-OPS Package

**Diamond Hands Protocol - LIT Protocol Operations**

Decoupled LIT Protocol operations supporting both standalone and service modes.

## 🎯 Purpose

This package provides a clean separation of LIT Protocol operations from the main SDK, enabling:

1. **Standalone Mode**: Users pay LIT tokens directly with their private keys
2. **Service Mode**: Backend service handles LIT token costs centrally

## 🏗️ Architecture

```
lit-ops/
├── src/
│   ├── client/          # LIT client management
│   ├── auth/            # SessionSigs & authentication
│   ├── pkp/             # PKP operations (mint, validate, burn)
│   ├── actions/         # LIT Action execution
│   ├── interfaces/      # Type definitions
│   └── index.ts         # Main exports
├── package.json
└── README.md
```

## 🚀 Usage

### Basic Setup

```typescript
import { LitOps } from "@diamond-hands/lit-ops";

// Standalone mode (user pays)
const wallet = ethers.Wallet.createRandom();
const litOps = new LitOps({
  mode: "standalone",
  network: "datil-test",
  signer: wallet,
  debug: true,
});

// Service mode (backend pays) - Future
const litOps = new LitOps({
  mode: "service",
  signer: wallet,
  network: "datil-test",
  serviceEndpoint: "https://api.diamond-hands.com",
  debug: false,
});
```

### PKP Operations

```typescript
// Create PKP
const pkpResult = await litOps.createPKP(signer, litActionCid);

// Validate PKP
const validation = await litOps.validatePKP(pkpId, signer);

// Burn PKP
const burnResult = await litOps.burnPKP(pkpId, signer, "liquidation");
```

### LIT Action Execution

```typescript
// Execute from CID (deployed LIT Action)
const result = await litOps.executeActionFromCID(
  "bafkreidxcjah2ogybxm5do5yvvy6z6klr4zca6vwvcyni4qmmtj6loef4q",
  pkpPublicKey,
  { message: "test" },
  signer
);

// Execute from code
const result = await litOps.executeActionFromCode(
  litActionCode,
  pkpPublicKey,
  { message: "test" },
  signer
);
```

## 🔧 Configuration

```typescript
interface LitOpsConfig {
  mode: "standalone" | "service";
  network: "datil-test" | "datil";
  debug?: boolean;
  serviceEndpoint?: string;
  domain?: string;
  sessionExpirationMinutes?: number;
}
```

## 📦 Integration

### In SDK

```typescript
// sdk/src/modules/PKPManager.ts
import { LitOps } from "../../lit-ops";

export class PKPManager {
  private litOps: LitOps;

  constructor(config: SDKConfig) {
    this.litOps = new LitOps({
      mode: config.litMode || "standalone",
      network: config.litNetwork,
      signer: config.signer, // Add signer to SDK config
      debug: config.debug,
    });
  }
}
```

### In Backend Service

```typescript
// backend-service/routes/lit.ts
import { LitOps } from "../lit-ops";

const serviceSigner = ethers.Wallet.fromMnemonic(process.env.SERVICE_MNEMONIC);
const litOps = new LitOps({
  mode: "service",
  network: "datil-test",
  signer: serviceSigner,
});

app.post("/api/lit/create-pkp", async (req, res) => {
  const result = await litOps.createPKP();
  res.json(result);
});
```

## 🔄 Operation Modes

### Standalone Mode

- User provides their own signer
- User pays LIT token costs
- Direct LIT Protocol interaction
- Full decentralization

### Service Mode (Future)

- Backend service handles LIT operations
- Centralized LIT token payment
- API-based interaction
- Simplified user experience

## 🧪 Development

```bash
# Install dependencies
npm install

# Build package
npm run build

# Run tests
npm test

# Watch mode
npm run dev
```

## 📝 Status

- ✅ **Standalone Mode**: Implemented
- ✅ **PKP Operations**: Mock implementation ready
- ✅ **LIT Action Execution**: Real execution from CID
- ✅ **SessionSigs Authentication**: Working
- ⏳ **Service Mode**: Future implementation
- ⏳ **Real PKP Minting**: Will replace mock implementation

## 🔗 Dependencies

- `@lit-protocol/lit-node-client`
- `@lit-protocol/auth-helpers`
- `@lit-protocol/constants`
- `ethers`
- `axios`

## 🎯 Benefits

1. **Separation of Concerns**: LIT operations isolated from business logic
2. **Reusability**: Same code in SDK and backend service
3. **Cost Flexibility**: Support both payment models
4. **Maintainability**: Single place for LIT Protocol interactions
5. **Testing**: Isolated testing of LIT operations