SDK Reference

TypeScript SDK for interacting with IRSB contracts. Two packages:

bash
npm install irsb        # Core SDK
npm install irsb-x402   # x402 HTTP payment integration

IRSBClient

Main entry point. Handles connection, contract interaction, and receipt lifecycle.

typescript
import { IRSBClient } from 'irsb';

const client = new IRSBClient({
  chainId: 11155111,
  rpcUrl: 'https://rpc.sepolia.org',
  // Optional: override default contract addresses
  contracts: {
    solverRegistry: '0x...',
    intentReceiptHub: '0x...',
    disputeModule: '0x...',
  },
});

Receipt Building

buildReceiptV1()

Single attestation receipt. Solver signature only.

typescript
import { buildReceiptV1 } from 'irsb';

const receipt = buildReceiptV1({
  intentHash: '0x...',     // keccak256 of intent data
  solverId: '0x...',       // Registered solver identifier
  constraintsHash: '0x...', // Hash of intent constraints
  routeHash: '0x...',      // Hash of execution route
  outcomeHash: '0x...',    // Hash of execution outcome
  evidenceHash: '0x...',   // Hash of evidence bundle
});

buildReceiptV2()

Dual attestation receipt with privacy support. Both solver and client sign via EIP-712.

typescript
import { buildReceiptV2 } from 'irsb';

const receipt = buildReceiptV2({
  // V1 fields
  intentHash: '0x...',
  solverId: '0x...',
  constraintsHash: '0x...',
  routeHash: '0x...',
  outcomeHash: '0x...',
  evidenceHash: '0x...',
  // V2 additions
  metadataCommitment: '0x...',  // Hash of metadata (not plaintext)
  ciphertextPointer: 'ipfs://...', // IPFS CID or content digest
  privacyLevel: 'SEMI_PUBLIC',  // PUBLIC | SEMI_PUBLIC | PRIVATE
  escrowId: '0x...',            // Optional escrow link
});

Posting Receipts

typescript
// Post V1 receipt
const receiptId = await client.postReceipt(receipt, signer);

// Post V2 receipt (requires both solver and client signatures)
const receiptId = await client.postReceiptV2(receipt, solverSigner, clientSigner);

// Verify a receipt
const isValid = await client.verifyReceipt(receiptId);

// Get receipt by ID
const receipt = await client.getReceipt(receiptId);

Bond Management

typescript
// Register solver
const solverId = await client.registerSolver(metadataURI, signer);

// Deposit bond (minimum 0.1 ETH)
await client.depositBond(solverId, ethers.parseEther('0.5'), signer);

// Request withdrawal (starts 7-day cooldown)
await client.requestWithdrawal(solverId, amount, signer);

// Execute withdrawal (after cooldown)
await client.executeWithdrawal(solverId, signer);

// Query bond balance
const balance = await client.getBondBalance(solverId);

Dispute Operations

typescript
// Open dispute (requires evidence and bond)
const disputeId = await client.openDispute({
  receiptId: '0x...',
  evidenceHash: '0x...',
  reasonCode: 'TIMEOUT', // TIMEOUT | WRONG_AMOUNT | CONSTRAINT_VIOLATION | OTHER
}, signer);

// Submit additional evidence
await client.submitEvidence(disputeId, evidenceHash, signer);

// Resolve deterministic dispute
await client.resolveDeterministic(disputeId, signer);

// Post counter-bond (optimistic disputes)
await client.postCounterBond(disputeId, amount, signer);

Reputation Queries

typescript
// Get IntentScore (0-10000 basis points)
const score = await client.getIntentScore(solverId);
// Returns: { score: 8500, components: { successRate, disputeWinRate, ... } }

// Get solver stats
const stats = await client.getSolverStats(solverId);
// Returns: { totalTasks, successfulTasks, disputes, jailCount, bondBalance }

Package Links