@open-e2ee/signal-protocol-sdk 4.0.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/README.md +2 -2
  3. package/SECURITY.md +2 -2
  4. package/client/README.md +3 -3
  5. package/dist/client/client.d.ts +9 -20
  6. package/dist/client/client.d.ts.map +1 -1
  7. package/dist/client/client.js +9 -22
  8. package/dist/client/client.js.map +1 -1
  9. package/dist/client/config.d.ts +25 -25
  10. package/dist/client/headless.d.ts +9 -20
  11. package/dist/client/headless.d.ts.map +1 -1
  12. package/dist/client/headless.js +22 -67
  13. package/dist/client/headless.js.map +1 -1
  14. package/dist/client/hosted-anonymous-delivery.d.ts.map +1 -1
  15. package/dist/client/hosted-anonymous-delivery.js +15 -2
  16. package/dist/client/hosted-anonymous-delivery.js.map +1 -1
  17. package/dist/client/hosted-mailbox-subscription.d.ts.map +1 -1
  18. package/dist/client/hosted-mailbox-subscription.js +32 -0
  19. package/dist/client/hosted-mailbox-subscription.js.map +1 -1
  20. package/dist/client/hosted-transport.d.ts +14 -7
  21. package/dist/client/hosted-transport.d.ts.map +1 -1
  22. package/dist/client/hosted-transport.js +81 -60
  23. package/dist/client/hosted-transport.js.map +1 -1
  24. package/dist/client/key-rotation-core.d.ts +46 -69
  25. package/dist/client/key-rotation-core.d.ts.map +1 -1
  26. package/dist/client/key-rotation-core.js +161 -256
  27. package/dist/client/key-rotation-core.js.map +1 -1
  28. package/dist/client/key-rotation.d.ts +14 -29
  29. package/dist/client/key-rotation.d.ts.map +1 -1
  30. package/dist/client/key-rotation.js +37 -61
  31. package/dist/client/key-rotation.js.map +1 -1
  32. package/dist/client/one-time-prekey-refill.d.ts +52 -0
  33. package/dist/client/one-time-prekey-refill.d.ts.map +1 -0
  34. package/dist/client/one-time-prekey-refill.js +79 -0
  35. package/dist/client/one-time-prekey-refill.js.map +1 -0
  36. package/dist/client/prekeys.d.ts.map +1 -1
  37. package/dist/client/prekeys.js +38 -73
  38. package/dist/client/prekeys.js.map +1 -1
  39. package/dist/client/signal-service-cipher.d.ts +1 -1
  40. package/dist/client/signal-service-cipher.js +2 -2
  41. package/dist/client/signal-service-cipher.js.map +1 -1
  42. package/dist/client/types.d.ts +1 -1
  43. package/dist/device/lifecycle/manager.d.ts.map +1 -1
  44. package/dist/device/lifecycle/manager.js +0 -3
  45. package/dist/device/lifecycle/manager.js.map +1 -1
  46. package/dist/device/lifecycle/types.d.ts +1 -9
  47. package/dist/device/lifecycle/types.d.ts.map +1 -1
  48. package/dist/device/lifecycle/utils.d.ts +2 -4
  49. package/dist/device/lifecycle/utils.d.ts.map +1 -1
  50. package/dist/device/lifecycle/utils.js +2 -4
  51. package/dist/device/lifecycle/utils.js.map +1 -1
  52. package/dist/hooks/index.d.ts +1 -2
  53. package/dist/hooks/index.d.ts.map +1 -1
  54. package/dist/hooks/index.js +0 -1
  55. package/dist/hooks/index.js.map +1 -1
  56. package/dist/hooks/use-key-rotation.d.ts +2 -5
  57. package/dist/hooks/use-key-rotation.d.ts.map +1 -1
  58. package/dist/hooks/use-key-rotation.js +8 -5
  59. package/dist/hooks/use-key-rotation.js.map +1 -1
  60. package/dist/hooks/use-single-flight.d.ts +4 -4
  61. package/dist/hooks/use-single-flight.js +4 -4
  62. package/dist/index.d.ts +2 -2
  63. package/dist/index.d.ts.map +1 -1
  64. package/dist/index.js.map +1 -1
  65. package/dist/internal/manager/manager.d.ts +4 -4
  66. package/dist/internal/manager/manager.js +4 -4
  67. package/dist/local/store/expo/models/ec-one-time-prekey.d.ts.map +1 -1
  68. package/dist/local/store/expo/models/ec-one-time-prekey.js +4 -6
  69. package/dist/local/store/expo/models/ec-one-time-prekey.js.map +1 -1
  70. package/dist/local/store/expo/models/kyber-one-time-prekey.d.ts.map +1 -1
  71. package/dist/local/store/expo/models/kyber-one-time-prekey.js +4 -8
  72. package/dist/local/store/expo/models/kyber-one-time-prekey.js.map +1 -1
  73. package/dist/remote/relay/memory/adapter.d.ts +2 -14
  74. package/dist/remote/relay/memory/adapter.d.ts.map +1 -1
  75. package/dist/remote/relay/memory/adapter.js +5 -58
  76. package/dist/remote/relay/memory/adapter.js.map +1 -1
  77. package/dist/remote/relay/types.d.ts +20 -64
  78. package/dist/remote/relay/types.d.ts.map +1 -1
  79. package/dist/safety/index.d.ts +2 -2
  80. package/dist/safety/index.js +2 -2
  81. package/dist/types/api.d.ts +25 -13
  82. package/dist/types/api.d.ts.map +1 -1
  83. package/docs/ASSURANCE.md +4 -4
  84. package/docs/ERROR_HANDLING.md +2 -2
  85. package/docs/PACKAGE_SURFACE.md +1 -2
  86. package/examples/browser/index.html +1 -1
  87. package/hooks/README.md +4 -14
  88. package/package.json +1 -5
  89. package/dist/hooks/use-connection-presence.d.ts +0 -66
  90. package/dist/hooks/use-connection-presence.d.ts.map +0 -1
  91. package/dist/hooks/use-connection-presence.js +0 -298
  92. package/dist/hooks/use-connection-presence.js.map +0 -1
@@ -1,40 +1,39 @@
1
1
  /**
2
2
  * Key Rotation Core
3
3
  *
4
- * Shared rotation logic that works with SignalProtocolRelayServer interface.
5
- * Used by both:
4
+ * Shared rotation logic that works with the SignalProtocolRelayServer
5
+ * interface. Used by both:
6
6
  * - SignalProtocolClient (foreground, via key-rotation.ts)
7
7
  * - Background tasks (headless, via headless.ts)
8
8
  *
9
- * This module handles the actual key generation and upload logic,
10
- * independent of React context or specific backend implementation.
9
+ * One rotation reads the inventory once, decides which of the EC signed
10
+ * prekey, the KEM last-resort prekey, and the one-time prekey batches are due,
11
+ * and publishes every due key in one publication. A rotation with nothing due
12
+ * costs one inventory read and no publication.
11
13
  *
12
14
  * ## Thread Safety
13
15
  *
14
- * Uses per-key-type AsyncLock to prevent race conditions when multiple
15
- * callers attempt key rotation concurrently. This protects against:
16
- * - Multiple React components calling rotation simultaneously
17
- * - Background tasks racing with foreground rotation
18
- * - Network requests completing out of order
19
- *
20
- * The lock wraps the entire check → generate → upload → store sequence
21
- * to make key rotation atomic.
16
+ * A per-identity AsyncLock serializes concurrent rotations for one device, so
17
+ * two callers cannot both generate and publish different keys. The lock wraps
18
+ * the whole read → decide → generate → publish → store sequence.
22
19
  *
23
20
  * ## Transactional Pattern
24
21
  *
25
- * Key rotation uses upload-first ordering for consistency:
26
- * 1. Check if rotation needed (metadata from server)
27
- * 2. Generate new key locally
28
- * 3. Upload to server (may fail - local state unchanged)
29
- * 4. Store locally only after successful upload
22
+ * Signed keys use publish-first ordering:
23
+ * 1. Read the inventory (through the relay adapter's publication fence)
24
+ * 2. Generate the due keys locally
25
+ * 3. Publish (may fail - the signed keys are not stored)
26
+ * 4. Store the signed keys locally only after the publication succeeds
30
27
  *
31
- * This keeps client and server in sync. If upload fails, local state does not
32
- * change, and the caller can safely retry rotation.
28
+ * One-time prekeys are stored before the publication, because their private
29
+ * halves must exist before a peer can consume the public halves.
33
30
  */
34
31
  import AsyncLock from 'async-lock';
35
32
  import { defaultSignalProtocolLogger } from '../logger.js';
36
- import { ONE_TIME_PREKEY_BATCH_SIZE } from '../types/index.js';
37
- import { KEY_REFRESH_INTERVAL_MS_DEFAULT, MAX_PREKEY_AGE_MS_DEFAULT, } from './config.js';
33
+ import { generateEcSignedPreKey, generateKyberLastResortPreKey } from '../keys/index.js';
34
+ import { getErrorMessage } from '../utils/errors.js';
35
+ import { getActiveIdentityTypes, KEY_REFRESH_INTERVAL_MS_DEFAULT, MAX_PREKEY_AGE_MS_DEFAULT, } from './config.js';
36
+ import { MIN_PREKEY_REPLENISHMENT_THRESHOLD, refillOneTimePreKeys, } from './one-time-prekey-refill.js';
38
37
  const rotationLock = new AsyncLock({
39
38
  timeout: 60000, // 60 second timeout for entire rotation operation
40
39
  maxPending: 10, // Limit queued rotation requests
@@ -66,21 +65,23 @@ async function getRequiredIdentityKey(storage, identityType = 'aci') {
66
65
  return identityKey;
67
66
  }
68
67
  /**
69
- * Execute a rotation operation with locking and error handling
68
+ * Run one rotation step under the per-identity lock. A thrown error is logged
69
+ * and returned as a message, so one failed identity type does not stop the
70
+ * others.
70
71
  */
71
- async function withRotationLock(userId, deviceId, keyType, operation, errorMessage, logger) {
72
- const lockKey = `${userId}:${deviceId}:${keyType}`;
72
+ async function withRotationLock(userId, deviceId, identityType, operation, errorMessage, logger) {
73
+ const lockKey = `${userId}:${deviceId}:rotation:${identityType}`;
73
74
  return rotationLock.acquire(lockKey, async () => {
74
75
  try {
75
- return await operation();
76
+ return { ok: true, value: await operation() };
76
77
  }
77
78
  catch (error) {
78
79
  logger.error(errorMessage, {
79
80
  category: 'E2EE',
80
81
  error: error,
81
- data: { userId, deviceId },
82
+ data: { userId, deviceId, identityType },
82
83
  });
83
- return false;
84
+ return { ok: false, error: getErrorMessage(error) };
84
85
  }
85
86
  });
86
87
  }
@@ -102,12 +103,7 @@ function checkRotationNeeded(metadata, refreshIntervalMs, keyTypeName, logger) {
102
103
  // ============================================================================
103
104
  // EXPORTS
104
105
  // ============================================================================
105
- /**
106
- * Minimum one-time prekeys before replenishment starts.
107
- * When the count drops below this threshold, the client generates and uploads
108
- * new prekeys.
109
- */
110
- export const MIN_PREKEY_REPLENISHMENT_THRESHOLD = 10;
106
+ export { MIN_PREKEY_REPLENISHMENT_THRESHOLD } from './one-time-prekey-refill.js';
111
107
  /**
112
108
  * Check if a key needs rotation based on age
113
109
  *
@@ -146,76 +142,6 @@ export function isPreKeyExpired(createdAt, maxAgeMs = MAX_PREKEY_AGE_MS_DEFAULT)
146
142
  const age = Date.now() - createdAt;
147
143
  return age >= maxAgeMs;
148
144
  }
149
- /**
150
- * Core signed prekey rotation
151
- *
152
- * Generates a new signed prekey and uploads to server.
153
- * Works without React context.
154
- *
155
- * @param relay - Signal Protocol relay server interface
156
- * @param userId - User identifier
157
- * @param deviceId - Device identifier
158
- * @param providedStorage - Local store instance for the current runtime
159
- * @param refreshIntervalMs - Custom refresh interval (defaults to 2 days)
160
- * @returns true if the function rotated the key
161
- */
162
- export async function rotateEcSignedPreKeyCore(relay, userId, deviceId, providedStorage, refreshIntervalMs = KEY_REFRESH_INTERVAL_MS_DEFAULT, identityTypes = ['aci', 'pni'], logger = defaultSignalProtocolLogger) {
163
- // Rotate for active identity types. The reference implementation rotates PNI
164
- // on the same schedule as ACI.
165
- // Use && so the function only returns true when ALL identities succeed.
166
- // The reference implementation uses exception propagation. If any identity fails, the entire job
167
- // fails, and the next rotation cycle retries it.
168
- let allRotated = true;
169
- for (const type of identityTypes) {
170
- const rotated = await rotateEcSignedPreKeyForIdentity(relay, userId, deviceId, type, providedStorage, refreshIntervalMs, logger);
171
- allRotated = allRotated && rotated;
172
- }
173
- return allRotated;
174
- }
175
- /**
176
- * Rotate signed prekey for a specific identity type.
177
- *
178
- * @param relay - Signal Protocol relay server interface
179
- * @param userId - User identifier
180
- * @param deviceId - Device identifier
181
- * @param identityType - 'aci' or 'pni'
182
- * @param providedStorage - Optional storage instance
183
- * @param refreshIntervalMs - Custom refresh interval
184
- * @returns true if the function rotated the key
185
- */
186
- async function rotateEcSignedPreKeyForIdentity(relay, userId, deviceId, identityType, providedStorage, refreshIntervalMs = KEY_REFRESH_INTERVAL_MS_DEFAULT, logger = defaultSignalProtocolLogger) {
187
- return withRotationLock(userId, deviceId, `signed:${identityType}`, async () => {
188
- // Check whether this identity type needs rotation
189
- const metadata = await relay.getEcSignedPreKeyMetadata(userId, deviceId, identityType);
190
- if (!checkRotationNeeded(metadata, refreshIntervalMs, `EC signed prekey (${identityType})`, logger)) {
191
- return false;
192
- }
193
- logger.info(`Rotating EC signed prekey (${identityType})`, {
194
- category: 'E2EE',
195
- data: { userId, deviceId, identityType },
196
- });
197
- const { generateEcSignedPreKey } = await import('../keys/index.js');
198
- const storage = await resolveStorage(providedStorage, logger);
199
- const identityKey = await getRequiredIdentityKey(storage, identityType);
200
- // Generate new EC signed prekey (but do not store yet)
201
- const newSignedPreKey = await generateEcSignedPreKey(identityKey);
202
- // TRANSACTIONAL PATTERN: Upload first, then commit locally
203
- // If upload fails, local state does not change, so a retry is safe.
204
- await relay.uploadEcSignedPreKey(userId, {
205
- keyId: newSignedPreKey.keyId,
206
- deviceId,
207
- publicKey: newSignedPreKey.publicKey,
208
- signature: newSignedPreKey.signature,
209
- timestamp: newSignedPreKey.timestamp,
210
- }, identityType);
211
- await storage.storeEcSignedPreKey(newSignedPreKey, identityType);
212
- logger.info(`EC signed prekey rotated successfully (${identityType})`, {
213
- category: 'E2EE',
214
- data: { userId, deviceId, identityType },
215
- });
216
- return true;
217
- }, `Failed to rotate EC signed prekey (${identityType})`, logger);
218
- }
219
145
  /**
220
146
  * The key id for the next Kyber last-resort prekey of one identity type.
221
147
  *
@@ -227,148 +153,141 @@ export async function nextKyberLastResortPreKeyId(storage, identityType) {
227
153
  const current = await storage.getKyberPreKey(identityType);
228
154
  return (current?.keyId ?? 0) + 1;
229
155
  }
230
- /**
231
- * Core post-quantum KEM prekey rotation.
232
- *
233
- * Generates fresh ML-KEM/Kyber-compatible key material and uploads it to the
234
- * relay.
235
- * Works without React context.
236
- *
237
- * @param relay - Signal Protocol relay server interface
238
- * @param userId - User identifier
239
- * @param deviceId - Device identifier
240
- * @param providedStorage - Local store instance for the current runtime
241
- * @param refreshIntervalMs - Custom refresh interval (defaults to 2 days)
242
- * @returns true if the function rotated the key
243
- */
244
- export async function rotateKyberPreKeyCore(relay, userId, deviceId, providedStorage, refreshIntervalMs = KEY_REFRESH_INTERVAL_MS_DEFAULT, identityTypes = ['aci', 'pni'], logger = defaultSignalProtocolLogger) {
245
- // Rotate for active identity types. The reference implementation rotates PNI
246
- // on the same schedule as ACI.
247
- // Use && so the function only returns true when ALL identities succeed.
248
- // The reference implementation uses exception propagation. If any identity fails, the entire job
249
- // fails, and the next rotation cycle retries it.
250
- let allRotated = true;
251
- for (const type of identityTypes) {
252
- const rotated = await rotateKyberPreKeyForIdentity(relay, userId, deviceId, type, providedStorage, refreshIntervalMs, logger);
253
- allRotated = allRotated && rotated;
254
- }
255
- return allRotated;
156
+ /** Whether one inventory calls for a refill of either one-time prekey set. */
157
+ export function oneTimePreKeysDue(inventory, threshold) {
158
+ return inventory.ecOneTimePreKeyCount < threshold || inventory.kemOneTimePreKeyCount < threshold;
256
159
  }
257
160
  /**
258
- * Rotate Kyber prekey for a specific identity type.
161
+ * Rotate the prekeys of one device: one inventory read and one publication
162
+ * per identity type.
259
163
  *
260
- * @param relay - Signal Protocol relay server interface
261
- * @param userId - User identifier
262
- * @param deviceId - Device identifier
263
- * @param identityType - 'aci' or 'pni'
264
- * @param providedStorage - Optional storage instance
265
- * @param refreshIntervalMs - Custom refresh interval
266
- * @returns true if the function rotated the key
267
- */
268
- async function rotateKyberPreKeyForIdentity(relay, userId, deviceId, identityType, providedStorage, refreshIntervalMs = KEY_REFRESH_INTERVAL_MS_DEFAULT, logger = defaultSignalProtocolLogger) {
269
- return withRotationLock(userId, deviceId, `kyber:${identityType}`, async () => {
270
- // Check whether this identity type needs rotation
271
- const metadata = await relay.getKemLastResortPreKeyMetadata(userId, deviceId, identityType);
272
- if (!checkRotationNeeded(metadata, refreshIntervalMs, `Kyber prekey (${identityType})`, logger)) {
273
- return false;
274
- }
275
- logger.info(`Rotating Kyber prekey for post-quantum security (${identityType})`, {
276
- category: 'E2EE',
277
- data: { userId, deviceId, identityType },
278
- });
279
- const storage = await resolveStorage(providedStorage, logger);
280
- const identityKey = await getRequiredIdentityKey(storage, identityType);
281
- const { generateKyberLastResortPreKey } = await import('../keys/generation.js');
282
- const kyberPreKey = await generateKyberLastResortPreKey(identityKey, await nextKyberLastResortPreKeyId(storage, identityType));
283
- // TRANSACTIONAL PATTERN: Upload first, then commit locally
284
- // If upload fails, local state does not change, so a retry is safe.
285
- const publicKyberPreKey = {
286
- keyId: kyberPreKey.keyId,
287
- publicKey: kyberPreKey.publicKey,
288
- signature: kyberPreKey.signature,
289
- timestamp: kyberPreKey.timestamp,
290
- };
291
- await relay.uploadKemLastResortPreKey(userId, { ...publicKyberPreKey, deviceId }, identityType);
292
- await storage.storeKyberPreKey({
293
- ...kyberPreKey,
294
- publicKey: kyberPreKey.publicKey,
295
- privateKey: kyberPreKey.privateKey,
296
- signature: kyberPreKey.signature,
297
- }, identityType);
298
- logger.info(`Kyber prekey rotated successfully (${identityType}, PQXDH security maintained)`, {
299
- category: 'E2EE',
300
- data: { userId, deviceId, identityType },
301
- });
302
- return true;
303
- }, `Failed to rotate Kyber prekey (${identityType})`, logger);
304
- }
305
- /**
306
- * Check and replenish one-time prekeys if running low
164
+ * Per PQXDH spec Section 3.2, the EC signed prekey and the KEM last-resort
165
+ * prekey rotate on the same schedule. The one-time prekey batches refill in
166
+ * the same publication when a server count is below the threshold. Nothing
167
+ * due costs one inventory read.
307
168
  *
308
- * Iterates both ACI and PNI identity types for consistency with
309
- * rotateEcSignedPreKeyCore and rotateKyberPreKeyCore.
169
+ * A failed identity type is reported in `errors` and does not stop the other
170
+ * identity types. The result booleans are true when any identity type rotated
171
+ * that key.
310
172
  *
311
- * @param relay - Signal Protocol relay server interface
312
- * @param userId - User identifier
313
- * @param deviceId - Device identifier
314
- * @param storage - Key storage for local persistence
315
- * @param threshold - Minimum number of prekeys before replenishment (default: 10)
316
- * @returns true if the function replenished both identity types
173
+ * @see https://signal.org/docs/specifications/pqxdh/#publishing-keys
317
174
  */
318
- export async function replenishOneTimePreKeysCore(relay, userId, deviceId, storage, threshold = MIN_PREKEY_REPLENISHMENT_THRESHOLD, identityTypes = ['aci', 'pni'], preKeyMaintenance, logger = defaultSignalProtocolLogger) {
319
- // Replenish for active identity types (consistent with rotateEcSignedPreKeyCore/rotateKyberPreKeyCore)
320
- let allReplenished = true;
321
- for (const type of identityTypes) {
322
- const replenished = await replenishOneTimePreKeysForIdentity(relay, userId, deviceId, storage, threshold, type, preKeyMaintenance, logger);
323
- allReplenished = allReplenished && replenished;
175
+ export async function rotatePreKeysCore(relay, userId, deviceId, providedStorage, options = {}) {
176
+ const { refreshIntervalMs = KEY_REFRESH_INTERVAL_MS_DEFAULT, threshold = MIN_PREKEY_REPLENISHMENT_THRESHOLD, identityTypes = getActiveIdentityTypes(), preKeyMaintenance, logger = defaultSignalProtocolLogger, } = options;
177
+ const result = {
178
+ signedRotated: false,
179
+ kyberRotated: false,
180
+ oneTimeReplenished: false,
181
+ errors: [],
182
+ };
183
+ const storage = await resolveStorage(providedStorage, logger);
184
+ for (const identityType of identityTypes) {
185
+ const outcome = await withRotationLock(userId, deviceId, identityType, () => rotatePreKeysForIdentity(relay, userId, deviceId, storage, identityType, {
186
+ refreshIntervalMs,
187
+ threshold,
188
+ preKeyMaintenance,
189
+ logger,
190
+ }), `Failed to rotate prekeys (${identityType})`, logger);
191
+ if (!outcome.ok) {
192
+ result.errors.push(`${identityType}: ${outcome.error}`);
193
+ continue;
194
+ }
195
+ result.signedRotated = result.signedRotated || outcome.value.signed !== null;
196
+ result.kyberRotated = result.kyberRotated || outcome.value.kyber !== null;
197
+ result.oneTimeReplenished = result.oneTimeReplenished || outcome.value.refill !== null;
324
198
  }
325
- return allReplenished;
199
+ return result;
326
200
  }
327
201
  /**
328
- * Replenish one-time prekeys for a specific identity type.
202
+ * Rotate the prekeys of one identity type under the caller's lock.
329
203
  *
330
- * @param relay - Signal Protocol relay server interface
331
- * @param userId - User identifier
332
- * @param deviceId - Device identifier
333
- * @param storage - Key storage for local persistence
334
- * @param threshold - Minimum number of prekeys before replenishment
335
- * @param identityType - 'aci' or 'pni'
336
- * @returns true if the function replenished the prekeys
204
+ * The plan runs inside the relay adapter's publication fence with the
205
+ * inventory the adapter read. The signed keys are stored only after the
206
+ * publication returns.
337
207
  */
338
- async function replenishOneTimePreKeysForIdentity(relay, userId, deviceId, storage, threshold, identityType, preKeyMaintenance, logger = defaultSignalProtocolLogger) {
339
- return withRotationLock(userId, deviceId, `prekeys:${identityType}`, async () => {
340
- const count = await relay.getPreKeyCount(userId, deviceId, 'ec', identityType);
341
- if (count >= threshold) {
342
- logger.breadcrumb('One-time prekeys sufficient, no replenishment needed', {
208
+ async function rotatePreKeysForIdentity(relay, userId, deviceId, storage, identityType, options) {
209
+ const { refreshIntervalMs, threshold, preKeyMaintenance, logger } = options;
210
+ const planned = { signed: null, kyber: null, refill: null };
211
+ await relay.publishPlannedPreKeys(userId, deviceId, async (inventory) => {
212
+ const signedDue = checkRotationNeeded(inventory.ecSignedPreKey, refreshIntervalMs, `EC signed prekey (${identityType})`, logger);
213
+ const kyberDue = checkRotationNeeded(inventory.kemLastResortPreKey, refreshIntervalMs, `Kyber prekey (${identityType})`, logger);
214
+ const refillDue = oneTimePreKeysDue(inventory, threshold);
215
+ if (!signedDue && !kyberDue && !refillDue) {
216
+ logger.breadcrumb('Prekeys current, no publication needed', {
343
217
  category: 'E2EE',
344
218
  level: 'debug',
345
- data: { count, threshold, identityType },
219
+ data: { identityType, threshold },
346
220
  });
347
- return false;
221
+ return [];
348
222
  }
349
- logger.info('Replenishing one-time prekeys', {
223
+ logger.info('Rotating prekeys', {
350
224
  category: 'E2EE',
351
- data: { currentCount: count, threshold, identityType },
225
+ data: { userId, deviceId, identityType, signedDue, kyberDue, refillDue },
352
226
  });
353
- // Mark active one-time prekeys as replaced before generating a new batch.
354
- await preKeyMaintenance?.markEcOneTimePreKeysReplaced(identityType);
355
- await preKeyMaintenance?.markKyberOneTimePreKeysReplaced(identityType);
356
- const keys = await import('../keys/index.js');
357
- const newPreKeys = await keys.generateEcOneTimePreKeys(ONE_TIME_PREKEY_BATCH_SIZE);
358
- // Store locally first (private keys needed for decryption)
359
- await storage.storeEcOneTimePreKeys(newPreKeys, identityType);
360
- // Upload public keys to server (with identity type)
361
- await relay.uploadPreKeys(userId, deviceId, newPreKeys.map((pk) => ({
362
- type: 'ecPreKey',
363
- keyId: pk.keyId,
364
- publicKey: pk.publicKey,
365
- })), identityType);
366
- logger.info('One-time prekeys replenished', {
227
+ const uploads = [];
228
+ if (signedDue || kyberDue) {
229
+ const identityKey = await getRequiredIdentityKey(storage, identityType);
230
+ if (signedDue) {
231
+ planned.signed = await generateEcSignedPreKey(identityKey);
232
+ uploads.push({
233
+ type: 'ecSignedPreKey',
234
+ keyId: planned.signed.keyId,
235
+ publicKey: planned.signed.publicKey,
236
+ signature: planned.signed.signature,
237
+ });
238
+ }
239
+ if (kyberDue) {
240
+ planned.kyber = await generateKyberLastResortPreKey(identityKey, await nextKyberLastResortPreKeyId(storage, identityType));
241
+ uploads.push({
242
+ type: 'kemLastResortPreKey',
243
+ keyId: planned.kyber.keyId,
244
+ publicKey: planned.kyber.publicKey,
245
+ signature: planned.kyber.signature,
246
+ });
247
+ }
248
+ }
249
+ if (refillDue) {
250
+ // Local store first (private keys needed for decryption), then one upload.
251
+ planned.refill = await refillOneTimePreKeys({
252
+ storage,
253
+ identityType,
254
+ serverEcCount: inventory.ecOneTimePreKeyCount,
255
+ serverKemCount: inventory.kemOneTimePreKeyCount,
256
+ threshold,
257
+ preKeyMaintenance,
258
+ logger,
259
+ });
260
+ uploads.push(...planned.refill.uploads);
261
+ }
262
+ return uploads;
263
+ }, identityType);
264
+ // TRANSACTIONAL PATTERN: the publication succeeded, so commit the signed keys locally.
265
+ if (planned.signed) {
266
+ await storage.storeEcSignedPreKey(planned.signed, identityType);
267
+ }
268
+ if (planned.kyber) {
269
+ await storage.storeKyberPreKey({
270
+ ...planned.kyber,
271
+ publicKey: planned.kyber.publicKey,
272
+ privateKey: planned.kyber.privateKey,
273
+ signature: planned.kyber.signature,
274
+ }, identityType);
275
+ }
276
+ if (planned.signed || planned.kyber || planned.refill) {
277
+ logger.info('Prekeys rotated', {
367
278
  category: 'E2EE',
368
- data: { addedCount: newPreKeys.length, previousCount: count, identityType },
279
+ data: {
280
+ userId,
281
+ deviceId,
282
+ identityType,
283
+ signedRotated: planned.signed !== null,
284
+ kyberRotated: planned.kyber !== null,
285
+ ecAdded: planned.refill?.ecGenerated ?? 0,
286
+ kemAdded: planned.refill?.kemGenerated ?? 0,
287
+ },
369
288
  });
370
- return true;
371
- }, `Failed to replenish one-time prekeys (${identityType})`, logger);
289
+ }
290
+ return planned;
372
291
  }
373
292
  /**
374
293
  * Check prekey age and rotate if needed before sending a message.
@@ -399,11 +318,10 @@ async function replenishOneTimePreKeysForIdentity(relay, userId, deviceId, stora
399
318
  * @see https://signal.org/docs/specifications/pqxdh/#publishing-keys
400
319
  */
401
320
  export async function ensurePreKeysValid(relay, userId, deviceId, storage, maxAgeMs = MAX_PREKEY_AGE_MS_DEFAULT, identityType = 'aci', logger = defaultSignalProtocolLogger) {
402
- // Check EC signed prekey metadata for the specified identity type
403
- const signedMetadata = await relay.getEcSignedPreKeyMetadata(userId, deviceId, identityType);
321
+ // One inventory read gives both signed-key records for the identity type.
322
+ const inventory = await relay.getPreKeyInventory(userId, deviceId, identityType);
323
+ const { ecSignedPreKey: signedMetadata, kemLastResortPreKey: kyberMetadata } = inventory;
404
324
  const signedExpired = signedMetadata ? isPreKeyExpired(signedMetadata.createdAt, maxAgeMs) : true;
405
- // Check Kyber prekey metadata for the specified identity type
406
- const kyberMetadata = await relay.getKemLastResortPreKeyMetadata(userId, deviceId, identityType);
407
325
  const kyberExpired = kyberMetadata ? isPreKeyExpired(kyberMetadata.createdAt, maxAgeMs) : true;
408
326
  // If neither key expired, sending can proceed
409
327
  if (!signedExpired && !kyberExpired) {
@@ -428,32 +346,19 @@ export async function ensurePreKeysValid(relay, userId, deviceId, storage, maxAg
428
346
  : null,
429
347
  },
430
348
  });
431
- let signedRotated = !signedExpired;
432
- let kyberRotated = !kyberExpired;
433
- // Rotate signed prekey if expired
434
- if (signedExpired) {
435
- signedRotated = await rotateEcSignedPreKeyCore(relay, userId, deviceId, storage, undefined, [identityType], logger);
436
- if (!signedRotated) {
437
- logger.error('Failed to rotate EC signed prekey before send', {
438
- category: 'E2EE',
439
- error: new Error('EC signed prekey rotation failed'),
440
- data: { userId, deviceId, identityType },
441
- });
442
- }
443
- }
444
- // Rotate Kyber prekey if expired
445
- if (kyberExpired) {
446
- kyberRotated = await rotateKyberPreKeyCore(relay, userId, deviceId, storage, undefined, [identityType], logger);
447
- if (!kyberRotated) {
448
- logger.error('Failed to rotate Kyber prekey before send', {
449
- category: 'E2EE',
450
- error: new Error('Kyber prekey rotation failed'),
451
- data: { userId, deviceId, identityType },
452
- });
453
- }
454
- }
455
- const allRotated = signedRotated && kyberRotated;
456
- if (!allRotated) {
349
+ // An expired key is older than the refresh interval, so the rotation finds it due.
350
+ const rotation = await rotatePreKeysCore(relay, userId, deviceId, storage, {
351
+ identityTypes: [identityType],
352
+ logger,
353
+ });
354
+ const signedRotated = !signedExpired || rotation.signedRotated;
355
+ const kyberRotated = !kyberExpired || rotation.kyberRotated;
356
+ if (!signedRotated || !kyberRotated) {
357
+ logger.error('Failed to rotate prekeys before send', {
358
+ category: 'E2EE',
359
+ error: new Error(rotation.errors.join('; ') || 'Prekey rotation left an expired key'),
360
+ data: { userId, deviceId, identityType, signedRotated, kyberRotated },
361
+ });
457
362
  return {
458
363
  canSend: false,
459
364
  rotationAttempted: true,
@@ -1 +1 @@
1
- {"version":3,"file":"key-rotation-core.js","sourceRoot":"","sources":["../../client/key-rotation-core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,SAAS,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,2BAA2B,EAAe,MAAM,WAAW,CAAC;AAKrE,OAAO,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAC;AAEtD,OAAO,EACL,+BAA+B,EAC/B,yBAAyB,GAE1B,MAAM,UAAU,CAAC;AAWlB,MAAM,YAAY,GAAG,IAAI,SAAS,CAAC;IACjC,OAAO,EAAE,KAAK,EAAE,kDAAkD;IAClE,UAAU,EAAE,EAAE,EAAE,iCAAiC;CAClD,CAAC,CAAC;AAEH,+EAA+E;AAC/E,iBAAiB;AACjB,+EAA+E;AAE/E;;GAEG;AACH,KAAK,UAAU,cAAc,CAC3B,eAA0C,EAC1C,MAAM,GAAqB,2BAA2B;IAEtD,IAAI,eAAe,EAAE,CAAC;QACpB,OAAO,eAAe,CAAC;IACzB,C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ACJ,CAAC"}
@@ -2,45 +2,30 @@
2
2
  * Key rotation operations for SignalProtocolClient
3
3
  *
4
4
  * Extracted from DefaultSignalProtocolClient class to reduce file size.
5
- * Rotates EC signed prekeys and Kyber (post-quantum) prekeys.
5
+ * One entry point rotates the EC signed prekey, the Kyber (post-quantum)
6
+ * last-resort prekey, and the one-time prekey batches.
6
7
  *
7
- * With relay configured: Delegates to key-rotation-core.ts for metadata-based
8
- * rotation decisions (skips if key is fresh).
8
+ * With relay configured: Delegates to key-rotation-core.ts, which reads the
9
+ * inventory once and publishes every due key in one publication.
9
10
  *
10
- * Without relay (local-only): Always rotates unconditionally since we cannot
11
- * check server metadata.
11
+ * Without relay (local-only): Always rotates both signed keys unconditionally
12
+ * since we cannot check server metadata. No one-time refill runs.
12
13
  */
14
+ import { type PreKeyRotationResult } from '../types/index.js';
13
15
  import type { SignalProtocolClientContext } from './types.js';
14
16
  /**
15
- * Rotate EC signed prekey
17
+ * Rotate the device's prekeys.
16
18
  *
17
19
  * Call this periodically (default: every 2 days) to maintain forward secrecy.
18
- * Generates new EC signed prekey and uploads to relay server if configured.
20
+ * Safe to call more often: nothing due costs one inventory read.
19
21
  *
20
- * With relay: Checks key age and config.keyRefreshIntervalMs to decide on rotation.
21
- * Without relay: Always rotates (local-only development mode).
22
+ * With relay: One inventory read decides on the signed keys (config.keyRefreshIntervalMs)
23
+ * and the one-time refill, and one publication carries every due key.
24
+ * Without relay: Always rotates both signed keys (local-only development mode).
22
25
  *
23
26
  * @param ctx - Client context with dependencies
24
- * @returns True if the function rotated the key, false if the key is still fresh
27
+ * @returns Which keys the rotation published, and one error per failed identity type
25
28
  */
26
29
  export {};
27
- export declare function rotateEcSignedPreKey(ctx: SignalProtocolClientContext): Promise<boolean>;
28
- /**
29
- * Rotate the post-quantum KEM last-resort prekey.
30
- *
31
- * Call this periodically (default: every 2 days) alongside signed prekey rotation.
32
- * Generates fresh ML-KEM/Kyber-compatible key material and uploads it to the
33
- * relay if configured.
34
- *
35
- * Each rotation takes the next key id, so a session that names an id resolves
36
- * to exactly one retained key.
37
- * Uses the same timing as signed prekey rotation for synchronized PQ security.
38
- *
39
- * With relay: Checks key age and config.keyRefreshIntervalMs to decide on rotation.
40
- * Without relay: Always rotates (local-only development mode).
41
- *
42
- * @param ctx - Client context with dependencies
43
- * @returns True if the function rotated the key, false if the key is still fresh
44
- */
45
- export declare function rotateKyberPreKey(ctx: SignalProtocolClientContext): Promise<boolean>;
30
+ export declare function rotatePreKeys(ctx: SignalProtocolClientContext): Promise<PreKeyRotationResult>;
46
31
  //# sourceMappingURL=key-rotation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"key-rotation.d.ts","sourceRoot":"","sources":["../../client/key-rotation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAIH,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAa3D;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,CAAC;AACV,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,2BAA2B,GAAG,OAAO,CAAC,OAAO,CAAC,CAkC7F;AAiDD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,iBAAiB,CAAC,GAAG,EAAE,2BAA2B,GAAG,OAAO,CAAC,OAAO,CAAC,CAkC1F"}
1
+ {"version":3,"file":"key-rotation.d.ts","sourceRoot":"","sources":["../../client/key-rotation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAwC,KAAK,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAE3F,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAS3D;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,CAAC;AACV,wBAAsB,aAAa,CAAC,GAAG,EAAE,2BAA2B,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAsCnG"}