@open-e2ee/signal-protocol-sdk 14.3.0 → 14.4.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 +70 -0
- package/README.md +1 -1
- package/SECURITY.md +2 -2
- package/dist/client/delivery-status.d.ts.map +1 -1
- package/dist/client/delivery-status.js +8 -7
- package/dist/client/delivery-status.js.map +1 -1
- package/dist/client/hosted-anonymous-delivery.d.ts +10 -4
- package/dist/client/hosted-anonymous-delivery.d.ts.map +1 -1
- package/dist/client/hosted-anonymous-delivery.js +17 -8
- package/dist/client/hosted-anonymous-delivery.js.map +1 -1
- package/dist/client/hosted-device-link-transport.d.ts +6 -2
- package/dist/client/hosted-device-link-transport.d.ts.map +1 -1
- package/dist/client/hosted-device-link-transport.js +10 -5
- package/dist/client/hosted-device-link-transport.js.map +1 -1
- package/dist/client/hosted-group-authority.d.ts +4 -2
- package/dist/client/hosted-group-authority.d.ts.map +1 -1
- package/dist/client/hosted-group-authority.js +10 -7
- package/dist/client/hosted-group-authority.js.map +1 -1
- package/dist/client/hosted-groups.d.ts +8 -3
- package/dist/client/hosted-groups.d.ts.map +1 -1
- package/dist/client/hosted-groups.js +15 -9
- package/dist/client/hosted-groups.js.map +1 -1
- package/dist/client/hosted-mailbox-subscription.d.ts +6 -2
- package/dist/client/hosted-mailbox-subscription.d.ts.map +1 -1
- package/dist/client/hosted-mailbox-subscription.js +20 -8
- package/dist/client/hosted-mailbox-subscription.js.map +1 -1
- package/dist/client/hosted-sandbox-identity.d.ts +23 -19
- package/dist/client/hosted-sandbox-identity.d.ts.map +1 -1
- package/dist/client/hosted-sandbox-identity.js +23 -19
- package/dist/client/hosted-sandbox-identity.js.map +1 -1
- package/dist/client/hosted-store-records.d.ts +22 -17
- package/dist/client/hosted-store-records.d.ts.map +1 -1
- package/dist/client/hosted-store-records.js +15 -10
- package/dist/client/hosted-store-records.js.map +1 -1
- package/dist/client/hosted-transport.d.ts +10 -6
- package/dist/client/hosted-transport.d.ts.map +1 -1
- package/dist/client/hosted-transport.js +132 -87
- package/dist/client/hosted-transport.js.map +1 -1
- package/dist/client/hosted.d.ts +15 -4
- package/dist/client/hosted.d.ts.map +1 -1
- package/dist/client/hosted.js +6 -6
- package/dist/client/hosted.js.map +1 -1
- package/dist/client/receive-work-seed.d.ts +4 -4
- package/dist/client/receive-work-seed.d.ts.map +1 -1
- package/dist/client/receive-work-seed.js +1 -1
- package/dist/client/receive-work-seed.js.map +1 -1
- package/dist/client/signal-relay-protocol.d.ts +83 -18
- package/dist/client/signal-relay-protocol.d.ts.map +1 -1
- package/dist/client/signal-relay-protocol.js +186 -15
- package/dist/client/signal-relay-protocol.js.map +1 -1
- package/dist/client/signal-relay-subscription.js +1 -1
- package/dist/client/signal-relay-subscription.js.map +1 -1
- package/dist/local/store/receive-work.d.ts +5 -5
- package/dist/local/store/receive-work.d.ts.map +1 -1
- package/dist/local/store/receive-work.js +10 -12
- package/dist/local/store/receive-work.js.map +1 -1
- package/dist/local/store/reliability.d.ts +7 -4
- package/dist/local/store/reliability.d.ts.map +1 -1
- package/dist/local/store/reliability.js.map +1 -1
- package/dist/types/api.d.ts +12 -9
- package/dist/types/api.d.ts.map +1 -1
- package/docs/ASSURANCE.md +3 -3
- package/package.json +1 -1
|
@@ -8,21 +8,26 @@ export function hostedStoreRecordKey(prefix, suffix) {
|
|
|
8
8
|
/**
|
|
9
9
|
* The stored value of a record, or `null` when neither key holds one. The
|
|
10
10
|
* current key wins when the store holds both keys.
|
|
11
|
+
*
|
|
12
|
+
* When only the earlier key holds the record, the read copies it to the
|
|
13
|
+
* current key and keeps the earlier key. The copy writes only an absent
|
|
14
|
+
* current key. When a concurrent write fills the current key first, the read
|
|
15
|
+
* returns that value.
|
|
11
16
|
*/
|
|
12
17
|
export async function readHostedStoreRecord(store, key) {
|
|
13
18
|
const current = await store.getMetadata(key.current);
|
|
14
|
-
|
|
19
|
+
if (current !== null)
|
|
20
|
+
return current;
|
|
21
|
+
const earlier = await store.getMetadata(key.earlier);
|
|
22
|
+
if (earlier === null)
|
|
23
|
+
return null;
|
|
24
|
+
if (await store.compareAndSetMetadata(key.current, null, earlier))
|
|
25
|
+
return earlier;
|
|
26
|
+
return store.getMetadata(key.current);
|
|
15
27
|
}
|
|
16
|
-
/**
|
|
17
|
-
* Stores a record under its earlier key. It first replaces a current key that
|
|
18
|
-
* the store holds, so that a failure between the two writes leaves the newer
|
|
19
|
-
* value under the key that a read prefers.
|
|
20
|
-
*/
|
|
28
|
+
/** Stores a record under its current key. The earlier key keeps its value. */
|
|
21
29
|
export async function writeHostedStoreRecord(store, key, value) {
|
|
22
|
-
|
|
23
|
-
await store.setMetadata(key.current, value);
|
|
24
|
-
}
|
|
25
|
-
await store.setMetadata(key.earlier, value);
|
|
30
|
+
await store.setMetadata(key.current, value);
|
|
26
31
|
}
|
|
27
32
|
/** Deletes both keys of a record, so a read finds no earlier value. */
|
|
28
33
|
export async function deleteHostedStoreRecord(store, key) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hosted-store-records.js","sourceRoot":"","sources":["../../client/hosted-store-records.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hosted-store-records.js","sourceRoot":"","sources":["../../client/hosted-store-records.ts"],"names":[],"mappings":"AAqCA,iEAAiE;AACjE,MAAM,UAAU,oBAAoB,CAClC,MAA+B,EAC/B,MAAc;IAEd,OAAO;QACL,OAAO,EAAE,GAAG,MAAM,CAAC,OAAO,GAAG,MAAM,EAAE;QACrC,OAAO,EAAE,GAAG,MAAM,CAAC,OAAO,GAAG,MAAM,EAAE;KACtC,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,KAAmB,EACnB,GAAyB;IAEzB,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACrD,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,OAAO,CAAC;IACrC,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACrD,IAAI,OAAO,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAClC,IAAI,MAAM,KAAK,CAAC,qBAAqB,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC;QAAE,OAAO,OAAO,CAAC;IAClF,OAAO,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACxC,CAAC;AAED,8EAA8E;AAC9E,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,KAAmB,EACnB,GAAyB,EACzB,KAAa;IAEb,MAAM,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AAC9C,CAAC;AAED,uEAAuE;AACvE,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,KAAoB,EACpB,GAAyB;IAEzB,MAAM,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACxC,MAAM,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -9,6 +9,7 @@ import type { HostedMailboxPage, HostedSignalProtocolRelayPushRegistration, Host
|
|
|
9
9
|
import type { HostedSignalProtocolRelayPresenceRuntime } from "./hosted-presence.js";
|
|
10
10
|
import { type HostedSignalProtocolRelayPresenceRequest } from "./hosted-presence-frames.js";
|
|
11
11
|
import { type MailboxSubscriptionHandle, type PresenceSocketEvent } from "./hosted-mailbox-subscription.js";
|
|
12
|
+
import { SignalRelayProtocolOffer } from "./signal-relay-protocol.js";
|
|
12
13
|
import { type StoredHostedPendingPreKeyPublication, type StoredHostedPreKeyPublication } from "./hosted-prekey-publication.js";
|
|
13
14
|
import { type SignalProtocolRelayDeliveryReceipt } from "./signal-relay-receipt-intake.js";
|
|
14
15
|
interface StoredHostedSignalProtocolRelaySession {
|
|
@@ -66,10 +67,11 @@ export declare class HostedSignalProtocolRelayHttpTransport implements SignalPro
|
|
|
66
67
|
private readonly receiptJoin;
|
|
67
68
|
constructor(connection: HostedSignalProtocolRelayConnection, storage: SignalProtocolLocalStore, deviceAuthentication: HostedSignalProtocolRelayDeviceAuthentication, session: StoredHostedSignalProtocolRelaySession, persistRefreshedToken?: boolean,
|
|
68
69
|
/**
|
|
69
|
-
* @internal The Relay protocol version
|
|
70
|
-
* transport.
|
|
70
|
+
* @internal The selected Relay protocol version, or the offer of the
|
|
71
|
+
* client that owns this transport. Without it, the transport offers
|
|
72
|
+
* version 3 first and falls back to version 2.
|
|
71
73
|
*/
|
|
72
|
-
|
|
74
|
+
signalRelayProtocol?: number | SignalRelayProtocolOffer);
|
|
73
75
|
get accountId(): string;
|
|
74
76
|
get deviceId(): number;
|
|
75
77
|
readonly objectStore: SignalProtocolRemoteObjectStore;
|
|
@@ -127,8 +129,10 @@ export declare class HostedSignalProtocolRelayHttpTransport implements SignalPro
|
|
|
127
129
|
*/
|
|
128
130
|
private publishCurrentPrekeys;
|
|
129
131
|
/**
|
|
130
|
-
* One mailbox page. Its
|
|
131
|
-
* carries `receipts` only when it is true.
|
|
132
|
+
* One mailbox page. Its receipts capability holds for this pull only: a
|
|
133
|
+
* page carries `receipts` only when it is true. Version 3 names the
|
|
134
|
+
* capability `signalRelayReceipts`, and versions 1 and 2 name it
|
|
135
|
+
* `relayReceipts`. With `cursor`, the page starts
|
|
132
136
|
* after the last message of the page that issued it. The cursor is opaque.
|
|
133
137
|
* A page without `retainedWork` comes from a Relay that does not report
|
|
134
138
|
* it, so the retained work after the page is unknown. A page without
|
|
@@ -179,7 +183,7 @@ export declare class HostedSignalProtocolRelayHttpTransport implements SignalPro
|
|
|
179
183
|
registerPush(registration: HostedSignalProtocolRelayPushRegistration): Promise<void>;
|
|
180
184
|
removePush(): Promise<void>;
|
|
181
185
|
get presenceScope(): string;
|
|
182
|
-
get presenceStore(): Pick<SignalProtocolLocalStore, "getMetadata" | "setMetadata">;
|
|
186
|
+
get presenceStore(): Pick<SignalProtocolLocalStore, "getMetadata" | "setMetadata" | "compareAndSetMetadata">;
|
|
183
187
|
/** The live mailbox socket, or `undefined` while no subscription runs. */
|
|
184
188
|
get presenceSocket(): MailboxSubscriptionHandle | undefined;
|
|
185
189
|
/** Receives the presence events of the newest subscription's socket. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hosted-transport.d.ts","sourceRoot":"","sources":["../../client/hosted-transport.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,2BAA2B,EAC3B,uBAAuB,EACvB,WAAW,EACX,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,QAAQ,EACR,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,yBAAyB,EACzB,8BAA8B,EAC9B,YAAY,EACZ,eAAe,EACf,qBAAqB,EACrB,YAAY,EACZ,kCAAkC,EAClC,gBAAgB,EAChB,WAAW,EACZ,MAAM,8BAA8B,CAAC;AAEtC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAiBvE,OAAO,KAAK,EAAU,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAGjE,OAAO,KAAK,EAAE,mCAAmC,EAAE,MAAM,qBAAqB,CAAC;AAC/E,OAAO,KAAK,EACV,6CAA6C,EAE7C,4CAA4C,EAC5C,iDAAiD,EACjD,gDAAgD,EACjD,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAMV,+BAA+B,EAChC,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EACV,iBAAiB,EACjB,yCAAyC,EACzC,oCAAoC,EACrC,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,wCAAwC,EAAE,MAAM,mBAAmB,CAAC;AAClF,OAAO,EAEL,KA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CAAC,wCAAwC,CAAC,CA8FnD;AAED,wBAAsB,wCAAwC,CAAC,OAAO,EAAE;IACtE,QAAQ,CAAC,UAAU,EAAE,mCAAmC,CAAC;IACzD,QAAQ,CAAC,oBAAoB,EAAE,6CAA6C,CAAC;IAC7E,QAAQ,CAAC,OAAO,EAAE,wBAAwB,CAAC;CAK5C,GAAG,OAAO,CAAC,wCAAwC,GAAG,SAAS,CAAC,CAgDhE;AAED,iFAAiF;AACjF,wBAAsB,sCAAsC,CAAC,OAAO,EAAE;IACpE,QAAQ,CAAC,UAAU,EAAE,mCAAmC,CAAC;IACzD,QAAQ,CAAC,aAAa,EAAE,wBAAwB,CAAC;IACjD,QAAQ,CAAC,OAAO,EAAE,wBAAwB,CAAC;IAC3C,QAAQ,CAAC,OAAO,EAAE,iDAAiD,CAAC;CACrE,GAAG,OAAO,CAAC,wCAAwC,GAAG,gDAAgD,CAAC,CAQvG"}
|
|
@@ -11,7 +11,7 @@ import { SignalProtocolRelayConnectionStateOwner } from "../remote/signal-relay/
|
|
|
11
11
|
import { presenceHttpBody, } from "./hosted-presence-frames.js";
|
|
12
12
|
import { subscribeHostedMailbox, } from "./hosted-mailbox-subscription.js";
|
|
13
13
|
import { HostedGroupServer } from "./hosted-groups.js";
|
|
14
|
-
import {
|
|
14
|
+
import { SignalRelayProtocolOffer, markSignalProtocolRelayAnswerVersion, sendOnSignalRelayProtocol, signalRelayProofLabels, signalRelayProtocolHeadersFor, signalRelayProtocolOffer, signalRelayRenamedField, throwIfProtocolFallBack, throwIfUpgradeRequired, } from "./signal-relay-protocol.js";
|
|
15
15
|
import { HostedSignalProtocolRelayDeviceUnknownError, throwIfDeviceRevoked, } from "./hosted-device-standing.js";
|
|
16
16
|
import { HostedAnonymousDelivery, HostedAnonymousDeliveryError, decodeHostedAnonymousEnvelope, } from "./hosted-anonymous-delivery.js";
|
|
17
17
|
import { createAdapterSignalProtocolRelayFanOut, rethrowSignalProtocolRelayWorkStopped } from "./signal-relay-work.js";
|
|
@@ -32,11 +32,12 @@ const DEVICE_TOKEN_REFRESH_SECONDS = 60;
|
|
|
32
32
|
const MAXIMUM_RESPONSE_BYTES = 1024 * 1024;
|
|
33
33
|
const PREKEY_EXPIRY_MILLISECONDS = 30 * 24 * 60 * 60 * 1000;
|
|
34
34
|
const DELIVERY_WIRE_VERSION = 1;
|
|
35
|
-
|
|
35
|
+
/**
|
|
36
|
+
* The registration material label. Every protocol version frames the
|
|
37
|
+
* material fingerprint with these bytes, and the Relay stores the
|
|
38
|
+
* fingerprint, so the label never changes.
|
|
39
|
+
*/
|
|
36
40
|
const REGISTRATION_MATERIAL_LABEL = stringToBytes("OpenE2EE Relay registration material v1\0");
|
|
37
|
-
const REGISTRATION_CHALLENGE_LABEL = stringToBytes("OpenE2EE Relay registration challenge v1\0");
|
|
38
|
-
const RECOVERY_CHALLENGE_LABEL = stringToBytes("OpenE2EE Relay recovery challenge v1\0");
|
|
39
|
-
const TOKEN_REFRESH_CHALLENGE_LABEL = stringToBytes("OpenE2EE Relay device token refresh challenge v1\0");
|
|
40
41
|
/** The rotation inventory that one status read describes. */
|
|
41
42
|
function inventoryFromStatus(status) {
|
|
42
43
|
const metadata = (algorithm) => {
|
|
@@ -165,9 +166,11 @@ function identifiedEndpoint(connection) {
|
|
|
165
166
|
/**
|
|
166
167
|
* Read the body of a Relay answer. An error answer throws, and the error
|
|
167
168
|
* records `signalRelayProtocolVersion`, the protocol version of the request that
|
|
168
|
-
* it answers.
|
|
169
|
+
* it answers. When the Relay refuses that version and `offer` falls back,
|
|
170
|
+
* the answer throws for `sendOnSignalRelayProtocol`, which sends the request
|
|
171
|
+
* again.
|
|
169
172
|
*/
|
|
170
|
-
async function parseResponse(response, signalRelayProtocolVersion) {
|
|
173
|
+
async function parseResponse(response, signalRelayProtocolVersion, offer) {
|
|
171
174
|
const body = await response.text();
|
|
172
175
|
if (body.length > MAXIMUM_RESPONSE_BYTES) {
|
|
173
176
|
throw new Error("Signal Protocol Relay response is too large");
|
|
@@ -188,10 +191,12 @@ async function parseResponse(response, signalRelayProtocolVersion) {
|
|
|
188
191
|
if (!response.ok) {
|
|
189
192
|
// `UPGRADE_REQUIRED` and `DEVICE_REVOKED` are terminal at any error
|
|
190
193
|
// status, so `authenticatedPost` and every other retry, which matches only
|
|
191
|
-
// a `HostedSignalProtocolRelayHttpError`, never repeat them.
|
|
194
|
+
// a `HostedSignalProtocolRelayHttpError`, never repeat them. A refused
|
|
195
|
+
// version 3 moves the offer to version 2. Any other `PROTOCOL_UNSUPPORTED`
|
|
192
196
|
// stays a `HostedSignalProtocolRelayHttpError` whose `retryable` is true: the Relay
|
|
193
197
|
// sends it for a version above the newest one that it serves, which
|
|
194
198
|
// happens only after a Relay rollback.
|
|
199
|
+
throwIfProtocolFallBack(offer, signalRelayProtocolVersion, parsed);
|
|
195
200
|
throwIfUpgradeRequired(response.status, parsed, signalRelayProtocolVersion);
|
|
196
201
|
throwIfDeviceRevoked(response.status, parsed);
|
|
197
202
|
const error = record(parsed) && record(parsed.error) ? parsed.error : {};
|
|
@@ -215,32 +220,51 @@ async function parseResponse(response, signalRelayProtocolVersion) {
|
|
|
215
220
|
function missingDestination(userId, deviceId) {
|
|
216
221
|
return markSignalProtocolRelayDeviceRefusal(new Error("Signal Protocol Relay destination device does not exist"), { code: "NOT_FOUND", userId, deviceId });
|
|
217
222
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
223
|
+
/**
|
|
224
|
+
* Post a JSON body with the version that `offer` holds. A body that signs
|
|
225
|
+
* a proof is a function of the version, because each version signs its own
|
|
226
|
+
* labels. When the Relay refuses version 3, the post runs once more with
|
|
227
|
+
* version 2.
|
|
228
|
+
*/
|
|
229
|
+
async function postJson(connection, offer, path, body, token) {
|
|
230
|
+
return sendOnSignalRelayProtocol(offer, async (signalRelayProtocolVersion) => {
|
|
231
|
+
const headers = new Headers({
|
|
232
|
+
accept: "application/json",
|
|
233
|
+
"content-type": "application/json",
|
|
234
|
+
...signalRelayProtocolHeadersFor(signalRelayProtocolVersion),
|
|
235
|
+
});
|
|
236
|
+
if (token !== undefined)
|
|
237
|
+
headers.set("authorization", `Bearer ${token}`);
|
|
238
|
+
const json = JSON.stringify(typeof body === "function" ? await body(signalRelayProtocolVersion) : body);
|
|
239
|
+
return withSignalProtocolRelayRequestDeadline(async (signal) => {
|
|
240
|
+
let response;
|
|
241
|
+
try {
|
|
242
|
+
response = await fetch(`${identifiedEndpoint(connection)}${path}`, {
|
|
243
|
+
body: json,
|
|
244
|
+
headers,
|
|
245
|
+
method: "POST",
|
|
246
|
+
credentials: "omit",
|
|
247
|
+
redirect: "error",
|
|
248
|
+
signal,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
catch (cause) {
|
|
252
|
+
throw new Error("Signal Protocol Relay request could not be completed", { cause });
|
|
253
|
+
}
|
|
254
|
+
return parseResponse(response, signalRelayProtocolVersion, offer);
|
|
255
|
+
});
|
|
242
256
|
});
|
|
243
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* The scope ID of a device response. Version 3 names the field
|
|
260
|
+
* `signalRelayScopeId`, and versions 1 and 2 name it `relayScopeId`.
|
|
261
|
+
*/
|
|
262
|
+
function responseScopeId(value, invalid) {
|
|
263
|
+
const scopeId = signalRelayRenamedField(value, "signalRelayScopeId", "relayScopeId", invalid);
|
|
264
|
+
if (typeof scopeId !== "string")
|
|
265
|
+
throw new Error(invalid);
|
|
266
|
+
return scopeId;
|
|
267
|
+
}
|
|
244
268
|
function serializedPreKey(prekey) {
|
|
245
269
|
return {
|
|
246
270
|
algorithm: prekey.algorithm,
|
|
@@ -278,10 +302,11 @@ async function registrationMaterialFingerprint(identity, registrationId, prekeys
|
|
|
278
302
|
lengthPrefixed(prekey.signature ?? new Uint8Array()),
|
|
279
303
|
]))));
|
|
280
304
|
}
|
|
281
|
-
async function registrationChallenge(request) {
|
|
305
|
+
async function registrationChallenge(request, signalRelayProtocolVersion) {
|
|
306
|
+
const labels = signalRelayProofLabels(signalRelayProtocolVersion);
|
|
282
307
|
return sha256(concatBytes(request.assertionPurpose === "recover"
|
|
283
|
-
?
|
|
284
|
-
:
|
|
308
|
+
? labels.recoveryChallenge
|
|
309
|
+
: labels.registrationChallenge, text(signalProtocolRelayScopeId(request.connection)), text(await hostedAssertionIdentifier(request.assertion, request.assertionPurpose, request.operationId)), text(request.operationId), text(await registrationMaterialFingerprint(request.signalIdentity, request.registrationId, request.registrationPreKeys))));
|
|
285
310
|
}
|
|
286
311
|
async function sessionMetadataKey(connection) {
|
|
287
312
|
return hostedStoreRecordKey(SESSION_METADATA_PREFIX, bytesToUrlSafeBase64(await sha256(concatBytes(stringToBytes(connection.publishableKey), new Uint8Array([0]), connection.relayScopeId))));
|
|
@@ -453,9 +478,13 @@ export class HostedSignalProtocolRelayHttpTransport {
|
|
|
453
478
|
deviceAuthentication;
|
|
454
479
|
session;
|
|
455
480
|
persistRefreshedToken;
|
|
456
|
-
signalRelayProtocolVersion;
|
|
457
481
|
groups;
|
|
458
482
|
groupServer;
|
|
483
|
+
/**
|
|
484
|
+
* @internal The Relay protocol version of the client that owns this
|
|
485
|
+
* transport. Every carrier of the client reads it for each request.
|
|
486
|
+
*/
|
|
487
|
+
signalRelayProtocol;
|
|
459
488
|
anonymousDelivery;
|
|
460
489
|
// The relay request bound of the client that uses this transport
|
|
461
490
|
fanOut;
|
|
@@ -471,16 +500,17 @@ export class HostedSignalProtocolRelayHttpTransport {
|
|
|
471
500
|
receiptJoin = new SignalProtocolRelayReceiptJoin();
|
|
472
501
|
constructor(connection, storage, deviceAuthentication, session, persistRefreshedToken = true,
|
|
473
502
|
/**
|
|
474
|
-
* @internal The Relay protocol version
|
|
475
|
-
* transport.
|
|
503
|
+
* @internal The selected Relay protocol version, or the offer of the
|
|
504
|
+
* client that owns this transport. Without it, the transport offers
|
|
505
|
+
* version 3 first and falls back to version 2.
|
|
476
506
|
*/
|
|
477
|
-
|
|
507
|
+
signalRelayProtocol) {
|
|
478
508
|
this.connection = connection;
|
|
479
509
|
this.storage = storage;
|
|
480
510
|
this.deviceAuthentication = deviceAuthentication;
|
|
481
511
|
this.session = session;
|
|
482
512
|
this.persistRefreshedToken = persistRefreshedToken;
|
|
483
|
-
this.
|
|
513
|
+
this.signalRelayProtocol = signalRelayProtocolOffer(signalRelayProtocol);
|
|
484
514
|
// The Relay refuses a removed device's mailbox on every send path before
|
|
485
515
|
// its device list shows the removal, so a direct send may post first.
|
|
486
516
|
declareRefusesRemovedDevices(this);
|
|
@@ -492,7 +522,7 @@ export class HostedSignalProtocolRelayHttpTransport {
|
|
|
492
522
|
// each acknowledgment with the messages whose receipt it owns.
|
|
493
523
|
declareSignalProtocolRelayReceiptIntake(this, this.receiptInbox);
|
|
494
524
|
declareSignalProtocolRelayReceiptJoin(this, this.receiptJoin);
|
|
495
|
-
this.groups = new HostedGroupServer(connection,
|
|
525
|
+
this.groups = new HostedGroupServer(connection, this.signalRelayProtocol);
|
|
496
526
|
this.groupServer = {
|
|
497
527
|
server: this.groups,
|
|
498
528
|
issueAuthCredential: (userId, authorityKeyId) => this.issueAuthCredential(userId, authorityKeyId),
|
|
@@ -512,7 +542,11 @@ export class HostedSignalProtocolRelayHttpTransport {
|
|
|
512
542
|
if (generation === undefined)
|
|
513
543
|
throw missingDestination(accountAddress, deviceId);
|
|
514
544
|
return { accountAddress, deviceId, generation };
|
|
515
|
-
}, (clientMessageId, request) => admitRepeatRequest(this, clientMessageId, request),
|
|
545
|
+
}, (clientMessageId, request) => admitRepeatRequest(this, clientMessageId, request), this.signalRelayProtocol, ({ accountAddress, deviceId, generation }) => this.destinationRecovered(accountAddress, deviceId, generation, true));
|
|
546
|
+
}
|
|
547
|
+
/** @internal The Relay protocol version that the next request of this client sends. */
|
|
548
|
+
get signalRelayProtocolVersion() {
|
|
549
|
+
return this.signalRelayProtocol.version;
|
|
516
550
|
}
|
|
517
551
|
get accountId() {
|
|
518
552
|
return this.session.canonicalAccountId;
|
|
@@ -617,19 +651,21 @@ export class HostedSignalProtocolRelayHttpTransport {
|
|
|
617
651
|
async refreshToken() {
|
|
618
652
|
const requestedAtSeconds = Math.floor(Date.now() / 1_000);
|
|
619
653
|
const nonce = await generateRandomBytes(32);
|
|
620
|
-
const challenge = await sha256(concatBytes(TOKEN_REFRESH_CHALLENGE_LABEL, text(this.session.relayScopeId), text(this.session.canonicalAccountId), uint32be(this.session.deviceId), uint32be(this.session.generation), uint32be(this.session.mailboxGeneration), text(String(requestedAtSeconds)), lengthPrefixed(nonce)));
|
|
621
|
-
const proof = await this.deviceAuthentication.signChallenge(challenge);
|
|
622
654
|
let value;
|
|
623
655
|
try {
|
|
624
|
-
value = await postJson(this.connection, this.
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
656
|
+
value = await postJson(this.connection, this.signalRelayProtocol, "/identity/token", async (version) => {
|
|
657
|
+
const challenge = await sha256(concatBytes(signalRelayProofLabels(version).deviceTokenRefreshChallenge, text(this.session.relayScopeId), text(this.session.canonicalAccountId), uint32be(this.session.deviceId), uint32be(this.session.generation), uint32be(this.session.mailboxGeneration), text(String(requestedAtSeconds)), lengthPrefixed(nonce)));
|
|
658
|
+
const proof = await this.deviceAuthentication.signChallenge(challenge, version);
|
|
659
|
+
return {
|
|
660
|
+
accountAddress: this.session.canonicalAccountId,
|
|
661
|
+
// The Relay checks this key against the keys that a recovery revoked.
|
|
662
|
+
deviceAuthenticationPublicKey: bytesToBase64(this.deviceAuthentication.publicKey),
|
|
663
|
+
deviceId: this.session.deviceId,
|
|
664
|
+
deviceProof: bytesToBase64(proof),
|
|
665
|
+
nonce: bytesToUrlSafeBase64(nonce),
|
|
666
|
+
publishableKey: this.connection.publishableKey,
|
|
667
|
+
requestedAtSeconds,
|
|
668
|
+
};
|
|
633
669
|
});
|
|
634
670
|
}
|
|
635
671
|
catch (error) {
|
|
@@ -671,11 +707,12 @@ export class HostedSignalProtocolRelayHttpTransport {
|
|
|
671
707
|
/** Private-package link capability. Detached active authority never persists. */
|
|
672
708
|
async linkDevice(request, storage) {
|
|
673
709
|
const materialFingerprint = await registrationMaterialFingerprint(request.signalIdentity, request.registrationId, request.registrationPreKeys);
|
|
674
|
-
const bodyFor =
|
|
710
|
+
const bodyFor = (body, token) => {
|
|
675
711
|
const claims = JSON.parse(utf8Decode(decodeBase64Url(token.split('.')[1], 'Device token')));
|
|
676
712
|
if (!record(claims) || typeof claims.jti !== 'string' || !claims.jti)
|
|
677
713
|
throw new Error('Signal Protocol Relay returned an invalid device token');
|
|
678
|
-
|
|
714
|
+
const tokenId = claims.jti;
|
|
715
|
+
return (version) => body(tokenId, version);
|
|
679
716
|
};
|
|
680
717
|
const value = await submitHostedSignalProtocolRelayDeviceLink(request, {
|
|
681
718
|
relayScopeId: this.session.relayScopeId,
|
|
@@ -684,13 +721,13 @@ export class HostedSignalProtocolRelayHttpTransport {
|
|
|
684
721
|
post: async (body) => {
|
|
685
722
|
let token = await this.token();
|
|
686
723
|
try {
|
|
687
|
-
return await postJson(this.connection, this.
|
|
724
|
+
return await postJson(this.connection, this.signalRelayProtocol, '/identity/devices/link', bodyFor(body, token), token);
|
|
688
725
|
}
|
|
689
726
|
catch (error) {
|
|
690
727
|
if (!(error instanceof HostedSignalProtocolRelayHttpError) || error.code !== 'TOKEN_INVALID')
|
|
691
728
|
throw error;
|
|
692
729
|
token = await this.token(true);
|
|
693
|
-
return postJson(this.connection, this.
|
|
730
|
+
return postJson(this.connection, this.signalRelayProtocol, '/identity/devices/link', bodyFor(body, token), token);
|
|
694
731
|
}
|
|
695
732
|
},
|
|
696
733
|
});
|
|
@@ -705,7 +742,7 @@ export class HostedSignalProtocolRelayHttpTransport {
|
|
|
705
742
|
mailboxGeneration: requiredNumber(value, 'mailboxGeneration'),
|
|
706
743
|
pendingPreKeyPublication: null,
|
|
707
744
|
preKeyPublication: storedPublication(generation, materialFingerprint, request.operationId, 0, request.registrationPreKeys),
|
|
708
|
-
relayScopeId:
|
|
745
|
+
relayScopeId: responseScopeId(value, 'Signal Protocol Relay returned an invalid managed device link'),
|
|
709
746
|
};
|
|
710
747
|
if (session.canonicalAccountId !== this.session.canonicalAccountId ||
|
|
711
748
|
session.relayScopeId !== this.session.relayScopeId || session.deviceId < 1 ||
|
|
@@ -728,7 +765,7 @@ export class HostedSignalProtocolRelayHttpTransport {
|
|
|
728
765
|
throw new Error('Stored Signal Protocol Relay link session conflicts with the retained attempt');
|
|
729
766
|
session = existing;
|
|
730
767
|
}
|
|
731
|
-
const transport = new HostedSignalProtocolRelayHttpTransport(this.connection, storage, request.newDeviceAuthentication, session, true, this.
|
|
768
|
+
const transport = new HostedSignalProtocolRelayHttpTransport(this.connection, storage, request.newDeviceAuthentication, session, true, this.signalRelayProtocol);
|
|
732
769
|
// Persist the complete shape before synchronization or token renewal can fail.
|
|
733
770
|
try {
|
|
734
771
|
await writeHostedStoreRecord(storage, key, JSON.stringify(session));
|
|
@@ -758,7 +795,7 @@ export class HostedSignalProtocolRelayHttpTransport {
|
|
|
758
795
|
async authenticatedPost(path, body, beforeRepeat) {
|
|
759
796
|
let token = await this.token();
|
|
760
797
|
try {
|
|
761
|
-
return await postJson(this.connection, this.
|
|
798
|
+
return await postJson(this.connection, this.signalRelayProtocol, path, body, token);
|
|
762
799
|
}
|
|
763
800
|
catch (error) {
|
|
764
801
|
if (!(error instanceof HostedSignalProtocolRelayHttpError) ||
|
|
@@ -772,7 +809,7 @@ export class HostedSignalProtocolRelayHttpTransport {
|
|
|
772
809
|
catch {
|
|
773
810
|
throw error;
|
|
774
811
|
}
|
|
775
|
-
return postJson(this.connection, this.
|
|
812
|
+
return postJson(this.connection, this.signalRelayProtocol, path, body, token);
|
|
776
813
|
}
|
|
777
814
|
}
|
|
778
815
|
assertCurrentIdentity(userId, deviceId, identityType = "aci") {
|
|
@@ -1010,8 +1047,10 @@ export class HostedSignalProtocolRelayHttpTransport {
|
|
|
1010
1047
|
});
|
|
1011
1048
|
}
|
|
1012
1049
|
/**
|
|
1013
|
-
* One mailbox page. Its
|
|
1014
|
-
* carries `receipts` only when it is true.
|
|
1050
|
+
* One mailbox page. Its receipts capability holds for this pull only: a
|
|
1051
|
+
* page carries `receipts` only when it is true. Version 3 names the
|
|
1052
|
+
* capability `signalRelayReceipts`, and versions 1 and 2 name it
|
|
1053
|
+
* `relayReceipts`. With `cursor`, the page starts
|
|
1015
1054
|
* after the last message of the page that issued it. The cursor is opaque.
|
|
1016
1055
|
* A page without `retainedWork` comes from a Relay that does not report
|
|
1017
1056
|
* it, so the retained work after the page is unknown. A page without
|
|
@@ -1023,11 +1062,14 @@ export class HostedSignalProtocolRelayHttpTransport {
|
|
|
1023
1062
|
publishableKey: this.connection.publishableKey,
|
|
1024
1063
|
...(cursor === undefined ? {} : { cursor }),
|
|
1025
1064
|
});
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1065
|
+
const invalid = "Signal Protocol Relay returned an invalid mailbox page";
|
|
1066
|
+
if (!record(value))
|
|
1067
|
+
throw new Error(invalid);
|
|
1068
|
+
const receiptsCapability = signalRelayRenamedField(value, "signalRelayReceipts", "relayReceipts", invalid);
|
|
1069
|
+
if (!Array.isArray(value.messages) ||
|
|
1070
|
+
(receiptsCapability !== undefined &&
|
|
1071
|
+
typeof receiptsCapability !== "boolean") ||
|
|
1072
|
+
(value.receipts !== undefined && receiptsCapability !== true) ||
|
|
1031
1073
|
(value.nextCursor !== undefined &&
|
|
1032
1074
|
(typeof value.nextCursor !== "string" || value.nextCursor === "")) ||
|
|
1033
1075
|
(value.retainedWork !== undefined &&
|
|
@@ -1038,7 +1080,7 @@ export class HostedSignalProtocolRelayHttpTransport {
|
|
|
1038
1080
|
typeof entry.messageId === "string" &&
|
|
1039
1081
|
entry.messageId !== "" &&
|
|
1040
1082
|
typeof entry.reason === "string")))) {
|
|
1041
|
-
throw new Error(
|
|
1083
|
+
throw new Error(invalid);
|
|
1042
1084
|
}
|
|
1043
1085
|
return {
|
|
1044
1086
|
messages: value.messages.map((candidate) => this.incomingEnvelope(candidate)),
|
|
@@ -1107,15 +1149,18 @@ export class HostedSignalProtocolRelayHttpTransport {
|
|
|
1107
1149
|
!claims.jti ||
|
|
1108
1150
|
claims.jti.includes("\0"))
|
|
1109
1151
|
throw new Error("Signal Protocol Relay certificate token is invalid");
|
|
1152
|
+
const tokenId = claims.jti;
|
|
1110
1153
|
const nonce = bytesToUrlSafeBase64(await generateRandomBytes(32));
|
|
1111
|
-
const proof = await this.deviceAuthentication.signCertificateRequest(claims.jti, nonce);
|
|
1112
|
-
if (proof.byteLength !== 64)
|
|
1113
|
-
throw new Error("Signal Protocol Relay certificate proof is invalid");
|
|
1114
1154
|
try {
|
|
1115
|
-
const result = await postJson(this.connection, this.
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1155
|
+
const result = await postJson(this.connection, this.signalRelayProtocol, "/certificates/issue", async (version) => {
|
|
1156
|
+
const proof = await this.deviceAuthentication.signCertificateRequest(tokenId, nonce, version);
|
|
1157
|
+
if (proof.byteLength !== 64)
|
|
1158
|
+
throw new Error("Signal Protocol Relay certificate proof is invalid");
|
|
1159
|
+
return {
|
|
1160
|
+
publishableKey: this.connection.publishableKey,
|
|
1161
|
+
nonce,
|
|
1162
|
+
deviceProof: bytesToBase64(proof),
|
|
1163
|
+
};
|
|
1119
1164
|
}, token);
|
|
1120
1165
|
if (!record(result) ||
|
|
1121
1166
|
typeof result.senderCertificate !== "string" ||
|
|
@@ -1329,7 +1374,7 @@ export class HostedSignalProtocolRelayHttpTransport {
|
|
|
1329
1374
|
expiresAt: tokenExpiration(token, this.session) * 1_000,
|
|
1330
1375
|
headers: {
|
|
1331
1376
|
authorization: `Bearer ${token}`,
|
|
1332
|
-
...signalRelayProtocolHeadersFor(this.
|
|
1377
|
+
...signalRelayProtocolHeadersFor(this.signalRelayProtocol.version),
|
|
1333
1378
|
"x-open-e2ee-publishable-key": this.connection.publishableKey,
|
|
1334
1379
|
"x-open-e2ee-object-id": input.objectId,
|
|
1335
1380
|
"x-open-e2ee-attachment-capability": input.readCapability,
|
|
@@ -1488,7 +1533,7 @@ export class HostedSignalProtocolRelayHttpTransport {
|
|
|
1488
1533
|
const generation = ++this.subscriptionGeneration;
|
|
1489
1534
|
const subscription = subscribeHostedMailbox({
|
|
1490
1535
|
...options,
|
|
1491
|
-
|
|
1536
|
+
signalRelayProtocol: this.signalRelayProtocol,
|
|
1492
1537
|
onConnectionState: (state, reason) => {
|
|
1493
1538
|
if (generation === this.subscriptionGeneration)
|
|
1494
1539
|
this.connectionState.move(state, reason);
|
|
@@ -1790,20 +1835,20 @@ export class HostedSignalProtocolRelayHttpTransport {
|
|
|
1790
1835
|
}
|
|
1791
1836
|
}
|
|
1792
1837
|
export async function bootstrapHostedSignalProtocolRelayTransport(request) {
|
|
1793
|
-
|
|
1794
|
-
//
|
|
1795
|
-
|
|
1796
|
-
const value = await postJson(request.connection,
|
|
1838
|
+
// A new client starts with a new offer, which the transport built below
|
|
1839
|
+
// also takes. A fallback during the registration holds for the client.
|
|
1840
|
+
const signalRelayProtocol = new SignalRelayProtocolOffer();
|
|
1841
|
+
const value = await postJson(request.connection, signalRelayProtocol, request.assertionPurpose === "recover"
|
|
1797
1842
|
? "/identity/recover"
|
|
1798
|
-
: "/identity/register", {
|
|
1843
|
+
: "/identity/register", async (version) => ({
|
|
1799
1844
|
assertion: request.assertion,
|
|
1800
1845
|
assertionPurpose: request.assertionPurpose,
|
|
1801
1846
|
deviceAuthenticationPublicKey: bytesToBase64(request.deviceAuthentication.publicKey),
|
|
1802
|
-
deviceProof: bytesToBase64(
|
|
1847
|
+
deviceProof: bytesToBase64(await request.deviceAuthentication.signChallenge(await registrationChallenge(request, version), version)),
|
|
1803
1848
|
operationId: request.operationId,
|
|
1804
1849
|
publishableKey: request.connection.publishableKey,
|
|
1805
1850
|
signalRegistration: signalRegistration(request.signalIdentity, request.registrationId, request.registrationPreKeys),
|
|
1806
|
-
});
|
|
1851
|
+
}));
|
|
1807
1852
|
if (!record(value))
|
|
1808
1853
|
throw new Error("Signal Protocol Relay returned an invalid registration");
|
|
1809
1854
|
const materialFingerprint = await registrationMaterialFingerprint(request.signalIdentity, request.registrationId, request.registrationPreKeys);
|
|
@@ -1818,7 +1863,7 @@ export async function bootstrapHostedSignalProtocolRelayTransport(request) {
|
|
|
1818
1863
|
mailboxGeneration: requiredNumber(value, "mailboxGeneration"),
|
|
1819
1864
|
pendingPreKeyPublication: null,
|
|
1820
1865
|
preKeyPublication: storedPublication(generation, materialFingerprint, request.operationId, 0, request.registrationPreKeys),
|
|
1821
|
-
relayScopeId:
|
|
1866
|
+
relayScopeId: responseScopeId(value, "Signal Protocol Relay returned an invalid registration"),
|
|
1822
1867
|
};
|
|
1823
1868
|
if (session.relayScopeId !== signalProtocolRelayScopeId(request.connection) ||
|
|
1824
1869
|
session.deviceId < 1 ||
|
|
@@ -1829,7 +1874,7 @@ export async function bootstrapHostedSignalProtocolRelayTransport(request) {
|
|
|
1829
1874
|
throw new Error("Signal Protocol Relay returned an invalid registration");
|
|
1830
1875
|
}
|
|
1831
1876
|
await writeHostedStoreRecord(request.storage, await sessionMetadataKey(request.connection), JSON.stringify(session));
|
|
1832
|
-
const transport = new HostedSignalProtocolRelayHttpTransport(request.connection, request.storage, request.deviceAuthentication, session);
|
|
1877
|
+
const transport = new HostedSignalProtocolRelayHttpTransport(request.connection, request.storage, request.deviceAuthentication, session, true, signalRelayProtocol);
|
|
1833
1878
|
const scopeId = request.connection.relayScopeId.slice();
|
|
1834
1879
|
return {
|
|
1835
1880
|
canonicalAccountId: session.canonicalAccountId,
|