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

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
@@ -30,15 +30,29 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
+ AccountSetup: () => AccountSetup,
34
+ AccountSetupClosedError: () => AccountSetupClosedError,
33
35
  BATCH_PARTIAL_PREFIX: () => BATCH_PARTIAL_PREFIX,
34
36
  CONTENT_TYPE_CBOR: () => CONTENT_TYPE_CBOR,
35
37
  CONTENT_TYPE_CBOR_LEGACY_V1: () => CONTENT_TYPE_CBOR_LEGACY_V1,
36
38
  CONTENT_TYPE_JSON: () => CONTENT_TYPE_JSON,
37
39
  CONTENT_TYPE_JSON_LEGACY_V1: () => CONTENT_TYPE_JSON_LEGACY_V1,
40
+ DEVICE_GROUP_BEHIND_PREFIX: () => DEVICE_GROUP_BEHIND_PREFIX,
41
+ DeviceGroupBehindError: () => DeviceGroupBehindError,
38
42
  EphemeralWorkerError: () => EphemeralWorkerError,
43
+ HISTORY_REFUSED_PREFIX: () => HISTORY_REFUSED_PREFIX,
39
44
  HPKE_PQ_ENC_BYTES: () => HPKE_PQ_ENC_BYTES,
40
45
  HPKE_PQ_PUBLIC_KEY_BYTES: () => HPKE_PQ_PUBLIC_KEY_BYTES,
46
+ HistoryRefusedError: () => HistoryRefusedError,
41
47
  IndexedDbStorage: () => IndexedDbStorage,
48
+ JOURNAL_FULL_PREFIX: () => JOURNAL_FULL_PREFIX,
49
+ JournalFullError: () => JournalFullError,
50
+ LINK_ADD_REFUSED_PREFIX: () => LINK_ADD_REFUSED_PREFIX,
51
+ LINK_CHAIN_TOO_DEEP_PREFIX: () => LINK_CHAIN_TOO_DEEP_PREFIX,
52
+ LINK_COMMITMENT_MISMATCH_PREFIX: () => LINK_COMMITMENT_MISMATCH_PREFIX,
53
+ LinkAddRefusedError: () => LinkAddRefusedError,
54
+ LinkChainTooDeepError: () => LinkChainTooDeepError,
55
+ LinkCommitmentMismatchError: () => LinkCommitmentMismatchError,
42
56
  MAX_PREVIEW_PREREQUISITES: () => MAX_PREVIEW_PREREQUISITES,
43
57
  MessagingClient: () => MessagingClient,
44
58
  MessagingClientClosedError: () => MessagingClientClosedError,
@@ -47,16 +61,38 @@ __export(src_exports, {
47
61
  PING_WIRE_CONTRACT_HEADER: () => PING_WIRE_CONTRACT_HEADER,
48
62
  PING_WIRE_CONTRACT_HEADER_VALUE: () => PING_WIRE_CONTRACT_HEADER_VALUE,
49
63
  PING_WIRE_CONTRACT_VERSION: () => PING_WIRE_CONTRACT_VERSION,
64
+ READ_ONLY_PREFIX: () => READ_ONLY_PREFIX,
65
+ ReadOnlyError: () => ReadOnlyError,
50
66
  SENDER_MISMATCH_PREFIX: () => SENDER_MISMATCH_PREFIX,
67
+ STALE_GENERATION_PREFIX: () => STALE_GENERATION_PREFIX,
68
+ STORE_MOVED_PREFIX: () => STORE_MOVED_PREFIX,
51
69
  SenderMismatchError: () => SenderMismatchError,
70
+ StaleGenerationError: () => StaleGenerationError,
71
+ StoreMovedError: () => StoreMovedError,
52
72
  ValidationError: () => ValidationError,
73
+ WELCOME_MISLABELED_PREFIX: () => WELCOME_MISLABELED_PREFIX,
74
+ WELCOME_WAITS_PREFIX: () => WELCOME_WAITS_PREFIX,
53
75
  WIRE_VERSION_MIN_ACCEPTED: () => WIRE_VERSION_MIN_ACCEPTED,
54
76
  WebSocketTransport: () => WebSocketTransport,
77
+ WelcomeMislabeledError: () => WelcomeMislabeledError,
78
+ WelcomeWaitsError: () => WelcomeWaitsError,
79
+ accountRefusalCode: () => accountRefusalCode,
55
80
  backupPhraseCheckFromWire: () => backupPhraseCheckFromWire,
56
81
  describeTransportError: () => describeTransportError,
57
82
  emulateSendBatch: () => emulateSendBatch,
83
+ isDeviceGroupBehindError: () => isDeviceGroupBehindError,
84
+ isHistoryRefusedError: () => isHistoryRefusedError,
85
+ isJournalFullError: () => isJournalFullError,
86
+ isLinkAddRefusedError: () => isLinkAddRefusedError,
87
+ isLinkChainTooDeepError: () => isLinkChainTooDeepError,
88
+ isLinkCommitmentMismatchError: () => isLinkCommitmentMismatchError,
58
89
  isNotPermittedError: () => isNotPermittedError,
90
+ isReadOnlyError: () => isReadOnlyError,
59
91
  isSenderMismatchError: () => isSenderMismatchError,
92
+ isStaleGenerationError: () => isStaleGenerationError,
93
+ isStoreMovedError: () => isStoreMovedError,
94
+ isWelcomeMislabeledError: () => isWelcomeMislabeledError,
95
+ isWelcomeWaitsError: () => isWelcomeWaitsError,
60
96
  negotiates: () => negotiates,
61
97
  notPermittedRule: () => notPermittedRule,
62
98
  openNotificationPreview: () => openNotificationPreview,
@@ -269,7 +305,8 @@ function logHeadToWire(h) {
269
305
  return {
270
306
  conversation_id: h.conversationId,
271
307
  head_server_seq: h.headServerSeq,
272
- head_epoch: h.headEpoch
308
+ head_epoch: h.headEpoch,
309
+ ...h.sealedGroupInfoWanted === true ? { sealed_group_info_wanted: true } : {}
273
310
  };
274
311
  }
275
312
  function logGapFromWire(g) {
@@ -315,13 +352,45 @@ function bufferOverflowFromWire(o) {
315
352
  dropped: o.dropped
316
353
  };
317
354
  }
355
+ function selfAdmissionFromWire(a) {
356
+ return {
357
+ conversationId: a.conversation_id,
358
+ identity: a.identity,
359
+ deviceId: a.device_id,
360
+ replacedOwnLeaf: a.replaced_own_leaf,
361
+ ownAccount: a.own_account,
362
+ epoch: a.epoch
363
+ };
364
+ }
365
+ function logHoleFromWire(h) {
366
+ return {
367
+ conversationId: h.conversation_id,
368
+ fromServerSeq: h.from_server_seq,
369
+ toServerSeq: h.to_server_seq,
370
+ reason: variant(h.reason),
371
+ contentHashes: h.content_hashes.map((c) => Uint8Array.from(c)),
372
+ kept: h.kept
373
+ };
374
+ }
375
+ function logAckFromWire(a) {
376
+ return { conversationId: a.conversation_id, serverSeq: a.server_seq };
377
+ }
378
+ function journalFullAtFromWire(j) {
379
+ return { conversationId: j.conversation_id, serverSeq: j.server_seq, rows: j.rows };
380
+ }
318
381
  function outcomesFromWire(r) {
319
382
  return {
320
383
  removed: (r.removed ?? []).map(conversationRemovalFromWire),
321
384
  welcomeFailures: (r.welcome_failures ?? []).map(welcomeFailureFromWire),
322
385
  stranded: (r.stranded ?? []).map(strandedConversationFromWire),
323
386
  proposalsPending: r.proposals_pending ?? [],
324
- overflow: (r.overflow ?? []).map(bufferOverflowFromWire)
387
+ overflow: (r.overflow ?? []).map(bufferOverflowFromWire),
388
+ selfAdmissions: (r.self_admissions ?? []).map(selfAdmissionFromWire),
389
+ // Absent from an older wasm: nothing recorded, nothing safe to acknowledge.
390
+ holes: (r.holes ?? []).map(logHoleFromWire),
391
+ acks: (r.acks ?? []).map(logAckFromWire),
392
+ // Absent from an older wasm, which never stopped for the journal.
393
+ journalFull: (r.journal_full ?? []).map(journalFullAtFromWire)
325
394
  };
326
395
  }
327
396
  function applyBatchResultFromWire(r) {
@@ -334,7 +403,10 @@ function applyBatchResultFromWire(r) {
334
403
  gaps: r.gaps.map(logGapFromWire),
335
404
  joined: r.joined,
336
405
  updated: r.updated.map(conversationUpdateFromWire),
337
- ...outcomesFromWire(r)
406
+ ...outcomesFromWire(r),
407
+ // Present only when the SDK says it: said once, with the batch at which
408
+ // the anchor record was seen to change.
409
+ ...r.state_backup_owed === true ? { stateBackupOwed: true } : {}
338
410
  };
339
411
  }
340
412
  function syncStepResultFromWire(r) {
@@ -370,6 +442,7 @@ function commitInDoubtFromWire(c) {
370
442
  var DB_NAME = "ping-sdk";
371
443
  var DB_VERSION = 1;
372
444
  var STORE = "kv";
445
+ var DURABLE = { durability: "strict" };
373
446
  function open() {
374
447
  return new Promise((resolve, reject) => {
375
448
  const req = indexedDB.open(DB_NAME, DB_VERSION);
@@ -401,7 +474,7 @@ var IndexedDbStorage = class {
401
474
  async put(namespace, key, value) {
402
475
  const db = await this.dbPromise;
403
476
  return new Promise((resolve, reject) => {
404
- const tx = db.transaction(STORE, "readwrite");
477
+ const tx = db.transaction(STORE, "readwrite", DURABLE);
405
478
  tx.objectStore(STORE).put({ ns: namespace, key, value });
406
479
  tx.oncomplete = () => resolve();
407
480
  tx.onerror = () => reject(tx.error);
@@ -410,7 +483,7 @@ var IndexedDbStorage = class {
410
483
  async del(namespace, key) {
411
484
  const db = await this.dbPromise;
412
485
  return new Promise((resolve, reject) => {
413
- const tx = db.transaction(STORE, "readwrite");
486
+ const tx = db.transaction(STORE, "readwrite", DURABLE);
414
487
  tx.objectStore(STORE).delete([namespace, key]);
415
488
  tx.oncomplete = () => resolve();
416
489
  tx.onerror = () => reject(tx.error);
@@ -426,7 +499,7 @@ var IndexedDbStorage = class {
426
499
  if (puts.length === 0 && deletes.length === 0) return;
427
500
  const db = await this.dbPromise;
428
501
  return new Promise((resolve, reject) => {
429
- const tx = db.transaction(STORE, "readwrite");
502
+ const tx = db.transaction(STORE, "readwrite", DURABLE);
430
503
  let settled = false;
431
504
  const fail = (e) => {
432
505
  if (settled) return;
@@ -659,6 +732,434 @@ function btoaUrl(b) {
659
732
  return btoa(s).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
660
733
  }
661
734
 
735
+ // src/account-setup.ts
736
+ var import_meta = {};
737
+ function phraseBytes(phrase) {
738
+ return new TextEncoder().encode(phrase);
739
+ }
740
+ function rotationAnswerFields(answer) {
741
+ return {
742
+ status: answer.status,
743
+ error: answer.error ?? null,
744
+ generation: answer.generation ?? null,
745
+ statement: answer.statement ?? null
746
+ };
747
+ }
748
+ function accountRefusalCode(error) {
749
+ const text = error instanceof Error ? error.message : String(error);
750
+ const at = text.indexOf("account refused: ");
751
+ return at < 0 ? null : text.slice(at + "account refused: ".length).trim();
752
+ }
753
+ var AccountSetupClosedError = class extends Error {
754
+ constructor() {
755
+ super("AccountSetup is closed");
756
+ this.name = "AccountSetupClosedError";
757
+ }
758
+ };
759
+ var AccountSetup = class _AccountSetup {
760
+ worker;
761
+ storage;
762
+ now;
763
+ pending = /* @__PURE__ */ new Map();
764
+ nextId = 1;
765
+ closed = false;
766
+ constructor(cfg, worker) {
767
+ this.worker = worker;
768
+ this.storage = cfg.accountNamespace !== void 0 && cfg.accountNamespace.length > 0 ? scopeStorage(cfg.storage, cfg.accountNamespace) : cfg.storage;
769
+ this.now = cfg.now ?? (() => Date.now());
770
+ this.worker.onmessage = (ev) => void this.handleWorker(ev.data);
771
+ this.worker.onerror = () => this.fail(new AccountSetupClosedError());
772
+ }
773
+ /** Start the SDK's set-up Worker over the device's own store. */
774
+ static open(cfg) {
775
+ const worker = new Worker(new URL("./worker.js", import_meta.url), { type: "module" });
776
+ return new _AccountSetup(cfg, worker);
777
+ }
778
+ /**
779
+ * Set a NEW account up on this browser after "Not now" (rule R34 b): the
780
+ * pending root first, then the device record. `identityState` is the
781
+ * sign-in body's `identity_state` field as the server sent it; only
782
+ * `"none_pinned"` lets the call run (ruling V102). `persistentStorage` is the
783
+ * browser's answer to `navigator.storage.persist()`, which the host asked
784
+ * for before this call (ruling ID39).
785
+ */
786
+ createAccount(args) {
787
+ return this.call({
788
+ kind: "createAccount",
789
+ id: this.nextId++,
790
+ slot: args.slot,
791
+ identityState: args.identityState,
792
+ persistentStorage: args.persistentStorage,
793
+ nowMs: this.now(),
794
+ storageFeatures: storageFeaturesOf(this.storage)
795
+ });
796
+ }
797
+ /** Whether the slot holds the pending root this device expects (rule R32).
798
+ * No prompt, no read of the seed. */
799
+ pendingStatus(slot) {
800
+ return this.call({
801
+ kind: "pendingStatus",
802
+ id: this.nextId++,
803
+ slot,
804
+ storageFeatures: storageFeaturesOf(this.storage)
805
+ });
806
+ }
807
+ /** The first backup of a PENDING account. `accountId` is the account's
808
+ * 16-byte id at the auth layer. */
809
+ makeBackup(args) {
810
+ return this.call({
811
+ kind: "makeBackup",
812
+ id: this.nextId++,
813
+ slot: args.slot,
814
+ phrase: phraseBytes(args.phrase),
815
+ accountId: args.accountId,
816
+ hostState: args.hostState,
817
+ nowMs: this.now(),
818
+ storageFeatures: storageFeaturesOf(this.storage)
819
+ });
820
+ }
821
+ /** Rule R10 (b): the root part READ BACK from where it was stored opens to
822
+ * this account. Answers the fingerprint `endPending` asks for. */
823
+ async proveBackup(args) {
824
+ const proof = await this.call({
825
+ kind: "proveBackup",
826
+ id: this.nextId++,
827
+ readBackRootPart: args.readBackRootPart,
828
+ phrase: phraseBytes(args.phrase),
829
+ storageFeatures: storageFeaturesOf(this.storage)
830
+ });
831
+ return proof.fingerprint;
832
+ }
833
+ /** End PENDING: delete the pending item, only against the proof on record. */
834
+ async endPending(args) {
835
+ await this.call({
836
+ kind: "endPending",
837
+ id: this.nextId++,
838
+ slot: args.slot,
839
+ fingerprint: args.fingerprint,
840
+ storageFeatures: storageFeaturesOf(this.storage)
841
+ });
842
+ }
843
+ // ---- The restore as a rotation (the account identity contract, sections
844
+ // 3.9, 3.13, 13.1). None of these needs a client or a session: the backup
845
+ // is opened and the whole `rotation` object is built before the device
846
+ // exists at the server. No call takes or returns a root. ----
847
+ /** Step 3 of a restore: the root part opens with the phrase to the PINNED
848
+ * root; `hostState` is there when the root part's secret opens the state
849
+ * part. Writes nothing. */
850
+ openBackupForRestore(args) {
851
+ return this.call({
852
+ kind: "openBackupForRestore",
853
+ id: this.nextId++,
854
+ rootPart: args.rootPart,
855
+ phrase: phraseBytes(args.phrase),
856
+ statePart: args.statePart,
857
+ pinnedRootPublicKey: args.pinnedRootPublicKey
858
+ });
859
+ }
860
+ /**
861
+ * M1, take the account over: the next generation (the pinned one plus one,
862
+ * or a refusal), a NEW device key, the new generation secret, the device's
863
+ * credential, the statement, its wrap, the new backup parts, and the
864
+ * rotation record. `oldStatePart` gives its anchors only; `hostState` is
865
+ * the NEW host state with the NEW sign-in key companion. Called again with
866
+ * the same rotation id it answers the same request and the same device key.
867
+ */
868
+ restoreTakeOver(args) {
869
+ return this.call({
870
+ kind: "restoreTakeOver",
871
+ id: this.nextId++,
872
+ rootPart: args.rootPart,
873
+ phrase: phraseBytes(args.phrase),
874
+ start: args.start,
875
+ oldStatePart: args.oldStatePart,
876
+ accountId: args.accountId,
877
+ hostState: args.hostState,
878
+ nowMs: this.now(),
879
+ storageFeatures: storageFeaturesOf(this.storage)
880
+ });
881
+ }
882
+ /** "Take your account back": the take-over with the pending root of the
883
+ * slot. The pending item is read, never written and never deleted.
884
+ * `oldStatePart` is the account's state part as the escrow served it
885
+ * (it gives its anchors only); `undefined` only when none was served.
886
+ * ON AN EMPTY STORE EVERY JOIN IS UNCHECKED: never empty the SDK's
887
+ * store on the service's word while the slot holds a pending item
888
+ * (ruling V538). */
889
+ takeAccountBack(args) {
890
+ return this.call({
891
+ kind: "takeAccountBack",
892
+ id: this.nextId++,
893
+ slot: args.slot,
894
+ start: args.start,
895
+ oldStatePart: args.oldStatePart,
896
+ accountId: args.accountId,
897
+ hostState: args.hostState,
898
+ nowMs: this.now(),
899
+ storageFeatures: storageFeaturesOf(this.storage)
900
+ });
901
+ }
902
+ /** At every start: the rotation this device built and has not finished, or
903
+ * `null`. While its phase is `"built"` the host sends the identical
904
+ * request again. */
905
+ resumeRotation() {
906
+ return this.call({
907
+ kind: "resumeRotation",
908
+ id: this.nextId++,
909
+ storageFeatures: storageFeaturesOf(this.storage)
910
+ });
911
+ }
912
+ /** `resumeRotation` WITH THE HOST'S CLOCK (ruling V461; `nowMs`, by default
913
+ * this client's own): the call an app makes at every start. A take-over
914
+ * the server never answered loses the sealing seed it kept once 30 days
915
+ * have passed since its record was made; the record itself stays. */
916
+ resumeRotationAt(nowMs = this.now()) {
917
+ return this.call({
918
+ kind: "resumeRotation",
919
+ id: this.nextId++,
920
+ nowMs,
921
+ storageFeatures: storageFeaturesOf(this.storage)
922
+ });
923
+ }
924
+ /** The server's answer to the request of record `recordId`, AS RECEIVED
925
+ * and judged inside the SDK (ruling V161): the device adopts, or discards
926
+ * the record only against a DIFFERENT pinned statement the root signed
927
+ * (`"lost"`); a final refusal of the server (`"refused"`, `400
928
+ * rotation_invalid` included) keeps the record until `abandonRotation`; any
929
+ * other answer is `"undecided"` and changes nothing. */
930
+ completeRotation(recordId, answer) {
931
+ return this.call({
932
+ kind: "completeRotation",
933
+ id: this.nextId++,
934
+ recordId,
935
+ answer: rotationAnswerFields(answer),
936
+ storageFeatures: storageFeaturesOf(this.storage)
937
+ });
938
+ }
939
+ /** Move an adopted rotation forward. */
940
+ async setRotationPhase(recordId, phase) {
941
+ await this.call({
942
+ kind: "setRotationPhase",
943
+ id: this.nextId++,
944
+ recordId,
945
+ phase,
946
+ storageFeatures: storageFeaturesOf(this.storage)
947
+ });
948
+ }
949
+ /** Step 6: delete the record of an adopted rotation. */
950
+ async finishRotation(recordId) {
951
+ await this.call({
952
+ kind: "finishRotation",
953
+ id: this.nextId++,
954
+ recordId,
955
+ storageFeatures: storageFeaturesOf(this.storage)
956
+ });
957
+ }
958
+ /** Ruling V212: ABANDON a rotation that was never adopted. Its record is
959
+ * deleted, so that another rotation can start. THE PERSON'S CHOICE (after
960
+ * `"refused"`, or to supply the phrase after `"root_part_required"`): the
961
+ * SDK never calls it. ONLY a record the server answered with one of
962
+ * those two is deleted (ruling V227): a record the server never answered
963
+ * is refused (`rotation-refused`) and its request is sent again, because
964
+ * the server may have applied it and the record then holds the only copy
965
+ * of the new device's key. An adopted rotation is refused
966
+ * (`rotation-refused`); it ends by `finishRotation`. */
967
+ async abandonRotation(recordId) {
968
+ await this.call({
969
+ kind: "abandonRotation",
970
+ id: this.nextId++,
971
+ recordId,
972
+ storageFeatures: storageFeaturesOf(this.storage)
973
+ });
974
+ }
975
+ /** Ruling V232: whether this store holds a rotation record and whether the
976
+ * server refused it for good, so a screen can offer "start over" after a
977
+ * restart without sending the request once more. One local read: no secret,
978
+ * no id, no request. The refusal it reports is the server's unauthenticated
979
+ * word; this read decides nothing. */
980
+ rotationRecordState() {
981
+ return this.call({
982
+ kind: "rotationRecordState",
983
+ id: this.nextId++,
984
+ storageFeatures: storageFeaturesOf(this.storage)
985
+ });
986
+ }
987
+ /** M2, join beside the devices that stay: no rotation; a depth 0 credential
988
+ * at the pinned generation. `restore-join-not-current`: offer M1 or a link. */
989
+ restoreJoin(args) {
990
+ return this.call({
991
+ kind: "restoreJoin",
992
+ id: this.nextId++,
993
+ rootPart: args.rootPart,
994
+ phrase: phraseBytes(args.phrase),
995
+ statePart: args.statePart,
996
+ start: args.start,
997
+ nowMs: this.now(),
998
+ storageFeatures: storageFeaturesOf(this.storage)
999
+ });
1000
+ }
1001
+ /** Open the account's state part with the generation secret this device
1002
+ * holds, and keep its anchors. No phrase, no root.
1003
+ * It is also the ONE look a linked device owes before it writes a state
1004
+ * part: until this ran once, `refreshStateBackup` and a rotation that keeps
1005
+ * the device's key reject with the code `state-part-look-owed`. Pass an
1006
+ * EMPTY part when the service serves none; whatever this answers, the look
1007
+ * is made. */
1008
+ openStateBackup(statePart) {
1009
+ return this.call({
1010
+ kind: "openStateBackup",
1011
+ id: this.nextId++,
1012
+ statePart,
1013
+ storageFeatures: storageFeaturesOf(this.storage)
1014
+ });
1015
+ }
1016
+ /** Write the account's state part anew under the generation secret this
1017
+ * device holds. */
1018
+ refreshStateBackup(args) {
1019
+ return this.call({
1020
+ kind: "refreshStateBackup",
1021
+ id: this.nextId++,
1022
+ accountId: args.accountId,
1023
+ hostState: args.hostState,
1024
+ nowMs: this.now(),
1025
+ storageFeatures: storageFeaturesOf(this.storage)
1026
+ });
1027
+ }
1028
+ /**
1029
+ * Begin a set-up session whose root is in memory only (rule R34 a): for the
1030
+ * person who makes the backup during set-up. One session per object; it
1031
+ * lives in the Worker until `sessionFinish`, `sessionKeepAsPending` or
1032
+ * `close`.
1033
+ */
1034
+ async beginInMemory(identityState) {
1035
+ await this.call({
1036
+ kind: "beginAccountSetupInMemory",
1037
+ id: this.nextId++,
1038
+ identityState,
1039
+ nowMs: this.now()
1040
+ });
1041
+ }
1042
+ /** The session's backup. */
1043
+ sessionMakeBackup(args) {
1044
+ return this.call({
1045
+ kind: "setupSessionMakeBackup",
1046
+ id: this.nextId++,
1047
+ phrase: phraseBytes(args.phrase),
1048
+ accountId: args.accountId,
1049
+ hostState: args.hostState,
1050
+ nowMs: this.now()
1051
+ });
1052
+ }
1053
+ /** Rule R10 (b) for the session. Answers the fingerprint. */
1054
+ async sessionProveBackup(args) {
1055
+ const proof = await this.call({
1056
+ kind: "setupSessionProveBackup",
1057
+ id: this.nextId++,
1058
+ readBackRootPart: args.readBackRootPart,
1059
+ phrase: phraseBytes(args.phrase)
1060
+ });
1061
+ return proof.fingerprint;
1062
+ }
1063
+ /** End the session after the proof: the device record is written, the root
1064
+ * is wiped. Only then does the host upload KeyPackages. */
1065
+ sessionFinish() {
1066
+ return this.call({
1067
+ kind: "setupSessionFinish",
1068
+ id: this.nextId++,
1069
+ storageFeatures: storageFeaturesOf(this.storage)
1070
+ });
1071
+ }
1072
+ /** "Not now" after the session began (ruling ID42): THIS session's root
1073
+ * becomes the pending item, then the device record is written. */
1074
+ sessionKeepAsPending(args) {
1075
+ return this.call({
1076
+ kind: "setupSessionKeepAsPending",
1077
+ id: this.nextId++,
1078
+ slot: args.slot,
1079
+ persistentStorage: args.persistentStorage,
1080
+ storageFeatures: storageFeaturesOf(this.storage)
1081
+ });
1082
+ }
1083
+ /** Stop the Worker. A session still open there is wiped with it. */
1084
+ close() {
1085
+ if (this.closed) return;
1086
+ this.closed = true;
1087
+ try {
1088
+ this.worker.postMessage({ kind: "endAccountSetupSession", id: this.nextId++ });
1089
+ } catch {
1090
+ }
1091
+ this.worker.onmessage = null;
1092
+ this.worker.onerror = null;
1093
+ this.worker.terminate();
1094
+ this.fail(new AccountSetupClosedError());
1095
+ }
1096
+ fail(error) {
1097
+ const waiting = [...this.pending.values()];
1098
+ this.pending.clear();
1099
+ for (const slot of waiting) slot.reject(error);
1100
+ }
1101
+ /** Post a request. A recovery phrase in it crossed as bytes (ruling
1102
+ * V253): this side's copy is zeroed when the call has answered, whatever
1103
+ * it answered; the Worker zeroes its own. */
1104
+ call(req) {
1105
+ const phrase = req.phrase;
1106
+ const answered = this.post(req);
1107
+ return phrase instanceof Uint8Array ? answered.finally(() => {
1108
+ phrase.fill(0);
1109
+ }) : answered;
1110
+ }
1111
+ post(req) {
1112
+ if (this.closed) return Promise.reject(new AccountSetupClosedError());
1113
+ return new Promise((resolve, reject) => {
1114
+ this.pending.set(req.id, { resolve, reject });
1115
+ try {
1116
+ this.worker.postMessage(req);
1117
+ } catch (e) {
1118
+ this.pending.delete(req.id);
1119
+ reject(e);
1120
+ }
1121
+ });
1122
+ }
1123
+ async handleWorker(msg) {
1124
+ switch (msg.kind) {
1125
+ case "result": {
1126
+ const slot = this.pending.get(msg.id);
1127
+ if (!slot) return;
1128
+ this.pending.delete(msg.id);
1129
+ if (msg.ok) slot.resolve(msg.value);
1130
+ else slot.reject(new Error(msg.error));
1131
+ return;
1132
+ }
1133
+ case "storage.call": {
1134
+ try {
1135
+ const method = this.storage[msg.method];
1136
+ if (typeof method !== "function") {
1137
+ throw new Error(`storage.${String(msg.method)} is not implemented by the host storage`);
1138
+ }
1139
+ const value = await method.apply(this.storage, msg.args);
1140
+ if (!this.closed) this.worker.postMessage({ kind: "storage.reply", id: msg.id, ok: true, value });
1141
+ } catch (e) {
1142
+ if (!this.closed) {
1143
+ this.worker.postMessage({ kind: "storage.reply", id: msg.id, ok: false, error: String(e) });
1144
+ }
1145
+ }
1146
+ return;
1147
+ }
1148
+ case "transport.call": {
1149
+ this.worker.postMessage({
1150
+ kind: "transport.reply",
1151
+ id: msg.id,
1152
+ ok: false,
1153
+ error: "account set-up has no transport"
1154
+ });
1155
+ return;
1156
+ }
1157
+ default:
1158
+ return;
1159
+ }
1160
+ }
1161
+ };
1162
+
662
1163
  // src/wasm-memory.ts
663
1164
  var RESERVE_MIB_TARGETS = [192, 128, 64, 32];
664
1165
  var WASM_PAGE_BYTES = 64 * 1024;
@@ -686,9 +1187,7 @@ async function openNotificationPreview(opts) {
686
1187
  opts.wasmModuleOrPath === void 0 ? void 0 : { module_or_path: opts.wasmModuleOrPath }
687
1188
  );
688
1189
  reserveLinearMemory(out.memory);
689
- const client = await wasm.PingClient.openReadOnly(
690
- opts.identityExport,
691
- // Label is unused on the read-only path (no LocalDevice is ever minted).
1190
+ const client = await wasm.PingClient.openReadOnlyFromDeviceRecord(
692
1191
  "notification-preview",
693
1192
  storage,
694
1193
  silentTransport(),
@@ -754,7 +1253,7 @@ function silentTransport() {
754
1253
  }
755
1254
 
756
1255
  // src/index.ts
757
- var import_meta = {};
1256
+ var import_meta2 = {};
758
1257
  var MessagingClient = class _MessagingClient {
759
1258
  worker;
760
1259
  nextId = 1;
@@ -814,56 +1313,6 @@ var MessagingClient = class _MessagingClient {
814
1313
  this.worker.onmessage = (ev) => this.handleWorker(ev.data);
815
1314
  this.worker.onerror = () => this.failPending(new MessagingClientClosedError("worker-error"));
816
1315
  }
817
- /** Generate a fresh identity. The returned bytes are a secret — store them encrypted. */
818
- static async generateIdentity() {
819
- return _MessagingClient.ephemeralWorkerCall({
820
- kind: "generateIdentity",
821
- id: 1
822
- });
823
- }
824
- /**
825
- * HPKE-seal a `LinkingTicket` for delivery to a new device ([CR-3]).
826
- *
827
- * Returns CBOR-encoded bytes safe to relay through an untrusted inbox. The new device's
828
- * X25519 public key (`newDevicePub`) is exchanged out-of-band — typically as part of a
829
- * QR-encoded handshake on the linking screen. Pure function; runs in an ephemeral
830
- * worker so no live `MessagingClient` is required on the sender side.
831
- *
832
- * Suite: `DHKEM(X25519, HKDF-SHA256), HKDF-SHA256, AES-128-GCM` (matches MLS).
833
- */
834
- static async sealLinkingTicket(ticket, newDevicePub) {
835
- if (newDevicePub.length !== 32) {
836
- throw new Error("sealLinkingTicket: newDevicePub must be 32 bytes");
837
- }
838
- return _MessagingClient.ephemeralWorkerCall({
839
- kind: "sealLinkingTicket",
840
- id: 1,
841
- ticket,
842
- newDevicePub
843
- });
844
- }
845
- /**
846
- * HPKE-open a sealed `LinkingTicket` on the new device ([CR-3]).
847
- *
848
- * The receiving device hasn't booted a `MessagingClient` yet — it only has its X25519
849
- * ephemeral keypair. This static method runs the open in an ephemeral worker, returning
850
- * the cleartext ticket which the host then feeds to `init()` + `consumeLinkingTicket()`.
851
- *
852
- * On failure the error message is deliberately generic (no discriminator between "wrong
853
- * key" vs "tampered ciphertext") so a probing attacker can't tell the new device's key
854
- * was the issue.
855
- */
856
- static async openLinkingTicket(sealed, newDevicePriv) {
857
- if (newDevicePriv.length !== 32) {
858
- throw new Error("openLinkingTicket: newDevicePriv must be 32 bytes");
859
- }
860
- return _MessagingClient.ephemeralWorkerCall({
861
- kind: "openLinkingTicket",
862
- id: 1,
863
- sealed,
864
- newDevicePriv
865
- });
866
- }
867
1316
  /**
868
1317
  * Generic HPKE-Base seal of arbitrary bytes to `recipientPub` (32-byte X25519)
869
1318
  * under a caller-supplied `info`. One shared HPKE implementation so app layers
@@ -963,39 +1412,6 @@ var MessagingClient = class _MessagingClient {
963
1412
  // forms stay for app inboxes created with a 32-byte key before the roll. A
964
1413
  // classical private key and an X-Wing seed are both 32 bytes but are NOT
965
1414
  // interchangeable: the host knows which family a stored key belongs to.
966
- /**
967
- * HPKE-seal a `LinkingTicket` under the new device's X-Wing public key
968
- * ([CR-3], post-quantum). CBOR `{v: 2, enc, ct}` under `ping/link/v2`; the
969
- * classical {@link openLinkingTicket} refuses it and {@link openLinkingTicketPq}
970
- * refuses a `v: 1` blob, so there is no downgrade in either direction.
971
- */
972
- static async sealLinkingTicketPq(ticket, newDevicePub) {
973
- if (newDevicePub.length !== HPKE_PQ_PUBLIC_KEY_BYTES) {
974
- throw new Error(`sealLinkingTicketPq: newDevicePub must be ${HPKE_PQ_PUBLIC_KEY_BYTES} bytes`);
975
- }
976
- return _MessagingClient.ephemeralWorkerCall({
977
- kind: "sealLinkingTicketPq",
978
- id: 1,
979
- ticket,
980
- newDevicePub
981
- });
982
- }
983
- /**
984
- * HPKE-open a sealed `v: 2` ticket with the new device's 32-byte X-Wing seed
985
- * ([CR-3], post-quantum). The error is deliberately generic, like
986
- * {@link openLinkingTicket}.
987
- */
988
- static async openLinkingTicketPq(sealed, newDevicePriv) {
989
- if (newDevicePriv.length !== 32) {
990
- throw new Error("openLinkingTicketPq: newDevicePriv must be 32 bytes");
991
- }
992
- return _MessagingClient.ephemeralWorkerCall({
993
- kind: "openLinkingTicketPq",
994
- id: 1,
995
- sealed,
996
- newDevicePriv
997
- });
998
- }
999
1415
  /** Post-quantum {@link hpkeSeal}: CBOR-wrapped (`v: 2`), `recipientPub` is 1216 bytes. */
1000
1416
  static async hpkeSealPq(plaintext, recipientPub, info) {
1001
1417
  if (recipientPub.length !== HPKE_PQ_PUBLIC_KEY_BYTES) {
@@ -1159,52 +1575,112 @@ var MessagingClient = class _MessagingClient {
1159
1575
  }
1160
1576
  return { deviceId: both.slice(0, 32), signature: both.slice(32) };
1161
1577
  }
1578
+ // ---- The link handshake commitment (2026-11-25) ----
1579
+ //
1580
+ // REMOVED 2026-11-28 (ruling V576): `openLinkingTicket`, `openLinkingTicketPq`,
1581
+ // `sealLinkingTicketFor`, `buildLinkingTicketFor`, `consumeLinkingTicket` and the type
1582
+ // `LinkingTicket`. A ticket of version 1 or 2 carries a binding an ACCOUNT KEY signs;
1583
+ // the only ticket is version 3 (`buildLinkingTicketV3For`, `completeDeviceLink`).
1584
+ // REMOVED 2026-11-25 (ruling ID15): `sealLinkingTicket`, `sealLinkingTicketPq`,
1585
+ // `signDeviceLinkApproval` (a raw key) and `buildLinkingTicket(deviceId,
1586
+ // keyPackage)`. Every call below takes the handshake payload the relay returned
1587
+ // together with what THIS device was shown (`expected`) and verifies inside the
1588
+ // call, so nothing can be approved for, built for or sealed to a handshake that
1589
+ // was not verified. `hpkeSeal*` refuse the infos `ping/link/*` and
1590
+ // `ping/link-auth/*`. Host notes: docs-site/api.md, "Device link commitment".
1591
+ /**
1592
+ * The commitment of a handshake payload: what a NEW device shows for the exact
1593
+ * bytes it publishes ({@link MessagingClient.linkHandshakePayload}). `qrText` is
1594
+ * `{"v":3,"h":"<base64url(commitment)>"}`; `code` is the 20 characters the relay
1595
+ * indexes; `codeDisplay` is the same in five groups of four.
1596
+ */
1597
+ static async linkCommitment(payload) {
1598
+ const parts = await _MessagingClient.ephemeralWorkerCall({
1599
+ kind: "linkCommitment",
1600
+ id: 1,
1601
+ payload
1602
+ });
1603
+ return { commitment: parts[0], qrText: parts[1], code: parts[2], codeDisplay: parts[3] };
1604
+ }
1162
1605
  /**
1163
- * Link verification v2, on the APPROVING device: approve ONE new device on ONE
1164
- * server link session (`POST /v1/auth/link/sessions` returned `approvalSessionId`)
1165
- * with this device's signing key. The new device sends the result with its own
1166
- * {@link signDeviceLinkPossession} proof to `POST /v1/auth/link/verify`.
1167
- *
1168
- * The SDK builds the signed bytes itself (`"ping/device-link-approve/v1" ||
1169
- * approvalSessionId || accountId || approverDeviceId || newDeviceId ||
1170
- * newDevicePubkey || audience`, see docs/DEVICE_LINK_V2_VECTORS.md) and derives
1171
- * both device ids from the keys, so this cannot sign anything else with the device
1172
- * key. `deviceSigningSecretKey` is the 32-byte seed the host holds for THIS device
1173
- * (the one registered as its device signing key); `accountId` (16 bytes) is the
1174
- * account stored with this device's session; `newDevicePubkey` (32 bytes) is the
1175
- * new device's key from its handshake; `audience` is the canonical origin of the API
1176
- * THIS host is configured to reach (`new URL(apiBase).origin`), as for
1177
- * {@link signDeviceReauth}.
1178
- *
1179
- * Rejects wrong widths, a non-canonical audience, a new key that is not a canonical
1180
- * Ed25519 point outside the small-order subgroup, and this device's own key. Runs in
1181
- * an ephemeral worker.
1606
+ * THE normaliser of a typed link code. Hand it what the person typed; send the
1607
+ * relay, and pass to the calls below, only the 20 characters it returns. No host
1608
+ * normalises a code itself. Rejects anything that is not a code.
1609
+ */
1610
+ static async normalizeLinkCode(typed) {
1611
+ return _MessagingClient.ephemeralWorkerCall({ kind: "normalizeLinkCode", id: 1, typed });
1612
+ }
1613
+ /** The 32 bytes of a QR text `{"v":3,"h":"..."}`. Rejects any other shape. */
1614
+ static async linkQrCommitment(qrText) {
1615
+ return _MessagingClient.ephemeralWorkerCall({ kind: "linkQrCommitment", id: 1, qrText });
1616
+ }
1617
+ /**
1618
+ * Verify the handshake payload a relay returned against what this device was
1619
+ * shown. Call it BEFORE anything else is done with the handshake. Rejects with
1620
+ * {@link LinkCommitmentMismatchError} when the payload is not the committed one:
1621
+ * send nothing, open no approval session, ask the person to try again.
1622
+ */
1623
+ static async verifyLinkHandshake(payload, expected) {
1624
+ const all = await _MessagingClient.ephemeralWorkerCall({
1625
+ kind: "verifyLinkHandshake",
1626
+ id: 1,
1627
+ payload,
1628
+ ...linkExpectedFields(expected)
1629
+ });
1630
+ if (all.length !== 97) {
1631
+ throw new Error("verifyLinkHandshake: expected 97 bytes");
1632
+ }
1633
+ return {
1634
+ deviceId: all.slice(0, 32),
1635
+ deviceSigningPubkey: all.slice(32, 64),
1636
+ commitment: all.slice(64, 96),
1637
+ verifiedByQr: all[96] === 1
1638
+ };
1639
+ }
1640
+ /**
1641
+ * HPKE-seal the device-linking auth envelope (`ping/link-auth/v2`) to the
1642
+ * X-Wing key of the handshake `payload`, verified inside the call.
1643
+ */
1644
+ static async sealLinkAuthFor(plaintext, payload, expected) {
1645
+ return _MessagingClient.ephemeralWorkerCall({
1646
+ kind: "sealLinkAuthFor",
1647
+ id: 1,
1648
+ plaintext,
1649
+ payload,
1650
+ ...linkExpectedFields(expected)
1651
+ });
1652
+ }
1653
+ /**
1654
+ * Link verification v2, on the EXISTING device: approve the new device of the
1655
+ * handshake `payload`, verified inside the call, on one server link session with
1656
+ * this device's signing key. The signed bytes are those of
1657
+ * docs/DEVICE_LINK_V2_VECTORS.md; the key that is approved is the handshake's
1658
+ * device signing key and cannot be passed separately. `audience` as for
1659
+ * {@link signDeviceReauth}. Runs in an ephemeral worker.
1182
1660
  */
1183
- static async signDeviceLinkApproval(params) {
1184
- const { deviceSigningSecretKey, approvalSessionId, accountId, newDevicePubkey, audience } = params;
1661
+ static async signDeviceLinkApprovalFor(params) {
1662
+ const { deviceSigningSecretKey, approvalSessionId, accountId, payload, expected, audience } = params;
1185
1663
  if (deviceSigningSecretKey.length !== 32) {
1186
- throw new Error("signDeviceLinkApproval: deviceSigningSecretKey must be 32 bytes");
1664
+ throw new Error("signDeviceLinkApprovalFor: deviceSigningSecretKey must be 32 bytes");
1187
1665
  }
1188
1666
  if (approvalSessionId.length !== 16) {
1189
- throw new Error("signDeviceLinkApproval: approvalSessionId must be 16 bytes");
1667
+ throw new Error("signDeviceLinkApprovalFor: approvalSessionId must be 16 bytes");
1190
1668
  }
1191
1669
  if (accountId.length !== 16) {
1192
- throw new Error("signDeviceLinkApproval: accountId must be 16 bytes");
1193
- }
1194
- if (newDevicePubkey.length !== 32) {
1195
- throw new Error("signDeviceLinkApproval: newDevicePubkey must be 32 bytes");
1670
+ throw new Error("signDeviceLinkApprovalFor: accountId must be 16 bytes");
1196
1671
  }
1197
1672
  const all = await _MessagingClient.ephemeralWorkerCall({
1198
- kind: "signDeviceLinkApproval",
1673
+ kind: "signDeviceLinkApprovalFor",
1199
1674
  id: 1,
1200
1675
  deviceSigningSecretKey,
1201
1676
  approvalSessionId,
1202
1677
  accountId,
1203
- newDevicePubkey,
1678
+ payload,
1679
+ ...linkExpectedFields(expected),
1204
1680
  audience
1205
1681
  });
1206
1682
  if (all.length !== 128) {
1207
- throw new Error("signDeviceLinkApproval: expected 128 bytes");
1683
+ throw new Error("signDeviceLinkApprovalFor: expected 128 bytes");
1208
1684
  }
1209
1685
  return {
1210
1686
  approverDeviceId: all.slice(0, 32),
@@ -1255,12 +1731,12 @@ var MessagingClient = class _MessagingClient {
1255
1731
  // result, on a worker `error` (the script failed to load or import, or threw at top
1256
1732
  // level), on a `messageerror` (a reply that could not be deserialised), and when the
1257
1733
  // worker cannot be created or the request cannot be posted. Only `onmessage` used to be
1258
- // wired, so a worker that failed to load left `generateIdentity()` pending forever and
1734
+ // wired, so a worker that failed to load left a static call pending forever and
1259
1735
  // the worker alive.
1260
1736
  static ephemeralWorkerCall(req) {
1261
1737
  let w;
1262
1738
  try {
1263
- w = new Worker(new URL("./worker.js", import_meta.url), { type: "module" });
1739
+ w = new Worker(new URL("./worker.js", import_meta2.url), { type: "module" });
1264
1740
  } catch {
1265
1741
  return Promise.reject(new EphemeralWorkerError("spawn"));
1266
1742
  }
@@ -1290,30 +1766,99 @@ var MessagingClient = class _MessagingClient {
1290
1766
  }
1291
1767
  });
1292
1768
  }
1293
- static async init(cfg) {
1294
- const worker = new Worker(new URL("./worker.js", import_meta.url), { type: "module" });
1769
+ /**
1770
+ * Start the client FROM THE DEVICE RECORD: the ONE start of a client (after
1771
+ * `AccountSetup`, a link or a restore wrote the record into `cfg.storage`).
1772
+ * The client holds no account key: every leaf and KeyPackage it builds
1773
+ * carries the one credential the device holds (`heldCredential()`). No call
1774
+ * starts a client from an account identity and none hands one out (the
1775
+ * start from an identity export, `generateIdentity` and `exportIdentity`
1776
+ * left every binding on 2026-11-28). Rejects when the
1777
+ * store holds no device record, or when `cfg.deviceSigningSecretKey` is not
1778
+ * the record's own device key.
1779
+ */
1780
+ static async initFromDeviceRecord(cfg) {
1781
+ return (await _MessagingClient.start(cfg, "record")).client;
1782
+ }
1783
+ /**
1784
+ * Begin a link on a NEW device, in one call: the SDK draws the device key
1785
+ * (no field of `cfg` is a key), records "link begun" in `cfg.storage`,
1786
+ * starts the staging client and builds the handshake payload. A repeat
1787
+ * after a reload answers the SAME key and the SAME handshake. Rejects with
1788
+ * `account refused: account-already-set-up` over a store that already holds
1789
+ * a device.
1790
+ */
1791
+ static async beginDeviceLink(cfg) {
1792
+ const { client, answer } = await _MessagingClient.start(cfg, "link");
1793
+ const begun = answer;
1794
+ return { client, ...begun };
1795
+ }
1796
+ /**
1797
+ * HPKE-seal a version 3 ticket to the X-Wing key of the handshake `payload`,
1798
+ * verified inside the call (`ping/link/v2`). Rejects a ticket that was built
1799
+ * for another device than the handshake's.
1800
+ */
1801
+ static async sealLinkingTicketV3For(ticket, payload, expected) {
1802
+ return _MessagingClient.ephemeralWorkerCall({
1803
+ kind: "sealLinkingTicketV3For",
1804
+ id: 1,
1805
+ ticket,
1806
+ payload,
1807
+ ...linkExpectedFields(expected)
1808
+ });
1809
+ }
1810
+ /**
1811
+ * HPKE-open a sealed version 3 ticket with the new device's X-Wing seed.
1812
+ * NOT yet verified: `completeDeviceLink` runs every check.
1813
+ */
1814
+ static async openLinkingTicketV3(sealed, newDevicePriv) {
1815
+ return _MessagingClient.ephemeralWorkerCall({
1816
+ kind: "openLinkingTicketV3",
1817
+ id: 1,
1818
+ sealed,
1819
+ newDevicePriv
1820
+ });
1821
+ }
1822
+ static async start(cfg, mode) {
1823
+ const worker = new Worker(new URL("./worker.js", import_meta2.url), { type: "module" });
1295
1824
  const client = new _MessagingClient(cfg, worker);
1296
1825
  const transportFeatures = {
1297
1826
  fetchLogSince: typeof cfg.transport.fetchLogSince === "function",
1298
- fetchLogHeads: typeof cfg.transport.fetchLogHeads === "function"
1827
+ fetchLogHeads: typeof cfg.transport.fetchLogHeads === "function",
1828
+ sendExternalCommit: typeof cfg.transport.sendExternalCommit === "function",
1829
+ fetchSelfAdmissionStates: typeof cfg.transport.fetchSelfAdmissionStates === "function",
1830
+ fetchSealedGroupInfos: typeof cfg.transport.fetchSealedGroupInfos === "function",
1831
+ sendExternalCommits: typeof cfg.transport.sendExternalCommits === "function",
1832
+ fetchSealingStatements: typeof cfg.transport.fetchSealingStatements === "function",
1833
+ publishSealedGroupInfo: typeof cfg.transport.publishSealedGroupInfo === "function"
1299
1834
  };
1300
1835
  const storageFeatures = storageFeaturesOf(client.storage);
1301
- await client.call({
1302
- kind: "init",
1836
+ const first = {
1303
1837
  id: client.nextId++,
1304
- identityExport: cfg.identityExport,
1305
1838
  deviceLabel: cfg.deviceLabel,
1306
1839
  nowMs: client.now(),
1307
1840
  ...cfg.deviceSigningSecretKey ? { deviceSigningSecretKey: cfg.deviceSigningSecretKey } : {},
1308
1841
  ...cfg.expectedOwners ? { expectedOwners: cfg.expectedOwners } : {},
1842
+ // Handed on as given: the Worker counts only the value `true`.
1843
+ ...cfg.tabClient !== void 0 ? { tabClient: cfg.tabClient } : {},
1309
1844
  transportFeatures,
1310
1845
  storageFeatures
1311
- });
1846
+ };
1847
+ const answer = await client.call(
1848
+ mode === "link" ? {
1849
+ kind: "beginDeviceLink",
1850
+ id: first.id,
1851
+ deviceLabel: first.deviceLabel,
1852
+ nowMs: first.nowMs,
1853
+ transportFeatures,
1854
+ storageFeatures
1855
+ } : { kind: "initFromDeviceRecord", ...first }
1856
+ );
1312
1857
  client.ownDeviceId = await client.deviceId();
1313
1858
  client.subscription = cfg.transport.subscribe(
1314
1859
  (frame) => client.dispatchIncoming(frame)
1315
1860
  );
1316
- return client;
1861
+ return { client, answer };
1317
1862
  }
1318
1863
  /**
1319
1864
  * Internal: route an inbound envelope to the right handler, IN ARRIVAL ORDER
@@ -1437,55 +1982,26 @@ var MessagingClient = class _MessagingClient {
1437
1982
  });
1438
1983
  const result = syncStepResultFromWire(raw);
1439
1984
  this.fanout.deliverBatch(result.messages, { source: "page" });
1440
- return result;
1441
- }
1442
- // ------------------------ Public API ------------------------
1443
- async userId() {
1444
- return await this.call({ kind: "userId", id: this.nextId++ });
1445
- }
1446
- /**
1447
- * Export the account identity seed (CBOR-wrapped Ed25519, **SECRET**).
1448
- * Transfer to a newly-linked device over the sealed linking channel so all of
1449
- * an account's devices share one `userId` — the basis for cross-device
1450
- * self-attribution (`IncomingMessage.sender_user_id === userId()`). Never log
1451
- * or persist in cleartext.
1452
- */
1453
- async exportIdentity() {
1454
- return await this.call({ kind: "exportIdentity", id: this.nextId++ });
1455
- }
1456
- /**
1457
- * RETIRED (2026-11-03): always rejects (`Invalid`) and changes nothing.
1458
- *
1459
- * It moved every conversation's own leaf to a new account identity with a
1460
- * credential-changing Commit, the way out of `409 mls_identity_conflict`.
1461
- * Every Ping client now refuses a Commit that changes a member's leaf
1462
- * credential (a hostile linked device could otherwise move its leaf to a
1463
- * peer's identity and escape the account's removal), so a rotation would
1464
- * strand every conversation it touched. The way out of an identity conflict
1465
- * is to link this device again, or sign out and in. Kept so no caller
1466
- * breaks. See `docs/MULTIDEVICE.md` "Identity rotation".
1467
- *
1468
- * @deprecated Retired: always rejects. Link this device again instead.
1469
- */
1470
- async rotateIdentity(newIdentityExport, nowMs = this.now()) {
1471
- return await this.call({
1472
- kind: "rotateIdentity",
1473
- id: this.nextId++,
1474
- newIdentityExport,
1475
- nowMs
1476
- });
1477
- }
1478
- /**
1479
- * RETIRED with [[rotateIdentity]]: always rejects (`Invalid`).
1480
- *
1481
- * @deprecated Retired: always rejects.
1482
- */
1483
- async rotateIdentityRetry(conv, nowMs = this.now()) {
1484
- await this.call({ kind: "rotateIdentityRetry", id: this.nextId++, conv, nowMs });
1985
+ return result;
1986
+ }
1987
+ // ------------------------ Public API ------------------------
1988
+ async userId() {
1989
+ return await this.call({ kind: "userId", id: this.nextId++ });
1485
1990
  }
1486
1991
  async deviceId() {
1487
1992
  return await this.call({ kind: "deviceId", id: this.nextId++ });
1488
1993
  }
1994
+ /** The credential this device HOLDS for itself (version 2), which every
1995
+ * leaf and KeyPackage it builds carries. A public value. Never absent
1996
+ * (2026-11-28): every client starts from a device record. Rejects with
1997
+ * `NoDeviceRecord` on a read-only client, which holds no credential. */
1998
+ async heldCredential() {
1999
+ return await this.call({ kind: "heldCredential", id: this.nextId++ });
2000
+ }
2001
+ /** The generation of the held credential. Rejects as `heldCredential` does. */
2002
+ async heldGeneration() {
2003
+ return await this.call({ kind: "heldGeneration", id: this.nextId++ });
2004
+ }
1489
2005
  /**
1490
2006
  * Release every file lock the MLS store holds so the host process can be
1491
2007
  * suspended. Resolves `true` when the locks are genuinely gone.
@@ -1877,6 +2393,91 @@ var MessagingClient = class _MessagingClient {
1877
2393
  // See docs/SYNC_PROTOCOL.md "Sequenced log sync". The subscribe path feeds
1878
2394
  // these itself for a transport that hands over sequenced frames; they are
1879
2395
  // public for hosts that drive their own socket.
2396
+ /**
2397
+ * SELF-ADMISSION: enter `conversationId` by this device's own act, from
2398
+ * what the delivery service returned for it (the sealed GroupInfo and
2399
+ * this account's wrap). Every refusal is a VALUE (`kind: "refused"`);
2400
+ * while the SDK is built without self-admission the answer is `refusal:
2401
+ * "notCompiled"` and nothing was touched. The client reads the anchor
2402
+ * record its device holds by itself, before the join. Rejects only for an
2403
+ * id of the wrong length.
2404
+ *
2405
+ * THE MESSAGES OF A JOIN. `joined` carries `replayed`: messages of this
2406
+ * conversation that waited for the join. Show them, save them and
2407
+ * confirm them (`confirmApplied`) exactly as the messages of a batch
2408
+ * (also for every `joined` entry of `selfAdmitMany`). This client
2409
+ * DELIVERS them to its observers by itself (source `live`), as it
2410
+ * delivers the messages of `processSequencedBatch`; Swift and Kotlin
2411
+ * return them, as they return a batch's messages.
2412
+ */
2413
+ async selfAdmit(conversationId, fetched) {
2414
+ const result = await this.call({
2415
+ kind: "selfAdmit",
2416
+ id: this.nextId++,
2417
+ conv: conversationId,
2418
+ fetched: {
2419
+ blob: fetched.blob,
2420
+ wrap: fetched.wrap,
2421
+ wrapCount: fetched.wrapCount,
2422
+ ...fetched.currentEpoch === void 0 ? {} : { currentEpoch: fetched.currentEpoch }
2423
+ },
2424
+ nowMs: this.now()
2425
+ });
2426
+ if (result.kind === "joined") {
2427
+ holeOfJoin(result);
2428
+ this.fanout.deliverBatch(result.replayed, { source: "live" });
2429
+ }
2430
+ return result;
2431
+ }
2432
+ /**
2433
+ * Enter MANY conversations with few requests (the transport's
2434
+ * `fetchSelfAdmissionStates`, `fetchSealedGroupInfos` and
2435
+ * `sendExternalCommits`): `first` (the conversation on screen) goes to
2436
+ * the head, then the order given, each once. One entry per conversation,
2437
+ * each judged and answered alone. A conversation this device holds and is
2438
+ * not stranded in answers `alreadyHeld` with no request. Nothing is
2439
+ * polled: call again when the account event of a publication arrives.
2440
+ */
2441
+ async selfAdmitMany(conversations, opts = {}) {
2442
+ const entries = await this.call({
2443
+ kind: "selfAdmitMany",
2444
+ id: this.nextId++,
2445
+ ...opts.first === void 0 ? {} : { first: opts.first },
2446
+ conversations,
2447
+ nowMs: this.now()
2448
+ });
2449
+ for (const entry of entries) {
2450
+ if (entry.result.kind === "joined") {
2451
+ holeOfJoin(entry.result);
2452
+ this.fanout.deliverBatch(entry.result.replayed, { source: "live" });
2453
+ }
2454
+ }
2455
+ return entries;
2456
+ }
2457
+ /**
2458
+ * THE ONE CALL A HOST REMEMBERS FOR THE ANCHOR RECORD: write the account's
2459
+ * state part from the RUNNING client. The record of who may sign a
2460
+ * GroupInfo a restoring device enters by is rebuilt from this client's
2461
+ * own conversations first (at every call; the SDK also rebuilds it
2462
+ * by itself during `processSequencedBatch` and at every rotation), and
2463
+ * the part carries it. The host stores the part where it stores every
2464
+ * state part. (`AccountSetup.refreshStateBackup` takes a store and
2465
+ * carries the record as it was last built.)
2466
+ *
2467
+ * A LINKED device owes ONE look first: until `AccountSetup.openStateBackup`
2468
+ * ran once on it, this rejects with the code `state-part-look-owed` (so does
2469
+ * a rotation that keeps the device's key). Pass an EMPTY part there when the
2470
+ * service serves none; whatever it answers, the look is made.
2471
+ */
2472
+ async refreshStateBackup(args) {
2473
+ return await this.call({
2474
+ kind: "clientRefreshStateBackup",
2475
+ id: this.nextId++,
2476
+ accountId: args.accountId,
2477
+ hostState: args.hostState,
2478
+ nowMs: this.now()
2479
+ });
2480
+ }
1880
2481
  /**
1881
2482
  * Apply a batch of live frames, each with its server log position, and
1882
2483
  * checkpoint once per touched conversation. Per conversation: the next
@@ -1964,6 +2565,30 @@ var MessagingClient = class _MessagingClient {
1964
2565
  serverSeq
1965
2566
  });
1966
2567
  }
2568
+ /**
2569
+ * The holes of one conversation's log on this device, lowest position
2570
+ * first: every position at or below the stored position that was not
2571
+ * applied, with the reason and the content hashes the envelopes named.
2572
+ * `kept: true` entries are rows the SDK still holds and retries by itself.
2573
+ */
2574
+ async logHoles(id) {
2575
+ const raw = await this.call({ kind: "logHoles", id: this.nextId++, conv: id });
2576
+ return raw.map(logHoleFromWire);
2577
+ }
2578
+ /**
2579
+ * The host filled `fromServerSeq..toServerSeq` (inclusive) of a
2580
+ * conversation from elsewhere (the account's other device): take the range
2581
+ * out of the recorded holes. Resolves `true` when a recorded hole changed.
2582
+ */
2583
+ async resolveLogHole(id, fromServerSeq, toServerSeq) {
2584
+ return await this.call({
2585
+ kind: "resolveLogHole",
2586
+ id: this.nextId++,
2587
+ conv: id,
2588
+ fromServerSeq,
2589
+ toServerSeq
2590
+ });
2591
+ }
1967
2592
  /**
1968
2593
  * Conversations the server's heads show this device is behind on: not
1969
2594
  * anchored yet, a head above the applied position, or frames held in the
@@ -2044,28 +2669,17 @@ var MessagingClient = class _MessagingClient {
2044
2669
  await this.call({ kind: "confirmApplied", id: this.nextId++, journalIds });
2045
2670
  }
2046
2671
  /**
2047
- * Build a `LinkingTicket` for a new device.
2048
- *
2049
- * [CR-13] `lastAppEvents` is host-supplied per-conversation "what you missed" data
2050
- * (decrypted AppEvent bytes the new device will render before sync catches up).
2051
- * Pass `[]` to suppress catchup data — the new device will see an empty conversation
2052
- * list until normal sync runs.
2053
- *
2054
- * Caller is responsible for HPKE-sealing the returned ticket via
2055
- * `MessagingClient.sealLinkingTicket` before transmitting (CR-3).
2056
- *
2057
- * Rejects (`Invalid`), before anything is sent, a KeyPackage that claims the
2058
- * identity of another account this client knows: a new device links under an
2059
- * identity of its own, or the account's.
2672
+ * The version 3 handshake payload this NEW device publishes: its own signing key,
2673
+ * the id derived from it, `hpkePublicKey` (X-Wing, 1216 bytes) and a KeyPackage it
2674
+ * just made. Show {@link MessagingClient.linkCommitment} of exactly these bytes and
2675
+ * publish exactly these bytes; nobody re-serialises them.
2060
2676
  */
2061
- async buildLinkingTicket(newDeviceId, newDeviceKp, lastAppEvents = []) {
2677
+ async linkHandshakePayload(hpkePublicKey, keyPackage) {
2062
2678
  return await this.call({
2063
- kind: "buildLinkingTicket",
2679
+ kind: "linkHandshakePayload",
2064
2680
  id: this.nextId++,
2065
- newDeviceId,
2066
- newDeviceKp,
2067
- lastAppEvents,
2068
- nowMs: this.now()
2681
+ hpkePublicKey,
2682
+ keyPackage
2069
2683
  });
2070
2684
  }
2071
2685
  /**
@@ -2086,18 +2700,201 @@ var MessagingClient = class _MessagingClient {
2086
2700
  snapshotBytes
2087
2701
  });
2088
2702
  }
2089
- async consumeLinkingTicket(ticket) {
2090
- await this.call({
2091
- kind: "consumeLinkingTicket",
2703
+ /**
2704
+ * The linking ticket, version 3, for the handshake `payload`, verified
2705
+ * inside the call: for a client started from a device record. The new
2706
+ * device's credential is signed by THIS device's key. Rejects when this
2707
+ * device's own chain is at its limit (show the "link from another device"
2708
+ * copy) or it holds no device record. Seal it with
2709
+ * {@link MessagingClient.sealLinkingTicketV3For} and the SAME payload and
2710
+ * `expected`.
2711
+ */
2712
+ async buildLinkingTicketV3For(payload, expected, lastAppEvents = []) {
2713
+ return await this.call({
2714
+ kind: "buildLinkingTicketV3For",
2715
+ id: this.nextId++,
2716
+ payload,
2717
+ ...linkExpectedFields(expected),
2718
+ lastAppEvents,
2719
+ nowMs: this.now()
2720
+ });
2721
+ }
2722
+ /**
2723
+ * The generation and its secret for the link-auth envelope, version 6:
2724
+ * answered only for a handshake whose version 3 ticket this client built
2725
+ * since it started.
2726
+ */
2727
+ async linkGenerationFor(payload, expected) {
2728
+ return await this.call({
2729
+ kind: "linkGenerationFor",
2730
+ id: this.nextId++,
2731
+ payload,
2732
+ ...linkExpectedFields(expected)
2733
+ });
2734
+ }
2735
+ /**
2736
+ * Complete the link on the NEW device, on the staging client of
2737
+ * {@link MessagingClient.beginDeviceLink}: every check of the ticket and of
2738
+ * the envelope's two values, then the DeviceGroup, then the device record.
2739
+ * Rejects with `account refused: link-refused` when anything does not fit:
2740
+ * nothing was kept. Afterwards close this client and start
2741
+ * {@link MessagingClient.initFromDeviceRecord} on the same store.
2742
+ */
2743
+ async completeDeviceLink(ticket, generation, generationSecret) {
2744
+ return await this.call({
2745
+ kind: "completeDeviceLink",
2092
2746
  id: this.nextId++,
2093
2747
  ticket,
2748
+ generation,
2749
+ generationSecret,
2750
+ nowMs: this.now(),
2751
+ storageFeatures: storageFeaturesOf(this.storage)
2752
+ });
2753
+ }
2754
+ /**
2755
+ * Create the DeviceGroup anew after a take-over (the account identity
2756
+ * contract, 3.13, "The DeviceGroup reset"): drops what this device holds
2757
+ * under the DeviceGroup's id, then creates the group alone. Call it ONLY
2758
+ * after the server answered the DeviceGroup reset with `200` or with the
2759
+ * reason `already_reset`. There is no call that joins a DeviceGroup from
2760
+ * outside.
2761
+ */
2762
+ async recreateDeviceGroup() {
2763
+ await this.call({ kind: "recreateDeviceGroup", id: this.nextId++, nowMs: this.now() });
2764
+ }
2765
+ /**
2766
+ * Step 0 of a rotation (removing a device, Secure my account): the next
2767
+ * generation is the pinned one plus one, proven by the root's own
2768
+ * statement, or the call rejects (`account refused:
2769
+ * pinned-generation-unproven`, `generation-ahead`). A listed device is
2770
+ * offered only when its signed delivery key verifies under a leaf of THIS
2771
+ * device's own DeviceGroup. Signs nothing.
2772
+ */
2773
+ async planRotation(start, devices, rootPartGeneration = 0) {
2774
+ return await this.call({
2775
+ kind: "planRotation",
2776
+ id: this.nextId++,
2777
+ start,
2778
+ devices,
2779
+ rootPartGeneration
2780
+ });
2781
+ }
2782
+ /**
2783
+ * Step 1 of a rotation, THE BUILD, with the pending item of `slot` as the
2784
+ * root's source (an account with no backup yet). It runs in this client's
2785
+ * Worker, which opens the root itself for the length of the call (rulings
2786
+ * V136 and V244): nothing of the root reaches this realm or any other
2787
+ * Worker, in the answer or in a refusal. Only the tab's own client builds
2788
+ * (`ClientConfig.tabClient`); any other answers `account refused:
2789
+ * background-worker`. `kept` is every device that stays, this one
2790
+ * included. The answer is the request for the server (public values and
2791
+ * ciphertext) with the record's id, or `keptSetRefused` naming the one
2792
+ * device that cannot be kept: a value, final for that kept set. The
2793
+ * request carries no root part. No request is made by this call.
2794
+ */
2795
+ async rotateGenerationWithPending(args) {
2796
+ return await this.call({
2797
+ kind: "rotateGenerationWithPending",
2798
+ id: this.nextId++,
2799
+ slot: args.slot,
2800
+ start: args.start,
2801
+ devices: args.devices,
2802
+ kept: args.kept,
2803
+ reason: args.reason,
2804
+ accountId: args.accountId,
2805
+ hostState: args.hostState,
2806
+ nowMs: this.now()
2807
+ });
2808
+ }
2809
+ /**
2810
+ * Step 1 of a rotation, THE BUILD, with the backup as the root's source:
2811
+ * the root part as the server holds it and the CURRENT recovery phrase,
2812
+ * and `newPhrase` when the person asked for a new one. As
2813
+ * {@link rotateGenerationWithPending}: the root part is opened inside this
2814
+ * client's Worker for the length of the call. The phrases cross to the
2815
+ * Worker as bytes; the Worker zeroes its copy when the call has answered
2816
+ * and this call zeroes the copy it made. The strings themselves are the
2817
+ * host's: drop them. A phrase that does not open the root part answers
2818
+ * `account refused: backup-authentication` and nothing of the cause.
2819
+ */
2820
+ async rotateGenerationWithBackup(args) {
2821
+ const encoder = new TextEncoder();
2822
+ const phrase = encoder.encode(args.phrase);
2823
+ const newPhrase = args.newPhrase === void 0 ? void 0 : encoder.encode(args.newPhrase);
2824
+ try {
2825
+ return await this.call({
2826
+ kind: "rotateGenerationWithBackup",
2827
+ id: this.nextId++,
2828
+ rootPart: args.rootPart,
2829
+ phrase,
2830
+ ...newPhrase ? { newPhrase } : {},
2831
+ start: args.start,
2832
+ devices: args.devices,
2833
+ kept: args.kept,
2834
+ reason: args.reason,
2835
+ accountId: args.accountId,
2836
+ hostState: args.hostState,
2837
+ nowMs: this.now()
2838
+ });
2839
+ } finally {
2840
+ phrase.fill(0);
2841
+ newPhrase?.fill(0);
2842
+ }
2843
+ }
2844
+ /**
2845
+ * Step 3 of a rotation this device built, on the running client: the
2846
+ * server's answer AS RECEIVED, judged inside the SDK (ruling V161; no
2847
+ * value says "applied"). When the device adopts, this client runs on the
2848
+ * new record from that moment. `"undecided"`: nothing changed, the record
2849
+ * stays.
2850
+ */
2851
+ async completeRotation(recordId, answer) {
2852
+ return await this.call({
2853
+ kind: "completeRotationOnClient",
2854
+ id: this.nextId++,
2855
+ recordId,
2856
+ answer: rotationAnswerFields(answer)
2857
+ });
2858
+ }
2859
+ /**
2860
+ * Step 7 of a rotation, on every other kept device: this device's mailbox
2861
+ * row (`GET /v1/devices/self/credential`). The credential must be this
2862
+ * device's and the root's own; the wrap must open with this device's
2863
+ * delivery key and match the root's statement. On any refusal the device
2864
+ * stays on its generation. From the adoption on, this device's next Commit
2865
+ * in each conversation carries its new credential.
2866
+ */
2867
+ async adoptGeneration(row) {
2868
+ return await this.call({
2869
+ kind: "adoptGeneration",
2870
+ id: this.nextId++,
2871
+ generation: row.generation,
2872
+ credential: row.credential,
2873
+ gsWrap: row.gsWrap,
2874
+ statement: row.statement,
2094
2875
  nowMs: this.now()
2095
2876
  });
2096
2877
  }
2097
2878
  // ------------------------ Recovery (account backup) ------------------------
2098
2879
  // All static + stateless: they run on an ephemeral worker, so the recovery screen can
2099
- // call them before any client is initialised. Same Argon2id/AES-256-GCM IdentityBackup
2100
- // wire format as the iOS/Android FFI bindings — backups are portable across platforms.
2880
+ // call them before any client is initialised. `encryptBackup` and `decryptBackup`
2881
+ // (the version 1 blob) took and returned the account identity and left every
2882
+ // binding on 2026-11-28: a backup is made, proven and opened by `AccountSetup`
2883
+ // and the restore calls, which hand no root to a host.
2884
+ /**
2885
+ * The one switch of self-admission as the wasm module of this package was
2886
+ * COMPILED (a constant of the SDK's source: the same value in every artifact
2887
+ * built from one commit). Read-only. `false`: the module refuses every
2888
+ * external Commit, lists no capability marker and sends nothing of the
2889
+ * feature. A host that ships more than one artifact asserts at start that
2890
+ * they agree.
2891
+ */
2892
+ static async selfAdmissionCompiled() {
2893
+ return _MessagingClient.ephemeralWorkerCall({
2894
+ kind: "selfAdmissionCompiled",
2895
+ id: 1
2896
+ });
2897
+ }
2101
2898
  /** Generate a fresh 12-word BIP39 mnemonic, returned as its canonical phrase string. */
2102
2899
  static async generateMnemonicPhrase() {
2103
2900
  return _MessagingClient.ephemeralWorkerCall({
@@ -2106,7 +2903,7 @@ var MessagingClient = class _MessagingClient {
2106
2903
  });
2107
2904
  }
2108
2905
  /** Validate + canonicalise a user-entered phrase (BIP39 wordlist + checksum). Rejects
2109
- * malformed input. Use on the recovery screen before calling `decryptBackup`. */
2906
+ * malformed input. */
2110
2907
  static async normalizeMnemonicPhrase(phrase) {
2111
2908
  return _MessagingClient.ephemeralWorkerCall({
2112
2909
  kind: "normalizeMnemonicPhrase",
@@ -2114,30 +2911,6 @@ var MessagingClient = class _MessagingClient {
2114
2911
  phrase
2115
2912
  });
2116
2913
  }
2117
- /** Encrypt an IdentityBackup for `POST /v1/recovery/blobs`. `deviceGroupSnapshot` may be
2118
- * empty (Conservative path) or the DeviceGroup's `exportConversationStateSnapshot`. */
2119
- static async encryptBackup(args) {
2120
- return _MessagingClient.ephemeralWorkerCall({
2121
- kind: "encryptBackup",
2122
- id: 1,
2123
- mnemonicPhrase: args.mnemonicPhrase,
2124
- accountId: args.accountId,
2125
- identityExport: args.identityExport,
2126
- deviceGroupSnapshot: args.deviceGroupSnapshot,
2127
- conversationSnapshots: args.conversationSnapshots ?? [],
2128
- createdAtMs: args.createdAtMs
2129
- });
2130
- }
2131
- /** Decrypt a recovery blob from `GET /v1/recovery/blobs`. Throws on wrong mnemonic or a
2132
- * tampered blob. The returned `identity_export` is the secret seed for `init`. */
2133
- static async decryptBackup(blob, mnemonicPhrase) {
2134
- return _MessagingClient.ephemeralWorkerCall({
2135
- kind: "decryptBackup",
2136
- id: 1,
2137
- blob,
2138
- mnemonicPhrase
2139
- });
2140
- }
2141
2914
  /**
2142
2915
  * Whether `mnemonicPhrase` opens `blob` (a recovery backup as the server returned
2143
2916
  * it), with THREE answers to switch on:
@@ -2152,7 +2925,6 @@ var MessagingClient = class _MessagingClient {
2152
2925
  * version or a format this build cannot read, a payload it cannot decode, a
2153
2926
  * failure inside the SDK. Delete nothing, claim nothing, ask again later.
2154
2927
  *
2155
- * `decryptBackup` rejects with one message for the last two alike; it is unchanged.
2156
2928
  * This call NEVER rejects: a wasm trap, an out-of-memory failure and a one-shot
2157
2929
  * worker that could not be created or did not answer are `couldNotCheck` with
2158
2930
  * `reason: "internal"`. It resolves nothing of the backup: the decrypted identity
@@ -2173,62 +2945,134 @@ var MessagingClient = class _MessagingClient {
2173
2945
  }
2174
2946
  }
2175
2947
  // ------------------------ Peer-assisted history transfer ------------------------
2176
- // Authenticated (sign-then-encrypt) device-to-device history used by linking and
2177
- // post-recovery peer re-add. Confidential to the recipient's ephemeral X25519 key AND
2178
- // signed by the account identity key, so the receiver proves the sender. Plaintext-only
2179
- // share — preserves forward secrecy (no MLS keys leave the device).
2180
- /** Seal+sign a `HistoryBundle` for a recipient device. `recipientPub` (X25519, 32B) is the
2181
- * recipient's ephemeral pubkey from the linking QR; `senderIdentitySecret` (Ed25519 seed,
2182
- * 32B) is this account's identity key. Returns the blob to POST to /v1/history-transfers. */
2183
- static async sealHistoryBundle(bundle, recipientPub, senderIdentitySecret) {
2184
- return _MessagingClient.ephemeralWorkerCall({
2185
- kind: "sealHistoryBundle",
2186
- id: 1,
2187
- bundle,
2188
- recipientPub,
2189
- senderIdentitySecret
2948
+ // History, version 3 (2026-11-25, rulings V88 to V92). A bundle is signed by
2949
+ // this DEVICE's key and sealed only to a key the SDK verified itself: the
2950
+ // signed delivery key of a device that is a verified leaf of this device's own
2951
+ // tree, or the key of a link handshake verified against what the person was
2952
+ // shown. No call takes a recipient key, so a server that answers a key request
2953
+ // with a key of its own gets nothing. The raw-key, seed-signed forms
2954
+ // (sealHistoryBundle, openHistoryBundle and their Pq twins) are REMOVED.
2955
+ /** The counter the next {@link publishHistoryDeliveryKey} with this floor will
2956
+ * sign. A host that keeps the device key outside the SDK's store writes this
2957
+ * number beside that key BEFORE the publish, and passes what it kept as
2958
+ * `counterFloor` from then on (0 when it keeps none). Never a server's number. */
2959
+ async historyDeliveryKeyNextCounter(counterFloor = 0) {
2960
+ return await this.call({
2961
+ kind: "historyDeliveryKeyNextCounter",
2962
+ id: this.nextId++,
2963
+ counterFloor
2190
2964
  });
2191
2965
  }
2192
- /** Open+verify a sealed history bundle. `recipientPriv` (X25519, 32B) is this device's
2193
- * ephemeral private key; `senderIdentityPub` (Ed25519, 32B) is the account identity pubkey
2194
- * from the linking handshake. Throws if the signature doesn't verify. */
2195
- static async openHistoryBundle(sealed, recipientPriv, senderIdentityPub) {
2196
- return _MessagingClient.ephemeralWorkerCall({
2197
- kind: "openHistoryBundle",
2198
- id: 1,
2199
- sealed,
2200
- recipientPriv,
2201
- senderIdentityPub
2966
+ /** This device's signed history delivery key: post it at every start. The key
2967
+ * pair is made once, inside the SDK; the device signs only the key it holds. */
2968
+ async publishHistoryDeliveryKey(counterFloor = 0) {
2969
+ return await this.call({
2970
+ kind: "publishHistoryDeliveryKey",
2971
+ id: this.nextId++,
2972
+ counterFloor
2973
+ });
2974
+ }
2975
+ /** The server refused the publication (`409 delivery_key_counter_behind`) and
2976
+ * answered with the statement IT holds. Taken only when that statement
2977
+ * verifies strictly under THIS device's own key and is not older than this
2978
+ * device's own; resolves with the statement to publish once more. Anything
2979
+ * else rejects ({@link NotPermittedError}) and nothing is signed. */
2980
+ async adoptHistoryDeliveryKeyCounter(stored) {
2981
+ return await this.call({
2982
+ kind: "adoptHistoryDeliveryKeyCounter",
2983
+ id: this.nextId++,
2984
+ stored
2202
2985
  });
2203
2986
  }
2204
2987
  /**
2205
- * Post-quantum {@link sealHistoryBundle}: `recipientPub` is the recipient's
2206
- * X-Wing public key ({@link HPKE_PQ_PUBLIC_KEY_BYTES} bytes). Wrapper `v: 2`;
2207
- * the classical open refuses it and vice versa.
2988
+ * Verify `recipient` (the statement a server returned for the device the bundle
2989
+ * names) in this device's own tree, then sign the bundle with the device key and
2990
+ * seal it to that key. `ownAccount` is what the host believes (true: a device of
2991
+ * this account, looked up in the DeviceGroup; false: another account's device,
2992
+ * looked up in the tree of the bundle's conversation). It decides nothing: the
2993
+ * SDK takes the path the recipient's verified identity gives and rejects
2994
+ * ({@link NotPermittedError}) when the host said the other one.
2208
2995
  */
2209
- static async sealHistoryBundlePq(bundle, recipientPub, senderIdentitySecret) {
2210
- if (recipientPub.length !== HPKE_PQ_PUBLIC_KEY_BYTES) {
2211
- throw new Error(`sealHistoryBundlePq: recipientPub must be ${HPKE_PQ_PUBLIC_KEY_BYTES} bytes`);
2212
- }
2213
- return _MessagingClient.ephemeralWorkerCall({
2214
- kind: "sealHistoryBundlePq",
2215
- id: 1,
2996
+ async sealHistoryBundleV3(bundle, recipient, ownAccount) {
2997
+ return await this.call({
2998
+ kind: "sealHistoryBundleV3",
2999
+ id: this.nextId++,
2216
3000
  bundle,
2217
- recipientPub,
2218
- senderIdentitySecret
3001
+ recipient,
3002
+ ownAccount
2219
3003
  });
2220
3004
  }
2221
- /** Post-quantum {@link openHistoryBundle}: `recipientPriv` is the 32-byte X-Wing seed. */
2222
- static async openHistoryBundlePq(sealed, recipientPriv, senderIdentityPub) {
2223
- if (recipientPriv.length !== 32) {
2224
- throw new Error("openHistoryBundlePq: recipientPriv must be 32 bytes");
2225
- }
2226
- return _MessagingClient.ephemeralWorkerCall({
2227
- kind: "openHistoryBundlePq",
2228
- id: 1,
3005
+ /** The link's own transfer. The handshake `payload` is verified inside the call
3006
+ * against what this device was shown, and the bundle is sealed to the verified
3007
+ * handshake's key: no key can be passed. Rejects with
3008
+ * {@link LinkCommitmentMismatchError} when the payload is not the committed one. */
3009
+ async sealLinkHistoryBundle(bundle, payload, expected) {
3010
+ return await this.call({
3011
+ kind: "sealLinkHistoryBundle",
3012
+ id: this.nextId++,
3013
+ bundle,
3014
+ payload,
3015
+ ...linkExpectedFields(expected)
3016
+ });
3017
+ }
3018
+ /** Open a transfer sealed to this device's published delivery key. `ownAccount`
3019
+ * as in {@link sealHistoryBundleV3}, and as there only a reason to refuse. A
3020
+ * bundle whose import the host CONFIRMED ({@link confirmHistoryImport}) is never
3021
+ * returned again: the transfer then rejects with {@link HistoryRefusedError}
3022
+ * `replayed`, and the host drops it. Until the confirmation the same transfer
3023
+ * opens again (the host's import is idempotent by event id). */
3024
+ async openHistoryBundleV3(sealed, ownAccount) {
3025
+ return await this.call({
3026
+ kind: "openHistoryBundleV3",
3027
+ id: this.nextId++,
2229
3028
  sealed,
2230
- recipientPriv,
2231
- senderIdentityPub
3029
+ ownAccount
3030
+ });
3031
+ }
3032
+ /** The NEW device opens its link's own transfer, sealed to the X-Wing key of the
3033
+ * handshake it published; `recipientPriv` is that key's 32-byte seed. */
3034
+ async openLinkHistoryBundle(sealed, recipientPriv) {
3035
+ return await this.call({
3036
+ kind: "openLinkHistoryBundle",
3037
+ id: this.nextId++,
3038
+ sealed,
3039
+ recipientPriv
3040
+ });
3041
+ }
3042
+ /** Ruling V177: call AFTER the host's own store holds the events of a bundle an
3043
+ * open returned, with that result's `import_id`. From then on the same bundle
3044
+ * (sealed afresh or not, from any sender) is refused as a replay. `true` when
3045
+ * this call recorded it, `false` when it was recorded before. The id may be
3046
+ * kept and confirmed after a restart. A local write; no request. */
3047
+ async confirmHistoryImport(importId) {
3048
+ return await this.call({
3049
+ kind: "confirmHistoryImport",
3050
+ id: this.nextId++,
3051
+ importId
3052
+ });
3053
+ }
3054
+ /** Whether this device's trust record names `deviceId` for history. */
3055
+ async historyTrust(deviceId) {
3056
+ return await this.call({
3057
+ kind: "historyTrust",
3058
+ id: this.nextId++,
3059
+ deviceId
3060
+ });
3061
+ }
3062
+ /** Record that this device shipped history to `deviceId`, once the server
3063
+ * accepted the transfer and never before. */
3064
+ async recordHistoryShipped(deviceId) {
3065
+ await this.call({ kind: "recordHistoryShipped", id: this.nextId++, deviceId });
3066
+ }
3067
+ /** For a device of this account: ship history by itself, only after the person
3068
+ * confirms on this device, or not at all. Ask it for every entry of the
3069
+ * admission ledger and before the "send your chats" prompt; a link's own
3070
+ * transfer does not ask. */
3071
+ async historyShipDecision(deviceId) {
3072
+ return await this.call({
3073
+ kind: "historyShipDecision",
3074
+ id: this.nextId++,
3075
+ deviceId
2232
3076
  });
2233
3077
  }
2234
3078
  /**
@@ -2365,6 +3209,32 @@ var MessagingClient = class _MessagingClient {
2365
3209
  nowMs
2366
3210
  });
2367
3211
  }
3212
+ /**
3213
+ * THE ONE TAP AFTER A RESTORE BESIDE DEVICES THAT STAY (ruling V123). Call it on
3214
+ * a KEPT device when the person confirmed, on that device, the device `deviceId`
3215
+ * that restored with the recovery phrase and waits for its DeviceGroup.
3216
+ * `keyPackage` is a KeyPackage of that device, as the host fetched it. Nothing
3217
+ * the server says is believed: the KeyPackage must be the named device's, and its
3218
+ * credential must verify for THIS device's own account root, be signed by the
3219
+ * root itself (a linked device enters by its ticket) and stand at the generation
3220
+ * this device holds; anything else rejects (`NotPermitted`; `StaleGeneration`
3221
+ * when this device is behind its account). Then the DeviceGroup's ordinary Add,
3222
+ * sent with its Welcome and merged only when the delivery service accepted. As
3223
+ * every Commit there it rejects with `DeviceGroupBehind` while this device is
3224
+ * behind or may not commit yet after a rotation (catch up, or run the sweep, and
3225
+ * call again), and with `WelcomeUndelivered` when the Add is in and the Welcome is
3226
+ * not (call again). The waiting device calls nothing: the Welcome reaches it by
3227
+ * the transport. MLS only.
3228
+ */
3229
+ async addRestoredDevice(deviceId, keyPackage, nowMs = this.now()) {
3230
+ await this.call({
3231
+ kind: "addRestoredDevice",
3232
+ id: this.nextId++,
3233
+ deviceId,
3234
+ keyPackage,
3235
+ nowMs
3236
+ });
3237
+ }
2368
3238
  /**
2369
3239
  * Export a portable MLS state snapshot for one conversation ([CR-7]).
2370
3240
  *
@@ -2665,6 +3535,29 @@ var MessagingClient = class _MessagingClient {
2665
3535
  const heads = await this.transport.fetchLogHeads();
2666
3536
  return heads === null || heads === void 0 ? null : heads.map(logHeadToWire);
2667
3537
  }
3538
+ if (method === "send" || method === "sendBatch") {
3539
+ try {
3540
+ return await t[method]?.(...args);
3541
+ } catch (e) {
3542
+ if (e?.staleGeneration === true) {
3543
+ throw new Error(TRANSPORT_STALE_GENERATION);
3544
+ }
3545
+ throw e;
3546
+ }
3547
+ }
3548
+ if (method === "sendExternalCommit" || method === "sendExternalCommits" || method === "publishSealedGroupInfo") {
3549
+ try {
3550
+ return await t[method]?.(...args) ?? null;
3551
+ } catch (e) {
3552
+ if (e?.epochOccupied === true) {
3553
+ throw new Error(EXTERNAL_COMMIT_EPOCH_OCCUPIED);
3554
+ }
3555
+ if (e?.staleGeneration === true) {
3556
+ throw new Error(TRANSPORT_STALE_GENERATION);
3557
+ }
3558
+ throw e;
3559
+ }
3560
+ }
2668
3561
  return await t[method]?.(...args);
2669
3562
  }
2670
3563
  async handleWorker(msg) {
@@ -2798,11 +3691,162 @@ function isSenderMismatchError(e) {
2798
3691
  const text = typeof e === "string" ? e : e !== null && typeof e === "object" && typeof e.message === "string" ? e.message : null;
2799
3692
  return text !== null && text.startsWith(SENDER_MISMATCH_PREFIX);
2800
3693
  }
3694
+ var STORE_MOVED_PREFIX = "store moved: ";
3695
+ var StoreMovedError = class extends Error {
3696
+ constructor(message) {
3697
+ super(message);
3698
+ this.name = "StoreMovedError";
3699
+ }
3700
+ };
3701
+ function isStoreMovedError(e) {
3702
+ const text = typeof e === "string" ? e : e !== null && typeof e === "object" && typeof e.message === "string" ? e.message : null;
3703
+ return text !== null && text.startsWith(STORE_MOVED_PREFIX);
3704
+ }
3705
+ var READ_ONLY_PREFIX = "read-only client: ";
3706
+ var ReadOnlyError = class extends Error {
3707
+ constructor(message) {
3708
+ super(message);
3709
+ this.name = "ReadOnlyError";
3710
+ }
3711
+ };
3712
+ function isReadOnlyError(e) {
3713
+ const text = typeof e === "string" ? e : e !== null && typeof e === "object" && typeof e.message === "string" ? e.message : null;
3714
+ return text !== null && text.startsWith(READ_ONLY_PREFIX);
3715
+ }
3716
+ function linkExpectedFields(expected) {
3717
+ return "code" in expected ? { expectedCode: expected.code } : { expectedQr: expected.qrCommitment };
3718
+ }
3719
+ var LINK_COMMITMENT_MISMATCH_PREFIX = "link commitment mismatch: ";
3720
+ var LinkCommitmentMismatchError = class extends Error {
3721
+ constructor(message) {
3722
+ super(message);
3723
+ this.name = "LinkCommitmentMismatchError";
3724
+ }
3725
+ };
3726
+ function isLinkCommitmentMismatchError(e) {
3727
+ if (e instanceof LinkCommitmentMismatchError) return true;
3728
+ const text = e instanceof Error ? e.message : typeof e === "string" ? e : null;
3729
+ return text !== null && text.startsWith(LINK_COMMITMENT_MISMATCH_PREFIX);
3730
+ }
3731
+ var WELCOME_MISLABELED_PREFIX = "welcome mislabeled: ";
3732
+ var WelcomeMislabeledError = class extends Error {
3733
+ constructor(message) {
3734
+ super(message);
3735
+ this.name = "WelcomeMislabeledError";
3736
+ }
3737
+ };
3738
+ function isWelcomeMislabeledError(e) {
3739
+ const text = typeof e === "string" ? e : e !== null && typeof e === "object" && typeof e.message === "string" ? e.message : null;
3740
+ return text !== null && text.startsWith(WELCOME_MISLABELED_PREFIX);
3741
+ }
3742
+ var STALE_GENERATION_PREFIX = "stale generation: ";
3743
+ var StaleGenerationError = class extends Error {
3744
+ constructor(message) {
3745
+ super(message);
3746
+ this.name = "StaleGenerationError";
3747
+ }
3748
+ };
3749
+ function isStaleGenerationError(e) {
3750
+ const text = typeof e === "string" ? e : e !== null && typeof e === "object" && typeof e.message === "string" ? e.message : null;
3751
+ return text !== null && text.startsWith(STALE_GENERATION_PREFIX);
3752
+ }
3753
+ var DEVICE_GROUP_BEHIND_PREFIX = "device group behind: ";
3754
+ var DeviceGroupBehindError = class extends Error {
3755
+ constructor(message) {
3756
+ super(message);
3757
+ this.name = "DeviceGroupBehindError";
3758
+ }
3759
+ };
3760
+ function isDeviceGroupBehindError(e) {
3761
+ const text = typeof e === "string" ? e : e !== null && typeof e === "object" && typeof e.message === "string" ? e.message : null;
3762
+ return text !== null && text.startsWith(DEVICE_GROUP_BEHIND_PREFIX);
3763
+ }
3764
+ var LINK_CHAIN_TOO_DEEP_PREFIX = "link chain too deep: ";
3765
+ var LinkChainTooDeepError = class extends Error {
3766
+ constructor(message) {
3767
+ super(message);
3768
+ this.name = "LinkChainTooDeepError";
3769
+ }
3770
+ };
3771
+ var LINK_ADD_REFUSED_PREFIX = "link add refused: ";
3772
+ var LinkAddRefusedError = class extends Error {
3773
+ constructor(message) {
3774
+ super(message);
3775
+ this.name = "LinkAddRefusedError";
3776
+ }
3777
+ };
3778
+ var WELCOME_WAITS_PREFIX = "welcome waits: ";
3779
+ var WelcomeWaitsError = class extends Error {
3780
+ constructor(message) {
3781
+ super(message);
3782
+ this.name = "WelcomeWaitsError";
3783
+ }
3784
+ };
3785
+ function startsWithPrefix(e, prefix) {
3786
+ const text = typeof e === "string" ? e : e !== null && typeof e === "object" && typeof e.message === "string" ? e.message : null;
3787
+ return text !== null && text.startsWith(prefix);
3788
+ }
3789
+ function isLinkChainTooDeepError(e) {
3790
+ return startsWithPrefix(e, LINK_CHAIN_TOO_DEEP_PREFIX);
3791
+ }
3792
+ function isLinkAddRefusedError(e) {
3793
+ return startsWithPrefix(e, LINK_ADD_REFUSED_PREFIX);
3794
+ }
3795
+ function isWelcomeWaitsError(e) {
3796
+ return startsWithPrefix(e, WELCOME_WAITS_PREFIX);
3797
+ }
3798
+ var HISTORY_REFUSED_PREFIX = "history refused: ";
3799
+ var HistoryRefusedError = class extends Error {
3800
+ reason;
3801
+ constructor(message) {
3802
+ super(message);
3803
+ this.name = "HistoryRefusedError";
3804
+ const reason = message.slice(HISTORY_REFUSED_PREFIX.length);
3805
+ this.reason = HISTORY_REFUSAL_REASONS.includes(reason) ? reason : "unknown";
3806
+ }
3807
+ };
3808
+ var HISTORY_REFUSAL_REASONS = [
3809
+ "recipient",
3810
+ "sender",
3811
+ "signature",
3812
+ "recipient-key",
3813
+ "too-large",
3814
+ "replayed"
3815
+ ];
3816
+ function isHistoryRefusedError(e) {
3817
+ if (e instanceof HistoryRefusedError) return true;
3818
+ const text = typeof e === "string" ? e : e !== null && typeof e === "object" && typeof e.message === "string" ? e.message : null;
3819
+ return text !== null && text.startsWith(HISTORY_REFUSED_PREFIX);
3820
+ }
3821
+ var JOURNAL_FULL_PREFIX = "journal full: ";
3822
+ var JournalFullError = class extends Error {
3823
+ constructor(message) {
3824
+ super(message);
3825
+ this.name = "JournalFullError";
3826
+ }
3827
+ };
3828
+ function isJournalFullError(e) {
3829
+ const text = typeof e === "string" ? e : e !== null && typeof e === "object" && typeof e.message === "string" ? e.message : null;
3830
+ return text !== null && text.startsWith(JOURNAL_FULL_PREFIX);
3831
+ }
2801
3832
  function errorFromWorker(text) {
2802
3833
  if (text.startsWith(NOT_PERMITTED_PREFIX)) return new NotPermittedError(text);
2803
3834
  if (text.startsWith(SENDER_MISMATCH_PREFIX)) return new SenderMismatchError(text);
3835
+ if (text.startsWith(STORE_MOVED_PREFIX)) return new StoreMovedError(text);
3836
+ if (text.startsWith(READ_ONLY_PREFIX)) return new ReadOnlyError(text);
3837
+ if (text.startsWith(WELCOME_MISLABELED_PREFIX)) return new WelcomeMislabeledError(text);
3838
+ if (text.startsWith(LINK_COMMITMENT_MISMATCH_PREFIX)) return new LinkCommitmentMismatchError(text);
3839
+ if (text.startsWith(STALE_GENERATION_PREFIX)) return new StaleGenerationError(text);
3840
+ if (text.startsWith(DEVICE_GROUP_BEHIND_PREFIX)) return new DeviceGroupBehindError(text);
3841
+ if (text.startsWith(JOURNAL_FULL_PREFIX)) return new JournalFullError(text);
3842
+ if (text.startsWith(LINK_CHAIN_TOO_DEEP_PREFIX)) return new LinkChainTooDeepError(text);
3843
+ if (text.startsWith(LINK_ADD_REFUSED_PREFIX)) return new LinkAddRefusedError(text);
3844
+ if (text.startsWith(WELCOME_WAITS_PREFIX)) return new WelcomeWaitsError(text);
3845
+ if (text.startsWith(HISTORY_REFUSED_PREFIX)) return new HistoryRefusedError(text);
2804
3846
  return new Error(text);
2805
3847
  }
3848
+ var EXTERNAL_COMMIT_EPOCH_OCCUPIED = "external commit: epoch occupied";
3849
+ var TRANSPORT_STALE_GENERATION = "transport: stale generation";
2806
3850
  async function emulateSendBatch(transport, envelopes) {
2807
3851
  let delivered = 0;
2808
3852
  for (const envelope of envelopes) {
@@ -2845,17 +3889,36 @@ function sameBytesU8(a, b) {
2845
3889
  for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
2846
3890
  return true;
2847
3891
  }
3892
+ function holeOfJoin(result) {
3893
+ if (result.beforeReturn !== void 0 && result.beforeReturn !== null) {
3894
+ result.beforeReturn = logHoleFromWire(result.beforeReturn);
3895
+ }
3896
+ }
2848
3897
  // Annotate the CommonJS export names for ESM import in node:
2849
3898
  0 && (module.exports = {
3899
+ AccountSetup,
3900
+ AccountSetupClosedError,
2850
3901
  BATCH_PARTIAL_PREFIX,
2851
3902
  CONTENT_TYPE_CBOR,
2852
3903
  CONTENT_TYPE_CBOR_LEGACY_V1,
2853
3904
  CONTENT_TYPE_JSON,
2854
3905
  CONTENT_TYPE_JSON_LEGACY_V1,
3906
+ DEVICE_GROUP_BEHIND_PREFIX,
3907
+ DeviceGroupBehindError,
2855
3908
  EphemeralWorkerError,
3909
+ HISTORY_REFUSED_PREFIX,
2856
3910
  HPKE_PQ_ENC_BYTES,
2857
3911
  HPKE_PQ_PUBLIC_KEY_BYTES,
3912
+ HistoryRefusedError,
2858
3913
  IndexedDbStorage,
3914
+ JOURNAL_FULL_PREFIX,
3915
+ JournalFullError,
3916
+ LINK_ADD_REFUSED_PREFIX,
3917
+ LINK_CHAIN_TOO_DEEP_PREFIX,
3918
+ LINK_COMMITMENT_MISMATCH_PREFIX,
3919
+ LinkAddRefusedError,
3920
+ LinkChainTooDeepError,
3921
+ LinkCommitmentMismatchError,
2859
3922
  MAX_PREVIEW_PREREQUISITES,
2860
3923
  MessagingClient,
2861
3924
  MessagingClientClosedError,
@@ -2864,16 +3927,38 @@ function sameBytesU8(a, b) {
2864
3927
  PING_WIRE_CONTRACT_HEADER,
2865
3928
  PING_WIRE_CONTRACT_HEADER_VALUE,
2866
3929
  PING_WIRE_CONTRACT_VERSION,
3930
+ READ_ONLY_PREFIX,
3931
+ ReadOnlyError,
2867
3932
  SENDER_MISMATCH_PREFIX,
3933
+ STALE_GENERATION_PREFIX,
3934
+ STORE_MOVED_PREFIX,
2868
3935
  SenderMismatchError,
3936
+ StaleGenerationError,
3937
+ StoreMovedError,
2869
3938
  ValidationError,
3939
+ WELCOME_MISLABELED_PREFIX,
3940
+ WELCOME_WAITS_PREFIX,
2870
3941
  WIRE_VERSION_MIN_ACCEPTED,
2871
3942
  WebSocketTransport,
3943
+ WelcomeMislabeledError,
3944
+ WelcomeWaitsError,
3945
+ accountRefusalCode,
2872
3946
  backupPhraseCheckFromWire,
2873
3947
  describeTransportError,
2874
3948
  emulateSendBatch,
3949
+ isDeviceGroupBehindError,
3950
+ isHistoryRefusedError,
3951
+ isJournalFullError,
3952
+ isLinkAddRefusedError,
3953
+ isLinkChainTooDeepError,
3954
+ isLinkCommitmentMismatchError,
2875
3955
  isNotPermittedError,
3956
+ isReadOnlyError,
2876
3957
  isSenderMismatchError,
3958
+ isStaleGenerationError,
3959
+ isStoreMovedError,
3960
+ isWelcomeMislabeledError,
3961
+ isWelcomeWaitsError,
2877
3962
  negotiates,
2878
3963
  notPermittedRule,
2879
3964
  openNotificationPreview,