@goodmeta/agent-verifier 0.2.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/LICENSE +21 -0
- package/README.md +180 -0
- package/package.json +21 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Good Meta
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# @goodmeta/agent-verifier
|
|
2
|
+
|
|
3
|
+
Can this agent spend $X on Y right now? One function call.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { checkPolicy } from "@goodmeta/agent-verifier"
|
|
7
|
+
|
|
8
|
+
const result = checkPolicy(policy, {
|
|
9
|
+
agentId: "agent-1",
|
|
10
|
+
amount: 4500,
|
|
11
|
+
idempotencyKey: "tx-1",
|
|
12
|
+
})
|
|
13
|
+
// → { approved: true, remaining: { budget: 15500 } }
|
|
14
|
+
// → { approved: false, reason: "BUDGET_EXCEEDED", detail: "$45 exceeds remaining $30" }
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Or with the hosted verifier (cross-agent budget tracking):
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { VerifierClient } from "@goodmeta/agent-verifier"
|
|
21
|
+
|
|
22
|
+
const verifier = new VerifierClient({ apiKey: "gm_live_..." })
|
|
23
|
+
const { approved, verificationId } = await verifier.verify(mandate, {
|
|
24
|
+
amount: "3000",
|
|
25
|
+
idempotencyKey: "tx-1",
|
|
26
|
+
})
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Why
|
|
30
|
+
|
|
31
|
+
Agents need spending limits. Without them, a runaway agent generates unlimited charges. This library answers one question before every transaction:
|
|
32
|
+
|
|
33
|
+
**Is this agent authorized to spend this amount?**
|
|
34
|
+
|
|
35
|
+
- **Budget caps** — $200/month, $50 max per transaction
|
|
36
|
+
- **Scope restrictions** — allowed API codes, allowed customers, blocklists
|
|
37
|
+
- **Cross-agent tracking** — one budget across multiple services (hosted mode)
|
|
38
|
+
- **Rail-agnostic** — works with Stripe, x402, MPP, bank transfers, anything
|
|
39
|
+
|
|
40
|
+
## Install
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npm install @goodmeta/agent-verifier
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
|
|
48
|
+
### Policy-based verification
|
|
49
|
+
|
|
50
|
+
No crypto, no signatures. Define spending rules, check against them. Good for billing systems, MCP servers, internal tools.
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { checkPolicy, type SpendingPolicy } from "@goodmeta/agent-verifier"
|
|
54
|
+
|
|
55
|
+
const policy: SpendingPolicy = {
|
|
56
|
+
agentId: "billing-agent",
|
|
57
|
+
budgetTotal: 20_000, // $200/month
|
|
58
|
+
budgetPeriod: "monthly",
|
|
59
|
+
constraints: {
|
|
60
|
+
maxPerEvent: 5_000, // $50 per event
|
|
61
|
+
allowedCodes: ["api_calls", "compute"],
|
|
62
|
+
},
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// ✅ approved
|
|
66
|
+
checkPolicy(policy, {
|
|
67
|
+
agentId: "billing-agent",
|
|
68
|
+
amount: 4_500,
|
|
69
|
+
idempotencyKey: "tx-1",
|
|
70
|
+
})
|
|
71
|
+
// → { approved: true, remaining: { budget: 15500, period: "monthly" } }
|
|
72
|
+
|
|
73
|
+
// ❌ over per-event limit
|
|
74
|
+
checkPolicy(policy, {
|
|
75
|
+
agentId: "billing-agent",
|
|
76
|
+
amount: 6_000,
|
|
77
|
+
idempotencyKey: "tx-2",
|
|
78
|
+
})
|
|
79
|
+
// → { approved: false, reason: "AMOUNT_EXCEEDED", detail: "$60.00 exceeds per-event max $50.00" }
|
|
80
|
+
|
|
81
|
+
// ❌ code not allowed
|
|
82
|
+
checkPolicy(policy, {
|
|
83
|
+
agentId: "billing-agent",
|
|
84
|
+
amount: 3_000,
|
|
85
|
+
metadata: { code: "storage" },
|
|
86
|
+
idempotencyKey: "tx-3",
|
|
87
|
+
})
|
|
88
|
+
// → { approved: false, reason: "CODE_NOT_ALLOWED", detail: 'Code "storage" not in allowed list' }
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### AP2 mandate verification
|
|
92
|
+
|
|
93
|
+
For agents carrying [AP2](https://ap2-protocol.org/) cryptographic mandates (Google, 60+ partners). Verifies EIP-712 signatures and checks constraints.
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
import {
|
|
97
|
+
verifyIntentSignature,
|
|
98
|
+
checkConstraints,
|
|
99
|
+
} from "@goodmeta/agent-verifier"
|
|
100
|
+
|
|
101
|
+
// verify the mandate signature is real
|
|
102
|
+
const sig = await verifyIntentSignature(mandate)
|
|
103
|
+
if (!sig.valid) throw new Error(sig.error)
|
|
104
|
+
|
|
105
|
+
// check spending constraints
|
|
106
|
+
const check = checkConstraints(mandate, {
|
|
107
|
+
amount: "3000",
|
|
108
|
+
merchantId: "merchant-1",
|
|
109
|
+
})
|
|
110
|
+
if (!check.valid) throw new Error(check.error)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Hosted verifier
|
|
114
|
+
|
|
115
|
+
When one agent's budget spans multiple services — Mistral AND Groq AND CoreWeave — a shared verifier tracks the total spend. Self-hosted verification can't do this because each service only sees its own transactions.
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
import { VerifierClient } from "@goodmeta/agent-verifier"
|
|
119
|
+
|
|
120
|
+
const verifier = new VerifierClient({
|
|
121
|
+
apiKey: "gm_live_...",
|
|
122
|
+
baseUrl: "https://verifier.goodmeta.co",
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
// verify + place budget hold
|
|
126
|
+
const { approved, verificationId } = await verifier.verify(mandate, {
|
|
127
|
+
amount: "3000",
|
|
128
|
+
currency: "USDC",
|
|
129
|
+
idempotencyKey: "order-123",
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
if (approved) {
|
|
133
|
+
// settle via any payment rail
|
|
134
|
+
const payment = await charge(/* stripe, x402, mpp, bank */)
|
|
135
|
+
|
|
136
|
+
await verifier.settle(verificationId!, {
|
|
137
|
+
success: payment.ok,
|
|
138
|
+
transactionId: payment.id,
|
|
139
|
+
rail: "card",
|
|
140
|
+
})
|
|
141
|
+
}
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## API
|
|
145
|
+
|
|
146
|
+
### Policy
|
|
147
|
+
|
|
148
|
+
| Function | Description |
|
|
149
|
+
| --- | --- |
|
|
150
|
+
| `checkPolicy(policy, request, currentSpend?)` | Check a spending request against policy constraints |
|
|
151
|
+
|
|
152
|
+
### AP2 mandates
|
|
153
|
+
|
|
154
|
+
| Function | Description |
|
|
155
|
+
| --- | --- |
|
|
156
|
+
| `verifyIntentSignature(mandate)` | Verify EIP-712 signature on an Intent Mandate |
|
|
157
|
+
| `verifyCartSignature(mandate)` | Verify EIP-712 signature on a Cart Mandate |
|
|
158
|
+
| `checkConstraints(mandate, tx)` | Check budget, merchant, category, and temporal constraints |
|
|
159
|
+
| `signIntentMandate(mandate, account)` | User signs autonomous spending authority |
|
|
160
|
+
| `signCartMandate(mandate, account)` | Merchant signs price commitment |
|
|
161
|
+
| `approveCartMandate(mandate, account)` | User approves a specific purchase |
|
|
162
|
+
|
|
163
|
+
### Hosted verifier client
|
|
164
|
+
|
|
165
|
+
| Method | Description |
|
|
166
|
+
| --- | --- |
|
|
167
|
+
| `verifier.verify(mandate, tx)` | Verify with full mandate object + place budget hold |
|
|
168
|
+
| `verifier.verifyById(mandateId, tx)` | Verify by ID (agent passes ID, verifier has mandate on file) |
|
|
169
|
+
| `verifier.settle(id, result)` | Confirm payment or release hold |
|
|
170
|
+
| `verifier.getMandateState(id)` | Query budget, tx count, and history |
|
|
171
|
+
|
|
172
|
+
## Related
|
|
173
|
+
|
|
174
|
+
- [AP2](https://ap2-protocol.org/) — Agent payment authorization by Google (60+ partners)
|
|
175
|
+
- [MPP](https://mpp.dev/) — Machine Payments Protocol by Tempo + Stripe
|
|
176
|
+
- [x402](https://www.x402.org/) — HTTP-native agent payments by Coinbase
|
|
177
|
+
|
|
178
|
+
## License
|
|
179
|
+
|
|
180
|
+
MIT — [Good Meta](https://goodmeta.co)
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@goodmeta/agent-verifier",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Agent spending verification — signature verification, policy-based constraints, and Verifier API client",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"demo": "tsx examples/single-merchant.ts"
|
|
11
|
+
},
|
|
12
|
+
"files": ["dist", "README.md"],
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"tsx": "^4.19.0",
|
|
15
|
+
"typescript": "^5.7.0"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"viem": "^2.23.0"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT"
|
|
21
|
+
}
|