Skip to content

Commit e29d189

Browse files
✨ feat: add agent integration and local integration documentation
- Introduced comprehensive guides for agent integration and local integration for SettlerEngine. - Added `agents.md` to detail the HTTP handshake process for payment signatures. - Created `local-integration.md` to explain local communication using UDS and SQLite persistence. - Updated `intro.md` to link to the new documents and highlight local integration features.
1 parent bc173ea commit e29d189

3 files changed

Lines changed: 121 additions & 1 deletion

File tree

docs/docs/agents.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Agent Integration Guide
2+
3+
AI Agents can integrate with SettlerEngine to perform autonomous, cryptographically secure payments for digital resources.
4+
5+
## 1. The HTTP Handshake (x402)
6+
7+
When an agent hits a protected endpoint, it receives an `HTTP 402 Payment Required` response.
8+
9+
### Step A: Receive Challenge
10+
```json
11+
{
12+
"status": 402,
13+
"title": "Payment Required",
14+
"description": "This resource requires a valid x402 payment signature.",
15+
"payment": {
16+
"amount": "1000000",
17+
"asset": "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
18+
"network": "84532",
19+
"recipient": "0x1234567890AbcdEF1234567890aBcdef12345678",
20+
"nonce": "c4e9de00cbdd804fdc7fd131701a2975"
21+
}
22+
}
23+
```
24+
25+
### Step B: Sign Intent to Pay
26+
The agent must sign an EIP-712 message containing the following fields:
27+
- `recipient`: The merchant wallet address.
28+
- `amount`: Atomic units of the asset.
29+
- `asset`: Contract address of the token (e.g., USDC).
30+
- `nonce`: The unique session identifier provided in the challenge.
31+
- `deadline`: A Unix timestamp after which the signature is invalid.
32+
33+
### Step C: Retry with X-Payment
34+
The agent sends the original request again, including the `X-Payment` header with the JSON-encoded `intent` and `signature`.
35+
36+
```http
37+
GET /protected-resource HTTP/1.1
38+
X-Payment: {"intent": {...}, "signature": "0x..."}
39+
```
40+
41+
## 2. Local Integration (Unix Domain Sockets)
42+
43+
For agents running on the same host as SettlerEngine, the Unix Domain Socket (UDS) provides a low-latency, secure channel.
44+
45+
### Socket Location
46+
- **Linux**: `~/.config/settlerengine/settler.sock`
47+
- **macOS**: `~/Library/Application Support/settlerengine/settler.sock`
48+
49+
### Benefits of UDS
50+
- **Zero Network Overhead**: Faster communication for high-frequency agents.
51+
- **Local Trust**: No need for complex network configurations or TLS for local traffic.
52+
- **Persistence**: Verified states are automatically cached in the local SQLite database.
53+
54+
## 3. Best Practices for Agents
55+
- **Nonce Management**: Always use the most recent nonce provided in the 402 challenge.
56+
- **Deadline Handling**: Set a reasonable deadline (e.g., +5 minutes) to avoid signature expiration during processing.
57+
- **Error Handling**: Be prepared to handle signature verification failures by requesting a new nonce.

docs/docs/intro.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ SettlerEngine is a protocol-agnostic settlement layer for the next generation of
77
- **x402 Protocol:** Handshake and verification lifecycle for machine-to-machine payments.
88
- **Hexagonal Architecture:** Decoupling domain core from external infrastructure.
99
- **Statelessness:** Relying on cryptographic signatures and the blockchain as the source of truth.
10+
- **Local Integration:** High-performance UDS and SQLite persistence for co-located agents.
1011

1112
## Getting Started
1213

13-
Refer to the internal modules and the `settler-proxy` for integration details.
14+
- [Agent Integration Guide](./agents.md)
15+
- [Local Integration & UDS](./local-integration.md)
16+
- [Architecture Overview](./architecture.md)
17+
- [x402 Protocol Deep Dive](./x402.md)
18+

docs/docs/local-integration.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Local Integration & UDS
2+
3+
SettlerEngine provides a robust local communication interface for co-located services and agents.
4+
5+
## Data Directory Structure
6+
7+
The engine stores its state and socket in a dedicated directory based on the OS standard (`os.UserConfigDir`):
8+
9+
```bash
10+
settlerengine/
11+
├── settler.db # SQLite3 database (CGO-free)
12+
└── settler.sock # Unix Domain Socket
13+
```
14+
15+
## Unix Domain Socket (UDS) Protocol
16+
17+
The `settler.sock` allows local processes to interact with the engine.
18+
19+
### Connection Example (Go)
20+
```go
21+
package main
22+
23+
import (
24+
"net"
25+
"log"
26+
)
27+
28+
func main() {
29+
conn, err := net.Dial("unix", "/path/to/settler.sock")
30+
if err != nil {
31+
log.Fatal(err)
32+
}
33+
defer conn.Close()
34+
35+
// Write and read protocol messages...
36+
}
37+
```
38+
39+
## Persistence via SQLite
40+
41+
SettlerEngine uses a CGO-free implementation of SQLite (`modernc.org/sqlite`) to ensure compatibility across all environments without needing a C toolchain.
42+
43+
### Verified Payments Table
44+
The engine persists every verified signature to ensure idempotency and prevent replay attacks across restarts.
45+
46+
```sql
47+
CREATE TABLE verified_payments (
48+
signature TEXT PRIMARY KEY,
49+
signer TEXT NOT NULL,
50+
amount TEXT NOT NULL,
51+
asset TEXT NOT NULL,
52+
nonce TEXT NOT NULL,
53+
verified_at DATETIME DEFAULT CURRENT_TIMESTAMP
54+
);
55+
```
56+
57+
### Automatic Cleanup
58+
Signatures are validated against their EIP-712 deadlines even when retrieved from the database. The engine performs periodic cleanup of expired session nonces.

0 commit comments

Comments
 (0)