@vinzsocket/baileys 3.0.0 → 3.0.15

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 (332) hide show
  1. package/WAProto/GenerateStatics.sh +2 -2
  2. package/WAProto/WAProto.proto +1339 -493
  3. package/WAProto/fix-imports.js +79 -14
  4. package/WAProto/index.d.ts +5274 -1945
  5. package/WAProto/index.js +97691 -1
  6. package/lib/Defaults/index.d.ts +25 -8
  7. package/lib/Defaults/index.d.ts.map +1 -1
  8. package/lib/Defaults/index.js +124 -109
  9. package/lib/Defaults/index.js.map +1 -1
  10. package/lib/Signal/Group/ciphertext-message.js +11 -15
  11. package/lib/Signal/Group/group-session-builder.js +27 -32
  12. package/lib/Signal/Group/group_cipher.d.ts +1 -2
  13. package/lib/Signal/Group/group_cipher.d.ts.map +1 -1
  14. package/lib/Signal/Group/group_cipher.js +75 -92
  15. package/lib/Signal/Group/group_cipher.js.map +1 -1
  16. package/lib/Signal/Group/index.js +12 -77
  17. package/lib/Signal/Group/keyhelper.d.ts.map +1 -1
  18. package/lib/Signal/Group/keyhelper.js +16 -24
  19. package/lib/Signal/Group/keyhelper.js.map +1 -1
  20. package/lib/Signal/Group/sender-chain-key.d.ts +1 -1
  21. package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -1
  22. package/lib/Signal/Group/sender-chain-key.js +24 -34
  23. package/lib/Signal/Group/sender-chain-key.js.map +1 -1
  24. package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -1
  25. package/lib/Signal/Group/sender-key-distribution-message.js +62 -58
  26. package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -1
  27. package/lib/Signal/Group/sender-key-message.d.ts.map +1 -1
  28. package/lib/Signal/Group/sender-key-message.js +64 -65
  29. package/lib/Signal/Group/sender-key-message.js.map +1 -1
  30. package/lib/Signal/Group/sender-key-name.js +41 -44
  31. package/lib/Signal/Group/sender-key-record.d.ts +1 -1
  32. package/lib/Signal/Group/sender-key-record.d.ts.map +1 -1
  33. package/lib/Signal/Group/sender-key-record.js +36 -47
  34. package/lib/Signal/Group/sender-key-record.js.map +1 -1
  35. package/lib/Signal/Group/sender-key-state.d.ts +4 -4
  36. package/lib/Signal/Group/sender-key-state.d.ts.map +1 -1
  37. package/lib/Signal/Group/sender-key-state.js +76 -93
  38. package/lib/Signal/Group/sender-key-state.js.map +1 -1
  39. package/lib/Signal/Group/sender-message-key.d.ts.map +1 -1
  40. package/lib/Signal/Group/sender-message-key.js +25 -31
  41. package/lib/Signal/Group/sender-message-key.js.map +1 -1
  42. package/lib/Signal/libsignal.d.ts +4 -7
  43. package/lib/Signal/libsignal.d.ts.map +1 -1
  44. package/lib/Signal/libsignal.js +417 -401
  45. package/lib/Signal/libsignal.js.map +1 -1
  46. package/lib/Signal/lid-mapping.d.ts +16 -23
  47. package/lib/Signal/lid-mapping.d.ts.map +1 -1
  48. package/lib/Signal/lid-mapping.js +273 -108
  49. package/lib/Signal/lid-mapping.js.map +1 -1
  50. package/lib/Socket/Client/index.js +3 -25
  51. package/lib/Socket/Client/types.d.ts +2 -2
  52. package/lib/Socket/Client/types.d.ts.map +1 -1
  53. package/lib/Socket/Client/types.js +10 -14
  54. package/lib/Socket/Client/websocket.d.ts +1 -1
  55. package/lib/Socket/Client/websocket.d.ts.map +1 -1
  56. package/lib/Socket/Client/websocket.js +53 -54
  57. package/lib/Socket/Client/websocket.js.map +1 -1
  58. package/lib/Socket/business.d.ts +45 -16
  59. package/lib/Socket/business.d.ts.map +1 -1
  60. package/lib/Socket/business.js +374 -360
  61. package/lib/Socket/business.js.map +1 -1
  62. package/lib/Socket/chats.d.ts +34 -8
  63. package/lib/Socket/chats.d.ts.map +1 -1
  64. package/lib/Socket/chats.js +1162 -1038
  65. package/lib/Socket/chats.js.map +1 -1
  66. package/lib/Socket/communities.d.ts +56 -16
  67. package/lib/Socket/communities.d.ts.map +1 -1
  68. package/lib/Socket/communities.js +418 -466
  69. package/lib/Socket/communities.js.map +1 -1
  70. package/lib/Socket/dugong.d.ts +205 -0
  71. package/lib/Socket/dugong.js +415 -0
  72. package/lib/Socket/groups.d.ts +32 -8
  73. package/lib/Socket/groups.d.ts.map +1 -1
  74. package/lib/Socket/groups.js +337 -390
  75. package/lib/Socket/groups.js.map +1 -1
  76. package/lib/Socket/index.d.ts +57 -16
  77. package/lib/Socket/index.d.ts.map +1 -1
  78. package/lib/Socket/index.js +10 -18
  79. package/lib/Socket/index.js.map +1 -1
  80. package/lib/Socket/messages-recv.d.ts +49 -19
  81. package/lib/Socket/messages-recv.d.ts.map +1 -1
  82. package/lib/Socket/messages-recv.js +1738 -1391
  83. package/lib/Socket/messages-recv.js.map +1 -1
  84. package/lib/Socket/messages-send.d.ts +47 -15
  85. package/lib/Socket/messages-send.d.ts.map +1 -1
  86. package/lib/Socket/messages-send.js +1144 -1242
  87. package/lib/Socket/messages-send.js.map +1 -1
  88. package/lib/Socket/mex.js +38 -48
  89. package/lib/Socket/newsletter.d.ts +30 -7
  90. package/lib/Socket/newsletter.d.ts.map +1 -1
  91. package/lib/Socket/newsletter.js +175 -222
  92. package/lib/Socket/newsletter.js.map +1 -1
  93. package/lib/Socket/socket.d.ts +15 -6
  94. package/lib/Socket/socket.d.ts.map +1 -1
  95. package/lib/Socket/socket.js +932 -913
  96. package/lib/Socket/socket.js.map +1 -1
  97. package/lib/Types/Auth.d.ts +12 -0
  98. package/lib/Types/Auth.d.ts.map +1 -1
  99. package/lib/Types/Auth.js +2 -3
  100. package/lib/Types/Bussines.js +2 -3
  101. package/lib/Types/Call.d.ts +2 -1
  102. package/lib/Types/Call.d.ts.map +1 -1
  103. package/lib/Types/Call.js +2 -3
  104. package/lib/Types/Chat.d.ts +1 -0
  105. package/lib/Types/Chat.d.ts.map +1 -1
  106. package/lib/Types/Chat.js +8 -5
  107. package/lib/Types/Contact.d.ts +2 -0
  108. package/lib/Types/Contact.d.ts.map +1 -1
  109. package/lib/Types/Contact.js +2 -3
  110. package/lib/Types/Events.d.ts +66 -9
  111. package/lib/Types/Events.d.ts.map +1 -1
  112. package/lib/Types/Events.js +2 -1
  113. package/lib/Types/GroupMetadata.d.ts +5 -0
  114. package/lib/Types/GroupMetadata.d.ts.map +1 -1
  115. package/lib/Types/GroupMetadata.js +2 -3
  116. package/lib/Types/Label.js +23 -26
  117. package/lib/Types/LabelAssociation.js +5 -8
  118. package/lib/Types/Message.d.ts +31 -11
  119. package/lib/Types/Message.d.ts.map +1 -1
  120. package/lib/Types/Message.js +9 -18
  121. package/lib/Types/Message.js.map +1 -1
  122. package/lib/Types/{Newsletter.d.ts → Mex.d.ts} +11 -5
  123. package/lib/Types/Mex.d.ts.map +1 -0
  124. package/lib/Types/Mex.js +37 -0
  125. package/lib/Types/Mex.js.map +1 -0
  126. package/lib/Types/Product.js +2 -3
  127. package/lib/Types/Signal.d.ts +21 -16
  128. package/lib/Types/Signal.d.ts.map +1 -1
  129. package/lib/Types/Signal.js +2 -1
  130. package/lib/Types/Socket.d.ts +23 -17
  131. package/lib/Types/Socket.d.ts.map +1 -1
  132. package/lib/Types/Socket.js +3 -2
  133. package/lib/Types/Socket.js.map +1 -1
  134. package/lib/Types/State.d.ts +58 -0
  135. package/lib/Types/State.d.ts.map +1 -1
  136. package/lib/Types/State.js +55 -15
  137. package/lib/Types/State.js.map +1 -1
  138. package/lib/Types/USync.js +2 -1
  139. package/lib/Types/index.d.ts +1 -1
  140. package/lib/Types/index.d.ts.map +1 -1
  141. package/lib/Types/index.js +25 -163
  142. package/lib/Types/index.js.map +1 -1
  143. package/lib/Utils/auth-utils.d.ts +7 -2
  144. package/lib/Utils/auth-utils.d.ts.map +1 -1
  145. package/lib/Utils/auth-utils.js +272 -458
  146. package/lib/Utils/auth-utils.js.map +1 -1
  147. package/lib/Utils/browser-utils.d.ts +4 -0
  148. package/lib/Utils/browser-utils.d.ts.map +1 -0
  149. package/lib/Utils/browser-utils.js +28 -0
  150. package/lib/Utils/browser-utils.js.map +1 -0
  151. package/lib/Utils/business.js +208 -221
  152. package/lib/Utils/chat-utils.d.ts +35 -6
  153. package/lib/Utils/chat-utils.d.ts.map +1 -1
  154. package/lib/Utils/chat-utils.js +828 -800
  155. package/lib/Utils/chat-utils.js.map +1 -1
  156. package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
  157. package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -0
  158. package/lib/Utils/companion-reg-client-utils.js +35 -0
  159. package/lib/Utils/companion-reg-client-utils.js.map +1 -0
  160. package/lib/Utils/crypto.d.ts +7 -11
  161. package/lib/Utils/crypto.d.ts.map +1 -1
  162. package/lib/Utils/crypto.js +88 -142
  163. package/lib/Utils/crypto.js.map +1 -1
  164. package/lib/Utils/decode-wa-message.d.ts +22 -2
  165. package/lib/Utils/decode-wa-message.d.ts.map +1 -1
  166. package/lib/Utils/decode-wa-message.js +293 -261
  167. package/lib/Utils/decode-wa-message.js.map +1 -1
  168. package/lib/Utils/event-buffer.d.ts +2 -0
  169. package/lib/Utils/event-buffer.d.ts.map +1 -1
  170. package/lib/Utils/event-buffer.js +599 -558
  171. package/lib/Utils/event-buffer.js.map +1 -1
  172. package/lib/Utils/generics.d.ts +6 -7
  173. package/lib/Utils/generics.d.ts.map +1 -1
  174. package/lib/Utils/generics.js +331 -362
  175. package/lib/Utils/generics.js.map +1 -1
  176. package/lib/Utils/history.d.ts +14 -10
  177. package/lib/Utils/history.d.ts.map +1 -1
  178. package/lib/Utils/history.js +129 -93
  179. package/lib/Utils/history.js.map +1 -1
  180. package/lib/Utils/identity-change-handler.d.ts +44 -0
  181. package/lib/Utils/identity-change-handler.d.ts.map +1 -0
  182. package/lib/Utils/identity-change-handler.js +50 -0
  183. package/lib/Utils/identity-change-handler.js.map +1 -0
  184. package/lib/Utils/index.d.ts +4 -3
  185. package/lib/Utils/index.d.ts.map +1 -1
  186. package/lib/Utils/index.js +23 -234
  187. package/lib/Utils/index.js.map +1 -1
  188. package/lib/Utils/link-preview.d.ts +1 -2
  189. package/lib/Utils/link-preview.d.ts.map +1 -1
  190. package/lib/Utils/link-preview.js +69 -83
  191. package/lib/Utils/link-preview.js.map +1 -1
  192. package/lib/Utils/logger.js +3 -9
  193. package/lib/Utils/lt-hash.d.ts +7 -12
  194. package/lib/Utils/lt-hash.d.ts.map +1 -1
  195. package/lib/Utils/lt-hash.js +3 -50
  196. package/lib/Utils/lt-hash.js.map +1 -1
  197. package/lib/Utils/make-mutex.d.ts +1 -0
  198. package/lib/Utils/make-mutex.d.ts.map +1 -1
  199. package/lib/Utils/make-mutex.js +30 -40
  200. package/lib/Utils/make-mutex.js.map +1 -1
  201. package/lib/Utils/mention.d.ts +8 -21
  202. package/lib/Utils/mention.js +99 -96
  203. package/lib/Utils/message-retry-manager.d.ts +38 -5
  204. package/lib/Utils/message-retry-manager.d.ts.map +1 -1
  205. package/lib/Utils/message-retry-manager.js +259 -159
  206. package/lib/Utils/message-retry-manager.js.map +1 -1
  207. package/lib/Utils/messages-media.d.ts +30 -10
  208. package/lib/Utils/messages-media.d.ts.map +1 -1
  209. package/lib/Utils/messages-media.js +734 -710
  210. package/lib/Utils/messages-media.js.map +1 -1
  211. package/lib/Utils/messages.d.ts +19 -4
  212. package/lib/Utils/messages.d.ts.map +1 -1
  213. package/lib/Utils/messages.js +817 -800
  214. package/lib/Utils/messages.js.map +1 -1
  215. package/lib/Utils/noise-handler.d.ts +4 -4
  216. package/lib/Utils/noise-handler.d.ts.map +1 -1
  217. package/lib/Utils/noise-handler.js +195 -165
  218. package/lib/Utils/noise-handler.js.map +1 -1
  219. package/lib/Utils/offline-node-processor.d.ts +17 -0
  220. package/lib/Utils/offline-node-processor.d.ts.map +1 -0
  221. package/lib/Utils/offline-node-processor.js +40 -0
  222. package/lib/Utils/offline-node-processor.js.map +1 -0
  223. package/lib/Utils/pre-key-manager.d.ts +28 -0
  224. package/lib/Utils/pre-key-manager.d.ts.map +1 -0
  225. package/lib/Utils/pre-key-manager.js +106 -0
  226. package/lib/Utils/pre-key-manager.js.map +1 -0
  227. package/lib/Utils/process-message.d.ts +26 -9
  228. package/lib/Utils/process-message.d.ts.map +1 -1
  229. package/lib/Utils/process-message.js +601 -422
  230. package/lib/Utils/process-message.js.map +1 -1
  231. package/lib/Utils/reporting-utils.d.ts +11 -0
  232. package/lib/Utils/reporting-utils.d.ts.map +1 -0
  233. package/lib/Utils/reporting-utils.js +258 -0
  234. package/lib/Utils/reporting-utils.js.map +1 -0
  235. package/lib/Utils/signal.d.ts +17 -4
  236. package/lib/Utils/signal.d.ts.map +1 -1
  237. package/lib/Utils/signal.js +180 -203
  238. package/lib/Utils/signal.js.map +1 -1
  239. package/lib/Utils/stanza-ack.d.ts +11 -0
  240. package/lib/Utils/stanza-ack.d.ts.map +1 -0
  241. package/lib/Utils/stanza-ack.js +38 -0
  242. package/lib/Utils/stanza-ack.js.map +1 -0
  243. package/lib/Utils/sync-action-utils.d.ts +19 -0
  244. package/lib/Utils/sync-action-utils.d.ts.map +1 -0
  245. package/lib/Utils/sync-action-utils.js +49 -0
  246. package/lib/Utils/sync-action-utils.js.map +1 -0
  247. package/lib/Utils/tc-token-utils.d.ts +37 -0
  248. package/lib/Utils/tc-token-utils.d.ts.map +1 -0
  249. package/lib/Utils/tc-token-utils.js +163 -0
  250. package/lib/Utils/tc-token-utils.js.map +1 -0
  251. package/lib/Utils/use-multi-file-auth-state.js +98 -98
  252. package/lib/Utils/use-multi-file-auth-state.js.map +1 -1
  253. package/lib/Utils/validate-connection.d.ts.map +1 -1
  254. package/lib/Utils/validate-connection.js +191 -185
  255. package/lib/Utils/validate-connection.js.map +1 -1
  256. package/lib/WABinary/constants.js +1297 -35
  257. package/lib/WABinary/decode.d.ts.map +1 -1
  258. package/lib/WABinary/decode.js +254 -229
  259. package/lib/WABinary/decode.js.map +1 -1
  260. package/lib/WABinary/encode.js +210 -209
  261. package/lib/WABinary/encode.js.map +1 -1
  262. package/lib/WABinary/generic-utils.d.ts +1 -1
  263. package/lib/WABinary/generic-utils.d.ts.map +1 -1
  264. package/lib/WABinary/generic-utils.js +99 -105
  265. package/lib/WABinary/generic-utils.js.map +1 -1
  266. package/lib/WABinary/index.js +6 -58
  267. package/lib/WABinary/jid-utils.d.ts +12 -1
  268. package/lib/WABinary/jid-utils.d.ts.map +1 -1
  269. package/lib/WABinary/jid-utils.js +83 -67
  270. package/lib/WABinary/jid-utils.js.map +1 -1
  271. package/lib/WABinary/types.js +2 -2
  272. package/lib/WAM/BinaryInfo.js +9 -13
  273. package/lib/WAM/constants.d.ts +1 -1
  274. package/lib/WAM/constants.d.ts.map +1 -1
  275. package/lib/WAM/constants.js +22853 -1
  276. package/lib/WAM/constants.js.map +1 -1
  277. package/lib/WAM/encode.js +135 -132
  278. package/lib/WAM/index.js +4 -36
  279. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -1
  280. package/lib/WAUSync/Protocols/USyncContactProtocol.js +50 -31
  281. package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -1
  282. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +50 -58
  283. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +25 -29
  284. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +35 -37
  285. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +4 -2
  286. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -0
  287. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +23 -27
  288. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -0
  289. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +47 -61
  290. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +2 -1
  291. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -1
  292. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +27 -23
  293. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -1
  294. package/lib/WAUSync/Protocols/index.d.ts.map +1 -1
  295. package/lib/WAUSync/Protocols/index.js +6 -58
  296. package/lib/WAUSync/Protocols/index.js.map +1 -1
  297. package/lib/WAUSync/USyncQuery.d.ts +1 -1
  298. package/lib/WAUSync/USyncQuery.d.ts.map +1 -1
  299. package/lib/WAUSync/USyncQuery.js +94 -94
  300. package/lib/WAUSync/USyncQuery.js.map +1 -1
  301. package/lib/WAUSync/USyncUser.d.ts +4 -0
  302. package/lib/WAUSync/USyncUser.d.ts.map +1 -1
  303. package/lib/WAUSync/USyncUser.js +30 -26
  304. package/lib/WAUSync/USyncUser.js.map +1 -1
  305. package/lib/WAUSync/index.js +4 -36
  306. package/lib/index.d.ts +0 -1
  307. package/lib/index.js +11 -112
  308. package/package.json +49 -22
  309. package/README.md +0 -1315
  310. package/lib/Signal/Group/queue-job.d.ts +0 -2
  311. package/lib/Signal/Group/queue-job.js +0 -59
  312. package/lib/Store/index.d.ts +0 -4
  313. package/lib/Store/index.js +0 -47
  314. package/lib/Store/make-cache-manager-store.d.ts +0 -17
  315. package/lib/Store/make-cache-manager-store.js +0 -104
  316. package/lib/Store/make-in-memory-store.d.ts +0 -118
  317. package/lib/Store/make-in-memory-store.js +0 -490
  318. package/lib/Store/make-ordered-dictionary.d.ts +0 -14
  319. package/lib/Store/make-ordered-dictionary.js +0 -81
  320. package/lib/Store/object-repository.d.ts +0 -10
  321. package/lib/Store/object-repository.js +0 -30
  322. package/lib/Types/Newsletter.d.ts.map +0 -1
  323. package/lib/Types/Newsletter.js +0 -34
  324. package/lib/Types/Newsletter.js.map +0 -1
  325. package/lib/Utils/baileys-event-stream.d.ts +0 -17
  326. package/lib/Utils/baileys-event-stream.d.ts.map +0 -1
  327. package/lib/Utils/baileys-event-stream.js +0 -71
  328. package/lib/Utils/baileys-event-stream.js.map +0 -1
  329. package/lib/Utils/extended-messages.d.ts +0 -73
  330. package/lib/Utils/extended-messages.js +0 -283
  331. package/lib/Utils/lid-resolver.d.ts +0 -17
  332. package/lib/Utils/lid-resolver.js +0 -79
@@ -1,488 +1,302 @@
1
- Object.defineProperty(exports, "__esModule", {
2
- value: true
3
- });
4
- exports.initAuthCreds = exports.addTransactionCapability = void 0;
5
- exports.makeCacheableSignalKeyStore = makeCacheableSignalKeyStore;
6
- var _nodeCache = _interopRequireDefault(require("@cacheable/node-cache"));
7
- var _asyncMutex = require("async-mutex");
8
- var _crypto = require("crypto");
9
- var _lruCache = require("lru-cache");
10
- var _index = require("../Defaults/index.js");
11
- var _crypto2 = require("./crypto.js");
12
- var _generics = require("./generics.js");
13
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
1
+ import NodeCache from '@cacheable/node-cache';
2
+ import { Boom } from '@hapi/boom';
3
+ import { AsyncLocalStorage } from 'async_hooks';
4
+ import { Mutex } from 'async-mutex';
5
+ import { randomBytes } from 'crypto';
6
+ import PQueue from 'p-queue';
7
+ import { DEFAULT_CACHE_TTLS } from '../Defaults/index.js';
8
+ import { Curve, signedKeyPair } from './crypto.js';
9
+ import { delay, generateRegistrationId } from './generics.js';
10
+ import { PreKeyManager } from './pre-key-manager.js';
14
11
  /**
15
12
  * Adds caching capability to a SignalKeyStore
16
13
  * @param store the store to add caching to
17
14
  * @param logger to log trace events
18
15
  * @param _cache cache store to use
19
16
  */
20
- function makeCacheableSignalKeyStore(store, logger, _cache) {
21
- const cache = _cache || new _nodeCache.default({
22
- stdTTL: _index.DEFAULT_CACHE_TTLS.SIGNAL_STORE,
23
- // 5 minutes
24
- useClones: false,
25
- deleteOnExpire: true
26
- });
27
- // Mutex for protecting cache operations
28
- const cacheMutex = new _asyncMutex.Mutex();
29
- function getUniqueId(type, id) {
30
- return `${type}.${id}`;
31
- }
32
- return {
33
- async get(type, ids) {
34
- return cacheMutex.runExclusive(async () => {
35
- const data = {};
36
- const idsToFetch = [];
37
- for (const id of ids) {
38
- const item = cache.get(getUniqueId(type, id));
39
- if (typeof item !== 'undefined') {
40
- data[id] = item;
41
- } else {
42
- idsToFetch.push(id);
43
- }
44
- }
45
- if (idsToFetch.length) {
46
- logger?.trace({
47
- items: idsToFetch.length
48
- }, 'loading from store');
49
- const fetched = await store.get(type, idsToFetch);
50
- for (const id of idsToFetch) {
51
- const item = fetched[id];
52
- if (item) {
53
- data[id] = item;
54
- cache.set(getUniqueId(type, id), item);
55
- }
56
- }
57
- }
58
- return data;
59
- });
60
- },
61
- async set(data) {
62
- return cacheMutex.runExclusive(async () => {
63
- let keys = 0;
64
- for (const type in data) {
65
- for (const id in data[type]) {
66
- cache.set(getUniqueId(type, id), data[type][id]);
67
- keys += 1;
68
- }
69
- }
70
- logger?.trace({
71
- keys
72
- }, 'updated cache');
73
- await store.set(data);
74
- });
75
- },
76
- async clear() {
77
- cache.flushAll();
78
- await store.clear?.();
79
- }
80
- };
81
- }
82
- // Module-level specialized mutexes for pre-key operations
83
- const preKeyMutex = new _asyncMutex.Mutex();
84
- const signedPreKeyMutex = new _asyncMutex.Mutex();
85
- /**
86
- * Get the appropriate mutex for the key type
87
- */
88
- const getPreKeyMutex = keyType => {
89
- return keyType === 'signed-pre-key' ? signedPreKeyMutex : preKeyMutex;
90
- };
91
- /**
92
- * Handles pre-key operations with mutex protection
93
- */
94
- async function handlePreKeyOperations(data, keyType, transactionCache, mutations, logger, isInTransaction, state) {
95
- const mutex = getPreKeyMutex(keyType);
96
- await mutex.runExclusive(async () => {
97
- const keyData = data[keyType];
98
- if (!keyData) return;
99
- // Ensure structures exist
100
- transactionCache[keyType] = transactionCache[keyType] || {};
101
- mutations[keyType] = mutations[keyType] || {};
102
- // Separate deletions from updates for batch processing
103
- const deletionKeys = [];
104
- const updateKeys = [];
105
- for (const keyId in keyData) {
106
- if (keyData[keyId] === null) {
107
- deletionKeys.push(keyId);
108
- } else {
109
- updateKeys.push(keyId);
110
- }
111
- }
112
- // Process updates first (no validation needed)
113
- for (const keyId of updateKeys) {
114
- if (transactionCache[keyType]) {
115
- transactionCache[keyType][keyId] = keyData[keyId];
116
- }
117
- if (mutations[keyType]) {
118
- mutations[keyType][keyId] = keyData[keyId];
119
- }
120
- }
121
- // Process deletions with validation
122
- if (deletionKeys.length === 0) return;
123
- if (isInTransaction) {
124
- // In transaction, only allow deletion if key exists in cache
125
- for (const keyId of deletionKeys) {
126
- if (transactionCache[keyType]) {
127
- transactionCache[keyType][keyId] = null;
128
- if (mutations[keyType]) {
129
- // Mark for deletion in mutations
130
- mutations[keyType][keyId] = null;
131
- }
132
- } else {
133
- logger.warn(`Skipping deletion of non-existent ${keyType} in transaction: ${keyId}`);
134
- }
135
- }
136
- return;
137
- }
138
- // Outside transaction, batch validate all deletions
139
- if (!state) return;
140
- const existingKeys = await state.get(keyType, deletionKeys);
141
- for (const keyId of deletionKeys) {
142
- if (existingKeys[keyId]) {
143
- if (transactionCache[keyType]) transactionCache[keyType][keyId] = null;
144
- if (mutations[keyType]) mutations[keyType][keyId] = null;
145
- } else {
146
- logger.warn(`Skipping deletion of non-existent ${keyType}: ${keyId}`);
147
- }
17
+ export function makeCacheableSignalKeyStore(store, logger, _cache) {
18
+ const cache = _cache ||
19
+ new NodeCache({
20
+ stdTTL: DEFAULT_CACHE_TTLS.SIGNAL_STORE, // 5 minutes
21
+ useClones: false,
22
+ deleteOnExpire: true
23
+ });
24
+ // Mutex for protecting cache operations
25
+ const cacheMutex = new Mutex();
26
+ function getUniqueId(type, id) {
27
+ return `${type}.${id}`;
148
28
  }
149
- });
150
- }
151
- /**
152
- * Handles normal key operations for transactions
153
- */
154
- function handleNormalKeyOperations(data, key, transactionCache, mutations) {
155
- Object.assign(transactionCache[key], data[key]);
156
- mutations[key] = mutations[key] || {};
157
- Object.assign(mutations[key], data[key]);
158
- }
159
- /**
160
- * Process pre-key deletions with validation
161
- */
162
- async function processPreKeyDeletions(data, keyType, state, logger) {
163
- const mutex = getPreKeyMutex(keyType);
164
- await mutex.runExclusive(async () => {
165
- const keyData = data[keyType];
166
- if (!keyData) return;
167
- // Validate deletions
168
- for (const keyId in keyData) {
169
- if (keyData[keyId] === null) {
170
- const existingKeys = await state.get(keyType, [keyId]);
171
- if (!existingKeys[keyId]) {
172
- logger.warn(`Skipping deletion of non-existent ${keyType}: ${keyId}`);
173
- if (data[keyType]) delete data[keyType][keyId];
29
+ return {
30
+ async get(type, ids) {
31
+ return cacheMutex.runExclusive(async () => {
32
+ const data = {};
33
+ const idsToFetch = [];
34
+ for (const id of ids) {
35
+ const item = (await cache.get(getUniqueId(type, id)));
36
+ if (typeof item !== 'undefined') {
37
+ data[id] = item;
38
+ }
39
+ else {
40
+ idsToFetch.push(id);
41
+ }
42
+ }
43
+ if (idsToFetch.length) {
44
+ logger?.trace({ items: idsToFetch.length }, 'loading from store');
45
+ const fetched = await store.get(type, idsToFetch);
46
+ for (const id of idsToFetch) {
47
+ const item = fetched[id];
48
+ if (item) {
49
+ data[id] = item;
50
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
51
+ await cache.set(getUniqueId(type, id), item);
52
+ }
53
+ }
54
+ }
55
+ return data;
56
+ });
57
+ },
58
+ async set(data) {
59
+ return cacheMutex.runExclusive(async () => {
60
+ let keys = 0;
61
+ for (const type in data) {
62
+ for (const id in data[type]) {
63
+ await cache.set(getUniqueId(type, id), data[type][id]);
64
+ keys += 1;
65
+ }
66
+ }
67
+ logger?.trace({ keys }, 'updated cache');
68
+ await store.set(data);
69
+ });
70
+ },
71
+ async clear() {
72
+ await cache.flushAll();
73
+ await store.clear?.();
174
74
  }
175
- }
176
- }
177
- });
178
- }
179
- /**
180
- * Executes a function with mutexes acquired for given key types
181
- * Uses async-mutex's runExclusive with efficient batching
182
- */
183
- async function withMutexes(keyTypes, getKeyTypeMutex, fn) {
184
- if (keyTypes.length === 0) {
185
- return fn();
186
- }
187
- if (keyTypes.length === 1) {
188
- return getKeyTypeMutex(keyTypes[0]).runExclusive(fn);
189
- }
190
- // For multiple mutexes, sort by key type to prevent deadlocks
191
- // Then acquire all mutexes in order using Promise.all for better efficiency
192
- const sortedKeyTypes = [...keyTypes].sort();
193
- const mutexes = sortedKeyTypes.map(getKeyTypeMutex);
194
- // Acquire all mutexes in order to prevent deadlocks
195
- const releases = [];
196
- try {
197
- for (const mutex of mutexes) {
198
- releases.push(await mutex.acquire());
199
- }
200
- return await fn();
201
- } finally {
202
- // Release in reverse order
203
- while (releases.length > 0) {
204
- const release = releases.pop();
205
- if (release) release();
206
- }
207
- }
75
+ };
208
76
  }
209
77
  /**
210
- * Adds DB like transaction capability (https://en.wikipedia.org/wiki/Database_transaction) to the SignalKeyStore,
211
- * this allows batch read & write operations & improves the performance of the lib
78
+ * Adds DB-like transaction capability to the SignalKeyStore
79
+ * Uses AsyncLocalStorage for automatic context management
212
80
  * @param state the key store to apply this capability to
213
81
  * @param logger logger to log events
214
82
  * @returns SignalKeyStore with transaction capability
215
83
  */
216
- const addTransactionCapability = (state, logger, {
217
- maxCommitRetries,
218
- delayBetweenTriesMs
219
- }) => {
220
- // number of queries made to the DB during the transaction
221
- // only there for logging purposes
222
- let dbQueriesInTransaction = 0;
223
- let transactionCache = {};
224
- let mutations = {};
225
- // LRU Cache to hold mutexes for different key types
226
- const mutexCache = new _lruCache.LRUCache({
227
- ttl: 60 * 60 * 1000,
228
- // 1 hour
229
- ttlAutopurge: true,
230
- updateAgeOnGet: true
231
- });
232
- let transactionsInProgress = 0;
233
- function getKeyTypeMutex(type) {
234
- return getMutex(`keytype:${type}`);
235
- }
236
- function getSenderKeyMutex(senderKeyName) {
237
- return getMutex(`senderkey:${senderKeyName}`);
238
- }
239
- function getTransactionMutex(key) {
240
- return getMutex(`transaction:${key}`);
241
- }
242
- // Get or create a mutex for a specific key name
243
- function getMutex(key) {
244
- let mutex = mutexCache.get(key);
245
- if (!mutex) {
246
- mutex = new _asyncMutex.Mutex();
247
- mutexCache.set(key, mutex);
248
- logger.info({
249
- key
250
- }, 'created new mutex');
251
- }
252
- return mutex;
253
- }
254
- // Sender key operations with proper mutex sequencing
255
- function queueSenderKeyOperation(senderKeyName, operation) {
256
- return getSenderKeyMutex(senderKeyName).runExclusive(operation);
257
- }
258
- // Check if we are currently in a transaction
259
- function isInTransaction() {
260
- return transactionsInProgress > 0;
261
- }
262
- // Helper function to handle transaction commit with retries
263
- async function commitTransaction() {
264
- if (!Object.keys(mutations).length) {
265
- logger.trace('no mutations in transaction');
266
- return;
267
- }
268
- logger.trace('committing transaction');
269
- let tries = maxCommitRetries;
270
- while (tries > 0) {
271
- tries -= 1;
272
- try {
273
- await state.set(mutations);
274
- logger.trace({
275
- dbQueriesInTransaction
276
- }, 'committed transaction');
277
- return;
278
- } catch (error) {
279
- logger.warn(`failed to commit ${Object.keys(mutations).length} mutations, tries left=${tries}`);
280
- if (tries > 0) {
281
- await (0, _generics.delay)(delayBetweenTriesMs);
84
+ export const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetweenTriesMs }) => {
85
+ const txStorage = new AsyncLocalStorage();
86
+ // Queues for concurrency control (keyed by signal data type - bounded set)
87
+ const keyQueues = new Map();
88
+ // Transaction mutexes with reference counting for cleanup
89
+ const txMutexes = new Map();
90
+ const txMutexRefCounts = new Map();
91
+ // Pre-key manager for specialized operations
92
+ const preKeyManager = new PreKeyManager(state, logger);
93
+ /**
94
+ * Get or create a queue for a specific key type
95
+ */
96
+ function getQueue(key) {
97
+ if (!keyQueues.has(key)) {
98
+ keyQueues.set(key, new PQueue({ concurrency: 1 }));
282
99
  }
283
- }
100
+ return keyQueues.get(key);
284
101
  }
285
- }
286
- // Helper function to clean up transaction state
287
- function cleanupTransactionState() {
288
- transactionsInProgress -= 1;
289
- if (transactionsInProgress === 0) {
290
- transactionCache = {};
291
- mutations = {};
292
- dbQueriesInTransaction = 0;
102
+ /**
103
+ * Get or create a transaction mutex
104
+ */
105
+ function getTxMutex(key) {
106
+ if (!txMutexes.has(key)) {
107
+ txMutexes.set(key, new Mutex());
108
+ txMutexRefCounts.set(key, 0);
109
+ }
110
+ return txMutexes.get(key);
293
111
  }
294
- }
295
- // Helper function to execute work within transaction
296
- async function executeTransactionWork(work) {
297
- const result = await work();
298
- // commit if this is the outermost transaction
299
- if (transactionsInProgress === 1) {
300
- await commitTransaction();
112
+ /**
113
+ * Acquire a reference to a transaction mutex
114
+ */
115
+ function acquireTxMutexRef(key) {
116
+ const count = txMutexRefCounts.get(key) ?? 0;
117
+ txMutexRefCounts.set(key, count + 1);
301
118
  }
302
- return result;
303
- }
304
- return {
305
- get: async (type, ids) => {
306
- if (isInTransaction()) {
307
- const dict = transactionCache[type];
308
- const idsRequiringFetch = dict ? ids.filter(item => typeof dict[item] === 'undefined') : ids;
309
- // only fetch if there are any items to fetch
310
- if (idsRequiringFetch.length) {
311
- dbQueriesInTransaction += 1;
312
- // Use per-sender-key queue for sender-key operations when possible
313
- if (type === 'sender-key') {
314
- logger.info({
315
- idsRequiringFetch
316
- }, 'processing sender keys in transaction');
317
- // For sender keys, process each one with queued operations to maintain serialization
318
- for (const senderKeyName of idsRequiringFetch) {
319
- await queueSenderKeyOperation(senderKeyName, async () => {
320
- logger.info({
321
- senderKeyName
322
- }, 'fetching sender key in transaction');
323
- const result = await state.get(type, [senderKeyName]);
324
- // Update transaction cache
325
- transactionCache[type] || (transactionCache[type] = {});
326
- Object.assign(transactionCache[type], result);
327
- logger.info({
328
- senderKeyName,
329
- hasResult: !!result[senderKeyName]
330
- }, 'sender key fetch complete');
331
- });
119
+ /**
120
+ * Release a reference to a transaction mutex and cleanup if no longer needed
121
+ */
122
+ function releaseTxMutexRef(key) {
123
+ const count = (txMutexRefCounts.get(key) ?? 1) - 1;
124
+ txMutexRefCounts.set(key, count);
125
+ // Cleanup if no more references and mutex is not locked
126
+ if (count <= 0) {
127
+ const mutex = txMutexes.get(key);
128
+ if (mutex && !mutex.isLocked()) {
129
+ txMutexes.delete(key);
130
+ txMutexRefCounts.delete(key);
332
131
  }
333
- } else {
334
- // Use runExclusive for cleaner mutex handling
335
- await getKeyTypeMutex(type).runExclusive(async () => {
336
- const result = await state.get(type, idsRequiringFetch);
337
- // Update transaction cache
338
- transactionCache[type] || (transactionCache[type] = {});
339
- Object.assign(transactionCache[type], result);
340
- });
341
- }
342
132
  }
343
- return ids.reduce((dict, id) => {
344
- const value = transactionCache[type]?.[id];
345
- if (value) {
346
- dict[id] = value;
347
- }
348
- return dict;
349
- }, {});
350
- } else {
351
- // Not in transaction, fetch directly with queue protection
352
- if (type === 'sender-key') {
353
- // For sender keys, use individual queues to maintain per-key serialization
354
- const results = {};
355
- for (const senderKeyName of ids) {
356
- const result = await queueSenderKeyOperation(senderKeyName, async () => await state.get(type, [senderKeyName]));
357
- Object.assign(results, result);
358
- }
359
- return results;
360
- } else {
361
- return await getKeyTypeMutex(type).runExclusive(() => state.get(type, ids));
133
+ }
134
+ /**
135
+ * Check if currently in a transaction
136
+ */
137
+ function isInTransaction() {
138
+ return !!txStorage.getStore();
139
+ }
140
+ /**
141
+ * Commit transaction with retries
142
+ */
143
+ async function commitWithRetry(mutations) {
144
+ if (Object.keys(mutations).length === 0) {
145
+ logger.trace('no mutations in transaction');
146
+ return;
362
147
  }
363
- }
364
- },
365
- set: async data => {
366
- if (isInTransaction()) {
367
- logger.trace({
368
- types: Object.keys(data)
369
- }, 'caching in transaction');
370
- for (const key_ in data) {
371
- const key = key_;
372
- transactionCache[key] = transactionCache[key] || {};
373
- // Special handling for pre-keys and signed-pre-keys
374
- if (key === 'pre-key') {
375
- await handlePreKeyOperations(data, key, transactionCache, mutations, logger, true);
376
- } else {
377
- // Normal handling for other key types
378
- handleNormalKeyOperations(data, key, transactionCache, mutations);
379
- }
148
+ logger.trace('committing transaction');
149
+ for (let attempt = 0; attempt < maxCommitRetries; attempt++) {
150
+ try {
151
+ await state.set(mutations);
152
+ logger.trace({ mutationCount: Object.keys(mutations).length }, 'committed transaction');
153
+ return;
154
+ }
155
+ catch (error) {
156
+ const retriesLeft = maxCommitRetries - attempt - 1;
157
+ logger.warn(`failed to commit mutations, retries left=${retriesLeft}`);
158
+ if (retriesLeft === 0) {
159
+ throw error;
160
+ }
161
+ await delay(delayBetweenTriesMs);
162
+ }
380
163
  }
381
- } else {
382
- // Not in transaction, apply directly with mutex protection
383
- const hasSenderKeys = 'sender-key' in data;
384
- const senderKeyNames = hasSenderKeys ? Object.keys(data['sender-key'] || {}) : [];
385
- if (hasSenderKeys) {
386
- logger.info({
387
- senderKeyNames
388
- }, 'processing sender key set operations');
389
- // Handle sender key operations with per-key queues
390
- for (const senderKeyName of senderKeyNames) {
391
- await queueSenderKeyOperation(senderKeyName, async () => {
392
- // Create data subset for this specific sender key
393
- const senderKeyData = {
394
- 'sender-key': {
395
- [senderKeyName]: data['sender-key'][senderKeyName]
164
+ }
165
+ return {
166
+ get: async (type, ids) => {
167
+ const ctx = txStorage.getStore();
168
+ if (!ctx) {
169
+ // No transaction - direct read without exclusive lock for concurrency
170
+ return state.get(type, ids);
171
+ }
172
+ // In transaction - check cache first
173
+ const cached = ctx.cache[type] || {};
174
+ const missing = ids.filter(id => !(id in cached));
175
+ if (missing.length > 0) {
176
+ ctx.dbQueries++;
177
+ logger.trace({ type, count: missing.length }, 'fetching missing keys in transaction');
178
+ const fetched = await getTxMutex(type).runExclusive(() => state.get(type, missing));
179
+ // Update cache
180
+ ctx.cache[type] = ctx.cache[type] || {};
181
+ Object.assign(ctx.cache[type], fetched);
182
+ }
183
+ // Return requested ids from cache
184
+ const result = {};
185
+ for (const id of ids) {
186
+ const value = ctx.cache[type]?.[id];
187
+ if (value !== undefined && value !== null) {
188
+ result[id] = value;
396
189
  }
397
- };
398
- logger.trace({
399
- senderKeyName
400
- }, 'storing sender key');
401
- // Apply changes to the store
402
- await state.set(senderKeyData);
403
- logger.trace({
404
- senderKeyName
405
- }, 'sender key stored');
406
- });
407
- }
408
- // Handle any non-sender-key data with regular mutexes
409
- const nonSenderKeyData = {
410
- ...data
411
- };
412
- delete nonSenderKeyData['sender-key'];
413
- if (Object.keys(nonSenderKeyData).length > 0) {
414
- await withMutexes(Object.keys(nonSenderKeyData), getKeyTypeMutex, async () => {
415
- // Process pre-keys and signed-pre-keys separately with specialized mutexes
416
- for (const key_ in nonSenderKeyData) {
417
- const keyType = key_;
418
- if (keyType === 'pre-key') {
419
- await processPreKeyDeletions(nonSenderKeyData, keyType, state, logger);
190
+ }
191
+ return result;
192
+ },
193
+ set: async (data) => {
194
+ const ctx = txStorage.getStore();
195
+ if (!ctx) {
196
+ // No transaction - direct write with queue protection
197
+ const types = Object.keys(data);
198
+ // Process pre-keys with validation
199
+ for (const type_ of types) {
200
+ const type = type_;
201
+ if (type === 'pre-key') {
202
+ await preKeyManager.validateDeletions(data, type);
203
+ }
420
204
  }
421
- }
422
- // Apply changes to the store
423
- await state.set(nonSenderKeyData);
424
- });
425
- }
426
- } else {
427
- // No sender keys - use original logic
428
- await withMutexes(Object.keys(data), getKeyTypeMutex, async () => {
429
- // Process pre-keys and signed-pre-keys separately with specialized mutexes
205
+ // Write all data in parallel
206
+ await Promise.all(types.map(type => getQueue(type).add(async () => {
207
+ const typeData = { [type]: data[type] };
208
+ await state.set(typeData);
209
+ })));
210
+ return;
211
+ }
212
+ // In transaction - update cache and mutations
213
+ logger.trace({ types: Object.keys(data) }, 'caching in transaction');
430
214
  for (const key_ in data) {
431
- const keyType = key_;
432
- if (keyType === 'pre-key') {
433
- await processPreKeyDeletions(data, keyType, state, logger);
434
- }
215
+ const key = key_;
216
+ // Ensure structures exist
217
+ ctx.cache[key] = ctx.cache[key] || {};
218
+ ctx.mutations[key] = ctx.mutations[key] || {};
219
+ // Special handling for pre-keys
220
+ if (key === 'pre-key') {
221
+ await preKeyManager.processOperations(data, key, ctx.cache, ctx.mutations, true);
222
+ }
223
+ else {
224
+ // Normal key types
225
+ Object.assign(ctx.cache[key], data[key]);
226
+ Object.assign(ctx.mutations[key], data[key]);
227
+ }
228
+ }
229
+ },
230
+ isInTransaction,
231
+ transaction: async (work, key) => {
232
+ const existing = txStorage.getStore();
233
+ // Nested transaction - reuse existing context
234
+ if (existing) {
235
+ logger.trace('reusing existing transaction context');
236
+ return work();
237
+ }
238
+ // New transaction - acquire mutex and create context
239
+ const mutex = getTxMutex(key);
240
+ acquireTxMutexRef(key);
241
+ try {
242
+ return await mutex.runExclusive(async () => {
243
+ const ctx = {
244
+ cache: {},
245
+ mutations: {},
246
+ dbQueries: 0
247
+ };
248
+ logger.trace('entering transaction');
249
+ try {
250
+ const result = await txStorage.run(ctx, work);
251
+ // Commit mutations
252
+ await commitWithRetry(ctx.mutations);
253
+ logger.trace({ dbQueries: ctx.dbQueries }, 'transaction completed');
254
+ return result;
255
+ }
256
+ catch (error) {
257
+ logger.error({ error }, 'transaction failed, rolling back');
258
+ throw error;
259
+ }
260
+ });
261
+ }
262
+ finally {
263
+ releaseTxMutexRef(key);
435
264
  }
436
- // Apply changes to the store
437
- await state.set(data);
438
- });
439
- }
440
- }
441
- },
442
- isInTransaction,
443
- async transaction(work, key) {
444
- const releaseTxMutex = await getTransactionMutex(key).acquire();
445
- try {
446
- transactionsInProgress += 1;
447
- if (transactionsInProgress === 1) {
448
- logger.trace('entering transaction');
449
- }
450
- // Release the transaction mutex now that we've updated the counter
451
- // This allows other transactions to start preparing
452
- releaseTxMutex();
453
- try {
454
- return await executeTransactionWork(work);
455
- } finally {
456
- cleanupTransactionState();
457
265
  }
458
- } catch (error) {
459
- releaseTxMutex();
460
- throw error;
461
- }
266
+ };
267
+ };
268
+ /**
269
+ * Returns the authenticated user's JID, or throws a Boom-401 if creds are not yet authenticated.
270
+ * Use this anywhere we'd otherwise reach for `creds.me!.id` to fail fast with a descriptive error.
271
+ */
272
+ export const assertMeId = (creds) => {
273
+ const id = creds.me?.id;
274
+ if (!id) {
275
+ throw new Boom('Cannot proceed: socket is not authenticated yet (creds.me.id is missing)', { statusCode: 401 });
462
276
  }
463
- };
277
+ return id;
464
278
  };
465
- exports.addTransactionCapability = addTransactionCapability;
466
- const initAuthCreds = () => {
467
- const identityKey = _crypto2.Curve.generateKeyPair();
468
- return {
469
- noiseKey: _crypto2.Curve.generateKeyPair(),
470
- pairingEphemeralKeyPair: _crypto2.Curve.generateKeyPair(),
471
- signedIdentityKey: identityKey,
472
- signedPreKey: (0, _crypto2.signedKeyPair)(identityKey, 1),
473
- registrationId: (0, _generics.generateRegistrationId)(),
474
- advSecretKey: (0, _crypto.randomBytes)(32).toString('base64'),
475
- processedHistoryMessages: [],
476
- nextPreKeyId: 1,
477
- firstUnuploadedPreKeyId: 1,
478
- accountSyncCounter: 0,
479
- accountSettings: {
480
- unarchiveChats: false
481
- },
482
- registered: false,
483
- pairingCode: undefined,
484
- lastPropHash: undefined,
485
- routingInfo: undefined
486
- };
279
+ export const initAuthCreds = () => {
280
+ const identityKey = Curve.generateKeyPair();
281
+ return {
282
+ noiseKey: Curve.generateKeyPair(),
283
+ pairingEphemeralKeyPair: Curve.generateKeyPair(),
284
+ signedIdentityKey: identityKey,
285
+ signedPreKey: signedKeyPair(identityKey, 1),
286
+ registrationId: generateRegistrationId(),
287
+ advSecretKey: randomBytes(32).toString('base64'),
288
+ processedHistoryMessages: [],
289
+ nextPreKeyId: 1,
290
+ firstUnuploadedPreKeyId: 1,
291
+ accountSyncCounter: 0,
292
+ accountSettings: {
293
+ unarchiveChats: false
294
+ },
295
+ registered: false,
296
+ pairingCode: undefined,
297
+ lastPropHash: undefined,
298
+ routingInfo: undefined,
299
+ additionalData: undefined
300
+ };
487
301
  };
488
- exports.initAuthCreds = initAuthCreds;
302
+ //# sourceMappingURL=auth-utils.js.map