@neelegirl/baileys 1.5.3 → 1.5.4
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/LICENSE +21 -21
- package/README.md +195 -195
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +478 -1153
- package/WAProto/fix-imports.js +29 -0
- package/WAProto/index.d.ts +2645 -51971
- package/WAProto/index.js +48649 -154035
- package/engine-requirements.js +10 -0
- package/lib/Defaults/index.d.ts +62 -78
- package/lib/Defaults/index.d.ts.map +1 -0
- package/lib/Defaults/index.js +115 -149
- 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 +12 -0
- package/lib/Signal/Group/ciphertext-message.js.map +1 -0
- package/lib/Signal/{WASignalGroup → Group}/group-session-builder.d.ts +11 -13
- package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
- package/lib/Signal/Group/group-session-builder.js +30 -0
- 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/{WASignalGroup → Group}/group_cipher.js +41 -70
- 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 -0
- 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 +18 -0
- 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 +26 -0
- 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 +63 -0
- 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 +66 -0
- 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 +48 -0
- 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 +41 -0
- 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 +84 -0
- 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/{WASignalGroup/sender_message_key.js → Group/sender-message-key.js} +26 -39
- package/lib/Signal/Group/sender-message-key.js.map +1 -0
- package/lib/Signal/libsignal.d.ts +5 -8
- package/lib/Signal/libsignal.d.ts.map +1 -0
- package/lib/Signal/libsignal.js +342 -391
- package/lib/Signal/libsignal.js.map +1 -0
- package/lib/Signal/lid-mapping.d.ts +23 -28
- package/lib/Signal/lid-mapping.d.ts.map +1 -0
- package/lib/Signal/lid-mapping.js +171 -184
- package/lib/Signal/lid-mapping.js.map +1 -0
- package/lib/Socket/Client/index.d.ts +3 -2
- package/lib/Socket/Client/index.d.ts.map +1 -0
- package/lib/Socket/Client/index.js +3 -22
- package/lib/Socket/Client/index.js.map +1 -0
- package/lib/Socket/Client/types.d.ts +15 -15
- package/lib/Socket/Client/types.d.ts.map +1 -0
- package/lib/Socket/Client/types.js +8 -15
- package/lib/Socket/Client/types.js.map +1 -0
- package/lib/Socket/Client/websocket.d.ts +12 -12
- package/lib/Socket/Client/websocket.d.ts.map +1 -0
- package/lib/Socket/Client/websocket.js +24 -36
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/business.d.ts +178 -177
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +81 -120
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts +93 -92
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +462 -618
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +244 -223
- package/lib/Socket/communities.d.ts.map +1 -0
- package/lib/Socket/communities.js +431 -433
- package/lib/Socket/communities.js.map +1 -0
- package/lib/Socket/groups.d.ts +118 -110
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +148 -181
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +222 -182
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +12 -18
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +165 -166
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +753 -1031
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +161 -157
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +564 -1396
- package/lib/Socket/messages-send.js.map +1 -0
- package/lib/Socket/mex.d.ts +3 -2
- package/lib/Socket/mex.d.ts.map +1 -0
- package/lib/Socket/mex.js +42 -47
- package/lib/Socket/mex.js.map +1 -0
- package/lib/Socket/newsletter.d.ts +139 -137
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +181 -295
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/socket.d.ts +42 -36
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +487 -557
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Types/Auth.d.ts +87 -97
- package/lib/Types/Auth.d.ts.map +1 -0
- package/lib/Types/Auth.js +2 -3
- 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 -3
- package/lib/Types/Bussines.js.map +1 -0
- package/lib/Types/Call.d.ts +13 -13
- package/lib/Types/Call.d.ts.map +1 -0
- package/lib/Types/Call.js +2 -3
- package/lib/Types/Call.js.map +1 -0
- package/lib/Types/Chat.d.ts +77 -97
- package/lib/Types/Chat.d.ts.map +1 -0
- package/lib/Types/Chat.js +8 -9
- package/lib/Types/Chat.js.map +1 -0
- package/lib/Types/Contact.d.ts +10 -9
- package/lib/Types/Contact.d.ts.map +1 -0
- package/lib/Types/Contact.js +2 -3
- package/lib/Types/Contact.js.map +1 -0
- package/lib/Types/Events.d.ts +151 -175
- 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 +49 -48
- package/lib/Types/GroupMetadata.d.ts.map +1 -0
- package/lib/Types/GroupMetadata.js +2 -3
- package/lib/Types/GroupMetadata.js.map +1 -0
- package/lib/Types/Label.d.ts +13 -14
- package/lib/Types/Label.d.ts.map +1 -0
- package/lib/Types/Label.js +24 -30
- package/lib/Types/Label.js.map +1 -0
- package/lib/Types/LabelAssociation.d.ts +15 -20
- package/lib/Types/LabelAssociation.d.ts.map +1 -0
- package/lib/Types/LabelAssociation.js +6 -12
- package/lib/Types/LabelAssociation.js.map +1 -0
- package/lib/Types/Message.d.ts +231 -412
- package/lib/Types/Message.d.ts.map +1 -0
- package/lib/Types/Message.js +11 -19
- package/lib/Types/Message.js.map +1 -0
- package/lib/Types/Newsletter.d.ts +130 -104
- package/lib/Types/Newsletter.d.ts.map +1 -0
- package/lib/Types/Newsletter.js +31 -40
- package/lib/Types/Newsletter.js.map +1 -0
- package/lib/Types/Product.d.ts +58 -71
- package/lib/Types/Product.d.ts.map +1 -0
- package/lib/Types/Product.js +2 -3
- package/lib/Types/Product.js.map +1 -0
- package/lib/Types/Signal.d.ts +60 -82
- 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 +73 -81
- package/lib/Types/Socket.d.ts.map +1 -0
- package/lib/Types/Socket.js +3 -3
- package/lib/Types/Socket.js.map +1 -0
- package/lib/Types/State.d.ts +17 -19
- package/lib/Types/State.d.ts.map +1 -0
- package/lib/Types/State.js +13 -14
- package/lib/Types/State.js.map +1 -0
- package/lib/Types/USync.d.ts +8 -8
- 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 +47 -62
- package/lib/Types/index.d.ts.map +1 -0
- package/lib/Types/index.js +26 -50
- package/lib/Types/index.js.map +1 -0
- package/lib/Utils/auth-utils.d.ts +19 -21
- package/lib/Utils/auth-utils.d.ts.map +1 -0
- package/lib/Utils/auth-utils.js +257 -528
- package/lib/Utils/auth-utils.js.map +1 -0
- package/lib/Utils/baileys-event-stream.d.ts +17 -18
- package/lib/Utils/baileys-event-stream.d.ts.map +1 -0
- package/lib/Utils/baileys-event-stream.js +56 -70
- package/lib/Utils/baileys-event-stream.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 -29
- package/lib/Utils/business.d.ts.map +1 -0
- package/lib/Utils/business.js +231 -255
- package/lib/Utils/business.js.map +1 -0
- package/lib/Utils/chat-utils.d.ts +70 -82
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +763 -809
- package/lib/Utils/chat-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts +41 -56
- package/lib/Utils/crypto.d.ts.map +1 -0
- package/lib/Utils/crypto.js +142 -189
- package/lib/Utils/crypto.js.map +1 -0
- package/lib/Utils/decode-wa-message.d.ts +48 -53
- package/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/lib/Utils/decode-wa-message.js +279 -323
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts +34 -39
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +548 -595
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts +90 -131
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +381 -630
- package/lib/Utils/generics.js.map +1 -0
- package/lib/Utils/history.d.ts +19 -23
- package/lib/Utils/history.d.ts.map +1 -0
- package/lib/Utils/history.js +84 -104
- package/lib/Utils/history.js.map +1 -0
- package/lib/Utils/index.d.ts +20 -20
- package/lib/Utils/index.d.ts.map +1 -0
- package/lib/Utils/index.js +19 -40
- package/lib/Utils/index.js.map +1 -0
- package/lib/Utils/link-preview.d.ts +21 -23
- package/lib/Utils/link-preview.d.ts.map +1 -0
- package/lib/Utils/link-preview.js +85 -120
- package/lib/Utils/link-preview.js.map +1 -0
- package/lib/Utils/logger.d.ts +12 -13
- package/lib/Utils/logger.d.ts.map +1 -0
- package/lib/Utils/logger.js +3 -7
- package/lib/Utils/logger.js.map +1 -0
- package/lib/Utils/lt-hash.d.ts +13 -14
- package/lib/Utils/lt-hash.d.ts.map +1 -0
- package/lib/Utils/lt-hash.js +48 -58
- package/lib/Utils/lt-hash.js.map +1 -0
- package/lib/Utils/make-mutex.d.ts +8 -9
- package/lib/Utils/make-mutex.d.ts.map +1 -0
- package/lib/Utils/make-mutex.js +40 -49
- package/lib/Utils/make-mutex.js.map +1 -0
- package/lib/Utils/message-retry-manager.d.ts +82 -88
- package/lib/Utils/message-retry-manager.d.ts.map +1 -0
- package/lib/Utils/message-retry-manager.js +149 -160
- package/lib/Utils/message-retry-manager.js.map +1 -0
- package/lib/Utils/messages-media.d.ts +114 -135
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +663 -869
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages.d.ts +76 -105
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +820 -1745
- package/lib/Utils/messages.js.map +1 -0
- package/lib/Utils/noise-handler.d.ts +20 -21
- package/lib/Utils/noise-handler.d.ts.map +1 -0
- package/lib/Utils/noise-handler.js +147 -165
- package/lib/Utils/noise-handler.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 +42 -49
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +413 -427
- package/lib/Utils/process-message.js.map +1 -0
- package/lib/Utils/signal.d.ts +34 -42
- package/lib/Utils/signal.d.ts.map +1 -0
- package/lib/Utils/signal.js +159 -166
- package/lib/Utils/signal.js.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -18
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +121 -238
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
- package/lib/Utils/validate-connection.d.ts +11 -13
- package/lib/Utils/validate-connection.d.ts.map +1 -0
- package/lib/Utils/validate-connection.js +195 -220
- package/lib/Utils/validate-connection.js.map +1 -0
- package/lib/WABinary/constants.d.ts +28 -30
- package/lib/WABinary/constants.d.ts.map +1 -0
- package/lib/WABinary/constants.js +1301 -1316
- package/lib/WABinary/constants.js.map +1 -0
- package/lib/WABinary/decode.d.ts +7 -9
- package/lib/WABinary/decode.d.ts.map +1 -0
- package/lib/WABinary/decode.js +238 -288
- package/lib/WABinary/decode.js.map +1 -0
- package/lib/WABinary/encode.d.ts +3 -3
- package/lib/WABinary/encode.d.ts.map +1 -0
- package/lib/WABinary/encode.js +216 -265
- package/lib/WABinary/encode.js.map +1 -0
- package/lib/WABinary/generic-utils.d.ts +15 -28
- package/lib/WABinary/generic-utils.d.ts.map +1 -0
- package/lib/WABinary/generic-utils.js +102 -142
- package/lib/WABinary/generic-utils.js.map +1 -0
- package/lib/WABinary/index.d.ts +6 -5
- package/lib/WABinary/index.d.ts.map +1 -0
- package/lib/WABinary/index.js +6 -25
- package/lib/WABinary/index.js.map +1 -0
- package/lib/WABinary/jid-utils.d.ts +48 -58
- package/lib/WABinary/jid-utils.d.ts.map +1 -0
- package/lib/WABinary/jid-utils.js +96 -104
- package/lib/WABinary/jid-utils.js.map +1 -0
- package/lib/WABinary/types.d.ts +19 -22
- package/lib/WABinary/types.d.ts.map +1 -0
- package/lib/WABinary/types.js +2 -3
- package/lib/WABinary/types.js.map +1 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -16
- package/lib/WAM/BinaryInfo.d.ts.map +1 -0
- package/lib/WAM/BinaryInfo.js +10 -17
- package/lib/WAM/BinaryInfo.js.map +1 -0
- package/lib/WAM/constants.d.ts +40 -47
- package/lib/WAM/constants.d.ts.map +1 -0
- package/lib/WAM/constants.js +22853 -15371
- package/lib/WAM/constants.js.map +1 -0
- package/lib/WAM/encode.d.ts +3 -3
- package/lib/WAM/encode.d.ts.map +1 -0
- package/lib/WAM/encode.js +150 -164
- package/lib/WAM/encode.js.map +1 -0
- package/lib/WAM/index.d.ts +4 -3
- package/lib/WAM/index.d.ts.map +1 -0
- package/lib/WAM/index.js +4 -23
- package/lib/WAM/index.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +12 -19
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +19 -22
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +18 -26
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +11 -12
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -20
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +11 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +16 -24
- package/lib/WAUSync/Protocols/USyncStatusProtocol.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 +51 -0
- 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 +29 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/index.d.ts +5 -6
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/index.js +5 -26
- package/lib/WAUSync/Protocols/index.js.map +1 -0
- package/lib/WAUSync/USyncQuery.d.ts +26 -28
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
- package/lib/WAUSync/USyncQuery.js +64 -62
- package/lib/WAUSync/USyncQuery.js.map +1 -0
- package/lib/WAUSync/USyncUser.d.ts +11 -10
- package/lib/WAUSync/USyncUser.d.ts.map +1 -0
- package/lib/WAUSync/USyncUser.js +12 -19
- package/lib/WAUSync/USyncUser.js.map +1 -0
- package/lib/WAUSync/index.d.ts +4 -3
- package/lib/WAUSync/index.d.ts.map +1 -0
- package/lib/WAUSync/index.js +4 -23
- package/lib/WAUSync/index.js.map +1 -0
- package/lib/index.d.ts +12 -13
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +11 -33
- package/lib/index.js.map +1 -0
- package/package.json +99 -96
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Defaults/phonenumber-mcc.json +0 -223
- package/lib/Signal/WASignalGroup/GroupProtocol.js +0 -1909
- package/lib/Signal/WASignalGroup/ciphertext-message.d.ts +0 -9
- package/lib/Signal/WASignalGroup/ciphertext-message.js +0 -19
- package/lib/Signal/WASignalGroup/ciphertext_message.js +0 -16
- package/lib/Signal/WASignalGroup/generate-proto.sh +0 -1
- package/lib/Signal/WASignalGroup/group-session-builder.js +0 -72
- package/lib/Signal/WASignalGroup/group.proto +0 -42
- package/lib/Signal/WASignalGroup/group_cipher.d.ts +0 -19
- package/lib/Signal/WASignalGroup/group_session_builder.js +0 -46
- package/lib/Signal/WASignalGroup/index.d.ts +0 -11
- package/lib/Signal/WASignalGroup/index.js +0 -61
- package/lib/Signal/WASignalGroup/keyhelper.d.ts +0 -16
- package/lib/Signal/WASignalGroup/keyhelper.js +0 -66
- package/lib/Signal/WASignalGroup/protobufs.js +0 -3
- package/lib/Signal/WASignalGroup/queue_job.js +0 -69
- package/lib/Signal/WASignalGroup/readme.md +0 -6
- package/lib/Signal/WASignalGroup/sender-chain-key.d.ts +0 -14
- package/lib/Signal/WASignalGroup/sender-chain-key.js +0 -47
- package/lib/Signal/WASignalGroup/sender-key-distribution-message.d.ts +0 -17
- package/lib/Signal/WASignalGroup/sender-key-distribution-message.js +0 -71
- package/lib/Signal/WASignalGroup/sender-key-message.d.ts +0 -19
- package/lib/Signal/WASignalGroup/sender-key-message.js +0 -73
- package/lib/Signal/WASignalGroup/sender-key-name.d.ts +0 -19
- package/lib/Signal/WASignalGroup/sender-key-name.js +0 -59
- package/lib/Signal/WASignalGroup/sender-key-record.d.ts +0 -32
- package/lib/Signal/WASignalGroup/sender-key-record.js +0 -58
- package/lib/Signal/WASignalGroup/sender-key-state.d.ts +0 -44
- package/lib/Signal/WASignalGroup/sender-key-state.js +0 -147
- package/lib/Signal/WASignalGroup/sender-message-key.d.ts +0 -11
- package/lib/Signal/WASignalGroup/sender-message-key.js +0 -33
- package/lib/Signal/WASignalGroup/sender_chain_key.js +0 -50
- package/lib/Signal/WASignalGroup/sender_key_distribution_message.js +0 -78
- package/lib/Signal/WASignalGroup/sender_key_message.js +0 -92
- package/lib/Signal/WASignalGroup/sender_key_name.js +0 -70
- package/lib/Signal/WASignalGroup/sender_key_record.js +0 -56
- package/lib/Signal/WASignalGroup/sender_key_state.js +0 -129
- package/lib/Socket/Client/abstract-socket-client.d.ts +0 -15
- package/lib/Socket/Client/abstract-socket-client.js +0 -13
- package/lib/Socket/Client/mobile-socket-client.d.ts +0 -12
- package/lib/Socket/Client/mobile-socket-client.js +0 -65
- package/lib/Socket/usync.d.ts +0 -37
- package/lib/Socket/usync.js +0 -83
- package/lib/Store/index.d.ts +0 -4
- package/lib/Store/index.js +0 -24
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-cache-manager-store.js +0 -90
- package/lib/Store/make-in-memory-store.d.ts +0 -123
- package/lib/Store/make-in-memory-store.js +0 -429
- package/lib/Store/make-ordered-dictionary.d.ts +0 -12
- package/lib/Store/make-ordered-dictionary.js +0 -86
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Store/object-repository.js +0 -31
- package/lib/Types/Bussiness.d.ts +0 -28
- package/lib/Types/MexUpdates.d.ts +0 -9
- package/lib/Types/MexUpdates.js +0 -18
- package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
- package/lib/Utils/use-mongo-file-auth-state.js +0 -84
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.js +0 -80
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +0 -69
- package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -38
package/lib/Utils/auth-utils.js
CHANGED
|
@@ -1,528 +1,257 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
//
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (!
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if (
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
ttlAutopurge: true,
|
|
259
|
-
updateAgeOnGet: true
|
|
260
|
-
})
|
|
261
|
-
|
|
262
|
-
let transactionsInProgress = 0
|
|
263
|
-
|
|
264
|
-
function getKeyTypeMutex(type) {
|
|
265
|
-
return getMutex(`keytype:${type}`)
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
function getSenderKeyMutex(senderKeyName) {
|
|
269
|
-
return getMutex(`senderkey:${senderKeyName}`)
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
function getTransactionMutex(key) {
|
|
273
|
-
return getMutex(`transaction:${key}`)
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// Get or create a mutex for a specific key name
|
|
277
|
-
function getMutex(key) {
|
|
278
|
-
let mutex = mutexCache.get(key)
|
|
279
|
-
if (!mutex) {
|
|
280
|
-
mutex = new mutex_1.Mutex()
|
|
281
|
-
mutexCache.set(key, mutex)
|
|
282
|
-
logger.info({ key }, 'created new mutex')
|
|
283
|
-
}
|
|
284
|
-
return mutex
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
// Sender key operations with proper mutex sequencing
|
|
288
|
-
function queueSenderKeyOperation(senderKeyName, operation) {
|
|
289
|
-
return getSenderKeyMutex(senderKeyName).runExclusive(operation)
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
// Check if we are currently in a transaction
|
|
293
|
-
function isInTransaction() {
|
|
294
|
-
return transactionsInProgress > 0
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
// Helper function to handle transaction commit with retries
|
|
298
|
-
async function commitTransaction() {
|
|
299
|
-
if (!Object.keys(mutations).length) {
|
|
300
|
-
logger.trace('no mutations in transaction')
|
|
301
|
-
return
|
|
302
|
-
}
|
|
303
|
-
logger.trace('committing transaction');
|
|
304
|
-
let tries = maxCommitRetries
|
|
305
|
-
while (tries > 0) {
|
|
306
|
-
tries -= 1;
|
|
307
|
-
try {
|
|
308
|
-
await state.set(mutations)
|
|
309
|
-
logger.trace({ dbQueriesInTransaction }, 'committed transaction')
|
|
310
|
-
return
|
|
311
|
-
}
|
|
312
|
-
catch (error) {
|
|
313
|
-
logger.warn(`failed to commit ${Object.keys(mutations).length} mutations, tries left=${tries}`)
|
|
314
|
-
if (tries > 0) {
|
|
315
|
-
await generics_1.delay(delayBetweenTriesMs)
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// Helper function to clean up transaction state
|
|
322
|
-
function cleanupTransactionState() {
|
|
323
|
-
transactionsInProgress -= 1
|
|
324
|
-
if (transactionsInProgress === 0) {
|
|
325
|
-
transactionCache = {}
|
|
326
|
-
mutations = {}
|
|
327
|
-
dbQueriesInTransaction = 0
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
// Helper function to execute work within transaction
|
|
332
|
-
async function executeTransactionWork(work) {
|
|
333
|
-
const result = await work()
|
|
334
|
-
// commit if this is the outermost transaction
|
|
335
|
-
if (transactionsInProgress === 1) {
|
|
336
|
-
await commitTransaction()
|
|
337
|
-
}
|
|
338
|
-
return result
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
return {
|
|
342
|
-
get: async (type, ids) => {
|
|
343
|
-
if (isInTransaction()) {
|
|
344
|
-
const dict = transactionCache[type]
|
|
345
|
-
const idsRequiringFetch = dict ? ids.filter(item => typeof dict[item] === 'undefined') : ids
|
|
346
|
-
|
|
347
|
-
// only fetch if there are any items to fetch
|
|
348
|
-
if (idsRequiringFetch.length) {
|
|
349
|
-
dbQueriesInTransaction += 1
|
|
350
|
-
|
|
351
|
-
// Use per-sender-key queue for sender-key operations when possible
|
|
352
|
-
if (type === 'sender-key') {
|
|
353
|
-
logger.info({ idsRequiringFetch }, 'processing sender keys in transaction')
|
|
354
|
-
// For sender keys, process each one with queued operations to maintain serialization
|
|
355
|
-
for (const senderKeyName of idsRequiringFetch) {
|
|
356
|
-
await queueSenderKeyOperation(senderKeyName, async () => {
|
|
357
|
-
logger.info({ senderKeyName }, 'fetching sender key in transaction')
|
|
358
|
-
const result = await state.get(type, [senderKeyName])
|
|
359
|
-
// Update transaction cache
|
|
360
|
-
transactionCache[type] || (transactionCache[type] = {})
|
|
361
|
-
Object.assign(transactionCache[type], result)
|
|
362
|
-
logger.info({ senderKeyName, hasResult: !!result[senderKeyName] }, 'sender key fetch complete')
|
|
363
|
-
})
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
else {
|
|
367
|
-
// Use runExclusive for cleaner mutex handling
|
|
368
|
-
await getKeyTypeMutex(type).runExclusive(async () => {
|
|
369
|
-
const result = await state.get(type, idsRequiringFetch)
|
|
370
|
-
// Update transaction cache
|
|
371
|
-
transactionCache[type] || (transactionCache[type] = {})
|
|
372
|
-
Object.assign(transactionCache[type], result)
|
|
373
|
-
})
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
return ids.reduce((dict, id) => {
|
|
377
|
-
const value = transactionCache[type]?.[id]
|
|
378
|
-
if (value) {
|
|
379
|
-
dict[id] = value
|
|
380
|
-
}
|
|
381
|
-
return dict
|
|
382
|
-
}, {})
|
|
383
|
-
}
|
|
384
|
-
else {
|
|
385
|
-
// Not in transaction, fetch directly with queue protection
|
|
386
|
-
if (type === 'sender-key') {
|
|
387
|
-
// For sender keys, use individual queues to maintain per-key serialization
|
|
388
|
-
const results = {}
|
|
389
|
-
for (const senderKeyName of ids) {
|
|
390
|
-
const result = await queueSenderKeyOperation(senderKeyName, async () => await state.get(type, [senderKeyName]))
|
|
391
|
-
Object.assign(results, result)
|
|
392
|
-
}
|
|
393
|
-
return results
|
|
394
|
-
}
|
|
395
|
-
else {
|
|
396
|
-
return await getKeyTypeMutex(type).runExclusive(() => state.get(type, ids))
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
},
|
|
400
|
-
set: async (data) => {
|
|
401
|
-
if (isInTransaction()) {
|
|
402
|
-
logger.trace({ types: Object.keys(data) }, 'caching in transaction')
|
|
403
|
-
for (const key_ in data) {
|
|
404
|
-
const key = key_
|
|
405
|
-
transactionCache[key] = transactionCache[key] || {}
|
|
406
|
-
// Special handling for pre-keys and signed-pre-keys
|
|
407
|
-
if (key === 'pre-key') {
|
|
408
|
-
await handlePreKeyOperations(data, key, transactionCache, mutations, logger, true)
|
|
409
|
-
}
|
|
410
|
-
else {
|
|
411
|
-
// Normal handling for other key types
|
|
412
|
-
handleNormalKeyOperations(data, key, transactionCache, mutations)
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
else {
|
|
417
|
-
// Not in transaction, apply directly with mutex protection
|
|
418
|
-
const hasSenderKeys = 'sender-key' in data
|
|
419
|
-
const senderKeyNames = hasSenderKeys ? Object.keys(data['sender-key'] || {}) : []
|
|
420
|
-
if (hasSenderKeys) {
|
|
421
|
-
logger.info({ senderKeyNames }, 'processing sender key set operations')
|
|
422
|
-
// Handle sender key operations with per-key queues
|
|
423
|
-
for (const senderKeyName of senderKeyNames) {
|
|
424
|
-
await queueSenderKeyOperation(senderKeyName, async () => {
|
|
425
|
-
// Create data subset for this specific sender key
|
|
426
|
-
const senderKeyData = {
|
|
427
|
-
'sender-key': {
|
|
428
|
-
[senderKeyName]: data['sender-key'][senderKeyName]
|
|
429
|
-
}
|
|
430
|
-
};
|
|
431
|
-
logger.trace({ senderKeyName }, 'storing sender key')
|
|
432
|
-
// Apply changes to the store
|
|
433
|
-
await state.set(senderKeyData)
|
|
434
|
-
logger.trace({ senderKeyName }, 'sender key stored')
|
|
435
|
-
})
|
|
436
|
-
}
|
|
437
|
-
// Handle any non-sender-key data with regular mutexes
|
|
438
|
-
const nonSenderKeyData = { ...data }
|
|
439
|
-
delete nonSenderKeyData['sender-key']
|
|
440
|
-
if (Object.keys(nonSenderKeyData).length > 0) {
|
|
441
|
-
await withMutexes(Object.keys(nonSenderKeyData), getKeyTypeMutex, async () => {
|
|
442
|
-
// Process pre-keys and signed-pre-keys separately with specialized mutexes
|
|
443
|
-
for (const key_ in nonSenderKeyData) {
|
|
444
|
-
const keyType = key_
|
|
445
|
-
if (keyType === 'pre-key') {
|
|
446
|
-
await processPreKeyDeletions(nonSenderKeyData, keyType, state, logger)
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
// Apply changes to the store
|
|
450
|
-
await state.set(nonSenderKeyData)
|
|
451
|
-
})
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
else {
|
|
455
|
-
// No sender keys - use original logic
|
|
456
|
-
await withMutexes(Object.keys(data), getKeyTypeMutex, async () => {
|
|
457
|
-
// Process pre-keys and signed-pre-keys separately with specialized mutexes
|
|
458
|
-
for (const key_ in data) {
|
|
459
|
-
const keyType = key_
|
|
460
|
-
if (keyType === 'pre-key') {
|
|
461
|
-
await processPreKeyDeletions(data, keyType, state, logger)
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
// Apply changes to the store
|
|
465
|
-
await state.set(data)
|
|
466
|
-
})
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
},
|
|
470
|
-
isInTransaction,
|
|
471
|
-
async transaction(work, key) {
|
|
472
|
-
const releaseTxMutex = await getTransactionMutex(key).acquire()
|
|
473
|
-
try {
|
|
474
|
-
transactionsInProgress += 1;
|
|
475
|
-
if (transactionsInProgress === 1) {
|
|
476
|
-
logger.trace('entering transaction')
|
|
477
|
-
}
|
|
478
|
-
// Release the transaction mutex now that we've updated the counter
|
|
479
|
-
// This allows other transactions to start preparing
|
|
480
|
-
releaseTxMutex()
|
|
481
|
-
try {
|
|
482
|
-
return await executeTransactionWork(work)
|
|
483
|
-
}
|
|
484
|
-
finally {
|
|
485
|
-
cleanupTransactionState();
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
catch (error) {
|
|
489
|
-
releaseTxMutex()
|
|
490
|
-
throw error
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
const initAuthCreds = () => {
|
|
497
|
-
const identityKey = crypto_2.Curve.generateKeyPair()
|
|
498
|
-
return {
|
|
499
|
-
noiseKey: crypto_2.Curve.generateKeyPair(),
|
|
500
|
-
pairingEphemeralKeyPair: crypto_2.Curve.generateKeyPair(),
|
|
501
|
-
signedIdentityKey: identityKey,
|
|
502
|
-
signedPreKey: crypto_2.signedKeyPair(identityKey, 1),
|
|
503
|
-
registrationId: generics_1.generateRegistrationId(),
|
|
504
|
-
advSecretKey: crypto_1.randomBytes(32).toString('base64'),
|
|
505
|
-
processedHistoryMessages: [],
|
|
506
|
-
nextPreKeyId: 1,
|
|
507
|
-
firstUnuploadedPreKeyId: 1,
|
|
508
|
-
accountSyncCounter: 0,
|
|
509
|
-
accountSettings: {
|
|
510
|
-
unarchiveChats: false
|
|
511
|
-
},
|
|
512
|
-
registered: false,
|
|
513
|
-
pairingCode: undefined,
|
|
514
|
-
lastPropHash: undefined,
|
|
515
|
-
routingInfo: undefined,
|
|
516
|
-
deviceId: Buffer.from((0, uuid_1.v4)().replace(/-/g, ''), 'hex').toString('base64url'),
|
|
517
|
-
phoneId: (0, uuid_1.v4)(),
|
|
518
|
-
identityId: (0, crypto_1.randomBytes)(20),
|
|
519
|
-
backupToken: (0, crypto_1.randomBytes)(20),
|
|
520
|
-
registration: {},
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
module.exports = {
|
|
525
|
-
makeCacheableSignalKeyStore,
|
|
526
|
-
addTransactionCapability,
|
|
527
|
-
initAuthCreds
|
|
528
|
-
}
|
|
1
|
+
import NodeCache from '@cacheable/node-cache';
|
|
2
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
3
|
+
import { Mutex } from 'async-mutex';
|
|
4
|
+
import { randomBytes } from 'crypto';
|
|
5
|
+
import PQueue from 'p-queue';
|
|
6
|
+
import { DEFAULT_CACHE_TTLS } from '../Defaults/index.js';
|
|
7
|
+
import { Curve, signedKeyPair } from './crypto.js';
|
|
8
|
+
import { delay, generateRegistrationId } from './generics.js';
|
|
9
|
+
import { PreKeyManager } from './pre-key-manager.js';
|
|
10
|
+
/**
|
|
11
|
+
* Adds caching capability to a SignalKeyStore
|
|
12
|
+
* @param store the store to add caching to
|
|
13
|
+
* @param logger to log trace events
|
|
14
|
+
* @param _cache cache store to use
|
|
15
|
+
*/
|
|
16
|
+
export function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
17
|
+
const cache = _cache ||
|
|
18
|
+
new NodeCache({
|
|
19
|
+
stdTTL: DEFAULT_CACHE_TTLS.SIGNAL_STORE, // 5 minutes
|
|
20
|
+
useClones: false,
|
|
21
|
+
deleteOnExpire: true
|
|
22
|
+
});
|
|
23
|
+
// Mutex for protecting cache operations
|
|
24
|
+
const cacheMutex = new Mutex();
|
|
25
|
+
function getUniqueId(type, id) {
|
|
26
|
+
return `${type}.${id}`;
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
async get(type, ids) {
|
|
30
|
+
return cacheMutex.runExclusive(async () => {
|
|
31
|
+
const data = {};
|
|
32
|
+
const idsToFetch = [];
|
|
33
|
+
for (const id of ids) {
|
|
34
|
+
const item = (await cache.get(getUniqueId(type, id)));
|
|
35
|
+
if (typeof item !== 'undefined') {
|
|
36
|
+
data[id] = item;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
idsToFetch.push(id);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (idsToFetch.length) {
|
|
43
|
+
logger?.trace({ items: idsToFetch.length }, 'loading from store');
|
|
44
|
+
const fetched = await store.get(type, idsToFetch);
|
|
45
|
+
for (const id of idsToFetch) {
|
|
46
|
+
const item = fetched[id];
|
|
47
|
+
if (item) {
|
|
48
|
+
data[id] = item;
|
|
49
|
+
cache.set(getUniqueId(type, id), item);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return data;
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
async set(data) {
|
|
57
|
+
return cacheMutex.runExclusive(async () => {
|
|
58
|
+
let keys = 0;
|
|
59
|
+
for (const type in data) {
|
|
60
|
+
for (const id in data[type]) {
|
|
61
|
+
await cache.set(getUniqueId(type, id), data[type][id]);
|
|
62
|
+
keys += 1;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
logger?.trace({ keys }, 'updated cache');
|
|
66
|
+
await store.set(data);
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
async clear() {
|
|
70
|
+
await cache.flushAll();
|
|
71
|
+
await store.clear?.();
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Adds DB-like transaction capability to the SignalKeyStore
|
|
77
|
+
* Uses AsyncLocalStorage for automatic context management
|
|
78
|
+
* @param state the key store to apply this capability to
|
|
79
|
+
* @param logger logger to log events
|
|
80
|
+
* @returns SignalKeyStore with transaction capability
|
|
81
|
+
*/
|
|
82
|
+
export const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetweenTriesMs }) => {
|
|
83
|
+
const txStorage = new AsyncLocalStorage();
|
|
84
|
+
// Queues for concurrency control
|
|
85
|
+
const keyQueues = new Map();
|
|
86
|
+
const txMutexes = new Map();
|
|
87
|
+
// Pre-key manager for specialized operations
|
|
88
|
+
const preKeyManager = new PreKeyManager(state, logger);
|
|
89
|
+
/**
|
|
90
|
+
* Get or create a queue for a specific key type
|
|
91
|
+
*/
|
|
92
|
+
function getQueue(key) {
|
|
93
|
+
if (!keyQueues.has(key)) {
|
|
94
|
+
keyQueues.set(key, new PQueue({ concurrency: 1 }));
|
|
95
|
+
}
|
|
96
|
+
return keyQueues.get(key);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Get or create a transaction mutex
|
|
100
|
+
*/
|
|
101
|
+
function getTxMutex(key) {
|
|
102
|
+
if (!txMutexes.has(key)) {
|
|
103
|
+
txMutexes.set(key, new Mutex());
|
|
104
|
+
}
|
|
105
|
+
return txMutexes.get(key);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Check if currently in a transaction
|
|
109
|
+
*/
|
|
110
|
+
function isInTransaction() {
|
|
111
|
+
return !!txStorage.getStore();
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Commit transaction with retries
|
|
115
|
+
*/
|
|
116
|
+
async function commitWithRetry(mutations) {
|
|
117
|
+
if (Object.keys(mutations).length === 0) {
|
|
118
|
+
logger.trace('no mutations in transaction');
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
logger.trace('committing transaction');
|
|
122
|
+
for (let attempt = 0; attempt < maxCommitRetries; attempt++) {
|
|
123
|
+
try {
|
|
124
|
+
await state.set(mutations);
|
|
125
|
+
logger.trace({ mutationCount: Object.keys(mutations).length }, 'committed transaction');
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
const retriesLeft = maxCommitRetries - attempt - 1;
|
|
130
|
+
logger.warn(`failed to commit mutations, retries left=${retriesLeft}`);
|
|
131
|
+
if (retriesLeft === 0) {
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
await delay(delayBetweenTriesMs);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
get: async (type, ids) => {
|
|
140
|
+
const ctx = txStorage.getStore();
|
|
141
|
+
if (!ctx) {
|
|
142
|
+
// No transaction - direct read without exclusive lock for concurrency
|
|
143
|
+
return state.get(type, ids);
|
|
144
|
+
}
|
|
145
|
+
// In transaction - check cache first
|
|
146
|
+
const cached = ctx.cache[type] || {};
|
|
147
|
+
const missing = ids.filter(id => !(id in cached));
|
|
148
|
+
if (missing.length > 0) {
|
|
149
|
+
ctx.dbQueries++;
|
|
150
|
+
logger.trace({ type, count: missing.length }, 'fetching missing keys in transaction');
|
|
151
|
+
const fetched = await getTxMutex(type).runExclusive(() => state.get(type, missing));
|
|
152
|
+
// Update cache
|
|
153
|
+
ctx.cache[type] = ctx.cache[type] || {};
|
|
154
|
+
Object.assign(ctx.cache[type], fetched);
|
|
155
|
+
}
|
|
156
|
+
// Return requested ids from cache
|
|
157
|
+
const result = {};
|
|
158
|
+
for (const id of ids) {
|
|
159
|
+
const value = ctx.cache[type]?.[id];
|
|
160
|
+
if (value !== undefined && value !== null) {
|
|
161
|
+
result[id] = value;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return result;
|
|
165
|
+
},
|
|
166
|
+
set: async (data) => {
|
|
167
|
+
const ctx = txStorage.getStore();
|
|
168
|
+
if (!ctx) {
|
|
169
|
+
// No transaction - direct write with queue protection
|
|
170
|
+
const types = Object.keys(data);
|
|
171
|
+
// Process pre-keys with validation
|
|
172
|
+
for (const type_ of types) {
|
|
173
|
+
const type = type_;
|
|
174
|
+
if (type === 'pre-key') {
|
|
175
|
+
await preKeyManager.validateDeletions(data, type);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
// Write all data in parallel
|
|
179
|
+
await Promise.all(types.map(type => getQueue(type).add(async () => {
|
|
180
|
+
const typeData = { [type]: data[type] };
|
|
181
|
+
await state.set(typeData);
|
|
182
|
+
})));
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
// In transaction - update cache and mutations
|
|
186
|
+
logger.trace({ types: Object.keys(data) }, 'caching in transaction');
|
|
187
|
+
for (const key_ in data) {
|
|
188
|
+
const key = key_;
|
|
189
|
+
// Ensure structures exist
|
|
190
|
+
ctx.cache[key] = ctx.cache[key] || {};
|
|
191
|
+
ctx.mutations[key] = ctx.mutations[key] || {};
|
|
192
|
+
// Special handling for pre-keys
|
|
193
|
+
if (key === 'pre-key') {
|
|
194
|
+
await preKeyManager.processOperations(data, key, ctx.cache, ctx.mutations, true);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
// Normal key types
|
|
198
|
+
Object.assign(ctx.cache[key], data[key]);
|
|
199
|
+
Object.assign(ctx.mutations[key], data[key]);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
isInTransaction,
|
|
204
|
+
transaction: async (work, key) => {
|
|
205
|
+
const existing = txStorage.getStore();
|
|
206
|
+
// Nested transaction - reuse existing context
|
|
207
|
+
if (existing) {
|
|
208
|
+
logger.trace('reusing existing transaction context');
|
|
209
|
+
return work();
|
|
210
|
+
}
|
|
211
|
+
// New transaction - acquire mutex and create context
|
|
212
|
+
return getTxMutex(key).runExclusive(async () => {
|
|
213
|
+
const ctx = {
|
|
214
|
+
cache: {},
|
|
215
|
+
mutations: {},
|
|
216
|
+
dbQueries: 0
|
|
217
|
+
};
|
|
218
|
+
logger.trace('entering transaction');
|
|
219
|
+
try {
|
|
220
|
+
const result = await txStorage.run(ctx, work);
|
|
221
|
+
// Commit mutations
|
|
222
|
+
await commitWithRetry(ctx.mutations);
|
|
223
|
+
logger.trace({ dbQueries: ctx.dbQueries }, 'transaction completed');
|
|
224
|
+
return result;
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
logger.error({ error }, 'transaction failed, rolling back');
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
};
|
|
234
|
+
export const initAuthCreds = () => {
|
|
235
|
+
const identityKey = Curve.generateKeyPair();
|
|
236
|
+
return {
|
|
237
|
+
noiseKey: Curve.generateKeyPair(),
|
|
238
|
+
pairingEphemeralKeyPair: Curve.generateKeyPair(),
|
|
239
|
+
signedIdentityKey: identityKey,
|
|
240
|
+
signedPreKey: signedKeyPair(identityKey, 1),
|
|
241
|
+
registrationId: generateRegistrationId(),
|
|
242
|
+
advSecretKey: randomBytes(32).toString('base64'),
|
|
243
|
+
processedHistoryMessages: [],
|
|
244
|
+
nextPreKeyId: 1,
|
|
245
|
+
firstUnuploadedPreKeyId: 1,
|
|
246
|
+
accountSyncCounter: 0,
|
|
247
|
+
accountSettings: {
|
|
248
|
+
unarchiveChats: false
|
|
249
|
+
},
|
|
250
|
+
registered: false,
|
|
251
|
+
pairingCode: undefined,
|
|
252
|
+
lastPropHash: undefined,
|
|
253
|
+
routingInfo: undefined,
|
|
254
|
+
additionalData: undefined
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
//# sourceMappingURL=auth-utils.js.map
|