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
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WaOfflineResumeCoordinator = void 0;
|
|
4
|
+
const offline_1 = require("../../transport/node/builders/offline");
|
|
5
|
+
const primitives_1 = require("../../util/primitives");
|
|
6
|
+
const WA_OFFLINE_RESUME = Object.freeze({
|
|
7
|
+
BATCH_SIZE: 200,
|
|
8
|
+
STANZA_TIMEOUT_MS: 60000
|
|
9
|
+
});
|
|
10
|
+
const WA_OFFLINE_RESUME_STATE = Object.freeze({
|
|
11
|
+
INIT: 'init',
|
|
12
|
+
RESUMING: 'resuming',
|
|
13
|
+
COMPLETE: 'complete'
|
|
14
|
+
});
|
|
15
|
+
class WaOfflineResumeCoordinator {
|
|
16
|
+
constructor(options) {
|
|
17
|
+
this.logger = options.logger;
|
|
18
|
+
this.runtime = options.runtime;
|
|
19
|
+
this.state = WA_OFFLINE_RESUME_STATE.INIT;
|
|
20
|
+
this.totalStanzas = 0;
|
|
21
|
+
this.pendingStanzas = 0;
|
|
22
|
+
this.stanzaTimeout = null;
|
|
23
|
+
}
|
|
24
|
+
get isComplete() {
|
|
25
|
+
return this.state === WA_OFFLINE_RESUME_STATE.COMPLETE;
|
|
26
|
+
}
|
|
27
|
+
get isResuming() {
|
|
28
|
+
return this.state === WA_OFFLINE_RESUME_STATE.RESUMING;
|
|
29
|
+
}
|
|
30
|
+
handleOfflinePreview(stanzaCount) {
|
|
31
|
+
this.clearTimers();
|
|
32
|
+
this.state = WA_OFFLINE_RESUME_STATE.RESUMING;
|
|
33
|
+
this.totalStanzas = stanzaCount;
|
|
34
|
+
this.pendingStanzas = stanzaCount;
|
|
35
|
+
this.logger.info('offline resume started', {
|
|
36
|
+
totalStanzas: stanzaCount
|
|
37
|
+
});
|
|
38
|
+
this.runtime.emitOfflineResume({
|
|
39
|
+
status: 'resuming',
|
|
40
|
+
totalStanzas: stanzaCount,
|
|
41
|
+
remainingStanzas: stanzaCount,
|
|
42
|
+
forced: false
|
|
43
|
+
});
|
|
44
|
+
void this.sendOfflineBatch();
|
|
45
|
+
this.resetStanzaTimeout();
|
|
46
|
+
}
|
|
47
|
+
handleOfflineComplete(serverStanzaCount) {
|
|
48
|
+
if (this.state !== WA_OFFLINE_RESUME_STATE.RESUMING) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
this.completeResume(false, serverStanzaCount);
|
|
52
|
+
}
|
|
53
|
+
trackOfflineStanza() {
|
|
54
|
+
if (this.state !== WA_OFFLINE_RESUME_STATE.RESUMING) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
this.pendingStanzas = Math.max(0, this.pendingStanzas - 1);
|
|
58
|
+
this.resetStanzaTimeout();
|
|
59
|
+
}
|
|
60
|
+
reset() {
|
|
61
|
+
this.clearTimers();
|
|
62
|
+
this.state = WA_OFFLINE_RESUME_STATE.INIT;
|
|
63
|
+
this.totalStanzas = 0;
|
|
64
|
+
this.pendingStanzas = 0;
|
|
65
|
+
}
|
|
66
|
+
completeResume(forced, serverStanzaCount) {
|
|
67
|
+
this.clearTimers();
|
|
68
|
+
this.state = WA_OFFLINE_RESUME_STATE.COMPLETE;
|
|
69
|
+
this.logger.info('offline resume complete', {
|
|
70
|
+
totalStanzas: this.totalStanzas,
|
|
71
|
+
remainingStanzas: this.pendingStanzas,
|
|
72
|
+
serverStanzaCount,
|
|
73
|
+
forced
|
|
74
|
+
});
|
|
75
|
+
this.runtime.emitOfflineResume({
|
|
76
|
+
status: 'complete',
|
|
77
|
+
totalStanzas: this.totalStanzas,
|
|
78
|
+
remainingStanzas: this.pendingStanzas,
|
|
79
|
+
forced
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
async sendOfflineBatch() {
|
|
83
|
+
try {
|
|
84
|
+
await this.runtime.sendNode((0, offline_1.buildOfflineBatchNode)(WA_OFFLINE_RESUME.BATCH_SIZE));
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
this.logger.warn('offline batch request failed', {
|
|
88
|
+
message: (0, primitives_1.toError)(err).message
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
resetStanzaTimeout() {
|
|
93
|
+
if (this.stanzaTimeout !== null) {
|
|
94
|
+
clearTimeout(this.stanzaTimeout);
|
|
95
|
+
}
|
|
96
|
+
this.stanzaTimeout = setTimeout(() => {
|
|
97
|
+
this.stanzaTimeout = null;
|
|
98
|
+
if (this.state === WA_OFFLINE_RESUME_STATE.RESUMING) {
|
|
99
|
+
this.logger.warn('offline resume forced complete due to stanza timeout', {
|
|
100
|
+
totalStanzas: this.totalStanzas,
|
|
101
|
+
remainingStanzas: this.pendingStanzas
|
|
102
|
+
});
|
|
103
|
+
this.completeResume(true);
|
|
104
|
+
}
|
|
105
|
+
}, WA_OFFLINE_RESUME.STANZA_TIMEOUT_MS);
|
|
106
|
+
}
|
|
107
|
+
clearTimers() {
|
|
108
|
+
if (this.stanzaTimeout !== null) {
|
|
109
|
+
clearTimeout(this.stanzaTimeout);
|
|
110
|
+
this.stanzaTimeout = null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.WaOfflineResumeCoordinator = WaOfflineResumeCoordinator;
|
|
@@ -10,6 +10,7 @@ class WaPassiveTasksCoordinator {
|
|
|
10
10
|
constructor(options) {
|
|
11
11
|
this.logger = options.logger;
|
|
12
12
|
this.signalStore = options.signalStore;
|
|
13
|
+
this.preKeyStore = options.preKeyStore;
|
|
13
14
|
this.signalDigestSync = options.signalDigestSync;
|
|
14
15
|
this.signalRotateKey = options.signalRotateKey;
|
|
15
16
|
this.signedPreKeyRotationIntervalMs =
|
|
@@ -17,6 +18,8 @@ class WaPassiveTasksCoordinator {
|
|
|
17
18
|
this.signedPreKeyServerErrorBackoffMs =
|
|
18
19
|
options.signedPreKeyServerErrorBackoffMs ?? constants_2.SIGNAL_SIGNED_PREKEY_SERVER_ERROR_BACKOFF_MS;
|
|
19
20
|
this.runtime = options.runtime;
|
|
21
|
+
this.mobilePrimary = options.mobilePrimary ?? false;
|
|
22
|
+
this.appStateSync = options.appStateSync;
|
|
20
23
|
this.passiveTasksPromise = null;
|
|
21
24
|
}
|
|
22
25
|
startPassiveTasksAfterConnect() {
|
|
@@ -34,6 +37,16 @@ class WaPassiveTasksCoordinator {
|
|
|
34
37
|
this.passiveTasksPromise = null;
|
|
35
38
|
});
|
|
36
39
|
}
|
|
40
|
+
async handlePreKeyLowNotification() {
|
|
41
|
+
await Promise.all([
|
|
42
|
+
this.preKeyStore.setServerHasPreKeys(false),
|
|
43
|
+
this.runtime.persistServerHasPreKeys(false)
|
|
44
|
+
]);
|
|
45
|
+
await this.uploadPreKeysIfMissing(false);
|
|
46
|
+
}
|
|
47
|
+
async handleDigestNotification() {
|
|
48
|
+
await this.validateDigestAndRecoverPreKeys();
|
|
49
|
+
}
|
|
37
50
|
resetInFlightState() {
|
|
38
51
|
if (!this.passiveTasksPromise) {
|
|
39
52
|
return;
|
|
@@ -47,14 +60,36 @@ class WaPassiveTasksCoordinator {
|
|
|
47
60
|
this.logger.trace('passive connect tasks skipped: session is not registered');
|
|
48
61
|
return;
|
|
49
62
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
63
|
+
this.runtime.syncAbProps();
|
|
64
|
+
if (this.mobilePrimary && this.appStateSync) {
|
|
65
|
+
await this.appStateSync.ensureInitialSyncKey().catch((error) => {
|
|
66
|
+
this.logger.warn('app-state initial key generation failed', {
|
|
67
|
+
message: (0, primitives_1.toError)(error).message
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
await this.runtime.sendPresenceAvailable().catch((error) => {
|
|
72
|
+
this.logger.warn('presence available send failed', {
|
|
73
|
+
message: (0, primitives_1.toError)(error).message
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
const [registrationInfo, signedPreKey, serverHasPreKeys, signedPreKeyRotationTs] = await Promise.all([
|
|
77
|
+
this.signalStore.getRegistrationInfo(),
|
|
78
|
+
this.signalStore.getSignedPreKey(),
|
|
79
|
+
this.preKeyStore.getServerHasPreKeys(),
|
|
80
|
+
this.signalStore.getSignedPreKeyRotationTs()
|
|
81
|
+
]);
|
|
82
|
+
const prefetchedLocalKeyBundle = registrationInfo && signedPreKey ? { registrationInfo, signedPreKey } : null;
|
|
83
|
+
await this.uploadPreKeysIfMissing(serverHasPreKeys, prefetchedLocalKeyBundle);
|
|
84
|
+
await this.validateDigestAndRecoverPreKeys(prefetchedLocalKeyBundle);
|
|
85
|
+
await this.rotateSignedPreKeyIfDue(signedPreKeyRotationTs);
|
|
53
86
|
await this.flushDanglingReceipts();
|
|
54
87
|
}
|
|
55
|
-
async validateDigestAndRecoverPreKeys() {
|
|
88
|
+
async validateDigestAndRecoverPreKeys(prefetchedLocalKeyBundle) {
|
|
56
89
|
try {
|
|
57
|
-
const validation =
|
|
90
|
+
const validation = prefetchedLocalKeyBundle
|
|
91
|
+
? await this.signalDigestSync.validateLocalKeyBundle(prefetchedLocalKeyBundle)
|
|
92
|
+
: await this.signalDigestSync.validateLocalKeyBundle();
|
|
58
93
|
if (validation.valid) {
|
|
59
94
|
this.logger.debug('signal digest validated', {
|
|
60
95
|
preKeyCount: validation.preKeyCount
|
|
@@ -70,10 +105,10 @@ class WaPassiveTasksCoordinator {
|
|
|
70
105
|
return;
|
|
71
106
|
}
|
|
72
107
|
await Promise.all([
|
|
73
|
-
this.
|
|
108
|
+
this.preKeyStore.setServerHasPreKeys(false),
|
|
74
109
|
this.runtime.persistServerHasPreKeys(false)
|
|
75
110
|
]);
|
|
76
|
-
await this.uploadPreKeysIfMissing();
|
|
111
|
+
await this.uploadPreKeysIfMissing(false, prefetchedLocalKeyBundle);
|
|
77
112
|
}
|
|
78
113
|
catch (error) {
|
|
79
114
|
this.logger.warn('signal digest validation failed with exception', {
|
|
@@ -81,21 +116,19 @@ class WaPassiveTasksCoordinator {
|
|
|
81
116
|
});
|
|
82
117
|
}
|
|
83
118
|
}
|
|
84
|
-
async uploadPreKeysIfMissing() {
|
|
85
|
-
const serverHasPreKeys = await this.
|
|
119
|
+
async uploadPreKeysIfMissing(serverHasPreKeysHint, prefetchedLocalKeyBundle) {
|
|
120
|
+
const serverHasPreKeys = serverHasPreKeysHint ?? (await this.preKeyStore.getServerHasPreKeys());
|
|
86
121
|
if (serverHasPreKeys) {
|
|
87
122
|
this.logger.trace('prekey upload skipped: server already has prekeys');
|
|
88
123
|
return;
|
|
89
124
|
}
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
this.signalStore.getSignedPreKey()
|
|
93
|
-
]);
|
|
94
|
-
if (!registrationInfo || !signedPreKey) {
|
|
125
|
+
const resolvedLocalKeyBundle = prefetchedLocalKeyBundle ?? (await this.resolveLocalKeyBundleFromStore());
|
|
126
|
+
if (!resolvedLocalKeyBundle) {
|
|
95
127
|
this.logger.warn('prekey upload skipped: registration info is missing');
|
|
96
128
|
return;
|
|
97
129
|
}
|
|
98
|
-
const
|
|
130
|
+
const { registrationInfo, signedPreKey } = resolvedLocalKeyBundle;
|
|
131
|
+
const preKeys = await this.preKeyStore.getOrGenPreKeys(constants_2.SIGNAL_UPLOAD_PREKEYS_COUNT, keygen_1.generatePreKeyPair);
|
|
99
132
|
if (preKeys.length === 0) {
|
|
100
133
|
throw new Error('no prekey available for upload');
|
|
101
134
|
}
|
|
@@ -104,11 +137,12 @@ class WaPassiveTasksCoordinator {
|
|
|
104
137
|
const response = await this.runtime.queryWithContext('prekeys.upload', uploadNode, constants_1.WA_DEFAULTS.IQ_TIMEOUT_MS, {
|
|
105
138
|
count: preKeys.length,
|
|
106
139
|
lastPreKeyId
|
|
107
|
-
});
|
|
140
|
+
}, this.mobilePrimary ? { useSystemId: true } : undefined);
|
|
108
141
|
if (response.attrs.type === 'result') {
|
|
109
|
-
|
|
142
|
+
// Mark uploaded key first so the serverHasPreKeys flag never commits ahead of local key progress.
|
|
143
|
+
await this.preKeyStore.markKeyAsUploaded(lastPreKeyId);
|
|
110
144
|
await Promise.all([
|
|
111
|
-
this.
|
|
145
|
+
this.preKeyStore.setServerHasPreKeys(true),
|
|
112
146
|
this.runtime.persistServerHasPreKeys(true)
|
|
113
147
|
]);
|
|
114
148
|
this.logger.info('uploaded prekeys to server', {
|
|
@@ -124,10 +158,12 @@ class WaPassiveTasksCoordinator {
|
|
|
124
158
|
errorText: failure.errorText
|
|
125
159
|
});
|
|
126
160
|
}
|
|
127
|
-
async rotateSignedPreKeyIfDue() {
|
|
161
|
+
async rotateSignedPreKeyIfDue(signedPreKeyRotationTsHint) {
|
|
128
162
|
try {
|
|
129
163
|
const nowMs = Date.now();
|
|
130
|
-
const lastRotationTs =
|
|
164
|
+
const lastRotationTs = signedPreKeyRotationTsHint === undefined
|
|
165
|
+
? await this.signalStore.getSignedPreKeyRotationTs()
|
|
166
|
+
: signedPreKeyRotationTsHint;
|
|
131
167
|
if (lastRotationTs === null) {
|
|
132
168
|
await this.signalStore.setSignedPreKeyRotationTs(nowMs);
|
|
133
169
|
this.logger.trace('signal rotate key skipped on first run');
|
|
@@ -153,6 +189,16 @@ class WaPassiveTasksCoordinator {
|
|
|
153
189
|
});
|
|
154
190
|
}
|
|
155
191
|
}
|
|
192
|
+
async resolveLocalKeyBundleFromStore() {
|
|
193
|
+
const [registrationInfo, signedPreKey] = await Promise.all([
|
|
194
|
+
this.signalStore.getRegistrationInfo(),
|
|
195
|
+
this.signalStore.getSignedPreKey()
|
|
196
|
+
]);
|
|
197
|
+
if (!registrationInfo || !signedPreKey) {
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
return { registrationInfo, signedPreKey };
|
|
201
|
+
}
|
|
156
202
|
resolveRotationTimestamp(nowMs, errorCode) {
|
|
157
203
|
if (errorCode !== undefined && errorCode >= 500) {
|
|
158
204
|
const retryInMs = Math.min(this.signedPreKeyServerErrorBackoffMs, this.signedPreKeyRotationIntervalMs);
|
|
@@ -170,29 +216,44 @@ class WaPassiveTasksCoordinator {
|
|
|
170
216
|
return;
|
|
171
217
|
}
|
|
172
218
|
this.logger.info('flushing dangling receipts', { count: pending.length });
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
219
|
+
let cursor = 0;
|
|
220
|
+
while (cursor < pending.length) {
|
|
221
|
+
const batchEnd = Math.min(cursor + 4, pending.length);
|
|
222
|
+
const promises = [];
|
|
223
|
+
for (let i = cursor; i < batchEnd; i += 1) {
|
|
224
|
+
promises.push(this.runtime.sendNodeDirect(pending[i]));
|
|
177
225
|
}
|
|
178
|
-
|
|
179
|
-
|
|
226
|
+
const results = await Promise.allSettled(promises);
|
|
227
|
+
let transientCount = 0;
|
|
228
|
+
for (let i = 0; i < results.length; i += 1) {
|
|
229
|
+
const result = results[i];
|
|
230
|
+
if (result.status === 'fulfilled') {
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
const node = pending[cursor + i];
|
|
234
|
+
const normalized = (0, primitives_1.toError)(result.reason);
|
|
180
235
|
if (this.runtime.shouldQueueDanglingReceipt(node, normalized)) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
236
|
+
this.runtime.requeueDanglingReceipt(node);
|
|
237
|
+
transientCount += 1;
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
this.logger.warn('dropping dangling receipt due non-retryable send error', {
|
|
241
|
+
id: node.attrs.id,
|
|
242
|
+
to: node.attrs.to,
|
|
186
243
|
message: normalized.message
|
|
187
244
|
});
|
|
188
|
-
return;
|
|
189
245
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
246
|
+
}
|
|
247
|
+
if (transientCount > 0) {
|
|
248
|
+
for (let i = batchEnd; i < pending.length; i += 1) {
|
|
249
|
+
this.runtime.requeueDanglingReceipt(pending[i]);
|
|
250
|
+
}
|
|
251
|
+
this.logger.warn('stopped dangling receipt flush due transient send error', {
|
|
252
|
+
remaining: transientCount + (pending.length - batchEnd)
|
|
194
253
|
});
|
|
254
|
+
return;
|
|
195
255
|
}
|
|
256
|
+
cursor = batchEnd;
|
|
196
257
|
}
|
|
197
258
|
this.logger.info('dangling receipts flushed');
|
|
198
259
|
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createPrivacyCoordinator = createPrivacyCoordinator;
|
|
4
|
+
const privacy_1 = require("../../protocol/privacy");
|
|
5
|
+
const privacy_2 = require("../../transport/node/builders/privacy");
|
|
6
|
+
const helpers_1 = require("../../transport/node/helpers");
|
|
7
|
+
const query_1 = require("../../transport/node/query");
|
|
8
|
+
const IGNORED_SERVER_CATEGORIES = new Set([
|
|
9
|
+
'pix',
|
|
10
|
+
'linked_profiles',
|
|
11
|
+
'stickers',
|
|
12
|
+
'dependentaccountmessages',
|
|
13
|
+
'cover_photo',
|
|
14
|
+
'dependent_account_calling',
|
|
15
|
+
'groupcreation'
|
|
16
|
+
]);
|
|
17
|
+
function isValidPrivacyValue(value) {
|
|
18
|
+
return (value !== privacy_1.WA_PRIVACY_VALUES.ERROR &&
|
|
19
|
+
Object.values(privacy_1.WA_PRIVACY_VALUES).includes(value));
|
|
20
|
+
}
|
|
21
|
+
function parsePrivacySettings(result) {
|
|
22
|
+
const privacyNode = (0, helpers_1.findNodeChild)(result, 'privacy');
|
|
23
|
+
if (!privacyNode) {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
const settings = {};
|
|
27
|
+
const categories = (0, helpers_1.getNodeChildrenByTag)(privacyNode, privacy_1.WA_PRIVACY_TAGS.CATEGORY);
|
|
28
|
+
for (let i = 0; i < categories.length; i += 1) {
|
|
29
|
+
const node = categories[i];
|
|
30
|
+
const name = node.attrs.name;
|
|
31
|
+
const value = node.attrs.value;
|
|
32
|
+
if (!name || !value) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (IGNORED_SERVER_CATEGORIES.has(name)) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (!isValidPrivacyValue(value)) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const settingName = privacy_1.WA_PRIVACY_CATEGORY_TO_SETTING[name];
|
|
42
|
+
if (settingName) {
|
|
43
|
+
settings[settingName] = value;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return settings;
|
|
47
|
+
}
|
|
48
|
+
function parseDisallowedList(result) {
|
|
49
|
+
const privacyNode = (0, helpers_1.findNodeChild)(result, 'privacy');
|
|
50
|
+
if (!privacyNode) {
|
|
51
|
+
return { jids: [] };
|
|
52
|
+
}
|
|
53
|
+
const listNode = (0, helpers_1.findNodeChild)(privacyNode, privacy_1.WA_PRIVACY_TAGS.LIST);
|
|
54
|
+
if (!listNode) {
|
|
55
|
+
return { jids: [] };
|
|
56
|
+
}
|
|
57
|
+
const dhash = listNode.attrs.dhash;
|
|
58
|
+
const userNodes = (0, helpers_1.getNodeChildrenByTag)(listNode, privacy_1.WA_PRIVACY_TAGS.USER);
|
|
59
|
+
const jids = new Array(userNodes.length);
|
|
60
|
+
let jidsCount = 0;
|
|
61
|
+
for (let i = 0; i < userNodes.length; i += 1) {
|
|
62
|
+
const jid = userNodes[i].attrs.jid;
|
|
63
|
+
if (jid) {
|
|
64
|
+
jids[jidsCount] = jid;
|
|
65
|
+
jidsCount += 1;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
jids.length = jidsCount;
|
|
69
|
+
return { jids, dhash };
|
|
70
|
+
}
|
|
71
|
+
function parseBlocklist(result) {
|
|
72
|
+
const listNode = (0, helpers_1.findNodeChild)(result, 'list');
|
|
73
|
+
if (!listNode) {
|
|
74
|
+
return { jids: [] };
|
|
75
|
+
}
|
|
76
|
+
const dhash = listNode.attrs.dhash;
|
|
77
|
+
const itemNodes = (0, helpers_1.getNodeChildren)(listNode);
|
|
78
|
+
const jids = new Array(itemNodes.length);
|
|
79
|
+
let jidsCount = 0;
|
|
80
|
+
for (let i = 0; i < itemNodes.length; i += 1) {
|
|
81
|
+
const jid = itemNodes[i].attrs.jid;
|
|
82
|
+
if (jid) {
|
|
83
|
+
jids[jidsCount] = jid;
|
|
84
|
+
jidsCount += 1;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
jids.length = jidsCount;
|
|
88
|
+
return { jids, dhash };
|
|
89
|
+
}
|
|
90
|
+
function createPrivacyCoordinator(options) {
|
|
91
|
+
const { queryWithContext } = options;
|
|
92
|
+
return {
|
|
93
|
+
getPrivacySettings: async () => {
|
|
94
|
+
const node = (0, privacy_2.buildGetPrivacySettingsIq)();
|
|
95
|
+
const result = await queryWithContext('privacy.getSettings', node);
|
|
96
|
+
(0, query_1.assertIqResult)(result, 'privacy.getSettings');
|
|
97
|
+
return parsePrivacySettings(result);
|
|
98
|
+
},
|
|
99
|
+
setPrivacySetting: async (setting, value) => {
|
|
100
|
+
const category = privacy_1.WA_PRIVACY_SETTING_TO_CATEGORY[setting];
|
|
101
|
+
const node = (0, privacy_2.buildSetPrivacyCategoryIq)(category, value);
|
|
102
|
+
const result = await queryWithContext('privacy.setSetting', node, undefined, {
|
|
103
|
+
category,
|
|
104
|
+
value
|
|
105
|
+
});
|
|
106
|
+
(0, query_1.assertIqResult)(result, 'privacy.setSetting');
|
|
107
|
+
},
|
|
108
|
+
getDisallowedList: async (setting) => {
|
|
109
|
+
const category = privacy_1.WA_PRIVACY_SETTING_TO_CATEGORY[setting];
|
|
110
|
+
const node = (0, privacy_2.buildGetPrivacyDisallowedListIq)(category);
|
|
111
|
+
const result = await queryWithContext('privacy.getDisallowedList', node, undefined, {
|
|
112
|
+
category
|
|
113
|
+
});
|
|
114
|
+
(0, query_1.assertIqResult)(result, 'privacy.getDisallowedList');
|
|
115
|
+
return parseDisallowedList(result);
|
|
116
|
+
},
|
|
117
|
+
getBlocklist: async () => {
|
|
118
|
+
const node = (0, privacy_2.buildGetBlocklistIq)();
|
|
119
|
+
const result = await queryWithContext('privacy.getBlocklist', node);
|
|
120
|
+
(0, query_1.assertIqResult)(result, 'privacy.getBlocklist');
|
|
121
|
+
return parseBlocklist(result);
|
|
122
|
+
},
|
|
123
|
+
blockUser: async (jid) => {
|
|
124
|
+
const node = (0, privacy_2.buildBlocklistChangeIq)(jid, 'block');
|
|
125
|
+
const result = await queryWithContext('privacy.blockUser', node, undefined, { jid });
|
|
126
|
+
(0, query_1.assertIqResult)(result, 'privacy.blockUser');
|
|
127
|
+
},
|
|
128
|
+
unblockUser: async (jid) => {
|
|
129
|
+
const node = (0, privacy_2.buildBlocklistChangeIq)(jid, 'unblock');
|
|
130
|
+
const result = await queryWithContext('privacy.unblockUser', node, undefined, { jid });
|
|
131
|
+
(0, query_1.assertIqResult)(result, 'privacy.unblockUser');
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createProfileCoordinator = createProfileCoordinator;
|
|
4
|
+
const profile_1 = require("../../transport/node/builders/profile");
|
|
5
|
+
const usync_1 = require("../../transport/node/builders/usync");
|
|
6
|
+
const helpers_1 = require("../../transport/node/helpers");
|
|
7
|
+
const query_1 = require("../../transport/node/query");
|
|
8
|
+
const bytes_1 = require("../../util/bytes");
|
|
9
|
+
function parseProfilePicture(result) {
|
|
10
|
+
const pictureNode = (0, helpers_1.findNodeChild)(result, 'picture');
|
|
11
|
+
if (!pictureNode) {
|
|
12
|
+
return {};
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
url: pictureNode.attrs.url,
|
|
16
|
+
directPath: pictureNode.attrs.direct_path,
|
|
17
|
+
id: pictureNode.attrs.id,
|
|
18
|
+
type: pictureNode.attrs.type
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function parseSetPictureResult(result) {
|
|
22
|
+
const pictureNode = (0, helpers_1.findNodeChild)(result, 'picture');
|
|
23
|
+
return pictureNode?.attrs.id ?? null;
|
|
24
|
+
}
|
|
25
|
+
function parseUsyncProfiles(result) {
|
|
26
|
+
const usyncNode = (0, helpers_1.findNodeChild)(result, 'usync');
|
|
27
|
+
if (!usyncNode) {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
const listNode = (0, helpers_1.findNodeChild)(usyncNode, 'list');
|
|
31
|
+
if (!listNode) {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
const userNodes = (0, helpers_1.getNodeChildren)(listNode);
|
|
35
|
+
const profiles = new Array(userNodes.length);
|
|
36
|
+
let count = 0;
|
|
37
|
+
for (let i = 0; i < userNodes.length; i += 1) {
|
|
38
|
+
const userNode = userNodes[i];
|
|
39
|
+
if (userNode.tag !== 'user') {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const jid = userNode.attrs.jid;
|
|
43
|
+
if (!jid) {
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const info = { jid };
|
|
47
|
+
const userContent = userNode.content;
|
|
48
|
+
if (!Array.isArray(userContent)) {
|
|
49
|
+
profiles[count] = info;
|
|
50
|
+
count += 1;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
for (let j = 0; j < userContent.length; j += 1) {
|
|
54
|
+
const child = userContent[j];
|
|
55
|
+
if (child.tag === 'picture') {
|
|
56
|
+
const idAttr = child.attrs.id;
|
|
57
|
+
if (idAttr) {
|
|
58
|
+
const parsed = Number.parseInt(idAttr, 10);
|
|
59
|
+
if (Number.isSafeInteger(parsed)) {
|
|
60
|
+
info.pictureId = parsed;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else if (child.tag === 'status') {
|
|
65
|
+
const code = child.attrs.code;
|
|
66
|
+
if (code !== undefined && Number.parseInt(code, 10) === 401) {
|
|
67
|
+
info.status = '';
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
const content = child.content;
|
|
71
|
+
if (content instanceof Uint8Array) {
|
|
72
|
+
const decoded = bytes_1.TEXT_DECODER.decode(content);
|
|
73
|
+
info.status = decoded.length > 0 ? decoded : null;
|
|
74
|
+
}
|
|
75
|
+
else if (typeof content === 'string') {
|
|
76
|
+
info.status = content.length > 0 ? content : null;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
info.status = null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
profiles[count] = info;
|
|
85
|
+
count += 1;
|
|
86
|
+
}
|
|
87
|
+
profiles.length = count;
|
|
88
|
+
return profiles;
|
|
89
|
+
}
|
|
90
|
+
function parseUsyncDisappearingModes(result) {
|
|
91
|
+
const usyncNode = (0, helpers_1.findNodeChild)(result, 'usync');
|
|
92
|
+
if (!usyncNode)
|
|
93
|
+
return [];
|
|
94
|
+
const listNode = (0, helpers_1.findNodeChild)(usyncNode, 'list');
|
|
95
|
+
if (!listNode)
|
|
96
|
+
return [];
|
|
97
|
+
const userNodes = (0, helpers_1.getNodeChildren)(listNode);
|
|
98
|
+
const results = new Array(userNodes.length);
|
|
99
|
+
let count = 0;
|
|
100
|
+
for (let i = 0; i < userNodes.length; i += 1) {
|
|
101
|
+
const userNode = userNodes[i];
|
|
102
|
+
if (userNode.tag !== 'user')
|
|
103
|
+
continue;
|
|
104
|
+
const userContent = userNode.content;
|
|
105
|
+
if (!Array.isArray(userContent))
|
|
106
|
+
continue;
|
|
107
|
+
for (let j = 0; j < userContent.length; j += 1) {
|
|
108
|
+
const child = userContent[j];
|
|
109
|
+
if (child.tag !== 'disappearing_mode')
|
|
110
|
+
continue;
|
|
111
|
+
const errorNode = (0, helpers_1.findNodeChild)(child, 'error');
|
|
112
|
+
if (errorNode)
|
|
113
|
+
continue;
|
|
114
|
+
const duration = Number.parseInt(child.attrs.duration ?? '0', 10);
|
|
115
|
+
const timestamp = Number.parseInt(child.attrs.t ?? '0', 10);
|
|
116
|
+
const entry = { duration, timestamp };
|
|
117
|
+
if (child.attrs.ephemerality_disabled === 'true') {
|
|
118
|
+
entry.ephemeralityDisabled = true;
|
|
119
|
+
}
|
|
120
|
+
results[count] = entry;
|
|
121
|
+
count += 1;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
results.length = count;
|
|
125
|
+
return results;
|
|
126
|
+
}
|
|
127
|
+
function parseUsyncStatus(result) {
|
|
128
|
+
const profiles = parseUsyncProfiles(result);
|
|
129
|
+
if (profiles.length === 0) {
|
|
130
|
+
return { status: null };
|
|
131
|
+
}
|
|
132
|
+
return { status: profiles[0].status ?? null };
|
|
133
|
+
}
|
|
134
|
+
function createProfileCoordinator(options) {
|
|
135
|
+
const { queryWithContext, generateSid } = options;
|
|
136
|
+
return {
|
|
137
|
+
getProfilePicture: async (jid, type, existingId) => {
|
|
138
|
+
const node = (0, profile_1.buildGetProfilePictureIq)(jid, type, existingId);
|
|
139
|
+
const result = await queryWithContext('profile.getPicture', node, undefined, {
|
|
140
|
+
jid,
|
|
141
|
+
type: type ?? 'preview'
|
|
142
|
+
});
|
|
143
|
+
(0, query_1.assertIqResult)(result, 'profile.getPicture');
|
|
144
|
+
return parseProfilePicture(result);
|
|
145
|
+
},
|
|
146
|
+
setProfilePicture: async (imageBytes, targetJid) => {
|
|
147
|
+
const node = (0, profile_1.buildSetProfilePictureIq)(imageBytes, targetJid);
|
|
148
|
+
const result = await queryWithContext('profile.setPicture', node, undefined, {
|
|
149
|
+
targetJid,
|
|
150
|
+
size: imageBytes.length
|
|
151
|
+
});
|
|
152
|
+
(0, query_1.assertIqResult)(result, 'profile.setPicture');
|
|
153
|
+
return parseSetPictureResult(result);
|
|
154
|
+
},
|
|
155
|
+
deleteProfilePicture: async (targetJid) => {
|
|
156
|
+
const node = (0, profile_1.buildDeleteProfilePictureIq)(targetJid);
|
|
157
|
+
const result = await queryWithContext('profile.deletePicture', node, undefined, {
|
|
158
|
+
targetJid
|
|
159
|
+
});
|
|
160
|
+
(0, query_1.assertIqResult)(result, 'profile.deletePicture');
|
|
161
|
+
},
|
|
162
|
+
getStatus: async (jid) => {
|
|
163
|
+
const sid = await generateSid();
|
|
164
|
+
const queryNodes = (0, profile_1.buildGetStatusUsyncQueryNodes)();
|
|
165
|
+
const usyncNode = (0, usync_1.buildUsyncIq)({
|
|
166
|
+
sid,
|
|
167
|
+
queryProtocolNodes: [queryNodes[1]],
|
|
168
|
+
users: [{ jid }]
|
|
169
|
+
});
|
|
170
|
+
const result = await queryWithContext('profile.getStatus', usyncNode, undefined, {
|
|
171
|
+
jid
|
|
172
|
+
});
|
|
173
|
+
(0, query_1.assertIqResult)(result, 'profile.getStatus');
|
|
174
|
+
return parseUsyncStatus(result);
|
|
175
|
+
},
|
|
176
|
+
setStatus: async (text) => {
|
|
177
|
+
const node = (0, profile_1.buildSetStatusIq)(text);
|
|
178
|
+
const result = await queryWithContext('profile.setStatus', node, undefined, undefined, {
|
|
179
|
+
useSystemId: true
|
|
180
|
+
});
|
|
181
|
+
(0, query_1.assertIqResult)(result, 'profile.setStatus');
|
|
182
|
+
},
|
|
183
|
+
getProfiles: async (jids) => {
|
|
184
|
+
if (jids.length === 0) {
|
|
185
|
+
return [];
|
|
186
|
+
}
|
|
187
|
+
const sid = await generateSid();
|
|
188
|
+
const queryProtocolNodes = (0, profile_1.buildGetStatusUsyncQueryNodes)();
|
|
189
|
+
const usyncNode = (0, usync_1.buildUsyncIq)({
|
|
190
|
+
sid,
|
|
191
|
+
queryProtocolNodes,
|
|
192
|
+
users: jids.map((jid) => ({ jid }))
|
|
193
|
+
});
|
|
194
|
+
const result = await queryWithContext('profile.getProfiles', usyncNode, undefined, {
|
|
195
|
+
count: jids.length
|
|
196
|
+
});
|
|
197
|
+
(0, query_1.assertIqResult)(result, 'profile.getProfiles');
|
|
198
|
+
return parseUsyncProfiles(result);
|
|
199
|
+
},
|
|
200
|
+
getDisappearingMode: async (jids) => {
|
|
201
|
+
if (jids.length === 0)
|
|
202
|
+
return [];
|
|
203
|
+
const sid = await generateSid();
|
|
204
|
+
const usyncNode = (0, usync_1.buildUsyncIq)({
|
|
205
|
+
sid,
|
|
206
|
+
queryProtocolNodes: [(0, profile_1.buildGetDisappearingModeUsyncQueryNode)()],
|
|
207
|
+
users: jids.map((jid) => ({ jid }))
|
|
208
|
+
});
|
|
209
|
+
const result = await queryWithContext('profile.getDisappearingMode', usyncNode, undefined, { count: jids.length });
|
|
210
|
+
(0, query_1.assertIqResult)(result, 'profile.getDisappearingMode');
|
|
211
|
+
return parseUsyncDisappearingModes(result);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
}
|