zapo-js 0.2.0 → 0.3.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/README.md +7 -3
- package/dist/appstate/WaAppStateCrypto.js +49 -41
- package/dist/appstate/WaAppStateSyncClient.js +79 -42
- package/dist/appstate/index.js +2 -2
- package/dist/auth/WaAuthClient.js +20 -11
- package/dist/auth/{flow/WaAuthCredentialsFlow.js → credentials-flow.js} +83 -18
- package/dist/auth/pairing/WaPairingFlow.js +26 -29
- package/dist/auth/pairing/{WaPairingCodeCrypto.js → pairing-code-crypto.js} +29 -13
- package/dist/client/WaClient.js +115 -75
- package/dist/client/WaClientFactory.js +113 -30
- package/dist/client/connection/WaConnectionManager.js +4 -1
- package/dist/client/coordinators/WaAbPropsCoordinator.js +141 -0
- package/dist/client/coordinators/WaBusinessCoordinator.js +3 -12
- package/dist/client/coordinators/WaEmailCoordinator.js +63 -0
- package/dist/client/coordinators/WaIncomingNodeCoordinator.js +33 -8
- package/dist/client/coordinators/WaMessageDispatchCoordinator.js +55 -25
- package/dist/client/coordinators/WaOfflineResumeCoordinator.js +114 -0
- package/dist/client/coordinators/WaPassiveTasksCoordinator.js +38 -20
- package/dist/client/coordinators/WaProfileCoordinator.js +3 -1
- package/dist/client/coordinators/WaRetryCoordinator.js +11 -9
- package/dist/client/coordinators/WaTrustedContactTokenCoordinator.js +22 -4
- package/dist/client/dirty.js +1 -1
- package/dist/client/events/abprops.js +43 -0
- package/dist/client/events/privacy-token.js +1 -2
- package/dist/client/events/registration.js +42 -0
- package/dist/client/incoming.js +37 -0
- package/dist/client/mailbox.js +17 -1
- package/dist/client/media.js +243 -0
- package/dist/client/messages.js +163 -86
- package/dist/crypto/core/index.js +4 -1
- package/dist/crypto/core/random.js +3 -9
- package/dist/crypto/core/xeddsa.js +57 -0
- package/dist/crypto/curves/X25519.js +18 -0
- package/dist/crypto/curves/constants.js +2 -1
- package/dist/esm/appstate/WaAppStateCrypto.js +39 -31
- package/dist/esm/appstate/WaAppStateSyncClient.js +68 -31
- package/dist/esm/appstate/index.js +1 -1
- package/dist/esm/appstate/{WaAppStateSyncResponseParser.js → response-parser.js} +1 -1
- package/dist/esm/auth/WaAuthClient.js +17 -8
- package/dist/esm/auth/{flow/WaAuthCredentialsFlow.js → credentials-flow.js} +83 -18
- package/dist/esm/auth/pairing/WaPairingFlow.js +25 -28
- package/dist/esm/auth/pairing/{WaPairingCodeCrypto.js → pairing-code-crypto.js} +20 -6
- package/dist/esm/client/WaClient.js +116 -76
- package/dist/esm/client/WaClientFactory.js +114 -31
- package/dist/esm/client/connection/WaConnectionManager.js +4 -1
- package/dist/esm/client/coordinators/WaAbPropsCoordinator.js +137 -0
- package/dist/esm/client/coordinators/WaBusinessCoordinator.js +4 -13
- package/dist/esm/client/coordinators/WaEmailCoordinator.js +60 -0
- package/dist/esm/client/coordinators/WaIncomingNodeCoordinator.js +35 -10
- package/dist/esm/client/coordinators/WaMessageDispatchCoordinator.js +47 -17
- package/dist/esm/client/coordinators/WaOfflineResumeCoordinator.js +110 -0
- package/dist/esm/client/coordinators/WaPassiveTasksCoordinator.js +38 -20
- package/dist/esm/client/coordinators/WaProfileCoordinator.js +3 -1
- package/dist/esm/client/coordinators/WaRetryCoordinator.js +11 -9
- package/dist/esm/client/coordinators/WaTrustedContactTokenCoordinator.js +24 -6
- package/dist/esm/client/dirty.js +1 -1
- package/dist/esm/client/events/abprops.js +40 -0
- package/dist/esm/client/events/privacy-token.js +1 -2
- package/dist/esm/client/events/registration.js +39 -0
- package/dist/esm/client/incoming.js +36 -0
- package/dist/esm/client/mailbox.js +17 -1
- package/dist/esm/client/media.js +234 -0
- package/dist/esm/client/messages.js +162 -85
- package/dist/esm/crypto/core/index.js +1 -0
- package/dist/esm/crypto/core/random.js +2 -7
- package/dist/esm/crypto/core/xeddsa.js +53 -0
- package/dist/esm/crypto/curves/X25519.js +20 -2
- package/dist/esm/crypto/curves/constants.js +1 -0
- package/dist/esm/infra/perf/StoreLock.js +7 -4
- package/dist/esm/media/WaMediaCrypto.js +257 -62
- package/dist/esm/media/WaMediaTransferClient.js +47 -190
- package/dist/esm/media/constants.js +2 -0
- package/dist/esm/media/processor.js +1 -0
- package/dist/esm/message/addon-crypto.js +130 -3
- package/dist/esm/message/content.js +12 -6
- package/dist/esm/message/icdc.js +8 -8
- package/dist/esm/message/incoming.js +14 -12
- package/dist/esm/message/phash.js +32 -12
- package/dist/esm/message/reporting-token.js +3 -3
- package/dist/esm/message/use-case-secret.js +1 -1
- package/dist/esm/protocol/abprops.js +159 -0
- package/dist/esm/protocol/browser.js +14 -0
- package/dist/esm/protocol/constants.js +3 -1
- package/dist/esm/protocol/email.js +30 -0
- package/dist/esm/protocol/jid.js +44 -10
- package/dist/esm/protocol/nodes.js +6 -2
- package/dist/esm/protocol/notification.js +7 -1
- package/dist/esm/retry/reason.js +1 -1
- package/dist/esm/signal/api/SignalDeviceSyncApi.js +5 -2
- package/dist/esm/signal/api/SignalDigestSyncApi.js +8 -6
- package/dist/esm/signal/api/SignalIdentitySyncApi.js +4 -4
- package/dist/esm/signal/api/SignalMissingPreKeysSyncApi.js +1 -1
- package/dist/esm/signal/api/SignalSessionSyncApi.js +1 -1
- package/dist/esm/signal/crypto/WaAdvSignature.js +5 -51
- package/dist/esm/signal/crypto/constants.js +0 -4
- package/dist/esm/signal/encoding.js +11 -54
- package/dist/esm/signal/group/SenderKeyChain.js +3 -3
- package/dist/esm/signal/group/SenderKeyCodec.js +5 -6
- package/dist/esm/signal/group/SenderKeyManager.js +13 -10
- package/dist/esm/signal/registration/keygen.js +2 -3
- package/dist/esm/signal/registration/utils.js +2 -2
- package/dist/esm/signal/session/SignalProtocol.js +18 -17
- package/dist/esm/signal/session/SignalRatchet.js +21 -10
- package/dist/esm/signal/session/SignalSerializer.js +5 -6
- package/dist/esm/signal/session/SignalSession.js +11 -9
- package/dist/esm/signal/session/resolver.js +6 -6
- package/dist/esm/store/contracts/identity.store.js +1 -0
- package/dist/esm/store/contracts/message-secret.store.js +1 -0
- package/dist/esm/store/contracts/pre-key.store.js +1 -0
- package/dist/esm/store/contracts/session.store.js +1 -0
- package/dist/esm/store/createStore.js +48 -12
- package/dist/esm/store/index.js +4 -0
- package/dist/esm/store/locks/identity.lock.js +16 -0
- package/dist/esm/store/locks/message-secret.lock.js +17 -0
- package/dist/esm/store/locks/pre-key.lock.js +27 -0
- package/dist/esm/store/locks/session.lock.js +19 -0
- package/dist/esm/store/locks/signal.lock.js +0 -24
- package/dist/esm/store/noop.store.js +20 -0
- package/dist/esm/store/providers/memory/device-list.store.js +3 -0
- package/dist/esm/store/providers/memory/identity.store.js +31 -0
- package/dist/esm/store/providers/memory/message-secret.store.js +81 -0
- package/dist/esm/store/providers/memory/participants.store.js +3 -0
- package/dist/esm/store/providers/memory/pre-key.store.js +97 -0
- package/dist/esm/store/providers/memory/retry.store.js +25 -11
- package/dist/esm/store/providers/memory/session.store.js +45 -0
- package/dist/esm/store/providers/memory/signal.store.js +1 -164
- package/dist/esm/transport/WaComms.js +4 -3
- package/dist/esm/transport/WaWebSocket.js +9 -1
- package/dist/esm/transport/index.js +6 -0
- package/dist/esm/transport/keepalive/WaKeepAlive.js +17 -8
- package/dist/esm/transport/node/WaMobileTcpSocket.js +114 -0
- package/dist/esm/transport/node/WaNodeOrchestrator.js +17 -8
- package/dist/esm/transport/node/builders/abprops.js +20 -0
- package/dist/esm/transport/node/builders/device.js +11 -0
- package/dist/esm/transport/node/builders/email.js +65 -0
- package/dist/esm/transport/node/builders/offline.js +14 -0
- package/dist/esm/transport/node/builders/prekeys.js +37 -40
- package/dist/esm/transport/node/builders/presence.js +13 -0
- package/dist/esm/transport/node/builders/privacy-token.js +19 -23
- package/dist/esm/transport/node/builders/retry.js +1 -1
- package/dist/esm/transport/node/helpers.js +24 -0
- package/dist/esm/transport/node/mex/argo-decoder.js +152 -0
- package/dist/esm/transport/node/mex/client.js +83 -0
- package/dist/esm/transport/node/mex/persist-ids.js +10 -0
- package/dist/esm/transport/noise/WaClientPayload.js +15 -10
- package/dist/esm/transport/noise/WaFrameCodec.js +2 -2
- package/dist/esm/transport/noise/WaMobileClientPayload.js +53 -0
- package/dist/esm/transport/noise/WaNoiseCert.js +9 -27
- package/dist/esm/transport/noise/WaNoiseSession.js +12 -11
- package/dist/infra/perf/StoreLock.js +7 -4
- package/dist/media/WaMediaCrypto.js +253 -58
- package/dist/media/WaMediaTransferClient.js +50 -223
- package/dist/media/constants.js +3 -1
- package/dist/media/processor.js +2 -0
- package/dist/message/addon-crypto.js +131 -0
- package/dist/message/content.js +13 -5
- package/dist/message/icdc.js +8 -8
- package/dist/message/incoming.js +14 -12
- package/dist/message/phash.js +32 -12
- package/dist/message/reporting-token.js +2 -2
- package/dist/message/use-case-secret.js +1 -1
- package/dist/protocol/abprops.js +163 -0
- package/dist/protocol/browser.js +15 -0
- package/dist/protocol/constants.js +14 -2
- package/dist/protocol/email.js +33 -0
- package/dist/protocol/jid.js +45 -10
- package/dist/protocol/nodes.js +6 -2
- package/dist/protocol/notification.js +8 -2
- package/dist/retry/reason.js +1 -1
- package/dist/signal/api/SignalDeviceSyncApi.js +5 -2
- package/dist/signal/api/SignalDigestSyncApi.js +8 -6
- package/dist/signal/api/SignalIdentitySyncApi.js +4 -4
- package/dist/signal/crypto/WaAdvSignature.js +2 -50
- package/dist/signal/crypto/constants.js +1 -5
- package/dist/signal/encoding.js +11 -49
- package/dist/signal/group/SenderKeyChain.js +2 -2
- package/dist/signal/group/SenderKeyCodec.js +4 -5
- package/dist/signal/group/SenderKeyManager.js +12 -9
- package/dist/signal/registration/keygen.js +1 -2
- package/dist/signal/registration/utils.js +2 -2
- package/dist/signal/session/SignalProtocol.js +18 -17
- package/dist/signal/session/SignalRatchet.js +19 -8
- package/dist/signal/session/SignalSerializer.js +5 -6
- package/dist/signal/session/SignalSession.js +11 -9
- package/dist/signal/session/resolver.js +6 -6
- package/dist/store/contracts/identity.store.js +2 -0
- package/dist/store/contracts/message-secret.store.js +2 -0
- package/dist/store/contracts/pre-key.store.js +2 -0
- package/dist/store/contracts/session.store.js +2 -0
- package/dist/store/createStore.js +47 -11
- package/dist/store/index.js +9 -1
- package/dist/store/locks/identity.lock.js +19 -0
- package/dist/store/locks/message-secret.lock.js +20 -0
- package/dist/store/locks/pre-key.lock.js +30 -0
- package/dist/store/locks/session.lock.js +22 -0
- package/dist/store/locks/signal.lock.js +0 -24
- package/dist/store/noop.store.js +21 -1
- package/dist/store/providers/memory/device-list.store.js +3 -0
- package/dist/store/providers/memory/identity.store.js +35 -0
- package/dist/store/providers/memory/message-secret.store.js +85 -0
- package/dist/store/providers/memory/participants.store.js +3 -0
- package/dist/store/providers/memory/pre-key.store.js +101 -0
- package/dist/store/providers/memory/retry.store.js +24 -10
- package/dist/store/providers/memory/session.store.js +49 -0
- package/dist/store/providers/memory/signal.store.js +1 -164
- package/dist/transport/WaComms.js +4 -3
- package/dist/transport/WaWebSocket.js +9 -1
- package/dist/transport/index.js +17 -1
- package/dist/transport/keepalive/WaKeepAlive.js +17 -8
- package/dist/transport/node/WaMobileTcpSocket.js +118 -0
- package/dist/transport/node/WaNodeOrchestrator.js +16 -7
- package/dist/transport/node/builders/abprops.js +23 -0
- package/dist/transport/node/builders/device.js +14 -0
- package/dist/transport/node/builders/email.js +72 -0
- package/dist/transport/node/builders/offline.js +17 -0
- package/dist/transport/node/builders/prekeys.js +36 -39
- package/dist/transport/node/builders/presence.js +16 -0
- package/dist/transport/node/builders/privacy-token.js +18 -22
- package/dist/transport/node/builders/retry.js +1 -1
- package/dist/transport/node/helpers.js +26 -0
- package/dist/transport/node/mex/argo-decoder.js +189 -0
- package/dist/transport/node/mex/client.js +86 -0
- package/dist/transport/node/mex/persist-ids.js +13 -0
- package/dist/transport/noise/WaClientPayload.js +14 -9
- package/dist/transport/noise/WaFrameCodec.js +1 -1
- package/dist/transport/noise/WaMobileClientPayload.js +56 -0
- package/dist/transport/noise/WaNoiseCert.js +8 -26
- package/dist/transport/noise/WaNoiseSession.js +11 -10
- package/dist/types/appstate/WaAppStateCrypto.d.ts +11 -8
- package/dist/types/appstate/WaAppStateSyncClient.d.ts +6 -2
- package/dist/types/appstate/index.d.ts +1 -1
- package/dist/types/appstate/{WaAppStateSyncResponseParser.d.ts → response-parser.d.ts} +1 -1
- package/dist/types/appstate/types.d.ts +1 -1
- package/dist/types/auth/WaAuthClient.d.ts +9 -3
- package/dist/types/auth/credentials-flow.d.ts +20 -0
- package/dist/types/auth/pairing/WaPairingFlow.d.ts +3 -2
- package/dist/types/auth/pairing/{WaPairingCodeCrypto.d.ts → pairing-code-crypto.d.ts} +6 -1
- package/dist/types/auth/types.d.ts +40 -0
- package/dist/types/client/WaClient.d.ts +19 -8
- package/dist/types/client/WaClientFactory.d.ts +10 -4
- package/dist/types/client/coordinators/WaAbPropsCoordinator.d.ts +26 -0
- package/dist/types/client/coordinators/WaBusinessCoordinator.d.ts +1 -1
- package/dist/types/client/coordinators/WaEmailCoordinator.d.ts +24 -0
- package/dist/types/client/coordinators/WaIncomingNodeCoordinator.d.ts +6 -1
- package/dist/types/client/coordinators/WaMessageDispatchCoordinator.d.ts +15 -2
- package/dist/types/client/coordinators/WaOfflineResumeCoordinator.d.ts +31 -0
- package/dist/types/client/coordinators/WaPassiveTasksCoordinator.d.ts +13 -2
- package/dist/types/client/coordinators/WaPrivacyCoordinator.d.ts +1 -1
- package/dist/types/client/coordinators/WaProfileCoordinator.d.ts +4 -2
- package/dist/types/client/coordinators/WaRetryCoordinator.d.ts +6 -0
- package/dist/types/client/coordinators/WaTrustedContactTokenCoordinator.d.ts +11 -1
- package/dist/types/client/dirty.d.ts +3 -1
- package/dist/types/client/events/abprops.d.ts +14 -0
- package/dist/types/client/events/registration.d.ts +17 -0
- package/dist/types/client/incoming.d.ts +6 -1
- package/dist/types/client/mailbox.d.ts +2 -0
- package/dist/types/client/media.d.ts +31 -0
- package/dist/types/client/messages.d.ts +2 -0
- package/dist/types/client/persistence/WriteBehindPersistence.d.ts +1 -1
- package/dist/types/client/types.d.ts +100 -1
- package/dist/types/crypto/core/index.d.ts +1 -0
- package/dist/types/crypto/core/primitives.d.ts +1 -1
- package/dist/types/crypto/core/random.d.ts +1 -1
- package/dist/types/crypto/core/xeddsa.d.ts +2 -0
- package/dist/types/crypto/curves/constants.d.ts +1 -0
- package/dist/types/crypto/index.d.ts +1 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/infra/log/ConsoleLogger.d.ts +1 -1
- package/dist/types/infra/log/PinoLogger.d.ts +1 -1
- package/dist/types/infra/perf/StoreLock.d.ts +1 -0
- package/dist/types/media/WaMediaCrypto.d.ts +15 -6
- package/dist/types/media/WaMediaTransferClient.d.ts +3 -11
- package/dist/types/media/constants.d.ts +2 -0
- package/dist/types/media/index.d.ts +1 -0
- package/dist/types/media/processor.d.ts +28 -0
- package/dist/types/media/types.d.ts +9 -3
- package/dist/types/message/addon-crypto.d.ts +34 -3
- package/dist/types/message/content.d.ts +3 -1
- package/dist/types/message/icdc.d.ts +4 -4
- package/dist/types/message/types.d.ts +16 -24
- package/dist/types/protocol/abprops.d.ts +142 -0
- package/dist/types/protocol/browser.d.ts +1 -0
- package/dist/types/protocol/constants.d.ts +5 -1
- package/dist/types/protocol/email.d.ts +32 -0
- package/dist/types/protocol/jid.d.ts +1 -0
- package/dist/types/protocol/nodes.d.ts +4 -0
- package/dist/types/protocol/notification.d.ts +6 -0
- package/dist/types/protocol/stream.d.ts +1 -0
- package/dist/types/retry/reason.d.ts +1 -1
- package/dist/types/signal/api/SignalDigestSyncApi.d.ts +3 -0
- package/dist/types/signal/api/SignalIdentitySyncApi.d.ts +3 -3
- package/dist/types/signal/crypto/WaAdvSignature.d.ts +0 -2
- package/dist/types/signal/crypto/constants.d.ts +0 -1
- package/dist/types/signal/encoding.d.ts +7 -1
- package/dist/types/signal/group/SenderKeyChain.d.ts +1 -1
- package/dist/types/signal/group/SenderKeyManager.d.ts +7 -2
- package/dist/types/signal/registration/utils.d.ts +2 -1
- package/dist/types/signal/session/SignalProtocol.d.ts +11 -2
- package/dist/types/signal/session/SignalSerializer.d.ts +2 -1
- package/dist/types/signal/session/resolver.d.ts +4 -2
- package/dist/types/signal/types.d.ts +16 -4
- package/dist/types/store/contracts/identity.store.d.ts +11 -0
- package/dist/types/store/contracts/message-secret.store.d.ts +16 -0
- package/dist/types/store/contracts/pre-key.store.d.ts +13 -0
- package/dist/types/store/contracts/session.store.d.ts +14 -0
- package/dist/types/store/contracts/signal.store.d.ts +1 -34
- package/dist/types/store/index.d.ts +9 -1
- package/dist/types/store/locks/identity.lock.d.ts +3 -0
- package/dist/types/store/locks/message-secret.lock.d.ts +3 -0
- package/dist/types/store/locks/pre-key.lock.d.ts +3 -0
- package/dist/types/store/locks/session.lock.d.ts +3 -0
- package/dist/types/store/noop.store.d.ts +4 -0
- package/dist/types/store/providers/memory/identity.store.d.ts +18 -0
- package/dist/types/store/providers/memory/message-secret.store.d.ts +21 -0
- package/dist/types/store/providers/memory/pre-key.store.d.ts +23 -0
- package/dist/types/store/providers/memory/retry.store.d.ts +7 -1
- package/dist/types/store/providers/memory/session.store.d.ts +21 -0
- package/dist/types/store/providers/memory/signal.store.d.ts +3 -45
- package/dist/types/store/providers/memory/thread.store.d.ts +1 -1
- package/dist/types/store/types.d.ts +21 -1
- package/dist/types/transport/WaWebSocket.d.ts +1 -0
- package/dist/types/transport/index.d.ts +8 -1
- package/dist/types/transport/keepalive/WaKeepAlive.d.ts +4 -1
- package/dist/types/transport/node/WaMobileTcpSocket.d.ts +18 -0
- package/dist/types/transport/node/WaNodeOrchestrator.d.ts +6 -2
- package/dist/types/transport/node/builders/abprops.d.ts +5 -0
- package/dist/types/transport/node/builders/device.d.ts +2 -0
- package/dist/types/transport/node/builders/email.d.ts +11 -0
- package/dist/types/transport/node/builders/offline.d.ts +2 -0
- package/dist/types/transport/node/builders/prekeys.d.ts +4 -3
- package/dist/types/transport/node/builders/presence.d.ts +6 -0
- package/dist/types/transport/node/helpers.d.ts +3 -0
- package/dist/types/transport/node/mex/argo-decoder.d.ts +11 -0
- package/dist/types/transport/node/mex/client.d.ts +18 -0
- package/dist/types/transport/node/mex/persist-ids.d.ts +14 -0
- package/dist/types/transport/noise/WaMobileClientPayload.d.ts +29 -0
- package/dist/types/transport/noise/WaNoiseCert.d.ts +7 -1
- package/dist/types/transport/noise/WaNoiseSession.d.ts +1 -0
- package/dist/types/transport/types.d.ts +8 -0
- package/package.json +6 -4
- package/dist/auth/pairing/constants.js +0 -5
- package/dist/client/connection/WaKeyShareCoordinator.js +0 -63
- package/dist/esm/auth/pairing/constants.js +0 -2
- package/dist/esm/client/connection/WaKeyShareCoordinator.js +0 -59
- package/dist/esm/transport/node/builders/index.js +0 -11
- package/dist/transport/node/builders/index.js +0 -51
- package/dist/types/auth/flow/WaAuthCredentialsFlow.d.ts +0 -14
- package/dist/types/auth/pairing/constants.d.ts +0 -2
- package/dist/types/client/connection/WaKeyShareCoordinator.d.ts +0 -14
- package/dist/types/transport/node/builders/index.d.ts +0 -11
- /package/dist/appstate/{WaAppStateSyncResponseParser.js → response-parser.js} +0 -0
|
@@ -6,12 +6,16 @@ import { persistIncomingMailboxEntities } from './mailbox.js';
|
|
|
6
6
|
import { WriteBehindPersistence } from './persistence/WriteBehindPersistence.js';
|
|
7
7
|
import { buildWaClientDependencies, resolveWaClientBase } from './WaClientFactory.js';
|
|
8
8
|
import { ConsoleLogger } from '../infra/log/ConsoleLogger.js';
|
|
9
|
+
import { buildAddonAdditionalData, decodeAddonPlaintext, decryptAddonPayload, identifyEncryptedAddon, resolveParentMessageSecret, resolvePollOptionNames, shouldUseAddonAdditionalData } from '../message/addon-crypto.js';
|
|
9
10
|
import { proto } from '../proto.js';
|
|
10
11
|
import { WA_APP_STATE_COLLECTION_STATES, WA_DEFAULTS } from '../protocol/constants.js';
|
|
11
12
|
import { normalizeDeviceJid, parsePhoneJid, toUserJid } from '../protocol/jid.js';
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
13
|
+
import { WA_LOGOUT_REASONS } from '../protocol/stream.js';
|
|
14
|
+
import { NOOP_MESSAGE_SECRET_STORE } from '../store/noop.store.js';
|
|
15
|
+
import { buildRemoveCompanionDeviceIq } from '../transport/node/builders/device.js';
|
|
16
|
+
import { buildPresenceNode } from '../transport/node/builders/presence.js';
|
|
17
|
+
import { assertIqResult, queryWithContext as queryNodeWithContext } from '../transport/node/query.js';
|
|
18
|
+
import { bytesToHex, decodeProtoBytes } from '../util/bytes.js';
|
|
15
19
|
import { toError } from '../util/primitives.js';
|
|
16
20
|
const SYNC_RELATED_PROTOCOL_TYPES = new Set([
|
|
17
21
|
proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_REQUEST,
|
|
@@ -19,8 +23,6 @@ const SYNC_RELATED_PROTOCOL_TYPES = new Set([
|
|
|
19
23
|
proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE,
|
|
20
24
|
proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE
|
|
21
25
|
]);
|
|
22
|
-
const WA_APP_STATE_KEY_SHARE_WAIT_TIMEOUT_MS = 15000;
|
|
23
|
-
const WA_APP_STATE_KEY_SHARE_MAX_RETRIES = 2;
|
|
24
26
|
export class WaClient extends EventEmitter {
|
|
25
27
|
constructor(options, logger = new ConsoleLogger('info')) {
|
|
26
28
|
super();
|
|
@@ -34,11 +36,15 @@ export class WaClient extends EventEmitter {
|
|
|
34
36
|
this.appStateStore = base.sessionStore.appState;
|
|
35
37
|
this.contactStore = base.sessionStore.contacts;
|
|
36
38
|
this.messageStore = base.sessionStore.messages;
|
|
39
|
+
this.messageSecretStore = base.sessionStore.messageSecret;
|
|
37
40
|
this.participantsStore = base.sessionStore.participants;
|
|
38
41
|
this.privacyTokenStore = base.sessionStore.privacyToken;
|
|
39
42
|
this.deviceListStore = base.sessionStore.deviceList;
|
|
40
43
|
this.retryStore = base.sessionStore.retry;
|
|
41
44
|
this.signalStore = base.sessionStore.signal;
|
|
45
|
+
this.preKeyStore = base.sessionStore.preKey;
|
|
46
|
+
this.sessionStore = base.sessionStore.session;
|
|
47
|
+
this.identityStore = base.sessionStore.identity;
|
|
42
48
|
this.senderKeyStore = base.sessionStore.senderKey;
|
|
43
49
|
this.threadStore = base.sessionStore.threads;
|
|
44
50
|
this.writeBehind = new WriteBehindPersistence({
|
|
@@ -46,11 +52,16 @@ export class WaClient extends EventEmitter {
|
|
|
46
52
|
threadStore: this.threadStore,
|
|
47
53
|
contactStore: this.contactStore
|
|
48
54
|
}, this.logger, this.options.writeBehind);
|
|
55
|
+
if (this.options.addons?.autoDecrypt &&
|
|
56
|
+
this.messageSecretStore === NOOP_MESSAGE_SECRET_STORE) {
|
|
57
|
+
this.logger.warn('addons.autoDecrypt is enabled but messageSecret cache is noop — ' +
|
|
58
|
+
'addon decryption will only work if secrets are in the message store');
|
|
59
|
+
}
|
|
49
60
|
const dependencies = buildWaClientDependencies({
|
|
50
61
|
base,
|
|
51
62
|
runtime: {
|
|
52
63
|
sendNode: (node) => this.sendNode(node),
|
|
53
|
-
query: (node, timeoutMs) => this.query(node, timeoutMs),
|
|
64
|
+
query: (node, timeoutMs, options) => this.query(node, timeoutMs, options),
|
|
54
65
|
queryWithContext: this.queryWithContext.bind(this),
|
|
55
66
|
syncAppState: () => this.syncAppState().then(() => { }),
|
|
56
67
|
syncAppStateWithOptions: (syncOptions) => this.syncAppState(syncOptions),
|
|
@@ -109,12 +120,16 @@ export class WaClient extends EventEmitter {
|
|
|
109
120
|
throw normalized;
|
|
110
121
|
}
|
|
111
122
|
}
|
|
112
|
-
async
|
|
123
|
+
async sendPresence(type) {
|
|
124
|
+
const credentials = this.authClient.getCurrentCredentials();
|
|
125
|
+
await this.nodeOrchestrator.sendNode(buildPresenceNode({ type, name: credentials?.meDisplayName ?? undefined }), false);
|
|
126
|
+
}
|
|
127
|
+
async query(node, timeoutMs = this.options.iqTimeoutMs ?? WA_DEFAULTS.IQ_TIMEOUT_MS, options = {}) {
|
|
113
128
|
if (!this.connectionManager.isConnected()) {
|
|
114
129
|
throw new Error('client is not connected');
|
|
115
130
|
}
|
|
116
131
|
this.logger.debug('wa client query', { tag: node.tag, id: node.attrs.id, timeoutMs });
|
|
117
|
-
return this.nodeOrchestrator.query(node, timeoutMs);
|
|
132
|
+
return this.nodeOrchestrator.query(node, timeoutMs, options);
|
|
118
133
|
}
|
|
119
134
|
registerIncomingHandler(registration) {
|
|
120
135
|
return this.incomingNode.registerIncomingHandler(registration);
|
|
@@ -141,8 +156,17 @@ export class WaClient extends EventEmitter {
|
|
|
141
156
|
void persistIncomingMailboxEntities({
|
|
142
157
|
logger: this.logger,
|
|
143
158
|
writeBehind: this.writeBehind,
|
|
159
|
+
messageSecretStore: this.messageSecretStore,
|
|
144
160
|
event
|
|
145
161
|
});
|
|
162
|
+
if (this.options.addons?.autoDecrypt && event.message) {
|
|
163
|
+
void this.tryDecryptAddon(event).catch((err) => {
|
|
164
|
+
this.logger.warn('addon auto-decrypt failed', {
|
|
165
|
+
id: event.stanzaId,
|
|
166
|
+
message: toError(err).message
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
}
|
|
146
170
|
const protocolMessage = event.message?.protocolMessage;
|
|
147
171
|
if (!protocolMessage) {
|
|
148
172
|
return;
|
|
@@ -209,16 +233,6 @@ export class WaClient extends EventEmitter {
|
|
|
209
233
|
imported
|
|
210
234
|
});
|
|
211
235
|
if (imported > 0) {
|
|
212
|
-
const hadWaiters = this.keyShareCoordinator.hasWaiters();
|
|
213
|
-
this.keyShareCoordinator.notifyReceived();
|
|
214
|
-
if (hadWaiters) {
|
|
215
|
-
this.logger.debug('app-state key share imported and waiters released', {
|
|
216
|
-
id: event.stanzaId,
|
|
217
|
-
from: event.chatJid,
|
|
218
|
-
imported
|
|
219
|
-
});
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
236
|
void this.syncAppState().catch((error) => {
|
|
223
237
|
this.logger.warn('failed to sync app-state after key share import', {
|
|
224
238
|
id: event.stanzaId,
|
|
@@ -359,8 +373,8 @@ export class WaClient extends EventEmitter {
|
|
|
359
373
|
});
|
|
360
374
|
}
|
|
361
375
|
}
|
|
362
|
-
async queryWithContext(context, node, timeoutMs = this.options.iqTimeoutMs ?? WA_DEFAULTS.IQ_TIMEOUT_MS, contextData = {}) {
|
|
363
|
-
return queryNodeWithContext(async (queryNode, queryTimeoutMs) => this.query(queryNode, queryTimeoutMs), this.logger, context, node, timeoutMs, contextData);
|
|
376
|
+
async queryWithContext(context, node, timeoutMs = this.options.iqTimeoutMs ?? WA_DEFAULTS.IQ_TIMEOUT_MS, contextData = {}, options = {}) {
|
|
377
|
+
return queryNodeWithContext(async (queryNode, queryTimeoutMs) => this.query(queryNode, queryTimeoutMs, options), this.logger, context, node, timeoutMs, contextData);
|
|
364
378
|
}
|
|
365
379
|
async handleIncomingFrame(frame) {
|
|
366
380
|
try {
|
|
@@ -400,7 +414,6 @@ export class WaClient extends EventEmitter {
|
|
|
400
414
|
remaining: writeBehindFlush.remaining
|
|
401
415
|
});
|
|
402
416
|
}
|
|
403
|
-
this.keyShareCoordinator.notifyDisconnected();
|
|
404
417
|
await this.connectionManager.disconnect();
|
|
405
418
|
this.emit('connection', {
|
|
406
419
|
status: 'close',
|
|
@@ -410,12 +423,12 @@ export class WaClient extends EventEmitter {
|
|
|
410
423
|
isNewLogin: false
|
|
411
424
|
});
|
|
412
425
|
}
|
|
413
|
-
async requestPairingCode(phoneNumber, shouldShowPushNotification = false) {
|
|
426
|
+
async requestPairingCode(phoneNumber, shouldShowPushNotification = false, customCode) {
|
|
414
427
|
if (!this.connectionManager.isConnected() || !this.authClient.getCurrentCredentials()) {
|
|
415
428
|
throw new Error('client is not connected');
|
|
416
429
|
}
|
|
417
430
|
this.logger.debug('wa client request pairing code');
|
|
418
|
-
return this.authClient.requestPairingCode(phoneNumber, shouldShowPushNotification);
|
|
431
|
+
return this.authClient.requestPairingCode(phoneNumber, shouldShowPushNotification, customCode);
|
|
419
432
|
}
|
|
420
433
|
async fetchPairingCountryCodeIso() {
|
|
421
434
|
if (!this.connectionManager.isConnected() || !this.authClient.getCurrentCredentials()) {
|
|
@@ -464,6 +477,22 @@ export class WaClient extends EventEmitter {
|
|
|
464
477
|
get business() {
|
|
465
478
|
return this.businessCoordinator;
|
|
466
479
|
}
|
|
480
|
+
get email() {
|
|
481
|
+
return this.emailCoordinator;
|
|
482
|
+
}
|
|
483
|
+
async logout(reason = WA_LOGOUT_REASONS.USER_INITIATED) {
|
|
484
|
+
const meJid = this.authClient.getCurrentCredentials()?.meJid;
|
|
485
|
+
if (!meJid) {
|
|
486
|
+
throw new Error('cannot logout: client is not authenticated');
|
|
487
|
+
}
|
|
488
|
+
const deviceJid = normalizeDeviceJid(meJid);
|
|
489
|
+
const node = buildRemoveCompanionDeviceIq(deviceJid, reason);
|
|
490
|
+
const result = await this.queryWithContext('client.logout', node, undefined, {
|
|
491
|
+
jid: deviceJid,
|
|
492
|
+
reason
|
|
493
|
+
});
|
|
494
|
+
assertIqResult(result, 'client.logout');
|
|
495
|
+
}
|
|
467
496
|
sendReceipt(input) {
|
|
468
497
|
return this.messageDispatch.sendReceipt(input);
|
|
469
498
|
}
|
|
@@ -480,60 +509,11 @@ export class WaClient extends EventEmitter {
|
|
|
480
509
|
if (!this.connectionManager.isConnected()) {
|
|
481
510
|
throw new Error('client is not connected');
|
|
482
511
|
}
|
|
483
|
-
const
|
|
484
|
-
|
|
485
|
-
this.keyShareCoordinator.markBootstrapDone();
|
|
486
|
-
this.logger.info('app-state bootstrap pre-sync waiting for key share', {
|
|
487
|
-
timeoutMs: WA_APP_STATE_KEY_SHARE_WAIT_TIMEOUT_MS
|
|
488
|
-
});
|
|
489
|
-
const received = await this.keyShareCoordinator.waitForShare(WA_APP_STATE_KEY_SHARE_WAIT_TIMEOUT_MS);
|
|
490
|
-
if (received) {
|
|
491
|
-
this.logger.info('app-state bootstrap pre-sync received key share, continuing sync');
|
|
492
|
-
}
|
|
493
|
-
else {
|
|
494
|
-
this.logger.warn('app-state bootstrap pre-sync key share wait timed out, continuing sync', {
|
|
495
|
-
timeoutMs: WA_APP_STATE_KEY_SHARE_WAIT_TIMEOUT_MS
|
|
496
|
-
});
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
let syncResult = await this.executeAppStateSync(options);
|
|
500
|
-
let blockedCollections = this.getBlockedAppStateCollections(syncResult);
|
|
501
|
-
if (!shouldWaitForKeyShare || blockedCollections.length === 0) {
|
|
502
|
-
this.emitChatEventsFromAppStateSyncResult(syncResult);
|
|
503
|
-
return syncResult;
|
|
504
|
-
}
|
|
505
|
-
let retryCount = 0;
|
|
506
|
-
let observedKeyShareVersion = this.keyShareCoordinator.getVersion();
|
|
507
|
-
while (blockedCollections.length > 0 && retryCount < WA_APP_STATE_KEY_SHARE_MAX_RETRIES) {
|
|
508
|
-
const hasFreshShare = this.keyShareCoordinator.getVersion() !== observedKeyShareVersion;
|
|
509
|
-
if (!hasFreshShare) {
|
|
510
|
-
this.logger.info('app-state bootstrap waiting for key share', {
|
|
511
|
-
blockedCollections: blockedCollections.join(','),
|
|
512
|
-
timeoutMs: WA_APP_STATE_KEY_SHARE_WAIT_TIMEOUT_MS,
|
|
513
|
-
retryCount: retryCount + 1
|
|
514
|
-
});
|
|
515
|
-
const received = await this.keyShareCoordinator.waitForShare(WA_APP_STATE_KEY_SHARE_WAIT_TIMEOUT_MS);
|
|
516
|
-
if (!received) {
|
|
517
|
-
this.logger.warn('app-state bootstrap key share wait timed out', {
|
|
518
|
-
blockedCollections: blockedCollections.join(','),
|
|
519
|
-
timeoutMs: WA_APP_STATE_KEY_SHARE_WAIT_TIMEOUT_MS
|
|
520
|
-
});
|
|
521
|
-
break;
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
observedKeyShareVersion = this.keyShareCoordinator.getVersion();
|
|
525
|
-
retryCount += 1;
|
|
526
|
-
this.logger.info('app-state bootstrap retrying sync after key share', {
|
|
527
|
-
retryCount,
|
|
528
|
-
blockedCollections: blockedCollections.join(',')
|
|
529
|
-
});
|
|
530
|
-
syncResult = await this.executeAppStateSync(options);
|
|
531
|
-
blockedCollections = this.getBlockedAppStateCollections(syncResult);
|
|
532
|
-
}
|
|
512
|
+
const syncResult = await this.executeAppStateSync(options);
|
|
513
|
+
const blockedCollections = this.getBlockedAppStateCollections(syncResult);
|
|
533
514
|
if (blockedCollections.length > 0) {
|
|
534
|
-
this.logger.warn('app-state
|
|
535
|
-
blockedCollections: blockedCollections.join(',')
|
|
536
|
-
retries: retryCount
|
|
515
|
+
this.logger.warn('app-state sync has blocked collections', {
|
|
516
|
+
blockedCollections: blockedCollections.join(',')
|
|
537
517
|
});
|
|
538
518
|
}
|
|
539
519
|
this.emitChatEventsFromAppStateSyncResult(syncResult);
|
|
@@ -634,6 +614,8 @@ export class WaClient extends EventEmitter {
|
|
|
634
614
|
await this.contactStore.clear();
|
|
635
615
|
if (shouldClear('messages'))
|
|
636
616
|
await this.messageStore.clear();
|
|
617
|
+
if (shouldClear('messageSecret'))
|
|
618
|
+
await this.messageSecretStore.clear();
|
|
637
619
|
if (shouldClear('participants'))
|
|
638
620
|
await this.participantsStore.clear();
|
|
639
621
|
if (shouldClear('deviceList'))
|
|
@@ -642,6 +624,12 @@ export class WaClient extends EventEmitter {
|
|
|
642
624
|
await this.retryStore.clear();
|
|
643
625
|
if (shouldClear('signal'))
|
|
644
626
|
await this.signalStore.clear();
|
|
627
|
+
if (shouldClear('preKey'))
|
|
628
|
+
await this.preKeyStore.clear();
|
|
629
|
+
if (shouldClear('session'))
|
|
630
|
+
await this.sessionStore.clear();
|
|
631
|
+
if (shouldClear('identity'))
|
|
632
|
+
await this.identityStore.clear();
|
|
645
633
|
if (shouldClear('senderKey'))
|
|
646
634
|
await this.senderKeyStore.clear();
|
|
647
635
|
if (shouldClear('threads'))
|
|
@@ -649,6 +637,58 @@ export class WaClient extends EventEmitter {
|
|
|
649
637
|
if (shouldClear('privacyToken'))
|
|
650
638
|
await this.privacyTokenStore.clear();
|
|
651
639
|
}
|
|
640
|
+
async tryDecryptAddon(event) {
|
|
641
|
+
const message = event.message;
|
|
642
|
+
if (!message)
|
|
643
|
+
return;
|
|
644
|
+
const addon = identifyEncryptedAddon(message);
|
|
645
|
+
if (!addon)
|
|
646
|
+
return;
|
|
647
|
+
const targetMessageId = addon.targetMessageKey.id;
|
|
648
|
+
if (!targetMessageId)
|
|
649
|
+
return;
|
|
650
|
+
const parentEntry = await resolveParentMessageSecret(targetMessageId, this.messageSecretStore, this.messageStore);
|
|
651
|
+
if (!parentEntry) {
|
|
652
|
+
this.logger.debug('addon parent message secret not found', {
|
|
653
|
+
id: event.stanzaId,
|
|
654
|
+
targetId: targetMessageId
|
|
655
|
+
});
|
|
656
|
+
return;
|
|
657
|
+
}
|
|
658
|
+
const parentMsgOriginalSender = parentEntry.senderJid;
|
|
659
|
+
const modificationSender = event.senderJid ?? '';
|
|
660
|
+
const plaintext = await decryptAddonPayload({
|
|
661
|
+
messageSecret: parentEntry.secret,
|
|
662
|
+
stanzaId: targetMessageId,
|
|
663
|
+
parentMsgOriginalSender,
|
|
664
|
+
modificationSender,
|
|
665
|
+
modificationType: addon.modificationType,
|
|
666
|
+
ciphertext: addon.encPayload,
|
|
667
|
+
iv: addon.encIv,
|
|
668
|
+
additionalData: shouldUseAddonAdditionalData(addon.modificationType)
|
|
669
|
+
? buildAddonAdditionalData(targetMessageId, modificationSender)
|
|
670
|
+
: undefined
|
|
671
|
+
});
|
|
672
|
+
let decrypted = decodeAddonPlaintext(addon.kind, plaintext);
|
|
673
|
+
if (decrypted.kind === 'poll_vote' && decrypted.pollVote.selectedOptions) {
|
|
674
|
+
const names = await resolvePollOptionNames(decrypted.pollVote.selectedOptions, targetMessageId, this.messageStore);
|
|
675
|
+
if (names) {
|
|
676
|
+
decrypted = { ...decrypted, selectedOptionNames: names };
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
const addonEvent = {
|
|
680
|
+
rawNode: event.rawNode,
|
|
681
|
+
stanzaId: event.stanzaId,
|
|
682
|
+
chatJid: event.chatJid,
|
|
683
|
+
stanzaType: event.stanzaType,
|
|
684
|
+
kind: addon.kind,
|
|
685
|
+
targetMessageId,
|
|
686
|
+
senderJid: modificationSender,
|
|
687
|
+
decrypted,
|
|
688
|
+
raw: message
|
|
689
|
+
};
|
|
690
|
+
this.emit('message_addon', addonEvent);
|
|
691
|
+
}
|
|
652
692
|
tryEnterIncomingHandler() {
|
|
653
693
|
if (!this.acceptingIncomingEvents) {
|
|
654
694
|
return false;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { WaAppStateSyncClient } from '../appstate/WaAppStateSyncClient.js';
|
|
2
2
|
import { WaAuthClient } from '../auth/WaAuthClient.js';
|
|
3
3
|
import { WaConnectionManager } from './connection/WaConnectionManager.js';
|
|
4
|
-
import { WaKeyShareCoordinator } from './connection/WaKeyShareCoordinator.js';
|
|
5
4
|
import { WaReceiptQueue } from './connection/WaReceiptQueue.js';
|
|
5
|
+
import { WaAbPropsCoordinator } from './coordinators/WaAbPropsCoordinator.js';
|
|
6
6
|
import { WaAppStateMutationCoordinator } from './coordinators/WaAppStateMutationCoordinator.js';
|
|
7
7
|
import { createBusinessCoordinator } from './coordinators/WaBusinessCoordinator.js';
|
|
8
|
+
import { createEmailCoordinator } from './coordinators/WaEmailCoordinator.js';
|
|
8
9
|
import { createGroupCoordinator } from './coordinators/WaGroupCoordinator.js';
|
|
9
10
|
import { WaIncomingNodeCoordinator } from './coordinators/WaIncomingNodeCoordinator.js';
|
|
10
11
|
import { WaMessageDispatchCoordinator } from './coordinators/WaMessageDispatchCoordinator.js';
|
|
12
|
+
import { WaOfflineResumeCoordinator } from './coordinators/WaOfflineResumeCoordinator.js';
|
|
11
13
|
import { WaPassiveTasksCoordinator } from './coordinators/WaPassiveTasksCoordinator.js';
|
|
12
14
|
import { createPrivacyCoordinator } from './coordinators/WaPrivacyCoordinator.js';
|
|
13
15
|
import { createProfileCoordinator } from './coordinators/WaProfileCoordinator.js';
|
|
@@ -39,11 +41,12 @@ import { createSignalSessionResolver } from '../signal/session/resolver.js';
|
|
|
39
41
|
import { SignalProtocol } from '../signal/session/SignalProtocol.js';
|
|
40
42
|
import { WaKeepAlive } from '../transport/keepalive/WaKeepAlive.js';
|
|
41
43
|
import { buildAckNode } from '../transport/node/builders/global.js';
|
|
44
|
+
import { buildPresenceNode } from '../transport/node/builders/presence.js';
|
|
42
45
|
import { getFirstNodeChild } from '../transport/node/helpers.js';
|
|
43
46
|
import { createUsyncSidGenerator } from '../transport/node/usync.js';
|
|
44
47
|
import { WaNodeOrchestrator } from '../transport/node/WaNodeOrchestrator.js';
|
|
45
48
|
import { WaNodeTransport } from '../transport/node/WaNodeTransport.js';
|
|
46
|
-
import { isProxyTransport, toProxyAgent
|
|
49
|
+
import { isProxyTransport, toProxyAgent } from '../transport/proxy.js';
|
|
47
50
|
import { toError } from '../util/primitives.js';
|
|
48
51
|
import { getRuntimeOsDisplayName } from '../util/runtime.js';
|
|
49
52
|
function assertProxyTransport(value, path) {
|
|
@@ -128,6 +131,8 @@ function createIncomingNodeRuntime(input) {
|
|
|
128
131
|
emitIncomingFailure: (event) => emitEvent('failure', event),
|
|
129
132
|
emitIncomingErrorStanza: (event) => emitEvent('stanza_error', event),
|
|
130
133
|
emitIncomingNotification: (event) => emitEvent('notification', event),
|
|
134
|
+
emitRegistrationCode: (event) => emitEvent('registration_code_received', event),
|
|
135
|
+
emitAccountTakeoverNotice: (event) => emitEvent('account_takeover_notice', event),
|
|
131
136
|
emitGroupEvent: (event) => {
|
|
132
137
|
emitEvent('group_event', event);
|
|
133
138
|
void messageDispatch.mutateParticipantsCacheFromGroupEvent(event).catch((error) => {
|
|
@@ -151,7 +156,7 @@ function createIncomingNodeRuntime(input) {
|
|
|
151
156
|
};
|
|
152
157
|
}
|
|
153
158
|
function createPassiveTasksRuntime(input) {
|
|
154
|
-
const { queryWithContext, authClient, nodeOrchestrator, receiptQueue, getCurrentCredentials } = input;
|
|
159
|
+
const { queryWithContext, authClient, nodeOrchestrator, receiptQueue, getCurrentCredentials, abPropsCoordinator } = input;
|
|
155
160
|
return {
|
|
156
161
|
queryWithContext,
|
|
157
162
|
getCurrentCredentials,
|
|
@@ -159,14 +164,18 @@ function createPassiveTasksRuntime(input) {
|
|
|
159
164
|
sendNodeDirect: (node) => nodeOrchestrator.sendNode(node),
|
|
160
165
|
takeDanglingReceipts: () => receiptQueue.take(),
|
|
161
166
|
requeueDanglingReceipt: (node) => receiptQueue.enqueue(node),
|
|
162
|
-
shouldQueueDanglingReceipt: (node, error) => receiptQueue.shouldQueue(node, error)
|
|
167
|
+
shouldQueueDanglingReceipt: (node, error) => receiptQueue.shouldQueue(node, error),
|
|
168
|
+
syncAbProps: () => abPropsCoordinator.sync(),
|
|
169
|
+
sendPresenceAvailable: async () => {
|
|
170
|
+
const credentials = getCurrentCredentials();
|
|
171
|
+
await nodeOrchestrator.sendNode(buildPresenceNode({ name: credentials?.meDisplayName ?? undefined }), false);
|
|
172
|
+
}
|
|
163
173
|
};
|
|
164
174
|
}
|
|
165
175
|
export function buildWaClientDependencies(input) {
|
|
166
176
|
const { base, runtime } = input;
|
|
167
177
|
const { options, logger, sessionStore } = base;
|
|
168
178
|
const receiptQueue = new WaReceiptQueue();
|
|
169
|
-
const keyShareCoordinator = new WaKeyShareCoordinator();
|
|
170
179
|
let connectionManager = null;
|
|
171
180
|
let passiveTasks = null;
|
|
172
181
|
let mediaConnCacheFallback = null;
|
|
@@ -176,23 +185,24 @@ export function buildWaClientDependencies(input) {
|
|
|
176
185
|
sendNode: async (node) => nodeTransport.sendNode(node),
|
|
177
186
|
logger,
|
|
178
187
|
defaultTimeoutMs: options.nodeQueryTimeoutMs,
|
|
179
|
-
hostDomain: WA_DEFAULTS.HOST_DOMAIN
|
|
188
|
+
hostDomain: WA_DEFAULTS.HOST_DOMAIN,
|
|
189
|
+
mobileIqIdFormat: options.mobileTransport !== undefined
|
|
180
190
|
});
|
|
181
191
|
const keepAlive = new WaKeepAlive({
|
|
182
192
|
logger,
|
|
183
193
|
nodeOrchestrator,
|
|
184
194
|
getComms: () => connectionManager?.getComms() ?? null,
|
|
185
195
|
intervalMs: options.keepAliveIntervalMs,
|
|
196
|
+
getIntervalMs: () => abPropsCoordinator.getConfigValue('heartbeat_interval_s') * 1000,
|
|
186
197
|
timeoutMs: options.deadSocketTimeoutMs,
|
|
187
198
|
hostDomain: WA_DEFAULTS.HOST_DOMAIN
|
|
188
199
|
});
|
|
189
200
|
const mediaTransfer = new WaMediaTransferClient({
|
|
190
201
|
logger,
|
|
191
202
|
defaultTimeoutMs: options.mediaTimeoutMs,
|
|
192
|
-
defaultUploadDispatcher: toProxyDispatcher(options.proxy?.mediaUpload),
|
|
193
|
-
defaultDownloadDispatcher: toProxyDispatcher(options.proxy?.mediaDownload),
|
|
194
203
|
defaultUploadAgent: toProxyAgent(options.proxy?.mediaUpload),
|
|
195
|
-
defaultDownloadAgent: toProxyAgent(options.proxy?.mediaDownload)
|
|
204
|
+
defaultDownloadAgent: toProxyAgent(options.proxy?.mediaDownload),
|
|
205
|
+
skipMacVerification: options.dangerous?.disableMediaMacVerification
|
|
196
206
|
});
|
|
197
207
|
const mediaMessageBuildOptions = {
|
|
198
208
|
logger,
|
|
@@ -208,7 +218,8 @@ export function buildWaClientDependencies(input) {
|
|
|
208
218
|
setMediaConnCache: (mediaConn) => {
|
|
209
219
|
mediaConnCacheFallback = mediaConn;
|
|
210
220
|
connectionManager?.setMediaConnCache(mediaConn);
|
|
211
|
-
}
|
|
221
|
+
},
|
|
222
|
+
media: options.media
|
|
212
223
|
};
|
|
213
224
|
const messageClient = new WaMessageClient({
|
|
214
225
|
logger,
|
|
@@ -218,12 +229,22 @@ export function buildWaClientDependencies(input) {
|
|
|
218
229
|
defaultMaxAttempts: options.messageMaxAttempts,
|
|
219
230
|
defaultRetryDelayMs: options.messageRetryDelayMs
|
|
220
231
|
});
|
|
221
|
-
const senderKeyManager = new SenderKeyManager(sessionStore.senderKey
|
|
222
|
-
|
|
232
|
+
const senderKeyManager = new SenderKeyManager(sessionStore.senderKey, {
|
|
233
|
+
getFutureMessagesMax: () => abPropsCoordinator.getConfigValue('web_signal_future_messages_max'),
|
|
234
|
+
skipSignatureVerification: options.dangerous?.disableSenderKeySignatureVerification
|
|
235
|
+
});
|
|
236
|
+
const signalProtocol = new SignalProtocol({
|
|
237
|
+
signal: sessionStore.signal,
|
|
238
|
+
preKey: sessionStore.preKey,
|
|
239
|
+
session: sessionStore.session,
|
|
240
|
+
identity: sessionStore.identity
|
|
241
|
+
}, logger);
|
|
242
|
+
const signalSystemQuery = (node, timeoutMs) => runtime.query(node, timeoutMs, { useSystemId: true });
|
|
223
243
|
const signalDigestSync = new SignalDigestSyncApi({
|
|
224
244
|
logger,
|
|
225
|
-
query:
|
|
245
|
+
query: signalSystemQuery,
|
|
226
246
|
signalStore: sessionStore.signal,
|
|
247
|
+
preKeyStore: sessionStore.preKey,
|
|
227
248
|
defaultTimeoutMs: options.signalFetchKeyBundlesTimeoutMs
|
|
228
249
|
});
|
|
229
250
|
const generateUsyncSid = createUsyncSidGenerator();
|
|
@@ -236,24 +257,24 @@ export function buildWaClientDependencies(input) {
|
|
|
236
257
|
});
|
|
237
258
|
const signalIdentitySync = new SignalIdentitySyncApi({
|
|
238
259
|
logger,
|
|
239
|
-
query:
|
|
240
|
-
|
|
260
|
+
query: signalSystemQuery,
|
|
261
|
+
identityStore: sessionStore.identity,
|
|
241
262
|
defaultTimeoutMs: options.signalFetchKeyBundlesTimeoutMs
|
|
242
263
|
});
|
|
243
264
|
const signalMissingPreKeysSync = new SignalMissingPreKeysSyncApi({
|
|
244
265
|
logger,
|
|
245
|
-
query:
|
|
266
|
+
query: signalSystemQuery,
|
|
246
267
|
defaultTimeoutMs: options.signalFetchKeyBundlesTimeoutMs
|
|
247
268
|
});
|
|
248
269
|
const signalRotateKey = new SignalRotateKeyApi({
|
|
249
270
|
logger,
|
|
250
|
-
query:
|
|
271
|
+
query: signalSystemQuery,
|
|
251
272
|
signalStore: sessionStore.signal,
|
|
252
273
|
defaultTimeoutMs: options.signalFetchKeyBundlesTimeoutMs
|
|
253
274
|
});
|
|
254
275
|
const signalSessionSync = new SignalSessionSyncApi({
|
|
255
276
|
logger,
|
|
256
|
-
query:
|
|
277
|
+
query: signalSystemQuery,
|
|
257
278
|
defaultTimeoutMs: options.signalFetchKeyBundlesTimeoutMs
|
|
258
279
|
});
|
|
259
280
|
const authClient = new WaAuthClient({
|
|
@@ -261,11 +282,14 @@ export function buildWaClientDependencies(input) {
|
|
|
261
282
|
deviceOsDisplayName: options.deviceOsDisplayName,
|
|
262
283
|
devicePlatform: options.devicePlatform,
|
|
263
284
|
requireFullSync: options.requireFullSync,
|
|
264
|
-
version: options.version
|
|
285
|
+
version: options.version,
|
|
286
|
+
dangerous: options.dangerous,
|
|
287
|
+
mobileTransport: options.mobileTransport
|
|
265
288
|
}, {
|
|
266
289
|
logger,
|
|
267
290
|
authStore: sessionStore.auth,
|
|
268
291
|
signalStore: sessionStore.signal,
|
|
292
|
+
preKeyStore: sessionStore.preKey,
|
|
269
293
|
socket: {
|
|
270
294
|
sendNode: runtime.sendNode,
|
|
271
295
|
query: runtime.query
|
|
@@ -298,13 +322,17 @@ export function buildWaClientDependencies(input) {
|
|
|
298
322
|
const businessCoordinator = createBusinessCoordinator({
|
|
299
323
|
queryWithContext: runtime.queryWithContext
|
|
300
324
|
});
|
|
325
|
+
const emailCoordinator = createEmailCoordinator({
|
|
326
|
+
queryWithContext: runtime.queryWithContext
|
|
327
|
+
});
|
|
301
328
|
const retryTracker = createOutboundRetryTracker({
|
|
302
329
|
retryStore: sessionStore.retry,
|
|
303
330
|
logger
|
|
304
331
|
});
|
|
305
332
|
const sessionResolver = createSignalSessionResolver({
|
|
306
333
|
signalProtocol,
|
|
307
|
-
|
|
334
|
+
sessionStore: sessionStore.session,
|
|
335
|
+
identityStore: sessionStore.identity,
|
|
308
336
|
signalIdentitySync,
|
|
309
337
|
signalSessionSync,
|
|
310
338
|
logger
|
|
@@ -339,7 +367,19 @@ export function buildWaClientDependencies(input) {
|
|
|
339
367
|
numBuckets: options.privacyToken?.tcTokenNumBuckets,
|
|
340
368
|
senderDurationS: options.privacyToken?.tcTokenSenderDurationS,
|
|
341
369
|
senderNumBuckets: options.privacyToken?.tcTokenSenderNumBuckets,
|
|
342
|
-
maxDurationS: options.privacyToken?.tcTokenMaxDurationS
|
|
370
|
+
maxDurationS: options.privacyToken?.tcTokenMaxDurationS,
|
|
371
|
+
getConfigOverrides: () => ({
|
|
372
|
+
durationS: abPropsCoordinator.getConfigValue('tctoken_duration'),
|
|
373
|
+
numBuckets: abPropsCoordinator.getConfigValue('tctoken_num_buckets'),
|
|
374
|
+
senderDurationS: abPropsCoordinator.getConfigValue('tctoken_duration_sender'),
|
|
375
|
+
senderNumBuckets: abPropsCoordinator.getConfigValue('tctoken_num_buckets_sender')
|
|
376
|
+
})
|
|
377
|
+
});
|
|
378
|
+
const abPropsCoordinator = new WaAbPropsCoordinator({
|
|
379
|
+
logger,
|
|
380
|
+
runtime: {
|
|
381
|
+
queryWithContext: runtime.queryWithContext
|
|
382
|
+
}
|
|
343
383
|
});
|
|
344
384
|
let messageDispatch;
|
|
345
385
|
const appStateSyncKeyProtocol = createAppStateSyncKeyProtocol({
|
|
@@ -361,7 +401,10 @@ export function buildWaClientDependencies(input) {
|
|
|
361
401
|
senderKeyManager,
|
|
362
402
|
signalProtocol,
|
|
363
403
|
signalStore: sessionStore.signal,
|
|
404
|
+
sessionStore: sessionStore.session,
|
|
405
|
+
identityStore: sessionStore.identity,
|
|
364
406
|
deviceListStore: sessionStore.deviceList,
|
|
407
|
+
messageSecretStore: sessionStore.messageSecret,
|
|
365
408
|
getCurrentMeJid,
|
|
366
409
|
getCurrentMeLid,
|
|
367
410
|
getCurrentSignedIdentity,
|
|
@@ -371,12 +414,16 @@ export function buildWaClientDependencies(input) {
|
|
|
371
414
|
to: recipientJid,
|
|
372
415
|
message: toError(err).message
|
|
373
416
|
}));
|
|
374
|
-
}
|
|
417
|
+
},
|
|
418
|
+
getIcdcHashLength: () => abPropsCoordinator.getConfigValue('md_icdc_hash_length'),
|
|
419
|
+
mobileMessageIdFormat: options.mobileTransport !== undefined
|
|
375
420
|
});
|
|
376
421
|
const retryCoordinator = new WaRetryCoordinator({
|
|
377
422
|
logger,
|
|
378
423
|
retryStore: sessionStore.retry,
|
|
379
424
|
signalStore: sessionStore.signal,
|
|
425
|
+
preKeyStore: sessionStore.preKey,
|
|
426
|
+
sessionStore: sessionStore.session,
|
|
380
427
|
senderKeyStore: sessionStore.senderKey,
|
|
381
428
|
signalProtocol,
|
|
382
429
|
signalDeviceSync,
|
|
@@ -395,7 +442,9 @@ export function buildWaClientDependencies(input) {
|
|
|
395
442
|
store: sessionStore.appState,
|
|
396
443
|
onMissingKeys: async ({ keyIds }) => {
|
|
397
444
|
await messageDispatch.requestAppStateSyncKeys(keyIds);
|
|
398
|
-
}
|
|
445
|
+
},
|
|
446
|
+
skipMacVerification: options.dangerous?.disableAppStateMacVerification,
|
|
447
|
+
mobilePrimary: options.mobileTransport !== undefined
|
|
399
448
|
});
|
|
400
449
|
const appStateMutations = new WaAppStateMutationCoordinator({
|
|
401
450
|
logger,
|
|
@@ -417,7 +466,8 @@ export function buildWaClientDependencies(input) {
|
|
|
417
466
|
}
|
|
418
467
|
scheduleReconnectAfterPairing = () => connectionManager?.scheduleReconnectAfterPairing();
|
|
419
468
|
const disconnectWithClientSideEffects = async (reason, isLogout, code) => {
|
|
420
|
-
|
|
469
|
+
abPropsCoordinator.reset();
|
|
470
|
+
offlineResume.reset();
|
|
421
471
|
await connectionManager?.disconnect();
|
|
422
472
|
runtime.emitEvent('connection', {
|
|
423
473
|
status: 'close',
|
|
@@ -474,8 +524,16 @@ export function buildWaClientDependencies(input) {
|
|
|
474
524
|
syncAppState: runtime.syncAppState,
|
|
475
525
|
generateUsyncSid
|
|
476
526
|
}, dirtyBits);
|
|
527
|
+
const offlineResume = new WaOfflineResumeCoordinator({
|
|
528
|
+
logger,
|
|
529
|
+
runtime: {
|
|
530
|
+
sendNode: (node) => nodeOrchestrator.sendNode(node, false),
|
|
531
|
+
emitOfflineResume: (event) => runtime.emitEvent('offline_resume', event)
|
|
532
|
+
}
|
|
533
|
+
});
|
|
477
534
|
const incomingNode = new WaIncomingNodeCoordinator({
|
|
478
535
|
logger,
|
|
536
|
+
offlineResume,
|
|
479
537
|
runtime: createIncomingNodeRuntime({
|
|
480
538
|
logger,
|
|
481
539
|
emitEvent: runtime.emitEvent,
|
|
@@ -578,12 +636,12 @@ export function buildWaClientDependencies(input) {
|
|
|
578
636
|
return true;
|
|
579
637
|
}
|
|
580
638
|
}
|
|
581
|
-
const oldIdentity = await sessionStore.
|
|
639
|
+
const oldIdentity = await sessionStore.identity.getRemoteIdentity(address);
|
|
582
640
|
if (oldIdentity) {
|
|
583
641
|
logger.info('identity-change: clearing session', {
|
|
584
642
|
jid: parsed.fromJid
|
|
585
643
|
});
|
|
586
|
-
await sessionStore.
|
|
644
|
+
await sessionStore.session.deleteSession(address);
|
|
587
645
|
const userJid = toUserJid(parsed.fromJid);
|
|
588
646
|
await trustedContactToken.reissueOnIdentityChange(userJid).catch((error) => {
|
|
589
647
|
logger.warn('identity-change: reissue tc token failed', {
|
|
@@ -634,7 +692,7 @@ export function buildWaClientDependencies(input) {
|
|
|
634
692
|
server: baseAddress.server,
|
|
635
693
|
device: device.deviceId
|
|
636
694
|
};
|
|
637
|
-
await sessionStore.
|
|
695
|
+
await sessionStore.session.deleteSession(address).catch((error) => {
|
|
638
696
|
logger.warn('devices-notification: delete session failed', {
|
|
639
697
|
message: toError(error).message
|
|
640
698
|
});
|
|
@@ -696,9 +754,30 @@ export function buildWaClientDependencies(input) {
|
|
|
696
754
|
return true;
|
|
697
755
|
}
|
|
698
756
|
});
|
|
757
|
+
// AB Props: sync after successful login and on server notification
|
|
758
|
+
incomingNode.registerIncomingHandler({
|
|
759
|
+
tag: WA_NODE_TAGS.NOTIFICATION,
|
|
760
|
+
subtype: WA_NOTIFICATION_TYPES.SERVER,
|
|
761
|
+
prepend: true,
|
|
762
|
+
handler: async (node) => {
|
|
763
|
+
const firstChild = getFirstNodeChild(node);
|
|
764
|
+
if (!firstChild || firstChild.tag !== WA_NODE_TAGS.ABPROPS) {
|
|
765
|
+
return false;
|
|
766
|
+
}
|
|
767
|
+
const ackNode = buildAckNode({
|
|
768
|
+
kind: 'notification',
|
|
769
|
+
node,
|
|
770
|
+
includeType: false
|
|
771
|
+
});
|
|
772
|
+
await runtime.sendNode(ackNode);
|
|
773
|
+
abPropsCoordinator.sync();
|
|
774
|
+
return true;
|
|
775
|
+
}
|
|
776
|
+
});
|
|
699
777
|
passiveTasks = new WaPassiveTasksCoordinator({
|
|
700
778
|
logger,
|
|
701
779
|
signalStore: sessionStore.signal,
|
|
780
|
+
preKeyStore: sessionStore.preKey,
|
|
702
781
|
signalDigestSync,
|
|
703
782
|
signalRotateKey,
|
|
704
783
|
runtime: createPassiveTasksRuntime({
|
|
@@ -706,8 +785,11 @@ export function buildWaClientDependencies(input) {
|
|
|
706
785
|
authClient,
|
|
707
786
|
nodeOrchestrator,
|
|
708
787
|
receiptQueue,
|
|
709
|
-
getCurrentCredentials
|
|
710
|
-
|
|
788
|
+
getCurrentCredentials,
|
|
789
|
+
abPropsCoordinator
|
|
790
|
+
}),
|
|
791
|
+
mobilePrimary: options.mobileTransport !== undefined,
|
|
792
|
+
appStateSync
|
|
711
793
|
});
|
|
712
794
|
return {
|
|
713
795
|
nodeTransport,
|
|
@@ -736,9 +818,10 @@ export function buildWaClientDependencies(input) {
|
|
|
736
818
|
privacyCoordinator,
|
|
737
819
|
profileCoordinator,
|
|
738
820
|
businessCoordinator,
|
|
821
|
+
emailCoordinator,
|
|
739
822
|
receiptQueue,
|
|
740
|
-
keyShareCoordinator,
|
|
741
823
|
connectionManager,
|
|
742
|
-
trustedContactToken
|
|
824
|
+
trustedContactToken,
|
|
825
|
+
abPropsCoordinator
|
|
743
826
|
};
|
|
744
827
|
}
|