@ping-app/ping-openmls-sdk 0.10.2 → 0.10.4
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/README.md +13 -10
- package/dist/index.cjs +1401 -266
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +999 -145
- package/dist/index.d.ts +999 -145
- package/dist/index.js +1360 -263
- package/dist/index.js.map +1 -1
- package/dist/notification-preview.cjs +1 -3
- package/dist/notification-preview.cjs.map +1 -1
- package/dist/notification-preview.d.cts +1 -8
- package/dist/notification-preview.d.ts +1 -8
- package/dist/notification-preview.js +1 -3
- package/dist/notification-preview.js.map +1 -1
- package/dist/storage/indexeddb.cjs +4 -3
- package/dist/storage/indexeddb.cjs.map +1 -1
- package/dist/storage/indexeddb.d.cts +1 -1
- package/dist/storage/indexeddb.d.ts +1 -1
- package/dist/storage/indexeddb.js +4 -3
- package/dist/storage/indexeddb.js.map +1 -1
- package/dist/transport/websocket.d.cts +1 -1
- package/dist/transport/websocket.d.ts +1 -1
- package/dist/{types-gAmJFSC-.d.cts → types-omhvRjtq.d.cts} +343 -45
- package/dist/{types-gAmJFSC-.d.ts → types-omhvRjtq.d.ts} +343 -45
- package/dist/worker.cjs +686 -69
- package/dist/worker.cjs.map +1 -1
- package/dist/worker.js +716 -80
- package/dist/worker.js.map +1 -1
- package/package.json +1 -1
- package/wasm/package.json +1 -1
- package/wasm/ping_wasm.d.ts +539 -112
- package/wasm/ping_wasm.js +1387 -322
- package/wasm/ping_wasm_bg.wasm +0 -0
- package/wasm/ping_wasm_bg.wasm.d.ts +74 -21
package/dist/worker.js
CHANGED
|
@@ -17,15 +17,19 @@ function reserveLinearMemory(memory) {
|
|
|
17
17
|
// src/worker.ts
|
|
18
18
|
import init, {
|
|
19
19
|
PingClient,
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
beginDeviceLink as wasmBeginDeviceLink,
|
|
21
|
+
sealLinkingTicketV3For as wasmSealLinkingTicketV3For,
|
|
22
|
+
openLinkingTicketV3 as wasmOpenLinkingTicketV3,
|
|
23
|
+
sealLinkAuthFor as wasmSealLinkAuthFor,
|
|
24
|
+
linkCommitment as wasmLinkCommitment,
|
|
25
|
+
normalizeLinkCode as wasmNormalizeLinkCode,
|
|
26
|
+
linkQrCommitment as wasmLinkQrCommitment,
|
|
27
|
+
verifyLinkHandshake as wasmVerifyLinkHandshake,
|
|
22
28
|
hpkeSeal as wasmHpkeSeal,
|
|
23
29
|
hpkeOpen as wasmHpkeOpen,
|
|
24
30
|
hpkeSealRaw as wasmHpkeSealRaw,
|
|
25
31
|
hpkeOpenRaw as wasmHpkeOpenRaw,
|
|
26
32
|
hpkeGenerateKeypair as wasmHpkeGenerateKeypair,
|
|
27
|
-
sealLinkingTicketPq as wasmSealLinkingTicketPq,
|
|
28
|
-
openLinkingTicketPq as wasmOpenLinkingTicketPq,
|
|
29
33
|
hpkeSealPq as wasmHpkeSealPq,
|
|
30
34
|
hpkeOpenPq as wasmHpkeOpenPq,
|
|
31
35
|
hpkeSealRawPq as wasmHpkeSealRawPq,
|
|
@@ -35,19 +39,235 @@ import init, {
|
|
|
35
39
|
hpkePublicKeyFromSeed as wasmHpkePublicKeyFromSeed,
|
|
36
40
|
hpkePublicKeyFromPrivate as wasmHpkePublicKeyFromPrivate,
|
|
37
41
|
signDeviceReauth as wasmSignDeviceReauth,
|
|
38
|
-
|
|
42
|
+
signDeviceLinkApprovalFor as wasmSignDeviceLinkApprovalFor,
|
|
39
43
|
signDeviceLinkPossession as wasmSignDeviceLinkPossession,
|
|
40
44
|
decodeCatchupSnapshot as wasmDecodeCatchupSnapshot,
|
|
41
45
|
generateMnemonicPhrase as wasmGenerateMnemonicPhrase,
|
|
46
|
+
selfAdmissionCompiled as wasmSelfAdmissionCompiled,
|
|
42
47
|
normalizeMnemonicPhrase as wasmNormalizeMnemonicPhrase,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
checkBackupPhrase as wasmCheckBackupPhrase,
|
|
49
|
+
createAccount as wasmCreateAccount,
|
|
50
|
+
pendingStatus as wasmPendingStatus,
|
|
51
|
+
makeBackup as wasmMakeBackup,
|
|
52
|
+
proveBackup as wasmProveBackup,
|
|
53
|
+
openBackupForRestore as wasmOpenBackupForRestore,
|
|
54
|
+
restoreTakeOver as wasmRestoreTakeOver,
|
|
55
|
+
takeAccountBack as wasmTakeAccountBack,
|
|
56
|
+
resumeRotation as wasmResumeRotation,
|
|
57
|
+
resumeRotationAt as wasmResumeRotationAt,
|
|
58
|
+
completeRotation as wasmCompleteRotation,
|
|
59
|
+
setRotationPhase as wasmSetRotationPhase,
|
|
60
|
+
finishRotation as wasmFinishRotation,
|
|
61
|
+
abandonRotation as wasmAbandonRotation,
|
|
62
|
+
rotationRecordState as wasmRotationRecordState,
|
|
63
|
+
restoreJoin as wasmRestoreJoin,
|
|
64
|
+
openStateBackup as wasmOpenStateBackup,
|
|
65
|
+
refreshStateBackup as wasmRefreshStateBackup,
|
|
66
|
+
endPending as wasmEndPending,
|
|
67
|
+
beginAccountSetupInMemory as wasmBeginAccountSetupInMemory
|
|
49
68
|
} from "../wasm/ping_wasm";
|
|
50
69
|
|
|
70
|
+
// src/pending-root-store.ts
|
|
71
|
+
var PENDING_ROOT_WRAP_LABEL = "ping/pending-root-wrap/v1";
|
|
72
|
+
var DB_PREFIX = "ping-pending-root:";
|
|
73
|
+
var STORE = "item";
|
|
74
|
+
var ITEM_KEY = "pending";
|
|
75
|
+
var SEED_LEN = 32;
|
|
76
|
+
var PUBLIC_KEY_LEN = 32;
|
|
77
|
+
var NONCE_LEN = 12;
|
|
78
|
+
var TAG_BITS = 128;
|
|
79
|
+
var WRAPPED_LEN = SEED_LEN + TAG_BITS / 8;
|
|
80
|
+
var PendingStoreUnavailableError = class extends Error {
|
|
81
|
+
constructor() {
|
|
82
|
+
super("the pending store is not available in this realm");
|
|
83
|
+
this.name = "PendingStoreUnavailable";
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var PendingRootExistsError = class extends Error {
|
|
87
|
+
constructor() {
|
|
88
|
+
super("the slot already holds a pending item");
|
|
89
|
+
this.name = "PendingRootExists";
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
function pendingRootDatabaseName(slot) {
|
|
93
|
+
return DB_PREFIX + slot;
|
|
94
|
+
}
|
|
95
|
+
function inServiceWorker() {
|
|
96
|
+
const scope = globalThis.ServiceWorkerGlobalScope;
|
|
97
|
+
return typeof scope === "function" && globalThis instanceof scope;
|
|
98
|
+
}
|
|
99
|
+
function realm() {
|
|
100
|
+
const idb = globalThis.indexedDB;
|
|
101
|
+
const subtle = globalThis.crypto?.subtle;
|
|
102
|
+
if (inServiceWorker() || !idb || !subtle) {
|
|
103
|
+
throw new PendingStoreUnavailableError();
|
|
104
|
+
}
|
|
105
|
+
return { idb, subtle };
|
|
106
|
+
}
|
|
107
|
+
function request(req) {
|
|
108
|
+
return new Promise((resolve, reject) => {
|
|
109
|
+
req.onsuccess = () => resolve(req.result);
|
|
110
|
+
req.onerror = () => reject(req.error ?? new Error("IndexedDB request failed"));
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function open(idb, slot) {
|
|
114
|
+
return new Promise((resolve, reject) => {
|
|
115
|
+
const req = idb.open(pendingRootDatabaseName(slot), 1);
|
|
116
|
+
req.onupgradeneeded = () => {
|
|
117
|
+
if (!req.result.objectStoreNames.contains(STORE)) {
|
|
118
|
+
req.result.createObjectStore(STORE);
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
req.onsuccess = () => resolve(req.result);
|
|
122
|
+
req.onerror = () => reject(req.error ?? new Error("IndexedDB open failed"));
|
|
123
|
+
req.onblocked = () => reject(new Error("IndexedDB open blocked"));
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
function done(tx) {
|
|
127
|
+
return new Promise((resolve, reject) => {
|
|
128
|
+
tx.oncomplete = () => resolve();
|
|
129
|
+
tx.onerror = () => reject(tx.error ?? new Error("IndexedDB transaction failed"));
|
|
130
|
+
tx.onabort = () => reject(tx.error ?? new Error("IndexedDB transaction aborted"));
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function source(bytes) {
|
|
134
|
+
return bytes;
|
|
135
|
+
}
|
|
136
|
+
function isBytes(value, length) {
|
|
137
|
+
return value instanceof Uint8Array && value.length === length;
|
|
138
|
+
}
|
|
139
|
+
function asItem(row) {
|
|
140
|
+
if (typeof row !== "object" || row === null) return null;
|
|
141
|
+
const item = row;
|
|
142
|
+
const key = item.key;
|
|
143
|
+
if (item.v !== 1 || !key || typeof key !== "object") return null;
|
|
144
|
+
if (key.type !== "secret" || key.extractable !== false) return null;
|
|
145
|
+
if (key.algorithm.name !== "AES-GCM" || key.algorithm.length !== 256) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
if (!isBytes(item.iv, NONCE_LEN) || !isBytes(item.ciphertext, WRAPPED_LEN)) return null;
|
|
149
|
+
if (!isBytes(item.rootPublicKey, PUBLIC_KEY_LEN)) return null;
|
|
150
|
+
return item;
|
|
151
|
+
}
|
|
152
|
+
async function associatedData(subtle, rootPublicKey) {
|
|
153
|
+
const label = new TextEncoder().encode(PENDING_ROOT_WRAP_LABEL);
|
|
154
|
+
const userId = new Uint8Array(await subtle.digest("SHA-256", source(rootPublicKey)));
|
|
155
|
+
const out = new Uint8Array(label.length + userId.length);
|
|
156
|
+
out.set(label, 0);
|
|
157
|
+
out.set(userId, label.length);
|
|
158
|
+
return out;
|
|
159
|
+
}
|
|
160
|
+
async function load(idb, slot) {
|
|
161
|
+
if (typeof idb.databases === "function") {
|
|
162
|
+
const names = (await idb.databases()).map((info) => info.name);
|
|
163
|
+
if (!names.includes(pendingRootDatabaseName(slot))) return null;
|
|
164
|
+
}
|
|
165
|
+
const db = await open(idb, slot);
|
|
166
|
+
try {
|
|
167
|
+
const tx = db.transaction(STORE, "readonly");
|
|
168
|
+
const row = await request(tx.objectStore(STORE).get(ITEM_KEY));
|
|
169
|
+
return asItem(row);
|
|
170
|
+
} finally {
|
|
171
|
+
db.close();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
var PendingRootStore = class {
|
|
175
|
+
/**
|
|
176
|
+
* Wrap `seed` and keep it for `slot`, with the root public key and the
|
|
177
|
+
* browser's answer to the persistent-storage request beside it. `seed` is
|
|
178
|
+
* zero-filled before this resolves or rejects.
|
|
179
|
+
*
|
|
180
|
+
* Create-if-absent and atomic: a slot that holds a row (an item, or a row
|
|
181
|
+
* that is not one) rejects with `PendingRootExistsError` and is unchanged.
|
|
182
|
+
*/
|
|
183
|
+
async write(slot, seed, rootPublicKey, persistentStorage) {
|
|
184
|
+
const { idb, subtle } = realm();
|
|
185
|
+
try {
|
|
186
|
+
if (!isBytes(seed, SEED_LEN) || !isBytes(rootPublicKey, PUBLIC_KEY_LEN)) {
|
|
187
|
+
throw new Error("pending root: wrong length");
|
|
188
|
+
}
|
|
189
|
+
const key = await subtle.generateKey({ name: "AES-GCM", length: 256 }, false, ["encrypt", "decrypt"]);
|
|
190
|
+
const iv = globalThis.crypto.getRandomValues(new Uint8Array(NONCE_LEN));
|
|
191
|
+
const publicKey = new Uint8Array(rootPublicKey);
|
|
192
|
+
const additionalData = await associatedData(subtle, publicKey);
|
|
193
|
+
const ciphertext = new Uint8Array(
|
|
194
|
+
await subtle.encrypt(
|
|
195
|
+
{ name: "AES-GCM", iv: source(iv), additionalData: source(additionalData), tagLength: TAG_BITS },
|
|
196
|
+
key,
|
|
197
|
+
source(seed)
|
|
198
|
+
)
|
|
199
|
+
);
|
|
200
|
+
const item = {
|
|
201
|
+
v: 1,
|
|
202
|
+
key,
|
|
203
|
+
iv,
|
|
204
|
+
ciphertext,
|
|
205
|
+
rootPublicKey: publicKey,
|
|
206
|
+
persistentStorage: persistentStorage ?? null
|
|
207
|
+
};
|
|
208
|
+
const db = await open(idb, slot);
|
|
209
|
+
try {
|
|
210
|
+
const tx = db.transaction(STORE, "readwrite");
|
|
211
|
+
const added = tx.objectStore(STORE).add(item, ITEM_KEY);
|
|
212
|
+
try {
|
|
213
|
+
await done(tx);
|
|
214
|
+
} catch (failed) {
|
|
215
|
+
if (added.error?.name === "ConstraintError") throw new PendingRootExistsError();
|
|
216
|
+
throw failed;
|
|
217
|
+
}
|
|
218
|
+
} finally {
|
|
219
|
+
db.close();
|
|
220
|
+
}
|
|
221
|
+
} finally {
|
|
222
|
+
seed.fill(0);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/** The root public key beside the item of `slot`, or `null`. No unwrap. */
|
|
226
|
+
async publicKey(slot) {
|
|
227
|
+
const { idb } = realm();
|
|
228
|
+
const item = await load(idb, slot);
|
|
229
|
+
return item ? new Uint8Array(item.rootPublicKey) : null;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* The seed of `slot`, unwrapped, or `null` when the slot holds no item
|
|
233
|
+
* or holds one that does not open with its own key object (a browser has
|
|
234
|
+
* no lock that could make that a passing state: such an item is gone).
|
|
235
|
+
* The caller zero-fills what it is given.
|
|
236
|
+
*/
|
|
237
|
+
async read(slot) {
|
|
238
|
+
const { idb, subtle } = realm();
|
|
239
|
+
const item = await load(idb, slot);
|
|
240
|
+
if (!item) return null;
|
|
241
|
+
const additionalData = await associatedData(subtle, item.rootPublicKey);
|
|
242
|
+
try {
|
|
243
|
+
const seed = await subtle.decrypt(
|
|
244
|
+
{ name: "AES-GCM", iv: source(item.iv), additionalData: source(additionalData), tagLength: TAG_BITS },
|
|
245
|
+
item.key,
|
|
246
|
+
source(item.ciphertext)
|
|
247
|
+
);
|
|
248
|
+
return new Uint8Array(seed);
|
|
249
|
+
} catch {
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
/** Delete the item of `slot`: the ciphertext and the key object, and their database. */
|
|
254
|
+
async del(slot) {
|
|
255
|
+
const { idb } = realm();
|
|
256
|
+
await new Promise((resolve, reject) => {
|
|
257
|
+
const req = idb.deleteDatabase(pendingRootDatabaseName(slot));
|
|
258
|
+
req.onsuccess = () => resolve();
|
|
259
|
+
req.onerror = () => reject(req.error ?? new Error("IndexedDB delete failed"));
|
|
260
|
+
req.onblocked = () => reject(new Error("IndexedDB delete blocked"));
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
/** The browser's answer to the persistent-storage request recorded beside the item, or `null`. */
|
|
264
|
+
async persistentStorage(slot) {
|
|
265
|
+
const { idb } = realm();
|
|
266
|
+
const item = await load(idb, slot);
|
|
267
|
+
return item ? item.persistentStorage : null;
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
|
|
51
271
|
// src/epoch-events.ts
|
|
52
272
|
function conversationKey(id) {
|
|
53
273
|
let out = "";
|
|
@@ -187,6 +407,51 @@ var RequestScheduler = class {
|
|
|
187
407
|
// src/worker.ts
|
|
188
408
|
var client = null;
|
|
189
409
|
var wasmReady = null;
|
|
410
|
+
var pendingRootStore = null;
|
|
411
|
+
var setupSession = null;
|
|
412
|
+
var ranAccountSetup = false;
|
|
413
|
+
function accountWorker() {
|
|
414
|
+
if (client) throw new Error("account refused: client-worker");
|
|
415
|
+
ranAccountSetup = true;
|
|
416
|
+
}
|
|
417
|
+
var ACCOUNT_LOCK_NAME = "ping-account-operations";
|
|
418
|
+
function accountExclusive(run) {
|
|
419
|
+
accountWorker();
|
|
420
|
+
const locks = globalThis.navigator?.locks;
|
|
421
|
+
if (!locks || typeof locks.request !== "function") {
|
|
422
|
+
return Promise.reject(new Error("account refused: pending-store-unavailable"));
|
|
423
|
+
}
|
|
424
|
+
return locks.request(ACCOUNT_LOCK_NAME, run);
|
|
425
|
+
}
|
|
426
|
+
function pendingStore() {
|
|
427
|
+
accountWorker();
|
|
428
|
+
pendingRootStore ??= new PendingRootStore();
|
|
429
|
+
return pendingRootStore;
|
|
430
|
+
}
|
|
431
|
+
function openSession() {
|
|
432
|
+
accountWorker();
|
|
433
|
+
if (!setupSession) throw new Error("account refused: setup-session-ended");
|
|
434
|
+
return setupSession;
|
|
435
|
+
}
|
|
436
|
+
function clientWorker() {
|
|
437
|
+
if (ranAccountSetup) {
|
|
438
|
+
throw new Error("this worker ran account set-up: a client starts in a worker of its own");
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
var tabClient = false;
|
|
442
|
+
function rotationBuild(run) {
|
|
443
|
+
const running = client;
|
|
444
|
+
if (!running) return Promise.reject(new Error("account refused: no-client"));
|
|
445
|
+
if (!tabClient) return Promise.reject(new Error("account refused: background-worker"));
|
|
446
|
+
const locks = globalThis.navigator?.locks;
|
|
447
|
+
if (!locks || typeof locks.request !== "function") {
|
|
448
|
+
return Promise.reject(new Error("account refused: pending-store-unavailable"));
|
|
449
|
+
}
|
|
450
|
+
return locks.request(ACCOUNT_LOCK_NAME, () => run(running));
|
|
451
|
+
}
|
|
452
|
+
function wipe(bytes) {
|
|
453
|
+
if (bytes instanceof Uint8Array) bytes.fill(0);
|
|
454
|
+
}
|
|
190
455
|
var pendingStorage = /* @__PURE__ */ new Map();
|
|
191
456
|
var pendingTransport = /* @__PURE__ */ new Map();
|
|
192
457
|
var nextStorageId = 1;
|
|
@@ -229,7 +494,28 @@ function makeProxyTransport(features) {
|
|
|
229
494
|
return {
|
|
230
495
|
...proxyTransport,
|
|
231
496
|
...features.fetchLogSince ? { fetchLogSince: fetchLogSinceProxy } : {},
|
|
232
|
-
...features.fetchLogHeads ? { fetchLogHeads: fetchLogHeadsProxy } : {}
|
|
497
|
+
...features.fetchLogHeads ? { fetchLogHeads: fetchLogHeadsProxy } : {},
|
|
498
|
+
// Self-admission: declared only when the host has them, like the two
|
|
499
|
+
// above (absent, the wasm bridge answers the core's default: no route).
|
|
500
|
+
...features.sendExternalCommit ? {
|
|
501
|
+
sendExternalCommit: (envelope) => callMain("transport", "sendExternalCommit", [envelope])
|
|
502
|
+
} : {},
|
|
503
|
+
...features.fetchSelfAdmissionStates ? {
|
|
504
|
+
fetchSelfAdmissionStates: (conversations, unusable) => callMain("transport", "fetchSelfAdmissionStates", [conversations, unusable ?? []])
|
|
505
|
+
} : {},
|
|
506
|
+
...features.fetchSealedGroupInfos ? {
|
|
507
|
+
fetchSealedGroupInfos: (conversations) => callMain("transport", "fetchSealedGroupInfos", [conversations])
|
|
508
|
+
} : {},
|
|
509
|
+
...features.sendExternalCommits ? {
|
|
510
|
+
sendExternalCommits: (envelopes) => callMain("transport", "sendExternalCommits", [envelopes])
|
|
511
|
+
} : {},
|
|
512
|
+
// The publishing half (ruling V320), declared like the four.
|
|
513
|
+
...features.fetchSealingStatements ? {
|
|
514
|
+
fetchSealingStatements: (accounts, conversation) => callMain("transport", "fetchSealingStatements", [accounts, conversation])
|
|
515
|
+
} : {},
|
|
516
|
+
...features.publishSealedGroupInfo ? {
|
|
517
|
+
publishSealedGroupInfo: (publication) => callMain("transport", "publishSealedGroupInfo", [publication])
|
|
518
|
+
} : {}
|
|
233
519
|
};
|
|
234
520
|
}
|
|
235
521
|
function callMain(kind, method, args) {
|
|
@@ -264,13 +550,15 @@ var EPOCH_ADVANCING_REQUESTS = /* @__PURE__ */ new Set([
|
|
|
264
550
|
"revokeDevice",
|
|
265
551
|
"removeDeviceEverywhere",
|
|
266
552
|
"removeOwnDevicesExcept",
|
|
553
|
+
"addRestoredDevice",
|
|
267
554
|
"syncConversations",
|
|
268
555
|
"syncConversation",
|
|
269
|
-
"
|
|
556
|
+
"completeDeviceLink",
|
|
557
|
+
"recreateDeviceGroup",
|
|
270
558
|
"importStateSnapshot"
|
|
271
559
|
]);
|
|
272
560
|
var EPOCH_UPKEEP_REQUESTS = /* @__PURE__ */ new Set([
|
|
273
|
-
"
|
|
561
|
+
"buildLinkingTicketV3For"
|
|
274
562
|
]);
|
|
275
563
|
function readMeta(id) {
|
|
276
564
|
if (!client) return null;
|
|
@@ -316,11 +604,11 @@ function refreshCached(ids) {
|
|
|
316
604
|
const metas = readMetas(ids);
|
|
317
605
|
const held = [];
|
|
318
606
|
const dropped = [];
|
|
319
|
-
const
|
|
607
|
+
const done2 = /* @__PURE__ */ new Set();
|
|
320
608
|
for (const id of ids) {
|
|
321
609
|
const key = conversationKey(id);
|
|
322
|
-
if (
|
|
323
|
-
|
|
610
|
+
if (done2.has(key)) continue;
|
|
611
|
+
done2.add(key);
|
|
324
612
|
const meta = metas.get(key) ?? null;
|
|
325
613
|
if (meta !== null) held.push(meta);
|
|
326
614
|
else dropped.push(id);
|
|
@@ -554,34 +842,49 @@ function catchUpPassStepper(msg) {
|
|
|
554
842
|
return pass();
|
|
555
843
|
};
|
|
556
844
|
}
|
|
845
|
+
var PHRASE_KINDS = /* @__PURE__ */ new Set([
|
|
846
|
+
"makeBackup",
|
|
847
|
+
"proveBackup",
|
|
848
|
+
"openBackupForRestore",
|
|
849
|
+
"restoreTakeOver",
|
|
850
|
+
"restoreJoin",
|
|
851
|
+
"setupSessionMakeBackup",
|
|
852
|
+
"setupSessionProveBackup"
|
|
853
|
+
]);
|
|
557
854
|
async function dispatch(msg) {
|
|
855
|
+
if (!PHRASE_KINDS.has(msg.kind)) return dispatchRequest(msg);
|
|
856
|
+
const carried = msg;
|
|
857
|
+
if (!(carried.phrase instanceof Uint8Array)) carried.phrase = new Uint8Array();
|
|
858
|
+
const phrase = carried.phrase;
|
|
859
|
+
try {
|
|
860
|
+
return await dispatchRequest(msg);
|
|
861
|
+
} finally {
|
|
862
|
+
wipe(phrase);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
async function dispatchRequest(msg) {
|
|
558
866
|
await ensureWasm();
|
|
559
867
|
switch (msg.kind) {
|
|
560
|
-
case "
|
|
868
|
+
case "initFromDeviceRecord": {
|
|
869
|
+
clientWorker();
|
|
561
870
|
transportFeatures = msg.transportFeatures ?? { fetchLogSince: false, fetchLogHeads: false };
|
|
562
|
-
client = await PingClient.
|
|
563
|
-
msg.identityExport,
|
|
871
|
+
client = await PingClient.initFromDeviceRecord(
|
|
564
872
|
msg.deviceLabel,
|
|
565
873
|
makeProxyStorage(msg.storageFeatures),
|
|
566
874
|
makeProxyTransport(transportFeatures),
|
|
567
875
|
msg.nowMs,
|
|
568
|
-
// Optional Ed25519 device signing secret — see protocol.ts
|
|
569
|
-
// and ClientConfig.deviceSigningSecretKey. Forwarding `null`
|
|
570
|
-
// explicitly when absent so the wasm-bindgen `Option<Vec<u8>>`
|
|
571
|
-
// shape is matched correctly.
|
|
572
876
|
msg.deviceSigningSecretKey ?? null,
|
|
573
|
-
// The owner each conversation's FIRST roles write must name
|
|
574
|
-
// (2026-11-04, round 2); `null` for none.
|
|
575
877
|
msg.expectedOwners ?? null
|
|
576
878
|
);
|
|
879
|
+
tabClient = msg.tabClient === true;
|
|
577
880
|
client.onMessage((m) => {
|
|
578
881
|
self.postMessage({ kind: "event.message", msg: m });
|
|
579
882
|
});
|
|
580
883
|
return null;
|
|
581
884
|
}
|
|
582
|
-
case "
|
|
583
|
-
|
|
584
|
-
|
|
885
|
+
case "openReadOnlyFromDeviceRecord": {
|
|
886
|
+
clientWorker();
|
|
887
|
+
client = await PingClient.openReadOnlyFromDeviceRecord(
|
|
585
888
|
msg.deviceLabel,
|
|
586
889
|
makeProxyStorage(msg.storageFeatures),
|
|
587
890
|
proxyTransport,
|
|
@@ -589,6 +892,318 @@ async function dispatch(msg) {
|
|
|
589
892
|
);
|
|
590
893
|
return null;
|
|
591
894
|
}
|
|
895
|
+
// The device link under the root design. `beginDeviceLink` starts a NEW
|
|
896
|
+
// device's staging client: the wasm draws the device key, and the client
|
|
897
|
+
// it answers becomes this worker's client until the link is complete.
|
|
898
|
+
case "beginDeviceLink": {
|
|
899
|
+
clientWorker();
|
|
900
|
+
transportFeatures = msg.transportFeatures ?? { fetchLogSince: false, fetchLogHeads: false };
|
|
901
|
+
const begun = await wasmBeginDeviceLink(
|
|
902
|
+
msg.deviceLabel,
|
|
903
|
+
makeProxyStorage(msg.storageFeatures),
|
|
904
|
+
makeProxyTransport(transportFeatures),
|
|
905
|
+
msg.nowMs
|
|
906
|
+
);
|
|
907
|
+
try {
|
|
908
|
+
client = begun.takeClient();
|
|
909
|
+
client.onMessage((m) => {
|
|
910
|
+
self.postMessage({ kind: "event.message", msg: m });
|
|
911
|
+
});
|
|
912
|
+
return {
|
|
913
|
+
payload: begun.payload,
|
|
914
|
+
deviceId: begun.deviceId,
|
|
915
|
+
deviceSigningSecretKey: begun.deviceSigningSecretKey,
|
|
916
|
+
hpkeSecretKey: begun.hpkeSecretKey
|
|
917
|
+
};
|
|
918
|
+
} finally {
|
|
919
|
+
begun.free();
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
case "buildLinkingTicketV3For":
|
|
923
|
+
return await ensureClient().buildLinkingTicketV3For(
|
|
924
|
+
msg.payload,
|
|
925
|
+
msg.expectedCode,
|
|
926
|
+
msg.expectedQr,
|
|
927
|
+
msg.lastAppEvents,
|
|
928
|
+
msg.nowMs
|
|
929
|
+
);
|
|
930
|
+
case "linkGenerationFor":
|
|
931
|
+
return ensureClient().linkGenerationFor(msg.payload, msg.expectedCode, msg.expectedQr);
|
|
932
|
+
case "recreateDeviceGroup":
|
|
933
|
+
await ensureClient().recreateDeviceGroup(msg.nowMs);
|
|
934
|
+
return null;
|
|
935
|
+
// The rotation in a client's Worker. The plan, the answer and the
|
|
936
|
+
// adoption touch no root; the two builds open it for the length of the
|
|
937
|
+
// call (see `rotationBuild` above).
|
|
938
|
+
case "rotateGenerationWithPending":
|
|
939
|
+
return await rotationBuild((running) => running.rotateGenerationWithPending(
|
|
940
|
+
// The SDK's own store, for this one call: never a host's object.
|
|
941
|
+
new PendingRootStore(),
|
|
942
|
+
msg.slot,
|
|
943
|
+
msg.start,
|
|
944
|
+
msg.devices,
|
|
945
|
+
msg.kept,
|
|
946
|
+
msg.reason,
|
|
947
|
+
msg.accountId,
|
|
948
|
+
msg.hostState,
|
|
949
|
+
msg.nowMs
|
|
950
|
+
));
|
|
951
|
+
case "rotateGenerationWithBackup": {
|
|
952
|
+
try {
|
|
953
|
+
if (!(msg.phrase instanceof Uint8Array)) throw new Error("account refused: invalid-phrase");
|
|
954
|
+
if (msg.newPhrase !== void 0 && !(msg.newPhrase instanceof Uint8Array)) {
|
|
955
|
+
throw new Error("account refused: invalid-phrase");
|
|
956
|
+
}
|
|
957
|
+
return await rotationBuild((running) => running.rotateGenerationWithBackup(
|
|
958
|
+
msg.rootPart,
|
|
959
|
+
msg.phrase,
|
|
960
|
+
msg.newPhrase,
|
|
961
|
+
msg.start,
|
|
962
|
+
msg.devices,
|
|
963
|
+
msg.kept,
|
|
964
|
+
msg.reason,
|
|
965
|
+
msg.accountId,
|
|
966
|
+
msg.hostState,
|
|
967
|
+
msg.nowMs
|
|
968
|
+
));
|
|
969
|
+
} finally {
|
|
970
|
+
wipe(msg.phrase);
|
|
971
|
+
wipe(msg.newPhrase);
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
case "planRotation":
|
|
975
|
+
return await ensureClient().planRotation(msg.start, msg.devices, msg.rootPartGeneration);
|
|
976
|
+
case "completeRotationOnClient":
|
|
977
|
+
return await ensureClient().completeRotation(msg.recordId, msg.answer);
|
|
978
|
+
case "adoptGeneration":
|
|
979
|
+
return await ensureClient().adoptGeneration(
|
|
980
|
+
msg.generation,
|
|
981
|
+
msg.credential,
|
|
982
|
+
msg.gsWrap,
|
|
983
|
+
msg.statement,
|
|
984
|
+
msg.nowMs
|
|
985
|
+
);
|
|
986
|
+
case "completeDeviceLink":
|
|
987
|
+
return await ensureClient().completeDeviceLink(
|
|
988
|
+
msg.ticket,
|
|
989
|
+
msg.generation,
|
|
990
|
+
msg.generationSecret,
|
|
991
|
+
msg.nowMs
|
|
992
|
+
);
|
|
993
|
+
case "sealLinkingTicketV3For":
|
|
994
|
+
return wasmSealLinkingTicketV3For(msg.ticket, msg.payload, msg.expectedCode, msg.expectedQr);
|
|
995
|
+
case "openLinkingTicketV3":
|
|
996
|
+
return wasmOpenLinkingTicketV3(msg.sealed, msg.newDevicePriv);
|
|
997
|
+
case "heldCredential":
|
|
998
|
+
return ensureClient().heldCredential();
|
|
999
|
+
case "heldGeneration":
|
|
1000
|
+
return ensureClient().heldGeneration();
|
|
1001
|
+
// Account set-up and the first backup: see the note at the top of this
|
|
1002
|
+
// file. The store is asked for FIRST, so a client's worker refuses
|
|
1003
|
+
// before anything else runs.
|
|
1004
|
+
case "createAccount": {
|
|
1005
|
+
return accountExclusive(async () => {
|
|
1006
|
+
const store = pendingStore();
|
|
1007
|
+
return wasmCreateAccount(
|
|
1008
|
+
makeProxyStorage(msg.storageFeatures),
|
|
1009
|
+
store,
|
|
1010
|
+
msg.slot,
|
|
1011
|
+
msg.identityState,
|
|
1012
|
+
msg.persistentStorage,
|
|
1013
|
+
msg.nowMs
|
|
1014
|
+
);
|
|
1015
|
+
});
|
|
1016
|
+
}
|
|
1017
|
+
case "pendingStatus": {
|
|
1018
|
+
const store = pendingStore();
|
|
1019
|
+
return wasmPendingStatus(
|
|
1020
|
+
makeProxyStorage(msg.storageFeatures),
|
|
1021
|
+
store,
|
|
1022
|
+
msg.slot
|
|
1023
|
+
);
|
|
1024
|
+
}
|
|
1025
|
+
case "makeBackup": {
|
|
1026
|
+
return accountExclusive(async () => {
|
|
1027
|
+
const store = pendingStore();
|
|
1028
|
+
return wasmMakeBackup(
|
|
1029
|
+
makeProxyStorage(msg.storageFeatures),
|
|
1030
|
+
store,
|
|
1031
|
+
msg.slot,
|
|
1032
|
+
msg.phrase,
|
|
1033
|
+
msg.accountId,
|
|
1034
|
+
msg.hostState,
|
|
1035
|
+
msg.nowMs
|
|
1036
|
+
);
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
case "proveBackup": {
|
|
1040
|
+
return accountExclusive(async () => {
|
|
1041
|
+
accountWorker();
|
|
1042
|
+
return wasmProveBackup(
|
|
1043
|
+
makeProxyStorage(msg.storageFeatures),
|
|
1044
|
+
msg.readBackRootPart,
|
|
1045
|
+
msg.phrase
|
|
1046
|
+
);
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
case "endPending": {
|
|
1050
|
+
return accountExclusive(async () => {
|
|
1051
|
+
const store = pendingStore();
|
|
1052
|
+
await wasmEndPending(
|
|
1053
|
+
makeProxyStorage(msg.storageFeatures),
|
|
1054
|
+
store,
|
|
1055
|
+
msg.slot,
|
|
1056
|
+
msg.fingerprint
|
|
1057
|
+
);
|
|
1058
|
+
return null;
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
// The restore as a rotation: the same Worker that never runs a client.
|
|
1062
|
+
case "openBackupForRestore": {
|
|
1063
|
+
accountWorker();
|
|
1064
|
+
return wasmOpenBackupForRestore(msg.rootPart, msg.phrase, msg.statePart, msg.pinnedRootPublicKey);
|
|
1065
|
+
}
|
|
1066
|
+
case "restoreTakeOver": {
|
|
1067
|
+
return accountExclusive(async () => {
|
|
1068
|
+
accountWorker();
|
|
1069
|
+
return wasmRestoreTakeOver(
|
|
1070
|
+
makeProxyStorage(msg.storageFeatures),
|
|
1071
|
+
msg.rootPart,
|
|
1072
|
+
msg.phrase,
|
|
1073
|
+
msg.start,
|
|
1074
|
+
msg.oldStatePart,
|
|
1075
|
+
msg.accountId,
|
|
1076
|
+
msg.hostState,
|
|
1077
|
+
msg.nowMs
|
|
1078
|
+
);
|
|
1079
|
+
});
|
|
1080
|
+
}
|
|
1081
|
+
case "takeAccountBack": {
|
|
1082
|
+
return accountExclusive(async () => {
|
|
1083
|
+
const store = pendingStore();
|
|
1084
|
+
return wasmTakeAccountBack(
|
|
1085
|
+
makeProxyStorage(msg.storageFeatures),
|
|
1086
|
+
store,
|
|
1087
|
+
msg.slot,
|
|
1088
|
+
msg.start,
|
|
1089
|
+
msg.oldStatePart,
|
|
1090
|
+
msg.accountId,
|
|
1091
|
+
msg.hostState,
|
|
1092
|
+
msg.nowMs
|
|
1093
|
+
);
|
|
1094
|
+
});
|
|
1095
|
+
}
|
|
1096
|
+
case "resumeRotation": {
|
|
1097
|
+
accountWorker();
|
|
1098
|
+
if (msg.nowMs === void 0) {
|
|
1099
|
+
return wasmResumeRotation(makeProxyStorage(msg.storageFeatures));
|
|
1100
|
+
}
|
|
1101
|
+
return wasmResumeRotationAt(makeProxyStorage(msg.storageFeatures), msg.nowMs);
|
|
1102
|
+
}
|
|
1103
|
+
case "completeRotation": {
|
|
1104
|
+
return accountExclusive(async () => {
|
|
1105
|
+
accountWorker();
|
|
1106
|
+
return wasmCompleteRotation(
|
|
1107
|
+
makeProxyStorage(msg.storageFeatures),
|
|
1108
|
+
msg.recordId,
|
|
1109
|
+
msg.answer
|
|
1110
|
+
);
|
|
1111
|
+
});
|
|
1112
|
+
}
|
|
1113
|
+
case "setRotationPhase": {
|
|
1114
|
+
return accountExclusive(async () => {
|
|
1115
|
+
accountWorker();
|
|
1116
|
+
await wasmSetRotationPhase(makeProxyStorage(msg.storageFeatures), msg.recordId, msg.phase);
|
|
1117
|
+
return null;
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
case "finishRotation": {
|
|
1121
|
+
return accountExclusive(async () => {
|
|
1122
|
+
accountWorker();
|
|
1123
|
+
await wasmFinishRotation(makeProxyStorage(msg.storageFeatures), msg.recordId);
|
|
1124
|
+
return null;
|
|
1125
|
+
});
|
|
1126
|
+
}
|
|
1127
|
+
case "abandonRotation": {
|
|
1128
|
+
return accountExclusive(async () => {
|
|
1129
|
+
accountWorker();
|
|
1130
|
+
await wasmAbandonRotation(makeProxyStorage(msg.storageFeatures), msg.recordId);
|
|
1131
|
+
return null;
|
|
1132
|
+
});
|
|
1133
|
+
}
|
|
1134
|
+
case "rotationRecordState": {
|
|
1135
|
+
accountWorker();
|
|
1136
|
+
return wasmRotationRecordState(makeProxyStorage(msg.storageFeatures));
|
|
1137
|
+
}
|
|
1138
|
+
case "restoreJoin": {
|
|
1139
|
+
return accountExclusive(async () => {
|
|
1140
|
+
accountWorker();
|
|
1141
|
+
return wasmRestoreJoin(
|
|
1142
|
+
makeProxyStorage(msg.storageFeatures),
|
|
1143
|
+
msg.rootPart,
|
|
1144
|
+
msg.phrase,
|
|
1145
|
+
msg.statePart,
|
|
1146
|
+
msg.start,
|
|
1147
|
+
msg.nowMs
|
|
1148
|
+
);
|
|
1149
|
+
});
|
|
1150
|
+
}
|
|
1151
|
+
case "openStateBackup": {
|
|
1152
|
+
accountWorker();
|
|
1153
|
+
return wasmOpenStateBackup(makeProxyStorage(msg.storageFeatures), msg.statePart);
|
|
1154
|
+
}
|
|
1155
|
+
case "refreshStateBackup": {
|
|
1156
|
+
return accountExclusive(async () => {
|
|
1157
|
+
accountWorker();
|
|
1158
|
+
return wasmRefreshStateBackup(
|
|
1159
|
+
makeProxyStorage(msg.storageFeatures),
|
|
1160
|
+
msg.accountId,
|
|
1161
|
+
msg.hostState,
|
|
1162
|
+
msg.nowMs
|
|
1163
|
+
);
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1166
|
+
case "beginAccountSetupInMemory": {
|
|
1167
|
+
accountWorker();
|
|
1168
|
+
if (setupSession) throw new Error("account refused: setup-session-open");
|
|
1169
|
+
setupSession = wasmBeginAccountSetupInMemory(msg.identityState, msg.nowMs);
|
|
1170
|
+
return null;
|
|
1171
|
+
}
|
|
1172
|
+
case "setupSessionMakeBackup":
|
|
1173
|
+
return openSession().makeBackup(msg.phrase, msg.accountId, msg.hostState, msg.nowMs);
|
|
1174
|
+
case "setupSessionProveBackup":
|
|
1175
|
+
return openSession().proveBackup(msg.readBackRootPart, msg.phrase);
|
|
1176
|
+
case "setupSessionFinish": {
|
|
1177
|
+
return accountExclusive(async () => {
|
|
1178
|
+
const session = openSession();
|
|
1179
|
+
const made = await session.finish(makeProxyStorage(msg.storageFeatures));
|
|
1180
|
+
session.free();
|
|
1181
|
+
setupSession = null;
|
|
1182
|
+
return made;
|
|
1183
|
+
});
|
|
1184
|
+
}
|
|
1185
|
+
case "setupSessionKeepAsPending": {
|
|
1186
|
+
return accountExclusive(async () => {
|
|
1187
|
+
const session = openSession();
|
|
1188
|
+
const store = pendingStore();
|
|
1189
|
+
const made = await session.keepAsPending(
|
|
1190
|
+
makeProxyStorage(msg.storageFeatures),
|
|
1191
|
+
store,
|
|
1192
|
+
msg.slot,
|
|
1193
|
+
msg.persistentStorage
|
|
1194
|
+
);
|
|
1195
|
+
session.free();
|
|
1196
|
+
setupSession = null;
|
|
1197
|
+
return made;
|
|
1198
|
+
});
|
|
1199
|
+
}
|
|
1200
|
+
case "endAccountSetupSession": {
|
|
1201
|
+
if (setupSession) {
|
|
1202
|
+
setupSession.free();
|
|
1203
|
+
setupSession = null;
|
|
1204
|
+
}
|
|
1205
|
+
return null;
|
|
1206
|
+
}
|
|
592
1207
|
case "previewEnvelope":
|
|
593
1208
|
return ensureClient().previewEnvelope(msg.envelope, msg.nowMs);
|
|
594
1209
|
case "previewEnvelopeWithPrerequisites":
|
|
@@ -597,16 +1212,8 @@ async function dispatch(msg) {
|
|
|
597
1212
|
msg.envelope,
|
|
598
1213
|
msg.nowMs
|
|
599
1214
|
);
|
|
600
|
-
case "generateIdentity":
|
|
601
|
-
return PingClient.generateIdentity();
|
|
602
1215
|
case "userId":
|
|
603
1216
|
return ensureClient().userId();
|
|
604
|
-
case "exportIdentity":
|
|
605
|
-
return ensureClient().exportIdentity();
|
|
606
|
-
case "rotateIdentity":
|
|
607
|
-
return await ensureClient().rotateIdentity(msg.newIdentityExport, msg.nowMs);
|
|
608
|
-
case "rotateIdentityRetry":
|
|
609
|
-
return await ensureClient().rotateIdentityRetry(msg.conv, msg.nowMs);
|
|
610
1217
|
case "deviceId":
|
|
611
1218
|
return ensureClient().deviceId();
|
|
612
1219
|
case "suspendStorage":
|
|
@@ -695,6 +1302,9 @@ async function dispatch(msg) {
|
|
|
695
1302
|
return await ensureClient().removeDeviceEverywhere(msg.deviceId, msg.nowMs);
|
|
696
1303
|
case "removeOwnDevicesExcept":
|
|
697
1304
|
return await ensureClient().removeOwnDevicesExcept(msg.keep, msg.listed, msg.nowMs);
|
|
1305
|
+
case "addRestoredDevice":
|
|
1306
|
+
await ensureClient().addRestoredDevice(msg.deviceId, msg.keyPackage, msg.nowMs);
|
|
1307
|
+
return null;
|
|
698
1308
|
case "processEnvelope": {
|
|
699
1309
|
const result = await ensureClient().processEnvelope(msg.envelope, msg.nowMs);
|
|
700
1310
|
postConversationEvent(
|
|
@@ -717,6 +1327,20 @@ async function dispatch(msg) {
|
|
|
717
1327
|
// (the wasm does not fan them out through `onMessage`); the main thread
|
|
718
1328
|
// delivers them from the result. Conversation updates are announced from
|
|
719
1329
|
// the core's exact `updated` list, before the result resolves.
|
|
1330
|
+
// Self-admission (ruling V273): every refusal is a value of the answer.
|
|
1331
|
+
case "selfAdmit":
|
|
1332
|
+
return ensureClient().selfAdmit(
|
|
1333
|
+
msg.conv,
|
|
1334
|
+
msg.fetched.blob,
|
|
1335
|
+
msg.fetched.wrap,
|
|
1336
|
+
msg.fetched.wrapCount,
|
|
1337
|
+
msg.fetched.currentEpoch,
|
|
1338
|
+
msg.nowMs
|
|
1339
|
+
);
|
|
1340
|
+
case "selfAdmitMany":
|
|
1341
|
+
return ensureClient().selfAdmitMany(msg.first, msg.conversations, msg.nowMs);
|
|
1342
|
+
case "clientRefreshStateBackup":
|
|
1343
|
+
return ensureClient().refreshStateBackup(msg.accountId, msg.hostState, msg.nowMs);
|
|
720
1344
|
case "processSequencedBatch": {
|
|
721
1345
|
const raw = await ensureClient().processSequencedBatch(msg.items, msg.nowMs);
|
|
722
1346
|
announceUpdated(raw.updated, welcomeSenders(msg.items, raw.joined), raw.removed);
|
|
@@ -733,6 +1357,10 @@ async function dispatch(msg) {
|
|
|
733
1357
|
return ensureClient().logPosition(msg.conv);
|
|
734
1358
|
case "adoptLogPosition":
|
|
735
1359
|
return await ensureClient().adoptLogPosition(msg.conv, msg.epoch, msg.serverSeq);
|
|
1360
|
+
case "logHoles":
|
|
1361
|
+
return ensureClient().logHoles(msg.conv);
|
|
1362
|
+
case "resolveLogHole":
|
|
1363
|
+
return await ensureClient().resolveLogHole(msg.conv, msg.fromServerSeq, msg.toServerSeq);
|
|
736
1364
|
case "conversationsBehind":
|
|
737
1365
|
return ensureClient().conversationsBehind(msg.heads);
|
|
738
1366
|
case "heldFrameCount":
|
|
@@ -750,16 +1378,8 @@ async function dispatch(msg) {
|
|
|
750
1378
|
}
|
|
751
1379
|
return null;
|
|
752
1380
|
}
|
|
753
|
-
case "
|
|
754
|
-
return
|
|
755
|
-
msg.newDeviceId,
|
|
756
|
-
msg.newDeviceKp,
|
|
757
|
-
msg.lastAppEvents,
|
|
758
|
-
msg.nowMs
|
|
759
|
-
);
|
|
760
|
-
case "consumeLinkingTicket":
|
|
761
|
-
await ensureClient().consumeLinkingTicket(msg.ticket, msg.nowMs);
|
|
762
|
-
return null;
|
|
1381
|
+
case "linkHandshakePayload":
|
|
1382
|
+
return ensureClient().linkHandshakePayload(msg.hpkePublicKey, msg.keyPackage);
|
|
763
1383
|
case "decodeCatchupSnapshot":
|
|
764
1384
|
return wasmDecodeCatchupSnapshot(msg.snapshotBytes);
|
|
765
1385
|
case "exportConversationSecret":
|
|
@@ -776,10 +1396,18 @@ async function dispatch(msg) {
|
|
|
776
1396
|
msg.context,
|
|
777
1397
|
msg.length
|
|
778
1398
|
);
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
case "
|
|
782
|
-
return
|
|
1399
|
+
// The link handshake commitment (2026-11-25): pure WASM, no client state.
|
|
1400
|
+
// Each call that acts on a handshake verifies it inside the call.
|
|
1401
|
+
case "linkCommitment":
|
|
1402
|
+
return wasmLinkCommitment(msg.payload);
|
|
1403
|
+
case "normalizeLinkCode":
|
|
1404
|
+
return wasmNormalizeLinkCode(msg.typed);
|
|
1405
|
+
case "linkQrCommitment":
|
|
1406
|
+
return wasmLinkQrCommitment(msg.qrText);
|
|
1407
|
+
case "verifyLinkHandshake":
|
|
1408
|
+
return wasmVerifyLinkHandshake(msg.payload, msg.expectedCode, msg.expectedQr);
|
|
1409
|
+
case "sealLinkAuthFor":
|
|
1410
|
+
return wasmSealLinkAuthFor(msg.plaintext, msg.payload, msg.expectedCode, msg.expectedQr);
|
|
783
1411
|
case "hpkeSeal":
|
|
784
1412
|
return wasmHpkeSeal(msg.plaintext, msg.recipientPub, msg.info);
|
|
785
1413
|
case "hpkeOpen":
|
|
@@ -791,10 +1419,6 @@ async function dispatch(msg) {
|
|
|
791
1419
|
case "hpkeGenerateKeypair":
|
|
792
1420
|
return wasmHpkeGenerateKeypair();
|
|
793
1421
|
// Post-quantum (X-Wing) twins: all pure WASM, no client state required.
|
|
794
|
-
case "sealLinkingTicketPq":
|
|
795
|
-
return wasmSealLinkingTicketPq(msg.ticket, msg.newDevicePub);
|
|
796
|
-
case "openLinkingTicketPq":
|
|
797
|
-
return wasmOpenLinkingTicketPq(msg.sealed, msg.newDevicePriv);
|
|
798
1422
|
case "hpkeSealPq":
|
|
799
1423
|
return wasmHpkeSealPq(msg.plaintext, msg.recipientPub, msg.info);
|
|
800
1424
|
case "hpkeOpenPq":
|
|
@@ -813,8 +1437,8 @@ async function dispatch(msg) {
|
|
|
813
1437
|
return wasmHpkePublicKeyFromPrivate(msg.privateKey);
|
|
814
1438
|
case "signDeviceReauth":
|
|
815
1439
|
return wasmSignDeviceReauth(msg.deviceSigningSecretKey, msg.challengeId, msg.nonce, msg.accountId, msg.audience);
|
|
816
|
-
case "
|
|
817
|
-
return
|
|
1440
|
+
case "signDeviceLinkApprovalFor":
|
|
1441
|
+
return wasmSignDeviceLinkApprovalFor(msg.deviceSigningSecretKey, msg.approvalSessionId, msg.accountId, msg.payload, msg.expectedCode, msg.expectedQr, msg.audience);
|
|
818
1442
|
case "signDeviceLinkPossession":
|
|
819
1443
|
return wasmSignDeviceLinkPossession(msg.deviceSigningSecretKey, msg.approvalSessionId, msg.accountId, msg.audience);
|
|
820
1444
|
case "exportConversationStateSnapshot":
|
|
@@ -824,32 +1448,44 @@ async function dispatch(msg) {
|
|
|
824
1448
|
// Recovery — all pure WASM; no client state required.
|
|
825
1449
|
case "generateMnemonicPhrase":
|
|
826
1450
|
return wasmGenerateMnemonicPhrase();
|
|
1451
|
+
case "selfAdmissionCompiled":
|
|
1452
|
+
return wasmSelfAdmissionCompiled();
|
|
827
1453
|
case "normalizeMnemonicPhrase":
|
|
828
1454
|
return wasmNormalizeMnemonicPhrase(msg.phrase);
|
|
829
|
-
case "
|
|
830
|
-
return
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
1455
|
+
case "checkBackupPhrase":
|
|
1456
|
+
return wasmCheckBackupPhrase(msg.blob, msg.mnemonicPhrase);
|
|
1457
|
+
// History, version 3 (rulings V88 to V92). The raw-key, seed-signed seals
|
|
1458
|
+
// and opens are gone: every call below runs in the client, which verifies
|
|
1459
|
+
// the recipient in its own tree (or the link handshake against what this
|
|
1460
|
+
// device was shown) before anything is signed or sealed.
|
|
1461
|
+
case "historyDeliveryKeyNextCounter":
|
|
1462
|
+
return await ensureClient().historyDeliveryKeyNextCounter(msg.counterFloor);
|
|
1463
|
+
case "publishHistoryDeliveryKey":
|
|
1464
|
+
return await ensureClient().publishHistoryDeliveryKey(msg.counterFloor);
|
|
1465
|
+
case "adoptHistoryDeliveryKeyCounter":
|
|
1466
|
+
return await ensureClient().adoptHistoryDeliveryKeyCounter(msg.stored);
|
|
1467
|
+
case "sealHistoryBundleV3":
|
|
1468
|
+
return await ensureClient().sealHistoryBundleV3(msg.bundle, msg.recipient, msg.ownAccount);
|
|
1469
|
+
case "sealLinkHistoryBundle":
|
|
1470
|
+
return ensureClient().sealLinkHistoryBundle(
|
|
1471
|
+
msg.bundle,
|
|
1472
|
+
msg.payload,
|
|
1473
|
+
msg.expectedCode,
|
|
1474
|
+
msg.expectedQr
|
|
842
1475
|
);
|
|
843
|
-
case "
|
|
844
|
-
return
|
|
845
|
-
case "
|
|
846
|
-
return
|
|
847
|
-
case "
|
|
848
|
-
return
|
|
849
|
-
case "
|
|
850
|
-
return
|
|
851
|
-
case "
|
|
852
|
-
|
|
1476
|
+
case "openHistoryBundleV3":
|
|
1477
|
+
return await ensureClient().openHistoryBundleV3(msg.sealed, msg.ownAccount);
|
|
1478
|
+
case "openLinkHistoryBundle":
|
|
1479
|
+
return await ensureClient().openLinkHistoryBundle(msg.sealed, msg.recipientPriv);
|
|
1480
|
+
case "confirmHistoryImport":
|
|
1481
|
+
return await ensureClient().confirmHistoryImport(msg.importId);
|
|
1482
|
+
case "historyTrust":
|
|
1483
|
+
return await ensureClient().historyTrust(msg.deviceId);
|
|
1484
|
+
case "recordHistoryShipped":
|
|
1485
|
+
await ensureClient().recordHistoryShipped(msg.deviceId);
|
|
1486
|
+
return null;
|
|
1487
|
+
case "historyShipDecision":
|
|
1488
|
+
return await ensureClient().historyShipDecision(msg.deviceId);
|
|
853
1489
|
default:
|
|
854
1490
|
throw new Error(`unknown request kind: ${msg.kind}`);
|
|
855
1491
|
}
|