@signalapp/libsignal-client 0.77.1 → 0.78.1

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/Native.d.ts CHANGED
@@ -228,9 +228,11 @@ export function BackupKey_DeriveLocalBackupMetadataKey(backupKey: Uint8Array): U
228
228
  export function BackupKey_DeriveMediaEncryptionKey(backupKey: Uint8Array, mediaId: Uint8Array): Uint8Array;
229
229
  export function BackupKey_DeriveMediaId(backupKey: Uint8Array, mediaName: string): Uint8Array;
230
230
  export function BackupKey_DeriveThumbnailTransitEncryptionKey(backupKey: Uint8Array, mediaId: Uint8Array): Uint8Array;
231
- export function BackupResponse_GetForwardSecrecyToken(response: Wrapper<BackupResponse>): Uint8Array;
232
- export function BackupResponse_GetNextBackupSecretData(response: Wrapper<BackupResponse>): Uint8Array;
233
- export function BackupResponse_GetOpaqueMetadata(response: Wrapper<BackupResponse>): Uint8Array;
231
+ export function BackupRestoreResponse_GetForwardSecrecyToken(response: Wrapper<BackupRestoreResponse>): Uint8Array;
232
+ export function BackupRestoreResponse_GetNextBackupSecretData(response: Wrapper<BackupRestoreResponse>): Uint8Array;
233
+ export function BackupStoreResponse_GetForwardSecrecyToken(response: Wrapper<BackupStoreResponse>): Uint8Array;
234
+ export function BackupStoreResponse_GetNextBackupSecretData(response: Wrapper<BackupStoreResponse>): Uint8Array;
235
+ export function BackupStoreResponse_GetOpaqueMetadata(response: Wrapper<BackupStoreResponse>): Uint8Array;
234
236
  export function BridgedStringMap_insert(map: Wrapper<BridgedStringMap>, key: string, value: string): void;
235
237
  export function BridgedStringMap_new(initialCapacity: number): BridgedStringMap;
236
238
  export function CallLinkAuthCredentialPresentation_CheckValidContents(presentationBytes: Uint8Array): void;
@@ -501,8 +503,9 @@ export function SealedSender_DecryptToUsmc(ctext: Uint8Array, identityStore: Ide
501
503
  export function SealedSender_Encrypt(destination: Wrapper<ProtocolAddress>, content: Wrapper<UnidentifiedSenderMessageContent>, identityKeyStore: IdentityKeyStore): Promise<Uint8Array>;
502
504
  export function SealedSender_MultiRecipientEncrypt(recipients: Wrapper<ProtocolAddress>[], recipientSessions: Wrapper<SessionRecord>[], excludedRecipients: Uint8Array, content: Wrapper<UnidentifiedSenderMessageContent>, identityKeyStore: IdentityKeyStore): Promise<Uint8Array>;
503
505
  export function SealedSender_MultiRecipientMessageForSingleRecipient(encodedMultiRecipientMessage: Uint8Array): Uint8Array;
504
- export function SecureValueRecoveryForBackups_RestoreBackupFromServer(asyncRuntime: Wrapper<TokioAsyncContext>, backupKey: Uint8Array, metadata: Uint8Array, connectionManager: Wrapper<ConnectionManager>, username: string, password: string): CancellablePromise<Uint8Array>;
505
- export function SecureValueRecoveryForBackups_StoreBackup(asyncRuntime: Wrapper<TokioAsyncContext>, backupKey: Uint8Array, previousSecretData: Uint8Array, connectionManager: Wrapper<ConnectionManager>, username: string, password: string): CancellablePromise<BackupResponse>;
506
+ export function SecureValueRecoveryForBackups_CreateNewBackupChain(environment: number, backupKey: Uint8Array): Uint8Array;
507
+ export function SecureValueRecoveryForBackups_RestoreBackupFromServer(asyncRuntime: Wrapper<TokioAsyncContext>, backupKey: Uint8Array, metadata: Uint8Array, connectionManager: Wrapper<ConnectionManager>, username: string, password: string): CancellablePromise<BackupRestoreResponse>;
508
+ export function SecureValueRecoveryForBackups_StoreBackup(asyncRuntime: Wrapper<TokioAsyncContext>, backupKey: Uint8Array, previousSecretData: Uint8Array, connectionManager: Wrapper<ConnectionManager>, username: string, password: string): CancellablePromise<BackupStoreResponse>;
506
509
  export function SenderCertificate_Deserialize(data: Uint8Array): SenderCertificate;
507
510
  export function SenderCertificate_GetCertificate(obj: Wrapper<SenderCertificate>): Uint8Array;
508
511
  export function SenderCertificate_GetDeviceId(obj: Wrapper<SenderCertificate>): number;
@@ -719,7 +722,8 @@ export function initLogger(maxLevel: LogLevel, callback: (level: LogLevel, targe
719
722
  export function test_only_fn_returns_123(): number;
720
723
  interface Aes256GcmSiv { readonly __type: unique symbol; }
721
724
  interface AuthenticatedChatConnection { readonly __type: unique symbol; }
722
- interface BackupResponse { readonly __type: unique symbol; }
725
+ interface BackupRestoreResponse { readonly __type: unique symbol; }
726
+ interface BackupStoreResponse { readonly __type: unique symbol; }
723
727
  interface BridgedStringMap { readonly __type: unique symbol; }
724
728
  interface CdsiLookup { readonly __type: unique symbol; }
725
729
  interface ChatConnectionInfo { readonly __type: unique symbol; }
@@ -30,7 +30,33 @@ export type StoreBackupResponse = {
30
30
  */
31
31
  metadata: Uint8Array;
32
32
  /**
33
- * Opaque value that must be persisted and provided to the next call to {@link SvrB#storeBackup}.
33
+ * Opaque value that must be persisted and provided to the next call to {@link SvrB#store}.
34
+ *
35
+ * See the {@link SvrB} documentation for lifecycle and persistence handling
36
+ * for this value.
37
+ */
38
+ nextBackupSecretData: Uint8Array;
39
+ };
40
+ /**
41
+ * The result of preparing a backup to be stored with forward secrecy guarantees.
42
+ *
43
+ * This context contains all the necessary components to encrypt and store a backup using a
44
+ * key derived from both the user's Account Entropy Pool and the SVR-B-protected
45
+ * Forward Secrecy Token.
46
+ *
47
+ * @see {@link BackupForwardSecrecyToken}
48
+ */
49
+ export type RestoreBackupResponse = {
50
+ /**
51
+ * The forward secrecy token used to derive MessageBackupKey instances.
52
+ *
53
+ * This token provides forward secrecy guarantees by ensuring that compromise of the backup key
54
+ * alone is insufficient to decrypt backups. Each backup is protected by a value stored on
55
+ * the SVR-B server that must be retrieved during restoration.
56
+ */
57
+ forwardSecrecyToken: BackupForwardSecrecyToken;
58
+ /**
59
+ * Opaque value that must be persisted and provided to the next call to {@link SvrB#store}.
34
60
  *
35
61
  * See the {@link SvrB} documentation for lifecycle and persistence handling
36
62
  * for this value.
@@ -56,23 +82,24 @@ export type StoreBackupResponse = {
56
82
  * ## Storage Flow
57
83
  *
58
84
  * 1. Create a {@link Net} instance and get the {@link SvrB} service via {@link Net#svrB}
59
- * 2. Call {@link SvrB#storeBackup}
60
- * - Pass the secret data from the last **successful** {@link SvrB#storeBackup} call
61
- * - If no previous backup exists or the secret data is unavailable, pass `undefined`
62
- * 3. Use the returned forward secrecy token to derive encryption keys
63
- * 4. Encrypt and upload the backup data to the user's remote, off-device storage location, including the
64
- * returned {@link StoreBackupResponse#metadata}. The upload **must succeed**
85
+ * 2. If this is a fresh install, call {@link SvrB#createNewBackupChain} and store the result
86
+ * locally. Otherwise, retrieve the secret data from the last **successful** backup operation
87
+ * (store or restore).
88
+ * 3. Call {@link SvrB#store}
89
+ * 4. Use the returned forward secrecy token to derive encryption keys
90
+ * 5. Encrypt and upload the backup data to the user's remote, off-device storage location,
91
+ * including the returned {@link StoreBackupResponse#metadata}. The upload **must succeed**
65
92
  * before proceeding or the previous backup might become unretrievable.
66
- * 5. Store the {@link StoreBackupResponse#nextBackupSecretData} locally, overwriting any previously-saved value.
93
+ * 6. Store the {@link StoreBackupResponse#nextBackupSecretData} locally, overwriting any
94
+ * previously-saved value.
67
95
  *
68
96
  * ## Secret handling
69
97
  *
70
- * When calling {@link SvrB#storeBackup}, the `previousSecretData` parameter
71
- * must be from the last call to {@link SvrB#storeBackup} that
72
- * succeeded. The returned secret from a successful `storeBackup()` call should
73
- * be persisted until it is overwritten by the value from a subsequent
74
- * successful call. The caller should pass `undefined` as `previousSecretData`
75
- * only for the very first backup from a device.
98
+ * When calling {@link SvrB#store}, the `previousSecretData` parameter must be from the last call to
99
+ * {@link SvrB#store} or {@link SvrB#restore} that succeeded. The returned secret from a successful
100
+ * store or restore should be persisted until it is overwritten by the value from a subsequent
101
+ * successful call. The caller should use {@link SvrB#createNewBackupChain} only for the very first
102
+ * backup with a particular backup key.
76
103
  *
77
104
  * ## Restore Flow
78
105
  *
@@ -81,6 +108,7 @@ export type StoreBackupResponse = {
81
108
  * 3. Call {@link SvrB#fetchForwardSecrecyTokenFromServer} to get the forward secrecy token
82
109
  * 4. Use the token to derive decryption keys
83
110
  * 5. Decrypt and restore the backup data
111
+ * 6. Store the returned {@link RestoreBackupResponse#nextBackupSecretData} locally.
84
112
  *
85
113
  * ## Usage
86
114
  * ```typescript
@@ -105,26 +133,35 @@ export declare class SvrB {
105
133
  username: string;
106
134
  password: string;
107
135
  }>, environment: Environment);
136
+ /**
137
+ * Generates backup "secret data" for a fresh install.
138
+ *
139
+ * Should not be used if any previous backups exist for this `backupKey`, whether uploaded or
140
+ * restored by the local device. See {@link SvrB} for more information.
141
+ */
142
+ createNewBackupChain(backupKey: BackupKey): Uint8Array;
108
143
  /**
109
144
  * Prepares a backup for storage with forward secrecy guarantees.
110
145
  *
111
- * This makes a network call to the SVR-B server to store the forward secrecy token
112
- * and returns a {@link StoreBackupResponse}. See its fields' documentation and {@link SvrB}
113
- * for how to continue persisting the backup on success.
146
+ * This makes a network call to the SVR-B server to store the forward secrecy token and returns a
147
+ * {@link StoreBackupResponse}. See its fields' documentation and {@link SvrB} for how to continue
148
+ * persisting the backup on success.
114
149
  *
115
150
  * @param backupKey The backup key derived from the Account Entropy Pool (AEP).
116
151
  * @param previousSecretData Optional secret data from the most recent previous backup.
117
- * **Critical**: This MUST be the {@link StoreBackupResponse#nextBackupSecretData} data
118
- * from the last {@link #storeBackup} whose returned {@link StoreBackupResponse#metadata} was
152
+ * **Critical**: This MUST be the secret data from the most recent of the following:
153
+ * - the last {@link #store} call whose returned {@link StoreBackupResponse#metadata} was
119
154
  * successfully uploaded, and whose `nextBackupSecretData` was persisted.
120
- * If `undefined`, starts a new chain and renders any prior backups unretrievable; this should
121
- * only be used for the very first backup from a device.
155
+ * - the last {@link #restore} call
156
+ * - the already-persisted result from {@link #createNewBackupChain}, only if neither of the other
157
+ * two are available.
122
158
  * @param options Optional configuration.
123
159
  * @param options.abortSignal An AbortSignal that will cancel the request.
124
- * @returns a {@link StoreBackupResponse} containing the forward secrecy token, metadata, and secret data.
125
- * @throws Error if the previous secret data is malformed, or if processing or upload fail.
160
+ * @returns a {@link StoreBackupResponse} containing the forward secrecy token, metadata, and
161
+ * secret data.
162
+ * @throws Error if the previous secret data is malformed, or if processing or upload fail.
126
163
  */
127
- storeBackup(backupKey: BackupKey, previousSecretData?: Uint8Array, options?: {
164
+ store(backupKey: BackupKey, previousSecretData: Uint8Array, options?: {
128
165
  abortSignal?: AbortSignal;
129
166
  }): Promise<StoreBackupResponse>;
130
167
  /**
@@ -139,6 +176,7 @@ export declare class SvrB {
139
176
  * 2. Call this function to retrieve the forward secrecy token from SVR-B
140
177
  * 3. Use the token to derive message backup keys
141
178
  * 4. Decrypt and restore the backup data
179
+ * 5. Store the returned {@link RestoreBackupResponse#nextBackupSecretData} locally.
142
180
  *
143
181
  * @param backupKey The backup key derived from the Account Entropy Pool (AEP).
144
182
  * @param metadata The metadata that was stored in a header in the backup file during backup creation.
@@ -148,8 +186,8 @@ export declare class SvrB {
148
186
  * @throws Error if the metadata is invalid, the network operation fails, or the
149
187
  * backup cannot be found.
150
188
  */
151
- fetchForwardSecrecyTokenFromServer(backupKey: BackupKey, metadata: Uint8Array, options?: {
189
+ restore(backupKey: BackupKey, metadata: Uint8Array, options?: {
152
190
  abortSignal?: AbortSignal;
153
- }): Promise<BackupForwardSecrecyToken>;
191
+ }): Promise<RestoreBackupResponse>;
154
192
  }
155
193
  export {};
package/dist/net/SvrB.js CHANGED
@@ -12,14 +12,26 @@ class StoreBackupResponseImpl {
12
12
  this._nativeHandle = handle;
13
13
  }
14
14
  get forwardSecrecyToken() {
15
- const tokenBytes = Native.BackupResponse_GetForwardSecrecyToken(this);
15
+ const tokenBytes = Native.BackupStoreResponse_GetForwardSecrecyToken(this);
16
16
  return new AccountKeys_1.BackupForwardSecrecyToken(tokenBytes);
17
17
  }
18
18
  get metadata() {
19
- return Native.BackupResponse_GetOpaqueMetadata(this);
19
+ return Native.BackupStoreResponse_GetOpaqueMetadata(this);
20
20
  }
21
21
  get nextBackupSecretData() {
22
- return Native.BackupResponse_GetNextBackupSecretData(this);
22
+ return Native.BackupStoreResponse_GetNextBackupSecretData(this);
23
+ }
24
+ }
25
+ class RestoreBackupResponseImpl {
26
+ constructor(handle) {
27
+ this._nativeHandle = handle;
28
+ }
29
+ get forwardSecrecyToken() {
30
+ const tokenBytes = Native.BackupRestoreResponse_GetForwardSecrecyToken(this);
31
+ return new AccountKeys_1.BackupForwardSecrecyToken(tokenBytes);
32
+ }
33
+ get nextBackupSecretData() {
34
+ return Native.BackupRestoreResponse_GetNextBackupSecretData(this);
23
35
  }
24
36
  }
25
37
  /**
@@ -41,23 +53,24 @@ class StoreBackupResponseImpl {
41
53
  * ## Storage Flow
42
54
  *
43
55
  * 1. Create a {@link Net} instance and get the {@link SvrB} service via {@link Net#svrB}
44
- * 2. Call {@link SvrB#storeBackup}
45
- * - Pass the secret data from the last **successful** {@link SvrB#storeBackup} call
46
- * - If no previous backup exists or the secret data is unavailable, pass `undefined`
47
- * 3. Use the returned forward secrecy token to derive encryption keys
48
- * 4. Encrypt and upload the backup data to the user's remote, off-device storage location, including the
49
- * returned {@link StoreBackupResponse#metadata}. The upload **must succeed**
56
+ * 2. If this is a fresh install, call {@link SvrB#createNewBackupChain} and store the result
57
+ * locally. Otherwise, retrieve the secret data from the last **successful** backup operation
58
+ * (store or restore).
59
+ * 3. Call {@link SvrB#store}
60
+ * 4. Use the returned forward secrecy token to derive encryption keys
61
+ * 5. Encrypt and upload the backup data to the user's remote, off-device storage location,
62
+ * including the returned {@link StoreBackupResponse#metadata}. The upload **must succeed**
50
63
  * before proceeding or the previous backup might become unretrievable.
51
- * 5. Store the {@link StoreBackupResponse#nextBackupSecretData} locally, overwriting any previously-saved value.
64
+ * 6. Store the {@link StoreBackupResponse#nextBackupSecretData} locally, overwriting any
65
+ * previously-saved value.
52
66
  *
53
67
  * ## Secret handling
54
68
  *
55
- * When calling {@link SvrB#storeBackup}, the `previousSecretData` parameter
56
- * must be from the last call to {@link SvrB#storeBackup} that
57
- * succeeded. The returned secret from a successful `storeBackup()` call should
58
- * be persisted until it is overwritten by the value from a subsequent
59
- * successful call. The caller should pass `undefined` as `previousSecretData`
60
- * only for the very first backup from a device.
69
+ * When calling {@link SvrB#store}, the `previousSecretData` parameter must be from the last call to
70
+ * {@link SvrB#store} or {@link SvrB#restore} that succeeded. The returned secret from a successful
71
+ * store or restore should be persisted until it is overwritten by the value from a subsequent
72
+ * successful call. The caller should use {@link SvrB#createNewBackupChain} only for the very first
73
+ * backup with a particular backup key.
61
74
  *
62
75
  * ## Restore Flow
63
76
  *
@@ -66,6 +79,7 @@ class StoreBackupResponseImpl {
66
79
  * 3. Call {@link SvrB#fetchForwardSecrecyTokenFromServer} to get the forward secrecy token
67
80
  * 4. Use the token to derive decryption keys
68
81
  * 5. Decrypt and restore the backup data
82
+ * 6. Store the returned {@link RestoreBackupResponse#nextBackupSecretData} locally.
69
83
  *
70
84
  * ## Usage
71
85
  * ```typescript
@@ -88,28 +102,38 @@ class SvrB {
88
102
  this.auth = auth;
89
103
  this.environment = environment;
90
104
  }
105
+ /**
106
+ * Generates backup "secret data" for a fresh install.
107
+ *
108
+ * Should not be used if any previous backups exist for this `backupKey`, whether uploaded or
109
+ * restored by the local device. See {@link SvrB} for more information.
110
+ */
111
+ createNewBackupChain(backupKey) {
112
+ return Native.SecureValueRecoveryForBackups_CreateNewBackupChain(this.environment, backupKey.serialize());
113
+ }
91
114
  /**
92
115
  * Prepares a backup for storage with forward secrecy guarantees.
93
116
  *
94
- * This makes a network call to the SVR-B server to store the forward secrecy token
95
- * and returns a {@link StoreBackupResponse}. See its fields' documentation and {@link SvrB}
96
- * for how to continue persisting the backup on success.
117
+ * This makes a network call to the SVR-B server to store the forward secrecy token and returns a
118
+ * {@link StoreBackupResponse}. See its fields' documentation and {@link SvrB} for how to continue
119
+ * persisting the backup on success.
97
120
  *
98
121
  * @param backupKey The backup key derived from the Account Entropy Pool (AEP).
99
122
  * @param previousSecretData Optional secret data from the most recent previous backup.
100
- * **Critical**: This MUST be the {@link StoreBackupResponse#nextBackupSecretData} data
101
- * from the last {@link #storeBackup} whose returned {@link StoreBackupResponse#metadata} was
123
+ * **Critical**: This MUST be the secret data from the most recent of the following:
124
+ * - the last {@link #store} call whose returned {@link StoreBackupResponse#metadata} was
102
125
  * successfully uploaded, and whose `nextBackupSecretData` was persisted.
103
- * If `undefined`, starts a new chain and renders any prior backups unretrievable; this should
104
- * only be used for the very first backup from a device.
126
+ * - the last {@link #restore} call
127
+ * - the already-persisted result from {@link #createNewBackupChain}, only if neither of the other
128
+ * two are available.
105
129
  * @param options Optional configuration.
106
130
  * @param options.abortSignal An AbortSignal that will cancel the request.
107
- * @returns a {@link StoreBackupResponse} containing the forward secrecy token, metadata, and secret data.
108
- * @throws Error if the previous secret data is malformed, or if processing or upload fail.
131
+ * @returns a {@link StoreBackupResponse} containing the forward secrecy token, metadata, and
132
+ * secret data.
133
+ * @throws Error if the previous secret data is malformed, or if processing or upload fail.
109
134
  */
110
- async storeBackup(backupKey, previousSecretData, options) {
111
- const secretData = previousSecretData ?? new Uint8Array(0);
112
- const promise = Native.SecureValueRecoveryForBackups_StoreBackup(this.asyncContext, backupKey.serialize(), secretData, this.connectionManager, this.auth.username, this.auth.password);
135
+ async store(backupKey, previousSecretData, options) {
136
+ const promise = Native.SecureValueRecoveryForBackups_StoreBackup(this.asyncContext, backupKey.serialize(), previousSecretData, this.connectionManager, this.auth.username, this.auth.password);
113
137
  const response = await this.asyncContext.makeCancellable(options?.abortSignal, promise);
114
138
  return new StoreBackupResponseImpl(response);
115
139
  }
@@ -125,6 +149,7 @@ class SvrB {
125
149
  * 2. Call this function to retrieve the forward secrecy token from SVR-B
126
150
  * 3. Use the token to derive message backup keys
127
151
  * 4. Decrypt and restore the backup data
152
+ * 5. Store the returned {@link RestoreBackupResponse#nextBackupSecretData} locally.
128
153
  *
129
154
  * @param backupKey The backup key derived from the Account Entropy Pool (AEP).
130
155
  * @param metadata The metadata that was stored in a header in the backup file during backup creation.
@@ -134,10 +159,10 @@ class SvrB {
134
159
  * @throws Error if the metadata is invalid, the network operation fails, or the
135
160
  * backup cannot be found.
136
161
  */
137
- async fetchForwardSecrecyTokenFromServer(backupKey, metadata, options) {
162
+ async restore(backupKey, metadata, options) {
138
163
  const promise = Native.SecureValueRecoveryForBackups_RestoreBackupFromServer(this.asyncContext, backupKey.serialize(), metadata, this.connectionManager, this.auth.username, this.auth.password);
139
- const tokenBytes = await this.asyncContext.makeCancellable(options?.abortSignal, promise);
140
- return new AccountKeys_1.BackupForwardSecrecyToken(tokenBytes);
164
+ const response = await this.asyncContext.makeCancellable(options?.abortSignal, promise);
165
+ return new RestoreBackupResponseImpl(response);
141
166
  }
142
167
  }
143
168
  exports.SvrB = SvrB;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signalapp/libsignal-client",
3
- "version": "0.77.1",
3
+ "version": "0.78.1",
4
4
  "license": "AGPL-3.0-only",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",