Agent Wallet SDK

Give your AI agent a self-custodial wallet with on-chain spend limits. The SDK handles x402 payments automatically.

Machine-readable version: /llms.txt

Overview

LumenBro Agents gives AI agents self-custodial wallets on Stellar. Your agent calls any x402-enabled API, the SDK detects the 402, signs a payment from the smart wallet, and retries. No API keys, no custodians, no seed phrases.

  1. Create a wallet at agents.lumenbro.com — deploys a Stellar smart account (C-address) secured by your passkey
  2. Register an agent signer — Ed25519 keypair or P-256 key, each gated by a daily spend policy
  3. Fund with USDC — send USDC to your wallet's C-address
  4. Use the SDKnpm install lumenjoule-sdk, call client.chat(), done

Agent keys only sign auth entries (not TX envelopes). The facilitator pays gas and submits the transaction. Agent keys never need XLM funding for x402 payments.

Smart Wallet Architecture

Each wallet is a Stellar smart account (C-address) that acts as a shared vault. Multiple agent signers draw from the same balance, each with independent daily limits.

Smart Wallet ArchitectureOne vault, multiple agents, independent spend limitsOwner PasskeySecp256r1 (WebAuthn)Full control: pause, revoke, addadmin authSmart Wallet (C-address)Stellar Smart Account · On-Chain ContractPooled BalanceUSDCAuthorization Gate__check_authEvery transfer validated: signer key + spend policy1Agent Signer (Ed25519)Secret key: S...XXXXXPlatform: Any (Linux, macOS, Windows)Starter Policy: $50/day2Agent Signer (P-256)Encrypted file: ~/.lumenjoule/Platform: Any (SoftP256Signer)Production: $500/day3Agent Signer (SE)Secure Enclave (hardware)Platform: macOS (KeypoSigner)Enterprise: $2,000/daysign authsign authsign authx402 Payment FlowAI Agentclient.chat()x402 APIReturns 402 +payment requirementsFacilitatorVerify + pay gasStellar Network~5s finalityWalletcheckauthrequestpaysubmitresponse (after settlement)Key InsightAgent keys never need XLM. Facilitatorpays gas. Spend policy caps damage on-chain.Vault (holds funds)Agent SignerSpend PolicyOwner (passkey)Contract: github.com/lumenbro/stellar-smart-account

C-address (Vault)

The smart account that holds all funds. Every transfer is gated by __check_auth which validates the signer's key + spend policy before allowing the transaction.

Agent Signers

Delegated signing keys registered on the wallet. Each signer has its own key type (Ed25519 or Secp256r1) and is bound to a spend policy contract. Like corporate cards — one funding account, multiple cards with individual limits.

Spend Policies

On-chain ExternalValidatorPolicy contracts that enforce daily USDC limits. Checked on every transfer() and approve(). Even if a key is compromised, damage is capped to one day's limit.

Smart account contract source: github.com/lumenbro/stellar-smart-account · Spend policy source: github.com/lumenbro/soroban-policies

Quick Start

1. Install

npm install lumenjoule-sdk

Create a wallet at agents.lumenbro.com if you haven't already.

2. Configure

import { SmartWalletClient } from "lumenjoule-sdk";

const client = new SmartWalletClient({
  agentSecretKey: process.env.AGENT_SECRET,  // S... key from portal
  walletAddress: "CXXX...",                   // your wallet C-address
  network: "mainnet",
});

3. Use

const response = await client.chat({
  model: "deepseek-ai/DeepSeek-V3",
  messages: [{ role: "user", content: "Hello!" }],
});

console.log(response.choices[0].message.content);

The SDK handles the x402 payment automatically: request → 402 → sign payment → retry → response.

Signer Types

Three signer implementations, same smart wallet. Pick based on your platform and security requirements.

SignerPlatformKey StorageBest For
Ed25519AllSecret key string (S...)Simplest setup, any platform
SoftP256SignerAllEncrypted file (~/.lumenjoule/)Linux VPS, cloud servers, dev
KeypoSignermacOSSecure Enclave (hardware)Maximum security, Mac Mini

Ed25519 — Stellar Keypair (Any Platform)

The simplest option. Generate a Stellar keypair, register the public key (G-address) as an agent signer in the portal, and pass the secret key to the SDK.

import { SmartWalletClient } from "lumenjoule-sdk";

const client = new SmartWalletClient({
  agentSecretKey: process.env.AGENT_SECRET,   // S... secret key
  walletAddress: "CXXX...",                    // wallet C-address
  network: "mainnet",
});

SoftP256Signer — Software P-256 (Any Platform)

Encrypted P-256 key stored on disk. Same signing format as Secure Enclave — production-ready on Linux VPS, Windows, macOS. AES-256-GCM encryption with PBKDF2-derived key.

import { SmartWalletClient, SoftP256Signer } from "lumenjoule-sdk";

// First time: generate and save encrypted key
const signer = await SoftP256Signer.generate("my-password");
// Saved to: ~/.lumenjoule/agent-key.enc
// Prints: public key (paste into portal when registering Secp256r1 signer)

// After: load existing key
const signer = await SoftP256Signer.load("my-password");

const client = new SmartWalletClient({
  signer,
  walletAddress: "CXXX...",
  network: "mainnet",
});

KeypoSigner — Secure Enclave (macOS)

Hardware-bound P-256 key via keypo-signer. The private key lives in the Secure Enclave and can never be extracted. Install: brew install keypo-signer.

import { SmartWalletClient, KeypoSigner } from "lumenjoule-sdk";

const signer = new KeypoSigner({
  keyLabel: "my-agent-key",
  publicKey: Buffer.from("BASE64_PUBLIC_KEY", "base64"),
});

const client = new SmartWalletClient({
  signer,
  walletAddress: "CXXX...",
  network: "mainnet",
});

Pay Any x402 Endpoint

The wallet isn't limited to one service. payAndFetch() works with any x402-compatible endpoint on any server. chat() is a convenience wrapper for OpenAI-compatible inference APIs.

// AI inference (OpenAI-compatible)
const response = await client.chat({
  model: "deepseek-ai/DeepSeek-V3",
  messages: [{ role: "user", content: "Analyze this data" }],
});

// Any x402 endpoint
const data = await client.payAndFetch("https://some-api.com/v1/data", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ query: "..." }),
});

// Direct USDC transfer (non-x402, agent pays gas)
const txHash = await client.transfer(
  USDC_CONTRACT,
  recipientAddress,
  1_000_000n,  // 0.1 USDC (7 decimals)
);

Spend Policies

Every agent signer is gated by an on-chain ExternalValidatorPolicy contract. The policy is enforced during __check_auth on every transfer and approval. Even if a key is compromised, damage is capped.

Starter
$50
per day
CBRGH27ZFVFDIHYKC4K3CSLKXHQSR5CFG2PLPZ2M37NH4PYBOBTTQAEC
Production
$500
per day
CCRIFGLMG3PT7R3V2IFSRNDNKR2Y2DLJAI5KXYBKNJPFCL2QC4MDIZNJ
Enterprise
$2,000
per day
CCSPAXNEVBNA5QAEU2YEUTU56O5KOZM4C2O7ONQ6GFPSHEWV5OJJS5H2

Query Budget

// Requires policyAddress in constructor
const client = new SmartWalletClient({
  agentSecretKey: process.env.AGENT_SECRET,
  walletAddress: "CXXX...",
  policyAddress: "CBRGH27Z...",  // Starter tier
});

const budget = await client.budgetStatus();
// { dailyLimitUsdc: 50, spentTodayUsdc: 3.20, remainingUsdc: 46.80 }

// Individual queries
const limit     = await client.dailyLimit();    // 500_000_000n (stroops)
const spent     = await client.spentToday();    // 32_000_000n
const remaining = await client.remaining();     // 468_000_000n

x402 Payment Protocol

The SDK implements the x402 payment protocol for Stellar. Compatible with both the LumenBro facilitator and the OpenZeppelin Stellar facilitator.

1.Agent sends request to x402-enabled API
2.Server returns 402 Payment Required with price, asset, and destination
3.SDK builds USDC transfer from smart wallet + signs auth with agent key
4.SDK retries with PAYMENT-SIGNATURE header (v2) + X-Payment (v1 compat)
5.Facilitator verifies signature, sponsors gas, submits on-chain (~5s finality)
6.Server confirms settlement, returns the response

The facilitator is a neutral relay — it doesn't need to understand smart wallets or signer types. It receives pre-signed auth entries, rebuilds the TX, and submits. The Soroban runtime calls __check_auth on your wallet contract transparently.

API Reference

SmartWalletClient Constructor

OptionTypeDefaultDescription
walletAddressstringrequiredSmart wallet C-address
agentSecretKeystringEd25519 secret key (S...)
signerAgentSignerPluggable signer (alternative to agentSecretKey)
network"testnet" | "mainnet""mainnet"Stellar network
computeUrlstringcompute.lumenbro.comDefault x402 endpoint for chat()
rpcUrlstringautoCustom Soroban RPC URL
policyAddressstringSpend policy contract (for budget queries)
preferredAssetstringUSDCPayment asset contract

Methods

MethodDescription
chat(request)OpenAI-compatible chat completion with automatic x402 payment
payAndFetch(url, init?)Pay any x402 endpoint and return the response
transfer(token, to, amount)Direct token transfer (Ed25519 only, agent pays gas)
usdcBalance()USDC balance of the wallet (7-decimal stroops)
balance(token?)Any token balance (defaults to LumenJoule)
gasBalance()XLM balance of the wallet
budgetStatus()Daily limit, spent today, remaining (requires policyAddress)
dailyLimit()Policy daily limit in stroops
spentToday()Amount spent today in stroops
remaining()Remaining daily budget in stroops

x402 Protocol Helpers

import { parsePaymentRequirements, performX402Dance } from "lumenjoule-sdk";

// Parse 402 response headers
const requirements = parsePaymentRequirements(response);
// { scheme, payTo, amount, asset, network, maxTimeoutSeconds, ... }

// Full dance: request -> 402 -> build payment -> retry
const paidResponse = await performX402Dance(url, init, buildPaymentFn);

Compute Server API

The default x402 endpoint for client.chat(). OpenAI-compatible, accepts USDC payments via x402.

POST /v1/chat/completions

OpenAI-compatible chat completion. Returns 402 with payment requirements on first request.

GET /api/models

List available models and per-token pricing

Base URL: https://compute.lumenbro.com

You can point computeUrl to any x402-compatible inference server. The wallet is not locked to LumenBro compute.

Why Self-Custody Matters

Your agent's signing key lives on your device. The server never touches private keys — it only wraps transactions for gas sponsorship.

ProviderKey ModelSelf-Custodial?
lumenjoule-sdkDevice-local (SE, passkey, encrypted file)Yes
PrivyMPC sharded (server holds share)No
CrossmintAPI key custodialNo
TurnkeyInfra-managed HSMNo
Coinbase AgentKitCDP API keyNo

If your wallet provider goes down or changes terms, your agent's wallet should still work. With self-custody, it does. The server is only a gas sponsor — it fee-bumps pre-signed transactions but never has access to your keys.

FAQ

Does my agent key need XLM?

No. For x402 payments (the primary use case), the facilitator pays gas. Your agent key only signs auth entries, not TX envelopes. A freshly-created agent key can immediately start making x402 payments. Only direct transfer() calls require XLM on the agent's G-address.

What happens if my agent key is compromised?

Damage is capped by the on-chain spend policy. If your agent is on the Starter tier, an attacker can drain at most $50 in one day. You can revoke the signer from the dashboard at any time using your passkey.

Can I use this with my own inference server?

Yes. Set computeUrl to your server, or use payAndFetch() for any x402-compatible endpoint. The wallet is a general-purpose x402 payment wallet — it works with any service that speaks the protocol.

Which signer should I use on a Linux VPS?

Use SoftP256Signer with an encrypted key file, or Ed25519 if you prefer simplicity. Cloud VPS providers don't expose hardware security modules. The spend policy is your primary security layer — it caps damage regardless of key custody method.

Can multiple agents share one wallet?

Yes, that's the design. One wallet C-address holds pooled USDC. Each agent signer has its own key and independent daily limit. Like a corporate card program — one funding account, multiple cards.

What's the difference between Ed25519 and P-256?

Ed25519 is the native Stellar key format — simple and widely supported. P-256 (secp256r1) is the curve used by Secure Enclave, TPM, and WebAuthn passkeys — it enables hardware-bound keys that can never be extracted. Both produce the same auth format from the smart wallet's perspective.

How do I upgrade my spend policy tier?

Revoke the existing signer from the dashboard, then re-register the same key with a higher-tier policy contract. Tier upgrades will be automated in a future portal update.

Resources