@hiroosy/baileys-lite 0.3.3 → 0.3.5

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 (242) hide show
  1. package/WAProto/index.js +247 -113252
  2. package/WAProto/parts/ADVDeviceIdentity.part +201 -0
  3. package/WAProto/parts/ADVEncryptionType.part +6 -0
  4. package/WAProto/parts/ADVKeyIndexList.part +201 -0
  5. package/WAProto/parts/ADVSignedDeviceIdentity.part +150 -0
  6. package/WAProto/parts/ADVSignedDeviceIdentityHMAC.part +142 -0
  7. package/WAProto/parts/ADVSignedKeyIndexList.part +128 -0
  8. package/WAProto/parts/AIHomeState.part +405 -0
  9. package/WAProto/parts/AIMediaCollectionMessage.part +119 -0
  10. package/WAProto/parts/AIMediaCollectionMetadata.part +100 -0
  11. package/WAProto/parts/AIMetadataOperation.part +83 -0
  12. package/WAProto/parts/AIQueryFanout.part +133 -0
  13. package/WAProto/parts/AIRegenerateMetadata.part +112 -0
  14. package/WAProto/parts/AIRichResponseCodeMetadata.part +252 -0
  15. package/WAProto/parts/AIRichResponseContentItemsMetadata.part +354 -0
  16. package/WAProto/parts/AIRichResponseDynamicMetadata.part +172 -0
  17. package/WAProto/parts/AIRichResponseGridImageMetadata.part +114 -0
  18. package/WAProto/parts/AIRichResponseImageURL.part +119 -0
  19. package/WAProto/parts/AIRichResponseInlineImageMetadata.part +164 -0
  20. package/WAProto/parts/AIRichResponseLatexMetadata.part +346 -0
  21. package/WAProto/parts/AIRichResponseMapMetadata.part +346 -0
  22. package/WAProto/parts/AIRichResponseMessage.part +167 -0
  23. package/WAProto/parts/AIRichResponseMessageType.part +5 -0
  24. package/WAProto/parts/AIRichResponseSubMessage.part +313 -0
  25. package/WAProto/parts/AIRichResponseSubMessageType.part +13 -0
  26. package/WAProto/parts/AIRichResponseTableMetadata.part +223 -0
  27. package/WAProto/parts/AIRichResponseUnifiedResponse.part +84 -0
  28. package/WAProto/parts/AISubscriptionRequestType.part +7 -0
  29. package/WAProto/parts/AISubscriptionUpsellMetadata.part +102 -0
  30. package/WAProto/parts/AIThreadInfo.part +316 -0
  31. package/WAProto/parts/Account.part +138 -0
  32. package/WAProto/parts/ActionLink.part +100 -0
  33. package/WAProto/parts/AutoDownloadSettings.part +138 -0
  34. package/WAProto/parts/AvatarUserSettings.part +100 -0
  35. package/WAProto/parts/BizAccountLinkInfo.part +210 -0
  36. package/WAProto/parts/BizAccountPayload.part +105 -0
  37. package/WAProto/parts/BizIdentityInfo.part +298 -0
  38. package/WAProto/parts/BotAgeCollectionMetadata.part +138 -0
  39. package/WAProto/parts/BotAgentDeepLinkMetadata.part +81 -0
  40. package/WAProto/parts/BotAgentMetadata.part +83 -0
  41. package/WAProto/parts/BotCapabilityMetadata.part +437 -0
  42. package/WAProto/parts/BotCommandMetadata.part +119 -0
  43. package/WAProto/parts/BotDocumentMessageMetadata.part +100 -0
  44. package/WAProto/parts/BotFeedbackMessage.part +1366 -0
  45. package/WAProto/parts/BotGroupMetadata.part +92 -0
  46. package/WAProto/parts/BotGroupParticipantMetadata.part +81 -0
  47. package/WAProto/parts/BotImagineMetadata.part +134 -0
  48. package/WAProto/parts/BotInfrastructureDiagnostics.part +148 -0
  49. package/WAProto/parts/BotLinkedAccount.part +95 -0
  50. package/WAProto/parts/BotLinkedAccountsMetadata.part +134 -0
  51. package/WAProto/parts/BotMediaMetadata.part +229 -0
  52. package/WAProto/parts/BotMemoryFact.part +100 -0
  53. package/WAProto/parts/BotMemoryMetadata.part +141 -0
  54. package/WAProto/parts/BotMemuMetadata.part +92 -0
  55. package/WAProto/parts/BotMessageOrigin.part +95 -0
  56. package/WAProto/parts/BotMessageOriginMetadata.part +92 -0
  57. package/WAProto/parts/BotMessageSharingInfo.part +297 -0
  58. package/WAProto/parts/BotMetadata.part +934 -0
  59. package/WAProto/parts/BotMetricsEntryPoint.part +51 -0
  60. package/WAProto/parts/BotMetricsMetadata.part +341 -0
  61. package/WAProto/parts/BotMetricsThreadEntryPoint.part +8 -0
  62. package/WAProto/parts/BotModeSelectionMetadata.part +151 -0
  63. package/WAProto/parts/BotModelMetadata.part +167 -0
  64. package/WAProto/parts/BotPluginMetadata.part +379 -0
  65. package/WAProto/parts/BotProgressIndicatorMetadata.part +837 -0
  66. package/WAProto/parts/BotPromotionMessageMetadata.part +124 -0
  67. package/WAProto/parts/BotPromptSuggestion.part +100 -0
  68. package/WAProto/parts/BotPromptSuggestions.part +92 -0
  69. package/WAProto/parts/BotPttPromptMetadata.part +81 -0
  70. package/WAProto/parts/BotQuotaMetadata.part +241 -0
  71. package/WAProto/parts/BotReminderMetadata.part +232 -0
  72. package/WAProto/parts/BotRenderingConfigMetadata.part +100 -0
  73. package/WAProto/parts/BotRenderingMetadata.part +203 -0
  74. package/WAProto/parts/BotResolvedToolCallMetadata.part +100 -0
  75. package/WAProto/parts/BotSessionMetadata.part +137 -0
  76. package/WAProto/parts/BotSessionSource.part +11 -0
  77. package/WAProto/parts/BotSignatureVerificationMetadata.part +92 -0
  78. package/WAProto/parts/BotSignatureVerificationUseCaseProof.part +183 -0
  79. package/WAProto/parts/BotSourcesMetadata.part +322 -0
  80. package/WAProto/parts/BotSuggestedPromptMetadata.part +150 -0
  81. package/WAProto/parts/BotUnifiedResponseMutation.part +339 -0
  82. package/WAProto/parts/CallLogRecord.part +646 -0
  83. package/WAProto/parts/CertChain.part +392 -0
  84. package/WAProto/parts/ChatLockSettings.part +102 -0
  85. package/WAProto/parts/ChatRowOpaqueData.part +712 -0
  86. package/WAProto/parts/Citation.part +119 -0
  87. package/WAProto/parts/ClientPairingProps.part +160 -0
  88. package/WAProto/parts/ClientPayload.part +2892 -0
  89. package/WAProto/parts/CollectionName.part +9 -0
  90. package/WAProto/parts/CommentMetadata.part +102 -0
  91. package/WAProto/parts/CompanionCommitment.part +84 -0
  92. package/WAProto/parts/CompanionEphemeralIdentity.part +227 -0
  93. package/WAProto/parts/Config.part +136 -0
  94. package/WAProto/parts/ContextInfo.part +4137 -0
  95. package/WAProto/parts/Conversation.part +1472 -0
  96. package/WAProto/parts/DeviceCapabilities.part +670 -0
  97. package/WAProto/parts/DeviceConsistencyCodeMessage.part +103 -0
  98. package/WAProto/parts/DeviceListMetadata.part +306 -0
  99. package/WAProto/parts/DeviceProps.part +982 -0
  100. package/WAProto/parts/DisappearingMode.part +206 -0
  101. package/WAProto/parts/EmbeddedContent.part +100 -0
  102. package/WAProto/parts/EmbeddedMessage.part +102 -0
  103. package/WAProto/parts/EmbeddedMusic.part +370 -0
  104. package/WAProto/parts/EncryptedPairingRequest.part +106 -0
  105. package/WAProto/parts/EphemeralSetting.part +110 -0
  106. package/WAProto/parts/EventAdditionalMetadata.part +81 -0
  107. package/WAProto/parts/EventResponse.part +152 -0
  108. package/WAProto/parts/ExitCode.part +110 -0
  109. package/WAProto/parts/ExternalBlobReference.part +195 -0
  110. package/WAProto/parts/Field.part +193 -0
  111. package/WAProto/parts/ForwardedAIBotMessageInfo.part +119 -0
  112. package/WAProto/parts/GlobalSettings.part +497 -0
  113. package/WAProto/parts/GroupHistoryBundleInfo.part +141 -0
  114. package/WAProto/parts/GroupHistoryIndividualMessageInfo.part +102 -0
  115. package/WAProto/parts/GroupMention.part +100 -0
  116. package/WAProto/parts/GroupParticipant.part +142 -0
  117. package/WAProto/parts/GroupRootKeyShare.part +92 -0
  118. package/WAProto/parts/GroupRootKeyShareEntry.part +161 -0
  119. package/WAProto/parts/HandshakeMessage.part +815 -0
  120. package/WAProto/parts/HatchMetadataSync.part +132 -0
  121. package/WAProto/parts/HistorySync.part +605 -0
  122. package/WAProto/parts/HistorySyncMsg.part +112 -0
  123. package/WAProto/parts/HydratedTemplateButton.part +501 -0
  124. package/WAProto/parts/IdentityKeyPairStructure.part +106 -0
  125. package/WAProto/parts/InThreadSurveyMetadata.part +779 -0
  126. package/WAProto/parts/InlineContact.part +157 -0
  127. package/WAProto/parts/InteractiveAnnotation.part +246 -0
  128. package/WAProto/parts/InteractiveMessageAdditionalMetadata.part +81 -0
  129. package/WAProto/parts/KeepInChat.part +225 -0
  130. package/WAProto/parts/KeepType.part +6 -0
  131. package/WAProto/parts/KeyExchangeMessage.part +169 -0
  132. package/WAProto/parts/KeyId.part +84 -0
  133. package/WAProto/parts/LIDMigrationMapping.part +149 -0
  134. package/WAProto/parts/LIDMigrationMappingSyncMessage.part +84 -0
  135. package/WAProto/parts/LIDMigrationMappingSyncPayload.part +122 -0
  136. package/WAProto/parts/LegacyMessage.part +104 -0
  137. package/WAProto/parts/LimitSharing.part +177 -0
  138. package/WAProto/parts/LocalizedName.part +119 -0
  139. package/WAProto/parts/Location.part +119 -0
  140. package/WAProto/parts/MediaData.part +81 -0
  141. package/WAProto/parts/MediaDomainInfo.part +120 -0
  142. package/WAProto/parts/MediaKeyDomain.part +6 -0
  143. package/WAProto/parts/MediaNotifyMessage.part +132 -0
  144. package/WAProto/parts/MediaRetryNotification.part +170 -0
  145. package/WAProto/parts/MediaVisibility.part +6 -0
  146. package/WAProto/parts/MemberLabel.part +110 -0
  147. package/WAProto/parts/Message.part +32376 -0
  148. package/WAProto/parts/MessageAddOn.part +305 -0
  149. package/WAProto/parts/MessageAddOnContextInfo.part +113 -0
  150. package/WAProto/parts/MessageAssociation.part +235 -0
  151. package/WAProto/parts/MessageContextInfo.part +451 -0
  152. package/WAProto/parts/MessageKey.part +138 -0
  153. package/WAProto/parts/MessageSecretMessage.part +125 -0
  154. package/WAProto/parts/Money.part +129 -0
  155. package/WAProto/parts/MsgOpaqueData.part +1732 -0
  156. package/WAProto/parts/MsgRowOpaqueData.part +104 -0
  157. package/WAProto/parts/MutationProps.part +89 -0
  158. package/WAProto/parts/NoiseCertificate.part +277 -0
  159. package/WAProto/parts/NotificationMessageInfo.part +152 -0
  160. package/WAProto/parts/NotificationSettings.part +176 -0
  161. package/WAProto/parts/PairingRequest.part +128 -0
  162. package/WAProto/parts/PastParticipant.part +148 -0
  163. package/WAProto/parts/PastParticipants.part +112 -0
  164. package/WAProto/parts/PatchDebugData.part +358 -0
  165. package/WAProto/parts/PaymentBackground.part +460 -0
  166. package/WAProto/parts/PaymentInfo.part +602 -0
  167. package/WAProto/parts/PhoneNumberToLIDMapping.part +100 -0
  168. package/WAProto/parts/PhotoChange.part +125 -0
  169. package/WAProto/parts/PinInChat.part +205 -0
  170. package/WAProto/parts/Point.part +138 -0
  171. package/WAProto/parts/PollAdditionalMetadata.part +216 -0
  172. package/WAProto/parts/PollEncValue.part +106 -0
  173. package/WAProto/parts/PollUpdate.part +202 -0
  174. package/WAProto/parts/PreKeyRecordStructure.part +125 -0
  175. package/WAProto/parts/PreKeySignalMessage.part +185 -0
  176. package/WAProto/parts/PremiumMessageInfo.part +81 -0
  177. package/WAProto/parts/PrimaryEphemeralIdentity.part +106 -0
  178. package/WAProto/parts/PrivacySystemMessage.part +6 -0
  179. package/WAProto/parts/ProcessedVideo.part +266 -0
  180. package/WAProto/parts/ProloguePayload.part +105 -0
  181. package/WAProto/parts/Pushname.part +100 -0
  182. package/WAProto/parts/QuarantinedMessage.part +103 -0
  183. package/WAProto/parts/Reaction.part +169 -0
  184. package/WAProto/parts/RecentEmojiWeight.part +100 -0
  185. package/WAProto/parts/RecordStructure.part +114 -0
  186. package/WAProto/parts/Reportable.part +138 -0
  187. package/WAProto/parts/ReportingTokenInfo.part +84 -0
  188. package/WAProto/parts/ScheduledMessageMetadata.part +132 -0
  189. package/WAProto/parts/SenderKeyDistributionMessage.part +144 -0
  190. package/WAProto/parts/SenderKeyMessage.part +122 -0
  191. package/WAProto/parts/SenderKeyRecordStructure.part +92 -0
  192. package/WAProto/parts/SenderKeyStateStructure.part +469 -0
  193. package/WAProto/parts/ServerErrorReceipt.part +81 -0
  194. package/WAProto/parts/SessionStructure.part +1087 -0
  195. package/WAProto/parts/SessionTransparencyMetadata.part +132 -0
  196. package/WAProto/parts/SessionTransparencyType.part +5 -0
  197. package/WAProto/parts/SignalMessage.part +144 -0
  198. package/WAProto/parts/SignedPreKeyRecordStructure.part +176 -0
  199. package/WAProto/parts/StatusAttribution.part +1235 -0
  200. package/WAProto/parts/StatusMentionMessage.part +83 -0
  201. package/WAProto/parts/StatusPSA.part +121 -0
  202. package/WAProto/parts/StickerMetadata.part +357 -0
  203. package/WAProto/parts/SyncActionData.part +146 -0
  204. package/WAProto/parts/SyncActionValue.part +12959 -0
  205. package/WAProto/parts/SyncdIndex.part +84 -0
  206. package/WAProto/parts/SyncdMutation.part +121 -0
  207. package/WAProto/parts/SyncdMutations.part +92 -0
  208. package/WAProto/parts/SyncdPatch.part +262 -0
  209. package/WAProto/parts/SyncdRecord.part +125 -0
  210. package/WAProto/parts/SyncdSnapshot.part +157 -0
  211. package/WAProto/parts/SyncdValue.part +84 -0
  212. package/WAProto/parts/SyncdVersion.part +91 -0
  213. package/WAProto/parts/TapLinkAction.part +100 -0
  214. package/WAProto/parts/TemplateButton.part +449 -0
  215. package/WAProto/parts/ThreadID.part +126 -0
  216. package/WAProto/parts/UrlTrackingMap.part +231 -0
  217. package/WAProto/parts/UserPassword.part +399 -0
  218. package/WAProto/parts/UserReceipt.part +221 -0
  219. package/WAProto/parts/VerifiedNameCertificate.part +318 -0
  220. package/WAProto/parts/WallpaperSettings.part +119 -0
  221. package/WAProto/parts/WebFeatures.part +1870 -0
  222. package/WAProto/parts/WebLinkRenderConfig.part +5 -0
  223. package/WAProto/parts/WebMessageInfo.part +2851 -0
  224. package/WAProto/parts/WebNotificationsInfo.part +160 -0
  225. package/package.json +1 -1
  226. package/src/binary/wa-binary.js +4 -2
  227. package/src/defaults.js +2 -1
  228. package/src/foundation/cache.js +99 -24
  229. package/src/foundation/memory.js +103 -0
  230. package/src/signal/libsignal.js +1 -8
  231. package/src/signal/signal-repository.js +6 -4
  232. package/src/socket/chats.js +2 -0
  233. package/src/socket/messages-recv.js +5 -3
  234. package/src/socket/messages-send.js +2 -2
  235. package/src/socket/socket-core.js +3 -0
  236. package/src/utils/auth-state-core.js +2 -1
  237. package/src/utils/chat-sync.js +4 -0
  238. package/src/utils/media.js +13 -8
  239. package/src/utils/message-processing.js +22 -6
  240. package/src/utils/wa-protocol-core.js +6 -5
  241. package/src/wam/wam-constants.js +22 -22851
  242. package/src/wam/wam-data.json +1 -0
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ function WebNotificationsInfo(p) {
3
+ this.notifyMessages = [];
4
+ if (p)
5
+ for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
6
+ if (p[ks[i]] != null && ks[i] !== "__proto__")
7
+ this[ks[i]] = p[ks[i]];
8
+ }
9
+ WebNotificationsInfo.prototype.timestamp = null;
10
+ WebNotificationsInfo.prototype.unreadChats = null;
11
+ WebNotificationsInfo.prototype.notifyMessageCount = null;
12
+ WebNotificationsInfo.prototype.notifyMessages = $util.emptyArray;
13
+ let $oneOfFields;
14
+ Object.defineProperty(WebNotificationsInfo.prototype, "_timestamp", {
15
+ get: $util.oneOfGetter($oneOfFields = ["timestamp"]),
16
+ set: $util.oneOfSetter($oneOfFields)
17
+ });
18
+ Object.defineProperty(WebNotificationsInfo.prototype, "_unreadChats", {
19
+ get: $util.oneOfGetter($oneOfFields = ["unreadChats"]),
20
+ set: $util.oneOfSetter($oneOfFields)
21
+ });
22
+ Object.defineProperty(WebNotificationsInfo.prototype, "_notifyMessageCount", {
23
+ get: $util.oneOfGetter($oneOfFields = ["notifyMessageCount"]),
24
+ set: $util.oneOfSetter($oneOfFields)
25
+ });
26
+ WebNotificationsInfo.create = function create(properties) {
27
+ return new WebNotificationsInfo(properties);
28
+ };
29
+ WebNotificationsInfo.encode = function encode(m, w) {
30
+ if (!w)
31
+ w = $Writer.create();
32
+ if (m.timestamp != null && Object.hasOwnProperty.call(m, "timestamp"))
33
+ w.uint32(16).uint64(m.timestamp);
34
+ if (m.unreadChats != null && Object.hasOwnProperty.call(m, "unreadChats"))
35
+ w.uint32(24).uint32(m.unreadChats);
36
+ if (m.notifyMessageCount != null && Object.hasOwnProperty.call(m, "notifyMessageCount"))
37
+ w.uint32(32).uint32(m.notifyMessageCount);
38
+ if (m.notifyMessages != null && m.notifyMessages.length) {
39
+ for (var i = 0; i < m.notifyMessages.length; ++i)
40
+ $root.proto.WebMessageInfo.encode(m.notifyMessages[i], w.uint32(42).fork()).ldelim();
41
+ }
42
+ return w;
43
+ };
44
+ WebNotificationsInfo.decode = function decode(r, l, e, n) {
45
+ if (!(r instanceof $Reader))
46
+ r = $Reader.create(r);
47
+ if (n === undefined)
48
+ n = 0;
49
+ if (n > $Reader.recursionLimit)
50
+ throw Error("maximum nesting depth exceeded");
51
+ var c = l === undefined ? r.len : r.pos + l, m = new $root.proto.WebNotificationsInfo();
52
+ while (r.pos < c) {
53
+ var t = r.uint32();
54
+ if (t === e)
55
+ break;
56
+ switch (t >>> 3) {
57
+ case 2: {
58
+ m.timestamp = r.uint64();
59
+ break;
60
+ }
61
+ case 3: {
62
+ m.unreadChats = r.uint32();
63
+ break;
64
+ }
65
+ case 4: {
66
+ m.notifyMessageCount = r.uint32();
67
+ break;
68
+ }
69
+ case 5: {
70
+ if (!(m.notifyMessages && m.notifyMessages.length))
71
+ m.notifyMessages = [];
72
+ m.notifyMessages.push($root.proto.WebMessageInfo.decode(r, r.uint32(), undefined, n + 1));
73
+ break;
74
+ }
75
+ default:
76
+ r.skipType(t & 7, n);
77
+ break;
78
+ }
79
+ }
80
+ return m;
81
+ };
82
+ WebNotificationsInfo.fromObject = function fromObject(d, n) {
83
+ if (d instanceof $root.proto.WebNotificationsInfo)
84
+ return d;
85
+ if (n === undefined)
86
+ n = 0;
87
+ if (n > $util.recursionLimit)
88
+ throw Error("maximum nesting depth exceeded");
89
+ var m = new $root.proto.WebNotificationsInfo();
90
+ if (d.timestamp != null) {
91
+ if ($util.Long)
92
+ (m.timestamp = $util.Long.fromValue(d.timestamp)).unsigned = true;
93
+ else if (typeof d.timestamp === "string")
94
+ m.timestamp = parseInt(d.timestamp, 10);
95
+ else if (typeof d.timestamp === "number")
96
+ m.timestamp = d.timestamp;
97
+ else if (typeof d.timestamp === "object")
98
+ m.timestamp = new $util.LongBits(d.timestamp.low >>> 0, d.timestamp.high >>> 0).toNumber(true);
99
+ }
100
+ if (d.unreadChats != null) {
101
+ m.unreadChats = d.unreadChats >>> 0;
102
+ }
103
+ if (d.notifyMessageCount != null) {
104
+ m.notifyMessageCount = d.notifyMessageCount >>> 0;
105
+ }
106
+ if (d.notifyMessages) {
107
+ if (!Array.isArray(d.notifyMessages))
108
+ throw TypeError(".proto.WebNotificationsInfo.notifyMessages: array expected");
109
+ m.notifyMessages = [];
110
+ for (var i = 0; i < d.notifyMessages.length; ++i) {
111
+ if (typeof d.notifyMessages[i] !== "object")
112
+ throw TypeError(".proto.WebNotificationsInfo.notifyMessages: object expected");
113
+ m.notifyMessages[i] = $root.proto.WebMessageInfo.fromObject(d.notifyMessages[i], n + 1);
114
+ }
115
+ }
116
+ return m;
117
+ };
118
+ WebNotificationsInfo.toObject = function toObject(m, o) {
119
+ if (!o)
120
+ o = {};
121
+ var d = {};
122
+ if (o.arrays || o.defaults) {
123
+ d.notifyMessages = [];
124
+ }
125
+ if (m.timestamp != null && m.hasOwnProperty("timestamp")) {
126
+ if (typeof m.timestamp === "number")
127
+ d.timestamp = o.longs === String ? String(m.timestamp) : m.timestamp;
128
+ else
129
+ d.timestamp = o.longs === String ? longToString(m.timestamp, true) : o.longs === Number ? longToNumber(m.timestamp, true) : m.timestamp;
130
+ if (o.oneofs)
131
+ d._timestamp = "timestamp";
132
+ }
133
+ if (m.unreadChats != null && m.hasOwnProperty("unreadChats")) {
134
+ d.unreadChats = m.unreadChats;
135
+ if (o.oneofs)
136
+ d._unreadChats = "unreadChats";
137
+ }
138
+ if (m.notifyMessageCount != null && m.hasOwnProperty("notifyMessageCount")) {
139
+ d.notifyMessageCount = m.notifyMessageCount;
140
+ if (o.oneofs)
141
+ d._notifyMessageCount = "notifyMessageCount";
142
+ }
143
+ if (m.notifyMessages && m.notifyMessages.length) {
144
+ d.notifyMessages = [];
145
+ for (var j = 0; j < m.notifyMessages.length; ++j) {
146
+ d.notifyMessages[j] = $root.proto.WebMessageInfo.toObject(m.notifyMessages[j], o);
147
+ }
148
+ }
149
+ return d;
150
+ };
151
+ WebNotificationsInfo.prototype.toJSON = function toJSON() {
152
+ return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
153
+ };
154
+ WebNotificationsInfo.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
155
+ if (typeUrlPrefix === undefined) {
156
+ typeUrlPrefix = "type.googleapis.com";
157
+ }
158
+ return typeUrlPrefix + "/proto.WebNotificationsInfo";
159
+ };
160
+ return WebNotificationsInfo;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hiroosy/baileys-lite",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "A Lightweight Baileys built with NodeJs 18+",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,5 +1,5 @@
1
1
  import { promisify } from 'node:util'
2
- import { inflate } from 'node:zlib'
2
+ import { inflate, inflateSync } from 'node:zlib'
3
3
  import { randomBytes } from 'node:crypto'
4
4
  import { Boom } from '../foundation/boom.js'
5
5
  import * as constants from './wa-binary-constants.js'
@@ -255,10 +255,12 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
255
255
  }
256
256
 
257
257
  const inflatePromise = promisify(inflate)
258
+ const SYNC_INFLATE_MAX_BYTES = 256 * 1024
258
259
 
259
260
  export const decompressingIfRequired = async buffer => {
260
261
  if (2 & buffer.readUInt8()) {
261
- buffer = await inflatePromise(buffer.slice(1))
262
+ const compressed = buffer.subarray(1)
263
+ buffer = compressed.length <= SYNC_INFLATE_MAX_BYTES ? inflateSync(compressed) : await inflatePromise(compressed)
262
264
  } else {
263
265
  buffer = buffer.slice(1)
264
266
  }
package/src/defaults.js CHANGED
@@ -69,7 +69,8 @@ export const DEFAULT_CONNECTION_CONFIG = {
69
69
  disableStickyRouting: false,
70
70
  auth: undefined,
71
71
  markOnlineOnConnect: true,
72
- syncFullHistory: true,
72
+ syncFullHistory: false,
73
+ memoryTrim: { enabled: true },
73
74
  patchMessageBeforeSending: msg => msg,
74
75
  shouldSyncHistoryMessage: ({ syncType }) => syncType !== proto.HistorySync.HistorySyncType.FULL,
75
76
  shouldIgnoreJid: () => false,
@@ -1,14 +1,78 @@
1
+ const SIZE_NODE_BUDGET = 4000
2
+
3
+ export const estimateSize = value => {
4
+ let total = 0
5
+ let nodes = 0
6
+ const stack = [value]
7
+ const seen = new Set()
8
+ while (stack.length && nodes < SIZE_NODE_BUDGET) {
9
+ const v = stack.pop()
10
+ nodes++
11
+ switch (typeof v) {
12
+ case 'string':
13
+ total += 16 + v.length
14
+ break
15
+ case 'number':
16
+ case 'boolean':
17
+ case 'bigint':
18
+ total += 8
19
+ break
20
+ case 'object': {
21
+ if (v === null) {
22
+ total += 8
23
+ break
24
+ }
25
+ if (ArrayBuffer.isView(v)) {
26
+ total += 32 + v.byteLength
27
+ break
28
+ }
29
+ if (v instanceof ArrayBuffer) {
30
+ total += 32 + v.byteLength
31
+ break
32
+ }
33
+ if (seen.has(v)) break
34
+ seen.add(v)
35
+ if (Array.isArray(v)) {
36
+ total += 16 + v.length * 8
37
+ for (let i = 0; i < v.length; i++) stack.push(v[i])
38
+ } else {
39
+ const keys = Object.keys(v)
40
+ total += 32 + keys.length * 16
41
+ for (let i = 0; i < keys.length; i++) {
42
+ total += keys[i].length
43
+ stack.push(v[keys[i]])
44
+ }
45
+ }
46
+ break
47
+ }
48
+ default:
49
+ break
50
+ }
51
+ }
52
+ if (stack.length) total += stack.length * 64
53
+ return total
54
+ }
55
+
1
56
  export class Cache {
2
57
  constructor(options = {}) {
3
58
  this.ttl = options.ttl ?? (options.stdTTL ? options.stdTTL * 1000 : 0)
4
59
  this.max = options.max || Infinity
60
+ this.maxBytes = options.maxBytes || 0
61
+ this.sizeOf = options.sizeOf || estimateSize
5
62
  this.updateAgeOnGet = !!options.updateAgeOnGet
6
63
  this.dispose = options.dispose || (() => {})
7
64
  this._store = new Map()
65
+ this._bytes = 0
8
66
 
9
67
  if (this.ttl > 0) {
10
- this._sweeper = setInterval(() => this._sweep(), Math.min(this.ttl, 60_000))
11
- this._sweeper.unref?.()
68
+ const ref = new WeakRef(this)
69
+ const timer = setInterval(() => {
70
+ const cache = ref.deref()
71
+ if (cache) cache._sweep()
72
+ else clearInterval(timer)
73
+ }, Math.min(this.ttl, 60_000))
74
+ timer.unref?.()
75
+ this._sweeper = timer
12
76
  }
13
77
  }
14
78
 
@@ -16,13 +80,23 @@ export class Cache {
16
80
  return this.ttl > 0 && entry.expiresAt !== 0 && entry.expiresAt <= Date.now()
17
81
  }
18
82
 
83
+ _remove(key, entry) {
84
+ this._store.delete(key)
85
+ this._bytes -= entry.size
86
+ this.dispose(entry.value, key)
87
+ }
88
+
19
89
  _sweep() {
20
90
  const now = Date.now()
21
91
  for (const [key, entry] of this._store) {
22
- if (entry.expiresAt !== 0 && entry.expiresAt <= now) {
23
- this._store.delete(key)
24
- this.dispose(entry.value, key)
25
- }
92
+ if (entry.expiresAt !== 0 && entry.expiresAt <= now) this._remove(key, entry)
93
+ }
94
+ }
95
+
96
+ _evict() {
97
+ while (this._store.size > this.max || (this.maxBytes > 0 && this._bytes > this.maxBytes && this._store.size > 1)) {
98
+ const oldestKey = this._store.keys().next().value
99
+ this._remove(oldestKey, this._store.get(oldestKey))
26
100
  }
27
101
  }
28
102
 
@@ -30,13 +104,11 @@ export class Cache {
30
104
  const entry = this._store.get(key)
31
105
  if (!entry) return undefined
32
106
  if (this._isExpired(entry)) {
33
- this._store.delete(key)
34
- this.dispose(entry.value, key)
107
+ this._remove(key, entry)
35
108
  return undefined
36
109
  }
37
110
  if (this.updateAgeOnGet && this.ttl > 0) {
38
111
  entry.expiresAt = Date.now() + this.ttl
39
-
40
112
  this._store.delete(key)
41
113
  this._store.set(key, entry)
42
114
  }
@@ -44,17 +116,15 @@ export class Cache {
44
116
  }
45
117
 
46
118
  set(key, value) {
47
- if (this._store.has(key)) this._store.delete(key)
48
- this._store.set(key, {
49
- value,
50
- expiresAt: this.ttl > 0 ? Date.now() + this.ttl : 0
51
- })
52
- while (this._store.size > this.max) {
53
- const oldestKey = this._store.keys().next().value
54
- const oldest = this._store.get(oldestKey)
55
- this._store.delete(oldestKey)
56
- this.dispose(oldest.value, oldestKey)
119
+ const previous = this._store.get(key)
120
+ if (previous) {
121
+ this._store.delete(key)
122
+ this._bytes -= previous.size
57
123
  }
124
+ const size = this.maxBytes > 0 ? this.sizeOf(value) : 0
125
+ this._store.set(key, { value, size, expiresAt: this.ttl > 0 ? Date.now() + this.ttl : 0 })
126
+ this._bytes += size
127
+ this._evict()
58
128
  return true
59
129
  }
60
130
 
@@ -62,8 +132,7 @@ export class Cache {
62
132
  const entry = this._store.get(key)
63
133
  if (!entry) return false
64
134
  if (this._isExpired(entry)) {
65
- this._store.delete(key)
66
- this.dispose(entry.value, key)
135
+ this._remove(key, entry)
67
136
  return false
68
137
  }
69
138
  return true
@@ -72,14 +141,15 @@ export class Cache {
72
141
  delete(key) {
73
142
  const entry = this._store.get(key)
74
143
  if (!entry) return false
75
- this._store.delete(key)
76
- this.dispose(entry.value, key)
144
+ this._remove(key, entry)
77
145
  return true
78
146
  }
79
147
 
80
148
  clear() {
81
- for (const [key, entry] of this._store) this.dispose(entry.value, key)
149
+ const entries = [...this._store]
82
150
  this._store.clear()
151
+ this._bytes = 0
152
+ for (const [key, entry] of entries) this.dispose(entry.value, key)
83
153
  }
84
154
 
85
155
  flushAll() {
@@ -95,6 +165,7 @@ export class Cache {
95
165
  clearInterval(this._sweeper)
96
166
  this._sweeper = undefined
97
167
  }
168
+ this.clear()
98
169
  }
99
170
 
100
171
  mget(keys) {
@@ -114,6 +185,10 @@ export class Cache {
114
185
  get size() {
115
186
  return this._store.size
116
187
  }
188
+
189
+ get bytes() {
190
+ return this._bytes
191
+ }
117
192
  }
118
193
 
119
194
  export const LRUCache = Cache
@@ -0,0 +1,103 @@
1
+ import v8 from 'node:v8'
2
+ import vm from 'node:vm'
3
+
4
+ const MB = 1024 * 1024
5
+
6
+ export const DEFAULT_MEMORY_TRIM = {
7
+ enabled: true,
8
+ checkIntervalMs: 15_000,
9
+ minIntervalMs: 30_000,
10
+ growthBytes: 16 * MB,
11
+ unusedHeapBytes: 16 * MB
12
+ }
13
+
14
+ let collector
15
+ let lastTrimAt = 0
16
+ let lastTrimRss = 0
17
+ let trimming = false
18
+ let guardTimer
19
+ let guardRefs = 0
20
+ let guardOptions = DEFAULT_MEMORY_TRIM
21
+ let pendingTrim
22
+
23
+ const resolveCollector = () => {
24
+ if (collector !== undefined) return collector
25
+ if (typeof globalThis.gc === 'function') {
26
+ collector = globalThis.gc
27
+ return collector
28
+ }
29
+ try {
30
+ v8.setFlagsFromString('--expose-gc')
31
+ collector = vm.runInNewContext('gc')
32
+ v8.setFlagsFromString('--no-expose-gc')
33
+ } catch {
34
+ collector = null
35
+ }
36
+ return collector
37
+ }
38
+
39
+ export const trimMemory = () => {
40
+ if (trimming) return false
41
+ const collect = resolveCollector()
42
+ if (!collect) return false
43
+ trimming = true
44
+ try {
45
+ try {
46
+ collect({ type: 'major', execution: 'sync', flavor: 'last-resort' })
47
+ } catch {
48
+ collect()
49
+ }
50
+ lastTrimAt = Date.now()
51
+ lastTrimRss = process.memoryUsage.rss()
52
+ return true
53
+ } finally {
54
+ trimming = false
55
+ }
56
+ }
57
+
58
+ export const requestTrim = (delayMs = 2000) => {
59
+ if (!guardOptions.enabled) return
60
+ if (pendingTrim) clearTimeout(pendingTrim)
61
+ pendingTrim = setTimeout(() => {
62
+ pendingTrim = undefined
63
+ if (Date.now() - lastTrimAt >= 5000) trimMemory()
64
+ }, delayMs)
65
+ pendingTrim.unref?.()
66
+ }
67
+
68
+ const guardTick = () => {
69
+ const now = Date.now()
70
+ if (now - lastTrimAt < guardOptions.minIntervalMs) return
71
+ const usage = process.memoryUsage()
72
+ const grew = usage.rss - lastTrimRss >= guardOptions.growthBytes
73
+ const unused = usage.heapTotal - usage.heapUsed >= guardOptions.unusedHeapBytes
74
+ if (grew || unused) trimMemory()
75
+ }
76
+
77
+ export const retainMemoryGuard = options => {
78
+ const resolved = { ...DEFAULT_MEMORY_TRIM, ...(options === false ? { enabled: false } : options || {}) }
79
+ guardOptions = resolved
80
+ if (!resolved.enabled) return () => {}
81
+ guardRefs++
82
+ if (!guardTimer) {
83
+ lastTrimRss = process.memoryUsage.rss()
84
+ guardTimer = setInterval(guardTick, resolved.checkIntervalMs)
85
+ guardTimer.unref?.()
86
+ }
87
+ let released = false
88
+ return () => {
89
+ if (released) return
90
+ released = true
91
+ guardRefs--
92
+ if (guardRefs <= 0) {
93
+ guardRefs = 0
94
+ clearInterval(guardTimer)
95
+ guardTimer = undefined
96
+ if (pendingTrim) {
97
+ clearTimeout(pendingTrim)
98
+ pendingTrim = undefined
99
+ }
100
+ requestTrim(1500)
101
+ }
102
+ }
103
+ }
@@ -580,16 +580,10 @@ export class SessionRecord {
580
580
  })
581
581
  }
582
582
  closeSession(session) {
583
- if (this.isClosed(session)) {
584
- console.warn('Session already closed', session)
585
- return
586
- }
587
- console.info('Closing session:', session)
583
+ if (this.isClosed(session)) return
588
584
  session.indexInfo.closed = Date.now()
589
585
  }
590
586
  openSession(session) {
591
- if (!this.isClosed(session)) console.warn('Session already open')
592
- console.info('Opening session:', session)
593
587
  session.indexInfo.closed = -1
594
588
  }
595
589
  isClosed(session) {
@@ -606,7 +600,6 @@ export class SessionRecord {
606
600
  }
607
601
  }
608
602
  if (oldestKey) {
609
- console.info('Removing old closed session:', oldestSession)
610
603
  delete this.sessions[oldestKey]
611
604
  } else {
612
605
  throw new Error('Corrupt sessions object')
@@ -7,7 +7,7 @@ import { SenderKeyName, SenderKeyRecord, GroupCipher, GroupSessionBuilder, Sende
7
7
 
8
8
  export class LIDMappingStore {
9
9
  constructor(keys, logger, pnToLIDFunc) {
10
- this.mappingCache = new Cache({ ttl: 3 * 24 * 60 * 60 * 1000, max: 10000, updateAgeOnGet: true })
10
+ this.mappingCache = new Cache({ ttl: 3 * 24 * 60 * 60 * 1000, max: 4000, updateAgeOnGet: true })
11
11
  this.inflightLIDLookups = new Map()
12
12
  this.inflightPNLookups = new Map()
13
13
  this.keys = keys
@@ -260,7 +260,9 @@ export class LIDMappingStore {
260
260
  }
261
261
 
262
262
  close() {
263
- this.mappingCache.clear()
263
+ this.mappingCache.close()
264
+ this.inflightLIDLookups.clear()
265
+ this.inflightPNLookups.clear()
264
266
  }
265
267
  }
266
268
 
@@ -281,7 +283,7 @@ export function makeLibSignalRepository(auth, logger, pnToLIDFunc) {
281
283
  const lidMapping = new LIDMappingStore(auth.keys, logger, pnToLIDFunc)
282
284
  const storage = signalStorage(auth, lidMapping)
283
285
  const parsedKeys = auth.keys
284
- const migratedSessionCache = new Cache({ ttl: 3 * 24 * 60 * 60 * 1000, updateAgeOnGet: true })
286
+ const migratedSessionCache = new Cache({ ttl: 3 * 24 * 60 * 60 * 1000, max: 4000, updateAgeOnGet: true })
285
287
 
286
288
  const ensureSenderKeyAndCreateSkdm = async (group, meId) => {
287
289
  const senderName = jidToSignalSenderKeyName(group, meId)
@@ -423,7 +425,7 @@ export function makeLibSignalRepository(auth, logger, pnToLIDFunc) {
423
425
  },
424
426
 
425
427
  close() {
426
- migratedSessionCache.clear()
428
+ migratedSessionCache.close()
427
429
  lidMapping.close()
428
430
  },
429
431
 
@@ -1,6 +1,7 @@
1
1
  import { proto } from '../../WAProto/index.js'
2
2
  import { Boom } from '../foundation/boom.js'
3
3
  import { Cache } from '../foundation/cache.js'
4
+ import { requestTrim } from '../foundation/memory.js'
4
5
  import { makeMutex } from '../foundation/concurrency.js'
5
6
  import { DEFAULT_CACHE_TTLS, HISTORY_SYNC_PAUSED_TIMEOUT_MS, PROCESSABLE_HISTORY_TYPES } from '../defaults.js'
6
7
  import { ALL_WA_PATCH_NAMES, SyncState } from '../constants.js'
@@ -501,6 +502,7 @@ export const makeChatsSocket = config => {
501
502
  syncState = SyncState.Online
502
503
  logger.info('App state sync complete, transitioning to Online state and flushing buffer')
503
504
  ev.flush()
505
+ requestTrim(5000)
504
506
  const accountSyncCounter = (authState.creds.accountSyncCounter || 0) + 1
505
507
  ev.emit('creds.update', { accountSyncCounter })
506
508
  }
@@ -79,13 +79,13 @@ export const makeMessagesRecvSocket = (config) => {
79
79
 
80
80
  const msgRetryCache = config.msgRetryCounterCache ||
81
81
  new Cache({
82
- max: 8192,
82
+ max: 2048,
83
83
  stdTTL: DEFAULT_CACHE_TTLS.MSG_RETRY,
84
84
  useClones: false
85
85
  });
86
86
  const callOfferCache = config.callOfferCache ||
87
87
  new Cache({
88
- max: 2048,
88
+ max: 256,
89
89
  stdTTL: DEFAULT_CACHE_TTLS.CALL_OFFER,
90
90
  useClones: false
91
91
  });
@@ -1336,7 +1336,7 @@ export const makeMessagesRecvSocket = (config) => {
1336
1336
  }
1337
1337
  await messageMutex.mutex(async () => {
1338
1338
  await decrypt();
1339
- if (msg.key?.remoteJid && msg.key?.id && msg.message && messageRetryManager) {
1339
+ if (msg.key?.fromMe && msg.key?.remoteJid && msg.key?.id && msg.message && messageRetryManager) {
1340
1340
  messageRetryManager.addRecentMessage(msg.key.remoteJid, msg.key.id, msg.message);
1341
1341
  }
1342
1342
 
@@ -1715,6 +1715,8 @@ export const makeMessagesRecvSocket = (config) => {
1715
1715
  callOfferCache.close();
1716
1716
  }
1717
1717
  identityAssertDebounce.close();
1718
+ inFlightPreKeyLow.clear();
1719
+ inFlight463Recoveries.clear();
1718
1720
  sendActiveReceipts = false;
1719
1721
  });
1720
1722
  async function pruneExpiredTcTokens() {
@@ -66,7 +66,7 @@ export const makeMessagesSocket = (config) => {
66
66
  const userDevicesCache = config.userDevicesCache ||
67
67
  new Cache({
68
68
  ttl: DEFAULT_CACHE_TTLS.USER_DEVICES * 1000,
69
- max: 1000
69
+ max: 500
70
70
  });
71
71
 
72
72
  const devicesMutex = makeMutex();
@@ -1105,7 +1105,7 @@ export const makeMessagesSocket = (config) => {
1105
1105
  }
1106
1106
  mediaConn = undefined;
1107
1107
  if (messageRetryManager) {
1108
- messageRetryManager.clear();
1108
+ messageRetryManager.close();
1109
1109
  }
1110
1110
  });
1111
1111
  const fullSock = {
@@ -33,6 +33,7 @@ import { USyncQuery, USyncUser } from './usync.js'
33
33
  import { normalizeUsername, isValidUsername, isValidUsernameKey } from '../utils/username.js'
34
34
  import { WebSocketClient } from '../socket-client/websocket-client.js'
35
35
  import { generateQR } from '../foundation/qrcode-terminal.js'
36
+ import { retainMemoryGuard } from '../foundation/memory.js'
36
37
 
37
38
  const wMexQuery = (variables, queryId, query, generateMessageTag) =>
38
39
  query({
@@ -93,6 +94,7 @@ export const makeSocket = config => {
93
94
  wsConfig = { ...config, options: { ...(config.options || {}), headers } }
94
95
  }
95
96
 
97
+ const releaseMemoryGuard = retainMemoryGuard(config.memoryTrim)
96
98
  const ephemeralKeyPair = Curve.generateKeyPair()
97
99
 
98
100
  const noise = makeNoiseHandler({ keyPair: ephemeralKeyPair, NOISE_HEADER: NOISE_WA_HEADER, logger, routingInfo: authState?.creds?.routingInfo })
@@ -481,6 +483,7 @@ export const makeSocket = config => {
481
483
 
482
484
  noise.destroy?.()
483
485
  signalRepository.close?.()
486
+ releaseMemoryGuard()
484
487
  if (!ws.isClosed && !ws.isClosing) {
485
488
  try {
486
489
 
@@ -100,10 +100,11 @@ export class PreKeyManager {
100
100
  }
101
101
 
102
102
  const txStorage = new AsyncLocalStorage()
103
+ const SIGNAL_CACHE_BYTES = 6 * 1024 * 1024
103
104
 
104
105
  export function makeCacheableSignalKeyStore(store, logger, _cache) {
105
106
 
106
- const cache = _cache || new Cache({ max: 8192, ttl: DEFAULT_CACHE_TTLS.SIGNAL_STORE * 1000 })
107
+ const cache = _cache || new Cache({ max: 2048, maxBytes: SIGNAL_CACHE_BYTES, ttl: DEFAULT_CACHE_TTLS.SIGNAL_STORE * 1000 })
107
108
  const cacheMutex = makeMutex()
108
109
 
109
110
  function getUniqueId(type, id) {