zapo-js 0.1.2 → 0.2.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 +12 -4
- package/dist/appstate/WaAppStateCrypto.js +1 -1
- package/dist/appstate/WaAppStateSyncClient.js +138 -93
- package/dist/appstate/{store/sqlite.js → encoding.js} +13 -8
- package/dist/appstate/index.js +8 -6
- package/dist/appstate/utils.js +0 -5
- package/dist/auth/WaAuthClient.js +36 -47
- package/dist/auth/flow/WaAuthCredentialsFlow.js +7 -7
- package/dist/auth/index.js +1 -6
- package/dist/auth/pairing/WaPairingCodeCrypto.js +6 -4
- package/dist/auth/pairing/WaPairingFlow.js +13 -3
- package/dist/client/WaClient.js +225 -101
- package/dist/client/WaClientFactory.js +294 -44
- package/dist/client/connection/WaConnectionManager.js +19 -10
- package/dist/client/coordinators/WaBusinessCoordinator.js +241 -0
- package/dist/client/coordinators/WaGroupCoordinator.js +11 -7
- package/dist/client/coordinators/WaIncomingNodeCoordinator.js +1 -0
- package/dist/client/coordinators/WaMessageDispatchCoordinator.js +292 -99
- package/dist/client/coordinators/WaPassiveTasksCoordinator.js +74 -31
- package/dist/client/coordinators/WaPrivacyCoordinator.js +134 -0
- package/dist/client/coordinators/WaProfileCoordinator.js +212 -0
- package/dist/client/coordinators/WaRetryCoordinator.js +179 -27
- package/dist/client/coordinators/WaStreamControlCoordinator.js +18 -11
- package/dist/client/coordinators/WaTrustedContactTokenCoordinator.js +166 -0
- package/dist/client/dirty.js +40 -20
- 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 +39 -0
- package/dist/client/history-sync.js +50 -9
- package/dist/client/incoming.js +37 -7
- package/dist/client/mailbox.js +24 -23
- package/dist/client/messages.js +107 -31
- 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 +2 -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 +22 -0
- package/dist/crypto/curves/X25519.js +25 -6
- 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 +1 -1
- package/dist/esm/appstate/WaAppStateSyncClient.js +138 -93
- package/dist/esm/appstate/{store/sqlite.js → encoding.js} +13 -8
- package/dist/esm/appstate/index.js +2 -2
- package/dist/esm/appstate/utils.js +2 -5
- package/dist/esm/auth/WaAuthClient.js +36 -47
- package/dist/esm/auth/flow/WaAuthCredentialsFlow.js +7 -7
- package/dist/esm/auth/index.js +0 -2
- package/dist/esm/auth/pairing/WaPairingCodeCrypto.js +6 -4
- package/dist/esm/auth/pairing/WaPairingFlow.js +14 -4
- package/dist/esm/client/WaClient.js +225 -101
- package/dist/esm/client/WaClientFactory.js +295 -45
- package/dist/esm/client/connection/WaConnectionManager.js +19 -10
- package/dist/esm/client/coordinators/WaBusinessCoordinator.js +238 -0
- package/dist/esm/client/coordinators/WaGroupCoordinator.js +11 -7
- package/dist/esm/client/coordinators/WaIncomingNodeCoordinator.js +1 -0
- package/dist/esm/client/coordinators/WaMessageDispatchCoordinator.js +295 -102
- package/dist/esm/client/coordinators/WaPassiveTasksCoordinator.js +74 -31
- package/dist/esm/client/coordinators/WaPrivacyCoordinator.js +131 -0
- package/dist/esm/client/coordinators/WaProfileCoordinator.js +209 -0
- package/dist/esm/client/coordinators/WaRetryCoordinator.js +181 -29
- package/dist/esm/client/coordinators/WaStreamControlCoordinator.js +19 -12
- package/dist/esm/client/coordinators/WaTrustedContactTokenCoordinator.js +162 -0
- package/dist/esm/client/dirty.js +40 -20
- 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 +36 -0
- package/dist/esm/client/history-sync.js +50 -9
- package/dist/esm/client/incoming.js +38 -8
- package/dist/esm/client/mailbox.js +24 -23
- package/dist/esm/client/messages.js +108 -32
- 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 +2 -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 +22 -1
- package/dist/esm/crypto/curves/X25519.js +25 -6
- 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 +77 -0
- package/dist/esm/media/WaMediaCrypto.js +95 -13
- package/dist/esm/media/WaMediaTransferClient.js +39 -47
- package/dist/esm/media/constants.js +2 -1
- package/dist/esm/message/WaMessageClient.js +26 -19
- package/dist/esm/message/content.js +195 -9
- package/dist/esm/message/icdc.js +76 -0
- package/dist/esm/message/incoming.js +24 -12
- package/dist/esm/message/phash.js +3 -1
- package/dist/esm/message/reporting-token.js +14 -27
- package/dist/esm/protocol/appstate.js +9 -40
- package/dist/esm/protocol/browser.js +10 -18
- package/dist/esm/protocol/constants.js +5 -3
- package/dist/esm/protocol/defaults.js +6 -0
- package/dist/esm/protocol/index.js +1 -2
- package/dist/esm/protocol/jid.js +105 -36
- package/dist/esm/protocol/message.js +61 -1
- package/dist/esm/protocol/nodes.js +2 -0
- package/dist/esm/protocol/notification.js +3 -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/replay.js +11 -7
- package/dist/esm/retry/tracker.js +50 -12
- package/dist/esm/signal/api/SignalDeviceSyncApi.js +49 -32
- package/dist/esm/signal/api/SignalDigestSyncApi.js +13 -9
- package/dist/esm/signal/api/SignalIdentitySyncApi.js +26 -11
- package/dist/esm/signal/api/SignalMissingPreKeysSyncApi.js +18 -7
- package/dist/esm/signal/api/SignalRotateKeyApi.js +4 -2
- package/dist/esm/signal/api/SignalSessionSyncApi.js +16 -7
- 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 +12 -6
- package/dist/esm/signal/{store/sqlite.js → encoding.js} +78 -24
- package/dist/esm/signal/group/SenderKeyCodec.js +3 -2
- package/dist/esm/signal/group/SenderKeyManager.js +125 -106
- package/dist/esm/signal/index.js +1 -0
- package/dist/esm/signal/registration/keygen.js +6 -2
- package/dist/esm/signal/registration/utils.js +1 -0
- package/dist/esm/signal/session/SignalProtocol.js +150 -74
- package/dist/esm/signal/session/resolver.js +137 -102
- package/dist/esm/store/contracts/privacy-token.store.js +1 -0
- package/dist/esm/store/createStore.js +101 -187
- package/dist/esm/store/index.js +1 -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/message.lock.js +21 -0
- package/dist/esm/store/locks/participants.lock.js +20 -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/signal.lock.js +63 -0
- package/dist/esm/store/locks/thread.lock.js +21 -0
- package/dist/esm/store/noop.store.js +1 -1
- package/dist/esm/store/providers/memory/appstate.store.js +22 -24
- package/dist/esm/store/providers/memory/device-list.store.js +10 -5
- package/dist/esm/store/providers/memory/privacy-token.store.js +43 -0
- package/dist/esm/store/providers/memory/retry.store.js +77 -2
- package/dist/esm/store/providers/memory/sender-key.store.js +6 -1
- package/dist/esm/store/providers/memory/signal.store.js +36 -19
- package/dist/esm/transport/WaComms.js +3 -1
- package/dist/esm/transport/WaWebSocket.js +0 -6
- 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/node/WaNodeOrchestrator.js +25 -19
- package/dist/esm/transport/node/builders/business.js +129 -0
- package/dist/esm/transport/node/builders/global.js +370 -0
- package/dist/esm/transport/node/builders/index.js +5 -2
- package/dist/esm/transport/node/builders/message.js +63 -239
- package/dist/esm/transport/node/builders/pairing.js +0 -24
- package/dist/esm/transport/node/builders/privacy-token.js +41 -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 +10 -22
- package/dist/esm/transport/node/builders/usync.js +6 -2
- package/dist/esm/transport/node/helpers.js +19 -1
- 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 +10 -10
- package/dist/esm/transport/noise/WaNoiseCert.js +3 -3
- package/dist/esm/transport/noise/WaNoiseSession.js +64 -23
- 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 +81 -0
- package/dist/media/WaMediaCrypto.js +94 -12
- package/dist/media/WaMediaTransferClient.js +39 -47
- package/dist/media/constants.js +2 -1
- package/dist/message/WaMessageClient.js +26 -19
- package/dist/message/content.js +198 -9
- package/dist/message/icdc.js +81 -0
- package/dist/message/incoming.js +24 -12
- package/dist/message/phash.js +3 -1
- package/dist/message/reporting-token.js +14 -28
- package/dist/protocol/appstate.js +10 -41
- package/dist/protocol/browser.js +10 -18
- package/dist/protocol/constants.js +21 -2
- package/dist/protocol/defaults.js +6 -0
- package/dist/protocol/index.js +8 -5
- package/dist/protocol/jid.js +111 -36
- package/dist/protocol/message.js +62 -2
- package/dist/protocol/nodes.js +2 -0
- package/dist/protocol/notification.js +3 -1
- 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/replay.js +10 -6
- package/dist/retry/tracker.js +50 -12
- package/dist/signal/api/SignalDeviceSyncApi.js +48 -31
- package/dist/signal/api/SignalDigestSyncApi.js +13 -9
- package/dist/signal/api/SignalIdentitySyncApi.js +25 -10
- 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 +11 -5
- package/dist/signal/{store/sqlite.js → encoding.js} +79 -25
- package/dist/signal/group/SenderKeyCodec.js +4 -3
- package/dist/signal/group/SenderKeyManager.js +125 -106
- package/dist/signal/index.js +13 -1
- package/dist/signal/registration/keygen.js +6 -2
- package/dist/signal/registration/utils.js +1 -0
- package/dist/signal/session/SignalProtocol.js +150 -74
- package/dist/signal/session/resolver.js +135 -100
- package/dist/store/contracts/privacy-token.store.js +2 -0
- package/dist/store/createStore.js +101 -187
- package/dist/store/index.js +15 -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/message.lock.js +24 -0
- package/dist/store/locks/participants.lock.js +23 -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/signal.lock.js +66 -0
- package/dist/store/locks/thread.lock.js +24 -0
- package/dist/store/noop.store.js +1 -1
- package/dist/store/providers/memory/appstate.store.js +22 -24
- package/dist/store/providers/memory/device-list.store.js +10 -5
- package/dist/store/providers/memory/privacy-token.store.js +47 -0
- package/dist/store/providers/memory/retry.store.js +77 -2
- package/dist/store/providers/memory/sender-key.store.js +6 -1
- package/dist/store/providers/memory/signal.store.js +36 -19
- package/dist/transport/WaComms.js +3 -1
- package/dist/transport/WaWebSocket.js +0 -6
- 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/node/WaNodeOrchestrator.js +24 -18
- package/dist/transport/node/builders/business.js +137 -0
- package/dist/transport/node/builders/global.js +375 -0
- package/dist/transport/node/builders/index.js +18 -9
- package/dist/transport/node/builders/message.js +64 -245
- package/dist/transport/node/builders/pairing.js +0 -26
- package/dist/transport/node/builders/privacy-token.js +46 -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 +9 -21
- package/dist/transport/node/builders/usync.js +6 -2
- package/dist/transport/node/helpers.js +20 -1
- package/dist/transport/node/usync.js +2 -32
- package/dist/transport/node/xml.js +35 -14
- package/dist/transport/noise/WaClientPayload.js +13 -13
- package/dist/transport/noise/WaNoiseCert.js +2 -2
- package/dist/transport/noise/WaNoiseSession.js +64 -23
- package/dist/transport/noise/WaNoiseSocket.js +8 -4
- package/dist/transport/stream/parse.js +7 -3
- package/dist/types/appstate/encoding.d.ts +7 -0
- package/dist/types/appstate/index.d.ts +3 -3
- package/dist/types/appstate/utils.d.ts +0 -2
- package/dist/types/auth/flow/WaAuthCredentialsFlow.d.ts +1 -1
- package/dist/types/auth/index.d.ts +0 -2
- package/dist/types/auth/types.d.ts +1 -0
- package/dist/types/client/WaClient.d.ts +27 -12
- package/dist/types/client/WaClientFactory.d.ts +12 -4
- package/dist/types/client/connection/WaConnectionManager.d.ts +2 -0
- package/dist/types/client/coordinators/WaBusinessCoordinator.d.ts +57 -0
- package/dist/types/client/coordinators/WaIncomingNodeCoordinator.d.ts +3 -1
- package/dist/types/client/coordinators/WaMessageDispatchCoordinator.d.ts +14 -0
- package/dist/types/client/coordinators/WaPassiveTasksCoordinator.d.ts +4 -0
- package/dist/types/client/coordinators/WaPrivacyCoordinator.d.ts +26 -0
- package/dist/types/client/coordinators/WaProfileCoordinator.d.ts +36 -0
- package/dist/types/client/coordinators/WaRetryCoordinator.d.ts +6 -0
- package/dist/types/client/coordinators/WaStreamControlCoordinator.d.ts +3 -2
- package/dist/types/client/coordinators/WaTrustedContactTokenCoordinator.d.ts +45 -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/history-sync.d.ts +9 -6
- package/dist/types/client/incoming.d.ts +3 -1
- package/dist/types/client/index.d.ts +1 -1
- package/dist/types/client/mailbox.d.ts +3 -5
- package/dist/types/client/messages.d.ts +1 -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 +51 -3
- package/dist/types/crypto/core/index.d.ts +2 -2
- package/dist/types/crypto/core/nonce.d.ts +2 -0
- package/dist/types/crypto/core/primitives.d.ts +0 -1
- package/dist/types/crypto/core/random.d.ts +1 -0
- package/dist/types/crypto/index.d.ts +1 -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 +5 -3
- 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 +10 -0
- package/dist/types/media/WaMediaCrypto.d.ts +3 -2
- package/dist/types/media/WaMediaTransferClient.d.ts +3 -12
- package/dist/types/media/constants.d.ts +1 -1
- package/dist/types/media/index.d.ts +1 -1
- package/dist/types/media/types.d.ts +10 -2
- package/dist/types/message/content.d.ts +8 -0
- 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 +45 -6
- package/dist/types/protocol/appstate.d.ts +0 -11
- package/dist/types/protocol/constants.d.ts +7 -3
- package/dist/types/protocol/defaults.d.ts +6 -0
- package/dist/types/protocol/index.d.ts +1 -2
- package/dist/types/protocol/jid.d.ts +19 -2
- package/dist/types/protocol/message.d.ts +60 -0
- package/dist/types/protocol/nodes.d.ts +2 -0
- package/dist/types/protocol/notification.d.ts +2 -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 +30 -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/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 +6 -0
- package/dist/types/signal/api/SignalIdentitySyncApi.d.ts +2 -0
- 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/{store/sqlite.d.ts → encoding.d.ts} +3 -3
- package/dist/types/signal/group/SenderKeyManager.d.ts +10 -5
- package/dist/types/signal/index.d.ts +2 -0
- package/dist/types/signal/session/SignalProtocol.d.ts +10 -4
- package/dist/types/signal/session/resolver.d.ts +7 -2
- package/dist/types/store/contracts/appstate.store.d.ts +1 -1
- 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/signal.store.d.ts +7 -0
- package/dist/types/store/createStore.d.ts +1 -1
- package/dist/types/store/index.d.ts +5 -13
- 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/message.lock.d.ts +3 -0
- package/dist/types/store/locks/participants.lock.d.ts +2 -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/signal.lock.d.ts +3 -0
- package/dist/types/store/locks/thread.lock.d.ts +3 -0
- package/dist/types/store/providers/memory/appstate.store.d.ts +1 -1
- package/dist/types/store/providers/memory/privacy-token.store.d.ts +13 -0
- package/dist/types/store/providers/memory/retry.store.d.ts +8 -0
- package/dist/types/store/providers/memory/signal.store.d.ts +2 -1
- package/dist/types/store/types.d.ts +49 -61
- package/dist/types/transport/WaWebSocket.d.ts +0 -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/node/WaNodeOrchestrator.d.ts +3 -4
- package/dist/types/transport/node/builders/business.d.ts +29 -0
- package/dist/types/transport/node/builders/global.d.ts +102 -0
- package/dist/types/transport/node/builders/index.d.ts +5 -2
- package/dist/types/transport/node/builders/message.d.ts +8 -7
- package/dist/types/transport/node/builders/pairing.d.ts +0 -2
- 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 +5 -0
- package/dist/types/transport/noise/WaNoiseSession.d.ts +3 -2
- package/dist/types/transport/noise/WaNoiseSocket.d.ts +4 -2
- 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 +29 -7
- package/proto/index.js +1 -1
- package/dist/crypto/core/constants.js +0 -4
- 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/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/types/appstate/store/sqlite.d.ts +0 -7
- 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
|
@@ -34,6 +34,16 @@ class WaPassiveTasksCoordinator {
|
|
|
34
34
|
this.passiveTasksPromise = null;
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
|
+
async handlePreKeyLowNotification() {
|
|
38
|
+
await Promise.all([
|
|
39
|
+
this.signalStore.setServerHasPreKeys(false),
|
|
40
|
+
this.runtime.persistServerHasPreKeys(false)
|
|
41
|
+
]);
|
|
42
|
+
await this.uploadPreKeysIfMissing(false);
|
|
43
|
+
}
|
|
44
|
+
async handleDigestNotification() {
|
|
45
|
+
await this.validateDigestAndRecoverPreKeys();
|
|
46
|
+
}
|
|
37
47
|
resetInFlightState() {
|
|
38
48
|
if (!this.passiveTasksPromise) {
|
|
39
49
|
return;
|
|
@@ -47,14 +57,18 @@ class WaPassiveTasksCoordinator {
|
|
|
47
57
|
this.logger.trace('passive connect tasks skipped: session is not registered');
|
|
48
58
|
return;
|
|
49
59
|
}
|
|
50
|
-
await this.
|
|
51
|
-
|
|
52
|
-
await this.
|
|
60
|
+
const signalMeta = await this.signalStore.getSignalMeta();
|
|
61
|
+
const prefetchedLocalKeyBundle = this.resolveLocalKeyBundle(signalMeta);
|
|
62
|
+
await this.uploadPreKeysIfMissing(signalMeta.serverHasPreKeys, prefetchedLocalKeyBundle);
|
|
63
|
+
await this.validateDigestAndRecoverPreKeys(prefetchedLocalKeyBundle);
|
|
64
|
+
await this.rotateSignedPreKeyIfDue(signalMeta.signedPreKeyRotationTs);
|
|
53
65
|
await this.flushDanglingReceipts();
|
|
54
66
|
}
|
|
55
|
-
async validateDigestAndRecoverPreKeys() {
|
|
67
|
+
async validateDigestAndRecoverPreKeys(prefetchedLocalKeyBundle) {
|
|
56
68
|
try {
|
|
57
|
-
const validation =
|
|
69
|
+
const validation = prefetchedLocalKeyBundle
|
|
70
|
+
? await this.signalDigestSync.validateLocalKeyBundle(prefetchedLocalKeyBundle)
|
|
71
|
+
: await this.signalDigestSync.validateLocalKeyBundle();
|
|
58
72
|
if (validation.valid) {
|
|
59
73
|
this.logger.debug('signal digest validated', {
|
|
60
74
|
preKeyCount: validation.preKeyCount
|
|
@@ -73,7 +87,7 @@ class WaPassiveTasksCoordinator {
|
|
|
73
87
|
this.signalStore.setServerHasPreKeys(false),
|
|
74
88
|
this.runtime.persistServerHasPreKeys(false)
|
|
75
89
|
]);
|
|
76
|
-
await this.uploadPreKeysIfMissing();
|
|
90
|
+
await this.uploadPreKeysIfMissing(false, prefetchedLocalKeyBundle);
|
|
77
91
|
}
|
|
78
92
|
catch (error) {
|
|
79
93
|
this.logger.warn('signal digest validation failed with exception', {
|
|
@@ -81,20 +95,18 @@ class WaPassiveTasksCoordinator {
|
|
|
81
95
|
});
|
|
82
96
|
}
|
|
83
97
|
}
|
|
84
|
-
async uploadPreKeysIfMissing() {
|
|
85
|
-
const serverHasPreKeys = await this.signalStore.getServerHasPreKeys();
|
|
98
|
+
async uploadPreKeysIfMissing(serverHasPreKeysHint, prefetchedLocalKeyBundle) {
|
|
99
|
+
const serverHasPreKeys = serverHasPreKeysHint ?? (await this.signalStore.getServerHasPreKeys());
|
|
86
100
|
if (serverHasPreKeys) {
|
|
87
101
|
this.logger.trace('prekey upload skipped: server already has prekeys');
|
|
88
102
|
return;
|
|
89
103
|
}
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
this.signalStore.getSignedPreKey()
|
|
93
|
-
]);
|
|
94
|
-
if (!registrationInfo || !signedPreKey) {
|
|
104
|
+
const resolvedLocalKeyBundle = prefetchedLocalKeyBundle ?? (await this.resolveLocalKeyBundleFromStore());
|
|
105
|
+
if (!resolvedLocalKeyBundle) {
|
|
95
106
|
this.logger.warn('prekey upload skipped: registration info is missing');
|
|
96
107
|
return;
|
|
97
108
|
}
|
|
109
|
+
const { registrationInfo, signedPreKey } = resolvedLocalKeyBundle;
|
|
98
110
|
const preKeys = await this.signalStore.getOrGenPreKeys(constants_2.SIGNAL_UPLOAD_PREKEYS_COUNT, keygen_1.generatePreKeyPair);
|
|
99
111
|
if (preKeys.length === 0) {
|
|
100
112
|
throw new Error('no prekey available for upload');
|
|
@@ -106,6 +118,7 @@ class WaPassiveTasksCoordinator {
|
|
|
106
118
|
lastPreKeyId
|
|
107
119
|
});
|
|
108
120
|
if (response.attrs.type === 'result') {
|
|
121
|
+
// Mark uploaded key first so the serverHasPreKeys flag never commits ahead of local key progress.
|
|
109
122
|
await this.signalStore.markKeyAsUploaded(lastPreKeyId);
|
|
110
123
|
await Promise.all([
|
|
111
124
|
this.signalStore.setServerHasPreKeys(true),
|
|
@@ -124,10 +137,12 @@ class WaPassiveTasksCoordinator {
|
|
|
124
137
|
errorText: failure.errorText
|
|
125
138
|
});
|
|
126
139
|
}
|
|
127
|
-
async rotateSignedPreKeyIfDue() {
|
|
140
|
+
async rotateSignedPreKeyIfDue(signedPreKeyRotationTsHint) {
|
|
128
141
|
try {
|
|
129
142
|
const nowMs = Date.now();
|
|
130
|
-
const lastRotationTs =
|
|
143
|
+
const lastRotationTs = signedPreKeyRotationTsHint === undefined
|
|
144
|
+
? await this.signalStore.getSignedPreKeyRotationTs()
|
|
145
|
+
: signedPreKeyRotationTsHint;
|
|
131
146
|
if (lastRotationTs === null) {
|
|
132
147
|
await this.signalStore.setSignedPreKeyRotationTs(nowMs);
|
|
133
148
|
this.logger.trace('signal rotate key skipped on first run');
|
|
@@ -153,6 +168,19 @@ class WaPassiveTasksCoordinator {
|
|
|
153
168
|
});
|
|
154
169
|
}
|
|
155
170
|
}
|
|
171
|
+
resolveLocalKeyBundle(signalMeta) {
|
|
172
|
+
const { registrationInfo, signedPreKey } = signalMeta;
|
|
173
|
+
if (!registrationInfo || !signedPreKey) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
registrationInfo,
|
|
178
|
+
signedPreKey
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
async resolveLocalKeyBundleFromStore() {
|
|
182
|
+
return this.resolveLocalKeyBundle(await this.signalStore.getSignalMeta());
|
|
183
|
+
}
|
|
156
184
|
resolveRotationTimestamp(nowMs, errorCode) {
|
|
157
185
|
if (errorCode !== undefined && errorCode >= 500) {
|
|
158
186
|
const retryInMs = Math.min(this.signedPreKeyServerErrorBackoffMs, this.signedPreKeyRotationIntervalMs);
|
|
@@ -170,29 +198,44 @@ class WaPassiveTasksCoordinator {
|
|
|
170
198
|
return;
|
|
171
199
|
}
|
|
172
200
|
this.logger.info('flushing dangling receipts', { count: pending.length });
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
201
|
+
let cursor = 0;
|
|
202
|
+
while (cursor < pending.length) {
|
|
203
|
+
const batchEnd = Math.min(cursor + 4, pending.length);
|
|
204
|
+
const promises = [];
|
|
205
|
+
for (let i = cursor; i < batchEnd; i += 1) {
|
|
206
|
+
promises.push(this.runtime.sendNodeDirect(pending[i]));
|
|
177
207
|
}
|
|
178
|
-
|
|
179
|
-
|
|
208
|
+
const results = await Promise.allSettled(promises);
|
|
209
|
+
let transientCount = 0;
|
|
210
|
+
for (let i = 0; i < results.length; i += 1) {
|
|
211
|
+
const result = results[i];
|
|
212
|
+
if (result.status === 'fulfilled') {
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
const node = pending[cursor + i];
|
|
216
|
+
const normalized = (0, primitives_1.toError)(result.reason);
|
|
180
217
|
if (this.runtime.shouldQueueDanglingReceipt(node, normalized)) {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
218
|
+
this.runtime.requeueDanglingReceipt(node);
|
|
219
|
+
transientCount += 1;
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
this.logger.warn('dropping dangling receipt due non-retryable send error', {
|
|
223
|
+
id: node.attrs.id,
|
|
224
|
+
to: node.attrs.to,
|
|
186
225
|
message: normalized.message
|
|
187
226
|
});
|
|
188
|
-
return;
|
|
189
227
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
228
|
+
}
|
|
229
|
+
if (transientCount > 0) {
|
|
230
|
+
for (let i = batchEnd; i < pending.length; i += 1) {
|
|
231
|
+
this.runtime.requeueDanglingReceipt(pending[i]);
|
|
232
|
+
}
|
|
233
|
+
this.logger.warn('stopped dangling receipt flush due transient send error', {
|
|
234
|
+
remaining: transientCount + (pending.length - batchEnd)
|
|
194
235
|
});
|
|
236
|
+
return;
|
|
195
237
|
}
|
|
238
|
+
cursor = batchEnd;
|
|
196
239
|
}
|
|
197
240
|
this.logger.info('dangling receipts flushed');
|
|
198
241
|
}
|
|
@@ -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,212 @@
|
|
|
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);
|
|
179
|
+
(0, query_1.assertIqResult)(result, 'profile.setStatus');
|
|
180
|
+
},
|
|
181
|
+
getProfiles: async (jids) => {
|
|
182
|
+
if (jids.length === 0) {
|
|
183
|
+
return [];
|
|
184
|
+
}
|
|
185
|
+
const sid = await generateSid();
|
|
186
|
+
const queryProtocolNodes = (0, profile_1.buildGetStatusUsyncQueryNodes)();
|
|
187
|
+
const usyncNode = (0, usync_1.buildUsyncIq)({
|
|
188
|
+
sid,
|
|
189
|
+
queryProtocolNodes,
|
|
190
|
+
users: jids.map((jid) => ({ jid }))
|
|
191
|
+
});
|
|
192
|
+
const result = await queryWithContext('profile.getProfiles', usyncNode, undefined, {
|
|
193
|
+
count: jids.length
|
|
194
|
+
});
|
|
195
|
+
(0, query_1.assertIqResult)(result, 'profile.getProfiles');
|
|
196
|
+
return parseUsyncProfiles(result);
|
|
197
|
+
},
|
|
198
|
+
getDisappearingMode: async (jids) => {
|
|
199
|
+
if (jids.length === 0)
|
|
200
|
+
return [];
|
|
201
|
+
const sid = await generateSid();
|
|
202
|
+
const usyncNode = (0, usync_1.buildUsyncIq)({
|
|
203
|
+
sid,
|
|
204
|
+
queryProtocolNodes: [(0, profile_1.buildGetDisappearingModeUsyncQueryNode)()],
|
|
205
|
+
users: jids.map((jid) => ({ jid }))
|
|
206
|
+
});
|
|
207
|
+
const result = await queryWithContext('profile.getDisappearingMode', usyncNode, undefined, { count: jids.length });
|
|
208
|
+
(0, query_1.assertIqResult)(result, 'profile.getDisappearingMode');
|
|
209
|
+
return parseUsyncDisappearingModes(result);
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
}
|