zapo-js 0.1.0 → 0.1.2
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 -7
- package/dist/appstate/WaAppStateCrypto.js +18 -25
- package/dist/appstate/WaAppStateSyncClient.js +181 -114
- package/dist/appstate/WaAppStateSyncResponseParser.js +16 -5
- package/dist/appstate/constants.js +4 -3
- package/dist/appstate/utils.js +10 -30
- package/dist/auth/WaAuthClient.js +48 -55
- package/dist/auth/flow/WaAuthCredentialsFlow.js +21 -14
- package/dist/auth/index.js +1 -3
- package/dist/auth/pairing/WaPairingFlow.js +21 -23
- package/dist/auth/pairing/WaQrFlow.js +37 -24
- package/dist/client/WaClient.js +103 -276
- package/dist/client/WaClientFactory.js +227 -110
- package/dist/client/connection/WaConnectionManager.js +292 -0
- package/dist/client/connection/WaKeyShareCoordinator.js +63 -0
- package/dist/client/connection/WaReceiptQueue.js +51 -0
- package/dist/client/coordinators/WaAppStateMutationCoordinator.js +471 -0
- package/dist/client/coordinators/WaGroupCoordinator.js +27 -17
- package/dist/client/coordinators/WaIncomingNodeCoordinator.js +20 -27
- package/dist/client/coordinators/WaMessageDispatchCoordinator.js +231 -686
- package/dist/client/coordinators/WaRetryCoordinator.js +70 -37
- package/dist/client/dirty.js +35 -29
- package/dist/client/events/chat.js +4 -3
- package/dist/client/events/group.js +59 -36
- package/dist/client/history-sync.js +53 -63
- package/dist/client/incoming.js +23 -20
- package/dist/client/mailbox.js +8 -8
- package/dist/client/messages.js +4 -4
- package/dist/client/messaging/fanout.js +189 -0
- package/dist/client/messaging/key-protocol.js +130 -0
- package/dist/client/messaging/participants.js +191 -0
- package/dist/crypto/core/hkdf.js +3 -8
- package/dist/crypto/core/index.js +1 -4
- package/dist/crypto/core/keys.js +2 -3
- package/dist/crypto/core/primitives.js +12 -15
- package/dist/crypto/core/random.js +7 -26
- package/dist/crypto/curves/Ed25519.js +7 -8
- package/dist/crypto/curves/X25519.js +13 -16
- package/dist/crypto/index.js +0 -5
- package/dist/esm/appstate/WaAppStateCrypto.js +6 -13
- package/dist/esm/appstate/WaAppStateSyncClient.js +174 -107
- package/dist/esm/appstate/WaAppStateSyncResponseParser.js +17 -6
- package/dist/esm/appstate/constants.js +3 -2
- package/dist/esm/appstate/utils.js +8 -27
- package/dist/esm/auth/WaAuthClient.js +48 -55
- package/dist/esm/auth/flow/WaAuthCredentialsFlow.js +21 -14
- package/dist/esm/auth/index.js +0 -1
- package/dist/esm/auth/pairing/WaPairingFlow.js +14 -16
- package/dist/esm/auth/pairing/WaQrFlow.js +37 -24
- package/dist/esm/client/WaClient.js +103 -276
- package/dist/esm/client/WaClientFactory.js +227 -110
- package/dist/esm/client/connection/WaConnectionManager.js +288 -0
- package/dist/esm/client/connection/WaKeyShareCoordinator.js +59 -0
- package/dist/esm/client/connection/WaReceiptQueue.js +47 -0
- package/dist/esm/client/coordinators/WaAppStateMutationCoordinator.js +467 -0
- package/dist/esm/client/coordinators/WaGroupCoordinator.js +20 -10
- package/dist/esm/client/coordinators/WaIncomingNodeCoordinator.js +20 -27
- package/dist/esm/client/coordinators/WaMessageDispatchCoordinator.js +232 -687
- package/dist/esm/client/coordinators/WaRetryCoordinator.js +71 -38
- package/dist/esm/client/dirty.js +30 -24
- package/dist/esm/client/events/chat.js +4 -3
- package/dist/esm/client/events/group.js +50 -28
- package/dist/esm/client/history-sync.js +50 -60
- package/dist/esm/client/incoming.js +23 -20
- package/dist/esm/client/mailbox.js +8 -8
- package/dist/esm/client/messages.js +1 -1
- package/dist/esm/client/messaging/fanout.js +186 -0
- package/dist/esm/client/messaging/key-protocol.js +127 -0
- package/dist/esm/client/messaging/participants.js +188 -0
- package/dist/esm/crypto/core/hkdf.js +3 -8
- package/dist/esm/crypto/core/index.js +0 -1
- package/dist/esm/crypto/core/keys.js +2 -3
- package/dist/esm/crypto/core/primitives.js +12 -15
- package/dist/esm/crypto/core/random.js +6 -25
- package/dist/esm/crypto/curves/Ed25519.js +4 -5
- package/dist/esm/crypto/curves/X25519.js +10 -13
- package/dist/esm/crypto/index.js +0 -2
- package/dist/esm/infra/log/ConsoleLogger.js +18 -17
- package/dist/esm/infra/log/PinoLogger.js +15 -9
- package/dist/esm/infra/log/types.js +11 -1
- package/dist/esm/infra/perf/BoundedTaskQueue.js +13 -17
- package/dist/esm/media/WaMediaCrypto.js +2 -4
- package/dist/esm/media/WaMediaTransferClient.js +226 -58
- package/dist/esm/media/conn.js +10 -6
- package/dist/esm/media/constants.js +4 -1
- package/dist/esm/message/WaMessageClient.js +4 -13
- package/dist/esm/message/ack.js +6 -6
- package/dist/esm/message/addon-crypto.js +59 -0
- package/dist/esm/message/incoming.js +106 -111
- package/dist/esm/message/index.js +2 -0
- package/dist/esm/message/reporting-token.js +438 -0
- package/dist/esm/message/use-case-secret.js +49 -0
- package/dist/esm/protocol/appstate.js +58 -0
- package/dist/esm/protocol/constants.js +2 -1
- package/dist/esm/protocol/index.js +2 -10
- package/dist/esm/protocol/jid.js +63 -51
- package/dist/esm/protocol/media.js +3 -3
- package/dist/esm/protocol/nodes.js +2 -0
- package/dist/esm/protocol/usync.js +11 -0
- package/dist/esm/retry/index.js +1 -0
- package/dist/esm/retry/outbound.js +4 -5
- package/dist/esm/retry/parse.js +58 -76
- package/dist/esm/retry/replay.js +48 -49
- package/dist/esm/retry/tracker.js +56 -0
- package/dist/esm/signal/api/SignalDeviceSyncApi.js +249 -82
- package/dist/esm/signal/api/SignalDigestSyncApi.js +6 -1
- package/dist/esm/signal/api/SignalIdentitySyncApi.js +49 -34
- package/dist/esm/signal/api/SignalMissingPreKeysSyncApi.js +70 -62
- package/dist/esm/signal/api/SignalSessionSyncApi.js +23 -30
- package/dist/esm/signal/crypto/WaAdvSignature.js +3 -5
- package/dist/esm/signal/group/SenderKeyChain.js +28 -23
- package/dist/esm/signal/group/SenderKeyCodec.js +2 -4
- package/dist/esm/signal/group/SenderKeyManager.js +26 -16
- package/dist/esm/signal/index.js +1 -0
- package/dist/esm/signal/session/SignalProtocol.js +49 -14
- package/dist/esm/signal/session/SignalRatchet.js +24 -15
- package/dist/esm/signal/session/SignalSession.js +14 -9
- package/dist/esm/signal/session/resolver.js +186 -0
- package/dist/esm/signal/store/sqlite.js +16 -37
- package/dist/esm/store/createStore.js +16 -18
- package/dist/esm/store/noop.store.js +3 -6
- package/dist/esm/store/providers/memory/appstate.store.js +30 -6
- package/dist/esm/store/providers/memory/contact.store.js +5 -0
- package/dist/esm/store/providers/memory/device-list.store.js +3 -30
- package/dist/esm/store/providers/memory/message.store.js +11 -5
- package/dist/esm/store/providers/memory/participants.store.js +1 -8
- package/dist/esm/store/providers/memory/sender-key.store.js +5 -7
- package/dist/esm/store/providers/memory/signal.store.js +13 -1
- package/dist/esm/store/providers/memory/thread.store.js +5 -0
- package/dist/esm/store/providers/sqlite/appstate.store.js +82 -1
- package/dist/esm/store/providers/sqlite/connection.js +18 -13
- package/dist/esm/store/providers/sqlite/contact.store.js +31 -18
- package/dist/esm/store/providers/sqlite/device-list.store.js +7 -35
- package/dist/esm/store/providers/sqlite/message.store.js +45 -32
- package/dist/esm/store/providers/sqlite/migrations.js +1 -1
- package/dist/esm/store/providers/sqlite/participants.store.js +1 -9
- package/dist/esm/store/providers/sqlite/retry.store.js +8 -11
- package/dist/esm/store/providers/sqlite/sender-key.store.js +25 -30
- package/dist/esm/store/providers/sqlite/signal.store.js +104 -22
- package/dist/esm/store/providers/sqlite/table-names.js +107 -0
- package/dist/esm/store/providers/sqlite/thread.store.js +35 -22
- package/dist/esm/transport/WaComms.js +25 -23
- package/dist/esm/transport/WaWebSocket.js +115 -12
- package/dist/esm/transport/binary/decoder.js +4 -4
- package/dist/esm/transport/binary/encoder.js +12 -4
- package/dist/esm/transport/index.js +1 -0
- package/dist/esm/transport/keepalive/WaKeepAlive.js +2 -8
- package/dist/esm/transport/node/WaNodeOrchestrator.js +2 -4
- package/dist/esm/transport/node/WaNodeTransport.js +0 -3
- package/dist/esm/transport/node/builders/{accountSync.js → account-sync.js} +16 -36
- package/dist/esm/transport/node/builders/index.js +2 -1
- package/dist/esm/transport/node/builders/message.js +9 -0
- package/dist/esm/transport/node/builders/pairing.js +4 -5
- package/dist/esm/transport/node/builders/usync.js +41 -0
- package/dist/esm/transport/node/helpers.js +107 -5
- package/dist/esm/transport/node/usync.js +35 -0
- package/dist/esm/transport/noise/WaFrameCodec.js +48 -33
- package/dist/esm/transport/noise/WaNoiseCert.js +3 -6
- package/dist/esm/transport/noise/WaNoiseSession.js +17 -10
- package/dist/esm/transport/proxy.js +27 -0
- package/dist/esm/transport/stream/parse.js +13 -48
- package/dist/esm/util/bytes.js +50 -32
- package/dist/esm/util/coercion.js +6 -14
- package/dist/esm/util/primitives.js +39 -14
- package/dist/infra/log/ConsoleLogger.js +18 -17
- package/dist/infra/log/PinoLogger.js +15 -9
- package/dist/infra/log/types.js +12 -0
- package/dist/infra/perf/BoundedTaskQueue.js +13 -17
- package/dist/media/WaMediaCrypto.js +1 -3
- package/dist/media/WaMediaTransferClient.js +259 -58
- package/dist/media/conn.js +10 -6
- package/dist/media/constants.js +4 -1
- package/dist/message/WaMessageClient.js +5 -14
- package/dist/message/ack.js +6 -6
- package/dist/message/addon-crypto.js +65 -0
- package/dist/message/incoming.js +104 -109
- package/dist/message/index.js +2 -0
- package/dist/message/reporting-token.js +443 -0
- package/dist/message/use-case-secret.js +55 -0
- package/dist/protocol/appstate.js +59 -1
- package/dist/protocol/constants.js +7 -1
- package/dist/protocol/index.js +20 -42
- package/dist/protocol/jid.js +64 -51
- package/dist/protocol/media.js +3 -3
- package/dist/protocol/nodes.js +2 -0
- package/dist/protocol/usync.js +14 -0
- package/dist/retry/index.js +3 -1
- package/dist/retry/outbound.js +6 -7
- package/dist/retry/parse.js +57 -75
- package/dist/retry/replay.js +46 -47
- package/dist/retry/tracker.js +59 -0
- package/dist/signal/api/SignalDeviceSyncApi.js +247 -80
- package/dist/signal/api/SignalDigestSyncApi.js +6 -1
- package/dist/signal/api/SignalIdentitySyncApi.js +49 -34
- package/dist/signal/api/SignalMissingPreKeysSyncApi.js +67 -59
- package/dist/signal/api/SignalSessionSyncApi.js +23 -30
- package/dist/signal/crypto/WaAdvSignature.js +2 -4
- package/dist/signal/group/SenderKeyChain.js +27 -22
- package/dist/signal/group/SenderKeyCodec.js +1 -3
- package/dist/signal/group/SenderKeyManager.js +26 -16
- package/dist/signal/index.js +3 -1
- package/dist/signal/session/SignalProtocol.js +49 -14
- package/dist/signal/session/SignalRatchet.js +24 -15
- package/dist/signal/session/SignalSession.js +14 -9
- package/dist/signal/session/resolver.js +189 -0
- package/dist/signal/store/sqlite.js +16 -37
- package/dist/store/createStore.js +16 -18
- package/dist/store/noop.store.js +3 -6
- package/dist/store/providers/memory/appstate.store.js +28 -4
- package/dist/store/providers/memory/contact.store.js +5 -0
- package/dist/store/providers/memory/device-list.store.js +3 -30
- package/dist/store/providers/memory/message.store.js +11 -5
- package/dist/store/providers/memory/participants.store.js +1 -8
- package/dist/store/providers/memory/sender-key.store.js +8 -10
- package/dist/store/providers/memory/signal.store.js +21 -9
- package/dist/store/providers/memory/thread.store.js +5 -0
- package/dist/store/providers/sqlite/appstate.store.js +81 -0
- package/dist/store/providers/sqlite/connection.js +18 -13
- package/dist/store/providers/sqlite/contact.store.js +31 -18
- package/dist/store/providers/sqlite/device-list.store.js +7 -35
- package/dist/store/providers/sqlite/message.store.js +45 -32
- package/dist/store/providers/sqlite/migrations.js +1 -1
- package/dist/store/providers/sqlite/participants.store.js +1 -9
- package/dist/store/providers/sqlite/retry.store.js +8 -11
- package/dist/store/providers/sqlite/sender-key.store.js +24 -29
- package/dist/store/providers/sqlite/signal.store.js +105 -23
- package/dist/store/providers/sqlite/table-names.js +113 -0
- package/dist/store/providers/sqlite/thread.store.js +35 -22
- package/dist/transport/WaComms.js +27 -25
- package/dist/transport/WaWebSocket.js +148 -12
- package/dist/transport/binary/decoder.js +4 -4
- package/dist/transport/binary/encoder.js +12 -4
- package/dist/transport/index.js +7 -1
- package/dist/transport/keepalive/WaKeepAlive.js +1 -7
- package/dist/transport/node/WaNodeOrchestrator.js +2 -4
- package/dist/transport/node/WaNodeTransport.js +0 -3
- package/dist/transport/node/builders/{accountSync.js → account-sync.js} +15 -35
- package/dist/transport/node/builders/index.js +12 -9
- package/dist/transport/node/builders/message.js +9 -0
- package/dist/transport/node/builders/pairing.js +4 -5
- package/dist/transport/node/builders/usync.js +45 -0
- package/dist/transport/node/helpers.js +112 -4
- package/dist/transport/node/usync.js +38 -0
- package/dist/transport/noise/WaFrameCodec.js +47 -32
- package/dist/transport/noise/WaNoiseCert.js +5 -8
- package/dist/transport/noise/WaNoiseSession.js +17 -10
- package/dist/transport/proxy.js +34 -0
- package/dist/transport/stream/parse.js +17 -53
- package/dist/types/appstate/WaAppStateCrypto.d.ts +0 -1
- package/dist/types/appstate/WaAppStateSyncClient.d.ts +5 -2
- package/dist/types/appstate/constants.d.ts +1 -0
- package/dist/types/appstate/store/sqlite.d.ts +4 -18
- package/dist/types/appstate/utils.d.ts +0 -1
- package/dist/types/auth/WaAuthClient.d.ts +10 -12
- package/dist/types/auth/index.d.ts +0 -2
- package/dist/types/auth/pairing/WaQrFlow.d.ts +1 -1
- package/dist/types/auth/types.d.ts +6 -9
- package/dist/types/client/WaClient.d.ts +27 -25
- package/dist/types/client/WaClientFactory.d.ts +22 -23
- package/dist/types/client/connection/WaConnectionManager.d.ts +64 -0
- package/dist/types/client/connection/WaKeyShareCoordinator.d.ts +14 -0
- package/dist/types/client/connection/WaReceiptQueue.d.ts +13 -0
- package/dist/types/client/coordinators/WaAppStateMutationCoordinator.d.ts +46 -0
- package/dist/types/client/coordinators/WaIncomingNodeCoordinator.d.ts +0 -1
- package/dist/types/client/coordinators/WaMessageDispatchCoordinator.d.ts +18 -41
- package/dist/types/client/coordinators/WaRetryCoordinator.d.ts +2 -0
- package/dist/types/client/dirty.d.ts +1 -0
- package/dist/types/client/events/group.d.ts +2 -1
- package/dist/types/client/index.d.ts +1 -1
- package/dist/types/client/messaging/fanout.d.ts +14 -0
- package/dist/types/client/messaging/key-protocol.d.ts +18 -0
- package/dist/types/client/messaging/participants.d.ts +13 -0
- package/dist/types/client/types.d.ts +24 -1
- package/dist/types/crypto/core/hkdf.d.ts +0 -6
- package/dist/types/crypto/core/index.d.ts +0 -1
- package/dist/types/crypto/core/random.d.ts +1 -7
- package/dist/types/crypto/index.d.ts +0 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/infra/log/ConsoleLogger.d.ts +2 -1
- package/dist/types/infra/log/PinoLogger.d.ts +1 -1
- package/dist/types/infra/log/types.d.ts +1 -0
- package/dist/types/infra/perf/BoundedTaskQueue.d.ts +1 -1
- package/dist/types/media/WaMediaTransferClient.d.ts +13 -3
- package/dist/types/media/types.d.ts +5 -0
- package/dist/types/message/addon-crypto.d.ts +25 -0
- package/dist/types/message/index.d.ts +2 -0
- package/dist/types/message/reporting-token.d.ts +19 -0
- package/dist/types/message/use-case-secret.d.ts +20 -0
- package/dist/types/protocol/appstate.d.ts +58 -0
- package/dist/types/protocol/constants.d.ts +2 -1
- package/dist/types/protocol/index.d.ts +2 -10
- package/dist/types/protocol/jid.d.ts +3 -3
- package/dist/types/protocol/nodes.d.ts +2 -0
- package/dist/types/protocol/usync.d.ts +11 -0
- package/dist/types/retry/index.d.ts +1 -0
- package/dist/types/retry/replay.d.ts +0 -4
- package/dist/types/retry/tracker.d.ts +19 -0
- package/dist/types/retry/types.d.ts +4 -3
- package/dist/types/signal/api/SignalDeviceSyncApi.d.ts +13 -1
- package/dist/types/signal/group/SenderKeyCodec.d.ts +4 -6
- package/dist/types/signal/index.d.ts +1 -0
- package/dist/types/signal/session/SignalProtocol.d.ts +9 -0
- package/dist/types/signal/session/resolver.d.ts +17 -0
- package/dist/types/store/contracts/appstate.store.d.ts +3 -0
- package/dist/types/store/contracts/contact.store.d.ts +1 -0
- package/dist/types/store/contracts/device-list.store.d.ts +0 -3
- package/dist/types/store/contracts/message.store.d.ts +1 -0
- package/dist/types/store/contracts/participants.store.d.ts +0 -1
- package/dist/types/store/contracts/sender-key.store.d.ts +0 -1
- package/dist/types/store/contracts/signal.store.d.ts +6 -0
- package/dist/types/store/contracts/thread.store.d.ts +1 -0
- package/dist/types/store/index.d.ts +1 -1
- package/dist/types/store/providers/memory/appstate.store.d.ts +2 -0
- package/dist/types/store/providers/memory/contact.store.d.ts +1 -0
- package/dist/types/store/providers/memory/device-list.store.d.ts +0 -3
- package/dist/types/store/providers/memory/message.store.d.ts +1 -0
- package/dist/types/store/providers/memory/participants.store.d.ts +0 -1
- package/dist/types/store/providers/memory/sender-key.store.d.ts +0 -1
- package/dist/types/store/providers/memory/signal.store.d.ts +6 -0
- package/dist/types/store/providers/memory/thread.store.d.ts +1 -0
- package/dist/types/store/providers/sqlite/appstate.store.d.ts +2 -0
- package/dist/types/store/providers/sqlite/contact.store.d.ts +2 -0
- package/dist/types/store/providers/sqlite/device-list.store.d.ts +0 -3
- package/dist/types/store/providers/sqlite/message.store.d.ts +2 -0
- package/dist/types/store/providers/sqlite/participants.store.d.ts +0 -1
- package/dist/types/store/providers/sqlite/retry.store.d.ts +0 -1
- package/dist/types/store/providers/sqlite/sender-key.store.d.ts +0 -1
- package/dist/types/store/providers/sqlite/signal.store.d.ts +7 -0
- package/dist/types/store/providers/sqlite/table-names.d.ts +5 -0
- package/dist/types/store/providers/sqlite/thread.store.d.ts +2 -0
- package/dist/types/store/types.d.ts +3 -0
- package/dist/types/transport/WaWebSocket.d.ts +3 -0
- package/dist/types/transport/index.d.ts +2 -1
- package/dist/types/transport/keepalive/WaKeepAlive.d.ts +0 -1
- package/dist/types/transport/node/WaNodeTransport.d.ts +0 -9
- package/dist/types/transport/node/builders/group.d.ts +4 -6
- package/dist/types/transport/node/builders/index.d.ts +2 -1
- package/dist/types/transport/node/builders/message.d.ts +14 -25
- package/dist/types/transport/node/builders/retry.d.ts +2 -4
- package/dist/types/transport/node/builders/usync.d.ts +21 -0
- package/dist/types/transport/node/helpers.d.ts +8 -0
- package/dist/types/transport/node/usync.d.ts +2 -0
- package/dist/types/transport/noise/WaFrameCodec.d.ts +3 -0
- package/dist/types/transport/noise/WaNoiseSession.d.ts +1 -0
- package/dist/types/transport/proxy.d.ts +6 -0
- package/dist/types/transport/stream/parse.d.ts +0 -1
- package/dist/types/transport/types.d.ts +18 -1
- package/dist/types/util/bytes.d.ts +5 -0
- package/dist/types/util/primitives.d.ts +3 -0
- package/dist/util/bytes.js +55 -33
- package/dist/util/coercion.js +6 -14
- package/dist/util/primitives.js +42 -14
- package/package.json +27 -9
- package/proto/index.d.ts +1090 -1048
- package/proto/index.js +1 -1
- package/scripts/check-node-version.cjs +0 -1
- package/dist/crypto/core/encoding.js +0 -29
- package/dist/esm/crypto/core/encoding.js +0 -25
- package/dist/esm/util/base64.js +0 -18
- package/dist/esm/util/signal-address.js +0 -5
- package/dist/types/crypto/core/encoding.d.ts +0 -11
- package/dist/types/util/base64.d.ts +0 -4
- package/dist/types/util/signal-address.d.ts +0 -2
- package/dist/util/base64.js +0 -24
- package/dist/util/signal-address.js +0 -8
- /package/dist/types/transport/node/builders/{accountSync.d.ts → account-sync.d.ts} +0 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSignalSessionResolver = createSignalSessionResolver;
|
|
4
|
+
const keys_1 = require("../../crypto/core/keys");
|
|
5
|
+
const jid_1 = require("../../protocol/jid");
|
|
6
|
+
const bytes_1 = require("../../util/bytes");
|
|
7
|
+
const primitives_1 = require("../../util/primitives");
|
|
8
|
+
function createSignalSessionResolver(options) {
|
|
9
|
+
const { signalProtocol, signalStore, signalIdentitySync, signalSessionSync, logger } = options;
|
|
10
|
+
const ensureSession = async (address, jid, expectedIdentity, reasonIdentity = false) => {
|
|
11
|
+
const expectedSerializedIdentity = expectedIdentity
|
|
12
|
+
? (0, keys_1.toSerializedPubKey)(expectedIdentity)
|
|
13
|
+
: null;
|
|
14
|
+
if (reasonIdentity) {
|
|
15
|
+
await signalIdentitySync.syncIdentityKeys([jid]);
|
|
16
|
+
}
|
|
17
|
+
if (await signalProtocol.hasSession(address)) {
|
|
18
|
+
if (expectedSerializedIdentity) {
|
|
19
|
+
const storedIdentity = await signalStore.getRemoteIdentity(address);
|
|
20
|
+
if (!storedIdentity || !(0, bytes_1.uint8Equal)(storedIdentity, expectedSerializedIdentity)) {
|
|
21
|
+
throw new Error('identity mismatch');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
logger.info('signal session missing, fetching remote key bundle', { jid });
|
|
27
|
+
const fetched = await signalSessionSync.fetchKeyBundle({
|
|
28
|
+
jid,
|
|
29
|
+
reasonIdentity
|
|
30
|
+
});
|
|
31
|
+
const remoteIdentity = (0, keys_1.toSerializedPubKey)(fetched.bundle.identity);
|
|
32
|
+
if (reasonIdentity) {
|
|
33
|
+
const storedIdentity = await signalStore.getRemoteIdentity(address);
|
|
34
|
+
if (storedIdentity && !(0, bytes_1.uint8Equal)(remoteIdentity, storedIdentity)) {
|
|
35
|
+
throw new Error('identity mismatch');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (expectedSerializedIdentity && !(0, bytes_1.uint8Equal)(remoteIdentity, expectedSerializedIdentity)) {
|
|
39
|
+
throw new Error('identity mismatch');
|
|
40
|
+
}
|
|
41
|
+
await signalProtocol.establishOutgoingSession(address, fetched.bundle);
|
|
42
|
+
logger.info('signal session synchronized', {
|
|
43
|
+
jid,
|
|
44
|
+
regId: fetched.bundle.regId,
|
|
45
|
+
hasOneTimeKey: fetched.bundle.oneTimeKey !== undefined
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
const ensureSessionsBatch = async (targetJids, expectedIdentityByJid) => {
|
|
49
|
+
const seenTargetJids = new Set();
|
|
50
|
+
const normalizedTargetJids = [];
|
|
51
|
+
const normalizedTargetAddresses = [];
|
|
52
|
+
for (let index = 0; index < targetJids.length; index += 1) {
|
|
53
|
+
const jid = (0, jid_1.normalizeDeviceJid)(targetJids[index]);
|
|
54
|
+
if (seenTargetJids.has(jid)) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
seenTargetJids.add(jid);
|
|
58
|
+
normalizedTargetJids.push(jid);
|
|
59
|
+
normalizedTargetAddresses.push((0, jid_1.parseSignalAddressFromJid)(jid));
|
|
60
|
+
}
|
|
61
|
+
if (normalizedTargetJids.length === 0) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const normalizedExpectedIdentityByJid = expectedIdentityByJid && expectedIdentityByJid.size > 0
|
|
65
|
+
? new Map()
|
|
66
|
+
: undefined;
|
|
67
|
+
if (normalizedExpectedIdentityByJid && expectedIdentityByJid) {
|
|
68
|
+
for (const [jid, identity] of expectedIdentityByJid.entries()) {
|
|
69
|
+
try {
|
|
70
|
+
normalizedExpectedIdentityByJid.set((0, jid_1.normalizeDeviceJid)(jid), identity);
|
|
71
|
+
}
|
|
72
|
+
catch (error) {
|
|
73
|
+
logger.trace('ignoring malformed expected identity jid during batch normalization', { jid, message: (0, primitives_1.toError)(error).message });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const hasSessions = await signalProtocol.hasSessions(normalizedTargetAddresses);
|
|
78
|
+
if (normalizedExpectedIdentityByJid) {
|
|
79
|
+
const identityAddresses = [];
|
|
80
|
+
const expectedSerializedIdentities = [];
|
|
81
|
+
for (let index = 0; index < normalizedTargetJids.length; index += 1) {
|
|
82
|
+
if (!hasSessions[index]) {
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const expectedIdentity = normalizedExpectedIdentityByJid.get(normalizedTargetJids[index]);
|
|
86
|
+
if (!expectedIdentity) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
identityAddresses.push(normalizedTargetAddresses[index]);
|
|
90
|
+
expectedSerializedIdentities.push((0, keys_1.toSerializedPubKey)(expectedIdentity));
|
|
91
|
+
}
|
|
92
|
+
const storedIdentities = await signalStore.getRemoteIdentities(identityAddresses);
|
|
93
|
+
for (let index = 0; index < storedIdentities.length; index += 1) {
|
|
94
|
+
const storedIdentity = storedIdentities[index];
|
|
95
|
+
if (!storedIdentity ||
|
|
96
|
+
!(0, bytes_1.uint8Equal)(storedIdentity, expectedSerializedIdentities[index])) {
|
|
97
|
+
throw new Error('identity mismatch');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const missingIndices = [];
|
|
102
|
+
for (let index = 0; index < normalizedTargetJids.length; index += 1) {
|
|
103
|
+
if (!hasSessions[index]) {
|
|
104
|
+
missingIndices.push(index);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (missingIndices.length === 0) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
try {
|
|
111
|
+
const batchRequest = [];
|
|
112
|
+
for (let index = 0; index < missingIndices.length; index += 1) {
|
|
113
|
+
batchRequest.push({ jid: normalizedTargetJids[missingIndices[index]] });
|
|
114
|
+
}
|
|
115
|
+
const batchResults = await signalSessionSync.fetchKeyBundles(batchRequest);
|
|
116
|
+
const fallbackIndices = [];
|
|
117
|
+
const establishedIndices = [];
|
|
118
|
+
const establishPromises = [];
|
|
119
|
+
for (let index = 0; index < missingIndices.length; index += 1) {
|
|
120
|
+
const targetIndex = missingIndices[index];
|
|
121
|
+
const result = batchResults[index];
|
|
122
|
+
if (!result || !('bundle' in result)) {
|
|
123
|
+
fallbackIndices.push(targetIndex);
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const targetJid = normalizedTargetJids[targetIndex];
|
|
127
|
+
const expectedIdentity = normalizedExpectedIdentityByJid?.get(targetJid);
|
|
128
|
+
const remoteIdentity = (0, keys_1.toSerializedPubKey)(result.bundle.identity);
|
|
129
|
+
if (expectedIdentity &&
|
|
130
|
+
!(0, bytes_1.uint8Equal)(remoteIdentity, (0, keys_1.toSerializedPubKey)(expectedIdentity))) {
|
|
131
|
+
throw new Error('identity mismatch');
|
|
132
|
+
}
|
|
133
|
+
establishedIndices.push(targetIndex);
|
|
134
|
+
establishPromises.push(signalProtocol
|
|
135
|
+
.establishOutgoingSession(normalizedTargetAddresses[targetIndex], result.bundle)
|
|
136
|
+
.then(() => {
|
|
137
|
+
logger.debug('signal session synchronized from batch key fetch', {
|
|
138
|
+
jid: targetJid,
|
|
139
|
+
regId: result.bundle.regId,
|
|
140
|
+
hasOneTimeKey: result.bundle.oneTimeKey !== undefined
|
|
141
|
+
});
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
const establishmentResults = await Promise.allSettled(establishPromises);
|
|
145
|
+
for (let index = 0; index < establishmentResults.length; index += 1) {
|
|
146
|
+
const result = establishmentResults[index];
|
|
147
|
+
if (result.status === 'fulfilled') {
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
const error = (0, primitives_1.toError)(result.reason);
|
|
151
|
+
if (error.message === 'identity mismatch') {
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
154
|
+
fallbackIndices.push(establishedIndices[index]);
|
|
155
|
+
}
|
|
156
|
+
if (fallbackIndices.length === 0) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
logger.warn('signal batch key fetch returned partial errors, falling back to single requests', {
|
|
160
|
+
requested: missingIndices.length,
|
|
161
|
+
fallbackTargets: fallbackIndices.length
|
|
162
|
+
});
|
|
163
|
+
for (let index = 0; index < fallbackIndices.length; index += 1) {
|
|
164
|
+
const targetIndex = fallbackIndices[index];
|
|
165
|
+
const jid = normalizedTargetJids[targetIndex];
|
|
166
|
+
await ensureSession(normalizedTargetAddresses[targetIndex], jid, normalizedExpectedIdentityByJid?.get(jid));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
const normalized = (0, primitives_1.toError)(error);
|
|
171
|
+
if (normalized.message === 'identity mismatch') {
|
|
172
|
+
throw normalized;
|
|
173
|
+
}
|
|
174
|
+
logger.warn('signal batch key fetch failed, falling back to single requests', {
|
|
175
|
+
requested: missingIndices.length,
|
|
176
|
+
message: normalized.message
|
|
177
|
+
});
|
|
178
|
+
for (let index = 0; index < missingIndices.length; index += 1) {
|
|
179
|
+
const targetIndex = missingIndices[index];
|
|
180
|
+
const jid = normalizedTargetJids[targetIndex];
|
|
181
|
+
await ensureSession(normalizedTargetAddresses[targetIndex], jid, normalizedExpectedIdentityByJid?.get(jid));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
return {
|
|
186
|
+
ensureSession,
|
|
187
|
+
ensureSessionsBatch
|
|
188
|
+
};
|
|
189
|
+
}
|
|
@@ -14,6 +14,7 @@ exports.decodeSqliteCount = decodeSqliteCount;
|
|
|
14
14
|
exports.decodeSignalRemoteIdentity = decodeSignalRemoteIdentity;
|
|
15
15
|
const _proto_1 = require("../../proto.js");
|
|
16
16
|
const constants_1 = require("../../protocol/constants");
|
|
17
|
+
const bytes_1 = require("../../util/bytes");
|
|
17
18
|
const coercion_1 = require("../../util/coercion");
|
|
18
19
|
function toSignalAddressParts(address) {
|
|
19
20
|
return {
|
|
@@ -108,17 +109,11 @@ function encodeSignalRecvChain(chain) {
|
|
|
108
109
|
}
|
|
109
110
|
function decodeSignalMessageKey(messageKey, field) {
|
|
110
111
|
const cipherKey = (0, coercion_1.asBytes)(messageKey.cipherKey, `${field}.cipherKey`);
|
|
111
|
-
|
|
112
|
-
throw new Error(`invalid ${field}.cipherKey length ${cipherKey.byteLength}`);
|
|
113
|
-
}
|
|
112
|
+
(0, bytes_1.assertByteLength)(cipherKey, 32, `invalid ${field}.cipherKey length ${cipherKey.byteLength}`);
|
|
114
113
|
const macKey = (0, coercion_1.asBytes)(messageKey.macKey, `${field}.macKey`);
|
|
115
|
-
|
|
116
|
-
throw new Error(`invalid ${field}.macKey length ${macKey.byteLength}`);
|
|
117
|
-
}
|
|
114
|
+
(0, bytes_1.assertByteLength)(macKey, 32, `invalid ${field}.macKey length ${macKey.byteLength}`);
|
|
118
115
|
const iv = (0, coercion_1.asBytes)(messageKey.iv, `${field}.iv`);
|
|
119
|
-
|
|
120
|
-
throw new Error(`invalid ${field}.iv length ${iv.byteLength}`);
|
|
121
|
-
}
|
|
116
|
+
(0, bytes_1.assertByteLength)(iv, 16, `invalid ${field}.iv length ${iv.byteLength}`);
|
|
122
117
|
return {
|
|
123
118
|
index: (0, coercion_1.asNumber)(messageKey.index, `${field}.index`),
|
|
124
119
|
cipherKey,
|
|
@@ -132,13 +127,9 @@ function decodeSignalRecvChain(chain, field) {
|
|
|
132
127
|
throw new Error(`missing ${field}.chainKey`);
|
|
133
128
|
}
|
|
134
129
|
const ratchetPubKey = (0, coercion_1.asBytes)(chain.senderRatchetKey, `${field}.senderRatchetKey`);
|
|
135
|
-
|
|
136
|
-
throw new Error(`invalid ${field}.senderRatchetKey length ${ratchetPubKey.byteLength}`);
|
|
137
|
-
}
|
|
130
|
+
(0, bytes_1.assertByteLength)(ratchetPubKey, 33, `invalid ${field}.senderRatchetKey length ${ratchetPubKey.byteLength}`);
|
|
138
131
|
const chainKeyBytes = (0, coercion_1.asBytes)(chainKey.key, `${field}.chainKey.key`);
|
|
139
|
-
|
|
140
|
-
throw new Error(`invalid ${field}.chainKey.key length ${chainKeyBytes.byteLength}`);
|
|
141
|
-
}
|
|
132
|
+
(0, bytes_1.assertByteLength)(chainKeyBytes, 32, `invalid ${field}.chainKey.key length ${chainKeyBytes.byteLength}`);
|
|
142
133
|
return {
|
|
143
134
|
ratchetPubKey,
|
|
144
135
|
nextMsgIndex: (0, coercion_1.asNumber)(chainKey.index, `${field}.chainKey.index`),
|
|
@@ -155,17 +146,11 @@ function decodeSignalSendChain(chain, field) {
|
|
|
155
146
|
if (!privateKey) {
|
|
156
147
|
throw new Error(`missing ${field}.senderRatchetKeyPrivate`);
|
|
157
148
|
}
|
|
158
|
-
|
|
159
|
-
throw new Error(`invalid ${field}.senderRatchetKeyPrivate length ${privateKey.byteLength}`);
|
|
160
|
-
}
|
|
149
|
+
(0, bytes_1.assertByteLength)(privateKey, 32, `invalid ${field}.senderRatchetKeyPrivate length ${privateKey.byteLength}`);
|
|
161
150
|
const ratchetPubKey = (0, coercion_1.asBytes)(chain.senderRatchetKey, `${field}.senderRatchetKey`);
|
|
162
|
-
|
|
163
|
-
throw new Error(`invalid ${field}.senderRatchetKey length ${ratchetPubKey.byteLength}`);
|
|
164
|
-
}
|
|
151
|
+
(0, bytes_1.assertByteLength)(ratchetPubKey, 33, `invalid ${field}.senderRatchetKey length ${ratchetPubKey.byteLength}`);
|
|
165
152
|
const chainKeyBytes = (0, coercion_1.asBytes)(chainKey.key, `${field}.chainKey.key`);
|
|
166
|
-
|
|
167
|
-
throw new Error(`invalid ${field}.chainKey.key length ${chainKeyBytes.byteLength}`);
|
|
168
|
-
}
|
|
153
|
+
(0, bytes_1.assertByteLength)(chainKeyBytes, 32, `invalid ${field}.chainKey.key length ${chainKeyBytes.byteLength}`);
|
|
169
154
|
return {
|
|
170
155
|
ratchetKey: {
|
|
171
156
|
pubKey: ratchetPubKey,
|
|
@@ -182,26 +167,20 @@ function decodeSignalSessionSnapshot(session, field) {
|
|
|
182
167
|
}
|
|
183
168
|
const pendingPreKey = session.pendingPreKey;
|
|
184
169
|
const localPubKey = (0, coercion_1.asBytes)(session.localIdentityPublic, `${field}.localIdentityPublic`);
|
|
185
|
-
|
|
186
|
-
throw new Error(`invalid ${field}.localIdentityPublic length ${localPubKey.byteLength}`);
|
|
187
|
-
}
|
|
170
|
+
(0, bytes_1.assertByteLength)(localPubKey, 33, `invalid ${field}.localIdentityPublic length ${localPubKey.byteLength}`);
|
|
188
171
|
const remotePubKey = (0, coercion_1.asBytes)(session.remoteIdentityPublic, `${field}.remoteIdentityPublic`);
|
|
189
|
-
|
|
190
|
-
throw new Error(`invalid ${field}.remoteIdentityPublic length ${remotePubKey.byteLength}`);
|
|
191
|
-
}
|
|
172
|
+
(0, bytes_1.assertByteLength)(remotePubKey, 33, `invalid ${field}.remoteIdentityPublic length ${remotePubKey.byteLength}`);
|
|
192
173
|
const rootKey = (0, coercion_1.asBytes)(session.rootKey, `${field}.rootKey`);
|
|
193
|
-
|
|
194
|
-
throw new Error(`invalid ${field}.rootKey length ${rootKey.byteLength}`);
|
|
195
|
-
}
|
|
174
|
+
(0, bytes_1.assertByteLength)(rootKey, 32, `invalid ${field}.rootKey length ${rootKey.byteLength}`);
|
|
196
175
|
const localOneTimePubKey = pendingPreKey
|
|
197
176
|
? (0, coercion_1.asBytes)(pendingPreKey.baseKey, `${field}.pendingPreKey.baseKey`)
|
|
198
177
|
: null;
|
|
199
|
-
if (localOneTimePubKey
|
|
200
|
-
|
|
178
|
+
if (localOneTimePubKey) {
|
|
179
|
+
(0, bytes_1.assertByteLength)(localOneTimePubKey, 33, `invalid ${field}.pendingPreKey.baseKey length ${localOneTimePubKey.byteLength}`);
|
|
201
180
|
}
|
|
202
181
|
const aliceBaseKey = (0, coercion_1.asOptionalBytes)(session.aliceBaseKey, `${field}.aliceBaseKey`) ?? null;
|
|
203
|
-
if (aliceBaseKey
|
|
204
|
-
|
|
182
|
+
if (aliceBaseKey) {
|
|
183
|
+
(0, bytes_1.assertByteLength)(aliceBaseKey, 33, `invalid ${field}.aliceBaseKey length ${aliceBaseKey.byteLength}`);
|
|
205
184
|
}
|
|
206
185
|
return {
|
|
207
186
|
local: {
|
|
@@ -104,18 +104,17 @@ function createStore(options) {
|
|
|
104
104
|
if (cached) {
|
|
105
105
|
return cached;
|
|
106
106
|
}
|
|
107
|
-
const
|
|
108
|
-
const
|
|
109
|
-
const
|
|
110
|
-
const
|
|
111
|
-
const
|
|
112
|
-
const
|
|
113
|
-
const
|
|
114
|
-
const
|
|
115
|
-
const
|
|
116
|
-
const
|
|
117
|
-
const
|
|
118
|
-
const customContacts = resolveStoreValue(normalizedSessionId, custom?.contacts, 'custom.contacts');
|
|
107
|
+
const resolveCustom = (value, domainPath) => resolveStoreValue(normalizedSessionId, value, domainPath);
|
|
108
|
+
const customAuth = resolveCustom(options.custom?.auth, 'custom.auth');
|
|
109
|
+
const customSignal = resolveCustom(options.custom?.signal, 'custom.signal');
|
|
110
|
+
const customSenderKey = resolveCustom(options.custom?.senderKey, 'custom.senderKey');
|
|
111
|
+
const customAppState = resolveCustom(options.custom?.appState, 'custom.appState');
|
|
112
|
+
const customRetry = resolveCustom(options.customCache?.retry, 'customCache.retry');
|
|
113
|
+
const customParticipants = resolveCustom(options.customCache?.participants, 'customCache.participants');
|
|
114
|
+
const customDeviceList = resolveCustom(options.customCache?.deviceList, 'customCache.deviceList');
|
|
115
|
+
const customMessages = resolveCustom(options.custom?.messages, 'custom.messages');
|
|
116
|
+
const customThreads = resolveCustom(options.custom?.threads, 'custom.threads');
|
|
117
|
+
const customContacts = resolveCustom(options.custom?.contacts, 'custom.contacts');
|
|
119
118
|
const memoryLimits = options.memory?.limits ?? {};
|
|
120
119
|
const requiresSqlite = !customAuth ||
|
|
121
120
|
(!customSignal && providers.signal === 'sqlite') ||
|
|
@@ -136,7 +135,8 @@ function createStore(options) {
|
|
|
136
135
|
path: sqlite.path,
|
|
137
136
|
sessionId: normalizedSessionId,
|
|
138
137
|
driver: sqlite.driver ?? 'auto',
|
|
139
|
-
pragmas: sqlite.pragmas
|
|
138
|
+
pragmas: sqlite.pragmas,
|
|
139
|
+
tableNames: sqlite.tableNames
|
|
140
140
|
}
|
|
141
141
|
: null;
|
|
142
142
|
const authStore = customAuth ?? new auth_store_1.WaAuthSqliteStore(sqliteOptions);
|
|
@@ -261,8 +261,7 @@ function createStore(options) {
|
|
|
261
261
|
return session;
|
|
262
262
|
},
|
|
263
263
|
async destroyCaches() {
|
|
264
|
-
const
|
|
265
|
-
for (const session of activeSessions) {
|
|
264
|
+
for (const session of sessions.values()) {
|
|
266
265
|
await session.destroyCaches();
|
|
267
266
|
}
|
|
268
267
|
},
|
|
@@ -271,9 +270,8 @@ function createStore(options) {
|
|
|
271
270
|
return;
|
|
272
271
|
}
|
|
273
272
|
storeDestroyed = true;
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
for (const session of activeSessions) {
|
|
273
|
+
for (const [sessionId, session] of sessions) {
|
|
274
|
+
sessions.delete(sessionId);
|
|
277
275
|
await session.destroy();
|
|
278
276
|
}
|
|
279
277
|
}
|
package/dist/store/noop.store.js
CHANGED
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.NOOP_DEVICE_LIST_STORE = exports.NOOP_PARTICIPANTS_STORE = exports.NOOP_CONTACT_STORE = exports.NOOP_THREAD_STORE = exports.NOOP_MESSAGE_STORE = void 0;
|
|
4
4
|
const EMPTY_STORE_LIST = Object.freeze([]);
|
|
5
|
-
const DEFAULT_PARTICIPANTS_CACHE_TTL_MS = 5 * 60 * 1000;
|
|
6
|
-
const DEFAULT_DEVICE_LIST_CACHE_TTL_MS = 5 * 60 * 1000;
|
|
7
5
|
exports.NOOP_MESSAGE_STORE = Object.freeze({
|
|
8
6
|
upsert: async (_record) => { },
|
|
7
|
+
upsertBatch: async (_records) => { },
|
|
9
8
|
getById: async (_id) => null,
|
|
10
9
|
listByThread: async (_threadJid, _limit, _beforeTimestampMs) => EMPTY_STORE_LIST,
|
|
11
10
|
deleteById: async (_id) => 0,
|
|
@@ -13,6 +12,7 @@ exports.NOOP_MESSAGE_STORE = Object.freeze({
|
|
|
13
12
|
});
|
|
14
13
|
exports.NOOP_THREAD_STORE = Object.freeze({
|
|
15
14
|
upsert: async (_record) => { },
|
|
15
|
+
upsertBatch: async (_records) => { },
|
|
16
16
|
getByJid: async (_jid) => null,
|
|
17
17
|
list: async (_limit) => EMPTY_STORE_LIST,
|
|
18
18
|
deleteByJid: async (_jid) => 0,
|
|
@@ -20,12 +20,12 @@ exports.NOOP_THREAD_STORE = Object.freeze({
|
|
|
20
20
|
});
|
|
21
21
|
exports.NOOP_CONTACT_STORE = Object.freeze({
|
|
22
22
|
upsert: async (_record) => { },
|
|
23
|
+
upsertBatch: async (_records) => { },
|
|
23
24
|
getByJid: async (_jid) => null,
|
|
24
25
|
deleteByJid: async (_jid) => 0,
|
|
25
26
|
clear: async () => { }
|
|
26
27
|
});
|
|
27
28
|
exports.NOOP_PARTICIPANTS_STORE = Object.freeze({
|
|
28
|
-
getTtlMs: () => DEFAULT_PARTICIPANTS_CACHE_TTL_MS,
|
|
29
29
|
upsertGroupParticipants: async (_snapshot) => { },
|
|
30
30
|
getGroupParticipants: async (_groupJid, _nowMs) => null,
|
|
31
31
|
deleteGroupParticipants: async (_groupJid) => 0,
|
|
@@ -34,10 +34,7 @@ exports.NOOP_PARTICIPANTS_STORE = Object.freeze({
|
|
|
34
34
|
destroy: async () => { }
|
|
35
35
|
});
|
|
36
36
|
exports.NOOP_DEVICE_LIST_STORE = Object.freeze({
|
|
37
|
-
getTtlMs: () => DEFAULT_DEVICE_LIST_CACHE_TTL_MS,
|
|
38
|
-
upsertUserDevices: async (_snapshot) => { },
|
|
39
37
|
upsertUserDevicesBatch: async (_snapshots) => { },
|
|
40
|
-
getUserDevices: async (_userJid, _nowMs) => null,
|
|
41
38
|
getUserDevicesBatch: async (userJids, _nowMs) => userJids.map(() => null),
|
|
42
39
|
deleteUserDevices: async (_userJid) => 0,
|
|
43
40
|
cleanupExpired: async (_nowMs) => 0,
|
|
@@ -25,13 +25,14 @@ class WaAppStateMemoryStore {
|
|
|
25
25
|
this.maxCollectionEntries = (0, coercion_1.resolvePositive)(options.maxCollectionEntries, DEFAULT_APPSTATE_MEMORY_STORE_LIMITS.collectionEntries, 'WaAppStateMemoryStoreOptions.maxCollectionEntries');
|
|
26
26
|
if (initial) {
|
|
27
27
|
for (const key of initial.keys) {
|
|
28
|
-
(0, collections_1.setBoundedMapEntry)(this.keys, (0,
|
|
28
|
+
(0, collections_1.setBoundedMapEntry)(this.keys, (0, bytes_1.bytesToHex)(key.keyId), key, this.maxSyncKeys);
|
|
29
29
|
}
|
|
30
30
|
for (const [collectionName, collection] of Object.entries(initial.collections)) {
|
|
31
31
|
if (!collection) {
|
|
32
32
|
continue;
|
|
33
33
|
}
|
|
34
34
|
this.collections.set(collectionName, {
|
|
35
|
+
initialized: true,
|
|
35
36
|
version: collection.version,
|
|
36
37
|
hash: collection.hash,
|
|
37
38
|
indexValueMap: toBoundedMap(Object.entries(collection.indexValueMap), this.maxCollectionEntries)
|
|
@@ -57,7 +58,7 @@ class WaAppStateMemoryStore {
|
|
|
57
58
|
async upsertSyncKeys(keys) {
|
|
58
59
|
let inserted = 0;
|
|
59
60
|
for (const key of keys) {
|
|
60
|
-
const keyHex = (0,
|
|
61
|
+
const keyHex = (0, bytes_1.bytesToHex)(key.keyId);
|
|
61
62
|
const existing = this.keys.get(keyHex);
|
|
62
63
|
if (existing && (0, bytes_1.uint8Equal)(existing.keyData, key.keyData)) {
|
|
63
64
|
continue;
|
|
@@ -68,10 +69,13 @@ class WaAppStateMemoryStore {
|
|
|
68
69
|
return inserted;
|
|
69
70
|
}
|
|
70
71
|
async getSyncKey(keyId) {
|
|
71
|
-
return this.keys.get((0,
|
|
72
|
+
return this.keys.get((0, bytes_1.bytesToHex)(keyId)) ?? null;
|
|
72
73
|
}
|
|
73
74
|
async getSyncKeyData(keyId) {
|
|
74
|
-
return this.keys.get((0,
|
|
75
|
+
return this.keys.get((0, bytes_1.bytesToHex)(keyId))?.keyData ?? null;
|
|
76
|
+
}
|
|
77
|
+
async getSyncKeyDataBatch(keyIds) {
|
|
78
|
+
return keyIds.map((keyId) => this.keys.get((0, bytes_1.bytesToHex)(keyId))?.keyData ?? null);
|
|
75
79
|
}
|
|
76
80
|
async getActiveSyncKey() {
|
|
77
81
|
return (0, utils_1.pickActiveSyncKey)(this.keys.values());
|
|
@@ -80,6 +84,7 @@ class WaAppStateMemoryStore {
|
|
|
80
84
|
let state = this.collections.get(collection);
|
|
81
85
|
if (!state) {
|
|
82
86
|
state = {
|
|
87
|
+
initialized: false,
|
|
83
88
|
version: 0,
|
|
84
89
|
hash: constants_1.APP_STATE_EMPTY_LT_HASH,
|
|
85
90
|
indexValueMap: new Map()
|
|
@@ -88,9 +93,28 @@ class WaAppStateMemoryStore {
|
|
|
88
93
|
}
|
|
89
94
|
return state;
|
|
90
95
|
}
|
|
96
|
+
async getCollectionStates(collections) {
|
|
97
|
+
const result = new Array(collections.length);
|
|
98
|
+
for (let index = 0; index < collections.length; index += 1) {
|
|
99
|
+
const collection = collections[index];
|
|
100
|
+
let state = this.collections.get(collection);
|
|
101
|
+
if (!state) {
|
|
102
|
+
state = {
|
|
103
|
+
initialized: false,
|
|
104
|
+
version: 0,
|
|
105
|
+
hash: constants_1.APP_STATE_EMPTY_LT_HASH,
|
|
106
|
+
indexValueMap: new Map()
|
|
107
|
+
};
|
|
108
|
+
this.collections.set(collection, state);
|
|
109
|
+
}
|
|
110
|
+
result[index] = state;
|
|
111
|
+
}
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
91
114
|
async setCollectionStates(updates) {
|
|
92
115
|
for (const update of updates) {
|
|
93
116
|
this.collections.set(update.collection, {
|
|
117
|
+
initialized: true,
|
|
94
118
|
version: update.version,
|
|
95
119
|
hash: update.hash,
|
|
96
120
|
indexValueMap: toBoundedMap(update.indexValueMap.entries(), this.maxCollectionEntries)
|
|
@@ -14,6 +14,11 @@ class WaContactMemoryStore {
|
|
|
14
14
|
async upsert(record) {
|
|
15
15
|
(0, collections_1.setBoundedMapEntry)(this.contacts, record.jid, record, this.maxContacts);
|
|
16
16
|
}
|
|
17
|
+
async upsertBatch(records) {
|
|
18
|
+
for (const record of records) {
|
|
19
|
+
(0, collections_1.setBoundedMapEntry)(this.contacts, record.jid, record, this.maxContacts);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
17
22
|
async getByJid(jid) {
|
|
18
23
|
return this.contacts.get(jid) ?? null;
|
|
19
24
|
}
|
|
@@ -17,38 +17,15 @@ class WaDeviceListMemoryStore {
|
|
|
17
17
|
}, (0, collections_1.resolveCleanupIntervalMs)(ttlMs));
|
|
18
18
|
this.cleanupTimer.unref();
|
|
19
19
|
}
|
|
20
|
-
getTtlMs() {
|
|
21
|
-
return this.ttlMs;
|
|
22
|
-
}
|
|
23
|
-
async upsertUserDevices(snapshot) {
|
|
24
|
-
(0, collections_1.setBoundedMapEntry)(this.records, snapshot.userJid, {
|
|
25
|
-
...snapshot,
|
|
26
|
-
expiresAtMs: snapshot.updatedAtMs + this.ttlMs
|
|
27
|
-
}, this.maxUsers);
|
|
28
|
-
}
|
|
29
20
|
async upsertUserDevicesBatch(snapshots) {
|
|
30
|
-
for (
|
|
21
|
+
for (let index = 0; index < snapshots.length; index += 1) {
|
|
22
|
+
const snapshot = snapshots[index];
|
|
31
23
|
(0, collections_1.setBoundedMapEntry)(this.records, snapshot.userJid, {
|
|
32
24
|
...snapshot,
|
|
33
25
|
expiresAtMs: snapshot.updatedAtMs + this.ttlMs
|
|
34
26
|
}, this.maxUsers);
|
|
35
27
|
}
|
|
36
28
|
}
|
|
37
|
-
async getUserDevices(userJid, nowMs = Date.now()) {
|
|
38
|
-
const record = this.records.get(userJid);
|
|
39
|
-
if (!record) {
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
if (record.expiresAtMs <= nowMs) {
|
|
43
|
-
this.records.delete(userJid);
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
userJid: record.userJid,
|
|
48
|
-
deviceJids: record.deviceJids,
|
|
49
|
-
updatedAtMs: record.updatedAtMs
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
29
|
async getUserDevicesBatch(userJids, nowMs = Date.now()) {
|
|
53
30
|
return userJids.map((userJid) => {
|
|
54
31
|
const record = this.records.get(userJid);
|
|
@@ -59,11 +36,7 @@ class WaDeviceListMemoryStore {
|
|
|
59
36
|
this.records.delete(userJid);
|
|
60
37
|
return null;
|
|
61
38
|
}
|
|
62
|
-
return
|
|
63
|
-
userJid: record.userJid,
|
|
64
|
-
deviceJids: record.deviceJids,
|
|
65
|
-
updatedAtMs: record.updatedAtMs
|
|
66
|
-
};
|
|
39
|
+
return record;
|
|
67
40
|
});
|
|
68
41
|
}
|
|
69
42
|
async deleteUserDevices(userJid) {
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.WaMessageMemoryStore = void 0;
|
|
4
4
|
const coercion_1 = require("../../../util/coercion");
|
|
5
5
|
const collections_1 = require("../../../util/collections");
|
|
6
|
-
const collections_2 = require("../../../util/collections");
|
|
7
6
|
const DEFAULT_MESSAGE_MEMORY_STORE_LIMITS = Object.freeze({
|
|
8
7
|
messages: 50000
|
|
9
8
|
});
|
|
@@ -13,7 +12,12 @@ class WaMessageMemoryStore {
|
|
|
13
12
|
this.maxMessages = (0, coercion_1.resolvePositive)(options.maxMessages, DEFAULT_MESSAGE_MEMORY_STORE_LIMITS.messages, 'WaMessageMemoryStoreOptions.maxMessages');
|
|
14
13
|
}
|
|
15
14
|
async upsert(record) {
|
|
16
|
-
(0,
|
|
15
|
+
(0, collections_1.setBoundedMapEntry)(this.messages, record.id, record, this.maxMessages);
|
|
16
|
+
}
|
|
17
|
+
async upsertBatch(records) {
|
|
18
|
+
for (const record of records) {
|
|
19
|
+
(0, collections_1.setBoundedMapEntry)(this.messages, record.id, record, this.maxMessages);
|
|
20
|
+
}
|
|
17
21
|
}
|
|
18
22
|
async getById(id) {
|
|
19
23
|
return this.messages.get(id) ?? null;
|
|
@@ -22,9 +26,8 @@ class WaMessageMemoryStore {
|
|
|
22
26
|
const normalizedLimit = (0, collections_1.normalizeQueryLimit)(limit, 50);
|
|
23
27
|
const records = [];
|
|
24
28
|
for (const record of this.messages.values()) {
|
|
25
|
-
if (record.threadJid !== threadJid)
|
|
29
|
+
if (record.threadJid !== threadJid)
|
|
26
30
|
continue;
|
|
27
|
-
}
|
|
28
31
|
if (beforeTimestampMs !== undefined &&
|
|
29
32
|
(record.timestampMs === undefined || record.timestampMs >= beforeTimestampMs)) {
|
|
30
33
|
continue;
|
|
@@ -32,7 +35,10 @@ class WaMessageMemoryStore {
|
|
|
32
35
|
records.push(record);
|
|
33
36
|
}
|
|
34
37
|
records.sort((left, right) => (right.timestampMs ?? 0) - (left.timestampMs ?? 0));
|
|
35
|
-
|
|
38
|
+
if (records.length > normalizedLimit) {
|
|
39
|
+
records.length = normalizedLimit;
|
|
40
|
+
}
|
|
41
|
+
return records;
|
|
36
42
|
}
|
|
37
43
|
async deleteById(id) {
|
|
38
44
|
return this.messages.delete(id) ? 1 : 0;
|
|
@@ -17,9 +17,6 @@ class WaParticipantsMemoryStore {
|
|
|
17
17
|
}, (0, collections_1.resolveCleanupIntervalMs)(ttlMs));
|
|
18
18
|
this.cleanupTimer.unref();
|
|
19
19
|
}
|
|
20
|
-
getTtlMs() {
|
|
21
|
-
return this.ttlMs;
|
|
22
|
-
}
|
|
23
20
|
async upsertGroupParticipants(snapshot) {
|
|
24
21
|
(0, collections_1.setBoundedMapEntry)(this.records, snapshot.groupJid, {
|
|
25
22
|
...snapshot,
|
|
@@ -35,11 +32,7 @@ class WaParticipantsMemoryStore {
|
|
|
35
32
|
this.records.delete(groupJid);
|
|
36
33
|
return null;
|
|
37
34
|
}
|
|
38
|
-
return
|
|
39
|
-
groupJid: record.groupJid,
|
|
40
|
-
participants: record.participants,
|
|
41
|
-
updatedAtMs: record.updatedAtMs
|
|
42
|
-
};
|
|
35
|
+
return record;
|
|
43
36
|
}
|
|
44
37
|
async deleteGroupParticipants(groupJid) {
|
|
45
38
|
return this.records.delete(groupJid) ? 1 : 0;
|