lordceaser-baileys 2.0.13 → 2.0.15

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 (188) hide show
  1. package/lib/Defaults/baileys-version.json +3 -0
  2. package/lib/Defaults/index.d.ts +284 -0
  3. package/lib/Defaults/index.js +121 -0
  4. package/lib/Defaults/phonenumber-mcc.json +223 -0
  5. package/lib/Signal/libsignal.d.ts +4 -0
  6. package/lib/Signal/libsignal.js +162 -0
  7. package/lib/Socket/Client/abstract-socket-client.d.ts +15 -0
  8. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  9. package/lib/Socket/Client/index.d.ts +2 -0
  10. package/lib/Socket/Client/index.js +22 -0
  11. package/lib/Socket/Client/mobile-socket-client.d.ts +12 -0
  12. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  13. package/lib/Socket/Client/types.d.ts +16 -0
  14. package/lib/Socket/Client/types.js +18 -0
  15. package/lib/Socket/Client/web-socket-client.js +62 -0
  16. package/lib/Socket/Client/websocket.d.ts +13 -0
  17. package/lib/Socket/Client/websocket.js +62 -0
  18. package/lib/Socket/business.d.ts +182 -0
  19. package/lib/Socket/business.js +268 -0
  20. package/lib/Socket/chats.d.ts +96 -0
  21. package/lib/Socket/chats.js +1026 -0
  22. package/lib/Socket/groups.d.ts +130 -0
  23. package/lib/Socket/groups.js +338 -0
  24. package/lib/Socket/index.d.ts +185 -0
  25. package/lib/Socket/index.js +14 -0
  26. package/lib/Socket/messages-recv.d.ts +171 -0
  27. package/lib/Socket/messages-recv.js +1182 -0
  28. package/lib/Socket/messages-send.d.ts +162 -0
  29. package/lib/Socket/messages-send.js +1006 -0
  30. package/lib/Socket/newsletter.d.ts +142 -0
  31. package/lib/Socket/newsletter.js +256 -0
  32. package/lib/Socket/registration.d.ts +264 -0
  33. package/lib/Socket/registration.js +166 -0
  34. package/lib/Socket/socket.d.ts +45 -0
  35. package/lib/Socket/socket.js +751 -0
  36. package/lib/Socket/socket.js.bak +751 -0
  37. package/lib/Socket/usync.d.ts +37 -0
  38. package/lib/Socket/usync.js +83 -0
  39. package/lib/Store/index.d.ts +4 -0
  40. package/lib/Store/index.js +24 -0
  41. package/lib/Store/make-cache-manager-store.d.ts +14 -0
  42. package/lib/Store/make-cache-manager-store.js +90 -0
  43. package/lib/Store/make-in-memory-store.d.ts +123 -0
  44. package/lib/Store/make-in-memory-store.js +429 -0
  45. package/lib/Store/make-ordered-dictionary.d.ts +12 -0
  46. package/lib/Store/make-ordered-dictionary.js +86 -0
  47. package/lib/Store/object-repository.d.ts +10 -0
  48. package/lib/Store/object-repository.js +31 -0
  49. package/lib/Types/Auth.d.ts +120 -0
  50. package/lib/Types/Auth.js +3 -0
  51. package/lib/Types/Call.d.ts +14 -0
  52. package/lib/Types/Call.js +3 -0
  53. package/lib/Types/Chat.d.ts +134 -0
  54. package/lib/Types/Chat.js +9 -0
  55. package/lib/Types/Contact.d.ts +25 -0
  56. package/lib/Types/Contact.js +3 -0
  57. package/lib/Types/Events.d.ts +212 -0
  58. package/lib/Types/Events.js +3 -0
  59. package/lib/Types/GroupMetadata.d.ts +64 -0
  60. package/lib/Types/GroupMetadata.js +3 -0
  61. package/lib/Types/Label.d.ts +48 -0
  62. package/lib/Types/Label.js +31 -0
  63. package/lib/Types/LabelAssociation.d.ts +35 -0
  64. package/lib/Types/LabelAssociation.js +13 -0
  65. package/lib/Types/Message.d.ts +459 -0
  66. package/lib/Types/Message.js +13 -0
  67. package/lib/Types/Newsletter.d.ts +107 -0
  68. package/lib/Types/Newsletter.js +38 -0
  69. package/lib/Types/Product.d.ts +92 -0
  70. package/lib/Types/Product.js +3 -0
  71. package/lib/Types/Signal.d.ts +68 -0
  72. package/lib/Types/Signal.js +3 -0
  73. package/lib/Types/Socket.d.ts +120 -0
  74. package/lib/Types/Socket.js +3 -0
  75. package/lib/Types/State.d.ts +29 -0
  76. package/lib/Types/State.js +3 -0
  77. package/lib/Types/USync.d.ts +26 -0
  78. package/lib/Types/USync.js +3 -0
  79. package/lib/Types/index.d.ts +78 -0
  80. package/lib/Types/index.js +47 -0
  81. package/lib/Utils/auth-utils.d.ts +21 -0
  82. package/lib/Utils/auth-utils.js +205 -0
  83. package/lib/Utils/baileys-event-stream.d.ts +18 -0
  84. package/lib/Utils/baileys-event-stream.js +70 -0
  85. package/lib/Utils/business.d.ts +29 -0
  86. package/lib/Utils/business.js +247 -0
  87. package/lib/Utils/chat-utils.d.ts +82 -0
  88. package/lib/Utils/chat-utils.js +774 -0
  89. package/lib/Utils/crypto.d.ts +56 -0
  90. package/lib/Utils/crypto.js +179 -0
  91. package/lib/Utils/decode-wa-message.d.ts +41 -0
  92. package/lib/Utils/decode-wa-message.js +236 -0
  93. package/lib/Utils/event-buffer.d.ts +39 -0
  94. package/lib/Utils/event-buffer.js +548 -0
  95. package/lib/Utils/generics.d.ts +129 -0
  96. package/lib/Utils/generics.js +485 -0
  97. package/lib/Utils/history.d.ts +23 -0
  98. package/lib/Utils/history.js +100 -0
  99. package/lib/Utils/index.d.ts +20 -0
  100. package/lib/Utils/index.js +40 -0
  101. package/lib/Utils/link-preview.d.ts +23 -0
  102. package/lib/Utils/link-preview.js +120 -0
  103. package/lib/Utils/logger.d.ts +13 -0
  104. package/lib/Utils/logger.js +7 -0
  105. package/lib/Utils/lt-hash.d.ts +14 -0
  106. package/lib/Utils/lt-hash.js +58 -0
  107. package/lib/Utils/make-mutex.d.ts +9 -0
  108. package/lib/Utils/make-mutex.js +49 -0
  109. package/lib/Utils/messages-media.d.ts +129 -0
  110. package/lib/Utils/messages-media.js +782 -0
  111. package/lib/Utils/messages.d.ts +103 -0
  112. package/lib/Utils/messages.js +1631 -0
  113. package/lib/Utils/noise-handler.d.ts +20 -0
  114. package/lib/Utils/noise-handler.js +155 -0
  115. package/lib/Utils/process-message.d.ts +49 -0
  116. package/lib/Utils/process-message.js +387 -0
  117. package/lib/Utils/signal.d.ts +42 -0
  118. package/lib/Utils/signal.js +166 -0
  119. package/lib/Utils/use-mongo-file-auth-state.d.ts +6 -0
  120. package/lib/Utils/use-mongo-file-auth-state.js +84 -0
  121. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  122. package/lib/Utils/use-multi-file-auth-state.js +131 -0
  123. package/lib/Utils/use-single-file-auth-state.d.ts +13 -0
  124. package/lib/Utils/use-single-file-auth-state.js +80 -0
  125. package/lib/Utils/use-sql-file-auth-state.d.ts +6 -0
  126. package/lib/Utils/use-sql-file-auth-state.js +143 -0
  127. package/lib/Utils/validate-connection.d.ts +13 -0
  128. package/lib/Utils/validate-connection.js +186 -0
  129. package/lib/WABinary/constants.d.ts +30 -0
  130. package/lib/WABinary/constants.js +53 -0
  131. package/lib/WABinary/decode.d.ts +9 -0
  132. package/lib/WABinary/decode.js +288 -0
  133. package/lib/WABinary/encode.d.ts +3 -0
  134. package/lib/WABinary/encode.js +256 -0
  135. package/lib/WABinary/generic-utils.d.ts +28 -0
  136. package/lib/WABinary/generic-utils.js +150 -0
  137. package/lib/WABinary/index.d.ts +5 -0
  138. package/lib/WABinary/index.js +25 -0
  139. package/lib/WABinary/jid-utils.d.ts +53 -0
  140. package/lib/WABinary/jid-utils.js +92 -0
  141. package/lib/WABinary/types.d.ts +22 -0
  142. package/lib/WABinary/types.js +3 -0
  143. package/lib/WAM/BinaryInfo.d.ts +16 -0
  144. package/lib/WAM/BinaryInfo.js +17 -0
  145. package/lib/WAM/constants.d.ts +47 -0
  146. package/lib/WAM/constants.js +15371 -0
  147. package/lib/WAM/encode.d.ts +3 -0
  148. package/lib/WAM/encode.js +165 -0
  149. package/lib/WAM/index.d.ts +3 -0
  150. package/lib/WAM/index.js +23 -0
  151. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +28 -0
  152. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +69 -0
  153. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  154. package/lib/WAUSync/Protocols/USyncContactProtocol.js +36 -0
  155. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +26 -0
  156. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +62 -0
  157. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +14 -0
  158. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +35 -0
  159. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +9 -0
  160. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +30 -0
  161. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +14 -0
  162. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +46 -0
  163. package/lib/WAUSync/Protocols/index.d.ts +6 -0
  164. package/lib/WAUSync/Protocols/index.js +26 -0
  165. package/lib/WAUSync/USyncQuery.d.ts +31 -0
  166. package/lib/WAUSync/USyncQuery.js +92 -0
  167. package/lib/WAUSync/USyncUser.d.ts +12 -0
  168. package/lib/WAUSync/USyncUser.js +30 -0
  169. package/lib/WAUSync/index.d.ts +3 -0
  170. package/lib/WAUSync/index.js +23 -0
  171. package/lib/index.d.ts +13 -0
  172. package/lib/index.js +33 -0
  173. package/package.json +1 -1
  174. package/WASignalGroup/GroupProtocol.js +0 -1697
  175. package/WASignalGroup/ciphertext_message.js +0 -16
  176. package/WASignalGroup/group_cipher.js +0 -120
  177. package/WASignalGroup/group_session_builder.js +0 -46
  178. package/WASignalGroup/index.js +0 -5
  179. package/WASignalGroup/keyhelper.js +0 -21
  180. package/WASignalGroup/protobufs.js +0 -3
  181. package/WASignalGroup/queue_job.js +0 -69
  182. package/WASignalGroup/sender_chain_key.js +0 -50
  183. package/WASignalGroup/sender_key_distribution_message.js +0 -78
  184. package/WASignalGroup/sender_key_message.js +0 -92
  185. package/WASignalGroup/sender_key_name.js +0 -70
  186. package/WASignalGroup/sender_key_record.js +0 -56
  187. package/WASignalGroup/sender_key_state.js +0 -129
  188. package/WASignalGroup/sender_message_key.js +0 -39
@@ -0,0 +1,162 @@
1
+ "use strict"
2
+
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k
5
+ var desc = Object.getOwnPropertyDescriptor(m, k)
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k] } }
8
+ }
9
+ Object.defineProperty(o, k2, desc)
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k
12
+ o[k2] = m[k]
13
+ }))
14
+
15
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
+ Object.defineProperty(o, "default", { enumerable: true, value: v })
17
+ }) : function(o, v) {
18
+ o["default"] = v
19
+ })
20
+
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod
23
+ var result = {}
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k)
25
+ __setModuleDefault(result, mod)
26
+ return result
27
+ }
28
+ Object.defineProperty(exports, "__esModule", { value: true })
29
+
30
+ const libsignal = __importStar(require("libsignal"))
31
+ const WASignalGroup_1 = require("../../WASignalGroup")
32
+ const Utils_1 = require("../Utils")
33
+ const WABinary_1 = require("../WABinary")
34
+
35
+ function makeLibSignalRepository(auth) {
36
+ const storage = signalStorage(auth)
37
+ return {
38
+ decryptGroupMessage({ group, authorJid, msg }) {
39
+ const senderName = jidToSignalSenderKeyName(group, authorJid)
40
+ const cipher = new WASignalGroup_1.GroupCipher(storage, senderName)
41
+ return cipher.decrypt(msg)
42
+ },
43
+ async processSenderKeyDistributionMessage({ item, authorJid }) {
44
+ const builder = new WASignalGroup_1.GroupSessionBuilder(storage)
45
+ const senderName = jidToSignalSenderKeyName(item.groupId, authorJid)
46
+ const senderMsg = new WASignalGroup_1.SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage)
47
+ const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName])
48
+ if (!senderKey) {
49
+ await storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord())
50
+ }
51
+ await builder.process(senderName, senderMsg)
52
+ },
53
+ async decryptMessage({ jid, type, ciphertext }) {
54
+ const addr = jidToSignalProtocolAddress(jid)
55
+ const session = new libsignal.SessionCipher(storage, addr)
56
+ let result
57
+ switch (type) {
58
+ case 'pkmsg':
59
+ result = await session.decryptPreKeyWhisperMessage(ciphertext)
60
+ break
61
+ case 'msg':
62
+ result = await session.decryptWhisperMessage(ciphertext)
63
+ break
64
+ }
65
+ return result
66
+ },
67
+ async encryptMessage({ jid, data }) {
68
+ const addr = jidToSignalProtocolAddress(jid)
69
+ const cipher = new libsignal.SessionCipher(storage, addr)
70
+ const { type: sigType, body } = await cipher.encrypt(data)
71
+ const type = sigType === 3 ? 'pkmsg' : 'msg'
72
+ return { type, ciphertext: Buffer.from(body, 'binary') }
73
+ },
74
+ async encryptGroupMessage({ group, meId, data }) {
75
+ const senderName = jidToSignalSenderKeyName(group, meId)
76
+ const builder = new WASignalGroup_1.GroupSessionBuilder(storage)
77
+ const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName])
78
+ if (!senderKey) {
79
+ await storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord())
80
+ }
81
+ const senderKeyDistributionMessage = await builder.create(senderName)
82
+ const session = new WASignalGroup_1.GroupCipher(storage, senderName)
83
+ const ciphertext = await session.encrypt(data)
84
+ return {
85
+ ciphertext,
86
+ senderKeyDistributionMessage: senderKeyDistributionMessage.serialize(),
87
+ }
88
+ },
89
+ async injectE2ESession({ jid, session }) {
90
+ const cipher = new libsignal.SessionBuilder(storage, jidToSignalProtocolAddress(jid))
91
+ await cipher.initOutgoing(session)
92
+ },
93
+ jidToSignalProtocolAddress(jid) {
94
+ return jidToSignalProtocolAddress(jid).toString()
95
+ },
96
+ }
97
+ }
98
+
99
+ const jidToSignalProtocolAddress = (jid) => {
100
+ const { user, device } = WABinary_1.jidDecode(jid)
101
+ return new libsignal.ProtocolAddress(user, device || 0)
102
+ }
103
+
104
+ const jidToSignalSenderKeyName = (group, user) => {
105
+ return new WASignalGroup_1.SenderKeyName(group, jidToSignalProtocolAddress(user)).toString()
106
+ }
107
+
108
+ function signalStorage({ creds, keys }) {
109
+ return {
110
+ loadSession: async (id) => {
111
+ const { [id]: sess } = await keys.get('session', [id])
112
+ if (sess) {
113
+ return libsignal.SessionRecord.deserialize(sess)
114
+ }
115
+ },
116
+ storeSession: async (id, session) => {
117
+ await keys.set({ 'session': { [id]: session.serialize() } })
118
+ },
119
+ isTrustedIdentity: () => {
120
+ return true
121
+ },
122
+ loadPreKey: async (id) => {
123
+ const keyId = id.toString()
124
+ const { [keyId]: key } = await keys.get('pre-key', [keyId])
125
+ if (key) {
126
+ return {
127
+ privKey: Buffer.from(key.private),
128
+ pubKey: Buffer.from(key.public)
129
+ }
130
+ }
131
+ },
132
+ removePreKey: (id) => keys.set({ 'pre-key': { [id]: null } }),
133
+ loadSignedPreKey: () => {
134
+ const key = creds.signedPreKey
135
+ return {
136
+ privKey: Buffer.from(key.keyPair.private),
137
+ pubKey: Buffer.from(key.keyPair.public)
138
+ }
139
+ },
140
+ loadSenderKey: async (keyId) => {
141
+ const { [keyId]: key } = await keys.get('sender-key', [keyId])
142
+ if (key) {
143
+ return new WASignalGroup_1.SenderKeyRecord(key)
144
+ }
145
+ },
146
+ storeSenderKey: async (keyId, key) => {
147
+ await keys.set({ 'sender-key': { [keyId]: key.serialize() } })
148
+ },
149
+ getOurRegistrationId: () => (creds.registrationId),
150
+ getOurIdentity: () => {
151
+ const { signedIdentityKey } = creds
152
+ return {
153
+ privKey: Buffer.from(signedIdentityKey.private),
154
+ pubKey: Utils_1.generateSignalPubKey(signedIdentityKey.public),
155
+ }
156
+ }
157
+ }
158
+ }
159
+
160
+ module.exports = {
161
+ makeLibSignalRepository
162
+ }
@@ -0,0 +1,15 @@
1
+ import { EventEmitter } from 'events';
2
+ import { URL } from 'url';
3
+ import { SocketConfig } from '../../Types';
4
+ export declare abstract class AbstractSocketClient extends EventEmitter {
5
+ url: URL;
6
+ config: SocketConfig;
7
+ abstract get isOpen(): boolean;
8
+ abstract get isClosed(): boolean;
9
+ abstract get isClosing(): boolean;
10
+ abstract get isConnecting(): boolean;
11
+ constructor(url: URL, config: SocketConfig);
12
+ abstract connect(): Promise<void>;
13
+ abstract close(): Promise<void>;
14
+ abstract send(str: Uint8Array | string, cb?: (err?: Error) => void): boolean;
15
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AbstractSocketClient = void 0;
4
+ const events_1 = require("events");
5
+ class AbstractSocketClient extends events_1.EventEmitter {
6
+ constructor(url, config) {
7
+ super();
8
+ this.url = url;
9
+ this.config = config;
10
+ this.setMaxListeners(0);
11
+ }
12
+ }
13
+ exports.AbstractSocketClient = AbstractSocketClient;
@@ -0,0 +1,2 @@
1
+ export * from './types'
2
+ export * from './websocket'
@@ -0,0 +1,22 @@
1
+ "use strict"
2
+
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k
5
+ var desc = Object.getOwnPropertyDescriptor(m, k)
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k] } }
8
+ }
9
+ Object.defineProperty(o, k2, desc)
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k
12
+ o[k2] = m[k]
13
+ }))
14
+
15
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p)
17
+ }
18
+
19
+ Object.defineProperty(exports, "__esModule", { value: true })
20
+
21
+ __exportStar(require("./types"), exports)
22
+ __exportStar(require("./websocket"), exports)
@@ -0,0 +1,12 @@
1
+ import { Socket } from 'net';
2
+ import { AbstractSocketClient } from './abstract-socket-client';
3
+ export declare class MobileSocketClient extends AbstractSocketClient {
4
+ protected socket: Socket | null;
5
+ get isOpen(): boolean;
6
+ get isClosed(): boolean;
7
+ get isClosing(): boolean;
8
+ get isConnecting(): boolean;
9
+ connect(): Promise<void>;
10
+ close(): Promise<void>;
11
+ send(str: string | Uint8Array, cb?: (err?: Error) => void): boolean;
12
+ }
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MobileSocketClient = void 0;
4
+ const net_1 = require("net");
5
+ const abstract_socket_client_1 = require("./abstract-socket-client");
6
+ class MobileSocketClient extends abstract_socket_client_1.AbstractSocketClient {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.socket = null;
10
+ }
11
+ get isOpen() {
12
+ var _a;
13
+ return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'open';
14
+ }
15
+ get isClosed() {
16
+ var _a;
17
+ return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'closed';
18
+ }
19
+ get isClosing() {
20
+ var _a;
21
+ return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'closed';
22
+ }
23
+ get isConnecting() {
24
+ var _a;
25
+ return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === 'opening';
26
+ }
27
+ async connect() {
28
+ var _a;
29
+ if (this.socket) {
30
+ return;
31
+ }
32
+ if (this.config.agent) {
33
+ throw new Error('There are not support for proxy agent for mobile connection');
34
+ }
35
+ else {
36
+ this.socket = (0, net_1.connect)({
37
+ host: this.url.hostname,
38
+ port: Number(this.url.port) || 443
39
+ });
40
+ }
41
+ this.socket.setMaxListeners(0);
42
+ const events = ['close', 'connect', 'data', 'drain', 'end', 'error', 'lookup', 'ready', 'timeout'];
43
+ for (const event of events) {
44
+ (_a = this.socket) === null || _a === void 0 ? void 0 : _a.on(event, (...args) => this.emit(event, ...args));
45
+ }
46
+ this.socket.on('data', (...args) => this.emit('message', ...args));
47
+ this.socket.on('ready', (...args) => this.emit('open', ...args));
48
+ }
49
+ async close() {
50
+ if (!this.socket) {
51
+ return;
52
+ }
53
+ return new Promise(resolve => {
54
+ this.socket.end(resolve);
55
+ this.socket = null;
56
+ });
57
+ }
58
+ send(str, cb) {
59
+ if (this.socket === null) {
60
+ return false;
61
+ }
62
+ return this.socket.write(str, undefined, cb);
63
+ }
64
+ }
65
+ exports.MobileSocketClient = MobileSocketClient;
@@ -0,0 +1,16 @@
1
+ import { EventEmitter } from 'events'
2
+ import { URL } from 'url'
3
+ import { SocketConfig } from '../../Types'
4
+
5
+ export declare abstract class AbstractSocketClient extends EventEmitter {
6
+ url: URL
7
+ config: SocketConfig
8
+ abstract get isOpen(): boolean
9
+ abstract get isClosed(): boolean
10
+ abstract get isClosing(): boolean
11
+ abstract get isConnecting(): boolean
12
+ constructor(url: URL, config: SocketConfig)
13
+ abstract connect(): Promise<void>
14
+ abstract close(): Promise<void>
15
+ abstract send(str: Uint8Array | string, cb?: (err?: Error) => void): boolean
16
+ }
@@ -0,0 +1,18 @@
1
+ "use strict"
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true })
4
+
5
+ const events_1 = require("events")
6
+
7
+ class AbstractSocketClient extends events_1.EventEmitter {
8
+ constructor(url, config) {
9
+ super()
10
+ this.url = url
11
+ this.config = config
12
+ this.setMaxListeners(0)
13
+ }
14
+ }
15
+
16
+ module.exports = {
17
+ AbstractSocketClient
18
+ }
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.WebSocketClient = void 0;
7
+ const ws_1 = __importDefault(require("ws"));
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 {
11
+ constructor() {
12
+ super(...arguments);
13
+ this.socket = null;
14
+ }
15
+ get isOpen() {
16
+ var _a;
17
+ return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.OPEN;
18
+ }
19
+ get isClosed() {
20
+ var _a;
21
+ return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CLOSED;
22
+ }
23
+ get isClosing() {
24
+ var _a;
25
+ return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CLOSING;
26
+ }
27
+ get isConnecting() {
28
+ var _a;
29
+ return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CONNECTING;
30
+ }
31
+ async connect() {
32
+ var _a, _b;
33
+ if (this.socket) {
34
+ return;
35
+ }
36
+ this.socket = new ws_1.default(this.url, {
37
+ origin: Defaults_1.DEFAULT_ORIGIN,
38
+ headers: (_a = this.config.options) === null || _a === void 0 ? void 0 : _a.headers,
39
+ handshakeTimeout: this.config.connectTimeoutMs,
40
+ timeout: this.config.connectTimeoutMs,
41
+ agent: this.config.agent,
42
+ });
43
+ this.socket.setMaxListeners(0);
44
+ const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response'];
45
+ for (const event of events) {
46
+ (_b = this.socket) === null || _b === void 0 ? void 0 : _b.on(event, (...args) => this.emit(event, ...args));
47
+ }
48
+ }
49
+ async close() {
50
+ if (!this.socket) {
51
+ return;
52
+ }
53
+ this.socket.close();
54
+ this.socket = null;
55
+ }
56
+ send(str, cb) {
57
+ var _a;
58
+ (_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(str, cb);
59
+ return Boolean(this.socket);
60
+ }
61
+ }
62
+ exports.WebSocketClient = WebSocketClient;
@@ -0,0 +1,13 @@
1
+ import WebSocket from 'ws'
2
+ import { AbstractSocketClient } from './types'
3
+
4
+ export declare class WebSocketClient extends AbstractSocketClient {
5
+ protected socket: WebSocket | null
6
+ get isOpen(): boolean
7
+ get isClosed(): boolean
8
+ get isClosing(): boolean
9
+ get isConnecting(): boolean
10
+ connect(): Promise<void>
11
+ close(): Promise<void>
12
+ send(str: string | Uint8Array, cb?: (err?: Error) => void): boolean
13
+ }
@@ -0,0 +1,62 @@
1
+ "use strict"
2
+
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod }
5
+ }
6
+
7
+ Object.defineProperty(exports, "__esModule", { value: true })
8
+
9
+ const ws_1 = __importDefault(require("ws"))
10
+ const Defaults_1 = require("../../Defaults")
11
+ const types_1 = require("./types")
12
+
13
+ class WebSocketClient extends types_1.AbstractSocketClient {
14
+ constructor() {
15
+ super(...arguments)
16
+ this.socket = null
17
+ }
18
+ get isOpen() {
19
+ return this.socket?.readyState === ws_1.default.OPEN
20
+ }
21
+ get isClosed() {
22
+ return this.socket?.readyState === ws_1.default.CLOSED
23
+ }
24
+ get isClosing() {
25
+ this.socket?.readyState === ws_1.default.CLOSING
26
+ }
27
+ get isConnecting() {
28
+ this.socket?.readyState === ws_1.default.CONNECTING
29
+ }
30
+ async connect() {
31
+ if (this.socket) {
32
+ return
33
+ }
34
+ this.socket = new ws_1.default(this.url, {
35
+ origin: Defaults_1.DEFAULT_ORIGIN,
36
+ headers: this.config.options?.headers,
37
+ handshakeTimeout: this.config.connectTimeoutMs,
38
+ timeout: this.config.connectTimeoutMs,
39
+ agent: this.config.agent,
40
+ })
41
+ this.socket.setMaxListeners(0)
42
+ const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response']
43
+ for (const event of events) {
44
+ this.socket?.on(event, (...args) => this.emit(event, ...args))
45
+ }
46
+ }
47
+ async close() {
48
+ if (!this.socket) {
49
+ return
50
+ }
51
+ this.socket.close()
52
+ this.socket = null
53
+ }
54
+ send(str, cb) {
55
+ this.socket?.send(str, cb)
56
+ return Boolean(this.socket)
57
+ }
58
+ }
59
+
60
+ module.exports = {
61
+ WebSocketClient
62
+ }
@@ -0,0 +1,182 @@
1
+ import { GetCatalogOptions, ProductCreate, ProductUpdate, SocketConfig } from '../Types'
2
+ import { BinaryNode } from '../WABinary'
3
+
4
+ export declare const makeBusinessSocket: (config: SocketConfig) => {
5
+ logger: import("../Utils/logger").ILogger
6
+ getOrderDetails: (orderId: string, tokenBase64: string) => Promise<import("../Types").OrderDetails>
7
+ getCatalog: ({ jid, limit, cursor }: GetCatalogOptions) => Promise<{
8
+ products: import("../Types").Product[]
9
+ nextPageCursor: string | undefined
10
+ }>
11
+ getCollections: (jid?: string, limit?: number) => Promise<{
12
+ collections: import("../Types").CatalogCollection[]
13
+ }>
14
+ productCreate: (create: ProductCreate) => Promise<import("../Types").Product>
15
+ productDelete: (productIds: string[]) => Promise<{
16
+ deleted: number
17
+ }>
18
+ productUpdate: (productId: string, update: ProductUpdate) => Promise<import("../Types").Product>
19
+ sendMessageAck: ({ tag, attrs, content }: BinaryNode, errorCode?: number | undefined) => Promise<void>
20
+ sendRetryRequest: (node: BinaryNode, forceIncludeKeys?: boolean) => Promise<void>
21
+ offerCall: (toJid: string, isVideo?: boolean) => Promise<{
22
+ id: any
23
+ to: string
24
+ }>
25
+ rejectCall: (callId: string, callFrom: string) => Promise<void>
26
+ fetchMessageHistory: (count: number, oldestMsgKey: import("../Types").WAProto.IMessageKey, oldestMsgTimestamp: number | import("long").Long) => Promise<string>
27
+ requestPlaceholderResend: (messageKey: import("../Types").WAProto.IMessageKey) => Promise<string | undefined>
28
+ getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>
29
+ assertSessions: (jids: string[], force: boolean) => Promise<boolean>
30
+ relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>
31
+ sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>
32
+ sendReceipts: (keys: import("../Types").WAProto.IMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>
33
+ readMessages: (keys: import("../Types").WAProto.IMessageKey[]) => Promise<void>
34
+ refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>
35
+ waUploadToServer: import("../Types").WAMediaUploadFunction
36
+ fetchPrivacySettings: (force?: boolean) => Promise<{
37
+ [_: string]: string
38
+ }>
39
+ sendPeerDataOperationMessage: (pdoMessage: import("../Types").WAProto.Message.IPeerDataOperationRequestMessage) => Promise<string>
40
+ createParticipantNodes: (jids: string[], message: import("../Types").WAProto.IMessage, extraAttrs?: {
41
+ [key: string]: string
42
+ } | undefined) => Promise<{
43
+ nodes: BinaryNode[]
44
+ shouldIncludeDeviceIdentity: boolean
45
+ }>
46
+ profilePictureUrl: (jid: string) => Promise<string>
47
+ getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("../WABinary").JidWithDevice[]>
48
+ updateMediaMessage: (message: import("../Types").WAProto.IWebMessageInfo) => Promise<import("../Types").WAProto.IWebMessageInfo>
49
+ sendStatusMentions: (content: import("../Types").WAProto.IMessage, jid: string, Private?: boolean) => Promise<string>
50
+ sendAlbumMessage: (jid: string, medias: import("../Types").WAProto.IMessage, options?: import("../Types").MiscMessageGenerationOptions) => Promise<string>
51
+ sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo | undefined>
52
+ groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>
53
+ groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>
54
+ groupLeave: (id: string) => Promise<void>
55
+ groupUpdateSubject: (jid: string, subject: string) => Promise<void>
56
+ groupRequestParticipantsList: (jid: string) => Promise<{
57
+ [key: string]: string
58
+ }[]>
59
+ groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "reject" | "approve") => Promise<{
60
+ status: string
61
+ jid: string
62
+ }[]>
63
+ groupParticipantsUpdate: (jid: string, participants: string[], action: import("../Types").ParticipantAction) => Promise<{
64
+ status: string
65
+ jid: string
66
+ content: BinaryNode
67
+ }[]>
68
+ subscribeNewsletterUpdates: (jid: string) => Promise<{
69
+ duration: string
70
+ }>
71
+ newsletterReactionMode: (jid: string, mode: import("../Types").NewsletterReactionMode) => Promise<void>
72
+ newsletterUpdateDescription: (jid: string, description?: string | undefined) => Promise<void>
73
+ newsletterUpdateName: (jid: string, name: string) => Promise<void>
74
+ newsletterUpdatePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>
75
+ newsletterRemovePicture: (jid: string) => Promise<void>
76
+ newsletterUnfollow: (jid: string) => Promise<void>
77
+ newsletterFollow: (jid: string) => Promise<void>
78
+ newsletterUnmute: (jid: string) => Promise<void>
79
+ newsletterMute: (jid: string) => Promise<void>
80
+ newsletterCreate: (name: string, description: string) => Promise<import("../Types").NewsletterMetadata>
81
+ newsletterQuery: (jid: string, type: string, content: BinaryNode) => Promise<BinaryNode>
82
+ newsletterWMexQuery: (jid?: string | undefined, query_id: number, content: BinaryNode) => Promise<BinaryNode>
83
+ newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole | undefined) => Promise<import("../Types").NewsletterMetadata>
84
+ newsletterAdminCount: (jid: string) => Promise<number>
85
+ newsletterChangeOwner: (jid: string, userLid: string) => Promise<void>
86
+ newsletterDemote: (jid: string, userLid: string) => Promise<void>
87
+ newsletterDelete: (jid: string) => Promise<void>
88
+ newsletterReactMessage: (jid: string, server_id: string, code?: string | undefined) => Promise<void>
89
+ newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>
90
+ newsletterFetchUpdates: (jid: string, count: number, after?: number | undefined, since?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>
91
+ groupQuery: (jid: string, type: string, content: BinaryNode) => Promise<BinaryNode>
92
+ groupUpdateDescription: (jid: string, description?: string | undefined) => Promise<void>
93
+ groupInviteCode: (jid: string) => Promise<string | undefined>
94
+ groupRevokeInvite: (jid: string) => Promise<string | undefined>
95
+ groupAcceptInvite: (code: string) => Promise<string | undefined>
96
+ groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>
97
+ groupAcceptInviteV4: (key: string | import("../Types").WAProto.IMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>
98
+ groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>
99
+ groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>
100
+ groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>
101
+ groupMemberAddMode: (jid: string, mode: "all_member_add" | "admin_add") => Promise<void>
102
+ groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>
103
+ groupFetchAllParticipating: () => Promise<{
104
+ [_: string]: import("../Types").GroupMetadata
105
+ }>
106
+ processingMutex: {
107
+ mutex<T>(code: () => T | Promise<T>): Promise<T>
108
+ }
109
+ upsertMessage: (msg: import("../Types").WAProto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>
110
+ appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>
111
+ sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string | undefined) => Promise<void>
112
+ presenceSubscribe: (toJid: string, tcToken?: Buffer | undefined) => Promise<void>
113
+ getBotListV2: () => Promise<BotListInfo[]>
114
+ getLidUser: (jid: string) => Promise<{
115
+ lid: string
116
+ id: string
117
+ }[] | undefined>
118
+ onWhatsApp: (...jids: string[]) => Promise<{
119
+ jid: string
120
+ exists: unknown
121
+ }[] | undefined>
122
+ fetchBlocklist: () => Promise<string[]>
123
+ fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>
124
+ fetchDisappearingDuration: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>
125
+ updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>
126
+ removeProfilePicture: (jid: string) => Promise<void>
127
+ updateProfileStatus: (status: string) => Promise<void>
128
+ updateProfileName: (name: string) => Promise<void>
129
+ updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>
130
+ updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>
131
+ updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>
132
+ updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>
133
+ updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>
134
+ updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>
135
+ updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>
136
+ updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>
137
+ updateDefaultDisappearingMode: (duration: number) => Promise<void>
138
+ getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>
139
+ resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>
140
+ chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>
141
+ cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>
142
+ addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>
143
+ addChatLabel: (jid: string, labelId: string) => Promise<void>
144
+ removeChatLabel: (jid: string, labelId: string) => Promise<void>
145
+ addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>
146
+ removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>
147
+ clearMessage: (jid: string, key: import("../Types").WAProto.IMessageKey, timeStamp: number | import("long").Long) => Promise<void>
148
+ star: (jid: string, messages: {
149
+ id: string
150
+ fromMe?: boolean | undefined
151
+ }[], star: boolean) => Promise<void>
152
+ executeUSyncQuery: (usyncQuery: import("..").USyncQuery) => Promise<import("..").USyncQueryResult | undefined>
153
+ type: "md"
154
+ ws: import("./Client").WebSocketClient
155
+ ev: import("../Types").BaileysEventEmitter & {
156
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void
157
+ buffer(): void
158
+ createBufferedFunction<A extends any[], T_1>(work: (...args: A) => Promise<T_1>): (...args: A) => Promise<T_1>
159
+ flush(force?: boolean | undefined): boolean
160
+ isBuffering(): boolean
161
+ }
162
+ authState: {
163
+ creds: import("../Types").AuthenticationCreds
164
+ keys: import("../Types").SignalKeyStoreWithTransaction
165
+ }
166
+ signalRepository: import("../Types").SignalRepository
167
+ user: import("../Types").Contact | undefined
168
+ generateMessageTag: () => string
169
+ query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>
170
+ waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>
171
+ waitForSocketOpen: () => Promise<void>
172
+ sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>
173
+ sendNode: (frame: BinaryNode) => Promise<void>
174
+ logout: (msg?: string | undefined) => Promise<void>
175
+ end: (error: Error | undefined) => void
176
+ onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void
177
+ uploadPreKeys: (count?: number) => Promise<void>
178
+ uploadPreKeysToServerIfRequired: () => Promise<void>
179
+ requestPairingCode: (phoneNumber: string, code?: string) => Promise<string>
180
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>
181
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>
182
+ }