tryharness 0.7.53 → 0.7.57

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 (167) hide show
  1. package/README.md +23 -19
  2. package/assets/dsh-plugin.mjs +72 -0
  3. package/assets/opencode-plugin.js +4 -3
  4. package/cli.mjs +484 -90
  5. package/lib/activity.mjs +10 -10
  6. package/lib/adapters.mjs +173 -222
  7. package/lib/agentBinaries.mjs +71 -0
  8. package/lib/agentRuntimeConfig.mjs +1 -1
  9. package/lib/agentRuntimes.mjs +34 -18
  10. package/lib/agentSignIn.mjs +456 -0
  11. package/lib/answers.mjs +5 -5
  12. package/lib/archetypes.d.ts +64 -0
  13. package/lib/archetypes.js +989 -0
  14. package/lib/asks.mjs +4 -4
  15. package/lib/audit.mjs +666 -0
  16. package/lib/backupSetup.mjs +143 -0
  17. package/lib/boardAccess.mjs +24 -11
  18. package/lib/boardBackup.mjs +283 -0
  19. package/lib/boardFileCommands.mjs +6 -6
  20. package/lib/boardFiles.mjs +13 -12
  21. package/lib/boardMirror.mjs +124 -25
  22. package/lib/boardProtocol.json +88 -2
  23. package/lib/boardWaits.mjs +101 -0
  24. package/lib/book.mjs +659 -0
  25. package/lib/bridge.mjs +6 -6
  26. package/lib/cards.mjs +138 -28
  27. package/lib/cloudAgents.mjs +216 -0
  28. package/lib/cloudAi.mjs +1312 -0
  29. package/lib/cloudAssistants.mjs +242 -0
  30. package/lib/cloudBoot.mjs +119 -0
  31. package/lib/cloudSave.mjs +197 -0
  32. package/lib/cloudSsh.mjs +178 -0
  33. package/lib/commands.mjs +7 -2
  34. package/lib/context.mjs +19 -5
  35. package/lib/contractGate.mjs +399 -0
  36. package/lib/control-client.mjs +9 -1
  37. package/lib/controlSocket.mjs +86 -0
  38. package/lib/coordinator.mjs +252 -144
  39. package/lib/daemon.mjs +1351 -2767
  40. package/lib/desk.mjs +240 -0
  41. package/lib/desktop.mjs +178 -74
  42. package/lib/directLink.mjs +16 -5
  43. package/lib/environment.mjs +2 -1
  44. package/lib/environments.mjs +247 -9
  45. package/lib/firewall.mjs +9 -9
  46. package/lib/folders.mjs +20 -16
  47. package/lib/frames.mjs +2 -3
  48. package/lib/gitHost.mjs +174 -0
  49. package/lib/goalCommands.mjs +25 -7
  50. package/lib/goals.mjs +7 -7
  51. package/lib/guestRequests.mjs +94 -0
  52. package/lib/handoffs.mjs +8 -7
  53. package/lib/handover.mjs +4 -4
  54. package/lib/harnessModel.mjs +6 -6
  55. package/lib/harnessOffers.mjs +266 -0
  56. package/lib/hookDialects.mjs +298 -0
  57. package/lib/inference.mjs +26 -8
  58. package/lib/jobAnswers.mjs +190 -0
  59. package/lib/landed.mjs +887 -0
  60. package/lib/lane.mjs +42 -11
  61. package/lib/lessons.mjs +16 -16
  62. package/lib/library.mjs +3 -3
  63. package/lib/lineup.mjs +3 -0
  64. package/lib/linkRelay.mjs +574 -0
  65. package/lib/live.mjs +284 -13
  66. package/lib/localAgentAsk.mjs +74 -0
  67. package/lib/localStack.mjs +536 -0
  68. package/lib/localmodels.mjs +6 -4
  69. package/lib/loopBackstop.mjs +4 -4
  70. package/lib/machineIdentity.mjs +9 -1
  71. package/lib/machineRoutes.mjs +181 -2
  72. package/lib/machineRuns.mjs +76 -1
  73. package/lib/machineSeal.mjs +39 -12
  74. package/lib/mcp-stdio.mjs +163 -27
  75. package/lib/mcpRelay.mjs +1 -1
  76. package/lib/members.json +29 -2
  77. package/lib/members.mjs +1 -1
  78. package/lib/models.mjs +85 -31
  79. package/lib/museSession.mjs +21 -13
  80. package/lib/nativeHost.mjs +36 -8
  81. package/lib/neovim.mjs +126 -0
  82. package/lib/network.mjs +50 -5
  83. package/lib/notify.mjs +7 -5
  84. package/lib/nudge.mjs +50 -19
  85. package/lib/ocr.mjs +9 -9
  86. package/lib/onboard.mjs +26 -20
  87. package/lib/oneLine.mjs +7 -7
  88. package/lib/ownMachines.mjs +1223 -140
  89. package/lib/pairing.mjs +60 -16
  90. package/lib/paths.mjs +19 -1
  91. package/lib/peerProcess.mjs +124 -0
  92. package/lib/personModel.mjs +89 -0
  93. package/lib/personNotices.mjs +151 -0
  94. package/lib/phones.mjs +538 -31
  95. package/lib/placeCommands.mjs +4 -4
  96. package/lib/places.mjs +400 -12
  97. package/lib/profile.mjs +67 -14
  98. package/lib/projectGit.mjs +158 -14
  99. package/lib/projectPieces.mjs +902 -0
  100. package/lib/projectSettings.mjs +7 -4
  101. package/lib/projects.mjs +384 -62
  102. package/lib/provenance.mjs +5 -1
  103. package/lib/proxyLinks.mjs +267 -0
  104. package/lib/reactions.mjs +7 -5
  105. package/lib/readiness.mjs +145 -23
  106. package/lib/record.mjs +128 -0
  107. package/lib/redact.mjs +4 -4
  108. package/lib/relayLimits.mjs +62 -0
  109. package/lib/release.mjs +170 -0
  110. package/lib/releaseKeys.json +6 -0
  111. package/lib/repoLinks.mjs +4 -4
  112. package/lib/roomChannels.mjs +24 -0
  113. package/lib/roomPage.mjs +1 -1
  114. package/lib/runAuthority.mjs +101 -0
  115. package/lib/runBrief.mjs +19 -8
  116. package/lib/runWorker.mjs +31 -7
  117. package/lib/runner.mjs +223 -29
  118. package/lib/runtime-install.mjs +143 -9
  119. package/lib/schedules.mjs +2 -2
  120. package/lib/screens.mjs +1 -1
  121. package/lib/sealed.mjs +11 -2
  122. package/lib/sealedThreads.mjs +671 -0
  123. package/lib/secretPatterns.json +1 -1
  124. package/lib/secrets.mjs +4 -4
  125. package/lib/seen.mjs +6 -6
  126. package/lib/serverWords.mjs +175 -0
  127. package/lib/service.mjs +22 -12
  128. package/lib/sessionControl.mjs +378 -90
  129. package/lib/specialties.json +74 -0
  130. package/lib/specialties.mjs +477 -0
  131. package/lib/specialtyKeys.d.ts +3 -0
  132. package/lib/specialtyKeys.js +57 -0
  133. package/lib/specialtyNotice.mjs +147 -0
  134. package/lib/specialtySnapshot.mjs +138 -0
  135. package/lib/speech.mjs +5 -5
  136. package/lib/store.mjs +420 -36
  137. package/lib/stuck.mjs +1 -1
  138. package/lib/swarm.mjs +304 -37
  139. package/lib/swarmDevices.mjs +319 -0
  140. package/lib/swarmMemory.mjs +27 -25
  141. package/lib/t3.mjs +24 -15
  142. package/lib/taskCommands.mjs +80 -20
  143. package/lib/taskRooms.mjs +125 -0
  144. package/lib/taskRuns.mjs +45 -3
  145. package/lib/team.json +255 -148
  146. package/lib/team.mjs +554 -190
  147. package/lib/threadActions.mjs +315 -0
  148. package/lib/threadAuthority.mjs +101 -0
  149. package/lib/threadBriefs.mjs +178 -0
  150. package/lib/threadLine.mjs +116 -0
  151. package/lib/threadRuns.mjs +209 -50
  152. package/lib/threadView.mjs +20 -7
  153. package/lib/usageTotals.mjs +2 -3
  154. package/lib/vault.mjs +101 -10
  155. package/lib/vaultCloud.mjs +2 -2
  156. package/lib/vaultCommands.mjs +15 -6
  157. package/lib/vaultTools.js +2 -2
  158. package/lib/verdicts.mjs +328 -0
  159. package/lib/wakes.mjs +1 -1
  160. package/lib/watches.mjs +2 -2
  161. package/lib/windowAsks.mjs +13 -5
  162. package/lib/worktrees.mjs +157 -25
  163. package/npm-shrinkwrap.json +1093 -0
  164. package/package.json +12 -11
  165. package/release.json +220 -0
  166. package/lib/modelTiers.json +0 -1183
  167. package/lib/modelTiers.mjs +0 -133
@@ -18,6 +18,12 @@ const LOCAL_OWNERS = new Set([
18
18
  "nativeRequests",
19
19
  ]);
20
20
 
21
+ /**
22
+ * Set on a board request by ownMachines.mjs alone, on home: the other computer the call came from. JSON cannot carry
23
+ * it, so no caller names a computer it is not on, and a request that has it came from another of the person's computers.
24
+ */
25
+ export const FROM_MACHINE = Symbol("the computer a board call came from");
26
+
21
27
  /** Whether a worker sends this board command to home. */
22
28
  export const goesHome = (command) =>
23
29
  String(command).startsWith("board.") &&
@@ -26,8 +32,8 @@ export const goesHome = (command) =>
26
32
  !LOCAL_OWNERS.has(boardCommandOwner(String(command)));
27
33
 
28
34
  // Writes an agent need not wait on: while home is out of reach the worker keeps them, sealed, and sends them when it is
29
- // back. A post is one: any computer can start a task (owner, October 21), with its id chosen there. A claim waits for
30
- // its answer instead, since two computers could take the same task.
35
+ // back. A post is one: any computer can start a task, with its id chosen there. A claim waits for its answer instead,
36
+ // since two computers could take the same task.
31
37
  const QUEUEABLE = new Set([
32
38
  "board.post",
33
39
  "board.report",
@@ -133,3 +139,176 @@ export function withComputer(post, computerOf) {
133
139
  const computer = computerOf(post.machine);
134
140
  return computer ? { ...post, computer } : post;
135
141
  }
142
+
143
+ // ---- what another of the person's computers may ask home to do (security audit 2026-10-25, M1) ----
144
+
145
+ // A worker's own upkeep with home, whoever it names: telling home its folders, taking and reporting the runs home keeps
146
+ // for its agents, the environment grants home's vault lends a run there (vault.mjs checks those itself).
147
+ const UPKEEP = new Set([
148
+ "board.machine.info",
149
+ "board.machine.runnable",
150
+ "board.machine.take",
151
+ "board.machine.session",
152
+ "board.machine.step",
153
+ "board.machine.finish",
154
+ "board.vault.env",
155
+ ]);
156
+
157
+ // What an agent on another computer does on home's board: what its Harness tools call there (mcp-stdio.mjs).
158
+ const AGENT_WORK = new Set([
159
+ "board.list",
160
+ "board.get",
161
+ "board.children",
162
+ "board.agents",
163
+ "board.post",
164
+ "board.claim",
165
+ "board.release",
166
+ "board.report",
167
+ "board.answer",
168
+ "board.context.add",
169
+ "board.context.search",
170
+ "board.trace",
171
+ "board.wait",
172
+ "board.wallet",
173
+ "board.standing.check",
174
+ "board.file.add",
175
+ "board.file.get",
176
+ "board.thread.read",
177
+ "board.thread.post",
178
+ "board.goal.list",
179
+ "board.goal.get",
180
+ "board.goal.finish",
181
+ "board.room.read",
182
+ "board.room.post",
183
+ "board.room.search",
184
+ "board.room.learn",
185
+ "board.swarm.list",
186
+ "board.swarm.read",
187
+ "board.swarm.agents",
188
+ "board.swarm.models",
189
+ "board.swarm.search",
190
+ "board.swarm.memory",
191
+ "board.swarm.forget",
192
+ "board.swarm.unforget",
193
+ "board.swarm.lessons",
194
+ "board.swarm.start",
195
+ "board.swarm.stop",
196
+ "board.swarm.note",
197
+ "board.swarm.health",
198
+ "board.swarm.rounds",
199
+ "board.swarm.checkins",
200
+ "board.swarm.checkin",
201
+ "board.swarm.checkin.remove",
202
+ "board.plan.add",
203
+ "board.template.list",
204
+ "board.template.get",
205
+ "board.template.use",
206
+ "board.project.plan",
207
+ "board.project.propose",
208
+ "board.desk.book",
209
+ "board.connector.list",
210
+ "board.connector.tools",
211
+ "board.connector.call",
212
+ "board.connector.result",
213
+ // A secret used through home, never handed over (vault.mjs keeps its own rules for another computer's agents).
214
+ "board.vault.list",
215
+ "board.vault.use",
216
+ ]);
217
+
218
+ // The person at a computer they drive from does the board's work there as on home: posts, runs, answers, stops,
219
+ // threads. How the swarm is set up (standing permission, spend ceilings, connectors' grants, the vault, the relay
220
+ // network, the desk's book, partners on projects, offices) is changed only on home itself or a phone paired with it.
221
+ const PERSON_WORK = new Set([
222
+ ...AGENT_WORK,
223
+ "board.run",
224
+ "board.remove",
225
+ "board.standing",
226
+ "board.file.share",
227
+ "board.thread.send",
228
+ "board.thread.discard",
229
+ "board.thread.auto",
230
+ "board.thread.end",
231
+ "board.goal.create",
232
+ "board.goal.stop",
233
+ "board.goal.resume",
234
+ "board.goal.folder",
235
+ "board.goal.invite",
236
+ "board.swarm.file",
237
+ "board.swarm.post",
238
+ "board.swarm.stop_all",
239
+ "board.swarm.resume",
240
+ "board.swarm.folder",
241
+ "board.swarm.coordinator",
242
+ "board.swarm.diff",
243
+ "board.swarm.merge",
244
+ "board.swarm.discard",
245
+ "board.swarm.start_run",
246
+ "board.swarm.steer",
247
+ "board.swarm.use_browser",
248
+ "board.swarm.places",
249
+ "board.swarm.browse",
250
+ "board.swarm.place",
251
+ "board.swarm.held",
252
+ "board.swarm.follow",
253
+ "board.swarm.seen",
254
+ "board.swarm.context",
255
+ "board.swarm.links",
256
+ "board.swarm.link",
257
+ "board.swarm.lessons.edit",
258
+ "board.swarm.lessons.remove",
259
+ "board.swarm.lessons.undo",
260
+ "board.swarm.specialties",
261
+ "board.swarm.offices",
262
+ "board.swarm.notice",
263
+ "board.swarm.model",
264
+ "board.swarm.specialty",
265
+ "board.swarm.pin",
266
+ "board.swarm.routing",
267
+ "board.plan.edit",
268
+ "board.plan.remove",
269
+ "board.plan.run",
270
+ "board.template.check",
271
+ "board.template.save",
272
+ "board.template.remove",
273
+ "board.project.list",
274
+ "board.project.read",
275
+ "board.project.answer",
276
+ "board.project.held",
277
+ "board.project.note",
278
+ "board.project.work",
279
+ "board.project.repos",
280
+ "board.project.agents",
281
+ "board.project.goal",
282
+ "board.project.retry",
283
+ "board.landed.thread",
284
+ "board.landed.folder",
285
+ "board.environments.list",
286
+ "board.relay.list",
287
+ "board.relay.seen",
288
+ "board.connector.operations",
289
+ "board.place.op",
290
+ ]);
291
+
292
+ /**
293
+ * Whether home answers this call from another of the person's computers, or why not. `agent` is what the call names:
294
+ * "user" (the person at that computer, only where they drive from it, or Harness in their window there), or an agent
295
+ * that runs on the person's computers; never a server member or another person. `drives`: the person paired that computer by typing its code; a
296
+ * hosted computer (a cloud computer) is agents only. Null when home answers it.
297
+ */
298
+ export function computerMay({ command, agent, drives }) {
299
+ const asked = String(command || "");
300
+ if (UPKEEP.has(asked)) return null;
301
+ // Harness in a window linked to that computer acts for the person there, so it has the same limits.
302
+ if (agent === "user" || agent === "harness") {
303
+ if (!drives)
304
+ return "That computer runs agents only, so nothing it sends acts as you.";
305
+ return PERSON_WORK.has(asked)
306
+ ? null
307
+ : `${asked} changes how your swarm is set up: do it on your home computer, or a phone paired with it.`;
308
+ }
309
+ if (member(agent)?.road !== "local")
310
+ return `${agent} does not run on that computer.`;
311
+ return AGENT_WORK.has(asked)
312
+ ? null
313
+ : `An agent on another of your computers cannot call ${asked} on home.`;
314
+ }
@@ -1,4 +1,6 @@
1
+ import fs from "node:fs";
1
2
  import path from "node:path";
3
+ import { within } from "./folders.mjs";
2
4
  import { provenanceLine } from "./provenance.mjs";
3
5
 
4
6
  // On a worker: the work home keeps for this computer's agents, run here. The person's Start (or a thread's authority)
@@ -12,8 +14,31 @@ import { provenanceLine } from "./provenance.mjs";
12
14
  // own run worker tells its steps, runWorker.mjs), the latest standing for those between. Nothing is told while a run
13
15
  // takes no step, and a step home could not hear is not kept: the last one it heard stands, as for a computer offline.
14
16
  const STEP_NOTICE_MS = 1_000;
17
+ // An agent's session id as this computer's agents name theirs; never one an agent's command line would read as a flag.
18
+ const SESSION_ID = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$/;
19
+ //
20
+ // Home lists the work; this computer decides where it runs (security audit 2026-10-25, M6). A run starts only in a folder
21
+ // this computer knows: one its own agents' sessions or T3 Code worked in, or a folder inside one. Any other folder home
22
+ // names (another place on this disk, a folder of home's) is refused, and home's board says so, so the person sees why.
23
+
24
+ const real = (dir) => {
25
+ try {
26
+ return fs.realpathSync(dir);
27
+ } catch {
28
+ return null;
29
+ }
30
+ };
15
31
 
16
- export function createMachineRuns({ callHome, taskRuns, agents, log }) {
32
+ export function createMachineRuns({
33
+ callHome,
34
+ taskRuns,
35
+ agents,
36
+ knownFolders = () => [],
37
+ log,
38
+ // The model and effort the run starts with, from the person's choice here (models.mjs createModelRouter): a choice
39
+ // for an agent is kept on the computer that runs it, so it is read here, not on home.
40
+ modelFor = async () => null,
41
+ }) {
17
42
  const active = new Map();
18
43
  const steps = new Map();
19
44
  let asking = false;
@@ -74,6 +99,7 @@ export function createMachineRuns({ callHome, taskRuns, agents, log }) {
74
99
  const agent = task.target_agent;
75
100
  log(`running ${agent}'s task ${task.id} from your home computer`);
76
101
  const secrets = await secretsFor(task, agent);
102
+ const chosen = await modelFor(task, agent).catch(() => null);
77
103
  // Sent again with the finish: the two calls go to home at once, and a finish that arrives first closes the run to
78
104
  // the session call (two-machines: home kept no session, one run in four).
79
105
  let session = null;
@@ -84,6 +110,13 @@ export function createMachineRuns({ callHome, taskRuns, agents, log }) {
84
110
  title: String(task.objective || "").slice(0, 120),
85
111
  brief: briefOf(task),
86
112
  cwd: task.run_workspace,
113
+ ...(chosen?.model ? { model: chosen.model } : {}),
114
+ ...(chosen?.effort ? { effort: chosen.effort } : {}),
115
+ ...(chosen?.model && chosen.limits ? { limits: chosen.limits } : {}),
116
+ // The turn after one the person's steer stopped here goes on in that turn's session (home names it).
117
+ ...(SESSION_ID.test(task.resumeSession ?? "")
118
+ ? { resumeSession: task.resumeSession }
119
+ : {}),
87
120
  ...secrets,
88
121
  },
89
122
  (kind, text, extra) => {
@@ -120,6 +153,43 @@ export function createMachineRuns({ callHome, taskRuns, agents, log }) {
120
153
  );
121
154
  };
122
155
 
156
+ // Why this computer will not run a task where home put it, or null when it will.
157
+ const refusalFor = (task) => {
158
+ const folder =
159
+ typeof task.run_workspace === "string" &&
160
+ path.isAbsolute(task.run_workspace)
161
+ ? real(task.run_workspace)
162
+ : null;
163
+ if (
164
+ folder &&
165
+ knownFolders().some((known) => {
166
+ const root = real(known);
167
+ return root && within(folder, root);
168
+ })
169
+ )
170
+ return null;
171
+ return `This computer runs work from your home computer only in a folder its own agents have worked in, and ${task.run_workspace || "no folder"} is not one. Start it there in one of this computer's folders.`;
172
+ };
173
+ // Taken in its agent's name and ended at once with the reason, so home's board shows why it did not run here.
174
+ const refuse = async (task, reason) => {
175
+ log(`did not run task ${task.id} from your home computer: ${reason}`);
176
+ const taken = await callHome({
177
+ command: "board.machine.take",
178
+ agent: task.target_agent,
179
+ id: task.id,
180
+ expectedVersion: task.version,
181
+ });
182
+ if (!taken?.ok) return;
183
+ await callHome({
184
+ command: "board.machine.finish",
185
+ agent: task.target_agent,
186
+ id: task.id,
187
+ status: "failed",
188
+ result: reason,
189
+ failure: "start",
190
+ });
191
+ };
192
+
123
193
  /** Ask home for this computer's authorized work and start what has a free folder. */
124
194
  const check = async () => {
125
195
  if (!agents.length) return;
@@ -135,6 +205,11 @@ export function createMachineRuns({ callHome, taskRuns, agents, log }) {
135
205
  agents,
136
206
  });
137
207
  for (const task of answer?.ok ? answer.tasks : []) {
208
+ const refused = refusalFor(task);
209
+ if (refused) {
210
+ await refuse(task, refused);
211
+ continue;
212
+ }
138
213
  const slot = slotOf(task);
139
214
  if (active.has(slot)) continue;
140
215
  const taken = await callHome({
@@ -1,4 +1,5 @@
1
- import { createHmac, randomBytes } from "node:crypto";
1
+ import { createHmac, pbkdf2, randomBytes, scrypt } from "node:crypto";
2
+ import { promisify } from "node:util";
2
3
  import {
3
4
  channelKey,
4
5
  constantTimeEqual,
@@ -14,11 +15,16 @@ import {
14
15
  // - Each computer has its static ECDH identity (phone-identity.json). The two keys of a home and a worker give one
15
16
  // AES-256-GCM key for the pair; every message binds its direction, the worker's id and its request id.
16
17
  // - Keys are pinned once (own_machines) by the join handshake: the worker shows a join code, the person types it on
17
- // home, and each side proves it holds the code by an HMAC over both computers' ids and keys. Harness never sees the
18
- // code, so it cannot stand in for either computer with a key of its own.
18
+ // home, and each side proves it holds the code by an HMAC over both computers' ids and keys, keyed by scrypt of the
19
+ // code. Harness never sees the code, so it cannot stand in for either computer with a key of its own.
19
20
  // - Setup shows one 16-character code that is both the pairing code and the join code. Harness hears only its first 4
20
21
  // characters, to find the waiting computer, and a verifier only the whole code makes, so approving it needs the
21
22
  // code the person read; the 12 characters it never hears keep the join's 60 secret bits.
23
+ // - Harness sees each proof and verifier, so each is made slow to guess from (security audit 2026-10-25, M7: one HMAC
24
+ // let 60 bits be searched offline in about 1e4 to 1e5 GPU hours). The verifier is PBKDF2-SHA256 at 600,000 rounds
25
+ // (OWASP's figure for it), because the browser makes the same one and Web Crypto has PBKDF2 but no scrypt; the join
26
+ // proofs, made only here, are keyed by scrypt (N 2^15, r 8, p 1: 32 MiB a guess). Not a PAKE: node:crypto has none,
27
+ // and one made up here would be new cryptography.
22
28
  // - A call is refused when it is stale (five minutes either way, seven days for a write queued while the worker was
23
29
  // offline), replayed, or sealed for another worker or direction.
24
30
 
@@ -54,24 +60,45 @@ export function normalizeJoinCode(text) {
54
60
  export const isPairCode = (code) =>
55
61
  code?.replace(/-/g, "").length === PAIR_LENGTH;
56
62
 
63
+ // The browser's twin is src/shared/pairCode.ts pairApproval: the same rounds and salt, or approval in a browser fails.
64
+ export const PAIR_VERIFIER_ROUNDS = 600_000;
65
+ const SCRYPT = { N: 2 ** 15, r: 8, p: 1, maxmem: 64 * 1024 * 1024 };
66
+ const pbkdf2Async = promisify(pbkdf2);
67
+ const scryptAsync = promisify(scrypt);
68
+
57
69
  /** What Harness hears of a pairing code: the part it finds the waiting computer by, and proof of the whole code. */
58
- export function pairClaim(code) {
70
+ export async function pairClaim(code) {
59
71
  const normal = normalizeJoinCode(code);
60
- return {
61
- lookup: normal.slice(0, LOOKUP_LENGTH),
62
- verifier: createHmac("sha256", normal)
63
- .update("HSC1-pair-verifier")
64
- .digest("base64url"),
65
- };
72
+ const lookup = normal.slice(0, LOOKUP_LENGTH);
73
+ const verifier = await pbkdf2Async(
74
+ normal,
75
+ `HSC1-pair-verifier\n${lookup}`,
76
+ PAIR_VERIFIER_ROUNDS,
77
+ 32,
78
+ "sha256"
79
+ );
80
+ return { lookup, verifier: verifier.toString("base64url") };
66
81
  }
67
82
 
83
+ // A code's join key, made once per code: a waiting computer hears a guess at most JOIN_TRIES times, and home tries one
84
+ // typed code on each computer waiting to join.
85
+ const joinKeys = new Map();
86
+ const joinKey = (code) => {
87
+ const normal = normalizeJoinCode(code) ?? "";
88
+ if (!joinKeys.has(normal)) {
89
+ if (joinKeys.size > 32) joinKeys.clear();
90
+ joinKeys.set(normal, scryptAsync(normal, "HSC1-join-key", 32, SCRYPT));
91
+ }
92
+ return joinKeys.get(normal);
93
+ };
94
+
68
95
  /** What a side of the join proves: it holds the code, over both computers' ids and keys. */
69
- export function joinProof(
96
+ export async function joinProof(
70
97
  code,
71
98
  side,
72
99
  { homeId, homeKey, workerId, workerKey }
73
100
  ) {
74
- return createHmac("sha256", normalizeJoinCode(code) ?? "")
101
+ return createHmac("sha256", await joinKey(code))
75
102
  .update(
76
103
  `HSC1-join\n${side}\n${homeId}\n${homeKey}\n${workerId}\n${workerKey}`
77
104
  )