@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,200 @@
|
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { proto } from '../../WAProto/index.js';
|
|
3
|
+
import { NOISE_MODE, WA_CERT_DETAILS } from '../Defaults/index.js';
|
|
4
|
+
import { decodeBinaryNode } from '../WABinary/index.js';
|
|
5
|
+
import { aesDecryptGCM, aesEncryptGCM, Curve, hkdf, sha256 } from './crypto.js';
|
|
6
|
+
const IV_LENGTH = 12;
|
|
7
|
+
const EMPTY_BUFFER = Buffer.alloc(0);
|
|
8
|
+
const generateIV = (counter) => {
|
|
9
|
+
const iv = new ArrayBuffer(IV_LENGTH);
|
|
10
|
+
new DataView(iv).setUint32(8, counter);
|
|
11
|
+
return new Uint8Array(iv);
|
|
12
|
+
};
|
|
13
|
+
class TransportState {
|
|
14
|
+
constructor(encKey, decKey) {
|
|
15
|
+
this.encKey = encKey;
|
|
16
|
+
this.decKey = decKey;
|
|
17
|
+
this.readCounter = 0;
|
|
18
|
+
this.writeCounter = 0;
|
|
19
|
+
this.iv = new Uint8Array(IV_LENGTH);
|
|
20
|
+
}
|
|
21
|
+
encrypt(plaintext) {
|
|
22
|
+
const c = this.writeCounter++;
|
|
23
|
+
this.iv[8] = (c >>> 24) & 0xff;
|
|
24
|
+
this.iv[9] = (c >>> 16) & 0xff;
|
|
25
|
+
this.iv[10] = (c >>> 8) & 0xff;
|
|
26
|
+
this.iv[11] = c & 0xff;
|
|
27
|
+
return aesEncryptGCM(plaintext, this.encKey, this.iv, EMPTY_BUFFER);
|
|
28
|
+
}
|
|
29
|
+
decrypt(ciphertext) {
|
|
30
|
+
const c = this.readCounter++;
|
|
31
|
+
this.iv[8] = (c >>> 24) & 0xff;
|
|
32
|
+
this.iv[9] = (c >>> 16) & 0xff;
|
|
33
|
+
this.iv[10] = (c >>> 8) & 0xff;
|
|
34
|
+
this.iv[11] = c & 0xff;
|
|
35
|
+
return aesDecryptGCM(ciphertext, this.decKey, this.iv, EMPTY_BUFFER);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export const makeNoiseHandler = ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, logger, routingInfo }) => {
|
|
39
|
+
logger = logger.child({ class: 'ns' });
|
|
40
|
+
const data = Buffer.from(NOISE_MODE);
|
|
41
|
+
let hash = data.byteLength === 32 ? data : sha256(data);
|
|
42
|
+
let salt = hash;
|
|
43
|
+
let encKey = hash;
|
|
44
|
+
let decKey = hash;
|
|
45
|
+
let counter = 0;
|
|
46
|
+
let sentIntro = false;
|
|
47
|
+
let inBytes = Buffer.alloc(0);
|
|
48
|
+
let transport = null;
|
|
49
|
+
let isWaitingForTransport = false;
|
|
50
|
+
let pendingOnFrame = null;
|
|
51
|
+
let introHeader;
|
|
52
|
+
if (routingInfo) {
|
|
53
|
+
introHeader = Buffer.alloc(7 + routingInfo.byteLength + NOISE_HEADER.length);
|
|
54
|
+
introHeader.write('ED', 0, 'utf8');
|
|
55
|
+
introHeader.writeUint8(0, 2);
|
|
56
|
+
introHeader.writeUint8(1, 3);
|
|
57
|
+
introHeader.writeUint8(routingInfo.byteLength >> 16, 4);
|
|
58
|
+
introHeader.writeUint16BE(routingInfo.byteLength & 65535, 5);
|
|
59
|
+
introHeader.set(routingInfo, 7);
|
|
60
|
+
introHeader.set(NOISE_HEADER, 7 + routingInfo.byteLength);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
introHeader = Buffer.from(NOISE_HEADER);
|
|
64
|
+
}
|
|
65
|
+
const authenticate = (data) => {
|
|
66
|
+
if (!transport) {
|
|
67
|
+
hash = sha256(Buffer.concat([hash, data]));
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const encrypt = (plaintext) => {
|
|
71
|
+
if (transport) {
|
|
72
|
+
return transport.encrypt(plaintext);
|
|
73
|
+
}
|
|
74
|
+
const result = aesEncryptGCM(plaintext, encKey, generateIV(counter++), hash);
|
|
75
|
+
authenticate(result);
|
|
76
|
+
return result;
|
|
77
|
+
};
|
|
78
|
+
const decrypt = (ciphertext) => {
|
|
79
|
+
if (transport) {
|
|
80
|
+
return transport.decrypt(ciphertext);
|
|
81
|
+
}
|
|
82
|
+
const result = aesDecryptGCM(ciphertext, decKey, generateIV(counter++), hash);
|
|
83
|
+
authenticate(ciphertext);
|
|
84
|
+
return result;
|
|
85
|
+
};
|
|
86
|
+
const localHKDF = (data) => {
|
|
87
|
+
const key = hkdf(Buffer.from(data), 64, { salt, info: '' });
|
|
88
|
+
return [key.subarray(0, 32), key.subarray(32)];
|
|
89
|
+
};
|
|
90
|
+
const mixIntoKey = (data) => {
|
|
91
|
+
const [write, read] = localHKDF(data);
|
|
92
|
+
salt = write;
|
|
93
|
+
encKey = read;
|
|
94
|
+
decKey = read;
|
|
95
|
+
counter = 0;
|
|
96
|
+
};
|
|
97
|
+
const finishInit = async () => {
|
|
98
|
+
isWaitingForTransport = true;
|
|
99
|
+
const [write, read] = localHKDF(new Uint8Array(0));
|
|
100
|
+
transport = new TransportState(write, read);
|
|
101
|
+
isWaitingForTransport = false;
|
|
102
|
+
logger.trace('Noise handler transitioned to Transport state');
|
|
103
|
+
if (pendingOnFrame) {
|
|
104
|
+
logger.trace({ length: inBytes.length }, 'Flushing buffered frames after transport ready');
|
|
105
|
+
await processData(pendingOnFrame);
|
|
106
|
+
pendingOnFrame = null;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const processData = async (onFrame) => {
|
|
110
|
+
let size;
|
|
111
|
+
while (true) {
|
|
112
|
+
if (inBytes.length < 3)
|
|
113
|
+
return;
|
|
114
|
+
size = (inBytes[0] << 16) | (inBytes[1] << 8) | inBytes[2];
|
|
115
|
+
if (inBytes.length < size + 3)
|
|
116
|
+
return;
|
|
117
|
+
let frame = inBytes.subarray(3, size + 3);
|
|
118
|
+
inBytes = inBytes.subarray(size + 3);
|
|
119
|
+
if (transport) {
|
|
120
|
+
const result = transport.decrypt(frame);
|
|
121
|
+
frame = await decodeBinaryNode(result);
|
|
122
|
+
}
|
|
123
|
+
if (logger.level === 'trace') {
|
|
124
|
+
logger.trace({ msg: frame?.attrs?.id }, 'recv frame');
|
|
125
|
+
}
|
|
126
|
+
onFrame(frame);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
authenticate(NOISE_HEADER);
|
|
130
|
+
authenticate(publicKey);
|
|
131
|
+
return {
|
|
132
|
+
encrypt,
|
|
133
|
+
decrypt,
|
|
134
|
+
authenticate,
|
|
135
|
+
mixIntoKey,
|
|
136
|
+
finishInit,
|
|
137
|
+
processHandshake: ({ serverHello }, noiseKey) => {
|
|
138
|
+
authenticate(serverHello.ephemeral);
|
|
139
|
+
mixIntoKey(Curve.sharedKey(privateKey, serverHello.ephemeral));
|
|
140
|
+
const decStaticContent = decrypt(serverHello.static);
|
|
141
|
+
mixIntoKey(Curve.sharedKey(privateKey, decStaticContent));
|
|
142
|
+
const certDecoded = decrypt(serverHello.payload);
|
|
143
|
+
const { intermediate: certIntermediate, leaf } = proto.CertChain.decode(certDecoded);
|
|
144
|
+
// leaf
|
|
145
|
+
if (!leaf?.details || !leaf?.signature) {
|
|
146
|
+
throw new Boom('invalid noise leaf certificate', { statusCode: 400 });
|
|
147
|
+
}
|
|
148
|
+
if (!certIntermediate?.details || !certIntermediate?.signature) {
|
|
149
|
+
throw new Boom('invalid noise intermediate certificate', { statusCode: 400 });
|
|
150
|
+
}
|
|
151
|
+
const details = proto.CertChain.NoiseCertificate.Details.decode(certIntermediate.details);
|
|
152
|
+
const { issuerSerial } = details;
|
|
153
|
+
const verify = Curve.verify(details.key, leaf.details, leaf.signature);
|
|
154
|
+
const verifyIntermediate = Curve.verify(WA_CERT_DETAILS.PUBLIC_KEY, certIntermediate.details, certIntermediate.signature);
|
|
155
|
+
if (!verify) {
|
|
156
|
+
throw new Boom('noise certificate signature invalid', { statusCode: 400 });
|
|
157
|
+
}
|
|
158
|
+
if (!verifyIntermediate) {
|
|
159
|
+
throw new Boom('noise intermediate certificate signature invalid', { statusCode: 400 });
|
|
160
|
+
}
|
|
161
|
+
if (issuerSerial !== WA_CERT_DETAILS.SERIAL) {
|
|
162
|
+
throw new Boom('certification match failed', { statusCode: 400 });
|
|
163
|
+
}
|
|
164
|
+
const keyEnc = encrypt(noiseKey.public);
|
|
165
|
+
mixIntoKey(Curve.sharedKey(noiseKey.private, serverHello.ephemeral));
|
|
166
|
+
return keyEnc;
|
|
167
|
+
},
|
|
168
|
+
encodeFrame: (data) => {
|
|
169
|
+
if (transport) {
|
|
170
|
+
data = transport.encrypt(data);
|
|
171
|
+
}
|
|
172
|
+
const dataLen = data.byteLength;
|
|
173
|
+
const introSize = sentIntro ? 0 : introHeader.length;
|
|
174
|
+
const frame = Buffer.allocUnsafe(introSize + 3 + dataLen);
|
|
175
|
+
if (!sentIntro) {
|
|
176
|
+
frame.set(introHeader);
|
|
177
|
+
sentIntro = true;
|
|
178
|
+
}
|
|
179
|
+
frame[introSize] = (dataLen >>> 16) & 0xff;
|
|
180
|
+
frame[introSize + 1] = (dataLen >>> 8) & 0xff;
|
|
181
|
+
frame[introSize + 2] = dataLen & 0xff;
|
|
182
|
+
frame.set(data, introSize + 3);
|
|
183
|
+
return frame;
|
|
184
|
+
},
|
|
185
|
+
decodeFrame: async (newData, onFrame) => {
|
|
186
|
+
if (isWaitingForTransport) {
|
|
187
|
+
inBytes = Buffer.concat([inBytes, newData]);
|
|
188
|
+
pendingOnFrame = onFrame;
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
if (inBytes.length === 0) {
|
|
192
|
+
inBytes = Buffer.from(newData);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
inBytes = Buffer.concat([inBytes, newData]);
|
|
196
|
+
}
|
|
197
|
+
await processData(onFrame);
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a processor for offline stanza nodes that:
|
|
3
|
+
* - Queues nodes for sequential processing
|
|
4
|
+
* - Yields to the event loop periodically to avoid blocking
|
|
5
|
+
* - Catches handler errors to prevent the processing loop from crashing
|
|
6
|
+
*/
|
|
7
|
+
export function makeOfflineNodeProcessor(nodeProcessorMap: any, deps: any, batchSize?: number): {
|
|
8
|
+
enqueue: (type: any, node: any) => void;
|
|
9
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a processor for offline stanza nodes that:
|
|
3
|
+
* - Queues nodes for sequential processing
|
|
4
|
+
* - Yields to the event loop periodically to avoid blocking
|
|
5
|
+
* - Catches handler errors to prevent the processing loop from crashing
|
|
6
|
+
*/
|
|
7
|
+
export function makeOfflineNodeProcessor(nodeProcessorMap, deps, batchSize = 10) {
|
|
8
|
+
const nodes = [];
|
|
9
|
+
let isProcessing = false;
|
|
10
|
+
const enqueue = (type, node) => {
|
|
11
|
+
nodes.push({ type, node });
|
|
12
|
+
if (isProcessing) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
isProcessing = true;
|
|
16
|
+
const promise = async () => {
|
|
17
|
+
let processedInBatch = 0;
|
|
18
|
+
while (nodes.length && deps.isWsOpen()) {
|
|
19
|
+
const { type, node } = nodes.shift();
|
|
20
|
+
const nodeProcessor = nodeProcessorMap.get(type);
|
|
21
|
+
if (!nodeProcessor) {
|
|
22
|
+
deps.onUnexpectedError(new Error(`unknown offline node type: ${type}`), 'processing offline node');
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
await nodeProcessor(node).catch(err => deps.onUnexpectedError(err, `processing offline ${type}`));
|
|
26
|
+
processedInBatch++;
|
|
27
|
+
// Yield to event loop after processing a batch
|
|
28
|
+
// This prevents blocking the event loop for too long when there are many offline nodes
|
|
29
|
+
if (processedInBatch >= batchSize) {
|
|
30
|
+
processedInBatch = 0;
|
|
31
|
+
await deps.yieldToEventLoop();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
isProcessing = false;
|
|
35
|
+
};
|
|
36
|
+
promise().catch(error => deps.onUnexpectedError(error, 'processing offline nodes'));
|
|
37
|
+
};
|
|
38
|
+
return { enqueue };
|
|
39
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export function normalizePairingCode(value: any): string;
|
|
2
|
+
export function formatPairingCode(code: any): string;
|
|
3
|
+
export function pairingErrorCode(error: any): any;
|
|
4
|
+
export function isRateLimitError(error: any): boolean;
|
|
5
|
+
export function isCustomPairingError(error: any): boolean;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Vanz@Port (2.0.3) --- from xbibzlibrary/whatsbibz 1.4.0 (BibzWhats/pairing.js: code + error classification) and
|
|
2
|
+
// @japofc/baileys 2.4.1 (qr-render.js: formatPairingCode). Pure helpers only; the donor PairingController (timers/refresh loop) is not ported.
|
|
3
|
+
/** Trim + upper-case a user-supplied custom pairing code. Returns '' unless it is exactly 8 chars of A-Z / 0-9. */
|
|
4
|
+
export const normalizePairingCode = (value) => {
|
|
5
|
+
const normalized = String(value ?? '').trim().toUpperCase();
|
|
6
|
+
return /^[A-Z0-9]{8}$/.test(normalized) ? normalized : '';
|
|
7
|
+
};
|
|
8
|
+
/** 'ABCDEFGH' -> 'ABCD-EFGH' for display; anything that is not 8 chars is returned untouched. */
|
|
9
|
+
export const formatPairingCode = (code) => {
|
|
10
|
+
const c = String(code ?? '');
|
|
11
|
+
return c.length === 8 ? `${c.slice(0, 4)}-${c.slice(4)}` : c;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Server error code of a failed pairing request. assertNodeErrorFree Boom errors keep the WA stanza code in `error.data`
|
|
15
|
+
* (e.g. 400 / 429) while Boom's own statusCode is a generic 500, so both are checked.
|
|
16
|
+
*/
|
|
17
|
+
export const pairingErrorCode = (error) => {
|
|
18
|
+
const fromData = typeof error?.data === 'number' ? error.data : undefined;
|
|
19
|
+
const status = error?.output?.statusCode ?? error?.statusCode ?? error?.status;
|
|
20
|
+
return fromData ?? (status && status !== 500 ? status : undefined);
|
|
21
|
+
};
|
|
22
|
+
export const isRateLimitError = (error) => {
|
|
23
|
+
const code = pairingErrorCode(error);
|
|
24
|
+
return code === 428 || code === 429 || /rate[- ]?overlimit|rate.?limit|too many/i.test(String(error?.message || error));
|
|
25
|
+
};
|
|
26
|
+
export const isCustomPairingError = (error) => {
|
|
27
|
+
const code = pairingErrorCode(error);
|
|
28
|
+
return code === 422 || /custom pairing code|pairing code.*(invalid|reject|unsupported)|invalid.*pairing/i.test(String(error?.message || error));
|
|
29
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Passkey companion-linking notification helper.
|
|
2
|
+
// Adapted from the MIT-licensed WhiskeySockets/Baileys passkey helper (PR #2696).
|
|
3
|
+
const SUPPORTED_PASSKEY_TYPES = new Set(['passkey_prologue_request', 'crsc_continuation']);
|
|
4
|
+
|
|
5
|
+
export const getPasskeyRequestState = (node) => {
|
|
6
|
+
const type = node?.attrs?.type;
|
|
7
|
+
if (!SUPPORTED_PASSKEY_TYPES.has(type)) return undefined;
|
|
8
|
+
const content = Array.isArray(node?.content) ? node.content : [];
|
|
9
|
+
const hasOptions = content.some((item) => item && typeof item === 'object' && 'tag' in item);
|
|
10
|
+
return { type, hasOptions };
|
|
11
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Ported from @queenanya/baileys `addons/past-participants.ts`.
|
|
2
|
+
// No logic changes — @vanzxysenpai/baileys's own WAProto already has the
|
|
3
|
+
// `proto.PastParticipant.LeaveReason` enum and `HistorySync.pastParticipants`
|
|
4
|
+
// field this depends on (confirmed present), so this ports as-is.
|
|
5
|
+
//
|
|
6
|
+
// This reads WhatsApp's own server-provided participant-leave history from
|
|
7
|
+
// a history-sync payload (`proto.IPastParticipants[]`) — it's real protocol
|
|
8
|
+
// data, not something reconstructed by listening to live events, so it
|
|
9
|
+
// includes participants who left/were removed *before* this session ever
|
|
10
|
+
// connected (which a live `group-participants.update` listener can never
|
|
11
|
+
// see).
|
|
12
|
+
import { proto } from '../../WAProto/index.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Process proto.IPastParticipants[] from a history sync payload.
|
|
16
|
+
* Returns a structured list per group.
|
|
17
|
+
*/
|
|
18
|
+
export const processPastParticipants = (pastParticipantsList) => {
|
|
19
|
+
return pastParticipantsList.map((pp) => {
|
|
20
|
+
const groupJid = pp.groupJid ?? '';
|
|
21
|
+
const participants = (pp.pastParticipants ?? []).map((p) => ({
|
|
22
|
+
jid: p.userJid ?? '',
|
|
23
|
+
leaveTs: p.leaveTs ? Number(p.leaveTs) : undefined,
|
|
24
|
+
leaveReason: p.leaveReason === proto.PastParticipant.LeaveReason.LEFT
|
|
25
|
+
? 'left'
|
|
26
|
+
: p.leaveReason === proto.PastParticipant.LeaveReason.REMOVED
|
|
27
|
+
? 'removed'
|
|
28
|
+
: undefined
|
|
29
|
+
}));
|
|
30
|
+
return { groupJid, participants };
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Check if a history sync event contains past participants data.
|
|
36
|
+
* (pastParticipants field replaces chunkOrder in this patch)
|
|
37
|
+
*/
|
|
38
|
+
export const hasPastParticipants = (event) => {
|
|
39
|
+
return Array.isArray(event.pastParticipants) && event.pastParticipants.length > 0;
|
|
40
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Verifica se a webMessage contém uma mensagem de pagamento — visível ou stealth. */
|
|
2
|
+
export function hasPaymentMessage(webMessage: any): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* Lê a marcação (quoted) de uma mensagem de pagamento — inclusive as enviadas
|
|
5
|
+
* de forma oculta para admins — e devolve o autor original e o id da
|
|
6
|
+
* mensagem citada. Ignora citações aninhadas para não atribuir o pagamento errado.
|
|
7
|
+
*/
|
|
8
|
+
export function getQuotedPaymentContext(webMessage: any): any;
|
|
9
|
+
/**
|
|
10
|
+
* Registra o envelope de uma mensagem de grupo. `isPayment` é calculado pelo
|
|
11
|
+
* chamador (que já roda a detecção de pagamento) para evitar import cíclico.
|
|
12
|
+
*/
|
|
13
|
+
export function recordMessageEnvelope(webMessage: any, isPayment: any): void;
|
|
14
|
+
/**
|
|
15
|
+
* Decide se uma marcação de pagamento é confiável o bastante para punir o autor.
|
|
16
|
+
*
|
|
17
|
+
* - corroborated: o bot recebeu a mensagem original, do MESMO autor, e ela era
|
|
18
|
+
* pagamento OU foi indecifrável (consistente com o truque stealth). Pode punir.
|
|
19
|
+
* - contradicted: o bot recebeu a mensagem, mas de OUTRO autor, ou ela era
|
|
20
|
+
* conteúdo legível que não era pagamento. É forja. Nunca punir.
|
|
21
|
+
* - nenhum dos dois: o bot não viu a mensagem original. Sem corroboração, não pune.
|
|
22
|
+
*/
|
|
23
|
+
export function verifyQuotedAuthor(opts1: { [key: string]: any;
|
|
24
|
+
groupJid: any;
|
|
25
|
+
stanzaId: any;
|
|
26
|
+
participant: any;
|
|
27
|
+
}): {
|
|
28
|
+
corroborated: boolean;
|
|
29
|
+
contradicted: boolean;
|
|
30
|
+
};
|
|
31
|
+
/** Apenas para testes: limpa o registro. */
|
|
32
|
+
export function __clearEnvelopeRegistry(): void;
|
|
33
|
+
/**
|
|
34
|
+
* Extrai o valor monetário de um requestPaymentMessage / sendPaymentMessage.
|
|
35
|
+
* Retorna { value, currencyCode } ou null se não encontrar.
|
|
36
|
+
*/
|
|
37
|
+
export function extractPaymentAmount(webMessage: any): {
|
|
38
|
+
value: number;
|
|
39
|
+
currencyCode: any;
|
|
40
|
+
};
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
// Vanz@Port --- ported from @lpzeravk/baileys 1.0.0 (payment-detection.js). Creator credits untouched. See NOTICE.md.
|
|
2
|
+
/**
|
|
3
|
+
* Detecção de mensagens de pagamento — incluindo cobranças STEALTH
|
|
4
|
+
* (ocultas para admins, indecifráveis pelo bot).
|
|
5
|
+
*
|
|
6
|
+
* Integrado na @lpzeravk/baileys.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const MAX_PAYMENT_SCAN_DEPTH = 8;
|
|
10
|
+
|
|
11
|
+
const PAYMENT_MESSAGE_KEYS = new Set([
|
|
12
|
+
'paymentInviteMessage',
|
|
13
|
+
'requestPaymentMessage',
|
|
14
|
+
'sendPaymentMessage',
|
|
15
|
+
'cancelPaymentRequestMessage',
|
|
16
|
+
'declinePaymentRequestMessage',
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
function canScanObject(value) {
|
|
20
|
+
return value && typeof value === 'object' && !(value instanceof ArrayBuffer) && !ArrayBuffer.isView(value);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function hasPaymentMessageKey(value, depth = 0, seenObjects = new WeakSet()) {
|
|
24
|
+
if (!canScanObject(value) || depth > MAX_PAYMENT_SCAN_DEPTH || seenObjects.has(value)) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
seenObjects.add(value);
|
|
29
|
+
|
|
30
|
+
for (const [key, childValue] of Object.entries(value)) {
|
|
31
|
+
if (key === 'quotedMessage') continue;
|
|
32
|
+
|
|
33
|
+
if (PAYMENT_MESSAGE_KEYS.has(key) && canScanObject(childValue)) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (hasPaymentMessageKey(childValue, depth + 1, seenObjects)) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Verifica se a webMessage contém uma mensagem de pagamento — visível ou stealth. */
|
|
46
|
+
export function hasPaymentMessage(webMessage) {
|
|
47
|
+
return hasPaymentMessageKey(webMessage?.message);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function findQuotedPaymentContext(value, depth = 0, seenObjects = new WeakSet()) {
|
|
51
|
+
if (!canScanObject(value) || depth > MAX_PAYMENT_SCAN_DEPTH || seenObjects.has(value)) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
seenObjects.add(value);
|
|
56
|
+
|
|
57
|
+
const contextInfo = value.contextInfo;
|
|
58
|
+
|
|
59
|
+
if (
|
|
60
|
+
canScanObject(contextInfo) &&
|
|
61
|
+
typeof contextInfo.participant === 'string' &&
|
|
62
|
+
canScanObject(contextInfo.quotedMessage) &&
|
|
63
|
+
hasPaymentMessageKey(contextInfo.quotedMessage)
|
|
64
|
+
) {
|
|
65
|
+
return {
|
|
66
|
+
participant: contextInfo.participant,
|
|
67
|
+
stanzaId: typeof contextInfo.stanzaId === 'string' ? contextInfo.stanzaId : undefined,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
for (const [key, childValue] of Object.entries(value)) {
|
|
72
|
+
if (key === 'quotedMessage') continue;
|
|
73
|
+
const found = findQuotedPaymentContext(childValue, depth + 1, seenObjects);
|
|
74
|
+
if (found) return found;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Lê a marcação (quoted) de uma mensagem de pagamento — inclusive as enviadas
|
|
82
|
+
* de forma oculta para admins — e devolve o autor original e o id da
|
|
83
|
+
* mensagem citada. Ignora citações aninhadas para não atribuir o pagamento errado.
|
|
84
|
+
*/
|
|
85
|
+
export function getQuotedPaymentContext(webMessage) {
|
|
86
|
+
return findQuotedPaymentContext(webMessage?.message);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// ─── Registro de envelopes (corroboração anti-forja) ──────────────────────
|
|
90
|
+
|
|
91
|
+
const ENVELOPE_TTL_MS = 60 * 60 * 1000; // 1 hora
|
|
92
|
+
const MAX_ENTRIES_PER_GROUP = 1000;
|
|
93
|
+
|
|
94
|
+
// registry: Map<groupJid, Map<msgId, {participant, contentState, stealth, ts}>>
|
|
95
|
+
const registry = new Map();
|
|
96
|
+
|
|
97
|
+
const NON_CONTENT_KEYS = new Set(['messageContextInfo', 'senderKeyDistributionMessage']);
|
|
98
|
+
|
|
99
|
+
function hasReadableContent(message) {
|
|
100
|
+
if (!message || typeof message !== 'object') return false;
|
|
101
|
+
return Object.keys(message).some((key) => !NON_CONTENT_KEYS.has(key));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function pruneGroup(groupMap) {
|
|
105
|
+
const now = Date.now();
|
|
106
|
+
|
|
107
|
+
for (const [id, entry] of groupMap) {
|
|
108
|
+
if (now - entry.ts > ENVELOPE_TTL_MS) {
|
|
109
|
+
groupMap.delete(id);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
while (groupMap.size > MAX_ENTRIES_PER_GROUP) {
|
|
114
|
+
const oldestKey = groupMap.keys().next().value;
|
|
115
|
+
if (oldestKey === undefined) break;
|
|
116
|
+
groupMap.delete(oldestKey);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Registra o envelope de uma mensagem de grupo. `isPayment` é calculado pelo
|
|
122
|
+
* chamador (que já roda a detecção de pagamento) para evitar import cíclico.
|
|
123
|
+
*/
|
|
124
|
+
export function recordMessageEnvelope(webMessage, isPayment) {
|
|
125
|
+
const remoteJid = webMessage?.key?.remoteJid;
|
|
126
|
+
const id = webMessage?.key?.id;
|
|
127
|
+
const participant = webMessage?.key?.participant;
|
|
128
|
+
|
|
129
|
+
if (!remoteJid?.endsWith('@g.us') || !id || !participant) return;
|
|
130
|
+
|
|
131
|
+
let groupMap = registry.get(remoteJid);
|
|
132
|
+
if (!groupMap) {
|
|
133
|
+
groupMap = new Map();
|
|
134
|
+
registry.set(remoteJid, groupMap);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const contentState = isPayment ? 'payment' : hasReadableContent(webMessage?.message) ? 'other' : 'unreadable';
|
|
138
|
+
|
|
139
|
+
groupMap.set(id, {
|
|
140
|
+
participant,
|
|
141
|
+
contentState,
|
|
142
|
+
stealth: Boolean(webMessage?.stealthMeta),
|
|
143
|
+
ts: Date.now(),
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
pruneGroup(groupMap);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Decide se uma marcação de pagamento é confiável o bastante para punir o autor.
|
|
151
|
+
*
|
|
152
|
+
* - corroborated: o bot recebeu a mensagem original, do MESMO autor, e ela era
|
|
153
|
+
* pagamento OU foi indecifrável (consistente com o truque stealth). Pode punir.
|
|
154
|
+
* - contradicted: o bot recebeu a mensagem, mas de OUTRO autor, ou ela era
|
|
155
|
+
* conteúdo legível que não era pagamento. É forja. Nunca punir.
|
|
156
|
+
* - nenhum dos dois: o bot não viu a mensagem original. Sem corroboração, não pune.
|
|
157
|
+
*/
|
|
158
|
+
export function verifyQuotedAuthor({ groupJid, stanzaId, participant }) {
|
|
159
|
+
if (!stanzaId) return { corroborated: false, contradicted: false };
|
|
160
|
+
|
|
161
|
+
const entry = registry.get(groupJid)?.get(stanzaId);
|
|
162
|
+
if (!entry) return { corroborated: false, contradicted: false };
|
|
163
|
+
|
|
164
|
+
if (entry.participant !== participant) {
|
|
165
|
+
return { corroborated: false, contradicted: true };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (entry.contentState === 'other') {
|
|
169
|
+
return { corroborated: false, contradicted: true };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return { corroborated: true, contradicted: false };
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Apenas para testes: limpa o registro. */
|
|
176
|
+
export function __clearEnvelopeRegistry() {
|
|
177
|
+
registry.clear();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// ─── Extração de valor monetário ───────────────────────────────────────────
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Extrai o valor monetário de um requestPaymentMessage / sendPaymentMessage.
|
|
184
|
+
* Retorna { value, currencyCode } ou null se não encontrar.
|
|
185
|
+
*/
|
|
186
|
+
export function extractPaymentAmount(webMessage) {
|
|
187
|
+
try {
|
|
188
|
+
const msg =
|
|
189
|
+
webMessage?.message?.requestPaymentMessage ||
|
|
190
|
+
webMessage?.message?.sendPaymentMessage ||
|
|
191
|
+
webMessage?.message?.paymentInviteMessage;
|
|
192
|
+
|
|
193
|
+
if (!msg) return null;
|
|
194
|
+
|
|
195
|
+
if (msg.amount && msg.amount.value !== undefined) {
|
|
196
|
+
const raw = typeof msg.amount.value === 'object' ? msg.amount.value.low ?? 0 : Number(msg.amount.value);
|
|
197
|
+
const offset = msg.amount.offset || 100;
|
|
198
|
+
return {
|
|
199
|
+
value: raw / offset,
|
|
200
|
+
currencyCode: msg.amount.currencyCode || msg.currencyCodeIso4217 || '???',
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (msg.amount1000 !== undefined) {
|
|
205
|
+
const raw = typeof msg.amount1000 === 'object' ? msg.amount1000.low ?? 0 : Number(msg.amount1000);
|
|
206
|
+
return { value: raw / 1000, currencyCode: msg.currencyCodeIso4217 || '???' };
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return null;
|
|
210
|
+
} catch {
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export function bindPaymentGuard(sock: any, hooks: PaymentGuardHooks): () => void;
|
|
2
|
+
export type PaymentGuardHooks = {
|
|
3
|
+
/**
|
|
4
|
+
* Função que decide se um webMessage (ou webMessage sintético de edição)
|
|
5
|
+
* é uma mensagem de pagamento. Normalmente seu `hasPaymentMessage`.
|
|
6
|
+
*/
|
|
7
|
+
isPaymentMessage: (webMessage: any) => boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Chamado para TODA mensagem de grupo vista (payment ou não), inclusive
|
|
10
|
+
* falhas de decrypt (com `webMessage.message === null`). Normalmente seu
|
|
11
|
+
* `recordMessageEnvelope`.
|
|
12
|
+
*/
|
|
13
|
+
recordEnvelope?: (webMessage: any, isPayment: boolean) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Chamado sempre que uma detecção (direta, editada ou indecifrável
|
|
16
|
+
* suspeita) acontece.
|
|
17
|
+
*/
|
|
18
|
+
onDetect: (detection: PaymentDetection) => void;
|
|
19
|
+
treatDecryptFailureAsSuspicious?: boolean;
|
|
20
|
+
};
|
|
21
|
+
export type PaymentDetection = {
|
|
22
|
+
type: "direct" | "edited" | "undecryptable";
|
|
23
|
+
remoteJid: string;
|
|
24
|
+
participant: string | undefined;
|
|
25
|
+
messageId: string | undefined;
|
|
26
|
+
isPreKeyError?: boolean;
|
|
27
|
+
errorMessage?: string;
|
|
28
|
+
};
|