@pontalabs/baileys 1.0.5 → 1.0.6
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 +1 -1
- package/README.md +267 -839
- package/WAProto/GenerateStatics.sh +3 -4
- package/WAProto/WAProto.proto +1215 -511
- package/WAProto/fix-imports.js +85 -0
- package/WAProto/index.d.ts +14017 -55
- package/WAProto/index.js +97689 -29
- package/engine-requirements.js +10 -0
- package/lib/Defaults/index.d.ts +72 -74
- package/lib/Defaults/index.d.ts.map +1 -0
- package/lib/Defaults/index.js +94 -108
- package/lib/Defaults/index.js.map +1 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +8 -7
- package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -0
- package/lib/Signal/Group/ciphertext-message.js +9 -16
- package/lib/Signal/Group/ciphertext-message.js.map +1 -0
- package/lib/Signal/Group/group-session-builder.d.ts +11 -13
- package/lib/Signal/Group/group-session-builder.d.ts.map +1 -0
- package/lib/Signal/Group/group-session-builder.js +19 -61
- package/lib/Signal/Group/group-session-builder.js.map +1 -0
- package/lib/Signal/Group/group_cipher.d.ts +14 -16
- package/lib/Signal/Group/group_cipher.d.ts.map +1 -0
- package/lib/Signal/Group/group_cipher.js +41 -70
- package/lib/Signal/Group/group_cipher.js.map +1 -0
- package/lib/Signal/Group/index.d.ts +12 -11
- package/lib/Signal/Group/index.d.ts.map +1 -0
- package/lib/Signal/Group/index.js +12 -61
- package/lib/Signal/Group/index.js.map +1 -0
- package/lib/Signal/Group/keyhelper.d.ts +9 -14
- package/lib/Signal/Group/keyhelper.d.ts.map +1 -0
- package/lib/Signal/Group/keyhelper.js +10 -58
- package/lib/Signal/Group/keyhelper.js.map +1 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -13
- package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-chain-key.js +13 -34
- package/lib/Signal/Group/sender-chain-key.js.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -16
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +28 -36
- package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -18
- package/lib/Signal/Group/sender-key-message.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-message.js +38 -45
- package/lib/Signal/Group/sender-key-message.js.map +1 -0
- package/lib/Signal/Group/sender-key-name.d.ts +14 -15
- package/lib/Signal/Group/sender-key-name.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-name.js +20 -31
- package/lib/Signal/Group/sender-key-name.js.map +1 -0
- package/lib/Signal/Group/sender-key-record.d.ts +24 -25
- package/lib/Signal/Group/sender-key-record.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-record.js +18 -35
- package/lib/Signal/Group/sender-key-record.js.map +1 -0
- package/lib/Signal/Group/sender-key-state.d.ts +29 -34
- package/lib/Signal/Group/sender-key-state.d.ts.map +1 -0
- package/lib/Signal/Group/sender-key-state.js +37 -100
- package/lib/Signal/Group/sender-key-state.js.map +1 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -10
- package/lib/Signal/Group/sender-message-key.d.ts.map +1 -0
- package/lib/Signal/Group/sender-message-key.js +15 -22
- package/lib/Signal/Group/sender-message-key.js.map +1 -0
- package/lib/Signal/libsignal.d.ts +5 -8
- package/lib/Signal/libsignal.d.ts.map +1 -0
- package/lib/Signal/libsignal.js +288 -142
- package/lib/Signal/libsignal.js.map +1 -0
- package/lib/Signal/lid-mapping.d.ts +23 -28
- package/lib/Signal/lid-mapping.d.ts.map +1 -0
- package/lib/Signal/lid-mapping.js +277 -184
- package/lib/Signal/lid-mapping.js.map +1 -0
- package/lib/Socket/Client/index.d.ts +3 -2
- package/lib/Socket/Client/index.d.ts.map +1 -0
- package/lib/Socket/Client/index.js +3 -22
- package/lib/Socket/Client/index.js.map +1 -0
- package/lib/Socket/Client/types.d.ts +15 -15
- package/lib/Socket/Client/types.d.ts.map +1 -0
- package/lib/Socket/Client/types.js +8 -15
- package/lib/Socket/Client/types.js.map +1 -0
- package/lib/Socket/Client/websocket.d.ts +12 -12
- package/lib/Socket/Client/websocket.d.ts.map +1 -0
- package/lib/Socket/Client/websocket.js +29 -37
- package/lib/Socket/Client/websocket.js.map +1 -0
- package/lib/Socket/business.d.ts +208 -178
- package/lib/Socket/business.d.ts.map +1 -0
- package/lib/Socket/business.js +91 -127
- package/lib/Socket/business.js.map +1 -0
- package/lib/Socket/chats.d.ts +120 -93
- package/lib/Socket/chats.d.ts.map +1 -0
- package/lib/Socket/chats.js +727 -652
- package/lib/Socket/chats.js.map +1 -0
- package/lib/Socket/communities.d.ts +273 -0
- package/lib/Socket/communities.d.ts.map +1 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/communities.js.map +1 -0
- package/lib/Socket/dugong.js +261 -0
- package/lib/Socket/dugong.js.bak +204 -0
- package/lib/Socket/groups.d.ts +143 -111
- package/lib/Socket/groups.d.ts.map +1 -0
- package/lib/Socket/groups.js +165 -177
- package/lib/Socket/groups.js.map +1 -0
- package/lib/Socket/index.d.ts +252 -183
- package/lib/Socket/index.d.ts.map +1 -0
- package/lib/Socket/index.js +38 -18
- package/lib/Socket/index.js.bak +44 -0
- package/lib/Socket/index.js.map +1 -0
- package/lib/Socket/messages-recv.d.ts +196 -167
- package/lib/Socket/messages-recv.d.ts.map +1 -0
- package/lib/Socket/messages-recv.js +1443 -1563
- package/lib/Socket/messages-recv.js.map +1 -0
- package/lib/Socket/messages-send.d.ts +192 -158
- package/lib/Socket/messages-send.d.ts.map +1 -0
- package/lib/Socket/messages-send.js +1102 -1208
- package/lib/Socket/messages-send.js.bak +1400 -0
- package/lib/Socket/messages-send.js.map +1 -0
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.d.ts.map +1 -0
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/mex.js.map +1 -0
- package/lib/Socket/newsletter.d.ts +163 -138
- package/lib/Socket/newsletter.d.ts.map +1 -0
- package/lib/Socket/newsletter.js +153 -249
- package/lib/Socket/newsletter.js.map +1 -0
- package/lib/Socket/socket.d.ts +50 -36
- package/lib/Socket/socket.d.ts.map +1 -0
- package/lib/Socket/socket.js +749 -820
- package/lib/Socket/socket.js.map +1 -0
- package/lib/Store/index.d.ts +4 -4
- package/lib/Store/index.d.ts.map +1 -0
- package/lib/Store/index.js +4 -24
- package/lib/Store/index.js.map +1 -0
- package/lib/Store/make-in-memory-store.d.ts +44 -104
- package/lib/Store/make-in-memory-store.d.ts.map +1 -0
- package/lib/Store/make-in-memory-store.js +199 -213
- package/lib/Store/make-in-memory-store.js.map +1 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -12
- package/lib/Store/make-ordered-dictionary.d.ts.map +1 -0
- package/lib/Store/make-ordered-dictionary.js +38 -45
- package/lib/Store/make-ordered-dictionary.js.map +1 -0
- package/lib/Store/object-repository.d.ts +11 -10
- package/lib/Store/object-repository.d.ts.map +1 -0
- package/lib/Store/object-repository.js +9 -16
- package/lib/Store/object-repository.js.map +1 -0
- package/lib/Types/Auth.d.ts +93 -97
- package/lib/Types/Auth.d.ts.map +1 -0
- package/lib/Types/Auth.js +2 -3
- package/lib/Types/Auth.js.map +1 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.d.ts.map +1 -0
- package/lib/Types/Bussines.js +2 -3
- package/lib/Types/Bussines.js.map +1 -0
- package/lib/Types/Call.d.ts +14 -13
- package/lib/Types/Call.d.ts.map +1 -0
- package/lib/Types/Call.js +2 -3
- package/lib/Types/Call.js.map +1 -0
- package/lib/Types/Chat.d.ts +78 -97
- package/lib/Types/Chat.d.ts.map +1 -0
- package/lib/Types/Chat.js +8 -9
- package/lib/Types/Chat.js.map +1 -0
- package/lib/Types/Contact.d.ts +12 -9
- package/lib/Types/Contact.d.ts.map +1 -0
- package/lib/Types/Contact.js +2 -3
- package/lib/Types/Contact.js.map +1 -0
- package/lib/Types/Events.d.ts +206 -176
- package/lib/Types/Events.d.ts.map +1 -0
- package/lib/Types/Events.js +2 -3
- package/lib/Types/Events.js.map +1 -0
- package/lib/Types/GroupMetadata.d.ts +53 -48
- package/lib/Types/GroupMetadata.d.ts.map +1 -0
- package/lib/Types/GroupMetadata.js +2 -3
- package/lib/Types/GroupMetadata.js.map +1 -0
- package/lib/Types/Label.d.ts +13 -14
- package/lib/Types/Label.d.ts.map +1 -0
- package/lib/Types/Label.js +24 -30
- package/lib/Types/Label.js.map +1 -0
- package/lib/Types/LabelAssociation.d.ts +15 -20
- package/lib/Types/LabelAssociation.d.ts.map +1 -0
- package/lib/Types/LabelAssociation.js +6 -12
- package/lib/Types/LabelAssociation.js.map +1 -0
- package/lib/Types/Message.d.ts +248 -412
- package/lib/Types/Message.d.ts.map +1 -0
- package/lib/Types/Message.js +17 -19
- package/lib/Types/Message.js.map +1 -0
- package/lib/Types/Mex.d.ts +141 -0
- package/lib/Types/Mex.d.ts.map +1 -0
- package/lib/Types/Mex.js +37 -0
- package/lib/Types/Mex.js.map +1 -0
- package/lib/Types/Product.d.ts +58 -71
- package/lib/Types/Product.d.ts.map +1 -0
- package/lib/Types/Product.js +2 -3
- package/lib/Types/Product.js.map +1 -0
- package/lib/Types/RichType.d.ts +3 -0
- package/lib/Types/RichType.d.ts.map +1 -0
- package/lib/Types/RichType.js +23 -0
- package/lib/Types/RichType.js.bak +23 -0
- package/lib/Types/RichType.js.map +1 -0
- package/lib/Types/Signal.d.ts +71 -82
- package/lib/Types/Signal.d.ts.map +1 -0
- package/lib/Types/Signal.js +2 -3
- package/lib/Types/Signal.js.map +1 -0
- package/lib/Types/Socket.d.ts +76 -81
- package/lib/Types/Socket.d.ts.map +1 -0
- package/lib/Types/Socket.js +3 -3
- package/lib/Types/Socket.js.map +1 -0
- package/lib/Types/State.d.ts +75 -19
- package/lib/Types/State.d.ts.map +1 -0
- package/lib/Types/State.js +56 -14
- package/lib/Types/State.js.map +1 -0
- package/lib/Types/USync.d.ts +8 -8
- package/lib/Types/USync.d.ts.map +1 -0
- package/lib/Types/USync.js +2 -3
- package/lib/Types/USync.js.map +1 -0
- package/lib/Types/index.d.ts +47 -62
- package/lib/Types/index.d.ts.map +1 -0
- package/lib/Types/index.js +26 -50
- package/lib/Types/index.js.map +1 -0
- package/lib/Utils/auth-utils.d.ts +13 -10
- package/lib/Utils/auth-utils.d.ts.map +1 -0
- package/lib/Utils/auth-utils.js +213 -472
- package/lib/Utils/auth-utils.js.map +1 -0
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.d.ts.map +1 -0
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/browser-utils.js.map +1 -0
- package/lib/Utils/business.d.ts +14 -20
- package/lib/Utils/business.d.ts.map +1 -0
- package/lib/Utils/business.js +110 -134
- package/lib/Utils/business.js.map +1 -0
- package/lib/Utils/chat-utils.d.ts +88 -70
- package/lib/Utils/chat-utils.d.ts.map +1 -0
- package/lib/Utils/chat-utils.js +466 -403
- package/lib/Utils/chat-utils.js.map +1 -0
- package/lib/Utils/companion-reg-client-utils.d.ts +17 -0
- package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -0
- package/lib/Utils/companion-reg-client-utils.js +35 -0
- package/lib/Utils/companion-reg-client-utils.js.map +1 -0
- package/lib/Utils/crypto.d.ts +27 -46
- package/lib/Utils/crypto.d.ts.map +1 -0
- package/lib/Utils/crypto.js +117 -188
- package/lib/Utils/crypto.js.map +1 -0
- package/lib/Utils/decode-wa-message.d.ts +58 -45
- package/lib/Utils/decode-wa-message.d.ts.map +1 -0
- package/lib/Utils/decode-wa-message.js +213 -303
- package/lib/Utils/decode-wa-message.js.map +1 -0
- package/lib/Utils/event-buffer.d.ts +14 -17
- package/lib/Utils/event-buffer.d.ts.map +1 -0
- package/lib/Utils/event-buffer.js +321 -296
- package/lib/Utils/event-buffer.js.map +1 -0
- package/lib/Utils/generics.d.ts +66 -92
- package/lib/Utils/generics.d.ts.map +1 -0
- package/lib/Utils/generics.js +270 -436
- package/lib/Utils/generics.js.map +1 -0
- package/lib/Utils/history.d.ts +24 -23
- package/lib/Utils/history.d.ts.map +1 -0
- package/lib/Utils/history.js +106 -76
- package/lib/Utils/history.js.map +1 -0
- package/lib/Utils/identity-change-handler.d.ts +44 -0
- package/lib/Utils/identity-change-handler.d.ts.map +1 -0
- package/lib/Utils/identity-change-handler.js +50 -0
- package/lib/Utils/identity-change-handler.js.map +1 -0
- package/lib/Utils/index.d.ts +24 -21
- package/lib/Utils/index.d.ts.map +1 -0
- package/lib/Utils/index.js +24 -41
- package/lib/Utils/index.js.map +1 -0
- package/lib/Utils/link-preview.d.ts +12 -14
- package/lib/Utils/link-preview.d.ts.map +1 -0
- package/lib/Utils/link-preview.js +40 -75
- package/lib/Utils/link-preview.js.map +1 -0
- package/lib/Utils/logger.d.ts +10 -11
- package/lib/Utils/logger.d.ts.map +1 -0
- package/lib/Utils/logger.js +3 -7
- package/lib/Utils/logger.js.map +1 -0
- package/lib/Utils/lt-hash.d.ts +8 -14
- package/lib/Utils/lt-hash.d.ts.map +1 -0
- package/lib/Utils/lt-hash.js +3 -53
- package/lib/Utils/lt-hash.js.map +1 -0
- package/lib/Utils/make-mutex.d.ts +7 -7
- package/lib/Utils/make-mutex.d.ts.map +1 -0
- package/lib/Utils/make-mutex.js +28 -44
- package/lib/Utils/make-mutex.js.map +1 -0
- package/lib/Utils/message-retry-manager.d.ts +115 -88
- package/lib/Utils/message-retry-manager.d.ts.map +1 -0
- package/lib/Utils/message-retry-manager.js +265 -160
- package/lib/Utils/message-retry-manager.js.map +1 -0
- package/lib/Utils/messages-media.d.ts +105 -107
- package/lib/Utils/messages-media.d.ts.map +1 -0
- package/lib/Utils/messages-media.js +548 -619
- package/lib/Utils/messages-media.js.bak +786 -0
- package/lib/Utils/messages-media.js.map +1 -0
- package/lib/Utils/messages.d.ts +52 -66
- package/lib/Utils/messages.d.ts.map +1 -0
- package/lib/Utils/messages.js +1730 -1558
- package/lib/Utils/messages.js.backup +1768 -0
- package/lib/Utils/messages.js.bak +1809 -0
- package/lib/Utils/messages.js.bak2 +893 -0
- package/lib/Utils/messages.js.bak3 +1183 -0
- package/lib/Utils/messages.js.map +1 -0
- package/lib/Utils/noise-handler.d.ts +18 -18
- package/lib/Utils/noise-handler.d.ts.map +1 -0
- package/lib/Utils/noise-handler.js +176 -130
- package/lib/Utils/noise-handler.js.map +1 -0
- package/lib/Utils/offline-node-processor.d.ts +17 -0
- package/lib/Utils/offline-node-processor.d.ts.map +1 -0
- package/lib/Utils/offline-node-processor.js +40 -0
- package/lib/Utils/offline-node-processor.js.map +1 -0
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.d.ts.map +1 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/pre-key-manager.js.map +1 -0
- package/lib/Utils/process-message.d.ts +43 -32
- package/lib/Utils/process-message.d.ts.map +1 -0
- package/lib/Utils/process-message.js +484 -282
- package/lib/Utils/process-message.js.map +1 -0
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.d.ts.map +1 -0
- package/lib/Utils/reporting-utils.js +258 -0
- package/lib/Utils/reporting-utils.js.map +1 -0
- package/lib/Utils/rich-message-utils.d.ts +49 -0
- package/lib/Utils/rich-message-utils.d.ts.map +1 -0
- package/lib/Utils/rich-message-utils.js +1220 -724
- package/lib/Utils/rich-message-utils.js.backup +706 -0
- package/lib/Utils/rich-message-utils.js.bak +246 -0
- package/lib/Utils/rich-message-utils.js.map +1 -0
- package/lib/Utils/rich-message-utils.js.original +1332 -0
- package/lib/Utils/signal.d.ts +37 -32
- package/lib/Utils/signal.d.ts.map +1 -0
- package/lib/Utils/signal.js +140 -105
- package/lib/Utils/signal.js.map +1 -0
- package/lib/Utils/stanza-ack.d.ts +11 -0
- package/lib/Utils/stanza-ack.d.ts.map +1 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/stanza-ack.js.map +1 -0
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.d.ts.map +1 -0
- package/lib/Utils/sync-action-utils.js +49 -0
- package/lib/Utils/sync-action-utils.js.map +1 -0
- package/lib/Utils/tc-token-utils.d.ts +37 -0
- package/lib/Utils/tc-token-utils.d.ts.map +1 -0
- package/lib/Utils/tc-token-utils.js +163 -0
- package/lib/Utils/tc-token-utils.js.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +5 -5
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-multi-file-auth-state.js +70 -120
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +11 -13
- package/lib/Utils/use-single-file-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-single-file-auth-state.js +92 -66
- package/lib/Utils/use-single-file-auth-state.js.map +1 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts.map +1 -0
- package/lib/Utils/use-sqlite-auth-state.js +109 -0
- package/lib/Utils/use-sqlite-auth-state.js.map +1 -0
- package/lib/Utils/validate-connection.d.ts +11 -13
- package/lib/Utils/validate-connection.d.ts.map +1 -0
- package/lib/Utils/validate-connection.js +128 -113
- package/lib/Utils/validate-connection.js.map +1 -0
- package/lib/WABinary/constants.d.ts +25 -27
- package/lib/WABinary/constants.d.ts.map +1 -0
- package/lib/WABinary/constants.js +1451 -1292
- package/lib/WABinary/constants.js.bak +1373 -0
- package/lib/WABinary/constants.js.map +1 -0
- package/lib/WABinary/decode.d.ts +7 -9
- package/lib/WABinary/decode.d.ts.map +1 -0
- package/lib/WABinary/decode.js +163 -189
- package/lib/WABinary/decode.js.map +1 -0
- package/lib/WABinary/encode.d.ts +3 -3
- package/lib/WABinary/encode.d.ts.map +1 -0
- package/lib/WABinary/encode.js +110 -155
- package/lib/WABinary/encode.js.map +1 -0
- package/lib/WABinary/generic-utils.d.ts +14 -27
- package/lib/WABinary/generic-utils.d.ts.map +1 -0
- package/lib/WABinary/generic-utils.js +177 -105
- package/lib/WABinary/generic-utils.js.map +1 -0
- package/lib/WABinary/index.d.ts +6 -5
- package/lib/WABinary/index.d.ts.map +1 -0
- package/lib/WABinary/index.js +6 -25
- package/lib/WABinary/index.js.map +1 -0
- package/lib/WABinary/jid-utils.d.ts +41 -51
- package/lib/WABinary/jid-utils.d.ts.map +1 -0
- package/lib/WABinary/jid-utils.js +83 -120
- package/lib/WABinary/jid-utils.js.map +1 -0
- package/lib/WABinary/types.d.ts +10 -13
- package/lib/WABinary/types.d.ts.map +1 -0
- package/lib/WABinary/types.js +2 -3
- package/lib/WABinary/types.js.map +1 -0
- package/lib/WAM/BinaryInfo.d.ts +8 -15
- package/lib/WAM/BinaryInfo.d.ts.map +1 -0
- package/lib/WAM/BinaryInfo.js +7 -14
- package/lib/WAM/BinaryInfo.js.map +1 -0
- package/lib/WAM/constants.d.ts +30 -37
- package/lib/WAM/constants.d.ts.map +1 -0
- package/lib/WAM/constants.js +19193 -11711
- package/lib/WAM/constants.js.map +1 -0
- package/lib/WAM/encode.d.ts +3 -3
- package/lib/WAM/encode.d.ts.map +1 -0
- package/lib/WAM/encode.js +95 -109
- package/lib/WAM/encode.js.map +1 -0
- package/lib/WAM/index.d.ts +4 -3
- package/lib/WAM/index.d.ts.map +1 -0
- package/lib/WAM/index.js +4 -23
- package/lib/WAM/index.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -9
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +37 -21
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +19 -22
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +18 -26
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +11 -12
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +12 -20
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +11 -12
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +16 -24
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -0
- package/lib/WAUSync/Protocols/index.d.ts +6 -6
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -0
- package/lib/WAUSync/Protocols/index.js +6 -26
- package/lib/WAUSync/Protocols/index.js.map +1 -0
- package/lib/WAUSync/USyncQuery.d.ts +27 -28
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -0
- package/lib/WAUSync/USyncQuery.js +68 -62
- package/lib/WAUSync/USyncQuery.js.map +1 -0
- package/lib/WAUSync/USyncUser.d.ts +15 -10
- package/lib/WAUSync/USyncUser.d.ts.map +1 -0
- package/lib/WAUSync/USyncUser.js +20 -19
- package/lib/WAUSync/USyncUser.js.map +1 -0
- package/lib/WAUSync/index.d.ts +4 -3
- package/lib/WAUSync/index.d.ts.map +1 -0
- package/lib/WAUSync/index.js +4 -23
- package/lib/WAUSync/index.js.map +1 -0
- package/lib/index.d.ts +11 -12
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +12 -39
- package/lib/index.js.map +1 -0
- package/package.json +86 -42
package/lib/Utils/auth-utils.js
CHANGED
|
@@ -1,545 +1,290 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const Defaults_1 = require("../Defaults")
|
|
12
|
-
const LRUCache_1 = require("lru-cache")
|
|
13
|
-
const crypto_2 = require("./crypto")
|
|
14
|
-
const generics_1 = require("./generics")
|
|
15
|
-
const mutex_1 = require("async-mutex")
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
// Cache bypass for signal-sensitive keys so runtime state doesn't keep stale
|
|
19
|
-
// session/pre-key material alive after decrypt failures or identity rotation.
|
|
20
|
-
const NO_CACHE_TYPES = new Set([
|
|
21
|
-
'pre-key',
|
|
22
|
-
'session',
|
|
23
|
-
'signed-pre-key',
|
|
24
|
-
'identity-key'
|
|
25
|
-
])
|
|
26
|
-
|
|
1
|
+
import NodeCache from '@cacheable/node-cache';
|
|
2
|
+
import { Boom } from '@hapi/boom';
|
|
3
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
4
|
+
import { Mutex } from 'async-mutex';
|
|
5
|
+
import { randomBytes } from 'crypto';
|
|
6
|
+
import PQueue from 'p-queue';
|
|
7
|
+
import { DEFAULT_CACHE_TTLS } from '../Defaults/index.js';
|
|
8
|
+
import { Curve, signedKeyPair } from './crypto.js';
|
|
9
|
+
import { delay, generateRegistrationId } from './generics.js';
|
|
10
|
+
import { PreKeyManager } from './pre-key-manager.js';
|
|
27
11
|
/**
|
|
28
12
|
* Adds caching capability to a SignalKeyStore
|
|
29
13
|
* @param store the store to add caching to
|
|
30
14
|
* @param logger to log trace events
|
|
31
15
|
* @param _cache cache store to use
|
|
32
16
|
*/
|
|
33
|
-
function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
34
|
-
const cache = _cache ||
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
17
|
+
export function makeCacheableSignalKeyStore(store, logger, _cache) {
|
|
18
|
+
const cache = _cache ||
|
|
19
|
+
new NodeCache({
|
|
20
|
+
stdTTL: DEFAULT_CACHE_TTLS.SIGNAL_STORE, // 5 minutes
|
|
21
|
+
useClones: false,
|
|
22
|
+
deleteOnExpire: true
|
|
23
|
+
});
|
|
40
24
|
// Mutex for protecting cache operations
|
|
41
|
-
const cacheMutex = new
|
|
42
|
-
|
|
25
|
+
const cacheMutex = new Mutex();
|
|
43
26
|
function getUniqueId(type, id) {
|
|
44
|
-
return `${type}.${id}
|
|
27
|
+
return `${type}.${id}`;
|
|
45
28
|
}
|
|
46
29
|
return {
|
|
47
30
|
async get(type, ids) {
|
|
48
|
-
if (NO_CACHE_TYPES.has(type)) {
|
|
49
|
-
logger?.trace({ type, items: ids.length }, 'bypassing cache for sensitive key type')
|
|
50
|
-
return await store.get(type, ids)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
31
|
return cacheMutex.runExclusive(async () => {
|
|
54
|
-
const data = {}
|
|
55
|
-
const idsToFetch = []
|
|
32
|
+
const data = {};
|
|
33
|
+
const idsToFetch = [];
|
|
56
34
|
for (const id of ids) {
|
|
57
|
-
const item = cache.get(getUniqueId(type, id))
|
|
35
|
+
const item = (await cache.get(getUniqueId(type, id)));
|
|
58
36
|
if (typeof item !== 'undefined') {
|
|
59
|
-
data[id] = item
|
|
37
|
+
data[id] = item;
|
|
60
38
|
}
|
|
61
39
|
else {
|
|
62
|
-
idsToFetch.push(id)
|
|
40
|
+
idsToFetch.push(id);
|
|
63
41
|
}
|
|
64
42
|
}
|
|
65
43
|
if (idsToFetch.length) {
|
|
66
|
-
logger?.trace({ items: idsToFetch.length }, 'loading from store')
|
|
67
|
-
const fetched = await store.get(type, idsToFetch)
|
|
44
|
+
logger?.trace({ items: idsToFetch.length }, 'loading from store');
|
|
45
|
+
const fetched = await store.get(type, idsToFetch);
|
|
68
46
|
for (const id of idsToFetch) {
|
|
69
|
-
const item = fetched[id]
|
|
47
|
+
const item = fetched[id];
|
|
70
48
|
if (item) {
|
|
71
|
-
data[id] = item
|
|
72
|
-
|
|
49
|
+
data[id] = item;
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
51
|
+
await cache.set(getUniqueId(type, id), item);
|
|
73
52
|
}
|
|
74
53
|
}
|
|
75
54
|
}
|
|
76
|
-
return data
|
|
77
|
-
})
|
|
55
|
+
return data;
|
|
56
|
+
});
|
|
78
57
|
},
|
|
79
58
|
async set(data) {
|
|
80
59
|
return cacheMutex.runExclusive(async () => {
|
|
81
|
-
let keys = 0
|
|
60
|
+
let keys = 0;
|
|
82
61
|
for (const type in data) {
|
|
83
|
-
if (NO_CACHE_TYPES.has(type)) {
|
|
84
|
-
continue
|
|
85
|
-
}
|
|
86
62
|
for (const id in data[type]) {
|
|
87
|
-
await cache.set(getUniqueId(type, id), data[type][id])
|
|
88
|
-
keys += 1
|
|
63
|
+
await cache.set(getUniqueId(type, id), data[type][id]);
|
|
64
|
+
keys += 1;
|
|
89
65
|
}
|
|
90
66
|
}
|
|
91
|
-
logger?.trace({ keys }, 'updated cache')
|
|
92
|
-
await store.set(data)
|
|
93
|
-
})
|
|
67
|
+
logger?.trace({ keys }, 'updated cache');
|
|
68
|
+
await store.set(data);
|
|
69
|
+
});
|
|
94
70
|
},
|
|
95
71
|
async clear() {
|
|
96
|
-
await cache.flushAll()
|
|
97
|
-
await store.clear?.
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Handles pre-key operations.
|
|
104
|
-
*
|
|
105
|
-
* IMPORTANT: locking for this function is provided by the CALLER via the
|
|
106
|
-
* session-scoped `getKeyTypeMutex(keyType)` mutex (the same one used by
|
|
107
|
-
* get()/set() for that key type). We intentionally do NOT acquire our own
|
|
108
|
-
* mutex here anymore.
|
|
109
|
-
*
|
|
110
|
-
* Previously this used module-level singleton mutexes (`preKeyMutex`,
|
|
111
|
-
* `signedPreKeyMutex`) declared OUTSIDE `addTransactionCapability`. Because
|
|
112
|
-
* those were created once per process (not once per auth state / socket),
|
|
113
|
-
* every session running in the same Node process shared the exact same
|
|
114
|
-
* lock. That caused two problems:
|
|
115
|
-
* 1. Unrelated sessions serialized on each other's pre-key writes
|
|
116
|
-
* (needless contention/latency when running multiple accounts).
|
|
117
|
-
* 2. The lock domain didn't match the one used by get()/withMutexes()
|
|
118
|
-
* (`getKeyTypeMutex`), so reads/writes and deletion-validation could
|
|
119
|
-
* interleave without real mutual exclusion (TOCTOU race on the
|
|
120
|
-
* "does this key still exist" check), which is what let pre-key /
|
|
121
|
-
* signed-pre-key state get corrupted under concurrent access.
|
|
122
|
-
*/
|
|
123
|
-
async function handlePreKeyOperations(data, keyType, transactionCache, mutations, logger, isInTransaction, state) {
|
|
124
|
-
const keyData = data[keyType]
|
|
125
|
-
if (!keyData)
|
|
126
|
-
return
|
|
127
|
-
|
|
128
|
-
// Ensure structures exist
|
|
129
|
-
transactionCache[keyType] = transactionCache[keyType] || {}
|
|
130
|
-
mutations[keyType] = mutations[keyType] || {}
|
|
131
|
-
|
|
132
|
-
// Separate deletions from updates for batch processing
|
|
133
|
-
const deletionKeys = []
|
|
134
|
-
const updateKeys = []
|
|
135
|
-
|
|
136
|
-
for (const keyId in keyData) {
|
|
137
|
-
if (keyData[keyId] === null) {
|
|
138
|
-
deletionKeys.push(keyId)
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
updateKeys.push(keyId)
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Process updates first (no validation needed)
|
|
146
|
-
for (const keyId of updateKeys) {
|
|
147
|
-
if (transactionCache[keyType]) {
|
|
148
|
-
transactionCache[keyType][keyId] = keyData[keyId]
|
|
149
|
-
}
|
|
150
|
-
if (mutations[keyType]) {
|
|
151
|
-
mutations[keyType][keyId] = keyData[keyId]
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Process deletions with validation
|
|
156
|
-
if (deletionKeys.length === 0)
|
|
157
|
-
return
|
|
158
|
-
|
|
159
|
-
if (isInTransaction) {
|
|
160
|
-
// In transaction, only allow deletion if key exists in cache
|
|
161
|
-
for (const keyId of deletionKeys) {
|
|
162
|
-
if (transactionCache[keyType]) {
|
|
163
|
-
transactionCache[keyType][keyId] = null
|
|
164
|
-
if (mutations[keyType]) {
|
|
165
|
-
// Mark for deletion in mutations
|
|
166
|
-
mutations[keyType][keyId] = null
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
logger.warn(`Skipping deletion of non-existent ${keyType} in transaction: ${keyId}`)
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// Outside transaction, batch validate all deletions
|
|
177
|
-
if (!state)
|
|
178
|
-
return
|
|
179
|
-
|
|
180
|
-
const existingKeys = await state.get(keyType, deletionKeys)
|
|
181
|
-
for (const keyId of deletionKeys) {
|
|
182
|
-
if (existingKeys[keyId]) {
|
|
183
|
-
if (transactionCache[keyType])
|
|
184
|
-
transactionCache[keyType][keyId] = null
|
|
185
|
-
if (mutations[keyType])
|
|
186
|
-
mutations[keyType][keyId] = null
|
|
72
|
+
await cache.flushAll();
|
|
73
|
+
await store.clear?.();
|
|
187
74
|
}
|
|
188
|
-
|
|
189
|
-
logger.warn(`Skipping deletion of non-existent ${keyType}: ${keyId}`)
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* Handles normal key operations for transactions
|
|
196
|
-
*/
|
|
197
|
-
function handleNormalKeyOperations(data, key, transactionCache, mutations) {
|
|
198
|
-
Object.assign(transactionCache[key], data[key])
|
|
199
|
-
mutations[key] = mutations[key] || {}
|
|
200
|
-
Object.assign(mutations[key], data[key])
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Process pre-key / signed-pre-key deletions with validation.
|
|
205
|
-
*
|
|
206
|
-
* NOTE: this is only ever called from inside a `withMutexes([..., keyType, ...])`
|
|
207
|
-
* block in `set()` below, which already holds the session-scoped
|
|
208
|
-
* `getKeyTypeMutex(keyType)` lock for the duration of the call. It must NOT
|
|
209
|
-
* acquire its own mutex here - `async-mutex`'s Mutex is not reentrant, so
|
|
210
|
-
* doing so would either deadlock (if it tried to re-acquire the same lock)
|
|
211
|
-
* or - as in the previous version - silently acquire a *different*, global
|
|
212
|
-
* lock that gave no real protection at all.
|
|
213
|
-
*/
|
|
214
|
-
async function processPreKeyDeletions(data, keyType, state, logger) {
|
|
215
|
-
const keyData = data[keyType]
|
|
216
|
-
if (!keyData)
|
|
217
|
-
return
|
|
218
|
-
|
|
219
|
-
// Validate deletions
|
|
220
|
-
const deletionIds = Object.keys(keyData).filter(id => keyData[id] === null)
|
|
221
|
-
if (deletionIds.length === 0)
|
|
222
|
-
return
|
|
223
|
-
|
|
224
|
-
const existingKeys = await state.get(keyType, deletionIds)
|
|
225
|
-
for (const keyId of deletionIds) {
|
|
226
|
-
if (!existingKeys[keyId]) {
|
|
227
|
-
logger.warn(`Skipping deletion of non-existent ${keyType}: ${keyId}`)
|
|
228
|
-
if (data[keyType])
|
|
229
|
-
delete data[keyType][keyId]
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Executes a function with mutexes acquired for given key types
|
|
236
|
-
* Uses async-mutex's runExclusive with efficient batching
|
|
237
|
-
*/
|
|
238
|
-
async function withMutexes(keyTypes, getKeyTypeMutex, fn) {
|
|
239
|
-
if (keyTypes.length === 0) {
|
|
240
|
-
return fn()
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
if (keyTypes.length === 1) {
|
|
244
|
-
return getKeyTypeMutex(keyTypes[0]).runExclusive(fn)
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
// For multiple mutexes, sort by key type to prevent deadlocks
|
|
248
|
-
// Then acquire all mutexes in order using Promise.all for better efficiency
|
|
249
|
-
const sortedKeyTypes = [...keyTypes].sort()
|
|
250
|
-
const mutexes = sortedKeyTypes.map(getKeyTypeMutex)
|
|
251
|
-
|
|
252
|
-
// Acquire all mutexes in order to prevent deadlocks
|
|
253
|
-
const releases = []
|
|
254
|
-
try {
|
|
255
|
-
for (const mutex of mutexes) {
|
|
256
|
-
releases.push(await mutex.acquire())
|
|
257
|
-
}
|
|
258
|
-
return await fn()
|
|
259
|
-
}
|
|
260
|
-
finally {
|
|
261
|
-
// Release in reverse order
|
|
262
|
-
while (releases.length > 0) {
|
|
263
|
-
const release = releases.pop()
|
|
264
|
-
if (release)
|
|
265
|
-
release()
|
|
266
|
-
}
|
|
267
|
-
}
|
|
75
|
+
};
|
|
268
76
|
}
|
|
269
|
-
|
|
270
77
|
/**
|
|
271
|
-
* Adds DB
|
|
272
|
-
*
|
|
78
|
+
* Adds DB-like transaction capability to the SignalKeyStore
|
|
79
|
+
* Uses AsyncLocalStorage for automatic context management
|
|
273
80
|
* @param state the key store to apply this capability to
|
|
274
81
|
* @param logger logger to log events
|
|
275
82
|
* @returns SignalKeyStore with transaction capability
|
|
276
83
|
*/
|
|
277
|
-
const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetweenTriesMs }) => {
|
|
278
|
-
|
|
279
|
-
//
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
//
|
|
285
|
-
const
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
return getMutex(`keytype:${type}`)
|
|
84
|
+
export const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetweenTriesMs }) => {
|
|
85
|
+
const txStorage = new AsyncLocalStorage();
|
|
86
|
+
// Queues for concurrency control (keyed by signal data type - bounded set)
|
|
87
|
+
const keyQueues = new Map();
|
|
88
|
+
// Transaction mutexes with reference counting for cleanup
|
|
89
|
+
const txMutexes = new Map();
|
|
90
|
+
const txMutexRefCounts = new Map();
|
|
91
|
+
// Pre-key manager for specialized operations
|
|
92
|
+
const preKeyManager = new PreKeyManager(state, logger);
|
|
93
|
+
/**
|
|
94
|
+
* Get or create a queue for a specific key type
|
|
95
|
+
*/
|
|
96
|
+
function getQueue(key) {
|
|
97
|
+
if (!keyQueues.has(key)) {
|
|
98
|
+
keyQueues.set(key, new PQueue({ concurrency: 1 }));
|
|
99
|
+
}
|
|
100
|
+
return keyQueues.get(key);
|
|
295
101
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
102
|
+
/**
|
|
103
|
+
* Get or create a transaction mutex
|
|
104
|
+
*/
|
|
105
|
+
function getTxMutex(key) {
|
|
106
|
+
if (!txMutexes.has(key)) {
|
|
107
|
+
txMutexes.set(key, new Mutex());
|
|
108
|
+
txMutexRefCounts.set(key, 0);
|
|
109
|
+
}
|
|
110
|
+
return txMutexes.get(key);
|
|
299
111
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
112
|
+
/**
|
|
113
|
+
* Acquire a reference to a transaction mutex
|
|
114
|
+
*/
|
|
115
|
+
function acquireTxMutexRef(key) {
|
|
116
|
+
const count = txMutexRefCounts.get(key) ?? 0;
|
|
117
|
+
txMutexRefCounts.set(key, count + 1);
|
|
303
118
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
119
|
+
/**
|
|
120
|
+
* Release a reference to a transaction mutex and cleanup if no longer needed
|
|
121
|
+
*/
|
|
122
|
+
function releaseTxMutexRef(key) {
|
|
123
|
+
const count = (txMutexRefCounts.get(key) ?? 1) - 1;
|
|
124
|
+
txMutexRefCounts.set(key, count);
|
|
125
|
+
// Cleanup if no more references and mutex is not locked
|
|
126
|
+
if (count <= 0) {
|
|
127
|
+
const mutex = txMutexes.get(key);
|
|
128
|
+
if (mutex && !mutex.isLocked()) {
|
|
129
|
+
txMutexes.delete(key);
|
|
130
|
+
txMutexRefCounts.delete(key);
|
|
131
|
+
}
|
|
312
132
|
}
|
|
313
|
-
return mutex
|
|
314
133
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
return getSenderKeyMutex(senderKeyName).runExclusive(operation)
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
// Check if we are currently in a transaction
|
|
134
|
+
/**
|
|
135
|
+
* Check if currently in a transaction
|
|
136
|
+
*/
|
|
322
137
|
function isInTransaction() {
|
|
323
|
-
return
|
|
138
|
+
return !!txStorage.getStore();
|
|
324
139
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
140
|
+
/**
|
|
141
|
+
* Commit transaction with retries
|
|
142
|
+
*/
|
|
143
|
+
async function commitWithRetry(mutations) {
|
|
144
|
+
if (Object.keys(mutations).length === 0) {
|
|
145
|
+
logger.trace('no mutations in transaction');
|
|
146
|
+
return;
|
|
331
147
|
}
|
|
332
148
|
logger.trace('committing transaction');
|
|
333
|
-
let
|
|
334
|
-
while (tries > 0) {
|
|
335
|
-
tries -= 1;
|
|
149
|
+
for (let attempt = 0; attempt < maxCommitRetries; attempt++) {
|
|
336
150
|
try {
|
|
337
|
-
await state.set(mutations)
|
|
338
|
-
logger.trace({
|
|
339
|
-
return
|
|
151
|
+
await state.set(mutations);
|
|
152
|
+
logger.trace({ mutationCount: Object.keys(mutations).length }, 'committed transaction');
|
|
153
|
+
return;
|
|
340
154
|
}
|
|
341
155
|
catch (error) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
156
|
+
const retriesLeft = maxCommitRetries - attempt - 1;
|
|
157
|
+
logger.warn(`failed to commit mutations, retries left=${retriesLeft}`);
|
|
158
|
+
if (retriesLeft === 0) {
|
|
159
|
+
throw error;
|
|
345
160
|
}
|
|
161
|
+
await delay(delayBetweenTriesMs);
|
|
346
162
|
}
|
|
347
163
|
}
|
|
348
164
|
}
|
|
349
|
-
|
|
350
|
-
// Helper function to clean up transaction state
|
|
351
|
-
function cleanupTransactionState() {
|
|
352
|
-
transactionsInProgress -= 1
|
|
353
|
-
if (transactionsInProgress === 0) {
|
|
354
|
-
transactionCache = {}
|
|
355
|
-
mutations = {}
|
|
356
|
-
dbQueriesInTransaction = 0
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
// Helper function to execute work within transaction
|
|
361
|
-
async function executeTransactionWork(work) {
|
|
362
|
-
const result = await work()
|
|
363
|
-
// commit if this is the outermost transaction
|
|
364
|
-
if (transactionsInProgress === 1) {
|
|
365
|
-
await commitTransaction()
|
|
366
|
-
}
|
|
367
|
-
return result
|
|
368
|
-
}
|
|
369
|
-
|
|
370
165
|
return {
|
|
371
166
|
get: async (type, ids) => {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
// only fetch if there are any items to fetch
|
|
377
|
-
if (idsRequiringFetch.length) {
|
|
378
|
-
dbQueriesInTransaction += 1
|
|
379
|
-
|
|
380
|
-
// Use per-sender-key queue for sender-key operations when possible
|
|
381
|
-
if (type === 'sender-key') {
|
|
382
|
-
logger.info({ idsRequiringFetch }, 'processing sender keys in transaction')
|
|
383
|
-
// For sender keys, process each one with queued operations to maintain serialization
|
|
384
|
-
for (const senderKeyName of idsRequiringFetch) {
|
|
385
|
-
await queueSenderKeyOperation(senderKeyName, async () => {
|
|
386
|
-
logger.info({ senderKeyName }, 'fetching sender key in transaction')
|
|
387
|
-
const result = await state.get(type, [senderKeyName])
|
|
388
|
-
// Update transaction cache
|
|
389
|
-
transactionCache[type] || (transactionCache[type] = {})
|
|
390
|
-
Object.assign(transactionCache[type], result)
|
|
391
|
-
logger.info({ senderKeyName, hasResult: !!result[senderKeyName] }, 'sender key fetch complete')
|
|
392
|
-
})
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
else {
|
|
396
|
-
// Use runExclusive for cleaner mutex handling
|
|
397
|
-
await getKeyTypeMutex(type).runExclusive(async () => {
|
|
398
|
-
const result = await state.get(type, idsRequiringFetch)
|
|
399
|
-
// Update transaction cache
|
|
400
|
-
transactionCache[type] || (transactionCache[type] = {})
|
|
401
|
-
Object.assign(transactionCache[type], result)
|
|
402
|
-
})
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
return ids.reduce((dict, id) => {
|
|
406
|
-
const value = transactionCache[type]?.[id]
|
|
407
|
-
if (value) {
|
|
408
|
-
dict[id] = value
|
|
409
|
-
}
|
|
410
|
-
return dict
|
|
411
|
-
}, {})
|
|
167
|
+
const ctx = txStorage.getStore();
|
|
168
|
+
if (!ctx) {
|
|
169
|
+
// No transaction - direct read without exclusive lock for concurrency
|
|
170
|
+
return state.get(type, ids);
|
|
412
171
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
172
|
+
// In transaction - check cache first
|
|
173
|
+
const cached = ctx.cache[type] || {};
|
|
174
|
+
const missing = ids.filter(id => !(id in cached));
|
|
175
|
+
if (missing.length > 0) {
|
|
176
|
+
ctx.dbQueries++;
|
|
177
|
+
logger.trace({ type, count: missing.length }, 'fetching missing keys in transaction');
|
|
178
|
+
const fetched = await getTxMutex(type).runExclusive(() => state.get(type, missing));
|
|
179
|
+
// Update cache
|
|
180
|
+
ctx.cache[type] = ctx.cache[type] || {};
|
|
181
|
+
Object.assign(ctx.cache[type], fetched);
|
|
182
|
+
}
|
|
183
|
+
// Return requested ids from cache
|
|
184
|
+
const result = {};
|
|
185
|
+
for (const id of ids) {
|
|
186
|
+
const value = ctx.cache[type]?.[id];
|
|
187
|
+
if (value !== undefined && value !== null) {
|
|
188
|
+
result[id] = value;
|
|
426
189
|
}
|
|
427
190
|
}
|
|
191
|
+
return result;
|
|
428
192
|
},
|
|
429
193
|
set: async (data) => {
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
// no lock-domain mismatch.
|
|
440
|
-
if (key === 'pre-key' || key === 'signed-pre-key') {
|
|
441
|
-
await getKeyTypeMutex(key).runExclusive(() => handlePreKeyOperations(data, key, transactionCache, mutations, logger, true))
|
|
442
|
-
}
|
|
443
|
-
else {
|
|
444
|
-
// Normal handling for other key types
|
|
445
|
-
handleNormalKeyOperations(data, key, transactionCache, mutations)
|
|
194
|
+
const ctx = txStorage.getStore();
|
|
195
|
+
if (!ctx) {
|
|
196
|
+
// No transaction - direct write with queue protection
|
|
197
|
+
const types = Object.keys(data);
|
|
198
|
+
// Process pre-keys with validation
|
|
199
|
+
for (const type_ of types) {
|
|
200
|
+
const type = type_;
|
|
201
|
+
if (type === 'pre-key') {
|
|
202
|
+
await preKeyManager.validateDeletions(data, type);
|
|
446
203
|
}
|
|
447
204
|
}
|
|
205
|
+
// Write all data in parallel
|
|
206
|
+
await Promise.all(types.map(type => getQueue(type).add(async () => {
|
|
207
|
+
const typeData = { [type]: data[type] };
|
|
208
|
+
await state.set(typeData);
|
|
209
|
+
})));
|
|
210
|
+
return;
|
|
448
211
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
const
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
const senderKeyData = {
|
|
460
|
-
'sender-key': {
|
|
461
|
-
[senderKeyName]: data['sender-key'][senderKeyName]
|
|
462
|
-
}
|
|
463
|
-
};
|
|
464
|
-
logger.trace({ senderKeyName }, 'storing sender key')
|
|
465
|
-
// Apply changes to the store
|
|
466
|
-
await state.set(senderKeyData)
|
|
467
|
-
logger.trace({ senderKeyName }, 'sender key stored')
|
|
468
|
-
})
|
|
469
|
-
}
|
|
470
|
-
// Handle any non-sender-key data with regular mutexes
|
|
471
|
-
const nonSenderKeyData = { ...data }
|
|
472
|
-
delete nonSenderKeyData['sender-key']
|
|
473
|
-
if (Object.keys(nonSenderKeyData).length > 0) {
|
|
474
|
-
await withMutexes(Object.keys(nonSenderKeyData), getKeyTypeMutex, async () => {
|
|
475
|
-
// Process pre-keys and signed-pre-keys separately with specialized mutexes
|
|
476
|
-
for (const key_ in nonSenderKeyData) {
|
|
477
|
-
const keyType = key_
|
|
478
|
-
if (keyType === 'pre-key' || keyType === 'signed-pre-key') {
|
|
479
|
-
await processPreKeyDeletions(nonSenderKeyData, keyType, state, logger)
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
// Apply changes to the store
|
|
483
|
-
await state.set(nonSenderKeyData)
|
|
484
|
-
})
|
|
485
|
-
}
|
|
212
|
+
// In transaction - update cache and mutations
|
|
213
|
+
logger.trace({ types: Object.keys(data) }, 'caching in transaction');
|
|
214
|
+
for (const key_ in data) {
|
|
215
|
+
const key = key_;
|
|
216
|
+
// Ensure structures exist
|
|
217
|
+
ctx.cache[key] = ctx.cache[key] || {};
|
|
218
|
+
ctx.mutations[key] = ctx.mutations[key] || {};
|
|
219
|
+
// Special handling for pre-keys
|
|
220
|
+
if (key === 'pre-key') {
|
|
221
|
+
await preKeyManager.processOperations(data, key, ctx.cache, ctx.mutations, true);
|
|
486
222
|
}
|
|
487
223
|
else {
|
|
488
|
-
//
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
for (const key_ in data) {
|
|
492
|
-
const keyType = key_
|
|
493
|
-
if (keyType === 'pre-key' || keyType === 'signed-pre-key') {
|
|
494
|
-
await processPreKeyDeletions(data, keyType, state, logger)
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
// Apply changes to the store
|
|
498
|
-
await state.set(data)
|
|
499
|
-
})
|
|
224
|
+
// Normal key types
|
|
225
|
+
Object.assign(ctx.cache[key], data[key]);
|
|
226
|
+
Object.assign(ctx.mutations[key], data[key]);
|
|
500
227
|
}
|
|
501
228
|
}
|
|
502
229
|
},
|
|
503
230
|
isInTransaction,
|
|
504
|
-
async
|
|
505
|
-
const
|
|
231
|
+
transaction: async (work, key) => {
|
|
232
|
+
const existing = txStorage.getStore();
|
|
233
|
+
// Nested transaction - reuse existing context
|
|
234
|
+
if (existing) {
|
|
235
|
+
logger.trace('reusing existing transaction context');
|
|
236
|
+
return work();
|
|
237
|
+
}
|
|
238
|
+
// New transaction - acquire mutex and create context
|
|
239
|
+
const mutex = getTxMutex(key);
|
|
240
|
+
acquireTxMutexRef(key);
|
|
506
241
|
try {
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
242
|
+
return await mutex.runExclusive(async () => {
|
|
243
|
+
const ctx = {
|
|
244
|
+
cache: {},
|
|
245
|
+
mutations: {},
|
|
246
|
+
dbQueries: 0
|
|
247
|
+
};
|
|
248
|
+
logger.trace('entering transaction');
|
|
249
|
+
try {
|
|
250
|
+
const result = await txStorage.run(ctx, work);
|
|
251
|
+
// Commit mutations
|
|
252
|
+
await commitWithRetry(ctx.mutations);
|
|
253
|
+
logger.trace({ dbQueries: ctx.dbQueries }, 'transaction completed');
|
|
254
|
+
return result;
|
|
255
|
+
}
|
|
256
|
+
catch (error) {
|
|
257
|
+
logger.error({ error }, 'transaction failed, rolling back');
|
|
258
|
+
throw error;
|
|
259
|
+
}
|
|
260
|
+
});
|
|
520
261
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
// (i.e., error thrown before transactionsInProgress was incremented)
|
|
524
|
-
if (transactionsInProgress > 0) {
|
|
525
|
-
cleanupTransactionState()
|
|
526
|
-
}
|
|
527
|
-
releaseTxMutex()
|
|
528
|
-
throw error
|
|
262
|
+
finally {
|
|
263
|
+
releaseTxMutexRef(key);
|
|
529
264
|
}
|
|
530
265
|
}
|
|
266
|
+
};
|
|
267
|
+
};
|
|
268
|
+
/**
|
|
269
|
+
* Returns the authenticated user's JID, or throws a Boom-401 if creds are not yet authenticated.
|
|
270
|
+
* Use this anywhere we'd otherwise reach for `creds.me!.id` to fail fast with a descriptive error.
|
|
271
|
+
*/
|
|
272
|
+
export const assertMeId = (creds) => {
|
|
273
|
+
const id = creds.me?.id;
|
|
274
|
+
if (!id) {
|
|
275
|
+
throw new Boom('Cannot proceed: socket is not authenticated yet (creds.me.id is missing)', { statusCode: 401 });
|
|
531
276
|
}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
const initAuthCreds = () => {
|
|
535
|
-
const identityKey =
|
|
277
|
+
return id;
|
|
278
|
+
};
|
|
279
|
+
export const initAuthCreds = () => {
|
|
280
|
+
const identityKey = Curve.generateKeyPair();
|
|
536
281
|
return {
|
|
537
|
-
noiseKey:
|
|
538
|
-
pairingEphemeralKeyPair:
|
|
282
|
+
noiseKey: Curve.generateKeyPair(),
|
|
283
|
+
pairingEphemeralKeyPair: Curve.generateKeyPair(),
|
|
539
284
|
signedIdentityKey: identityKey,
|
|
540
|
-
signedPreKey:
|
|
541
|
-
registrationId:
|
|
542
|
-
advSecretKey:
|
|
285
|
+
signedPreKey: signedKeyPair(identityKey, 1),
|
|
286
|
+
registrationId: generateRegistrationId(),
|
|
287
|
+
advSecretKey: randomBytes(32).toString('base64'),
|
|
543
288
|
processedHistoryMessages: [],
|
|
544
289
|
nextPreKeyId: 1,
|
|
545
290
|
firstUnuploadedPreKeyId: 1,
|
|
@@ -550,12 +295,8 @@ const initAuthCreds = () => {
|
|
|
550
295
|
registered: false,
|
|
551
296
|
pairingCode: undefined,
|
|
552
297
|
lastPropHash: undefined,
|
|
553
|
-
routingInfo: undefined
|
|
554
|
-
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
makeCacheableSignalKeyStore,
|
|
559
|
-
addTransactionCapability,
|
|
560
|
-
initAuthCreds
|
|
561
|
-
}
|
|
298
|
+
routingInfo: undefined,
|
|
299
|
+
additionalData: undefined
|
|
300
|
+
};
|
|
301
|
+
};
|
|
302
|
+
//# sourceMappingURL=auth-utils.js.map
|