@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.
@@ -1,4 +1,4 @@
1
- import { S as Storage, M as MessageEnvelope, I as IncomingMessage } from './types-omhvRjtq.cjs';
1
+ import { S as Storage, M as MessageEnvelope, I as IncomingMessage } from './types-D8fIp-_0.cjs';
2
2
 
3
3
  /**
4
4
  * Wrap a host `Storage` so every namespace carries the per-account scope
@@ -1,4 +1,4 @@
1
- import { S as Storage, M as MessageEnvelope, I as IncomingMessage } from './types-omhvRjtq.js';
1
+ import { S as Storage, M as MessageEnvelope, I as IncomingMessage } from './types-D8fIp-_0.js';
2
2
 
3
3
  /**
4
4
  * Wrap a host `Storage` so every namespace carries the per-account scope
@@ -1,4 +1,4 @@
1
- import { S as Storage } from '../types-omhvRjtq.cjs';
1
+ import { S as Storage } from '../types-D8fIp-_0.cjs';
2
2
 
3
3
  declare class IndexedDbStorage implements Storage {
4
4
  private dbPromise;
@@ -1,4 +1,4 @@
1
- import { S as Storage } from '../types-omhvRjtq.js';
1
+ import { S as Storage } from '../types-D8fIp-_0.js';
2
2
 
3
3
  declare class IndexedDbStorage implements Storage {
4
4
  private dbPromise;
@@ -1,4 +1,4 @@
1
- import { T as Transport, M as MessageEnvelope, C as ConversationId, U as UserId, D as DiscoveredDevice } from '../types-omhvRjtq.cjs';
1
+ import { T as Transport, M as MessageEnvelope, C as ConversationId, U as UserId, D as DiscoveredDevice } from '../types-D8fIp-_0.cjs';
2
2
 
3
3
  interface WsTransportConfig {
4
4
  baseUrl: string;
@@ -1,4 +1,4 @@
1
- import { T as Transport, M as MessageEnvelope, C as ConversationId, U as UserId, D as DiscoveredDevice } from '../types-omhvRjtq.js';
1
+ import { T as Transport, M as MessageEnvelope, C as ConversationId, U as UserId, D as DiscoveredDevice } from '../types-D8fIp-_0.js';
2
2
 
3
3
  interface WsTransportConfig {
4
4
  baseUrl: string;
@@ -587,6 +587,30 @@ interface ApplyBatchResult {
587
587
  * `confirmApplied`, then hand the rows again (the same batch, or the
588
588
  * conversation's next page). Empty in every other case. */
589
589
  journalFull: JournalFullAt[];
590
+ /** THE SDK OWNS THE JOURNAL'S PACE (2026-11-28). The INDEXES, into the rows
591
+ * this call was handed and ascending, of every row it did NOT take because
592
+ * the pending-apply journal had no room. Keep exactly those rows, in this
593
+ * order and in front of anything newer; save the messages handed over,
594
+ * call `confirmApplied`, hand them again. Empty: every row was taken.
595
+ *
596
+ * The call takes the longest prefix of the hand, in arrival order, that
597
+ * fits: from the first application row with no room, no application row is
598
+ * taken; a Commit, a proposal or a Welcome behind it is, unless an earlier
599
+ * row of its own conversation was not. A row not taken was not consumed:
600
+ * not acknowledged, not held, not kept, not a hole, and no gap is reported
601
+ * for it, so no page is owed. */
602
+ notTaken: number[];
603
+ /** The entries free in the pending-apply journal at the end of this call.
604
+ * Each id a later `confirmApplied` removes frees one more. THE ROOM IS
605
+ * ADVICE: with nothing to confirm, a host hands what it holds anyway,
606
+ * whatever room the last answer stated (the call cuts by itself). A call
607
+ * with no rows answers the room and takes no row; it releases the held
608
+ * frames an earlier call could not release for want of room. */
609
+ journalRoomRows: number;
610
+ /** The record bytes free in the journal at the end of this call (an
611
+ * application row needs its payload length plus 1024; an empty journal
612
+ * takes one row of any size). */
613
+ journalRoomBytes: number;
590
614
  /** THE ACCOUNT'S STATE PART IS OWED A WRITE (2026-11-27): the anchor record
591
615
  * changed (a join, a leave, a change of a group's owner or admins). Said
592
616
  * once, with the batch at which the SDK saw it; the host calls
@@ -620,6 +644,10 @@ interface SyncStepResult {
620
644
  /** As `ApplyBatchResult.journalFull`. A page that stopped for the journal
621
645
  * and moved no position answers `hasMore: false`. */
622
646
  journalFull: JournalFullAt[];
647
+ /** As `ApplyBatchResult.journalRoomRows`: the room at the end of this page. */
648
+ journalRoomRows: number;
649
+ /** As `ApplyBatchResult.journalRoomBytes`. */
650
+ journalRoomBytes: number;
623
651
  }
624
652
  /** Where a batch delivered to `onMessageBatch` came from: a live socket
625
653
  * batch, or a page of the server log (a gap fill, or the whole-account
@@ -587,6 +587,30 @@ interface ApplyBatchResult {
587
587
  * `confirmApplied`, then hand the rows again (the same batch, or the
588
588
  * conversation's next page). Empty in every other case. */
589
589
  journalFull: JournalFullAt[];
590
+ /** THE SDK OWNS THE JOURNAL'S PACE (2026-11-28). The INDEXES, into the rows
591
+ * this call was handed and ascending, of every row it did NOT take because
592
+ * the pending-apply journal had no room. Keep exactly those rows, in this
593
+ * order and in front of anything newer; save the messages handed over,
594
+ * call `confirmApplied`, hand them again. Empty: every row was taken.
595
+ *
596
+ * The call takes the longest prefix of the hand, in arrival order, that
597
+ * fits: from the first application row with no room, no application row is
598
+ * taken; a Commit, a proposal or a Welcome behind it is, unless an earlier
599
+ * row of its own conversation was not. A row not taken was not consumed:
600
+ * not acknowledged, not held, not kept, not a hole, and no gap is reported
601
+ * for it, so no page is owed. */
602
+ notTaken: number[];
603
+ /** The entries free in the pending-apply journal at the end of this call.
604
+ * Each id a later `confirmApplied` removes frees one more. THE ROOM IS
605
+ * ADVICE: with nothing to confirm, a host hands what it holds anyway,
606
+ * whatever room the last answer stated (the call cuts by itself). A call
607
+ * with no rows answers the room and takes no row; it releases the held
608
+ * frames an earlier call could not release for want of room. */
609
+ journalRoomRows: number;
610
+ /** The record bytes free in the journal at the end of this call (an
611
+ * application row needs its payload length plus 1024; an empty journal
612
+ * takes one row of any size). */
613
+ journalRoomBytes: number;
590
614
  /** THE ACCOUNT'S STATE PART IS OWED A WRITE (2026-11-27): the anchor record
591
615
  * changed (a join, a leave, a change of a group's owner or admins). Said
592
616
  * once, with the batch at which the SDK saw it; the host calls
@@ -620,6 +644,10 @@ interface SyncStepResult {
620
644
  /** As `ApplyBatchResult.journalFull`. A page that stopped for the journal
621
645
  * and moved no position answers `hasMore: false`. */
622
646
  journalFull: JournalFullAt[];
647
+ /** As `ApplyBatchResult.journalRoomRows`: the room at the end of this page. */
648
+ journalRoomRows: number;
649
+ /** As `ApplyBatchResult.journalRoomBytes`. */
650
+ journalRoomBytes: number;
623
651
  }
624
652
  /** Where a batch delivered to `onMessageBatch` came from: a live socket
625
653
  * batch, or a page of the server log (a gap fill, or the whole-account
package/dist/worker.cjs CHANGED
@@ -397,6 +397,11 @@ function accountExclusive(run) {
397
397
  }
398
398
  return locks.request(ACCOUNT_LOCK_NAME, run);
399
399
  }
400
+ function linkBeginExclusive(run) {
401
+ const locks = globalThis.navigator?.locks;
402
+ if (!locks || typeof locks.request !== "function") return run();
403
+ return locks.request(ACCOUNT_LOCK_NAME, run);
404
+ }
400
405
  function pendingStore() {
401
406
  accountWorker();
402
407
  pendingRootStore ??= new PendingRootStore();
@@ -872,12 +877,13 @@ async function dispatchRequest(msg) {
872
877
  case "beginDeviceLink": {
873
878
  clientWorker();
874
879
  transportFeatures = msg.transportFeatures ?? { fetchLogSince: false, fetchLogHeads: false };
875
- const begun = await (0, import_ping_wasm.beginDeviceLink)(
880
+ const linkTransport = makeProxyTransport(transportFeatures);
881
+ const begun = await linkBeginExclusive(() => (0, import_ping_wasm.beginDeviceLink)(
876
882
  msg.deviceLabel,
877
883
  makeProxyStorage(msg.storageFeatures),
878
- makeProxyTransport(transportFeatures),
884
+ linkTransport,
879
885
  msg.nowMs
880
- );
886
+ ));
881
887
  try {
882
888
  client = begun.takeClient();
883
889
  client.onMessage((m) => {
@@ -988,6 +994,22 @@ async function dispatchRequest(msg) {
988
994
  );
989
995
  });
990
996
  }
997
+ // The prepared device key: the two calls that write hold the origin's
998
+ // account lock (two tabs that prepare at once answer ONE key); a realm
999
+ // with no Web Locks is refused, typed. The predicate reads only.
1000
+ case "prepareDeviceKey": {
1001
+ return accountExclusive(() => (0, import_ping_wasm.prepareDeviceKey)(makeProxyStorage(msg.storageFeatures), msg.nowMs));
1002
+ }
1003
+ case "discardPreparedDeviceKey": {
1004
+ return accountExclusive(() => (0, import_ping_wasm.discardPreparedDeviceKey)(makeProxyStorage(msg.storageFeatures)));
1005
+ }
1006
+ case "deviceStartCheck": {
1007
+ accountWorker();
1008
+ return (0, import_ping_wasm.deviceStartCheck)(
1009
+ makeProxyStorage(msg.storageFeatures),
1010
+ msg.expectedDeviceId ?? null
1011
+ );
1012
+ }
991
1013
  case "pendingStatus": {
992
1014
  const store = pendingStore();
993
1015
  return (0, import_ping_wasm.pendingStatus)(
@@ -1140,8 +1162,15 @@ async function dispatchRequest(msg) {
1140
1162
  case "beginAccountSetupInMemory": {
1141
1163
  accountWorker();
1142
1164
  if (setupSession) throw new Error("account refused: setup-session-open");
1143
- setupSession = (0, import_ping_wasm.beginAccountSetupInMemory)(msg.identityState, msg.nowMs);
1144
- return null;
1165
+ return accountExclusive(async () => {
1166
+ if (setupSession) throw new Error("account refused: setup-session-open");
1167
+ setupSession = await (0, import_ping_wasm.beginAccountSetupInMemoryOn)(
1168
+ makeProxyStorage(msg.storageFeatures),
1169
+ msg.identityState,
1170
+ msg.nowMs
1171
+ );
1172
+ return null;
1173
+ });
1145
1174
  }
1146
1175
  case "setupSessionMakeBackup":
1147
1176
  return openSession().makeBackup(msg.phrase, msg.accountId, msg.hostState, msg.nowMs);