lordceaser-baileys 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/WAProto/index.js +136901 -78899
- package/WASignalGroup/GroupProtocol.js +1697 -0
- package/WASignalGroup/ciphertext_message.js +16 -0
- package/WASignalGroup/group_cipher.js +120 -0
- package/WASignalGroup/group_session_builder.js +46 -0
- package/WASignalGroup/index.js +5 -0
- package/WASignalGroup/keyhelper.js +21 -0
- package/WASignalGroup/protobufs.js +3 -0
- package/WASignalGroup/queue_job.js +69 -0
- package/WASignalGroup/sender_chain_key.js +50 -0
- package/WASignalGroup/sender_key_distribution_message.js +78 -0
- package/WASignalGroup/sender_key_message.js +92 -0
- package/WASignalGroup/sender_key_name.js +70 -0
- package/WASignalGroup/sender_key_record.js +56 -0
- package/WASignalGroup/sender_key_state.js +129 -0
- package/{lib/Signal/Group/sender-message-key.js → WASignalGroup/sender_message_key.js} +16 -3
- package/index.js +17 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +15 -37
- package/lib/Defaults/index.js +60 -81
- package/lib/Signal/libsignal.d.ts +3 -5
- package/lib/Signal/libsignal.js +80 -359
- package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +5 -4
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.d.ts +3 -3
- package/lib/Socket/Client/index.js +19 -3
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +2 -3
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/business.d.ts +100 -147
- package/lib/Socket/business.js +43 -162
- package/lib/Socket/chats.d.ts +41 -85
- package/lib/Socket/chats.js +321 -569
- package/lib/Socket/groups.d.ts +57 -103
- package/lib/Socket/groups.js +84 -116
- package/lib/Socket/index.d.ts +106 -194
- package/lib/Socket/index.js +9 -11
- package/lib/Socket/messages-recv.d.ts +89 -134
- package/lib/Socket/messages-recv.js +475 -1275
- package/lib/Socket/messages-send.d.ts +97 -141
- package/lib/Socket/messages-send.js +633 -691
- package/lib/Socket/newsletter.d.ts +74 -112
- package/lib/Socket/newsletter.js +202 -147
- package/lib/Socket/registration.d.ts +264 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +19 -34
- package/lib/Socket/socket.js +219 -547
- package/lib/Socket/usync.d.ts +37 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +10 -0
- package/lib/Store/make-cache-manager-store.d.ts +14 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-in-memory-store.js +431 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.d.ts +11 -19
- package/lib/Types/Auth.js +2 -2
- package/lib/Types/Call.d.ts +1 -3
- package/lib/Types/Call.js +2 -2
- package/lib/Types/Chat.d.ts +8 -25
- package/lib/Types/Chat.js +4 -8
- package/lib/Types/Contact.d.ts +1 -8
- package/lib/Types/Contact.js +2 -2
- package/lib/Types/Events.d.ts +17 -101
- package/lib/Types/Events.js +2 -2
- package/lib/Types/GroupMetadata.d.ts +3 -18
- package/lib/Types/GroupMetadata.js +2 -2
- package/lib/Types/Label.d.ts +0 -1
- package/lib/Types/Label.js +5 -3
- package/lib/Types/LabelAssociation.d.ts +0 -1
- package/lib/Types/LabelAssociation.js +5 -3
- package/lib/Types/Message.d.ts +204 -91
- package/lib/Types/Message.js +9 -11
- package/lib/Types/Newsletter.d.ts +92 -0
- package/lib/Types/Newsletter.js +32 -0
- package/lib/Types/Product.d.ts +1 -2
- package/lib/Types/Product.js +2 -2
- package/lib/Types/Signal.d.ts +2 -32
- package/lib/Types/Signal.js +2 -2
- package/lib/Types/Socket.d.ts +24 -44
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.d.ts +2 -72
- package/lib/Types/State.js +2 -56
- package/lib/Types/USync.d.ts +2 -3
- package/lib/Types/USync.js +2 -2
- package/lib/Types/index.d.ts +16 -16
- package/lib/Types/index.js +31 -15
- package/lib/Utils/auth-utils.d.ts +6 -12
- package/lib/Utils/auth-utils.js +143 -239
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/business.d.ts +3 -4
- package/lib/Utils/business.js +69 -66
- package/lib/Utils/c4-compat.js +0 -8
- package/lib/Utils/chat-utils.d.ts +17 -47
- package/lib/Utils/chat-utils.js +237 -364
- package/lib/Utils/crypto.d.ts +21 -18
- package/lib/Utils/crypto.js +125 -44
- package/lib/Utils/decode-wa-message.d.ts +8 -38
- package/lib/Utils/decode-wa-message.js +90 -173
- package/lib/Utils/event-buffer.d.ts +8 -9
- package/lib/Utils/event-buffer.js +71 -176
- package/lib/Utils/generics.d.ts +22 -26
- package/lib/Utils/generics.js +175 -166
- package/lib/Utils/history.d.ts +11 -16
- package/lib/Utils/history.js +53 -93
- package/lib/Utils/index.d.ts +17 -22
- package/lib/Utils/index.js +34 -22
- package/lib/Utils/link-preview.d.ts +5 -5
- package/lib/Utils/link-preview.js +24 -16
- package/lib/Utils/logger.d.ts +1 -11
- package/lib/Utils/logger.js +7 -3
- package/lib/Utils/lt-hash.d.ts +12 -8
- package/lib/Utils/lt-hash.js +46 -3
- package/lib/Utils/make-mutex.d.ts +0 -2
- package/lib/Utils/make-mutex.js +34 -24
- package/lib/Utils/messages-media.d.ts +45 -65
- package/lib/Utils/messages-media.js +358 -425
- package/lib/Utils/messages.d.ts +18 -32
- package/lib/Utils/messages.js +720 -392
- package/lib/Utils/noise-handler.d.ts +13 -13
- package/lib/Utils/noise-handler.js +108 -149
- package/lib/Utils/process-message.d.ts +11 -30
- package/lib/Utils/process-message.js +166 -423
- package/lib/Utils/signal.d.ts +6 -20
- package/lib/Utils/signal.js +65 -107
- package/lib/Utils/use-multi-file-auth-state.d.ts +1 -2
- package/lib/Utils/use-multi-file-auth-state.js +103 -57
- package/lib/Utils/use-single-file-auth-state.d.ts +12 -0
- package/lib/Utils/use-single-file-auth-state.js +76 -0
- package/lib/Utils/validate-connection.d.ts +6 -6
- package/lib/Utils/validate-connection.js +114 -119
- package/lib/WABinary/constants.d.ts +4 -5
- package/lib/WABinary/constants.js +20 -1281
- package/lib/WABinary/decode.d.ts +3 -4
- package/lib/WABinary/decode.js +53 -51
- package/lib/WABinary/encode.d.ts +1 -2
- package/lib/WABinary/encode.js +44 -12
- package/lib/WABinary/generic-utils.d.ts +6 -7
- package/lib/WABinary/generic-utils.js +43 -46
- package/lib/WABinary/index.d.ts +5 -6
- package/lib/WABinary/index.js +21 -6
- package/lib/WABinary/jid-utils.d.ts +7 -24
- package/lib/WABinary/jid-utils.js +40 -74
- package/lib/WABinary/types.d.ts +1 -2
- package/lib/WABinary/types.js +2 -2
- package/lib/WAM/BinaryInfo.d.ts +1 -2
- package/lib/WAM/BinaryInfo.js +5 -2
- package/lib/WAM/constants.d.ts +3 -5
- package/lib/WAM/constants.js +11958 -19461
- package/lib/WAM/encode.d.ts +2 -3
- package/lib/WAM/encode.js +22 -17
- package/lib/WAM/index.d.ts +3 -4
- package/lib/WAM/index.js +19 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +13 -33
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +14 -11
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -9
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -3
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +13 -9
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +3 -4
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +22 -20
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -5
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +8 -13
- package/lib/WAUSync/Protocols/index.d.ts +4 -6
- package/lib/WAUSync/Protocols/index.js +20 -6
- package/lib/WAUSync/USyncQuery.d.ts +4 -6
- package/lib/WAUSync/USyncQuery.js +35 -44
- package/lib/WAUSync/USyncUser.d.ts +4 -11
- package/lib/WAUSync/USyncUser.js +5 -10
- package/lib/WAUSync/index.d.ts +3 -4
- package/lib/WAUSync/index.js +19 -4
- package/lib/index.js +31 -13
- package/package.json +19 -10
- package/WAProto/GenerateStatics.sh +0 -3
- package/WAProto/WAProto.proto +0 -5479
- package/WAProto/fix-imports.js +0 -85
- package/WAProto/index.d.ts +0 -14017
- 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 -277
- 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 +0 -11
- 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 +0 -54
- 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 +0 -273
- package/lib/Socket/communities.d.ts.map +0 -1
- package/lib/Socket/communities.js +0 -431
- 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 +0 -3
- package/lib/Socket/mex.d.ts.map +0 -1
- package/lib/Socket/mex.js +0 -42
- 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/Mex.d.ts +0 -141
- package/lib/Types/Mex.d.ts.map +0 -1
- package/lib/Types/Mex.js +0 -37
- package/lib/Types/Mex.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/browser-utils.d.ts +0 -4
- package/lib/Utils/browser-utils.d.ts.map +0 -1
- package/lib/Utils/browser-utils.js +0 -29
- 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/companion-reg-client-utils.d.ts +0 -17
- package/lib/Utils/companion-reg-client-utils.d.ts.map +0 -1
- package/lib/Utils/companion-reg-client-utils.js +0 -35
- package/lib/Utils/companion-reg-client-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/identity-change-handler.d.ts +0 -44
- package/lib/Utils/identity-change-handler.d.ts.map +0 -1
- package/lib/Utils/identity-change-handler.js +0 -50
- package/lib/Utils/identity-change-handler.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 +0 -115
- package/lib/Utils/message-retry-manager.d.ts.map +0 -1
- package/lib/Utils/message-retry-manager.js +0 -265
- 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/offline-node-processor.d.ts +0 -17
- package/lib/Utils/offline-node-processor.d.ts.map +0 -1
- package/lib/Utils/offline-node-processor.js +0 -40
- package/lib/Utils/offline-node-processor.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/reporting-utils.d.ts +0 -11
- package/lib/Utils/reporting-utils.d.ts.map +0 -1
- package/lib/Utils/reporting-utils.js +0 -258
- package/lib/Utils/reporting-utils.js.map +0 -1
- package/lib/Utils/signal.d.ts.map +0 -1
- package/lib/Utils/signal.js.map +0 -1
- package/lib/Utils/stanza-ack.d.ts +0 -11
- package/lib/Utils/stanza-ack.d.ts.map +0 -1
- package/lib/Utils/stanza-ack.js +0 -38
- package/lib/Utils/stanza-ack.js.map +0 -1
- package/lib/Utils/sync-action-utils.d.ts +0 -19
- package/lib/Utils/sync-action-utils.d.ts.map +0 -1
- package/lib/Utils/sync-action-utils.js +0 -49
- package/lib/Utils/sync-action-utils.js.map +0 -1
- package/lib/Utils/tc-token-utils.d.ts +0 -37
- package/lib/Utils/tc-token-utils.d.ts.map +0 -1
- package/lib/Utils/tc-token-utils.js +0 -164
- package/lib/Utils/tc-token-utils.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/USyncUsernameProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +0 -1
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +0 -25
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +0 -1
- 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.map +0 -1
- 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 +0 -12
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
package/lib/Utils/signal.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
1
|
+
import { SignalRepository } from '../Types';
|
|
2
|
+
import { AuthenticationCreds, AuthenticationState, KeyPair, SignalIdentity, SignalKeyStore, SignedKeyPair } from '../Types/Auth';
|
|
3
|
+
import { BinaryNode, JidWithDevice } from '../WABinary';
|
|
4
|
+
import { USyncQueryResultList } from '../WAUSync';
|
|
5
5
|
export declare const createSignalIdentity: (wid: string, accountSignatureKey: Uint8Array) => SignalIdentity;
|
|
6
6
|
export declare const getPreKeys: ({ get }: SignalKeyStore, min: number, limit: number) => Promise<{
|
|
7
7
|
[id: string]: KeyPair;
|
|
@@ -15,21 +15,8 @@ export declare const generateOrGetPreKeys: (creds: AuthenticationCreds, range: n
|
|
|
15
15
|
};
|
|
16
16
|
export declare const xmppSignedPreKey: (key: SignedKeyPair) => BinaryNode;
|
|
17
17
|
export declare const xmppPreKey: (pair: KeyPair, id: number) => BinaryNode;
|
|
18
|
-
export declare const
|
|
19
|
-
|
|
20
|
-
identityKey: Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike>;
|
|
21
|
-
signedPreKey: {
|
|
22
|
-
keyId: number;
|
|
23
|
-
publicKey: Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike>;
|
|
24
|
-
signature: Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike>;
|
|
25
|
-
};
|
|
26
|
-
preKey: {
|
|
27
|
-
keyId: number;
|
|
28
|
-
publicKey: Uint8Array;
|
|
29
|
-
} | undefined;
|
|
30
|
-
} | null;
|
|
31
|
-
export declare const parseAndInjectE2ESessions: (node: BinaryNode, repository: SignalRepositoryWithLIDStore) => Promise<void>;
|
|
32
|
-
export declare const extractDeviceJids: (result: USyncQueryResultList[], myJid: string, myLid: string, excludeZeroDevices: boolean) => FullJid[];
|
|
18
|
+
export declare const parseAndInjectE2ESessions: (node: BinaryNode, repository: SignalRepository) => Promise<void>;
|
|
19
|
+
export declare const extractDeviceJids: (result: USyncQueryResultList[], myJid: string, excludeZeroDevices: boolean) => JidWithDevice[];
|
|
33
20
|
/**
|
|
34
21
|
* get the next N keys for upload or processing
|
|
35
22
|
* @param count number of pre-keys to get or generate
|
|
@@ -44,4 +31,3 @@ export declare const getNextPreKeysNode: (state: AuthenticationState, count: num
|
|
|
44
31
|
update: Partial<AuthenticationCreds>;
|
|
45
32
|
node: BinaryNode;
|
|
46
33
|
}>;
|
|
47
|
-
//# sourceMappingURL=signal.d.ts.map
|
package/lib/Utils/signal.js
CHANGED
|
@@ -1,113 +1,77 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getNextPreKeysNode = exports.getNextPreKeys = exports.extractDeviceJids = exports.parseAndInjectE2ESessions = exports.xmppPreKey = exports.xmppSignedPreKey = exports.generateOrGetPreKeys = exports.getPreKeys = exports.createSignalIdentity = void 0;
|
|
4
|
+
const Defaults_1 = require("../Defaults");
|
|
5
|
+
const WABinary_1 = require("../WABinary");
|
|
6
|
+
const crypto_1 = require("./crypto");
|
|
7
|
+
const generics_1 = require("./generics");
|
|
5
8
|
function chunk(array, size) {
|
|
6
|
-
const
|
|
9
|
+
const result = [];
|
|
7
10
|
for (let i = 0; i < array.length; i += size) {
|
|
8
|
-
|
|
11
|
+
result.push(array.slice(i, i + size));
|
|
9
12
|
}
|
|
10
|
-
return
|
|
13
|
+
return result;
|
|
11
14
|
}
|
|
12
|
-
|
|
15
|
+
const createSignalIdentity = (wid, accountSignatureKey) => {
|
|
13
16
|
return {
|
|
14
17
|
identifier: { name: wid, deviceId: 0 },
|
|
15
|
-
identifierKey: generateSignalPubKey(accountSignatureKey)
|
|
18
|
+
identifierKey: (0, crypto_1.generateSignalPubKey)(accountSignatureKey)
|
|
16
19
|
};
|
|
17
20
|
};
|
|
18
|
-
|
|
21
|
+
exports.createSignalIdentity = createSignalIdentity;
|
|
22
|
+
const getPreKeys = async ({ get }, min, limit) => {
|
|
19
23
|
const idList = [];
|
|
20
24
|
for (let id = min; id < limit; id++) {
|
|
21
25
|
idList.push(id.toString());
|
|
22
26
|
}
|
|
23
27
|
return get('pre-key', idList);
|
|
24
28
|
};
|
|
25
|
-
|
|
29
|
+
exports.getPreKeys = getPreKeys;
|
|
30
|
+
const generateOrGetPreKeys = (creds, range) => {
|
|
26
31
|
const avaliable = creds.nextPreKeyId - creds.firstUnuploadedPreKeyId;
|
|
27
32
|
const remaining = range - avaliable;
|
|
28
33
|
const lastPreKeyId = creds.nextPreKeyId + remaining - 1;
|
|
29
34
|
const newPreKeys = {};
|
|
30
35
|
if (remaining > 0) {
|
|
31
36
|
for (let i = creds.nextPreKeyId; i <= lastPreKeyId; i++) {
|
|
32
|
-
newPreKeys[i] = Curve.generateKeyPair();
|
|
37
|
+
newPreKeys[i] = crypto_1.Curve.generateKeyPair();
|
|
33
38
|
}
|
|
34
39
|
}
|
|
35
40
|
return {
|
|
36
41
|
newPreKeys,
|
|
37
42
|
lastPreKeyId,
|
|
38
|
-
preKeysRange: [creds.firstUnuploadedPreKeyId, range]
|
|
43
|
+
preKeysRange: [creds.firstUnuploadedPreKeyId, range],
|
|
39
44
|
};
|
|
40
45
|
};
|
|
41
|
-
|
|
46
|
+
exports.generateOrGetPreKeys = generateOrGetPreKeys;
|
|
47
|
+
const xmppSignedPreKey = (key) => ({
|
|
42
48
|
tag: 'skey',
|
|
43
49
|
attrs: {},
|
|
44
50
|
content: [
|
|
45
|
-
{ tag: 'id', attrs: {}, content: encodeBigEndian(key.keyId, 3) },
|
|
51
|
+
{ tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(key.keyId, 3) },
|
|
46
52
|
{ tag: 'value', attrs: {}, content: key.keyPair.public },
|
|
47
53
|
{ tag: 'signature', attrs: {}, content: key.signature }
|
|
48
54
|
]
|
|
49
55
|
});
|
|
50
|
-
|
|
56
|
+
exports.xmppSignedPreKey = xmppSignedPreKey;
|
|
57
|
+
const xmppPreKey = (pair, id) => ({
|
|
51
58
|
tag: 'key',
|
|
52
59
|
attrs: {},
|
|
53
60
|
content: [
|
|
54
|
-
{ tag: 'id', attrs: {}, content: encodeBigEndian(id, 3) },
|
|
61
|
+
{ tag: 'id', attrs: {}, content: (0, generics_1.encodeBigEndian)(id, 3) },
|
|
55
62
|
{ tag: 'value', attrs: {}, content: pair.public }
|
|
56
63
|
]
|
|
57
64
|
});
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const identity = getBinaryNodeChildBuffer(keysNode, 'identity');
|
|
67
|
-
const skey = getBinaryNodeChild(keysNode, 'skey');
|
|
68
|
-
if (!identity || identity.length !== 32 || !skey)
|
|
69
|
-
return null;
|
|
70
|
-
const registrationId = getBinaryNodeChildUInt(receipt, 'registration', 4);
|
|
71
|
-
if (!isValidUInt(registrationId))
|
|
72
|
-
return null;
|
|
73
|
-
const signedPubKey = getBinaryNodeChildBuffer(skey, 'value');
|
|
74
|
-
const signedSig = getBinaryNodeChildBuffer(skey, 'signature');
|
|
75
|
-
const signedKeyId = getBinaryNodeChildUInt(skey, 'id', 3);
|
|
76
|
-
if (!signedPubKey || signedPubKey.length !== 32 || !signedSig || !isValidUInt(signedKeyId)) {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
const preKeyNode = getBinaryNodeChild(keysNode, 'key');
|
|
80
|
-
let preKey;
|
|
81
|
-
if (preKeyNode) {
|
|
82
|
-
const preKeyPub = getBinaryNodeChildBuffer(preKeyNode, 'value');
|
|
83
|
-
const preKeyId = getBinaryNodeChildUInt(preKeyNode, 'id', 3);
|
|
84
|
-
if (!preKeyPub || preKeyPub.length !== 32 || !isValidUInt(preKeyId)) {
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
preKey = { keyId: preKeyId, publicKey: generateSignalPubKey(preKeyPub) };
|
|
88
|
-
}
|
|
89
|
-
return {
|
|
90
|
-
registrationId,
|
|
91
|
-
identityKey: generateSignalPubKey(identity),
|
|
92
|
-
signedPreKey: {
|
|
93
|
-
keyId: signedKeyId,
|
|
94
|
-
publicKey: generateSignalPubKey(signedPubKey),
|
|
95
|
-
signature: signedSig
|
|
96
|
-
},
|
|
97
|
-
preKey
|
|
98
|
-
};
|
|
99
|
-
};
|
|
100
|
-
export const parseAndInjectE2ESessions = async (node, repository) => {
|
|
101
|
-
const extractKey = (key) => key
|
|
102
|
-
? {
|
|
103
|
-
keyId: getBinaryNodeChildUInt(key, 'id', 3),
|
|
104
|
-
publicKey: generateSignalPubKey(getBinaryNodeChildBuffer(key, 'value')),
|
|
105
|
-
signature: getBinaryNodeChildBuffer(key, 'signature')
|
|
106
|
-
}
|
|
107
|
-
: undefined;
|
|
108
|
-
const nodes = getBinaryNodeChildren(getBinaryNodeChild(node, 'list'), 'user');
|
|
65
|
+
exports.xmppPreKey = xmppPreKey;
|
|
66
|
+
const parseAndInjectE2ESessions = async (node, repository) => {
|
|
67
|
+
const extractKey = (key) => (key ? ({
|
|
68
|
+
keyId: (0, WABinary_1.getBinaryNodeChildUInt)(key, 'id', 3),
|
|
69
|
+
publicKey: (0, crypto_1.generateSignalPubKey)((0, WABinary_1.getBinaryNodeChildBuffer)(key, 'value')),
|
|
70
|
+
signature: (0, WABinary_1.getBinaryNodeChildBuffer)(key, 'signature'),
|
|
71
|
+
}) : undefined);
|
|
72
|
+
const nodes = (0, WABinary_1.getBinaryNodeChildren)((0, WABinary_1.getBinaryNodeChild)(node, 'list'), 'user');
|
|
109
73
|
for (const node of nodes) {
|
|
110
|
-
assertNodeErrorFree(node);
|
|
74
|
+
(0, WABinary_1.assertNodeErrorFree)(node);
|
|
111
75
|
}
|
|
112
76
|
// Most of the work in repository.injectE2ESession is CPU intensive, not IO
|
|
113
77
|
// So Promise.all doesn't really help here,
|
|
@@ -117,85 +81,79 @@ export const parseAndInjectE2ESessions = async (node, repository) => {
|
|
|
117
81
|
const chunkSize = 100;
|
|
118
82
|
const chunks = chunk(nodes, chunkSize);
|
|
119
83
|
for (const nodesChunk of chunks) {
|
|
120
|
-
|
|
121
|
-
const signedKey = getBinaryNodeChild(node, 'skey');
|
|
122
|
-
const key = getBinaryNodeChild(node, 'key');
|
|
123
|
-
const identity = getBinaryNodeChildBuffer(node, 'identity');
|
|
84
|
+
await Promise.all(nodesChunk.map(async (node) => {
|
|
85
|
+
const signedKey = (0, WABinary_1.getBinaryNodeChild)(node, 'skey');
|
|
86
|
+
const key = (0, WABinary_1.getBinaryNodeChild)(node, 'key');
|
|
87
|
+
const identity = (0, WABinary_1.getBinaryNodeChildBuffer)(node, 'identity');
|
|
124
88
|
const jid = node.attrs.jid;
|
|
125
|
-
const registrationId = getBinaryNodeChildUInt(node, 'registration', 4);
|
|
89
|
+
const registrationId = (0, WABinary_1.getBinaryNodeChildUInt)(node, 'registration', 4);
|
|
126
90
|
await repository.injectE2ESession({
|
|
127
91
|
jid,
|
|
128
92
|
session: {
|
|
129
93
|
registrationId: registrationId,
|
|
130
|
-
identityKey: generateSignalPubKey(identity),
|
|
94
|
+
identityKey: (0, crypto_1.generateSignalPubKey)(identity),
|
|
131
95
|
signedPreKey: extractKey(signedKey),
|
|
132
96
|
preKey: extractKey(key)
|
|
133
97
|
}
|
|
134
98
|
});
|
|
135
|
-
}
|
|
99
|
+
}));
|
|
136
100
|
}
|
|
137
101
|
};
|
|
138
|
-
|
|
139
|
-
|
|
102
|
+
exports.parseAndInjectE2ESessions = parseAndInjectE2ESessions;
|
|
103
|
+
const extractDeviceJids = (result, myJid, excludeZeroDevices) => {
|
|
104
|
+
const { user: myUser, device: myDevice } = (0, WABinary_1.jidDecode)(myJid);
|
|
140
105
|
const extracted = [];
|
|
141
106
|
for (const userResult of result) {
|
|
142
107
|
const { devices, id } = userResult;
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
) {
|
|
153
|
-
if (isHosted) {
|
|
154
|
-
domainType = domainType === WAJIDDomains.LID ? WAJIDDomains.HOSTED_LID : WAJIDDomains.HOSTED;
|
|
108
|
+
const { user } = (0, WABinary_1.jidDecode)(id);
|
|
109
|
+
const deviceList = devices === null || devices === void 0 ? void 0 : devices.deviceList;
|
|
110
|
+
if (Array.isArray(deviceList)) {
|
|
111
|
+
for (const { id: device, keyIndex } of deviceList) {
|
|
112
|
+
if ((!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
|
|
113
|
+
(myUser !== user || myDevice !== device) && // either different user or if me user, not this device
|
|
114
|
+
(device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
|
|
115
|
+
) {
|
|
116
|
+
extracted.push({ user, device });
|
|
155
117
|
}
|
|
156
|
-
extracted.push({
|
|
157
|
-
user,
|
|
158
|
-
device,
|
|
159
|
-
domainType,
|
|
160
|
-
server: getServerFromDomainType(server, domainType)
|
|
161
|
-
});
|
|
162
118
|
}
|
|
163
119
|
}
|
|
164
120
|
}
|
|
165
121
|
return extracted;
|
|
166
122
|
};
|
|
123
|
+
exports.extractDeviceJids = extractDeviceJids;
|
|
167
124
|
/**
|
|
168
125
|
* get the next N keys for upload or processing
|
|
169
126
|
* @param count number of pre-keys to get or generate
|
|
170
127
|
*/
|
|
171
|
-
|
|
172
|
-
const { newPreKeys, lastPreKeyId, preKeysRange } = generateOrGetPreKeys(creds, count);
|
|
128
|
+
const getNextPreKeys = async ({ creds, keys }, count) => {
|
|
129
|
+
const { newPreKeys, lastPreKeyId, preKeysRange } = (0, exports.generateOrGetPreKeys)(creds, count);
|
|
173
130
|
const update = {
|
|
174
131
|
nextPreKeyId: Math.max(lastPreKeyId + 1, creds.nextPreKeyId),
|
|
175
132
|
firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId + 1)
|
|
176
133
|
};
|
|
177
134
|
await keys.set({ 'pre-key': newPreKeys });
|
|
178
|
-
const preKeys = await getPreKeys(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1]);
|
|
135
|
+
const preKeys = await (0, exports.getPreKeys)(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1]);
|
|
179
136
|
return { update, preKeys };
|
|
180
137
|
};
|
|
181
|
-
|
|
138
|
+
exports.getNextPreKeys = getNextPreKeys;
|
|
139
|
+
const getNextPreKeysNode = async (state, count) => {
|
|
182
140
|
const { creds } = state;
|
|
183
|
-
const { update, preKeys } = await getNextPreKeys(state, count);
|
|
141
|
+
const { update, preKeys } = await (0, exports.getNextPreKeys)(state, count);
|
|
184
142
|
const node = {
|
|
185
143
|
tag: 'iq',
|
|
186
144
|
attrs: {
|
|
187
145
|
xmlns: 'encrypt',
|
|
188
146
|
type: 'set',
|
|
189
|
-
to: S_WHATSAPP_NET
|
|
147
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
190
148
|
},
|
|
191
149
|
content: [
|
|
192
|
-
{ tag: 'registration', attrs: {}, content: encodeBigEndian(creds.registrationId) },
|
|
193
|
-
{ tag: 'type', attrs: {}, content: KEY_BUNDLE_TYPE },
|
|
150
|
+
{ tag: 'registration', attrs: {}, content: (0, generics_1.encodeBigEndian)(creds.registrationId) },
|
|
151
|
+
{ tag: 'type', attrs: {}, content: Defaults_1.KEY_BUNDLE_TYPE },
|
|
194
152
|
{ tag: 'identity', attrs: {}, content: creds.signedIdentityKey.public },
|
|
195
|
-
{ tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => xmppPreKey(preKeys[+k], +k)) },
|
|
196
|
-
xmppSignedPreKey(creds.signedPreKey)
|
|
153
|
+
{ tag: 'list', attrs: {}, content: Object.keys(preKeys).map(k => (0, exports.xmppPreKey)(preKeys[+k], +k)) },
|
|
154
|
+
(0, exports.xmppSignedPreKey)(creds.signedPreKey)
|
|
197
155
|
]
|
|
198
156
|
};
|
|
199
157
|
return { update, node };
|
|
200
158
|
};
|
|
201
|
-
|
|
159
|
+
exports.getNextPreKeysNode = getNextPreKeysNode;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { AuthenticationState } from '../Types';
|
|
2
2
|
/**
|
|
3
3
|
* stores the full authentication state in a single folder.
|
|
4
4
|
* Far more efficient than singlefileauthstate
|
|
@@ -10,4 +10,3 @@ export declare const useMultiFileAuthState: (folder: string) => Promise<{
|
|
|
10
10
|
state: AuthenticationState;
|
|
11
11
|
saveCreds: () => Promise<void>;
|
|
12
12
|
}>;
|
|
13
|
-
//# sourceMappingURL=use-multi-file-auth-state.d.ts.map
|
|
@@ -1,23 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.useMultiFileAuthState = void 0;
|
|
7
|
+
const async_lock_1 = __importDefault(require("async-lock"));
|
|
8
|
+
const promises_1 = require("fs/promises");
|
|
9
|
+
const path_1 = require("path");
|
|
10
|
+
const WAProto_1 = require("../../WAProto");
|
|
11
|
+
const auth_utils_1 = require("./auth-utils");
|
|
12
|
+
const generics_1 = require("./generics");
|
|
7
13
|
// We need to lock files due to the fact that we are using async functions to read and write files
|
|
8
14
|
// https://github.com/WhiskeySockets/Baileys/issues/794
|
|
9
15
|
// https://github.com/nodejs/node/issues/26338
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
// Default pending is 1000, set it to infinity
|
|
17
|
+
// https://github.com/rogierschouten/async-lock/issues/63
|
|
18
|
+
const fileLock = new async_lock_1.default({ maxPending: Infinity });
|
|
19
|
+
|
|
20
|
+
// Helper function to log debug information if authDebug is enabled
|
|
21
|
+
const logDebug = (message, options) => {
|
|
22
|
+
if (options && typeof options === 'object' && options.authDebug === true) {
|
|
23
|
+
console.log(`[AUTH_DEBUG] ${message}`);
|
|
18
24
|
}
|
|
19
|
-
return mutex;
|
|
20
25
|
};
|
|
26
|
+
|
|
21
27
|
/**
|
|
22
28
|
* stores the full authentication state in a single folder.
|
|
23
29
|
* Far more efficient than singlefileauthstate
|
|
@@ -25,97 +31,137 @@ const getFileLock = (path) => {
|
|
|
25
31
|
* Again, I wouldn't endorse this for any production level use other than perhaps a bot.
|
|
26
32
|
* Would recommend writing an auth state for use with a proper SQL or No-SQL DB
|
|
27
33
|
* */
|
|
28
|
-
|
|
34
|
+
const useMultiFileAuthState = async (folder, options) => {
|
|
35
|
+
logDebug(`Initializing auth state in folder: ${folder}`, options);
|
|
29
36
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
-
const writeData =
|
|
31
|
-
const filePath = join(folder, fixFileName(file));
|
|
32
|
-
|
|
33
|
-
return
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
const writeData = (data, file) => {
|
|
38
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
39
|
+
logDebug(`Writing data to file: ${filePath}`, options);
|
|
40
|
+
return fileLock.acquire(filePath, () => {
|
|
41
|
+
logDebug(`Lock acquired for writing: ${filePath}`, options);
|
|
42
|
+
return (0, promises_1.writeFile)((0, path_1.join)(filePath), JSON.stringify(data, generics_1.BufferJSON.replacer))
|
|
43
|
+
.then(() => {
|
|
44
|
+
logDebug(`Successfully wrote data to: ${filePath}`, options);
|
|
45
|
+
})
|
|
46
|
+
.catch((error) => {
|
|
47
|
+
logDebug(`Error writing to file ${filePath}: ${error.message}`, options);
|
|
48
|
+
throw error;
|
|
49
|
+
});
|
|
40
50
|
});
|
|
41
51
|
};
|
|
52
|
+
|
|
42
53
|
const readData = async (file) => {
|
|
43
54
|
try {
|
|
44
|
-
const filePath = join(folder, fixFileName(file));
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return JSON.parse(data, BufferJSON.reviver);
|
|
50
|
-
}
|
|
51
|
-
finally {
|
|
52
|
-
release();
|
|
53
|
-
}
|
|
55
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
56
|
+
logDebug(`Attempting to read data from: ${filePath}`, options);
|
|
57
|
+
const data = await fileLock.acquire(filePath, () => {
|
|
58
|
+
logDebug(`Lock acquired for reading: ${filePath}`, options);
|
|
59
|
+
return (0, promises_1.readFile)(filePath, { encoding: 'utf-8' });
|
|
54
60
|
});
|
|
61
|
+
logDebug(`Successfully read data from: ${filePath}`, options);
|
|
62
|
+
return JSON.parse(data, generics_1.BufferJSON.reviver);
|
|
55
63
|
}
|
|
56
64
|
catch (error) {
|
|
65
|
+
logDebug(`Could not read file ${file}: ${error.message}`, options);
|
|
57
66
|
return null;
|
|
58
67
|
}
|
|
59
68
|
};
|
|
69
|
+
|
|
60
70
|
const removeData = async (file) => {
|
|
61
71
|
try {
|
|
62
|
-
const filePath = join(folder, fixFileName(file));
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
catch {
|
|
69
|
-
}
|
|
70
|
-
finally {
|
|
71
|
-
release();
|
|
72
|
-
}
|
|
72
|
+
const filePath = (0, path_1.join)(folder, fixFileName(file));
|
|
73
|
+
logDebug(`Attempting to remove file: ${filePath}`, options);
|
|
74
|
+
await fileLock.acquire(filePath, () => {
|
|
75
|
+
logDebug(`Lock acquired for removal: ${filePath}`, options);
|
|
76
|
+
return (0, promises_1.unlink)(filePath);
|
|
73
77
|
});
|
|
78
|
+
logDebug(`Successfully removed file: ${filePath}`, options);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
logDebug(`Error removing file ${file}: ${error.message}`, options);
|
|
74
82
|
}
|
|
75
|
-
catch { }
|
|
76
83
|
};
|
|
77
|
-
|
|
84
|
+
|
|
85
|
+
const folderInfo = await (0, promises_1.stat)(folder).catch(() => {
|
|
86
|
+
logDebug(`Folder ${folder} does not exist yet`, options);
|
|
87
|
+
});
|
|
88
|
+
|
|
78
89
|
if (folderInfo) {
|
|
79
90
|
if (!folderInfo.isDirectory()) {
|
|
91
|
+
logDebug(`Error: ${folder} is not a directory`, options);
|
|
80
92
|
throw new Error(`found something that is not a directory at ${folder}, either delete it or specify a different location`);
|
|
81
93
|
}
|
|
94
|
+
logDebug(`Using existing folder: ${folder}`, options);
|
|
82
95
|
}
|
|
83
96
|
else {
|
|
84
|
-
|
|
97
|
+
logDebug(`Creating folder: ${folder}`, options);
|
|
98
|
+
await (0, promises_1.mkdir)(folder, { recursive: true });
|
|
99
|
+
logDebug(`Successfully created folder: ${folder}`, options);
|
|
85
100
|
}
|
|
86
|
-
|
|
87
|
-
const
|
|
101
|
+
|
|
102
|
+
const fixFileName = (file) => {
|
|
103
|
+
var _a;
|
|
104
|
+
const fixedName = (_a = file === null || file === void 0 ? void 0 : file.replace(/\//g, '__')) === null || _a === void 0 ? void 0 : _a.replace(/:/g, '-');
|
|
105
|
+
logDebug(`Original filename: ${file}, Fixed filename: ${fixedName}`, options);
|
|
106
|
+
return fixedName;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
logDebug(`Reading credentials file`, options);
|
|
110
|
+
const creds = await readData('creds.json') || (0, auth_utils_1.initAuthCreds)();
|
|
111
|
+
if (!creds) {
|
|
112
|
+
logDebug(`No existing credentials found, initialized new auth credentials`, options);
|
|
113
|
+
} else {
|
|
114
|
+
logDebug(`Successfully loaded credentials`, options);
|
|
115
|
+
}
|
|
116
|
+
|
|
88
117
|
return {
|
|
89
118
|
state: {
|
|
90
119
|
creds,
|
|
91
120
|
keys: {
|
|
92
121
|
get: async (type, ids) => {
|
|
122
|
+
logDebug(`Getting keys of type: ${type}, ids: ${JSON.stringify(ids)}`, options);
|
|
93
123
|
const data = {};
|
|
94
124
|
await Promise.all(ids.map(async (id) => {
|
|
125
|
+
logDebug(`Fetching key: ${type}-${id}`, options);
|
|
95
126
|
let value = await readData(`${type}-${id}.json`);
|
|
96
127
|
if (type === 'app-state-sync-key' && value) {
|
|
97
|
-
|
|
128
|
+
logDebug(`Converting app-state-sync-key to protobuf for id: ${id}`, options);
|
|
129
|
+
value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
98
130
|
}
|
|
99
131
|
data[id] = value;
|
|
132
|
+
logDebug(`Key ${id} ${value ? 'found' : 'not found'}`, options);
|
|
100
133
|
}));
|
|
101
134
|
return data;
|
|
102
135
|
},
|
|
103
136
|
set: async (data) => {
|
|
137
|
+
logDebug(`Setting keys: ${JSON.stringify(Object.keys(data))}`, options);
|
|
104
138
|
const tasks = [];
|
|
105
139
|
for (const category in data) {
|
|
140
|
+
logDebug(`Processing category: ${category}`, options);
|
|
106
141
|
for (const id in data[category]) {
|
|
107
142
|
const value = data[category][id];
|
|
108
143
|
const file = `${category}-${id}.json`;
|
|
144
|
+
logDebug(`${value ? 'Setting' : 'Removing'} key: ${file}`, options);
|
|
109
145
|
tasks.push(value ? writeData(value, file) : removeData(file));
|
|
110
146
|
}
|
|
111
147
|
}
|
|
112
148
|
await Promise.all(tasks);
|
|
149
|
+
logDebug(`Successfully completed setting all keys`, options);
|
|
113
150
|
}
|
|
114
151
|
}
|
|
115
152
|
},
|
|
116
|
-
saveCreds:
|
|
117
|
-
|
|
118
|
-
|
|
153
|
+
saveCreds: () => {
|
|
154
|
+
logDebug(`Saving credentials to creds.json`, options);
|
|
155
|
+
return writeData(creds, 'creds.json')
|
|
156
|
+
.then(() => {
|
|
157
|
+
logDebug(`Successfully saved credentials`, options);
|
|
158
|
+
})
|
|
159
|
+
.catch((error) => {
|
|
160
|
+
logDebug(`Error saving credentials: ${error.message}`, options);
|
|
161
|
+
throw error;
|
|
162
|
+
});
|
|
163
|
+
},
|
|
164
|
+
cache: null
|
|
119
165
|
};
|
|
120
166
|
};
|
|
121
|
-
|
|
167
|
+
exports.useMultiFileAuthState = useMultiFileAuthState;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Logger } from 'pino';
|
|
2
|
+
import type { AuthenticationState } from '../Types';
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated use multi file auth state instead please
|
|
5
|
+
* stores the full authentication state in a single JSON file
|
|
6
|
+
*
|
|
7
|
+
* DO NOT USE IN A PROD ENVIRONMENT, only meant to serve as an example
|
|
8
|
+
* */
|
|
9
|
+
export declare const useSingleFileAuthState: (filename: string, logger?: Logger) => {
|
|
10
|
+
state: AuthenticationState;
|
|
11
|
+
saveState: () => void;
|
|
12
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useSingleFileAuthState = void 0;
|
|
4
|
+
const WAProto_1 = require("../../WAProto");
|
|
5
|
+
const auth_utils_1 = require("./auth-utils");
|
|
6
|
+
const generics_1 = require("./generics");
|
|
7
|
+
// useless key map only there to maintain backwards compatibility
|
|
8
|
+
// do not use in your own systems please
|
|
9
|
+
const KEY_MAP = {
|
|
10
|
+
'pre-key': 'preKeys',
|
|
11
|
+
'session': 'sessions',
|
|
12
|
+
'sender-key': 'senderKeys',
|
|
13
|
+
'app-state-sync-key': 'appStateSyncKeys',
|
|
14
|
+
'app-state-sync-version': 'appStateVersions',
|
|
15
|
+
'sender-key-memory': 'senderKeyMemory'
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated use multi file auth state instead please
|
|
19
|
+
* stores the full authentication state in a single JSON file
|
|
20
|
+
*
|
|
21
|
+
* DO NOT USE IN A PROD ENVIRONMENT, only meant to serve as an example
|
|
22
|
+
* */
|
|
23
|
+
const useSingleFileAuthState = (filename, logger) => {
|
|
24
|
+
// require fs here so that in case "fs" is not available -- the app does not crash
|
|
25
|
+
const { readFileSync, writeFileSync, existsSync } = require('fs');
|
|
26
|
+
let creds;
|
|
27
|
+
let keys = {};
|
|
28
|
+
// save the authentication state to a file
|
|
29
|
+
const saveState = () => {
|
|
30
|
+
logger && logger.trace('saving auth state');
|
|
31
|
+
writeFileSync(filename,
|
|
32
|
+
// BufferJSON replacer utility saves buffers nicely
|
|
33
|
+
JSON.stringify({ creds, keys }, generics_1.BufferJSON.replacer, 2));
|
|
34
|
+
};
|
|
35
|
+
if (existsSync(filename)) {
|
|
36
|
+
const result = JSON.parse(readFileSync(filename, { encoding: 'utf-8' }), generics_1.BufferJSON.reviver);
|
|
37
|
+
creds = result.creds;
|
|
38
|
+
keys = result.keys;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
creds = (0, auth_utils_1.initAuthCreds)();
|
|
42
|
+
keys = {};
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
state: {
|
|
46
|
+
creds,
|
|
47
|
+
keys: {
|
|
48
|
+
get: (type, ids) => {
|
|
49
|
+
const key = KEY_MAP[type];
|
|
50
|
+
return ids.reduce((dict, id) => {
|
|
51
|
+
var _a;
|
|
52
|
+
let value = (_a = keys[key]) === null || _a === void 0 ? void 0 : _a[id];
|
|
53
|
+
if (value) {
|
|
54
|
+
if (type === 'app-state-sync-key') {
|
|
55
|
+
value = WAProto_1.proto.Message.AppStateSyncKeyData.fromObject(value);
|
|
56
|
+
}
|
|
57
|
+
dict[id] = value;
|
|
58
|
+
}
|
|
59
|
+
return dict;
|
|
60
|
+
}, {});
|
|
61
|
+
},
|
|
62
|
+
set: (data) => {
|
|
63
|
+
for (const _key in data) {
|
|
64
|
+
const key = KEY_MAP[_key];
|
|
65
|
+
keys[key] = keys[key] || {};
|
|
66
|
+
Object.assign(keys[key], data[_key]);
|
|
67
|
+
}
|
|
68
|
+
saveState();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
saveState,
|
|
73
|
+
cache: null
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
exports.useSingleFileAuthState = useSingleFileAuthState;
|