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.
Files changed (216) hide show
  1. package/README.md +21 -19
  2. package/assets/dsh-plugin.mjs +75 -4
  3. package/assets/herdr-mod/harness/main.js +367 -0
  4. package/assets/herdr-mod/harness/mod.json +6 -0
  5. package/assets/opencode-plugin.js +87 -22
  6. package/assets/pi-extension.ts +81 -2
  7. package/cli.mjs +544 -208
  8. package/lib/adapters.mjs +62 -27
  9. package/lib/agentBinaries.mjs +6 -8
  10. package/lib/agentClaims.mjs +168 -0
  11. package/lib/agentReadTools.json +415 -0
  12. package/lib/agentSignIn.mjs +17 -18
  13. package/lib/agentWiring.mjs +114 -0
  14. package/lib/archetypes.js +10 -11
  15. package/lib/attention.mjs +100 -0
  16. package/lib/audit.mjs +1 -1
  17. package/lib/backupSetup.mjs +6 -28
  18. package/lib/bankrApprovals.mjs +86 -0
  19. package/lib/boardAccess.mjs +40 -66
  20. package/lib/boardBackup.mjs +86 -85
  21. package/lib/boardCommands.mjs +28 -0
  22. package/lib/boardFileCommands.mjs +29 -36
  23. package/lib/boardFiles.mjs +83 -15
  24. package/lib/boardMirror.mjs +78 -11
  25. package/lib/boardProtocol.json +193 -123
  26. package/lib/boardThreads.mjs +19 -37
  27. package/lib/boardTools.mjs +22 -15
  28. package/lib/boardWatches.mjs +43 -15
  29. package/lib/bridge.mjs +7 -3
  30. package/lib/browserAgentTools.mjs +59 -0
  31. package/lib/browserWake.mjs +0 -6
  32. package/lib/cards.mjs +57 -2
  33. package/lib/circling.mjs +189 -0
  34. package/lib/cleanup.mjs +234 -0
  35. package/lib/cloudBoot.mjs +21 -4
  36. package/lib/cloudSave.mjs +46 -5
  37. package/lib/compaction.mjs +8 -1
  38. package/lib/completion.mjs +358 -0
  39. package/lib/computerDevices.mjs +853 -0
  40. package/lib/connectionStatus.mjs +34 -0
  41. package/lib/connectors.mjs +139 -1
  42. package/lib/coordinator.mjs +108 -14
  43. package/lib/coreModels.mjs +36 -12
  44. package/lib/daemon.mjs +2435 -333
  45. package/lib/daemonLock.mjs +103 -0
  46. package/lib/deviceDoor.mjs +308 -0
  47. package/lib/deviceIdentity.mjs +114 -0
  48. package/lib/deviceList.mjs +172 -0
  49. package/lib/deviceSeal.mjs +74 -0
  50. package/lib/dispatcher.mjs +497 -26
  51. package/lib/dispatches.mjs +3 -3
  52. package/lib/environment.mjs +2 -1
  53. package/lib/environments.mjs +67 -41
  54. package/lib/events.mjs +318 -0
  55. package/lib/facts.mjs +170 -0
  56. package/lib/fileSource.mjs +540 -0
  57. package/lib/files.mjs +47 -2
  58. package/lib/gitHost.mjs +39 -1
  59. package/lib/goalCommands.mjs +12 -80
  60. package/lib/handover.mjs +21 -16
  61. package/lib/harnessOffers.mjs +140 -15
  62. package/lib/herdr.mjs +100 -15
  63. package/lib/herdrAppCall.mjs +19 -0
  64. package/lib/herdrCore.mjs +59 -0
  65. package/lib/herdrRuns.mjs +1126 -0
  66. package/lib/hookDialects.mjs +235 -50
  67. package/lib/identityLink.mjs +81 -0
  68. package/lib/inference.mjs +31 -2
  69. package/lib/jamAccess.mjs +82 -0
  70. package/lib/{projectBoard.mjs → jamBoard.mjs} +5 -4
  71. package/lib/{projectGit.mjs → jamGit.mjs} +53 -15
  72. package/lib/jamKey.mjs +274 -0
  73. package/lib/{projectPieces.mjs → jamPieces.mjs} +35 -29
  74. package/lib/{projectSettings.mjs → jamSettings.mjs} +12 -22
  75. package/lib/jamStore.mjs +973 -0
  76. package/lib/jamUpgrade.mjs +112 -0
  77. package/lib/jams.mjs +3079 -0
  78. package/lib/kanban.mjs +13 -7
  79. package/lib/landed.mjs +5 -1
  80. package/lib/library.mjs +41 -22
  81. package/lib/limits.mjs +91 -0
  82. package/lib/lineDiff.mjs +97 -0
  83. package/lib/lineup.mjs +18 -13
  84. package/lib/link.mjs +584 -0
  85. package/lib/localStack.mjs +75 -16
  86. package/lib/localmodels.mjs +58 -78
  87. package/lib/loopBackstop.mjs +2 -1
  88. package/lib/machine.mjs +544 -0
  89. package/lib/machineLink.mjs +446 -0
  90. package/lib/machineRoutes.mjs +68 -19
  91. package/lib/machineRuns.mjs +85 -4
  92. package/lib/machineSeal.mjs +6 -31
  93. package/lib/manager.mjs +134 -12
  94. package/lib/mcp-stdio.mjs +492 -215
  95. package/lib/mcpRelay.mjs +34 -35
  96. package/lib/members.json +2 -2
  97. package/lib/modelRoute.mjs +162 -0
  98. package/lib/nativeHost.mjs +81 -90
  99. package/lib/nativeSenses.mjs +258 -0
  100. package/lib/nerves.mjs +523 -0
  101. package/lib/network.mjs +117 -278
  102. package/lib/networkPlaces.mjs +578 -0
  103. package/lib/nextStep.mjs +95 -0
  104. package/lib/notify.mjs +2 -2
  105. package/lib/nudge.mjs +116 -10
  106. package/lib/onboard.mjs +6 -6
  107. package/lib/originals.mjs +216 -0
  108. package/lib/outsideEvents.mjs +383 -0
  109. package/lib/outsideRuns.mjs +230 -0
  110. package/lib/ownMachines.mjs +674 -256
  111. package/lib/pain.mjs +215 -0
  112. package/lib/pairing.mjs +91 -11
  113. package/lib/paths.mjs +42 -3
  114. package/lib/peerProcess.mjs +21 -7
  115. package/lib/peopleLink.mjs +268 -0
  116. package/lib/personNotices.mjs +3 -2
  117. package/lib/phones.mjs +252 -542
  118. package/lib/placeCards.mjs +282 -0
  119. package/lib/placeChecks.mjs +95 -0
  120. package/lib/placeCommands.mjs +8 -17
  121. package/lib/placeRequests.mjs +152 -0
  122. package/lib/placeStore.mjs +295 -0
  123. package/lib/placeTool.d.ts +12 -0
  124. package/lib/placeTool.js +40 -0
  125. package/lib/places.mjs +63 -14
  126. package/lib/plans.mjs +53 -8
  127. package/lib/presence.mjs +270 -0
  128. package/lib/privateNetwork.d.ts +2 -0
  129. package/lib/privateNetwork.js +93 -0
  130. package/lib/proposals.mjs +300 -0
  131. package/lib/publicFetch.d.ts +32 -0
  132. package/lib/publicFetch.js +248 -0
  133. package/lib/reach.mjs +128 -0
  134. package/lib/rebuildable.mjs +72 -0
  135. package/lib/recall.mjs +216 -0
  136. package/lib/record.mjs +13 -0
  137. package/lib/reflexes.mjs +392 -0
  138. package/lib/relayLimits.mjs +31 -2
  139. package/lib/releaseNotice.mjs +198 -0
  140. package/lib/removeHarness.mjs +15 -4
  141. package/lib/repoLinks.mjs +204 -35
  142. package/lib/runAuthority.mjs +102 -39
  143. package/lib/runBrief.mjs +93 -40
  144. package/lib/runRequests.mjs +52 -14
  145. package/lib/runUsage.mjs +31 -0
  146. package/lib/runWorker.mjs +74 -25
  147. package/lib/runner.mjs +289 -45
  148. package/lib/runtime-install.mjs +37 -8
  149. package/lib/schedules.mjs +171 -47
  150. package/lib/screenWatches.mjs +221 -0
  151. package/lib/sealed.mjs +12 -30
  152. package/lib/sealedThreads.mjs +198 -392
  153. package/lib/secretStore.mjs +178 -0
  154. package/lib/secrets.mjs +11 -0
  155. package/lib/seen.mjs +3 -9
  156. package/lib/selfUpdate.mjs +51 -15
  157. package/lib/senseCall.mjs +1514 -0
  158. package/lib/senseHook.mjs +114 -0
  159. package/lib/senseTools.mjs +1298 -0
  160. package/lib/sessionBriefs.mjs +87 -0
  161. package/lib/sessionControl.mjs +63 -13
  162. package/lib/sessionFiles.mjs +85 -0
  163. package/lib/setupChoices.mjs +12 -3
  164. package/lib/setupMode.mjs +70 -25
  165. package/lib/sharedKeys.mjs +166 -0
  166. package/lib/sleep.mjs +396 -0
  167. package/lib/sources.mjs +306 -0
  168. package/lib/speech.mjs +166 -411
  169. package/lib/spoken.mjs +210 -0
  170. package/lib/steerHook.mjs +3 -1
  171. package/lib/steerQueue.mjs +40 -11
  172. package/lib/store.mjs +323 -130
  173. package/lib/stuck.mjs +85 -7
  174. package/lib/swarm.mjs +157 -49
  175. package/lib/swarmDevices.mjs +25 -85
  176. package/lib/swarmMemory.mjs +93 -9
  177. package/lib/t3.mjs +73 -3
  178. package/lib/taskCommands.mjs +51 -60
  179. package/lib/taskRooms.mjs +30 -4
  180. package/lib/taskRules.json +29 -0
  181. package/lib/taskRules.mjs +21 -0
  182. package/lib/taskRuns.mjs +74 -11
  183. package/lib/team.mjs +2 -1
  184. package/lib/threadActions.mjs +37 -9
  185. package/lib/threadAuthority.mjs +4 -4
  186. package/lib/threadBriefs.mjs +173 -43
  187. package/lib/threadNotes.mjs +320 -0
  188. package/lib/threadRecord.mjs +491 -0
  189. package/lib/threadRuns.mjs +216 -108
  190. package/lib/threadView.mjs +27 -30
  191. package/lib/threadWatches.mjs +1962 -0
  192. package/lib/timeSense.mjs +839 -0
  193. package/lib/tripwires.mjs +454 -0
  194. package/lib/ui.mjs +1 -1
  195. package/lib/vault.mjs +560 -45
  196. package/lib/vaultCommands.mjs +5 -3
  197. package/lib/vaultPeers.mjs +165 -0
  198. package/lib/vaultTools.d.ts +4 -1
  199. package/lib/vaultTools.js +22 -1
  200. package/lib/verdicts.mjs +12 -26
  201. package/lib/versions.mjs +117 -0
  202. package/lib/waitTool.mjs +278 -0
  203. package/lib/wakePicture.mjs +268 -0
  204. package/lib/wakeQueue.mjs +108 -0
  205. package/lib/watchResponses.mjs +533 -0
  206. package/lib/watches.mjs +290 -145
  207. package/lib/windowAsks.mjs +80 -17
  208. package/lib/worktrees.mjs +159 -9
  209. package/npm-shrinkwrap.json +138 -631
  210. package/package.json +7 -6
  211. package/release.json +212 -130
  212. package/lib/callSessions.mjs +0 -51
  213. package/lib/directLink.mjs +0 -349
  214. package/lib/peopleBoard.mjs +0 -131
  215. package/lib/projects.mjs +0 -2917
  216. 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, readJson } from "./files.mjs";
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('"__HARNESS_RUNTIME__"', JSON.stringify(runtimeRoot))
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
- const config = readJson(file, {});
248
- const servers = { ...(config.mcpServers ?? {}) };
249
- if (entry) servers.harness = entry;
250
- else if (!servers.harness) return;
251
- else delete servers.harness;
252
- ensureDir(path.dirname(file));
253
- fs.writeFileSync(
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
- writeMcpEntry(setup.file(homeDir), {
265
- ...setup.entry,
266
- command: harnessNode(),
267
- args: server,
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, { runtimeRoot, homeDir });
322
- } catch {
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
- : "MCP configured; the session hooks could not be written"
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
- removeMcpServer(found.agent, found.path, { homeDir, execute });
412
- removeSessionHooks(found.agent, homeDir);
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
- const config = readJson(file, null);
424
- if (!config?.mcp?.harness) continue;
425
- delete config.mcp.harness;
426
- fs.writeFileSync(file, JSON.stringify(config, null, 2) + "\n");
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);
@@ -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, writeJsonAtomic } from "./files.mjs";
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 config = readJson(file, {});
30
- const before = config.agentBinaries?.[agent]?.path ?? null;
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
- const config = readJson(file, {});
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
+ }