@vanzxysenpai/baileys 0.0.0-stage → 0.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/CHANGELOG.md +30 -0
- package/LICENSE +25 -0
- package/NOTICE.md +158 -0
- package/README.md +5294 -2
- package/VanzxyBanner.js +134 -0
- package/WAProto/index.d.ts +13317 -0
- package/WAProto/index.js +147553 -0
- package/lib/Builders/A2UI.d.ts +131 -0
- package/lib/Builders/A2UI.js +343 -0
- package/lib/Builders/AIRich.d.ts +1021 -0
- package/lib/Builders/AIRich.js +2889 -0
- package/lib/Builders/Album.d.ts +51 -0
- package/lib/Builders/Album.js +99 -0
- package/lib/Builders/Button.d.ts +137449 -0
- package/lib/Builders/Button.js +1054 -0
- package/lib/Builders/ButtonV2.d.ts +43 -0
- package/lib/Builders/ButtonV2.js +175 -0
- package/lib/Builders/ButtonV3.d.ts +35 -0
- package/lib/Builders/ButtonV3.js +189 -0
- package/lib/Builders/Carousel.d.ts +68 -0
- package/lib/Builders/Carousel.js +161 -0
- package/lib/Builders/Event.d.ts +61 -0
- package/lib/Builders/Event.js +118 -0
- package/lib/Builders/Expiring.d.ts +17 -0
- package/lib/Builders/Expiring.js +27 -0
- package/lib/Builders/Poll.d.ts +63 -0
- package/lib/Builders/Poll.js +139 -0
- package/lib/Builders/VanzxyBaileys.d.ts +42 -0
- package/lib/Builders/VanzxyBaileys.js +110 -0
- package/lib/Builders/errors.d.ts +25 -0
- package/lib/Builders/errors.js +29 -0
- package/lib/Builders/index.d.ts +14 -0
- package/lib/Builders/index.js +23 -0
- package/lib/Builders/shared.d.ts +395 -0
- package/lib/Builders/shared.js +738 -0
- package/lib/Defaults/bot-jid.d.ts +1 -0
- package/lib/Defaults/bot-jid.js +1 -0
- package/lib/Defaults/index.d.ts +161 -0
- package/lib/Defaults/index.js +165 -0
- package/lib/Defaults/version.d.ts +1 -0
- package/lib/Defaults/version.js +1 -0
- package/lib/Framework/Bot.d.ts +865 -0
- package/lib/Framework/Bot.js +230 -0
- package/lib/Framework/Context.d.ts +17 -0
- package/lib/Framework/Context.js +90 -0
- package/lib/Framework/MediaManager.d.ts +15 -0
- package/lib/Framework/MediaManager.js +154 -0
- package/lib/Framework/SessionManager.d.ts +10 -0
- package/lib/Framework/SessionManager.js +34 -0
- package/lib/Framework/StatsManager.d.ts +20 -0
- package/lib/Framework/StatsManager.js +117 -0
- package/lib/Framework/Store/SQLiteStore.d.ts +13 -0
- package/lib/Framework/Store/SQLiteStore.js +68 -0
- package/lib/Framework/index.d.ts +6 -0
- package/lib/Framework/index.js +11 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +11 -0
- package/lib/Signal/Group/group-session-builder.d.ts +7 -0
- package/lib/Signal/Group/group-session-builder.js +29 -0
- package/lib/Signal/Group/group_cipher.d.ts +10 -0
- package/lib/Signal/Group/group_cipher.js +81 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +11 -0
- package/lib/Signal/Group/keyhelper.d.ts +6 -0
- package/lib/Signal/Group/keyhelper.js +17 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +25 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +65 -0
- package/lib/Signal/Group/sender-key-name.d.ts +11 -0
- package/lib/Signal/Group/sender-key-name.js +47 -0
- package/lib/Signal/Group/sender-key-record.d.ts +12 -0
- package/lib/Signal/Group/sender-key-record.js +40 -0
- package/lib/Signal/Group/sender-key-state.d.ts +16 -0
- package/lib/Signal/Group/sender-key-state.js +83 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/Group/sender-message-key.js +25 -0
- package/lib/Signal/libsignal.d.ts +58 -0
- package/lib/Signal/libsignal.js +436 -0
- package/lib/Signal/lid-mapping.d.ts +20 -0
- package/lib/Signal/lid-mapping.js +276 -0
- package/lib/Socket/Client/index.d.ts +2 -0
- package/lib/Socket/Client/index.js +2 -0
- package/lib/Socket/Client/types.d.ts +5 -0
- package/lib/Socket/Client/types.js +10 -0
- package/lib/Socket/Client/websocket.d.ts +12 -0
- package/lib/Socket/Client/websocket.js +53 -0
- package/lib/Socket/business.d.ts +674 -0
- package/lib/Socket/business.js +379 -0
- package/lib/Socket/chats.d.ts +137 -0
- package/lib/Socket/chats.js +1299 -0
- package/lib/Socket/communities.d.ts +805 -0
- package/lib/Socket/communities.js +454 -0
- package/lib/Socket/dugong.d.ts +118 -0
- package/lib/Socket/dugong.js +810 -0
- package/lib/Socket/groups.d.ts +287 -0
- package/lib/Socket/groups.js +386 -0
- package/lib/Socket/index.d.ts +826 -0
- package/lib/Socket/index.js +35 -0
- package/lib/Socket/messages-recv.d.ts +613 -0
- package/lib/Socket/messages-recv.js +1851 -0
- package/lib/Socket/messages-send.d.ts +608 -0
- package/lib/Socket/messages-send.js +1574 -0
- package/lib/Socket/mex-fallback.d.ts +51 -0
- package/lib/Socket/mex-fallback.js +97 -0
- package/lib/Socket/mex.d.ts +1 -0
- package/lib/Socket/mex.js +41 -0
- package/lib/Socket/newsletter-ext.d.ts +47 -0
- package/lib/Socket/newsletter-ext.js +262 -0
- package/lib/Socket/newsletter.d.ts +285 -0
- package/lib/Socket/newsletter.js +223 -0
- package/lib/Socket/socket.d.ts +60 -0
- package/lib/Socket/socket.js +1001 -0
- package/lib/Socket/username.d.ts +842 -0
- package/lib/Socket/username.js +156 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +3 -0
- package/lib/Store/make-in-memory-store.d.ts +62 -0
- package/lib/Store/make-in-memory-store.js +425 -0
- package/lib/Store/make-ordered-dictionary.d.ts +12 -0
- package/lib/Store/make-ordered-dictionary.js +78 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +23 -0
- package/lib/Types/Auth.d.ts +1 -0
- package/lib/Types/Auth.js +1 -0
- package/lib/Types/Bussines.d.ts +1 -0
- package/lib/Types/Bussines.js +1 -0
- package/lib/Types/Call.d.ts +1 -0
- package/lib/Types/Call.js +1 -0
- package/lib/Types/Chat.d.ts +1 -0
- package/lib/Types/Chat.js +7 -0
- package/lib/Types/Contact.d.ts +1 -0
- package/lib/Types/Contact.js +1 -0
- package/lib/Types/Events.d.ts +1 -0
- package/lib/Types/Events.js +1 -0
- package/lib/Types/GroupMetadata.d.ts +1 -0
- package/lib/Types/GroupMetadata.js +1 -0
- package/lib/Types/Label.d.ts +2 -0
- package/lib/Types/Label.js +24 -0
- package/lib/Types/LabelAssociation.d.ts +2 -0
- package/lib/Types/LabelAssociation.js +6 -0
- package/lib/Types/Message.d.ts +11 -0
- package/lib/Types/Message.js +17 -0
- package/lib/Types/Mex.d.ts +2 -0
- package/lib/Types/Mex.js +38 -0
- package/lib/Types/Product.d.ts +1 -0
- package/lib/Types/Product.js +1 -0
- package/lib/Types/RichType.d.ts +2 -0
- package/lib/Types/RichType.js +22 -0
- package/lib/Types/Signal.d.ts +1 -0
- package/lib/Types/Signal.js +1 -0
- package/lib/Types/Socket.d.ts +1 -0
- package/lib/Types/Socket.js +1 -0
- package/lib/Types/State.d.ts +5 -0
- package/lib/Types/State.js +55 -0
- package/lib/Types/USync.d.ts +1 -0
- package/lib/Types/USync.js +1 -0
- package/lib/Types/index.d.ts +15 -0
- package/lib/Types/index.js +27 -0
- package/lib/Utils/PersistentStore.d.ts +83 -0
- package/lib/Utils/PersistentStore.js +592 -0
- package/lib/Utils/anchor-guard.d.ts +31 -0
- package/lib/Utils/anchor-guard.js +329 -0
- package/lib/Utils/android-stanza-id.d.ts +4 -0
- package/lib/Utils/android-stanza-id.js +21 -0
- package/lib/Utils/anti-delete.d.ts +62 -0
- package/lib/Utils/anti-delete.js +212 -0
- package/lib/Utils/auth-secure.d.ts +180 -0
- package/lib/Utils/auth-secure.js +791 -0
- package/lib/Utils/auth-utils.d.ts +59 -0
- package/lib/Utils/auth-utils.js +326 -0
- package/lib/Utils/auto-reconnect.d.ts +8 -0
- package/lib/Utils/auto-reconnect.js +204 -0
- package/lib/Utils/auto-reply.d.ts +35 -0
- package/lib/Utils/auto-reply.js +152 -0
- package/lib/Utils/bad-mac-handler.d.ts +59 -0
- package/lib/Utils/bad-mac-handler.js +119 -0
- package/lib/Utils/baileys-event-stream.d.ts +5 -0
- package/lib/Utils/baileys-event-stream.js +62 -0
- package/lib/Utils/browser-utils.d.ts +9 -0
- package/lib/Utils/browser-utils.js +29 -0
- package/lib/Utils/business.d.ts +49 -0
- package/lib/Utils/business.js +236 -0
- package/lib/Utils/button-helper-utils.d.ts +59 -0
- package/lib/Utils/button-helper-utils.js +266 -0
- package/lib/Utils/button-sender.d.ts +164 -0
- package/lib/Utils/button-sender.js +845 -0
- package/lib/Utils/chat-control.d.ts +98 -0
- package/lib/Utils/chat-control.js +231 -0
- package/lib/Utils/chat-history-helpers.d.ts +4 -0
- package/lib/Utils/chat-history-helpers.js +70 -0
- package/lib/Utils/chat-utils.d.ts +408 -0
- package/lib/Utils/chat-utils.js +879 -0
- package/lib/Utils/companion-reg-client-utils.d.ts +4 -0
- package/lib/Utils/companion-reg-client-utils.js +39 -0
- package/lib/Utils/connection-watchdog.d.ts +10 -0
- package/lib/Utils/connection-watchdog.js +74 -0
- package/lib/Utils/crypto.d.ts +41 -0
- package/lib/Utils/crypto.js +145 -0
- package/lib/Utils/decode-wa-message.d.ts +83 -0
- package/lib/Utils/decode-wa-message.js +315 -0
- package/lib/Utils/disconnect-reason.d.ts +13 -0
- package/lib/Utils/disconnect-reason.js +36 -0
- package/lib/Utils/event-buffer.d.ts +12 -0
- package/lib/Utils/event-buffer.js +640 -0
- package/lib/Utils/fetch-timeout.d.ts +4 -0
- package/lib/Utils/fetch-timeout.js +14 -0
- package/lib/Utils/ffmpeg-path.d.ts +5 -0
- package/lib/Utils/ffmpeg-path.js +130 -0
- package/lib/Utils/generics.d.ts +79 -0
- package/lib/Utils/generics.js +426 -0
- package/lib/Utils/group-metadata-cache.d.ts +3 -0
- package/lib/Utils/group-metadata-cache.js +25 -0
- package/lib/Utils/group-status-detection.d.ts +5 -0
- package/lib/Utils/group-status-detection.js +114 -0
- package/lib/Utils/history.d.ts +91 -0
- package/lib/Utils/history.js +144 -0
- package/lib/Utils/html-app.d.ts +14 -0
- package/lib/Utils/html-app.js +97 -0
- package/lib/Utils/html-multiplayer.d.ts +8 -0
- package/lib/Utils/html-multiplayer.js +90 -0
- package/lib/Utils/humanizer.d.ts +8 -0
- package/lib/Utils/humanizer.js +74 -0
- package/lib/Utils/identity-change-handler.d.ts +13 -0
- package/lib/Utils/identity-change-handler.js +49 -0
- package/lib/Utils/index.d.ts +88 -0
- package/lib/Utils/index.js +93 -0
- package/lib/Utils/jid-tools.d.ts +3 -0
- package/lib/Utils/jid-tools.js +78 -0
- package/lib/Utils/link-preview-metadata.d.ts +47 -0
- package/lib/Utils/link-preview-metadata.js +90 -0
- package/lib/Utils/link-preview.d.ts +12 -0
- package/lib/Utils/link-preview.js +84 -0
- package/lib/Utils/lock-manager.d.ts +5 -0
- package/lib/Utils/lock-manager.js +50 -0
- package/lib/Utils/logger.d.ts +2 -0
- package/lib/Utils/logger.js +2 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/lt-hash.js +26 -0
- package/lib/Utils/make-mutex.d.ts +6 -0
- package/lib/Utils/make-mutex.js +32 -0
- package/lib/Utils/media-messages.d.ts +35 -0
- package/lib/Utils/media-messages.js +70 -0
- package/lib/Utils/media-processor.d.ts +6 -0
- package/lib/Utils/media-processor.js +174 -0
- package/lib/Utils/media-set.d.ts +6 -0
- package/lib/Utils/media-set.js +169 -0
- package/lib/Utils/message-kind.d.ts +26 -0
- package/lib/Utils/message-kind.js +138 -0
- package/lib/Utils/message-retry-manager.d.ts +79 -0
- package/lib/Utils/message-retry-manager.js +264 -0
- package/lib/Utils/message-search.d.ts +40 -0
- package/lib/Utils/message-search.js +181 -0
- package/lib/Utils/messages-media.d.ts +136 -0
- package/lib/Utils/messages-media.js +867 -0
- package/lib/Utils/messages.d.ts +66 -0
- package/lib/Utils/messages.js +2271 -0
- package/lib/Utils/meta-ai-msmsg.d.ts +3 -0
- package/lib/Utils/meta-ai-msmsg.js +132 -0
- package/lib/Utils/meta-ai.d.ts +4 -0
- package/lib/Utils/meta-ai.js +75 -0
- package/lib/Utils/migrate-auth-state.d.ts +23 -0
- package/lib/Utils/migrate-auth-state.js +126 -0
- package/lib/Utils/mini-app.d.ts +20 -0
- package/lib/Utils/mini-app.js +215 -0
- package/lib/Utils/mock-socket.d.ts +67 -0
- package/lib/Utils/mock-socket.js +254 -0
- package/lib/Utils/modern-messages.d.ts +64 -0
- package/lib/Utils/modern-messages.js +497 -0
- package/lib/Utils/native-flow.d.ts +19 -0
- package/lib/Utils/native-flow.js +112 -0
- package/lib/Utils/newsletter-status.d.ts +157 -0
- package/lib/Utils/newsletter-status.js +652 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +200 -0
- package/lib/Utils/offline-node-processor.d.ts +9 -0
- package/lib/Utils/offline-node-processor.js +39 -0
- package/lib/Utils/pairing-utils.d.ts +5 -0
- package/lib/Utils/pairing-utils.js +29 -0
- package/lib/Utils/passkey.d.ts +4 -0
- package/lib/Utils/passkey.js +11 -0
- package/lib/Utils/past-participants.d.ts +2 -0
- package/lib/Utils/past-participants.js +40 -0
- package/lib/Utils/payment-detection.d.ts +40 -0
- package/lib/Utils/payment-detection.js +213 -0
- package/lib/Utils/payment-guard.d.ts +28 -0
- package/lib/Utils/payment-guard.js +143 -0
- package/lib/Utils/payment-messages.d.ts +42 -0
- package/lib/Utils/payment-messages.js +161 -0
- package/lib/Utils/payment-utils.d.ts +75 -0
- package/lib/Utils/payment-utils.js +145 -0
- package/lib/Utils/phone-utils.d.ts +3 -0
- package/lib/Utils/phone-utils.js +29 -0
- package/lib/Utils/pre-key-manager.d.ts +25 -0
- package/lib/Utils/pre-key-manager.js +105 -0
- package/lib/Utils/process-message.d.ts +103 -0
- package/lib/Utils/process-message.js +868 -0
- package/lib/Utils/qr-terminal.d.ts +1 -0
- package/lib/Utils/qr-terminal.js +16 -0
- package/lib/Utils/reconnect-backoff.d.ts +25 -0
- package/lib/Utils/reconnect-backoff.js +47 -0
- package/lib/Utils/reporting-utils.d.ts +12 -0
- package/lib/Utils/reporting-utils.js +257 -0
- package/lib/Utils/rich-message-utils.d.ts +54 -0
- package/lib/Utils/rich-message-utils.js +435 -0
- package/lib/Utils/rich-messages.d.ts +298 -0
- package/lib/Utils/rich-messages.js +1145 -0
- package/lib/Utils/scheduled-message.d.ts +81 -0
- package/lib/Utils/scheduled-message.js +101 -0
- package/lib/Utils/scheduling.d.ts +59 -0
- package/lib/Utils/scheduling.js +139 -0
- package/lib/Utils/signal.d.ts +82 -0
- package/lib/Utils/signal.js +200 -0
- package/lib/Utils/stanza-ack.d.ts +16 -0
- package/lib/Utils/stanza-ack.js +37 -0
- package/lib/Utils/status-stickers.d.ts +79 -0
- package/lib/Utils/status-stickers.js +261 -0
- package/lib/Utils/status.d.ts +107 -0
- package/lib/Utils/status.js +131 -0
- package/lib/Utils/sticker-pack-maker.d.ts +20 -0
- package/lib/Utils/sticker-pack-maker.js +112 -0
- package/lib/Utils/stickerpack.d.ts +18 -0
- package/lib/Utils/stickerpack.js +316 -0
- package/lib/Utils/sync-action-utils.d.ts +2 -0
- package/lib/Utils/sync-action-utils.js +48 -0
- package/lib/Utils/tag.d.ts +8 -0
- package/lib/Utils/tag.js +45 -0
- package/lib/Utils/tc-token-utils.d.ts +29 -0
- package/lib/Utils/tc-token-utils.js +162 -0
- package/lib/Utils/templates.d.ts +86 -0
- package/lib/Utils/templates.js +148 -0
- package/lib/Utils/text-format.d.ts +13 -0
- package/lib/Utils/text-format.js +81 -0
- package/lib/Utils/text-tools.d.ts +3 -0
- package/lib/Utils/text-tools.js +38 -0
- package/lib/Utils/ttl-cache.d.ts +29 -0
- package/lib/Utils/ttl-cache.js +123 -0
- package/lib/Utils/use-cache-manager-auth-state.d.ts +22 -0
- package/lib/Utils/use-cache-manager-auth-state.js +86 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +20 -0
- package/lib/Utils/use-multi-file-auth-state.js +201 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +10 -0
- package/lib/Utils/use-single-file-auth-state.js +111 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts +13 -0
- package/lib/Utils/use-sqlite-auth-state.js +171 -0
- package/lib/Utils/username.d.ts +22 -0
- package/lib/Utils/username.js +59 -0
- package/lib/Utils/validate-connection.d.ts +43 -0
- package/lib/Utils/validate-connection.js +197 -0
- package/lib/Utils/vcard.d.ts +40 -0
- package/lib/Utils/vcard.js +92 -0
- package/lib/Utils/voice-note.d.ts +13 -0
- package/lib/Utils/voice-note.js +47 -0
- package/lib/VoIP/audio-feeder.d.ts +15 -0
- package/lib/VoIP/audio-feeder.js +132 -0
- package/lib/VoIP/index.d.ts +22 -0
- package/lib/VoIP/index.js +277 -0
- package/lib/VoIP/relay-transport.d.ts +16 -0
- package/lib/VoIP/relay-transport.js +559 -0
- package/lib/VoIP/signaling.d.ts +16 -0
- package/lib/VoIP/signaling.js +624 -0
- package/lib/VoIP/types.d.ts +11 -0
- package/lib/VoIP/types.js +17 -0
- package/lib/VoIP/wasm-engine.d.ts +28 -0
- package/lib/VoIP/wasm-engine.js +1214 -0
- package/lib/VoIP/worker-bootstrap.d.ts +1 -0
- package/lib/VoIP/worker-bootstrap.js +1042 -0
- package/lib/WABinary/constants.d.ts +61 -0
- package/lib/WABinary/constants.js +1466 -0
- package/lib/WABinary/decode.d.ts +9 -0
- package/lib/WABinary/decode.js +261 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/encode.js +219 -0
- package/lib/WABinary/generic-utils.d.ts +45 -0
- package/lib/WABinary/generic-utils.js +285 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +5 -0
- package/lib/WABinary/jid-utils.d.ts +32 -0
- package/lib/WABinary/jid-utils.js +102 -0
- package/lib/WABinary/types.d.ts +1 -0
- package/lib/WABinary/types.js +1 -0
- package/lib/WAM/BinaryInfo.d.ts +7 -0
- package/lib/WAM/BinaryInfo.js +9 -0
- package/lib/WAM/constants.d.ts +34926 -0
- package/lib/WAM/constants.js +22852 -0
- package/lib/WAM/encode.d.ts +1 -0
- package/lib/WAM/encode.js +149 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +3 -0
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.d.ts +43 -0
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +51 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +29 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +60 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +28 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +28 -0
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.d.ts +20 -0
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +23 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.d.ts +14 -0
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +24 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +49 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
- package/lib/WAUSync/Protocols/index.d.ts +12 -0
- package/lib/WAUSync/Protocols/index.js +12 -0
- package/lib/WAUSync/USyncQuery.d.ts +25 -0
- package/lib/WAUSync/USyncQuery.js +140 -0
- package/lib/WAUSync/USyncUser.d.ts +24 -0
- package/lib/WAUSync/USyncUser.js +47 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +3 -0
- package/lib/assets/wasm/loader.js +5 -0
- package/lib/assets/wasm/whatsapp.wasm +0 -0
- package/lib/assets/wasm/worker-modules.js +273 -0
- package/lib/exports-extra.d.ts +45 -0
- package/lib/exports-extra.js +47 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.js +24 -0
- package/package.json +161 -4
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export const SCHEDULED_MSG_META_TYPE: "scheduled_message";
|
|
2
|
+
export const SCHEDULED_MSG_MAX_PER_CHAT: 30;
|
|
3
|
+
export const SCHEDULED_MSG_MAX_MEDIA: 1;
|
|
4
|
+
export const SCHEDULED_MSG_RESOURCE_LIMIT_NACK_CODE: 419;
|
|
5
|
+
export const SCHEDULED_MSG_REVEAL_KEY_BYTES: 32;
|
|
6
|
+
export const SCHEDULED_MSG_REVEAL_KEY_IV_BYTES: 12;
|
|
7
|
+
export const SCHEDULED_MSG_REVEAL_KEY_RETENTION_DAYS: 30;
|
|
8
|
+
export const SCHEDULED_MSG_TAG_BYTES: 16;
|
|
9
|
+
export const SCHEDULED_MSG_WINDOW: Readonly<{
|
|
10
|
+
chat: {
|
|
11
|
+
minSeconds: number;
|
|
12
|
+
maxSeconds: number;
|
|
13
|
+
};
|
|
14
|
+
newsletter: {
|
|
15
|
+
minSeconds: number;
|
|
16
|
+
maxSeconds: number;
|
|
17
|
+
};
|
|
18
|
+
}>;
|
|
19
|
+
export function generateRevealKey(): any;
|
|
20
|
+
export function generateRevealKeyId(): any;
|
|
21
|
+
export function encryptWithRevealKey(plaintext: any, revealKey: any): {
|
|
22
|
+
encIv: any;
|
|
23
|
+
encPayload: any;
|
|
24
|
+
};
|
|
25
|
+
export function decryptWithRevealKey(encPayload: any, encIv: any, revealKey: any): any;
|
|
26
|
+
export function buildConditionalRevealMessage(opts1: { [key: string]: any;
|
|
27
|
+
encPayload: any;
|
|
28
|
+
encIv: any;
|
|
29
|
+
revealKeyId: any;
|
|
30
|
+
}): {
|
|
31
|
+
conditionalRevealMessage: {
|
|
32
|
+
conditionalRevealMessageType: proto.Message.ConditionalRevealMessage.ConditionalRevealMessageType;
|
|
33
|
+
encPayload: any;
|
|
34
|
+
encIv: any;
|
|
35
|
+
revealKeyId: any;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export function encodeScheduledMessage(message: any, revealKey?: any): {
|
|
39
|
+
revealKey: any;
|
|
40
|
+
revealKeyId: any;
|
|
41
|
+
encIv: any;
|
|
42
|
+
encPayload: any;
|
|
43
|
+
message: {
|
|
44
|
+
conditionalRevealMessage: {
|
|
45
|
+
conditionalRevealMessageType: proto.Message.ConditionalRevealMessage.ConditionalRevealMessageType;
|
|
46
|
+
encPayload: any;
|
|
47
|
+
encIv: any;
|
|
48
|
+
revealKeyId: any;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export function decodeScheduledMessage(conditionalRevealMessage: any, revealKey: any): proto.Message;
|
|
53
|
+
export function buildScheduledMsgMetaNode(opts2: { [key: string]: any;
|
|
54
|
+
kind?: string;
|
|
55
|
+
scheduledTimestampS: any;
|
|
56
|
+
revealKeyId: any;
|
|
57
|
+
revealKey: any;
|
|
58
|
+
}): {
|
|
59
|
+
tag: string;
|
|
60
|
+
attrs: {
|
|
61
|
+
type: string;
|
|
62
|
+
};
|
|
63
|
+
content: {
|
|
64
|
+
tag: string;
|
|
65
|
+
attrs: {
|
|
66
|
+
rkid: any;
|
|
67
|
+
};
|
|
68
|
+
content: any;
|
|
69
|
+
}[];
|
|
70
|
+
};
|
|
71
|
+
export function buildUnscheduleProtocolMessage(key: any): {
|
|
72
|
+
protocolMessage: {
|
|
73
|
+
key: any;
|
|
74
|
+
type: proto.Message.ProtocolMessage.Type;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
export function isScheduledTimeValid(scheduledTimestampS: any, nowSeconds?: number, window?: {
|
|
78
|
+
minSeconds: number;
|
|
79
|
+
maxSeconds: number;
|
|
80
|
+
}): boolean;
|
|
81
|
+
import { proto } from '../../WAProto/index.js';
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// Vanz@Port --- ported from @blurose/baileys 1.1.23 (scheduled-message.js). Creator credits untouched. See NOTICE.md.
|
|
2
|
+
import { createCipheriv, createDecipheriv, randomBytes, randomUUID } from 'crypto';
|
|
3
|
+
import { proto } from '../../WAProto/index.js';
|
|
4
|
+
export const SCHEDULED_MSG_META_TYPE = 'scheduled_message';
|
|
5
|
+
export const SCHEDULED_MSG_MAX_PER_CHAT = 30;
|
|
6
|
+
export const SCHEDULED_MSG_MAX_MEDIA = 1;
|
|
7
|
+
export const SCHEDULED_MSG_RESOURCE_LIMIT_NACK_CODE = 419;
|
|
8
|
+
export const SCHEDULED_MSG_REVEAL_KEY_BYTES = 32;
|
|
9
|
+
export const SCHEDULED_MSG_REVEAL_KEY_IV_BYTES = 12;
|
|
10
|
+
export const SCHEDULED_MSG_REVEAL_KEY_RETENTION_DAYS = 30;
|
|
11
|
+
export const SCHEDULED_MSG_TAG_BYTES = 16;
|
|
12
|
+
export const SCHEDULED_MSG_WINDOW = Object.freeze({
|
|
13
|
+
chat: { minSeconds: 600, maxSeconds: 1209600 },
|
|
14
|
+
newsletter: { minSeconds: 600, maxSeconds: 2592000 }
|
|
15
|
+
});
|
|
16
|
+
export const generateRevealKey = () => randomBytes(SCHEDULED_MSG_REVEAL_KEY_BYTES);
|
|
17
|
+
export const generateRevealKeyId = () => randomUUID();
|
|
18
|
+
export const encryptWithRevealKey = (plaintext, revealKey) => {
|
|
19
|
+
const key = Buffer.from(revealKey);
|
|
20
|
+
if (key.length !== SCHEDULED_MSG_REVEAL_KEY_BYTES) {
|
|
21
|
+
throw new TypeError(`reveal key must be ${SCHEDULED_MSG_REVEAL_KEY_BYTES} bytes`);
|
|
22
|
+
}
|
|
23
|
+
const encIv = randomBytes(SCHEDULED_MSG_REVEAL_KEY_IV_BYTES);
|
|
24
|
+
const cipher = createCipheriv('aes-256-gcm', key, encIv);
|
|
25
|
+
const body = Buffer.concat([cipher.update(Buffer.from(plaintext)), cipher.final()]);
|
|
26
|
+
return { encIv, encPayload: Buffer.concat([body, cipher.getAuthTag()]) };
|
|
27
|
+
};
|
|
28
|
+
export const decryptWithRevealKey = (encPayload, encIv, revealKey) => {
|
|
29
|
+
const key = Buffer.from(revealKey);
|
|
30
|
+
const payload = Buffer.from(encPayload);
|
|
31
|
+
if (payload.length < SCHEDULED_MSG_TAG_BYTES) {
|
|
32
|
+
throw new TypeError('encrypted payload is too short to carry an auth tag');
|
|
33
|
+
}
|
|
34
|
+
const decipher = createDecipheriv('aes-256-gcm', key, Buffer.from(encIv));
|
|
35
|
+
decipher.setAuthTag(payload.subarray(payload.length - SCHEDULED_MSG_TAG_BYTES));
|
|
36
|
+
return Buffer.concat([
|
|
37
|
+
decipher.update(payload.subarray(0, payload.length - SCHEDULED_MSG_TAG_BYTES)),
|
|
38
|
+
decipher.final()
|
|
39
|
+
]);
|
|
40
|
+
};
|
|
41
|
+
export const buildConditionalRevealMessage = ({ encPayload, encIv, revealKeyId }) => ({
|
|
42
|
+
conditionalRevealMessage: {
|
|
43
|
+
conditionalRevealMessageType: proto.Message.ConditionalRevealMessage.ConditionalRevealMessageType.SCHEDULED_MESSAGE,
|
|
44
|
+
encPayload: Buffer.from(encPayload),
|
|
45
|
+
encIv: Buffer.from(encIv),
|
|
46
|
+
revealKeyId
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
export const encodeScheduledMessage = (message, revealKey = generateRevealKey()) => {
|
|
50
|
+
const plaintext = proto.Message.encode(proto.Message.fromObject(message)).finish();
|
|
51
|
+
const { encIv, encPayload } = encryptWithRevealKey(plaintext, revealKey);
|
|
52
|
+
const revealKeyId = generateRevealKeyId();
|
|
53
|
+
return {
|
|
54
|
+
revealKey,
|
|
55
|
+
revealKeyId,
|
|
56
|
+
encIv,
|
|
57
|
+
encPayload,
|
|
58
|
+
message: buildConditionalRevealMessage({ encPayload, encIv, revealKeyId })
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
export const decodeScheduledMessage = (conditionalRevealMessage, revealKey) => {
|
|
62
|
+
const inner = conditionalRevealMessage?.conditionalRevealMessage ?? conditionalRevealMessage;
|
|
63
|
+
if (!inner?.encPayload || !inner?.encIv) {
|
|
64
|
+
throw new TypeError('conditionalRevealMessage is missing encPayload or encIv');
|
|
65
|
+
}
|
|
66
|
+
return proto.Message.decode(decryptWithRevealKey(inner.encPayload, inner.encIv, revealKey));
|
|
67
|
+
};
|
|
68
|
+
export const buildScheduledMsgMetaNode = ({ kind = 'schedule', scheduledTimestampS, revealKeyId, revealKey }) => {
|
|
69
|
+
if (!revealKeyId) {
|
|
70
|
+
throw new TypeError('revealKeyId is required');
|
|
71
|
+
}
|
|
72
|
+
if (kind === 'schedule' && !revealKey) {
|
|
73
|
+
throw new TypeError('scheduling requires the reveal key');
|
|
74
|
+
}
|
|
75
|
+
const attrs = { type: SCHEDULED_MSG_META_TYPE };
|
|
76
|
+
if (kind === 'schedule') {
|
|
77
|
+
if (scheduledTimestampS === undefined || !Number.isFinite(Number(scheduledTimestampS))) {
|
|
78
|
+
throw new TypeError('scheduledTimestampS must be a unix timestamp in seconds');
|
|
79
|
+
}
|
|
80
|
+
attrs.st = String(Math.floor(Number(scheduledTimestampS)));
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
tag: 'meta',
|
|
84
|
+
attrs,
|
|
85
|
+
content: [{
|
|
86
|
+
tag: 'key',
|
|
87
|
+
attrs: { rkid: revealKeyId },
|
|
88
|
+
content: kind === 'schedule' ? Buffer.from(revealKey) : undefined
|
|
89
|
+
}]
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
export const buildUnscheduleProtocolMessage = (key) => ({
|
|
93
|
+
protocolMessage: {
|
|
94
|
+
key,
|
|
95
|
+
type: proto.Message.ProtocolMessage.Type.MESSAGE_UNSCHEDULE
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
export const isScheduledTimeValid = (scheduledTimestampS, nowSeconds = Math.floor(Date.now() / 1000), window = SCHEDULED_MSG_WINDOW.chat) => {
|
|
99
|
+
const rounded = Math.floor(nowSeconds / 60) * 60;
|
|
100
|
+
return scheduledTimestampS - rounded >= window.minSeconds && scheduledTimestampS - nowSeconds <= window.maxSeconds;
|
|
101
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ported from Bail-master addons/scheduling.ts + message-scheduler.ts.
|
|
3
|
+
* Bail-master shipped these as two separate, overlapping schedulers (one class-based
|
|
4
|
+
* with polling, one function-based with setTimeout + repeat support). Merged here into
|
|
5
|
+
* a single class-based scheduler so multiple independent instances can be bound to
|
|
6
|
+
* different sendMessage functions (e.g. multi-session bots), while keeping the
|
|
7
|
+
* repeat-interval/maxRepeats feature from the function-based version.
|
|
8
|
+
*/
|
|
9
|
+
export class MessageScheduler {
|
|
10
|
+
constructor(sendMessage: any, options?: {});
|
|
11
|
+
queue: Map<any, any>;
|
|
12
|
+
timer: any;
|
|
13
|
+
sendMessage: any;
|
|
14
|
+
options: {
|
|
15
|
+
maxQueue: any;
|
|
16
|
+
checkInterval: any;
|
|
17
|
+
onSent: any;
|
|
18
|
+
onFailed: any;
|
|
19
|
+
};
|
|
20
|
+
generateId(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Schedule a message for a specific Date. Pass `repeatIntervalMs` to
|
|
23
|
+
* re-queue the job that many ms after each send (optionally capped by
|
|
24
|
+
* `maxRepeats`).
|
|
25
|
+
*/
|
|
26
|
+
schedule(jid: any, content: any, scheduledTime: any, repeatOptions: any): {
|
|
27
|
+
id: string;
|
|
28
|
+
jid: any;
|
|
29
|
+
content: any;
|
|
30
|
+
scheduledTime: any;
|
|
31
|
+
createdAt: Date;
|
|
32
|
+
status: string;
|
|
33
|
+
repeatIntervalMs: any;
|
|
34
|
+
maxRepeats: any;
|
|
35
|
+
repeatCount: number;
|
|
36
|
+
};
|
|
37
|
+
scheduleDelay(jid: any, content: any, delayMs: any, repeatOptions: any): {
|
|
38
|
+
id: string;
|
|
39
|
+
jid: any;
|
|
40
|
+
content: any;
|
|
41
|
+
scheduledTime: any;
|
|
42
|
+
createdAt: Date;
|
|
43
|
+
status: string;
|
|
44
|
+
repeatIntervalMs: any;
|
|
45
|
+
maxRepeats: any;
|
|
46
|
+
repeatCount: number;
|
|
47
|
+
};
|
|
48
|
+
cancel(id: any): boolean;
|
|
49
|
+
cancelForJid(jid: any): number;
|
|
50
|
+
getPending(): any[];
|
|
51
|
+
get(id: any): any;
|
|
52
|
+
clearAll(): number;
|
|
53
|
+
processQueue(): Promise<void>;
|
|
54
|
+
ensureTimerRunning(): void;
|
|
55
|
+
stopTimer(): void;
|
|
56
|
+
stop(): void;
|
|
57
|
+
start(): void;
|
|
58
|
+
}
|
|
59
|
+
export function createMessageScheduler(sendMessage: any, options: any): MessageScheduler;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ported from Bail-master addons/scheduling.ts + message-scheduler.ts.
|
|
3
|
+
* Bail-master shipped these as two separate, overlapping schedulers (one class-based
|
|
4
|
+
* with polling, one function-based with setTimeout + repeat support). Merged here into
|
|
5
|
+
* a single class-based scheduler so multiple independent instances can be bound to
|
|
6
|
+
* different sendMessage functions (e.g. multi-session bots), while keeping the
|
|
7
|
+
* repeat-interval/maxRepeats feature from the function-based version.
|
|
8
|
+
*/
|
|
9
|
+
export class MessageScheduler {
|
|
10
|
+
queue = new Map();
|
|
11
|
+
timer = null;
|
|
12
|
+
sendMessage;
|
|
13
|
+
options;
|
|
14
|
+
constructor(sendMessage, options = {}) {
|
|
15
|
+
this.sendMessage = sendMessage;
|
|
16
|
+
this.options = {
|
|
17
|
+
maxQueue: options.maxQueue ?? 1000,
|
|
18
|
+
checkInterval: options.checkInterval ?? 1000,
|
|
19
|
+
onSent: options.onSent ?? (() => { }),
|
|
20
|
+
onFailed: options.onFailed ?? (() => { })
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
generateId() {
|
|
24
|
+
return `sched_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Schedule a message for a specific Date. Pass `repeatIntervalMs` to
|
|
28
|
+
* re-queue the job that many ms after each send (optionally capped by
|
|
29
|
+
* `maxRepeats`).
|
|
30
|
+
*/
|
|
31
|
+
schedule(jid, content, scheduledTime, repeatOptions) {
|
|
32
|
+
if (this.queue.size >= this.options.maxQueue)
|
|
33
|
+
throw new Error(`Maximum queue size (${this.options.maxQueue}) reached`);
|
|
34
|
+
if (scheduledTime.getTime() <= Date.now())
|
|
35
|
+
throw new Error('Scheduled time must be in the future');
|
|
36
|
+
const scheduled = {
|
|
37
|
+
id: this.generateId(),
|
|
38
|
+
jid,
|
|
39
|
+
content,
|
|
40
|
+
scheduledTime,
|
|
41
|
+
createdAt: new Date(),
|
|
42
|
+
status: 'pending',
|
|
43
|
+
repeatIntervalMs: repeatOptions?.repeatIntervalMs,
|
|
44
|
+
maxRepeats: repeatOptions?.maxRepeats,
|
|
45
|
+
repeatCount: 0
|
|
46
|
+
};
|
|
47
|
+
this.queue.set(scheduled.id, scheduled);
|
|
48
|
+
this.ensureTimerRunning();
|
|
49
|
+
return scheduled;
|
|
50
|
+
}
|
|
51
|
+
scheduleDelay(jid, content, delayMs, repeatOptions) {
|
|
52
|
+
return this.schedule(jid, content, new Date(Date.now() + delayMs), repeatOptions);
|
|
53
|
+
}
|
|
54
|
+
cancel(id) {
|
|
55
|
+
const s = this.queue.get(id);
|
|
56
|
+
if (s?.status === 'pending') {
|
|
57
|
+
s.status = 'cancelled';
|
|
58
|
+
this.queue.delete(id);
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
cancelForJid(jid) {
|
|
64
|
+
let cancelled = 0;
|
|
65
|
+
for (const [id, s] of this.queue) {
|
|
66
|
+
if (s.jid === jid && s.status === 'pending') {
|
|
67
|
+
s.status = 'cancelled';
|
|
68
|
+
this.queue.delete(id);
|
|
69
|
+
cancelled++;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return cancelled;
|
|
73
|
+
}
|
|
74
|
+
getPending() {
|
|
75
|
+
return Array.from(this.queue.values()).filter((s) => s.status === 'pending');
|
|
76
|
+
}
|
|
77
|
+
get(id) {
|
|
78
|
+
return this.queue.get(id);
|
|
79
|
+
}
|
|
80
|
+
clearAll() {
|
|
81
|
+
const count = this.queue.size;
|
|
82
|
+
this.queue.clear();
|
|
83
|
+
this.stopTimer();
|
|
84
|
+
return count;
|
|
85
|
+
}
|
|
86
|
+
async processQueue() {
|
|
87
|
+
const now = Date.now();
|
|
88
|
+
for (const [id, s] of this.queue) {
|
|
89
|
+
if (s.status !== 'pending')
|
|
90
|
+
continue;
|
|
91
|
+
if (s.scheduledTime.getTime() > now)
|
|
92
|
+
continue;
|
|
93
|
+
try {
|
|
94
|
+
const message = await this.sendMessage(s.jid, s.content);
|
|
95
|
+
s.messageId = message?.key?.id ?? undefined;
|
|
96
|
+
this.options.onSent(s, message);
|
|
97
|
+
// Handle repeating jobs — re-arm instead of removing from the queue.
|
|
98
|
+
if (s.repeatIntervalMs && s.repeatIntervalMs > 0) {
|
|
99
|
+
const nextCount = (s.repeatCount ?? 0) + 1;
|
|
100
|
+
if (s.maxRepeats === undefined || nextCount < s.maxRepeats) {
|
|
101
|
+
s.repeatCount = nextCount;
|
|
102
|
+
s.scheduledTime = new Date(Date.now() + s.repeatIntervalMs);
|
|
103
|
+
s.status = 'pending';
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
s.status = 'sent';
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
s.status = 'failed';
|
|
111
|
+
s.error = error?.message || String(error);
|
|
112
|
+
this.options.onFailed(s, error);
|
|
113
|
+
}
|
|
114
|
+
this.queue.delete(id);
|
|
115
|
+
}
|
|
116
|
+
if (this.queue.size === 0)
|
|
117
|
+
this.stopTimer();
|
|
118
|
+
}
|
|
119
|
+
ensureTimerRunning() {
|
|
120
|
+
if (!this.timer) {
|
|
121
|
+
this.timer = setInterval(() => this.processQueue(), this.options.checkInterval);
|
|
122
|
+
this.timer?.unref?.();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
stopTimer() {
|
|
126
|
+
if (this.timer) {
|
|
127
|
+
clearInterval(this.timer);
|
|
128
|
+
this.timer = null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
stop() {
|
|
132
|
+
this.stopTimer();
|
|
133
|
+
}
|
|
134
|
+
start() {
|
|
135
|
+
if (this.queue.size > 0)
|
|
136
|
+
this.ensureTimerRunning();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
export const createMessageScheduler = (sendMessage, options) => new MessageScheduler(sendMessage, options);
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export function createSignalIdentity(wid: any, accountSignatureKey: any): {
|
|
2
|
+
identifier: {
|
|
3
|
+
name: any;
|
|
4
|
+
deviceId: number;
|
|
5
|
+
};
|
|
6
|
+
identifierKey: any;
|
|
7
|
+
};
|
|
8
|
+
export function getPreKeys(opts1: { [key: string]: any;
|
|
9
|
+
get: any;
|
|
10
|
+
}, min: any, limit: any): Promise<any>;
|
|
11
|
+
export function generateOrGetPreKeys(creds: any, range: any): {
|
|
12
|
+
newPreKeys: {};
|
|
13
|
+
lastPreKeyId: number;
|
|
14
|
+
preKeysRange: any[];
|
|
15
|
+
};
|
|
16
|
+
export function xmppSignedPreKey(key: any): {
|
|
17
|
+
tag: string;
|
|
18
|
+
attrs: {};
|
|
19
|
+
content: {
|
|
20
|
+
tag: string;
|
|
21
|
+
attrs: {};
|
|
22
|
+
content: any;
|
|
23
|
+
}[];
|
|
24
|
+
};
|
|
25
|
+
export function xmppPreKey(pair: any, id: any): {
|
|
26
|
+
tag: string;
|
|
27
|
+
attrs: {};
|
|
28
|
+
content: {
|
|
29
|
+
tag: string;
|
|
30
|
+
attrs: {};
|
|
31
|
+
content: any;
|
|
32
|
+
}[];
|
|
33
|
+
};
|
|
34
|
+
export function extractE2ESessionFromRetryReceipt(receipt: any): {
|
|
35
|
+
registrationId: number;
|
|
36
|
+
identityKey: any;
|
|
37
|
+
signedPreKey: {
|
|
38
|
+
keyId: number;
|
|
39
|
+
publicKey: any;
|
|
40
|
+
signature: any;
|
|
41
|
+
};
|
|
42
|
+
preKey: {
|
|
43
|
+
keyId: number;
|
|
44
|
+
publicKey: any;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export function parseAndInjectE2ESessions(node: any, repository: any): Promise<void>;
|
|
48
|
+
export function extractDeviceJids(result: any, myJid: any, myLid: any, excludeZeroDevices: any): {
|
|
49
|
+
user: any;
|
|
50
|
+
device: any;
|
|
51
|
+
domainType: any;
|
|
52
|
+
server: any;
|
|
53
|
+
}[];
|
|
54
|
+
export function getNextPreKeys(opts2: { [key: string]: any;
|
|
55
|
+
creds: any;
|
|
56
|
+
keys: any;
|
|
57
|
+
}, count: any): Promise<{
|
|
58
|
+
update: {
|
|
59
|
+
nextPreKeyId: number;
|
|
60
|
+
firstUnuploadedPreKeyId: number;
|
|
61
|
+
};
|
|
62
|
+
preKeys: any;
|
|
63
|
+
}>;
|
|
64
|
+
export function getNextPreKeysNode(state: any, count: any): Promise<{
|
|
65
|
+
update: {
|
|
66
|
+
nextPreKeyId: number;
|
|
67
|
+
firstUnuploadedPreKeyId: number;
|
|
68
|
+
};
|
|
69
|
+
node: {
|
|
70
|
+
tag: string;
|
|
71
|
+
attrs: {
|
|
72
|
+
xmlns: string;
|
|
73
|
+
type: string;
|
|
74
|
+
to: "@s.whatsapp.net";
|
|
75
|
+
};
|
|
76
|
+
content: {
|
|
77
|
+
tag: string;
|
|
78
|
+
attrs: {};
|
|
79
|
+
content: any;
|
|
80
|
+
}[];
|
|
81
|
+
};
|
|
82
|
+
}>;
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { KEY_BUNDLE_TYPE } from '../Defaults/index.js';
|
|
2
|
+
import { assertNodeErrorFree, getBinaryNodeChild, getBinaryNodeChildBuffer, getBinaryNodeChildren, getBinaryNodeChildUInt, getServerFromDomainType, jidDecode, S_WHATSAPP_NET, WAJIDDomains } from '../WABinary/index.js';
|
|
3
|
+
import { Curve, generateSignalPubKey } from './crypto.js';
|
|
4
|
+
import { encodeBigEndian } from './generics.js';
|
|
5
|
+
function chunk(array, size) {
|
|
6
|
+
const chunks = [];
|
|
7
|
+
for (let i = 0; i < array.length; i += size) {
|
|
8
|
+
chunks.push(array.slice(i, i + size));
|
|
9
|
+
}
|
|
10
|
+
return chunks;
|
|
11
|
+
}
|
|
12
|
+
export const createSignalIdentity = (wid, accountSignatureKey) => {
|
|
13
|
+
return {
|
|
14
|
+
identifier: { name: wid, deviceId: 0 },
|
|
15
|
+
identifierKey: generateSignalPubKey(accountSignatureKey)
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export const getPreKeys = async ({ get }, min, limit) => {
|
|
19
|
+
const idList = [];
|
|
20
|
+
for (let id = min; id < limit; id++) {
|
|
21
|
+
idList.push(id.toString());
|
|
22
|
+
}
|
|
23
|
+
return get('pre-key', idList);
|
|
24
|
+
};
|
|
25
|
+
export const generateOrGetPreKeys = (creds, range) => {
|
|
26
|
+
const avaliable = creds.nextPreKeyId - creds.firstUnuploadedPreKeyId;
|
|
27
|
+
const remaining = range - avaliable;
|
|
28
|
+
const lastPreKeyId = creds.nextPreKeyId + remaining - 1;
|
|
29
|
+
const newPreKeys = {};
|
|
30
|
+
if (remaining > 0) {
|
|
31
|
+
for (let i = creds.nextPreKeyId; i <= lastPreKeyId; i++) {
|
|
32
|
+
newPreKeys[i] = Curve.generateKeyPair();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
newPreKeys,
|
|
37
|
+
lastPreKeyId,
|
|
38
|
+
preKeysRange: [creds.firstUnuploadedPreKeyId, range]
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
export const xmppSignedPreKey = (key) => ({
|
|
42
|
+
tag: 'skey',
|
|
43
|
+
attrs: {},
|
|
44
|
+
content: [
|
|
45
|
+
{ tag: 'id', attrs: {}, content: encodeBigEndian(key.keyId, 3) },
|
|
46
|
+
{ tag: 'value', attrs: {}, content: key.keyPair.public },
|
|
47
|
+
{ tag: 'signature', attrs: {}, content: key.signature }
|
|
48
|
+
]
|
|
49
|
+
});
|
|
50
|
+
export const xmppPreKey = (pair, id) => ({
|
|
51
|
+
tag: 'key',
|
|
52
|
+
attrs: {},
|
|
53
|
+
content: [
|
|
54
|
+
{ tag: 'id', attrs: {}, content: encodeBigEndian(id, 3) },
|
|
55
|
+
{ tag: 'value', attrs: {}, content: pair.public }
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
const isValidUInt = (n) => typeof n === 'number' && Number.isInteger(n);
|
|
59
|
+
export const extractE2ESessionFromRetryReceipt = (receipt) => {
|
|
60
|
+
const keysNode = getBinaryNodeChild(receipt, 'keys');
|
|
61
|
+
if (!keysNode)
|
|
62
|
+
return null;
|
|
63
|
+
const typeBuf = getBinaryNodeChildBuffer(keysNode, 'type');
|
|
64
|
+
if (!typeBuf || typeBuf.length !== 1 || typeBuf[0] !== KEY_BUNDLE_TYPE[0])
|
|
65
|
+
return null;
|
|
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');
|
|
109
|
+
for (const node of nodes) {
|
|
110
|
+
assertNodeErrorFree(node);
|
|
111
|
+
}
|
|
112
|
+
// Most of the work in repository.injectE2ESession is CPU intensive, not IO
|
|
113
|
+
// So Promise.all doesn't really help here,
|
|
114
|
+
// but blocks even loop if we're using it inside keys.transaction, and it makes it "sync" actually
|
|
115
|
+
// This way we chunk it in smaller parts and between those parts we can yield to the event loop
|
|
116
|
+
// It's rare case when you need to E2E sessions for so many users, but it's possible
|
|
117
|
+
const chunkSize = 100;
|
|
118
|
+
const chunks = chunk(nodes, chunkSize);
|
|
119
|
+
for (const nodesChunk of chunks) {
|
|
120
|
+
for (const node of nodesChunk) {
|
|
121
|
+
const signedKey = getBinaryNodeChild(node, 'skey');
|
|
122
|
+
const key = getBinaryNodeChild(node, 'key');
|
|
123
|
+
const identity = getBinaryNodeChildBuffer(node, 'identity');
|
|
124
|
+
const jid = node.attrs.jid;
|
|
125
|
+
const registrationId = getBinaryNodeChildUInt(node, 'registration', 4);
|
|
126
|
+
await repository.injectE2ESession({
|
|
127
|
+
jid,
|
|
128
|
+
session: {
|
|
129
|
+
registrationId: registrationId,
|
|
130
|
+
identityKey: generateSignalPubKey(identity),
|
|
131
|
+
signedPreKey: extractKey(signedKey),
|
|
132
|
+
preKey: extractKey(key)
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
export const extractDeviceJids = (result, myJid, myLid, excludeZeroDevices) => {
|
|
139
|
+
const { user: myUser, device: myDevice } = jidDecode(myJid);
|
|
140
|
+
const extracted = [];
|
|
141
|
+
for (const userResult of result) {
|
|
142
|
+
const { devices, id } = userResult;
|
|
143
|
+
const decoded = jidDecode(id), { user, server } = decoded;
|
|
144
|
+
let { domainType } = decoded;
|
|
145
|
+
const deviceList = devices?.deviceList;
|
|
146
|
+
if (!Array.isArray(deviceList))
|
|
147
|
+
continue;
|
|
148
|
+
for (const { id: device, keyIndex, isHosted } of deviceList) {
|
|
149
|
+
if ((!excludeZeroDevices || device !== 0) && // if zero devices are not-excluded, or device is non zero
|
|
150
|
+
((myUser !== user && myLid !== user) || myDevice !== device) && // either different user or if me user, not this device
|
|
151
|
+
(device === 0 || !!keyIndex) // ensure that "key-index" is specified for "non-zero" devices, produces a bad req otherwise
|
|
152
|
+
) {
|
|
153
|
+
if (isHosted) {
|
|
154
|
+
domainType = domainType === WAJIDDomains.LID ? WAJIDDomains.HOSTED_LID : WAJIDDomains.HOSTED;
|
|
155
|
+
}
|
|
156
|
+
extracted.push({
|
|
157
|
+
user,
|
|
158
|
+
device,
|
|
159
|
+
domainType,
|
|
160
|
+
server: getServerFromDomainType(server, domainType)
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return extracted;
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* get the next N keys for upload or processing
|
|
169
|
+
* @param count number of pre-keys to get or generate
|
|
170
|
+
*/
|
|
171
|
+
export const getNextPreKeys = async ({ creds, keys }, count) => {
|
|
172
|
+
const { newPreKeys, lastPreKeyId, preKeysRange } = generateOrGetPreKeys(creds, count);
|
|
173
|
+
const update = {
|
|
174
|
+
nextPreKeyId: Math.max(lastPreKeyId + 1, creds.nextPreKeyId),
|
|
175
|
+
firstUnuploadedPreKeyId: Math.max(creds.firstUnuploadedPreKeyId, lastPreKeyId + 1)
|
|
176
|
+
};
|
|
177
|
+
await keys.set({ 'pre-key': newPreKeys });
|
|
178
|
+
const preKeys = await getPreKeys(keys, preKeysRange[0], preKeysRange[0] + preKeysRange[1]);
|
|
179
|
+
return { update, preKeys };
|
|
180
|
+
};
|
|
181
|
+
export const getNextPreKeysNode = async (state, count) => {
|
|
182
|
+
const { creds } = state;
|
|
183
|
+
const { update, preKeys } = await getNextPreKeys(state, count);
|
|
184
|
+
const node = {
|
|
185
|
+
tag: 'iq',
|
|
186
|
+
attrs: {
|
|
187
|
+
xmlns: 'encrypt',
|
|
188
|
+
type: 'set',
|
|
189
|
+
to: S_WHATSAPP_NET
|
|
190
|
+
},
|
|
191
|
+
content: [
|
|
192
|
+
{ tag: 'registration', attrs: {}, content: encodeBigEndian(creds.registrationId) },
|
|
193
|
+
{ tag: 'type', attrs: {}, content: KEY_BUNDLE_TYPE },
|
|
194
|
+
{ 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)
|
|
197
|
+
]
|
|
198
|
+
};
|
|
199
|
+
return { update, node };
|
|
200
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds an ACK stanza for a received node.
|
|
3
|
+
* Pure function -- no I/O, no side effects.
|
|
4
|
+
*
|
|
5
|
+
* Mirrors WhatsApp Web's ACK construction:
|
|
6
|
+
* - WAWebHandleMsgSendAck.sendAck / sendNack
|
|
7
|
+
* - WAWebCreateNackFromStanza.createNackFromStanza
|
|
8
|
+
*/
|
|
9
|
+
export function buildAckStanza(node: any, errorCode: any, meId: any): {
|
|
10
|
+
tag: string;
|
|
11
|
+
attrs: {
|
|
12
|
+
id: any;
|
|
13
|
+
to: any;
|
|
14
|
+
class: any;
|
|
15
|
+
};
|
|
16
|
+
};
|