Skip to content

Feature/mandate core - #4

Open
Akshat-Mishra101 wants to merge 6 commits into
ChaosChain:mainfrom
quillai-network:feature/mandate-core
Open

Feature/mandate core#4
Akshat-Mishra101 wants to merge 6 commits into
ChaosChain:mainfrom
quillai-network:feature/mandate-core

Conversation

@Akshat-Mishra101

Copy link
Copy Markdown

Adds WachAI's Mandate system for Task Verification of ChaosChain Agents

Changes:

  • Added MandateIntegration class in Mandate.ts. This class provides high-level wrappers over the core package.

  • Added functions for mandate utility in ChaosChainSDK.ts

  • Allows enabling mandates from the client sdk.

  • Provides utilities for mandate creation, signature verification and canonicalization

  • Automatically handles signing logic specific to client and server agents.

Usage:

/**
 * Mandate Integration Usage Example
 * Demonstrates creating, signing, and verifying mandates with CAIP-10 identities
 */

import { ChaosChainSDK, NetworkConfig, AgentRole } from '@chaoschain/sdk';
import type { MandateCreateParams } from '@chaoschain/sdk';
import * as dotenv from 'dotenv';

dotenv.config();

async function main() {
  // Initialize SDK with mandate integration enabled (enabled by default)
  const sdk = new ChaosChainSDK({
    agentName: 'ServiceAgent',
    agentDomain: 'service.example.com',
    agentRole: AgentRole.SERVER,
    network: NetworkConfig.BASE_SEPOLIA,
    privateKey: process.env.PRIVATE_KEY,
    enableMandate: true, // Optional: enabled by default
  });


  // 1. Create a mandate with CAIP-10 identities
  console.log('Creating mandate.');
  const clientAddress = '0x1234567890abcdef1234567890abcdef12345678';
  const serverAddress = sdk.getAddress();
  const chainId = 84532; // Base Sepolia

  const mandateParams: MandateCreateParams = {
    client: `eip155:${chainId}:${clientAddress}`,
    server: `eip155:${chainId}:${serverAddress}`,
    intent: 'AI service agreement',
    deadline: new Date(Date.now() + 60 * 60 * 1000).toISOString(), // 1 hour from now
    core: {
      kind: 'serviceAgreement',
      payload: {
        service: 'ai-inference',
        model: 'gpt-4',
        price: '10 USDC',
        duration: '1 hour',
      },
    },
    version: '0.1.0',
  };

  const creationResult = sdk.createMandate(mandateParams);
  
  if (!creationResult.success) {
    throw new Error(`Failed to create mandate: ${creationResult.error}`);
  }

  console.log('Mandate created');
  console.log(`Mandate ID: ${creationResult.mandate?.mandateId}`);
  console.log(`Mandate Hash: ${creationResult.mandateHash}`);


}

main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error('Error:', error);
    process.exit(1);
  });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants