@signalapp/libsignal-client 0.27.0 → 0.29.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
@@ -306,6 +306,11 @@ export function ServerSecretParams_SignDeterministic(params: Serialized<ServerSe
306
306
  export function ServerSecretParams_VerifyAuthCredentialPresentation(serverSecretParams: Serialized<ServerSecretParams>, groupPublicParams: Serialized<GroupPublicParams>, presentationBytes: Buffer, currentTimeInSeconds: Timestamp): void;
307
307
  export function ServerSecretParams_VerifyProfileKeyCredentialPresentation(serverSecretParams: Serialized<ServerSecretParams>, groupPublicParams: Serialized<GroupPublicParams>, presentationBytes: Buffer, currentTimeInSeconds: Timestamp): void;
308
308
  export function ServerSecretParams_VerifyReceiptCredentialPresentation(serverSecretParams: Serialized<ServerSecretParams>, presentation: Serialized<ReceiptCredentialPresentation>): void;
309
+ export function ServiceId_ParseFromServiceIdBinary(input: Buffer): Buffer;
310
+ export function ServiceId_ParseFromServiceIdString(input: string): Buffer;
311
+ export function ServiceId_ServiceIdBinary(value: Buffer): Buffer;
312
+ export function ServiceId_ServiceIdLog(value: Buffer): string;
313
+ export function ServiceId_ServiceIdString(value: Buffer): string;
309
314
  export function SessionBuilder_ProcessPreKeyBundle(bundle: Wrapper<PreKeyBundle>, protocolAddress: Wrapper<ProtocolAddress>, sessionStore: SessionStore, identityKeyStore: IdentityKeyStore, ctx: null): Promise<void>;
310
315
  export function SessionCipher_DecryptPreKeySignalMessage(message: Wrapper<PreKeySignalMessage>, protocolAddress: Wrapper<ProtocolAddress>, sessionStore: SessionStore, identityKeyStore: IdentityKeyStore, prekeyStore: PreKeyStore, signedPrekeyStore: SignedPreKeyStore, kyberPrekeyStore: KyberPreKeyStore, ctx: null): Promise<Buffer>;
311
316
  export function SessionCipher_DecryptSignalMessage(message: Wrapper<SignalMessage>, protocolAddress: Wrapper<ProtocolAddress>, sessionStore: SessionStore, identityKeyStore: IdentityKeyStore, ctx: null): Promise<Buffer>;
@@ -345,6 +350,8 @@ export function UnidentifiedSenderMessageContent_GetMsgType(m: Wrapper<Unidentif
345
350
  export function UnidentifiedSenderMessageContent_GetSenderCert(m: Wrapper<UnidentifiedSenderMessageContent>): SenderCertificate;
346
351
  export function UnidentifiedSenderMessageContent_New(message: Wrapper<CiphertextMessage>, sender: Wrapper<SenderCertificate>, contentHint: number, groupId: Buffer | null): UnidentifiedSenderMessageContent;
347
352
  export function UnidentifiedSenderMessageContent_Serialize(obj: Wrapper<UnidentifiedSenderMessageContent>): Buffer;
353
+ export function UsernameLink_Create(username: string): Buffer;
354
+ export function UsernameLink_DecryptUsername(entropy: Buffer, encryptedUsername: Buffer): string;
348
355
  export function Username_CandidatesFrom(nickname: string, minLen: number, maxLen: number): string;
349
356
  export function Username_Hash(username: string): Buffer;
350
357
  export function Username_Proof(username: string, randomness: Buffer): Buffer;
package/dist/Address.d.ts CHANGED
@@ -1,9 +1,49 @@
1
+ /// <reference types="node" />
1
2
  import * as Native from '../Native';
3
+ declare enum ServiceIdKind {
4
+ Aci = 0,
5
+ Pni = 1
6
+ }
7
+ type ThisType<T extends {
8
+ prototype: unknown;
9
+ }> = T['prototype'];
10
+ export declare class ServiceId extends Object {
11
+ private readonly serviceIdFixedWidthBinary;
12
+ protected constructor(serviceIdFixedWidthBinary: Buffer);
13
+ protected static fromUuidBytesAndKind<T extends typeof ServiceId>(this: T, uuidBytes: ArrayLike<number>, kind: ServiceIdKind): ThisType<T>;
14
+ getServiceIdBinary(): Buffer;
15
+ getServiceIdString(): string;
16
+ toString(): string;
17
+ private static parseFromServiceIdFixedWidthBinary;
18
+ static parseFromServiceIdBinary(serviceIdBinary: Buffer): ServiceId;
19
+ static parseFromServiceIdString(serviceIdString: string): ServiceId;
20
+ getRawUuid(): string;
21
+ getRawUuidBytes(): Buffer;
22
+ isEqual(other: ServiceId): boolean;
23
+ }
24
+ export declare class Aci extends ServiceId {
25
+ private readonly __type?;
26
+ static fromUuid(uuidString: string): Aci;
27
+ static fromUuidBytes(uuidBytes: ArrayLike<number>): Aci;
28
+ }
29
+ export declare class Pni extends ServiceId {
30
+ private readonly __type?;
31
+ static fromUuid(uuidString: string): Pni;
32
+ static fromUuidBytes(uuidBytes: ArrayLike<number>): Pni;
33
+ }
2
34
  export declare class ProtocolAddress {
3
35
  readonly _nativeHandle: Native.ProtocolAddress;
4
36
  private constructor();
5
37
  static _fromNativeHandle(handle: Native.ProtocolAddress): ProtocolAddress;
6
- static new(name: string, deviceId: number): ProtocolAddress;
38
+ static new(name: string | ServiceId, deviceId: number): ProtocolAddress;
7
39
  name(): string;
40
+ /**
41
+ * Returns a ServiceId if this address contains a valid ServiceId, `null` otherwise.
42
+ *
43
+ * In a future release ProtocolAddresses will *only* support ServiceIds.
44
+ */
45
+ serviceId(): ServiceId | null;
8
46
  deviceId(): number;
47
+ toString(): string;
9
48
  }
49
+ export {};
package/dist/Address.js CHANGED
@@ -4,8 +4,83 @@
4
4
  // SPDX-License-Identifier: AGPL-3.0-only
5
5
  //
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.ProtocolAddress = void 0;
7
+ exports.ProtocolAddress = exports.Pni = exports.Aci = exports.ServiceId = void 0;
8
8
  const Native = require("../Native");
9
+ const uuid = require("uuid");
10
+ var ServiceIdKind;
11
+ (function (ServiceIdKind) {
12
+ ServiceIdKind[ServiceIdKind["Aci"] = 0] = "Aci";
13
+ ServiceIdKind[ServiceIdKind["Pni"] = 1] = "Pni";
14
+ })(ServiceIdKind || (ServiceIdKind = {}));
15
+ const SERVICE_ID_FIXED_WIDTH_BINARY_LEN = 17;
16
+ class ServiceId extends Object {
17
+ constructor(serviceIdFixedWidthBinary) {
18
+ super();
19
+ if (serviceIdFixedWidthBinary.length != SERVICE_ID_FIXED_WIDTH_BINARY_LEN) {
20
+ throw new TypeError('invalid Service-Id-FixedWidthBinary');
21
+ }
22
+ this.serviceIdFixedWidthBinary = serviceIdFixedWidthBinary;
23
+ }
24
+ static fromUuidBytesAndKind(uuidBytes, kind) {
25
+ const buffer = Buffer.alloc(SERVICE_ID_FIXED_WIDTH_BINARY_LEN);
26
+ buffer[0] = kind;
27
+ buffer.set(uuidBytes, 1);
28
+ return new this(buffer);
29
+ }
30
+ getServiceIdBinary() {
31
+ return Native.ServiceId_ServiceIdBinary(this.serviceIdFixedWidthBinary);
32
+ }
33
+ getServiceIdString() {
34
+ return Native.ServiceId_ServiceIdString(this.serviceIdFixedWidthBinary);
35
+ }
36
+ toString() {
37
+ return Native.ServiceId_ServiceIdLog(this.serviceIdFixedWidthBinary);
38
+ }
39
+ static parseFromServiceIdFixedWidthBinary(serviceIdFixedWidthBinary) {
40
+ switch (serviceIdFixedWidthBinary[0]) {
41
+ case ServiceIdKind.Aci:
42
+ return new Aci(serviceIdFixedWidthBinary);
43
+ case ServiceIdKind.Pni:
44
+ return new Pni(serviceIdFixedWidthBinary);
45
+ default:
46
+ throw new TypeError('unknown type in Service-Id-FixedWidthBinary');
47
+ }
48
+ }
49
+ static parseFromServiceIdBinary(serviceIdBinary) {
50
+ return ServiceId.parseFromServiceIdFixedWidthBinary(Native.ServiceId_ParseFromServiceIdBinary(serviceIdBinary));
51
+ }
52
+ static parseFromServiceIdString(serviceIdString) {
53
+ return ServiceId.parseFromServiceIdFixedWidthBinary(Native.ServiceId_ParseFromServiceIdString(serviceIdString));
54
+ }
55
+ getRawUuid() {
56
+ return uuid.stringify(this.serviceIdFixedWidthBinary, 1);
57
+ }
58
+ getRawUuidBytes() {
59
+ return Buffer.from(this.serviceIdFixedWidthBinary.buffer, 1);
60
+ }
61
+ isEqual(other) {
62
+ return this.serviceIdFixedWidthBinary.equals(other.serviceIdFixedWidthBinary);
63
+ }
64
+ }
65
+ exports.ServiceId = ServiceId;
66
+ class Aci extends ServiceId {
67
+ static fromUuid(uuidString) {
68
+ return this.fromUuidBytes(uuid.parse(uuidString));
69
+ }
70
+ static fromUuidBytes(uuidBytes) {
71
+ return super.fromUuidBytesAndKind(uuidBytes, ServiceIdKind.Aci);
72
+ }
73
+ }
74
+ exports.Aci = Aci;
75
+ class Pni extends ServiceId {
76
+ static fromUuid(uuidString) {
77
+ return this.fromUuidBytes(uuid.parse(uuidString));
78
+ }
79
+ static fromUuidBytes(uuidBytes) {
80
+ return super.fromUuidBytesAndKind(uuidBytes, ServiceIdKind.Pni);
81
+ }
82
+ }
83
+ exports.Pni = Pni;
9
84
  class ProtocolAddress {
10
85
  constructor(handle) {
11
86
  this._nativeHandle = handle;
@@ -14,14 +89,33 @@ class ProtocolAddress {
14
89
  return new ProtocolAddress(handle);
15
90
  }
16
91
  static new(name, deviceId) {
92
+ if (typeof name !== 'string') {
93
+ name = name.getServiceIdString();
94
+ }
17
95
  return new ProtocolAddress(Native.ProtocolAddress_New(name, deviceId));
18
96
  }
19
97
  name() {
20
98
  return Native.ProtocolAddress_Name(this);
21
99
  }
100
+ /**
101
+ * Returns a ServiceId if this address contains a valid ServiceId, `null` otherwise.
102
+ *
103
+ * In a future release ProtocolAddresses will *only* support ServiceIds.
104
+ */
105
+ serviceId() {
106
+ try {
107
+ return ServiceId.parseFromServiceIdString(this.name());
108
+ }
109
+ catch (_a) {
110
+ return null;
111
+ }
112
+ }
22
113
  deviceId() {
23
114
  return Native.ProtocolAddress_DeviceId(this);
24
115
  }
116
+ toString() {
117
+ return `${this.name()}.${this.deviceId()}`;
118
+ }
25
119
  }
26
120
  exports.ProtocolAddress = ProtocolAddress;
27
121
  //# sourceMappingURL=Address.js.map
package/dist/Errors.d.ts CHANGED
@@ -17,7 +17,10 @@ export declare enum ErrorCode {
17
17
  NicknameTooLong = 13,
18
18
  IoError = 14,
19
19
  InvalidMediaInput = 15,
20
- UnsupportedMediaInput = 16
20
+ UnsupportedMediaInput = 16,
21
+ InputDataTooLong = 17,
22
+ InvalidEntropyDataLength = 18,
23
+ InvalidUsernameLinkEncryptedData = 19
21
24
  }
22
25
  export declare class LibSignalErrorBase extends Error {
23
26
  readonly code: ErrorCode;
@@ -72,6 +75,15 @@ export type NicknameTooShortError = LibSignalErrorCommon & {
72
75
  export type NicknameTooLongError = LibSignalErrorCommon & {
73
76
  code: ErrorCode.NicknameTooLong;
74
77
  };
78
+ export type InputDataTooLong = LibSignalErrorCommon & {
79
+ code: ErrorCode.InputDataTooLong;
80
+ };
81
+ export type InvalidEntropyDataLength = LibSignalErrorCommon & {
82
+ code: ErrorCode.InvalidEntropyDataLength;
83
+ };
84
+ export type InvalidUsernameLinkEncryptedData = LibSignalErrorCommon & {
85
+ code: ErrorCode.InvalidUsernameLinkEncryptedData;
86
+ };
75
87
  export type IoError = LibSignalErrorCommon & {
76
88
  code: ErrorCode.IoError;
77
89
  };
@@ -81,4 +93,4 @@ export type InvalidMediaInputError = LibSignalErrorCommon & {
81
93
  export type UnsupportedMediaInputError = LibSignalErrorCommon & {
82
94
  code: ErrorCode.UnsupportedMediaInput;
83
95
  };
84
- export type LibSignalError = GenericError | DuplicatedMessageError | SealedSenderSelfSendError | UntrustedIdentityError | InvalidRegistrationIdError | VerificationFailedError | InvalidSessionError | InvalidSenderKeySessionError | CannotBeEmptyError | CannotStartWithDigitError | MissingSeparatorError | BadNicknameCharacterError | NicknameTooShortError | NicknameTooLongError | IoError | InvalidMediaInputError | UnsupportedMediaInputError;
96
+ export type LibSignalError = GenericError | DuplicatedMessageError | SealedSenderSelfSendError | UntrustedIdentityError | InvalidRegistrationIdError | VerificationFailedError | InvalidSessionError | InvalidSenderKeySessionError | CannotBeEmptyError | CannotStartWithDigitError | MissingSeparatorError | BadNicknameCharacterError | NicknameTooShortError | NicknameTooLongError | InputDataTooLong | InvalidEntropyDataLength | InvalidUsernameLinkEncryptedData | IoError | InvalidMediaInputError | UnsupportedMediaInputError;
package/dist/Errors.js CHANGED
@@ -25,6 +25,9 @@ var ErrorCode;
25
25
  ErrorCode[ErrorCode["IoError"] = 14] = "IoError";
26
26
  ErrorCode[ErrorCode["InvalidMediaInput"] = 15] = "InvalidMediaInput";
27
27
  ErrorCode[ErrorCode["UnsupportedMediaInput"] = 16] = "UnsupportedMediaInput";
28
+ ErrorCode[ErrorCode["InputDataTooLong"] = 17] = "InputDataTooLong";
29
+ ErrorCode[ErrorCode["InvalidEntropyDataLength"] = 18] = "InvalidEntropyDataLength";
30
+ ErrorCode[ErrorCode["InvalidUsernameLinkEncryptedData"] = 19] = "InvalidUsernameLinkEncryptedData";
28
31
  })(ErrorCode = exports.ErrorCode || (exports.ErrorCode = {}));
29
32
  class LibSignalErrorBase extends Error {
30
33
  constructor(message, name, operation, extraProps) {
@@ -1,6 +1,12 @@
1
1
  /// <reference types="node" />
2
+ export type UsernameLink = {
3
+ entropy: Buffer;
4
+ encryptedUsername: Buffer;
5
+ };
2
6
  export declare function generateCandidates(nickname: string, minNicknameLength: number, maxNicknameLength: number): string[];
3
7
  export declare function hash(username: string): Buffer;
4
8
  export declare function generateProof(username: string): Buffer;
5
9
  export declare function generateProofWithRandom(username: string, random: Buffer): Buffer;
10
+ export declare function decryptUsernameLink(usernameLink: UsernameLink): string;
11
+ export declare function createUsernameLink(username: string): UsernameLink;
6
12
  export declare function verifyProof(proof: Buffer, hash: Buffer): void;
package/dist/usernames.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.verifyProof = exports.generateProofWithRandom = exports.generateProof = exports.hash = exports.generateCandidates = void 0;
7
+ exports.verifyProof = exports.createUsernameLink = exports.decryptUsernameLink = exports.generateProofWithRandom = exports.generateProof = exports.hash = exports.generateCandidates = void 0;
8
8
  /* eslint @typescript-eslint/no-shadow: ["error", { "allow": ["hash"] }] */
9
9
  const crypto_1 = require("crypto");
10
10
  const Constants_1 = require("./zkgroup/internal/Constants");
@@ -26,6 +26,17 @@ function generateProofWithRandom(username, random) {
26
26
  return Native.Username_Proof(username, random);
27
27
  }
28
28
  exports.generateProofWithRandom = generateProofWithRandom;
29
+ function decryptUsernameLink(usernameLink) {
30
+ return Native.UsernameLink_DecryptUsername(usernameLink.entropy, usernameLink.encryptedUsername);
31
+ }
32
+ exports.decryptUsernameLink = decryptUsernameLink;
33
+ function createUsernameLink(username) {
34
+ const usernameLinkData = Native.UsernameLink_Create(username);
35
+ const entropy = usernameLinkData.slice(0, 32);
36
+ const encryptedUsername = usernameLinkData.slice(32);
37
+ return { entropy, encryptedUsername };
38
+ }
39
+ exports.createUsernameLink = createUsernameLink;
29
40
  // Only for testing. Will throw on failure.
30
41
  function verifyProof(proof, hash) {
31
42
  Native.Username_Verify(proof, hash);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signalapp/libsignal-client",
3
- "version": "0.27.0",
3
+ "version": "0.29.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