@queenanya/baileys 8.3.1 → 8.3.2

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 (87) hide show
  1. package/lib/Defaults/index.d.ts +0 -231
  2. package/lib/Defaults/index.js +1 -17
  3. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  4. package/lib/Signal/Group/ciphertext-message.js +15 -0
  5. package/lib/Signal/Group/group-session-builder.d.ts +14 -0
  6. package/lib/Signal/Group/group-session-builder.js +64 -0
  7. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  8. package/lib/Signal/Group/group_cipher.js +96 -0
  9. package/lib/Signal/Group/index.d.ts +11 -0
  10. package/lib/Signal/Group/index.js +57 -0
  11. package/lib/Signal/Group/keyhelper.d.ts +10 -0
  12. package/lib/Signal/Group/keyhelper.js +55 -0
  13. package/lib/Signal/Group/queue-job.d.ts +1 -0
  14. package/lib/Signal/Group/queue-job.js +57 -0
  15. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  16. package/lib/Signal/Group/sender-chain-key.js +34 -0
  17. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  18. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  19. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  20. package/lib/Signal/Group/sender-key-message.js +69 -0
  21. package/lib/Signal/Group/sender-key-name.d.ts +17 -0
  22. package/lib/Signal/Group/sender-key-name.js +51 -0
  23. package/lib/Signal/Group/sender-key-record.d.ts +30 -0
  24. package/lib/Signal/Group/sender-key-record.js +53 -0
  25. package/lib/Signal/Group/sender-key-state.d.ts +38 -0
  26. package/lib/Signal/Group/sender-key-state.js +99 -0
  27. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  28. package/{WASignalGroup/sender_message_key.js → lib/Signal/Group/sender-message-key.js} +6 -16
  29. package/lib/Signal/libsignal.js +33 -20
  30. package/lib/Socket/Client/index.d.ts +2 -3
  31. package/lib/Socket/Client/index.js +2 -3
  32. package/lib/Socket/Client/{abstract-socket-client.d.ts → types.d.ts} +1 -0
  33. package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +2 -1
  34. package/lib/Socket/Client/{web-socket-client.js → websocket.js} +12 -2
  35. package/lib/Socket/business.d.ts +5 -3
  36. package/lib/Socket/chats.d.ts +3 -1
  37. package/lib/Socket/chats.js +11 -8
  38. package/lib/Socket/groups.d.ts +3 -1
  39. package/lib/Socket/index.d.ts +5 -5
  40. package/lib/Socket/index.js +2 -2
  41. package/lib/Socket/messages-recv.d.ts +5 -3
  42. package/lib/Socket/messages-recv.js +16 -8
  43. package/lib/Socket/messages-send.d.ts +4 -2
  44. package/lib/Socket/messages-send.js +75 -9
  45. package/lib/Socket/newsletter.d.ts +3 -1
  46. package/lib/Socket/socket.d.ts +2 -1
  47. package/lib/Socket/socket.js +71 -14
  48. package/lib/Socket/usync.d.ts +1 -1
  49. package/lib/Store/make-in-memory-store.js +8 -10
  50. package/lib/Types/Auth.d.ts +0 -6
  51. package/lib/Types/Message.d.ts +16 -3
  52. package/lib/Types/Socket.d.ts +3 -3
  53. package/lib/Utils/auth-utils.js +0 -7
  54. package/lib/Utils/event-buffer.js +4 -6
  55. package/lib/Utils/index.d.ts +1 -0
  56. package/lib/Utils/index.js +1 -0
  57. package/lib/Utils/messages-media.js +11 -10
  58. package/lib/Utils/messages.js +10 -2
  59. package/lib/Utils/noise-handler.d.ts +1 -2
  60. package/lib/Utils/noise-handler.js +5 -10
  61. package/lib/Utils/use-single-file-auth-state.d.ts +5 -0
  62. package/lib/Utils/use-single-file-auth-state.js +66 -0
  63. package/lib/Utils/validate-connection.d.ts +0 -1
  64. package/lib/Utils/validate-connection.js +10 -44
  65. package/lib/WABinary/jid-utils.d.ts +1 -1
  66. package/lib/WABinary/jid-utils.js +1 -1
  67. package/package.json +2 -1
  68. package/WASignalGroup/GroupProtocol.js +0 -1697
  69. package/WASignalGroup/ciphertext_message.js +0 -16
  70. package/WASignalGroup/group_cipher.js +0 -120
  71. package/WASignalGroup/group_session_builder.js +0 -46
  72. package/WASignalGroup/index.js +0 -5
  73. package/WASignalGroup/keyhelper.js +0 -21
  74. package/WASignalGroup/protobufs.js +0 -3
  75. package/WASignalGroup/queue_job.js +0 -69
  76. package/WASignalGroup/sender_chain_key.js +0 -50
  77. package/WASignalGroup/sender_key_distribution_message.js +0 -78
  78. package/WASignalGroup/sender_key_message.js +0 -92
  79. package/WASignalGroup/sender_key_name.js +0 -70
  80. package/WASignalGroup/sender_key_record.js +0 -56
  81. package/WASignalGroup/sender_key_state.js +0 -129
  82. package/lib/Defaults/phonenumber-mcc.json +0 -223
  83. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -12
  84. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  85. package/lib/Socket/registration.d.ts +0 -266
  86. package/lib/Socket/registration.js +0 -166
  87. /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
@@ -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,17 +87,18 @@ 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,
92
- senderKeyDistributionMessage: senderKeyDistributionMessage.serialize(),
101
+ senderKeyDistributionMessage: senderKeyDistributionMessage.serialize()
93
102
  };
94
103
  },
95
104
  async injectE2ESession({ jid, session }) {
@@ -98,7 +107,7 @@ function makeLibSignalRepository(auth) {
98
107
  },
99
108
  jidToSignalProtocolAddress(jid) {
100
109
  return jidToSignalProtocolAddress(jid).toString();
101
- },
110
+ }
102
111
  };
103
112
  }
104
113
  const jidToSignalProtocolAddress = (jid) => {
@@ -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 {
@@ -117,7 +126,7 @@ function signalStorage({ creds, keys }) {
117
126
  }
118
127
  },
119
128
  storeSession: async (id, session) => {
120
- await keys.set({ 'session': { [id]: session.serialize() } });
129
+ await keys.set({ session: { [id]: session.serialize() } });
121
130
  },
122
131
  isTrustedIdentity: () => {
123
132
  return true;
@@ -140,21 +149,25 @@ 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
- getOurRegistrationId: () => (creds.registrationId),
165
+ getOurRegistrationId: () => creds.registrationId,
153
166
  getOurIdentity: () => {
154
167
  const { signedIdentityKey } = creds;
155
168
  return {
156
169
  privKey: Buffer.from(signedIdentityKey.private),
157
- pubKey: (0, Utils_1.generateSignalPubKey)(signedIdentityKey.public),
170
+ pubKey: (0, Utils_1.generateSignalPubKey)(signedIdentityKey.public)
158
171
  };
159
172
  }
160
173
  };
@@ -1,3 +1,2 @@
1
- export * from './abstract-socket-client';
2
- export * from './mobile-socket-client';
3
- export * from './web-socket-client';
1
+ export * from './types';
2
+ export * from './websocket';
@@ -14,6 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./abstract-socket-client"), exports);
18
- __exportStar(require("./mobile-socket-client"), exports);
19
- __exportStar(require("./web-socket-client"), exports);
17
+ __exportStar(require("./types"), exports);
18
+ __exportStar(require("./websocket"), exports);
@@ -11,5 +11,6 @@ export declare abstract class AbstractSocketClient extends EventEmitter {
11
11
  constructor(url: URL, config: SocketConfig);
12
12
  abstract connect(): Promise<void>;
13
13
  abstract close(): Promise<void>;
14
+ abstract restart(): Promise<void>;
14
15
  abstract send(str: Uint8Array | string, cb?: (err?: Error) => void): boolean;
15
16
  }
@@ -1,5 +1,5 @@
1
1
  import WebSocket from 'ws';
2
- import { AbstractSocketClient } from './abstract-socket-client';
2
+ import { AbstractSocketClient } from './types';
3
3
  export declare class WebSocketClient extends AbstractSocketClient {
4
4
  protected socket: WebSocket | null;
5
5
  get isOpen(): boolean;
@@ -8,5 +8,6 @@ export declare class WebSocketClient extends AbstractSocketClient {
8
8
  get isConnecting(): boolean;
9
9
  connect(): Promise<void>;
10
10
  close(): Promise<void>;
11
+ restart(): Promise<void>;
11
12
  send(str: string | Uint8Array, cb?: (err?: Error) => void): boolean;
12
13
  }
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.WebSocketClient = void 0;
7
7
  const ws_1 = __importDefault(require("ws"));
8
8
  const Defaults_1 = require("../../Defaults");
9
- const abstract_socket_client_1 = require("./abstract-socket-client");
10
- class WebSocketClient extends abstract_socket_client_1.AbstractSocketClient {
9
+ const types_1 = require("./types");
10
+ class WebSocketClient extends types_1.AbstractSocketClient {
11
11
  constructor() {
12
12
  super(...arguments);
13
13
  this.socket = null;
@@ -53,6 +53,16 @@ class WebSocketClient extends abstract_socket_client_1.AbstractSocketClient {
53
53
  this.socket.close();
54
54
  this.socket = null;
55
55
  }
56
+ async restart() {
57
+ if (this.socket) {
58
+ await new Promise(resolve => {
59
+ this.socket.once('close', resolve);
60
+ this.socket.terminate();
61
+ });
62
+ this.socket = null;
63
+ }
64
+ await this.connect();
65
+ }
56
66
  send(str, cb) {
57
67
  var _a;
58
68
  (_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(str, cb);
@@ -24,7 +24,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
24
24
  isVideo: boolean;
25
25
  }>;
26
26
  fetchMessageHistory: (count: number, oldestMsgKey: import("../Types").WAMessageKey, oldestMsgTimestamp: number | Long) => Promise<string>;
27
- requestPlaceholderResend: (messageKey: import("../Types").WAMessageKey) => Promise<"RESOLVED" | string | undefined>;
27
+ requestPlaceholderResend: (messageKey: import("../Types").WAMessageKey) => Promise<string | undefined>;
28
28
  getPrivacyTokens: (jids: string[]) => Promise<any>;
29
29
  assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
30
30
  relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
@@ -43,7 +43,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
43
43
  }>;
44
44
  sendPeerDataOperationMessage: (pdoMessage: import("../Types").WAProto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
45
45
  updateMediaMessage: (message: import("../Types").WAProto.IWebMessageInfo) => Promise<import("../Types").WAProto.IWebMessageInfo>;
46
- sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo | undefined>;
46
+ sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo>;
47
47
  subscribeNewsletterUpdates: (jid: string) => Promise<{
48
48
  duration: string;
49
49
  }>;
@@ -114,6 +114,8 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
114
114
  fetchDisappearingDuration: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
115
115
  fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
116
116
  updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
117
+ updateProfilePictureFull: any;
118
+ updateProfilePictureFull2: any;
117
119
  removeProfilePicture: (jid: string) => Promise<void>;
118
120
  updateProfileStatus: (status: string) => Promise<void>;
119
121
  updateProfileName: (name: string) => Promise<void>;
@@ -141,7 +143,7 @@ export declare const makeBusinessSocket: (config: SocketConfig) => {
141
143
  }[], star: boolean) => Promise<void>;
142
144
  executeUSyncQuery: (usyncQuery: import("..").USyncQuery) => Promise<import("..").USyncQueryResult | undefined>;
143
145
  type: "md";
144
- ws: any;
146
+ ws: import("./Client").WebSocketClient;
145
147
  ev: import("../Types").BaileysEventEmitter & {
146
148
  process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
147
149
  buffer(): void;
@@ -25,6 +25,8 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
25
25
  fetchDisappearingDuration: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
26
26
  fetchStatus: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
27
27
  updateProfilePicture: (jid: string, content: WAMediaUpload) => Promise<void>;
28
+ updateProfilePictureFull: any;
29
+ updateProfilePictureFull2: any;
28
30
  removeProfilePicture: (jid: string) => Promise<void>;
29
31
  updateProfileStatus: (status: string) => Promise<void>;
30
32
  updateProfileName: (name: string) => Promise<void>;
@@ -52,7 +54,7 @@ export declare const makeChatsSocket: (config: SocketConfig) => {
52
54
  }[], star: boolean) => Promise<void>;
53
55
  executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../WAUSync").USyncQueryResult | undefined>;
54
56
  type: "md";
55
- ws: any;
57
+ ws: import("./Client").WebSocketClient;
56
58
  ev: import("../Types").BaileysEventEmitter & {
57
59
  process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
58
60
  buffer(): void;
@@ -10,6 +10,7 @@ const WAProto_1 = require("../../WAProto");
10
10
  const Defaults_1 = require("../Defaults");
11
11
  const Types_1 = require("../Types");
12
12
  const Utils_1 = require("../Utils");
13
+ const chat_set_1 = require("./chat-set");
13
14
  const make_mutex_1 = require("../Utils/make-mutex");
14
15
  const process_message_1 = __importDefault(require("../Utils/process-message"));
15
16
  const WABinary_1 = require("../WABinary");
@@ -490,16 +491,18 @@ const makeChatsSocket = (config) => {
490
491
  await sendNode({
491
492
  tag: 'presence',
492
493
  attrs: {
493
- name: me.name,
494
+ name: me.name.replace(/@/g, ''),
494
495
  type
495
496
  }
496
497
  });
497
498
  }
498
499
  else {
500
+ const { server } = (0, WABinary_1.jidDecode)(toJid);
501
+ const isLid = server === 'lid';
499
502
  await sendNode({
500
503
  tag: 'chatstate',
501
504
  attrs: {
502
- from: me.id,
505
+ from: isLid ? me.lid : me.id,
503
506
  to: toJid,
504
507
  },
505
508
  content: [
@@ -819,14 +822,12 @@ const makeChatsSocket = (config) => {
819
822
  sendPresenceUpdate(markOnlineOnConnect ? 'available' : 'unavailable')
820
823
  .catch(error => onUnexpectedError(error, 'presence update requests'));
821
824
  }
822
- if (receivedPendingNotifications) {
823
- // if we don't have the app state key
825
+ if (receivedPendingNotifications && // if we don't have the app state key
824
826
  // we keep buffering events until we finally have
825
827
  // the key and can sync the messages
826
- if (!((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId) && !config.mobile) {
827
- ev.buffer();
828
- needToFlushWithAppStateSync = true;
829
- }
828
+ !((_a = authState.creds) === null || _a === void 0 ? void 0 : _a.myAppStateKeyId)) {
829
+ ev.buffer();
830
+ needToFlushWithAppStateSync = true;
830
831
  }
831
832
  });
832
833
  return {
@@ -844,6 +845,8 @@ const makeChatsSocket = (config) => {
844
845
  fetchDisappearingDuration,
845
846
  fetchStatus,
846
847
  updateProfilePicture,
848
+ updateProfilePictureFull: chat_set_1.updateProfilePictureFull,
849
+ updateProfilePictureFull2: chat_set_1.updateProfilePictureFull2,
847
850
  removeProfilePicture,
848
851
  updateProfileStatus,
849
852
  updateProfileName,
@@ -65,6 +65,8 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
65
65
  fetchDisappearingDuration: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
66
66
  fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
67
67
  updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
68
+ updateProfilePictureFull: any;
69
+ updateProfilePictureFull2: any;
68
70
  removeProfilePicture: (jid: string) => Promise<void>;
69
71
  updateProfileStatus: (status: string) => Promise<void>;
70
72
  updateProfileName: (name: string) => Promise<void>;
@@ -92,7 +94,7 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
92
94
  }[], star: boolean) => Promise<void>;
93
95
  executeUSyncQuery: (usyncQuery: import("..").USyncQuery) => Promise<import("..").USyncQueryResult | undefined>;
94
96
  type: "md";
95
- ws: any;
97
+ ws: import("./Client").WebSocketClient;
96
98
  ev: import("../Types").BaileysEventEmitter & {
97
99
  process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
98
100
  buffer(): void;
@@ -1,7 +1,5 @@
1
1
  import { UserFacingSocketConfig } from '../Types';
2
2
  declare const makeWASocket: (config: UserFacingSocketConfig) => {
3
- register: (code: string) => Promise<import("./registration").ExistsResponse>;
4
- requestRegistrationCode: (registrationOptions?: import("./registration").RegistrationOptions) => Promise<import("./registration").ExistsResponse>;
5
3
  logger: import("../Utils/logger").ILogger;
6
4
  getOrderDetails: (orderId: string, tokenBase64: string) => Promise<import("../Types").OrderDetails>;
7
5
  getCatalog: ({ jid, limit, cursor }: import("../Types").GetCatalogOptions) => Promise<{
@@ -25,7 +23,7 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
25
23
  isVideo: boolean;
26
24
  }>;
27
25
  fetchMessageHistory: (count: number, oldestMsgKey: import("../Types").WAMessageKey, oldestMsgTimestamp: number | Long) => Promise<string>;
28
- requestPlaceholderResend: (messageKey: import("../Types").WAMessageKey) => Promise<"RESOLVED" | string | undefined>;
26
+ requestPlaceholderResend: (messageKey: import("../Types").WAMessageKey) => Promise<string | undefined>;
29
27
  getPrivacyTokens: (jids: string[]) => Promise<any>;
30
28
  assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
31
29
  relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
@@ -44,7 +42,7 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
44
42
  }>;
45
43
  sendPeerDataOperationMessage: (pdoMessage: import("../Types").WAProto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
46
44
  updateMediaMessage: (message: import("../Types").WAProto.IWebMessageInfo) => Promise<import("../Types").WAProto.IWebMessageInfo>;
47
- sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo | undefined>;
45
+ sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo>;
48
46
  subscribeNewsletterUpdates: (jid: string) => Promise<{
49
47
  duration: string;
50
48
  }>;
@@ -115,6 +113,8 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
115
113
  fetchDisappearingDuration: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
116
114
  fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
117
115
  updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
116
+ updateProfilePictureFull: any;
117
+ updateProfilePictureFull2: any;
118
118
  removeProfilePicture: (jid: string) => Promise<void>;
119
119
  updateProfileStatus: (status: string) => Promise<void>;
120
120
  updateProfileName: (name: string) => Promise<void>;
@@ -142,7 +142,7 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
142
142
  }[], star: boolean) => Promise<void>;
143
143
  executeUSyncQuery: (usyncQuery: import("..").USyncQuery) => Promise<import("..").USyncQueryResult | undefined>;
144
144
  type: "md";
145
- ws: any;
145
+ ws: import("./Client").WebSocketClient;
146
146
  ev: import("../Types").BaileysEventEmitter & {
147
147
  process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
148
148
  buffer(): void;
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const Defaults_1 = require("../Defaults");
4
- const registration_1 = require("./registration");
4
+ const business_1 = require("./business");
5
5
  // export the last socket layer
6
- const makeWASocket = (config) => ((0, registration_1.makeRegistrationSocket)({
6
+ const makeWASocket = (config) => ((0, business_1.makeBusinessSocket)({
7
7
  ...Defaults_1.DEFAULT_CONNECTION_CONFIG,
8
8
  ...config
9
9
  }));
@@ -13,7 +13,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
13
13
  isVideo: boolean;
14
14
  }>;
15
15
  fetchMessageHistory: (count: number, oldestMsgKey: WAMessageKey, oldestMsgTimestamp: number | Long) => Promise<string>;
16
- requestPlaceholderResend: (messageKey: WAMessageKey) => Promise<"RESOLVED" | string | undefined>;
16
+ requestPlaceholderResend: (messageKey: WAMessageKey) => Promise<string | undefined>;
17
17
  getPrivacyTokens: (jids: string[]) => Promise<any>;
18
18
  assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
19
19
  relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<string>;
@@ -32,7 +32,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
32
32
  }>;
33
33
  sendPeerDataOperationMessage: (pdoMessage: proto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
34
34
  updateMediaMessage: (message: proto.IWebMessageInfo) => Promise<proto.IWebMessageInfo>;
35
- sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo | undefined>;
35
+ sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo>;
36
36
  subscribeNewsletterUpdates: (jid: string) => Promise<{
37
37
  duration: string;
38
38
  }>;
@@ -103,6 +103,8 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
103
103
  fetchDisappearingDuration: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
104
104
  fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
105
105
  updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
106
+ updateProfilePictureFull: any;
107
+ updateProfilePictureFull2: any;
106
108
  removeProfilePicture: (jid: string) => Promise<void>;
107
109
  updateProfileStatus: (status: string) => Promise<void>;
108
110
  updateProfileName: (name: string) => Promise<void>;
@@ -130,7 +132,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
130
132
  }[], star: boolean) => Promise<void>;
131
133
  executeUSyncQuery: (usyncQuery: import("..").USyncQuery) => Promise<import("..").USyncQueryResult | undefined>;
132
134
  type: "md";
133
- ws: any;
135
+ ws: import("./Client").WebSocketClient;
134
136
  ev: import("../Types").BaileysEventEmitter & {
135
137
  process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
136
138
  buffer(): void;
@@ -18,7 +18,7 @@ const messages_send_1 = require("./messages-send");
18
18
  const makeMessagesRecvSocket = (config) => {
19
19
  const { logger, retryRequestDelayMs, maxMsgRetryCount, getMessage, shouldIgnoreJid } = config;
20
20
  const sock = (0, messages_send_1.makeMessagesSocket)(config);
21
- const { ev, authState, ws, processingMutex, signalRepository, query, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, createParticipantNodes, getUSyncDevices, sendPeerDataOperationMessage, } = sock;
21
+ const { ev, authState, ws, processingMutex, signalRepository, query, upsertMessage, resyncAppState, groupMetadata, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, createParticipantNodes, getUSyncDevices, sendPeerDataOperationMessage, } = sock;
22
22
  /** this mutex ensures that each retryRequest will wait for the previous one to finish */
23
23
  const retryMutex = (0, make_mutex_1.makeMutex)();
24
24
  const msgRetryCache = config.msgRetryCounterCache || new node_cache_1.default({
@@ -574,8 +574,7 @@ const makeMessagesRecvSocket = (config) => {
574
574
  await authState.keys.set({ 'sender-key-memory': { [remoteJid]: null } });
575
575
  }
576
576
  logger.debug({ participant, sendToAll }, 'forced new session for retry recp');
577
- for (let i = 0; i < msgs.length; i++) {
578
- const msg = msgs[i];
577
+ for (const [i, msg] of msgs.entries()) {
579
578
  if (msg) {
580
579
  updateSendMessageAgainCount(ids[i], participant);
581
580
  const msgRelayOpts = { messageId: ids[i] };
@@ -742,15 +741,13 @@ const makeMessagesRecvSocket = (config) => {
742
741
  if (response && ((_a = msg === null || msg === void 0 ? void 0 : msg.messageStubParameters) === null || _a === void 0 ? void 0 : _a[0]) === Utils_1.NO_MESSAGE_FOUND_ERROR_TEXT) {
743
742
  msg.messageStubParameters = [Utils_1.NO_MESSAGE_FOUND_ERROR_TEXT, response];
744
743
  }
745
- if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.type) === WAProto_1.proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER) {
746
- if (node.attrs.sender_pn) {
747
- ev.emit('chats.phoneNumberShare', { lid: node.attrs.from, jid: node.attrs.sender_pn });
748
- }
744
+ if (((_c = (_b = msg.message) === null || _b === void 0 ? void 0 : _b.protocolMessage) === null || _c === void 0 ? void 0 : _c.type) === WAProto_1.proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER && node.attrs.sender_pn) {
745
+ ev.emit('chats.phoneNumberShare', { lid: node.attrs.from, jid: node.attrs.sender_pn });
749
746
  }
750
747
  try {
751
748
  await Promise.all([
752
749
  processingMutex.mutex(async () => {
753
- var _a, _b;
750
+ var _a, _b, _c, _d, _e, _f;
754
751
  await decrypt();
755
752
  // message failed to decrypt
756
753
  if (msg.messageStubType === WAProto_1.proto.WebMessageInfo.StubType.CIPHERTEXT) {
@@ -779,6 +776,17 @@ const makeMessagesRecvSocket = (config) => {
779
776
  if ((_b = msg.key.participant) === null || _b === void 0 ? void 0 : _b.endsWith('@lid')) {
780
777
  msg.key.participant = node.attrs.participant_pn || authState.creds.me.id;
781
778
  }
779
+ if ((0, WABinary_1.isJidGroup)(msg.key.remoteJid) && ((_f = (_e = (_d = (_c = msg.message) === null || _c === void 0 ? void 0 : _c.extendedTextMessage) === null || _d === void 0 ? void 0 : _d.contextInfo) === null || _e === void 0 ? void 0 : _e.participant) === null || _f === void 0 ? void 0 : _f.endsWith('@lid'))) {
780
+ if (msg.message.extendedTextMessage.contextInfo) {
781
+ const metadata = await groupMetadata(msg.key.remoteJid);
782
+ const sender = msg.message.extendedTextMessage.contextInfo.participant;
783
+ const found = metadata.participants.find(p => p.id === sender);
784
+ msg.message.extendedTextMessage.contextInfo.participant = (found === null || found === void 0 ? void 0 : found.jid) || sender;
785
+ }
786
+ }
787
+ if (!(0, WABinary_1.isJidGroup)(msg.key.remoteJid) && (0, WABinary_1.isLidUser)(msg.key.remoteJid)) {
788
+ msg.key.remoteJid = node.attrs.sender_pn || node.attrs.peer_recipient_pn;
789
+ }
782
790
  let participant = msg.key.participant;
783
791
  if (category === 'peer') { // special peer message
784
792
  type = 'peer_msg';
@@ -22,7 +22,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
22
22
  }>;
23
23
  sendPeerDataOperationMessage: (pdoMessage: proto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
24
24
  updateMediaMessage: (message: proto.IWebMessageInfo) => Promise<proto.IWebMessageInfo>;
25
- sendMessage: (jid: string, content: AnyMessageContent, options?: MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo | undefined>;
25
+ sendMessage: (jid: string, content: AnyMessageContent, options?: MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo>;
26
26
  subscribeNewsletterUpdates: (jid: string) => Promise<{
27
27
  duration: string;
28
28
  }>;
@@ -93,6 +93,8 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
93
93
  fetchDisappearingDuration: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
94
94
  fetchStatus: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
95
95
  updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
96
+ updateProfilePictureFull: any;
97
+ updateProfilePictureFull2: any;
96
98
  removeProfilePicture: (jid: string) => Promise<void>;
97
99
  updateProfileStatus: (status: string) => Promise<void>;
98
100
  updateProfileName: (name: string) => Promise<void>;
@@ -120,7 +122,7 @@ export declare const makeMessagesSocket: (config: SocketConfig) => {
120
122
  }[], star: boolean) => Promise<void>;
121
123
  executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../WAUSync").USyncQueryResult | undefined>;
122
124
  type: "md";
123
- ws: any;
125
+ ws: import("./Client").WebSocketClient;
124
126
  ev: import("../Types").BaileysEventEmitter & {
125
127
  process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
126
128
  buffer(): void;
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.makeMessagesSocket = void 0;
7
7
  const boom_1 = require("@hapi/boom");
8
8
  const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
9
+ const crypto_1 = require("crypto");
9
10
  const WAProto_1 = require("../../WAProto");
10
11
  const Defaults_1 = require("../Defaults");
11
12
  const Utils_1 = require("../Utils");
@@ -279,7 +280,8 @@ const makeMessagesSocket = (config) => {
279
280
  deviceSentMessage: {
280
281
  destinationJid,
281
282
  message
282
- }
283
+ },
284
+ messageContextInfo: message.messageContextInfo
283
285
  };
284
286
  const extraAttrs = {};
285
287
  if (participant) {
@@ -401,14 +403,13 @@ const makeMessagesSocket = (config) => {
401
403
  });
402
404
  }
403
405
  else {
404
- const { user: meUser, device: meDevice } = (0, WABinary_1.jidDecode)(meId);
406
+ const { user: meUser } = (0, WABinary_1.jidDecode)(meId);
405
407
  if (!participant) {
406
408
  devices.push({ user });
407
- // do not send message to self if the device is 0 (mobile)
408
- if (!((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) === 'peer' && user === meUser)) {
409
- if (meDevice !== undefined && meDevice !== 0) {
410
- devices.push({ user: meUser });
411
- }
409
+ if (user !== meUser) {
410
+ devices.push({ user: meUser });
411
+ }
412
+ if ((additionalAttributes === null || additionalAttributes === void 0 ? void 0 : additionalAttributes['category']) !== 'peer') {
412
413
  const additionalDevices = await getUSyncDevices([meId, jid], !!useUserDevicesCache, true);
413
414
  devices.push(...additionalDevices);
414
415
  }
@@ -686,7 +687,7 @@ const makeMessagesSocket = (config) => {
686
687
  return message;
687
688
  },
688
689
  sendMessage: async (jid, content, options = {}) => {
689
- var _a, _b, _c, _d, _e;
690
+ var _a, _b, _c;
690
691
  const userJid = authState.creds.me.id;
691
692
  if (!options.ephemeralExpiration) {
692
693
  if ((0, WABinary_1.isJidGroup)(jid)) {
@@ -711,6 +712,71 @@ const makeMessagesSocket = (config) => {
711
712
  disappearingMessagesInChat;
712
713
  await groupToggleEphemeral(jid, value);
713
714
  }
715
+ if (typeof content === 'object' && 'album' in content && content.album) {
716
+ const { album, caption } = content;
717
+ if (caption && !album[0].caption) {
718
+ album[0].caption = caption;
719
+ }
720
+ let mediaHandle;
721
+ let mediaMsg;
722
+ const albumMsg = (0, Utils_1.generateWAMessageFromContent)(jid, {
723
+ albumMessage: {
724
+ expectedImageCount: album.filter(item => 'image' in item).length,
725
+ expectedVideoCount: album.filter(item => 'video' in item).length
726
+ }
727
+ }, { userJid, ...options });
728
+ await relayMessage(jid, albumMsg.message, {
729
+ messageId: albumMsg.key.id
730
+ });
731
+ for (const i in album) {
732
+ const media = album[i];
733
+ if ('image' in media) {
734
+ mediaMsg = await (0, Utils_1.generateWAMessage)(jid, {
735
+ image: media.image,
736
+ ...(media.caption ? { caption: media.caption } : {}),
737
+ ...options
738
+ }, {
739
+ userJid,
740
+ upload: async (readStream, opts) => {
741
+ const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
742
+ mediaHandle = up.handle;
743
+ return up;
744
+ },
745
+ ...options,
746
+ });
747
+ }
748
+ else if ('video' in media) {
749
+ mediaMsg = await (0, Utils_1.generateWAMessage)(jid, {
750
+ video: media.video,
751
+ ...(media.caption ? { caption: media.caption } : {}),
752
+ ...(media.gifPlayback !== undefined ? { gifPlayback: media.gifPlayback } : {}),
753
+ ...options
754
+ }, {
755
+ userJid,
756
+ upload: async (readStream, opts) => {
757
+ const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
758
+ mediaHandle = up.handle;
759
+ return up;
760
+ },
761
+ ...options,
762
+ });
763
+ }
764
+ if (mediaMsg) {
765
+ mediaMsg.message.messageContextInfo = {
766
+ messageSecret: (0, crypto_1.randomBytes)(32),
767
+ messageAssociation: {
768
+ associationType: 1,
769
+ parentMessageKey: albumMsg.key
770
+ }
771
+ };
772
+ }
773
+ await relayMessage(jid, mediaMsg.message, {
774
+ messageId: mediaMsg.key.id
775
+ });
776
+ await new Promise(resolve => setTimeout(resolve, 800));
777
+ }
778
+ return albumMsg;
779
+ }
714
780
  else {
715
781
  let mediaHandle;
716
782
  const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
@@ -749,7 +815,7 @@ const makeMessagesSocket = (config) => {
749
815
  // required for delete
750
816
  if (isDeleteMsg) {
751
817
  // if the chat is a group, and I am not the author, then delete the message as an admin
752
- if (((0, WABinary_1.isJidGroup)((_d = content.delete) === null || _d === void 0 ? void 0 : _d.remoteJid) && !((_e = content.delete) === null || _e === void 0 ? void 0 : _e.fromMe)) || (0, WABinary_1.isJidNewsletter)(jid)) {
818
+ if (((0, WABinary_1.isJidGroup)(content.delete.remoteJid) && !content.delete.fromMe) || (0, WABinary_1.isJidNewsletter)(jid)) {
753
819
  additionalAttributes.edit = '8';
754
820
  }
755
821
  else {