Dubstrata ensures absolute trustless billing by coupling API execution natively with Solana micropayments and Ed25519 cryptography, allowing fully autonomous agent accounting.
Every query routes through a validation middleware that executes standard token evaluation and seamlessly falls back to x402 web3 gateway routing when pre-paid credits are depleted.
# 1. Standard API Key validation (SHA-256 matching)
token_hash = hashlib.sha256(token.encode('utf-8')).hexdigest()
key_response = supabase.table("api_keys").select("id, tenant_id, is_revoked").eq("key_hash", token_hash).execute()
# 2. Tenancy Status Verification
tenant_response = supabase.table("tenant_agents").select("subscription_status").eq("id", tenant_id).execute()
# 3. Micro-balance Fallback (x402 Gateway Trigger)
if status != "active":
return await verify_x402_payment(request, x_transaction_signature)
When a transaction signature is passed to the x402 gateway, the system executes a trustless on-chain verification sequence:
x402_transactions for the unique signature.api.mainnet-beta.solana.com via JSON-RPC.preTokenBalances and postTokenBalances for the treasury owner and USDC mint.net_received = post_usdc - pre_usdc.The /api/v1/auth/agent/update endpoint validates rotated public key ownership cryptographically to prevent account hijacking:
new_wallet_address) from Base58 (32 bytes).signature from Base58 or 64-byte hex representation.tenant_agents, transfers balance accountability in billing_credits, and writes an audit log to agent_identity_logs.