@haven_ai/sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,157 @@
1
+ # @haven_ai/sdk
2
+
3
+ TypeScript SDK for [Haven](https://github.com/d-hinders/Haven) — agent wallet infrastructure for the autonomous economy.
4
+
5
+ Haven gives AI agents the ability to hold, send, and receive money within strict, user-defined guardrails. This SDK makes it trivial to integrate Haven payments into any agent.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install @haven_ai/sdk
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```typescript
16
+ import { HavenClient } from '@haven_ai/sdk'
17
+
18
+ const haven = new HavenClient({
19
+ apiKey: 'sk_agent_xxx', // from Haven dashboard
20
+ delegateKey: '0x...', // agent's delegate EOA private key
21
+ baseUrl: 'http://localhost:3001', // Haven API URL
22
+ })
23
+
24
+ // One-liner payment — handles intent, signing, submission, and confirmation
25
+ const result = await haven.pay({
26
+ token: 'EURe',
27
+ amount: '5.00',
28
+ to: '0xabc...',
29
+ })
30
+
31
+ console.log(result.txHash) // 0x...
32
+ console.log(result.explorerUrl) // https://gnosisscan.io/tx/0x... (or basescan.org for Base)
33
+ ```
34
+
35
+ ## Supported Networks & Tokens
36
+
37
+ | Network | CAIP-2 | Tokens |
38
+ |---------|--------|--------|
39
+ | Gnosis Chain | `eip155:100` | EURe, USDC.e, xDAI |
40
+ | Base | `eip155:8453` | USDC, ETH |
41
+
42
+ ## Step-by-Step API
43
+
44
+ For agents that need control over each step (e.g., external signing):
45
+
46
+ ```typescript
47
+ // Step 1: Create a payment intent
48
+ const intent = await haven.createIntent({
49
+ token: 'USDC',
50
+ amount: '5.00',
51
+ to: '0xabc...',
52
+ })
53
+
54
+ // Step 2: Sign the hash (or sign externally)
55
+ const signature = haven.sign(intent.signData.hash)
56
+
57
+ // Step 3: Submit the signature
58
+ await haven.submitSignature(intent.paymentId, signature)
59
+
60
+ // Step 4: Wait for on-chain confirmation
61
+ const result = await haven.waitForConfirmation(intent.paymentId)
62
+ ```
63
+
64
+ ## x402 Protocol Support
65
+
66
+ Haven natively supports the [x402](https://x402.org) payment protocol. When an API returns HTTP 402, Haven evaluates the payment against policy, executes from the Safe, and retries automatically:
67
+
68
+ ```typescript
69
+ // Automatic — fetch() intercepts 402, pays, and retries
70
+ const response = await haven.fetch('https://paid-api.example.com/data')
71
+ const data = await response.json()
72
+
73
+ // Manual — parse and authorize the 402 yourself
74
+ import { parsePaymentRequired } from '@haven_ai/sdk'
75
+
76
+ const apiResponse = await fetch('https://paid-api.example.com/data')
77
+ if (apiResponse.status === 402) {
78
+ const paymentRequired = parsePaymentRequired(apiResponse)
79
+ const receipt = await haven.authorizeX402(paymentRequired)
80
+ console.log(receipt.explorerUrl)
81
+ }
82
+ ```
83
+
84
+ Supported x402 networks: `eip155:100` (Gnosis Chain) and `eip155:8453` (Base).
85
+
86
+ ## AI Agent Integration
87
+
88
+ ### Pre-built Tool Definitions
89
+
90
+ The SDK ships with ready-made tool schemas for Claude and OpenAI:
91
+
92
+ ```typescript
93
+ import { HavenClient, havenTools } from '@haven_ai/sdk'
94
+ import Anthropic from '@anthropic-ai/sdk'
95
+
96
+ const haven = new HavenClient({ apiKey, delegateKey })
97
+ const anthropic = new Anthropic()
98
+
99
+ const response = await anthropic.messages.create({
100
+ model: 'claude-opus-4-6',
101
+ tools: havenTools.claude(), // or havenTools.openai() for OpenAI
102
+ messages: [{ role: 'user', content: 'Pay 5 EURe to 0xabc for API access' }],
103
+ })
104
+
105
+ // Handle tool calls
106
+ for (const block of response.content) {
107
+ if (block.type === 'tool_use') {
108
+ const result = await haven.executeTool(block.name, block.input)
109
+ // send result back to the model
110
+ }
111
+ }
112
+ ```
113
+
114
+ ### Available Tools
115
+
116
+ | Tool | Description |
117
+ |------|-------------|
118
+ | `make_payment` | Send a payment from the Haven-managed Safe wallet |
119
+ | `get_payment_status` | Check the status of a previously initiated payment |
120
+ | `authorize_x402_payment` | Pay for an HTTP 402 resource via the x402 protocol |
121
+
122
+ ## Configuration
123
+
124
+ ```typescript
125
+ const haven = new HavenClient({
126
+ apiKey: 'sk_agent_xxx', // required — Haven agent API key
127
+ delegateKey: '0x...', // optional — enables .pay() and .sign()
128
+ baseUrl: 'http://localhost:3001', // default
129
+ requestTimeout: 30000, // per-request timeout (ms)
130
+ confirmationTimeout: 90000, // polling timeout (ms)
131
+ pollingInterval: 3000, // polling interval (ms)
132
+ })
133
+ ```
134
+
135
+ ## Error Handling
136
+
137
+ ```typescript
138
+ import { HavenApiError, HavenSigningError, HavenTimeoutError } from '@haven_ai/sdk'
139
+
140
+ try {
141
+ await haven.pay({ token: 'EURe', amount: '5.00', to: '0xabc...' })
142
+ } catch (err) {
143
+ if (err instanceof HavenApiError) {
144
+ console.log(err.statusCode, err.message) // API returned an error
145
+ }
146
+ if (err instanceof HavenSigningError) {
147
+ console.log(err.message) // Signing failed
148
+ }
149
+ if (err instanceof HavenTimeoutError) {
150
+ console.log(err.paymentId) // Confirmation timed out
151
+ }
152
+ }
153
+ ```
154
+
155
+ ## License
156
+
157
+ MIT