@open-e2ee/signal-protocol-sdk 13.0.0 → 13.2.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 +63 -0
- package/LICENSE +1 -1
- package/LICENSE-MIT +1 -1
- package/NOTICE +1 -1
- package/README.md +1 -1
- package/SECURITY.md +2 -2
- package/device/README.md +11 -1
- package/dist/client/config.d.ts +6 -2
- package/dist/client/config.d.ts.map +1 -1
- package/dist/client/config.js.map +1 -1
- package/dist/client/hosted-device-link-transport.d.ts +11 -0
- package/dist/client/hosted-device-link-transport.d.ts.map +1 -0
- package/dist/client/hosted-device-link-transport.js +25 -0
- package/dist/client/hosted-device-link-transport.js.map +1 -0
- package/dist/client/hosted-mailbox-subscription.d.ts +36 -4
- package/dist/client/hosted-mailbox-subscription.d.ts.map +1 -1
- package/dist/client/hosted-mailbox-subscription.js +238 -69
- package/dist/client/hosted-mailbox-subscription.js.map +1 -1
- package/dist/client/hosted-push.d.ts +11 -0
- package/dist/client/hosted-push.d.ts.map +1 -1
- package/dist/client/hosted-push.js +12 -4
- package/dist/client/hosted-push.js.map +1 -1
- package/dist/client/hosted-transport.d.ts +16 -2
- package/dist/client/hosted-transport.d.ts.map +1 -1
- package/dist/client/hosted-transport.js +144 -6
- package/dist/client/hosted-transport.js.map +1 -1
- package/dist/client/hosted.d.ts +4 -1
- package/dist/client/hosted.d.ts.map +1 -1
- package/dist/client/hosted.js +14 -4
- package/dist/client/hosted.js.map +1 -1
- package/docs/ASSURANCE.md +5 -5
- package/docs/GETTING_STARTED.md +11 -1
- package/docs/RECIPES.md +44 -0
- package/local/store/web-sqlite/README.md +28 -0
- package/package.json +1 -1
|
@@ -119,6 +119,9 @@ async function commitHeld(client, envelopes) {
|
|
|
119
119
|
* wake whose page past the cursor is empty clears the cursor, so the wake
|
|
120
120
|
* after it pulls from the head and offers those envelopes again. A failed
|
|
121
121
|
* wake also clears the cursor.
|
|
122
|
+
*
|
|
123
|
+
* One call makes one pull. The result copies `retainedWork` from the Relay
|
|
124
|
+
* page. When it is true, the caller runs the next pass.
|
|
122
125
|
*/
|
|
123
126
|
export async function pullHostedRelayAfterWake(options) {
|
|
124
127
|
const runtime = hostedRuntime(options.client);
|
|
@@ -126,7 +129,7 @@ export async function pullHostedRelayAfterWake(options) {
|
|
|
126
129
|
// pulls from the head. This includes a Relay refusal of the cursor.
|
|
127
130
|
const cursor = pullCursors.get(runtime);
|
|
128
131
|
pullCursors.delete(runtime);
|
|
129
|
-
const { messages: envelopes, receipts, nextCursor, } = await runtime.pullMailbox(cursor);
|
|
132
|
+
const { messages: envelopes, receipts, nextCursor, retainedWork, failedEntries, } = await runtime.pullMailbox(cursor);
|
|
130
133
|
const inputIds = new Set(envelopes.map((envelope) => envelope.id));
|
|
131
134
|
if (inputIds.size !== envelopes.length ||
|
|
132
135
|
envelopes.some((envelope) => !envelope.id)) {
|
|
@@ -163,10 +166,14 @@ export async function pullHostedRelayAfterWake(options) {
|
|
|
163
166
|
// too, and the redelivery finds its record. The release wakes the queue.
|
|
164
167
|
results.release();
|
|
165
168
|
}
|
|
166
|
-
//
|
|
167
|
-
//
|
|
169
|
+
// A page that holds an envelope or a failed entry keeps its `nextCursor`,
|
|
170
|
+
// so the next wake pulls past that page. A page that holds neither keeps
|
|
171
|
+
// the cursor cleared, so the next wake pulls from the head. A Relay page
|
|
172
|
+
// without a `nextCursor` keeps the cursor cleared too. That branch is
|
|
168
173
|
// removed in the first release after every Relay lane serves the cursor.
|
|
169
|
-
if (envelopes.length > 0
|
|
174
|
+
if ((envelopes.length > 0 ||
|
|
175
|
+
(failedEntries !== undefined && failedEntries.length > 0)) &&
|
|
176
|
+
nextCursor !== undefined) {
|
|
170
177
|
pullCursors.set(runtime, nextCursor);
|
|
171
178
|
}
|
|
172
179
|
// The committed receives are durable, so they run after the acknowledgment
|
|
@@ -176,6 +183,7 @@ export async function pullHostedRelayAfterWake(options) {
|
|
|
176
183
|
acknowledgedMessageIds,
|
|
177
184
|
failedMessageIds,
|
|
178
185
|
pulled: envelopes.length,
|
|
186
|
+
...(retainedWork === undefined ? {} : { retainedWork }),
|
|
179
187
|
};
|
|
180
188
|
}
|
|
181
189
|
//# sourceMappingURL=hosted-push.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hosted-push.js","sourceRoot":"","sources":["../../client/hosted-push.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAkB,MAAM,sBAAsB,CAAC;AAKhE,MAAM,yBAAyB,GAAG,KAAK,CAAC;AACxC,MAAM,4BAA4B,GAAG,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"hosted-push.js","sourceRoot":"","sources":["../../client/hosted-push.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAkB,MAAM,sBAAsB,CAAC;AAKhE,MAAM,yBAAyB,GAAG,KAAK,CAAC;AACxC,MAAM,4BAA4B,GAAG,KAAK,CAAC;AAkH3C,MAAM,cAAc,GAAG,IAAI,OAAO,EAAkC,CAAC;AACrE;;;GAGG;AACH,MAAM,WAAW,GAAG,IAAI,OAAO,EAAkC,CAAC;AAElE,yEAAyE;AACzE,MAAM,UAAU,0BAA0B,CACxC,MAA6B,EAC7B,OAA+B;IAE/B,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AACtC,CAAC;AAED,SAAS,aAAa,CAAC,MAA6B;IAClD,MAAM,OAAO,GAAG,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC3C,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;IACvF,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,SAAS,WAAW,CAAC,KAAa;IAChC,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC,MAAM,GAAG,yBAAyB,EAAE,CAAC;QACvD,MAAM,IAAI,KAAK,CAA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AC;QACnB,CAAC,aAAa,KAAK,SAAS,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC5D,UAAU,KAAK,SAAS,EACxB,CAAC;QACD,WAAW,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IACvC,CAAC;IACD,2EAA2E;IAC3E,WAAW;IACX,MAAM,OAAO,CAAC,MAAM,CAAC,sBAAsB,CACzC,OAAO,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,UAAU,EAAE,CAC3E,CAAC;IACF,OAAO;QACL,sBAAsB;QACtB,gBAAgB;QAChB,MAAM,EAAE,SAAS,CAAC,MAAM;QACxB,GAAG,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC;KACxD,CAAC;AACJ,CAAC"}
|
|
@@ -3,7 +3,7 @@ import type { GroupAuthorization } from "../internal/groups/manager.js";
|
|
|
3
3
|
import type { CompositeIdentityV1, IdentityType } from "../keys/types.js";
|
|
4
4
|
import type { SignalProtocolLocalStore } from "../types/index.js";
|
|
5
5
|
import type { HostedRelayConnection } from "./hosted-connection.js";
|
|
6
|
-
import type { HostedRelayDeviceAuthentication, HostedRelayRegistrationPreKeys } from "./hosted.js";
|
|
6
|
+
import type { HostedRelayDeviceAuthentication, HostedRelayRegistrationPreKeys, HostedRelayManagedDeviceLinkRequest, HostedRelayManagedDeviceLinkResult } from "./hosted.js";
|
|
7
7
|
import type { SignalProtocolRemoteObjectStore } from "../remote/object-store/index.js";
|
|
8
8
|
import type { HostedMailboxPage, HostedRelayPushRegistration, HostedRelayPushRuntime } from "./hosted-push.js";
|
|
9
9
|
import type { HostedRelayPresenceRuntime } from "./hosted-presence.js";
|
|
@@ -45,6 +45,7 @@ export declare class HostedRelayHttpTransport implements SignalProtocolRelayServ
|
|
|
45
45
|
private readonly storage;
|
|
46
46
|
private readonly deviceAuthentication;
|
|
47
47
|
private session;
|
|
48
|
+
private readonly persistRefreshedToken;
|
|
48
49
|
private readonly groups;
|
|
49
50
|
readonly groupServer: RelayGroupServer;
|
|
50
51
|
private readonly anonymousDelivery;
|
|
@@ -59,7 +60,7 @@ export declare class HostedRelayHttpTransport implements SignalProtocolRelayServ
|
|
|
59
60
|
private readonly presenceListeners;
|
|
60
61
|
private readonly receiptInbox;
|
|
61
62
|
private readonly receiptJoin;
|
|
62
|
-
constructor(connection: HostedRelayConnection, storage: SignalProtocolLocalStore, deviceAuthentication: HostedRelayDeviceAuthentication, session: StoredHostedRelaySession);
|
|
63
|
+
constructor(connection: HostedRelayConnection, storage: SignalProtocolLocalStore, deviceAuthentication: HostedRelayDeviceAuthentication, session: StoredHostedRelaySession, persistRefreshedToken?: boolean);
|
|
63
64
|
get accountId(): string;
|
|
64
65
|
get deviceId(): number;
|
|
65
66
|
readonly objectStore: SignalProtocolRemoteObjectStore;
|
|
@@ -70,6 +71,8 @@ export declare class HostedRelayHttpTransport implements SignalProtocolRelayServ
|
|
|
70
71
|
private token;
|
|
71
72
|
/** Verify that the stored device authority can get a current token. */
|
|
72
73
|
ensureAuthenticated(force?: boolean): Promise<void>;
|
|
74
|
+
/** Private-package link capability. Detached active authority never persists. */
|
|
75
|
+
linkDevice(request: HostedRelayManagedDeviceLinkRequest, storage: SignalProtocolLocalStore): Promise<HostedRelayTransportResult & HostedRelayManagedDeviceLinkResult>;
|
|
73
76
|
private authenticatedPost;
|
|
74
77
|
private assertCurrentIdentity;
|
|
75
78
|
/**
|
|
@@ -101,6 +104,10 @@ export declare class HostedRelayHttpTransport implements SignalProtocolRelayServ
|
|
|
101
104
|
* One mailbox page. Its `relayReceipts` holds for this pull only: a page
|
|
102
105
|
* carries `receipts` only when it is true. With `cursor`, the page starts
|
|
103
106
|
* after the last message of the page that issued it. The cursor is opaque.
|
|
107
|
+
* A page without `retainedWork` comes from a Relay that does not report
|
|
108
|
+
* it, so the retained work after the page is unknown. A page without
|
|
109
|
+
* `failedEntries` comes from a Relay that does not report the messages that
|
|
110
|
+
* it could not serve.
|
|
104
111
|
*/
|
|
105
112
|
private pullIncoming;
|
|
106
113
|
/** One retained mailbox message, from a pull page or a `durable-message` frame. */
|
|
@@ -220,5 +227,12 @@ export declare function resumeHostedRelayTransport(options: {
|
|
|
220
227
|
readonly deviceAuthentication: HostedRelayDeviceAuthentication;
|
|
221
228
|
readonly storage: SignalProtocolLocalStore;
|
|
222
229
|
}): Promise<HostedRelayTransportResult | undefined>;
|
|
230
|
+
/** Compose a link using a detached active session without publication writes. */
|
|
231
|
+
export declare function linkHostedRelayTransport(options: {
|
|
232
|
+
readonly connection: HostedRelayConnection;
|
|
233
|
+
readonly activeStorage: SignalProtocolLocalStore;
|
|
234
|
+
readonly storage: SignalProtocolLocalStore;
|
|
235
|
+
readonly request: HostedRelayManagedDeviceLinkRequest;
|
|
236
|
+
}): Promise<HostedRelayTransportResult & HostedRelayManagedDeviceLinkResult>;
|
|
223
237
|
export {};
|
|
224
238
|
//# sourceMappingURL=hosted-transport.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hosted-transport.d.ts","sourceRoot":"","sources":["../../client/hosted-transport.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hosted-transport.d.ts","sourceRoot":"","sources":["../../client/hosted-transport.ts"],"names":[],"mappings":"AAIA,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,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,qBAAqB,EACrB,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,EAChB,WAAW,EACZ,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,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yBAAyB,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,cAAc,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC,CAIxH;YACa,eAAe;CAiB9B;AAED,wBAAsB,6BAA6B,CACjD,OAAO,EAAE,oCAAoC,GAC5C,OAAO,CAAC,0BAA0B,CAAC,CAkFrC;AAED,wBAAsB,0BAA0B,CAAC,OAAO,EAAE;IACxD,QAAQ,CAAC,UAAU,EAAE,qBAAqB,CAAC;IAC3C,QAAQ,CAAC,oBAAoB,EAAE,+BAA+B,CAAC;IAC/D,QAAQ,CAAC,OAAO,EAAE,wBAAwB,CAAC;CAC5C,GAAG,OAAO,CAAC,0BAA0B,GAAG,SAAS,CAAC,CAqBlD;AAED,iFAAiF;AACjF,wBAAsB,wBAAwB,CAAC,OAAO,EAAE;IACtD,QAAQ,CAAC,UAAU,EAAE,qBAAqB,CAAC;IAC3C,QAAQ,CAAC,aAAa,EAAE,wBAAwB,CAAC;IACjD,QAAQ,CAAC,OAAO,EAAE,wBAAwB,CAAC;IAC3C,QAAQ,CAAC,OAAO,EAAE,mCAAmC,CAAC;CACvD,GAAG,OAAO,CAAC,0BAA0B,GAAG,kCAAkC,CAAC,CAQ3E"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { hostedAssertionIdentifier } from "./hosted-assertion-id.js";
|
|
2
2
|
import { HostedRelayHttpError } from "./hosted-http-error.js";
|
|
3
|
+
import { submitHostedRelayDeviceLink } from "./hosted-device-link-transport.js";
|
|
3
4
|
import { utf8Decode, websocketUrl } from "../internal/platform/index.js";
|
|
4
5
|
import AsyncLock from "async-lock";
|
|
5
6
|
import { createCompositeIdentityV1, decodeCompositeIdentityV1, encodeCompositeIdentityV1, } from "../keys/identity.js";
|
|
@@ -322,6 +323,22 @@ function tokenExpiration(token, session) {
|
|
|
322
323
|
return 0;
|
|
323
324
|
}
|
|
324
325
|
}
|
|
326
|
+
function assertLinkToken(session) {
|
|
327
|
+
const parts = session.deviceToken.split('.');
|
|
328
|
+
if (parts.length !== 3)
|
|
329
|
+
throw new Error('Signal Protocol Relay returned an invalid link token');
|
|
330
|
+
const header = JSON.parse(utf8Decode(decodeBase64Url(parts[0], 'Device token header')));
|
|
331
|
+
const claims = JSON.parse(utf8Decode(decodeBase64Url(parts[1], 'Device token claims')));
|
|
332
|
+
if (!record(header) || Object.keys(header).sort().join(',') !== 'alg,kid,typ' ||
|
|
333
|
+
header.alg !== 'EdDSA' || header.typ !== 'JWT' || typeof header.kid !== 'string' || !header.kid ||
|
|
334
|
+
decodeBase64Url(parts[2], 'Device token signature').length !== 64 ||
|
|
335
|
+
!record(claims) || typeof claims.jti !== 'string' || !claims.jti ||
|
|
336
|
+
claims.iss !== 'open-e2ee-relay' || claims.aud !== 'open-e2ee-relay-device' || claims.token_use !== 'device' ||
|
|
337
|
+
typeof claims.account_state_id !== 'string' || !claims.account_state_id ||
|
|
338
|
+
!Number.isSafeInteger(claims.iat) || claims.iat < 0 ||
|
|
339
|
+
tokenExpiration(session.deviceToken, session) <= claims.iat)
|
|
340
|
+
throw new Error('Signal Protocol Relay returned an invalid link token');
|
|
341
|
+
}
|
|
325
342
|
function requiredNumber(object, key) {
|
|
326
343
|
const value = object[key];
|
|
327
344
|
if (!Number.isSafeInteger(value))
|
|
@@ -391,6 +408,7 @@ export class HostedRelayHttpTransport {
|
|
|
391
408
|
storage;
|
|
392
409
|
deviceAuthentication;
|
|
393
410
|
session;
|
|
411
|
+
persistRefreshedToken;
|
|
394
412
|
groups;
|
|
395
413
|
groupServer;
|
|
396
414
|
anonymousDelivery;
|
|
@@ -406,11 +424,12 @@ export class HostedRelayHttpTransport {
|
|
|
406
424
|
presenceListeners = new Set();
|
|
407
425
|
receiptInbox = new RelayReceiptInbox();
|
|
408
426
|
receiptJoin = new RelayReceiptJoin();
|
|
409
|
-
constructor(connection, storage, deviceAuthentication, session) {
|
|
427
|
+
constructor(connection, storage, deviceAuthentication, session, persistRefreshedToken = true) {
|
|
410
428
|
this.connection = connection;
|
|
411
429
|
this.storage = storage;
|
|
412
430
|
this.deviceAuthentication = deviceAuthentication;
|
|
413
431
|
this.session = session;
|
|
432
|
+
this.persistRefreshedToken = persistRefreshedToken;
|
|
414
433
|
// The Relay refuses a removed device's mailbox on every send path before
|
|
415
434
|
// its device list shows the removal, so a direct send may post first.
|
|
416
435
|
declareRefusesRemovedDevices(this);
|
|
@@ -578,7 +597,8 @@ export class HostedRelayHttpTransport {
|
|
|
578
597
|
requestedAtSeconds) {
|
|
579
598
|
throw new Error("Signal Protocol Relay returned an invalid device token");
|
|
580
599
|
}
|
|
581
|
-
|
|
600
|
+
if (this.persistRefreshedToken)
|
|
601
|
+
await this.persistSession();
|
|
582
602
|
}
|
|
583
603
|
async token(force = false) {
|
|
584
604
|
const now = Math.floor(Date.now() / 1_000);
|
|
@@ -597,6 +617,86 @@ export class HostedRelayHttpTransport {
|
|
|
597
617
|
async ensureAuthenticated(force = false) {
|
|
598
618
|
await this.token(force);
|
|
599
619
|
}
|
|
620
|
+
/** Private-package link capability. Detached active authority never persists. */
|
|
621
|
+
async linkDevice(request, storage) {
|
|
622
|
+
const materialFingerprint = await registrationMaterialFingerprint(request.signalIdentity, request.registrationId, request.registrationPreKeys);
|
|
623
|
+
const bodyFor = async (body, token) => {
|
|
624
|
+
const claims = JSON.parse(utf8Decode(decodeBase64Url(token.split('.')[1], 'Device token')));
|
|
625
|
+
if (!record(claims) || typeof claims.jti !== 'string' || !claims.jti)
|
|
626
|
+
throw new Error('Signal Protocol Relay returned an invalid device token');
|
|
627
|
+
return body(claims.jti);
|
|
628
|
+
};
|
|
629
|
+
const value = await submitHostedRelayDeviceLink(request, {
|
|
630
|
+
relayScopeId: this.session.relayScopeId,
|
|
631
|
+
materialFingerprint,
|
|
632
|
+
signalRegistration: signalRegistration(request.signalIdentity, request.registrationId, request.registrationPreKeys),
|
|
633
|
+
post: async (body) => {
|
|
634
|
+
let token = await this.token();
|
|
635
|
+
try {
|
|
636
|
+
return await postJson(this.connection, '/identity/devices/link', await bodyFor(body, token), token);
|
|
637
|
+
}
|
|
638
|
+
catch (error) {
|
|
639
|
+
if (!(error instanceof HostedRelayHttpError) || error.code !== 'TOKEN_INVALID')
|
|
640
|
+
throw error;
|
|
641
|
+
token = await this.token(true);
|
|
642
|
+
return postJson(this.connection, '/identity/devices/link', await bodyFor(body, token), token);
|
|
643
|
+
}
|
|
644
|
+
},
|
|
645
|
+
});
|
|
646
|
+
if (!record(value) || value.accountPreserved !== true || value.protocolStateCopied !== false)
|
|
647
|
+
throw new Error('Signal Protocol Relay returned an invalid managed device link');
|
|
648
|
+
const generation = requiredNumber(value, 'deviceAuthorizationGeneration');
|
|
649
|
+
let session = {
|
|
650
|
+
canonicalAccountId: requiredString(value, 'canonicalAccountId'),
|
|
651
|
+
deviceId: requiredNumber(value, 'deviceId'),
|
|
652
|
+
deviceToken: requiredString(value, 'deviceToken'),
|
|
653
|
+
generation,
|
|
654
|
+
mailboxGeneration: requiredNumber(value, 'mailboxGeneration'),
|
|
655
|
+
pendingPreKeyPublication: null,
|
|
656
|
+
preKeyPublication: storedPublication(generation, materialFingerprint, request.operationId, 0, request.registrationPreKeys),
|
|
657
|
+
relayScopeId: requiredString(value, 'relayScopeId'),
|
|
658
|
+
};
|
|
659
|
+
if (session.canonicalAccountId !== this.session.canonicalAccountId ||
|
|
660
|
+
session.relayScopeId !== this.session.relayScopeId || session.deviceId < 1 ||
|
|
661
|
+
session.deviceId === this.session.deviceId || generation < 0 || session.mailboxGeneration < 0 ||
|
|
662
|
+
tokenExpiration(session.deviceToken, session) <= 0)
|
|
663
|
+
throw new Error('Signal Protocol Relay returned an invalid managed device link');
|
|
664
|
+
assertLinkToken(session);
|
|
665
|
+
const key = await sessionMetadataKey(this.connection);
|
|
666
|
+
const stored = await storage.getMetadata(key);
|
|
667
|
+
if (stored !== null) {
|
|
668
|
+
const existing = parseSession(stored, this.connection);
|
|
669
|
+
assertLinkToken(existing);
|
|
670
|
+
if (existing.canonicalAccountId !== session.canonicalAccountId || existing.deviceId !== session.deviceId ||
|
|
671
|
+
existing.generation !== generation || existing.mailboxGeneration !== session.mailboxGeneration ||
|
|
672
|
+
tokenExpiration(existing.deviceToken, existing) <= 0 ||
|
|
673
|
+
existing.preKeyPublication.authorityGeneration !== generation ||
|
|
674
|
+
(existing.preKeyPublication.revision === 0 &&
|
|
675
|
+
(existing.preKeyPublication.operationId !== request.operationId ||
|
|
676
|
+
existing.preKeyPublication.materialFingerprint !== materialFingerprint)))
|
|
677
|
+
throw new Error('Stored Signal Protocol Relay link session conflicts with the retained attempt');
|
|
678
|
+
session = existing;
|
|
679
|
+
}
|
|
680
|
+
const transport = new HostedRelayHttpTransport(this.connection, storage, request.newDeviceAuthentication, session);
|
|
681
|
+
// Persist the complete shape before synchronization or token renewal can fail.
|
|
682
|
+
try {
|
|
683
|
+
await storage.setMetadata(key, JSON.stringify(session));
|
|
684
|
+
await transport.ensureAuthenticated();
|
|
685
|
+
}
|
|
686
|
+
catch (error) {
|
|
687
|
+
// A renewal refusal cannot prove that the accepted link had no effect.
|
|
688
|
+
if (error instanceof HostedRelayHttpError && !error.retryable &&
|
|
689
|
+
(error.code === 'KEY_PROOF_INVALID' || error.code === 'CONFLICT'))
|
|
690
|
+
throw new Error('Signal Protocol Relay accepted the link but session adoption failed', { cause: error });
|
|
691
|
+
throw error;
|
|
692
|
+
}
|
|
693
|
+
return {
|
|
694
|
+
canonicalAccountId: session.canonicalAccountId, deviceId: session.deviceId,
|
|
695
|
+
relayScopeId: this.connection.relayScopeId.slice(), relay: transport,
|
|
696
|
+
remoteObjectStore: transport.objectStore, transport,
|
|
697
|
+
accountPreserved: true, protocolStateCopied: false,
|
|
698
|
+
};
|
|
699
|
+
}
|
|
600
700
|
async authenticatedPost(path, body) {
|
|
601
701
|
let token = await this.token();
|
|
602
702
|
try {
|
|
@@ -825,6 +925,10 @@ export class HostedRelayHttpTransport {
|
|
|
825
925
|
* One mailbox page. Its `relayReceipts` holds for this pull only: a page
|
|
826
926
|
* carries `receipts` only when it is true. With `cursor`, the page starts
|
|
827
927
|
* after the last message of the page that issued it. The cursor is opaque.
|
|
928
|
+
* A page without `retainedWork` comes from a Relay that does not report
|
|
929
|
+
* it, so the retained work after the page is unknown. A page without
|
|
930
|
+
* `failedEntries` comes from a Relay that does not report the messages that
|
|
931
|
+
* it could not serve.
|
|
828
932
|
*/
|
|
829
933
|
async pullIncoming(cursor) {
|
|
830
934
|
const value = await this.authenticatedPost("/mailbox/pull", {
|
|
@@ -837,7 +941,15 @@ export class HostedRelayHttpTransport {
|
|
|
837
941
|
typeof value.relayReceipts !== "boolean") ||
|
|
838
942
|
(value.receipts !== undefined && value.relayReceipts !== true) ||
|
|
839
943
|
(value.nextCursor !== undefined &&
|
|
840
|
-
(typeof value.nextCursor !== "string" || value.nextCursor === ""))
|
|
944
|
+
(typeof value.nextCursor !== "string" || value.nextCursor === "")) ||
|
|
945
|
+
(value.retainedWork !== undefined &&
|
|
946
|
+
typeof value.retainedWork !== "boolean") ||
|
|
947
|
+
(value.failedEntries !== undefined &&
|
|
948
|
+
(!Array.isArray(value.failedEntries) ||
|
|
949
|
+
!value.failedEntries.every((entry) => record(entry) &&
|
|
950
|
+
typeof entry.messageId === "string" &&
|
|
951
|
+
entry.messageId !== "" &&
|
|
952
|
+
typeof entry.reason === "string")))) {
|
|
841
953
|
throw new Error("Signal Protocol Relay returned an invalid mailbox page");
|
|
842
954
|
}
|
|
843
955
|
return {
|
|
@@ -848,6 +960,17 @@ export class HostedRelayHttpTransport {
|
|
|
848
960
|
...(value.nextCursor === undefined
|
|
849
961
|
? {}
|
|
850
962
|
: { nextCursor: value.nextCursor }),
|
|
963
|
+
...(value.retainedWork === undefined
|
|
964
|
+
? {}
|
|
965
|
+
: { retainedWork: value.retainedWork }),
|
|
966
|
+
...(value.failedEntries === undefined
|
|
967
|
+
? {}
|
|
968
|
+
: {
|
|
969
|
+
failedEntries: value.failedEntries.map(({ messageId, reason }) => ({
|
|
970
|
+
messageId: messageId,
|
|
971
|
+
reason: reason,
|
|
972
|
+
})),
|
|
973
|
+
}),
|
|
851
974
|
};
|
|
852
975
|
}
|
|
853
976
|
/** One retained mailbox message, from a pull page or a `durable-message` frame. */
|
|
@@ -1007,6 +1130,7 @@ export class HostedRelayHttpTransport {
|
|
|
1007
1130
|
}
|
|
1008
1131
|
return {
|
|
1009
1132
|
receipted: value.receipted ?? [],
|
|
1133
|
+
acknowledged: value.acknowledged,
|
|
1010
1134
|
receiptsAcknowledged: value.receiptsAcknowledged ?? 0,
|
|
1011
1135
|
};
|
|
1012
1136
|
}
|
|
@@ -1276,11 +1400,13 @@ export class HostedRelayHttpTransport {
|
|
|
1276
1400
|
isConclusiveRefusal,
|
|
1277
1401
|
decodeDurable: (message) => this.incomingEnvelope(message),
|
|
1278
1402
|
pull: async (cursor) => {
|
|
1279
|
-
const { messages, receipts, nextCursor } = await this.pullIncoming(cursor);
|
|
1403
|
+
const { messages, receipts, nextCursor, retainedWork, failedEntries } = await this.pullIncoming(cursor);
|
|
1280
1404
|
return {
|
|
1281
1405
|
messages: messages,
|
|
1282
1406
|
receipts,
|
|
1283
1407
|
...(nextCursor === undefined ? {} : { nextCursor }),
|
|
1408
|
+
...(retainedWork === undefined ? {} : { retainedWork }),
|
|
1409
|
+
...(failedEntries === undefined ? {} : { failedEntries }),
|
|
1284
1410
|
};
|
|
1285
1411
|
},
|
|
1286
1412
|
acknowledge: (messageIds, receiptIds) => this.acknowledge(messageIds, receiptIds),
|
|
@@ -1332,9 +1458,13 @@ export class HostedRelayHttpTransport {
|
|
|
1332
1458
|
async markDelivered(envelopeId) {
|
|
1333
1459
|
if (this.ephemeralAcknowledgments.has(envelopeId))
|
|
1334
1460
|
return;
|
|
1335
|
-
|
|
1461
|
+
const subscription = this.subscription;
|
|
1462
|
+
if (subscription?.acknowledge(envelopeId) === true)
|
|
1336
1463
|
return;
|
|
1337
|
-
|
|
1464
|
+
const send = () => this.acknowledgeAndAnswer([envelopeId]);
|
|
1465
|
+
await (subscription === undefined
|
|
1466
|
+
? send()
|
|
1467
|
+
: subscription.acknowledgeOverHttp(send));
|
|
1338
1468
|
}
|
|
1339
1469
|
async getDevices(userId) {
|
|
1340
1470
|
return (await this.directory(userId)).map((device) => ({
|
|
@@ -1598,4 +1728,12 @@ export async function resumeHostedRelayTransport(options) {
|
|
|
1598
1728
|
transport,
|
|
1599
1729
|
};
|
|
1600
1730
|
}
|
|
1731
|
+
/** Compose a link using a detached active session without publication writes. */
|
|
1732
|
+
export async function linkHostedRelayTransport(options) {
|
|
1733
|
+
const stored = await options.activeStorage.getMetadata(await sessionMetadataKey(options.connection));
|
|
1734
|
+
if (!stored)
|
|
1735
|
+
throw new Error('Signal Protocol Relay device link requires an active hosted session');
|
|
1736
|
+
const active = new HostedRelayHttpTransport(options.connection, options.activeStorage, options.request.activeDeviceAuthentication, parseSession(stored, options.connection), false);
|
|
1737
|
+
return active.linkDevice(options.request, options.storage);
|
|
1738
|
+
}
|
|
1601
1739
|
//# sourceMappingURL=hosted-transport.js.map
|