@signalapp/libsignal-client 0.40.0 → 0.41.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
@@ -21,6 +21,24 @@ interface LookupResponseEntry {
21
21
  readonly pni: string | undefined;
22
22
  }
23
23
 
24
+ interface Response {
25
+ status: number;
26
+ message: string | undefined;
27
+ headers: ReadonlyArray<[string, string]>;
28
+ body: Buffer | undefined;
29
+ }
30
+
31
+ interface DebugInfo {
32
+ connectionReused: boolean;
33
+ reconnectCount: number;
34
+ ipType: number;
35
+ }
36
+
37
+ interface ResponseAndDebugInfo {
38
+ response: Response;
39
+ debugInfo: DebugInfo;
40
+ }
41
+
24
42
  interface SealedSenderMultiRecipientMessageRecipient {
25
43
  deviceIds: number[];
26
44
  registrationIds: number[];
@@ -126,9 +144,9 @@ export function BackupAuthCredentialPresentation_Verify(presentationBytes: Buffe
126
144
  export function BackupAuthCredentialRequestContext_CheckValidContents(contextBytes: Buffer): void;
127
145
  export function BackupAuthCredentialRequestContext_GetRequest(contextBytes: Buffer): Buffer;
128
146
  export function BackupAuthCredentialRequestContext_New(backupKey: Buffer, uuid: Uuid): Buffer;
129
- export function BackupAuthCredentialRequestContext_ReceiveResponse(contextBytes: Buffer, responseBytes: Buffer, paramsBytes: Buffer, expectedReceiptLevel: Buffer): Buffer;
147
+ export function BackupAuthCredentialRequestContext_ReceiveResponse(contextBytes: Buffer, responseBytes: Buffer, paramsBytes: Buffer, expectedReceiptLevel: bigint): Buffer;
130
148
  export function BackupAuthCredentialRequest_CheckValidContents(requestBytes: Buffer): void;
131
- export function BackupAuthCredentialRequest_IssueDeterministic(requestBytes: Buffer, redemptionTime: Timestamp, receiptLevel: Buffer, paramsBytes: Buffer, randomness: Buffer): Buffer;
149
+ export function BackupAuthCredentialRequest_IssueDeterministic(requestBytes: Buffer, redemptionTime: Timestamp, receiptLevel: bigint, paramsBytes: Buffer, randomness: Buffer): Buffer;
132
150
  export function BackupAuthCredentialResponse_CheckValidContents(responseBytes: Buffer): void;
133
151
  export function BackupAuthCredential_CheckValidContents(paramsBytes: Buffer): void;
134
152
  export function BackupAuthCredential_GetBackupId(credentialBytes: Buffer): Buffer;
@@ -150,6 +168,10 @@ export function Cds2ClientState_New(mrenclave: Buffer, attestationMsg: Buffer, c
150
168
  export function CdsiLookup_complete(asyncRuntime: Wrapper<TokioAsyncContext>, lookup: Wrapper<CdsiLookup>): Promise<LookupResponse>;
151
169
  export function CdsiLookup_new(asyncRuntime: Wrapper<TokioAsyncContext>, connectionManager: Wrapper<ConnectionManager>, username: string, password: string, request: Wrapper<LookupRequest>, timeoutMillis: number): Promise<CdsiLookup>;
152
170
  export function CdsiLookup_token(lookup: Wrapper<CdsiLookup>): Buffer;
171
+ export function ChatService_disconnect(asyncRuntime: Wrapper<TokioAsyncContext>, chat: Wrapper<Chat>): Promise<void>;
172
+ export function ChatService_new(connectionManager: Wrapper<ConnectionManager>, username: string, password: string): Chat;
173
+ export function ChatService_unauth_send(asyncRuntime: Wrapper<TokioAsyncContext>, chat: Wrapper<Chat>, httpRequest: Wrapper<HttpRequest>, timeoutMillis: number): Promise<Response>;
174
+ export function ChatService_unauth_send_and_debug(asyncRuntime: Wrapper<TokioAsyncContext>, chat: Wrapper<Chat>, httpRequest: Wrapper<HttpRequest>, timeoutMillis: number): Promise<ResponseAndDebugInfo>;
153
175
  export function CiphertextMessage_FromPlaintextContent(m: Wrapper<PlaintextContent>): CiphertextMessage;
154
176
  export function CiphertextMessage_Serialize(obj: Wrapper<CiphertextMessage>): Buffer;
155
177
  export function CiphertextMessage_Type(msg: Wrapper<CiphertextMessage>): number;
@@ -165,6 +187,8 @@ export function CreateCallLinkCredentialRequest_IssueDeterministic(requestBytes:
165
187
  export function CreateCallLinkCredentialResponse_CheckValidContents(responseBytes: Buffer): void;
166
188
  export function CreateCallLinkCredential_CheckValidContents(paramsBytes: Buffer): void;
167
189
  export function CreateCallLinkCredential_PresentDeterministic(credentialBytes: Buffer, roomId: Buffer, userId: Buffer, serverParamsBytes: Buffer, callLinkParamsBytes: Buffer, randomness: Buffer): Buffer;
190
+ export function CreateOTP(username: string, secret: Buffer): string;
191
+ export function CreateOTPFromBase64(username: string, secret: string): string;
168
192
  export function DecryptionErrorMessage_Deserialize(data: Buffer): DecryptionErrorMessage;
169
193
  export function DecryptionErrorMessage_ExtractFromSerializedContent(bytes: Buffer): DecryptionErrorMessage;
170
194
  export function DecryptionErrorMessage_ForOriginalMessage(originalBytes: Buffer, originalType: number, originalTimestamp: Timestamp, originalSenderDeviceId: number): DecryptionErrorMessage;
@@ -213,6 +237,8 @@ export function HsmEnclaveClient_EstablishedRecv(cli: Wrapper<HsmEnclaveClient>,
213
237
  export function HsmEnclaveClient_EstablishedSend(cli: Wrapper<HsmEnclaveClient>, plaintextToSend: Buffer): Buffer;
214
238
  export function HsmEnclaveClient_InitialRequest(obj: Wrapper<HsmEnclaveClient>): Buffer;
215
239
  export function HsmEnclaveClient_New(trustedPublicKey: Buffer, trustedCodeHashes: Buffer): HsmEnclaveClient;
240
+ export function HttpRequest_add_header(request: Wrapper<HttpRequest>, name: string, value: string): void;
241
+ export function HttpRequest_new(method: string, path: string, bodyAsSlice: Buffer | null): HttpRequest;
216
242
  export function IdentityKeyPair_Deserialize(buffer: Buffer): {publicKey:PublicKey,privateKey:PrivateKey};
217
243
  export function IdentityKeyPair_Serialize(publicKey: Wrapper<PublicKey>, privateKey: Wrapper<PrivateKey>): Buffer;
218
244
  export function IdentityKeyPair_SignAlternateIdentity(publicKey: Wrapper<PublicKey>, privateKey: Wrapper<PrivateKey>, otherIdentity: Wrapper<PublicKey>): Buffer;
@@ -245,9 +271,9 @@ export function LookupRequest_new(): LookupRequest;
245
271
  export function LookupRequest_setReturnAcisWithoutUaks(request: Wrapper<LookupRequest>, returnAcisWithoutUaks: boolean): void;
246
272
  export function LookupRequest_setToken(request: Wrapper<LookupRequest>, token: Buffer): void;
247
273
  export function MessageBackupKey_New(masterKey: Buffer, aci: Buffer): MessageBackupKey;
248
- export function MessageBackupValidator_Validate(key: Wrapper<MessageBackupKey>, firstStream: InputStream, secondStream: InputStream, len: Buffer): Promise<MessageBackupValidationOutcome>;
274
+ export function MessageBackupValidator_Validate(key: Wrapper<MessageBackupKey>, firstStream: InputStream, secondStream: InputStream, len: bigint, purpose: number): Promise<MessageBackupValidationOutcome>;
249
275
  export function MinidumpToJSONString(buffer: Buffer): string;
250
- export function Mp4Sanitizer_Sanitize(input: InputStream, len: Buffer): Promise<SanitizedMetadata>;
276
+ export function Mp4Sanitizer_Sanitize(input: InputStream, len: bigint): Promise<SanitizedMetadata>;
251
277
  export function PlaintextContent_Deserialize(data: Buffer): PlaintextContent;
252
278
  export function PlaintextContent_FromDecryptionErrorMessage(m: Wrapper<DecryptionErrorMessage>): PlaintextContent;
253
279
  export function PlaintextContent_GetBody(obj: Wrapper<PlaintextContent>): Buffer;
@@ -306,7 +332,7 @@ export function PublicKey_Serialize(obj: Wrapper<PublicKey>): Buffer;
306
332
  export function PublicKey_Verify(key: Wrapper<PublicKey>, message: Buffer, signature: Buffer): boolean;
307
333
  export function ReceiptCredentialPresentation_CheckValidContents(buffer: Buffer): void;
308
334
  export function ReceiptCredentialPresentation_GetReceiptExpirationTime(presentation: Serialized<ReceiptCredentialPresentation>): Timestamp;
309
- export function ReceiptCredentialPresentation_GetReceiptLevel(presentation: Serialized<ReceiptCredentialPresentation>): Buffer;
335
+ export function ReceiptCredentialPresentation_GetReceiptLevel(presentation: Serialized<ReceiptCredentialPresentation>): bigint;
310
336
  export function ReceiptCredentialPresentation_GetReceiptSerial(presentation: Serialized<ReceiptCredentialPresentation>): Buffer;
311
337
  export function ReceiptCredentialRequestContext_CheckValidContents(buffer: Buffer): void;
312
338
  export function ReceiptCredentialRequestContext_GetRequest(requestContext: Serialized<ReceiptCredentialRequestContext>): Serialized<ReceiptCredentialRequest>;
@@ -314,9 +340,9 @@ export function ReceiptCredentialRequest_CheckValidContents(buffer: Buffer): voi
314
340
  export function ReceiptCredentialResponse_CheckValidContents(buffer: Buffer): void;
315
341
  export function ReceiptCredential_CheckValidContents(buffer: Buffer): void;
316
342
  export function ReceiptCredential_GetReceiptExpirationTime(receiptCredential: Serialized<ReceiptCredential>): Timestamp;
317
- export function ReceiptCredential_GetReceiptLevel(receiptCredential: Serialized<ReceiptCredential>): Buffer;
318
- export function SanitizedMetadata_GetDataLen(sanitized: Wrapper<SanitizedMetadata>): Buffer;
319
- export function SanitizedMetadata_GetDataOffset(sanitized: Wrapper<SanitizedMetadata>): Buffer;
343
+ export function ReceiptCredential_GetReceiptLevel(receiptCredential: Serialized<ReceiptCredential>): bigint;
344
+ export function SanitizedMetadata_GetDataLen(sanitized: Wrapper<SanitizedMetadata>): bigint;
345
+ export function SanitizedMetadata_GetDataOffset(sanitized: Wrapper<SanitizedMetadata>): bigint;
320
346
  export function SanitizedMetadata_GetMetadata(sanitized: Wrapper<SanitizedMetadata>): Buffer;
321
347
  export function ScannableFingerprint_Compare(fprint1: Buffer, fprint2: Buffer): boolean;
322
348
  export function SealedSenderDecryptionResult_GetDeviceId(obj: Wrapper<SealedSenderDecryptionResult>): number;
@@ -387,7 +413,7 @@ export function ServerSecretParams_IssueAuthCredentialDeterministic(serverSecret
387
413
  export function ServerSecretParams_IssueAuthCredentialWithPniAsAciDeterministic(serverSecretParams: Serialized<ServerSecretParams>, randomness: Buffer, aci: Buffer, pni: Buffer, redemptionTime: Timestamp): Serialized<AuthCredentialWithPniResponse>;
388
414
  export function ServerSecretParams_IssueAuthCredentialWithPniAsServiceIdDeterministic(serverSecretParams: Serialized<ServerSecretParams>, randomness: Buffer, aci: Buffer, pni: Buffer, redemptionTime: Timestamp): Serialized<AuthCredentialWithPniResponse>;
389
415
  export function ServerSecretParams_IssueExpiringProfileKeyCredentialDeterministic(serverSecretParams: Serialized<ServerSecretParams>, randomness: Buffer, request: Serialized<ProfileKeyCredentialRequest>, userId: Buffer, commitment: Serialized<ProfileKeyCommitment>, expirationInSeconds: Timestamp): Serialized<ExpiringProfileKeyCredentialResponse>;
390
- export function ServerSecretParams_IssueReceiptCredentialDeterministic(serverSecretParams: Serialized<ServerSecretParams>, randomness: Buffer, request: Serialized<ReceiptCredentialRequest>, receiptExpirationTime: Timestamp, receiptLevel: Buffer): Serialized<ReceiptCredentialResponse>;
416
+ export function ServerSecretParams_IssueReceiptCredentialDeterministic(serverSecretParams: Serialized<ServerSecretParams>, randomness: Buffer, request: Serialized<ReceiptCredentialRequest>, receiptExpirationTime: Timestamp, receiptLevel: bigint): Serialized<ReceiptCredentialResponse>;
391
417
  export function ServerSecretParams_SignDeterministic(params: Serialized<ServerSecretParams>, randomness: Buffer, message: Buffer): Buffer;
392
418
  export function ServerSecretParams_VerifyAuthCredentialPresentation(serverSecretParams: Serialized<ServerSecretParams>, groupPublicParams: Serialized<GroupPublicParams>, presentationBytes: Buffer, currentTimeInSeconds: Timestamp): void;
393
419
  export function ServerSecretParams_VerifyProfileKeyCredentialPresentation(serverSecretParams: Serialized<ServerSecretParams>, groupPublicParams: Serialized<GroupPublicParams>, presentationBytes: Buffer, currentTimeInSeconds: Timestamp): void;
@@ -428,8 +454,17 @@ export function SignedPreKeyRecord_GetSignature(obj: Wrapper<SignedPreKeyRecord>
428
454
  export function SignedPreKeyRecord_GetTimestamp(obj: Wrapper<SignedPreKeyRecord>): Timestamp;
429
455
  export function SignedPreKeyRecord_New(id: number, timestamp: Timestamp, pubKey: Wrapper<PublicKey>, privKey: Wrapper<PrivateKey>, signature: Buffer): SignedPreKeyRecord;
430
456
  export function SignedPreKeyRecord_Serialize(obj: Wrapper<SignedPreKeyRecord>): Buffer;
457
+ export function Svr3Backup(asyncRuntime: Wrapper<TokioAsyncContext>, connectionManager: Wrapper<ConnectionManager>, secret: Buffer, password: string, maxTries: number, username: string, enclavePassword: string, opTimeoutMs: number): Promise<Buffer>;
458
+ export function Svr3Restore(asyncRuntime: Wrapper<TokioAsyncContext>, connectionManager: Wrapper<ConnectionManager>, password: string, shareSet: Buffer, username: string, enclavePassword: string, opTimeoutMs: number): Promise<Buffer>;
431
459
  export function TESTING_CdsiLookupErrorConvert(): void;
432
- export function TESTING_CdsiLookupResponseConvert(): LookupResponse;
460
+ export function TESTING_CdsiLookupResponseConvert(asyncRuntime: Wrapper<TokioAsyncContext>): Promise<LookupResponse>;
461
+ export function TESTING_ChatRequestGetBody(request: Wrapper<HttpRequest>): Buffer | null;
462
+ export function TESTING_ChatRequestGetHeaderValue(request: Wrapper<HttpRequest>, headerName: string): string;
463
+ export function TESTING_ChatRequestGetMethod(request: Wrapper<HttpRequest>): string;
464
+ export function TESTING_ChatRequestGetPath(request: Wrapper<HttpRequest>): string;
465
+ export function TESTING_ChatServiceDebugInfoConvert(): DebugInfo;
466
+ export function TESTING_ChatServiceErrorConvert(): void;
467
+ export function TESTING_ChatServiceResponseConvert(bodyPresent: boolean): Response;
433
468
  export function TESTING_ErrorOnBorrowAsync(_input: null): Promise<void>;
434
469
  export function TESTING_ErrorOnBorrowIo(asyncRuntime: Wrapper<NonSuspendingBackgroundThreadRuntime>, _input: null): Promise<void>;
435
470
  export function TESTING_ErrorOnBorrowSync(_input: null): void;
@@ -484,6 +519,7 @@ interface AuthCredentialResponse { readonly __type: unique symbol; }
484
519
  interface AuthCredentialWithPni { readonly __type: unique symbol; }
485
520
  interface AuthCredentialWithPniResponse { readonly __type: unique symbol; }
486
521
  interface CdsiLookup { readonly __type: unique symbol; }
522
+ interface Chat { readonly __type: unique symbol; }
487
523
  interface CiphertextMessage { readonly __type: unique symbol; }
488
524
  interface ConnectionManager { readonly __type: unique symbol; }
489
525
  interface DecryptionErrorMessage { readonly __type: unique symbol; }
@@ -494,6 +530,7 @@ interface GroupMasterKey { readonly __type: unique symbol; }
494
530
  interface GroupPublicParams { readonly __type: unique symbol; }
495
531
  interface GroupSecretParams { readonly __type: unique symbol; }
496
532
  interface HsmEnclaveClient { readonly __type: unique symbol; }
533
+ interface HttpRequest { readonly __type: unique symbol; }
497
534
  interface IncrementalMac { readonly __type: unique symbol; }
498
535
  interface KyberKeyPair { readonly __type: unique symbol; }
499
536
  interface KyberPreKeyRecord { readonly __type: unique symbol; }
package/dist/Address.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import * as Native from '../Native';
3
- declare enum ServiceIdKind {
3
+ export declare enum ServiceIdKind {
4
4
  Aci = 0,
5
5
  Pni = 1
6
6
  }
@@ -46,4 +46,3 @@ export declare class ProtocolAddress {
46
46
  deviceId(): number;
47
47
  toString(): string;
48
48
  }
49
- export {};
package/dist/Address.js CHANGED
@@ -4,14 +4,14 @@
4
4
  // SPDX-License-Identifier: AGPL-3.0-only
5
5
  //
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.ProtocolAddress = exports.Pni = exports.Aci = exports.ServiceId = void 0;
7
+ exports.ProtocolAddress = exports.Pni = exports.Aci = exports.ServiceId = exports.ServiceIdKind = void 0;
8
8
  const Native = require("../Native");
9
9
  const uuid = require("uuid");
10
10
  var ServiceIdKind;
11
11
  (function (ServiceIdKind) {
12
12
  ServiceIdKind[ServiceIdKind["Aci"] = 0] = "Aci";
13
13
  ServiceIdKind[ServiceIdKind["Pni"] = 1] = "Pni";
14
- })(ServiceIdKind || (ServiceIdKind = {}));
14
+ })(ServiceIdKind = exports.ServiceIdKind || (exports.ServiceIdKind = {}));
15
15
  const SERVICE_ID_FIXED_WIDTH_BINARY_LEN = 17;
16
16
  class ServiceId extends Object {
17
17
  // This has to be public for `InstanceType<T>`, which we use below.
package/dist/Errors.d.ts CHANGED
@@ -27,7 +27,10 @@ export declare enum ErrorCode {
27
27
  InputDataTooLong = 23,
28
28
  InvalidEntropyDataLength = 24,
29
29
  InvalidUsernameLinkEncryptedData = 25,
30
- RateLimitedError = 26
30
+ RateLimitedError = 26,
31
+ SvrDataMissing = 27,
32
+ SvrRequestFailed = 28,
33
+ SvrRestoreFailed = 29
31
34
  }
32
35
  export declare class LibSignalErrorBase extends Error {
33
36
  readonly code: ErrorCode;
@@ -122,4 +125,13 @@ export type RateLimitedError = LibSignalErrorBase & {
122
125
  code: ErrorCode.RateLimitedError;
123
126
  readonly retryAfterSecs: number;
124
127
  };
125
- 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 | InvalidMediaInputError | UnsupportedMediaInputError;
128
+ export type SvrDataMissingError = LibSignalErrorBase & {
129
+ code: ErrorCode.SvrDataMissing;
130
+ };
131
+ export type SvrRequestFailedError = LibSignalErrorCommon & {
132
+ code: ErrorCode.SvrRequestFailed;
133
+ };
134
+ export type SvrRestoreFailedError = LibSignalErrorCommon & {
135
+ code: ErrorCode.SvrRestoreFailed;
136
+ };
137
+ 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 | InvalidMediaInputError | SvrDataMissingError | SvrRestoreFailedError | SvrRequestFailedError | UnsupportedMediaInputError;
package/dist/Errors.js CHANGED
@@ -35,6 +35,9 @@ var ErrorCode;
35
35
  ErrorCode[ErrorCode["InvalidEntropyDataLength"] = 24] = "InvalidEntropyDataLength";
36
36
  ErrorCode[ErrorCode["InvalidUsernameLinkEncryptedData"] = 25] = "InvalidUsernameLinkEncryptedData";
37
37
  ErrorCode[ErrorCode["RateLimitedError"] = 26] = "RateLimitedError";
38
+ ErrorCode[ErrorCode["SvrDataMissing"] = 27] = "SvrDataMissing";
39
+ ErrorCode[ErrorCode["SvrRequestFailed"] = 28] = "SvrRequestFailed";
40
+ ErrorCode[ErrorCode["SvrRestoreFailed"] = 29] = "SvrRestoreFailed";
38
41
  })(ErrorCode = exports.ErrorCode || (exports.ErrorCode = {}));
39
42
  class LibSignalErrorBase extends Error {
40
43
  constructor(message, name, operation, extraProps) {
@@ -41,13 +41,18 @@ export declare class MessageBackupKey {
41
41
  */
42
42
  constructor(masterKeyBytes: Buffer, aci: Aci);
43
43
  }
44
+ export declare enum Purpose {
45
+ DeviceTransfer = 0,
46
+ RemoteBackup = 1
47
+ }
44
48
  /**
45
49
  * Validate a backup file
46
50
  *
47
51
  * @param backupKey The key to use to decrypt the backup contents.
52
+ * @param purpose Whether the backup is intended for device-to-device transfer or remote storage.
48
53
  * @param inputFactory A function that returns new input streams that read the backup contents.
49
54
  * @param length The exact length of the input stream.
50
55
  * @returns The outcome of validation, including any errors and warnings.
51
56
  * @throws IoError If an IO error on the input occurs.
52
57
  */
53
- export declare function validate(backupKey: MessageBackupKey, inputFactory: InputStreamFactory, length: bigint): Promise<ValidationOutcome>;
58
+ export declare function validate(backupKey: MessageBackupKey, purpose: Purpose, inputFactory: InputStreamFactory, length: bigint): Promise<ValidationOutcome>;
@@ -4,14 +4,13 @@
4
4
  // SPDX-License-Identifier: AGPL-3.0-only
5
5
  //
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.validate = exports.MessageBackupKey = exports.ValidationOutcome = void 0;
7
+ exports.validate = exports.Purpose = exports.MessageBackupKey = exports.ValidationOutcome = void 0;
8
8
  /**
9
9
  * Message backup validation routines.
10
10
  *
11
11
  * @module MessageBackup
12
12
  */
13
13
  const Native = require("../Native");
14
- const BigIntUtil_1 = require("./zkgroup/internal/BigIntUtil");
15
14
  /**
16
15
  * Result of validating a message backup bundle.
17
16
  */
@@ -45,19 +44,26 @@ class MessageBackupKey {
45
44
  }
46
45
  }
47
46
  exports.MessageBackupKey = MessageBackupKey;
47
+ // This must match the Rust version of the enum.
48
+ var Purpose;
49
+ (function (Purpose) {
50
+ Purpose[Purpose["DeviceTransfer"] = 0] = "DeviceTransfer";
51
+ Purpose[Purpose["RemoteBackup"] = 1] = "RemoteBackup";
52
+ })(Purpose = exports.Purpose || (exports.Purpose = {}));
48
53
  /**
49
54
  * Validate a backup file
50
55
  *
51
56
  * @param backupKey The key to use to decrypt the backup contents.
57
+ * @param purpose Whether the backup is intended for device-to-device transfer or remote storage.
52
58
  * @param inputFactory A function that returns new input streams that read the backup contents.
53
59
  * @param length The exact length of the input stream.
54
60
  * @returns The outcome of validation, including any errors and warnings.
55
61
  * @throws IoError If an IO error on the input occurs.
56
62
  */
57
- async function validate(backupKey, inputFactory, length) {
63
+ async function validate(backupKey, purpose, inputFactory, length) {
58
64
  const firstStream = inputFactory();
59
65
  const secondStream = inputFactory();
60
- return new ValidationOutcome(await Native.MessageBackupValidator_Validate(backupKey, firstStream, secondStream, (0, BigIntUtil_1.bufferFromBigUInt64BE)(length)));
66
+ return new ValidationOutcome(await Native.MessageBackupValidator_Validate(backupKey, firstStream, secondStream, length, purpose));
61
67
  }
62
68
  exports.validate = validate;
63
69
  //# sourceMappingURL=MessageBackup.js.map
@@ -34,7 +34,7 @@ export declare class SanitizedMetadata {
34
34
  static _fromNativeHandle(handle: Native.SanitizedMetadata): SanitizedMetadata;
35
35
  /**
36
36
  * Get the sanitized metadata, if any.
37
- * @returns The sanitized metadata, or {@code null} if it didn't need to be sanitized.
37
+ * @returns The sanitized metadata, or `null` if it didn't need to be sanitized.
38
38
  */
39
39
  getMetadata(): Buffer | null;
40
40
  /**
@@ -52,10 +52,10 @@ export declare class SanitizedMetadata {
52
52
  * Sanitize an MP4 input.
53
53
  *
54
54
  * @param input An MP4 format input stream.
55
- * @param length The exact length of the input stream.
55
+ * @param len The exact length of the input stream.
56
56
  * @returns The sanitized metadata.
57
- * @throws IoError If an IO error on the input occurs.
58
- * @throws InvalidMediaInputError If the input could not be parsed because it was invalid.
59
- * @throws UnsupportedMediaInputError If the input could not be parsed because it's unsupported in some way.
57
+ * @throws {IoError} If an IO error on the input occurs.
58
+ * @throws {InvalidMediaInputError} If the input could not be parsed because it was invalid.
59
+ * @throws {UnsupportedMediaInputError} If the input could not be parsed because it's unsupported in some way.
60
60
  */
61
61
  export declare function sanitize(input: InputStream, len: bigint): Promise<SanitizedMetadata>;
@@ -33,7 +33,6 @@ exports.sanitize = exports.SanitizedMetadata = void 0;
33
33
  * @module Mp4Sanitizer
34
34
  */
35
35
  const Native = require("../Native");
36
- const BigIntUtil_1 = require("./zkgroup/internal/BigIntUtil");
37
36
  class SanitizedMetadata {
38
37
  constructor(handle) {
39
38
  this._nativeHandle = handle;
@@ -43,7 +42,7 @@ class SanitizedMetadata {
43
42
  }
44
43
  /**
45
44
  * Get the sanitized metadata, if any.
46
- * @returns The sanitized metadata, or {@code null} if it didn't need to be sanitized.
45
+ * @returns The sanitized metadata, or `null` if it didn't need to be sanitized.
47
46
  */
48
47
  getMetadata() {
49
48
  const metadata = Native.SanitizedMetadata_GetMetadata(this);
@@ -57,16 +56,14 @@ class SanitizedMetadata {
57
56
  * @returns The offset of the media data in the processed input.
58
57
  */
59
58
  getDataOffset() {
60
- const buffer = Native.SanitizedMetadata_GetDataOffset(this);
61
- return buffer.readBigUInt64BE();
59
+ return Native.SanitizedMetadata_GetDataOffset(this);
62
60
  }
63
61
  /**
64
62
  * Get the length of the media data in the processed input.
65
63
  * @returns The length of the media data in the processed input.
66
64
  */
67
65
  getDataLen() {
68
- const buffer = Native.SanitizedMetadata_GetDataLen(this);
69
- return buffer.readBigUInt64BE();
66
+ return Native.SanitizedMetadata_GetDataLen(this);
70
67
  }
71
68
  }
72
69
  exports.SanitizedMetadata = SanitizedMetadata;
@@ -74,14 +71,14 @@ exports.SanitizedMetadata = SanitizedMetadata;
74
71
  * Sanitize an MP4 input.
75
72
  *
76
73
  * @param input An MP4 format input stream.
77
- * @param length The exact length of the input stream.
74
+ * @param len The exact length of the input stream.
78
75
  * @returns The sanitized metadata.
79
- * @throws IoError If an IO error on the input occurs.
80
- * @throws InvalidMediaInputError If the input could not be parsed because it was invalid.
81
- * @throws UnsupportedMediaInputError If the input could not be parsed because it's unsupported in some way.
76
+ * @throws {IoError} If an IO error on the input occurs.
77
+ * @throws {InvalidMediaInputError} If the input could not be parsed because it was invalid.
78
+ * @throws {UnsupportedMediaInputError} If the input could not be parsed because it's unsupported in some way.
82
79
  */
83
80
  async function sanitize(input, len) {
84
- const sanitizedMetadataNativeHandle = await Native.Mp4Sanitizer_Sanitize(input, (0, BigIntUtil_1.bufferFromBigUInt64BE)(len));
81
+ const sanitizedMetadataNativeHandle = await Native.Mp4Sanitizer_Sanitize(input, len);
85
82
  return SanitizedMetadata._fromNativeHandle(sanitizedMetadataNativeHandle);
86
83
  }
87
84
  exports.sanitize = sanitize;
@@ -3,9 +3,8 @@
3
3
  * Sanitize a WebP input.
4
4
  *
5
5
  * @param input A WebP format input stream.
6
- * @param length The exact length of the input stream.
7
- * @throws IoError If an IO error on the input occurs.
8
- * @throws InvalidMediaInputError If the input could not be parsed because it was invalid.
9
- * @throws UnsupportedMediaInputError If the input could not be parsed because it's unsupported in some way.
6
+ * @throws {IoError} If an IO error on the input occurs.
7
+ * @throws {InvalidMediaInputError} If the input could not be parsed because it was invalid.
8
+ * @throws {UnsupportedMediaInputError} If the input could not be parsed because it's unsupported in some way.
10
9
  */
11
10
  export declare function sanitize(input: Buffer): void;
@@ -18,10 +18,9 @@ const Native = require("../Native");
18
18
  * Sanitize a WebP input.
19
19
  *
20
20
  * @param input A WebP format input stream.
21
- * @param length The exact length of the input stream.
22
- * @throws IoError If an IO error on the input occurs.
23
- * @throws InvalidMediaInputError If the input could not be parsed because it was invalid.
24
- * @throws UnsupportedMediaInputError If the input could not be parsed because it's unsupported in some way.
21
+ * @throws {IoError} If an IO error on the input occurs.
22
+ * @throws {InvalidMediaInputError} If the input could not be parsed because it was invalid.
23
+ * @throws {UnsupportedMediaInputError} If the input could not be parsed because it's unsupported in some way.
25
24
  */
26
25
  function sanitize(input) {
27
26
  Native.WebpSanitizer_Sanitize(input);
@@ -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.40.0, libsignal-jni 0.40.0, libsignal-message-backup 0.1.0, libsignal-message-backup-macros 0.1.0, libsignal-net 0.1.0, libsignal-node 0.40.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
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.41.0, libsignal-jni 0.41.0, libsignal-message-backup 0.1.0, libsignal-message-backup-macros 0.1.0, libsignal-net 0.1.0, libsignal-node 0.41.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
@@ -2395,7 +2395,7 @@ express Statement of Purpose.
2395
2395
  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
2396
2396
  ```
2397
2397
 
2398
- ## libloading 0.6.7, libloading 0.8.1
2398
+ ## libloading 0.8.1
2399
2399
 
2400
2400
  ```
2401
2401
  Copyright © 2015, Simonas Kazlauskas
@@ -2805,7 +2805,7 @@ DEALINGS IN THE SOFTWARE.
2805
2805
 
2806
2806
  ```
2807
2807
 
2808
- ## bitflags 1.3.2, bitflags 2.4.2, glob 0.3.1, log 0.4.20, num-derive 0.4.2, num-integer 0.1.45, num-traits 0.2.17, range-map 0.2.0, regex 1.10.3, regex-automata 0.4.4, regex-syntax 0.8.2, semver 0.9.0
2808
+ ## bitflags 1.3.2, bitflags 2.4.2, glob 0.3.1, log 0.4.20, num-derive 0.4.2, num-integer 0.1.45, num-traits 0.2.17, range-map 0.2.0, regex 1.10.3, regex-automata 0.4.4, regex-syntax 0.8.2
2809
2809
 
2810
2810
  ```
2811
2811
  Copyright (c) 2014 The Rust Project Developers
@@ -3007,7 +3007,7 @@ THE SOFTWARE.
3007
3007
 
3008
3008
  ```
3009
3009
 
3010
- ## neon 0.10.1, neon-build 0.10.1, neon-macros 0.10.1, neon-runtime 0.10.1
3010
+ ## neon-macros 1.0.0
3011
3011
 
3012
3012
  ```
3013
3013
  Copyright (c) 2015 David Herman
@@ -3150,6 +3150,31 @@ DEALINGS IN THE SOFTWARE.
3150
3150
 
3151
3151
  ```
3152
3152
 
3153
+ ## procfs-core 0.16.0
3154
+
3155
+ ```
3156
+ Copyright (c) 2015 The procfs Developers
3157
+
3158
+ Permission is hereby granted, free of charge, to any person obtaining a copy
3159
+ of this software and associated documentation files (the "Software"), to deal
3160
+ in the Software without restriction, including without limitation the rights
3161
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
3162
+ copies of the Software, and to permit persons to whom the Software is
3163
+ furnished to do so, subject to the following conditions:
3164
+
3165
+ The above copyright notice and this permission notice shall be included in all
3166
+ copies or substantial portions of the Software.
3167
+
3168
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
3169
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
3170
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
3171
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
3172
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
3173
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3174
+ SOFTWARE.
3175
+
3176
+ ```
3177
+
3153
3178
  ## jni-sys 0.3.0
3154
3179
 
3155
3180
  ```
@@ -3602,37 +3627,6 @@ DEALINGS IN THE SOFTWARE.
3602
3627
 
3603
3628
  ```
3604
3629
 
3605
- ## semver-parser 0.7.0
3606
-
3607
- ```
3608
- Copyright (c) 2016 Steve Klabnik
3609
-
3610
- Permission is hereby granted, free of charge, to any
3611
- person obtaining a copy of this software and associated
3612
- documentation files (the "Software"), to deal in the
3613
- Software without restriction, including without
3614
- limitation the rights to use, copy, modify, merge,
3615
- publish, distribute, sublicense, and/or sell copies of
3616
- the Software, and to permit persons to whom the Software
3617
- is furnished to do so, subject to the following
3618
- conditions:
3619
-
3620
- The above copyright notice and this permission notice
3621
- shall be included in all copies or substantial portions
3622
- of the Software.
3623
-
3624
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
3625
- ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
3626
- TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
3627
- PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
3628
- SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
3629
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
3630
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
3631
- IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
3632
- DEALINGS IN THE SOFTWARE.
3633
-
3634
- ```
3635
-
3636
3630
  ## lock_api 0.4.11, parking_lot 0.12.1, parking_lot_core 0.9.9, rustc_version 0.4.0
3637
3631
 
3638
3632
  ```
@@ -4686,7 +4680,7 @@ DEALINGS IN THE SOFTWARE.
4686
4680
 
4687
4681
  ```
4688
4682
 
4689
- ## protobuf 3.3.0, protobuf-codegen 3.3.0
4683
+ ## protobuf 3.3.0, protobuf-codegen 3.3.0, protobuf-json-mapping 3.3.0, protobuf-parse 3.3.0, protobuf-support 3.3.0
4690
4684
 
4691
4685
  ```
4692
4686
  Copyright (c) 2019 Stepan Koltsov
@@ -5760,6 +5754,33 @@ SOFTWARE.
5760
5754
 
5761
5755
  ```
5762
5756
 
5757
+ ## strum 0.26.1, strum_macros 0.26.1
5758
+
5759
+ ```
5760
+ MIT License
5761
+
5762
+ Copyright (c) 2019 Peter Glotfelty
5763
+
5764
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5765
+ of this software and associated documentation files (the "Software"), to deal
5766
+ in the Software without restriction, including without limitation the rights
5767
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
5768
+ copies of the Software, and to permit persons to whom the Software is
5769
+ furnished to do so, subject to the following conditions:
5770
+
5771
+ The above copyright notice and this permission notice shall be included in all
5772
+ copies or substantial portions of the Software.
5773
+
5774
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5775
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
5776
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
5777
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
5778
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
5779
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
5780
+ SOFTWARE.
5781
+
5782
+ ```
5783
+
5763
5784
  ## fslock 0.2.1
5764
5785
 
5765
5786
  ```
@@ -5841,6 +5862,32 @@ SOFTWARE.
5841
5862
 
5842
5863
  ```
5843
5864
 
5865
+ ## const-str 0.5.6
5866
+
5867
+ ```
5868
+ MIT License
5869
+
5870
+ Copyright (c) 2020 Nugine
5871
+
5872
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5873
+ of this software and associated documentation files (the "Software"), to deal
5874
+ in the Software without restriction, including without limitation the rights
5875
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
5876
+ copies of the Software, and to permit persons to whom the Software is
5877
+ furnished to do so, subject to the following conditions:
5878
+
5879
+ The above copyright notice and this permission notice shall be included in all
5880
+ copies or substantial portions of the Software.
5881
+
5882
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5883
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
5884
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
5885
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
5886
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
5887
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
5888
+ SOFTWARE.
5889
+ ```
5890
+
5844
5891
  ## tinyvec_macros 0.1.1
5845
5892
 
5846
5893
  ```
@@ -5949,7 +5996,7 @@ SOFTWARE.
5949
5996
 
5950
5997
  ```
5951
5998
 
5952
- ## cesu8 1.1.0, const-str 0.5.6, curve25519-dalek-derive 0.1.0, half 1.8.2, pqcrypto-internals 0.2.5, pqcrypto-kyber 0.7.9, pqcrypto-kyber 0.8.0, pqcrypto-traits 0.3.5, procfs-core 0.16.0, protobuf-parse 3.3.0, protobuf-support 3.3.0
5999
+ ## cesu8 1.1.0, curve25519-dalek-derive 0.1.0, half 1.8.2, neon 1.0.0, pqcrypto-internals 0.2.5, pqcrypto-kyber 0.7.9, pqcrypto-kyber 0.8.0, pqcrypto-traits 0.3.5
5953
6000
 
5954
6001
  ```
5955
6002
  MIT License
@@ -6063,7 +6110,7 @@ DEALINGS IN THE SOFTWARE.
6063
6110
 
6064
6111
  ```
6065
6112
 
6066
- ## adler 1.0.2, anyhow 1.0.79, async-trait 0.1.77, dyn-clone 1.0.16, fastrand 2.0.1, home 0.5.9, itoa 1.0.10, linkme 0.3.22, linkme-impl 0.3.22, linux-raw-sys 0.4.13, minimal-lexical 0.2.1, num_enum 0.6.1, num_enum_derive 0.6.1, once_cell 1.19.0, paste 1.0.14, pin-project-lite 0.2.13, prettyplease 0.2.16, proc-macro-crate 1.3.1, proc-macro2 1.0.78, quote 1.0.35, rustc-hash 1.1.0, rustix 0.38.30, semver 1.0.21, serde 1.0.195, serde_derive 1.0.195, serde_json 1.0.111, syn 1.0.109, syn 2.0.48, syn-mid 0.5.4, syn-mid 0.6.0, thiserror 1.0.56, thiserror-impl 1.0.56, unicode-ident 1.0.12, utf-8 0.7.6
6113
+ ## adler 1.0.2, anyhow 1.0.79, async-trait 0.1.77, dyn-clone 1.0.16, fastrand 2.0.1, home 0.5.9, itoa 1.0.10, linkme 0.3.22, linkme-impl 0.3.22, linux-raw-sys 0.4.13, minimal-lexical 0.2.1, num_enum 0.6.1, num_enum_derive 0.6.1, once_cell 1.19.0, paste 1.0.14, pin-project-lite 0.2.13, prettyplease 0.2.16, proc-macro-crate 1.3.1, proc-macro2 1.0.78, quote 1.0.35, rustc-hash 1.1.0, rustix 0.38.30, rustversion 1.0.14, semver 1.0.21, send_wrapper 0.6.0, serde 1.0.195, serde_derive 1.0.195, serde_json 1.0.111, syn 1.0.109, syn 2.0.48, syn-mid 0.6.0, thiserror 1.0.56, thiserror-impl 1.0.56, unicode-ident 1.0.12, utf-8 0.7.6
6067
6114
 
6068
6115
  ```
6069
6116
  Permission is hereby granted, free of charge, to any
@@ -6865,3 +6912,7 @@ written authorization of the copyright holder.
6865
6912
 
6866
6913
  ```
6867
6914
 
6915
+
6916
+ ## Kyber Patent License
6917
+
6918
+ <https://csrc.nist.gov/csrc/media/Projects/post-quantum-cryptography/documents/selected-algos-2022/nist-pqc-license-summary-and-excerpts.pdf>
package/dist/index.d.ts CHANGED
@@ -349,7 +349,7 @@ export declare class SealedSenderDecryptionResult {
349
349
  senderAci(): Aci | null;
350
350
  deviceId(): number;
351
351
  }
352
- interface CiphertextMessageConvertible {
352
+ export interface CiphertextMessageConvertible {
353
353
  asCiphertextMessage(): CiphertextMessage;
354
354
  }
355
355
  export declare class CiphertextMessage {
@@ -387,7 +387,7 @@ export declare function signalDecrypt(message: SignalMessage, address: ProtocolA
387
387
  export declare function signalDecryptPreKey(message: PreKeySignalMessage, address: ProtocolAddress, sessionStore: SessionStore, identityStore: IdentityKeyStore, prekeyStore: PreKeyStore, signedPrekeyStore: SignedPreKeyStore, kyberPrekeyStore: KyberPreKeyStore): Promise<Buffer>;
388
388
  export declare function sealedSenderEncryptMessage(message: Buffer, address: ProtocolAddress, senderCert: SenderCertificate, sessionStore: SessionStore, identityStore: IdentityKeyStore): Promise<Buffer>;
389
389
  export declare function sealedSenderEncrypt(content: UnidentifiedSenderMessageContent, address: ProtocolAddress, identityStore: IdentityKeyStore): Promise<Buffer>;
390
- type SealedSenderMultiRecipientEncryptOptions = {
390
+ export type SealedSenderMultiRecipientEncryptOptions = {
391
391
  content: UnidentifiedSenderMessageContent;
392
392
  recipients: ProtocolAddress[];
393
393
  excludedRecipients?: ServiceId[];
package/dist/net.d.ts CHANGED
@@ -1,9 +1,11 @@
1
+ /// <reference types="node" />
1
2
  import type { ReadonlyDeep } from 'type-fest';
3
+ import * as Native from '../Native';
2
4
  export declare enum Environment {
3
5
  Staging = 0,
4
6
  Production = 1
5
7
  }
6
- export type CDSAuthType = {
8
+ export type ServiceAuth = {
7
9
  username: string;
8
10
  password: string;
9
11
  };
@@ -25,9 +27,122 @@ export interface CDSResponseType<Aci, Pni> {
25
27
  entries: CDSResponseEntries<Aci, Pni>;
26
28
  debugPermitsUsed: number;
27
29
  }
30
+ export type ChatRequest = Readonly<{
31
+ verb: string;
32
+ path: string;
33
+ headers: ReadonlyArray<[string, string]>;
34
+ body?: Uint8Array;
35
+ timeoutMillis?: number;
36
+ }>;
28
37
  export declare class Net {
29
38
  private readonly _asyncContext;
39
+ private readonly _chatService;
30
40
  private readonly _connectionManager;
41
+ /**
42
+ * Instance of the {@link Svr3Client} to access SVR3.
43
+ */
44
+ svr3: Svr3Client;
31
45
  constructor(env: Environment);
32
- cdsiLookup({ username, password }: Readonly<CDSAuthType>, { e164s, acisAndAccessKeys, timeout, returnAcisWithoutUaks, }: ReadonlyDeep<CDSRequestOptionsType>): Promise<CDSResponseType<string, string>>;
46
+ disconnectChatService(): Promise<void>;
47
+ unauthenticatedFetchAndDebug(chatRequest: ChatRequest): Promise<Native.ResponseAndDebugInfo>;
48
+ unauthenticatedFetch(chatRequest: ChatRequest): Promise<Native.Response>;
49
+ static buildHttpRequest(chatRequest: ChatRequest): {
50
+ _nativeHandle: Native.HttpRequest;
51
+ };
52
+ cdsiLookup({ username, password }: Readonly<ServiceAuth>, { e164s, acisAndAccessKeys, timeout, returnAcisWithoutUaks, }: ReadonlyDeep<CDSRequestOptionsType>): Promise<CDSResponseType<string, string>>;
53
+ }
54
+ /**
55
+ * This interface provides functionality for communicating with SVR3
56
+ *
57
+ * Its instance can be obtained from an {@link Net#svr3} property
58
+ * of the {@link Net} class.
59
+ *
60
+ * Example usage:
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * import { Environment, Net } from '../net';
65
+ * // Obtain an instance
66
+ * const SVR3 = new Net(Environment.Staging).svr3;
67
+ * // Instantiate ServiceAuth with the username and password obtained from the Chat Server.
68
+ * const auth = { username: USERNAME, password: ENCLAVE_PASSWORD };
69
+ * // Store a value in SVR3. Here 10 is the number of permitted restore attempts.
70
+ * const shareSet = await SVR3.backup(SECRET_TO_BE_STORED, PASSWORD, 10, auth, TIMEOUT);
71
+ * const restoredSecret = await SVR3.restore( PASSWORD, shareSet, auth, TIMEOUT);
72
+ * ```
73
+ */
74
+ export interface Svr3Client {
75
+ /**
76
+ * Backup a secret to SVR3.
77
+ *
78
+ * Error messages are expected to be log-safe and not contain any sensitive
79
+ * data.
80
+ *
81
+ * @param what - The secret to be stored. Must be 32 bytes long.
82
+ * @param password - User-provided password that will be used to derive the
83
+ * encryption key for the secret.
84
+ * @param maxTries - Number of times the secret will be allowed to be guessed.
85
+ * Each call to {@link Svr3Client#restore} that has reached the server will
86
+ * decrement the counter. Must be positive.
87
+ * @param auth - An instance of {@link ServiceAuth} containing the username
88
+ * and password obtained from the Chat Server. The password is an OTP which is
89
+ * generally good for about 15 minutes, therefore it can be reused for the
90
+ * subsequent calls to either backup or restore that are not too far apart in
91
+ * time.
92
+ * @param opTimeoutMs - The maximum wall time libsignal is allowed to spend
93
+ * communicating with SVR3 service.
94
+ * @returns A `Promise` which--when awaited--will return a byte array with a
95
+ * serialized masked share set. It is supposed to be an opaque blob for the
96
+ * clients and therefore no assumptions should be made about its contents.
97
+ * This byte array should be stored by the clients and used to restore the
98
+ * secret along with the password. Please note that masked share set does not
99
+ * have to be treated as secret.
100
+ *
101
+ * The returned `Promise` can also fail due to the network issues (including the
102
+ * timeout), problems establishing the Noise connection to the enclaves, or
103
+ * invalid arguments' values. {@link IoError} errors can, in general, be
104
+ * retried, although there is already a retry-with-backoff mechanism inside
105
+ * libsignal used to connect to the SVR3 servers. Other exceptions are caused
106
+ * by the bad input or data missing on the server. They are therefore
107
+ * non-actionable and are guaranteed to be thrown again when retried.
108
+ */
109
+ backup(what: Buffer, password: string, maxTries: number, auth: Readonly<ServiceAuth>, opTimeoutMs: number): Promise<Buffer>;
110
+ /**
111
+ * Restore a secret from SVR3.
112
+ *
113
+ * Error messages are expected to be log-safe and not contain any sensitive
114
+ * data.
115
+ *
116
+ * @param password - User-provided password that will be used to derive the
117
+ * decryption key for the secret.
118
+ * @param shareSet - a serialized masked share set returned by a call to
119
+ * {@link Svr3Client#backup}.
120
+ * @param auth - An instance of {@link ServiceAuth} containing the username
121
+ * and password obtained from the Chat Server. The password is an OTP which is
122
+ * generally good for about 15 minutes, therefore it can be reused for the
123
+ * subsequent calls to either backup or restore that are not too far apart in
124
+ * time.
125
+ * @param opTimeoutMs - The maximum wall time libsignal is allowed to spend
126
+ * communicating with SVR3 service.
127
+ * @returns A `Promise` which--when awaited--will return a byte array with the
128
+ * restored secret.
129
+ *
130
+ * The returned `Promise` can also fail due to the network issues (including the
131
+ * timeout), problems establishing the Noise connection to the enclaves, or
132
+ * invalid arguments' values. {@link IoError} errors can, in general, be
133
+ * retried, although there is already a retry-with-backoff mechanism inside
134
+ * libsignal used to connect to the SVR3 servers. Other exceptions are caused
135
+ * by the bad input or data missing on the server. They are therefore
136
+ * non-actionable and are guaranteed to be thrown again when retried.
137
+ *
138
+ * - {@link SvrDataMissingError} is returned when the maximum restore attempts
139
+ * number has been exceeded or if the value has never been backed up.
140
+ * - {@link SvrRestoreFailedError} is returned when the combination of the
141
+ * password and masked share set does not result in successful restoration
142
+ * of the secret.
143
+ * - {@link SvrRequestFailedError} is returned when the de-serialization of a
144
+ * masked share set fails, or when the server requests fail for reasons
145
+ * other than "maximum attempts exceeded".
146
+ */
147
+ restore(password: string, shareSet: Buffer, auth: Readonly<ServiceAuth>, opTimeoutMs: number): Promise<Buffer>;
33
148
  }
package/dist/net.js CHANGED
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.Net = exports.Environment = void 0;
8
8
  const Native = require("../Native");
9
9
  const Address_1 = require("./Address");
10
+ const DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS = 5000;
10
11
  // This must match the libsignal-bridge Rust enum of the same name.
11
12
  var Environment;
12
13
  (function (Environment) {
@@ -15,8 +16,35 @@ var Environment;
15
16
  })(Environment = exports.Environment || (exports.Environment = {}));
16
17
  class Net {
17
18
  constructor(env) {
18
- this._asyncContext = Native.TokioAsyncContext_new();
19
- this._connectionManager = Native.ConnectionManager_new(env);
19
+ this._asyncContext = { _nativeHandle: Native.TokioAsyncContext_new() };
20
+ this._connectionManager = {
21
+ _nativeHandle: Native.ConnectionManager_new(env),
22
+ };
23
+ this._chatService = {
24
+ _nativeHandle: Native.ChatService_new(this._connectionManager, '', ''),
25
+ };
26
+ this.svr3 = new Svr3ClientImpl(this._asyncContext, this._connectionManager);
27
+ }
28
+ async disconnectChatService() {
29
+ await Native.ChatService_disconnect(this._asyncContext, this._chatService);
30
+ }
31
+ async unauthenticatedFetchAndDebug(chatRequest) {
32
+ return await Native.ChatService_unauth_send_and_debug(this._asyncContext, this._chatService, Net.buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS);
33
+ }
34
+ async unauthenticatedFetch(chatRequest) {
35
+ return await Native.ChatService_unauth_send(this._asyncContext, this._chatService, Net.buildHttpRequest(chatRequest), chatRequest.timeoutMillis ?? DEFAULT_CHAT_REQUEST_TIMEOUT_MILLIS);
36
+ }
37
+ static buildHttpRequest(chatRequest) {
38
+ const { verb, path, body, headers } = chatRequest;
39
+ const bodyBuffer = body !== undefined ? Buffer.from(body) : null;
40
+ const httpRequest = {
41
+ _nativeHandle: Native.HttpRequest_new(verb, path, bodyBuffer),
42
+ };
43
+ headers.forEach((header) => {
44
+ const [name, value] = header;
45
+ Native.HttpRequest_add_header(httpRequest, name, value);
46
+ });
47
+ return httpRequest;
20
48
  }
21
49
  async cdsiLookup({ username, password }, { e164s, acisAndAccessKeys, timeout, returnAcisWithoutUaks, }) {
22
50
  const request = { _nativeHandle: Native.LookupRequest_new() };
@@ -27,9 +55,23 @@ class Net {
27
55
  Native.LookupRequest_addAciAndAccessKey(request, Address_1.Aci.parseFromServiceIdString(aciStr).getServiceIdFixedWidthBinary(), Buffer.from(accessKeyStr, 'base64'));
28
56
  });
29
57
  Native.LookupRequest_setReturnAcisWithoutUaks(request, returnAcisWithoutUaks);
30
- const lookup = await Native.CdsiLookup_new({ _nativeHandle: this._asyncContext }, { _nativeHandle: this._connectionManager }, username, password, request, timeout);
31
- return await Native.CdsiLookup_complete({ _nativeHandle: this._asyncContext }, { _nativeHandle: lookup });
58
+ const lookup = await Native.CdsiLookup_new(this._asyncContext, this._connectionManager, username, password, request, timeout);
59
+ return await Native.CdsiLookup_complete(this._asyncContext, {
60
+ _nativeHandle: lookup,
61
+ });
32
62
  }
33
63
  }
34
64
  exports.Net = Net;
65
+ class Svr3ClientImpl {
66
+ constructor(_asyncContext, _connectionManager) {
67
+ this._asyncContext = _asyncContext;
68
+ this._connectionManager = _connectionManager;
69
+ }
70
+ async backup(what, password, maxTries, auth, opTimeoutMs) {
71
+ return Native.Svr3Backup(this._asyncContext, this._connectionManager, what, password, maxTries, auth.username, auth.password, opTimeoutMs);
72
+ }
73
+ async restore(password, shareSet, auth, opTimeoutMs) {
74
+ return Native.Svr3Restore(this._asyncContext, this._connectionManager, password, shareSet, auth.username, auth.password, opTimeoutMs);
75
+ }
76
+ }
35
77
  //# sourceMappingURL=net.js.map
@@ -9,7 +9,6 @@ const Native = require("../../../Native");
9
9
  const ByteArray_1 = require("../internal/ByteArray");
10
10
  const Constants_1 = require("../internal/Constants");
11
11
  const BackupAuthCredentialResponse_1 = require("./BackupAuthCredentialResponse");
12
- const BigIntUtil_1 = require("../internal/BigIntUtil");
13
12
  class BackupAuthCredentialRequest extends ByteArray_1.default {
14
13
  constructor(contents) {
15
14
  super(contents, Native.BackupAuthCredentialRequest_CheckValidContents);
@@ -19,7 +18,7 @@ class BackupAuthCredentialRequest extends ByteArray_1.default {
19
18
  return this.issueCredentialWithRandom(timestamp, receiptLevel, params, random);
20
19
  }
21
20
  issueCredentialWithRandom(timestamp, receiptLevel, params, random) {
22
- return new BackupAuthCredentialResponse_1.default(Native.BackupAuthCredentialRequest_IssueDeterministic(this.contents, timestamp, (0, BigIntUtil_1.bufferFromBigUInt64BE)(receiptLevel), params.contents, random));
21
+ return new BackupAuthCredentialResponse_1.default(Native.BackupAuthCredentialRequest_IssueDeterministic(this.contents, timestamp, receiptLevel, params.contents, random));
23
22
  }
24
23
  }
25
24
  exports.default = BackupAuthCredentialRequest;
@@ -9,7 +9,6 @@ const ByteArray_1 = require("../internal/ByteArray");
9
9
  const Native = require("../../../Native");
10
10
  const BackupAuthCredentialRequest_1 = require("./BackupAuthCredentialRequest");
11
11
  const BackupAuthCredential_1 = require("./BackupAuthCredential");
12
- const BigIntUtil_1 = require("../internal/BigIntUtil");
13
12
  class BackupAuthCredentialRequestContext extends ByteArray_1.default {
14
13
  constructor(contents) {
15
14
  super(contents, Native.BackupAuthCredentialRequestContext_CheckValidContents);
@@ -21,7 +20,7 @@ class BackupAuthCredentialRequestContext extends ByteArray_1.default {
21
20
  return new BackupAuthCredentialRequest_1.default(Native.BackupAuthCredentialRequestContext_GetRequest(this.contents));
22
21
  }
23
22
  receive(response, params, expectedReceiptLevel) {
24
- return new BackupAuthCredential_1.default(Native.BackupAuthCredentialRequestContext_ReceiveResponse(this.contents, response.contents, params.contents, (0, BigIntUtil_1.bufferFromBigUInt64BE)(expectedReceiptLevel)));
23
+ return new BackupAuthCredential_1.default(Native.BackupAuthCredentialRequestContext_ReceiveResponse(this.contents, response.contents, params.contents, expectedReceiptLevel));
25
24
  }
26
25
  }
27
26
  exports.default = BackupAuthCredentialRequestContext;
@@ -14,7 +14,7 @@ class ReceiptCredential extends ByteArray_1.default {
14
14
  return Native.ReceiptCredential_GetReceiptExpirationTime(this.contents);
15
15
  }
16
16
  getReceiptLevel() {
17
- return Native.ReceiptCredential_GetReceiptLevel(this.contents).readBigUInt64BE();
17
+ return Native.ReceiptCredential_GetReceiptLevel(this.contents);
18
18
  }
19
19
  }
20
20
  exports.default = ReceiptCredential;
@@ -15,7 +15,7 @@ class ReceiptCredentialPresentation extends ByteArray_1.default {
15
15
  return Native.ReceiptCredentialPresentation_GetReceiptExpirationTime(this.contents);
16
16
  }
17
17
  getReceiptLevel() {
18
- return Native.ReceiptCredentialPresentation_GetReceiptLevel(this.contents).readBigUInt64BE();
18
+ return Native.ReceiptCredentialPresentation_GetReceiptLevel(this.contents);
19
19
  }
20
20
  getReceiptSerialBytes() {
21
21
  return new ReceiptSerial_1.default(Native.ReceiptCredentialPresentation_GetReceiptSerial(this.contents));
@@ -7,7 +7,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  const crypto_1 = require("crypto");
8
8
  const Native = require("../../../Native");
9
9
  const Constants_1 = require("../internal/Constants");
10
- const BigIntUtil_1 = require("../internal/BigIntUtil");
11
10
  const ReceiptCredentialResponse_1 = require("./ReceiptCredentialResponse");
12
11
  class ServerZkReceiptOperations {
13
12
  constructor(serverSecretParams) {
@@ -18,7 +17,7 @@ class ServerZkReceiptOperations {
18
17
  return this.issueReceiptCredentialWithRandom(random, receiptCredentialRequest, receiptExpirationTime, receiptLevel);
19
18
  }
20
19
  issueReceiptCredentialWithRandom(random, receiptCredentialRequest, receiptExpirationTime, receiptLevel) {
21
- return new ReceiptCredentialResponse_1.default(Native.ServerSecretParams_IssueReceiptCredentialDeterministic(this.serverSecretParams.getContents(), random, receiptCredentialRequest.getContents(), receiptExpirationTime, (0, BigIntUtil_1.bufferFromBigUInt64BE)(receiptLevel)));
20
+ return new ReceiptCredentialResponse_1.default(Native.ServerSecretParams_IssueReceiptCredentialDeterministic(this.serverSecretParams.getContents(), random, receiptCredentialRequest.getContents(), receiptExpirationTime, receiptLevel));
22
21
  }
23
22
  verifyReceiptCredentialPresentation(receiptCredentialPresentation) {
24
23
  Native.ServerSecretParams_VerifyReceiptCredentialPresentation(this.serverSecretParams.getContents(), receiptCredentialPresentation.getContents());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signalapp/libsignal-client",
3
- "version": "0.40.0",
3
+ "version": "0.41.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
@@ -1,2 +0,0 @@
1
- /// <reference types="node" />
2
- export declare function bufferFromBigUInt64BE(value: bigint): Buffer;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- //
3
- // Copyright 2021 Signal Messenger, LLC.
4
- // SPDX-License-Identifier: AGPL-3.0-only
5
- //
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.bufferFromBigUInt64BE = void 0;
8
- const UINT64_MAX = 0xffffffffffffffffn;
9
- function bufferFromBigUInt64BE(value) {
10
- if (value < 0 || value > UINT64_MAX) {
11
- throw new RangeError(`value ${value} isn't representable as a u64`);
12
- }
13
- const result = Buffer.alloc(8);
14
- result.writeBigUInt64BE(value);
15
- return result;
16
- }
17
- exports.bufferFromBigUInt64BE = bufferFromBigUInt64BE;
18
- //# sourceMappingURL=BigIntUtil.js.map