@vinzsocket/baileys 2.8.35 → 3.0.10
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.
- package/WAProto/GenerateStatics.sh +2 -2
- package/WAProto/WAProto.proto +1339 -493
- package/WAProto/fix-imports.js +75 -19
- package/WAProto/index.d.ts +5274 -1945
- package/WAProto/index.js +81079 -20694
- package/lib/Defaults/index.d.ts +75 -0
- package/lib/Defaults/index.d.ts.map +1 -0
- package/lib/Defaults/index.js +122 -110
- package/lib/Defaults/index.js.map +1 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
- package/lib/Signal/Group/ciphertext-message.js +11 -18
- package/lib/Signal/Group/ciphertext-message.js.map +1 -0
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
- package/lib/Signal/Group/group-session-builder.js +27 -35
- package/lib/Signal/Group/group-session-builder.js.map +1 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
- package/lib/Signal/Group/group_cipher.js +75 -95
- package/lib/Signal/Group/group_cipher.js.map +1 -0
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.d.ts.map +1 -0
- package/lib/Signal/Group/index.js +12 -79
- package/lib/Signal/Group/index.js.map +1 -0
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
- package/lib/Signal/Group/keyhelper.js +14 -25
- package/lib/Signal/Group/keyhelper.js.map +1 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-chain-key.js +24 -37
- package/lib/Signal/Group/sender-chain-key.js.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -61
- package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-message.js +64 -68
- package/lib/Signal/Group/sender-key-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-name.js +41 -47
- package/lib/Signal/Group/sender-key-name.js.map +1 -0
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-record.js +36 -50
- package/lib/Signal/Group/sender-key-record.js.map +1 -0
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-state.js +76 -96
- package/lib/Signal/Group/sender-key-state.js.map +1 -0
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-message-key.js +25 -34
- package/lib/Signal/Group/sender-message-key.js.map +1 -0
- package/lib/Signal/libsignal.d.ts +5 -0
- package/lib/Signal/libsignal.d.ts.map +1 -0
- package/lib/Signal/libsignal.js +415 -402
- package/lib/Signal/libsignal.js.map +1 -0
- package/lib/Signal/lid-mapping.d.ts +23 -0
- package/lib/Signal/lid-mapping.d.ts.map +1 -0
- package/lib/Signal/lid-mapping.js +273 -111
- package/lib/Signal/lid-mapping.js.map +1 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.d.ts.map +1 -0
- package/lib/Socket/Client/index.js +3 -27
- package/lib/Socket/Client/index.js.map +1 -0
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.d.ts.map +1 -0
- package/lib/Socket/Client/types.js +10 -17
- package/lib/Socket/Client/types.js.map +1 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.d.ts.map +1 -0
- package/lib/Socket/Client/websocket.js +53 -57
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/business.d.ts +217 -0
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +374 -363
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts +124 -0
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +1162 -1041
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +273 -0
- package/lib/Socket/communities.d.ts.map +1 -0
- package/lib/Socket/communities.js +418 -469
- package/lib/Socket/communities.js.map +1 -0
- package/lib/Socket/groups.d.ts +161 -0
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +337 -393
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +260 -0
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +10 -20
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +203 -0
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +1738 -1394
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +199 -0
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +1101 -1245
- package/lib/Socket/messages-send.js.map +1 -0
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.d.ts.map +1 -0
- package/lib/Socket/mex.js +38 -51
- package/lib/Socket/mex.js.map +1 -0
- package/lib/Socket/newsletter.d.ts +170 -0
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +175 -225
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/socket.d.ts +59 -0
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +930 -914
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Types/Auth.d.ts +117 -0
- package/lib/Types/Auth.d.ts.map +1 -0
- package/lib/Types/Auth.js +2 -5
- package/lib/Types/Auth.js.map +1 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.d.ts.map +1 -0
- package/lib/Types/Bussines.js +2 -5
- package/lib/Types/Bussines.js.map +1 -0
- package/lib/Types/Call.d.ts +15 -0
- package/lib/Types/Call.d.ts.map +1 -0
- package/lib/Types/Call.js +2 -5
- package/lib/Types/Call.js.map +1 -0
- package/lib/Types/Chat.d.ts +124 -0
- package/lib/Types/Chat.d.ts.map +1 -0
- package/lib/Types/Chat.js +7 -7
- package/lib/Types/Chat.js.map +1 -0
- package/lib/Types/Contact.d.ts +26 -0
- package/lib/Types/Contact.d.ts.map +1 -0
- package/lib/Types/Contact.js +2 -5
- package/lib/Types/Contact.js.map +1 -0
- package/lib/Types/Events.d.ts +256 -0
- package/lib/Types/Events.d.ts.map +1 -0
- package/lib/Types/Events.js +2 -3
- package/lib/Types/Events.js.map +1 -0
- package/lib/Types/GroupMetadata.d.ts +71 -0
- package/lib/Types/GroupMetadata.d.ts.map +1 -0
- package/lib/Types/GroupMetadata.js +2 -5
- package/lib/Types/GroupMetadata.js.map +1 -0
- package/lib/Types/Label.d.ts +47 -0
- package/lib/Types/Label.d.ts.map +1 -0
- package/lib/Types/Label.js +22 -28
- package/lib/Types/Label.js.map +1 -0
- package/lib/Types/LabelAssociation.d.ts +30 -0
- package/lib/Types/LabelAssociation.d.ts.map +1 -0
- package/lib/Types/LabelAssociation.js +4 -10
- package/lib/Types/LabelAssociation.js.map +1 -0
- package/lib/Types/Message.d.ts +320 -0
- package/lib/Types/Message.d.ts.map +1 -0
- package/lib/Types/Message.js +8 -20
- package/lib/Types/Message.js.map +1 -0
- package/lib/Types/Mex.d.ts +141 -0
- package/lib/Types/Mex.d.ts.map +1 -0
- package/lib/Types/Mex.js +37 -0
- package/lib/Types/Mex.js.map +1 -0
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Product.d.ts.map +1 -0
- package/lib/Types/Product.js +2 -5
- package/lib/Types/Product.js.map +1 -0
- package/lib/Types/Signal.d.ts +87 -0
- package/lib/Types/Signal.d.ts.map +1 -0
- package/lib/Types/Signal.js +2 -3
- package/lib/Types/Signal.js.map +1 -0
- package/lib/Types/Socket.d.ts +136 -0
- package/lib/Types/Socket.d.ts.map +1 -0
- package/lib/Types/Socket.js +3 -4
- package/lib/Types/Socket.js.map +1 -0
- package/lib/Types/State.d.ts +97 -0
- package/lib/Types/State.d.ts.map +1 -0
- package/lib/Types/State.js +54 -17
- package/lib/Types/State.js.map +1 -0
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/USync.d.ts.map +1 -0
- package/lib/Types/USync.js +2 -3
- package/lib/Types/USync.js.map +1 -0
- package/lib/Types/index.d.ts +65 -0
- package/lib/Types/index.d.ts.map +1 -0
- package/lib/Types/index.js +24 -165
- package/lib/Types/index.js.map +1 -0
- package/lib/Utils/auth-utils.d.ts +24 -0
- package/lib/Utils/auth-utils.d.ts.map +1 -0
- package/lib/Utils/auth-utils.js +272 -461
- package/lib/Utils/auth-utils.js.map +1 -0
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.d.ts.map +1 -0
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/browser-utils.js.map +1 -0
- package/lib/Utils/business.d.ts +23 -0
- package/lib/Utils/business.d.ts.map +1 -0
- package/lib/Utils/business.js +207 -223
- package/lib/Utils/business.js.map +1 -0
- package/lib/Utils/chat-utils.d.ts +100 -0
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +828 -803
- package/lib/Utils/chat-utils.js.map +1 -0
- package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
- package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -0
- package/lib/Utils/companion-reg-client-utils.js +35 -0
- package/lib/Utils/companion-reg-client-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts +37 -0
- package/lib/Utils/crypto.d.ts.map +1 -0
- package/lib/Utils/crypto.js +87 -144
- package/lib/Utils/crypto.js.map +1 -0
- package/lib/Utils/decode-wa-message.d.ts +66 -0
- package/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/lib/Utils/decode-wa-message.js +291 -262
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts +36 -0
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +598 -560
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts +91 -0
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +329 -363
- package/lib/Utils/generics.js.map +1 -0
- package/lib/Utils/history.d.ts +24 -0
- package/lib/Utils/history.d.ts.map +1 -0
- package/lib/Utils/history.js +129 -96
- package/lib/Utils/history.js.map +1 -0
- package/lib/Utils/identity-change-handler.d.ts +44 -0
- package/lib/Utils/identity-change-handler.d.ts.map +1 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/identity-change-handler.js.map +1 -0
- package/lib/Utils/index.d.ts +22 -0
- package/lib/Utils/index.d.ts.map +1 -0
- package/lib/Utils/index.js +22 -236
- package/lib/Utils/index.js.map +1 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.d.ts.map +1 -0
- package/lib/Utils/link-preview.js +69 -86
- package/lib/Utils/link-preview.js.map +1 -0
- package/lib/Utils/logger.d.ts +12 -0
- package/lib/Utils/logger.d.ts.map +1 -0
- package/lib/Utils/logger.js +3 -11
- package/lib/Utils/logger.js.map +1 -0
- package/lib/Utils/lt-hash.d.ts +8 -0
- package/lib/Utils/lt-hash.d.ts.map +1 -0
- package/lib/Utils/lt-hash.js +2 -52
- package/lib/Utils/lt-hash.js.map +1 -0
- package/lib/Utils/make-mutex.d.ts +9 -0
- package/lib/Utils/make-mutex.d.ts.map +1 -0
- package/lib/Utils/make-mutex.js +30 -43
- package/lib/Utils/make-mutex.js.map +1 -0
- package/lib/Utils/message-retry-manager.d.ts +115 -0
- package/lib/Utils/message-retry-manager.d.ts.map +1 -0
- package/lib/Utils/message-retry-manager.js +259 -162
- package/lib/Utils/message-retry-manager.js.map +1 -0
- package/lib/Utils/messages-media.d.ts +133 -0
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +732 -711
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages.d.ts +91 -0
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +817 -803
- package/lib/Utils/messages.js.map +1 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.d.ts.map +1 -0
- package/lib/Utils/noise-handler.js +195 -168
- package/lib/Utils/noise-handler.js.map +1 -0
- package/lib/Utils/offline-node-processor.d.ts +17 -0
- package/lib/Utils/offline-node-processor.d.ts.map +1 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/offline-node-processor.js.map +1 -0
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.d.ts.map +1 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/pre-key-manager.js.map +1 -0
- package/lib/Utils/process-message.d.ts +60 -0
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +601 -424
- package/lib/Utils/process-message.js.map +1 -0
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.d.ts.map +1 -0
- package/lib/Utils/reporting-utils.js +258 -0
- package/lib/Utils/reporting-utils.js.map +1 -0
- package/lib/Utils/signal.d.ts +47 -0
- package/lib/Utils/signal.d.ts.map +1 -0
- package/lib/Utils/signal.js +180 -206
- package/lib/Utils/signal.js.map +1 -0
- package/lib/Utils/stanza-ack.d.ts +11 -0
- package/lib/Utils/stanza-ack.d.ts.map +1 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/stanza-ack.js.map +1 -0
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.d.ts.map +1 -0
- package/lib/Utils/sync-action-utils.js +49 -0
- package/lib/Utils/sync-action-utils.js.map +1 -0
- package/lib/Utils/tc-token-utils.d.ts +37 -0
- package/lib/Utils/tc-token-utils.d.ts.map +1 -0
- package/lib/Utils/tc-token-utils.js +163 -0
- package/lib/Utils/tc-token-utils.js.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +98 -101
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.d.ts.map +1 -0
- package/lib/Utils/validate-connection.js +191 -188
- package/lib/Utils/validate-connection.js.map +1 -0
- package/lib/WABinary/constants.d.ts +28 -0
- package/lib/WABinary/constants.d.ts.map +1 -0
- package/lib/WABinary/constants.js +1295 -36
- package/lib/WABinary/constants.js.map +1 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.d.ts.map +1 -0
- package/lib/WABinary/decode.js +254 -232
- package/lib/WABinary/decode.js.map +1 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.d.ts.map +1 -0
- package/lib/WABinary/encode.js +208 -210
- package/lib/WABinary/encode.js.map +1 -0
- package/lib/WABinary/generic-utils.d.ts +15 -0
- package/lib/WABinary/generic-utils.d.ts.map +1 -0
- package/lib/WABinary/generic-utils.js +97 -106
- package/lib/WABinary/generic-utils.js.map +1 -0
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.d.ts.map +1 -0
- package/lib/WABinary/index.js +6 -60
- package/lib/WABinary/index.js.map +1 -0
- package/lib/WABinary/jid-utils.d.ts +48 -0
- package/lib/WABinary/jid-utils.d.ts.map +1 -0
- package/lib/WABinary/jid-utils.js +83 -70
- package/lib/WABinary/jid-utils.js.map +1 -0
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WABinary/types.d.ts.map +1 -0
- package/lib/WABinary/types.js +2 -4
- package/lib/WABinary/types.js.map +1 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -0
- package/lib/WAM/BinaryInfo.d.ts.map +1 -0
- package/lib/WAM/BinaryInfo.js +9 -16
- package/lib/WAM/BinaryInfo.js.map +1 -0
- package/lib/WAM/constants.d.ts +40 -0
- package/lib/WAM/constants.d.ts.map +1 -0
- package/lib/WAM/constants.js +22853 -13001
- package/lib/WAM/constants.js.map +1 -0
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.d.ts.map +1 -0
- package/lib/WAM/encode.js +133 -133
- package/lib/WAM/encode.js.map +1 -0
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.d.ts.map +1 -0
- package/lib/WAM/index.js +4 -38
- package/lib/WAM/index.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +50 -34
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +50 -61
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +25 -32
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +35 -40
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +23 -29
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +47 -64
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +27 -26
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/index.d.ts +6 -0
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/index.js +6 -60
- package/lib/WAUSync/Protocols/index.js.map +1 -0
- package/lib/WAUSync/USyncQuery.d.ts +30 -0
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
- package/lib/WAUSync/USyncQuery.js +94 -97
- package/lib/WAUSync/USyncQuery.js.map +1 -0
- package/lib/WAUSync/USyncUser.d.ts +17 -0
- package/lib/WAUSync/USyncUser.d.ts.map +1 -0
- package/lib/WAUSync/USyncUser.js +30 -29
- package/lib/WAUSync/USyncUser.js.map +1 -0
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.d.ts.map +1 -0
- package/lib/WAUSync/index.js +4 -38
- package/lib/WAUSync/index.js.map +1 -0
- package/lib/index.d.ts +12 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -114
- package/lib/index.js.map +1 -0
- package/package.json +47 -20
- package/README.md +0 -1315
- package/lib/Signal/Group/queue-job.js +0 -61
- package/lib/Store/index.js +0 -49
- package/lib/Store/make-cache-manager-store.js +0 -106
- package/lib/Store/make-in-memory-store.js +0 -497
- package/lib/Store/make-ordered-dictionary.js +0 -83
- package/lib/Store/object-repository.js +0 -32
- package/lib/Types/Newsletter.js +0 -37
- package/lib/Utils/baileys-event-stream.js +0 -74
- package/lib/Utils/extended-messages.js +0 -285
- package/lib/Utils/lid-resolver.js +0 -81
- package/lib/Utils/mention.js +0 -137
package/lib/Utils/auth-utils.js
CHANGED
|
@@ -1,491 +1,302 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var _lruCache = require("lru-cache");
|
|
12
|
-
var _index = require("../Defaults/index.js");
|
|
13
|
-
var _crypto2 = require("./crypto.js");
|
|
14
|
-
var _generics = require("./generics.js");
|
|
15
|
-
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';
|
|
16
11
|
/**
|
|
17
12
|
* Adds caching capability to a SignalKeyStore
|
|
18
13
|
* @param store the store to add caching to
|
|
19
14
|
* @param logger to log trace events
|
|
20
15
|
* @param _cache cache store to use
|
|
21
16
|
*/
|
|
22
|
-
function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
async get(type, ids) {
|
|
36
|
-
return cacheMutex.runExclusive(async () => {
|
|
37
|
-
const data = {};
|
|
38
|
-
const idsToFetch = [];
|
|
39
|
-
for (const id of ids) {
|
|
40
|
-
const item = cache.get(getUniqueId(type, id));
|
|
41
|
-
if (typeof item !== 'undefined') {
|
|
42
|
-
data[id] = item;
|
|
43
|
-
} else {
|
|
44
|
-
idsToFetch.push(id);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (idsToFetch.length) {
|
|
48
|
-
logger?.trace({
|
|
49
|
-
items: idsToFetch.length
|
|
50
|
-
}, 'loading from store');
|
|
51
|
-
const fetched = await store.get(type, idsToFetch);
|
|
52
|
-
for (const id of idsToFetch) {
|
|
53
|
-
const item = fetched[id];
|
|
54
|
-
if (item) {
|
|
55
|
-
data[id] = item;
|
|
56
|
-
cache.set(getUniqueId(type, id), item);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return data;
|
|
61
|
-
});
|
|
62
|
-
},
|
|
63
|
-
async set(data) {
|
|
64
|
-
return cacheMutex.runExclusive(async () => {
|
|
65
|
-
let keys = 0;
|
|
66
|
-
for (const type in data) {
|
|
67
|
-
for (const id in data[type]) {
|
|
68
|
-
cache.set(getUniqueId(type, id), data[type][id]);
|
|
69
|
-
keys += 1;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
logger?.trace({
|
|
73
|
-
keys
|
|
74
|
-
}, 'updated cache');
|
|
75
|
-
await store.set(data);
|
|
76
|
-
});
|
|
77
|
-
},
|
|
78
|
-
async clear() {
|
|
79
|
-
cache.flushAll();
|
|
80
|
-
await store.clear?.();
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
// Module-level specialized mutexes for pre-key operations
|
|
85
|
-
const preKeyMutex = new _asyncMutex.Mutex();
|
|
86
|
-
const signedPreKeyMutex = new _asyncMutex.Mutex();
|
|
87
|
-
/**
|
|
88
|
-
* Get the appropriate mutex for the key type
|
|
89
|
-
*/
|
|
90
|
-
const getPreKeyMutex = keyType => {
|
|
91
|
-
return keyType === 'signed-pre-key' ? signedPreKeyMutex : preKeyMutex;
|
|
92
|
-
};
|
|
93
|
-
/**
|
|
94
|
-
* Handles pre-key operations with mutex protection
|
|
95
|
-
*/
|
|
96
|
-
async function handlePreKeyOperations(data, keyType, transactionCache, mutations, logger, isInTransaction, state) {
|
|
97
|
-
const mutex = getPreKeyMutex(keyType);
|
|
98
|
-
await mutex.runExclusive(async () => {
|
|
99
|
-
const keyData = data[keyType];
|
|
100
|
-
if (!keyData) return;
|
|
101
|
-
// Ensure structures exist
|
|
102
|
-
transactionCache[keyType] = transactionCache[keyType] || {};
|
|
103
|
-
mutations[keyType] = mutations[keyType] || {};
|
|
104
|
-
// Separate deletions from updates for batch processing
|
|
105
|
-
const deletionKeys = [];
|
|
106
|
-
const updateKeys = [];
|
|
107
|
-
for (const keyId in keyData) {
|
|
108
|
-
if (keyData[keyId] === null) {
|
|
109
|
-
deletionKeys.push(keyId);
|
|
110
|
-
} else {
|
|
111
|
-
updateKeys.push(keyId);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
// Process updates first (no validation needed)
|
|
115
|
-
for (const keyId of updateKeys) {
|
|
116
|
-
if (transactionCache[keyType]) {
|
|
117
|
-
transactionCache[keyType][keyId] = keyData[keyId];
|
|
118
|
-
}
|
|
119
|
-
if (mutations[keyType]) {
|
|
120
|
-
mutations[keyType][keyId] = keyData[keyId];
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
// Process deletions with validation
|
|
124
|
-
if (deletionKeys.length === 0) return;
|
|
125
|
-
if (isInTransaction) {
|
|
126
|
-
// In transaction, only allow deletion if key exists in cache
|
|
127
|
-
for (const keyId of deletionKeys) {
|
|
128
|
-
if (transactionCache[keyType]) {
|
|
129
|
-
transactionCache[keyType][keyId] = null;
|
|
130
|
-
if (mutations[keyType]) {
|
|
131
|
-
// Mark for deletion in mutations
|
|
132
|
-
mutations[keyType][keyId] = null;
|
|
133
|
-
}
|
|
134
|
-
} else {
|
|
135
|
-
logger.warn(`Skipping deletion of non-existent ${keyType} in transaction: ${keyId}`);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
// Outside transaction, batch validate all deletions
|
|
141
|
-
if (!state) return;
|
|
142
|
-
const existingKeys = await state.get(keyType, deletionKeys);
|
|
143
|
-
for (const keyId of deletionKeys) {
|
|
144
|
-
if (existingKeys[keyId]) {
|
|
145
|
-
if (transactionCache[keyType]) transactionCache[keyType][keyId] = null;
|
|
146
|
-
if (mutations[keyType]) mutations[keyType][keyId] = null;
|
|
147
|
-
} else {
|
|
148
|
-
logger.warn(`Skipping deletion of non-existent ${keyType}: ${keyId}`);
|
|
149
|
-
}
|
|
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}`;
|
|
150
28
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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?.();
|
|
176
74
|
}
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Executes a function with mutexes acquired for given key types
|
|
183
|
-
* Uses async-mutex's runExclusive with efficient batching
|
|
184
|
-
*/
|
|
185
|
-
async function withMutexes(keyTypes, getKeyTypeMutex, fn) {
|
|
186
|
-
if (keyTypes.length === 0) {
|
|
187
|
-
return fn();
|
|
188
|
-
}
|
|
189
|
-
if (keyTypes.length === 1) {
|
|
190
|
-
return getKeyTypeMutex(keyTypes[0]).runExclusive(fn);
|
|
191
|
-
}
|
|
192
|
-
// For multiple mutexes, sort by key type to prevent deadlocks
|
|
193
|
-
// Then acquire all mutexes in order using Promise.all for better efficiency
|
|
194
|
-
const sortedKeyTypes = [...keyTypes].sort();
|
|
195
|
-
const mutexes = sortedKeyTypes.map(getKeyTypeMutex);
|
|
196
|
-
// Acquire all mutexes in order to prevent deadlocks
|
|
197
|
-
const releases = [];
|
|
198
|
-
try {
|
|
199
|
-
for (const mutex of mutexes) {
|
|
200
|
-
releases.push(await mutex.acquire());
|
|
201
|
-
}
|
|
202
|
-
return await fn();
|
|
203
|
-
} finally {
|
|
204
|
-
// Release in reverse order
|
|
205
|
-
while (releases.length > 0) {
|
|
206
|
-
const release = releases.pop();
|
|
207
|
-
if (release) release();
|
|
208
|
-
}
|
|
209
|
-
}
|
|
75
|
+
};
|
|
210
76
|
}
|
|
211
77
|
/**
|
|
212
|
-
* Adds DB
|
|
213
|
-
*
|
|
78
|
+
* Adds DB-like transaction capability to the SignalKeyStore
|
|
79
|
+
* Uses AsyncLocalStorage for automatic context management
|
|
214
80
|
* @param state the key store to apply this capability to
|
|
215
81
|
* @param logger logger to log events
|
|
216
82
|
* @returns SignalKeyStore with transaction capability
|
|
217
83
|
*/
|
|
218
|
-
const addTransactionCapability = (state, logger, {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
});
|
|
234
|
-
let transactionsInProgress = 0;
|
|
235
|
-
function getKeyTypeMutex(type) {
|
|
236
|
-
return getMutex(`keytype:${type}`);
|
|
237
|
-
}
|
|
238
|
-
function getSenderKeyMutex(senderKeyName) {
|
|
239
|
-
return getMutex(`senderkey:${senderKeyName}`);
|
|
240
|
-
}
|
|
241
|
-
function getTransactionMutex(key) {
|
|
242
|
-
return getMutex(`transaction:${key}`);
|
|
243
|
-
}
|
|
244
|
-
// Get or create a mutex for a specific key name
|
|
245
|
-
function getMutex(key) {
|
|
246
|
-
let mutex = mutexCache.get(key);
|
|
247
|
-
if (!mutex) {
|
|
248
|
-
mutex = new _asyncMutex.Mutex();
|
|
249
|
-
mutexCache.set(key, mutex);
|
|
250
|
-
logger.info({
|
|
251
|
-
key
|
|
252
|
-
}, 'created new mutex');
|
|
253
|
-
}
|
|
254
|
-
return mutex;
|
|
255
|
-
}
|
|
256
|
-
// Sender key operations with proper mutex sequencing
|
|
257
|
-
function queueSenderKeyOperation(senderKeyName, operation) {
|
|
258
|
-
return getSenderKeyMutex(senderKeyName).runExclusive(operation);
|
|
259
|
-
}
|
|
260
|
-
// Check if we are currently in a transaction
|
|
261
|
-
function isInTransaction() {
|
|
262
|
-
return transactionsInProgress > 0;
|
|
263
|
-
}
|
|
264
|
-
// Helper function to handle transaction commit with retries
|
|
265
|
-
async function commitTransaction() {
|
|
266
|
-
if (!Object.keys(mutations).length) {
|
|
267
|
-
logger.trace('no mutations in transaction');
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
logger.trace('committing transaction');
|
|
271
|
-
let tries = maxCommitRetries;
|
|
272
|
-
while (tries > 0) {
|
|
273
|
-
tries -= 1;
|
|
274
|
-
try {
|
|
275
|
-
await state.set(mutations);
|
|
276
|
-
logger.trace({
|
|
277
|
-
dbQueriesInTransaction
|
|
278
|
-
}, 'committed transaction');
|
|
279
|
-
return;
|
|
280
|
-
} catch (error) {
|
|
281
|
-
logger.warn(`failed to commit ${Object.keys(mutations).length} mutations, tries left=${tries}`);
|
|
282
|
-
if (tries > 0) {
|
|
283
|
-
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 }));
|
|
284
99
|
}
|
|
285
|
-
|
|
100
|
+
return keyQueues.get(key);
|
|
286
101
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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);
|
|
295
111
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
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);
|
|
303
118
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
logger.info({
|
|
317
|
-
idsRequiringFetch
|
|
318
|
-
}, 'processing sender keys in transaction');
|
|
319
|
-
// For sender keys, process each one with queued operations to maintain serialization
|
|
320
|
-
for (const senderKeyName of idsRequiringFetch) {
|
|
321
|
-
await queueSenderKeyOperation(senderKeyName, async () => {
|
|
322
|
-
logger.info({
|
|
323
|
-
senderKeyName
|
|
324
|
-
}, 'fetching sender key in transaction');
|
|
325
|
-
const result = await state.get(type, [senderKeyName]);
|
|
326
|
-
// Update transaction cache
|
|
327
|
-
transactionCache[type] || (transactionCache[type] = {});
|
|
328
|
-
Object.assign(transactionCache[type], result);
|
|
329
|
-
logger.info({
|
|
330
|
-
senderKeyName,
|
|
331
|
-
hasResult: !!result[senderKeyName]
|
|
332
|
-
}, 'sender key fetch complete');
|
|
333
|
-
});
|
|
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);
|
|
334
131
|
}
|
|
335
|
-
} else {
|
|
336
|
-
// Use runExclusive for cleaner mutex handling
|
|
337
|
-
await getKeyTypeMutex(type).runExclusive(async () => {
|
|
338
|
-
const result = await state.get(type, idsRequiringFetch);
|
|
339
|
-
// Update transaction cache
|
|
340
|
-
transactionCache[type] || (transactionCache[type] = {});
|
|
341
|
-
Object.assign(transactionCache[type], result);
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
132
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
Object.assign(results, result);
|
|
360
|
-
}
|
|
361
|
-
return results;
|
|
362
|
-
} else {
|
|
363
|
-
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;
|
|
364
147
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
handleNormalKeyOperations(data, key, transactionCache, mutations);
|
|
381
|
-
}
|
|
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
|
+
}
|
|
382
163
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
'
|
|
397
|
-
|
|
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;
|
|
398
189
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
};
|
|
414
|
-
delete nonSenderKeyData['sender-key'];
|
|
415
|
-
if (Object.keys(nonSenderKeyData).length > 0) {
|
|
416
|
-
await withMutexes(Object.keys(nonSenderKeyData), getKeyTypeMutex, async () => {
|
|
417
|
-
// Process pre-keys and signed-pre-keys separately with specialized mutexes
|
|
418
|
-
for (const key_ in nonSenderKeyData) {
|
|
419
|
-
const keyType = key_;
|
|
420
|
-
if (keyType === 'pre-key') {
|
|
421
|
-
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
|
+
}
|
|
422
204
|
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
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');
|
|
432
214
|
for (const key_ in data) {
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
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);
|
|
437
264
|
}
|
|
438
|
-
// Apply changes to the store
|
|
439
|
-
await state.set(data);
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
},
|
|
444
|
-
isInTransaction,
|
|
445
|
-
async transaction(work, key) {
|
|
446
|
-
const releaseTxMutex = await getTransactionMutex(key).acquire();
|
|
447
|
-
try {
|
|
448
|
-
transactionsInProgress += 1;
|
|
449
|
-
if (transactionsInProgress === 1) {
|
|
450
|
-
logger.trace('entering transaction');
|
|
451
|
-
}
|
|
452
|
-
// Release the transaction mutex now that we've updated the counter
|
|
453
|
-
// This allows other transactions to start preparing
|
|
454
|
-
releaseTxMutex();
|
|
455
|
-
try {
|
|
456
|
-
return await executeTransactionWork(work);
|
|
457
|
-
} finally {
|
|
458
|
-
cleanupTransactionState();
|
|
459
265
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
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 });
|
|
464
276
|
}
|
|
465
|
-
|
|
277
|
+
return id;
|
|
466
278
|
};
|
|
467
|
-
|
|
468
|
-
const
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
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
|
+
};
|
|
489
301
|
};
|
|
490
|
-
//# sourceMappingURL=auth-utils.js.map
|
|
491
|
-
exports.initAuthCreds = initAuthCreds;
|
|
302
|
+
//# sourceMappingURL=auth-utils.js.map
|