@ping-app/ping-openmls-sdk 0.9.2 → 0.10.1
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 +91 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +52 -5
- package/dist/index.d.ts +52 -5
- package/dist/index.js +90 -8
- package/dist/index.js.map +1 -1
- package/dist/notification-preview.cjs +25 -0
- package/dist/notification-preview.cjs.map +1 -1
- package/dist/notification-preview.d.cts +40 -1
- package/dist/notification-preview.d.ts +40 -1
- package/dist/notification-preview.js +23 -0
- package/dist/notification-preview.js.map +1 -1
- package/dist/worker.cjs +214 -53
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.js +214 -53
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
- package/wasm/package.json +1 -1
- package/wasm/ping_wasm.d.ts +47 -2
- package/wasm/ping_wasm.js +102 -23
- package/wasm/ping_wasm_bg.wasm +0 -0
- package/wasm/ping_wasm_bg.wasm.d.ts +4 -2
package/dist/index.cjs
CHANGED
|
@@ -39,6 +39,7 @@ __export(src_exports, {
|
|
|
39
39
|
HPKE_PQ_ENC_BYTES: () => HPKE_PQ_ENC_BYTES,
|
|
40
40
|
HPKE_PQ_PUBLIC_KEY_BYTES: () => HPKE_PQ_PUBLIC_KEY_BYTES,
|
|
41
41
|
IndexedDbStorage: () => IndexedDbStorage,
|
|
42
|
+
MAX_PREVIEW_PREREQUISITES: () => MAX_PREVIEW_PREREQUISITES,
|
|
42
43
|
MessagingClient: () => MessagingClient,
|
|
43
44
|
MessagingClientClosedError: () => MessagingClientClosedError,
|
|
44
45
|
NOT_PERMITTED_PREFIX: () => NOT_PERMITTED_PREFIX,
|
|
@@ -674,6 +675,7 @@ function reserveLinearMemory(memory) {
|
|
|
674
675
|
}
|
|
675
676
|
|
|
676
677
|
// src/notification-preview.ts
|
|
678
|
+
var MAX_PREVIEW_PREREQUISITES = 64;
|
|
677
679
|
async function openNotificationPreview(opts) {
|
|
678
680
|
const now = opts.now ?? (() => Date.now());
|
|
679
681
|
const scoped = opts.accountNamespace !== void 0 && opts.accountNamespace.length > 0 ? scopeStorage(opts.storage, opts.accountNamespace) : opts.storage;
|
|
@@ -698,6 +700,16 @@ async function openNotificationPreview(opts) {
|
|
|
698
700
|
const result = client.previewEnvelope(envelope, now());
|
|
699
701
|
return result ?? null;
|
|
700
702
|
},
|
|
703
|
+
async previewEnvelopeWithPrerequisites(prerequisites, envelope) {
|
|
704
|
+
if (closed) throw new Error("notification-preview session is closed");
|
|
705
|
+
assertPrerequisiteCount(prerequisites);
|
|
706
|
+
const result = client.previewEnvelopeWithPrerequisites(
|
|
707
|
+
prerequisites,
|
|
708
|
+
envelope,
|
|
709
|
+
now()
|
|
710
|
+
);
|
|
711
|
+
return result ?? null;
|
|
712
|
+
},
|
|
701
713
|
close() {
|
|
702
714
|
if (closed) return;
|
|
703
715
|
closed = true;
|
|
@@ -705,6 +717,16 @@ async function openNotificationPreview(opts) {
|
|
|
705
717
|
}
|
|
706
718
|
};
|
|
707
719
|
}
|
|
720
|
+
function assertPrerequisiteCount(prerequisites) {
|
|
721
|
+
if (!Array.isArray(prerequisites)) {
|
|
722
|
+
throw new Error("notification-preview prerequisites must be an array");
|
|
723
|
+
}
|
|
724
|
+
if (prerequisites.length > MAX_PREVIEW_PREREQUISITES) {
|
|
725
|
+
throw new Error(
|
|
726
|
+
`notification-preview takes at most ${MAX_PREVIEW_PREREQUISITES} prerequisite envelopes`
|
|
727
|
+
);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
708
730
|
function readOnlyStorage(storage) {
|
|
709
731
|
const refuse = (op) => Promise.reject(
|
|
710
732
|
new Error(`notification-preview storage is read-only (attempted ${op})`)
|
|
@@ -743,6 +765,19 @@ var MessagingClient = class _MessagingClient {
|
|
|
743
765
|
fanout = new MessageFanout();
|
|
744
766
|
conversationHandlers = /* @__PURE__ */ new Set();
|
|
745
767
|
subscription = null;
|
|
768
|
+
/**
|
|
769
|
+
* This client's copy of each conversation's metadata, keyed by lowercase-hex
|
|
770
|
+
* conversation id: what a conversation handle's `name`, `epoch` and `meta()`
|
|
771
|
+
* answer from.
|
|
772
|
+
*
|
|
773
|
+
* It is never older than what the host has been told. The worker attaches a
|
|
774
|
+
* conversation's metadata to every change it reports, and {@link handleWorker}
|
|
775
|
+
* stores it before it calls a listener or settles a call; an entry whose
|
|
776
|
+
* conversation changed with no metadata attached is dropped, never kept.
|
|
777
|
+
* Bounded by the conversations the client holds: an entry goes when its
|
|
778
|
+
* conversation is left, dropped or removed, and `listConversations()`
|
|
779
|
+
* replaces the whole map.
|
|
780
|
+
*/
|
|
746
781
|
metaCache = /* @__PURE__ */ new Map();
|
|
747
782
|
/**
|
|
748
783
|
* Per-conversation batching of sequenced live frames: the first frame goes
|
|
@@ -1530,6 +1565,33 @@ var MessagingClient = class _MessagingClient {
|
|
|
1530
1565
|
for (const m of metas) this.metaCache.set(hex(m.id), m);
|
|
1531
1566
|
return metas;
|
|
1532
1567
|
}
|
|
1568
|
+
/**
|
|
1569
|
+
* ONE conversation's metadata as the group holds it now: the same record as
|
|
1570
|
+
* its element of {@link listConversations}, without listing the others.
|
|
1571
|
+
* Resolves `null` when this client does not hold the conversation (unknown,
|
|
1572
|
+
* dropped, removed, or left). A pure read of local state: nothing is
|
|
1573
|
+
* fetched. Rejects for an id that is not 16 bytes.
|
|
1574
|
+
*
|
|
1575
|
+
* It also brings the conversation handle's `name`, `epoch` and `meta()` to
|
|
1576
|
+
* the answer, though they do not need it to be fresh: the client replaces
|
|
1577
|
+
* its copy of a conversation's metadata
|
|
1578
|
+
* - before any {@link onConversationUpdated} listener is told the
|
|
1579
|
+
* conversation changed (a Commit from another member, a join, a page of
|
|
1580
|
+
* a catch-up), and
|
|
1581
|
+
* - before this device's own call that changed it resolves (a rename, a
|
|
1582
|
+
* roles or membership change, a creation, a leave).
|
|
1583
|
+
* Use this read for a conversation nothing has reported yet in this
|
|
1584
|
+
* session, or to learn that a conversation is no longer held.
|
|
1585
|
+
*/
|
|
1586
|
+
async readConversationMeta(id) {
|
|
1587
|
+
const meta = await this.call({
|
|
1588
|
+
kind: "conversationMeta",
|
|
1589
|
+
id: this.nextId++,
|
|
1590
|
+
conv: id
|
|
1591
|
+
});
|
|
1592
|
+
this.storeMeta(id, meta);
|
|
1593
|
+
return meta ?? null;
|
|
1594
|
+
}
|
|
1533
1595
|
/**
|
|
1534
1596
|
* Conversations detected as STRANDED during catch-up — a Commit was missed
|
|
1535
1597
|
* and the group can no longer advance from local state, so new messages stop
|
|
@@ -2382,12 +2444,14 @@ var MessagingClient = class _MessagingClient {
|
|
|
2382
2444
|
return {
|
|
2383
2445
|
id,
|
|
2384
2446
|
async send(plaintext) {
|
|
2447
|
+
const heldEpoch = self.metaCache.get(hex(id))?.epoch;
|
|
2385
2448
|
return await self.call({
|
|
2386
2449
|
kind: "send",
|
|
2387
2450
|
id: self.nextId++,
|
|
2388
2451
|
conv: id,
|
|
2389
2452
|
plaintext,
|
|
2390
|
-
nowMs: self.now()
|
|
2453
|
+
nowMs: self.now(),
|
|
2454
|
+
...heldEpoch !== void 0 ? { heldEpoch } : {}
|
|
2391
2455
|
});
|
|
2392
2456
|
},
|
|
2393
2457
|
async addMembers(entries) {
|
|
@@ -2465,8 +2529,8 @@ var MessagingClient = class _MessagingClient {
|
|
|
2465
2529
|
});
|
|
2466
2530
|
},
|
|
2467
2531
|
/**
|
|
2468
|
-
* The conversation's MLS GroupContext name
|
|
2469
|
-
*
|
|
2532
|
+
* The conversation's MLS GroupContext name as the group holds it now, or
|
|
2533
|
+
* `undefined` when it has none or the client holds no metadata for it.
|
|
2470
2534
|
*
|
|
2471
2535
|
* This accessor did not exist, and hosts reasonably assumed it did:
|
|
2472
2536
|
* `getConversation(id).name` read `undefined` on every call, which
|
|
@@ -2475,24 +2539,36 @@ var MessagingClient = class _MessagingClient {
|
|
|
2475
2539
|
* absent, so a group would materialise unnamed until a best-effort
|
|
2476
2540
|
* broadcast happened to arrive.
|
|
2477
2541
|
*
|
|
2478
|
-
* A getter rather than a snapshot, so it reflects the
|
|
2479
|
-
*
|
|
2542
|
+
* A getter rather than a snapshot, so it reflects the client's copy at
|
|
2543
|
+
* read time. That copy used to be refilled by `listConversations()`
|
|
2544
|
+
* only, and this answered the name from BEFORE a rename until the host
|
|
2545
|
+
* listed again; it is now replaced with every change the worker reports
|
|
2546
|
+
* (see `metaCache`).
|
|
2480
2547
|
*/
|
|
2481
2548
|
get name() {
|
|
2482
2549
|
return self.metaCache.get(hex(id))?.name ?? void 0;
|
|
2483
2550
|
},
|
|
2484
|
-
/** The conversation's current MLS epoch, or `undefined` when the
|
|
2485
|
-
*
|
|
2551
|
+
/** The conversation's current MLS epoch, or `undefined` when the client
|
|
2552
|
+
* holds no metadata for it. */
|
|
2486
2553
|
get epoch() {
|
|
2487
2554
|
return self.metaCache.get(hex(id))?.epoch;
|
|
2488
2555
|
},
|
|
2489
2556
|
meta() {
|
|
2490
2557
|
const cached = self.metaCache.get(hex(id));
|
|
2491
|
-
if (!cached)
|
|
2558
|
+
if (!cached) {
|
|
2559
|
+
throw new Error("conversation meta not loaded; call readConversationMeta(id) or listConversations() first");
|
|
2560
|
+
}
|
|
2492
2561
|
return cached;
|
|
2493
2562
|
}
|
|
2494
2563
|
};
|
|
2495
2564
|
}
|
|
2565
|
+
/** Replace this client's copy of one conversation's metadata with what the
|
|
2566
|
+
* worker read; no metadata means the copy is dropped, so the handle answers
|
|
2567
|
+
* "not held" instead of what the group held before. */
|
|
2568
|
+
storeMeta(id, meta) {
|
|
2569
|
+
if (meta === null || meta === void 0) this.metaCache.delete(hex(id));
|
|
2570
|
+
else this.metaCache.set(hex(id), meta);
|
|
2571
|
+
}
|
|
2496
2572
|
call(req) {
|
|
2497
2573
|
if (this.closed) return Promise.reject(new MessagingClientClosedError("closed"));
|
|
2498
2574
|
return new Promise((resolve, reject) => {
|
|
@@ -2546,6 +2622,7 @@ var MessagingClient = class _MessagingClient {
|
|
|
2546
2622
|
return;
|
|
2547
2623
|
}
|
|
2548
2624
|
case "event.conversation": {
|
|
2625
|
+
this.storeMeta(msg.id, msg.meta);
|
|
2549
2626
|
for (const h of this.conversationHandlers) {
|
|
2550
2627
|
try {
|
|
2551
2628
|
h(msg.id, msg.epoch, msg.sender);
|
|
@@ -2557,6 +2634,11 @@ var MessagingClient = class _MessagingClient {
|
|
|
2557
2634
|
}
|
|
2558
2635
|
return;
|
|
2559
2636
|
}
|
|
2637
|
+
case "cache.conversations": {
|
|
2638
|
+
for (const meta of msg.held) this.storeMeta(meta.id, meta);
|
|
2639
|
+
for (const id of msg.dropped) this.storeMeta(id, null);
|
|
2640
|
+
return;
|
|
2641
|
+
}
|
|
2560
2642
|
case "storage.call": {
|
|
2561
2643
|
try {
|
|
2562
2644
|
const method = this.storage[msg.method];
|
|
@@ -2697,6 +2779,7 @@ function sameBytesU8(a, b) {
|
|
|
2697
2779
|
HPKE_PQ_ENC_BYTES,
|
|
2698
2780
|
HPKE_PQ_PUBLIC_KEY_BYTES,
|
|
2699
2781
|
IndexedDbStorage,
|
|
2782
|
+
MAX_PREVIEW_PREREQUISITES,
|
|
2700
2783
|
MessagingClient,
|
|
2701
2784
|
MessagingClientClosedError,
|
|
2702
2785
|
NOT_PERMITTED_PREFIX,
|