zapo-js 0.1.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -4
- package/dist/appstate/WaAppStateCrypto.js +50 -42
- package/dist/appstate/WaAppStateSyncClient.js +215 -133
- package/dist/appstate/{store/sqlite.js → encoding.js} +13 -8
- package/dist/appstate/index.js +9 -7
- package/dist/appstate/utils.js +0 -5
- package/dist/auth/WaAuthClient.js +55 -57
- package/dist/auth/credentials-flow.js +195 -0
- package/dist/auth/index.js +1 -6
- package/dist/auth/pairing/WaPairingFlow.js +39 -32
- package/dist/auth/pairing/{WaPairingCodeCrypto.js → pairing-code-crypto.js} +35 -17
- package/dist/client/WaClient.js +338 -174
- package/dist/client/WaClientFactory.js +399 -66
- package/dist/client/connection/WaConnectionManager.js +23 -11
- package/dist/client/coordinators/WaAbPropsCoordinator.js +141 -0
- package/dist/client/coordinators/WaBusinessCoordinator.js +232 -0
- package/dist/client/coordinators/WaEmailCoordinator.js +63 -0
- package/dist/client/coordinators/WaGroupCoordinator.js +11 -7
- package/dist/client/coordinators/WaIncomingNodeCoordinator.js +34 -8
- package/dist/client/coordinators/WaMessageDispatchCoordinator.js +341 -118
- package/dist/client/coordinators/WaOfflineResumeCoordinator.js +114 -0
- package/dist/client/coordinators/WaPassiveTasksCoordinator.js +97 -36
- package/dist/client/coordinators/WaPrivacyCoordinator.js +134 -0
- package/dist/client/coordinators/WaProfileCoordinator.js +214 -0
- package/dist/client/coordinators/WaRetryCoordinator.js +184 -30
- package/dist/client/coordinators/WaStreamControlCoordinator.js +18 -11
- package/dist/client/coordinators/WaTrustedContactTokenCoordinator.js +184 -0
- package/dist/client/dirty.js +41 -21
- package/dist/client/events/abprops.js +43 -0
- 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 +38 -0
- package/dist/client/events/registration.js +42 -0
- package/dist/client/history-sync.js +50 -9
- package/dist/client/incoming.js +74 -7
- package/dist/client/mailbox.js +40 -23
- package/dist/client/media.js +243 -0
- package/dist/client/messages.js +245 -92
- 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 +5 -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 +24 -8
- package/dist/crypto/core/xeddsa.js +57 -0
- package/dist/crypto/curves/X25519.js +43 -6
- package/dist/crypto/curves/constants.js +2 -1
- 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 +40 -32
- package/dist/esm/appstate/WaAppStateSyncClient.js +206 -124
- package/dist/esm/appstate/{store/sqlite.js → encoding.js} +13 -8
- package/dist/esm/appstate/index.js +2 -2
- package/dist/esm/appstate/{WaAppStateSyncResponseParser.js → response-parser.js} +1 -1
- package/dist/esm/appstate/utils.js +2 -5
- package/dist/esm/auth/WaAuthClient.js +52 -54
- package/dist/esm/auth/credentials-flow.js +190 -0
- package/dist/esm/auth/index.js +0 -2
- package/dist/esm/auth/pairing/WaPairingFlow.js +39 -32
- package/dist/esm/auth/pairing/{WaPairingCodeCrypto.js → pairing-code-crypto.js} +26 -10
- package/dist/esm/client/WaClient.js +339 -175
- package/dist/esm/client/WaClientFactory.js +401 -68
- package/dist/esm/client/connection/WaConnectionManager.js +23 -11
- package/dist/esm/client/coordinators/WaAbPropsCoordinator.js +137 -0
- package/dist/esm/client/coordinators/WaBusinessCoordinator.js +229 -0
- package/dist/esm/client/coordinators/WaEmailCoordinator.js +60 -0
- package/dist/esm/client/coordinators/WaGroupCoordinator.js +11 -7
- package/dist/esm/client/coordinators/WaIncomingNodeCoordinator.js +36 -10
- package/dist/esm/client/coordinators/WaMessageDispatchCoordinator.js +337 -114
- package/dist/esm/client/coordinators/WaOfflineResumeCoordinator.js +110 -0
- package/dist/esm/client/coordinators/WaPassiveTasksCoordinator.js +97 -36
- package/dist/esm/client/coordinators/WaPrivacyCoordinator.js +131 -0
- package/dist/esm/client/coordinators/WaProfileCoordinator.js +211 -0
- package/dist/esm/client/coordinators/WaRetryCoordinator.js +186 -32
- package/dist/esm/client/coordinators/WaStreamControlCoordinator.js +19 -12
- package/dist/esm/client/coordinators/WaTrustedContactTokenCoordinator.js +180 -0
- package/dist/esm/client/dirty.js +41 -21
- package/dist/esm/client/events/abprops.js +40 -0
- 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 +35 -0
- package/dist/esm/client/events/registration.js +39 -0
- package/dist/esm/client/history-sync.js +50 -9
- package/dist/esm/client/incoming.js +74 -8
- package/dist/esm/client/mailbox.js +40 -23
- package/dist/esm/client/media.js +234 -0
- package/dist/esm/client/messages.js +244 -91
- 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 +3 -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 +23 -7
- package/dist/esm/crypto/core/xeddsa.js +53 -0
- package/dist/esm/crypto/curves/X25519.js +45 -8
- package/dist/esm/crypto/curves/constants.js +1 -0
- 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 +80 -0
- package/dist/esm/media/WaMediaCrypto.js +332 -55
- package/dist/esm/media/WaMediaTransferClient.js +69 -220
- package/dist/esm/media/constants.js +4 -1
- package/dist/esm/media/processor.js +1 -0
- package/dist/esm/message/WaMessageClient.js +26 -19
- package/dist/esm/message/addon-crypto.js +130 -3
- package/dist/esm/message/content.js +206 -14
- package/dist/esm/message/icdc.js +76 -0
- package/dist/esm/message/incoming.js +38 -24
- package/dist/esm/message/phash.js +35 -13
- package/dist/esm/message/reporting-token.js +17 -30
- package/dist/esm/message/use-case-secret.js +1 -1
- package/dist/esm/protocol/abprops.js +159 -0
- package/dist/esm/protocol/appstate.js +9 -40
- package/dist/esm/protocol/browser.js +24 -18
- package/dist/esm/protocol/constants.js +8 -4
- package/dist/esm/protocol/defaults.js +6 -0
- package/dist/esm/protocol/email.js +30 -0
- package/dist/esm/protocol/index.js +1 -2
- package/dist/esm/protocol/jid.js +142 -39
- package/dist/esm/protocol/message.js +61 -1
- package/dist/esm/protocol/nodes.js +8 -2
- package/dist/esm/protocol/notification.js +9 -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/reason.js +1 -1
- package/dist/esm/retry/replay.js +11 -7
- package/dist/esm/retry/tracker.js +50 -12
- package/dist/esm/signal/api/SignalDeviceSyncApi.js +52 -32
- package/dist/esm/signal/api/SignalDigestSyncApi.js +21 -15
- package/dist/esm/signal/api/SignalIdentitySyncApi.js +30 -15
- package/dist/esm/signal/api/SignalMissingPreKeysSyncApi.js +19 -8
- package/dist/esm/signal/api/SignalRotateKeyApi.js +4 -2
- package/dist/esm/signal/api/SignalSessionSyncApi.js +17 -8
- 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 +5 -45
- package/dist/esm/signal/crypto/constants.js +0 -4
- package/dist/esm/signal/{store/sqlite.js → encoding.js} +40 -29
- package/dist/esm/signal/group/SenderKeyChain.js +3 -3
- package/dist/esm/signal/group/SenderKeyCodec.js +8 -8
- package/dist/esm/signal/group/SenderKeyManager.js +131 -109
- package/dist/esm/signal/index.js +1 -0
- package/dist/esm/signal/registration/keygen.js +8 -5
- package/dist/esm/signal/registration/utils.js +3 -2
- package/dist/esm/signal/session/SignalProtocol.js +158 -81
- package/dist/esm/signal/session/SignalRatchet.js +21 -10
- package/dist/esm/signal/session/SignalSerializer.js +5 -6
- package/dist/esm/signal/session/SignalSession.js +11 -9
- package/dist/esm/signal/session/resolver.js +140 -105
- package/dist/esm/store/contracts/identity.store.js +1 -0
- package/dist/esm/store/contracts/message-secret.store.js +1 -0
- package/dist/esm/store/contracts/pre-key.store.js +1 -0
- package/dist/esm/store/contracts/privacy-token.store.js +1 -0
- package/dist/esm/store/contracts/session.store.js +1 -0
- package/dist/esm/store/createStore.js +143 -193
- package/dist/esm/store/index.js +5 -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/identity.lock.js +16 -0
- package/dist/esm/store/locks/message-secret.lock.js +17 -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/pre-key.lock.js +27 -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/session.lock.js +19 -0
- package/dist/esm/store/locks/signal.lock.js +39 -0
- package/dist/esm/store/locks/thread.lock.js +21 -0
- package/dist/esm/store/noop.store.js +21 -1
- package/dist/esm/store/providers/memory/appstate.store.js +22 -24
- package/dist/esm/store/providers/memory/device-list.store.js +13 -5
- package/dist/esm/store/providers/memory/identity.store.js +31 -0
- package/dist/esm/store/providers/memory/message-secret.store.js +81 -0
- package/dist/esm/store/providers/memory/participants.store.js +3 -0
- package/dist/esm/store/providers/memory/pre-key.store.js +97 -0
- package/dist/esm/store/providers/memory/privacy-token.store.js +43 -0
- package/dist/esm/store/providers/memory/retry.store.js +99 -10
- package/dist/esm/store/providers/memory/sender-key.store.js +6 -1
- package/dist/esm/store/providers/memory/session.store.js +45 -0
- package/dist/esm/store/providers/memory/signal.store.js +1 -147
- package/dist/esm/transport/WaComms.js +7 -4
- package/dist/esm/transport/WaWebSocket.js +9 -7
- 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/index.js +6 -0
- package/dist/esm/transport/keepalive/WaKeepAlive.js +17 -8
- package/dist/esm/transport/node/WaMobileTcpSocket.js +114 -0
- package/dist/esm/transport/node/WaNodeOrchestrator.js +37 -22
- package/dist/esm/transport/node/builders/abprops.js +20 -0
- package/dist/esm/transport/node/builders/business.js +129 -0
- package/dist/esm/transport/node/builders/device.js +11 -0
- package/dist/esm/transport/node/builders/email.js +65 -0
- package/dist/esm/transport/node/builders/global.js +370 -0
- package/dist/esm/transport/node/builders/message.js +63 -239
- package/dist/esm/transport/node/builders/offline.js +14 -0
- package/dist/esm/transport/node/builders/pairing.js +0 -24
- package/dist/esm/transport/node/builders/prekeys.js +37 -40
- package/dist/esm/transport/node/builders/presence.js +13 -0
- package/dist/esm/transport/node/builders/privacy-token.js +37 -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 +11 -23
- package/dist/esm/transport/node/builders/usync.js +6 -2
- package/dist/esm/transport/node/helpers.js +43 -1
- package/dist/esm/transport/node/mex/argo-decoder.js +152 -0
- package/dist/esm/transport/node/mex/client.js +83 -0
- package/dist/esm/transport/node/mex/persist-ids.js +10 -0
- package/dist/esm/transport/node/usync.js +3 -33
- package/dist/esm/transport/node/xml.js +35 -14
- package/dist/esm/transport/noise/WaClientPayload.js +24 -19
- package/dist/esm/transport/noise/WaFrameCodec.js +2 -2
- package/dist/esm/transport/noise/WaMobileClientPayload.js +53 -0
- package/dist/esm/transport/noise/WaNoiseCert.js +9 -27
- package/dist/esm/transport/noise/WaNoiseSession.js +76 -34
- 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 +84 -0
- package/dist/media/WaMediaCrypto.js +328 -51
- package/dist/media/WaMediaTransferClient.js +72 -253
- package/dist/media/constants.js +5 -2
- package/dist/media/processor.js +2 -0
- package/dist/message/WaMessageClient.js +26 -19
- package/dist/message/addon-crypto.js +131 -0
- package/dist/message/content.js +211 -14
- package/dist/message/icdc.js +81 -0
- package/dist/message/incoming.js +38 -24
- package/dist/message/phash.js +35 -13
- package/dist/message/reporting-token.js +16 -30
- package/dist/message/use-case-secret.js +1 -1
- package/dist/protocol/abprops.js +163 -0
- package/dist/protocol/appstate.js +10 -41
- package/dist/protocol/browser.js +25 -18
- package/dist/protocol/constants.js +33 -2
- package/dist/protocol/defaults.js +6 -0
- package/dist/protocol/email.js +33 -0
- package/dist/protocol/index.js +8 -5
- package/dist/protocol/jid.js +149 -39
- package/dist/protocol/message.js +62 -2
- package/dist/protocol/nodes.js +8 -2
- package/dist/protocol/notification.js +10 -2
- 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/reason.js +1 -1
- package/dist/retry/replay.js +10 -6
- package/dist/retry/tracker.js +50 -12
- package/dist/signal/api/SignalDeviceSyncApi.js +51 -31
- package/dist/signal/api/SignalDigestSyncApi.js +21 -15
- package/dist/signal/api/SignalIdentitySyncApi.js +29 -14
- 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 +2 -44
- package/dist/signal/crypto/constants.js +1 -5
- package/dist/signal/{store/sqlite.js → encoding.js} +41 -25
- package/dist/signal/group/SenderKeyChain.js +2 -2
- package/dist/signal/group/SenderKeyCodec.js +8 -8
- package/dist/signal/group/SenderKeyManager.js +130 -108
- package/dist/signal/index.js +13 -1
- package/dist/signal/registration/keygen.js +7 -4
- package/dist/signal/registration/utils.js +3 -2
- package/dist/signal/session/SignalProtocol.js +158 -81
- package/dist/signal/session/SignalRatchet.js +19 -8
- package/dist/signal/session/SignalSerializer.js +5 -6
- package/dist/signal/session/SignalSession.js +11 -9
- package/dist/signal/session/resolver.js +138 -103
- package/dist/store/contracts/identity.store.js +2 -0
- package/dist/store/contracts/message-secret.store.js +2 -0
- package/dist/store/contracts/pre-key.store.js +2 -0
- package/dist/store/contracts/privacy-token.store.js +2 -0
- package/dist/store/contracts/session.store.js +2 -0
- package/dist/store/createStore.js +142 -192
- package/dist/store/index.js +23 -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/identity.lock.js +19 -0
- package/dist/store/locks/message-secret.lock.js +20 -0
- package/dist/store/locks/message.lock.js +24 -0
- package/dist/store/locks/participants.lock.js +23 -0
- package/dist/store/locks/pre-key.lock.js +30 -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/session.lock.js +22 -0
- package/dist/store/locks/signal.lock.js +42 -0
- package/dist/store/locks/thread.lock.js +24 -0
- package/dist/store/noop.store.js +22 -2
- package/dist/store/providers/memory/appstate.store.js +22 -24
- package/dist/store/providers/memory/device-list.store.js +13 -5
- package/dist/store/providers/memory/identity.store.js +35 -0
- package/dist/store/providers/memory/message-secret.store.js +85 -0
- package/dist/store/providers/memory/participants.store.js +3 -0
- package/dist/store/providers/memory/pre-key.store.js +101 -0
- package/dist/store/providers/memory/privacy-token.store.js +47 -0
- package/dist/store/providers/memory/retry.store.js +98 -9
- package/dist/store/providers/memory/sender-key.store.js +6 -1
- package/dist/store/providers/memory/session.store.js +49 -0
- package/dist/store/providers/memory/signal.store.js +1 -147
- package/dist/transport/WaComms.js +7 -4
- package/dist/transport/WaWebSocket.js +9 -7
- 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/index.js +17 -1
- package/dist/transport/keepalive/WaKeepAlive.js +17 -8
- package/dist/transport/node/WaMobileTcpSocket.js +118 -0
- package/dist/transport/node/WaNodeOrchestrator.js +36 -21
- package/dist/transport/node/builders/abprops.js +23 -0
- package/dist/transport/node/builders/business.js +137 -0
- package/dist/transport/node/builders/device.js +14 -0
- package/dist/transport/node/builders/email.js +72 -0
- package/dist/transport/node/builders/global.js +375 -0
- package/dist/transport/node/builders/message.js +64 -245
- package/dist/transport/node/builders/offline.js +17 -0
- package/dist/transport/node/builders/pairing.js +0 -26
- package/dist/transport/node/builders/prekeys.js +36 -39
- package/dist/transport/node/builders/presence.js +16 -0
- package/dist/transport/node/builders/privacy-token.js +42 -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 +10 -22
- package/dist/transport/node/builders/usync.js +6 -2
- package/dist/transport/node/helpers.js +46 -1
- package/dist/transport/node/mex/argo-decoder.js +189 -0
- package/dist/transport/node/mex/client.js +86 -0
- package/dist/transport/node/mex/persist-ids.js +13 -0
- package/dist/transport/node/usync.js +2 -32
- package/dist/transport/node/xml.js +35 -14
- package/dist/transport/noise/WaClientPayload.js +26 -21
- package/dist/transport/noise/WaFrameCodec.js +1 -1
- package/dist/transport/noise/WaMobileClientPayload.js +56 -0
- package/dist/transport/noise/WaNoiseCert.js +8 -26
- package/dist/transport/noise/WaNoiseSession.js +75 -33
- package/dist/transport/noise/WaNoiseSocket.js +8 -4
- package/dist/transport/stream/parse.js +7 -3
- package/dist/types/appstate/WaAppStateCrypto.d.ts +11 -8
- package/dist/types/appstate/WaAppStateSyncClient.d.ts +6 -2
- package/dist/types/appstate/encoding.d.ts +7 -0
- package/dist/types/appstate/index.d.ts +3 -3
- package/dist/types/appstate/{WaAppStateSyncResponseParser.d.ts → response-parser.d.ts} +1 -1
- package/dist/types/appstate/types.d.ts +1 -1
- package/dist/types/appstate/utils.d.ts +0 -2
- package/dist/types/auth/WaAuthClient.d.ts +9 -3
- package/dist/types/auth/credentials-flow.d.ts +20 -0
- package/dist/types/auth/index.d.ts +0 -2
- package/dist/types/auth/pairing/WaPairingFlow.d.ts +3 -2
- package/dist/types/auth/pairing/{WaPairingCodeCrypto.d.ts → pairing-code-crypto.d.ts} +6 -1
- package/dist/types/auth/types.d.ts +41 -0
- package/dist/types/client/WaClient.d.ts +44 -18
- package/dist/types/client/WaClientFactory.d.ts +22 -8
- package/dist/types/client/connection/WaConnectionManager.d.ts +2 -0
- package/dist/types/client/coordinators/WaAbPropsCoordinator.d.ts +26 -0
- package/dist/types/client/coordinators/WaBusinessCoordinator.d.ts +57 -0
- package/dist/types/client/coordinators/WaEmailCoordinator.d.ts +24 -0
- package/dist/types/client/coordinators/WaIncomingNodeCoordinator.d.ts +9 -2
- package/dist/types/client/coordinators/WaMessageDispatchCoordinator.d.ts +29 -2
- package/dist/types/client/coordinators/WaOfflineResumeCoordinator.d.ts +31 -0
- package/dist/types/client/coordinators/WaPassiveTasksCoordinator.d.ts +16 -1
- package/dist/types/client/coordinators/WaPrivacyCoordinator.d.ts +26 -0
- package/dist/types/client/coordinators/WaProfileCoordinator.d.ts +38 -0
- package/dist/types/client/coordinators/WaRetryCoordinator.d.ts +12 -0
- package/dist/types/client/coordinators/WaStreamControlCoordinator.d.ts +3 -2
- package/dist/types/client/coordinators/WaTrustedContactTokenCoordinator.d.ts +55 -0
- package/dist/types/client/dirty.d.ts +3 -1
- package/dist/types/client/events/abprops.d.ts +14 -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/events/registration.d.ts +17 -0
- package/dist/types/client/history-sync.d.ts +9 -6
- package/dist/types/client/incoming.d.ts +9 -2
- package/dist/types/client/index.d.ts +1 -1
- package/dist/types/client/mailbox.d.ts +5 -5
- package/dist/types/client/media.d.ts +31 -0
- package/dist/types/client/messages.d.ts +3 -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 +151 -4
- package/dist/types/crypto/core/index.d.ts +3 -2
- package/dist/types/crypto/core/nonce.d.ts +2 -0
- package/dist/types/crypto/core/primitives.d.ts +1 -2
- package/dist/types/crypto/core/random.d.ts +2 -1
- package/dist/types/crypto/core/xeddsa.d.ts +2 -0
- package/dist/types/crypto/curves/constants.d.ts +1 -0
- package/dist/types/crypto/index.d.ts +2 -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 +6 -3
- package/dist/types/infra/log/ConsoleLogger.d.ts +1 -1
- package/dist/types/infra/log/PinoLogger.d.ts +1 -1
- package/dist/types/infra/perf/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 +11 -0
- package/dist/types/media/WaMediaCrypto.d.ts +16 -6
- package/dist/types/media/WaMediaTransferClient.d.ts +6 -23
- package/dist/types/media/constants.d.ts +3 -1
- package/dist/types/media/index.d.ts +2 -1
- package/dist/types/media/processor.d.ts +28 -0
- package/dist/types/media/types.d.ts +19 -5
- package/dist/types/message/addon-crypto.d.ts +34 -3
- package/dist/types/message/content.d.ts +11 -1
- 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 +42 -11
- package/dist/types/protocol/abprops.d.ts +142 -0
- package/dist/types/protocol/appstate.d.ts +0 -11
- package/dist/types/protocol/browser.d.ts +1 -0
- package/dist/types/protocol/constants.d.ts +12 -4
- package/dist/types/protocol/defaults.d.ts +6 -0
- package/dist/types/protocol/email.d.ts +32 -0
- package/dist/types/protocol/index.d.ts +1 -2
- package/dist/types/protocol/jid.d.ts +20 -2
- package/dist/types/protocol/message.d.ts +60 -0
- package/dist/types/protocol/nodes.d.ts +6 -0
- package/dist/types/protocol/notification.d.ts +8 -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 +31 -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/reason.d.ts +1 -1
- 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 +9 -0
- package/dist/types/signal/api/SignalIdentitySyncApi.d.ts +5 -3
- 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/crypto/WaAdvSignature.d.ts +0 -2
- package/dist/types/signal/crypto/constants.d.ts +0 -1
- package/dist/types/signal/{store/sqlite.d.ts → encoding.d.ts} +9 -3
- package/dist/types/signal/group/SenderKeyChain.d.ts +1 -1
- package/dist/types/signal/group/SenderKeyManager.d.ts +17 -7
- package/dist/types/signal/index.d.ts +2 -0
- package/dist/types/signal/registration/utils.d.ts +2 -1
- package/dist/types/signal/session/SignalProtocol.d.ts +21 -6
- package/dist/types/signal/session/SignalSerializer.d.ts +2 -1
- package/dist/types/signal/session/resolver.d.ts +11 -4
- package/dist/types/signal/types.d.ts +16 -4
- package/dist/types/store/contracts/appstate.store.d.ts +1 -1
- package/dist/types/store/contracts/identity.store.d.ts +11 -0
- package/dist/types/store/contracts/message-secret.store.d.ts +16 -0
- package/dist/types/store/contracts/pre-key.store.d.ts +13 -0
- package/dist/types/store/contracts/privacy-token.store.d.ts +16 -0
- package/dist/types/store/contracts/retry.store.d.ts +7 -0
- package/dist/types/store/contracts/session.store.d.ts +14 -0
- package/dist/types/store/contracts/signal.store.d.ts +1 -27
- package/dist/types/store/createStore.d.ts +1 -1
- package/dist/types/store/index.d.ts +12 -12
- 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/identity.lock.d.ts +3 -0
- package/dist/types/store/locks/message-secret.lock.d.ts +3 -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/pre-key.lock.d.ts +3 -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/session.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/noop.store.d.ts +4 -0
- package/dist/types/store/providers/memory/appstate.store.d.ts +1 -1
- package/dist/types/store/providers/memory/identity.store.d.ts +18 -0
- package/dist/types/store/providers/memory/message-secret.store.d.ts +21 -0
- package/dist/types/store/providers/memory/pre-key.store.d.ts +23 -0
- package/dist/types/store/providers/memory/privacy-token.store.d.ts +13 -0
- package/dist/types/store/providers/memory/retry.store.d.ts +15 -1
- package/dist/types/store/providers/memory/session.store.d.ts +21 -0
- package/dist/types/store/providers/memory/signal.store.d.ts +2 -43
- package/dist/types/store/providers/memory/thread.store.d.ts +1 -1
- package/dist/types/store/types.d.ts +69 -61
- package/dist/types/transport/WaWebSocket.d.ts +1 -1
- package/dist/types/transport/binary/constants.d.ts +0 -30
- package/dist/types/transport/binary/index.d.ts +0 -1
- package/dist/types/transport/index.d.ts +8 -1
- package/dist/types/transport/keepalive/WaKeepAlive.d.ts +4 -1
- package/dist/types/transport/node/WaMobileTcpSocket.d.ts +18 -0
- package/dist/types/transport/node/WaNodeOrchestrator.d.ts +9 -6
- package/dist/types/transport/node/builders/abprops.d.ts +5 -0
- package/dist/types/transport/node/builders/business.d.ts +29 -0
- package/dist/types/transport/node/builders/device.d.ts +2 -0
- package/dist/types/transport/node/builders/email.d.ts +11 -0
- package/dist/types/transport/node/builders/global.d.ts +102 -0
- package/dist/types/transport/node/builders/message.d.ts +8 -7
- package/dist/types/transport/node/builders/offline.d.ts +2 -0
- package/dist/types/transport/node/builders/pairing.d.ts +0 -2
- package/dist/types/transport/node/builders/prekeys.d.ts +4 -3
- package/dist/types/transport/node/builders/presence.d.ts +6 -0
- package/dist/types/transport/node/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 +8 -0
- package/dist/types/transport/node/mex/argo-decoder.d.ts +11 -0
- package/dist/types/transport/node/mex/client.d.ts +18 -0
- package/dist/types/transport/node/mex/persist-ids.d.ts +14 -0
- package/dist/types/transport/noise/WaMobileClientPayload.d.ts +29 -0
- package/dist/types/transport/noise/WaNoiseCert.d.ts +7 -1
- package/dist/types/transport/noise/WaNoiseSession.d.ts +4 -2
- package/dist/types/transport/noise/WaNoiseSocket.d.ts +4 -2
- package/dist/types/transport/types.d.ts +8 -0
- 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 +34 -10
- package/proto/index.js +1 -1
- package/dist/auth/flow/WaAuthCredentialsFlow.js +0 -130
- package/dist/auth/pairing/constants.js +0 -5
- package/dist/client/connection/WaKeyShareCoordinator.js +0 -63
- package/dist/crypto/core/constants.js +0 -4
- package/dist/esm/auth/flow/WaAuthCredentialsFlow.js +0 -125
- package/dist/esm/auth/pairing/constants.js +0 -2
- package/dist/esm/client/connection/WaKeyShareCoordinator.js +0 -59
- 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/esm/transport/node/builders/index.js +0 -8
- 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/transport/node/builders/index.js +0 -42
- package/dist/types/appstate/store/sqlite.d.ts +0 -7
- package/dist/types/auth/flow/WaAuthCredentialsFlow.d.ts +0 -14
- package/dist/types/auth/pairing/constants.d.ts +0 -2
- package/dist/types/client/connection/WaKeyShareCoordinator.d.ts +0 -14
- package/dist/types/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
- package/dist/types/transport/node/builders/index.d.ts +0 -8
- /package/dist/appstate/{WaAppStateSyncResponseParser.js → response-parser.js} +0 -0
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.WaAppStateSyncClient = exports.WaAppStateMissingKeyError = void 0;
|
|
4
4
|
const constants_1 = require("./constants");
|
|
5
|
+
const response_parser_1 = require("./response-parser");
|
|
5
6
|
const WaAppStateCrypto_1 = require("./WaAppStateCrypto");
|
|
6
|
-
const
|
|
7
|
+
const _crypto_1 = require("../crypto/index.js");
|
|
7
8
|
const _proto_1 = require("../proto.js");
|
|
8
9
|
const constants_2 = require("../protocol/constants");
|
|
9
10
|
const jid_1 = require("../protocol/jid");
|
|
10
11
|
const query_1 = require("../transport/node/query");
|
|
11
12
|
const bytes_1 = require("../util/bytes");
|
|
12
|
-
const bytes_2 = require("../util/bytes");
|
|
13
13
|
const primitives_1 = require("../util/primitives");
|
|
14
14
|
class WaAppStateMissingKeyError extends Error {
|
|
15
15
|
constructor(message, keyId, collection) {
|
|
@@ -29,7 +29,8 @@ class WaAppStateSyncClient {
|
|
|
29
29
|
this.hostDomain = options.hostDomain ?? constants_2.WA_DEFAULTS.HOST_DOMAIN;
|
|
30
30
|
this.defaultTimeoutMs = options.defaultTimeoutMs ?? constants_2.WA_DEFAULTS.APP_STATE_SYNC_TIMEOUT_MS;
|
|
31
31
|
this.onMissingKeys = options.onMissingKeys;
|
|
32
|
-
this.crypto = new WaAppStateCrypto_1.WaAppStateCrypto();
|
|
32
|
+
this.crypto = new WaAppStateCrypto_1.WaAppStateCrypto(undefined, options.skipMacVerification === true);
|
|
33
|
+
this.mobilePrimary = options.mobilePrimary ?? false;
|
|
33
34
|
this.syncContext = null;
|
|
34
35
|
this.syncPromise = null;
|
|
35
36
|
}
|
|
@@ -37,6 +38,28 @@ class WaAppStateSyncClient {
|
|
|
37
38
|
this.logger.trace('app-state export requested');
|
|
38
39
|
return this.store.exportData();
|
|
39
40
|
}
|
|
41
|
+
async ensureInitialSyncKey() {
|
|
42
|
+
const existing = await this.store.getActiveSyncKey();
|
|
43
|
+
if (existing) {
|
|
44
|
+
return existing;
|
|
45
|
+
}
|
|
46
|
+
const keyIdBytes = await (0, _crypto_1.randomBytesAsync)(2);
|
|
47
|
+
const keyData = await (0, _crypto_1.randomBytesAsync)(32);
|
|
48
|
+
const rawId = await (0, _crypto_1.randomIntAsync)(0, 4294967295);
|
|
49
|
+
const key = {
|
|
50
|
+
keyId: keyIdBytes,
|
|
51
|
+
keyData,
|
|
52
|
+
timestamp: Date.now(),
|
|
53
|
+
fingerprint: { rawId, currentIndex: 0, deviceIndexes: [0] }
|
|
54
|
+
};
|
|
55
|
+
await this.store.upsertSyncKeys([key]);
|
|
56
|
+
this.crypto.clearCache();
|
|
57
|
+
this.logger.info('app-state initial sync key generated (mobile primary)', {
|
|
58
|
+
keyId: (0, bytes_1.bytesToHex)(keyIdBytes),
|
|
59
|
+
rawId
|
|
60
|
+
});
|
|
61
|
+
return key;
|
|
62
|
+
}
|
|
40
63
|
async importSyncKeys(keys) {
|
|
41
64
|
this.logger.debug('app-state importing sync keys', { count: keys.length });
|
|
42
65
|
const inserted = await this.store.upsertSyncKeys(keys);
|
|
@@ -52,7 +75,7 @@ class WaAppStateSyncClient {
|
|
|
52
75
|
const keyId = (0, bytes_1.decodeProtoBytes)(item.keyId?.keyId, 'appStateSyncKeyShare.keys[].keyId.keyId');
|
|
53
76
|
if (!item.keyData?.keyData) {
|
|
54
77
|
this.logger.debug('app-state sync key share entry missing key data', {
|
|
55
|
-
keyId: (0,
|
|
78
|
+
keyId: (0, bytes_1.bytesToHex)(keyId)
|
|
56
79
|
});
|
|
57
80
|
continue;
|
|
58
81
|
}
|
|
@@ -168,7 +191,12 @@ class WaAppStateSyncClient {
|
|
|
168
191
|
}
|
|
169
192
|
}
|
|
170
193
|
async syncCollectionsRound(collections, pendingByCollection, options) {
|
|
171
|
-
const
|
|
194
|
+
const activeSyncKey = await this.store.getActiveSyncKey();
|
|
195
|
+
const requestPromises = new Array(collections.length);
|
|
196
|
+
for (let index = 0; index < collections.length; index += 1) {
|
|
197
|
+
requestPromises[index] = this.buildCollectionSyncRequest(collections[index], pendingByCollection, activeSyncKey);
|
|
198
|
+
}
|
|
199
|
+
const requests = await Promise.all(requestPromises);
|
|
172
200
|
const collectionNodes = new Array(requests.length);
|
|
173
201
|
const outgoingContexts = new Map();
|
|
174
202
|
const skippedUploadCollections = new Set();
|
|
@@ -184,21 +212,26 @@ class WaAppStateSyncClient {
|
|
|
184
212
|
}
|
|
185
213
|
const iqNode = this.buildSyncIqNode(collectionNodes);
|
|
186
214
|
const payloadByCollection = await this.fetchSyncPayloadByCollection(iqNode, options.timeoutMs ?? this.defaultTimeoutMs);
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
215
|
+
const collectionOutcomePromises = new Array(collections.length);
|
|
216
|
+
for (let index = 0; index < collections.length; index += 1) {
|
|
217
|
+
collectionOutcomePromises[index] = this.processCollectionRound({
|
|
218
|
+
collection: collections[index],
|
|
219
|
+
payloadByCollection,
|
|
220
|
+
pendingByCollection,
|
|
221
|
+
options,
|
|
222
|
+
outgoingContexts,
|
|
223
|
+
skippedUploadCollections
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
const collectionOutcomes = await Promise.all(collectionOutcomePromises);
|
|
195
227
|
const results = [];
|
|
196
228
|
const collectionsToRefetch = [];
|
|
197
229
|
const blockedCollections = [];
|
|
198
230
|
const missingKeyIds = [];
|
|
199
231
|
const missingKeyIdHexes = new Set();
|
|
200
232
|
let stateChanged = false;
|
|
201
|
-
for (
|
|
233
|
+
for (let index = 0; index < collectionOutcomes.length; index += 1) {
|
|
234
|
+
const entry = collectionOutcomes[index];
|
|
202
235
|
results.push(entry.result);
|
|
203
236
|
if (entry.shouldRefetch) {
|
|
204
237
|
collectionsToRefetch.push(entry.collection);
|
|
@@ -210,7 +243,7 @@ class WaAppStateSyncClient {
|
|
|
210
243
|
blockedCollections.push(entry.collection);
|
|
211
244
|
}
|
|
212
245
|
if (entry.missingKeyId) {
|
|
213
|
-
const keyHex = (0,
|
|
246
|
+
const keyHex = (0, bytes_1.bytesToHex)(entry.missingKeyId);
|
|
214
247
|
if (!missingKeyIdHexes.has(keyHex)) {
|
|
215
248
|
missingKeyIdHexes.add(keyHex);
|
|
216
249
|
missingKeyIds.push(entry.missingKeyId);
|
|
@@ -225,7 +258,7 @@ class WaAppStateSyncClient {
|
|
|
225
258
|
blockedCollections
|
|
226
259
|
};
|
|
227
260
|
}
|
|
228
|
-
async buildCollectionSyncRequest(collection, pendingByCollection) {
|
|
261
|
+
async buildCollectionSyncRequest(collection, pendingByCollection, activeSyncKey) {
|
|
229
262
|
const collectionState = await this.getCollectionState(collection);
|
|
230
263
|
const hasPersistedState = collectionState.initialized;
|
|
231
264
|
const attrs = {
|
|
@@ -246,7 +279,7 @@ class WaAppStateSyncClient {
|
|
|
246
279
|
});
|
|
247
280
|
}
|
|
248
281
|
else {
|
|
249
|
-
const outgoing = await this.buildOutgoingPatch(collection, collectionState, pendingMutations);
|
|
282
|
+
const outgoing = await this.buildOutgoingPatch(collection, collectionState, pendingMutations, activeSyncKey);
|
|
250
283
|
outgoingContext = outgoing.context;
|
|
251
284
|
children.push({
|
|
252
285
|
tag: constants_2.WA_NODE_TAGS.PATCH,
|
|
@@ -277,7 +310,7 @@ class WaAppStateSyncClient {
|
|
|
277
310
|
content: [
|
|
278
311
|
{
|
|
279
312
|
tag: constants_2.WA_NODE_TAGS.SYNC,
|
|
280
|
-
attrs: {},
|
|
313
|
+
attrs: this.mobilePrimary ? { data_namespace: '3' } : {},
|
|
281
314
|
content: collectionNodes
|
|
282
315
|
}
|
|
283
316
|
]
|
|
@@ -290,7 +323,7 @@ class WaAppStateSyncClient {
|
|
|
290
323
|
type: responseNode.attrs.type
|
|
291
324
|
});
|
|
292
325
|
(0, query_1.assertIqResult)(responseNode, 'app-state sync');
|
|
293
|
-
const payloads = (0,
|
|
326
|
+
const payloads = (0, response_parser_1.parseSyncResponse)(responseNode);
|
|
294
327
|
this.logger.debug('app-state sync payloads parsed', { count: payloads.length });
|
|
295
328
|
const payloadByCollection = new Map();
|
|
296
329
|
for (const payload of payloads) {
|
|
@@ -332,14 +365,14 @@ class WaAppStateSyncClient {
|
|
|
332
365
|
const snapshotBytes = await downloader(payload.collection, 'snapshot', payload.snapshotReference);
|
|
333
366
|
const snapshot = this.validateSnapshot(payload.collection, _proto_1.proto.SyncdSnapshot.decode(snapshotBytes));
|
|
334
367
|
const snapshotMutations = await this.applySnapshot(payload.collection, snapshot);
|
|
335
|
-
appliedMutations
|
|
368
|
+
appliedMutations.push(...snapshotMutations);
|
|
336
369
|
collectionStateChanged = true;
|
|
337
370
|
}
|
|
338
371
|
if (payload.patches.length > 0) {
|
|
339
372
|
const readyPatches = await this.resolveReadyPatches(payload, options);
|
|
340
373
|
for (const readyPatch of readyPatches) {
|
|
341
374
|
const patchMutations = await this.applyPatch(payload.collection, readyPatch);
|
|
342
|
-
appliedMutations
|
|
375
|
+
appliedMutations.push(...patchMutations);
|
|
343
376
|
collectionStateChanged = true;
|
|
344
377
|
}
|
|
345
378
|
}
|
|
@@ -407,7 +440,7 @@ class WaAppStateSyncClient {
|
|
|
407
440
|
if (keyIds.length === 0 || collections.length === 0) {
|
|
408
441
|
return;
|
|
409
442
|
}
|
|
410
|
-
const keyIdsHex = keyIds.map((keyId) => (0,
|
|
443
|
+
const keyIdsHex = keyIds.map((keyId) => (0, bytes_1.bytesToHex)(keyId));
|
|
411
444
|
this.logger.info('app-state requesting missing sync keys', {
|
|
412
445
|
keys: keyIdsHex.length,
|
|
413
446
|
keyIds: keyIdsHex.join(','),
|
|
@@ -428,13 +461,12 @@ class WaAppStateSyncClient {
|
|
|
428
461
|
}
|
|
429
462
|
}
|
|
430
463
|
async resolveReadyPatches(payload, options) {
|
|
431
|
-
const sortedPatches = payload.patches
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
.map((entry) => entry.patch);
|
|
464
|
+
const sortedPatches = payload.patches.slice();
|
|
465
|
+
const sortVersions = new Map();
|
|
466
|
+
for (const patch of sortedPatches) {
|
|
467
|
+
sortVersions.set(patch, this.parseCollectionPatchVersion(payload.collection, patch));
|
|
468
|
+
}
|
|
469
|
+
sortedPatches.sort((left, right) => sortVersions.get(left) - sortVersions.get(right));
|
|
438
470
|
return Promise.all(sortedPatches.map(async (patch) => {
|
|
439
471
|
let readyPatch = patch;
|
|
440
472
|
if ((!readyPatch.mutations || readyPatch.mutations.length === 0) &&
|
|
@@ -457,11 +489,13 @@ class WaAppStateSyncClient {
|
|
|
457
489
|
if (!snapshot.version?.version) {
|
|
458
490
|
throw new Error(`snapshot for ${collection} is missing version`);
|
|
459
491
|
}
|
|
460
|
-
if (!
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
492
|
+
if (!this.crypto.isMacVerificationSkipped) {
|
|
493
|
+
if (!snapshot.mac) {
|
|
494
|
+
throw new Error(`snapshot for ${collection} is missing mac`);
|
|
495
|
+
}
|
|
496
|
+
if (!snapshot.keyId?.id) {
|
|
497
|
+
throw new Error(`snapshot for ${collection} is missing keyId`);
|
|
498
|
+
}
|
|
465
499
|
}
|
|
466
500
|
return snapshot;
|
|
467
501
|
}
|
|
@@ -476,14 +510,16 @@ class WaAppStateSyncClient {
|
|
|
476
510
|
if (!patch.version?.version) {
|
|
477
511
|
throw new Error(`patch for ${collection} is missing version`);
|
|
478
512
|
}
|
|
479
|
-
if (!
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
513
|
+
if (!this.crypto.isMacVerificationSkipped) {
|
|
514
|
+
if (!patch.snapshotMac) {
|
|
515
|
+
throw new Error(`patch for ${collection} is missing snapshotMac`);
|
|
516
|
+
}
|
|
517
|
+
if (!patch.patchMac) {
|
|
518
|
+
throw new Error(`patch for ${collection} is missing patchMac`);
|
|
519
|
+
}
|
|
520
|
+
if (!patch.keyId?.id) {
|
|
521
|
+
throw new Error(`patch for ${collection} is missing keyId`);
|
|
522
|
+
}
|
|
487
523
|
}
|
|
488
524
|
if (patch.mutations && patch.mutations.length > 0 && patch.externalMutations) {
|
|
489
525
|
throw new Error(`patch for ${collection} has inline and external mutations together`);
|
|
@@ -497,16 +533,19 @@ class WaAppStateSyncClient {
|
|
|
497
533
|
}
|
|
498
534
|
async applySnapshot(collection, snapshot) {
|
|
499
535
|
const version = this.normalizeProtoLong(snapshot.version?.version, `snapshot.version.version (${collection})`);
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
536
|
+
let keyData = null;
|
|
537
|
+
if (!this.crypto.isMacVerificationSkipped) {
|
|
538
|
+
const keyId = (0, bytes_1.decodeProtoBytes)(snapshot.keyId?.id, `snapshot.keyId.id (${collection})`);
|
|
539
|
+
keyData = await this.getKeyData(keyId);
|
|
540
|
+
if (!keyData) {
|
|
541
|
+
throw new WaAppStateMissingKeyError(`missing snapshot key ${(0, bytes_1.bytesToHex)(keyId)} for ${collection}`, keyId, collection);
|
|
542
|
+
}
|
|
504
543
|
}
|
|
505
544
|
const indexValueMap = new Map();
|
|
506
545
|
const mutations = [];
|
|
507
546
|
const decryptedRecords = await this.decryptSnapshotRecords(collection, snapshot);
|
|
508
547
|
for (const { decrypted, recordKeyId } of decryptedRecords) {
|
|
509
|
-
const indexMacHex = (0,
|
|
548
|
+
const indexMacHex = (0, bytes_1.bytesToHex)(decrypted.indexMac);
|
|
510
549
|
indexValueMap.set(indexMacHex, decrypted.valueMac);
|
|
511
550
|
mutations.push({
|
|
512
551
|
collection,
|
|
@@ -521,10 +560,18 @@ class WaAppStateSyncClient {
|
|
|
521
560
|
timestamp: this.normalizeProtoLong(decrypted.value?.timestamp, `snapshot.record.value.timestamp (${collection})`)
|
|
522
561
|
});
|
|
523
562
|
}
|
|
524
|
-
const
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
563
|
+
const ltHashInput = new Array(indexValueMap.size);
|
|
564
|
+
let ltHashInputIndex = 0;
|
|
565
|
+
for (const valueMac of indexValueMap.values()) {
|
|
566
|
+
ltHashInput[ltHashInputIndex] = valueMac;
|
|
567
|
+
ltHashInputIndex += 1;
|
|
568
|
+
}
|
|
569
|
+
const ltHash = await this.crypto.ltHashAdd(constants_1.APP_STATE_EMPTY_LT_HASH, ltHashInput);
|
|
570
|
+
if (keyData !== null) {
|
|
571
|
+
const expectedSnapshotMac = await this.crypto.generateSnapshotMac(keyData, ltHash, version, collection);
|
|
572
|
+
if (!(0, bytes_1.uint8Equal)(expectedSnapshotMac, snapshot.mac)) {
|
|
573
|
+
throw new Error(`snapshot MAC mismatch for ${collection}`);
|
|
574
|
+
}
|
|
528
575
|
}
|
|
529
576
|
this.setCollectionState(collection, version, ltHash, indexValueMap);
|
|
530
577
|
return mutations;
|
|
@@ -535,10 +582,13 @@ class WaAppStateSyncClient {
|
|
|
535
582
|
if (current.version !== patchVersion - 1) {
|
|
536
583
|
throw new Error(`patch version mismatch for ${collection}: local=${current.version}, incoming=${patchVersion}`);
|
|
537
584
|
}
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
585
|
+
let patchKeyData = null;
|
|
586
|
+
if (!this.crypto.isMacVerificationSkipped) {
|
|
587
|
+
const patchKeyId = (0, bytes_1.decodeProtoBytes)(patch.keyId?.id, `patch.keyId.id (${collection})`);
|
|
588
|
+
patchKeyData = await this.getKeyData(patchKeyId);
|
|
589
|
+
if (!patchKeyData) {
|
|
590
|
+
throw new WaAppStateMissingKeyError(`missing patch key ${(0, bytes_1.bytesToHex)(patchKeyId)} for ${collection}`, patchKeyId, collection);
|
|
591
|
+
}
|
|
542
592
|
}
|
|
543
593
|
const decryptedMutations = await this.decryptPatchMutations(collection, patch);
|
|
544
594
|
const macMutations = new Array(decryptedMutations.length);
|
|
@@ -553,37 +603,56 @@ class WaAppStateSyncClient {
|
|
|
553
603
|
};
|
|
554
604
|
}
|
|
555
605
|
const nextState = await this.computeNextCollectionState(current.hash, current.indexValueMap, macMutations, collection);
|
|
556
|
-
|
|
606
|
+
if (patchKeyData !== null) {
|
|
607
|
+
await this.assertPatchMacsMatch(patch, collection, patchKeyData, patchVersion, nextState.hash, valueMacs);
|
|
608
|
+
}
|
|
557
609
|
this.setCollectionState(collection, patchVersion, nextState.hash, nextState.indexValueMap);
|
|
558
|
-
return decryptedMutations
|
|
610
|
+
return decryptedMutations;
|
|
559
611
|
}
|
|
560
612
|
async decryptSnapshotRecords(collection, snapshot) {
|
|
561
|
-
const
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
throw new WaAppStateMissingKeyError(`missing snapshot mutation key ${(0, bytes_2.bytesToHex)(recordKeyId)} for ${collection}`, recordKeyId, collection);
|
|
571
|
-
}
|
|
572
|
-
const decrypted = await this.crypto.decryptMutation({
|
|
573
|
-
operation: _proto_1.proto.SyncdMutation.SyncdOperation.SET,
|
|
574
|
-
keyId: recordKeyId,
|
|
575
|
-
keyData: recordKeyData,
|
|
576
|
-
indexMac,
|
|
577
|
-
valueBlob
|
|
578
|
-
});
|
|
579
|
-
return {
|
|
580
|
-
decrypted,
|
|
613
|
+
const rawRecords = snapshot.records ?? [];
|
|
614
|
+
const records = new Array(rawRecords.length);
|
|
615
|
+
const recordKeyIds = new Array(rawRecords.length);
|
|
616
|
+
for (let i = 0; i < rawRecords.length; i += 1) {
|
|
617
|
+
const record = rawRecords[i];
|
|
618
|
+
const recordKeyId = (0, bytes_1.decodeProtoBytes)(record.keyId?.id, `snapshot.record.keyId.id (${collection})`);
|
|
619
|
+
records[i] = {
|
|
620
|
+
indexMac: (0, bytes_1.decodeProtoBytes)(record.index?.blob, `snapshot.record.index.blob (${collection})`),
|
|
621
|
+
valueBlob: (0, bytes_1.decodeProtoBytes)(record.value?.blob, `snapshot.record.value.blob (${collection})`),
|
|
581
622
|
recordKeyId
|
|
582
623
|
};
|
|
583
|
-
|
|
624
|
+
recordKeyIds[i] = recordKeyId;
|
|
625
|
+
}
|
|
626
|
+
await this.preloadKeyData(recordKeyIds);
|
|
627
|
+
const decryptTasks = new Array(records.length);
|
|
628
|
+
for (let i = 0; i < records.length; i += 1) {
|
|
629
|
+
const { indexMac, valueBlob, recordKeyId } = records[i];
|
|
630
|
+
decryptTasks[i] = (async () => {
|
|
631
|
+
const recordKeyData = await this.getKeyData(recordKeyId);
|
|
632
|
+
if (!recordKeyData) {
|
|
633
|
+
throw new WaAppStateMissingKeyError(`missing snapshot mutation key ${(0, bytes_1.bytesToHex)(recordKeyId)} for ${collection}`, recordKeyId, collection);
|
|
634
|
+
}
|
|
635
|
+
const decrypted = await this.crypto.decryptMutation({
|
|
636
|
+
operation: _proto_1.proto.SyncdMutation.SyncdOperation.SET,
|
|
637
|
+
keyId: recordKeyId,
|
|
638
|
+
keyData: recordKeyData,
|
|
639
|
+
indexMac,
|
|
640
|
+
valueBlob
|
|
641
|
+
});
|
|
642
|
+
return {
|
|
643
|
+
decrypted,
|
|
644
|
+
recordKeyId
|
|
645
|
+
};
|
|
646
|
+
})();
|
|
647
|
+
}
|
|
648
|
+
return Promise.all(decryptTasks);
|
|
584
649
|
}
|
|
585
650
|
async decryptPatchMutations(collection, patch) {
|
|
586
|
-
const
|
|
651
|
+
const rawMutations = patch.mutations ?? [];
|
|
652
|
+
const parsedMutations = new Array(rawMutations.length);
|
|
653
|
+
const mutationKeyIds = new Array(rawMutations.length);
|
|
654
|
+
for (let i = 0; i < rawMutations.length; i += 1) {
|
|
655
|
+
const mutation = rawMutations[i];
|
|
587
656
|
const operationCode = mutation.operation;
|
|
588
657
|
if (operationCode === null || operationCode === undefined) {
|
|
589
658
|
throw new Error(`patch mutation is missing operation (${collection})`);
|
|
@@ -592,57 +661,63 @@ class WaAppStateSyncClient {
|
|
|
592
661
|
if (!record) {
|
|
593
662
|
throw new Error(`patch mutation is missing record (${collection})`);
|
|
594
663
|
}
|
|
595
|
-
|
|
664
|
+
const recordKeyId = (0, bytes_1.decodeProtoBytes)(record.keyId?.id, `patch.record.keyId.id (${collection})`);
|
|
665
|
+
parsedMutations[i] = {
|
|
596
666
|
operationCode,
|
|
597
667
|
indexMac: (0, bytes_1.decodeProtoBytes)(record.index?.blob, `patch.record.index.blob (${collection})`),
|
|
598
668
|
valueBlob: (0, bytes_1.decodeProtoBytes)(record.value?.blob, `patch.record.value.blob (${collection})`),
|
|
599
|
-
recordKeyId
|
|
600
|
-
};
|
|
601
|
-
});
|
|
602
|
-
await this.preloadKeyData(parsedMutations.map((mutation) => mutation.recordKeyId));
|
|
603
|
-
return Promise.all(parsedMutations.map(async ({ operationCode, indexMac, valueBlob, recordKeyId }) => {
|
|
604
|
-
const recordKeyData = await this.getKeyData(recordKeyId);
|
|
605
|
-
if (!recordKeyData) {
|
|
606
|
-
throw new WaAppStateMissingKeyError(`missing mutation key ${(0, bytes_2.bytesToHex)(recordKeyId)} for ${collection}`, recordKeyId, collection);
|
|
607
|
-
}
|
|
608
|
-
const decrypted = await this.crypto.decryptMutation({
|
|
609
|
-
operation: operationCode,
|
|
610
|
-
keyId: recordKeyId,
|
|
611
|
-
keyData: recordKeyData,
|
|
612
|
-
indexMac,
|
|
613
|
-
valueBlob
|
|
614
|
-
});
|
|
615
|
-
return {
|
|
616
|
-
collection,
|
|
617
|
-
operation: operationCode === _proto_1.proto.SyncdMutation.SyncdOperation.REMOVE
|
|
618
|
-
? 'remove'
|
|
619
|
-
: 'set',
|
|
620
|
-
source: 'patch',
|
|
621
|
-
operationCode,
|
|
622
|
-
index: decrypted.index,
|
|
623
|
-
value: decrypted.value,
|
|
624
|
-
version: decrypted.version,
|
|
625
|
-
indexMac: decrypted.indexMac,
|
|
626
|
-
valueMac: decrypted.valueMac,
|
|
627
|
-
keyId: recordKeyId,
|
|
628
|
-
timestamp: this.normalizeProtoLong(decrypted.value?.timestamp, `patch.record.value.timestamp (${collection})`)
|
|
669
|
+
recordKeyId
|
|
629
670
|
};
|
|
630
|
-
|
|
671
|
+
mutationKeyIds[i] = recordKeyId;
|
|
672
|
+
}
|
|
673
|
+
await this.preloadKeyData(mutationKeyIds);
|
|
674
|
+
const decryptTasks = new Array(parsedMutations.length);
|
|
675
|
+
for (let i = 0; i < parsedMutations.length; i += 1) {
|
|
676
|
+
const { operationCode, indexMac, valueBlob, recordKeyId } = parsedMutations[i];
|
|
677
|
+
decryptTasks[i] = (async () => {
|
|
678
|
+
const recordKeyData = await this.getKeyData(recordKeyId);
|
|
679
|
+
if (!recordKeyData) {
|
|
680
|
+
throw new WaAppStateMissingKeyError(`missing mutation key ${(0, bytes_1.bytesToHex)(recordKeyId)} for ${collection}`, recordKeyId, collection);
|
|
681
|
+
}
|
|
682
|
+
const decrypted = await this.crypto.decryptMutation({
|
|
683
|
+
operation: operationCode,
|
|
684
|
+
keyId: recordKeyId,
|
|
685
|
+
keyData: recordKeyData,
|
|
686
|
+
indexMac,
|
|
687
|
+
valueBlob
|
|
688
|
+
});
|
|
689
|
+
return {
|
|
690
|
+
collection,
|
|
691
|
+
operation: operationCode === _proto_1.proto.SyncdMutation.SyncdOperation.REMOVE
|
|
692
|
+
? 'remove'
|
|
693
|
+
: 'set',
|
|
694
|
+
source: 'patch',
|
|
695
|
+
operationCode,
|
|
696
|
+
index: decrypted.index,
|
|
697
|
+
value: decrypted.value,
|
|
698
|
+
version: decrypted.version,
|
|
699
|
+
indexMac: decrypted.indexMac,
|
|
700
|
+
valueMac: decrypted.valueMac,
|
|
701
|
+
keyId: recordKeyId,
|
|
702
|
+
timestamp: this.normalizeProtoLong(decrypted.value?.timestamp, `patch.record.value.timestamp (${collection})`)
|
|
703
|
+
};
|
|
704
|
+
})();
|
|
705
|
+
}
|
|
706
|
+
return Promise.all(decryptTasks);
|
|
631
707
|
}
|
|
632
708
|
async assertPatchMacsMatch(patch, collection, patchKeyData, patchVersion, nextHash, valueMacs) {
|
|
633
709
|
const snapshotMac = (0, bytes_1.decodeProtoBytes)(patch.snapshotMac, `patch.snapshotMac (${collection})`);
|
|
634
710
|
const expectedSnapshotMac = await this.crypto.generateSnapshotMac(patchKeyData, nextHash, patchVersion, collection);
|
|
635
|
-
if (!(0,
|
|
711
|
+
if (!(0, bytes_1.uint8Equal)(expectedSnapshotMac, snapshotMac)) {
|
|
636
712
|
throw new Error(`patch snapshot MAC mismatch for ${collection}`);
|
|
637
713
|
}
|
|
638
714
|
const patchMac = (0, bytes_1.decodeProtoBytes)(patch.patchMac, `patch.patchMac (${collection})`);
|
|
639
715
|
const expectedPatchMac = await this.crypto.generatePatchMac(patchKeyData, snapshotMac, valueMacs, patchVersion, collection);
|
|
640
|
-
if (!(0,
|
|
716
|
+
if (!(0, bytes_1.uint8Equal)(expectedPatchMac, patchMac)) {
|
|
641
717
|
throw new Error(`patch MAC mismatch for ${collection}`);
|
|
642
718
|
}
|
|
643
719
|
}
|
|
644
|
-
async buildOutgoingPatch(collection, snapshot, pendingMutations) {
|
|
645
|
-
const activeKey = await this.store.getActiveSyncKey();
|
|
720
|
+
async buildOutgoingPatch(collection, snapshot, pendingMutations, activeKey) {
|
|
646
721
|
if (!activeKey) {
|
|
647
722
|
throw new WaAppStateMissingKeyError(`no sync key available to upload ${collection}`, null, collection);
|
|
648
723
|
}
|
|
@@ -661,23 +736,30 @@ class WaAppStateSyncClient {
|
|
|
661
736
|
});
|
|
662
737
|
return { operationCode, encrypted };
|
|
663
738
|
}));
|
|
664
|
-
const encryptedMutations = encryptedResults.
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
739
|
+
const encryptedMutations = new Array(encryptedResults.length);
|
|
740
|
+
const macMutations = new Array(encryptedResults.length);
|
|
741
|
+
const valueMacs = new Array(encryptedResults.length);
|
|
742
|
+
for (let i = 0; i < encryptedResults.length; i += 1) {
|
|
743
|
+
const { operationCode, encrypted } = encryptedResults[i];
|
|
744
|
+
encryptedMutations[i] = {
|
|
745
|
+
operation: operationCode,
|
|
746
|
+
record: {
|
|
747
|
+
keyId: { id: activeKey.keyId },
|
|
748
|
+
index: { blob: encrypted.indexMac },
|
|
749
|
+
value: { blob: encrypted.valueBlob }
|
|
750
|
+
}
|
|
751
|
+
};
|
|
752
|
+
macMutations[i] = {
|
|
753
|
+
operation: operationCode,
|
|
754
|
+
indexMac: encrypted.indexMac,
|
|
755
|
+
valueMac: encrypted.valueMac
|
|
756
|
+
};
|
|
757
|
+
valueMacs[i] = encrypted.valueMac;
|
|
758
|
+
}
|
|
677
759
|
const nextState = await this.computeNextCollectionState(snapshot.hash, snapshot.indexValueMap, macMutations, collection);
|
|
678
760
|
const patchVersion = snapshot.version + 1;
|
|
679
761
|
const snapshotMac = await this.crypto.generateSnapshotMac(activeKey.keyData, nextState.hash, patchVersion, collection);
|
|
680
|
-
const patchMac = await this.crypto.generatePatchMac(activeKey.keyData, snapshotMac,
|
|
762
|
+
const patchMac = await this.crypto.generatePatchMac(activeKey.keyData, snapshotMac, valueMacs, patchVersion, collection);
|
|
681
763
|
const deviceIndex = this.resolveDeviceIndex();
|
|
682
764
|
const clientDebugData = this.buildPatchClientDebugData();
|
|
683
765
|
const encodedPatch = _proto_1.proto.SyncdPatch.encode({
|
|
@@ -726,7 +808,7 @@ class WaAppStateSyncClient {
|
|
|
726
808
|
const removeValues = [];
|
|
727
809
|
let missingRemoveCount = 0;
|
|
728
810
|
for (const mutation of mutations) {
|
|
729
|
-
const indexMacHex = (0,
|
|
811
|
+
const indexMacHex = (0, bytes_1.bytesToHex)(mutation.indexMac);
|
|
730
812
|
const existing = indexValueMap.get(indexMacHex);
|
|
731
813
|
if (mutation.operation === _proto_1.proto.SyncdMutation.SyncdOperation.REMOVE) {
|
|
732
814
|
if (!existing) {
|
|
@@ -800,7 +882,7 @@ class WaAppStateSyncClient {
|
|
|
800
882
|
const missingKeyHexes = new Set();
|
|
801
883
|
for (let index = 0; index < keyIds.length; index += 1) {
|
|
802
884
|
const keyId = keyIds[index];
|
|
803
|
-
const keyHex = (0,
|
|
885
|
+
const keyHex = (0, bytes_1.bytesToHex)(keyId);
|
|
804
886
|
if (context.keys.has(keyHex) || missingKeyHexes.has(keyHex)) {
|
|
805
887
|
continue;
|
|
806
888
|
}
|
|
@@ -812,12 +894,12 @@ class WaAppStateSyncClient {
|
|
|
812
894
|
}
|
|
813
895
|
const loadedKeyData = await this.store.getSyncKeyDataBatch(missingKeyIds);
|
|
814
896
|
for (let index = 0; index < missingKeyIds.length; index += 1) {
|
|
815
|
-
context.keys.set((0,
|
|
897
|
+
context.keys.set((0, bytes_1.bytesToHex)(missingKeyIds[index]), loadedKeyData[index] ?? null);
|
|
816
898
|
}
|
|
817
899
|
}
|
|
818
900
|
async getKeyData(keyId) {
|
|
819
901
|
const context = this.requireSyncContext();
|
|
820
|
-
const keyHex = (0,
|
|
902
|
+
const keyHex = (0, bytes_1.bytesToHex)(keyId);
|
|
821
903
|
if (context.keys.has(keyHex)) {
|
|
822
904
|
return context.keys.get(keyHex) ?? null;
|
|
823
905
|
}
|
|
@@ -4,8 +4,8 @@ exports.encodeAppStateFingerprint = encodeAppStateFingerprint;
|
|
|
4
4
|
exports.decodeAppStateFingerprint = decodeAppStateFingerprint;
|
|
5
5
|
exports.decodeAppStateSyncKeys = decodeAppStateSyncKeys;
|
|
6
6
|
exports.decodeAppStateCollections = decodeAppStateCollections;
|
|
7
|
-
const _proto_1 = require("
|
|
8
|
-
const coercion_1 = require("
|
|
7
|
+
const _proto_1 = require("../proto.js");
|
|
8
|
+
const coercion_1 = require("../util/coercion");
|
|
9
9
|
function encodeAppStateFingerprint(fingerprint) {
|
|
10
10
|
if (!fingerprint) {
|
|
11
11
|
return null;
|
|
@@ -26,12 +26,17 @@ function decodeAppStateFingerprint(raw) {
|
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
function decodeAppStateSyncKeys(rows) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
const decoded = new Array(rows.length);
|
|
30
|
+
for (let i = 0; i < rows.length; i += 1) {
|
|
31
|
+
const row = rows[i];
|
|
32
|
+
decoded[i] = {
|
|
33
|
+
keyId: (0, coercion_1.asBytes)(row.key_id, 'appstate_sync_keys.key_id'),
|
|
34
|
+
keyData: (0, coercion_1.asBytes)(row.key_data, 'appstate_sync_keys.key_data'),
|
|
35
|
+
timestamp: (0, coercion_1.asNumber)(row.timestamp, 'appstate_sync_keys.timestamp'),
|
|
36
|
+
fingerprint: decodeAppStateFingerprint(row.fingerprint)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return decoded;
|
|
35
40
|
}
|
|
36
41
|
function decodeAppStateCollections(versionRows, valueRows) {
|
|
37
42
|
const valueMapByCollection = new Map();
|
package/dist/appstate/index.js
CHANGED
|
@@ -14,15 +14,17 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.WaAppStateSyncClient = exports.parseSyncResponse = exports.
|
|
17
|
+
exports.WaAppStateSyncClient = exports.parseSyncResponse = exports.WaAppStateCrypto = exports.decodeAppStateSyncKeys = exports.decodeAppStateCollections = exports.decodeAppStateFingerprint = exports.encodeAppStateFingerprint = void 0;
|
|
18
18
|
__exportStar(require("./constants"), exports);
|
|
19
|
+
var encoding_1 = require("./encoding");
|
|
20
|
+
Object.defineProperty(exports, "encodeAppStateFingerprint", { enumerable: true, get: function () { return encoding_1.encodeAppStateFingerprint; } });
|
|
21
|
+
Object.defineProperty(exports, "decodeAppStateFingerprint", { enumerable: true, get: function () { return encoding_1.decodeAppStateFingerprint; } });
|
|
22
|
+
Object.defineProperty(exports, "decodeAppStateCollections", { enumerable: true, get: function () { return encoding_1.decodeAppStateCollections; } });
|
|
23
|
+
Object.defineProperty(exports, "decodeAppStateSyncKeys", { enumerable: true, get: function () { return encoding_1.decodeAppStateSyncKeys; } });
|
|
19
24
|
__exportStar(require("./utils"), exports);
|
|
20
25
|
var WaAppStateCrypto_1 = require("./WaAppStateCrypto");
|
|
21
26
|
Object.defineProperty(exports, "WaAppStateCrypto", { enumerable: true, get: function () { return WaAppStateCrypto_1.WaAppStateCrypto; } });
|
|
27
|
+
var response_parser_1 = require("./response-parser");
|
|
28
|
+
Object.defineProperty(exports, "parseSyncResponse", { enumerable: true, get: function () { return response_parser_1.parseSyncResponse; } });
|
|
22
29
|
var WaAppStateSyncClient_1 = require("./WaAppStateSyncClient");
|
|
23
|
-
Object.defineProperty(exports, "
|
|
24
|
-
var WaAppStateSyncResponseParser_1 = require("./WaAppStateSyncResponseParser");
|
|
25
|
-
Object.defineProperty(exports, "parseCollectionState", { enumerable: true, get: function () { return WaAppStateSyncResponseParser_1.parseCollectionState; } });
|
|
26
|
-
Object.defineProperty(exports, "parseSyncResponse", { enumerable: true, get: function () { return WaAppStateSyncResponseParser_1.parseSyncResponse; } });
|
|
27
|
-
var WaAppStateSyncClient_2 = require("./WaAppStateSyncClient");
|
|
28
|
-
Object.defineProperty(exports, "WaAppStateSyncClient", { enumerable: true, get: function () { return WaAppStateSyncClient_2.WaAppStateSyncClient; } });
|
|
30
|
+
Object.defineProperty(exports, "WaAppStateSyncClient", { enumerable: true, get: function () { return WaAppStateSyncClient_1.WaAppStateSyncClient; } });
|
package/dist/appstate/utils.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseCollectionName = parseCollectionName;
|
|
4
|
-
exports.keyDeviceId = keyDeviceId;
|
|
5
4
|
exports.keyEpoch = keyEpoch;
|
|
6
5
|
exports.pickActiveSyncKey = pickActiveSyncKey;
|
|
7
|
-
exports.toNetworkOrder64 = toNetworkOrder64;
|
|
8
6
|
exports.downloadExternalBlobReference = downloadExternalBlobReference;
|
|
9
7
|
const constants_1 = require("../protocol/constants");
|
|
10
8
|
const bytes_1 = require("../util/bytes");
|
|
@@ -44,9 +42,6 @@ function pickActiveSyncKey(keys) {
|
|
|
44
42
|
}
|
|
45
43
|
return active;
|
|
46
44
|
}
|
|
47
|
-
function toNetworkOrder64(value) {
|
|
48
|
-
return (0, bytes_1.intToBytes)(8, value);
|
|
49
|
-
}
|
|
50
45
|
async function downloadExternalBlobReference(mediaTransfer, reference) {
|
|
51
46
|
if (!reference.directPath) {
|
|
52
47
|
throw new Error('external blob reference is missing directPath');
|