tryharness 0.7.82 → 0.7.86
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 +21 -19
- package/assets/dsh-plugin.mjs +75 -4
- package/assets/herdr-mod/harness/main.js +367 -0
- package/assets/herdr-mod/harness/mod.json +6 -0
- package/assets/opencode-plugin.js +87 -22
- package/assets/pi-extension.ts +81 -2
- package/cli.mjs +544 -208
- package/lib/adapters.mjs +62 -27
- package/lib/agentBinaries.mjs +6 -8
- package/lib/agentClaims.mjs +168 -0
- package/lib/agentReadTools.json +415 -0
- package/lib/agentSignIn.mjs +17 -18
- package/lib/agentWiring.mjs +114 -0
- package/lib/archetypes.js +10 -11
- package/lib/attention.mjs +100 -0
- package/lib/audit.mjs +1 -1
- package/lib/backupSetup.mjs +6 -28
- package/lib/bankrApprovals.mjs +86 -0
- package/lib/boardAccess.mjs +40 -66
- package/lib/boardBackup.mjs +86 -85
- package/lib/boardCommands.mjs +28 -0
- package/lib/boardFileCommands.mjs +29 -36
- package/lib/boardFiles.mjs +83 -15
- package/lib/boardMirror.mjs +78 -11
- package/lib/boardProtocol.json +193 -123
- package/lib/boardThreads.mjs +19 -37
- package/lib/boardTools.mjs +22 -15
- package/lib/boardWatches.mjs +43 -15
- package/lib/bridge.mjs +7 -3
- package/lib/browserAgentTools.mjs +59 -0
- package/lib/browserWake.mjs +0 -6
- package/lib/cards.mjs +57 -2
- package/lib/circling.mjs +189 -0
- package/lib/cleanup.mjs +234 -0
- package/lib/cloudBoot.mjs +21 -4
- package/lib/cloudSave.mjs +46 -5
- package/lib/compaction.mjs +8 -1
- package/lib/completion.mjs +358 -0
- package/lib/computerDevices.mjs +853 -0
- package/lib/connectionStatus.mjs +34 -0
- package/lib/connectors.mjs +139 -1
- package/lib/coordinator.mjs +108 -14
- package/lib/coreModels.mjs +36 -12
- package/lib/daemon.mjs +2435 -333
- package/lib/daemonLock.mjs +103 -0
- package/lib/deviceDoor.mjs +308 -0
- package/lib/deviceIdentity.mjs +114 -0
- package/lib/deviceList.mjs +172 -0
- package/lib/deviceSeal.mjs +74 -0
- package/lib/dispatcher.mjs +497 -26
- package/lib/dispatches.mjs +3 -3
- package/lib/environment.mjs +2 -1
- package/lib/environments.mjs +67 -41
- package/lib/events.mjs +318 -0
- package/lib/facts.mjs +170 -0
- package/lib/fileSource.mjs +540 -0
- package/lib/files.mjs +47 -2
- package/lib/gitHost.mjs +39 -1
- package/lib/goalCommands.mjs +12 -80
- package/lib/handover.mjs +21 -16
- package/lib/harnessOffers.mjs +140 -15
- package/lib/herdr.mjs +100 -15
- package/lib/herdrAppCall.mjs +19 -0
- package/lib/herdrCore.mjs +59 -0
- package/lib/herdrRuns.mjs +1126 -0
- package/lib/hookDialects.mjs +235 -50
- package/lib/identityLink.mjs +81 -0
- package/lib/inference.mjs +31 -2
- package/lib/jamAccess.mjs +82 -0
- package/lib/{projectBoard.mjs → jamBoard.mjs} +5 -4
- package/lib/{projectGit.mjs → jamGit.mjs} +53 -15
- package/lib/jamKey.mjs +274 -0
- package/lib/{projectPieces.mjs → jamPieces.mjs} +35 -29
- package/lib/{projectSettings.mjs → jamSettings.mjs} +12 -22
- package/lib/jamStore.mjs +973 -0
- package/lib/jamUpgrade.mjs +112 -0
- package/lib/jams.mjs +3079 -0
- package/lib/kanban.mjs +13 -7
- package/lib/landed.mjs +5 -1
- package/lib/library.mjs +41 -22
- package/lib/limits.mjs +91 -0
- package/lib/lineDiff.mjs +97 -0
- package/lib/lineup.mjs +18 -13
- package/lib/link.mjs +584 -0
- package/lib/localStack.mjs +75 -16
- package/lib/localmodels.mjs +58 -78
- package/lib/loopBackstop.mjs +2 -1
- package/lib/machine.mjs +544 -0
- package/lib/machineLink.mjs +446 -0
- package/lib/machineRoutes.mjs +68 -19
- package/lib/machineRuns.mjs +85 -4
- package/lib/machineSeal.mjs +6 -31
- package/lib/manager.mjs +134 -12
- package/lib/mcp-stdio.mjs +492 -215
- package/lib/mcpRelay.mjs +34 -35
- package/lib/members.json +2 -2
- package/lib/modelRoute.mjs +162 -0
- package/lib/nativeHost.mjs +81 -90
- package/lib/nativeSenses.mjs +258 -0
- package/lib/nerves.mjs +523 -0
- package/lib/network.mjs +117 -278
- package/lib/networkPlaces.mjs +578 -0
- package/lib/nextStep.mjs +95 -0
- package/lib/notify.mjs +2 -2
- package/lib/nudge.mjs +116 -10
- package/lib/onboard.mjs +6 -6
- package/lib/originals.mjs +216 -0
- package/lib/outsideEvents.mjs +383 -0
- package/lib/outsideRuns.mjs +230 -0
- package/lib/ownMachines.mjs +674 -256
- package/lib/pain.mjs +215 -0
- package/lib/pairing.mjs +91 -11
- package/lib/paths.mjs +42 -3
- package/lib/peerProcess.mjs +21 -7
- package/lib/peopleLink.mjs +268 -0
- package/lib/personNotices.mjs +3 -2
- package/lib/phones.mjs +252 -542
- package/lib/placeCards.mjs +282 -0
- package/lib/placeChecks.mjs +95 -0
- package/lib/placeCommands.mjs +8 -17
- package/lib/placeRequests.mjs +152 -0
- package/lib/placeStore.mjs +295 -0
- package/lib/placeTool.d.ts +12 -0
- package/lib/placeTool.js +40 -0
- package/lib/places.mjs +63 -14
- package/lib/plans.mjs +53 -8
- package/lib/presence.mjs +270 -0
- package/lib/privateNetwork.d.ts +2 -0
- package/lib/privateNetwork.js +93 -0
- package/lib/proposals.mjs +300 -0
- package/lib/publicFetch.d.ts +32 -0
- package/lib/publicFetch.js +248 -0
- package/lib/reach.mjs +128 -0
- package/lib/rebuildable.mjs +72 -0
- package/lib/recall.mjs +216 -0
- package/lib/record.mjs +13 -0
- package/lib/reflexes.mjs +392 -0
- package/lib/relayLimits.mjs +31 -2
- package/lib/releaseNotice.mjs +198 -0
- package/lib/removeHarness.mjs +15 -4
- package/lib/repoLinks.mjs +204 -35
- package/lib/runAuthority.mjs +102 -39
- package/lib/runBrief.mjs +93 -40
- package/lib/runRequests.mjs +52 -14
- package/lib/runUsage.mjs +31 -0
- package/lib/runWorker.mjs +74 -25
- package/lib/runner.mjs +289 -45
- package/lib/runtime-install.mjs +37 -8
- package/lib/schedules.mjs +171 -47
- package/lib/screenWatches.mjs +221 -0
- package/lib/sealed.mjs +12 -30
- package/lib/sealedThreads.mjs +198 -392
- package/lib/secretStore.mjs +178 -0
- package/lib/secrets.mjs +11 -0
- package/lib/seen.mjs +3 -9
- package/lib/selfUpdate.mjs +51 -15
- package/lib/senseCall.mjs +1514 -0
- package/lib/senseHook.mjs +114 -0
- package/lib/senseTools.mjs +1298 -0
- package/lib/sessionBriefs.mjs +87 -0
- package/lib/sessionControl.mjs +63 -13
- package/lib/sessionFiles.mjs +85 -0
- package/lib/setupChoices.mjs +12 -3
- package/lib/setupMode.mjs +70 -25
- package/lib/sharedKeys.mjs +166 -0
- package/lib/sleep.mjs +396 -0
- package/lib/sources.mjs +306 -0
- package/lib/speech.mjs +166 -411
- package/lib/spoken.mjs +210 -0
- package/lib/steerHook.mjs +3 -1
- package/lib/steerQueue.mjs +40 -11
- package/lib/store.mjs +323 -130
- package/lib/stuck.mjs +85 -7
- package/lib/swarm.mjs +157 -49
- package/lib/swarmDevices.mjs +25 -85
- package/lib/swarmMemory.mjs +93 -9
- package/lib/t3.mjs +73 -3
- package/lib/taskCommands.mjs +51 -60
- package/lib/taskRooms.mjs +30 -4
- package/lib/taskRules.json +29 -0
- package/lib/taskRules.mjs +21 -0
- package/lib/taskRuns.mjs +74 -11
- package/lib/team.mjs +2 -1
- package/lib/threadActions.mjs +37 -9
- package/lib/threadAuthority.mjs +4 -4
- package/lib/threadBriefs.mjs +173 -43
- package/lib/threadNotes.mjs +320 -0
- package/lib/threadRecord.mjs +491 -0
- package/lib/threadRuns.mjs +216 -108
- package/lib/threadView.mjs +27 -30
- package/lib/threadWatches.mjs +1962 -0
- package/lib/timeSense.mjs +839 -0
- package/lib/tripwires.mjs +454 -0
- package/lib/ui.mjs +1 -1
- package/lib/vault.mjs +560 -45
- package/lib/vaultCommands.mjs +5 -3
- package/lib/vaultPeers.mjs +165 -0
- package/lib/vaultTools.d.ts +4 -1
- package/lib/vaultTools.js +22 -1
- package/lib/verdicts.mjs +12 -26
- package/lib/versions.mjs +117 -0
- package/lib/waitTool.mjs +278 -0
- package/lib/wakePicture.mjs +268 -0
- package/lib/wakeQueue.mjs +108 -0
- package/lib/watchResponses.mjs +533 -0
- package/lib/watches.mjs +290 -145
- package/lib/windowAsks.mjs +80 -17
- package/lib/worktrees.mjs +159 -9
- package/npm-shrinkwrap.json +138 -631
- package/package.json +7 -6
- package/release.json +212 -130
- package/lib/callSessions.mjs +0 -51
- package/lib/directLink.mjs +0 -349
- package/lib/peopleBoard.mjs +0 -131
- package/lib/projects.mjs +0 -2917
- package/lib/roomChannels.mjs +0 -667
package/lib/adapters.mjs
CHANGED
|
@@ -2,15 +2,16 @@ import fs from "node:fs";
|
|
|
2
2
|
import os from "node:os";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { detectAgents, run } from "./commands.mjs";
|
|
5
|
-
import { ensureDir,
|
|
5
|
+
import { ensureDir, updateJson } from "./files.mjs";
|
|
6
6
|
import { MACHINE_RUNNERS } from "./members.mjs";
|
|
7
7
|
import {
|
|
8
8
|
HOOK_AGENTS,
|
|
9
|
+
hookDialect,
|
|
9
10
|
installSessionHooks,
|
|
10
11
|
removeSessionHooks,
|
|
11
12
|
sessionHooksPath,
|
|
12
13
|
} from "./hookDialects.mjs";
|
|
13
|
-
import { harnessNode } from "./paths.mjs";
|
|
14
|
+
import { harnessNode, stableRuntimeRoot } from "./paths.mjs";
|
|
14
15
|
|
|
15
16
|
export const AGENTS = MACHINE_RUNNERS;
|
|
16
17
|
|
|
@@ -119,9 +120,13 @@ function installAsset(
|
|
|
119
120
|
{ runtimeRoot, nodePath = harnessNode(), agent = "" }
|
|
120
121
|
) {
|
|
121
122
|
ensureDir(path.dirname(target));
|
|
123
|
+
// By the name that stays the same across Harness's updates, as the agents' hooks are (hookDialects.mjs).
|
|
122
124
|
const text = fs
|
|
123
125
|
.readFileSync(source, "utf8")
|
|
124
|
-
.replaceAll(
|
|
126
|
+
.replaceAll(
|
|
127
|
+
'"__HARNESS_RUNTIME__"',
|
|
128
|
+
JSON.stringify(stableRuntimeRoot(runtimeRoot))
|
|
129
|
+
)
|
|
125
130
|
.replaceAll('"__HARNESS_NODE__"', JSON.stringify(nodePath))
|
|
126
131
|
.replaceAll('"__HARNESS_AGENT__"', JSON.stringify(agent));
|
|
127
132
|
fs.writeFileSync(target, text, { mode: 0o600 });
|
|
@@ -244,16 +249,13 @@ const MCP_SETUP = {
|
|
|
244
249
|
};
|
|
245
250
|
|
|
246
251
|
function writeMcpEntry(file, entry) {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
file,
|
|
255
|
-
JSON.stringify({ ...config, mcpServers: servers }, null, 2) + "\n"
|
|
256
|
-
);
|
|
252
|
+
updateJson(file, (config) => {
|
|
253
|
+
const servers = { ...(config.mcpServers ?? {}) };
|
|
254
|
+
if (entry) servers.harness = entry;
|
|
255
|
+
else if (!servers.harness) return null;
|
|
256
|
+
else delete servers.harness;
|
|
257
|
+
return { ...config, mcpServers: servers };
|
|
258
|
+
});
|
|
257
259
|
}
|
|
258
260
|
|
|
259
261
|
/** Harness's MCP server in a hook agent's own config: the command's result, or the file written. */
|
|
@@ -261,11 +263,15 @@ function addMcpServer(agent, executable, { mcpPath, homeDir, execute }) {
|
|
|
261
263
|
const setup = MCP_SETUP[agent];
|
|
262
264
|
const server = [mcpPath, "--agent", agent, ...(setup.flags ?? [])];
|
|
263
265
|
if (setup.file) {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
266
|
+
try {
|
|
267
|
+
writeMcpEntry(setup.file(homeDir), {
|
|
268
|
+
...setup.entry,
|
|
269
|
+
command: harnessNode(),
|
|
270
|
+
args: server,
|
|
271
|
+
});
|
|
272
|
+
} catch (error) {
|
|
273
|
+
return { ok: false, error: error.message };
|
|
274
|
+
}
|
|
269
275
|
if (setup.enable) execute(executable, setup.enable);
|
|
270
276
|
return { ok: true };
|
|
271
277
|
}
|
|
@@ -279,6 +285,13 @@ function removeMcpServer(agent, executable, { homeDir, execute }) {
|
|
|
279
285
|
else execute(executable, setup.remove);
|
|
280
286
|
}
|
|
281
287
|
|
|
288
|
+
// An agent's own version, asked only where one of Harness's hooks works from a version on (hookDialects.mjs).
|
|
289
|
+
function versionOf(agent, executable, execute) {
|
|
290
|
+
if (!hookDialect(agent).afterSince) return null;
|
|
291
|
+
const said = execute(executable, ["--version"], { timeout: 10_000 });
|
|
292
|
+
return said?.ok ? `${said.stdout} ${said.stderr}` : null;
|
|
293
|
+
}
|
|
294
|
+
|
|
282
295
|
export function configureAgents({
|
|
283
296
|
runtimeRoot,
|
|
284
297
|
selected = AGENTS,
|
|
@@ -317,10 +330,16 @@ export function configureAgents({
|
|
|
317
330
|
execute,
|
|
318
331
|
});
|
|
319
332
|
let hooked = true;
|
|
333
|
+
let unhooked = "";
|
|
320
334
|
try {
|
|
321
|
-
installSessionHooks(agent, {
|
|
322
|
-
|
|
335
|
+
installSessionHooks(agent, {
|
|
336
|
+
runtimeRoot,
|
|
337
|
+
homeDir,
|
|
338
|
+
version: versionOf(agent, found.path, execute),
|
|
339
|
+
});
|
|
340
|
+
} catch (error) {
|
|
323
341
|
hooked = false;
|
|
342
|
+
unhooked = error.message;
|
|
324
343
|
}
|
|
325
344
|
const note = MCP_SETUP[agent].note;
|
|
326
345
|
states.push({
|
|
@@ -330,7 +349,7 @@ export function configureAgents({
|
|
|
330
349
|
detail: added.ok
|
|
331
350
|
? hooked
|
|
332
351
|
? `MCP and session hooks configured${note ? `; ${note}` : ""}`
|
|
333
|
-
:
|
|
352
|
+
: `MCP configured; the session hooks could not be written: ${unhooked}`
|
|
334
353
|
: diagnostic(added),
|
|
335
354
|
});
|
|
336
355
|
} else if (agent === "pi") {
|
|
@@ -408,8 +427,17 @@ export function removeAgentConfigurations({
|
|
|
408
427
|
} = {}) {
|
|
409
428
|
for (const found of detected) {
|
|
410
429
|
if (!found.path || !HOOK_AGENTS.includes(found.agent)) continue;
|
|
411
|
-
|
|
412
|
-
|
|
430
|
+
// A settings file Harness cannot read is left as it is; the rest still comes out.
|
|
431
|
+
try {
|
|
432
|
+
removeMcpServer(found.agent, found.path, { homeDir, execute });
|
|
433
|
+
} catch (error) {
|
|
434
|
+
console.warn(error.message);
|
|
435
|
+
}
|
|
436
|
+
try {
|
|
437
|
+
removeSessionHooks(found.agent, homeDir);
|
|
438
|
+
} catch (error) {
|
|
439
|
+
console.warn(error.message);
|
|
440
|
+
}
|
|
413
441
|
}
|
|
414
442
|
// opencode and Kilo have no `mcp remove`, so the entry comes out of the config file `mcp add` wrote it to.
|
|
415
443
|
for (const file of [
|
|
@@ -420,10 +448,17 @@ export function removeAgentConfigurations({
|
|
|
420
448
|
(name) => path.join(homeDir, ".config", "kilo", name)
|
|
421
449
|
),
|
|
422
450
|
]) {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
451
|
+
if (!fs.existsSync(file)) continue;
|
|
452
|
+
try {
|
|
453
|
+
updateJson(file, (config) => {
|
|
454
|
+
if (!config.mcp?.harness) return null;
|
|
455
|
+
const { harness: _harness, ...mcp } = config.mcp;
|
|
456
|
+
return { ...config, mcp };
|
|
457
|
+
});
|
|
458
|
+
} catch (error) {
|
|
459
|
+
// Left as it is: its harness entry has to come out by hand.
|
|
460
|
+
console.warn(error.message);
|
|
461
|
+
}
|
|
427
462
|
}
|
|
428
463
|
writeDshRows(homeDir);
|
|
429
464
|
const assets = integrationAssets(homeDir);
|
package/lib/agentBinaries.mjs
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import { AGENT_COMMANDS, resolveCommand } from "./commands.mjs";
|
|
8
8
|
import { runtimeOf } from "./agentRuntimeConfig.mjs";
|
|
9
|
-
import { readJson,
|
|
9
|
+
import { readJson, updateJson } from "./files.mjs";
|
|
10
10
|
import { paths } from "./paths.mjs";
|
|
11
11
|
import { relayCommand } from "./runtime-install.mjs";
|
|
12
12
|
|
|
@@ -26,15 +26,14 @@ export function confirmAgentBinary(
|
|
|
26
26
|
const command = agentCommand(agent);
|
|
27
27
|
const found = command && resolveCommand(command, env);
|
|
28
28
|
if (!found) return null;
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
writeJsonAtomic(file, {
|
|
29
|
+
const before = readJson(file, {}).agentBinaries?.[agent]?.path ?? null;
|
|
30
|
+
updateJson(file, (config) => ({
|
|
32
31
|
...config,
|
|
33
32
|
agentBinaries: {
|
|
34
33
|
...config.agentBinaries,
|
|
35
34
|
[agent]: { command, path: found },
|
|
36
35
|
},
|
|
37
|
-
});
|
|
36
|
+
}));
|
|
38
37
|
return { path: found, previous: before && before !== found ? before : null };
|
|
39
38
|
}
|
|
40
39
|
|
|
@@ -52,14 +51,13 @@ export function agentBinary(
|
|
|
52
51
|
if (!recorded || recorded.command !== command) {
|
|
53
52
|
const found = resolveCommand(command, env);
|
|
54
53
|
if (!found) return null;
|
|
55
|
-
|
|
56
|
-
writeJsonAtomic(file, {
|
|
54
|
+
updateJson(file, (config) => ({
|
|
57
55
|
...config,
|
|
58
56
|
agentBinaries: {
|
|
59
57
|
...config.agentBinaries,
|
|
60
58
|
[agent]: { command, path: found },
|
|
61
59
|
},
|
|
62
|
-
});
|
|
60
|
+
}));
|
|
63
61
|
return found;
|
|
64
62
|
}
|
|
65
63
|
if (resolveCommand(recorded.path, env)) return recorded.path;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { createHash, webcrypto } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
// Which agent made a call, checkable by anyone who knows the person (owner, November 14: an agent's identity is the
|
|
4
|
+
// person's key plus the computer plus the agent's name, signed by the computer). The computer an agent runs on signs a
|
|
5
|
+
// claim at the moment the agent asks: this agent, on this computer, for this person, at this time, about exactly this
|
|
6
|
+
// (a hash of the request or the words). Beside it travels the computer's certificate: its own signing key, signed with
|
|
7
|
+
// the person's identity (identityLink.mjs), so a friend who pinned the identity can check a computer they never saw.
|
|
8
|
+
// Harness checks the claim against the person's signed device list instead (src/shared/agentClaim.ts).
|
|
9
|
+
//
|
|
10
|
+
// What a claim does not do: stop one agent on a computer from naming itself as another there. The computer signs what
|
|
11
|
+
// the agent's own connection to it says; keeping agents apart on one computer is containment, parked.
|
|
12
|
+
|
|
13
|
+
const { subtle } = webcrypto;
|
|
14
|
+
const SIGNING = { name: "ECDSA", namedCurve: "P-256" };
|
|
15
|
+
const SIGNATURE = { name: "ECDSA", hash: "SHA-256" };
|
|
16
|
+
const toBase64 = (bytes) => Buffer.from(bytes).toString("base64");
|
|
17
|
+
const fromBase64 = (text) =>
|
|
18
|
+
new Uint8Array(Buffer.from(String(text), "base64"));
|
|
19
|
+
|
|
20
|
+
const claimBytes = (claim) =>
|
|
21
|
+
new TextEncoder().encode(
|
|
22
|
+
[
|
|
23
|
+
"harness agent claim v1",
|
|
24
|
+
claim.identity,
|
|
25
|
+
claim.deviceId,
|
|
26
|
+
claim.agent,
|
|
27
|
+
claim.at,
|
|
28
|
+
claim.about,
|
|
29
|
+
].join("\n")
|
|
30
|
+
);
|
|
31
|
+
const certBytes = ({ identity, deviceId, signingKey }) =>
|
|
32
|
+
new TextEncoder().encode(
|
|
33
|
+
["harness device v1", identity, deviceId, signingKey].join("\n")
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
/** What a claim is about: a SHA-256 of the exact words or request, base64. */
|
|
37
|
+
export const aboutOf = (value) =>
|
|
38
|
+
createHash("sha256")
|
|
39
|
+
.update(typeof value === "string" ? value : JSON.stringify(value))
|
|
40
|
+
.digest("base64");
|
|
41
|
+
|
|
42
|
+
/** One agent's stable identity: the person's key, the computer and the agent's name. */
|
|
43
|
+
export const agentIdOf = (claim) =>
|
|
44
|
+
`${createHash("sha256").update(String(claim.identity)).digest("hex").slice(0, 16)}/${claim.deviceId}/${claim.agent}`;
|
|
45
|
+
|
|
46
|
+
async function verifies(publicKey, signature, bytes) {
|
|
47
|
+
try {
|
|
48
|
+
const key = await subtle.importKey(
|
|
49
|
+
"raw",
|
|
50
|
+
fromBase64(publicKey),
|
|
51
|
+
SIGNING,
|
|
52
|
+
false,
|
|
53
|
+
["verify"]
|
|
54
|
+
);
|
|
55
|
+
return await subtle.verify(SIGNATURE, key, fromBase64(signature), bytes);
|
|
56
|
+
} catch {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* A computer's claims. `device()`: this computer's id and signing key pair (deviceIdentity.mjs). `identity()`: the
|
|
63
|
+
* person's identity as it holds it ({ signingKey, signingPrivateKey }), or null while it holds none, when no claim is
|
|
64
|
+
* made.
|
|
65
|
+
*/
|
|
66
|
+
export function createAgentClaims({ device, identity }) {
|
|
67
|
+
let cert = null;
|
|
68
|
+
const certFor = async (me, held) => {
|
|
69
|
+
if (cert?.identity === held.signingKey) return cert.value;
|
|
70
|
+
const value = toBase64(
|
|
71
|
+
new Uint8Array(
|
|
72
|
+
await subtle.sign(
|
|
73
|
+
SIGNATURE,
|
|
74
|
+
held.signingPrivateKey,
|
|
75
|
+
certBytes({
|
|
76
|
+
identity: held.signingKey,
|
|
77
|
+
deviceId: me.deviceId,
|
|
78
|
+
signingKey: me.signing.publicKey,
|
|
79
|
+
})
|
|
80
|
+
)
|
|
81
|
+
)
|
|
82
|
+
);
|
|
83
|
+
cert = { identity: held.signingKey, value };
|
|
84
|
+
return value;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/** This computer's claim that `agent` asked for `about`, or null while it holds no identity. */
|
|
88
|
+
const mint = async (agent, about) => {
|
|
89
|
+
const me = await device();
|
|
90
|
+
const held = await identity();
|
|
91
|
+
if (!me || !held?.signingKey) return null;
|
|
92
|
+
const unsigned = {
|
|
93
|
+
v: 1,
|
|
94
|
+
agent: String(agent),
|
|
95
|
+
deviceId: me.deviceId,
|
|
96
|
+
identity: held.signingKey,
|
|
97
|
+
at: new Date().toISOString(),
|
|
98
|
+
about,
|
|
99
|
+
};
|
|
100
|
+
const signature = toBase64(
|
|
101
|
+
new Uint8Array(
|
|
102
|
+
await subtle.sign(
|
|
103
|
+
SIGNATURE,
|
|
104
|
+
me.signing.privateKey,
|
|
105
|
+
claimBytes(unsigned)
|
|
106
|
+
)
|
|
107
|
+
)
|
|
108
|
+
);
|
|
109
|
+
return {
|
|
110
|
+
...unsigned,
|
|
111
|
+
signature,
|
|
112
|
+
device: {
|
|
113
|
+
signingKey: me.signing.publicKey,
|
|
114
|
+
cert: await certFor(me, held),
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
return { mint };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Whether a claim holds for someone who knows the person's identity: one of `identitySigningKeys` (theirs now, or
|
|
124
|
+
* before their keys changed) certified the computer's key, that key signed the claim, and it is about `about`.
|
|
125
|
+
*/
|
|
126
|
+
export async function claimHolds(claim, { identitySigningKeys, about }) {
|
|
127
|
+
if (
|
|
128
|
+
claim?.v !== 1 ||
|
|
129
|
+
typeof claim.agent !== "string" ||
|
|
130
|
+
typeof claim.deviceId !== "string" ||
|
|
131
|
+
typeof claim.signature !== "string" ||
|
|
132
|
+
typeof claim.device?.signingKey !== "string" ||
|
|
133
|
+
typeof claim.device?.cert !== "string" ||
|
|
134
|
+
claim.about !== about ||
|
|
135
|
+
!identitySigningKeys.includes(claim.identity)
|
|
136
|
+
)
|
|
137
|
+
return false;
|
|
138
|
+
const certified = await verifies(
|
|
139
|
+
claim.identity,
|
|
140
|
+
claim.device.cert,
|
|
141
|
+
certBytes({
|
|
142
|
+
identity: claim.identity,
|
|
143
|
+
deviceId: claim.deviceId,
|
|
144
|
+
signingKey: claim.device.signingKey,
|
|
145
|
+
})
|
|
146
|
+
);
|
|
147
|
+
return (
|
|
148
|
+
certified &&
|
|
149
|
+
(await verifies(
|
|
150
|
+
claim.device.signingKey,
|
|
151
|
+
claim.signature,
|
|
152
|
+
claimBytes(claim)
|
|
153
|
+
))
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Whether the computer whose signing key is `deviceSigningKey` (read from the person's signed device list) signed this
|
|
159
|
+
* claim, about `about`: what one of the person's own computers checks, which needs no certificate.
|
|
160
|
+
*/
|
|
161
|
+
export async function claimSignedBy(claim, deviceSigningKey, about) {
|
|
162
|
+
return (
|
|
163
|
+
claim?.v === 1 &&
|
|
164
|
+
claim.about === about &&
|
|
165
|
+
typeof claim.signature === "string" &&
|
|
166
|
+
(await verifies(deviceSigningKey, claim.signature, claimBytes(claim)))
|
|
167
|
+
);
|
|
168
|
+
}
|