@ping-app/ping-openmls-sdk 0.10.0 → 0.10.2

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 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})`)
@@ -2367,6 +2389,34 @@ var MessagingClient = class _MessagingClient {
2367
2389
  length
2368
2390
  });
2369
2391
  }
2392
+ /**
2393
+ * {@link exportConversationSecret} together with the MLS epoch the secret was
2394
+ * exported at, from one read under one lock inside the core: the pair can
2395
+ * never disagree across a Commit.
2396
+ *
2397
+ * A host that files a key under an epoch number (a call's media key ring)
2398
+ * takes BOTH from this call. A conversation handle's `epoch` is this thread's
2399
+ * copy and any other read is a second request, so either may be a Commit away
2400
+ * from the secret.
2401
+ *
2402
+ * Same derivation, same arguments and the same refusals as
2403
+ * {@link exportConversationSecret}: at one epoch both answer the same bytes.
2404
+ * `secret` is a secret: never log it, persist it only encrypted, and call
2405
+ * `secret.fill(0)` after use. `epoch` is a plain number and may be logged.
2406
+ */
2407
+ async exportConversationSecretWithEpoch(conv, label, context, length) {
2408
+ if (length <= 0 || length > 1024) {
2409
+ throw new Error("exportConversationSecretWithEpoch: length must be 1..=1024");
2410
+ }
2411
+ return await this.call({
2412
+ kind: "exportConversationSecretWithEpoch",
2413
+ id: this.nextId++,
2414
+ conv,
2415
+ label,
2416
+ context,
2417
+ length
2418
+ });
2419
+ }
2370
2420
  /**
2371
2421
  * Subscribe to decrypted application messages, one call per message. A
2372
2422
  * batch or page result (the sequenced paths) is fanned out here per
@@ -2757,6 +2807,7 @@ function sameBytesU8(a, b) {
2757
2807
  HPKE_PQ_ENC_BYTES,
2758
2808
  HPKE_PQ_PUBLIC_KEY_BYTES,
2759
2809
  IndexedDbStorage,
2810
+ MAX_PREVIEW_PREREQUISITES,
2760
2811
  MessagingClient,
2761
2812
  MessagingClientClosedError,
2762
2813
  NOT_PERMITTED_PREFIX,