zapo-js 0.1.2 → 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 +16 -4
- package/dist/appstate/WaAppStateCrypto.js +50 -42
- package/dist/appstate/WaAppStateSyncClient.js +215 -133
- package/dist/appstate/{store/sqlite.js → encoding.js} +13 -8
- package/dist/appstate/index.js +9 -7
- package/dist/appstate/utils.js +0 -5
- package/dist/auth/WaAuthClient.js +55 -57
- package/dist/auth/credentials-flow.js +195 -0
- package/dist/auth/index.js +1 -6
- package/dist/auth/pairing/WaPairingFlow.js +39 -32
- package/dist/auth/pairing/{WaPairingCodeCrypto.js → pairing-code-crypto.js} +35 -17
- package/dist/client/WaClient.js +338 -174
- package/dist/client/WaClientFactory.js +399 -66
- package/dist/client/connection/WaConnectionManager.js +23 -11
- package/dist/client/coordinators/WaAbPropsCoordinator.js +141 -0
- package/dist/client/coordinators/WaBusinessCoordinator.js +232 -0
- package/dist/client/coordinators/WaEmailCoordinator.js +63 -0
- package/dist/client/coordinators/WaGroupCoordinator.js +11 -7
- package/dist/client/coordinators/WaIncomingNodeCoordinator.js +34 -8
- package/dist/client/coordinators/WaMessageDispatchCoordinator.js +341 -118
- package/dist/client/coordinators/WaOfflineResumeCoordinator.js +114 -0
- package/dist/client/coordinators/WaPassiveTasksCoordinator.js +97 -36
- package/dist/client/coordinators/WaPrivacyCoordinator.js +134 -0
- package/dist/client/coordinators/WaProfileCoordinator.js +214 -0
- package/dist/client/coordinators/WaRetryCoordinator.js +184 -30
- package/dist/client/coordinators/WaStreamControlCoordinator.js +18 -11
- package/dist/client/coordinators/WaTrustedContactTokenCoordinator.js +184 -0
- package/dist/client/dirty.js +41 -21
- package/dist/client/events/abprops.js +43 -0
- package/dist/client/events/devices.js +72 -0
- package/dist/client/events/group.js +3 -11
- package/dist/client/events/identity.js +22 -0
- package/dist/client/events/privacy-token.js +38 -0
- package/dist/client/events/registration.js +42 -0
- package/dist/client/history-sync.js +50 -9
- package/dist/client/incoming.js +74 -7
- package/dist/client/mailbox.js +40 -23
- package/dist/client/media.js +243 -0
- package/dist/client/messages.js +245 -92
- package/dist/client/messaging/fanout.js +21 -11
- package/dist/client/messaging/participants.js +6 -4
- package/dist/client/persistence/WriteBehindPersistence.js +129 -0
- package/dist/client/tokens/cs-token.js +50 -0
- package/dist/client/tokens/tc-token.js +25 -0
- package/dist/crypto/core/index.js +5 -2
- package/dist/crypto/core/keys.js +4 -4
- package/dist/crypto/core/nonce.js +2 -0
- package/dist/crypto/core/primitives.js +0 -8
- package/dist/crypto/core/random.js +24 -8
- package/dist/crypto/core/xeddsa.js +57 -0
- package/dist/crypto/curves/X25519.js +43 -6
- package/dist/crypto/curves/constants.js +2 -1
- package/dist/crypto/index.js +3 -0
- package/dist/crypto/math/constants.js +13 -36
- package/dist/crypto/math/edwards.js +171 -44
- package/dist/crypto/math/fe.js +706 -0
- package/dist/crypto/math/mod.js +10 -3
- package/dist/esm/appstate/WaAppStateCrypto.js +40 -32
- package/dist/esm/appstate/WaAppStateSyncClient.js +206 -124
- package/dist/esm/appstate/{store/sqlite.js → encoding.js} +13 -8
- package/dist/esm/appstate/index.js +2 -2
- package/dist/esm/appstate/{WaAppStateSyncResponseParser.js → response-parser.js} +1 -1
- package/dist/esm/appstate/utils.js +2 -5
- package/dist/esm/auth/WaAuthClient.js +52 -54
- package/dist/esm/auth/credentials-flow.js +190 -0
- package/dist/esm/auth/index.js +0 -2
- package/dist/esm/auth/pairing/WaPairingFlow.js +39 -32
- package/dist/esm/auth/pairing/{WaPairingCodeCrypto.js → pairing-code-crypto.js} +26 -10
- package/dist/esm/client/WaClient.js +339 -175
- package/dist/esm/client/WaClientFactory.js +401 -68
- package/dist/esm/client/connection/WaConnectionManager.js +23 -11
- package/dist/esm/client/coordinators/WaAbPropsCoordinator.js +137 -0
- package/dist/esm/client/coordinators/WaBusinessCoordinator.js +229 -0
- package/dist/esm/client/coordinators/WaEmailCoordinator.js +60 -0
- package/dist/esm/client/coordinators/WaGroupCoordinator.js +11 -7
- package/dist/esm/client/coordinators/WaIncomingNodeCoordinator.js +36 -10
- package/dist/esm/client/coordinators/WaMessageDispatchCoordinator.js +337 -114
- package/dist/esm/client/coordinators/WaOfflineResumeCoordinator.js +110 -0
- package/dist/esm/client/coordinators/WaPassiveTasksCoordinator.js +97 -36
- package/dist/esm/client/coordinators/WaPrivacyCoordinator.js +131 -0
- package/dist/esm/client/coordinators/WaProfileCoordinator.js +211 -0
- package/dist/esm/client/coordinators/WaRetryCoordinator.js +186 -32
- package/dist/esm/client/coordinators/WaStreamControlCoordinator.js +19 -12
- package/dist/esm/client/coordinators/WaTrustedContactTokenCoordinator.js +180 -0
- package/dist/esm/client/dirty.js +41 -21
- package/dist/esm/client/events/abprops.js +40 -0
- package/dist/esm/client/events/devices.js +68 -0
- package/dist/esm/client/events/group.js +3 -11
- package/dist/esm/client/events/identity.js +19 -0
- package/dist/esm/client/events/privacy-token.js +35 -0
- package/dist/esm/client/events/registration.js +39 -0
- package/dist/esm/client/history-sync.js +50 -9
- package/dist/esm/client/incoming.js +74 -8
- package/dist/esm/client/mailbox.js +40 -23
- package/dist/esm/client/media.js +234 -0
- package/dist/esm/client/messages.js +244 -91
- package/dist/esm/client/messaging/fanout.js +22 -12
- package/dist/esm/client/messaging/participants.js +6 -4
- package/dist/esm/client/persistence/WriteBehindPersistence.js +125 -0
- package/dist/esm/client/tokens/cs-token.js +46 -0
- package/dist/esm/client/tokens/tc-token.js +18 -0
- package/dist/esm/crypto/core/index.js +3 -2
- package/dist/esm/crypto/core/keys.js +1 -1
- package/dist/esm/crypto/core/nonce.js +2 -0
- package/dist/esm/crypto/core/primitives.js +0 -7
- package/dist/esm/crypto/core/random.js +23 -7
- package/dist/esm/crypto/core/xeddsa.js +53 -0
- package/dist/esm/crypto/curves/X25519.js +45 -8
- package/dist/esm/crypto/curves/constants.js +1 -0
- package/dist/esm/crypto/index.js +1 -0
- package/dist/esm/crypto/math/constants.js +12 -35
- package/dist/esm/crypto/math/edwards.js +174 -47
- package/dist/esm/crypto/math/fe.js +691 -0
- package/dist/esm/crypto/math/mod.js +10 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/infra/perf/BackgroundQueue.js +478 -0
- package/dist/esm/infra/perf/BoundedTaskQueue.js +3 -1
- package/dist/esm/infra/perf/PromiseDedup.js +20 -0
- package/dist/esm/infra/perf/SharedExclusiveGate.js +109 -0
- package/dist/esm/infra/perf/StoreLock.js +80 -0
- package/dist/esm/media/WaMediaCrypto.js +332 -55
- package/dist/esm/media/WaMediaTransferClient.js +69 -220
- package/dist/esm/media/constants.js +4 -1
- package/dist/esm/media/processor.js +1 -0
- package/dist/esm/message/WaMessageClient.js +26 -19
- package/dist/esm/message/addon-crypto.js +130 -3
- package/dist/esm/message/content.js +206 -14
- package/dist/esm/message/icdc.js +76 -0
- package/dist/esm/message/incoming.js +38 -24
- package/dist/esm/message/phash.js +35 -13
- package/dist/esm/message/reporting-token.js +17 -30
- package/dist/esm/message/use-case-secret.js +1 -1
- package/dist/esm/protocol/abprops.js +159 -0
- package/dist/esm/protocol/appstate.js +9 -40
- package/dist/esm/protocol/browser.js +24 -18
- package/dist/esm/protocol/constants.js +8 -4
- package/dist/esm/protocol/defaults.js +6 -0
- package/dist/esm/protocol/email.js +30 -0
- package/dist/esm/protocol/index.js +1 -2
- package/dist/esm/protocol/jid.js +142 -39
- package/dist/esm/protocol/message.js +61 -1
- package/dist/esm/protocol/nodes.js +8 -2
- package/dist/esm/protocol/notification.js +9 -1
- package/dist/esm/protocol/privacy-token.js +17 -0
- package/dist/esm/protocol/privacy.js +55 -0
- package/dist/esm/protocol/stream.js +26 -1
- package/dist/esm/retry/codec.js +216 -0
- package/dist/esm/retry/constants.js +1 -1
- package/dist/esm/retry/index.js +2 -2
- package/dist/esm/retry/parse.js +50 -30
- package/dist/esm/retry/reason.js +1 -1
- package/dist/esm/retry/replay.js +11 -7
- package/dist/esm/retry/tracker.js +50 -12
- package/dist/esm/signal/api/SignalDeviceSyncApi.js +52 -32
- package/dist/esm/signal/api/SignalDigestSyncApi.js +21 -15
- package/dist/esm/signal/api/SignalIdentitySyncApi.js +30 -15
- package/dist/esm/signal/api/SignalMissingPreKeysSyncApi.js +19 -8
- package/dist/esm/signal/api/SignalRotateKeyApi.js +4 -2
- package/dist/esm/signal/api/SignalSessionSyncApi.js +17 -8
- package/dist/esm/signal/api/result-map.js +10 -0
- package/dist/esm/signal/constants.js +0 -4
- package/dist/esm/signal/crypto/WaAdvSignature.js +5 -45
- package/dist/esm/signal/crypto/constants.js +0 -4
- package/dist/esm/signal/{store/sqlite.js → encoding.js} +40 -29
- package/dist/esm/signal/group/SenderKeyChain.js +3 -3
- package/dist/esm/signal/group/SenderKeyCodec.js +8 -8
- package/dist/esm/signal/group/SenderKeyManager.js +131 -109
- package/dist/esm/signal/index.js +1 -0
- package/dist/esm/signal/registration/keygen.js +8 -5
- package/dist/esm/signal/registration/utils.js +3 -2
- package/dist/esm/signal/session/SignalProtocol.js +158 -81
- 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 +140 -105
- 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/privacy-token.store.js +1 -0
- package/dist/esm/store/contracts/session.store.js +1 -0
- package/dist/esm/store/createStore.js +143 -193
- package/dist/esm/store/index.js +5 -10
- package/dist/esm/store/locks/appstate.lock.js +26 -0
- package/dist/esm/store/locks/auth.lock.js +15 -0
- package/dist/esm/store/locks/contact.lock.js +20 -0
- package/dist/esm/store/locks/device-list.lock.js +20 -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/message.lock.js +21 -0
- package/dist/esm/store/locks/participants.lock.js +20 -0
- package/dist/esm/store/locks/pre-key.lock.js +27 -0
- package/dist/esm/store/locks/privacy-token.lock.js +18 -0
- package/dist/esm/store/locks/retry.lock.js +29 -0
- package/dist/esm/store/locks/sender-key.lock.js +52 -0
- package/dist/esm/store/locks/session.lock.js +19 -0
- package/dist/esm/store/locks/signal.lock.js +39 -0
- package/dist/esm/store/locks/thread.lock.js +21 -0
- package/dist/esm/store/noop.store.js +21 -1
- package/dist/esm/store/providers/memory/appstate.store.js +22 -24
- package/dist/esm/store/providers/memory/device-list.store.js +13 -5
- 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/privacy-token.store.js +43 -0
- package/dist/esm/store/providers/memory/retry.store.js +99 -10
- package/dist/esm/store/providers/memory/sender-key.store.js +6 -1
- package/dist/esm/store/providers/memory/session.store.js +45 -0
- package/dist/esm/store/providers/memory/signal.store.js +1 -147
- package/dist/esm/transport/WaComms.js +7 -4
- package/dist/esm/transport/WaWebSocket.js +9 -7
- package/dist/esm/transport/binary/constants.js +0 -30
- package/dist/esm/transport/binary/decoder.js +4 -4
- package/dist/esm/transport/binary/encoder.js +8 -15
- package/dist/esm/transport/binary/index.js +0 -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 +37 -22
- package/dist/esm/transport/node/builders/abprops.js +20 -0
- package/dist/esm/transport/node/builders/business.js +129 -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/global.js +370 -0
- package/dist/esm/transport/node/builders/message.js +63 -239
- package/dist/esm/transport/node/builders/offline.js +14 -0
- package/dist/esm/transport/node/builders/pairing.js +0 -24
- 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 +37 -0
- package/dist/esm/transport/node/builders/privacy.js +48 -0
- package/dist/esm/transport/node/builders/profile.js +70 -0
- package/dist/esm/transport/node/builders/retry.js +11 -23
- package/dist/esm/transport/node/builders/usync.js +6 -2
- package/dist/esm/transport/node/helpers.js +43 -1
- 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/node/usync.js +3 -33
- package/dist/esm/transport/node/xml.js +35 -14
- package/dist/esm/transport/noise/WaClientPayload.js +24 -19
- 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 +76 -34
- package/dist/esm/transport/noise/WaNoiseSocket.js +8 -4
- package/dist/esm/transport/stream/parse.js +8 -4
- package/dist/esm/util/bytes.js +22 -18
- package/dist/esm/util/index.js +5 -0
- package/dist/esm/util/primitives.js +3 -2
- package/dist/index.js +7 -1
- package/dist/infra/perf/BackgroundQueue.js +482 -0
- package/dist/infra/perf/BoundedTaskQueue.js +3 -1
- package/dist/infra/perf/PromiseDedup.js +24 -0
- package/dist/infra/perf/SharedExclusiveGate.js +113 -0
- package/dist/infra/perf/StoreLock.js +84 -0
- package/dist/media/WaMediaCrypto.js +328 -51
- package/dist/media/WaMediaTransferClient.js +72 -253
- package/dist/media/constants.js +5 -2
- package/dist/media/processor.js +2 -0
- package/dist/message/WaMessageClient.js +26 -19
- package/dist/message/addon-crypto.js +131 -0
- package/dist/message/content.js +211 -14
- package/dist/message/icdc.js +81 -0
- package/dist/message/incoming.js +38 -24
- package/dist/message/phash.js +35 -13
- package/dist/message/reporting-token.js +16 -30
- package/dist/message/use-case-secret.js +1 -1
- package/dist/protocol/abprops.js +163 -0
- package/dist/protocol/appstate.js +10 -41
- package/dist/protocol/browser.js +25 -18
- package/dist/protocol/constants.js +33 -2
- package/dist/protocol/defaults.js +6 -0
- package/dist/protocol/email.js +33 -0
- package/dist/protocol/index.js +8 -5
- package/dist/protocol/jid.js +149 -39
- package/dist/protocol/message.js +62 -2
- package/dist/protocol/nodes.js +8 -2
- package/dist/protocol/notification.js +10 -2
- package/dist/protocol/privacy-token.js +20 -0
- package/dist/protocol/privacy.js +58 -0
- package/dist/protocol/stream.js +27 -2
- package/dist/retry/codec.js +220 -0
- package/dist/retry/constants.js +1 -1
- package/dist/retry/index.js +5 -5
- package/dist/retry/parse.js +51 -30
- package/dist/retry/reason.js +1 -1
- package/dist/retry/replay.js +10 -6
- package/dist/retry/tracker.js +50 -12
- package/dist/signal/api/SignalDeviceSyncApi.js +51 -31
- package/dist/signal/api/SignalDigestSyncApi.js +21 -15
- package/dist/signal/api/SignalIdentitySyncApi.js +29 -14
- package/dist/signal/api/SignalMissingPreKeysSyncApi.js +17 -6
- package/dist/signal/api/SignalRotateKeyApi.js +4 -2
- package/dist/signal/api/SignalSessionSyncApi.js +16 -7
- package/dist/signal/api/result-map.js +13 -0
- package/dist/signal/constants.js +1 -5
- package/dist/signal/crypto/WaAdvSignature.js +2 -44
- package/dist/signal/crypto/constants.js +1 -5
- package/dist/signal/{store/sqlite.js → encoding.js} +41 -25
- package/dist/signal/group/SenderKeyChain.js +2 -2
- package/dist/signal/group/SenderKeyCodec.js +8 -8
- package/dist/signal/group/SenderKeyManager.js +130 -108
- package/dist/signal/index.js +13 -1
- package/dist/signal/registration/keygen.js +7 -4
- package/dist/signal/registration/utils.js +3 -2
- package/dist/signal/session/SignalProtocol.js +158 -81
- 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 +138 -103
- 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/privacy-token.store.js +2 -0
- package/dist/store/contracts/session.store.js +2 -0
- package/dist/store/createStore.js +142 -192
- package/dist/store/index.js +23 -33
- package/dist/store/locks/appstate.lock.js +29 -0
- package/dist/store/locks/auth.lock.js +18 -0
- package/dist/store/locks/contact.lock.js +23 -0
- package/dist/store/locks/device-list.lock.js +23 -0
- package/dist/store/locks/identity.lock.js +19 -0
- package/dist/store/locks/message-secret.lock.js +20 -0
- package/dist/store/locks/message.lock.js +24 -0
- package/dist/store/locks/participants.lock.js +23 -0
- package/dist/store/locks/pre-key.lock.js +30 -0
- package/dist/store/locks/privacy-token.lock.js +21 -0
- package/dist/store/locks/retry.lock.js +32 -0
- package/dist/store/locks/sender-key.lock.js +55 -0
- package/dist/store/locks/session.lock.js +22 -0
- package/dist/store/locks/signal.lock.js +42 -0
- package/dist/store/locks/thread.lock.js +24 -0
- package/dist/store/noop.store.js +22 -2
- package/dist/store/providers/memory/appstate.store.js +22 -24
- package/dist/store/providers/memory/device-list.store.js +13 -5
- 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/privacy-token.store.js +47 -0
- package/dist/store/providers/memory/retry.store.js +98 -9
- package/dist/store/providers/memory/sender-key.store.js +6 -1
- package/dist/store/providers/memory/session.store.js +49 -0
- package/dist/store/providers/memory/signal.store.js +1 -147
- package/dist/transport/WaComms.js +7 -4
- package/dist/transport/WaWebSocket.js +9 -7
- package/dist/transport/binary/constants.js +1 -31
- package/dist/transport/binary/decoder.js +4 -4
- package/dist/transport/binary/encoder.js +8 -15
- package/dist/transport/binary/index.js +0 -4
- 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 +36 -21
- package/dist/transport/node/builders/abprops.js +23 -0
- package/dist/transport/node/builders/business.js +137 -0
- package/dist/transport/node/builders/device.js +14 -0
- package/dist/transport/node/builders/email.js +72 -0
- package/dist/transport/node/builders/global.js +375 -0
- package/dist/transport/node/builders/message.js +64 -245
- package/dist/transport/node/builders/offline.js +17 -0
- package/dist/transport/node/builders/pairing.js +0 -26
- 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 +42 -0
- package/dist/transport/node/builders/privacy.js +55 -0
- package/dist/transport/node/builders/profile.js +78 -0
- package/dist/transport/node/builders/retry.js +10 -22
- package/dist/transport/node/builders/usync.js +6 -2
- package/dist/transport/node/helpers.js +46 -1
- 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/node/usync.js +2 -32
- package/dist/transport/node/xml.js +35 -14
- package/dist/transport/noise/WaClientPayload.js +26 -21
- 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 +75 -33
- package/dist/transport/noise/WaNoiseSocket.js +8 -4
- package/dist/transport/stream/parse.js +7 -3
- package/dist/types/appstate/WaAppStateCrypto.d.ts +11 -8
- package/dist/types/appstate/WaAppStateSyncClient.d.ts +6 -2
- package/dist/types/appstate/encoding.d.ts +7 -0
- package/dist/types/appstate/index.d.ts +3 -3
- 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/appstate/utils.d.ts +0 -2
- package/dist/types/auth/WaAuthClient.d.ts +9 -3
- package/dist/types/auth/credentials-flow.d.ts +20 -0
- package/dist/types/auth/index.d.ts +0 -2
- 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 +41 -0
- package/dist/types/client/WaClient.d.ts +44 -18
- package/dist/types/client/WaClientFactory.d.ts +22 -8
- package/dist/types/client/connection/WaConnectionManager.d.ts +2 -0
- package/dist/types/client/coordinators/WaAbPropsCoordinator.d.ts +26 -0
- package/dist/types/client/coordinators/WaBusinessCoordinator.d.ts +57 -0
- package/dist/types/client/coordinators/WaEmailCoordinator.d.ts +24 -0
- package/dist/types/client/coordinators/WaIncomingNodeCoordinator.d.ts +9 -2
- package/dist/types/client/coordinators/WaMessageDispatchCoordinator.d.ts +29 -2
- package/dist/types/client/coordinators/WaOfflineResumeCoordinator.d.ts +31 -0
- package/dist/types/client/coordinators/WaPassiveTasksCoordinator.d.ts +16 -1
- package/dist/types/client/coordinators/WaPrivacyCoordinator.d.ts +26 -0
- package/dist/types/client/coordinators/WaProfileCoordinator.d.ts +38 -0
- package/dist/types/client/coordinators/WaRetryCoordinator.d.ts +12 -0
- package/dist/types/client/coordinators/WaStreamControlCoordinator.d.ts +3 -2
- package/dist/types/client/coordinators/WaTrustedContactTokenCoordinator.d.ts +55 -0
- package/dist/types/client/dirty.d.ts +3 -1
- package/dist/types/client/events/abprops.d.ts +14 -0
- package/dist/types/client/events/devices.d.ts +20 -0
- package/dist/types/client/events/identity.d.ts +9 -0
- package/dist/types/client/events/privacy-token.d.ts +7 -0
- package/dist/types/client/events/registration.d.ts +17 -0
- package/dist/types/client/history-sync.d.ts +9 -6
- package/dist/types/client/incoming.d.ts +9 -2
- package/dist/types/client/index.d.ts +1 -1
- package/dist/types/client/mailbox.d.ts +5 -5
- package/dist/types/client/media.d.ts +31 -0
- package/dist/types/client/messages.d.ts +3 -2
- package/dist/types/client/persistence/WriteBehindPersistence.d.ts +34 -0
- package/dist/types/client/tokens/cs-token.d.ts +10 -0
- package/dist/types/client/tokens/tc-token.d.ts +5 -0
- package/dist/types/client/types.d.ts +151 -4
- package/dist/types/crypto/core/index.d.ts +3 -2
- package/dist/types/crypto/core/nonce.d.ts +2 -0
- package/dist/types/crypto/core/primitives.d.ts +1 -2
- package/dist/types/crypto/core/random.d.ts +2 -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 +2 -0
- package/dist/types/crypto/math/constants.d.ts +4 -2
- package/dist/types/crypto/math/fe.d.ts +30 -0
- package/dist/types/crypto/math/mod.d.ts +0 -2
- package/dist/types/crypto/math/types.d.ts +11 -4
- package/dist/types/index.d.ts +6 -3
- 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/BackgroundQueue.d.ts +58 -0
- package/dist/types/infra/perf/PromiseDedup.d.ts +4 -0
- package/dist/types/infra/perf/SharedExclusiveGate.d.ts +17 -0
- package/dist/types/infra/perf/StoreLock.d.ts +11 -0
- package/dist/types/media/WaMediaCrypto.d.ts +16 -6
- package/dist/types/media/WaMediaTransferClient.d.ts +6 -23
- package/dist/types/media/constants.d.ts +3 -1
- package/dist/types/media/index.d.ts +2 -1
- package/dist/types/media/processor.d.ts +28 -0
- package/dist/types/media/types.d.ts +19 -5
- package/dist/types/message/addon-crypto.d.ts +34 -3
- package/dist/types/message/content.d.ts +11 -1
- package/dist/types/message/icdc.d.ts +13 -0
- package/dist/types/message/reporting-token.d.ts +0 -1
- package/dist/types/message/types.d.ts +42 -11
- package/dist/types/protocol/abprops.d.ts +142 -0
- package/dist/types/protocol/appstate.d.ts +0 -11
- package/dist/types/protocol/browser.d.ts +1 -0
- package/dist/types/protocol/constants.d.ts +12 -4
- package/dist/types/protocol/defaults.d.ts +6 -0
- package/dist/types/protocol/email.d.ts +32 -0
- package/dist/types/protocol/index.d.ts +1 -2
- package/dist/types/protocol/jid.d.ts +20 -2
- package/dist/types/protocol/message.d.ts +60 -0
- package/dist/types/protocol/nodes.d.ts +6 -0
- package/dist/types/protocol/notification.d.ts +8 -0
- package/dist/types/protocol/privacy-token.d.ts +17 -0
- package/dist/types/protocol/privacy.d.ts +75 -0
- package/dist/types/protocol/stream.d.ts +31 -0
- package/dist/types/retry/codec.d.ts +3 -0
- package/dist/types/retry/index.d.ts +3 -3
- package/dist/types/retry/parse.d.ts +5 -2
- package/dist/types/retry/reason.d.ts +1 -1
- package/dist/types/retry/tracker.d.ts +1 -0
- package/dist/types/retry/types.d.ts +6 -1
- package/dist/types/signal/api/SignalDeviceSyncApi.d.ts +2 -1
- package/dist/types/signal/api/SignalDigestSyncApi.d.ts +9 -0
- package/dist/types/signal/api/SignalIdentitySyncApi.d.ts +5 -3
- package/dist/types/signal/api/SignalRotateKeyApi.d.ts +4 -5
- package/dist/types/signal/api/SignalSessionSyncApi.d.ts +8 -6
- package/dist/types/signal/api/result-map.d.ts +1 -0
- package/dist/types/signal/constants.d.ts +0 -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/{store/sqlite.d.ts → encoding.d.ts} +9 -3
- package/dist/types/signal/group/SenderKeyChain.d.ts +1 -1
- package/dist/types/signal/group/SenderKeyManager.d.ts +17 -7
- package/dist/types/signal/index.d.ts +2 -0
- package/dist/types/signal/registration/utils.d.ts +2 -1
- package/dist/types/signal/session/SignalProtocol.d.ts +21 -6
- package/dist/types/signal/session/SignalSerializer.d.ts +2 -1
- package/dist/types/signal/session/resolver.d.ts +11 -4
- package/dist/types/signal/types.d.ts +16 -4
- package/dist/types/store/contracts/appstate.store.d.ts +1 -1
- 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/privacy-token.store.d.ts +16 -0
- package/dist/types/store/contracts/retry.store.d.ts +7 -0
- package/dist/types/store/contracts/session.store.d.ts +14 -0
- package/dist/types/store/contracts/signal.store.d.ts +1 -27
- package/dist/types/store/createStore.d.ts +1 -1
- package/dist/types/store/index.d.ts +12 -12
- package/dist/types/store/locks/appstate.lock.d.ts +3 -0
- package/dist/types/store/locks/auth.lock.d.ts +3 -0
- package/dist/types/store/locks/contact.lock.d.ts +3 -0
- package/dist/types/store/locks/device-list.lock.d.ts +2 -0
- 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/message.lock.d.ts +3 -0
- package/dist/types/store/locks/participants.lock.d.ts +2 -0
- package/dist/types/store/locks/pre-key.lock.d.ts +3 -0
- package/dist/types/store/locks/privacy-token.lock.d.ts +2 -0
- package/dist/types/store/locks/retry.lock.d.ts +2 -0
- package/dist/types/store/locks/sender-key.lock.d.ts +3 -0
- package/dist/types/store/locks/session.lock.d.ts +3 -0
- package/dist/types/store/locks/signal.lock.d.ts +3 -0
- package/dist/types/store/locks/thread.lock.d.ts +3 -0
- package/dist/types/store/noop.store.d.ts +4 -0
- package/dist/types/store/providers/memory/appstate.store.d.ts +1 -1
- 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/privacy-token.store.d.ts +13 -0
- package/dist/types/store/providers/memory/retry.store.d.ts +15 -1
- package/dist/types/store/providers/memory/session.store.d.ts +21 -0
- package/dist/types/store/providers/memory/signal.store.d.ts +2 -43
- package/dist/types/store/providers/memory/thread.store.d.ts +1 -1
- package/dist/types/store/types.d.ts +69 -61
- package/dist/types/transport/WaWebSocket.d.ts +1 -1
- package/dist/types/transport/binary/constants.d.ts +0 -30
- package/dist/types/transport/binary/index.d.ts +0 -1
- 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 +9 -6
- package/dist/types/transport/node/builders/abprops.d.ts +5 -0
- package/dist/types/transport/node/builders/business.d.ts +29 -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/global.d.ts +102 -0
- package/dist/types/transport/node/builders/message.d.ts +8 -7
- package/dist/types/transport/node/builders/offline.d.ts +2 -0
- package/dist/types/transport/node/builders/pairing.d.ts +0 -2
- 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/builders/privacy-token.d.ts +9 -0
- package/dist/types/transport/node/builders/privacy.d.ts +7 -0
- package/dist/types/transport/node/builders/profile.d.ts +8 -0
- package/dist/types/transport/node/builders/retry.d.ts +0 -1
- package/dist/types/transport/node/helpers.d.ts +8 -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 +4 -2
- package/dist/types/transport/noise/WaNoiseSocket.d.ts +4 -2
- package/dist/types/transport/types.d.ts +8 -0
- package/dist/types/util/bytes.d.ts +1 -1
- package/dist/types/util/index.d.ts +5 -0
- package/dist/types/util/primitives.d.ts +0 -1
- package/dist/util/bytes.js +22 -18
- package/dist/util/index.js +23 -0
- package/dist/util/primitives.js +2 -2
- package/package.json +34 -10
- package/proto/index.js +1 -1
- package/dist/auth/flow/WaAuthCredentialsFlow.js +0 -130
- package/dist/auth/pairing/constants.js +0 -5
- package/dist/client/connection/WaKeyShareCoordinator.js +0 -63
- package/dist/crypto/core/constants.js +0 -4
- package/dist/esm/auth/flow/WaAuthCredentialsFlow.js +0 -125
- package/dist/esm/auth/pairing/constants.js +0 -2
- package/dist/esm/client/connection/WaKeyShareCoordinator.js +0 -59
- package/dist/esm/crypto/core/constants.js +0 -1
- package/dist/esm/retry/outbound.js +0 -82
- package/dist/esm/store/providers/sqlite/BaseSqliteStore.js +0 -37
- package/dist/esm/store/providers/sqlite/appstate.store.js +0 -250
- package/dist/esm/store/providers/sqlite/auth.store.js +0 -176
- package/dist/esm/store/providers/sqlite/connection.js +0 -245
- package/dist/esm/store/providers/sqlite/contact.store.js +0 -74
- package/dist/esm/store/providers/sqlite/device-list.store.js +0 -127
- package/dist/esm/store/providers/sqlite/message.store.js +0 -132
- package/dist/esm/store/providers/sqlite/migrations.js +0 -347
- package/dist/esm/store/providers/sqlite/participants.store.js +0 -77
- package/dist/esm/store/providers/sqlite/retry.store.js +0 -141
- package/dist/esm/store/providers/sqlite/sender-key.store.js +0 -198
- package/dist/esm/store/providers/sqlite/signal.store.js +0 -435
- package/dist/esm/store/providers/sqlite/table-names.js +0 -107
- package/dist/esm/store/providers/sqlite/thread.store.js +0 -85
- package/dist/esm/transport/node/builders/index.js +0 -8
- package/dist/retry/outbound.js +0 -87
- package/dist/store/providers/sqlite/BaseSqliteStore.js +0 -41
- package/dist/store/providers/sqlite/appstate.store.js +0 -254
- package/dist/store/providers/sqlite/auth.store.js +0 -180
- package/dist/store/providers/sqlite/connection.js +0 -281
- package/dist/store/providers/sqlite/contact.store.js +0 -78
- package/dist/store/providers/sqlite/device-list.store.js +0 -131
- package/dist/store/providers/sqlite/message.store.js +0 -136
- package/dist/store/providers/sqlite/migrations.js +0 -350
- package/dist/store/providers/sqlite/participants.store.js +0 -81
- package/dist/store/providers/sqlite/retry.store.js +0 -145
- package/dist/store/providers/sqlite/sender-key.store.js +0 -202
- package/dist/store/providers/sqlite/signal.store.js +0 -439
- package/dist/store/providers/sqlite/table-names.js +0 -113
- package/dist/store/providers/sqlite/thread.store.js +0 -89
- package/dist/transport/node/builders/index.js +0 -42
- package/dist/types/appstate/store/sqlite.d.ts +0 -7
- 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/crypto/core/constants.d.ts +0 -1
- package/dist/types/retry/outbound.d.ts +0 -4
- package/dist/types/store/providers/sqlite/BaseSqliteStore.d.ts +0 -12
- package/dist/types/store/providers/sqlite/appstate.store.d.ts +0 -17
- package/dist/types/store/providers/sqlite/auth.store.d.ts +0 -10
- package/dist/types/store/providers/sqlite/connection.d.ts +0 -10
- package/dist/types/store/providers/sqlite/contact.store.d.ts +0 -12
- package/dist/types/store/providers/sqlite/device-list.store.d.ts +0 -15
- package/dist/types/store/providers/sqlite/message.store.d.ts +0 -13
- package/dist/types/store/providers/sqlite/migrations.d.ts +0 -3
- package/dist/types/store/providers/sqlite/participants.store.d.ts +0 -12
- package/dist/types/store/providers/sqlite/retry.store.d.ts +0 -15
- package/dist/types/store/providers/sqlite/sender-key.store.d.ts +0 -24
- package/dist/types/store/providers/sqlite/signal.store.d.ts +0 -53
- package/dist/types/store/providers/sqlite/table-names.d.ts +0 -5
- package/dist/types/store/providers/sqlite/thread.store.d.ts +0 -13
- package/dist/types/transport/node/builders/index.d.ts +0 -8
- /package/dist/appstate/{WaAppStateSyncResponseParser.js → response-parser.js} +0 -0
|
@@ -3,14 +3,19 @@ import { downloadExternalBlobReference } from '../appstate/utils.js';
|
|
|
3
3
|
import { parseChatEventFromAppStateMutation } from './events/chat.js';
|
|
4
4
|
import { processHistorySyncNotification } from './history-sync.js';
|
|
5
5
|
import { persistIncomingMailboxEntities } from './mailbox.js';
|
|
6
|
+
import { WriteBehindPersistence } from './persistence/WriteBehindPersistence.js';
|
|
6
7
|
import { buildWaClientDependencies, resolveWaClientBase } from './WaClientFactory.js';
|
|
7
8
|
import { ConsoleLogger } from '../infra/log/ConsoleLogger.js';
|
|
9
|
+
import { buildAddonAdditionalData, decodeAddonPlaintext, decryptAddonPayload, identifyEncryptedAddon, resolveParentMessageSecret, resolvePollOptionNames, shouldUseAddonAdditionalData } from '../message/addon-crypto.js';
|
|
8
10
|
import { proto } from '../proto.js';
|
|
9
11
|
import { WA_APP_STATE_COLLECTION_STATES, WA_DEFAULTS } from '../protocol/constants.js';
|
|
10
12
|
import { normalizeDeviceJid, parsePhoneJid, toUserJid } from '../protocol/jid.js';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
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';
|
|
14
19
|
import { toError } from '../util/primitives.js';
|
|
15
20
|
const SYNC_RELATED_PROTOCOL_TYPES = new Set([
|
|
16
21
|
proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_REQUEST,
|
|
@@ -18,29 +23,45 @@ const SYNC_RELATED_PROTOCOL_TYPES = new Set([
|
|
|
18
23
|
proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_MESSAGE,
|
|
19
24
|
proto.Message.ProtocolMessage.Type.PEER_DATA_OPERATION_REQUEST_RESPONSE_MESSAGE
|
|
20
25
|
]);
|
|
21
|
-
const WA_APP_STATE_KEY_SHARE_WAIT_TIMEOUT_MS = 15000;
|
|
22
|
-
const WA_APP_STATE_KEY_SHARE_MAX_RETRIES = 2;
|
|
23
26
|
export class WaClient extends EventEmitter {
|
|
24
27
|
constructor(options, logger = new ConsoleLogger('info')) {
|
|
25
28
|
super();
|
|
26
29
|
this.connectPromise = null;
|
|
30
|
+
this.acceptingIncomingEvents = true;
|
|
31
|
+
this.activeIncomingHandlers = 0;
|
|
32
|
+
this.incomingHandlersDrainedWaiters = [];
|
|
27
33
|
const base = resolveWaClientBase(options, logger);
|
|
28
34
|
this.options = base.options;
|
|
29
35
|
this.logger = base.logger;
|
|
30
36
|
this.appStateStore = base.sessionStore.appState;
|
|
31
37
|
this.contactStore = base.sessionStore.contacts;
|
|
32
38
|
this.messageStore = base.sessionStore.messages;
|
|
39
|
+
this.messageSecretStore = base.sessionStore.messageSecret;
|
|
33
40
|
this.participantsStore = base.sessionStore.participants;
|
|
41
|
+
this.privacyTokenStore = base.sessionStore.privacyToken;
|
|
34
42
|
this.deviceListStore = base.sessionStore.deviceList;
|
|
35
43
|
this.retryStore = base.sessionStore.retry;
|
|
36
44
|
this.signalStore = base.sessionStore.signal;
|
|
45
|
+
this.preKeyStore = base.sessionStore.preKey;
|
|
46
|
+
this.sessionStore = base.sessionStore.session;
|
|
47
|
+
this.identityStore = base.sessionStore.identity;
|
|
37
48
|
this.senderKeyStore = base.sessionStore.senderKey;
|
|
38
49
|
this.threadStore = base.sessionStore.threads;
|
|
50
|
+
this.writeBehind = new WriteBehindPersistence({
|
|
51
|
+
messageStore: this.messageStore,
|
|
52
|
+
threadStore: this.threadStore,
|
|
53
|
+
contactStore: this.contactStore
|
|
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
|
+
}
|
|
39
60
|
const dependencies = buildWaClientDependencies({
|
|
40
61
|
base,
|
|
41
62
|
runtime: {
|
|
42
63
|
sendNode: (node) => this.sendNode(node),
|
|
43
|
-
query: (node, timeoutMs) => this.query(node, timeoutMs),
|
|
64
|
+
query: (node, timeoutMs, options) => this.query(node, timeoutMs, options),
|
|
44
65
|
queryWithContext: this.queryWithContext.bind(this),
|
|
45
66
|
syncAppState: () => this.syncAppState().then(() => { }),
|
|
46
67
|
syncAppStateWithOptions: (syncOptions) => this.syncAppState(syncOptions),
|
|
@@ -48,7 +69,10 @@ export class WaClient extends EventEmitter {
|
|
|
48
69
|
handleIncomingMessageEvent: this.handleIncomingMessageEvent.bind(this),
|
|
49
70
|
handleError: this.handleError.bind(this),
|
|
50
71
|
handleIncomingFrame: this.handleIncomingFrame.bind(this),
|
|
51
|
-
clearStoredState: this.clearStoredState.bind(this)
|
|
72
|
+
clearStoredState: this.clearStoredState.bind(this),
|
|
73
|
+
resumeIncomingEvents: () => {
|
|
74
|
+
this.acceptingIncomingEvents = true;
|
|
75
|
+
}
|
|
52
76
|
}
|
|
53
77
|
});
|
|
54
78
|
Object.assign(this, dependencies);
|
|
@@ -96,12 +120,16 @@ export class WaClient extends EventEmitter {
|
|
|
96
120
|
throw normalized;
|
|
97
121
|
}
|
|
98
122
|
}
|
|
99
|
-
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 = {}) {
|
|
100
128
|
if (!this.connectionManager.isConnected()) {
|
|
101
129
|
throw new Error('client is not connected');
|
|
102
130
|
}
|
|
103
131
|
this.logger.debug('wa client query', { tag: node.tag, id: node.attrs.id, timeoutMs });
|
|
104
|
-
return this.nodeOrchestrator.query(node, timeoutMs);
|
|
132
|
+
return this.nodeOrchestrator.query(node, timeoutMs, options);
|
|
105
133
|
}
|
|
106
134
|
registerIncomingHandler(registration) {
|
|
107
135
|
return this.incomingNode.registerIncomingHandler(registration);
|
|
@@ -119,63 +147,74 @@ export class WaClient extends EventEmitter {
|
|
|
119
147
|
this.handleError(error);
|
|
120
148
|
});
|
|
121
149
|
}
|
|
122
|
-
getMailboxPersistenceDeps() {
|
|
123
|
-
return {
|
|
124
|
-
logger: this.logger,
|
|
125
|
-
contactStore: this.contactStore,
|
|
126
|
-
messageStore: this.messageStore
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
150
|
async handleIncomingMessageEvent(event) {
|
|
130
|
-
this.
|
|
131
|
-
void persistIncomingMailboxEntities({
|
|
132
|
-
...this.getMailboxPersistenceDeps(),
|
|
133
|
-
event
|
|
134
|
-
});
|
|
135
|
-
const protocolMessage = event.message?.protocolMessage;
|
|
136
|
-
if (!protocolMessage) {
|
|
151
|
+
if (!this.tryEnterIncomingHandler()) {
|
|
137
152
|
return;
|
|
138
153
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
this.logger.debug('incoming protocol message without type', {
|
|
147
|
-
id: event.stanzaId,
|
|
148
|
-
from: event.chatJid
|
|
154
|
+
try {
|
|
155
|
+
this.emit('message', event);
|
|
156
|
+
void persistIncomingMailboxEntities({
|
|
157
|
+
logger: this.logger,
|
|
158
|
+
writeBehind: this.writeBehind,
|
|
159
|
+
messageSecretStore: this.messageSecretStore,
|
|
160
|
+
event
|
|
149
161
|
});
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
await this.handleIncomingAppStateSyncKeyShare(event, protocolMessage);
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
if (protocolType === proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION) {
|
|
161
|
-
if (this.options.history?.enabled && protocolMessage.historySyncNotification) {
|
|
162
|
-
await this.handleHistorySyncNotification(protocolMessage.historySyncNotification);
|
|
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
|
+
});
|
|
163
169
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
170
|
+
const protocolMessage = event.message?.protocolMessage;
|
|
171
|
+
if (!protocolMessage) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const protocolEvent = {
|
|
175
|
+
...event,
|
|
176
|
+
protocolMessage
|
|
177
|
+
};
|
|
178
|
+
this.emit('message_protocol', protocolEvent);
|
|
179
|
+
const protocolType = protocolMessage.type;
|
|
180
|
+
if (protocolType === null || protocolType === undefined) {
|
|
181
|
+
this.logger.debug('incoming protocol message without type', {
|
|
182
|
+
id: event.stanzaId,
|
|
183
|
+
from: event.chatJid
|
|
184
|
+
});
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (protocolType === proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_REQUEST) {
|
|
188
|
+
await this.handleIncomingAppStateSyncKeyRequest(event, protocolMessage);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
if (protocolType === proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE) {
|
|
192
|
+
await this.handleIncomingAppStateSyncKeyShare(event, protocolMessage);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (protocolType === proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION) {
|
|
196
|
+
if (this.options.history?.enabled && protocolMessage.historySyncNotification) {
|
|
197
|
+
await this.handleHistorySyncNotification(protocolMessage.historySyncNotification);
|
|
198
|
+
}
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
if (SYNC_RELATED_PROTOCOL_TYPES.has(protocolType)) {
|
|
202
|
+
this.logger.info('incoming sync-related protocol message', {
|
|
203
|
+
id: event.stanzaId,
|
|
204
|
+
from: event.chatJid,
|
|
205
|
+
protocolType
|
|
206
|
+
});
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
this.logger.debug('incoming protocol message received', {
|
|
168
210
|
id: event.stanzaId,
|
|
169
211
|
from: event.chatJid,
|
|
170
212
|
protocolType
|
|
171
213
|
});
|
|
172
|
-
return;
|
|
173
214
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
protocolType
|
|
178
|
-
});
|
|
215
|
+
finally {
|
|
216
|
+
this.leaveIncomingHandler();
|
|
217
|
+
}
|
|
179
218
|
}
|
|
180
219
|
async handleIncomingAppStateSyncKeyShare(event, protocolMessage) {
|
|
181
220
|
const share = protocolMessage.appStateSyncKeyShare;
|
|
@@ -194,16 +233,6 @@ export class WaClient extends EventEmitter {
|
|
|
194
233
|
imported
|
|
195
234
|
});
|
|
196
235
|
if (imported > 0) {
|
|
197
|
-
const hadWaiters = this.keyShareCoordinator.hasWaiters();
|
|
198
|
-
this.keyShareCoordinator.notifyReceived();
|
|
199
|
-
if (hadWaiters) {
|
|
200
|
-
this.logger.debug('app-state key share imported and waiters released', {
|
|
201
|
-
id: event.stanzaId,
|
|
202
|
-
from: event.chatJid,
|
|
203
|
-
imported
|
|
204
|
-
});
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
236
|
void this.syncAppState().catch((error) => {
|
|
208
237
|
this.logger.warn('failed to sync app-state after key share import', {
|
|
209
238
|
id: event.stanzaId,
|
|
@@ -264,9 +293,18 @@ export class WaClient extends EventEmitter {
|
|
|
264
293
|
});
|
|
265
294
|
return;
|
|
266
295
|
}
|
|
267
|
-
const requestedKeys = await
|
|
268
|
-
const availableKeys =
|
|
269
|
-
const missingKeyIds =
|
|
296
|
+
const requestedKeys = await this.appStateStore.getSyncKeysBatch(requestedKeyIds);
|
|
297
|
+
const availableKeys = [];
|
|
298
|
+
const missingKeyIds = [];
|
|
299
|
+
for (let i = 0; i < requestedKeys.length; i += 1) {
|
|
300
|
+
const key = requestedKeys[i];
|
|
301
|
+
if (key !== null) {
|
|
302
|
+
availableKeys.push(key);
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
missingKeyIds.push(requestedKeyIds[i]);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
270
308
|
try {
|
|
271
309
|
await this.messageDispatch.sendAppStateSyncKeyShare(requesterDeviceJid, availableKeys, missingKeyIds);
|
|
272
310
|
this.logger.info('responded to app-state key request', {
|
|
@@ -313,18 +351,18 @@ export class WaClient extends EventEmitter {
|
|
|
313
351
|
return false;
|
|
314
352
|
}
|
|
315
353
|
const candidateUser = toUserJid(candidateJid);
|
|
316
|
-
|
|
317
|
-
.
|
|
318
|
-
.map((jid) => toUserJid(jid));
|
|
319
|
-
return meUsers.includes(candidateUser);
|
|
354
|
+
return ((!!credentials.meJid && toUserJid(credentials.meJid) === candidateUser) ||
|
|
355
|
+
(!!credentials.meLid && toUserJid(credentials.meLid) === candidateUser));
|
|
320
356
|
}
|
|
321
357
|
async handleHistorySyncNotification(notification) {
|
|
322
358
|
try {
|
|
323
359
|
await processHistorySyncNotification({
|
|
324
|
-
|
|
360
|
+
logger: this.logger,
|
|
325
361
|
mediaTransfer: this.mediaTransfer,
|
|
326
|
-
|
|
327
|
-
emitEvent: this.emit.bind(this)
|
|
362
|
+
writeBehind: this.writeBehind,
|
|
363
|
+
emitEvent: this.emit.bind(this),
|
|
364
|
+
onPrivacyTokens: (conversations) => this.trustedContactToken.hydrateFromHistorySync(conversations),
|
|
365
|
+
onNctSalt: (salt) => this.trustedContactToken.hydrateNctSaltFromHistorySync(salt)
|
|
328
366
|
}, notification);
|
|
329
367
|
}
|
|
330
368
|
catch (error) {
|
|
@@ -335,8 +373,8 @@ export class WaClient extends EventEmitter {
|
|
|
335
373
|
});
|
|
336
374
|
}
|
|
337
375
|
}
|
|
338
|
-
async queryWithContext(context, node, timeoutMs = this.options.iqTimeoutMs ?? WA_DEFAULTS.IQ_TIMEOUT_MS, contextData = {}) {
|
|
339
|
-
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);
|
|
340
378
|
}
|
|
341
379
|
async handleIncomingFrame(frame) {
|
|
342
380
|
try {
|
|
@@ -351,10 +389,17 @@ export class WaClient extends EventEmitter {
|
|
|
351
389
|
this.logger.trace('wa client connect already in-flight');
|
|
352
390
|
return this.connectPromise;
|
|
353
391
|
}
|
|
392
|
+
this.acceptingIncomingEvents = true;
|
|
354
393
|
this.connectPromise = this.connectionManager
|
|
355
394
|
.connect((frame) => this.handleIncomingFrame(frame))
|
|
356
395
|
.then(() => {
|
|
357
|
-
this.emit('
|
|
396
|
+
this.emit('connection', {
|
|
397
|
+
status: 'open',
|
|
398
|
+
reason: 'connected',
|
|
399
|
+
code: null,
|
|
400
|
+
isLogout: false,
|
|
401
|
+
isNewLogin: this.connectionManager.wasNewLogin()
|
|
402
|
+
});
|
|
358
403
|
})
|
|
359
404
|
.finally(() => {
|
|
360
405
|
this.connectPromise = null;
|
|
@@ -362,16 +407,28 @@ export class WaClient extends EventEmitter {
|
|
|
362
407
|
return this.connectPromise;
|
|
363
408
|
}
|
|
364
409
|
async disconnect() {
|
|
365
|
-
this.
|
|
410
|
+
await this.pauseIncomingEventsAndWaitDrain();
|
|
411
|
+
const writeBehindFlush = await this.writeBehind.flush(this.options.writeBehind?.flushTimeoutMs);
|
|
412
|
+
if (writeBehindFlush.remaining > 0) {
|
|
413
|
+
this.logger.warn('disconnect continuing with pending write-behind entries', {
|
|
414
|
+
remaining: writeBehindFlush.remaining
|
|
415
|
+
});
|
|
416
|
+
}
|
|
366
417
|
await this.connectionManager.disconnect();
|
|
367
|
-
this.emit('
|
|
418
|
+
this.emit('connection', {
|
|
419
|
+
status: 'close',
|
|
420
|
+
reason: 'client_disconnected',
|
|
421
|
+
code: null,
|
|
422
|
+
isLogout: false,
|
|
423
|
+
isNewLogin: false
|
|
424
|
+
});
|
|
368
425
|
}
|
|
369
|
-
async requestPairingCode(phoneNumber, shouldShowPushNotification = false) {
|
|
426
|
+
async requestPairingCode(phoneNumber, shouldShowPushNotification = false, customCode) {
|
|
370
427
|
if (!this.connectionManager.isConnected() || !this.authClient.getCurrentCredentials()) {
|
|
371
428
|
throw new Error('client is not connected');
|
|
372
429
|
}
|
|
373
430
|
this.logger.debug('wa client request pairing code');
|
|
374
|
-
return this.authClient.requestPairingCode(phoneNumber, shouldShowPushNotification);
|
|
431
|
+
return this.authClient.requestPairingCode(phoneNumber, shouldShowPushNotification, customCode);
|
|
375
432
|
}
|
|
376
433
|
async fetchPairingCountryCodeIso() {
|
|
377
434
|
if (!this.connectionManager.isConnected() || !this.authClient.getCurrentCredentials()) {
|
|
@@ -384,7 +441,10 @@ export class WaClient extends EventEmitter {
|
|
|
384
441
|
if (!this.connectionManager.isConnected() || !this.authClient.getCurrentCredentials()) {
|
|
385
442
|
throw new Error('client is not connected');
|
|
386
443
|
}
|
|
387
|
-
const normalizedPhoneJids = phoneNumbers.
|
|
444
|
+
const normalizedPhoneJids = new Array(phoneNumbers.length);
|
|
445
|
+
for (let index = 0; index < phoneNumbers.length; index += 1) {
|
|
446
|
+
normalizedPhoneJids[index] = parsePhoneJid(phoneNumbers[index]);
|
|
447
|
+
}
|
|
388
448
|
this.logger.trace('wa client query lids by phone numbers', {
|
|
389
449
|
phones: normalizedPhoneJids.length
|
|
390
450
|
});
|
|
@@ -393,41 +453,54 @@ export class WaClient extends EventEmitter {
|
|
|
393
453
|
sendMessage(to, content, options = {}) {
|
|
394
454
|
return this.messageDispatch.sendMessage(to, content, options);
|
|
395
455
|
}
|
|
396
|
-
syncSignalSession(jid, reasonIdentity = false) {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
456
|
+
async syncSignalSession(jid, reasonIdentity = false) {
|
|
457
|
+
await this.messageDispatch.syncSignalSession(jid, reasonIdentity);
|
|
458
|
+
if (reasonIdentity) {
|
|
459
|
+
this.trustedContactToken.reissueOnIdentityChange(jid).catch((err) => this.logger.warn('tc token reissue on identity change failed', {
|
|
460
|
+
jid,
|
|
461
|
+
message: toError(err).message
|
|
462
|
+
}));
|
|
463
|
+
}
|
|
404
464
|
}
|
|
405
|
-
|
|
406
|
-
return this.
|
|
465
|
+
get chat() {
|
|
466
|
+
return this.chatCoordinator;
|
|
407
467
|
}
|
|
408
|
-
|
|
409
|
-
return this.
|
|
468
|
+
get group() {
|
|
469
|
+
return this.groupCoordinator;
|
|
410
470
|
}
|
|
411
|
-
|
|
412
|
-
return this.
|
|
471
|
+
get privacy() {
|
|
472
|
+
return this.privacyCoordinator;
|
|
413
473
|
}
|
|
414
|
-
|
|
415
|
-
return this.
|
|
474
|
+
get profile() {
|
|
475
|
+
return this.profileCoordinator;
|
|
416
476
|
}
|
|
417
|
-
|
|
418
|
-
return this.
|
|
477
|
+
get business() {
|
|
478
|
+
return this.businessCoordinator;
|
|
419
479
|
}
|
|
420
|
-
|
|
421
|
-
return this.
|
|
480
|
+
get email() {
|
|
481
|
+
return this.emailCoordinator;
|
|
422
482
|
}
|
|
423
|
-
|
|
424
|
-
|
|
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');
|
|
425
495
|
}
|
|
426
|
-
|
|
427
|
-
return this.
|
|
496
|
+
sendReceipt(input) {
|
|
497
|
+
return this.messageDispatch.sendReceipt(input);
|
|
428
498
|
}
|
|
429
499
|
flushAppStateMutations() {
|
|
430
|
-
return this.
|
|
500
|
+
return this.chatCoordinator.flushMutations();
|
|
501
|
+
}
|
|
502
|
+
flushWriteBehind(timeoutMs) {
|
|
503
|
+
return this.writeBehind.flush(timeoutMs);
|
|
431
504
|
}
|
|
432
505
|
async exportAppState() {
|
|
433
506
|
return this.appStateSync.exportState();
|
|
@@ -436,60 +509,11 @@ export class WaClient extends EventEmitter {
|
|
|
436
509
|
if (!this.connectionManager.isConnected()) {
|
|
437
510
|
throw new Error('client is not connected');
|
|
438
511
|
}
|
|
439
|
-
const
|
|
440
|
-
|
|
441
|
-
this.keyShareCoordinator.markBootstrapDone();
|
|
442
|
-
this.logger.info('app-state bootstrap pre-sync waiting for key share', {
|
|
443
|
-
timeoutMs: WA_APP_STATE_KEY_SHARE_WAIT_TIMEOUT_MS
|
|
444
|
-
});
|
|
445
|
-
const received = await this.keyShareCoordinator.waitForShare(WA_APP_STATE_KEY_SHARE_WAIT_TIMEOUT_MS);
|
|
446
|
-
if (received) {
|
|
447
|
-
this.logger.info('app-state bootstrap pre-sync received key share, continuing sync');
|
|
448
|
-
}
|
|
449
|
-
else {
|
|
450
|
-
this.logger.warn('app-state bootstrap pre-sync key share wait timed out, continuing sync', {
|
|
451
|
-
timeoutMs: WA_APP_STATE_KEY_SHARE_WAIT_TIMEOUT_MS
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
let syncResult = await this.executeAppStateSync(options);
|
|
456
|
-
let blockedCollections = this.getBlockedAppStateCollections(syncResult);
|
|
457
|
-
if (!shouldWaitForKeyShare || blockedCollections.length === 0) {
|
|
458
|
-
this.emitChatEventsFromAppStateSyncResult(syncResult);
|
|
459
|
-
return syncResult;
|
|
460
|
-
}
|
|
461
|
-
let retryCount = 0;
|
|
462
|
-
let observedKeyShareVersion = this.keyShareCoordinator.getVersion();
|
|
463
|
-
while (blockedCollections.length > 0 && retryCount < WA_APP_STATE_KEY_SHARE_MAX_RETRIES) {
|
|
464
|
-
const hasFreshShare = this.keyShareCoordinator.getVersion() !== observedKeyShareVersion;
|
|
465
|
-
if (!hasFreshShare) {
|
|
466
|
-
this.logger.info('app-state bootstrap waiting for key share', {
|
|
467
|
-
blockedCollections: blockedCollections.join(','),
|
|
468
|
-
timeoutMs: WA_APP_STATE_KEY_SHARE_WAIT_TIMEOUT_MS,
|
|
469
|
-
retryCount: retryCount + 1
|
|
470
|
-
});
|
|
471
|
-
const received = await this.keyShareCoordinator.waitForShare(WA_APP_STATE_KEY_SHARE_WAIT_TIMEOUT_MS);
|
|
472
|
-
if (!received) {
|
|
473
|
-
this.logger.warn('app-state bootstrap key share wait timed out', {
|
|
474
|
-
blockedCollections: blockedCollections.join(','),
|
|
475
|
-
timeoutMs: WA_APP_STATE_KEY_SHARE_WAIT_TIMEOUT_MS
|
|
476
|
-
});
|
|
477
|
-
break;
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
observedKeyShareVersion = this.keyShareCoordinator.getVersion();
|
|
481
|
-
retryCount += 1;
|
|
482
|
-
this.logger.info('app-state bootstrap retrying sync after key share', {
|
|
483
|
-
retryCount,
|
|
484
|
-
blockedCollections: blockedCollections.join(',')
|
|
485
|
-
});
|
|
486
|
-
syncResult = await this.executeAppStateSync(options);
|
|
487
|
-
blockedCollections = this.getBlockedAppStateCollections(syncResult);
|
|
488
|
-
}
|
|
512
|
+
const syncResult = await this.executeAppStateSync(options);
|
|
513
|
+
const blockedCollections = this.getBlockedAppStateCollections(syncResult);
|
|
489
514
|
if (blockedCollections.length > 0) {
|
|
490
|
-
this.logger.warn('app-state
|
|
491
|
-
blockedCollections: blockedCollections.join(',')
|
|
492
|
-
retries: retryCount
|
|
515
|
+
this.logger.warn('app-state sync has blocked collections', {
|
|
516
|
+
blockedCollections: blockedCollections.join(',')
|
|
493
517
|
});
|
|
494
518
|
}
|
|
495
519
|
this.emitChatEventsFromAppStateSyncResult(syncResult);
|
|
@@ -504,9 +528,13 @@ export class WaClient extends EventEmitter {
|
|
|
504
528
|
});
|
|
505
529
|
}
|
|
506
530
|
getBlockedAppStateCollections(syncResult) {
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
531
|
+
const blocked = [];
|
|
532
|
+
for (const entry of syncResult.collections) {
|
|
533
|
+
if (entry.state === WA_APP_STATE_COLLECTION_STATES.BLOCKED) {
|
|
534
|
+
blocked.push(entry.collection);
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
return blocked;
|
|
510
538
|
}
|
|
511
539
|
emitChatEventsFromAppStateSyncResult(syncResult) {
|
|
512
540
|
const shouldEmitSnapshotMutations = this.options.chatEvents?.emitSnapshotMutations === true;
|
|
@@ -530,6 +558,7 @@ export class WaClient extends EventEmitter {
|
|
|
530
558
|
continue;
|
|
531
559
|
}
|
|
532
560
|
try {
|
|
561
|
+
this.handleNctSaltMutation(mutation);
|
|
533
562
|
const event = parseChatEventFromAppStateMutation(mutation);
|
|
534
563
|
if (!event) {
|
|
535
564
|
continue;
|
|
@@ -547,23 +576,158 @@ export class WaClient extends EventEmitter {
|
|
|
547
576
|
}
|
|
548
577
|
}
|
|
549
578
|
}
|
|
579
|
+
handleNctSaltMutation(mutation) {
|
|
580
|
+
const nctAction = mutation.value?.nctSaltSyncAction;
|
|
581
|
+
if (!nctAction) {
|
|
582
|
+
return;
|
|
583
|
+
}
|
|
584
|
+
if (mutation.operation === 'set' && nctAction.salt) {
|
|
585
|
+
this.trustedContactToken.handleNctSaltSync(nctAction.salt).catch((err) => this.logger.warn('nct salt sync set failed', {
|
|
586
|
+
message: toError(err).message
|
|
587
|
+
}));
|
|
588
|
+
}
|
|
589
|
+
else if (mutation.operation === 'remove') {
|
|
590
|
+
this.trustedContactToken.handleNctSaltSync(null).catch((err) => this.logger.warn('nct salt sync remove failed', {
|
|
591
|
+
message: toError(err).message
|
|
592
|
+
}));
|
|
593
|
+
}
|
|
594
|
+
}
|
|
550
595
|
async clearStoredState() {
|
|
596
|
+
await this.pauseIncomingEventsAndWaitDrain();
|
|
597
|
+
const writeBehindDestroy = await this.writeBehind.destroy(this.options.writeBehind?.flushTimeoutMs);
|
|
598
|
+
if (writeBehindDestroy.remaining > 0) {
|
|
599
|
+
throw new Error(`clear stored state aborted: write-behind did not fully drain (remaining=${writeBehindDestroy.remaining})`);
|
|
600
|
+
}
|
|
551
601
|
const danglingReceipts = this.receiptQueue.take();
|
|
552
602
|
if (danglingReceipts.length > 0) {
|
|
553
603
|
this.logger.debug('cleared dangling receipts while clearing stored state', {
|
|
554
604
|
count: danglingReceipts.length
|
|
555
605
|
});
|
|
556
606
|
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
607
|
+
const s = this.options.logoutStoreClear;
|
|
608
|
+
const shouldClear = (key) => s === undefined || s[key] !== false;
|
|
609
|
+
if (shouldClear('auth'))
|
|
610
|
+
await this.authClient.clearStoredCredentials();
|
|
611
|
+
if (shouldClear('appState'))
|
|
612
|
+
await this.appStateStore.clear();
|
|
613
|
+
if (shouldClear('contacts'))
|
|
614
|
+
await this.contactStore.clear();
|
|
615
|
+
if (shouldClear('messages'))
|
|
616
|
+
await this.messageStore.clear();
|
|
617
|
+
if (shouldClear('messageSecret'))
|
|
618
|
+
await this.messageSecretStore.clear();
|
|
619
|
+
if (shouldClear('participants'))
|
|
620
|
+
await this.participantsStore.clear();
|
|
621
|
+
if (shouldClear('deviceList'))
|
|
622
|
+
await this.deviceListStore.clear();
|
|
623
|
+
if (shouldClear('retry'))
|
|
624
|
+
await this.retryStore.clear();
|
|
625
|
+
if (shouldClear('signal'))
|
|
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();
|
|
633
|
+
if (shouldClear('senderKey'))
|
|
634
|
+
await this.senderKeyStore.clear();
|
|
635
|
+
if (shouldClear('threads'))
|
|
636
|
+
await this.threadStore.clear();
|
|
637
|
+
if (shouldClear('privacyToken'))
|
|
638
|
+
await this.privacyTokenStore.clear();
|
|
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
|
+
}
|
|
692
|
+
tryEnterIncomingHandler() {
|
|
693
|
+
if (!this.acceptingIncomingEvents) {
|
|
694
|
+
return false;
|
|
695
|
+
}
|
|
696
|
+
this.activeIncomingHandlers += 1;
|
|
697
|
+
if (this.acceptingIncomingEvents) {
|
|
698
|
+
return true;
|
|
699
|
+
}
|
|
700
|
+
this.leaveIncomingHandler();
|
|
701
|
+
return false;
|
|
702
|
+
}
|
|
703
|
+
leaveIncomingHandler() {
|
|
704
|
+
if (this.activeIncomingHandlers <= 0) {
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
this.activeIncomingHandlers -= 1;
|
|
708
|
+
if (this.activeIncomingHandlers === 0) {
|
|
709
|
+
this.notifyIncomingHandlersDrained();
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
async pauseIncomingEventsAndWaitDrain() {
|
|
713
|
+
this.acceptingIncomingEvents = false;
|
|
714
|
+
if (this.activeIncomingHandlers === 0) {
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
717
|
+
await new Promise((resolve) => {
|
|
718
|
+
this.incomingHandlersDrainedWaiters[this.incomingHandlersDrainedWaiters.length] =
|
|
719
|
+
resolve;
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
notifyIncomingHandlersDrained() {
|
|
723
|
+
if (this.incomingHandlersDrainedWaiters.length === 0) {
|
|
724
|
+
return;
|
|
725
|
+
}
|
|
726
|
+
const waitersLength = this.incomingHandlersDrainedWaiters.length;
|
|
727
|
+
for (let index = 0; index < waitersLength; index += 1) {
|
|
728
|
+
this.incomingHandlersDrainedWaiters[index]();
|
|
729
|
+
}
|
|
730
|
+
this.incomingHandlersDrainedWaiters.length = 0;
|
|
567
731
|
}
|
|
568
732
|
handleError(error) {
|
|
569
733
|
this.logger.error('wa client error', { message: error.message });
|