How the3rdweblabs/cosign works
Purpose and topology
Cosign is a BOT Chain payment-control system for autonomous agents. It separates policy/state on-chain, transaction facilitation and sponsorship off-chain, human approval in a browser console, and reusable client integrations. BOT Chain testnet (968) and mainnet (677) are selected through BOT_NETWORK and network-specific environment variables.
On-chain policy boundary
AgentRegistry maps agents to guardians and spending policy; ConsentGateway decides whether an action may auto-settle, must await guardian consent, or is rejected. The contracts hold policy/state rather than user funds. Deployment creates and wires both contracts.
• contracts/src/AgentRegistry.sol
• contracts/src/ConsentGateway.sol
• contracts/script/Deploy.s.sol
Facilitator: payment execution boundary
The Node/TypeScript facilitator is the operational payment service. It adapts x402 payment requests to BOT Chain execution, assesses sponsorship policy, and sends transactions. It first attempts BOT Chain native EOA paymaster sponsorship, then guarantees a self-pay fallback when sponsorship is unavailable.
• facilitator/src/server.ts
• facilitator/src/x402-adapter.ts
• facilitator/src/paymaster.ts
• facilitator/src/selfpay-fallback.ts
• facilitator/src/policy.ts
Transaction and chain services
The facilitator encapsulates RPC/network selection, fee calculations, and transaction bundling, insulating x402 callers from BOT Chain-specific paymaster RPC methods (pm_isSponsorable) and raw transaction submission. Sponsor credentials and deployed contract addresses are runtime configuration.
• facilitator/src/chain.ts
• facilitator/src/bundler.ts
• facilitator/src/fee.ts
SDK integration layer
The workspace SDK exposes reusable primitives for consent-aware payment clients, wallet sourcing, middleware, x402 protocol handling, and network configuration. Adapter packages provide fetch interception, guardian-oriented use, and MCP servers/CLIs for agent/tool integrations.
• facilitator/sdk/packages/core/src/consent-client.ts
• facilitator/sdk/packages/core/src/middleware.ts
• facilitator/sdk/packages/fetch/src/index.ts
• facilitator/sdk/packages/guardian/src/index.ts
• facilitator/sdk/packages/mcp/src/agent-server.ts
x402 reference flow
A resource server exposes paid endpoints and returns HTTP 402 until payment settles. An agent uses wallet, reasoning, and consent client code to request resources through the x402 flow. The primary control path is: agent request → 402 payment terms → facilitator/payment execution → resource server serves protected response; policy-sensitive calls route through the consent contracts.
• examples/resource-server/src/server.ts
• examples/resource-server/src/routes/x402.ts
• examples/resource-server/src/routes/hubot-task.ts
• examples/agent/src/agent.ts
• examples/agent/src/consent-client.ts
Guardian console
The Vite/React console is the human-facing boundary. It connects a wallet, registers agents, reads consent state, presents pending approvals, and displays activity; guardian signatures/transactions resolve paused actions on-chain.
• console/src/main.tsx
• console/src/App.tsx
• console/src/ApprovalQueue.tsx
• console/src/hooks/useConsent.ts
• console/src/chain.ts
Runtimes and infrastructure
Solidity contracts use Foundry; services, SDK, examples, and console use Node.js/TypeScript. The console runs as a Vite browser application. External dependencies are BOT Chain RPC endpoints, its explorer/faucet, native paymaster RPC, deployed registry/gateway addresses, agent/guardian wallets, and x402-compatible resource endpoints.
Main entry points: ConsentGateway.sol Consent Gateway · chain.ts Chain execution · consent-client.ts Consent client & middleware · policy.ts Sponsorship policy
Components 22
On-chain policy
Foundry contracts on BOT Chain.
- Agent Registry · Maps agents to guardians and spending policy.
contracts/src/AgentRegistry.sol - Consent Gateway · Routes actions to auto-settlement, consent, or rejection.
contracts/src/ConsentGateway.sol - Contract deployment · Deploys and wires registry and gateway.
contracts/script/Deploy.s.sol
Payment facilitator
Node service executing x402 payments.
- Facilitator API · Operational boundary for payment execution.
facilitator/src/server.ts - x402 adapter · Converts x402 payment requests into BOT Chain execution.
facilitator/src/x402-adapter.ts - Sponsorship policy · Assesses whether a payment can be sponsored.
facilitator/src/policy.ts - Native paymaster · Attempts native EOA paymaster sponsorship first.
facilitator/src/paymaster.ts - Self-pay fallback · Guarantees execution when sponsorship is unavailable.
facilitator/src/selfpay-fallback.ts - Chain execution · Selects network and submits BOT Chain transactions.
facilitator/src/chain.ts - Transaction bundler · Builds execution bundles.
facilitator/src/bundler.ts
SDK integrations
Reusable TypeScript client packages.
- Consent client & middleware · Consent-aware client primitives and middleware.
facilitator/sdk/packages/core/src/consent-client.ts - Fetch adapter · Intercepts fetch requests for x402 handling.
facilitator/sdk/packages/fetch/src/index.ts - Guardian adapter · Guardian-oriented integration primitives.
facilitator/sdk/packages/guardian/src/index.ts - MCP agent server · Exposes agent and tool integration endpoints.
facilitator/sdk/packages/mcp/src/agent-server.ts
x402 reference flow
Agent and protected resource examples.
- Autonomous agent · Requests paid resources using wallet and consent code.
examples/agent/src/agent.ts - Protected resource server · Returns 402 terms until payment settles.
examples/resource-server/src/server.ts - Paid endpoint routes · Defines protected x402 and task endpoints.
examples/resource-server/src/routes/x402.ts
Guardian console
Vite browser application for human approvals.
- Guardian console · Wallet-connected interface for agent and consent management.
console/src/App.tsx - Approval queue · Shows pending guardian approvals and activity.
console/src/ApprovalQueue.tsx - Consent state hook · Reads consent state and resolves approvals.
console/src/hooks/useConsent.ts
Other components
- BOT Chain · Testnet 968 or mainnet 677 selected at runtime.
- Paymaster RPC · Provides pm_isSponsorable for native sponsorship.
Connections 26
- Contract deployment → Agent Registry: deploys
- Contract deployment → Consent Gateway: wires
- Consent Gateway → Agent Registry: checks agent policy
- Agent Registry → BOT Chain: stores policy on
- Consent Gateway → BOT Chain: records consent state on
- Autonomous agent → Fetch adapter: requests through
- Fetch adapter → Consent client & middleware: uses
- Consent client & middleware → Facilitator API: submits payment
- Autonomous agent → Protected resource server: requests protected resource
- Protected resource server → Autonomous agent: returns 402 terms
- Protected resource server → Paid endpoint routes: serves
- Facilitator API → x402 adapter: adapts request
- x402 adapter → Sponsorship policy: evaluates
- Sponsorship policy → Native paymaster: sponsorable
- Sponsorship policy → Self-pay fallback: not sponsored
- Native paymaster → Paymaster RPC: checks sponsorship
- Native paymaster → Chain execution: sponsored transaction
- Self-pay fallback → Chain execution: self-paid transaction
- Chain execution → Transaction bundler: builds bundle
- Transaction bundler → BOT Chain: submits transaction
- Chain execution → Consent Gateway: invokes consent policy
- Guardian console → Approval queue: presents
- Approval queue → Consent state hook: uses
- Consent state hook → Consent Gateway: reads and resolves consent
- Guardian adapter → Consent client & middleware: builds on
- MCP agent server → Consent client & middleware: builds on