@open-e2ee/signal-protocol-sdk 9.4.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 +176 -0
- package/README.md +1 -1
- package/SECURITY.md +2 -2
- package/dist/client/client.d.ts +61 -62
- package/dist/client/client.d.ts.map +1 -1
- package/dist/client/client.js +127 -169
- package/dist/client/client.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/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 +3 -3
- package/dist/client/hosted-anonymous-delivery.js.map +1 -1
- package/dist/client/hosted-transport.d.ts +1 -1
- 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/relay-acceptance.d.ts +8 -0
- package/dist/client/relay-acceptance.d.ts.map +1 -1
- package/dist/client/relay-acceptance.js +7 -0
- package/dist/client/relay-acceptance.js.map +1 -1
- package/dist/client/relay-subscription.d.ts +12 -0
- package/dist/client/relay-subscription.d.ts.map +1 -1
- package/dist/client/relay-subscription.js +226 -80
- package/dist/client/relay-subscription.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 +63 -22
- package/dist/client/retry.d.ts.map +1 -1
- package/dist/client/retry.js +234 -136
- 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 +184 -16
- package/dist/client/signal-service-cipher.js.map +1 -1
- package/dist/client/state.d.ts +7 -60
- package/dist/client/state.d.ts.map +1 -1
- package/dist/client/state.js +8 -86
- package/dist/client/state.js.map +1 -1
- package/dist/client/types.d.ts +10 -2
- package/dist/client/types.d.ts.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 +258 -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 +22 -29
- package/dist/remote/relay/types.d.ts.map +1 -1
- package/dist/types/api.d.ts +43 -22
- 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
package/dist/client/retry.d.ts
CHANGED
|
@@ -7,18 +7,16 @@
|
|
|
7
7
|
import type { PreKeyBundle } from '../keys/index.js';
|
|
8
8
|
import { ContentHint } from '../types/messages.js';
|
|
9
9
|
import { ProtocolAddress } from '../types/address.js';
|
|
10
|
-
import type {
|
|
10
|
+
import type { RetryFamilyReceive } from './retry-family.js';
|
|
11
|
+
import type { SignalProtocolClientContext, IncomingEnvelope, ProcessEnvelopeOptions } from './types.js';
|
|
11
12
|
import { type SesameManager, type RetryRequest } from '../internal/sesame/types.js';
|
|
13
|
+
import { type RetryResendTarget } from '../local/store/reliability.js';
|
|
12
14
|
/**
|
|
13
|
-
*
|
|
15
|
+
* Retry response state (passed by client, mutated in place)
|
|
14
16
|
*/
|
|
15
17
|
export {};
|
|
16
|
-
export interface
|
|
17
|
-
/**
|
|
18
|
-
recentRetryRequests: Map<string, number>;
|
|
19
|
-
/** Timestamp of last cleanup */
|
|
20
|
-
lastRetryCleanupTime: number;
|
|
21
|
-
/** Tracks retry response counts per message: key = dedupKey, value = response count */
|
|
18
|
+
export interface RetryResponseState {
|
|
19
|
+
/** Retry responses per message: key = `${sessionId}:${failedTimestamp}`, value = response count */
|
|
22
20
|
retryResponseCounts: Map<string, number>;
|
|
23
21
|
}
|
|
24
22
|
/**
|
|
@@ -27,6 +25,11 @@ export interface RetryDedupState {
|
|
|
27
25
|
export interface RetryContext extends SignalProtocolClientContext {
|
|
28
26
|
sesameManager: SesameManager;
|
|
29
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* The request attempt that a retry request envelope is: the failed envelope,
|
|
30
|
+
* the retry ID of its request record and the ID of the request envelope.
|
|
31
|
+
*/
|
|
32
|
+
export type RetryRequestAttempt = Omit<RetryResendTarget, 'kind'>;
|
|
30
33
|
/**
|
|
31
34
|
* Callbacks for operations that need to delegate back to SignalProtocolClient
|
|
32
35
|
*/
|
|
@@ -35,11 +38,25 @@ export interface RetryCallbacks {
|
|
|
35
38
|
archiveSession: (address: ProtocolAddress) => Promise<void>;
|
|
36
39
|
/** Establish a new session with prekey bundle */
|
|
37
40
|
establishSession: (address: ProtocolAddress, bundle: PreKeyBundle) => Promise<void>;
|
|
38
|
-
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Encrypt content for one device of a user and post it to that device
|
|
43
|
+
* only. The send makes no sent-sync transcript. With a retry target, the
|
|
44
|
+
* sender keeps one resend record for the device and the failed envelope.
|
|
45
|
+
* A call for the request attempt and the kind of that record posts its
|
|
46
|
+
* stored bytes again under their own ID. A call for another request
|
|
47
|
+
* attempt or kind encrypts again, and the resend takes the attempt
|
|
48
|
+
* number of the request. A new encryption for the same request attempt,
|
|
49
|
+
* as after the Relay refuses the stored bytes as expired, posts the same
|
|
50
|
+
* ID: the processed ledger of the requester and the RETRY_CONFLICT
|
|
51
|
+
* answer of the Relay cover the new bytes. Null content posts only a
|
|
52
|
+
* stored attempt. It returns false only when null content has no stored
|
|
53
|
+
* attempt to post.
|
|
54
|
+
*/
|
|
55
|
+
resend: (userId: string, deviceId: number, content: string | null, options: {
|
|
56
|
+
timestamp: number;
|
|
41
57
|
contentHint?: ContentHint;
|
|
42
|
-
|
|
58
|
+
retry?: RetryResendTarget;
|
|
59
|
+
}) => Promise<boolean>;
|
|
43
60
|
/** Generate replacement prekeys and upload their public material. */
|
|
44
61
|
forcePreKeyRotation: () => Promise<void>;
|
|
45
62
|
}
|
|
@@ -49,10 +66,6 @@ export interface RetryCallbacks {
|
|
|
49
66
|
export interface RetryConfig {
|
|
50
67
|
/** Debounce interval for forced prekey rotations in ms */
|
|
51
68
|
keyRotationDebounceMs: number;
|
|
52
|
-
/** Deduplication window for retry requests in ms */
|
|
53
|
-
retryDedupWindowMs: number;
|
|
54
|
-
/** Cleanup interval for retry dedup entries in ms */
|
|
55
|
-
retryCleanupIntervalMs: number;
|
|
56
69
|
}
|
|
57
70
|
export declare const MAX_RETRY_REQUESTS_PER_SENDER = 10;
|
|
58
71
|
export declare const RETRY_REQUEST_WINDOW_MS: number;
|
|
@@ -78,7 +91,6 @@ export interface RetryRateLimitState {
|
|
|
78
91
|
export declare function checkRetryRateLimit(rateLimitState: RetryRateLimitState, senderId: string, now?: number): boolean;
|
|
79
92
|
/**
|
|
80
93
|
* Default configuration values
|
|
81
|
-
* Imports common values from state.ts to avoid duplication
|
|
82
94
|
*/
|
|
83
95
|
export declare const DEFAULT_RETRY_CONFIG: RetryConfig;
|
|
84
96
|
/**
|
|
@@ -88,8 +100,17 @@ export declare function getSessionKey(userId: string, deviceId: number): string;
|
|
|
88
100
|
/**
|
|
89
101
|
* Send retry request for failed decryption (internal)
|
|
90
102
|
*
|
|
91
|
-
*
|
|
103
|
+
* Sends a `retry_request` envelope to the failed sender device through the
|
|
104
|
+
* relay. Without a relay, it gives the envelope to the options callback.
|
|
92
105
|
* Handles IMPLICIT content type discarding, rate limiting, and stale prekey rotation.
|
|
106
|
+
* An envelope without an identified sender, or from the local device, gets
|
|
107
|
+
* one warn line and no request. The request is stored under the failed
|
|
108
|
+
* envelope ID before its post, and a later failure of the same envelope posts
|
|
109
|
+
* the stored request again. The rate limit counts each post. A failed resend
|
|
110
|
+
* or null message asks again for its failed envelope through the retry
|
|
111
|
+
* family, whatever its content hint. A member that fails with an error that
|
|
112
|
+
* is not retryable posts nothing here, and its redelivery on the pull path
|
|
113
|
+
* asks again.
|
|
93
114
|
*
|
|
94
115
|
* @param ctx - Retry context with dependencies
|
|
95
116
|
* @param envelope - The failed message envelope
|
|
@@ -97,14 +118,19 @@ export declare function getSessionKey(userId: string, deviceId: number): string;
|
|
|
97
118
|
* @param rateLimitState - State for rate limiting (mutated in place)
|
|
98
119
|
* @param callbacks - Callbacks for operations needing SignalProtocolClient
|
|
99
120
|
* @param config - Configuration constants
|
|
121
|
+
* @param family - The retry family of the envelope
|
|
122
|
+
* @param fingerprint - The fingerprint of the envelope as the Relay delivered
|
|
123
|
+
* it, before any unseal. The stored request binds to it.
|
|
100
124
|
* @param options - Optional transport callbacks (for background without relay)
|
|
101
125
|
*/
|
|
102
|
-
export declare function sendRetryRequestInternal(ctx: RetryContext, envelope: IncomingEnvelope, error: Error, rateLimitState: RetryRateLimitState, callbacks: Pick<RetryCallbacks, 'forcePreKeyRotation'>, config: RetryConfig, options?: ProcessEnvelopeOptions): Promise<void>;
|
|
126
|
+
export declare function sendRetryRequestInternal(ctx: RetryContext, envelope: IncomingEnvelope, error: Error, rateLimitState: RetryRateLimitState, callbacks: Pick<RetryCallbacks, 'forcePreKeyRotation'>, config: RetryConfig, family: RetryFamilyReceive, fingerprint: string | undefined, options?: ProcessEnvelopeOptions): Promise<void>;
|
|
103
127
|
/**
|
|
104
128
|
* Handle incoming retry request and resend the original message
|
|
105
129
|
*
|
|
106
130
|
* Per SESAME spec §4.1, this method:
|
|
107
|
-
* 1. Looks up the MessageRecord for the failed sequence number
|
|
131
|
+
* 1. Looks up the MessageRecord for the failed sequence number. When the
|
|
132
|
+
* sender already stored a resend or a null message for this request
|
|
133
|
+
* envelope, it posts the stored bytes again and does no session work
|
|
108
134
|
* 2. Verifies the requester is the intended recipient
|
|
109
135
|
* 3. Checks retry limits and TTL
|
|
110
136
|
* 4. Creates new session if orphaned, or uses existing different session
|
|
@@ -112,11 +138,26 @@ export declare function sendRetryRequestInternal(ctx: RetryContext, envelope: In
|
|
|
112
138
|
* MessageRecord with the record of the new encryption. Only a delivery
|
|
113
139
|
* receipt from the device or the TTL deletes that record.
|
|
114
140
|
*
|
|
141
|
+
* It refuses a request for a message sent more than
|
|
142
|
+
* `RELIABILITY_RECORD_TTL_MS` ago, before it reads a stored resend. The
|
|
143
|
+
* Relay can keep the last resend post for that time again, and the
|
|
144
|
+
* requester keeps its retry records for both periods.
|
|
145
|
+
*
|
|
146
|
+
* It returns normally when it resends the message or refuses the request.
|
|
147
|
+
* It throws every other error, so the caller keeps the request envelope and
|
|
148
|
+
* a later pull gives it again.
|
|
149
|
+
*
|
|
115
150
|
* @param ctx - Retry context with dependencies
|
|
116
151
|
* @param retryRequest - The retry request from the recipient
|
|
117
|
-
* @param
|
|
152
|
+
* @param responseState - Retry response counts (mutated in place)
|
|
118
153
|
* @param callbacks - Callbacks for SignalProtocolClient operations
|
|
119
154
|
* @param config - Configuration constants
|
|
155
|
+
* @param retry - The ID of the envelope that the requester could not
|
|
156
|
+
* decrypt and the retry ID of its request record, from the request, and
|
|
157
|
+
* the ID of the request envelope. Each request attempt gets one
|
|
158
|
+
* encryption. The content resend has the ID `<retryId>:resend`, and the
|
|
159
|
+
* null message has the ID `<retryId>:null`. Attempt n of either adds
|
|
160
|
+
* `:<n>` from attempt 2.
|
|
120
161
|
*/
|
|
121
|
-
export declare function handleRetryRequestAndResend(ctx: RetryContext, retryRequest: RetryRequest,
|
|
162
|
+
export declare function handleRetryRequestAndResend(ctx: RetryContext, retryRequest: RetryRequest, responseState: RetryResponseState, callbacks: RetryCallbacks, config: RetryConfig, retry?: RetryRequestAttempt): Promise<void>;
|
|
122
163
|
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../client/retry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGnD,OAAO,KAAK,EACV,2BAA2B,EAC3B,gBAAgB,EAChB,sBAAsB,
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../client/retry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGnD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EACV,2BAA2B,EAC3B,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,SAAS,CAAC;AACjB,OAAO,EAGL,KAAK,aAAa,EAElB,KAAK,YAAY,EAClB,MAAM,0BAA0B,CAAC;AAUlC,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,4BAA4B,CAAC;AAEpC;;GAEG;AACH,OAAO,EAAE,CAAC;AACV,MAAM,WAAW,kBAAkB;IACjC,mGAA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