@kyde/score 0.9.6 → 0.10.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/bin/kyde.js +166 -2
- package/package.json +6 -2
package/bin/kyde.js
CHANGED
|
@@ -14,11 +14,13 @@
|
|
|
14
14
|
"use strict";
|
|
15
15
|
|
|
16
16
|
const { spawnSync } = require("node:child_process");
|
|
17
|
+
const crypto = require("node:crypto");
|
|
17
18
|
const fs = require("node:fs");
|
|
18
19
|
const os = require("node:os");
|
|
19
20
|
const path = require("node:path");
|
|
20
21
|
|
|
21
22
|
const BASE = process.env.KYDE_ENDPOINT || "https://score.kyde.com";
|
|
23
|
+
const SHINE = process.env.KYDE_SHINE_ENDPOINT || "https://shine.kyde.com";
|
|
22
24
|
const VERSION = require("../package.json").version;
|
|
23
25
|
|
|
24
26
|
// Carried over from 0.1.0 (published 2026-11-04): the copy-paste line
|
|
@@ -37,9 +39,17 @@ Usage:
|
|
|
37
39
|
npx @kyde/score prompt print the one-line setup prompt to paste into
|
|
38
40
|
a coding agent, which then runs init itself:
|
|
39
41
|
${SETUP_PROMPT}
|
|
42
|
+
npx @kyde/score verify <shine-id>
|
|
43
|
+
challenge the agent behind a Shine ID via
|
|
44
|
+
${SHINE}, wait for its
|
|
45
|
+
confirmation and print the Ed25519-signed
|
|
46
|
+
statement, verified locally against the JWKS.
|
|
47
|
+
Options: --challenger <name> --session <s>
|
|
48
|
+
--timeout <seconds, default 300>
|
|
40
49
|
|
|
41
|
-
Options via environment: KYDE_KEY, KYDE_ENDPOINT,
|
|
42
|
-
KYDE_REMOVE_GLOBAL_NAME=1 —
|
|
50
|
+
Options via environment: KYDE_KEY, KYDE_ENDPOINT, KYDE_SHINE_ENDPOINT,
|
|
51
|
+
KYDE_BLOCK (ask|deny|off), KYDE_REMOVE_GLOBAL_NAME=1 —
|
|
52
|
+
see https://score.kyde.com/llms.txt
|
|
43
53
|
`);
|
|
44
54
|
process.exit(code);
|
|
45
55
|
}
|
|
@@ -96,9 +106,163 @@ async function init() {
|
|
|
96
106
|
}
|
|
97
107
|
}
|
|
98
108
|
|
|
109
|
+
// --- verify: the challenger side of the Shine challenge (KYDE-439) ---------
|
|
110
|
+
|
|
111
|
+
function b64urlDecode(text) {
|
|
112
|
+
return Buffer.from(text, "base64url");
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async function shineJson(method, path, body, headers) {
|
|
116
|
+
const res = await fetch(`${SHINE}${path}`, {
|
|
117
|
+
method,
|
|
118
|
+
headers: { "content-type": "application/json", ...(headers || {}) },
|
|
119
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
120
|
+
signal: AbortSignal.timeout(15000),
|
|
121
|
+
});
|
|
122
|
+
let payload = {};
|
|
123
|
+
try {
|
|
124
|
+
payload = await res.json();
|
|
125
|
+
} catch {
|
|
126
|
+
/* non-JSON error body */
|
|
127
|
+
}
|
|
128
|
+
return { status: res.status, payload };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Verify the compact JWS against the JWKS, compare the nonce hash and
|
|
132
|
+
// the expiry — the same checks the MCP verify_agent tool runs, so both
|
|
133
|
+
// entry points accept exactly the same statements.
|
|
134
|
+
function verifyStatement(statement, jwks, nonce) {
|
|
135
|
+
const [head, payload, sig] = statement.split(".");
|
|
136
|
+
const header = JSON.parse(b64urlDecode(head).toString());
|
|
137
|
+
if (header.alg !== "EdDSA") {
|
|
138
|
+
throw new Error(`unexpected statement alg: ${header.alg}`);
|
|
139
|
+
}
|
|
140
|
+
const jwk = (jwks.keys || []).find(
|
|
141
|
+
(k) => k.kid === header.kid && k.kty === "OKP" && k.crv === "Ed25519",
|
|
142
|
+
);
|
|
143
|
+
if (!jwk) throw new Error("statement kid not found in shine JWKS");
|
|
144
|
+
const key = crypto.createPublicKey({
|
|
145
|
+
key: { kty: "OKP", crv: "Ed25519", x: jwk.x },
|
|
146
|
+
format: "jwk",
|
|
147
|
+
});
|
|
148
|
+
const ok = crypto.verify(
|
|
149
|
+
null,
|
|
150
|
+
Buffer.from(`${head}.${payload}`),
|
|
151
|
+
key,
|
|
152
|
+
b64urlDecode(sig),
|
|
153
|
+
);
|
|
154
|
+
if (!ok) throw new Error("statement signature does not verify");
|
|
155
|
+
const claims = JSON.parse(b64urlDecode(payload).toString());
|
|
156
|
+
const nonceHash = crypto.createHash("sha256").update(nonce).digest("hex");
|
|
157
|
+
if (claims.nonce_sha256 !== nonceHash) {
|
|
158
|
+
throw new Error("nonce mismatch: the statement answers a different challenge");
|
|
159
|
+
}
|
|
160
|
+
if (!(claims.exp > Date.now() / 1000)) {
|
|
161
|
+
throw new Error("statement expired — verify again");
|
|
162
|
+
}
|
|
163
|
+
return claims;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async function verify(args) {
|
|
167
|
+
const flags = {};
|
|
168
|
+
const positional = [];
|
|
169
|
+
for (let i = 0; i < args.length; i++) {
|
|
170
|
+
if (args[i].startsWith("--")) {
|
|
171
|
+
flags[args[i]] = args[i + 1];
|
|
172
|
+
i++;
|
|
173
|
+
} else {
|
|
174
|
+
positional.push(args[i]);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
const shineId = positional[0];
|
|
178
|
+
if (!shineId) {
|
|
179
|
+
process.stderr.write("usage: npx @kyde/score verify <shine-id> " +
|
|
180
|
+
"[--challenger <name>] [--session <s>] [--timeout <seconds>]\n");
|
|
181
|
+
process.exit(2);
|
|
182
|
+
}
|
|
183
|
+
const challenger = flags["--challenger"] || `npx-verify@${os.hostname()}`;
|
|
184
|
+
const session = flags["--session"] || "";
|
|
185
|
+
const timeoutS = Number(flags["--timeout"] || "300");
|
|
186
|
+
const nonce = crypto.randomBytes(18).toString("base64url");
|
|
187
|
+
|
|
188
|
+
const created = await shineJson("POST", "/shine/v0/challenges", {
|
|
189
|
+
shine_id: shineId,
|
|
190
|
+
nonce,
|
|
191
|
+
challenger,
|
|
192
|
+
session,
|
|
193
|
+
});
|
|
194
|
+
if (created.status !== 202) {
|
|
195
|
+
throw new Error(`shine rejected the challenge (${created.status}): ` +
|
|
196
|
+
`${created.payload.detail || JSON.stringify(created.payload)}`);
|
|
197
|
+
}
|
|
198
|
+
const { challenge_id: challengeId, result_token: resultToken } =
|
|
199
|
+
created.payload;
|
|
200
|
+
process.stderr.write(
|
|
201
|
+
`challenge ${challengeId} sent to ${shineId} as "${challenger}" — ` +
|
|
202
|
+
"waiting for the agent to confirm (it may poll only every 30 s)\n",
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
const deadline = Date.now() + timeoutS * 1000;
|
|
206
|
+
for (;;) {
|
|
207
|
+
const res = await shineJson(
|
|
208
|
+
"GET",
|
|
209
|
+
`/shine/v0/challenges/${challengeId}/result`,
|
|
210
|
+
undefined,
|
|
211
|
+
{ "x-shine-result-token": resultToken },
|
|
212
|
+
);
|
|
213
|
+
if (res.status !== 200) {
|
|
214
|
+
throw new Error(`shine result lookup failed (${res.status})`);
|
|
215
|
+
}
|
|
216
|
+
if (res.payload.status === "confirmed") {
|
|
217
|
+
const jwks = (await shineJson("GET", "/.well-known/jwks.json")).payload;
|
|
218
|
+
const claims = verifyStatement(res.payload.statement, jwks, nonce);
|
|
219
|
+
const summary =
|
|
220
|
+
claims.band === "learning"
|
|
221
|
+
? "identity confirmed; behavior not yet scored (learning, <30 " +
|
|
222
|
+
"runs) — delegating to a learning agent is your policy call"
|
|
223
|
+
: claims.measured
|
|
224
|
+
? `identity confirmed; band ${claims.band}, score ${claims.score}` +
|
|
225
|
+
` over ${claims.runs} runs`
|
|
226
|
+
: "identity confirmed; no behavioral measurement available " +
|
|
227
|
+
"(measured: false)";
|
|
228
|
+
process.stderr.write(
|
|
229
|
+
`confirmed and verified against ${SHINE}/.well-known/jwks.json\n` +
|
|
230
|
+
`${summary}\n`,
|
|
231
|
+
);
|
|
232
|
+
process.stdout.write(
|
|
233
|
+
JSON.stringify(
|
|
234
|
+
{ status: "confirmed", verified: true, claims,
|
|
235
|
+
statement: res.payload.statement,
|
|
236
|
+
jwks_url: `${SHINE}/.well-known/jwks.json` },
|
|
237
|
+
null,
|
|
238
|
+
2,
|
|
239
|
+
) + "\n",
|
|
240
|
+
);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (res.payload.status === "expired" || Date.now() >= deadline) {
|
|
244
|
+
process.stderr.write(
|
|
245
|
+
"not confirmed: the agent did not answer before the challenge " +
|
|
246
|
+
"expired — identity not proven (there is no attest fallback " +
|
|
247
|
+
"by design)\n",
|
|
248
|
+
);
|
|
249
|
+
process.stdout.write(JSON.stringify(
|
|
250
|
+
{ status: res.payload.status === "expired" ? "expired" : "timeout",
|
|
251
|
+
verified: false }) + "\n");
|
|
252
|
+
process.exit(3);
|
|
253
|
+
}
|
|
254
|
+
await new Promise((r) => setTimeout(r, 3000));
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
99
258
|
const arg = process.argv[2];
|
|
100
259
|
if (arg === "init") {
|
|
101
260
|
init();
|
|
261
|
+
} else if (arg === "verify") {
|
|
262
|
+
verify(process.argv.slice(3)).catch((err) => {
|
|
263
|
+
process.stderr.write(`kyde verify: ${err.message}\n`);
|
|
264
|
+
process.exit(1);
|
|
265
|
+
});
|
|
102
266
|
} else if (arg === "prompt") {
|
|
103
267
|
process.stdout.write(SETUP_PROMPT + "\n");
|
|
104
268
|
} else if (!arg || arg === "--help" || arg === "-h" || arg === "help") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kyde/score",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "KYDE Score setup: `npx @kyde/score init` wires an agent harness (Claude Code first) to score.kyde.com — OpenTelemetry export plus the warn/pause hook, in one step.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent",
|
|
@@ -8,7 +8,11 @@
|
|
|
8
8
|
"opentelemetry",
|
|
9
9
|
"claude-code",
|
|
10
10
|
"drift",
|
|
11
|
-
"monitoring"
|
|
11
|
+
"monitoring",
|
|
12
|
+
"verify-agent",
|
|
13
|
+
"agent-status",
|
|
14
|
+
"delegation",
|
|
15
|
+
"trust"
|
|
12
16
|
],
|
|
13
17
|
"homepage": "https://score.kyde.com",
|
|
14
18
|
"license": "MIT",
|