hivedesk 1.0.2 → 1.1.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +5 -6
  3. package/desktop/README.md +0 -3
  4. package/desktop/release-notes/1.1.0.json +12 -0
  5. package/i18n/README.pt-BR.md +5 -6
  6. package/i18n/de.json +7 -31
  7. package/i18n/en.json +7 -31
  8. package/i18n/es.json +7 -31
  9. package/i18n/fr.json +7 -31
  10. package/i18n/it.json +7 -31
  11. package/i18n/ja.json +7 -31
  12. package/i18n/ko.json +7 -31
  13. package/i18n/parts/s2-p2p.de.json +5 -15
  14. package/i18n/parts/s2-p2p.en.json +5 -15
  15. package/i18n/parts/s2-p2p.es.json +5 -15
  16. package/i18n/parts/s2-p2p.fr.json +5 -15
  17. package/i18n/parts/s2-p2p.it.json +5 -15
  18. package/i18n/parts/s2-p2p.ja.json +5 -15
  19. package/i18n/parts/s2-p2p.ko.json +5 -15
  20. package/i18n/parts/s2-p2p.pt-BR.json +5 -15
  21. package/i18n/parts/s2-p2p.ru.json +5 -15
  22. package/i18n/parts/s2-p2p.zh-CN.json +5 -15
  23. package/i18n/pt-BR.json +7 -31
  24. package/i18n/ru.json +7 -31
  25. package/i18n/zh-CN.json +7 -31
  26. package/package.json +1 -1
  27. package/src/city/membership.js +1 -1
  28. package/src/extensions/engine-hook.js +1 -1
  29. package/src/lend/index.js +4 -3
  30. package/src/p2p/city-port.js +2 -2
  31. package/src/p2p/cli.js +31 -38
  32. package/src/p2p/engine.js +1 -1
  33. package/src/p2p/node.js +25 -8
  34. package/ui/js/widgets/lend.js +2 -2
  35. package/ui/lend/collab/client.js +9 -27
  36. package/ui/lend/collab/frames.js +1 -1
  37. package/ui/lend/collab/panel.js +8 -20
  38. package/ui/lend/collab/session.js +1 -1
  39. package/ui/lend/core/frames.js +1 -1
  40. package/ui/lend/core/session.js +37 -44
  41. package/ui/lend/join-window.js +8 -21
  42. package/ui/lend/lend-screen.js +14 -29
  43. package/ui/lend/lend.css +0 -2
  44. package/ui/lend/p2p-model.js +8 -19
  45. package/ui/lend/p2p-screen.js +21 -43
  46. package/ui/lend/p2p-text.js +4 -14
  47. package/ui/lend/text.js +1 -6
  48. package/ui/lend/view.js +1 -1
@@ -1,20 +1,19 @@
1
1
  // Pairing for Lend your PC, built from the howlden and filefinch pieces (MIT, Alexandre Kohler):
2
- // the six word rendezvous on public MQTT brokers (pairing.js), one WebRTC link (rtc.js) and the
3
- // confirmation words from both DTLS fingerprints (words.js confirmWords).
2
+ // the six word rendezvous on public MQTT brokers (pairing.js) and one WebRTC link (rtc.js).
4
3
  //
5
4
  // friend (lends): LendOffer shows the words, sends the WebRTC offer to the first device
6
5
  // that knocks, applies its answer
7
6
  // host (borrows): LendJoin knocks with the words, answers the offer
8
7
  //
9
- // When the data channel opens both sides compute the same six confirmation words. A device that
10
- // learned the words over someone's shoulder has its own certificate, so its words differ. Nothing
11
- // but the hello frame travels until the person on each side confirms the words match.
8
+ // The six words are the whole pairing: they derive the relay topic and the key that seals the
9
+ // WebRTC offer and answer, they work once and expire after ten minutes. Whoever answers the
10
+ // sealed offer holds the words, so the link is ready as soon as the data channel opens; there is
11
+ // no second step. The channel itself is DTLS encrypted end to end.
12
12
 
13
13
  import { Emitter } from './emitter.js';
14
14
  import { CodeCreator, CodeJoiner } from './pairing.js';
15
15
  import { RtcLink } from './rtc.js';
16
16
  import { randomId } from './bytes.js';
17
- import { confirmWords } from './words.js';
18
17
  import { FrameError, decodeFrame, encodeFrame, LIMITS } from './frames.js';
19
18
 
20
19
  /** The lend frames (frames.js). Code together passes its own codec with the same shape. */
@@ -25,22 +24,20 @@ export const CHUNK_CHARS = 60000;
25
24
  const MAX_PARTS = 200;
26
25
 
27
26
  /**
28
- * One open connection after pairing: sends and receives checked frames, tracks the two
29
- * confirmations. Works over anything with send(text), onmessage, onclose and close(), so tests
30
- * run it over an in-memory pair. Long frames are split into parts and joined again.
31
- * events: 'frame' (frame), 'ready' (both sides confirmed), 'rejected' (error), 'close' (reason)
27
+ * One open connection after pairing: sends and receives checked frames. Works over anything with
28
+ * send(text), onmessage, onclose and close(), so tests run it over an in-memory pair. Long frames
29
+ * are split into parts and joined again. Both sides send a hello frame first; the peer is ready
30
+ * once the other side's hello arrived, with nothing for anyone to confirm.
31
+ * events: 'frame' (frame), 'ready' (the other hello arrived), 'rejected' (error), 'close' (reason)
32
32
  */
33
33
  export class LendPeer extends Emitter {
34
- constructor(link, { confirm = [], limits = LIMITS, codec = LEND_CODEC } = {}) {
34
+ constructor(link, { limits = LIMITS, codec = LEND_CODEC } = {}) {
35
35
  super();
36
36
  this.link = link;
37
37
  this.limits = limits;
38
38
  this.codec = codec;
39
39
  this.parts = new Map(); // id -> { n, got: string[], count }
40
40
  this.nextPart = 0;
41
- this.confirm = confirm;
42
- this.localConfirmed = false;
43
- this.remoteConfirmed = false;
44
41
  this.remoteHello = null;
45
42
  this.closed = false;
46
43
  link.onmessage = (text) => this._receive(text);
@@ -48,7 +45,7 @@ export class LendPeer extends Emitter {
48
45
  }
49
46
 
50
47
  get ready() {
51
- return this.localConfirmed && this.remoteConfirmed && !this.closed;
48
+ return !!this.remoteHello && !this.closed;
52
49
  }
53
50
 
54
51
  /** Joins a frame sent in parts. Returns the whole text, or null while parts are missing. */
@@ -90,11 +87,25 @@ export class LendPeer extends Emitter {
90
87
  this.emit('rejected', err instanceof FrameError ? err : new FrameError('bad_frame', String(err?.message || err)));
91
88
  return;
92
89
  }
93
- if (frame.t === 'hello') this.remoteHello = frame;
94
- if (frame.t === 'confirm') {
95
- const was = this.ready;
96
- this.remoteConfirmed = true;
97
- if (!was && this.ready) this.emit('ready');
90
+ // Sent by apps before 1.1 after their person clicked; nothing waits for it any more.
91
+ if (frame.t === 'confirm') return;
92
+ if (frame.t === 'hello') {
93
+ const first = !this.remoteHello;
94
+ this.remoteHello = frame;
95
+ this.emit('frame', frame);
96
+ if (!first || this.closed) return;
97
+ // An app before 1.1 still waits for this frame before it serves anything.
98
+ try {
99
+ this.send({ t: 'confirm' });
100
+ } catch {
101
+ // the link may already be gone
102
+ }
103
+ this.emit('ready');
104
+ return;
105
+ }
106
+ // Requests and answers come after the hello, which travels first on the same ordered channel.
107
+ if (!this.remoteHello) {
108
+ this.emit('rejected', new FrameError('no_hello', 'A frame arrived before the hello'));
98
109
  return;
99
110
  }
100
111
  if (frame.t === 'stop') {
@@ -102,11 +113,6 @@ export class LendPeer extends Emitter {
102
113
  this._closed(`stopped by the other side: ${frame.reason}`);
103
114
  return;
104
115
  }
105
- // Requests and answers only flow once both people confirmed the words.
106
- if (frame.t !== 'hello' && !this.ready) {
107
- this.emit('rejected', new FrameError('not_confirmed', 'A frame arrived before the confirmation words were checked'));
108
- return;
109
- }
110
116
  this.emit('frame', frame);
111
117
  }
112
118
 
@@ -124,15 +130,6 @@ export class LendPeer extends Emitter {
124
130
  for (let i = 0; i < n; i++) this.link.send(JSON.stringify({ t: '~', id, i, n, s: text.slice(i * CHUNK_CHARS, (i + 1) * CHUNK_CHARS) }));
125
131
  }
126
132
 
127
- /** The person on this side checked the confirmation words. */
128
- confirmLocal() {
129
- if (this.localConfirmed || this.closed) return;
130
- const was = this.ready;
131
- this.localConfirmed = true;
132
- this.send({ t: 'confirm' });
133
- if (!was && this.ready) this.emit('ready');
134
- }
135
-
136
133
  /** Ends lending: tells the other side, then closes. */
137
134
  stop(reason = 'stopped') {
138
135
  if (this.closed) return;
@@ -160,7 +157,7 @@ const clean = (o) => Object.fromEntries(Object.entries(o).filter(([, v]) => v !=
160
157
 
161
158
  /**
162
159
  * The friend's side. start() resolves with the six words to show.
163
- * events: 'status' (relay status), 'connected' (LendPeer, confirmation words), 'failed' (reason), 'expired'
160
+ * events: 'status' (relay status), 'connected' (LendPeer), 'failed' (reason), 'expired'
164
161
  */
165
162
  export class LendOffer extends Emitter {
166
163
  constructor(options = {}) {
@@ -195,10 +192,8 @@ export class LendOffer extends Emitter {
195
192
 
196
193
  _open() {
197
194
  this.creator.stop();
198
- const [a, b] = this.link.fingerprints();
199
- const words = confirmWords(a, b, this.nonce);
200
- const peer = new LendPeer(this.link, { confirm: words, limits: this.options.limits, codec: this.options.codec });
201
- this.emit('connected', peer, words);
195
+ const peer = new LendPeer(this.link, { limits: this.options.limits, codec: this.options.codec });
196
+ this.emit('connected', peer);
202
197
  }
203
198
 
204
199
  stop() {
@@ -209,7 +204,7 @@ export class LendOffer extends Emitter {
209
204
 
210
205
  /**
211
206
  * The host's side. start(words) knocks until the friend's offer arrives.
212
- * events: 'status', 'connected' (LendPeer, confirmation words), 'failed' (reason), 'timeout'
207
+ * events: 'status', 'connected' (LendPeer), 'failed' (reason), 'timeout'
213
208
  */
214
209
  export class LendJoin extends Emitter {
215
210
  constructor(options = {}) {
@@ -241,10 +236,8 @@ export class LendJoin extends Emitter {
241
236
 
242
237
  _open() {
243
238
  this.joiner.stop();
244
- const [a, b] = this.link.fingerprints();
245
- const words = confirmWords(a, b, this.nonce);
246
- const peer = new LendPeer(this.link, { confirm: words, limits: this.options.limits, codec: this.options.codec });
247
- this.emit('connected', peer, words);
239
+ const peer = new LendPeer(this.link, { limits: this.options.limits, codec: this.options.codec });
240
+ this.emit('connected', peer);
248
241
  }
249
242
 
250
243
  stop() {
@@ -1,6 +1,6 @@
1
1
  // The host's side: the "Use a friend's PC" window. Six word boxes (a whole phrase or the share
2
- // link pasted into one box fills all six), an optional QR scan, then the confirmation words,
3
- // then the friend's model joins the turn scheduler as one more brain.
2
+ // link pasted into one box fills all six) or an optional QR scan; once the link opens, the
3
+ // friend's model joins the turn scheduler as one more brain. Nothing to confirm in between.
4
4
  // Every text follows a live language switch (liveScope in view.js); unmount() unsubscribes.
5
5
 
6
6
  import { LendJoin } from './core/session.js';
@@ -19,7 +19,7 @@ import { runP2PJoin } from './p2p-screen.js';
19
19
  */
20
20
  export function mountJoinWindow(root, { hive, options = {}, initial = '', label = 'host' } = {}) {
21
21
  root.classList.add('lend-join');
22
- const state = { phase: 'idle', join: null, peer: null, bridge: null, confirm: null };
22
+ const state = { phase: 'idle', join: null, peer: null, bridge: null };
23
23
  const live = liveScope(root);
24
24
  const api = { state, connect, root, fill, unmount };
25
25
  let inputs = [];
@@ -130,7 +130,7 @@ export function mountJoinWindow(root, { hive, options = {}, initial = '', label
130
130
 
131
131
  async function connect(words) {
132
132
  state.join?.stop();
133
- // A 1.0 engine joins through its control plane: identities, SAS words, the host's Accept.
133
+ // A 1.0 engine joins through its control plane: identities and the grants the friend chose.
134
134
  if (state.p2p === undefined) state.p2p = await hive.command('lend.status').then((s) => !!s?.p2p && !options.legacy, () => false);
135
135
  if (state.p2p) {
136
136
  state.phase = 'p2p';
@@ -144,7 +144,7 @@ export function mountJoinWindow(root, { hive, options = {}, initial = '', label
144
144
  state.join = join;
145
145
  join.on('timeout', () => state.join === join && !state.peer && ended(() => T.joinTimeout));
146
146
  join.on('failed', (reason) => state.join === join && ended(() => failText(reason)));
147
- join.on('connected', (peer, cw) => state.join === join && connected(peer, cw));
147
+ join.on('connected', (peer) => state.join === join && connected(peer));
148
148
  try {
149
149
  await join.start(words);
150
150
  } catch (err) {
@@ -152,9 +152,8 @@ export function mountJoinWindow(root, { hive, options = {}, initial = '', label
152
152
  }
153
153
  }
154
154
 
155
- function connected(peer, confirmWords) {
155
+ function connected(peer) {
156
156
  state.peer = peer;
157
- state.confirm = confirmWords;
158
157
  const bridge = new HostBridge({ hive, peer, label });
159
158
  state.bridge = bridge;
160
159
  const log = requestLog({ title: () => T.borrowLog, empty: () => T.logEmpty });
@@ -162,20 +161,8 @@ export function mountJoinWindow(root, { hive, options = {}, initial = '', label
162
161
  bridge.on('log', (e) => log.add({ ...e, status: e.kind }));
163
162
  bridge.on('detached', (why) => ended(() => T.borrowEnded(coreText(why))));
164
163
  bridge.on('attached', () => borrowing(bridge, log));
165
- const wait = live.text('p', { class: 'lend-muted', hidden: true }, () => T.confirmWaitFriend);
166
- const yes = button(
167
- 'lend-btn is-primary',
168
- 'tip.lend.confirmYes',
169
- () => T.confirmYes,
170
- () => {
171
- peer.confirmLocal();
172
- yes.disabled = no.disabled = true;
173
- if (!peer.ready) wait.hidden = false;
174
- },
175
- { dataset: { act: 'confirm' } },
176
- );
177
- const no = button('lend-btn', 'tip.lend.confirmNo', () => T.confirmNo, () => (bridge.stop('The confirmation words did not match'), ended(() => T.confirmMismatch)));
178
- set('confirm', h('section', { class: 'lend-card' }, live.text('h3', null, () => T.confirmTitle), live.text('p', null, () => T.confirmHelp), wordGrid(confirmWords, 'is-confirm'), h('div', { class: 'lend-row' }, yes, no), wait));
164
+ // The friend's hello comes first on the channel; the brain is attached a moment later.
165
+ if (state.phase !== 'borrowing') set('opening', h('section', { class: 'lend-card' }, live.text('p', { class: 'lend-status' }, () => T.joinOpening)));
179
166
  }
180
167
 
181
168
  function borrowing(bridge, log) {
@@ -1,6 +1,6 @@
1
1
  // The friend's side: the Lend screen shown by `npx hivedesk --lend`.
2
- // Six words, a QR code and a share link; then the confirmation words; then a live log of every
3
- // request with a Stop lending button that works at any moment.
2
+ // Six words, a QR code and a share link; once the friend pastes them, a live log of every
3
+ // request with a Stop lending button that works at any moment. Nothing to confirm in between.
4
4
  // Every text follows a live language switch (liveScope in view.js); unmount() unsubscribes.
5
5
 
6
6
  import { LendOffer } from './core/session.js';
@@ -16,12 +16,12 @@ import { mountP2PLend } from './p2p-screen.js';
16
16
  * hive: a connected HiveSocket (or anything with command, notify, on, hello).
17
17
  * options: passed to LendOffer (brokers, iceServers, iterations, ...), plus linkBase.
18
18
  * A 1.0 engine (lend.status has p2p) gets the grant based screen of p2p-screen.js: identities,
19
- * the SAS check, per resource limits and real revokes. options.legacy keeps the 0.2 screen for a
19
+ * per resource limits chosen before the words are made, and real revokes. options.legacy keeps the 0.2 screen for a
20
20
  * friend who still runs 0.2.
21
21
  */
22
22
  export function mountLendScreen(root, { hive, options = {}, linkBase } = {}) {
23
23
  root.classList.add('lend-screen');
24
- const state = { phase: 'idle', words: null, confirm: null, bridge: null, offer: null, peer: null, chatCommand: 'lend.chat' };
24
+ const state = { phase: 'idle', words: null, bridge: null, offer: null, peer: null, chatCommand: 'lend.chat' };
25
25
  const live = liveScope(root);
26
26
  const api = { state, start, stop, unmount, root };
27
27
  const model = () => hive.hello?.state?.brain?.model || hive.hello?.state?.settings?.brain?.model || '';
@@ -64,7 +64,7 @@ export function mountLendScreen(root, { hive, options = {}, linkBase } = {}) {
64
64
  });
65
65
  offer.on('expired', () => state.phase === 'share' && set('expired', h('section', { class: 'lend-card' }, live.text('p', null, () => T.lendExpired), newWordsButton())));
66
66
  offer.on('failed', (reason) => state.offer === offer && showFail(reason));
67
- offer.on('connected', (peer, words) => state.offer === offer && connected(peer, words));
67
+ offer.on('connected', (peer) => state.offer === offer && connected(peer));
68
68
  let words;
69
69
  try {
70
70
  words = await offer.start();
@@ -114,41 +114,24 @@ export function mountLendScreen(root, { hive, options = {}, linkBase } = {}) {
114
114
  set('failed', h('section', { class: 'lend-card' }, live.text('p', { class: 'lend-error' }, () => failText(reason)), newWordsButton()));
115
115
  }
116
116
 
117
- function connected(peer, confirmWords) {
117
+ /** The friend used the words: lending starts right away, with the indicator and Stop lending. */
118
+ function connected(peer) {
118
119
  state.peer = peer;
119
- state.confirm = confirmWords;
120
120
  const bridge = new LenderBridge({ hive, peer, info: { label: hive.hello?.label || 'friend', model: model() || undefined }, chatCommand: state.chatCommand });
121
121
  state.bridge = bridge;
122
122
  const log = requestLog({ title: () => T.logTitle, empty: () => T.logEmpty, withPreview: true });
123
123
  live.add(log.relabel, log.el);
124
124
  bridge.on('log', (e) => log.add(e));
125
125
  bridge.on('stopped', (reason) => stopped(reason));
126
- const wait = live.text('p', { class: 'lend-muted', hidden: true }, () => T.confirmWaitFriend);
127
- const yes = button(
128
- 'lend-btn is-primary',
129
- 'tip.lend.confirmYes',
130
- () => T.confirmYes,
131
- () => {
132
- peer.confirmLocal();
133
- yes.disabled = no.disabled = true;
134
- if (!peer.ready) wait.hidden = false;
135
- },
136
- { dataset: { act: 'confirm' } },
137
- );
138
- const no = button('lend-btn', 'tip.lend.confirmNo', () => T.confirmNo, () => mismatch());
139
- set('confirm', h('section', { class: 'lend-card' }, live.text('h2', null, () => T.confirmTitle), live.text('p', null, () => T.confirmHelp), wordGrid(confirmWords, 'is-confirm'), h('div', { class: 'lend-row' }, yes, no), wait));
140
- peer.on('ready', () => lending(bridge, log));
141
- if (peer.ready) lending(bridge, log);
126
+ lending(bridge, log);
127
+ peer.on('ready', () => state.phase === 'lending' && relabel());
142
128
  }
143
129
 
144
- function mismatch() {
145
- state.bridge?.stop('The confirmation words did not match');
146
- set('mismatch', h('section', { class: 'lend-card' }, live.text('p', { class: 'lend-error' }, () => T.confirmMismatch), newWordsButton()));
147
- }
130
+ let relabel = () => {};
148
131
 
149
132
  function lending(bridge, log) {
150
133
  if (state.phase === 'lending') return;
151
- const label = bridge.peer.remoteHello?.label;
134
+ const label = () => bridge.peer.remoteHello?.label;
152
135
  const counters = h('p', { class: 'lend-counters' });
153
136
  const refresh = () => {
154
137
  const used = bridge.limiter.usage().requests;
@@ -157,6 +140,8 @@ export function mountLendScreen(root, { hive, options = {}, linkBase } = {}) {
157
140
  };
158
141
  bridge.on('log', refresh);
159
142
  const m = model();
143
+ const title = live.text('h2', null, () => T.lendingTo(label() || T.yourFriend));
144
+ relabel = () => (title.textContent = T.lendingTo(label() || T.yourFriend));
160
145
  set(
161
146
  'lending',
162
147
  h(
@@ -166,7 +151,7 @@ export function mountLendScreen(root, { hive, options = {}, linkBase } = {}) {
166
151
  'div',
167
152
  { class: 'lend-live-head' },
168
153
  h('span', { class: 'lend-dot is-on', attrs: { 'aria-hidden': 'true' } }),
169
- live.text('h2', null, () => T.lendingTo(label || T.yourFriend)),
154
+ title,
170
155
  button('lend-btn is-danger', 'tip.lend.stop', () => T.stopLending, () => stop(), { dataset: { act: 'stop' } }),
171
156
  ),
172
157
  live.text('p', { class: 'lend-muted' }, () => (m ? T.lendingModel(m) : T.lendingNoModel)),
package/ui/lend/lend.css CHANGED
@@ -92,7 +92,6 @@ body.lend-page {
92
92
  }
93
93
  .lend-words b { font-weight: 600; overflow-wrap: anywhere; }
94
94
  .lend-words.is-big b { font-size: 20px; letter-spacing: 0.01em; }
95
- .lend-words.is-confirm li { border-color: rgba(242, 169, 59, 0.45); }
96
95
  .lend-n { color: var(--lend-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
97
96
 
98
97
  .lend-qr {
@@ -254,7 +253,6 @@ body.lend-page .hd-tip .kbd { font: 11px/1.4 ui-monospace, monospace; padding: 0
254
253
  .lend-num { width: 84px; background: var(--lend-panel-2); color: var(--lend-text); border: 1px solid var(--lend-line); border-radius: 8px; padding: 6px 8px; font: inherit; }
255
254
  .lend-select { background: var(--lend-panel-2); color: var(--lend-text); border: 1px solid var(--lend-line); border-radius: 8px; padding: 6px 8px; font: inherit; }
256
255
  .lend-caps { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; }
257
- .lend-sas-q { font-size: 20px; font-weight: 700; color: var(--lend-honey); }
258
256
  .lend-now { gap: 10px; }
259
257
  .lend-peer { border-top: 1px solid var(--lend-line); padding-top: 10px; display: flex; flex-direction: column; gap: 6px; }
260
258
  .lend-peer .lend-live-head { display: flex; gap: 10px; align-items: center; }
@@ -60,19 +60,6 @@ export function minutesLeft(iso, now = Date.now()) {
60
60
  return Math.max(0, Math.ceil((Date.parse(iso) - now) / 60_000));
61
61
  }
62
62
 
63
- /** The confirm card for a join request (p2p.join.request live frame). */
64
- export function confirmModel(request, offeredCaps = [], now = Date.now()) {
65
- return {
66
- requestId: request.requestId,
67
- name: request.peer.name,
68
- fingerprint: request.peer.fingerprint.words,
69
- knownBefore: !!request.peer.knownBefore,
70
- sas: request.sas,
71
- lines: offeredCaps.map(capLine),
72
- expiresIn: minutesLeft(request.expiresAt, now),
73
- };
74
- }
75
-
76
63
  /** Rows for "Lending now" from lend.grants. */
77
64
  export function lendingModel(lending = [], now = Date.now()) {
78
65
  return lending.map((p) => ({
@@ -84,14 +71,16 @@ export function lendingModel(lending = [], now = Date.now()) {
84
71
  }));
85
72
  }
86
73
 
87
- /** The Join window state from p2p.join.update frames (the last one wins). */
88
- export function joinModel(update) {
74
+ /**
75
+ * The Join window state from p2p.join.update frames (the last one wins). The engine still
76
+ * reports the handshake's short words; they are not shown, since nobody has to compare them.
77
+ */
78
+ export function joinModel(update, host = update?.host) {
89
79
  if (!update) return { phase: 'idle' };
90
80
  const out = { phase: update.phase };
91
- if (update.sas) {
92
- out.sas = update.sas;
93
- out.hostName = update.host?.name;
94
- out.hostFingerprint = update.host?.fingerprint?.words;
81
+ if (host) {
82
+ out.hostName = host.name;
83
+ out.hostFingerprint = host.fingerprint?.words;
95
84
  }
96
85
  if (update.phase === 'accepted') out.lines = (update.grants || []).map((g) => capLine(g.capability));
97
86
  if (update.phase === 'failed') out.reasonKey = `lend.p2p.join.failed.${['words', 'timeout', 'refused'].includes(update.reason) ? update.reason : 'words'}`;
@@ -1,13 +1,13 @@
1
1
  // The 1.0 Lend screen and Join window, on the engine's control plane (src/p2p/, src/lend/share.js):
2
2
  // lender: the form (GPU, CPU, RAM, storage, each with its limit) -> lend.offer -> six words
3
- // -> the window meets the friend on the relays (PipeOffer) -> the engine's join
4
- // request -> the SAS words with "Do these words match on their screen?" -> lend.accept
5
- // -> Lending now, with Revoke per person and Stop lending (real revokes)
6
- // borrower: six words -> p2p.join -> PipeJoin -> the SAS words to read out -> accepted or not
3
+ // -> the window meets the friend on the relays (PipeOffer) -> the engine lets the
4
+ // friend in with exactly what the form chose -> Lending now, with Revoke per person
5
+ // and Stop lending (real revokes). Nobody is asked anything after the words.
6
+ // borrower: six words -> p2p.join -> PipeJoin -> connected, with the list of what is lent
7
7
  // The window never holds a key; it renders what the engine reports and asks.
8
8
 
9
9
  import { PipeJoin, PipeOffer } from './core/p2p-pipe.js';
10
- import { BORROW_REQUEST, DEFAULT_FORM, MINUTE_CHOICES, canLend, capLine, confirmModel, joinModel, lendingModel, readForm } from './p2p-model.js';
10
+ import { BORROW_REQUEST, DEFAULT_FORM, MINUTE_CHOICES, canLend, capLine, joinModel, lendingModel, readForm } from './p2p-model.js';
11
11
  import { lineText, loadI18n, tx } from './p2p-text.js';
12
12
  import { clear, copyText, h, wordGrid } from './view.js';
13
13
 
@@ -22,7 +22,7 @@ export async function mountP2PLend(root, { hive, options = {} } = {}) {
22
22
  root.classList.add('lend-screen', 'is-p2p');
23
23
  // offer: the invite waiting on the relays; links: offers whose data channel carries a session
24
24
  // (they stay open after the words are used, until the session ends or the screen goes away).
25
- const state = { phase: 'form', form: readForm(DEFAULT_FORM), offer: null, links: [], invite: null, request: null };
25
+ const state = { phase: 'form', form: readForm(DEFAULT_FORM), offer: null, links: [], invite: null, joined: null };
26
26
  const dropOffer = () => {
27
27
  const o = state.offer;
28
28
  state.offer = null;
@@ -69,7 +69,7 @@ export async function mountP2PLend(root, { hive, options = {} } = {}) {
69
69
  offs.push(hive.on('live:p2p.peers', () => refreshLending()));
70
70
 
71
71
  // ---- 1. the form ----
72
- function showForm(message) {
72
+ function showForm(message, joined) {
73
73
  dropOffer();
74
74
  const f = state.form;
75
75
  const gpuOn = check(f.gpu.on);
@@ -106,6 +106,7 @@ export async function mountP2PLend(root, { hive, options = {} } = {}) {
106
106
  h('fieldset', { class: 'lend-part' }, h('legend', null, h('label', null, ramOn, h('span', { text: tx('lend.p2p.ram') }))), field(tx('lend.p2p.ramGB'), ram)),
107
107
  h('fieldset', { class: 'lend-part' }, h('legend', null, h('label', null, stOn, h('span', { text: tx('lend.p2p.storage') }))), field(tx('lend.p2p.storageGB'), st), h('label', { class: 'lend-field' }, dl, h('span', { text: tx('lend.p2p.modelDownload') }))),
108
108
  field(tx('lend.p2p.minutes'), minutes),
109
+ joined ? h('p', { class: 'lend-ok', text: tx('lend.p2p.joined', { name: joined }) }) : '',
109
110
  note,
110
111
  h('div', { class: 'lend-row' }, go)));
111
112
  }
@@ -145,34 +146,12 @@ export async function mountP2PLend(root, { hive, options = {} } = {}) {
145
146
  po.start().catch((err) => showForm(err.message));
146
147
  }
147
148
 
148
- // ---- 3. the join request: SAS words, then the person decides ----
149
- offs.push(hive.on('live:p2p.join.request', (req) => {
150
- state.request = req;
151
- const m = confirmModel(req, state.invite?.offeredCaps || []);
152
- const answer = (sasMatches) => async () => {
153
- try {
154
- if (sasMatches) await hive.command('lend.accept', { requestId: m.requestId, form: state.form, sasMatches: true });
155
- else await hive.command('p2p.join.answer', { requestId: m.requestId, accept: false, sasMatches: false });
156
- } catch (err) {
157
- return showForm(err.message);
158
- }
159
- if (!sasMatches) {
160
- state.offer?.stop();
161
- state.offer = null;
162
- }
163
- if (sasMatches) showForm();
164
- else set('mismatch', h('section', { class: 'lend-card' }, h('p', { class: 'lend-error', text: tx('lend.p2p.mismatch') }), btn('lend-btn is-primary', tx('lend.p2p.makeWords'), () => showForm())));
165
- refreshLending();
166
- };
167
- set('confirm', h('section', { class: 'lend-card lend-confirm' },
168
- h('h2', { text: tx(m.knownBefore ? 'lend.p2p.requestKnown' : 'lend.p2p.request', { name: m.name }) }),
169
- h('p', { class: 'lend-muted', text: tx('lend.p2p.theirFingerprint', { words: m.fingerprint.join(' ') }) }),
170
- h('p', { class: 'lend-sas-q', text: tx('lend.p2p.sasQuestion') }),
171
- wordGrid(m.sas, 'is-big is-confirm'),
172
- h('p', { class: 'lend-muted', text: tx('lend.p2p.sasHelp') }),
173
- h('ul', { class: 'lend-caps' }, m.lines.map((l) => h('li', { text: lineText(l) }))),
174
- m.expiresIn !== null ? h('p', { class: 'lend-muted', text: tx('lend.p2p.decideIn', { n: m.expiresIn }) }) : '',
175
- h('div', { class: 'lend-row' }, btn('lend-btn is-primary', tx('lend.p2p.match'), answer(true), { dataset: { act: 'match' } }), btn('lend-btn', tx('lend.p2p.noMatch'), answer(false), { dataset: { act: 'nomatch' } }))));
149
+ // ---- 3. the friend used the words: the engine let them in with the form's grants ----
150
+ offs.push(hive.on('live:p2p.join.decided', (d) => {
151
+ if (!d?.accepted || !d.auto || state.phase !== 'share') return;
152
+ state.joined = d.name || '';
153
+ showForm('', state.joined);
154
+ refreshLending();
176
155
  }));
177
156
  offs.push(hive.on('live:p2p.invite.burned', () => state.phase === 'share' && set('burned', h('section', { class: 'lend-card' }, h('p', { class: 'lend-error', text: tx('lend.p2p.burned') }), btn('lend-btn is-primary', tx('lend.p2p.makeWords'), () => showForm())))));
178
157
 
@@ -206,16 +185,15 @@ export async function runP2PJoin(root, { hive, words, options = {} }) {
206
185
  return { failed: err.message, stop: () => {} };
207
186
  }
208
187
  const pj = new PipeJoin({ hive, rendezvous: join.rendezvous, joinId: join.joinId, options });
188
+ let host = null;
209
189
  const render = (u) => {
210
- const m = joinModel(u);
190
+ if (u.host) host = u.host;
191
+ const m = joinModel(u, host);
211
192
  clear(box);
212
- if (m.phase === 'handshake') box.append(h('p', { class: 'lend-status', text: tx('lend.p2p.join.handshake') }));
213
- if (m.sas) {
214
- box.append(h('p', { text: tx('lend.p2p.join.sas') }), wordGrid(m.sas, 'is-big is-confirm'), h('p', { class: 'lend-muted', text: tx('lend.p2p.join.hostFingerprint', { words: (m.hostFingerprint || []).join(' ') }) }));
215
- if (m.phase === 'sas') box.append(h('p', { class: 'lend-muted', text: tx('lend.p2p.join.waiting') }));
216
- }
217
- if (m.phase === 'accepted') box.append(h('p', { class: 'lend-ok', text: tx('lend.p2p.join.accepted') }), h('ul', { class: 'lend-caps' }, m.lines.map((l) => h('li', { text: lineText(l) }))));
218
- if (m.phase === 'refused') box.append(h('p', { class: 'lend-error', text: tx(m.reason === 'sas_mismatch' ? 'lend.p2p.join.refusedMismatch' : 'lend.p2p.join.refused') }));
193
+ if (m.phase === 'handshake' || m.phase === 'sas') box.append(h('p', { class: 'lend-status', text: tx('lend.p2p.join.handshake') }));
194
+ if (m.phase === 'accepted') box.append(h('p', { class: 'lend-ok', text: tx('lend.p2p.join.accepted', { name: m.hostName || '' }) }), h('ul', { class: 'lend-caps' }, m.lines.map((l) => h('li', { text: lineText(l) }))));
195
+ if (m.hostFingerprint && m.phase === 'accepted') box.append(h('p', { class: 'lend-muted', text: tx('lend.p2p.join.hostFingerprint', { words: m.hostFingerprint.join(' ') }) }));
196
+ if (m.phase === 'refused') box.append(h('p', { class: 'lend-error', text: tx('lend.p2p.join.refused') }));
219
197
  if (m.phase === 'failed') box.append(h('p', { class: 'lend-error', text: tx(m.reasonKey) }));
220
198
  root.dataset.phase = m.phase;
221
199
  if (m.phase === 'failed' || m.phase === 'refused') pj.stop();
@@ -4,7 +4,7 @@
4
4
 
5
5
  export const P2P_EN = Object.freeze({
6
6
  'lend.p2p.formTitle': 'What you lend',
7
- 'lend.p2p.formHelp': 'Nothing is shared until you accept someone. Each part has its own limit, and every grant ends on time or when you stop.',
7
+ 'lend.p2p.formHelp': 'Choose what to lend, then make the words. Whoever uses them gets exactly this, right away. Each part has its own limit, and every grant ends on time or when you stop.',
8
8
  'lend.p2p.gpu': 'GPU',
9
9
  'lend.p2p.gpuVram': 'VRAM limit in GB',
10
10
  'lend.p2p.cpu': 'CPU',
@@ -30,15 +30,7 @@ export const P2P_EN = Object.freeze({
30
30
  'lend.p2p.cap.storageDownload': 'Storage: up to {gb} GB, model downloads allowed',
31
31
  'lend.p2p.cap.cityView': 'See your City (no file contents)',
32
32
  'lend.p2p.cap.other': '{name}',
33
- 'lend.p2p.request': '{name} wants to borrow this PC',
34
- 'lend.p2p.requestKnown': '{name} wants to borrow this PC again',
35
33
  'lend.p2p.theirFingerprint': 'Their fingerprint: {words}',
36
- 'lend.p2p.sasQuestion': 'Do these words match on their screen?',
37
- 'lend.p2p.sasHelp': 'Ask your friend to read the six words on their screen. Accept only if every word is the same.',
38
- 'lend.p2p.match': 'They match: lend',
39
- 'lend.p2p.noMatch': 'They do not match',
40
- 'lend.p2p.mismatch': 'The words did not match, so nobody was let in. Make new words and try again.',
41
- 'lend.p2p.decideIn': 'Decide within {n} minutes',
42
34
  'lend.p2p.lendingTitle': 'Lending now',
43
35
  'lend.p2p.left': '{n} minutes left',
44
36
  'lend.p2p.revoke': 'Revoke',
@@ -50,15 +42,13 @@ export const P2P_EN = Object.freeze({
50
42
  'lend.p2p.join.start': 'Join',
51
43
  'lend.p2p.join.meeting': 'Meeting your friend on the relays...',
52
44
  'lend.p2p.join.handshake': 'Checking the words...',
53
- 'lend.p2p.join.sas': 'Read these six words to your friend. They accept only if their screen shows the same words.',
54
45
  'lend.p2p.join.hostFingerprint': 'Their fingerprint: {words}',
55
- 'lend.p2p.join.waiting': 'Waiting for your friend to accept...',
56
- 'lend.p2p.join.accepted': 'Your friend accepted. You may use:',
57
- 'lend.p2p.join.refused': 'Your friend did not accept.',
58
- 'lend.p2p.join.refusedMismatch': 'Your friend saw other words, so the connection was refused. Someone else may have the words; ask for new ones.',
46
+ 'lend.p2p.join.accepted': 'Connected to {name}. You may use:',
47
+ 'lend.p2p.join.refused': 'Your friend\'s PC did not let you in.',
59
48
  'lend.p2p.join.failed.words': 'The words did not work. They work once and for 10 minutes; ask for new words.',
60
49
  'lend.p2p.join.failed.timeout': 'Nobody answered in time.',
61
50
  'lend.p2p.join.failed.refused': 'That PC refused the connection.',
51
+ 'lend.p2p.joined': '{name} is in and can use what you chose. Make new words for someone else.',
62
52
  });
63
53
 
64
54
  let i18n = null;
package/ui/lend/text.js CHANGED
@@ -20,12 +20,6 @@ export const T = {
20
20
  get copied() { return t('lend.copied'); },
21
21
  get newWords() { return t('lend.newWords'); },
22
22
  get shareLink() { return t('lend.shareLink'); },
23
- get confirmTitle() { return t('lend.confirm.title'); },
24
- get confirmHelp() { return t('lend.confirm.help'); },
25
- get confirmYes() { return t('lend.confirm.yes'); },
26
- get confirmNo() { return t('lend.confirm.no'); },
27
- get confirmWaitFriend() { return t('lend.confirm.waitFriend'); },
28
- get confirmMismatch() { return t('lend.confirm.mismatch'); },
29
23
  lendingTo: (who) => t('lend.lending.to', { who }),
30
24
  lendingModel: (model) => t('lend.lending.model', { model }),
31
25
  get lendingNoModel() { return t('lend.lending.noModel'); },
@@ -57,6 +51,7 @@ export const T = {
57
51
  get joinIncomplete() { return t('lend.join.incomplete'); },
58
52
  get joinUnknown() { return t('lend.join.unknown'); },
59
53
  get joinKnocking() { return t('lend.join.knocking'); },
54
+ get joinOpening() { return t('lend.join.opening'); },
60
55
  get joinTimeout() { return t('lend.join.timeout'); },
61
56
  borrowing: (who, model) => (model ? t('lend.borrow.usingModel', { who, model }) : t('lend.borrow.using', { who })),
62
57
  get borrowingNote() { return t('lend.borrow.note'); },
package/ui/lend/view.js CHANGED
@@ -185,7 +185,7 @@ const CORE = {
185
185
  'Frames are text': 'lend.core.notText',
186
186
  'A frame is not valid JSON': 'lend.core.badJson',
187
187
  'The friend could not answer': 'lend.core.noAnswer',
188
- 'A frame arrived before the confirmation words were checked': 'lend.core.notConfirmed',
188
+ 'A frame arrived before the hello': 'lend.core.noHello',
189
189
  'The connection is closed': 'lend.core.closed',
190
190
  'link is not open': 'lend.core.closed',
191
191
  'Lending is stopped': 'lend.core.lendingStopped',