torbaileys 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/LICENSE +21 -0
  2. package/WAProto/WAProto.proto +5311 -0
  3. package/WAProto/index.js +94091 -0
  4. package/lib/Defaults/index.js +123 -0
  5. package/lib/KeyDB/BinarySearch.js +20 -0
  6. package/lib/KeyDB/KeyedDB.js +167 -0
  7. package/lib/KeyDB/index.js +4 -0
  8. package/lib/Signal/Group/ciphertext-message.js +13 -0
  9. package/lib/Signal/Group/group-session-builder.js +32 -0
  10. package/lib/Signal/Group/group_cipher.js +84 -0
  11. package/lib/Signal/Group/index.js +13 -0
  12. package/lib/Signal/Group/keyhelper.js +20 -0
  13. package/lib/Signal/Group/sender-chain-key.js +28 -0
  14. package/lib/Signal/Group/sender-key-distribution-message.js +65 -0
  15. package/lib/Signal/Group/sender-key-message.js +68 -0
  16. package/lib/Signal/Group/sender-key-name.js +52 -0
  17. package/lib/Signal/Group/sender-key-record.js +43 -0
  18. package/lib/Signal/Group/sender-key-state.js +86 -0
  19. package/lib/Signal/Group/sender-message-key.js +28 -0
  20. package/lib/Signal/libsignal.js +324 -0
  21. package/lib/Signal/lid-mapping.js +155 -0
  22. package/lib/Socket/Client/index.js +4 -0
  23. package/lib/Socket/Client/types.js +13 -0
  24. package/lib/Socket/Client/websocket.js +52 -0
  25. package/lib/Socket/Client/websocket.js.bak +53 -0
  26. package/lib/Socket/business.js +377 -0
  27. package/lib/Socket/chats.js +881 -0
  28. package/lib/Socket/communities.js +413 -0
  29. package/lib/Socket/groups.js +312 -0
  30. package/lib/Socket/index.js +16 -0
  31. package/lib/Socket/messages-recv.js +1163 -0
  32. package/lib/Socket/messages-send.js +1100 -0
  33. package/lib/Socket/mex.js +45 -0
  34. package/lib/Socket/newsletter.js +262 -0
  35. package/lib/Socket/socket.js +820 -0
  36. package/lib/Store/index.js +6 -0
  37. package/lib/Store/make-cache-manager-store.js +75 -0
  38. package/lib/Store/make-in-memory-store.js +290 -0
  39. package/lib/Store/make-ordered-dictionary.js +79 -0
  40. package/lib/Store/object-repository.js +25 -0
  41. package/lib/Types/Auth.js +3 -0
  42. package/lib/Types/Bussines.js +3 -0
  43. package/lib/Types/Call.js +3 -0
  44. package/lib/Types/Chat.js +9 -0
  45. package/lib/Types/Contact.js +3 -0
  46. package/lib/Types/Events.js +3 -0
  47. package/lib/Types/GroupMetadata.js +3 -0
  48. package/lib/Types/Label.js +25 -0
  49. package/lib/Types/LabelAssociation.js +7 -0
  50. package/lib/Types/Message.js +12 -0
  51. package/lib/Types/Newsletter.js +33 -0
  52. package/lib/Types/Newsletter.js.bak +33 -0
  53. package/lib/Types/Product.js +3 -0
  54. package/lib/Types/Signal.js +3 -0
  55. package/lib/Types/Socket.js +4 -0
  56. package/lib/Types/State.js +11 -0
  57. package/lib/Types/USync.js +3 -0
  58. package/lib/Types/index.js +28 -0
  59. package/lib/Utils/auth-utils.js +219 -0
  60. package/lib/Utils/baileys-event-stream.js +44 -0
  61. package/lib/Utils/browser-utils.js +25 -0
  62. package/lib/Utils/business.js +233 -0
  63. package/lib/Utils/chat-utils.js +752 -0
  64. package/lib/Utils/crypto.js +130 -0
  65. package/lib/Utils/decode-wa-message.js +267 -0
  66. package/lib/Utils/decode-wa-message.js.bak +267 -0
  67. package/lib/Utils/event-buffer.js +528 -0
  68. package/lib/Utils/generics.js +355 -0
  69. package/lib/Utils/history.js +87 -0
  70. package/lib/Utils/index.js +21 -0
  71. package/lib/Utils/link-preview.js +81 -0
  72. package/lib/Utils/logger.js +5 -0
  73. package/lib/Utils/lt-hash.js +45 -0
  74. package/lib/Utils/make-mutex.js +36 -0
  75. package/lib/Utils/message-retry-manager.js +113 -0
  76. package/lib/Utils/messages-media.js +601 -0
  77. package/lib/Utils/messages.js +907 -0
  78. package/lib/Utils/noise-handler.js +144 -0
  79. package/lib/Utils/pre-key-manager.js +85 -0
  80. package/lib/Utils/process-message.js +341 -0
  81. package/lib/Utils/signal.js +161 -0
  82. package/lib/Utils/use-multi-file-auth-state.js +111 -0
  83. package/lib/Utils/validate-connection.js +200 -0
  84. package/lib/WABinary/constants.js +1303 -0
  85. package/lib/WABinary/decode.js +240 -0
  86. package/lib/WABinary/encode.js +218 -0
  87. package/lib/WABinary/generic-utils.js +189 -0
  88. package/lib/WABinary/index.js +7 -0
  89. package/lib/WABinary/jid-utils.js +93 -0
  90. package/lib/WABinary/types.js +3 -0
  91. package/lib/WAM/BinaryInfo.js +11 -0
  92. package/lib/WAM/constants.js +22853 -0
  93. package/lib/WAM/encode.js +154 -0
  94. package/lib/WAM/index.js +5 -0
  95. package/lib/WAUSync/Protocols/USyncContactProtocol.js +30 -0
  96. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
  97. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +29 -0
  98. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +39 -0
  99. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
  100. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +30 -0
  101. package/lib/WAUSync/Protocols/index.js +6 -0
  102. package/lib/WAUSync/USyncQuery.js +90 -0
  103. package/lib/WAUSync/USyncUser.js +24 -0
  104. package/lib/WAUSync/index.js +5 -0
  105. package/lib/index.js +16 -0
  106. package/package.json +105 -0
@@ -0,0 +1,93 @@
1
+ //=======================================================//
2
+ export const OFFICIAL_BIZ_JID = "16505361212@c.us";
3
+ export const S_WHATSAPP_NET = "@s.whatsapp.net";
4
+ export const STORIES_JID = "status@broadcast";
5
+ export const META_AI_JID = "13135550002@c.us";
6
+ export const SERVER_JID = "server@c.us";
7
+ export const PSA_WID = "0@c.us";
8
+ //=======================================================//
9
+ export var WAJIDDomains;
10
+ (function (WAJIDDomains) {
11
+ WAJIDDomains[WAJIDDomains["WHATSAPP"] = 0] = "WHATSAPP";
12
+ WAJIDDomains[WAJIDDomains["LID"] = 1] = "LID";
13
+ WAJIDDomains[WAJIDDomains["HOSTED"] = 128] = "HOSTED";
14
+ WAJIDDomains[WAJIDDomains["HOSTED_LID"] = 129] = "HOSTED_LID";
15
+ })(WAJIDDomains || (WAJIDDomains = {}));
16
+ export const getServerFromDomainType = (initialServer, domainType) => {
17
+ switch (domainType) {
18
+ case WAJIDDomains.LID:
19
+ return "lid";
20
+ case WAJIDDomains.HOSTED:
21
+ return "hosted";
22
+ case WAJIDDomains.HOSTED_LID:
23
+ return "hosted.lid";
24
+ case WAJIDDomains.WHATSAPP:
25
+ default:
26
+ return initialServer;
27
+ }
28
+ };
29
+ //=======================================================//
30
+ export const jidEncode = (user, server, device, agent) => {
31
+ return `${user || ""}${!!agent ? `_${agent}` : ""}${!!device ? `:${device}` : ""}@${server}`;
32
+ };
33
+ //=======================================================//
34
+ export const jidDecode = (jid) => {
35
+ const sepIdx = typeof jid === "string" ? jid.indexOf("@") : -1;
36
+ if (sepIdx < 0) {
37
+ return undefined;
38
+ }
39
+ const server = jid.slice(sepIdx + 1);
40
+ const userCombined = jid.slice(0, sepIdx);
41
+ const [userAgent, device] = userCombined.split(":");
42
+ const [user, agent] = userAgent.split("_");
43
+ let domainType = WAJIDDomains.WHATSAPP;
44
+ if (server === "lid") {
45
+ domainType = WAJIDDomains.LID;
46
+ }
47
+ else if (server === "hosted") {
48
+ domainType = WAJIDDomains.HOSTED;
49
+ }
50
+ else if (server === "hosted.lid") {
51
+ domainType = WAJIDDomains.HOSTED_LID;
52
+ }
53
+ else if (agent) {
54
+ domainType = parseInt(agent);
55
+ }
56
+ return {
57
+ server: server,
58
+ user: user,
59
+ domainType,
60
+ device: device ? +device : undefined
61
+ };
62
+ };
63
+ //=======================================================//
64
+ export const areJidsSameUser = (jid1, jid2) => jidDecode(jid1)?.user === jidDecode(jid2)?.user;
65
+ export const isJidMetaAI = (jid) => jid?.endsWith("@bot");
66
+ export const isPnUser = (jid) => jid?.endsWith("@s.whatsapp.net");
67
+ export const isLidUser = (jid) => jid?.endsWith("@lid");
68
+ export const isJidBroadcast = (jid) => jid?.endsWith("@broadcast");
69
+ export const isJidGroup = (jid) => jid?.endsWith("@g.us");
70
+ export const isJidStatusBroadcast = (jid) => jid === "status@broadcast";
71
+ export const isJidNewsletter = (jid) => jid?.endsWith("@newsletter");
72
+ export const isHostedPnUser = (jid) => jid?.endsWith("@hosted");
73
+ export const isHostedLidUser = (jid) => jid?.endsWith("@hosted.lid");
74
+ //=======================================================//
75
+ const botRegexp = /^1313555\d{4}$|^131655500\d{2}$/;
76
+ //=======================================================//
77
+ export const isJidBot = (jid) => jid && botRegexp.test(jid.split("@")[0]) && jid.endsWith("@c.us");
78
+ export const jidNormalizedUser = (jid) => {
79
+ const result = jidDecode(jid);
80
+ if (!result) {
81
+ return "";
82
+ }
83
+ const { user, server } = result;
84
+ return jidEncode(user, server === "c.us" ? "s.whatsapp.net" : server);
85
+ };
86
+ //=======================================================//
87
+ export const transferDevice = (fromJid, toJid) => {
88
+ const fromDecoded = jidDecode(fromJid);
89
+ const deviceId = fromDecoded?.device || 0;
90
+ const { server, user } = jidDecode(toJid);
91
+ return jidEncode(user, server, deviceId);
92
+ };
93
+ //=======================================================//
@@ -0,0 +1,3 @@
1
+ //=======================================================//
2
+ import * as constants from "./constants.js";
3
+ //=======================================================//
@@ -0,0 +1,11 @@
1
+ //=======================================================//
2
+ export class BinaryInfo {
3
+ constructor(options = {}) {
4
+ this.protocolVersion = 5;
5
+ this.sequence = 0;
6
+ this.events = [];
7
+ this.buffer = [];
8
+ Object.assign(this, options);
9
+ }
10
+ }
11
+ //=======================================================//