@eduh_dev021/baileys 0.0.0-stage → 1.0.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 +495 -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/http-error.d.ts +18 -0
- package/cjs/lib/Addon/http-error.js +66 -0
- package/cjs/lib/Addon/index.d.ts +3 -0
- package/cjs/lib/Addon/index.js +50 -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/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/http-error.d.ts +18 -0
- package/lib/Addon/http-error.js +40 -0
- package/lib/Addon/index.d.ts +3 -0
- package/lib/Addon/index.js +4 -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/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 +1911 -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 +369 -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 +228 -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 +79 -5
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vendored from zapo-js v1.12.0 (https://github.com/vinikjkkj/zapo)
|
|
3
|
+
* Copyright (c) vinikjkkj — MIT License <https://github.com/vinikjkkj/zapo/blob/main/LICENSE>
|
|
4
|
+
* Modified for use inside @eduh_dev021/baileys (ESM import paths only).
|
|
5
|
+
* SPDX-License-Identifier: MIT
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { FIELD_P, GROUP_L } from './constants.js';
|
|
9
|
+
export function mod(value, modulus = FIELD_P) {
|
|
10
|
+
const remainder = value % modulus;
|
|
11
|
+
return remainder >= 0n ? remainder : remainder + modulus;
|
|
12
|
+
}
|
|
13
|
+
export function modGroup(value) {
|
|
14
|
+
return mod(value, GROUP_L);
|
|
15
|
+
}
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vendored from zapo-js v1.12.0 (https://github.com/vinikjkkj/zapo)
|
|
3
|
+
* Copyright (c) vinikjkkj — MIT License <https://github.com/vinikjkkj/zapo/blob/main/LICENSE>
|
|
4
|
+
* Modified for use inside @eduh_dev021/baileys (ESM import paths only).
|
|
5
|
+
* SPDX-License-Identifier: MIT
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { timingSafeEqual } from 'node:crypto';
|
|
9
|
+
export const TEXT_ENCODER = new TextEncoder();
|
|
10
|
+
export const TEXT_DECODER = new TextDecoder();
|
|
11
|
+
export const ZERO_BYTES = new Uint8Array([0]);
|
|
12
|
+
export const EMPTY_BYTES = Object.freeze(new Uint8Array(0));
|
|
13
|
+
const HEX_CHARS = '0123456789abcdef';
|
|
14
|
+
const HEX_TABLE = /* @__PURE__ */ (() => {
|
|
15
|
+
const table = new Array(256);
|
|
16
|
+
for (let i = 0; i < 256; i += 1) {
|
|
17
|
+
table[i] = HEX_CHARS[i >> 4] + HEX_CHARS[i & 0x0f];
|
|
18
|
+
}
|
|
19
|
+
return table;
|
|
20
|
+
})();
|
|
21
|
+
const HEX_LOOKUP = /* @__PURE__ */ (() => {
|
|
22
|
+
const table = new Int8Array(128).fill(-1);
|
|
23
|
+
for (let i = 0x30; i <= 0x39; i += 1)
|
|
24
|
+
table[i] = i - 0x30;
|
|
25
|
+
for (let i = 0x41; i <= 0x46; i += 1)
|
|
26
|
+
table[i] = i - 0x41 + 10;
|
|
27
|
+
for (let i = 0x61; i <= 0x66; i += 1)
|
|
28
|
+
table[i] = i - 0x61 + 10;
|
|
29
|
+
return table;
|
|
30
|
+
})();
|
|
31
|
+
const BASE64_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
32
|
+
const BASE64URL_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
|
|
33
|
+
const BASE64_LOOKUP = /* @__PURE__ */ (() => {
|
|
34
|
+
const table = new Uint8Array(128).fill(0xff);
|
|
35
|
+
for (let i = 0; i < BASE64_CHARS.length; i += 1) {
|
|
36
|
+
table[BASE64_CHARS.charCodeAt(i)] = i;
|
|
37
|
+
}
|
|
38
|
+
table[0x3d] = 0; // '='
|
|
39
|
+
return table;
|
|
40
|
+
})();
|
|
41
|
+
/**
|
|
42
|
+
* Encodes a Uint8Array to a hex string
|
|
43
|
+
*/
|
|
44
|
+
export function bytesToHex(value) {
|
|
45
|
+
let out = '';
|
|
46
|
+
for (let i = 0; i < value.length; i += 1) {
|
|
47
|
+
out += HEX_TABLE[value[i]];
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Decodes a hex string to a Uint8Array
|
|
53
|
+
*/
|
|
54
|
+
export function hexToBytes(value) {
|
|
55
|
+
const len = value.length;
|
|
56
|
+
if (len & 1) {
|
|
57
|
+
throw new Error('hex string must have even length');
|
|
58
|
+
}
|
|
59
|
+
const out = new Uint8Array(len >> 1);
|
|
60
|
+
for (let i = 0; i < len; i += 2) {
|
|
61
|
+
const hiCode = value.charCodeAt(i);
|
|
62
|
+
const loCode = value.charCodeAt(i + 1);
|
|
63
|
+
const hi = hiCode < 128 ? HEX_LOOKUP[hiCode] : -1;
|
|
64
|
+
const lo = loCode < 128 ? HEX_LOOKUP[loCode] : -1;
|
|
65
|
+
if ((hi | lo) < 0) {
|
|
66
|
+
throw new Error('invalid hex character');
|
|
67
|
+
}
|
|
68
|
+
out[i >> 1] = (hi << 4) | lo;
|
|
69
|
+
}
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
/** Encodes a Uint8Array to a standard padded base64 string. */
|
|
73
|
+
export function bytesToBase64(value) {
|
|
74
|
+
return encodeBase64(value, BASE64_CHARS, true);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Decodes a standard padded base64 string to a Uint8Array. Throws on invalid
|
|
78
|
+
* characters or a length that is not a multiple of 4.
|
|
79
|
+
*/
|
|
80
|
+
export function base64ToBytes(value) {
|
|
81
|
+
const len = value.length;
|
|
82
|
+
if (len === 0)
|
|
83
|
+
return EMPTY_BYTES;
|
|
84
|
+
if ((len & 3) !== 0) {
|
|
85
|
+
throw new Error('base64 string length must be multiple of 4');
|
|
86
|
+
}
|
|
87
|
+
let padding = 0;
|
|
88
|
+
if (value.charCodeAt(len - 1) === 0x3d)
|
|
89
|
+
padding += 1;
|
|
90
|
+
if (value.charCodeAt(len - 2) === 0x3d)
|
|
91
|
+
padding += 1;
|
|
92
|
+
const outLen = ((len * 3) >> 2) - padding;
|
|
93
|
+
const out = new Uint8Array(outLen);
|
|
94
|
+
let j = 0;
|
|
95
|
+
const mainLen = len - 4;
|
|
96
|
+
let i = 0;
|
|
97
|
+
for (; i < mainLen; i += 4) {
|
|
98
|
+
const a = lookupBase64(value.charCodeAt(i));
|
|
99
|
+
const b = lookupBase64(value.charCodeAt(i + 1));
|
|
100
|
+
const c = lookupBase64(value.charCodeAt(i + 2));
|
|
101
|
+
const d = lookupBase64(value.charCodeAt(i + 3));
|
|
102
|
+
out[j++] = (a << 2) | (b >> 4);
|
|
103
|
+
out[j++] = ((b & 0x0f) << 4) | (c >> 2);
|
|
104
|
+
out[j++] = ((c & 0x03) << 6) | d;
|
|
105
|
+
}
|
|
106
|
+
const a = lookupBase64(value.charCodeAt(i));
|
|
107
|
+
const b = lookupBase64(value.charCodeAt(i + 1));
|
|
108
|
+
out[j++] = (a << 2) | (b >> 4);
|
|
109
|
+
if (j < outLen) {
|
|
110
|
+
const c = lookupBase64(value.charCodeAt(i + 2));
|
|
111
|
+
out[j++] = ((b & 0x0f) << 4) | (c >> 2);
|
|
112
|
+
if (j < outLen) {
|
|
113
|
+
const d = lookupBase64(value.charCodeAt(i + 3));
|
|
114
|
+
out[j++] = ((c & 0x03) << 6) | d;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return out;
|
|
118
|
+
}
|
|
119
|
+
export function base64ToBytesChecked(value, field) {
|
|
120
|
+
if (value.length === 0) {
|
|
121
|
+
throw new Error(`invalid base64 payload for ${field}`);
|
|
122
|
+
}
|
|
123
|
+
return base64ToBytes(value);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Decodes a base64url-encoded value to a Uint8Array, restoring padding and
|
|
127
|
+
* the `+`/`/` alphabet first. Throws with a `missing ${field}` message when
|
|
128
|
+
* `value` is empty/undefined.
|
|
129
|
+
*/
|
|
130
|
+
export function decodeBase64Url(value, field) {
|
|
131
|
+
if (!value) {
|
|
132
|
+
throw new Error(`missing ${field}`);
|
|
133
|
+
}
|
|
134
|
+
const padded = value
|
|
135
|
+
.replace(/-/g, '+')
|
|
136
|
+
.replace(/_/g, '/')
|
|
137
|
+
.padEnd(Math.ceil(value.length / 4) * 4, '=');
|
|
138
|
+
return base64ToBytesChecked(padded, field);
|
|
139
|
+
}
|
|
140
|
+
export function assertByteLength(value, expectedLength, errorMessage) {
|
|
141
|
+
if (value.length !== expectedLength) {
|
|
142
|
+
throw new Error(errorMessage);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
export function decodeProtoBytes(value, field) {
|
|
146
|
+
if (value === null || value === undefined) {
|
|
147
|
+
throw new Error(`missing protobuf bytes field ${field}`);
|
|
148
|
+
}
|
|
149
|
+
if (value instanceof Uint8Array) {
|
|
150
|
+
return value;
|
|
151
|
+
}
|
|
152
|
+
return base64ToBytes(value);
|
|
153
|
+
}
|
|
154
|
+
function lookupBase64(code) {
|
|
155
|
+
if (code > 127) {
|
|
156
|
+
throw new Error('invalid base64 character');
|
|
157
|
+
}
|
|
158
|
+
const v = BASE64_LOOKUP[code];
|
|
159
|
+
if (v === 0xff) {
|
|
160
|
+
throw new Error('invalid base64 character');
|
|
161
|
+
}
|
|
162
|
+
return v;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Encodes a Uint8Array to a base64url string (URL-safe, no padding)
|
|
166
|
+
*/
|
|
167
|
+
export function bytesToBase64UrlSafe(value) {
|
|
168
|
+
return encodeBase64(value, BASE64URL_CHARS, false);
|
|
169
|
+
}
|
|
170
|
+
function encodeBase64(value, alphabet, pad) {
|
|
171
|
+
const len = value.length;
|
|
172
|
+
if (len === 0)
|
|
173
|
+
return '';
|
|
174
|
+
const remainder = len % 3;
|
|
175
|
+
const mainLen = len - remainder;
|
|
176
|
+
const chunks = Math.ceil(len / 3);
|
|
177
|
+
const out = new Array(pad ? chunks * 4 : Math.ceil((len * 4) / 3));
|
|
178
|
+
let k = 0;
|
|
179
|
+
for (let i = 0; i < mainLen; i += 3) {
|
|
180
|
+
const a = value[i];
|
|
181
|
+
const b = value[i + 1];
|
|
182
|
+
const c = value[i + 2];
|
|
183
|
+
out[k++] = alphabet[a >> 2];
|
|
184
|
+
out[k++] = alphabet[((a & 0x03) << 4) | (b >> 4)];
|
|
185
|
+
out[k++] = alphabet[((b & 0x0f) << 2) | (c >> 6)];
|
|
186
|
+
out[k++] = alphabet[c & 0x3f];
|
|
187
|
+
}
|
|
188
|
+
if (remainder === 1) {
|
|
189
|
+
const a = value[mainLen];
|
|
190
|
+
out[k++] = alphabet[a >> 2];
|
|
191
|
+
out[k++] = alphabet[(a & 0x03) << 4];
|
|
192
|
+
if (pad) {
|
|
193
|
+
out[k++] = '=';
|
|
194
|
+
out[k++] = '=';
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
else if (remainder === 2) {
|
|
198
|
+
const a = value[mainLen];
|
|
199
|
+
const b = value[mainLen + 1];
|
|
200
|
+
out[k++] = alphabet[a >> 2];
|
|
201
|
+
out[k++] = alphabet[((a & 0x03) << 4) | (b >> 4)];
|
|
202
|
+
out[k++] = alphabet[(b & 0x0f) << 2];
|
|
203
|
+
if (pad) {
|
|
204
|
+
out[k++] = '=';
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return out.join('');
|
|
208
|
+
}
|
|
209
|
+
/** Concatenates an array of Uint8Arrays into a single new Uint8Array. */
|
|
210
|
+
export function concatBytes(parts) {
|
|
211
|
+
let total = 0;
|
|
212
|
+
for (let i = 0; i < parts.length; i += 1) {
|
|
213
|
+
total += parts[i].length;
|
|
214
|
+
}
|
|
215
|
+
const out = new Uint8Array(total);
|
|
216
|
+
let offset = 0;
|
|
217
|
+
for (let i = 0; i < parts.length; i += 1) {
|
|
218
|
+
out.set(parts[i], offset);
|
|
219
|
+
offset += parts[i].length;
|
|
220
|
+
}
|
|
221
|
+
return out;
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Returns a zero-copy `Uint8Array` view over the input. Subclasses of
|
|
225
|
+
* `Uint8Array` (Node `Buffer`) are wrapped in a plain view; `ArrayBuffer`/
|
|
226
|
+
* `ArrayBufferView` get a view over their backing buffer. Use at system
|
|
227
|
+
* boundaries (WebCrypto / Node crypto / WebSocket results) – not on values
|
|
228
|
+
* that are already plain `Uint8Array`.
|
|
229
|
+
*/
|
|
230
|
+
export function toBytesView(value) {
|
|
231
|
+
if (value instanceof Uint8Array) {
|
|
232
|
+
return value.constructor === Uint8Array
|
|
233
|
+
? value
|
|
234
|
+
: new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
235
|
+
}
|
|
236
|
+
if (value instanceof ArrayBuffer) {
|
|
237
|
+
return new Uint8Array(value);
|
|
238
|
+
}
|
|
239
|
+
return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Normalizes an arbitrary stream chunk (string / Uint8Array / ArrayBuffer /
|
|
243
|
+
* ArrayBufferView) to a Uint8Array. Throws on unsupported types.
|
|
244
|
+
*/
|
|
245
|
+
export function toChunkBytes(chunk) {
|
|
246
|
+
if (typeof chunk === 'string') {
|
|
247
|
+
return TEXT_ENCODER.encode(chunk);
|
|
248
|
+
}
|
|
249
|
+
if (chunk instanceof Uint8Array || chunk instanceof ArrayBuffer || ArrayBuffer.isView(chunk)) {
|
|
250
|
+
return toBytesView(chunk);
|
|
251
|
+
}
|
|
252
|
+
throw new Error(`unsupported stream chunk type: ${typeof chunk}`);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Constant-time, JIT-resistant equality over `Uint8Array`s. Required for
|
|
256
|
+
* MAC/HMAC/signature comparisons (use {@link uint8Equal} for non-secret data).
|
|
257
|
+
*/
|
|
258
|
+
export function uint8TimingSafeEqual(left, right) {
|
|
259
|
+
if (left.byteLength !== right.byteLength) {
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
return timingSafeEqual(left, right);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* XOR-accumulated equality over `Uint8Array`s. Suitable for non-secret data
|
|
266
|
+
* (e.g. identity key match). Use {@link uint8TimingSafeEqual} for MAC checks.
|
|
267
|
+
*/
|
|
268
|
+
export function uint8Equal(a, b) {
|
|
269
|
+
if (a.length !== b.length) {
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
let diff = 0;
|
|
273
|
+
for (let i = 0; i < a.length; i += 1) {
|
|
274
|
+
diff |= a[i] ^ b[i];
|
|
275
|
+
}
|
|
276
|
+
return diff === 0;
|
|
277
|
+
}
|
|
278
|
+
export function removeAt(items, index) {
|
|
279
|
+
if (items.length === 0) {
|
|
280
|
+
return [];
|
|
281
|
+
}
|
|
282
|
+
if (index < 0 || index >= items.length) {
|
|
283
|
+
const out = new Array(items.length);
|
|
284
|
+
for (let i = 0; i < items.length; i += 1) {
|
|
285
|
+
out[i] = items[i];
|
|
286
|
+
}
|
|
287
|
+
return out;
|
|
288
|
+
}
|
|
289
|
+
const out = new Array(items.length - 1);
|
|
290
|
+
let k = 0;
|
|
291
|
+
for (let i = 0; i < items.length; i += 1) {
|
|
292
|
+
if (i !== index) {
|
|
293
|
+
out[k++] = items[i];
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return out;
|
|
297
|
+
}
|
|
298
|
+
export function intToBytes(byteLength, value) {
|
|
299
|
+
if (!Number.isSafeInteger(value) || value < 0) {
|
|
300
|
+
throw new Error(`invalid integer value: ${value}`);
|
|
301
|
+
}
|
|
302
|
+
const out = new Uint8Array(byteLength);
|
|
303
|
+
let current = value;
|
|
304
|
+
for (let i = byteLength - 1; i >= 0; i -= 1) {
|
|
305
|
+
out[i] = current & 0xff;
|
|
306
|
+
current = Math.floor(current / 256);
|
|
307
|
+
}
|
|
308
|
+
return out;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Drains a Node `Readable` stream into a single Uint8Array. When
|
|
312
|
+
* `options.maxBytes` is set, the stream is destroyed and the promise rejects
|
|
313
|
+
* once the limit is exceeded.
|
|
314
|
+
*/
|
|
315
|
+
export async function readAllBytes(stream, options = {}) {
|
|
316
|
+
const maxBytes = options.maxBytes;
|
|
317
|
+
if (maxBytes !== undefined && (!Number.isSafeInteger(maxBytes) || maxBytes < 0)) {
|
|
318
|
+
throw new Error(`invalid max bytes limit: ${maxBytes}`);
|
|
319
|
+
}
|
|
320
|
+
const chunks = [];
|
|
321
|
+
let total = 0;
|
|
322
|
+
for await (const chunk of stream) {
|
|
323
|
+
const bytes = toChunkBytes(chunk);
|
|
324
|
+
chunks.push(bytes);
|
|
325
|
+
total += bytes.byteLength;
|
|
326
|
+
if (maxBytes !== undefined && total > maxBytes) {
|
|
327
|
+
const error = new Error(`stream exceeded max bytes limit (${maxBytes})`);
|
|
328
|
+
stream.destroy(error);
|
|
329
|
+
throw error;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
if (total === 0) {
|
|
333
|
+
return EMPTY_BYTES;
|
|
334
|
+
}
|
|
335
|
+
if (chunks.length === 1) {
|
|
336
|
+
return chunks[0];
|
|
337
|
+
}
|
|
338
|
+
return concatBytes(chunks);
|
|
339
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure-TypeScript X25519 (curve25519) operations backed by Node.js native crypto.
|
|
3
|
+
*
|
|
4
|
+
* Replaces the `whatsapp-rust-bridge` WASM dependency used by the original
|
|
5
|
+
* @itsliaaa/baileys fork. Function signatures and output shapes are kept
|
|
6
|
+
* byte-compatible with the WASM bridge so no other code changes are needed.
|
|
7
|
+
*
|
|
8
|
+
* Key-derivation logic (Edwards encoding of the public key) is derived from
|
|
9
|
+
* zapo-js v1.12.0 (https://github.com/vinikjkkj/zapo) by vinikjkkj — MIT License.
|
|
10
|
+
* SPDX-License-Identifier: MIT
|
|
11
|
+
*/
|
|
12
|
+
import {
|
|
13
|
+
createPrivateKey,
|
|
14
|
+
createPublicKey,
|
|
15
|
+
diffieHellman,
|
|
16
|
+
generateKeyPairSync
|
|
17
|
+
} from 'node:crypto';
|
|
18
|
+
import { fe, feAdd, feFromBytes, feInv, feMul, fePack, feSub } from './math/fe.js';
|
|
19
|
+
import { FE_ONE } from './math/constants.js';
|
|
20
|
+
import { encodeExtendedPoint, scalarMultBase } from './math/edwards.js';
|
|
21
|
+
import { bytesToBigIntLE } from './math/le.js';
|
|
22
|
+
import { assertByteLength, concatBytes } from './util/bytes.js';
|
|
23
|
+
|
|
24
|
+
const X25519_PKCS8_PREFIX = Uint8Array.from([
|
|
25
|
+
0x30, 0x2e, 0x02, 0x01, 0x00, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x6e, 0x04, 0x22, 0x04, 0x20
|
|
26
|
+
]);
|
|
27
|
+
const X25519_SPKI_PREFIX = Uint8Array.from([
|
|
28
|
+
0x30, 0x2a, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x6e, 0x03, 0x21, 0x00
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
const VERSION_BYTE = 0x05;
|
|
32
|
+
|
|
33
|
+
/** Applies the standard curve25519 scalar clamping in place. Ported from zapo-js. */
|
|
34
|
+
export function clampCurvePrivateKeyInPlace(privateKey) {
|
|
35
|
+
assertByteLength(privateKey, 32, `invalid curve25519 private key length ${privateKey.length}`);
|
|
36
|
+
privateKey[0] &= 248;
|
|
37
|
+
privateKey[31] &= 127;
|
|
38
|
+
privateKey[31] |= 64;
|
|
39
|
+
return privateKey;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// p-1 = 2^255-20 in LE bytes: 0xEC, 0xFF×30, 0x7F
|
|
43
|
+
// Mask bit 255 before comparing (non-canonical inputs may have it set)
|
|
44
|
+
function isFieldPMinus1(b) {
|
|
45
|
+
if (b[0] !== 0xec || (b[31] & 0x7f) !== 0x7f)
|
|
46
|
+
return false;
|
|
47
|
+
for (let i = 1; i < 31; i++)
|
|
48
|
+
if (b[i] !== 0xff)
|
|
49
|
+
return false;
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Pre-allocated temps for montgomeryToEdwardsPublic (safe: single-threaded)
|
|
54
|
+
const _mx = fe();
|
|
55
|
+
const _m1 = fe();
|
|
56
|
+
const _m2 = fe();
|
|
57
|
+
const _m3 = fe();
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Converts a 32-byte Montgomery (curve25519) public key to its Edwards form
|
|
61
|
+
* for XEdDSA verification, applying the supplied `signBit` (`0x80` mask).
|
|
62
|
+
* Ported from zapo-js (crypto/curves/X25519.js).
|
|
63
|
+
*/
|
|
64
|
+
export function montgomeryToEdwardsPublic(curvePublicKey, signBit) {
|
|
65
|
+
assertByteLength(curvePublicKey, 32, `invalid curve25519 public key length ${curvePublicKey.length}`);
|
|
66
|
+
if (isFieldPMinus1(curvePublicKey)) {
|
|
67
|
+
throw new Error('invalid curve25519 low-order public key');
|
|
68
|
+
}
|
|
69
|
+
feFromBytes(_mx, curvePublicKey);
|
|
70
|
+
feSub(_m1, _mx, FE_ONE);
|
|
71
|
+
feAdd(_m2, _mx, FE_ONE);
|
|
72
|
+
feInv(_m3, _m2);
|
|
73
|
+
feMul(_m1, _m1, _m3);
|
|
74
|
+
const encoded = new Uint8Array(32);
|
|
75
|
+
fePack(encoded, _m1);
|
|
76
|
+
encoded[31] = (encoded[31] & 0x7f) | (signBit & 0x80);
|
|
77
|
+
return encoded;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Derives the clamped private scalar and its Edwards-encoded public key. */
|
|
81
|
+
export function deriveEdwardsKeyMaterial(privateKey) {
|
|
82
|
+
const clamped = Uint8Array.from(privateKey);
|
|
83
|
+
clampCurvePrivateKeyInPlace(clamped);
|
|
84
|
+
const privateScalar = bytesToBigIntLE(clamped);
|
|
85
|
+
const encodedPublic = encodeExtendedPoint(scalarMultBase(privateScalar));
|
|
86
|
+
return { clamped, privateScalar, encodedPublic };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function privateToKeyObject(privKey) {
|
|
90
|
+
return createPrivateKey({
|
|
91
|
+
key: concatBytes([X25519_PKCS8_PREFIX, privKey]),
|
|
92
|
+
format: 'der',
|
|
93
|
+
type: 'pkcs8'
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function publicToKeyObject(pubKey) {
|
|
98
|
+
return createPublicKey({
|
|
99
|
+
key: concatBytes([X25519_SPKI_PREFIX, pubKey]),
|
|
100
|
+
format: 'der',
|
|
101
|
+
type: 'spki'
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Accepts raw 32-byte public keys and Signal version-prefixed (0x05) 33-byte keys. */
|
|
106
|
+
function normalizePublicKey(pubKey) {
|
|
107
|
+
if (pubKey.byteLength === 33 && pubKey[0] === VERSION_BYTE) {
|
|
108
|
+
return pubKey.subarray(1);
|
|
109
|
+
}
|
|
110
|
+
assertByteLength(pubKey, 32, `invalid curve25519 public key length ${pubKey.byteLength}`);
|
|
111
|
+
return pubKey;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Generates a fresh X25519 key pair.
|
|
116
|
+
* `pubKey` is 33 bytes: `[0x05, ...32-byte public]` (Signal version byte),
|
|
117
|
+
* `privKey` is the clamped 32-byte scalar — identical to the WASM bridge output.
|
|
118
|
+
*/
|
|
119
|
+
export function generateKeyPair() {
|
|
120
|
+
const { publicKey, privateKey } = generateKeyPairSync('x25519');
|
|
121
|
+
const rawPub = publicKey.export({ format: 'der', type: 'spki' }).subarray(X25519_SPKI_PREFIX.length);
|
|
122
|
+
const rawPriv = privateKey.export({ format: 'der', type: 'pkcs8' }).subarray(X25519_PKCS8_PREFIX.length);
|
|
123
|
+
clampCurvePrivateKeyInPlace(rawPriv);
|
|
124
|
+
return {
|
|
125
|
+
pubKey: concatBytes([Uint8Array.of(VERSION_BYTE), rawPub]),
|
|
126
|
+
privKey: rawPriv
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Derives the 33-byte public key (`[0x05, ...]`) from a 32-byte private key,
|
|
132
|
+
* using the Edwards (XEdDSA) encoding — byte-compatible with the WASM bridge.
|
|
133
|
+
*/
|
|
134
|
+
export function getPublicFromPrivateKey(privKey) {
|
|
135
|
+
const { encodedPublic } = deriveEdwardsKeyMaterial(privKey);
|
|
136
|
+
return concatBytes([Uint8Array.of(VERSION_BYTE), encodedPublic]);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Standard X25519 Diffie-Hellman between a 32/33-byte public and 32-byte private key. */
|
|
140
|
+
export function calculateAgreement(pubKey, privKey) {
|
|
141
|
+
assertByteLength(privKey, 32, `invalid curve25519 private key length ${privKey.byteLength}`);
|
|
142
|
+
const priv = privateToKeyObject(privKey);
|
|
143
|
+
const pub = publicToKeyObject(normalizePublicKey(pubKey));
|
|
144
|
+
return diffieHellman({ privateKey: priv, publicKey: pub });
|
|
145
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Synchronous XEdDSA (sign/verify) for curve25519 keys, derived from the
|
|
3
|
+
* zapo-js v1.12.0 implementation (https://github.com/vinikjkkj/zapo) by
|
|
4
|
+
* vinikjkkj — MIT License. Converted from async to sync and adapted to the
|
|
5
|
+
* `whatsapp-rust-bridge` API surface used by @eduh_dev021/baileys.
|
|
6
|
+
* SPDX-License-Identifier: MIT
|
|
7
|
+
*/
|
|
8
|
+
import { createHash, createPublicKey, randomBytes, verify as nodeVerify } from 'node:crypto';
|
|
9
|
+
import { encodeExtendedPoint, scalarMultBase } from './math/edwards.js';
|
|
10
|
+
import { bytesToBigIntLE, bigIntToBytesLE } from './math/le.js';
|
|
11
|
+
import { modGroup } from './math/mod.js';
|
|
12
|
+
import { assertByteLength, concatBytes } from './util/bytes.js';
|
|
13
|
+
import { deriveEdwardsKeyMaterial, montgomeryToEdwardsPublic } from './x25519.js';
|
|
14
|
+
|
|
15
|
+
const ED25519_SPKI_PREFIX = Uint8Array.from([
|
|
16
|
+
0x30, 0x2a, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, 0x70, 0x03, 0x21, 0x00
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
// 0xFE followed by 31 × 0xFF — XEdDSA nonce-derivation prefix (port of zapo-js).
|
|
20
|
+
const PREFIX_SIGNATURE_RANDOM = Uint8Array.from([
|
|
21
|
+
0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
22
|
+
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
function sha512Chunks(chunks) {
|
|
26
|
+
const hash = createHash('sha512');
|
|
27
|
+
for (const chunk of chunks) {
|
|
28
|
+
hash.update(chunk);
|
|
29
|
+
}
|
|
30
|
+
return hash.digest();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Signs `message` with an X25519 (Montgomery) private key using the XEdDSA
|
|
35
|
+
* construction with a random nonce (matching the WASM bridge behaviour).
|
|
36
|
+
* Returns a 64-byte signature.
|
|
37
|
+
*/
|
|
38
|
+
export function calculateSignature(privateKey, message) {
|
|
39
|
+
assertByteLength(privateKey, 32, `invalid curve25519 private key length ${privateKey.length}`);
|
|
40
|
+
const { clamped, privateScalar, encodedPublic } = deriveEdwardsKeyMaterial(privateKey);
|
|
41
|
+
const pubKeySignBit = encodedPublic[31] & 0x80;
|
|
42
|
+
const randomSuffix = randomBytes(64);
|
|
43
|
+
const r = modGroup(bytesToBigIntLE(sha512Chunks([
|
|
44
|
+
PREFIX_SIGNATURE_RANDOM,
|
|
45
|
+
clamped,
|
|
46
|
+
message,
|
|
47
|
+
randomSuffix
|
|
48
|
+
])));
|
|
49
|
+
const encodedR = encodeExtendedPoint(scalarMultBase(r));
|
|
50
|
+
const h = modGroup(bytesToBigIntLE(sha512Chunks([encodedR, encodedPublic, message])));
|
|
51
|
+
const s = modGroup(r + h * privateScalar);
|
|
52
|
+
const encodedS = bigIntToBytesLE(s, 32);
|
|
53
|
+
encodedS[31] = (encodedS[31] & 0x7f) | pubKeySignBit;
|
|
54
|
+
return concatBytes([encodedR, encodedS]);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Verifies an XEdDSA signature over `message` against an X25519 (Montgomery)
|
|
59
|
+
* public key (32 or 33 bytes, Signal `0x05` prefix accepted). Returns a
|
|
60
|
+
* boolean — never throws — matching the WASM bridge contract.
|
|
61
|
+
*/
|
|
62
|
+
export function verifySignature(publicKey, message, signature) {
|
|
63
|
+
let sig = Uint8Array.from(signature);
|
|
64
|
+
if (sig.byteLength !== 64) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
if ((sig[63] & 0x60) !== 0) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
const lastByteIndex = 63;
|
|
71
|
+
const originalLastByte = sig[lastByteIndex];
|
|
72
|
+
const signBit = originalLastByte & 0x80;
|
|
73
|
+
sig[lastByteIndex] = originalLastByte & 0x7f;
|
|
74
|
+
try {
|
|
75
|
+
const pubKey = publicKey.byteLength === 33 && publicKey[0] === 0x05
|
|
76
|
+
? publicKey.subarray(1)
|
|
77
|
+
: publicKey;
|
|
78
|
+
const edPublic = montgomeryToEdwardsPublic(pubKey, signBit);
|
|
79
|
+
const keyObject = createPublicKey({
|
|
80
|
+
key: concatBytes([ED25519_SPKI_PREFIX, edPublic]),
|
|
81
|
+
format: 'der',
|
|
82
|
+
type: 'spki'
|
|
83
|
+
});
|
|
84
|
+
return nodeVerify(null, message, keyObject, sig);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
sig[lastByteIndex] = originalLastByte;
|
|
91
|
+
}
|
|
92
|
+
}
|