@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,301 @@
|
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
import { calculateMAC, decrypt, deriveSecrets, encrypt, verifyMAC } from './crypto.js';
|
|
3
|
+
import { calculateAgreement, generateKeyPair } from './curve.js';
|
|
4
|
+
import { ChainType, ProtocolAddress, errors, queueJob } from './internals.js';
|
|
5
|
+
import SessionBuilder from './session-builder.js';
|
|
6
|
+
import SessionRecord from './session-record.js';
|
|
7
|
+
const VERSION = 3;
|
|
8
|
+
function assertBuffer(value) {
|
|
9
|
+
if (!Buffer.isBuffer(value)) {
|
|
10
|
+
throw TypeError(`Expected Buffer instead of: ${value.constructor.name}`);
|
|
11
|
+
}
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
class SessionCipher {
|
|
15
|
+
constructor(storage, protocolAddress) {
|
|
16
|
+
if (!(protocolAddress instanceof ProtocolAddress)) {
|
|
17
|
+
throw new TypeError('protocolAddress must be a ProtocolAddress');
|
|
18
|
+
}
|
|
19
|
+
this.addr = protocolAddress;
|
|
20
|
+
this.storage = storage;
|
|
21
|
+
}
|
|
22
|
+
_encodeTupleByte(number1, number2) {
|
|
23
|
+
if (number1 > 15 || number2 > 15) {
|
|
24
|
+
throw TypeError('Numbers must be 4 bits or less');
|
|
25
|
+
}
|
|
26
|
+
return (number1 << 4) | number2;
|
|
27
|
+
}
|
|
28
|
+
_decodeTupleByte(byte) {
|
|
29
|
+
return [byte >> 4, byte & 0xf];
|
|
30
|
+
}
|
|
31
|
+
toString() {
|
|
32
|
+
return `<SessionCipher(${this.addr.toString()})>`;
|
|
33
|
+
}
|
|
34
|
+
async getRecord() {
|
|
35
|
+
const record = await this.storage.loadSession(this.addr.toString());
|
|
36
|
+
if (record && !(record instanceof SessionRecord)) {
|
|
37
|
+
throw new TypeError('SessionRecord type expected from loadSession');
|
|
38
|
+
}
|
|
39
|
+
return record;
|
|
40
|
+
}
|
|
41
|
+
async storeRecord(record) {
|
|
42
|
+
record.removeOldSessions();
|
|
43
|
+
await this.storage.storeSession(this.addr.toString(), record);
|
|
44
|
+
}
|
|
45
|
+
async queueJob(awaitable) {
|
|
46
|
+
return await queueJob(this.addr.toString(), awaitable);
|
|
47
|
+
}
|
|
48
|
+
async encrypt(data) {
|
|
49
|
+
assertBuffer(data);
|
|
50
|
+
const ourIdentityKey = await this.storage.getOurIdentity();
|
|
51
|
+
return await this.queueJob(async () => {
|
|
52
|
+
const record = await this.getRecord();
|
|
53
|
+
if (!record) {
|
|
54
|
+
throw new errors.SessionError('No sessions');
|
|
55
|
+
}
|
|
56
|
+
const session = record.getOpenSession();
|
|
57
|
+
if (!session) {
|
|
58
|
+
throw new errors.SessionError('No open session');
|
|
59
|
+
}
|
|
60
|
+
const remoteIdentityKey = session.indexInfo.remoteIdentityKey;
|
|
61
|
+
if (!await this.storage.isTrustedIdentity(this.addr.id, remoteIdentityKey)) {
|
|
62
|
+
throw new errors.UntrustedIdentityKeyError(this.addr.id, remoteIdentityKey);
|
|
63
|
+
}
|
|
64
|
+
const chain = session.getChain(session.currentRatchet.ephemeralKeyPair.pubKey);
|
|
65
|
+
if (chain.chainType === ChainType.RECEIVING) {
|
|
66
|
+
throw new Error('Tried to encrypt on a receiving chain');
|
|
67
|
+
}
|
|
68
|
+
this.fillMessageKeys(chain, chain.chainKey.counter + 1);
|
|
69
|
+
const keys = deriveSecrets(chain.messageKeys[chain.chainKey.counter], Buffer.alloc(32), Buffer.from('WhisperMessageKeys'));
|
|
70
|
+
delete chain.messageKeys[chain.chainKey.counter];
|
|
71
|
+
const msg = proto.SignalMessage.create();
|
|
72
|
+
msg.ratchetKey = session.currentRatchet.ephemeralKeyPair.pubKey;
|
|
73
|
+
msg.counter = chain.chainKey.counter;
|
|
74
|
+
msg.previousCounter = session.currentRatchet.previousCounter;
|
|
75
|
+
msg.ciphertext = encrypt(keys[0], data, keys[2].slice(0, 16));
|
|
76
|
+
const msgBuf = proto.SignalMessage.encode(msg).finish();
|
|
77
|
+
const macInput = Buffer.alloc(msgBuf.byteLength + (33 * 2) + 1);
|
|
78
|
+
macInput.set(ourIdentityKey.pubKey);
|
|
79
|
+
macInput.set(session.indexInfo.remoteIdentityKey, 33);
|
|
80
|
+
macInput[33 * 2] = this._encodeTupleByte(VERSION, VERSION);
|
|
81
|
+
macInput.set(msgBuf, (33 * 2) + 1);
|
|
82
|
+
const mac = calculateMAC(keys[1], macInput);
|
|
83
|
+
const result = Buffer.alloc(msgBuf.byteLength + 9);
|
|
84
|
+
result[0] = this._encodeTupleByte(VERSION, VERSION);
|
|
85
|
+
result.set(msgBuf, 1);
|
|
86
|
+
result.set(mac.slice(0, 8), msgBuf.byteLength + 1);
|
|
87
|
+
await this.storeRecord(record);
|
|
88
|
+
let type, body;
|
|
89
|
+
if (session.pendingPreKey) {
|
|
90
|
+
type = 3;
|
|
91
|
+
const preKeyMsg = proto.PreKeySignalMessage.create({
|
|
92
|
+
identityKey: ourIdentityKey.pubKey,
|
|
93
|
+
registrationId: await this.storage.getOurRegistrationId(),
|
|
94
|
+
baseKey: session.pendingPreKey.baseKey,
|
|
95
|
+
signedPreKeyId: session.pendingPreKey.signedKeyId,
|
|
96
|
+
message: result
|
|
97
|
+
});
|
|
98
|
+
if (session.pendingPreKey.preKeyId) {
|
|
99
|
+
preKeyMsg.preKeyId = session.pendingPreKey.preKeyId;
|
|
100
|
+
}
|
|
101
|
+
body = Buffer.concat([
|
|
102
|
+
Buffer.from([this._encodeTupleByte(VERSION, VERSION)]),
|
|
103
|
+
Buffer.from(proto.PreKeySignalMessage.encode(preKeyMsg).finish())
|
|
104
|
+
]);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
type = 1;
|
|
108
|
+
body = result;
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
type,
|
|
112
|
+
body,
|
|
113
|
+
registrationId: session.registrationId
|
|
114
|
+
};
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
async decryptWithSessions(data, sessions) {
|
|
118
|
+
if (!sessions.length) {
|
|
119
|
+
throw new errors.SessionError('No sessions available');
|
|
120
|
+
}
|
|
121
|
+
for (const session of sessions) {
|
|
122
|
+
let plaintext;
|
|
123
|
+
try {
|
|
124
|
+
plaintext = await this.doDecryptWhisperMessage(data, session);
|
|
125
|
+
session.indexInfo.used = Date.now();
|
|
126
|
+
return {
|
|
127
|
+
session,
|
|
128
|
+
plaintext
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
// Try the next known session without retaining failed error objects.
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
throw new errors.SessionError('No matching sessions found for message');
|
|
136
|
+
}
|
|
137
|
+
async decryptWhisperMessage(data) {
|
|
138
|
+
assertBuffer(data);
|
|
139
|
+
return await this.queueJob(async () => {
|
|
140
|
+
const record = await this.getRecord();
|
|
141
|
+
if (!record) {
|
|
142
|
+
throw new errors.SessionError('No session record');
|
|
143
|
+
}
|
|
144
|
+
const result = await this.decryptWithSessions(data, record.getSessions());
|
|
145
|
+
const remoteIdentityKey = result.session.indexInfo.remoteIdentityKey;
|
|
146
|
+
if (!await this.storage.isTrustedIdentity(this.addr.id, remoteIdentityKey)) {
|
|
147
|
+
throw new errors.UntrustedIdentityKeyError(this.addr.id, remoteIdentityKey);
|
|
148
|
+
}
|
|
149
|
+
if (record.isClosed(result.session)) {
|
|
150
|
+
// It's possible for this to happen when processing a backlog of messages.
|
|
151
|
+
// The message was, hopefully, just sent back in a time when this session
|
|
152
|
+
// was the most current. Simply make a note of it and continue. If our
|
|
153
|
+
// actual open session is for reason invalid, that must be handled via
|
|
154
|
+
// a full SessionError response.
|
|
155
|
+
// Backlog messages may legitimately belong to a closed session.
|
|
156
|
+
}
|
|
157
|
+
await this.storeRecord(record);
|
|
158
|
+
return result.plaintext;
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
async decryptPreKeyWhisperMessage(data) {
|
|
162
|
+
assertBuffer(data);
|
|
163
|
+
const versions = this._decodeTupleByte(data[0]);
|
|
164
|
+
if (versions[1] > 3 || versions[0] < 3) {
|
|
165
|
+
throw new Error('Incompatible version number on PreKeySignalMessage');
|
|
166
|
+
}
|
|
167
|
+
return await this.queueJob(async () => {
|
|
168
|
+
let record = await this.getRecord();
|
|
169
|
+
const preKeyProto = proto.PreKeySignalMessage.decode(data.slice(1));
|
|
170
|
+
if (!record) {
|
|
171
|
+
if (preKeyProto.registrationId == null) {
|
|
172
|
+
throw new Error('No registrationId');
|
|
173
|
+
}
|
|
174
|
+
record = new SessionRecord();
|
|
175
|
+
}
|
|
176
|
+
const builder = new SessionBuilder(this.storage, this.addr);
|
|
177
|
+
const preKeyId = await builder.initIncoming(record, preKeyProto);
|
|
178
|
+
const session = record.getSession(preKeyProto.baseKey);
|
|
179
|
+
const plaintext = await this.doDecryptWhisperMessage(preKeyProto.message, session);
|
|
180
|
+
await this.storeRecord(record);
|
|
181
|
+
if (preKeyId !== null) {
|
|
182
|
+
await this.storage.removePreKey(preKeyId);
|
|
183
|
+
}
|
|
184
|
+
return plaintext;
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
async doDecryptWhisperMessage(messageBuffer, session) {
|
|
188
|
+
assertBuffer(messageBuffer);
|
|
189
|
+
if (!session) {
|
|
190
|
+
throw new TypeError('session required');
|
|
191
|
+
}
|
|
192
|
+
const versions = this._decodeTupleByte(messageBuffer[0]);
|
|
193
|
+
if (versions[1] > 3 || versions[0] < 3) {
|
|
194
|
+
throw new Error('Incompatible version number on SignalMessage');
|
|
195
|
+
}
|
|
196
|
+
const messageProto = messageBuffer.slice(1, -8);
|
|
197
|
+
const message = proto.SignalMessage.decode(messageProto);
|
|
198
|
+
this.maybeStepRatchet(session, message.ratchetKey, message.previousCounter);
|
|
199
|
+
const chain = session.getChain(message.ratchetKey);
|
|
200
|
+
if (chain.chainType === ChainType.SENDING) {
|
|
201
|
+
throw new Error('Tried to decrypt on a sending chain');
|
|
202
|
+
}
|
|
203
|
+
this.fillMessageKeys(chain, message.counter);
|
|
204
|
+
if (!chain.messageKeys.hasOwnProperty(message.counter)) {
|
|
205
|
+
// Most likely the message was already decrypted and we are trying to process
|
|
206
|
+
// twice. This can happen if the user restarts before the server gets an ACK.
|
|
207
|
+
throw new errors.MessageCounterError('Key used already or never filled');
|
|
208
|
+
}
|
|
209
|
+
const messageKey = chain.messageKeys[message.counter];
|
|
210
|
+
delete chain.messageKeys[message.counter];
|
|
211
|
+
const keys = deriveSecrets(messageKey, Buffer.alloc(32), Buffer.from('WhisperMessageKeys'));
|
|
212
|
+
const ourIdentityKey = await this.storage.getOurIdentity();
|
|
213
|
+
const macInput = Buffer.alloc(messageProto.byteLength + (33 * 2) + 1);
|
|
214
|
+
macInput.set(session.indexInfo.remoteIdentityKey);
|
|
215
|
+
macInput.set(ourIdentityKey.pubKey, 33);
|
|
216
|
+
macInput[33 * 2] = this._encodeTupleByte(VERSION, VERSION);
|
|
217
|
+
macInput.set(messageProto, (33 * 2) + 1);
|
|
218
|
+
verifyMAC(macInput, keys[1], messageBuffer.slice(-8), 8);
|
|
219
|
+
const plaintext = decrypt(keys[0], message.ciphertext, keys[2].slice(0, 16));
|
|
220
|
+
delete session.pendingPreKey;
|
|
221
|
+
return plaintext;
|
|
222
|
+
}
|
|
223
|
+
fillMessageKeys(chain, counter) {
|
|
224
|
+
if (chain.chainKey.counter >= counter) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
if (counter - chain.chainKey.counter > 2000) {
|
|
228
|
+
throw new errors.SessionError('Over 2000 messages into the future!');
|
|
229
|
+
}
|
|
230
|
+
if (chain.chainKey.key === undefined) {
|
|
231
|
+
throw new errors.SessionError('Chain closed');
|
|
232
|
+
}
|
|
233
|
+
while (chain.chainKey.counter < counter) {
|
|
234
|
+
const key = chain.chainKey.key;
|
|
235
|
+
if (key === undefined) {
|
|
236
|
+
throw new errors.SessionError('Chain closed');
|
|
237
|
+
}
|
|
238
|
+
const nextCounter = chain.chainKey.counter + 1;
|
|
239
|
+
chain.messageKeys[nextCounter] = calculateMAC(key, Buffer.from([1]));
|
|
240
|
+
chain.chainKey.key = calculateMAC(key, Buffer.from([2]));
|
|
241
|
+
chain.chainKey.counter = nextCounter;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
maybeStepRatchet(session, remoteKey, previousCounter) {
|
|
245
|
+
if (session.getChain(remoteKey)) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
const ratchet = session.currentRatchet;
|
|
249
|
+
let previousRatchet = session.getChain(ratchet.lastRemoteEphemeralKey);
|
|
250
|
+
if (previousRatchet) {
|
|
251
|
+
this.fillMessageKeys(previousRatchet, previousCounter);
|
|
252
|
+
delete previousRatchet.chainKey.key;
|
|
253
|
+
}
|
|
254
|
+
this.calculateRatchet(session, remoteKey, false);
|
|
255
|
+
const prevCounter = session.getChain(ratchet.ephemeralKeyPair.pubKey);
|
|
256
|
+
if (prevCounter) {
|
|
257
|
+
ratchet.previousCounter = prevCounter.chainKey.counter;
|
|
258
|
+
session.deleteChain(ratchet.ephemeralKeyPair.pubKey);
|
|
259
|
+
}
|
|
260
|
+
ratchet.ephemeralKeyPair = generateKeyPair();
|
|
261
|
+
this.calculateRatchet(session, remoteKey, true);
|
|
262
|
+
ratchet.lastRemoteEphemeralKey = remoteKey;
|
|
263
|
+
}
|
|
264
|
+
calculateRatchet(session, remoteKey, sending) {
|
|
265
|
+
let ratchet = session.currentRatchet;
|
|
266
|
+
const sharedSecret = calculateAgreement(remoteKey, ratchet.ephemeralKeyPair.privKey);
|
|
267
|
+
const masterKey = deriveSecrets(sharedSecret, ratchet.rootKey, Buffer.from('WhisperRatchet'), /*chunks*/ 2);
|
|
268
|
+
const chainKey = sending ? ratchet.ephemeralKeyPair.pubKey : remoteKey;
|
|
269
|
+
session.addChain(chainKey, {
|
|
270
|
+
messageKeys: {},
|
|
271
|
+
chainKey: {
|
|
272
|
+
counter: -1,
|
|
273
|
+
key: masterKey[1]
|
|
274
|
+
},
|
|
275
|
+
chainType: sending ? ChainType.SENDING : ChainType.RECEIVING
|
|
276
|
+
});
|
|
277
|
+
ratchet.rootKey = masterKey[0];
|
|
278
|
+
}
|
|
279
|
+
async hasOpenSession() {
|
|
280
|
+
return await this.queueJob(async () => {
|
|
281
|
+
const record = await this.getRecord();
|
|
282
|
+
if (!record) {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
return record.haveOpenSession();
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
async closeOpenSession() {
|
|
289
|
+
return await this.queueJob(async () => {
|
|
290
|
+
const record = await this.getRecord();
|
|
291
|
+
if (record) {
|
|
292
|
+
const openSession = record.getOpenSession();
|
|
293
|
+
if (openSession) {
|
|
294
|
+
record.closeSession(openSession);
|
|
295
|
+
await this.storeRecord(record);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
export default SessionCipher;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export default SessionRecord;
|
|
2
|
+
declare class SessionRecord {
|
|
3
|
+
static createEntry(): SessionEntry;
|
|
4
|
+
static migrate(data: any): void;
|
|
5
|
+
static deserialize(data: any): SessionRecord;
|
|
6
|
+
sessions: {};
|
|
7
|
+
version: string;
|
|
8
|
+
serialize(): {
|
|
9
|
+
_sessions: {};
|
|
10
|
+
version: string;
|
|
11
|
+
};
|
|
12
|
+
haveOpenSession(): boolean;
|
|
13
|
+
getSession(key: any): any;
|
|
14
|
+
getOpenSession(): any;
|
|
15
|
+
setSession(session: any): void;
|
|
16
|
+
getSessions(): any[];
|
|
17
|
+
closeSession(session: any): void;
|
|
18
|
+
openSession(session: any): void;
|
|
19
|
+
isClosed(session: any): boolean;
|
|
20
|
+
removeOldSessions(): void;
|
|
21
|
+
deleteAllSessions(): void;
|
|
22
|
+
}
|
|
23
|
+
declare class SessionEntry {
|
|
24
|
+
static deserialize(data: any): SessionEntry;
|
|
25
|
+
static _deserialize_chains(chains_data: any): {};
|
|
26
|
+
_chains: {};
|
|
27
|
+
toString(): string;
|
|
28
|
+
inspect(): string;
|
|
29
|
+
addChain(key: any, value: any): void;
|
|
30
|
+
getChain(key: any): any;
|
|
31
|
+
deleteChain(key: any): void;
|
|
32
|
+
chains(): Generator<any[], void, unknown>;
|
|
33
|
+
serialize(): {
|
|
34
|
+
registrationId: any;
|
|
35
|
+
currentRatchet: {
|
|
36
|
+
ephemeralKeyPair: {
|
|
37
|
+
pubKey: any;
|
|
38
|
+
privKey: any;
|
|
39
|
+
};
|
|
40
|
+
lastRemoteEphemeralKey: any;
|
|
41
|
+
previousCounter: any;
|
|
42
|
+
rootKey: any;
|
|
43
|
+
};
|
|
44
|
+
indexInfo: {
|
|
45
|
+
baseKey: any;
|
|
46
|
+
baseKeyType: any;
|
|
47
|
+
closed: any;
|
|
48
|
+
used: any;
|
|
49
|
+
created: any;
|
|
50
|
+
remoteIdentityKey: any;
|
|
51
|
+
};
|
|
52
|
+
_chains: {};
|
|
53
|
+
};
|
|
54
|
+
_serialize_chains(chains: any): {};
|
|
55
|
+
}
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { BaseKeyType } from './internals.js';
|
|
2
|
+
const CLOSED_SESSIONS_MAX = 40;
|
|
3
|
+
const SESSION_RECORD_VERSION = 'v1';
|
|
4
|
+
function assertBuffer(value) {
|
|
5
|
+
if (!Buffer.isBuffer(value)) {
|
|
6
|
+
throw new TypeError('Buffer required');
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
class SessionEntry {
|
|
10
|
+
constructor() {
|
|
11
|
+
this._chains = {};
|
|
12
|
+
}
|
|
13
|
+
toString() {
|
|
14
|
+
const baseKey = this.indexInfo && this.indexInfo.baseKey &&
|
|
15
|
+
this.indexInfo.baseKey.toString('base64');
|
|
16
|
+
return `<SessionEntry [baseKey=${baseKey}]>`;
|
|
17
|
+
}
|
|
18
|
+
inspect() {
|
|
19
|
+
return this.toString();
|
|
20
|
+
}
|
|
21
|
+
addChain(key, value) {
|
|
22
|
+
assertBuffer(key);
|
|
23
|
+
const id = key.toString('base64');
|
|
24
|
+
if (this._chains.hasOwnProperty(id)) {
|
|
25
|
+
throw new Error('Overwrite attempt');
|
|
26
|
+
}
|
|
27
|
+
this._chains[id] = value;
|
|
28
|
+
}
|
|
29
|
+
getChain(key) {
|
|
30
|
+
assertBuffer(key);
|
|
31
|
+
return this._chains[key.toString('base64')];
|
|
32
|
+
}
|
|
33
|
+
deleteChain(key) {
|
|
34
|
+
assertBuffer(key);
|
|
35
|
+
const id = key.toString('base64');
|
|
36
|
+
if (!this._chains.hasOwnProperty(id)) {
|
|
37
|
+
throw new ReferenceError('Not Found');
|
|
38
|
+
}
|
|
39
|
+
delete this._chains[id];
|
|
40
|
+
}
|
|
41
|
+
*chains() {
|
|
42
|
+
for (const [k, v] of Object.entries(this._chains)) {
|
|
43
|
+
yield [Buffer.from(k, 'base64'), v];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
serialize() {
|
|
47
|
+
const data = {
|
|
48
|
+
registrationId: this.registrationId,
|
|
49
|
+
currentRatchet: {
|
|
50
|
+
ephemeralKeyPair: {
|
|
51
|
+
pubKey: this.currentRatchet.ephemeralKeyPair.pubKey.toString('base64'),
|
|
52
|
+
privKey: this.currentRatchet.ephemeralKeyPair.privKey.toString('base64')
|
|
53
|
+
},
|
|
54
|
+
lastRemoteEphemeralKey: this.currentRatchet.lastRemoteEphemeralKey.toString('base64'),
|
|
55
|
+
previousCounter: this.currentRatchet.previousCounter,
|
|
56
|
+
rootKey: this.currentRatchet.rootKey.toString('base64')
|
|
57
|
+
},
|
|
58
|
+
indexInfo: {
|
|
59
|
+
baseKey: this.indexInfo.baseKey.toString('base64'),
|
|
60
|
+
baseKeyType: this.indexInfo.baseKeyType,
|
|
61
|
+
closed: this.indexInfo.closed,
|
|
62
|
+
used: this.indexInfo.used,
|
|
63
|
+
created: this.indexInfo.created,
|
|
64
|
+
remoteIdentityKey: this.indexInfo.remoteIdentityKey.toString('base64')
|
|
65
|
+
},
|
|
66
|
+
_chains: this._serialize_chains(this._chains)
|
|
67
|
+
};
|
|
68
|
+
if (this.pendingPreKey) {
|
|
69
|
+
data.pendingPreKey = Object.assign({}, this.pendingPreKey);
|
|
70
|
+
data.pendingPreKey.baseKey = this.pendingPreKey.baseKey.toString('base64');
|
|
71
|
+
}
|
|
72
|
+
return data;
|
|
73
|
+
}
|
|
74
|
+
static deserialize(data) {
|
|
75
|
+
const obj = new this();
|
|
76
|
+
obj.registrationId = data.registrationId;
|
|
77
|
+
obj.currentRatchet = {
|
|
78
|
+
ephemeralKeyPair: {
|
|
79
|
+
pubKey: Buffer.from(data.currentRatchet.ephemeralKeyPair.pubKey, 'base64'),
|
|
80
|
+
privKey: Buffer.from(data.currentRatchet.ephemeralKeyPair.privKey, 'base64')
|
|
81
|
+
},
|
|
82
|
+
lastRemoteEphemeralKey: Buffer.from(data.currentRatchet.lastRemoteEphemeralKey, 'base64'),
|
|
83
|
+
previousCounter: data.currentRatchet.previousCounter,
|
|
84
|
+
rootKey: Buffer.from(data.currentRatchet.rootKey, 'base64')
|
|
85
|
+
};
|
|
86
|
+
obj.indexInfo = {
|
|
87
|
+
baseKey: Buffer.from(data.indexInfo.baseKey, 'base64'),
|
|
88
|
+
baseKeyType: data.indexInfo.baseKeyType,
|
|
89
|
+
closed: data.indexInfo.closed,
|
|
90
|
+
used: data.indexInfo.used,
|
|
91
|
+
created: data.indexInfo.created,
|
|
92
|
+
remoteIdentityKey: Buffer.from(data.indexInfo.remoteIdentityKey, 'base64')
|
|
93
|
+
};
|
|
94
|
+
obj._chains = this._deserialize_chains(data._chains);
|
|
95
|
+
if (data.pendingPreKey) {
|
|
96
|
+
obj.pendingPreKey = Object.assign({}, data.pendingPreKey);
|
|
97
|
+
obj.pendingPreKey.baseKey = Buffer.from(data.pendingPreKey.baseKey, 'base64');
|
|
98
|
+
}
|
|
99
|
+
return obj;
|
|
100
|
+
}
|
|
101
|
+
_serialize_chains(chains) {
|
|
102
|
+
const r = {};
|
|
103
|
+
for (const key of Object.keys(chains)) {
|
|
104
|
+
const c = chains[key];
|
|
105
|
+
const messageKeys = {};
|
|
106
|
+
for (const [idx, key] of Object.entries(c.messageKeys)) {
|
|
107
|
+
messageKeys[idx] = key.toString('base64');
|
|
108
|
+
}
|
|
109
|
+
r[key] = {
|
|
110
|
+
chainKey: {
|
|
111
|
+
counter: c.chainKey.counter,
|
|
112
|
+
key: c.chainKey.key && c.chainKey.key.toString('base64')
|
|
113
|
+
},
|
|
114
|
+
chainType: c.chainType,
|
|
115
|
+
messageKeys: messageKeys
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return r;
|
|
119
|
+
}
|
|
120
|
+
static _deserialize_chains(chains_data) {
|
|
121
|
+
const r = {};
|
|
122
|
+
for (const key of Object.keys(chains_data)) {
|
|
123
|
+
const c = chains_data[key];
|
|
124
|
+
const messageKeys = {};
|
|
125
|
+
for (const [idx, key] of Object.entries(c.messageKeys)) {
|
|
126
|
+
messageKeys[idx] = Buffer.from(key, 'base64');
|
|
127
|
+
}
|
|
128
|
+
r[key] = {
|
|
129
|
+
chainKey: {
|
|
130
|
+
counter: c.chainKey.counter,
|
|
131
|
+
key: c.chainKey.key && Buffer.from(c.chainKey.key, 'base64')
|
|
132
|
+
},
|
|
133
|
+
chainType: c.chainType,
|
|
134
|
+
messageKeys: messageKeys
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
return r;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
const migrations = [{
|
|
141
|
+
version: 'v1',
|
|
142
|
+
migrate: function migrateV1(data) {
|
|
143
|
+
const sessions = data._sessions;
|
|
144
|
+
if (data.registrationId) {
|
|
145
|
+
for (const key in sessions) {
|
|
146
|
+
if (!sessions[key].registrationId) {
|
|
147
|
+
sessions[key].registrationId = data.registrationId;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
for (const key in sessions) {
|
|
153
|
+
if (sessions[key].indexInfo.closed === -1) {
|
|
154
|
+
console.error('V1 session storage migration error: registrationId', data.registrationId, 'for open session version', data.version);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}];
|
|
160
|
+
class SessionRecord {
|
|
161
|
+
static createEntry() {
|
|
162
|
+
return new SessionEntry();
|
|
163
|
+
}
|
|
164
|
+
static migrate(data) {
|
|
165
|
+
let run = (data.version === undefined);
|
|
166
|
+
for (let i = 0; i < migrations.length; ++i) {
|
|
167
|
+
if (run) {
|
|
168
|
+
migrations[i].migrate(data);
|
|
169
|
+
}
|
|
170
|
+
else if (migrations[i].version === data.version) {
|
|
171
|
+
run = true;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (!run) {
|
|
175
|
+
throw new Error('Error migrating SessionRecord');
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
static deserialize(data) {
|
|
179
|
+
if (data.version !== SESSION_RECORD_VERSION) {
|
|
180
|
+
this.migrate(data);
|
|
181
|
+
}
|
|
182
|
+
const obj = new this();
|
|
183
|
+
if (data._sessions) {
|
|
184
|
+
for (const [key, entry] of Object.entries(data._sessions)) {
|
|
185
|
+
obj.sessions[key] = SessionEntry.deserialize(entry);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return obj;
|
|
189
|
+
}
|
|
190
|
+
constructor() {
|
|
191
|
+
this.sessions = {};
|
|
192
|
+
this.version = SESSION_RECORD_VERSION;
|
|
193
|
+
}
|
|
194
|
+
serialize() {
|
|
195
|
+
const _sessions = {};
|
|
196
|
+
for (const [key, entry] of Object.entries(this.sessions)) {
|
|
197
|
+
_sessions[key] = entry.serialize();
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
_sessions,
|
|
201
|
+
version: this.version
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
haveOpenSession() {
|
|
205
|
+
const openSession = this.getOpenSession();
|
|
206
|
+
return (!!openSession && typeof openSession.registrationId === 'number');
|
|
207
|
+
}
|
|
208
|
+
getSession(key) {
|
|
209
|
+
assertBuffer(key);
|
|
210
|
+
const session = this.sessions[key.toString('base64')];
|
|
211
|
+
if (session && session.indexInfo.baseKeyType === BaseKeyType.OURS) {
|
|
212
|
+
throw new Error('Tried to lookup a session using our basekey');
|
|
213
|
+
}
|
|
214
|
+
return session;
|
|
215
|
+
}
|
|
216
|
+
getOpenSession() {
|
|
217
|
+
for (const session of Object.values(this.sessions)) {
|
|
218
|
+
if (!this.isClosed(session)) {
|
|
219
|
+
return session;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
setSession(session) {
|
|
224
|
+
this.sessions[session.indexInfo.baseKey.toString('base64')] = session;
|
|
225
|
+
}
|
|
226
|
+
getSessions() {
|
|
227
|
+
return Array.from(Object.values(this.sessions)).sort((a, b) => {
|
|
228
|
+
const aUsed = a.indexInfo.used || 0;
|
|
229
|
+
const bUsed = b.indexInfo.used || 0;
|
|
230
|
+
return aUsed === bUsed ? 0 : aUsed < bUsed ? 1 : -1;
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
closeSession(session) {
|
|
234
|
+
if (this.isClosed(session)) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
session.indexInfo.closed = Date.now();
|
|
238
|
+
}
|
|
239
|
+
openSession(session) {
|
|
240
|
+
if (!this.isClosed(session)) {
|
|
241
|
+
}
|
|
242
|
+
session.indexInfo.closed = -1;
|
|
243
|
+
}
|
|
244
|
+
isClosed(session) {
|
|
245
|
+
return session.indexInfo.closed !== -1;
|
|
246
|
+
}
|
|
247
|
+
removeOldSessions() {
|
|
248
|
+
while (Object.keys(this.sessions).length > CLOSED_SESSIONS_MAX) {
|
|
249
|
+
let oldestKey;
|
|
250
|
+
let oldestSession;
|
|
251
|
+
for (const [key, session] of Object.entries(this.sessions)) {
|
|
252
|
+
if (session.indexInfo.closed !== -1 &&
|
|
253
|
+
(!oldestSession || session.indexInfo.closed < oldestSession.indexInfo.closed)) {
|
|
254
|
+
oldestKey = key;
|
|
255
|
+
oldestSession = session;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (oldestKey) {
|
|
259
|
+
delete this.sessions[oldestKey];
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
throw new Error('Corrupt sessions object');
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
deleteAllSessions() {
|
|
267
|
+
for (const key of Object.keys(this.sessions)) {
|
|
268
|
+
delete this.sessions[key];
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
export default SessionRecord;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const ALL_WA_PATCH_NAMES: string[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|