@signalapp/libsignal-client
Advanced tools
Comparing version 0.47.0 to 0.48.0
@@ -36,3 +36,6 @@ import { ProtocolAddress } from './Address'; | ||
SvrRestoreFailed = 31, | ||
ChatServiceInactive = 32 | ||
ChatServiceInactive = 32, | ||
AppExpired = 33, | ||
DeviceDelinked = 34, | ||
Cancelled = 35 | ||
} | ||
@@ -141,2 +144,8 @@ export declare class LibSignalErrorBase extends Error { | ||
}; | ||
export type AppExpiredError = LibSignalErrorBase & { | ||
code: ErrorCode.AppExpired; | ||
}; | ||
export type DeviceDelinkedError = LibSignalErrorBase & { | ||
code: ErrorCode.DeviceDelinked; | ||
}; | ||
export type SvrDataMissingError = LibSignalErrorBase & { | ||
@@ -152,2 +161,5 @@ code: ErrorCode.SvrDataMissing; | ||
}; | ||
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; | ||
export type CancellationError = LibSignalErrorCommon & { | ||
code: ErrorCode.Cancelled; | ||
}; | ||
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; |
@@ -44,2 +44,5 @@ "use strict"; | ||
ErrorCode[ErrorCode["ChatServiceInactive"] = 32] = "ChatServiceInactive"; | ||
ErrorCode[ErrorCode["AppExpired"] = 33] = "AppExpired"; | ||
ErrorCode[ErrorCode["DeviceDelinked"] = 34] = "DeviceDelinked"; | ||
ErrorCode[ErrorCode["Cancelled"] = 35] = "Cancelled"; | ||
})(ErrorCode = exports.ErrorCode || (exports.ErrorCode = {})); | ||
@@ -46,0 +49,0 @@ class LibSignalErrorBase extends Error { |
@@ -20,2 +20,3 @@ /// <reference types="node" /> | ||
returnAcisWithoutUaks: boolean; | ||
abortSignal?: AbortSignal; | ||
}; | ||
@@ -38,4 +39,9 @@ export type CDSResponseEntryType<Aci, Pni> = { | ||
}>; | ||
type TokioAsyncContext = Wrapper<Native.TokioAsyncContext>; | ||
type ConnectionManager = Wrapper<Native.ConnectionManager>; | ||
/** Low-level async runtime control, mostly just exported for testing. */ | ||
export declare class TokioAsyncContext { | ||
readonly _nativeHandle: Native.TokioAsyncContext; | ||
constructor(handle: Native.TokioAsyncContext); | ||
makeCancellable<T>(abortSignal: AbortSignal | undefined, promise: Promise<T>): Promise<T>; | ||
} | ||
/** | ||
@@ -65,4 +71,9 @@ * Provides API methods to connect and communicate with the Chat Service. | ||
* automatic reconnect attempt will be made. | ||
* | ||
* @throws {AppExpiredError} if the current app version is too old (as judged by the server). | ||
* @throws {LibSignalError} with other codes for other failures. | ||
*/ | ||
connectUnauthenticated(): Promise<Native.ChatServiceDebugInfo>; | ||
connectUnauthenticated(options?: { | ||
abortSignal?: AbortSignal; | ||
}): Promise<Native.ChatServiceDebugInfo>; | ||
/** | ||
@@ -75,4 +86,10 @@ * Initiates establishing of the underlying authenticated connection to the Chat Service. Once the | ||
* Calling this method will result in starting to accept incoming requests from the Chat Service. | ||
* | ||
* @throws {AppExpiredError} if the current app version is too old (as judged by the server). | ||
* @throws {DeviceDelinkedError} if the current device has been delinked. | ||
* @throws {LibSignalError} with other codes for other failures. | ||
*/ | ||
connectAuthenticated(): Promise<Native.ChatServiceDebugInfo>; | ||
connectAuthenticated(options?: { | ||
abortSignal?: AbortSignal; | ||
}): Promise<Native.ChatServiceDebugInfo>; | ||
/** | ||
@@ -87,3 +104,5 @@ * Sends request to the Chat Service over an unauthenticated channel. | ||
*/ | ||
unauthenticatedFetchAndDebug(chatRequest: ChatRequest): Promise<Native.ResponseAndDebugInfo>; | ||
unauthenticatedFetchAndDebug(chatRequest: ChatRequest, options?: { | ||
abortSignal?: AbortSignal; | ||
}): Promise<Native.ResponseAndDebugInfo>; | ||
/** | ||
@@ -95,3 +114,5 @@ * Sends request to the Chat Service over an unauthenticated channel. | ||
*/ | ||
unauthenticatedFetch(chatRequest: ChatRequest): Promise<Native.ChatResponse>; | ||
unauthenticatedFetch(chatRequest: ChatRequest, options?: { | ||
abortSignal?: AbortSignal; | ||
}): Promise<Native.ChatResponse>; | ||
/** | ||
@@ -106,3 +127,5 @@ * Sends request to the Chat Service over an authenticated channel. | ||
*/ | ||
authenticatedFetchAndDebug(chatRequest: ChatRequest): Promise<Native.ResponseAndDebugInfo>; | ||
authenticatedFetchAndDebug(chatRequest: ChatRequest, options?: { | ||
abortSignal?: AbortSignal; | ||
}): Promise<Native.ResponseAndDebugInfo>; | ||
/** | ||
@@ -114,3 +137,5 @@ * Sends request to the Chat Service over an authenticated channel. | ||
*/ | ||
authenticatedFetch(chatRequest: ChatRequest): Promise<Native.ChatResponse>; | ||
authenticatedFetch(chatRequest: ChatRequest, options?: { | ||
abortSignal?: AbortSignal; | ||
}): Promise<Native.ChatResponse>; | ||
static buildHttpRequest(chatRequest: ChatRequest): { | ||
@@ -155,3 +180,3 @@ _nativeHandle: Native.HttpRequest; | ||
clearProxy(): void; | ||
cdsiLookup({ username, password }: Readonly<ServiceAuth>, { e164s, acisAndAccessKeys, returnAcisWithoutUaks, }: ReadonlyDeep<CDSRequestOptionsType>): Promise<CDSResponseType<string, string>>; | ||
cdsiLookup({ username, password }: Readonly<ServiceAuth>, { e164s, acisAndAccessKeys, returnAcisWithoutUaks, abortSignal, }: ReadonlyDeep<CDSRequestOptionsType>): Promise<CDSResponseType<string, string>>; | ||
} | ||
@@ -211,3 +236,5 @@ /** | ||
*/ | ||
backup(what: Buffer, password: string, maxTries: number, auth: Readonly<ServiceAuth>): Promise<Buffer>; | ||
backup(what: Buffer, password: string, maxTries: number, auth: Readonly<ServiceAuth>, options?: { | ||
abortSignal?: AbortSignal; | ||
}): Promise<Buffer>; | ||
/** | ||
@@ -248,3 +275,5 @@ * Restore a secret from SVR3. | ||
*/ | ||
restore(password: string, shareSet: Buffer, auth: Readonly<ServiceAuth>): Promise<RestoredSecret>; | ||
restore(password: string, shareSet: Buffer, auth: Readonly<ServiceAuth>, options?: { | ||
abortSignal?: AbortSignal; | ||
}): Promise<RestoredSecret>; | ||
/** | ||
@@ -275,3 +304,5 @@ * Remove a value stored in SVR3. | ||
*/ | ||
remove(auth: Readonly<ServiceAuth>): Promise<void>; | ||
remove(auth: Readonly<ServiceAuth>, options?: { | ||
abortSignal?: AbortSignal; | ||
}): Promise<void>; | ||
} | ||
@@ -278,0 +309,0 @@ /** |
@@ -7,3 +7,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RestoredSecret = exports.Net = exports.ChatService = exports.Environment = void 0; | ||
exports.RestoredSecret = exports.Net = exports.ChatService = exports.TokioAsyncContext = exports.Environment = void 0; | ||
const Native = require("../Native"); | ||
@@ -23,2 +23,26 @@ const Address_1 = require("./Address"); | ||
} | ||
/** Low-level async runtime control, mostly just exported for testing. */ | ||
class TokioAsyncContext { | ||
constructor(handle) { | ||
this._nativeHandle = handle; | ||
} | ||
makeCancellable(abortSignal, promise) { | ||
if (abortSignal !== undefined && | ||
'_cancellationToken' in promise && | ||
typeof promise._cancellationToken === 'bigint') { | ||
const cancellationToken = promise._cancellationToken; | ||
const cancel = () => { | ||
Native.TokioAsyncContext_cancel(this, cancellationToken); | ||
}; | ||
if (abortSignal.aborted) { | ||
cancel(); | ||
} | ||
else { | ||
abortSignal.addEventListener('abort', cancel); | ||
} | ||
} | ||
return promise; | ||
} | ||
} | ||
exports.TokioAsyncContext = TokioAsyncContext; | ||
/** | ||
@@ -43,4 +67,4 @@ * Provides API methods to connect and communicate with the Chat Service. | ||
*/ | ||
async disconnect() { | ||
await Native.ChatService_disconnect(this.asyncContext, this.chatService); | ||
disconnect() { | ||
return Native.ChatService_disconnect(this.asyncContext, this.chatService); | ||
} | ||
@@ -52,5 +76,8 @@ /** | ||
* automatic reconnect attempt will be made. | ||
* | ||
* @throws {AppExpiredError} if the current app version is too old (as judged by the server). | ||
* @throws {LibSignalError} with other codes for other failures. | ||
*/ | ||
async connectUnauthenticated() { | ||
return await Native.ChatService_connect_unauth(this.asyncContext, this.chatService); | ||
connectUnauthenticated(options) { | ||
return this.asyncContext.makeCancellable(options?.abortSignal, Native.ChatService_connect_unauth(this.asyncContext, this.chatService)); | ||
} | ||
@@ -64,5 +91,9 @@ /** | ||
* Calling this method will result in starting to accept incoming requests from the Chat Service. | ||
* | ||
* @throws {AppExpiredError} if the current app version is too old (as judged by the server). | ||
* @throws {DeviceDelinkedError} if the current device has been delinked. | ||
* @throws {LibSignalError} with other codes for other failures. | ||
*/ | ||
async connectAuthenticated() { | ||
return await Native.ChatService_connect_auth(this.asyncContext, this.chatService); | ||
connectAuthenticated(options) { | ||
return this.asyncContext.makeCancellable(options?.abortSignal, Native.ChatService_connect_auth(this.asyncContext, this.chatService)); | ||
} | ||
@@ -78,4 +109,4 @@ /** | ||
*/ | ||
async unauthenticatedFetchAndDebug(chatRequest) { | ||
return await Native.ChatService_unauth_send_and_debug(this.asyncContext, this.chatService, ChatService.buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS); | ||
unauthenticatedFetchAndDebug(chatRequest, options) { | ||
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)); | ||
} | ||
@@ -88,4 +119,4 @@ /** | ||
*/ | ||
async unauthenticatedFetch(chatRequest) { | ||
return await Native.ChatService_unauth_send(this.asyncContext, this.chatService, ChatService.buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS); | ||
unauthenticatedFetch(chatRequest, options) { | ||
return this.asyncContext.makeCancellable(options?.abortSignal, Native.ChatService_unauth_send(this.asyncContext, this.chatService, ChatService.buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS)); | ||
} | ||
@@ -101,4 +132,4 @@ /** | ||
*/ | ||
async authenticatedFetchAndDebug(chatRequest) { | ||
return await Native.ChatService_auth_send_and_debug(this.asyncContext, this.chatService, ChatService.buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS); | ||
authenticatedFetchAndDebug(chatRequest, options) { | ||
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)); | ||
} | ||
@@ -111,4 +142,4 @@ /** | ||
*/ | ||
async authenticatedFetch(chatRequest) { | ||
return await Native.ChatService_auth_send(this.asyncContext, this.chatService, ChatService.buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS); | ||
authenticatedFetch(chatRequest, options) { | ||
return this.asyncContext.makeCancellable(options?.abortSignal, Native.ChatService_auth_send(this.asyncContext, this.chatService, ChatService.buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS)); | ||
} | ||
@@ -131,3 +162,3 @@ static buildHttpRequest(chatRequest) { | ||
constructor(env, userAgent) { | ||
this.asyncContext = newNativeHandle(Native.TokioAsyncContext_new()); | ||
this.asyncContext = new TokioAsyncContext(Native.TokioAsyncContext_new()); | ||
this.connectionManager = newNativeHandle(Native.ConnectionManager_new(env, userAgent)); | ||
@@ -171,3 +202,3 @@ this.svr3 = new Svr3ClientImpl(this.asyncContext, this.connectionManager); | ||
} | ||
async cdsiLookup({ username, password }, { e164s, acisAndAccessKeys, returnAcisWithoutUaks, }) { | ||
async cdsiLookup({ username, password }, { e164s, acisAndAccessKeys, returnAcisWithoutUaks, abortSignal, }) { | ||
const request = newNativeHandle(Native.LookupRequest_new()); | ||
@@ -181,4 +212,4 @@ e164s.forEach((e164) => { | ||
Native.LookupRequest_setReturnAcisWithoutUaks(request, returnAcisWithoutUaks); | ||
const lookup = await Native.CdsiLookup_new(this.asyncContext, this.connectionManager, username, password, request); | ||
return await Native.CdsiLookup_complete(this.asyncContext, newNativeHandle(lookup)); | ||
const lookup = await this.asyncContext.makeCancellable(abortSignal, Native.CdsiLookup_new(this.asyncContext, this.connectionManager, username, password, request)); | ||
return await this.asyncContext.makeCancellable(abortSignal, Native.CdsiLookup_complete(this.asyncContext, newNativeHandle(lookup))); | ||
} | ||
@@ -203,13 +234,13 @@ } | ||
} | ||
async backup(what, password, maxTries, auth) { | ||
return Native.Svr3Backup(this.asyncContext, this.connectionManager, what, password, maxTries, auth.username, auth.password); | ||
async backup(what, password, maxTries, auth, options) { | ||
return this.asyncContext.makeCancellable(options?.abortSignal, Native.Svr3Backup(this.asyncContext, this.connectionManager, what, password, maxTries, auth.username, auth.password)); | ||
} | ||
async restore(password, shareSet, auth) { | ||
const serialized = await Native.Svr3Restore(this.asyncContext, this.connectionManager, password, shareSet, auth.username, auth.password); | ||
async restore(password, shareSet, auth, options) { | ||
const serialized = await this.asyncContext.makeCancellable(options?.abortSignal, Native.Svr3Restore(this.asyncContext, this.connectionManager, password, shareSet, auth.username, auth.password)); | ||
return new RestoredSecret(serialized); | ||
} | ||
async remove(auth) { | ||
return Native.Svr3Remove(this.asyncContext, this.connectionManager, auth.username, auth.password); | ||
async remove(auth, options) { | ||
return this.asyncContext.makeCancellable(options?.abortSignal, Native.Svr3Remove(this.asyncContext, this.connectionManager, auth.username, auth.password)); | ||
} | ||
} | ||
//# sourceMappingURL=net.js.map |
@@ -480,4 +480,3 @@ // | ||
export function TESTING_ChatServiceDebugInfoConvert(): ChatServiceDebugInfo; | ||
export function TESTING_ChatServiceErrorConvert(): void; | ||
export function TESTING_ChatServiceInactiveErrorConvert(): void; | ||
export function TESTING_ChatServiceErrorConvert(errorDescription: string): void; | ||
export function TESTING_ChatServiceResponseAndDebugInfoConvert(): ResponseAndDebugInfo; | ||
@@ -484,0 +483,0 @@ export function TESTING_ChatServiceResponseConvert(bodyPresent: boolean): ChatResponse; |
{ | ||
"name": "@signalapp/libsignal-client", | ||
"version": "0.47.0", | ||
"version": "0.48.0", | ||
"license": "AGPL-3.0-only", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
92929813
6148