@signalapp/libsignal-client 0.41.1 → 0.42.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.
Files changed (37) hide show
  1. package/Native.d.ts +25 -25
  2. package/dist/acknowledgments.md +72 -68
  3. package/dist/zkgroup/auth/ClientZkAuthOperations.d.ts +0 -5
  4. package/dist/zkgroup/auth/ClientZkAuthOperations.js +0 -11
  5. package/dist/zkgroup/auth/ServerZkAuthOperations.d.ts +2 -3
  6. package/dist/zkgroup/auth/ServerZkAuthOperations.js +7 -8
  7. package/dist/zkgroup/groupsend/GroupSendDerivedKeyPair.d.ts +23 -0
  8. package/dist/zkgroup/groupsend/GroupSendDerivedKeyPair.js +34 -0
  9. package/dist/zkgroup/groupsend/GroupSendEndorsement.d.ts +68 -0
  10. package/dist/zkgroup/groupsend/GroupSendEndorsement.js +84 -0
  11. package/dist/zkgroup/groupsend/GroupSendEndorsementsResponse.d.ts +73 -0
  12. package/dist/zkgroup/groupsend/GroupSendEndorsementsResponse.js +102 -0
  13. package/dist/zkgroup/groupsend/GroupSendFullToken.d.ts +23 -0
  14. package/dist/zkgroup/groupsend/GroupSendFullToken.js +36 -0
  15. package/dist/zkgroup/groupsend/GroupSendToken.d.ts +22 -0
  16. package/dist/zkgroup/groupsend/GroupSendToken.js +34 -0
  17. package/dist/zkgroup/index.d.ts +5 -5
  18. package/dist/zkgroup/index.js +12 -12
  19. package/dist/zkgroup/internal/ByteArray.d.ts +2 -1
  20. package/dist/zkgroup/internal/ByteArray.js +9 -2
  21. package/package.json +2 -1
  22. package/prebuilds/darwin-arm64/node.napi.node +0 -0
  23. package/prebuilds/darwin-x64/node.napi.node +0 -0
  24. package/prebuilds/linux-arm64/node.napi.node +0 -0
  25. package/prebuilds/linux-x64/node.napi.node +0 -0
  26. package/prebuilds/win32-arm64/node.napi.node +0 -0
  27. package/prebuilds/win32-x64/node.napi.node +0 -0
  28. package/dist/zkgroup/auth/AuthCredential.d.ts +0 -6
  29. package/dist/zkgroup/auth/AuthCredential.js +0 -15
  30. package/dist/zkgroup/auth/AuthCredentialResponse.d.ts +0 -6
  31. package/dist/zkgroup/auth/AuthCredentialResponse.js +0 -15
  32. package/dist/zkgroup/groupsend/GroupSendCredential.d.ts +0 -30
  33. package/dist/zkgroup/groupsend/GroupSendCredential.js +0 -45
  34. package/dist/zkgroup/groupsend/GroupSendCredentialPresentation.d.ts +0 -24
  35. package/dist/zkgroup/groupsend/GroupSendCredentialPresentation.js +0 -34
  36. package/dist/zkgroup/groupsend/GroupSendCredentialResponse.d.ts +0 -67
  37. package/dist/zkgroup/groupsend/GroupSendCredentialResponse.js +0 -87
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ //
3
+ // Copyright 2024 Signal Messenger, LLC.
4
+ // SPDX-License-Identifier: AGPL-3.0-only
5
+ //
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const ByteArray_1 = require("../internal/ByteArray");
8
+ const Native = require("../../../Native");
9
+ /**
10
+ * The key pair used to issue and verify group send endorsements.
11
+ *
12
+ * Group send endorsements use a different key pair depending on the endorsement's expiration (but
13
+ * not the user ID being endorsed). The server may cache these keys to avoid the (small) cost of
14
+ * deriving them from the root key in {@link ServerSecretParams}. The key object stores the
15
+ * expiration so that it doesn't need to be provided again when issuing endorsements.
16
+ *
17
+ * @see {@link GroupSendEndorsementsResponse.issue}
18
+ * @see {@link GroupSendFullToken#verify}
19
+ */
20
+ class GroupSendDerivedKeyPair extends ByteArray_1.default {
21
+ constructor(contents) {
22
+ super(contents, Native.GroupSendDerivedKeyPair_CheckValidContents);
23
+ }
24
+ /**
25
+ * Derives a new key for group send endorsements that expire at `expiration`.
26
+ *
27
+ * `expiration` must be day-aligned as a protection against fingerprinting by the issuing server.
28
+ */
29
+ static forExpiration(expiration, params) {
30
+ return new GroupSendDerivedKeyPair(Native.GroupSendDerivedKeyPair_ForExpiration(Math.floor(expiration.getTime() / 1000), params.contents));
31
+ }
32
+ }
33
+ exports.default = GroupSendDerivedKeyPair;
34
+ //# sourceMappingURL=GroupSendDerivedKeyPair.js.map
@@ -0,0 +1,68 @@
1
+ /// <reference types="node" />
2
+ import ByteArray, { UNCHECKED_AND_UNCLONED } from '../internal/ByteArray';
3
+ import GroupSecretParams from '../groups/GroupSecretParams';
4
+ import GroupSendFullToken from './GroupSendFullToken';
5
+ import GroupSendToken from './GroupSendToken';
6
+ /**
7
+ * An endorsement for a user or set of users in a group.
8
+ *
9
+ * GroupSendEndorsements provide a form of authorization by demonstrating that the holder of the
10
+ * endorsement is in a group with a particular user or set of users. They can be
11
+ * [combined]{@link #combine} and [removed]{@link #byRemoving} in a set-like fashion.
12
+ *
13
+ * The endorsement "flow" starts with receiving a {@link GroupSendEndorsementsResponse} from the
14
+ * group server, which contains endorsements for all members in a group (including the local user).
15
+ * The response object provides the single expiration for all the endorsements. From there, the
16
+ * `receive` method produces a {@link ReceivedEndorsements}, which exposes the individual
17
+ * endorsements as well as a combined endorsement for everyone but the local user. Clients should
18
+ * save these endorsements and the expiration with the group state.
19
+ *
20
+ * When it comes time to send a message to an individual user, clients should check to see if they
21
+ * have a {@link GroupSendToken} for that user, and generate and cache one using
22
+ * {@link GroupSendEndorsement#toToken} if not. The token should then be converted to a full token
23
+ * using {@link GroupSendToken#toFullToken}, providing the expiration saved previously. Finally, the
24
+ * serialized full token can be used as authorization in a request to the chat server.
25
+ *
26
+ * Similarly, when it comes time to send a message to the group, clients should start by
27
+ * [removing]{@link #byRemoving} the endorsements of any users they are excluding (say, because they
28
+ * need a Sender Key Distribution Message first), and then converting the resulting endorsement to a
29
+ * token. From there, the token can be converted to a full token and serialized as for an individual
30
+ * send. (Saving the repeated work of converting to a token is left to the clients here; worst case,
31
+ * it's still cheaper than a usual zkgroup presentation.)
32
+ */
33
+ export default class GroupSendEndorsement extends ByteArray {
34
+ constructor(contents: Buffer, marker?: typeof UNCHECKED_AND_UNCLONED);
35
+ /**
36
+ * Combines several endorsements into one.
37
+ *
38
+ * For example, if you have endorsements to send to Meredith and Aruna individually, then you can
39
+ * combine them to produce an endorsement to send a multi-recipient message to the two of them.
40
+ */
41
+ static combine(endorsements: GroupSendEndorsement[]): GroupSendEndorsement;
42
+ /**
43
+ * Removes an endorsement (individual or combined) from this combined endorsement.
44
+ *
45
+ * If `this` is *not* a combined endorsement, or `toRemove` includes endorsements that were not
46
+ * combined into `this`, the result will not generate valid tokens.
47
+ */
48
+ byRemoving(toRemove: GroupSendEndorsement): GroupSendEndorsement;
49
+ /**
50
+ * Generates a cacheable token used to authenticate sends.
51
+ *
52
+ * The token is no longer associated with the group; it merely identifies the user or set of users
53
+ * referenced by this endorsement. (Of course, a set of users is a pretty good stand-in for a
54
+ * group.)
55
+ *
56
+ * @see {@link GroupSendToken}
57
+ */
58
+ toToken(groupParams: GroupSecretParams): GroupSendToken;
59
+ /**
60
+ * Generates a token used to authenticate sends, ready to put in an auth header.
61
+ *
62
+ * `expiration` must be the same expiration that was in the original {@link
63
+ * GroupSendEndorsementsResponse}, or the resulting token will fail to verify.
64
+ *
65
+ * Equivalent to {@link #toToken} followed by {@link GroupSendToken#toFullToken}.
66
+ */
67
+ toFullToken(groupParams: GroupSecretParams, expiration: Date): GroupSendFullToken;
68
+ }
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ //
3
+ // Copyright 2024 Signal Messenger, LLC.
4
+ // SPDX-License-Identifier: AGPL-3.0-only
5
+ //
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const ByteArray_1 = require("../internal/ByteArray");
8
+ const Native = require("../../../Native");
9
+ const GroupSendToken_1 = require("./GroupSendToken");
10
+ /**
11
+ * An endorsement for a user or set of users in a group.
12
+ *
13
+ * GroupSendEndorsements provide a form of authorization by demonstrating that the holder of the
14
+ * endorsement is in a group with a particular user or set of users. They can be
15
+ * [combined]{@link #combine} and [removed]{@link #byRemoving} in a set-like fashion.
16
+ *
17
+ * The endorsement "flow" starts with receiving a {@link GroupSendEndorsementsResponse} from the
18
+ * group server, which contains endorsements for all members in a group (including the local user).
19
+ * The response object provides the single expiration for all the endorsements. From there, the
20
+ * `receive` method produces a {@link ReceivedEndorsements}, which exposes the individual
21
+ * endorsements as well as a combined endorsement for everyone but the local user. Clients should
22
+ * save these endorsements and the expiration with the group state.
23
+ *
24
+ * When it comes time to send a message to an individual user, clients should check to see if they
25
+ * have a {@link GroupSendToken} for that user, and generate and cache one using
26
+ * {@link GroupSendEndorsement#toToken} if not. The token should then be converted to a full token
27
+ * using {@link GroupSendToken#toFullToken}, providing the expiration saved previously. Finally, the
28
+ * serialized full token can be used as authorization in a request to the chat server.
29
+ *
30
+ * Similarly, when it comes time to send a message to the group, clients should start by
31
+ * [removing]{@link #byRemoving} the endorsements of any users they are excluding (say, because they
32
+ * need a Sender Key Distribution Message first), and then converting the resulting endorsement to a
33
+ * token. From there, the token can be converted to a full token and serialized as for an individual
34
+ * send. (Saving the repeated work of converting to a token is left to the clients here; worst case,
35
+ * it's still cheaper than a usual zkgroup presentation.)
36
+ */
37
+ class GroupSendEndorsement extends ByteArray_1.default {
38
+ constructor(contents, marker) {
39
+ super(contents, marker ?? Native.GroupSendEndorsement_CheckValidContents);
40
+ }
41
+ /**
42
+ * Combines several endorsements into one.
43
+ *
44
+ * For example, if you have endorsements to send to Meredith and Aruna individually, then you can
45
+ * combine them to produce an endorsement to send a multi-recipient message to the two of them.
46
+ */
47
+ static combine(endorsements) {
48
+ return new GroupSendEndorsement(Native.GroupSendEndorsement_Combine(endorsements.map((next) => next.contents)));
49
+ }
50
+ /**
51
+ * Removes an endorsement (individual or combined) from this combined endorsement.
52
+ *
53
+ * If `this` is *not* a combined endorsement, or `toRemove` includes endorsements that were not
54
+ * combined into `this`, the result will not generate valid tokens.
55
+ */
56
+ byRemoving(toRemove) {
57
+ return new GroupSendEndorsement(Native.GroupSendEndorsement_Remove(this.contents, toRemove.contents));
58
+ }
59
+ /**
60
+ * Generates a cacheable token used to authenticate sends.
61
+ *
62
+ * The token is no longer associated with the group; it merely identifies the user or set of users
63
+ * referenced by this endorsement. (Of course, a set of users is a pretty good stand-in for a
64
+ * group.)
65
+ *
66
+ * @see {@link GroupSendToken}
67
+ */
68
+ toToken(groupParams) {
69
+ return new GroupSendToken_1.default(Native.GroupSendEndorsement_ToToken(this.contents, groupParams.contents));
70
+ }
71
+ /**
72
+ * Generates a token used to authenticate sends, ready to put in an auth header.
73
+ *
74
+ * `expiration` must be the same expiration that was in the original {@link
75
+ * GroupSendEndorsementsResponse}, or the resulting token will fail to verify.
76
+ *
77
+ * Equivalent to {@link #toToken} followed by {@link GroupSendToken#toFullToken}.
78
+ */
79
+ toFullToken(groupParams, expiration) {
80
+ return this.toToken(groupParams).toFullToken(expiration);
81
+ }
82
+ }
83
+ exports.default = GroupSendEndorsement;
84
+ //# sourceMappingURL=GroupSendEndorsement.js.map
@@ -0,0 +1,73 @@
1
+ /// <reference types="node" />
2
+ import ByteArray from '../internal/ByteArray';
3
+ import GroupSecretParams from '../groups/GroupSecretParams';
4
+ import ServerPublicParams from '../ServerPublicParams';
5
+ import UuidCiphertext from '../groups/UuidCiphertext';
6
+ import { Aci, ServiceId } from '../../Address';
7
+ import GroupSendDerivedKeyPair from './GroupSendDerivedKeyPair';
8
+ import GroupSendEndorsement from './GroupSendEndorsement';
9
+ /**
10
+ * A collection of endorsements known to be valid.
11
+ *
12
+ * The result of the `receive` operations on {@link GroupSendEndorsementsResponse}. Contains an
13
+ * endorsement for each member of the group, in the same order they were originally provided, plus a
14
+ * combined endorsement for "everyone but me", intended for multi-recipient sends.
15
+ */
16
+ export type ReceivedEndorsements = {
17
+ endorsements: GroupSendEndorsement[];
18
+ combinedEndorsement: GroupSendEndorsement;
19
+ };
20
+ /**
21
+ * A set of endorsements of the members in a group, along with a proof of their validity.
22
+ *
23
+ * Issued by the group server based on the group's member ciphertexts. The endorsements will
24
+ * eventually be verified by the chat server in the form of {@link GroupSendFullToken}s. See
25
+ * {@link GroupSendEndorsement} for a full description of the endorsement flow from the client's
26
+ * perspective.
27
+ */
28
+ export default class GroupSendEndorsementsResponse extends ByteArray {
29
+ constructor(contents: Buffer);
30
+ /**
31
+ * Issues a new set of endorsements for `groupMembers`.
32
+ *
33
+ * `groupMembers` should include `requestingUser` as well.
34
+ */
35
+ static issue(groupMembers: UuidCiphertext[], keyPair: GroupSendDerivedKeyPair): GroupSendEndorsementsResponse;
36
+ /**
37
+ * Issues a new set of endorsements for `groupMembers`, with an explicity-chosen expiration and
38
+ * source of randomness.
39
+ *
40
+ * Should only be used for testing purposes.
41
+ *
42
+ * @see {@link GroupSendEndorsementsResponse#issue}
43
+ */
44
+ static issueWithRandom(groupMembers: UuidCiphertext[], keyPair: GroupSendDerivedKeyPair, random: Buffer): GroupSendEndorsementsResponse;
45
+ /** Returns the expiration for the contained endorsements. */
46
+ getExpiration(): Date;
47
+ /**
48
+ * Receives, validates, and extracts the endorsements from a response.
49
+ *
50
+ * Note that the `receive` operation is provided for both {@link ServiceId}s and {@link
51
+ * UuidCiphertext}s. If you already have the ciphertexts for the group members available, {@link
52
+ * #receiveWithCiphertexts} should be faster; if you don't, this method is faster than generating
53
+ * the ciphertexts and throwing them away afterwards.
54
+ *
55
+ * `localUser` should be included in `groupMembers`.
56
+ *
57
+ * @throws {VerificationFailedError} if the endorsements are not valid for any reason
58
+ */
59
+ receiveWithServiceIds(groupMembers: ServiceId[], localUser: Aci, groupParams: GroupSecretParams, serverParams: ServerPublicParams, now?: Date): ReceivedEndorsements;
60
+ /**
61
+ * Receives, validates, and extracts the endorsements from a response.
62
+ *
63
+ * Note that the `receive` operation is provided for both {@link ServiceId}s and {@link
64
+ * UuidCiphertext}s. If you already have the ciphertexts for the group members available, this
65
+ * method should be faster; if you don't, {@link #receiveWithServiceIds} is faster than generating
66
+ * the ciphertexts and throwing them away afterwards.
67
+ *
68
+ * `localUser` should be included in `groupMembers`.
69
+ *
70
+ * @throws {VerificationFailedError} if the endorsements are not valid for any reason
71
+ */
72
+ receiveWithCiphertexts(groupMembers: UuidCiphertext[], localUser: UuidCiphertext, serverParams: ServerPublicParams, now?: Date): ReceivedEndorsements;
73
+ }
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ //
3
+ // Copyright 2024 Signal Messenger, LLC.
4
+ // SPDX-License-Identifier: AGPL-3.0-only
5
+ //
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const crypto_1 = require("crypto");
8
+ const ByteArray_1 = require("../internal/ByteArray");
9
+ const Native = require("../../../Native");
10
+ const Constants_1 = require("../internal/Constants");
11
+ const UuidCiphertext_1 = require("../groups/UuidCiphertext");
12
+ const Address_1 = require("../../Address");
13
+ const GroupSendEndorsement_1 = require("./GroupSendEndorsement");
14
+ /**
15
+ * A set of endorsements of the members in a group, along with a proof of their validity.
16
+ *
17
+ * Issued by the group server based on the group's member ciphertexts. The endorsements will
18
+ * eventually be verified by the chat server in the form of {@link GroupSendFullToken}s. See
19
+ * {@link GroupSendEndorsement} for a full description of the endorsement flow from the client's
20
+ * perspective.
21
+ */
22
+ class GroupSendEndorsementsResponse extends ByteArray_1.default {
23
+ constructor(contents) {
24
+ super(contents, Native.GroupSendEndorsementsResponse_CheckValidContents);
25
+ }
26
+ /**
27
+ * Issues a new set of endorsements for `groupMembers`.
28
+ *
29
+ * `groupMembers` should include `requestingUser` as well.
30
+ */
31
+ static issue(groupMembers, keyPair) {
32
+ const random = (0, crypto_1.randomBytes)(Constants_1.RANDOM_LENGTH);
33
+ return this.issueWithRandom(groupMembers, keyPair, random);
34
+ }
35
+ /**
36
+ * Issues a new set of endorsements for `groupMembers`, with an explicity-chosen expiration and
37
+ * source of randomness.
38
+ *
39
+ * Should only be used for testing purposes.
40
+ *
41
+ * @see {@link GroupSendEndorsementsResponse#issue}
42
+ */
43
+ static issueWithRandom(groupMembers, keyPair, random) {
44
+ return new GroupSendEndorsementsResponse(Native.GroupSendEndorsementsResponse_IssueDeterministic(UuidCiphertext_1.default.serializeAndConcatenate(groupMembers), keyPair.contents, random));
45
+ }
46
+ /** Returns the expiration for the contained endorsements. */
47
+ getExpiration() {
48
+ return new Date(1000 * Native.GroupSendEndorsementsResponse_GetExpiration(this.contents));
49
+ }
50
+ /**
51
+ * Receives, validates, and extracts the endorsements from a response.
52
+ *
53
+ * Note that the `receive` operation is provided for both {@link ServiceId}s and {@link
54
+ * UuidCiphertext}s. If you already have the ciphertexts for the group members available, {@link
55
+ * #receiveWithCiphertexts} should be faster; if you don't, this method is faster than generating
56
+ * the ciphertexts and throwing them away afterwards.
57
+ *
58
+ * `localUser` should be included in `groupMembers`.
59
+ *
60
+ * @throws {VerificationFailedError} if the endorsements are not valid for any reason
61
+ */
62
+ receiveWithServiceIds(groupMembers, localUser, groupParams, serverParams, now = new Date()) {
63
+ const endorsementContents = Native.GroupSendEndorsementsResponse_ReceiveAndCombineWithServiceIds(this.contents, Address_1.ServiceId.toConcatenatedFixedWidthBinary(groupMembers), localUser.getServiceIdFixedWidthBinary(), Math.floor(now.getTime() / 1000), groupParams.contents, serverParams.contents);
64
+ const endorsements = endorsementContents.map((next) => {
65
+ // Normally we don't notice the cost of validating just-created zkgroup objects,
66
+ // but in this case we may have up to 1000 of these. Let's assume they're created correctly.
67
+ return new GroupSendEndorsement_1.default(next, ByteArray_1.UNCHECKED_AND_UNCLONED);
68
+ });
69
+ const combinedEndorsement = endorsements.pop();
70
+ if (!combinedEndorsement) {
71
+ throw new Error("GroupSendEndorsementsResponse_ReceiveAndCombineWithServiceIds didn't produce a combined endorsement");
72
+ }
73
+ return { endorsements, combinedEndorsement };
74
+ }
75
+ /**
76
+ * Receives, validates, and extracts the endorsements from a response.
77
+ *
78
+ * Note that the `receive` operation is provided for both {@link ServiceId}s and {@link
79
+ * UuidCiphertext}s. If you already have the ciphertexts for the group members available, this
80
+ * method should be faster; if you don't, {@link #receiveWithServiceIds} is faster than generating
81
+ * the ciphertexts and throwing them away afterwards.
82
+ *
83
+ * `localUser` should be included in `groupMembers`.
84
+ *
85
+ * @throws {VerificationFailedError} if the endorsements are not valid for any reason
86
+ */
87
+ receiveWithCiphertexts(groupMembers, localUser, serverParams, now = new Date()) {
88
+ const endorsementContents = Native.GroupSendEndorsementsResponse_ReceiveAndCombineWithCiphertexts(this.contents, UuidCiphertext_1.default.serializeAndConcatenate(groupMembers), localUser.contents, Math.floor(now.getTime() / 1000), serverParams.contents);
89
+ const endorsements = endorsementContents.map((next) => {
90
+ // Normally we don't notice the cost of validating just-created zkgroup objects,
91
+ // but in this case we may have up to 1000 of these. Let's assume they're created correctly.
92
+ return new GroupSendEndorsement_1.default(next, ByteArray_1.UNCHECKED_AND_UNCLONED);
93
+ });
94
+ const combinedEndorsement = endorsements.pop();
95
+ if (!combinedEndorsement) {
96
+ throw new Error("GroupSendEndorsementsResponse_ReceiveAndCombineWithCiphertexts didn't produce a combined endorsement");
97
+ }
98
+ return { endorsements, combinedEndorsement };
99
+ }
100
+ }
101
+ exports.default = GroupSendEndorsementsResponse;
102
+ //# sourceMappingURL=GroupSendEndorsementsResponse.js.map
@@ -0,0 +1,23 @@
1
+ /// <reference types="node" />
2
+ import ByteArray from '../internal/ByteArray';
3
+ import { ServiceId } from '../../Address';
4
+ import GroupSendDerivedKeyPair from './GroupSendDerivedKeyPair';
5
+ /**
6
+ * A token representing a particular {@link GroupSendEndorsement}, along with the endorsement's
7
+ * expiration.
8
+ *
9
+ * Generated by {@link GroupSendToken#toFullToken}, and verified by the chat server.
10
+ */
11
+ export default class GroupSendFullToken extends ByteArray {
12
+ constructor(contents: Buffer);
13
+ /** Gets the expiration embedded in the token. */
14
+ getExpiration(): Date;
15
+ /**
16
+ * Verifies that this token was generated from an endorsement of `userIds` by `keyPair`.
17
+ *
18
+ * The correct `keyPair` must be selected based on {@link #getExpiration}.
19
+ *
20
+ * @throws {VerificationFailedError} if the token is invalid.
21
+ */
22
+ verify(userIds: ServiceId[], keyPair: GroupSendDerivedKeyPair, now?: Date): void;
23
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ //
3
+ // Copyright 2024 Signal Messenger, LLC.
4
+ // SPDX-License-Identifier: AGPL-3.0-only
5
+ //
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const ByteArray_1 = require("../internal/ByteArray");
8
+ const Native = require("../../../Native");
9
+ const Address_1 = require("../../Address");
10
+ /**
11
+ * A token representing a particular {@link GroupSendEndorsement}, along with the endorsement's
12
+ * expiration.
13
+ *
14
+ * Generated by {@link GroupSendToken#toFullToken}, and verified by the chat server.
15
+ */
16
+ class GroupSendFullToken extends ByteArray_1.default {
17
+ constructor(contents) {
18
+ super(contents, Native.GroupSendFullToken_CheckValidContents);
19
+ }
20
+ /** Gets the expiration embedded in the token. */
21
+ getExpiration() {
22
+ return new Date(1000 * Native.GroupSendFullToken_GetExpiration(this.contents));
23
+ }
24
+ /**
25
+ * Verifies that this token was generated from an endorsement of `userIds` by `keyPair`.
26
+ *
27
+ * The correct `keyPair` must be selected based on {@link #getExpiration}.
28
+ *
29
+ * @throws {VerificationFailedError} if the token is invalid.
30
+ */
31
+ verify(userIds, keyPair, now = new Date()) {
32
+ Native.GroupSendFullToken_Verify(this.contents, Address_1.ServiceId.toConcatenatedFixedWidthBinary(userIds), Math.floor(now.getTime() / 1000), keyPair.contents);
33
+ }
34
+ }
35
+ exports.default = GroupSendFullToken;
36
+ //# sourceMappingURL=GroupSendFullToken.js.map
@@ -0,0 +1,22 @@
1
+ /// <reference types="node" />
2
+ import ByteArray from '../internal/ByteArray';
3
+ import GroupSendFullToken from './GroupSendFullToken';
4
+ /**
5
+ * A minimal cacheable representation of an endorsement.
6
+ *
7
+ * This contains the minimal information needed to represent this specific endorsement; it must be
8
+ * converted to a {@link GroupSendFullToken} before sending to the chat server. (It is valid to do
9
+ * this immediately; it just uses up extra space.)
10
+ *
11
+ * Generated by {@link GroupSendEndorsement#toToken}.
12
+ */
13
+ export default class GroupSendToken extends ByteArray {
14
+ constructor(contents: Buffer);
15
+ /**
16
+ * Converts this token to a "full token", which can be sent to the chat server as authentication.
17
+ *
18
+ * {@code expiration} must be the same expiration that was in the original
19
+ * {@link GroupSendEndorsementsResponse}, or the resulting token will fail to verify.
20
+ */
21
+ toFullToken(expiration: Date): GroupSendFullToken;
22
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ //
3
+ // Copyright 2024 Signal Messenger, LLC.
4
+ // SPDX-License-Identifier: AGPL-3.0-only
5
+ //
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const ByteArray_1 = require("../internal/ByteArray");
8
+ const Native = require("../../../Native");
9
+ const GroupSendFullToken_1 = require("./GroupSendFullToken");
10
+ /**
11
+ * A minimal cacheable representation of an endorsement.
12
+ *
13
+ * This contains the minimal information needed to represent this specific endorsement; it must be
14
+ * converted to a {@link GroupSendFullToken} before sending to the chat server. (It is valid to do
15
+ * this immediately; it just uses up extra space.)
16
+ *
17
+ * Generated by {@link GroupSendEndorsement#toToken}.
18
+ */
19
+ class GroupSendToken extends ByteArray_1.default {
20
+ constructor(contents) {
21
+ super(contents, Native.GroupSendToken_CheckValidContents);
22
+ }
23
+ /**
24
+ * Converts this token to a "full token", which can be sent to the chat server as authentication.
25
+ *
26
+ * {@code expiration} must be the same expiration that was in the original
27
+ * {@link GroupSendEndorsementsResponse}, or the resulting token will fail to verify.
28
+ */
29
+ toFullToken(expiration) {
30
+ return new GroupSendFullToken_1.default(Native.GroupSendToken_ToFullToken(this.contents, Math.floor(expiration.getTime() / 1000)));
31
+ }
32
+ }
33
+ exports.default = GroupSendToken;
34
+ //# sourceMappingURL=GroupSendToken.js.map
@@ -5,8 +5,6 @@ export { default as GenericServerSecretParams } from './GenericServerSecretParam
5
5
  export { default as NotarySignature } from './NotarySignature';
6
6
  export { default as ClientZkAuthOperations } from './auth/ClientZkAuthOperations';
7
7
  export { default as ServerZkAuthOperations } from './auth/ServerZkAuthOperations';
8
- export { default as AuthCredential } from './auth/AuthCredential';
9
- export { default as AuthCredentialResponse } from './auth/AuthCredentialResponse';
10
8
  export { default as AuthCredentialPresentation } from './auth/AuthCredentialPresentation';
11
9
  export { default as AuthCredentialWithPni } from './auth/AuthCredentialWithPni';
12
10
  export { default as AuthCredentialWithPniResponse } from './auth/AuthCredentialWithPniResponse';
@@ -50,6 +48,8 @@ export { default as BackupAuthCredentialPresentation } from './backups/BackupAut
50
48
  export { default as BackupAuthCredentialRequest } from './backups/BackupAuthCredentialRequest';
51
49
  export { default as BackupAuthCredentialRequestContext } from './backups/BackupAuthCredentialRequestContext';
52
50
  export { default as BackupAuthCredentialResponse } from './backups/BackupAuthCredentialResponse';
53
- export { default as GroupSendCredential } from './groupsend/GroupSendCredential';
54
- export { default as GroupSendCredentialPresentation } from './groupsend/GroupSendCredentialPresentation';
55
- export { default as GroupSendCredentialResponse } from './groupsend/GroupSendCredentialResponse';
51
+ export { default as GroupSendDerivedKeyPair } from './groupsend/GroupSendDerivedKeyPair';
52
+ export { default as GroupSendEndorsement } from './groupsend/GroupSendEndorsement';
53
+ export { default as GroupSendEndorsementsResponse } from './groupsend/GroupSendEndorsementsResponse';
54
+ export { default as GroupSendFullToken } from './groupsend/GroupSendFullToken';
55
+ export { default as GroupSendToken } from './groupsend/GroupSendToken';
@@ -4,8 +4,8 @@
4
4
  // SPDX-License-Identifier: AGPL-3.0-only
5
5
  //
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.BackupAuthCredentialRequest = exports.BackupAuthCredentialPresentation = exports.BackupAuthCredential = exports.CreateCallLinkCredentialResponse = exports.CreateCallLinkCredentialRequestContext = exports.CreateCallLinkCredentialRequest = exports.CreateCallLinkCredentialPresentation = exports.CreateCallLinkCredential = exports.CallLinkAuthCredentialResponse = exports.CallLinkAuthCredentialPresentation = exports.CallLinkAuthCredential = exports.CallLinkSecretParams = exports.CallLinkPublicParams = exports.ReceiptSerial = exports.ReceiptCredentialResponse = exports.ReceiptCredentialRequestContext = exports.ReceiptCredentialRequest = exports.ReceiptCredentialPresentation = exports.ReceiptCredential = exports.ServerZkReceiptOperations = exports.ClientZkReceiptOperations = exports.ExpiringProfileKeyCredentialResponse = exports.ExpiringProfileKeyCredential = exports.ProfileKeyVersion = exports.ProfileKeyCredentialRequestContext = exports.ProfileKeyCredentialRequest = exports.ProfileKeyCredentialPresentation = exports.ProfileKeyCommitment = exports.ProfileKey = exports.ServerZkProfileOperations = exports.ClientZkProfileOperations = exports.UuidCiphertext = exports.ProfileKeyCiphertext = exports.GroupSecretParams = exports.GroupPublicParams = exports.GroupMasterKey = exports.GroupIdentifier = exports.ClientZkGroupCipher = exports.AuthCredentialWithPniResponse = exports.AuthCredentialWithPni = exports.AuthCredentialPresentation = exports.AuthCredentialResponse = exports.AuthCredential = exports.ServerZkAuthOperations = exports.ClientZkAuthOperations = exports.NotarySignature = exports.GenericServerSecretParams = exports.GenericServerPublicParams = exports.ServerSecretParams = exports.ServerPublicParams = void 0;
8
- exports.GroupSendCredentialResponse = exports.GroupSendCredentialPresentation = exports.GroupSendCredential = exports.BackupAuthCredentialResponse = exports.BackupAuthCredentialRequestContext = void 0;
7
+ exports.BackupAuthCredentialResponse = exports.BackupAuthCredentialRequestContext = exports.BackupAuthCredentialRequest = exports.BackupAuthCredentialPresentation = exports.BackupAuthCredential = exports.CreateCallLinkCredentialResponse = exports.CreateCallLinkCredentialRequestContext = exports.CreateCallLinkCredentialRequest = exports.CreateCallLinkCredentialPresentation = exports.CreateCallLinkCredential = exports.CallLinkAuthCredentialResponse = exports.CallLinkAuthCredentialPresentation = exports.CallLinkAuthCredential = exports.CallLinkSecretParams = exports.CallLinkPublicParams = exports.ReceiptSerial = exports.ReceiptCredentialResponse = exports.ReceiptCredentialRequestContext = exports.ReceiptCredentialRequest = exports.ReceiptCredentialPresentation = exports.ReceiptCredential = exports.ServerZkReceiptOperations = exports.ClientZkReceiptOperations = exports.ExpiringProfileKeyCredentialResponse = exports.ExpiringProfileKeyCredential = exports.ProfileKeyVersion = exports.ProfileKeyCredentialRequestContext = exports.ProfileKeyCredentialRequest = exports.ProfileKeyCredentialPresentation = exports.ProfileKeyCommitment = exports.ProfileKey = exports.ServerZkProfileOperations = exports.ClientZkProfileOperations = exports.UuidCiphertext = exports.ProfileKeyCiphertext = exports.GroupSecretParams = exports.GroupPublicParams = exports.GroupMasterKey = exports.GroupIdentifier = exports.ClientZkGroupCipher = exports.AuthCredentialWithPniResponse = exports.AuthCredentialWithPni = exports.AuthCredentialPresentation = exports.ServerZkAuthOperations = exports.ClientZkAuthOperations = exports.NotarySignature = exports.GenericServerSecretParams = exports.GenericServerPublicParams = exports.ServerSecretParams = exports.ServerPublicParams = void 0;
8
+ exports.GroupSendToken = exports.GroupSendFullToken = exports.GroupSendEndorsementsResponse = exports.GroupSendEndorsement = exports.GroupSendDerivedKeyPair = void 0;
9
9
  // Root
10
10
  var ServerPublicParams_1 = require("./ServerPublicParams");
11
11
  Object.defineProperty(exports, "ServerPublicParams", { enumerable: true, get: function () { return ServerPublicParams_1.default; } });
@@ -22,10 +22,6 @@ var ClientZkAuthOperations_1 = require("./auth/ClientZkAuthOperations");
22
22
  Object.defineProperty(exports, "ClientZkAuthOperations", { enumerable: true, get: function () { return ClientZkAuthOperations_1.default; } });
23
23
  var ServerZkAuthOperations_1 = require("./auth/ServerZkAuthOperations");
24
24
  Object.defineProperty(exports, "ServerZkAuthOperations", { enumerable: true, get: function () { return ServerZkAuthOperations_1.default; } });
25
- var AuthCredential_1 = require("./auth/AuthCredential");
26
- Object.defineProperty(exports, "AuthCredential", { enumerable: true, get: function () { return AuthCredential_1.default; } });
27
- var AuthCredentialResponse_1 = require("./auth/AuthCredentialResponse");
28
- Object.defineProperty(exports, "AuthCredentialResponse", { enumerable: true, get: function () { return AuthCredentialResponse_1.default; } });
29
25
  var AuthCredentialPresentation_1 = require("./auth/AuthCredentialPresentation");
30
26
  Object.defineProperty(exports, "AuthCredentialPresentation", { enumerable: true, get: function () { return AuthCredentialPresentation_1.default; } });
31
27
  var AuthCredentialWithPni_1 = require("./auth/AuthCredentialWithPni");
@@ -118,10 +114,14 @@ Object.defineProperty(exports, "BackupAuthCredentialRequestContext", { enumerabl
118
114
  var BackupAuthCredentialResponse_1 = require("./backups/BackupAuthCredentialResponse");
119
115
  Object.defineProperty(exports, "BackupAuthCredentialResponse", { enumerable: true, get: function () { return BackupAuthCredentialResponse_1.default; } });
120
116
  // Group Send
121
- var GroupSendCredential_1 = require("./groupsend/GroupSendCredential");
122
- Object.defineProperty(exports, "GroupSendCredential", { enumerable: true, get: function () { return GroupSendCredential_1.default; } });
123
- var GroupSendCredentialPresentation_1 = require("./groupsend/GroupSendCredentialPresentation");
124
- Object.defineProperty(exports, "GroupSendCredentialPresentation", { enumerable: true, get: function () { return GroupSendCredentialPresentation_1.default; } });
125
- var GroupSendCredentialResponse_1 = require("./groupsend/GroupSendCredentialResponse");
126
- Object.defineProperty(exports, "GroupSendCredentialResponse", { enumerable: true, get: function () { return GroupSendCredentialResponse_1.default; } });
117
+ var GroupSendDerivedKeyPair_1 = require("./groupsend/GroupSendDerivedKeyPair");
118
+ Object.defineProperty(exports, "GroupSendDerivedKeyPair", { enumerable: true, get: function () { return GroupSendDerivedKeyPair_1.default; } });
119
+ var GroupSendEndorsement_1 = require("./groupsend/GroupSendEndorsement");
120
+ Object.defineProperty(exports, "GroupSendEndorsement", { enumerable: true, get: function () { return GroupSendEndorsement_1.default; } });
121
+ var GroupSendEndorsementsResponse_1 = require("./groupsend/GroupSendEndorsementsResponse");
122
+ Object.defineProperty(exports, "GroupSendEndorsementsResponse", { enumerable: true, get: function () { return GroupSendEndorsementsResponse_1.default; } });
123
+ var GroupSendFullToken_1 = require("./groupsend/GroupSendFullToken");
124
+ Object.defineProperty(exports, "GroupSendFullToken", { enumerable: true, get: function () { return GroupSendFullToken_1.default; } });
125
+ var GroupSendToken_1 = require("./groupsend/GroupSendToken");
126
+ Object.defineProperty(exports, "GroupSendToken", { enumerable: true, get: function () { return GroupSendToken_1.default; } });
127
127
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,8 @@
1
1
  /// <reference types="node" />
2
+ export declare const UNCHECKED_AND_UNCLONED: unique symbol;
2
3
  export default class ByteArray {
3
4
  contents: Buffer;
4
- constructor(contents: Buffer, checkValid: (contents: Buffer) => void);
5
+ constructor(contents: Buffer, checkValid: ((contents: Buffer) => void) | typeof UNCHECKED_AND_UNCLONED);
5
6
  protected static checkLength(expectedLength: number): (contents: Buffer) => void;
6
7
  getContents(): Buffer;
7
8
  serialize(): Buffer;
@@ -4,11 +4,18 @@
4
4
  // SPDX-License-Identifier: AGPL-3.0-only
5
5
  //
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.UNCHECKED_AND_UNCLONED = void 0;
7
8
  const Errors_1 = require("../../Errors");
9
+ exports.UNCHECKED_AND_UNCLONED = Symbol();
8
10
  class ByteArray {
9
11
  constructor(contents, checkValid) {
10
- checkValid(contents);
11
- this.contents = Buffer.from(contents);
12
+ if (checkValid === exports.UNCHECKED_AND_UNCLONED) {
13
+ this.contents = contents;
14
+ }
15
+ else {
16
+ checkValid(contents);
17
+ this.contents = Buffer.from(contents);
18
+ }
12
19
  }
13
20
  static checkLength(expectedLength) {
14
21
  return (contents) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signalapp/libsignal-client",
3
- "version": "0.41.1",
3
+ "version": "0.42.0",
4
4
  "license": "AGPL-3.0-only",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -32,6 +32,7 @@
32
32
  "uuid": "^8.3.0"
33
33
  },
34
34
  "devDependencies": {
35
+ "@indutny/bencher": "^1.2.0",
35
36
  "@types/bindings": "^1.3.0",
36
37
  "@types/chai": "^4.3.1",
37
38
  "@types/chai-as-promised": "^7.1.3",
Binary file
Binary file
Binary file
@@ -1,6 +0,0 @@
1
- /// <reference types="node" />
2
- import ByteArray from '../internal/ByteArray';
3
- export default class AuthCredential extends ByteArray {
4
- private readonly __type?;
5
- constructor(contents: Buffer);
6
- }
@@ -1,15 +0,0 @@
1
- "use strict";
2
- //
3
- // Copyright 2020-2021 Signal Messenger, LLC.
4
- // SPDX-License-Identifier: AGPL-3.0-only
5
- //
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- const ByteArray_1 = require("../internal/ByteArray");
8
- const Native = require("../../../Native");
9
- class AuthCredential extends ByteArray_1.default {
10
- constructor(contents) {
11
- super(contents, Native.AuthCredential_CheckValidContents);
12
- }
13
- }
14
- exports.default = AuthCredential;
15
- //# sourceMappingURL=AuthCredential.js.map