@sheaf-labs/kya 0.0.0-stage → 0.1.1
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 +75 -2
- package/bin/kya.mjs +207 -0
- package/package.json +11 -4
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
CHANGED
|
@@ -1,3 +1,76 @@
|
|
|
1
|
-
#
|
|
1
|
+
# kya: Know Your Agent
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Banks run Know Your Customer before they open an account. KYA is the same check for AI agents.
|
|
4
|
+
Before one agent deals with another, it asks who the other is, who stands behind it, and what it has done.
|
|
5
|
+
|
|
6
|
+
`kya` puts an agent on the [Register of Traceable Agents](https://traceableagents.org) in one command,
|
|
7
|
+
lets it prove who it is, writes its record, and checks other agents before dealing with them.
|
|
8
|
+
|
|
9
|
+
It needs Node 18 or later and nothing else. Keys are made on your machine and never leave it.
|
|
10
|
+
The register only ever sees public keys and signatures.
|
|
11
|
+
|
|
12
|
+
## Put an agent on the register
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
npx @sheaf-labs/kya init --owner "Acme Ltd" --website https://acme.example
|
|
16
|
+
npx @sheaf-labs/kya join invoice-payer
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The first command makes your owner key. You sign for your agents with it. The second makes a key for
|
|
20
|
+
the agent, signs its ID as its owner, and enters it on the register. It prints the agent's ID, its
|
|
21
|
+
fingerprint and the page where anyone can look it up.
|
|
22
|
+
|
|
23
|
+
The agent is now **identified, owner on record**. To move the owner to **verified**, prove you control
|
|
24
|
+
your domain: the register gives you a token to put in a DNS record or at
|
|
25
|
+
`/.well-known/traceable-agents.txt`. See [owner verification](https://traceableagents.org/format.html#verification).
|
|
26
|
+
|
|
27
|
+
## The handshake
|
|
28
|
+
|
|
29
|
+
Agent A wants to deal with agent B.
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
# A makes a challenge and sends it to B
|
|
33
|
+
kya challenge
|
|
34
|
+
# B answers with a proof signed by its key
|
|
35
|
+
kya prove invoice-payer 3f9a…
|
|
36
|
+
# A checks the proof and reads B's record in one call
|
|
37
|
+
kya check 9c21e0a7b4d3f815 --proof '<the JSON B returned>' --challenge 3f9a…
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The answer is one of three: identified with a verified owner, identified with an owner on record, or
|
|
41
|
+
unknown. What A does with each answer is A's own policy.
|
|
42
|
+
|
|
43
|
+
## The record
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
kya receipt invoice-payer --kind payment --decision approved --action "INV-2041 £1,200 to Supplier Ltd"
|
|
47
|
+
kya record invoice-payer
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Each receipt adds one action to the agent's chain: the kind, the decision, the time, a hash of the
|
|
51
|
+
action and the hash of the receipt before it. The register never holds the text of the action.
|
|
52
|
+
Kinds and decisions are yours to name. Three kinds carry meaning for the Record Score: `held` (a person
|
|
53
|
+
stopped the action), `released` (a person let it go ahead) and `rejected` (a person refused it). The score
|
|
54
|
+
starts at 100 and comes down with the share of actions held or rejected; the formula is on the format page.
|
|
55
|
+
A receipt you write for your own agent is your own report of what it did; the register says so.
|
|
56
|
+
Receipts written by a system that runs the agent for you and holds its key carry that system's name.
|
|
57
|
+
|
|
58
|
+
## Everything else
|
|
59
|
+
|
|
60
|
+
```sh
|
|
61
|
+
kya whoami # your owner ID and your agents
|
|
62
|
+
kya retire invoice-payer # end the agent's life; the record stays
|
|
63
|
+
kya revoke invoice-payer # withdraw it for cause; the record stays
|
|
64
|
+
KYA_REGISTER=http://localhost:8080 kya … # another register
|
|
65
|
+
KYA_HOME=/path kya … # where keys live (default ~/.config/kya)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Without this tool
|
|
69
|
+
|
|
70
|
+
Every call is plain JSON over HTTPS with Ed25519 signatures. The format and every call are on
|
|
71
|
+
[traceableagents.org/format.html](https://traceableagents.org/format.html). This tool is about 200 lines;
|
|
72
|
+
read it to see the exact bytes that are signed.
|
|
73
|
+
|
|
74
|
+
## Licence
|
|
75
|
+
|
|
76
|
+
Apache-2.0. The format is open. Anyone may run a register; traceableagents.org is the public one.
|
package/bin/kya.mjs
ADDED
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// kya: Know Your Agent. Put an AI agent on the Register of Traceable Agents, prove who it is,
|
|
3
|
+
// write its record, and check other agents before dealing with them.
|
|
4
|
+
//
|
|
5
|
+
// Needs Node 18 or later and nothing else. Keys are made here and never leave this machine
|
|
6
|
+
// except as public keys and signatures. The register is https://traceableagents.org; set
|
|
7
|
+
// KYA_REGISTER to use another one. Keys live in ~/.config/kya; set KYA_HOME to move them.
|
|
8
|
+
import { generateKeyPairSync, createPrivateKey, sign, createHash, randomBytes } from "node:crypto";
|
|
9
|
+
import { readFileSync, writeFileSync, existsSync, mkdirSync, readdirSync, chmodSync } from "node:fs";
|
|
10
|
+
import { join as pathJoin } from "node:path";
|
|
11
|
+
import { homedir } from "node:os";
|
|
12
|
+
|
|
13
|
+
const REGISTER = (process.env.KYA_REGISTER || "https://traceableagents.org").replace(/\/$/, "");
|
|
14
|
+
const HOME = process.env.KYA_HOME || pathJoin(process.env.XDG_CONFIG_HOME || pathJoin(homedir(), ".config"), "kya");
|
|
15
|
+
const AGENTS = pathJoin(HOME, "agents");
|
|
16
|
+
|
|
17
|
+
// ── the format ──────────────────────────────────────────────────────────────────────────────
|
|
18
|
+
const B58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
19
|
+
const b58 = bytes => { let n = BigInt("0x" + Buffer.from(bytes).toString("hex")), s = ""; while (n > 0n) { s = B58[Number(n % 58n)] + s; n /= 58n; } for (const b of bytes) { if (b !== 0) break; s = "1" + s; } return s; };
|
|
20
|
+
const canonical = v => Array.isArray(v) ? "[" + v.map(canonical).join(",") + "]"
|
|
21
|
+
: v && typeof v === "object" ? "{" + Object.keys(v).sort().map(k => JSON.stringify(k) + ":" + canonical(v[k])).join(",") + "}"
|
|
22
|
+
: JSON.stringify(v);
|
|
23
|
+
const sha256 = buf => createHash("sha256").update(buf).digest();
|
|
24
|
+
const pubOf = priv => Buffer.from(createPrivateKey(priv).export({ format: "jwk" }).x, "base64url");
|
|
25
|
+
const didOf = priv => "did:key:z" + b58(Buffer.concat([Buffer.from([0xed, 0x01]), pubOf(priv)]));
|
|
26
|
+
const fingerprintOf = priv => sha256(pubOf(priv)).toString("hex").slice(0, 16);
|
|
27
|
+
const signB64 = (priv, bytes) => sign(null, bytes, createPrivateKey(priv)).toString("base64");
|
|
28
|
+
const signed = (priv, body) => ({ ...body, signature: signB64(priv, Buffer.from(canonical(body), "utf8")) });
|
|
29
|
+
const now = () => new Date().toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
30
|
+
const GENESIS = "0".repeat(64);
|
|
31
|
+
|
|
32
|
+
// ── files ───────────────────────────────────────────────────────────────────────────────────
|
|
33
|
+
const ownerKeyPath = pathJoin(HOME, "owner.key"), ownerPath = pathJoin(HOME, "owner.json");
|
|
34
|
+
const agentKeyPath = n => pathJoin(AGENTS, n + ".key"), agentPath = n => pathJoin(AGENTS, n + ".json");
|
|
35
|
+
const readJson = p => JSON.parse(readFileSync(p, "utf8"));
|
|
36
|
+
const writeJson = (p, v) => writeFileSync(p, JSON.stringify(v, null, 2) + "\n", { mode: 0o600 });
|
|
37
|
+
const writeKey = (p, kp) => { writeFileSync(p, kp.privateKey.export({ type: "pkcs8", format: "pem" }), { mode: 0o600 }); chmodSync(p, 0o600); };
|
|
38
|
+
const owner = () => { if (!existsSync(ownerKeyPath)) die("No owner key yet. Run: kya init --owner \"Your name or company\""); return { key: readFileSync(ownerKeyPath), ...readJson(ownerPath) }; };
|
|
39
|
+
const agent = n => { if (!existsSync(agentKeyPath(n))) die(`No agent called "${n}" here. Run: kya join ${n}`); return { key: readFileSync(agentKeyPath(n)), ...readJson(agentPath(n)) }; };
|
|
40
|
+
const safeName = n => { if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,79}$/.test(n || "")) die("An agent name is 1 to 80 letters, digits, dots, dashes or underscores."); return n; };
|
|
41
|
+
|
|
42
|
+
// ── the wire ────────────────────────────────────────────────────────────────────────────────
|
|
43
|
+
async function post(path, body) {
|
|
44
|
+
const r = await fetch(REGISTER + path, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) });
|
|
45
|
+
const j = await r.json().catch(() => ({}));
|
|
46
|
+
if (!j.ok) die(`${REGISTER}${path} said: ${j.error || j.message || r.status}`);
|
|
47
|
+
return j;
|
|
48
|
+
}
|
|
49
|
+
async function get(path) { const r = await fetch(REGISTER + path); return r.json(); }
|
|
50
|
+
|
|
51
|
+
// ── arguments ───────────────────────────────────────────────────────────────────────────────
|
|
52
|
+
const argv = process.argv.slice(2);
|
|
53
|
+
const flags = {}, words = [];
|
|
54
|
+
for (let i = 0; i < argv.length; i++) {
|
|
55
|
+
const a = argv[i];
|
|
56
|
+
if (a.startsWith("--")) { const k = a.slice(2); const v = argv[i + 1]; if (v !== undefined && !v.startsWith("--")) { flags[k] = v; i++; } else flags[k] = true; }
|
|
57
|
+
else words.push(a);
|
|
58
|
+
}
|
|
59
|
+
const [cmd, ...rest] = words;
|
|
60
|
+
function die(msg) { console.error(msg); process.exit(1); }
|
|
61
|
+
function out(v) { console.log(typeof v === "string" ? v : JSON.stringify(v, null, 2)); }
|
|
62
|
+
|
|
63
|
+
const HELP = `kya: Know Your Agent. The Register of Traceable Agents from the command line.
|
|
64
|
+
|
|
65
|
+
kya init --owner "Name" [--website https://…] [--hidden]
|
|
66
|
+
Make your owner key. You sign for your agents with it. Keep it; a lost key cannot be replaced.
|
|
67
|
+
kya join <agent> [--kind agent] [--test] [--parent <agent>]
|
|
68
|
+
Make a key for the agent, sign its ID as its owner, and enter it on the register.
|
|
69
|
+
kya whoami
|
|
70
|
+
Your owner ID and the agents you have entered.
|
|
71
|
+
kya prove <agent> <challenge> [--audience <did>]
|
|
72
|
+
Answer another agent's challenge: a proof signed with this agent's key, as JSON.
|
|
73
|
+
kya check <id or fingerprint> [--proof '<json>' --challenge <c>]
|
|
74
|
+
Look another agent up. With a proof and the challenge you sent, also checks the proof is theirs.
|
|
75
|
+
kya challenge
|
|
76
|
+
A fresh random challenge to send to another agent.
|
|
77
|
+
kya receipt <agent> --kind <kind> --decision <decision> [--action "<text>"] [--run <id>]
|
|
78
|
+
Add one action to the agent's record. Kinds and decisions are yours to name, for example
|
|
79
|
+
payment / approved or email / sent. Three kinds have meaning for the Record Score: held (a person
|
|
80
|
+
stopped it), released (a person let it go), rejected (a person refused it). The register keeps
|
|
81
|
+
a hash of the action, never the text.
|
|
82
|
+
kya retire <agent> [--reason "…"] End the agent's life. Its record stays.
|
|
83
|
+
kya revoke <agent> [--reason "…"] Withdraw the agent for cause. Its record stays.
|
|
84
|
+
kya record <agent> The agent's Record of Action and Record Score, from the register.
|
|
85
|
+
|
|
86
|
+
Register: ${REGISTER} Keys: ${HOME}
|
|
87
|
+
The format, with every call: ${REGISTER}/format.html`;
|
|
88
|
+
|
|
89
|
+
// ── commands ────────────────────────────────────────────────────────────────────────────────
|
|
90
|
+
async function init() {
|
|
91
|
+
const name = (flags.owner || "").trim();
|
|
92
|
+
if (!name) die('Who signs for these agents? kya init --owner "Your name or company"');
|
|
93
|
+
mkdirSync(AGENTS, { recursive: true, mode: 0o700 });
|
|
94
|
+
if (existsSync(ownerKeyPath)) die(`${ownerKeyPath} already exists. Your owner ID is ${didOf(readFileSync(ownerKeyPath))}. Move the file away first if you mean to start over; agents signed by the old key stay with it.`);
|
|
95
|
+
const kp = generateKeyPairSync("ed25519");
|
|
96
|
+
writeKey(ownerKeyPath, kp);
|
|
97
|
+
const o = { name: name.slice(0, 120), website: flags.website || undefined, listed: !flags.hidden, createdAt: now() };
|
|
98
|
+
writeJson(ownerPath, o);
|
|
99
|
+
out(`Owner key written to ${ownerKeyPath}. Keep it private and backed up.`);
|
|
100
|
+
out(`Owner ID: ${didOf(readFileSync(ownerKeyPath))}`);
|
|
101
|
+
out(`Next: kya join <agent-name>`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function join() {
|
|
105
|
+
const name = safeName(rest[0]);
|
|
106
|
+
const o = owner();
|
|
107
|
+
mkdirSync(AGENTS, { recursive: true, mode: 0o700 });
|
|
108
|
+
if (existsSync(agentKeyPath(name))) die(`"${name}" already has a key here (${readJson(agentPath(name)).id}). Pick another name.`);
|
|
109
|
+
const kind = (flags.kind || "agent").toString().slice(0, 60);
|
|
110
|
+
const environment = flags.test ? "test" : "production";
|
|
111
|
+
const parent = flags.parent ? agent(flags.parent) : null;
|
|
112
|
+
if (parent && parent.environment === "test" && environment !== "test") die("A child of a test agent is a test agent. Add --test.");
|
|
113
|
+
const kp = generateKeyPairSync("ed25519");
|
|
114
|
+
const priv = kp.privateKey.export({ type: "pkcs8", format: "pem" });
|
|
115
|
+
const issuedAt = now(), expiresAt = new Date(Date.now() + 365 * 86400e3).toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
116
|
+
const descriptor = { v: 1, type: "traceable-agent", id: didOf(priv), owner: didOf(o.key), name, kind, environment: parent ? parent.environment : environment, issuedAt, expiresAt };
|
|
117
|
+
if (parent) descriptor.parent = parent.id;
|
|
118
|
+
const bytes = Buffer.from(canonical(descriptor), "utf8");
|
|
119
|
+
const entry = { descriptor, ownerSignature: signB64(o.key, bytes) };
|
|
120
|
+
if (parent) entry.parentSignature = signB64(parent.key, bytes);
|
|
121
|
+
const body = signed(o.key, { type: "traceable-join", at: now(), owner: { id: didOf(o.key), name: o.name, website: o.website, listed: o.listed !== false }, agent: entry });
|
|
122
|
+
const r = await post("/api/v1/register/join", body);
|
|
123
|
+
writeKey(agentKeyPath(name), kp);
|
|
124
|
+
writeJson(agentPath(name), { id: descriptor.id, fingerprint: fingerprintOf(priv), name, kind, environment: descriptor.environment, parent: descriptor.parent, parentName: parent ? parent.name : undefined, descriptor, issuedAt, expiresAt, lookup: r.agent.lookup, seq: 0, prevHash: GENESIS });
|
|
125
|
+
out(`${name} is on the register.`);
|
|
126
|
+
out(`ID: ${descriptor.id}`);
|
|
127
|
+
out(`Fingerprint: ${fingerprintOf(priv)}`);
|
|
128
|
+
out(`Look it up: ${REGISTER}/a/${fingerprintOf(priv)}`);
|
|
129
|
+
out(`Key: ${agentKeyPath(name)} (the agent proves who it is with this; keep it private)`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async function whoami() {
|
|
133
|
+
const o = owner();
|
|
134
|
+
out(`Owner: ${o.name}${o.listed === false ? " (name hidden)" : ""}`);
|
|
135
|
+
out(`ID: ${didOf(o.key)}`);
|
|
136
|
+
out(`Page: ${REGISTER}/o/${didOf(o.key)}`);
|
|
137
|
+
const names = existsSync(AGENTS) ? readdirSync(AGENTS).filter(f => f.endsWith(".json")).map(f => f.slice(0, -5)) : [];
|
|
138
|
+
if (!names.length) { out("Agents: none yet. kya join <agent-name>"); return; }
|
|
139
|
+
out("Agents:");
|
|
140
|
+
for (const n of names) { const a = readJson(agentPath(n)); out(` ${n.padEnd(24)} ${a.fingerprint} ${a.environment}${a.parent ? " child of " + (a.parentName || a.parent) : ""} ${REGISTER}/a/${a.fingerprint}`); }
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function prove() {
|
|
144
|
+
const a = agent(safeName(rest[0]));
|
|
145
|
+
const challenge = rest[1];
|
|
146
|
+
if (!challenge) die("kya prove <agent> <challenge>: the challenge is the value the other agent sent you.");
|
|
147
|
+
const proof = { v: 1, type: "traceable-proof", id: a.id, challenge, audience: flags.audience || null, at: now() };
|
|
148
|
+
out(signed(a.key, proof));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async function check() {
|
|
152
|
+
const id = rest[0];
|
|
153
|
+
if (!id) die("kya check <id or fingerprint>");
|
|
154
|
+
let r;
|
|
155
|
+
if (flags.proof) {
|
|
156
|
+
let proof; try { proof = JSON.parse(flags.proof); } catch { die("--proof must be the proof JSON exactly as the other agent gave it."); }
|
|
157
|
+
if (!flags.challenge) die("--challenge is the value you sent; the register checks the proof is over it.");
|
|
158
|
+
r = await post("/api/v1/register/check", { proof, challenge: flags.challenge });
|
|
159
|
+
} else {
|
|
160
|
+
r = await post("/api/v1/register/check", { id });
|
|
161
|
+
}
|
|
162
|
+
out(r.summary || r.answer || r);
|
|
163
|
+
if (flags.json) out(r);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async function challenge() { out(randomBytes(16).toString("hex")); }
|
|
167
|
+
|
|
168
|
+
async function headOf(a) {
|
|
169
|
+
const j = await get(`/api/v1/register/agents/${a.id}`);
|
|
170
|
+
const rec = j && j.record ? j.record : {};
|
|
171
|
+
return { seq: rec.headSeq || 0, prevHash: rec.headHash || GENESIS };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async function receipt() {
|
|
175
|
+
const name = safeName(rest[0]); const a = agent(name); const o = owner();
|
|
176
|
+
const kind = flags.kind, decision = flags.decision;
|
|
177
|
+
if (!kind || !decision) die('kya receipt <agent> --kind <kind> --decision <decision> [--action "<text>"] [--run <id>]');
|
|
178
|
+
const head = await headOf(a);
|
|
179
|
+
const seq = head.seq + 1, prevHash = head.prevHash, at = now();
|
|
180
|
+
const actionHash = flags.action ? sha256(Buffer.from(String(flags.action), "utf8")).toString("hex") : null;
|
|
181
|
+
const ledgerRowHash = sha256(Buffer.from(canonical({ at, kind, decision, actionHash, run: flags.run || null, seq }), "utf8")).toString("hex");
|
|
182
|
+
const runId = flags.run ? String(flags.run) : null;
|
|
183
|
+
const hash = sha256(Buffer.from(canonical(["traceable-receipt", a.id, seq, at, kind, decision, runId, actionHash, ledgerRowHash, prevHash]), "utf8")).toString("hex");
|
|
184
|
+
const rc = { seq, at, kind, decision, runId, actionHash, ledgerRowHash, prevHash, hash, signature: signB64(a.key, Buffer.from(hash, "hex")) };
|
|
185
|
+
const r = await post("/api/v1/register/receipts", signed(o.key, { verifier: didOf(o.key), at: now(), agent: a.id, receipts: [rc] }));
|
|
186
|
+
writeJson(agentPath(name), { ...a, key: undefined, seq: r.headSeq, prevHash: r.headHash });
|
|
187
|
+
out(`Receipt ${r.headSeq} on ${name}'s record: ${kind} / ${decision}. ${REGISTER}/a/${a.fingerprint}`);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async function standing(status) {
|
|
191
|
+
const name = safeName(rest[0]); const a = agent(name); const o = owner();
|
|
192
|
+
const r = await post("/api/v1/register/entries/status", signed(o.key, { verifier: didOf(o.key), at: now(), agent: a.id, status, reason: flags.reason ? String(flags.reason).slice(0, 200) : undefined }));
|
|
193
|
+
out(`${name} is ${r.agent.status}. Its record stays at ${REGISTER}/a/${a.fingerprint}`);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async function record() {
|
|
197
|
+
const a = agent(safeName(rest[0]));
|
|
198
|
+
const j = await get(`/api/v1/register/agents/${a.id}/record`);
|
|
199
|
+
if (!j || !j.ok) die("The register did not answer.");
|
|
200
|
+
out(j.story || j.recordOfAction?.story || j);
|
|
201
|
+
if (flags.json) out(j);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const run = { init, join, whoami, prove, check, challenge, receipt, record, retire: () => standing("retired"), revoke: () => standing("revoked") };
|
|
205
|
+
if (!cmd || cmd === "help" || flags.help) { out(HELP); process.exit(0); }
|
|
206
|
+
if (!run[cmd]) die(`Unknown command "${cmd}".\n\n${HELP}`);
|
|
207
|
+
run[cmd]().catch(e => die(e && e.message ? e.message : String(e)));
|
package/package.json
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sheaf-labs/kya",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
}
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Know Your Agent. Put an AI agent on the Register of Traceable Agents, prove who it is, write its record, and check other agents before dealing with them.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": { "kya": "bin/kya.mjs" },
|
|
7
|
+
"files": ["bin", "README.md", "LICENSE"],
|
|
8
|
+
"engines": { "node": ">=18" },
|
|
9
|
+
"keywords": ["kya", "know-your-agent", "ai-agents", "agent-identity", "did", "ed25519", "traceable-agents", "register"],
|
|
10
|
+
"homepage": "https://traceableagents.org",
|
|
11
|
+
"repository": { "type": "git", "url": "https://github.com/jackmitchelwidman/traceable-agents" },
|
|
12
|
+
"license": "Apache-2.0"
|
|
13
|
+
}
|