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
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WaPreKeyMemoryStore = void 0;
|
|
4
|
+
const coercion_1 = require("../../../util/coercion");
|
|
5
|
+
const collections_1 = require("../../../util/collections");
|
|
6
|
+
const DEFAULT_MAX_PRE_KEYS = 4096;
|
|
7
|
+
class WaPreKeyMemoryStore {
|
|
8
|
+
constructor(options = {}) {
|
|
9
|
+
this.preKeys = new Map();
|
|
10
|
+
this.uploadedPreKeys = new Set();
|
|
11
|
+
this.serverHasPreKeys = false;
|
|
12
|
+
this.nextPreKeyId = 1;
|
|
13
|
+
this.maxPreKeys = (0, coercion_1.resolvePositive)(options.maxPreKeys, DEFAULT_MAX_PRE_KEYS, 'WaPreKeyMemoryStoreOptions.maxPreKeys');
|
|
14
|
+
}
|
|
15
|
+
async putPreKey(record) {
|
|
16
|
+
(0, collections_1.setBoundedMapEntry)(this.preKeys, record.keyId, record, this.maxPreKeys, (keyId) => {
|
|
17
|
+
this.uploadedPreKeys.delete(keyId);
|
|
18
|
+
});
|
|
19
|
+
if (record.keyId >= this.nextPreKeyId) {
|
|
20
|
+
this.nextPreKeyId = record.keyId + 1;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
async getOrGenPreKeys(count, generator) {
|
|
24
|
+
if (!Number.isSafeInteger(count) || count <= 0) {
|
|
25
|
+
throw new Error(`invalid prekey count: ${count}`);
|
|
26
|
+
}
|
|
27
|
+
const available = [];
|
|
28
|
+
const availableKeyIds = [];
|
|
29
|
+
for (const keyId of this.preKeys.keys()) {
|
|
30
|
+
if (!this.uploadedPreKeys.has(keyId)) {
|
|
31
|
+
availableKeyIds.push(keyId);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
availableKeyIds.sort((left, right) => left - right);
|
|
35
|
+
for (let index = 0; index < availableKeyIds.length; index += 1) {
|
|
36
|
+
const keyId = availableKeyIds[index];
|
|
37
|
+
const record = this.preKeys.get(keyId);
|
|
38
|
+
if (!record) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
available.push(record);
|
|
42
|
+
if (available.length >= count) {
|
|
43
|
+
return available;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
while (available.length < count) {
|
|
47
|
+
const record = await generator(this.nextPreKeyId++);
|
|
48
|
+
(0, collections_1.setBoundedMapEntry)(this.preKeys, record.keyId, record, this.maxPreKeys, (keyId) => {
|
|
49
|
+
this.uploadedPreKeys.delete(keyId);
|
|
50
|
+
});
|
|
51
|
+
available.push(record);
|
|
52
|
+
}
|
|
53
|
+
return available;
|
|
54
|
+
}
|
|
55
|
+
async getPreKeyById(keyId) {
|
|
56
|
+
return this.preKeys.get(keyId) ?? null;
|
|
57
|
+
}
|
|
58
|
+
async getPreKeysById(keyIds) {
|
|
59
|
+
const result = new Array(keyIds.length);
|
|
60
|
+
for (let i = 0; i < keyIds.length; i += 1) {
|
|
61
|
+
result[i] = this.preKeys.get(keyIds[i]) ?? null;
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
async consumePreKeyById(keyId) {
|
|
66
|
+
const record = this.preKeys.get(keyId) ?? null;
|
|
67
|
+
if (!record) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
this.preKeys.delete(keyId);
|
|
71
|
+
this.uploadedPreKeys.delete(keyId);
|
|
72
|
+
return record;
|
|
73
|
+
}
|
|
74
|
+
async getOrGenSinglePreKey(generator) {
|
|
75
|
+
const preKeys = await this.getOrGenPreKeys(1, generator);
|
|
76
|
+
return preKeys[0];
|
|
77
|
+
}
|
|
78
|
+
async markKeyAsUploaded(keyId) {
|
|
79
|
+
if (keyId < 0 || keyId >= this.nextPreKeyId) {
|
|
80
|
+
throw new Error(`prekey ${keyId} is out of boundary`);
|
|
81
|
+
}
|
|
82
|
+
for (const candidate of this.preKeys.keys()) {
|
|
83
|
+
if (candidate <= keyId) {
|
|
84
|
+
this.uploadedPreKeys.add(candidate);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
async setServerHasPreKeys(value) {
|
|
89
|
+
this.serverHasPreKeys = value;
|
|
90
|
+
}
|
|
91
|
+
async getServerHasPreKeys() {
|
|
92
|
+
return this.serverHasPreKeys;
|
|
93
|
+
}
|
|
94
|
+
async clear() {
|
|
95
|
+
this.preKeys.clear();
|
|
96
|
+
this.uploadedPreKeys.clear();
|
|
97
|
+
this.serverHasPreKeys = false;
|
|
98
|
+
this.nextPreKeyId = 1;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.WaPreKeyMemoryStore = WaPreKeyMemoryStore;
|
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WaRetryMemoryStore = void 0;
|
|
4
|
+
const coercion_1 = require("../../../util/coercion");
|
|
4
5
|
const collections_1 = require("../../../util/collections");
|
|
5
|
-
const
|
|
6
|
+
const DEFAULTS = Object.freeze({
|
|
7
|
+
ttlMs: 60 * 1000,
|
|
8
|
+
maxOutboundMessages: 10000,
|
|
9
|
+
maxInboundCounters: 20000
|
|
10
|
+
});
|
|
6
11
|
class WaRetryMemoryStore {
|
|
7
|
-
constructor(ttlMs =
|
|
12
|
+
constructor(ttlMs = DEFAULTS.ttlMs, options = {}) {
|
|
13
|
+
if (!Number.isFinite(ttlMs) || ttlMs <= 0) {
|
|
14
|
+
throw new Error('retry ttlMs must be a positive finite number');
|
|
15
|
+
}
|
|
8
16
|
this.outboundMessages = new Map();
|
|
9
17
|
this.eligibleSets = new Map();
|
|
10
18
|
this.inboundCounters = new Map();
|
|
11
19
|
this.ttlMs = ttlMs;
|
|
20
|
+
this.maxOutboundMessages = (0, coercion_1.resolvePositive)(options.maxOutboundMessages, DEFAULTS.maxOutboundMessages, 'WaRetryMemoryStoreOptions.maxOutboundMessages');
|
|
21
|
+
this.maxInboundCounters = (0, coercion_1.resolvePositive)(options.maxInboundCounters, DEFAULTS.maxInboundCounters, 'WaRetryMemoryStoreOptions.maxInboundCounters');
|
|
12
22
|
this.cleanupTimer = setInterval(() => {
|
|
13
23
|
void this.cleanupExpired(Date.now());
|
|
14
|
-
}, (0, collections_1.resolveCleanupIntervalMs)(ttlMs));
|
|
24
|
+
}, (0, collections_1.resolveCleanupIntervalMs)(this.ttlMs));
|
|
15
25
|
this.cleanupTimer.unref();
|
|
16
26
|
}
|
|
17
27
|
getTtlMs() {
|
|
@@ -57,7 +67,7 @@ class WaRetryMemoryStore {
|
|
|
57
67
|
return { eligible: true, delivered: false };
|
|
58
68
|
}
|
|
59
69
|
async upsertOutboundMessage(record) {
|
|
60
|
-
|
|
70
|
+
const storedRecord = {
|
|
61
71
|
...record,
|
|
62
72
|
eligibleRequesterDeviceJids: record.eligibleRequesterDeviceJids
|
|
63
73
|
? [...record.eligibleRequesterDeviceJids]
|
|
@@ -65,6 +75,9 @@ class WaRetryMemoryStore {
|
|
|
65
75
|
deliveredRequesterDeviceJids: record.deliveredRequesterDeviceJids
|
|
66
76
|
? [...record.deliveredRequesterDeviceJids]
|
|
67
77
|
: undefined
|
|
78
|
+
};
|
|
79
|
+
(0, collections_1.setBoundedMapEntry)(this.outboundMessages, record.messageId, storedRecord, this.maxOutboundMessages, (messageId) => {
|
|
80
|
+
this.eligibleSets.delete(messageId);
|
|
68
81
|
});
|
|
69
82
|
if (record.eligibleRequesterDeviceJids && record.eligibleRequesterDeviceJids.length > 0) {
|
|
70
83
|
this.eligibleSets.set(record.messageId, new Set(record.eligibleRequesterDeviceJids));
|
|
@@ -86,11 +99,13 @@ class WaRetryMemoryStore {
|
|
|
86
99
|
if (!current) {
|
|
87
100
|
return;
|
|
88
101
|
}
|
|
89
|
-
this.outboundMessages
|
|
102
|
+
(0, collections_1.setBoundedMapEntry)(this.outboundMessages, messageId, {
|
|
90
103
|
...current,
|
|
91
104
|
state,
|
|
92
105
|
updatedAtMs,
|
|
93
106
|
expiresAtMs
|
|
107
|
+
}, this.maxOutboundMessages, (evictedMessageId) => {
|
|
108
|
+
this.eligibleSets.delete(evictedMessageId);
|
|
94
109
|
});
|
|
95
110
|
}
|
|
96
111
|
async markOutboundRequesterDelivered(messageId, requesterDeviceJid, updatedAtMs, expiresAtMs) {
|
|
@@ -100,21 +115,20 @@ class WaRetryMemoryStore {
|
|
|
100
115
|
}
|
|
101
116
|
const delivered = new Set(current.deliveredRequesterDeviceJids ?? []);
|
|
102
117
|
delivered.add(requesterDeviceJid);
|
|
103
|
-
this.outboundMessages
|
|
118
|
+
(0, collections_1.setBoundedMapEntry)(this.outboundMessages, messageId, {
|
|
104
119
|
...current,
|
|
105
120
|
deliveredRequesterDeviceJids: Array.from(delivered),
|
|
106
121
|
updatedAtMs,
|
|
107
122
|
expiresAtMs
|
|
123
|
+
}, this.maxOutboundMessages, (evictedMessageId) => {
|
|
124
|
+
this.eligibleSets.delete(evictedMessageId);
|
|
108
125
|
});
|
|
109
126
|
}
|
|
110
127
|
async incrementInboundCounter(messageId, requesterJid, _updatedAtMs, expiresAtMs) {
|
|
111
128
|
const key = this.counterKey(messageId, requesterJid);
|
|
112
129
|
const current = this.inboundCounters.get(key);
|
|
113
130
|
const count = current ? current.count + 1 : 1;
|
|
114
|
-
this.inboundCounters
|
|
115
|
-
count,
|
|
116
|
-
expiresAtMs
|
|
117
|
-
});
|
|
131
|
+
(0, collections_1.setBoundedMapEntry)(this.inboundCounters, key, { count, expiresAtMs }, this.maxInboundCounters);
|
|
118
132
|
return count;
|
|
119
133
|
}
|
|
120
134
|
async cleanupExpired(nowMs) {
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WaSessionMemoryStore = void 0;
|
|
4
|
+
const jid_1 = require("../../../protocol/jid");
|
|
5
|
+
const coercion_1 = require("../../../util/coercion");
|
|
6
|
+
const collections_1 = require("../../../util/collections");
|
|
7
|
+
const DEFAULT_MAX_SESSIONS = 8192;
|
|
8
|
+
class WaSessionMemoryStore {
|
|
9
|
+
constructor(options = {}) {
|
|
10
|
+
this.signalSessions = new Map();
|
|
11
|
+
this.maxSessions = (0, coercion_1.resolvePositive)(options.maxSessions, DEFAULT_MAX_SESSIONS, 'WaSessionMemoryStoreOptions.maxSessions');
|
|
12
|
+
}
|
|
13
|
+
async hasSession(address) {
|
|
14
|
+
return this.signalSessions.has((0, jid_1.signalAddressKey)(address));
|
|
15
|
+
}
|
|
16
|
+
async hasSessions(addresses) {
|
|
17
|
+
const result = new Array(addresses.length);
|
|
18
|
+
for (let i = 0; i < addresses.length; i += 1) {
|
|
19
|
+
result[i] = this.signalSessions.has((0, jid_1.signalAddressKey)(addresses[i]));
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
async getSession(address) {
|
|
24
|
+
return this.signalSessions.get((0, jid_1.signalAddressKey)(address)) ?? null;
|
|
25
|
+
}
|
|
26
|
+
async getSessionsBatch(addresses) {
|
|
27
|
+
const result = new Array(addresses.length);
|
|
28
|
+
for (let i = 0; i < addresses.length; i += 1) {
|
|
29
|
+
result[i] = this.signalSessions.get((0, jid_1.signalAddressKey)(addresses[i])) ?? null;
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
async setSession(address, session) {
|
|
34
|
+
(0, collections_1.setBoundedMapEntry)(this.signalSessions, (0, jid_1.signalAddressKey)(address), session, this.maxSessions);
|
|
35
|
+
}
|
|
36
|
+
async setSessionsBatch(entries) {
|
|
37
|
+
for (let index = 0; index < entries.length; index += 1) {
|
|
38
|
+
const entry = entries[index];
|
|
39
|
+
(0, collections_1.setBoundedMapEntry)(this.signalSessions, (0, jid_1.signalAddressKey)(entry.address), entry.session, this.maxSessions);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async deleteSession(address) {
|
|
43
|
+
this.signalSessions.delete((0, jid_1.signalAddressKey)(address));
|
|
44
|
+
}
|
|
45
|
+
async clear() {
|
|
46
|
+
this.signalSessions.clear();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.WaSessionMemoryStore = WaSessionMemoryStore;
|
|
@@ -1,28 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WaSignalMemoryStore = void 0;
|
|
4
|
-
const jid_1 = require("../../../protocol/jid");
|
|
5
|
-
const coercion_1 = require("../../../util/coercion");
|
|
6
|
-
const collections_1 = require("../../../util/collections");
|
|
7
|
-
const DEFAULT_SIGNAL_STORE_LIMITS = Object.freeze({
|
|
8
|
-
preKeys: 4096,
|
|
9
|
-
sessions: 8192,
|
|
10
|
-
remoteIdentities: 8192
|
|
11
|
-
});
|
|
12
4
|
class WaSignalMemoryStore {
|
|
13
|
-
constructor(
|
|
5
|
+
constructor() {
|
|
14
6
|
this.registrationInfo = null;
|
|
15
7
|
this.signedPreKey = null;
|
|
16
8
|
this.signedPreKeyRotationTs = null;
|
|
17
|
-
this.preKeys = new Map();
|
|
18
|
-
this.uploadedPreKeys = new Set();
|
|
19
|
-
this.serverHasPreKeys = false;
|
|
20
|
-
this.signalSessions = new Map();
|
|
21
|
-
this.remoteIdentities = new Map();
|
|
22
|
-
this.nextPreKeyId = 1;
|
|
23
|
-
this.maxPreKeys = (0, coercion_1.resolvePositive)(options.maxPreKeys, DEFAULT_SIGNAL_STORE_LIMITS.preKeys, 'WaSignalMemoryStoreOptions.maxPreKeys');
|
|
24
|
-
this.maxSessions = (0, coercion_1.resolvePositive)(options.maxSessions, DEFAULT_SIGNAL_STORE_LIMITS.sessions, 'WaSignalMemoryStoreOptions.maxSessions');
|
|
25
|
-
this.maxRemoteIdentities = (0, coercion_1.resolvePositive)(options.maxRemoteIdentities, DEFAULT_SIGNAL_STORE_LIMITS.remoteIdentities, 'WaSignalMemoryStoreOptions.maxRemoteIdentities');
|
|
26
9
|
}
|
|
27
10
|
async getRegistrationInfo() {
|
|
28
11
|
return this.registrationInfo;
|
|
@@ -48,156 +31,10 @@ class WaSignalMemoryStore {
|
|
|
48
31
|
async getSignedPreKeyRotationTs() {
|
|
49
32
|
return this.signedPreKeyRotationTs;
|
|
50
33
|
}
|
|
51
|
-
async putPreKey(record) {
|
|
52
|
-
(0, collections_1.setBoundedMapEntry)(this.preKeys, record.keyId, record, this.maxPreKeys, (keyId) => {
|
|
53
|
-
this.uploadedPreKeys.delete(keyId);
|
|
54
|
-
});
|
|
55
|
-
if (record.keyId >= this.nextPreKeyId) {
|
|
56
|
-
this.nextPreKeyId = record.keyId + 1;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
async getOrGenPreKeys(count, generator) {
|
|
60
|
-
if (!Number.isSafeInteger(count) || count <= 0) {
|
|
61
|
-
throw new Error(`invalid prekey count: ${count}`);
|
|
62
|
-
}
|
|
63
|
-
const available = [];
|
|
64
|
-
const availableKeyIds = [];
|
|
65
|
-
for (const keyId of this.preKeys.keys()) {
|
|
66
|
-
if (!this.uploadedPreKeys.has(keyId)) {
|
|
67
|
-
availableKeyIds.push(keyId);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
availableKeyIds.sort((left, right) => left - right);
|
|
71
|
-
for (let index = 0; index < availableKeyIds.length; index += 1) {
|
|
72
|
-
const keyId = availableKeyIds[index];
|
|
73
|
-
const record = this.preKeys.get(keyId);
|
|
74
|
-
if (!record) {
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
available.push(record);
|
|
78
|
-
if (available.length >= count) {
|
|
79
|
-
return available;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
while (available.length < count) {
|
|
83
|
-
const record = await generator(this.nextPreKeyId++);
|
|
84
|
-
(0, collections_1.setBoundedMapEntry)(this.preKeys, record.keyId, record, this.maxPreKeys, (keyId) => {
|
|
85
|
-
this.uploadedPreKeys.delete(keyId);
|
|
86
|
-
});
|
|
87
|
-
available.push(record);
|
|
88
|
-
}
|
|
89
|
-
return available;
|
|
90
|
-
}
|
|
91
|
-
async getPreKeyById(keyId) {
|
|
92
|
-
return this.preKeys.get(keyId) ?? null;
|
|
93
|
-
}
|
|
94
|
-
async getPreKeysById(keyIds) {
|
|
95
|
-
const result = new Array(keyIds.length);
|
|
96
|
-
for (let i = 0; i < keyIds.length; i += 1) {
|
|
97
|
-
result[i] = this.preKeys.get(keyIds[i]) ?? null;
|
|
98
|
-
}
|
|
99
|
-
return result;
|
|
100
|
-
}
|
|
101
|
-
async consumePreKeyById(keyId) {
|
|
102
|
-
const record = this.preKeys.get(keyId) ?? null;
|
|
103
|
-
if (!record) {
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
this.preKeys.delete(keyId);
|
|
107
|
-
this.uploadedPreKeys.delete(keyId);
|
|
108
|
-
return record;
|
|
109
|
-
}
|
|
110
|
-
async getOrGenSinglePreKey(generator) {
|
|
111
|
-
const preKeys = await this.getOrGenPreKeys(1, generator);
|
|
112
|
-
return preKeys[0];
|
|
113
|
-
}
|
|
114
|
-
async markKeyAsUploaded(keyId) {
|
|
115
|
-
if (keyId < 0 || keyId >= this.nextPreKeyId) {
|
|
116
|
-
throw new Error(`prekey ${keyId} is out of boundary`);
|
|
117
|
-
}
|
|
118
|
-
for (const candidate of this.preKeys.keys()) {
|
|
119
|
-
if (candidate <= keyId) {
|
|
120
|
-
this.addUploadedPreKey(candidate);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
async setServerHasPreKeys(value) {
|
|
125
|
-
this.serverHasPreKeys = value;
|
|
126
|
-
}
|
|
127
|
-
async getServerHasPreKeys() {
|
|
128
|
-
return this.serverHasPreKeys;
|
|
129
|
-
}
|
|
130
|
-
async getSignalMeta() {
|
|
131
|
-
return {
|
|
132
|
-
serverHasPreKeys: this.serverHasPreKeys,
|
|
133
|
-
signedPreKeyRotationTs: this.signedPreKeyRotationTs,
|
|
134
|
-
registrationInfo: this.registrationInfo,
|
|
135
|
-
signedPreKey: this.signedPreKey
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
async hasSession(address) {
|
|
139
|
-
return this.signalSessions.has((0, jid_1.signalAddressKey)(address));
|
|
140
|
-
}
|
|
141
|
-
async hasSessions(addresses) {
|
|
142
|
-
const result = new Array(addresses.length);
|
|
143
|
-
for (let i = 0; i < addresses.length; i += 1) {
|
|
144
|
-
result[i] = this.signalSessions.has((0, jid_1.signalAddressKey)(addresses[i]));
|
|
145
|
-
}
|
|
146
|
-
return result;
|
|
147
|
-
}
|
|
148
|
-
async getSession(address) {
|
|
149
|
-
return this.signalSessions.get((0, jid_1.signalAddressKey)(address)) ?? null;
|
|
150
|
-
}
|
|
151
|
-
async getSessionsBatch(addresses) {
|
|
152
|
-
const result = new Array(addresses.length);
|
|
153
|
-
for (let i = 0; i < addresses.length; i += 1) {
|
|
154
|
-
result[i] = this.signalSessions.get((0, jid_1.signalAddressKey)(addresses[i])) ?? null;
|
|
155
|
-
}
|
|
156
|
-
return result;
|
|
157
|
-
}
|
|
158
|
-
async setSession(address, session) {
|
|
159
|
-
(0, collections_1.setBoundedMapEntry)(this.signalSessions, (0, jid_1.signalAddressKey)(address), session, this.maxSessions);
|
|
160
|
-
}
|
|
161
|
-
async setSessionsBatch(entries) {
|
|
162
|
-
for (let index = 0; index < entries.length; index += 1) {
|
|
163
|
-
const entry = entries[index];
|
|
164
|
-
(0, collections_1.setBoundedMapEntry)(this.signalSessions, (0, jid_1.signalAddressKey)(entry.address), entry.session, this.maxSessions);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
async deleteSession(address) {
|
|
168
|
-
this.signalSessions.delete((0, jid_1.signalAddressKey)(address));
|
|
169
|
-
}
|
|
170
|
-
async getRemoteIdentity(address) {
|
|
171
|
-
return this.remoteIdentities.get((0, jid_1.signalAddressKey)(address)) ?? null;
|
|
172
|
-
}
|
|
173
|
-
async getRemoteIdentities(addresses) {
|
|
174
|
-
const result = new Array(addresses.length);
|
|
175
|
-
for (let i = 0; i < addresses.length; i += 1) {
|
|
176
|
-
result[i] = this.remoteIdentities.get((0, jid_1.signalAddressKey)(addresses[i])) ?? null;
|
|
177
|
-
}
|
|
178
|
-
return result;
|
|
179
|
-
}
|
|
180
|
-
async setRemoteIdentity(address, identityKey) {
|
|
181
|
-
(0, collections_1.setBoundedMapEntry)(this.remoteIdentities, (0, jid_1.signalAddressKey)(address), identityKey, this.maxRemoteIdentities);
|
|
182
|
-
}
|
|
183
|
-
async setRemoteIdentities(entries) {
|
|
184
|
-
for (const entry of entries) {
|
|
185
|
-
(0, collections_1.setBoundedMapEntry)(this.remoteIdentities, (0, jid_1.signalAddressKey)(entry.address), entry.identityKey, this.maxRemoteIdentities);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
34
|
async clear() {
|
|
189
35
|
this.registrationInfo = null;
|
|
190
36
|
this.signedPreKey = null;
|
|
191
37
|
this.signedPreKeyRotationTs = null;
|
|
192
|
-
this.preKeys.clear();
|
|
193
|
-
this.uploadedPreKeys.clear();
|
|
194
|
-
this.serverHasPreKeys = false;
|
|
195
|
-
this.signalSessions.clear();
|
|
196
|
-
this.remoteIdentities.clear();
|
|
197
|
-
this.nextPreKeyId = 1;
|
|
198
|
-
}
|
|
199
|
-
addUploadedPreKey(keyId) {
|
|
200
|
-
this.uploadedPreKeys.add(keyId);
|
|
201
38
|
}
|
|
202
39
|
}
|
|
203
40
|
exports.WaSignalMemoryStore = WaSignalMemoryStore;
|
|
@@ -7,7 +7,6 @@ const constants_1 = require("../protocol/constants");
|
|
|
7
7
|
const WaNoiseSession_1 = require("./noise/WaNoiseSession");
|
|
8
8
|
const WaWebSocket_1 = require("./WaWebSocket");
|
|
9
9
|
const bytes_1 = require("../util/bytes");
|
|
10
|
-
const bytes_2 = require("../util/bytes");
|
|
11
10
|
const primitives_1 = require("../util/primitives");
|
|
12
11
|
const WA_FRAME_HANDLER_QUEUE_MAX_SIZE = 4096;
|
|
13
12
|
const WA_FRAME_HANDLER_MAX_CONCURRENCY = 8;
|
|
@@ -32,7 +31,9 @@ class WaComms {
|
|
|
32
31
|
protocols: this.config.protocols,
|
|
33
32
|
dispatcher: this.config.dispatcher,
|
|
34
33
|
agent: this.config.agent,
|
|
35
|
-
|
|
34
|
+
headers: this.config.headers,
|
|
35
|
+
timeoutIntervalMs: this.config.timeoutIntervalMs,
|
|
36
|
+
rawWebSocketConstructor: this.config.rawWebSocketConstructor
|
|
36
37
|
}, logger);
|
|
37
38
|
this.socket.setHandlers({
|
|
38
39
|
onOpen: async () => {
|
|
@@ -340,7 +341,7 @@ class WaComms {
|
|
|
340
341
|
this.noiseSession = null;
|
|
341
342
|
throw error;
|
|
342
343
|
}
|
|
343
|
-
const buffered = await session.pushWireChunk(
|
|
344
|
+
const buffered = await session.pushWireChunk(bytes_1.EMPTY_BYTES);
|
|
344
345
|
this.routeDecodedFrames(buffered);
|
|
345
346
|
this.resumeHandshakeFailures = 0;
|
|
346
347
|
this.lastServerStaticKey = session.getServerStaticKey();
|
|
@@ -111,7 +111,8 @@ class WaWebSocket {
|
|
|
111
111
|
});
|
|
112
112
|
this.socketUrls = resolveSocketUrls(config);
|
|
113
113
|
this.logger = logger;
|
|
114
|
-
this.webSocketCtor = resolveWebSocketConstructor();
|
|
114
|
+
this.webSocketCtor = config.rawWebSocketConstructor ?? resolveWebSocketConstructor();
|
|
115
|
+
this.customWebSocketCtor = Boolean(config.rawWebSocketConstructor);
|
|
115
116
|
this.socketRuntime = resolveSocketRuntime();
|
|
116
117
|
this.connectingSockets = new Set();
|
|
117
118
|
this.handlers = {};
|
|
@@ -447,6 +448,13 @@ class WaWebSocket {
|
|
|
447
448
|
const headers = this.config.headers;
|
|
448
449
|
const dispatcher = this.config.dispatcher;
|
|
449
450
|
const agent = this.config.agent;
|
|
451
|
+
if (this.customWebSocketCtor) {
|
|
452
|
+
return new this.webSocketCtor(url, this.config.protocols, {
|
|
453
|
+
headers,
|
|
454
|
+
dispatcher,
|
|
455
|
+
agent
|
|
456
|
+
});
|
|
457
|
+
}
|
|
450
458
|
let hasHeaders = false;
|
|
451
459
|
if (headers) {
|
|
452
460
|
for (const key in headers) {
|
package/dist/transport/index.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.queryWithContext = exports.parseIqError = exports.buildIqNode = exports.assertIqResult = exports.WaNodeTransport = exports.WaNodeOrchestrator = exports.WaKeepAlive = exports.WaWebSocket = exports.WaComms = exports.toProxyDispatcher = exports.toProxyAgent = exports.isProxyTransport = exports.isProxyDispatcher = exports.isProxyAgent = void 0;
|
|
3
|
+
exports.queryWithContext = exports.parseIqError = exports.buildIqNode = exports.assertIqResult = exports.buildMobileLoginPayload = exports.WaMobileTcpSocketCtor = exports.WaMobileTcpSocket = exports.WaNodeTransport = exports.WaNodeOrchestrator = exports.WaKeepAlive = exports.WaWebSocket = exports.WaNoiseSocket = exports.WaNoiseHandshake = exports.verifyNoiseCertificateChain = exports.WaComms = exports.toProxyDispatcher = exports.toProxyAgent = exports.isProxyTransport = exports.isProxyDispatcher = exports.isProxyAgent = exports.encodeBinaryNodeStanza = exports.encodeBinaryNode = exports.decodeBinaryNodeStanza = exports.decodeBinaryNode = void 0;
|
|
4
|
+
var binary_1 = require("./binary");
|
|
5
|
+
Object.defineProperty(exports, "decodeBinaryNode", { enumerable: true, get: function () { return binary_1.decodeBinaryNode; } });
|
|
6
|
+
Object.defineProperty(exports, "decodeBinaryNodeStanza", { enumerable: true, get: function () { return binary_1.decodeBinaryNodeStanza; } });
|
|
7
|
+
Object.defineProperty(exports, "encodeBinaryNode", { enumerable: true, get: function () { return binary_1.encodeBinaryNode; } });
|
|
8
|
+
Object.defineProperty(exports, "encodeBinaryNodeStanza", { enumerable: true, get: function () { return binary_1.encodeBinaryNodeStanza; } });
|
|
4
9
|
var proxy_1 = require("./proxy");
|
|
5
10
|
Object.defineProperty(exports, "isProxyAgent", { enumerable: true, get: function () { return proxy_1.isProxyAgent; } });
|
|
6
11
|
Object.defineProperty(exports, "isProxyDispatcher", { enumerable: true, get: function () { return proxy_1.isProxyDispatcher; } });
|
|
@@ -9,6 +14,12 @@ Object.defineProperty(exports, "toProxyAgent", { enumerable: true, get: function
|
|
|
9
14
|
Object.defineProperty(exports, "toProxyDispatcher", { enumerable: true, get: function () { return proxy_1.toProxyDispatcher; } });
|
|
10
15
|
var WaComms_1 = require("./WaComms");
|
|
11
16
|
Object.defineProperty(exports, "WaComms", { enumerable: true, get: function () { return WaComms_1.WaComms; } });
|
|
17
|
+
var WaNoiseCert_1 = require("./noise/WaNoiseCert");
|
|
18
|
+
Object.defineProperty(exports, "verifyNoiseCertificateChain", { enumerable: true, get: function () { return WaNoiseCert_1.verifyNoiseCertificateChain; } });
|
|
19
|
+
var WaNoiseHandshake_1 = require("./noise/WaNoiseHandshake");
|
|
20
|
+
Object.defineProperty(exports, "WaNoiseHandshake", { enumerable: true, get: function () { return WaNoiseHandshake_1.WaNoiseHandshake; } });
|
|
21
|
+
var WaNoiseSocket_1 = require("./noise/WaNoiseSocket");
|
|
22
|
+
Object.defineProperty(exports, "WaNoiseSocket", { enumerable: true, get: function () { return WaNoiseSocket_1.WaNoiseSocket; } });
|
|
12
23
|
var WaWebSocket_1 = require("./WaWebSocket");
|
|
13
24
|
Object.defineProperty(exports, "WaWebSocket", { enumerable: true, get: function () { return WaWebSocket_1.WaWebSocket; } });
|
|
14
25
|
var WaKeepAlive_1 = require("./keepalive/WaKeepAlive");
|
|
@@ -17,6 +28,11 @@ var WaNodeOrchestrator_1 = require("./node/WaNodeOrchestrator");
|
|
|
17
28
|
Object.defineProperty(exports, "WaNodeOrchestrator", { enumerable: true, get: function () { return WaNodeOrchestrator_1.WaNodeOrchestrator; } });
|
|
18
29
|
var WaNodeTransport_1 = require("./node/WaNodeTransport");
|
|
19
30
|
Object.defineProperty(exports, "WaNodeTransport", { enumerable: true, get: function () { return WaNodeTransport_1.WaNodeTransport; } });
|
|
31
|
+
var WaMobileTcpSocket_1 = require("./node/WaMobileTcpSocket");
|
|
32
|
+
Object.defineProperty(exports, "WaMobileTcpSocket", { enumerable: true, get: function () { return WaMobileTcpSocket_1.WaMobileTcpSocket; } });
|
|
33
|
+
Object.defineProperty(exports, "WaMobileTcpSocketCtor", { enumerable: true, get: function () { return WaMobileTcpSocket_1.WaMobileTcpSocketCtor; } });
|
|
34
|
+
var WaMobileClientPayload_1 = require("./noise/WaMobileClientPayload");
|
|
35
|
+
Object.defineProperty(exports, "buildMobileLoginPayload", { enumerable: true, get: function () { return WaMobileClientPayload_1.buildMobileLoginPayload; } });
|
|
20
36
|
var query_1 = require("./node/query");
|
|
21
37
|
Object.defineProperty(exports, "assertIqResult", { enumerable: true, get: function () { return query_1.assertIqResult; } });
|
|
22
38
|
Object.defineProperty(exports, "buildIqNode", { enumerable: true, get: function () { return query_1.buildIqNode; } });
|
|
@@ -11,7 +11,8 @@ class WaKeepAlive {
|
|
|
11
11
|
this.logger = options.logger;
|
|
12
12
|
this.nodeOrchestrator = options.nodeOrchestrator;
|
|
13
13
|
this.getCommsFn = options.getComms;
|
|
14
|
-
this.
|
|
14
|
+
this.baseIntervalMs = options.intervalMs ?? constants_1.WA_DEFAULTS.HEALTH_CHECK_INTERVAL_MS;
|
|
15
|
+
this.getIntervalMs = options.getIntervalMs;
|
|
15
16
|
this.timeoutMs = options.timeoutMs ?? constants_1.WA_DEFAULTS.DEAD_SOCKET_TIMEOUT_MS;
|
|
16
17
|
this.hostDomain = options.hostDomain ?? constants_1.WA_DEFAULTS.HOST_DOMAIN;
|
|
17
18
|
this.jitterRatio = this.normalizeJitterRatio(options.jitterRatio);
|
|
@@ -22,7 +23,7 @@ class WaKeepAlive {
|
|
|
22
23
|
}
|
|
23
24
|
start() {
|
|
24
25
|
this.logger.info('keepalive start', {
|
|
25
|
-
intervalMs: this.
|
|
26
|
+
intervalMs: this.resolveIntervalMs(),
|
|
26
27
|
timeoutMs: this.timeoutMs,
|
|
27
28
|
jitterRatio: this.jitterRatio,
|
|
28
29
|
minJitterMs: this.minJitterMs
|
|
@@ -51,7 +52,7 @@ class WaKeepAlive {
|
|
|
51
52
|
this.logger.trace('keepalive scheduled', {
|
|
52
53
|
generation,
|
|
53
54
|
inMs: nextDelayMs,
|
|
54
|
-
baseIntervalMs: this.
|
|
55
|
+
baseIntervalMs: this.resolveIntervalMs()
|
|
55
56
|
});
|
|
56
57
|
}
|
|
57
58
|
async run(generation) {
|
|
@@ -113,20 +114,28 @@ class WaKeepAlive {
|
|
|
113
114
|
const normalized = value;
|
|
114
115
|
return Math.min(Math.max(normalized, 0), KEEPALIVE_MAX_JITTER_RATIO);
|
|
115
116
|
}
|
|
117
|
+
resolveIntervalMs() {
|
|
118
|
+
const candidate = this.getIntervalMs?.() ?? this.baseIntervalMs;
|
|
119
|
+
if (!Number.isFinite(candidate) || candidate <= 0) {
|
|
120
|
+
return this.baseIntervalMs;
|
|
121
|
+
}
|
|
122
|
+
return candidate;
|
|
123
|
+
}
|
|
116
124
|
computeNextDelayMs() {
|
|
117
|
-
|
|
125
|
+
const intervalMs = this.resolveIntervalMs();
|
|
126
|
+
if (intervalMs <= 0) {
|
|
118
127
|
return 0;
|
|
119
128
|
}
|
|
120
129
|
if (this.jitterRatio <= 0 && this.minJitterMs <= 0) {
|
|
121
|
-
return
|
|
130
|
+
return intervalMs;
|
|
122
131
|
}
|
|
123
|
-
const ratioJitterMs = Math.floor(
|
|
132
|
+
const ratioJitterMs = Math.floor(intervalMs * this.jitterRatio);
|
|
124
133
|
const jitterWindowMs = Math.max(this.minJitterMs, ratioJitterMs);
|
|
125
134
|
if (jitterWindowMs <= 0) {
|
|
126
|
-
return
|
|
135
|
+
return intervalMs;
|
|
127
136
|
}
|
|
128
137
|
const offsetMs = Math.floor(Math.random() * (jitterWindowMs * 2 + 1) - jitterWindowMs);
|
|
129
|
-
return Math.max(1,
|
|
138
|
+
return Math.max(1, intervalMs + offsetMs);
|
|
130
139
|
}
|
|
131
140
|
clearTimer() {
|
|
132
141
|
if (!this.timer) {
|