@eduh_dev021/baileys 0.0.0-stage → 1.1.0
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/LICENSE +23 -0
- package/README.md +1843 -2
- package/WAProto/index.d.ts +22220 -0
- package/WAProto/index.js +5 -0
- package/cjs/WAProto/index.d.ts +22220 -0
- package/cjs/WAProto/index.js +60125 -0
- package/cjs/engine-requirements.js +12 -0
- package/cjs/lib/Addon/cache.js +179 -0
- package/cjs/lib/Addon/crc32.js +41 -0
- package/cjs/lib/Addon/file-type.js +217 -0
- package/cjs/lib/Addon/get-file.js +99 -0
- package/cjs/lib/Addon/http-error.d.ts +18 -0
- package/cjs/lib/Addon/http-error.js +66 -0
- package/cjs/lib/Addon/index.d.ts +96 -0
- package/cjs/lib/Addon/index.js +58 -0
- package/cjs/lib/Addon/keyed-db.d.ts +14 -0
- package/cjs/lib/Addon/keyed-db.js +264 -0
- package/cjs/lib/Addon/link-preview.d.ts +15 -0
- package/cjs/lib/Addon/link-preview.js +104 -0
- package/cjs/lib/Addon/media-info.js +98 -0
- package/cjs/lib/Addon/mutex.js +78 -0
- package/cjs/lib/Addon/qr.js +464 -0
- package/cjs/lib/Addon/queue.js +54 -0
- package/cjs/lib/Addon/waveform.js +130 -0
- package/cjs/lib/Addon/zip.js +136 -0
- package/cjs/lib/Defaults/index.d.ts +184 -0
- package/cjs/lib/Defaults/index.js +292 -0
- package/cjs/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/cjs/lib/Signal/Group/ciphertext-message.js +37 -0
- package/cjs/lib/Signal/Group/group-cipher.d.ts +10 -0
- package/cjs/lib/Signal/Group/group-cipher.js +105 -0
- package/cjs/lib/Signal/Group/group-session-builder.d.ts +7 -0
- package/cjs/lib/Signal/Group/group-session-builder.js +65 -0
- package/cjs/lib/Signal/Group/index.d.ts +11 -0
- package/cjs/lib/Signal/Group/index.js +67 -0
- package/cjs/lib/Signal/Group/keyhelper.d.ts +6 -0
- package/cjs/lib/Signal/Group/keyhelper.js +47 -0
- package/cjs/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/cjs/lib/Signal/Group/sender-chain-key.js +51 -0
- package/cjs/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/cjs/lib/Signal/Group/sender-key-distribution-message.js +80 -0
- package/cjs/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/cjs/lib/Signal/Group/sender-key-message.js +87 -0
- package/cjs/lib/Signal/Group/sender-key-name.d.ts +11 -0
- package/cjs/lib/Signal/Group/sender-key-name.js +73 -0
- package/cjs/lib/Signal/Group/sender-key-record.d.ts +12 -0
- package/cjs/lib/Signal/Group/sender-key-record.js +66 -0
- package/cjs/lib/Signal/Group/sender-key-state.d.ts +16 -0
- package/cjs/lib/Signal/Group/sender-key-state.js +106 -0
- package/cjs/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/cjs/lib/Signal/Group/sender-message-key.js +51 -0
- package/cjs/lib/Signal/libsignal.d.ts +54 -0
- package/cjs/lib/Signal/libsignal.js +421 -0
- package/cjs/lib/Signal/lid-mapping.d.ts +20 -0
- package/cjs/lib/Signal/lid-mapping.js +292 -0
- package/cjs/lib/Socket/Client/index.d.ts +2 -0
- package/cjs/lib/Socket/Client/index.js +23 -0
- package/cjs/lib/Socket/Client/types.d.ts +5 -0
- package/cjs/lib/Socket/Client/types.js +36 -0
- package/cjs/lib/Socket/Client/websocket.d.ts +12 -0
- package/cjs/lib/Socket/Client/websocket.js +143 -0
- package/cjs/lib/Socket/business.d.ts +387 -0
- package/cjs/lib/Socket/business.js +402 -0
- package/cjs/lib/Socket/chats.d.ts +144 -0
- package/cjs/lib/Socket/chats.js +1118 -0
- package/cjs/lib/Socket/communities.d.ts +554 -0
- package/cjs/lib/Socket/communities.js +456 -0
- package/cjs/lib/Socket/groups.d.ts +286 -0
- package/cjs/lib/Socket/groups.js +366 -0
- package/cjs/lib/Socket/index.d.ts +522 -0
- package/cjs/lib/Socket/index.js +32 -0
- package/cjs/lib/Socket/messages-recv.d.ts +326 -0
- package/cjs/lib/Socket/messages-recv.js +1670 -0
- package/cjs/lib/Socket/messages-send.d.ts +321 -0
- package/cjs/lib/Socket/messages-send.js +1252 -0
- package/cjs/lib/Socket/mex.d.ts +1 -0
- package/cjs/lib/Socket/mex.js +65 -0
- package/cjs/lib/Socket/newsletter.d.ts +283 -0
- package/cjs/lib/Socket/newsletter.js +243 -0
- package/cjs/lib/Socket/socket.d.ts +61 -0
- package/cjs/lib/Socket/socket.js +908 -0
- package/cjs/lib/Store/index.d.ts +3 -0
- package/cjs/lib/Store/index.js +25 -0
- package/cjs/lib/Store/make-in-memory-store.d.ts +63 -0
- package/cjs/lib/Store/make-in-memory-store.js +431 -0
- package/cjs/lib/Store/make-ordered-dictionary.d.ts +12 -0
- package/cjs/lib/Store/make-ordered-dictionary.js +101 -0
- package/cjs/lib/Store/object-repository.d.ts +10 -0
- package/cjs/lib/Store/object-repository.js +49 -0
- package/cjs/lib/Transport/crypto.d.ts +6 -0
- package/cjs/lib/Transport/crypto.js +107 -0
- package/cjs/lib/Transport/curve.d.ts +8 -0
- package/cjs/lib/Transport/curve.js +94 -0
- package/cjs/lib/Transport/index.d.ts +16 -0
- package/cjs/lib/Transport/index.js +67 -0
- package/cjs/lib/Transport/internals.d.ts +57 -0
- package/cjs/lib/Transport/internals.js +203 -0
- package/cjs/lib/Transport/session-builder.d.ts +40 -0
- package/cjs/lib/Transport/session-builder.js +169 -0
- package/cjs/lib/Transport/session-cipher.d.ts +26 -0
- package/cjs/lib/Transport/session-cipher.js +328 -0
- package/cjs/lib/Transport/session-record.d.ts +55 -0
- package/cjs/lib/Transport/session-record.js +289 -0
- package/cjs/lib/Types/Auth.d.ts +1 -0
- package/cjs/lib/Types/Auth.js +15 -0
- package/cjs/lib/Types/Bussines.d.ts +1 -0
- package/cjs/lib/Types/Bussines.js +15 -0
- package/cjs/lib/Types/Call.d.ts +1 -0
- package/cjs/lib/Types/Call.js +15 -0
- package/cjs/lib/Types/Chat.d.ts +1 -0
- package/cjs/lib/Types/Chat.js +33 -0
- package/cjs/lib/Types/Contact.d.ts +1 -0
- package/cjs/lib/Types/Contact.js +15 -0
- package/cjs/lib/Types/Events.d.ts +1 -0
- package/cjs/lib/Types/Events.js +1 -0
- package/cjs/lib/Types/GroupMetadata.d.ts +1 -0
- package/cjs/lib/Types/GroupMetadata.js +15 -0
- package/cjs/lib/Types/Label.d.ts +2 -0
- package/cjs/lib/Types/Label.js +49 -0
- package/cjs/lib/Types/LabelAssociation.d.ts +2 -0
- package/cjs/lib/Types/LabelAssociation.js +31 -0
- package/cjs/lib/Types/Message.d.ts +11 -0
- package/cjs/lib/Types/Message.js +58 -0
- package/cjs/lib/Types/Mex.d.ts +2 -0
- package/cjs/lib/Types/Mex.js +66 -0
- package/cjs/lib/Types/Product.d.ts +1 -0
- package/cjs/lib/Types/Product.js +15 -0
- package/cjs/lib/Types/RichType.d.ts +2 -0
- package/cjs/lib/Types/RichType.js +50 -0
- package/cjs/lib/Types/Signal.d.ts +1 -0
- package/cjs/lib/Types/Signal.js +1 -0
- package/cjs/lib/Types/Socket.d.ts +1 -0
- package/cjs/lib/Types/Socket.js +1 -0
- package/cjs/lib/Types/State.d.ts +5 -0
- package/cjs/lib/Types/State.js +83 -0
- package/cjs/lib/Types/USync.d.ts +1 -0
- package/cjs/lib/Types/USync.js +1 -0
- package/cjs/lib/Types/index.d.ts +13 -0
- package/cjs/lib/Types/index.js +64 -0
- package/cjs/lib/Utils/auth-utils.d.ts +58 -0
- package/cjs/lib/Utils/auth-utils.js +275 -0
- package/cjs/lib/Utils/browser-utils.d.ts +9 -0
- package/cjs/lib/Utils/browser-utils.js +56 -0
- package/cjs/lib/Utils/business.d.ts +49 -0
- package/cjs/lib/Utils/business.js +259 -0
- package/cjs/lib/Utils/chat-utils.d.ts +408 -0
- package/cjs/lib/Utils/chat-utils.js +821 -0
- package/cjs/lib/Utils/companion-reg-client-utils.d.ts +4 -0
- package/cjs/lib/Utils/companion-reg-client-utils.js +71 -0
- package/cjs/lib/Utils/crypto.d.ts +39 -0
- package/cjs/lib/Utils/crypto.js +155 -0
- package/cjs/lib/Utils/decode-wa-message.d.ts +83 -0
- package/cjs/lib/Utils/decode-wa-message.js +316 -0
- package/cjs/lib/Utils/event-buffer.d.ts +12 -0
- package/cjs/lib/Utils/event-buffer.js +605 -0
- package/cjs/lib/Utils/generics.d.ts +63 -0
- package/cjs/lib/Utils/generics.js +440 -0
- package/cjs/lib/Utils/history.d.ts +75 -0
- package/cjs/lib/Utils/history.js +153 -0
- package/cjs/lib/Utils/identity-change-handler.d.ts +13 -0
- package/cjs/lib/Utils/identity-change-handler.js +73 -0
- package/cjs/lib/Utils/index.d.ts +24 -0
- package/cjs/lib/Utils/index.js +67 -0
- package/cjs/lib/Utils/link-preview.d.ts +13 -0
- package/cjs/lib/Utils/link-preview.js +87 -0
- package/cjs/lib/Utils/logger.d.ts +12 -0
- package/cjs/lib/Utils/logger.js +40 -0
- package/cjs/lib/Utils/lt-hash.d.ts +6 -0
- package/cjs/lib/Utils/lt-hash.js +28 -0
- package/cjs/lib/Utils/make-mutex.d.ts +6 -0
- package/cjs/lib/Utils/make-mutex.js +58 -0
- package/cjs/lib/Utils/message-retry-manager.d.ts +79 -0
- package/cjs/lib/Utils/message-retry-manager.js +274 -0
- package/cjs/lib/Utils/messages-media.d.ts +134 -0
- package/cjs/lib/Utils/messages-media.js +799 -0
- package/cjs/lib/Utils/messages.d.ts +47 -0
- package/cjs/lib/Utils/messages.js +1667 -0
- package/cjs/lib/Utils/noise-handler.d.ts +20 -0
- package/cjs/lib/Utils/noise-handler.js +223 -0
- package/cjs/lib/Utils/offline-node-processor.d.ts +10 -0
- package/cjs/lib/Utils/offline-node-processor.js +60 -0
- package/cjs/lib/Utils/pre-key-manager.d.ts +25 -0
- package/cjs/lib/Utils/pre-key-manager.js +116 -0
- package/cjs/lib/Utils/process-message.d.ts +83 -0
- package/cjs/lib/Utils/process-message.js +607 -0
- package/cjs/lib/Utils/reporting-utils.d.ts +12 -0
- package/cjs/lib/Utils/reporting-utils.js +282 -0
- package/cjs/lib/Utils/rich-message-utils.d.ts +48 -0
- package/cjs/lib/Utils/rich-message-utils.js +381 -0
- package/cjs/lib/Utils/signal.d.ts +82 -0
- package/cjs/lib/Utils/signal.js +232 -0
- package/cjs/lib/Utils/stanza-ack.d.ts +16 -0
- package/cjs/lib/Utils/stanza-ack.js +53 -0
- package/cjs/lib/Utils/sync-action-utils.d.ts +2 -0
- package/cjs/lib/Utils/sync-action-utils.js +68 -0
- package/cjs/lib/Utils/tc-token-utils.d.ts +29 -0
- package/cjs/lib/Utils/tc-token-utils.js +182 -0
- package/cjs/lib/Utils/use-multi-file-auth-state.d.ts +10 -0
- package/cjs/lib/Utils/use-multi-file-auth-state.js +135 -0
- package/cjs/lib/Utils/use-single-file-auth-state.d.ts +11 -0
- package/cjs/lib/Utils/use-single-file-auth-state.js +115 -0
- package/cjs/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
- package/cjs/lib/Utils/use-sqlite-auth-state.js +140 -0
- package/cjs/lib/Utils/validate-connection.d.ts +44 -0
- package/cjs/lib/Utils/validate-connection.js +229 -0
- package/cjs/lib/WABinary/constants.d.ts +61 -0
- package/cjs/lib/WABinary/constants.js +1992 -0
- package/cjs/lib/WABinary/decode.d.ts +9 -0
- package/cjs/lib/WABinary/decode.js +292 -0
- package/cjs/lib/WABinary/encode.d.ts +2 -0
- package/cjs/lib/WABinary/encode.js +240 -0
- package/cjs/lib/WABinary/generic-utils.d.ts +79 -0
- package/cjs/lib/WABinary/generic-utils.js +252 -0
- package/cjs/lib/WABinary/index.d.ts +5 -0
- package/cjs/lib/WABinary/index.js +29 -0
- package/cjs/lib/WABinary/jid-utils.d.ts +28 -0
- package/cjs/lib/WABinary/jid-utils.js +151 -0
- package/cjs/lib/WABinary/types.d.ts +1 -0
- package/cjs/lib/WABinary/types.js +23 -0
- package/cjs/lib/WACrypto/appstate-keys.js +39 -0
- package/cjs/lib/WACrypto/curves/constants.js +37 -0
- package/cjs/lib/WACrypto/hkdf.js +38 -0
- package/cjs/lib/WACrypto/index.js +51 -0
- package/cjs/lib/WACrypto/lthash.js +59 -0
- package/cjs/lib/WACrypto/math/constants.js +53 -0
- package/cjs/lib/WACrypto/math/edwards.js +206 -0
- package/cjs/lib/WACrypto/math/fe.js +449 -0
- package/cjs/lib/WACrypto/math/le.js +44 -0
- package/cjs/lib/WACrypto/math/mod.js +36 -0
- package/cjs/lib/WACrypto/util/bytes.js +348 -0
- package/cjs/lib/WACrypto/x25519.js +157 -0
- package/cjs/lib/WACrypto/xeddsa.js +134 -0
- package/cjs/lib/WAM/BinaryInfo.d.ts +7 -0
- package/cjs/lib/WAM/BinaryInfo.js +35 -0
- package/cjs/lib/WAM/constants.d.ts +34926 -0
- package/cjs/lib/WAM/constants.js +22890 -0
- package/cjs/lib/WAM/encode.d.ts +1 -0
- package/cjs/lib/WAM/encode.js +162 -0
- package/cjs/lib/WAM/index.d.ts +3 -0
- package/cjs/lib/WAM/index.js +25 -0
- package/cjs/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +36 -0
- package/cjs/lib/WAUSync/Protocols/USyncContactProtocol.js +77 -0
- package/cjs/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/cjs/lib/WAUSync/Protocols/USyncDeviceProtocol.js +76 -0
- package/cjs/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/cjs/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +52 -0
- package/cjs/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/cjs/lib/WAUSync/Protocols/USyncStatusProtocol.js +61 -0
- package/cjs/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +9 -0
- package/cjs/lib/WAUSync/Protocols/USyncUsernameProtocol.js +50 -0
- package/cjs/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +38 -0
- package/cjs/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +76 -0
- package/cjs/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +14 -0
- package/cjs/lib/WAUSync/Protocols/UsyncLIDProtocol.js +53 -0
- package/cjs/lib/WAUSync/Protocols/index.d.ts +5 -0
- package/cjs/lib/WAUSync/Protocols/index.js +29 -0
- package/cjs/lib/WAUSync/USyncQuery.d.ts +20 -0
- package/cjs/lib/WAUSync/USyncQuery.js +113 -0
- package/cjs/lib/WAUSync/USyncUser.d.ts +16 -0
- package/cjs/lib/WAUSync/USyncUser.js +56 -0
- package/cjs/lib/WAUSync/index.d.ts +3 -0
- package/cjs/lib/WAUSync/index.js +25 -0
- package/cjs/lib/index.d.ts +11 -0
- package/cjs/lib/index.js +56 -0
- package/cjs/package.json +3 -0
- package/engine-requirements.js +12 -0
- package/lib/Addon/cache.js +201 -0
- package/lib/Addon/crc32.js +21 -0
- package/lib/Addon/file-type.js +198 -0
- package/lib/Addon/get-file.js +98 -0
- package/lib/Addon/http-error.d.ts +18 -0
- package/lib/Addon/http-error.js +40 -0
- package/lib/Addon/index.d.ts +96 -0
- package/lib/Addon/index.js +26 -0
- package/lib/Addon/keyed-db.d.ts +14 -0
- package/lib/Addon/keyed-db.js +241 -0
- package/lib/Addon/link-preview.d.ts +15 -0
- package/lib/Addon/link-preview.js +79 -0
- package/lib/Addon/media-info.js +96 -0
- package/lib/Addon/mutex.js +76 -0
- package/lib/Addon/qr.js +531 -0
- package/lib/Addon/queue.js +44 -0
- package/lib/Addon/waveform.js +135 -0
- package/lib/Addon/zip.js +144 -0
- package/lib/Defaults/index.d.ts +184 -0
- package/lib/Defaults/index.js +181 -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-cipher.d.ts +10 -0
- package/lib/Signal/Group/group-cipher.js +81 -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/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 +54 -0
- package/lib/Signal/libsignal.js +426 -0
- package/lib/Signal/lid-mapping.d.ts +20 -0
- package/lib/Signal/lid-mapping.js +274 -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 +119 -0
- package/lib/Socket/business.d.ts +387 -0
- package/lib/Socket/business.js +379 -0
- package/lib/Socket/chats.d.ts +144 -0
- package/lib/Socket/chats.js +1216 -0
- package/lib/Socket/communities.d.ts +554 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/groups.d.ts +286 -0
- package/lib/Socket/groups.js +347 -0
- package/lib/Socket/index.d.ts +522 -0
- package/lib/Socket/index.js +11 -0
- package/lib/Socket/messages-recv.d.ts +326 -0
- package/lib/Socket/messages-recv.js +1822 -0
- package/lib/Socket/messages-send.d.ts +321 -0
- package/lib/Socket/messages-send.js +1378 -0
- package/lib/Socket/mex.d.ts +1 -0
- package/lib/Socket/mex.js +41 -0
- package/lib/Socket/newsletter.d.ts +283 -0
- package/lib/Socket/newsletter.js +225 -0
- package/lib/Socket/socket.d.ts +61 -0
- package/lib/Socket/socket.js +992 -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 +63 -0
- package/lib/Store/make-in-memory-store.js +419 -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/Transport/crypto.d.ts +6 -0
- package/lib/Transport/crypto.js +61 -0
- package/lib/Transport/curve.d.ts +8 -0
- package/lib/Transport/curve.js +66 -0
- package/lib/Transport/index.d.ts +16 -0
- package/lib/Transport/index.js +9 -0
- package/lib/Transport/internals.d.ts +57 -0
- package/lib/Transport/internals.js +155 -0
- package/lib/Transport/session-builder.d.ts +40 -0
- package/lib/Transport/session-builder.js +143 -0
- package/lib/Transport/session-cipher.d.ts +26 -0
- package/lib/Transport/session-cipher.js +301 -0
- package/lib/Transport/session-record.d.ts +55 -0
- package/lib/Transport/session-record.js +272 -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 +54 -0
- package/lib/Types/USync.d.ts +1 -0
- package/lib/Types/USync.js +1 -0
- package/lib/Types/index.d.ts +13 -0
- package/lib/Types/index.js +25 -0
- package/lib/Utils/auth-utils.d.ts +58 -0
- package/lib/Utils/auth-utils.js +316 -0
- package/lib/Utils/browser-utils.d.ts +9 -0
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/business.d.ts +49 -0
- package/lib/Utils/business.js +230 -0
- package/lib/Utils/chat-utils.d.ts +408 -0
- package/lib/Utils/chat-utils.js +871 -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/crypto.d.ts +39 -0
- package/lib/Utils/crypto.js +117 -0
- package/lib/Utils/decode-wa-message.d.ts +83 -0
- package/lib/Utils/decode-wa-message.js +316 -0
- package/lib/Utils/event-buffer.d.ts +12 -0
- package/lib/Utils/event-buffer.js +621 -0
- package/lib/Utils/generics.d.ts +63 -0
- package/lib/Utils/generics.js +394 -0
- package/lib/Utils/history.d.ts +75 -0
- package/lib/Utils/history.js +133 -0
- package/lib/Utils/identity-change-handler.d.ts +13 -0
- package/lib/Utils/identity-change-handler.js +48 -0
- package/lib/Utils/index.d.ts +24 -0
- package/lib/Utils/index.js +24 -0
- package/lib/Utils/link-preview.d.ts +13 -0
- package/lib/Utils/link-preview.js +73 -0
- package/lib/Utils/logger.d.ts +12 -0
- package/lib/Utils/logger.js +12 -0
- package/lib/Utils/lt-hash.d.ts +6 -0
- package/lib/Utils/lt-hash.js +7 -0
- package/lib/Utils/make-mutex.d.ts +6 -0
- package/lib/Utils/make-mutex.js +32 -0
- package/lib/Utils/message-retry-manager.d.ts +79 -0
- package/lib/Utils/message-retry-manager.js +259 -0
- package/lib/Utils/messages-media.d.ts +134 -0
- package/lib/Utils/messages-media.js +802 -0
- package/lib/Utils/messages.d.ts +47 -0
- package/lib/Utils/messages.js +1907 -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 +10 -0
- package/lib/Utils/offline-node-processor.js +40 -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 +83 -0
- package/lib/Utils/process-message.js +748 -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 +48 -0
- package/lib/Utils/rich-message-utils.js +366 -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/sync-action-utils.d.ts +2 -0
- package/lib/Utils/sync-action-utils.js +48 -0
- package/lib/Utils/tc-token-utils.d.ts +29 -0
- package/lib/Utils/tc-token-utils.js +163 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +10 -0
- package/lib/Utils/use-multi-file-auth-state.js +116 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
- package/lib/Utils/use-single-file-auth-state.js +94 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
- package/lib/Utils/use-sqlite-auth-state.js +109 -0
- package/lib/Utils/validate-connection.d.ts +44 -0
- package/lib/Utils/validate-connection.js +210 -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 +79 -0
- package/lib/WABinary/generic-utils.js +226 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +5 -0
- package/lib/WABinary/jid-utils.d.ts +28 -0
- package/lib/WABinary/jid-utils.js +95 -0
- package/lib/WABinary/types.d.ts +1 -0
- package/lib/WABinary/types.js +1 -0
- package/lib/WACrypto/appstate-keys.js +26 -0
- package/lib/WACrypto/curves/constants.js +12 -0
- package/lib/WACrypto/hkdf.js +27 -0
- package/lib/WACrypto/index.js +20 -0
- package/lib/WACrypto/lthash.js +54 -0
- package/lib/WACrypto/math/constants.js +24 -0
- package/lib/WACrypto/math/edwards.js +194 -0
- package/lib/WACrypto/math/fe.js +698 -0
- package/lib/WACrypto/math/le.js +23 -0
- package/lib/WACrypto/math/mod.js +15 -0
- package/lib/WACrypto/util/bytes.js +339 -0
- package/lib/WACrypto/x25519.js +145 -0
- package/lib/WACrypto/xeddsa.js +92 -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/USyncContactProtocol.d.ts +36 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +51 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -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 +50 -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 +5 -0
- package/lib/WAUSync/Protocols/index.js +5 -0
- package/lib/WAUSync/USyncQuery.d.ts +20 -0
- package/lib/WAUSync/USyncQuery.js +97 -0
- package/lib/WAUSync/USyncUser.d.ts +16 -0
- package/lib/WAUSync/USyncUser.js +30 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +3 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +11 -0
- package/package.json +74 -5
- package/tests/addon-test.mjs +162 -0
- package/tests/differential-test.mjs +90 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function decompressingIfRequired(buffer: any): Promise<any>;
|
|
2
|
+
export function decodeDecompressedBinaryNode(buffer: any, opts: any, indexRef?: {
|
|
3
|
+
index: number;
|
|
4
|
+
}): {
|
|
5
|
+
tag: any;
|
|
6
|
+
attrs: {};
|
|
7
|
+
content: any;
|
|
8
|
+
};
|
|
9
|
+
export function decodeBinaryNode(buff: any): Promise<any>;
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { promisify } from 'node:util';
|
|
2
|
+
import { inflate } from 'node:zlib';
|
|
3
|
+
import * as constants from './constants.js';
|
|
4
|
+
import { jidEncode, WAJIDDomains } from './jid-utils.js';
|
|
5
|
+
const inflatePromise = promisify(inflate);
|
|
6
|
+
export const decompressingIfRequired = async (buffer) => {
|
|
7
|
+
if (2 & buffer.readUInt8()) {
|
|
8
|
+
buffer = await inflatePromise(buffer.slice(1));
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
// nodes with no compression have a 0x00 prefix, we remove that
|
|
12
|
+
buffer = buffer.slice(1);
|
|
13
|
+
}
|
|
14
|
+
return buffer;
|
|
15
|
+
};
|
|
16
|
+
export const decodeDecompressedBinaryNode = (buffer, opts, indexRef = { index: 0 }) => {
|
|
17
|
+
const { DOUBLE_BYTE_TOKENS, SINGLE_BYTE_TOKENS, TAGS } = opts;
|
|
18
|
+
const checkEOS = (length) => {
|
|
19
|
+
if (indexRef.index + length > buffer.length) {
|
|
20
|
+
throw new Error('end of stream');
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const next = () => {
|
|
24
|
+
const value = buffer[indexRef.index];
|
|
25
|
+
indexRef.index += 1;
|
|
26
|
+
return value;
|
|
27
|
+
};
|
|
28
|
+
const readByte = () => {
|
|
29
|
+
checkEOS(1);
|
|
30
|
+
return next();
|
|
31
|
+
};
|
|
32
|
+
const readBytes = (n) => {
|
|
33
|
+
checkEOS(n);
|
|
34
|
+
const value = buffer.slice(indexRef.index, indexRef.index + n);
|
|
35
|
+
indexRef.index += n;
|
|
36
|
+
return value;
|
|
37
|
+
};
|
|
38
|
+
const readStringFromChars = (length) => {
|
|
39
|
+
return readBytes(length).toString('utf-8');
|
|
40
|
+
};
|
|
41
|
+
const readInt = (n, littleEndian = false) => {
|
|
42
|
+
checkEOS(n);
|
|
43
|
+
let val = 0;
|
|
44
|
+
for (let i = 0; i < n; i++) {
|
|
45
|
+
const shift = littleEndian ? i : n - 1 - i;
|
|
46
|
+
val |= next() << (shift * 8);
|
|
47
|
+
}
|
|
48
|
+
return val;
|
|
49
|
+
};
|
|
50
|
+
const readInt20 = () => {
|
|
51
|
+
checkEOS(3);
|
|
52
|
+
return ((next() & 15) << 16) + (next() << 8) + next();
|
|
53
|
+
};
|
|
54
|
+
const unpackHex = (value) => {
|
|
55
|
+
if (value >= 0 && value < 16) {
|
|
56
|
+
return value < 10 ? '0'.charCodeAt(0) + value : 'A'.charCodeAt(0) + value - 10;
|
|
57
|
+
}
|
|
58
|
+
throw new Error('invalid hex: ' + value);
|
|
59
|
+
};
|
|
60
|
+
const unpackNibble = (value) => {
|
|
61
|
+
if (value >= 0 && value <= 9) {
|
|
62
|
+
return '0'.charCodeAt(0) + value;
|
|
63
|
+
}
|
|
64
|
+
switch (value) {
|
|
65
|
+
case 10:
|
|
66
|
+
return '-'.charCodeAt(0);
|
|
67
|
+
case 11:
|
|
68
|
+
return '.'.charCodeAt(0);
|
|
69
|
+
case 15:
|
|
70
|
+
return '\0'.charCodeAt(0);
|
|
71
|
+
default:
|
|
72
|
+
throw new Error('invalid nibble: ' + value);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const unpackByte = (tag, value) => {
|
|
76
|
+
if (tag === TAGS.NIBBLE_8) {
|
|
77
|
+
return unpackNibble(value);
|
|
78
|
+
}
|
|
79
|
+
else if (tag === TAGS.HEX_8) {
|
|
80
|
+
return unpackHex(value);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
throw new Error('unknown tag: ' + tag);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const readPacked8 = (tag) => {
|
|
87
|
+
const startByte = readByte();
|
|
88
|
+
let value = '';
|
|
89
|
+
for (let i = 0; i < (startByte & 127); i++) {
|
|
90
|
+
const curByte = readByte();
|
|
91
|
+
value += String.fromCharCode(unpackByte(tag, (curByte & 0xf0) >> 4));
|
|
92
|
+
value += String.fromCharCode(unpackByte(tag, curByte & 0x0f));
|
|
93
|
+
}
|
|
94
|
+
if (startByte >> 7 !== 0) {
|
|
95
|
+
value = value.slice(0, -1);
|
|
96
|
+
}
|
|
97
|
+
return value;
|
|
98
|
+
};
|
|
99
|
+
const isListTag = (tag) => {
|
|
100
|
+
return tag === TAGS.LIST_EMPTY || tag === TAGS.LIST_8 || tag === TAGS.LIST_16;
|
|
101
|
+
};
|
|
102
|
+
const readListSize = (tag) => {
|
|
103
|
+
switch (tag) {
|
|
104
|
+
case TAGS.LIST_EMPTY:
|
|
105
|
+
return 0;
|
|
106
|
+
case TAGS.LIST_8:
|
|
107
|
+
return readByte();
|
|
108
|
+
case TAGS.LIST_16:
|
|
109
|
+
return readInt(2);
|
|
110
|
+
default:
|
|
111
|
+
throw new Error('invalid tag for list size: ' + tag);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const readJidPair = () => {
|
|
115
|
+
const i = readString(readByte());
|
|
116
|
+
const j = readString(readByte());
|
|
117
|
+
if (j) {
|
|
118
|
+
return (i || '') + '@' + j;
|
|
119
|
+
}
|
|
120
|
+
throw new Error('invalid jid pair: ' + i + ', ' + j);
|
|
121
|
+
};
|
|
122
|
+
const readAdJid = () => {
|
|
123
|
+
const rawDomainType = readByte();
|
|
124
|
+
const domainType = Number(rawDomainType);
|
|
125
|
+
const device = readByte();
|
|
126
|
+
const user = readString(readByte());
|
|
127
|
+
let server = 's.whatsapp.net'; // default whatsapp server
|
|
128
|
+
if (domainType === WAJIDDomains.LID) {
|
|
129
|
+
server = 'lid';
|
|
130
|
+
}
|
|
131
|
+
else if (domainType === WAJIDDomains.HOSTED) {
|
|
132
|
+
server = 'hosted';
|
|
133
|
+
}
|
|
134
|
+
else if (domainType === WAJIDDomains.HOSTED_LID) {
|
|
135
|
+
server = 'hosted.lid';
|
|
136
|
+
}
|
|
137
|
+
return jidEncode(user, server, device);
|
|
138
|
+
};
|
|
139
|
+
const readFbJid = () => {
|
|
140
|
+
const user = readString(readByte());
|
|
141
|
+
const device = readInt(2);
|
|
142
|
+
const server = readString(readByte());
|
|
143
|
+
return `${user}:${device}@${server}`;
|
|
144
|
+
};
|
|
145
|
+
const readInteropJid = () => {
|
|
146
|
+
const user = readString(readByte());
|
|
147
|
+
const device = readInt(2);
|
|
148
|
+
const integrator = readInt(2);
|
|
149
|
+
let server = 'interop';
|
|
150
|
+
const beforeServer = indexRef.index;
|
|
151
|
+
try {
|
|
152
|
+
server = readString(readByte());
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
indexRef.index = beforeServer;
|
|
156
|
+
}
|
|
157
|
+
return `${integrator}-${user}:${device}@${server}`;
|
|
158
|
+
};
|
|
159
|
+
const readString = (tag) => {
|
|
160
|
+
if (tag >= 1 && tag < SINGLE_BYTE_TOKENS.length) {
|
|
161
|
+
return SINGLE_BYTE_TOKENS[tag] || '';
|
|
162
|
+
}
|
|
163
|
+
switch (tag) {
|
|
164
|
+
case TAGS.DICTIONARY_0:
|
|
165
|
+
case TAGS.DICTIONARY_1:
|
|
166
|
+
case TAGS.DICTIONARY_2:
|
|
167
|
+
case TAGS.DICTIONARY_3:
|
|
168
|
+
return getTokenDouble(tag - TAGS.DICTIONARY_0, readByte());
|
|
169
|
+
case TAGS.LIST_EMPTY:
|
|
170
|
+
return '';
|
|
171
|
+
case TAGS.BINARY_8:
|
|
172
|
+
return readStringFromChars(readByte());
|
|
173
|
+
case TAGS.BINARY_20:
|
|
174
|
+
return readStringFromChars(readInt20());
|
|
175
|
+
case TAGS.BINARY_32:
|
|
176
|
+
return readStringFromChars(readInt(4));
|
|
177
|
+
case TAGS.JID_PAIR:
|
|
178
|
+
return readJidPair();
|
|
179
|
+
case TAGS.FB_JID:
|
|
180
|
+
return readFbJid();
|
|
181
|
+
case TAGS.INTEROP_JID:
|
|
182
|
+
return readInteropJid();
|
|
183
|
+
case TAGS.AD_JID:
|
|
184
|
+
return readAdJid();
|
|
185
|
+
case TAGS.HEX_8:
|
|
186
|
+
case TAGS.NIBBLE_8:
|
|
187
|
+
return readPacked8(tag);
|
|
188
|
+
default:
|
|
189
|
+
throw new Error('invalid string with tag: ' + tag);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
const readList = (tag) => {
|
|
193
|
+
const items = [];
|
|
194
|
+
const size = readListSize(tag);
|
|
195
|
+
for (let i = 0; i < size; i++) {
|
|
196
|
+
items.push(decodeDecompressedBinaryNode(buffer, opts, indexRef));
|
|
197
|
+
}
|
|
198
|
+
return items;
|
|
199
|
+
};
|
|
200
|
+
const getTokenDouble = (index1, index2) => {
|
|
201
|
+
const dict = DOUBLE_BYTE_TOKENS[index1];
|
|
202
|
+
if (!dict) {
|
|
203
|
+
throw new Error(`Invalid double token dict (${index1})`);
|
|
204
|
+
}
|
|
205
|
+
const value = dict[index2];
|
|
206
|
+
if (typeof value === 'undefined') {
|
|
207
|
+
throw new Error(`Invalid double token (${index2})`);
|
|
208
|
+
}
|
|
209
|
+
return value;
|
|
210
|
+
};
|
|
211
|
+
const listSize = readListSize(readByte());
|
|
212
|
+
const header = readString(readByte());
|
|
213
|
+
if (!listSize || !header.length) {
|
|
214
|
+
throw new Error('invalid node');
|
|
215
|
+
}
|
|
216
|
+
const attrs = {};
|
|
217
|
+
let data;
|
|
218
|
+
if (listSize === 0 || !header) {
|
|
219
|
+
throw new Error('invalid node');
|
|
220
|
+
}
|
|
221
|
+
// read the attributes in
|
|
222
|
+
const attributesLength = (listSize - 1) >> 1;
|
|
223
|
+
for (let i = 0; i < attributesLength; i++) {
|
|
224
|
+
const key = readString(readByte());
|
|
225
|
+
const value = readString(readByte());
|
|
226
|
+
attrs[key] = value;
|
|
227
|
+
}
|
|
228
|
+
if (listSize % 2 === 0) {
|
|
229
|
+
const tag = readByte();
|
|
230
|
+
if (isListTag(tag)) {
|
|
231
|
+
data = readList(tag);
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
let decoded;
|
|
235
|
+
switch (tag) {
|
|
236
|
+
case TAGS.BINARY_8:
|
|
237
|
+
decoded = readBytes(readByte());
|
|
238
|
+
break;
|
|
239
|
+
case TAGS.BINARY_20:
|
|
240
|
+
decoded = readBytes(readInt20());
|
|
241
|
+
break;
|
|
242
|
+
case TAGS.BINARY_32:
|
|
243
|
+
decoded = readBytes(readInt(4));
|
|
244
|
+
break;
|
|
245
|
+
default:
|
|
246
|
+
decoded = readString(tag);
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
data = decoded;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return {
|
|
253
|
+
tag: header,
|
|
254
|
+
attrs,
|
|
255
|
+
content: data
|
|
256
|
+
};
|
|
257
|
+
};
|
|
258
|
+
export const decodeBinaryNode = async (buff) => {
|
|
259
|
+
const decompBuff = await decompressingIfRequired(buff);
|
|
260
|
+
return decodeDecompressedBinaryNode(decompBuff, constants);
|
|
261
|
+
};
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import * as constants from './constants.js';
|
|
2
|
+
import { jidDecode } from './jid-utils.js';
|
|
3
|
+
export const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
|
|
4
|
+
const encoded = encodeBinaryNodeInner(node, opts, buffer);
|
|
5
|
+
return Buffer.from(encoded);
|
|
6
|
+
};
|
|
7
|
+
const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
|
|
8
|
+
const { TAGS, TOKEN_MAP } = opts;
|
|
9
|
+
const pushByte = (value) => buffer.push(value & 0xff);
|
|
10
|
+
const pushInt = (value, n, littleEndian = false) => {
|
|
11
|
+
for (let i = 0; i < n; i++) {
|
|
12
|
+
const curShift = littleEndian ? i : n - 1 - i;
|
|
13
|
+
buffer.push((value >> (curShift * 8)) & 0xff);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const pushBytes = (bytes) => {
|
|
17
|
+
for (const b of bytes) {
|
|
18
|
+
buffer.push(b);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const pushInt16 = (value) => {
|
|
22
|
+
pushBytes([(value >> 8) & 0xff, value & 0xff]);
|
|
23
|
+
};
|
|
24
|
+
const pushInt20 = (value) => pushBytes([(value >> 16) & 0x0f, (value >> 8) & 0xff, value & 0xff]);
|
|
25
|
+
const writeByteLength = (length) => {
|
|
26
|
+
if (length >= 4294967296) {
|
|
27
|
+
throw new Error('string too large to encode: ' + length);
|
|
28
|
+
}
|
|
29
|
+
if (length >= 1 << 20) {
|
|
30
|
+
pushByte(TAGS.BINARY_32);
|
|
31
|
+
pushInt(length, 4); // 32 bit integer
|
|
32
|
+
}
|
|
33
|
+
else if (length >= 256) {
|
|
34
|
+
pushByte(TAGS.BINARY_20);
|
|
35
|
+
pushInt20(length);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
pushByte(TAGS.BINARY_8);
|
|
39
|
+
pushByte(length);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const writeStringRaw = (str) => {
|
|
43
|
+
const bytes = Buffer.from(str, 'utf-8');
|
|
44
|
+
writeByteLength(bytes.length);
|
|
45
|
+
pushBytes(bytes);
|
|
46
|
+
};
|
|
47
|
+
const writeJid = ({ domainType, device, user, server }) => {
|
|
48
|
+
if (typeof device !== 'undefined') {
|
|
49
|
+
pushByte(TAGS.AD_JID);
|
|
50
|
+
pushByte(domainType || 0);
|
|
51
|
+
pushByte(device || 0);
|
|
52
|
+
writeString(user);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
pushByte(TAGS.JID_PAIR);
|
|
56
|
+
if (user.length) {
|
|
57
|
+
writeString(user);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
pushByte(TAGS.LIST_EMPTY);
|
|
61
|
+
}
|
|
62
|
+
writeString(server);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const packNibble = (char) => {
|
|
66
|
+
switch (char) {
|
|
67
|
+
case '-':
|
|
68
|
+
return 10;
|
|
69
|
+
case '.':
|
|
70
|
+
return 11;
|
|
71
|
+
case '\0':
|
|
72
|
+
return 15;
|
|
73
|
+
default:
|
|
74
|
+
if (char >= '0' && char <= '9') {
|
|
75
|
+
return char.charCodeAt(0) - '0'.charCodeAt(0);
|
|
76
|
+
}
|
|
77
|
+
throw new Error(`invalid byte for nibble "${char}"`);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
const packHex = (char) => {
|
|
81
|
+
if (char >= '0' && char <= '9') {
|
|
82
|
+
return char.charCodeAt(0) - '0'.charCodeAt(0);
|
|
83
|
+
}
|
|
84
|
+
if (char >= 'A' && char <= 'F') {
|
|
85
|
+
return 10 + char.charCodeAt(0) - 'A'.charCodeAt(0);
|
|
86
|
+
}
|
|
87
|
+
if (char >= 'a' && char <= 'f') {
|
|
88
|
+
return 10 + char.charCodeAt(0) - 'a'.charCodeAt(0);
|
|
89
|
+
}
|
|
90
|
+
if (char === '\0') {
|
|
91
|
+
return 15;
|
|
92
|
+
}
|
|
93
|
+
throw new Error(`Invalid hex char "${char}"`);
|
|
94
|
+
};
|
|
95
|
+
const writePackedBytes = (str, type) => {
|
|
96
|
+
if (str.length > TAGS.PACKED_MAX) {
|
|
97
|
+
throw new Error('Too many bytes to pack');
|
|
98
|
+
}
|
|
99
|
+
pushByte(type === 'nibble' ? TAGS.NIBBLE_8 : TAGS.HEX_8);
|
|
100
|
+
let roundedLength = Math.ceil(str.length / 2.0);
|
|
101
|
+
if (str.length % 2 !== 0) {
|
|
102
|
+
roundedLength |= 128;
|
|
103
|
+
}
|
|
104
|
+
pushByte(roundedLength);
|
|
105
|
+
const packFunction = type === 'nibble' ? packNibble : packHex;
|
|
106
|
+
const packBytePair = (v1, v2) => {
|
|
107
|
+
const result = (packFunction(v1) << 4) | packFunction(v2);
|
|
108
|
+
return result;
|
|
109
|
+
};
|
|
110
|
+
const strLengthHalf = Math.floor(str.length / 2);
|
|
111
|
+
for (let i = 0; i < strLengthHalf; i++) {
|
|
112
|
+
pushByte(packBytePair(str[2 * i], str[2 * i + 1]));
|
|
113
|
+
}
|
|
114
|
+
if (str.length % 2 !== 0) {
|
|
115
|
+
pushByte(packBytePair(str[str.length - 1], '\x00'));
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
const isNibble = (str) => {
|
|
119
|
+
if (!str || str.length > TAGS.PACKED_MAX) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
for (const char of str) {
|
|
123
|
+
const isInNibbleRange = char >= '0' && char <= '9';
|
|
124
|
+
if (!isInNibbleRange && char !== '-' && char !== '.') {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return true;
|
|
129
|
+
};
|
|
130
|
+
const isHex = (str) => {
|
|
131
|
+
if (!str || str.length > TAGS.PACKED_MAX) {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
for (const char of str) {
|
|
135
|
+
const isInNibbleRange = char >= '0' && char <= '9';
|
|
136
|
+
if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return true;
|
|
141
|
+
};
|
|
142
|
+
const writeString = (str) => {
|
|
143
|
+
if (str === undefined || str === null) {
|
|
144
|
+
pushByte(TAGS.LIST_EMPTY);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (str === '') {
|
|
148
|
+
writeStringRaw(str);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const tokenIndex = TOKEN_MAP[str];
|
|
152
|
+
if (tokenIndex) {
|
|
153
|
+
if (typeof tokenIndex.dict === 'number') {
|
|
154
|
+
pushByte(TAGS.DICTIONARY_0 + tokenIndex.dict);
|
|
155
|
+
}
|
|
156
|
+
pushByte(tokenIndex.index);
|
|
157
|
+
}
|
|
158
|
+
else if (isNibble(str)) {
|
|
159
|
+
writePackedBytes(str, 'nibble');
|
|
160
|
+
}
|
|
161
|
+
else if (isHex(str)) {
|
|
162
|
+
writePackedBytes(str, 'hex');
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
const decodedJid = jidDecode(str);
|
|
166
|
+
if (decodedJid) {
|
|
167
|
+
writeJid(decodedJid);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
writeStringRaw(str);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
const writeListStart = (listSize) => {
|
|
175
|
+
if (listSize === 0) {
|
|
176
|
+
pushByte(TAGS.LIST_EMPTY);
|
|
177
|
+
}
|
|
178
|
+
else if (listSize < 256) {
|
|
179
|
+
pushBytes([TAGS.LIST_8, listSize]);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
pushByte(TAGS.LIST_16);
|
|
183
|
+
pushInt16(listSize);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
if (!tag) {
|
|
187
|
+
throw new Error('Invalid node: tag cannot be undefined');
|
|
188
|
+
}
|
|
189
|
+
const validAttributes = Object.keys(attrs || {}).filter(k => typeof attrs[k] !== 'undefined' && attrs[k] !== null);
|
|
190
|
+
writeListStart(2 * validAttributes.length + 1 + (typeof content !== 'undefined' ? 1 : 0));
|
|
191
|
+
writeString(tag);
|
|
192
|
+
for (const key of validAttributes) {
|
|
193
|
+
if (typeof attrs[key] === 'string') {
|
|
194
|
+
writeString(key);
|
|
195
|
+
writeString(attrs[key]);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (typeof content === 'string') {
|
|
199
|
+
writeString(content);
|
|
200
|
+
}
|
|
201
|
+
else if (Buffer.isBuffer(content) || content instanceof Uint8Array) {
|
|
202
|
+
writeByteLength(content.length);
|
|
203
|
+
pushBytes(content);
|
|
204
|
+
}
|
|
205
|
+
else if (Array.isArray(content)) {
|
|
206
|
+
const validContent = content.filter(item => item && (item.tag || Buffer.isBuffer(item) || item instanceof Uint8Array || typeof item === 'string'));
|
|
207
|
+
writeListStart(validContent.length);
|
|
208
|
+
for (const item of validContent) {
|
|
209
|
+
encodeBinaryNodeInner(item, opts, buffer);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
else if (typeof content === 'undefined') {
|
|
213
|
+
// do nothing
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`);
|
|
217
|
+
}
|
|
218
|
+
return buffer;
|
|
219
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export function binaryNodeToString(node: any, i?: number): any;
|
|
2
|
+
export function getBinaryNodeChildren(node: any, childTag: any): any;
|
|
3
|
+
export function getBinaryNodeChild(node: any, childTag: any): any;
|
|
4
|
+
export function getAllBinaryNodeChildren({ content }: {
|
|
5
|
+
content: any;
|
|
6
|
+
}): any[];
|
|
7
|
+
export function getBinaryNodeChildBuffer(node: any, childTag: any): any;
|
|
8
|
+
export function getBinaryNodeChildString(node: any, childTag: any): any;
|
|
9
|
+
export function getBinaryNodeChildUInt(node: any, childTag: any, length: any): number | undefined;
|
|
10
|
+
export function assertNodeErrorFree(node: any): void;
|
|
11
|
+
export function reduceBinaryNodeToDictionary(node: any, tag: any): any;
|
|
12
|
+
export function getBinaryNodeMessages({ content }: {
|
|
13
|
+
content: any;
|
|
14
|
+
}): {
|
|
15
|
+
[k: string]: any;
|
|
16
|
+
}[];
|
|
17
|
+
export function getBizBinaryNode(message: any): {
|
|
18
|
+
tag: string;
|
|
19
|
+
attrs: {
|
|
20
|
+
actual_actors: string;
|
|
21
|
+
host_storage: string;
|
|
22
|
+
privacy_mode_ts: string;
|
|
23
|
+
};
|
|
24
|
+
content: ({
|
|
25
|
+
tag: string;
|
|
26
|
+
attrs: {
|
|
27
|
+
decision_id: any;
|
|
28
|
+
source_type: string;
|
|
29
|
+
};
|
|
30
|
+
content: {
|
|
31
|
+
tag: string;
|
|
32
|
+
attrs: {
|
|
33
|
+
value: string;
|
|
34
|
+
};
|
|
35
|
+
}[];
|
|
36
|
+
} | {
|
|
37
|
+
tag: string;
|
|
38
|
+
attrs: {
|
|
39
|
+
type: string;
|
|
40
|
+
v: string;
|
|
41
|
+
};
|
|
42
|
+
content: {
|
|
43
|
+
tag: string;
|
|
44
|
+
attrs: {
|
|
45
|
+
name: any;
|
|
46
|
+
v?: undefined;
|
|
47
|
+
} | {
|
|
48
|
+
v: string;
|
|
49
|
+
name: any;
|
|
50
|
+
};
|
|
51
|
+
}[];
|
|
52
|
+
})[];
|
|
53
|
+
} | {
|
|
54
|
+
tag: string;
|
|
55
|
+
attrs: {
|
|
56
|
+
actual_actors: string;
|
|
57
|
+
host_storage: string;
|
|
58
|
+
privacy_mode_ts: string;
|
|
59
|
+
};
|
|
60
|
+
content: ({
|
|
61
|
+
tag: string;
|
|
62
|
+
attrs: {
|
|
63
|
+
decision_id: any;
|
|
64
|
+
source_type: string;
|
|
65
|
+
};
|
|
66
|
+
content: {
|
|
67
|
+
tag: string;
|
|
68
|
+
attrs: {
|
|
69
|
+
value: string;
|
|
70
|
+
};
|
|
71
|
+
}[];
|
|
72
|
+
} | {
|
|
73
|
+
tag: string;
|
|
74
|
+
attrs: {
|
|
75
|
+
v: string;
|
|
76
|
+
type: string;
|
|
77
|
+
};
|
|
78
|
+
})[];
|
|
79
|
+
};
|