@periskope/baileys 6.7.18-alpha.4 → 6.7.18-alpha.5

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 (75) hide show
  1. package/README.md +1 -1
  2. package/WAProto/GenerateStatics.sh +2 -0
  3. package/WAProto/WAProto.proto +4633 -0
  4. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  5. package/lib/Signal/Group/ciphertext-message.js +15 -0
  6. package/lib/Signal/Group/group-session-builder.d.ts +14 -0
  7. package/lib/Signal/Group/group-session-builder.js +64 -0
  8. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  9. package/lib/Signal/Group/group_cipher.js +96 -0
  10. package/lib/Signal/Group/index.d.ts +11 -0
  11. package/lib/Signal/Group/index.js +57 -0
  12. package/lib/Signal/Group/keyhelper.d.ts +10 -0
  13. package/lib/Signal/Group/keyhelper.js +55 -0
  14. package/lib/Signal/Group/queue-job.d.ts +1 -0
  15. package/lib/Signal/Group/queue-job.js +57 -0
  16. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  17. package/lib/Signal/Group/sender-chain-key.js +34 -0
  18. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  19. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  20. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  21. package/lib/Signal/Group/sender-key-message.js +69 -0
  22. package/lib/Signal/Group/sender-key-name.d.ts +17 -0
  23. package/lib/Signal/Group/sender-key-name.js +51 -0
  24. package/lib/Signal/Group/sender-key-record.d.ts +30 -0
  25. package/lib/Signal/Group/sender-key-record.js +53 -0
  26. package/lib/Signal/Group/sender-key-state.d.ts +38 -0
  27. package/lib/Signal/Group/sender-key-state.js +99 -0
  28. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  29. package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +29 -39
  30. package/lib/Signal/libsignal.js +28 -15
  31. package/lib/Socket/business.d.ts +29 -3
  32. package/lib/Socket/chats.d.ts +7 -5
  33. package/lib/Socket/chats.js +6 -4
  34. package/lib/Socket/groups.d.ts +7 -3
  35. package/lib/Socket/index.d.ts +29 -3
  36. package/lib/Socket/messages-recv.d.ts +29 -3
  37. package/lib/Socket/messages-recv.js +140 -0
  38. package/lib/Socket/messages-send.d.ts +29 -3
  39. package/lib/Socket/messages-send.js +28 -2
  40. package/lib/Socket/mex.d.ts +2 -0
  41. package/lib/Socket/mex.js +46 -0
  42. package/lib/Socket/newsletter.d.ts +139 -0
  43. package/lib/Socket/newsletter.js +183 -0
  44. package/lib/Socket/socket.d.ts +1 -1
  45. package/lib/Socket/socket.js +6 -2
  46. package/lib/Socket/usync.d.ts +1 -1
  47. package/lib/Types/Events.d.ts +26 -0
  48. package/lib/Types/Message.d.ts +8 -2
  49. package/lib/Types/Newsletter.d.ts +134 -0
  50. package/lib/Types/Newsletter.js +33 -0
  51. package/lib/Types/index.d.ts +1 -0
  52. package/lib/Types/index.js +1 -0
  53. package/lib/Utils/decode-wa-message.d.ts +3 -4
  54. package/lib/Utils/decode-wa-message.js +7 -2
  55. package/lib/Utils/generics.d.ts +1 -0
  56. package/lib/Utils/generics.js +4 -0
  57. package/lib/Utils/messages-media.d.ts +9 -1
  58. package/lib/Utils/messages-media.js +63 -28
  59. package/lib/Utils/messages.d.ts +2 -2
  60. package/lib/Utils/messages.js +39 -9
  61. package/package.json +2 -4
  62. package/WASignalGroup/GroupProtocol.js +0 -1697
  63. package/WASignalGroup/ciphertext_message.js +0 -16
  64. package/WASignalGroup/group_cipher.js +0 -120
  65. package/WASignalGroup/group_session_builder.js +0 -46
  66. package/WASignalGroup/index.js +0 -5
  67. package/WASignalGroup/keyhelper.js +0 -21
  68. package/WASignalGroup/protobufs.js +0 -3
  69. package/WASignalGroup/queue_job.js +0 -69
  70. package/WASignalGroup/sender_chain_key.js +0 -50
  71. package/WASignalGroup/sender_key_distribution_message.js +0 -78
  72. package/WASignalGroup/sender_key_message.js +0 -92
  73. package/WASignalGroup/sender_key_name.js +0 -70
  74. package/WASignalGroup/sender_key_record.js +0 -56
  75. package/WASignalGroup/sender_key_state.js +0 -129
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SenderKeyName = void 0;
4
+ function isNull(str) {
5
+ return str === null || str === '';
6
+ }
7
+ function intValue(num) {
8
+ const MAX_VALUE = 0x7fffffff;
9
+ const MIN_VALUE = -0x80000000;
10
+ if (num > MAX_VALUE || num < MIN_VALUE) {
11
+ return num & 0xffffffff;
12
+ }
13
+ return num;
14
+ }
15
+ function hashCode(strKey) {
16
+ let hash = 0;
17
+ if (!isNull(strKey)) {
18
+ for (let i = 0; i < strKey.length; i++) {
19
+ hash = hash * 31 + strKey.charCodeAt(i);
20
+ hash = intValue(hash);
21
+ }
22
+ }
23
+ return hash;
24
+ }
25
+ class SenderKeyName {
26
+ constructor(groupId, sender) {
27
+ this.groupId = groupId;
28
+ this.sender = sender;
29
+ }
30
+ getGroupId() {
31
+ return this.groupId;
32
+ }
33
+ getSender() {
34
+ return this.sender;
35
+ }
36
+ serialize() {
37
+ return `${this.groupId}::${this.sender.id}::${this.sender.deviceId}`;
38
+ }
39
+ toString() {
40
+ return this.serialize();
41
+ }
42
+ equals(other) {
43
+ if (other === null)
44
+ return false;
45
+ return this.groupId === other.groupId && this.sender.toString() === other.sender.toString();
46
+ }
47
+ hashCode() {
48
+ return hashCode(this.groupId) ^ hashCode(this.sender.toString());
49
+ }
50
+ }
51
+ exports.SenderKeyName = SenderKeyName;
@@ -0,0 +1,30 @@
1
+ import { SenderKeyState } from './sender-key-state';
2
+ export interface SenderKeyStateStructure {
3
+ senderKeyId: number;
4
+ senderChainKey: {
5
+ iteration: number;
6
+ seed: Uint8Array;
7
+ };
8
+ senderSigningKey: {
9
+ public: Uint8Array;
10
+ private?: Uint8Array;
11
+ };
12
+ senderMessageKeys: Array<{
13
+ iteration: number;
14
+ seed: Uint8Array;
15
+ }>;
16
+ }
17
+ export declare class SenderKeyRecord {
18
+ private readonly MAX_STATES;
19
+ private readonly senderKeyStates;
20
+ constructor(serialized?: SenderKeyStateStructure[]);
21
+ isEmpty(): boolean;
22
+ getSenderKeyState(keyId?: number): SenderKeyState | undefined;
23
+ addSenderKeyState(id: number, iteration: number, chainKey: Uint8Array, signatureKey: Uint8Array): void;
24
+ setSenderKeyState(id: number, iteration: number, chainKey: Uint8Array, keyPair: {
25
+ public: Uint8Array;
26
+ private: Uint8Array;
27
+ }): void;
28
+ serialize(): SenderKeyStateStructure[];
29
+ static deserialize(data: Uint8Array | string | SenderKeyStateStructure[]): SenderKeyRecord;
30
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SenderKeyRecord = void 0;
4
+ const generics_1 = require("../../Utils/generics");
5
+ const sender_key_state_1 = require("./sender-key-state");
6
+ class SenderKeyRecord {
7
+ constructor(serialized) {
8
+ this.MAX_STATES = 5;
9
+ this.senderKeyStates = [];
10
+ if (serialized) {
11
+ for (const structure of serialized) {
12
+ this.senderKeyStates.push(new sender_key_state_1.SenderKeyState(null, null, null, null, null, null, structure));
13
+ }
14
+ }
15
+ }
16
+ isEmpty() {
17
+ return this.senderKeyStates.length === 0;
18
+ }
19
+ getSenderKeyState(keyId) {
20
+ if (keyId === undefined && this.senderKeyStates.length) {
21
+ return this.senderKeyStates[this.senderKeyStates.length - 1];
22
+ }
23
+ return this.senderKeyStates.find(state => state.getKeyId() === keyId);
24
+ }
25
+ addSenderKeyState(id, iteration, chainKey, signatureKey) {
26
+ this.senderKeyStates.push(new sender_key_state_1.SenderKeyState(id, iteration, chainKey, null, signatureKey));
27
+ if (this.senderKeyStates.length > this.MAX_STATES) {
28
+ this.senderKeyStates.shift();
29
+ }
30
+ }
31
+ setSenderKeyState(id, iteration, chainKey, keyPair) {
32
+ this.senderKeyStates.length = 0;
33
+ this.senderKeyStates.push(new sender_key_state_1.SenderKeyState(id, iteration, chainKey, keyPair));
34
+ }
35
+ serialize() {
36
+ return this.senderKeyStates.map(state => state.getStructure());
37
+ }
38
+ static deserialize(data) {
39
+ let parsed;
40
+ if (typeof data === 'string') {
41
+ parsed = JSON.parse(data, generics_1.BufferJSON.reviver);
42
+ }
43
+ else if (data instanceof Uint8Array) {
44
+ const str = Buffer.from(data).toString('utf-8');
45
+ parsed = JSON.parse(str, generics_1.BufferJSON.reviver);
46
+ }
47
+ else {
48
+ parsed = data;
49
+ }
50
+ return new SenderKeyRecord(parsed);
51
+ }
52
+ }
53
+ exports.SenderKeyRecord = SenderKeyRecord;
@@ -0,0 +1,38 @@
1
+ import { SenderChainKey } from './sender-chain-key';
2
+ import { SenderMessageKey } from './sender-message-key';
3
+ interface SenderChainKeyStructure {
4
+ iteration: number;
5
+ seed: Uint8Array;
6
+ }
7
+ interface SenderSigningKeyStructure {
8
+ public: Uint8Array;
9
+ private?: Uint8Array;
10
+ }
11
+ interface SenderMessageKeyStructure {
12
+ iteration: number;
13
+ seed: Uint8Array;
14
+ }
15
+ interface SenderKeyStateStructure {
16
+ senderKeyId: number;
17
+ senderChainKey: SenderChainKeyStructure;
18
+ senderSigningKey: SenderSigningKeyStructure;
19
+ senderMessageKeys: SenderMessageKeyStructure[];
20
+ }
21
+ export declare class SenderKeyState {
22
+ private readonly MAX_MESSAGE_KEYS;
23
+ private readonly senderKeyStateStructure;
24
+ constructor(id?: number | null, iteration?: number | null, chainKey?: Uint8Array | null, signatureKeyPair?: {
25
+ public: Uint8Array;
26
+ private: Uint8Array;
27
+ } | null, signatureKeyPublic?: Uint8Array | null, signatureKeyPrivate?: Uint8Array | null, senderKeyStateStructure?: SenderKeyStateStructure | null);
28
+ getKeyId(): number;
29
+ getSenderChainKey(): SenderChainKey;
30
+ setSenderChainKey(chainKey: SenderChainKey): void;
31
+ getSigningKeyPublic(): Buffer;
32
+ getSigningKeyPrivate(): Buffer | undefined;
33
+ hasSenderMessageKey(iteration: number): boolean;
34
+ addSenderMessageKey(senderMessageKey: SenderMessageKey): void;
35
+ removeSenderMessageKey(iteration: number): SenderMessageKey | null;
36
+ getStructure(): SenderKeyStateStructure;
37
+ }
38
+ export {};
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SenderKeyState = void 0;
4
+ const sender_chain_key_1 = require("./sender-chain-key");
5
+ const sender_message_key_1 = require("./sender-message-key");
6
+ class SenderKeyState {
7
+ constructor(id, iteration, chainKey, signatureKeyPair, signatureKeyPublic, signatureKeyPrivate, senderKeyStateStructure) {
8
+ this.MAX_MESSAGE_KEYS = 2000;
9
+ if (senderKeyStateStructure) {
10
+ this.senderKeyStateStructure = senderKeyStateStructure;
11
+ }
12
+ else {
13
+ if (signatureKeyPair) {
14
+ signatureKeyPublic = signatureKeyPair.public;
15
+ signatureKeyPrivate = signatureKeyPair.private;
16
+ }
17
+ chainKey = typeof chainKey === 'string' ? Buffer.from(chainKey, 'base64') : chainKey;
18
+ const senderChainKeyStructure = {
19
+ iteration: iteration || 0,
20
+ seed: chainKey || Buffer.alloc(0)
21
+ };
22
+ const signingKeyStructure = {
23
+ public: typeof signatureKeyPublic === 'string'
24
+ ? Buffer.from(signatureKeyPublic, 'base64')
25
+ : signatureKeyPublic || Buffer.alloc(0)
26
+ };
27
+ if (signatureKeyPrivate) {
28
+ signingKeyStructure.private =
29
+ typeof signatureKeyPrivate === 'string' ? Buffer.from(signatureKeyPrivate, 'base64') : signatureKeyPrivate;
30
+ }
31
+ this.senderKeyStateStructure = {
32
+ senderKeyId: id || 0,
33
+ senderChainKey: senderChainKeyStructure,
34
+ senderSigningKey: signingKeyStructure,
35
+ senderMessageKeys: []
36
+ };
37
+ }
38
+ }
39
+ getKeyId() {
40
+ return this.senderKeyStateStructure.senderKeyId;
41
+ }
42
+ getSenderChainKey() {
43
+ return new sender_chain_key_1.SenderChainKey(this.senderKeyStateStructure.senderChainKey.iteration, this.senderKeyStateStructure.senderChainKey.seed);
44
+ }
45
+ setSenderChainKey(chainKey) {
46
+ this.senderKeyStateStructure.senderChainKey = {
47
+ iteration: chainKey.getIteration(),
48
+ seed: chainKey.getSeed()
49
+ };
50
+ }
51
+ getSigningKeyPublic() {
52
+ const publicKey = this.senderKeyStateStructure.senderSigningKey.public;
53
+ if (publicKey instanceof Buffer) {
54
+ return publicKey;
55
+ }
56
+ else if (typeof publicKey === 'string') {
57
+ return Buffer.from(publicKey, 'base64');
58
+ }
59
+ return Buffer.from(publicKey || []);
60
+ }
61
+ getSigningKeyPrivate() {
62
+ const privateKey = this.senderKeyStateStructure.senderSigningKey.private;
63
+ if (!privateKey) {
64
+ return undefined;
65
+ }
66
+ if (privateKey instanceof Buffer) {
67
+ return privateKey;
68
+ }
69
+ else if (typeof privateKey === 'string') {
70
+ return Buffer.from(privateKey, 'base64');
71
+ }
72
+ return Buffer.from(privateKey || []);
73
+ }
74
+ hasSenderMessageKey(iteration) {
75
+ return this.senderKeyStateStructure.senderMessageKeys.some(key => key.iteration === iteration);
76
+ }
77
+ addSenderMessageKey(senderMessageKey) {
78
+ this.senderKeyStateStructure.senderMessageKeys.push({
79
+ iteration: senderMessageKey.getIteration(),
80
+ seed: senderMessageKey.getSeed()
81
+ });
82
+ if (this.senderKeyStateStructure.senderMessageKeys.length > this.MAX_MESSAGE_KEYS) {
83
+ this.senderKeyStateStructure.senderMessageKeys.shift();
84
+ }
85
+ }
86
+ removeSenderMessageKey(iteration) {
87
+ const index = this.senderKeyStateStructure.senderMessageKeys.findIndex(key => key.iteration === iteration);
88
+ if (index !== -1) {
89
+ const messageKey = this.senderKeyStateStructure.senderMessageKeys[index];
90
+ this.senderKeyStateStructure.senderMessageKeys.splice(index, 1);
91
+ return new sender_message_key_1.SenderMessageKey(messageKey.iteration, messageKey.seed);
92
+ }
93
+ return null;
94
+ }
95
+ getStructure() {
96
+ return this.senderKeyStateStructure;
97
+ }
98
+ }
99
+ exports.SenderKeyState = SenderKeyState;
@@ -0,0 +1,11 @@
1
+ export declare class SenderMessageKey {
2
+ private readonly iteration;
3
+ private readonly iv;
4
+ private readonly cipherKey;
5
+ private readonly seed;
6
+ constructor(iteration: number, seed: Uint8Array);
7
+ getIteration(): number;
8
+ getIv(): Uint8Array;
9
+ getCipherKey(): Uint8Array;
10
+ getSeed(): Uint8Array;
11
+ }
@@ -1,39 +1,29 @@
1
- const { deriveSecrets } = require('libsignal/src/crypto');
2
- class SenderMessageKey {
3
- iteration = 0;
4
-
5
- iv = Buffer.alloc(0);
6
-
7
- cipherKey = Buffer.alloc(0);
8
-
9
- seed = Buffer.alloc(0);
10
-
11
- constructor(iteration, seed) {
12
- const derivative = deriveSecrets(seed, Buffer.alloc(32), Buffer.from('WhisperGroup'));
13
- const keys = new Uint8Array(32);
14
- keys.set(new Uint8Array(derivative[0].slice(16)));
15
- keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16);
16
- this.iv = Buffer.from(derivative[0].slice(0, 16));
17
- this.cipherKey = Buffer.from(keys.buffer);
18
-
19
- this.iteration = iteration;
20
- this.seed = seed;
21
- }
22
-
23
- getIteration() {
24
- return this.iteration;
25
- }
26
-
27
- getIv() {
28
- return this.iv;
29
- }
30
-
31
- getCipherKey() {
32
- return this.cipherKey;
33
- }
34
-
35
- getSeed() {
36
- return this.seed;
37
- }
38
- }
39
- module.exports = SenderMessageKey;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SenderMessageKey = void 0;
4
+ const crypto_1 = require("libsignal/src/crypto");
5
+ class SenderMessageKey {
6
+ constructor(iteration, seed) {
7
+ const derivative = (0, crypto_1.deriveSecrets)(seed, Buffer.alloc(32), Buffer.from('WhisperGroup'));
8
+ const keys = new Uint8Array(32);
9
+ keys.set(new Uint8Array(derivative[0].slice(16)));
10
+ keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16);
11
+ this.iv = Buffer.from(derivative[0].slice(0, 16));
12
+ this.cipherKey = Buffer.from(keys.buffer);
13
+ this.iteration = iteration;
14
+ this.seed = seed;
15
+ }
16
+ getIteration() {
17
+ return this.iteration;
18
+ }
19
+ getIv() {
20
+ return this.iv;
21
+ }
22
+ getCipherKey() {
23
+ return this.cipherKey;
24
+ }
25
+ getSeed() {
26
+ return this.seed;
27
+ }
28
+ }
29
+ exports.SenderMessageKey = SenderMessageKey;
@@ -35,24 +35,30 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.makeLibSignalRepository = makeLibSignalRepository;
37
37
  const libsignal = __importStar(require("libsignal"));
38
- const WASignalGroup_1 = require("../../WASignalGroup");
39
38
  const Utils_1 = require("../Utils");
40
39
  const WABinary_1 = require("../WABinary");
40
+ const sender_key_name_1 = require("./Group/sender-key-name");
41
+ const sender_key_record_1 = require("./Group/sender-key-record");
42
+ const Group_1 = require("./Group");
41
43
  function makeLibSignalRepository(auth) {
42
44
  const storage = signalStorage(auth);
43
45
  return {
44
46
  decryptGroupMessage({ group, authorJid, msg }) {
45
47
  const senderName = jidToSignalSenderKeyName(group, authorJid);
46
- const cipher = new WASignalGroup_1.GroupCipher(storage, senderName);
48
+ const cipher = new Group_1.GroupCipher(storage, senderName);
47
49
  return cipher.decrypt(msg);
48
50
  },
49
51
  async processSenderKeyDistributionMessage({ item, authorJid }) {
50
- const builder = new WASignalGroup_1.GroupSessionBuilder(storage);
52
+ const builder = new Group_1.GroupSessionBuilder(storage);
53
+ if (!item.groupId) {
54
+ throw new Error('Group ID is required for sender key distribution message');
55
+ }
51
56
  const senderName = jidToSignalSenderKeyName(item.groupId, authorJid);
52
- const senderMsg = new WASignalGroup_1.SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage);
53
- const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName]);
57
+ const senderMsg = new Group_1.SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage);
58
+ const senderNameStr = senderName.toString();
59
+ const { [senderNameStr]: senderKey } = await auth.keys.get('sender-key', [senderNameStr]);
54
60
  if (!senderKey) {
55
- await storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord());
61
+ await storage.storeSenderKey(senderName, new sender_key_record_1.SenderKeyRecord());
56
62
  }
57
63
  await builder.process(senderName, senderMsg);
58
64
  },
@@ -67,6 +73,8 @@ function makeLibSignalRepository(auth) {
67
73
  case 'msg':
68
74
  result = await session.decryptWhisperMessage(ciphertext);
69
75
  break;
76
+ default:
77
+ throw new Error(`Unknown message type: ${type}`);
70
78
  }
71
79
  return result;
72
80
  },
@@ -79,13 +87,14 @@ function makeLibSignalRepository(auth) {
79
87
  },
80
88
  async encryptGroupMessage({ group, meId, data }) {
81
89
  const senderName = jidToSignalSenderKeyName(group, meId);
82
- const builder = new WASignalGroup_1.GroupSessionBuilder(storage);
83
- const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName]);
90
+ const builder = new Group_1.GroupSessionBuilder(storage);
91
+ const senderNameStr = senderName.toString();
92
+ const { [senderNameStr]: senderKey } = await auth.keys.get('sender-key', [senderNameStr]);
84
93
  if (!senderKey) {
85
- await storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord());
94
+ await storage.storeSenderKey(senderName, new sender_key_record_1.SenderKeyRecord());
86
95
  }
87
96
  const senderKeyDistributionMessage = await builder.create(senderName);
88
- const session = new WASignalGroup_1.GroupCipher(storage, senderName);
97
+ const session = new Group_1.GroupCipher(storage, senderName);
89
98
  const ciphertext = await session.encrypt(data);
90
99
  return {
91
100
  ciphertext,
@@ -106,7 +115,7 @@ const jidToSignalProtocolAddress = (jid) => {
106
115
  return new libsignal.ProtocolAddress(user, device || 0);
107
116
  };
108
117
  const jidToSignalSenderKeyName = (group, user) => {
109
- return new WASignalGroup_1.SenderKeyName(group, jidToSignalProtocolAddress(user)).toString();
118
+ return new sender_key_name_1.SenderKeyName(group, jidToSignalProtocolAddress(user));
110
119
  };
111
120
  function signalStorage({ creds, keys }) {
112
121
  return {
@@ -140,14 +149,18 @@ function signalStorage({ creds, keys }) {
140
149
  pubKey: Buffer.from(key.keyPair.public)
141
150
  };
142
151
  },
143
- loadSenderKey: async (keyId) => {
152
+ loadSenderKey: async (senderKeyName) => {
153
+ const keyId = senderKeyName.toString();
144
154
  const { [keyId]: key } = await keys.get('sender-key', [keyId]);
145
155
  if (key) {
146
- return new WASignalGroup_1.SenderKeyRecord(key);
156
+ return sender_key_record_1.SenderKeyRecord.deserialize(key);
147
157
  }
158
+ return new sender_key_record_1.SenderKeyRecord();
148
159
  },
149
- storeSenderKey: async (keyId, key) => {
150
- await keys.set({ 'sender-key': { [keyId]: key.serialize() } });
160
+ storeSenderKey: async (senderKeyName, key) => {
161
+ const keyId = senderKeyName.toString();
162
+ const serialized = JSON.stringify(key.serialize());
163
+ await keys.set({ 'sender-key': { [keyId]: Buffer.from(serialized, 'utf-8') } });
151
164
  },
152
165
  getOurRegistrationId: () => creds.registrationId,
153
166
  getOurIdentity: () => {
@@ -39,6 +39,29 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
39
39
  getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("../WABinary").JidWithDevice[]>;
40
40
  updateMediaMessage: (message: import("../Types").WAProto.IWebMessageInfo) => Promise<import("../Types").WAProto.IWebMessageInfo>;
41
41
  sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo | undefined>;
42
+ newsletterCreate: (name: string, description?: string) => Promise<import("../Types").NewsletterMetadata>;
43
+ newsletterUpdate: (jid: string, updates: import("../Types").NewsletterUpdate) => Promise<unknown>;
44
+ newsletterSubscribers: (jid: string) => Promise<{
45
+ subscribers: number;
46
+ }>;
47
+ newsletterMetadata: (type: "invite" | "jid", key: string) => Promise<import("../Types").NewsletterMetadata | null>;
48
+ newsletterFollow: (jid: string) => Promise<unknown>;
49
+ newsletterUnfollow: (jid: string) => Promise<unknown>;
50
+ newsletterMute: (jid: string) => Promise<unknown>;
51
+ newsletterUnmute: (jid: string) => Promise<unknown>;
52
+ newsletterUpdateName: (jid: string, name: string) => Promise<unknown>;
53
+ newsletterUpdateDescription: (jid: string, description: string) => Promise<unknown>;
54
+ newsletterUpdatePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<unknown>;
55
+ newsletterRemovePicture: (jid: string) => Promise<unknown>;
56
+ newsletterReactMessage: (jid: string, serverId: string, reaction?: string) => Promise<void>;
57
+ newsletterFetchMessages: (jid: string, count: number, since: number, after: number) => Promise<any>;
58
+ subscribeNewsletterUpdates: (jid: string) => Promise<{
59
+ duration: string;
60
+ } | null>;
61
+ newsletterAdminCount: (jid: string) => Promise<number>;
62
+ newsletterChangeOwner: (jid: string, newOwnerJid: string) => Promise<void>;
63
+ newsletterDemote: (jid: string, userJid: string) => Promise<void>;
64
+ newsletterDelete: (jid: string) => Promise<void>;
42
65
  groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
43
66
  groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
44
67
  groupLeave: (id: string) => Promise<void>;
@@ -73,7 +96,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
73
96
  processingMutex: {
74
97
  mutex<T>(code: () => Promise<T> | T): Promise<T>;
75
98
  };
76
- upsertMessage: (msg: import("../Types").WAProto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
99
+ upsertMessage: (msg: import("../Types").WAMessage, type: import("../Types").MessageUpsertType) => Promise<void>;
77
100
  appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
78
101
  sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
79
102
  presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
@@ -86,7 +109,10 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
86
109
  fetchBlocklist: () => Promise<string[]>;
87
110
  fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
88
111
  fetchDisappearingDuration: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
89
- updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
112
+ updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload, dimensions?: {
113
+ width: number;
114
+ height: number;
115
+ }) => Promise<void>;
90
116
  removeProfilePicture: (jid: string) => Promise<void>;
91
117
  updateProfileStatus: (status: string) => Promise<void>;
92
118
  updateProfileName: (name: string) => Promise<void>;
@@ -140,7 +166,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
140
166
  onUnexpectedError: (err: Error | import("@hapi/boom").Boom, msg: string) => void;
141
167
  uploadPreKeys: (count?: number) => Promise<void>;
142
168
  uploadPreKeysToServerIfRequired: () => Promise<void>;
143
- requestPairingCode: (phoneNumber: string) => Promise<string>;
169
+ requestPairingCode: (phoneNumber: string, customPairingCode?: string) => Promise<string>;
144
170
  waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
145
171
  sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
146
172
  };
@@ -1,6 +1,5 @@
1
1
  import { Boom } from '@hapi/boom';
2
- import { proto } from '../../WAProto';
3
- import { BotListInfo, ChatModification, MessageUpsertType, SocketConfig, WABusinessProfile, WAMediaUpload, WAPatchCreate, WAPresence, WAPrivacyCallValue, WAPrivacyGroupAddValue, WAPrivacyMessagesValue, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from '../Types';
2
+ import { BotListInfo, ChatModification, MessageUpsertType, SocketConfig, WABusinessProfile, WAMediaUpload, WAMessage, WAPatchCreate, WAPresence, WAPrivacyCallValue, WAPrivacyGroupAddValue, WAPrivacyMessagesValue, WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from '../Types';
4
3
  import { LabelActionBody } from '../Types/Label';
5
4
  import { BinaryNode } from '../WABinary';
6
5
  import { USyncQuery } from '../WAUSync';
@@ -12,7 +11,7 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
12
11
  fetchPrivacySettings: (force?: boolean) => Promise<{
13
12
  [_: string]: string;
14
13
  }>;
15
- upsertMessage: (msg: proto.IWebMessageInfo, type: MessageUpsertType) => Promise<void>;
14
+ upsertMessage: (msg: WAMessage, type: MessageUpsertType) => Promise<void>;
16
15
  appPatch: (patchCreate: WAPatchCreate) => Promise<void>;
17
16
  sendPresenceUpdate: (type: WAPresence, toJid?: string) => Promise<void>;
18
17
  presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
@@ -25,7 +24,10 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
25
24
  fetchBlocklist: () => Promise<string[]>;
26
25
  fetchStatus: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
27
26
  fetchDisappearingDuration: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
28
- updateProfilePicture: (jid: string, content: WAMediaUpload) => Promise<void>;
27
+ updateProfilePicture: (jid: string, content: WAMediaUpload, dimensions?: {
28
+ width: number;
29
+ height: number;
30
+ }) => Promise<void>;
29
31
  removeProfilePicture: (jid: string) => Promise<void>;
30
32
  updateProfileStatus: (status: string) => Promise<void>;
31
33
  updateProfileName: (name: string) => Promise<void>;
@@ -79,7 +81,7 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
79
81
  onUnexpectedError: (err: Error | Boom, msg: string) => void;
80
82
  uploadPreKeys: (count?: number) => Promise<void>;
81
83
  uploadPreKeysToServerIfRequired: () => Promise<void>;
82
- requestPairingCode: (phoneNumber: string) => Promise<string>;
84
+ requestPairingCode: (phoneNumber: string, customPairingCode?: string) => Promise<string>;
83
85
  waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
84
86
  sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
85
87
  };
@@ -181,7 +181,7 @@ const makeChatsSocket = (config) => {
181
181
  }
182
182
  };
183
183
  /** update the profile picture for yourself or a group */
184
- const updateProfilePicture = async (jid, content) => {
184
+ const updateProfilePicture = async (jid, content, dimensions) => {
185
185
  let targetJid;
186
186
  if (!jid) {
187
187
  throw new boom_1.Boom('Illegal no-jid profile update. Please specify either your ID or the ID of the chat you wish to update');
@@ -189,7 +189,7 @@ const makeChatsSocket = (config) => {
189
189
  if ((0, WABinary_1.jidNormalizedUser)(jid) !== (0, WABinary_1.jidNormalizedUser)(authState.creds.me.id)) {
190
190
  targetJid = (0, WABinary_1.jidNormalizedUser)(jid); // in case it is someone other than us
191
191
  }
192
- const { img } = await (0, Utils_1.generateProfilePicture)(content);
192
+ const { img } = await (0, Utils_1.generateProfilePicture)(content, dimensions);
193
193
  await query({
194
194
  tag: 'iq',
195
195
  attrs: {
@@ -493,16 +493,18 @@ const makeChatsSocket = (config) => {
493
493
  await sendNode({
494
494
  tag: 'presence',
495
495
  attrs: {
496
- name: me.name,
496
+ name: me.name.replace(/@/g, ''),
497
497
  type
498
498
  }
499
499
  });
500
500
  }
501
501
  else {
502
+ const { server } = (0, WABinary_1.jidDecode)(toJid);
503
+ const isLid = server === 'lid';
502
504
  await sendNode({
503
505
  tag: 'chatstate',
504
506
  attrs: {
505
- from: me.id,
507
+ from: isLid ? me.lid : me.id,
506
508
  to: toJid
507
509
  },
508
510
  content: [
@@ -50,7 +50,7 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
50
50
  fetchPrivacySettings: (force?: boolean) => Promise<{
51
51
  [_: string]: string;
52
52
  }>;
53
- upsertMessage: (msg: proto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
53
+ upsertMessage: (msg: import("../Types").WAMessage, type: import("../Types").MessageUpsertType) => Promise<void>;
54
54
  appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
55
55
  sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
56
56
  presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
@@ -63,7 +63,10 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
63
63
  fetchBlocklist: () => Promise<string[]>;
64
64
  fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
65
65
  fetchDisappearingDuration: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
66
- updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
66
+ updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload, dimensions?: {
67
+ width: number;
68
+ height: number;
69
+ }) => Promise<void>;
67
70
  removeProfilePicture: (jid: string) => Promise<void>;
68
71
  updateProfileStatus: (status: string) => Promise<void>;
69
72
  updateProfileName: (name: string) => Promise<void>;
@@ -117,8 +120,9 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
117
120
  onUnexpectedError: (err: Error | import("@hapi/boom").Boom, msg: string) => void;
118
121
  uploadPreKeys: (count?: number) => Promise<void>;
119
122
  uploadPreKeysToServerIfRequired: () => Promise<void>;
120
- requestPairingCode: (phoneNumber: string) => Promise<string>;
123
+ requestPairingCode: (phoneNumber: string, customPairingCode?: string) => Promise<string>;
121
124
  waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
122
125
  sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
123
126
  };
124
127
  export declare const extractGroupMetadata: (result: BinaryNode) => GroupMetadata;
128
+ export type GroupsSocket = ReturnType<typeof makeGroupsSocket>;