jagproject 26.3.22 → 26.3.25

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 (206) hide show
  1. package/WAProto/GenerateStatics.sh +3 -4
  2. package/WAProto/WAProto.proto +1215 -511
  3. package/WAProto/fix-imports.js +73 -0
  4. package/WAProto/index.d.ts +14017 -0
  5. package/WAProto/index.js +64857 -145167
  6. package/engine-requirements.js +4 -7
  7. package/lib/Defaults/index.d.ts +74 -0
  8. package/lib/Defaults/index.js +51 -33
  9. package/lib/Defaults/phonenumber-mcc.json +223 -0
  10. package/lib/Defaults/wileys-version.json +2 -2
  11. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  12. package/lib/Signal/Group/group-session-builder.d.ts +15 -0
  13. package/lib/Signal/Group/group-session-builder.js +5 -3
  14. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  15. package/lib/Signal/Group/group_cipher.js +35 -46
  16. package/lib/Signal/Group/index.d.ts +12 -0
  17. package/lib/Signal/Group/index.js +21 -21
  18. package/lib/Signal/Group/keyhelper.d.ts +11 -0
  19. package/lib/Signal/Group/keyhelper.js +2 -2
  20. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  21. package/lib/Signal/Group/sender-chain-key.js +5 -10
  22. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  23. package/lib/Signal/Group/sender-key-distribution-message.js +7 -7
  24. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  25. package/lib/Signal/Group/sender-key-message.js +8 -8
  26. package/lib/Signal/Group/sender-key-name.d.ts +18 -0
  27. package/lib/Signal/Group/sender-key-record.d.ts +31 -0
  28. package/lib/Signal/Group/sender-key-record.js +7 -16
  29. package/lib/Signal/Group/sender-key-state.d.ts +39 -0
  30. package/lib/Signal/Group/sender-key-state.js +25 -37
  31. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  32. package/lib/Signal/Group/sender-message-key.js +2 -2
  33. package/lib/Signal/libsignal.d.ts +5 -0
  34. package/lib/Signal/libsignal.js +358 -54
  35. package/lib/Signal/lid-mapping.d.ts +19 -0
  36. package/lib/Signal/lid-mapping.js +274 -0
  37. package/lib/Socket/Client/index.d.ts +3 -0
  38. package/lib/Socket/Client/index.js +2 -2
  39. package/lib/Socket/Client/types.d.ts +16 -0
  40. package/lib/Socket/Client/types.js +1 -0
  41. package/lib/Socket/Client/websocket.d.ts +13 -0
  42. package/lib/Socket/Client/websocket.js +18 -30
  43. package/lib/Socket/business.d.ts +202 -0
  44. package/lib/Socket/business.js +160 -38
  45. package/lib/Socket/chats.d.ts +111 -0
  46. package/lib/Socket/chats.js +497 -314
  47. package/lib/Socket/communities.d.ts +258 -0
  48. package/lib/Socket/communities.js +438 -0
  49. package/lib/Socket/community.js +333 -0
  50. package/lib/Socket/groups.d.ts +150 -0
  51. package/lib/Socket/groups.js +229 -91
  52. package/lib/Socket/index.d.ts +245 -0
  53. package/lib/Socket/index.js +9 -6
  54. package/lib/Socket/messages-recv.d.ts +187 -0
  55. package/lib/Socket/messages-recv.js +1105 -501
  56. package/lib/Socket/messages-send.d.ts +183 -0
  57. package/lib/Socket/messages-send.js +1184 -501
  58. package/lib/Socket/mex.d.ts +3 -0
  59. package/lib/Socket/mex.js +45 -0
  60. package/lib/Socket/newsletter.d.ts +160 -0
  61. package/lib/Socket/newsletter.js +227 -200
  62. package/lib/Socket/socket.d.ts +55 -0
  63. package/lib/Socket/socket.js +507 -206
  64. package/lib/Socket/usync.js +6 -6
  65. package/lib/Store/index.js +17 -5
  66. package/lib/Store/make-cache-manager-store.js +83 -0
  67. package/lib/Store/make-in-memory-store.js +48 -89
  68. package/lib/Store/make-ordered-dictionary.js +1 -1
  69. package/lib/Types/Auth.d.ts +116 -0
  70. package/lib/Types/Bussines.d.ts +25 -0
  71. package/lib/Types/Bussines.js +2 -0
  72. package/lib/Types/Call.d.ts +15 -0
  73. package/lib/Types/Chat.d.ts +123 -0
  74. package/lib/Types/Chat.js +7 -1
  75. package/lib/Types/Contact.d.ts +24 -0
  76. package/lib/Types/Events.d.ts +237 -0
  77. package/lib/Types/Events.js +1 -0
  78. package/lib/Types/GroupMetadata.d.ts +67 -0
  79. package/lib/Types/Label.d.ts +47 -0
  80. package/lib/Types/Label.js +1 -3
  81. package/lib/Types/LabelAssociation.d.ts +30 -0
  82. package/lib/Types/LabelAssociation.js +1 -3
  83. package/lib/Types/Message.d.ts +305 -0
  84. package/lib/Types/Message.js +9 -5
  85. package/lib/Types/MexUpdates.js +11 -0
  86. package/lib/Types/Newsletter.d.ts +135 -0
  87. package/lib/Types/Newsletter.js +36 -11
  88. package/lib/Types/Product.d.ts +79 -0
  89. package/lib/Types/Signal.d.ts +76 -0
  90. package/lib/Types/Signal.js +1 -0
  91. package/lib/Types/Socket.d.ts +133 -0
  92. package/lib/Types/Socket.js +1 -0
  93. package/lib/Types/State.d.ts +39 -0
  94. package/lib/Types/State.js +12 -0
  95. package/lib/Types/USync.d.ts +26 -0
  96. package/lib/Types/USync.js +1 -0
  97. package/lib/Types/index.d.ts +65 -0
  98. package/lib/Types/index.js +14 -14
  99. package/lib/Utils/audioToBuffer.js +31 -0
  100. package/lib/Utils/auth-utils.d.ts +19 -0
  101. package/lib/Utils/auth-utils.js +222 -123
  102. package/lib/Utils/baileys-event-stream.js +60 -0
  103. package/lib/Utils/browser-utils.d.ts +4 -0
  104. package/lib/Utils/browser-utils.js +38 -29
  105. package/lib/Utils/business.d.ts +23 -0
  106. package/lib/Utils/business.js +54 -48
  107. package/lib/Utils/chat-utils.d.ts +70 -0
  108. package/lib/Utils/chat-utils.js +284 -189
  109. package/lib/Utils/crypto.d.ts +37 -0
  110. package/lib/Utils/crypto.js +16 -41
  111. package/lib/Utils/decode-wa-message.d.ts +48 -0
  112. package/lib/Utils/decode-wa-message.js +128 -48
  113. package/lib/Utils/event-buffer.d.ts +34 -0
  114. package/lib/Utils/event-buffer.js +124 -62
  115. package/lib/Utils/generics.d.ts +91 -0
  116. package/lib/Utils/generics.js +154 -138
  117. package/lib/Utils/history.d.ts +22 -0
  118. package/lib/Utils/history.js +77 -34
  119. package/lib/Utils/identity-change-handler.d.ts +37 -0
  120. package/lib/Utils/identity-change-handler.js +54 -0
  121. package/lib/Utils/index.d.ts +22 -0
  122. package/lib/Utils/index.js +32 -19
  123. package/lib/Utils/link-preview.d.ts +21 -0
  124. package/lib/Utils/link-preview.js +12 -17
  125. package/lib/Utils/logger.d.ts +13 -0
  126. package/lib/Utils/lt-hash.d.ts +8 -0
  127. package/lib/Utils/lt-hash.js +2 -43
  128. package/lib/Utils/make-mutex.d.ts +9 -0
  129. package/lib/Utils/make-mutex.js +21 -27
  130. package/lib/Utils/message-retry-manager.d.ts +110 -0
  131. package/lib/Utils/message-retry-manager.js +143 -45
  132. package/lib/Utils/messages-media.d.ts +130 -0
  133. package/lib/Utils/messages-media.js +429 -502
  134. package/lib/Utils/messages-newsletter.d.ts +84 -0
  135. package/lib/Utils/messages-newsletter.js +295 -0
  136. package/lib/Utils/messages.d.ts +92 -0
  137. package/lib/Utils/messages.js +1099 -400
  138. package/lib/Utils/noise-handler.d.ts +20 -0
  139. package/lib/Utils/noise-handler.js +145 -91
  140. package/lib/Utils/pre-key-manager.d.ts +28 -0
  141. package/lib/Utils/pre-key-manager.js +112 -0
  142. package/lib/Utils/process-message.d.ts +60 -0
  143. package/lib/Utils/process-message.js +316 -184
  144. package/lib/Utils/reporting-utils.d.ts +11 -0
  145. package/lib/Utils/reporting-utils.js +262 -0
  146. package/lib/Utils/resolve-jid.d.ts +43 -0
  147. package/lib/Utils/resolve-jid.js +95 -0
  148. package/lib/Utils/serial-task-queue.js +29 -0
  149. package/lib/Utils/signal.d.ts +34 -0
  150. package/lib/Utils/signal.js +56 -39
  151. package/lib/Utils/streamToBuffer.js +17 -0
  152. package/lib/Utils/sync-action-utils.d.ts +19 -0
  153. package/lib/Utils/sync-action-utils.js +52 -0
  154. package/lib/Utils/tc-token-utils.d.ts +12 -0
  155. package/lib/Utils/tc-token-utils.js +20 -0
  156. package/lib/Utils/use-mongo-file-auth-state.js +71 -0
  157. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  158. package/lib/Utils/use-multi-file-auth-state.js +11 -12
  159. package/lib/Utils/use-single-file-auth-state.js +73 -0
  160. package/lib/Utils/validate-connection.d.ts +11 -0
  161. package/lib/Utils/validate-connection.js +59 -82
  162. package/lib/Utils/wileys-event-stream.js +1 -61
  163. package/lib/WABinary/constants.d.ts +28 -0
  164. package/lib/WABinary/decode.d.ts +7 -0
  165. package/lib/WABinary/decode.js +39 -4
  166. package/lib/WABinary/encode.d.ts +3 -0
  167. package/lib/WABinary/encode.js +17 -11
  168. package/lib/WABinary/generic-utils.d.ts +15 -0
  169. package/lib/WABinary/generic-utils.js +46 -18
  170. package/lib/WABinary/index.d.ts +6 -0
  171. package/lib/WABinary/index.js +9 -5
  172. package/lib/WABinary/jid-utils.d.ts +48 -0
  173. package/lib/WABinary/jid-utils.js +67 -37
  174. package/lib/WABinary/types.d.ts +19 -0
  175. package/lib/WABinary/types.js +34 -0
  176. package/lib/WAM/BinaryInfo.d.ts +9 -0
  177. package/lib/WAM/constants.d.ts +40 -0
  178. package/lib/WAM/constants.js +19183 -11678
  179. package/lib/WAM/encode.d.ts +3 -0
  180. package/lib/WAM/encode.js +15 -17
  181. package/lib/WAM/index.d.ts +4 -0
  182. package/lib/WAM/index.js +3 -3
  183. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  184. package/lib/WAUSync/Protocols/USyncContactProtocol.js +6 -6
  185. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  186. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +9 -9
  187. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  188. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +6 -6
  189. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  190. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -8
  191. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  192. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +18 -17
  193. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  194. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +11 -3
  195. package/lib/WAUSync/Protocols/index.d.ts +5 -0
  196. package/lib/WAUSync/Protocols/index.js +6 -4
  197. package/lib/WAUSync/USyncQuery.d.ts +29 -0
  198. package/lib/WAUSync/USyncQuery.js +38 -30
  199. package/lib/WAUSync/USyncUser.d.ts +13 -0
  200. package/lib/WAUSync/index.d.ts +4 -0
  201. package/lib/WAUSync/index.js +3 -3
  202. package/lib/index.d.ts +12 -0
  203. package/lib/index.js +3 -5
  204. package/package.json +10 -6
  205. package/readme.md +97 -0
  206. package/LICENSE +0 -21
@@ -0,0 +1,11 @@
1
+ import { proto } from '../../WAProto/index.js';
2
+ import type { WAMessageContent, WAMessageKey } from '../Types/index.js';
3
+ import type { BinaryNode } from '../WABinary/index.js';
4
+ export type ReportingField = {
5
+ f: number;
6
+ m?: boolean;
7
+ s?: ReportingField[];
8
+ };
9
+ export declare const shouldIncludeReportingToken: (message: proto.IMessage) => boolean;
10
+ export declare const getMessageReportingToken: (msgProtobuf: Buffer, message: WAMessageContent, key: WAMessageKey) => Promise<BinaryNode | null>;
11
+ //# sourceMappingURL=reporting-utils.d.ts.map
@@ -0,0 +1,262 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMessageReportingToken = exports.shouldIncludeReportingToken = void 0;
4
+ const crypto_1 = require("crypto");
5
+ const index_js_1 = require("../../WAProto/index.js");
6
+ const crypto_js_1 = require("./crypto.js");
7
+ const reportingFields = [
8
+ { f: 1 },
9
+ {
10
+ f: 3,
11
+ s: [{ f: 2 }, { f: 3 }, { f: 8 }, { f: 11 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 25 }]
12
+ },
13
+ { f: 4, s: [{ f: 1 }, { f: 16 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }] },
14
+ { f: 5, s: [{ f: 3 }, { f: 4 }, { f: 5 }, { f: 16 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }] },
15
+ { f: 6, s: [{ f: 1 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 30 }] },
16
+ { f: 7, s: [{ f: 2 }, { f: 7 }, { f: 10 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 20 }] },
17
+ { f: 8, s: [{ f: 2 }, { f: 7 }, { f: 9 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 21 }] },
18
+ { f: 9, s: [{ f: 2 }, { f: 6 }, { f: 7 }, { f: 13 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 20 }] },
19
+ { f: 12, s: [{ f: 1 }, { f: 2 }, { f: 14, m: true }, { f: 15 }] },
20
+ { f: 18, s: [{ f: 6 }, { f: 16 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }] },
21
+ { f: 26, s: [{ f: 4 }, { f: 5 }, { f: 8 }, { f: 13 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }] },
22
+ { f: 28, s: [{ f: 1 }, { f: 2 }, { f: 4 }, { f: 5 }, { f: 6 }, { f: 7, s: [{ f: 21 }, { f: 22 }] }] },
23
+ { f: 37, s: [{ f: 1, m: true }] },
24
+ {
25
+ f: 49,
26
+ s: [
27
+ { f: 2 },
28
+ { f: 3, s: [{ f: 1 }, { f: 2 }] },
29
+ { f: 5, s: [{ f: 21 }, { f: 22 }] },
30
+ { f: 8, s: [{ f: 1 }, { f: 2 }] }
31
+ ]
32
+ },
33
+ { f: 53, s: [{ f: 1, m: true }] },
34
+ { f: 55, s: [{ f: 1, m: true }] },
35
+ { f: 58, s: [{ f: 1, m: true }] },
36
+ { f: 59, s: [{ f: 1, m: true }] },
37
+ {
38
+ f: 60,
39
+ s: [
40
+ { f: 2 },
41
+ { f: 3, s: [{ f: 1 }, { f: 2 }] },
42
+ { f: 5, s: [{ f: 21 }, { f: 22 }] },
43
+ { f: 8, s: [{ f: 1 }, { f: 2 }] }
44
+ ]
45
+ },
46
+ {
47
+ f: 64,
48
+ s: [
49
+ { f: 2 },
50
+ { f: 3, s: [{ f: 1 }, { f: 2 }] },
51
+ { f: 5, s: [{ f: 21 }, { f: 22 }] },
52
+ { f: 8, s: [{ f: 1 }, { f: 2 }] }
53
+ ]
54
+ },
55
+ { f: 66, s: [{ f: 2 }, { f: 6 }, { f: 7 }, { f: 13 }, { f: 17, s: [{ f: 21 }, { f: 22 }] }, { f: 20 }] },
56
+ { f: 74, s: [{ f: 1, m: true }] },
57
+ { f: 87, s: [{ f: 1, m: true }] },
58
+ { f: 88, s: [{ f: 1 }, { f: 2, s: [{ f: 1 }] }, { f: 3, s: [{ f: 21 }, { f: 22 }] }] },
59
+ { f: 92, s: [{ f: 1, m: true }] },
60
+ { f: 93, s: [{ f: 1, m: true }] },
61
+ { f: 94, s: [{ f: 1, m: true }] }
62
+ ];
63
+ const compileReportingFields = (fields) => {
64
+ const map = new Map();
65
+ for (const f of fields) {
66
+ map.set(f.f, {
67
+ m: f.m,
68
+ children: f.s ? compileReportingFields(f.s) : undefined
69
+ });
70
+ }
71
+ return map;
72
+ };
73
+ const compiledReportingFields = compileReportingFields(reportingFields);
74
+ const EMPTY_MAP = new Map();
75
+ const ENC_SECRET_REPORT_TOKEN = 'Report Token';
76
+ const WIRE = {
77
+ VARINT: 0,
78
+ FIXED64: 1,
79
+ BYTES: 2,
80
+ FIXED32: 5
81
+ };
82
+ const shouldIncludeReportingToken = (message) => !message.reactionMessage &&
83
+ !message.encReactionMessage &&
84
+ !message.encEventResponseMessage &&
85
+ !message.pollUpdateMessage;
86
+ exports.shouldIncludeReportingToken = shouldIncludeReportingToken;
87
+ const generateMsgSecretKey = (modificationType, origMsgId, origMsgSender, modificationSender, origMsgSecret) => {
88
+ const useCaseSecret = Buffer.concat([
89
+ Buffer.from(origMsgId, 'utf8'),
90
+ Buffer.from(origMsgSender, 'utf8'),
91
+ Buffer.from(modificationSender, 'utf8'),
92
+ Buffer.from(modificationType, 'utf8')
93
+ ]);
94
+ return (0, crypto_js_1.hkdf)(origMsgSecret, 32, { info: useCaseSecret.toString('latin1') });
95
+ };
96
+ const extractReportingTokenContent = (data, cfg) => {
97
+ const out = [];
98
+ let i = 0;
99
+ while (i < data.length) {
100
+ const tag = decodeVarint(data, i);
101
+ if (!tag.ok) {
102
+ return null;
103
+ }
104
+ const fieldNum = tag.value >> 3;
105
+ const wireType = tag.value & 0x7;
106
+ const fieldStart = i;
107
+ i += tag.bytes;
108
+ const fieldCfg = cfg.get(fieldNum);
109
+ const pushSlice = (end) => {
110
+ if (end > data.length) {
111
+ return false;
112
+ }
113
+ out.push({ num: fieldNum, bytes: data.subarray(fieldStart, end) });
114
+ i = end;
115
+ return true;
116
+ };
117
+ const skip = (end) => {
118
+ if (end > data.length) {
119
+ return false;
120
+ }
121
+ i = end;
122
+ return true;
123
+ };
124
+ if (wireType === WIRE.VARINT) {
125
+ const v = decodeVarint(data, i);
126
+ if (!v.ok) {
127
+ return null;
128
+ }
129
+ const end = i + v.bytes;
130
+ if (!fieldCfg) {
131
+ if (!skip(end)) {
132
+ return null;
133
+ }
134
+ continue;
135
+ }
136
+ if (!pushSlice(end)) {
137
+ return null;
138
+ }
139
+ continue;
140
+ }
141
+ if (wireType === WIRE.FIXED64) {
142
+ const end = i + 8;
143
+ if (!fieldCfg) {
144
+ if (!skip(end)) {
145
+ return null;
146
+ }
147
+ continue;
148
+ }
149
+ if (!pushSlice(end)) {
150
+ return null;
151
+ }
152
+ continue;
153
+ }
154
+ if (wireType === WIRE.FIXED32) {
155
+ const end = i + 4;
156
+ if (!fieldCfg) {
157
+ if (!skip(end)) {
158
+ return null;
159
+ }
160
+ continue;
161
+ }
162
+ if (!pushSlice(end)) {
163
+ return null;
164
+ }
165
+ continue;
166
+ }
167
+ if (wireType === WIRE.BYTES) {
168
+ const len = decodeVarint(data, i);
169
+ if (!len.ok) {
170
+ return null;
171
+ }
172
+ const valStart = i + len.bytes;
173
+ const valEnd = valStart + len.value;
174
+ if (valEnd > data.length) {
175
+ return null;
176
+ }
177
+ if (!fieldCfg) {
178
+ i = valEnd;
179
+ continue;
180
+ }
181
+ if (fieldCfg.m || fieldCfg.children) {
182
+ const sub = extractReportingTokenContent(data.subarray(valStart, valEnd), fieldCfg.children ?? EMPTY_MAP);
183
+ if (sub === null) {
184
+ return null;
185
+ }
186
+ if (sub.length > 0) {
187
+ const newTag = encodeVarint(tag.value);
188
+ const newLen = encodeVarint(sub.length);
189
+ out.push({
190
+ num: fieldNum,
191
+ bytes: Buffer.concat([newTag, newLen, sub])
192
+ });
193
+ }
194
+ i = valEnd;
195
+ continue;
196
+ }
197
+ out.push({ num: fieldNum, bytes: data.subarray(fieldStart, valEnd) });
198
+ i = valEnd;
199
+ continue;
200
+ }
201
+ return null;
202
+ }
203
+ if (out.length === 0) {
204
+ return Buffer.alloc(0);
205
+ }
206
+ out.sort((a, b) => a.num - b.num);
207
+ return Buffer.concat(out.map(f => f.bytes));
208
+ };
209
+ const decodeVarint = (buffer, offset) => {
210
+ let value = 0;
211
+ let bytes = 0;
212
+ let shift = 0;
213
+ while (offset + bytes < buffer.length) {
214
+ const current = buffer[offset + bytes];
215
+ value |= (current & 0x7f) << shift;
216
+ bytes++;
217
+ if ((current & 0x80) === 0) {
218
+ return { value, bytes, ok: true };
219
+ }
220
+ shift += 7;
221
+ if (shift > 35) {
222
+ return { value: 0, bytes: 0, ok: false };
223
+ }
224
+ }
225
+ return { value: 0, bytes: 0, ok: false };
226
+ };
227
+ const encodeVarint = (value) => {
228
+ const parts = [];
229
+ let remaining = value >>> 0;
230
+ while (remaining > 0x7f) {
231
+ parts.push((remaining & 0x7f) | 0x80);
232
+ remaining >>>= 7;
233
+ }
234
+ parts.push(remaining);
235
+ return Buffer.from(parts);
236
+ };
237
+ const getMessageReportingToken = async (msgProtobuf, message, key) => {
238
+ const msgSecret = message.messageContextInfo?.messageSecret;
239
+ if (!msgSecret || !key.id) {
240
+ return null;
241
+ }
242
+ const from = key.fromMe ? key.remoteJid : key.participant || key.remoteJid;
243
+ const to = key.fromMe ? key.participant || key.remoteJid : key.remoteJid;
244
+ const reportingSecret = generateMsgSecretKey(ENC_SECRET_REPORT_TOKEN, key.id, from, to, msgSecret);
245
+ const content = extractReportingTokenContent(msgProtobuf, compiledReportingFields);
246
+ if (!content || content.length === 0) {
247
+ return null;
248
+ }
249
+ const reportingToken = (0, crypto_1.createHmac)('sha256', reportingSecret).update(content).digest().subarray(0, 16);
250
+ return {
251
+ tag: 'reporting',
252
+ attrs: {},
253
+ content: [
254
+ {
255
+ tag: 'reporting_token',
256
+ attrs: { v: '2' },
257
+ content: reportingToken
258
+ }
259
+ ]
260
+ };
261
+ };
262
+ exports.getMessageReportingToken = getMessageReportingToken;
@@ -0,0 +1,43 @@
1
+ import type { WASocket } from '../Types/index.js';
2
+
3
+ /**
4
+ * Resolve LID / mention JID / participant ID menjadi JID @s.whatsapp.net.
5
+ *
6
+ * @param conn WASocket instance
7
+ * @param m serialized message object (dari handler)
8
+ * @param target JID/LID eksplisit, opsional (override dari m)
9
+ * @returns JID @s.whatsapp.net atau null jika tidak bisa di-resolve
10
+ *
11
+ * @example
12
+ * const jid = await resolveJid(conn, m);
13
+ * if (!jid) return conn.sendMessage(m.chat, { text: 'Gagal resolve JID' });
14
+ * await conn.sendMessage(m.chat, { text: `JID: ${jid}` });
15
+ *
16
+ * @example
17
+ * // Resolve dari mention pertama
18
+ * const jid = await resolveJid(conn, m, m.mentionedJid?.[0]);
19
+ */
20
+ export declare function resolveJid(
21
+ conn: WASocket,
22
+ m: {
23
+ sender?: string;
24
+ jid?: string;
25
+ chat?: string;
26
+ isGroup?: boolean;
27
+ mentionedJid?: string[];
28
+ quoted?: { sender?: string; participant?: string };
29
+ },
30
+ target?: string | null
31
+ ): Promise<string | null>;
32
+
33
+ /**
34
+ * Resolve banyak JID/LID sekaligus.
35
+ *
36
+ * @example
37
+ * const jids = await resolveJids(conn, m, m.mentionedJid);
38
+ */
39
+ export declare function resolveJids(
40
+ conn: WASocket,
41
+ m: Parameters<typeof resolveJid>[1],
42
+ targets?: string[]
43
+ ): Promise<(string | null)[]>;
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ /**
3
+ * resolve-jid.js
4
+ * Resolve LID / participant ID menjadi JID WhatsApp asli (@s.whatsapp.net).
5
+ *
6
+ * Berguna saat participant.jid di grup adalah format @lid,
7
+ * dan kamu butuh nomor WA aslinya.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.resolveJid = resolveJid;
11
+ exports.resolveJids = resolveJids;
12
+ const index_js_1 = require("../WABinary/index.js");
13
+ /**
14
+ * Resolve LID, mention JID, atau sender menjadi JID @s.whatsapp.net.
15
+ *
16
+ * @param {import('../Types').WASocket} conn
17
+ * @param {object} m — serialized message object
18
+ * @param {string} [target] — JID/LID eksplisit (opsional, override otomatis)
19
+ * @returns {Promise<string|null>}
20
+ *
21
+ * @example
22
+ * // Di dalam handler:
23
+ * const jid = await resolveJid(conn, m);
24
+ * if (!jid) return conn.sendMessage(m.chat, { text: 'Tidak bisa resolve JID' });
25
+ * await conn.sendMessage(m.chat, { text: `JID: ${jid}` });
26
+ *
27
+ * @example
28
+ * // Dengan target eksplisit (misalnya dari mention):
29
+ * const jid = await resolveJid(conn, m, m.mentionedJid?.[0]);
30
+ */
31
+ async function resolveJid(conn, m, target) {
32
+ // Tentukan input — prioritas: target > mention > quoted sender > sender
33
+ const input = target ||
34
+ (m.mentionedJid && m.mentionedJid[0]) ||
35
+ (m.quoted && (m.quoted.sender || m.quoted.participant)) ||
36
+ m.sender ||
37
+ m.jid;
38
+ if (!input)
39
+ return null;
40
+ // Sudah berbentuk JID normal → langsung return
41
+ if (/@s\.whatsapp\.net$/.test(input)) {
42
+ return (0, index_js_1.jidNormalizedUser)(input);
43
+ }
44
+ // Jika bukan di grup, tidak bisa resolve LID via groupMetadata
45
+ if (!m.isGroup || !m.chat) {
46
+ // Coba normalise saja (untuk kasus user JID tanpa domain)
47
+ if (/^\d+$/.test(input.split('@')[0])) {
48
+ return `${input.split('@')[0]}@s.whatsapp.net`;
49
+ }
50
+ return null;
51
+ }
52
+ let meta;
53
+ try {
54
+ meta = await conn.groupMetadata(m.chat);
55
+ }
56
+ catch {
57
+ return null;
58
+ }
59
+ if (!meta || !Array.isArray(meta.participants))
60
+ return null;
61
+ // Cari match di participants: by jid, id, lid, atau user number
62
+ const inputUser = input.split('@')[0];
63
+ const participant = meta.participants.find(p => {
64
+ if (!p)
65
+ return false;
66
+ const pJid = p.jid || p.id || '';
67
+ const pLid = p.lid || '';
68
+ return (pJid === input ||
69
+ pLid === input ||
70
+ pJid.split('@')[0] === inputUser ||
71
+ pLid.split('@')[0] === inputUser);
72
+ });
73
+ if (participant) {
74
+ // Return JID yang sudah pasti @s.whatsapp.net
75
+ const resolved = participant.jid || participant.id;
76
+ if (resolved && /@s\.whatsapp\.net$/.test(resolved)) {
77
+ return (0, index_js_1.jidNormalizedUser)(resolved);
78
+ }
79
+ }
80
+ return null;
81
+ }
82
+ /**
83
+ * Resolve banyak JID/LID sekaligus.
84
+ *
85
+ * @param {import('../Types').WASocket} conn
86
+ * @param {object} m
87
+ * @param {string[]} targets
88
+ * @returns {Promise<(string|null)[]>}
89
+ *
90
+ * @example
91
+ * const jids = await resolveJids(conn, m, m.mentionedJid);
92
+ */
93
+ async function resolveJids(conn, m, targets = []) {
94
+ return Promise.all(targets.map(t => resolveJid(conn, m, t)));
95
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class SerialTaskQueue {
4
+ constructor(options = {}) {
5
+ this.concurrency = Math.max(1, Number(options.concurrency || 1));
6
+ this.running = 0;
7
+ this.queue = [];
8
+ }
9
+ add(task) {
10
+ return new Promise((resolve, reject) => {
11
+ this.queue.push({ task, resolve, reject });
12
+ this._drain();
13
+ });
14
+ }
15
+ _drain() {
16
+ while (this.running < this.concurrency && this.queue.length) {
17
+ const item = this.queue.shift();
18
+ this.running += 1;
19
+ Promise.resolve()
20
+ .then(() => item.task())
21
+ .then(value => item.resolve(value), error => item.reject(error))
22
+ .finally(() => {
23
+ this.running -= 1;
24
+ this._drain();
25
+ });
26
+ }
27
+ }
28
+ }
29
+ exports.default = SerialTaskQueue;
@@ -0,0 +1,34 @@
1
+ import type { SignalRepositoryWithLIDStore } from '../Types/index.js';
2
+ import type { AuthenticationCreds, AuthenticationState, KeyPair, SignalIdentity, SignalKeyStore, SignedKeyPair } from '../Types/Auth.js';
3
+ import { type BinaryNode, type FullJid } from '../WABinary/index.js';
4
+ import type { USyncQueryResultList } from '../WAUSync/index.js';
5
+ export declare const createSignalIdentity: (wid: string, accountSignatureKey: Uint8Array) => SignalIdentity;
6
+ export declare const getPreKeys: ({ get }: SignalKeyStore, min: number, limit: number) => Promise<{
7
+ [id: string]: KeyPair;
8
+ }>;
9
+ export declare const generateOrGetPreKeys: (creds: AuthenticationCreds, range: number) => {
10
+ newPreKeys: {
11
+ [id: number]: KeyPair;
12
+ };
13
+ lastPreKeyId: number;
14
+ preKeysRange: readonly [number, number];
15
+ };
16
+ export declare const xmppSignedPreKey: (key: SignedKeyPair) => BinaryNode;
17
+ export declare const xmppPreKey: (pair: KeyPair, id: number) => BinaryNode;
18
+ export declare const parseAndInjectE2ESessions: (node: BinaryNode, repository: SignalRepositoryWithLIDStore) => Promise<void>;
19
+ export declare const extractDeviceJids: (result: USyncQueryResultList[], myJid: string, myLid: string, excludeZeroDevices: boolean) => FullJid[];
20
+ /**
21
+ * get the next N keys for upload or processing
22
+ * @param count number of pre-keys to get or generate
23
+ */
24
+ export declare const getNextPreKeys: ({ creds, keys }: AuthenticationState, count: number) => Promise<{
25
+ update: Partial<AuthenticationCreds>;
26
+ preKeys: {
27
+ [id: string]: KeyPair;
28
+ };
29
+ }>;
30
+ export declare const getNextPreKeysNode: (state: AuthenticationState, count: number) => Promise<{
31
+ update: Partial<AuthenticationCreds>;
32
+ node: BinaryNode;
33
+ }>;
34
+ //# sourceMappingURL=signal.d.ts.map
@@ -1,15 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getNextPreKeysNode = exports.getNextPreKeys = exports.extractDeviceJids = exports.parseAndInjectE2ESessions = exports.xmppPreKey = exports.xmppSignedPreKey = exports.generateOrGetPreKeys = exports.getPreKeys = exports.createSignalIdentity = void 0;
4
- const lodash_1 = require("lodash");
5
- const Defaults_1 = require("../Defaults");
6
- const WABinary_1 = require("../WABinary");
7
- const crypto_1 = require("./crypto");
8
- const generics_1 = require("./generics");
4
+ const index_js_1 = require("../Defaults/index.js");
5
+ const index_js_2 = require("../WABinary/index.js");
6
+ const crypto_js_1 = require("./crypto.js");
7
+ const generics_js_1 = require("./generics.js");
8
+ function chunk(array, size) {
9
+ const chunks = [];
10
+ for (let i = 0; i < array.length; i += size) {
11
+ chunks.push(array.slice(i, i + size));
12
+ }
13
+ return chunks;
14
+ }
9
15
  const createSignalIdentity = (wid, accountSignatureKey) => {
10
16
  return {
11
17
  identifier: { name: wid, deviceId: 0 },
12
- identifierKey: (0, crypto_1.generateSignalPubKey)(accountSignatureKey)
18
+ identifierKey: (0, crypto_js_1.generateSignalPubKey)(accountSignatureKey)
13
19
  };
14
20
  };
15
21
  exports.createSignalIdentity = createSignalIdentity;
@@ -28,13 +34,13 @@ const generateOrGetPreKeys = (creds, range) => {
28
34
  const newPreKeys = {};
29
35
  if (remaining > 0) {
30
36
  for (let i = creds.nextPreKeyId; i <= lastPreKeyId; i++) {
31
- newPreKeys[i] = crypto_1.Curve.generateKeyPair();
37
+ newPreKeys[i] = crypto_js_1.Curve.generateKeyPair();
32
38
  }
33
39
  }
34
40
  return {
35
41
  newPreKeys,
36
42
  lastPreKeyId,
37
- preKeysRange: [creds.firstUnuploadedPreKeyId, range],
43
+ preKeysRange: [creds.firstUnuploadedPreKeyId, range]
38
44
  };
39
45
  };
40
46
  exports.generateOrGetPreKeys = generateOrGetPreKeys;
@@ -42,7 +48,7 @@ const xmppSignedPreKey = (key) => ({
42
48
  tag: 'skey',
43
49
  attrs: {},
44
50
  content: [
45
- { tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(key.keyId, 3) },
51
+ { tag: 'id', attrs: {}, content: (0, generics_js_1.encodeBigEndian)(key.keyId, 3) },
46
52
  { tag: 'value', attrs: {}, content: key.keyPair.public },
47
53
  { tag: 'signature', attrs: {}, content: key.signature }
48
54
  ]
@@ -52,20 +58,22 @@ const xmppPreKey = (pair, id) => ({
52
58
  tag: 'key',
53
59
  attrs: {},
54
60
  content: [
55
- { tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(id, 3) },
61
+ { tag: 'id', attrs: {}, content: (0, generics_js_1.encodeBigEndian)(id, 3) },
56
62
  { tag: 'value', attrs: {}, content: pair.public }
57
63
  ]
58
64
  });
59
65
  exports.xmppPreKey = xmppPreKey;
60
66
  const parseAndInjectE2ESessions = async (node, repository) => {
61
- const extractKey = (key) => (key ? ({
62
- keyId: (0, WABinary_1.getBinaryNodeChildUInt)(key, 'id', 3),
63
- publicKey: (0, crypto_1.generateSignalPubKey)((0, WABinary_1.getBinaryNodeChildBuffer)(key, 'value')),
64
- signature: (0, WABinary_1.getBinaryNodeChildBuffer)(key, 'signature'),
65
- }) : undefined);
66
- const nodes = (0, WABinary_1.getBinaryNodeChildren)((0, WABinary_1.getBinaryNodeChild)(node, 'list'), 'user');
67
+ const extractKey = (key) => key
68
+ ? {
69
+ keyId: (0, index_js_2.getBinaryNodeChildUInt)(key, 'id', 3),
70
+ publicKey: (0, crypto_js_1.generateSignalPubKey)((0, index_js_2.getBinaryNodeChildBuffer)(key, 'value')),
71
+ signature: (0, index_js_2.getBinaryNodeChildBuffer)(key, 'signature')
72
+ }
73
+ : undefined;
74
+ const nodes = (0, index_js_2.getBinaryNodeChildren)((0, index_js_2.getBinaryNodeChild)(node, 'list'), 'user');
67
75
  for (const node of nodes) {
68
- (0, WABinary_1.assertNodeErrorFree)(node);
76
+ (0, index_js_2.assertNodeErrorFree)(node);
69
77
  }
70
78
  // Most of the work in repository.injectE2ESession is CPU intensive, not IO
71
79
  // So Promise.all doesn't really help here,
@@ -73,42 +81,51 @@ const parseAndInjectE2ESessions = async (node, repository) => {
73
81
  // This way we chunk it in smaller parts and between those parts we can yield to the event loop
74
82
  // It's rare case when you need to E2E sessions for so many users, but it's possible
75
83
  const chunkSize = 100;
76
- const chunks = (0, lodash_1.chunk)(nodes, chunkSize);
84
+ const chunks = chunk(nodes, chunkSize);
77
85
  for (const nodesChunk of chunks) {
78
- await Promise.all(nodesChunk.map(async (node) => {
79
- const signedKey = (0, WABinary_1.getBinaryNodeChild)(node, 'skey');
80
- const key = (0, WABinary_1.getBinaryNodeChild)(node, 'key');
81
- const identity = (0, WABinary_1.getBinaryNodeChildBuffer)(node, 'identity');
86
+ for (const node of nodesChunk) {
87
+ const signedKey = (0, index_js_2.getBinaryNodeChild)(node, 'skey');
88
+ const key = (0, index_js_2.getBinaryNodeChild)(node, 'key');
89
+ const identity = (0, index_js_2.getBinaryNodeChildBuffer)(node, 'identity');
82
90
  const jid = node.attrs.jid;
83
- const registrationId = (0, WABinary_1.getBinaryNodeChildUInt)(node, 'registration', 4);
91
+ const registrationId = (0, index_js_2.getBinaryNodeChildUInt)(node, 'registration', 4);
84
92
  await repository.injectE2ESession({
85
93
  jid,
86
94
  session: {
87
95
  registrationId: registrationId,
88
- identityKey: (0, crypto_1.generateSignalPubKey)(identity),
96
+ identityKey: (0, crypto_js_1.generateSignalPubKey)(identity),
89
97
  signedPreKey: extractKey(signedKey),
90
98
  preKey: extractKey(key)
91
99
  }
92
100
  });
93
- }));
101
+ }
94
102
  }
95
103
  };
96
104
  exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
97
- const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
98
- const { user: myUser, device: myDevice } = (0, WABinary_1.jidDecode)(myJid);
105
+ const extractDeviceJids = (result, myJid, myLid, excludeZeroDevices) => {
106
+ const { user: myUser, device: myDevice } = (0, index_js_2.jidDecode)(myJid);
99
107
  const extracted = [];
100
108
  for (const userResult of result) {
101
109
  const { devices, id } = userResult;
102
- const { user } = (0, WABinary_1.jidDecode)(id);
103
- const deviceList = devices === null || devices === void 0 ? void 0 : devices.deviceList;
104
- if (Array.isArray(deviceList)) {
105
- for (const { id: device, keyIndex } of deviceList) {
106
- if ((!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
107
- (myUser !== user || myDevice !== device) && // either different user or if me user, not this device
108
- (device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
109
- ) {
110
- extracted.push({ user, device });
110
+ const decoded = (0, index_js_2.jidDecode)(id), { user, server } = decoded;
111
+ let { domainType } = decoded;
112
+ const deviceList = devices?.deviceList;
113
+ if (!Array.isArray(deviceList))
114
+ continue;
115
+ for (const { id: device, keyIndex, isHosted } of deviceList) {
116
+ if ((!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
117
+ ((myUser !== user && myLid !== user) || myDevice !== device) && // either different user or if me user, not this device
118
+ (device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
119
+ ) {
120
+ if (isHosted) {
121
+ domainType = domainType === index_js_2.WAJIDDomains.LID ? index_js_2.WAJIDDomains.HOSTED_LID : index_js_2.WAJIDDomains.HOSTED;
111
122
  }
123
+ extracted.push({
124
+ user,
125
+ device,
126
+ domainType,
127
+ server: (0, index_js_2.getServerFromDomainType)(server, domainType)
128
+ });
112
129
  }
113
130
  }
114
131
  }
@@ -138,11 +155,11 @@ const getNextPreKeysNode = async (state, count) => {
138
155
  attrs: {
139
156
  xmlns: 'encrypt',
140
157
  type: 'set',
141
- to: WABinary_1.S_WHATSAPP_NET,
158
+ to: index_js_2.S_WHATSAPP_NET
142
159
  },
143
160
  content: [
144
- { tag: 'registration', attrs: {}, content: (0, generics_1.encodeBigEndian)(creds.registrationId) },
145
- { tag: 'type', attrs: {}, content: Defaults_1.KEY_BUNDLE_TYPE },
161
+ { tag: 'registration', attrs: {}, content: (0, generics_js_1.encodeBigEndian)(creds.registrationId) },
162
+ { tag: 'type', attrs: {}, content: index_js_1.KEY_BUNDLE_TYPE },
146
163
  { tag: 'identity', attrs: {}, content: creds.signedIdentityKey.public },
147
164
  { tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => (0, exports.xmppPreKey)(preKeys[+k], +k)) },
148
165
  (0, exports.xmppSignedPreKey)(creds.signedPreKey)
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.streamToBuffer = streamToBuffer;
4
+ const stream_1 = require("stream");
5
+ /**
6
+ * Mengonversi Node.js Readable Stream menjadi Buffer.
7
+ * @param {Readable} stream Aliran data yang dapat dibaca.
8
+ * @returns {Promise<Buffer>} Promise yang diselesaikan dengan Buffer berisi semua data dari aliran.
9
+ */
10
+ async function streamToBuffer(stream) {
11
+ const chunks = [];
12
+ return new Promise((resolve, reject) => {
13
+ stream.on('data', chunk => chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)));
14
+ stream.on('end', () => resolve(Buffer.concat(chunks)));
15
+ stream.on('error', reject);
16
+ });
17
+ }