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

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,7 +64,10 @@ import init, {
64
64
  openStateBackup as wasmOpenStateBackup,
65
65
  refreshStateBackup as wasmRefreshStateBackup,
66
66
  endPending as wasmEndPending,
67
- beginAccountSetupInMemory as wasmBeginAccountSetupInMemory
67
+ beginAccountSetupInMemoryOn as wasmBeginAccountSetupInMemoryOn,
68
+ prepareDeviceKey as wasmPrepareDeviceKey,
69
+ discardPreparedDeviceKey as wasmDiscardPreparedDeviceKey,
70
+ deviceStartCheck as wasmDeviceStartCheck
68
71
  } from "../wasm/ping_wasm";
69
72
 
70
73
  // src/pending-root-store.ts
@@ -423,6 +426,11 @@ function accountExclusive(run) {
423
426
  }
424
427
  return locks.request(ACCOUNT_LOCK_NAME, run);
425
428
  }
429
+ function linkBeginExclusive(run) {
430
+ const locks = globalThis.navigator?.locks;
431
+ if (!locks || typeof locks.request !== "function") return run();
432
+ return locks.request(ACCOUNT_LOCK_NAME, run);
433
+ }
426
434
  function pendingStore() {
427
435
  accountWorker();
428
436
  pendingRootStore ??= new PendingRootStore();
@@ -898,12 +906,13 @@ async function dispatchRequest(msg) {
898
906
  case "beginDeviceLink": {
899
907
  clientWorker();
900
908
  transportFeatures = msg.transportFeatures ?? { fetchLogSince: false, fetchLogHeads: false };
901
- const begun = await wasmBeginDeviceLink(
909
+ const linkTransport = makeProxyTransport(transportFeatures);
910
+ const begun = await linkBeginExclusive(() => wasmBeginDeviceLink(
902
911
  msg.deviceLabel,
903
912
  makeProxyStorage(msg.storageFeatures),
904
- makeProxyTransport(transportFeatures),
913
+ linkTransport,
905
914
  msg.nowMs
906
- );
915
+ ));
907
916
  try {
908
917
  client = begun.takeClient();
909
918
  client.onMessage((m) => {
@@ -1014,6 +1023,22 @@ async function dispatchRequest(msg) {
1014
1023
  );
1015
1024
  });
1016
1025
  }
1026
+ // The prepared device key: the two calls that write hold the origin's
1027
+ // account lock (two tabs that prepare at once answer ONE key); a realm
1028
+ // with no Web Locks is refused, typed. The predicate reads only.
1029
+ case "prepareDeviceKey": {
1030
+ return accountExclusive(() => wasmPrepareDeviceKey(makeProxyStorage(msg.storageFeatures), msg.nowMs));
1031
+ }
1032
+ case "discardPreparedDeviceKey": {
1033
+ return accountExclusive(() => wasmDiscardPreparedDeviceKey(makeProxyStorage(msg.storageFeatures)));
1034
+ }
1035
+ case "deviceStartCheck": {
1036
+ accountWorker();
1037
+ return wasmDeviceStartCheck(
1038
+ makeProxyStorage(msg.storageFeatures),
1039
+ msg.expectedDeviceId ?? null
1040
+ );
1041
+ }
1017
1042
  case "pendingStatus": {
1018
1043
  const store = pendingStore();
1019
1044
  return wasmPendingStatus(
@@ -1166,8 +1191,15 @@ async function dispatchRequest(msg) {
1166
1191
  case "beginAccountSetupInMemory": {
1167
1192
  accountWorker();
1168
1193
  if (setupSession) throw new Error("account refused: setup-session-open");
1169
- setupSession = wasmBeginAccountSetupInMemory(msg.identityState, msg.nowMs);
1170
- return null;
1194
+ return accountExclusive(async () => {
1195
+ if (setupSession) throw new Error("account refused: setup-session-open");
1196
+ setupSession = await wasmBeginAccountSetupInMemoryOn(
1197
+ makeProxyStorage(msg.storageFeatures),
1198
+ msg.identityState,
1199
+ msg.nowMs
1200
+ );
1201
+ return null;
1202
+ });
1171
1203
  }
1172
1204
  case "setupSessionMakeBackup":
1173
1205
  return openSession().makeBackup(msg.phrase, msg.accountId, msg.hostState, msg.nowMs);