@aseppxyzz12/baileys 1.1.8

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 (185) hide show
  1. package/LICENSE +25 -0
  2. package/README.md +2579 -0
  3. package/WAProto/AICommon/AICommon.js +19396 -0
  4. package/WAProto/AICommon/AICommon.proto +820 -0
  5. package/WAProto/Adv/Adv.js +1137 -0
  6. package/WAProto/Adv/Adv.proto +42 -0
  7. package/WAProto/BotMetadata/BotMetadata.js +8975 -0
  8. package/WAProto/BotMetadata/BotMetadata.proto +484 -0
  9. package/WAProto/Cert/Cert.js +893 -0
  10. package/WAProto/Cert/Cert.proto +30 -0
  11. package/WAProto/ChatLockSettings/ChatLockSettings.js +673 -0
  12. package/WAProto/ChatLockSettings/ChatLockSettings.proto +9 -0
  13. package/WAProto/CompanionReg/CompanionReg.js +2457 -0
  14. package/WAProto/CompanionReg/CompanionReg.proto +103 -0
  15. package/WAProto/DeviceCapabilities/DeviceCapabilities.js +846 -0
  16. package/WAProto/DeviceCapabilities/DeviceCapabilities.proto +38 -0
  17. package/WAProto/E2E/E2E.js +78728 -0
  18. package/WAProto/E2E/E2E.proto +1970 -0
  19. package/WAProto/Ephemeral/Ephemeral.js +143 -0
  20. package/WAProto/Ephemeral/Ephemeral.proto +7 -0
  21. package/WAProto/HistorySync/HistorySync.js +95931 -0
  22. package/WAProto/HistorySync/HistorySync.proto +229 -0
  23. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.js +414 -0
  24. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.proto +13 -0
  25. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.js +980 -0
  26. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.proto +38 -0
  27. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +81185 -0
  28. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.proto +88 -0
  29. package/WAProto/MmsRetry/MmsRetry.js +310 -0
  30. package/WAProto/MmsRetry/MmsRetry.proto +19 -0
  31. package/WAProto/Protocol/Protocol.js +399 -0
  32. package/WAProto/Protocol/Protocol.proto +22 -0
  33. package/WAProto/Reporting/Reporting.js +535 -0
  34. package/WAProto/Reporting/Reporting.proto +22 -0
  35. package/WAProto/ServerSync/ServerSync.js +1830 -0
  36. package/WAProto/ServerSync/ServerSync.proto +70 -0
  37. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.js +3267 -0
  38. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.proto +95 -0
  39. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.js +1140 -0
  40. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.proto +44 -0
  41. package/WAProto/StatusAttributions/StatusAttributions.js +1604 -0
  42. package/WAProto/StatusAttributions/StatusAttributions.proto +89 -0
  43. package/WAProto/SyncAction/SyncAction.js +17424 -0
  44. package/WAProto/SyncAction/SyncAction.proto +663 -0
  45. package/WAProto/UserPassword/UserPassword.js +544 -0
  46. package/WAProto/UserPassword/UserPassword.proto +28 -0
  47. package/WAProto/VnameCert/VnameCert.js +1466 -0
  48. package/WAProto/VnameCert/VnameCert.proto +65 -0
  49. package/WAProto/Wa6/Wa6.js +4601 -0
  50. package/WAProto/Wa6/Wa6.proto +241 -0
  51. package/WAProto/Web/Web.js +90819 -0
  52. package/WAProto/Web/Web.proto +605 -0
  53. package/WAProto/index.js +30 -0
  54. package/engine-requirements.js +9 -0
  55. package/lib/Defaults/baileys-version.json +3 -0
  56. package/lib/Defaults/connection.js +39 -0
  57. package/lib/Defaults/constants.js +50 -0
  58. package/lib/Defaults/history.js +13 -0
  59. package/lib/Defaults/index.js +36 -0
  60. package/lib/Defaults/media.js +43 -0
  61. package/lib/Defaults/phonenumber-mcc.json +223 -0
  62. package/lib/Defaults/prefix.js +12 -0
  63. package/lib/Function/Download/tiktok.js +19 -0
  64. package/lib/Function/Tools/bypass.js +19 -0
  65. package/lib/Function/index.js +13 -0
  66. package/lib/Signal/Group/ciphertext-message.js +14 -0
  67. package/lib/Signal/Group/group-session-builder.js +46 -0
  68. package/lib/Signal/Group/group_cipher.js +104 -0
  69. package/lib/Signal/Group/index.js +42 -0
  70. package/lib/Signal/Group/keyhelper.js +21 -0
  71. package/lib/Signal/Group/queue-job.js +57 -0
  72. package/lib/Signal/Group/sender-chain-key.js +34 -0
  73. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  74. package/lib/Signal/Group/sender-key-message.js +78 -0
  75. package/lib/Signal/Group/sender-key-name.js +49 -0
  76. package/lib/Signal/Group/sender-key-record.js +45 -0
  77. package/lib/Signal/Group/sender-key-state.js +100 -0
  78. package/lib/Signal/Group/sender-message-key.js +28 -0
  79. package/lib/Signal/libsignal.js +364 -0
  80. package/lib/Signal/lid-mapping.js +164 -0
  81. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  82. package/lib/Socket/Client/index.js +31 -0
  83. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  84. package/lib/Socket/Client/types.js +12 -0
  85. package/lib/Socket/Client/web-socket-client.js +62 -0
  86. package/lib/Socket/Client/websocket.js +67 -0
  87. package/lib/Socket/business.js +291 -0
  88. package/lib/Socket/chats.js +874 -0
  89. package/lib/Socket/community.js +454 -0
  90. package/lib/Socket/dugong.js +658 -0
  91. package/lib/Socket/groups.js +357 -0
  92. package/lib/Socket/index.js +13 -0
  93. package/lib/Socket/messages-recv.js +1509 -0
  94. package/lib/Socket/messages-send.js +1505 -0
  95. package/lib/Socket/mex.js +54 -0
  96. package/lib/Socket/newsletter.js +171 -0
  97. package/lib/Socket/registration.js +167 -0
  98. package/lib/Socket/rich-content.js +279 -0
  99. package/lib/Socket/socket.js +905 -0
  100. package/lib/Socket/username.js +157 -0
  101. package/lib/Socket/usync.js +70 -0
  102. package/lib/Store/index.js +37 -0
  103. package/lib/Store/keyed-db.js +114 -0
  104. package/lib/Store/make-cache-manager-store.js +77 -0
  105. package/lib/Store/make-in-memory-store.js +423 -0
  106. package/lib/Store/make-ordered-dictionary.js +78 -0
  107. package/lib/Store/object-repository.js +26 -0
  108. package/lib/Types/Auth.js +2 -0
  109. package/lib/Types/Bussines.js +2 -0
  110. package/lib/Types/Call.js +2 -0
  111. package/lib/Types/Chat.js +10 -0
  112. package/lib/Types/Contact.js +2 -0
  113. package/lib/Types/Events.js +2 -0
  114. package/lib/Types/GroupMetadata.js +2 -0
  115. package/lib/Types/Label.js +25 -0
  116. package/lib/Types/LabelAssociation.js +4 -0
  117. package/lib/Types/Message.js +11 -0
  118. package/lib/Types/Mex.js +40 -0
  119. package/lib/Types/MexUpdates.js +15 -0
  120. package/lib/Types/Newsletter.js +32 -0
  121. package/lib/Types/Product.js +2 -0
  122. package/lib/Types/Signal.js +2 -0
  123. package/lib/Types/Socket.js +2 -0
  124. package/lib/Types/State.js +9 -0
  125. package/lib/Types/USync.js +2 -0
  126. package/lib/Types/index.js +60 -0
  127. package/lib/Utils/auth-utils.js +256 -0
  128. package/lib/Utils/baileys-event-stream.js +63 -0
  129. package/lib/Utils/bot-toolkit.js +455 -0
  130. package/lib/Utils/browser-utils.js +29 -0
  131. package/lib/Utils/business.js +233 -0
  132. package/lib/Utils/chat-utils.js +904 -0
  133. package/lib/Utils/companion-reg-client-utils.js +41 -0
  134. package/lib/Utils/crypto.js +144 -0
  135. package/lib/Utils/decode-wa-message.js +305 -0
  136. package/lib/Utils/event-buffer.js +555 -0
  137. package/lib/Utils/generics.js +411 -0
  138. package/lib/Utils/history.js +100 -0
  139. package/lib/Utils/identity-change-handler.js +53 -0
  140. package/lib/Utils/index.js +57 -0
  141. package/lib/Utils/link-preview.js +76 -0
  142. package/lib/Utils/logger.js +4 -0
  143. package/lib/Utils/lt-hash.js +45 -0
  144. package/lib/Utils/make-mutex.js +33 -0
  145. package/lib/Utils/message-composer.js +289 -0
  146. package/lib/Utils/message-retry-manager.js +134 -0
  147. package/lib/Utils/messages-media.js +806 -0
  148. package/lib/Utils/messages.js +1908 -0
  149. package/lib/Utils/noise-handler.js +157 -0
  150. package/lib/Utils/offline-node-processor.js +42 -0
  151. package/lib/Utils/pre-key-manager.js +86 -0
  152. package/lib/Utils/process-message.js +814 -0
  153. package/lib/Utils/reporting-utils.js +264 -0
  154. package/lib/Utils/signal.js +183 -0
  155. package/lib/Utils/stanza-ack.js +36 -0
  156. package/lib/Utils/sync-action-utils.js +52 -0
  157. package/lib/Utils/tc-token-utils.js +167 -0
  158. package/lib/Utils/use-multi-file-auth-state.js +104 -0
  159. package/lib/Utils/validate-connection.js +229 -0
  160. package/lib/Utils/vialeys-event-stream.js +41 -0
  161. package/lib/WABinary/constants.js +1308 -0
  162. package/lib/WABinary/decode.js +233 -0
  163. package/lib/WABinary/encode.js +212 -0
  164. package/lib/WABinary/generic-utils.js +124 -0
  165. package/lib/WABinary/index.js +36 -0
  166. package/lib/WABinary/jid-utils.js +101 -0
  167. package/lib/WABinary/types.js +2 -0
  168. package/lib/WAM/BinaryInfo.js +12 -0
  169. package/lib/WAM/constants.js +20491 -0
  170. package/lib/WAM/encode.js +148 -0
  171. package/lib/WAM/index.js +34 -0
  172. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +62 -0
  173. package/lib/WAUSync/Protocols/USyncContactProtocol.js +38 -0
  174. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +50 -0
  175. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +25 -0
  176. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +24 -0
  177. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +32 -0
  178. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
  179. package/lib/WAUSync/Protocols/index.js +38 -0
  180. package/lib/WAUSync/USyncQuery.js +97 -0
  181. package/lib/WAUSync/USyncUser.js +33 -0
  182. package/lib/WAUSync/index.js +34 -0
  183. package/lib/index.js +113 -0
  184. package/lib/messages-send.js +1496 -0
  185. package/package.json +100 -0
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const {
4
+ FLAG_BYTE: FLAG_BYTE,
5
+ FLAG_EVENT: FLAG_EVENT,
6
+ FLAG_EXTENDED: FLAG_EXTENDED,
7
+ FLAG_FIELD: FLAG_FIELD,
8
+ FLAG_GLOBAL: FLAG_GLOBAL,
9
+ WEB_EVENTS: WEB_EVENTS,
10
+ WEB_GLOBALS: WEB_GLOBALS,
11
+ } = require("./constants");
12
+ const getHeaderBitLength = (key) => (key < 256 ? 2 : 3);
13
+ const encodeWAM = (binaryInfo) => {
14
+ binaryInfo.buffer = [];
15
+ encodeWAMHeader(binaryInfo);
16
+ encodeEvents(binaryInfo);
17
+ const totalSize = binaryInfo.buffer.map((a) => a.length).reduce((a, b) => a + b);
18
+ const buffer = Buffer.alloc(totalSize);
19
+ let offset = 0;
20
+ for (const buffer_ of binaryInfo.buffer) {
21
+ buffer_.copy(buffer, offset);
22
+ offset += buffer_.length;
23
+ }
24
+ return buffer;
25
+ };
26
+ function encodeWAMHeader(binaryInfo) {
27
+ const headerBuffer = Buffer.alloc(8);
28
+ headerBuffer.write("WAM", 0, "utf8");
29
+ headerBuffer.writeUInt8(binaryInfo.protocolVersion, 3);
30
+ headerBuffer.writeUInt8(1, 4);
31
+ headerBuffer.writeUInt16BE(binaryInfo.sequence, 5);
32
+ headerBuffer.writeUInt8(0, 7);
33
+ binaryInfo.buffer.push(headerBuffer);
34
+ }
35
+ function encodeGlobalAttributes(binaryInfo, globals) {
36
+ for (const [key, _value] of Object.entries(globals)) {
37
+ const id = WEB_GLOBALS.find((a) => a?.name === key).id;
38
+ let value = _value;
39
+ if (typeof value === "boolean") {
40
+ value = value ? 1 : 0;
41
+ }
42
+ binaryInfo.buffer.push(serializeData(id, value, FLAG_GLOBAL));
43
+ }
44
+ }
45
+ function encodeEvents(binaryInfo) {
46
+ for (const [name, { props: props, globals: globals }] of binaryInfo.events.map(
47
+ (a) => Object.entries(a)[0]
48
+ )) {
49
+ encodeGlobalAttributes(binaryInfo, globals);
50
+ const event = WEB_EVENTS.find((a) => a.name === name);
51
+ const props_ = Object.entries(props);
52
+ let extended = false;
53
+ for (const [, value] of props_) {
54
+ extended || (extended = value !== null);
55
+ }
56
+ const eventFlag = extended ? FLAG_EVENT : FLAG_EVENT | FLAG_EXTENDED;
57
+ binaryInfo.buffer.push(serializeData(event.id, -event.weight, eventFlag));
58
+ for (let i = 0; i < props_.length; i++) {
59
+ const [key, _value] = props_[i];
60
+ const id = event.props[key]?.[0];
61
+ extended = i < props_.length - 1;
62
+ let value = _value;
63
+ if (typeof value === "boolean") {
64
+ value = value ? 1 : 0;
65
+ }
66
+ const fieldFlag = extended ? FLAG_EVENT : FLAG_FIELD | FLAG_EXTENDED;
67
+ binaryInfo.buffer.push(serializeData(id, value, fieldFlag));
68
+ }
69
+ }
70
+ }
71
+ function serializeData(key, value, flag) {
72
+ const bufferLength = getHeaderBitLength(key);
73
+ let buffer;
74
+ let offset = 0;
75
+ if (value === null) {
76
+ if (flag === FLAG_GLOBAL) {
77
+ buffer = Buffer.alloc(bufferLength);
78
+ offset = serializeHeader(buffer, offset, key, flag);
79
+ return buffer;
80
+ }
81
+ } else if (typeof value === "number" && Number.isInteger(value)) {
82
+ if (value === 0 || value === 1) {
83
+ buffer = Buffer.alloc(bufferLength);
84
+ offset = serializeHeader(buffer, offset, key, flag | ((value + 1) << 4));
85
+ return buffer;
86
+ } else if (-128 <= value && value < 128) {
87
+ buffer = Buffer.alloc(bufferLength + 1);
88
+ offset = serializeHeader(buffer, offset, key, flag | (3 << 4));
89
+ buffer.writeInt8(value, offset);
90
+ return buffer;
91
+ } else if (-32768 <= value && value < 32768) {
92
+ buffer = Buffer.alloc(bufferLength + 2);
93
+ offset = serializeHeader(buffer, offset, key, flag | (4 << 4));
94
+ buffer.writeInt16LE(value, offset);
95
+ return buffer;
96
+ } else if (-2147483648 <= value && value < 2147483648) {
97
+ buffer = Buffer.alloc(bufferLength + 4);
98
+ offset = serializeHeader(buffer, offset, key, flag | (5 << 4));
99
+ buffer.writeInt32LE(value, offset);
100
+ return buffer;
101
+ } else {
102
+ buffer = Buffer.alloc(bufferLength + 8);
103
+ offset = serializeHeader(buffer, offset, key, flag | (7 << 4));
104
+ buffer.writeDoubleLE(value, offset);
105
+ return buffer;
106
+ }
107
+ } else if (typeof value === "number") {
108
+ buffer = Buffer.alloc(bufferLength + 8);
109
+ offset = serializeHeader(buffer, offset, key, flag | (7 << 4));
110
+ buffer.writeDoubleLE(value, offset);
111
+ return buffer;
112
+ } else if (typeof value === "string") {
113
+ const utf8Bytes = Buffer.byteLength(value, "utf8");
114
+ if (utf8Bytes < 256) {
115
+ buffer = Buffer.alloc(bufferLength + 1 + utf8Bytes);
116
+ offset = serializeHeader(buffer, offset, key, flag | (8 << 4));
117
+ buffer.writeUint8(utf8Bytes, offset++);
118
+ } else if (utf8Bytes < 65536) {
119
+ buffer = Buffer.alloc(bufferLength + 2 + utf8Bytes);
120
+ offset = serializeHeader(buffer, offset, key, flag | (9 << 4));
121
+ buffer.writeUInt16LE(utf8Bytes, offset);
122
+ offset += 2;
123
+ } else {
124
+ buffer = Buffer.alloc(bufferLength + 4 + utf8Bytes);
125
+ offset = serializeHeader(buffer, offset, key, flag | (10 << 4));
126
+ buffer.writeUInt32LE(utf8Bytes, offset);
127
+ offset += 4;
128
+ }
129
+ buffer.write(value, offset, "utf8");
130
+ return buffer;
131
+ }
132
+ throw "missing";
133
+ }
134
+ function serializeHeader(buffer, offset, key, flag) {
135
+ if (key < 256) {
136
+ buffer.writeUInt8(flag, offset);
137
+ offset += 1;
138
+ buffer.writeUInt8(key, offset);
139
+ offset += 1;
140
+ } else {
141
+ buffer.writeUInt8(flag | FLAG_BYTE, offset);
142
+ offset += 1;
143
+ buffer.writeUInt16LE(key, offset);
144
+ offset += 2;
145
+ }
146
+ return offset;
147
+ }
148
+ module.exports = { encodeWAM: encodeWAM };
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ const __createBinding =
3
+ (this && this.__createBinding) ||
4
+ (Object.create
5
+ ? function (o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ let desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = {
10
+ enumerable: true,
11
+ get: function () {
12
+ return m[k];
13
+ },
14
+ };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
17
+ }
18
+ : function (o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ });
22
+ const __exportStar =
23
+ (this && this.__exportStar) ||
24
+ function (m, exports) {
25
+ for (var p in m) {
26
+ if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) {
27
+ __createBinding(exports, m, p);
28
+ }
29
+ }
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ __exportStar(require("./constants"), exports);
33
+ __exportStar(require("./encode"), exports);
34
+ __exportStar(require("./BinaryInfo"), exports);
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const {
4
+ getBinaryNodeChild: getBinaryNodeChild,
5
+ getBinaryNodeChildren: getBinaryNodeChildren,
6
+ getBinaryNodeChildString: getBinaryNodeChildString,
7
+ } = require("../../WABinary");
8
+ class USyncBotProfileProtocol {
9
+ constructor() {
10
+ this.name = "bot";
11
+ }
12
+ getQueryElement() {
13
+ return {
14
+ tag: "bot",
15
+ attrs: {},
16
+ content: [{ tag: "profile", attrs: { v: "1" } }],
17
+ };
18
+ }
19
+ getUserElement(user) {
20
+ return {
21
+ tag: "bot",
22
+ attrs: {},
23
+ content: [{ tag: "profile", attrs: { persona_id: user.personaId } }],
24
+ };
25
+ }
26
+ parser(node) {
27
+ const botNode = getBinaryNodeChild(node, "bot");
28
+ const profile = getBinaryNodeChild(botNode, "profile");
29
+ const commandsNode = getBinaryNodeChild(profile, "commands");
30
+ const promptsNode = getBinaryNodeChild(profile, "prompts");
31
+ const commands = [];
32
+ const prompts = [];
33
+ if (commandsNode) {
34
+ for (const command of getBinaryNodeChildren(commandsNode, "command")) {
35
+ commands.push({
36
+ name: getBinaryNodeChildString(command, "name") || "",
37
+ description: getBinaryNodeChildString(command, "description") || "",
38
+ });
39
+ }
40
+ }
41
+ if (promptsNode) {
42
+ for (const prompt of getBinaryNodeChildren(promptsNode, "prompt")) {
43
+ prompts.push(
44
+ `${getBinaryNodeChildString(prompt, "emoji") || ""} ${getBinaryNodeChildString(prompt, "text") || ""}`
45
+ );
46
+ }
47
+ }
48
+ return {
49
+ isDefault: !!getBinaryNodeChild(profile, "default"),
50
+ jid: node.attrs.jid,
51
+ name: getBinaryNodeChildString(profile, "name") || "",
52
+ attributes: getBinaryNodeChildString(profile, "attributes") || "",
53
+ description: getBinaryNodeChildString(profile, "description") || "",
54
+ category: getBinaryNodeChildString(profile, "category") || "",
55
+ personaId: profile.attrs["persona_id"] || "",
56
+ commandsDescription: getBinaryNodeChildString(commandsNode, "description") || "",
57
+ commands: commands,
58
+ prompts: prompts,
59
+ };
60
+ }
61
+ }
62
+ module.exports = { USyncBotProfileProtocol: USyncBotProfileProtocol };
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const { assertNodeErrorFree: assertNodeErrorFree } = require("../../WABinary");
4
+ class USyncContactProtocol {
5
+ constructor() {
6
+ this.name = "contact";
7
+ }
8
+ getQueryElement() {
9
+ return { tag: "contact", attrs: {} };
10
+ }
11
+ getUserElement(user) {
12
+ if (user.phone) {
13
+ return { tag: "contact", attrs: {}, content: user.phone };
14
+ }
15
+ if (user.username) {
16
+ return {
17
+ tag: "contact",
18
+ attrs: {
19
+ username: user.username,
20
+ ...(user.usernameKey ? { pin: user.usernameKey } : {}),
21
+ ...(user.lid ? { lid: user.lid } : {}),
22
+ },
23
+ };
24
+ }
25
+ if (user.type) {
26
+ return { tag: "contact", attrs: { type: user.type } };
27
+ }
28
+ return { tag: "contact", attrs: {} };
29
+ }
30
+ parser(node) {
31
+ if (node.tag === "contact") {
32
+ assertNodeErrorFree(node);
33
+ return node?.attrs?.type === "in";
34
+ }
35
+ return false;
36
+ }
37
+ }
38
+ module.exports = { USyncContactProtocol: USyncContactProtocol };
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const {
4
+ getBinaryNodeChild: getBinaryNodeChild,
5
+ assertNodeErrorFree: assertNodeErrorFree,
6
+ } = require("../../WABinary");
7
+ class USyncDeviceProtocol {
8
+ constructor() {
9
+ this.name = "devices";
10
+ }
11
+ getQueryElement() {
12
+ return { tag: "devices", attrs: { version: "2" } };
13
+ }
14
+ getUserElement() {
15
+ return null;
16
+ }
17
+ parser(node) {
18
+ const deviceList = [];
19
+ let keyIndex = undefined;
20
+ if (node.tag === "devices") {
21
+ assertNodeErrorFree(node);
22
+ const deviceListNode = getBinaryNodeChild(node, "device-list");
23
+ const keyIndexNode = getBinaryNodeChild(node, "key-index-list");
24
+ if (Array.isArray(deviceListNode?.content)) {
25
+ for (const { tag: tag, attrs: attrs } of deviceListNode.content) {
26
+ const id = +attrs.id;
27
+ const keyIndex = +attrs["key-index"];
28
+ if (tag === "device") {
29
+ deviceList.push({
30
+ id: id,
31
+ keyIndex: keyIndex,
32
+ isHosted: !!(attrs["is_hosted"] && attrs["is_hosted"] === "true"),
33
+ });
34
+ }
35
+ }
36
+ }
37
+ if (keyIndexNode?.tag === "key-index-list") {
38
+ keyIndex = {
39
+ timestamp: +keyIndexNode.attrs["ts"],
40
+ signedKeyIndex: keyIndexNode?.content,
41
+ expectedTimestamp: keyIndexNode.attrs["expected_ts"]
42
+ ? +keyIndexNode.attrs["expected_ts"]
43
+ : undefined,
44
+ };
45
+ }
46
+ }
47
+ return { deviceList: deviceList, keyIndex: keyIndex };
48
+ }
49
+ }
50
+ module.exports = { USyncDeviceProtocol: USyncDeviceProtocol };
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const { assertNodeErrorFree: assertNodeErrorFree } = require("../../WABinary");
4
+ class USyncDisappearingModeProtocol {
5
+ constructor() {
6
+ this.name = "disappearing_mode";
7
+ }
8
+ getQueryElement() {
9
+ return { tag: "disappearing_mode", attrs: {} };
10
+ }
11
+ getUserElement() {
12
+ return null;
13
+ }
14
+ parser(node) {
15
+ if (node.tag === "disappearing_mode") {
16
+ assertNodeErrorFree(node);
17
+ const duration = +node?.attrs?.duration;
18
+ const setAt = new Date(+(node?.attrs?.t || 0) * 1e3);
19
+ return { duration: duration, setAt: setAt };
20
+ }
21
+ }
22
+ }
23
+ module.exports = {
24
+ USyncDisappearingModeProtocol: USyncDisappearingModeProtocol,
25
+ };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class USyncLIDProtocol {
4
+ constructor() {
5
+ this.name = "lid";
6
+ }
7
+ getQueryElement() {
8
+ return { tag: "lid", attrs: {} };
9
+ }
10
+ getUserElement(user) {
11
+ if (user.lid) {
12
+ return { tag: "lid", attrs: { jid: user.lid } };
13
+ } else {
14
+ return null;
15
+ }
16
+ }
17
+ parser(node) {
18
+ if (node.tag === "lid") {
19
+ return node.attrs.val;
20
+ }
21
+ return null;
22
+ }
23
+ }
24
+ module.exports = { USyncLIDProtocol: USyncLIDProtocol };
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const { assertNodeErrorFree: assertNodeErrorFree } = require("../../WABinary");
4
+ class USyncStatusProtocol {
5
+ constructor() {
6
+ this.name = "status";
7
+ }
8
+ getQueryElement() {
9
+ return { tag: "status", attrs: {} };
10
+ }
11
+ getUserElement() {
12
+ return null;
13
+ }
14
+ parser(node) {
15
+ if (node.tag === "status") {
16
+ assertNodeErrorFree(node);
17
+ let status = node?.content?.toString() || null;
18
+ const setAt = new Date(+(node?.attrs?.t || 0) * 1e3);
19
+ if (!status) {
20
+ if (+node.attrs?.code === 401) {
21
+ status = "";
22
+ } else {
23
+ status = null;
24
+ }
25
+ } else if (typeof status === "string" && status.length === 0) {
26
+ status = null;
27
+ }
28
+ return { status: status, setAt: setAt };
29
+ }
30
+ }
31
+ }
32
+ module.exports = { USyncStatusProtocol: USyncStatusProtocol };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ // Ported & adapted from PouCode fork for AsepXyz Baileys
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const { assertNodeErrorFree: assertNodeErrorFree } = require("../../WABinary");
5
+ class USyncUsernameProtocol {
6
+ constructor() {
7
+ this.name = "username";
8
+ }
9
+ getQueryElement() {
10
+ return { tag: "username", attrs: {} };
11
+ }
12
+ getUserElement(user) {
13
+ void user;
14
+ return null;
15
+ }
16
+ parser(node) {
17
+ if (node.tag === "username") {
18
+ assertNodeErrorFree(node);
19
+ return typeof node.content === "string" ? node.content : null;
20
+ }
21
+ return null;
22
+ }
23
+ }
24
+ module.exports = { USyncUsernameProtocol: USyncUsernameProtocol };
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ const __createBinding =
3
+ (this && this.__createBinding) ||
4
+ (Object.create
5
+ ? function (o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ let desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = {
10
+ enumerable: true,
11
+ get: function () {
12
+ return m[k];
13
+ },
14
+ };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
17
+ }
18
+ : function (o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ });
22
+ const __exportStar =
23
+ (this && this.__exportStar) ||
24
+ function (m, exports) {
25
+ for (var p in m) {
26
+ if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) {
27
+ __createBinding(exports, m, p);
28
+ }
29
+ }
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ __exportStar(require("./USyncBotProfileProtocol"), exports);
33
+ __exportStar(require("./USyncContactProtocol"), exports);
34
+ __exportStar(require("./USyncDeviceProtocol"), exports);
35
+ __exportStar(require("./USyncLIDProtocol"), exports);
36
+ __exportStar(require("./USyncStatusProtocol"), exports);
37
+ __exportStar(require("./USyncDisappearingModeProtocol"), exports);
38
+ __exportStar(require("./USyncUsernameProtocol"), exports);
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const { getBinaryNodeChild: getBinaryNodeChild } = require("../WABinary");
4
+ const {
5
+ USyncLIDProtocol: USyncLIDProtocol,
6
+ USyncDeviceProtocol: USyncDeviceProtocol,
7
+ USyncContactProtocol: USyncContactProtocol,
8
+ USyncStatusProtocol: USyncStatusProtocol,
9
+ USyncBotProfileProtocol: USyncBotProfileProtocol,
10
+ USyncDisappearingModeProtocol: USyncDisappearingModeProtocol,
11
+ USyncUsernameProtocol: USyncUsernameProtocol,
12
+ } = require("./Protocols");
13
+ class USyncQuery {
14
+ constructor() {
15
+ this.protocols = [];
16
+ this.users = [];
17
+ this.context = "interactive";
18
+ this.mode = "query";
19
+ }
20
+ withMode(mode) {
21
+ this.mode = mode;
22
+ return this;
23
+ }
24
+ withContext(context) {
25
+ this.context = context;
26
+ return this;
27
+ }
28
+ withUser(user) {
29
+ this.users.push(user);
30
+ return this;
31
+ }
32
+ parseUSyncQueryResult(result) {
33
+ if (!result || result.attrs.type !== "result") {
34
+ return;
35
+ }
36
+ const protocolMap = Object.fromEntries(
37
+ this.protocols.map((protocol) => [protocol.name, protocol.parser])
38
+ );
39
+ const queryResult = { list: [], sideList: [] };
40
+ const usyncNode = getBinaryNodeChild(result, "usync");
41
+ const listNode = usyncNode ? getBinaryNodeChild(usyncNode, "list") : undefined;
42
+ if (listNode?.content && Array.isArray(listNode.content)) {
43
+ queryResult.list = listNode.content.reduce((acc, node) => {
44
+ const id = node?.attrs.jid;
45
+ if (id) {
46
+ const data = Array.isArray(node?.content)
47
+ ? Object.fromEntries(
48
+ node.content
49
+ .map((content) => {
50
+ const protocol = content.tag;
51
+ const parser = protocolMap[protocol];
52
+ if (parser) {
53
+ return [protocol, parser(content)];
54
+ } else {
55
+ return [protocol, null];
56
+ }
57
+ })
58
+ .filter(([, b]) => b !== null)
59
+ )
60
+ : {};
61
+ acc.push({ ...data, id: id });
62
+ }
63
+ return acc;
64
+ }, []);
65
+ }
66
+ return queryResult;
67
+ }
68
+ withLIDProtocol() {
69
+ this.protocols.push(new USyncLIDProtocol());
70
+ return this;
71
+ }
72
+ withDeviceProtocol() {
73
+ this.protocols.push(new USyncDeviceProtocol());
74
+ return this;
75
+ }
76
+ withContactProtocol() {
77
+ this.protocols.push(new USyncContactProtocol());
78
+ return this;
79
+ }
80
+ withStatusProtocol() {
81
+ this.protocols.push(new USyncStatusProtocol());
82
+ return this;
83
+ }
84
+ withBotProfileProtocol() {
85
+ this.protocols.push(new USyncBotProfileProtocol());
86
+ return this;
87
+ }
88
+ withDisappearingModeProtocol() {
89
+ this.protocols.push(new USyncDisappearingModeProtocol());
90
+ return this;
91
+ }
92
+ withUsernameProtocol() {
93
+ this.protocols.push(new USyncUsernameProtocol());
94
+ return this;
95
+ }
96
+ }
97
+ module.exports = { USyncQuery: USyncQuery };
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class USyncUser {
4
+ withId(id) {
5
+ this.id = id;
6
+ return this;
7
+ }
8
+ withLid(lid) {
9
+ this.lid = lid;
10
+ return this;
11
+ }
12
+ withPhone(phone) {
13
+ this.phone = phone;
14
+ return this;
15
+ }
16
+ withUsername(username) {
17
+ this.username = username;
18
+ return this;
19
+ }
20
+ withUsernameKey(usernameKey) {
21
+ this.usernameKey = usernameKey;
22
+ return this;
23
+ }
24
+ withType(type) {
25
+ this.type = type;
26
+ return this;
27
+ }
28
+ withPersonaId(personaId) {
29
+ this.personaId = personaId;
30
+ return this;
31
+ }
32
+ }
33
+ module.exports = { USyncUser: USyncUser };
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ const __createBinding =
3
+ (this && this.__createBinding) ||
4
+ (Object.create
5
+ ? function (o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ let desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = {
10
+ enumerable: true,
11
+ get: function () {
12
+ return m[k];
13
+ },
14
+ };
15
+ }
16
+ Object.defineProperty(o, k2, desc);
17
+ }
18
+ : function (o, m, k, k2) {
19
+ if (k2 === undefined) k2 = k;
20
+ o[k2] = m[k];
21
+ });
22
+ const __exportStar =
23
+ (this && this.__exportStar) ||
24
+ function (m, exports) {
25
+ for (var p in m) {
26
+ if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) {
27
+ __createBinding(exports, m, p);
28
+ }
29
+ }
30
+ };
31
+ Object.defineProperty(exports, "__esModule", { value: true });
32
+ __exportStar(require("./Protocols"), exports);
33
+ __exportStar(require("./USyncQuery"), exports);
34
+ __exportStar(require("./USyncUser"), exports);