@vantic/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 +42 -0
- package/dist/adapters.d.ts +66 -0
- package/dist/adapters.d.ts.map +1 -0
- package/dist/adapters.js +67 -0
- package/dist/adapters.js.map +1 -0
- package/dist/credential.d.ts +51 -0
- package/dist/credential.d.ts.map +1 -0
- package/dist/credential.js +78 -0
- package/dist/credential.js.map +1 -0
- package/dist/crypto.d.ts +27 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +103 -0
- package/dist/crypto.js.map +1 -0
- package/dist/did.d.ts +54 -0
- package/dist/did.d.ts.map +1 -0
- package/dist/did.js +152 -0
- package/dist/did.js.map +1 -0
- package/dist/envelope.d.ts +23 -0
- package/dist/envelope.d.ts.map +1 -0
- package/dist/envelope.js +31 -0
- package/dist/envelope.js.map +1 -0
- package/dist/gate.d.ts +48 -0
- package/dist/gate.d.ts.map +1 -0
- package/dist/gate.js +46 -0
- package/dist/gate.js.map +1 -0
- package/dist/guard.d.ts +53 -0
- package/dist/guard.d.ts.map +1 -0
- package/dist/guard.js +76 -0
- package/dist/guard.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-server.d.ts +23 -0
- package/dist/mcp-server.d.ts.map +1 -0
- package/dist/mcp-server.js +141 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/mcp.d.ts +3 -0
- package/dist/mcp.d.ts.map +1 -0
- package/dist/mcp.js +5 -0
- package/dist/mcp.js.map +1 -0
- package/dist/receipt.d.ts +24 -0
- package/dist/receipt.d.ts.map +1 -0
- package/dist/receipt.js +41 -0
- package/dist/receipt.js.map +1 -0
- package/dist/revocation.d.ts +23 -0
- package/dist/revocation.d.ts.map +1 -0
- package/dist/revocation.js +30 -0
- package/dist/revocation.js.map +1 -0
- package/dist/types.d.ts +98 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/verify.d.ts +24 -0
- package/dist/verify.d.ts.map +1 -0
- package/dist/verify.js +124 -0
- package/dist/verify.js.map +1 -0
- package/package.json +39 -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,42 @@
|
|
|
1
|
+
# @vantic/sdk
|
|
2
|
+
|
|
3
|
+
Signed mandates and receipt chains for autonomous agent transactions — and a
|
|
4
|
+
client-side spending firewall so your agent can't be prompt-injected into paying an attacker.
|
|
5
|
+
|
|
6
|
+
Zero runtime dependencies (Node ≥ 18 built-in crypto). Ed25519 + SHA-256 + canonical JSON,
|
|
7
|
+
with `did:key`/`did:web` identity and W3C Verifiable Credentials for the sponsor chain.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @vantic/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { generateKeyPair, issueMandate, AgentWallet } from "@vantic/sdk";
|
|
15
|
+
|
|
16
|
+
const principal = generateKeyPair();
|
|
17
|
+
const agent = generateKeyPair();
|
|
18
|
+
|
|
19
|
+
const mandate = issueMandate({
|
|
20
|
+
agent: agent.publicKey,
|
|
21
|
+
principal: principal.publicKey,
|
|
22
|
+
principalPrivateKeyPem: principal.privateKeyPem,
|
|
23
|
+
ttlSeconds: 7 * 24 * 3600,
|
|
24
|
+
scope: {
|
|
25
|
+
budget: { currency: "USD", amount: 50000, windowSeconds: 7 * 24 * 3600 }, // $500 / 7d
|
|
26
|
+
maxPerTransaction: 20000,
|
|
27
|
+
allowedActions: ["purchase"],
|
|
28
|
+
allowedCounterparties: ["etsy.com", "*.shop.example"],
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Wrap your agent's spend calls. A blocked action throws BEFORE any money moves.
|
|
33
|
+
const wallet = new AgentWallet(mandate, agent.privateKeyPem);
|
|
34
|
+
await wallet.spend(
|
|
35
|
+
{ type: "purchase", counterparty: "etsy.com", amount: 4500, currency: "USD" },
|
|
36
|
+
async (a) => ({ outcome: "settled", result: await pay(a) }),
|
|
37
|
+
);
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Also ships as an MCP server (`npx vantic-mcp`) exposing stateless verification tools.
|
|
41
|
+
|
|
42
|
+
Full docs, protocol spec, and demos: see the repository. Apache-2.0.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework adapters — drop Vantic into an existing agent with one wrap, not a rewrite.
|
|
3
|
+
*
|
|
4
|
+
* Agent frameworks (MCP, LangChain, OpenAI function-calling) all expose "tools": functions
|
|
5
|
+
* the model invokes with JSON args that produce a side effect. `guardTool` wraps any such
|
|
6
|
+
* money-moving tool so every call flows through the AgentWallet firewall automatically.
|
|
7
|
+
* `wrapMcpTool` is the MCP-shaped convenience: a blocked call returns a structured tool
|
|
8
|
+
* error the model can read and reason about, and — critically — the underlying side effect
|
|
9
|
+
* never runs.
|
|
10
|
+
*/
|
|
11
|
+
import { AgentWallet } from "./guard.js";
|
|
12
|
+
import type { Action, Outcome, Receipt } from "./types.js";
|
|
13
|
+
export type GuardedToolResponse<T> = {
|
|
14
|
+
ok: true;
|
|
15
|
+
receipt: Receipt;
|
|
16
|
+
result?: T;
|
|
17
|
+
} | {
|
|
18
|
+
ok: false;
|
|
19
|
+
blocked: true;
|
|
20
|
+
reasons: string[];
|
|
21
|
+
};
|
|
22
|
+
export interface GuardToolOptions<Args, T> {
|
|
23
|
+
wallet: AgentWallet;
|
|
24
|
+
/** Map the tool's call arguments to a Vantic Action (type/counterparty/amount/currency). */
|
|
25
|
+
toAction: (args: Args) => Action;
|
|
26
|
+
/** The real side effect (charge card, submit x402, call purchase API). Runs only if authorized. */
|
|
27
|
+
execute: (args: Args) => Promise<{
|
|
28
|
+
outcome: Outcome;
|
|
29
|
+
result?: T;
|
|
30
|
+
}> | {
|
|
31
|
+
outcome: Outcome;
|
|
32
|
+
result?: T;
|
|
33
|
+
};
|
|
34
|
+
/** Throw GuardViolation on block instead of returning a structured denial. Default: false. */
|
|
35
|
+
throwOnBlock?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Wrap a money-moving tool handler so it is gated by the wallet. The returned function has
|
|
39
|
+
* the same call shape; on a blocked action `execute` is never called and no money moves.
|
|
40
|
+
*/
|
|
41
|
+
export declare function guardTool<Args, T>(opts: GuardToolOptions<Args, T>): (args: Args) => Promise<GuardedToolResponse<T>>;
|
|
42
|
+
export interface McpToolResult {
|
|
43
|
+
content: Array<{
|
|
44
|
+
type: "text";
|
|
45
|
+
text: string;
|
|
46
|
+
}>;
|
|
47
|
+
isError?: boolean;
|
|
48
|
+
}
|
|
49
|
+
export interface McpTool {
|
|
50
|
+
name: string;
|
|
51
|
+
description?: string;
|
|
52
|
+
inputSchema: Record<string, unknown>;
|
|
53
|
+
handler: (args: any) => Promise<McpToolResult> | McpToolResult;
|
|
54
|
+
}
|
|
55
|
+
export interface WrapMcpOptions {
|
|
56
|
+
wallet: AgentWallet;
|
|
57
|
+
/** Map the MCP tool's arguments to a Vantic Action. */
|
|
58
|
+
toAction: (args: any) => Action;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Wrap an MCP tool definition so its handler is guarded by the wallet. A blocked call
|
|
62
|
+
* returns `{ isError: true }` with a readable reason (the model sees it and can adjust);
|
|
63
|
+
* the wrapped tool's original handler runs only when the action is authorized.
|
|
64
|
+
*/
|
|
65
|
+
export declare function wrapMcpTool(tool: McpTool, opts: WrapMcpOptions): McpTool;
|
|
66
|
+
//# sourceMappingURL=adapters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapters.d.ts","sourceRoot":"","sources":["../src/adapters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,WAAW,EAAkB,MAAM,YAAY,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAE3D,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAC7B;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,CAAC,CAAA;CAAE,GAC1C;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAEpD,MAAM,WAAW,gBAAgB,CAAC,IAAI,EAAE,CAAC;IACvC,MAAM,EAAE,WAAW,CAAC;IACpB,4FAA4F;IAC5F,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC;IACjC,mGAAmG;IACnG,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,CAAC,CAAA;KAAE,CAAC,GAAG;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,MAAM,CAAC,EAAE,CAAC,CAAA;KAAE,CAAC;IACtG,8FAA8F;IAC9F,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,gBAAgB,CAAC,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAcnH;AAGD,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACrC,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,OAAO,CAAC,aAAa,CAAC,GAAG,aAAa,CAAC;CAChE;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,WAAW,CAAC;IACpB,uDAAuD;IACvD,QAAQ,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,MAAM,CAAC;CACjC;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO,CA6BxE"}
|
package/dist/adapters.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework adapters — drop Vantic into an existing agent with one wrap, not a rewrite.
|
|
3
|
+
*
|
|
4
|
+
* Agent frameworks (MCP, LangChain, OpenAI function-calling) all expose "tools": functions
|
|
5
|
+
* the model invokes with JSON args that produce a side effect. `guardTool` wraps any such
|
|
6
|
+
* money-moving tool so every call flows through the AgentWallet firewall automatically.
|
|
7
|
+
* `wrapMcpTool` is the MCP-shaped convenience: a blocked call returns a structured tool
|
|
8
|
+
* error the model can read and reason about, and — critically — the underlying side effect
|
|
9
|
+
* never runs.
|
|
10
|
+
*/
|
|
11
|
+
import { GuardViolation } from "./guard.js";
|
|
12
|
+
/**
|
|
13
|
+
* Wrap a money-moving tool handler so it is gated by the wallet. The returned function has
|
|
14
|
+
* the same call shape; on a blocked action `execute` is never called and no money moves.
|
|
15
|
+
*/
|
|
16
|
+
export function guardTool(opts) {
|
|
17
|
+
return async (args) => {
|
|
18
|
+
const action = opts.toAction(args);
|
|
19
|
+
try {
|
|
20
|
+
const { receipt, result } = await opts.wallet.spend(action, () => opts.execute(args));
|
|
21
|
+
return { ok: true, receipt, result };
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
if (e instanceof GuardViolation) {
|
|
25
|
+
if (opts.throwOnBlock)
|
|
26
|
+
throw e;
|
|
27
|
+
return { ok: false, blocked: true, reasons: e.reasons };
|
|
28
|
+
}
|
|
29
|
+
throw e;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Wrap an MCP tool definition so its handler is guarded by the wallet. A blocked call
|
|
35
|
+
* returns `{ isError: true }` with a readable reason (the model sees it and can adjust);
|
|
36
|
+
* the wrapped tool's original handler runs only when the action is authorized.
|
|
37
|
+
*/
|
|
38
|
+
export function wrapMcpTool(tool, opts) {
|
|
39
|
+
const guarded = guardTool({
|
|
40
|
+
wallet: opts.wallet,
|
|
41
|
+
toAction: opts.toAction,
|
|
42
|
+
execute: async (args) => {
|
|
43
|
+
const res = await tool.handler(args);
|
|
44
|
+
return { outcome: (res.isError ? "failed" : "settled"), result: res };
|
|
45
|
+
},
|
|
46
|
+
throwOnBlock: false,
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
...tool,
|
|
50
|
+
handler: async (args) => {
|
|
51
|
+
const r = await guarded(args);
|
|
52
|
+
if (!r.ok) {
|
|
53
|
+
return {
|
|
54
|
+
content: [
|
|
55
|
+
{
|
|
56
|
+
type: "text",
|
|
57
|
+
text: `PAYMENT BLOCKED BY MANDATE — this action is not authorized: ${r.reasons.join("; ")}`,
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
isError: true,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return r.result ?? { content: [{ type: "text", text: "ok" }] };
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=adapters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapters.js","sourceRoot":"","sources":["../src/adapters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAe,cAAc,EAAE,MAAM,YAAY,CAAC;AAiBzD;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAU,IAA+B;IAChE,OAAO,KAAK,EAAE,IAAU,EAAE,EAAE;QAC1B,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACnC,IAAI,CAAC;YACH,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAI,MAAM,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;YACzF,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;QACvC,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,IAAI,CAAC,YAAY,cAAc,EAAE,CAAC;gBAChC,IAAI,IAAI,CAAC,YAAY;oBAAE,MAAM,CAAC,CAAC;gBAC/B,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC;YAC1D,CAAC;YACD,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC,CAAC;AACJ,CAAC;AAqBD;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,IAAa,EAAE,IAAoB;IAC7D,MAAM,OAAO,GAAG,SAAS,CAAqB;QAC5C,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,QAAQ,EAAE,IAAI,CAAC,QAAQ;QACvB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;YACtB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACrC,OAAO,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAY,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;QACnF,CAAC;QACD,YAAY,EAAE,KAAK;KACpB,CAAC,CAAC;IAEH,OAAO;QACL,GAAG,IAAI;QACP,OAAO,EAAE,KAAK,EAAE,IAAS,EAA0B,EAAE;YACnD,MAAM,CAAC,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;YAC9B,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;gBACV,OAAO;oBACL,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,MAAM;4BACZ,IAAI,EAAE,+DAA+D,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;yBAC5F;qBACF;oBACD,OAAO,EAAE,IAAI;iBACd,CAAC;YACJ,CAAC;YACD,OAAO,CAAC,CAAC,MAAM,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QACjE,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ISO8601 } from "./types.js";
|
|
2
|
+
export interface CredentialProof {
|
|
3
|
+
type: "Ed25519Signature2020";
|
|
4
|
+
created: ISO8601;
|
|
5
|
+
verificationMethod: string;
|
|
6
|
+
proofPurpose: "assertionMethod";
|
|
7
|
+
/** base64url Ed25519 signature over the canonical credential (sans proof). */
|
|
8
|
+
proofValue: string;
|
|
9
|
+
}
|
|
10
|
+
export interface SponsorCredential {
|
|
11
|
+
"@context": string[];
|
|
12
|
+
type: string[];
|
|
13
|
+
/** Issuer DID (the sponsor / principal). */
|
|
14
|
+
issuer: string;
|
|
15
|
+
issuanceDate: ISO8601;
|
|
16
|
+
expirationDate?: ISO8601;
|
|
17
|
+
credentialSubject: {
|
|
18
|
+
/** Subject DID (the agent). */
|
|
19
|
+
id: string;
|
|
20
|
+
role: "authorized-agent";
|
|
21
|
+
sponsor: string;
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
};
|
|
24
|
+
proof?: CredentialProof;
|
|
25
|
+
}
|
|
26
|
+
export interface IssueSponsorCredentialParams {
|
|
27
|
+
/** Issuer (principal) DID — `did:key:...`. */
|
|
28
|
+
issuerDid: string;
|
|
29
|
+
/** Issuer's PKCS#8 PEM private key. */
|
|
30
|
+
issuerPrivateKeyPem: string;
|
|
31
|
+
/** Subject (agent) DID — `did:key:...`. */
|
|
32
|
+
subjectDid: string;
|
|
33
|
+
/** Optional extra claims merged into credentialSubject. */
|
|
34
|
+
claims?: Record<string, unknown>;
|
|
35
|
+
/** Optional validity in seconds from `now`. */
|
|
36
|
+
ttlSeconds?: number;
|
|
37
|
+
now?: Date;
|
|
38
|
+
}
|
|
39
|
+
/** Issue and sign a sponsor credential. */
|
|
40
|
+
export declare function issueSponsorCredential(params: IssueSponsorCredentialParams): SponsorCredential;
|
|
41
|
+
export interface CredentialVerifyOptions {
|
|
42
|
+
now?: Date;
|
|
43
|
+
/** If set, require the credential's subject DID to equal this. */
|
|
44
|
+
expectSubject?: string;
|
|
45
|
+
}
|
|
46
|
+
/** Verify a sponsor credential's proof, issuer binding, and validity window. */
|
|
47
|
+
export declare function verifySponsorCredential(cred: SponsorCredential, opts?: CredentialVerifyOptions): {
|
|
48
|
+
ok: boolean;
|
|
49
|
+
reasons: string[];
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=credential.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential.d.ts","sourceRoot":"","sources":["../src/credential.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,OAAO,EAAE,MA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,uBAAuB,CAAC,IAAI,EAAE,iBAAiB,EAAE,IAAI,GAAE,uBAA4B,GAAG;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CAkCvI"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sponsor credential — a minimal W3C Verifiable Credential asserting the human/org sponsor
|
|
3
|
+
* relationship for an agent (the human sponsor chain). This is separate
|
|
4
|
+
* from any single envelope: it is a portable, verifiable statement "principal P sponsors
|
|
5
|
+
* agent A", which a counterparty can check once and cache, independent of individual mandates.
|
|
6
|
+
*
|
|
7
|
+
* Shape follows W3C VC Data Model with an Ed25519 proof. Issuer/subject are DIDs.
|
|
8
|
+
*/
|
|
9
|
+
import { canonicalize, signBytes, verifyBytes } from "./crypto.js";
|
|
10
|
+
import { isDidKey, keyIdToDidKey, isKeyId } from "./did.js";
|
|
11
|
+
function toDid(id) {
|
|
12
|
+
return isKeyId(id) ? keyIdToDidKey(id) : id;
|
|
13
|
+
}
|
|
14
|
+
/** Issue and sign a sponsor credential. */
|
|
15
|
+
export function issueSponsorCredential(params) {
|
|
16
|
+
const now = params.now ?? new Date();
|
|
17
|
+
const issuer = toDid(params.issuerDid);
|
|
18
|
+
const subject = toDid(params.subjectDid);
|
|
19
|
+
const unsigned = {
|
|
20
|
+
"@context": ["https://www.w3.org/ns/credentials/v2"],
|
|
21
|
+
type: ["VerifiableCredential", "AgentSponsorship"],
|
|
22
|
+
issuer,
|
|
23
|
+
issuanceDate: now.toISOString(),
|
|
24
|
+
...(params.ttlSeconds ? { expirationDate: new Date(now.getTime() + params.ttlSeconds * 1000).toISOString() } : {}),
|
|
25
|
+
credentialSubject: {
|
|
26
|
+
id: subject,
|
|
27
|
+
role: "authorized-agent",
|
|
28
|
+
sponsor: issuer,
|
|
29
|
+
...(params.claims ?? {}),
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
const bytes = Buffer.from(canonicalize(unsigned), "utf8");
|
|
33
|
+
const proof = {
|
|
34
|
+
type: "Ed25519Signature2020",
|
|
35
|
+
created: now.toISOString(),
|
|
36
|
+
verificationMethod: isDidKey(issuer) ? `${issuer}#${issuer.slice("did:key:".length)}` : issuer,
|
|
37
|
+
proofPurpose: "assertionMethod",
|
|
38
|
+
proofValue: signBytes(params.issuerPrivateKeyPem, bytes),
|
|
39
|
+
};
|
|
40
|
+
return { ...unsigned, proof };
|
|
41
|
+
}
|
|
42
|
+
/** Verify a sponsor credential's proof, issuer binding, and validity window. */
|
|
43
|
+
export function verifySponsorCredential(cred, opts = {}) {
|
|
44
|
+
const now = opts.now ?? new Date();
|
|
45
|
+
const reasons = [];
|
|
46
|
+
if (!cred.proof) {
|
|
47
|
+
return { ok: false, reasons: ["missing proof"] };
|
|
48
|
+
}
|
|
49
|
+
if (!isDidKey(cred.issuer)) {
|
|
50
|
+
// did:web (or other) verification requires resolution; out of scope for the sync path.
|
|
51
|
+
reasons.push(`issuer is not a did:key (got ${cred.issuer}); resolve its key to verify`);
|
|
52
|
+
}
|
|
53
|
+
// The proof's verificationMethod must belong to the issuer.
|
|
54
|
+
if (!cred.proof.verificationMethod.startsWith(cred.issuer)) {
|
|
55
|
+
reasons.push("proof.verificationMethod does not match issuer");
|
|
56
|
+
}
|
|
57
|
+
// credentialSubject.sponsor must equal issuer (the sponsor-chain assertion).
|
|
58
|
+
if (cred.credentialSubject.sponsor !== cred.issuer) {
|
|
59
|
+
reasons.push("credentialSubject.sponsor does not match issuer");
|
|
60
|
+
}
|
|
61
|
+
if (opts.expectSubject && cred.credentialSubject.id !== opts.expectSubject) {
|
|
62
|
+
reasons.push(`subject mismatch: expected ${opts.expectSubject}`);
|
|
63
|
+
}
|
|
64
|
+
// Validity window.
|
|
65
|
+
if (new Date(cred.issuanceDate).getTime() > now.getTime())
|
|
66
|
+
reasons.push("credential not yet valid");
|
|
67
|
+
if (cred.expirationDate && new Date(cred.expirationDate).getTime() <= now.getTime())
|
|
68
|
+
reasons.push("credential expired");
|
|
69
|
+
// Signature (only checkable synchronously for did:key issuers).
|
|
70
|
+
if (isDidKey(cred.issuer)) {
|
|
71
|
+
const { proof, ...unsigned } = cred;
|
|
72
|
+
const bytes = Buffer.from(canonicalize(unsigned), "utf8");
|
|
73
|
+
if (!verifyBytes(cred.issuer, bytes, proof.proofValue))
|
|
74
|
+
reasons.push("credential proof signature invalid");
|
|
75
|
+
}
|
|
76
|
+
return { ok: reasons.length === 0, reasons };
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=credential.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credential.js","sourceRoot":"","sources":["../src/credential.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AA2C5D,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC9C,CAAC;AAED,2CAA2C;AAC3C,MAAM,UAAU,sBAAsB,CAAC,MAAoC;IACzE,MAAM,GAAG,GAAG,MAAM,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC;IACrC,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACvC,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAEzC,MAAM,QAAQ,GAAsB;QAClC,UAAU,EAAE,CAAC,sCAAsC,CAAC;QACpD,IAAI,EAAE,CAAC,sBAAsB,EAAE,kBAAkB,CAAC;QAClD,MAAM;QACN,YAAY,EAAE,GAAG,CAAC,WAAW,EAAE;QAC/B,GAAG,CAAC,MAAM,CAAC,UAAU,CAA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MAAM,CAAC,CAAC;QAC1D,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC;YAAE,OAAO,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC;IAC7G,CAAC;IAED,OAAO,EAAE,EAAE,EAAE,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,OAAO,EAAE,CAAC;AAC/C,CAAC"}
|
package/dist/crypto.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { KeyId, KeyPair, Signature } from "./types.js";
|
|
2
|
+
/** Generate a fresh Ed25519 keypair with both a `key:<x>` id and its `did:key` form. */
|
|
3
|
+
export declare function generateKeyPair(): KeyPair;
|
|
4
|
+
/** Sign bytes with a PKCS#8 PEM Ed25519 private key; returns base64url. */
|
|
5
|
+
export declare function signBytes(privateKeyPem: string, data: Buffer): string;
|
|
6
|
+
/** Verify a base64url Ed25519 signature against a `key:<x>` id. Never throws. */
|
|
7
|
+
export declare function verifyBytes(keyId: KeyId, data: Buffer, signatureB64url: string): boolean;
|
|
8
|
+
/** SHA-256, hex-encoded. */
|
|
9
|
+
export declare function sha256Hex(data: Buffer | string): string;
|
|
10
|
+
/** A UUID for envelope/receipt ids. */
|
|
11
|
+
export declare function newId(): string;
|
|
12
|
+
/**
|
|
13
|
+
* Canonical JSON serialization (JCS-compatible subset, RFC 8785 target):
|
|
14
|
+
* object keys sorted lexicographically, no insignificant whitespace, UTF-8.
|
|
15
|
+
* Amounts are integers by protocol rule (§4.1), so number formatting is unambiguous.
|
|
16
|
+
*/
|
|
17
|
+
export declare function canonicalize(value: unknown): string;
|
|
18
|
+
/**
|
|
19
|
+
* Produce a Signature over an object, excluding any existing `signature` field.
|
|
20
|
+
* Used to sign both envelopes (by principal) and receipts (by agent).
|
|
21
|
+
*/
|
|
22
|
+
export declare function signObject(obj: Record<string, unknown>, by: KeyId, privateKeyPem: string): Signature;
|
|
23
|
+
/** Verify an object's embedded Signature was produced by `expectedSigner`. */
|
|
24
|
+
export declare function verifyObjectSignature(obj: Record<string, unknown> & {
|
|
25
|
+
signature?: Signature;
|
|
26
|
+
}, expectedSigner: KeyId): boolean;
|
|
27
|
+
//# sourceMappingURL=crypto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../src/crypto.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG5D,wFAAwF;AACxF,wBAAgB,eAAe,IAAI,OAAO,CAUzC;AAWD,2EAA2E;AAC3E,wBAAgB,SAAS,CAAC,aAAa,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAIrE;AAED,iFAAiF;AACjF,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAOxF;AAED,4BAA4B;AAC5B,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAEvD;AAED,uCAAuC;AACvC,wBAAgB,KAAK,IAAI,MAAM,CAE9B;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAmBnD;AAED;;;GAGG;AACH,wBAAgB,UAAU,CACxB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,EAAE,EAAE,KAAK,EACT,aAAa,EAAE,MAAM,GACpB,SAAS,CAIX;AAED,8EAA8E;AAC9E,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAAE,SAAS,CAAC,EAAE,SAAS,CAAA;CAAE,EACxD,cAAc,EAAE,KAAK,GACpB,OAAO,CAOT"}
|