@open-e2ee/signal-protocol-sdk 9.3.0 → 9.5.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/ADAPTERS.md +1 -0
- package/CHANGELOG.md +269 -0
- package/README.md +1 -1
- package/SECURITY.md +2 -2
- package/client/README.md +11 -14
- package/dist/client/client.d.ts +134 -64
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +333 -179
- package/dist/client/client.js.map +1 -1
- package/dist/client/config.d.ts +4 -7
- package/dist/client/config.d.ts.map +1 -1
- package/dist/client/config.js.map +1 -1
- package/dist/client/content-adapter.d.ts +8 -0
- package/dist/client/content-adapter.d.ts.map +1 -1
- package/dist/client/content-adapter.js +4 -0
- package/dist/client/content-adapter.js.map +1 -1
- package/dist/client/event-hooks.d.ts +1 -1
- package/dist/client/group-outbox.d.ts +2 -4
- package/dist/client/group-outbox.d.ts.map +1 -1
- package/dist/client/group-outbox.js +7 -1
- package/dist/client/group-outbox.js.map +1 -1
- package/dist/client/hosted-anonymous-delivery.d.ts +1 -1
- package/dist/client/hosted-anonymous-delivery.d.ts.map +1 -1
- package/dist/client/hosted-anonymous-delivery.js +5 -14
- package/dist/client/hosted-anonymous-delivery.js.map +1 -1
- package/dist/client/hosted-mailbox-subscription.d.ts.map +1 -1
- package/dist/client/hosted-mailbox-subscription.js +136 -15
- package/dist/client/hosted-mailbox-subscription.js.map +1 -1
- package/dist/client/hosted-transport.d.ts +2 -2
- package/dist/client/hosted-transport.d.ts.map +1 -1
- package/dist/client/hosted-transport.js +20 -5
- package/dist/client/hosted-transport.js.map +1 -1
- package/dist/client/messages.d.ts.map +1 -1
- package/dist/client/messages.js +12 -2
- package/dist/client/messages.js.map +1 -1
- package/dist/client/relay-acceptance.d.ts +29 -0
- package/dist/client/relay-acceptance.d.ts.map +1 -0
- package/dist/client/relay-acceptance.js +29 -0
- package/dist/client/relay-acceptance.js.map +1 -0
- package/dist/client/relay-subscription.d.ts +43 -1
- package/dist/client/relay-subscription.d.ts.map +1 -1
- package/dist/client/relay-subscription.js +278 -100
- package/dist/client/relay-subscription.js.map +1 -1
- package/dist/client/relay-work.d.ts +7 -6
- package/dist/client/relay-work.d.ts.map +1 -1
- package/dist/client/relay-work.js +34 -9
- package/dist/client/relay-work.js.map +1 -1
- package/dist/client/retry-family.d.ts +119 -0
- package/dist/client/retry-family.d.ts.map +1 -0
- package/dist/client/retry-family.js +170 -0
- package/dist/client/retry-family.js.map +1 -0
- package/dist/client/retry-request-envelope.d.ts +106 -0
- package/dist/client/retry-request-envelope.d.ts.map +1 -0
- package/dist/client/retry-request-envelope.js +245 -0
- package/dist/client/retry-request-envelope.js.map +1 -0
- package/dist/client/retry.d.ts +66 -24
- package/dist/client/retry.d.ts.map +1 -1
- package/dist/client/retry.js +239 -139
- package/dist/client/retry.js.map +1 -1
- package/dist/client/sealed-sender.d.ts +15 -3
- package/dist/client/sealed-sender.d.ts.map +1 -1
- package/dist/client/sealed-sender.js +22 -3
- package/dist/client/sealed-sender.js.map +1 -1
- package/dist/client/signal-service-cipher.d.ts +52 -0
- package/dist/client/signal-service-cipher.d.ts.map +1 -1
- package/dist/client/signal-service-cipher.js +185 -15
- package/dist/client/signal-service-cipher.js.map +1 -1
- package/dist/client/state.d.ts +12 -64
- package/dist/client/state.d.ts.map +1 -1
- package/dist/client/state.js +22 -98
- package/dist/client/state.js.map +1 -1
- package/dist/client/types.d.ts +28 -2
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/types.js.map +1 -1
- package/dist/internal/protocol/sealed-sender/types.d.ts +1 -1
- package/dist/internal/protocol/sealed-sender/types.js +1 -1
- package/dist/local/store/received-content.d.ts +16 -2
- package/dist/local/store/received-content.d.ts.map +1 -1
- package/dist/local/store/received-content.js +18 -3
- package/dist/local/store/received-content.js.map +1 -1
- package/dist/local/store/reliability.d.ts +260 -2
- package/dist/local/store/reliability.d.ts.map +1 -1
- package/dist/local/store/reliability.js +390 -12
- package/dist/local/store/reliability.js.map +1 -1
- package/dist/remote/relay/types.d.ts +31 -31
- package/dist/remote/relay/types.d.ts.map +1 -1
- package/dist/types/api.d.ts +74 -26
- package/dist/types/api.d.ts.map +1 -1
- package/docs/ASSURANCE.md +5 -5
- package/docs/DEVIATIONS.md +4 -5
- package/docs/INTERFACES.md +2 -0
- package/package.json +1 -1
|
@@ -10,6 +10,7 @@ import type { SealedSenderConfig, SealedSenderDeliveryMode } from './config.js';
|
|
|
10
10
|
import type { Envelope, SealedSenderAuth } from '../remote/relay/types.js';
|
|
11
11
|
import { type Logger } from '../logger.js';
|
|
12
12
|
import type { SignalProtocolLocalStore } from '../types/index.js';
|
|
13
|
+
import { ContentHint } from '../types/messages.js';
|
|
13
14
|
import type { EndorsementManager } from './endorsement-manager.js';
|
|
14
15
|
import { type ContactProfileStateStore } from '../profile/contact-state.js';
|
|
15
16
|
import { SealedSenderContentType } from '../internal/protocol/sealed-sender/types.js';
|
|
@@ -42,7 +43,7 @@ export interface SealedSenderResolutionContext {
|
|
|
42
43
|
export declare function serializeDirectSealedSenderMessage(msg: {
|
|
43
44
|
recipientUserId: string;
|
|
44
45
|
recipientDeviceId: number;
|
|
45
|
-
}, ciphertextBase64: string, messageType: 'prekey_bundle' | 'ciphertext' | 'sender_key', recipientRegistrationId: number | undefined, sealedSender: ResolvedSealedSenderContext): Promise<string>;
|
|
46
|
+
}, ciphertextBase64: string, messageType: 'prekey_bundle' | 'ciphertext' | 'sender_key', recipientRegistrationId: number | undefined, sealedSender: ResolvedSealedSenderContext, contentHint: ContentHint | undefined): Promise<string>;
|
|
46
47
|
export declare function resolveSealedSenderContext(context: SealedSenderResolutionContext, recipientUserId: string, groupId?: string): Promise<ResolvedSealedSenderContext | null>;
|
|
47
48
|
/**
|
|
48
49
|
* Unseal a sealed sender message to reveal the sender and inner ciphertext.
|
|
@@ -57,19 +58,21 @@ export declare function resolveSealedSenderContext(context: SealedSenderResoluti
|
|
|
57
58
|
* @param recipientDeviceId - Recipient's device ID
|
|
58
59
|
* @param config - Sealed sender config with trust roots
|
|
59
60
|
* @param relayEnqueueTime - Immutable time when Relay accepted the message
|
|
60
|
-
* @returns Unsealed envelope info with sender identity and
|
|
61
|
+
* @returns Unsealed envelope info with sender identity, inner ciphertext and content hint
|
|
61
62
|
*/
|
|
62
63
|
export declare function unsealMessage(sealedCiphertextBase64: string, recipientIdentityPrivate: Uint8Array, recipientUuid: string, recipientDeviceId: number, config: SealedSenderConfig, relayEnqueueTime: number | undefined, providedLogger?: Logger): Promise<{
|
|
63
64
|
senderUserId: string;
|
|
64
65
|
senderDeviceId: number;
|
|
65
66
|
innerCiphertextBase64: string;
|
|
66
67
|
contentType: SealedSenderContentType;
|
|
68
|
+
contentHint: ContentHint;
|
|
67
69
|
}>;
|
|
68
70
|
/**
|
|
69
71
|
* Reconstruct an Envelope from an unsealed message.
|
|
70
72
|
*
|
|
71
73
|
* Takes the original sealed sender envelope (with empty sender fields)
|
|
72
|
-
* and fills in the sender identity revealed by unsealing.
|
|
74
|
+
* and fills in the sender identity revealed by unsealing. The content hint
|
|
75
|
+
* also travels inside the seal, so the unsealed envelope carries it.
|
|
73
76
|
*
|
|
74
77
|
* @param originalEnvelope - The incoming envelope with messageType 'unidentified_sender'
|
|
75
78
|
* @param unsealed - The unsealed sender info and inner ciphertext
|
|
@@ -80,7 +83,16 @@ export declare function reconstructEnvelope(originalEnvelope: Envelope, unsealed
|
|
|
80
83
|
senderDeviceId: number;
|
|
81
84
|
innerCiphertextBase64: string;
|
|
82
85
|
contentType: SealedSenderContentType;
|
|
86
|
+
contentHint: ContentHint;
|
|
83
87
|
}): Envelope;
|
|
88
|
+
/**
|
|
89
|
+
* Attach the unsealed envelope to an error that its decryption threw. The
|
|
90
|
+
* error handler then asks the unsealed sender device for a resend, because
|
|
91
|
+
* the sealed envelope names no sender.
|
|
92
|
+
*/
|
|
93
|
+
export declare function attachUnsealedEnvelope(error: unknown, envelope: Envelope): void;
|
|
94
|
+
/** The unsealed envelope that `attachUnsealedEnvelope` attached to an error. */
|
|
95
|
+
export declare function unsealedEnvelopeOf(error: unknown): Envelope | undefined;
|
|
84
96
|
/**
|
|
85
97
|
* Map a sealed envelope's content type onto the envelope type the decrypt
|
|
86
98
|
* path routes on.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sealed-sender.d.ts","sourceRoot":"","sources":["../../client/sealed-sender.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAC7E,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACxE,OAAO,EAA+B,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AACrE,OAAO,KAAK,EAAU,wBAAwB,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"sealed-sender.d.ts","sourceRoot":"","sources":["../../client/sealed-sender.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,UAAU,CAAC;AAC7E,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACxE,OAAO,EAA+B,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AACrE,OAAO,KAAK,EAAU,wBAAwB,EAAE,MAAM,UAAU,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIhD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAA0B,KAAK,wBAAwB,EAAE,MAAM,0BAA0B,CAAC;AACjG,OAAO,EACL,uBAAuB,EAGxB,MAAM,0CAA0C,CAAC;AASlD,OAAO,EAAE,CAAC;AAEV,MAAM,MAAM,oBAAoB,GAAG,MAAM,OAAO,CAAC;IAC/C,uBAAuB,EAAE,MAAM,CAAC;IA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ignalProtocolLogger } from '../logger.js';
|
|
10
|
+
import { ContentHint } from '../types/messages.js';
|
|
10
11
|
import { ProtocolAddress } from '../types/address.js';
|
|
11
12
|
import { x25519 } from '@noble/curves/ed25519.js';
|
|
12
13
|
import { base64ToBytes, bytesToBase64 } from '../internal/crypto/index.js';
|
|
@@ -16,7 +17,7 @@ import { deserializeSenderCertificate, sealMultiRecipient } from '../internal/pr
|
|
|
16
17
|
import { deriveAccessKey } from '../internal/protocol/sealed-sender/delivery-token.js';
|
|
17
18
|
import { unseal } from '../internal/protocol/sealed-sender/decryption.js';
|
|
18
19
|
import { deserializeReceivedMessage, serializeSentMessage, } from '../internal/protocol/sealed-sender/multi-recipient-message.js';
|
|
19
|
-
export async function serializeDirectSealedSenderMessage(msg, ciphertextBase64, messageType, recipientRegistrationId, sealedSender) {
|
|
20
|
+
export async function serializeDirectSealedSenderMessage(msg, ciphertextBase64, messageType, recipientRegistrationId, sealedSender, contentHint) {
|
|
20
21
|
const senderCertificate = deserializeSenderCertificate(base64ToBytes(sealedSender.senderCertificateBase64));
|
|
21
22
|
const sealed = await sealMultiRecipient({
|
|
22
23
|
senderCertificate,
|
|
@@ -31,6 +32,7 @@ export async function serializeDirectSealedSenderMessage(msg, ciphertextBase64,
|
|
|
31
32
|
},
|
|
32
33
|
],
|
|
33
34
|
signalProtocolMessage: base64ToBytes(ciphertextBase64),
|
|
35
|
+
contentHint,
|
|
34
36
|
contentType: messageType === 'sender_key'
|
|
35
37
|
? SealedSenderContentType.SENDERKEY_MESSAGE
|
|
36
38
|
: messageType === 'prekey_bundle'
|
|
@@ -164,7 +166,7 @@ export async function resolveSealedSenderContext(context, recipientUserId, group
|
|
|
164
166
|
* @param recipientDeviceId - Recipient's device ID
|
|
165
167
|
* @param config - Sealed sender config with trust roots
|
|
166
168
|
* @param relayEnqueueTime - Immutable time when Relay accepted the message
|
|
167
|
-
* @returns Unsealed envelope info with sender identity and
|
|
169
|
+
* @returns Unsealed envelope info with sender identity, inner ciphertext and content hint
|
|
168
170
|
*/
|
|
169
171
|
export async function unsealMessage(sealedCiphertextBase64, recipientIdentityPrivate, recipientUuid, recipientDeviceId, config, relayEnqueueTime, providedLogger) {
|
|
170
172
|
if (typeof relayEnqueueTime !== 'number' ||
|
|
@@ -237,13 +239,15 @@ async function unsealReceivedMessage(sealedBytes, recipientIdentityPrivate, reci
|
|
|
237
239
|
senderDeviceId: content.senderCertificate.senderDeviceId,
|
|
238
240
|
innerCiphertextBase64: content.signalProtocolMessage,
|
|
239
241
|
contentType: content.contentType,
|
|
242
|
+
contentHint: content.contentHint ?? ContentHint.Default,
|
|
240
243
|
};
|
|
241
244
|
}
|
|
242
245
|
/**
|
|
243
246
|
* Reconstruct an Envelope from an unsealed message.
|
|
244
247
|
*
|
|
245
248
|
* Takes the original sealed sender envelope (with empty sender fields)
|
|
246
|
-
* and fills in the sender identity revealed by unsealing.
|
|
249
|
+
* and fills in the sender identity revealed by unsealing. The content hint
|
|
250
|
+
* also travels inside the seal, so the unsealed envelope carries it.
|
|
247
251
|
*
|
|
248
252
|
* @param originalEnvelope - The incoming envelope with messageType 'unidentified_sender'
|
|
249
253
|
* @param unsealed - The unsealed sender info and inner ciphertext
|
|
@@ -256,8 +260,23 @@ export function reconstructEnvelope(originalEnvelope, unsealed) {
|
|
|
256
260
|
senderDeviceId: unsealed.senderDeviceId,
|
|
257
261
|
ciphertext: unsealed.innerCiphertextBase64,
|
|
258
262
|
messageType: envelopeTypeForContent(unsealed.contentType),
|
|
263
|
+
contentHint: unsealed.contentHint,
|
|
259
264
|
};
|
|
260
265
|
}
|
|
266
|
+
const unsealedEnvelopes = new WeakMap();
|
|
267
|
+
/**
|
|
268
|
+
* Attach the unsealed envelope to an error that its decryption threw. The
|
|
269
|
+
* error handler then asks the unsealed sender device for a resend, because
|
|
270
|
+
* the sealed envelope names no sender.
|
|
271
|
+
*/
|
|
272
|
+
export function attachUnsealedEnvelope(error, envelope) {
|
|
273
|
+
if (typeof error === 'object' && error !== null)
|
|
274
|
+
unsealedEnvelopes.set(error, envelope);
|
|
275
|
+
}
|
|
276
|
+
/** The unsealed envelope that `attachUnsealedEnvelope` attached to an error. */
|
|
277
|
+
export function unsealedEnvelopeOf(error) {
|
|
278
|
+
return typeof error === 'object' && error !== null ? unsealedEnvelopes.get(error) : undefined;
|
|
279
|
+
}
|
|
261
280
|
/**
|
|
262
281
|
* Map a sealed envelope's content type onto the envelope type the decrypt
|
|
263
282
|
* path routes on.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sealed-sender.js","sourceRoot":"","sources":["../../client/sealed-sender.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAE,2BAA2B,EAAe,MAAM,WAAW,CAAC;AAErE,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAElE,OAAO,EAAE,sBAAsB,EAAiC,MAAM,0BAA0B,CAAC;AACjG,OAAO,EACL,uBAAuB,EACvB,mCAAmC,EACnC,6BAA6B,GAC9B,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,4BAA4B,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AACtG,OAAO,EAAE,eAAe,EAAE,MAAM,mDAAmD,CAAC;AACpF,OAAO,EAAE,MAAM,EAAE,MAAM,+CAA+C,CAAC;AACvE,OAAO,EACL,0BAA0B,EAC1B,oBAAoB,GACrB,MAAM,4DAA4D,CAAC;AAkCpE,MAAM,CAAC,KAAK,UAAU,kCAAkC,CACtD,GAA2D,EAC3D,gBAAwB,EACxB,WAA0D,EAC1D,uBAA2C,EAC3C,YAAyC;
|
|
1
|
+
{"version":3,"file":"sealed-sender.js","sourceRoot":"","sources":["../../client/sealed-sender.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAE,2BA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CAAC,QAAQ,CAAC,WAAW,CAAC;QACzD,WAAW,EAAE,QAAQ,CAAC,WAAW;KAClC,CAAC;AACJ,CAAC;AAED,MAAM,iBAAiB,GAAG,IAAI,OAAO,EAAoB,CAAC;AAE1D;;;;GAIG;AACH,MAAM,UAAU,sBAAsB,CAAC,KAAc,EAAE,QAAkB;IACvE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,iBAAiB,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;AAC1F,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AAChG,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,sBAAsB,CACpC,WAAoC;IAEpC,QAAQ,WAAW,EAAE,CAAC;QACpB,KAAK,uBAAuB,CAAC,iBAAiB;YAC5C,OAAO,YAAY,CAAC;QACtB,KAAK,uBAAuB,CAAC,cAAc,CAAC;QAC5C,KAAK,uBAAuB,CAAC,OAAO;YAClC,OAAO,YAAY,CAAC;QACtB;YACE,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC9D,CAAC;AACH,CAAC"}
|
|
@@ -22,7 +22,9 @@ import { SenderKeyManager } from '../internal/protocol/sender-keys/index.js';
|
|
|
22
22
|
import type { EndorsementManager } from './endorsement-manager.js';
|
|
23
23
|
import type { GroupReceiveAuthorizer } from './group-receive-authorization.js';
|
|
24
24
|
import type { PreparedAttachmentUpload, SendOptions, SendResult } from './types.js';
|
|
25
|
+
import { ContentHint } from '../types/messages.js';
|
|
25
26
|
import { type BlockedRecipientsSyncInput, type ConfigurationSyncInput, type MediaAttachmentDeleteSyncInput, type ReadSyncEntryInput, type RecipientUsernameSyncInput, type SignalProtocolContentAdapter, type TaskNotificationAckSyncInput, type UsernameStateSyncInput, type VerificationStateSyncInput, type ViewOnceOpenSyncInput } from './content-adapter.js';
|
|
27
|
+
import { type RetryResendTarget } from '../local/store/reliability.js';
|
|
26
28
|
import { type BoundedFanOut } from '../utils/bounded-fan-out.js';
|
|
27
29
|
import { type SealedSenderProvider as SealedSenderProviderContract } from './sealed-sender.js';
|
|
28
30
|
import { type ContactProfileStateStore } from '../profile/contact-state.js';
|
|
@@ -256,6 +258,56 @@ export declare class SignalProtocolServiceCipher {
|
|
|
256
258
|
* @see https://signal.org/docs/specifications/sesame/
|
|
257
259
|
*/
|
|
258
260
|
encrypt(recipientId: string, content: Uint8Array, options?: SendOptions, sessions?: SendSessionCallbacks | undefined, stopSignal?: AbortSignal): Promise<SendResult>;
|
|
261
|
+
/**
|
|
262
|
+
* Encrypt content for one device of a user and post it to that device only.
|
|
263
|
+
* The send makes no outbox intent and no sent-sync transcript. A retry
|
|
264
|
+
* resend uses it: the retry request is the durable job, and only the device
|
|
265
|
+
* that asked gets the message again. The post uses the sealed-sender
|
|
266
|
+
* context of a direct send to the user.
|
|
267
|
+
*
|
|
268
|
+
* With a retry target, the resend stores its encryption under the device
|
|
269
|
+
* and the failed envelope ID. The resend carries the attempt number of
|
|
270
|
+
* the request that it answers, from the request envelope ID. Its client
|
|
271
|
+
* message ID is `<retryId>:resend` or `<retryId>:null`, with
|
|
272
|
+
* `:<attempt>` from attempt 2. A call for the request envelope and the
|
|
273
|
+
* kind of the stored record posts the stored bytes with their epoch
|
|
274
|
+
* again, and does not encrypt: that is the sender's own retry of a post
|
|
275
|
+
* that did not complete. A call for another request envelope or kind
|
|
276
|
+
* encrypts with a fresh epoch, replaces the record in one write, and
|
|
277
|
+
* posts it. So does a call whose stored bytes the Relay refuses with
|
|
278
|
+
* OPERATION_EXPIRED: the new bytes post under the same ID. A
|
|
279
|
+
* RETRY_CONFLICT answer to a post means that the Relay holds an earlier
|
|
280
|
+
* encryption under this ID, so the answer is complete. When the Relay
|
|
281
|
+
* admits the new bytes after the recipient acknowledged the earlier
|
|
282
|
+
* ones, the recipient drops them as processed. Nothing deletes the
|
|
283
|
+
* record before `RELIABILITY_RECORD_TTL_MS`.
|
|
284
|
+
*
|
|
285
|
+
* @param recipientUserId - The user of the device
|
|
286
|
+
* @param recipientDeviceId - The device that gets the message
|
|
287
|
+
* @param content - The plaintext to encrypt. Null when the plaintext is
|
|
288
|
+
* gone: then only a stored attempt can post
|
|
289
|
+
* @param options - The client timestamp and the content hint of the
|
|
290
|
+
* message, and the retry request that a retry resend answers. Without a
|
|
291
|
+
* retry target, the client message ID is a new UUID and nothing is
|
|
292
|
+
* stored. The timestamp goes in the envelope
|
|
293
|
+
* @param stopSignal - The stop signal of the relay work that sends. When it
|
|
294
|
+
* aborts while the send waits for the recipient's lock, the send throws
|
|
295
|
+
* RelayWorkStopped
|
|
296
|
+
* @returns False only when the content is null and no stored attempt can
|
|
297
|
+
* post: there is none for this request attempt, or the Relay refused it
|
|
298
|
+
* with OPERATION_EXPIRED
|
|
299
|
+
* @throws Error when the request envelope ID is not a retry request of
|
|
300
|
+
* the retry ID. Nothing is posted
|
|
301
|
+
*/
|
|
302
|
+
resendToDevice(recipientUserId: string, recipientDeviceId: number, content: string | null, options: {
|
|
303
|
+
timestamp: number;
|
|
304
|
+
contentHint?: ContentHint;
|
|
305
|
+
retry?: RetryResendTarget;
|
|
306
|
+
}, stopSignal?: AbortSignal): Promise<boolean>;
|
|
307
|
+
/** Post the encrypted bytes of a resend with their operation epoch, under one client message ID. */
|
|
308
|
+
private postResend;
|
|
309
|
+
/** Encrypt one attempt of a resend, with the current time as its operation epoch. */
|
|
310
|
+
private encryptResend;
|
|
259
311
|
/**
|
|
260
312
|
* Encrypt and upload attachment data without sending a standalone message.
|
|
261
313
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signal-service-cipher.d.ts","sourceRoot":"","sources":["../../client/signal-service-cipher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,KAAK,EACV,yBAAyB,EACzB,QAAQ,EAGR,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,KAAK,EAAE,wBAAwB,EAA2B,MAAM,UAAU,CAAC;AAIlF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAGvD,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAwB,MAAM,0BAA0B,CAAC;AACnG,OAAO,EAA+B,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAEpE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAE5E,OAAO,KAAK,EAAE,wBAAwB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"signal-service-cipher.d.ts","sourceRoot":"","sources":["../../client/signal-service-cipher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,KAAK,EACV,yBAAyB,EACzB,QAAQ,EAGR,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,KAAK,EAAE,wBAAwB,EAA2B,MAAM,UAAU,CAAC;AAIlF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAGvD,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAwB,MAAM,0BAA0B,CAAC;AACnG,OAAO,EAA+B,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AACrE,OAAO,EAAE,gBAAgB,E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1C,OAAO,CAAC,wBAAwB,CAAC,CAGnC;IAMD;;OAEG;IACH,OAAO,CAAC,eAAe;IAsBvB;;;;;;OAMG;IACG,eAAe,CAAC,aAAa,EAAE,aAAa,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA4BvF;IAED;;;;;;;;;OASG;YACW,YAAY;IA6F1B;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;YACW,qBAAqB;YAsDrB,gBAAgB;IAU9B,uFAAuF;IACvF,OAAO,CAAC,sBAAsB;IAM9B;;;;;;;;;;OAUG;YACW,uBAAuB;IA6FrC;;OAEG;YACW,aAAa;YAeb,uBAAuB;YAkBvB,6BAA6B;IA2H3C;;;;;;;;;;;;OAYG;YACW,oCAAoC;IAmDlD,sFAAsF;YACxE,4BAA4B;IAc1C;;;;;OAKG;YACW,qBAAqB;IA2CnC,kFAAkF;YACpE,+BAA+B;YAW/B,gCAAgC;IAoC9C;;;;;;OAMG;YACW,iCAAiC;YAYjC,uCAAuC;YAsCvC,6BAA6B;IAyC3C,qFAAqF;YACvE,6BAA6B;IA4B3C;;;;OAIG;YACW,sBAAsB;YAgFtB,wBAAwB;YAyHxB,+BAA+B;YAmC/B,6BAA6B;YAuC7B,kCAAkC;IAqBhD;;;;;;;;;;;;;;;;;;;;;;;OAuBG;YACW,0BAA0B;IA+BxC;;;;;;;;;;;;;;;;OAgBG;YACW,YAAY;IA2L1B;;;;;;;;OAQG;YACW,yBAAyB;YA0BzB,4BAA4B;IA+H1C;;;;;OAKG;YACW,cAAc;IAuB5B;;;;;;;;;;;;;;;;OAgBG;YACW,uBAAuB;YA4CvB,uBAAuB;CAmCtC"}
|
|
@@ -24,14 +24,15 @@ import { isGroupId, extractGroupId } from '../internal/groups/index.js';
|
|
|
24
24
|
import { GroupSenderKeyOperations } from './group-sender-key-operations.js';
|
|
25
25
|
import { createDefaultSignalProtocolContentAdapter, } from './content-adapter.js';
|
|
26
26
|
import * as CryptoUtils from '../internal/crypto/index.js';
|
|
27
|
-
import { completeOutgoingMessageIntent, getOutgoingMessageIntent, reconcileOutgoingDirectDeviceMessages, replaceOutgoingDirectDeviceMessage, storeOutgoingMessageIntent, withOutgoingMessageIntentLock, } from '../local/store/reliability.js';
|
|
27
|
+
import { completeOutgoingMessageIntent, getOutgoingMessageIntent, getRetryResend, reconcileOutgoingDirectDeviceMessages, replaceOutgoingDirectDeviceMessage, retryAttemptClientMessageId, retryNullMessageClientMessageId, retryRequestAttempt, retryResendClientMessageId, storeOutgoingMessageIntent, storeRetryResend, withOutgoingMessageIntentLock, } from '../local/store/reliability.js';
|
|
28
28
|
import { FanOutError, firstItemError } from '../utils/bounded-fan-out.js';
|
|
29
29
|
import { withRetry } from '../utils/retry.js';
|
|
30
30
|
import { acquireUntilStopped, createRelayFanOut, RelayWorkStopped, relaySendsSealedUnderItsBound, rethrowRelayWorkStopped, } from './relay-work.js';
|
|
31
31
|
import { refusesRemovedDevices, relayDeviceRefusal } from './relay-device-refusal.js';
|
|
32
|
+
import { aggregateRelayAcceptance, relayOperationRefusal, } from './relay-acceptance.js';
|
|
32
33
|
import { prepareGroupSharedMessage } from './group-sealed-sender.js';
|
|
33
34
|
import { sendGroupWithExactOutbox } from './group-outbox.js';
|
|
34
|
-
import { reconstructEnvelope, resolveSealedSenderContext as resolveSealedSenderSendContext, serializeDirectSealedSenderMessage as serializeDirectSealedSenderTransport, unsealMessage, } from './sealed-sender.js';
|
|
35
|
+
import { attachUnsealedEnvelope, reconstructEnvelope, resolveSealedSenderContext as resolveSealedSenderSendContext, serializeDirectSealedSenderMessage as serializeDirectSealedSenderTransport, unsealMessage, } from './sealed-sender.js';
|
|
35
36
|
import { prepareMediaAttachmentUpload, serializeMediaAttachmentMessage } from '../media/index.js';
|
|
36
37
|
import { UnidentifiedAccessMode, } from '../profile/contact-state.js';
|
|
37
38
|
/**
|
|
@@ -147,6 +148,13 @@ function isRefusalOfDevice(error, message) {
|
|
|
147
148
|
const refusal = relayDeviceRefusal(error);
|
|
148
149
|
return (refusal?.userId === message.recipientUserId && refusal.deviceId === message.recipientDeviceId);
|
|
149
150
|
}
|
|
151
|
+
/** The client message ID of one attempt of a stored resend or null message. */
|
|
152
|
+
function retryResendAttemptId(resend) {
|
|
153
|
+
const id = resend.kind === 'resend'
|
|
154
|
+
? retryResendClientMessageId(resend.retryId)
|
|
155
|
+
: retryNullMessageClientMessageId(resend.retryId);
|
|
156
|
+
return retryAttemptClientMessageId(id, resend.attempt);
|
|
157
|
+
}
|
|
150
158
|
/**
|
|
151
159
|
* SignalProtocolServiceCipher - Routes encryption and decryption to appropriate ciphers
|
|
152
160
|
*
|
|
@@ -476,7 +484,14 @@ export class SignalProtocolServiceCipher {
|
|
|
476
484
|
// Reconstruct envelope with revealed sender identity
|
|
477
485
|
const innerEnvelope = reconstructEnvelope(envelope, unsealed);
|
|
478
486
|
// Recursively decrypt the inner message (now a standard ciphertext)
|
|
479
|
-
|
|
487
|
+
let decrypted;
|
|
488
|
+
try {
|
|
489
|
+
decrypted = await this.decrypt(innerEnvelope, undefined, receiveId, stopSignal);
|
|
490
|
+
}
|
|
491
|
+
catch (error) {
|
|
492
|
+
attachUnsealedEnvelope(error, innerEnvelope);
|
|
493
|
+
throw error;
|
|
494
|
+
}
|
|
480
495
|
return { ...decrypted, arrivedSealed: true };
|
|
481
496
|
}
|
|
482
497
|
// Validate message type before processing
|
|
@@ -621,6 +636,150 @@ export class SignalProtocolServiceCipher {
|
|
|
621
636
|
throw attachClientMessageId(error, clientMessageId);
|
|
622
637
|
}
|
|
623
638
|
}
|
|
639
|
+
/**
|
|
640
|
+
* Encrypt content for one device of a user and post it to that device only.
|
|
641
|
+
* The send makes no outbox intent and no sent-sync transcript. A retry
|
|
642
|
+
* resend uses it: the retry request is the durable job, and only the device
|
|
643
|
+
* that asked gets the message again. The post uses the sealed-sender
|
|
644
|
+
* context of a direct send to the user.
|
|
645
|
+
*
|
|
646
|
+
* With a retry target, the resend stores its encryption under the device
|
|
647
|
+
* and the failed envelope ID. The resend carries the attempt number of
|
|
648
|
+
* the request that it answers, from the request envelope ID. Its client
|
|
649
|
+
* message ID is `<retryId>:resend` or `<retryId>:null`, with
|
|
650
|
+
* `:<attempt>` from attempt 2. A call for the request envelope and the
|
|
651
|
+
* kind of the stored record posts the stored bytes with their epoch
|
|
652
|
+
* again, and does not encrypt: that is the sender's own retry of a post
|
|
653
|
+
* that did not complete. A call for another request envelope or kind
|
|
654
|
+
* encrypts with a fresh epoch, replaces the record in one write, and
|
|
655
|
+
* posts it. So does a call whose stored bytes the Relay refuses with
|
|
656
|
+
* OPERATION_EXPIRED: the new bytes post under the same ID. A
|
|
657
|
+
* RETRY_CONFLICT answer to a post means that the Relay holds an earlier
|
|
658
|
+
* encryption under this ID, so the answer is complete. When the Relay
|
|
659
|
+
* admits the new bytes after the recipient acknowledged the earlier
|
|
660
|
+
* ones, the recipient drops them as processed. Nothing deletes the
|
|
661
|
+
* record before `RELIABILITY_RECORD_TTL_MS`.
|
|
662
|
+
*
|
|
663
|
+
* @param recipientUserId - The user of the device
|
|
664
|
+
* @param recipientDeviceId - The device that gets the message
|
|
665
|
+
* @param content - The plaintext to encrypt. Null when the plaintext is
|
|
666
|
+
* gone: then only a stored attempt can post
|
|
667
|
+
* @param options - The client timestamp and the content hint of the
|
|
668
|
+
* message, and the retry request that a retry resend answers. Without a
|
|
669
|
+
* retry target, the client message ID is a new UUID and nothing is
|
|
670
|
+
* stored. The timestamp goes in the envelope
|
|
671
|
+
* @param stopSignal - The stop signal of the relay work that sends. When it
|
|
672
|
+
* aborts while the send waits for the recipient's lock, the send throws
|
|
673
|
+
* RelayWorkStopped
|
|
674
|
+
* @returns False only when the content is null and no stored attempt can
|
|
675
|
+
* post: there is none for this request attempt, or the Relay refused it
|
|
676
|
+
* with OPERATION_EXPIRED
|
|
677
|
+
* @throws Error when the request envelope ID is not a retry request of
|
|
678
|
+
* the retry ID. Nothing is posted
|
|
679
|
+
*/
|
|
680
|
+
async resendToDevice(recipientUserId, recipientDeviceId, content, options, stopSignal) {
|
|
681
|
+
if (!this.relay)
|
|
682
|
+
throw new Error('Relay not configured - cannot resend');
|
|
683
|
+
const { retry } = options;
|
|
684
|
+
if (content === null && retry === undefined) {
|
|
685
|
+
throw new Error('A resend without content needs a stored attempt');
|
|
686
|
+
}
|
|
687
|
+
// The answer carries the attempt number of its request.
|
|
688
|
+
const target = retry && { ...retry, attempt: retryRequestAttempt(retry) };
|
|
689
|
+
const post = async (resend) => {
|
|
690
|
+
try {
|
|
691
|
+
await this.postResend(resend, retryResendAttemptId(resend), stopSignal);
|
|
692
|
+
}
|
|
693
|
+
catch (error) {
|
|
694
|
+
if (relayOperationRefusal(error) !== 'RETRY_CONFLICT')
|
|
695
|
+
throw error;
|
|
696
|
+
// Only this sender posts this ID. A new encryption for the same
|
|
697
|
+
// request attempt and kind posts the same ID, so a conflict means
|
|
698
|
+
// that the Relay holds the earlier encryption.
|
|
699
|
+
this.logger.info('The Relay holds an earlier encryption of a retry resend attempt', {
|
|
700
|
+
category: 'E2EE',
|
|
701
|
+
data: { retryId: resend.retryId, kind: resend.kind, attempt: resend.attempt },
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
};
|
|
705
|
+
return await acquireUntilStopped(this.lock, `encrypt:${recipientUserId}`, async () => {
|
|
706
|
+
if (target === undefined) {
|
|
707
|
+
const resend = await this.encryptResend(recipientUserId, recipientDeviceId, content, options);
|
|
708
|
+
await this.postResend(resend, await CryptoUtils.generateUuidV4(), stopSignal);
|
|
709
|
+
return true;
|
|
710
|
+
}
|
|
711
|
+
const stored = await getRetryResend(this.storage, recipientUserId, recipientDeviceId, target.failedEnvelopeId);
|
|
712
|
+
if (stored?.requestEnvelopeId === target.requestEnvelopeId && stored.kind === target.kind) {
|
|
713
|
+
try {
|
|
714
|
+
await post(stored);
|
|
715
|
+
return true;
|
|
716
|
+
}
|
|
717
|
+
catch (error) {
|
|
718
|
+
if (relayOperationRefusal(error) !== 'OPERATION_EXPIRED')
|
|
719
|
+
throw error;
|
|
720
|
+
}
|
|
721
|
+
// The Relay no longer admits or replays the stored operation.
|
|
722
|
+
if (content === null) {
|
|
723
|
+
this.logger.info('A stored retry resend expired, and its plaintext is gone', {
|
|
724
|
+
category: 'E2EE',
|
|
725
|
+
data: { retryId: stored.retryId, attempt: stored.attempt },
|
|
726
|
+
});
|
|
727
|
+
return false;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
if (content === null)
|
|
731
|
+
return false;
|
|
732
|
+
// A new encryption replaces the record before its post.
|
|
733
|
+
const resend = {
|
|
734
|
+
...target,
|
|
735
|
+
...(await this.encryptResend(recipientUserId, recipientDeviceId, content, options)),
|
|
736
|
+
};
|
|
737
|
+
await storeRetryResend(this.storage, resend);
|
|
738
|
+
await post(resend);
|
|
739
|
+
return true;
|
|
740
|
+
}, stopSignal);
|
|
741
|
+
}
|
|
742
|
+
/** Post the encrypted bytes of a resend with their operation epoch, under one client message ID. */
|
|
743
|
+
async postResend(resend, clientMessageId, stopSignal) {
|
|
744
|
+
const { message } = resend;
|
|
745
|
+
if (resend.transportMode !== 'identified' &&
|
|
746
|
+
(!message.sealedSenderMessage || !resend.sealedSenderAuth)) {
|
|
747
|
+
throw new Error('Corrupt retry-resend record');
|
|
748
|
+
}
|
|
749
|
+
await this.sendToDevice(message, message.ciphertext, message.messageType, message.recipientRegistrationId, null, resend.contentHint, clientMessageId, resend.transportMode === 'identified'
|
|
750
|
+
? undefined
|
|
751
|
+
: {
|
|
752
|
+
sentMessageBase64: message.sealedSenderMessage,
|
|
753
|
+
auth: resend.sealedSenderAuth,
|
|
754
|
+
deliveryMode: resend.transportMode === 'sealed_sender_required' ? 'required' : 'preferred',
|
|
755
|
+
}, {
|
|
756
|
+
...(stopSignal && { stopSignal }),
|
|
757
|
+
operationEpochMilliseconds: resend.operationEpochMilliseconds,
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
/** Encrypt one attempt of a resend, with the current time as its operation epoch. */
|
|
761
|
+
async encryptResend(recipientUserId, recipientDeviceId, content, options) {
|
|
762
|
+
const operationEpochMilliseconds = Date.now();
|
|
763
|
+
const sealedSender = await this.resolveSealedSenderContext(recipientUserId);
|
|
764
|
+
const directSealedSender = sealedSender && this.relay?.sendMultiRecipientUnidentified ? sealedSender : null;
|
|
765
|
+
if (directSealedSender && directSealedSender.auth.type !== 'accessKey') {
|
|
766
|
+
throw new Error('Direct sealed-sender delivery requires access-key authorization');
|
|
767
|
+
}
|
|
768
|
+
const message = await this.sesameManager.sendMessage(recipientUserId, recipientDeviceId, new TextEncoder().encode(content), { clientTimestamp: options.timestamp, includeSyncMessages: false });
|
|
769
|
+
return {
|
|
770
|
+
operationEpochMilliseconds,
|
|
771
|
+
transportMode: directSealedSender
|
|
772
|
+
? directSealedSender.config.deliveryMode === 'required'
|
|
773
|
+
? 'sealed_sender_required'
|
|
774
|
+
: 'sealed_sender_preferred'
|
|
775
|
+
: 'identified',
|
|
776
|
+
...(directSealedSender?.auth.type === 'accessKey' && {
|
|
777
|
+
sealedSenderAuth: { ...directSealedSender.auth },
|
|
778
|
+
}),
|
|
779
|
+
...(options.contentHint !== undefined && { contentHint: options.contentHint }),
|
|
780
|
+
message: await this.prepareStoredDirectDeviceMessage(message, directSealedSender, options.contentHint),
|
|
781
|
+
};
|
|
782
|
+
}
|
|
624
783
|
/**
|
|
625
784
|
* Encrypt and upload attachment data without sending a standalone message.
|
|
626
785
|
*/
|
|
@@ -948,7 +1107,7 @@ export class SignalProtocolServiceCipher {
|
|
|
948
1107
|
});
|
|
949
1108
|
// Local work: a stop does not end it, so the intent keeps the ciphertext.
|
|
950
1109
|
const deviceMessages = await this.fanOut
|
|
951
|
-
.all(batch.deviceMessages, (message) => this.prepareStoredDirectDeviceMessage(message, directSealedSender))
|
|
1110
|
+
.all(batch.deviceMessages, (message) => this.prepareStoredDirectDeviceMessage(message, directSealedSender, options.contentHint))
|
|
952
1111
|
.catch((error) => {
|
|
953
1112
|
throw firstItemError(error);
|
|
954
1113
|
});
|
|
@@ -1078,7 +1237,7 @@ export class SignalProtocolServiceCipher {
|
|
|
1078
1237
|
if (sealedSender === undefined) {
|
|
1079
1238
|
sealedSender = await this.resolveStoredDirectSealedSender(intent);
|
|
1080
1239
|
}
|
|
1081
|
-
added.push(await this.prepareStoredDirectDeviceMessage(message, sealedSender));
|
|
1240
|
+
added.push(await this.prepareStoredDirectDeviceMessage(message, sealedSender, intent.contentHint));
|
|
1082
1241
|
}
|
|
1083
1242
|
if (removed.length === 0 && added.length === 0)
|
|
1084
1243
|
return intent;
|
|
@@ -1094,7 +1253,7 @@ export class SignalProtocolServiceCipher {
|
|
|
1094
1253
|
}
|
|
1095
1254
|
return sealedSender;
|
|
1096
1255
|
}
|
|
1097
|
-
async prepareStoredDirectDeviceMessage(message, sealedSender) {
|
|
1256
|
+
async prepareStoredDirectDeviceMessage(message, sealedSender, contentHint) {
|
|
1098
1257
|
const messageType = getEnvelopeMessageType(message.ciphertext);
|
|
1099
1258
|
const session = messageType === 'prekey_bundle'
|
|
1100
1259
|
? await this.sesameManager.getSession(message.recipientUserId, message.recipientDeviceId)
|
|
@@ -1112,7 +1271,7 @@ export class SignalProtocolServiceCipher {
|
|
|
1112
1271
|
}),
|
|
1113
1272
|
};
|
|
1114
1273
|
if (sealedSender) {
|
|
1115
|
-
storedMessage.sealedSenderMessage = await this.serializeDirectSealedSenderMessage(storedMessage, storedMessage.ciphertext, storedMessage.messageType, storedMessage.recipientRegistrationId, sealedSender);
|
|
1274
|
+
storedMessage.sealedSenderMessage = await this.serializeDirectSealedSenderMessage(storedMessage, storedMessage.ciphertext, storedMessage.messageType, storedMessage.recipientRegistrationId, sealedSender, contentHint);
|
|
1116
1275
|
}
|
|
1117
1276
|
return storedMessage;
|
|
1118
1277
|
}
|
|
@@ -1134,7 +1293,7 @@ export class SignalProtocolServiceCipher {
|
|
|
1134
1293
|
throw new EncryptionError('Failed to refresh a rejected recipient device', EncryptionErrorCode.SESSION_ESTABLISHMENT_FAILED, { recipientUserId: rejected.recipientUserId });
|
|
1135
1294
|
}
|
|
1136
1295
|
const freshMessage = await this.sesameManager.sendMessage(rejected.recipientUserId, rejected.recipientDeviceId, plaintextBytes, { clientTimestamp: intent.clientTimestamp, includeSyncMessages: false });
|
|
1137
|
-
const replacement = await this.prepareStoredDirectDeviceMessage(freshMessage, await this.resolveStoredDirectSealedSender(intent));
|
|
1296
|
+
const replacement = await this.prepareStoredDirectDeviceMessage(freshMessage, await this.resolveStoredDirectSealedSender(intent), intent.contentHint);
|
|
1138
1297
|
await replaceOutgoingDirectDeviceMessage(this.storage, intent.clientMessageId, rejected, replacement);
|
|
1139
1298
|
return replacement;
|
|
1140
1299
|
}
|
|
@@ -1217,6 +1376,7 @@ export class SignalProtocolServiceCipher {
|
|
|
1217
1376
|
messageId,
|
|
1218
1377
|
timestamp,
|
|
1219
1378
|
recipientDeviceCount: intent.deviceMessages.length,
|
|
1379
|
+
...aggregateRelayAcceptance(results),
|
|
1220
1380
|
};
|
|
1221
1381
|
await completeOutgoingMessageIntent(this.storage, intent.clientMessageId, result);
|
|
1222
1382
|
return result;
|
|
@@ -1309,7 +1469,7 @@ export class SignalProtocolServiceCipher {
|
|
|
1309
1469
|
const sealedSender = await this.resolveSealedSenderContext(member.userId, groupId);
|
|
1310
1470
|
if (!sealedSender || !this.relay?.sendMultiRecipientUnidentified)
|
|
1311
1471
|
return stored;
|
|
1312
|
-
stored.sealedSenderMessage = await this.serializeDirectSealedSenderMessage(stored, ciphertext, 'sender_key', undefined, sealedSender);
|
|
1472
|
+
stored.sealedSenderMessage = await this.serializeDirectSealedSenderMessage(stored, ciphertext, 'sender_key', undefined, sealedSender, undefined);
|
|
1313
1473
|
stored.sealedSenderDeliveryMode =
|
|
1314
1474
|
sealedSender.config.deliveryMode === 'required' ? 'required' : 'preferred';
|
|
1315
1475
|
if (sealedSender.auth.type === 'accessKey') {
|
|
@@ -1350,8 +1510,8 @@ export class SignalProtocolServiceCipher {
|
|
|
1350
1510
|
}
|
|
1351
1511
|
: null;
|
|
1352
1512
|
}
|
|
1353
|
-
async serializeDirectSealedSenderMessage(msg, ciphertextBase64, messageType, recipientRegistrationId, sealedSender) {
|
|
1354
|
-
return serializeDirectSealedSenderTransport(msg, ciphertextBase64, messageType, recipientRegistrationId, sealedSender);
|
|
1513
|
+
async serializeDirectSealedSenderMessage(msg, ciphertextBase64, messageType, recipientRegistrationId, sealedSender, contentHint) {
|
|
1514
|
+
return serializeDirectSealedSenderTransport(msg, ciphertextBase64, messageType, recipientRegistrationId, sealedSender, contentHint);
|
|
1355
1515
|
}
|
|
1356
1516
|
/**
|
|
1357
1517
|
* Resolve sealed sender context for a recipient.
|
|
@@ -1433,16 +1593,23 @@ export class SignalProtocolServiceCipher {
|
|
|
1433
1593
|
const prepared = preparedSealedSender ??
|
|
1434
1594
|
(sealedSender
|
|
1435
1595
|
? {
|
|
1436
|
-
sentMessageBase64: await this.serializeDirectSealedSenderMessage(msg, ciphertextBase64, messageType, recipientRegistrationId, sealedSender),
|
|
1596
|
+
sentMessageBase64: await this.serializeDirectSealedSenderMessage(msg, ciphertextBase64, messageType, recipientRegistrationId, sealedSender, contentHint),
|
|
1437
1597
|
auth: sealedSender.auth,
|
|
1438
1598
|
deliveryMode: sealedSender.config.deliveryMode === 'required' ? 'required' : 'preferred',
|
|
1439
1599
|
}
|
|
1440
1600
|
: undefined);
|
|
1441
1601
|
if (!prepared)
|
|
1442
1602
|
throw new Error('Missing sealed-sender delivery state');
|
|
1443
|
-
identifiedControl = {
|
|
1603
|
+
identifiedControl = {
|
|
1604
|
+
...(control.stopSignal && { stopSignal: control.stopSignal }),
|
|
1605
|
+
...(control.operationEpochMilliseconds !== undefined && {
|
|
1606
|
+
operationEpochMilliseconds: control.operationEpochMilliseconds,
|
|
1607
|
+
}),
|
|
1608
|
+
};
|
|
1444
1609
|
try {
|
|
1445
|
-
const result = await this.postToRelay(() => this.relay.sendMultiRecipientUnidentified(prepared.sentMessageBase64, prepared.auth, msg.timestamp, 'user-visible', [msg.recipientUserId], effectiveClientMessageId
|
|
1610
|
+
const result = await this.postToRelay(() => this.relay.sendMultiRecipientUnidentified(prepared.sentMessageBase64, prepared.auth, msg.timestamp, 'user-visible', [msg.recipientUserId], effectiveClientMessageId, ...(control.operationEpochMilliseconds === undefined
|
|
1611
|
+
? []
|
|
1612
|
+
: [control.operationEpochMilliseconds])), true, control);
|
|
1446
1613
|
if (result.uuids404.length > 0) {
|
|
1447
1614
|
throw new SealedSenderRecipientRejectedError();
|
|
1448
1615
|
}
|
|
@@ -1521,6 +1688,9 @@ export class SignalProtocolServiceCipher {
|
|
|
1521
1688
|
messageType,
|
|
1522
1689
|
deliveryClass: 'user-visible',
|
|
1523
1690
|
timestamp: msg.timestamp,
|
|
1691
|
+
...(identifiedControl.operationEpochMilliseconds !== undefined && {
|
|
1692
|
+
operationEpochMilliseconds: identifiedControl.operationEpochMilliseconds,
|
|
1693
|
+
}),
|
|
1524
1694
|
clientMessageId: effectiveClientMessageId,
|
|
1525
1695
|
recipientRegistrationId,
|
|
1526
1696
|
contentHint,
|
|
@@ -1602,7 +1772,7 @@ export class SignalProtocolServiceCipher {
|
|
|
1602
1772
|
});
|
|
1603
1773
|
const stored = [];
|
|
1604
1774
|
for (const message of batch.deviceMessages) {
|
|
1605
|
-
stored.push(await this.prepareStoredDirectDeviceMessage(message, null));
|
|
1775
|
+
stored.push(await this.prepareStoredDirectDeviceMessage(message, null, undefined));
|
|
1606
1776
|
}
|
|
1607
1777
|
return stored;
|
|
1608
1778
|
}, stopSignal)
|