@veyto/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/LICENSE +202 -0
- package/README.md +58 -0
- package/dist/client.d.ts +398 -0
- package/dist/client.js +395 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/localSigner.d.ts +4 -0
- package/dist/localSigner.js +31 -0
- package/package.json +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# @veyto/sdk
|
|
2
|
+
|
|
3
|
+
**Give an AI agent a wallet with enforceable spending rules, and get a signed receipt for
|
|
4
|
+
every payment it makes.**
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
npm install @veyto/sdk viem
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```ts
|
|
11
|
+
import { VeytoClient, VeytoDeniedError, localSigner } from "@veyto/sdk";
|
|
12
|
+
|
|
13
|
+
const veyto = new VeytoClient({
|
|
14
|
+
baseUrl: "https://sandbox.veyto.io",
|
|
15
|
+
apiKey: process.env.VEYTO_API_KEY!,
|
|
16
|
+
agentId: process.env.VEYTO_AGENT_ID!,
|
|
17
|
+
rail: "eip155:84532", // Base Sepolia
|
|
18
|
+
currency: "USDC-6",
|
|
19
|
+
sign: localSigner(process.env.MY_WALLET_KEY!), // your key — stays in YOUR process
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// $1 per payment, $5 per day, 20 payments an hour
|
|
23
|
+
await veyto.setPolicy(agentId, "1000000", "5000000", 20);
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const res = await veyto.payingFetch("https://some-service/premium/data");
|
|
27
|
+
} catch (e) {
|
|
28
|
+
if (e instanceof VeytoDeniedError) {
|
|
29
|
+
console.log("Blocked:", e.reason); // a guardrail did its job; no money moved
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Your key stays yours
|
|
35
|
+
|
|
36
|
+
Veyto is **non-custodial**. For a non-custodial agent the API returns *unsigned* EIP-3009
|
|
37
|
+
material and `localSigner` signs it in your process. Only the signature goes back. There is
|
|
38
|
+
no route that accepts a private key.
|
|
39
|
+
|
|
40
|
+
## Blocked is not an error
|
|
41
|
+
|
|
42
|
+
`VeytoDeniedError` means a limit stopped the payment and **nothing moved** — not reserved,
|
|
43
|
+
not signed, not settled. Treat it differently from a thrown exception: one is an answer, the
|
|
44
|
+
other is a problem.
|
|
45
|
+
|
|
46
|
+
## What it does
|
|
47
|
+
|
|
48
|
+
`payingFetch` · `createAgent` · `setPolicy` · `freeze` / `unfreeze` · `listAgents` ·
|
|
49
|
+
`getAgent` · `getPolicy` · `getWallet` · `listIntents` · `getIntent` · `listReceipts` ·
|
|
50
|
+
`getReceipt`.
|
|
51
|
+
|
|
52
|
+
Full documentation: **[docs.veyto.io](https://docs.veyto.io)**.
|
|
53
|
+
|
|
54
|
+
## Beta
|
|
55
|
+
|
|
56
|
+
Base Sepolia and test USDC only. No mainnet. The API may change without ceremony.
|
|
57
|
+
|
|
58
|
+
Copyright 2026 Veyto. Licensed under the Apache License, Version 2.0 — see [LICENSE](./LICENSE).
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
import type { SignCallback } from "./localSigner.js";
|
|
2
|
+
export interface VeytoClientConfig {
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
apiKey: string;
|
|
5
|
+
agentId: string;
|
|
6
|
+
rail: string;
|
|
7
|
+
/**
|
|
8
|
+
* Hash the delivered payload and report it on settle, so the receipt binds a
|
|
9
|
+
* claim about WHAT arrived. Off by default: it buffers the whole body (double
|
|
10
|
+
* memory on a large download). Veyto records it as CALLER-ASSERTED — it is
|
|
11
|
+
* non-repudiation, not proof Veyto inspected the goods.
|
|
12
|
+
*/
|
|
13
|
+
attestGoods?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Extra headers sent on every call to the Veyto API (never to the paid
|
|
16
|
+
* resource — that request is the caller's own).
|
|
17
|
+
*
|
|
18
|
+
* Exists because a hosted Veyto can sit behind an edge gateway that
|
|
19
|
+
* authenticates the CALLER before the request ever reaches the API. The
|
|
20
|
+
* sandbox does: Cloudflare Access checks a service token, and without those
|
|
21
|
+
* headers an agent gets a 302 to a human login page it can never complete.
|
|
22
|
+
* That is two independent locks by design — the gateway decides who may
|
|
23
|
+
* reach the API at all, Veyto decides what they may spend — so the SDK has
|
|
24
|
+
* to be able to carry the first one.
|
|
25
|
+
*
|
|
26
|
+
* extraHeaders: {
|
|
27
|
+
* "CF-Access-Client-Id": process.env.CF_ACCESS_CLIENT_ID!,
|
|
28
|
+
* "CF-Access-Client-Secret": process.env.CF_ACCESS_CLIENT_SECRET!,
|
|
29
|
+
* }
|
|
30
|
+
*/
|
|
31
|
+
extraHeaders?: Record<string, string>;
|
|
32
|
+
/**
|
|
33
|
+
* Why this agent spends — cost centre, project, client. Sent on every payment
|
|
34
|
+
* and SIGNED into the receipt. Optional, but the one accounting field that
|
|
35
|
+
* cannot be added later (ADR-0020).
|
|
36
|
+
*/
|
|
37
|
+
purpose?: string;
|
|
38
|
+
currency: string;
|
|
39
|
+
fetchImpl?: typeof fetch;
|
|
40
|
+
sign?: SignCallback;
|
|
41
|
+
}
|
|
42
|
+
/** A receipt as the API returns it: the signed material, and what we have learned since. */
|
|
43
|
+
export interface ReceiptRecord {
|
|
44
|
+
receipt_id: string;
|
|
45
|
+
intent_id: string;
|
|
46
|
+
created_at: string;
|
|
47
|
+
/** Exactly what was signed. Verify over `body_canonical` — it is already JSON; parse it yourself. */
|
|
48
|
+
signed: {
|
|
49
|
+
body_canonical: string;
|
|
50
|
+
signature: string;
|
|
51
|
+
};
|
|
52
|
+
/** Derived from the ledger, NOT signed. `signed: false` is stated in the payload, not implied. */
|
|
53
|
+
finality: {
|
|
54
|
+
state: string;
|
|
55
|
+
observed_at: string | null;
|
|
56
|
+
evidence: unknown;
|
|
57
|
+
signed: false;
|
|
58
|
+
source: string;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export interface ReceiptPage {
|
|
62
|
+
items: ReceiptRecord[];
|
|
63
|
+
/** Pass back as `before` to page. Null when the last page has been reached. */
|
|
64
|
+
next_before: string | null;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* An agent's GOVERNED FINANCIAL STATE — deliberately not a balance.
|
|
68
|
+
*
|
|
69
|
+
* ⚠️ Veyto records what it governed; it does not hold or observe wallet funds. Every figure
|
|
70
|
+
* under `governed_exposure` is an amount recorded moving OUT under policy, and
|
|
71
|
+
* `policy_headroom` is a permission limit. Neither is money available. There is no balance
|
|
72
|
+
* field here because there is no balance Veyto can honestly report: the ledger posts
|
|
73
|
+
* `agent_wallet -N / external +N` on settlement and has no deposit postings at all.
|
|
74
|
+
*/
|
|
75
|
+
export interface WalletState {
|
|
76
|
+
agent_id: string;
|
|
77
|
+
wallet_account_id: string | null;
|
|
78
|
+
currency: string | null;
|
|
79
|
+
/** Other wallet accounts this agent owns that these figures do NOT cover. Empty today. */
|
|
80
|
+
wallet_accounts_not_summarized: Array<{
|
|
81
|
+
wallet_account_id: string;
|
|
82
|
+
currency: string;
|
|
83
|
+
}>;
|
|
84
|
+
/** Currencies present on this wallet that these figures do NOT cover. Empty today. */
|
|
85
|
+
currencies_not_summarized: string[];
|
|
86
|
+
custody_mode: "tier0" | "tier1" | "noncustodial";
|
|
87
|
+
/** The address this agent pays FROM. An identifier — read it on chain yourself for funds. */
|
|
88
|
+
payer_address: string;
|
|
89
|
+
agent_status?: "active" | "frozen";
|
|
90
|
+
governed_exposure: GovernedExposure | null;
|
|
91
|
+
reservations: Reservations | null;
|
|
92
|
+
policy_headroom: WalletPolicyHeadroom | null;
|
|
93
|
+
not_reported: NotReported;
|
|
94
|
+
}
|
|
95
|
+
export interface GovernedExposure {
|
|
96
|
+
/** Always "outflow": these are amounts recorded LEAVING, not holdings. */
|
|
97
|
+
direction: "outflow";
|
|
98
|
+
/**
|
|
99
|
+
* The ledger's `final` class. **`null` means CANNOT BE ANSWERED** — never zero. The account
|
|
100
|
+
* holds at least one disputed entry, and a contradicted book has no trustworthy total;
|
|
101
|
+
* `disputed.entry_count` says how many. Treating null as 0 would manufacture the certainty
|
|
102
|
+
* this field exists to withhold.
|
|
103
|
+
*
|
|
104
|
+
* This said "chain-verified" and that promised more than the ledger defines: the final class
|
|
105
|
+
* also folds entries to which settlement finality does not apply. Every entry today is a
|
|
106
|
+
* settlement, so the figure IS chain-verified in fact — but the name follows the definition.
|
|
107
|
+
*/
|
|
108
|
+
finalized_outflow_minor: string | null;
|
|
109
|
+
/** Recorded but not independently confirmed on chain. Money may well have moved. */
|
|
110
|
+
provisional_exposure_minor: string | null;
|
|
111
|
+
adjudicated_minor: string | null;
|
|
112
|
+
disputed: {
|
|
113
|
+
entry_count: number;
|
|
114
|
+
/** True when `entries` was capped and does not list every disputed entry. */
|
|
115
|
+
entries_truncated: boolean;
|
|
116
|
+
/** One row per ENTRY, enumerated and never summed. Each id resolves through `getIntent`. */
|
|
117
|
+
entries: Array<{
|
|
118
|
+
entry_id: string;
|
|
119
|
+
intent_id: string;
|
|
120
|
+
amount_minor: string;
|
|
121
|
+
/** Per entry, by its own sign — a positive disputed position is not forced to "outflow". */
|
|
122
|
+
direction: "outflow" | "inflow";
|
|
123
|
+
}>;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Non-null only if a net INFLOW ever appears — no posting produces one today.
|
|
127
|
+
*
|
|
128
|
+
* Reported PER CLASS and never summed: mixing evidence levels into one number is exactly
|
|
129
|
+
* what the rest of this response refuses to do. `null` when there is no inflow at all.
|
|
130
|
+
*/
|
|
131
|
+
unexpected_net_inflow: null | {
|
|
132
|
+
/**
|
|
133
|
+
* Named `finalized_minor` deliberately: A24 reserves the shorter balance name for a figure
|
|
134
|
+
* that must always travel with its disputed count, and this is an inflow, not a balance.
|
|
135
|
+
*/
|
|
136
|
+
finalized_minor: string | null;
|
|
137
|
+
provisional_minor: string | null;
|
|
138
|
+
adjudicated_minor: string | null;
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
/** Every status a reservation can carry — none is dropped, so nothing tied up goes unseen. */
|
|
142
|
+
export interface Reservations {
|
|
143
|
+
pending_minor: string;
|
|
144
|
+
pending_count: number;
|
|
145
|
+
committed_minor: string;
|
|
146
|
+
committed_count: number;
|
|
147
|
+
expired_minor: string;
|
|
148
|
+
expired_count: number;
|
|
149
|
+
released_minor: string;
|
|
150
|
+
released_count: number;
|
|
151
|
+
}
|
|
152
|
+
export interface WalletPolicyHeadroom {
|
|
153
|
+
/** Always "policy_permission_not_funds" — it travels with the number on purpose. */
|
|
154
|
+
basis: "policy_permission_not_funds";
|
|
155
|
+
/** How much more this agent is PERMITTED to spend today. Not money available. */
|
|
156
|
+
remaining_policy_headroom_minor: string | null;
|
|
157
|
+
cap_per_day_minor: string;
|
|
158
|
+
spent_today_minor: string;
|
|
159
|
+
as_of: string;
|
|
160
|
+
}
|
|
161
|
+
/** What Veyto declines to claim, stated rather than left to inference. */
|
|
162
|
+
export interface NotReported {
|
|
163
|
+
funds_held_minor: null;
|
|
164
|
+
spendable_minor: null;
|
|
165
|
+
reason: string;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* One decision record: what the agent attempted, what Veyto decided, and — where the attempt was
|
|
169
|
+
* DENIED by policy — why.
|
|
170
|
+
*
|
|
171
|
+
* This is the audit trail's unit. Receipts cover the payments that happened; this covers every
|
|
172
|
+
* attempt, including the ones that were refused. For a governed payer the refusals are the point.
|
|
173
|
+
*/
|
|
174
|
+
export interface IntentRecord {
|
|
175
|
+
intent_id: string;
|
|
176
|
+
agent_id: string;
|
|
177
|
+
/** Microsecond precision, formatted by the database — never routed through a JS `Date`. */
|
|
178
|
+
created_at: string;
|
|
179
|
+
updated_at: string;
|
|
180
|
+
attempt: IntentAttempt;
|
|
181
|
+
decision: IntentDecision;
|
|
182
|
+
evidence: IntentEvidence;
|
|
183
|
+
}
|
|
184
|
+
/** What the agent asked for, exactly as recorded. */
|
|
185
|
+
export interface IntentAttempt {
|
|
186
|
+
amount_minor: string;
|
|
187
|
+
max_fees_minor: string;
|
|
188
|
+
currency: string;
|
|
189
|
+
payee: string;
|
|
190
|
+
rail: string;
|
|
191
|
+
resource_url: string | null;
|
|
192
|
+
purpose: string | null;
|
|
193
|
+
}
|
|
194
|
+
export interface IntentDecision {
|
|
195
|
+
/** The recorded lifecycle status, passed through. */
|
|
196
|
+
status: "requested" | "denied" | "approved" | "executing" | "settled" | "failed" | "uncertain" | "expired";
|
|
197
|
+
/**
|
|
198
|
+
* The recorded policy reason, **verbatim** — one of "exceeds daily cap",
|
|
199
|
+
* "exceeds per-payment cap", "exceeds hourly velocity", "amount must be positive",
|
|
200
|
+
* "max_fees negative".
|
|
201
|
+
*
|
|
202
|
+
* ⚠️ Non-null ONLY where the record was DENIED by policy. This says nothing about whether an
|
|
203
|
+
* evaluation happened for any other record — it says only that no policy denial reason is
|
|
204
|
+
* carried. The pay path records an internal string in the same column for a signing failure,
|
|
205
|
+
* and that is deliberately never exposed here.
|
|
206
|
+
*/
|
|
207
|
+
reason: string | null;
|
|
208
|
+
/** Always `"policy_evaluation"` when a reason is present — it travels with the number. */
|
|
209
|
+
reason_basis: "policy_evaluation" | null;
|
|
210
|
+
/**
|
|
211
|
+
* Why no reason is given, stated rather than left to inference.
|
|
212
|
+
*
|
|
213
|
+
* Scoped to the DENIAL, deliberately. An approval is a recorded decision too, and a
|
|
214
|
+
* `requested` record may never have been evaluated at all, so any wording that classified
|
|
215
|
+
* evaluation would contradict the evidence in one direction or the other. This says only that
|
|
216
|
+
* the record carries no policy denial reason.
|
|
217
|
+
*/
|
|
218
|
+
reason_not_recorded: "none_recorded" | "not_a_policy_denial" | null;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* References, never inferences.
|
|
222
|
+
*
|
|
223
|
+
* ⚠️ `receipt_id: null` means only "no receipt row is linked" — it is NOT evidence the payment
|
|
224
|
+
* did not happen. A `settled` status does not imply a receipt exists; measured on production,
|
|
225
|
+
* some settled intents have neither a receipt nor a verdict. For finality, read the receipt.
|
|
226
|
+
*/
|
|
227
|
+
export interface IntentEvidence {
|
|
228
|
+
receipt_id: string | null;
|
|
229
|
+
/**
|
|
230
|
+
* A verdict record is present **now**. Not "a verdict was issued": verdict records are not
|
|
231
|
+
* append-only, so absence proves only absence.
|
|
232
|
+
*/
|
|
233
|
+
verdict_present: boolean;
|
|
234
|
+
}
|
|
235
|
+
export interface IntentPage {
|
|
236
|
+
items: IntentRecord[];
|
|
237
|
+
next_before: string | null;
|
|
238
|
+
}
|
|
239
|
+
/** An agent as the API returns it. Identity and freeze state — never a key, never a balance. */
|
|
240
|
+
export interface AgentRecord {
|
|
241
|
+
id: string;
|
|
242
|
+
name: string;
|
|
243
|
+
custody_mode: "tier0" | "tier1" | "noncustodial";
|
|
244
|
+
/** The address this agent pays FROM. An identifier, not a balance. */
|
|
245
|
+
payer_address: string;
|
|
246
|
+
status: "active" | "frozen";
|
|
247
|
+
created_at: string;
|
|
248
|
+
}
|
|
249
|
+
export interface AgentPage {
|
|
250
|
+
items: AgentRecord[];
|
|
251
|
+
/** Pass back as `before` to page. Null when the last page has been reached. */
|
|
252
|
+
next_before: string | null;
|
|
253
|
+
}
|
|
254
|
+
/** The caps in force on an agent. Immutable per version — a change is a new version. */
|
|
255
|
+
export interface PolicyInForce {
|
|
256
|
+
version: number;
|
|
257
|
+
cap_per_payment_minor: string;
|
|
258
|
+
cap_per_day_minor: string;
|
|
259
|
+
velocity_max_per_hour: number;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* What the agent has spent and how much room is left.
|
|
263
|
+
*
|
|
264
|
+
* ⚠️ A SNAPSHOT, NOT A GUARANTEE. Read without the wallet lock the enforcement path takes, so
|
|
265
|
+
* a concurrent payment may already have consumed some of what is reported here. Plan with it;
|
|
266
|
+
* never treat it as a promise that the next payment will be approved — only the reservation
|
|
267
|
+
* itself decides that, and it decides under a lock this read deliberately does not take.
|
|
268
|
+
*/
|
|
269
|
+
export interface SpendState {
|
|
270
|
+
wallet_account_id: string;
|
|
271
|
+
currency: string;
|
|
272
|
+
spent_today_minor: string;
|
|
273
|
+
remaining_today_minor: string;
|
|
274
|
+
count_last_hour: number;
|
|
275
|
+
remaining_this_hour: number;
|
|
276
|
+
/**
|
|
277
|
+
* The database instant every number above was computed at — one transaction-stable
|
|
278
|
+
* moment, taken from Postgres rather than from the API process's own clock, so it
|
|
279
|
+
* cannot drift away from the data it describes.
|
|
280
|
+
*/
|
|
281
|
+
as_of: string;
|
|
282
|
+
}
|
|
283
|
+
/** `policy` and `spend` are both null for an agent that has never been given a policy. */
|
|
284
|
+
export interface PolicyState {
|
|
285
|
+
agent_id: string;
|
|
286
|
+
agent_status?: "active" | "frozen";
|
|
287
|
+
policy: PolicyInForce | null;
|
|
288
|
+
spend: SpendState | null;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* A read that the server refused. `status` is preserved so a caller can tell a missing scope
|
|
292
|
+
* (403) from a bad key (401) from a receipt that is not theirs (404).
|
|
293
|
+
*
|
|
294
|
+
* ⚠️ 404 remains deliberately ambiguous: the API does not distinguish "no such receipt" from
|
|
295
|
+
* "not yours", because a 403 there would confirm to an enumerating caller that an id is real.
|
|
296
|
+
* The SDK preserves that ambiguity rather than trying to be helpful about it.
|
|
297
|
+
*/
|
|
298
|
+
export declare class VeytoReadError extends Error {
|
|
299
|
+
readonly status: number;
|
|
300
|
+
constructor(status: number, operation: string);
|
|
301
|
+
}
|
|
302
|
+
export declare class VeytoDeniedError extends Error {
|
|
303
|
+
reason: string;
|
|
304
|
+
constructor(reason: string);
|
|
305
|
+
}
|
|
306
|
+
export declare class VeytoClient {
|
|
307
|
+
private readonly cfg;
|
|
308
|
+
constructor(cfg: VeytoClientConfig);
|
|
309
|
+
private get f();
|
|
310
|
+
private authHeaders;
|
|
311
|
+
payingFetch(url: string, init?: RequestInit): Promise<Response>;
|
|
312
|
+
private decodePayment;
|
|
313
|
+
/**
|
|
314
|
+
* Parse the payee's settlement response header.
|
|
315
|
+
*
|
|
316
|
+
* Distinguishes ABSENT from MALFORMED: a genuine settlement whose header failed to
|
|
317
|
+
* parse is not the same fact as a payee that sent none, and collapsing them would
|
|
318
|
+
* hide a real payment behind a parse error.
|
|
319
|
+
*/
|
|
320
|
+
private settlementClaimFrom;
|
|
321
|
+
createAgent(name: string, custodyMode: "tier0" | "tier1" | "noncustodial", payerAddress: string): Promise<string>;
|
|
322
|
+
setPolicy(agentId: string, capPerPaymentMinor: string, capPerDayMinor: string, velocityMaxPerHour: number): Promise<void>;
|
|
323
|
+
/**
|
|
324
|
+
* Stop an agent spending, immediately.
|
|
325
|
+
*
|
|
326
|
+
* ⚠️ THE RESPONSE IS CHECKED, WHICH IT PREVIOUSLY WAS NOT. This was one of only two methods
|
|
327
|
+
* with no `!r.ok` guard, so a freeze that failed — wrong scope, frozen account, network —
|
|
328
|
+
* returned silently as though it had worked. A kill switch that lies about having fired is
|
|
329
|
+
* worse than no kill switch, because it is believed.
|
|
330
|
+
*/
|
|
331
|
+
freeze(agentId: string, reason: string): Promise<void>;
|
|
332
|
+
/**
|
|
333
|
+
* Let a frozen agent spend again.
|
|
334
|
+
*
|
|
335
|
+
* The API has had this since the freeze primitive shipped — the two are generated by the same
|
|
336
|
+
* loop behind the same `policies:admin` scope. Only the SDK was missing it, which made freeze
|
|
337
|
+
* a one-way door for anyone who never dropped to raw HTTP.
|
|
338
|
+
*/
|
|
339
|
+
unfreeze(agentId: string, reason: string): Promise<void>;
|
|
340
|
+
/**
|
|
341
|
+
* This account's receipts, newest first.
|
|
342
|
+
*
|
|
343
|
+
* `finality` is Veyto's CURRENT belief about on-chain settlement and is deliberately NOT
|
|
344
|
+
* part of the signed body — it is knowledge acquired after the receipt was signed, and a
|
|
345
|
+
* signature cannot learn things. Verify `signed`; read `finality`.
|
|
346
|
+
*/
|
|
347
|
+
listReceipts(opts?: {
|
|
348
|
+
limit?: number;
|
|
349
|
+
before?: string;
|
|
350
|
+
}): Promise<ReceiptPage>;
|
|
351
|
+
/** One receipt. A receipt belonging to another account is indistinguishable from one that does not exist. */
|
|
352
|
+
getReceipt(receiptId: string): Promise<ReceiptRecord>;
|
|
353
|
+
/** What happened to one payment: status, submission, its receipt id, and current finality. */
|
|
354
|
+
getIntent(intentId: string): Promise<Record<string, unknown>>;
|
|
355
|
+
/** This account's agents, newest first. */
|
|
356
|
+
listAgents(opts?: {
|
|
357
|
+
limit?: number;
|
|
358
|
+
before?: string;
|
|
359
|
+
}): Promise<AgentPage>;
|
|
360
|
+
/** One agent, including whether it is frozen. Another account's agent looks like none at all. */
|
|
361
|
+
getAgent(agentId: string): Promise<AgentRecord>;
|
|
362
|
+
/**
|
|
363
|
+
* The policy governing an agent, and how much of it is left today.
|
|
364
|
+
*
|
|
365
|
+
* Requires `policies:read`, which is deliberately NOT implied by `policies:admin`-style
|
|
366
|
+
* write access nor by `agents:read`: checking your own headroom must not require the
|
|
367
|
+
* authority to raise your own ceiling.
|
|
368
|
+
*/
|
|
369
|
+
getPolicy(agentId: string): Promise<PolicyState>;
|
|
370
|
+
/**
|
|
371
|
+
* An agent's governed financial state: what Veyto recorded moving out (by finality), what is
|
|
372
|
+
* currently reserved, and the policy headroom — with an explicit statement of what is NOT
|
|
373
|
+
* reported.
|
|
374
|
+
*
|
|
375
|
+
* ⚠️ There is no balance here, and that is deliberate. Veyto's ledger records governed
|
|
376
|
+
* outflow, not funds held; for money actually available, read the payer address on chain.
|
|
377
|
+
* `governed_exposure.finalized_outflow_minor === null` means the figure CANNOT BE ANSWERED
|
|
378
|
+
* because a disputed entry exists — never treat it as zero.
|
|
379
|
+
*/
|
|
380
|
+
getWallet(agentId: string): Promise<WalletState>;
|
|
381
|
+
/**
|
|
382
|
+
* The decision history: what this account's agents attempted, and what Veyto decided.
|
|
383
|
+
*
|
|
384
|
+
* The answer to "why did my agent stop paying?" — which, before this existed, could not be
|
|
385
|
+
* asked at all: the intent route was POST-only and reading one record required an id you were
|
|
386
|
+
* never given a way to discover.
|
|
387
|
+
*
|
|
388
|
+
* ⚠️ A `reason` appears only where the record was DENIED by policy. Every other record reports
|
|
389
|
+
* `reason_not_recorded: "not_a_policy_denial"` instead, which asserts nothing about whether an
|
|
390
|
+
* evaluation occurred. No receipt or finality claim is implied by any status.
|
|
391
|
+
*/
|
|
392
|
+
listIntents(opts?: {
|
|
393
|
+
agentId?: string;
|
|
394
|
+
status?: IntentDecision["status"];
|
|
395
|
+
limit?: number;
|
|
396
|
+
before?: string;
|
|
397
|
+
}): Promise<IntentPage>;
|
|
398
|
+
}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
// Veyto TypeScript SDK. The whole point of M1: an agent developer calls
|
|
2
|
+
// `payingFetch(url)` and the governed flow happens invisibly —
|
|
3
|
+
// GET → 402 → authorize+sign via Veyto → attach payment → retry → report settle.
|
|
4
|
+
// Keys stay in Veyto; the developer never touches a wallet. `fetchImpl` is
|
|
5
|
+
// injectable so the flow is testable without a network.
|
|
6
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
7
|
+
import { encodePayment } from "@veyto/x402-wire";
|
|
8
|
+
/**
|
|
9
|
+
* A read that the server refused. `status` is preserved so a caller can tell a missing scope
|
|
10
|
+
* (403) from a bad key (401) from a receipt that is not theirs (404).
|
|
11
|
+
*
|
|
12
|
+
* ⚠️ 404 remains deliberately ambiguous: the API does not distinguish "no such receipt" from
|
|
13
|
+
* "not yours", because a 403 there would confirm to an enumerating caller that an id is real.
|
|
14
|
+
* The SDK preserves that ambiguity rather than trying to be helpful about it.
|
|
15
|
+
*/
|
|
16
|
+
export class VeytoReadError extends Error {
|
|
17
|
+
status;
|
|
18
|
+
constructor(status, operation) {
|
|
19
|
+
super(`${operation} failed: ${status}`);
|
|
20
|
+
this.status = status;
|
|
21
|
+
this.name = "VeytoReadError";
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export class VeytoDeniedError extends Error {
|
|
25
|
+
reason;
|
|
26
|
+
constructor(reason) {
|
|
27
|
+
super(`payment denied by policy: ${reason}`);
|
|
28
|
+
this.reason = reason;
|
|
29
|
+
this.name = "VeytoDeniedError";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// x402 V2 header names as observed on the wire in the G0a S1 spike.
|
|
33
|
+
const REQUIREMENTS_HEADER = "payment-required";
|
|
34
|
+
const PAYMENT_HEADER = "payment-signature";
|
|
35
|
+
const SETTLEMENT_HEADER = "payment-response";
|
|
36
|
+
export class VeytoClient {
|
|
37
|
+
cfg;
|
|
38
|
+
constructor(cfg) {
|
|
39
|
+
this.cfg = cfg;
|
|
40
|
+
}
|
|
41
|
+
get f() {
|
|
42
|
+
return this.cfg.fetchImpl ?? fetch;
|
|
43
|
+
}
|
|
44
|
+
authHeaders() {
|
|
45
|
+
// extraHeaders first so the SDK's own auth/content-type always win: a typo'd
|
|
46
|
+
// "authorization" in extraHeaders must not silently replace the API key.
|
|
47
|
+
return {
|
|
48
|
+
...(this.cfg.extraHeaders ?? {}),
|
|
49
|
+
authorization: `Bearer ${this.cfg.apiKey}`,
|
|
50
|
+
"content-type": "application/json",
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
// The governed paying fetch. Returns the resource's final Response. Throws
|
|
54
|
+
// VeytoDeniedError if policy blocks the payment (the caller's spend cap did its
|
|
55
|
+
// job); other failures surface as thrown errors or the resource's own status.
|
|
56
|
+
async payingFetch(url, init) {
|
|
57
|
+
const f = this.f;
|
|
58
|
+
const first = await f(url, init);
|
|
59
|
+
if (first.status !== 402)
|
|
60
|
+
return first; // not paywalled — nothing to govern
|
|
61
|
+
const requirementsB64 = first.headers.get(REQUIREMENTS_HEADER);
|
|
62
|
+
if (!requirementsB64)
|
|
63
|
+
throw new Error("402 response missing payment-required header");
|
|
64
|
+
// authorize + sign through Veyto (idempotency key makes retries safe)
|
|
65
|
+
const idempotencyKey = randomUUID();
|
|
66
|
+
const payRes = await f(`${this.cfg.baseUrl}/v1/pay`, {
|
|
67
|
+
method: "POST",
|
|
68
|
+
headers: this.authHeaders(),
|
|
69
|
+
body: JSON.stringify({
|
|
70
|
+
agent_id: this.cfg.agentId,
|
|
71
|
+
rail: this.cfg.rail,
|
|
72
|
+
currency: this.cfg.currency,
|
|
73
|
+
requirements_b64: requirementsB64,
|
|
74
|
+
idempotency_key: idempotencyKey,
|
|
75
|
+
// ADR-0020: why this spend happened, declared at authorization time and
|
|
76
|
+
// signed into the receipt. Cannot be reconstructed afterwards.
|
|
77
|
+
...(this.cfg.purpose ? { purpose: this.cfg.purpose } : {}),
|
|
78
|
+
}),
|
|
79
|
+
});
|
|
80
|
+
const pay = (await payRes.json());
|
|
81
|
+
if (pay.status === "denied")
|
|
82
|
+
throw new VeytoDeniedError(pay.reason ?? "unknown");
|
|
83
|
+
// A non-2xx from /v1/pay carries {error}, not {status}, so reading `status` gave
|
|
84
|
+
// `unexpected /v1/pay result: undefined` — which is what a developer saw when their
|
|
85
|
+
// agent was FROZEN. The refusal is the most important thing Veyto ever says; it
|
|
86
|
+
// must not arrive unreadable. Surfaced as a denial with the API's own reason.
|
|
87
|
+
if (!payRes.ok) {
|
|
88
|
+
const reason = pay.error ?? `HTTP ${payRes.status}`;
|
|
89
|
+
throw new VeytoDeniedError(reason);
|
|
90
|
+
}
|
|
91
|
+
if (!pay.intentId)
|
|
92
|
+
throw new Error(`unexpected /v1/pay result: ${pay.status}`);
|
|
93
|
+
// Resolve to a payment header + the ACTUAL amount/payee being paid — uniform
|
|
94
|
+
// across custodial (Veyto signed) and non-custodial (developer signs locally).
|
|
95
|
+
let paymentHeader;
|
|
96
|
+
let actualAmount;
|
|
97
|
+
let actualPayee;
|
|
98
|
+
if (pay.status === "approved_signed" && pay.paymentHeader) {
|
|
99
|
+
paymentHeader = pay.paymentHeader;
|
|
100
|
+
const a = this.decodePayment(paymentHeader).payload.authorization;
|
|
101
|
+
actualAmount = a.value;
|
|
102
|
+
actualPayee = a.to;
|
|
103
|
+
}
|
|
104
|
+
else if (pay.status === "approved_unsigned" && pay.eip3009 && pay.accepted && pay.resource) {
|
|
105
|
+
if (!this.cfg.sign) {
|
|
106
|
+
throw new Error("this agent is non-custodial; configure a `sign` callback (e.g. localSigner(pk))");
|
|
107
|
+
}
|
|
108
|
+
const { domain, fields } = pay.eip3009;
|
|
109
|
+
const signature = await this.cfg.sign(domain, fields);
|
|
110
|
+
const payload = {
|
|
111
|
+
x402Version: 2,
|
|
112
|
+
payload: { authorization: { ...fields }, signature },
|
|
113
|
+
resource: pay.resource,
|
|
114
|
+
accepted: pay.accepted,
|
|
115
|
+
};
|
|
116
|
+
paymentHeader = encodePayment(payload);
|
|
117
|
+
actualAmount = fields.value; // what the developer actually signed
|
|
118
|
+
actualPayee = fields.to;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
throw new Error(`unexpected /v1/pay result: ${pay.status}`);
|
|
122
|
+
}
|
|
123
|
+
// retry the resource request with the payment attached
|
|
124
|
+
const retryHeaders = new Headers(init?.headers);
|
|
125
|
+
retryHeaders.set(PAYMENT_HEADER, paymentHeader);
|
|
126
|
+
const paid = await f(url, { ...init, headers: retryHeaders });
|
|
127
|
+
// ── Report the outcome. Two INDEPENDENT dimensions, never collapsed ──────────
|
|
128
|
+
//
|
|
129
|
+
// The resource's HTTP status is an APPLICATION outcome the buyer observed. It says
|
|
130
|
+
// nothing about whether value moved. Once a signed EIP-3009 authorization has left
|
|
131
|
+
// this process it is a bearer credential the payee can settle until `validBefore`,
|
|
132
|
+
// so "the request failed" NEVER licenses "no payment occurred".
|
|
133
|
+
//
|
|
134
|
+
// Reporting `failed` on a non-2xx — which this did until 2026-08-16 — told Veyto
|
|
135
|
+
// "no value moved". The API then released the hold and marked the submission
|
|
136
|
+
// failed, and because the reconciler scans only settled/uncertain submissions, a
|
|
137
|
+
// real on-chain payment became invisible to reconciliation permanently. The
|
|
138
|
+
// settlement header, the one piece of proof, was discarded in exactly the case
|
|
139
|
+
// where it was the evidence.
|
|
140
|
+
//
|
|
141
|
+
// The settlement header is read ALWAYS, and is a PAYEE CLAIM — not verification.
|
|
142
|
+
// Only the reconciler's chain read can establish that value moved.
|
|
143
|
+
const settlementClaim = this.settlementClaimFrom(paid.headers.get(SETTLEMENT_HEADER));
|
|
144
|
+
// A claim only counts as PROOF if it actually asserts success and carries something
|
|
145
|
+
// shaped like a transaction hash. A payee explicitly saying `success:false`, or
|
|
146
|
+
// sending garbage where the hash goes, must not be read as "money moved" — that
|
|
147
|
+
// would be a false money-moved claim, the opposite failure to the one being fixed.
|
|
148
|
+
const txHash = settlementClaim.success === false ? undefined : settlementClaim.transaction;
|
|
149
|
+
const outcome = paid.ok ? "settled" : txHash ? "denied_after_payment" : "uncertain";
|
|
150
|
+
// 2xx + claim → settled (delivery observed, payee claims settled)
|
|
151
|
+
// 2xx + none → settled, no hash (delivery observed; nothing to reconcile)
|
|
152
|
+
// !2xx + claim → denied_after_payment (value moved per payee; request denied)
|
|
153
|
+
// !2xx + none → uncertain (UNKNOWN — the hold stays, per A9.2/SECURITY-MODEL:
|
|
154
|
+
// only reconciliation releases uncertain holds)
|
|
155
|
+
// `failed` is never reported from here: this code cannot establish that no value moved.
|
|
156
|
+
// Optionally attest WHAT arrived. Off by default: hashing means buffering the
|
|
157
|
+
// whole body, which doubles memory for a large download and silently changes
|
|
158
|
+
// behavior for existing callers. The response is CLONED so the caller still
|
|
159
|
+
// gets an unread stream. Best-effort — a hashing failure must never break a
|
|
160
|
+
// payment that already succeeded.
|
|
161
|
+
let goodsDigest;
|
|
162
|
+
if (this.cfg.attestGoods && paid.ok) {
|
|
163
|
+
try {
|
|
164
|
+
const bytes = new Uint8Array(await paid.clone().arrayBuffer());
|
|
165
|
+
goodsDigest = createHash("sha256").update(bytes).digest("hex");
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
goodsDigest = undefined;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
await f(`${this.cfg.baseUrl}/v1/pay/${pay.intentId}/settle`, {
|
|
172
|
+
method: "POST",
|
|
173
|
+
headers: this.authHeaders(),
|
|
174
|
+
body: JSON.stringify({
|
|
175
|
+
outcome, tx_hash: txHash, actual_amount_minor: actualAmount, actual_payee: actualPayee,
|
|
176
|
+
...(goodsDigest ? { goods_digest_sha256: goodsDigest } : {}),
|
|
177
|
+
// The exchange, captured as evidence (RAIL-ADAPTER-CONTRACT walkthrough #2).
|
|
178
|
+
// Bounded scalars with explicit provenance — never the bearer payment payload.
|
|
179
|
+
evidence: {
|
|
180
|
+
resource_status: paid.status,
|
|
181
|
+
resource_status_basis: "buyer_observed_http_status",
|
|
182
|
+
settlement_claim_present: settlementClaim.present,
|
|
183
|
+
settlement_claim_parsed: settlementClaim.parsed,
|
|
184
|
+
settlement_claim_success: settlementClaim.success,
|
|
185
|
+
settlement_claim_network: settlementClaim.network,
|
|
186
|
+
settlement_claim_basis: "payee_response_header_unverified",
|
|
187
|
+
},
|
|
188
|
+
}),
|
|
189
|
+
}).catch(() => undefined);
|
|
190
|
+
return paid;
|
|
191
|
+
}
|
|
192
|
+
decodePayment(headerB64) {
|
|
193
|
+
return JSON.parse(Buffer.from(headerB64, "base64").toString("utf8"));
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Parse the payee's settlement response header.
|
|
197
|
+
*
|
|
198
|
+
* Distinguishes ABSENT from MALFORMED: a genuine settlement whose header failed to
|
|
199
|
+
* parse is not the same fact as a payee that sent none, and collapsing them would
|
|
200
|
+
* hide a real payment behind a parse error.
|
|
201
|
+
*/
|
|
202
|
+
settlementClaimFrom(header) {
|
|
203
|
+
if (!header)
|
|
204
|
+
return { present: false, parsed: false, transaction: undefined, success: undefined, network: undefined };
|
|
205
|
+
try {
|
|
206
|
+
const d = JSON.parse(Buffer.from(header, "base64").toString("utf8"));
|
|
207
|
+
return {
|
|
208
|
+
present: true,
|
|
209
|
+
parsed: true,
|
|
210
|
+
// A hash is only useful to reconciliation if it is structurally a hash.
|
|
211
|
+
// Structurally a hash, or no hash at all. A malformed value handed to the
|
|
212
|
+
// reconciler becomes a terminal `not_found` against a payment that may be real.
|
|
213
|
+
transaction: typeof d.transaction === "string" && /^0x[0-9a-fA-F]{64}$/.test(d.transaction) ? d.transaction : undefined,
|
|
214
|
+
success: typeof d.success === "boolean" ? d.success : undefined,
|
|
215
|
+
network: typeof d.network === "string" ? d.network : undefined,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
return { present: true, parsed: false, transaction: undefined, success: undefined, network: undefined };
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
// ── convenience admin helpers (used by the quickstart) ──
|
|
223
|
+
async createAgent(name, custodyMode, payerAddress) {
|
|
224
|
+
const r = await this.f(`${this.cfg.baseUrl}/v1/agents`, {
|
|
225
|
+
method: "POST",
|
|
226
|
+
headers: this.authHeaders(),
|
|
227
|
+
body: JSON.stringify({ name, custody_mode: custodyMode, payer_address: payerAddress, currency: this.cfg.currency }),
|
|
228
|
+
});
|
|
229
|
+
if (!r.ok)
|
|
230
|
+
throw new Error(`createAgent failed: ${r.status}`);
|
|
231
|
+
return (await r.json()).id;
|
|
232
|
+
}
|
|
233
|
+
async setPolicy(agentId, capPerPaymentMinor, capPerDayMinor, velocityMaxPerHour) {
|
|
234
|
+
const r = await this.f(`${this.cfg.baseUrl}/v1/agents/${agentId}/policy`, {
|
|
235
|
+
method: "PUT",
|
|
236
|
+
headers: this.authHeaders(),
|
|
237
|
+
body: JSON.stringify({ cap_per_payment_minor: capPerPaymentMinor, cap_per_day_minor: capPerDayMinor, velocity_max_per_hour: velocityMaxPerHour }),
|
|
238
|
+
});
|
|
239
|
+
if (!r.ok)
|
|
240
|
+
throw new Error(`setPolicy failed: ${r.status}`);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Stop an agent spending, immediately.
|
|
244
|
+
*
|
|
245
|
+
* ⚠️ THE RESPONSE IS CHECKED, WHICH IT PREVIOUSLY WAS NOT. This was one of only two methods
|
|
246
|
+
* with no `!r.ok` guard, so a freeze that failed — wrong scope, frozen account, network —
|
|
247
|
+
* returned silently as though it had worked. A kill switch that lies about having fired is
|
|
248
|
+
* worse than no kill switch, because it is believed.
|
|
249
|
+
*/
|
|
250
|
+
async freeze(agentId, reason) {
|
|
251
|
+
const r = await this.f(`${this.cfg.baseUrl}/v1/agents/${agentId}/freeze`, {
|
|
252
|
+
method: "POST",
|
|
253
|
+
headers: this.authHeaders(),
|
|
254
|
+
body: JSON.stringify({ reason }),
|
|
255
|
+
});
|
|
256
|
+
if (!r.ok)
|
|
257
|
+
throw new VeytoReadError(r.status, "freeze");
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Let a frozen agent spend again.
|
|
261
|
+
*
|
|
262
|
+
* The API has had this since the freeze primitive shipped — the two are generated by the same
|
|
263
|
+
* loop behind the same `policies:admin` scope. Only the SDK was missing it, which made freeze
|
|
264
|
+
* a one-way door for anyone who never dropped to raw HTTP.
|
|
265
|
+
*/
|
|
266
|
+
async unfreeze(agentId, reason) {
|
|
267
|
+
const r = await this.f(`${this.cfg.baseUrl}/v1/agents/${agentId}/unfreeze`, {
|
|
268
|
+
method: "POST",
|
|
269
|
+
headers: this.authHeaders(),
|
|
270
|
+
body: JSON.stringify({ reason }),
|
|
271
|
+
});
|
|
272
|
+
if (!r.ok)
|
|
273
|
+
throw new VeytoReadError(r.status, "unfreeze");
|
|
274
|
+
}
|
|
275
|
+
// ── evidence: reading back what was signed ──
|
|
276
|
+
//
|
|
277
|
+
// A receipt you cannot fetch is not evidence, it is a log line we kept. These return the
|
|
278
|
+
// signed bytes VERBATIM so `verifyReceipt` can be run over them — by you, by your auditor,
|
|
279
|
+
// or by a counterparty who does not trust us and should not have to.
|
|
280
|
+
/**
|
|
281
|
+
* This account's receipts, newest first.
|
|
282
|
+
*
|
|
283
|
+
* `finality` is Veyto's CURRENT belief about on-chain settlement and is deliberately NOT
|
|
284
|
+
* part of the signed body — it is knowledge acquired after the receipt was signed, and a
|
|
285
|
+
* signature cannot learn things. Verify `signed`; read `finality`.
|
|
286
|
+
*/
|
|
287
|
+
async listReceipts(opts = {}) {
|
|
288
|
+
const q = new URLSearchParams();
|
|
289
|
+
if (opts.limit !== undefined)
|
|
290
|
+
q.set("limit", String(opts.limit));
|
|
291
|
+
if (opts.before !== undefined)
|
|
292
|
+
q.set("before", opts.before);
|
|
293
|
+
const qs = q.toString();
|
|
294
|
+
const r = await this.f(`${this.cfg.baseUrl}/v1/receipts${qs ? `?${qs}` : ""}`, { headers: this.authHeaders() });
|
|
295
|
+
if (!r.ok)
|
|
296
|
+
throw new VeytoReadError(r.status, "listReceipts");
|
|
297
|
+
return (await r.json());
|
|
298
|
+
}
|
|
299
|
+
/** One receipt. A receipt belonging to another account is indistinguishable from one that does not exist. */
|
|
300
|
+
async getReceipt(receiptId) {
|
|
301
|
+
const r = await this.f(`${this.cfg.baseUrl}/v1/receipts/${receiptId}`, { headers: this.authHeaders() });
|
|
302
|
+
if (!r.ok)
|
|
303
|
+
throw new VeytoReadError(r.status, "getReceipt");
|
|
304
|
+
return (await r.json());
|
|
305
|
+
}
|
|
306
|
+
/** What happened to one payment: status, submission, its receipt id, and current finality. */
|
|
307
|
+
async getIntent(intentId) {
|
|
308
|
+
const r = await this.f(`${this.cfg.baseUrl}/v1/intents/${intentId}`, { headers: this.authHeaders() });
|
|
309
|
+
if (!r.ok)
|
|
310
|
+
throw new VeytoReadError(r.status, "getIntent");
|
|
311
|
+
return (await r.json());
|
|
312
|
+
}
|
|
313
|
+
// ── guardrails: reading the rules you are governed by ──
|
|
314
|
+
//
|
|
315
|
+
// Being governed by a cap you cannot read is the same problem as holding a receipt you
|
|
316
|
+
// cannot fetch. These answer "what am I allowed to spend, and how much of it is left"
|
|
317
|
+
// WITHOUT needing the authority to change the answer.
|
|
318
|
+
/** This account's agents, newest first. */
|
|
319
|
+
async listAgents(opts = {}) {
|
|
320
|
+
const q = new URLSearchParams();
|
|
321
|
+
if (opts.limit !== undefined)
|
|
322
|
+
q.set("limit", String(opts.limit));
|
|
323
|
+
if (opts.before !== undefined)
|
|
324
|
+
q.set("before", opts.before);
|
|
325
|
+
const qs = q.toString();
|
|
326
|
+
const r = await this.f(`${this.cfg.baseUrl}/v1/agents${qs ? `?${qs}` : ""}`, { headers: this.authHeaders() });
|
|
327
|
+
if (!r.ok)
|
|
328
|
+
throw new VeytoReadError(r.status, "listAgents");
|
|
329
|
+
return (await r.json());
|
|
330
|
+
}
|
|
331
|
+
/** One agent, including whether it is frozen. Another account's agent looks like none at all. */
|
|
332
|
+
async getAgent(agentId) {
|
|
333
|
+
const r = await this.f(`${this.cfg.baseUrl}/v1/agents/${agentId}`, { headers: this.authHeaders() });
|
|
334
|
+
if (!r.ok)
|
|
335
|
+
throw new VeytoReadError(r.status, "getAgent");
|
|
336
|
+
return (await r.json());
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* The policy governing an agent, and how much of it is left today.
|
|
340
|
+
*
|
|
341
|
+
* Requires `policies:read`, which is deliberately NOT implied by `policies:admin`-style
|
|
342
|
+
* write access nor by `agents:read`: checking your own headroom must not require the
|
|
343
|
+
* authority to raise your own ceiling.
|
|
344
|
+
*/
|
|
345
|
+
async getPolicy(agentId) {
|
|
346
|
+
const r = await this.f(`${this.cfg.baseUrl}/v1/agents/${agentId}/policy`, { headers: this.authHeaders() });
|
|
347
|
+
if (!r.ok)
|
|
348
|
+
throw new VeytoReadError(r.status, "getPolicy");
|
|
349
|
+
return (await r.json());
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* An agent's governed financial state: what Veyto recorded moving out (by finality), what is
|
|
353
|
+
* currently reserved, and the policy headroom — with an explicit statement of what is NOT
|
|
354
|
+
* reported.
|
|
355
|
+
*
|
|
356
|
+
* ⚠️ There is no balance here, and that is deliberate. Veyto's ledger records governed
|
|
357
|
+
* outflow, not funds held; for money actually available, read the payer address on chain.
|
|
358
|
+
* `governed_exposure.finalized_outflow_minor === null` means the figure CANNOT BE ANSWERED
|
|
359
|
+
* because a disputed entry exists — never treat it as zero.
|
|
360
|
+
*/
|
|
361
|
+
async getWallet(agentId) {
|
|
362
|
+
const r = await this.f(`${this.cfg.baseUrl}/v1/agents/${agentId}/wallet`, { headers: this.authHeaders() });
|
|
363
|
+
if (!r.ok)
|
|
364
|
+
throw new VeytoReadError(r.status, "getWallet");
|
|
365
|
+
return (await r.json());
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* The decision history: what this account's agents attempted, and what Veyto decided.
|
|
369
|
+
*
|
|
370
|
+
* The answer to "why did my agent stop paying?" — which, before this existed, could not be
|
|
371
|
+
* asked at all: the intent route was POST-only and reading one record required an id you were
|
|
372
|
+
* never given a way to discover.
|
|
373
|
+
*
|
|
374
|
+
* ⚠️ A `reason` appears only where the record was DENIED by policy. Every other record reports
|
|
375
|
+
* `reason_not_recorded: "not_a_policy_denial"` instead, which asserts nothing about whether an
|
|
376
|
+
* evaluation occurred. No receipt or finality claim is implied by any status.
|
|
377
|
+
*/
|
|
378
|
+
async listIntents(opts = {}) {
|
|
379
|
+
const q = new URLSearchParams();
|
|
380
|
+
if (opts.status !== undefined)
|
|
381
|
+
q.set("status", opts.status);
|
|
382
|
+
if (opts.limit !== undefined)
|
|
383
|
+
q.set("limit", String(opts.limit));
|
|
384
|
+
if (opts.before !== undefined)
|
|
385
|
+
q.set("before", opts.before);
|
|
386
|
+
const path = opts.agentId ? `/v1/agents/${opts.agentId}/intents` : "/v1/intents";
|
|
387
|
+
const qs = q.toString();
|
|
388
|
+
const r = await this.f(`${this.cfg.baseUrl}${path}${qs ? `?${qs}` : ""}`, {
|
|
389
|
+
headers: this.authHeaders(),
|
|
390
|
+
});
|
|
391
|
+
if (!r.ok)
|
|
392
|
+
throw new VeytoReadError(r.status, "listIntents");
|
|
393
|
+
return (await r.json());
|
|
394
|
+
}
|
|
395
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { VeytoClient, VeytoDeniedError, VeytoReadError, type VeytoClientConfig, type ReceiptRecord, type ReceiptPage, type AgentRecord, type AgentPage, type PolicyInForce, type SpendState, type PolicyState, type WalletState, type GovernedExposure, type Reservations, type WalletPolicyHeadroom, type NotReported, type IntentRecord, type IntentAttempt, type IntentDecision, type IntentEvidence, type IntentPage } from "./client.js";
|
|
2
|
+
export { localSigner, type SignCallback } from "./localSigner.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Non-custodial signing helpers. A `SignCallback` decouples signing from key
|
|
2
|
+
// management, so the SDK works with a raw key, a viem account, an external wallet,
|
|
3
|
+
// or a customer KMS. `localSigner` is the simple raw-key case. Keys stay in the
|
|
4
|
+
// developer's process; Veyto never sees them.
|
|
5
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
6
|
+
const EIP3009_TYPES = {
|
|
7
|
+
TransferWithAuthorization: [
|
|
8
|
+
{ name: "from", type: "address" },
|
|
9
|
+
{ name: "to", type: "address" },
|
|
10
|
+
{ name: "value", type: "uint256" },
|
|
11
|
+
{ name: "validAfter", type: "uint256" },
|
|
12
|
+
{ name: "validBefore", type: "uint256" },
|
|
13
|
+
{ name: "nonce", type: "bytes32" },
|
|
14
|
+
],
|
|
15
|
+
};
|
|
16
|
+
export function localSigner(privateKey) {
|
|
17
|
+
const account = privateKeyToAccount(privateKey);
|
|
18
|
+
return async (domain, fields) => account.signTypedData({
|
|
19
|
+
domain,
|
|
20
|
+
types: EIP3009_TYPES,
|
|
21
|
+
primaryType: "TransferWithAuthorization",
|
|
22
|
+
message: {
|
|
23
|
+
from: fields.from,
|
|
24
|
+
to: fields.to,
|
|
25
|
+
value: BigInt(fields.value),
|
|
26
|
+
validAfter: BigInt(fields.validAfter),
|
|
27
|
+
validBefore: BigInt(fields.validBefore),
|
|
28
|
+
nonce: fields.nonce,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@veyto/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"viem": "^2.55.0",
|
|
9
|
+
"@veyto/x402-wire": "0.1.0"
|
|
10
|
+
},
|
|
11
|
+
"license": "Apache-2.0",
|
|
12
|
+
"description": "Veyto TypeScript SDK — give an AI agent a wallet with enforceable spending rules.",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
17
|
+
"homepage": "https://docs.veyto.io",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"email": "sandbox@veyto.io"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"x402",
|
|
23
|
+
"agent",
|
|
24
|
+
"payments",
|
|
25
|
+
"eip-3009",
|
|
26
|
+
"base",
|
|
27
|
+
"usdc",
|
|
28
|
+
"spending-limits"
|
|
29
|
+
],
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": ">=20"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc -p tsconfig.json",
|
|
35
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
36
|
+
"test": "vitest run --passWithNoTests"
|
|
37
|
+
}
|
|
38
|
+
}
|