zapo-js 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -4
- package/dist/appstate/WaAppStateCrypto.js +1 -1
- package/dist/appstate/WaAppStateSyncClient.js +138 -93
- package/dist/appstate/{store/sqlite.js → encoding.js} +13 -8
- package/dist/appstate/index.js +8 -6
- package/dist/appstate/utils.js +0 -5
- package/dist/auth/WaAuthClient.js +36 -47
- package/dist/auth/flow/WaAuthCredentialsFlow.js +7 -7
- package/dist/auth/index.js +1 -6
- package/dist/auth/pairing/WaPairingCodeCrypto.js +6 -4
- package/dist/auth/pairing/WaPairingFlow.js +13 -3
- package/dist/client/WaClient.js +225 -101
- package/dist/client/WaClientFactory.js +294 -44
- package/dist/client/connection/WaConnectionManager.js +19 -10
- package/dist/client/coordinators/WaBusinessCoordinator.js +241 -0
- package/dist/client/coordinators/WaGroupCoordinator.js +11 -7
- package/dist/client/coordinators/WaIncomingNodeCoordinator.js +1 -0
- package/dist/client/coordinators/WaMessageDispatchCoordinator.js +292 -99
- package/dist/client/coordinators/WaPassiveTasksCoordinator.js +74 -31
- package/dist/client/coordinators/WaPrivacyCoordinator.js +134 -0
- package/dist/client/coordinators/WaProfileCoordinator.js +212 -0
- package/dist/client/coordinators/WaRetryCoordinator.js +179 -27
- package/dist/client/coordinators/WaStreamControlCoordinator.js +18 -11
- package/dist/client/coordinators/WaTrustedContactTokenCoordinator.js +166 -0
- package/dist/client/dirty.js +40 -20
- package/dist/client/events/devices.js +72 -0
- package/dist/client/events/group.js +3 -11
- package/dist/client/events/identity.js +22 -0
- package/dist/client/events/privacy-token.js +39 -0
- package/dist/client/history-sync.js +50 -9
- package/dist/client/incoming.js +37 -7
- package/dist/client/mailbox.js +24 -23
- package/dist/client/messages.js +107 -31
- package/dist/client/messaging/fanout.js +21 -11
- package/dist/client/messaging/participants.js +6 -4
- package/dist/client/persistence/WriteBehindPersistence.js +129 -0
- package/dist/client/tokens/cs-token.js +50 -0
- package/dist/client/tokens/tc-token.js +25 -0
- package/dist/crypto/core/index.js +2 -2
- package/dist/crypto/core/keys.js +4 -4
- package/dist/crypto/core/nonce.js +2 -0
- package/dist/crypto/core/primitives.js +0 -8
- package/dist/crypto/core/random.js +22 -0
- package/dist/crypto/curves/X25519.js +25 -6
- package/dist/crypto/index.js +3 -0
- package/dist/crypto/math/constants.js +13 -36
- package/dist/crypto/math/edwards.js +171 -44
- package/dist/crypto/math/fe.js +706 -0
- package/dist/crypto/math/mod.js +10 -3
- package/dist/esm/appstate/WaAppStateCrypto.js +1 -1
- package/dist/esm/appstate/WaAppStateSyncClient.js +138 -93
- package/dist/esm/appstate/{store/sqlite.js → encoding.js} +13 -8
- package/dist/esm/appstate/index.js +2 -2
- package/dist/esm/appstate/utils.js +2 -5
- package/dist/esm/auth/WaAuthClient.js +36 -47
- package/dist/esm/auth/flow/WaAuthCredentialsFlow.js +7 -7
- package/dist/esm/auth/index.js +0 -2
- package/dist/esm/auth/pairing/WaPairingCodeCrypto.js +6 -4
- package/dist/esm/auth/pairing/WaPairingFlow.js +14 -4
- package/dist/esm/client/WaClient.js +225 -101
- package/dist/esm/client/WaClientFactory.js +295 -45
- package/dist/esm/client/connection/WaConnectionManager.js +19 -10
- package/dist/esm/client/coordinators/WaBusinessCoordinator.js +238 -0
- package/dist/esm/client/coordinators/WaGroupCoordinator.js +11 -7
- package/dist/esm/client/coordinators/WaIncomingNodeCoordinator.js +1 -0
- package/dist/esm/client/coordinators/WaMessageDispatchCoordinator.js +295 -102
- package/dist/esm/client/coordinators/WaPassiveTasksCoordinator.js +74 -31
- package/dist/esm/client/coordinators/WaPrivacyCoordinator.js +131 -0
- package/dist/esm/client/coordinators/WaProfileCoordinator.js +209 -0
- package/dist/esm/client/coordinators/WaRetryCoordinator.js +181 -29
- package/dist/esm/client/coordinators/WaStreamControlCoordinator.js +19 -12
- package/dist/esm/client/coordinators/WaTrustedContactTokenCoordinator.js +162 -0
- package/dist/esm/client/dirty.js +40 -20
- package/dist/esm/client/events/devices.js +68 -0
- package/dist/esm/client/events/group.js +3 -11
- package/dist/esm/client/events/identity.js +19 -0
- package/dist/esm/client/events/privacy-token.js +36 -0
- package/dist/esm/client/history-sync.js +50 -9
- package/dist/esm/client/incoming.js +38 -8
- package/dist/esm/client/mailbox.js +24 -23
- package/dist/esm/client/messages.js +108 -32
- package/dist/esm/client/messaging/fanout.js +22 -12
- package/dist/esm/client/messaging/participants.js +6 -4
- package/dist/esm/client/persistence/WriteBehindPersistence.js +125 -0
- package/dist/esm/client/tokens/cs-token.js +46 -0
- package/dist/esm/client/tokens/tc-token.js +18 -0
- package/dist/esm/crypto/core/index.js +2 -2
- package/dist/esm/crypto/core/keys.js +1 -1
- package/dist/esm/crypto/core/nonce.js +2 -0
- package/dist/esm/crypto/core/primitives.js +0 -7
- package/dist/esm/crypto/core/random.js +22 -1
- package/dist/esm/crypto/curves/X25519.js +25 -6
- package/dist/esm/crypto/index.js +1 -0
- package/dist/esm/crypto/math/constants.js +12 -35
- package/dist/esm/crypto/math/edwards.js +174 -47
- package/dist/esm/crypto/math/fe.js +691 -0
- package/dist/esm/crypto/math/mod.js +10 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/infra/perf/BackgroundQueue.js +478 -0
- package/dist/esm/infra/perf/BoundedTaskQueue.js +3 -1
- package/dist/esm/infra/perf/PromiseDedup.js +20 -0
- package/dist/esm/infra/perf/SharedExclusiveGate.js +109 -0
- package/dist/esm/infra/perf/StoreLock.js +77 -0
- package/dist/esm/media/WaMediaCrypto.js +95 -13
- package/dist/esm/media/WaMediaTransferClient.js +39 -47
- package/dist/esm/media/constants.js +2 -1
- package/dist/esm/message/WaMessageClient.js +26 -19
- package/dist/esm/message/content.js +195 -9
- package/dist/esm/message/icdc.js +76 -0
- package/dist/esm/message/incoming.js +24 -12
- package/dist/esm/message/phash.js +3 -1
- package/dist/esm/message/reporting-token.js +14 -27
- package/dist/esm/protocol/appstate.js +9 -40
- package/dist/esm/protocol/browser.js +10 -18
- package/dist/esm/protocol/constants.js +5 -3
- package/dist/esm/protocol/defaults.js +6 -0
- package/dist/esm/protocol/index.js +1 -2
- package/dist/esm/protocol/jid.js +105 -36
- package/dist/esm/protocol/message.js +61 -1
- package/dist/esm/protocol/nodes.js +2 -0
- package/dist/esm/protocol/notification.js +3 -1
- package/dist/esm/protocol/privacy-token.js +17 -0
- package/dist/esm/protocol/privacy.js +55 -0
- package/dist/esm/protocol/stream.js +26 -1
- package/dist/esm/retry/codec.js +216 -0
- package/dist/esm/retry/constants.js +1 -1
- package/dist/esm/retry/index.js +2 -2
- package/dist/esm/retry/parse.js +50 -30
- package/dist/esm/retry/replay.js +11 -7
- package/dist/esm/retry/tracker.js +50 -12
- package/dist/esm/signal/api/SignalDeviceSyncApi.js +49 -32
- package/dist/esm/signal/api/SignalDigestSyncApi.js +13 -9
- package/dist/esm/signal/api/SignalIdentitySyncApi.js +26 -11
- package/dist/esm/signal/api/SignalMissingPreKeysSyncApi.js +18 -7
- package/dist/esm/signal/api/SignalRotateKeyApi.js +4 -2
- package/dist/esm/signal/api/SignalSessionSyncApi.js +16 -7
- package/dist/esm/signal/api/result-map.js +10 -0
- package/dist/esm/signal/constants.js +0 -4
- package/dist/esm/signal/crypto/WaAdvSignature.js +12 -6
- package/dist/esm/signal/{store/sqlite.js → encoding.js} +78 -24
- package/dist/esm/signal/group/SenderKeyCodec.js +3 -2
- package/dist/esm/signal/group/SenderKeyManager.js +125 -106
- package/dist/esm/signal/index.js +1 -0
- package/dist/esm/signal/registration/keygen.js +6 -2
- package/dist/esm/signal/registration/utils.js +1 -0
- package/dist/esm/signal/session/SignalProtocol.js +150 -74
- package/dist/esm/signal/session/resolver.js +137 -102
- package/dist/esm/store/contracts/privacy-token.store.js +1 -0
- package/dist/esm/store/createStore.js +101 -187
- package/dist/esm/store/index.js +1 -10
- package/dist/esm/store/locks/appstate.lock.js +26 -0
- package/dist/esm/store/locks/auth.lock.js +15 -0
- package/dist/esm/store/locks/contact.lock.js +20 -0
- package/dist/esm/store/locks/device-list.lock.js +20 -0
- package/dist/esm/store/locks/message.lock.js +21 -0
- package/dist/esm/store/locks/participants.lock.js +20 -0
- package/dist/esm/store/locks/privacy-token.lock.js +18 -0
- package/dist/esm/store/locks/retry.lock.js +29 -0
- package/dist/esm/store/locks/sender-key.lock.js +52 -0
- package/dist/esm/store/locks/signal.lock.js +63 -0
- package/dist/esm/store/locks/thread.lock.js +21 -0
- package/dist/esm/store/noop.store.js +1 -1
- package/dist/esm/store/providers/memory/appstate.store.js +22 -24
- package/dist/esm/store/providers/memory/device-list.store.js +10 -5
- package/dist/esm/store/providers/memory/privacy-token.store.js +43 -0
- package/dist/esm/store/providers/memory/retry.store.js +77 -2
- package/dist/esm/store/providers/memory/sender-key.store.js +6 -1
- package/dist/esm/store/providers/memory/signal.store.js +36 -19
- package/dist/esm/transport/WaComms.js +3 -1
- package/dist/esm/transport/WaWebSocket.js +0 -6
- package/dist/esm/transport/binary/constants.js +0 -30
- package/dist/esm/transport/binary/decoder.js +4 -4
- package/dist/esm/transport/binary/encoder.js +8 -15
- package/dist/esm/transport/binary/index.js +0 -1
- package/dist/esm/transport/node/WaNodeOrchestrator.js +25 -19
- package/dist/esm/transport/node/builders/business.js +129 -0
- package/dist/esm/transport/node/builders/global.js +370 -0
- package/dist/esm/transport/node/builders/index.js +5 -2
- package/dist/esm/transport/node/builders/message.js +63 -239
- package/dist/esm/transport/node/builders/pairing.js +0 -24
- package/dist/esm/transport/node/builders/privacy-token.js +41 -0
- package/dist/esm/transport/node/builders/privacy.js +48 -0
- package/dist/esm/transport/node/builders/profile.js +70 -0
- package/dist/esm/transport/node/builders/retry.js +10 -22
- package/dist/esm/transport/node/builders/usync.js +6 -2
- package/dist/esm/transport/node/helpers.js +19 -1
- package/dist/esm/transport/node/usync.js +3 -33
- package/dist/esm/transport/node/xml.js +35 -14
- package/dist/esm/transport/noise/WaClientPayload.js +10 -10
- package/dist/esm/transport/noise/WaNoiseCert.js +3 -3
- package/dist/esm/transport/noise/WaNoiseSession.js +64 -23
- package/dist/esm/transport/noise/WaNoiseSocket.js +8 -4
- package/dist/esm/transport/stream/parse.js +8 -4
- package/dist/esm/util/bytes.js +22 -18
- package/dist/esm/util/index.js +5 -0
- package/dist/esm/util/primitives.js +3 -2
- package/dist/index.js +7 -1
- package/dist/infra/perf/BackgroundQueue.js +482 -0
- package/dist/infra/perf/BoundedTaskQueue.js +3 -1
- package/dist/infra/perf/PromiseDedup.js +24 -0
- package/dist/infra/perf/SharedExclusiveGate.js +113 -0
- package/dist/infra/perf/StoreLock.js +81 -0
- package/dist/media/WaMediaCrypto.js +94 -12
- package/dist/media/WaMediaTransferClient.js +39 -47
- package/dist/media/constants.js +2 -1
- package/dist/message/WaMessageClient.js +26 -19
- package/dist/message/content.js +198 -9
- package/dist/message/icdc.js +81 -0
- package/dist/message/incoming.js +24 -12
- package/dist/message/phash.js +3 -1
- package/dist/message/reporting-token.js +14 -28
- package/dist/protocol/appstate.js +10 -41
- package/dist/protocol/browser.js +10 -18
- package/dist/protocol/constants.js +21 -2
- package/dist/protocol/defaults.js +6 -0
- package/dist/protocol/index.js +8 -5
- package/dist/protocol/jid.js +111 -36
- package/dist/protocol/message.js +62 -2
- package/dist/protocol/nodes.js +2 -0
- package/dist/protocol/notification.js +3 -1
- package/dist/protocol/privacy-token.js +20 -0
- package/dist/protocol/privacy.js +58 -0
- package/dist/protocol/stream.js +27 -2
- package/dist/retry/codec.js +220 -0
- package/dist/retry/constants.js +1 -1
- package/dist/retry/index.js +5 -5
- package/dist/retry/parse.js +51 -30
- package/dist/retry/replay.js +10 -6
- package/dist/retry/tracker.js +50 -12
- package/dist/signal/api/SignalDeviceSyncApi.js +48 -31
- package/dist/signal/api/SignalDigestSyncApi.js +13 -9
- package/dist/signal/api/SignalIdentitySyncApi.js +25 -10
- package/dist/signal/api/SignalMissingPreKeysSyncApi.js +17 -6
- package/dist/signal/api/SignalRotateKeyApi.js +4 -2
- package/dist/signal/api/SignalSessionSyncApi.js +16 -7
- package/dist/signal/api/result-map.js +13 -0
- package/dist/signal/constants.js +1 -5
- package/dist/signal/crypto/WaAdvSignature.js +11 -5
- package/dist/signal/{store/sqlite.js → encoding.js} +79 -25
- package/dist/signal/group/SenderKeyCodec.js +4 -3
- package/dist/signal/group/SenderKeyManager.js +125 -106
- package/dist/signal/index.js +13 -1
- package/dist/signal/registration/keygen.js +6 -2
- package/dist/signal/registration/utils.js +1 -0
- package/dist/signal/session/SignalProtocol.js +150 -74
- package/dist/signal/session/resolver.js +135 -100
- package/dist/store/contracts/privacy-token.store.js +2 -0
- package/dist/store/createStore.js +101 -187
- package/dist/store/index.js +15 -33
- package/dist/store/locks/appstate.lock.js +29 -0
- package/dist/store/locks/auth.lock.js +18 -0
- package/dist/store/locks/contact.lock.js +23 -0
- package/dist/store/locks/device-list.lock.js +23 -0
- package/dist/store/locks/message.lock.js +24 -0
- package/dist/store/locks/participants.lock.js +23 -0
- package/dist/store/locks/privacy-token.lock.js +21 -0
- package/dist/store/locks/retry.lock.js +32 -0
- package/dist/store/locks/sender-key.lock.js +55 -0
- package/dist/store/locks/signal.lock.js +66 -0
- package/dist/store/locks/thread.lock.js +24 -0
- package/dist/store/noop.store.js +1 -1
- package/dist/store/providers/memory/appstate.store.js +22 -24
- package/dist/store/providers/memory/device-list.store.js +10 -5
- package/dist/store/providers/memory/privacy-token.store.js +47 -0
- package/dist/store/providers/memory/retry.store.js +77 -2
- package/dist/store/providers/memory/sender-key.store.js +6 -1
- package/dist/store/providers/memory/signal.store.js +36 -19
- package/dist/transport/WaComms.js +3 -1
- package/dist/transport/WaWebSocket.js +0 -6
- package/dist/transport/binary/constants.js +1 -31
- package/dist/transport/binary/decoder.js +4 -4
- package/dist/transport/binary/encoder.js +8 -15
- package/dist/transport/binary/index.js +0 -4
- package/dist/transport/node/WaNodeOrchestrator.js +24 -18
- package/dist/transport/node/builders/business.js +137 -0
- package/dist/transport/node/builders/global.js +375 -0
- package/dist/transport/node/builders/index.js +18 -9
- package/dist/transport/node/builders/message.js +64 -245
- package/dist/transport/node/builders/pairing.js +0 -26
- package/dist/transport/node/builders/privacy-token.js +46 -0
- package/dist/transport/node/builders/privacy.js +55 -0
- package/dist/transport/node/builders/profile.js +78 -0
- package/dist/transport/node/builders/retry.js +9 -21
- package/dist/transport/node/builders/usync.js +6 -2
- package/dist/transport/node/helpers.js +20 -1
- package/dist/transport/node/usync.js +2 -32
- package/dist/transport/node/xml.js +35 -14
- package/dist/transport/noise/WaClientPayload.js +13 -13
- package/dist/transport/noise/WaNoiseCert.js +2 -2
- package/dist/transport/noise/WaNoiseSession.js +64 -23
- package/dist/transport/noise/WaNoiseSocket.js +8 -4
- package/dist/transport/stream/parse.js +7 -3
- package/dist/types/appstate/encoding.d.ts +7 -0
- package/dist/types/appstate/index.d.ts +3 -3
- package/dist/types/appstate/utils.d.ts +0 -2
- package/dist/types/auth/flow/WaAuthCredentialsFlow.d.ts +1 -1
- package/dist/types/auth/index.d.ts +0 -2
- package/dist/types/auth/types.d.ts +1 -0
- package/dist/types/client/WaClient.d.ts +27 -12
- package/dist/types/client/WaClientFactory.d.ts +12 -4
- package/dist/types/client/connection/WaConnectionManager.d.ts +2 -0
- package/dist/types/client/coordinators/WaBusinessCoordinator.d.ts +57 -0
- package/dist/types/client/coordinators/WaIncomingNodeCoordinator.d.ts +3 -1
- package/dist/types/client/coordinators/WaMessageDispatchCoordinator.d.ts +14 -0
- package/dist/types/client/coordinators/WaPassiveTasksCoordinator.d.ts +4 -0
- package/dist/types/client/coordinators/WaPrivacyCoordinator.d.ts +26 -0
- package/dist/types/client/coordinators/WaProfileCoordinator.d.ts +36 -0
- package/dist/types/client/coordinators/WaRetryCoordinator.d.ts +6 -0
- package/dist/types/client/coordinators/WaStreamControlCoordinator.d.ts +3 -2
- package/dist/types/client/coordinators/WaTrustedContactTokenCoordinator.d.ts +45 -0
- package/dist/types/client/events/devices.d.ts +20 -0
- package/dist/types/client/events/identity.d.ts +9 -0
- package/dist/types/client/events/privacy-token.d.ts +7 -0
- package/dist/types/client/history-sync.d.ts +9 -6
- package/dist/types/client/incoming.d.ts +3 -1
- package/dist/types/client/index.d.ts +1 -1
- package/dist/types/client/mailbox.d.ts +3 -5
- package/dist/types/client/messages.d.ts +1 -2
- package/dist/types/client/persistence/WriteBehindPersistence.d.ts +34 -0
- package/dist/types/client/tokens/cs-token.d.ts +10 -0
- package/dist/types/client/tokens/tc-token.d.ts +5 -0
- package/dist/types/client/types.d.ts +51 -3
- package/dist/types/crypto/core/index.d.ts +2 -2
- package/dist/types/crypto/core/nonce.d.ts +2 -0
- package/dist/types/crypto/core/primitives.d.ts +0 -1
- package/dist/types/crypto/core/random.d.ts +1 -0
- package/dist/types/crypto/index.d.ts +1 -0
- package/dist/types/crypto/math/constants.d.ts +4 -2
- package/dist/types/crypto/math/fe.d.ts +30 -0
- package/dist/types/crypto/math/mod.d.ts +0 -2
- package/dist/types/crypto/math/types.d.ts +11 -4
- package/dist/types/index.d.ts +5 -3
- package/dist/types/infra/perf/BackgroundQueue.d.ts +58 -0
- package/dist/types/infra/perf/PromiseDedup.d.ts +4 -0
- package/dist/types/infra/perf/SharedExclusiveGate.d.ts +17 -0
- package/dist/types/infra/perf/StoreLock.d.ts +10 -0
- package/dist/types/media/WaMediaCrypto.d.ts +3 -2
- package/dist/types/media/WaMediaTransferClient.d.ts +3 -12
- package/dist/types/media/constants.d.ts +1 -1
- package/dist/types/media/index.d.ts +1 -1
- package/dist/types/media/types.d.ts +10 -2
- package/dist/types/message/content.d.ts +8 -0
- package/dist/types/message/icdc.d.ts +13 -0
- package/dist/types/message/reporting-token.d.ts +0 -1
- package/dist/types/message/types.d.ts +45 -6
- package/dist/types/protocol/appstate.d.ts +0 -11
- package/dist/types/protocol/constants.d.ts +7 -3
- package/dist/types/protocol/defaults.d.ts +6 -0
- package/dist/types/protocol/index.d.ts +1 -2
- package/dist/types/protocol/jid.d.ts +19 -2
- package/dist/types/protocol/message.d.ts +60 -0
- package/dist/types/protocol/nodes.d.ts +2 -0
- package/dist/types/protocol/notification.d.ts +2 -0
- package/dist/types/protocol/privacy-token.d.ts +17 -0
- package/dist/types/protocol/privacy.d.ts +75 -0
- package/dist/types/protocol/stream.d.ts +30 -0
- package/dist/types/retry/codec.d.ts +3 -0
- package/dist/types/retry/index.d.ts +3 -3
- package/dist/types/retry/parse.d.ts +5 -2
- package/dist/types/retry/tracker.d.ts +1 -0
- package/dist/types/retry/types.d.ts +6 -1
- package/dist/types/signal/api/SignalDeviceSyncApi.d.ts +2 -1
- package/dist/types/signal/api/SignalDigestSyncApi.d.ts +6 -0
- package/dist/types/signal/api/SignalIdentitySyncApi.d.ts +2 -0
- package/dist/types/signal/api/SignalRotateKeyApi.d.ts +4 -5
- package/dist/types/signal/api/SignalSessionSyncApi.d.ts +8 -6
- package/dist/types/signal/api/result-map.d.ts +1 -0
- package/dist/types/signal/constants.d.ts +0 -3
- package/dist/types/signal/{store/sqlite.d.ts → encoding.d.ts} +3 -3
- package/dist/types/signal/group/SenderKeyManager.d.ts +10 -5
- package/dist/types/signal/index.d.ts +2 -0
- package/dist/types/signal/session/SignalProtocol.d.ts +10 -4
- package/dist/types/signal/session/resolver.d.ts +7 -2
- package/dist/types/store/contracts/appstate.store.d.ts +1 -1
- package/dist/types/store/contracts/privacy-token.store.d.ts +16 -0
- package/dist/types/store/contracts/retry.store.d.ts +7 -0
- package/dist/types/store/contracts/signal.store.d.ts +7 -0
- package/dist/types/store/createStore.d.ts +1 -1
- package/dist/types/store/index.d.ts +5 -13
- package/dist/types/store/locks/appstate.lock.d.ts +3 -0
- package/dist/types/store/locks/auth.lock.d.ts +3 -0
- package/dist/types/store/locks/contact.lock.d.ts +3 -0
- package/dist/types/store/locks/device-list.lock.d.ts +2 -0
- package/dist/types/store/locks/message.lock.d.ts +3 -0
- package/dist/types/store/locks/participants.lock.d.ts +2 -0
- package/dist/types/store/locks/privacy-token.lock.d.ts +2 -0
- package/dist/types/store/locks/retry.lock.d.ts +2 -0
- package/dist/types/store/locks/sender-key.lock.d.ts +3 -0
- package/dist/types/store/locks/signal.lock.d.ts +3 -0
- package/dist/types/store/locks/thread.lock.d.ts +3 -0
- package/dist/types/store/providers/memory/appstate.store.d.ts +1 -1
- package/dist/types/store/providers/memory/privacy-token.store.d.ts +13 -0
- package/dist/types/store/providers/memory/retry.store.d.ts +8 -0
- package/dist/types/store/providers/memory/signal.store.d.ts +2 -1
- package/dist/types/store/types.d.ts +49 -61
- package/dist/types/transport/WaWebSocket.d.ts +0 -1
- package/dist/types/transport/binary/constants.d.ts +0 -30
- package/dist/types/transport/binary/index.d.ts +0 -1
- package/dist/types/transport/node/WaNodeOrchestrator.d.ts +3 -4
- package/dist/types/transport/node/builders/business.d.ts +29 -0
- package/dist/types/transport/node/builders/global.d.ts +102 -0
- package/dist/types/transport/node/builders/index.d.ts +5 -2
- package/dist/types/transport/node/builders/message.d.ts +8 -7
- package/dist/types/transport/node/builders/pairing.d.ts +0 -2
- package/dist/types/transport/node/builders/privacy-token.d.ts +9 -0
- package/dist/types/transport/node/builders/privacy.d.ts +7 -0
- package/dist/types/transport/node/builders/profile.d.ts +8 -0
- package/dist/types/transport/node/builders/retry.d.ts +0 -1
- package/dist/types/transport/node/helpers.d.ts +5 -0
- package/dist/types/transport/noise/WaNoiseSession.d.ts +3 -2
- package/dist/types/transport/noise/WaNoiseSocket.d.ts +4 -2
- package/dist/types/util/bytes.d.ts +1 -1
- package/dist/types/util/index.d.ts +5 -0
- package/dist/types/util/primitives.d.ts +0 -1
- package/dist/util/bytes.js +22 -18
- package/dist/util/index.js +23 -0
- package/dist/util/primitives.js +2 -2
- package/package.json +29 -7
- package/proto/index.js +1 -1
- package/dist/crypto/core/constants.js +0 -4
- package/dist/esm/crypto/core/constants.js +0 -1
- package/dist/esm/retry/outbound.js +0 -82
- package/dist/esm/store/providers/sqlite/BaseSqliteStore.js +0 -37
- package/dist/esm/store/providers/sqlite/appstate.store.js +0 -250
- package/dist/esm/store/providers/sqlite/auth.store.js +0 -176
- package/dist/esm/store/providers/sqlite/connection.js +0 -245
- package/dist/esm/store/providers/sqlite/contact.store.js +0 -74
- package/dist/esm/store/providers/sqlite/device-list.store.js +0 -127
- package/dist/esm/store/providers/sqlite/message.store.js +0 -132
- package/dist/esm/store/providers/sqlite/migrations.js +0 -347
- package/dist/esm/store/providers/sqlite/participants.store.js +0 -77
- package/dist/esm/store/providers/sqlite/retry.store.js +0 -141
- package/dist/esm/store/providers/sqlite/sender-key.store.js +0 -198
- package/dist/esm/store/providers/sqlite/signal.store.js +0 -435
- package/dist/esm/store/providers/sqlite/table-names.js +0 -107
- package/dist/esm/store/providers/sqlite/thread.store.js +0 -85
- package/dist/retry/outbound.js +0 -87
- package/dist/store/providers/sqlite/BaseSqliteStore.js +0 -41
- package/dist/store/providers/sqlite/appstate.store.js +0 -254
- package/dist/store/providers/sqlite/auth.store.js +0 -180
- package/dist/store/providers/sqlite/connection.js +0 -281
- package/dist/store/providers/sqlite/contact.store.js +0 -78
- package/dist/store/providers/sqlite/device-list.store.js +0 -131
- package/dist/store/providers/sqlite/message.store.js +0 -136
- package/dist/store/providers/sqlite/migrations.js +0 -350
- package/dist/store/providers/sqlite/participants.store.js +0 -81
- package/dist/store/providers/sqlite/retry.store.js +0 -145
- package/dist/store/providers/sqlite/sender-key.store.js +0 -202
- package/dist/store/providers/sqlite/signal.store.js +0 -439
- package/dist/store/providers/sqlite/table-names.js +0 -113
- package/dist/store/providers/sqlite/thread.store.js +0 -89
- package/dist/types/appstate/store/sqlite.d.ts +0 -7
- package/dist/types/crypto/core/constants.d.ts +0 -1
- package/dist/types/retry/outbound.d.ts +0 -4
- package/dist/types/store/providers/sqlite/BaseSqliteStore.d.ts +0 -12
- package/dist/types/store/providers/sqlite/appstate.store.d.ts +0 -17
- package/dist/types/store/providers/sqlite/auth.store.d.ts +0 -10
- package/dist/types/store/providers/sqlite/connection.d.ts +0 -10
- package/dist/types/store/providers/sqlite/contact.store.d.ts +0 -12
- package/dist/types/store/providers/sqlite/device-list.store.d.ts +0 -15
- package/dist/types/store/providers/sqlite/message.store.d.ts +0 -13
- package/dist/types/store/providers/sqlite/migrations.d.ts +0 -3
- package/dist/types/store/providers/sqlite/participants.store.d.ts +0 -12
- package/dist/types/store/providers/sqlite/retry.store.d.ts +0 -15
- package/dist/types/store/providers/sqlite/sender-key.store.d.ts +0 -24
- package/dist/types/store/providers/sqlite/signal.store.d.ts +0 -53
- package/dist/types/store/providers/sqlite/table-names.d.ts +0 -5
- package/dist/types/store/providers/sqlite/thread.store.d.ts +0 -13
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
const SQLITE_TABLE_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
2
|
-
const WA_SQLITE_TABLE_NAME_ORDER = Object.freeze([
|
|
3
|
-
'wa_migrations',
|
|
4
|
-
'auth_credentials',
|
|
5
|
-
'signal_meta',
|
|
6
|
-
'signal_registration',
|
|
7
|
-
'signal_signed_prekey',
|
|
8
|
-
'signal_prekey',
|
|
9
|
-
'signal_session',
|
|
10
|
-
'signal_identity',
|
|
11
|
-
'sender_keys',
|
|
12
|
-
'sender_key_distribution',
|
|
13
|
-
'appstate_sync_keys',
|
|
14
|
-
'appstate_collection_versions',
|
|
15
|
-
'appstate_collection_index_values',
|
|
16
|
-
'retry_outbound_messages',
|
|
17
|
-
'retry_inbound_counters',
|
|
18
|
-
'mailbox_messages',
|
|
19
|
-
'mailbox_threads',
|
|
20
|
-
'mailbox_contacts',
|
|
21
|
-
'group_participants_cache',
|
|
22
|
-
'device_list_cache'
|
|
23
|
-
]);
|
|
24
|
-
const WA_SQLITE_ALLOWED_TABLE_NAME_SET = new Set(WA_SQLITE_TABLE_NAME_ORDER);
|
|
25
|
-
const WA_SQLITE_ALLOWED_TABLE_NAME_LIST = WA_SQLITE_TABLE_NAME_ORDER.join(', ');
|
|
26
|
-
export const WA_SQLITE_DEFAULT_TABLE_NAMES = Object.freeze({
|
|
27
|
-
wa_migrations: 'wa_migrations',
|
|
28
|
-
auth_credentials: 'auth_credentials',
|
|
29
|
-
signal_meta: 'signal_meta',
|
|
30
|
-
signal_registration: 'signal_registration',
|
|
31
|
-
signal_signed_prekey: 'signal_signed_prekey',
|
|
32
|
-
signal_prekey: 'signal_prekey',
|
|
33
|
-
signal_session: 'signal_session',
|
|
34
|
-
signal_identity: 'signal_identity',
|
|
35
|
-
sender_keys: 'sender_keys',
|
|
36
|
-
sender_key_distribution: 'sender_key_distribution',
|
|
37
|
-
appstate_sync_keys: 'appstate_sync_keys',
|
|
38
|
-
appstate_collection_versions: 'appstate_collection_versions',
|
|
39
|
-
appstate_collection_index_values: 'appstate_collection_index_values',
|
|
40
|
-
retry_outbound_messages: 'retry_outbound_messages',
|
|
41
|
-
retry_inbound_counters: 'retry_inbound_counters',
|
|
42
|
-
mailbox_messages: 'mailbox_messages',
|
|
43
|
-
mailbox_threads: 'mailbox_threads',
|
|
44
|
-
mailbox_contacts: 'mailbox_contacts',
|
|
45
|
-
group_participants_cache: 'group_participants_cache',
|
|
46
|
-
device_list_cache: 'device_list_cache'
|
|
47
|
-
});
|
|
48
|
-
const DEFAULT_SQLITE_TABLE_NAME_SERIALIZATION = serializeSqliteTableNames(WA_SQLITE_DEFAULT_TABLE_NAMES);
|
|
49
|
-
function normalizeTableName(table, rawValue) {
|
|
50
|
-
const value = rawValue.trim();
|
|
51
|
-
if (value.length === 0) {
|
|
52
|
-
throw new Error(`sqlite tableNames.${table} must be a non-empty string`);
|
|
53
|
-
}
|
|
54
|
-
if (!SQLITE_TABLE_NAME_PATTERN.test(value)) {
|
|
55
|
-
throw new Error(`sqlite tableNames.${table} must match ${SQLITE_TABLE_NAME_PATTERN.toString()}`);
|
|
56
|
-
}
|
|
57
|
-
return value;
|
|
58
|
-
}
|
|
59
|
-
function assertNoDuplicateTableNames(tableNames) {
|
|
60
|
-
const seen = new Set();
|
|
61
|
-
for (const table of WA_SQLITE_TABLE_NAME_ORDER) {
|
|
62
|
-
const mapped = tableNames[table];
|
|
63
|
-
const normalizedMapped = mapped.toLowerCase();
|
|
64
|
-
if (seen.has(normalizedMapped)) {
|
|
65
|
-
throw new Error(`sqlite tableNames contains duplicate target "${mapped}"`);
|
|
66
|
-
}
|
|
67
|
-
seen.add(normalizedMapped);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
export function resolveSqliteTableNames(overrides) {
|
|
71
|
-
if (!overrides) {
|
|
72
|
-
return WA_SQLITE_DEFAULT_TABLE_NAMES;
|
|
73
|
-
}
|
|
74
|
-
const entries = Object.entries(overrides);
|
|
75
|
-
if (entries.length === 0) {
|
|
76
|
-
return WA_SQLITE_DEFAULT_TABLE_NAMES;
|
|
77
|
-
}
|
|
78
|
-
const resolved = {
|
|
79
|
-
...WA_SQLITE_DEFAULT_TABLE_NAMES
|
|
80
|
-
};
|
|
81
|
-
for (const [table, rawName] of entries) {
|
|
82
|
-
if (!WA_SQLITE_ALLOWED_TABLE_NAME_SET.has(table)) {
|
|
83
|
-
throw new Error(`unsupported sqlite tableNames key "${table}". Allowed table names: ${WA_SQLITE_ALLOWED_TABLE_NAME_LIST}`);
|
|
84
|
-
}
|
|
85
|
-
if (typeof rawName !== 'string') {
|
|
86
|
-
throw new Error(`sqlite tableNames.${table} must be a string`);
|
|
87
|
-
}
|
|
88
|
-
const tableName = table;
|
|
89
|
-
resolved[tableName] = normalizeTableName(tableName, rawName);
|
|
90
|
-
}
|
|
91
|
-
assertNoDuplicateTableNames(resolved);
|
|
92
|
-
return Object.freeze(resolved);
|
|
93
|
-
}
|
|
94
|
-
export function serializeSqliteTableNames(tableNames) {
|
|
95
|
-
return WA_SQLITE_TABLE_NAME_ORDER.map((table) => `${table}=${tableNames[table]}`).join(';');
|
|
96
|
-
}
|
|
97
|
-
function escapeRegexToken(value) {
|
|
98
|
-
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
99
|
-
}
|
|
100
|
-
export function createSqliteTableNameSqlResolver(tableNames) {
|
|
101
|
-
const serialized = serializeSqliteTableNames(tableNames);
|
|
102
|
-
if (serialized === DEFAULT_SQLITE_TABLE_NAME_SERIALIZATION) {
|
|
103
|
-
return (sql) => sql;
|
|
104
|
-
}
|
|
105
|
-
const pattern = new RegExp(`\\b(?:${WA_SQLITE_TABLE_NAME_ORDER.map(escapeRegexToken).join('|')})\\b`, 'g');
|
|
106
|
-
return (sql) => sql.replace(pattern, (token) => tableNames[token] ?? token);
|
|
107
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { BaseSqliteStore } from '../../providers/sqlite/BaseSqliteStore.js';
|
|
2
|
-
import { asOptionalNumber, asOptionalString, asString, toBoolOrUndef } from '../../../util/coercion.js';
|
|
3
|
-
import { normalizeQueryLimit } from '../../../util/collections.js';
|
|
4
|
-
const THREAD_COLUMNS = 'jid, name, unread_count, archived, pinned, mute_end_ms, marked_as_unread, ephemeral_expiration';
|
|
5
|
-
function decodeThreadRow(row) {
|
|
6
|
-
return {
|
|
7
|
-
jid: asString(row.jid, 'mailbox_threads.jid'),
|
|
8
|
-
name: asOptionalString(row.name, 'mailbox_threads.name'),
|
|
9
|
-
unreadCount: asOptionalNumber(row.unread_count, 'mailbox_threads.unread_count'),
|
|
10
|
-
archived: toBoolOrUndef(row.archived),
|
|
11
|
-
pinned: asOptionalNumber(row.pinned, 'mailbox_threads.pinned'),
|
|
12
|
-
muteEndMs: asOptionalNumber(row.mute_end_ms, 'mailbox_threads.mute_end_ms'),
|
|
13
|
-
markedAsUnread: toBoolOrUndef(row.marked_as_unread),
|
|
14
|
-
ephemeralExpiration: asOptionalNumber(row.ephemeral_expiration, 'mailbox_threads.ephemeral_expiration')
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
export class WaThreadSqliteStore extends BaseSqliteStore {
|
|
18
|
-
constructor(options) {
|
|
19
|
-
super(options, ['mailbox']);
|
|
20
|
-
}
|
|
21
|
-
async upsert(record) {
|
|
22
|
-
const db = await this.getConnection();
|
|
23
|
-
this.upsertThreadRow(db, record);
|
|
24
|
-
}
|
|
25
|
-
async upsertBatch(records) {
|
|
26
|
-
if (records.length === 0) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
await this.withTransaction((db) => {
|
|
30
|
-
for (const record of records) {
|
|
31
|
-
this.upsertThreadRow(db, record);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
async getByJid(jid) {
|
|
36
|
-
const db = await this.getConnection();
|
|
37
|
-
const row = db.get(`SELECT ${THREAD_COLUMNS}
|
|
38
|
-
FROM mailbox_threads
|
|
39
|
-
WHERE session_id = ? AND jid = ?`, [this.options.sessionId, jid]);
|
|
40
|
-
return row ? decodeThreadRow(row) : null;
|
|
41
|
-
}
|
|
42
|
-
async list(limit) {
|
|
43
|
-
const db = await this.getConnection();
|
|
44
|
-
const rows = db.all(`SELECT ${THREAD_COLUMNS}
|
|
45
|
-
FROM mailbox_threads
|
|
46
|
-
WHERE session_id = ?
|
|
47
|
-
LIMIT ?`, [this.options.sessionId, normalizeQueryLimit(limit, 100)]);
|
|
48
|
-
return rows.map(decodeThreadRow);
|
|
49
|
-
}
|
|
50
|
-
async deleteByJid(jid) {
|
|
51
|
-
const db = await this.getConnection();
|
|
52
|
-
db.run(`DELETE FROM mailbox_threads
|
|
53
|
-
WHERE session_id = ? AND jid = ?`, [this.options.sessionId, jid]);
|
|
54
|
-
const row = db.get('SELECT changes() AS total', []);
|
|
55
|
-
return row ? Number(row.total) : 0;
|
|
56
|
-
}
|
|
57
|
-
async clear() {
|
|
58
|
-
const db = await this.getConnection();
|
|
59
|
-
db.run('DELETE FROM mailbox_threads WHERE session_id = ?', [this.options.sessionId]);
|
|
60
|
-
}
|
|
61
|
-
upsertThreadRow(db, record) {
|
|
62
|
-
db.run(`INSERT INTO mailbox_threads (
|
|
63
|
-
session_id, jid, name, unread_count, archived, pinned,
|
|
64
|
-
mute_end_ms, marked_as_unread, ephemeral_expiration
|
|
65
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
66
|
-
ON CONFLICT(session_id, jid) DO UPDATE SET
|
|
67
|
-
name=COALESCE(excluded.name, mailbox_threads.name),
|
|
68
|
-
unread_count=COALESCE(excluded.unread_count, mailbox_threads.unread_count),
|
|
69
|
-
archived=COALESCE(excluded.archived, mailbox_threads.archived),
|
|
70
|
-
pinned=COALESCE(excluded.pinned, mailbox_threads.pinned),
|
|
71
|
-
mute_end_ms=COALESCE(excluded.mute_end_ms, mailbox_threads.mute_end_ms),
|
|
72
|
-
marked_as_unread=COALESCE(excluded.marked_as_unread, mailbox_threads.marked_as_unread),
|
|
73
|
-
ephemeral_expiration=COALESCE(excluded.ephemeral_expiration, mailbox_threads.ephemeral_expiration)`, [
|
|
74
|
-
this.options.sessionId,
|
|
75
|
-
record.jid,
|
|
76
|
-
record.name ?? null,
|
|
77
|
-
record.unreadCount ?? null,
|
|
78
|
-
record.archived === undefined ? null : record.archived ? 1 : 0,
|
|
79
|
-
record.pinned ?? null,
|
|
80
|
-
record.muteEndMs ?? null,
|
|
81
|
-
record.markedAsUnread === undefined ? null : record.markedAsUnread ? 1 : 0,
|
|
82
|
-
record.ephemeralExpiration ?? null
|
|
83
|
-
]);
|
|
84
|
-
}
|
|
85
|
-
}
|
package/dist/retry/outbound.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.encodeRetryReplayPayload = encodeRetryReplayPayload;
|
|
4
|
-
exports.decodeRetryReplayPayload = decodeRetryReplayPayload;
|
|
5
|
-
exports.pickRetryStateMax = pickRetryStateMax;
|
|
6
|
-
const bytes_1 = require("../util/bytes");
|
|
7
|
-
function requireObject(value) {
|
|
8
|
-
if (!value || typeof value !== 'object') {
|
|
9
|
-
throw new Error('invalid retry replay payload');
|
|
10
|
-
}
|
|
11
|
-
return value;
|
|
12
|
-
}
|
|
13
|
-
function requireString(value, field) {
|
|
14
|
-
if (typeof value !== 'string') {
|
|
15
|
-
throw new Error(`invalid retry replay payload field: ${field}`);
|
|
16
|
-
}
|
|
17
|
-
return value;
|
|
18
|
-
}
|
|
19
|
-
function encodeRetryReplayPayload(payload) {
|
|
20
|
-
const serialized = payload.mode === 'plaintext'
|
|
21
|
-
? {
|
|
22
|
-
mode: payload.mode,
|
|
23
|
-
to: payload.to,
|
|
24
|
-
type: payload.type,
|
|
25
|
-
plaintext: (0, bytes_1.bytesToBase64)(payload.plaintext)
|
|
26
|
-
}
|
|
27
|
-
: payload.mode === 'encrypted'
|
|
28
|
-
? {
|
|
29
|
-
mode: payload.mode,
|
|
30
|
-
to: payload.to,
|
|
31
|
-
type: payload.type,
|
|
32
|
-
encType: payload.encType,
|
|
33
|
-
ciphertext: (0, bytes_1.bytesToBase64)(payload.ciphertext),
|
|
34
|
-
participant: payload.participant
|
|
35
|
-
}
|
|
36
|
-
: {
|
|
37
|
-
mode: payload.mode,
|
|
38
|
-
node: (0, bytes_1.bytesToBase64)(payload.node)
|
|
39
|
-
};
|
|
40
|
-
return bytes_1.TEXT_ENCODER.encode(JSON.stringify(serialized));
|
|
41
|
-
}
|
|
42
|
-
function decodeRetryReplayPayload(raw) {
|
|
43
|
-
const json = JSON.parse(bytes_1.TEXT_DECODER.decode(raw));
|
|
44
|
-
const parsed = requireObject(json);
|
|
45
|
-
const mode = requireString(parsed.mode, 'mode');
|
|
46
|
-
if (mode === 'plaintext') {
|
|
47
|
-
return {
|
|
48
|
-
mode,
|
|
49
|
-
to: requireString(parsed.to, 'to'),
|
|
50
|
-
type: requireString(parsed.type, 'type'),
|
|
51
|
-
plaintext: (0, bytes_1.base64ToBytesChecked)(requireString(parsed.plaintext, 'plaintext'), 'retry.plaintext')
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
if (mode === 'encrypted') {
|
|
55
|
-
const encType = requireString(parsed.encType, 'encType');
|
|
56
|
-
if (encType !== 'msg' && encType !== 'pkmsg' && encType !== 'skmsg') {
|
|
57
|
-
throw new Error(`invalid retry encrypted encType: ${encType}`);
|
|
58
|
-
}
|
|
59
|
-
return {
|
|
60
|
-
mode,
|
|
61
|
-
to: requireString(parsed.to, 'to'),
|
|
62
|
-
type: requireString(parsed.type, 'type'),
|
|
63
|
-
encType,
|
|
64
|
-
ciphertext: (0, bytes_1.base64ToBytesChecked)(requireString(parsed.ciphertext, 'ciphertext'), 'retry.ciphertext'),
|
|
65
|
-
participant: parsed.participant === undefined
|
|
66
|
-
? undefined
|
|
67
|
-
: requireString(parsed.participant, 'participant')
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
if (mode === 'opaque_node') {
|
|
71
|
-
return {
|
|
72
|
-
mode,
|
|
73
|
-
node: (0, bytes_1.base64ToBytesChecked)(requireString(parsed.node, 'node'), 'retry.node')
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
throw new Error(`invalid retry replay payload mode: ${mode}`);
|
|
77
|
-
}
|
|
78
|
-
const RETRY_STATE_RANK = {
|
|
79
|
-
pending: 0,
|
|
80
|
-
delivered: 1,
|
|
81
|
-
read: 2,
|
|
82
|
-
played: 3,
|
|
83
|
-
ineligible: 4
|
|
84
|
-
};
|
|
85
|
-
function pickRetryStateMax(left, right) {
|
|
86
|
-
return RETRY_STATE_RANK[left] >= RETRY_STATE_RANK[right] ? left : right;
|
|
87
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseSqliteStore = void 0;
|
|
4
|
-
const connection_1 = require("../../providers/sqlite/connection");
|
|
5
|
-
const migrations_1 = require("../../providers/sqlite/migrations");
|
|
6
|
-
class BaseSqliteStore {
|
|
7
|
-
constructor(options, migrationDomains) {
|
|
8
|
-
this.options = options;
|
|
9
|
-
this.migrationDomains = migrationDomains;
|
|
10
|
-
this.connectionPromise = null;
|
|
11
|
-
}
|
|
12
|
-
async getConnection() {
|
|
13
|
-
if (!this.connectionPromise) {
|
|
14
|
-
this.connectionPromise = (0, connection_1.openSqliteConnection)(this.options).then((connection) => (0, migrations_1.ensureSqliteMigrations)(connection, this.migrationDomains).then(() => connection));
|
|
15
|
-
}
|
|
16
|
-
return this.connectionPromise;
|
|
17
|
-
}
|
|
18
|
-
async withTransaction(run) {
|
|
19
|
-
const db = await this.getConnection();
|
|
20
|
-
db.exec('BEGIN');
|
|
21
|
-
try {
|
|
22
|
-
const result = await run(db);
|
|
23
|
-
db.exec('COMMIT');
|
|
24
|
-
return result;
|
|
25
|
-
}
|
|
26
|
-
catch (error) {
|
|
27
|
-
db.exec('ROLLBACK');
|
|
28
|
-
throw error;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
async destroy() {
|
|
32
|
-
const connectionPromise = this.connectionPromise;
|
|
33
|
-
this.connectionPromise = null;
|
|
34
|
-
if (!connectionPromise) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
const connection = await connectionPromise;
|
|
38
|
-
connection.close();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
exports.BaseSqliteStore = BaseSqliteStore;
|
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WaAppStateSqliteStore = void 0;
|
|
4
|
-
const constants_1 = require("../../../appstate/constants");
|
|
5
|
-
const sqlite_1 = require("../../../appstate/store/sqlite");
|
|
6
|
-
const utils_1 = require("../../../appstate/utils");
|
|
7
|
-
const BaseSqliteStore_1 = require("../../providers/sqlite/BaseSqliteStore");
|
|
8
|
-
const bytes_1 = require("../../../util/bytes");
|
|
9
|
-
const coercion_1 = require("../../../util/coercion");
|
|
10
|
-
function repeatSqlToken(token, count, separator) {
|
|
11
|
-
if (count <= 1) {
|
|
12
|
-
return token;
|
|
13
|
-
}
|
|
14
|
-
let out = token;
|
|
15
|
-
for (let index = 1; index < count; index += 1) {
|
|
16
|
-
out += separator + token;
|
|
17
|
-
}
|
|
18
|
-
return out;
|
|
19
|
-
}
|
|
20
|
-
class WaAppStateSqliteStore extends BaseSqliteStore_1.BaseSqliteStore {
|
|
21
|
-
constructor(options) {
|
|
22
|
-
super(options, ['appState']);
|
|
23
|
-
}
|
|
24
|
-
async exportData() {
|
|
25
|
-
const db = await this.getConnection();
|
|
26
|
-
const keyRows = db.all(`SELECT key_id, key_data, timestamp, fingerprint
|
|
27
|
-
FROM appstate_sync_keys
|
|
28
|
-
WHERE session_id = ?`, [this.options.sessionId]);
|
|
29
|
-
const versionRows = db.all(`SELECT collection, version, hash
|
|
30
|
-
FROM appstate_collection_versions
|
|
31
|
-
WHERE session_id = ?`, [this.options.sessionId]);
|
|
32
|
-
const valueRows = db.all(`SELECT collection, index_mac_hex, value_mac
|
|
33
|
-
FROM appstate_collection_index_values
|
|
34
|
-
WHERE session_id = ?`, [this.options.sessionId]);
|
|
35
|
-
return {
|
|
36
|
-
keys: (0, sqlite_1.decodeAppStateSyncKeys)(keyRows),
|
|
37
|
-
collections: (0, sqlite_1.decodeAppStateCollections)(versionRows, valueRows)
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
async upsertSyncKeys(keys) {
|
|
41
|
-
let inserted = 0;
|
|
42
|
-
await this.withTransaction((db) => {
|
|
43
|
-
for (const key of keys) {
|
|
44
|
-
const existing = db.get(`SELECT key_data
|
|
45
|
-
FROM appstate_sync_keys
|
|
46
|
-
WHERE session_id = ? AND key_id = ?`, [this.options.sessionId, key.keyId]);
|
|
47
|
-
if (existing &&
|
|
48
|
-
(0, bytes_1.uint8Equal)((0, coercion_1.asBytes)(existing.key_data, 'appstate_sync_keys.key_data'), key.keyData)) {
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
db.run(`INSERT INTO appstate_sync_keys (
|
|
52
|
-
session_id,
|
|
53
|
-
key_id,
|
|
54
|
-
key_data,
|
|
55
|
-
timestamp,
|
|
56
|
-
fingerprint,
|
|
57
|
-
key_epoch
|
|
58
|
-
) VALUES (?, ?, ?, ?, ?, ?)
|
|
59
|
-
ON CONFLICT(session_id, key_id) DO UPDATE SET
|
|
60
|
-
key_data=excluded.key_data,
|
|
61
|
-
timestamp=excluded.timestamp,
|
|
62
|
-
fingerprint=excluded.fingerprint,
|
|
63
|
-
key_epoch=excluded.key_epoch`, [
|
|
64
|
-
this.options.sessionId,
|
|
65
|
-
key.keyId,
|
|
66
|
-
key.keyData,
|
|
67
|
-
key.timestamp,
|
|
68
|
-
(0, sqlite_1.encodeAppStateFingerprint)(key.fingerprint),
|
|
69
|
-
(0, utils_1.keyEpoch)(key.keyId)
|
|
70
|
-
]);
|
|
71
|
-
inserted += 1;
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
return inserted;
|
|
75
|
-
}
|
|
76
|
-
async getSyncKey(keyId) {
|
|
77
|
-
const db = await this.getConnection();
|
|
78
|
-
const row = db.get(`SELECT key_id, key_data, timestamp, fingerprint
|
|
79
|
-
FROM appstate_sync_keys
|
|
80
|
-
WHERE session_id = ? AND key_id = ?`, [this.options.sessionId, keyId]);
|
|
81
|
-
if (!row) {
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
return {
|
|
85
|
-
keyId: (0, coercion_1.asBytes)(row.key_id, 'appstate_sync_keys.key_id'),
|
|
86
|
-
keyData: (0, coercion_1.asBytes)(row.key_data, 'appstate_sync_keys.key_data'),
|
|
87
|
-
timestamp: (0, coercion_1.asNumber)(row.timestamp, 'appstate_sync_keys.timestamp'),
|
|
88
|
-
fingerprint: (0, sqlite_1.decodeAppStateFingerprint)(row.fingerprint)
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
async getSyncKeyData(keyId) {
|
|
92
|
-
const db = await this.getConnection();
|
|
93
|
-
const row = db.get(`SELECT key_data
|
|
94
|
-
FROM appstate_sync_keys
|
|
95
|
-
WHERE session_id = ? AND key_id = ?`, [this.options.sessionId, keyId]);
|
|
96
|
-
if (!row) {
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
return (0, coercion_1.asBytes)(row.key_data, 'appstate_sync_keys.key_data');
|
|
100
|
-
}
|
|
101
|
-
async getSyncKeyDataBatch(keyIds) {
|
|
102
|
-
if (keyIds.length === 0) {
|
|
103
|
-
return [];
|
|
104
|
-
}
|
|
105
|
-
const db = await this.getConnection();
|
|
106
|
-
const uniqueKeyIds = [
|
|
107
|
-
...new Map(keyIds.map((keyId) => [(0, bytes_1.bytesToHex)(keyId), keyId])).values()
|
|
108
|
-
];
|
|
109
|
-
const placeholders = repeatSqlToken('?', uniqueKeyIds.length, ', ');
|
|
110
|
-
const params = [this.options.sessionId, ...uniqueKeyIds];
|
|
111
|
-
const rows = db.all(`SELECT key_id, key_data
|
|
112
|
-
FROM appstate_sync_keys
|
|
113
|
-
WHERE session_id = ? AND key_id IN (${placeholders})`, params);
|
|
114
|
-
const byKeyHex = new Map();
|
|
115
|
-
for (const row of rows) {
|
|
116
|
-
byKeyHex.set((0, bytes_1.bytesToHex)((0, coercion_1.asBytes)(row.key_id, 'appstate_sync_keys.key_id')), (0, coercion_1.asBytes)(row.key_data, 'appstate_sync_keys.key_data'));
|
|
117
|
-
}
|
|
118
|
-
return keyIds.map((keyId) => byKeyHex.get((0, bytes_1.bytesToHex)(keyId)) ?? null);
|
|
119
|
-
}
|
|
120
|
-
async getActiveSyncKey() {
|
|
121
|
-
const db = await this.getConnection();
|
|
122
|
-
const rows = db.all(`SELECT key_id, key_data, timestamp, fingerprint
|
|
123
|
-
FROM appstate_sync_keys
|
|
124
|
-
WHERE session_id = ?`, [this.options.sessionId]);
|
|
125
|
-
const keys = [];
|
|
126
|
-
for (const row of rows) {
|
|
127
|
-
const key = {
|
|
128
|
-
keyId: (0, coercion_1.asBytes)(row.key_id, 'appstate_sync_keys.key_id'),
|
|
129
|
-
keyData: (0, coercion_1.asBytes)(row.key_data, 'appstate_sync_keys.key_data'),
|
|
130
|
-
timestamp: (0, coercion_1.asNumber)(row.timestamp, 'appstate_sync_keys.timestamp'),
|
|
131
|
-
fingerprint: (0, sqlite_1.decodeAppStateFingerprint)(row.fingerprint)
|
|
132
|
-
};
|
|
133
|
-
keys.push(key);
|
|
134
|
-
}
|
|
135
|
-
return (0, utils_1.pickActiveSyncKey)(keys);
|
|
136
|
-
}
|
|
137
|
-
async getCollectionState(collection) {
|
|
138
|
-
const db = await this.getConnection();
|
|
139
|
-
const versionRow = db.get(`SELECT version, hash
|
|
140
|
-
FROM appstate_collection_versions
|
|
141
|
-
WHERE session_id = ? AND collection = ?`, [this.options.sessionId, collection]);
|
|
142
|
-
if (!versionRow) {
|
|
143
|
-
return {
|
|
144
|
-
initialized: false,
|
|
145
|
-
version: 0,
|
|
146
|
-
hash: constants_1.APP_STATE_EMPTY_LT_HASH,
|
|
147
|
-
indexValueMap: new Map()
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
const valueRows = db.all(`SELECT index_mac_hex, value_mac
|
|
151
|
-
FROM appstate_collection_index_values
|
|
152
|
-
WHERE session_id = ? AND collection = ?`, [this.options.sessionId, collection]);
|
|
153
|
-
const indexValueMap = new Map();
|
|
154
|
-
for (const row of valueRows) {
|
|
155
|
-
indexValueMap.set((0, coercion_1.asString)(row.index_mac_hex, 'appstate_collection_index_values.index_mac_hex'), (0, coercion_1.asBytes)(row.value_mac, 'appstate_collection_index_values.value_mac'));
|
|
156
|
-
}
|
|
157
|
-
return {
|
|
158
|
-
initialized: true,
|
|
159
|
-
version: (0, coercion_1.asNumber)(versionRow.version, 'appstate_collection_versions.version'),
|
|
160
|
-
hash: (0, coercion_1.asBytes)(versionRow.hash, 'appstate_collection_versions.hash'),
|
|
161
|
-
indexValueMap
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
async getCollectionStates(collections) {
|
|
165
|
-
if (collections.length === 0) {
|
|
166
|
-
return [];
|
|
167
|
-
}
|
|
168
|
-
const db = await this.getConnection();
|
|
169
|
-
const uniqueCollections = [...new Set(collections)];
|
|
170
|
-
const placeholders = repeatSqlToken('?', uniqueCollections.length, ', ');
|
|
171
|
-
const params = [this.options.sessionId, ...uniqueCollections];
|
|
172
|
-
const versionRows = db.all(`SELECT collection, version, hash
|
|
173
|
-
FROM appstate_collection_versions
|
|
174
|
-
WHERE session_id = ? AND collection IN (${placeholders})`, params);
|
|
175
|
-
const valueRows = db.all(`SELECT collection, index_mac_hex, value_mac
|
|
176
|
-
FROM appstate_collection_index_values
|
|
177
|
-
WHERE session_id = ? AND collection IN (${placeholders})`, params);
|
|
178
|
-
const versionsByCollection = new Map();
|
|
179
|
-
for (const row of versionRows) {
|
|
180
|
-
const collection = (0, coercion_1.asString)(row.collection, 'appstate_collection_versions.collection');
|
|
181
|
-
versionsByCollection.set(collection, {
|
|
182
|
-
version: (0, coercion_1.asNumber)(row.version, 'appstate_collection_versions.version'),
|
|
183
|
-
hash: (0, coercion_1.asBytes)(row.hash, 'appstate_collection_versions.hash')
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
const indexValueMaps = new Map();
|
|
187
|
-
for (const row of valueRows) {
|
|
188
|
-
const collection = (0, coercion_1.asString)(row.collection, 'appstate_collection_index_values.collection');
|
|
189
|
-
const map = indexValueMaps.get(collection);
|
|
190
|
-
const targetMap = map ?? new Map();
|
|
191
|
-
targetMap.set((0, coercion_1.asString)(row.index_mac_hex, 'appstate_collection_index_values.index_mac_hex'), (0, coercion_1.asBytes)(row.value_mac, 'appstate_collection_index_values.value_mac'));
|
|
192
|
-
if (!map) {
|
|
193
|
-
indexValueMaps.set(collection, targetMap);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return collections.map((collection) => {
|
|
197
|
-
const version = versionsByCollection.get(collection);
|
|
198
|
-
if (!version) {
|
|
199
|
-
return {
|
|
200
|
-
initialized: false,
|
|
201
|
-
version: 0,
|
|
202
|
-
hash: constants_1.APP_STATE_EMPTY_LT_HASH,
|
|
203
|
-
indexValueMap: new Map()
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
return {
|
|
207
|
-
initialized: true,
|
|
208
|
-
version: version.version,
|
|
209
|
-
hash: version.hash,
|
|
210
|
-
indexValueMap: indexValueMaps.get(collection) ?? new Map()
|
|
211
|
-
};
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
async setCollectionStates(updates) {
|
|
215
|
-
if (updates.length === 0) {
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
await this.withTransaction((db) => {
|
|
219
|
-
for (const update of updates) {
|
|
220
|
-
db.run(`INSERT INTO appstate_collection_versions (
|
|
221
|
-
session_id,
|
|
222
|
-
collection,
|
|
223
|
-
version,
|
|
224
|
-
hash
|
|
225
|
-
) VALUES (?, ?, ?, ?)
|
|
226
|
-
ON CONFLICT(session_id, collection) DO UPDATE SET
|
|
227
|
-
version=excluded.version,
|
|
228
|
-
hash=excluded.hash`, [this.options.sessionId, update.collection, update.version, update.hash]);
|
|
229
|
-
db.run(`DELETE FROM appstate_collection_index_values
|
|
230
|
-
WHERE session_id = ? AND collection = ?`, [this.options.sessionId, update.collection]);
|
|
231
|
-
for (const [indexMacHex, valueMac] of update.indexValueMap.entries()) {
|
|
232
|
-
db.run(`INSERT INTO appstate_collection_index_values (
|
|
233
|
-
session_id,
|
|
234
|
-
collection,
|
|
235
|
-
index_mac_hex,
|
|
236
|
-
value_mac
|
|
237
|
-
) VALUES (?, ?, ?, ?)`, [this.options.sessionId, update.collection, indexMacHex, valueMac]);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
async clear() {
|
|
243
|
-
await this.withTransaction((db) => {
|
|
244
|
-
db.run('DELETE FROM appstate_sync_keys WHERE session_id = ?', [this.options.sessionId]);
|
|
245
|
-
db.run('DELETE FROM appstate_collection_versions WHERE session_id = ?', [
|
|
246
|
-
this.options.sessionId
|
|
247
|
-
]);
|
|
248
|
-
db.run('DELETE FROM appstate_collection_index_values WHERE session_id = ?', [
|
|
249
|
-
this.options.sessionId
|
|
250
|
-
]);
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
exports.WaAppStateSqliteStore = WaAppStateSqliteStore;
|