jagproject 26.3.23 → 26.3.26

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 (209) 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 +49 -35
  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 +1181 -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/bridge-runtime.d.ts +1 -0
  104. package/lib/Utils/bridge-runtime.js +14 -0
  105. package/lib/Utils/browser-utils.d.ts +4 -0
  106. package/lib/Utils/browser-utils.js +38 -29
  107. package/lib/Utils/business.d.ts +23 -0
  108. package/lib/Utils/business.js +54 -48
  109. package/lib/Utils/chat-utils.d.ts +70 -0
  110. package/lib/Utils/chat-utils.js +284 -189
  111. package/lib/Utils/crypto.d.ts +37 -0
  112. package/lib/Utils/crypto.js +16 -41
  113. package/lib/Utils/decode-wa-message.d.ts +48 -0
  114. package/lib/Utils/decode-wa-message.js +128 -48
  115. package/lib/Utils/event-buffer.d.ts +34 -0
  116. package/lib/Utils/event-buffer.js +124 -62
  117. package/lib/Utils/generics.d.ts +91 -0
  118. package/lib/Utils/generics.js +154 -138
  119. package/lib/Utils/history.d.ts +22 -0
  120. package/lib/Utils/history.js +77 -34
  121. package/lib/Utils/identity-change-handler.d.ts +37 -0
  122. package/lib/Utils/identity-change-handler.js +54 -0
  123. package/lib/Utils/index.d.ts +22 -0
  124. package/lib/Utils/index.js +32 -19
  125. package/lib/Utils/link-preview.d.ts +21 -0
  126. package/lib/Utils/link-preview.js +12 -17
  127. package/lib/Utils/logger.d.ts +13 -0
  128. package/lib/Utils/lt-hash.d.ts +8 -0
  129. package/lib/Utils/lt-hash.js +2 -43
  130. package/lib/Utils/make-mutex.d.ts +9 -0
  131. package/lib/Utils/make-mutex.js +21 -27
  132. package/lib/Utils/message-retry-manager.d.ts +110 -0
  133. package/lib/Utils/message-retry-manager.js +143 -45
  134. package/lib/Utils/messages-media.d.ts +130 -0
  135. package/lib/Utils/messages-media.js +429 -502
  136. package/lib/Utils/messages-newsletter.d.ts +84 -0
  137. package/lib/Utils/messages-newsletter.js +295 -0
  138. package/lib/Utils/messages.d.ts +92 -0
  139. package/lib/Utils/messages.js +1025 -674
  140. package/lib/Utils/noise-handler.d.ts +20 -0
  141. package/lib/Utils/noise-handler.js +145 -91
  142. package/lib/Utils/pre-key-manager.d.ts +28 -0
  143. package/lib/Utils/pre-key-manager.js +112 -0
  144. package/lib/Utils/process-message.d.ts +60 -0
  145. package/lib/Utils/process-message.js +316 -184
  146. package/lib/Utils/reporting-utils.d.ts +11 -0
  147. package/lib/Utils/reporting-utils.js +262 -0
  148. package/lib/Utils/resolve-jid.d.ts +43 -0
  149. package/lib/Utils/resolve-jid.js +95 -0
  150. package/lib/Utils/rust-bridge-shim.d.ts +22 -0
  151. package/lib/Utils/rust-bridge-shim.js +70 -0
  152. package/lib/Utils/serial-task-queue.js +29 -0
  153. package/lib/Utils/signal.d.ts +34 -0
  154. package/lib/Utils/signal.js +56 -39
  155. package/lib/Utils/streamToBuffer.js +17 -0
  156. package/lib/Utils/sync-action-utils.d.ts +19 -0
  157. package/lib/Utils/sync-action-utils.js +52 -0
  158. package/lib/Utils/tc-token-utils.d.ts +12 -0
  159. package/lib/Utils/tc-token-utils.js +20 -0
  160. package/lib/Utils/use-mongo-file-auth-state.js +71 -0
  161. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  162. package/lib/Utils/use-multi-file-auth-state.js +11 -12
  163. package/lib/Utils/use-single-file-auth-state.js +73 -0
  164. package/lib/Utils/validate-connection.d.ts +11 -0
  165. package/lib/Utils/validate-connection.js +59 -82
  166. package/lib/Utils/wileys-event-stream.js +1 -61
  167. package/lib/WABinary/constants.d.ts +28 -0
  168. package/lib/WABinary/decode.d.ts +7 -0
  169. package/lib/WABinary/decode.js +39 -4
  170. package/lib/WABinary/encode.d.ts +3 -0
  171. package/lib/WABinary/encode.js +17 -11
  172. package/lib/WABinary/generic-utils.d.ts +15 -0
  173. package/lib/WABinary/generic-utils.js +46 -18
  174. package/lib/WABinary/index.d.ts +6 -0
  175. package/lib/WABinary/index.js +9 -5
  176. package/lib/WABinary/jid-utils.d.ts +48 -0
  177. package/lib/WABinary/jid-utils.js +67 -37
  178. package/lib/WABinary/types.d.ts +19 -0
  179. package/lib/WABinary/types.js +34 -0
  180. package/lib/WAM/BinaryInfo.d.ts +9 -0
  181. package/lib/WAM/constants.d.ts +40 -0
  182. package/lib/WAM/constants.js +19183 -11678
  183. package/lib/WAM/encode.d.ts +3 -0
  184. package/lib/WAM/encode.js +15 -17
  185. package/lib/WAM/index.d.ts +4 -0
  186. package/lib/WAM/index.js +3 -3
  187. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  188. package/lib/WAUSync/Protocols/USyncContactProtocol.js +6 -6
  189. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  190. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +9 -9
  191. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  192. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +6 -6
  193. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  194. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -8
  195. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
  196. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +18 -17
  197. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
  198. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +11 -3
  199. package/lib/WAUSync/Protocols/index.d.ts +5 -0
  200. package/lib/WAUSync/Protocols/index.js +6 -4
  201. package/lib/WAUSync/USyncQuery.d.ts +29 -0
  202. package/lib/WAUSync/USyncQuery.js +38 -30
  203. package/lib/WAUSync/USyncUser.d.ts +13 -0
  204. package/lib/WAUSync/index.d.ts +4 -0
  205. package/lib/WAUSync/index.js +3 -3
  206. package/lib/index.d.ts +12 -0
  207. package/lib/index.js +3 -5
  208. package/package.json +7 -4
  209. package/LICENSE +0 -21
@@ -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
+ }
@@ -0,0 +1,19 @@
1
+ import { proto } from '../../WAProto/index.js';
2
+ import type { BaileysEventEmitter, BaileysEventMap, Contact } from '../Types/index.js';
3
+ import type { ILogger } from './logger.js';
4
+ export type ContactsUpsertResult = {
5
+ event: 'contacts.upsert';
6
+ data: Contact[];
7
+ };
8
+ export type LidMappingUpdateResult = {
9
+ event: 'lid-mapping.update';
10
+ data: BaileysEventMap['lid-mapping.update'];
11
+ };
12
+ export type SyncActionResult = ContactsUpsertResult | LidMappingUpdateResult;
13
+ /**
14
+ * Process contactAction and return events to emit.
15
+ * Pure function - no side effects.
16
+ */
17
+ export declare const processContactAction: (action: proto.SyncActionValue.IContactAction, id: string | undefined, logger?: ILogger) => SyncActionResult[];
18
+ export declare const emitSyncActionResults: (ev: BaileysEventEmitter, results: SyncActionResult[]) => void;
19
+ //# sourceMappingURL=sync-action-utils.d.ts.map
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.emitSyncActionResults = exports.processContactAction = void 0;
4
+ const index_js_1 = require("../../WAProto/index.js");
5
+ const index_js_2 = require("../WABinary/index.js");
6
+ /**
7
+ * Process contactAction and return events to emit.
8
+ * Pure function - no side effects.
9
+ */
10
+ const processContactAction = (action, id, logger) => {
11
+ const results = [];
12
+ if (!id) {
13
+ logger?.warn({ hasFullName: !!action.fullName, hasLidJid: !!action.lidJid, hasPnJid: !!action.pnJid }, 'contactAction sync: missing id in index');
14
+ return results;
15
+ }
16
+ const lidJid = action.lidJid;
17
+ const idIsPn = (0, index_js_2.isPnUser)(id);
18
+ // PN is in index[1], not in contactAction.pnJid which is usually null
19
+ const phoneNumber = idIsPn ? id : action.pnJid || undefined;
20
+ // Always emit contacts.upsert
21
+ results.push({
22
+ event: 'contacts.upsert',
23
+ data: [
24
+ {
25
+ id,
26
+ name: action.fullName || action.firstName || action.username || undefined,
27
+ lid: lidJid || undefined,
28
+ phoneNumber
29
+ }
30
+ ]
31
+ });
32
+ // Emit lid-mapping.update if we have valid LID-PN pair
33
+ if (lidJid && (0, index_js_2.isLidUser)(lidJid) && idIsPn) {
34
+ results.push({
35
+ event: 'lid-mapping.update',
36
+ data: { lid: lidJid, pn: id }
37
+ });
38
+ }
39
+ return results;
40
+ };
41
+ exports.processContactAction = processContactAction;
42
+ const emitSyncActionResults = (ev, results) => {
43
+ for (const result of results) {
44
+ if (result.event === 'contacts.upsert') {
45
+ ev.emit('contacts.upsert', result.data);
46
+ }
47
+ else {
48
+ ev.emit('lid-mapping.update', result.data);
49
+ }
50
+ }
51
+ };
52
+ exports.emitSyncActionResults = emitSyncActionResults;
@@ -0,0 +1,12 @@
1
+ import type { SignalKeyStoreWithTransaction } from '../Types/index.js';
2
+ import type { BinaryNode } from '../WABinary/index.js';
3
+ type TcTokenParams = {
4
+ jid: string;
5
+ baseContent?: BinaryNode[];
6
+ authState: {
7
+ keys: SignalKeyStoreWithTransaction;
8
+ };
9
+ };
10
+ export declare function buildTcTokenFromJid({ authState, jid, baseContent }: TcTokenParams): Promise<BinaryNode[] | undefined>;
11
+ export {};
12
+ //# sourceMappingURL=tc-token-utils.d.ts.map
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildTcTokenFromJid = buildTcTokenFromJid;
4
+ async function buildTcTokenFromJid({ authState, jid, baseContent = [] }) {
5
+ try {
6
+ const tcTokenData = await authState.keys.get('tctoken', [jid]);
7
+ const tcTokenBuffer = tcTokenData?.[jid]?.token;
8
+ if (!tcTokenBuffer)
9
+ return baseContent.length > 0 ? baseContent : undefined;
10
+ baseContent.push({
11
+ tag: 'tctoken',
12
+ attrs: {},
13
+ content: tcTokenBuffer
14
+ });
15
+ return baseContent;
16
+ }
17
+ catch (error) {
18
+ return baseContent.length > 0 ? baseContent : undefined;
19
+ }
20
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useMongoFileAuthState = void 0;
4
+ const index_js_1 = require("../../WAProto/index.js");
5
+ const auth_utils_js_1 = require("./auth-utils.js");
6
+ const generics_js_1 = require("./generics.js");
7
+ /*
8
+ code from amiruldev readjusted by @irull2nd, don't delete WM!
9
+ */
10
+ const useMongoFileAuthState = async (collection) => {
11
+ const writeData = (data, id) => {
12
+ const informationToStore = JSON.parse(JSON.stringify(data, generics_js_1.BufferJSON.replacer));
13
+ const update = {
14
+ $set: {
15
+ ...informationToStore,
16
+ },
17
+ };
18
+ return collection.updateOne({ _id: id }, update, { upsert: true });
19
+ };
20
+ const readData = async (id) => {
21
+ try {
22
+ const data = JSON.stringify(await collection.findOne({ _id: id }));
23
+ return JSON.parse(data, generics_js_1.BufferJSON.reviver);
24
+ }
25
+ catch (err) {
26
+ console.log(err);
27
+ }
28
+ };
29
+ const removeData = async (id) => {
30
+ try {
31
+ await collection.deleteOne({ _id: id });
32
+ }
33
+ catch (err) {
34
+ console.log('error', err);
35
+ }
36
+ };
37
+ const creds = (await readData('creds')) || (0, auth_utils_js_1.initAuthCreds)();
38
+ return {
39
+ state: {
40
+ creds,
41
+ keys: {
42
+ get: async (type, ids) => {
43
+ const data = {};
44
+ await Promise.all(ids.map(async (id) => {
45
+ let value = await readData(`${type}-${id}`);
46
+ if (type === 'app-state-sync-key') {
47
+ value = index_js_1.proto.Message.AppStateSyncKeyData.fromObject(data);
48
+ }
49
+ data[id] = value;
50
+ }));
51
+ return data;
52
+ },
53
+ set: async (data) => {
54
+ const tasks = [];
55
+ for (const category of Object.keys(data)) {
56
+ for (const id of Object.keys(data[category])) {
57
+ const value = data[category][id];
58
+ const key = `${category}-${id}`;
59
+ tasks.push(value ? writeData(value, key) : removeData(key));
60
+ }
61
+ }
62
+ await Promise.all(tasks);
63
+ },
64
+ },
65
+ },
66
+ saveCreds: () => {
67
+ return writeData(creds, 'creds');
68
+ }
69
+ };
70
+ };
71
+ exports.useMongoFileAuthState = useMongoFileAuthState;
@@ -0,0 +1,13 @@
1
+ import type { AuthenticationState } from '../Types/index.js';
2
+ /**
3
+ * stores the full authentication state in a single folder.
4
+ * Far more efficient than singlefileauthstate
5
+ *
6
+ * Again, I wouldn't endorse this for any production level use other than perhaps a bot.
7
+ * Would recommend writing an auth state for use with a proper SQL or No-SQL DB
8
+ * */
9
+ export declare const useMultiFileAuthState: (folder: string) => Promise<{
10
+ state: AuthenticationState;
11
+ saveCreds: () => Promise<void>;
12
+ }>;
13
+ //# sourceMappingURL=use-multi-file-auth-state.d.ts.map
@@ -4,11 +4,11 @@ exports.useMultiFileAuthState = void 0;
4
4
  const async_mutex_1 = require("async-mutex");
5
5
  const promises_1 = require("fs/promises");
6
6
  const path_1 = require("path");
7
- const WAProto_1 = require("../../WAProto");
8
- const auth_utils_1 = require("./auth-utils");
9
- const generics_1 = require("./generics");
7
+ const index_js_1 = require("../../WAProto/index.js");
8
+ const auth_utils_js_1 = require("./auth-utils.js");
9
+ const generics_js_1 = require("./generics.js");
10
10
  // We need to lock files due to the fact that we are using async functions to read and write files
11
- // https://github.com/WhiskeySockets/Wileys/issues/794
11
+ // https://github.com/WhiskeySockets/Baileys/issues/794
12
12
  // https://github.com/nodejs/node/issues/26338
13
13
  // Use a Map to store mutexes for each file path
14
14
  const fileLocks = new Map();
@@ -35,7 +35,7 @@ const useMultiFileAuthState = async (folder) => {
35
35
  const mutex = getFileLock(filePath);
36
36
  return mutex.acquire().then(async (release) => {
37
37
  try {
38
- await (0, promises_1.writeFile)(filePath, JSON.stringify(data, generics_1.BufferJSON.replacer));
38
+ await (0, promises_1.writeFile)(filePath, JSON.stringify(data, generics_js_1.BufferJSON.replacer));
39
39
  }
40
40
  finally {
41
41
  release();
@@ -49,7 +49,7 @@ const useMultiFileAuthState = async (folder) => {
49
49
  return await mutex.acquire().then(async (release) => {
50
50
  try {
51
51
  const data = await (0, promises_1.readFile)(filePath, { encoding: 'utf-8' });
52
- return JSON.parse(data, generics_1.BufferJSON.reviver);
52
+ return JSON.parse(data, generics_js_1.BufferJSON.reviver);
53
53
  }
54
54
  finally {
55
55
  release();
@@ -68,15 +68,14 @@ const useMultiFileAuthState = async (folder) => {
68
68
  try {
69
69
  await (0, promises_1.unlink)(filePath);
70
70
  }
71
- catch (_a) {
71
+ catch {
72
72
  }
73
73
  finally {
74
74
  release();
75
75
  }
76
76
  });
77
77
  }
78
- catch (_a) {
79
- }
78
+ catch { }
80
79
  };
81
80
  const folderInfo = await (0, promises_1.stat)(folder).catch(() => { });
82
81
  if (folderInfo) {
@@ -87,8 +86,8 @@ const useMultiFileAuthState = async (folder) => {
87
86
  else {
88
87
  await (0, promises_1.mkdir)(folder, { recursive: true });
89
88
  }
90
- const fixFileName = (file) => { var _a; return (_a = file === null || file === void 0 ? void 0 : file.replace(/\//g, '__')) === null || _a === void 0 ? void 0 : _a.replace(/:/g, '-'); };
91
- const creds = await readData('creds.json') || (0, auth_utils_1.initAuthCreds)();
89
+ const fixFileName = (file) => file?.replace(/\//g, '__')?.replace(/:/g, '-');
90
+ const creds = (await readData('creds.json')) || (0, auth_utils_js_1.initAuthCreds)();
92
91
  return {
93
92
  state: {
94
93
  creds,
@@ -98,7 +97,7 @@ const useMultiFileAuthState = async (folder) => {
98
97
  await Promise.all(ids.map(async (id) => {
99
98
  let value = await readData(`${type}-${id}.json`);
100
99
  if (type === 'app-state-sync-key' && value) {
101
- value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value);
100
+ value = index_js_1.proto.Message.AppStateSyncKeyData.fromObject(value);
102
101
  }
103
102
  data[id] = value;
104
103
  }));
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSingleFileAuthState = void 0;
4
+ const index_js_1 = require("../../WAProto/index.js");
5
+ const auth_utils_js_1 = require("./auth-utils.js");
6
+ const generics_js_1 = require("./generics.js");
7
+ // useless key map only there to maintain backwards compatibility
8
+ // do not use in your own systems please
9
+ const KEY_MAP = {
10
+ 'pre-key': 'preKeys',
11
+ 'session': 'sessions',
12
+ 'sender-key': 'senderKeys',
13
+ 'app-state-sync-key': 'appStateSyncKeys',
14
+ 'app-state-sync-version': 'appStateVersions',
15
+ 'sender-key-memory': 'senderKeyMemory'
16
+ };
17
+ /**
18
+ * @deprecated use multi file auth state instead please
19
+ * stores the full authentication state in a single JSON file
20
+ *
21
+ * DO NOT USE IN A PROD ENVIRONMENT, only meant to serve as an example
22
+ * */
23
+ const useSingleFileAuthState = (filename, logger) => {
24
+ const { readFileSync, writeFileSync, existsSync } = require('fs');
25
+ let creds;
26
+ let keys = {};
27
+ // save the authentication state to a file
28
+ const saveState = () => {
29
+ logger && logger.trace('saving auth state');
30
+ writeFileSync(filename,
31
+ // BufferJSON replacer utility saves buffers nicely
32
+ JSON.stringify({ creds, keys }, generics_js_1.BufferJSON.replacer, 2));
33
+ };
34
+ if (existsSync(filename)) {
35
+ const result = JSON.parse(readFileSync(filename, { encoding: 'utf-8' }), generics_js_1.BufferJSON.reviver);
36
+ creds = result.creds;
37
+ keys = result.keys;
38
+ }
39
+ else {
40
+ creds = (0, auth_utils_js_1.initAuthCreds)();
41
+ keys = {};
42
+ }
43
+ return {
44
+ state: {
45
+ creds,
46
+ keys: {
47
+ get: (type, ids) => {
48
+ const key = KEY_MAP[type];
49
+ return ids.reduce((dict, id) => {
50
+ let value = keys[key]?.[id];
51
+ if (value) {
52
+ if (type === 'app-state-sync-key') {
53
+ value = index_js_1.proto.Message.AppStateSyncKeyData.fromObject(value);
54
+ }
55
+ dict[id] = value;
56
+ }
57
+ return dict;
58
+ }, {});
59
+ },
60
+ set: (data) => {
61
+ for (const _key in data) {
62
+ const key = KEY_MAP[_key];
63
+ keys[key] = keys[key] || {};
64
+ Object.assign(keys[key], data[_key]);
65
+ }
66
+ saveState();
67
+ }
68
+ }
69
+ },
70
+ saveState
71
+ };
72
+ };
73
+ exports.useSingleFileAuthState = useSingleFileAuthState;
@@ -0,0 +1,11 @@
1
+ import { proto } from '../../WAProto/index.js';
2
+ import type { AuthenticationCreds, SignalCreds, SocketConfig } from '../Types/index.js';
3
+ import { type BinaryNode } from '../WABinary/index.js';
4
+ export declare const generateLoginNode: (userJid: string, config: SocketConfig) => proto.IClientPayload;
5
+ export declare const generateRegistrationNode: ({ registrationId, signedPreKey, signedIdentityKey }: SignalCreds, config: SocketConfig) => proto.ClientPayload;
6
+ export declare const configureSuccessfulPairing: (stanza: BinaryNode, { advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds, "advSecretKey" | "signedIdentityKey" | "signalIdentities">) => {
7
+ creds: Partial<AuthenticationCreds>;
8
+ reply: BinaryNode;
9
+ };
10
+ export declare const encodeSignedDeviceIdentity: (account: proto.IADVSignedDeviceIdentity, includeSignatureKey: boolean) => Uint8Array<ArrayBufferLike>;
11
+ //# sourceMappingURL=validate-connection.d.ts.map