@kya-brasil/agent-tools 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -29,11 +29,15 @@ const verdict = await kya.allowed(credentialId, { // $0.01, signed
29
29
  if (!verdict.allowed) reject(verdict.reason);
30
30
 
31
31
  await verifyAttestation(verdict); // local Ed25519 check of the issuer's signature
32
+
33
+ const receipt = await kya.registerAct(credentialId, { // $0.02 once you accept it: signed receipt,
34
+ action: "order", amount: 4200, currency: "BRL", counterparty: "12345678000190", reference: "PO-1"
35
+ }); // daily ceilings enforced across counterparties
32
36
  ```
33
37
 
34
38
  Also check that the key that signed the agent's request is `v.agent.id`; the credential_id alone proves nothing.
35
39
 
36
- Agent frameworks (verifier tools `kya_verify`, `kya_check_action`, `kya_verify_paid`):
40
+ Agent frameworks (verifier tools `kya_verify`, `kya_check_action`, `kya_register_act`, `kya_verify_paid`):
37
41
 
38
42
  ```ts
39
43
  import { toOpenAI, toVercelAI, toLangChain, toAnthropic } from "@kya-brasil/agent-tools";
@@ -52,7 +56,13 @@ const kya = createKyaClient({ privateKey: payerPk });
52
56
  const reg = await kya.register({ // $0.50
53
57
  agent: { kind: "evm", id: agentAddress },
54
58
  cnpj: "11.222.333/0001-81",
55
- mandate: { actions: ["quote", "order", "pay"], max_per_operation: 5000, max_per_day: 20000, currencies: ["BRL", "USDC"] }
59
+ mandate: {
60
+ actions: ["quote", "order", "pay"],
61
+ max_per_operation: { amount: 5000, currency: "BRL" },
62
+ max_per_day: { amount: 20000, currency: "BRL" },
63
+ currencies: ["BRL"],
64
+ counterparties: ["12345678000190", "*.beta.com.br"]
65
+ }
56
66
  });
57
67
 
58
68
  const agent_signature = await signChallengeWithEvmKey(agentPk, reg.challenge.text);
@@ -78,6 +88,7 @@ Renew every 90 days (`kya.renew` then `kya.renewProve`), revoke at once (`kya.re
78
88
  |---|---|
79
89
  | verify, verifyByKey, prove, renewProve, revoke, revocations | free |
80
90
  | verified (signed receipt, no limit), allowed (signed verdict) | 0.01 |
91
+ | registerAct (signed receipt of what the agent did) | 0.02 |
81
92
  | renew | 0.10 |
82
93
  | register | 0.50 |
83
94
 
package/dist/index.d.ts CHANGED
@@ -8,15 +8,23 @@ export interface KyaOptions {
8
8
  internalKey?: string;
9
9
  fetch?: typeof fetch;
10
10
  }
11
+ /** erc8004: id is eip155:<chainId>:<identityRegistry>:<agentId>; the on-chain agentWallet signs (credential.agent.wallet). */
11
12
  export type AgentKey = {
12
- kind: "evm" | "web-bot-auth";
13
+ kind: "evm" | "web-bot-auth" | "erc8004";
13
14
  id: string;
15
+ wallet?: `0x${string}`;
14
16
  };
15
17
  export type CredentialStatus = "pending" | "active" | "suspended" | "revoked" | "expired";
16
18
  export interface Mandate {
17
19
  actions?: string[];
18
- max_per_operation?: number;
19
- max_per_day?: number;
20
+ max_per_operation?: {
21
+ amount: number;
22
+ currency: string;
23
+ };
24
+ max_per_day?: {
25
+ amount: number;
26
+ currency: string;
27
+ };
20
28
  currencies?: string[];
21
29
  counterparties?: string[];
22
30
  valid_from?: string;
@@ -123,6 +131,45 @@ export interface Proof {
123
131
  agent_signature: string;
124
132
  ecnpj_signature: string;
125
133
  }
134
+ export interface ActInput {
135
+ action: string;
136
+ amount?: number;
137
+ currency?: string;
138
+ counterparty?: string;
139
+ reference?: string;
140
+ content_sha256?: string;
141
+ registered_by?: "counterparty" | "agent";
142
+ registrant?: string;
143
+ agent_signature?: string;
144
+ }
145
+ export interface ActReceipt {
146
+ act_id: string;
147
+ credential_id: string;
148
+ status: CredentialStatus;
149
+ allowed: boolean;
150
+ reason: string;
151
+ act: ActInput & {
152
+ agent_signed: boolean;
153
+ };
154
+ checks: {
155
+ rule: string;
156
+ ok: boolean;
157
+ detail?: string;
158
+ }[];
159
+ not_evaluated: string[];
160
+ spent_today_registered_before: {
161
+ currency: string;
162
+ amount: number;
163
+ } | null;
164
+ spent_today_registered_after: {
165
+ currency: string;
166
+ amount: number;
167
+ } | null;
168
+ registered_at: string;
169
+ receipt_url: string;
170
+ attestation?: Attestation;
171
+ [k: string]: unknown;
172
+ }
126
173
  export declare class KyaError extends Error {
127
174
  readonly code: string;
128
175
  readonly status: number;
@@ -176,6 +223,27 @@ export interface KyaClient {
176
223
  credential_id: string;
177
224
  status: "revoked";
178
225
  }>;
226
+ /** $0.02: register what the agent did (you accepted it); mandate re-checked with today's registered acts; signed receipt. */
227
+ registerAct(credentialId: string, act: ActInput): Promise<ActReceipt>;
228
+ /** Free: a registered act and its receipt, by act_id. */
229
+ act(actId: string): Promise<ActReceipt>;
230
+ /** Free: the exact text the agent signs for an act (optional agent_signature). */
231
+ actText(credentialId: string, act: ActInput): Promise<{
232
+ credential_id: string;
233
+ agent: AgentKey;
234
+ text: string;
235
+ }>;
236
+ /** Free, company only: the trail of an agent's acts, request signed with the e-CNPJ over actsExportText(id). */
237
+ exportActs(credentialId: string, input: {
238
+ signed_text: string;
239
+ ecnpj_signature: string;
240
+ since?: string;
241
+ }): Promise<{
242
+ credential_id: string;
243
+ since: string;
244
+ count: number;
245
+ acts: Record<string, unknown>[];
246
+ }>;
179
247
  /** Free: credentials revoked since a date (default 30 days). */
180
248
  revocations(since?: string): Promise<{
181
249
  since: string;
@@ -248,6 +316,8 @@ export interface ECnpjMaterial {
248
316
  * Works with A1 certificates (file). A3 (token or smart card) must sign through the vendor's software.
249
317
  */
250
318
  export declare function signWithECnpj(material: ECnpjMaterial, text: string): Promise<string>;
319
+ /** The text the company signs to read its agent's trail of acts. */
320
+ export declare function actsExportText(credentialId: string, nonce?: string): string;
251
321
  /** The text the company signs to revoke a credential. */
252
322
  export declare function revocationText(credentialId: string, nonce?: string): string;
253
323
  export interface VerifyResult {
package/dist/index.js CHANGED
@@ -80,6 +80,10 @@ export function createKyaClient(opts = {}) {
80
80
  renewProve: (id, proof) => call("POST", `/v1/agents/${encodeURIComponent(id)}/renew/prove`, proof),
81
81
  revoke: (id, input) => call("POST", `/v1/agents/${encodeURIComponent(id)}/revoke`, input),
82
82
  revocations: (since) => call("GET", `/v1/revocations${q({ since })}`),
83
+ registerAct: (id, act) => call("POST", `/v1/agents/${encodeURIComponent(id)}/acts`, act, true, 0.02),
84
+ act: (actId) => call("GET", `/v1/acts/${encodeURIComponent(actId)}`),
85
+ actText: (id, act) => call("POST", `/v1/agents/${encodeURIComponent(id)}/acts/text`, act),
86
+ exportActs: (id, input) => call("POST", `/v1/agents/${encodeURIComponent(id)}/acts/export`, input),
83
87
  tools: [],
84
88
  execute: async (name, args) => {
85
89
  const t = client.tools.find((x) => x.name === name);
@@ -93,7 +97,7 @@ export function createKyaClient(opts = {}) {
93
97
  {
94
98
  name: "kya_verify", priceUsd: 0,
95
99
  description: "Free. Is this AI agent credentialed by a Brazilian company? Returns the credential (company CNPJ and name, mandate, KYB snapshot), its live status (active, suspended, revoked, expired) and history. Give credential_id, or the agent key (kind + id) to look it up.",
96
- parameters: { type: "object", properties: { credential_id: ID, kind: { type: "string", enum: ["evm", "web-bot-auth"] }, id: { type: "string", description: "0x address or base64url Ed25519 key" } }, additionalProperties: false },
100
+ parameters: { type: "object", properties: { credential_id: ID, kind: { type: "string", enum: ["evm", "web-bot-auth", "erc8004"] }, id: { type: "string", description: "0x address, base64url Ed25519 key, or eip155:<chainId>:<registry>:<agentId>" } }, additionalProperties: false },
97
101
  execute: async (a) => (a.credential_id ? client.verify(String(a.credential_id)) : client.verifyByKey({ kind: a.kind, id: String(a.id) }))
98
102
  },
99
103
  {
@@ -102,6 +106,12 @@ export function createKyaClient(opts = {}) {
102
106
  parameters: { type: "object", properties: { credential_id: ID, action: { type: "string" }, amount: { type: "number" }, currency: { type: "string" }, counterparty: { type: "string", description: "Your CNPJ, domain or wallet address" }, spent_today: { type: "number" } }, required: ["credential_id"], additionalProperties: false },
103
107
  execute: async (a) => client.allowed(String(a.credential_id), { action: a.action, amount: a.amount, currency: a.currency, counterparty: a.counterparty, spent_today: a.spent_today })
104
108
  },
109
+ {
110
+ name: "kya_register_act", priceUsd: 0.02,
111
+ description: "Register an action you accepted from an agent ($0.02): the issuer re-checks the mandate including everything registered today by anyone (so daily ceilings hold across counterparties) and returns a signed receipt, your proof of what the agent could and did do. Denied acts are recorded too.",
112
+ parameters: { type: "object", properties: { credential_id: ID, action: { type: "string" }, amount: { type: "number" }, currency: { type: "string" }, counterparty: { type: "string", description: "You: CNPJ, domain or wallet" }, reference: { type: "string" }, content_sha256: { type: "string" } }, required: ["credential_id", "action"], additionalProperties: false },
113
+ execute: async (a) => { const { credential_id, ...act } = a; return client.registerAct(String(credential_id), act); }
114
+ },
105
115
  {
106
116
  name: "kya_verify_paid", priceUsd: 0.01,
107
117
  description: "Same as kya_verify without the daily limit, plus a signed receipt of the verification ($0.01).",
@@ -163,6 +173,10 @@ export async function signWithECnpj(material, text) {
163
173
  s += String.fromCharCode(b);
164
174
  return btoa(s);
165
175
  }
176
+ /** The text the company signs to read its agent's trail of acts. */
177
+ export function actsExportText(credentialId, nonce = crypto.randomUUID()) {
178
+ return `KYA Brasil: acts ${credentialId}\n${nonce}`;
179
+ }
166
180
  /** The text the company signs to revoke a credential. */
167
181
  export function revocationText(credentialId, nonce = crypto.randomUUID()) {
168
182
  return `KYA Brasil: revoke ${credentialId}\n${nonce}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kya-brasil/agent-tools",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "KYA Brasil for AI agents: verify that an agent acts for a Brazilian company (e-CNPJ-signed, KYB-checked credential), check an action against its mandate, or give your own agent a credential. x402 payments (USDC on Base) handled for you. Adapters for Vercel AI SDK, LangChain, OpenAI and Anthropic.",
5
5
  "license": "MIT",
6
6
  "type": "module",