@open-e2ee/signal-protocol-sdk 5.0.0 → 7.0.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 +96 -0
- package/README.md +2 -2
- package/SECURITY.md +2 -2
- package/client/README.md +55 -0
- package/dist/client/client.d.ts +16 -0
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +34 -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 +15 -1
- package/dist/client/hosted-mailbox-subscription.d.ts.map +1 -1
- package/dist/client/hosted-mailbox-subscription.js +100 -15
- package/dist/client/hosted-mailbox-subscription.js.map +1 -1
- package/dist/client/hosted-presence-frames.d.ts +117 -0
- package/dist/client/hosted-presence-frames.d.ts.map +1 -0
- package/dist/client/hosted-presence-frames.js +244 -0
- package/dist/client/hosted-presence-frames.js.map +1 -0
- package/dist/client/hosted-presence.d.ts +69 -0
- package/dist/client/hosted-presence.d.ts.map +1 -0
- package/dist/client/hosted-presence.js +262 -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 +15 -2
- package/dist/client/hosted-transport.d.ts.map +1 -1
- package/dist/client/hosted-transport.js +30 -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 +2 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +2 -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-lifecycle.d.ts +57 -0
- package/dist/client/relay-lifecycle.d.ts.map +1 -0
- package/dist/client/relay-lifecycle.js +61 -0
- package/dist/client/relay-lifecycle.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/hooks/index.d.ts +2 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +2 -0
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/use-relay-connection-state.d.ts +32 -0
- package/dist/hooks/use-relay-connection-state.d.ts.map +1 -0
- package/dist/hooks/use-relay-connection-state.js +31 -0
- package/dist/hooks/use-relay-connection-state.js.map +1 -0
- package/dist/hooks/use-relay-lifecycle.d.ts +36 -0
- package/dist/hooks/use-relay-lifecycle.d.ts.map +1 -0
- package/dist/hooks/use-relay-lifecycle.js +35 -0
- package/dist/hooks/use-relay-lifecycle.js.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/remote/relay/connection-state.d.ts +16 -0
- package/dist/remote/relay/connection-state.d.ts.map +1 -0
- package/dist/remote/relay/connection-state.js +39 -0
- package/dist/remote/relay/connection-state.js.map +1 -0
- package/dist/remote/relay/index.d.ts +1 -1
- package/dist/remote/relay/index.d.ts.map +1 -1
- package/dist/remote/relay/index.js.map +1 -1
- package/dist/remote/relay/memory/adapter.d.ts +11 -1
- package/dist/remote/relay/memory/adapter.d.ts.map +1 -1
- package/dist/remote/relay/memory/adapter.js +23 -0
- package/dist/remote/relay/memory/adapter.js.map +1 -1
- package/dist/remote/relay/types.d.ts +46 -0
- package/dist/remote/relay/types.d.ts.map +1 -1
- package/dist/types/api.d.ts +21 -0
- package/dist/types/api.d.ts.map +1 -1
- package/docs/ASSURANCE.md +5 -5
- package/examples/browser/index.html +1 -1
- package/hooks/README.md +43 -6
- package/package.json +1 -1
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The presence wire contract of the hosted Relay, version 1.
|
|
3
|
+
*
|
|
4
|
+
* A device with a mailbox socket sends each presence request as one text frame
|
|
5
|
+
* on that socket. The frame carries `type`, `version`, and an `id` that the
|
|
6
|
+
* Relay echoes in its one answer: a `presence-result` or a `presence-error`
|
|
7
|
+
* frame. The Relay closes the socket with code 1008 on a frame type or a
|
|
8
|
+
* version that it does not accept, as it does for every other unknown frame.
|
|
9
|
+
* The SDK has no fallback for that close. It rejects the pending requests
|
|
10
|
+
* with `FRAME_REJECTED`.
|
|
11
|
+
*
|
|
12
|
+
* A wake client has no socket. It sends the same request body, without `id`
|
|
13
|
+
* and with `publishableKey`, as an authenticated `POST /presence`, and the
|
|
14
|
+
* response body is the `result` object of the same request type.
|
|
15
|
+
*/
|
|
16
|
+
import { base64ToBytes, bytesToUrlSafeBase64, urlSafeToBase64, } from "../internal/crypto/index.js";
|
|
17
|
+
/** The version that every presence request and answer carries. */
|
|
18
|
+
export const PRESENCE_FRAME_VERSION = 1;
|
|
19
|
+
/** The Relay refuses a presence read with more accounts. */
|
|
20
|
+
export const PRESENCE_READ_LIMIT = 100;
|
|
21
|
+
/** A presence key is 16 bytes, sent as 22 canonical base64url characters. */
|
|
22
|
+
const PRESENCE_KEY_BYTES = 16;
|
|
23
|
+
const PRESENCE_KEY_CHARACTERS = 22;
|
|
24
|
+
const MAXIMUM_ACCOUNT_CHARACTERS = 256;
|
|
25
|
+
const MAXIMUM_ERROR_CODE_CHARACTERS = 64;
|
|
26
|
+
const MAXIMUM_ERROR_MESSAGE_CHARACTERS = 1_024;
|
|
27
|
+
const REQUEST_ID = /^[A-Za-z0-9_-]{1,64}$/u;
|
|
28
|
+
const ERROR_CODE = /^[A-Z][A-Z0-9_]*$/u;
|
|
29
|
+
/** A presence request that the Relay refused or that got no answer. */
|
|
30
|
+
export class HostedRelayPresenceError extends Error {
|
|
31
|
+
code;
|
|
32
|
+
/** True when the same request can be sent again later. */
|
|
33
|
+
retryable;
|
|
34
|
+
constructor(code, message, retryable) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.name = "HostedRelayPresenceError";
|
|
37
|
+
this.code = code;
|
|
38
|
+
this.retryable = retryable;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function record(value) {
|
|
42
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
43
|
+
}
|
|
44
|
+
function exactKeys(value, keys) {
|
|
45
|
+
const present = Object.keys(value);
|
|
46
|
+
return (present.length === keys.length && keys.every((key) => key in value));
|
|
47
|
+
}
|
|
48
|
+
function invalidResult() {
|
|
49
|
+
return new Error("Signal Protocol Relay returned an invalid presence result");
|
|
50
|
+
}
|
|
51
|
+
/** Throws unless the account is a Relay account address of 1-256 characters. */
|
|
52
|
+
export function assertPresenceAccount(account) {
|
|
53
|
+
if (typeof account !== "string" ||
|
|
54
|
+
account.length === 0 ||
|
|
55
|
+
account.length > MAXIMUM_ACCOUNT_CHARACTERS)
|
|
56
|
+
throw new Error("Signal Protocol Relay presence account is invalid");
|
|
57
|
+
return account;
|
|
58
|
+
}
|
|
59
|
+
/** Throws unless the key is exactly 16 bytes of canonical base64url. */
|
|
60
|
+
export function assertPresenceKey(presenceKey) {
|
|
61
|
+
if (typeof presenceKey !== "string" ||
|
|
62
|
+
presenceKey.length !== PRESENCE_KEY_CHARACTERS)
|
|
63
|
+
throw new Error("Signal Protocol Relay presence key is invalid");
|
|
64
|
+
let bytes;
|
|
65
|
+
try {
|
|
66
|
+
bytes = base64ToBytes(urlSafeToBase64(presenceKey));
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
throw new Error("Signal Protocol Relay presence key is invalid");
|
|
70
|
+
}
|
|
71
|
+
if (bytes.length !== PRESENCE_KEY_BYTES ||
|
|
72
|
+
bytesToUrlSafeBase64(bytes) !== presenceKey)
|
|
73
|
+
throw new Error("Signal Protocol Relay presence key is invalid");
|
|
74
|
+
return presenceKey;
|
|
75
|
+
}
|
|
76
|
+
/** The request fields after `type` and `version`, in their wire order. */
|
|
77
|
+
function requestFields(request) {
|
|
78
|
+
switch (request.type) {
|
|
79
|
+
case "presence-policy":
|
|
80
|
+
case "presence-account":
|
|
81
|
+
return {};
|
|
82
|
+
case "presence-setting":
|
|
83
|
+
if (request.setting !== "visible" && request.setting !== "hidden")
|
|
84
|
+
throw new Error("Signal Protocol Relay presence setting is invalid");
|
|
85
|
+
return { setting: request.setting };
|
|
86
|
+
case "presence-key":
|
|
87
|
+
return { presenceKey: assertPresenceKey(request.presenceKey) };
|
|
88
|
+
case "presence-read":
|
|
89
|
+
if (!Array.isArray(request.accounts) ||
|
|
90
|
+
request.accounts.length === 0 ||
|
|
91
|
+
request.accounts.length > PRESENCE_READ_LIMIT)
|
|
92
|
+
throw new Error("Signal Protocol Relay presence read is invalid");
|
|
93
|
+
return {
|
|
94
|
+
accounts: request.accounts.map((target) => target.presenceKey === undefined
|
|
95
|
+
? { account: assertPresenceAccount(target.account) }
|
|
96
|
+
: {
|
|
97
|
+
account: assertPresenceAccount(target.account),
|
|
98
|
+
presenceKey: assertPresenceKey(target.presenceKey),
|
|
99
|
+
}),
|
|
100
|
+
};
|
|
101
|
+
default:
|
|
102
|
+
throw new Error("Signal Protocol Relay presence request is invalid");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/** The socket frame of one presence request. */
|
|
106
|
+
export function encodePresenceFrame(id, request) {
|
|
107
|
+
if (!REQUEST_ID.test(id))
|
|
108
|
+
throw new Error("Signal Protocol Relay presence request id is invalid");
|
|
109
|
+
return JSON.stringify({
|
|
110
|
+
type: request.type,
|
|
111
|
+
version: PRESENCE_FRAME_VERSION,
|
|
112
|
+
id,
|
|
113
|
+
...requestFields(request),
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/** The HTTP body of one presence request from a client with no socket. */
|
|
117
|
+
export function presenceHttpBody(publishableKey, request) {
|
|
118
|
+
return {
|
|
119
|
+
type: request.type,
|
|
120
|
+
version: PRESENCE_FRAME_VERSION,
|
|
121
|
+
...requestFields(request),
|
|
122
|
+
publishableKey,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/** True for the frame types that answer a presence request. */
|
|
126
|
+
export function isPresenceAnswerType(type) {
|
|
127
|
+
return type === "presence-result" || type === "presence-error";
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Decodes a `presence-result` or `presence-error` frame. A malformed answer
|
|
131
|
+
* throws, and the subscription treats it as an invalid frame.
|
|
132
|
+
*/
|
|
133
|
+
export function decodePresenceAnswer(frame) {
|
|
134
|
+
if (frame.version !== PRESENCE_FRAME_VERSION ||
|
|
135
|
+
typeof frame.id !== "string" ||
|
|
136
|
+
!REQUEST_ID.test(frame.id))
|
|
137
|
+
throw new Error("Invalid presence frame.");
|
|
138
|
+
if (frame.type === "presence-result") {
|
|
139
|
+
if (!exactKeys(frame, ["type", "version", "id", "result"]))
|
|
140
|
+
throw new Error("Invalid presence frame.");
|
|
141
|
+
return { id: frame.id, result: frame.result };
|
|
142
|
+
}
|
|
143
|
+
if (frame.type !== "presence-error" ||
|
|
144
|
+
!exactKeys(frame, ["type", "version", "id", "code", "message", "retryable"]) ||
|
|
145
|
+
typeof frame.code !== "string" ||
|
|
146
|
+
frame.code.length > MAXIMUM_ERROR_CODE_CHARACTERS ||
|
|
147
|
+
!ERROR_CODE.test(frame.code) ||
|
|
148
|
+
typeof frame.message !== "string" ||
|
|
149
|
+
frame.message.length > MAXIMUM_ERROR_MESSAGE_CHARACTERS ||
|
|
150
|
+
typeof frame.retryable !== "boolean")
|
|
151
|
+
throw new Error("Invalid presence frame.");
|
|
152
|
+
return {
|
|
153
|
+
id: frame.id,
|
|
154
|
+
error: new HostedRelayPresenceError(frame.code, frame.message, frame.retryable),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
const MODES = ["off", "default-on", "default-off", "forced"];
|
|
158
|
+
const AUDIENCES = ["contacts", "project"];
|
|
159
|
+
const LAST_SEEN_POLICIES = [
|
|
160
|
+
"exact",
|
|
161
|
+
"approximate",
|
|
162
|
+
"hidden",
|
|
163
|
+
];
|
|
164
|
+
const SETTINGS = ["unset", "visible", "hidden"];
|
|
165
|
+
const VISIBILITIES = ["visible", "hidden"];
|
|
166
|
+
const APPROXIMATE_LAST_SEEN = [
|
|
167
|
+
"recently",
|
|
168
|
+
"within-week",
|
|
169
|
+
"within-month",
|
|
170
|
+
"long-ago",
|
|
171
|
+
];
|
|
172
|
+
function decodePolicy(value) {
|
|
173
|
+
if (!record(value) ||
|
|
174
|
+
!exactKeys(value, ["audience", "lastSeen", "mode", "reciprocal"]) ||
|
|
175
|
+
!AUDIENCES.includes(value.audience) ||
|
|
176
|
+
!LAST_SEEN_POLICIES.includes(value.lastSeen) ||
|
|
177
|
+
!MODES.includes(value.mode) ||
|
|
178
|
+
typeof value.reciprocal !== "boolean")
|
|
179
|
+
throw invalidResult();
|
|
180
|
+
return {
|
|
181
|
+
audience: value.audience,
|
|
182
|
+
lastSeen: value.lastSeen,
|
|
183
|
+
mode: value.mode,
|
|
184
|
+
reciprocal: value.reciprocal,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
function decodeAccount(value) {
|
|
188
|
+
if (!record(value) ||
|
|
189
|
+
!exactKeys(value, ["effective", "keyRegistered", "mode", "setting"]) ||
|
|
190
|
+
!VISIBILITIES.includes(value.effective) ||
|
|
191
|
+
typeof value.keyRegistered !== "boolean" ||
|
|
192
|
+
!MODES.includes(value.mode) ||
|
|
193
|
+
!SETTINGS.includes(value.setting))
|
|
194
|
+
throw invalidResult();
|
|
195
|
+
return {
|
|
196
|
+
effective: value.effective,
|
|
197
|
+
keyRegistered: value.keyRegistered,
|
|
198
|
+
mode: value.mode,
|
|
199
|
+
setting: value.setting,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function decodeStatus(value) {
|
|
203
|
+
if (value === null)
|
|
204
|
+
return null;
|
|
205
|
+
if (!record(value) ||
|
|
206
|
+
!exactKeys(value, ["lastSeen", "online"]) ||
|
|
207
|
+
typeof value.online !== "boolean" ||
|
|
208
|
+
!(value.lastSeen === null ||
|
|
209
|
+
APPROXIMATE_LAST_SEEN.includes(value.lastSeen) ||
|
|
210
|
+
(typeof value.lastSeen === "number" &&
|
|
211
|
+
Number.isSafeInteger(value.lastSeen) &&
|
|
212
|
+
value.lastSeen >= 0)))
|
|
213
|
+
throw invalidResult();
|
|
214
|
+
return {
|
|
215
|
+
lastSeen: value.lastSeen,
|
|
216
|
+
online: value.online,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
/** Decodes the `result` of one request, and throws on any other shape. */
|
|
220
|
+
export function decodePresenceResult(request, value) {
|
|
221
|
+
switch (request.type) {
|
|
222
|
+
case "presence-policy":
|
|
223
|
+
return decodePolicy(value);
|
|
224
|
+
case "presence-account":
|
|
225
|
+
case "presence-setting":
|
|
226
|
+
return decodeAccount(value);
|
|
227
|
+
case "presence-key":
|
|
228
|
+
if (!record(value) || Object.keys(value).length !== 0)
|
|
229
|
+
throw invalidResult();
|
|
230
|
+
return undefined;
|
|
231
|
+
case "presence-read": {
|
|
232
|
+
if (!record(value) ||
|
|
233
|
+
!exactKeys(value, ["results"]) ||
|
|
234
|
+
!Array.isArray(value.results) ||
|
|
235
|
+
value.results.length !== request.accounts.length)
|
|
236
|
+
throw invalidResult();
|
|
237
|
+
const results = value.results.map(decodeStatus);
|
|
238
|
+
return results;
|
|
239
|
+
}
|
|
240
|
+
default:
|
|
241
|
+
throw invalidResult();
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
//# sourceMappingURL=hosted-presence-frames.js.map
|
|
@@ -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;AACH,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Unsubscribe } from "../remote/relay/types.js";
|
|
2
|
+
import type { DefaultSignalProtocolClient } from "./client.js";
|
|
3
|
+
import type { HostedRelayWakeClient } from "./hosted-push.js";
|
|
4
|
+
import { type HostedRelayPresenceAccount, type HostedRelayPresencePolicy, type HostedRelayPresenceStatus, type HostedRelayPresenceVisibility } from "./hosted-presence-frames.js";
|
|
5
|
+
export { HostedRelayPresenceError, type HostedRelayPresenceAccount, type HostedRelayPresenceApproximateLastSeen, type HostedRelayPresenceAudience, type HostedRelayPresenceErrorCode, type HostedRelayPresenceLastSeenPolicy, type HostedRelayPresenceMode, type HostedRelayPresencePolicy, type HostedRelayPresenceSetting, type HostedRelayPresenceStatus, type HostedRelayPresenceVisibility, } from "./hosted-presence-frames.js";
|
|
6
|
+
/** The interval of the `watch()` poll while the mailbox socket is connected. */
|
|
7
|
+
export declare const PRESENCE_WATCH_POLL_MILLISECONDS = 30000;
|
|
8
|
+
/**
|
|
9
|
+
* The presence of a hosted client with a mailbox subscription. Each request
|
|
10
|
+
* needs a connected socket and otherwise fails with `NOT_CONNECTED`.
|
|
11
|
+
*/
|
|
12
|
+
export interface HostedRelayPresence {
|
|
13
|
+
/** The project's presence policy, so the app can show or disable its toggle. */
|
|
14
|
+
policy(): Promise<HostedRelayPresencePolicy>;
|
|
15
|
+
/** The local account's setting and the visibility that applies. */
|
|
16
|
+
setting(): Promise<HostedRelayPresenceAccount>;
|
|
17
|
+
/**
|
|
18
|
+
* Writes the local account's setting. It fails with
|
|
19
|
+
* `PRESENCE_SETTING_FORCED` under the `forced` mode and with
|
|
20
|
+
* `INVALID_TRANSITION` under the `off` mode.
|
|
21
|
+
*/
|
|
22
|
+
setVisibility(visibility: HostedRelayPresenceVisibility): Promise<HostedRelayPresenceAccount>;
|
|
23
|
+
/**
|
|
24
|
+
* Reads the presence of each account, in the order given. A null result is
|
|
25
|
+
* the same for a hidden account, an unknown account, a missing or wrong
|
|
26
|
+
* key, and a project with presence off. The read sends the key that
|
|
27
|
+
* `grant()` stored for each account.
|
|
28
|
+
*/
|
|
29
|
+
read(accounts: readonly string[]): Promise<(HostedRelayPresenceStatus | null)[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Calls `onChange` with the account's presence, then again after each
|
|
32
|
+
* change. It reads every 30 s while the mailbox socket is connected, and at
|
|
33
|
+
* once when the socket connects. A failed read keeps the last value. After
|
|
34
|
+
* a `FRAME_REJECTED` read, it waits 30 s after the reconnect.
|
|
35
|
+
*/
|
|
36
|
+
watch(account: string, onChange: (status: HostedRelayPresenceStatus | null) => void): Unsubscribe;
|
|
37
|
+
/**
|
|
38
|
+
* Derives this account's presence key from its 32-byte profile key,
|
|
39
|
+
* registers the key with the Relay, and returns it. A new profile key
|
|
40
|
+
* revokes every old holder. With `hosted.profileKeys`, the SDK calls it
|
|
41
|
+
* when the profile key changes.
|
|
42
|
+
*/
|
|
43
|
+
accessKey(profileKey: Uint8Array): Promise<string>;
|
|
44
|
+
/**
|
|
45
|
+
* Stores the presence key that a contact sent, for later reads. With
|
|
46
|
+
* `hosted.profileKeys`, the SDK calls it for each contact profile key that
|
|
47
|
+
* it receives.
|
|
48
|
+
*/
|
|
49
|
+
grant(account: string, presenceKey: string): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The presence of a wake client: a hosted client in a push handler, a
|
|
53
|
+
* notification service extension, or a background task, which pulls its
|
|
54
|
+
* mailbox without a subscription. Each request is one authenticated HTTP
|
|
55
|
+
* request. A wake client has no `watch()`.
|
|
56
|
+
*/
|
|
57
|
+
export type HostedRelayWakePresence = Omit<HostedRelayPresence, "watch">;
|
|
58
|
+
/**
|
|
59
|
+
* The presence of a hosted client with a mailbox subscription. Every request
|
|
60
|
+
* goes over the socket, so start the subscription first. Each client has one
|
|
61
|
+
* presence object, and its watches share one poll.
|
|
62
|
+
*/
|
|
63
|
+
export declare function hostedRelayPresence(client: DefaultSignalProtocolClient): HostedRelayPresence;
|
|
64
|
+
/**
|
|
65
|
+
* The presence of a wake client, over HTTP. Use it only where the client runs
|
|
66
|
+
* no mailbox subscription, for example beside `pullHostedRelayAfterWake()`.
|
|
67
|
+
*/
|
|
68
|
+
export declare function hostedRelayWakePresence(client: HostedRelayWakeClient): HostedRelayWakePresence;
|
|
69
|
+
//# sourceMappingURL=hosted-presence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hosted-presence.d.ts","sourceRoot":"","sources":["../../client/hosted-presence.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAEV,WAAW,EACZ,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAC;AAE5D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE3D,OAAO,EAML,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,EAG9B,KAAK,yBAAyB,EAE9B,KAAK,6BAA6B,EACnC,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,wBAAwB,EACxB,KAAK,0BAA0B,EAC/B,KAAK,sCAAsC,EAC3C,KAAK,2BAA2B,EAChC,KAAK,4BAA4B,EACjC,KAAK,iCAAiC,EACtC,KAAK,uBAAuB,EAC5B,KAAK,yBAAyB,EAC9B,KAAK,0BAA0B,EAC/B,KAAK,yBAAyB,EAC9B,KAAK,6BAA6B,GACnC,MAAM,0BAA0B,CAAC;AAElC,gFAAgF;AAChF,eAAO,MAAM,gCAAgC,QAAS,CAAC;AAQvD;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,gFAAgF;IAChF,MAAM,IAAI,OAAO,CAAC,yBAAyB,CAAC,CAAC;IAC7C,mEAAmE;IACnE,OAAO,IAAI,OAAO,CAAC,0BAA0B,CAAC,CAAC;IAC/C;;;;OAIG;IACH,aAAa,CACX,UAAU,EAAE,6BAA6B,GACxC,OAAO,CAAC,0BAA0B,CAAC,CAAC;IACvC;;;;;OAKG;IACH,IAAI,CACF,QAAQ,EAAE,SAAS,MAAM,EAAE,GAC1B,OAAO,CAAC,CAAC,yBAAyB,GAAG,IAAI,CAAC,EAAE,CAAC,CAAC;IACjD;;;;;OAKG;IACH,KAAK,CACH,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,CAAC,MAAM,EAAE,yBAAyB,GAAG,IAAI,KAAK,IAAI,GAC3D,WAAW,CAAC;IACf;;;;;OAKG;IACH,SAAS,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACnD;;;;OAIG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5D;AAED;;;;;GAKG;AACH,MAAM,MAAM,uBAAuB,GAAG,IAAI,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC;AAyQzE;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,2BAA2B,GAClC,mBAAmB,CAsBrB;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,qBAAqB,GAC5B,uBAAuB,CAczB"}
|
|
@@ -0,0 +1,262 @@
|
|
|
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, assertPresenceAccount, assertPresenceKey, decodePresenceResult, } from "./hosted-presence-frames.js";
|
|
17
|
+
export { HostedRelayPresenceError, } from "./hosted-presence-frames.js";
|
|
18
|
+
/** The interval of the `watch()` poll while the mailbox socket is connected. */
|
|
19
|
+
export const PRESENCE_WATCH_POLL_MILLISECONDS = 30_000;
|
|
20
|
+
/** The HKDF info of the presence key. No other key uses this label. */
|
|
21
|
+
const PRESENCE_KEY_INFO = stringToBytes("open-e2ee-presence-key-v1");
|
|
22
|
+
const PRESENCE_KEY_BYTES = 16;
|
|
23
|
+
const PROFILE_KEY_BYTES = 32;
|
|
24
|
+
const PRESENCE_GRANT_METADATA_PREFIX = "hostedRelay.presenceGrant.v1:";
|
|
25
|
+
const runtimes = new WeakMap();
|
|
26
|
+
const presences = new WeakMap();
|
|
27
|
+
/** @internal Bind the SDK-owned transport to the client that uses it. */
|
|
28
|
+
export function bindHostedRelayPresenceRuntime(client, runtime) {
|
|
29
|
+
runtimes.set(client, runtime);
|
|
30
|
+
presences.delete(client);
|
|
31
|
+
}
|
|
32
|
+
function presenceRuntime(client) {
|
|
33
|
+
const runtime = runtimes.get(client);
|
|
34
|
+
if (runtime === undefined)
|
|
35
|
+
throw new Error("The client is not connected to the OpenE2EE Signal Protocol Relay");
|
|
36
|
+
return runtime;
|
|
37
|
+
}
|
|
38
|
+
/** @internal HKDF-SHA-256 over the profile key, with an empty salt, 16 bytes out. */
|
|
39
|
+
export async function derivePresenceKey(profileKey) {
|
|
40
|
+
if (!(profileKey instanceof Uint8Array) ||
|
|
41
|
+
profileKey.length !== PROFILE_KEY_BYTES)
|
|
42
|
+
throw new Error("Signal Protocol Relay profile key is invalid");
|
|
43
|
+
return bytesToUrlSafeBase64(await hkdf(profileKey, new Uint8Array(0), PRESENCE_KEY_INFO, PRESENCE_KEY_BYTES));
|
|
44
|
+
}
|
|
45
|
+
function grantMetadataKey(runtime, account) {
|
|
46
|
+
return `${PRESENCE_GRANT_METADATA_PREFIX}${runtime.presenceScope}:${account}`;
|
|
47
|
+
}
|
|
48
|
+
function presenceOperations(runtime, send) {
|
|
49
|
+
const request = async (value) => decodePresenceResult(value, await send(value));
|
|
50
|
+
const target = async (account) => {
|
|
51
|
+
const stored = await runtime.presenceStore.getMetadata(grantMetadataKey(runtime, account));
|
|
52
|
+
return stored === null
|
|
53
|
+
? { account }
|
|
54
|
+
: { account, presenceKey: assertPresenceKey(stored) };
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
policy: () => request({ type: "presence-policy" }),
|
|
58
|
+
setting: () => request({ type: "presence-account" }),
|
|
59
|
+
setVisibility: (visibility) => request({ type: "presence-setting", setting: visibility }),
|
|
60
|
+
read: async (accounts) => {
|
|
61
|
+
if (!Array.isArray(accounts))
|
|
62
|
+
throw new Error("Signal Protocol Relay presence read is invalid");
|
|
63
|
+
accounts.forEach(assertPresenceAccount);
|
|
64
|
+
const targets = await Promise.all(accounts.map(target));
|
|
65
|
+
const results = [];
|
|
66
|
+
for (let start = 0; start < targets.length; start += PRESENCE_READ_LIMIT)
|
|
67
|
+
results.push(...(await request({
|
|
68
|
+
type: "presence-read",
|
|
69
|
+
accounts: targets.slice(start, start + PRESENCE_READ_LIMIT),
|
|
70
|
+
})));
|
|
71
|
+
return results;
|
|
72
|
+
},
|
|
73
|
+
accessKey: async (profileKey) => {
|
|
74
|
+
const presenceKey = await derivePresenceKey(profileKey);
|
|
75
|
+
await request({ type: "presence-key", presenceKey });
|
|
76
|
+
return presenceKey;
|
|
77
|
+
},
|
|
78
|
+
grant: async (account, presenceKey) => {
|
|
79
|
+
await runtime.presenceStore.setMetadata(grantMetadataKey(runtime, assertPresenceAccount(account)), assertPresenceKey(presenceKey));
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
function sameStatus(left, right) {
|
|
84
|
+
if (left === null || right === null)
|
|
85
|
+
return left === right;
|
|
86
|
+
return left.online === right.online && left.lastSeen === right.lastSeen;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* One poll for every watched account of a client. It runs only while the
|
|
90
|
+
* mailbox socket is connected, which the lifecycle binding limits to the
|
|
91
|
+
* foreground.
|
|
92
|
+
*/
|
|
93
|
+
class PresenceWatch {
|
|
94
|
+
runtime;
|
|
95
|
+
read;
|
|
96
|
+
watched = new Map();
|
|
97
|
+
timer;
|
|
98
|
+
polling = false;
|
|
99
|
+
pollAgain = false;
|
|
100
|
+
/**
|
|
101
|
+
* The Signal Protocol Relay closed the socket on the last read frame. The
|
|
102
|
+
* next read waits one full interval after the reconnect, so a Relay without
|
|
103
|
+
* presence frames does not see a reconnect loop.
|
|
104
|
+
*/
|
|
105
|
+
rejected = false;
|
|
106
|
+
stopStateListener;
|
|
107
|
+
constructor(runtime, read) {
|
|
108
|
+
this.runtime = runtime;
|
|
109
|
+
this.read = read;
|
|
110
|
+
}
|
|
111
|
+
watch(account, onChange) {
|
|
112
|
+
assertPresenceAccount(account);
|
|
113
|
+
if (typeof onChange !== "function")
|
|
114
|
+
throw new Error("Signal Protocol Relay presence listener is invalid");
|
|
115
|
+
let entry = this.watched.get(account);
|
|
116
|
+
if (entry === undefined) {
|
|
117
|
+
entry = { listeners: new Set(), known: false, status: null };
|
|
118
|
+
this.watched.set(account, entry);
|
|
119
|
+
}
|
|
120
|
+
const watchedEntry = entry;
|
|
121
|
+
// Each call owns its own listener, so one callback can watch twice.
|
|
122
|
+
const listener = (status) => onChange(status);
|
|
123
|
+
watchedEntry.listeners.add(listener);
|
|
124
|
+
this.stopStateListener ??= this.runtime.subscribeRelayConnectionState((state) => {
|
|
125
|
+
if (state.state !== "connected")
|
|
126
|
+
this.cancel();
|
|
127
|
+
else if (this.rejected)
|
|
128
|
+
this.schedule(PRESENCE_WATCH_POLL_MILLISECONDS);
|
|
129
|
+
else
|
|
130
|
+
this.pollSoon();
|
|
131
|
+
});
|
|
132
|
+
if (watchedEntry.known) {
|
|
133
|
+
queueMicrotask(() => {
|
|
134
|
+
if (watchedEntry.listeners.has(listener))
|
|
135
|
+
notify(listener, watchedEntry.status);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
else
|
|
139
|
+
this.pollSoon();
|
|
140
|
+
return () => {
|
|
141
|
+
if (!watchedEntry.listeners.delete(listener))
|
|
142
|
+
return;
|
|
143
|
+
if (watchedEntry.listeners.size === 0 &&
|
|
144
|
+
this.watched.get(account) === watchedEntry)
|
|
145
|
+
this.watched.delete(account);
|
|
146
|
+
if (this.watched.size > 0)
|
|
147
|
+
return;
|
|
148
|
+
this.cancel();
|
|
149
|
+
this.stopStateListener?.();
|
|
150
|
+
this.stopStateListener = undefined;
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
connected() {
|
|
154
|
+
return this.runtime.relayConnectionState.state === "connected";
|
|
155
|
+
}
|
|
156
|
+
cancel() {
|
|
157
|
+
clearTimeout(this.timer);
|
|
158
|
+
this.timer = undefined;
|
|
159
|
+
}
|
|
160
|
+
schedule(milliseconds) {
|
|
161
|
+
this.cancel();
|
|
162
|
+
this.timer = setTimeout(() => {
|
|
163
|
+
this.timer = undefined;
|
|
164
|
+
void this.poll();
|
|
165
|
+
}, milliseconds);
|
|
166
|
+
}
|
|
167
|
+
/** Reads at the next turn, so watches that start together share one read. */
|
|
168
|
+
pollSoon() {
|
|
169
|
+
if (!this.connected() || this.watched.size === 0)
|
|
170
|
+
return;
|
|
171
|
+
if (this.polling)
|
|
172
|
+
this.pollAgain = true;
|
|
173
|
+
else
|
|
174
|
+
this.schedule(0);
|
|
175
|
+
}
|
|
176
|
+
async poll() {
|
|
177
|
+
if (this.polling || !this.connected() || this.watched.size === 0)
|
|
178
|
+
return;
|
|
179
|
+
this.polling = true;
|
|
180
|
+
this.pollAgain = false;
|
|
181
|
+
const accounts = [...this.watched.keys()];
|
|
182
|
+
try {
|
|
183
|
+
const results = await this.read(accounts);
|
|
184
|
+
this.rejected = false;
|
|
185
|
+
accounts.forEach((account, index) => {
|
|
186
|
+
const entry = this.watched.get(account);
|
|
187
|
+
const status = results[index] ?? null;
|
|
188
|
+
if (entry === undefined || (entry.known && sameStatus(entry.status, status)))
|
|
189
|
+
return;
|
|
190
|
+
entry.known = true;
|
|
191
|
+
entry.status = status;
|
|
192
|
+
for (const listener of [...entry.listeners])
|
|
193
|
+
notify(listener, status);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
// A failed read keeps the last value. The next poll reads again.
|
|
198
|
+
if (error instanceof HostedRelayPresenceError &&
|
|
199
|
+
error.code === "FRAME_REJECTED")
|
|
200
|
+
this.rejected = true;
|
|
201
|
+
}
|
|
202
|
+
finally {
|
|
203
|
+
this.polling = false;
|
|
204
|
+
if (this.connected() && this.watched.size > 0)
|
|
205
|
+
this.schedule(this.pollAgain ? 0 : PRESENCE_WATCH_POLL_MILLISECONDS);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/** A listener that throws does not stop the others or the poll. */
|
|
210
|
+
function notify(listener, status) {
|
|
211
|
+
try {
|
|
212
|
+
listener(status);
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
queueMicrotask(() => {
|
|
216
|
+
throw error;
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* The presence of a hosted client with a mailbox subscription. Every request
|
|
222
|
+
* goes over the socket, so start the subscription first. Each client has one
|
|
223
|
+
* presence object, and its watches share one poll.
|
|
224
|
+
*/
|
|
225
|
+
export function hostedRelayPresence(client) {
|
|
226
|
+
const existing = presences.get(client);
|
|
227
|
+
if (existing !== undefined)
|
|
228
|
+
return existing;
|
|
229
|
+
const runtime = presenceRuntime(client);
|
|
230
|
+
// Every request goes over the socket, never over HTTP.
|
|
231
|
+
const operations = presenceOperations(runtime, async (request) => {
|
|
232
|
+
const socket = runtime.presenceSocket;
|
|
233
|
+
if (socket === undefined)
|
|
234
|
+
throw new HostedRelayPresenceError("NOT_CONNECTED", "The mailbox subscription is not running", true);
|
|
235
|
+
return socket.presence(request);
|
|
236
|
+
});
|
|
237
|
+
const watch = new PresenceWatch(runtime, operations.read);
|
|
238
|
+
const presence = {
|
|
239
|
+
...operations,
|
|
240
|
+
watch: (account, onChange) => watch.watch(account, onChange),
|
|
241
|
+
};
|
|
242
|
+
presences.set(client, presence);
|
|
243
|
+
return presence;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* The presence of a wake client, over HTTP. Use it only where the client runs
|
|
247
|
+
* no mailbox subscription, for example beside `pullHostedRelayAfterWake()`.
|
|
248
|
+
*/
|
|
249
|
+
export function hostedRelayWakePresence(client) {
|
|
250
|
+
const runtime = presenceRuntime(client);
|
|
251
|
+
return presenceOperations(runtime, async (request) => {
|
|
252
|
+
try {
|
|
253
|
+
return await runtime.postPresence(request);
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
if (!(error instanceof HostedRelayHttpError))
|
|
257
|
+
throw error;
|
|
258
|
+
throw new HostedRelayPresenceError(error.code, error.message, error.retryable);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
//# 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;AAS/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,qBAAqB,EACrB,iBAAiB,EACjB,oBAAoB,GAQrB,MAAM,0BAA0B,CAAC;AA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,QAAQ,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;IACH,MAAM,KAAK,GAAG,IAAI,aAAa,CAAC,OAAO,EAAE,UAAU,CAAC,IAAI,CAAC,CAAC;IAC1D,MAAM,QAAQ,GAAwB;QACpC,GAAG,UAAU;QACb,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"}
|