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
package/dist/auth/index.js
CHANGED
|
@@ -14,12 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.
|
|
17
|
+
exports.WaAuthClient = void 0;
|
|
18
18
|
__exportStar(require("./types"), exports);
|
|
19
19
|
var WaAuthClient_1 = require("./WaAuthClient");
|
|
20
20
|
Object.defineProperty(exports, "WaAuthClient", { enumerable: true, get: function () { return WaAuthClient_1.WaAuthClient; } });
|
|
21
|
-
var WaPairingCodeCrypto_1 = require("./pairing/WaPairingCodeCrypto");
|
|
22
|
-
Object.defineProperty(exports, "completeCompanionFinish", { enumerable: true, get: function () { return WaPairingCodeCrypto_1.completeCompanionFinish; } });
|
|
23
|
-
Object.defineProperty(exports, "createCompanionHello", { enumerable: true, get: function () { return WaPairingCodeCrypto_1.createCompanionHello; } });
|
|
24
|
-
var auth_store_1 = require("../store/providers/sqlite/auth.store");
|
|
25
|
-
Object.defineProperty(exports, "WaAuthSqliteStore", { enumerable: true, get: function () { return auth_store_1.WaAuthSqliteStore; } });
|
|
@@ -49,8 +49,8 @@ async function completeCompanionFinish(args) {
|
|
|
49
49
|
if (primaryEphemeralPub.length === 0) {
|
|
50
50
|
throw new Error('empty primary ephemeral public key');
|
|
51
51
|
}
|
|
52
|
-
const sharedEphemeral = await
|
|
53
|
-
|
|
52
|
+
const [sharedEphemeral, bundleSalt, bundleSecret, bundleIv] = await Promise.all([
|
|
53
|
+
X25519_1.X25519.scalarMult(args.companionEphemeralPrivKey, primaryEphemeralPub),
|
|
54
54
|
(0, _crypto_1.randomBytesAsync)(32),
|
|
55
55
|
(0, _crypto_1.randomBytesAsync)(32),
|
|
56
56
|
(0, _crypto_1.randomBytesAsync)(12)
|
|
@@ -62,9 +62,11 @@ async function completeCompanionFinish(args) {
|
|
|
62
62
|
args.primaryIdentityPub,
|
|
63
63
|
bundleSecret
|
|
64
64
|
]);
|
|
65
|
-
const encryptedBundle = await
|
|
65
|
+
const [encryptedBundle, sharedIdentity] = await Promise.all([
|
|
66
|
+
(0, _crypto_1.aesGcmEncrypt)(bundleEncryptionKey, bundleIv, plaintextBundle),
|
|
67
|
+
X25519_1.X25519.scalarMult(args.registrationIdentityKeyPair.privKey, args.primaryIdentityPub)
|
|
68
|
+
]);
|
|
66
69
|
const wrappedKeyBundle = (0, bytes_1.concatBytes)([bundleSalt, bundleIv, encryptedBundle]);
|
|
67
|
-
const sharedIdentity = await X25519_1.X25519.scalarMult(args.registrationIdentityKeyPair.privKey, args.primaryIdentityPub);
|
|
68
70
|
const advMaterial = (0, bytes_1.concatBytes)([sharedEphemeral, sharedIdentity, bundleSecret]);
|
|
69
71
|
const advSecret = await (0, _crypto_1.hkdf)(advMaterial, null, constants_2.WA_PAIRING_KDF_INFO.ADV_SECRET, 32);
|
|
70
72
|
return {
|
|
@@ -7,6 +7,7 @@ const _proto_1 = require("../../proto.js");
|
|
|
7
7
|
const constants_1 = require("../../protocol/constants");
|
|
8
8
|
const jid_1 = require("../../protocol/jid");
|
|
9
9
|
const WaAdvSignature_1 = require("../../signal/crypto/WaAdvSignature");
|
|
10
|
+
const global_1 = require("../../transport/node/builders/global");
|
|
10
11
|
const pairing_1 = require("../../transport/node/builders/pairing");
|
|
11
12
|
const helpers_1 = require("../../transport/node/helpers");
|
|
12
13
|
const bytes_1 = require("../../util/bytes");
|
|
@@ -121,7 +122,10 @@ class WaPairingFlow {
|
|
|
121
122
|
id: node.attrs.id,
|
|
122
123
|
stage: linkCodeNode.attrs.stage
|
|
123
124
|
});
|
|
124
|
-
await this.opts.socket.sendNode((0,
|
|
125
|
+
await this.opts.socket.sendNode((0, global_1.buildAckNode)({
|
|
126
|
+
kind: 'notification',
|
|
127
|
+
node
|
|
128
|
+
}));
|
|
125
129
|
const stage = linkCodeNode.attrs.stage;
|
|
126
130
|
if (stage === constants_1.WA_SIGNALING.LINK_CODE_STAGE_REFRESH_CODE) {
|
|
127
131
|
const refNode = (0, helpers_1.findNodeChild)(linkCodeNode, constants_1.WA_NODE_TAGS.LINK_CODE_PAIRING_REF);
|
|
@@ -149,18 +153,24 @@ class WaPairingFlow {
|
|
|
149
153
|
if (!hasExpectedChild) {
|
|
150
154
|
return false;
|
|
151
155
|
}
|
|
152
|
-
|
|
156
|
+
// Rotate first so we don't ack success before local credential state is durably updated.
|
|
153
157
|
await this.rotateAdvSecret(this.requireCredentials());
|
|
158
|
+
await this.opts.socket.sendNode((0, global_1.buildAckNode)({
|
|
159
|
+
kind: 'notification',
|
|
160
|
+
node,
|
|
161
|
+
typeOverride: constants_1.WA_SIGNALING.COMPANION_REG_REFRESH_NOTIFICATION
|
|
162
|
+
}));
|
|
154
163
|
this.opts.logger.info('handled companion_reg_refresh notification');
|
|
155
164
|
this.opts.qrFlow.refreshCurrentQr();
|
|
156
165
|
return true;
|
|
157
166
|
}
|
|
158
167
|
async handlePairDevice(iqNode, pairDeviceNode) {
|
|
159
168
|
const refs = (0, helpers_1.getNodeChildrenNonEmptyUtf8ByTag)(pairDeviceNode, constants_1.WA_NODE_TAGS.REF, 'pair-device.ref');
|
|
169
|
+
// Commit adv-secret rotation before sending IQ success to avoid protocol/state divergence.
|
|
160
170
|
await this.rotateAdvSecret(this.requireCredentials());
|
|
171
|
+
await this.opts.socket.sendNode((0, global_1.buildIqResultNode)(iqNode));
|
|
161
172
|
this.opts.qrFlow.setRefs(refs);
|
|
162
173
|
this.opts.logger.info('pair-device refs updated', { refsCount: refs.length });
|
|
163
|
-
await this.opts.socket.sendNode((0, pairing_1.buildIqResultNode)(iqNode));
|
|
164
174
|
}
|
|
165
175
|
async handlePairSuccess(iqNode, pairSuccessNode) {
|
|
166
176
|
this.opts.logger.info('processing pair-success node');
|
package/dist/client/WaClient.js
CHANGED
|
@@ -6,6 +6,7 @@ const utils_1 = require("../appstate/utils");
|
|
|
6
6
|
const chat_1 = require("./events/chat");
|
|
7
7
|
const history_sync_1 = require("./history-sync");
|
|
8
8
|
const mailbox_1 = require("./mailbox");
|
|
9
|
+
const WriteBehindPersistence_1 = require("./persistence/WriteBehindPersistence");
|
|
9
10
|
const WaClientFactory_1 = require("./WaClientFactory");
|
|
10
11
|
const ConsoleLogger_1 = require("../infra/log/ConsoleLogger");
|
|
11
12
|
const _proto_1 = require("../proto.js");
|
|
@@ -27,6 +28,9 @@ class WaClient extends node_events_1.EventEmitter {
|
|
|
27
28
|
constructor(options, logger = new ConsoleLogger_1.ConsoleLogger('info')) {
|
|
28
29
|
super();
|
|
29
30
|
this.connectPromise = null;
|
|
31
|
+
this.acceptingIncomingEvents = true;
|
|
32
|
+
this.activeIncomingHandlers = 0;
|
|
33
|
+
this.incomingHandlersDrainedWaiters = [];
|
|
30
34
|
const base = (0, WaClientFactory_1.resolveWaClientBase)(options, logger);
|
|
31
35
|
this.options = base.options;
|
|
32
36
|
this.logger = base.logger;
|
|
@@ -34,11 +38,17 @@ class WaClient extends node_events_1.EventEmitter {
|
|
|
34
38
|
this.contactStore = base.sessionStore.contacts;
|
|
35
39
|
this.messageStore = base.sessionStore.messages;
|
|
36
40
|
this.participantsStore = base.sessionStore.participants;
|
|
41
|
+
this.privacyTokenStore = base.sessionStore.privacyToken;
|
|
37
42
|
this.deviceListStore = base.sessionStore.deviceList;
|
|
38
43
|
this.retryStore = base.sessionStore.retry;
|
|
39
44
|
this.signalStore = base.sessionStore.signal;
|
|
40
45
|
this.senderKeyStore = base.sessionStore.senderKey;
|
|
41
46
|
this.threadStore = base.sessionStore.threads;
|
|
47
|
+
this.writeBehind = new WriteBehindPersistence_1.WriteBehindPersistence({
|
|
48
|
+
messageStore: this.messageStore,
|
|
49
|
+
threadStore: this.threadStore,
|
|
50
|
+
contactStore: this.contactStore
|
|
51
|
+
}, this.logger, this.options.writeBehind);
|
|
42
52
|
const dependencies = (0, WaClientFactory_1.buildWaClientDependencies)({
|
|
43
53
|
base,
|
|
44
54
|
runtime: {
|
|
@@ -51,7 +61,10 @@ class WaClient extends node_events_1.EventEmitter {
|
|
|
51
61
|
handleIncomingMessageEvent: this.handleIncomingMessageEvent.bind(this),
|
|
52
62
|
handleError: this.handleError.bind(this),
|
|
53
63
|
handleIncomingFrame: this.handleIncomingFrame.bind(this),
|
|
54
|
-
clearStoredState: this.clearStoredState.bind(this)
|
|
64
|
+
clearStoredState: this.clearStoredState.bind(this),
|
|
65
|
+
resumeIncomingEvents: () => {
|
|
66
|
+
this.acceptingIncomingEvents = true;
|
|
67
|
+
}
|
|
55
68
|
}
|
|
56
69
|
});
|
|
57
70
|
Object.assign(this, dependencies);
|
|
@@ -122,63 +135,65 @@ class WaClient extends node_events_1.EventEmitter {
|
|
|
122
135
|
this.handleError(error);
|
|
123
136
|
});
|
|
124
137
|
}
|
|
125
|
-
getMailboxPersistenceDeps() {
|
|
126
|
-
return {
|
|
127
|
-
logger: this.logger,
|
|
128
|
-
contactStore: this.contactStore,
|
|
129
|
-
messageStore: this.messageStore
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
138
|
async handleIncomingMessageEvent(event) {
|
|
133
|
-
this.
|
|
134
|
-
void (0, mailbox_1.persistIncomingMailboxEntities)({
|
|
135
|
-
...this.getMailboxPersistenceDeps(),
|
|
136
|
-
event
|
|
137
|
-
});
|
|
138
|
-
const protocolMessage = event.message?.protocolMessage;
|
|
139
|
-
if (!protocolMessage) {
|
|
139
|
+
if (!this.tryEnterIncomingHandler()) {
|
|
140
140
|
return;
|
|
141
141
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
if (protocolType === null || protocolType === undefined) {
|
|
149
|
-
this.logger.debug('incoming protocol message without type', {
|
|
150
|
-
id: event.stanzaId,
|
|
151
|
-
from: event.chatJid
|
|
142
|
+
try {
|
|
143
|
+
this.emit('message', event);
|
|
144
|
+
void (0, mailbox_1.persistIncomingMailboxEntities)({
|
|
145
|
+
logger: this.logger,
|
|
146
|
+
writeBehind: this.writeBehind,
|
|
147
|
+
event
|
|
152
148
|
});
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
await this.handleIncomingAppStateSyncKeyRequest(event, protocolMessage);
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
if (protocolType === _proto_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE) {
|
|
160
|
-
await this.handleIncomingAppStateSyncKeyShare(event, protocolMessage);
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
if (protocolType === _proto_1.proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION) {
|
|
164
|
-
if (this.options.history?.enabled && protocolMessage.historySyncNotification) {
|
|
165
|
-
await this.handleHistorySyncNotification(protocolMessage.historySyncNotification);
|
|
149
|
+
const protocolMessage = event.message?.protocolMessage;
|
|
150
|
+
if (!protocolMessage) {
|
|
151
|
+
return;
|
|
166
152
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
153
|
+
const protocolEvent = {
|
|
154
|
+
...event,
|
|
155
|
+
protocolMessage
|
|
156
|
+
};
|
|
157
|
+
this.emit('message_protocol', protocolEvent);
|
|
158
|
+
const protocolType = protocolMessage.type;
|
|
159
|
+
if (protocolType === null || protocolType === undefined) {
|
|
160
|
+
this.logger.debug('incoming protocol message without type', {
|
|
161
|
+
id: event.stanzaId,
|
|
162
|
+
from: event.chatJid
|
|
163
|
+
});
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (protocolType === _proto_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_REQUEST) {
|
|
167
|
+
await this.handleIncomingAppStateSyncKeyRequest(event, protocolMessage);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (protocolType === _proto_1.proto.Message.ProtocolMessage.Type.APP_STATE_SYNC_KEY_SHARE) {
|
|
171
|
+
await this.handleIncomingAppStateSyncKeyShare(event, protocolMessage);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
if (protocolType === _proto_1.proto.Message.ProtocolMessage.Type.HISTORY_SYNC_NOTIFICATION) {
|
|
175
|
+
if (this.options.history?.enabled && protocolMessage.historySyncNotification) {
|
|
176
|
+
await this.handleHistorySyncNotification(protocolMessage.historySyncNotification);
|
|
177
|
+
}
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
if (SYNC_RELATED_PROTOCOL_TYPES.has(protocolType)) {
|
|
181
|
+
this.logger.info('incoming sync-related protocol message', {
|
|
182
|
+
id: event.stanzaId,
|
|
183
|
+
from: event.chatJid,
|
|
184
|
+
protocolType
|
|
185
|
+
});
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
this.logger.debug('incoming protocol message received', {
|
|
171
189
|
id: event.stanzaId,
|
|
172
190
|
from: event.chatJid,
|
|
173
191
|
protocolType
|
|
174
192
|
});
|
|
175
|
-
return;
|
|
176
193
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
protocolType
|
|
181
|
-
});
|
|
194
|
+
finally {
|
|
195
|
+
this.leaveIncomingHandler();
|
|
196
|
+
}
|
|
182
197
|
}
|
|
183
198
|
async handleIncomingAppStateSyncKeyShare(event, protocolMessage) {
|
|
184
199
|
const share = protocolMessage.appStateSyncKeyShare;
|
|
@@ -267,9 +282,18 @@ class WaClient extends node_events_1.EventEmitter {
|
|
|
267
282
|
});
|
|
268
283
|
return;
|
|
269
284
|
}
|
|
270
|
-
const requestedKeys = await
|
|
271
|
-
const availableKeys =
|
|
272
|
-
const missingKeyIds =
|
|
285
|
+
const requestedKeys = await this.appStateStore.getSyncKeysBatch(requestedKeyIds);
|
|
286
|
+
const availableKeys = [];
|
|
287
|
+
const missingKeyIds = [];
|
|
288
|
+
for (let i = 0; i < requestedKeys.length; i += 1) {
|
|
289
|
+
const key = requestedKeys[i];
|
|
290
|
+
if (key !== null) {
|
|
291
|
+
availableKeys.push(key);
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
missingKeyIds.push(requestedKeyIds[i]);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
273
297
|
try {
|
|
274
298
|
await this.messageDispatch.sendAppStateSyncKeyShare(requesterDeviceJid, availableKeys, missingKeyIds);
|
|
275
299
|
this.logger.info('responded to app-state key request', {
|
|
@@ -316,18 +340,18 @@ class WaClient extends node_events_1.EventEmitter {
|
|
|
316
340
|
return false;
|
|
317
341
|
}
|
|
318
342
|
const candidateUser = (0, jid_1.toUserJid)(candidateJid);
|
|
319
|
-
|
|
320
|
-
.
|
|
321
|
-
.map((jid) => (0, jid_1.toUserJid)(jid));
|
|
322
|
-
return meUsers.includes(candidateUser);
|
|
343
|
+
return ((!!credentials.meJid && (0, jid_1.toUserJid)(credentials.meJid) === candidateUser) ||
|
|
344
|
+
(!!credentials.meLid && (0, jid_1.toUserJid)(credentials.meLid) === candidateUser));
|
|
323
345
|
}
|
|
324
346
|
async handleHistorySyncNotification(notification) {
|
|
325
347
|
try {
|
|
326
348
|
await (0, history_sync_1.processHistorySyncNotification)({
|
|
327
|
-
|
|
349
|
+
logger: this.logger,
|
|
328
350
|
mediaTransfer: this.mediaTransfer,
|
|
329
|
-
|
|
330
|
-
emitEvent: this.emit.bind(this)
|
|
351
|
+
writeBehind: this.writeBehind,
|
|
352
|
+
emitEvent: this.emit.bind(this),
|
|
353
|
+
onPrivacyTokens: (conversations) => this.trustedContactToken.hydrateFromHistorySync(conversations),
|
|
354
|
+
onNctSalt: (salt) => this.trustedContactToken.hydrateNctSaltFromHistorySync(salt)
|
|
331
355
|
}, notification);
|
|
332
356
|
}
|
|
333
357
|
catch (error) {
|
|
@@ -354,10 +378,17 @@ class WaClient extends node_events_1.EventEmitter {
|
|
|
354
378
|
this.logger.trace('wa client connect already in-flight');
|
|
355
379
|
return this.connectPromise;
|
|
356
380
|
}
|
|
381
|
+
this.acceptingIncomingEvents = true;
|
|
357
382
|
this.connectPromise = this.connectionManager
|
|
358
383
|
.connect((frame) => this.handleIncomingFrame(frame))
|
|
359
384
|
.then(() => {
|
|
360
|
-
this.emit('
|
|
385
|
+
this.emit('connection', {
|
|
386
|
+
status: 'open',
|
|
387
|
+
reason: 'connected',
|
|
388
|
+
code: null,
|
|
389
|
+
isLogout: false,
|
|
390
|
+
isNewLogin: this.connectionManager.wasNewLogin()
|
|
391
|
+
});
|
|
361
392
|
})
|
|
362
393
|
.finally(() => {
|
|
363
394
|
this.connectPromise = null;
|
|
@@ -365,9 +396,22 @@ class WaClient extends node_events_1.EventEmitter {
|
|
|
365
396
|
return this.connectPromise;
|
|
366
397
|
}
|
|
367
398
|
async disconnect() {
|
|
399
|
+
await this.pauseIncomingEventsAndWaitDrain();
|
|
400
|
+
const writeBehindFlush = await this.writeBehind.flush(this.options.writeBehind?.flushTimeoutMs);
|
|
401
|
+
if (writeBehindFlush.remaining > 0) {
|
|
402
|
+
this.logger.warn('disconnect continuing with pending write-behind entries', {
|
|
403
|
+
remaining: writeBehindFlush.remaining
|
|
404
|
+
});
|
|
405
|
+
}
|
|
368
406
|
this.keyShareCoordinator.notifyDisconnected();
|
|
369
407
|
await this.connectionManager.disconnect();
|
|
370
|
-
this.emit('
|
|
408
|
+
this.emit('connection', {
|
|
409
|
+
status: 'close',
|
|
410
|
+
reason: 'client_disconnected',
|
|
411
|
+
code: null,
|
|
412
|
+
isLogout: false,
|
|
413
|
+
isNewLogin: false
|
|
414
|
+
});
|
|
371
415
|
}
|
|
372
416
|
async requestPairingCode(phoneNumber, shouldShowPushNotification = false) {
|
|
373
417
|
if (!this.connectionManager.isConnected() || !this.authClient.getCurrentCredentials()) {
|
|
@@ -387,7 +431,10 @@ class WaClient extends node_events_1.EventEmitter {
|
|
|
387
431
|
if (!this.connectionManager.isConnected() || !this.authClient.getCurrentCredentials()) {
|
|
388
432
|
throw new Error('client is not connected');
|
|
389
433
|
}
|
|
390
|
-
const normalizedPhoneJids = phoneNumbers.
|
|
434
|
+
const normalizedPhoneJids = new Array(phoneNumbers.length);
|
|
435
|
+
for (let index = 0; index < phoneNumbers.length; index += 1) {
|
|
436
|
+
normalizedPhoneJids[index] = (0, jid_1.parsePhoneJid)(phoneNumbers[index]);
|
|
437
|
+
}
|
|
391
438
|
this.logger.trace('wa client query lids by phone numbers', {
|
|
392
439
|
phones: normalizedPhoneJids.length
|
|
393
440
|
});
|
|
@@ -396,41 +443,38 @@ class WaClient extends node_events_1.EventEmitter {
|
|
|
396
443
|
sendMessage(to, content, options = {}) {
|
|
397
444
|
return this.messageDispatch.sendMessage(to, content, options);
|
|
398
445
|
}
|
|
399
|
-
syncSignalSession(jid, reasonIdentity = false) {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
}
|
|
408
|
-
setChatRead(chatJid, read) {
|
|
409
|
-
return this.appStateMutations.setChatRead(chatJid, read);
|
|
410
|
-
}
|
|
411
|
-
setChatPin(chatJid, pinned) {
|
|
412
|
-
return this.appStateMutations.setChatPin(chatJid, pinned);
|
|
446
|
+
async syncSignalSession(jid, reasonIdentity = false) {
|
|
447
|
+
await this.messageDispatch.syncSignalSession(jid, reasonIdentity);
|
|
448
|
+
if (reasonIdentity) {
|
|
449
|
+
this.trustedContactToken.reissueOnIdentityChange(jid).catch((err) => this.logger.warn('tc token reissue on identity change failed', {
|
|
450
|
+
jid,
|
|
451
|
+
message: (0, primitives_1.toError)(err).message
|
|
452
|
+
}));
|
|
453
|
+
}
|
|
413
454
|
}
|
|
414
|
-
|
|
415
|
-
return this.
|
|
455
|
+
get chat() {
|
|
456
|
+
return this.chatCoordinator;
|
|
416
457
|
}
|
|
417
|
-
|
|
418
|
-
return this.
|
|
458
|
+
get group() {
|
|
459
|
+
return this.groupCoordinator;
|
|
419
460
|
}
|
|
420
|
-
|
|
421
|
-
return this.
|
|
461
|
+
get privacy() {
|
|
462
|
+
return this.privacyCoordinator;
|
|
422
463
|
}
|
|
423
|
-
|
|
424
|
-
return this.
|
|
464
|
+
get profile() {
|
|
465
|
+
return this.profileCoordinator;
|
|
425
466
|
}
|
|
426
|
-
|
|
427
|
-
return this.
|
|
467
|
+
get business() {
|
|
468
|
+
return this.businessCoordinator;
|
|
428
469
|
}
|
|
429
|
-
|
|
430
|
-
return this.
|
|
470
|
+
sendReceipt(input) {
|
|
471
|
+
return this.messageDispatch.sendReceipt(input);
|
|
431
472
|
}
|
|
432
473
|
flushAppStateMutations() {
|
|
433
|
-
return this.
|
|
474
|
+
return this.chatCoordinator.flushMutations();
|
|
475
|
+
}
|
|
476
|
+
flushWriteBehind(timeoutMs) {
|
|
477
|
+
return this.writeBehind.flush(timeoutMs);
|
|
434
478
|
}
|
|
435
479
|
async exportAppState() {
|
|
436
480
|
return this.appStateSync.exportState();
|
|
@@ -507,9 +551,13 @@ class WaClient extends node_events_1.EventEmitter {
|
|
|
507
551
|
});
|
|
508
552
|
}
|
|
509
553
|
getBlockedAppStateCollections(syncResult) {
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
554
|
+
const blocked = [];
|
|
555
|
+
for (const entry of syncResult.collections) {
|
|
556
|
+
if (entry.state === constants_1.WA_APP_STATE_COLLECTION_STATES.BLOCKED) {
|
|
557
|
+
blocked.push(entry.collection);
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
return blocked;
|
|
513
561
|
}
|
|
514
562
|
emitChatEventsFromAppStateSyncResult(syncResult) {
|
|
515
563
|
const shouldEmitSnapshotMutations = this.options.chatEvents?.emitSnapshotMutations === true;
|
|
@@ -533,6 +581,7 @@ class WaClient extends node_events_1.EventEmitter {
|
|
|
533
581
|
continue;
|
|
534
582
|
}
|
|
535
583
|
try {
|
|
584
|
+
this.handleNctSaltMutation(mutation);
|
|
536
585
|
const event = (0, chat_1.parseChatEventFromAppStateMutation)(mutation);
|
|
537
586
|
if (!event) {
|
|
538
587
|
continue;
|
|
@@ -550,23 +599,98 @@ class WaClient extends node_events_1.EventEmitter {
|
|
|
550
599
|
}
|
|
551
600
|
}
|
|
552
601
|
}
|
|
602
|
+
handleNctSaltMutation(mutation) {
|
|
603
|
+
const nctAction = mutation.value?.nctSaltSyncAction;
|
|
604
|
+
if (!nctAction) {
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
if (mutation.operation === 'set' && nctAction.salt) {
|
|
608
|
+
this.trustedContactToken.handleNctSaltSync(nctAction.salt).catch((err) => this.logger.warn('nct salt sync set failed', {
|
|
609
|
+
message: (0, primitives_1.toError)(err).message
|
|
610
|
+
}));
|
|
611
|
+
}
|
|
612
|
+
else if (mutation.operation === 'remove') {
|
|
613
|
+
this.trustedContactToken.handleNctSaltSync(null).catch((err) => this.logger.warn('nct salt sync remove failed', {
|
|
614
|
+
message: (0, primitives_1.toError)(err).message
|
|
615
|
+
}));
|
|
616
|
+
}
|
|
617
|
+
}
|
|
553
618
|
async clearStoredState() {
|
|
619
|
+
await this.pauseIncomingEventsAndWaitDrain();
|
|
620
|
+
const writeBehindDestroy = await this.writeBehind.destroy(this.options.writeBehind?.flushTimeoutMs);
|
|
621
|
+
if (writeBehindDestroy.remaining > 0) {
|
|
622
|
+
throw new Error(`clear stored state aborted: write-behind did not fully drain (remaining=${writeBehindDestroy.remaining})`);
|
|
623
|
+
}
|
|
554
624
|
const danglingReceipts = this.receiptQueue.take();
|
|
555
625
|
if (danglingReceipts.length > 0) {
|
|
556
626
|
this.logger.debug('cleared dangling receipts while clearing stored state', {
|
|
557
627
|
count: danglingReceipts.length
|
|
558
628
|
});
|
|
559
629
|
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
630
|
+
const s = this.options.logoutStoreClear;
|
|
631
|
+
const shouldClear = (key) => s === undefined || s[key] !== false;
|
|
632
|
+
if (shouldClear('auth'))
|
|
633
|
+
await this.authClient.clearStoredCredentials();
|
|
634
|
+
if (shouldClear('appState'))
|
|
635
|
+
await this.appStateStore.clear();
|
|
636
|
+
if (shouldClear('contacts'))
|
|
637
|
+
await this.contactStore.clear();
|
|
638
|
+
if (shouldClear('messages'))
|
|
639
|
+
await this.messageStore.clear();
|
|
640
|
+
if (shouldClear('participants'))
|
|
641
|
+
await this.participantsStore.clear();
|
|
642
|
+
if (shouldClear('deviceList'))
|
|
643
|
+
await this.deviceListStore.clear();
|
|
644
|
+
if (shouldClear('retry'))
|
|
645
|
+
await this.retryStore.clear();
|
|
646
|
+
if (shouldClear('signal'))
|
|
647
|
+
await this.signalStore.clear();
|
|
648
|
+
if (shouldClear('senderKey'))
|
|
649
|
+
await this.senderKeyStore.clear();
|
|
650
|
+
if (shouldClear('threads'))
|
|
651
|
+
await this.threadStore.clear();
|
|
652
|
+
if (shouldClear('privacyToken'))
|
|
653
|
+
await this.privacyTokenStore.clear();
|
|
654
|
+
}
|
|
655
|
+
tryEnterIncomingHandler() {
|
|
656
|
+
if (!this.acceptingIncomingEvents) {
|
|
657
|
+
return false;
|
|
658
|
+
}
|
|
659
|
+
this.activeIncomingHandlers += 1;
|
|
660
|
+
if (this.acceptingIncomingEvents) {
|
|
661
|
+
return true;
|
|
662
|
+
}
|
|
663
|
+
this.leaveIncomingHandler();
|
|
664
|
+
return false;
|
|
665
|
+
}
|
|
666
|
+
leaveIncomingHandler() {
|
|
667
|
+
if (this.activeIncomingHandlers <= 0) {
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
this.activeIncomingHandlers -= 1;
|
|
671
|
+
if (this.activeIncomingHandlers === 0) {
|
|
672
|
+
this.notifyIncomingHandlersDrained();
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
async pauseIncomingEventsAndWaitDrain() {
|
|
676
|
+
this.acceptingIncomingEvents = false;
|
|
677
|
+
if (this.activeIncomingHandlers === 0) {
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
await new Promise((resolve) => {
|
|
681
|
+
this.incomingHandlersDrainedWaiters[this.incomingHandlersDrainedWaiters.length] =
|
|
682
|
+
resolve;
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
notifyIncomingHandlersDrained() {
|
|
686
|
+
if (this.incomingHandlersDrainedWaiters.length === 0) {
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
689
|
+
const waitersLength = this.incomingHandlersDrainedWaiters.length;
|
|
690
|
+
for (let index = 0; index < waitersLength; index += 1) {
|
|
691
|
+
this.incomingHandlersDrainedWaiters[index]();
|
|
692
|
+
}
|
|
693
|
+
this.incomingHandlersDrainedWaiters.length = 0;
|
|
570
694
|
}
|
|
571
695
|
handleError(error) {
|
|
572
696
|
this.logger.error('wa client error', { message: error.message });
|