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
package/dist/client/dirty.js
CHANGED
|
@@ -28,7 +28,13 @@ function parseDirtyBitNode(node, logger) {
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
function resolveAccountSyncProtocols(protocols) {
|
|
31
|
-
const selected =
|
|
31
|
+
const selected = [];
|
|
32
|
+
for (let index = 0; index < protocols.length; index += 1) {
|
|
33
|
+
const protocol = protocols[index];
|
|
34
|
+
if (ACCOUNT_SYNC_PROTOCOL_SET.has(protocol)) {
|
|
35
|
+
selected.push(protocol);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
32
38
|
if (selected.length > 0) {
|
|
33
39
|
return selected;
|
|
34
40
|
}
|
|
@@ -60,12 +66,24 @@ async function handleDirtyBits(runtime, dirtyBits) {
|
|
|
60
66
|
}
|
|
61
67
|
unsupported.push(dirtyBit);
|
|
62
68
|
}
|
|
69
|
+
const supportedTypes = new Array(supported.length);
|
|
70
|
+
for (let index = 0; index < supported.length; index += 1) {
|
|
71
|
+
supportedTypes[index] = supported[index].type;
|
|
72
|
+
}
|
|
73
|
+
const unsupportedTypes = new Array(unsupported.length);
|
|
74
|
+
for (let index = 0; index < unsupported.length; index += 1) {
|
|
75
|
+
unsupportedTypes[index] = unsupported[index].type;
|
|
76
|
+
}
|
|
63
77
|
runtime.logger.info('handling dirty bits from info bulletin', {
|
|
64
|
-
supported:
|
|
65
|
-
unsupported:
|
|
78
|
+
supported: supportedTypes.join(','),
|
|
79
|
+
unsupported: unsupportedTypes.join(',')
|
|
66
80
|
});
|
|
67
81
|
const clearableDirtyBits = [...unsupported];
|
|
68
|
-
const
|
|
82
|
+
const supportedPromises = new Array(supported.length);
|
|
83
|
+
for (let index = 0; index < supported.length; index += 1) {
|
|
84
|
+
supportedPromises[index] = handleDirtyBit(runtime, supported[index]);
|
|
85
|
+
}
|
|
86
|
+
const settledSupported = await Promise.allSettled(supportedPromises);
|
|
69
87
|
for (let index = 0; index < settledSupported.length; index += 1) {
|
|
70
88
|
const result = settledSupported[index];
|
|
71
89
|
if (result.status === 'fulfilled') {
|
|
@@ -105,18 +123,23 @@ async function handleAccountSyncDirtyBit(runtime, protocols) {
|
|
|
105
123
|
protocols: selectedProtocols.join(',')
|
|
106
124
|
});
|
|
107
125
|
const failures = [];
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
126
|
+
const protocolPromises = new Array(selectedProtocols.length);
|
|
127
|
+
for (let index = 0; index < selectedProtocols.length; index += 1) {
|
|
128
|
+
const protocol = selectedProtocols[index];
|
|
129
|
+
protocolPromises[index] = (async () => {
|
|
130
|
+
try {
|
|
131
|
+
await runAccountSyncProtocol(runtime, protocol);
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
failures.push(protocol);
|
|
135
|
+
runtime.logger.warn('account_sync protocol failed', {
|
|
136
|
+
protocol,
|
|
137
|
+
message: (0, primitives_1.toError)(error).message
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
})();
|
|
141
|
+
}
|
|
142
|
+
await Promise.all(protocolPromises);
|
|
120
143
|
if (failures.length > 0) {
|
|
121
144
|
throw new Error(`account_sync protocols failed: ${failures.join(',')}`);
|
|
122
145
|
}
|
|
@@ -136,7 +159,7 @@ async function runAccountSyncProtocol(runtime, protocol) {
|
|
|
136
159
|
await syncAccountBlocklistDirtyBit(runtime);
|
|
137
160
|
return;
|
|
138
161
|
case constants_1.WA_DIRTY_PROTOCOLS.NOTICE:
|
|
139
|
-
|
|
162
|
+
runtime.logger.info('account_sync notice protocol received (no GraphQL/MEX job configured)');
|
|
140
163
|
return;
|
|
141
164
|
default:
|
|
142
165
|
runtime.logger.debug('unsupported account_sync protocol', {
|
|
@@ -211,9 +234,6 @@ async function syncAccountBlocklistDirtyBit(runtime) {
|
|
|
211
234
|
logMessage: 'account_sync blocklist synchronized'
|
|
212
235
|
});
|
|
213
236
|
}
|
|
214
|
-
async function syncAccountNoticeDirtyBit(runtime) {
|
|
215
|
-
runtime.logger.info('account_sync notice protocol received (no GraphQL/MEX job configured)');
|
|
216
|
-
}
|
|
217
237
|
async function syncGroupsDirtyBit(runtime) {
|
|
218
238
|
await runSyncQuery(runtime, {
|
|
219
239
|
queryContext: 'dirty.groups',
|
|
@@ -246,7 +266,7 @@ async function clearDirtyBits(runtime, dirtyBits) {
|
|
|
246
266
|
try {
|
|
247
267
|
await runtime.queryWithContext('dirty.clear', (0, account_sync_1.buildClearDirtyBitsIq)(dirtyBits), constants_1.WA_DEFAULTS.IQ_TIMEOUT_MS, {
|
|
248
268
|
count: dirtyBits.length
|
|
249
|
-
});
|
|
269
|
+
}, { useSystemId: true });
|
|
250
270
|
runtime.logger.info('dirty bits cleared', {
|
|
251
271
|
count: dirtyBits.length
|
|
252
272
|
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseAbPropsIqResult = parseAbPropsIqResult;
|
|
4
|
+
const helpers_1 = require("../../transport/node/helpers");
|
|
5
|
+
const primitives_1 = require("../../util/primitives");
|
|
6
|
+
function parseAbPropsIqResult(node) {
|
|
7
|
+
const propsNode = (0, helpers_1.findNodeChild)(node, 'props');
|
|
8
|
+
if (!propsNode) {
|
|
9
|
+
return {
|
|
10
|
+
abKey: null,
|
|
11
|
+
hash: null,
|
|
12
|
+
refresh: null,
|
|
13
|
+
refreshId: null,
|
|
14
|
+
isDeltaUpdate: false,
|
|
15
|
+
props: []
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const attrs = propsNode.attrs;
|
|
19
|
+
const propChildren = (0, helpers_1.getNodeChildren)(propsNode);
|
|
20
|
+
const props = [];
|
|
21
|
+
for (let i = 0; i < propChildren.length; i += 1) {
|
|
22
|
+
const child = propChildren[i];
|
|
23
|
+
if (child.tag !== 'prop') {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const configCode = (0, primitives_1.parseOptionalInt)(child.attrs.config_code);
|
|
27
|
+
if (configCode === undefined) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
props.push({
|
|
31
|
+
configCode,
|
|
32
|
+
configValue: child.attrs.config_value ?? null
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
abKey: attrs.ab_key ?? null,
|
|
37
|
+
hash: attrs.hash ?? null,
|
|
38
|
+
refresh: (0, primitives_1.parseOptionalInt)(attrs.refresh) ?? null,
|
|
39
|
+
refreshId: (0, primitives_1.parseOptionalInt)(attrs.refresh_id) ?? null,
|
|
40
|
+
isDeltaUpdate: attrs.delta_update === 'true',
|
|
41
|
+
props
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEVICE_NOTIFICATION_ACTIONS = void 0;
|
|
4
|
+
exports.parseDeviceNotification = parseDeviceNotification;
|
|
5
|
+
const jid_1 = require("../../protocol/jid");
|
|
6
|
+
const helpers_1 = require("../../transport/node/helpers");
|
|
7
|
+
exports.DEVICE_NOTIFICATION_ACTIONS = Object.freeze({
|
|
8
|
+
ADD: 'add',
|
|
9
|
+
REMOVE: 'remove',
|
|
10
|
+
UPDATE: 'update'
|
|
11
|
+
});
|
|
12
|
+
function parseDeviceNotification(node) {
|
|
13
|
+
const stanzaId = node.attrs.id;
|
|
14
|
+
const fromJid = node.attrs.from;
|
|
15
|
+
if (!stanzaId || !fromJid) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
let action;
|
|
19
|
+
let actionNode;
|
|
20
|
+
if ((0, helpers_1.findNodeChild)(node, exports.DEVICE_NOTIFICATION_ACTIONS.REMOVE)) {
|
|
21
|
+
action = exports.DEVICE_NOTIFICATION_ACTIONS.REMOVE;
|
|
22
|
+
actionNode = (0, helpers_1.findNodeChild)(node, exports.DEVICE_NOTIFICATION_ACTIONS.REMOVE);
|
|
23
|
+
}
|
|
24
|
+
else if ((0, helpers_1.findNodeChild)(node, exports.DEVICE_NOTIFICATION_ACTIONS.ADD)) {
|
|
25
|
+
action = exports.DEVICE_NOTIFICATION_ACTIONS.ADD;
|
|
26
|
+
actionNode = (0, helpers_1.findNodeChild)(node, exports.DEVICE_NOTIFICATION_ACTIONS.ADD);
|
|
27
|
+
}
|
|
28
|
+
else if ((0, helpers_1.findNodeChild)(node, exports.DEVICE_NOTIFICATION_ACTIONS.UPDATE)) {
|
|
29
|
+
action = exports.DEVICE_NOTIFICATION_ACTIONS.UPDATE;
|
|
30
|
+
actionNode = (0, helpers_1.findNodeChild)(node, exports.DEVICE_NOTIFICATION_ACTIONS.UPDATE);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
const devices = [];
|
|
36
|
+
if (action !== exports.DEVICE_NOTIFICATION_ACTIONS.UPDATE && actionNode) {
|
|
37
|
+
const deviceNodes = (0, helpers_1.getNodeChildrenByTag)(actionNode, 'device');
|
|
38
|
+
for (let index = 0; index < deviceNodes.length; index += 1) {
|
|
39
|
+
const deviceNode = deviceNodes[index];
|
|
40
|
+
const jidAttr = deviceNode.attrs.jid;
|
|
41
|
+
if (!jidAttr) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
let deviceId;
|
|
45
|
+
try {
|
|
46
|
+
deviceId = (0, jid_1.parseSignalAddressFromJid)(jidAttr).device;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const keyIndexAttr = deviceNode.attrs['key-index'];
|
|
52
|
+
const parsedKeyIndex = keyIndexAttr === undefined ? null : Number.parseInt(keyIndexAttr, 10);
|
|
53
|
+
const keyIndex = parsedKeyIndex !== null &&
|
|
54
|
+
Number.isSafeInteger(parsedKeyIndex) &&
|
|
55
|
+
parsedKeyIndex >= 0
|
|
56
|
+
? parsedKeyIndex
|
|
57
|
+
: null;
|
|
58
|
+
devices[devices.length] = {
|
|
59
|
+
deviceId,
|
|
60
|
+
keyIndex
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
action,
|
|
66
|
+
stanzaId,
|
|
67
|
+
fromJid,
|
|
68
|
+
lid: node.attrs.lid,
|
|
69
|
+
hash: action === exports.DEVICE_NOTIFICATION_ACTIONS.UPDATE ? actionNode?.attrs.hash : undefined,
|
|
70
|
+
devices
|
|
71
|
+
};
|
|
72
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseParticipants = parseParticipants;
|
|
4
4
|
exports.parseGroupNotificationEvents = parseGroupNotificationEvents;
|
|
5
|
+
const incoming_1 = require("../incoming");
|
|
5
6
|
const constants_1 = require("../../protocol/constants");
|
|
6
7
|
const nodes_1 = require("../../protocol/nodes");
|
|
7
8
|
const helpers_1 = require("../../transport/node/helpers");
|
|
@@ -103,15 +104,6 @@ function createBaseGroupEvent(notificationNode, actionNode) {
|
|
|
103
104
|
timestampSeconds: (0, primitives_1.parseOptionalInt)(notificationNode.attrs.t)
|
|
104
105
|
};
|
|
105
106
|
}
|
|
106
|
-
function createUnhandledStanzaEvent(notificationNode, reason) {
|
|
107
|
-
return {
|
|
108
|
-
rawNode: notificationNode,
|
|
109
|
-
stanzaId: notificationNode.attrs.id,
|
|
110
|
-
chatJid: notificationNode.attrs.from,
|
|
111
|
-
stanzaType: notificationNode.attrs.type,
|
|
112
|
-
reason
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
107
|
function parseCreateGroupAction(notificationNode, actionNode) {
|
|
116
108
|
const groupNode = (0, helpers_1.findNodeChild)(actionNode, nodes_1.WA_NODE_TAGS.GROUP);
|
|
117
109
|
if (!groupNode) {
|
|
@@ -417,13 +409,13 @@ function parseGroupNotificationEvents(notificationNode) {
|
|
|
417
409
|
try {
|
|
418
410
|
const parsedEvent = parseGroupActionNode(notificationNode, actionNode);
|
|
419
411
|
if (!parsedEvent) {
|
|
420
|
-
unhandled.push(
|
|
412
|
+
unhandled.push((0, incoming_1.createUnhandledIncomingNodeEvent)(notificationNode, `notification.${constants_1.WA_NOTIFICATION_TYPES.GROUP}.${actionNode.tag}.not_supported`));
|
|
421
413
|
continue;
|
|
422
414
|
}
|
|
423
415
|
events.push(parsedEvent);
|
|
424
416
|
}
|
|
425
417
|
catch {
|
|
426
|
-
unhandled.push(
|
|
418
|
+
unhandled.push((0, incoming_1.createUnhandledIncomingNodeEvent)(notificationNode, `notification.${constants_1.WA_NOTIFICATION_TYPES.GROUP}.${actionNode.tag}.parse_failed`));
|
|
427
419
|
}
|
|
428
420
|
}
|
|
429
421
|
return {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseIdentityChangeNotification = parseIdentityChangeNotification;
|
|
4
|
+
const helpers_1 = require("../../transport/node/helpers");
|
|
5
|
+
function parseIdentityChangeNotification(node) {
|
|
6
|
+
const child = (0, helpers_1.getFirstNodeChild)(node);
|
|
7
|
+
if (!child || child.tag !== 'identity') {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
const fromJid = node.attrs.from;
|
|
11
|
+
const stanzaId = node.attrs.id;
|
|
12
|
+
if (!fromJid || !stanzaId) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
fromJid,
|
|
17
|
+
stanzaId,
|
|
18
|
+
displayName: node.attrs.display_name,
|
|
19
|
+
lid: node.attrs.lid,
|
|
20
|
+
offline: node.attrs.offline
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parsePrivacyTokenNotification = parsePrivacyTokenNotification;
|
|
4
|
+
const privacy_token_1 = require("../../protocol/privacy-token");
|
|
5
|
+
const helpers_1 = require("../../transport/node/helpers");
|
|
6
|
+
const coercion_1 = require("../../util/coercion");
|
|
7
|
+
function parsePrivacyTokenNotification(node) {
|
|
8
|
+
const tokensNode = (0, helpers_1.findNodeChild)(node, privacy_token_1.WA_PRIVACY_TOKEN_TAGS.TOKENS);
|
|
9
|
+
if (!tokensNode) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
const children = (0, helpers_1.getNodeChildren)(tokensNode);
|
|
13
|
+
const result = [];
|
|
14
|
+
for (let i = 0; i < children.length; i += 1) {
|
|
15
|
+
const child = children[i];
|
|
16
|
+
if (child.tag !== privacy_token_1.WA_PRIVACY_TOKEN_TAGS.TOKEN) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const type = child.attrs.type;
|
|
20
|
+
if (!type) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
const rawTimestamp = child.attrs.t;
|
|
24
|
+
if (!rawTimestamp) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const content = child.content;
|
|
28
|
+
if (!(content instanceof Uint8Array)) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
result[result.length] = {
|
|
32
|
+
type,
|
|
33
|
+
tokenBytes: content,
|
|
34
|
+
timestampS: (0, coercion_1.asNumber)(Number(rawTimestamp), 'privacy_token.t')
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseRegistrationNotification = parseRegistrationNotification;
|
|
4
|
+
const notification_1 = require("../../protocol/notification");
|
|
5
|
+
const helpers_1 = require("../../transport/node/helpers");
|
|
6
|
+
const primitives_1 = require("../../util/primitives");
|
|
7
|
+
function parseRegistrationNotification(node) {
|
|
8
|
+
const firstChild = (0, helpers_1.getFirstNodeChild)(node);
|
|
9
|
+
if (!firstChild) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
if (firstChild.tag === notification_1.WA_REGISTRATION_NOTIFICATION_TAGS.WA_OLD_REGISTRATION) {
|
|
13
|
+
const code = firstChild.attrs.code;
|
|
14
|
+
const expirySeconds = (0, primitives_1.parseOptionalInt)(firstChild.attrs.expiry_t);
|
|
15
|
+
const fromDeviceId = firstChild.attrs.device_id;
|
|
16
|
+
if (!code || expirySeconds === undefined || !fromDeviceId) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
kind: 'registration_code',
|
|
21
|
+
code,
|
|
22
|
+
expiryTimestampMs: expirySeconds * 1000,
|
|
23
|
+
fromDeviceId
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
if (firstChild.tag === notification_1.WA_REGISTRATION_NOTIFICATION_TAGS.DEVICE_LOGOUT) {
|
|
27
|
+
const serverToken = firstChild.attrs.id;
|
|
28
|
+
const tSeconds = (0, primitives_1.parseOptionalInt)(firstChild.attrs.t);
|
|
29
|
+
if (!serverToken || tSeconds === undefined) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
kind: 'account_takeover_notice',
|
|
34
|
+
serverToken,
|
|
35
|
+
attemptTimestampMs: tSeconds * 1000,
|
|
36
|
+
newDeviceName: firstChild.attrs.device,
|
|
37
|
+
newDevicePlatform: firstChild.attrs.new_device_platform,
|
|
38
|
+
newDeviceAppVersion: firstChild.attrs.new_device_app_version
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
@@ -13,6 +13,7 @@ const HANDLED_SYNC_TYPES = new Set([
|
|
|
13
13
|
_proto_1.proto.Message.HistorySyncType.FULL,
|
|
14
14
|
_proto_1.proto.Message.HistorySyncType.PUSH_NAME
|
|
15
15
|
]);
|
|
16
|
+
const HISTORY_SYNC_MAX_PENDING_WRITES = 1024;
|
|
16
17
|
async function processHistorySyncNotification(deps, notification) {
|
|
17
18
|
const syncType = notification.syncType;
|
|
18
19
|
if (syncType === null || syncType === undefined || !HANDLED_SYNC_TYPES.has(syncType)) {
|
|
@@ -30,19 +31,20 @@ async function processHistorySyncNotification(deps, notification) {
|
|
|
30
31
|
pushnames: historySync.pushnames.length
|
|
31
32
|
});
|
|
32
33
|
const nowMs = Date.now();
|
|
33
|
-
const
|
|
34
|
+
const pendingWrites = [];
|
|
34
35
|
for (const pn of historySync.pushnames) {
|
|
35
36
|
if (!pn.id) {
|
|
36
37
|
continue;
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
+
pendingWrites[pendingWrites.length] = deps.writeBehind.persistContactAsync({
|
|
39
40
|
jid: pn.id,
|
|
40
41
|
pushName: pn.pushname ?? undefined,
|
|
41
42
|
lastUpdatedMs: nowMs
|
|
42
43
|
});
|
|
44
|
+
if (pendingWrites.length >= HISTORY_SYNC_MAX_PENDING_WRITES) {
|
|
45
|
+
await flushPendingWrites(pendingWrites);
|
|
46
|
+
}
|
|
43
47
|
}
|
|
44
|
-
const threads = [];
|
|
45
|
-
const messages = [];
|
|
46
48
|
let messagesCount = 0;
|
|
47
49
|
for (const conversation of historySync.conversations) {
|
|
48
50
|
const threadJid = conversation.id;
|
|
@@ -50,7 +52,7 @@ async function processHistorySyncNotification(deps, notification) {
|
|
|
50
52
|
deps.logger.debug('skipping history sync conversation without thread jid');
|
|
51
53
|
continue;
|
|
52
54
|
}
|
|
53
|
-
|
|
55
|
+
pendingWrites[pendingWrites.length] = deps.writeBehind.persistThreadAsync({
|
|
54
56
|
jid: threadJid,
|
|
55
57
|
name: conversation.name ?? undefined,
|
|
56
58
|
unreadCount: conversation.unreadCount ?? undefined,
|
|
@@ -60,13 +62,16 @@ async function processHistorySyncNotification(deps, notification) {
|
|
|
60
62
|
markedAsUnread: conversation.markedAsUnread ?? undefined,
|
|
61
63
|
ephemeralExpiration: conversation.ephemeralExpiration ?? undefined
|
|
62
64
|
});
|
|
65
|
+
if (pendingWrites.length >= HISTORY_SYNC_MAX_PENDING_WRITES) {
|
|
66
|
+
await flushPendingWrites(pendingWrites);
|
|
67
|
+
}
|
|
63
68
|
for (const histMsg of conversation.messages ?? []) {
|
|
64
69
|
const webMsg = histMsg.message;
|
|
65
70
|
if (!webMsg?.key?.id) {
|
|
66
71
|
continue;
|
|
67
72
|
}
|
|
68
73
|
const timestampMs = (0, primitives_1.longToNumber)(webMsg.messageTimestamp) * 1000;
|
|
69
|
-
|
|
74
|
+
pendingWrites[pendingWrites.length] = deps.writeBehind.persistMessageAsync({
|
|
70
75
|
id: webMsg.key.id,
|
|
71
76
|
threadJid,
|
|
72
77
|
senderJid: webMsg.key.participant ?? undefined,
|
|
@@ -76,12 +81,35 @@ async function processHistorySyncNotification(deps, notification) {
|
|
|
76
81
|
? _proto_1.proto.Message.encode(webMsg.message).finish()
|
|
77
82
|
: undefined
|
|
78
83
|
});
|
|
84
|
+
if (pendingWrites.length >= HISTORY_SYNC_MAX_PENDING_WRITES) {
|
|
85
|
+
await flushPendingWrites(pendingWrites);
|
|
86
|
+
}
|
|
79
87
|
messagesCount += 1;
|
|
80
88
|
}
|
|
81
89
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
90
|
+
if (deps.onPrivacyTokens) {
|
|
91
|
+
const tokenConversations = [];
|
|
92
|
+
for (const conversation of historySync.conversations) {
|
|
93
|
+
if (!conversation.id)
|
|
94
|
+
continue;
|
|
95
|
+
if (conversation.tcToken ||
|
|
96
|
+
conversation.tcTokenTimestamp ||
|
|
97
|
+
conversation.tcTokenSenderTimestamp) {
|
|
98
|
+
tokenConversations[tokenConversations.length] = {
|
|
99
|
+
jid: conversation.id,
|
|
100
|
+
tcToken: conversation.tcToken,
|
|
101
|
+
tcTokenTimestamp: (0, primitives_1.longToNumber)(conversation.tcTokenTimestamp) || undefined,
|
|
102
|
+
tcTokenSenderTimestamp: (0, primitives_1.longToNumber)(conversation.tcTokenSenderTimestamp) || undefined
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (tokenConversations.length > 0) {
|
|
107
|
+
pendingWrites[pendingWrites.length] = deps.onPrivacyTokens(tokenConversations);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (deps.onNctSalt && historySync.nctSalt) {
|
|
111
|
+
pendingWrites[pendingWrites.length] = deps.onNctSalt(historySync.nctSalt);
|
|
112
|
+
}
|
|
85
113
|
const event = {
|
|
86
114
|
syncType,
|
|
87
115
|
messagesCount,
|
|
@@ -90,8 +118,21 @@ async function processHistorySyncNotification(deps, notification) {
|
|
|
90
118
|
chunkOrder: historySync.chunkOrder ?? undefined,
|
|
91
119
|
progress: historySync.progress ?? undefined
|
|
92
120
|
};
|
|
121
|
+
await flushPendingWrites(pendingWrites);
|
|
93
122
|
deps.emitEvent('history_sync_chunk', event);
|
|
94
123
|
}
|
|
124
|
+
async function flushPendingWrites(pendingWrites) {
|
|
125
|
+
if (pendingWrites.length === 0) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const pendingCount = pendingWrites.length;
|
|
129
|
+
const batch = new Array(pendingCount);
|
|
130
|
+
for (let index = 0; index < pendingCount; index += 1) {
|
|
131
|
+
batch[index] = pendingWrites[index];
|
|
132
|
+
}
|
|
133
|
+
pendingWrites.length = 0;
|
|
134
|
+
await Promise.all(batch);
|
|
135
|
+
}
|
|
95
136
|
async function downloadHistorySyncBlob(deps, notification) {
|
|
96
137
|
if (notification.initialHistBootstrapInlinePayload) {
|
|
97
138
|
return (0, bytes_1.decodeProtoBytes)(notification.initialHistBootstrapInlinePayload, 'initialHistBootstrapInlinePayload');
|
package/dist/client/incoming.js
CHANGED
|
@@ -4,15 +4,24 @@ exports.createIncomingBaseEvent = createIncomingBaseEvent;
|
|
|
4
4
|
exports.createIncomingReceiptHandler = createIncomingReceiptHandler;
|
|
5
5
|
exports.createIncomingFailureHandler = createIncomingFailureHandler;
|
|
6
6
|
exports.createIncomingNotificationHandler = createIncomingNotificationHandler;
|
|
7
|
+
exports.createIncomingRegistrationNotificationHandler = createIncomingRegistrationNotificationHandler;
|
|
7
8
|
exports.createIncomingGroupNotificationHandler = createIncomingGroupNotificationHandler;
|
|
8
9
|
exports.createInfoBulletinNotificationEvent = createInfoBulletinNotificationEvent;
|
|
9
10
|
exports.createUnhandledIncomingNodeEvent = createUnhandledIncomingNodeEvent;
|
|
10
11
|
const group_1 = require("./events/group");
|
|
12
|
+
const registration_1 = require("./events/registration");
|
|
11
13
|
const constants_1 = require("../protocol/constants");
|
|
12
|
-
const
|
|
13
|
-
const pairing_1 = require("../transport/node/builders/pairing");
|
|
14
|
+
const global_1 = require("../transport/node/builders/global");
|
|
14
15
|
const helpers_1 = require("../transport/node/helpers");
|
|
15
16
|
const primitives_1 = require("../util/primitives");
|
|
17
|
+
const FAILURE_REASON_TO_DISCONNECT = {
|
|
18
|
+
401: constants_1.WA_DISCONNECT_REASONS.FAILURE_NOT_AUTHORIZED,
|
|
19
|
+
403: constants_1.WA_DISCONNECT_REASONS.FAILURE_LOCKED,
|
|
20
|
+
406: constants_1.WA_DISCONNECT_REASONS.FAILURE_BANNED,
|
|
21
|
+
405: constants_1.WA_DISCONNECT_REASONS.FAILURE_CLIENT_TOO_OLD,
|
|
22
|
+
409: constants_1.WA_DISCONNECT_REASONS.FAILURE_BAD_USER_AGENT,
|
|
23
|
+
503: constants_1.WA_DISCONNECT_REASONS.FAILURE_SERVICE_UNAVAILABLE
|
|
24
|
+
};
|
|
16
25
|
const LOGOUT_FAILURE_REASONS = new Set([401, 403, 406]);
|
|
17
26
|
const DISCONNECT_FAILURE_REASONS = new Set([405, 409, 503]);
|
|
18
27
|
const CORE_NOTIFICATION_TYPES = new Set([
|
|
@@ -39,6 +48,8 @@ const OUT_OF_SCOPE_NOTIFICATION_TYPES = new Set([
|
|
|
39
48
|
'waffle',
|
|
40
49
|
'hosted'
|
|
41
50
|
]);
|
|
51
|
+
const NOTIFICATION_TYPES_WITH_PARTICIPANT_ACK = new Set(['mediaretry', 'psa']);
|
|
52
|
+
const NOTIFICATION_TYPES_WITHOUT_TYPE_ACK = new Set(['encrypt', 'devices']);
|
|
42
53
|
function createIncomingBaseEvent(node) {
|
|
43
54
|
return {
|
|
44
55
|
rawNode: node,
|
|
@@ -72,7 +83,9 @@ function classifyNotificationType(notificationType) {
|
|
|
72
83
|
}
|
|
73
84
|
async function applyFailureAction(options, reason, clearStoredCredentials) {
|
|
74
85
|
try {
|
|
75
|
-
|
|
86
|
+
options.stopComms();
|
|
87
|
+
const disconnectReason = FAILURE_REASON_TO_DISCONNECT[reason] ?? constants_1.WA_DISCONNECT_REASONS.STREAM_ERROR_OTHER;
|
|
88
|
+
await options.disconnect(disconnectReason, clearStoredCredentials, reason);
|
|
76
89
|
if (clearStoredCredentials) {
|
|
77
90
|
await options.clearStoredCredentials();
|
|
78
91
|
}
|
|
@@ -117,11 +130,19 @@ function createIncomingReceiptHandler(options) {
|
|
|
117
130
|
await options.handleIncomingRetryReceipt(node);
|
|
118
131
|
}
|
|
119
132
|
else {
|
|
120
|
-
await sendSafeAck(options.logger, options.sendNode, (0,
|
|
133
|
+
await sendSafeAck(options.logger, options.sendNode, (0, global_1.buildAckNode)({
|
|
134
|
+
kind: 'receipt',
|
|
135
|
+
node,
|
|
136
|
+
retryType: true
|
|
137
|
+
}));
|
|
121
138
|
}
|
|
122
139
|
return true;
|
|
123
140
|
}
|
|
124
|
-
await sendSafeAck(options.logger, options.sendNode, (0,
|
|
141
|
+
await sendSafeAck(options.logger, options.sendNode, (0, global_1.buildAckNode)({
|
|
142
|
+
kind: 'receipt',
|
|
143
|
+
node,
|
|
144
|
+
includeParticipant: receiptType !== 'server-error'
|
|
145
|
+
}));
|
|
125
146
|
return true;
|
|
126
147
|
};
|
|
127
148
|
}
|
|
@@ -147,6 +168,8 @@ function createIncomingFailureHandler(options) {
|
|
|
147
168
|
function createIncomingNotificationHandler(options) {
|
|
148
169
|
return async (node) => {
|
|
149
170
|
const notificationType = node.attrs.type ?? '';
|
|
171
|
+
const includeParticipantInAck = NOTIFICATION_TYPES_WITH_PARTICIPANT_ACK.has(notificationType);
|
|
172
|
+
const includeTypeInAck = !NOTIFICATION_TYPES_WITHOUT_TYPE_ACK.has(notificationType);
|
|
150
173
|
const classification = classifyNotificationType(notificationType);
|
|
151
174
|
const firstChildTag = (0, helpers_1.getFirstNodeChild)(node)?.tag;
|
|
152
175
|
const baseEvent = createIncomingBaseEvent(node);
|
|
@@ -181,7 +204,12 @@ function createIncomingNotificationHandler(options) {
|
|
|
181
204
|
reason: `notification.${notificationType || 'unknown'}.not_supported`
|
|
182
205
|
});
|
|
183
206
|
}
|
|
184
|
-
await sendSafeAck(options.logger, options.sendNode, (0,
|
|
207
|
+
await sendSafeAck(options.logger, options.sendNode, (0, global_1.buildAckNode)({
|
|
208
|
+
kind: 'notification',
|
|
209
|
+
node,
|
|
210
|
+
includeParticipant: includeParticipantInAck,
|
|
211
|
+
includeType: includeTypeInAck
|
|
212
|
+
}));
|
|
185
213
|
if (notificationType === 'server_sync' && serverSyncCollections.length > 0) {
|
|
186
214
|
const collectionsCsv = serverSyncCollections.join(',');
|
|
187
215
|
if (!options.syncAppState) {
|
|
@@ -200,6 +228,41 @@ function createIncomingNotificationHandler(options) {
|
|
|
200
228
|
return true;
|
|
201
229
|
};
|
|
202
230
|
}
|
|
231
|
+
function createIncomingRegistrationNotificationHandler(options) {
|
|
232
|
+
return async (node) => {
|
|
233
|
+
if (node.attrs.type !== constants_1.WA_NOTIFICATION_TYPES.REGISTRATION) {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
const parsed = (0, registration_1.parseRegistrationNotification)(node);
|
|
237
|
+
if (!parsed) {
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
const baseEvent = createIncomingBaseEvent(node);
|
|
241
|
+
if (parsed.kind === 'registration_code') {
|
|
242
|
+
options.emitRegistrationCode({
|
|
243
|
+
...baseEvent,
|
|
244
|
+
code: parsed.code,
|
|
245
|
+
expiryTimestampMs: parsed.expiryTimestampMs,
|
|
246
|
+
fromDeviceId: parsed.fromDeviceId
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
options.emitAccountTakeoverNotice({
|
|
251
|
+
...baseEvent,
|
|
252
|
+
serverToken: parsed.serverToken,
|
|
253
|
+
attemptTimestampMs: parsed.attemptTimestampMs,
|
|
254
|
+
newDeviceName: parsed.newDeviceName,
|
|
255
|
+
newDevicePlatform: parsed.newDevicePlatform,
|
|
256
|
+
newDeviceAppVersion: parsed.newDeviceAppVersion
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
await sendSafeAck(options.logger, options.sendNode, (0, global_1.buildAckNode)({
|
|
260
|
+
kind: 'notification',
|
|
261
|
+
node
|
|
262
|
+
}));
|
|
263
|
+
return true;
|
|
264
|
+
};
|
|
265
|
+
}
|
|
203
266
|
function createIncomingGroupNotificationHandler(options) {
|
|
204
267
|
return async (node) => {
|
|
205
268
|
if (node.attrs.type !== constants_1.WA_NOTIFICATION_TYPES.GROUP) {
|
|
@@ -219,7 +282,11 @@ function createIncomingGroupNotificationHandler(options) {
|
|
|
219
282
|
reason: `notification.${constants_1.WA_NOTIFICATION_TYPES.GROUP}.empty`
|
|
220
283
|
});
|
|
221
284
|
}
|
|
222
|
-
await sendSafeAck(options.logger, options.sendNode, (0,
|
|
285
|
+
await sendSafeAck(options.logger, options.sendNode, (0, global_1.buildAckNode)({
|
|
286
|
+
kind: 'notification',
|
|
287
|
+
node,
|
|
288
|
+
includeParticipant: true
|
|
289
|
+
}));
|
|
223
290
|
return true;
|
|
224
291
|
};
|
|
225
292
|
}
|