zapo-js 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -3
- package/dist/appstate/WaAppStateCrypto.js +49 -41
- package/dist/appstate/WaAppStateSyncClient.js +79 -42
- package/dist/appstate/index.js +2 -2
- package/dist/auth/WaAuthClient.js +20 -11
- package/dist/auth/{flow/WaAuthCredentialsFlow.js → credentials-flow.js} +83 -18
- package/dist/auth/pairing/WaPairingFlow.js +26 -29
- package/dist/auth/pairing/{WaPairingCodeCrypto.js → pairing-code-crypto.js} +29 -13
- package/dist/client/WaClient.js +115 -75
- package/dist/client/WaClientFactory.js +113 -30
- package/dist/client/connection/WaConnectionManager.js +4 -1
- package/dist/client/coordinators/WaAbPropsCoordinator.js +141 -0
- package/dist/client/coordinators/WaBusinessCoordinator.js +3 -12
- package/dist/client/coordinators/WaEmailCoordinator.js +63 -0
- package/dist/client/coordinators/WaIncomingNodeCoordinator.js +33 -8
- package/dist/client/coordinators/WaMessageDispatchCoordinator.js +55 -25
- package/dist/client/coordinators/WaOfflineResumeCoordinator.js +114 -0
- package/dist/client/coordinators/WaPassiveTasksCoordinator.js +38 -20
- package/dist/client/coordinators/WaProfileCoordinator.js +3 -1
- package/dist/client/coordinators/WaRetryCoordinator.js +11 -9
- package/dist/client/coordinators/WaTrustedContactTokenCoordinator.js +22 -4
- package/dist/client/dirty.js +1 -1
- package/dist/client/events/abprops.js +43 -0
- package/dist/client/events/privacy-token.js +1 -2
- package/dist/client/events/registration.js +42 -0
- package/dist/client/incoming.js +37 -0
- package/dist/client/mailbox.js +17 -1
- package/dist/client/media.js +243 -0
- package/dist/client/messages.js +163 -86
- package/dist/crypto/core/index.js +4 -1
- package/dist/crypto/core/random.js +3 -9
- package/dist/crypto/core/xeddsa.js +57 -0
- package/dist/crypto/curves/X25519.js +18 -0
- package/dist/crypto/curves/constants.js +2 -1
- package/dist/esm/appstate/WaAppStateCrypto.js +39 -31
- package/dist/esm/appstate/WaAppStateSyncClient.js +68 -31
- package/dist/esm/appstate/index.js +1 -1
- package/dist/esm/appstate/{WaAppStateSyncResponseParser.js → response-parser.js} +1 -1
- package/dist/esm/auth/WaAuthClient.js +17 -8
- package/dist/esm/auth/{flow/WaAuthCredentialsFlow.js → credentials-flow.js} +83 -18
- package/dist/esm/auth/pairing/WaPairingFlow.js +25 -28
- package/dist/esm/auth/pairing/{WaPairingCodeCrypto.js → pairing-code-crypto.js} +20 -6
- package/dist/esm/client/WaClient.js +116 -76
- package/dist/esm/client/WaClientFactory.js +114 -31
- package/dist/esm/client/connection/WaConnectionManager.js +4 -1
- package/dist/esm/client/coordinators/WaAbPropsCoordinator.js +137 -0
- package/dist/esm/client/coordinators/WaBusinessCoordinator.js +4 -13
- package/dist/esm/client/coordinators/WaEmailCoordinator.js +60 -0
- package/dist/esm/client/coordinators/WaIncomingNodeCoordinator.js +35 -10
- package/dist/esm/client/coordinators/WaMessageDispatchCoordinator.js +47 -17
- package/dist/esm/client/coordinators/WaOfflineResumeCoordinator.js +110 -0
- package/dist/esm/client/coordinators/WaPassiveTasksCoordinator.js +38 -20
- package/dist/esm/client/coordinators/WaProfileCoordinator.js +3 -1
- package/dist/esm/client/coordinators/WaRetryCoordinator.js +11 -9
- package/dist/esm/client/coordinators/WaTrustedContactTokenCoordinator.js +24 -6
- package/dist/esm/client/dirty.js +1 -1
- package/dist/esm/client/events/abprops.js +40 -0
- package/dist/esm/client/events/privacy-token.js +1 -2
- package/dist/esm/client/events/registration.js +39 -0
- package/dist/esm/client/incoming.js +36 -0
- package/dist/esm/client/mailbox.js +17 -1
- package/dist/esm/client/media.js +234 -0
- package/dist/esm/client/messages.js +162 -85
- package/dist/esm/crypto/core/index.js +1 -0
- package/dist/esm/crypto/core/random.js +2 -7
- package/dist/esm/crypto/core/xeddsa.js +53 -0
- package/dist/esm/crypto/curves/X25519.js +20 -2
- package/dist/esm/crypto/curves/constants.js +1 -0
- package/dist/esm/infra/perf/StoreLock.js +7 -4
- package/dist/esm/media/WaMediaCrypto.js +257 -62
- package/dist/esm/media/WaMediaTransferClient.js +47 -190
- package/dist/esm/media/constants.js +2 -0
- package/dist/esm/media/processor.js +1 -0
- package/dist/esm/message/addon-crypto.js +130 -3
- package/dist/esm/message/content.js +12 -6
- package/dist/esm/message/icdc.js +8 -8
- package/dist/esm/message/incoming.js +14 -12
- package/dist/esm/message/phash.js +32 -12
- package/dist/esm/message/reporting-token.js +3 -3
- package/dist/esm/message/use-case-secret.js +1 -1
- package/dist/esm/protocol/abprops.js +159 -0
- package/dist/esm/protocol/browser.js +14 -0
- package/dist/esm/protocol/constants.js +3 -1
- package/dist/esm/protocol/email.js +30 -0
- package/dist/esm/protocol/jid.js +44 -10
- package/dist/esm/protocol/nodes.js +6 -2
- package/dist/esm/protocol/notification.js +7 -1
- package/dist/esm/retry/reason.js +1 -1
- package/dist/esm/signal/api/SignalDeviceSyncApi.js +5 -2
- package/dist/esm/signal/api/SignalDigestSyncApi.js +8 -6
- package/dist/esm/signal/api/SignalIdentitySyncApi.js +4 -4
- package/dist/esm/signal/api/SignalMissingPreKeysSyncApi.js +1 -1
- package/dist/esm/signal/api/SignalSessionSyncApi.js +1 -1
- package/dist/esm/signal/crypto/WaAdvSignature.js +5 -51
- package/dist/esm/signal/crypto/constants.js +0 -4
- package/dist/esm/signal/encoding.js +11 -54
- package/dist/esm/signal/group/SenderKeyChain.js +3 -3
- package/dist/esm/signal/group/SenderKeyCodec.js +5 -6
- package/dist/esm/signal/group/SenderKeyManager.js +13 -10
- package/dist/esm/signal/registration/keygen.js +2 -3
- package/dist/esm/signal/registration/utils.js +2 -2
- package/dist/esm/signal/session/SignalProtocol.js +18 -17
- package/dist/esm/signal/session/SignalRatchet.js +21 -10
- package/dist/esm/signal/session/SignalSerializer.js +5 -6
- package/dist/esm/signal/session/SignalSession.js +11 -9
- package/dist/esm/signal/session/resolver.js +6 -6
- package/dist/esm/store/contracts/identity.store.js +1 -0
- package/dist/esm/store/contracts/message-secret.store.js +1 -0
- package/dist/esm/store/contracts/pre-key.store.js +1 -0
- package/dist/esm/store/contracts/session.store.js +1 -0
- package/dist/esm/store/createStore.js +48 -12
- package/dist/esm/store/index.js +4 -0
- package/dist/esm/store/locks/identity.lock.js +16 -0
- package/dist/esm/store/locks/message-secret.lock.js +17 -0
- package/dist/esm/store/locks/pre-key.lock.js +27 -0
- package/dist/esm/store/locks/session.lock.js +19 -0
- package/dist/esm/store/locks/signal.lock.js +0 -24
- package/dist/esm/store/noop.store.js +20 -0
- package/dist/esm/store/providers/memory/device-list.store.js +3 -0
- package/dist/esm/store/providers/memory/identity.store.js +31 -0
- package/dist/esm/store/providers/memory/message-secret.store.js +81 -0
- package/dist/esm/store/providers/memory/participants.store.js +3 -0
- package/dist/esm/store/providers/memory/pre-key.store.js +97 -0
- package/dist/esm/store/providers/memory/retry.store.js +25 -11
- package/dist/esm/store/providers/memory/session.store.js +45 -0
- package/dist/esm/store/providers/memory/signal.store.js +1 -164
- package/dist/esm/transport/WaComms.js +4 -3
- package/dist/esm/transport/WaWebSocket.js +9 -1
- package/dist/esm/transport/index.js +6 -0
- package/dist/esm/transport/keepalive/WaKeepAlive.js +17 -8
- package/dist/esm/transport/node/WaMobileTcpSocket.js +114 -0
- package/dist/esm/transport/node/WaNodeOrchestrator.js +17 -8
- package/dist/esm/transport/node/builders/abprops.js +20 -0
- package/dist/esm/transport/node/builders/device.js +11 -0
- package/dist/esm/transport/node/builders/email.js +65 -0
- package/dist/esm/transport/node/builders/offline.js +14 -0
- package/dist/esm/transport/node/builders/prekeys.js +37 -40
- package/dist/esm/transport/node/builders/presence.js +13 -0
- package/dist/esm/transport/node/builders/privacy-token.js +19 -23
- package/dist/esm/transport/node/builders/retry.js +1 -1
- package/dist/esm/transport/node/helpers.js +24 -0
- package/dist/esm/transport/node/mex/argo-decoder.js +152 -0
- package/dist/esm/transport/node/mex/client.js +83 -0
- package/dist/esm/transport/node/mex/persist-ids.js +10 -0
- package/dist/esm/transport/noise/WaClientPayload.js +15 -10
- package/dist/esm/transport/noise/WaFrameCodec.js +2 -2
- package/dist/esm/transport/noise/WaMobileClientPayload.js +53 -0
- package/dist/esm/transport/noise/WaNoiseCert.js +9 -27
- package/dist/esm/transport/noise/WaNoiseSession.js +12 -11
- package/dist/infra/perf/StoreLock.js +7 -4
- package/dist/media/WaMediaCrypto.js +253 -58
- package/dist/media/WaMediaTransferClient.js +50 -223
- package/dist/media/constants.js +3 -1
- package/dist/media/processor.js +2 -0
- package/dist/message/addon-crypto.js +131 -0
- package/dist/message/content.js +13 -5
- package/dist/message/icdc.js +8 -8
- package/dist/message/incoming.js +14 -12
- package/dist/message/phash.js +32 -12
- package/dist/message/reporting-token.js +2 -2
- package/dist/message/use-case-secret.js +1 -1
- package/dist/protocol/abprops.js +163 -0
- package/dist/protocol/browser.js +15 -0
- package/dist/protocol/constants.js +14 -2
- package/dist/protocol/email.js +33 -0
- package/dist/protocol/jid.js +45 -10
- package/dist/protocol/nodes.js +6 -2
- package/dist/protocol/notification.js +8 -2
- package/dist/retry/reason.js +1 -1
- package/dist/signal/api/SignalDeviceSyncApi.js +5 -2
- package/dist/signal/api/SignalDigestSyncApi.js +8 -6
- package/dist/signal/api/SignalIdentitySyncApi.js +4 -4
- package/dist/signal/crypto/WaAdvSignature.js +2 -50
- package/dist/signal/crypto/constants.js +1 -5
- package/dist/signal/encoding.js +11 -49
- package/dist/signal/group/SenderKeyChain.js +2 -2
- package/dist/signal/group/SenderKeyCodec.js +4 -5
- package/dist/signal/group/SenderKeyManager.js +12 -9
- package/dist/signal/registration/keygen.js +1 -2
- package/dist/signal/registration/utils.js +2 -2
- package/dist/signal/session/SignalProtocol.js +18 -17
- package/dist/signal/session/SignalRatchet.js +19 -8
- package/dist/signal/session/SignalSerializer.js +5 -6
- package/dist/signal/session/SignalSession.js +11 -9
- package/dist/signal/session/resolver.js +6 -6
- package/dist/store/contracts/identity.store.js +2 -0
- package/dist/store/contracts/message-secret.store.js +2 -0
- package/dist/store/contracts/pre-key.store.js +2 -0
- package/dist/store/contracts/session.store.js +2 -0
- package/dist/store/createStore.js +47 -11
- package/dist/store/index.js +9 -1
- package/dist/store/locks/identity.lock.js +19 -0
- package/dist/store/locks/message-secret.lock.js +20 -0
- package/dist/store/locks/pre-key.lock.js +30 -0
- package/dist/store/locks/session.lock.js +22 -0
- package/dist/store/locks/signal.lock.js +0 -24
- package/dist/store/noop.store.js +21 -1
- package/dist/store/providers/memory/device-list.store.js +3 -0
- package/dist/store/providers/memory/identity.store.js +35 -0
- package/dist/store/providers/memory/message-secret.store.js +85 -0
- package/dist/store/providers/memory/participants.store.js +3 -0
- package/dist/store/providers/memory/pre-key.store.js +101 -0
- package/dist/store/providers/memory/retry.store.js +24 -10
- package/dist/store/providers/memory/session.store.js +49 -0
- package/dist/store/providers/memory/signal.store.js +1 -164
- package/dist/transport/WaComms.js +4 -3
- package/dist/transport/WaWebSocket.js +9 -1
- package/dist/transport/index.js +17 -1
- package/dist/transport/keepalive/WaKeepAlive.js +17 -8
- package/dist/transport/node/WaMobileTcpSocket.js +118 -0
- package/dist/transport/node/WaNodeOrchestrator.js +16 -7
- package/dist/transport/node/builders/abprops.js +23 -0
- package/dist/transport/node/builders/device.js +14 -0
- package/dist/transport/node/builders/email.js +72 -0
- package/dist/transport/node/builders/offline.js +17 -0
- package/dist/transport/node/builders/prekeys.js +36 -39
- package/dist/transport/node/builders/presence.js +16 -0
- package/dist/transport/node/builders/privacy-token.js +18 -22
- package/dist/transport/node/builders/retry.js +1 -1
- package/dist/transport/node/helpers.js +26 -0
- package/dist/transport/node/mex/argo-decoder.js +189 -0
- package/dist/transport/node/mex/client.js +86 -0
- package/dist/transport/node/mex/persist-ids.js +13 -0
- package/dist/transport/noise/WaClientPayload.js +14 -9
- package/dist/transport/noise/WaFrameCodec.js +1 -1
- package/dist/transport/noise/WaMobileClientPayload.js +56 -0
- package/dist/transport/noise/WaNoiseCert.js +8 -26
- package/dist/transport/noise/WaNoiseSession.js +11 -10
- package/dist/types/appstate/WaAppStateCrypto.d.ts +11 -8
- package/dist/types/appstate/WaAppStateSyncClient.d.ts +6 -2
- package/dist/types/appstate/index.d.ts +1 -1
- package/dist/types/appstate/{WaAppStateSyncResponseParser.d.ts → response-parser.d.ts} +1 -1
- package/dist/types/appstate/types.d.ts +1 -1
- package/dist/types/auth/WaAuthClient.d.ts +9 -3
- package/dist/types/auth/credentials-flow.d.ts +20 -0
- package/dist/types/auth/pairing/WaPairingFlow.d.ts +3 -2
- package/dist/types/auth/pairing/{WaPairingCodeCrypto.d.ts → pairing-code-crypto.d.ts} +6 -1
- package/dist/types/auth/types.d.ts +40 -0
- package/dist/types/client/WaClient.d.ts +19 -8
- package/dist/types/client/WaClientFactory.d.ts +10 -4
- package/dist/types/client/coordinators/WaAbPropsCoordinator.d.ts +26 -0
- package/dist/types/client/coordinators/WaBusinessCoordinator.d.ts +1 -1
- package/dist/types/client/coordinators/WaEmailCoordinator.d.ts +24 -0
- package/dist/types/client/coordinators/WaIncomingNodeCoordinator.d.ts +6 -1
- package/dist/types/client/coordinators/WaMessageDispatchCoordinator.d.ts +15 -2
- package/dist/types/client/coordinators/WaOfflineResumeCoordinator.d.ts +31 -0
- package/dist/types/client/coordinators/WaPassiveTasksCoordinator.d.ts +13 -2
- package/dist/types/client/coordinators/WaPrivacyCoordinator.d.ts +1 -1
- package/dist/types/client/coordinators/WaProfileCoordinator.d.ts +4 -2
- package/dist/types/client/coordinators/WaRetryCoordinator.d.ts +6 -0
- package/dist/types/client/coordinators/WaTrustedContactTokenCoordinator.d.ts +11 -1
- package/dist/types/client/dirty.d.ts +3 -1
- package/dist/types/client/events/abprops.d.ts +14 -0
- package/dist/types/client/events/registration.d.ts +17 -0
- package/dist/types/client/incoming.d.ts +6 -1
- package/dist/types/client/mailbox.d.ts +2 -0
- package/dist/types/client/media.d.ts +31 -0
- package/dist/types/client/messages.d.ts +2 -0
- package/dist/types/client/persistence/WriteBehindPersistence.d.ts +1 -1
- package/dist/types/client/types.d.ts +100 -1
- package/dist/types/crypto/core/index.d.ts +1 -0
- package/dist/types/crypto/core/primitives.d.ts +1 -1
- package/dist/types/crypto/core/random.d.ts +1 -1
- package/dist/types/crypto/core/xeddsa.d.ts +2 -0
- package/dist/types/crypto/curves/constants.d.ts +1 -0
- package/dist/types/crypto/index.d.ts +1 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/infra/log/ConsoleLogger.d.ts +1 -1
- package/dist/types/infra/log/PinoLogger.d.ts +1 -1
- package/dist/types/infra/perf/StoreLock.d.ts +1 -0
- package/dist/types/media/WaMediaCrypto.d.ts +15 -6
- package/dist/types/media/WaMediaTransferClient.d.ts +3 -11
- package/dist/types/media/constants.d.ts +2 -0
- package/dist/types/media/index.d.ts +1 -0
- package/dist/types/media/processor.d.ts +28 -0
- package/dist/types/media/types.d.ts +9 -3
- package/dist/types/message/addon-crypto.d.ts +34 -3
- package/dist/types/message/content.d.ts +3 -1
- package/dist/types/message/icdc.d.ts +4 -4
- package/dist/types/message/types.d.ts +16 -24
- package/dist/types/protocol/abprops.d.ts +142 -0
- package/dist/types/protocol/browser.d.ts +1 -0
- package/dist/types/protocol/constants.d.ts +5 -1
- package/dist/types/protocol/email.d.ts +32 -0
- package/dist/types/protocol/jid.d.ts +1 -0
- package/dist/types/protocol/nodes.d.ts +4 -0
- package/dist/types/protocol/notification.d.ts +6 -0
- package/dist/types/protocol/stream.d.ts +1 -0
- package/dist/types/retry/reason.d.ts +1 -1
- package/dist/types/signal/api/SignalDigestSyncApi.d.ts +3 -0
- package/dist/types/signal/api/SignalIdentitySyncApi.d.ts +3 -3
- package/dist/types/signal/crypto/WaAdvSignature.d.ts +0 -2
- package/dist/types/signal/crypto/constants.d.ts +0 -1
- package/dist/types/signal/encoding.d.ts +7 -1
- package/dist/types/signal/group/SenderKeyChain.d.ts +1 -1
- package/dist/types/signal/group/SenderKeyManager.d.ts +7 -2
- package/dist/types/signal/registration/utils.d.ts +2 -1
- package/dist/types/signal/session/SignalProtocol.d.ts +11 -2
- package/dist/types/signal/session/SignalSerializer.d.ts +2 -1
- package/dist/types/signal/session/resolver.d.ts +4 -2
- package/dist/types/signal/types.d.ts +16 -4
- package/dist/types/store/contracts/identity.store.d.ts +11 -0
- package/dist/types/store/contracts/message-secret.store.d.ts +16 -0
- package/dist/types/store/contracts/pre-key.store.d.ts +13 -0
- package/dist/types/store/contracts/session.store.d.ts +14 -0
- package/dist/types/store/contracts/signal.store.d.ts +1 -34
- package/dist/types/store/index.d.ts +9 -1
- package/dist/types/store/locks/identity.lock.d.ts +3 -0
- package/dist/types/store/locks/message-secret.lock.d.ts +3 -0
- package/dist/types/store/locks/pre-key.lock.d.ts +3 -0
- package/dist/types/store/locks/session.lock.d.ts +3 -0
- package/dist/types/store/noop.store.d.ts +4 -0
- package/dist/types/store/providers/memory/identity.store.d.ts +18 -0
- package/dist/types/store/providers/memory/message-secret.store.d.ts +21 -0
- package/dist/types/store/providers/memory/pre-key.store.d.ts +23 -0
- package/dist/types/store/providers/memory/retry.store.d.ts +7 -1
- package/dist/types/store/providers/memory/session.store.d.ts +21 -0
- package/dist/types/store/providers/memory/signal.store.d.ts +3 -45
- package/dist/types/store/providers/memory/thread.store.d.ts +1 -1
- package/dist/types/store/types.d.ts +21 -1
- package/dist/types/transport/WaWebSocket.d.ts +1 -0
- package/dist/types/transport/index.d.ts +8 -1
- package/dist/types/transport/keepalive/WaKeepAlive.d.ts +4 -1
- package/dist/types/transport/node/WaMobileTcpSocket.d.ts +18 -0
- package/dist/types/transport/node/WaNodeOrchestrator.d.ts +6 -2
- package/dist/types/transport/node/builders/abprops.d.ts +5 -0
- package/dist/types/transport/node/builders/device.d.ts +2 -0
- package/dist/types/transport/node/builders/email.d.ts +11 -0
- package/dist/types/transport/node/builders/offline.d.ts +2 -0
- package/dist/types/transport/node/builders/prekeys.d.ts +4 -3
- package/dist/types/transport/node/builders/presence.d.ts +6 -0
- package/dist/types/transport/node/helpers.d.ts +3 -0
- package/dist/types/transport/node/mex/argo-decoder.d.ts +11 -0
- package/dist/types/transport/node/mex/client.d.ts +18 -0
- package/dist/types/transport/node/mex/persist-ids.d.ts +14 -0
- package/dist/types/transport/noise/WaMobileClientPayload.d.ts +29 -0
- package/dist/types/transport/noise/WaNoiseCert.d.ts +7 -1
- package/dist/types/transport/noise/WaNoiseSession.d.ts +1 -0
- package/dist/types/transport/types.d.ts +8 -0
- package/package.json +6 -4
- package/dist/auth/pairing/constants.js +0 -5
- package/dist/client/connection/WaKeyShareCoordinator.js +0 -63
- package/dist/esm/auth/pairing/constants.js +0 -2
- package/dist/esm/client/connection/WaKeyShareCoordinator.js +0 -59
- package/dist/esm/transport/node/builders/index.js +0 -11
- package/dist/transport/node/builders/index.js +0 -51
- package/dist/types/auth/flow/WaAuthCredentialsFlow.d.ts +0 -14
- package/dist/types/auth/pairing/constants.d.ts +0 -2
- package/dist/types/client/connection/WaKeyShareCoordinator.d.ts +0 -14
- package/dist/types/transport/node/builders/index.d.ts +0 -11
- /package/dist/appstate/{WaAppStateSyncResponseParser.js → response-parser.js} +0 -0
|
@@ -7,6 +7,7 @@ export class WaPassiveTasksCoordinator {
|
|
|
7
7
|
constructor(options) {
|
|
8
8
|
this.logger = options.logger;
|
|
9
9
|
this.signalStore = options.signalStore;
|
|
10
|
+
this.preKeyStore = options.preKeyStore;
|
|
10
11
|
this.signalDigestSync = options.signalDigestSync;
|
|
11
12
|
this.signalRotateKey = options.signalRotateKey;
|
|
12
13
|
this.signedPreKeyRotationIntervalMs =
|
|
@@ -14,6 +15,8 @@ export class WaPassiveTasksCoordinator {
|
|
|
14
15
|
this.signedPreKeyServerErrorBackoffMs =
|
|
15
16
|
options.signedPreKeyServerErrorBackoffMs ?? SIGNAL_SIGNED_PREKEY_SERVER_ERROR_BACKOFF_MS;
|
|
16
17
|
this.runtime = options.runtime;
|
|
18
|
+
this.mobilePrimary = options.mobilePrimary ?? false;
|
|
19
|
+
this.appStateSync = options.appStateSync;
|
|
17
20
|
this.passiveTasksPromise = null;
|
|
18
21
|
}
|
|
19
22
|
startPassiveTasksAfterConnect() {
|
|
@@ -33,7 +36,7 @@ export class WaPassiveTasksCoordinator {
|
|
|
33
36
|
}
|
|
34
37
|
async handlePreKeyLowNotification() {
|
|
35
38
|
await Promise.all([
|
|
36
|
-
this.
|
|
39
|
+
this.preKeyStore.setServerHasPreKeys(false),
|
|
37
40
|
this.runtime.persistServerHasPreKeys(false)
|
|
38
41
|
]);
|
|
39
42
|
await this.uploadPreKeysIfMissing(false);
|
|
@@ -54,11 +57,29 @@ export class WaPassiveTasksCoordinator {
|
|
|
54
57
|
this.logger.trace('passive connect tasks skipped: session is not registered');
|
|
55
58
|
return;
|
|
56
59
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
this.runtime.syncAbProps();
|
|
61
|
+
if (this.mobilePrimary && this.appStateSync) {
|
|
62
|
+
await this.appStateSync.ensureInitialSyncKey().catch((error) => {
|
|
63
|
+
this.logger.warn('app-state initial key generation failed', {
|
|
64
|
+
message: toError(error).message
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
await this.runtime.sendPresenceAvailable().catch((error) => {
|
|
69
|
+
this.logger.warn('presence available send failed', {
|
|
70
|
+
message: toError(error).message
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
const [registrationInfo, signedPreKey, serverHasPreKeys, signedPreKeyRotationTs] = await Promise.all([
|
|
74
|
+
this.signalStore.getRegistrationInfo(),
|
|
75
|
+
this.signalStore.getSignedPreKey(),
|
|
76
|
+
this.preKeyStore.getServerHasPreKeys(),
|
|
77
|
+
this.signalStore.getSignedPreKeyRotationTs()
|
|
78
|
+
]);
|
|
79
|
+
const prefetchedLocalKeyBundle = registrationInfo && signedPreKey ? { registrationInfo, signedPreKey } : null;
|
|
80
|
+
await this.uploadPreKeysIfMissing(serverHasPreKeys, prefetchedLocalKeyBundle);
|
|
60
81
|
await this.validateDigestAndRecoverPreKeys(prefetchedLocalKeyBundle);
|
|
61
|
-
await this.rotateSignedPreKeyIfDue(
|
|
82
|
+
await this.rotateSignedPreKeyIfDue(signedPreKeyRotationTs);
|
|
62
83
|
await this.flushDanglingReceipts();
|
|
63
84
|
}
|
|
64
85
|
async validateDigestAndRecoverPreKeys(prefetchedLocalKeyBundle) {
|
|
@@ -81,7 +102,7 @@ export class WaPassiveTasksCoordinator {
|
|
|
81
102
|
return;
|
|
82
103
|
}
|
|
83
104
|
await Promise.all([
|
|
84
|
-
this.
|
|
105
|
+
this.preKeyStore.setServerHasPreKeys(false),
|
|
85
106
|
this.runtime.persistServerHasPreKeys(false)
|
|
86
107
|
]);
|
|
87
108
|
await this.uploadPreKeysIfMissing(false, prefetchedLocalKeyBundle);
|
|
@@ -93,7 +114,7 @@ export class WaPassiveTasksCoordinator {
|
|
|
93
114
|
}
|
|
94
115
|
}
|
|
95
116
|
async uploadPreKeysIfMissing(serverHasPreKeysHint, prefetchedLocalKeyBundle) {
|
|
96
|
-
const serverHasPreKeys = serverHasPreKeysHint ?? (await this.
|
|
117
|
+
const serverHasPreKeys = serverHasPreKeysHint ?? (await this.preKeyStore.getServerHasPreKeys());
|
|
97
118
|
if (serverHasPreKeys) {
|
|
98
119
|
this.logger.trace('prekey upload skipped: server already has prekeys');
|
|
99
120
|
return;
|
|
@@ -104,7 +125,7 @@ export class WaPassiveTasksCoordinator {
|
|
|
104
125
|
return;
|
|
105
126
|
}
|
|
106
127
|
const { registrationInfo, signedPreKey } = resolvedLocalKeyBundle;
|
|
107
|
-
const preKeys = await this.
|
|
128
|
+
const preKeys = await this.preKeyStore.getOrGenPreKeys(SIGNAL_UPLOAD_PREKEYS_COUNT, generatePreKeyPair);
|
|
108
129
|
if (preKeys.length === 0) {
|
|
109
130
|
throw new Error('no prekey available for upload');
|
|
110
131
|
}
|
|
@@ -113,12 +134,12 @@ export class WaPassiveTasksCoordinator {
|
|
|
113
134
|
const response = await this.runtime.queryWithContext('prekeys.upload', uploadNode, WA_DEFAULTS.IQ_TIMEOUT_MS, {
|
|
114
135
|
count: preKeys.length,
|
|
115
136
|
lastPreKeyId
|
|
116
|
-
});
|
|
137
|
+
}, this.mobilePrimary ? { useSystemId: true } : undefined);
|
|
117
138
|
if (response.attrs.type === 'result') {
|
|
118
139
|
// Mark uploaded key first so the serverHasPreKeys flag never commits ahead of local key progress.
|
|
119
|
-
await this.
|
|
140
|
+
await this.preKeyStore.markKeyAsUploaded(lastPreKeyId);
|
|
120
141
|
await Promise.all([
|
|
121
|
-
this.
|
|
142
|
+
this.preKeyStore.setServerHasPreKeys(true),
|
|
122
143
|
this.runtime.persistServerHasPreKeys(true)
|
|
123
144
|
]);
|
|
124
145
|
this.logger.info('uploaded prekeys to server', {
|
|
@@ -165,18 +186,15 @@ export class WaPassiveTasksCoordinator {
|
|
|
165
186
|
});
|
|
166
187
|
}
|
|
167
188
|
}
|
|
168
|
-
|
|
169
|
-
const
|
|
189
|
+
async resolveLocalKeyBundleFromStore() {
|
|
190
|
+
const [registrationInfo, signedPreKey] = await Promise.all([
|
|
191
|
+
this.signalStore.getRegistrationInfo(),
|
|
192
|
+
this.signalStore.getSignedPreKey()
|
|
193
|
+
]);
|
|
170
194
|
if (!registrationInfo || !signedPreKey) {
|
|
171
195
|
return null;
|
|
172
196
|
}
|
|
173
|
-
return {
|
|
174
|
-
registrationInfo,
|
|
175
|
-
signedPreKey
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
async resolveLocalKeyBundleFromStore() {
|
|
179
|
-
return this.resolveLocalKeyBundle(await this.signalStore.getSignalMeta());
|
|
197
|
+
return { registrationInfo, signedPreKey };
|
|
180
198
|
}
|
|
181
199
|
resolveRotationTimestamp(nowMs, errorCode) {
|
|
182
200
|
if (errorCode !== undefined && errorCode >= 500) {
|
|
@@ -172,7 +172,9 @@ export function createProfileCoordinator(options) {
|
|
|
172
172
|
},
|
|
173
173
|
setStatus: async (text) => {
|
|
174
174
|
const node = buildSetStatusIq(text);
|
|
175
|
-
const result = await queryWithContext('profile.setStatus', node
|
|
175
|
+
const result = await queryWithContext('profile.setStatus', node, undefined, undefined, {
|
|
176
|
+
useSystemId: true
|
|
177
|
+
});
|
|
176
178
|
assertIqResult(result, 'profile.setStatus');
|
|
177
179
|
},
|
|
178
180
|
getProfiles: async (jids) => {
|
|
@@ -37,6 +37,8 @@ export class WaRetryCoordinator {
|
|
|
37
37
|
this.retryStore = options.retryStore;
|
|
38
38
|
this.retryTtlMs = this.retryStore.getTtlMs?.() ?? RETRY_OUTBOUND_TTL_MS;
|
|
39
39
|
this.signalStore = options.signalStore;
|
|
40
|
+
this.preKeyStore = options.preKeyStore;
|
|
41
|
+
this.sessionStore = options.sessionStore;
|
|
40
42
|
this.senderKeyStore = options.senderKeyStore;
|
|
41
43
|
this.signalProtocol = options.signalProtocol;
|
|
42
44
|
this.signalDeviceSync = options.signalDeviceSync;
|
|
@@ -338,13 +340,13 @@ export class WaRetryCoordinator {
|
|
|
338
340
|
async buildRetryKeysSection(identity) {
|
|
339
341
|
const [signedPreKey, preKey] = await Promise.all([
|
|
340
342
|
this.signalStore.getSignedPreKey(),
|
|
341
|
-
this.
|
|
343
|
+
this.preKeyStore.getOrGenSinglePreKey(generatePreKeyPair)
|
|
342
344
|
]);
|
|
343
345
|
if (!signedPreKey) {
|
|
344
346
|
this.logger.warn('retry keys section skipped: signed prekey unavailable');
|
|
345
347
|
return undefined;
|
|
346
348
|
}
|
|
347
|
-
await this.
|
|
349
|
+
await this.preKeyStore.markKeyAsUploaded(preKey.keyId);
|
|
348
350
|
const signedIdentity = this.getCurrentSignedIdentity();
|
|
349
351
|
return {
|
|
350
352
|
identity,
|
|
@@ -365,11 +367,11 @@ export class WaRetryCoordinator {
|
|
|
365
367
|
async updateLocalSessionFromRetryRequest(request, requesterJid, requesterAddress, requesterNormalizedDeviceJid) {
|
|
366
368
|
const [, currentSession] = await Promise.all([
|
|
367
369
|
this.markRetryRequesterSenderKeyAsStale(request, requesterJid, requesterAddress),
|
|
368
|
-
this.
|
|
370
|
+
this.sessionStore.getSession(requesterAddress)
|
|
369
371
|
]);
|
|
370
372
|
const regIdMismatch = !!currentSession && request.regId > 0 && currentSession.remote.regId !== request.regId;
|
|
371
373
|
if (regIdMismatch && !request.keyBundle) {
|
|
372
|
-
await this.
|
|
374
|
+
await this.sessionStore.deleteSession(requesterAddress);
|
|
373
375
|
}
|
|
374
376
|
if (request.keyBundle) {
|
|
375
377
|
if (!request.keyBundle.key || !request.keyBundle.skey.signature) {
|
|
@@ -384,7 +386,7 @@ export class WaRetryCoordinator {
|
|
|
384
386
|
remoteRetryCount: request.retryCount,
|
|
385
387
|
...getRemoteRetryReasonLogFields(request.retryReason)
|
|
386
388
|
});
|
|
387
|
-
await this.
|
|
389
|
+
await this.sessionStore.deleteSession(requesterAddress);
|
|
388
390
|
return false;
|
|
389
391
|
}
|
|
390
392
|
if (regIdMismatch) {
|
|
@@ -395,12 +397,12 @@ export class WaRetryCoordinator {
|
|
|
395
397
|
remoteRetryCount: request.retryCount,
|
|
396
398
|
...getRemoteRetryReasonLogFields(request.retryReason)
|
|
397
399
|
});
|
|
398
|
-
await this.
|
|
400
|
+
await this.sessionStore.deleteSession(requesterAddress);
|
|
399
401
|
return false;
|
|
400
402
|
}
|
|
401
403
|
}
|
|
402
404
|
else if (regIdMismatch) {
|
|
403
|
-
await this.
|
|
405
|
+
await this.sessionStore.deleteSession(requesterAddress);
|
|
404
406
|
}
|
|
405
407
|
await this.signalProtocol.establishOutgoingSession(requesterAddress, {
|
|
406
408
|
regId: request.regId,
|
|
@@ -432,7 +434,7 @@ export class WaRetryCoordinator {
|
|
|
432
434
|
if (request.retryCount < 2) {
|
|
433
435
|
return true;
|
|
434
436
|
}
|
|
435
|
-
const currentSession = await this.
|
|
437
|
+
const currentSession = await this.sessionStore.getSession(requesterAddress);
|
|
436
438
|
const sessionBaseKey = currentSession?.aliceBaseKey ?? null;
|
|
437
439
|
if (!sessionBaseKey) {
|
|
438
440
|
return true;
|
|
@@ -446,7 +448,7 @@ export class WaRetryCoordinator {
|
|
|
446
448
|
if (!saved || !uint8Equal(saved.baseKey, sessionBaseKey)) {
|
|
447
449
|
return true;
|
|
448
450
|
}
|
|
449
|
-
await this.
|
|
451
|
+
await this.sessionStore.deleteSession(requesterAddress);
|
|
450
452
|
this.logger.info('retry request forcing session refresh due to repeated base key', {
|
|
451
453
|
id: request.stanzaId,
|
|
452
454
|
originalMsgId: request.originalMsgId,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { CsTokenGenerator } from '../tokens/cs-token.js';
|
|
2
|
-
import { isTokenExpired, shouldSendNewToken
|
|
2
|
+
import { clampDuration, isTokenExpired, shouldSendNewToken } from '../tokens/tc-token.js';
|
|
3
3
|
import { PromiseDedup } from '../../infra/perf/PromiseDedup.js';
|
|
4
4
|
import { WA_PRIVACY_TOKEN_TYPES, WA_TC_TOKEN_DEFAULTS } from '../../protocol/privacy-token.js';
|
|
5
|
-
import { buildPrivacyTokenIqNode, buildTcTokenMessageNode
|
|
5
|
+
import { buildCsTokenMessageNode, buildPrivacyTokenIqNode, buildTcTokenMessageNode } from '../../transport/node/builders/privacy-token.js';
|
|
6
6
|
import { toError } from '../../util/primitives.js';
|
|
7
7
|
const NCT_SALT_SENTINEL_JID = '__nct_salt__';
|
|
8
8
|
export class WaTrustedContactTokenCoordinator {
|
|
@@ -11,24 +11,40 @@ export class WaTrustedContactTokenCoordinator {
|
|
|
11
11
|
this.store = options.store;
|
|
12
12
|
this.runtime = options.runtime;
|
|
13
13
|
const maxDurationS = options.maxDurationS ?? WA_TC_TOKEN_DEFAULTS.MAX_DURATION_S;
|
|
14
|
-
this.
|
|
14
|
+
this.baseConfig = {
|
|
15
15
|
durationS: clampDuration(options.durationS ?? WA_TC_TOKEN_DEFAULTS.DURATION_S, maxDurationS),
|
|
16
16
|
numBuckets: options.numBuckets ?? WA_TC_TOKEN_DEFAULTS.NUM_BUCKETS,
|
|
17
17
|
senderDurationS: clampDuration(options.senderDurationS ?? WA_TC_TOKEN_DEFAULTS.SENDER_DURATION_S, maxDurationS),
|
|
18
18
|
senderNumBuckets: options.senderNumBuckets ?? WA_TC_TOKEN_DEFAULTS.SENDER_NUM_BUCKETS,
|
|
19
19
|
maxDurationS
|
|
20
20
|
};
|
|
21
|
+
this.getConfigOverrides = options.getConfigOverrides;
|
|
21
22
|
this.csTokenGenerator = new CsTokenGenerator();
|
|
22
23
|
this.senderTokenDedup = new PromiseDedup();
|
|
23
24
|
this.cachedNctSalt = null;
|
|
24
25
|
this.nctSaltHydrated = false;
|
|
25
26
|
}
|
|
27
|
+
resolveConfig() {
|
|
28
|
+
const overrides = this.getConfigOverrides?.();
|
|
29
|
+
if (!overrides) {
|
|
30
|
+
return this.baseConfig;
|
|
31
|
+
}
|
|
32
|
+
const maxDurationS = overrides.maxDurationS ?? this.baseConfig.maxDurationS;
|
|
33
|
+
return {
|
|
34
|
+
durationS: clampDuration(overrides.durationS ?? this.baseConfig.durationS, maxDurationS),
|
|
35
|
+
numBuckets: overrides.numBuckets ?? this.baseConfig.numBuckets,
|
|
36
|
+
senderDurationS: clampDuration(overrides.senderDurationS ?? this.baseConfig.senderDurationS, maxDurationS),
|
|
37
|
+
senderNumBuckets: overrides.senderNumBuckets ?? this.baseConfig.senderNumBuckets,
|
|
38
|
+
maxDurationS
|
|
39
|
+
};
|
|
40
|
+
}
|
|
26
41
|
async resolveTokenForMessage(recipientJid) {
|
|
27
42
|
const record = await this.store.getByJid(recipientJid);
|
|
28
43
|
const nowS = Math.floor(Date.now() / 1000);
|
|
44
|
+
const config = this.resolveConfig();
|
|
29
45
|
if (record?.tcToken &&
|
|
30
46
|
record.tcTokenTimestamp !== undefined &&
|
|
31
|
-
!isTokenExpired(record.tcTokenTimestamp, nowS,
|
|
47
|
+
!isTokenExpired(record.tcTokenTimestamp, nowS, config.durationS, config.numBuckets)) {
|
|
32
48
|
return buildTcTokenMessageNode(record.tcToken);
|
|
33
49
|
}
|
|
34
50
|
const nctSalt = await this.getNctSalt();
|
|
@@ -69,8 +85,9 @@ export class WaTrustedContactTokenCoordinator {
|
|
|
69
85
|
const nowS = Math.floor(Date.now() / 1000);
|
|
70
86
|
const record = await this.store.getByJid(recipientJid);
|
|
71
87
|
const senderTimestampS = record?.tcTokenSenderTimestamp;
|
|
88
|
+
const config = this.resolveConfig();
|
|
72
89
|
if (senderTimestampS !== undefined && senderTimestampS > 0) {
|
|
73
|
-
if (!shouldSendNewToken(senderTimestampS, nowS,
|
|
90
|
+
if (!shouldSendNewToken(senderTimestampS, nowS, config.senderDurationS)) {
|
|
74
91
|
return;
|
|
75
92
|
}
|
|
76
93
|
}
|
|
@@ -88,7 +105,8 @@ export class WaTrustedContactTokenCoordinator {
|
|
|
88
105
|
return;
|
|
89
106
|
}
|
|
90
107
|
const nowS = Math.floor(Date.now() / 1000);
|
|
91
|
-
|
|
108
|
+
const config = this.resolveConfig();
|
|
109
|
+
if (isTokenExpired(record.tcTokenSenderTimestamp, nowS, config.senderDurationS, config.senderNumBuckets)) {
|
|
92
110
|
return;
|
|
93
111
|
}
|
|
94
112
|
try {
|
package/dist/esm/client/dirty.js
CHANGED
|
@@ -262,7 +262,7 @@ async function clearDirtyBits(runtime, dirtyBits) {
|
|
|
262
262
|
try {
|
|
263
263
|
await runtime.queryWithContext('dirty.clear', buildClearDirtyBitsIq(dirtyBits), WA_DEFAULTS.IQ_TIMEOUT_MS, {
|
|
264
264
|
count: dirtyBits.length
|
|
265
|
-
});
|
|
265
|
+
}, { useSystemId: true });
|
|
266
266
|
runtime.logger.info('dirty bits cleared', {
|
|
267
267
|
count: dirtyBits.length
|
|
268
268
|
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { findNodeChild, getNodeChildren } from '../../transport/node/helpers.js';
|
|
2
|
+
import { parseOptionalInt } from '../../util/primitives.js';
|
|
3
|
+
export function parseAbPropsIqResult(node) {
|
|
4
|
+
const propsNode = findNodeChild(node, 'props');
|
|
5
|
+
if (!propsNode) {
|
|
6
|
+
return {
|
|
7
|
+
abKey: null,
|
|
8
|
+
hash: null,
|
|
9
|
+
refresh: null,
|
|
10
|
+
refreshId: null,
|
|
11
|
+
isDeltaUpdate: false,
|
|
12
|
+
props: []
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
const attrs = propsNode.attrs;
|
|
16
|
+
const propChildren = getNodeChildren(propsNode);
|
|
17
|
+
const props = [];
|
|
18
|
+
for (let i = 0; i < propChildren.length; i += 1) {
|
|
19
|
+
const child = propChildren[i];
|
|
20
|
+
if (child.tag !== 'prop') {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
const configCode = parseOptionalInt(child.attrs.config_code);
|
|
24
|
+
if (configCode === undefined) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
props.push({
|
|
28
|
+
configCode,
|
|
29
|
+
configValue: child.attrs.config_value ?? null
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
abKey: attrs.ab_key ?? null,
|
|
34
|
+
hash: attrs.hash ?? null,
|
|
35
|
+
refresh: parseOptionalInt(attrs.refresh) ?? null,
|
|
36
|
+
refreshId: parseOptionalInt(attrs.refresh_id) ?? null,
|
|
37
|
+
isDeltaUpdate: attrs.delta_update === 'true',
|
|
38
|
+
props
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { WA_PRIVACY_TOKEN_TAGS } from '../../protocol/privacy-token.js';
|
|
2
2
|
import { findNodeChild, getNodeChildren } from '../../transport/node/helpers.js';
|
|
3
|
-
import { toBytesView } from '../../util/bytes.js';
|
|
4
3
|
import { asNumber } from '../../util/coercion.js';
|
|
5
4
|
export function parsePrivacyTokenNotification(node) {
|
|
6
5
|
const tokensNode = findNodeChild(node, WA_PRIVACY_TOKEN_TAGS.TOKENS);
|
|
@@ -28,7 +27,7 @@ export function parsePrivacyTokenNotification(node) {
|
|
|
28
27
|
}
|
|
29
28
|
result[result.length] = {
|
|
30
29
|
type,
|
|
31
|
-
tokenBytes:
|
|
30
|
+
tokenBytes: content,
|
|
32
31
|
timestampS: asNumber(Number(rawTimestamp), 'privacy_token.t')
|
|
33
32
|
};
|
|
34
33
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { WA_REGISTRATION_NOTIFICATION_TAGS } from '../../protocol/notification.js';
|
|
2
|
+
import { getFirstNodeChild } from '../../transport/node/helpers.js';
|
|
3
|
+
import { parseOptionalInt } from '../../util/primitives.js';
|
|
4
|
+
export function parseRegistrationNotification(node) {
|
|
5
|
+
const firstChild = getFirstNodeChild(node);
|
|
6
|
+
if (!firstChild) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
if (firstChild.tag === WA_REGISTRATION_NOTIFICATION_TAGS.WA_OLD_REGISTRATION) {
|
|
10
|
+
const code = firstChild.attrs.code;
|
|
11
|
+
const expirySeconds = parseOptionalInt(firstChild.attrs.expiry_t);
|
|
12
|
+
const fromDeviceId = firstChild.attrs.device_id;
|
|
13
|
+
if (!code || expirySeconds === undefined || !fromDeviceId) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
kind: 'registration_code',
|
|
18
|
+
code,
|
|
19
|
+
expiryTimestampMs: expirySeconds * 1000,
|
|
20
|
+
fromDeviceId
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
if (firstChild.tag === WA_REGISTRATION_NOTIFICATION_TAGS.DEVICE_LOGOUT) {
|
|
24
|
+
const serverToken = firstChild.attrs.id;
|
|
25
|
+
const tSeconds = parseOptionalInt(firstChild.attrs.t);
|
|
26
|
+
if (!serverToken || tSeconds === undefined) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
kind: 'account_takeover_notice',
|
|
31
|
+
serverToken,
|
|
32
|
+
attemptTimestampMs: tSeconds * 1000,
|
|
33
|
+
newDeviceName: firstChild.attrs.device,
|
|
34
|
+
newDevicePlatform: firstChild.attrs.new_device_platform,
|
|
35
|
+
newDeviceAppVersion: firstChild.attrs.new_device_app_version
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { parseGroupNotificationEvents } from './events/group.js';
|
|
2
|
+
import { parseRegistrationNotification } from './events/registration.js';
|
|
2
3
|
import { WA_DISCONNECT_REASONS, WA_NODE_TAGS, WA_NOTIFICATION_TYPES } from '../protocol/constants.js';
|
|
3
4
|
import { buildAckNode } from '../transport/node/builders/global.js';
|
|
4
5
|
import { getFirstNodeChild, getNodeChildrenNonEmptyAttrValuesByTag } from '../transport/node/helpers.js';
|
|
@@ -217,6 +218,41 @@ export function createIncomingNotificationHandler(options) {
|
|
|
217
218
|
return true;
|
|
218
219
|
};
|
|
219
220
|
}
|
|
221
|
+
export function createIncomingRegistrationNotificationHandler(options) {
|
|
222
|
+
return async (node) => {
|
|
223
|
+
if (node.attrs.type !== WA_NOTIFICATION_TYPES.REGISTRATION) {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
const parsed = parseRegistrationNotification(node);
|
|
227
|
+
if (!parsed) {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
const baseEvent = createIncomingBaseEvent(node);
|
|
231
|
+
if (parsed.kind === 'registration_code') {
|
|
232
|
+
options.emitRegistrationCode({
|
|
233
|
+
...baseEvent,
|
|
234
|
+
code: parsed.code,
|
|
235
|
+
expiryTimestampMs: parsed.expiryTimestampMs,
|
|
236
|
+
fromDeviceId: parsed.fromDeviceId
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
options.emitAccountTakeoverNotice({
|
|
241
|
+
...baseEvent,
|
|
242
|
+
serverToken: parsed.serverToken,
|
|
243
|
+
attemptTimestampMs: parsed.attemptTimestampMs,
|
|
244
|
+
newDeviceName: parsed.newDeviceName,
|
|
245
|
+
newDevicePlatform: parsed.newDevicePlatform,
|
|
246
|
+
newDeviceAppVersion: parsed.newDeviceAppVersion
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
await sendSafeAck(options.logger, options.sendNode, buildAckNode({
|
|
250
|
+
kind: 'notification',
|
|
251
|
+
node
|
|
252
|
+
}));
|
|
253
|
+
return true;
|
|
254
|
+
};
|
|
255
|
+
}
|
|
220
256
|
export function createIncomingGroupNotificationHandler(options) {
|
|
221
257
|
return async (node) => {
|
|
222
258
|
if (node.attrs.type !== WA_NOTIFICATION_TYPES.GROUP) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { needsSecretPersistence } from '../message/content.js';
|
|
1
2
|
import { proto } from '../proto.js';
|
|
2
3
|
import { toError } from '../util/primitives.js';
|
|
3
4
|
function persistContacts(writeBehind, event, nowMs) {
|
|
@@ -14,7 +15,7 @@ function persistContacts(writeBehind, event, nowMs) {
|
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
export function persistIncomingMailboxEntities(options) {
|
|
17
|
-
const { logger, writeBehind, event } = options;
|
|
18
|
+
const { logger, writeBehind, messageSecretStore, event } = options;
|
|
18
19
|
const { stanzaId, chatJid } = event;
|
|
19
20
|
if (!stanzaId || !chatJid) {
|
|
20
21
|
return;
|
|
@@ -36,6 +37,21 @@ export function persistIncomingMailboxEntities(options) {
|
|
|
36
37
|
messageBytes
|
|
37
38
|
});
|
|
38
39
|
persistContacts(writeBehind, event, nowMs);
|
|
40
|
+
const rawSecret = event.message?.messageContextInfo?.messageSecret;
|
|
41
|
+
if (rawSecret &&
|
|
42
|
+
rawSecret.length > 0 &&
|
|
43
|
+
event.message &&
|
|
44
|
+
needsSecretPersistence(event.message)) {
|
|
45
|
+
const senderJid = event.senderJid ?? event.rawNode.attrs.participant ?? '';
|
|
46
|
+
void messageSecretStore
|
|
47
|
+
.set(stanzaId, { secret: rawSecret, senderJid })
|
|
48
|
+
.catch((error) => {
|
|
49
|
+
logger.warn('failed to persist message secret', {
|
|
50
|
+
id: stanzaId,
|
|
51
|
+
message: toError(error).message
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
39
55
|
}
|
|
40
56
|
catch (error) {
|
|
41
57
|
logger.warn('failed to persist incoming mailbox entities', {
|