@ping-app/ping-openmls-sdk 0.10.1 → 0.10.3

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
@@ -52,6 +52,7 @@ __export(src_exports, {
52
52
  ValidationError: () => ValidationError,
53
53
  WIRE_VERSION_MIN_ACCEPTED: () => WIRE_VERSION_MIN_ACCEPTED,
54
54
  WebSocketTransport: () => WebSocketTransport,
55
+ backupPhraseCheckFromWire: () => backupPhraseCheckFromWire,
55
56
  describeTransportError: () => describeTransportError,
56
57
  emulateSendBatch: () => emulateSendBatch,
57
58
  isNotPermittedError: () => isNotPermittedError,
@@ -2137,6 +2138,40 @@ var MessagingClient = class _MessagingClient {
2137
2138
  mnemonicPhrase
2138
2139
  });
2139
2140
  }
2141
+ /**
2142
+ * Whether `mnemonicPhrase` opens `blob` (a recovery backup as the server returned
2143
+ * it), with THREE answers to switch on:
2144
+ *
2145
+ * - `{ outcome: "opens" }`;
2146
+ * - `{ outcome: "authenticationFailed" }`: PROOF. The backup's own authentication
2147
+ * check failed under the key derived from the phrase, so the phrase does not open
2148
+ * these exact bytes (wrong words, or bytes that are not what the words sealed: an
2149
+ * AEAD cannot tell a changed or shortened ciphertext from wrong words, so hand in
2150
+ * the complete bytes). The only answer on which to delete a stored phrase;
2151
+ * - `{ outcome: "couldNotCheck", reason }`: DOUBT. A phrase that is not a phrase, a
2152
+ * version or a format this build cannot read, a payload it cannot decode, a
2153
+ * failure inside the SDK. Delete nothing, claim nothing, ask again later.
2154
+ *
2155
+ * `decryptBackup` rejects with one message for the last two alike; it is unchanged.
2156
+ * This call NEVER rejects: a wasm trap, an out-of-memory failure and a one-shot
2157
+ * worker that could not be created or did not answer are `couldNotCheck` with
2158
+ * `reason: "internal"`. It resolves nothing of the backup: the decrypted identity
2159
+ * is wiped inside the SDK. One Argon2id derivation, on a one-shot worker.
2160
+ */
2161
+ static async checkBackupPhrase(blob, mnemonicPhrase) {
2162
+ try {
2163
+ return backupPhraseCheckFromWire(
2164
+ await _MessagingClient.ephemeralWorkerCall({
2165
+ kind: "checkBackupPhrase",
2166
+ id: 1,
2167
+ blob,
2168
+ mnemonicPhrase
2169
+ })
2170
+ );
2171
+ } catch {
2172
+ return { outcome: "couldNotCheck", reason: "internal" };
2173
+ }
2174
+ }
2140
2175
  // ------------------------ Peer-assisted history transfer ------------------------
2141
2176
  // Authenticated (sign-then-encrypt) device-to-device history used by linking and
2142
2177
  // post-recovery peer re-add. Confidential to the recipient's ephemeral X25519 key AND
@@ -2389,6 +2424,34 @@ var MessagingClient = class _MessagingClient {
2389
2424
  length
2390
2425
  });
2391
2426
  }
2427
+ /**
2428
+ * {@link exportConversationSecret} together with the MLS epoch the secret was
2429
+ * exported at, from one read under one lock inside the core: the pair can
2430
+ * never disagree across a Commit.
2431
+ *
2432
+ * A host that files a key under an epoch number (a call's media key ring)
2433
+ * takes BOTH from this call. A conversation handle's `epoch` is this thread's
2434
+ * copy and any other read is a second request, so either may be a Commit away
2435
+ * from the secret.
2436
+ *
2437
+ * Same derivation, same arguments and the same refusals as
2438
+ * {@link exportConversationSecret}: at one epoch both answer the same bytes.
2439
+ * `secret` is a secret: never log it, persist it only encrypted, and call
2440
+ * `secret.fill(0)` after use. `epoch` is a plain number and may be logged.
2441
+ */
2442
+ async exportConversationSecretWithEpoch(conv, label, context, length) {
2443
+ if (length <= 0 || length > 1024) {
2444
+ throw new Error("exportConversationSecretWithEpoch: length must be 1..=1024");
2445
+ }
2446
+ return await this.call({
2447
+ kind: "exportConversationSecretWithEpoch",
2448
+ id: this.nextId++,
2449
+ conv,
2450
+ label,
2451
+ context,
2452
+ length
2453
+ });
2454
+ }
2392
2455
  /**
2393
2456
  * Subscribe to decrypted application messages, one call per message. A
2394
2457
  * batch or page result (the sequenced paths) is fanned out here per
@@ -2674,6 +2737,20 @@ var MessagingClient = class _MessagingClient {
2674
2737
  }
2675
2738
  }
2676
2739
  };
2740
+ var BACKUP_CHECK_FAILURES = [
2741
+ "invalidPhrase",
2742
+ "unsupportedVersion",
2743
+ "malformed",
2744
+ "undecodable",
2745
+ "internal"
2746
+ ];
2747
+ function backupPhraseCheckFromWire(raw) {
2748
+ const rec = raw !== null && typeof raw === "object" ? raw : {};
2749
+ if (rec.outcome === "opens") return { outcome: "opens" };
2750
+ if (rec.outcome === "authenticationFailed") return { outcome: "authenticationFailed" };
2751
+ const reason = rec.outcome === "couldNotCheck" ? BACKUP_CHECK_FAILURES.find((known) => known === rec.reason) : void 0;
2752
+ return { outcome: "couldNotCheck", reason: reason ?? "internal" };
2753
+ }
2677
2754
  var EphemeralWorkerError = class extends Error {
2678
2755
  reason;
2679
2756
  constructor(reason) {
@@ -2792,6 +2869,7 @@ function sameBytesU8(a, b) {
2792
2869
  ValidationError,
2793
2870
  WIRE_VERSION_MIN_ACCEPTED,
2794
2871
  WebSocketTransport,
2872
+ backupPhraseCheckFromWire,
2795
2873
  describeTransportError,
2796
2874
  emulateSendBatch,
2797
2875
  isNotPermittedError,