zapo-js 0.3.0 → 1.0.1
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 +98 -178
- 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 +20 -8
- package/dist/auth/pairing/WaPairingFlow.js +35 -26
- package/dist/auth/pairing/pairing-code-crypto.js +17 -19
- package/dist/client/WaClient.js +343 -474
- package/dist/client/WaClientFactory.js +281 -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 +685 -207
- 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 +257 -126
- package/dist/client/coordinators/WaStatusCoordinator.js +49 -0
- package/dist/client/coordinators/WaStreamControlCoordinator.js +8 -9
- 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 +163 -6
- package/dist/client/messaging/fanout.js +9 -10
- package/dist/client/messaging/{participants.js → group-metadata.js} +93 -44
- package/dist/client/messaging/ignore-key.js +132 -0
- package/dist/client/messaging/key-protocol.js +4 -18
- 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 +282 -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 +8 -9
- 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 +158 -8
- package/dist/esm/client/messaging/fanout.js +10 -11
- package/dist/esm/client/messaging/{participants.js → group-metadata.js} +92 -43
- 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 +69 -20
- 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 +8 -1
- 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/locks/pre-key.lock.js +4 -1
- 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 +35 -5
- 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 +130 -36
- package/dist/retry/tracker.js +3 -7
- package/dist/signal/api/SignalDeviceSyncApi.js +67 -18
- package/dist/signal/api/SignalDigestSyncApi.js +7 -2
- 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 +6 -8
- package/dist/signal/constants.js +4 -1
- package/dist/signal/encoding.js +5 -303
- package/dist/signal/group/SenderKeyChain.js +18 -33
- package/dist/signal/group/SenderKeyCodec.js +2 -2
- package/dist/signal/group/SenderKeyManager.js +26 -9
- 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 +11 -1
- package/dist/signal/registration/utils.js +8 -1
- package/dist/signal/session/SignalProtocol.js +113 -11
- package/dist/signal/session/SignalRatchet.js +26 -56
- package/dist/signal/session/SignalSerializer.js +2 -2
- package/dist/signal/session/SignalSession.js +7 -15
- 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/locks/pre-key.lock.js +4 -1
- 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 +2 -2
- 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 +3 -2
- 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 +9 -9
- package/dist/transport/noise/WaMobileClientPayload.js +6 -1
- package/dist/transport/noise/WaNoiseCert.js +7 -2
- package/dist/transport/noise/WaNoiseHandshake.js +26 -24
- package/dist/transport/noise/WaNoiseSession.js +41 -61
- package/dist/transport/noise/WaNoiseSocket.js +19 -13
- 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/types.d.ts +1 -1
- package/dist/types/appstate/utils.d.ts +18 -2
- 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 +49 -2
- 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 +55 -32
- 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 +844 -72
- 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 +34 -8
- 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 +209 -11
- 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 +18 -1
- 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/signal/types.d.ts +1 -1
- 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 +6 -1
- 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/noise/types.d.ts +1 -1
- 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
package/dist/client/WaClient.js
CHANGED
|
@@ -2,23 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WaClient = void 0;
|
|
4
4
|
const node_events_1 = require("node:events");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const mailbox_1 = require("./mailbox");
|
|
5
|
+
const ignore_key_1 = require("./messaging/ignore-key");
|
|
6
|
+
const history_sync_1 = require("./persistence/history-sync");
|
|
7
|
+
const mailbox_1 = require("./persistence/mailbox");
|
|
9
8
|
const WriteBehindPersistence_1 = require("./persistence/WriteBehindPersistence");
|
|
10
9
|
const WaClientFactory_1 = require("./WaClientFactory");
|
|
11
10
|
const ConsoleLogger_1 = require("../infra/log/ConsoleLogger");
|
|
12
|
-
const
|
|
13
|
-
const _proto_1 = require("../proto.js");
|
|
11
|
+
const _proto_1 = require("../proto");
|
|
14
12
|
const constants_1 = require("../protocol/constants");
|
|
15
13
|
const jid_1 = require("../protocol/jid");
|
|
16
14
|
const stream_1 = require("../protocol/stream");
|
|
17
15
|
const noop_store_1 = require("../store/noop.store");
|
|
18
16
|
const device_1 = require("../transport/node/builders/device");
|
|
19
|
-
const presence_1 = require("../transport/node/builders/presence");
|
|
20
17
|
const query_1 = require("../transport/node/query");
|
|
21
|
-
const
|
|
18
|
+
const wa_web_version_fetcher_1 = require("../transport/wa-web-version-fetcher");
|
|
22
19
|
const primitives_1 = require("../util/primitives");
|
|
23
20
|
const SYNC_RELATED_PROTOCOL_TYPES = new Set([
|
|
24
21
|
_proto_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_REQUEST,
|
|
@@ -26,7 +23,59 @@ const SYNC_RELATED_PROTOCOL_TYPES = new Set([
|
|
|
26
23
|
_proto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE,
|
|
27
24
|
_proto_1.proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE
|
|
28
25
|
]);
|
|
26
|
+
/**
|
|
27
|
+
* Top-level WhatsApp client. Owns the transport, auth, signal, and per-feature
|
|
28
|
+
* coordinators (accessible via getters such as {@link message}, {@link group},
|
|
29
|
+
* {@link newsletter}, etc.) and re-emits every {@link WaClientEventMap} event.
|
|
30
|
+
*
|
|
31
|
+
* Lifecycle: construct with {@link WaClientOptions}, call {@link connect} to
|
|
32
|
+
* open the socket, react to `connection`/`auth_qr`/`auth_pairing_code` events,
|
|
33
|
+
* then use the coordinator getters to drive the session. Call {@link disconnect}
|
|
34
|
+
* to shut down cleanly or {@link logout} to remove the companion device.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { createPinoLogger, createStore, WaClient } from '..'
|
|
39
|
+
* import { createSqliteStore } from '@zapo-js/store-sqlite'
|
|
40
|
+
*
|
|
41
|
+
* const store = createStore({
|
|
42
|
+
* backends: { sqlite: createSqliteStore({ path: '.auth/state.sqlite' }) },
|
|
43
|
+
* providers: {
|
|
44
|
+
* auth: 'sqlite',
|
|
45
|
+
* signal: 'sqlite',
|
|
46
|
+
* preKey: 'sqlite',
|
|
47
|
+
* session: 'sqlite',
|
|
48
|
+
* identity: 'sqlite',
|
|
49
|
+
* senderKey: 'sqlite',
|
|
50
|
+
* appState: 'sqlite',
|
|
51
|
+
* privacyToken: 'sqlite',
|
|
52
|
+
* messages: 'sqlite',
|
|
53
|
+
* threads: 'sqlite',
|
|
54
|
+
* contacts: 'sqlite'
|
|
55
|
+
* }
|
|
56
|
+
* })
|
|
57
|
+
*
|
|
58
|
+
* const client = new WaClient(
|
|
59
|
+
* { store, sessionId: 'default' },
|
|
60
|
+
* await createPinoLogger({ level: 'info', pretty: true })
|
|
61
|
+
* )
|
|
62
|
+
*
|
|
63
|
+
* client.on('auth_qr', ({ qr, ttlMs }) => console.log('scan:', qr, ttlMs))
|
|
64
|
+
* client.on('connection', (event) => console.log('connection', event))
|
|
65
|
+
* client.on('message', async (event) => {
|
|
66
|
+
* if (event.message?.conversation === 'ping') {
|
|
67
|
+
* await client.message.send(event.chatJid!, 'pong')
|
|
68
|
+
* }
|
|
69
|
+
* })
|
|
70
|
+
*
|
|
71
|
+
* await client.connect()
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
29
74
|
class WaClient extends node_events_1.EventEmitter {
|
|
75
|
+
/**
|
|
76
|
+
* @param options Client configuration (store, transport, addons, history...).
|
|
77
|
+
* @param logger Optional structured logger. Defaults to a `ConsoleLogger('info')`.
|
|
78
|
+
*/
|
|
30
79
|
constructor(options, logger = new ConsoleLogger_1.ConsoleLogger('info')) {
|
|
31
80
|
super();
|
|
32
81
|
this.connectPromise = null;
|
|
@@ -36,38 +85,26 @@ class WaClient extends node_events_1.EventEmitter {
|
|
|
36
85
|
const base = (0, WaClientFactory_1.resolveWaClientBase)(options, logger);
|
|
37
86
|
this.options = base.options;
|
|
38
87
|
this.logger = base.logger;
|
|
39
|
-
this.
|
|
40
|
-
this.contactStore = base.sessionStore.contacts;
|
|
41
|
-
this.messageStore = base.sessionStore.messages;
|
|
42
|
-
this.messageSecretStore = base.sessionStore.messageSecret;
|
|
43
|
-
this.participantsStore = base.sessionStore.participants;
|
|
44
|
-
this.privacyTokenStore = base.sessionStore.privacyToken;
|
|
45
|
-
this.deviceListStore = base.sessionStore.deviceList;
|
|
46
|
-
this.retryStore = base.sessionStore.retry;
|
|
47
|
-
this.signalStore = base.sessionStore.signal;
|
|
48
|
-
this.preKeyStore = base.sessionStore.preKey;
|
|
49
|
-
this.sessionStore = base.sessionStore.session;
|
|
50
|
-
this.identityStore = base.sessionStore.identity;
|
|
51
|
-
this.senderKeyStore = base.sessionStore.senderKey;
|
|
52
|
-
this.threadStore = base.sessionStore.threads;
|
|
88
|
+
this.stores = base.sessionStore;
|
|
53
89
|
this.writeBehind = new WriteBehindPersistence_1.WriteBehindPersistence({
|
|
54
|
-
messageStore: this.
|
|
55
|
-
threadStore: this.
|
|
56
|
-
contactStore: this.
|
|
90
|
+
messageStore: this.stores.messages,
|
|
91
|
+
threadStore: this.stores.threads,
|
|
92
|
+
contactStore: this.stores.contacts
|
|
57
93
|
}, this.logger, this.options.writeBehind);
|
|
58
|
-
if (this.options.addons?.autoDecrypt &&
|
|
59
|
-
this.
|
|
60
|
-
this.logger.warn('addons.autoDecrypt is
|
|
61
|
-
'addon decryption will only work if secrets are in the message store'
|
|
94
|
+
if (this.options.addons?.autoDecrypt !== false &&
|
|
95
|
+
this.stores.messageSecret === noop_store_1.NOOP_MESSAGE_SECRET_STORE) {
|
|
96
|
+
this.logger.warn('addons.autoDecrypt is on (default) but messageSecret cache is noop – ' +
|
|
97
|
+
'addon decryption will only work if secrets are in the message store. ' +
|
|
98
|
+
'Set addons.autoDecrypt: false to silence this warning.');
|
|
62
99
|
}
|
|
63
100
|
const dependencies = (0, WaClientFactory_1.buildWaClientDependencies)({
|
|
64
101
|
base,
|
|
65
102
|
runtime: {
|
|
66
|
-
sendNode: (node) => this.sendNode(node),
|
|
67
|
-
query: (node, timeoutMs, options) => this.query(node, timeoutMs, options),
|
|
103
|
+
sendNode: (node) => this.deps.lowLevelCoordinator.sendNode(node),
|
|
104
|
+
query: (node, timeoutMs, options) => this.deps.lowLevelCoordinator.query(node, timeoutMs, options),
|
|
68
105
|
queryWithContext: this.queryWithContext.bind(this),
|
|
69
|
-
syncAppState: () => this.
|
|
70
|
-
syncAppStateWithOptions: (syncOptions) => this.
|
|
106
|
+
syncAppState: () => this.deps.chatCoordinator.sync().then(() => { }),
|
|
107
|
+
syncAppStateWithOptions: (syncOptions) => this.deps.chatCoordinator.sync(syncOptions),
|
|
71
108
|
emitEvent: this.emit.bind(this),
|
|
72
109
|
handleIncomingMessageEvent: this.handleIncomingMessageEvent.bind(this),
|
|
73
110
|
handleError: this.handleError.bind(this),
|
|
@@ -75,11 +112,50 @@ class WaClient extends node_events_1.EventEmitter {
|
|
|
75
112
|
clearStoredState: this.clearStoredState.bind(this),
|
|
76
113
|
resumeIncomingEvents: () => {
|
|
77
114
|
this.acceptingIncomingEvents = true;
|
|
78
|
-
}
|
|
115
|
+
},
|
|
116
|
+
subscribeProtocolMessage: (handler) => {
|
|
117
|
+
this.on('message_protocol', handler);
|
|
118
|
+
return () => {
|
|
119
|
+
this.off('message_protocol', handler);
|
|
120
|
+
};
|
|
121
|
+
},
|
|
122
|
+
persistContact: (record) => this.writeBehind.persistContact(record)
|
|
79
123
|
}
|
|
80
124
|
});
|
|
81
|
-
|
|
125
|
+
this.deps = dependencies;
|
|
126
|
+
this.appStateSync = dependencies.appStateSync;
|
|
127
|
+
this.mediaTransfer = dependencies.mediaTransfer;
|
|
82
128
|
this.bindNodeTransportEvents();
|
|
129
|
+
this.on('connection', (event) => {
|
|
130
|
+
if (event.status !== 'close')
|
|
131
|
+
return;
|
|
132
|
+
if (!this.options.recoverFromClientTooOld)
|
|
133
|
+
return;
|
|
134
|
+
if (event.reason !== stream_1.WA_DISCONNECT_REASONS.FAILURE_CLIENT_TOO_OLD)
|
|
135
|
+
return;
|
|
136
|
+
this.logger.warn('wa rejected the connect with client_too_old: the zapo default WA Web version is outdated. ' +
|
|
137
|
+
'Auto-recovering by fetching the current version from web.whatsapp.com – ' +
|
|
138
|
+
'please upgrade zapo so the shipped default catches up.');
|
|
139
|
+
void this.runClientTooOldRecover();
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
async runClientTooOldRecover() {
|
|
143
|
+
try {
|
|
144
|
+
if (this.connectPromise) {
|
|
145
|
+
await this.connectPromise.catch(() => undefined);
|
|
146
|
+
}
|
|
147
|
+
const latest = await (0, wa_web_version_fetcher_1.fetchLatestWaWebVersion)();
|
|
148
|
+
this.logger.info('client_too_old auto-recover: reconnecting', {
|
|
149
|
+
version: latest.version
|
|
150
|
+
});
|
|
151
|
+
this.deps.authClient.setNextConnectVersion(latest.version);
|
|
152
|
+
await this.connect();
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
this.logger.warn('client_too_old auto-recover failed', {
|
|
156
|
+
message: (0, primitives_1.toError)(error).message
|
|
157
|
+
});
|
|
158
|
+
}
|
|
83
159
|
}
|
|
84
160
|
on(event, listener) {
|
|
85
161
|
return super.on(event, listener);
|
|
@@ -93,60 +169,36 @@ class WaClient extends node_events_1.EventEmitter {
|
|
|
93
169
|
emit(event, ...args) {
|
|
94
170
|
return super.emit(event, ...args);
|
|
95
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Returns the current auth state snapshot (credentials, registration,
|
|
174
|
+
* connection flag) – useful for resuming or inspecting the client.
|
|
175
|
+
*/
|
|
96
176
|
getState() {
|
|
97
|
-
const connected = this.connectionManager.isConnected();
|
|
177
|
+
const connected = this.deps.connectionManager.isConnected();
|
|
98
178
|
this.logger.trace('wa client state requested', { connected });
|
|
99
|
-
return this.authClient.getState(connected);
|
|
179
|
+
return this.deps.authClient.getState(connected);
|
|
100
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Returns the credentials persisted for the current session, or `null` if
|
|
183
|
+
* the client has not been paired yet.
|
|
184
|
+
*/
|
|
101
185
|
getCredentials() {
|
|
102
|
-
return this.authClient.getCurrentCredentials();
|
|
186
|
+
return this.deps.authClient.getCurrentCredentials();
|
|
103
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Returns the measured skew between the local clock and the server, in
|
|
190
|
+
* milliseconds, or `null` if no handshake has completed yet.
|
|
191
|
+
*/
|
|
104
192
|
getClockSkewMs() {
|
|
105
|
-
return this.connectionManager.getClockSkewMs();
|
|
106
|
-
}
|
|
107
|
-
async sendNode(node) {
|
|
108
|
-
try {
|
|
109
|
-
await this.nodeOrchestrator.sendNode(node);
|
|
110
|
-
}
|
|
111
|
-
catch (error) {
|
|
112
|
-
const normalized = (0, primitives_1.toError)(error);
|
|
113
|
-
if (this.receiptQueue.shouldQueue(node, normalized)) {
|
|
114
|
-
this.receiptQueue.enqueue(node);
|
|
115
|
-
this.logger.warn('queued dangling receipt after send failure', {
|
|
116
|
-
id: node.attrs.id,
|
|
117
|
-
to: node.attrs.to,
|
|
118
|
-
message: normalized.message,
|
|
119
|
-
queueSize: this.receiptQueue.size()
|
|
120
|
-
});
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
throw normalized;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
async sendPresence(type) {
|
|
127
|
-
const credentials = this.authClient.getCurrentCredentials();
|
|
128
|
-
await this.nodeOrchestrator.sendNode((0, presence_1.buildPresenceNode)({ type, name: credentials?.meDisplayName ?? undefined }), false);
|
|
129
|
-
}
|
|
130
|
-
async query(node, timeoutMs = this.options.iqTimeoutMs ?? constants_1.WA_DEFAULTS.IQ_TIMEOUT_MS, options = {}) {
|
|
131
|
-
if (!this.connectionManager.isConnected()) {
|
|
132
|
-
throw new Error('client is not connected');
|
|
133
|
-
}
|
|
134
|
-
this.logger.debug('wa client query', { tag: node.tag, id: node.attrs.id, timeoutMs });
|
|
135
|
-
return this.nodeOrchestrator.query(node, timeoutMs, options);
|
|
136
|
-
}
|
|
137
|
-
registerIncomingHandler(registration) {
|
|
138
|
-
return this.incomingNode.registerIncomingHandler(registration);
|
|
139
|
-
}
|
|
140
|
-
unregisterIncomingHandler(registration) {
|
|
141
|
-
return this.incomingNode.unregisterIncomingHandler(registration);
|
|
193
|
+
return this.deps.connectionManager.getClockSkewMs();
|
|
142
194
|
}
|
|
143
195
|
bindNodeTransportEvents() {
|
|
144
|
-
this.nodeTransport.on('frame_in', (frame) => this.emit('
|
|
145
|
-
this.nodeTransport.on('frame_out', (frame) => this.emit('
|
|
146
|
-
this.nodeTransport.on('node_in', (node, frame) => this.emit('
|
|
147
|
-
this.nodeTransport.on('node_out', (node, frame) => this.emit('
|
|
148
|
-
this.nodeTransport.on('decode_error', (error, frame) => {
|
|
149
|
-
this.emit('
|
|
196
|
+
this.deps.nodeTransport.on('frame_in', (frame) => this.emit('debug_transport_frame_in', { frame }));
|
|
197
|
+
this.deps.nodeTransport.on('frame_out', (frame) => this.emit('debug_transport_frame_out', { frame }));
|
|
198
|
+
this.deps.nodeTransport.on('node_in', (node, frame) => this.emit('debug_transport_node_in', { node, frame }));
|
|
199
|
+
this.deps.nodeTransport.on('node_out', (node, frame) => this.emit('debug_transport_node_out', { node, frame }));
|
|
200
|
+
this.deps.nodeTransport.on('decode_error', (error, frame) => {
|
|
201
|
+
this.emit('debug_transport_decode_error', { error, frame });
|
|
150
202
|
this.handleError(error);
|
|
151
203
|
});
|
|
152
204
|
}
|
|
@@ -159,13 +211,23 @@ class WaClient extends node_events_1.EventEmitter {
|
|
|
159
211
|
void (0, mailbox_1.persistIncomingMailboxEntities)({
|
|
160
212
|
logger: this.logger,
|
|
161
213
|
writeBehind: this.writeBehind,
|
|
162
|
-
messageSecretStore: this.
|
|
214
|
+
messageSecretStore: this.stores.messageSecret,
|
|
163
215
|
event
|
|
164
216
|
});
|
|
165
|
-
if (this.options.addons?.autoDecrypt && event.message) {
|
|
166
|
-
void this.tryDecryptAddon(event).catch((err) => {
|
|
217
|
+
if (this.options.addons?.autoDecrypt !== false && event.message) {
|
|
218
|
+
void this.deps.messageCoordinator.tryDecryptAddon(event).catch((err) => {
|
|
167
219
|
this.logger.warn('addon auto-decrypt failed', {
|
|
168
|
-
id: event.
|
|
220
|
+
id: event.key.id,
|
|
221
|
+
message: (0, primitives_1.toError)(err).message
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
// Decode unconditionally – chunks whose parent prompt we never sent
|
|
226
|
+
// are skipped by the secret-store lookup downstream.
|
|
227
|
+
if (event.message) {
|
|
228
|
+
void this.deps.botCoordinator.tryDecryptChunk(event).catch((err) => {
|
|
229
|
+
this.logger.warn('bot chunk auto-decrypt failed', {
|
|
230
|
+
id: event.key.id,
|
|
169
231
|
message: (0, primitives_1.toError)(err).message
|
|
170
232
|
});
|
|
171
233
|
});
|
|
@@ -182,36 +244,62 @@ class WaClient extends node_events_1.EventEmitter {
|
|
|
182
244
|
const protocolType = protocolMessage.type;
|
|
183
245
|
if (protocolType === null || protocolType === undefined) {
|
|
184
246
|
this.logger.debug('incoming protocol message without type', {
|
|
185
|
-
id: event.
|
|
186
|
-
from: event.
|
|
247
|
+
id: event.key.id,
|
|
248
|
+
from: event.key.remoteJid
|
|
187
249
|
});
|
|
188
250
|
return;
|
|
189
251
|
}
|
|
190
252
|
if (protocolType === _proto_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_REQUEST) {
|
|
191
|
-
await this.
|
|
253
|
+
await this.appStateSync.handleIncomingKeyRequest(event.key, protocolMessage);
|
|
192
254
|
return;
|
|
193
255
|
}
|
|
194
256
|
if (protocolType === _proto_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE) {
|
|
195
|
-
await this.
|
|
257
|
+
await this.appStateSync.handleIncomingKeyShare(event.key, protocolMessage);
|
|
196
258
|
return;
|
|
197
259
|
}
|
|
198
260
|
if (protocolType === _proto_1.proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION) {
|
|
199
|
-
if (this.options.history?.enabled
|
|
200
|
-
|
|
261
|
+
if (this.options.history?.enabled !== false &&
|
|
262
|
+
protocolMessage.historySyncNotification) {
|
|
263
|
+
const peerRemoteJid = event.key.remoteJid;
|
|
264
|
+
const peerStanzaId = event.key.id;
|
|
265
|
+
await (0, history_sync_1.runHistorySyncNotification)({
|
|
266
|
+
logger: this.logger,
|
|
267
|
+
mediaTransfer: this.mediaTransfer,
|
|
268
|
+
writeBehind: this.writeBehind,
|
|
269
|
+
emitEvent: this.emit.bind(this),
|
|
270
|
+
onPrivacyTokens: (conversations) => this.deps.trustedContactToken.hydrateFromHistorySync(conversations),
|
|
271
|
+
onNctSalt: (salt) => this.deps.trustedContactToken.hydrateNctSaltFromHistorySync(salt),
|
|
272
|
+
onProcessed: peerRemoteJid && peerStanzaId
|
|
273
|
+
? async () => {
|
|
274
|
+
try {
|
|
275
|
+
await this.message.sendReceipt(peerRemoteJid, peerStanzaId, {
|
|
276
|
+
type: constants_1.WA_MESSAGE_TYPES.RECEIPT_TYPE_HISTORY_SYNC
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
catch (err) {
|
|
280
|
+
this.logger.warn('failed to send hist_sync receipt', {
|
|
281
|
+
id: peerStanzaId,
|
|
282
|
+
to: peerRemoteJid,
|
|
283
|
+
message: (0, primitives_1.toError)(err).message
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
: undefined
|
|
288
|
+
}, protocolMessage.historySyncNotification);
|
|
201
289
|
}
|
|
202
290
|
return;
|
|
203
291
|
}
|
|
204
292
|
if (SYNC_RELATED_PROTOCOL_TYPES.has(protocolType)) {
|
|
205
293
|
this.logger.info('incoming sync-related protocol message', {
|
|
206
|
-
id: event.
|
|
207
|
-
from: event.
|
|
294
|
+
id: event.key.id,
|
|
295
|
+
from: event.key.remoteJid,
|
|
208
296
|
protocolType
|
|
209
297
|
});
|
|
210
298
|
return;
|
|
211
299
|
}
|
|
212
300
|
this.logger.debug('incoming protocol message received', {
|
|
213
|
-
id: event.
|
|
214
|
-
from: event.
|
|
301
|
+
id: event.key.id,
|
|
302
|
+
from: event.key.remoteJid,
|
|
215
303
|
protocolType
|
|
216
304
|
});
|
|
217
305
|
}
|
|
@@ -219,189 +307,60 @@ class WaClient extends node_events_1.EventEmitter {
|
|
|
219
307
|
this.leaveIncomingHandler();
|
|
220
308
|
}
|
|
221
309
|
}
|
|
222
|
-
async handleIncomingAppStateSyncKeyShare(event, protocolMessage) {
|
|
223
|
-
const share = protocolMessage.appStateSyncKeyShare;
|
|
224
|
-
if (!share) {
|
|
225
|
-
this.logger.warn('incoming app-state key share protocol message without payload', {
|
|
226
|
-
id: event.stanzaId,
|
|
227
|
-
from: event.chatJid
|
|
228
|
-
});
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
try {
|
|
232
|
-
const imported = await this.appStateSync.importSyncKeyShare(share);
|
|
233
|
-
this.logger.info('imported app-state sync key share from protocol message', {
|
|
234
|
-
id: event.stanzaId,
|
|
235
|
-
from: event.chatJid,
|
|
236
|
-
imported
|
|
237
|
-
});
|
|
238
|
-
if (imported > 0) {
|
|
239
|
-
void this.syncAppState().catch((error) => {
|
|
240
|
-
this.logger.warn('failed to sync app-state after key share import', {
|
|
241
|
-
id: event.stanzaId,
|
|
242
|
-
from: event.chatJid,
|
|
243
|
-
message: (0, primitives_1.toError)(error).message
|
|
244
|
-
});
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
catch (error) {
|
|
249
|
-
this.logger.warn('failed to import app-state sync key share from protocol message', {
|
|
250
|
-
id: event.stanzaId,
|
|
251
|
-
from: event.chatJid,
|
|
252
|
-
message: (0, primitives_1.toError)(error).message
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
async handleIncomingAppStateSyncKeyRequest(event, protocolMessage) {
|
|
257
|
-
const request = protocolMessage.appStateSyncKeyRequest;
|
|
258
|
-
if (!request) {
|
|
259
|
-
this.logger.warn('incoming app-state key request protocol message without payload', {
|
|
260
|
-
id: event.stanzaId,
|
|
261
|
-
from: event.chatJid
|
|
262
|
-
});
|
|
263
|
-
return;
|
|
264
|
-
}
|
|
265
|
-
const requesterRaw = event.senderJid ?? event.chatJid;
|
|
266
|
-
if (!requesterRaw) {
|
|
267
|
-
this.logger.warn('incoming app-state key request missing sender jid', {
|
|
268
|
-
id: event.stanzaId
|
|
269
|
-
});
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
let requesterDeviceJid;
|
|
273
|
-
try {
|
|
274
|
-
requesterDeviceJid = (0, jid_1.normalizeDeviceJid)(requesterRaw);
|
|
275
|
-
}
|
|
276
|
-
catch (error) {
|
|
277
|
-
this.logger.warn('incoming app-state key request has malformed sender jid', {
|
|
278
|
-
id: event.stanzaId,
|
|
279
|
-
from: requesterRaw,
|
|
280
|
-
message: (0, primitives_1.toError)(error).message
|
|
281
|
-
});
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
if (!this.isOwnAccountDeviceJid(requesterDeviceJid)) {
|
|
285
|
-
this.logger.warn('incoming app-state key request ignored: sender is not own account', {
|
|
286
|
-
id: event.stanzaId,
|
|
287
|
-
from: requesterDeviceJid
|
|
288
|
-
});
|
|
289
|
-
return;
|
|
290
|
-
}
|
|
291
|
-
const requestedKeyIds = this.extractAppStateSyncKeyRequestIds(request);
|
|
292
|
-
if (requestedKeyIds.length === 0) {
|
|
293
|
-
this.logger.warn('incoming app-state key request has no valid key ids', {
|
|
294
|
-
id: event.stanzaId,
|
|
295
|
-
from: requesterDeviceJid
|
|
296
|
-
});
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
const requestedKeys = await this.appStateStore.getSyncKeysBatch(requestedKeyIds);
|
|
300
|
-
const availableKeys = [];
|
|
301
|
-
const missingKeyIds = [];
|
|
302
|
-
for (let i = 0; i < requestedKeys.length; i += 1) {
|
|
303
|
-
const key = requestedKeys[i];
|
|
304
|
-
if (key !== null) {
|
|
305
|
-
availableKeys.push(key);
|
|
306
|
-
}
|
|
307
|
-
else {
|
|
308
|
-
missingKeyIds.push(requestedKeyIds[i]);
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
try {
|
|
312
|
-
await this.messageDispatch.sendAppStateSyncKeyShare(requesterDeviceJid, availableKeys, missingKeyIds);
|
|
313
|
-
this.logger.info('responded to app-state key request', {
|
|
314
|
-
id: event.stanzaId,
|
|
315
|
-
to: requesterDeviceJid,
|
|
316
|
-
requested: requestedKeyIds.length,
|
|
317
|
-
shared: availableKeys.length,
|
|
318
|
-
missing: missingKeyIds.length
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
catch (error) {
|
|
322
|
-
this.logger.warn('failed to respond to app-state key request', {
|
|
323
|
-
id: event.stanzaId,
|
|
324
|
-
to: requesterDeviceJid,
|
|
325
|
-
requested: requestedKeyIds.length,
|
|
326
|
-
shared: availableKeys.length,
|
|
327
|
-
missing: missingKeyIds.length,
|
|
328
|
-
message: (0, primitives_1.toError)(error).message
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
extractAppStateSyncKeyRequestIds(request) {
|
|
333
|
-
const deduped = new Map();
|
|
334
|
-
for (const key of request.keyIds ?? []) {
|
|
335
|
-
try {
|
|
336
|
-
const keyId = (0, bytes_1.decodeProtoBytes)(key.keyId, 'appStateSyncKeyRequest.keyIds[].keyId');
|
|
337
|
-
const keyHex = (0, bytes_1.bytesToHex)(keyId);
|
|
338
|
-
if (deduped.has(keyHex)) {
|
|
339
|
-
continue;
|
|
340
|
-
}
|
|
341
|
-
deduped.set(keyHex, keyId);
|
|
342
|
-
}
|
|
343
|
-
catch (error) {
|
|
344
|
-
this.logger.trace('ignoring malformed app-state key id request entry', {
|
|
345
|
-
message: (0, primitives_1.toError)(error).message
|
|
346
|
-
});
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
return [...deduped.values()];
|
|
350
|
-
}
|
|
351
|
-
isOwnAccountDeviceJid(candidateJid) {
|
|
352
|
-
const credentials = this.authClient.getCurrentCredentials();
|
|
353
|
-
if (!credentials) {
|
|
354
|
-
return false;
|
|
355
|
-
}
|
|
356
|
-
const candidateUser = (0, jid_1.toUserJid)(candidateJid);
|
|
357
|
-
return ((!!credentials.meJid && (0, jid_1.toUserJid)(credentials.meJid) === candidateUser) ||
|
|
358
|
-
(!!credentials.meLid && (0, jid_1.toUserJid)(credentials.meLid) === candidateUser));
|
|
359
|
-
}
|
|
360
|
-
async handleHistorySyncNotification(notification) {
|
|
361
|
-
try {
|
|
362
|
-
await (0, history_sync_1.processHistorySyncNotification)({
|
|
363
|
-
logger: this.logger,
|
|
364
|
-
mediaTransfer: this.mediaTransfer,
|
|
365
|
-
writeBehind: this.writeBehind,
|
|
366
|
-
emitEvent: this.emit.bind(this),
|
|
367
|
-
onPrivacyTokens: (conversations) => this.trustedContactToken.hydrateFromHistorySync(conversations),
|
|
368
|
-
onNctSalt: (salt) => this.trustedContactToken.hydrateNctSaltFromHistorySync(salt)
|
|
369
|
-
}, notification);
|
|
370
|
-
}
|
|
371
|
-
catch (error) {
|
|
372
|
-
this.logger.warn('failed to process history sync notification', {
|
|
373
|
-
syncType: notification.syncType,
|
|
374
|
-
chunkOrder: notification.chunkOrder,
|
|
375
|
-
message: (0, primitives_1.toError)(error).message
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
310
|
async queryWithContext(context, node, timeoutMs = this.options.iqTimeoutMs ?? constants_1.WA_DEFAULTS.IQ_TIMEOUT_MS, contextData = {}, options = {}) {
|
|
380
|
-
return (0, query_1.queryWithContext)(async (queryNode, queryTimeoutMs) => this.query(queryNode, queryTimeoutMs, options), this.logger, context, node, timeoutMs, contextData);
|
|
311
|
+
return (0, query_1.queryWithContext)(async (queryNode, queryTimeoutMs) => this.deps.lowLevelCoordinator.query(queryNode, queryTimeoutMs, options), this.logger, context, node, timeoutMs, contextData);
|
|
381
312
|
}
|
|
382
313
|
async handleIncomingFrame(frame) {
|
|
383
314
|
try {
|
|
384
|
-
await this.nodeTransport.dispatchIncomingFrame(frame, async (node) => this.incomingNode.handleIncomingNode(node));
|
|
315
|
+
await this.deps.nodeTransport.dispatchIncomingFrame(frame, async (node) => this.deps.incomingNode.handleIncomingNode(node));
|
|
385
316
|
}
|
|
386
317
|
catch (error) {
|
|
387
318
|
this.handleError((0, primitives_1.toError)(error));
|
|
388
319
|
}
|
|
389
320
|
}
|
|
321
|
+
/**
|
|
322
|
+
* Opens the transport and runs the noise/auth handshake. If a connection
|
|
323
|
+
* is already in flight, the in-flight promise is reused. Resolves once the
|
|
324
|
+
* client is fully ready; pairing prompts are surfaced via the `auth_qr`
|
|
325
|
+
* and `auth_pairing_code` events while this awaits.
|
|
326
|
+
*
|
|
327
|
+
* **First-time pairing:** the promise stays pending until the user scans a
|
|
328
|
+
* QR or types the pairing code. Subscribe to `auth_qr` / `auth_pairing_code`
|
|
329
|
+
* *before* awaiting – they fire while `connect()` is still running.
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
* ```ts
|
|
333
|
+
* // QR pairing (default – works headless)
|
|
334
|
+
* client.on('auth_qr', ({ qr }) => console.log('scan:', qr))
|
|
335
|
+
* client.on('auth_paired', ({ credentials }) => console.log('paired:', credentials.meJid))
|
|
336
|
+
* await client.connect()
|
|
337
|
+
*
|
|
338
|
+
* // Link-code pairing – call requestPairingCode while connect() is running
|
|
339
|
+
* void client.connect()
|
|
340
|
+
* await new Promise((r) => client.once('auth_pairing_required', r))
|
|
341
|
+
* const code = await client.auth.requestPairingCode('5511999999999')
|
|
342
|
+
* console.log('enter code on phone:', code)
|
|
343
|
+
* ```
|
|
344
|
+
*/
|
|
390
345
|
async connect() {
|
|
391
346
|
if (this.connectPromise) {
|
|
392
347
|
this.logger.trace('wa client connect already in-flight');
|
|
393
348
|
return this.connectPromise;
|
|
394
349
|
}
|
|
350
|
+
this.writeBehind.restart();
|
|
395
351
|
this.acceptingIncomingEvents = true;
|
|
396
|
-
this.connectPromise = this.connectionManager
|
|
352
|
+
this.connectPromise = this.deps.connectionManager
|
|
397
353
|
.connect((frame) => this.handleIncomingFrame(frame))
|
|
398
354
|
.then(() => {
|
|
355
|
+
if (!this.deps.authClient.getCurrentCredentials()?.meJid) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
399
358
|
this.emit('connection', {
|
|
400
359
|
status: 'open',
|
|
401
360
|
reason: 'connected',
|
|
402
361
|
code: null,
|
|
403
362
|
isLogout: false,
|
|
404
|
-
isNewLogin:
|
|
363
|
+
isNewLogin: false
|
|
405
364
|
});
|
|
406
365
|
})
|
|
407
366
|
.finally(() => {
|
|
@@ -409,6 +368,14 @@ class WaClient extends node_events_1.EventEmitter {
|
|
|
409
368
|
});
|
|
410
369
|
return this.connectPromise;
|
|
411
370
|
}
|
|
371
|
+
/**
|
|
372
|
+
* Closes the transport gracefully: pauses incoming events, flushes the
|
|
373
|
+
* write-behind persistence queue, and emits a `connection` close event
|
|
374
|
+
* with reason `client_disconnected`. Does not clear stored credentials -
|
|
375
|
+
* call {@link connect} again to resume the same session. There is no
|
|
376
|
+
* built-in auto-reconnect; subscribe to `connection: { status: 'close' }`
|
|
377
|
+
* and decide your own backoff.
|
|
378
|
+
*/
|
|
412
379
|
async disconnect() {
|
|
413
380
|
await this.pauseIncomingEventsAndWaitDrain();
|
|
414
381
|
const writeBehindFlush = await this.writeBehind.flush(this.options.writeBehind?.flushTimeoutMs);
|
|
@@ -417,7 +384,7 @@ class WaClient extends node_events_1.EventEmitter {
|
|
|
417
384
|
remaining: writeBehindFlush.remaining
|
|
418
385
|
});
|
|
419
386
|
}
|
|
420
|
-
await this.connectionManager.disconnect();
|
|
387
|
+
await this.deps.connectionManager.disconnect();
|
|
421
388
|
this.emit('connection', {
|
|
422
389
|
status: 'close',
|
|
423
390
|
reason: 'client_disconnected',
|
|
@@ -426,65 +393,112 @@ class WaClient extends node_events_1.EventEmitter {
|
|
|
426
393
|
isNewLogin: false
|
|
427
394
|
});
|
|
428
395
|
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
396
|
+
/**
|
|
397
|
+
* Drops matching inbound stanzas before any handler runs. Server still
|
|
398
|
+
* gets the ack so it stops re-delivering. Returns an `unregister` function.
|
|
399
|
+
*
|
|
400
|
+
* Accepts either a declarative descriptor or a predicate. The descriptor
|
|
401
|
+
* matches by `remoteJid`/`fromMe`/`id`/`participant` (PN ↔ LID alt-attrs
|
|
402
|
+
* resolved automatically) and throws when no match field is given or
|
|
403
|
+
* arrays are empty. The predicate receives a parsed
|
|
404
|
+
* {@link WaIgnoreKeyContext} and returns `true` to drop the stanza.
|
|
405
|
+
*
|
|
406
|
+
* @example
|
|
407
|
+
* ```ts
|
|
408
|
+
* client.ignoreKey({ remoteJid: spammerJid })
|
|
409
|
+
* client.ignoreKey({ fromMe: true, only: ['message'] })
|
|
410
|
+
* client.ignoreKey((m) => m.kind === 'message' && isGroupJid(m.remoteJid ?? ''))
|
|
411
|
+
* ```
|
|
412
|
+
*/
|
|
413
|
+
ignoreKey(input) {
|
|
414
|
+
if (typeof input !== 'function') {
|
|
415
|
+
(0, ignore_key_1.validateIgnoreKey)(input);
|
|
416
|
+
}
|
|
417
|
+
const filter = (0, ignore_key_1.createIgnoreKeyFilter)(input, () => this.deps.authClient.getCurrentCredentials()?.meJid);
|
|
418
|
+
return this.deps.incomingNode.registerIncomingStanzaFilter(filter);
|
|
419
|
+
}
|
|
420
|
+
/** Auth client: pairing, credentials, registration state. */
|
|
421
|
+
get auth() {
|
|
422
|
+
return this.deps.authClient;
|
|
423
|
+
}
|
|
424
|
+
/** Message coordinator: send/receive, receipts, addons, media download. */
|
|
425
|
+
get message() {
|
|
426
|
+
return this.deps.messageCoordinator;
|
|
427
|
+
}
|
|
428
|
+
/** Presence coordinator: own/peer presence subscriptions. */
|
|
429
|
+
get presence() {
|
|
430
|
+
return this.deps.presenceCoordinator;
|
|
431
|
+
}
|
|
432
|
+
/** Low-level coordinator: raw node send/query escape hatch. */
|
|
433
|
+
get lowlevel() {
|
|
434
|
+
return this.deps.lowLevelCoordinator;
|
|
435
|
+
}
|
|
436
|
+
/** App-state mutation coordinator: chat-side settings (mute, pin, etc.). */
|
|
437
|
+
get chat() {
|
|
438
|
+
return this.deps.chatCoordinator;
|
|
435
439
|
}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
}
|
|
440
|
-
this.logger.trace('wa client fetch pairing country code iso');
|
|
441
|
-
return this.authClient.fetchPairingCountryCodeIso();
|
|
440
|
+
/** Group coordinator: create/query/manage WhatsApp groups and communities. */
|
|
441
|
+
get group() {
|
|
442
|
+
return this.deps.groupCoordinator;
|
|
442
443
|
}
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
}
|
|
447
|
-
const normalizedPhoneJids = new Array(phoneNumbers.length);
|
|
448
|
-
for (let index = 0; index < phoneNumbers.length; index += 1) {
|
|
449
|
-
normalizedPhoneJids[index] = (0, jid_1.parsePhoneJid)(phoneNumbers[index]);
|
|
450
|
-
}
|
|
451
|
-
this.logger.trace('wa client query lids by phone numbers', {
|
|
452
|
-
phones: normalizedPhoneJids.length
|
|
453
|
-
});
|
|
454
|
-
return this.signalDeviceSync.queryLidsByPhoneJids(normalizedPhoneJids);
|
|
455
|
-
}
|
|
456
|
-
sendMessage(to, content, options = {}) {
|
|
457
|
-
return this.messageDispatch.sendMessage(to, content, options);
|
|
458
|
-
}
|
|
459
|
-
async syncSignalSession(jid, reasonIdentity = false) {
|
|
460
|
-
await this.messageDispatch.syncSignalSession(jid, reasonIdentity);
|
|
461
|
-
if (reasonIdentity) {
|
|
462
|
-
this.trustedContactToken.reissueOnIdentityChange(jid).catch((err) => this.logger.warn('tc token reissue on identity change failed', {
|
|
463
|
-
jid,
|
|
464
|
-
message: (0, primitives_1.toError)(err).message
|
|
465
|
-
}));
|
|
466
|
-
}
|
|
444
|
+
/** Status coordinator: status broadcast send and reactions. */
|
|
445
|
+
get status() {
|
|
446
|
+
return this.deps.statusCoordinator;
|
|
467
447
|
}
|
|
468
|
-
|
|
469
|
-
|
|
448
|
+
/**
|
|
449
|
+
* Broadcast-list coordinator: list management and broadcast sends.
|
|
450
|
+
* **Business-only** - the underlying app-state schema rejects regular
|
|
451
|
+
* accounts. See {@link WaBroadcastListCoordinator}.
|
|
452
|
+
*/
|
|
453
|
+
get broadcastList() {
|
|
454
|
+
return this.deps.broadcastListCoordinator;
|
|
470
455
|
}
|
|
471
|
-
|
|
472
|
-
|
|
456
|
+
/** Newsletter coordinator: create/query/follow/admin/send for channels. */
|
|
457
|
+
get newsletter() {
|
|
458
|
+
return this.deps.newsletterCoordinator;
|
|
473
459
|
}
|
|
460
|
+
/** Privacy coordinator: privacy categories, blocklist, disallowed list. */
|
|
474
461
|
get privacy() {
|
|
475
|
-
return this.privacyCoordinator;
|
|
462
|
+
return this.deps.privacyCoordinator;
|
|
476
463
|
}
|
|
464
|
+
/** Profile coordinator: own/peer profile fields (picture, status, username). */
|
|
477
465
|
get profile() {
|
|
478
|
-
return this.profileCoordinator;
|
|
479
|
-
}
|
|
466
|
+
return this.deps.profileCoordinator;
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Business coordinator: business profile, verified-name lookups. Reads
|
|
470
|
+
* work from any account; **writes (`editBusinessProfile`,
|
|
471
|
+
* `updateCoverPhoto`, `deleteCoverPhoto`) are business-only** and throw
|
|
472
|
+
* on regular accounts. See {@link WaBusinessCoordinator}.
|
|
473
|
+
*/
|
|
480
474
|
get business() {
|
|
481
|
-
return this.businessCoordinator;
|
|
475
|
+
return this.deps.businessCoordinator;
|
|
482
476
|
}
|
|
483
|
-
|
|
484
|
-
|
|
477
|
+
/** Bot coordinator: Meta-AI bot profiles, prompt/chunk decryption. */
|
|
478
|
+
get bot() {
|
|
479
|
+
return this.deps.botCoordinator;
|
|
485
480
|
}
|
|
481
|
+
/**
|
|
482
|
+
* Email coordinator: bind/unbind/verify email on the account.
|
|
483
|
+
* **Mobile-only** - every method throws unless the client is connected
|
|
484
|
+
* via `options.mobileTransport`. See {@link WaEmailCoordinator}.
|
|
485
|
+
*/
|
|
486
|
+
get email() {
|
|
487
|
+
return this.deps.emailCoordinator;
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Unpairs this companion device by removing it server-side. Requires an
|
|
491
|
+
* authenticated session; throws when no `meJid` is present.
|
|
492
|
+
*
|
|
493
|
+
* **Does not** disconnect the socket or clear local stores by itself -
|
|
494
|
+
* the server initiates the close after accepting the IQ, which surfaces
|
|
495
|
+
* via a `connection` event with `isLogout: true`. That close handler is
|
|
496
|
+
* what wipes the persisted state, honoring `options.logoutStoreClear`.
|
|
497
|
+
* The {@link WaClient} instance is single-shot after logout: create a
|
|
498
|
+
* fresh one (with a fresh `sessionId` or pre-cleared store) to re-pair.
|
|
499
|
+
*/
|
|
486
500
|
async logout(reason = stream_1.WA_LOGOUT_REASONS.USER_INITIATED) {
|
|
487
|
-
const meJid = this.authClient.getCurrentCredentials()?.meJid;
|
|
501
|
+
const meJid = this.deps.authClient.getCurrentCredentials()?.meJid;
|
|
488
502
|
if (!meJid) {
|
|
489
503
|
throw new Error('cannot logout: client is not authenticated');
|
|
490
504
|
}
|
|
@@ -496,201 +510,56 @@ class WaClient extends node_events_1.EventEmitter {
|
|
|
496
510
|
});
|
|
497
511
|
(0, query_1.assertIqResult)(result, 'client.logout');
|
|
498
512
|
}
|
|
499
|
-
sendReceipt(input) {
|
|
500
|
-
return this.messageDispatch.sendReceipt(input);
|
|
501
|
-
}
|
|
502
|
-
flushAppStateMutations() {
|
|
503
|
-
return this.chatCoordinator.flushMutations();
|
|
504
|
-
}
|
|
505
|
-
flushWriteBehind(timeoutMs) {
|
|
506
|
-
return this.writeBehind.flush(timeoutMs);
|
|
507
|
-
}
|
|
508
|
-
async exportAppState() {
|
|
509
|
-
return this.appStateSync.exportState();
|
|
510
|
-
}
|
|
511
|
-
async syncAppState(options = {}) {
|
|
512
|
-
if (!this.connectionManager.isConnected()) {
|
|
513
|
-
throw new Error('client is not connected');
|
|
514
|
-
}
|
|
515
|
-
const syncResult = await this.executeAppStateSync(options);
|
|
516
|
-
const blockedCollections = this.getBlockedAppStateCollections(syncResult);
|
|
517
|
-
if (blockedCollections.length > 0) {
|
|
518
|
-
this.logger.warn('app-state sync has blocked collections', {
|
|
519
|
-
blockedCollections: blockedCollections.join(',')
|
|
520
|
-
});
|
|
521
|
-
}
|
|
522
|
-
this.emitChatEventsFromAppStateSyncResult(syncResult);
|
|
523
|
-
return syncResult;
|
|
524
|
-
}
|
|
525
|
-
async executeAppStateSync(options) {
|
|
526
|
-
return options.downloadExternalBlob
|
|
527
|
-
? this.appStateSync.sync(options)
|
|
528
|
-
: this.appStateSync.sync({
|
|
529
|
-
...options,
|
|
530
|
-
downloadExternalBlob: async (_collection, _kind, reference) => (0, utils_1.downloadExternalBlobReference)(this.mediaTransfer, reference)
|
|
531
|
-
});
|
|
532
|
-
}
|
|
533
|
-
getBlockedAppStateCollections(syncResult) {
|
|
534
|
-
const blocked = [];
|
|
535
|
-
for (const entry of syncResult.collections) {
|
|
536
|
-
if (entry.state === constants_1.WA_APP_STATE_COLLECTION_STATES.BLOCKED) {
|
|
537
|
-
blocked.push(entry.collection);
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
return blocked;
|
|
541
|
-
}
|
|
542
|
-
emitChatEventsFromAppStateSyncResult(syncResult) {
|
|
543
|
-
const shouldEmitSnapshotMutations = this.options.chatEvents?.emitSnapshotMutations === true;
|
|
544
|
-
for (const collectionResult of syncResult.collections) {
|
|
545
|
-
const mutations = collectionResult.mutations ?? [];
|
|
546
|
-
const lastMutationIndexByKey = new Map();
|
|
547
|
-
for (let mutationIndex = 0; mutationIndex < mutations.length; mutationIndex += 1) {
|
|
548
|
-
const mutation = mutations[mutationIndex];
|
|
549
|
-
if (!shouldEmitSnapshotMutations && mutation.source === 'snapshot') {
|
|
550
|
-
continue;
|
|
551
|
-
}
|
|
552
|
-
lastMutationIndexByKey.set(`${mutation.collection}\u0001${mutation.index}`, mutationIndex);
|
|
553
|
-
}
|
|
554
|
-
for (let mutationIndex = 0; mutationIndex < mutations.length; mutationIndex += 1) {
|
|
555
|
-
const mutation = mutations[mutationIndex];
|
|
556
|
-
if (!shouldEmitSnapshotMutations && mutation.source === 'snapshot') {
|
|
557
|
-
continue;
|
|
558
|
-
}
|
|
559
|
-
const coalesceKey = `${mutation.collection}\u0001${mutation.index}`;
|
|
560
|
-
if (lastMutationIndexByKey.get(coalesceKey) !== mutationIndex) {
|
|
561
|
-
continue;
|
|
562
|
-
}
|
|
563
|
-
try {
|
|
564
|
-
this.handleNctSaltMutation(mutation);
|
|
565
|
-
const event = (0, chat_1.parseChatEventFromAppStateMutation)(mutation);
|
|
566
|
-
if (!event) {
|
|
567
|
-
continue;
|
|
568
|
-
}
|
|
569
|
-
this.emit('chat_event', event);
|
|
570
|
-
}
|
|
571
|
-
catch (error) {
|
|
572
|
-
this.logger.debug('failed to parse chat event from app-state mutation', {
|
|
573
|
-
collection: mutation.collection,
|
|
574
|
-
source: mutation.source,
|
|
575
|
-
index: mutation.index,
|
|
576
|
-
message: (0, primitives_1.toError)(error).message
|
|
577
|
-
});
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
handleNctSaltMutation(mutation) {
|
|
583
|
-
const nctAction = mutation.value?.nctSaltSyncAction;
|
|
584
|
-
if (!nctAction) {
|
|
585
|
-
return;
|
|
586
|
-
}
|
|
587
|
-
if (mutation.operation === 'set' && nctAction.salt) {
|
|
588
|
-
this.trustedContactToken.handleNctSaltSync(nctAction.salt).catch((err) => this.logger.warn('nct salt sync set failed', {
|
|
589
|
-
message: (0, primitives_1.toError)(err).message
|
|
590
|
-
}));
|
|
591
|
-
}
|
|
592
|
-
else if (mutation.operation === 'remove') {
|
|
593
|
-
this.trustedContactToken.handleNctSaltSync(null).catch((err) => this.logger.warn('nct salt sync remove failed', {
|
|
594
|
-
message: (0, primitives_1.toError)(err).message
|
|
595
|
-
}));
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
513
|
async clearStoredState() {
|
|
599
514
|
await this.pauseIncomingEventsAndWaitDrain();
|
|
600
515
|
const writeBehindDestroy = await this.writeBehind.destroy(this.options.writeBehind?.flushTimeoutMs);
|
|
601
516
|
if (writeBehindDestroy.remaining > 0) {
|
|
602
517
|
throw new Error(`clear stored state aborted: write-behind did not fully drain (remaining=${writeBehindDestroy.remaining})`);
|
|
603
518
|
}
|
|
604
|
-
const danglingReceipts = this.receiptQueue.take();
|
|
519
|
+
const danglingReceipts = this.deps.receiptQueue.take();
|
|
605
520
|
if (danglingReceipts.length > 0) {
|
|
606
521
|
this.logger.debug('cleared dangling receipts while clearing stored state', {
|
|
607
522
|
count: danglingReceipts.length
|
|
608
523
|
});
|
|
609
524
|
}
|
|
610
525
|
const s = this.options.logoutStoreClear;
|
|
611
|
-
const
|
|
526
|
+
const isMailbox = (key) => key === 'messages' || key === 'threads' || key === 'contacts';
|
|
527
|
+
const shouldClear = (key) => {
|
|
528
|
+
const explicit = s?.[key];
|
|
529
|
+
if (explicit !== undefined)
|
|
530
|
+
return explicit;
|
|
531
|
+
return !isMailbox(key);
|
|
532
|
+
};
|
|
612
533
|
if (shouldClear('auth'))
|
|
613
|
-
await this.authClient.clearStoredCredentials();
|
|
534
|
+
await this.deps.authClient.clearStoredCredentials();
|
|
614
535
|
if (shouldClear('appState'))
|
|
615
|
-
await this.
|
|
536
|
+
await this.stores.appState.clear();
|
|
616
537
|
if (shouldClear('contacts'))
|
|
617
|
-
await this.
|
|
538
|
+
await this.stores.contacts.clear();
|
|
618
539
|
if (shouldClear('messages'))
|
|
619
|
-
await this.
|
|
540
|
+
await this.stores.messages.clear();
|
|
620
541
|
if (shouldClear('messageSecret'))
|
|
621
|
-
await this.
|
|
622
|
-
if (shouldClear('
|
|
623
|
-
await this.
|
|
542
|
+
await this.stores.messageSecret.clear();
|
|
543
|
+
if (shouldClear('groupMetadata'))
|
|
544
|
+
await this.stores.groupMetadata.clear();
|
|
624
545
|
if (shouldClear('deviceList'))
|
|
625
|
-
await this.
|
|
546
|
+
await this.stores.deviceList.clear();
|
|
626
547
|
if (shouldClear('retry'))
|
|
627
|
-
await this.
|
|
548
|
+
await this.stores.retry.clear();
|
|
628
549
|
if (shouldClear('signal'))
|
|
629
|
-
await this.
|
|
550
|
+
await this.stores.signal.clear();
|
|
630
551
|
if (shouldClear('preKey'))
|
|
631
|
-
await this.
|
|
552
|
+
await this.stores.preKey.clear();
|
|
632
553
|
if (shouldClear('session'))
|
|
633
|
-
await this.
|
|
554
|
+
await this.stores.session.clear();
|
|
634
555
|
if (shouldClear('identity'))
|
|
635
|
-
await this.
|
|
556
|
+
await this.stores.identity.clear();
|
|
636
557
|
if (shouldClear('senderKey'))
|
|
637
|
-
await this.
|
|
558
|
+
await this.stores.senderKey.clear();
|
|
638
559
|
if (shouldClear('threads'))
|
|
639
|
-
await this.
|
|
560
|
+
await this.stores.threads.clear();
|
|
640
561
|
if (shouldClear('privacyToken'))
|
|
641
|
-
await this.
|
|
642
|
-
}
|
|
643
|
-
async tryDecryptAddon(event) {
|
|
644
|
-
const message = event.message;
|
|
645
|
-
if (!message)
|
|
646
|
-
return;
|
|
647
|
-
const addon = (0, addon_crypto_1.identifyEncryptedAddon)(message);
|
|
648
|
-
if (!addon)
|
|
649
|
-
return;
|
|
650
|
-
const targetMessageId = addon.targetMessageKey.id;
|
|
651
|
-
if (!targetMessageId)
|
|
652
|
-
return;
|
|
653
|
-
const parentEntry = await (0, addon_crypto_1.resolveParentMessageSecret)(targetMessageId, this.messageSecretStore, this.messageStore);
|
|
654
|
-
if (!parentEntry) {
|
|
655
|
-
this.logger.debug('addon parent message secret not found', {
|
|
656
|
-
id: event.stanzaId,
|
|
657
|
-
targetId: targetMessageId
|
|
658
|
-
});
|
|
659
|
-
return;
|
|
660
|
-
}
|
|
661
|
-
const parentMsgOriginalSender = parentEntry.senderJid;
|
|
662
|
-
const modificationSender = event.senderJid ?? '';
|
|
663
|
-
const plaintext = await (0, addon_crypto_1.decryptAddonPayload)({
|
|
664
|
-
messageSecret: parentEntry.secret,
|
|
665
|
-
stanzaId: targetMessageId,
|
|
666
|
-
parentMsgOriginalSender,
|
|
667
|
-
modificationSender,
|
|
668
|
-
modificationType: addon.modificationType,
|
|
669
|
-
ciphertext: addon.encPayload,
|
|
670
|
-
iv: addon.encIv,
|
|
671
|
-
additionalData: (0, addon_crypto_1.shouldUseAddonAdditionalData)(addon.modificationType)
|
|
672
|
-
? (0, addon_crypto_1.buildAddonAdditionalData)(targetMessageId, modificationSender)
|
|
673
|
-
: undefined
|
|
674
|
-
});
|
|
675
|
-
let decrypted = (0, addon_crypto_1.decodeAddonPlaintext)(addon.kind, plaintext);
|
|
676
|
-
if (decrypted.kind === 'poll_vote' && decrypted.pollVote.selectedOptions) {
|
|
677
|
-
const names = await (0, addon_crypto_1.resolvePollOptionNames)(decrypted.pollVote.selectedOptions, targetMessageId, this.messageStore);
|
|
678
|
-
if (names) {
|
|
679
|
-
decrypted = { ...decrypted, selectedOptionNames: names };
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
const addonEvent = {
|
|
683
|
-
rawNode: event.rawNode,
|
|
684
|
-
stanzaId: event.stanzaId,
|
|
685
|
-
chatJid: event.chatJid,
|
|
686
|
-
stanzaType: event.stanzaType,
|
|
687
|
-
kind: addon.kind,
|
|
688
|
-
targetMessageId,
|
|
689
|
-
senderJid: modificationSender,
|
|
690
|
-
decrypted,
|
|
691
|
-
raw: message
|
|
692
|
-
};
|
|
693
|
-
this.emit('message_addon', addonEvent);
|
|
562
|
+
await this.stores.privacyToken.clear();
|
|
694
563
|
}
|
|
695
564
|
tryEnterIncomingHandler() {
|
|
696
565
|
if (!this.acceptingIncomingEvents) {
|
|
@@ -734,7 +603,7 @@ class WaClient extends node_events_1.EventEmitter {
|
|
|
734
603
|
}
|
|
735
604
|
handleError(error) {
|
|
736
605
|
this.logger.error('wa client error', { message: error.message });
|
|
737
|
-
this.emit('
|
|
606
|
+
this.emit('debug_client_error', { error });
|
|
738
607
|
}
|
|
739
608
|
}
|
|
740
609
|
exports.WaClient = WaClient;
|