@signalapp/libsignal-client 0.65.4 → 0.65.6

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
@@ -233,8 +233,10 @@ export function ConnectionManager_clear_proxy(connectionManager: Wrapper<Connect
233
233
  export function ConnectionManager_new(environment: number, userAgent: string): ConnectionManager;
234
234
  export function ConnectionManager_on_network_change(connectionManager: Wrapper<ConnectionManager>): void;
235
235
  export function ConnectionManager_set_censorship_circumvention_enabled(connectionManager: Wrapper<ConnectionManager>, enabled: boolean): void;
236
+ export function ConnectionManager_set_invalid_proxy(connectionManager: Wrapper<ConnectionManager>): void;
236
237
  export function ConnectionManager_set_ipv6_enabled(connectionManager: Wrapper<ConnectionManager>, ipv6Enabled: boolean): void;
237
- export function ConnectionManager_set_proxy(connectionManager: Wrapper<ConnectionManager>, host: string, port: number): void;
238
+ export function ConnectionManager_set_proxy(connectionManager: Wrapper<ConnectionManager>, proxy: Wrapper<ConnectionProxyConfig>): void;
239
+ export function ConnectionProxyConfig_new(scheme: string, host: string, port: number, username: string | null, password: string | null): ConnectionProxyConfig;
238
240
  export function CreateCallLinkCredentialPresentation_CheckValidContents(presentationBytes: Buffer): void;
239
241
  export function CreateCallLinkCredentialPresentation_Verify(presentationBytes: Buffer, roomId: Buffer, now: Timestamp, serverParamsBytes: Buffer, callLinkParamsBytes: Buffer): void;
240
242
  export function CreateCallLinkCredentialRequestContext_CheckValidContents(contextBytes: Buffer): void;
@@ -537,6 +539,7 @@ export function TESTING_ChatServiceResponseConvert(bodyPresent: boolean): ChatRe
537
539
  export function TESTING_ChatService_InjectConnectionInterrupted(chat: Wrapper<AuthChat>): void;
538
540
  export function TESTING_ChatService_InjectIntentionalDisconnect(chat: Wrapper<AuthChat>): void;
539
541
  export function TESTING_ChatService_InjectRawServerRequest(chat: Wrapper<AuthChat>, bytes: Buffer): void;
542
+ export function TESTING_ConnectionManager_isUsingProxy(manager: Wrapper<ConnectionManager>): number;
540
543
  export function TESTING_ConnectionManager_newLocalOverride(userAgent: string, chatPort: number, cdsiPort: number, svr2Port: number, svr3SgxPort: number, svr3NitroPort: number, svr3Tpm2SnpPort: number, rootCertificateDer: Buffer): ConnectionManager;
541
544
  export function TESTING_ErrorOnBorrowAsync(_input: null): Promise<void>;
542
545
  export function TESTING_ErrorOnBorrowIo(asyncRuntime: Wrapper<NonSuspendingBackgroundThreadRuntime>, _input: null): CancellablePromise<void>;
@@ -544,6 +547,11 @@ export function TESTING_ErrorOnBorrowSync(_input: null): void;
544
547
  export function TESTING_ErrorOnReturnAsync(_needsCleanup: null): Promise<null>;
545
548
  export function TESTING_ErrorOnReturnIo(asyncRuntime: Wrapper<NonSuspendingBackgroundThreadRuntime>, _needsCleanup: null): CancellablePromise<null>;
546
549
  export function TESTING_ErrorOnReturnSync(_needsCleanup: null): null;
550
+ export function TESTING_FakeChatConnection_Create(tokio: Wrapper<TokioAsyncContext>, listener: ChatListener): FakeChatConnection;
551
+ export function TESTING_FakeChatConnection_TakeAuthenticatedChat(chat: Wrapper<FakeChatConnection>): AuthenticatedChatConnection;
552
+ export function TESTING_FakeChatConnection_TakeRemote(chat: Wrapper<FakeChatConnection>): FakeChatRemoteEnd;
553
+ export function TESTING_FakeChatRemoteEnd_InjectConnectionInterrupted(chat: Wrapper<FakeChatRemoteEnd>): void;
554
+ export function TESTING_FakeChatRemoteEnd_SendRawServerRequest(chat: Wrapper<FakeChatRemoteEnd>, bytes: Buffer): void;
547
555
  export function TESTING_FutureFailure(asyncRuntime: Wrapper<NonSuspendingBackgroundThreadRuntime>, _input: number): CancellablePromise<number>;
548
556
  export function TESTING_FutureProducesOtherPointerType(asyncRuntime: Wrapper<NonSuspendingBackgroundThreadRuntime>, input: string): CancellablePromise<OtherTestingHandleType>;
549
557
  export function TESTING_FutureProducesPointerType(asyncRuntime: Wrapper<NonSuspendingBackgroundThreadRuntime>, input: number): CancellablePromise<TestingHandleType>;
@@ -566,6 +574,11 @@ export function TESTING_PanicOnReturnIo(asyncRuntime: Wrapper<NonSuspendingBackg
566
574
  export function TESTING_PanicOnReturnSync(_needsCleanup: null): null;
567
575
  export function TESTING_ProcessBytestringArray(input: Buffer[]): Buffer[];
568
576
  export function TESTING_ReturnStringArray(): string[];
577
+ export function TESTING_RoundTripI32(input: number): number;
578
+ export function TESTING_RoundTripU16(input: number): number;
579
+ export function TESTING_RoundTripU32(input: number): number;
580
+ export function TESTING_RoundTripU64(input: bigint): bigint;
581
+ export function TESTING_RoundTripU8(input: number): number;
569
582
  export function TESTING_ServerMessageAck_Create(): ServerMessageAck;
570
583
  export function TESTING_TestingHandleType_getValue(handle: Wrapper<TestingHandleType>): number;
571
584
  export function TokioAsyncContext_cancel(context: Wrapper<TokioAsyncContext>, rawCancellationId: bigint): void;
@@ -606,9 +619,12 @@ interface CiphertextMessage { readonly __type: unique symbol; }
606
619
  interface ComparableBackup { readonly __type: unique symbol; }
607
620
  interface ComparableBackup { readonly __type: unique symbol; }
608
621
  interface ConnectionManager { readonly __type: unique symbol; }
622
+ interface ConnectionProxyConfig { readonly __type: unique symbol; }
609
623
  interface DecryptionErrorMessage { readonly __type: unique symbol; }
610
624
  interface ExpiringProfileKeyCredential { readonly __type: unique symbol; }
611
625
  interface ExpiringProfileKeyCredentialResponse { readonly __type: unique symbol; }
626
+ interface FakeChatConnection { readonly __type: unique symbol; }
627
+ interface FakeChatRemoteEnd { readonly __type: unique symbol; }
612
628
  interface Fingerprint { readonly __type: unique symbol; }
613
629
  interface GroupMasterKey { readonly __type: unique symbol; }
614
630
  interface GroupPublicParams { readonly __type: unique symbol; }
@@ -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
- ## libsignal-account-keys, attest, libsignal-ffi, libsignal-jni, libsignal-jni-testing, libsignal-node, signal-neon-futures, signal-neon-futures-tests, libsignal-bridge, libsignal-bridge-macros, libsignal-bridge-testing, libsignal-bridge-types, libsignal-core, signal-crypto, device-transfer, libsignal-keytrans, signal-media, libsignal-message-backup, libsignal-message-backup-macros, libsignal-net, libsignal-net-infra, poksho, libsignal-protocol, libsignal-svr3, usernames, zkcredential, zkgroup
672
+ ## libsignal-account-keys, attest, libsignal-ffi, libsignal-jni, libsignal-jni-impl, libsignal-jni-testing, libsignal-node, signal-neon-futures, signal-neon-futures-tests, libsignal-bridge, libsignal-bridge-macros, libsignal-bridge-testing, libsignal-bridge-types, libsignal-core, signal-crypto, device-transfer, libsignal-keytrans, signal-media, libsignal-message-backup, libsignal-message-backup-macros, libsignal-net, libsignal-net-infra, poksho, libsignal-protocol, libsignal-svr3, usernames, zkcredential, zkgroup
673
673
 
674
674
  ```
675
675
  GNU AFFERO GENERAL PUBLIC LICENSE
@@ -5974,7 +5974,7 @@ SOFTWARE.
5974
5974
 
5975
5975
  ```
5976
5976
 
5977
- ## mediasan-common 0.5.1, mp4san-derive 0.5.1, mp4san 0.5.1, webpsan 0.5.1
5977
+ ## mediasan-common 0.5.3, mp4san-derive 0.5.3, mp4san 0.5.3, webpsan 0.5.3
5978
5978
 
5979
5979
  ```
5980
5980
  Copyright (c) 2022 jessa0
@@ -6512,7 +6512,7 @@ SOFTWARE.
6512
6512
 
6513
6513
  ```
6514
6514
 
6515
- ## darling 0.14.4, darling_core 0.14.4, darling_macro 0.14.4
6515
+ ## darling 0.20.10, darling_core 0.20.10, darling_macro 0.20.10
6516
6516
 
6517
6517
  ```
6518
6518
  MIT License
@@ -7277,7 +7277,7 @@ THE SOFTWARE.
7277
7277
 
7278
7278
  ```
7279
7279
 
7280
- ## strsim 0.10.0, strsim 0.11.1
7280
+ ## strsim 0.11.1
7281
7281
 
7282
7282
  ```
7283
7283
  The MIT License (MIT)
@@ -7496,7 +7496,7 @@ SOFTWARE.
7496
7496
 
7497
7497
  ```
7498
7498
 
7499
- ## derive_builder 0.12.0, derive_builder_core 0.12.0, derive_builder_macro 0.12.0
7499
+ ## derive_builder 0.20.2, derive_builder_core 0.20.2, derive_builder_macro 0.20.2
7500
7500
 
7501
7501
  ```
7502
7502
  The MIT License (MIT)
package/dist/net.d.ts CHANGED
@@ -185,6 +185,15 @@ export declare class AuthenticatedChatConnection implements ChatConnection {
185
185
  static connect(asyncContext: TokioAsyncContext, connectionManager: ConnectionManager, username: string, password: string, receiveStories: boolean, listener: ChatServiceListener, options?: {
186
186
  abortSignal?: AbortSignal;
187
187
  }): Promise<AuthenticatedChatConnection>;
188
+ /**
189
+ * Creates a chat connection backed by a fake remote end.
190
+ *
191
+ * @param asyncContext the async runtime to use
192
+ * @param listener the listener to send events to
193
+ * @returns an {@link AuthenticatedChatConnection} and handle for the remote
194
+ * end of the fake connection.
195
+ */
196
+ static fakeConnect(asyncContext: TokioAsyncContext, listener: ChatServiceListener): [AuthenticatedChatConnection, Wrapper<Native.FakeChatRemoteEnd>];
188
197
  private constructor();
189
198
  fetch(chatRequest: ChatRequest, options?: {
190
199
  abortSignal?: AbortSignal;
@@ -244,9 +253,20 @@ export type NetConstructorOptions = Readonly<{
244
253
  TESTING_localServer_svr3Tpm2SnpPort: number;
245
254
  TESTING_localServer_rootCertificateDer: Buffer;
246
255
  }>;
256
+ /** See {@link Net.setProxy()}. */
257
+ export type ProxyOptions = {
258
+ scheme: string;
259
+ host: string;
260
+ port?: number;
261
+ username?: string;
262
+ password?: string;
263
+ };
264
+ /** The "scheme" for Signal TLS proxies. See {@link Net.setProxy()}. */
265
+ export declare const SIGNAL_TLS_PROXY_SCHEME = "org.signal.tls";
247
266
  export declare class Net {
248
267
  private readonly asyncContext;
249
- private readonly connectionManager;
268
+ /** Exposed only for testing. */
269
+ readonly _connectionManager: ConnectionManager;
250
270
  constructor(options: NetConstructorOptions);
251
271
  /**
252
272
  * Creates a new instance of {@link AuthenticatedChatService}.
@@ -298,18 +318,62 @@ export declare class Net {
298
318
  /**
299
319
  * Sets the proxy host to be used for all new connections (until overridden).
300
320
  *
301
- * Sets a domain name and port to be used to proxy all new outgoing
302
- * connections. The proxy can be overridden by calling this method again or
303
- * unset by calling {@link #clearProxy}.
321
+ * Sets a server to be used to proxy all new outgoing connections. The proxy can be overridden by
322
+ * calling this method again or unset by calling {@link #clearProxy}. Omitting the `port` means
323
+ * the default port for the scheme will be used.
324
+ *
325
+ * To specify a Signal transparent TLS proxy, use {@link SIGNAL_TLS_PROXY_SCHEME}, or the
326
+ * overload that takes a separate domain and port number.
327
+ *
328
+ * Throws if the scheme is unsupported or if the provided parameters are invalid for that scheme
329
+ * (e.g. Signal TLS proxies don't support authentication)
330
+ */
331
+ setProxy(options: Readonly<ProxyOptions>): void;
332
+ /**
333
+ * Sets the Signal TLS proxy host to be used for all new connections (until overridden).
334
+ *
335
+ * Sets a domain name and port to be used to proxy all new outgoing connections, using a Signal
336
+ * transparent TLS proxy. The proxy can be overridden by calling this method again or unset by
337
+ * calling {@link #clearProxy}.
304
338
  *
305
339
  * Throws if the host or port is structurally invalid, such as a port that doesn't fit in u16.
306
340
  */
307
- setProxy(host: string, port: number): void;
341
+ setProxy(host: string, port?: number): void;
342
+ /**
343
+ * Like {@link #setProxy}, but parses the proxy options from a URL. See there for more
344
+ * information.
345
+ *
346
+ * Takes a string rather than a URL so that an *invalid* string can result in disabling
347
+ * connections until {@link #clearProxy} is called, consistent with other ways {@link #setProxy}
348
+ * might consider its parameters invalid.
349
+ *
350
+ * Throws if the URL contains unnecessary parts (like a query string), or if the resulting options
351
+ * are not supported.
352
+ */
353
+ setProxyFromUrl(urlString: string): void;
354
+ /**
355
+ * Parses a proxy URL into an options object, suitable for passing to {@link #setProxy}.
356
+ *
357
+ * It is recommended not to call this directly. Instead, use {@link #setProxyFromUrl}, which will
358
+ * treat an invalid URL uniformly with one that is structurally valid but unsupported by
359
+ * libsignal.
360
+ *
361
+ * Throws if the URL is known to not be a valid proxy URL; however it's still possible the
362
+ * resulting options object cannot be used as a proxy.
363
+ */
364
+ static proxyOptionsFromUrl(urlString: string): ProxyOptions;
365
+ /**
366
+ * Refuses to make any new connections until a new proxy configuration is set or
367
+ * {@link #clearProxy} is called.
368
+ *
369
+ * Existing connections will not be affected.
370
+ */
371
+ setInvalidProxy(): void;
308
372
  /**
309
373
  * Ensures that future connections will be made directly, not through a proxy.
310
374
  *
311
- * Clears any proxy configuration set via {@link #setProxy}. If none was set, calling this
312
- * method is a no-op.
375
+ * Clears any proxy configuration set via {@link #setProxy} or {@link #setInvalidProxy}. If none
376
+ * was set, calling this method is a no-op.
313
377
  */
314
378
  clearProxy(): void;
315
379
  /**
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.buildHttpRequest = exports.UnauthenticatedChatService = exports.AuthenticatedChatService = exports.AuthenticatedChatConnection = exports.UnauthenticatedChatConnection = exports.ChatServerMessageAck = exports.TokioAsyncContext = exports.newNativeHandle = exports.Environment = void 0;
7
+ exports.Net = exports.SIGNAL_TLS_PROXY_SCHEME = exports.buildHttpRequest = exports.UnauthenticatedChatService = exports.AuthenticatedChatService = exports.AuthenticatedChatConnection = exports.UnauthenticatedChatConnection = exports.ChatServerMessageAck = exports.TokioAsyncContext = exports.newNativeHandle = exports.Environment = void 0;
8
8
  const Native = require("../Native");
9
9
  const Address_1 = require("./Address");
10
10
  const node_buffer_1 = require("node:buffer");
@@ -116,6 +116,23 @@ class AuthenticatedChatConnection {
116
116
  Native.AuthenticatedChatConnection_init_listener(connection, new WeakListenerWrapper(nativeChatListener));
117
117
  return new AuthenticatedChatConnection(asyncContext, connection, nativeChatListener);
118
118
  }
119
+ /**
120
+ * Creates a chat connection backed by a fake remote end.
121
+ *
122
+ * @param asyncContext the async runtime to use
123
+ * @param listener the listener to send events to
124
+ * @returns an {@link AuthenticatedChatConnection} and handle for the remote
125
+ * end of the fake connection.
126
+ */
127
+ static fakeConnect(asyncContext, listener) {
128
+ const nativeChatListener = makeNativeChatListener(asyncContext, listener);
129
+ const fakeChat = newNativeHandle(Native.TESTING_FakeChatConnection_Create(asyncContext, new WeakListenerWrapper(nativeChatListener)));
130
+ const chat = newNativeHandle(Native.TESTING_FakeChatConnection_TakeAuthenticatedChat(fakeChat));
131
+ return [
132
+ new AuthenticatedChatConnection(asyncContext, chat, nativeChatListener),
133
+ newNativeHandle(Native.TESTING_FakeChatConnection_TakeRemote(fakeChat)),
134
+ ];
135
+ }
119
136
  constructor(asyncContext, chatService,
120
137
  // Unused except to keep the listener alive since the Rust code only holds a
121
138
  // weak reference to the same object.
@@ -263,14 +280,16 @@ function buildHttpRequest(chatRequest) {
263
280
  return httpRequest;
264
281
  }
265
282
  exports.buildHttpRequest = buildHttpRequest;
283
+ /** The "scheme" for Signal TLS proxies. See {@link Net.setProxy()}. */
284
+ exports.SIGNAL_TLS_PROXY_SCHEME = 'org.signal.tls';
266
285
  class Net {
267
286
  constructor(options) {
268
287
  this.asyncContext = new TokioAsyncContext(Native.TokioAsyncContext_new());
269
288
  if (options.localTestServer) {
270
- this.connectionManager = newNativeHandle(Native.TESTING_ConnectionManager_newLocalOverride(options.userAgent, options.TESTING_localServer_chatPort, options.TESTING_localServer_cdsiPort, options.TESTING_localServer_svr2Port, options.TESTING_localServer_svr3SgxPort, options.TESTING_localServer_svr3NitroPort, options.TESTING_localServer_svr3Tpm2SnpPort, options.TESTING_localServer_rootCertificateDer));
289
+ this._connectionManager = newNativeHandle(Native.TESTING_ConnectionManager_newLocalOverride(options.userAgent, options.TESTING_localServer_chatPort, options.TESTING_localServer_cdsiPort, options.TESTING_localServer_svr2Port, options.TESTING_localServer_svr3SgxPort, options.TESTING_localServer_svr3NitroPort, options.TESTING_localServer_svr3Tpm2SnpPort, options.TESTING_localServer_rootCertificateDer));
271
290
  }
272
291
  else {
273
- this.connectionManager = newNativeHandle(Native.ConnectionManager_new(options.env, options.userAgent));
292
+ this._connectionManager = newNativeHandle(Native.ConnectionManager_new(options.env, options.userAgent));
274
293
  }
275
294
  }
276
295
  /**
@@ -282,13 +301,13 @@ class Net {
282
301
  * to eventually break it (either using a weak reference or by assigning over the strong reference).
283
302
  */
284
303
  newAuthenticatedChatService(username, password, receiveStories, listener) {
285
- return new AuthenticatedChatService(this.asyncContext, this.connectionManager, username, password, receiveStories, listener);
304
+ return new AuthenticatedChatService(this.asyncContext, this._connectionManager, username, password, receiveStories, listener);
286
305
  }
287
306
  /**
288
307
  * Creates a new instance of {@link UnauthenticatedChatService}.
289
308
  */
290
309
  newUnauthenticatedChatService(listener) {
291
- return new UnauthenticatedChatService(this.asyncContext, this.connectionManager, listener);
310
+ return new UnauthenticatedChatService(this.asyncContext, this._connectionManager, listener);
292
311
  }
293
312
  /**
294
313
  *
@@ -299,13 +318,13 @@ class Net {
299
318
  * @returns the connected listener, if the connection succeeds.
300
319
  */
301
320
  async connectUnauthenticatedChat(listener, options) {
302
- return UnauthenticatedChatConnection.connect(this.asyncContext, this.connectionManager, listener, options);
321
+ return UnauthenticatedChatConnection.connect(this.asyncContext, this._connectionManager, listener, options);
303
322
  }
304
323
  /**
305
324
  * Creates a new instance of {@link AuthenticatedChatConnection}.
306
325
  */
307
326
  connectAuthenticatedChat(username, password, receiveStories, listener, options) {
308
- return AuthenticatedChatConnection.connect(this.asyncContext, this.connectionManager, username, password, receiveStories, listener, options);
327
+ return AuthenticatedChatConnection.connect(this.asyncContext, this._connectionManager, username, password, receiveStories, listener, options);
309
328
  }
310
329
  /**
311
330
  * Enables/disables IPv6 for all new connections (until changed).
@@ -313,7 +332,7 @@ class Net {
313
332
  * The flag is `true` by default.
314
333
  */
315
334
  setIpv6Enabled(ipv6Enabled) {
316
- Native.ConnectionManager_set_ipv6_enabled(this.connectionManager, ipv6Enabled);
335
+ Native.ConnectionManager_set_ipv6_enabled(this._connectionManager, ipv6Enabled);
317
336
  }
318
337
  /**
319
338
  * Enables or disables censorship circumvention for all new connections (until changed).
@@ -326,28 +345,108 @@ class Net {
326
345
  * CC is off by default.
327
346
  */
328
347
  setCensorshipCircumventionEnabled(enabled) {
329
- Native.ConnectionManager_set_censorship_circumvention_enabled(this.connectionManager, enabled);
348
+ Native.ConnectionManager_set_censorship_circumvention_enabled(this._connectionManager, enabled);
349
+ }
350
+ setProxy(hostOrOptions, portOrNothing) {
351
+ if (typeof hostOrOptions === 'string') {
352
+ // Support <username>@<host> syntax to allow UNENCRYPTED_FOR_TESTING as a marker user.
353
+ // This is not a stable feature of the API and may go away in the future;
354
+ // the Rust layer will reject any other users anyway. But it's convenient for us.
355
+ const [before, after] = hostOrOptions.split('@', 2);
356
+ const [username, domain] = after ? [before, after] : [undefined, before];
357
+ hostOrOptions = {
358
+ scheme: exports.SIGNAL_TLS_PROXY_SCHEME,
359
+ host: domain,
360
+ port: portOrNothing,
361
+ username,
362
+ };
363
+ }
364
+ const { scheme, host, port, username, password } = hostOrOptions;
365
+ try {
366
+ const proxyConfig = newNativeHandle(Native.ConnectionProxyConfig_new(scheme, host,
367
+ // i32::MIN represents "no port provided"; we don't expect anyone to pass that manually.
368
+ port ?? -2147483648, username ?? null, password ?? null));
369
+ Native.ConnectionManager_set_proxy(this._connectionManager, proxyConfig);
370
+ }
371
+ catch (e) {
372
+ this.setInvalidProxy();
373
+ throw e;
374
+ }
330
375
  }
331
376
  /**
332
- * Sets the proxy host to be used for all new connections (until overridden).
377
+ * Like {@link #setProxy}, but parses the proxy options from a URL. See there for more
378
+ * information.
333
379
  *
334
- * Sets a domain name and port to be used to proxy all new outgoing
335
- * connections. The proxy can be overridden by calling this method again or
336
- * unset by calling {@link #clearProxy}.
380
+ * Takes a string rather than a URL so that an *invalid* string can result in disabling
381
+ * connections until {@link #clearProxy} is called, consistent with other ways {@link #setProxy}
382
+ * might consider its parameters invalid.
383
+ *
384
+ * Throws if the URL contains unnecessary parts (like a query string), or if the resulting options
385
+ * are not supported.
386
+ */
387
+ setProxyFromUrl(urlString) {
388
+ let options;
389
+ try {
390
+ options = Net.proxyOptionsFromUrl(urlString);
391
+ }
392
+ catch (e) {
393
+ // Make sure we set an invalid proxy on error,
394
+ // so no connection can be made until the problem is fixed.
395
+ this.setInvalidProxy();
396
+ throw e;
397
+ }
398
+ this.setProxy(options);
399
+ }
400
+ /**
401
+ * Parses a proxy URL into an options object, suitable for passing to {@link #setProxy}.
402
+ *
403
+ * It is recommended not to call this directly. Instead, use {@link #setProxyFromUrl}, which will
404
+ * treat an invalid URL uniformly with one that is structurally valid but unsupported by
405
+ * libsignal.
406
+ *
407
+ * Throws if the URL is known to not be a valid proxy URL; however it's still possible the
408
+ * resulting options object cannot be used as a proxy.
409
+ */
410
+ static proxyOptionsFromUrl(urlString) {
411
+ const url = new URL(urlString);
412
+ // Check all the parts of the URL.
413
+ // scheme://username:password@hostname:port/path?query#fragment
414
+ const scheme = url.protocol.slice(0, -1);
415
+ // This does not distinguish between "https://proxy.example" and "https://@proxy.example".
416
+ // This could be done by manually checking `url.href`.
417
+ // But until someone complains about it, let's not worry about it.
418
+ const username = url.username != '' ? url.username : undefined;
419
+ const password = url.password != '' ? url.password : undefined;
420
+ const host = url.hostname;
421
+ const port = url.port != '' ? Number.parseInt(url.port, 10) : undefined;
422
+ if (url.pathname != '' && url.pathname != '/') {
423
+ throw new Error('proxy URLs should not have path components');
424
+ }
425
+ if (url.search != '') {
426
+ throw new Error('proxy URLs should not have query components');
427
+ }
428
+ if (url.hash != '') {
429
+ throw new Error('proxy URLs should not have fragment components');
430
+ }
431
+ return { scheme, username, password, host, port };
432
+ }
433
+ /**
434
+ * Refuses to make any new connections until a new proxy configuration is set or
435
+ * {@link #clearProxy} is called.
337
436
  *
338
- * Throws if the host or port is structurally invalid, such as a port that doesn't fit in u16.
437
+ * Existing connections will not be affected.
339
438
  */
340
- setProxy(host, port) {
341
- Native.ConnectionManager_set_proxy(this.connectionManager, host, port);
439
+ setInvalidProxy() {
440
+ Native.ConnectionManager_set_invalid_proxy(this._connectionManager);
342
441
  }
343
442
  /**
344
443
  * Ensures that future connections will be made directly, not through a proxy.
345
444
  *
346
- * Clears any proxy configuration set via {@link #setProxy}. If none was set, calling this
347
- * method is a no-op.
445
+ * Clears any proxy configuration set via {@link #setProxy} or {@link #setInvalidProxy}. If none
446
+ * was set, calling this method is a no-op.
348
447
  */
349
448
  clearProxy() {
350
- Native.ConnectionManager_clear_proxy(this.connectionManager);
449
+ Native.ConnectionManager_clear_proxy(this._connectionManager);
351
450
  }
352
451
  /**
353
452
  * Notifies libsignal that the network has changed.
@@ -355,7 +454,7 @@ class Net {
355
454
  * This will lead to, e.g. caches being cleared and cooldowns being reset.
356
455
  */
357
456
  onNetworkChange() {
358
- Native.ConnectionManager_on_network_change(this.connectionManager);
457
+ Native.ConnectionManager_on_network_change(this._connectionManager);
359
458
  }
360
459
  async cdsiLookup({ username, password }, { e164s, acisAndAccessKeys, abortSignal, }) {
361
460
  const request = newNativeHandle(Native.LookupRequest_new());
@@ -365,7 +464,7 @@ class Net {
365
464
  acisAndAccessKeys.forEach(({ aci: aciStr, accessKey: accessKeyStr }) => {
366
465
  Native.LookupRequest_addAciAndAccessKey(request, Address_1.Aci.parseFromServiceIdString(aciStr).getServiceIdFixedWidthBinary(), node_buffer_1.Buffer.from(accessKeyStr, 'base64'));
367
466
  });
368
- const lookup = await this.asyncContext.makeCancellable(abortSignal, Native.CdsiLookup_new(this.asyncContext, this.connectionManager, username, password, request));
467
+ const lookup = await this.asyncContext.makeCancellable(abortSignal, Native.CdsiLookup_new(this.asyncContext, this._connectionManager, username, password, request));
369
468
  return await this.asyncContext.makeCancellable(abortSignal, Native.CdsiLookup_complete(this.asyncContext, newNativeHandle(lookup)));
370
469
  }
371
470
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signalapp/libsignal-client",
3
- "version": "0.65.4",
3
+ "version": "0.65.6",
4
4
  "license": "AGPL-3.0-only",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",