@open-e2ee/signal-protocol-sdk 6.0.0 → 7.1.0
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/CHANGELOG.md +75 -0
- package/README.md +2 -2
- package/SECURITY.md +2 -2
- package/client/README.md +59 -0
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +12 -1
- package/dist/client/client.js.map +1 -1
- package/dist/client/content-adapter.d.ts +4 -0
- package/dist/client/content-adapter.d.ts.map +1 -1
- package/dist/client/content-adapter.js +7 -0
- package/dist/client/content-adapter.js.map +1 -1
- package/dist/client/hosted-mailbox-subscription.d.ts +23 -0
- package/dist/client/hosted-mailbox-subscription.d.ts.map +1 -1
- package/dist/client/hosted-mailbox-subscription.js +83 -4
- package/dist/client/hosted-mailbox-subscription.js.map +1 -1
- package/dist/client/hosted-presence-frames.d.ts +140 -0
- package/dist/client/hosted-presence-frames.d.ts.map +1 -0
- package/dist/client/hosted-presence-frames.js +291 -0
- package/dist/client/hosted-presence-frames.js.map +1 -0
- package/dist/client/hosted-presence.d.ts +83 -0
- package/dist/client/hosted-presence.d.ts.map +1 -0
- package/dist/client/hosted-presence.js +448 -0
- package/dist/client/hosted-presence.js.map +1 -0
- package/dist/client/hosted-profile-keys.d.ts +14 -0
- package/dist/client/hosted-profile-keys.d.ts.map +1 -0
- package/dist/client/hosted-profile-keys.js +139 -0
- package/dist/client/hosted-profile-keys.js.map +1 -0
- package/dist/client/hosted-transport.d.ts +13 -1
- package/dist/client/hosted-transport.d.ts.map +1 -1
- package/dist/client/hosted-transport.js +38 -0
- package/dist/client/hosted-transport.js.map +1 -1
- package/dist/client/hosted.d.ts +10 -0
- package/dist/client/hosted.d.ts.map +1 -1
- package/dist/client/hosted.js +12 -3
- package/dist/client/hosted.js.map +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/client/profile-key-exchange.d.ts +13 -0
- package/dist/client/profile-key-exchange.d.ts.map +1 -0
- package/dist/client/profile-key-exchange.js +22 -0
- package/dist/client/profile-key-exchange.js.map +1 -0
- package/dist/client/relay-subscription.js +10 -0
- package/dist/client/relay-subscription.js.map +1 -1
- package/dist/client/types.d.ts +3 -0
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/types.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/docs/ASSURANCE.md +5 -5
- package/examples/browser/index.html +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Presence for a hosted client: the project policy, the account's own
|
|
3
|
+
* setting, batch reads, a watch for an open chat, and the presence key
|
|
4
|
+
* operations. With `hosted.profileKeys`, the SDK carries the key in its own
|
|
5
|
+
* end-to-end encrypted 1:1 messages and calls `accessKey()` and `grant()`.
|
|
6
|
+
*
|
|
7
|
+
* A client with a mailbox subscription sends every request over its socket.
|
|
8
|
+
* A wake client, which has no socket, sends them over HTTP. The two are
|
|
9
|
+
* separate entry points, and neither falls back to the other.
|
|
10
|
+
*
|
|
11
|
+
* The SDK reports no presence state. The Relay records the socket edges, and
|
|
12
|
+
* the lifecycle binding closes the socket in the background.
|
|
13
|
+
*/
|
|
14
|
+
import { bytesToUrlSafeBase64, hkdf, stringToBytes } from "../internal/crypto/index.js";
|
|
15
|
+
import { HostedRelayHttpError } from "./hosted-transport.js";
|
|
16
|
+
import { HostedRelayPresenceError, PRESENCE_READ_LIMIT, PRESENCE_WATCH_LIMIT, assertPresenceAccount, assertPresenceKey, decodePresenceResult, } from "./hosted-presence-frames.js";
|
|
17
|
+
export { HostedRelayPresenceError, } from "./hosted-presence-frames.js";
|
|
18
|
+
/**
|
|
19
|
+
* The interval of the `watch()` poll. It reads only the accounts that no
|
|
20
|
+
* answered presence watch covers.
|
|
21
|
+
*/
|
|
22
|
+
export const PRESENCE_WATCH_POLL_MILLISECONDS = 30_000;
|
|
23
|
+
/**
|
|
24
|
+
* The interval of the `watch()` renewal. Each renewal sends the whole watch
|
|
25
|
+
* set again, and its answer is the read of the watched accounts. The Relay
|
|
26
|
+
* drops a watch that is not renewed in two intervals.
|
|
27
|
+
*/
|
|
28
|
+
export const PRESENCE_WATCH_RENEWAL_MILLISECONDS = 120_000;
|
|
29
|
+
/** The HKDF info of the presence key. No other key uses this label. */
|
|
30
|
+
const PRESENCE_KEY_INFO = stringToBytes("open-e2ee-presence-key-v1");
|
|
31
|
+
const PRESENCE_KEY_BYTES = 16;
|
|
32
|
+
const PROFILE_KEY_BYTES = 32;
|
|
33
|
+
const PRESENCE_GRANT_METADATA_PREFIX = "hostedRelay.presenceGrant.v1:";
|
|
34
|
+
const runtimes = new WeakMap();
|
|
35
|
+
const presences = new WeakMap();
|
|
36
|
+
/** @internal Bind the SDK-owned transport to the client that uses it. */
|
|
37
|
+
export function bindHostedRelayPresenceRuntime(client, runtime) {
|
|
38
|
+
runtimes.set(client, runtime);
|
|
39
|
+
presences.delete(client);
|
|
40
|
+
}
|
|
41
|
+
function presenceRuntime(client) {
|
|
42
|
+
const runtime = runtimes.get(client);
|
|
43
|
+
if (runtime === undefined)
|
|
44
|
+
throw new Error("The client is not connected to the OpenE2EE Signal Protocol Relay");
|
|
45
|
+
return runtime;
|
|
46
|
+
}
|
|
47
|
+
/** @internal HKDF-SHA-256 over the profile key, with an empty salt, 16 bytes out. */
|
|
48
|
+
export async function derivePresenceKey(profileKey) {
|
|
49
|
+
if (!(profileKey instanceof Uint8Array) ||
|
|
50
|
+
profileKey.length !== PROFILE_KEY_BYTES)
|
|
51
|
+
throw new Error("Signal Protocol Relay profile key is invalid");
|
|
52
|
+
return bytesToUrlSafeBase64(await hkdf(profileKey, new Uint8Array(0), PRESENCE_KEY_INFO, PRESENCE_KEY_BYTES));
|
|
53
|
+
}
|
|
54
|
+
function grantMetadataKey(runtime, account) {
|
|
55
|
+
return `${PRESENCE_GRANT_METADATA_PREFIX}${runtime.presenceScope}:${account}`;
|
|
56
|
+
}
|
|
57
|
+
/** The account with the key that `grant()` stored for it, if any. */
|
|
58
|
+
async function presenceTarget(runtime, account) {
|
|
59
|
+
const stored = await runtime.presenceStore.getMetadata(grantMetadataKey(runtime, account));
|
|
60
|
+
return stored === null
|
|
61
|
+
? { account }
|
|
62
|
+
: { account, presenceKey: assertPresenceKey(stored) };
|
|
63
|
+
}
|
|
64
|
+
function presenceOperations(runtime, send) {
|
|
65
|
+
const request = async (value) => decodePresenceResult(value, await send(value));
|
|
66
|
+
const target = (account) => presenceTarget(runtime, account);
|
|
67
|
+
return {
|
|
68
|
+
policy: () => request({ type: "presence-policy" }),
|
|
69
|
+
setting: () => request({ type: "presence-account" }),
|
|
70
|
+
setVisibility: (visibility) => request({ type: "presence-setting", setting: visibility }),
|
|
71
|
+
read: async (accounts) => {
|
|
72
|
+
if (!Array.isArray(accounts))
|
|
73
|
+
throw new Error("Signal Protocol Relay presence read is invalid");
|
|
74
|
+
accounts.forEach(assertPresenceAccount);
|
|
75
|
+
const targets = await Promise.all(accounts.map(target));
|
|
76
|
+
const results = [];
|
|
77
|
+
for (let start = 0; start < targets.length; start += PRESENCE_READ_LIMIT)
|
|
78
|
+
results.push(...(await request({
|
|
79
|
+
type: "presence-read",
|
|
80
|
+
accounts: targets.slice(start, start + PRESENCE_READ_LIMIT),
|
|
81
|
+
})));
|
|
82
|
+
return results;
|
|
83
|
+
},
|
|
84
|
+
accessKey: async (profileKey) => {
|
|
85
|
+
const presenceKey = await derivePresenceKey(profileKey);
|
|
86
|
+
await request({ type: "presence-key", presenceKey });
|
|
87
|
+
return presenceKey;
|
|
88
|
+
},
|
|
89
|
+
grant: async (account, presenceKey) => {
|
|
90
|
+
await runtime.presenceStore.setMetadata(grantMetadataKey(runtime, assertPresenceAccount(account)), assertPresenceKey(presenceKey));
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function sameStatus(left, right) {
|
|
95
|
+
if (left === null || right === null)
|
|
96
|
+
return left === right;
|
|
97
|
+
return left.online === right.online && left.lastSeen === right.lastSeen;
|
|
98
|
+
}
|
|
99
|
+
function sameAccounts(left, right) {
|
|
100
|
+
return (left.length === right.length &&
|
|
101
|
+
left.every((account, index) => account === right[index]));
|
|
102
|
+
}
|
|
103
|
+
function refused(error) {
|
|
104
|
+
return (error instanceof HostedRelayPresenceError && error.code === "FRAME_REJECTED");
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The presence watch of a client, shared by all its `watch()` calls. It runs
|
|
108
|
+
* only while the mailbox socket is connected, which the lifecycle binding
|
|
109
|
+
* limits to the foreground.
|
|
110
|
+
*
|
|
111
|
+
* The first PRESENCE_WATCH_LIMIT watched accounts, in watch order, are the
|
|
112
|
+
* watch set. One `presence-watch` request registers that set on the socket.
|
|
113
|
+
* Its answer is the read of those accounts, and the Relay then pushes each
|
|
114
|
+
* change as a `presence-update` frame. The client sends the set again at each
|
|
115
|
+
* change of the set, at each new socket, and every
|
|
116
|
+
* PRESENCE_WATCH_RENEWAL_MILLISECONDS. The Relay drops a watch that is not
|
|
117
|
+
* renewed, and it can lose a watch without a signal, so the renewal is also
|
|
118
|
+
* the bound of a lost watch.
|
|
119
|
+
*
|
|
120
|
+
* The poll reads the accounts past the watch set, and every account while no
|
|
121
|
+
* answered watch covers the set: after a failed watch, until a watch answers
|
|
122
|
+
* again.
|
|
123
|
+
*/
|
|
124
|
+
class PresenceWatch {
|
|
125
|
+
runtime;
|
|
126
|
+
read;
|
|
127
|
+
target;
|
|
128
|
+
send;
|
|
129
|
+
watched = new Map();
|
|
130
|
+
/** The next registration: at once, or the renewal of the last one. */
|
|
131
|
+
registerTimer;
|
|
132
|
+
registering = false;
|
|
133
|
+
registerAgain = false;
|
|
134
|
+
/**
|
|
135
|
+
* The accounts of the last watch request on this socket. An empty list
|
|
136
|
+
* means that the socket holds no watch, so an empty set sends nothing.
|
|
137
|
+
*/
|
|
138
|
+
requested = [];
|
|
139
|
+
/** The presence keys of the last watch request, for each account. */
|
|
140
|
+
requestedKeys = new Map();
|
|
141
|
+
/** The last watch request on this socket was answered. */
|
|
142
|
+
confirmed = false;
|
|
143
|
+
pollTimer;
|
|
144
|
+
polling = false;
|
|
145
|
+
pollAgain = false;
|
|
146
|
+
/**
|
|
147
|
+
* The Signal Protocol Relay closed the socket on the last presence frame.
|
|
148
|
+
* After the reconnect, the client reads one full poll interval later and
|
|
149
|
+
* watches one full renewal interval later, so a Relay without these frames
|
|
150
|
+
* does not see a reconnect loop.
|
|
151
|
+
*/
|
|
152
|
+
rejected = false;
|
|
153
|
+
stopListeners;
|
|
154
|
+
constructor(runtime, read, target, send) {
|
|
155
|
+
this.runtime = runtime;
|
|
156
|
+
this.read = read;
|
|
157
|
+
this.target = target;
|
|
158
|
+
this.send = send;
|
|
159
|
+
}
|
|
160
|
+
watch(account, onChange) {
|
|
161
|
+
assertPresenceAccount(account);
|
|
162
|
+
if (typeof onChange !== "function")
|
|
163
|
+
throw new Error("Signal Protocol Relay presence listener is invalid");
|
|
164
|
+
let entry = this.watched.get(account);
|
|
165
|
+
const added = entry === undefined;
|
|
166
|
+
if (entry === undefined) {
|
|
167
|
+
entry = { listeners: new Set(), known: false, status: null };
|
|
168
|
+
this.watched.set(account, entry);
|
|
169
|
+
}
|
|
170
|
+
const watchedEntry = entry;
|
|
171
|
+
// Each call owns its own listener, so one callback can watch twice.
|
|
172
|
+
const listener = (status) => onChange(status);
|
|
173
|
+
watchedEntry.listeners.add(listener);
|
|
174
|
+
this.listen();
|
|
175
|
+
if (watchedEntry.known) {
|
|
176
|
+
queueMicrotask(() => {
|
|
177
|
+
if (watchedEntry.listeners.has(listener))
|
|
178
|
+
notify(listener, watchedEntry.status);
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
if (added)
|
|
182
|
+
this.changed();
|
|
183
|
+
return () => {
|
|
184
|
+
if (!watchedEntry.listeners.delete(listener))
|
|
185
|
+
return;
|
|
186
|
+
if (watchedEntry.listeners.size === 0 &&
|
|
187
|
+
this.watched.get(account) === watchedEntry) {
|
|
188
|
+
this.watched.delete(account);
|
|
189
|
+
this.changed();
|
|
190
|
+
}
|
|
191
|
+
this.release();
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
/** A new key for a watched account goes to the Relay with the watch. */
|
|
195
|
+
granted(account, presenceKey) {
|
|
196
|
+
if (this.connected() &&
|
|
197
|
+
this.watchSet().includes(account) &&
|
|
198
|
+
this.requestedKeys.get(account) !== presenceKey)
|
|
199
|
+
this.registerSoon();
|
|
200
|
+
}
|
|
201
|
+
listen() {
|
|
202
|
+
if (this.stopListeners !== undefined)
|
|
203
|
+
return;
|
|
204
|
+
const stopState = this.runtime.subscribeRelayConnectionState((state) => {
|
|
205
|
+
if (state.state === "connected")
|
|
206
|
+
return;
|
|
207
|
+
// A closed socket holds no watch. A new socket registers again.
|
|
208
|
+
this.cancel();
|
|
209
|
+
this.requested = [];
|
|
210
|
+
this.confirmed = false;
|
|
211
|
+
this.release();
|
|
212
|
+
});
|
|
213
|
+
const stopSocket = this.runtime.subscribePresenceSocket((event) => {
|
|
214
|
+
if (event.type === "update") {
|
|
215
|
+
this.apply(event.update.account, event.update.presence);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
this.cancel();
|
|
219
|
+
this.requested = [];
|
|
220
|
+
this.confirmed = false;
|
|
221
|
+
if (this.watched.size === 0)
|
|
222
|
+
return;
|
|
223
|
+
if (!this.rejected) {
|
|
224
|
+
this.changed();
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
this.schedulePoll(PRESENCE_WATCH_POLL_MILLISECONDS);
|
|
228
|
+
this.registerTimer = setTimeout(() => void this.register(), PRESENCE_WATCH_RENEWAL_MILLISECONDS);
|
|
229
|
+
});
|
|
230
|
+
this.stopListeners = () => {
|
|
231
|
+
stopState();
|
|
232
|
+
stopSocket();
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
/** Stops listening when nothing is watched and no request waits. */
|
|
236
|
+
release() {
|
|
237
|
+
if (this.watched.size > 0 ||
|
|
238
|
+
this.registering ||
|
|
239
|
+
this.registerTimer !== undefined)
|
|
240
|
+
return;
|
|
241
|
+
clearTimeout(this.pollTimer);
|
|
242
|
+
this.pollTimer = undefined;
|
|
243
|
+
this.stopListeners?.();
|
|
244
|
+
this.stopListeners = undefined;
|
|
245
|
+
}
|
|
246
|
+
connected() {
|
|
247
|
+
return this.runtime.relayConnectionState.state === "connected";
|
|
248
|
+
}
|
|
249
|
+
cancel() {
|
|
250
|
+
clearTimeout(this.registerTimer);
|
|
251
|
+
this.registerTimer = undefined;
|
|
252
|
+
clearTimeout(this.pollTimer);
|
|
253
|
+
this.pollTimer = undefined;
|
|
254
|
+
}
|
|
255
|
+
watchSet() {
|
|
256
|
+
return [...this.watched.keys()].slice(0, PRESENCE_WATCH_LIMIT);
|
|
257
|
+
}
|
|
258
|
+
/** The accounts that the poll reads. */
|
|
259
|
+
pollSet() {
|
|
260
|
+
const accounts = [...this.watched.keys()];
|
|
261
|
+
return this.registering || this.confirmed
|
|
262
|
+
? accounts.slice(PRESENCE_WATCH_LIMIT)
|
|
263
|
+
: accounts;
|
|
264
|
+
}
|
|
265
|
+
/** Registers when the watch set changed, and reads a new account past it. */
|
|
266
|
+
changed() {
|
|
267
|
+
if (!this.connected())
|
|
268
|
+
return;
|
|
269
|
+
if (!sameAccounts(this.watchSet(), this.requested))
|
|
270
|
+
this.registerSoon();
|
|
271
|
+
const unknown = [...this.watched.values()]
|
|
272
|
+
.slice(PRESENCE_WATCH_LIMIT)
|
|
273
|
+
.some((entry) => !entry.known);
|
|
274
|
+
if (unknown)
|
|
275
|
+
this.pollSoon();
|
|
276
|
+
}
|
|
277
|
+
/** Registers at the next turn, so watches that start together share one. */
|
|
278
|
+
registerSoon() {
|
|
279
|
+
if (!this.connected())
|
|
280
|
+
return;
|
|
281
|
+
if (this.registering) {
|
|
282
|
+
this.registerAgain = true;
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
clearTimeout(this.registerTimer);
|
|
286
|
+
this.registerTimer = setTimeout(() => void this.register(), 0);
|
|
287
|
+
}
|
|
288
|
+
async register() {
|
|
289
|
+
this.registerTimer = undefined;
|
|
290
|
+
if (this.registering || !this.connected())
|
|
291
|
+
return;
|
|
292
|
+
const accounts = this.watchSet();
|
|
293
|
+
if (accounts.length === 0 && this.requested.length === 0) {
|
|
294
|
+
this.release();
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
this.registering = true;
|
|
298
|
+
this.registerAgain = false;
|
|
299
|
+
this.requested = accounts;
|
|
300
|
+
try {
|
|
301
|
+
const targets = await Promise.all(accounts.map(this.target));
|
|
302
|
+
this.requestedKeys = new Map(targets.map((target) => [target.account, target.presenceKey]));
|
|
303
|
+
const request = { type: "presence-watch", accounts: targets };
|
|
304
|
+
const results = decodePresenceResult(request, await this.send(request));
|
|
305
|
+
this.rejected = false;
|
|
306
|
+
this.confirmed = true;
|
|
307
|
+
accounts.forEach((account, index) => this.apply(account, results[index] ?? null));
|
|
308
|
+
}
|
|
309
|
+
catch (error) {
|
|
310
|
+
// The Relay can hold the new set or the old one. The poll reads every
|
|
311
|
+
// account until a watch answers again.
|
|
312
|
+
this.confirmed = false;
|
|
313
|
+
if (refused(error))
|
|
314
|
+
this.rejected = true;
|
|
315
|
+
}
|
|
316
|
+
finally {
|
|
317
|
+
this.registering = false;
|
|
318
|
+
if (this.connected()) {
|
|
319
|
+
if (this.registerAgain)
|
|
320
|
+
this.registerSoon();
|
|
321
|
+
else if (this.watched.size > 0)
|
|
322
|
+
this.registerTimer = setTimeout(() => void this.register(), PRESENCE_WATCH_RENEWAL_MILLISECONDS);
|
|
323
|
+
this.schedulePoll(PRESENCE_WATCH_POLL_MILLISECONDS);
|
|
324
|
+
}
|
|
325
|
+
this.release();
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Starts the poll when it has accounts to read, and stops it when it has
|
|
330
|
+
* none. A running poll keeps its interval.
|
|
331
|
+
*/
|
|
332
|
+
schedulePoll(milliseconds) {
|
|
333
|
+
if (this.pollSet().length === 0) {
|
|
334
|
+
clearTimeout(this.pollTimer);
|
|
335
|
+
this.pollTimer = undefined;
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
if (this.pollTimer !== undefined && milliseconds > 0)
|
|
339
|
+
return;
|
|
340
|
+
clearTimeout(this.pollTimer);
|
|
341
|
+
this.pollTimer = setTimeout(() => {
|
|
342
|
+
this.pollTimer = undefined;
|
|
343
|
+
void this.poll();
|
|
344
|
+
}, milliseconds);
|
|
345
|
+
}
|
|
346
|
+
/** Reads at the next turn, so watches that start together share one read. */
|
|
347
|
+
pollSoon() {
|
|
348
|
+
if (!this.connected())
|
|
349
|
+
return;
|
|
350
|
+
if (this.polling)
|
|
351
|
+
this.pollAgain = true;
|
|
352
|
+
else
|
|
353
|
+
this.schedulePoll(0);
|
|
354
|
+
}
|
|
355
|
+
async poll() {
|
|
356
|
+
if (this.polling || !this.connected())
|
|
357
|
+
return;
|
|
358
|
+
const accounts = this.pollSet();
|
|
359
|
+
if (accounts.length === 0)
|
|
360
|
+
return;
|
|
361
|
+
this.polling = true;
|
|
362
|
+
this.pollAgain = false;
|
|
363
|
+
try {
|
|
364
|
+
const results = await this.read(accounts);
|
|
365
|
+
this.rejected = false;
|
|
366
|
+
accounts.forEach((account, index) => this.apply(account, results[index] ?? null));
|
|
367
|
+
}
|
|
368
|
+
catch (error) {
|
|
369
|
+
// A failed read keeps the last value. The next poll reads again.
|
|
370
|
+
if (refused(error))
|
|
371
|
+
this.rejected = true;
|
|
372
|
+
}
|
|
373
|
+
finally {
|
|
374
|
+
this.polling = false;
|
|
375
|
+
if (this.connected())
|
|
376
|
+
this.schedulePoll(this.pollAgain ? 0 : PRESENCE_WATCH_POLL_MILLISECONDS);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
/** Notifies the listeners of a watched account when its presence changed. */
|
|
380
|
+
apply(account, status) {
|
|
381
|
+
const entry = this.watched.get(account);
|
|
382
|
+
if (entry === undefined || (entry.known && sameStatus(entry.status, status)))
|
|
383
|
+
return;
|
|
384
|
+
entry.known = true;
|
|
385
|
+
entry.status = status;
|
|
386
|
+
for (const listener of [...entry.listeners])
|
|
387
|
+
notify(listener, status);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
/** A listener that throws does not stop the others or the poll. */
|
|
391
|
+
function notify(listener, status) {
|
|
392
|
+
try {
|
|
393
|
+
listener(status);
|
|
394
|
+
}
|
|
395
|
+
catch (error) {
|
|
396
|
+
queueMicrotask(() => {
|
|
397
|
+
throw error;
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* The presence of a hosted client with a mailbox subscription. Every request
|
|
403
|
+
* goes over the socket, so start the subscription first. Each client has one
|
|
404
|
+
* presence object, and its watches share one presence watch and one poll.
|
|
405
|
+
*/
|
|
406
|
+
export function hostedRelayPresence(client) {
|
|
407
|
+
const existing = presences.get(client);
|
|
408
|
+
if (existing !== undefined)
|
|
409
|
+
return existing;
|
|
410
|
+
const runtime = presenceRuntime(client);
|
|
411
|
+
// Every request goes over the socket, never over HTTP.
|
|
412
|
+
const send = async (request) => {
|
|
413
|
+
const socket = runtime.presenceSocket;
|
|
414
|
+
if (socket === undefined)
|
|
415
|
+
throw new HostedRelayPresenceError("NOT_CONNECTED", "The mailbox subscription is not running", true);
|
|
416
|
+
return socket.presence(request);
|
|
417
|
+
};
|
|
418
|
+
const operations = presenceOperations(runtime, send);
|
|
419
|
+
const watch = new PresenceWatch(runtime, operations.read, (account) => presenceTarget(runtime, account), send);
|
|
420
|
+
const presence = {
|
|
421
|
+
...operations,
|
|
422
|
+
grant: async (account, presenceKey) => {
|
|
423
|
+
await operations.grant(account, presenceKey);
|
|
424
|
+
watch.granted(account, presenceKey);
|
|
425
|
+
},
|
|
426
|
+
watch: (account, onChange) => watch.watch(account, onChange),
|
|
427
|
+
};
|
|
428
|
+
presences.set(client, presence);
|
|
429
|
+
return presence;
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* The presence of a wake client, over HTTP. Use it only where the client runs
|
|
433
|
+
* no mailbox subscription, for example beside `pullHostedRelayAfterWake()`.
|
|
434
|
+
*/
|
|
435
|
+
export function hostedRelayWakePresence(client) {
|
|
436
|
+
const runtime = presenceRuntime(client);
|
|
437
|
+
return presenceOperations(runtime, async (request) => {
|
|
438
|
+
try {
|
|
439
|
+
return await runtime.postPresence(request);
|
|
440
|
+
}
|
|
441
|
+
catch (error) {
|
|
442
|
+
if (!(error instanceof HostedRelayHttpError))
|
|
443
|
+
throw error;
|
|
444
|
+
throw new HostedRelayPresenceError(error.code, error.message, error.retryable);
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
//# sourceMappingURL=hosted-presence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hosted-presence.js","sourceRoot":"","sources":["../../client/hosted-presence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,oBAAoB,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAY/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,iBAAiB,EACjB,oBAAoB,GAQrB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,wBAAwB,GAWzB,MAAM,0BAA0B,CAAC;AAElC;;;GAGG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,MAAM,CAAC;AAEvD;;;;GAIG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAAG,OAAO,CAAC;AAE3D,uEAAuE;AACvE,MAAM,iBAAiB,GAAG,aAAa,CAAC,2B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QACD,KAAK,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC;KAC7D,CAAC;IACF,SAAS,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;IAChC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CACrC,MAA6B;IAE7B,MAAM,OAAO,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;IACxC,OAAO,kBAAkB,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;QACnD,IAAI,CAAC;YACH,OAAO,MAAM,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAC7C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,CAAC,KAAK,YAAY,oBAAoB,CAAC;gBAAE,MAAM,KAAK,CAAC;YAC1D,MAAM,IAAI,wBAAwB,CAChC,KAAK,CAAC,IAAI,EACV,KAAK,CAAC,OAAO,EACb,KAAK,CAAC,SAAS,CAChB,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type MutableContactProfileStateStore } from "../profile/contact-state.js";
|
|
2
|
+
/** The profile keys that a hosted client carries in its 1:1 messages. */
|
|
3
|
+
export interface HostedRelayProfileKeys {
|
|
4
|
+
/**
|
|
5
|
+
* Returns this account's 32-byte profile key, or null when it has none. The
|
|
6
|
+
* SDK reads it before each 1:1 send and when the mailbox socket connects,
|
|
7
|
+
* so a new key takes effect at the next of these. Each device of the
|
|
8
|
+
* account must return the same key.
|
|
9
|
+
*/
|
|
10
|
+
getOwnProfileKey(): Promise<Uint8Array | null>;
|
|
11
|
+
/** Keeps the profile key that each contact sent. */
|
|
12
|
+
readonly contacts: MutableContactProfileStateStore;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=hosted-profile-keys.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hosted-profile-keys.d.ts","sourceRoot":"","sources":["../../client/hosted-profile-keys.ts"],"names":[],"mappings":"AAaA,OAAO,EAEL,KAAK,+BAA+B,EACrC,MAAM,0BAA0B,CAAC;AAclC,yEAAyE;AACzE,MAAM,WAAW,sBAAsB;IACrC;;;;;OAKG;IACH,gBAAgB,IAAI,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC;IAC/C,oDAAoD;IACpD,QAAQ,CAAC,QAAQ,EAAE,+BAA+B,CAAC;CACpD"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The presence key exchange of a hosted client. The client carries this
|
|
3
|
+
* account's profile key in its end-to-end encrypted 1:1 content, in the Signal
|
|
4
|
+
* `DataMessage.profileKey` shape. The receiving client keeps the key in the
|
|
5
|
+
* contact profile store, derives the sender's presence key from it, and
|
|
6
|
+
* grants that key. When the profile key changes, the client registers the new
|
|
7
|
+
* presence key, and the Relay revokes the old one.
|
|
8
|
+
*
|
|
9
|
+
* The profile key goes only in encrypted content. The presence key goes only
|
|
10
|
+
* in the `presence-key`, `presence-read`, and `presence-watch` frames.
|
|
11
|
+
*/
|
|
12
|
+
import { base64ToBytes, bytesToBase64 } from "../internal/crypto/index.js";
|
|
13
|
+
import { storeReceivedProfileKey, } from "../profile/contact-state.js";
|
|
14
|
+
import { asBase64 } from "../types/utils.js";
|
|
15
|
+
import { HostedRelayPresenceError, derivePresenceKey, hostedRelayPresence, } from "./hosted-presence.js";
|
|
16
|
+
import { PROFILE_KEY_UPDATE_FLAG, bindProfileKeyExchange, } from "./profile-key-exchange.js";
|
|
17
|
+
const DELIVERED_METADATA_PREFIX = "hostedRelay.profileKeyDelivered.v1:";
|
|
18
|
+
/** @internal Throws unless the option has the members that the SDK calls. */
|
|
19
|
+
export function assertHostedRelayProfileKeys(keys) {
|
|
20
|
+
if (typeof keys?.getOwnProfileKey !== "function" ||
|
|
21
|
+
typeof keys.contacts?.storeContactProfileKey !== "function" ||
|
|
22
|
+
typeof keys.contacts.updateUnidentifiedAccessMode !== "function")
|
|
23
|
+
throw new Error("Signal Protocol Relay profile keys are invalid");
|
|
24
|
+
}
|
|
25
|
+
/** @internal Bind the presence key exchange of a hosted client. */
|
|
26
|
+
export function bindHostedRelayProfileKeys(client, runtime, keys, logger) {
|
|
27
|
+
assertHostedRelayProfileKeys(keys);
|
|
28
|
+
const presence = hostedRelayPresence(client);
|
|
29
|
+
/** The presence key that the Relay holds from this client. */
|
|
30
|
+
let registered;
|
|
31
|
+
/** A presence key that the Relay refused. The client does not send it again. */
|
|
32
|
+
let refused;
|
|
33
|
+
let registering;
|
|
34
|
+
const offers = new Map();
|
|
35
|
+
const warn = (message, error) => logger.warn(message, {
|
|
36
|
+
category: "E2EE",
|
|
37
|
+
data: { error: error instanceof Error ? error.message : String(error) },
|
|
38
|
+
});
|
|
39
|
+
/** Reads this account's profile key. It throws unless the key has 32 bytes. */
|
|
40
|
+
const own = async () => {
|
|
41
|
+
const bytes = await keys.getOwnProfileKey();
|
|
42
|
+
if (bytes === null)
|
|
43
|
+
return undefined;
|
|
44
|
+
const presenceKey = await derivePresenceKey(bytes);
|
|
45
|
+
return { bytes, profileKey: bytesToBase64(bytes), presenceKey };
|
|
46
|
+
};
|
|
47
|
+
const deliveredMetadataKey = (recipient) => `${DELIVERED_METADATA_PREFIX}${runtime.presenceScope}:${recipient}`;
|
|
48
|
+
/**
|
|
49
|
+
* Registers the presence key once for each client and again after each
|
|
50
|
+
* profile key change. A later send or connect retries a retryable failure.
|
|
51
|
+
*/
|
|
52
|
+
const register = (key) => {
|
|
53
|
+
if (registering !== undefined ||
|
|
54
|
+
key.presenceKey === registered ||
|
|
55
|
+
key.presenceKey === refused ||
|
|
56
|
+
runtime.relayConnectionState.state !== "connected")
|
|
57
|
+
return;
|
|
58
|
+
registering = presence
|
|
59
|
+
.accessKey(key.bytes)
|
|
60
|
+
.then(() => {
|
|
61
|
+
registered = key.presenceKey;
|
|
62
|
+
}, (error) => {
|
|
63
|
+
if (!(error instanceof HostedRelayPresenceError) || !error.retryable)
|
|
64
|
+
refused = key.presenceKey;
|
|
65
|
+
warn("Signal Protocol Relay presence key registration failed", error);
|
|
66
|
+
})
|
|
67
|
+
.finally(() => {
|
|
68
|
+
registering = undefined;
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
runtime.subscribeRelayConnectionState((state) => {
|
|
72
|
+
if (state.state !== "connected")
|
|
73
|
+
return;
|
|
74
|
+
own().then((key) => {
|
|
75
|
+
if (key !== undefined)
|
|
76
|
+
register(key);
|
|
77
|
+
}, (error) => warn("Signal Protocol profile key is invalid", error));
|
|
78
|
+
});
|
|
79
|
+
bindProfileKeyExchange(client, {
|
|
80
|
+
outgoing: async () => {
|
|
81
|
+
try {
|
|
82
|
+
const key = await own();
|
|
83
|
+
if (key === undefined)
|
|
84
|
+
return undefined;
|
|
85
|
+
register(key);
|
|
86
|
+
return key.profileKey;
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
warn("Signal Protocol profile key is invalid", error);
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
delivered: async (recipient, profileKey) => {
|
|
94
|
+
try {
|
|
95
|
+
const presenceKey = await derivePresenceKey(base64ToBytes(asBase64(profileKey)));
|
|
96
|
+
const metadataKey = deliveredMetadataKey(recipient);
|
|
97
|
+
if ((await runtime.presenceStore.getMetadata(metadataKey)) !== presenceKey)
|
|
98
|
+
await runtime.presenceStore.setMetadata(metadataKey, presenceKey);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
warn("Signal Protocol profile key delivery was not recorded", error);
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
offer: (recipient) => {
|
|
105
|
+
const pending = offers.get(recipient);
|
|
106
|
+
if (pending !== undefined)
|
|
107
|
+
return pending;
|
|
108
|
+
const offer = (async () => {
|
|
109
|
+
const key = await own();
|
|
110
|
+
if (key === undefined)
|
|
111
|
+
return;
|
|
112
|
+
register(key);
|
|
113
|
+
const delivered = await runtime.presenceStore.getMetadata(deliveredMetadataKey(recipient));
|
|
114
|
+
if (delivered === key.presenceKey)
|
|
115
|
+
return;
|
|
116
|
+
// The DataMessage path adds the profile key and records the delivery.
|
|
117
|
+
await client.send(recipient, { flags: PROFILE_KEY_UPDATE_FLAG });
|
|
118
|
+
})()
|
|
119
|
+
.catch((error) => warn("Signal Protocol profile key update was not sent", error))
|
|
120
|
+
.finally(() => {
|
|
121
|
+
offers.delete(recipient);
|
|
122
|
+
});
|
|
123
|
+
offers.set(recipient, offer);
|
|
124
|
+
return offer;
|
|
125
|
+
},
|
|
126
|
+
incoming: async (sender, profileKey) => {
|
|
127
|
+
try {
|
|
128
|
+
const bytes = base64ToBytes(asBase64(profileKey));
|
|
129
|
+
const presenceKey = await derivePresenceKey(bytes);
|
|
130
|
+
await storeReceivedProfileKey(sender, bytesToBase64(bytes), keys.contacts, logger);
|
|
131
|
+
await presence.grant(sender, presenceKey);
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
warn("Signal Protocol contact profile key was not kept", error);
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=hosted-profile-keys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hosted-profile-keys.js","sourceRoot":"","sources":["../../client/hosted-profile-keys.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAElE,OAAO,EACL,uBAAuB,GAExB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,mBAAmB,GAEpB,MAAM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