@vinzsocket/baileys 2.8.30 → 2.8.35
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/lib/Defaults/index.js +38 -31
- package/lib/Signal/Group/ciphertext-message.js +9 -2
- package/lib/Signal/Group/group-session-builder.js +15 -7
- package/lib/Signal/Group/group_cipher.js +21 -13
- package/lib/Signal/Group/index.js +79 -12
- package/lib/Signal/Group/keyhelper.js +16 -6
- package/lib/Signal/Group/queue-job.js +9 -2
- package/lib/Signal/Group/sender-chain-key.js +14 -6
- package/lib/Signal/Group/sender-key-distribution-message.js +13 -6
- package/lib/Signal/Group/sender-key-message.js +17 -9
- package/lib/Signal/Group/sender-key-name.js +9 -2
- package/lib/Signal/Group/sender-key-record.js +16 -9
- package/lib/Signal/Group/sender-key-state.js +13 -6
- package/lib/Signal/Group/sender-message-key.js +12 -4
- package/lib/Signal/libsignal.js +35 -26
- package/lib/Signal/lid-mapping.js +27 -19
- package/lib/Socket/Client/index.js +27 -3
- package/lib/Socket/Client/types.js +11 -4
- package/lib/Socket/Client/websocket.js +19 -11
- package/lib/Socket/business.js +41 -34
- package/lib/Socket/chats.js +103 -95
- package/lib/Socket/communities.js +58 -49
- package/lib/Socket/groups.js +59 -51
- package/lib/Socket/index.js +11 -6
- package/lib/Socket/messages-recv.js +153 -145
- package/lib/Socket/messages-send.js +112 -104
- package/lib/Socket/mex.js +15 -8
- package/lib/Socket/newsletter.js +30 -23
- package/lib/Socket/socket.js +112 -105
- package/lib/Store/index.js +49 -4
- package/lib/Store/make-cache-manager-store.js +19 -11
- package/lib/Store/make-in-memory-store.js +38 -29
- package/lib/Store/make-ordered-dictionary.js +9 -2
- package/lib/Store/object-repository.js +9 -2
- package/lib/Types/Auth.js +5 -2
- package/lib/Types/Bussines.js +5 -2
- package/lib/Types/Call.js +5 -2
- package/lib/Types/Chat.js +7 -1
- package/lib/Types/Contact.js +5 -2
- package/lib/Types/Events.js +3 -2
- package/lib/Types/GroupMetadata.js +5 -2
- package/lib/Types/Label.js +8 -2
- package/lib/Types/LabelAssociation.js +8 -2
- package/lib/Types/Message.js +18 -6
- package/lib/Types/Newsletter.js +10 -4
- package/lib/Types/Product.js +5 -2
- package/lib/Types/Signal.js +3 -2
- package/lib/Types/Socket.js +4 -3
- package/lib/Types/State.js +9 -3
- package/lib/Types/USync.js +3 -2
- package/lib/Types/index.js +155 -14
- package/lib/Utils/auth-utils.js +35 -25
- package/lib/Utils/baileys-event-stream.js +24 -15
- package/lib/Utils/business.js +72 -59
- package/lib/Utils/chat-utils.js +94 -77
- package/lib/Utils/crypto.js +55 -30
- package/lib/Utils/decode-wa-message.js +47 -37
- package/lib/Utils/event-buffer.js +25 -17
- package/lib/Utils/extended-messages.js +16 -9
- package/lib/Utils/generics.js +101 -62
- package/lib/Utils/history.js +33 -23
- package/lib/Utils/index.js +236 -22
- package/lib/Utils/lid-resolver.js +14 -5
- package/lib/Utils/link-preview.js +14 -7
- package/lib/Utils/logger.js +10 -4
- package/lib/Utils/lt-hash.js +10 -4
- package/lib/Utils/make-mutex.js +11 -3
- package/lib/Utils/mention.js +14 -4
- package/lib/Utils/message-retry-manager.js +13 -6
- package/lib/Utils/messages-media.js +128 -93
- package/lib/Utils/messages.js +125 -98
- package/lib/Utils/noise-handler.js +28 -21
- package/lib/Utils/process-message.js +74 -63
- package/lib/Utils/signal.js +48 -33
- package/lib/Utils/use-multi-file-auth-state.js +27 -20
- package/lib/Utils/validate-connection.js +57 -47
- package/lib/WABinary/constants.js +10 -4
- package/lib/WABinary/decode.js +20 -10
- package/lib/WABinary/encode.js +12 -4
- package/lib/WABinary/generic-utils.js +32 -15
- package/lib/WABinary/index.js +60 -6
- package/lib/WABinary/jid-utils.js +39 -20
- package/lib/WABinary/types.js +4 -2
- package/lib/WAM/BinaryInfo.js +9 -2
- package/lib/WAM/constants.js +13001 -1
- package/lib/WAM/encode.js +17 -10
- package/lib/WAM/index.js +38 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +12 -5
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +13 -6
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +11 -4
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +11 -4
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +11 -4
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +26 -19
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +9 -2
- package/lib/WAUSync/Protocols/index.js +60 -6
- package/lib/WAUSync/USyncQuery.js +24 -17
- package/lib/WAUSync/USyncUser.js +9 -2
- package/lib/WAUSync/index.js +38 -4
- package/lib/index.js +114 -12
- package/package.json +3 -1
- package/lib/Defaults/index.d.ts +0 -58
- 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.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.map +0 -1
- package/lib/Signal/Group/group_cipher.d.ts +0 -18
- package/lib/Signal/Group/group_cipher.d.ts.map +0 -1
- 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.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.map +0 -1
- package/lib/Signal/Group/queue-job.d.ts +0 -2
- 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.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.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.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.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.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.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 +0 -8
- 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 -30
- package/lib/Signal/lid-mapping.d.ts.map +0 -1
- package/lib/Signal/lid-mapping.js.map +0 -1
- package/lib/Socket/Client/index.d.ts +0 -3
- 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 +0 -16
- 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 +0 -13
- 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 +0 -188
- package/lib/Socket/business.d.ts.map +0 -1
- package/lib/Socket/business.js.map +0 -1
- package/lib/Socket/chats.d.ts +0 -98
- package/lib/Socket/chats.d.ts.map +0 -1
- package/lib/Socket/chats.js.map +0 -1
- package/lib/Socket/communities.d.ts +0 -233
- package/lib/Socket/communities.d.ts.map +0 -1
- package/lib/Socket/communities.js.map +0 -1
- package/lib/Socket/groups.d.ts +0 -137
- package/lib/Socket/groups.d.ts.map +0 -1
- package/lib/Socket/groups.js.map +0 -1
- package/lib/Socket/index.d.ts +0 -220
- package/lib/Socket/index.d.ts.map +0 -1
- package/lib/Socket/index.js.map +0 -1
- package/lib/Socket/messages-recv.d.ts +0 -173
- 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 +0 -169
- 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 +0 -3
- package/lib/Socket/mex.d.ts.map +0 -1
- package/lib/Socket/mex.js.map +0 -1
- package/lib/Socket/newsletter.d.ts +0 -147
- package/lib/Socket/newsletter.d.ts.map +0 -1
- package/lib/Socket/newsletter.js.map +0 -1
- package/lib/Socket/socket.d.ts +0 -50
- package/lib/Socket/socket.d.ts.map +0 -1
- package/lib/Socket/socket.js.map +0 -1
- package/lib/Store/index.d.ts +0 -4
- package/lib/Store/make-cache-manager-store.d.ts +0 -17
- package/lib/Store/make-in-memory-store.d.ts +0 -118
- package/lib/Store/make-ordered-dictionary.d.ts +0 -14
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -105
- 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.map +0 -1
- package/lib/Types/Call.d.ts +0 -14
- package/lib/Types/Call.d.ts.map +0 -1
- package/lib/Types/Call.js.map +0 -1
- package/lib/Types/Chat.d.ts +0 -123
- package/lib/Types/Chat.d.ts.map +0 -1
- package/lib/Types/Chat.js.map +0 -1
- package/lib/Types/Contact.d.ts +0 -24
- package/lib/Types/Contact.d.ts.map +0 -1
- package/lib/Types/Contact.js.map +0 -1
- package/lib/Types/Events.d.ts +0 -199
- package/lib/Types/Events.d.ts.map +0 -1
- package/lib/Types/Events.js.map +0 -1
- package/lib/Types/GroupMetadata.d.ts +0 -66
- package/lib/Types/GroupMetadata.d.ts.map +0 -1
- package/lib/Types/GroupMetadata.js.map +0 -1
- package/lib/Types/Label.d.ts +0 -47
- package/lib/Types/Label.d.ts.map +0 -1
- package/lib/Types/Label.js.map +0 -1
- package/lib/Types/LabelAssociation.d.ts +0 -30
- package/lib/Types/LabelAssociation.d.ts.map +0 -1
- package/lib/Types/LabelAssociation.js.map +0 -1
- package/lib/Types/Message.d.ts +0 -300
- package/lib/Types/Message.d.ts.map +0 -1
- package/lib/Types/Message.js.map +0 -1
- package/lib/Types/Newsletter.d.ts +0 -135
- package/lib/Types/Newsletter.d.ts.map +0 -1
- package/lib/Types/Newsletter.js.map +0 -1
- package/lib/Types/Product.d.ts +0 -79
- package/lib/Types/Product.d.ts.map +0 -1
- package/lib/Types/Product.js.map +0 -1
- package/lib/Types/Signal.d.ts +0 -82
- package/lib/Types/Signal.d.ts.map +0 -1
- package/lib/Types/Signal.js.map +0 -1
- package/lib/Types/Socket.d.ts +0 -130
- package/lib/Types/Socket.d.ts.map +0 -1
- package/lib/Types/Socket.js.map +0 -1
- package/lib/Types/State.d.ts +0 -39
- package/lib/Types/State.d.ts.map +0 -1
- package/lib/Types/State.js.map +0 -1
- package/lib/Types/USync.d.ts +0 -26
- package/lib/Types/USync.d.ts.map +0 -1
- package/lib/Types/USync.js.map +0 -1
- package/lib/Types/index.d.ts +0 -65
- package/lib/Types/index.d.ts.map +0 -1
- package/lib/Types/index.js.map +0 -1
- package/lib/Utils/auth-utils.d.ts +0 -19
- 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 +0 -17
- package/lib/Utils/baileys-event-stream.d.ts.map +0 -1
- package/lib/Utils/baileys-event-stream.js.map +0 -1
- package/lib/Utils/business.d.ts +0 -23
- package/lib/Utils/business.d.ts.map +0 -1
- package/lib/Utils/business.js.map +0 -1
- package/lib/Utils/chat-utils.d.ts +0 -71
- 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 +0 -41
- 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 +0 -46
- 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 +0 -34
- package/lib/Utils/event-buffer.d.ts.map +0 -1
- package/lib/Utils/event-buffer.js.map +0 -1
- package/lib/Utils/extended-messages.d.ts +0 -73
- package/lib/Utils/generics.d.ts +0 -92
- package/lib/Utils/generics.d.ts.map +0 -1
- package/lib/Utils/generics.js.map +0 -1
- package/lib/Utils/history.d.ts +0 -20
- package/lib/Utils/history.d.ts.map +0 -1
- package/lib/Utils/history.js.map +0 -1
- package/lib/Utils/index.d.ts +0 -22
- package/lib/Utils/index.d.ts.map +0 -1
- package/lib/Utils/index.js.map +0 -1
- package/lib/Utils/lid-resolver.d.ts +0 -17
- package/lib/Utils/link-preview.d.ts +0 -22
- 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 +0 -12
- package/lib/Utils/logger.d.ts.map +0 -1
- package/lib/Utils/logger.js.map +0 -1
- package/lib/Utils/lt-hash.d.ts +0 -13
- 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 +0 -8
- package/lib/Utils/make-mutex.d.ts.map +0 -1
- package/lib/Utils/make-mutex.js.map +0 -1
- package/lib/Utils/mention.d.ts +0 -27
- package/lib/Utils/message-retry-manager.d.ts +0 -82
- 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 +0 -113
- 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 +0 -76
- package/lib/Utils/messages.d.ts.map +0 -1
- package/lib/Utils/messages.js.map +0 -1
- package/lib/Utils/noise-handler.d.ts +0 -20
- package/lib/Utils/noise-handler.d.ts.map +0 -1
- package/lib/Utils/noise-handler.js.map +0 -1
- package/lib/Utils/process-message.d.ts +0 -43
- 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 +0 -34
- 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 +0 -13
- 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 +0 -11
- 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 +0 -28
- package/lib/WABinary/constants.d.ts.map +0 -1
- package/lib/WABinary/constants.js.map +0 -1
- package/lib/WABinary/decode.d.ts +0 -7
- package/lib/WABinary/decode.d.ts.map +0 -1
- package/lib/WABinary/decode.js.map +0 -1
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/encode.d.ts.map +0 -1
- package/lib/WABinary/encode.js.map +0 -1
- package/lib/WABinary/generic-utils.d.ts +0 -15
- 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 +0 -6
- package/lib/WABinary/index.d.ts.map +0 -1
- package/lib/WABinary/index.js.map +0 -1
- package/lib/WABinary/jid-utils.d.ts +0 -37
- 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 +0 -19
- package/lib/WABinary/types.d.ts.map +0 -1
- package/lib/WABinary/types.js.map +0 -1
- package/lib/WAM/BinaryInfo.d.ts +0 -9
- package/lib/WAM/BinaryInfo.d.ts.map +0 -1
- package/lib/WAM/BinaryInfo.js.map +0 -1
- package/lib/WAM/constants.d.ts +0 -40
- package/lib/WAM/constants.d.ts.map +0 -1
- package/lib/WAM/constants.js.map +0 -1
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/encode.d.ts.map +0 -1
- package/lib/WAM/encode.js.map +0 -1
- package/lib/WAM/index.d.ts +0 -4
- package/lib/WAM/index.d.ts.map +0 -1
- package/lib/WAM/index.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
- 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 +0 -23
- 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 +0 -13
- 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 +0 -13
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +0 -8
- 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.map +0 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -9
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +0 -1
- package/lib/WAUSync/Protocols/index.d.ts +0 -6
- 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 +0 -30
- package/lib/WAUSync/USyncQuery.d.ts.map +0 -1
- package/lib/WAUSync/USyncQuery.js.map +0 -1
- package/lib/WAUSync/USyncUser.d.ts +0 -13
- package/lib/WAUSync/USyncUser.d.ts.map +0 -1
- package/lib/WAUSync/USyncUser.js.map +0 -1
- package/lib/WAUSync/index.d.ts +0 -4
- package/lib/WAUSync/index.d.ts.map +0 -1
- package/lib/WAUSync/index.js.map +0 -1
- package/lib/index.d.ts +0 -13
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
package/lib/Utils/chat-utils.js
CHANGED
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.processSyncAction = exports.newLTHashState = exports.extractSyncdPatches = exports.encodeSyncdPatch = exports.downloadExternalPatch = exports.downloadExternalBlob = exports.decodeSyncdSnapshot = exports.decodeSyncdPatch = exports.decodeSyncdMutations = exports.decodePatches = exports.chatModificationToAppPatch = void 0;
|
|
7
|
+
var _boom = require("@hapi/boom");
|
|
8
|
+
var _index = require("../../WAProto/index.js");
|
|
9
|
+
var _LabelAssociation = require("../Types/LabelAssociation.js");
|
|
10
|
+
var _index2 = require("../WABinary/index.js");
|
|
11
|
+
var _crypto = require("./crypto.js");
|
|
12
|
+
var _generics = require("./generics.js");
|
|
13
|
+
var _ltHash = require("./lt-hash.js");
|
|
14
|
+
var _messagesMedia = require("./messages-media.js");
|
|
9
15
|
const mutationKeys = async keydata => {
|
|
10
|
-
const expanded = await hkdf(keydata, 160, {
|
|
16
|
+
const expanded = await (0, _crypto.hkdf)(keydata, 160, {
|
|
11
17
|
info: 'WhatsApp Mutation Keys'
|
|
12
18
|
});
|
|
13
19
|
return {
|
|
@@ -22,10 +28,10 @@ const generateMac = (operation, data, keyId, key) => {
|
|
|
22
28
|
const getKeyData = () => {
|
|
23
29
|
let r;
|
|
24
30
|
switch (operation) {
|
|
25
|
-
case proto.SyncdMutation.SyncdOperation.SET:
|
|
31
|
+
case _index.proto.SyncdMutation.SyncdOperation.SET:
|
|
26
32
|
r = 0x01;
|
|
27
33
|
break;
|
|
28
|
-
case proto.SyncdMutation.SyncdOperation.REMOVE:
|
|
34
|
+
case _index.proto.SyncdMutation.SyncdOperation.REMOVE:
|
|
29
35
|
r = 0x02;
|
|
30
36
|
break;
|
|
31
37
|
}
|
|
@@ -36,7 +42,7 @@ const generateMac = (operation, data, keyId, key) => {
|
|
|
36
42
|
const last = Buffer.alloc(8); // 8 bytes
|
|
37
43
|
last.set([keyData.length], last.length - 1);
|
|
38
44
|
const total = Buffer.concat([keyData, data, last]);
|
|
39
|
-
const hmac = hmacSign(total, key, 'sha512');
|
|
45
|
+
const hmac = (0, _crypto.hmacSign)(total, key, 'sha512');
|
|
40
46
|
return hmac.slice(0, 32);
|
|
41
47
|
};
|
|
42
48
|
const to64BitNetworkOrder = e => {
|
|
@@ -61,9 +67,9 @@ const makeLtHashGenerator = ({
|
|
|
61
67
|
}) => {
|
|
62
68
|
const indexMacBase64 = Buffer.from(indexMac).toString('base64');
|
|
63
69
|
const prevOp = indexValueMap[indexMacBase64];
|
|
64
|
-
if (operation === proto.SyncdMutation.SyncdOperation.REMOVE) {
|
|
70
|
+
if (operation === _index.proto.SyncdMutation.SyncdOperation.REMOVE) {
|
|
65
71
|
if (!prevOp) {
|
|
66
|
-
throw new Boom('tried remove, but no previous op', {
|
|
72
|
+
throw new _boom.Boom('tried remove, but no previous op', {
|
|
67
73
|
data: {
|
|
68
74
|
indexMac,
|
|
69
75
|
valueMac
|
|
@@ -85,7 +91,7 @@ const makeLtHashGenerator = ({
|
|
|
85
91
|
},
|
|
86
92
|
finish: async () => {
|
|
87
93
|
const hashArrayBuffer = new Uint8Array(hash).buffer;
|
|
88
|
-
const result = await LT_HASH_ANTI_TAMPERING.subtractThenAdd(hashArrayBuffer, addBuffs, subBuffs);
|
|
94
|
+
const result = await _ltHash.LT_HASH_ANTI_TAMPERING.subtractThenAdd(hashArrayBuffer, addBuffs, subBuffs);
|
|
89
95
|
const buffer = Buffer.from(result);
|
|
90
96
|
return {
|
|
91
97
|
hash: buffer,
|
|
@@ -96,18 +102,19 @@ const makeLtHashGenerator = ({
|
|
|
96
102
|
};
|
|
97
103
|
const generateSnapshotMac = (lthash, version, name, key) => {
|
|
98
104
|
const total = Buffer.concat([lthash, to64BitNetworkOrder(version), Buffer.from(name, 'utf-8')]);
|
|
99
|
-
return hmacSign(total, key, 'sha256');
|
|
105
|
+
return (0, _crypto.hmacSign)(total, key, 'sha256');
|
|
100
106
|
};
|
|
101
107
|
const generatePatchMac = (snapshotMac, valueMacs, version, type, key) => {
|
|
102
108
|
const total = Buffer.concat([snapshotMac, ...valueMacs, to64BitNetworkOrder(version), Buffer.from(type, 'utf-8')]);
|
|
103
|
-
return hmacSign(total, key);
|
|
109
|
+
return (0, _crypto.hmacSign)(total, key);
|
|
104
110
|
};
|
|
105
|
-
|
|
111
|
+
const newLTHashState = () => ({
|
|
106
112
|
version: 0,
|
|
107
113
|
hash: Buffer.alloc(128),
|
|
108
114
|
indexValueMap: {}
|
|
109
115
|
});
|
|
110
|
-
|
|
116
|
+
exports.newLTHashState = newLTHashState;
|
|
117
|
+
const encodeSyncdPatch = async ({
|
|
111
118
|
type,
|
|
112
119
|
index,
|
|
113
120
|
syncAction,
|
|
@@ -116,7 +123,7 @@ export const encodeSyncdPatch = async ({
|
|
|
116
123
|
}, myAppStateKeyId, state, getAppStateSyncKey) => {
|
|
117
124
|
const key = !!myAppStateKeyId ? await getAppStateSyncKey(myAppStateKeyId) : undefined;
|
|
118
125
|
if (!key) {
|
|
119
|
-
throw new Boom(`myAppStateKey ("${myAppStateKeyId}") not present`, {
|
|
126
|
+
throw new _boom.Boom(`myAppStateKey ("${myAppStateKeyId}") not present`, {
|
|
120
127
|
statusCode: 404
|
|
121
128
|
});
|
|
122
129
|
}
|
|
@@ -128,17 +135,17 @@ export const encodeSyncdPatch = async ({
|
|
|
128
135
|
}
|
|
129
136
|
};
|
|
130
137
|
const indexBuffer = Buffer.from(JSON.stringify(index));
|
|
131
|
-
const dataProto = proto.SyncActionData.create({
|
|
138
|
+
const dataProto = _index.proto.SyncActionData.create({
|
|
132
139
|
index: indexBuffer,
|
|
133
140
|
value: syncAction,
|
|
134
141
|
padding: new Uint8Array(0),
|
|
135
142
|
version: apiVersion
|
|
136
143
|
});
|
|
137
|
-
const encoded = proto.SyncActionData.encode(dataProto).finish();
|
|
144
|
+
const encoded = _index.proto.SyncActionData.encode(dataProto).finish();
|
|
138
145
|
const keyValue = await mutationKeys(key.keyData);
|
|
139
|
-
const encValue = aesEncrypt(encoded, keyValue.valueEncryptionKey);
|
|
146
|
+
const encValue = (0, _crypto.aesEncrypt)(encoded, keyValue.valueEncryptionKey);
|
|
140
147
|
const valueMac = generateMac(operation, encValue, encKeyId, keyValue.valueMacKey);
|
|
141
|
-
const indexMac = hmacSign(indexBuffer, keyValue.indexKey);
|
|
148
|
+
const indexMac = (0, _crypto.hmacSign)(indexBuffer, keyValue.indexKey);
|
|
142
149
|
// update LT hash
|
|
143
150
|
const generator = makeLtHashGenerator(state);
|
|
144
151
|
generator.mix({
|
|
@@ -179,7 +186,8 @@ export const encodeSyncdPatch = async ({
|
|
|
179
186
|
state
|
|
180
187
|
};
|
|
181
188
|
};
|
|
182
|
-
|
|
189
|
+
exports.encodeSyncdPatch = encodeSyncdPatch;
|
|
190
|
+
const decodeSyncdMutations = async (msgMutations, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
|
|
183
191
|
const ltGenerator = makeLtHashGenerator(initialState);
|
|
184
192
|
// indexKey used to HMAC sign record.index.blob
|
|
185
193
|
// valueEncryptionKey used to AES-256-CBC encrypt record.value.blob[0:-32]
|
|
@@ -187,7 +195,7 @@ export const decodeSyncdMutations = async (msgMutations, initialState, getAppSta
|
|
|
187
195
|
for (const msgMutation of msgMutations) {
|
|
188
196
|
// if it's a syncdmutation, get the operation property
|
|
189
197
|
// otherwise, if it's only a record -- it'll be a SET mutation
|
|
190
|
-
const operation = 'operation' in msgMutation ? msgMutation.operation : proto.SyncdMutation.SyncdOperation.SET;
|
|
198
|
+
const operation = 'operation' in msgMutation ? msgMutation.operation : _index.proto.SyncdMutation.SyncdOperation.SET;
|
|
191
199
|
const record = 'record' in msgMutation && !!msgMutation.record ? msgMutation.record : msgMutation;
|
|
192
200
|
const key = await getKey(record.keyId.id);
|
|
193
201
|
const content = Buffer.from(record.value.blob);
|
|
@@ -196,15 +204,15 @@ export const decodeSyncdMutations = async (msgMutations, initialState, getAppSta
|
|
|
196
204
|
if (validateMacs) {
|
|
197
205
|
const contentHmac = generateMac(operation, encContent, record.keyId.id, key.valueMacKey);
|
|
198
206
|
if (Buffer.compare(contentHmac, ogValueMac) !== 0) {
|
|
199
|
-
throw new Boom('HMAC content verification failed');
|
|
207
|
+
throw new _boom.Boom('HMAC content verification failed');
|
|
200
208
|
}
|
|
201
209
|
}
|
|
202
|
-
const result = aesDecrypt(encContent, key.valueEncryptionKey);
|
|
203
|
-
const syncAction = proto.SyncActionData.decode(result);
|
|
210
|
+
const result = (0, _crypto.aesDecrypt)(encContent, key.valueEncryptionKey);
|
|
211
|
+
const syncAction = _index.proto.SyncActionData.decode(result);
|
|
204
212
|
if (validateMacs) {
|
|
205
|
-
const hmac = hmacSign(syncAction.index, key.indexKey);
|
|
213
|
+
const hmac = (0, _crypto.hmacSign)(syncAction.index, key.indexKey);
|
|
206
214
|
if (Buffer.compare(hmac, record.index.blob) !== 0) {
|
|
207
|
-
throw new Boom('HMAC index verification failed');
|
|
215
|
+
throw new _boom.Boom('HMAC index verification failed');
|
|
208
216
|
}
|
|
209
217
|
}
|
|
210
218
|
const indexStr = Buffer.from(syncAction.index).toString();
|
|
@@ -223,7 +231,7 @@ export const decodeSyncdMutations = async (msgMutations, initialState, getAppSta
|
|
|
223
231
|
const base64Key = Buffer.from(keyId).toString('base64');
|
|
224
232
|
const keyEnc = await getAppStateSyncKey(base64Key);
|
|
225
233
|
if (!keyEnc) {
|
|
226
|
-
throw new Boom(`failed to find key "${base64Key}" to decode mutation`, {
|
|
234
|
+
throw new _boom.Boom(`failed to find key "${base64Key}" to decode mutation`, {
|
|
227
235
|
statusCode: 404,
|
|
228
236
|
data: {
|
|
229
237
|
msgMutations
|
|
@@ -233,12 +241,13 @@ export const decodeSyncdMutations = async (msgMutations, initialState, getAppSta
|
|
|
233
241
|
return mutationKeys(keyEnc.keyData);
|
|
234
242
|
}
|
|
235
243
|
};
|
|
236
|
-
|
|
244
|
+
exports.decodeSyncdMutations = decodeSyncdMutations;
|
|
245
|
+
const decodeSyncdPatch = async (msg, name, initialState, getAppStateSyncKey, onMutation, validateMacs) => {
|
|
237
246
|
if (validateMacs) {
|
|
238
247
|
const base64Key = Buffer.from(msg.keyId.id).toString('base64');
|
|
239
248
|
const mainKeyObj = await getAppStateSyncKey(base64Key);
|
|
240
249
|
if (!mainKeyObj) {
|
|
241
|
-
throw new Boom(`failed to find key "${base64Key}" to decode patch`, {
|
|
250
|
+
throw new _boom.Boom(`failed to find key "${base64Key}" to decode patch`, {
|
|
242
251
|
statusCode: 404,
|
|
243
252
|
data: {
|
|
244
253
|
msg
|
|
@@ -247,22 +256,23 @@ export const decodeSyncdPatch = async (msg, name, initialState, getAppStateSyncK
|
|
|
247
256
|
}
|
|
248
257
|
const mainKey = await mutationKeys(mainKeyObj.keyData);
|
|
249
258
|
const mutationmacs = msg.mutations.map(mutation => mutation.record.value.blob.slice(-32));
|
|
250
|
-
const patchMac = generatePatchMac(msg.snapshotMac, mutationmacs, toNumber(msg.version.version), name, mainKey.patchMacKey);
|
|
259
|
+
const patchMac = generatePatchMac(msg.snapshotMac, mutationmacs, (0, _generics.toNumber)(msg.version.version), name, mainKey.patchMacKey);
|
|
251
260
|
if (Buffer.compare(patchMac, msg.patchMac) !== 0) {
|
|
252
|
-
throw new Boom('Invalid patch mac');
|
|
261
|
+
throw new _boom.Boom('Invalid patch mac');
|
|
253
262
|
}
|
|
254
263
|
}
|
|
255
264
|
const result = await decodeSyncdMutations(msg.mutations, initialState, getAppStateSyncKey, onMutation, validateMacs);
|
|
256
265
|
return result;
|
|
257
266
|
};
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
const
|
|
267
|
+
exports.decodeSyncdPatch = decodeSyncdPatch;
|
|
268
|
+
const extractSyncdPatches = async (result, options) => {
|
|
269
|
+
const syncNode = (0, _index2.getBinaryNodeChild)(result, 'sync');
|
|
270
|
+
const collectionNodes = (0, _index2.getBinaryNodeChildren)(syncNode, 'collection');
|
|
261
271
|
const final = {};
|
|
262
272
|
await Promise.all(collectionNodes.map(async collectionNode => {
|
|
263
|
-
const patchesNode = getBinaryNodeChild(collectionNode, 'patches');
|
|
264
|
-
const patches = getBinaryNodeChildren(patchesNode || collectionNode, 'patch');
|
|
265
|
-
const snapshotNode = getBinaryNodeChild(collectionNode, 'snapshot');
|
|
273
|
+
const patchesNode = (0, _index2.getBinaryNodeChild)(collectionNode, 'patches');
|
|
274
|
+
const patches = (0, _index2.getBinaryNodeChildren)(patchesNode || collectionNode, 'patch');
|
|
275
|
+
const snapshotNode = (0, _index2.getBinaryNodeChild)(collectionNode, 'snapshot');
|
|
266
276
|
const syncds = [];
|
|
267
277
|
const name = collectionNode.attrs.name;
|
|
268
278
|
const hasMorePatches = collectionNode.attrs.has_more_patches === 'true';
|
|
@@ -271,9 +281,9 @@ export const extractSyncdPatches = async (result, options) => {
|
|
|
271
281
|
if (!Buffer.isBuffer(snapshotNode)) {
|
|
272
282
|
snapshotNode.content = Buffer.from(Object.values(snapshotNode.content));
|
|
273
283
|
}
|
|
274
|
-
const blobRef = proto.ExternalBlobReference.decode(snapshotNode.content);
|
|
284
|
+
const blobRef = _index.proto.ExternalBlobReference.decode(snapshotNode.content);
|
|
275
285
|
const data = await downloadExternalBlob(blobRef, options);
|
|
276
|
-
snapshot = proto.SyncdSnapshot.decode(data);
|
|
286
|
+
snapshot = _index.proto.SyncdSnapshot.decode(data);
|
|
277
287
|
}
|
|
278
288
|
for (let {
|
|
279
289
|
content
|
|
@@ -282,7 +292,7 @@ export const extractSyncdPatches = async (result, options) => {
|
|
|
282
292
|
if (!Buffer.isBuffer(content)) {
|
|
283
293
|
content = Buffer.from(Object.values(content));
|
|
284
294
|
}
|
|
285
|
-
const syncd = proto.SyncdPatch.decode(content);
|
|
295
|
+
const syncd = _index.proto.SyncdPatch.decode(content);
|
|
286
296
|
if (!syncd.version) {
|
|
287
297
|
syncd.version = {
|
|
288
298
|
version: +collectionNode.attrs.version + 1
|
|
@@ -299,8 +309,9 @@ export const extractSyncdPatches = async (result, options) => {
|
|
|
299
309
|
}));
|
|
300
310
|
return final;
|
|
301
311
|
};
|
|
302
|
-
|
|
303
|
-
|
|
312
|
+
exports.extractSyncdPatches = extractSyncdPatches;
|
|
313
|
+
const downloadExternalBlob = async (blob, options) => {
|
|
314
|
+
const stream = await (0, _messagesMedia.downloadContentFromMessage)(blob, 'md-app-state', {
|
|
304
315
|
options
|
|
305
316
|
});
|
|
306
317
|
const bufferArray = [];
|
|
@@ -309,14 +320,16 @@ export const downloadExternalBlob = async (blob, options) => {
|
|
|
309
320
|
}
|
|
310
321
|
return Buffer.concat(bufferArray);
|
|
311
322
|
};
|
|
312
|
-
|
|
323
|
+
exports.downloadExternalBlob = downloadExternalBlob;
|
|
324
|
+
const downloadExternalPatch = async (blob, options) => {
|
|
313
325
|
const buffer = await downloadExternalBlob(blob, options);
|
|
314
|
-
const syncData = proto.SyncdMutations.decode(buffer);
|
|
326
|
+
const syncData = _index.proto.SyncdMutations.decode(buffer);
|
|
315
327
|
return syncData;
|
|
316
328
|
};
|
|
317
|
-
|
|
329
|
+
exports.downloadExternalPatch = downloadExternalPatch;
|
|
330
|
+
const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, minimumVersionNumber, validateMacs = true) => {
|
|
318
331
|
const newState = newLTHashState();
|
|
319
|
-
newState.version = toNumber(snapshot.version.version);
|
|
332
|
+
newState.version = (0, _generics.toNumber)(snapshot.version.version);
|
|
320
333
|
const mutationMap = {};
|
|
321
334
|
const areMutationsRequired = typeof minimumVersionNumber === 'undefined' || newState.version > minimumVersionNumber;
|
|
322
335
|
const {
|
|
@@ -332,12 +345,12 @@ export const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, mi
|
|
|
332
345
|
const base64Key = Buffer.from(snapshot.keyId.id).toString('base64');
|
|
333
346
|
const keyEnc = await getAppStateSyncKey(base64Key);
|
|
334
347
|
if (!keyEnc) {
|
|
335
|
-
throw new Boom(`failed to find key "${base64Key}" to decode mutation`);
|
|
348
|
+
throw new _boom.Boom(`failed to find key "${base64Key}" to decode mutation`);
|
|
336
349
|
}
|
|
337
350
|
const result = await mutationKeys(keyEnc.keyData);
|
|
338
351
|
const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
|
|
339
352
|
if (Buffer.compare(snapshot.mac, computedSnapshotMac) !== 0) {
|
|
340
|
-
throw new Boom(`failed to verify LTHash at ${newState.version} of ${name} from snapshot`);
|
|
353
|
+
throw new _boom.Boom(`failed to verify LTHash at ${newState.version} of ${name} from snapshot`);
|
|
341
354
|
}
|
|
342
355
|
}
|
|
343
356
|
return {
|
|
@@ -345,7 +358,8 @@ export const decodeSyncdSnapshot = async (name, snapshot, getAppStateSyncKey, mi
|
|
|
345
358
|
mutationMap
|
|
346
359
|
};
|
|
347
360
|
};
|
|
348
|
-
|
|
361
|
+
exports.decodeSyncdSnapshot = decodeSyncdSnapshot;
|
|
362
|
+
const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options, minimumVersionNumber, logger, validateMacs = true) => {
|
|
349
363
|
const newState = {
|
|
350
364
|
...initial,
|
|
351
365
|
indexValueMap: {
|
|
@@ -372,7 +386,7 @@ export const decodePatches = async (name, syncds, initial, getAppStateSyncKey, o
|
|
|
372
386
|
}, 'downloaded external patch');
|
|
373
387
|
syncd.mutations?.push(...ref.mutations);
|
|
374
388
|
}
|
|
375
|
-
const patchVersion = toNumber(version.version);
|
|
389
|
+
const patchVersion = (0, _generics.toNumber)(version.version);
|
|
376
390
|
newState.version = patchVersion;
|
|
377
391
|
const shouldMutate = typeof minimumVersionNumber === 'undefined' || patchVersion > minimumVersionNumber;
|
|
378
392
|
const decodeResult = await decodeSyncdPatch(syncd, name, newState, getAppStateSyncKey, shouldMutate ? mutation => {
|
|
@@ -385,12 +399,12 @@ export const decodePatches = async (name, syncds, initial, getAppStateSyncKey, o
|
|
|
385
399
|
const base64Key = Buffer.from(keyId.id).toString('base64');
|
|
386
400
|
const keyEnc = await getAppStateSyncKey(base64Key);
|
|
387
401
|
if (!keyEnc) {
|
|
388
|
-
throw new Boom(`failed to find key "${base64Key}" to decode mutation`);
|
|
402
|
+
throw new _boom.Boom(`failed to find key "${base64Key}" to decode mutation`);
|
|
389
403
|
}
|
|
390
404
|
const result = await mutationKeys(keyEnc.keyData);
|
|
391
405
|
const computedSnapshotMac = generateSnapshotMac(newState.hash, newState.version, name, result.snapshotMacKey);
|
|
392
406
|
if (Buffer.compare(snapshotMac, computedSnapshotMac) !== 0) {
|
|
393
|
-
throw new Boom(`failed to verify LTHash at ${newState.version} of ${name}`);
|
|
407
|
+
throw new _boom.Boom(`failed to verify LTHash at ${newState.version} of ${name}`);
|
|
394
408
|
}
|
|
395
409
|
}
|
|
396
410
|
// clear memory used up by the mutations
|
|
@@ -401,8 +415,9 @@ export const decodePatches = async (name, syncds, initial, getAppStateSyncKey, o
|
|
|
401
415
|
mutationMap
|
|
402
416
|
};
|
|
403
417
|
};
|
|
404
|
-
|
|
405
|
-
|
|
418
|
+
exports.decodePatches = decodePatches;
|
|
419
|
+
const chatModificationToAppPatch = (mod, jid) => {
|
|
420
|
+
const OP = _index.proto.SyncdMutation.SyncdOperation;
|
|
406
421
|
const getMessageRange = lastMessages => {
|
|
407
422
|
let messageRange;
|
|
408
423
|
if (Array.isArray(lastMessages)) {
|
|
@@ -411,25 +426,25 @@ export const chatModificationToAppPatch = (mod, jid) => {
|
|
|
411
426
|
lastMessageTimestamp: lastMsg?.messageTimestamp,
|
|
412
427
|
messages: lastMessages?.length ? lastMessages.map(m => {
|
|
413
428
|
if (!m.key?.id || !m.key?.remoteJid) {
|
|
414
|
-
throw new Boom('Incomplete key', {
|
|
429
|
+
throw new _boom.Boom('Incomplete key', {
|
|
415
430
|
statusCode: 400,
|
|
416
431
|
data: m
|
|
417
432
|
});
|
|
418
433
|
}
|
|
419
|
-
if (isJidGroup(m.key.remoteJid) && !m.key.fromMe && !m.key.participant) {
|
|
420
|
-
throw new Boom('Expected not from me message to have participant', {
|
|
434
|
+
if ((0, _index2.isJidGroup)(m.key.remoteJid) && !m.key.fromMe && !m.key.participant) {
|
|
435
|
+
throw new _boom.Boom('Expected not from me message to have participant', {
|
|
421
436
|
statusCode: 400,
|
|
422
437
|
data: m
|
|
423
438
|
});
|
|
424
439
|
}
|
|
425
|
-
if (!m.messageTimestamp || !toNumber(m.messageTimestamp)) {
|
|
426
|
-
throw new Boom('Missing timestamp in last message list', {
|
|
440
|
+
if (!m.messageTimestamp || !(0, _generics.toNumber)(m.messageTimestamp)) {
|
|
441
|
+
throw new _boom.Boom('Missing timestamp in last message list', {
|
|
427
442
|
statusCode: 400,
|
|
428
443
|
data: m
|
|
429
444
|
});
|
|
430
445
|
}
|
|
431
446
|
if (m.key.participant) {
|
|
432
|
-
m.key.participant = jidNormalizedUser(m.key.participant);
|
|
447
|
+
m.key.participant = (0, _index2.jidNormalizedUser)(m.key.participant);
|
|
433
448
|
}
|
|
434
449
|
return m;
|
|
435
450
|
}) : undefined
|
|
@@ -616,7 +631,7 @@ export const chatModificationToAppPatch = (mod, jid) => {
|
|
|
616
631
|
labeled: true
|
|
617
632
|
}
|
|
618
633
|
},
|
|
619
|
-
index: [LabelAssociationType.Chat, mod.addChatLabel.labelId, jid],
|
|
634
|
+
index: [_LabelAssociation.LabelAssociationType.Chat, mod.addChatLabel.labelId, jid],
|
|
620
635
|
type: 'regular',
|
|
621
636
|
apiVersion: 3,
|
|
622
637
|
operation: OP.SET
|
|
@@ -628,7 +643,7 @@ export const chatModificationToAppPatch = (mod, jid) => {
|
|
|
628
643
|
labeled: false
|
|
629
644
|
}
|
|
630
645
|
},
|
|
631
|
-
index: [LabelAssociationType.Chat, mod.removeChatLabel.labelId, jid],
|
|
646
|
+
index: [_LabelAssociation.LabelAssociationType.Chat, mod.removeChatLabel.labelId, jid],
|
|
632
647
|
type: 'regular',
|
|
633
648
|
apiVersion: 3,
|
|
634
649
|
operation: OP.SET
|
|
@@ -640,7 +655,7 @@ export const chatModificationToAppPatch = (mod, jid) => {
|
|
|
640
655
|
labeled: true
|
|
641
656
|
}
|
|
642
657
|
},
|
|
643
|
-
index: [LabelAssociationType.Message, mod.addMessageLabel.labelId, jid, mod.addMessageLabel.messageId, '0', '0'],
|
|
658
|
+
index: [_LabelAssociation.LabelAssociationType.Message, mod.addMessageLabel.labelId, jid, mod.addMessageLabel.messageId, '0', '0'],
|
|
644
659
|
type: 'regular',
|
|
645
660
|
apiVersion: 3,
|
|
646
661
|
operation: OP.SET
|
|
@@ -652,18 +667,19 @@ export const chatModificationToAppPatch = (mod, jid) => {
|
|
|
652
667
|
labeled: false
|
|
653
668
|
}
|
|
654
669
|
},
|
|
655
|
-
index: [LabelAssociationType.Message, mod.removeMessageLabel.labelId, jid, mod.removeMessageLabel.messageId, '0', '0'],
|
|
670
|
+
index: [_LabelAssociation.LabelAssociationType.Message, mod.removeMessageLabel.labelId, jid, mod.removeMessageLabel.messageId, '0', '0'],
|
|
656
671
|
type: 'regular',
|
|
657
672
|
apiVersion: 3,
|
|
658
673
|
operation: OP.SET
|
|
659
674
|
};
|
|
660
675
|
} else {
|
|
661
|
-
throw new Boom('not supported');
|
|
676
|
+
throw new _boom.Boom('not supported');
|
|
662
677
|
}
|
|
663
678
|
patch.syncAction.timestamp = Date.now();
|
|
664
679
|
return patch;
|
|
665
680
|
};
|
|
666
|
-
|
|
681
|
+
exports.chatModificationToAppPatch = chatModificationToAppPatch;
|
|
682
|
+
const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) => {
|
|
667
683
|
const isInitialSync = !!initialSyncOpts;
|
|
668
684
|
const accountSettings = initialSyncOpts?.accountSettings;
|
|
669
685
|
logger?.trace({
|
|
@@ -679,7 +695,7 @@ export const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) =
|
|
|
679
695
|
if (action?.muteAction) {
|
|
680
696
|
ev.emit('chats.update', [{
|
|
681
697
|
id,
|
|
682
|
-
muteEndTime: action.muteAction?.muted ? toNumber(action.muteAction.muteEndTimestamp) : null,
|
|
698
|
+
muteEndTime: action.muteAction?.muted ? (0, _generics.toNumber)(action.muteAction.muteEndTimestamp) : null,
|
|
683
699
|
conditional: getChatUpdateConditional(id, undefined)
|
|
684
700
|
}]);
|
|
685
701
|
} else if (action?.archiveChatAction || type === 'archive' || type === 'unarchive') {
|
|
@@ -746,7 +762,7 @@ export const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) =
|
|
|
746
762
|
} else if (action?.pinAction) {
|
|
747
763
|
ev.emit('chats.update', [{
|
|
748
764
|
id,
|
|
749
|
-
pinned: action.pinAction?.pinned ? toNumber(action.timestamp) : null,
|
|
765
|
+
pinned: action.pinAction?.pinned ? (0, _generics.toNumber)(action.timestamp) : null,
|
|
750
766
|
conditional: getChatUpdateConditional(id, undefined)
|
|
751
767
|
}]);
|
|
752
768
|
} else if (action?.unarchiveChatsSetting) {
|
|
@@ -796,12 +812,12 @@ export const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) =
|
|
|
796
812
|
} else if (action?.labelAssociationAction) {
|
|
797
813
|
ev.emit('labels.association', {
|
|
798
814
|
type: action.labelAssociationAction.labeled ? 'add' : 'remove',
|
|
799
|
-
association: type === LabelAssociationType.Chat ? {
|
|
800
|
-
type: LabelAssociationType.Chat,
|
|
815
|
+
association: type === _LabelAssociation.LabelAssociationType.Chat ? {
|
|
816
|
+
type: _LabelAssociation.LabelAssociationType.Chat,
|
|
801
817
|
chatId: syncAction.index[2],
|
|
802
818
|
labelId: syncAction.index[1]
|
|
803
819
|
} : {
|
|
804
|
-
type: LabelAssociationType.Message,
|
|
820
|
+
type: _LabelAssociation.LabelAssociationType.Message,
|
|
805
821
|
chatId: syncAction.index[2],
|
|
806
822
|
messageId: syncAction.index[3],
|
|
807
823
|
labelId: syncAction.index[1]
|
|
@@ -827,4 +843,5 @@ export const processSyncAction = (syncAction, ev, me, initialSyncOpts, logger) =
|
|
|
827
843
|
return lastMsgTimestamp >= chatLastMsgTimestamp;
|
|
828
844
|
}
|
|
829
845
|
};
|
|
830
|
-
//# sourceMappingURL=chat-utils.js.map
|
|
846
|
+
//# sourceMappingURL=chat-utils.js.map
|
|
847
|
+
exports.processSyncAction = processSyncAction;
|
package/lib/Utils/crypto.js
CHANGED
|
@@ -1,14 +1,38 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Curve = void 0;
|
|
7
|
+
exports.aesDecrypt = aesDecrypt;
|
|
8
|
+
exports.aesDecryptCTR = aesDecryptCTR;
|
|
9
|
+
exports.aesDecryptGCM = aesDecryptGCM;
|
|
10
|
+
exports.aesDecryptWithIV = aesDecryptWithIV;
|
|
11
|
+
exports.aesEncrypWithIV = aesEncrypWithIV;
|
|
12
|
+
exports.aesEncrypt = aesEncrypt;
|
|
13
|
+
exports.aesEncryptCTR = aesEncryptCTR;
|
|
14
|
+
exports.aesEncryptGCM = aesEncryptGCM;
|
|
15
|
+
exports.derivePairingCodeKey = derivePairingCodeKey;
|
|
16
|
+
exports.generateSignalPubKey = void 0;
|
|
17
|
+
exports.hkdf = hkdf;
|
|
18
|
+
exports.hmacSign = hmacSign;
|
|
19
|
+
exports.md5 = md5;
|
|
20
|
+
exports.sha256 = sha256;
|
|
21
|
+
exports.signedKeyPair = void 0;
|
|
22
|
+
var _crypto = require("crypto");
|
|
23
|
+
var libsignal = _interopRequireWildcard(require("libsignal"));
|
|
24
|
+
var _index = require("../Defaults/index.js");
|
|
25
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
2
26
|
/* @ts-ignore */
|
|
3
|
-
|
|
4
|
-
import { KEY_BUNDLE_TYPE } from '../Defaults/index.js';
|
|
27
|
+
|
|
5
28
|
// insure browser & node compatibility
|
|
6
29
|
const {
|
|
7
30
|
subtle
|
|
8
31
|
} = globalThis.crypto;
|
|
9
32
|
/** prefix version byte to the pub keys, required for some curve crypto functions */
|
|
10
|
-
|
|
11
|
-
|
|
33
|
+
const generateSignalPubKey = pubKey => pubKey.length === 33 ? pubKey : Buffer.concat([_index.KEY_BUNDLE_TYPE, pubKey]);
|
|
34
|
+
exports.generateSignalPubKey = generateSignalPubKey;
|
|
35
|
+
const Curve = exports.Curve = {
|
|
12
36
|
generateKeyPair: () => {
|
|
13
37
|
const {
|
|
14
38
|
pubKey,
|
|
@@ -34,7 +58,7 @@ export const Curve = {
|
|
|
34
58
|
}
|
|
35
59
|
}
|
|
36
60
|
};
|
|
37
|
-
|
|
61
|
+
const signedKeyPair = (identityKeyPair, keyId) => {
|
|
38
62
|
const preKey = Curve.generateKeyPair();
|
|
39
63
|
const pubKey = generateSignalPubKey(preKey.public);
|
|
40
64
|
const signature = Curve.sign(identityKeyPair.private, pubKey);
|
|
@@ -44,13 +68,14 @@ export const signedKeyPair = (identityKeyPair, keyId) => {
|
|
|
44
68
|
keyId
|
|
45
69
|
};
|
|
46
70
|
};
|
|
71
|
+
exports.signedKeyPair = signedKeyPair;
|
|
47
72
|
const GCM_TAG_LENGTH = 128 >> 3;
|
|
48
73
|
/**
|
|
49
74
|
* encrypt AES 256 GCM;
|
|
50
75
|
* where the tag tag is suffixed to the ciphertext
|
|
51
76
|
* */
|
|
52
|
-
|
|
53
|
-
const cipher = createCipheriv('aes-256-gcm', key, iv);
|
|
77
|
+
function aesEncryptGCM(plaintext, key, iv, additionalData) {
|
|
78
|
+
const cipher = (0, _crypto.createCipheriv)('aes-256-gcm', key, iv);
|
|
54
79
|
cipher.setAAD(additionalData);
|
|
55
80
|
return Buffer.concat([cipher.update(plaintext), cipher.final(), cipher.getAuthTag()]);
|
|
56
81
|
}
|
|
@@ -58,8 +83,8 @@ export function aesEncryptGCM(plaintext, key, iv, additionalData) {
|
|
|
58
83
|
* decrypt AES 256 GCM;
|
|
59
84
|
* where the auth tag is suffixed to the ciphertext
|
|
60
85
|
* */
|
|
61
|
-
|
|
62
|
-
const decipher = createDecipheriv('aes-256-gcm', key, iv);
|
|
86
|
+
function aesDecryptGCM(ciphertext, key, iv, additionalData) {
|
|
87
|
+
const decipher = (0, _crypto.createDecipheriv)('aes-256-gcm', key, iv);
|
|
63
88
|
// decrypt additional adata
|
|
64
89
|
const enc = ciphertext.slice(0, ciphertext.length - GCM_TAG_LENGTH);
|
|
65
90
|
const tag = ciphertext.slice(ciphertext.length - GCM_TAG_LENGTH);
|
|
@@ -68,46 +93,46 @@ export function aesDecryptGCM(ciphertext, key, iv, additionalData) {
|
|
|
68
93
|
decipher.setAuthTag(tag);
|
|
69
94
|
return Buffer.concat([decipher.update(enc), decipher.final()]);
|
|
70
95
|
}
|
|
71
|
-
|
|
72
|
-
const cipher = createCipheriv('aes-256-ctr', key, iv);
|
|
96
|
+
function aesEncryptCTR(plaintext, key, iv) {
|
|
97
|
+
const cipher = (0, _crypto.createCipheriv)('aes-256-ctr', key, iv);
|
|
73
98
|
return Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
74
99
|
}
|
|
75
|
-
|
|
76
|
-
const decipher = createDecipheriv('aes-256-ctr', key, iv);
|
|
100
|
+
function aesDecryptCTR(ciphertext, key, iv) {
|
|
101
|
+
const decipher = (0, _crypto.createDecipheriv)('aes-256-ctr', key, iv);
|
|
77
102
|
return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
78
103
|
}
|
|
79
104
|
/** decrypt AES 256 CBC; where the IV is prefixed to the buffer */
|
|
80
|
-
|
|
105
|
+
function aesDecrypt(buffer, key) {
|
|
81
106
|
return aesDecryptWithIV(buffer.slice(16, buffer.length), key, buffer.slice(0, 16));
|
|
82
107
|
}
|
|
83
108
|
/** decrypt AES 256 CBC */
|
|
84
|
-
|
|
85
|
-
const aes = createDecipheriv('aes-256-cbc', key, IV);
|
|
109
|
+
function aesDecryptWithIV(buffer, key, IV) {
|
|
110
|
+
const aes = (0, _crypto.createDecipheriv)('aes-256-cbc', key, IV);
|
|
86
111
|
return Buffer.concat([aes.update(buffer), aes.final()]);
|
|
87
112
|
}
|
|
88
113
|
// encrypt AES 256 CBC; where a random IV is prefixed to the buffer
|
|
89
|
-
|
|
90
|
-
const IV = randomBytes(16);
|
|
91
|
-
const aes = createCipheriv('aes-256-cbc', key, IV);
|
|
114
|
+
function aesEncrypt(buffer, key) {
|
|
115
|
+
const IV = (0, _crypto.randomBytes)(16);
|
|
116
|
+
const aes = (0, _crypto.createCipheriv)('aes-256-cbc', key, IV);
|
|
92
117
|
return Buffer.concat([IV, aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
|
93
118
|
}
|
|
94
119
|
// encrypt AES 256 CBC with a given IV
|
|
95
|
-
|
|
96
|
-
const aes = createCipheriv('aes-256-cbc', key, IV);
|
|
120
|
+
function aesEncrypWithIV(buffer, key, IV) {
|
|
121
|
+
const aes = (0, _crypto.createCipheriv)('aes-256-cbc', key, IV);
|
|
97
122
|
return Buffer.concat([aes.update(buffer), aes.final()]); // prefix IV to the buffer
|
|
98
123
|
}
|
|
99
124
|
// sign HMAC using SHA 256
|
|
100
|
-
|
|
101
|
-
return createHmac(variant, key).update(buffer).digest();
|
|
125
|
+
function hmacSign(buffer, key, variant = 'sha256') {
|
|
126
|
+
return (0, _crypto.createHmac)(variant, key).update(buffer).digest();
|
|
102
127
|
}
|
|
103
|
-
|
|
104
|
-
return createHash('sha256').update(buffer).digest();
|
|
128
|
+
function sha256(buffer) {
|
|
129
|
+
return (0, _crypto.createHash)('sha256').update(buffer).digest();
|
|
105
130
|
}
|
|
106
|
-
|
|
107
|
-
return createHash('md5').update(buffer).digest();
|
|
131
|
+
function md5(buffer) {
|
|
132
|
+
return (0, _crypto.createHash)('md5').update(buffer).digest();
|
|
108
133
|
}
|
|
109
134
|
// HKDF key expansion
|
|
110
|
-
|
|
135
|
+
async function hkdf(buffer, expandedLength, info) {
|
|
111
136
|
// Ensure we have a Uint8Array for the key material
|
|
112
137
|
const inputKeyMaterial = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
|
113
138
|
// Set default values if not provided
|
|
@@ -127,7 +152,7 @@ export async function hkdf(buffer, expandedLength, info) {
|
|
|
127
152
|
);
|
|
128
153
|
return Buffer.from(derivedBits);
|
|
129
154
|
}
|
|
130
|
-
|
|
155
|
+
async function derivePairingCodeKey(pairingCode, salt) {
|
|
131
156
|
// Convert inputs to formats Web Crypto API can work with
|
|
132
157
|
const encoder = new TextEncoder();
|
|
133
158
|
const pairingCodeBuffer = encoder.encode(pairingCode);
|