@ping-app/ping-openmls-sdk 0.10.5 → 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/index.cjs +191 -64
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +106 -23
- package/dist/index.d.ts +106 -23
- package/dist/index.js +191 -64
- package/dist/index.js.map +1 -1
- package/dist/notification-preview.d.cts +1 -1
- package/dist/notification-preview.d.ts +1 -1
- package/dist/storage/indexeddb.d.cts +1 -1
- package/dist/storage/indexeddb.d.ts +1 -1
- package/dist/transport/websocket.d.cts +1 -1
- package/dist/transport/websocket.d.ts +1 -1
- package/dist/{types-omhvRjtq.d.cts → types-D8fIp-_0.d.cts} +28 -0
- package/dist/{types-omhvRjtq.d.ts → types-D8fIp-_0.d.ts} +28 -0
- package/dist/worker.cjs +79 -6
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.js +84 -7
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
- package/wasm/package.json +1 -1
- package/wasm/ping_wasm.d.ts +55 -2
- package/wasm/ping_wasm.js +121 -32
- package/wasm/ping_wasm_bg.wasm +0 -0
- package/wasm/ping_wasm_bg.wasm.d.ts +7 -2
package/dist/worker.js
CHANGED
|
@@ -64,7 +64,11 @@ import init, {
|
|
|
64
64
|
openStateBackup as wasmOpenStateBackup,
|
|
65
65
|
refreshStateBackup as wasmRefreshStateBackup,
|
|
66
66
|
endPending as wasmEndPending,
|
|
67
|
-
|
|
67
|
+
discardPendingRoot as wasmDiscardPendingRoot,
|
|
68
|
+
beginAccountSetupInMemoryOn as wasmBeginAccountSetupInMemoryOn,
|
|
69
|
+
prepareDeviceKey as wasmPrepareDeviceKey,
|
|
70
|
+
discardPreparedDeviceKey as wasmDiscardPreparedDeviceKey,
|
|
71
|
+
deviceStartCheck as wasmDeviceStartCheck
|
|
68
72
|
} from "../wasm/ping_wasm";
|
|
69
73
|
|
|
70
74
|
// src/pending-root-store.ts
|
|
@@ -309,11 +313,17 @@ function changedHoldings(before, after) {
|
|
|
309
313
|
}
|
|
310
314
|
|
|
311
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
|
+
}
|
|
312
321
|
function catchUpPass(deps) {
|
|
313
322
|
const seen = /* @__PURE__ */ new Set();
|
|
314
323
|
const delivered = [];
|
|
315
324
|
let pending = null;
|
|
316
325
|
let relisted = false;
|
|
326
|
+
let stopped = false;
|
|
317
327
|
const sortedUnseen = (ids) => ids.filter((id) => !seen.has(conversationKey(id))).sort((a, b) => conversationKey(a) < conversationKey(b) ? -1 : 1);
|
|
318
328
|
const initial = async () => {
|
|
319
329
|
const heads = await deps.fetchHeads();
|
|
@@ -324,6 +334,16 @@ function catchUpPass(deps) {
|
|
|
324
334
|
return sortedUnseen(behind);
|
|
325
335
|
};
|
|
326
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
|
+
}
|
|
327
347
|
try {
|
|
328
348
|
if (pending === null) pending = await initial();
|
|
329
349
|
if (pending.length === 0 && !relisted) {
|
|
@@ -336,6 +356,13 @@ function catchUpPass(deps) {
|
|
|
336
356
|
}
|
|
337
357
|
const id = pending[0];
|
|
338
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
|
+
}
|
|
339
366
|
deps.finish(true, delivered);
|
|
340
367
|
return false;
|
|
341
368
|
}
|
|
@@ -345,7 +372,12 @@ function catchUpPass(deps) {
|
|
|
345
372
|
for (const m of page.messages) delivered.push(m);
|
|
346
373
|
deps.onPage(page);
|
|
347
374
|
more = page.has_more;
|
|
348
|
-
} catch {
|
|
375
|
+
} catch (e) {
|
|
376
|
+
if (isStoreMoved(e)) {
|
|
377
|
+
stopped = true;
|
|
378
|
+
deps.finish(false, e);
|
|
379
|
+
return false;
|
|
380
|
+
}
|
|
349
381
|
}
|
|
350
382
|
if (!more) {
|
|
351
383
|
seen.add(conversationKey(id));
|
|
@@ -423,6 +455,11 @@ function accountExclusive(run) {
|
|
|
423
455
|
}
|
|
424
456
|
return locks.request(ACCOUNT_LOCK_NAME, run);
|
|
425
457
|
}
|
|
458
|
+
function linkBeginExclusive(run) {
|
|
459
|
+
const locks = globalThis.navigator?.locks;
|
|
460
|
+
if (!locks || typeof locks.request !== "function") return run();
|
|
461
|
+
return locks.request(ACCOUNT_LOCK_NAME, run);
|
|
462
|
+
}
|
|
426
463
|
function pendingStore() {
|
|
427
464
|
accountWorker();
|
|
428
465
|
pendingRootStore ??= new PendingRootStore();
|
|
@@ -808,6 +845,12 @@ function catchUpPassStepper(msg) {
|
|
|
808
845
|
return false;
|
|
809
846
|
}
|
|
810
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
|
+
},
|
|
811
854
|
listConversationIds: () => ensureClient().listConversations().map((meta) => meta.id),
|
|
812
855
|
fetchHeads: async () => transportFeatures.fetchLogHeads ? await fetchLogHeadsProxy() ?? null : null,
|
|
813
856
|
conversationsBehind: (heads) => ensureClient().conversationsBehind(heads),
|
|
@@ -898,12 +941,13 @@ async function dispatchRequest(msg) {
|
|
|
898
941
|
case "beginDeviceLink": {
|
|
899
942
|
clientWorker();
|
|
900
943
|
transportFeatures = msg.transportFeatures ?? { fetchLogSince: false, fetchLogHeads: false };
|
|
901
|
-
const
|
|
944
|
+
const linkTransport = makeProxyTransport(transportFeatures);
|
|
945
|
+
const begun = await linkBeginExclusive(() => wasmBeginDeviceLink(
|
|
902
946
|
msg.deviceLabel,
|
|
903
947
|
makeProxyStorage(msg.storageFeatures),
|
|
904
|
-
|
|
948
|
+
linkTransport,
|
|
905
949
|
msg.nowMs
|
|
906
|
-
);
|
|
950
|
+
));
|
|
907
951
|
try {
|
|
908
952
|
client = begun.takeClient();
|
|
909
953
|
client.onMessage((m) => {
|
|
@@ -1014,6 +1058,22 @@ async function dispatchRequest(msg) {
|
|
|
1014
1058
|
);
|
|
1015
1059
|
});
|
|
1016
1060
|
}
|
|
1061
|
+
// The prepared device key: the two calls that write hold the origin's
|
|
1062
|
+
// account lock (two tabs that prepare at once answer ONE key); a realm
|
|
1063
|
+
// with no Web Locks is refused, typed. The predicate reads only.
|
|
1064
|
+
case "prepareDeviceKey": {
|
|
1065
|
+
return accountExclusive(() => wasmPrepareDeviceKey(makeProxyStorage(msg.storageFeatures), msg.nowMs));
|
|
1066
|
+
}
|
|
1067
|
+
case "discardPreparedDeviceKey": {
|
|
1068
|
+
return accountExclusive(() => wasmDiscardPreparedDeviceKey(makeProxyStorage(msg.storageFeatures)));
|
|
1069
|
+
}
|
|
1070
|
+
case "deviceStartCheck": {
|
|
1071
|
+
accountWorker();
|
|
1072
|
+
return wasmDeviceStartCheck(
|
|
1073
|
+
makeProxyStorage(msg.storageFeatures),
|
|
1074
|
+
msg.expectedDeviceId ?? null
|
|
1075
|
+
);
|
|
1076
|
+
}
|
|
1017
1077
|
case "pendingStatus": {
|
|
1018
1078
|
const store = pendingStore();
|
|
1019
1079
|
return wasmPendingStatus(
|
|
@@ -1058,6 +1118,16 @@ async function dispatchRequest(msg) {
|
|
|
1058
1118
|
return null;
|
|
1059
1119
|
});
|
|
1060
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
|
+
}
|
|
1061
1131
|
// The restore as a rotation: the same Worker that never runs a client.
|
|
1062
1132
|
case "openBackupForRestore": {
|
|
1063
1133
|
accountWorker();
|
|
@@ -1166,8 +1236,15 @@ async function dispatchRequest(msg) {
|
|
|
1166
1236
|
case "beginAccountSetupInMemory": {
|
|
1167
1237
|
accountWorker();
|
|
1168
1238
|
if (setupSession) throw new Error("account refused: setup-session-open");
|
|
1169
|
-
|
|
1170
|
-
|
|
1239
|
+
return accountExclusive(async () => {
|
|
1240
|
+
if (setupSession) throw new Error("account refused: setup-session-open");
|
|
1241
|
+
setupSession = await wasmBeginAccountSetupInMemoryOn(
|
|
1242
|
+
makeProxyStorage(msg.storageFeatures),
|
|
1243
|
+
msg.identityState,
|
|
1244
|
+
msg.nowMs
|
|
1245
|
+
);
|
|
1246
|
+
return null;
|
|
1247
|
+
});
|
|
1171
1248
|
}
|
|
1172
1249
|
case "setupSessionMakeBackup":
|
|
1173
1250
|
return openSession().makeBackup(msg.phrase, msg.accountId, msg.hostState, msg.nowMs);
|