@alannxd/baileys 6.0.5 → 6.0.6

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 (234) hide show
  1. package/WAProto/fix-import.js +29 -0
  2. package/WAProto/index.js +160 -201
  3. package/engine-requirements.js +1 -1
  4. package/lib/Defaults/baileys-version.json +3 -0
  5. package/lib/Defaults/index.d.ts +15 -37
  6. package/lib/Defaults/index.js +136 -119
  7. package/lib/Defaults/phonenumber-mcc.json +223 -0
  8. package/lib/Signal/Group/ciphertext-message.d.ts +0 -1
  9. package/lib/Signal/Group/ciphertext-message.js +5 -2
  10. package/lib/Signal/Group/group-session-builder.d.ts +3 -4
  11. package/lib/Signal/Group/group-session-builder.js +41 -7
  12. package/lib/Signal/Group/group_cipher.d.ts +4 -4
  13. package/lib/Signal/Group/group_cipher.js +51 -37
  14. package/lib/Signal/Group/index.d.ts +11 -12
  15. package/lib/Signal/Group/index.js +57 -12
  16. package/lib/Signal/Group/keyhelper.d.ts +1 -2
  17. package/lib/Signal/Group/keyhelper.js +44 -7
  18. package/lib/Signal/Group/queue-job.d.ts +1 -0
  19. package/lib/Signal/Group/queue-job.js +57 -0
  20. package/lib/Signal/Group/sender-chain-key.d.ts +2 -3
  21. package/lib/Signal/Group/sender-chain-key.js +15 -7
  22. package/lib/Signal/Group/sender-key-distribution-message.d.ts +1 -2
  23. package/lib/Signal/Group/sender-key-distribution-message.js +11 -8
  24. package/lib/Signal/Group/sender-key-message.d.ts +1 -2
  25. package/lib/Signal/Group/sender-key-message.js +12 -9
  26. package/lib/Signal/Group/sender-key-name.d.ts +0 -1
  27. package/lib/Signal/Group/sender-key-name.js +5 -2
  28. package/lib/Signal/Group/sender-key-record.d.ts +2 -3
  29. package/lib/Signal/Group/sender-key-record.js +21 -9
  30. package/lib/Signal/Group/sender-key-state.d.ts +6 -7
  31. package/lib/Signal/Group/sender-key-state.js +42 -27
  32. package/lib/Signal/Group/sender-message-key.d.ts +0 -1
  33. package/lib/Signal/Group/sender-message-key.js +7 -4
  34. package/lib/Signal/libsignal.d.ts +3 -5
  35. package/lib/Signal/libsignal.js +90 -347
  36. package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +5 -4
  37. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  38. package/lib/Socket/Client/index.d.ts +3 -3
  39. package/lib/Socket/Client/index.js +19 -3
  40. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  41. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  42. package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +2 -3
  43. package/lib/Socket/Client/web-socket-client.js +62 -0
  44. package/lib/Socket/business.d.ts +108 -154
  45. package/lib/Socket/business.js +43 -162
  46. package/lib/Socket/chats.d.ts +239 -96
  47. package/lib/Socket/chats.js +427 -627
  48. package/lib/Socket/communities.d.ts +146 -239
  49. package/lib/Socket/communities.js +80 -90
  50. package/lib/Socket/groups.d.ts +57 -104
  51. package/lib/Socket/groups.js +161 -154
  52. package/lib/Socket/index.d.ts +115 -202
  53. package/lib/Socket/index.js +10 -11
  54. package/lib/Socket/luxu.d.ts +266 -22
  55. package/lib/Socket/luxu.js +465 -422
  56. package/lib/Socket/messages-recv.d.ts +84 -136
  57. package/lib/Socket/messages-recv.js +615 -1421
  58. package/lib/Socket/messages-send.d.ts +126 -142
  59. package/lib/Socket/messages-send.js +671 -878
  60. package/lib/Socket/newsletter.d.ts +85 -121
  61. package/lib/Socket/newsletter.js +272 -147
  62. package/lib/Socket/registration.d.ts +267 -0
  63. package/lib/Socket/registration.js +166 -0
  64. package/lib/Socket/socket.d.ts +19 -34
  65. package/lib/Socket/socket.js +313 -544
  66. package/lib/Socket/usync.d.ts +36 -0
  67. package/lib/Socket/usync.js +70 -0
  68. package/lib/Store/index.d.ts +3 -10
  69. package/lib/Store/index.js +10 -10
  70. package/lib/Store/make-cache-manager-store.d.ts +11 -17
  71. package/lib/Store/make-cache-manager-store.js +41 -43
  72. package/lib/Store/make-in-memory-store.d.ts +118 -39
  73. package/lib/Store/make-in-memory-store.js +341 -112
  74. package/lib/Store/make-ordered-dictionary.d.ts +10 -11
  75. package/lib/Store/make-ordered-dictionary.js +20 -14
  76. package/lib/Store/object-repository.d.ts +9 -10
  77. package/lib/Store/object-repository.js +6 -11
  78. package/lib/Types/Auth.d.ts +12 -19
  79. package/lib/Types/Auth.js +2 -2
  80. package/lib/Types/Call.d.ts +1 -3
  81. package/lib/Types/Call.js +2 -2
  82. package/lib/Types/Chat.d.ts +13 -35
  83. package/lib/Types/Chat.js +4 -8
  84. package/lib/Types/Contact.d.ts +1 -8
  85. package/lib/Types/Contact.js +2 -2
  86. package/lib/Types/Events.d.ts +17 -116
  87. package/lib/Types/Events.js +2 -2
  88. package/lib/Types/GroupMetadata.d.ts +5 -21
  89. package/lib/Types/GroupMetadata.js +2 -2
  90. package/lib/Types/Label.d.ts +0 -12
  91. package/lib/Types/Label.js +5 -3
  92. package/lib/Types/LabelAssociation.d.ts +0 -1
  93. package/lib/Types/LabelAssociation.js +5 -3
  94. package/lib/Types/Message.d.ts +58 -105
  95. package/lib/Types/Message.js +9 -11
  96. package/lib/Types/Newsletter.d.ts +103 -0
  97. package/lib/Types/Newsletter.js +38 -0
  98. package/lib/Types/Product.d.ts +1 -2
  99. package/lib/Types/Product.js +2 -2
  100. package/lib/Types/Signal.d.ts +2 -32
  101. package/lib/Types/Signal.js +2 -2
  102. package/lib/Types/Socket.d.ts +25 -50
  103. package/lib/Types/Socket.js +2 -3
  104. package/lib/Types/State.d.ts +2 -72
  105. package/lib/Types/State.js +2 -56
  106. package/lib/Types/USync.d.ts +2 -3
  107. package/lib/Types/USync.js +2 -2
  108. package/lib/Types/index.d.ts +14 -22
  109. package/lib/Types/index.js +31 -15
  110. package/lib/Utils/auth-utils.d.ts +6 -12
  111. package/lib/Utils/auth-utils.js +143 -239
  112. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  113. package/lib/Utils/baileys-event-stream.js +63 -0
  114. package/lib/Utils/business.d.ts +2 -3
  115. package/lib/Utils/business.js +69 -66
  116. package/lib/Utils/chat-utils.d.ts +23 -52
  117. package/lib/Utils/chat-utils.js +253 -396
  118. package/lib/Utils/crypto.d.ts +22 -18
  119. package/lib/Utils/crypto.js +90 -57
  120. package/lib/Utils/decode-wa-message.d.ts +8 -55
  121. package/lib/Utils/decode-wa-message.js +84 -203
  122. package/lib/Utils/event-buffer.d.ts +8 -9
  123. package/lib/Utils/event-buffer.js +77 -185
  124. package/lib/Utils/generics.d.ts +29 -28
  125. package/lib/Utils/generics.js +210 -180
  126. package/lib/Utils/history.d.ts +9 -18
  127. package/lib/Utils/history.js +55 -93
  128. package/lib/Utils/index.d.ts +17 -22
  129. package/lib/Utils/index.js +33 -22
  130. package/lib/Utils/link-preview.d.ts +5 -5
  131. package/lib/Utils/link-preview.js +24 -16
  132. package/lib/Utils/logger.d.ts +3 -11
  133. package/lib/Utils/logger.js +7 -3
  134. package/lib/Utils/lt-hash.d.ts +12 -8
  135. package/lib/Utils/lt-hash.js +46 -3
  136. package/lib/Utils/make-mutex.d.ts +2 -4
  137. package/lib/Utils/make-mutex.js +34 -24
  138. package/lib/Utils/messages-media.d.ts +44 -61
  139. package/lib/Utils/messages-media.js +482 -451
  140. package/lib/Utils/messages.d.ts +18 -32
  141. package/lib/Utils/messages.js +369 -458
  142. package/lib/Utils/noise-handler.d.ts +14 -13
  143. package/lib/Utils/noise-handler.js +99 -145
  144. package/lib/Utils/process-message.d.ts +12 -31
  145. package/lib/Utils/process-message.js +150 -459
  146. package/lib/Utils/signal.d.ts +5 -20
  147. package/lib/Utils/signal.js +72 -120
  148. package/lib/Utils/use-multi-file-auth-state.d.ts +2 -2
  149. package/lib/Utils/use-multi-file-auth-state.js +27 -29
  150. package/lib/Utils/validate-connection.d.ts +7 -7
  151. package/lib/Utils/validate-connection.js +99 -73
  152. package/lib/WABinary/constants.d.ts +27 -25
  153. package/lib/WABinary/constants.js +20 -1281
  154. package/lib/WABinary/decode.d.ts +5 -5
  155. package/lib/WABinary/decode.js +42 -52
  156. package/lib/WABinary/encode.d.ts +3 -3
  157. package/lib/WABinary/encode.js +155 -110
  158. package/lib/WABinary/generic-utils.d.ts +7 -8
  159. package/lib/WABinary/generic-utils.js +49 -48
  160. package/lib/WABinary/index.d.ts +5 -6
  161. package/lib/WABinary/index.js +21 -6
  162. package/lib/WABinary/jid-utils.d.ts +8 -25
  163. package/lib/WABinary/jid-utils.js +40 -74
  164. package/lib/WABinary/types.d.ts +1 -2
  165. package/lib/WABinary/types.js +2 -2
  166. package/lib/WAM/BinaryInfo.d.ts +11 -3
  167. package/lib/WAM/BinaryInfo.js +5 -2
  168. package/lib/WAM/constants.d.ts +3 -5
  169. package/lib/WAM/constants.js +11958 -19461
  170. package/lib/WAM/encode.d.ts +3 -3
  171. package/lib/WAM/encode.js +22 -17
  172. package/lib/WAM/index.d.ts +3 -4
  173. package/lib/WAM/index.js +19 -4
  174. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +3 -4
  175. package/lib/WAUSync/Protocols/USyncContactProtocol.js +13 -33
  176. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -3
  177. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
  178. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -3
  179. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -9
  180. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -3
  181. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
  182. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +3 -4
  183. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
  184. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -5
  185. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +8 -13
  186. package/lib/WAUSync/Protocols/index.d.ts +4 -6
  187. package/lib/WAUSync/Protocols/index.js +20 -6
  188. package/lib/WAUSync/USyncQuery.d.ts +4 -6
  189. package/lib/WAUSync/USyncQuery.js +35 -44
  190. package/lib/WAUSync/USyncUser.d.ts +5 -10
  191. package/lib/WAUSync/USyncUser.js +5 -10
  192. package/lib/WAUSync/index.js +19 -4
  193. package/lib/index.d.ts +9 -10
  194. package/lib/index.js +34 -12
  195. package/package.json +50 -83
  196. package/WAProto/GenerateStatics.sh +0 -3
  197. package/WAProto/WAProto.proto +0 -5479
  198. package/WAProto/fix-imports.js +0 -85
  199. package/WAProto/index.d.ts +0 -14017
  200. package/lib/Signal/lid-mapping.d.ts +0 -23
  201. package/lib/Signal/lid-mapping.js +0 -277
  202. package/lib/Socket/Client/types.js +0 -11
  203. package/lib/Socket/Client/websocket.js +0 -54
  204. package/lib/Socket/mex.d.ts +0 -3
  205. package/lib/Socket/mex.js +0 -42
  206. package/lib/Store/keyed-db.d.ts +0 -22
  207. package/lib/Store/keyed-db.js +0 -108
  208. package/lib/Types/Bussines.d.ts +0 -25
  209. package/lib/Types/Bussines.js +0 -2
  210. package/lib/Types/Mex.d.ts +0 -141
  211. package/lib/Types/Mex.js +0 -37
  212. package/lib/Utils/browser-utils.d.ts +0 -4
  213. package/lib/Utils/browser-utils.js +0 -28
  214. package/lib/Utils/companion-reg-client-utils.d.ts +0 -17
  215. package/lib/Utils/companion-reg-client-utils.js +0 -35
  216. package/lib/Utils/identity-change-handler.d.ts +0 -44
  217. package/lib/Utils/identity-change-handler.js +0 -50
  218. package/lib/Utils/message-retry-manager.d.ts +0 -115
  219. package/lib/Utils/message-retry-manager.js +0 -265
  220. package/lib/Utils/offline-node-processor.d.ts +0 -17
  221. package/lib/Utils/offline-node-processor.js +0 -40
  222. package/lib/Utils/pre-key-manager.d.ts +0 -28
  223. package/lib/Utils/pre-key-manager.js +0 -106
  224. package/lib/Utils/reporting-utils.d.ts +0 -11
  225. package/lib/Utils/reporting-utils.js +0 -258
  226. package/lib/Utils/stanza-ack.d.ts +0 -11
  227. package/lib/Utils/stanza-ack.js +0 -38
  228. package/lib/Utils/sync-action-utils.d.ts +0 -19
  229. package/lib/Utils/sync-action-utils.js +0 -49
  230. package/lib/Utils/tc-token-utils.d.ts +0 -37
  231. package/lib/Utils/tc-token-utils.js +0 -163
  232. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +0 -10
  233. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +0 -25
  234. package/lib/WAUSync/index.d.ts +0 -4
@@ -1,7 +1,6 @@
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';
1
+ import { SignalRepository } from '../Types';
2
+ import { AuthenticationCreds, AuthenticationState, KeyPair, SignalIdentity, SignalKeyStore, SignedKeyPair } from '../Types/Auth';
3
+ import { BinaryNode, JidWithDevice } from '../WABinary';
5
4
  export declare const createSignalIdentity: (wid: string, accountSignatureKey: Uint8Array) => SignalIdentity;
6
5
  export declare const getPreKeys: ({ get }: SignalKeyStore, min: number, limit: number) => Promise<{
7
6
  [id: string]: KeyPair;
@@ -15,21 +14,8 @@ export declare const generateOrGetPreKeys: (creds: AuthenticationCreds, range: n
15
14
  };
16
15
  export declare const xmppSignedPreKey: (key: SignedKeyPair) => BinaryNode;
17
16
  export declare const xmppPreKey: (pair: KeyPair, id: number) => BinaryNode;
18
- export declare const extractE2ESessionFromRetryReceipt: (receipt: BinaryNode) => {
19
- registrationId: number;
20
- identityKey: Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike>;
21
- signedPreKey: {
22
- keyId: number;
23
- publicKey: Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike>;
24
- signature: Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike>;
25
- };
26
- preKey: {
27
- keyId: number;
28
- publicKey: Uint8Array;
29
- } | undefined;
30
- } | null;
31
- export declare const parseAndInjectE2ESessions: (node: BinaryNode, repository: SignalRepositoryWithLIDStore) => Promise<void>;
32
- export declare const extractDeviceJids: (result: USyncQueryResultList[], myJid: string, myLid: string, excludeZeroDevices: boolean) => FullJid[];
17
+ export declare const parseAndInjectE2ESessions: (node: BinaryNode, repository: SignalRepository) => Promise<void>;
18
+ export declare const extractDeviceJids: (result: BinaryNode, myJid: string, excludeZeroDevices: boolean) => JidWithDevice[];
33
19
  /**
34
20
  * get the next N keys for upload or processing
35
21
  * @param count number of pre-keys to get or generate
@@ -44,4 +30,3 @@ export declare const getNextPreKeysNode: (state: AuthenticationState, count: num
44
30
  update: Partial<AuthenticationCreds>;
45
31
  node: BinaryNode;
46
32
  }>;
47
- //# sourceMappingURL=signal.d.ts.map
@@ -1,201 +1,153 @@
1
- import { KEY_BUNDLE_TYPE } from '../Defaults/index.js';
2
- import { assertNodeErrorFree, getBinaryNodeChild, getBinaryNodeChildBuffer, getBinaryNodeChildren, getBinaryNodeChildUInt, getServerFromDomainType, jidDecode, S_WHATSAPP_NET, WAJIDDomains } from '../WABinary/index.js';
3
- import { Curve, generateSignalPubKey } from './crypto.js';
4
- import { encodeBigEndian } from './generics.js';
5
- function chunk(array, size) {
6
- const chunks = [];
7
- for (let i = 0; i < array.length; i += size) {
8
- chunks.push(array.slice(i, i + size));
9
- }
10
- return chunks;
11
- }
12
- export const createSignalIdentity = (wid, accountSignatureKey) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNextPreKeysNode = exports.getNextPreKeys = exports.extractDeviceJids = exports.parseAndInjectE2ESessions = exports.xmppPreKey = exports.xmppSignedPreKey = exports.generateOrGetPreKeys = exports.getPreKeys = exports.createSignalIdentity = void 0;
4
+ const Defaults_1 = require("../Defaults");
5
+ const WABinary_1 = require("../WABinary");
6
+ const crypto_1 = require("./crypto");
7
+ const lodash_1 = require("lodash")
8
+ const generics_1 = require("./generics");
9
+ const createSignalIdentity = (wid, accountSignatureKey) => {
13
10
  return {
14
11
  identifier: { name: wid, deviceId: 0 },
15
- identifierKey: generateSignalPubKey(accountSignatureKey)
12
+ identifierKey: (0, crypto_1.generateSignalPubKey)(accountSignatureKey)
16
13
  };
17
14
  };
18
- export const getPreKeys = async ({ get }, min, limit) => {
15
+ exports.createSignalIdentity = createSignalIdentity;
16
+ const getPreKeys = async ({ get }, min, limit) => {
19
17
  const idList = [];
20
18
  for (let id = min; id < limit; id++) {
21
19
  idList.push(id.toString());
22
20
  }
23
21
  return get('pre-key', idList);
24
22
  };
25
- export const generateOrGetPreKeys = (creds, range) => {
23
+ exports.getPreKeys = getPreKeys;
24
+ const generateOrGetPreKeys = (creds, range) => {
26
25
  const avaliable = creds.nextPreKeyId - creds.firstUnuploadedPreKeyId;
27
26
  const remaining = range - avaliable;
28
27
  const lastPreKeyId = creds.nextPreKeyId + remaining - 1;
29
28
  const newPreKeys = {};
30
29
  if (remaining > 0) {
31
30
  for (let i = creds.nextPreKeyId; i <= lastPreKeyId; i++) {
32
- newPreKeys[i] = Curve.generateKeyPair();
31
+ newPreKeys[i] = crypto_1.Curve.generateKeyPair();
33
32
  }
34
33
  }
35
34
  return {
36
35
  newPreKeys,
37
36
  lastPreKeyId,
38
- preKeysRange: [creds.firstUnuploadedPreKeyId, range]
37
+ preKeysRange: [creds.firstUnuploadedPreKeyId, range],
39
38
  };
40
39
  };
41
- export const xmppSignedPreKey = (key) => ({
40
+ exports.generateOrGetPreKeys = generateOrGetPreKeys;
41
+ const xmppSignedPreKey = (key) => ({
42
42
  tag: 'skey',
43
43
  attrs: {},
44
44
  content: [
45
- { tag: 'id', attrs: {}, content: encodeBigEndian(key.keyId, 3) },
45
+ { tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(key.keyId, 3) },
46
46
  { tag: 'value', attrs: {}, content: key.keyPair.public },
47
47
  { tag: 'signature', attrs: {}, content: key.signature }
48
48
  ]
49
49
  });
50
- export const xmppPreKey = (pair, id) => ({
50
+ exports.xmppSignedPreKey = xmppSignedPreKey;
51
+ const xmppPreKey = (pair, id) => ({
51
52
  tag: 'key',
52
53
  attrs: {},
53
54
  content: [
54
- { tag: 'id', attrs: {}, content: encodeBigEndian(id, 3) },
55
+ { tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(id, 3) },
55
56
  { tag: 'value', attrs: {}, content: pair.public }
56
57
  ]
57
58
  });
58
- const isValidUInt = (n) => typeof n === 'number' && Number.isInteger(n);
59
- export const extractE2ESessionFromRetryReceipt = (receipt) => {
60
- const keysNode = getBinaryNodeChild(receipt, 'keys');
61
- if (!keysNode)
62
- return null;
63
- const typeBuf = getBinaryNodeChildBuffer(keysNode, 'type');
64
- if (!typeBuf || typeBuf.length !== 1 || typeBuf[0] !== KEY_BUNDLE_TYPE[0])
65
- return null;
66
- const identity = getBinaryNodeChildBuffer(keysNode, 'identity');
67
- const skey = getBinaryNodeChild(keysNode, 'skey');
68
- if (!identity || identity.length !== 32 || !skey)
69
- return null;
70
- const registrationId = getBinaryNodeChildUInt(receipt, 'registration', 4);
71
- if (!isValidUInt(registrationId))
72
- return null;
73
- const signedPubKey = getBinaryNodeChildBuffer(skey, 'value');
74
- const signedSig = getBinaryNodeChildBuffer(skey, 'signature');
75
- const signedKeyId = getBinaryNodeChildUInt(skey, 'id', 3);
76
- if (!signedPubKey || signedPubKey.length !== 32 || !signedSig || !isValidUInt(signedKeyId)) {
77
- return null;
78
- }
79
- const preKeyNode = getBinaryNodeChild(keysNode, 'key');
80
- let preKey;
81
- if (preKeyNode) {
82
- const preKeyPub = getBinaryNodeChildBuffer(preKeyNode, 'value');
83
- const preKeyId = getBinaryNodeChildUInt(preKeyNode, 'id', 3);
84
- if (!preKeyPub || preKeyPub.length !== 32 || !isValidUInt(preKeyId)) {
85
- return null;
86
- }
87
- preKey = { keyId: preKeyId, publicKey: generateSignalPubKey(preKeyPub) };
88
- }
89
- return {
90
- registrationId,
91
- identityKey: generateSignalPubKey(identity),
92
- signedPreKey: {
93
- keyId: signedKeyId,
94
- publicKey: generateSignalPubKey(signedPubKey),
95
- signature: signedSig
96
- },
97
- preKey
98
- };
99
- };
100
- export const parseAndInjectE2ESessions = async (node, repository) => {
101
- const extractKey = (key) => key
102
- ? {
103
- keyId: getBinaryNodeChildUInt(key, 'id', 3),
104
- publicKey: generateSignalPubKey(getBinaryNodeChildBuffer(key, 'value')),
105
- signature: getBinaryNodeChildBuffer(key, 'signature')
106
- }
107
- : undefined;
108
- const nodes = getBinaryNodeChildren(getBinaryNodeChild(node, 'list'), 'user');
59
+ exports.xmppPreKey = xmppPreKey;
60
+ const parseAndInjectE2ESessions = async (node, repository) => {
61
+ const extractKey = (key) => (key ? ({
62
+ keyId: WABinary_1.getBinaryNodeChildUInt(key, 'id', 3),
63
+ publicKey: crypto_1.generateSignalPubKey(WABinary_1.getBinaryNodeChildBuffer(key, 'value')),
64
+ signature: WABinary_1.getBinaryNodeChildBuffer(key, 'signature')
65
+ }) : undefined)
66
+ const nodes = WABinary_1.getBinaryNodeChildren(WABinary_1.getBinaryNodeChild(node, 'list'), 'user')
109
67
  for (const node of nodes) {
110
- assertNodeErrorFree(node);
68
+ WABinary_1.assertNodeErrorFree(node)
111
69
  }
112
70
  // Most of the work in repository.injectE2ESession is CPU intensive, not IO
113
71
  // So Promise.all doesn't really help here,
114
72
  // but blocks even loop if we're using it inside keys.transaction, and it makes it "sync" actually
115
73
  // This way we chunk it in smaller parts and between those parts we can yield to the event loop
116
74
  // It's rare case when you need to E2E sessions for so many users, but it's possible
117
- const chunkSize = 100;
118
- const chunks = chunk(nodes, chunkSize);
75
+ const chunkSize = 100
76
+ const chunks = lodash_1.chunk(nodes, chunkSize)
119
77
  for (const nodesChunk of chunks) {
120
- for (const node of nodesChunk) {
121
- const signedKey = getBinaryNodeChild(node, 'skey');
122
- const key = getBinaryNodeChild(node, 'key');
123
- const identity = getBinaryNodeChildBuffer(node, 'identity');
124
- const jid = node.attrs.jid;
125
- const registrationId = getBinaryNodeChildUInt(node, 'registration', 4);
78
+ await Promise.all(nodesChunk.map(async (node) => {
79
+ const signedKey = WABinary_1.getBinaryNodeChild(node, 'skey')
80
+ const key = WABinary_1.getBinaryNodeChild(node, 'key')
81
+ const identity = WABinary_1.getBinaryNodeChildBuffer(node, 'identity')
82
+ const jid = node.attrs.jid
83
+ const registrationId = WABinary_1.getBinaryNodeChildUInt(node, 'registration', 4)
126
84
  await repository.injectE2ESession({
127
85
  jid,
128
86
  session: {
129
87
  registrationId: registrationId,
130
- identityKey: generateSignalPubKey(identity),
88
+ identityKey: crypto_1.generateSignalPubKey(identity),
131
89
  signedPreKey: extractKey(signedKey),
132
90
  preKey: extractKey(key)
133
91
  }
134
- });
135
- }
92
+ })
93
+ }))
136
94
  }
137
- };
138
- export const extractDeviceJids = (result, myJid, myLid, excludeZeroDevices) => {
139
- const { user: myUser, device: myDevice } = jidDecode(myJid);
140
- const extracted = [];
95
+ }
96
+ exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
97
+ const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
98
+ const { user: myUser, device: myDevice } = WABinary_1.jidDecode(myJid)
99
+ const extracted = []
141
100
  for (const userResult of result) {
142
- const { devices, id } = userResult;
143
- const decoded = jidDecode(id), { user, server } = decoded;
144
- let { domainType } = decoded;
145
- const deviceList = devices?.deviceList;
146
- if (!Array.isArray(deviceList))
147
- continue;
148
- for (const { id: device, keyIndex, isHosted } of deviceList) {
149
- if ((!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
150
- ((myUser !== user && myLid !== user) || myDevice !== device) && // either different user or if me user, not this device
151
- (device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
152
- ) {
153
- if (isHosted) {
154
- domainType = domainType === WAJIDDomains.LID ? WAJIDDomains.HOSTED_LID : WAJIDDomains.HOSTED;
101
+ const { devices, id } = userResult
102
+ const { user } = WABinary_1.jidDecode(id)
103
+ const deviceList = 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 })
155
111
  }
156
- extracted.push({
157
- user,
158
- device,
159
- domainType,
160
- server: getServerFromDomainType(server, domainType)
161
- });
162
112
  }
163
113
  }
164
114
  }
165
- return extracted;
166
- };
115
+ return extracted
116
+ }
117
+ exports.extractDeviceJids = extractDeviceJids;
167
118
  /**
168
119
  * get the next N keys for upload or processing
169
120
  * @param count number of pre-keys to get or generate
170
121
  */
171
- export const getNextPreKeys = async ({ creds, keys }, count) => {
172
- const { newPreKeys, lastPreKeyId, preKeysRange } = generateOrGetPreKeys(creds, count);
122
+ const getNextPreKeys = async ({ creds, keys }, count) => {
123
+ const { newPreKeys, lastPreKeyId, preKeysRange } = (0, exports.generateOrGetPreKeys)(creds, count);
173
124
  const update = {
174
125
  nextPreKeyId: Math.max(lastPreKeyId + 1, creds.nextPreKeyId),
175
126
  firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId + 1)
176
127
  };
177
128
  await keys.set({ 'pre-key': newPreKeys });
178
- const preKeys = await getPreKeys(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1]);
129
+ const preKeys = await (0, exports.getPreKeys)(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1]);
179
130
  return { update, preKeys };
180
131
  };
181
- export const getNextPreKeysNode = async (state, count) => {
132
+ exports.getNextPreKeys = getNextPreKeys;
133
+ const getNextPreKeysNode = async (state, count) => {
182
134
  const { creds } = state;
183
- const { update, preKeys } = await getNextPreKeys(state, count);
135
+ const { update, preKeys } = await (0, exports.getNextPreKeys)(state, count);
184
136
  const node = {
185
137
  tag: 'iq',
186
138
  attrs: {
187
139
  xmlns: 'encrypt',
188
140
  type: 'set',
189
- to: S_WHATSAPP_NET
141
+ to: WABinary_1.S_WHATSAPP_NET,
190
142
  },
191
143
  content: [
192
- { tag: 'registration', attrs: {}, content: encodeBigEndian(creds.registrationId) },
193
- { tag: 'type', attrs: {}, content: KEY_BUNDLE_TYPE },
144
+ { tag: 'registration', attrs: {}, content: (0, generics_1.encodeBigEndian)(creds.registrationId) },
145
+ { tag: 'type', attrs: {}, content: Defaults_1.KEY_BUNDLE_TYPE },
194
146
  { tag: 'identity', attrs: {}, content: creds.signedIdentityKey.public },
195
- { tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => xmppPreKey(preKeys[+k], +k)) },
196
- xmppSignedPreKey(creds.signedPreKey)
147
+ { tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => (0, exports.xmppPreKey)(preKeys[+k], +k)) },
148
+ (0, exports.xmppSignedPreKey)(creds.signedPreKey)
197
149
  ]
198
150
  };
199
151
  return { update, node };
200
152
  };
201
- //# sourceMappingURL=signal.js.map
153
+ exports.getNextPreKeysNode = getNextPreKeysNode;
@@ -1,4 +1,4 @@
1
- import type { AuthenticationState } from '../Types/index.js';
1
+ import { AuthenticationState } from '../Types';
2
2
  /**
3
3
  * stores the full authentication state in a single folder.
4
4
  * Far more efficient than singlefileauthstate
@@ -10,4 +10,4 @@ export declare const useMultiFileAuthState: (folder: string) => Promise<{
10
10
  state: AuthenticationState;
11
11
  saveCreds: () => Promise<void>;
12
12
  }>;
13
- //# sourceMappingURL=use-multi-file-auth-state.d.ts.map
13
+
@@ -1,19 +1,17 @@
1
- import { Mutex } from 'async-mutex';
2
- import { mkdir, readFile, stat, unlink, writeFile } from 'fs/promises';
3
- import { join } from 'path';
4
- import { proto } from '../../WAProto/index.js';
5
- import { initAuthCreds } from './auth-utils.js';
6
- import { BufferJSON } from './generics.js';
7
- // We need to lock files due to the fact that we are using async functions to read and write files
8
- // https://github.com/WhiskeySockets/Baileys/issues/794
9
- // https://github.com/nodejs/node/issues/26338
10
- // Use a Map to store mutexes for each file path
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useMultiFileAuthState = void 0;
4
+ const async_mutex_1 = require("async-mutex");
5
+ const promises_1 = require("fs/promises");
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");
11
10
  const fileLocks = new Map();
12
- // Get or create a mutex for a specific file path
13
11
  const getFileLock = (path) => {
14
12
  let mutex = fileLocks.get(path);
15
13
  if (!mutex) {
16
- mutex = new Mutex();
14
+ mutex = new async_mutex_1.Mutex();
17
15
  fileLocks.set(path, mutex);
18
16
  }
19
17
  return mutex;
@@ -25,14 +23,13 @@ const getFileLock = (path) => {
25
23
  * Again, I wouldn't endorse this for any production level use other than perhaps a bot.
26
24
  * Would recommend writing an auth state for use with a proper SQL or No-SQL DB
27
25
  * */
28
- export const useMultiFileAuthState = async (folder) => {
29
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
+ const useMultiFileAuthState = async (folder) => {
30
27
  const writeData = async (data, file) => {
31
- const filePath = join(folder, fixFileName(file));
28
+ const filePath = (0, path_1.join)(folder, fixFileName(file));
32
29
  const mutex = getFileLock(filePath);
33
30
  return mutex.acquire().then(async (release) => {
34
31
  try {
35
- await writeFile(filePath, JSON.stringify(data, BufferJSON.replacer));
32
+ await (0, promises_1.writeFile)(filePath, JSON.stringify(data, generics_1.BufferJSON.replacer));
36
33
  }
37
34
  finally {
38
35
  release();
@@ -41,12 +38,12 @@ export const useMultiFileAuthState = async (folder) => {
41
38
  };
42
39
  const readData = async (file) => {
43
40
  try {
44
- const filePath = join(folder, fixFileName(file));
41
+ const filePath = (0, path_1.join)(folder, fixFileName(file));
45
42
  const mutex = getFileLock(filePath);
46
43
  return await mutex.acquire().then(async (release) => {
47
44
  try {
48
- const data = await readFile(filePath, { encoding: 'utf-8' });
49
- return JSON.parse(data, BufferJSON.reviver);
45
+ const data = await (0, promises_1.readFile)(filePath, { encoding: 'utf-8' });
46
+ return JSON.parse(data, generics_1.BufferJSON.reviver);
50
47
  }
51
48
  finally {
52
49
  release();
@@ -59,32 +56,33 @@ export const useMultiFileAuthState = async (folder) => {
59
56
  };
60
57
  const removeData = async (file) => {
61
58
  try {
62
- const filePath = join(folder, fixFileName(file));
59
+ const filePath = (0, path_1.join)(folder, fixFileName(file));
63
60
  const mutex = getFileLock(filePath);
64
61
  return mutex.acquire().then(async (release) => {
65
62
  try {
66
- await unlink(filePath);
63
+ await (0, promises_1.unlink)(filePath);
67
64
  }
68
- catch {
65
+ catch (_a) {
69
66
  }
70
67
  finally {
71
68
  release();
72
69
  }
73
70
  });
74
71
  }
75
- catch { }
72
+ catch (_a) {
73
+ }
76
74
  };
77
- const folderInfo = await stat(folder).catch(() => { });
75
+ const folderInfo = await (0, promises_1.stat)(folder).catch(() => { });
78
76
  if (folderInfo) {
79
77
  if (!folderInfo.isDirectory()) {
80
78
  throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`);
81
79
  }
82
80
  }
83
81
  else {
84
- await mkdir(folder, { recursive: true });
82
+ await (0, promises_1.mkdir)(folder, { recursive: true });
85
83
  }
86
- const fixFileName = (file) => file?.replace(/\//g, '__')?.replace(/:/g, '-');
87
- const creds = (await readData('creds.json')) || initAuthCreds();
84
+ 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, '-'); };
85
+ const creds = await readData('creds.json') || (0, auth_utils_1.initAuthCreds)();
88
86
  return {
89
87
  state: {
90
88
  creds,
@@ -94,7 +92,7 @@ export const useMultiFileAuthState = async (folder) => {
94
92
  await Promise.all(ids.map(async (id) => {
95
93
  let value = await readData(`${type}-${id}.json`);
96
94
  if (type === 'app-state-sync-key' && value) {
97
- value = proto.Message.AppStateSyncKeyData.fromObject(value);
95
+ value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value);
98
96
  }
99
97
  data[id] = value;
100
98
  }));
@@ -118,4 +116,4 @@ export const useMultiFileAuthState = async (folder) => {
118
116
  }
119
117
  };
120
118
  };
121
- //# sourceMappingURL=use-multi-file-auth-state.js.map
119
+ exports.useMultiFileAuthState = useMultiFileAuthState;
@@ -1,11 +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';
1
+ import { proto } from '../../WAProto';
2
+ import type { AuthenticationCreds, SignalCreds, SocketConfig } from '../Types';
3
+ import { BinaryNode } from '../WABinary';
4
+ export declare const generateMobileNode: (config: SocketConfig) => proto.IClientPayload;
4
5
  export declare const generateLoginNode: (userJid: string, config: SocketConfig) => proto.IClientPayload;
5
6
  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
+ export declare const configureSuccessfulPairing: (stanza: BinaryNode, { advSecretKey, signedIdentityKey, signalIdentities }: Pick<AuthenticationCreds, 'advSecretKey' | 'signedIdentityKey' | 'signalIdentities'>) => {
7
8
  creds: Partial<AuthenticationCreds>;
8
9
  reply: BinaryNode;
9
- };
10
- export declare const encodeSignedDeviceIdentity: (account: proto.IADVSignedDeviceIdentity, includeSignatureKey: boolean) => Uint8Array<ArrayBufferLike>;
11
- //# sourceMappingURL=validate-connection.d.ts.map
10
+ };
11
+ export declare const encodeSignedDeviceIdentity: (account: proto.IADVSignedDeviceIdentity, includeSignatureKey: boolean) => Uint8Array;