zapo-js 0.3.0 → 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 +21 -0
- package/README.md +97 -177
- package/dist/appstate/{WaAppStateCrypto.js → crypto/WaAppStateCrypto.js} +58 -49
- package/dist/appstate/index.js +7 -6
- package/dist/appstate/{encoding.js → parsers/encoding.js} +11 -4
- package/dist/appstate/{response-parser.js → parsers/response-parser.js} +20 -8
- package/dist/appstate/{WaAppStateSyncClient.js → sync/WaAppStateSyncClient.js} +174 -53
- package/dist/appstate/utils.js +16 -0
- package/dist/appstate-spec.js +89 -0
- package/dist/auth/WaAuthClient.js +100 -5
- package/dist/auth/credentials-flow.js +19 -7
- package/dist/auth/pairing/WaPairingFlow.js +33 -24
- package/dist/auth/pairing/pairing-code-crypto.js +16 -18
- package/dist/client/WaClient.js +342 -473
- package/dist/client/WaClientFactory.js +279 -78
- package/dist/client/connection/WaConnectionManager.js +28 -11
- package/dist/client/coordinators/WaAbPropsCoordinator.js +1 -2
- package/dist/client/coordinators/WaAppStateMutationCoordinator.js +663 -143
- package/dist/client/coordinators/WaBotCoordinator.js +345 -0
- package/dist/client/coordinators/WaBroadcastListCoordinator.js +20 -0
- package/dist/client/coordinators/WaBusinessCoordinator.js +81 -171
- package/dist/client/coordinators/WaEmailCoordinator.js +1 -0
- package/dist/client/coordinators/WaGroupCoordinator.js +529 -52
- package/dist/client/coordinators/WaIncomingNodeCoordinator.js +97 -12
- package/dist/client/coordinators/WaLowLevelCoordinator.js +41 -0
- package/dist/client/coordinators/WaMessageCoordinator.js +365 -0
- package/dist/client/coordinators/WaMessageDispatchCoordinator.js +682 -204
- package/dist/client/coordinators/WaNewsletterCoordinator.js +18 -0
- package/dist/client/coordinators/WaPassiveTasksCoordinator.js +17 -4
- package/dist/client/coordinators/WaPresenceCoordinator.js +21 -0
- package/dist/client/coordinators/WaPrivacyCoordinator.js +7 -5
- package/dist/client/coordinators/WaProfileCoordinator.js +220 -49
- package/dist/client/coordinators/WaRetryCoordinator.js +256 -125
- package/dist/client/coordinators/WaStatusCoordinator.js +49 -0
- package/dist/client/coordinators/WaStreamControlCoordinator.js +6 -6
- package/dist/client/coordinators/WaTrustedContactTokenCoordinator.js +7 -6
- package/dist/client/events/appstate-mutation.js +133 -0
- package/dist/client/events/business.js +375 -0
- package/dist/client/events/call.js +58 -0
- package/dist/client/events/chatstate.js +23 -0
- package/dist/client/events/devices.js +15 -16
- package/dist/client/{dirty.js → events/dirty.js} +33 -19
- package/dist/client/events/group.js +13 -24
- package/dist/client/events/identity.js +2 -1
- package/dist/client/events/incoming.js +502 -0
- package/dist/client/events/mex-notification.js +181 -0
- package/dist/client/events/picture.js +33 -0
- package/dist/client/events/presence.js +44 -0
- package/dist/client/events/receipt.js +26 -0
- package/dist/client/media.js +161 -4
- package/dist/client/messaging/fanout.js +9 -10
- package/dist/client/messaging/{participants.js → group-metadata.js} +73 -35
- package/dist/client/messaging/ignore-key.js +132 -0
- package/dist/client/messaging/key-protocol.js +3 -17
- package/dist/client/messaging/link-preview.js +159 -0
- package/dist/client/messaging/messages.js +671 -0
- package/dist/client/newsletter/admin.js +165 -0
- package/dist/client/newsletter/content.js +253 -0
- package/dist/client/newsletter/discovery.js +115 -0
- package/dist/client/newsletter/messaging.js +197 -0
- package/dist/client/newsletter/mex.js +41 -0
- package/dist/client/newsletter/parse.js +217 -0
- package/dist/client/persistence/WriteBehindPersistence.js +31 -4
- package/dist/client/{history-sync.js → persistence/history-sync.js} +125 -18
- package/dist/client/persistence/mailbox.js +104 -0
- package/dist/client/tokens/cs-token.js +11 -17
- package/dist/crypto/core/hkdf.js +12 -12
- package/dist/crypto/core/index.js +6 -8
- package/dist/crypto/core/keys.js +1 -8
- package/dist/crypto/core/nonce.js +12 -12
- package/dist/crypto/core/primitives.js +123 -93
- package/dist/crypto/core/random.js +6 -0
- package/dist/crypto/core/xeddsa.js +11 -9
- package/dist/crypto/curves/Ed25519.js +32 -21
- package/dist/crypto/curves/X25519.js +70 -34
- package/dist/crypto/curves/constants.js +2 -1
- package/dist/crypto/math/constants.js +1 -2
- package/dist/crypto/math/mod.js +0 -33
- package/dist/esm/appstate/{WaAppStateCrypto.js → crypto/WaAppStateCrypto.js} +58 -49
- package/dist/esm/appstate/index.js +5 -5
- package/dist/esm/appstate/{encoding.js → parsers/encoding.js} +11 -4
- package/dist/esm/appstate/{response-parser.js → parsers/response-parser.js} +20 -8
- package/dist/esm/appstate/{WaAppStateSyncClient.js → sync/WaAppStateSyncClient.js} +174 -52
- package/dist/esm/appstate/utils.js +16 -0
- package/dist/esm/appstate-spec.js +79 -0
- package/dist/esm/auth/WaAuthClient.js +100 -5
- package/dist/esm/auth/credentials-flow.js +18 -6
- package/dist/esm/auth/pairing/WaPairingFlow.js +34 -25
- package/dist/esm/auth/pairing/pairing-code-crypto.js +12 -14
- package/dist/esm/client/WaClient.js +345 -476
- package/dist/esm/client/WaClientFactory.js +280 -79
- package/dist/esm/client/connection/WaConnectionManager.js +28 -11
- package/dist/esm/client/coordinators/WaAbPropsCoordinator.js +2 -3
- package/dist/esm/client/coordinators/WaAppStateMutationCoordinator.js +665 -145
- package/dist/esm/client/coordinators/WaBotCoordinator.js +342 -0
- package/dist/esm/client/coordinators/WaBroadcastListCoordinator.js +17 -0
- package/dist/esm/client/coordinators/WaBusinessCoordinator.js +79 -169
- package/dist/esm/client/coordinators/WaEmailCoordinator.js +1 -0
- package/dist/esm/client/coordinators/WaGroupCoordinator.js +532 -55
- package/dist/esm/client/coordinators/WaIncomingNodeCoordinator.js +98 -13
- package/dist/esm/client/coordinators/WaLowLevelCoordinator.js +38 -0
- package/dist/esm/client/coordinators/WaMessageCoordinator.js +361 -0
- package/dist/esm/client/coordinators/WaMessageDispatchCoordinator.js +686 -208
- package/dist/esm/client/coordinators/WaNewsletterCoordinator.js +13 -0
- package/dist/esm/client/coordinators/WaPassiveTasksCoordinator.js +18 -5
- package/dist/esm/client/coordinators/WaPresenceCoordinator.js +18 -0
- package/dist/esm/client/coordinators/WaPrivacyCoordinator.js +7 -5
- package/dist/esm/client/coordinators/WaProfileCoordinator.js +223 -52
- package/dist/esm/client/coordinators/WaRetryCoordinator.js +258 -127
- package/dist/esm/client/coordinators/WaStatusCoordinator.js +46 -0
- package/dist/esm/client/coordinators/WaStreamControlCoordinator.js +6 -6
- package/dist/esm/client/coordinators/WaTrustedContactTokenCoordinator.js +7 -6
- package/dist/esm/client/events/appstate-mutation.js +130 -0
- package/dist/esm/client/events/business.js +370 -0
- package/dist/esm/client/events/call.js +55 -0
- package/dist/esm/client/events/chatstate.js +20 -0
- package/dist/esm/client/events/devices.js +15 -16
- package/dist/esm/client/{dirty.js → events/dirty.js} +33 -19
- package/dist/esm/client/events/group.js +14 -25
- package/dist/esm/client/events/identity.js +2 -1
- package/dist/esm/client/events/incoming.js +487 -0
- package/dist/esm/client/events/mex-notification.js +178 -0
- package/dist/esm/client/events/picture.js +30 -0
- package/dist/esm/client/events/presence.js +41 -0
- package/dist/esm/client/events/receipt.js +23 -0
- package/dist/esm/client/media.js +156 -6
- package/dist/esm/client/messaging/fanout.js +10 -11
- package/dist/esm/client/messaging/{participants.js → group-metadata.js} +72 -34
- package/dist/esm/client/messaging/ignore-key.js +126 -0
- package/dist/esm/client/messaging/key-protocol.js +3 -17
- package/dist/esm/client/messaging/link-preview.js +156 -0
- package/dist/esm/client/messaging/messages.js +667 -0
- package/dist/esm/client/newsletter/admin.js +162 -0
- package/dist/esm/client/newsletter/content.js +249 -0
- package/dist/esm/client/newsletter/discovery.js +112 -0
- package/dist/esm/client/newsletter/messaging.js +194 -0
- package/dist/esm/client/newsletter/mex.js +37 -0
- package/dist/esm/client/newsletter/parse.js +200 -0
- package/dist/esm/client/persistence/WriteBehindPersistence.js +31 -4
- package/dist/esm/client/{history-sync.js → persistence/history-sync.js} +124 -18
- package/dist/esm/client/persistence/mailbox.js +101 -0
- package/dist/esm/client/tokens/cs-token.js +12 -18
- package/dist/esm/crypto/core/hkdf.js +14 -14
- package/dist/esm/crypto/core/index.js +2 -2
- package/dist/esm/crypto/core/keys.js +1 -7
- package/dist/esm/crypto/core/nonce.js +11 -11
- package/dist/esm/crypto/core/primitives.js +121 -88
- package/dist/esm/crypto/core/random.js +6 -0
- package/dist/esm/crypto/core/xeddsa.js +11 -9
- package/dist/esm/crypto/curves/Ed25519.js +35 -24
- package/dist/esm/crypto/curves/X25519.js +72 -36
- package/dist/esm/crypto/curves/constants.js +1 -0
- package/dist/esm/crypto/math/constants.js +1 -2
- package/dist/esm/crypto/math/mod.js +0 -32
- package/dist/esm/index.js +7 -2
- package/dist/esm/infra/log/ConsoleLogger.js +30 -6
- package/dist/esm/infra/log/PinoLogger.js +64 -0
- package/dist/esm/infra/log/types.js +4 -2
- package/dist/esm/infra/perf/BackgroundQueue.js +55 -13
- package/dist/esm/media/constants.js +33 -2
- package/dist/esm/media/crypto/WaMediaCrypto.js +374 -0
- package/dist/esm/media/index.js +4 -3
- package/dist/esm/media/sticker/sticker-pack.js +133 -0
- package/dist/esm/media/{WaMediaTransferClient.js → transfer/WaMediaTransferClient.js} +37 -6
- package/dist/esm/media/{conn.js → transfer/conn.js} +10 -5
- package/dist/esm/message/WaMessageClient.js +46 -15
- package/dist/esm/message/addons/link-preview/builder.js +36 -0
- package/dist/esm/message/addons/link-preview/detect.js +55 -0
- package/dist/esm/message/addons/link-preview/fetcher.js +391 -0
- package/dist/esm/message/addons/link-preview/types.js +1 -0
- package/dist/esm/message/context-info.js +123 -0
- package/dist/esm/message/{addon-crypto.js → crypto/addon-crypto.js} +68 -10
- package/dist/esm/message/{icdc.js → crypto/icdc.js} +5 -7
- package/dist/esm/message/crypto/phash.js +133 -0
- package/dist/esm/message/{reporting-token.js → crypto/reporting-token.js} +6 -6
- package/dist/esm/message/{use-case-secret.js → crypto/use-case-secret.js} +20 -3
- package/dist/esm/message/{content.js → encode/content.js} +176 -7
- package/dist/esm/message/encode/media-payload.js +42 -0
- package/dist/esm/message/{padding.js → encode/padding.js} +9 -3
- package/dist/esm/message/index.js +2 -2
- package/dist/esm/message/kinds/bot.js +111 -0
- package/dist/esm/message/kinds/newsletter.js +244 -0
- package/dist/esm/message/kinds/sticker-pack.js +29 -0
- package/dist/esm/message/{ack.js → primitives/ack.js} +8 -1
- package/dist/esm/message/{incoming.js → primitives/incoming.js} +215 -31
- package/dist/esm/message/primitives/peer-data-operation.js +93 -0
- package/dist/esm/mex.js +1 -0
- package/dist/esm/protocol/abprops.js +10 -0
- package/dist/esm/protocol/appstate.js +6 -30
- package/dist/esm/protocol/auth.js +3 -2
- package/dist/esm/protocol/bot.js +77 -0
- package/dist/esm/protocol/browser.js +8 -0
- package/dist/esm/protocol/business.js +19 -0
- package/dist/esm/protocol/call.js +48 -0
- package/dist/esm/protocol/constants.js +8 -2
- package/dist/esm/protocol/defaults.js +3 -0
- package/dist/esm/protocol/index.js +1 -1
- package/dist/esm/protocol/jid.js +102 -5
- package/dist/esm/protocol/media.js +25 -12
- package/dist/esm/protocol/message.js +4 -1
- package/dist/esm/protocol/newsletter.js +61 -0
- package/dist/esm/protocol/nodes.js +22 -2
- package/dist/esm/protocol/notification.js +18 -2
- package/dist/esm/protocol/presence.js +13 -0
- package/dist/esm/protocol/status.js +6 -0
- package/dist/esm/retry/codec.js +5 -0
- package/dist/esm/retry/parse.js +20 -38
- package/dist/esm/retry/reason.js +5 -0
- package/dist/esm/retry/replay.js +131 -37
- package/dist/esm/retry/tracker.js +4 -8
- package/dist/esm/signal/api/SignalDeviceSyncApi.js +66 -19
- package/dist/esm/signal/api/SignalDigestSyncApi.js +7 -2
- package/dist/esm/signal/api/SignalIdentitySyncApi.js +9 -0
- package/dist/esm/signal/api/SignalMissingPreKeysSyncApi.js +24 -63
- package/dist/esm/signal/api/SignalRotateKeyApi.js +10 -0
- package/dist/esm/signal/api/SignalSessionSyncApi.js +23 -51
- package/dist/esm/signal/api/codec.js +52 -1
- package/dist/esm/signal/api/prekeys.js +4 -0
- package/dist/esm/signal/{crypto → attestation}/WaAdvSignature.js +5 -6
- package/dist/esm/signal/constants.js +3 -0
- package/dist/esm/signal/encoding.js +6 -289
- package/dist/esm/signal/group/SenderKeyChain.js +18 -33
- package/dist/esm/signal/group/SenderKeyManager.js +25 -8
- package/dist/esm/signal/group/encoding.js +96 -0
- package/dist/esm/signal/index.js +4 -1
- package/dist/esm/signal/registration/encoding.js +34 -0
- package/dist/esm/signal/registration/keygen.js +10 -0
- package/dist/esm/signal/registration/utils.js +6 -0
- package/dist/esm/signal/session/SignalProtocol.js +113 -11
- package/dist/esm/signal/session/SignalRatchet.js +29 -58
- package/dist/esm/signal/session/SignalSession.js +7 -14
- package/dist/esm/signal/session/encoding.js +173 -0
- package/dist/esm/signal/session/resolver.js +139 -30
- package/dist/esm/store/cache/identity.cache.js +75 -0
- package/dist/esm/store/cache/privacy-token.cache.js +57 -0
- package/dist/esm/store/cache/sender-key.cache.js +101 -0
- package/dist/esm/store/cache/session.cache.js +92 -0
- package/dist/esm/store/contracts/group-metadata.store.js +1 -0
- package/dist/esm/store/createStore.js +91 -37
- package/dist/esm/store/index.js +15 -14
- package/dist/esm/store/locks/contact.lock.js +1 -0
- package/dist/esm/store/locks/device-list.lock.js +1 -0
- package/dist/esm/store/locks/group-metadata.lock.js +20 -0
- package/dist/esm/store/{providers/memory → memory}/appstate.store.js +5 -5
- package/dist/esm/store/memory/auth.store.js +24 -0
- package/dist/esm/store/memory/contact.store.js +79 -0
- package/dist/esm/store/memory/device-list.store.js +103 -0
- package/dist/esm/store/{providers/memory/participants.store.js → memory/group-metadata.store.js} +22 -13
- package/dist/esm/store/{providers/memory → memory}/identity.store.js +3 -3
- package/dist/esm/store/{providers/memory → memory}/message-secret.store.js +17 -8
- package/dist/esm/store/{providers/memory → memory}/message.store.js +2 -2
- package/dist/esm/store/{providers/memory → memory}/pre-key.store.js +2 -2
- package/dist/esm/store/{providers/memory → memory}/privacy-token.store.js +1 -1
- package/dist/esm/store/{providers/memory → memory}/retry.store.js +28 -7
- package/dist/esm/store/{providers/memory → memory}/sender-key.store.js +3 -3
- package/dist/esm/store/{providers/memory → memory}/session.store.js +3 -3
- package/dist/esm/store/{providers/memory → memory}/thread.store.js +2 -2
- package/dist/esm/store/noop.store.js +6 -4
- package/dist/esm/transport/WaComms.js +14 -5
- package/dist/esm/transport/WaWebSocket.js +32 -8
- package/dist/esm/transport/binary/constants.js +10 -4
- package/dist/esm/transport/binary/decoder.js +21 -15
- package/dist/esm/transport/binary/encoder.js +96 -21
- package/dist/esm/transport/binary/tokens.js +12 -12
- package/dist/esm/transport/index.js +1 -0
- package/dist/esm/transport/keepalive/WaKeepAlive.js +18 -4
- package/dist/esm/transport/node/WaMobileTcpSocket.js +6 -0
- package/dist/esm/transport/node/WaNodeOrchestrator.js +9 -5
- package/dist/esm/transport/node/WaNodeTransport.js +13 -0
- package/dist/esm/transport/node/builders/abprops.js +2 -2
- package/dist/esm/transport/node/builders/account-sync.js +7 -15
- package/dist/esm/transport/node/builders/bot.js +38 -0
- package/dist/esm/transport/node/builders/business.js +30 -30
- package/dist/esm/transport/node/builders/chatstate.js +28 -0
- package/dist/esm/transport/node/builders/community.js +53 -0
- package/dist/esm/transport/node/builders/device.js +2 -2
- package/dist/esm/transport/node/builders/email.js +6 -5
- package/dist/esm/transport/node/builders/global.js +1 -1
- package/dist/esm/transport/node/builders/group.js +114 -4
- package/dist/esm/transport/node/builders/media.js +2 -2
- package/dist/esm/transport/node/builders/message.js +83 -49
- package/dist/esm/transport/node/builders/newsletter.js +176 -0
- package/dist/esm/transport/node/builders/passive.js +7 -0
- package/dist/esm/transport/node/builders/prekeys.js +4 -4
- package/dist/esm/transport/node/builders/presence.js +27 -1
- package/dist/esm/transport/node/builders/privacy-token.js +2 -2
- package/dist/esm/transport/node/builders/privacy.js +6 -6
- package/dist/esm/transport/node/builders/profile.js +28 -8
- package/dist/esm/transport/node/builders/tos.js +58 -0
- package/dist/esm/transport/node/builders/usync.js +51 -2
- package/dist/esm/transport/node/helpers.js +3 -1
- package/dist/esm/transport/node/mex/argo-decoder.js +2 -2
- package/dist/esm/transport/node/mex/client.js +22 -0
- package/dist/esm/transport/node/query.js +17 -0
- package/dist/esm/transport/node/usync.js +12 -0
- package/dist/esm/transport/noise/WaClientPayload.js +8 -8
- package/dist/esm/transport/noise/WaMobileClientPayload.js +5 -0
- package/dist/esm/transport/noise/WaNoiseCert.js +5 -0
- package/dist/esm/transport/noise/WaNoiseHandshake.js +27 -25
- package/dist/esm/transport/noise/WaNoiseSession.js +39 -59
- package/dist/esm/transport/noise/WaNoiseSocket.js +19 -13
- package/dist/esm/transport/noise/constants.js +0 -1
- package/dist/esm/transport/proxy.js +5 -0
- package/dist/esm/transport/stream/parse.js +3 -7
- package/dist/esm/transport/wa-web-version-fetcher.js +91 -0
- package/dist/esm/util/async.js +4 -0
- package/dist/esm/util/bytes.js +37 -2
- package/dist/esm/util/clock.js +15 -0
- package/dist/esm/util/coercion.js +45 -3
- package/dist/esm/util/collections.js +11 -0
- package/dist/esm/util/index.js +2 -2
- package/dist/esm/util/primitives.js +19 -0
- package/dist/esm/util/runtime.js +5 -0
- package/dist/esm/version-spec.js +1 -0
- package/dist/index.js +31 -1
- package/dist/infra/log/ConsoleLogger.js +30 -6
- package/dist/infra/log/PinoLogger.js +64 -0
- package/dist/infra/log/types.js +4 -2
- package/dist/infra/perf/BackgroundQueue.js +55 -13
- package/dist/media/constants.js +34 -3
- package/dist/media/crypto/WaMediaCrypto.js +378 -0
- package/dist/media/index.js +9 -4
- package/dist/media/sticker/sticker-pack.js +136 -0
- package/dist/media/{WaMediaTransferClient.js → transfer/WaMediaTransferClient.js} +37 -6
- package/dist/media/{conn.js → transfer/conn.js} +10 -5
- package/dist/message/WaMessageClient.js +46 -15
- package/dist/message/addons/link-preview/builder.js +39 -0
- package/dist/message/addons/link-preview/detect.js +58 -0
- package/dist/message/addons/link-preview/fetcher.js +394 -0
- package/dist/message/addons/link-preview/types.js +2 -0
- package/dist/message/context-info.js +129 -0
- package/dist/message/{addon-crypto.js → crypto/addon-crypto.js} +68 -10
- package/dist/message/{icdc.js → crypto/icdc.js} +5 -7
- package/dist/message/crypto/phash.js +136 -0
- package/dist/message/{reporting-token.js → crypto/reporting-token.js} +6 -6
- package/dist/message/{use-case-secret.js → crypto/use-case-secret.js} +20 -3
- package/dist/message/{content.js → encode/content.js} +192 -7
- package/dist/message/encode/media-payload.js +45 -0
- package/dist/message/{padding.js → encode/padding.js} +9 -3
- package/dist/message/index.js +2 -2
- package/dist/message/kinds/bot.js +120 -0
- package/dist/message/kinds/newsletter.js +248 -0
- package/dist/message/kinds/sticker-pack.js +34 -0
- package/dist/message/{ack.js → primitives/ack.js} +8 -1
- package/dist/message/{incoming.js → primitives/incoming.js} +216 -31
- package/dist/message/primitives/peer-data-operation.js +96 -0
- package/dist/mex.js +6 -0
- package/dist/proto.js +1 -1
- package/dist/protocol/abprops.js +10 -0
- package/dist/protocol/appstate.js +7 -31
- package/dist/protocol/auth.js +3 -2
- package/dist/protocol/bot.js +81 -0
- package/dist/protocol/browser.js +8 -0
- package/dist/protocol/business.js +22 -0
- package/dist/protocol/call.js +51 -0
- package/dist/protocol/constants.js +39 -3
- package/dist/protocol/defaults.js +3 -0
- package/dist/protocol/index.js +12 -3
- package/dist/protocol/jid.js +107 -5
- package/dist/protocol/media.js +25 -12
- package/dist/protocol/message.js +4 -1
- package/dist/protocol/newsletter.js +64 -0
- package/dist/protocol/nodes.js +22 -2
- package/dist/protocol/notification.js +19 -3
- package/dist/protocol/presence.js +16 -0
- package/dist/protocol/status.js +9 -0
- package/dist/retry/codec.js +5 -0
- package/dist/retry/parse.js +16 -34
- package/dist/retry/reason.js +5 -0
- package/dist/retry/replay.js +129 -35
- package/dist/retry/tracker.js +3 -7
- package/dist/signal/api/SignalDeviceSyncApi.js +64 -17
- package/dist/signal/api/SignalDigestSyncApi.js +6 -1
- package/dist/signal/api/SignalIdentitySyncApi.js +9 -0
- package/dist/signal/api/SignalMissingPreKeysSyncApi.js +21 -60
- package/dist/signal/api/SignalRotateKeyApi.js +10 -0
- package/dist/signal/api/SignalSessionSyncApi.js +20 -48
- package/dist/signal/api/codec.js +52 -0
- package/dist/signal/api/prekeys.js +4 -0
- package/dist/signal/{crypto → attestation}/WaAdvSignature.js +5 -7
- package/dist/signal/constants.js +4 -1
- package/dist/signal/encoding.js +5 -303
- package/dist/signal/group/SenderKeyChain.js +17 -32
- package/dist/signal/group/SenderKeyManager.js +24 -7
- package/dist/signal/group/encoding.js +101 -0
- package/dist/signal/index.js +13 -10
- package/dist/signal/registration/encoding.js +39 -0
- package/dist/signal/registration/keygen.js +10 -0
- package/dist/signal/registration/utils.js +6 -0
- package/dist/signal/session/SignalProtocol.js +112 -10
- package/dist/signal/session/SignalRatchet.js +24 -54
- package/dist/signal/session/SignalSession.js +6 -14
- package/dist/signal/session/encoding.js +183 -0
- package/dist/signal/session/resolver.js +139 -30
- package/dist/store/cache/identity.cache.js +78 -0
- package/dist/store/cache/privacy-token.cache.js +60 -0
- package/dist/store/cache/sender-key.cache.js +104 -0
- package/dist/store/cache/session.cache.js +95 -0
- package/dist/store/contracts/group-metadata.store.js +2 -0
- package/dist/store/createStore.js +90 -36
- package/dist/store/index.js +18 -16
- package/dist/store/locks/contact.lock.js +1 -0
- package/dist/store/locks/device-list.lock.js +1 -0
- package/dist/store/locks/group-metadata.lock.js +23 -0
- package/dist/store/{providers/memory → memory}/appstate.store.js +5 -5
- package/dist/store/memory/auth.store.js +28 -0
- package/dist/store/memory/contact.store.js +83 -0
- package/dist/store/memory/device-list.store.js +107 -0
- package/dist/store/{providers/memory/participants.store.js → memory/group-metadata.store.js} +24 -15
- package/dist/store/{providers/memory → memory}/identity.store.js +3 -3
- package/dist/store/{providers/memory → memory}/message-secret.store.js +17 -8
- package/dist/store/{providers/memory → memory}/message.store.js +2 -2
- package/dist/store/{providers/memory → memory}/pre-key.store.js +2 -2
- package/dist/store/{providers/memory → memory}/privacy-token.store.js +1 -1
- package/dist/store/{providers/memory → memory}/retry.store.js +28 -7
- package/dist/store/{providers/memory → memory}/sender-key.store.js +3 -3
- package/dist/store/{providers/memory → memory}/session.store.js +3 -3
- package/dist/store/{providers/memory → memory}/thread.store.js +2 -2
- package/dist/store/noop.store.js +7 -5
- package/dist/transport/WaComms.js +14 -5
- package/dist/transport/WaWebSocket.js +32 -8
- package/dist/transport/binary/constants.js +11 -5
- package/dist/transport/binary/decoder.js +24 -18
- package/dist/transport/binary/encoder.js +109 -34
- package/dist/transport/binary/tokens.js +12 -12
- package/dist/transport/index.js +3 -1
- package/dist/transport/keepalive/WaKeepAlive.js +18 -4
- package/dist/transport/node/WaMobileTcpSocket.js +6 -0
- package/dist/transport/node/WaNodeOrchestrator.js +9 -5
- package/dist/transport/node/WaNodeTransport.js +13 -0
- package/dist/transport/node/builders/abprops.js +1 -1
- package/dist/transport/node/builders/account-sync.js +7 -16
- package/dist/transport/node/builders/bot.js +43 -0
- package/dist/transport/node/builders/business.js +31 -31
- package/dist/transport/node/builders/chatstate.js +31 -0
- package/dist/transport/node/builders/community.js +59 -0
- package/dist/transport/node/builders/device.js +1 -1
- package/dist/transport/node/builders/email.js +6 -5
- package/dist/transport/node/builders/global.js +1 -1
- package/dist/transport/node/builders/group.js +121 -3
- package/dist/transport/node/builders/media.js +1 -1
- package/dist/transport/node/builders/message.js +84 -49
- package/dist/transport/node/builders/newsletter.js +183 -0
- package/dist/transport/node/builders/passive.js +10 -0
- package/dist/transport/node/builders/prekeys.js +3 -3
- package/dist/transport/node/builders/presence.js +28 -1
- package/dist/transport/node/builders/privacy-token.js +1 -1
- package/dist/transport/node/builders/privacy.js +5 -5
- package/dist/transport/node/builders/profile.js +30 -7
- package/dist/transport/node/builders/tos.js +63 -0
- package/dist/transport/node/builders/usync.js +52 -1
- package/dist/transport/node/helpers.js +2 -1
- package/dist/transport/node/mex/argo-decoder.js +2 -2
- package/dist/transport/node/mex/client.js +23 -0
- package/dist/transport/node/query.js +17 -0
- package/dist/transport/node/usync.js +13 -0
- package/dist/transport/noise/WaClientPayload.js +8 -8
- package/dist/transport/noise/WaMobileClientPayload.js +5 -0
- package/dist/transport/noise/WaNoiseCert.js +5 -0
- package/dist/transport/noise/WaNoiseHandshake.js +25 -23
- package/dist/transport/noise/WaNoiseSession.js +39 -59
- package/dist/transport/noise/WaNoiseSocket.js +18 -12
- package/dist/transport/noise/constants.js +1 -2
- package/dist/transport/proxy.js +5 -0
- package/dist/transport/stream/parse.js +3 -7
- package/dist/transport/wa-web-version-fetcher.js +94 -0
- package/dist/types/appstate/constants.d.ts +1 -1
- package/dist/types/appstate/{WaAppStateCrypto.d.ts → crypto/WaAppStateCrypto.d.ts} +26 -9
- package/dist/types/appstate/index.d.ts +5 -5
- package/dist/types/appstate/{encoding.d.ts → parsers/encoding.d.ts} +8 -1
- package/dist/types/appstate/{response-parser.d.ts → parsers/response-parser.d.ts} +13 -3
- package/dist/types/appstate/sync/WaAppStateSyncClient.d.ts +105 -0
- package/dist/types/appstate/utils.d.ts +17 -1
- package/dist/types/appstate-spec.d.ts +24 -0
- package/dist/types/auth/WaAuthClient.d.ts +89 -3
- package/dist/types/auth/credentials-flow.d.ts +4 -3
- package/dist/types/auth/pairing/pairing-code-crypto.d.ts +0 -1
- package/dist/types/auth/types.d.ts +48 -1
- package/dist/types/client/WaClient.d.ts +178 -71
- package/dist/types/client/WaClientFactory.d.ts +30 -5
- package/dist/types/client/connection/WaConnectionManager.d.ts +4 -2
- package/dist/types/client/connection/WaReceiptQueue.d.ts +1 -1
- package/dist/types/client/coordinators/WaAppStateMutationCoordinator.d.ts +215 -5
- package/dist/types/client/coordinators/WaBotCoordinator.d.ts +117 -0
- package/dist/types/client/coordinators/WaBroadcastListCoordinator.d.ts +39 -0
- package/dist/types/client/coordinators/WaBusinessCoordinator.d.ts +44 -43
- package/dist/types/client/coordinators/WaEmailCoordinator.d.ts +16 -0
- package/dist/types/client/coordinators/WaGroupCoordinator.d.ts +311 -9
- package/dist/types/client/coordinators/WaIncomingNodeCoordinator.d.ts +11 -4
- package/dist/types/client/coordinators/WaLowLevelCoordinator.d.ts +47 -0
- package/dist/types/client/coordinators/WaMessageCoordinator.d.ts +232 -0
- package/dist/types/client/coordinators/WaMessageDispatchCoordinator.d.ts +54 -31
- package/dist/types/client/coordinators/WaNewsletterCoordinator.d.ts +13 -0
- package/dist/types/client/coordinators/WaPassiveTasksCoordinator.d.ts +4 -3
- package/dist/types/client/coordinators/WaPresenceCoordinator.d.ts +27 -0
- package/dist/types/client/coordinators/WaPrivacyCoordinator.d.ts +27 -0
- package/dist/types/client/coordinators/WaProfileCoordinator.d.ts +113 -0
- package/dist/types/client/coordinators/WaRetryCoordinator.d.ts +19 -17
- package/dist/types/client/coordinators/WaStatusCoordinator.d.ts +42 -0
- package/dist/types/client/coordinators/WaTrustedContactTokenCoordinator.d.ts +5 -1
- package/dist/types/client/events/abprops.d.ts +2 -1
- package/dist/types/client/events/appstate-mutation.d.ts +3 -0
- package/dist/types/client/events/business.d.ts +10 -0
- package/dist/types/client/events/call.d.ts +31 -0
- package/dist/types/client/events/chatstate.d.ts +9 -0
- package/dist/types/client/events/devices.d.ts +5 -4
- package/dist/types/client/{dirty.d.ts → events/dirty.d.ts} +4 -3
- package/dist/types/client/events/group.d.ts +2 -1
- package/dist/types/client/events/identity.d.ts +2 -1
- package/dist/types/client/{incoming.d.ts → events/incoming.d.ts} +27 -4
- package/dist/types/client/events/mex-notification.d.ts +6 -0
- package/dist/types/client/events/picture.d.ts +8 -0
- package/dist/types/client/events/presence.d.ts +28 -0
- package/dist/types/client/events/receipt.d.ts +14 -0
- package/dist/types/client/events/registration.d.ts +4 -3
- package/dist/types/client/index.d.ts +1 -1
- package/dist/types/client/media.d.ts +35 -1
- package/dist/types/client/messaging/fanout.d.ts +2 -2
- package/dist/types/client/messaging/group-metadata.d.ts +19 -0
- package/dist/types/client/messaging/ignore-key.d.ts +11 -0
- package/dist/types/client/messaging/key-protocol.d.ts +9 -7
- package/dist/types/client/messaging/link-preview.d.ts +19 -0
- package/dist/types/client/messaging/messages.d.ts +28 -0
- package/dist/types/client/newsletter/admin.d.ts +71 -0
- package/dist/types/client/newsletter/content.d.ts +42 -0
- package/dist/types/client/newsletter/discovery.d.ts +33 -0
- package/dist/types/client/newsletter/messaging.d.ts +66 -0
- package/dist/types/client/newsletter/mex.d.ts +14 -0
- package/dist/types/client/newsletter/parse.d.ts +19 -0
- package/dist/types/client/newsletter/types.d.ts +190 -0
- package/dist/types/client/persistence/WriteBehindPersistence.d.ts +12 -1
- package/dist/types/client/persistence/history-sync.d.ts +29 -0
- package/dist/types/client/{mailbox.d.ts → persistence/mailbox.d.ts} +4 -4
- package/dist/types/client/tokens/cs-token.d.ts +1 -3
- package/dist/types/client/types.d.ts +843 -71
- package/dist/types/crypto/core/hkdf.d.ts +10 -2
- package/dist/types/crypto/core/index.d.ts +2 -2
- package/dist/types/crypto/core/keys.d.ts +0 -4
- package/dist/types/crypto/core/nonce.d.ts +4 -5
- package/dist/types/crypto/core/primitives.d.ts +31 -20
- package/dist/types/crypto/core/random.d.ts +6 -0
- package/dist/types/crypto/core/xeddsa.d.ts +9 -0
- package/dist/types/crypto/curves/Ed25519.d.ts +7 -1
- package/dist/types/crypto/curves/X25519.d.ts +20 -1
- package/dist/types/crypto/curves/constants.d.ts +4 -3
- package/dist/types/crypto/curves/types.d.ts +0 -5
- package/dist/types/crypto/math/constants.d.ts +0 -1
- package/dist/types/crypto/math/mod.d.ts +0 -1
- package/dist/types/index.d.ts +32 -6
- package/dist/types/infra/log/ConsoleLogger.d.ts +18 -1
- package/dist/types/infra/log/PinoLogger.d.ts +55 -1
- package/dist/types/infra/log/types.d.ts +6 -0
- package/dist/types/infra/perf/BackgroundQueue.d.ts +19 -0
- package/dist/types/media/constants.d.ts +7 -2
- package/dist/types/media/crypto/WaMediaCrypto.d.ts +59 -0
- package/dist/types/media/index.d.ts +7 -5
- package/dist/types/media/processor.d.ts +27 -5
- package/dist/types/media/sticker/sticker-pack.d.ts +6 -0
- package/dist/types/media/{WaMediaTransferClient.d.ts → transfer/WaMediaTransferClient.d.ts} +30 -1
- package/dist/types/media/transfer/conn.d.ts +7 -0
- package/dist/types/media/types.d.ts +1 -2
- package/dist/types/message/WaMessageClient.d.ts +14 -0
- package/dist/types/message/addons/link-preview/builder.d.ts +13 -0
- package/dist/types/message/addons/link-preview/detect.d.ts +5 -0
- package/dist/types/message/addons/link-preview/fetcher.d.ts +13 -0
- package/dist/types/message/addons/link-preview/types.d.ts +51 -0
- package/dist/types/message/context-info.d.ts +66 -0
- package/dist/types/message/{addon-crypto.d.ts → crypto/addon-crypto.d.ts} +27 -5
- package/dist/types/message/{icdc.d.ts → crypto/icdc.d.ts} +4 -4
- package/dist/types/message/{phash.d.ts → crypto/phash.d.ts} +1 -1
- package/dist/types/message/{reporting-token.d.ts → crypto/reporting-token.d.ts} +2 -2
- package/dist/types/message/{use-case-secret.d.ts → crypto/use-case-secret.d.ts} +17 -1
- package/dist/types/message/encode/content.d.ts +43 -0
- package/dist/types/message/{device-sent.d.ts → encode/device-sent.d.ts} +1 -1
- package/dist/types/message/encode/media-payload.d.ts +12 -0
- package/dist/types/message/index.d.ts +2 -2
- package/dist/types/message/kinds/bot.d.ts +31 -0
- package/dist/types/message/kinds/newsletter.d.ts +12 -0
- package/dist/types/message/kinds/sticker-pack.d.ts +6 -0
- package/dist/types/message/{ack.d.ts → primitives/ack.d.ts} +1 -1
- package/dist/types/message/primitives/incoming.d.ts +21 -0
- package/dist/types/message/primitives/peer-data-operation.d.ts +23 -0
- package/dist/types/message/types.d.ts +208 -10
- package/dist/types/mex.d.ts +2 -0
- package/dist/types/proto.d.ts +2 -2
- package/dist/types/protocol/abprops.d.ts +9 -0
- package/dist/types/protocol/appstate.d.ts +4 -49
- package/dist/types/protocol/auth.d.ts +2 -2
- package/dist/types/protocol/bot.d.ts +45 -0
- package/dist/types/protocol/browser.d.ts +8 -0
- package/dist/types/protocol/business.d.ts +21 -0
- package/dist/types/protocol/call.d.ts +44 -0
- package/dist/types/protocol/constants.d.ts +16 -3
- package/dist/types/protocol/defaults.d.ts +3 -0
- package/dist/types/protocol/group.d.ts +1 -1
- package/dist/types/protocol/index.d.ts +2 -1
- package/dist/types/protocol/jid.d.ts +78 -0
- package/dist/types/protocol/media.d.ts +21 -13
- package/dist/types/protocol/message.d.ts +4 -0
- package/dist/types/protocol/newsletter.d.ts +65 -0
- package/dist/types/protocol/nodes.d.ts +20 -0
- package/dist/types/protocol/notification.d.ts +16 -0
- package/dist/types/protocol/presence.d.ts +16 -0
- package/dist/types/protocol/status.d.ts +7 -0
- package/dist/types/retry/codec.d.ts +5 -0
- package/dist/types/retry/index.d.ts +1 -1
- package/dist/types/retry/parse.d.ts +9 -0
- package/dist/types/retry/reason.d.ts +5 -0
- package/dist/types/retry/replay.d.ts +19 -5
- package/dist/types/retry/tracker.d.ts +10 -3
- package/dist/types/retry/types.d.ts +3 -8
- package/dist/types/signal/api/SignalDeviceSyncApi.d.ts +20 -0
- package/dist/types/signal/api/SignalDigestSyncApi.d.ts +10 -0
- package/dist/types/signal/api/SignalIdentitySyncApi.d.ts +9 -0
- package/dist/types/signal/api/SignalMissingPreKeysSyncApi.d.ts +8 -0
- package/dist/types/signal/api/SignalRotateKeyApi.d.ts +10 -0
- package/dist/types/signal/api/SignalSessionSyncApi.d.ts +13 -0
- package/dist/types/signal/api/codec.d.ts +20 -0
- package/dist/types/signal/api/constants.d.ts +1 -1
- package/dist/types/signal/api/prekeys.d.ts +4 -0
- package/dist/types/signal/{crypto → attestation}/WaAdvSignature.d.ts +2 -2
- package/dist/types/signal/attestation/constants.d.ts +4 -0
- package/dist/types/signal/constants.d.ts +7 -4
- package/dist/types/signal/encoding.d.ts +6 -68
- package/dist/types/signal/group/SenderKeyChain.d.ts +1 -1
- package/dist/types/signal/group/SenderKeyManager.d.ts +17 -0
- package/dist/types/signal/group/encoding.d.ts +25 -0
- package/dist/types/signal/index.d.ts +4 -1
- package/dist/types/signal/registration/encoding.d.ts +30 -0
- package/dist/types/signal/registration/keygen.d.ts +10 -0
- package/dist/types/signal/registration/utils.d.ts +5 -0
- package/dist/types/signal/session/SignalProtocol.d.ts +55 -0
- package/dist/types/signal/session/SignalRatchet.d.ts +2 -3
- package/dist/types/signal/session/SignalSession.d.ts +0 -1
- package/dist/types/signal/session/encoding.d.ts +28 -0
- package/dist/types/signal/session/resolver.d.ts +14 -0
- package/dist/types/store/cache/identity.cache.d.ts +15 -0
- package/dist/types/store/cache/privacy-token.cache.d.ts +15 -0
- package/dist/types/store/cache/sender-key.cache.d.ts +18 -0
- package/dist/types/store/cache/session.cache.d.ts +23 -0
- package/dist/types/store/contracts/contact.store.d.ts +14 -0
- package/dist/types/store/contracts/device-list.store.d.ts +13 -0
- package/dist/types/store/contracts/group-metadata.store.d.ts +14 -0
- package/dist/types/store/contracts/message.store.d.ts +0 -2
- package/dist/types/store/createStore.d.ts +54 -2
- package/dist/types/store/index.d.ts +17 -16
- package/dist/types/store/locks/group-metadata.lock.d.ts +2 -0
- package/dist/types/store/{providers/memory → memory}/appstate.store.d.ts +2 -2
- package/dist/types/store/memory/auth.store.d.ts +18 -0
- package/dist/types/store/{providers/memory → memory}/contact.store.d.ts +6 -1
- package/dist/types/store/{providers/memory → memory}/device-list.store.d.ts +15 -2
- package/dist/types/store/memory/group-metadata.store.d.ts +27 -0
- package/dist/types/store/{providers/memory → memory}/identity.store.d.ts +2 -2
- package/dist/types/store/{providers/memory → memory}/message-secret.store.d.ts +12 -2
- package/dist/types/store/{providers/memory → memory}/message.store.d.ts +1 -1
- package/dist/types/store/{providers/memory → memory}/pre-key.store.d.ts +2 -2
- package/dist/types/store/{providers/memory → memory}/privacy-token.store.d.ts +1 -1
- package/dist/types/store/{providers/memory → memory}/retry.store.d.ts +16 -3
- package/dist/types/store/{providers/memory → memory}/sender-key.store.d.ts +2 -2
- package/dist/types/store/{providers/memory → memory}/session.store.d.ts +2 -2
- package/dist/types/store/{providers/memory → memory}/signal.store.d.ts +2 -2
- package/dist/types/store/{providers/memory → memory}/thread.store.d.ts +1 -1
- package/dist/types/store/noop.store.d.ts +2 -2
- package/dist/types/store/types.d.ts +250 -6
- package/dist/types/transport/WaComms.d.ts +5 -0
- package/dist/types/transport/WaWebSocket.d.ts +5 -0
- package/dist/types/transport/binary/constants.d.ts +8 -2
- package/dist/types/transport/binary/decoder.d.ts +5 -0
- package/dist/types/transport/binary/encoder.d.ts +5 -0
- package/dist/types/transport/binary/tokens.d.ts +6 -6
- package/dist/types/transport/index.d.ts +3 -1
- package/dist/types/transport/keepalive/WaKeepAlive.d.ts +7 -0
- package/dist/types/transport/node/WaMobileTcpSocket.d.ts +6 -0
- package/dist/types/transport/node/WaNodeOrchestrator.d.ts +5 -0
- package/dist/types/transport/node/WaNodeTransport.d.ts +13 -0
- package/dist/types/transport/node/builders/account-sync.d.ts +1 -2
- package/dist/types/transport/node/builders/bot.d.ts +4 -0
- package/dist/types/transport/node/builders/business.d.ts +21 -4
- package/dist/types/transport/node/builders/chatstate.d.ts +11 -0
- package/dist/types/transport/node/builders/community.d.ts +17 -0
- package/dist/types/transport/node/builders/group.d.ts +44 -2
- package/dist/types/transport/node/builders/message.d.ts +11 -6
- package/dist/types/transport/node/builders/newsletter.d.ts +73 -0
- package/dist/types/transport/node/builders/passive.d.ts +3 -0
- package/dist/types/transport/node/builders/presence.d.ts +8 -1
- package/dist/types/transport/node/builders/profile.d.ts +3 -0
- package/dist/types/transport/node/builders/tos.d.ts +12 -0
- package/dist/types/transport/node/builders/usync.d.ts +16 -0
- package/dist/types/transport/node/helpers.d.ts +1 -2
- package/dist/types/transport/node/mex/client.d.ts +12 -1
- package/dist/types/transport/node/query.d.ts +19 -1
- package/dist/types/transport/node/usync.d.ts +3 -0
- package/dist/types/transport/noise/WaMobileClientPayload.d.ts +5 -0
- package/dist/types/transport/noise/WaNoiseCert.d.ts +5 -0
- package/dist/types/transport/noise/WaNoiseHandshake.d.ts +12 -6
- package/dist/types/transport/noise/WaNoiseSession.d.ts +0 -1
- package/dist/types/transport/noise/WaNoiseSocket.d.ts +12 -6
- package/dist/types/transport/noise/constants.d.ts +4 -5
- package/dist/types/transport/proxy.d.ts +5 -0
- package/dist/types/transport/types.d.ts +14 -7
- package/dist/types/transport/wa-web-version-fetcher.d.ts +44 -0
- package/dist/types/util/async.d.ts +4 -0
- package/dist/types/util/bytes.d.ts +36 -1
- package/dist/types/util/clock.d.ts +6 -0
- package/dist/types/util/coercion.d.ts +25 -0
- package/dist/types/util/collections.d.ts +8 -0
- package/dist/types/util/index.d.ts +2 -2
- package/dist/types/util/primitives.d.ts +11 -0
- package/dist/types/util/runtime.d.ts +5 -0
- package/dist/types/version-spec.d.ts +1 -0
- package/dist/util/async.js +4 -0
- package/dist/util/bytes.js +37 -2
- package/dist/util/clock.js +18 -0
- package/dist/util/coercion.js +48 -3
- package/dist/util/collections.js +12 -0
- package/dist/util/index.js +7 -1
- package/dist/util/primitives.js +20 -0
- package/dist/util/runtime.js +5 -0
- package/dist/version-spec.js +5 -0
- package/package.json +32 -8
- package/spec/appstate/index.d.ts +188 -0
- package/spec/appstate/index.js +850 -0
- package/spec/mex/index.d.ts +4172 -0
- package/spec/mex/index.js +261 -0
- package/spec/proto/index.d.ts +16305 -0
- package/spec/proto/index.js +1 -0
- package/spec/version/index.d.ts +4 -0
- package/spec/version/index.js +9 -0
- package/spec/version/version.json +3 -0
- package/dist/client/events/chat.js +0 -227
- package/dist/client/incoming.js +0 -306
- package/dist/client/mailbox.js +0 -66
- package/dist/client/messages.js +0 -305
- package/dist/esm/client/events/chat.js +0 -224
- package/dist/esm/client/incoming.js +0 -296
- package/dist/esm/client/mailbox.js +0 -63
- package/dist/esm/client/messages.js +0 -301
- package/dist/esm/media/WaMediaCrypto.js +0 -499
- package/dist/esm/message/phash.js +0 -47
- package/dist/esm/store/locks/participants.lock.js +0 -20
- package/dist/esm/store/providers/memory/contact.store.js +0 -28
- package/dist/esm/store/providers/memory/device-list.store.js +0 -67
- package/dist/esm/transport/node/mex/persist-ids.js +0 -10
- package/dist/media/WaMediaCrypto.js +0 -503
- package/dist/message/phash.js +0 -50
- package/dist/store/locks/participants.lock.js +0 -23
- package/dist/store/providers/memory/contact.store.js +0 -32
- package/dist/store/providers/memory/device-list.store.js +0 -71
- package/dist/transport/node/mex/persist-ids.js +0 -13
- package/dist/types/appstate/WaAppStateSyncClient.d.ts +0 -70
- package/dist/types/client/events/chat.d.ts +0 -3
- package/dist/types/client/history-sync.d.ts +0 -20
- package/dist/types/client/messages.d.ts +0 -18
- package/dist/types/client/messaging/participants.d.ts +0 -13
- package/dist/types/media/WaMediaCrypto.d.ts +0 -22
- package/dist/types/media/conn.d.ts +0 -3
- package/dist/types/message/content.d.ts +0 -14
- package/dist/types/message/incoming.d.ts +0 -18
- package/dist/types/signal/crypto/constants.d.ts +0 -4
- package/dist/types/store/contracts/participants.store.d.ts +0 -13
- package/dist/types/store/locks/participants.lock.d.ts +0 -2
- package/dist/types/store/providers/memory/participants.store.d.ts +0 -17
- package/dist/types/transport/node/mex/persist-ids.d.ts +0 -14
- package/proto/index.d.ts +0 -10903
- package/proto/index.js +0 -1
- /package/dist/{store/contracts/participants.store.js → client/newsletter/types.js} +0 -0
- /package/dist/esm/{store/contracts/participants.store.js → client/newsletter/types.js} +0 -0
- /package/dist/esm/message/{device-sent.js → encode/device-sent.js} +0 -0
- /package/dist/esm/signal/{crypto → attestation}/constants.js +0 -0
- /package/dist/esm/store/{providers/memory → memory}/signal.store.js +0 -0
- /package/dist/message/{device-sent.js → encode/device-sent.js} +0 -0
- /package/dist/signal/{crypto → attestation}/constants.js +0 -0
- /package/dist/store/{providers/memory → memory}/signal.store.js +0 -0
- /package/dist/types/message/{padding.d.ts → encode/padding.d.ts} +0 -0
|
@@ -5,12 +5,14 @@ const _crypto_1 = require("../../crypto/index.js");
|
|
|
5
5
|
const primitives_1 = require("../../crypto/core/primitives");
|
|
6
6
|
const PromiseDedup_1 = require("../../infra/perf/PromiseDedup");
|
|
7
7
|
const _message_1 = require("../../message/index.js");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
8
|
+
const context_info_1 = require("../../message/context-info");
|
|
9
|
+
const icdc_1 = require("../../message/crypto/icdc");
|
|
10
|
+
const phash_1 = require("../../message/crypto/phash");
|
|
11
|
+
const reporting_token_1 = require("../../message/crypto/reporting-token");
|
|
12
|
+
const content_1 = require("../../message/encode/content");
|
|
13
|
+
const device_sent_1 = require("../../message/encode/device-sent");
|
|
14
|
+
const padding_1 = require("../../message/encode/padding");
|
|
15
|
+
const bot_1 = require("../../message/kinds/bot");
|
|
14
16
|
const _proto_1 = require("../../proto.js");
|
|
15
17
|
const constants_1 = require("../../protocol/constants");
|
|
16
18
|
const jid_1 = require("../../protocol/jid");
|
|
@@ -23,51 +25,28 @@ class WaMessageDispatchCoordinator {
|
|
|
23
25
|
this.icdcDedup = new PromiseDedup_1.PromiseDedup();
|
|
24
26
|
this.privacyTokenDedup = new PromiseDedup_1.PromiseDedup();
|
|
25
27
|
this.distributionDedup = new PromiseDedup_1.PromiseDedup();
|
|
26
|
-
this.
|
|
27
|
-
this.messageClient = options.messageClient;
|
|
28
|
-
this.retryTracker = options.retryTracker;
|
|
29
|
-
this.sessionResolver = options.sessionResolver;
|
|
30
|
-
this.fanoutResolver = options.fanoutResolver;
|
|
31
|
-
this.participantsCache = options.participantsCache;
|
|
32
|
-
this.appStateSyncKeyProtocol = options.appStateSyncKeyProtocol;
|
|
33
|
-
this.buildMessageContent = options.buildMessageContent;
|
|
34
|
-
this.senderKeyManager = options.senderKeyManager;
|
|
35
|
-
this.signalProtocol = options.signalProtocol;
|
|
36
|
-
this.signalStore = options.signalStore;
|
|
37
|
-
this.sessionStore = options.sessionStore;
|
|
38
|
-
this.identityStore = options.identityStore;
|
|
39
|
-
this.deviceListStore = options.deviceListStore;
|
|
40
|
-
this.messageSecretStore = options.messageSecretStore;
|
|
41
|
-
this.getCurrentMeJid = options.getCurrentMeJid;
|
|
42
|
-
this.getCurrentMeLid = options.getCurrentMeLid;
|
|
43
|
-
this.getCurrentSignedIdentity = options.getCurrentSignedIdentity;
|
|
44
|
-
this.resolvePrivacyTokenNode = options.resolvePrivacyTokenNode;
|
|
45
|
-
this.onDirectMessageSent = options.onDirectMessageSent;
|
|
46
|
-
this.getIcdcHashLength = options.getIcdcHashLength;
|
|
28
|
+
this.deps = options;
|
|
47
29
|
this.mobileMessageIdFormat = options.mobileMessageIdFormat ?? false;
|
|
30
|
+
this.serverClock = options.serverClock;
|
|
48
31
|
}
|
|
49
32
|
async publishMessageNode(node, options = {}) {
|
|
50
|
-
this.logger.
|
|
33
|
+
this.deps.logger.trace('wa client publish message node', {
|
|
51
34
|
tag: node.tag,
|
|
52
35
|
type: node.attrs.type,
|
|
53
36
|
to: node.attrs.to
|
|
54
37
|
});
|
|
55
|
-
const messageType = node.attrs.type ?? 'text';
|
|
56
38
|
const replayPayload = {
|
|
57
39
|
mode: 'opaque_node',
|
|
58
40
|
node: (0, binary_1.encodeBinaryNode)(node)
|
|
59
41
|
};
|
|
60
|
-
return this.retryTracker.track({
|
|
42
|
+
return this.deps.retryTracker.track({
|
|
61
43
|
messageIdHint: node.attrs.id,
|
|
62
44
|
toJid: node.attrs.to,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
participantJid: node.attrs.participant,
|
|
66
|
-
recipientJid: node.attrs.recipient
|
|
67
|
-
}, async () => this.messageClient.publishNode(node, options));
|
|
45
|
+
replayPayload
|
|
46
|
+
}, async () => this.deps.messageClient.publishNode(node, options));
|
|
68
47
|
}
|
|
69
48
|
async publishEncryptedMessage(input, options = {}) {
|
|
70
|
-
this.logger.
|
|
49
|
+
this.deps.logger.trace('wa client publish encrypted message', {
|
|
71
50
|
to: input.to,
|
|
72
51
|
type: input.type,
|
|
73
52
|
encType: input.encType
|
|
@@ -80,14 +59,12 @@ class WaMessageDispatchCoordinator {
|
|
|
80
59
|
ciphertext: input.ciphertext,
|
|
81
60
|
participant: input.participant
|
|
82
61
|
};
|
|
83
|
-
return this.retryTracker.track({
|
|
62
|
+
return this.deps.retryTracker.track({
|
|
84
63
|
messageIdHint: input.id,
|
|
85
64
|
toJid: input.to,
|
|
86
|
-
type: input.type ?? 'text',
|
|
87
65
|
replayPayload,
|
|
88
|
-
participantJid: input.participant,
|
|
89
66
|
eligibleRequesterDeviceJids: [input.to]
|
|
90
|
-
}, async () => this.messageClient.publishEncrypted(input, options));
|
|
67
|
+
}, async () => this.deps.messageClient.publishEncrypted(input, options));
|
|
91
68
|
}
|
|
92
69
|
async publishSignalMessage(input, options = {}) {
|
|
93
70
|
this.requireCurrentMeJid('publishSignalMessage');
|
|
@@ -95,30 +72,29 @@ class WaMessageDispatchCoordinator {
|
|
|
95
72
|
if (address.server === constants_1.WA_DEFAULTS.GROUP_SERVER) {
|
|
96
73
|
throw new Error('publishSignalMessage currently supports only direct chats; use sender-key flow for groups');
|
|
97
74
|
}
|
|
98
|
-
this.logger.
|
|
75
|
+
this.deps.logger.trace('wa client publish signal message', {
|
|
99
76
|
to: input.to,
|
|
100
77
|
type: input.type
|
|
101
78
|
});
|
|
102
79
|
const [paddedPlaintext] = await Promise.all([
|
|
103
80
|
(0, padding_1.writeRandomPadMax16)(input.plaintext),
|
|
104
|
-
this.sessionResolver.ensureSession(address, input.to, input.expectedIdentity)
|
|
81
|
+
this.deps.sessionResolver.ensureSession(address, input.to, input.expectedIdentity)
|
|
105
82
|
]);
|
|
106
|
-
const encrypted = await this.signalProtocol.encryptMessage(address, paddedPlaintext, input.expectedIdentity);
|
|
83
|
+
const encrypted = await this.deps.signalProtocol.encryptMessage(address, paddedPlaintext, input.expectedIdentity);
|
|
107
84
|
const messageType = input.type ?? 'text';
|
|
85
|
+
const deviceIdentity = encrypted.type === 'pkmsg' ? this.getEncodedSignedDeviceIdentity() : undefined;
|
|
108
86
|
const replayPayload = {
|
|
109
87
|
mode: 'plaintext',
|
|
110
88
|
to: input.to,
|
|
111
89
|
type: messageType,
|
|
112
90
|
plaintext: paddedPlaintext
|
|
113
91
|
};
|
|
114
|
-
return this.retryTracker.track({
|
|
92
|
+
return this.deps.retryTracker.track({
|
|
115
93
|
messageIdHint: input.id,
|
|
116
94
|
toJid: input.to,
|
|
117
|
-
type: messageType,
|
|
118
95
|
replayPayload,
|
|
119
|
-
participantJid: input.participant,
|
|
120
96
|
eligibleRequesterDeviceJids: [input.to]
|
|
121
|
-
}, async () => this.messageClient.publishEncrypted({
|
|
97
|
+
}, async () => this.deps.messageClient.publishEncrypted({
|
|
122
98
|
to: input.to,
|
|
123
99
|
encType: encrypted.type,
|
|
124
100
|
ciphertext: encrypted.ciphertext,
|
|
@@ -127,33 +103,130 @@ class WaMessageDispatchCoordinator {
|
|
|
127
103
|
category: input.category,
|
|
128
104
|
pushPriority: input.pushPriority,
|
|
129
105
|
participant: input.participant,
|
|
130
|
-
deviceFanout: input.deviceFanout
|
|
106
|
+
deviceFanout: input.deviceFanout,
|
|
107
|
+
deviceIdentity,
|
|
108
|
+
metaNode: input.metaNode
|
|
131
109
|
}, options));
|
|
132
110
|
}
|
|
133
111
|
async sendMessage(to, content, options = {}) {
|
|
134
112
|
const recipientJid = (0, jid_1.normalizeRecipientJid)(to);
|
|
135
|
-
|
|
136
|
-
this.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
113
|
+
if ((0, jid_1.isNewsletterJid)(recipientJid)) {
|
|
114
|
+
if (!this.deps.sendNewsletterMessage) {
|
|
115
|
+
throw new Error('newsletter sendMessage requires sendNewsletterMessage dependency');
|
|
116
|
+
}
|
|
117
|
+
const newsletterCtx = (0, context_info_1.resolveSendContextInfo)({
|
|
118
|
+
contentLevel: pickContentContextInfo(content),
|
|
119
|
+
optionsLevel: options.contextInfo,
|
|
120
|
+
quote: options.quote,
|
|
121
|
+
forward: options.forward,
|
|
122
|
+
mentions: options.mentions
|
|
123
|
+
});
|
|
124
|
+
assertNewsletterContextInfoCompatible(newsletterCtx);
|
|
125
|
+
const sendOptions = await this.withResolvedMessageId(options);
|
|
126
|
+
return this.deps.sendNewsletterMessage(recipientJid, content, sendOptions, newsletterCtx);
|
|
127
|
+
}
|
|
128
|
+
let built;
|
|
129
|
+
let sendOptions;
|
|
130
|
+
if ((0, content_1.isSendAddonCryptoMessage)(content)) {
|
|
131
|
+
sendOptions = await this.withResolvedMessageId(options);
|
|
132
|
+
const meJid = this.deps.getCurrentCredentials()?.meJid;
|
|
133
|
+
if (!meJid) {
|
|
134
|
+
throw new Error(`${content.type} sendMessage requires registered meJid`);
|
|
135
|
+
}
|
|
136
|
+
built = await this.deps.buildMessageContent(content, {
|
|
137
|
+
to: recipientJid,
|
|
138
|
+
outgoingStanzaId: sendOptions.id,
|
|
139
|
+
meJid: (0, jid_1.toUserJid)(meJid)
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
;
|
|
144
|
+
[built, sendOptions] = await Promise.all([
|
|
145
|
+
this.deps.buildMessageContent(content, { to: recipientJid }),
|
|
146
|
+
this.withResolvedMessageId(options)
|
|
147
|
+
]);
|
|
148
|
+
}
|
|
149
|
+
let optionsCtx = options.contextInfo;
|
|
150
|
+
if (options.expirationSeconds !== undefined) {
|
|
151
|
+
optionsCtx = { ...optionsCtx, expirationSeconds: options.expirationSeconds };
|
|
152
|
+
}
|
|
153
|
+
if ((0, jid_1.isGroupJid)(recipientJid) &&
|
|
154
|
+
optionsCtx?.expirationSeconds === undefined &&
|
|
155
|
+
!options.disableGroupEphemeralAutoInject) {
|
|
156
|
+
const cachedEphemeral = await this.deps.groupMetadataCache.resolveEphemeral(recipientJid);
|
|
157
|
+
if (cachedEphemeral !== null && cachedEphemeral > 0) {
|
|
158
|
+
optionsCtx = { ...optionsCtx, expirationSeconds: cachedEphemeral };
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const ctx = (0, context_info_1.resolveSendContextInfo)({
|
|
162
|
+
contentLevel: pickContentContextInfo(content),
|
|
163
|
+
optionsLevel: optionsCtx,
|
|
164
|
+
quote: options.quote,
|
|
165
|
+
forward: options.forward,
|
|
166
|
+
mentions: options.mentions,
|
|
167
|
+
meLid: this.deps.getCurrentCredentials()?.meLid
|
|
168
|
+
});
|
|
169
|
+
const withCtx = ctx ? (0, context_info_1.applyContextInfo)(built.message, ctx) : built.message;
|
|
170
|
+
const withViewOnce = options.viewOnce ? (0, content_1.wrapAsViewOnce)(withCtx) : withCtx;
|
|
171
|
+
const editKey = options.editKey;
|
|
172
|
+
let editId;
|
|
173
|
+
let editParticipant;
|
|
174
|
+
let editTimestamp;
|
|
175
|
+
if (editKey) {
|
|
176
|
+
if ('rawNode' in editKey) {
|
|
177
|
+
editId = editKey.key?.id ?? undefined;
|
|
178
|
+
editParticipant = editKey.key?.participant ?? undefined;
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
editId = editKey.id;
|
|
182
|
+
editParticipant = editKey.participant;
|
|
183
|
+
editTimestamp = 'timestampMs' in editKey ? editKey.timestampMs : undefined;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const message = editKey
|
|
187
|
+
? {
|
|
188
|
+
protocolMessage: {
|
|
189
|
+
type: _proto_1.proto.Message.ProtocolMessage.Type.MESSAGE_EDIT,
|
|
190
|
+
key: {
|
|
191
|
+
remoteJid: recipientJid,
|
|
192
|
+
fromMe: true,
|
|
193
|
+
id: editId,
|
|
194
|
+
...(editParticipant ? { participant: editParticipant } : {})
|
|
195
|
+
},
|
|
196
|
+
editedMessage: withViewOnce,
|
|
197
|
+
timestampMs: editTimestamp ?? this.serverClock.nowMs()
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
: withViewOnce;
|
|
201
|
+
const upload = built.upload;
|
|
202
|
+
const messageWithOverride = options.messageSecret
|
|
203
|
+
? {
|
|
204
|
+
...message,
|
|
205
|
+
messageContextInfo: {
|
|
206
|
+
...(message.messageContextInfo ?? {}),
|
|
207
|
+
messageSecret: (0, _message_1.assertMessageSecret)(options.messageSecret, 'options.messageSecret')
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
: message;
|
|
211
|
+
const messageWithSecret = await (0, _message_1.ensureMessageSecret)(messageWithOverride);
|
|
140
212
|
const rawSecret = messageWithSecret.messageContextInfo?.messageSecret;
|
|
141
213
|
if (rawSecret &&
|
|
142
214
|
rawSecret.length > 0 &&
|
|
143
215
|
sendOptions.id &&
|
|
144
216
|
(0, content_1.needsSecretPersistence)(messageWithSecret)) {
|
|
145
|
-
const meJid = this.
|
|
146
|
-
void this.messageSecretStore
|
|
217
|
+
const meJid = this.deps.getCurrentCredentials()?.meJid ?? '';
|
|
218
|
+
void this.deps.messageSecretStore
|
|
147
219
|
.set(sendOptions.id, { secret: rawSecret, senderJid: meJid })
|
|
148
220
|
.catch((error) => {
|
|
149
|
-
this.logger.warn('failed to persist outgoing message secret', {
|
|
221
|
+
this.deps.logger.warn('failed to persist outgoing message secret', {
|
|
150
222
|
id: sendOptions.id,
|
|
223
|
+
to: recipientJid,
|
|
151
224
|
message: (0, primitives_2.toError)(error).message
|
|
152
225
|
});
|
|
153
226
|
});
|
|
154
227
|
}
|
|
155
|
-
const meJid = this.
|
|
156
|
-
const regInfo = meJid ? await this.signalStore.getRegistrationInfo() : null;
|
|
228
|
+
const meJid = this.deps.getCurrentCredentials()?.meJid;
|
|
229
|
+
const regInfo = meJid ? await this.deps.signalStore.getRegistrationInfo() : null;
|
|
157
230
|
const localPubKey = regInfo?.identityKeyPair.pubKey;
|
|
158
231
|
const meParsed = meJid ? (0, jid_1.parseJidFull)(meJid) : undefined;
|
|
159
232
|
const meUserJid = meParsed?.userJid;
|
|
@@ -165,67 +238,343 @@ class WaMessageDispatchCoordinator {
|
|
|
165
238
|
]);
|
|
166
239
|
const messageWithIcdc = (0, icdc_1.injectDeviceListMetadata)(messageWithSecret, senderIcdc, recipientIcdc);
|
|
167
240
|
const plaintext = await (0, padding_1.writeRandomPadMax16)(_proto_1.proto.Message.encode(messageWithIcdc).finish());
|
|
168
|
-
const
|
|
169
|
-
const
|
|
170
|
-
|
|
241
|
+
const buttonAddonKind = (0, content_1.resolveButtonAddonKind)(messageWithIcdc);
|
|
242
|
+
const buttonAddonNode = buttonAddonKind ? (0, message_1.buildButtonAddonNode)(buttonAddonKind) : undefined;
|
|
243
|
+
// when a <biz> companion is attached the stanza must advertise type=text and
|
|
244
|
+
// omit enc.mediatype; sending type=media + mediatype=list/button alongside the
|
|
245
|
+
// companion is rejected by the server as SMAX_INVALID (479).
|
|
246
|
+
const type = buttonAddonKind ? 'text' : (0, content_1.resolveMessageTypeAttr)(messageWithIcdc);
|
|
247
|
+
const edit = (0, content_1.resolveEditAttr)(messageWithIcdc) ?? undefined;
|
|
248
|
+
const mediatype = buttonAddonKind
|
|
249
|
+
? undefined
|
|
250
|
+
: ((0, content_1.resolveEncMediaType)(messageWithIcdc) ?? undefined);
|
|
171
251
|
const metaAttrs = (0, content_1.resolveMetaAttrs)(messageWithIcdc);
|
|
172
252
|
const metaNode = metaAttrs ? (0, message_1.buildMetaNode)(metaAttrs) : undefined;
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
253
|
+
const customNodes = [];
|
|
254
|
+
if (metaNode)
|
|
255
|
+
customNodes.push(metaNode);
|
|
256
|
+
if (buttonAddonNode)
|
|
257
|
+
customNodes.push(buttonAddonNode);
|
|
258
|
+
if (options.customNodes) {
|
|
259
|
+
for (const node of options.customNodes) {
|
|
260
|
+
customNodes.push(node);
|
|
176
261
|
}
|
|
177
|
-
return this.publishGroupSenderKeyMessage(recipientJid, messageWithIcdc, plaintext, type, sendOptions, {}, edit, mediatype, metaNode);
|
|
178
262
|
}
|
|
179
|
-
const
|
|
180
|
-
|
|
263
|
+
const decryptFail = (0, content_1.resolveDecryptFailAttr)(messageWithIcdc);
|
|
264
|
+
const envelope = {
|
|
265
|
+
message: messageWithIcdc,
|
|
266
|
+
plaintext,
|
|
267
|
+
type,
|
|
268
|
+
edit,
|
|
269
|
+
mediatype,
|
|
270
|
+
decryptFail,
|
|
271
|
+
customNodes: customNodes.length > 0 ? customNodes : undefined,
|
|
272
|
+
sendOptions
|
|
273
|
+
};
|
|
274
|
+
const directRecipientJid = isGroup
|
|
275
|
+
? recipientJid
|
|
276
|
+
: await this.resolveDirectRecipientLid((0, jid_1.toUserJid)(recipientJid));
|
|
277
|
+
const publishResult = isGroup
|
|
278
|
+
? this.shouldUseGroupDirectPath(messageWithIcdc)
|
|
279
|
+
? await this.publishGroupDirectMessage(recipientJid, envelope)
|
|
280
|
+
: await this.publishGroupSenderKeyMessage(recipientJid, envelope)
|
|
281
|
+
: await this.publishDirectSignalMessageWithFanout(directRecipientJid, envelope);
|
|
282
|
+
return upload ? { ...publishResult, upload } : publishResult;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* For a 1:1 recipient passed in PN form, returns the LID-addressed user JID
|
|
286
|
+
* (cache-first; falls back to a one-shot `queryLidsByPhoneJids`). Switching
|
|
287
|
+
* to LID before fanout ensures the envelope, eligible-requester list, and
|
|
288
|
+
* retry-receipt addressing all agree, which keeps the retry tracker from
|
|
289
|
+
* rejecting receipts that arrive in LID form. Returns the original PN if
|
|
290
|
+
* no LID is known/resolvable. Inputs already in LID form pass through.
|
|
291
|
+
*/
|
|
292
|
+
async resolveDirectRecipientLid(pnUserJid) {
|
|
293
|
+
if ((0, jid_1.isLidJid)(pnUserJid))
|
|
294
|
+
return pnUserJid;
|
|
295
|
+
const cached = await this.deps.deviceListStore.findByAnyUserJid(pnUserJid);
|
|
296
|
+
if (cached) {
|
|
297
|
+
if ((0, jid_1.isLidJid)(cached.userJid))
|
|
298
|
+
return cached.userJid;
|
|
299
|
+
if (cached.altUserJid && (0, jid_1.isLidJid)(cached.altUserJid))
|
|
300
|
+
return cached.altUserJid;
|
|
301
|
+
}
|
|
302
|
+
try {
|
|
303
|
+
const results = await this.deps.signalDeviceSync.queryLidsByPhoneJids([pnUserJid]);
|
|
304
|
+
const match = results.find((entry) => entry.phoneJid === pnUserJid);
|
|
305
|
+
if (match?.lidJid)
|
|
306
|
+
return match.lidJid;
|
|
307
|
+
}
|
|
308
|
+
catch (error) {
|
|
309
|
+
this.deps.logger.debug('lid resolution failed for direct recipient', {
|
|
310
|
+
pnUserJid,
|
|
311
|
+
message: (0, primitives_2.toError)(error).message
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
return pnUserJid;
|
|
181
315
|
}
|
|
182
316
|
async syncSignalSession(jid, reasonIdentity = false) {
|
|
183
317
|
const address = (0, jid_1.parseSignalAddressFromJid)(jid);
|
|
184
318
|
if (address.server === constants_1.WA_DEFAULTS.GROUP_SERVER) {
|
|
185
319
|
throw new Error('syncSignalSession supports only direct chats');
|
|
186
320
|
}
|
|
187
|
-
await this.sessionResolver.ensureSession(address, jid, undefined, reasonIdentity);
|
|
321
|
+
await this.deps.sessionResolver.ensureSession(address, jid, undefined, reasonIdentity);
|
|
188
322
|
}
|
|
189
323
|
async sendReceipt(input) {
|
|
190
|
-
await this.messageClient.sendReceipt(input);
|
|
324
|
+
await this.deps.messageClient.sendReceipt(input);
|
|
325
|
+
}
|
|
326
|
+
async publishProtocolMessageToDevice(deviceJid, protocolMessage, options) {
|
|
327
|
+
const meJid = this.deps.getCurrentCredentials()?.meJid;
|
|
328
|
+
const meParsed = meJid ? (0, jid_1.parseJidFull)(meJid) : undefined;
|
|
329
|
+
const meUserJid = meParsed?.userJid;
|
|
330
|
+
let senderIcdc = null;
|
|
331
|
+
if (meUserJid) {
|
|
332
|
+
const regInfo = await this.deps.signalStore.getRegistrationInfo();
|
|
333
|
+
const localPubKey = regInfo?.identityKeyPair.pubKey;
|
|
334
|
+
const localIdentity = meParsed && localPubKey
|
|
335
|
+
? { address: meParsed.address, pubKey: localPubKey }
|
|
336
|
+
: undefined;
|
|
337
|
+
senderIcdc = await this.resolveUserIcdc(meUserJid, localIdentity);
|
|
338
|
+
}
|
|
339
|
+
const message = (0, icdc_1.injectDeviceListMetadata)({ protocolMessage }, senderIcdc, null);
|
|
340
|
+
return this.publishSignalMessage({
|
|
341
|
+
to: deviceJid,
|
|
342
|
+
plaintext: _proto_1.proto.Message.encode(message).finish(),
|
|
343
|
+
id: options?.id,
|
|
344
|
+
type: 'text',
|
|
345
|
+
category: 'peer',
|
|
346
|
+
pushPriority: options?.pushPriority ?? 'high',
|
|
347
|
+
metaNode: (0, message_1.buildMetaNode)({ appdata: 'default' })
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
async publishStatusMessage(input) {
|
|
351
|
+
if (input.recipients.length === 0) {
|
|
352
|
+
throw new Error('publishStatusMessage requires at least one recipient');
|
|
353
|
+
}
|
|
354
|
+
this.requireCurrentMeJid('publishStatusMessage');
|
|
355
|
+
const meLid = this.deps.getCurrentCredentials()?.meLid;
|
|
356
|
+
if (!meLid) {
|
|
357
|
+
throw new Error('publishStatusMessage requires current me lid');
|
|
358
|
+
}
|
|
359
|
+
const senderJid = (0, jid_1.normalizeDeviceJid)(meLid);
|
|
360
|
+
const meUserLid = (0, jid_1.toUserJid)(meLid);
|
|
361
|
+
const seen = new Set();
|
|
362
|
+
const recipientsWithSelf = [];
|
|
363
|
+
for (const jid of input.recipients) {
|
|
364
|
+
if (seen.has(jid))
|
|
365
|
+
continue;
|
|
366
|
+
seen.add(jid);
|
|
367
|
+
recipientsWithSelf.push(jid);
|
|
368
|
+
}
|
|
369
|
+
if (!seen.has(meUserLid)) {
|
|
370
|
+
recipientsWithSelf.push(meUserLid);
|
|
371
|
+
}
|
|
372
|
+
const statusSetting = input.statusSetting ?? 'contacts';
|
|
373
|
+
return this.publishSenderKeyFanout({
|
|
374
|
+
groupJid: constants_1.WA_DEFAULTS.STATUS_BROADCAST_JID,
|
|
375
|
+
senderJid,
|
|
376
|
+
recipients: recipientsWithSelf,
|
|
377
|
+
message: input.message,
|
|
378
|
+
options: input.options ?? {},
|
|
379
|
+
logTag: 'status',
|
|
380
|
+
replayStatusSetting: statusSetting,
|
|
381
|
+
// Bare `<to jid=user>` ack hints route the skmsg through primary
|
|
382
|
+
// devices that already hold the sender key.
|
|
383
|
+
customize: async ({ fanoutDeviceJids, distributionParticipants, messageWithSecret, sendOptions }) => {
|
|
384
|
+
const distributedAddressKeys = new Set();
|
|
385
|
+
for (let i = 0; i < distributionParticipants.length; i += 1) {
|
|
386
|
+
distributedAddressKeys.add((0, jid_1.signalAddressKey)(distributionParticipants[i].address));
|
|
387
|
+
}
|
|
388
|
+
const ackHints = [];
|
|
389
|
+
const seenAck = new Set();
|
|
390
|
+
for (let i = 0; i < fanoutDeviceJids.length; i += 1) {
|
|
391
|
+
const deviceJid = fanoutDeviceJids[i];
|
|
392
|
+
const address = (0, jid_1.parseSignalAddressFromJid)(deviceJid);
|
|
393
|
+
if (distributedAddressKeys.has((0, jid_1.signalAddressKey)(address)))
|
|
394
|
+
continue;
|
|
395
|
+
if (address.device !== 0)
|
|
396
|
+
continue;
|
|
397
|
+
const userJid = (0, jid_1.toUserJid)(deviceJid);
|
|
398
|
+
if (seenAck.has(userJid))
|
|
399
|
+
continue;
|
|
400
|
+
seenAck.add(userJid);
|
|
401
|
+
ackHints.push({ jid: userJid });
|
|
402
|
+
}
|
|
403
|
+
const reportingArtifacts = await this.tryBuildReportingTokenArtifacts({
|
|
404
|
+
message: messageWithSecret,
|
|
405
|
+
stanzaId: sendOptions.id,
|
|
406
|
+
senderUserJid: (0, jid_1.toUserJid)(senderJid),
|
|
407
|
+
remoteJid: constants_1.WA_DEFAULTS.STATUS_BROADCAST_JID,
|
|
408
|
+
context: 'status'
|
|
409
|
+
});
|
|
410
|
+
const customNodes = [(0, message_1.buildMetaNode)({ status_setting: statusSetting })];
|
|
411
|
+
if (reportingArtifacts?.node)
|
|
412
|
+
customNodes.push(reportingArtifacts.node);
|
|
413
|
+
return {
|
|
414
|
+
extraParticipants: ackHints,
|
|
415
|
+
customNodes
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
async publishBroadcastListMessage(input) {
|
|
421
|
+
if (input.recipients.length === 0) {
|
|
422
|
+
throw new Error('publishBroadcastListMessage requires at least one recipient');
|
|
423
|
+
}
|
|
424
|
+
const meJid = this.requireCurrentMeJid('publishBroadcastListMessage');
|
|
425
|
+
const senderJid = (0, jid_1.normalizeDeviceJid)(meJid);
|
|
426
|
+
return this.publishSenderKeyFanout({
|
|
427
|
+
groupJid: input.listJid,
|
|
428
|
+
senderJid,
|
|
429
|
+
recipients: input.recipients,
|
|
430
|
+
message: input.message,
|
|
431
|
+
options: input.options ?? {},
|
|
432
|
+
logTag: 'broadcast list',
|
|
433
|
+
customize: ({ fanoutDeviceJids }) => {
|
|
434
|
+
const phashTargets = new Array(fanoutDeviceJids.length + 1);
|
|
435
|
+
let phashTargetCount = 0;
|
|
436
|
+
for (let i = 0; i < fanoutDeviceJids.length; i += 1) {
|
|
437
|
+
const candidate = fanoutDeviceJids[i];
|
|
438
|
+
if ((0, jid_1.isHostedDeviceJid)(candidate))
|
|
439
|
+
continue;
|
|
440
|
+
phashTargets[phashTargetCount] = candidate;
|
|
441
|
+
phashTargetCount += 1;
|
|
442
|
+
}
|
|
443
|
+
phashTargets[phashTargetCount] = senderJid;
|
|
444
|
+
phashTargets.length = phashTargetCount + 1;
|
|
445
|
+
return Promise.resolve({ phash: (0, phash_1.computePhashV2)(phashTargets) });
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
async publishSenderKeyFanout(input) {
|
|
450
|
+
const sendOptions = await this.withResolvedMessageId(input.options);
|
|
451
|
+
const sender = (0, jid_1.parseSignalAddressFromJid)(input.senderJid);
|
|
452
|
+
const messageWithSecret = await (0, _message_1.ensureMessageSecret)(input.message);
|
|
453
|
+
const plaintext = await (0, padding_1.writeRandomPadMax16)(_proto_1.proto.Message.encode(messageWithSecret).finish());
|
|
454
|
+
const { distributionMessage, ciphertext: groupCiphertext, keyId: senderKeyId } = await this.deps.senderKeyManager.prepareGroupEncryption(input.groupJid, sender, plaintext);
|
|
455
|
+
const { fanoutDeviceJids, distributionParticipants } = await this.encryptGroupDistributionParticipants(input.groupJid, senderKeyId, distributionMessage, input.recipients);
|
|
456
|
+
let shouldAttachDeviceIdentity = false;
|
|
457
|
+
for (let i = 0; i < distributionParticipants.length; i += 1) {
|
|
458
|
+
if (distributionParticipants[i].encType === 'pkmsg') {
|
|
459
|
+
shouldAttachDeviceIdentity = true;
|
|
460
|
+
break;
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
const extras = input.customize
|
|
464
|
+
? await input.customize({
|
|
465
|
+
fanoutDeviceJids,
|
|
466
|
+
distributionParticipants,
|
|
467
|
+
messageWithSecret,
|
|
468
|
+
sendOptions
|
|
469
|
+
})
|
|
470
|
+
: {};
|
|
471
|
+
const participants = distributionParticipants.map((p) => ({
|
|
472
|
+
jid: p.jid,
|
|
473
|
+
encType: p.encType,
|
|
474
|
+
ciphertext: p.ciphertext
|
|
475
|
+
}));
|
|
476
|
+
if (extras.extraParticipants) {
|
|
477
|
+
for (const entry of extras.extraParticipants) {
|
|
478
|
+
participants.push(entry);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
const messageNode = (0, message_1.buildGroupSenderKeyMessageNode)({
|
|
482
|
+
to: input.groupJid,
|
|
483
|
+
type: (0, content_1.resolveMessageTypeAttr)(messageWithSecret),
|
|
484
|
+
id: sendOptions.id,
|
|
485
|
+
phash: extras.phash,
|
|
486
|
+
edit: (0, content_1.resolveEditAttr)(messageWithSecret) ?? undefined,
|
|
487
|
+
mediatype: (0, content_1.resolveEncMediaType)(messageWithSecret) ?? undefined,
|
|
488
|
+
decryptFail: (0, content_1.resolveDecryptFailAttr)(messageWithSecret),
|
|
489
|
+
groupCiphertext: groupCiphertext.ciphertext,
|
|
490
|
+
participants,
|
|
491
|
+
deviceIdentity: shouldAttachDeviceIdentity
|
|
492
|
+
? this.getEncodedSignedDeviceIdentity()
|
|
493
|
+
: undefined,
|
|
494
|
+
customNodes: extras.customNodes,
|
|
495
|
+
additionalAttributes: sendOptions.additionalAttributes
|
|
496
|
+
});
|
|
497
|
+
const replayPayload = {
|
|
498
|
+
mode: 'plaintext',
|
|
499
|
+
to: input.groupJid,
|
|
500
|
+
type: messageNode.attrs.type,
|
|
501
|
+
plaintext,
|
|
502
|
+
...(input.replayStatusSetting ? { statusSetting: input.replayStatusSetting } : {})
|
|
503
|
+
};
|
|
504
|
+
const result = await this.deps.retryTracker.track({
|
|
505
|
+
messageIdHint: messageNode.attrs.id ?? sendOptions.id,
|
|
506
|
+
toJid: input.groupJid,
|
|
507
|
+
replayPayload,
|
|
508
|
+
eligibleRequesterDeviceJids: undefined
|
|
509
|
+
}, async () => this.deps.messageClient.publishNode(messageNode, sendOptions));
|
|
510
|
+
const distributedAddresses = new Array(distributionParticipants.length);
|
|
511
|
+
for (let i = 0; i < distributionParticipants.length; i += 1) {
|
|
512
|
+
distributedAddresses[i] = distributionParticipants[i].address;
|
|
513
|
+
}
|
|
514
|
+
try {
|
|
515
|
+
await this.deps.senderKeyManager.markSenderKeyDistributed(input.groupJid, senderKeyId, distributedAddresses);
|
|
516
|
+
}
|
|
517
|
+
catch (error) {
|
|
518
|
+
this.deps.logger.warn('failed to mark sender key distribution targets', {
|
|
519
|
+
logTag: input.logTag,
|
|
520
|
+
groupJid: input.groupJid,
|
|
521
|
+
participants: distributedAddresses.length,
|
|
522
|
+
message: (0, primitives_2.toError)(error).message
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
return result;
|
|
191
526
|
}
|
|
192
527
|
async requestAppStateSyncKeys(keyIds) {
|
|
193
|
-
return this.appStateSyncKeyProtocol.requestKeys(keyIds);
|
|
528
|
+
return this.deps.appStateSyncKeyProtocol.requestKeys(keyIds);
|
|
194
529
|
}
|
|
195
530
|
async sendAppStateSyncKeyShare(toDeviceJid, keys, missingKeyIds = []) {
|
|
196
|
-
await this.appStateSyncKeyProtocol.sendKeyShare(toDeviceJid, keys, missingKeyIds);
|
|
531
|
+
await this.deps.appStateSyncKeyProtocol.sendKeyShare(toDeviceJid, keys, missingKeyIds);
|
|
197
532
|
}
|
|
198
|
-
async
|
|
199
|
-
await this.
|
|
533
|
+
async mutateGroupMetadataCacheFromGroupEvent(event) {
|
|
534
|
+
await this.deps.groupMetadataCache.mutateFromGroupEvent(event);
|
|
200
535
|
}
|
|
536
|
+
// noop for now
|
|
201
537
|
shouldUseGroupDirectPath(message) {
|
|
202
|
-
|
|
203
|
-
if (protocolType === _proto_1.proto.Message.ProtocolMessage.Type.REVOKE ||
|
|
204
|
-
protocolType === _proto_1.proto.Message.ProtocolMessage.Type.MESSAGE_EDIT) {
|
|
205
|
-
return true;
|
|
206
|
-
}
|
|
207
|
-
return message.keepInChatMessage?.keepType === _proto_1.proto.KeepType.UNDO_KEEP_FOR_ALL;
|
|
538
|
+
return false;
|
|
208
539
|
}
|
|
209
|
-
async publishGroupDirectMessage(groupJid,
|
|
210
|
-
const sendOptions =
|
|
540
|
+
async publishGroupDirectMessage(groupJid, envelope, retryContext = {}) {
|
|
541
|
+
const { message, plaintext, type, edit, mediatype, sendOptions } = envelope;
|
|
211
542
|
const meJid = this.requireCurrentMeJid('sendMessage');
|
|
212
543
|
const participantUserJids = retryContext.forceRefreshParticipants
|
|
213
|
-
? await this.
|
|
214
|
-
: await this.
|
|
544
|
+
? await this.deps.groupMetadataCache.refreshParticipantUsers(groupJid)
|
|
545
|
+
: await this.deps.groupMetadataCache.resolveParticipantUsers(groupJid);
|
|
215
546
|
const addressingMode = retryContext.forceAddressingMode ??
|
|
216
547
|
this.resolveGroupAddressingMode(participantUserJids, groupJid);
|
|
217
548
|
const senderForPhash = this.resolveSenderForAddressingMode(addressingMode, meJid);
|
|
218
|
-
const fanoutDeviceJids = await this.fanoutResolver.resolveGroupParticipantDeviceJids(participantUserJids);
|
|
549
|
+
const fanoutDeviceJids = await this.deps.fanoutResolver.resolveGroupParticipantDeviceJids(participantUserJids);
|
|
219
550
|
if (fanoutDeviceJids.length === 0) {
|
|
220
551
|
throw new Error('group direct send resolved no target devices');
|
|
221
552
|
}
|
|
222
|
-
const resolvedFanoutTargets = await this.sessionResolver.ensureSessionsBatch(fanoutDeviceJids);
|
|
553
|
+
const resolvedFanoutTargets = await this.deps.sessionResolver.ensureSessionsBatch(fanoutDeviceJids);
|
|
554
|
+
const resolvedNormalizedJids = new Set();
|
|
555
|
+
for (let index = 0; index < resolvedFanoutTargets.length; index += 1) {
|
|
556
|
+
resolvedNormalizedJids.add(resolvedFanoutTargets[index].jid);
|
|
557
|
+
}
|
|
223
558
|
const uniqueNormalizedFanoutJids = new Set();
|
|
224
559
|
for (let index = 0; index < fanoutDeviceJids.length; index += 1) {
|
|
225
560
|
uniqueNormalizedFanoutJids.add((0, jid_1.normalizeDeviceJid)(fanoutDeviceJids[index]));
|
|
226
561
|
}
|
|
227
|
-
|
|
228
|
-
|
|
562
|
+
const droppedDevices = [];
|
|
563
|
+
for (const expected of uniqueNormalizedFanoutJids) {
|
|
564
|
+
if (!resolvedNormalizedJids.has(expected)) {
|
|
565
|
+
droppedDevices.push(expected);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
if (droppedDevices.length > 0) {
|
|
569
|
+
this.deps.logger.warn('group direct fanout dropping devices without signal session', {
|
|
570
|
+
groupJid,
|
|
571
|
+
droppedCount: droppedDevices.length,
|
|
572
|
+
totalExpected: uniqueNormalizedFanoutJids.size,
|
|
573
|
+
sample: droppedDevices.slice(0, 3)
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
if (resolvedFanoutTargets.length === 0) {
|
|
577
|
+
throw new Error('group direct send resolved no signal sessions');
|
|
229
578
|
}
|
|
230
579
|
const participantEncryptRequests = new Array(resolvedFanoutTargets.length);
|
|
231
580
|
for (let index = 0; index < resolvedFanoutTargets.length; index += 1) {
|
|
@@ -235,7 +584,7 @@ class WaMessageDispatchCoordinator {
|
|
|
235
584
|
plaintext
|
|
236
585
|
};
|
|
237
586
|
}
|
|
238
|
-
const encryptedParticipants = await this.signalProtocol.encryptMessagesBatch(participantEncryptRequests, resolvedFanoutTargets);
|
|
587
|
+
const encryptedParticipants = await this.deps.signalProtocol.encryptMessagesBatch(participantEncryptRequests, resolvedFanoutTargets);
|
|
239
588
|
const participants = new Array(resolvedFanoutTargets.length);
|
|
240
589
|
for (let index = 0; index < resolvedFanoutTargets.length; index += 1) {
|
|
241
590
|
const target = resolvedFanoutTargets[index];
|
|
@@ -253,20 +602,27 @@ class WaMessageDispatchCoordinator {
|
|
|
253
602
|
}
|
|
254
603
|
}
|
|
255
604
|
const phashTargets = new Array(resolvedFanoutTargets.length + 1);
|
|
605
|
+
let phashTargetCount = 0;
|
|
256
606
|
for (let index = 0; index < resolvedFanoutTargets.length; index += 1) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
607
|
+
const candidate = resolvedFanoutTargets[index].jid;
|
|
608
|
+
if ((0, jid_1.isHostedDeviceJid)(candidate))
|
|
609
|
+
continue;
|
|
610
|
+
phashTargets[phashTargetCount] = candidate;
|
|
611
|
+
phashTargetCount += 1;
|
|
612
|
+
}
|
|
613
|
+
phashTargets[phashTargetCount] = senderForPhash;
|
|
614
|
+
phashTargets.length = phashTargetCount + 1;
|
|
615
|
+
const localPhash = (0, phash_1.computePhashV2)(phashTargets);
|
|
616
|
+
const reportingArtifacts = await this.tryBuildReportingTokenArtifacts({
|
|
617
|
+
message,
|
|
618
|
+
stanzaId: sendOptions.id,
|
|
619
|
+
senderUserJid: (0, jid_1.toUserJid)(senderForPhash),
|
|
620
|
+
remoteJid: groupJid,
|
|
621
|
+
context: 'group_direct'
|
|
622
|
+
});
|
|
623
|
+
const customNodes = envelope.customNodes ? [...envelope.customNodes] : [];
|
|
624
|
+
if (reportingArtifacts?.node)
|
|
625
|
+
customNodes.push(reportingArtifacts.node);
|
|
270
626
|
const messageNode = (0, message_1.buildDirectMessageFanoutNode)({
|
|
271
627
|
to: groupJid,
|
|
272
628
|
type,
|
|
@@ -278,9 +634,10 @@ class WaMessageDispatchCoordinator {
|
|
|
278
634
|
deviceIdentity: shouldAttachDeviceIdentity
|
|
279
635
|
? this.getEncodedSignedDeviceIdentity()
|
|
280
636
|
: undefined,
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
637
|
+
customNodes: customNodes.length > 0 ? customNodes : undefined,
|
|
638
|
+
mediatype,
|
|
639
|
+
decryptFail: envelope.decryptFail,
|
|
640
|
+
additionalAttributes: sendOptions.additionalAttributes
|
|
284
641
|
});
|
|
285
642
|
const replayPayload = {
|
|
286
643
|
mode: 'plaintext',
|
|
@@ -288,13 +645,12 @@ class WaMessageDispatchCoordinator {
|
|
|
288
645
|
type,
|
|
289
646
|
plaintext
|
|
290
647
|
};
|
|
291
|
-
const result = await this.retryTracker.track({
|
|
292
|
-
messageIdHint:
|
|
648
|
+
const result = await this.deps.retryTracker.track({
|
|
649
|
+
messageIdHint: messageNode.attrs.id ?? sendOptions.id,
|
|
293
650
|
toJid: groupJid,
|
|
294
|
-
type,
|
|
295
651
|
replayPayload,
|
|
296
652
|
eligibleRequesterDeviceJids: undefined
|
|
297
|
-
}, async () => this.messageClient.publishNode(messageNode, sendOptions));
|
|
653
|
+
}, async () => this.deps.messageClient.publishNode(messageNode, sendOptions));
|
|
298
654
|
const ackError = result.ack.error;
|
|
299
655
|
const serverPhash = result.ack.phash;
|
|
300
656
|
const serverAddressingMode = result.ack.addressingMode;
|
|
@@ -303,7 +659,7 @@ class WaMessageDispatchCoordinator {
|
|
|
303
659
|
const hasAddressingError = ackError === 421;
|
|
304
660
|
if (!retryContext.retried &&
|
|
305
661
|
(hasPhashMismatch || hasAddressingMismatch || hasAddressingError)) {
|
|
306
|
-
this.logger.warn('group direct publish acknowledged with mismatch metadata', {
|
|
662
|
+
this.deps.logger.warn('group direct publish acknowledged with mismatch metadata', {
|
|
307
663
|
id: result.id,
|
|
308
664
|
groupJid,
|
|
309
665
|
localPhash,
|
|
@@ -312,28 +668,88 @@ class WaMessageDispatchCoordinator {
|
|
|
312
668
|
serverAddressingMode,
|
|
313
669
|
ackError
|
|
314
670
|
});
|
|
315
|
-
return this.publishGroupDirectMessage(groupJid,
|
|
316
|
-
...
|
|
317
|
-
id: result.id
|
|
671
|
+
return this.publishGroupDirectMessage(groupJid, {
|
|
672
|
+
...envelope,
|
|
673
|
+
sendOptions: { ...sendOptions, id: result.id }
|
|
318
674
|
}, {
|
|
319
675
|
retried: true,
|
|
320
676
|
forceRefreshParticipants: true,
|
|
321
677
|
forceAddressingMode: serverAddressingMode
|
|
322
|
-
}
|
|
678
|
+
});
|
|
323
679
|
}
|
|
324
680
|
return result;
|
|
325
681
|
}
|
|
326
|
-
|
|
327
|
-
|
|
682
|
+
// Returns null on any failure so the group send still goes out unchanged.
|
|
683
|
+
async buildBotSidecarParticipant(message) {
|
|
684
|
+
const botJid = (0, bot_1.extractInvokedBotJid)(message);
|
|
685
|
+
if (!botJid)
|
|
686
|
+
return null;
|
|
687
|
+
let address;
|
|
688
|
+
try {
|
|
689
|
+
address = (0, jid_1.parseSignalAddressFromJid)(botJid);
|
|
690
|
+
}
|
|
691
|
+
catch (error) {
|
|
692
|
+
this.deps.logger.debug('bot sidecar: failed to parse bot jid', {
|
|
693
|
+
botJid,
|
|
694
|
+
message: (0, primitives_2.toError)(error).message
|
|
695
|
+
});
|
|
696
|
+
return null;
|
|
697
|
+
}
|
|
698
|
+
let resolvedTargets;
|
|
699
|
+
try {
|
|
700
|
+
resolvedTargets = await this.deps.sessionResolver.ensureSessionsBatch([botJid]);
|
|
701
|
+
}
|
|
702
|
+
catch (error) {
|
|
703
|
+
this.deps.logger.debug('bot sidecar: signal session sync failed', {
|
|
704
|
+
botJid,
|
|
705
|
+
message: (0, primitives_2.toError)(error).message
|
|
706
|
+
});
|
|
707
|
+
return null;
|
|
708
|
+
}
|
|
709
|
+
if (resolvedTargets.length === 0) {
|
|
710
|
+
this.deps.logger.debug('bot sidecar: signal session not established', { botJid });
|
|
711
|
+
return null;
|
|
712
|
+
}
|
|
713
|
+
// The bot seeds its streaming-response keys from this HKDF derivation.
|
|
714
|
+
const parentMessageSecret = message.messageContextInfo?.messageSecret;
|
|
715
|
+
const botMessageSecret = parentMessageSecret && parentMessageSecret.byteLength > 0
|
|
716
|
+
? (0, bot_1.genBotMsgSecret)(parentMessageSecret)
|
|
717
|
+
: undefined;
|
|
718
|
+
const botCopy = (0, bot_1.buildBotInvokeProtoCopy)(message, botMessageSecret);
|
|
719
|
+
const botPlaintext = await (0, padding_1.writeRandomPadMax16)(_proto_1.proto.Message.encode(botCopy).finish());
|
|
720
|
+
try {
|
|
721
|
+
const [encrypted] = await this.deps.signalProtocol.encryptMessagesBatch([{ address, plaintext: botPlaintext }], resolvedTargets.map((target) => ({
|
|
722
|
+
address: target.address,
|
|
723
|
+
session: target.session
|
|
724
|
+
})));
|
|
725
|
+
if (!encrypted)
|
|
726
|
+
return null;
|
|
727
|
+
this.deps.logger.trace('bot sidecar encrypted', { botJid, encType: encrypted.type });
|
|
728
|
+
return {
|
|
729
|
+
jid: botJid,
|
|
730
|
+
encType: encrypted.type,
|
|
731
|
+
ciphertext: encrypted.ciphertext
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
catch (error) {
|
|
735
|
+
this.deps.logger.debug('bot sidecar: encryption failed', {
|
|
736
|
+
botJid,
|
|
737
|
+
message: (0, primitives_2.toError)(error).message
|
|
738
|
+
});
|
|
739
|
+
return null;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
async publishGroupSenderKeyMessage(groupJid, envelope, retryContext = {}) {
|
|
743
|
+
const { message, plaintext, type, edit, mediatype, sendOptions } = envelope;
|
|
328
744
|
const meJid = this.requireCurrentMeJid('sendMessage');
|
|
329
745
|
const participantUserJids = retryContext.forceRefreshParticipants
|
|
330
|
-
? await this.
|
|
331
|
-
: await this.
|
|
746
|
+
? await this.deps.groupMetadataCache.refreshParticipantUsers(groupJid)
|
|
747
|
+
: await this.deps.groupMetadataCache.resolveParticipantUsers(groupJid);
|
|
332
748
|
const addressingMode = retryContext.forceAddressingMode ??
|
|
333
749
|
this.resolveGroupAddressingMode(participantUserJids, groupJid);
|
|
334
750
|
const senderJid = this.resolveSenderForAddressingMode(addressingMode, meJid);
|
|
335
751
|
const sender = (0, jid_1.parseSignalAddressFromJid)(senderJid);
|
|
336
|
-
const { distributionMessage: senderKeyDistributionMessage, ciphertext: groupCiphertext, keyId: senderKeyId } = await this.senderKeyManager.prepareGroupEncryption(groupJid, sender, plaintext);
|
|
752
|
+
const { distributionMessage: senderKeyDistributionMessage, ciphertext: groupCiphertext, keyId: senderKeyId } = await this.deps.senderKeyManager.prepareGroupEncryption(groupJid, sender, plaintext);
|
|
337
753
|
const distributionData = await this.distributionDedup.run(`dist:${groupJid}:${senderKeyId}`, () => this.encryptGroupDistributionParticipants(groupJid, senderKeyId, senderKeyDistributionMessage, participantUserJids));
|
|
338
754
|
const { fanoutDeviceJids, distributionParticipants } = distributionData;
|
|
339
755
|
let shouldAttachDeviceIdentity = false;
|
|
@@ -344,20 +760,28 @@ class WaMessageDispatchCoordinator {
|
|
|
344
760
|
}
|
|
345
761
|
}
|
|
346
762
|
const phashTargets = new Array(fanoutDeviceJids.length + 1);
|
|
763
|
+
let phashTargetCount = 0;
|
|
347
764
|
for (let index = 0; index < fanoutDeviceJids.length; index += 1) {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
765
|
+
const candidate = fanoutDeviceJids[index];
|
|
766
|
+
if ((0, jid_1.isHostedDeviceJid)(candidate))
|
|
767
|
+
continue;
|
|
768
|
+
phashTargets[phashTargetCount] = candidate;
|
|
769
|
+
phashTargetCount += 1;
|
|
770
|
+
}
|
|
771
|
+
phashTargets[phashTargetCount] = senderJid;
|
|
772
|
+
phashTargets.length = phashTargetCount + 1;
|
|
773
|
+
const localPhash = (0, phash_1.computePhashV2)(phashTargets);
|
|
774
|
+
const reportingArtifacts = await this.tryBuildReportingTokenArtifacts({
|
|
775
|
+
message,
|
|
776
|
+
stanzaId: sendOptions.id,
|
|
777
|
+
senderUserJid: (0, jid_1.toUserJid)(senderJid),
|
|
778
|
+
remoteJid: groupJid,
|
|
779
|
+
context: 'group_sender_key'
|
|
780
|
+
});
|
|
781
|
+
const botSidecar = await this.buildBotSidecarParticipant(message);
|
|
782
|
+
const customNodes = envelope.customNodes ? [...envelope.customNodes] : [];
|
|
783
|
+
if (reportingArtifacts?.node)
|
|
784
|
+
customNodes.push(reportingArtifacts.node);
|
|
361
785
|
const messageNode = (0, message_1.buildGroupSenderKeyMessageNode)({
|
|
362
786
|
to: groupJid,
|
|
363
787
|
type,
|
|
@@ -367,12 +791,14 @@ class WaMessageDispatchCoordinator {
|
|
|
367
791
|
addressingMode,
|
|
368
792
|
groupCiphertext: groupCiphertext.ciphertext,
|
|
369
793
|
participants: distributionParticipants,
|
|
370
|
-
deviceIdentity: shouldAttachDeviceIdentity
|
|
794
|
+
deviceIdentity: shouldAttachDeviceIdentity || botSidecar?.encType === 'pkmsg'
|
|
371
795
|
? this.getEncodedSignedDeviceIdentity()
|
|
372
796
|
: undefined,
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
797
|
+
customNodes: customNodes.length > 0 ? customNodes : undefined,
|
|
798
|
+
mediatype,
|
|
799
|
+
decryptFail: envelope.decryptFail,
|
|
800
|
+
botParticipants: botSidecar ? [botSidecar] : undefined,
|
|
801
|
+
additionalAttributes: sendOptions.additionalAttributes
|
|
376
802
|
});
|
|
377
803
|
const replayPayload = {
|
|
378
804
|
mode: 'plaintext',
|
|
@@ -380,22 +806,21 @@ class WaMessageDispatchCoordinator {
|
|
|
380
806
|
type,
|
|
381
807
|
plaintext
|
|
382
808
|
};
|
|
383
|
-
const result = await this.retryTracker.track({
|
|
384
|
-
messageIdHint:
|
|
809
|
+
const result = await this.deps.retryTracker.track({
|
|
810
|
+
messageIdHint: messageNode.attrs.id ?? sendOptions.id,
|
|
385
811
|
toJid: groupJid,
|
|
386
|
-
type,
|
|
387
812
|
replayPayload,
|
|
388
813
|
eligibleRequesterDeviceJids: undefined
|
|
389
|
-
}, async () => this.messageClient.publishNode(messageNode, sendOptions));
|
|
814
|
+
}, async () => this.deps.messageClient.publishNode(messageNode, sendOptions));
|
|
390
815
|
const distributedAddresses = new Array(distributionParticipants.length);
|
|
391
816
|
for (let index = 0; index < distributionParticipants.length; index += 1) {
|
|
392
817
|
distributedAddresses[index] = distributionParticipants[index].address;
|
|
393
818
|
}
|
|
394
819
|
try {
|
|
395
|
-
await this.senderKeyManager.markSenderKeyDistributed(groupJid, senderKeyId, distributedAddresses);
|
|
820
|
+
await this.deps.senderKeyManager.markSenderKeyDistributed(groupJid, senderKeyId, distributedAddresses);
|
|
396
821
|
}
|
|
397
822
|
catch (error) {
|
|
398
|
-
this.logger.warn('failed to mark sender key distribution targets', {
|
|
823
|
+
this.deps.logger.warn('failed to mark sender key distribution targets', {
|
|
399
824
|
groupJid,
|
|
400
825
|
participants: distributedAddresses.length,
|
|
401
826
|
message: (0, primitives_2.toError)(error).message
|
|
@@ -409,7 +834,7 @@ class WaMessageDispatchCoordinator {
|
|
|
409
834
|
const hasAddressingError = ackError === 421;
|
|
410
835
|
if (!retryContext.retried &&
|
|
411
836
|
(hasPhashMismatch || hasAddressingMismatch || hasAddressingError)) {
|
|
412
|
-
this.logger.warn('group message publish acknowledged with mismatch metadata', {
|
|
837
|
+
this.deps.logger.warn('group message publish acknowledged with mismatch metadata', {
|
|
413
838
|
id: result.id,
|
|
414
839
|
groupJid,
|
|
415
840
|
localPhash,
|
|
@@ -418,14 +843,14 @@ class WaMessageDispatchCoordinator {
|
|
|
418
843
|
serverAddressingMode,
|
|
419
844
|
ackError
|
|
420
845
|
});
|
|
421
|
-
return this.publishGroupSenderKeyMessage(groupJid,
|
|
422
|
-
...
|
|
423
|
-
id: result.id
|
|
846
|
+
return this.publishGroupSenderKeyMessage(groupJid, {
|
|
847
|
+
...envelope,
|
|
848
|
+
sendOptions: { ...sendOptions, id: result.id }
|
|
424
849
|
}, {
|
|
425
850
|
retried: true,
|
|
426
851
|
forceRefreshParticipants: true,
|
|
427
852
|
forceAddressingMode: serverAddressingMode
|
|
428
|
-
}
|
|
853
|
+
});
|
|
429
854
|
}
|
|
430
855
|
return result;
|
|
431
856
|
}
|
|
@@ -435,7 +860,7 @@ class WaMessageDispatchCoordinator {
|
|
|
435
860
|
return 'lid';
|
|
436
861
|
}
|
|
437
862
|
}
|
|
438
|
-
this.logger.trace('group addressing mode resolved to pn (default)', {
|
|
863
|
+
this.deps.logger.trace('group addressing mode resolved to pn (default)', {
|
|
439
864
|
groupJid,
|
|
440
865
|
participants: participantUserJids.length
|
|
441
866
|
});
|
|
@@ -443,13 +868,13 @@ class WaMessageDispatchCoordinator {
|
|
|
443
868
|
}
|
|
444
869
|
resolveSenderForAddressingMode(addressingMode, meJid) {
|
|
445
870
|
if (addressingMode === 'lid') {
|
|
446
|
-
const meLid = this.
|
|
871
|
+
const meLid = this.deps.getCurrentCredentials()?.meLid;
|
|
447
872
|
if (meLid && meLid.includes('@')) {
|
|
448
873
|
try {
|
|
449
874
|
return (0, jid_1.normalizeDeviceJid)(meLid);
|
|
450
875
|
}
|
|
451
876
|
catch (error) {
|
|
452
|
-
this.logger.trace('ignoring malformed me lid jid', {
|
|
877
|
+
this.deps.logger.trace('ignoring malformed me lid jid', {
|
|
453
878
|
meLid,
|
|
454
879
|
message: (0, primitives_2.toError)(error).message
|
|
455
880
|
});
|
|
@@ -462,7 +887,7 @@ class WaMessageDispatchCoordinator {
|
|
|
462
887
|
const distributionPayload = await (0, padding_1.writeRandomPadMax16)(_proto_1.proto.Message.encode({
|
|
463
888
|
senderKeyDistributionMessage
|
|
464
889
|
}).finish());
|
|
465
|
-
const fanoutDeviceJids = await this.fanoutResolver.resolveGroupParticipantDeviceJids(participantUserJids);
|
|
890
|
+
const fanoutDeviceJids = await this.deps.fanoutResolver.resolveGroupParticipantDeviceJids(participantUserJids);
|
|
466
891
|
if (fanoutDeviceJids.length === 0) {
|
|
467
892
|
return {
|
|
468
893
|
fanoutDeviceJids,
|
|
@@ -477,7 +902,7 @@ class WaMessageDispatchCoordinator {
|
|
|
477
902
|
fanoutAddresses[index] = address;
|
|
478
903
|
fanoutTargetsByAddressKey.set((0, jid_1.signalAddressKey)(address), { jid, address });
|
|
479
904
|
}
|
|
480
|
-
const pendingAddresses = await this.senderKeyManager.filterParticipantsNeedingDistribution(groupJid, senderKeyId, fanoutAddresses);
|
|
905
|
+
const pendingAddresses = await this.deps.senderKeyManager.filterParticipantsNeedingDistribution(groupJid, senderKeyId, fanoutAddresses);
|
|
481
906
|
if (pendingAddresses.length === 0) {
|
|
482
907
|
return {
|
|
483
908
|
fanoutDeviceJids,
|
|
@@ -510,7 +935,7 @@ class WaMessageDispatchCoordinator {
|
|
|
510
935
|
let availableTargets = [];
|
|
511
936
|
let prefetchedAvailableTargets;
|
|
512
937
|
try {
|
|
513
|
-
const resolvedTargets = await this.sessionResolver.ensureSessionsBatch(pendingTargetJids);
|
|
938
|
+
const resolvedTargets = await this.deps.sessionResolver.ensureSessionsBatch(pendingTargetJids);
|
|
514
939
|
availableTargets = resolvedTargets;
|
|
515
940
|
prefetchedAvailableTargets = resolvedTargets;
|
|
516
941
|
}
|
|
@@ -519,7 +944,7 @@ class WaMessageDispatchCoordinator {
|
|
|
519
944
|
if (normalized.message === 'identity mismatch') {
|
|
520
945
|
throw normalized;
|
|
521
946
|
}
|
|
522
|
-
this.logger.warn('group sender-key distribution session sync failed, continuing with available sessions', {
|
|
947
|
+
this.deps.logger.warn('group sender-key distribution session sync failed, continuing with available sessions', {
|
|
523
948
|
groupJid,
|
|
524
949
|
requested: pendingTargetJids.length,
|
|
525
950
|
message: normalized.message
|
|
@@ -528,7 +953,7 @@ class WaMessageDispatchCoordinator {
|
|
|
528
953
|
for (let index = 0; index < pendingTargets.length; index += 1) {
|
|
529
954
|
pendingTargetAddresses[index] = pendingTargets[index].address;
|
|
530
955
|
}
|
|
531
|
-
const hasPendingSessions = await this.sessionStore.hasSessions(pendingTargetAddresses);
|
|
956
|
+
const hasPendingSessions = await this.deps.sessionStore.hasSessions(pendingTargetAddresses);
|
|
532
957
|
const nextAvailableTargets = [];
|
|
533
958
|
for (let index = 0; index < pendingTargets.length; index += 1) {
|
|
534
959
|
if (hasPendingSessions[index]) {
|
|
@@ -551,7 +976,7 @@ class WaMessageDispatchCoordinator {
|
|
|
551
976
|
plaintext: distributionPayload
|
|
552
977
|
};
|
|
553
978
|
}
|
|
554
|
-
const encryptedDistributionParticipants = await this.signalProtocol.encryptMessagesBatch(distributionEncryptRequests, prefetchedAvailableTargets);
|
|
979
|
+
const encryptedDistributionParticipants = await this.deps.signalProtocol.encryptMessagesBatch(distributionEncryptRequests, prefetchedAvailableTargets);
|
|
555
980
|
const distributionParticipants = new Array(availableTargets.length);
|
|
556
981
|
for (let index = 0; index < availableTargets.length; index += 1) {
|
|
557
982
|
const target = availableTargets[index];
|
|
@@ -567,12 +992,12 @@ class WaMessageDispatchCoordinator {
|
|
|
567
992
|
distributionParticipants
|
|
568
993
|
};
|
|
569
994
|
}
|
|
570
|
-
async publishDirectSignalMessageWithFanout(recipientJid,
|
|
571
|
-
const sendOptions =
|
|
995
|
+
async publishDirectSignalMessageWithFanout(recipientJid, envelope) {
|
|
996
|
+
const { message, plaintext, type, edit, mediatype, sendOptions } = envelope;
|
|
572
997
|
const meJid = this.requireCurrentMeJid('sendMessage');
|
|
573
|
-
const meLid = this.
|
|
574
|
-
const selfDeviceJidForRecipient = this.fanoutResolver.resolveSelfDeviceJidForRecipient(recipientJid, meJid, meLid);
|
|
575
|
-
const deviceJids = await this.fanoutResolver.resolveDirectFanoutDeviceJids(recipientJid, selfDeviceJidForRecipient);
|
|
998
|
+
const meLid = this.deps.getCurrentCredentials()?.meLid;
|
|
999
|
+
const selfDeviceJidForRecipient = this.deps.fanoutResolver.resolveSelfDeviceJidForRecipient(recipientJid, meJid, meLid);
|
|
1000
|
+
const deviceJids = await this.deps.fanoutResolver.resolveDirectFanoutDeviceJids(recipientJid, selfDeviceJidForRecipient);
|
|
576
1001
|
const targets = new Array(deviceJids.length);
|
|
577
1002
|
for (let index = 0; index < deviceJids.length; index += 1) {
|
|
578
1003
|
const jid = deviceJids[index];
|
|
@@ -585,7 +1010,7 @@ class WaMessageDispatchCoordinator {
|
|
|
585
1010
|
}
|
|
586
1011
|
const recipientUserJid = (0, jid_1.toUserJid)(recipientJid);
|
|
587
1012
|
const meUserJid = (0, jid_1.toUserJid)(selfDeviceJidForRecipient);
|
|
588
|
-
this.logger.
|
|
1013
|
+
this.deps.logger.trace('wa client publish signal fanout', {
|
|
589
1014
|
to: recipientJid,
|
|
590
1015
|
devices: deviceJids.length,
|
|
591
1016
|
type
|
|
@@ -599,20 +1024,42 @@ class WaMessageDispatchCoordinator {
|
|
|
599
1024
|
}
|
|
600
1025
|
}
|
|
601
1026
|
}
|
|
602
|
-
const resolvedFanoutTargets = await this.sessionResolver.ensureSessionsBatch(deviceJids, expectedIdentityByJid);
|
|
1027
|
+
const resolvedFanoutTargets = await this.deps.sessionResolver.ensureSessionsBatch(deviceJids, expectedIdentityByJid);
|
|
603
1028
|
const resolvedFanoutTargetsByJid = new Map();
|
|
604
1029
|
for (let index = 0; index < resolvedFanoutTargets.length; index += 1) {
|
|
605
1030
|
const target = resolvedFanoutTargets[index];
|
|
606
1031
|
resolvedFanoutTargetsByJid.set((0, jid_1.normalizeDeviceJid)(target.jid), target);
|
|
607
1032
|
}
|
|
1033
|
+
const liveTargets = [];
|
|
1034
|
+
const droppedSecondaryDevices = [];
|
|
608
1035
|
for (let index = 0; index < targets.length; index += 1) {
|
|
609
|
-
|
|
610
|
-
|
|
1036
|
+
const target = targets[index];
|
|
1037
|
+
if (resolvedFanoutTargetsByJid.has(target.normalizedJid)) {
|
|
1038
|
+
liveTargets.push(target);
|
|
1039
|
+
continue;
|
|
611
1040
|
}
|
|
1041
|
+
const isPrimaryRecipient = target.userJid === recipientUserJid && target.normalizedJid === target.userJid;
|
|
1042
|
+
if (isPrimaryRecipient) {
|
|
1043
|
+
this.deps.logger.error('direct fanout dropping primary recipient device without signal session', { to: recipientJid, device: target.jid });
|
|
1044
|
+
}
|
|
1045
|
+
else {
|
|
1046
|
+
droppedSecondaryDevices.push(target.jid);
|
|
1047
|
+
}
|
|
1048
|
+
}
|
|
1049
|
+
if (droppedSecondaryDevices.length > 0) {
|
|
1050
|
+
this.deps.logger.warn('direct fanout dropping secondary devices without signal session', {
|
|
1051
|
+
to: recipientJid,
|
|
1052
|
+
droppedCount: droppedSecondaryDevices.length,
|
|
1053
|
+
totalExpected: targets.length,
|
|
1054
|
+
sample: droppedSecondaryDevices.slice(0, 3)
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
if (liveTargets.length === 0) {
|
|
1058
|
+
throw new Error('direct fanout missing signal sessions for all targets');
|
|
612
1059
|
}
|
|
613
1060
|
let hasSelfDeviceFanout = false;
|
|
614
|
-
for (let index = 0; index <
|
|
615
|
-
if (
|
|
1061
|
+
for (let index = 0; index < liveTargets.length; index += 1) {
|
|
1062
|
+
if (liveTargets[index].userJid === meUserJid) {
|
|
616
1063
|
hasSelfDeviceFanout = true;
|
|
617
1064
|
break;
|
|
618
1065
|
}
|
|
@@ -620,13 +1067,10 @@ class WaMessageDispatchCoordinator {
|
|
|
620
1067
|
const selfDevicePlaintext = hasSelfDeviceFanout
|
|
621
1068
|
? await (0, padding_1.writeRandomPadMax16)(_proto_1.proto.Message.encode((0, device_sent_1.wrapDeviceSentMessage)(message, recipientUserJid)).finish())
|
|
622
1069
|
: null;
|
|
623
|
-
const participantRequests = new Array(
|
|
624
|
-
for (let index = 0; index <
|
|
625
|
-
const target =
|
|
1070
|
+
const participantRequests = new Array(liveTargets.length);
|
|
1071
|
+
for (let index = 0; index < liveTargets.length; index += 1) {
|
|
1072
|
+
const target = liveTargets[index];
|
|
626
1073
|
const resolvedTarget = resolvedFanoutTargetsByJid.get(target.normalizedJid);
|
|
627
|
-
if (!resolvedTarget) {
|
|
628
|
-
throw new Error('direct fanout missing signal session for target');
|
|
629
|
-
}
|
|
630
1074
|
participantRequests[index] = {
|
|
631
1075
|
target,
|
|
632
1076
|
address: resolvedTarget.address,
|
|
@@ -651,15 +1095,20 @@ class WaMessageDispatchCoordinator {
|
|
|
651
1095
|
session: request.session
|
|
652
1096
|
};
|
|
653
1097
|
}
|
|
654
|
-
const encryptedParticipants = await this.signalProtocol.encryptMessagesBatch(encryptRequests, prefetchedSessions);
|
|
655
|
-
const
|
|
1098
|
+
const encryptedParticipants = await this.deps.signalProtocol.encryptMessagesBatch(encryptRequests, prefetchedSessions);
|
|
1099
|
+
const isBotRecipient = (0, jid_1.isBotJid)(recipientJid);
|
|
1100
|
+
const participants = [];
|
|
656
1101
|
for (let index = 0; index < participantRequests.length; index += 1) {
|
|
657
1102
|
const request = participantRequests[index];
|
|
658
|
-
|
|
1103
|
+
const entry = {
|
|
659
1104
|
jid: request.target.jid,
|
|
660
1105
|
encType: encryptedParticipants[index].type,
|
|
661
1106
|
ciphertext: encryptedParticipants[index].ciphertext
|
|
662
1107
|
};
|
|
1108
|
+
// wa-web direct 1:1 to bot puts the bot device alongside self devices
|
|
1109
|
+
// inside `<participants>`; the `<bot>` envelope is only used for group
|
|
1110
|
+
// mentions (the sidecar copy) or for bot feedback / revoke flows.
|
|
1111
|
+
participants.push(entry);
|
|
663
1112
|
}
|
|
664
1113
|
let shouldAttachDeviceIdentity = false;
|
|
665
1114
|
for (let index = 0; index < participants.length; index += 1) {
|
|
@@ -679,16 +1128,23 @@ class WaMessageDispatchCoordinator {
|
|
|
679
1128
|
context: 'direct_fanout'
|
|
680
1129
|
});
|
|
681
1130
|
let privacyTokenNode;
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
1131
|
+
if (!isBotRecipient) {
|
|
1132
|
+
try {
|
|
1133
|
+
privacyTokenNode =
|
|
1134
|
+
(await this.privacyTokenDedup.run(`pt:${recipientUserJid}`, () => this.deps.resolvePrivacyTokenNode(recipientUserJid))) ?? undefined;
|
|
1135
|
+
}
|
|
1136
|
+
catch (error) {
|
|
1137
|
+
this.deps.logger.warn('privacy token resolution failed', {
|
|
1138
|
+
to: recipientUserJid,
|
|
1139
|
+
message: (0, primitives_2.toError)(error).message
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
691
1142
|
}
|
|
1143
|
+
const customNodes = envelope.customNodes ? [...envelope.customNodes] : [];
|
|
1144
|
+
if (reportingArtifacts?.node)
|
|
1145
|
+
customNodes.push(reportingArtifacts.node);
|
|
1146
|
+
if (privacyTokenNode)
|
|
1147
|
+
customNodes.push(privacyTokenNode);
|
|
692
1148
|
const messageNode = (0, message_1.buildDirectMessageFanoutNode)({
|
|
693
1149
|
to: recipientJid,
|
|
694
1150
|
type,
|
|
@@ -696,10 +1152,10 @@ class WaMessageDispatchCoordinator {
|
|
|
696
1152
|
edit,
|
|
697
1153
|
participants,
|
|
698
1154
|
deviceIdentity,
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
1155
|
+
customNodes: customNodes.length > 0 ? customNodes : undefined,
|
|
1156
|
+
mediatype,
|
|
1157
|
+
decryptFail: envelope.decryptFail,
|
|
1158
|
+
additionalAttributes: sendOptions.additionalAttributes
|
|
703
1159
|
});
|
|
704
1160
|
const replayPayload = {
|
|
705
1161
|
mode: 'plaintext',
|
|
@@ -707,14 +1163,13 @@ class WaMessageDispatchCoordinator {
|
|
|
707
1163
|
type,
|
|
708
1164
|
plaintext
|
|
709
1165
|
};
|
|
710
|
-
const result = await this.retryTracker.track({
|
|
711
|
-
messageIdHint:
|
|
1166
|
+
const result = await this.deps.retryTracker.track({
|
|
1167
|
+
messageIdHint: messageNode.attrs.id ?? sendOptions.id,
|
|
712
1168
|
toJid: recipientJid,
|
|
713
|
-
type,
|
|
714
1169
|
replayPayload,
|
|
715
1170
|
eligibleRequesterDeviceJids: deviceJids
|
|
716
|
-
}, async () => this.messageClient.publishNode(messageNode, sendOptions));
|
|
717
|
-
this.onDirectMessageSent(recipientUserJid);
|
|
1171
|
+
}, async () => this.deps.messageClient.publishNode(messageNode, sendOptions));
|
|
1172
|
+
this.deps.onDirectMessageSent(recipientUserJid);
|
|
718
1173
|
return result;
|
|
719
1174
|
}
|
|
720
1175
|
async withResolvedMessageId(options) {
|
|
@@ -740,26 +1195,24 @@ class WaMessageDispatchCoordinator {
|
|
|
740
1195
|
const dv = new DataView(timestampBytes.buffer, timestampBytes.byteOffset, timestampBytes.byteLength);
|
|
741
1196
|
if (this.mobileMessageIdFormat) {
|
|
742
1197
|
dv.setBigUint64(0, BigInt(Date.now()), false);
|
|
743
|
-
const
|
|
1198
|
+
const digest = (0, primitives_1.md5Bytes)([
|
|
744
1199
|
timestampBytes,
|
|
745
1200
|
bytes_1.TEXT_ENCODER.encode(meUserJid),
|
|
746
1201
|
await (0, _crypto_1.randomBytesAsync)(16)
|
|
747
1202
|
]);
|
|
748
|
-
const digest = (0, primitives_1.md5Bytes)(entropy);
|
|
749
1203
|
digest[0] = 0xac;
|
|
750
1204
|
return (0, bytes_1.bytesToHex)(digest).toUpperCase();
|
|
751
1205
|
}
|
|
752
1206
|
dv.setBigUint64(0, BigInt(Math.floor(Date.now() / 1000)), false);
|
|
753
|
-
const
|
|
1207
|
+
const digest = (0, _crypto_1.sha256)([
|
|
754
1208
|
timestampBytes,
|
|
755
1209
|
bytes_1.TEXT_ENCODER.encode(meUserJid),
|
|
756
1210
|
await (0, _crypto_1.randomBytesAsync)(8)
|
|
757
1211
|
]);
|
|
758
|
-
const digest = await (0, _crypto_1.sha256)(entropy);
|
|
759
1212
|
return `3EB0${(0, bytes_1.bytesToHex)(digest.subarray(0, 9)).toUpperCase()}`;
|
|
760
1213
|
}
|
|
761
1214
|
catch (error) {
|
|
762
|
-
this.logger.warn('failed to generate message id, falling back to random', {
|
|
1215
|
+
this.deps.logger.warn('failed to generate message id, falling back to random', {
|
|
763
1216
|
message: (0, primitives_2.toError)(error).message
|
|
764
1217
|
});
|
|
765
1218
|
if (this.mobileMessageIdFormat) {
|
|
@@ -783,7 +1236,7 @@ class WaMessageDispatchCoordinator {
|
|
|
783
1236
|
});
|
|
784
1237
|
}
|
|
785
1238
|
catch (error) {
|
|
786
|
-
this.logger.warn('failed to generate reporting token', {
|
|
1239
|
+
this.deps.logger.warn('failed to generate reporting token', {
|
|
787
1240
|
context: input.context,
|
|
788
1241
|
id: input.stanzaId,
|
|
789
1242
|
remoteJid: input.remoteJid,
|
|
@@ -793,7 +1246,7 @@ class WaMessageDispatchCoordinator {
|
|
|
793
1246
|
}
|
|
794
1247
|
}
|
|
795
1248
|
getEncodedSignedDeviceIdentity() {
|
|
796
|
-
const signedIdentity = this.
|
|
1249
|
+
const signedIdentity = this.deps.getCurrentCredentials()?.signedIdentity;
|
|
797
1250
|
if (!signedIdentity) {
|
|
798
1251
|
return undefined;
|
|
799
1252
|
}
|
|
@@ -802,15 +1255,15 @@ class WaMessageDispatchCoordinator {
|
|
|
802
1255
|
resolveUserIcdc(userJid, localIdentity) {
|
|
803
1256
|
return this.icdcDedup.run(`icdc:${userJid}:${localIdentity ? '1' : '0'}`, async () => {
|
|
804
1257
|
try {
|
|
805
|
-
const snapshots = await this.deviceListStore.getUserDevicesBatch([userJid]);
|
|
1258
|
+
const snapshots = await this.deps.deviceListStore.getUserDevicesBatch([userJid]);
|
|
806
1259
|
const snapshot = snapshots[0];
|
|
807
1260
|
if (!snapshot || snapshot.deviceJids.length === 0) {
|
|
808
1261
|
return null;
|
|
809
1262
|
}
|
|
810
|
-
return (0, icdc_1.resolveIcdcMeta)(snapshot.deviceJids, this.identityStore, snapshot.updatedAtMs, localIdentity, this.getIcdcHashLength?.());
|
|
1263
|
+
return (0, icdc_1.resolveIcdcMeta)(snapshot.deviceJids, this.deps.identityStore, snapshot.updatedAtMs, localIdentity, this.deps.getIcdcHashLength?.());
|
|
811
1264
|
}
|
|
812
1265
|
catch (error) {
|
|
813
|
-
this.logger.trace('icdc resolution failed', {
|
|
1266
|
+
this.deps.logger.trace('icdc resolution failed', {
|
|
814
1267
|
userJid,
|
|
815
1268
|
message: (0, primitives_2.toError)(error).message
|
|
816
1269
|
});
|
|
@@ -819,7 +1272,7 @@ class WaMessageDispatchCoordinator {
|
|
|
819
1272
|
});
|
|
820
1273
|
}
|
|
821
1274
|
requireCurrentMeJid(context) {
|
|
822
|
-
const meJid = this.
|
|
1275
|
+
const meJid = this.deps.getCurrentCredentials()?.meJid;
|
|
823
1276
|
if (meJid) {
|
|
824
1277
|
return meJid;
|
|
825
1278
|
}
|
|
@@ -827,3 +1280,28 @@ class WaMessageDispatchCoordinator {
|
|
|
827
1280
|
}
|
|
828
1281
|
}
|
|
829
1282
|
exports.WaMessageDispatchCoordinator = WaMessageDispatchCoordinator;
|
|
1283
|
+
function pickContentContextInfo(content) {
|
|
1284
|
+
if (typeof content !== 'object' || content === null)
|
|
1285
|
+
return undefined;
|
|
1286
|
+
if ((0, content_1.isSendTextMessage)(content) || (0, content_1.isSendMediaMessage)(content)) {
|
|
1287
|
+
return content.contextInfo;
|
|
1288
|
+
}
|
|
1289
|
+
return undefined;
|
|
1290
|
+
}
|
|
1291
|
+
function assertNewsletterContextInfoCompatible(ctx) {
|
|
1292
|
+
if (!ctx)
|
|
1293
|
+
return;
|
|
1294
|
+
const unsupported = [];
|
|
1295
|
+
if (ctx.quotedMessageId !== undefined)
|
|
1296
|
+
unsupported.push('quote');
|
|
1297
|
+
if (ctx.mentionedJids?.length)
|
|
1298
|
+
unsupported.push('mentions');
|
|
1299
|
+
if (ctx.isSpoiler === true)
|
|
1300
|
+
unsupported.push('isSpoiler');
|
|
1301
|
+
if (ctx.groupSubject !== undefined || ctx.parentGroupJid !== undefined) {
|
|
1302
|
+
unsupported.push('group invite reply (groupSubject/parentGroupJid)');
|
|
1303
|
+
}
|
|
1304
|
+
if (unsupported.length > 0) {
|
|
1305
|
+
throw new Error(`newsletter sends do not support: ${unsupported.join(', ')}`);
|
|
1306
|
+
}
|
|
1307
|
+
}
|