supunmd-bail 2.1.1 → 2.1.3

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 (216) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +428 -0
  3. package/WAProto/index.js +130529 -45236
  4. package/engine-requirements.js +1 -1
  5. package/lib/Defaults/baileys-version.json +1 -1
  6. package/lib/Defaults/index.d.ts +9 -18
  7. package/lib/Defaults/index.js +136 -104
  8. package/lib/Defaults/phonenumber-mcc.json +223 -0
  9. package/lib/Signal/Group/ciphertext-message.d.ts +0 -1
  10. package/lib/Signal/Group/ciphertext-message.js +5 -2
  11. package/lib/Signal/Group/group-session-builder.d.ts +3 -4
  12. package/lib/Signal/Group/group-session-builder.js +41 -7
  13. package/lib/Signal/Group/group_cipher.d.ts +4 -4
  14. package/lib/Signal/Group/group_cipher.js +51 -37
  15. package/lib/Signal/Group/index.d.ts +11 -12
  16. package/lib/Signal/Group/index.js +57 -12
  17. package/lib/Signal/Group/keyhelper.d.ts +1 -2
  18. package/lib/Signal/Group/keyhelper.js +44 -7
  19. package/lib/Signal/Group/queue-job.d.ts +0 -1
  20. package/lib/Signal/Group/queue-job.js +5 -2
  21. package/lib/Signal/Group/sender-chain-key.d.ts +2 -3
  22. package/lib/Signal/Group/sender-chain-key.js +15 -7
  23. package/lib/Signal/Group/sender-key-distribution-message.d.ts +1 -2
  24. package/lib/Signal/Group/sender-key-distribution-message.js +11 -8
  25. package/lib/Signal/Group/sender-key-message.d.ts +1 -2
  26. package/lib/Signal/Group/sender-key-message.js +12 -9
  27. package/lib/Signal/Group/sender-key-name.d.ts +0 -1
  28. package/lib/Signal/Group/sender-key-name.js +5 -2
  29. package/lib/Signal/Group/sender-key-record.d.ts +2 -3
  30. package/lib/Signal/Group/sender-key-record.js +21 -9
  31. package/lib/Signal/Group/sender-key-state.d.ts +6 -7
  32. package/lib/Signal/Group/sender-key-state.js +42 -27
  33. package/lib/Signal/Group/sender-message-key.d.ts +0 -1
  34. package/lib/Signal/Group/sender-message-key.js +7 -4
  35. package/lib/Signal/libsignal.d.ts +3 -5
  36. package/lib/Signal/libsignal.js +90 -258
  37. package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +3 -2
  38. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  39. package/lib/Socket/Client/index.d.ts +3 -3
  40. package/lib/Socket/Client/index.js +19 -3
  41. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  42. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  43. package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -2
  44. package/lib/Socket/Client/web-socket-client.js +62 -0
  45. package/lib/Socket/business.d.ts +108 -125
  46. package/lib/Socket/business.js +43 -159
  47. package/lib/Socket/chats.d.ts +239 -70
  48. package/lib/Socket/chats.js +384 -363
  49. package/lib/Socket/dugong.d.ts +254 -0
  50. package/lib/Socket/dugong.js +484 -0
  51. package/lib/Socket/groups.d.ts +56 -78
  52. package/lib/Socket/groups.js +96 -106
  53. package/lib/Socket/index.d.ts +115 -173
  54. package/lib/Socket/index.js +10 -17
  55. package/lib/Socket/messages-recv.d.ts +79 -91
  56. package/lib/Socket/messages-recv.js +521 -639
  57. package/lib/Socket/messages-send.d.ts +91 -111
  58. package/lib/Socket/messages-send.js +438 -599
  59. package/lib/Socket/newsletter.d.ts +84 -97
  60. package/lib/Socket/newsletter.js +1 -181
  61. package/lib/Socket/registration.d.ts +267 -0
  62. package/lib/Socket/registration.js +166 -0
  63. package/lib/Socket/socket.d.ts +18 -26
  64. package/lib/Socket/socket.js +230 -448
  65. package/lib/Socket/usync.d.ts +16 -17
  66. package/lib/Socket/usync.js +26 -19
  67. package/lib/Store/index.d.ts +3 -0
  68. package/lib/Store/index.js +10 -0
  69. package/lib/Store/make-cache-manager-store.d.ts +13 -0
  70. package/lib/Store/make-cache-manager-store.js +83 -0
  71. package/lib/Store/make-in-memory-store.d.ts +118 -0
  72. package/lib/Store/make-in-memory-store.js +427 -0
  73. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  74. package/lib/Store/make-ordered-dictionary.js +81 -0
  75. package/lib/Store/object-repository.d.ts +10 -0
  76. package/lib/Store/object-repository.js +27 -0
  77. package/lib/Types/Auth.d.ts +12 -13
  78. package/lib/Types/Auth.js +2 -2
  79. package/lib/Types/Call.d.ts +1 -2
  80. package/lib/Types/Call.js +2 -2
  81. package/lib/Types/Chat.d.ts +13 -34
  82. package/lib/Types/Chat.js +4 -8
  83. package/lib/Types/Contact.d.ts +1 -6
  84. package/lib/Types/Contact.js +2 -2
  85. package/lib/Types/Events.d.ts +15 -60
  86. package/lib/Types/Events.js +2 -2
  87. package/lib/Types/GroupMetadata.d.ts +5 -17
  88. package/lib/Types/GroupMetadata.js +2 -2
  89. package/lib/Types/Label.d.ts +0 -12
  90. package/lib/Types/Label.js +5 -3
  91. package/lib/Types/LabelAssociation.d.ts +0 -1
  92. package/lib/Types/LabelAssociation.js +5 -3
  93. package/lib/Types/Message.d.ts +54 -84
  94. package/lib/Types/Message.js +9 -11
  95. package/lib/Types/Newsletter.d.ts +98 -130
  96. package/lib/Types/Newsletter.js +38 -31
  97. package/lib/Types/Product.d.ts +1 -2
  98. package/lib/Types/Product.js +2 -2
  99. package/lib/Types/Signal.d.ts +1 -20
  100. package/lib/Types/Signal.js +2 -2
  101. package/lib/Types/Socket.d.ts +25 -47
  102. package/lib/Types/Socket.js +2 -3
  103. package/lib/Types/State.d.ts +2 -14
  104. package/lib/Types/State.js +2 -13
  105. package/lib/Types/USync.d.ts +2 -3
  106. package/lib/Types/USync.js +2 -2
  107. package/lib/Types/index.d.ts +14 -22
  108. package/lib/Types/index.js +31 -15
  109. package/lib/Utils/auth-utils.d.ts +6 -7
  110. package/lib/Utils/auth-utils.js +148 -199
  111. package/lib/Utils/baileys-event-stream.d.ts +1 -2
  112. package/lib/Utils/baileys-event-stream.js +22 -15
  113. package/lib/Utils/business.d.ts +2 -3
  114. package/lib/Utils/business.js +69 -66
  115. package/lib/Utils/chat-utils.d.ts +22 -21
  116. package/lib/Utils/chat-utils.js +226 -260
  117. package/lib/Utils/crypto.d.ts +19 -19
  118. package/lib/Utils/crypto.js +86 -77
  119. package/lib/Utils/decode-wa-message.d.ts +8 -37
  120. package/lib/Utils/decode-wa-message.js +83 -164
  121. package/lib/Utils/event-buffer.d.ts +8 -7
  122. package/lib/Utils/event-buffer.js +76 -110
  123. package/lib/Utils/generics.d.ts +29 -27
  124. package/lib/Utils/generics.js +210 -168
  125. package/lib/Utils/history.d.ts +8 -12
  126. package/lib/Utils/history.js +46 -34
  127. package/lib/Utils/index.d.ts +17 -20
  128. package/lib/Utils/index.js +33 -20
  129. package/lib/Utils/link-preview.d.ts +5 -5
  130. package/lib/Utils/link-preview.js +22 -14
  131. package/lib/Utils/logger.d.ts +3 -11
  132. package/lib/Utils/logger.js +7 -3
  133. package/lib/Utils/lt-hash.d.ts +8 -9
  134. package/lib/Utils/lt-hash.js +28 -25
  135. package/lib/Utils/make-mutex.d.ts +2 -3
  136. package/lib/Utils/make-mutex.js +10 -7
  137. package/lib/Utils/messages-media.d.ts +44 -42
  138. package/lib/Utils/messages-media.js +475 -319
  139. package/lib/Utils/messages.d.ts +18 -17
  140. package/lib/Utils/messages.js +259 -383
  141. package/lib/Utils/noise-handler.d.ts +15 -14
  142. package/lib/Utils/noise-handler.js +38 -30
  143. package/lib/Utils/process-message.d.ts +13 -14
  144. package/lib/Utils/process-message.js +147 -239
  145. package/lib/Utils/signal.d.ts +5 -7
  146. package/lib/Utils/signal.js +72 -78
  147. package/lib/Utils/use-multi-file-auth-state.d.ts +2 -2
  148. package/lib/Utils/use-multi-file-auth-state.js +27 -29
  149. package/lib/Utils/validate-connection.d.ts +7 -7
  150. package/lib/Utils/validate-connection.js +106 -72
  151. package/lib/WABinary/constants.d.ts +27 -25
  152. package/lib/WABinary/constants.js +20 -1281
  153. package/lib/WABinary/decode.d.ts +5 -5
  154. package/lib/WABinary/decode.js +42 -28
  155. package/lib/WABinary/encode.d.ts +3 -3
  156. package/lib/WABinary/encode.js +154 -105
  157. package/lib/WABinary/generic-utils.d.ts +7 -5
  158. package/lib/WABinary/generic-utils.js +63 -56
  159. package/lib/WABinary/index.d.ts +5 -6
  160. package/lib/WABinary/index.js +21 -6
  161. package/lib/WABinary/jid-utils.d.ts +8 -25
  162. package/lib/WABinary/jid-utils.js +40 -74
  163. package/lib/WABinary/types.d.ts +1 -2
  164. package/lib/WABinary/types.js +2 -2
  165. package/lib/WAM/BinaryInfo.d.ts +11 -3
  166. package/lib/WAM/BinaryInfo.js +5 -2
  167. package/lib/WAM/constants.d.ts +3 -5
  168. package/lib/WAM/constants.js +11958 -19461
  169. package/lib/WAM/encode.d.ts +3 -3
  170. package/lib/WAM/encode.js +22 -17
  171. package/lib/WAM/index.d.ts +3 -4
  172. package/lib/WAM/index.js +19 -4
  173. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +3 -4
  174. package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -8
  175. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -3
  176. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
  177. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -3
  178. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -9
  179. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -3
  180. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
  181. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +3 -4
  182. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
  183. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -5
  184. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +8 -13
  185. package/lib/WAUSync/Protocols/index.d.ts +4 -5
  186. package/lib/WAUSync/Protocols/index.js +20 -5
  187. package/lib/WAUSync/USyncQuery.d.ts +4 -5
  188. package/lib/WAUSync/USyncQuery.js +35 -40
  189. package/lib/WAUSync/USyncUser.d.ts +5 -6
  190. package/lib/WAUSync/USyncUser.js +5 -2
  191. package/lib/WAUSync/index.d.ts +3 -4
  192. package/lib/WAUSync/index.js +19 -4
  193. package/lib/index.d.ts +9 -19
  194. package/lib/index.js +1 -36
  195. package/package.json +109 -99
  196. package/WAProto/GenerateStatics.sh +0 -3
  197. package/WAProto/WAProto.proto +0 -5519
  198. package/WAProto/fix-imports.js +0 -29
  199. package/WAProto/index.d.ts +0 -11969
  200. package/lib/Signal/lid-mapping.d.ts +0 -23
  201. package/lib/Signal/lid-mapping.js +0 -171
  202. package/lib/Socket/Client/types.js +0 -11
  203. package/lib/Socket/Client/websocket.js +0 -50
  204. package/lib/Socket/communities.d.ts +0 -244
  205. package/lib/Socket/communities.js +0 -431
  206. package/lib/Socket/mex.d.ts +0 -3
  207. package/lib/Socket/mex.js +0 -42
  208. package/lib/Types/Bussines.d.ts +0 -25
  209. package/lib/Types/Bussines.js +0 -2
  210. package/lib/Utils/browser-utils.d.ts +0 -4
  211. package/lib/Utils/browser-utils.js +0 -28
  212. package/lib/Utils/message-retry-manager.d.ts +0 -82
  213. package/lib/Utils/message-retry-manager.js +0 -149
  214. package/lib/Utils/pre-key-manager.d.ts +0 -28
  215. package/lib/Utils/pre-key-manager.js +0 -106
  216. /package/lib/{supun → supunmd} +0 -0
@@ -1,159 +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
- export const parseAndInjectE2ESessions = async (node, repository) => {
59
- const extractKey = (key) => key
60
- ? {
61
- keyId: getBinaryNodeChildUInt(key, 'id', 3),
62
- publicKey: generateSignalPubKey(getBinaryNodeChildBuffer(key, 'value')),
63
- signature: getBinaryNodeChildBuffer(key, 'signature')
64
- }
65
- : undefined;
66
- 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')
67
67
  for (const node of nodes) {
68
- assertNodeErrorFree(node);
68
+ WABinary_1.assertNodeErrorFree(node)
69
69
  }
70
70
  // Most of the work in repository.injectE2ESession is CPU intensive, not IO
71
71
  // So Promise.all doesn't really help here,
72
72
  // but blocks even loop if we're using it inside keys.transaction, and it makes it "sync" actually
73
73
  // This way we chunk it in smaller parts and between those parts we can yield to the event loop
74
74
  // It's rare case when you need to E2E sessions for so many users, but it's possible
75
- const chunkSize = 100;
76
- const chunks = chunk(nodes, chunkSize);
75
+ const chunkSize = 100
76
+ const chunks = lodash_1.chunk(nodes, chunkSize)
77
77
  for (const nodesChunk of chunks) {
78
- for (const node of nodesChunk) {
79
- const signedKey = getBinaryNodeChild(node, 'skey');
80
- const key = getBinaryNodeChild(node, 'key');
81
- const identity = getBinaryNodeChildBuffer(node, 'identity');
82
- const jid = node.attrs.jid;
83
- 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)
84
84
  await repository.injectE2ESession({
85
85
  jid,
86
86
  session: {
87
87
  registrationId: registrationId,
88
- identityKey: generateSignalPubKey(identity),
88
+ identityKey: crypto_1.generateSignalPubKey(identity),
89
89
  signedPreKey: extractKey(signedKey),
90
90
  preKey: extractKey(key)
91
91
  }
92
- });
93
- }
92
+ })
93
+ }))
94
94
  }
95
- };
96
- export const extractDeviceJids = (result, myJid, myLid, excludeZeroDevices) => {
97
- const { user: myUser, device: myDevice } = jidDecode(myJid);
98
- 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 = []
99
100
  for (const userResult of result) {
100
- const { devices, id } = userResult;
101
- const decoded = jidDecode(id), { user, server } = decoded;
102
- let { domainType } = decoded;
103
- const deviceList = devices?.deviceList;
104
- if (!Array.isArray(deviceList))
105
- continue;
106
- for (const { id: device, keyIndex, isHosted } of deviceList) {
107
- if ((!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
108
- ((myUser !== user && myLid !== user) || myDevice !== device) && // either different user or if me user, not this device
109
- (device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
110
- ) {
111
- if (isHosted) {
112
- 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 })
113
111
  }
114
- extracted.push({
115
- user,
116
- device,
117
- domainType,
118
- server: getServerFromDomainType(server, domainType)
119
- });
120
112
  }
121
113
  }
122
114
  }
123
- return extracted;
124
- };
115
+ return extracted
116
+ }
117
+ exports.extractDeviceJids = extractDeviceJids;
125
118
  /**
126
119
  * get the next N keys for upload or processing
127
120
  * @param count number of pre-keys to get or generate
128
121
  */
129
- export const getNextPreKeys = async ({ creds, keys }, count) => {
130
- const { newPreKeys, lastPreKeyId, preKeysRange } = generateOrGetPreKeys(creds, count);
122
+ const getNextPreKeys = async ({ creds, keys }, count) => {
123
+ const { newPreKeys, lastPreKeyId, preKeysRange } = (0, exports.generateOrGetPreKeys)(creds, count);
131
124
  const update = {
132
125
  nextPreKeyId: Math.max(lastPreKeyId + 1, creds.nextPreKeyId),
133
126
  firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId + 1)
134
127
  };
135
128
  await keys.set({ 'pre-key': newPreKeys });
136
- 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]);
137
130
  return { update, preKeys };
138
131
  };
139
- export const getNextPreKeysNode = async (state, count) => {
132
+ exports.getNextPreKeys = getNextPreKeys;
133
+ const getNextPreKeysNode = async (state, count) => {
140
134
  const { creds } = state;
141
- const { update, preKeys } = await getNextPreKeys(state, count);
135
+ const { update, preKeys } = await (0, exports.getNextPreKeys)(state, count);
142
136
  const node = {
143
137
  tag: 'iq',
144
138
  attrs: {
145
139
  xmlns: 'encrypt',
146
140
  type: 'set',
147
- to: S_WHATSAPP_NET
141
+ to: WABinary_1.S_WHATSAPP_NET,
148
142
  },
149
143
  content: [
150
- { tag: 'registration', attrs: {}, content: encodeBigEndian(creds.registrationId) },
151
- { 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 },
152
146
  { tag: 'identity', attrs: {}, content: creds.signedIdentityKey.public },
153
- { tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => xmppPreKey(preKeys[+k], +k)) },
154
- 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)
155
149
  ]
156
150
  };
157
151
  return { update, node };
158
152
  };
159
- //# 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;