@armory-sh/middleware-hono 0.3.23 → 0.3.24
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 +115 -161
- package/package.json +22 -3
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# @armory-sh/middleware-hono
|
|
2
2
|
|
|
3
|
-
x402
|
|
3
|
+
Armory x402 SDK — Payment middleware for Hono. Accept x402 payments from any client in your Hono app. 100% compatible with Coinbase x402 SDKs.
|
|
4
|
+
|
|
5
|
+
[Documentation](https://armory.sh) | [License](LICENSE)
|
|
4
6
|
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
@@ -8,213 +10,165 @@ x402 payment middleware for Hono applications.
|
|
|
8
10
|
bun add @armory-sh/middleware-hono
|
|
9
11
|
```
|
|
10
12
|
|
|
11
|
-
##
|
|
13
|
+
## Why Armory?
|
|
14
|
+
|
|
15
|
+
Armory enables HTTP API payments via EIP-3009 `transferWithAuthorization`. Accept payments from any x402-compatible client—Coinbase SDK, Armory SDK, or your own implementation.
|
|
16
|
+
|
|
17
|
+
## Key Exports
|
|
12
18
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
19
|
+
```typescript
|
|
20
|
+
import {
|
|
21
|
+
// Middleware
|
|
22
|
+
paymentMiddleware,
|
|
23
|
+
routeAwarePaymentMiddleware,
|
|
24
|
+
|
|
25
|
+
// Requirements
|
|
26
|
+
createPaymentRequirements,
|
|
27
|
+
|
|
28
|
+
// Types
|
|
29
|
+
type PaymentConfig,
|
|
30
|
+
type RouteAwarePaymentConfig,
|
|
31
|
+
type HonoPaymentContext,
|
|
32
|
+
} from '@armory-sh/middleware-hono';
|
|
33
|
+
```
|
|
18
34
|
|
|
19
|
-
##
|
|
35
|
+
## Quick Start
|
|
36
|
+
|
|
37
|
+
### Basic Middleware
|
|
20
38
|
|
|
21
39
|
```typescript
|
|
22
|
-
import { Hono } from
|
|
23
|
-
import { paymentMiddleware } from
|
|
40
|
+
import { Hono } from 'hono'
|
|
41
|
+
import { paymentMiddleware } from '@armory-sh/middleware-hono'
|
|
24
42
|
|
|
25
|
-
const app = new Hono()
|
|
43
|
+
const app = new Hono()
|
|
26
44
|
|
|
27
|
-
app.use(
|
|
28
|
-
payTo:
|
|
29
|
-
|
|
30
|
-
token:
|
|
31
|
-
amount:
|
|
32
|
-
}))
|
|
45
|
+
app.use('/*', paymentMiddleware({
|
|
46
|
+
payTo: '0xYourAddress...',
|
|
47
|
+
network: 'base',
|
|
48
|
+
token: 'usdc',
|
|
49
|
+
amount: '1.0'
|
|
50
|
+
}))
|
|
33
51
|
|
|
34
|
-
app.get(
|
|
35
|
-
const payment = c.get(
|
|
52
|
+
app.get('/api/data', (c) => {
|
|
53
|
+
const payment = c.get('payment')
|
|
36
54
|
return c.json({
|
|
37
|
-
data:
|
|
38
|
-
payerAddress: payment?.payload?.authorization?.from
|
|
39
|
-
})
|
|
40
|
-
})
|
|
41
|
-
```
|
|
55
|
+
data: 'protected data',
|
|
56
|
+
payerAddress: payment?.payload?.authorization?.from
|
|
57
|
+
})
|
|
58
|
+
})
|
|
42
59
|
|
|
43
|
-
|
|
60
|
+
app.listen(3000)
|
|
61
|
+
```
|
|
44
62
|
|
|
45
|
-
|
|
63
|
+
### Route-Aware Middleware
|
|
46
64
|
|
|
47
65
|
```typescript
|
|
48
|
-
import { routeAwarePaymentMiddleware } from
|
|
49
|
-
|
|
50
|
-
const app = new Hono()
|
|
51
|
-
|
|
52
|
-
//
|
|
53
|
-
app.use(
|
|
54
|
-
routes: [
|
|
55
|
-
payTo:
|
|
56
|
-
amount:
|
|
57
|
-
network:
|
|
58
|
-
}));
|
|
59
|
-
|
|
60
|
-
// Multiple routes with per-route configuration
|
|
61
|
-
app.use("/api/*", routeAwarePaymentMiddleware({
|
|
62
|
-
routes: ["/api/basic", "/api/premium/*"],
|
|
63
|
-
payTo: "0xYourAddress...",
|
|
64
|
-
amount: "$1.00", // Default amount
|
|
65
|
-
network: "base",
|
|
66
|
+
import { routeAwarePaymentMiddleware } from '@armory-sh/middleware-hono'
|
|
67
|
+
|
|
68
|
+
const app = new Hono()
|
|
69
|
+
|
|
70
|
+
// Different pricing for different routes
|
|
71
|
+
app.use('/api/*', routeAwarePaymentMiddleware({
|
|
72
|
+
routes: ['/api/basic', '/api/premium/*'],
|
|
73
|
+
payTo: '0xYourAddress...',
|
|
74
|
+
amount: '$1.00',
|
|
75
|
+
network: 'base',
|
|
66
76
|
perRoute: {
|
|
67
|
-
|
|
68
|
-
amount:
|
|
69
|
-
network: "ethereum",
|
|
77
|
+
'/api/premium/*': {
|
|
78
|
+
amount: '$5.00'
|
|
70
79
|
}
|
|
71
80
|
}
|
|
72
|
-
}))
|
|
81
|
+
}))
|
|
73
82
|
```
|
|
74
83
|
|
|
75
|
-
|
|
84
|
+
### Multi-Network Support
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
app.use('/*', paymentMiddleware({
|
|
88
|
+
payTo: '0xYourAddress...',
|
|
89
|
+
chains: ['base', 'ethereum', 'skale-base'],
|
|
90
|
+
tokens: ['usdc', 'eurc'],
|
|
91
|
+
amount: '1.0'
|
|
92
|
+
}))
|
|
93
|
+
```
|
|
76
94
|
|
|
77
|
-
###
|
|
95
|
+
### Per-Chain Configuration
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
app.use('/*', paymentMiddleware({
|
|
99
|
+
payTo: '0xDefaultAddress...',
|
|
100
|
+
payToByChain: {
|
|
101
|
+
base: '0xBaseAddress...',
|
|
102
|
+
ethereum: '0xEthAddress...'
|
|
103
|
+
},
|
|
104
|
+
chain: 'base',
|
|
105
|
+
token: 'usdc'
|
|
106
|
+
}))
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Configuration Options
|
|
78
110
|
|
|
79
111
|
```typescript
|
|
80
112
|
interface PaymentConfig {
|
|
81
|
-
payTo: string
|
|
82
|
-
chain?: string | number
|
|
83
|
-
chains?: Array<string | number
|
|
84
|
-
token?: string
|
|
85
|
-
tokens?: string[]
|
|
86
|
-
amount?: string
|
|
87
|
-
maxTimeoutSeconds?: number
|
|
113
|
+
payTo: string // Payment recipient address
|
|
114
|
+
chain?: string | number // Network (name or chain ID)
|
|
115
|
+
chains?: Array<string | number> // Multiple networks
|
|
116
|
+
token?: string // Token symbol
|
|
117
|
+
tokens?: string[] // Multiple tokens
|
|
118
|
+
amount?: string // Amount (default: "1.0")
|
|
119
|
+
maxTimeoutSeconds?: number // Payment timeout (default: 300)
|
|
88
120
|
|
|
89
121
|
// Per-chain configuration
|
|
90
|
-
payToByChain?: Record<string, string
|
|
91
|
-
facilitatorUrlByChain?: Record<string, string
|
|
122
|
+
payToByChain?: Record<string, string>
|
|
123
|
+
facilitatorUrlByChain?: Record<string, string>
|
|
92
124
|
|
|
93
125
|
// Per-token-per-chain configuration
|
|
94
|
-
payToByToken?: Record<string, Record<string, string
|
|
95
|
-
facilitatorUrlByToken?: Record<string, Record<string, string
|
|
126
|
+
payToByToken?: Record<string, Record<string, string>>
|
|
127
|
+
facilitatorUrlByToken?: Record<string, Record<string, string>>
|
|
96
128
|
}
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
### RouteAwarePaymentConfig
|
|
100
129
|
|
|
101
|
-
```typescript
|
|
102
130
|
interface RouteAwarePaymentConfig extends PaymentConfig {
|
|
103
|
-
route?: string
|
|
104
|
-
routes?: string[]
|
|
105
|
-
perRoute?: Record<string, Partial<PaymentConfig
|
|
131
|
+
route?: string // Single exact route
|
|
132
|
+
routes?: string[] // Multiple routes (allows wildcards)
|
|
133
|
+
perRoute?: Record<string, Partial<PaymentConfig>>
|
|
106
134
|
}
|
|
107
135
|
```
|
|
108
136
|
|
|
109
|
-
## Payment Context
|
|
110
|
-
|
|
111
|
-
The middleware adds payment information to the Hono context:
|
|
112
|
-
|
|
113
|
-
```typescript
|
|
114
|
-
app.get("/api/data", (c) => {
|
|
115
|
-
const payment = c.get("payment");
|
|
116
|
-
// payment.payload: PaymentPayloadV2
|
|
117
|
-
// payment.verified: boolean
|
|
118
|
-
// payment.route: string (only for route-aware middleware)
|
|
119
|
-
});
|
|
120
|
-
```
|
|
121
|
-
|
|
122
137
|
## Input Formats
|
|
123
138
|
|
|
124
|
-
**Networks**
|
|
139
|
+
**Networks** — Use any format:
|
|
125
140
|
```typescript
|
|
126
141
|
'base' // name
|
|
127
142
|
8453 // chain ID
|
|
128
143
|
'eip155:8453' // CAIP-2
|
|
129
144
|
```
|
|
130
145
|
|
|
131
|
-
**Tokens**
|
|
146
|
+
**Tokens** — Use any format:
|
|
132
147
|
```typescript
|
|
133
148
|
'usdc' // symbol (case-insensitive)
|
|
134
149
|
'0x8335...' // EVM address
|
|
135
150
|
'eip155:8453/erc20:0x8335...' // CAIP Asset ID
|
|
136
151
|
```
|
|
137
152
|
|
|
138
|
-
##
|
|
139
|
-
|
|
140
|
-
- **Exact**: `/api/users` - matches only `/api/users`
|
|
141
|
-
- **Wildcard**: `/api/*` - matches `/api/users`, `/api/posts/123`
|
|
142
|
-
- **Parameterized**: `/api/users/:id` - matches `/api/users/123`
|
|
143
|
-
|
|
144
|
-
Priority order: Exact matches > Parameterized routes > Wildcard routes
|
|
145
|
-
|
|
146
|
-
## Examples
|
|
147
|
-
|
|
148
|
-
### Multi-Network Support
|
|
149
|
-
|
|
150
|
-
```typescript
|
|
151
|
-
app.use("/*", paymentMiddleware({
|
|
152
|
-
payTo: "0xYourAddress...",
|
|
153
|
-
chains: ["base", "ethereum", "skale-base"],
|
|
154
|
-
tokens: ["usdc", "eurc"],
|
|
155
|
-
amount: "1.0"
|
|
156
|
-
}));
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
### Per-Chain Configuration
|
|
160
|
-
|
|
161
|
-
```typescript
|
|
162
|
-
app.use("/*", paymentMiddleware({
|
|
163
|
-
payTo: "0xDefaultAddress...",
|
|
164
|
-
payToByChain: {
|
|
165
|
-
base: "0xBaseAddress...",
|
|
166
|
-
ethereum: "0xEthAddress...",
|
|
167
|
-
},
|
|
168
|
-
chain: "base",
|
|
169
|
-
token: "usdc"
|
|
170
|
-
}));
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
### Route-Specific Pricing
|
|
174
|
-
|
|
175
|
-
```typescript
|
|
176
|
-
app.use("/api/*", routeAwarePaymentMiddleware({
|
|
177
|
-
routes: ["/api/basic", "/api/pro", "/api/enterprise"],
|
|
178
|
-
payTo: "0xYourAddress...",
|
|
179
|
-
amount: "$1.00",
|
|
180
|
-
network: "base",
|
|
181
|
-
perRoute: {
|
|
182
|
-
"/api/pro": {
|
|
183
|
-
amount: "$5.00",
|
|
184
|
-
},
|
|
185
|
-
"/api/enterprise": {
|
|
186
|
-
amount: "$50.00",
|
|
187
|
-
network: "ethereum",
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}));
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
## API
|
|
194
|
-
|
|
195
|
-
### `paymentMiddleware(config)`
|
|
196
|
-
|
|
197
|
-
Creates a basic payment middleware for Hono.
|
|
198
|
-
|
|
199
|
-
**Parameters:**
|
|
200
|
-
- `config`: Payment configuration
|
|
201
|
-
|
|
202
|
-
**Returns:** Hono middleware function
|
|
203
|
-
|
|
204
|
-
### `createPaymentRequirements(config)`
|
|
205
|
-
|
|
206
|
-
Creates payment requirements from configuration (for advanced use).
|
|
207
|
-
|
|
208
|
-
**Parameters:**
|
|
209
|
-
- `config`: Payment configuration
|
|
153
|
+
## Features
|
|
210
154
|
|
|
211
|
-
**
|
|
155
|
+
- **x402 Compatible**: Accept payments from any x402 client
|
|
156
|
+
- **Route-Aware**: Different pricing for different routes
|
|
157
|
+
- **Multi-Network**: Ethereum, Base, SKALE support
|
|
158
|
+
- **Multi-Token**: USDC, EURC, USDT, WBTC, WETH, SKL
|
|
159
|
+
- **Per-Chain Config**: Different addresses per network
|
|
160
|
+
- **Facilitator Integration**: Optional facilitator support
|
|
212
161
|
|
|
213
|
-
|
|
162
|
+
## Supported Networks
|
|
214
163
|
|
|
215
|
-
|
|
164
|
+
| Network | Chain ID |
|
|
165
|
+
|---------|----------|
|
|
166
|
+
| Ethereum | 1 |
|
|
167
|
+
| Base | 8453 |
|
|
168
|
+
| Base Sepolia | 84532 |
|
|
169
|
+
| SKALE Base | 1187947933 |
|
|
170
|
+
| SKALE Base Sepolia | 324705682 |
|
|
216
171
|
|
|
217
|
-
|
|
218
|
-
- `config`: Route-aware payment configuration
|
|
172
|
+
## License
|
|
219
173
|
|
|
220
|
-
|
|
174
|
+
MIT © [Sawyer Cutler](https://github.com/TheGreatAxios/armory)
|
package/package.json
CHANGED
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@armory-sh/middleware-hono",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.24",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Sawyer Cutler <sawyer@dirtroad.dev>",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"x402",
|
|
8
|
+
"ai",
|
|
9
|
+
"agentic commerce",
|
|
10
|
+
"ai agent",
|
|
11
|
+
"stablecoins",
|
|
12
|
+
"eip-3009",
|
|
13
|
+
"skale",
|
|
14
|
+
"base",
|
|
15
|
+
"machine economy",
|
|
16
|
+
"payment",
|
|
17
|
+
"crypto",
|
|
18
|
+
"web3",
|
|
19
|
+
"ethereum",
|
|
20
|
+
"usdc",
|
|
21
|
+
"hono",
|
|
22
|
+
"middleware",
|
|
23
|
+
"server"
|
|
24
|
+
],
|
|
6
25
|
"type": "module",
|
|
7
26
|
"main": "./dist/index.js",
|
|
8
27
|
"types": "./dist/index.d.ts",
|
|
@@ -33,8 +52,8 @@
|
|
|
33
52
|
"hono": "^4"
|
|
34
53
|
},
|
|
35
54
|
"dependencies": {
|
|
36
|
-
"@armory-sh/base": "0.2.
|
|
37
|
-
"@armory-sh/extensions": "0.1.
|
|
55
|
+
"@armory-sh/base": "0.2.24",
|
|
56
|
+
"@armory-sh/extensions": "0.1.5"
|
|
38
57
|
},
|
|
39
58
|
"devDependencies": {
|
|
40
59
|
"bun-types": "latest",
|