zapo-js 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -4
- package/dist/appstate/WaAppStateCrypto.js +19 -26
- package/dist/appstate/WaAppStateSyncClient.js +293 -181
- package/dist/appstate/WaAppStateSyncResponseParser.js +16 -5
- package/dist/appstate/constants.js +4 -3
- package/dist/appstate/{store/sqlite.js → encoding.js} +13 -8
- package/dist/appstate/index.js +8 -6
- package/dist/appstate/utils.js +9 -34
- package/dist/auth/WaAuthClient.js +43 -61
- package/dist/auth/flow/WaAuthCredentialsFlow.js +22 -15
- package/dist/auth/index.js +1 -8
- package/dist/auth/pairing/WaPairingCodeCrypto.js +6 -4
- package/dist/auth/pairing/WaPairingFlow.js +34 -26
- package/dist/auth/pairing/WaQrFlow.js +37 -24
- package/dist/client/WaClient.js +275 -324
- package/dist/client/WaClientFactory.js +500 -133
- package/dist/client/connection/WaConnectionManager.js +301 -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/WaBusinessCoordinator.js +241 -0
- package/dist/client/coordinators/WaGroupCoordinator.js +30 -16
- package/dist/client/coordinators/WaIncomingNodeCoordinator.js +21 -27
- package/dist/client/coordinators/WaMessageDispatchCoordinator.js +439 -701
- package/dist/client/coordinators/WaPassiveTasksCoordinator.js +74 -31
- package/dist/client/coordinators/WaPrivacyCoordinator.js +134 -0
- package/dist/client/coordinators/WaProfileCoordinator.js +212 -0
- package/dist/client/coordinators/WaRetryCoordinator.js +242 -57
- package/dist/client/coordinators/WaStreamControlCoordinator.js +18 -11
- package/dist/client/coordinators/WaTrustedContactTokenCoordinator.js +166 -0
- package/dist/client/dirty.js +74 -48
- package/dist/client/events/chat.js +4 -3
- package/dist/client/events/devices.js +72 -0
- package/dist/client/events/group.js +62 -47
- package/dist/client/events/identity.js +22 -0
- package/dist/client/events/privacy-token.js +39 -0
- package/dist/client/history-sync.js +94 -63
- package/dist/client/incoming.js +60 -27
- package/dist/client/mailbox.js +24 -23
- package/dist/client/messages.js +107 -31
- package/dist/client/messaging/fanout.js +199 -0
- package/dist/client/messaging/key-protocol.js +130 -0
- package/dist/client/messaging/participants.js +193 -0
- package/dist/client/persistence/WriteBehindPersistence.js +129 -0
- package/dist/client/tokens/cs-token.js +50 -0
- package/dist/client/tokens/tc-token.js +25 -0
- package/dist/crypto/core/hkdf.js +3 -8
- package/dist/crypto/core/index.js +2 -5
- package/dist/crypto/core/keys.js +6 -7
- package/dist/crypto/core/nonce.js +2 -0
- package/dist/crypto/core/primitives.js +12 -23
- package/dist/crypto/core/random.js +26 -23
- package/dist/crypto/curves/Ed25519.js +7 -8
- package/dist/crypto/curves/X25519.js +38 -22
- package/dist/crypto/index.js +1 -3
- package/dist/crypto/math/constants.js +13 -36
- package/dist/crypto/math/edwards.js +171 -44
- package/dist/crypto/math/fe.js +706 -0
- package/dist/crypto/math/mod.js +10 -3
- package/dist/esm/appstate/WaAppStateCrypto.js +7 -14
- package/dist/esm/appstate/WaAppStateSyncClient.js +284 -172
- package/dist/esm/appstate/WaAppStateSyncResponseParser.js +17 -6
- package/dist/esm/appstate/constants.js +3 -2
- package/dist/esm/appstate/{store/sqlite.js → encoding.js} +13 -8
- package/dist/esm/appstate/index.js +2 -2
- package/dist/esm/appstate/utils.js +8 -30
- package/dist/esm/auth/WaAuthClient.js +43 -61
- package/dist/esm/auth/flow/WaAuthCredentialsFlow.js +22 -15
- package/dist/esm/auth/index.js +0 -3
- package/dist/esm/auth/pairing/WaPairingCodeCrypto.js +6 -4
- package/dist/esm/auth/pairing/WaPairingFlow.js +28 -20
- package/dist/esm/auth/pairing/WaQrFlow.js +37 -24
- package/dist/esm/client/WaClient.js +275 -324
- package/dist/esm/client/WaClientFactory.js +501 -134
- package/dist/esm/client/connection/WaConnectionManager.js +297 -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/WaBusinessCoordinator.js +238 -0
- package/dist/esm/client/coordinators/WaGroupCoordinator.js +23 -9
- package/dist/esm/client/coordinators/WaIncomingNodeCoordinator.js +21 -27
- package/dist/esm/client/coordinators/WaMessageDispatchCoordinator.js +443 -705
- package/dist/esm/client/coordinators/WaPassiveTasksCoordinator.js +74 -31
- package/dist/esm/client/coordinators/WaPrivacyCoordinator.js +131 -0
- package/dist/esm/client/coordinators/WaProfileCoordinator.js +209 -0
- package/dist/esm/client/coordinators/WaRetryCoordinator.js +244 -59
- package/dist/esm/client/coordinators/WaStreamControlCoordinator.js +19 -12
- package/dist/esm/client/coordinators/WaTrustedContactTokenCoordinator.js +162 -0
- package/dist/esm/client/dirty.js +69 -43
- package/dist/esm/client/events/chat.js +4 -3
- package/dist/esm/client/events/devices.js +68 -0
- package/dist/esm/client/events/group.js +53 -39
- package/dist/esm/client/events/identity.js +19 -0
- package/dist/esm/client/events/privacy-token.js +36 -0
- package/dist/esm/client/history-sync.js +91 -60
- package/dist/esm/client/incoming.js +61 -28
- package/dist/esm/client/mailbox.js +24 -23
- package/dist/esm/client/messages.js +108 -32
- package/dist/esm/client/messaging/fanout.js +196 -0
- package/dist/esm/client/messaging/key-protocol.js +127 -0
- package/dist/esm/client/messaging/participants.js +190 -0
- package/dist/esm/client/persistence/WriteBehindPersistence.js +125 -0
- package/dist/esm/client/tokens/cs-token.js +46 -0
- package/dist/esm/client/tokens/tc-token.js +18 -0
- package/dist/esm/crypto/core/hkdf.js +3 -8
- package/dist/esm/crypto/core/index.js +2 -3
- package/dist/esm/crypto/core/keys.js +3 -4
- package/dist/esm/crypto/core/nonce.js +2 -0
- package/dist/esm/crypto/core/primitives.js +12 -22
- package/dist/esm/crypto/core/random.js +25 -23
- package/dist/esm/crypto/curves/Ed25519.js +4 -5
- package/dist/esm/crypto/curves/X25519.js +35 -19
- package/dist/esm/crypto/index.js +0 -1
- package/dist/esm/crypto/math/constants.js +12 -35
- package/dist/esm/crypto/math/edwards.js +174 -47
- package/dist/esm/crypto/math/fe.js +691 -0
- package/dist/esm/crypto/math/mod.js +10 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/infra/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/BackgroundQueue.js +478 -0
- package/dist/esm/infra/perf/BoundedTaskQueue.js +16 -18
- package/dist/esm/infra/perf/PromiseDedup.js +20 -0
- package/dist/esm/infra/perf/SharedExclusiveGate.js +109 -0
- package/dist/esm/infra/perf/StoreLock.js +77 -0
- package/dist/esm/media/WaMediaCrypto.js +96 -16
- package/dist/esm/media/WaMediaTransferClient.js +251 -91
- package/dist/esm/media/conn.js +10 -6
- package/dist/esm/media/constants.js +6 -2
- package/dist/esm/message/WaMessageClient.js +30 -32
- package/dist/esm/message/ack.js +6 -6
- package/dist/esm/message/addon-crypto.js +59 -0
- package/dist/esm/message/content.js +195 -9
- package/dist/esm/message/icdc.js +76 -0
- package/dist/esm/message/incoming.js +129 -122
- package/dist/esm/message/index.js +2 -0
- package/dist/esm/message/phash.js +3 -1
- package/dist/esm/message/reporting-token.js +425 -0
- package/dist/esm/message/use-case-secret.js +49 -0
- package/dist/esm/protocol/appstate.js +27 -0
- package/dist/esm/protocol/browser.js +10 -18
- package/dist/esm/protocol/constants.js +6 -3
- package/dist/esm/protocol/defaults.js +6 -0
- package/dist/esm/protocol/index.js +2 -11
- package/dist/esm/protocol/jid.js +133 -52
- package/dist/esm/protocol/media.js +3 -3
- package/dist/esm/protocol/message.js +61 -1
- package/dist/esm/protocol/nodes.js +4 -0
- package/dist/esm/protocol/notification.js +3 -1
- package/dist/esm/protocol/privacy-token.js +17 -0
- package/dist/esm/protocol/privacy.js +55 -0
- package/dist/esm/protocol/stream.js +26 -1
- package/dist/esm/protocol/usync.js +11 -0
- package/dist/esm/retry/codec.js +216 -0
- package/dist/esm/retry/constants.js +1 -1
- package/dist/esm/retry/index.js +3 -2
- package/dist/esm/retry/parse.js +88 -86
- package/dist/esm/retry/replay.js +54 -51
- package/dist/esm/retry/tracker.js +94 -0
- package/dist/esm/signal/api/SignalDeviceSyncApi.js +276 -92
- package/dist/esm/signal/api/SignalDigestSyncApi.js +17 -8
- package/dist/esm/signal/api/SignalIdentitySyncApi.js +67 -37
- package/dist/esm/signal/api/SignalMissingPreKeysSyncApi.js +86 -67
- package/dist/esm/signal/api/SignalRotateKeyApi.js +4 -2
- package/dist/esm/signal/api/SignalSessionSyncApi.js +36 -34
- package/dist/esm/signal/api/result-map.js +10 -0
- package/dist/esm/signal/constants.js +0 -4
- package/dist/esm/signal/crypto/WaAdvSignature.js +13 -9
- package/dist/esm/signal/{store/sqlite.js → encoding.js} +93 -60
- package/dist/esm/signal/group/SenderKeyChain.js +28 -23
- package/dist/esm/signal/group/SenderKeyCodec.js +5 -6
- package/dist/esm/signal/group/SenderKeyManager.js +144 -115
- package/dist/esm/signal/index.js +2 -0
- package/dist/esm/signal/registration/keygen.js +6 -2
- package/dist/esm/signal/registration/utils.js +1 -0
- package/dist/esm/signal/session/SignalProtocol.js +164 -53
- 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 +221 -0
- package/dist/esm/store/contracts/privacy-token.store.js +1 -0
- package/dist/esm/store/createStore.js +100 -188
- package/dist/esm/store/index.js +1 -10
- package/dist/esm/store/locks/appstate.lock.js +26 -0
- package/dist/esm/store/locks/auth.lock.js +15 -0
- package/dist/esm/store/locks/contact.lock.js +20 -0
- package/dist/esm/store/locks/device-list.lock.js +20 -0
- package/dist/esm/store/locks/message.lock.js +21 -0
- package/dist/esm/store/locks/participants.lock.js +20 -0
- package/dist/esm/store/locks/privacy-token.lock.js +18 -0
- package/dist/esm/store/locks/retry.lock.js +29 -0
- package/dist/esm/store/locks/sender-key.lock.js +52 -0
- package/dist/esm/store/locks/signal.lock.js +63 -0
- package/dist/esm/store/locks/thread.lock.js +21 -0
- package/dist/esm/store/noop.store.js +4 -7
- package/dist/esm/store/providers/memory/appstate.store.js +38 -16
- package/dist/esm/store/providers/memory/contact.store.js +5 -0
- package/dist/esm/store/providers/memory/device-list.store.js +12 -34
- 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/privacy-token.store.js +43 -0
- package/dist/esm/store/providers/memory/retry.store.js +77 -2
- package/dist/esm/store/providers/memory/sender-key.store.js +11 -8
- package/dist/esm/store/providers/memory/signal.store.js +47 -18
- package/dist/esm/store/providers/memory/thread.store.js +5 -0
- package/dist/esm/transport/WaComms.js +28 -24
- package/dist/esm/transport/WaWebSocket.js +115 -18
- package/dist/esm/transport/binary/constants.js +0 -30
- package/dist/esm/transport/binary/decoder.js +8 -8
- package/dist/esm/transport/binary/encoder.js +10 -9
- package/dist/esm/transport/binary/index.js +0 -1
- package/dist/esm/transport/index.js +1 -0
- package/dist/esm/transport/keepalive/WaKeepAlive.js +2 -8
- package/dist/esm/transport/node/WaNodeOrchestrator.js +25 -21
- 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/business.js +129 -0
- package/dist/esm/transport/node/builders/global.js +370 -0
- package/dist/esm/transport/node/builders/index.js +7 -3
- package/dist/esm/transport/node/builders/message.js +63 -230
- package/dist/esm/transport/node/builders/pairing.js +2 -27
- package/dist/esm/transport/node/builders/privacy-token.js +41 -0
- package/dist/esm/transport/node/builders/privacy.js +48 -0
- package/dist/esm/transport/node/builders/profile.js +70 -0
- package/dist/esm/transport/node/builders/retry.js +10 -22
- package/dist/esm/transport/node/builders/usync.js +45 -0
- package/dist/esm/transport/node/helpers.js +125 -5
- package/dist/esm/transport/node/usync.js +5 -0
- package/dist/esm/transport/node/xml.js +35 -14
- package/dist/esm/transport/noise/WaClientPayload.js +10 -10
- package/dist/esm/transport/noise/WaFrameCodec.js +48 -33
- package/dist/esm/transport/noise/WaNoiseCert.js +4 -7
- package/dist/esm/transport/noise/WaNoiseSession.js +77 -29
- package/dist/esm/transport/noise/WaNoiseSocket.js +8 -4
- package/dist/esm/transport/proxy.js +27 -0
- package/dist/esm/transport/stream/parse.js +17 -48
- package/dist/esm/util/bytes.js +67 -45
- package/dist/esm/util/coercion.js +6 -14
- package/dist/esm/util/index.js +5 -0
- package/dist/esm/util/primitives.js +40 -14
- package/dist/index.js +7 -1
- 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/BackgroundQueue.js +482 -0
- package/dist/infra/perf/BoundedTaskQueue.js +16 -18
- package/dist/infra/perf/PromiseDedup.js +24 -0
- package/dist/infra/perf/SharedExclusiveGate.js +113 -0
- package/dist/infra/perf/StoreLock.js +81 -0
- package/dist/media/WaMediaCrypto.js +95 -15
- package/dist/media/WaMediaTransferClient.js +284 -91
- package/dist/media/conn.js +10 -6
- package/dist/media/constants.js +6 -2
- package/dist/message/WaMessageClient.js +31 -33
- package/dist/message/ack.js +6 -6
- package/dist/message/addon-crypto.js +65 -0
- package/dist/message/content.js +198 -9
- package/dist/message/icdc.js +81 -0
- package/dist/message/incoming.js +127 -120
- package/dist/message/index.js +2 -0
- package/dist/message/phash.js +3 -1
- package/dist/message/reporting-token.js +429 -0
- package/dist/message/use-case-secret.js +55 -0
- package/dist/protocol/appstate.js +28 -1
- package/dist/protocol/browser.js +10 -18
- package/dist/protocol/constants.js +26 -1
- package/dist/protocol/defaults.js +6 -0
- package/dist/protocol/index.js +23 -42
- package/dist/protocol/jid.js +140 -52
- package/dist/protocol/media.js +3 -3
- package/dist/protocol/message.js +62 -2
- package/dist/protocol/nodes.js +4 -0
- package/dist/protocol/notification.js +3 -1
- package/dist/protocol/privacy-token.js +20 -0
- package/dist/protocol/privacy.js +58 -0
- package/dist/protocol/stream.js +27 -2
- package/dist/protocol/usync.js +14 -0
- package/dist/retry/codec.js +220 -0
- package/dist/retry/constants.js +1 -1
- package/dist/retry/index.js +7 -5
- package/dist/retry/parse.js +88 -85
- package/dist/retry/replay.js +52 -49
- package/dist/retry/tracker.js +97 -0
- package/dist/signal/api/SignalDeviceSyncApi.js +273 -89
- package/dist/signal/api/SignalDigestSyncApi.js +17 -8
- package/dist/signal/api/SignalIdentitySyncApi.js +66 -36
- package/dist/signal/api/SignalMissingPreKeysSyncApi.js +82 -63
- package/dist/signal/api/SignalRotateKeyApi.js +4 -2
- package/dist/signal/api/SignalSessionSyncApi.js +36 -34
- package/dist/signal/api/result-map.js +13 -0
- package/dist/signal/constants.js +1 -5
- package/dist/signal/crypto/WaAdvSignature.js +11 -7
- package/dist/signal/{store/sqlite.js → encoding.js} +94 -61
- package/dist/signal/group/SenderKeyChain.js +27 -22
- package/dist/signal/group/SenderKeyCodec.js +5 -6
- package/dist/signal/group/SenderKeyManager.js +144 -115
- package/dist/signal/index.js +15 -1
- package/dist/signal/registration/keygen.js +6 -2
- package/dist/signal/registration/utils.js +1 -0
- package/dist/signal/session/SignalProtocol.js +164 -53
- package/dist/signal/session/SignalRatchet.js +24 -15
- package/dist/signal/session/SignalSession.js +14 -9
- package/dist/signal/session/resolver.js +224 -0
- package/dist/store/contracts/privacy-token.store.js +2 -0
- package/dist/store/createStore.js +100 -188
- package/dist/store/index.js +15 -33
- package/dist/store/locks/appstate.lock.js +29 -0
- package/dist/store/locks/auth.lock.js +18 -0
- package/dist/store/locks/contact.lock.js +23 -0
- package/dist/store/locks/device-list.lock.js +23 -0
- package/dist/store/locks/message.lock.js +24 -0
- package/dist/store/locks/participants.lock.js +23 -0
- package/dist/store/locks/privacy-token.lock.js +21 -0
- package/dist/store/locks/retry.lock.js +32 -0
- package/dist/store/locks/sender-key.lock.js +55 -0
- package/dist/store/locks/signal.lock.js +66 -0
- package/dist/store/locks/thread.lock.js +24 -0
- package/dist/store/noop.store.js +4 -7
- package/dist/store/providers/memory/appstate.store.js +36 -14
- package/dist/store/providers/memory/contact.store.js +5 -0
- package/dist/store/providers/memory/device-list.store.js +12 -34
- 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/privacy-token.store.js +47 -0
- package/dist/store/providers/memory/retry.store.js +77 -2
- package/dist/store/providers/memory/sender-key.store.js +14 -11
- package/dist/store/providers/memory/signal.store.js +54 -25
- package/dist/store/providers/memory/thread.store.js +5 -0
- package/dist/transport/WaComms.js +30 -26
- package/dist/transport/WaWebSocket.js +148 -18
- package/dist/transport/binary/constants.js +1 -31
- package/dist/transport/binary/decoder.js +8 -8
- package/dist/transport/binary/encoder.js +10 -9
- package/dist/transport/binary/index.js +0 -4
- package/dist/transport/index.js +7 -1
- package/dist/transport/keepalive/WaKeepAlive.js +1 -7
- package/dist/transport/node/WaNodeOrchestrator.js +25 -21
- 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/business.js +137 -0
- package/dist/transport/node/builders/global.js +375 -0
- package/dist/transport/node/builders/index.js +29 -17
- package/dist/transport/node/builders/message.js +64 -236
- package/dist/transport/node/builders/pairing.js +2 -29
- package/dist/transport/node/builders/privacy-token.js +46 -0
- package/dist/transport/node/builders/privacy.js +55 -0
- package/dist/transport/node/builders/profile.js +78 -0
- package/dist/transport/node/builders/retry.js +9 -21
- package/dist/transport/node/builders/usync.js +49 -0
- package/dist/transport/node/helpers.js +131 -4
- package/dist/transport/node/usync.js +8 -0
- package/dist/transport/node/xml.js +35 -14
- package/dist/transport/noise/WaClientPayload.js +13 -13
- package/dist/transport/noise/WaFrameCodec.js +47 -32
- package/dist/transport/noise/WaNoiseCert.js +5 -8
- package/dist/transport/noise/WaNoiseSession.js +77 -29
- package/dist/transport/noise/WaNoiseSocket.js +8 -4
- package/dist/transport/proxy.js +34 -0
- package/dist/transport/stream/parse.js +20 -52
- 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/encoding.d.ts +7 -0
- package/dist/types/appstate/index.d.ts +3 -3
- package/dist/types/appstate/utils.d.ts +0 -3
- package/dist/types/auth/WaAuthClient.d.ts +10 -12
- package/dist/types/auth/flow/WaAuthCredentialsFlow.d.ts +1 -1
- package/dist/types/auth/index.d.ts +0 -4
- package/dist/types/auth/pairing/WaQrFlow.d.ts +1 -1
- package/dist/types/auth/types.d.ts +7 -9
- package/dist/types/client/WaClient.d.ts +42 -25
- package/dist/types/client/WaClientFactory.d.ts +33 -26
- package/dist/types/client/connection/WaConnectionManager.d.ts +66 -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/WaBusinessCoordinator.d.ts +57 -0
- package/dist/types/client/coordinators/WaIncomingNodeCoordinator.d.ts +3 -2
- package/dist/types/client/coordinators/WaMessageDispatchCoordinator.d.ts +29 -38
- package/dist/types/client/coordinators/WaPassiveTasksCoordinator.d.ts +4 -0
- package/dist/types/client/coordinators/WaPrivacyCoordinator.d.ts +26 -0
- package/dist/types/client/coordinators/WaProfileCoordinator.d.ts +36 -0
- package/dist/types/client/coordinators/WaRetryCoordinator.d.ts +8 -0
- package/dist/types/client/coordinators/WaStreamControlCoordinator.d.ts +3 -2
- package/dist/types/client/coordinators/WaTrustedContactTokenCoordinator.d.ts +45 -0
- package/dist/types/client/dirty.d.ts +1 -0
- package/dist/types/client/events/devices.d.ts +20 -0
- package/dist/types/client/events/group.d.ts +2 -1
- package/dist/types/client/events/identity.d.ts +9 -0
- package/dist/types/client/events/privacy-token.d.ts +7 -0
- package/dist/types/client/history-sync.d.ts +9 -6
- package/dist/types/client/incoming.d.ts +3 -1
- package/dist/types/client/index.d.ts +1 -1
- package/dist/types/client/mailbox.d.ts +3 -5
- package/dist/types/client/messages.d.ts +1 -2
- package/dist/types/client/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/persistence/WriteBehindPersistence.d.ts +34 -0
- package/dist/types/client/tokens/cs-token.d.ts +10 -0
- package/dist/types/client/tokens/tc-token.d.ts +5 -0
- package/dist/types/client/types.d.ts +75 -4
- package/dist/types/crypto/core/hkdf.d.ts +0 -6
- package/dist/types/crypto/core/index.d.ts +2 -3
- package/dist/types/crypto/core/nonce.d.ts +2 -0
- package/dist/types/crypto/core/primitives.d.ts +0 -1
- package/dist/types/crypto/core/random.d.ts +2 -7
- package/dist/types/crypto/index.d.ts +0 -1
- package/dist/types/crypto/math/constants.d.ts +4 -2
- package/dist/types/crypto/math/fe.d.ts +30 -0
- package/dist/types/crypto/math/mod.d.ts +0 -2
- package/dist/types/crypto/math/types.d.ts +11 -4
- package/dist/types/index.d.ts +5 -3
- package/dist/types/infra/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/BackgroundQueue.d.ts +58 -0
- package/dist/types/infra/perf/BoundedTaskQueue.d.ts +1 -1
- package/dist/types/infra/perf/PromiseDedup.d.ts +4 -0
- package/dist/types/infra/perf/SharedExclusiveGate.d.ts +17 -0
- package/dist/types/infra/perf/StoreLock.d.ts +10 -0
- package/dist/types/media/WaMediaCrypto.d.ts +3 -2
- package/dist/types/media/WaMediaTransferClient.d.ts +16 -15
- package/dist/types/media/constants.d.ts +1 -1
- package/dist/types/media/index.d.ts +1 -1
- package/dist/types/media/types.d.ts +15 -2
- package/dist/types/message/addon-crypto.d.ts +25 -0
- package/dist/types/message/content.d.ts +8 -0
- package/dist/types/message/icdc.d.ts +13 -0
- package/dist/types/message/index.d.ts +2 -0
- package/dist/types/message/reporting-token.d.ts +18 -0
- package/dist/types/message/types.d.ts +45 -6
- package/dist/types/message/use-case-secret.d.ts +20 -0
- package/dist/types/protocol/appstate.d.ts +47 -0
- package/dist/types/protocol/constants.d.ts +8 -3
- package/dist/types/protocol/defaults.d.ts +6 -0
- package/dist/types/protocol/index.d.ts +2 -11
- package/dist/types/protocol/jid.d.ts +22 -5
- package/dist/types/protocol/message.d.ts +60 -0
- package/dist/types/protocol/nodes.d.ts +4 -0
- package/dist/types/protocol/notification.d.ts +2 -0
- package/dist/types/protocol/privacy-token.d.ts +17 -0
- package/dist/types/protocol/privacy.d.ts +75 -0
- package/dist/types/protocol/stream.d.ts +30 -0
- package/dist/types/protocol/usync.d.ts +11 -0
- package/dist/types/retry/codec.d.ts +3 -0
- package/dist/types/retry/index.d.ts +4 -3
- package/dist/types/retry/parse.d.ts +5 -2
- package/dist/types/retry/replay.d.ts +0 -4
- package/dist/types/retry/tracker.d.ts +20 -0
- package/dist/types/retry/types.d.ts +10 -4
- package/dist/types/signal/api/SignalDeviceSyncApi.d.ts +15 -2
- package/dist/types/signal/api/SignalDigestSyncApi.d.ts +6 -0
- package/dist/types/signal/api/SignalIdentitySyncApi.d.ts +2 -0
- package/dist/types/signal/api/SignalRotateKeyApi.d.ts +4 -5
- package/dist/types/signal/api/SignalSessionSyncApi.d.ts +8 -6
- package/dist/types/signal/api/result-map.d.ts +1 -0
- package/dist/types/signal/constants.d.ts +0 -3
- package/dist/types/signal/{store/sqlite.d.ts → encoding.d.ts} +3 -3
- package/dist/types/signal/group/SenderKeyCodec.d.ts +4 -6
- package/dist/types/signal/group/SenderKeyManager.d.ts +10 -5
- package/dist/types/signal/index.d.ts +3 -0
- package/dist/types/signal/session/SignalProtocol.d.ts +19 -4
- package/dist/types/signal/session/resolver.d.ts +22 -0
- package/dist/types/store/contracts/appstate.store.d.ts +4 -1
- 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/privacy-token.store.d.ts +16 -0
- package/dist/types/store/contracts/retry.store.d.ts +7 -0
- package/dist/types/store/contracts/sender-key.store.d.ts +0 -1
- package/dist/types/store/contracts/signal.store.d.ts +13 -0
- package/dist/types/store/contracts/thread.store.d.ts +1 -0
- package/dist/types/store/createStore.d.ts +1 -1
- package/dist/types/store/index.d.ts +5 -13
- package/dist/types/store/locks/appstate.lock.d.ts +3 -0
- package/dist/types/store/locks/auth.lock.d.ts +3 -0
- package/dist/types/store/locks/contact.lock.d.ts +3 -0
- package/dist/types/store/locks/device-list.lock.d.ts +2 -0
- package/dist/types/store/locks/message.lock.d.ts +3 -0
- package/dist/types/store/locks/participants.lock.d.ts +2 -0
- package/dist/types/store/locks/privacy-token.lock.d.ts +2 -0
- package/dist/types/store/locks/retry.lock.d.ts +2 -0
- package/dist/types/store/locks/sender-key.lock.d.ts +3 -0
- package/dist/types/store/locks/signal.lock.d.ts +3 -0
- package/dist/types/store/locks/thread.lock.d.ts +3 -0
- package/dist/types/store/providers/memory/appstate.store.d.ts +3 -1
- 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/privacy-token.store.d.ts +13 -0
- package/dist/types/store/providers/memory/retry.store.d.ts +8 -0
- package/dist/types/store/providers/memory/sender-key.store.d.ts +0 -1
- package/dist/types/store/providers/memory/signal.store.d.ts +8 -1
- package/dist/types/store/providers/memory/thread.store.d.ts +1 -0
- package/dist/types/store/types.d.ts +49 -58
- package/dist/types/transport/WaWebSocket.d.ts +3 -1
- package/dist/types/transport/binary/constants.d.ts +0 -30
- package/dist/types/transport/binary/index.d.ts +0 -1
- package/dist/types/transport/index.d.ts +2 -1
- package/dist/types/transport/keepalive/WaKeepAlive.d.ts +0 -1
- package/dist/types/transport/node/WaNodeOrchestrator.d.ts +3 -4
- package/dist/types/transport/node/WaNodeTransport.d.ts +0 -9
- package/dist/types/transport/node/builders/business.d.ts +29 -0
- package/dist/types/transport/node/builders/global.d.ts +102 -0
- package/dist/types/transport/node/builders/group.d.ts +4 -6
- package/dist/types/transport/node/builders/index.d.ts +7 -3
- package/dist/types/transport/node/builders/message.d.ts +20 -30
- package/dist/types/transport/node/builders/pairing.d.ts +0 -2
- package/dist/types/transport/node/builders/privacy-token.d.ts +9 -0
- package/dist/types/transport/node/builders/privacy.d.ts +7 -0
- package/dist/types/transport/node/builders/profile.d.ts +8 -0
- package/dist/types/transport/node/builders/retry.d.ts +2 -5
- package/dist/types/transport/node/builders/usync.d.ts +21 -0
- package/dist/types/transport/node/helpers.d.ts +13 -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 +4 -2
- package/dist/types/transport/noise/WaNoiseSocket.d.ts +4 -2
- 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/index.d.ts +5 -0
- package/dist/types/util/primitives.d.ts +2 -0
- package/dist/util/bytes.js +72 -46
- package/dist/util/coercion.js +6 -14
- package/dist/util/index.js +23 -0
- package/dist/util/primitives.js +42 -14
- package/package.json +52 -9
- package/proto/index.js +1 -1
- package/dist/crypto/core/constants.js +0 -4
- package/dist/crypto/core/encoding.js +0 -29
- package/dist/esm/crypto/core/constants.js +0 -1
- package/dist/esm/crypto/core/encoding.js +0 -25
- package/dist/esm/retry/outbound.js +0 -83
- package/dist/esm/store/providers/sqlite/BaseSqliteStore.js +0 -37
- package/dist/esm/store/providers/sqlite/appstate.store.js +0 -169
- package/dist/esm/store/providers/sqlite/auth.store.js +0 -176
- package/dist/esm/store/providers/sqlite/connection.js +0 -240
- package/dist/esm/store/providers/sqlite/contact.store.js +0 -61
- package/dist/esm/store/providers/sqlite/device-list.store.js +0 -155
- package/dist/esm/store/providers/sqlite/message.store.js +0 -119
- package/dist/esm/store/providers/sqlite/migrations.js +0 -347
- package/dist/esm/store/providers/sqlite/participants.store.js +0 -85
- package/dist/esm/store/providers/sqlite/retry.store.js +0 -144
- package/dist/esm/store/providers/sqlite/sender-key.store.js +0 -203
- package/dist/esm/store/providers/sqlite/signal.store.js +0 -353
- package/dist/esm/store/providers/sqlite/thread.store.js +0 -72
- package/dist/esm/util/base64.js +0 -18
- package/dist/esm/util/signal-address.js +0 -5
- package/dist/retry/outbound.js +0 -88
- package/dist/store/providers/sqlite/BaseSqliteStore.js +0 -41
- package/dist/store/providers/sqlite/appstate.store.js +0 -173
- package/dist/store/providers/sqlite/auth.store.js +0 -180
- package/dist/store/providers/sqlite/connection.js +0 -276
- package/dist/store/providers/sqlite/contact.store.js +0 -65
- package/dist/store/providers/sqlite/device-list.store.js +0 -159
- package/dist/store/providers/sqlite/message.store.js +0 -123
- package/dist/store/providers/sqlite/migrations.js +0 -350
- package/dist/store/providers/sqlite/participants.store.js +0 -89
- package/dist/store/providers/sqlite/retry.store.js +0 -148
- package/dist/store/providers/sqlite/sender-key.store.js +0 -207
- package/dist/store/providers/sqlite/signal.store.js +0 -357
- package/dist/store/providers/sqlite/thread.store.js +0 -76
- package/dist/types/appstate/store/sqlite.d.ts +0 -21
- package/dist/types/crypto/core/constants.d.ts +0 -1
- package/dist/types/crypto/core/encoding.d.ts +0 -11
- package/dist/types/retry/outbound.d.ts +0 -4
- package/dist/types/store/providers/sqlite/BaseSqliteStore.d.ts +0 -12
- package/dist/types/store/providers/sqlite/appstate.store.d.ts +0 -15
- package/dist/types/store/providers/sqlite/auth.store.d.ts +0 -10
- package/dist/types/store/providers/sqlite/connection.d.ts +0 -10
- package/dist/types/store/providers/sqlite/contact.store.d.ts +0 -10
- package/dist/types/store/providers/sqlite/device-list.store.d.ts +0 -18
- package/dist/types/store/providers/sqlite/message.store.d.ts +0 -11
- package/dist/types/store/providers/sqlite/migrations.d.ts +0 -3
- package/dist/types/store/providers/sqlite/participants.store.d.ts +0 -13
- package/dist/types/store/providers/sqlite/retry.store.d.ts +0 -16
- package/dist/types/store/providers/sqlite/sender-key.store.d.ts +0 -25
- package/dist/types/store/providers/sqlite/signal.store.d.ts +0 -46
- package/dist/types/store/providers/sqlite/thread.store.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
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SenderKeySqliteStore = void 0;
|
|
4
|
-
const sqlite_1 = require("../../../signal/store/sqlite");
|
|
5
|
-
const BaseSqliteStore_1 = require("../../providers/sqlite/BaseSqliteStore");
|
|
6
|
-
const coercion_1 = require("../../../util/coercion");
|
|
7
|
-
const DEFAULTS = Object.freeze({
|
|
8
|
-
distributionBatchSize: 250
|
|
9
|
-
});
|
|
10
|
-
class SenderKeySqliteStore extends BaseSqliteStore_1.BaseSqliteStore {
|
|
11
|
-
constructor(options, distributionBatchSize) {
|
|
12
|
-
super(options, ['senderKey']);
|
|
13
|
-
this.distributionBatchSize = (0, coercion_1.resolvePositive)(distributionBatchSize, DEFAULTS.distributionBatchSize, 'senderKey.sqlite.distributionBatchSize');
|
|
14
|
-
}
|
|
15
|
-
async upsertSenderKey(record) {
|
|
16
|
-
const db = await this.getConnection();
|
|
17
|
-
const sender = (0, sqlite_1.toSignalAddressParts)(record.sender);
|
|
18
|
-
db.run(`INSERT INTO sender_keys (
|
|
19
|
-
session_id,
|
|
20
|
-
group_id,
|
|
21
|
-
sender_user,
|
|
22
|
-
sender_server,
|
|
23
|
-
sender_device,
|
|
24
|
-
record
|
|
25
|
-
) VALUES (?, ?, ?, ?, ?, ?)
|
|
26
|
-
ON CONFLICT(session_id, group_id, sender_user, sender_server, sender_device) DO UPDATE SET
|
|
27
|
-
record=excluded.record`, [
|
|
28
|
-
this.options.sessionId,
|
|
29
|
-
record.groupId,
|
|
30
|
-
sender.user,
|
|
31
|
-
sender.server,
|
|
32
|
-
sender.device,
|
|
33
|
-
(0, sqlite_1.encodeSenderKeyRecord)(record)
|
|
34
|
-
]);
|
|
35
|
-
}
|
|
36
|
-
async upsertSenderKeyDistribution(record) {
|
|
37
|
-
const db = await this.getConnection();
|
|
38
|
-
const sender = (0, sqlite_1.toSignalAddressParts)(record.sender);
|
|
39
|
-
this.upsertSenderKeyDistributionRow(db, record, sender);
|
|
40
|
-
}
|
|
41
|
-
async upsertSenderKeyDistributions(records) {
|
|
42
|
-
if (records.length === 0) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
await this.withTransaction((db) => {
|
|
46
|
-
for (const record of records) {
|
|
47
|
-
const sender = (0, sqlite_1.toSignalAddressParts)(record.sender);
|
|
48
|
-
this.upsertSenderKeyDistributionRow(db, record, sender);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
async getGroupSenderKeyList(groupId) {
|
|
53
|
-
const db = await this.getConnection();
|
|
54
|
-
const senderRows = db.all(`SELECT group_id, sender_user, sender_server, sender_device, record
|
|
55
|
-
FROM sender_keys
|
|
56
|
-
WHERE session_id = ? AND group_id = ?`, [this.options.sessionId, groupId]);
|
|
57
|
-
const distributionRows = db.all(`SELECT group_id, sender_user, sender_server, sender_device, key_id, timestamp_ms
|
|
58
|
-
FROM sender_key_distribution
|
|
59
|
-
WHERE session_id = ? AND group_id = ?`, [this.options.sessionId, groupId]);
|
|
60
|
-
return {
|
|
61
|
-
skList: senderRows.map((row) => (0, sqlite_1.decodeSenderKeyRecord)(row.record, (0, coercion_1.asString)(row.group_id, 'sender_keys.group_id'), {
|
|
62
|
-
user: (0, coercion_1.asString)(row.sender_user, 'sender_keys.sender_user'),
|
|
63
|
-
server: (0, coercion_1.asString)(row.sender_server, 'sender_keys.sender_server'),
|
|
64
|
-
device: (0, coercion_1.asNumber)(row.sender_device, 'sender_keys.sender_device')
|
|
65
|
-
})),
|
|
66
|
-
skDistribList: distributionRows.map((row) => (0, sqlite_1.decodeSenderKeyDistributionRow)(row))
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
async getDeviceSenderKey(groupId, sender) {
|
|
70
|
-
const db = await this.getConnection();
|
|
71
|
-
const target = (0, sqlite_1.toSignalAddressParts)(sender);
|
|
72
|
-
const row = db.get(`SELECT group_id, sender_user, sender_server, sender_device, record
|
|
73
|
-
FROM sender_keys
|
|
74
|
-
WHERE session_id = ?
|
|
75
|
-
AND group_id = ?
|
|
76
|
-
AND sender_user = ?
|
|
77
|
-
AND sender_server = ?
|
|
78
|
-
AND sender_device = ?`, [this.options.sessionId, groupId, target.user, target.server, target.device]);
|
|
79
|
-
if (!row) {
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
return (0, sqlite_1.decodeSenderKeyRecord)(row.record, (0, coercion_1.asString)(row.group_id, 'sender_keys.group_id'), {
|
|
83
|
-
user: (0, coercion_1.asString)(row.sender_user, 'sender_keys.sender_user'),
|
|
84
|
-
server: (0, coercion_1.asString)(row.sender_server, 'sender_keys.sender_server'),
|
|
85
|
-
device: (0, coercion_1.asNumber)(row.sender_device, 'sender_keys.sender_device')
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
async getDeviceSenderKeyDistribution(groupId, sender) {
|
|
89
|
-
const db = await this.getConnection();
|
|
90
|
-
const target = (0, sqlite_1.toSignalAddressParts)(sender);
|
|
91
|
-
const row = db.get(`SELECT group_id, sender_user, sender_server, sender_device, key_id, timestamp_ms
|
|
92
|
-
FROM sender_key_distribution
|
|
93
|
-
WHERE session_id = ?
|
|
94
|
-
AND group_id = ?
|
|
95
|
-
AND sender_user = ?
|
|
96
|
-
AND sender_server = ?
|
|
97
|
-
AND sender_device = ?`, [this.options.sessionId, groupId, target.user, target.server, target.device]);
|
|
98
|
-
return row ? (0, sqlite_1.decodeSenderKeyDistributionRow)(row) : null;
|
|
99
|
-
}
|
|
100
|
-
async getDeviceSenderKeyDistributions(groupId, senders) {
|
|
101
|
-
if (senders.length === 0) {
|
|
102
|
-
return [];
|
|
103
|
-
}
|
|
104
|
-
const db = await this.getConnection();
|
|
105
|
-
const targets = senders.map((sender) => (0, sqlite_1.toSignalAddressParts)(sender));
|
|
106
|
-
const map = new Map();
|
|
107
|
-
for (let start = 0; start < targets.length; start += this.distributionBatchSize) {
|
|
108
|
-
const end = Math.min(start + this.distributionBatchSize, targets.length);
|
|
109
|
-
const batchLength = end - start;
|
|
110
|
-
const filters = new Array(batchLength)
|
|
111
|
-
.fill('(sender_user = ? AND sender_server = ? AND sender_device = ?)')
|
|
112
|
-
.join(' OR ');
|
|
113
|
-
const params = [this.options.sessionId, groupId];
|
|
114
|
-
for (let index = start; index < end; index += 1) {
|
|
115
|
-
const target = targets[index];
|
|
116
|
-
params.push(target.user, target.server, target.device);
|
|
117
|
-
}
|
|
118
|
-
const rows = db.all(`SELECT group_id, sender_user, sender_server, sender_device, key_id, timestamp_ms
|
|
119
|
-
FROM sender_key_distribution
|
|
120
|
-
WHERE session_id = ? AND group_id = ? AND (${filters})`, params);
|
|
121
|
-
for (const row of rows) {
|
|
122
|
-
map.set(this.distributionRowKey(row), (0, sqlite_1.decodeSenderKeyDistributionRow)(row));
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return targets.map((target) => {
|
|
126
|
-
return (map.get(this.distributionTargetKey(target.user, target.server, target.device)) ??
|
|
127
|
-
null);
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
async deleteDeviceSenderKey(target, groupId) {
|
|
131
|
-
const sender = (0, sqlite_1.toSignalAddressParts)(target);
|
|
132
|
-
return this.withTransaction((db) => {
|
|
133
|
-
const senderCount = this.countDelete(db, 'sender_keys', sender, groupId);
|
|
134
|
-
const distributionCount = this.countDelete(db, 'sender_key_distribution', sender, groupId);
|
|
135
|
-
return senderCount + distributionCount;
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
async markForgetSenderKey(groupId, participants) {
|
|
139
|
-
if (participants.length === 0) {
|
|
140
|
-
return 0;
|
|
141
|
-
}
|
|
142
|
-
return this.withTransaction(async (db) => {
|
|
143
|
-
let deleted = 0;
|
|
144
|
-
for (const participant of participants) {
|
|
145
|
-
const sender = (0, sqlite_1.toSignalAddressParts)(participant);
|
|
146
|
-
deleted += this.countDelete(db, 'sender_keys', sender, groupId);
|
|
147
|
-
deleted += this.countDelete(db, 'sender_key_distribution', sender, groupId);
|
|
148
|
-
}
|
|
149
|
-
return deleted;
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
async clear() {
|
|
153
|
-
await this.withTransaction((db) => {
|
|
154
|
-
db.run('DELETE FROM sender_keys WHERE session_id = ?', [this.options.sessionId]);
|
|
155
|
-
db.run('DELETE FROM sender_key_distribution WHERE session_id = ?', [
|
|
156
|
-
this.options.sessionId
|
|
157
|
-
]);
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
countDelete(db, table, target, groupId) {
|
|
161
|
-
const whereWithGroup = 'session_id = ? AND sender_user = ? AND sender_server = ? AND sender_device = ? AND group_id = ?';
|
|
162
|
-
const whereAllGroups = 'session_id = ? AND sender_user = ? AND sender_server = ? AND sender_device = ?';
|
|
163
|
-
const countRow = db.get(`SELECT COUNT(*) AS count
|
|
164
|
-
FROM ${table}
|
|
165
|
-
WHERE ${groupId ? whereWithGroup : whereAllGroups}`, groupId
|
|
166
|
-
? [this.options.sessionId, target.user, target.server, target.device, groupId]
|
|
167
|
-
: [this.options.sessionId, target.user, target.server, target.device]);
|
|
168
|
-
const count = (0, sqlite_1.decodeSqliteCount)(countRow, `${table}.count`);
|
|
169
|
-
if (count === 0) {
|
|
170
|
-
return 0;
|
|
171
|
-
}
|
|
172
|
-
db.run(`DELETE FROM ${table}
|
|
173
|
-
WHERE ${groupId ? whereWithGroup : whereAllGroups}`, groupId
|
|
174
|
-
? [this.options.sessionId, target.user, target.server, target.device, groupId]
|
|
175
|
-
: [this.options.sessionId, target.user, target.server, target.device]);
|
|
176
|
-
return count;
|
|
177
|
-
}
|
|
178
|
-
upsertSenderKeyDistributionRow(db, record, sender) {
|
|
179
|
-
db.run(`INSERT INTO sender_key_distribution (
|
|
180
|
-
session_id,
|
|
181
|
-
group_id,
|
|
182
|
-
sender_user,
|
|
183
|
-
sender_server,
|
|
184
|
-
sender_device,
|
|
185
|
-
key_id,
|
|
186
|
-
timestamp_ms
|
|
187
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
188
|
-
ON CONFLICT(session_id, group_id, sender_user, sender_server, sender_device) DO UPDATE SET
|
|
189
|
-
key_id=excluded.key_id,
|
|
190
|
-
timestamp_ms=excluded.timestamp_ms`, [
|
|
191
|
-
this.options.sessionId,
|
|
192
|
-
record.groupId,
|
|
193
|
-
sender.user,
|
|
194
|
-
sender.server,
|
|
195
|
-
sender.device,
|
|
196
|
-
record.keyId,
|
|
197
|
-
record.timestampMs
|
|
198
|
-
]);
|
|
199
|
-
}
|
|
200
|
-
distributionRowKey(row) {
|
|
201
|
-
return this.distributionTargetKey((0, coercion_1.asString)(row.sender_user, 'sender_key_distribution.sender_user'), (0, coercion_1.asString)(row.sender_server, 'sender_key_distribution.sender_server'), (0, coercion_1.asNumber)(row.sender_device, 'sender_key_distribution.sender_device'));
|
|
202
|
-
}
|
|
203
|
-
distributionTargetKey(user, server, device) {
|
|
204
|
-
return `${user}|${server}|${device}`;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
exports.SenderKeySqliteStore = SenderKeySqliteStore;
|
|
@@ -1,357 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WaSignalSqliteStore = void 0;
|
|
4
|
-
const sqlite_1 = require("../../../signal/store/sqlite");
|
|
5
|
-
const BaseSqliteStore_1 = require("../../providers/sqlite/BaseSqliteStore");
|
|
6
|
-
const coercion_1 = require("../../../util/coercion");
|
|
7
|
-
const signal_address_1 = require("../../../util/signal-address");
|
|
8
|
-
const DEFAULTS = Object.freeze({
|
|
9
|
-
preKeyBatchSize: 500,
|
|
10
|
-
hasSessionBatchSize: 250
|
|
11
|
-
});
|
|
12
|
-
class WaSignalSqliteStore extends BaseSqliteStore_1.BaseSqliteStore {
|
|
13
|
-
constructor(options, storeOptions = {}) {
|
|
14
|
-
super(options, ['signal']);
|
|
15
|
-
this.preKeyBatchSize = (0, coercion_1.resolvePositive)(storeOptions.preKeyBatchSize, DEFAULTS.preKeyBatchSize, 'signal.sqlite.preKeyBatchSize');
|
|
16
|
-
this.hasSessionBatchSize = (0, coercion_1.resolvePositive)(storeOptions.hasSessionBatchSize, DEFAULTS.hasSessionBatchSize, 'signal.sqlite.hasSessionBatchSize');
|
|
17
|
-
}
|
|
18
|
-
async getRegistrationInfo() {
|
|
19
|
-
const db = await this.getConnection();
|
|
20
|
-
const row = db.get(`SELECT registration_id, identity_pub_key, identity_priv_key
|
|
21
|
-
FROM signal_registration
|
|
22
|
-
WHERE session_id = ?`, [this.options.sessionId]);
|
|
23
|
-
return row ? (0, sqlite_1.decodeSignalRegistrationRow)(row) : null;
|
|
24
|
-
}
|
|
25
|
-
async setRegistrationInfo(info) {
|
|
26
|
-
const db = await this.getConnection();
|
|
27
|
-
db.run(`INSERT INTO signal_registration (
|
|
28
|
-
session_id,
|
|
29
|
-
registration_id,
|
|
30
|
-
identity_pub_key,
|
|
31
|
-
identity_priv_key
|
|
32
|
-
) VALUES (?, ?, ?, ?)
|
|
33
|
-
ON CONFLICT(session_id) DO UPDATE SET
|
|
34
|
-
registration_id=excluded.registration_id,
|
|
35
|
-
identity_pub_key=excluded.identity_pub_key,
|
|
36
|
-
identity_priv_key=excluded.identity_priv_key`, [
|
|
37
|
-
this.options.sessionId,
|
|
38
|
-
info.registrationId,
|
|
39
|
-
info.identityKeyPair.pubKey,
|
|
40
|
-
info.identityKeyPair.privKey
|
|
41
|
-
]);
|
|
42
|
-
}
|
|
43
|
-
async getSignedPreKey() {
|
|
44
|
-
const db = await this.getConnection();
|
|
45
|
-
const row = db.get(`SELECT key_id, pub_key, priv_key, signature, uploaded
|
|
46
|
-
FROM signal_signed_prekey
|
|
47
|
-
WHERE session_id = ?`, [this.options.sessionId]);
|
|
48
|
-
return row ? (0, sqlite_1.decodeSignalSignedPreKeyRow)(row) : null;
|
|
49
|
-
}
|
|
50
|
-
async setSignedPreKey(record) {
|
|
51
|
-
const db = await this.getConnection();
|
|
52
|
-
db.run(`INSERT INTO signal_signed_prekey (
|
|
53
|
-
session_id,
|
|
54
|
-
key_id,
|
|
55
|
-
pub_key,
|
|
56
|
-
priv_key,
|
|
57
|
-
signature,
|
|
58
|
-
uploaded
|
|
59
|
-
) VALUES (?, ?, ?, ?, ?, ?)
|
|
60
|
-
ON CONFLICT(session_id) DO UPDATE SET
|
|
61
|
-
key_id=excluded.key_id,
|
|
62
|
-
pub_key=excluded.pub_key,
|
|
63
|
-
priv_key=excluded.priv_key,
|
|
64
|
-
signature=excluded.signature,
|
|
65
|
-
uploaded=excluded.uploaded`, [
|
|
66
|
-
this.options.sessionId,
|
|
67
|
-
record.keyId,
|
|
68
|
-
record.keyPair.pubKey,
|
|
69
|
-
record.keyPair.privKey,
|
|
70
|
-
record.signature,
|
|
71
|
-
record.uploaded === true ? 1 : 0
|
|
72
|
-
]);
|
|
73
|
-
}
|
|
74
|
-
async getSignedPreKeyById(keyId) {
|
|
75
|
-
const db = await this.getConnection();
|
|
76
|
-
const row = db.get(`SELECT key_id, pub_key, priv_key, signature, uploaded
|
|
77
|
-
FROM signal_signed_prekey
|
|
78
|
-
WHERE session_id = ? AND key_id = ?`, [this.options.sessionId, keyId]);
|
|
79
|
-
return row ? (0, sqlite_1.decodeSignalSignedPreKeyRow)(row) : null;
|
|
80
|
-
}
|
|
81
|
-
async setSignedPreKeyRotationTs(value) {
|
|
82
|
-
const db = await this.getConnection();
|
|
83
|
-
this.ensureMetaRow(db);
|
|
84
|
-
db.run(`UPDATE signal_meta
|
|
85
|
-
SET signed_prekey_rotation_ts = ?
|
|
86
|
-
WHERE session_id = ?`, [value, this.options.sessionId]);
|
|
87
|
-
}
|
|
88
|
-
async getSignedPreKeyRotationTs() {
|
|
89
|
-
const db = await this.getConnection();
|
|
90
|
-
const meta = this.getMeta(db);
|
|
91
|
-
return meta.signedPreKeyRotationTs;
|
|
92
|
-
}
|
|
93
|
-
async putPreKey(record) {
|
|
94
|
-
const db = await this.getConnection();
|
|
95
|
-
this.ensureMetaRow(db);
|
|
96
|
-
this.upsertPreKey(db, record);
|
|
97
|
-
db.run(`UPDATE signal_meta
|
|
98
|
-
SET next_prekey_id = MAX(next_prekey_id, ?)
|
|
99
|
-
WHERE session_id = ?`, [record.keyId + 1, this.options.sessionId]);
|
|
100
|
-
}
|
|
101
|
-
async getOrGenPreKeys(count, generator) {
|
|
102
|
-
if (!Number.isSafeInteger(count) || count <= 0) {
|
|
103
|
-
throw new Error(`invalid prekey count: ${count}`);
|
|
104
|
-
}
|
|
105
|
-
return this.withTransaction(async (db) => {
|
|
106
|
-
this.ensureMetaRow(db);
|
|
107
|
-
const available = db
|
|
108
|
-
.all(`SELECT key_id, pub_key, priv_key, uploaded
|
|
109
|
-
FROM signal_prekey
|
|
110
|
-
WHERE session_id = ? AND uploaded = 0
|
|
111
|
-
ORDER BY key_id ASC
|
|
112
|
-
LIMIT ?`, [this.options.sessionId, count])
|
|
113
|
-
.map((row) => (0, sqlite_1.decodeSignalPreKeyRow)(row));
|
|
114
|
-
if (available.length < count) {
|
|
115
|
-
let nextPreKeyId = this.getMeta(db).nextPreKeyId;
|
|
116
|
-
while (available.length < count) {
|
|
117
|
-
const requestedKeyId = nextPreKeyId;
|
|
118
|
-
const generated = await generator(requestedKeyId);
|
|
119
|
-
this.upsertPreKey(db, generated);
|
|
120
|
-
available.push(generated);
|
|
121
|
-
nextPreKeyId = Math.max(requestedKeyId + 1, generated.keyId + 1);
|
|
122
|
-
}
|
|
123
|
-
db.run(`UPDATE signal_meta
|
|
124
|
-
SET next_prekey_id = ?
|
|
125
|
-
WHERE session_id = ?`, [nextPreKeyId, this.options.sessionId]);
|
|
126
|
-
}
|
|
127
|
-
return available;
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
async getPreKeyById(keyId) {
|
|
131
|
-
const db = await this.getConnection();
|
|
132
|
-
const row = db.get(`SELECT key_id, pub_key, priv_key, uploaded
|
|
133
|
-
FROM signal_prekey
|
|
134
|
-
WHERE session_id = ? AND key_id = ?`, [this.options.sessionId, keyId]);
|
|
135
|
-
return row ? (0, sqlite_1.decodeSignalPreKeyRow)(row) : null;
|
|
136
|
-
}
|
|
137
|
-
async getPreKeysById(keyIds) {
|
|
138
|
-
if (keyIds.length === 0) {
|
|
139
|
-
return [];
|
|
140
|
-
}
|
|
141
|
-
const db = await this.getConnection();
|
|
142
|
-
const uniqueKeyIds = [...new Set(keyIds)];
|
|
143
|
-
const byId = new Map();
|
|
144
|
-
for (let start = 0; start < uniqueKeyIds.length; start += this.preKeyBatchSize) {
|
|
145
|
-
const end = Math.min(start + this.preKeyBatchSize, uniqueKeyIds.length);
|
|
146
|
-
const batchLength = end - start;
|
|
147
|
-
const placeholders = new Array(batchLength).fill('?').join(', ');
|
|
148
|
-
const params = [this.options.sessionId];
|
|
149
|
-
for (let index = start; index < end; index += 1) {
|
|
150
|
-
params.push(uniqueKeyIds[index]);
|
|
151
|
-
}
|
|
152
|
-
const rows = db.all(`SELECT key_id, pub_key, priv_key, uploaded
|
|
153
|
-
FROM signal_prekey
|
|
154
|
-
WHERE session_id = ? AND key_id IN (${placeholders})`, params);
|
|
155
|
-
for (const row of rows) {
|
|
156
|
-
const record = (0, sqlite_1.decodeSignalPreKeyRow)(row);
|
|
157
|
-
byId.set(record.keyId, record);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
return keyIds.map((keyId) => byId.get(keyId) ?? null);
|
|
161
|
-
}
|
|
162
|
-
async consumePreKeyById(keyId) {
|
|
163
|
-
return this.withTransaction((db) => {
|
|
164
|
-
const row = db.get(`SELECT key_id, pub_key, priv_key, uploaded
|
|
165
|
-
FROM signal_prekey
|
|
166
|
-
WHERE session_id = ? AND key_id = ?`, [this.options.sessionId, keyId]);
|
|
167
|
-
if (!row) {
|
|
168
|
-
return null;
|
|
169
|
-
}
|
|
170
|
-
db.run(`DELETE FROM signal_prekey
|
|
171
|
-
WHERE session_id = ? AND key_id = ?`, [this.options.sessionId, keyId]);
|
|
172
|
-
return (0, sqlite_1.decodeSignalPreKeyRow)(row);
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
async getOrGenSinglePreKey(generator) {
|
|
176
|
-
const records = await this.getOrGenPreKeys(1, generator);
|
|
177
|
-
return records[0];
|
|
178
|
-
}
|
|
179
|
-
async markKeyAsUploaded(keyId) {
|
|
180
|
-
const db = await this.getConnection();
|
|
181
|
-
const meta = this.getMeta(db);
|
|
182
|
-
if (keyId < 0 || keyId >= meta.nextPreKeyId) {
|
|
183
|
-
throw new Error(`prekey ${keyId} is out of boundary`);
|
|
184
|
-
}
|
|
185
|
-
db.run(`UPDATE signal_prekey
|
|
186
|
-
SET uploaded = 1
|
|
187
|
-
WHERE session_id = ? AND key_id <= ?`, [this.options.sessionId, keyId]);
|
|
188
|
-
}
|
|
189
|
-
async setServerHasPreKeys(value) {
|
|
190
|
-
const db = await this.getConnection();
|
|
191
|
-
this.ensureMetaRow(db);
|
|
192
|
-
db.run(`UPDATE signal_meta
|
|
193
|
-
SET server_has_prekeys = ?
|
|
194
|
-
WHERE session_id = ?`, [value ? 1 : 0, this.options.sessionId]);
|
|
195
|
-
}
|
|
196
|
-
async getServerHasPreKeys() {
|
|
197
|
-
const db = await this.getConnection();
|
|
198
|
-
const meta = this.getMeta(db);
|
|
199
|
-
return meta.serverHasPreKeys;
|
|
200
|
-
}
|
|
201
|
-
async hasSession(address) {
|
|
202
|
-
const db = await this.getConnection();
|
|
203
|
-
const target = (0, sqlite_1.toSignalAddressParts)(address);
|
|
204
|
-
return (db.get(`SELECT 1 AS has_session
|
|
205
|
-
FROM signal_session
|
|
206
|
-
WHERE session_id = ? AND user = ? AND server = ? AND device = ?
|
|
207
|
-
LIMIT 1`, [this.options.sessionId, target.user, target.server, target.device]) !== null);
|
|
208
|
-
}
|
|
209
|
-
async hasSessions(addresses) {
|
|
210
|
-
if (addresses.length === 0) {
|
|
211
|
-
return [];
|
|
212
|
-
}
|
|
213
|
-
const db = await this.getConnection();
|
|
214
|
-
const targets = addresses.map((address) => (0, sqlite_1.toSignalAddressParts)(address));
|
|
215
|
-
const existingKeys = new Set();
|
|
216
|
-
for (let start = 0; start < targets.length; start += this.hasSessionBatchSize) {
|
|
217
|
-
const end = Math.min(start + this.hasSessionBatchSize, targets.length);
|
|
218
|
-
const batchLength = end - start;
|
|
219
|
-
const filters = new Array(batchLength)
|
|
220
|
-
.fill('(user = ? AND server = ? AND device = ?)')
|
|
221
|
-
.join(' OR ');
|
|
222
|
-
const params = [this.options.sessionId];
|
|
223
|
-
for (let index = start; index < end; index += 1) {
|
|
224
|
-
const target = targets[index];
|
|
225
|
-
params.push(target.user, target.server, target.device);
|
|
226
|
-
}
|
|
227
|
-
const rows = db.all(`SELECT user, server, device
|
|
228
|
-
FROM signal_session
|
|
229
|
-
WHERE session_id = ? AND (${filters})`, params);
|
|
230
|
-
for (const row of rows) {
|
|
231
|
-
existingKeys.add((0, signal_address_1.signalAddressKey)({
|
|
232
|
-
user: (0, coercion_1.asString)(row.user, 'signal_session.user'),
|
|
233
|
-
server: (0, coercion_1.asString)(row.server, 'signal_session.server'),
|
|
234
|
-
device: (0, coercion_1.asNumber)(row.device, 'signal_session.device')
|
|
235
|
-
}));
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
return addresses.map((address) => existingKeys.has((0, signal_address_1.signalAddressKey)(address)));
|
|
239
|
-
}
|
|
240
|
-
async getSession(address) {
|
|
241
|
-
const db = await this.getConnection();
|
|
242
|
-
const target = (0, sqlite_1.toSignalAddressParts)(address);
|
|
243
|
-
const row = db.get(`SELECT user, server, device, record
|
|
244
|
-
FROM signal_session
|
|
245
|
-
WHERE session_id = ? AND user = ? AND server = ? AND device = ?`, [this.options.sessionId, target.user, target.server, target.device]);
|
|
246
|
-
return row ? (0, sqlite_1.decodeSignalSessionRecord)(row.record) : null;
|
|
247
|
-
}
|
|
248
|
-
async setSession(address, session) {
|
|
249
|
-
const db = await this.getConnection();
|
|
250
|
-
const target = (0, sqlite_1.toSignalAddressParts)(address);
|
|
251
|
-
db.run(`INSERT INTO signal_session (
|
|
252
|
-
session_id,
|
|
253
|
-
user,
|
|
254
|
-
server,
|
|
255
|
-
device,
|
|
256
|
-
record
|
|
257
|
-
) VALUES (?, ?, ?, ?, ?)
|
|
258
|
-
ON CONFLICT(session_id, user, server, device) DO UPDATE SET
|
|
259
|
-
record=excluded.record`, [
|
|
260
|
-
this.options.sessionId,
|
|
261
|
-
target.user,
|
|
262
|
-
target.server,
|
|
263
|
-
target.device,
|
|
264
|
-
(0, sqlite_1.encodeSignalSessionRecord)(session)
|
|
265
|
-
]);
|
|
266
|
-
}
|
|
267
|
-
async deleteSession(address) {
|
|
268
|
-
const db = await this.getConnection();
|
|
269
|
-
const target = (0, sqlite_1.toSignalAddressParts)(address);
|
|
270
|
-
db.run(`DELETE FROM signal_session
|
|
271
|
-
WHERE session_id = ? AND user = ? AND server = ? AND device = ?`, [this.options.sessionId, target.user, target.server, target.device]);
|
|
272
|
-
}
|
|
273
|
-
async getRemoteIdentity(address) {
|
|
274
|
-
const db = await this.getConnection();
|
|
275
|
-
const target = (0, sqlite_1.toSignalAddressParts)(address);
|
|
276
|
-
const row = db.get(`SELECT identity_key
|
|
277
|
-
FROM signal_identity
|
|
278
|
-
WHERE session_id = ? AND user = ? AND server = ? AND device = ?`, [this.options.sessionId, target.user, target.server, target.device]);
|
|
279
|
-
return row ? (0, sqlite_1.decodeSignalRemoteIdentity)(row.identity_key) : null;
|
|
280
|
-
}
|
|
281
|
-
async setRemoteIdentity(address, identityKey) {
|
|
282
|
-
const db = await this.getConnection();
|
|
283
|
-
const target = (0, sqlite_1.toSignalAddressParts)(address);
|
|
284
|
-
this.upsertRemoteIdentity(db, target, identityKey);
|
|
285
|
-
}
|
|
286
|
-
async setRemoteIdentities(entries) {
|
|
287
|
-
if (entries.length === 0) {
|
|
288
|
-
return;
|
|
289
|
-
}
|
|
290
|
-
await this.withTransaction((db) => {
|
|
291
|
-
for (const entry of entries) {
|
|
292
|
-
const target = (0, sqlite_1.toSignalAddressParts)(entry.address);
|
|
293
|
-
this.upsertRemoteIdentity(db, target, entry.identityKey);
|
|
294
|
-
}
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
async clear() {
|
|
298
|
-
await this.withTransaction((db) => {
|
|
299
|
-
db.run('DELETE FROM signal_registration WHERE session_id = ?', [this.options.sessionId]);
|
|
300
|
-
db.run('DELETE FROM signal_signed_prekey WHERE session_id = ?', [this.options.sessionId]);
|
|
301
|
-
db.run('DELETE FROM signal_prekey WHERE session_id = ?', [this.options.sessionId]);
|
|
302
|
-
db.run('DELETE FROM signal_session WHERE session_id = ?', [this.options.sessionId]);
|
|
303
|
-
db.run('DELETE FROM signal_identity WHERE session_id = ?', [this.options.sessionId]);
|
|
304
|
-
db.run('DELETE FROM signal_meta WHERE session_id = ?', [this.options.sessionId]);
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
upsertPreKey(db, record) {
|
|
308
|
-
db.run(`INSERT INTO signal_prekey (
|
|
309
|
-
session_id,
|
|
310
|
-
key_id,
|
|
311
|
-
pub_key,
|
|
312
|
-
priv_key,
|
|
313
|
-
uploaded
|
|
314
|
-
) VALUES (?, ?, ?, ?, ?)
|
|
315
|
-
ON CONFLICT(session_id, key_id) DO UPDATE SET
|
|
316
|
-
pub_key=excluded.pub_key,
|
|
317
|
-
priv_key=excluded.priv_key,
|
|
318
|
-
uploaded=excluded.uploaded`, [
|
|
319
|
-
this.options.sessionId,
|
|
320
|
-
record.keyId,
|
|
321
|
-
record.keyPair.pubKey,
|
|
322
|
-
record.keyPair.privKey,
|
|
323
|
-
record.uploaded === true ? 1 : 0
|
|
324
|
-
]);
|
|
325
|
-
}
|
|
326
|
-
ensureMetaRow(db) {
|
|
327
|
-
db.run(`INSERT INTO signal_meta (
|
|
328
|
-
session_id,
|
|
329
|
-
server_has_prekeys,
|
|
330
|
-
next_prekey_id
|
|
331
|
-
) VALUES (?, 0, 1)
|
|
332
|
-
ON CONFLICT(session_id) DO NOTHING`, [this.options.sessionId]);
|
|
333
|
-
}
|
|
334
|
-
getMeta(db) {
|
|
335
|
-
this.ensureMetaRow(db);
|
|
336
|
-
const row = db.get(`SELECT server_has_prekeys, next_prekey_id, signed_prekey_rotation_ts
|
|
337
|
-
FROM signal_meta
|
|
338
|
-
WHERE session_id = ?`, [this.options.sessionId]);
|
|
339
|
-
return {
|
|
340
|
-
serverHasPreKeys: (0, coercion_1.toBoolOrUndef)(row.server_has_prekeys) === true,
|
|
341
|
-
nextPreKeyId: (0, coercion_1.asNumber)(row.next_prekey_id, 'signal_meta.next_prekey_id'),
|
|
342
|
-
signedPreKeyRotationTs: (0, coercion_1.asOptionalNumber)(row.signed_prekey_rotation_ts, 'signal_meta.signed_prekey_rotation_ts') ?? null
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
upsertRemoteIdentity(db, target, identityKey) {
|
|
346
|
-
db.run(`INSERT INTO signal_identity (
|
|
347
|
-
session_id,
|
|
348
|
-
user,
|
|
349
|
-
server,
|
|
350
|
-
device,
|
|
351
|
-
identity_key
|
|
352
|
-
) VALUES (?, ?, ?, ?, ?)
|
|
353
|
-
ON CONFLICT(session_id, user, server, device) DO UPDATE SET
|
|
354
|
-
identity_key=excluded.identity_key`, [this.options.sessionId, target.user, target.server, target.device, identityKey]);
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
exports.WaSignalSqliteStore = WaSignalSqliteStore;
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WaThreadSqliteStore = void 0;
|
|
4
|
-
const BaseSqliteStore_1 = require("../../providers/sqlite/BaseSqliteStore");
|
|
5
|
-
const coercion_1 = require("../../../util/coercion");
|
|
6
|
-
const collections_1 = require("../../../util/collections");
|
|
7
|
-
const THREAD_COLUMNS = 'jid, name, unread_count, archived, pinned, mute_end_ms, marked_as_unread, ephemeral_expiration';
|
|
8
|
-
function decodeThreadRow(row) {
|
|
9
|
-
return {
|
|
10
|
-
jid: (0, coercion_1.asString)(row.jid, 'mailbox_threads.jid'),
|
|
11
|
-
name: (0, coercion_1.asOptionalString)(row.name, 'mailbox_threads.name'),
|
|
12
|
-
unreadCount: (0, coercion_1.asOptionalNumber)(row.unread_count, 'mailbox_threads.unread_count'),
|
|
13
|
-
archived: (0, coercion_1.toBoolOrUndef)(row.archived),
|
|
14
|
-
pinned: (0, coercion_1.asOptionalNumber)(row.pinned, 'mailbox_threads.pinned'),
|
|
15
|
-
muteEndMs: (0, coercion_1.asOptionalNumber)(row.mute_end_ms, 'mailbox_threads.mute_end_ms'),
|
|
16
|
-
markedAsUnread: (0, coercion_1.toBoolOrUndef)(row.marked_as_unread),
|
|
17
|
-
ephemeralExpiration: (0, coercion_1.asOptionalNumber)(row.ephemeral_expiration, 'mailbox_threads.ephemeral_expiration')
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
class WaThreadSqliteStore extends BaseSqliteStore_1.BaseSqliteStore {
|
|
21
|
-
constructor(options) {
|
|
22
|
-
super(options, ['mailbox']);
|
|
23
|
-
}
|
|
24
|
-
async upsert(record) {
|
|
25
|
-
const db = await this.getConnection();
|
|
26
|
-
db.run(`INSERT INTO mailbox_threads (
|
|
27
|
-
session_id, jid, name, unread_count, archived, pinned,
|
|
28
|
-
mute_end_ms, marked_as_unread, ephemeral_expiration
|
|
29
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
30
|
-
ON CONFLICT(session_id, jid) DO UPDATE SET
|
|
31
|
-
name=COALESCE(excluded.name, mailbox_threads.name),
|
|
32
|
-
unread_count=COALESCE(excluded.unread_count, mailbox_threads.unread_count),
|
|
33
|
-
archived=COALESCE(excluded.archived, mailbox_threads.archived),
|
|
34
|
-
pinned=COALESCE(excluded.pinned, mailbox_threads.pinned),
|
|
35
|
-
mute_end_ms=COALESCE(excluded.mute_end_ms, mailbox_threads.mute_end_ms),
|
|
36
|
-
marked_as_unread=COALESCE(excluded.marked_as_unread, mailbox_threads.marked_as_unread),
|
|
37
|
-
ephemeral_expiration=COALESCE(excluded.ephemeral_expiration, mailbox_threads.ephemeral_expiration)`, [
|
|
38
|
-
this.options.sessionId,
|
|
39
|
-
record.jid,
|
|
40
|
-
record.name ?? null,
|
|
41
|
-
record.unreadCount ?? null,
|
|
42
|
-
record.archived === undefined ? null : record.archived ? 1 : 0,
|
|
43
|
-
record.pinned ?? null,
|
|
44
|
-
record.muteEndMs ?? null,
|
|
45
|
-
record.markedAsUnread === undefined ? null : record.markedAsUnread ? 1 : 0,
|
|
46
|
-
record.ephemeralExpiration ?? null
|
|
47
|
-
]);
|
|
48
|
-
}
|
|
49
|
-
async getByJid(jid) {
|
|
50
|
-
const db = await this.getConnection();
|
|
51
|
-
const row = db.get(`SELECT ${THREAD_COLUMNS}
|
|
52
|
-
FROM mailbox_threads
|
|
53
|
-
WHERE session_id = ? AND jid = ?`, [this.options.sessionId, jid]);
|
|
54
|
-
return row ? decodeThreadRow(row) : null;
|
|
55
|
-
}
|
|
56
|
-
async list(limit) {
|
|
57
|
-
const db = await this.getConnection();
|
|
58
|
-
const rows = db.all(`SELECT ${THREAD_COLUMNS}
|
|
59
|
-
FROM mailbox_threads
|
|
60
|
-
WHERE session_id = ?
|
|
61
|
-
LIMIT ?`, [this.options.sessionId, (0, collections_1.normalizeQueryLimit)(limit, 100)]);
|
|
62
|
-
return rows.map(decodeThreadRow);
|
|
63
|
-
}
|
|
64
|
-
async deleteByJid(jid) {
|
|
65
|
-
const db = await this.getConnection();
|
|
66
|
-
db.run(`DELETE FROM mailbox_threads
|
|
67
|
-
WHERE session_id = ? AND jid = ?`, [this.options.sessionId, jid]);
|
|
68
|
-
const row = db.get('SELECT changes() AS total', []);
|
|
69
|
-
return row ? Number(row.total) : 0;
|
|
70
|
-
}
|
|
71
|
-
async clear() {
|
|
72
|
-
const db = await this.getConnection();
|
|
73
|
-
db.run('DELETE FROM mailbox_threads WHERE session_id = ?', [this.options.sessionId]);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
exports.WaThreadSqliteStore = WaThreadSqliteStore;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { WaAppStateStoreData, WaAppStateSyncKey } from '../types';
|
|
2
|
-
export interface AppStateSyncKeyRow extends Record<string, unknown> {
|
|
3
|
-
readonly key_id: unknown;
|
|
4
|
-
readonly key_data: unknown;
|
|
5
|
-
readonly timestamp: unknown;
|
|
6
|
-
readonly fingerprint: unknown;
|
|
7
|
-
}
|
|
8
|
-
export interface AppStateCollectionVersionRow extends Record<string, unknown> {
|
|
9
|
-
readonly collection: unknown;
|
|
10
|
-
readonly version: unknown;
|
|
11
|
-
readonly hash: unknown;
|
|
12
|
-
}
|
|
13
|
-
export interface AppStateCollectionValueRow extends Record<string, unknown> {
|
|
14
|
-
readonly collection: unknown;
|
|
15
|
-
readonly index_mac_hex: unknown;
|
|
16
|
-
readonly value_mac: unknown;
|
|
17
|
-
}
|
|
18
|
-
export declare function encodeAppStateFingerprint(fingerprint: WaAppStateSyncKey['fingerprint']): Uint8Array | null;
|
|
19
|
-
export declare function decodeAppStateFingerprint(raw: unknown): WaAppStateSyncKey['fingerprint'] | undefined;
|
|
20
|
-
export declare function decodeAppStateSyncKeys(rows: readonly AppStateSyncKeyRow[]): readonly WaAppStateSyncKey[];
|
|
21
|
-
export declare function decodeAppStateCollections(versionRows: readonly AppStateCollectionVersionRow[], valueRows: readonly AppStateCollectionValueRow[]): WaAppStateStoreData['collections'];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const SERIALIZED_PUB_KEY_PREFIX = 5;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base64 URL encoding utilities
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Decodes a base64url encoded string to Uint8Array
|
|
6
|
-
*/
|
|
7
|
-
export declare function decodeBase64Url(value: string | undefined, field: string): Uint8Array;
|
|
8
|
-
/**
|
|
9
|
-
* Asserts that a Uint8Array is exactly 32 bytes
|
|
10
|
-
*/
|
|
11
|
-
export declare function assert32(value: Uint8Array, name: string): void;
|