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
|
@@ -5,6 +5,7 @@ const WaComms_1 = require("../../transport/WaComms");
|
|
|
5
5
|
const primitives_1 = require("../../util/primitives");
|
|
6
6
|
class WaConnectionManager {
|
|
7
7
|
constructor(options) {
|
|
8
|
+
this.lastConnectWasNewLogin = false;
|
|
8
9
|
this.logger = options.logger;
|
|
9
10
|
this.options = options.options;
|
|
10
11
|
this.authClient = options.authClient;
|
|
@@ -33,11 +34,12 @@ class WaConnectionManager {
|
|
|
33
34
|
const operation = this.runLifecycleOperation(async () => {
|
|
34
35
|
await this.connectInternal(frameHandler, lifecycleGeneration);
|
|
35
36
|
});
|
|
36
|
-
|
|
37
|
-
if (this.connectPromise ===
|
|
37
|
+
const promise = operation.finally(() => {
|
|
38
|
+
if (this.connectPromise === promise) {
|
|
38
39
|
this.connectPromise = null;
|
|
39
40
|
}
|
|
40
41
|
});
|
|
42
|
+
this.connectPromise = promise;
|
|
41
43
|
return this.connectPromise;
|
|
42
44
|
}
|
|
43
45
|
scheduleReconnectAfterPairing() {
|
|
@@ -67,6 +69,9 @@ class WaConnectionManager {
|
|
|
67
69
|
isConnected() {
|
|
68
70
|
return !!(this.comms && this.comms.getCommsState().connected);
|
|
69
71
|
}
|
|
72
|
+
wasNewLogin() {
|
|
73
|
+
return this.lastConnectWasNewLogin;
|
|
74
|
+
}
|
|
70
75
|
getComms() {
|
|
71
76
|
return this.comms;
|
|
72
77
|
}
|
|
@@ -96,6 +101,7 @@ class WaConnectionManager {
|
|
|
96
101
|
}
|
|
97
102
|
this.logger.info('wa client connect start');
|
|
98
103
|
let credentials = await this.authClient.loadOrCreateCredentials();
|
|
104
|
+
this.lastConnectWasNewLogin = !credentials.meJid;
|
|
99
105
|
this.assertLifecycleCurrent(lifecycleGeneration, 'connect');
|
|
100
106
|
try {
|
|
101
107
|
await this.startCommsWithCredentials(credentials, frameHandler, lifecycleGeneration);
|
|
@@ -130,11 +136,12 @@ class WaConnectionManager {
|
|
|
130
136
|
const operation = this.runLifecycleOperation(async () => {
|
|
131
137
|
await this.reconnectAsRegisteredAfterPairingInternal();
|
|
132
138
|
});
|
|
133
|
-
|
|
134
|
-
if (this.pairingReconnectPromise ===
|
|
139
|
+
const promise = operation.finally(() => {
|
|
140
|
+
if (this.pairingReconnectPromise === promise) {
|
|
135
141
|
this.pairingReconnectPromise = null;
|
|
136
142
|
}
|
|
137
143
|
});
|
|
144
|
+
this.pairingReconnectPromise = promise;
|
|
138
145
|
return this.pairingReconnectPromise;
|
|
139
146
|
}
|
|
140
147
|
async reconnectAsRegisteredAfterPairingInternal() {
|
|
@@ -179,12 +186,14 @@ class WaConnectionManager {
|
|
|
179
186
|
this.pendingComms = null;
|
|
180
187
|
this.clearCommsBinding(currentComms ?? undefined);
|
|
181
188
|
await this.authClient.clearTransientState();
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
189
|
+
await Promise.all([
|
|
190
|
+
pendingComms && pendingComms !== currentComms
|
|
191
|
+
? this.stopCommsQuietly(pendingComms, 'failed to stop pending comms during disconnect')
|
|
192
|
+
: Promise.resolve(),
|
|
193
|
+
currentComms
|
|
194
|
+
? this.stopCommsQuietly(currentComms, 'failed to stop comms during disconnect')
|
|
195
|
+
: Promise.resolve()
|
|
196
|
+
]);
|
|
188
197
|
if (this.isLifecycleCurrent(lifecycleGeneration)) {
|
|
189
198
|
this.logger.info('wa client disconnected');
|
|
190
199
|
}
|
|
@@ -194,7 +203,10 @@ class WaConnectionManager {
|
|
|
194
203
|
this.logger.debug('starting comms with credentials', {
|
|
195
204
|
registered: credentials.meJid !== null && credentials.meJid !== undefined
|
|
196
205
|
});
|
|
197
|
-
const commsConfig = this.authClient.buildCommsConfig(this.options
|
|
206
|
+
const commsConfig = this.authClient.buildCommsConfig(this.options, {
|
|
207
|
+
noiseTrustedRootCa: this.options.testHooks?.noiseRootCa,
|
|
208
|
+
disableNoiseCertificateChainVerification: this.options.dangerous?.disableNoiseCertificateChainVerification
|
|
209
|
+
});
|
|
198
210
|
const comms = new WaComms_1.WaComms(commsConfig, this.logger);
|
|
199
211
|
this.pendingComms = comms;
|
|
200
212
|
this.mediaConnCache = null;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WaAbPropsCoordinator = void 0;
|
|
4
|
+
const abprops_1 = require("../events/abprops");
|
|
5
|
+
const abprops_2 = require("../../protocol/abprops");
|
|
6
|
+
const constants_1 = require("../../protocol/constants");
|
|
7
|
+
const abprops_3 = require("../../transport/node/builders/abprops");
|
|
8
|
+
const primitives_1 = require("../../util/primitives");
|
|
9
|
+
class WaAbPropsCoordinator {
|
|
10
|
+
constructor(options) {
|
|
11
|
+
this.logger = options.logger;
|
|
12
|
+
this.runtime = options.runtime;
|
|
13
|
+
this.cache = new Map();
|
|
14
|
+
this.syncState = { hash: null, abKey: null, refreshId: null };
|
|
15
|
+
this.syncPromise = null;
|
|
16
|
+
this.syncEpoch = 0;
|
|
17
|
+
this.pendingSync = false;
|
|
18
|
+
}
|
|
19
|
+
getConfigValue(name) {
|
|
20
|
+
const cached = this.cache.get(name);
|
|
21
|
+
if (cached !== undefined) {
|
|
22
|
+
return cached;
|
|
23
|
+
}
|
|
24
|
+
return abprops_2.AB_PROP_CONFIGS[name].defaultValue;
|
|
25
|
+
}
|
|
26
|
+
sync() {
|
|
27
|
+
if (this.syncPromise) {
|
|
28
|
+
this.pendingSync = true;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
this.startSync();
|
|
32
|
+
}
|
|
33
|
+
reset() {
|
|
34
|
+
this.cache.clear();
|
|
35
|
+
this.syncState.hash = null;
|
|
36
|
+
this.syncState.abKey = null;
|
|
37
|
+
this.syncState.refreshId = null;
|
|
38
|
+
this.syncPromise = null;
|
|
39
|
+
this.pendingSync = false;
|
|
40
|
+
this.syncEpoch += 1;
|
|
41
|
+
}
|
|
42
|
+
startSync() {
|
|
43
|
+
const epoch = this.syncEpoch;
|
|
44
|
+
this.pendingSync = false;
|
|
45
|
+
this.syncPromise = this.executeSyncWithRetry(epoch)
|
|
46
|
+
.catch((error) => {
|
|
47
|
+
this.logger.warn('ab props sync failed', {
|
|
48
|
+
message: (0, primitives_1.toError)(error).message
|
|
49
|
+
});
|
|
50
|
+
})
|
|
51
|
+
.finally(() => {
|
|
52
|
+
if (this.syncEpoch !== epoch) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
this.syncPromise = null;
|
|
56
|
+
if (this.pendingSync) {
|
|
57
|
+
this.startSync();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
async executeSyncWithRetry(epoch) {
|
|
62
|
+
const maxRetries = 3;
|
|
63
|
+
for (let attempt = 0; attempt < maxRetries; attempt += 1) {
|
|
64
|
+
if (this.syncEpoch !== epoch) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
await this.executeSync(epoch);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
if (attempt === maxRetries - 1) {
|
|
73
|
+
throw error;
|
|
74
|
+
}
|
|
75
|
+
this.logger.debug('ab props sync retrying', {
|
|
76
|
+
attempt: attempt + 1,
|
|
77
|
+
message: (0, primitives_1.toError)(error).message
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async executeSync(epoch) {
|
|
83
|
+
const iqNode = (0, abprops_3.buildGetAbPropsIq)({
|
|
84
|
+
hash: this.syncState.hash,
|
|
85
|
+
refreshId: this.syncState.refreshId
|
|
86
|
+
});
|
|
87
|
+
const response = await this.runtime.queryWithContext('abprops.sync', iqNode, constants_1.WA_DEFAULTS.IQ_TIMEOUT_MS);
|
|
88
|
+
if (this.syncEpoch !== epoch) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const result = (0, abprops_1.parseAbPropsIqResult)(response);
|
|
92
|
+
if (result.abKey !== null) {
|
|
93
|
+
this.syncState.abKey = result.abKey;
|
|
94
|
+
}
|
|
95
|
+
if (result.hash !== null) {
|
|
96
|
+
this.syncState.hash = result.hash;
|
|
97
|
+
}
|
|
98
|
+
if (result.refreshId !== null) {
|
|
99
|
+
this.syncState.refreshId = result.refreshId;
|
|
100
|
+
}
|
|
101
|
+
if (!result.isDeltaUpdate) {
|
|
102
|
+
this.cache.clear();
|
|
103
|
+
}
|
|
104
|
+
let applied = 0;
|
|
105
|
+
for (let i = 0; i < result.props.length; i += 1) {
|
|
106
|
+
const entry = result.props[i];
|
|
107
|
+
const name = (0, abprops_2.resolveAbPropNameByCode)(entry.configCode);
|
|
108
|
+
if (!name) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const config = abprops_2.AB_PROP_CONFIGS[name];
|
|
112
|
+
const parsed = parseConfigValue(entry.configValue, config.type, config.defaultValue);
|
|
113
|
+
this.cache.set(name, parsed);
|
|
114
|
+
applied += 1;
|
|
115
|
+
}
|
|
116
|
+
this.logger.info('ab props synced', {
|
|
117
|
+
received: result.props.length,
|
|
118
|
+
applied,
|
|
119
|
+
isDelta: result.isDeltaUpdate,
|
|
120
|
+
abKey: result.abKey,
|
|
121
|
+
refresh: result.refresh !== null ? clampRefresh(result.refresh) : null
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.WaAbPropsCoordinator = WaAbPropsCoordinator;
|
|
126
|
+
function parseConfigValue(value, type, defaultValue) {
|
|
127
|
+
if (value === null) {
|
|
128
|
+
return defaultValue;
|
|
129
|
+
}
|
|
130
|
+
if (type === 'bool') {
|
|
131
|
+
return value === '1' || value === 'true' || value === 'True';
|
|
132
|
+
}
|
|
133
|
+
if (type === 'int') {
|
|
134
|
+
const parsed = Number.parseInt(value, 10);
|
|
135
|
+
return Number.isSafeInteger(parsed) ? parsed : defaultValue;
|
|
136
|
+
}
|
|
137
|
+
return value;
|
|
138
|
+
}
|
|
139
|
+
function clampRefresh(seconds) {
|
|
140
|
+
return Math.max(abprops_2.WA_ABPROPS_REFRESH_BOUNDS.MIN_S, Math.min(abprops_2.WA_ABPROPS_REFRESH_BOUNDS.MAX_S, seconds));
|
|
141
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createBusinessCoordinator = createBusinessCoordinator;
|
|
4
|
+
const _proto_1 = require("../../proto.js");
|
|
5
|
+
const business_1 = require("../../transport/node/builders/business");
|
|
6
|
+
const helpers_1 = require("../../transport/node/helpers");
|
|
7
|
+
const query_1 = require("../../transport/node/query");
|
|
8
|
+
const primitives_1 = require("../../util/primitives");
|
|
9
|
+
function parseBusinessProfiles(result) {
|
|
10
|
+
const bizNode = (0, helpers_1.findNodeChild)(result, 'business_profile');
|
|
11
|
+
if (!bizNode) {
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
const profileNodes = (0, helpers_1.getNodeChildren)(bizNode);
|
|
15
|
+
const results = new Array(profileNodes.length);
|
|
16
|
+
let count = 0;
|
|
17
|
+
for (let i = 0; i < profileNodes.length; i += 1) {
|
|
18
|
+
const profileNode = profileNodes[i];
|
|
19
|
+
if (profileNode.tag !== 'profile')
|
|
20
|
+
continue;
|
|
21
|
+
const jid = profileNode.attrs.jid;
|
|
22
|
+
if (!jid)
|
|
23
|
+
continue;
|
|
24
|
+
const entry = { jid };
|
|
25
|
+
const tag = profileNode.attrs.tag;
|
|
26
|
+
if (tag)
|
|
27
|
+
entry.tag = tag;
|
|
28
|
+
const children = profileNode.content;
|
|
29
|
+
if (!Array.isArray(children)) {
|
|
30
|
+
results[count] = entry;
|
|
31
|
+
count += 1;
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const websites = [];
|
|
35
|
+
for (let j = 0; j < children.length; j += 1) {
|
|
36
|
+
const child = children[j];
|
|
37
|
+
const text = (0, helpers_1.getNodeTextContent)(child);
|
|
38
|
+
switch (child.tag) {
|
|
39
|
+
case 'description':
|
|
40
|
+
if (text !== undefined)
|
|
41
|
+
entry.description = text;
|
|
42
|
+
break;
|
|
43
|
+
case 'address':
|
|
44
|
+
if (text !== undefined)
|
|
45
|
+
entry.address = text;
|
|
46
|
+
break;
|
|
47
|
+
case 'email':
|
|
48
|
+
if (text !== undefined)
|
|
49
|
+
entry.email = text;
|
|
50
|
+
break;
|
|
51
|
+
case 'website':
|
|
52
|
+
if (text !== undefined)
|
|
53
|
+
websites.push({ url: text });
|
|
54
|
+
break;
|
|
55
|
+
case 'latitude':
|
|
56
|
+
if (text !== undefined) {
|
|
57
|
+
const val = Number.parseFloat(text);
|
|
58
|
+
if (!Number.isNaN(val))
|
|
59
|
+
entry.latitude = val;
|
|
60
|
+
}
|
|
61
|
+
break;
|
|
62
|
+
case 'longitude':
|
|
63
|
+
if (text !== undefined) {
|
|
64
|
+
const val = Number.parseFloat(text);
|
|
65
|
+
if (!Number.isNaN(val))
|
|
66
|
+
entry.longitude = val;
|
|
67
|
+
}
|
|
68
|
+
break;
|
|
69
|
+
case 'categories':
|
|
70
|
+
entry.categories = parseBusinessCategories(child);
|
|
71
|
+
break;
|
|
72
|
+
case 'business_hours':
|
|
73
|
+
entry.businessHours = parseBusinessHoursNode(child);
|
|
74
|
+
break;
|
|
75
|
+
case 'profile_options':
|
|
76
|
+
entry.profileOptions = parseProfileOptions(child);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (websites.length > 0)
|
|
81
|
+
entry.websites = websites;
|
|
82
|
+
results[count] = entry;
|
|
83
|
+
count += 1;
|
|
84
|
+
}
|
|
85
|
+
results.length = count;
|
|
86
|
+
return results;
|
|
87
|
+
}
|
|
88
|
+
function parseBusinessCategories(node) {
|
|
89
|
+
const children = (0, helpers_1.getNodeChildren)(node);
|
|
90
|
+
const categories = new Array(children.length);
|
|
91
|
+
let count = 0;
|
|
92
|
+
for (let i = 0; i < children.length; i += 1) {
|
|
93
|
+
const child = children[i];
|
|
94
|
+
if (child.tag !== 'category')
|
|
95
|
+
continue;
|
|
96
|
+
const id = child.attrs.id;
|
|
97
|
+
if (!id)
|
|
98
|
+
continue;
|
|
99
|
+
categories[count] = { id, name: (0, helpers_1.getNodeTextContent)(child) ?? '' };
|
|
100
|
+
count += 1;
|
|
101
|
+
}
|
|
102
|
+
categories.length = count;
|
|
103
|
+
return categories;
|
|
104
|
+
}
|
|
105
|
+
function parseBusinessHoursNode(node) {
|
|
106
|
+
const timezone = node.attrs.timezone;
|
|
107
|
+
const children = (0, helpers_1.getNodeChildren)(node);
|
|
108
|
+
const config = new Array(children.length);
|
|
109
|
+
let count = 0;
|
|
110
|
+
for (let i = 0; i < children.length; i += 1) {
|
|
111
|
+
const child = children[i];
|
|
112
|
+
if (child.tag !== 'business_hours_config')
|
|
113
|
+
continue;
|
|
114
|
+
const dayOfWeek = child.attrs.day_of_week;
|
|
115
|
+
const mode = child.attrs.mode;
|
|
116
|
+
if (!dayOfWeek || !mode)
|
|
117
|
+
continue;
|
|
118
|
+
const entry = { dayOfWeek, mode };
|
|
119
|
+
const openTime = child.attrs.open_time;
|
|
120
|
+
const closeTime = child.attrs.close_time;
|
|
121
|
+
if (openTime)
|
|
122
|
+
entry.openTime = Number.parseInt(openTime, 10);
|
|
123
|
+
if (closeTime)
|
|
124
|
+
entry.closeTime = Number.parseInt(closeTime, 10);
|
|
125
|
+
config[count] = entry;
|
|
126
|
+
count += 1;
|
|
127
|
+
}
|
|
128
|
+
config.length = count;
|
|
129
|
+
return { timezone, config };
|
|
130
|
+
}
|
|
131
|
+
function parseProfileOptions(node) {
|
|
132
|
+
const children = (0, helpers_1.getNodeChildren)(node);
|
|
133
|
+
const options = {};
|
|
134
|
+
for (let i = 0; i < children.length; i += 1) {
|
|
135
|
+
const child = children[i];
|
|
136
|
+
const text = (0, helpers_1.getNodeTextContent)(child);
|
|
137
|
+
if (text !== undefined) {
|
|
138
|
+
options[child.tag] = text;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return options;
|
|
142
|
+
}
|
|
143
|
+
const VN_ISSUER_API = 'ent:wa';
|
|
144
|
+
const VN_ISSUER_SMB = 'smb:wa';
|
|
145
|
+
function parseCertificateContent(contentBytes) {
|
|
146
|
+
try {
|
|
147
|
+
const cert = _proto_1.proto.VerifiedNameCertificate.decode(contentBytes);
|
|
148
|
+
if (!cert.details)
|
|
149
|
+
return null;
|
|
150
|
+
const details = _proto_1.proto.VerifiedNameCertificate.Details.decode(cert.details);
|
|
151
|
+
return {
|
|
152
|
+
name: details.verifiedName ?? undefined,
|
|
153
|
+
serial: details.serial !== null && details.serial !== undefined
|
|
154
|
+
? String((0, primitives_1.longToNumber)(details.serial))
|
|
155
|
+
: undefined,
|
|
156
|
+
isApi: details.issuer === VN_ISSUER_API,
|
|
157
|
+
isSmb: details.issuer === VN_ISSUER_SMB
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function parseVerifiedName(result) {
|
|
165
|
+
const vnNode = (0, helpers_1.findNodeChild)(result, 'verified_name');
|
|
166
|
+
if (!vnNode)
|
|
167
|
+
return null;
|
|
168
|
+
const level = vnNode.attrs.verified_level;
|
|
169
|
+
const attrSerial = vnNode.attrs.serial;
|
|
170
|
+
const contentBytes = vnNode.content instanceof Uint8Array ? vnNode.content : undefined;
|
|
171
|
+
const certData = contentBytes !== undefined ? parseCertificateContent(contentBytes) : null;
|
|
172
|
+
const entry = {
|
|
173
|
+
name: certData?.name,
|
|
174
|
+
level,
|
|
175
|
+
serial: attrSerial ?? certData?.serial,
|
|
176
|
+
isApi: certData?.isApi === true,
|
|
177
|
+
isSmb: certData?.isSmb === true
|
|
178
|
+
};
|
|
179
|
+
const actualActors = vnNode.attrs.actual_actors;
|
|
180
|
+
const hostStorage = vnNode.attrs.host_storage;
|
|
181
|
+
const privacyModeTs = vnNode.attrs.privacy_mode_ts;
|
|
182
|
+
if (actualActors !== undefined && hostStorage !== undefined && privacyModeTs !== undefined) {
|
|
183
|
+
entry.privacyMode = {
|
|
184
|
+
actualActors: Number.parseInt(actualActors, 10),
|
|
185
|
+
hostStorage: Number.parseInt(hostStorage, 10),
|
|
186
|
+
privacyModeTs: Number.parseInt(privacyModeTs, 10)
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
return entry;
|
|
190
|
+
}
|
|
191
|
+
function createBusinessCoordinator(options) {
|
|
192
|
+
const { queryWithContext } = options;
|
|
193
|
+
return {
|
|
194
|
+
getBusinessProfile: async (jids) => {
|
|
195
|
+
if (jids.length === 0)
|
|
196
|
+
return [];
|
|
197
|
+
const node = (0, business_1.buildGetBusinessProfileIq)(jids);
|
|
198
|
+
const result = await queryWithContext('business.getProfile', node, undefined, {
|
|
199
|
+
count: jids.length
|
|
200
|
+
});
|
|
201
|
+
(0, query_1.assertIqResult)(result, 'business.getProfile');
|
|
202
|
+
return parseBusinessProfiles(result);
|
|
203
|
+
},
|
|
204
|
+
editBusinessProfile: async (input) => {
|
|
205
|
+
const node = (0, business_1.buildEditBusinessProfileIq)(input);
|
|
206
|
+
const result = await queryWithContext('business.editProfile', node);
|
|
207
|
+
(0, query_1.assertIqResult)(result, 'business.editProfile');
|
|
208
|
+
},
|
|
209
|
+
getVerifiedName: async (jid) => {
|
|
210
|
+
const node = (0, business_1.buildGetVerifiedNameIq)(jid);
|
|
211
|
+
const result = await queryWithContext('business.getVerifiedName', node, undefined, {
|
|
212
|
+
jid
|
|
213
|
+
});
|
|
214
|
+
(0, query_1.assertIqResult)(result, 'business.getVerifiedName');
|
|
215
|
+
return parseVerifiedName(result);
|
|
216
|
+
},
|
|
217
|
+
updateCoverPhoto: async (id, timestamp, token) => {
|
|
218
|
+
const node = (0, business_1.buildUpdateCoverPhotoIq)(id, timestamp, token);
|
|
219
|
+
const result = await queryWithContext('business.updateCoverPhoto', node, undefined, {
|
|
220
|
+
id
|
|
221
|
+
});
|
|
222
|
+
(0, query_1.assertIqResult)(result, 'business.updateCoverPhoto');
|
|
223
|
+
},
|
|
224
|
+
deleteCoverPhoto: async (id) => {
|
|
225
|
+
const node = (0, business_1.buildDeleteCoverPhotoIq)(id);
|
|
226
|
+
const result = await queryWithContext('business.deleteCoverPhoto', node, undefined, {
|
|
227
|
+
id
|
|
228
|
+
});
|
|
229
|
+
(0, query_1.assertIqResult)(result, 'business.deleteCoverPhoto');
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createEmailCoordinator = createEmailCoordinator;
|
|
4
|
+
const email_1 = require("../../protocol/email");
|
|
5
|
+
const email_2 = require("../../transport/node/builders/email");
|
|
6
|
+
const helpers_1 = require("../../transport/node/helpers");
|
|
7
|
+
const query_1 = require("../../transport/node/query");
|
|
8
|
+
function createEmailCoordinator(options) {
|
|
9
|
+
const { queryWithContext } = options;
|
|
10
|
+
return {
|
|
11
|
+
getStatus: async () => {
|
|
12
|
+
const result = await queryWithContext('email.getStatus', (0, email_2.buildGetEmailIq)());
|
|
13
|
+
(0, query_1.assertIqResult)(result, 'email.getStatus');
|
|
14
|
+
return parseEmailStatus(result);
|
|
15
|
+
},
|
|
16
|
+
setEmail: async (email, context) => {
|
|
17
|
+
const result = await queryWithContext('email.set', (0, email_2.buildSetEmailIq)(email, context), undefined, context !== undefined ? { context } : {});
|
|
18
|
+
(0, query_1.assertIqResult)(result, 'email.set');
|
|
19
|
+
return parseEmailStatus(result);
|
|
20
|
+
},
|
|
21
|
+
requestVerificationCode: async (input) => {
|
|
22
|
+
const result = await queryWithContext('email.requestCode', (0, email_2.buildRequestEmailVerificationCodeIq)(input), undefined, { languageCode: input.languageCode, localeCode: input.localeCode });
|
|
23
|
+
(0, query_1.assertIqResult)(result, 'email.requestCode');
|
|
24
|
+
},
|
|
25
|
+
verifyCode: async (code) => {
|
|
26
|
+
const result = await queryWithContext('email.verifyCode', (0, email_2.buildVerifyEmailCodeIq)(code));
|
|
27
|
+
(0, query_1.assertIqResult)(result, 'email.verifyCode');
|
|
28
|
+
return parseVerifyCodeResult(result);
|
|
29
|
+
},
|
|
30
|
+
confirm: async (context) => {
|
|
31
|
+
const result = await queryWithContext('email.confirm', (0, email_2.buildConfirmEmailIq)(context), undefined, context !== undefined ? { context } : {});
|
|
32
|
+
(0, query_1.assertIqResult)(result, 'email.confirm');
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function parseEmailStatus(result) {
|
|
37
|
+
const emailNode = (0, helpers_1.findNodeChild)(result, email_1.WA_EMAIL_TAGS.EMAIL);
|
|
38
|
+
if (!emailNode) {
|
|
39
|
+
return { email: null, verified: false, confirmed: false };
|
|
40
|
+
}
|
|
41
|
+
const verifiedAttr = emailNode.attrs.verified;
|
|
42
|
+
const addressNode = (0, helpers_1.findNodeChild)(emailNode, email_1.WA_EMAIL_TAGS.EMAIL_ADDRESS);
|
|
43
|
+
const confirmedNode = (0, helpers_1.findNodeChild)(emailNode, email_1.WA_EMAIL_TAGS.CONFIRMED);
|
|
44
|
+
return {
|
|
45
|
+
email: addressNode ? ((0, helpers_1.getNodeTextContent)(addressNode) ?? null) : null,
|
|
46
|
+
verified: verifiedAttr === 'true',
|
|
47
|
+
confirmed: confirmedNode ? (0, helpers_1.getNodeTextContent)(confirmedNode) === 'true' : false
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function parseVerifyCodeResult(result) {
|
|
51
|
+
const emailNode = (0, helpers_1.findNodeChild)(result, email_1.WA_EMAIL_TAGS.EMAIL);
|
|
52
|
+
if (!emailNode) {
|
|
53
|
+
return { verified: false, autoVerifyFailed: false, email: null };
|
|
54
|
+
}
|
|
55
|
+
const doVerify = emailNode.attrs.do_verify;
|
|
56
|
+
const autoVerifyNode = (0, helpers_1.findNodeChild)(emailNode, email_1.WA_EMAIL_TAGS.AUTO_VERIFY);
|
|
57
|
+
const addressNode = (0, helpers_1.findNodeChild)(emailNode, email_1.WA_EMAIL_TAGS.EMAIL_ADDRESS);
|
|
58
|
+
return {
|
|
59
|
+
verified: doVerify === 'true',
|
|
60
|
+
autoVerifyFailed: autoVerifyNode ? (0, helpers_1.getNodeTextContent)(autoVerifyNode) === 'fail' : false,
|
|
61
|
+
email: addressNode ? ((0, helpers_1.getNodeTextContent)(addressNode) ?? null) : null
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -10,20 +10,24 @@ const helpers_1 = require("../../transport/node/helpers");
|
|
|
10
10
|
const query_1 = require("../../transport/node/query");
|
|
11
11
|
function parseGroupParticipants(node) {
|
|
12
12
|
const parsed = (0, group_1.parseParticipants)(node);
|
|
13
|
-
const participants =
|
|
14
|
-
|
|
13
|
+
const participants = new Array(parsed.length);
|
|
14
|
+
let participantsCount = 0;
|
|
15
|
+
for (let index = 0; index < parsed.length; index += 1) {
|
|
16
|
+
const participant = parsed[index];
|
|
15
17
|
if (!participant.jid) {
|
|
16
18
|
continue;
|
|
17
19
|
}
|
|
18
20
|
const type = participant.role ?? group_2.WA_GROUP_PARTICIPANT_TYPES.REGULAR;
|
|
19
|
-
participants
|
|
21
|
+
participants[participantsCount] = {
|
|
20
22
|
jid: participant.jid,
|
|
21
23
|
type,
|
|
22
24
|
isAdmin: type === group_2.WA_GROUP_PARTICIPANT_TYPES.ADMIN ||
|
|
23
25
|
type === group_2.WA_GROUP_PARTICIPANT_TYPES.SUPERADMIN,
|
|
24
26
|
isSuperAdmin: type === group_2.WA_GROUP_PARTICIPANT_TYPES.SUPERADMIN
|
|
25
|
-
}
|
|
27
|
+
};
|
|
28
|
+
participantsCount += 1;
|
|
26
29
|
}
|
|
30
|
+
participants.length = participantsCount;
|
|
27
31
|
return participants;
|
|
28
32
|
}
|
|
29
33
|
function parseGroupMetadata(node) {
|
|
@@ -104,9 +108,9 @@ function createGroupCoordinator(options) {
|
|
|
104
108
|
const result = await queryWithContext('group.list', node);
|
|
105
109
|
(0, query_1.assertIqResult)(result, 'group.list');
|
|
106
110
|
const groupNodes = (0, helpers_1.getNodeChildrenByTagFromChildren)(result, nodes_1.WA_NODE_TAGS.GROUP);
|
|
107
|
-
const metadata =
|
|
108
|
-
for (
|
|
109
|
-
metadata
|
|
111
|
+
const metadata = new Array(groupNodes.length);
|
|
112
|
+
for (let index = 0; index < groupNodes.length; index += 1) {
|
|
113
|
+
metadata[index] = parseGroupMetadata(groupNodes[index]);
|
|
110
114
|
}
|
|
111
115
|
return metadata;
|
|
112
116
|
},
|
|
@@ -6,7 +6,7 @@ const constants_1 = require("../../protocol/constants");
|
|
|
6
6
|
const helpers_1 = require("../../transport/node/helpers");
|
|
7
7
|
const parse_1 = require("../../transport/stream/parse");
|
|
8
8
|
const primitives_1 = require("../../util/primitives");
|
|
9
|
-
const
|
|
9
|
+
const INFO_BULLETIN_CHILD_TAGS = new Set([
|
|
10
10
|
'offline',
|
|
11
11
|
'offline_preview',
|
|
12
12
|
'priority_offline_complete',
|
|
@@ -18,6 +18,7 @@ class WaIncomingNodeCoordinator {
|
|
|
18
18
|
constructor(options) {
|
|
19
19
|
this.logger = options.logger;
|
|
20
20
|
this.runtime = options.runtime;
|
|
21
|
+
this.offlineResume = options.offlineResume;
|
|
21
22
|
this.nodeHandlerRegistry = new Map();
|
|
22
23
|
this.registerDefaultIncomingHandlers();
|
|
23
24
|
this.mediaConnWarmupPromise = null;
|
|
@@ -28,6 +29,9 @@ class WaIncomingNodeCoordinator {
|
|
|
28
29
|
id: node.attrs.id,
|
|
29
30
|
type: node.attrs.type
|
|
30
31
|
});
|
|
32
|
+
if (node.attrs.offline !== undefined) {
|
|
33
|
+
this.offlineResume.trackOfflineStanza();
|
|
34
|
+
}
|
|
31
35
|
const streamControlResult = (0, parse_1.parseStreamControlNode)(node);
|
|
32
36
|
if (streamControlResult) {
|
|
33
37
|
await this.runtime.handleStreamControlResult(streamControlResult);
|
|
@@ -147,6 +151,16 @@ class WaIncomingNodeCoordinator {
|
|
|
147
151
|
emitUnhandledStanza: runtime.emitUnhandledIncomingNode
|
|
148
152
|
})
|
|
149
153
|
});
|
|
154
|
+
this.registerIncomingHandler({
|
|
155
|
+
tag: constants_1.WA_NODE_TAGS.NOTIFICATION,
|
|
156
|
+
subtype: constants_1.WA_NOTIFICATION_TYPES.REGISTRATION,
|
|
157
|
+
handler: (0, incoming_1.createIncomingRegistrationNotificationHandler)({
|
|
158
|
+
logger: this.logger,
|
|
159
|
+
sendNode: runtime.sendNode,
|
|
160
|
+
emitRegistrationCode: runtime.emitRegistrationCode,
|
|
161
|
+
emitAccountTakeoverNotice: runtime.emitAccountTakeoverNotice
|
|
162
|
+
})
|
|
163
|
+
});
|
|
150
164
|
this.registerIncomingHandler({
|
|
151
165
|
tag: constants_1.WA_NODE_TAGS.NOTIFICATION,
|
|
152
166
|
handler: (0, incoming_1.createIncomingNotificationHandler)({
|
|
@@ -200,6 +214,7 @@ class WaIncomingNodeCoordinator {
|
|
|
200
214
|
handler: (0, incoming_1.createIncomingFailureHandler)({
|
|
201
215
|
logger: this.logger,
|
|
202
216
|
emitIncomingFailure: runtime.emitIncomingFailure,
|
|
217
|
+
stopComms: runtime.stopComms,
|
|
203
218
|
disconnect: runtime.disconnect,
|
|
204
219
|
clearStoredCredentials: runtime.clearStoredCredentials
|
|
205
220
|
})
|
|
@@ -265,13 +280,24 @@ class WaIncomingNodeCoordinator {
|
|
|
265
280
|
return false;
|
|
266
281
|
}
|
|
267
282
|
let handled = false;
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
283
|
+
const children = (0, helpers_1.getNodeChildren)(node);
|
|
284
|
+
for (const child of children) {
|
|
285
|
+
if (INFO_BULLETIN_CHILD_TAGS.has(child.tag)) {
|
|
286
|
+
this.runtime.emitIncomingNotification((0, incoming_1.createInfoBulletinNotificationEvent)(node, child.tag, {
|
|
287
|
+
count: (0, primitives_1.parseOptionalInt)(child.attrs.count),
|
|
288
|
+
message: (0, primitives_1.parseOptionalInt)(child.attrs.message),
|
|
289
|
+
receipt: (0, primitives_1.parseOptionalInt)(child.attrs.receipt),
|
|
290
|
+
notification: (0, primitives_1.parseOptionalInt)(child.attrs.notification),
|
|
291
|
+
t: (0, primitives_1.parseOptionalInt)(child.attrs.t)
|
|
292
|
+
}));
|
|
293
|
+
if (child.tag === 'offline_preview') {
|
|
294
|
+
this.offlineResume.handleOfflinePreview((0, primitives_1.parseOptionalInt)(child.attrs.count) ?? 0);
|
|
295
|
+
}
|
|
296
|
+
if (child.tag === 'offline') {
|
|
297
|
+
this.offlineResume.handleOfflineComplete((0, primitives_1.parseOptionalInt)(child.attrs.count) ?? 0);
|
|
298
|
+
}
|
|
299
|
+
handled = true;
|
|
300
|
+
}
|
|
275
301
|
}
|
|
276
302
|
const edgeRoutingNode = (0, helpers_1.findNodeChild)(node, constants_1.WA_NODE_TAGS.EDGE_ROUTING);
|
|
277
303
|
if (edgeRoutingNode) {
|