@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as Storage, M as MessageEnvelope, I as IncomingMessage } from './types-
|
|
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-
|
|
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 { T as Transport, M as MessageEnvelope, C as ConversationId, U as UserId, D as DiscoveredDevice } from '../types-
|
|
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-
|
|
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
|
@@ -283,11 +283,17 @@ function changedHoldings(before, after) {
|
|
|
283
283
|
}
|
|
284
284
|
|
|
285
285
|
// src/catch-up-pass.ts
|
|
286
|
+
var STORE_MOVED = "store moved: ";
|
|
287
|
+
function isStoreMoved(e) {
|
|
288
|
+
const text = typeof e === "string" ? e : e !== null && typeof e === "object" && typeof e.message === "string" ? e.message : null;
|
|
289
|
+
return text !== null && text.startsWith(STORE_MOVED);
|
|
290
|
+
}
|
|
286
291
|
function catchUpPass(deps) {
|
|
287
292
|
const seen = /* @__PURE__ */ new Set();
|
|
288
293
|
const delivered = [];
|
|
289
294
|
let pending = null;
|
|
290
295
|
let relisted = false;
|
|
296
|
+
let stopped = false;
|
|
291
297
|
const sortedUnseen = (ids) => ids.filter((id) => !seen.has(conversationKey(id))).sort((a, b) => conversationKey(a) < conversationKey(b) ? -1 : 1);
|
|
292
298
|
const initial = async () => {
|
|
293
299
|
const heads = await deps.fetchHeads();
|
|
@@ -298,6 +304,16 @@ function catchUpPass(deps) {
|
|
|
298
304
|
return sortedUnseen(behind);
|
|
299
305
|
};
|
|
300
306
|
return async () => {
|
|
307
|
+
if (stopped) return false;
|
|
308
|
+
if (pending === null) {
|
|
309
|
+
try {
|
|
310
|
+
await deps.door();
|
|
311
|
+
} catch (e) {
|
|
312
|
+
stopped = true;
|
|
313
|
+
deps.finish(false, e);
|
|
314
|
+
return false;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
301
317
|
try {
|
|
302
318
|
if (pending === null) pending = await initial();
|
|
303
319
|
if (pending.length === 0 && !relisted) {
|
|
@@ -310,6 +326,13 @@ function catchUpPass(deps) {
|
|
|
310
326
|
}
|
|
311
327
|
const id = pending[0];
|
|
312
328
|
if (id === void 0) {
|
|
329
|
+
try {
|
|
330
|
+
await deps.door();
|
|
331
|
+
} catch (e) {
|
|
332
|
+
stopped = true;
|
|
333
|
+
deps.finish(false, e);
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
313
336
|
deps.finish(true, delivered);
|
|
314
337
|
return false;
|
|
315
338
|
}
|
|
@@ -319,7 +342,12 @@ function catchUpPass(deps) {
|
|
|
319
342
|
for (const m of page.messages) delivered.push(m);
|
|
320
343
|
deps.onPage(page);
|
|
321
344
|
more = page.has_more;
|
|
322
|
-
} catch {
|
|
345
|
+
} catch (e) {
|
|
346
|
+
if (isStoreMoved(e)) {
|
|
347
|
+
stopped = true;
|
|
348
|
+
deps.finish(false, e);
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
323
351
|
}
|
|
324
352
|
if (!more) {
|
|
325
353
|
seen.add(conversationKey(id));
|
|
@@ -397,6 +425,11 @@ function accountExclusive(run) {
|
|
|
397
425
|
}
|
|
398
426
|
return locks.request(ACCOUNT_LOCK_NAME, run);
|
|
399
427
|
}
|
|
428
|
+
function linkBeginExclusive(run) {
|
|
429
|
+
const locks = globalThis.navigator?.locks;
|
|
430
|
+
if (!locks || typeof locks.request !== "function") return run();
|
|
431
|
+
return locks.request(ACCOUNT_LOCK_NAME, run);
|
|
432
|
+
}
|
|
400
433
|
function pendingStore() {
|
|
401
434
|
accountWorker();
|
|
402
435
|
pendingRootStore ??= new PendingRootStore();
|
|
@@ -782,6 +815,12 @@ function catchUpPassStepper(msg) {
|
|
|
782
815
|
return false;
|
|
783
816
|
}
|
|
784
817
|
pass = catchUpPass({
|
|
818
|
+
// The client's door (ruling V1993): a guarded call that does nothing
|
|
819
|
+
// on a live client (no id, so no row and no checkpoint) and rejects
|
|
820
|
+
// with the typed stop on a client that failed closed.
|
|
821
|
+
door: async () => {
|
|
822
|
+
await ensureClient().confirmApplied([]);
|
|
823
|
+
},
|
|
785
824
|
listConversationIds: () => ensureClient().listConversations().map((meta) => meta.id),
|
|
786
825
|
fetchHeads: async () => transportFeatures.fetchLogHeads ? await fetchLogHeadsProxy() ?? null : null,
|
|
787
826
|
conversationsBehind: (heads) => ensureClient().conversationsBehind(heads),
|
|
@@ -872,12 +911,13 @@ async function dispatchRequest(msg) {
|
|
|
872
911
|
case "beginDeviceLink": {
|
|
873
912
|
clientWorker();
|
|
874
913
|
transportFeatures = msg.transportFeatures ?? { fetchLogSince: false, fetchLogHeads: false };
|
|
875
|
-
const
|
|
914
|
+
const linkTransport = makeProxyTransport(transportFeatures);
|
|
915
|
+
const begun = await linkBeginExclusive(() => (0, import_ping_wasm.beginDeviceLink)(
|
|
876
916
|
msg.deviceLabel,
|
|
877
917
|
makeProxyStorage(msg.storageFeatures),
|
|
878
|
-
|
|
918
|
+
linkTransport,
|
|
879
919
|
msg.nowMs
|
|
880
|
-
);
|
|
920
|
+
));
|
|
881
921
|
try {
|
|
882
922
|
client = begun.takeClient();
|
|
883
923
|
client.onMessage((m) => {
|
|
@@ -988,6 +1028,22 @@ async function dispatchRequest(msg) {
|
|
|
988
1028
|
);
|
|
989
1029
|
});
|
|
990
1030
|
}
|
|
1031
|
+
// The prepared device key: the two calls that write hold the origin's
|
|
1032
|
+
// account lock (two tabs that prepare at once answer ONE key); a realm
|
|
1033
|
+
// with no Web Locks is refused, typed. The predicate reads only.
|
|
1034
|
+
case "prepareDeviceKey": {
|
|
1035
|
+
return accountExclusive(() => (0, import_ping_wasm.prepareDeviceKey)(makeProxyStorage(msg.storageFeatures), msg.nowMs));
|
|
1036
|
+
}
|
|
1037
|
+
case "discardPreparedDeviceKey": {
|
|
1038
|
+
return accountExclusive(() => (0, import_ping_wasm.discardPreparedDeviceKey)(makeProxyStorage(msg.storageFeatures)));
|
|
1039
|
+
}
|
|
1040
|
+
case "deviceStartCheck": {
|
|
1041
|
+
accountWorker();
|
|
1042
|
+
return (0, import_ping_wasm.deviceStartCheck)(
|
|
1043
|
+
makeProxyStorage(msg.storageFeatures),
|
|
1044
|
+
msg.expectedDeviceId ?? null
|
|
1045
|
+
);
|
|
1046
|
+
}
|
|
991
1047
|
case "pendingStatus": {
|
|
992
1048
|
const store = pendingStore();
|
|
993
1049
|
return (0, import_ping_wasm.pendingStatus)(
|
|
@@ -1032,6 +1088,16 @@ async function dispatchRequest(msg) {
|
|
|
1032
1088
|
return null;
|
|
1033
1089
|
});
|
|
1034
1090
|
}
|
|
1091
|
+
case "discardPendingRoot": {
|
|
1092
|
+
return accountExclusive(async () => {
|
|
1093
|
+
const store = pendingStore();
|
|
1094
|
+
return (0, import_ping_wasm.discardPendingRoot)(
|
|
1095
|
+
makeProxyStorage(msg.storageFeatures),
|
|
1096
|
+
store,
|
|
1097
|
+
msg.slot
|
|
1098
|
+
);
|
|
1099
|
+
});
|
|
1100
|
+
}
|
|
1035
1101
|
// The restore as a rotation: the same Worker that never runs a client.
|
|
1036
1102
|
case "openBackupForRestore": {
|
|
1037
1103
|
accountWorker();
|
|
@@ -1140,8 +1206,15 @@ async function dispatchRequest(msg) {
|
|
|
1140
1206
|
case "beginAccountSetupInMemory": {
|
|
1141
1207
|
accountWorker();
|
|
1142
1208
|
if (setupSession) throw new Error("account refused: setup-session-open");
|
|
1143
|
-
|
|
1144
|
-
|
|
1209
|
+
return accountExclusive(async () => {
|
|
1210
|
+
if (setupSession) throw new Error("account refused: setup-session-open");
|
|
1211
|
+
setupSession = await (0, import_ping_wasm.beginAccountSetupInMemoryOn)(
|
|
1212
|
+
makeProxyStorage(msg.storageFeatures),
|
|
1213
|
+
msg.identityState,
|
|
1214
|
+
msg.nowMs
|
|
1215
|
+
);
|
|
1216
|
+
return null;
|
|
1217
|
+
});
|
|
1145
1218
|
}
|
|
1146
1219
|
case "setupSessionMakeBackup":
|
|
1147
1220
|
return openSession().makeBackup(msg.phrase, msg.accountId, msg.hostState, msg.nowMs);
|