@neelegirl/baileys 1.5.6 → 1.5.8
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/README.md +24 -27
- package/WAProto/WAProto.proto +665 -291
- package/WAProto/index.d.ts +48037 -2294
- package/WAProto/index.js +139804 -45203
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +64 -58
- package/lib/Defaults/index.js +96 -74
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/WASignalGroup/GroupProtocol.js +1909 -0
- package/lib/Signal/WASignalGroup/ciphertext_message.js +16 -0
- package/lib/Signal/WASignalGroup/generate-proto.sh +1 -0
- package/lib/Signal/WASignalGroup/group.proto +42 -0
- package/lib/Signal/WASignalGroup/group_cipher.js +120 -0
- package/lib/Signal/WASignalGroup/group_session_builder.js +46 -0
- package/lib/Signal/WASignalGroup/index.js +6 -0
- package/lib/Signal/WASignalGroup/keyhelper.js +21 -0
- package/lib/Signal/WASignalGroup/protobufs.js +3 -0
- package/lib/Signal/WASignalGroup/queue_job.js +69 -0
- package/lib/Signal/WASignalGroup/readme.md +6 -0
- package/lib/Signal/WASignalGroup/sender_chain_key.js +50 -0
- package/lib/Signal/WASignalGroup/sender_key_distribution_message.js +78 -0
- package/lib/Signal/WASignalGroup/sender_key_message.js +92 -0
- package/lib/Signal/WASignalGroup/sender_key_name.js +70 -0
- package/lib/Signal/WASignalGroup/sender_key_record.js +56 -0
- package/lib/Signal/WASignalGroup/sender_key_state.js +129 -0
- package/lib/Signal/{Group/sender-message-key.js → WASignalGroup/sender_message_key.js} +16 -3
- package/lib/Signal/libsignal.d.ts +4 -5
- package/lib/Signal/libsignal.js +112 -292
- package/lib/Socket/Client/abstract-socket-client.d.ts +15 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.d.ts +2 -3
- package/lib/Socket/Client/index.js +22 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +12 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/types.d.ts +15 -15
- package/lib/Socket/Client/types.js +15 -8
- package/lib/Socket/Client/websocket.d.ts +12 -12
- package/lib/Socket/Client/websocket.js +36 -24
- package/lib/Socket/business.d.ts +177 -178
- package/lib/Socket/business.js +71 -179
- package/lib/Socket/chats.d.ts +93 -93
- package/lib/Socket/chats.js +625 -474
- package/lib/Socket/communities.d.ts +62 -83
- package/lib/Socket/communities.js +414 -412
- package/lib/Socket/groups.d.ts +112 -118
- package/lib/Socket/groups.js +171 -146
- package/lib/Socket/index.d.ts +182 -222
- package/lib/Socket/index.js +17 -12
- package/lib/Socket/messages-recv.d.ts +169 -165
- package/lib/Socket/messages-recv.js +1721 -1185
- package/lib/Socket/messages-send.d.ts +160 -161
- package/lib/Socket/messages-send.js +992 -642
- package/lib/Socket/mex.d.ts +0 -1
- package/lib/Socket/mex.js +9 -4
- package/lib/Socket/newsletter.d.ts +139 -139
- package/lib/Socket/newsletter.js +258 -153
- package/lib/Socket/registration.d.ts +266 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +36 -42
- package/lib/Socket/socket.js +615 -533
- package/lib/Socket/usync.d.ts +37 -0
- package/lib/Socket/usync.js +83 -0
- package/lib/Store/index.d.ts +4 -0
- package/lib/Store/index.js +24 -0
- package/lib/Store/make-cache-manager-store.d.ts +14 -0
- package/lib/Store/make-cache-manager-store.js +90 -0
- package/lib/Store/make-in-memory-store.d.ts +123 -0
- package/lib/Store/make-in-memory-store.js +429 -0
- package/lib/Store/make-ordered-dictionary.d.ts +12 -0
- package/lib/Store/make-ordered-dictionary.js +86 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +31 -0
- package/lib/Types/Auth.d.ts +96 -87
- package/lib/Types/Auth.js +3 -2
- package/lib/Types/Call.d.ts +13 -13
- package/lib/Types/Call.js +3 -2
- package/lib/Types/Chat.d.ts +94 -79
- package/lib/Types/Chat.js +9 -8
- package/lib/Types/Contact.d.ts +9 -13
- package/lib/Types/Contact.js +3 -2
- package/lib/Types/Events.d.ts +179 -152
- package/lib/Types/Events.js +3 -2
- package/lib/Types/GroupMetadata.d.ts +48 -49
- package/lib/Types/GroupMetadata.js +3 -2
- package/lib/Types/Label.d.ts +14 -13
- package/lib/Types/Label.js +30 -24
- package/lib/Types/LabelAssociation.d.ts +20 -15
- package/lib/Types/LabelAssociation.js +12 -6
- package/lib/Types/Message.d.ts +404 -234
- package/lib/Types/Message.js +13 -11
- package/lib/Types/MexUpdates.d.ts +9 -0
- package/lib/Types/MexUpdates.js +18 -0
- package/lib/Types/Newsletter.d.ts +104 -130
- package/lib/Types/Newsletter.js +40 -31
- package/lib/Types/Product.d.ts +71 -58
- package/lib/Types/Product.js +3 -2
- package/lib/Types/Signal.d.ts +55 -63
- package/lib/Types/Signal.js +3 -2
- package/lib/Types/Socket.d.ts +66 -77
- package/lib/Types/Socket.js +3 -3
- package/lib/Types/State.d.ts +19 -17
- package/lib/Types/State.js +14 -13
- package/lib/Types/USync.d.ts +8 -8
- package/lib/Types/USync.js +3 -2
- package/lib/Types/index.d.ts +61 -47
- package/lib/Types/index.js +48 -26
- package/lib/Utils/auth-utils.d.ts +10 -8
- package/lib/Utils/auth-utils.js +154 -206
- package/lib/Utils/baileys-event-stream.d.ts +7 -6
- package/lib/Utils/baileys-event-stream.js +43 -29
- package/lib/Utils/business.d.ts +20 -14
- package/lib/Utils/business.js +134 -110
- package/lib/Utils/chat-utils.d.ts +69 -57
- package/lib/Utils/chat-utils.js +380 -362
- package/lib/Utils/check-npm-version.d.ts +15 -0
- package/lib/Utils/check-npm-version.js +52 -0
- package/lib/Utils/crypto.d.ts +45 -30
- package/lib/Utils/crypto.js +178 -141
- package/lib/Utils/decode-wa-message.d.ts +35 -42
- package/lib/Utils/decode-wa-message.js +150 -176
- package/lib/Utils/event-buffer.d.ts +17 -12
- package/lib/Utils/event-buffer.js +286 -269
- package/lib/Utils/generics.d.ts +99 -60
- package/lib/Utils/generics.js +481 -244
- package/lib/Utils/history.d.ts +22 -18
- package/lib/Utils/history.js +80 -54
- package/lib/Utils/index.d.ts +19 -20
- package/lib/Utils/index.js +41 -19
- package/lib/Utils/link-preview.d.ts +14 -12
- package/lib/Utils/link-preview.js +75 -40
- package/lib/Utils/logger.d.ts +11 -10
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.d.ts +13 -12
- package/lib/Utils/lt-hash.js +37 -27
- package/lib/Utils/make-mutex.d.ts +7 -6
- package/lib/Utils/make-mutex.js +29 -20
- package/lib/Utils/message-retry-manager.d.ts +6 -6
- package/lib/Utils/message-retry-manager.js +36 -8
- package/lib/Utils/messages-media.d.ts +102 -87
- package/lib/Utils/messages-media.js +570 -427
- package/lib/Utils/messages.d.ts +64 -37
- package/lib/Utils/messages.js +1270 -511
- package/lib/Utils/noise-handler.d.ts +18 -18
- package/lib/Utils/noise-handler.js +109 -101
- package/lib/Utils/process-message.d.ts +32 -25
- package/lib/Utils/process-message.js +281 -266
- package/lib/Utils/signal.d.ts +32 -24
- package/lib/Utils/signal.js +105 -98
- package/lib/Utils/use-mongo-file-auth-state.d.ts +6 -0
- package/lib/Utils/use-mongo-file-auth-state.js +84 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +10 -5
- package/lib/Utils/use-multi-file-auth-state.js +186 -69
- package/lib/Utils/use-single-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-single-file-auth-state.js +80 -0
- package/lib/Utils/validate-connection.d.ts +13 -11
- package/lib/Utils/validate-connection.js +116 -124
- package/lib/WABinary/constants.d.ts +27 -25
- package/lib/WABinary/constants.js +1292 -1277
- package/lib/WABinary/decode.d.ts +9 -7
- package/lib/WABinary/decode.js +189 -139
- package/lib/WABinary/encode.d.ts +3 -3
- package/lib/WABinary/encode.js +154 -105
- package/lib/WABinary/generic-utils.d.ts +27 -14
- package/lib/WABinary/generic-utils.js +102 -62
- package/lib/WABinary/index.d.ts +5 -6
- package/lib/WABinary/index.js +25 -6
- package/lib/WABinary/jid-utils.d.ts +46 -41
- package/lib/WABinary/jid-utils.js +80 -84
- package/lib/WABinary/types.d.ts +13 -10
- package/lib/WABinary/types.js +3 -2
- package/lib/WAM/BinaryInfo.d.ts +15 -8
- package/lib/WAM/BinaryInfo.js +14 -7
- package/lib/WAM/constants.d.ts +37 -30
- package/lib/WAM/constants.js +11983 -19465
- package/lib/WAM/encode.d.ts +3 -3
- package/lib/WAM/encode.js +110 -95
- package/lib/WAM/index.d.ts +3 -4
- package/lib/WAM/index.js +23 -4
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +28 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +69 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +19 -12
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -19
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +26 -18
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +20 -12
- package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -11
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +24 -16
- package/lib/WAUSync/Protocols/index.d.ts +6 -5
- package/lib/WAUSync/Protocols/index.js +26 -5
- package/lib/WAUSync/USyncQuery.d.ts +28 -26
- package/lib/WAUSync/USyncQuery.js +62 -64
- package/lib/WAUSync/USyncUser.d.ts +10 -11
- package/lib/WAUSync/USyncUser.js +19 -12
- package/lib/WAUSync/index.d.ts +3 -4
- package/lib/WAUSync/index.js +23 -4
- package/lib/index.d.ts +11 -10
- package/lib/index.js +33 -11
- package/package.json +43 -48
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/fix-imports.js +0 -29
- package/engine-requirements.js +0 -10
- package/lib/Defaults/index.d.ts.map +0 -1
- package/lib/Defaults/index.js.map +0 -1
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -10
- package/lib/Signal/Group/ciphertext-message.d.ts.map +0 -1
- package/lib/Signal/Group/ciphertext-message.js +0 -12
- package/lib/Signal/Group/ciphertext-message.js.map +0 -1
- package/lib/Signal/Group/group-session-builder.d.ts +0 -15
- package/lib/Signal/Group/group-session-builder.d.ts.map +0 -1
- package/lib/Signal/Group/group-session-builder.js +0 -30
- package/lib/Signal/Group/group-session-builder.js.map +0 -1
- package/lib/Signal/Group/group_cipher.d.ts +0 -17
- package/lib/Signal/Group/group_cipher.d.ts.map +0 -1
- package/lib/Signal/Group/group_cipher.js +0 -82
- package/lib/Signal/Group/group_cipher.js.map +0 -1
- package/lib/Signal/Group/index.d.ts +0 -12
- package/lib/Signal/Group/index.d.ts.map +0 -1
- package/lib/Signal/Group/index.js +0 -12
- package/lib/Signal/Group/index.js.map +0 -1
- package/lib/Signal/Group/keyhelper.d.ts +0 -11
- package/lib/Signal/Group/keyhelper.d.ts.map +0 -1
- package/lib/Signal/Group/keyhelper.js +0 -18
- package/lib/Signal/Group/keyhelper.js.map +0 -1
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
- package/lib/Signal/Group/sender-chain-key.d.ts.map +0 -1
- package/lib/Signal/Group/sender-chain-key.js +0 -26
- package/lib/Signal/Group/sender-chain-key.js.map +0 -1
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-distribution-message.js +0 -63
- package/lib/Signal/Group/sender-key-distribution-message.js.map +0 -1
- package/lib/Signal/Group/sender-key-message.d.ts +0 -19
- package/lib/Signal/Group/sender-key-message.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-message.js +0 -66
- package/lib/Signal/Group/sender-key-message.js.map +0 -1
- package/lib/Signal/Group/sender-key-name.d.ts +0 -18
- package/lib/Signal/Group/sender-key-name.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-name.js +0 -48
- package/lib/Signal/Group/sender-key-name.js.map +0 -1
- package/lib/Signal/Group/sender-key-record.d.ts +0 -31
- package/lib/Signal/Group/sender-key-record.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-record.js +0 -41
- package/lib/Signal/Group/sender-key-record.js.map +0 -1
- package/lib/Signal/Group/sender-key-state.d.ts +0 -39
- package/lib/Signal/Group/sender-key-state.d.ts.map +0 -1
- package/lib/Signal/Group/sender-key-state.js +0 -84
- package/lib/Signal/Group/sender-key-state.js.map +0 -1
- package/lib/Signal/Group/sender-message-key.d.ts +0 -12
- package/lib/Signal/Group/sender-message-key.d.ts.map +0 -1
- package/lib/Signal/Group/sender-message-key.js.map +0 -1
- package/lib/Signal/libsignal.d.ts.map +0 -1
- package/lib/Signal/libsignal.js.map +0 -1
- package/lib/Signal/lid-mapping.d.ts +0 -23
- package/lib/Signal/lid-mapping.d.ts.map +0 -1
- package/lib/Signal/lid-mapping.js +0 -171
- package/lib/Signal/lid-mapping.js.map +0 -1
- package/lib/Socket/Client/index.d.ts.map +0 -1
- package/lib/Socket/Client/index.js.map +0 -1
- package/lib/Socket/Client/types.d.ts.map +0 -1
- package/lib/Socket/Client/types.js.map +0 -1
- package/lib/Socket/Client/websocket.d.ts.map +0 -1
- package/lib/Socket/Client/websocket.js.map +0 -1
- package/lib/Socket/business.d.ts.map +0 -1
- package/lib/Socket/business.js.map +0 -1
- package/lib/Socket/chats.d.ts.map +0 -1
- package/lib/Socket/chats.js.map +0 -1
- package/lib/Socket/communities.d.ts.map +0 -1
- package/lib/Socket/communities.js.map +0 -1
- package/lib/Socket/groups.d.ts.map +0 -1
- package/lib/Socket/groups.js.map +0 -1
- package/lib/Socket/index.d.ts.map +0 -1
- package/lib/Socket/index.js.map +0 -1
- package/lib/Socket/messages-recv.d.ts.map +0 -1
- package/lib/Socket/messages-recv.js.map +0 -1
- package/lib/Socket/messages-send.d.ts.map +0 -1
- package/lib/Socket/messages-send.js.map +0 -1
- package/lib/Socket/mex.d.ts.map +0 -1
- package/lib/Socket/mex.js.map +0 -1
- package/lib/Socket/newsletter.d.ts.map +0 -1
- package/lib/Socket/newsletter.js.map +0 -1
- package/lib/Socket/socket.d.ts.map +0 -1
- package/lib/Socket/socket.js.map +0 -1
- package/lib/Types/Auth.d.ts.map +0 -1
- package/lib/Types/Auth.js.map +0 -1
- package/lib/Types/Bussines.d.ts +0 -25
- package/lib/Types/Bussines.d.ts.map +0 -1
- package/lib/Types/Bussines.js +0 -2
- package/lib/Types/Bussines.js.map +0 -1
- package/lib/Types/Call.d.ts.map +0 -1
- package/lib/Types/Call.js.map +0 -1
- package/lib/Types/Chat.d.ts.map +0 -1
- package/lib/Types/Chat.js.map +0 -1
- package/lib/Types/Contact.d.ts.map +0 -1
- package/lib/Types/Contact.js.map +0 -1
- package/lib/Types/Events.d.ts.map +0 -1
- package/lib/Types/Events.js.map +0 -1
- package/lib/Types/GroupMetadata.d.ts.map +0 -1
- package/lib/Types/GroupMetadata.js.map +0 -1
- package/lib/Types/Label.d.ts.map +0 -1
- package/lib/Types/Label.js.map +0 -1
- package/lib/Types/LabelAssociation.d.ts.map +0 -1
- package/lib/Types/LabelAssociation.js.map +0 -1
- package/lib/Types/Message.d.ts.map +0 -1
- package/lib/Types/Message.js.map +0 -1
- package/lib/Types/Newsletter.d.ts.map +0 -1
- package/lib/Types/Newsletter.js.map +0 -1
- package/lib/Types/Product.d.ts.map +0 -1
- package/lib/Types/Product.js.map +0 -1
- package/lib/Types/Signal.d.ts.map +0 -1
- package/lib/Types/Signal.js.map +0 -1
- package/lib/Types/Socket.d.ts.map +0 -1
- package/lib/Types/Socket.js.map +0 -1
- package/lib/Types/State.d.ts.map +0 -1
- package/lib/Types/State.js.map +0 -1
- package/lib/Types/USync.d.ts.map +0 -1
- package/lib/Types/USync.js.map +0 -1
- package/lib/Types/index.d.ts.map +0 -1
- package/lib/Types/index.js.map +0 -1
- package/lib/Utils/auth-utils.d.ts.map +0 -1
- package/lib/Utils/auth-utils.js.map +0 -1
- package/lib/Utils/baileys-event-stream.d.ts.map +0 -1
- package/lib/Utils/baileys-event-stream.js.map +0 -1
- package/lib/Utils/browser-utils.d.ts +0 -4
- package/lib/Utils/browser-utils.d.ts.map +0 -1
- package/lib/Utils/browser-utils.js +0 -28
- package/lib/Utils/browser-utils.js.map +0 -1
- package/lib/Utils/business.d.ts.map +0 -1
- package/lib/Utils/business.js.map +0 -1
- package/lib/Utils/chat-utils.d.ts.map +0 -1
- package/lib/Utils/chat-utils.js.map +0 -1
- package/lib/Utils/crypto.d.ts.map +0 -1
- package/lib/Utils/crypto.js.map +0 -1
- package/lib/Utils/decode-wa-message.d.ts.map +0 -1
- package/lib/Utils/decode-wa-message.js.map +0 -1
- package/lib/Utils/event-buffer.d.ts.map +0 -1
- package/lib/Utils/event-buffer.js.map +0 -1
- package/lib/Utils/generics.d.ts.map +0 -1
- package/lib/Utils/generics.js.map +0 -1
- package/lib/Utils/history.d.ts.map +0 -1
- package/lib/Utils/history.js.map +0 -1
- package/lib/Utils/index.d.ts.map +0 -1
- package/lib/Utils/index.js.map +0 -1
- package/lib/Utils/link-preview.d.ts.map +0 -1
- package/lib/Utils/link-preview.js.map +0 -1
- package/lib/Utils/logger.d.ts.map +0 -1
- package/lib/Utils/logger.js.map +0 -1
- package/lib/Utils/lt-hash.d.ts.map +0 -1
- package/lib/Utils/lt-hash.js.map +0 -1
- package/lib/Utils/make-mutex.d.ts.map +0 -1
- package/lib/Utils/make-mutex.js.map +0 -1
- package/lib/Utils/message-retry-manager.d.ts.map +0 -1
- package/lib/Utils/message-retry-manager.js.map +0 -1
- package/lib/Utils/messages-media.d.ts.map +0 -1
- package/lib/Utils/messages-media.js.map +0 -1
- package/lib/Utils/messages.d.ts.map +0 -1
- package/lib/Utils/messages.js.map +0 -1
- package/lib/Utils/noise-handler.d.ts.map +0 -1
- package/lib/Utils/noise-handler.js.map +0 -1
- package/lib/Utils/pre-key-manager.d.ts +0 -28
- package/lib/Utils/pre-key-manager.d.ts.map +0 -1
- package/lib/Utils/pre-key-manager.js +0 -106
- package/lib/Utils/pre-key-manager.js.map +0 -1
- package/lib/Utils/process-message.d.ts.map +0 -1
- package/lib/Utils/process-message.js.map +0 -1
- package/lib/Utils/signal.d.ts.map +0 -1
- package/lib/Utils/signal.js.map +0 -1
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +0 -1
- package/lib/Utils/use-multi-file-auth-state.js.map +0 -1
- package/lib/Utils/validate-connection.d.ts.map +0 -1
- package/lib/Utils/validate-connection.js.map +0 -1
- package/lib/WABinary/constants.d.ts.map +0 -1
- package/lib/WABinary/constants.js.map +0 -1
- package/lib/WABinary/decode.d.ts.map +0 -1
- package/lib/WABinary/decode.js.map +0 -1
- package/lib/WABinary/encode.d.ts.map +0 -1
- package/lib/WABinary/encode.js.map +0 -1
- package/lib/WABinary/generic-utils.d.ts.map +0 -1
- package/lib/WABinary/generic-utils.js.map +0 -1
- package/lib/WABinary/index.d.ts.map +0 -1
- package/lib/WABinary/index.js.map +0 -1
- package/lib/WABinary/jid-utils.d.ts.map +0 -1
- package/lib/WABinary/jid-utils.js.map +0 -1
- package/lib/WABinary/types.d.ts.map +0 -1
- package/lib/WABinary/types.js.map +0 -1
- package/lib/WAM/BinaryInfo.d.ts.map +0 -1
- package/lib/WAM/BinaryInfo.js.map +0 -1
- package/lib/WAM/constants.d.ts.map +0 -1
- package/lib/WAM/constants.js.map +0 -1
- package/lib/WAM/encode.d.ts.map +0 -1
- package/lib/WAM/encode.js.map +0 -1
- package/lib/WAM/index.d.ts.map +0 -1
- package/lib/WAM/index.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -26
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +0 -51
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +0 -29
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/index.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/index.js.map +0 -1
- package/lib/WAUSync/USyncQuery.d.ts.map +0 -1
- package/lib/WAUSync/USyncQuery.js.map +0 -1
- package/lib/WAUSync/USyncUser.d.ts.map +0 -1
- package/lib/WAUSync/USyncUser.js.map +0 -1
- package/lib/WAUSync/index.d.ts.map +0 -1
- package/lib/WAUSync/index.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
const SenderChainKey = require('./sender_chain_key');
|
|
2
|
+
const SenderMessageKey = require('./sender_message_key');
|
|
3
|
+
|
|
4
|
+
const protobufs = require('./protobufs');
|
|
5
|
+
|
|
6
|
+
class SenderKeyState {
|
|
7
|
+
MAX_MESSAGE_KEYS = 2000;
|
|
8
|
+
|
|
9
|
+
constructor(
|
|
10
|
+
id = null,
|
|
11
|
+
iteration = null,
|
|
12
|
+
chainKey = null,
|
|
13
|
+
signatureKeyPair = null,
|
|
14
|
+
signatureKeyPublic = null,
|
|
15
|
+
signatureKeyPrivate = null,
|
|
16
|
+
senderKeyStateStructure = null
|
|
17
|
+
) {
|
|
18
|
+
if (senderKeyStateStructure) {
|
|
19
|
+
this.senderKeyStateStructure = senderKeyStateStructure;
|
|
20
|
+
} else {
|
|
21
|
+
if (signatureKeyPair) {
|
|
22
|
+
signatureKeyPublic = signatureKeyPair.public;
|
|
23
|
+
signatureKeyPrivate = signatureKeyPair.private;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
chainKey = typeof chainKey === 'string' ? Buffer.from(chainKey, 'base64') : chainKey;
|
|
27
|
+
this.senderKeyStateStructure = protobufs.SenderKeyStateStructure.create();
|
|
28
|
+
const senderChainKeyStructure = protobufs.SenderChainKey.create();
|
|
29
|
+
senderChainKeyStructure.iteration = iteration;
|
|
30
|
+
senderChainKeyStructure.seed = chainKey;
|
|
31
|
+
this.senderKeyStateStructure.senderChainKey = senderChainKeyStructure;
|
|
32
|
+
|
|
33
|
+
const signingKeyStructure = protobufs.SenderSigningKey.create();
|
|
34
|
+
signingKeyStructure.public =
|
|
35
|
+
typeof signatureKeyPublic === 'string' ?
|
|
36
|
+
Buffer.from(signatureKeyPublic, 'base64') :
|
|
37
|
+
signatureKeyPublic;
|
|
38
|
+
if (signatureKeyPrivate) {
|
|
39
|
+
signingKeyStructure.private =
|
|
40
|
+
typeof signatureKeyPrivate === 'string' ?
|
|
41
|
+
Buffer.from(signatureKeyPrivate, 'base64') :
|
|
42
|
+
signatureKeyPrivate;
|
|
43
|
+
}
|
|
44
|
+
this.senderKeyStateStructure.senderKeyId = id;
|
|
45
|
+
this.senderChainKey = senderChainKeyStructure;
|
|
46
|
+
this.senderKeyStateStructure.senderSigningKey = signingKeyStructure;
|
|
47
|
+
}
|
|
48
|
+
this.senderKeyStateStructure.senderMessageKeys =
|
|
49
|
+
this.senderKeyStateStructure.senderMessageKeys || [];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
SenderKeyState(senderKeyStateStructure) {
|
|
53
|
+
this.senderKeyStateStructure = senderKeyStateStructure;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
getKeyId() {
|
|
57
|
+
return this.senderKeyStateStructure.senderKeyId;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
getSenderChainKey() {
|
|
61
|
+
return new SenderChainKey(
|
|
62
|
+
this.senderKeyStateStructure.senderChainKey.iteration,
|
|
63
|
+
this.senderKeyStateStructure.senderChainKey.seed
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
setSenderChainKey(chainKey) {
|
|
68
|
+
const senderChainKeyStructure = protobufs.SenderChainKey.create({
|
|
69
|
+
iteration: chainKey.getIteration(),
|
|
70
|
+
seed: chainKey.getSeed(),
|
|
71
|
+
});
|
|
72
|
+
this.senderKeyStateStructure.senderChainKey = senderChainKeyStructure;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
getSigningKeyPublic() {
|
|
76
|
+
return typeof this.senderKeyStateStructure.senderSigningKey.public === 'string' ?
|
|
77
|
+
Buffer.from(this.senderKeyStateStructure.senderSigningKey.public, 'base64') :
|
|
78
|
+
this.senderKeyStateStructure.senderSigningKey.public;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
getSigningKeyPrivate() {
|
|
82
|
+
return typeof this.senderKeyStateStructure.senderSigningKey.private === 'string' ?
|
|
83
|
+
Buffer.from(this.senderKeyStateStructure.senderSigningKey.private, 'base64') :
|
|
84
|
+
this.senderKeyStateStructure.senderSigningKey.private;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
hasSenderMessageKey(iteration) {
|
|
88
|
+
const list = this.senderKeyStateStructure.senderMessageKeys;
|
|
89
|
+
for (let o = 0; o < list.length; o++) {
|
|
90
|
+
const senderMessageKey = list[o];
|
|
91
|
+
if (senderMessageKey.iteration === iteration) return true;
|
|
92
|
+
}
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
addSenderMessageKey(senderMessageKey) {
|
|
97
|
+
const senderMessageKeyStructure = protobufs.SenderKeyStateStructure.create({
|
|
98
|
+
iteration: senderMessageKey.getIteration(),
|
|
99
|
+
seed: senderMessageKey.getSeed(),
|
|
100
|
+
});
|
|
101
|
+
this.senderKeyStateStructure.senderMessageKeys.push(senderMessageKeyStructure);
|
|
102
|
+
|
|
103
|
+
if (this.senderKeyStateStructure.senderMessageKeys.length > this.MAX_MESSAGE_KEYS) {
|
|
104
|
+
this.senderKeyStateStructure.senderMessageKeys.shift();
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
removeSenderMessageKey(iteration) {
|
|
109
|
+
let result = null;
|
|
110
|
+
|
|
111
|
+
this.senderKeyStateStructure.senderMessageKeys = this.senderKeyStateStructure.senderMessageKeys.filter(
|
|
112
|
+
senderMessageKey => {
|
|
113
|
+
if (senderMessageKey.iteration === iteration) result = senderMessageKey;
|
|
114
|
+
return senderMessageKey.iteration !== iteration;
|
|
115
|
+
}
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
if (result != null) {
|
|
119
|
+
return new SenderMessageKey(result.iteration, result.seed);
|
|
120
|
+
}
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
getStructure() {
|
|
125
|
+
return this.senderKeyStateStructure;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
module.exports = SenderKeyState;
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const { deriveSecrets } = require('@neelegirl/libsignal/src/crypto');
|
|
2
|
+
class SenderMessageKey {
|
|
3
|
+
iteration = 0;
|
|
4
|
+
|
|
5
|
+
iv = Buffer.alloc(0);
|
|
6
|
+
|
|
7
|
+
cipherKey = Buffer.alloc(0);
|
|
8
|
+
|
|
9
|
+
seed = Buffer.alloc(0);
|
|
10
|
+
|
|
3
11
|
constructor(iteration, seed) {
|
|
4
12
|
const derivative = deriveSecrets(seed, Buffer.alloc(32), Buffer.from('WhisperGroup'));
|
|
5
13
|
const keys = new Uint8Array(32);
|
|
@@ -7,20 +15,25 @@ export class SenderMessageKey {
|
|
|
7
15
|
keys.set(new Uint8Array(derivative[1].slice(0, 16)), 16);
|
|
8
16
|
this.iv = Buffer.from(derivative[0].slice(0, 16));
|
|
9
17
|
this.cipherKey = Buffer.from(keys.buffer);
|
|
18
|
+
|
|
10
19
|
this.iteration = iteration;
|
|
11
20
|
this.seed = seed;
|
|
12
21
|
}
|
|
22
|
+
|
|
13
23
|
getIteration() {
|
|
14
24
|
return this.iteration;
|
|
15
25
|
}
|
|
26
|
+
|
|
16
27
|
getIv() {
|
|
17
28
|
return this.iv;
|
|
18
29
|
}
|
|
30
|
+
|
|
19
31
|
getCipherKey() {
|
|
20
32
|
return this.cipherKey;
|
|
21
33
|
}
|
|
34
|
+
|
|
22
35
|
getSeed() {
|
|
23
36
|
return this.seed;
|
|
24
37
|
}
|
|
25
38
|
}
|
|
26
|
-
|
|
39
|
+
module.exports = SenderMessageKey;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
export declare function makeLibSignalRepository(auth: SignalAuthState
|
|
5
|
-
//# sourceMappingURL=libsignal.d.ts.map
|
|
1
|
+
import { SignalAuthState } from '../Types'
|
|
2
|
+
import { SignalRepository } from '../Types/Signal'
|
|
3
|
+
|
|
4
|
+
export declare function makeLibSignalRepository(auth: SignalAuthState): SignalRepository
|
package/lib/Signal/libsignal.js
CHANGED
|
@@ -1,342 +1,162 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k)
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k] } }
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc)
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k
|
|
12
|
+
o[k2] = m[k]
|
|
13
|
+
}))
|
|
14
|
+
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v })
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
+
if (mod && mod.__esModule) return mod
|
|
23
|
+
var result = {}
|
|
24
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k)
|
|
25
|
+
__setModuleDefault(result, mod)
|
|
26
|
+
return result
|
|
27
|
+
}
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
29
|
+
|
|
30
|
+
const libsignal = __importStar(require("@neelegirl/libsignal"))
|
|
31
|
+
const WASignalGroup_1 = require("./WASignalGroup")
|
|
32
|
+
const Utils_1 = require("../Utils")
|
|
33
|
+
const WABinary_1 = require("../WABinary")
|
|
34
|
+
|
|
35
|
+
function makeLibSignalRepository(auth) {
|
|
36
|
+
const storage = signalStorage(auth)
|
|
37
|
+
return {
|
|
20
38
|
decryptGroupMessage({ group, authorJid, msg }) {
|
|
21
|
-
const senderName = jidToSignalSenderKeyName(group, authorJid)
|
|
22
|
-
const cipher = new GroupCipher(storage, senderName)
|
|
23
|
-
|
|
24
|
-
return parsedKeys.transaction(async () => {
|
|
25
|
-
return cipher.decrypt(msg);
|
|
26
|
-
}, group);
|
|
39
|
+
const senderName = jidToSignalSenderKeyName(group, authorJid)
|
|
40
|
+
const cipher = new WASignalGroup_1.GroupCipher(storage, senderName)
|
|
41
|
+
return cipher.decrypt(msg)
|
|
27
42
|
},
|
|
28
43
|
async processSenderKeyDistributionMessage({ item, authorJid }) {
|
|
29
|
-
const builder = new GroupSessionBuilder(storage)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
const senderName = jidToSignalSenderKeyName(item.groupId, authorJid);
|
|
34
|
-
const senderMsg = new SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage);
|
|
35
|
-
const senderNameStr = senderName.toString();
|
|
36
|
-
const { [senderNameStr]: senderKey } = await auth.keys.get('sender-key', [senderNameStr]);
|
|
44
|
+
const builder = new WASignalGroup_1.GroupSessionBuilder(storage)
|
|
45
|
+
const senderName = jidToSignalSenderKeyName(item.groupId, authorJid)
|
|
46
|
+
const senderMsg = new WASignalGroup_1.SenderKeyDistributionMessage(null, null, null, null, item.axolotlSenderKeyDistributionMessage)
|
|
47
|
+
const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName])
|
|
37
48
|
if (!senderKey) {
|
|
38
|
-
await storage.storeSenderKey(senderName, new SenderKeyRecord())
|
|
49
|
+
await storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord())
|
|
39
50
|
}
|
|
40
|
-
|
|
41
|
-
const { [senderNameStr]: senderKey } = await auth.keys.get('sender-key', [senderNameStr]);
|
|
42
|
-
if (!senderKey) {
|
|
43
|
-
await storage.storeSenderKey(senderName, new SenderKeyRecord());
|
|
44
|
-
}
|
|
45
|
-
await builder.process(senderName, senderMsg);
|
|
46
|
-
}, item.groupId);
|
|
51
|
+
await builder.process(senderName, senderMsg)
|
|
47
52
|
},
|
|
48
53
|
async decryptMessage({ jid, type, ciphertext }) {
|
|
49
|
-
const addr = jidToSignalProtocolAddress(jid)
|
|
50
|
-
const session = new libsignal.SessionCipher(storage, addr)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
return result;
|
|
54
|
+
const addr = jidToSignalProtocolAddress(jid)
|
|
55
|
+
const session = new libsignal.SessionCipher(storage, addr)
|
|
56
|
+
let result
|
|
57
|
+
switch (type) {
|
|
58
|
+
case 'pkmsg':
|
|
59
|
+
result = await session.decryptPreKeyWhisperMessage(ciphertext)
|
|
60
|
+
break
|
|
61
|
+
case 'msg':
|
|
62
|
+
result = await session.decryptWhisperMessage(ciphertext)
|
|
63
|
+
break
|
|
62
64
|
}
|
|
63
|
-
|
|
64
|
-
// For regular messages, we use a transaction to ensure atomicity
|
|
65
|
-
return parsedKeys.transaction(async () => {
|
|
66
|
-
return await doDecrypt();
|
|
67
|
-
}, jid);
|
|
65
|
+
return result
|
|
68
66
|
},
|
|
69
67
|
async encryptMessage({ jid, data }) {
|
|
70
|
-
const addr = jidToSignalProtocolAddress(jid)
|
|
71
|
-
const cipher = new libsignal.SessionCipher(storage, addr)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const type = sigType === 3 ? 'pkmsg' : 'msg';
|
|
76
|
-
return { type, ciphertext: Buffer.from(body, 'binary') };
|
|
77
|
-
}, jid);
|
|
68
|
+
const addr = jidToSignalProtocolAddress(jid)
|
|
69
|
+
const cipher = new libsignal.SessionCipher(storage, addr)
|
|
70
|
+
const { type: sigType, body } = await cipher.encrypt(data)
|
|
71
|
+
const type = sigType === 3 ? 'pkmsg' : 'msg'
|
|
72
|
+
return { type, ciphertext: Buffer.from(body, 'binary') }
|
|
78
73
|
},
|
|
79
74
|
async encryptGroupMessage({ group, meId, data }) {
|
|
80
|
-
const senderName = jidToSignalSenderKeyName(group, meId)
|
|
81
|
-
const builder = new GroupSessionBuilder(storage)
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
senderKeyDistributionMessage: senderKeyDistributionMessage.serialize()
|
|
94
|
-
};
|
|
95
|
-
}, group);
|
|
75
|
+
const senderName = jidToSignalSenderKeyName(group, meId)
|
|
76
|
+
const builder = new WASignalGroup_1.GroupSessionBuilder(storage)
|
|
77
|
+
const { [senderName]: senderKey } = await auth.keys.get('sender-key', [senderName])
|
|
78
|
+
if (!senderKey) {
|
|
79
|
+
await storage.storeSenderKey(senderName, new WASignalGroup_1.SenderKeyRecord())
|
|
80
|
+
}
|
|
81
|
+
const senderKeyDistributionMessage = await builder.create(senderName)
|
|
82
|
+
const session = new WASignalGroup_1.GroupCipher(storage, senderName)
|
|
83
|
+
const ciphertext = await session.encrypt(data)
|
|
84
|
+
return {
|
|
85
|
+
ciphertext,
|
|
86
|
+
senderKeyDistributionMessage: senderKeyDistributionMessage.serialize(),
|
|
87
|
+
}
|
|
96
88
|
},
|
|
97
89
|
async injectE2ESession({ jid, session }) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return parsedKeys.transaction(async () => {
|
|
101
|
-
await cipher.initOutgoing(session);
|
|
102
|
-
}, jid);
|
|
90
|
+
const cipher = new libsignal.SessionBuilder(storage, jidToSignalProtocolAddress(jid))
|
|
91
|
+
await cipher.initOutgoing(session)
|
|
103
92
|
},
|
|
104
93
|
jidToSignalProtocolAddress(jid) {
|
|
105
|
-
return jidToSignalProtocolAddress(jid).toString()
|
|
106
|
-
},
|
|
107
|
-
// Optimized direct access to LID mapping store
|
|
108
|
-
lidMapping,
|
|
109
|
-
async validateSession(jid) {
|
|
110
|
-
try {
|
|
111
|
-
const addr = jidToSignalProtocolAddress(jid);
|
|
112
|
-
const session = await storage.loadSession(addr.toString());
|
|
113
|
-
if (!session) {
|
|
114
|
-
return { exists: false, reason: 'no session' };
|
|
115
|
-
}
|
|
116
|
-
if (!session.haveOpenSession()) {
|
|
117
|
-
return { exists: false, reason: 'no open session' };
|
|
118
|
-
}
|
|
119
|
-
return { exists: true };
|
|
120
|
-
}
|
|
121
|
-
catch (error) {
|
|
122
|
-
return { exists: false, reason: 'validation error' };
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
async deleteSession(jids) {
|
|
126
|
-
if (!jids.length)
|
|
127
|
-
return;
|
|
128
|
-
// Convert JIDs to signal addresses and prepare for bulk deletion
|
|
129
|
-
const sessionUpdates = {};
|
|
130
|
-
jids.forEach(jid => {
|
|
131
|
-
const addr = jidToSignalProtocolAddress(jid);
|
|
132
|
-
sessionUpdates[addr.toString()] = null;
|
|
133
|
-
});
|
|
134
|
-
// Single transaction for all deletions
|
|
135
|
-
return parsedKeys.transaction(async () => {
|
|
136
|
-
await auth.keys.set({ session: sessionUpdates });
|
|
137
|
-
}, `delete-${jids.length}-sessions`);
|
|
94
|
+
return jidToSignalProtocolAddress(jid).toString()
|
|
138
95
|
},
|
|
139
|
-
|
|
140
|
-
// TODO: use usync to handle this entire mess
|
|
141
|
-
if (!fromJid || (!isLidUser(toJid) && !isHostedLidUser(toJid)))
|
|
142
|
-
return { migrated: 0, skipped: 0, total: 0 };
|
|
143
|
-
// Only support PN to LID migration
|
|
144
|
-
if (!isPnUser(fromJid) && !isHostedPnUser(fromJid)) {
|
|
145
|
-
return { migrated: 0, skipped: 0, total: 1 };
|
|
146
|
-
}
|
|
147
|
-
const { user } = jidDecode(fromJid);
|
|
148
|
-
logger.debug({ fromJid }, 'bulk device migration - loading all user devices');
|
|
149
|
-
// Get user's device list from storage
|
|
150
|
-
const { [user]: userDevices } = await parsedKeys.get('device-list', [user]);
|
|
151
|
-
if (!userDevices) {
|
|
152
|
-
return { migrated: 0, skipped: 0, total: 0 };
|
|
153
|
-
}
|
|
154
|
-
const { device: fromDevice } = jidDecode(fromJid);
|
|
155
|
-
const fromDeviceStr = fromDevice?.toString() || '0';
|
|
156
|
-
if (!userDevices.includes(fromDeviceStr)) {
|
|
157
|
-
userDevices.push(fromDeviceStr);
|
|
158
|
-
}
|
|
159
|
-
// Filter out cached devices before database fetch
|
|
160
|
-
const uncachedDevices = userDevices.filter(device => {
|
|
161
|
-
const deviceKey = `${user}.${device}`;
|
|
162
|
-
return !migratedSessionCache.has(deviceKey);
|
|
163
|
-
});
|
|
164
|
-
// Bulk check session existence only for uncached devices
|
|
165
|
-
const deviceSessionKeys = uncachedDevices.map(device => `${user}.${device}`);
|
|
166
|
-
const existingSessions = await parsedKeys.get('session', deviceSessionKeys);
|
|
167
|
-
// Step 3: Convert existing sessions to JIDs (only migrate sessions that exist)
|
|
168
|
-
const deviceJids = [];
|
|
169
|
-
for (const [sessionKey, sessionData] of Object.entries(existingSessions)) {
|
|
170
|
-
if (sessionData) {
|
|
171
|
-
// Session exists in storage
|
|
172
|
-
const deviceStr = sessionKey.split('.')[1];
|
|
173
|
-
if (!deviceStr)
|
|
174
|
-
continue;
|
|
175
|
-
const deviceNum = parseInt(deviceStr);
|
|
176
|
-
let jid = deviceNum === 0 ? `${user}@s.whatsapp.net` : `${user}:${deviceNum}@s.whatsapp.net`;
|
|
177
|
-
if (deviceNum === 99) {
|
|
178
|
-
jid = `${user}:99@hosted`;
|
|
179
|
-
}
|
|
180
|
-
deviceJids.push(jid);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
logger.debug({
|
|
184
|
-
fromJid,
|
|
185
|
-
totalDevices: userDevices.length,
|
|
186
|
-
devicesWithSessions: deviceJids.length,
|
|
187
|
-
devices: deviceJids
|
|
188
|
-
}, 'bulk device migration complete - all user devices processed');
|
|
189
|
-
// Single transaction for all migrations
|
|
190
|
-
return parsedKeys.transaction(async () => {
|
|
191
|
-
const migrationOps = deviceJids.map(jid => {
|
|
192
|
-
const lidWithDevice = transferDevice(jid, toJid);
|
|
193
|
-
const fromDecoded = jidDecode(jid);
|
|
194
|
-
const toDecoded = jidDecode(lidWithDevice);
|
|
195
|
-
return {
|
|
196
|
-
fromJid: jid,
|
|
197
|
-
toJid: lidWithDevice,
|
|
198
|
-
pnUser: fromDecoded.user,
|
|
199
|
-
lidUser: toDecoded.user,
|
|
200
|
-
deviceId: fromDecoded.device || 0,
|
|
201
|
-
fromAddr: jidToSignalProtocolAddress(jid),
|
|
202
|
-
toAddr: jidToSignalProtocolAddress(lidWithDevice)
|
|
203
|
-
};
|
|
204
|
-
});
|
|
205
|
-
const totalOps = migrationOps.length;
|
|
206
|
-
let migratedCount = 0;
|
|
207
|
-
// Bulk fetch PN sessions - already exist (verified during device discovery)
|
|
208
|
-
const pnAddrStrings = Array.from(new Set(migrationOps.map(op => op.fromAddr.toString())));
|
|
209
|
-
const pnSessions = await parsedKeys.get('session', pnAddrStrings);
|
|
210
|
-
// Prepare bulk session updates (PN → LID migration + deletion)
|
|
211
|
-
const sessionUpdates = {};
|
|
212
|
-
for (const op of migrationOps) {
|
|
213
|
-
const pnAddrStr = op.fromAddr.toString();
|
|
214
|
-
const lidAddrStr = op.toAddr.toString();
|
|
215
|
-
const pnSession = pnSessions[pnAddrStr];
|
|
216
|
-
if (pnSession) {
|
|
217
|
-
// Session exists (guaranteed from device discovery)
|
|
218
|
-
const fromSession = libsignal.SessionRecord.deserialize(pnSession);
|
|
219
|
-
if (fromSession.haveOpenSession()) {
|
|
220
|
-
// Queue for bulk update: copy to LID, delete from PN
|
|
221
|
-
sessionUpdates[lidAddrStr] = fromSession.serialize();
|
|
222
|
-
sessionUpdates[pnAddrStr] = null;
|
|
223
|
-
migratedCount++;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
// Single bulk session update for all migrations
|
|
228
|
-
if (Object.keys(sessionUpdates).length > 0) {
|
|
229
|
-
await parsedKeys.set({ session: sessionUpdates });
|
|
230
|
-
logger.debug({ migratedSessions: migratedCount }, 'bulk session migration complete');
|
|
231
|
-
// Cache device-level migrations
|
|
232
|
-
for (const op of migrationOps) {
|
|
233
|
-
if (sessionUpdates[op.toAddr.toString()]) {
|
|
234
|
-
const deviceKey = `${op.pnUser}.${op.deviceId}`;
|
|
235
|
-
migratedSessionCache.set(deviceKey, true);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
const skippedCount = totalOps - migratedCount;
|
|
240
|
-
return { migrated: migratedCount, skipped: skippedCount, total: totalOps };
|
|
241
|
-
}, `migrate-${deviceJids.length}-sessions-${jidDecode(toJid)?.user}`);
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
return repository;
|
|
96
|
+
}
|
|
245
97
|
}
|
|
98
|
+
|
|
246
99
|
const jidToSignalProtocolAddress = (jid) => {
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
const signalUser = domainType !== WAJIDDomains.WHATSAPP ? `${user}_${domainType}` : user;
|
|
253
|
-
const finalDevice = device || 0;
|
|
254
|
-
if (device === 99 && decoded.server !== 'hosted' && decoded.server !== 'hosted.lid') {
|
|
255
|
-
throw new Error('Unexpected non-hosted device JID with device 99. This ID seems invalid. ID:' + jid);
|
|
256
|
-
}
|
|
257
|
-
return new libsignal.ProtocolAddress(signalUser, finalDevice);
|
|
258
|
-
};
|
|
100
|
+
const { user, device } = WABinary_1.jidDecode(jid)
|
|
101
|
+
return new libsignal.ProtocolAddress(user, device || 0)
|
|
102
|
+
}
|
|
103
|
+
|
|
259
104
|
const jidToSignalSenderKeyName = (group, user) => {
|
|
260
|
-
return new SenderKeyName(group, jidToSignalProtocolAddress(user))
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
const resolveLIDSignalAddress = async (id) => {
|
|
265
|
-
if (id.includes('.')) {
|
|
266
|
-
const [deviceId, device] = id.split('.');
|
|
267
|
-
const [user, domainType_] = deviceId.split('_');
|
|
268
|
-
const domainType = parseInt(domainType_ || '0');
|
|
269
|
-
if (domainType === WAJIDDomains.LID || domainType === WAJIDDomains.HOSTED_LID)
|
|
270
|
-
return id;
|
|
271
|
-
const pnJid = `${user}${device !== '0' ? `:${device}` : ''}@${domainType === WAJIDDomains.HOSTED ? 'hosted' : 's.whatsapp.net'}`;
|
|
272
|
-
const lidForPN = await lidMapping.getLIDForPN(pnJid);
|
|
273
|
-
if (lidForPN) {
|
|
274
|
-
const lidAddr = jidToSignalProtocolAddress(lidForPN);
|
|
275
|
-
return lidAddr.toString();
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
return id;
|
|
279
|
-
};
|
|
105
|
+
return new WASignalGroup_1.SenderKeyName(group, jidToSignalProtocolAddress(user)).toString()
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function signalStorage({ creds, keys }) {
|
|
280
109
|
return {
|
|
281
110
|
loadSession: async (id) => {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
if (sess) {
|
|
286
|
-
return libsignal.SessionRecord.deserialize(sess);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
catch (e) {
|
|
290
|
-
return null;
|
|
111
|
+
const { [id]: sess } = await keys.get('session', [id])
|
|
112
|
+
if (sess) {
|
|
113
|
+
return libsignal.SessionRecord.deserialize(sess)
|
|
291
114
|
}
|
|
292
|
-
return null;
|
|
293
115
|
},
|
|
294
116
|
storeSession: async (id, session) => {
|
|
295
|
-
|
|
296
|
-
await keys.set({ session: { [wireJid]: session.serialize() } });
|
|
117
|
+
await keys.set({ 'session': { [id]: session.serialize() } })
|
|
297
118
|
},
|
|
298
119
|
isTrustedIdentity: () => {
|
|
299
|
-
return true
|
|
120
|
+
return true
|
|
300
121
|
},
|
|
301
122
|
loadPreKey: async (id) => {
|
|
302
|
-
const keyId = id.toString()
|
|
303
|
-
const { [keyId]: key } = await keys.get('pre-key', [keyId])
|
|
123
|
+
const keyId = id.toString()
|
|
124
|
+
const { [keyId]: key } = await keys.get('pre-key', [keyId])
|
|
304
125
|
if (key) {
|
|
305
126
|
return {
|
|
306
127
|
privKey: Buffer.from(key.private),
|
|
307
128
|
pubKey: Buffer.from(key.public)
|
|
308
|
-
}
|
|
129
|
+
}
|
|
309
130
|
}
|
|
310
131
|
},
|
|
311
132
|
removePreKey: (id) => keys.set({ 'pre-key': { [id]: null } }),
|
|
312
133
|
loadSignedPreKey: () => {
|
|
313
|
-
const key = creds.signedPreKey
|
|
134
|
+
const key = creds.signedPreKey
|
|
314
135
|
return {
|
|
315
136
|
privKey: Buffer.from(key.keyPair.private),
|
|
316
137
|
pubKey: Buffer.from(key.keyPair.public)
|
|
317
|
-
}
|
|
138
|
+
}
|
|
318
139
|
},
|
|
319
|
-
loadSenderKey: async (
|
|
320
|
-
const keyId =
|
|
321
|
-
const { [keyId]: key } = await keys.get('sender-key', [keyId]);
|
|
140
|
+
loadSenderKey: async (keyId) => {
|
|
141
|
+
const { [keyId]: key } = await keys.get('sender-key', [keyId])
|
|
322
142
|
if (key) {
|
|
323
|
-
return SenderKeyRecord
|
|
143
|
+
return new WASignalGroup_1.SenderKeyRecord(key)
|
|
324
144
|
}
|
|
325
|
-
return new SenderKeyRecord();
|
|
326
145
|
},
|
|
327
|
-
storeSenderKey: async (
|
|
328
|
-
|
|
329
|
-
const serialized = JSON.stringify(key.serialize());
|
|
330
|
-
await keys.set({ 'sender-key': { [keyId]: Buffer.from(serialized, 'utf-8') } });
|
|
146
|
+
storeSenderKey: async (keyId, key) => {
|
|
147
|
+
await keys.set({ 'sender-key': { [keyId]: key.serialize() } })
|
|
331
148
|
},
|
|
332
|
-
getOurRegistrationId: () => creds.registrationId,
|
|
149
|
+
getOurRegistrationId: () => (creds.registrationId),
|
|
333
150
|
getOurIdentity: () => {
|
|
334
|
-
const { signedIdentityKey } = creds
|
|
151
|
+
const { signedIdentityKey } = creds
|
|
335
152
|
return {
|
|
336
153
|
privKey: Buffer.from(signedIdentityKey.private),
|
|
337
|
-
pubKey:
|
|
338
|
-
}
|
|
154
|
+
pubKey: Utils_1.generateSignalPubKey(signedIdentityKey.public),
|
|
155
|
+
}
|
|
339
156
|
}
|
|
340
|
-
}
|
|
157
|
+
}
|
|
341
158
|
}
|
|
342
|
-
|
|
159
|
+
|
|
160
|
+
module.exports = {
|
|
161
|
+
makeLibSignalRepository
|
|
162
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import { URL } from 'url';
|
|
3
|
+
import { SocketConfig } from '../../Types';
|
|
4
|
+
export declare abstract class AbstractSocketClient extends EventEmitter {
|
|
5
|
+
url: URL;
|
|
6
|
+
config: SocketConfig;
|
|
7
|
+
abstract get isOpen(): boolean;
|
|
8
|
+
abstract get isClosed(): boolean;
|
|
9
|
+
abstract get isClosing(): boolean;
|
|
10
|
+
abstract get isConnecting(): boolean;
|
|
11
|
+
constructor(url: URL, config: SocketConfig);
|
|
12
|
+
abstract connect(): Promise<void>;
|
|
13
|
+
abstract close(): Promise<void>;
|
|
14
|
+
abstract send(str: Uint8Array | string, cb?: (err?: Error) => void): boolean;
|
|
15
|
+
}
|