gifted-baileys 1.5.5 → 1.5.7

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 (251) hide show
  1. package/README.md +6 -1642
  2. package/WAProto/WAProto.proto +969 -88
  3. package/WAProto/index.d.ts +13199 -1260
  4. package/WAProto/index.js +124901 -74525
  5. package/lib/Defaults/baileys-version.json +3 -0
  6. package/lib/Defaults/index.d.ts +284 -0
  7. package/{src → lib}/Defaults/index.js +7 -14
  8. package/lib/Signal/libsignal.d.ts +3 -0
  9. package/lib/Signal/libsignal.js +161 -0
  10. package/lib/Socket/Client/abstract-socket-client.d.ts +15 -0
  11. package/lib/Socket/Client/index.d.ts +2 -0
  12. package/{src → lib}/Socket/Client/index.js +2 -3
  13. package/lib/Socket/Client/mobile-socket-client.d.ts +12 -0
  14. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  15. package/lib/Socket/Client/types.d.ts +17 -0
  16. package/lib/Socket/Client/types.js +13 -0
  17. package/lib/Socket/Client/websocket.d.ts +12 -0
  18. package/lib/Socket/Client/websocket.js +62 -0
  19. package/lib/Socket/business.d.ts +170 -0
  20. package/{src → lib}/Socket/business.js +28 -33
  21. package/lib/Socket/chats.d.ts +81 -0
  22. package/{src → lib}/Socket/chats.js +174 -176
  23. package/lib/Socket/groups.d.ts +115 -0
  24. package/{src → lib}/Socket/groups.js +80 -68
  25. package/lib/Socket/index.d.ts +172 -0
  26. package/{src → lib}/Socket/index.js +4 -1
  27. package/lib/Socket/messages-recv.d.ts +158 -0
  28. package/{src → lib}/Socket/messages-recv.js +378 -211
  29. package/lib/Socket/messages-send.d.ts +155 -0
  30. package/{src → lib}/Socket/messages-send.js +452 -177
  31. package/lib/Socket/newsletter.d.ts +132 -0
  32. package/{src → lib}/Socket/newsletter.js +107 -98
  33. package/lib/Socket/registration.d.ts +264 -0
  34. package/{src → lib}/Socket/registration.js +56 -48
  35. package/lib/Socket/socket.d.ts +44 -0
  36. package/{src → lib}/Socket/socket.js +77 -77
  37. package/lib/Socket/usync.d.ts +37 -0
  38. package/lib/Socket/usync.js +70 -0
  39. package/lib/Store/index.d.ts +3 -0
  40. package/lib/Store/make-cache-manager-store.d.ts +14 -0
  41. package/{src → lib}/Store/make-cache-manager-store.js +25 -34
  42. package/lib/Store/make-in-memory-store.d.ts +118 -0
  43. package/{src → lib}/Store/make-in-memory-store.js +36 -32
  44. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  45. package/lib/Store/object-repository.d.ts +10 -0
  46. package/{src → lib}/Store/object-repository.js +1 -1
  47. package/lib/Types/Auth.d.ts +109 -0
  48. package/lib/Types/Call.d.ts +13 -0
  49. package/lib/Types/Chat.d.ts +107 -0
  50. package/{src/Types/Contact.ts → lib/Types/Contact.d.ts} +8 -9
  51. package/lib/Types/Events.d.ts +172 -0
  52. package/lib/Types/GroupMetadata.d.ts +56 -0
  53. package/lib/Types/Label.d.ts +46 -0
  54. package/{src/Types/LabelAssociation.ts → lib/Types/LabelAssociation.d.ts} +16 -22
  55. package/lib/Types/Message.d.ts +433 -0
  56. package/lib/Types/Newsletter.d.ts +92 -0
  57. package/lib/Types/Product.d.ts +78 -0
  58. package/lib/Types/Signal.d.ts +57 -0
  59. package/{src/Types/Socket.ts → lib/Types/Socket.d.ts} +61 -68
  60. package/lib/Types/State.d.ts +27 -0
  61. package/lib/Types/USync.d.ts +25 -0
  62. package/lib/Types/index.d.ts +66 -0
  63. package/lib/Utils/auth-utils.d.ts +18 -0
  64. package/{src → lib}/Utils/auth-utils.js +73 -90
  65. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  66. package/lib/Utils/baileys-event-stream.js +63 -0
  67. package/lib/Utils/business.d.ts +22 -0
  68. package/{src → lib}/Utils/business.js +15 -43
  69. package/lib/Utils/chat-utils.d.ts +70 -0
  70. package/{src → lib}/Utils/chat-utils.js +87 -94
  71. package/lib/Utils/crypto.d.ts +40 -0
  72. package/{src → lib}/Utils/crypto.js +4 -2
  73. package/lib/Utils/decode-wa-message.d.ts +36 -0
  74. package/lib/Utils/decode-wa-message.js +226 -0
  75. package/lib/Utils/event-buffer.d.ts +35 -0
  76. package/{src → lib}/Utils/event-buffer.js +4 -13
  77. package/lib/Utils/generics.d.ts +88 -0
  78. package/{src → lib}/Utils/generics.js +67 -86
  79. package/lib/Utils/history.d.ts +19 -0
  80. package/{src → lib}/Utils/history.js +13 -39
  81. package/lib/Utils/index.d.ts +17 -0
  82. package/lib/Utils/link-preview.d.ts +21 -0
  83. package/{src → lib}/Utils/link-preview.js +17 -54
  84. package/lib/Utils/logger.d.ts +2 -0
  85. package/lib/Utils/lt-hash.d.ts +12 -0
  86. package/lib/Utils/make-mutex.d.ts +7 -0
  87. package/{src → lib}/Utils/make-mutex.js +4 -13
  88. package/lib/Utils/messages-media.d.ts +113 -0
  89. package/{src → lib}/Utils/messages-media.js +193 -255
  90. package/lib/Utils/messages.d.ts +77 -0
  91. package/{src → lib}/Utils/messages.js +588 -118
  92. package/lib/Utils/noise-handler.d.ts +20 -0
  93. package/lib/Utils/process-message.d.ts +41 -0
  94. package/{src → lib}/Utils/process-message.js +27 -30
  95. package/lib/Utils/signal.d.ts +33 -0
  96. package/{src → lib}/Utils/signal.js +25 -42
  97. package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
  98. package/{src → lib}/Utils/use-multi-file-auth-state.js +27 -28
  99. package/lib/Utils/validate-connection.d.ts +11 -0
  100. package/{src → lib}/Utils/validate-connection.js +40 -9
  101. package/lib/WABinary/constants.d.ts +27 -0
  102. package/lib/WABinary/decode.d.ts +6 -0
  103. package/lib/WABinary/encode.d.ts +2 -0
  104. package/{src → lib}/WABinary/encode.js +16 -10
  105. package/lib/WABinary/generic-utils.d.ts +14 -0
  106. package/lib/WABinary/index.d.ts +5 -0
  107. package/lib/WABinary/jid-utils.d.ts +31 -0
  108. package/lib/WABinary/types.d.ts +18 -0
  109. package/lib/WABinary/types.js +2 -0
  110. package/lib/WAM/BinaryInfo.d.ts +8 -0
  111. package/lib/WAM/constants.d.ts +38 -0
  112. package/lib/WAM/encode.d.ts +2 -0
  113. package/lib/WAM/index.d.ts +3 -0
  114. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  115. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  116. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  117. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  118. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  119. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  120. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  121. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  122. package/lib/WAUSync/Protocols/index.d.ts +4 -0
  123. package/lib/WAUSync/Protocols/index.js +20 -0
  124. package/lib/WAUSync/USyncQuery.d.ts +26 -0
  125. package/lib/WAUSync/USyncQuery.js +79 -0
  126. package/lib/WAUSync/USyncUser.d.ts +10 -0
  127. package/lib/WAUSync/USyncUser.js +22 -0
  128. package/lib/WAUSync/index.d.ts +3 -0
  129. package/lib/WAUSync/index.js +19 -0
  130. package/{src → lib}/index.js +1 -0
  131. package/package.json +26 -8
  132. package/LICENSE +0 -21
  133. package/src/Defaults/baileys-version.json +0 -3
  134. package/src/Defaults/index.ts +0 -131
  135. package/src/Signal/libsignal.js +0 -180
  136. package/src/Signal/libsignal.ts +0 -141
  137. package/src/Socket/Client/abstract-socket-client.ts +0 -19
  138. package/src/Socket/Client/index.ts +0 -3
  139. package/src/Socket/Client/mobile-socket-client.js +0 -78
  140. package/src/Socket/Client/mobile-socket-client.ts +0 -66
  141. package/src/Socket/Client/web-socket-client.js +0 -75
  142. package/src/Socket/Client/web-socket-client.ts +0 -57
  143. package/src/Socket/business.ts +0 -281
  144. package/src/Socket/chats.ts +0 -1030
  145. package/src/Socket/groups.ts +0 -356
  146. package/src/Socket/index.ts +0 -13
  147. package/src/Socket/messages-recv.ts +0 -985
  148. package/src/Socket/messages-send.ts +0 -871
  149. package/src/Socket/newsletter.ts +0 -282
  150. package/src/Socket/registration.ts +0 -250
  151. package/src/Socket/socket.ts +0 -777
  152. package/src/Store/index.ts +0 -3
  153. package/src/Store/make-cache-manager-store.ts +0 -100
  154. package/src/Store/make-in-memory-store.ts +0 -475
  155. package/src/Store/make-ordered-dictionary.ts +0 -86
  156. package/src/Store/object-repository.ts +0 -32
  157. package/src/Tests/test.app-state-sync.js +0 -204
  158. package/src/Tests/test.app-state-sync.ts +0 -207
  159. package/src/Tests/test.event-buffer.js +0 -270
  160. package/src/Tests/test.event-buffer.ts +0 -319
  161. package/src/Tests/test.key-store.js +0 -76
  162. package/src/Tests/test.key-store.ts +0 -92
  163. package/src/Tests/test.libsignal.js +0 -141
  164. package/src/Tests/test.libsignal.ts +0 -186
  165. package/src/Tests/test.media-download.js +0 -93
  166. package/src/Tests/test.media-download.ts +0 -76
  167. package/src/Tests/test.messages.js +0 -33
  168. package/src/Tests/test.messages.ts +0 -37
  169. package/src/Tests/utils.js +0 -34
  170. package/src/Tests/utils.ts +0 -36
  171. package/src/Types/Auth.ts +0 -113
  172. package/src/Types/Call.ts +0 -15
  173. package/src/Types/Chat.ts +0 -106
  174. package/src/Types/Events.ts +0 -93
  175. package/src/Types/GroupMetadata.ts +0 -53
  176. package/src/Types/Label.ts +0 -36
  177. package/src/Types/Message.ts +0 -288
  178. package/src/Types/Newsletter.ts +0 -98
  179. package/src/Types/Product.ts +0 -85
  180. package/src/Types/Signal.ts +0 -68
  181. package/src/Types/State.ts +0 -29
  182. package/src/Types/index.ts +0 -59
  183. package/src/Utils/auth-utils.ts +0 -222
  184. package/src/Utils/baileys-event-stream.js +0 -92
  185. package/src/Utils/baileys-event-stream.ts +0 -66
  186. package/src/Utils/business.ts +0 -275
  187. package/src/Utils/chat-utils.ts +0 -860
  188. package/src/Utils/crypto.ts +0 -131
  189. package/src/Utils/decode-wa-message.js +0 -211
  190. package/src/Utils/decode-wa-message.ts +0 -228
  191. package/src/Utils/event-buffer.ts +0 -613
  192. package/src/Utils/generics.ts +0 -434
  193. package/src/Utils/history.ts +0 -112
  194. package/src/Utils/index.ts +0 -17
  195. package/src/Utils/link-preview.ts +0 -122
  196. package/src/Utils/logger.ts +0 -3
  197. package/src/Utils/lt-hash.ts +0 -61
  198. package/src/Utils/make-mutex.ts +0 -44
  199. package/src/Utils/messages-media.ts +0 -847
  200. package/src/Utils/messages.ts +0 -956
  201. package/src/Utils/noise-handler.ts +0 -197
  202. package/src/Utils/process-message.ts +0 -414
  203. package/src/Utils/signal.ts +0 -177
  204. package/src/Utils/use-multi-file-auth-state.ts +0 -90
  205. package/src/Utils/validate-connection.ts +0 -238
  206. package/src/WABinary/constants.ts +0 -42
  207. package/src/WABinary/decode.ts +0 -265
  208. package/src/WABinary/encode.ts +0 -236
  209. package/src/WABinary/generic-utils.ts +0 -121
  210. package/src/WABinary/index.ts +0 -5
  211. package/src/WABinary/jid-utils.ts +0 -68
  212. package/src/WABinary/types.ts +0 -17
  213. package/src/WAM/BinaryInfo.ts +0 -12
  214. package/src/WAM/constants.ts +0 -15382
  215. package/src/WAM/encode.ts +0 -174
  216. package/src/WAM/index.ts +0 -3
  217. package/src/gifted +0 -1
  218. package/src/index.ts +0 -13
  219. /package/{src → lib}/Defaults/phonenumber-mcc.json +0 -0
  220. /package/{src → lib}/Socket/Client/abstract-socket-client.js +0 -0
  221. /package/{src → lib}/Store/index.js +0 -0
  222. /package/{src → lib}/Store/make-ordered-dictionary.js +0 -0
  223. /package/{src → lib}/Types/Auth.js +0 -0
  224. /package/{src → lib}/Types/Call.js +0 -0
  225. /package/{src → lib}/Types/Chat.js +0 -0
  226. /package/{src → lib}/Types/Contact.js +0 -0
  227. /package/{src → lib}/Types/Events.js +0 -0
  228. /package/{src → lib}/Types/GroupMetadata.js +0 -0
  229. /package/{src → lib}/Types/Label.js +0 -0
  230. /package/{src → lib}/Types/LabelAssociation.js +0 -0
  231. /package/{src → lib}/Types/Message.js +0 -0
  232. /package/{src → lib}/Types/Newsletter.js +0 -0
  233. /package/{src → lib}/Types/Product.js +0 -0
  234. /package/{src → lib}/Types/Signal.js +0 -0
  235. /package/{src → lib}/Types/Socket.js +0 -0
  236. /package/{src → lib}/Types/State.js +0 -0
  237. /package/{src/WABinary/types.js → lib/Types/USync.js} +0 -0
  238. /package/{src → lib}/Types/index.js +0 -0
  239. /package/{src → lib}/Utils/index.js +0 -0
  240. /package/{src → lib}/Utils/logger.js +0 -0
  241. /package/{src → lib}/Utils/lt-hash.js +0 -0
  242. /package/{src → lib}/Utils/noise-handler.js +0 -0
  243. /package/{src → lib}/WABinary/constants.js +0 -0
  244. /package/{src → lib}/WABinary/decode.js +0 -0
  245. /package/{src → lib}/WABinary/generic-utils.js +0 -0
  246. /package/{src → lib}/WABinary/index.js +0 -0
  247. /package/{src → lib}/WABinary/jid-utils.js +0 -0
  248. /package/{src → lib}/WAM/BinaryInfo.js +0 -0
  249. /package/{src → lib}/WAM/constants.js +0 -0
  250. /package/{src → lib}/WAM/encode.js +0 -0
  251. /package/{src → lib}/WAM/index.js +0 -0
@@ -0,0 +1,27 @@
1
+ export declare const TAGS: {
2
+ LIST_EMPTY: number;
3
+ DICTIONARY_0: number;
4
+ DICTIONARY_1: number;
5
+ DICTIONARY_2: number;
6
+ DICTIONARY_3: number;
7
+ AD_JID: number;
8
+ LIST_8: number;
9
+ LIST_16: number;
10
+ JID_PAIR: number;
11
+ HEX_8: number;
12
+ BINARY_8: number;
13
+ BINARY_20: number;
14
+ BINARY_32: number;
15
+ NIBBLE_8: number;
16
+ PACKED_MAX: number;
17
+ SINGLE_BYTE_MAX: number;
18
+ STREAM_END: number;
19
+ };
20
+ export declare const DOUBLE_BYTE_TOKENS: string[][];
21
+ export declare const SINGLE_BYTE_TOKENS: (string | null)[];
22
+ export declare const TOKEN_MAP: {
23
+ [token: string]: {
24
+ dict?: number;
25
+ index: number;
26
+ };
27
+ };
@@ -0,0 +1,6 @@
1
+ import type { BinaryNode, BinaryNodeCodingOptions } from './types';
2
+ export declare const decompressingIfRequired: (buffer: Buffer) => Buffer;
3
+ export declare const decodeDecompressedBinaryNode: (buffer: Buffer, opts: Pick<BinaryNodeCodingOptions, "DOUBLE_BYTE_TOKENS" | "SINGLE_BYTE_TOKENS" | "TAGS">, indexRef?: {
4
+ index: number;
5
+ }) => BinaryNode;
6
+ export declare const decodeBinaryNode: (buff: Buffer) => BinaryNode;
@@ -0,0 +1,2 @@
1
+ import type { BinaryNode, BinaryNodeCodingOptions } from './types';
2
+ export declare const encodeBinaryNode: (node: BinaryNode, opts?: Pick<BinaryNodeCodingOptions, "TAGS" | "TOKEN_MAP">, buffer?: number[]) => Buffer;
@@ -36,7 +36,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.encodeBinaryNode = void 0;
37
37
  const constants = __importStar(require("./constants"));
38
38
  const jid_utils_1 = require("./jid-utils");
39
- const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0]) => {
39
+ const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
40
+ const encoded = encodeBinaryNodeInner(node, opts, buffer);
41
+ return Buffer.from(encoded);
42
+ };
43
+ exports.encodeBinaryNode = encodeBinaryNode;
44
+ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
40
45
  const { TAGS, TOKEN_MAP } = opts;
41
46
  const pushByte = (value) => buffer.push(value & 0xff);
42
47
  const pushInt = (value, n, littleEndian = false) => {
@@ -45,7 +50,11 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
45
50
  buffer.push((value >> (curShift * 8)) & 0xff);
46
51
  }
47
52
  };
48
- const pushBytes = (bytes) => (bytes.forEach(b => buffer.push(b)));
53
+ const pushBytes = (bytes) => {
54
+ for (const b of bytes) {
55
+ buffer.push(b);
56
+ }
57
+ };
49
58
  const pushInt16 = (value) => {
50
59
  pushBytes([(value >> 8) & 0xff, value & 0xff]);
51
60
  };
@@ -147,8 +156,7 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
147
156
  if (str.length > TAGS.PACKED_MAX) {
148
157
  return false;
149
158
  }
150
- for (let i = 0; i < str.length; i++) {
151
- const char = str[i];
159
+ for (const char of str) {
152
160
  const isInNibbleRange = char >= '0' && char <= '9';
153
161
  if (!isInNibbleRange && char !== '-' && char !== '.') {
154
162
  return false;
@@ -160,10 +168,9 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
160
168
  if (str.length > TAGS.PACKED_MAX) {
161
169
  return false;
162
170
  }
163
- for (let i = 0; i < str.length; i++) {
164
- const char = str[i];
171
+ for (const char of str) {
165
172
  const isInNibbleRange = char >= '0' && char <= '9';
166
- if (!isInNibbleRange && !(char >= 'A' && char <= 'F') && !(char >= 'a' && char <= 'f')) {
173
+ if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
167
174
  return false;
168
175
  }
169
176
  }
@@ -224,7 +231,7 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
224
231
  else if (Array.isArray(content)) {
225
232
  writeListStart(content.length);
226
233
  for (const item of content) {
227
- (0, exports.encodeBinaryNode)(item, opts, buffer);
234
+ encodeBinaryNodeInner(item, opts, buffer);
228
235
  }
229
236
  }
230
237
  else if (typeof content === 'undefined') {
@@ -233,6 +240,5 @@ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0
233
240
  else {
234
241
  throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`);
235
242
  }
236
- return Buffer.from(buffer);
243
+ return buffer;
237
244
  };
238
- exports.encodeBinaryNode = encodeBinaryNode;
@@ -0,0 +1,14 @@
1
+ import { proto } from '../../WAProto';
2
+ import { BinaryNode } from './types';
3
+ export declare const getBinaryNodeChildren: (node: BinaryNode | undefined, childTag: string) => BinaryNode[];
4
+ export declare const getAllBinaryNodeChildren: ({ content }: BinaryNode) => BinaryNode[];
5
+ export declare const getBinaryNodeChild: (node: BinaryNode | undefined, childTag: string) => BinaryNode | undefined;
6
+ export declare const getBinaryNodeChildBuffer: (node: BinaryNode | undefined, childTag: string) => string | Uint8Array<ArrayBufferLike> | BinaryNode[] | undefined;
7
+ export declare const getBinaryNodeChildString: (node: BinaryNode | undefined, childTag: string) => any;
8
+ export declare const getBinaryNodeChildUInt: (node: BinaryNode, childTag: string, length: number) => number | undefined;
9
+ export declare const assertNodeErrorFree: (node: BinaryNode) => void;
10
+ export declare const reduceBinaryNodeToDictionary: (node: BinaryNode, tag: string) => {
11
+ [_: string]: string;
12
+ };
13
+ export declare const getBinaryNodeMessages: ({ content }: BinaryNode) => proto.WebMessageInfo[];
14
+ export declare function binaryNodeToString(node: BinaryNode | BinaryNode['content'], i?: number): any;
@@ -0,0 +1,5 @@
1
+ export * from './encode';
2
+ export * from './decode';
3
+ export * from './generic-utils';
4
+ export * from './jid-utils';
5
+ export * from './types';
@@ -0,0 +1,31 @@
1
+ export declare const S_WHATSAPP_NET = "@s.whatsapp.net";
2
+ export declare const OFFICIAL_BIZ_JID = "16505361212@c.us";
3
+ export declare const SERVER_JID = "server@c.us";
4
+ export declare const PSA_WID = "0@c.us";
5
+ export declare const STORIES_JID = "status@broadcast";
6
+ export type JidServer = 'c.us' | 'g.us' | 'broadcast' | 's.whatsapp.net' | 'call' | 'lid' | 'newsletter';
7
+ export type JidWithDevice = {
8
+ user: string;
9
+ device?: number;
10
+ };
11
+ export type FullJid = JidWithDevice & {
12
+ server: JidServer | string;
13
+ domainType?: number;
14
+ };
15
+ export declare const jidEncode: (user: string | number | null, server: JidServer, device?: number, agent?: number) => string;
16
+ export declare const jidDecode: (jid: string | undefined) => FullJid | undefined;
17
+ /** is the jid a user */
18
+ export declare const areJidsSameUser: (jid1: string | undefined, jid2: string | undefined) => boolean;
19
+ /** is the jid a user */
20
+ export declare const isJidUser: (jid: string | undefined) => boolean | undefined;
21
+ /** is the jid a group */
22
+ export declare const isLidUser: (jid: string | undefined) => boolean | undefined;
23
+ /** is the jid a broadcast */
24
+ export declare const isJidBroadcast: (jid: string | undefined) => boolean | undefined;
25
+ /** is the jid a group */
26
+ export declare const isJidGroup: (jid: string | undefined) => boolean | undefined;
27
+ /** is the jid the status broadcast */
28
+ export declare const isJidStatusBroadcast: (jid: string) => jid is "status@broadcast";
29
+ /** is the jid the newsletter */
30
+ export declare const isJidNewsLetter: (jid: string | undefined) => boolean | undefined;
31
+ export declare const jidNormalizedUser: (jid: string | undefined) => string;
@@ -0,0 +1,18 @@
1
+ import * as constants from './constants';
2
+ /**
3
+ * the binary node WA uses internally for communication
4
+ *
5
+ * this is manipulated soley as an object and it does not have any functions.
6
+ * This is done for easy serialization, to prevent running into issues with prototypes &
7
+ * to maintain functional code structure
8
+ * */
9
+ export type BinaryNode = {
10
+ tag: string;
11
+ attrs: {
12
+ [key: string]: string;
13
+ };
14
+ content?: BinaryNode[] | string | Uint8Array;
15
+ };
16
+ export type BinaryNodeAttributes = BinaryNode['attrs'];
17
+ export type BinaryNodeData = BinaryNode['content'];
18
+ export type BinaryNodeCodingOptions = typeof constants;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,8 @@
1
+ import { EventInputType } from './constants';
2
+ export declare class BinaryInfo {
3
+ protocolVersion: number;
4
+ sequence: number;
5
+ events: EventInputType[];
6
+ buffer: Buffer[];
7
+ constructor(options?: Partial<BinaryInfo>);
8
+ }
@@ -0,0 +1,38 @@
1
+ export declare const WEB_EVENTS: Event[];
2
+ export declare const WEB_GLOBALS: Global[];
3
+ export declare const FLAG_BYTE = 8, FLAG_GLOBAL = 0, FLAG_EVENT = 1, FLAG_FIELD = 2, FLAG_EXTENDED = 4;
4
+ export type Event = {
5
+ name: string;
6
+ id: number;
7
+ props: {
8
+ [key: string]: [number, string | {
9
+ [key: string]: number;
10
+ }];
11
+ };
12
+ weight: number;
13
+ wamChannel: string;
14
+ privateStatsIdInt: number;
15
+ };
16
+ export type Global = {
17
+ name: string;
18
+ id: number;
19
+ type: string | {
20
+ [key: string]: number;
21
+ };
22
+ validator?: string;
23
+ channels: string[];
24
+ };
25
+ type EventByName<T extends Event['name']> = Extract<Event, {
26
+ name: T;
27
+ }>;
28
+ export type EventInputType = {
29
+ [key in Event['name']]: {
30
+ props: {
31
+ [k in keyof EventByName<key>['props']]: any;
32
+ };
33
+ globals: {
34
+ [x: string]: any;
35
+ };
36
+ };
37
+ } & {};
38
+ export {};
@@ -0,0 +1,2 @@
1
+ import { BinaryInfo } from './BinaryInfo';
2
+ export declare const encodeWAM: (binaryInfo: BinaryInfo) => any;
@@ -0,0 +1,3 @@
1
+ export * from './constants';
2
+ export * from './encode';
3
+ export * from './BinaryInfo';
@@ -0,0 +1,9 @@
1
+ import { USyncQueryProtocol } from '../../Types/USync';
2
+ import { BinaryNode } from '../../WABinary';
3
+ import { USyncUser } from '../USyncUser';
4
+ export declare class USyncContactProtocol implements USyncQueryProtocol {
5
+ name: string;
6
+ getQueryElement(): BinaryNode;
7
+ getUserElement(user: USyncUser): BinaryNode;
8
+ parser(node: BinaryNode): boolean;
9
+ }
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.USyncContactProtocol = void 0;
4
+ const WABinary_1 = require("../../WABinary");
5
+ class USyncContactProtocol {
6
+ constructor() {
7
+ this.name = 'contact';
8
+ }
9
+ getQueryElement() {
10
+ return {
11
+ tag: 'contact',
12
+ attrs: {},
13
+ };
14
+ }
15
+ getUserElement(user) {
16
+ //TODO: Implement type / username fields (not yet supported)
17
+ return {
18
+ tag: 'contact',
19
+ attrs: {},
20
+ content: user.phone,
21
+ };
22
+ }
23
+ parser(node) {
24
+ var _a;
25
+ if (node.tag === 'contact') {
26
+ (0, WABinary_1.assertNodeErrorFree)(node);
27
+ return ((_a = node === null || node === void 0 ? void 0 : node.attrs) === null || _a === void 0 ? void 0 : _a.type) === 'in';
28
+ }
29
+ return false;
30
+ }
31
+ }
32
+ exports.USyncContactProtocol = USyncContactProtocol;
@@ -0,0 +1,22 @@
1
+ import { USyncQueryProtocol } from '../../Types/USync';
2
+ import { BinaryNode } from '../../WABinary';
3
+ export type KeyIndexData = {
4
+ timestamp: number;
5
+ signedKeyIndex?: Uint8Array;
6
+ expectedTimestamp?: number;
7
+ };
8
+ export type DeviceListData = {
9
+ id: number;
10
+ keyIndex?: number;
11
+ isHosted?: boolean;
12
+ };
13
+ export type ParsedDeviceInfo = {
14
+ deviceList?: DeviceListData[];
15
+ keyIndex?: KeyIndexData;
16
+ };
17
+ export declare class USyncDeviceProtocol implements USyncQueryProtocol {
18
+ name: string;
19
+ getQueryElement(): BinaryNode;
20
+ getUserElement(): BinaryNode | null;
21
+ parser(node: BinaryNode): ParsedDeviceInfo;
22
+ }
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.USyncDeviceProtocol = void 0;
4
+ const WABinary_1 = require("../../WABinary");
5
+ class USyncDeviceProtocol {
6
+ constructor() {
7
+ this.name = 'devices';
8
+ }
9
+ getQueryElement() {
10
+ return {
11
+ tag: 'devices',
12
+ attrs: {
13
+ version: '2',
14
+ },
15
+ };
16
+ }
17
+ getUserElement( /* user: USyncUser */) {
18
+ //TODO: Implement device phashing, ts and expectedTs
19
+ //TODO: if all are not present, return null <- current behavior
20
+ //TODO: otherwise return a node w tag 'devices' w those as attrs
21
+ return null;
22
+ }
23
+ parser(node) {
24
+ const deviceList = [];
25
+ let keyIndex = undefined;
26
+ if (node.tag === 'devices') {
27
+ (0, WABinary_1.assertNodeErrorFree)(node);
28
+ const deviceListNode = (0, WABinary_1.getBinaryNodeChild)(node, 'device-list');
29
+ const keyIndexNode = (0, WABinary_1.getBinaryNodeChild)(node, 'key-index-list');
30
+ if (Array.isArray(deviceListNode === null || deviceListNode === void 0 ? void 0 : deviceListNode.content)) {
31
+ for (const { tag, attrs } of deviceListNode.content) {
32
+ const id = +attrs.id;
33
+ const keyIndex = +attrs['key-index'];
34
+ if (tag === 'device') {
35
+ deviceList.push({
36
+ id,
37
+ keyIndex,
38
+ isHosted: !!(attrs['is_hosted'] && attrs['is_hosted'] === 'true')
39
+ });
40
+ }
41
+ }
42
+ }
43
+ if ((keyIndexNode === null || keyIndexNode === void 0 ? void 0 : keyIndexNode.tag) === 'key-index-list') {
44
+ keyIndex = {
45
+ timestamp: +keyIndexNode.attrs['ts'],
46
+ signedKeyIndex: keyIndexNode === null || keyIndexNode === void 0 ? void 0 : keyIndexNode.content,
47
+ expectedTimestamp: keyIndexNode.attrs['expected_ts'] ? +keyIndexNode.attrs['expected_ts'] : undefined
48
+ };
49
+ }
50
+ }
51
+ return {
52
+ deviceList,
53
+ keyIndex
54
+ };
55
+ }
56
+ }
57
+ exports.USyncDeviceProtocol = USyncDeviceProtocol;
@@ -0,0 +1,12 @@
1
+ import { USyncQueryProtocol } from '../../Types/USync';
2
+ import { BinaryNode } from '../../WABinary';
3
+ export type DisappearingModeData = {
4
+ duration: number;
5
+ setAt?: Date;
6
+ };
7
+ export declare class USyncDisappearingModeProtocol implements USyncQueryProtocol {
8
+ name: string;
9
+ getQueryElement(): BinaryNode;
10
+ getUserElement(): null;
11
+ parser(node: BinaryNode): DisappearingModeData | undefined;
12
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.USyncDisappearingModeProtocol = void 0;
4
+ const WABinary_1 = require("../../WABinary");
5
+ class USyncDisappearingModeProtocol {
6
+ constructor() {
7
+ this.name = 'disappearing_mode';
8
+ }
9
+ getQueryElement() {
10
+ return {
11
+ tag: 'disappearing_mode',
12
+ attrs: {},
13
+ };
14
+ }
15
+ getUserElement() {
16
+ return null;
17
+ }
18
+ parser(node) {
19
+ if (node.tag === 'status') {
20
+ (0, WABinary_1.assertNodeErrorFree)(node);
21
+ const duration = +(node === null || node === void 0 ? void 0 : node.attrs.duration);
22
+ const setAt = new Date(+((node === null || node === void 0 ? void 0 : node.attrs.t) || 0) * 1000);
23
+ return {
24
+ duration,
25
+ setAt,
26
+ };
27
+ }
28
+ }
29
+ }
30
+ exports.USyncDisappearingModeProtocol = USyncDisappearingModeProtocol;
@@ -0,0 +1,12 @@
1
+ import { USyncQueryProtocol } from '../../Types/USync';
2
+ import { BinaryNode } from '../../WABinary';
3
+ export type StatusData = {
4
+ status?: string | null;
5
+ setAt?: Date;
6
+ };
7
+ export declare class USyncStatusProtocol implements USyncQueryProtocol {
8
+ name: string;
9
+ getQueryElement(): BinaryNode;
10
+ getUserElement(): null;
11
+ parser(node: BinaryNode): StatusData | undefined;
12
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.USyncStatusProtocol = void 0;
4
+ const WABinary_1 = require("../../WABinary");
5
+ class USyncStatusProtocol {
6
+ constructor() {
7
+ this.name = 'status';
8
+ }
9
+ getQueryElement() {
10
+ return {
11
+ tag: 'status',
12
+ attrs: {},
13
+ };
14
+ }
15
+ getUserElement() {
16
+ return null;
17
+ }
18
+ parser(node) {
19
+ var _a;
20
+ if (node.tag === 'status') {
21
+ (0, WABinary_1.assertNodeErrorFree)(node);
22
+ let status = node === null || node === void 0 ? void 0 : node.content.toString();
23
+ const setAt = new Date(+((node === null || node === void 0 ? void 0 : node.attrs.t) || 0) * 1000);
24
+ if (!status) {
25
+ if (+((_a = node.attrs) === null || _a === void 0 ? void 0 : _a.code) === 401) {
26
+ status = '';
27
+ }
28
+ else {
29
+ status = null;
30
+ }
31
+ }
32
+ else if (typeof status === 'string' && status.length === 0) {
33
+ status = null;
34
+ }
35
+ return {
36
+ status,
37
+ setAt,
38
+ };
39
+ }
40
+ }
41
+ }
42
+ exports.USyncStatusProtocol = USyncStatusProtocol;
@@ -0,0 +1,4 @@
1
+ export * from './USyncDeviceProtocol';
2
+ export * from './USyncContactProtocol';
3
+ export * from './USyncStatusProtocol';
4
+ export * from './USyncDisappearingModeProtocol';
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./USyncDeviceProtocol"), exports);
18
+ __exportStar(require("./USyncContactProtocol"), exports);
19
+ __exportStar(require("./USyncStatusProtocol"), exports);
20
+ __exportStar(require("./USyncDisappearingModeProtocol"), exports);
@@ -0,0 +1,26 @@
1
+ import { USyncQueryProtocol } from '../Types/USync';
2
+ import { BinaryNode } from '../WABinary';
3
+ import { USyncUser } from './USyncUser';
4
+ export type USyncQueryResultList = {
5
+ [protocol: string]: unknown;
6
+ id: string;
7
+ };
8
+ export type USyncQueryResult = {
9
+ list: USyncQueryResultList[];
10
+ sideList: USyncQueryResultList[];
11
+ };
12
+ export declare class USyncQuery {
13
+ protocols: USyncQueryProtocol[];
14
+ users: USyncUser[];
15
+ context: string;
16
+ mode: string;
17
+ constructor();
18
+ withMode(mode: string): this;
19
+ withContext(context: string): this;
20
+ withUser(user: USyncUser): this;
21
+ parseUSyncQueryResult(result: BinaryNode): USyncQueryResult | undefined;
22
+ withDeviceProtocol(): this;
23
+ withContactProtocol(): this;
24
+ withStatusProtocol(): this;
25
+ withDisappearingModeProtocol(): this;
26
+ }
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.USyncQuery = void 0;
4
+ const WABinary_1 = require("../WABinary");
5
+ const Protocols_1 = require("./Protocols");
6
+ class USyncQuery {
7
+ constructor() {
8
+ this.protocols = [];
9
+ this.users = [];
10
+ this.context = 'interactive';
11
+ this.mode = 'query';
12
+ }
13
+ withMode(mode) {
14
+ this.mode = mode;
15
+ return this;
16
+ }
17
+ withContext(context) {
18
+ this.context = context;
19
+ return this;
20
+ }
21
+ withUser(user) {
22
+ this.users.push(user);
23
+ return this;
24
+ }
25
+ parseUSyncQueryResult(result) {
26
+ if (result.attrs.type !== 'result') {
27
+ return;
28
+ }
29
+ const protocolMap = Object.fromEntries(this.protocols.map((protocol) => {
30
+ return [protocol.name, protocol.parser];
31
+ }));
32
+ const queryResult = {
33
+ // TODO: implement errors etc.
34
+ list: [],
35
+ sideList: [],
36
+ };
37
+ const usyncNode = (0, WABinary_1.getBinaryNodeChild)(result, 'usync');
38
+ //TODO: implement error backoff, refresh etc.
39
+ //TODO: see if there are any errors in the result node
40
+ //const resultNode = getBinaryNodeChild(usyncNode, 'result')
41
+ const listNode = (0, WABinary_1.getBinaryNodeChild)(usyncNode, 'list');
42
+ if (Array.isArray(listNode === null || listNode === void 0 ? void 0 : listNode.content) && typeof listNode !== 'undefined') {
43
+ queryResult.list = listNode.content.map((node) => {
44
+ const id = node === null || node === void 0 ? void 0 : node.attrs.jid;
45
+ const data = Array.isArray(node === null || node === void 0 ? void 0 : node.content) ? Object.fromEntries(node.content.map((content) => {
46
+ const protocol = content.tag;
47
+ const parser = protocolMap[protocol];
48
+ if (parser) {
49
+ return [protocol, parser(content)];
50
+ }
51
+ else {
52
+ return [protocol, null];
53
+ }
54
+ }).filter(([, b]) => b !== null)) : {};
55
+ return { ...data, id };
56
+ });
57
+ }
58
+ //TODO: implement side list
59
+ //const sideListNode = getBinaryNodeChild(usyncNode, 'side_list')
60
+ return queryResult;
61
+ }
62
+ withDeviceProtocol() {
63
+ this.protocols.push(new Protocols_1.USyncDeviceProtocol());
64
+ return this;
65
+ }
66
+ withContactProtocol() {
67
+ this.protocols.push(new Protocols_1.USyncContactProtocol());
68
+ return this;
69
+ }
70
+ withStatusProtocol() {
71
+ this.protocols.push(new Protocols_1.USyncStatusProtocol());
72
+ return this;
73
+ }
74
+ withDisappearingModeProtocol() {
75
+ this.protocols.push(new Protocols_1.USyncDisappearingModeProtocol());
76
+ return this;
77
+ }
78
+ }
79
+ exports.USyncQuery = USyncQuery;
@@ -0,0 +1,10 @@
1
+ export declare class USyncUser {
2
+ id: string;
3
+ lid: string;
4
+ phone: string;
5
+ type: string;
6
+ withId(id: string): this;
7
+ withLid(lid: string): this;
8
+ withPhone(phone: string): this;
9
+ withType(type: string): this;
10
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.USyncUser = void 0;
4
+ class USyncUser {
5
+ withId(id) {
6
+ this.id = id;
7
+ return this;
8
+ }
9
+ withLid(lid) {
10
+ this.lid = lid;
11
+ return this;
12
+ }
13
+ withPhone(phone) {
14
+ this.phone = phone;
15
+ return this;
16
+ }
17
+ withType(type) {
18
+ this.type = type;
19
+ return this;
20
+ }
21
+ }
22
+ exports.USyncUser = USyncUser;
@@ -0,0 +1,3 @@
1
+ export * from './Protocols';
2
+ export * from './USyncQuery';
3
+ export * from './USyncUser';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./Protocols"), exports);
18
+ __exportStar(require("./USyncQuery"), exports);
19
+ __exportStar(require("./USyncUser"), exports);