@gvnrdao/dh-lit-ops
v0.0.193
Published
Diamond Hands Protocol - LIT Protocol Operations Package
Readme
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:
- Standalone Mode: Users pay LIT tokens directly with their private keys
- 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
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
// 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
// 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
interface LitOpsConfig {
mode: "standalone" | "service";
network: "datil-test" | "datil";
debug?: boolean;
serviceEndpoint?: string;
domain?: string;
sessionExpirationMinutes?: number;
}📦 Integration
In SDK
// 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
// 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
# 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/constantsethersaxios
🎯 Benefits
- Separation of Concerns: LIT operations isolated from business logic
- Reusability: Same code in SDK and backend service
- Cost Flexibility: Support both payment models
- Maintainability: Single place for LIT Protocol interactions
- Testing: Isolated testing of LIT operations
