Skip to main content
Wraith has three layers: the SDK (client library), the TEE infrastructure (managed by Wraith), and the blockchains.

System Diagram

System Architecture Developers never run servers, manage keys, or handle chain-specific crypto. They install the SDK, get an API key, and build.

TEE Server Architecture

One NestJS server deployment with a chain connector registry. The core agent engine is chain-agnostic. Chain-specific logic lives behind a pluggable interface. TEE Server Architecture

Module Structure

src/
  main.ts                           <-- NestJS bootstrap
  app.module.ts                     <-- root module
  config/
    configuration.ts                <-- env vars config
  tee/
    tee.service.ts                  <-- DStack key derivation
    tee.controller.ts               <-- attestation endpoints
  agent/
    agent.controller.ts             <-- HTTP API (create, chat, export)
    agent.service.ts                <-- agent lifecycle, chat orchestration
    tools/
      tool-definitions.ts           <-- AI function declarations + system prompt
      agent-tools.service.ts        <-- tool execution
  storage/
    database.service.ts             <-- TypeORM repository access
    entities/                       <-- agent, conversation, invoice, etc.
  notifications/
    notification.service.ts         <-- create, list, mark read
  scheduler/
    scheduler.service.ts            <-- cron-based scheduled payments
  health/
    health.controller.ts            <-- /health endpoint

Agent Lifecycle

Creation

1. Client sends POST /agent/create { name, wallet, signature, chain }
2. Server verifies wallet signature (EIP-191 for EVM, ed25519 for Stellar)
3. Generate UUID for agent
4. Derive keys inside TEE: seed -> chain connector -> { address, stealthKeys, metaAddress }
5. Fund agent wallet via chain faucet (testnet)
6. Store agent in DB (id, name, chain, ownerWallet, address, metaAddress)
7. Register .wraith name on-chain
8. Return { id, name, chain, address, metaAddress }

Chat Orchestration

The chat method runs a multi-turn tool-calling loop: Chat Orchestration The AI can call multiple tools in one response. A cap (10 iterations) prevents infinite loops.

Tool Execution

Each tool call routes to the appropriate chain connector:
import { Chain } from "@wraith-protocol/sdk";

// The agent service resolves the connector automatically
async executeTool(toolName: string, args: Record<string, unknown>, agent: Agent) {
  const connector = this.chainRegistry.get(agent.chain);
  const stealthKeys = await this.tee.deriveStealthKeys(agent.id, agent.chain);

  switch (toolName) {
    case "send_payment":
      return connector.sendPayment({
        senderAddress: agent.address,
        senderStealthKeys: stealthKeys,
        recipientMetaAddress: args.recipient as string,
        amount: args.amount as string,
      });
    case "scan_payments":
      return connector.scanPayments(stealthKeys);
    case "get_balance":
      return connector.getBalance(agent.address);
    // ... 13 more tools
  }
}

Database Schema

agents

ColumnTypeDescription
idUUID (PK)Agent identifier
nameVARCHAR.wraith name (unique)
chainVARCHARTarget chain identifier
ownerWalletVARCHAROwner’s wallet address
addressVARCHARAgent’s on-chain address
metaAddressTEXTStealth meta-address
createdAtTIMESTAMPCreation time

conversations

ColumnTypeDescription
idUUID (PK)Conversation identifier
agentIdUUID (FK)References agents.id
titleVARCHARConversation title
createdAtTIMESTAMPCreated
updatedAtTIMESTAMPLast updated

messages

ColumnTypeDescription
idSERIAL (PK)Message identifier
conversationIdUUID (FK)References conversations.id
roleVARCHARuser, agent, tool, or system
textTEXTMessage content
createdAtTIMESTAMPCreated

invoices

ColumnTypeDescription
idUUID (PK)Invoice identifier
agentIdUUID (FK)References agents.id
amountVARCHARPayment amount
assetVARCHARAsset symbol
memoTEXTInvoice description
statusVARCHARpending or paid
txHashVARCHARTransaction hash (null until paid)
createdAtTIMESTAMPCreated

notifications

ColumnTypeDescription
idSERIAL (PK)Notification identifier
agentIdUUID (FK)References agents.id
typeVARCHARNotification type
titleVARCHARTitle
bodyTEXTBody
readBOOLEANRead status
createdAtTIMESTAMPCreated

scheduled_payments

ColumnTypeDescription
idUUID (PK)Schedule identifier
agentIdUUID (FK)References agents.id
recipientVARCHAR.wraith name or meta-address
amountVARCHARPayment amount
assetVARCHARAsset symbol
intervalVARCHARdaily, weekly, or monthly
statusVARCHARactive, paused, or cancelled
lastRunTIMESTAMPLast execution (null if never)
nextRunTIMESTAMPNext scheduled execution
createdAtTIMESTAMPCreated

Platform Model

Wraith operates as a managed service, similar to Privy or Turnkey.

What Wraith Manages

  • TEE infrastructure (Phala deployment)
  • Key derivation and security
  • Chain connectors and RPC endpoints
  • Database and session storage
  • Name registration and gas sponsorship
  • Payment scanning and notifications

AI Model Options

OptionDescription
DefaultWraith’s hosted Gemini model (included in API usage)
Bring Your OwnPass your own OpenAI/Claude/Gemini API key
import { Wraith } from "@wraith-protocol/sdk";

// Default — uses Wraith's Gemini
const wraith = new Wraith({ apiKey: "wraith_..." });

// Bring your own model
const wraith = new Wraith({
  apiKey: "wraith_...",
  ai: { provider: "openai", apiKey: "sk-..." },
});