dcodeindra-baileyspro 2.3.9

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 (286) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2534 -0
  3. package/WAProto/Adv/Adv.d.ts +518 -0
  4. package/WAProto/Adv/Adv.js +1734 -0
  5. package/WAProto/Adv/Adv.proto +36 -0
  6. package/WAProto/BotMetadata/BotMetadata.d.ts +5745 -0
  7. package/WAProto/BotMetadata/BotMetadata.js +16291 -0
  8. package/WAProto/BotMetadata/BotMetadata.proto +463 -0
  9. package/WAProto/Cert/Cert.d.ts +497 -0
  10. package/WAProto/Cert/Cert.js +1503 -0
  11. package/WAProto/Cert/Cert.proto +28 -0
  12. package/WAProto/ChatLockSettings/ChatLockSettings.d.ts +391 -0
  13. package/WAProto/ChatLockSettings/ChatLockSettings.js +1155 -0
  14. package/WAProto/ChatLockSettings/ChatLockSettings.proto +7 -0
  15. package/WAProto/CompanionReg/CompanionReg.d.ts +1055 -0
  16. package/WAProto/CompanionReg/CompanionReg.js +3532 -0
  17. package/WAProto/CompanionReg/CompanionReg.proto +89 -0
  18. package/WAProto/DeviceCapabilities/DeviceCapabilities.d.ts +187 -0
  19. package/WAProto/DeviceCapabilities/DeviceCapabilities.js +520 -0
  20. package/WAProto/DeviceCapabilities/DeviceCapabilities.proto +14 -0
  21. package/WAProto/E2E/E2E.d.ts +28417 -0
  22. package/WAProto/E2E/E2E.js +98438 -0
  23. package/WAProto/E2E/E2E.proto +2289 -0
  24. package/WAProto/Ephemeral/Ephemeral.d.ts +95 -0
  25. package/WAProto/Ephemeral/Ephemeral.js +269 -0
  26. package/WAProto/Ephemeral/Ephemeral.proto +6 -0
  27. package/WAProto/HistorySync/HistorySync.d.ts +40728 -0
  28. package/WAProto/HistorySync/HistorySync.js +142980 -0
  29. package/WAProto/HistorySync/HistorySync.proto +207 -0
  30. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.d.ts +189 -0
  31. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.js +585 -0
  32. package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.proto +11 -0
  33. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.d.ts +461 -0
  34. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.js +1559 -0
  35. package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.proto +37 -0
  36. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +29294 -0
  37. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +101732 -0
  38. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.proto +76 -0
  39. package/WAProto/MmsRetry/MmsRetry.d.ts +200 -0
  40. package/WAProto/MmsRetry/MmsRetry.js +586 -0
  41. package/WAProto/MmsRetry/MmsRetry.proto +17 -0
  42. package/WAProto/Protocol/Protocol.d.ts +218 -0
  43. package/WAProto/Protocol/Protocol.js +701 -0
  44. package/WAProto/Protocol/Protocol.proto +20 -0
  45. package/WAProto/Reporting/Reporting.d.ts +301 -0
  46. package/WAProto/Reporting/Reporting.js +989 -0
  47. package/WAProto/Reporting/Reporting.proto +19 -0
  48. package/WAProto/ServerSync/ServerSync.d.ts +1050 -0
  49. package/WAProto/ServerSync/ServerSync.js +3176 -0
  50. package/WAProto/ServerSync/ServerSync.proto +59 -0
  51. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.d.ts +1507 -0
  52. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.js +4756 -0
  53. package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.proto +88 -0
  54. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.d.ts +617 -0
  55. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.js +1940 -0
  56. package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.proto +38 -0
  57. package/WAProto/StatusAttributions/StatusAttributions.d.ts +636 -0
  58. package/WAProto/StatusAttributions/StatusAttributions.js +2037 -0
  59. package/WAProto/StatusAttributions/StatusAttributions.proto +61 -0
  60. package/WAProto/SyncAction/SyncAction.d.ts +7227 -0
  61. package/WAProto/SyncAction/SyncAction.js +22271 -0
  62. package/WAProto/SyncAction/SyncAction.proto +423 -0
  63. package/WAProto/UserPassword/UserPassword.d.ts +298 -0
  64. package/WAProto/UserPassword/UserPassword.js +898 -0
  65. package/WAProto/UserPassword/UserPassword.proto +27 -0
  66. package/WAProto/VnameCert/VnameCert.d.ts +658 -0
  67. package/WAProto/VnameCert/VnameCert.js +2225 -0
  68. package/WAProto/VnameCert/VnameCert.proto +60 -0
  69. package/WAProto/Wa6/Wa6.d.ts +1613 -0
  70. package/WAProto/Wa6/Wa6.js +6299 -0
  71. package/WAProto/Wa6/Wa6.proto +229 -0
  72. package/WAProto/Web/Web.d.ts +31718 -0
  73. package/WAProto/Web/Web.js +113402 -0
  74. package/WAProto/Web/Web.proto +545 -0
  75. package/WAProto/index.d.ts +49 -0
  76. package/WAProto/index.js +28 -0
  77. package/WASignalGroup/GroupProtocol.js +1771 -0
  78. package/WASignalGroup/ciphertext_message.js +10 -0
  79. package/WASignalGroup/group_cipher.js +103 -0
  80. package/WASignalGroup/group_session_builder.js +39 -0
  81. package/WASignalGroup/index.js +5 -0
  82. package/WASignalGroup/keyhelper.js +17 -0
  83. package/WASignalGroup/protobufs.js +2 -0
  84. package/WASignalGroup/queue_job.js +64 -0
  85. package/WASignalGroup/sender_chain_key.js +38 -0
  86. package/WASignalGroup/sender_key_distribution_message.js +68 -0
  87. package/WASignalGroup/sender_key_message.js +79 -0
  88. package/WASignalGroup/sender_key_name.js +59 -0
  89. package/WASignalGroup/sender_key_record.js +47 -0
  90. package/WASignalGroup/sender_key_state.js +110 -0
  91. package/WASignalGroup/sender_message_key.js +30 -0
  92. package/check-node-version.js +10 -0
  93. package/lib/Defaults/baileys-version.json +3 -0
  94. package/lib/Defaults/index.d.ts +51 -0
  95. package/lib/Defaults/index.js +108 -0
  96. package/lib/Defaults/phonenumber-mcc.json +223 -0
  97. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  98. package/lib/Signal/Group/ciphertext-message.js +19 -0
  99. package/lib/Signal/Group/group-session-builder.d.ts +17 -0
  100. package/lib/Signal/Group/group-session-builder.js +72 -0
  101. package/lib/Signal/Group/group_cipher.d.ts +19 -0
  102. package/lib/Signal/Group/group_cipher.js +99 -0
  103. package/lib/Signal/Group/index.d.ts +11 -0
  104. package/lib/Signal/Group/index.js +61 -0
  105. package/lib/Signal/Group/keyhelper.d.ts +16 -0
  106. package/lib/Signal/Group/keyhelper.js +66 -0
  107. package/lib/Signal/Group/queue-job.d.ts +1 -0
  108. package/lib/Signal/Group/queue-job.js +64 -0
  109. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  110. package/lib/Signal/Group/sender-chain-key.js +39 -0
  111. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  112. package/lib/Signal/Group/sender-key-distribution-message.js +71 -0
  113. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  114. package/lib/Signal/Group/sender-key-message.js +73 -0
  115. package/lib/Signal/Group/sender-key-name.d.ts +19 -0
  116. package/lib/Signal/Group/sender-key-name.js +59 -0
  117. package/lib/Signal/Group/sender-key-record.d.ts +32 -0
  118. package/lib/Signal/Group/sender-key-record.js +53 -0
  119. package/lib/Signal/Group/sender-key-record.ts +77 -0
  120. package/lib/Signal/Group/sender-key-state.d.ts +44 -0
  121. package/lib/Signal/Group/sender-key-state.js +104 -0
  122. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  123. package/lib/Signal/Group/sender-message-key.js +33 -0
  124. package/lib/Signal/libsignal.d.ts +3 -0
  125. package/lib/Signal/libsignal.js +153 -0
  126. package/lib/Socket/Client/index.d.ts +2 -0
  127. package/lib/Socket/Client/index.js +18 -0
  128. package/lib/Socket/Client/types.d.ts +15 -0
  129. package/lib/Socket/Client/types.js +14 -0
  130. package/lib/Socket/Client/websocket.d.ts +12 -0
  131. package/lib/Socket/Client/websocket.js +57 -0
  132. package/lib/Socket/business.d.ts +181 -0
  133. package/lib/Socket/business.js +259 -0
  134. package/lib/Socket/chats.d.ts +95 -0
  135. package/lib/Socket/chats.js +906 -0
  136. package/lib/Socket/community.d.ts +131 -0
  137. package/lib/Socket/community.js +369 -0
  138. package/lib/Socket/groups.d.ts +122 -0
  139. package/lib/Socket/groups.js +360 -0
  140. package/lib/Socket/index.d.ts +183 -0
  141. package/lib/Socket/index.js +10 -0
  142. package/lib/Socket/messages-recv.d.ts +170 -0
  143. package/lib/Socket/messages-recv.js +1074 -0
  144. package/lib/Socket/messages-send.d.ts +161 -0
  145. package/lib/Socket/messages-send.js +982 -0
  146. package/lib/Socket/newsletter.d.ts +140 -0
  147. package/lib/Socket/newsletter.js +242 -0
  148. package/lib/Socket/socket.d.ts +43 -0
  149. package/lib/Socket/socket.js +749 -0
  150. package/lib/Socket/usync.d.ts +36 -0
  151. package/lib/Socket/usync.js +71 -0
  152. package/lib/Store/index.d.ts +4 -0
  153. package/lib/Store/index.js +20 -0
  154. package/lib/Store/make-cache-manager-store.d.ts +13 -0
  155. package/lib/Store/make-cache-manager-store.js +77 -0
  156. package/lib/Store/make-in-memory-store.d.ts +117 -0
  157. package/lib/Store/make-in-memory-store.js +420 -0
  158. package/lib/Store/make-ordered-dictionary.d.ts +12 -0
  159. package/lib/Store/make-ordered-dictionary.js +83 -0
  160. package/lib/Store/object-repository.d.ts +10 -0
  161. package/lib/Store/object-repository.js +28 -0
  162. package/lib/Types/Auth.d.ts +103 -0
  163. package/lib/Types/Auth.js +2 -0
  164. package/lib/Types/Call.d.ts +13 -0
  165. package/lib/Types/Call.js +2 -0
  166. package/lib/Types/Chat.d.ts +115 -0
  167. package/lib/Types/Chat.js +6 -0
  168. package/lib/Types/Contact.d.ts +35 -0
  169. package/lib/Types/Contact.js +2 -0
  170. package/lib/Types/Events.d.ts +208 -0
  171. package/lib/Types/Events.js +2 -0
  172. package/lib/Types/GroupMetadata.d.ts +81 -0
  173. package/lib/Types/GroupMetadata.js +2 -0
  174. package/lib/Types/Label.d.ts +46 -0
  175. package/lib/Types/Label.js +28 -0
  176. package/lib/Types/LabelAssociation.d.ts +29 -0
  177. package/lib/Types/LabelAssociation.js +10 -0
  178. package/lib/Types/Message.d.ts +480 -0
  179. package/lib/Types/Message.js +9 -0
  180. package/lib/Types/MexUpdates.d.ts +9 -0
  181. package/lib/Types/MexUpdates.js +18 -0
  182. package/lib/Types/Newsletter.d.ts +92 -0
  183. package/lib/Types/Newsletter.js +33 -0
  184. package/lib/Types/Product.d.ts +78 -0
  185. package/lib/Types/Product.js +2 -0
  186. package/lib/Types/Signal.d.ts +57 -0
  187. package/lib/Types/Signal.js +2 -0
  188. package/lib/Types/Socket.d.ts +116 -0
  189. package/lib/Types/Socket.js +2 -0
  190. package/lib/Types/State.d.ts +27 -0
  191. package/lib/Types/State.js +2 -0
  192. package/lib/Types/USync.d.ts +25 -0
  193. package/lib/Types/USync.js +2 -0
  194. package/lib/Types/index.d.ts +70 -0
  195. package/lib/Types/index.js +42 -0
  196. package/lib/Utils/auth-utils.d.ts +18 -0
  197. package/lib/Utils/auth-utils.js +198 -0
  198. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  199. package/lib/Utils/baileys-event-stream.js +64 -0
  200. package/lib/Utils/business.d.ts +22 -0
  201. package/lib/Utils/business.js +243 -0
  202. package/lib/Utils/chat-utils.d.ts +72 -0
  203. package/lib/Utils/chat-utils.js +762 -0
  204. package/lib/Utils/crypto.d.ts +40 -0
  205. package/lib/Utils/crypto.js +150 -0
  206. package/lib/Utils/decode-wa-message.d.ts +252 -0
  207. package/lib/Utils/decode-wa-message.js +232 -0
  208. package/lib/Utils/event-buffer.d.ts +35 -0
  209. package/lib/Utils/event-buffer.js +539 -0
  210. package/lib/Utils/generics.d.ts +96 -0
  211. package/lib/Utils/generics.js +553 -0
  212. package/lib/Utils/history.d.ts +29 -0
  213. package/lib/Utils/history.js +109 -0
  214. package/lib/Utils/index.d.ts +19 -0
  215. package/lib/Utils/index.js +35 -0
  216. package/lib/Utils/link-preview.d.ts +21 -0
  217. package/lib/Utils/link-preview.js +112 -0
  218. package/lib/Utils/logger.d.ts +11 -0
  219. package/lib/Utils/logger.js +7 -0
  220. package/lib/Utils/lt-hash.d.ts +12 -0
  221. package/lib/Utils/lt-hash.js +53 -0
  222. package/lib/Utils/make-mutex.d.ts +7 -0
  223. package/lib/Utils/make-mutex.js +45 -0
  224. package/lib/Utils/messages-media.d.ts +104 -0
  225. package/lib/Utils/messages-media.js +751 -0
  226. package/lib/Utils/messages.d.ts +80 -0
  227. package/lib/Utils/messages.js +1741 -0
  228. package/lib/Utils/noise-handler.d.ts +19 -0
  229. package/lib/Utils/noise-handler.js +150 -0
  230. package/lib/Utils/process-message.d.ts +41 -0
  231. package/lib/Utils/process-message.js +391 -0
  232. package/lib/Utils/signal.d.ts +33 -0
  233. package/lib/Utils/signal.js +154 -0
  234. package/lib/Utils/use-mongo-file-auth-state.d.ts +5 -0
  235. package/lib/Utils/use-mongo-file-auth-state.js +75 -0
  236. package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
  237. package/lib/Utils/use-multi-file-auth-state.js +123 -0
  238. package/lib/Utils/use-single-file-auth-state.d.ts +12 -0
  239. package/lib/Utils/use-single-file-auth-state.js +75 -0
  240. package/lib/Utils/validate-connection.d.ts +10 -0
  241. package/lib/Utils/validate-connection.js +174 -0
  242. package/lib/WABinary/constants.d.ts +27 -0
  243. package/lib/WABinary/constants.js +45 -0
  244. package/lib/WABinary/decode.d.ts +6 -0
  245. package/lib/WABinary/decode.js +255 -0
  246. package/lib/WABinary/encode.d.ts +2 -0
  247. package/lib/WABinary/encode.js +243 -0
  248. package/lib/WABinary/generic-utils.d.ts +16 -0
  249. package/lib/WABinary/generic-utils.js +125 -0
  250. package/lib/WABinary/index.d.ts +5 -0
  251. package/lib/WABinary/index.js +21 -0
  252. package/lib/WABinary/jid-utils.d.ts +34 -0
  253. package/lib/WABinary/jid-utils.js +73 -0
  254. package/lib/WABinary/types.d.ts +18 -0
  255. package/lib/WABinary/types.js +2 -0
  256. package/lib/WAM/BinaryInfo.d.ts +16 -0
  257. package/lib/WAM/BinaryInfo.js +14 -0
  258. package/lib/WAM/constants.d.ts +39 -0
  259. package/lib/WAM/constants.js +15362 -0
  260. package/lib/WAM/encode.d.ts +2 -0
  261. package/lib/WAM/encode.js +156 -0
  262. package/lib/WAM/index.d.ts +3 -0
  263. package/lib/WAM/index.js +19 -0
  264. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +25 -0
  265. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +60 -0
  266. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  267. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  268. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  269. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +58 -0
  270. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  271. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +31 -0
  272. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +8 -0
  273. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +26 -0
  274. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  275. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  276. package/lib/WAUSync/Protocols/index.d.ts +6 -0
  277. package/lib/WAUSync/Protocols/index.js +22 -0
  278. package/lib/WAUSync/USyncQuery.d.ts +28 -0
  279. package/lib/WAUSync/USyncQuery.js +88 -0
  280. package/lib/WAUSync/USyncUser.d.ts +12 -0
  281. package/lib/WAUSync/USyncUser.js +27 -0
  282. package/lib/WAUSync/index.d.ts +3 -0
  283. package/lib/WAUSync/index.js +19 -0
  284. package/lib/index.d.ts +13 -0
  285. package/lib/index.js +45 -0
  286. package/package.json +63 -0
@@ -0,0 +1,2 @@
1
+ import { BinaryInfo } from './BinaryInfo'
2
+ export declare const encodeWAM: (binaryInfo: BinaryInfo) => Buffer
@@ -0,0 +1,156 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", { value: true })
3
+ const constants_1 = require("./constants")
4
+ const getHeaderBitLength = (key) => (key < 256 ? 2 : 3)
5
+ const encodeWAM = (binaryInfo) => {
6
+ binaryInfo.buffer = []
7
+ encodeWAMHeader(binaryInfo)
8
+ encodeEvents(binaryInfo)
9
+ console.log(binaryInfo.buffer)
10
+ const totalSize = binaryInfo.buffer
11
+ .map((a) => a.length)
12
+ .reduce((a, b) => a + b)
13
+ const buffer = Buffer.alloc(totalSize)
14
+ let offset = 0
15
+ for (const buffer_ of binaryInfo.buffer) {
16
+ buffer_.copy(buffer, offset)
17
+ offset += buffer_.length
18
+ }
19
+ return buffer
20
+ }
21
+ function encodeWAMHeader(binaryInfo) {
22
+ const headerBuffer = Buffer.alloc(8) // starting buffer
23
+ headerBuffer.write('WAM', 0, 'utf8')
24
+ headerBuffer.writeUInt8(binaryInfo.protocolVersion, 3)
25
+ headerBuffer.writeUInt8(1, 4) //random flag
26
+ headerBuffer.writeUInt16BE(binaryInfo.sequence, 5)
27
+ headerBuffer.writeUInt8(0, 7) // regular channel
28
+ binaryInfo.buffer.push(headerBuffer)
29
+ }
30
+ function encodeGlobalAttributes(binaryInfo, globals) {
31
+ for (const [key, _value] of Object.entries(globals)) {
32
+ const id = constants_1.WEB_GLOBALS.find(a => a?.name === key)?.id
33
+ let value = _value
34
+ if (typeof value === 'boolean') {
35
+ value = value ? 1 : 0
36
+ }
37
+ binaryInfo.buffer.push(serializeData(id, value, constants_1.FLAG_GLOBAL))
38
+ }
39
+ }
40
+ function encodeEvents(binaryInfo) {
41
+ for (const [name, { props, globals },] of binaryInfo.events.map((a) => Object.entries(a)[0])) {
42
+ encodeGlobalAttributes(binaryInfo, globals)
43
+ const event = constants_1.WEB_EVENTS.find((a) => a.name === name)
44
+ const props_ = Object.entries(props)
45
+ let extended = false
46
+ for (const [, value] of props_) {
47
+ extended || (extended = value !== null)
48
+ }
49
+ const eventFlag = extended ? constants_1.FLAG_EVENT : constants_1.FLAG_EVENT | constants_1.FLAG_EXTENDED
50
+ binaryInfo.buffer.push(serializeData(event.id, -event.weight, eventFlag))
51
+ for (let i = 0; i < props_.length; i++) {
52
+ const [key, _value] = props_[i]
53
+ const id = (event.props)[key][0]
54
+ extended = i < (props_.length - 1)
55
+ let value = _value
56
+ if (typeof value === 'boolean') {
57
+ value = value ? 1 : 0
58
+ }
59
+ const fieldFlag = extended ? constants_1.FLAG_EVENT : constants_1.FLAG_FIELD | constants_1.FLAG_EXTENDED
60
+ binaryInfo.buffer.push(serializeData(id, value, fieldFlag))
61
+ }
62
+ }
63
+ }
64
+ function serializeData(key, value, flag) {
65
+ const bufferLength = getHeaderBitLength(key)
66
+ let buffer
67
+ let offset = 0
68
+ if (value === null) {
69
+ if (flag === constants_1.FLAG_GLOBAL) {
70
+ buffer = Buffer.alloc(bufferLength)
71
+ offset = serializeHeader(buffer, offset, key, flag)
72
+ return buffer
73
+ }
74
+ }
75
+ else if (typeof value === 'number' && Number.isInteger(value)) {
76
+ // is number
77
+ if (value === 0 || value === 1) {
78
+ buffer = Buffer.alloc(bufferLength)
79
+ offset = serializeHeader(buffer, offset, key, flag | ((value + 1) << 4))
80
+ return buffer
81
+ }
82
+ else if (-128 <= value && value < 128) {
83
+ buffer = Buffer.alloc(bufferLength + 1)
84
+ offset = serializeHeader(buffer, offset, key, flag | (3 << 4))
85
+ buffer.writeInt8(value, offset)
86
+ return buffer
87
+ }
88
+ else if (-32768 <= value && value < 32768) {
89
+ buffer = Buffer.alloc(bufferLength + 2)
90
+ offset = serializeHeader(buffer, offset, key, flag | (4 << 4))
91
+ buffer.writeInt16LE(value, offset)
92
+ return buffer
93
+ }
94
+ else if (-2147483648 <= value && value < 2147483648) {
95
+ buffer = Buffer.alloc(bufferLength + 4)
96
+ offset = serializeHeader(buffer, offset, key, flag | (5 << 4))
97
+ buffer.writeInt32LE(value, offset)
98
+ return buffer
99
+ }
100
+ else {
101
+ buffer = Buffer.alloc(bufferLength + 8)
102
+ offset = serializeHeader(buffer, offset, key, flag | (7 << 4))
103
+ buffer.writeDoubleLE(value, offset)
104
+ return buffer
105
+ }
106
+ }
107
+ else if (typeof value === 'number') {
108
+ // is float
109
+ buffer = Buffer.alloc(bufferLength + 8)
110
+ offset = serializeHeader(buffer, offset, key, flag | (7 << 4))
111
+ buffer.writeDoubleLE(value, offset)
112
+ return buffer
113
+ }
114
+ else if (typeof value === 'string') {
115
+ // is string
116
+ const utf8Bytes = Buffer.byteLength(value, 'utf8')
117
+ if (utf8Bytes < 256) {
118
+ buffer = Buffer.alloc(bufferLength + 1 + utf8Bytes)
119
+ offset = serializeHeader(buffer, offset, key, flag | (8 << 4))
120
+ buffer.writeUint8(utf8Bytes, offset++)
121
+ }
122
+ else if (utf8Bytes < 65536) {
123
+ buffer = Buffer.alloc(bufferLength + 2 + utf8Bytes)
124
+ offset = serializeHeader(buffer, offset, key, flag | (9 << 4))
125
+ buffer.writeUInt16LE(utf8Bytes, offset)
126
+ offset += 2
127
+ }
128
+ else {
129
+ buffer = Buffer.alloc(bufferLength + 4 + utf8Bytes)
130
+ offset = serializeHeader(buffer, offset, key, flag | (10 << 4))
131
+ buffer.writeUInt32LE(utf8Bytes, offset)
132
+ offset += 4
133
+ }
134
+ buffer.write(value, offset, 'utf8')
135
+ return buffer
136
+ }
137
+ throw 'missing'
138
+ }
139
+ function serializeHeader(buffer, offset, key, flag) {
140
+ if (key < 256) {
141
+ buffer.writeUInt8(flag, offset)
142
+ offset += 1
143
+ buffer.writeUInt8(key, offset)
144
+ offset += 1
145
+ }
146
+ else {
147
+ buffer.writeUInt8(flag | constants_1.FLAG_BYTE, offset)
148
+ offset += 1
149
+ buffer.writeUInt16LE(key, offset)
150
+ offset += 2
151
+ }
152
+ return offset
153
+ }
154
+ module.exports = {
155
+ encodeWAM
156
+ }
@@ -0,0 +1,3 @@
1
+ export * from './constants'
2
+ export * from './encode'
3
+ export * from './BinaryInfo'
@@ -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("./constants"), exports)
18
+ __exportStar(require("./encode"), exports)
19
+ __exportStar(require("./BinaryInfo"), exports)
@@ -0,0 +1,25 @@
1
+ import { USyncQueryProtocol } from '../../Types/USync'
2
+ import { BinaryNode } from '../../WABinary'
3
+ import { USyncUser } from '../USyncUser'
4
+ export type BotProfileCommand = {
5
+ name: string
6
+ description: string
7
+ }
8
+ export type BotProfileInfo = {
9
+ jid: string
10
+ name: string
11
+ attributes: string
12
+ description: string
13
+ category: string
14
+ isDefault: boolean
15
+ prompts: string[]
16
+ personaId: string
17
+ commands: BotProfileCommand[]
18
+ commandsDescription: string
19
+ }
20
+ export declare class USyncBotProfileProtocol implements USyncQueryProtocol {
21
+ name: string
22
+ getQueryElement(): BinaryNode
23
+ getUserElement(user: USyncUser): BinaryNode
24
+ parser(node: BinaryNode): BotProfileInfo | undefined
25
+ }
@@ -0,0 +1,60 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", { value: true })
3
+ const WABinary_1 = require("../../WABinary")
4
+ class USyncBotProfileProtocol {
5
+ constructor() {
6
+ this.name = 'bot'
7
+ }
8
+ getQueryElement() {
9
+ return {
10
+ tag: 'bot',
11
+ attrs: {},
12
+ content: [{ tag: 'profile', attrs: { v: '1' } }]
13
+ }
14
+ }
15
+ getUserElement(user) {
16
+ return {
17
+ tag: 'bot',
18
+ attrs: {},
19
+ content: [{ tag: 'profile', attrs: { 'persona_id': user.personaId } }]
20
+ }
21
+ }
22
+ parser(node) {
23
+ const botNode = WABinary_1.getBinaryNodeChild(node, 'bot')
24
+ const profile = WABinary_1.getBinaryNodeChild(botNode, 'profile')
25
+ const commandsNode = WABinary_1.getBinaryNodeChild(profile, 'commands')
26
+ const promptsNode = WABinary_1.getBinaryNodeChild(profile, 'prompts')
27
+ const commands = []
28
+ const prompts = []
29
+ if (commandsNode) {
30
+ for (const command of WABinary_1.getBinaryNodeChildren(commandsNode, 'command')) {
31
+ commands.push({
32
+ name: WABinary_1.getBinaryNodeChildString(command, 'name') || '',
33
+ description: WABinary_1.getBinaryNodeChildString(command, 'description') || ''
34
+ })
35
+ }
36
+ }
37
+ if (promptsNode) {
38
+ for (const prompt of WABinary_1.getBinaryNodeChildren(promptsNode, 'prompt')) {
39
+ prompts.push(
40
+ `${WABinary_1.getBinaryNodeChildString(prompt, 'emoji') || ''} ${WABinary_1.getBinaryNodeChildString(prompt, 'text') || ''}`
41
+ )
42
+ }
43
+ }
44
+ return {
45
+ isDefault: !!WABinary_1.getBinaryNodeChild(profile, 'default'),
46
+ jid: node.attrs.jid,
47
+ name: WABinary_1.getBinaryNodeChildString(profile, 'name') || '',
48
+ attributes: WABinary_1.getBinaryNodeChildString(profile, 'attributes') || '',
49
+ description: WABinary_1.getBinaryNodeChildString(profile, 'description') || '',
50
+ category: WABinary_1.getBinaryNodeChildString(profile, 'category') || '',
51
+ personaId: profile.attrs['persona_id'] || '',
52
+ commandsDescription: WABinary_1.getBinaryNodeChildString(commandsNode, 'description') || '',
53
+ commands,
54
+ prompts
55
+ }
56
+ }
57
+ }
58
+ module.exports = {
59
+ USyncBotProfileProtocol
60
+ }
@@ -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
+ const WABinary_1 = require("../../WABinary")
4
+ class USyncContactProtocol {
5
+ constructor() {
6
+ this.name = 'contact'
7
+ }
8
+ getQueryElement() {
9
+ return {
10
+ tag: 'contact',
11
+ attrs: {},
12
+ }
13
+ }
14
+ getUserElement(user) {
15
+ //TODO: Implement type / username fields (not yet supported)
16
+ return {
17
+ tag: 'contact',
18
+ attrs: {},
19
+ content: user.phone,
20
+ }
21
+ }
22
+ parser(node) {
23
+ if (node.tag === 'contact') {
24
+ WABinary_1.assertNodeErrorFree(node)
25
+ return node?.attrs?.type === 'in'
26
+ }
27
+ return false
28
+ }
29
+ }
30
+ module.exports = {
31
+ USyncContactProtocol
32
+ }
@@ -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,58 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", { value: true })
3
+ const WABinary_1 = require("../../WABinary")
4
+ class USyncDeviceProtocol {
5
+ constructor() {
6
+ this.name = 'devices'
7
+ }
8
+ getQueryElement() {
9
+ return {
10
+ tag: 'devices',
11
+ attrs: {
12
+ version: '2',
13
+ },
14
+ }
15
+ }
16
+ getUserElement( /* user: USyncUser */) {
17
+ //TODO: Implement device phashing, ts and expectedTs
18
+ //TODO: if all are not present, return null <- current behavior
19
+ //TODO: otherwise return a node w tag 'devices' w those as attrs
20
+ return null
21
+ }
22
+ parser(node) {
23
+ const deviceList = []
24
+ let keyIndex = undefined
25
+ if (node.tag === 'devices') {
26
+ WABinary_1.assertNodeErrorFree(node)
27
+ const deviceListNode = WABinary_1.getBinaryNodeChild(node, 'device-list')
28
+ const keyIndexNode = WABinary_1.getBinaryNodeChild(node, 'key-index-list')
29
+ if (Array.isArray(deviceListNode?.content)) {
30
+ for (const { tag, attrs } of deviceListNode.content) {
31
+ const id = +attrs.id
32
+ const keyIndex = +attrs['key-index']
33
+ if (tag === 'device') {
34
+ deviceList.push({
35
+ id,
36
+ keyIndex,
37
+ isHosted: !!(attrs['is_hosted'] && attrs['is_hosted'] === 'true')
38
+ })
39
+ }
40
+ }
41
+ }
42
+ if (keyIndexNode?.tag === 'key-index-list') {
43
+ keyIndex = {
44
+ timestamp: +keyIndexNode.attrs['ts'],
45
+ signedKeyIndex: keyIndexNode?.content,
46
+ expectedTimestamp: keyIndexNode.attrs['expected_ts'] ? +keyIndexNode.attrs['expected_ts'] : undefined
47
+ }
48
+ }
49
+ }
50
+ return {
51
+ deviceList,
52
+ keyIndex
53
+ }
54
+ }
55
+ }
56
+ module.exports = {
57
+ USyncDeviceProtocol
58
+ }
@@ -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,31 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", { value: true })
3
+ const WABinary_1 = require("../../WABinary")
4
+ class USyncDisappearingModeProtocol {
5
+ constructor() {
6
+ this.name = 'disappearing_mode'
7
+ }
8
+ getQueryElement() {
9
+ return {
10
+ tag: 'disappearing_mode',
11
+ attrs: {},
12
+ }
13
+ }
14
+ getUserElement() {
15
+ return null
16
+ }
17
+ parser(node) {
18
+ if (node.tag === 'status') {
19
+ WABinary_1.assertNodeErrorFree(node)
20
+ const duration = +node?.attrs?.duration
21
+ const setAt = new Date(+(node?.attrs?.t || 0) * 1000)
22
+ return {
23
+ duration,
24
+ setAt,
25
+ }
26
+ }
27
+ }
28
+ }
29
+ module.exports = {
30
+ USyncDisappearingModeProtocol
31
+ }
@@ -0,0 +1,8 @@
1
+ import { USyncQueryProtocol } from '../../Types/USync'
2
+ import { BinaryNode } from '../../WABinary'
3
+ export declare class USyncLIDProtocol implements USyncQueryProtocol {
4
+ name: string
5
+ getQueryElement(): BinaryNode
6
+ getUserElement(): null
7
+ parser(node: BinaryNode): string | null
8
+ }
@@ -0,0 +1,26 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", { value: true })
3
+ const WABinary_1 = require("../../WABinary")
4
+ class USyncLIDProtocol {
5
+ constructor() {
6
+ this.name = 'lid'
7
+ }
8
+ getQueryElement() {
9
+ return {
10
+ tag: 'lid',
11
+ attrs: {}
12
+ }
13
+ }
14
+ getUserElement() {
15
+ return null
16
+ }
17
+ parser(node) {
18
+ if (node.tag === 'lid') {
19
+ return node.attrs.val
20
+ }
21
+ return null
22
+ }
23
+ }
24
+ module.exports = {
25
+ USyncLIDProtocol
26
+ }
@@ -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
+ const WABinary_1 = require("../../WABinary")
4
+ class USyncStatusProtocol {
5
+ constructor() {
6
+ this.name = 'status'
7
+ }
8
+ getQueryElement() {
9
+ return {
10
+ tag: 'status',
11
+ attrs: {},
12
+ }
13
+ }
14
+ getUserElement() {
15
+ return null
16
+ }
17
+ parser(node) {
18
+ if (node.tag === 'status') {
19
+ WABinary_1.assertNodeErrorFree(node)
20
+ let status = node?.content?.toString() || null
21
+ const setAt = new Date(+(node?.attrs?.t || 0) * 1000)
22
+ if (!status) {
23
+ if (+node.attrs?.code === 401) {
24
+ status = ''
25
+ }
26
+ else {
27
+ status = null
28
+ }
29
+ }
30
+ else if (typeof status === 'string' && status.length === 0) {
31
+ status = null
32
+ }
33
+ return {
34
+ status,
35
+ setAt,
36
+ }
37
+ }
38
+ }
39
+ }
40
+ module.exports = {
41
+ USyncStatusProtocol
42
+ }
@@ -0,0 +1,6 @@
1
+ export * from './USyncBotProfileProtocol'
2
+ export * from './USyncContactProtocol'
3
+ export * from './USyncDeviceProtocol'
4
+ export * from './USyncLIDProtocol'
5
+ export * from './USyncStatusProtocol'
6
+ export * from './USyncDisappearingModeProtocol'
@@ -0,0 +1,22 @@
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("./USyncBotProfileProtocol"), exports)
18
+ __exportStar(require("./USyncContactProtocol"), exports)
19
+ __exportStar(require("./USyncDeviceProtocol"), exports)
20
+ __exportStar(require("./USyncLIDProtocol"), exports)
21
+ __exportStar(require("./USyncStatusProtocol"), exports)
22
+ __exportStar(require("./USyncDisappearingModeProtocol"), exports)
@@ -0,0 +1,28 @@
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
+ withLIDProtocol(): this
23
+ withDeviceProtocol(): this
24
+ withContactProtocol(): this
25
+ withStatusProtocol(): this
26
+ withBotProfileProtocol(): this
27
+ withDisappearingModeProtocol(): this
28
+ }
@@ -0,0 +1,88 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", { value: true })
3
+ const WABinary_1 = require("../WABinary")
4
+ const Protocols_1 = require("./Protocols")
5
+ class USyncQuery {
6
+ constructor() {
7
+ this.protocols = []
8
+ this.users = []
9
+ this.context = 'interactive'
10
+ this.mode = 'query'
11
+ }
12
+ withMode(mode) {
13
+ this.mode = mode
14
+ return this
15
+ }
16
+ withContext(context) {
17
+ this.context = context
18
+ return this
19
+ }
20
+ withUser(user) {
21
+ this.users.push(user)
22
+ return this
23
+ }
24
+ parseUSyncQueryResult(result) {
25
+ if (result.attrs.type !== 'result') {
26
+ return
27
+ }
28
+ const protocolMap = Object.fromEntries(this.protocols.map((protocol) => {
29
+ return [protocol.name, protocol.parser]
30
+ }))
31
+ const queryResult = {
32
+ // TODO: implement errors etc.
33
+ list: [],
34
+ sideList: [],
35
+ }
36
+ const usyncNode = WABinary_1.getBinaryNodeChild(result, 'usync')
37
+ //TODO: implement error backoff, refresh etc.
38
+ //TODO: see if there are any errors in the result node
39
+ //const resultNode = getBinaryNodeChild(usyncNode, 'result')
40
+ const listNode = WABinary_1.getBinaryNodeChild(usyncNode, 'list')
41
+ if (Array.isArray(listNode?.content) && typeof listNode !== 'undefined') {
42
+ queryResult.list = listNode.content.map((node) => {
43
+ const id = node?.attrs?.jid
44
+ const data = Array.isArray(node?.content) ? Object.fromEntries(node.content.map((content) => {
45
+ const protocol = content.tag
46
+ const parser = protocolMap[protocol]
47
+ if (parser) {
48
+ return [protocol, parser(content)]
49
+ }
50
+ else {
51
+ return [protocol, null]
52
+ }
53
+ }).filter(([, b]) => b !== null)) : {}
54
+ return { ...data, id }
55
+ })
56
+ }
57
+ //TODO: implement side list
58
+ //const sideListNode = getBinaryNodeChild(usyncNode, 'side_list')
59
+ return queryResult
60
+ }
61
+ withLIDProtocol() {
62
+ this.protocols.push(new Protocols_1.USyncLIDProtocol())
63
+ return this
64
+ }
65
+ withDeviceProtocol() {
66
+ this.protocols.push(new Protocols_1.USyncDeviceProtocol())
67
+ return this
68
+ }
69
+ withContactProtocol() {
70
+ this.protocols.push(new Protocols_1.USyncContactProtocol())
71
+ return this
72
+ }
73
+ withStatusProtocol() {
74
+ this.protocols.push(new Protocols_1.USyncStatusProtocol())
75
+ return this
76
+ }
77
+ withBotProfileProtocol() {
78
+ this.protocols.push(new Protocols_1.USyncBotProfileProtocol())
79
+ return this
80
+ }
81
+ withDisappearingModeProtocol() {
82
+ this.protocols.push(new Protocols_1.USyncDisappearingModeProtocol())
83
+ return this
84
+ }
85
+ }
86
+ module.exports = {
87
+ USyncQuery
88
+ }