@signalapp/libsignal-client 0.46.2 → 0.48.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
@@ -407,6 +407,7 @@ export function ServerCertificate_GetKeyId(obj: Wrapper<ServerCertificate>): num
407
407
  export function ServerCertificate_GetSerialized(obj: Wrapper<ServerCertificate>): Buffer;
408
408
  export function ServerCertificate_GetSignature(obj: Wrapper<ServerCertificate>): Buffer;
409
409
  export function ServerCertificate_New(keyId: number, serverKey: Wrapper<PublicKey>, trustRoot: Wrapper<PrivateKey>): ServerCertificate;
410
+ export function ServerMessageAck_Send(asyncRuntime: Wrapper<TokioAsyncContext>, ack: Wrapper<ServerMessageAck>): Promise<void>;
410
411
  export function ServerPublicParams_CreateAuthCredentialWithPniPresentationDeterministic(serverPublicParams: Wrapper<ServerPublicParams>, randomness: Buffer, groupSecretParams: Serialized<GroupSecretParams>, authCredentialWithPniBytes: Buffer): Buffer;
411
412
  export function ServerPublicParams_CreateExpiringProfileKeyCredentialPresentationDeterministic(serverPublicParams: Wrapper<ServerPublicParams>, randomness: Buffer, groupSecretParams: Serialized<GroupSecretParams>, profileKeyCredential: Serialized<ExpiringProfileKeyCredential>): Buffer;
412
413
  export function ServerPublicParams_CreateProfileKeyCredentialRequestContextDeterministic(serverPublicParams: Wrapper<ServerPublicParams>, randomness: Buffer, userId: Buffer, profileKey: Serialized<ProfileKey>): Serialized<ProfileKeyCredentialRequestContext>;
@@ -467,6 +468,7 @@ export function SignedPreKeyRecord_GetTimestamp(obj: Wrapper<SignedPreKeyRecord>
467
468
  export function SignedPreKeyRecord_New(id: number, timestamp: Timestamp, pubKey: Wrapper<PublicKey>, privKey: Wrapper<PrivateKey>, signature: Buffer): SignedPreKeyRecord;
468
469
  export function SignedPreKeyRecord_Serialize(obj: Wrapper<SignedPreKeyRecord>): Buffer;
469
470
  export function Svr3Backup(asyncRuntime: Wrapper<TokioAsyncContext>, connectionManager: Wrapper<ConnectionManager>, secret: Buffer, password: string, maxTries: number, username: string, enclavePassword: string): Promise<Buffer>;
471
+ export function Svr3Remove(asyncRuntime: Wrapper<TokioAsyncContext>, connectionManager: Wrapper<ConnectionManager>, username: string, enclavePassword: string): Promise<void>;
470
472
  export function Svr3Restore(asyncRuntime: Wrapper<TokioAsyncContext>, connectionManager: Wrapper<ConnectionManager>, password: string, shareSet: Buffer, username: string, enclavePassword: string): Promise<Buffer>;
471
473
  export function TESTING_CdsiLookupErrorConvert(errorDescription: string): void;
472
474
  export function TESTING_CdsiLookupResponseConvert(asyncRuntime: Wrapper<TokioAsyncContext>): Promise<LookupResponse>;
@@ -475,10 +477,10 @@ export function TESTING_ChatRequestGetHeaderValue(request: Wrapper<HttpRequest>,
475
477
  export function TESTING_ChatRequestGetMethod(request: Wrapper<HttpRequest>): string;
476
478
  export function TESTING_ChatRequestGetPath(request: Wrapper<HttpRequest>): string;
477
479
  export function TESTING_ChatServiceDebugInfoConvert(): ChatServiceDebugInfo;
478
- export function TESTING_ChatServiceErrorConvert(): void;
479
- export function TESTING_ChatServiceInactiveErrorConvert(): void;
480
+ export function TESTING_ChatServiceErrorConvert(errorDescription: string): void;
480
481
  export function TESTING_ChatServiceResponseAndDebugInfoConvert(): ResponseAndDebugInfo;
481
482
  export function TESTING_ChatServiceResponseConvert(bodyPresent: boolean): ChatResponse;
483
+ export function TESTING_ChatService_InjectRawServerRequest(chat: Wrapper<Chat>, bytes: Buffer): void;
482
484
  export function TESTING_ErrorOnBorrowAsync(_input: null): Promise<void>;
483
485
  export function TESTING_ErrorOnBorrowIo(asyncRuntime: Wrapper<NonSuspendingBackgroundThreadRuntime>, _input: null): Promise<void>;
484
486
  export function TESTING_ErrorOnBorrowSync(_input: null): void;
@@ -490,6 +492,7 @@ export function TESTING_FutureProducesOtherPointerType(asyncRuntime: Wrapper<Non
490
492
  export function TESTING_FutureProducesPointerType(asyncRuntime: Wrapper<NonSuspendingBackgroundThreadRuntime>, input: number): Promise<TestingHandleType>;
491
493
  export function TESTING_FutureSuccess(asyncRuntime: Wrapper<NonSuspendingBackgroundThreadRuntime>, input: number): Promise<number>;
492
494
  export function TESTING_NonSuspendingBackgroundThreadRuntime_New(): NonSuspendingBackgroundThreadRuntime;
495
+ export function TESTING_OnlyCompletesByCancellation(asyncRuntime: Wrapper<TokioAsyncContext>): Promise<void>;
493
496
  export function TESTING_OtherTestingHandleType_getValue(handle: Wrapper<OtherTestingHandleType>): string;
494
497
  export function TESTING_PanicInBodyAsync(_input: null): Promise<void>;
495
498
  export function TESTING_PanicInBodyIo(asyncRuntime: Wrapper<NonSuspendingBackgroundThreadRuntime>, _input: null): Promise<void>;
@@ -506,6 +509,7 @@ export function TESTING_PanicOnReturnSync(_needsCleanup: null): null;
506
509
  export function TESTING_ProcessBytestringArray(input: Buffer[]): Buffer[];
507
510
  export function TESTING_ReturnStringArray(): string[];
508
511
  export function TESTING_TestingHandleType_getValue(handle: Wrapper<TestingHandleType>): number;
512
+ export function TokioAsyncContext_cancel(context: Wrapper<TokioAsyncContext>, rawCancellationId: bigint): void;
509
513
  export function TokioAsyncContext_new(): TokioAsyncContext;
510
514
  export function UnidentifiedSenderMessageContent_Deserialize(data: Buffer): UnidentifiedSenderMessageContent;
511
515
  export function UnidentifiedSenderMessageContent_GetContentHint(m: Wrapper<UnidentifiedSenderMessageContent>): number;
@@ -575,6 +579,7 @@ interface SenderKeyDistributionMessage { readonly __type: unique symbol; }
575
579
  interface SenderKeyMessage { readonly __type: unique symbol; }
576
580
  interface SenderKeyRecord { readonly __type: unique symbol; }
577
581
  interface ServerCertificate { readonly __type: unique symbol; }
582
+ interface ServerMessageAck { readonly __type: unique symbol; }
578
583
  interface ServerPublicParams { readonly __type: unique symbol; }
579
584
  interface ServerSecretParams { readonly __type: unique symbol; }
580
585
  interface SessionRecord { readonly __type: unique symbol; }
package/dist/Errors.d.ts CHANGED
@@ -33,7 +33,10 @@ export declare enum ErrorCode {
33
33
  SvrDataMissing = 29,
34
34
  SvrRequestFailed = 30,
35
35
  SvrRestoreFailed = 31,
36
- ChatServiceInactive = 32
36
+ ChatServiceInactive = 32,
37
+ AppExpired = 33,
38
+ DeviceDelinked = 34,
39
+ Cancelled = 35
37
40
  }
38
41
  export declare class LibSignalErrorBase extends Error {
39
42
  readonly code: ErrorCode;
@@ -137,6 +140,12 @@ export type RateLimitedError = LibSignalErrorBase & {
137
140
  export type ChatServiceInactive = LibSignalErrorBase & {
138
141
  code: ErrorCode.ChatServiceInactive;
139
142
  };
143
+ export type AppExpiredError = LibSignalErrorBase & {
144
+ code: ErrorCode.AppExpired;
145
+ };
146
+ export type DeviceDelinkedError = LibSignalErrorBase & {
147
+ code: ErrorCode.DeviceDelinked;
148
+ };
140
149
  export type SvrDataMissingError = LibSignalErrorBase & {
141
150
  code: ErrorCode.SvrDataMissing;
142
151
  };
@@ -145,5 +154,9 @@ export type SvrRequestFailedError = LibSignalErrorCommon & {
145
154
  };
146
155
  export type SvrRestoreFailedError = LibSignalErrorCommon & {
147
156
  code: ErrorCode.SvrRestoreFailed;
157
+ readonly triesRemaining: number;
158
+ };
159
+ export type CancellationError = LibSignalErrorCommon & {
160
+ code: ErrorCode.Cancelled;
148
161
  };
149
- export type LibSignalError = GenericError | DuplicatedMessageError | SealedSenderSelfSendError | UntrustedIdentityError | InvalidRegistrationIdError | VerificationFailedError | InvalidSessionError | InvalidSenderKeySessionError | NicknameCannotBeEmptyError | CannotStartWithDigitError | MissingSeparatorError | BadNicknameCharacterError | NicknameTooShortError | NicknameTooLongError | DiscriminatorCannotBeEmptyError | DiscriminatorCannotBeZeroError | DiscriminatorCannotBeSingleDigitError | DiscriminatorCannotHaveLeadingZerosError | BadDiscriminatorCharacterError | DiscriminatorTooLargeError | InputDataTooLong | InvalidEntropyDataLength | InvalidUsernameLinkEncryptedData | IoError | CdsiInvalidTokenError | InvalidUriError | InvalidMediaInputError | SvrDataMissingError | SvrRestoreFailedError | SvrRequestFailedError | UnsupportedMediaInputError | ChatServiceInactive;
162
+ export type LibSignalError = GenericError | DuplicatedMessageError | SealedSenderSelfSendError | UntrustedIdentityError | InvalidRegistrationIdError | VerificationFailedError | InvalidSessionError | InvalidSenderKeySessionError | NicknameCannotBeEmptyError | CannotStartWithDigitError | MissingSeparatorError | BadNicknameCharacterError | NicknameTooShortError | NicknameTooLongError | DiscriminatorCannotBeEmptyError | DiscriminatorCannotBeZeroError | DiscriminatorCannotBeSingleDigitError | DiscriminatorCannotHaveLeadingZerosError | BadDiscriminatorCharacterError | DiscriminatorTooLargeError | InputDataTooLong | InvalidEntropyDataLength | InvalidUsernameLinkEncryptedData | IoError | CdsiInvalidTokenError | InvalidUriError | InvalidMediaInputError | SvrDataMissingError | SvrRestoreFailedError | SvrRequestFailedError | UnsupportedMediaInputError | ChatServiceInactive | AppExpiredError | DeviceDelinkedError | CancellationError;
package/dist/Errors.js CHANGED
@@ -41,6 +41,9 @@ var ErrorCode;
41
41
  ErrorCode[ErrorCode["SvrRequestFailed"] = 30] = "SvrRequestFailed";
42
42
  ErrorCode[ErrorCode["SvrRestoreFailed"] = 31] = "SvrRestoreFailed";
43
43
  ErrorCode[ErrorCode["ChatServiceInactive"] = 32] = "ChatServiceInactive";
44
+ ErrorCode[ErrorCode["AppExpired"] = 33] = "AppExpired";
45
+ ErrorCode[ErrorCode["DeviceDelinked"] = 34] = "DeviceDelinked";
46
+ ErrorCode[ErrorCode["Cancelled"] = 35] = "Cancelled";
44
47
  })(ErrorCode = exports.ErrorCode || (exports.ErrorCode = {}));
45
48
  class LibSignalErrorBase extends Error {
46
49
  constructor(message, name, operation, extraProps) {
@@ -669,7 +669,7 @@ For more information on this, and how to apply and follow the GNU AGPL, see
669
669
 
670
670
  ```
671
671
 
672
- ## attest 0.1.0, device-transfer 0.1.0, libsignal-bridge 0.1.0, libsignal-bridge-macros 0.1.0, libsignal-core 0.1.0, libsignal-ffi 0.46.2, libsignal-jni 0.46.2, libsignal-message-backup 0.1.0, libsignal-message-backup-io 0.1.0, libsignal-message-backup-macros 0.1.0, libsignal-net 0.1.0, libsignal-node 0.46.2, libsignal-protocol 0.1.0, libsignal-svr3 0.1.0, poksho 0.7.0, signal-crypto 0.1.0, signal-media 0.1.0, signal-neon-futures 0.1.0, signal-neon-futures-tests 0.1.0, signal-pin 0.1.0, usernames 0.1.0, zkcredential 0.1.0, zkgroup 0.9.0
672
+ ## attest 0.1.0, device-transfer 0.1.0, libsignal-bridge 0.1.0, libsignal-bridge-macros 0.1.0, libsignal-core 0.1.0, libsignal-ffi 0.48.0, libsignal-jni 0.48.0, libsignal-message-backup 0.1.0, libsignal-message-backup-macros 0.1.0, libsignal-net 0.1.0, libsignal-node 0.48.0, libsignal-protocol 0.1.0, libsignal-svr3 0.1.0, poksho 0.7.0, signal-crypto 0.1.0, signal-media 0.1.0, signal-neon-futures 0.1.0, signal-neon-futures-tests 0.1.0, signal-pin 0.1.0, usernames 0.1.0, zkcredential 0.1.0, zkgroup 0.9.0
673
673
 
674
674
  ```
675
675
  GNU AFFERO GENERAL PUBLIC LICENSE
@@ -4454,7 +4454,7 @@ DEALINGS IN THE SOFTWARE.
4454
4454
 
4455
4455
  ```
4456
4456
 
4457
- ## smallvec 1.13.1
4457
+ ## smallvec 1.13.2
4458
4458
 
4459
4459
  ```
4460
4460
  Copyright (c) 2018 The Servo Project Developers
@@ -6830,6 +6830,39 @@ SOFTWARE.
6830
6830
 
6831
6831
  ```
6832
6832
 
6833
+ ## atomic-take 1.1.0
6834
+
6835
+ ```
6836
+ The MIT License (MIT)
6837
+
6838
+ Copyright (c) 2019 Alice Ryhl
6839
+
6840
+ Permission is hereby granted, free of charge, to any
6841
+ person obtaining a copy of this software and associated
6842
+ documentation files (the "Software"), to deal in the
6843
+ Software without restriction, including without
6844
+ limitation the rights to use, copy, modify, merge,
6845
+ publish, distribute, sublicense, and/or sell copies of
6846
+ the Software, and to permit persons to whom the Software
6847
+ is furnished to do so, subject to the following
6848
+ conditions:
6849
+
6850
+ The above copyright notice and this permission notice
6851
+ shall be included in all copies or substantial portions
6852
+ of the Software.
6853
+
6854
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
6855
+ ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
6856
+ TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
6857
+ PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
6858
+ SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
6859
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
6860
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
6861
+ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
6862
+ DEALINGS IN THE SOFTWARE.
6863
+
6864
+ ```
6865
+
6833
6866
  ## crossbeam-deque 0.8.5, crossbeam-epoch 0.9.18, crossbeam-utils 0.8.19
6834
6867
 
6835
6868
  ```
package/dist/net.d.ts CHANGED
@@ -17,6 +17,7 @@ export type CDSRequestOptionsType = {
17
17
  accessKey: string;
18
18
  }>;
19
19
  returnAcisWithoutUaks: boolean;
20
+ abortSignal?: AbortSignal;
20
21
  };
21
22
  export type CDSResponseEntryType<Aci, Pni> = {
22
23
  aci: Aci | undefined;
@@ -34,8 +35,13 @@ export type ChatRequest = Readonly<{
34
35
  body?: Uint8Array;
35
36
  timeoutMillis?: number;
36
37
  }>;
37
- type TokioAsyncContext = Wrapper<Native.TokioAsyncContext>;
38
38
  type ConnectionManager = Wrapper<Native.ConnectionManager>;
39
+ /** Low-level async runtime control, mostly just exported for testing. */
40
+ export declare class TokioAsyncContext {
41
+ readonly _nativeHandle: Native.TokioAsyncContext;
42
+ constructor(handle: Native.TokioAsyncContext);
43
+ makeCancellable<T>(abortSignal: AbortSignal | undefined, promise: Promise<T>): Promise<T>;
44
+ }
39
45
  /**
40
46
  * Provides API methods to connect and communicate with the Chat Service.
41
47
  * Before using either authenticated or unauthenticated channels,
@@ -60,8 +66,13 @@ export declare class ChatService {
60
66
  * the service is connected, all the requests will be using the established connection. Also, if
61
67
  * the connection is lost for any reason other than the call to {@link #disconnect()}, an
62
68
  * automatic reconnect attempt will be made.
69
+ *
70
+ * @throws {AppExpiredError} if the current app version is too old (as judged by the server).
71
+ * @throws {LibSignalError} with other codes for other failures.
63
72
  */
64
- connectUnauthenticated(): Promise<Native.ChatServiceDebugInfo>;
73
+ connectUnauthenticated(options?: {
74
+ abortSignal?: AbortSignal;
75
+ }): Promise<Native.ChatServiceDebugInfo>;
65
76
  /**
66
77
  * Initiates establishing of the underlying authenticated connection to the Chat Service. Once the
67
78
  * service is connected, all the requests will be using the established connection. Also, if the
@@ -69,8 +80,14 @@ export declare class ChatService {
69
80
  * reconnect attempt will be made.
70
81
  *
71
82
  * Calling this method will result in starting to accept incoming requests from the Chat Service.
83
+ *
84
+ * @throws {AppExpiredError} if the current app version is too old (as judged by the server).
85
+ * @throws {DeviceDelinkedError} if the current device has been delinked.
86
+ * @throws {LibSignalError} with other codes for other failures.
72
87
  */
73
- connectAuthenticated(): Promise<Native.ChatServiceDebugInfo>;
88
+ connectAuthenticated(options?: {
89
+ abortSignal?: AbortSignal;
90
+ }): Promise<Native.ChatServiceDebugInfo>;
74
91
  /**
75
92
  * Sends request to the Chat Service over an unauthenticated channel.
76
93
  *
@@ -80,14 +97,18 @@ export declare class ChatService {
80
97
  * @throws {ChatServiceInactive} if you haven't called {@link #connectUnauthenticated()} (as a
81
98
  * rejection of the promise).
82
99
  */
83
- unauthenticatedFetchAndDebug(chatRequest: ChatRequest): Promise<Native.ResponseAndDebugInfo>;
100
+ unauthenticatedFetchAndDebug(chatRequest: ChatRequest, options?: {
101
+ abortSignal?: AbortSignal;
102
+ }): Promise<Native.ResponseAndDebugInfo>;
84
103
  /**
85
104
  * Sends request to the Chat Service over an unauthenticated channel.
86
105
  *
87
106
  * @throws {ChatServiceInactive} if you haven't called {@link #connectUnauthenticated()} (as a
88
107
  * rejection of the promise).
89
108
  */
90
- unauthenticatedFetch(chatRequest: ChatRequest): Promise<Native.ChatResponse>;
109
+ unauthenticatedFetch(chatRequest: ChatRequest, options?: {
110
+ abortSignal?: AbortSignal;
111
+ }): Promise<Native.ChatResponse>;
91
112
  /**
92
113
  * Sends request to the Chat Service over an authenticated channel.
93
114
  *
@@ -97,14 +118,18 @@ export declare class ChatService {
97
118
  * @throws {ChatServiceInactive} if you haven't called {@link #connectAuthenticated()} (as a
98
119
  * rejection of the promise).
99
120
  */
100
- authenticatedFetchAndDebug(chatRequest: ChatRequest): Promise<Native.ResponseAndDebugInfo>;
121
+ authenticatedFetchAndDebug(chatRequest: ChatRequest, options?: {
122
+ abortSignal?: AbortSignal;
123
+ }): Promise<Native.ResponseAndDebugInfo>;
101
124
  /**
102
125
  * Sends request to the Chat Service over an authenticated channel.
103
126
  *
104
127
  * @throws {ChatServiceInactive} if you haven't called {@link #connectAuthenticated()} (as a
105
128
  * rejection of the promise).
106
129
  */
107
- authenticatedFetch(chatRequest: ChatRequest): Promise<Native.ChatResponse>;
130
+ authenticatedFetch(chatRequest: ChatRequest, options?: {
131
+ abortSignal?: AbortSignal;
132
+ }): Promise<Native.ChatResponse>;
108
133
  static buildHttpRequest(chatRequest: ChatRequest): {
109
134
  _nativeHandle: Native.HttpRequest;
110
135
  };
@@ -144,7 +169,7 @@ export declare class Net {
144
169
  * method is a no-op.
145
170
  */
146
171
  clearProxy(): void;
147
- cdsiLookup({ username, password }: Readonly<ServiceAuth>, { e164s, acisAndAccessKeys, returnAcisWithoutUaks, }: ReadonlyDeep<CDSRequestOptionsType>): Promise<CDSResponseType<string, string>>;
172
+ cdsiLookup({ username, password }: Readonly<ServiceAuth>, { e164s, acisAndAccessKeys, returnAcisWithoutUaks, abortSignal, }: ReadonlyDeep<CDSRequestOptionsType>): Promise<CDSResponseType<string, string>>;
148
173
  }
149
174
  /**
150
175
  * This interface provides functionality for communicating with SVR3
@@ -170,8 +195,7 @@ export interface Svr3Client {
170
195
  /**
171
196
  * Backup a secret to SVR3.
172
197
  *
173
- * Error messages are expected to be log-safe and not contain any sensitive
174
- * data.
198
+ * Error messages are log-safe and do not contain any sensitive data.
175
199
  *
176
200
  * @param what - The secret to be stored. Must be 32 bytes long.
177
201
  * @param password - User-provided password that will be used to derive the
@@ -200,12 +224,13 @@ export interface Svr3Client {
200
224
  * are therefore non-actionable and are guaranteed to be thrown again when
201
225
  * retried.
202
226
  */
203
- backup(what: Buffer, password: string, maxTries: number, auth: Readonly<ServiceAuth>): Promise<Buffer>;
227
+ backup(what: Buffer, password: string, maxTries: number, auth: Readonly<ServiceAuth>, options?: {
228
+ abortSignal?: AbortSignal;
229
+ }): Promise<Buffer>;
204
230
  /**
205
231
  * Restore a secret from SVR3.
206
232
  *
207
- * Error messages are expected to be log-safe and not contain any sensitive
208
- * data.
233
+ * Error messages are log-safe and do not contain any sensitive data.
209
234
  *
210
235
  * @param password - User-provided password that will be used to derive the
211
236
  * decryption key for the secret.
@@ -216,8 +241,8 @@ export interface Svr3Client {
216
241
  * generally good for about 15 minutes, therefore it can be reused for the
217
242
  * subsequent calls to either backup or restore that are not too far apart in
218
243
  * time.
219
- * @returns A `Promise` which--when awaited--will return a byte array with the
220
- * restored secret.
244
+ * @returns A `Promise` which--when awaited--will return a
245
+ * {@link RestoredSecret} object, containing the restored secret.
221
246
  *
222
247
  * The returned `Promise` can also fail due to the network issues (including
223
248
  * the connection timeout), problems establishing the Noise connection to the
@@ -237,6 +262,45 @@ export interface Svr3Client {
237
262
  * masked share set fails, or when the server requests fail for reasons
238
263
  * other than "maximum attempts exceeded".
239
264
  */
240
- restore(password: string, shareSet: Buffer, auth: Readonly<ServiceAuth>): Promise<Buffer>;
265
+ restore(password: string, shareSet: Buffer, auth: Readonly<ServiceAuth>, options?: {
266
+ abortSignal?: AbortSignal;
267
+ }): Promise<RestoredSecret>;
268
+ /**
269
+ * Remove a value stored in SVR3.
270
+ *
271
+ * This method will succeed even if the data has never been backed up in the
272
+ * first place.
273
+ *
274
+ * Error messages are log-safe and do not contain any sensitive data.
275
+ *
276
+ * @param auth - An instance of {@link ServiceAuth} containing the username
277
+ * and password obtained from the Chat Server. The password is an OTP which is
278
+ * generally good for about 15 minutes, therefore it can be reused for the
279
+ * subsequent calls to either backup or restore that are not too far apart in
280
+ * time.
281
+ * @returns A `Promise` successful completion of which will mean the data has
282
+ * been removed.
283
+ *
284
+ * The returned `Promise` can also fail due to the network issues (including
285
+ * the connection timeout), problems establishing the Noise connection to the
286
+ * enclaves, or invalid arguments' values. {@link IoError} errors can, in
287
+ * general, be retried, although there is already a retry-with-backoff
288
+ * mechanism inside libsignal used to connect to the SVR3 servers. Other
289
+ * exceptions are caused by the bad input or data missing on the server. They
290
+ * are therefore non-actionable and are guaranteed to be thrown again when
291
+ * retried.
292
+ */
293
+ remove(auth: Readonly<ServiceAuth>, options?: {
294
+ abortSignal?: AbortSignal;
295
+ }): Promise<void>;
296
+ }
297
+ /**
298
+ * A simple data class containing the secret restored from SVR3 as well as the
299
+ * number of restore attempts remaining.
300
+ */
301
+ export declare class RestoredSecret {
302
+ readonly triesRemaining: number;
303
+ readonly value: Buffer;
304
+ constructor(serialized: Buffer);
241
305
  }
242
306
  export {};
package/dist/net.js CHANGED
@@ -4,7 +4,7 @@
4
4
  // SPDX-License-Identifier: AGPL-3.0-only
5
5
  //
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.Net = exports.ChatService = exports.Environment = void 0;
7
+ exports.RestoredSecret = exports.Net = exports.ChatService = exports.TokioAsyncContext = exports.Environment = void 0;
8
8
  const Native = require("../Native");
9
9
  const Address_1 = require("./Address");
10
10
  const DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS = 5000;
@@ -19,6 +19,30 @@ function newNativeHandle(handle) {
19
19
  _nativeHandle: handle,
20
20
  };
21
21
  }
22
+ /** Low-level async runtime control, mostly just exported for testing. */
23
+ class TokioAsyncContext {
24
+ constructor(handle) {
25
+ this._nativeHandle = handle;
26
+ }
27
+ makeCancellable(abortSignal, promise) {
28
+ if (abortSignal !== undefined &&
29
+ '_cancellationToken' in promise &&
30
+ typeof promise._cancellationToken === 'bigint') {
31
+ const cancellationToken = promise._cancellationToken;
32
+ const cancel = () => {
33
+ Native.TokioAsyncContext_cancel(this, cancellationToken);
34
+ };
35
+ if (abortSignal.aborted) {
36
+ cancel();
37
+ }
38
+ else {
39
+ abortSignal.addEventListener('abort', cancel);
40
+ }
41
+ }
42
+ return promise;
43
+ }
44
+ }
45
+ exports.TokioAsyncContext = TokioAsyncContext;
22
46
  /**
23
47
  * Provides API methods to connect and communicate with the Chat Service.
24
48
  * Before using either authenticated or unauthenticated channels,
@@ -38,17 +62,20 @@ class ChatService {
38
62
  * Note: the same instance of `ChatService` can be reused after `disconnect()` was
39
63
  * called.
40
64
  */
41
- async disconnect() {
42
- await Native.ChatService_disconnect(this.asyncContext, this.chatService);
65
+ disconnect() {
66
+ return Native.ChatService_disconnect(this.asyncContext, this.chatService);
43
67
  }
44
68
  /**
45
69
  * Initiates establishing of the underlying unauthenticated connection to the Chat Service. Once
46
70
  * the service is connected, all the requests will be using the established connection. Also, if
47
71
  * the connection is lost for any reason other than the call to {@link #disconnect()}, an
48
72
  * automatic reconnect attempt will be made.
73
+ *
74
+ * @throws {AppExpiredError} if the current app version is too old (as judged by the server).
75
+ * @throws {LibSignalError} with other codes for other failures.
49
76
  */
50
- async connectUnauthenticated() {
51
- return await Native.ChatService_connect_unauth(this.asyncContext, this.chatService);
77
+ connectUnauthenticated(options) {
78
+ return this.asyncContext.makeCancellable(options?.abortSignal, Native.ChatService_connect_unauth(this.asyncContext, this.chatService));
52
79
  }
53
80
  /**
54
81
  * Initiates establishing of the underlying authenticated connection to the Chat Service. Once the
@@ -57,9 +84,13 @@ class ChatService {
57
84
  * reconnect attempt will be made.
58
85
  *
59
86
  * Calling this method will result in starting to accept incoming requests from the Chat Service.
87
+ *
88
+ * @throws {AppExpiredError} if the current app version is too old (as judged by the server).
89
+ * @throws {DeviceDelinkedError} if the current device has been delinked.
90
+ * @throws {LibSignalError} with other codes for other failures.
60
91
  */
61
- async connectAuthenticated() {
62
- return await Native.ChatService_connect_auth(this.asyncContext, this.chatService);
92
+ connectAuthenticated(options) {
93
+ return this.asyncContext.makeCancellable(options?.abortSignal, Native.ChatService_connect_auth(this.asyncContext, this.chatService));
63
94
  }
64
95
  /**
65
96
  * Sends request to the Chat Service over an unauthenticated channel.
@@ -70,8 +101,8 @@ class ChatService {
70
101
  * @throws {ChatServiceInactive} if you haven't called {@link #connectUnauthenticated()} (as a
71
102
  * rejection of the promise).
72
103
  */
73
- async unauthenticatedFetchAndDebug(chatRequest) {
74
- return await Native.ChatService_unauth_send_and_debug(this.asyncContext, this.chatService, ChatService.buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS);
104
+ unauthenticatedFetchAndDebug(chatRequest, options) {
105
+ return this.asyncContext.makeCancellable(options?.abortSignal, Native.ChatService_unauth_send_and_debug(this.asyncContext, this.chatService, ChatService.buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS));
75
106
  }
76
107
  /**
77
108
  * Sends request to the Chat Service over an unauthenticated channel.
@@ -79,8 +110,8 @@ class ChatService {
79
110
  * @throws {ChatServiceInactive} if you haven't called {@link #connectUnauthenticated()} (as a
80
111
  * rejection of the promise).
81
112
  */
82
- async unauthenticatedFetch(chatRequest) {
83
- return await Native.ChatService_unauth_send(this.asyncContext, this.chatService, ChatService.buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS);
113
+ unauthenticatedFetch(chatRequest, options) {
114
+ return this.asyncContext.makeCancellable(options?.abortSignal, Native.ChatService_unauth_send(this.asyncContext, this.chatService, ChatService.buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS));
84
115
  }
85
116
  /**
86
117
  * Sends request to the Chat Service over an authenticated channel.
@@ -91,8 +122,8 @@ class ChatService {
91
122
  * @throws {ChatServiceInactive} if you haven't called {@link #connectAuthenticated()} (as a
92
123
  * rejection of the promise).
93
124
  */
94
- async authenticatedFetchAndDebug(chatRequest) {
95
- return await Native.ChatService_auth_send_and_debug(this.asyncContext, this.chatService, ChatService.buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS);
125
+ authenticatedFetchAndDebug(chatRequest, options) {
126
+ return this.asyncContext.makeCancellable(options?.abortSignal, Native.ChatService_auth_send_and_debug(this.asyncContext, this.chatService, ChatService.buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS));
96
127
  }
97
128
  /**
98
129
  * Sends request to the Chat Service over an authenticated channel.
@@ -100,8 +131,8 @@ class ChatService {
100
131
  * @throws {ChatServiceInactive} if you haven't called {@link #connectAuthenticated()} (as a
101
132
  * rejection of the promise).
102
133
  */
103
- async authenticatedFetch(chatRequest) {
104
- return await Native.ChatService_auth_send(this.asyncContext, this.chatService, ChatService.buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS);
134
+ authenticatedFetch(chatRequest, options) {
135
+ return this.asyncContext.makeCancellable(options?.abortSignal, Native.ChatService_auth_send(this.asyncContext, this.chatService, ChatService.buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS));
105
136
  }
106
137
  static buildHttpRequest(chatRequest) {
107
138
  const { verb, path, body, headers } = chatRequest;
@@ -119,7 +150,7 @@ class ChatService {
119
150
  exports.ChatService = ChatService;
120
151
  class Net {
121
152
  constructor(env, userAgent) {
122
- this.asyncContext = newNativeHandle(Native.TokioAsyncContext_new());
153
+ this.asyncContext = new TokioAsyncContext(Native.TokioAsyncContext_new());
123
154
  this.connectionManager = newNativeHandle(Native.ConnectionManager_new(env, userAgent));
124
155
  this.svr3 = new Svr3ClientImpl(this.asyncContext, this.connectionManager);
125
156
  }
@@ -158,7 +189,7 @@ class Net {
158
189
  clearProxy() {
159
190
  Native.ConnectionManager_clear_proxy(this.connectionManager);
160
191
  }
161
- async cdsiLookup({ username, password }, { e164s, acisAndAccessKeys, returnAcisWithoutUaks, }) {
192
+ async cdsiLookup({ username, password }, { e164s, acisAndAccessKeys, returnAcisWithoutUaks, abortSignal, }) {
162
193
  const request = newNativeHandle(Native.LookupRequest_new());
163
194
  e164s.forEach((e164) => {
164
195
  Native.LookupRequest_addE164(request, e164);
@@ -167,21 +198,36 @@ class Net {
167
198
  Native.LookupRequest_addAciAndAccessKey(request, Address_1.Aci.parseFromServiceIdString(aciStr).getServiceIdFixedWidthBinary(), Buffer.from(accessKeyStr, 'base64'));
168
199
  });
169
200
  Native.LookupRequest_setReturnAcisWithoutUaks(request, returnAcisWithoutUaks);
170
- const lookup = await Native.CdsiLookup_new(this.asyncContext, this.connectionManager, username, password, request);
171
- return await Native.CdsiLookup_complete(this.asyncContext, newNativeHandle(lookup));
201
+ const lookup = await this.asyncContext.makeCancellable(abortSignal, Native.CdsiLookup_new(this.asyncContext, this.connectionManager, username, password, request));
202
+ return await this.asyncContext.makeCancellable(abortSignal, Native.CdsiLookup_complete(this.asyncContext, newNativeHandle(lookup)));
172
203
  }
173
204
  }
174
205
  exports.Net = Net;
206
+ /**
207
+ * A simple data class containing the secret restored from SVR3 as well as the
208
+ * number of restore attempts remaining.
209
+ */
210
+ class RestoredSecret {
211
+ constructor(serialized) {
212
+ this.triesRemaining = serialized.readInt32BE();
213
+ this.value = serialized.subarray(4);
214
+ }
215
+ }
216
+ exports.RestoredSecret = RestoredSecret;
175
217
  class Svr3ClientImpl {
176
218
  constructor(asyncContext, connectionManager) {
177
219
  this.asyncContext = asyncContext;
178
220
  this.connectionManager = connectionManager;
179
221
  }
180
- async backup(what, password, maxTries, auth) {
181
- return Native.Svr3Backup(this.asyncContext, this.connectionManager, what, password, maxTries, auth.username, auth.password);
222
+ async backup(what, password, maxTries, auth, options) {
223
+ return this.asyncContext.makeCancellable(options?.abortSignal, Native.Svr3Backup(this.asyncContext, this.connectionManager, what, password, maxTries, auth.username, auth.password));
224
+ }
225
+ async restore(password, shareSet, auth, options) {
226
+ const serialized = await this.asyncContext.makeCancellable(options?.abortSignal, Native.Svr3Restore(this.asyncContext, this.connectionManager, password, shareSet, auth.username, auth.password));
227
+ return new RestoredSecret(serialized);
182
228
  }
183
- async restore(password, shareSet, auth) {
184
- return Native.Svr3Restore(this.asyncContext, this.connectionManager, password, shareSet, auth.username, auth.password);
229
+ async remove(auth, options) {
230
+ return this.asyncContext.makeCancellable(options?.abortSignal, Native.Svr3Remove(this.asyncContext, this.connectionManager, auth.username, auth.password));
185
231
  }
186
232
  }
187
233
  //# sourceMappingURL=net.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signalapp/libsignal-client",
3
- "version": "0.46.2",
3
+ "version": "0.48.0",
4
4
  "license": "AGPL-3.0-only",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
Binary file
Binary file
Binary file