@mmstack/mesh 21.16.0 → 21.16.1

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 CHANGED
@@ -193,7 +193,11 @@ the outbox. The new tab's next save is then refused, and its handle ends `ejecte
193
193
  an earlier write that has already started, so over idb-keyval this is not expected.
194
194
 
195
195
  The saved outbox also keeps this client's origin, so every boot that reads it continues as the same
196
- client: one origin per saved outbox, stable across reloads. Two keys are written, `<key>:log` and
196
+ client: one origin per saved outbox, stable across reloads. Pass `originPrefix` to make every origin
197
+ this client mints start with a string of yours. A host that gives each writer its own prefix can
198
+ then check at the hello whose an origin is, with nothing stored: its relay's `canJoin` compares the
199
+ start of the origin with the writer it authenticated. `agentSeat` takes the same option. An outbox
200
+ that already holds an origin keeps it, so set the prefix before the first boot, or clear the outbox. Two keys are written, `<key>:log` and
197
201
  `<key>:snap`, and nothing is deleted from them. An outbox saved by an earlier version of this
198
202
  library under `key` itself is not read: it is deleted unread at each boot, when the store can
199
203
  delete, and the writes it held are not sent.
@@ -2453,9 +2453,10 @@ const bornReason = (e) => {
2453
2453
  * Boots the journal under `key` in `store` (a memory journal without one): removes the old client's
2454
2454
  * slot under `key` unread, when the store can delete, then reads the journal. Nothing is written
2455
2455
  * until `open()`. A stored journal that cannot be read is left untouched and this boot runs over a
2456
- * memory journal.
2456
+ * memory journal. An origin minted by `open()` starts with `originPrefix`; a journal that holds an
2457
+ * origin keeps it.
2457
2458
  */
2458
- function sessionBoot(outbox, hooks = {}) {
2459
+ function sessionBoot(outbox, hooks = {}, originPrefix = '') {
2459
2460
  let ended = false;
2460
2461
  let reading = false;
2461
2462
  let j = null;
@@ -2529,7 +2530,7 @@ function sessionBoot(outbox, hooks = {}) {
2529
2530
  const had = journal.state().origin;
2530
2531
  if (had)
2531
2532
  return { ...opened, origin: had, born: Promise.resolve() };
2532
- const origin = mintOrigin();
2533
+ const origin = originPrefix + mintOrigin();
2533
2534
  const landed = journal.submit([{ k: 'born', origin }]);
2534
2535
  const stop = journal.ended();
2535
2536
  const born = landed
@@ -3484,7 +3485,7 @@ function meshSync(source, opt) {
3484
3485
  unreadableOutbox = true;
3485
3486
  changed();
3486
3487
  },
3487
- });
3488
+ }, opt.originPrefix);
3488
3489
  boot = b;
3489
3490
  let read;
3490
3491
  try {
@@ -3789,7 +3790,7 @@ function agentSeat(initial, opt) {
3789
3790
  env.policyVersion === policyVersion &&
3790
3791
  checkEnvelope(opt.policy, env, { ...opt.ctx, writer: opt.writer }, opt.room, { seq: 0, empty: !!env.seed }) === null;
3791
3792
  const start = async () => {
3792
- const b = sessionBoot(undefined);
3793
+ const b = sessionBoot(undefined, {}, opt.originPrefix);
3793
3794
  boot = b;
3794
3795
  let read;
3795
3796
  let opened;