@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,8 @@
|
|
|
1
|
+
export function getPublicFromPrivateKey(privKey: any): any;
|
|
2
|
+
export function generateKeyPair(): {
|
|
3
|
+
pubKey: any;
|
|
4
|
+
privKey: any;
|
|
5
|
+
};
|
|
6
|
+
export function calculateAgreement(pubKey: any, privKey: any): any;
|
|
7
|
+
export function calculateSignature(privKey: any, message: any): any;
|
|
8
|
+
export function verifySignature(pubKey: any, msg: any, sig: any, isInit: any): any;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Curve25519/XEdDSA primitives. Backed by the internal pure-TypeScript
|
|
3
|
+
* WACrypto module (Node.js native crypto) — the `whatsapp-rust-bridge`
|
|
4
|
+
* WASM dependency was removed in @eduh_dev021/baileys 1.0.0.
|
|
5
|
+
*/
|
|
6
|
+
import { generateKeyPair as waGenerateKeyPair, calculateAgreement as waCalculateAgreement, calculateSignature as waCalculateSignature, verifySignature as waVerifySignature, getPublicFromPrivateKey as waGetPublicFromPrivateKey } from '../WACrypto/index.js';
|
|
7
|
+
function validatePrivKey(privKey) {
|
|
8
|
+
if (privKey === undefined) {
|
|
9
|
+
throw new Error('Undefined private key');
|
|
10
|
+
}
|
|
11
|
+
if (!Buffer.isBuffer(privKey)) {
|
|
12
|
+
throw new Error(`Invalid private key type: ${privKey?.constructor?.name ?? typeof privKey}`);
|
|
13
|
+
}
|
|
14
|
+
if (privKey.byteLength != 32) {
|
|
15
|
+
throw new Error(`Incorrect private key length: ${privKey.byteLength}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function scrubPubKeyFormat(pubKey) {
|
|
19
|
+
if (!Buffer.isBuffer(pubKey)) {
|
|
20
|
+
throw new Error(`Invalid public key type: ${pubKey?.constructor?.name ?? typeof pubKey}`);
|
|
21
|
+
}
|
|
22
|
+
if ((pubKey.byteLength !== 33 || pubKey[0] !== 5) && pubKey.byteLength !== 32) {
|
|
23
|
+
throw new Error('Invalid public key');
|
|
24
|
+
}
|
|
25
|
+
if (pubKey.byteLength == 33) {
|
|
26
|
+
return pubKey.slice(1);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
console.error('WARNING: Expected pubkey of length 33, please report the ST and client that generated the pubkey');
|
|
30
|
+
return pubKey;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export function getPublicFromPrivateKey(privKey) {
|
|
34
|
+
return Buffer.from(waGetPublicFromPrivateKey(privKey));
|
|
35
|
+
}
|
|
36
|
+
export function generateKeyPair() {
|
|
37
|
+
const kp = waGenerateKeyPair();
|
|
38
|
+
return {
|
|
39
|
+
pubKey: Buffer.from(kp.pubKey),
|
|
40
|
+
privKey: Buffer.from(kp.privKey)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export function calculateAgreement(pubKey, privKey) {
|
|
44
|
+
pubKey = scrubPubKeyFormat(pubKey);
|
|
45
|
+
validatePrivKey(privKey);
|
|
46
|
+
return Buffer.from(waCalculateAgreement(pubKey, privKey));
|
|
47
|
+
}
|
|
48
|
+
export function calculateSignature(privKey, message) {
|
|
49
|
+
validatePrivKey(privKey);
|
|
50
|
+
if (!message) {
|
|
51
|
+
throw new Error('Invalid message');
|
|
52
|
+
}
|
|
53
|
+
return Buffer.from(waCalculateSignature(privKey, message));
|
|
54
|
+
}
|
|
55
|
+
export function verifySignature(pubKey, msg, sig, isInit) {
|
|
56
|
+
if (isInit)
|
|
57
|
+
return true;
|
|
58
|
+
pubKey = scrubPubKeyFormat(pubKey);
|
|
59
|
+
if (!msg) {
|
|
60
|
+
throw new Error('Invalid message');
|
|
61
|
+
}
|
|
62
|
+
if (!sig || sig.byteLength != 64) {
|
|
63
|
+
throw new Error('Invalid signature');
|
|
64
|
+
}
|
|
65
|
+
return waVerifySignature(pubKey, msg, sig);
|
|
66
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * as crypto from "./crypto.js";
|
|
2
|
+
export * as curve from "./curve.js";
|
|
3
|
+
export namespace keyhelper {
|
|
4
|
+
export { generateIdentityKeyPair };
|
|
5
|
+
export { generateRegistrationId };
|
|
6
|
+
export { generateSignedPreKey };
|
|
7
|
+
export { generatePreKey };
|
|
8
|
+
}
|
|
9
|
+
export { default as SessionBuilder } from "./session-builder.js";
|
|
10
|
+
export { default as SessionCipher } from "./session-cipher.js";
|
|
11
|
+
export { default as SessionRecord } from "./session-record.js";
|
|
12
|
+
import { generateIdentityKeyPair } from './internals.js';
|
|
13
|
+
import { generateRegistrationId } from './internals.js';
|
|
14
|
+
import { generateSignedPreKey } from './internals.js';
|
|
15
|
+
import { generatePreKey } from './internals.js';
|
|
16
|
+
export { default as ProtocolAddress, SignalError, UntrustedIdentityKeyError, SessionError, MessageCounterError, PreKeyError } from "./internals.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * as crypto from './crypto.js';
|
|
2
|
+
export * as curve from './curve.js';
|
|
3
|
+
import { generateIdentityKeyPair, generateRegistrationId, generateSignedPreKey, generatePreKey } from './internals.js';
|
|
4
|
+
export const keyhelper = { generateIdentityKeyPair, generateRegistrationId, generateSignedPreKey, generatePreKey };
|
|
5
|
+
export { default as ProtocolAddress } from './internals.js';
|
|
6
|
+
export { default as SessionBuilder } from './session-builder.js';
|
|
7
|
+
export { default as SessionCipher } from './session-cipher.js';
|
|
8
|
+
export { default as SessionRecord } from './session-record.js';
|
|
9
|
+
export { SignalError, UntrustedIdentityKeyError, SessionError, MessageCounterError, PreKeyError } from './internals.js';
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export function queueJob(key: any, run: any): Promise<any>;
|
|
2
|
+
export function generateRegistrationId(): number;
|
|
3
|
+
export function generateSignedPreKey(identityKeyPair: any, signedKeyId: any): {
|
|
4
|
+
keyId: any;
|
|
5
|
+
keyPair: {
|
|
6
|
+
pubKey: any;
|
|
7
|
+
privKey: any;
|
|
8
|
+
};
|
|
9
|
+
signature: any;
|
|
10
|
+
};
|
|
11
|
+
export function generatePreKey(keyId: any): {
|
|
12
|
+
keyId: any;
|
|
13
|
+
keyPair: {
|
|
14
|
+
pubKey: any;
|
|
15
|
+
privKey: any;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export namespace BaseKeyType {
|
|
19
|
+
let OURS: number;
|
|
20
|
+
let THEIRS: number;
|
|
21
|
+
}
|
|
22
|
+
export namespace ChainType {
|
|
23
|
+
let SENDING: number;
|
|
24
|
+
let RECEIVING: number;
|
|
25
|
+
}
|
|
26
|
+
export class SignalError extends Error {
|
|
27
|
+
}
|
|
28
|
+
export class UntrustedIdentityKeyError extends SignalError {
|
|
29
|
+
constructor(addr: any, identityKey: any);
|
|
30
|
+
addr: any;
|
|
31
|
+
identityKey: any;
|
|
32
|
+
}
|
|
33
|
+
export class SessionError extends SignalError {
|
|
34
|
+
constructor(message: any);
|
|
35
|
+
}
|
|
36
|
+
export class MessageCounterError extends SessionError {
|
|
37
|
+
}
|
|
38
|
+
export class PreKeyError extends SessionError {
|
|
39
|
+
}
|
|
40
|
+
export namespace errors {
|
|
41
|
+
export { SignalError };
|
|
42
|
+
export { UntrustedIdentityKeyError };
|
|
43
|
+
export { SessionError };
|
|
44
|
+
export { MessageCounterError };
|
|
45
|
+
export { PreKeyError };
|
|
46
|
+
}
|
|
47
|
+
export class ProtocolAddress {
|
|
48
|
+
static from(encodedAddress: any): ProtocolAddress;
|
|
49
|
+
constructor(id: any, deviceId: any);
|
|
50
|
+
id: string;
|
|
51
|
+
deviceId: number;
|
|
52
|
+
toString(): string;
|
|
53
|
+
is(other: any): boolean;
|
|
54
|
+
}
|
|
55
|
+
export const generateIdentityKeyPair: typeof generateKeyPair;
|
|
56
|
+
export default ProtocolAddress;
|
|
57
|
+
import { generateKeyPair } from './curve.js';
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
import { calculateSignature, generateKeyPair } from './curve.js';
|
|
3
|
+
export const BaseKeyType = {
|
|
4
|
+
OURS: 1,
|
|
5
|
+
THEIRS: 2
|
|
6
|
+
};
|
|
7
|
+
export const ChainType = {
|
|
8
|
+
SENDING: 1,
|
|
9
|
+
RECEIVING: 2
|
|
10
|
+
};
|
|
11
|
+
export class SignalError extends Error {
|
|
12
|
+
}
|
|
13
|
+
export class UntrustedIdentityKeyError extends SignalError {
|
|
14
|
+
constructor(addr, identityKey) {
|
|
15
|
+
super();
|
|
16
|
+
this.name = 'UntrustedIdentityKeyError';
|
|
17
|
+
this.addr = addr;
|
|
18
|
+
this.identityKey = identityKey;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export class SessionError extends SignalError {
|
|
22
|
+
constructor(message) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = 'SessionError';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
export class MessageCounterError extends SessionError {
|
|
28
|
+
constructor(message) {
|
|
29
|
+
super(message);
|
|
30
|
+
this.name = 'MessageCounterError';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export class PreKeyError extends SessionError {
|
|
34
|
+
constructor(message) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.name = 'PreKeyError';
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export const errors = {
|
|
40
|
+
SignalError,
|
|
41
|
+
UntrustedIdentityKeyError,
|
|
42
|
+
SessionError,
|
|
43
|
+
MessageCounterError,
|
|
44
|
+
PreKeyError
|
|
45
|
+
};
|
|
46
|
+
const queues = new Map();
|
|
47
|
+
async function drain(key, queue) {
|
|
48
|
+
try {
|
|
49
|
+
while (queue.head < queue.jobs.length) {
|
|
50
|
+
const job = queue.jobs[queue.head++];
|
|
51
|
+
queue.jobs[queue.head - 1] = null;
|
|
52
|
+
try {
|
|
53
|
+
job.resolve(await job.run());
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
job.reject(error);
|
|
57
|
+
}
|
|
58
|
+
if (queue.head >= 1024 && queue.head * 2 >= queue.jobs.length) {
|
|
59
|
+
queue.jobs = queue.jobs.slice(queue.head);
|
|
60
|
+
queue.head = 0;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
if (queues.get(key) === queue) {
|
|
66
|
+
queues.delete(key);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export function queueJob(key, run) {
|
|
71
|
+
if (typeof run !== 'function') {
|
|
72
|
+
return Promise.reject(new TypeError('Job must be a function'));
|
|
73
|
+
}
|
|
74
|
+
let queue = queues.get(key);
|
|
75
|
+
const start = !queue;
|
|
76
|
+
if (!queue) {
|
|
77
|
+
queue = { jobs: [], head: 0 };
|
|
78
|
+
queues.set(key, queue);
|
|
79
|
+
}
|
|
80
|
+
const promise = new Promise((resolve, reject) => {
|
|
81
|
+
queue.jobs.push({ run, resolve, reject });
|
|
82
|
+
});
|
|
83
|
+
if (start) {
|
|
84
|
+
void drain(key, queue);
|
|
85
|
+
}
|
|
86
|
+
return promise;
|
|
87
|
+
}
|
|
88
|
+
export class ProtocolAddress {
|
|
89
|
+
static from(encodedAddress) {
|
|
90
|
+
if (typeof encodedAddress !== 'string' || !encodedAddress.match(/.*\.\d+/)) {
|
|
91
|
+
throw new Error('Invalid address encoding');
|
|
92
|
+
}
|
|
93
|
+
const parts = encodedAddress.split('.');
|
|
94
|
+
return new this(parts[0], parseInt(parts[1]));
|
|
95
|
+
}
|
|
96
|
+
constructor(id, deviceId) {
|
|
97
|
+
if (typeof id !== 'string') {
|
|
98
|
+
throw new TypeError('id required for addr');
|
|
99
|
+
}
|
|
100
|
+
if (id.indexOf('.') !== -1) {
|
|
101
|
+
throw new TypeError('encoded addr detected');
|
|
102
|
+
}
|
|
103
|
+
this.id = id;
|
|
104
|
+
if (typeof deviceId !== 'number') {
|
|
105
|
+
throw new TypeError('number required for deviceId');
|
|
106
|
+
}
|
|
107
|
+
this.deviceId = deviceId;
|
|
108
|
+
}
|
|
109
|
+
toString() {
|
|
110
|
+
return `${this.id}.${this.deviceId}`;
|
|
111
|
+
}
|
|
112
|
+
is(other) {
|
|
113
|
+
if (!(other instanceof ProtocolAddress)) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
return other.id === this.id && other.deviceId === this.deviceId;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function isNonNegativeInteger(n) {
|
|
120
|
+
return (typeof n === 'number' && (n % 1) === 0 && n >= 0);
|
|
121
|
+
}
|
|
122
|
+
export const generateIdentityKeyPair = generateKeyPair;
|
|
123
|
+
export function generateRegistrationId() {
|
|
124
|
+
var registrationId = Uint16Array.from(randomBytes(2))[0];
|
|
125
|
+
return registrationId & 0x3fff;
|
|
126
|
+
}
|
|
127
|
+
export function generateSignedPreKey(identityKeyPair, signedKeyId) {
|
|
128
|
+
if (!(identityKeyPair.privKey instanceof Buffer) ||
|
|
129
|
+
identityKeyPair.privKey.byteLength != 32 ||
|
|
130
|
+
!(identityKeyPair.pubKey instanceof Buffer) ||
|
|
131
|
+
identityKeyPair.pubKey.byteLength != 33) {
|
|
132
|
+
throw new TypeError('Invalid argument for identityKeyPair');
|
|
133
|
+
}
|
|
134
|
+
if (!isNonNegativeInteger(signedKeyId)) {
|
|
135
|
+
throw new TypeError('Invalid argument for signedKeyId: ' + signedKeyId);
|
|
136
|
+
}
|
|
137
|
+
const keyPair = generateKeyPair();
|
|
138
|
+
const sig = calculateSignature(identityKeyPair.privKey, keyPair.pubKey);
|
|
139
|
+
return {
|
|
140
|
+
keyId: signedKeyId,
|
|
141
|
+
keyPair: keyPair,
|
|
142
|
+
signature: sig
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
export function generatePreKey(keyId) {
|
|
146
|
+
if (!isNonNegativeInteger(keyId)) {
|
|
147
|
+
throw new TypeError('Invalid argument for keyId: ' + keyId);
|
|
148
|
+
}
|
|
149
|
+
const keyPair = generateKeyPair();
|
|
150
|
+
return {
|
|
151
|
+
keyId,
|
|
152
|
+
keyPair
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
export default ProtocolAddress;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export default SessionBuilder;
|
|
2
|
+
declare class SessionBuilder {
|
|
3
|
+
constructor(storage: any, protocolAddress: any);
|
|
4
|
+
addr: any;
|
|
5
|
+
storage: any;
|
|
6
|
+
initOutgoing(device: any): Promise<any>;
|
|
7
|
+
initIncoming(record: any, message: any): Promise<any>;
|
|
8
|
+
initSession(isInitiator: any, ourEphemeralKey: any, ourSignedKey: any, theirIdentityPubKey: any, theirEphemeralPubKey: any, theirSignedPubKey: any, registrationId: any): Promise<{
|
|
9
|
+
_chains: {};
|
|
10
|
+
toString(): string;
|
|
11
|
+
inspect(): string;
|
|
12
|
+
addChain(key: any, value: any): void;
|
|
13
|
+
getChain(key: any): any;
|
|
14
|
+
deleteChain(key: any): void;
|
|
15
|
+
chains(): Generator<any[], void, unknown>;
|
|
16
|
+
serialize(): {
|
|
17
|
+
registrationId: any;
|
|
18
|
+
currentRatchet: {
|
|
19
|
+
ephemeralKeyPair: {
|
|
20
|
+
pubKey: any;
|
|
21
|
+
privKey: any;
|
|
22
|
+
};
|
|
23
|
+
lastRemoteEphemeralKey: any;
|
|
24
|
+
previousCounter: any;
|
|
25
|
+
rootKey: any;
|
|
26
|
+
};
|
|
27
|
+
indexInfo: {
|
|
28
|
+
baseKey: any;
|
|
29
|
+
baseKeyType: any;
|
|
30
|
+
closed: any;
|
|
31
|
+
used: any;
|
|
32
|
+
created: any;
|
|
33
|
+
remoteIdentityKey: any;
|
|
34
|
+
};
|
|
35
|
+
_chains: {};
|
|
36
|
+
};
|
|
37
|
+
_serialize_chains(chains: any): {};
|
|
38
|
+
}>;
|
|
39
|
+
calculateSendingRatchet(session: any, remoteKey: any): void;
|
|
40
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { deriveSecrets } from './crypto.js';
|
|
2
|
+
import { calculateAgreement, generateKeyPair, verifySignature } from './curve.js';
|
|
3
|
+
import { BaseKeyType, ChainType, errors, queueJob } from './internals.js';
|
|
4
|
+
import SessionRecord from './session-record.js';
|
|
5
|
+
class SessionBuilder {
|
|
6
|
+
constructor(storage, protocolAddress) {
|
|
7
|
+
this.addr = protocolAddress;
|
|
8
|
+
this.storage = storage;
|
|
9
|
+
}
|
|
10
|
+
async initOutgoing(device) {
|
|
11
|
+
const fqAddr = this.addr.toString();
|
|
12
|
+
return await queueJob(fqAddr, async () => {
|
|
13
|
+
if (!await this.storage.isTrustedIdentity(this.addr.id, device.identityKey)) {
|
|
14
|
+
throw new errors.UntrustedIdentityKeyError(this.addr.id, device.identityKey);
|
|
15
|
+
}
|
|
16
|
+
verifySignature(device.identityKey, device.signedPreKey.publicKey, device.signedPreKey.signature, true);
|
|
17
|
+
const baseKey = generateKeyPair();
|
|
18
|
+
const devicePreKey = device.preKey && device.preKey.publicKey;
|
|
19
|
+
const session = await this.initSession(true, baseKey, undefined, device.identityKey, devicePreKey, device.signedPreKey.publicKey, device.registrationId);
|
|
20
|
+
session.pendingPreKey = {
|
|
21
|
+
signedKeyId: device.signedPreKey.keyId,
|
|
22
|
+
baseKey: baseKey.pubKey
|
|
23
|
+
};
|
|
24
|
+
if (device.preKey) {
|
|
25
|
+
session.pendingPreKey.preKeyId = device.preKey.keyId;
|
|
26
|
+
}
|
|
27
|
+
let record = await this.storage.loadSession(fqAddr);
|
|
28
|
+
if (!record) {
|
|
29
|
+
record = new SessionRecord();
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
const openSession = record.getOpenSession();
|
|
33
|
+
if (openSession) {
|
|
34
|
+
record.closeSession(openSession);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
record.setSession(session);
|
|
38
|
+
await this.storage.storeSession(fqAddr, record);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async initIncoming(record, message) {
|
|
42
|
+
const fqAddr = this.addr.toString();
|
|
43
|
+
if (!await this.storage.isTrustedIdentity(fqAddr, message.identityKey)) {
|
|
44
|
+
throw new errors.UntrustedIdentityKeyError(this.addr.id, message.identityKey);
|
|
45
|
+
}
|
|
46
|
+
if (record.getSession(message.baseKey)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const preKeyPair = message.preKeyId == null
|
|
50
|
+
? undefined
|
|
51
|
+
: await this.storage.loadPreKey(message.preKeyId);
|
|
52
|
+
if (message.preKeyId && !preKeyPair) {
|
|
53
|
+
throw new errors.PreKeyError('Invalid PreKey ID');
|
|
54
|
+
}
|
|
55
|
+
const signedPreKeyPair = await this.storage.loadSignedPreKey(message.signedPreKeyId);
|
|
56
|
+
if (!signedPreKeyPair) {
|
|
57
|
+
throw new errors.PreKeyError('Missing SignedPreKey');
|
|
58
|
+
}
|
|
59
|
+
const existingOpenSession = record.getOpenSession();
|
|
60
|
+
if (existingOpenSession) {
|
|
61
|
+
record.closeSession(existingOpenSession);
|
|
62
|
+
}
|
|
63
|
+
record.setSession(await this.initSession(false, preKeyPair, signedPreKeyPair, message.identityKey, message.baseKey, undefined, message.registrationId));
|
|
64
|
+
return message.preKeyId;
|
|
65
|
+
}
|
|
66
|
+
async initSession(isInitiator, ourEphemeralKey, ourSignedKey, theirIdentityPubKey, theirEphemeralPubKey, theirSignedPubKey, registrationId) {
|
|
67
|
+
if (isInitiator) {
|
|
68
|
+
if (ourSignedKey) {
|
|
69
|
+
throw new Error('Invalid call to initSession');
|
|
70
|
+
}
|
|
71
|
+
ourSignedKey = ourEphemeralKey;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
if (theirSignedPubKey) {
|
|
75
|
+
throw new Error('Invalid call to initSession');
|
|
76
|
+
}
|
|
77
|
+
theirSignedPubKey = theirEphemeralPubKey;
|
|
78
|
+
}
|
|
79
|
+
let sharedSecret;
|
|
80
|
+
if (!ourEphemeralKey || !theirEphemeralPubKey) {
|
|
81
|
+
sharedSecret = new Uint8Array(32 * 4);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
sharedSecret = new Uint8Array(32 * 5);
|
|
85
|
+
}
|
|
86
|
+
for (var i = 0; i < 32; i++) {
|
|
87
|
+
sharedSecret[i] = 0xff;
|
|
88
|
+
}
|
|
89
|
+
const ourIdentityKey = await this.storage.getOurIdentity();
|
|
90
|
+
const a1 = calculateAgreement(theirSignedPubKey, ourIdentityKey.privKey);
|
|
91
|
+
const a2 = calculateAgreement(theirIdentityPubKey, ourSignedKey.privKey);
|
|
92
|
+
const a3 = calculateAgreement(theirSignedPubKey, ourSignedKey.privKey);
|
|
93
|
+
if (isInitiator) {
|
|
94
|
+
sharedSecret.set(new Uint8Array(a1), 32);
|
|
95
|
+
sharedSecret.set(new Uint8Array(a2), 32 * 2);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
sharedSecret.set(new Uint8Array(a1), 32 * 2);
|
|
99
|
+
sharedSecret.set(new Uint8Array(a2), 32);
|
|
100
|
+
}
|
|
101
|
+
sharedSecret.set(new Uint8Array(a3), 32 * 3);
|
|
102
|
+
if (ourEphemeralKey && theirEphemeralPubKey) {
|
|
103
|
+
const a4 = calculateAgreement(theirEphemeralPubKey, ourEphemeralKey.privKey);
|
|
104
|
+
sharedSecret.set(new Uint8Array(a4), 32 * 4);
|
|
105
|
+
}
|
|
106
|
+
const masterKey = deriveSecrets(Buffer.from(sharedSecret), Buffer.alloc(32), Buffer.from('WhisperText'));
|
|
107
|
+
const session = SessionRecord.createEntry();
|
|
108
|
+
session.registrationId = registrationId;
|
|
109
|
+
session.currentRatchet = {
|
|
110
|
+
rootKey: masterKey[0],
|
|
111
|
+
ephemeralKeyPair: isInitiator ? generateKeyPair() : ourSignedKey,
|
|
112
|
+
lastRemoteEphemeralKey: theirSignedPubKey,
|
|
113
|
+
previousCounter: 0
|
|
114
|
+
};
|
|
115
|
+
session.indexInfo = {
|
|
116
|
+
created: Date.now(),
|
|
117
|
+
used: Date.now(),
|
|
118
|
+
remoteIdentityKey: theirIdentityPubKey,
|
|
119
|
+
baseKey: isInitiator ? ourEphemeralKey.pubKey : theirEphemeralPubKey,
|
|
120
|
+
baseKeyType: isInitiator ? BaseKeyType.OURS : BaseKeyType.THEIRS,
|
|
121
|
+
closed: -1
|
|
122
|
+
};
|
|
123
|
+
if (isInitiator) {
|
|
124
|
+
this.calculateSendingRatchet(session, theirSignedPubKey);
|
|
125
|
+
}
|
|
126
|
+
return session;
|
|
127
|
+
}
|
|
128
|
+
calculateSendingRatchet(session, remoteKey) {
|
|
129
|
+
const ratchet = session.currentRatchet;
|
|
130
|
+
const sharedSecret = calculateAgreement(remoteKey, ratchet.ephemeralKeyPair.privKey);
|
|
131
|
+
const masterKey = deriveSecrets(sharedSecret, ratchet.rootKey, Buffer.from('WhisperRatchet'));
|
|
132
|
+
session.addChain(ratchet.ephemeralKeyPair.pubKey, {
|
|
133
|
+
messageKeys: {},
|
|
134
|
+
chainKey: {
|
|
135
|
+
counter: -1,
|
|
136
|
+
key: masterKey[1]
|
|
137
|
+
},
|
|
138
|
+
chainType: ChainType.SENDING
|
|
139
|
+
});
|
|
140
|
+
ratchet.rootKey = masterKey[0];
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
export default SessionBuilder;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export default SessionCipher;
|
|
2
|
+
declare class SessionCipher {
|
|
3
|
+
constructor(storage: any, protocolAddress: any);
|
|
4
|
+
addr: ProtocolAddress;
|
|
5
|
+
storage: any;
|
|
6
|
+
_encodeTupleByte(number1: any, number2: any): number;
|
|
7
|
+
_decodeTupleByte(byte: any): number[];
|
|
8
|
+
toString(): string;
|
|
9
|
+
getRecord(): Promise<any>;
|
|
10
|
+
storeRecord(record: any): Promise<void>;
|
|
11
|
+
queueJob(awaitable: any): Promise<any>;
|
|
12
|
+
encrypt(data: any): Promise<any>;
|
|
13
|
+
decryptWithSessions(data: any, sessions: any): Promise<{
|
|
14
|
+
session: any;
|
|
15
|
+
plaintext: any;
|
|
16
|
+
}>;
|
|
17
|
+
decryptWhisperMessage(data: any): Promise<any>;
|
|
18
|
+
decryptPreKeyWhisperMessage(data: any): Promise<any>;
|
|
19
|
+
doDecryptWhisperMessage(messageBuffer: any, session: any): Promise<any>;
|
|
20
|
+
fillMessageKeys(chain: any, counter: any): void;
|
|
21
|
+
maybeStepRatchet(session: any, remoteKey: any, previousCounter: any): void;
|
|
22
|
+
calculateRatchet(session: any, remoteKey: any, sending: any): void;
|
|
23
|
+
hasOpenSession(): Promise<any>;
|
|
24
|
+
closeOpenSession(): Promise<any>;
|
|
25
|
+
}
|
|
26
|
+
import { ProtocolAddress } from './internals.js';
|