@signalapp/libsignal-client 0.77.0 → 0.78.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/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,9 +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_CreateStoreArgs(backupKey: Uint8Array, previousSecretData: Uint8Array, environment: number): StoreArgs;
505
- export function SecureValueRecoveryForBackups_RestoreBackupFromServer(asyncRuntime: Wrapper<TokioAsyncContext>, backupKey: Uint8Array, metadata: Uint8Array, connectionManager: Wrapper<ConnectionManager>, username: string, password: string): CancellablePromise<Uint8Array>;
506
- export function SecureValueRecoveryForBackups_StoreBackup(asyncRuntime: Wrapper<TokioAsyncContext>, store: Wrapper<StoreArgs>, 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>;
507
509
  export function SenderCertificate_Deserialize(data: Uint8Array): SenderCertificate;
508
510
  export function SenderCertificate_GetCertificate(obj: Wrapper<SenderCertificate>): Uint8Array;
509
511
  export function SenderCertificate_GetDeviceId(obj: Wrapper<SenderCertificate>): number;
@@ -720,7 +722,8 @@ export function initLogger(maxLevel: LogLevel, callback: (level: LogLevel, targe
720
722
  export function test_only_fn_returns_123(): number;
721
723
  interface Aes256GcmSiv { readonly __type: unique symbol; }
722
724
  interface AuthenticatedChatConnection { readonly __type: unique symbol; }
723
- interface BackupResponse { readonly __type: unique symbol; }
725
+ interface BackupRestoreResponse { readonly __type: unique symbol; }
726
+ interface BackupStoreResponse { readonly __type: unique symbol; }
724
727
  interface BridgedStringMap { readonly __type: unique symbol; }
725
728
  interface CdsiLookup { readonly __type: unique symbol; }
726
729
  interface ChatConnectionInfo { readonly __type: unique symbol; }
@@ -789,7 +792,6 @@ interface SessionRecord { readonly __type: unique symbol; }
789
792
  interface SgxClientState { readonly __type: unique symbol; }
790
793
  interface SignalMessage { readonly __type: unique symbol; }
791
794
  interface SignedPreKeyRecord { readonly __type: unique symbol; }
792
- interface StoreArgs { readonly __type: unique symbol; }
793
795
  interface TestingFutureCancellationCounter { readonly __type: unique symbol; }
794
796
  interface TestingHandleType { readonly __type: unique symbol; }
795
797
  interface TestingSemaphore { 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
@@ -7,20 +7,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.SvrB = void 0;
8
8
  const Native = require("../../Native");
9
9
  const AccountKeys_1 = require("../AccountKeys");
10
- const internal_1 = require("../internal");
11
10
  class StoreBackupResponseImpl {
12
11
  constructor(handle) {
13
12
  this._nativeHandle = handle;
14
13
  }
15
14
  get forwardSecrecyToken() {
16
- const tokenBytes = Native.BackupResponse_GetForwardSecrecyToken(this);
15
+ const tokenBytes = Native.BackupStoreResponse_GetForwardSecrecyToken(this);
17
16
  return new AccountKeys_1.BackupForwardSecrecyToken(tokenBytes);
18
17
  }
19
18
  get metadata() {
20
- return Native.BackupResponse_GetOpaqueMetadata(this);
19
+ return Native.BackupStoreResponse_GetOpaqueMetadata(this);
21
20
  }
22
21
  get nextBackupSecretData() {
23
- 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);
24
35
  }
25
36
  }
26
37
  /**
@@ -42,23 +53,24 @@ class StoreBackupResponseImpl {
42
53
  * ## Storage Flow
43
54
  *
44
55
  * 1. Create a {@link Net} instance and get the {@link SvrB} service via {@link Net#svrB}
45
- * 2. Call {@link SvrB#storeBackup}
46
- * - Pass the secret data from the last **successful** {@link SvrB#storeBackup} call
47
- * - If no previous backup exists or the secret data is unavailable, pass `undefined`
48
- * 3. Use the returned forward secrecy token to derive encryption keys
49
- * 4. Encrypt and upload the backup data to the user's remote, off-device storage location, including the
50
- * 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**
51
63
  * before proceeding or the previous backup might become unretrievable.
52
- * 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.
53
66
  *
54
67
  * ## Secret handling
55
68
  *
56
- * When calling {@link SvrB#storeBackup}, the `previousSecretData` parameter
57
- * must be from the last call to {@link SvrB#storeBackup} that
58
- * succeeded. The returned secret from a successful `storeBackup()` call should
59
- * be persisted until it is overwritten by the value from a subsequent
60
- * successful call. The caller should pass `undefined` as `previousSecretData`
61
- * 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.
62
74
  *
63
75
  * ## Restore Flow
64
76
  *
@@ -67,6 +79,7 @@ class StoreBackupResponseImpl {
67
79
  * 3. Call {@link SvrB#fetchForwardSecrecyTokenFromServer} to get the forward secrecy token
68
80
  * 4. Use the token to derive decryption keys
69
81
  * 5. Decrypt and restore the backup data
82
+ * 6. Store the returned {@link RestoreBackupResponse#nextBackupSecretData} locally.
70
83
  *
71
84
  * ## Usage
72
85
  * ```typescript
@@ -89,29 +102,38 @@ class SvrB {
89
102
  this.auth = auth;
90
103
  this.environment = environment;
91
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
+ }
92
114
  /**
93
115
  * Prepares a backup for storage with forward secrecy guarantees.
94
116
  *
95
- * This makes a network call to the SVR-B server to store the forward secrecy token
96
- * and returns a {@link StoreBackupResponse}. See its fields' documentation and {@link SvrB}
97
- * 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.
98
120
  *
99
121
  * @param backupKey The backup key derived from the Account Entropy Pool (AEP).
100
122
  * @param previousSecretData Optional secret data from the most recent previous backup.
101
- * **Critical**: This MUST be the {@link StoreBackupResponse#nextBackupSecretData} data
102
- * 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
103
125
  * successfully uploaded, and whose `nextBackupSecretData` was persisted.
104
- * If `undefined`, starts a new chain and renders any prior backups unretrievable; this should
105
- * 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.
106
129
  * @param options Optional configuration.
107
130
  * @param options.abortSignal An AbortSignal that will cancel the request.
108
- * @returns a {@link StoreBackupResponse} containing the forward secrecy token, metadata, and secret data.
109
- * @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.
110
134
  */
111
- async storeBackup(backupKey, previousSecretData, options) {
112
- const secretData = previousSecretData ?? new Uint8Array(0);
113
- const handle = (0, internal_1.newNativeHandle)(Native.SecureValueRecoveryForBackups_CreateStoreArgs(backupKey.serialize(), secretData, this.environment));
114
- const promise = Native.SecureValueRecoveryForBackups_StoreBackup(this.asyncContext, handle, 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);
115
137
  const response = await this.asyncContext.makeCancellable(options?.abortSignal, promise);
116
138
  return new StoreBackupResponseImpl(response);
117
139
  }
@@ -127,6 +149,7 @@ class SvrB {
127
149
  * 2. Call this function to retrieve the forward secrecy token from SVR-B
128
150
  * 3. Use the token to derive message backup keys
129
151
  * 4. Decrypt and restore the backup data
152
+ * 5. Store the returned {@link RestoreBackupResponse#nextBackupSecretData} locally.
130
153
  *
131
154
  * @param backupKey The backup key derived from the Account Entropy Pool (AEP).
132
155
  * @param metadata The metadata that was stored in a header in the backup file during backup creation.
@@ -136,10 +159,10 @@ class SvrB {
136
159
  * @throws Error if the metadata is invalid, the network operation fails, or the
137
160
  * backup cannot be found.
138
161
  */
139
- async fetchForwardSecrecyTokenFromServer(backupKey, metadata, options) {
162
+ async restore(backupKey, metadata, options) {
140
163
  const promise = Native.SecureValueRecoveryForBackups_RestoreBackupFromServer(this.asyncContext, backupKey.serialize(), metadata, this.connectionManager, this.auth.username, this.auth.password);
141
- const tokenBytes = await this.asyncContext.makeCancellable(options?.abortSignal, promise);
142
- return new AccountKeys_1.BackupForwardSecrecyToken(tokenBytes);
164
+ const response = await this.asyncContext.makeCancellable(options?.abortSignal, promise);
165
+ return new RestoreBackupResponseImpl(response);
143
166
  }
144
167
  }
145
168
  exports.SvrB = SvrB;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signalapp/libsignal-client",
3
- "version": "0.77.0",
3
+ "version": "0.78.0",
4
4
  "license": "AGPL-3.0-only",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",