@ping-app/ping-openmls-sdk 0.10.6 → 0.10.7

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/dist/worker.js CHANGED
@@ -64,6 +64,7 @@ import init, {
64
64
  openStateBackup as wasmOpenStateBackup,
65
65
  refreshStateBackup as wasmRefreshStateBackup,
66
66
  endPending as wasmEndPending,
67
+ discardPendingRoot as wasmDiscardPendingRoot,
67
68
  beginAccountSetupInMemoryOn as wasmBeginAccountSetupInMemoryOn,
68
69
  prepareDeviceKey as wasmPrepareDeviceKey,
69
70
  discardPreparedDeviceKey as wasmDiscardPreparedDeviceKey,
@@ -312,11 +313,17 @@ function changedHoldings(before, after) {
312
313
  }
313
314
 
314
315
  // src/catch-up-pass.ts
316
+ var STORE_MOVED = "store moved: ";
317
+ function isStoreMoved(e) {
318
+ const text = typeof e === "string" ? e : e !== null && typeof e === "object" && typeof e.message === "string" ? e.message : null;
319
+ return text !== null && text.startsWith(STORE_MOVED);
320
+ }
315
321
  function catchUpPass(deps) {
316
322
  const seen = /* @__PURE__ */ new Set();
317
323
  const delivered = [];
318
324
  let pending = null;
319
325
  let relisted = false;
326
+ let stopped = false;
320
327
  const sortedUnseen = (ids) => ids.filter((id) => !seen.has(conversationKey(id))).sort((a, b) => conversationKey(a) < conversationKey(b) ? -1 : 1);
321
328
  const initial = async () => {
322
329
  const heads = await deps.fetchHeads();
@@ -327,6 +334,16 @@ function catchUpPass(deps) {
327
334
  return sortedUnseen(behind);
328
335
  };
329
336
  return async () => {
337
+ if (stopped) return false;
338
+ if (pending === null) {
339
+ try {
340
+ await deps.door();
341
+ } catch (e) {
342
+ stopped = true;
343
+ deps.finish(false, e);
344
+ return false;
345
+ }
346
+ }
330
347
  try {
331
348
  if (pending === null) pending = await initial();
332
349
  if (pending.length === 0 && !relisted) {
@@ -339,6 +356,13 @@ function catchUpPass(deps) {
339
356
  }
340
357
  const id = pending[0];
341
358
  if (id === void 0) {
359
+ try {
360
+ await deps.door();
361
+ } catch (e) {
362
+ stopped = true;
363
+ deps.finish(false, e);
364
+ return false;
365
+ }
342
366
  deps.finish(true, delivered);
343
367
  return false;
344
368
  }
@@ -348,7 +372,12 @@ function catchUpPass(deps) {
348
372
  for (const m of page.messages) delivered.push(m);
349
373
  deps.onPage(page);
350
374
  more = page.has_more;
351
- } catch {
375
+ } catch (e) {
376
+ if (isStoreMoved(e)) {
377
+ stopped = true;
378
+ deps.finish(false, e);
379
+ return false;
380
+ }
352
381
  }
353
382
  if (!more) {
354
383
  seen.add(conversationKey(id));
@@ -816,6 +845,12 @@ function catchUpPassStepper(msg) {
816
845
  return false;
817
846
  }
818
847
  pass = catchUpPass({
848
+ // The client's door (ruling V1993): a guarded call that does nothing
849
+ // on a live client (no id, so no row and no checkpoint) and rejects
850
+ // with the typed stop on a client that failed closed.
851
+ door: async () => {
852
+ await ensureClient().confirmApplied([]);
853
+ },
819
854
  listConversationIds: () => ensureClient().listConversations().map((meta) => meta.id),
820
855
  fetchHeads: async () => transportFeatures.fetchLogHeads ? await fetchLogHeadsProxy() ?? null : null,
821
856
  conversationsBehind: (heads) => ensureClient().conversationsBehind(heads),
@@ -1083,6 +1118,16 @@ async function dispatchRequest(msg) {
1083
1118
  return null;
1084
1119
  });
1085
1120
  }
1121
+ case "discardPendingRoot": {
1122
+ return accountExclusive(async () => {
1123
+ const store = pendingStore();
1124
+ return wasmDiscardPendingRoot(
1125
+ makeProxyStorage(msg.storageFeatures),
1126
+ store,
1127
+ msg.slot
1128
+ );
1129
+ });
1130
+ }
1086
1131
  // The restore as a rotation: the same Worker that never runs a client.
1087
1132
  case "openBackupForRestore": {
1088
1133
  accountWorker();