zapo-js 0.1.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 +235 -0
- package/dist/appstate/WaAppStateCrypto.js +202 -0
- package/dist/appstate/WaAppStateSyncClient.js +808 -0
- package/dist/appstate/WaAppStateSyncResponseParser.js +71 -0
- package/dist/appstate/constants.js +23 -0
- package/dist/appstate/index.js +28 -0
- package/dist/appstate/store/sqlite.js +55 -0
- package/dist/appstate/types.js +2 -0
- package/dist/appstate/utils.js +84 -0
- package/dist/auth/WaAuthClient.js +266 -0
- package/dist/auth/flow/WaAuthCredentialsFlow.js +123 -0
- package/dist/auth/index.js +27 -0
- package/dist/auth/pairing/WaPairingCodeCrypto.js +75 -0
- package/dist/auth/pairing/WaPairingFlow.js +328 -0
- package/dist/auth/pairing/WaQrFlow.js +86 -0
- package/dist/auth/pairing/constants.js +5 -0
- package/dist/auth/types.js +2 -0
- package/dist/client/WaClient.js +749 -0
- package/dist/client/WaClientFactory.js +381 -0
- package/dist/client/coordinators/WaGroupCoordinator.js +191 -0
- package/dist/client/coordinators/WaIncomingNodeCoordinator.js +315 -0
- package/dist/client/coordinators/WaMessageDispatchCoordinator.js +1061 -0
- package/dist/client/coordinators/WaPassiveTasksCoordinator.js +200 -0
- package/dist/client/coordinators/WaRetryCoordinator.js +494 -0
- package/dist/client/coordinators/WaStreamControlCoordinator.js +123 -0
- package/dist/client/dirty.js +254 -0
- package/dist/client/events/chat.js +226 -0
- package/dist/client/events/group.js +410 -0
- package/dist/client/history-sync.js +122 -0
- package/dist/client/incoming.js +236 -0
- package/dist/client/index.js +5 -0
- package/dist/client/mailbox.js +49 -0
- package/dist/client/messages.js +152 -0
- package/dist/client/types.js +2 -0
- package/dist/crypto/core/constants.js +4 -0
- package/dist/crypto/core/encoding.js +29 -0
- package/dist/crypto/core/hkdf.js +26 -0
- package/dist/crypto/core/index.js +43 -0
- package/dist/crypto/core/keys.js +73 -0
- package/dist/crypto/core/nonce.js +18 -0
- package/dist/crypto/core/primitives.js +121 -0
- package/dist/crypto/core/random.js +32 -0
- package/dist/crypto/curves/Ed25519.js +42 -0
- package/dist/crypto/curves/X25519.js +64 -0
- package/dist/crypto/curves/constants.js +6 -0
- package/dist/crypto/curves/types.js +9 -0
- package/dist/crypto/index.js +22 -0
- package/dist/crypto/math/constants.js +44 -0
- package/dist/crypto/math/edwards.js +64 -0
- package/dist/crypto/math/le.js +20 -0
- package/dist/crypto/math/mod.js +38 -0
- package/dist/crypto/math/types.js +2 -0
- package/dist/esm/appstate/WaAppStateCrypto.js +198 -0
- package/dist/esm/appstate/WaAppStateSyncClient.js +803 -0
- package/dist/esm/appstate/WaAppStateSyncResponseParser.js +67 -0
- package/dist/esm/appstate/constants.js +20 -0
- package/dist/esm/appstate/index.js +6 -0
- package/dist/esm/appstate/store/sqlite.js +49 -0
- package/dist/esm/appstate/types.js +1 -0
- package/dist/esm/appstate/utils.js +75 -0
- package/dist/esm/auth/WaAuthClient.js +262 -0
- package/dist/esm/auth/flow/WaAuthCredentialsFlow.js +118 -0
- package/dist/esm/auth/index.js +5 -0
- package/dist/esm/auth/pairing/WaPairingCodeCrypto.js +71 -0
- package/dist/esm/auth/pairing/WaPairingFlow.js +324 -0
- package/dist/esm/auth/pairing/WaQrFlow.js +82 -0
- package/dist/esm/auth/pairing/constants.js +2 -0
- package/dist/esm/auth/types.js +1 -0
- package/dist/esm/client/WaClient.js +745 -0
- package/dist/esm/client/WaClientFactory.js +377 -0
- package/dist/esm/client/coordinators/WaGroupCoordinator.js +188 -0
- package/dist/esm/client/coordinators/WaIncomingNodeCoordinator.js +311 -0
- package/dist/esm/client/coordinators/WaMessageDispatchCoordinator.js +1057 -0
- package/dist/esm/client/coordinators/WaPassiveTasksCoordinator.js +196 -0
- package/dist/esm/client/coordinators/WaRetryCoordinator.js +490 -0
- package/dist/esm/client/coordinators/WaStreamControlCoordinator.js +120 -0
- package/dist/esm/client/dirty.js +250 -0
- package/dist/esm/client/events/chat.js +223 -0
- package/dist/esm/client/events/group.js +407 -0
- package/dist/esm/client/history-sync.js +119 -0
- package/dist/esm/client/incoming.js +227 -0
- package/dist/esm/client/index.js +1 -0
- package/dist/esm/client/mailbox.js +46 -0
- package/dist/esm/client/messages.js +148 -0
- package/dist/esm/client/types.js +1 -0
- package/dist/esm/crypto/core/constants.js +1 -0
- package/dist/esm/crypto/core/encoding.js +25 -0
- package/dist/esm/crypto/core/hkdf.js +22 -0
- package/dist/esm/crypto/core/index.js +11 -0
- package/dist/esm/crypto/core/keys.js +66 -0
- package/dist/esm/crypto/core/nonce.js +15 -0
- package/dist/esm/crypto/core/primitives.js +102 -0
- package/dist/esm/crypto/core/random.js +28 -0
- package/dist/esm/crypto/curves/Ed25519.js +38 -0
- package/dist/esm/crypto/curves/X25519.js +58 -0
- package/dist/esm/crypto/curves/constants.js +3 -0
- package/dist/esm/crypto/curves/types.js +6 -0
- package/dist/esm/crypto/index.js +3 -0
- package/dist/esm/crypto/math/constants.js +41 -0
- package/dist/esm/crypto/math/edwards.js +60 -0
- package/dist/esm/crypto/math/le.js +16 -0
- package/dist/esm/crypto/math/mod.js +31 -0
- package/dist/esm/crypto/math/types.js +1 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/infra/log/ConsoleLogger.js +40 -0
- package/dist/esm/infra/log/PinoLogger.js +73 -0
- package/dist/esm/infra/log/types.js +1 -0
- package/dist/esm/infra/perf/BoundedTaskQueue.js +62 -0
- package/dist/esm/media/WaMediaCrypto.js +224 -0
- package/dist/esm/media/WaMediaTransferClient.js +361 -0
- package/dist/esm/media/conn.js +33 -0
- package/dist/esm/media/constants.js +18 -0
- package/dist/esm/media/index.js +3 -0
- package/dist/esm/media/types.js +1 -0
- package/dist/esm/message/WaMessageClient.js +210 -0
- package/dist/esm/message/ack.js +46 -0
- package/dist/esm/message/content.js +20 -0
- package/dist/esm/message/device-sent.js +49 -0
- package/dist/esm/message/incoming.js +318 -0
- package/dist/esm/message/index.js +2 -0
- package/dist/esm/message/padding.js +20 -0
- package/dist/esm/message/phash.js +25 -0
- package/dist/esm/message/types.js +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/proto.js +3 -0
- package/dist/esm/protocol/appstate.js +34 -0
- package/dist/esm/protocol/auth.js +12 -0
- package/dist/esm/protocol/browser.js +41 -0
- package/dist/esm/protocol/constants.js +11 -0
- package/dist/esm/protocol/defaults.js +27 -0
- package/dist/esm/protocol/dirty.js +26 -0
- package/dist/esm/protocol/group.js +5 -0
- package/dist/esm/protocol/index.js +11 -0
- package/dist/esm/protocol/jid.js +94 -0
- package/dist/esm/protocol/media.js +20 -0
- package/dist/esm/protocol/message.js +16 -0
- package/dist/esm/protocol/nodes.js +83 -0
- package/dist/esm/protocol/notification.js +50 -0
- package/dist/esm/protocol/stream.js +60 -0
- package/dist/esm/retry/constants.js +20 -0
- package/dist/esm/retry/index.js +5 -0
- package/dist/esm/retry/outbound.js +83 -0
- package/dist/esm/retry/parse.js +130 -0
- package/dist/esm/retry/reason.js +50 -0
- package/dist/esm/retry/replay.js +177 -0
- package/dist/esm/retry/types.js +1 -0
- package/dist/esm/signal/api/SignalDeviceSyncApi.js +185 -0
- package/dist/esm/signal/api/SignalDigestSyncApi.js +179 -0
- package/dist/esm/signal/api/SignalIdentitySyncApi.js +111 -0
- package/dist/esm/signal/api/SignalMissingPreKeysSyncApi.js +141 -0
- package/dist/esm/signal/api/SignalRotateKeyApi.js +59 -0
- package/dist/esm/signal/api/SignalSessionSyncApi.js +187 -0
- package/dist/esm/signal/api/codec.js +23 -0
- package/dist/esm/signal/api/constants.js +9 -0
- package/dist/esm/signal/api/prekeys.js +9 -0
- package/dist/esm/signal/constants.js +16 -0
- package/dist/esm/signal/crypto/WaAdvSignature.js +60 -0
- package/dist/esm/signal/crypto/constants.js +8 -0
- package/dist/esm/signal/group/SenderKeyChain.js +97 -0
- package/dist/esm/signal/group/SenderKeyCodec.js +46 -0
- package/dist/esm/signal/group/SenderKeyManager.js +176 -0
- package/dist/esm/signal/index.js +11 -0
- package/dist/esm/signal/registration/keygen.js +31 -0
- package/dist/esm/signal/registration/utils.js +16 -0
- package/dist/esm/signal/session/SignalProtocol.js +122 -0
- package/dist/esm/signal/session/SignalRatchet.js +260 -0
- package/dist/esm/signal/session/SignalSerializer.js +63 -0
- package/dist/esm/signal/session/SignalSession.js +153 -0
- package/dist/esm/signal/store/sqlite.js +310 -0
- package/dist/esm/signal/types.js +1 -0
- package/dist/esm/store/contracts/appstate.store.js +1 -0
- package/dist/esm/store/contracts/auth.store.js +1 -0
- package/dist/esm/store/contracts/contact.store.js +1 -0
- package/dist/esm/store/contracts/device-list.store.js +1 -0
- package/dist/esm/store/contracts/message.store.js +1 -0
- package/dist/esm/store/contracts/participants.store.js +1 -0
- package/dist/esm/store/contracts/retry.store.js +1 -0
- package/dist/esm/store/contracts/sender-key.store.js +1 -0
- package/dist/esm/store/contracts/signal.store.js +1 -0
- package/dist/esm/store/contracts/thread.store.js +1 -0
- package/dist/esm/store/createStore.js +278 -0
- package/dist/esm/store/index.js +20 -0
- package/dist/esm/store/noop.store.js +43 -0
- package/dist/esm/store/providers/memory/appstate.store.js +101 -0
- package/dist/esm/store/providers/memory/contact.store.js +23 -0
- package/dist/esm/store/providers/memory/device-list.store.js +86 -0
- package/dist/esm/store/providers/memory/message.store.js +40 -0
- package/dist/esm/store/providers/memory/participants.store.js +61 -0
- package/dist/esm/store/providers/memory/retry.store.js +71 -0
- package/dist/esm/store/providers/memory/sender-key.store.js +88 -0
- package/dist/esm/store/providers/memory/signal.store.js +170 -0
- package/dist/esm/store/providers/memory/thread.store.js +34 -0
- package/dist/esm/store/providers/sqlite/BaseSqliteStore.js +37 -0
- package/dist/esm/store/providers/sqlite/appstate.store.js +169 -0
- package/dist/esm/store/providers/sqlite/auth.store.js +176 -0
- package/dist/esm/store/providers/sqlite/connection.js +240 -0
- package/dist/esm/store/providers/sqlite/contact.store.js +61 -0
- package/dist/esm/store/providers/sqlite/device-list.store.js +155 -0
- package/dist/esm/store/providers/sqlite/message.store.js +119 -0
- package/dist/esm/store/providers/sqlite/migrations.js +347 -0
- package/dist/esm/store/providers/sqlite/participants.store.js +85 -0
- package/dist/esm/store/providers/sqlite/retry.store.js +144 -0
- package/dist/esm/store/providers/sqlite/sender-key.store.js +203 -0
- package/dist/esm/store/providers/sqlite/signal.store.js +353 -0
- package/dist/esm/store/providers/sqlite/thread.store.js +72 -0
- package/dist/esm/store/types.js +1 -0
- package/dist/esm/transport/WaComms.js +527 -0
- package/dist/esm/transport/WaWebSocket.js +361 -0
- package/dist/esm/transport/binary/constants.js +96 -0
- package/dist/esm/transport/binary/decoder.js +275 -0
- package/dist/esm/transport/binary/encoder.js +210 -0
- package/dist/esm/transport/binary/index.js +4 -0
- package/dist/esm/transport/binary/tokens.js +1280 -0
- package/dist/esm/transport/index.js +6 -0
- package/dist/esm/transport/keepalive/WaKeepAlive.js +141 -0
- package/dist/esm/transport/node/WaNodeOrchestrator.js +143 -0
- package/dist/esm/transport/node/WaNodeTransport.js +64 -0
- package/dist/esm/transport/node/builders/accountSync.js +101 -0
- package/dist/esm/transport/node/builders/group.js +47 -0
- package/dist/esm/transport/node/builders/index.js +7 -0
- package/dist/esm/transport/node/builders/media.js +10 -0
- package/dist/esm/transport/node/builders/message.js +317 -0
- package/dist/esm/transport/node/builders/pairing.js +130 -0
- package/dist/esm/transport/node/builders/prekeys.js +102 -0
- package/dist/esm/transport/node/builders/retry.js +116 -0
- package/dist/esm/transport/node/helpers.js +37 -0
- package/dist/esm/transport/node/query.js +53 -0
- package/dist/esm/transport/node/xml.js +39 -0
- package/dist/esm/transport/noise/WaClientPayload.js +162 -0
- package/dist/esm/transport/noise/WaFrameCodec.js +121 -0
- package/dist/esm/transport/noise/WaNoiseCert.js +74 -0
- package/dist/esm/transport/noise/WaNoiseHandshake.js +57 -0
- package/dist/esm/transport/noise/WaNoiseSession.js +322 -0
- package/dist/esm/transport/noise/WaNoiseSocket.js +17 -0
- package/dist/esm/transport/noise/constants.js +8 -0
- package/dist/esm/transport/noise/types.js +1 -0
- package/dist/esm/transport/stream/parse.js +91 -0
- package/dist/esm/transport/types.js +1 -0
- package/dist/esm/util/async.js +5 -0
- package/dist/esm/util/base64.js +18 -0
- package/dist/esm/util/bytes.js +275 -0
- package/dist/esm/util/coercion.js +56 -0
- package/dist/esm/util/collections.js +27 -0
- package/dist/esm/util/primitives.js +32 -0
- package/dist/esm/util/runtime.js +15 -0
- package/dist/esm/util/signal-address.js +5 -0
- package/dist/index.js +52 -0
- package/dist/infra/log/ConsoleLogger.js +44 -0
- package/dist/infra/log/PinoLogger.js +111 -0
- package/dist/infra/log/types.js +2 -0
- package/dist/infra/perf/BoundedTaskQueue.js +67 -0
- package/dist/media/WaMediaCrypto.js +228 -0
- package/dist/media/WaMediaTransferClient.js +365 -0
- package/dist/media/conn.js +36 -0
- package/dist/media/constants.js +21 -0
- package/dist/media/index.js +9 -0
- package/dist/media/types.js +2 -0
- package/dist/message/WaMessageClient.js +214 -0
- package/dist/message/ack.js +52 -0
- package/dist/message/content.js +24 -0
- package/dist/message/device-sent.js +53 -0
- package/dist/message/incoming.js +321 -0
- package/dist/message/index.js +20 -0
- package/dist/message/padding.js +24 -0
- package/dist/message/phash.js +28 -0
- package/dist/message/types.js +2 -0
- package/dist/proto.js +5 -0
- package/dist/protocol/appstate.js +37 -0
- package/dist/protocol/auth.js +15 -0
- package/dist/protocol/browser.js +45 -0
- package/dist/protocol/constants.js +46 -0
- package/dist/protocol/defaults.js +30 -0
- package/dist/protocol/dirty.js +29 -0
- package/dist/protocol/group.js +8 -0
- package/dist/protocol/index.js +53 -0
- package/dist/protocol/jid.js +107 -0
- package/dist/protocol/media.js +24 -0
- package/dist/protocol/message.js +19 -0
- package/dist/protocol/nodes.js +86 -0
- package/dist/protocol/notification.js +53 -0
- package/dist/protocol/stream.js +63 -0
- package/dist/retry/constants.js +23 -0
- package/dist/retry/index.js +19 -0
- package/dist/retry/outbound.js +88 -0
- package/dist/retry/parse.js +133 -0
- package/dist/retry/reason.js +53 -0
- package/dist/retry/replay.js +181 -0
- package/dist/retry/types.js +2 -0
- package/dist/signal/api/SignalDeviceSyncApi.js +189 -0
- package/dist/signal/api/SignalDigestSyncApi.js +183 -0
- package/dist/signal/api/SignalIdentitySyncApi.js +115 -0
- package/dist/signal/api/SignalMissingPreKeysSyncApi.js +145 -0
- package/dist/signal/api/SignalRotateKeyApi.js +63 -0
- package/dist/signal/api/SignalSessionSyncApi.js +191 -0
- package/dist/signal/api/codec.js +27 -0
- package/dist/signal/api/constants.js +12 -0
- package/dist/signal/api/prekeys.js +16 -0
- package/dist/signal/constants.js +19 -0
- package/dist/signal/crypto/WaAdvSignature.js +72 -0
- package/dist/signal/crypto/constants.js +11 -0
- package/dist/signal/group/SenderKeyChain.js +101 -0
- package/dist/signal/group/SenderKeyCodec.js +50 -0
- package/dist/signal/group/SenderKeyManager.js +180 -0
- package/dist/signal/index.js +29 -0
- package/dist/signal/registration/keygen.js +37 -0
- package/dist/signal/registration/utils.js +19 -0
- package/dist/signal/session/SignalProtocol.js +126 -0
- package/dist/signal/session/SignalRatchet.js +268 -0
- package/dist/signal/session/SignalSerializer.js +69 -0
- package/dist/signal/session/SignalSession.js +165 -0
- package/dist/signal/store/sqlite.js +324 -0
- package/dist/signal/types.js +2 -0
- package/dist/store/contracts/appstate.store.js +2 -0
- package/dist/store/contracts/auth.store.js +2 -0
- package/dist/store/contracts/contact.store.js +2 -0
- package/dist/store/contracts/device-list.store.js +2 -0
- package/dist/store/contracts/message.store.js +2 -0
- package/dist/store/contracts/participants.store.js +2 -0
- package/dist/store/contracts/retry.store.js +2 -0
- package/dist/store/contracts/sender-key.store.js +2 -0
- package/dist/store/contracts/signal.store.js +2 -0
- package/dist/store/contracts/thread.store.js +2 -0
- package/dist/store/createStore.js +281 -0
- package/dist/store/index.js +43 -0
- package/dist/store/noop.store.js +46 -0
- package/dist/store/providers/memory/appstate.store.js +105 -0
- package/dist/store/providers/memory/contact.store.js +27 -0
- package/dist/store/providers/memory/device-list.store.js +90 -0
- package/dist/store/providers/memory/message.store.js +44 -0
- package/dist/store/providers/memory/participants.store.js +65 -0
- package/dist/store/providers/memory/retry.store.js +75 -0
- package/dist/store/providers/memory/sender-key.store.js +92 -0
- package/dist/store/providers/memory/signal.store.js +174 -0
- package/dist/store/providers/memory/thread.store.js +38 -0
- package/dist/store/providers/sqlite/BaseSqliteStore.js +41 -0
- package/dist/store/providers/sqlite/appstate.store.js +173 -0
- package/dist/store/providers/sqlite/auth.store.js +180 -0
- package/dist/store/providers/sqlite/connection.js +276 -0
- package/dist/store/providers/sqlite/contact.store.js +65 -0
- package/dist/store/providers/sqlite/device-list.store.js +159 -0
- package/dist/store/providers/sqlite/message.store.js +123 -0
- package/dist/store/providers/sqlite/migrations.js +350 -0
- package/dist/store/providers/sqlite/participants.store.js +89 -0
- package/dist/store/providers/sqlite/retry.store.js +148 -0
- package/dist/store/providers/sqlite/sender-key.store.js +207 -0
- package/dist/store/providers/sqlite/signal.store.js +357 -0
- package/dist/store/providers/sqlite/thread.store.js +76 -0
- package/dist/store/types.js +2 -0
- package/dist/transport/WaComms.js +531 -0
- package/dist/transport/WaWebSocket.js +365 -0
- package/dist/transport/binary/constants.js +99 -0
- package/dist/transport/binary/decoder.js +279 -0
- package/dist/transport/binary/encoder.js +214 -0
- package/dist/transport/binary/index.js +23 -0
- package/dist/transport/binary/tokens.js +1283 -0
- package/dist/transport/index.js +18 -0
- package/dist/transport/keepalive/WaKeepAlive.js +145 -0
- package/dist/transport/node/WaNodeOrchestrator.js +147 -0
- package/dist/transport/node/WaNodeTransport.js +68 -0
- package/dist/transport/node/builders/accountSync.js +110 -0
- package/dist/transport/node/builders/group.js +52 -0
- package/dist/transport/node/builders/index.js +39 -0
- package/dist/transport/node/builders/media.js +13 -0
- package/dist/transport/node/builders/message.js +328 -0
- package/dist/transport/node/builders/pairing.js +137 -0
- package/dist/transport/node/builders/prekeys.js +107 -0
- package/dist/transport/node/builders/retry.js +119 -0
- package/dist/transport/node/helpers.js +46 -0
- package/dist/transport/node/query.js +59 -0
- package/dist/transport/node/xml.js +42 -0
- package/dist/transport/noise/WaClientPayload.js +166 -0
- package/dist/transport/noise/WaFrameCodec.js +125 -0
- package/dist/transport/noise/WaNoiseCert.js +77 -0
- package/dist/transport/noise/WaNoiseHandshake.js +61 -0
- package/dist/transport/noise/WaNoiseSession.js +326 -0
- package/dist/transport/noise/WaNoiseSocket.js +21 -0
- package/dist/transport/noise/constants.js +11 -0
- package/dist/transport/noise/types.js +2 -0
- package/dist/transport/stream/parse.js +97 -0
- package/dist/transport/types.js +2 -0
- package/dist/types/appstate/WaAppStateCrypto.d.ts +59 -0
- package/dist/types/appstate/WaAppStateSyncClient.d.ts +63 -0
- package/dist/types/appstate/WaAppStateSyncResponseParser.d.ts +12 -0
- package/dist/types/appstate/constants.d.ts +14 -0
- package/dist/types/appstate/index.d.ts +7 -0
- package/dist/types/appstate/store/sqlite.d.ts +21 -0
- package/dist/types/appstate/types.d.ts +66 -0
- package/dist/types/appstate/utils.d.ts +10 -0
- package/dist/types/auth/WaAuthClient.d.ts +61 -0
- package/dist/types/auth/flow/WaAuthCredentialsFlow.d.ts +14 -0
- package/dist/types/auth/index.d.ts +6 -0
- package/dist/types/auth/pairing/WaPairingCodeCrypto.d.ts +17 -0
- package/dist/types/auth/pairing/WaPairingFlow.d.ts +48 -0
- package/dist/types/auth/pairing/WaQrFlow.d.ts +23 -0
- package/dist/types/auth/pairing/constants.d.ts +2 -0
- package/dist/types/auth/types.d.ts +48 -0
- package/dist/types/client/WaClient.d.ts +97 -0
- package/dist/types/client/WaClientFactory.d.ts +83 -0
- package/dist/types/client/coordinators/WaGroupCoordinator.d.ts +48 -0
- package/dist/types/client/coordinators/WaIncomingNodeCoordinator.d.ts +60 -0
- package/dist/types/client/coordinators/WaMessageDispatchCoordinator.d.ts +90 -0
- package/dist/types/client/coordinators/WaPassiveTasksCoordinator.d.ts +43 -0
- package/dist/types/client/coordinators/WaRetryCoordinator.d.ts +61 -0
- package/dist/types/client/coordinators/WaStreamControlCoordinator.d.ts +17 -0
- package/dist/types/client/dirty.d.ts +17 -0
- package/dist/types/client/events/chat.d.ts +3 -0
- package/dist/types/client/events/group.d.ts +7 -0
- package/dist/types/client/history-sync.d.ts +17 -0
- package/dist/types/client/incoming.d.ts +35 -0
- package/dist/types/client/index.d.ts +2 -0
- package/dist/types/client/mailbox.d.ts +12 -0
- package/dist/types/client/messages.d.ts +17 -0
- package/dist/types/client/types.d.ts +235 -0
- package/dist/types/crypto/core/constants.d.ts +1 -0
- package/dist/types/crypto/core/encoding.d.ts +11 -0
- package/dist/types/crypto/core/hkdf.d.ts +8 -0
- package/dist/types/crypto/core/index.d.ts +11 -0
- package/dist/types/crypto/core/keys.d.ts +20 -0
- package/dist/types/crypto/core/nonce.d.ts +5 -0
- package/dist/types/crypto/core/primitives.d.ts +25 -0
- package/dist/types/crypto/core/random.d.ts +8 -0
- package/dist/types/crypto/curves/Ed25519.d.ts +7 -0
- package/dist/types/crypto/curves/X25519.d.ts +8 -0
- package/dist/types/crypto/curves/constants.d.ts +2 -0
- package/dist/types/crypto/curves/types.d.ts +10 -0
- package/dist/types/crypto/index.d.ts +3 -0
- package/dist/types/crypto/math/constants.d.ts +7 -0
- package/dist/types/crypto/math/edwards.d.ts +3 -0
- package/dist/types/crypto/math/le.d.ts +2 -0
- package/dist/types/crypto/math/mod.d.ts +5 -0
- package/dist/types/crypto/math/types.d.ts +6 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/infra/log/ConsoleLogger.d.ts +11 -0
- package/dist/types/infra/log/PinoLogger.d.ts +30 -0
- package/dist/types/infra/log/types.d.ts +9 -0
- package/dist/types/infra/perf/BoundedTaskQueue.d.ts +19 -0
- package/dist/types/media/WaMediaCrypto.d.ts +12 -0
- package/dist/types/media/WaMediaTransferClient.d.ts +81 -0
- package/dist/types/media/conn.d.ts +3 -0
- package/dist/types/media/constants.d.ts +10 -0
- package/dist/types/media/index.d.ts +4 -0
- package/dist/types/media/types.d.ts +56 -0
- package/dist/types/message/WaMessageClient.d.ts +29 -0
- package/dist/types/message/ack.d.ts +5 -0
- package/dist/types/message/content.d.ts +4 -0
- package/dist/types/message/device-sent.d.ts +3 -0
- package/dist/types/message/incoming.d.ts +18 -0
- package/dist/types/message/index.d.ts +2 -0
- package/dist/types/message/padding.d.ts +2 -0
- package/dist/types/message/phash.d.ts +1 -0
- package/dist/types/message/types.d.ts +58 -0
- package/dist/types/proto.d.ts +2 -0
- package/dist/types/protocol/appstate.d.ts +34 -0
- package/dist/types/protocol/auth.d.ts +12 -0
- package/dist/types/protocol/browser.d.ts +22 -0
- package/dist/types/protocol/constants.d.ts +11 -0
- package/dist/types/protocol/defaults.d.ts +26 -0
- package/dist/types/protocol/dirty.d.ts +15 -0
- package/dist/types/protocol/group.d.ts +6 -0
- package/dist/types/protocol/index.d.ts +11 -0
- package/dist/types/protocol/jid.d.ts +19 -0
- package/dist/types/protocol/media.d.ts +15 -0
- package/dist/types/protocol/message.d.ts +16 -0
- package/dist/types/protocol/nodes.d.ts +83 -0
- package/dist/types/protocol/notification.d.ts +50 -0
- package/dist/types/protocol/stream.d.ts +60 -0
- package/dist/types/retry/constants.d.ts +21 -0
- package/dist/types/retry/index.d.ts +7 -0
- package/dist/types/retry/outbound.d.ts +4 -0
- package/dist/types/retry/parse.d.ts +3 -0
- package/dist/types/retry/reason.d.ts +2 -0
- package/dist/types/retry/replay.d.ts +30 -0
- package/dist/types/retry/types.d.ts +70 -0
- package/dist/types/signal/api/SignalDeviceSyncApi.d.ts +31 -0
- package/dist/types/signal/api/SignalDigestSyncApi.d.ts +27 -0
- package/dist/types/signal/api/SignalIdentitySyncApi.d.ts +26 -0
- package/dist/types/signal/api/SignalMissingPreKeysSyncApi.d.ts +39 -0
- package/dist/types/signal/api/SignalRotateKeyApi.d.ts +22 -0
- package/dist/types/signal/api/SignalSessionSyncApi.d.ts +38 -0
- package/dist/types/signal/api/codec.d.ts +3 -0
- package/dist/types/signal/api/constants.d.ts +9 -0
- package/dist/types/signal/api/prekeys.d.ts +6 -0
- package/dist/types/signal/constants.d.ts +14 -0
- package/dist/types/signal/crypto/WaAdvSignature.d.ts +7 -0
- package/dist/types/signal/crypto/constants.d.ts +5 -0
- package/dist/types/signal/group/SenderKeyChain.d.ts +11 -0
- package/dist/types/signal/group/SenderKeyCodec.d.ts +14 -0
- package/dist/types/signal/group/SenderKeyManager.d.ts +22 -0
- package/dist/types/signal/index.d.ts +12 -0
- package/dist/types/signal/registration/keygen.d.ts +5 -0
- package/dist/types/signal/registration/utils.d.ts +9 -0
- package/dist/types/signal/session/SignalProtocol.d.ts +22 -0
- package/dist/types/signal/session/SignalRatchet.d.ts +25 -0
- package/dist/types/signal/session/SignalSerializer.d.ts +6 -0
- package/dist/types/signal/session/SignalSession.d.ts +43 -0
- package/dist/types/signal/store/sqlite.d.ts +72 -0
- package/dist/types/signal/types.d.ts +110 -0
- package/dist/types/store/contracts/appstate.store.d.ts +22 -0
- package/dist/types/store/contracts/auth.store.d.ts +6 -0
- package/dist/types/store/contracts/contact.store.d.ts +14 -0
- package/dist/types/store/contracts/device-list.store.d.ts +16 -0
- package/dist/types/store/contracts/message.store.d.ts +18 -0
- package/dist/types/store/contracts/participants.store.d.ts +14 -0
- package/dist/types/store/contracts/retry.store.d.ts +11 -0
- package/dist/types/store/contracts/sender-key.store.d.ts +16 -0
- package/dist/types/store/contracts/signal.store.d.ts +31 -0
- package/dist/types/store/contracts/thread.store.d.ts +17 -0
- package/dist/types/store/createStore.d.ts +2 -0
- package/dist/types/store/index.d.ts +31 -0
- package/dist/types/store/noop.store.d.ts +10 -0
- package/dist/types/store/providers/memory/appstate.store.d.ts +21 -0
- package/dist/types/store/providers/memory/contact.store.d.ts +13 -0
- package/dist/types/store/providers/memory/device-list.store.d.ts +20 -0
- package/dist/types/store/providers/memory/message.store.d.ts +14 -0
- package/dist/types/store/providers/memory/participants.store.d.ts +18 -0
- package/dist/types/store/providers/memory/retry.store.d.ts +18 -0
- package/dist/types/store/providers/memory/sender-key.store.d.ts +28 -0
- package/dist/types/store/providers/memory/signal.store.d.ts +51 -0
- package/dist/types/store/providers/memory/thread.store.d.ts +14 -0
- package/dist/types/store/providers/sqlite/BaseSqliteStore.d.ts +12 -0
- package/dist/types/store/providers/sqlite/appstate.store.d.ts +15 -0
- package/dist/types/store/providers/sqlite/auth.store.d.ts +10 -0
- package/dist/types/store/providers/sqlite/connection.d.ts +10 -0
- package/dist/types/store/providers/sqlite/contact.store.d.ts +10 -0
- package/dist/types/store/providers/sqlite/device-list.store.d.ts +18 -0
- package/dist/types/store/providers/sqlite/message.store.d.ts +11 -0
- package/dist/types/store/providers/sqlite/migrations.d.ts +3 -0
- package/dist/types/store/providers/sqlite/participants.store.d.ts +13 -0
- package/dist/types/store/providers/sqlite/retry.store.d.ts +16 -0
- package/dist/types/store/providers/sqlite/sender-key.store.d.ts +25 -0
- package/dist/types/store/providers/sqlite/signal.store.d.ts +46 -0
- package/dist/types/store/providers/sqlite/thread.store.d.ts +11 -0
- package/dist/types/store/types.d.ts +103 -0
- package/dist/types/transport/WaComms.d.ts +61 -0
- package/dist/types/transport/WaWebSocket.d.ts +36 -0
- package/dist/types/transport/binary/constants.d.ts +49 -0
- package/dist/types/transport/binary/decoder.d.ts +3 -0
- package/dist/types/transport/binary/encoder.d.ts +3 -0
- package/dist/types/transport/binary/index.d.ts +4 -0
- package/dist/types/transport/binary/tokens.d.ts +11 -0
- package/dist/types/transport/index.d.ts +7 -0
- package/dist/types/transport/keepalive/WaKeepAlive.d.ts +39 -0
- package/dist/types/transport/node/WaNodeOrchestrator.d.ts +28 -0
- package/dist/types/transport/node/WaNodeTransport.d.ts +22 -0
- package/dist/types/transport/node/builders/accountSync.d.ts +11 -0
- package/dist/types/transport/node/builders/group.d.ts +16 -0
- package/dist/types/transport/node/builders/index.d.ts +7 -0
- package/dist/types/transport/node/builders/media.d.ts +2 -0
- package/dist/types/transport/node/builders/message.d.ts +52 -0
- package/dist/types/transport/node/builders/pairing.d.ts +18 -0
- package/dist/types/transport/node/builders/prekeys.d.ts +5 -0
- package/dist/types/transport/node/builders/retry.d.ts +18 -0
- package/dist/types/transport/node/helpers.d.ts +8 -0
- package/dist/types/transport/node/query.d.ts +10 -0
- package/dist/types/transport/node/xml.d.ts +2 -0
- package/dist/types/transport/noise/WaClientPayload.d.ts +3 -0
- package/dist/types/transport/noise/WaFrameCodec.d.ts +9 -0
- package/dist/types/transport/noise/WaNoiseCert.d.ts +1 -0
- package/dist/types/transport/noise/WaNoiseHandshake.d.ts +14 -0
- package/dist/types/transport/noise/WaNoiseSession.d.ts +33 -0
- package/dist/types/transport/noise/WaNoiseSocket.d.ts +10 -0
- package/dist/types/transport/noise/constants.d.ts +7 -0
- package/dist/types/transport/noise/types.d.ts +23 -0
- package/dist/types/transport/stream/parse.d.ts +23 -0
- package/dist/types/transport/types.d.ts +71 -0
- package/dist/types/util/async.d.ts +1 -0
- package/dist/types/util/base64.d.ts +4 -0
- package/dist/types/util/bytes.d.ts +28 -0
- package/dist/types/util/coercion.d.ts +8 -0
- package/dist/types/util/collections.d.ts +3 -0
- package/dist/types/util/primitives.d.ts +7 -0
- package/dist/types/util/runtime.d.ts +2 -0
- package/dist/types/util/signal-address.d.ts +2 -0
- package/dist/util/async.js +8 -0
- package/dist/util/base64.js +24 -0
- package/dist/util/bytes.js +291 -0
- package/dist/util/coercion.js +66 -0
- package/dist/util/collections.js +32 -0
- package/dist/util/primitives.js +37 -0
- package/dist/util/runtime.js +19 -0
- package/dist/util/signal-address.js +8 -0
- package/package.json +150 -0
- package/proto/index.d.ts +10861 -0
- package/proto/index.js +1 -0
- package/scripts/check-node-version.cjs +55 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WaAuthSqliteStore = void 0;
|
|
4
|
+
const _proto_1 = require("../../../proto.js");
|
|
5
|
+
const BaseSqliteStore_1 = require("../../providers/sqlite/BaseSqliteStore");
|
|
6
|
+
const coercion_1 = require("../../../util/coercion");
|
|
7
|
+
class WaAuthSqliteStore extends BaseSqliteStore_1.BaseSqliteStore {
|
|
8
|
+
constructor(options) {
|
|
9
|
+
super(options, ['auth']);
|
|
10
|
+
}
|
|
11
|
+
async load() {
|
|
12
|
+
const db = await this.getConnection();
|
|
13
|
+
const row = db.get(`SELECT
|
|
14
|
+
noise_pub_key,
|
|
15
|
+
noise_priv_key,
|
|
16
|
+
registration_id,
|
|
17
|
+
identity_pub_key,
|
|
18
|
+
identity_priv_key,
|
|
19
|
+
signed_prekey_id,
|
|
20
|
+
signed_prekey_pub_key,
|
|
21
|
+
signed_prekey_priv_key,
|
|
22
|
+
signed_prekey_signature,
|
|
23
|
+
adv_secret_key,
|
|
24
|
+
signed_identity,
|
|
25
|
+
me_jid,
|
|
26
|
+
me_lid,
|
|
27
|
+
me_display_name,
|
|
28
|
+
companion_enc_static,
|
|
29
|
+
platform,
|
|
30
|
+
server_static_key,
|
|
31
|
+
server_has_prekeys,
|
|
32
|
+
routing_info,
|
|
33
|
+
last_success_ts,
|
|
34
|
+
props_version,
|
|
35
|
+
ab_props_version,
|
|
36
|
+
connection_location,
|
|
37
|
+
account_creation_ts
|
|
38
|
+
FROM auth_credentials
|
|
39
|
+
WHERE session_id = ?`, [this.options.sessionId]);
|
|
40
|
+
if (!row) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const signedIdentityBytes = (0, coercion_1.asOptionalBytes)(row.signed_identity);
|
|
44
|
+
return {
|
|
45
|
+
noiseKeyPair: {
|
|
46
|
+
pubKey: (0, coercion_1.asBytes)(row.noise_pub_key, 'noise_pub_key'),
|
|
47
|
+
privKey: (0, coercion_1.asBytes)(row.noise_priv_key, 'noise_priv_key')
|
|
48
|
+
},
|
|
49
|
+
registrationInfo: {
|
|
50
|
+
registrationId: (0, coercion_1.asNumber)(row.registration_id, 'registration_id'),
|
|
51
|
+
identityKeyPair: {
|
|
52
|
+
pubKey: (0, coercion_1.asBytes)(row.identity_pub_key, 'identity_pub_key'),
|
|
53
|
+
privKey: (0, coercion_1.asBytes)(row.identity_priv_key, 'identity_priv_key')
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
signedPreKey: {
|
|
57
|
+
keyId: (0, coercion_1.asNumber)(row.signed_prekey_id, 'signed_prekey_id'),
|
|
58
|
+
keyPair: {
|
|
59
|
+
pubKey: (0, coercion_1.asBytes)(row.signed_prekey_pub_key, 'signed_prekey_pub_key'),
|
|
60
|
+
privKey: (0, coercion_1.asBytes)(row.signed_prekey_priv_key, 'signed_prekey_priv_key')
|
|
61
|
+
},
|
|
62
|
+
signature: (0, coercion_1.asBytes)(row.signed_prekey_signature, 'signed_prekey_signature'),
|
|
63
|
+
uploaded: false
|
|
64
|
+
},
|
|
65
|
+
advSecretKey: (0, coercion_1.asBytes)(row.adv_secret_key, 'adv_secret_key'),
|
|
66
|
+
signedIdentity: signedIdentityBytes
|
|
67
|
+
? _proto_1.proto.ADVSignedDeviceIdentity.decode(signedIdentityBytes)
|
|
68
|
+
: undefined,
|
|
69
|
+
meJid: (0, coercion_1.asOptionalString)(row.me_jid),
|
|
70
|
+
meLid: (0, coercion_1.asOptionalString)(row.me_lid),
|
|
71
|
+
meDisplayName: (0, coercion_1.asOptionalString)(row.me_display_name),
|
|
72
|
+
companionEncStatic: (0, coercion_1.asOptionalBytes)(row.companion_enc_static),
|
|
73
|
+
platform: (0, coercion_1.asOptionalString)(row.platform),
|
|
74
|
+
serverStaticKey: (0, coercion_1.asOptionalBytes)(row.server_static_key),
|
|
75
|
+
serverHasPreKeys: (0, coercion_1.toBoolOrUndef)(row.server_has_prekeys),
|
|
76
|
+
routingInfo: (0, coercion_1.asOptionalBytes)(row.routing_info),
|
|
77
|
+
lastSuccessTs: (0, coercion_1.asOptionalNumber)(row.last_success_ts),
|
|
78
|
+
propsVersion: (0, coercion_1.asOptionalNumber)(row.props_version),
|
|
79
|
+
abPropsVersion: (0, coercion_1.asOptionalNumber)(row.ab_props_version),
|
|
80
|
+
connectionLocation: (0, coercion_1.asOptionalString)(row.connection_location),
|
|
81
|
+
accountCreationTs: (0, coercion_1.asOptionalNumber)(row.account_creation_ts)
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
async save(credentials) {
|
|
85
|
+
await this.withTransaction(async (db) => {
|
|
86
|
+
db.run(`INSERT INTO auth_credentials (
|
|
87
|
+
session_id,
|
|
88
|
+
noise_pub_key,
|
|
89
|
+
noise_priv_key,
|
|
90
|
+
registration_id,
|
|
91
|
+
identity_pub_key,
|
|
92
|
+
identity_priv_key,
|
|
93
|
+
signed_prekey_id,
|
|
94
|
+
signed_prekey_pub_key,
|
|
95
|
+
signed_prekey_priv_key,
|
|
96
|
+
signed_prekey_signature,
|
|
97
|
+
adv_secret_key,
|
|
98
|
+
signed_identity,
|
|
99
|
+
me_jid,
|
|
100
|
+
me_lid,
|
|
101
|
+
me_display_name,
|
|
102
|
+
companion_enc_static,
|
|
103
|
+
platform,
|
|
104
|
+
server_static_key,
|
|
105
|
+
server_has_prekeys,
|
|
106
|
+
routing_info,
|
|
107
|
+
last_success_ts,
|
|
108
|
+
props_version,
|
|
109
|
+
ab_props_version,
|
|
110
|
+
connection_location,
|
|
111
|
+
account_creation_ts
|
|
112
|
+
) VALUES (
|
|
113
|
+
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
|
|
114
|
+
)
|
|
115
|
+
ON CONFLICT(session_id) DO UPDATE SET
|
|
116
|
+
noise_pub_key=excluded.noise_pub_key,
|
|
117
|
+
noise_priv_key=excluded.noise_priv_key,
|
|
118
|
+
registration_id=excluded.registration_id,
|
|
119
|
+
identity_pub_key=excluded.identity_pub_key,
|
|
120
|
+
identity_priv_key=excluded.identity_priv_key,
|
|
121
|
+
signed_prekey_id=excluded.signed_prekey_id,
|
|
122
|
+
signed_prekey_pub_key=excluded.signed_prekey_pub_key,
|
|
123
|
+
signed_prekey_priv_key=excluded.signed_prekey_priv_key,
|
|
124
|
+
signed_prekey_signature=excluded.signed_prekey_signature,
|
|
125
|
+
adv_secret_key=excluded.adv_secret_key,
|
|
126
|
+
signed_identity=excluded.signed_identity,
|
|
127
|
+
me_jid=excluded.me_jid,
|
|
128
|
+
me_lid=excluded.me_lid,
|
|
129
|
+
me_display_name=excluded.me_display_name,
|
|
130
|
+
companion_enc_static=excluded.companion_enc_static,
|
|
131
|
+
platform=excluded.platform,
|
|
132
|
+
server_static_key=excluded.server_static_key,
|
|
133
|
+
server_has_prekeys=excluded.server_has_prekeys,
|
|
134
|
+
routing_info=excluded.routing_info,
|
|
135
|
+
last_success_ts=excluded.last_success_ts,
|
|
136
|
+
props_version=excluded.props_version,
|
|
137
|
+
ab_props_version=excluded.ab_props_version,
|
|
138
|
+
connection_location=excluded.connection_location,
|
|
139
|
+
account_creation_ts=excluded.account_creation_ts`, [
|
|
140
|
+
this.options.sessionId,
|
|
141
|
+
credentials.noiseKeyPair.pubKey,
|
|
142
|
+
credentials.noiseKeyPair.privKey,
|
|
143
|
+
credentials.registrationInfo.registrationId,
|
|
144
|
+
credentials.registrationInfo.identityKeyPair.pubKey,
|
|
145
|
+
credentials.registrationInfo.identityKeyPair.privKey,
|
|
146
|
+
credentials.signedPreKey.keyId,
|
|
147
|
+
credentials.signedPreKey.keyPair.pubKey,
|
|
148
|
+
credentials.signedPreKey.keyPair.privKey,
|
|
149
|
+
credentials.signedPreKey.signature,
|
|
150
|
+
credentials.advSecretKey,
|
|
151
|
+
credentials.signedIdentity
|
|
152
|
+
? _proto_1.proto.ADVSignedDeviceIdentity.encode(credentials.signedIdentity).finish()
|
|
153
|
+
: null,
|
|
154
|
+
credentials.meJid ?? null,
|
|
155
|
+
credentials.meLid ?? null,
|
|
156
|
+
credentials.meDisplayName ?? null,
|
|
157
|
+
credentials.companionEncStatic ?? null,
|
|
158
|
+
credentials.platform ?? null,
|
|
159
|
+
credentials.serverStaticKey ?? null,
|
|
160
|
+
credentials.serverHasPreKeys === undefined
|
|
161
|
+
? null
|
|
162
|
+
: credentials.serverHasPreKeys
|
|
163
|
+
? 1
|
|
164
|
+
: 0,
|
|
165
|
+
credentials.routingInfo ?? null,
|
|
166
|
+
credentials.lastSuccessTs ?? null,
|
|
167
|
+
credentials.propsVersion ?? null,
|
|
168
|
+
credentials.abPropsVersion ?? null,
|
|
169
|
+
credentials.connectionLocation ?? null,
|
|
170
|
+
credentials.accountCreationTs ?? null
|
|
171
|
+
]);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
async clear() {
|
|
175
|
+
await this.withTransaction(async (db) => {
|
|
176
|
+
db.run('DELETE FROM auth_credentials WHERE session_id = ?', [this.options.sessionId]);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
exports.WaAuthSqliteStore = WaAuthSqliteStore;
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.openSqliteConnection = openSqliteConnection;
|
|
37
|
+
const primitives_1 = require("../../../util/primitives");
|
|
38
|
+
const runtime_1 = require("../../../util/runtime");
|
|
39
|
+
const BETTER_SQLITE3_MODULE = 'better-sqlite3';
|
|
40
|
+
const BUN_SQLITE_MODULE = 'bun:sqlite';
|
|
41
|
+
const SQLITE_PRAGMA_TOKEN_PATTERN = /^[A-Za-z0-9_+-]+$/;
|
|
42
|
+
const DEFAULT_SQLITE_PRAGMAS = Object.freeze({
|
|
43
|
+
journal_mode: 'WAL',
|
|
44
|
+
synchronous: 'normal',
|
|
45
|
+
busy_timeout: 5000
|
|
46
|
+
});
|
|
47
|
+
const ALLOWED_SQLITE_PRAGMAS = {
|
|
48
|
+
auto_vacuum: 'token_or_int',
|
|
49
|
+
busy_timeout: 'int',
|
|
50
|
+
cache_size: 'int',
|
|
51
|
+
foreign_keys: 'token_or_int',
|
|
52
|
+
journal_mode: 'token',
|
|
53
|
+
journal_size_limit: 'int',
|
|
54
|
+
legacy_alter_table: 'token_or_int',
|
|
55
|
+
locking_mode: 'token',
|
|
56
|
+
mmap_size: 'int',
|
|
57
|
+
page_size: 'int',
|
|
58
|
+
recursive_triggers: 'token_or_int',
|
|
59
|
+
secure_delete: 'token_or_int',
|
|
60
|
+
synchronous: 'token_or_int',
|
|
61
|
+
temp_store: 'token_or_int',
|
|
62
|
+
wal_autocheckpoint: 'int'
|
|
63
|
+
};
|
|
64
|
+
function asConstructor(loaded) {
|
|
65
|
+
if (typeof loaded === 'function') {
|
|
66
|
+
return loaded;
|
|
67
|
+
}
|
|
68
|
+
if (loaded && typeof loaded === 'object') {
|
|
69
|
+
const candidate = loaded.default;
|
|
70
|
+
if (typeof candidate === 'function') {
|
|
71
|
+
return candidate;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
throw new Error('invalid sqlite driver export');
|
|
75
|
+
}
|
|
76
|
+
function statementFor(db, sql) {
|
|
77
|
+
const prepare = db.prepare ?? db.query;
|
|
78
|
+
if (!prepare) {
|
|
79
|
+
throw new Error('sqlite driver does not expose prepare/query method');
|
|
80
|
+
}
|
|
81
|
+
const statement = prepare.call(db, sql);
|
|
82
|
+
if (!statement ||
|
|
83
|
+
typeof statement.run !== 'function' ||
|
|
84
|
+
typeof statement.get !== 'function' ||
|
|
85
|
+
typeof statement.all !== 'function') {
|
|
86
|
+
throw new Error('invalid sqlite statement API');
|
|
87
|
+
}
|
|
88
|
+
return statement;
|
|
89
|
+
}
|
|
90
|
+
function wrapConnection(db, driver, onClose) {
|
|
91
|
+
const statementCache = new Map();
|
|
92
|
+
const cachedStatementFor = (sql) => {
|
|
93
|
+
const cached = statementCache.get(sql);
|
|
94
|
+
if (cached) {
|
|
95
|
+
return cached;
|
|
96
|
+
}
|
|
97
|
+
const statement = statementFor(db, sql);
|
|
98
|
+
statementCache.set(sql, statement);
|
|
99
|
+
return statement;
|
|
100
|
+
};
|
|
101
|
+
return {
|
|
102
|
+
driver,
|
|
103
|
+
exec(sql) {
|
|
104
|
+
db.exec(sql);
|
|
105
|
+
},
|
|
106
|
+
run(sql, params) {
|
|
107
|
+
const statement = cachedStatementFor(sql);
|
|
108
|
+
if (!params || params.length === 0) {
|
|
109
|
+
statement.run();
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
statement.run(...params);
|
|
113
|
+
},
|
|
114
|
+
get(sql, params) {
|
|
115
|
+
const statement = cachedStatementFor(sql);
|
|
116
|
+
const row = !params || params.length === 0 ? statement.get() : statement.get(...params);
|
|
117
|
+
return row ?? null;
|
|
118
|
+
},
|
|
119
|
+
all(sql, params) {
|
|
120
|
+
const statement = cachedStatementFor(sql);
|
|
121
|
+
const rows = !params || params.length === 0 ? statement.all() : statement.all(...params);
|
|
122
|
+
return Array.isArray(rows) ? rows : [];
|
|
123
|
+
},
|
|
124
|
+
close() {
|
|
125
|
+
statementCache.clear();
|
|
126
|
+
try {
|
|
127
|
+
db.close();
|
|
128
|
+
}
|
|
129
|
+
finally {
|
|
130
|
+
onClose?.();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
function pragmaEntries(options) {
|
|
136
|
+
return Object.entries(mergePragmas(options.pragmas));
|
|
137
|
+
}
|
|
138
|
+
function mergePragmas(pragmas) {
|
|
139
|
+
return {
|
|
140
|
+
...DEFAULT_SQLITE_PRAGMAS,
|
|
141
|
+
...(pragmas ?? {})
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
const ALLOWED_SQLITE_PRAGMA_LIST = Object.keys(ALLOWED_SQLITE_PRAGMAS).sort().join(', ');
|
|
145
|
+
function normalizePragmaKey(rawKey) {
|
|
146
|
+
const key = rawKey.trim().toLowerCase();
|
|
147
|
+
if (!Object.prototype.hasOwnProperty.call(ALLOWED_SQLITE_PRAGMAS, key)) {
|
|
148
|
+
throw new Error(`unsupported sqlite pragma "${rawKey}". Allowed pragmas: ${ALLOWED_SQLITE_PRAGMA_LIST}`);
|
|
149
|
+
}
|
|
150
|
+
return key;
|
|
151
|
+
}
|
|
152
|
+
function normalizePragmaToken(key, rawValue) {
|
|
153
|
+
const value = rawValue.trim();
|
|
154
|
+
if (value.length === 0 || !SQLITE_PRAGMA_TOKEN_PATTERN.test(value)) {
|
|
155
|
+
throw new Error(`invalid sqlite pragma "${key}" value "${rawValue}". Allowed token pattern: ${SQLITE_PRAGMA_TOKEN_PATTERN}`);
|
|
156
|
+
}
|
|
157
|
+
return value;
|
|
158
|
+
}
|
|
159
|
+
function normalizePragmaValue(key, rawValue) {
|
|
160
|
+
const kind = ALLOWED_SQLITE_PRAGMAS[key];
|
|
161
|
+
if (kind === 'int') {
|
|
162
|
+
if (typeof rawValue !== 'number') {
|
|
163
|
+
throw new Error(`sqlite pragma "${key}" must be a number`);
|
|
164
|
+
}
|
|
165
|
+
return String((0, primitives_1.toSafeNumber)(rawValue, `sqlite pragma "${key}"`));
|
|
166
|
+
}
|
|
167
|
+
if (kind === 'token') {
|
|
168
|
+
if (typeof rawValue !== 'string') {
|
|
169
|
+
throw new Error(`sqlite pragma "${key}" must be a string token`);
|
|
170
|
+
}
|
|
171
|
+
return normalizePragmaToken(key, rawValue);
|
|
172
|
+
}
|
|
173
|
+
if (typeof rawValue === 'number') {
|
|
174
|
+
return String((0, primitives_1.toSafeNumber)(rawValue, `sqlite pragma "${key}"`));
|
|
175
|
+
}
|
|
176
|
+
return normalizePragmaToken(key, rawValue);
|
|
177
|
+
}
|
|
178
|
+
function applyPragmas(db, options) {
|
|
179
|
+
for (const [rawKey, rawValue] of pragmaEntries(options)) {
|
|
180
|
+
const key = normalizePragmaKey(rawKey);
|
|
181
|
+
const value = normalizePragmaValue(key, rawValue);
|
|
182
|
+
const statement = `${key}=${value}`;
|
|
183
|
+
if (db.pragma) {
|
|
184
|
+
db.pragma(statement);
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
db.exec(`PRAGMA ${statement}`);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function closeDatabaseSafely(db) {
|
|
191
|
+
try {
|
|
192
|
+
db.close();
|
|
193
|
+
}
|
|
194
|
+
catch {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
async function openBetterSqlite(options, onClose) {
|
|
199
|
+
let loaded;
|
|
200
|
+
try {
|
|
201
|
+
loaded = await Promise.resolve(`${BETTER_SQLITE3_MODULE}`).then(s => __importStar(require(s)));
|
|
202
|
+
}
|
|
203
|
+
catch {
|
|
204
|
+
throw new Error('optional dependency "better-sqlite3" is not installed. Install with: npm i better-sqlite3');
|
|
205
|
+
}
|
|
206
|
+
const Database = asConstructor(loaded);
|
|
207
|
+
const db = new Database(options.path);
|
|
208
|
+
try {
|
|
209
|
+
applyPragmas(db, options);
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
closeDatabaseSafely(db);
|
|
213
|
+
throw error;
|
|
214
|
+
}
|
|
215
|
+
return wrapConnection(db, 'better-sqlite3', onClose);
|
|
216
|
+
}
|
|
217
|
+
async function openBunSqlite(options, onClose) {
|
|
218
|
+
let loaded;
|
|
219
|
+
try {
|
|
220
|
+
loaded = await Promise.resolve(`${BUN_SQLITE_MODULE}`).then(s => __importStar(require(s)));
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
throw new Error('bun runtime sqlite module "bun:sqlite" is unavailable. Run this in Bun or set storage.sqlite.driver to "better-sqlite3".');
|
|
224
|
+
}
|
|
225
|
+
if (!loaded || typeof loaded !== 'object') {
|
|
226
|
+
throw new Error('invalid bun sqlite module export');
|
|
227
|
+
}
|
|
228
|
+
const ctor = loaded.Database;
|
|
229
|
+
if (typeof ctor !== 'function') {
|
|
230
|
+
throw new Error('invalid bun sqlite module export');
|
|
231
|
+
}
|
|
232
|
+
const db = new ctor(options.path);
|
|
233
|
+
try {
|
|
234
|
+
applyPragmas(db, options);
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
closeDatabaseSafely(db);
|
|
238
|
+
throw error;
|
|
239
|
+
}
|
|
240
|
+
return wrapConnection(db, 'bun', onClose);
|
|
241
|
+
}
|
|
242
|
+
function resolveDriver(requested) {
|
|
243
|
+
if (requested && requested !== 'auto') {
|
|
244
|
+
return requested;
|
|
245
|
+
}
|
|
246
|
+
return (0, runtime_1.isBunRuntime)() ? 'bun' : 'better-sqlite3';
|
|
247
|
+
}
|
|
248
|
+
async function openSqliteConnection(options) {
|
|
249
|
+
const driver = resolveDriver(options.driver);
|
|
250
|
+
const normalizedOptions = {
|
|
251
|
+
...options,
|
|
252
|
+
driver,
|
|
253
|
+
pragmas: mergePragmas(options.pragmas)
|
|
254
|
+
};
|
|
255
|
+
const cacheKey = `${driver}|${options.path}|${Object.entries(normalizedOptions.pragmas ?? {})
|
|
256
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
257
|
+
.map(([key, value]) => `${key}=${String(value)}`)
|
|
258
|
+
.join(';')}`;
|
|
259
|
+
const cached = SQLITE_CONNECTION_CACHE.get(cacheKey);
|
|
260
|
+
if (cached) {
|
|
261
|
+
return cached;
|
|
262
|
+
}
|
|
263
|
+
const onClose = () => {
|
|
264
|
+
SQLITE_CONNECTION_CACHE.delete(cacheKey);
|
|
265
|
+
};
|
|
266
|
+
const created = driver === 'bun'
|
|
267
|
+
? openBunSqlite(normalizedOptions, onClose)
|
|
268
|
+
: openBetterSqlite(normalizedOptions, onClose);
|
|
269
|
+
const guarded = created.catch((error) => {
|
|
270
|
+
SQLITE_CONNECTION_CACHE.delete(cacheKey);
|
|
271
|
+
throw error;
|
|
272
|
+
});
|
|
273
|
+
SQLITE_CONNECTION_CACHE.set(cacheKey, guarded);
|
|
274
|
+
return guarded;
|
|
275
|
+
}
|
|
276
|
+
const SQLITE_CONNECTION_CACHE = new Map();
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WaContactSqliteStore = void 0;
|
|
4
|
+
const BaseSqliteStore_1 = require("../../providers/sqlite/BaseSqliteStore");
|
|
5
|
+
const coercion_1 = require("../../../util/coercion");
|
|
6
|
+
function decodeContactRow(row) {
|
|
7
|
+
return {
|
|
8
|
+
jid: (0, coercion_1.asString)(row.jid, 'mailbox_contacts.jid'),
|
|
9
|
+
displayName: (0, coercion_1.asOptionalString)(row.display_name, 'mailbox_contacts.display_name'),
|
|
10
|
+
pushName: (0, coercion_1.asOptionalString)(row.push_name, 'mailbox_contacts.push_name'),
|
|
11
|
+
lid: (0, coercion_1.asOptionalString)(row.lid, 'mailbox_contacts.lid'),
|
|
12
|
+
phoneNumber: (0, coercion_1.asOptionalString)(row.phone_number, 'mailbox_contacts.phone_number'),
|
|
13
|
+
lastUpdatedMs: (0, coercion_1.asNumber)(row.last_updated_ms, 'mailbox_contacts.last_updated_ms')
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
class WaContactSqliteStore extends BaseSqliteStore_1.BaseSqliteStore {
|
|
17
|
+
constructor(options) {
|
|
18
|
+
super(options, ['mailbox']);
|
|
19
|
+
}
|
|
20
|
+
async upsert(record) {
|
|
21
|
+
const db = await this.getConnection();
|
|
22
|
+
db.run(`INSERT INTO mailbox_contacts (
|
|
23
|
+
session_id,
|
|
24
|
+
jid,
|
|
25
|
+
display_name,
|
|
26
|
+
push_name,
|
|
27
|
+
lid,
|
|
28
|
+
phone_number,
|
|
29
|
+
last_updated_ms
|
|
30
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
31
|
+
ON CONFLICT(session_id, jid) DO UPDATE SET
|
|
32
|
+
display_name=COALESCE(excluded.display_name, mailbox_contacts.display_name),
|
|
33
|
+
push_name=COALESCE(excluded.push_name, mailbox_contacts.push_name),
|
|
34
|
+
lid=COALESCE(excluded.lid, mailbox_contacts.lid),
|
|
35
|
+
phone_number=COALESCE(excluded.phone_number, mailbox_contacts.phone_number),
|
|
36
|
+
last_updated_ms=excluded.last_updated_ms`, [
|
|
37
|
+
this.options.sessionId,
|
|
38
|
+
record.jid,
|
|
39
|
+
record.displayName ?? null,
|
|
40
|
+
record.pushName ?? null,
|
|
41
|
+
record.lid ?? null,
|
|
42
|
+
record.phoneNumber ?? null,
|
|
43
|
+
record.lastUpdatedMs
|
|
44
|
+
]);
|
|
45
|
+
}
|
|
46
|
+
async getByJid(jid) {
|
|
47
|
+
const db = await this.getConnection();
|
|
48
|
+
const row = db.get(`SELECT jid, display_name, push_name, lid, phone_number, last_updated_ms
|
|
49
|
+
FROM mailbox_contacts
|
|
50
|
+
WHERE session_id = ? AND jid = ?`, [this.options.sessionId, jid]);
|
|
51
|
+
return row ? decodeContactRow(row) : null;
|
|
52
|
+
}
|
|
53
|
+
async deleteByJid(jid) {
|
|
54
|
+
const db = await this.getConnection();
|
|
55
|
+
db.run(`DELETE FROM mailbox_contacts
|
|
56
|
+
WHERE session_id = ? AND jid = ?`, [this.options.sessionId, jid]);
|
|
57
|
+
const row = db.get('SELECT changes() AS total', []);
|
|
58
|
+
return row ? Number(row.total) : 0;
|
|
59
|
+
}
|
|
60
|
+
async clear() {
|
|
61
|
+
const db = await this.getConnection();
|
|
62
|
+
db.run('DELETE FROM mailbox_contacts WHERE session_id = ?', [this.options.sessionId]);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.WaContactSqliteStore = WaContactSqliteStore;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WaDeviceListSqliteStore = void 0;
|
|
4
|
+
const BaseSqliteStore_1 = require("../../providers/sqlite/BaseSqliteStore");
|
|
5
|
+
const coercion_1 = require("../../../util/coercion");
|
|
6
|
+
const DEFAULTS = Object.freeze({
|
|
7
|
+
ttlMs: 5 * 60 * 1000,
|
|
8
|
+
batchSize: 500
|
|
9
|
+
});
|
|
10
|
+
class WaDeviceListSqliteStore extends BaseSqliteStore_1.BaseSqliteStore {
|
|
11
|
+
constructor(options, ttlMs = DEFAULTS.ttlMs, batchSize) {
|
|
12
|
+
super(options, ['deviceList']);
|
|
13
|
+
this.ttlMs = ttlMs;
|
|
14
|
+
this.batchSize = (0, coercion_1.resolvePositive)(batchSize, DEFAULTS.batchSize, 'deviceList.sqlite.batchSize');
|
|
15
|
+
}
|
|
16
|
+
getTtlMs() {
|
|
17
|
+
return this.ttlMs;
|
|
18
|
+
}
|
|
19
|
+
async upsertUserDevices(snapshot) {
|
|
20
|
+
const db = await this.getConnection();
|
|
21
|
+
this.upsertUserDevicesRow(db, snapshot);
|
|
22
|
+
}
|
|
23
|
+
async upsertUserDevicesBatch(snapshots) {
|
|
24
|
+
if (snapshots.length === 0) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
await this.withTransaction((db) => {
|
|
28
|
+
for (const snapshot of snapshots) {
|
|
29
|
+
this.upsertUserDevicesRow(db, snapshot);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async getUserDevices(userJid, nowMs = Date.now()) {
|
|
34
|
+
const db = await this.getConnection();
|
|
35
|
+
const row = db.get(`SELECT user_jid, device_jids_json, updated_at_ms, expires_at_ms
|
|
36
|
+
FROM device_list_cache
|
|
37
|
+
WHERE session_id = ? AND user_jid = ?`, [this.options.sessionId, userJid]);
|
|
38
|
+
if (!row) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const expiresAtMs = (0, coercion_1.asNumber)(row.expires_at_ms, 'device_list_cache.expires_at_ms');
|
|
42
|
+
if (expiresAtMs <= nowMs) {
|
|
43
|
+
db.run(`DELETE FROM device_list_cache
|
|
44
|
+
WHERE session_id = ? AND user_jid = ?`, [this.options.sessionId, userJid]);
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
userJid: (0, coercion_1.asString)(row.user_jid, 'device_list_cache.user_jid'),
|
|
49
|
+
deviceJids: decodeDeviceJids(row.device_jids_json),
|
|
50
|
+
updatedAtMs: (0, coercion_1.asNumber)(row.updated_at_ms, 'device_list_cache.updated_at_ms')
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
async getUserDevicesBatch(userJids, nowMs = Date.now()) {
|
|
54
|
+
if (userJids.length === 0) {
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
const uniqueUserJids = [...new Set(userJids)];
|
|
58
|
+
return this.withTransaction((db) => {
|
|
59
|
+
const activeByUserJid = new Map();
|
|
60
|
+
const expiredUserJids = [];
|
|
61
|
+
for (let start = 0; start < uniqueUserJids.length; start += this.batchSize) {
|
|
62
|
+
const end = Math.min(start + this.batchSize, uniqueUserJids.length);
|
|
63
|
+
const batchLength = end - start;
|
|
64
|
+
const placeholders = new Array(batchLength).fill('?').join(', ');
|
|
65
|
+
const params = [this.options.sessionId];
|
|
66
|
+
for (let index = start; index < end; index += 1) {
|
|
67
|
+
params.push(uniqueUserJids[index]);
|
|
68
|
+
}
|
|
69
|
+
const rows = db.all(`SELECT user_jid, device_jids_json, updated_at_ms, expires_at_ms
|
|
70
|
+
FROM device_list_cache
|
|
71
|
+
WHERE session_id = ? AND user_jid IN (${placeholders})`, params);
|
|
72
|
+
for (const row of rows) {
|
|
73
|
+
const userJid = (0, coercion_1.asString)(row.user_jid, 'device_list_cache.user_jid');
|
|
74
|
+
const expiresAtMs = (0, coercion_1.asNumber)(row.expires_at_ms, 'device_list_cache.expires_at_ms');
|
|
75
|
+
if (expiresAtMs <= nowMs) {
|
|
76
|
+
expiredUserJids.push(userJid);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
activeByUserJid.set(userJid, {
|
|
80
|
+
userJid,
|
|
81
|
+
deviceJids: decodeDeviceJids(row.device_jids_json),
|
|
82
|
+
updatedAtMs: (0, coercion_1.asNumber)(row.updated_at_ms, 'device_list_cache.updated_at_ms')
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (expiredUserJids.length > 0) {
|
|
87
|
+
this.deleteUserDevicesByJids(db, expiredUserJids);
|
|
88
|
+
}
|
|
89
|
+
return userJids.map((userJid) => activeByUserJid.get(userJid) ?? null);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
async deleteUserDevices(userJid) {
|
|
93
|
+
const db = await this.getConnection();
|
|
94
|
+
db.run(`DELETE FROM device_list_cache
|
|
95
|
+
WHERE session_id = ? AND user_jid = ?`, [this.options.sessionId, userJid]);
|
|
96
|
+
const row = db.get('SELECT changes() AS total', []);
|
|
97
|
+
return row ? Number(row.total) : 0;
|
|
98
|
+
}
|
|
99
|
+
async cleanupExpired(nowMs) {
|
|
100
|
+
const db = await this.getConnection();
|
|
101
|
+
db.run(`DELETE FROM device_list_cache
|
|
102
|
+
WHERE session_id = ? AND expires_at_ms <= ?`, [this.options.sessionId, nowMs]);
|
|
103
|
+
const row = db.get('SELECT changes() AS total', []);
|
|
104
|
+
return row ? Number(row.total) : 0;
|
|
105
|
+
}
|
|
106
|
+
async clear() {
|
|
107
|
+
const db = await this.getConnection();
|
|
108
|
+
db.run('DELETE FROM device_list_cache WHERE session_id = ?', [this.options.sessionId]);
|
|
109
|
+
}
|
|
110
|
+
upsertUserDevicesRow(db, snapshot) {
|
|
111
|
+
db.run(`INSERT INTO device_list_cache (
|
|
112
|
+
session_id,
|
|
113
|
+
user_jid,
|
|
114
|
+
device_jids_json,
|
|
115
|
+
updated_at_ms,
|
|
116
|
+
expires_at_ms
|
|
117
|
+
) VALUES (?, ?, ?, ?, ?)
|
|
118
|
+
ON CONFLICT(session_id, user_jid) DO UPDATE SET
|
|
119
|
+
device_jids_json=excluded.device_jids_json,
|
|
120
|
+
updated_at_ms=excluded.updated_at_ms,
|
|
121
|
+
expires_at_ms=excluded.expires_at_ms`, [
|
|
122
|
+
this.options.sessionId,
|
|
123
|
+
snapshot.userJid,
|
|
124
|
+
JSON.stringify(snapshot.deviceJids),
|
|
125
|
+
snapshot.updatedAtMs,
|
|
126
|
+
snapshot.updatedAtMs + this.ttlMs
|
|
127
|
+
]);
|
|
128
|
+
}
|
|
129
|
+
deleteUserDevicesByJids(db, userJids) {
|
|
130
|
+
if (userJids.length === 0) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
for (let start = 0; start < userJids.length; start += this.batchSize) {
|
|
134
|
+
const end = Math.min(start + this.batchSize, userJids.length);
|
|
135
|
+
const batchLength = end - start;
|
|
136
|
+
const placeholders = new Array(batchLength).fill('?').join(', ');
|
|
137
|
+
const params = [this.options.sessionId];
|
|
138
|
+
for (let index = start; index < end; index += 1) {
|
|
139
|
+
params.push(userJids[index]);
|
|
140
|
+
}
|
|
141
|
+
db.run(`DELETE FROM device_list_cache
|
|
142
|
+
WHERE session_id = ? AND user_jid IN (${placeholders})`, params);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.WaDeviceListSqliteStore = WaDeviceListSqliteStore;
|
|
147
|
+
function decodeDeviceJids(raw) {
|
|
148
|
+
const json = (0, coercion_1.asString)(raw, 'device_list_cache.device_jids_json');
|
|
149
|
+
const parsed = JSON.parse(json);
|
|
150
|
+
if (!Array.isArray(parsed)) {
|
|
151
|
+
throw new Error('device_list_cache.device_jids_json must be an array');
|
|
152
|
+
}
|
|
153
|
+
return parsed.filter((entry) => {
|
|
154
|
+
if (typeof entry !== 'string') {
|
|
155
|
+
throw new Error('device_list_cache.device_jids_json entry must be string');
|
|
156
|
+
}
|
|
157
|
+
return true;
|
|
158
|
+
});
|
|
159
|
+
}
|