zapo-js 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -4
- package/dist/appstate/WaAppStateCrypto.js +1 -1
- package/dist/appstate/WaAppStateSyncClient.js +138 -93
- package/dist/appstate/{store/sqlite.js → encoding.js} +13 -8
- package/dist/appstate/index.js +8 -6
- package/dist/appstate/utils.js +0 -5
- package/dist/auth/WaAuthClient.js +36 -47
- package/dist/auth/flow/WaAuthCredentialsFlow.js +7 -7
- package/dist/auth/index.js +1 -6
- package/dist/auth/pairing/WaPairingCodeCrypto.js +6 -4
- package/dist/auth/pairing/WaPairingFlow.js +13 -3
- package/dist/client/WaClient.js +225 -101
- package/dist/client/WaClientFactory.js +294 -44
- package/dist/client/connection/WaConnectionManager.js +19 -10
- package/dist/client/coordinators/WaBusinessCoordinator.js +241 -0
- package/dist/client/coordinators/WaGroupCoordinator.js +11 -7
- package/dist/client/coordinators/WaIncomingNodeCoordinator.js +1 -0
- package/dist/client/coordinators/WaMessageDispatchCoordinator.js +292 -99
- package/dist/client/coordinators/WaPassiveTasksCoordinator.js +74 -31
- package/dist/client/coordinators/WaPrivacyCoordinator.js +134 -0
- package/dist/client/coordinators/WaProfileCoordinator.js +212 -0
- package/dist/client/coordinators/WaRetryCoordinator.js +179 -27
- package/dist/client/coordinators/WaStreamControlCoordinator.js +18 -11
- package/dist/client/coordinators/WaTrustedContactTokenCoordinator.js +166 -0
- package/dist/client/dirty.js +40 -20
- package/dist/client/events/devices.js +72 -0
- package/dist/client/events/group.js +3 -11
- package/dist/client/events/identity.js +22 -0
- package/dist/client/events/privacy-token.js +39 -0
- package/dist/client/history-sync.js +50 -9
- package/dist/client/incoming.js +37 -7
- package/dist/client/mailbox.js +24 -23
- package/dist/client/messages.js +107 -31
- package/dist/client/messaging/fanout.js +21 -11
- package/dist/client/messaging/participants.js +6 -4
- package/dist/client/persistence/WriteBehindPersistence.js +129 -0
- package/dist/client/tokens/cs-token.js +50 -0
- package/dist/client/tokens/tc-token.js +25 -0
- package/dist/crypto/core/index.js +2 -2
- package/dist/crypto/core/keys.js +4 -4
- package/dist/crypto/core/nonce.js +2 -0
- package/dist/crypto/core/primitives.js +0 -8
- package/dist/crypto/core/random.js +22 -0
- package/dist/crypto/curves/X25519.js +25 -6
- package/dist/crypto/index.js +3 -0
- package/dist/crypto/math/constants.js +13 -36
- package/dist/crypto/math/edwards.js +171 -44
- package/dist/crypto/math/fe.js +706 -0
- package/dist/crypto/math/mod.js +10 -3
- package/dist/esm/appstate/WaAppStateCrypto.js +1 -1
- package/dist/esm/appstate/WaAppStateSyncClient.js +138 -93
- package/dist/esm/appstate/{store/sqlite.js → encoding.js} +13 -8
- package/dist/esm/appstate/index.js +2 -2
- package/dist/esm/appstate/utils.js +2 -5
- package/dist/esm/auth/WaAuthClient.js +36 -47
- package/dist/esm/auth/flow/WaAuthCredentialsFlow.js +7 -7
- package/dist/esm/auth/index.js +0 -2
- package/dist/esm/auth/pairing/WaPairingCodeCrypto.js +6 -4
- package/dist/esm/auth/pairing/WaPairingFlow.js +14 -4
- package/dist/esm/client/WaClient.js +225 -101
- package/dist/esm/client/WaClientFactory.js +295 -45
- package/dist/esm/client/connection/WaConnectionManager.js +19 -10
- package/dist/esm/client/coordinators/WaBusinessCoordinator.js +238 -0
- package/dist/esm/client/coordinators/WaGroupCoordinator.js +11 -7
- package/dist/esm/client/coordinators/WaIncomingNodeCoordinator.js +1 -0
- package/dist/esm/client/coordinators/WaMessageDispatchCoordinator.js +295 -102
- package/dist/esm/client/coordinators/WaPassiveTasksCoordinator.js +74 -31
- package/dist/esm/client/coordinators/WaPrivacyCoordinator.js +131 -0
- package/dist/esm/client/coordinators/WaProfileCoordinator.js +209 -0
- package/dist/esm/client/coordinators/WaRetryCoordinator.js +181 -29
- package/dist/esm/client/coordinators/WaStreamControlCoordinator.js +19 -12
- package/dist/esm/client/coordinators/WaTrustedContactTokenCoordinator.js +162 -0
- package/dist/esm/client/dirty.js +40 -20
- package/dist/esm/client/events/devices.js +68 -0
- package/dist/esm/client/events/group.js +3 -11
- package/dist/esm/client/events/identity.js +19 -0
- package/dist/esm/client/events/privacy-token.js +36 -0
- package/dist/esm/client/history-sync.js +50 -9
- package/dist/esm/client/incoming.js +38 -8
- package/dist/esm/client/mailbox.js +24 -23
- package/dist/esm/client/messages.js +108 -32
- package/dist/esm/client/messaging/fanout.js +22 -12
- package/dist/esm/client/messaging/participants.js +6 -4
- package/dist/esm/client/persistence/WriteBehindPersistence.js +125 -0
- package/dist/esm/client/tokens/cs-token.js +46 -0
- package/dist/esm/client/tokens/tc-token.js +18 -0
- package/dist/esm/crypto/core/index.js +2 -2
- package/dist/esm/crypto/core/keys.js +1 -1
- package/dist/esm/crypto/core/nonce.js +2 -0
- package/dist/esm/crypto/core/primitives.js +0 -7
- package/dist/esm/crypto/core/random.js +22 -1
- package/dist/esm/crypto/curves/X25519.js +25 -6
- package/dist/esm/crypto/index.js +1 -0
- package/dist/esm/crypto/math/constants.js +12 -35
- package/dist/esm/crypto/math/edwards.js +174 -47
- package/dist/esm/crypto/math/fe.js +691 -0
- package/dist/esm/crypto/math/mod.js +10 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/infra/perf/BackgroundQueue.js +478 -0
- package/dist/esm/infra/perf/BoundedTaskQueue.js +3 -1
- package/dist/esm/infra/perf/PromiseDedup.js +20 -0
- package/dist/esm/infra/perf/SharedExclusiveGate.js +109 -0
- package/dist/esm/infra/perf/StoreLock.js +77 -0
- package/dist/esm/media/WaMediaCrypto.js +95 -13
- package/dist/esm/media/WaMediaTransferClient.js +39 -47
- package/dist/esm/media/constants.js +2 -1
- package/dist/esm/message/WaMessageClient.js +26 -19
- package/dist/esm/message/content.js +195 -9
- package/dist/esm/message/icdc.js +76 -0
- package/dist/esm/message/incoming.js +24 -12
- package/dist/esm/message/phash.js +3 -1
- package/dist/esm/message/reporting-token.js +14 -27
- package/dist/esm/protocol/appstate.js +9 -40
- package/dist/esm/protocol/browser.js +10 -18
- package/dist/esm/protocol/constants.js +5 -3
- package/dist/esm/protocol/defaults.js +6 -0
- package/dist/esm/protocol/index.js +1 -2
- package/dist/esm/protocol/jid.js +105 -36
- package/dist/esm/protocol/message.js +61 -1
- package/dist/esm/protocol/nodes.js +2 -0
- package/dist/esm/protocol/notification.js +3 -1
- package/dist/esm/protocol/privacy-token.js +17 -0
- package/dist/esm/protocol/privacy.js +55 -0
- package/dist/esm/protocol/stream.js +26 -1
- package/dist/esm/retry/codec.js +216 -0
- package/dist/esm/retry/constants.js +1 -1
- package/dist/esm/retry/index.js +2 -2
- package/dist/esm/retry/parse.js +50 -30
- package/dist/esm/retry/replay.js +11 -7
- package/dist/esm/retry/tracker.js +50 -12
- package/dist/esm/signal/api/SignalDeviceSyncApi.js +49 -32
- package/dist/esm/signal/api/SignalDigestSyncApi.js +13 -9
- package/dist/esm/signal/api/SignalIdentitySyncApi.js +26 -11
- package/dist/esm/signal/api/SignalMissingPreKeysSyncApi.js +18 -7
- package/dist/esm/signal/api/SignalRotateKeyApi.js +4 -2
- package/dist/esm/signal/api/SignalSessionSyncApi.js +16 -7
- package/dist/esm/signal/api/result-map.js +10 -0
- package/dist/esm/signal/constants.js +0 -4
- package/dist/esm/signal/crypto/WaAdvSignature.js +12 -6
- package/dist/esm/signal/{store/sqlite.js → encoding.js} +78 -24
- package/dist/esm/signal/group/SenderKeyCodec.js +3 -2
- package/dist/esm/signal/group/SenderKeyManager.js +125 -106
- package/dist/esm/signal/index.js +1 -0
- package/dist/esm/signal/registration/keygen.js +6 -2
- package/dist/esm/signal/registration/utils.js +1 -0
- package/dist/esm/signal/session/SignalProtocol.js +150 -74
- package/dist/esm/signal/session/resolver.js +137 -102
- package/dist/esm/store/contracts/privacy-token.store.js +1 -0
- package/dist/esm/store/createStore.js +101 -187
- package/dist/esm/store/index.js +1 -10
- package/dist/esm/store/locks/appstate.lock.js +26 -0
- package/dist/esm/store/locks/auth.lock.js +15 -0
- package/dist/esm/store/locks/contact.lock.js +20 -0
- package/dist/esm/store/locks/device-list.lock.js +20 -0
- package/dist/esm/store/locks/message.lock.js +21 -0
- package/dist/esm/store/locks/participants.lock.js +20 -0
- package/dist/esm/store/locks/privacy-token.lock.js +18 -0
- package/dist/esm/store/locks/retry.lock.js +29 -0
- package/dist/esm/store/locks/sender-key.lock.js +52 -0
- package/dist/esm/store/locks/signal.lock.js +63 -0
- package/dist/esm/store/locks/thread.lock.js +21 -0
- package/dist/esm/store/noop.store.js +1 -1
- package/dist/esm/store/providers/memory/appstate.store.js +22 -24
- package/dist/esm/store/providers/memory/device-list.store.js +10 -5
- package/dist/esm/store/providers/memory/privacy-token.store.js +43 -0
- package/dist/esm/store/providers/memory/retry.store.js +77 -2
- package/dist/esm/store/providers/memory/sender-key.store.js +6 -1
- package/dist/esm/store/providers/memory/signal.store.js +36 -19
- package/dist/esm/transport/WaComms.js +3 -1
- package/dist/esm/transport/WaWebSocket.js +0 -6
- package/dist/esm/transport/binary/constants.js +0 -30
- package/dist/esm/transport/binary/decoder.js +4 -4
- package/dist/esm/transport/binary/encoder.js +8 -15
- package/dist/esm/transport/binary/index.js +0 -1
- package/dist/esm/transport/node/WaNodeOrchestrator.js +25 -19
- package/dist/esm/transport/node/builders/business.js +129 -0
- package/dist/esm/transport/node/builders/global.js +370 -0
- package/dist/esm/transport/node/builders/index.js +5 -2
- package/dist/esm/transport/node/builders/message.js +63 -239
- package/dist/esm/transport/node/builders/pairing.js +0 -24
- package/dist/esm/transport/node/builders/privacy-token.js +41 -0
- package/dist/esm/transport/node/builders/privacy.js +48 -0
- package/dist/esm/transport/node/builders/profile.js +70 -0
- package/dist/esm/transport/node/builders/retry.js +10 -22
- package/dist/esm/transport/node/builders/usync.js +6 -2
- package/dist/esm/transport/node/helpers.js +19 -1
- package/dist/esm/transport/node/usync.js +3 -33
- package/dist/esm/transport/node/xml.js +35 -14
- package/dist/esm/transport/noise/WaClientPayload.js +10 -10
- package/dist/esm/transport/noise/WaNoiseCert.js +3 -3
- package/dist/esm/transport/noise/WaNoiseSession.js +64 -23
- package/dist/esm/transport/noise/WaNoiseSocket.js +8 -4
- package/dist/esm/transport/stream/parse.js +8 -4
- package/dist/esm/util/bytes.js +22 -18
- package/dist/esm/util/index.js +5 -0
- package/dist/esm/util/primitives.js +3 -2
- package/dist/index.js +7 -1
- package/dist/infra/perf/BackgroundQueue.js +482 -0
- package/dist/infra/perf/BoundedTaskQueue.js +3 -1
- package/dist/infra/perf/PromiseDedup.js +24 -0
- package/dist/infra/perf/SharedExclusiveGate.js +113 -0
- package/dist/infra/perf/StoreLock.js +81 -0
- package/dist/media/WaMediaCrypto.js +94 -12
- package/dist/media/WaMediaTransferClient.js +39 -47
- package/dist/media/constants.js +2 -1
- package/dist/message/WaMessageClient.js +26 -19
- package/dist/message/content.js +198 -9
- package/dist/message/icdc.js +81 -0
- package/dist/message/incoming.js +24 -12
- package/dist/message/phash.js +3 -1
- package/dist/message/reporting-token.js +14 -28
- package/dist/protocol/appstate.js +10 -41
- package/dist/protocol/browser.js +10 -18
- package/dist/protocol/constants.js +21 -2
- package/dist/protocol/defaults.js +6 -0
- package/dist/protocol/index.js +8 -5
- package/dist/protocol/jid.js +111 -36
- package/dist/protocol/message.js +62 -2
- package/dist/protocol/nodes.js +2 -0
- package/dist/protocol/notification.js +3 -1
- package/dist/protocol/privacy-token.js +20 -0
- package/dist/protocol/privacy.js +58 -0
- package/dist/protocol/stream.js +27 -2
- package/dist/retry/codec.js +220 -0
- package/dist/retry/constants.js +1 -1
- package/dist/retry/index.js +5 -5
- package/dist/retry/parse.js +51 -30
- package/dist/retry/replay.js +10 -6
- package/dist/retry/tracker.js +50 -12
- package/dist/signal/api/SignalDeviceSyncApi.js +48 -31
- package/dist/signal/api/SignalDigestSyncApi.js +13 -9
- package/dist/signal/api/SignalIdentitySyncApi.js +25 -10
- package/dist/signal/api/SignalMissingPreKeysSyncApi.js +17 -6
- package/dist/signal/api/SignalRotateKeyApi.js +4 -2
- package/dist/signal/api/SignalSessionSyncApi.js +16 -7
- package/dist/signal/api/result-map.js +13 -0
- package/dist/signal/constants.js +1 -5
- package/dist/signal/crypto/WaAdvSignature.js +11 -5
- package/dist/signal/{store/sqlite.js → encoding.js} +79 -25
- package/dist/signal/group/SenderKeyCodec.js +4 -3
- package/dist/signal/group/SenderKeyManager.js +125 -106
- package/dist/signal/index.js +13 -1
- package/dist/signal/registration/keygen.js +6 -2
- package/dist/signal/registration/utils.js +1 -0
- package/dist/signal/session/SignalProtocol.js +150 -74
- package/dist/signal/session/resolver.js +135 -100
- package/dist/store/contracts/privacy-token.store.js +2 -0
- package/dist/store/createStore.js +101 -187
- package/dist/store/index.js +15 -33
- package/dist/store/locks/appstate.lock.js +29 -0
- package/dist/store/locks/auth.lock.js +18 -0
- package/dist/store/locks/contact.lock.js +23 -0
- package/dist/store/locks/device-list.lock.js +23 -0
- package/dist/store/locks/message.lock.js +24 -0
- package/dist/store/locks/participants.lock.js +23 -0
- package/dist/store/locks/privacy-token.lock.js +21 -0
- package/dist/store/locks/retry.lock.js +32 -0
- package/dist/store/locks/sender-key.lock.js +55 -0
- package/dist/store/locks/signal.lock.js +66 -0
- package/dist/store/locks/thread.lock.js +24 -0
- package/dist/store/noop.store.js +1 -1
- package/dist/store/providers/memory/appstate.store.js +22 -24
- package/dist/store/providers/memory/device-list.store.js +10 -5
- package/dist/store/providers/memory/privacy-token.store.js +47 -0
- package/dist/store/providers/memory/retry.store.js +77 -2
- package/dist/store/providers/memory/sender-key.store.js +6 -1
- package/dist/store/providers/memory/signal.store.js +36 -19
- package/dist/transport/WaComms.js +3 -1
- package/dist/transport/WaWebSocket.js +0 -6
- package/dist/transport/binary/constants.js +1 -31
- package/dist/transport/binary/decoder.js +4 -4
- package/dist/transport/binary/encoder.js +8 -15
- package/dist/transport/binary/index.js +0 -4
- package/dist/transport/node/WaNodeOrchestrator.js +24 -18
- package/dist/transport/node/builders/business.js +137 -0
- package/dist/transport/node/builders/global.js +375 -0
- package/dist/transport/node/builders/index.js +18 -9
- package/dist/transport/node/builders/message.js +64 -245
- package/dist/transport/node/builders/pairing.js +0 -26
- package/dist/transport/node/builders/privacy-token.js +46 -0
- package/dist/transport/node/builders/privacy.js +55 -0
- package/dist/transport/node/builders/profile.js +78 -0
- package/dist/transport/node/builders/retry.js +9 -21
- package/dist/transport/node/builders/usync.js +6 -2
- package/dist/transport/node/helpers.js +20 -1
- package/dist/transport/node/usync.js +2 -32
- package/dist/transport/node/xml.js +35 -14
- package/dist/transport/noise/WaClientPayload.js +13 -13
- package/dist/transport/noise/WaNoiseCert.js +2 -2
- package/dist/transport/noise/WaNoiseSession.js +64 -23
- package/dist/transport/noise/WaNoiseSocket.js +8 -4
- package/dist/transport/stream/parse.js +7 -3
- package/dist/types/appstate/encoding.d.ts +7 -0
- package/dist/types/appstate/index.d.ts +3 -3
- package/dist/types/appstate/utils.d.ts +0 -2
- package/dist/types/auth/flow/WaAuthCredentialsFlow.d.ts +1 -1
- package/dist/types/auth/index.d.ts +0 -2
- package/dist/types/auth/types.d.ts +1 -0
- package/dist/types/client/WaClient.d.ts +27 -12
- package/dist/types/client/WaClientFactory.d.ts +12 -4
- package/dist/types/client/connection/WaConnectionManager.d.ts +2 -0
- package/dist/types/client/coordinators/WaBusinessCoordinator.d.ts +57 -0
- package/dist/types/client/coordinators/WaIncomingNodeCoordinator.d.ts +3 -1
- package/dist/types/client/coordinators/WaMessageDispatchCoordinator.d.ts +14 -0
- package/dist/types/client/coordinators/WaPassiveTasksCoordinator.d.ts +4 -0
- package/dist/types/client/coordinators/WaPrivacyCoordinator.d.ts +26 -0
- package/dist/types/client/coordinators/WaProfileCoordinator.d.ts +36 -0
- package/dist/types/client/coordinators/WaRetryCoordinator.d.ts +6 -0
- package/dist/types/client/coordinators/WaStreamControlCoordinator.d.ts +3 -2
- package/dist/types/client/coordinators/WaTrustedContactTokenCoordinator.d.ts +45 -0
- package/dist/types/client/events/devices.d.ts +20 -0
- package/dist/types/client/events/identity.d.ts +9 -0
- package/dist/types/client/events/privacy-token.d.ts +7 -0
- package/dist/types/client/history-sync.d.ts +9 -6
- package/dist/types/client/incoming.d.ts +3 -1
- package/dist/types/client/index.d.ts +1 -1
- package/dist/types/client/mailbox.d.ts +3 -5
- package/dist/types/client/messages.d.ts +1 -2
- package/dist/types/client/persistence/WriteBehindPersistence.d.ts +34 -0
- package/dist/types/client/tokens/cs-token.d.ts +10 -0
- package/dist/types/client/tokens/tc-token.d.ts +5 -0
- package/dist/types/client/types.d.ts +51 -3
- package/dist/types/crypto/core/index.d.ts +2 -2
- package/dist/types/crypto/core/nonce.d.ts +2 -0
- package/dist/types/crypto/core/primitives.d.ts +0 -1
- package/dist/types/crypto/core/random.d.ts +1 -0
- package/dist/types/crypto/index.d.ts +1 -0
- package/dist/types/crypto/math/constants.d.ts +4 -2
- package/dist/types/crypto/math/fe.d.ts +30 -0
- package/dist/types/crypto/math/mod.d.ts +0 -2
- package/dist/types/crypto/math/types.d.ts +11 -4
- package/dist/types/index.d.ts +5 -3
- package/dist/types/infra/perf/BackgroundQueue.d.ts +58 -0
- package/dist/types/infra/perf/PromiseDedup.d.ts +4 -0
- package/dist/types/infra/perf/SharedExclusiveGate.d.ts +17 -0
- package/dist/types/infra/perf/StoreLock.d.ts +10 -0
- package/dist/types/media/WaMediaCrypto.d.ts +3 -2
- package/dist/types/media/WaMediaTransferClient.d.ts +3 -12
- package/dist/types/media/constants.d.ts +1 -1
- package/dist/types/media/index.d.ts +1 -1
- package/dist/types/media/types.d.ts +10 -2
- package/dist/types/message/content.d.ts +8 -0
- package/dist/types/message/icdc.d.ts +13 -0
- package/dist/types/message/reporting-token.d.ts +0 -1
- package/dist/types/message/types.d.ts +45 -6
- package/dist/types/protocol/appstate.d.ts +0 -11
- package/dist/types/protocol/constants.d.ts +7 -3
- package/dist/types/protocol/defaults.d.ts +6 -0
- package/dist/types/protocol/index.d.ts +1 -2
- package/dist/types/protocol/jid.d.ts +19 -2
- package/dist/types/protocol/message.d.ts +60 -0
- package/dist/types/protocol/nodes.d.ts +2 -0
- package/dist/types/protocol/notification.d.ts +2 -0
- package/dist/types/protocol/privacy-token.d.ts +17 -0
- package/dist/types/protocol/privacy.d.ts +75 -0
- package/dist/types/protocol/stream.d.ts +30 -0
- package/dist/types/retry/codec.d.ts +3 -0
- package/dist/types/retry/index.d.ts +3 -3
- package/dist/types/retry/parse.d.ts +5 -2
- package/dist/types/retry/tracker.d.ts +1 -0
- package/dist/types/retry/types.d.ts +6 -1
- package/dist/types/signal/api/SignalDeviceSyncApi.d.ts +2 -1
- package/dist/types/signal/api/SignalDigestSyncApi.d.ts +6 -0
- package/dist/types/signal/api/SignalIdentitySyncApi.d.ts +2 -0
- package/dist/types/signal/api/SignalRotateKeyApi.d.ts +4 -5
- package/dist/types/signal/api/SignalSessionSyncApi.d.ts +8 -6
- package/dist/types/signal/api/result-map.d.ts +1 -0
- package/dist/types/signal/constants.d.ts +0 -3
- package/dist/types/signal/{store/sqlite.d.ts → encoding.d.ts} +3 -3
- package/dist/types/signal/group/SenderKeyManager.d.ts +10 -5
- package/dist/types/signal/index.d.ts +2 -0
- package/dist/types/signal/session/SignalProtocol.d.ts +10 -4
- package/dist/types/signal/session/resolver.d.ts +7 -2
- package/dist/types/store/contracts/appstate.store.d.ts +1 -1
- package/dist/types/store/contracts/privacy-token.store.d.ts +16 -0
- package/dist/types/store/contracts/retry.store.d.ts +7 -0
- package/dist/types/store/contracts/signal.store.d.ts +7 -0
- package/dist/types/store/createStore.d.ts +1 -1
- package/dist/types/store/index.d.ts +5 -13
- package/dist/types/store/locks/appstate.lock.d.ts +3 -0
- package/dist/types/store/locks/auth.lock.d.ts +3 -0
- package/dist/types/store/locks/contact.lock.d.ts +3 -0
- package/dist/types/store/locks/device-list.lock.d.ts +2 -0
- package/dist/types/store/locks/message.lock.d.ts +3 -0
- package/dist/types/store/locks/participants.lock.d.ts +2 -0
- package/dist/types/store/locks/privacy-token.lock.d.ts +2 -0
- package/dist/types/store/locks/retry.lock.d.ts +2 -0
- package/dist/types/store/locks/sender-key.lock.d.ts +3 -0
- package/dist/types/store/locks/signal.lock.d.ts +3 -0
- package/dist/types/store/locks/thread.lock.d.ts +3 -0
- package/dist/types/store/providers/memory/appstate.store.d.ts +1 -1
- package/dist/types/store/providers/memory/privacy-token.store.d.ts +13 -0
- package/dist/types/store/providers/memory/retry.store.d.ts +8 -0
- package/dist/types/store/providers/memory/signal.store.d.ts +2 -1
- package/dist/types/store/types.d.ts +49 -61
- package/dist/types/transport/WaWebSocket.d.ts +0 -1
- package/dist/types/transport/binary/constants.d.ts +0 -30
- package/dist/types/transport/binary/index.d.ts +0 -1
- package/dist/types/transport/node/WaNodeOrchestrator.d.ts +3 -4
- package/dist/types/transport/node/builders/business.d.ts +29 -0
- package/dist/types/transport/node/builders/global.d.ts +102 -0
- package/dist/types/transport/node/builders/index.d.ts +5 -2
- package/dist/types/transport/node/builders/message.d.ts +8 -7
- package/dist/types/transport/node/builders/pairing.d.ts +0 -2
- package/dist/types/transport/node/builders/privacy-token.d.ts +9 -0
- package/dist/types/transport/node/builders/privacy.d.ts +7 -0
- package/dist/types/transport/node/builders/profile.d.ts +8 -0
- package/dist/types/transport/node/builders/retry.d.ts +0 -1
- package/dist/types/transport/node/helpers.d.ts +5 -0
- package/dist/types/transport/noise/WaNoiseSession.d.ts +3 -2
- package/dist/types/transport/noise/WaNoiseSocket.d.ts +4 -2
- package/dist/types/util/bytes.d.ts +1 -1
- package/dist/types/util/index.d.ts +5 -0
- package/dist/types/util/primitives.d.ts +0 -1
- package/dist/util/bytes.js +22 -18
- package/dist/util/index.js +23 -0
- package/dist/util/primitives.js +2 -2
- package/package.json +29 -7
- package/proto/index.js +1 -1
- package/dist/crypto/core/constants.js +0 -4
- package/dist/esm/crypto/core/constants.js +0 -1
- package/dist/esm/retry/outbound.js +0 -82
- package/dist/esm/store/providers/sqlite/BaseSqliteStore.js +0 -37
- package/dist/esm/store/providers/sqlite/appstate.store.js +0 -250
- package/dist/esm/store/providers/sqlite/auth.store.js +0 -176
- package/dist/esm/store/providers/sqlite/connection.js +0 -245
- package/dist/esm/store/providers/sqlite/contact.store.js +0 -74
- package/dist/esm/store/providers/sqlite/device-list.store.js +0 -127
- package/dist/esm/store/providers/sqlite/message.store.js +0 -132
- package/dist/esm/store/providers/sqlite/migrations.js +0 -347
- package/dist/esm/store/providers/sqlite/participants.store.js +0 -77
- package/dist/esm/store/providers/sqlite/retry.store.js +0 -141
- package/dist/esm/store/providers/sqlite/sender-key.store.js +0 -198
- package/dist/esm/store/providers/sqlite/signal.store.js +0 -435
- package/dist/esm/store/providers/sqlite/table-names.js +0 -107
- package/dist/esm/store/providers/sqlite/thread.store.js +0 -85
- package/dist/retry/outbound.js +0 -87
- package/dist/store/providers/sqlite/BaseSqliteStore.js +0 -41
- package/dist/store/providers/sqlite/appstate.store.js +0 -254
- package/dist/store/providers/sqlite/auth.store.js +0 -180
- package/dist/store/providers/sqlite/connection.js +0 -281
- package/dist/store/providers/sqlite/contact.store.js +0 -78
- package/dist/store/providers/sqlite/device-list.store.js +0 -131
- package/dist/store/providers/sqlite/message.store.js +0 -136
- package/dist/store/providers/sqlite/migrations.js +0 -350
- package/dist/store/providers/sqlite/participants.store.js +0 -81
- package/dist/store/providers/sqlite/retry.store.js +0 -145
- package/dist/store/providers/sqlite/sender-key.store.js +0 -202
- package/dist/store/providers/sqlite/signal.store.js +0 -439
- package/dist/store/providers/sqlite/table-names.js +0 -113
- package/dist/store/providers/sqlite/thread.store.js +0 -89
- package/dist/types/appstate/store/sqlite.d.ts +0 -7
- package/dist/types/crypto/core/constants.d.ts +0 -1
- package/dist/types/retry/outbound.d.ts +0 -4
- package/dist/types/store/providers/sqlite/BaseSqliteStore.d.ts +0 -12
- package/dist/types/store/providers/sqlite/appstate.store.d.ts +0 -17
- package/dist/types/store/providers/sqlite/auth.store.d.ts +0 -10
- package/dist/types/store/providers/sqlite/connection.d.ts +0 -10
- package/dist/types/store/providers/sqlite/contact.store.d.ts +0 -12
- package/dist/types/store/providers/sqlite/device-list.store.d.ts +0 -15
- package/dist/types/store/providers/sqlite/message.store.d.ts +0 -13
- package/dist/types/store/providers/sqlite/migrations.d.ts +0 -3
- package/dist/types/store/providers/sqlite/participants.store.d.ts +0 -12
- package/dist/types/store/providers/sqlite/retry.store.d.ts +0 -15
- package/dist/types/store/providers/sqlite/sender-key.store.d.ts +0 -24
- package/dist/types/store/providers/sqlite/signal.store.d.ts +0 -53
- package/dist/types/store/providers/sqlite/table-names.d.ts +0 -5
- package/dist/types/store/providers/sqlite/thread.store.d.ts +0 -13
|
@@ -1,35 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { formatNodeIdPrefixFromSeed } from './helpers.js';
|
|
1
|
+
import { createNodeIdGenerator } from './helpers.js';
|
|
3
2
|
export function createUsyncSidGenerator() {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
prefixPromise: null,
|
|
7
|
-
counter: 1
|
|
8
|
-
};
|
|
9
|
-
return async () => {
|
|
10
|
-
const prefix = await getUsyncPrefix(state);
|
|
11
|
-
const sid = `${prefix}${state.counter}`;
|
|
12
|
-
state.counter += 1;
|
|
13
|
-
return sid;
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
async function getUsyncPrefix(state) {
|
|
17
|
-
if (state.prefix) {
|
|
18
|
-
return state.prefix;
|
|
19
|
-
}
|
|
20
|
-
if (!state.prefixPromise) {
|
|
21
|
-
state.prefixPromise = buildUsyncPrefix()
|
|
22
|
-
.then((prefix) => {
|
|
23
|
-
state.prefix = prefix;
|
|
24
|
-
return prefix;
|
|
25
|
-
})
|
|
26
|
-
.finally(() => {
|
|
27
|
-
state.prefixPromise = null;
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
return state.prefixPromise;
|
|
31
|
-
}
|
|
32
|
-
async function buildUsyncPrefix() {
|
|
33
|
-
const seed = await randomBytesAsync(4);
|
|
34
|
-
return formatNodeIdPrefixFromSeed(seed);
|
|
3
|
+
const generatorPromise = createNodeIdGenerator();
|
|
4
|
+
return async () => (await generatorPromise).next();
|
|
35
5
|
}
|
|
@@ -1,23 +1,41 @@
|
|
|
1
1
|
import { bytesToBase64 } from '../../util/bytes.js';
|
|
2
2
|
const XML_INDENT = ' ';
|
|
3
3
|
function escapeXml(value) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
.
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
4
|
+
let out = '';
|
|
5
|
+
let last = 0;
|
|
6
|
+
for (let i = 0; i < value.length; i++) {
|
|
7
|
+
let esc;
|
|
8
|
+
switch (value.charCodeAt(i)) {
|
|
9
|
+
case 38:
|
|
10
|
+
esc = '&';
|
|
11
|
+
break;
|
|
12
|
+
case 60:
|
|
13
|
+
esc = '<';
|
|
14
|
+
break;
|
|
15
|
+
case 62:
|
|
16
|
+
esc = '>';
|
|
17
|
+
break;
|
|
18
|
+
case 34:
|
|
19
|
+
esc = '"';
|
|
20
|
+
break;
|
|
21
|
+
case 39:
|
|
22
|
+
esc = ''';
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
if (esc) {
|
|
26
|
+
out += value.slice(last, i) + esc;
|
|
27
|
+
last = i + 1;
|
|
28
|
+
}
|
|
15
29
|
}
|
|
16
|
-
return
|
|
30
|
+
return last === 0 ? value : out + value.slice(last);
|
|
17
31
|
}
|
|
18
32
|
function renderNode(node, depth) {
|
|
19
33
|
const indent = XML_INDENT.repeat(depth);
|
|
20
|
-
const
|
|
34
|
+
const keys = Object.keys(node.attrs);
|
|
35
|
+
let attrs = '';
|
|
36
|
+
for (let i = 0; i < keys.length; i++) {
|
|
37
|
+
attrs += ` ${keys[i]}='${escapeXml(node.attrs[keys[i]])}'`;
|
|
38
|
+
}
|
|
21
39
|
const content = node.content;
|
|
22
40
|
if (content === undefined) {
|
|
23
41
|
return `${indent}<${node.tag}${attrs}/>`;
|
|
@@ -31,7 +49,10 @@ function renderNode(node, depth) {
|
|
|
31
49
|
if (content.length === 0) {
|
|
32
50
|
return `${indent}<${node.tag}${attrs}/>`;
|
|
33
51
|
}
|
|
34
|
-
|
|
52
|
+
let children = renderNode(content[0], depth + 1);
|
|
53
|
+
for (let i = 1; i < content.length; i++) {
|
|
54
|
+
children += '\n' + renderNode(content[i], depth + 1);
|
|
55
|
+
}
|
|
35
56
|
return `${indent}<${node.tag}${attrs}>\n${children}\n${indent}</${node.tag}>`;
|
|
36
57
|
}
|
|
37
58
|
export function formatBinaryNodeAsXml(node) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
import { md5Bytes } from '../../crypto/core/primitives.js';
|
|
3
3
|
import { proto } from '../../proto.js';
|
|
4
|
-
import { KEY_TYPE_CURVE25519 } from '../../signal/constants.js';
|
|
5
4
|
import { DEFAULT_VERSION_BASE } from '../noise/constants.js';
|
|
6
5
|
import { intToBytes, toBytesView } from '../../util/bytes.js';
|
|
7
6
|
function parseVersion(versionBase) {
|
|
@@ -60,8 +59,8 @@ function resolveDevicePropsPlatformType(deviceBrowser) {
|
|
|
60
59
|
return proto.DeviceProps.PlatformType.UNKNOWN;
|
|
61
60
|
}
|
|
62
61
|
}
|
|
63
|
-
function defaultUserAgent(versionBase, deviceOsDisplayName) {
|
|
64
|
-
const { primary, secondary, tertiary } = parseVersion(versionBase);
|
|
62
|
+
function defaultUserAgent(versionBase, deviceOsDisplayName, version) {
|
|
63
|
+
const { primary, secondary, tertiary } = version ?? parseVersion(versionBase);
|
|
65
64
|
const locale = resolveLocale();
|
|
66
65
|
return {
|
|
67
66
|
platform: proto.ClientPayload.UserAgent.Platform.WEB,
|
|
@@ -82,8 +81,8 @@ function defaultUserAgent(versionBase, deviceOsDisplayName) {
|
|
|
82
81
|
localeCountryIso31661Alpha2: locale.lc
|
|
83
82
|
};
|
|
84
83
|
}
|
|
85
|
-
function defaultDeviceProps(versionBase, config) {
|
|
86
|
-
const { primary, secondary, tertiary } = parseVersion(versionBase);
|
|
84
|
+
function defaultDeviceProps(versionBase, config, version) {
|
|
85
|
+
const { primary, secondary, tertiary } = version ?? parseVersion(versionBase);
|
|
87
86
|
return proto.DeviceProps.encode({
|
|
88
87
|
os: config.deviceOsDisplayName ?? process.platform,
|
|
89
88
|
version: {
|
|
@@ -105,7 +104,7 @@ function defaultDeviceProps(versionBase, config) {
|
|
|
105
104
|
}
|
|
106
105
|
}).finish();
|
|
107
106
|
}
|
|
108
|
-
function buildCommonPayload(config) {
|
|
107
|
+
function buildCommonPayload(config, version) {
|
|
109
108
|
const versionBase = config.versionBase ?? DEFAULT_VERSION_BASE;
|
|
110
109
|
const pull = config.pull ?? true;
|
|
111
110
|
return {
|
|
@@ -113,7 +112,7 @@ function buildCommonPayload(config) {
|
|
|
113
112
|
pull,
|
|
114
113
|
connectType: proto.ClientPayload.ConnectType.WIFI_UNKNOWN,
|
|
115
114
|
connectReason: proto.ClientPayload.ConnectReason.USER_ACTIVATED,
|
|
116
|
-
userAgent: config.userAgent ?? defaultUserAgent(versionBase, config.deviceOsDisplayName),
|
|
115
|
+
userAgent: config.userAgent ?? defaultUserAgent(versionBase, config.deviceOsDisplayName, version),
|
|
117
116
|
webInfo: config.webInfo ??
|
|
118
117
|
{
|
|
119
118
|
webSubPlatform: defaultWebSubPlatform()
|
|
@@ -142,14 +141,15 @@ export function buildRegistrationPayload(config) {
|
|
|
142
141
|
throw new Error('registration payload requires a valid signedPreKeyId');
|
|
143
142
|
}
|
|
144
143
|
const versionBase = config.versionBase ?? DEFAULT_VERSION_BASE;
|
|
145
|
-
const
|
|
144
|
+
const version = parseVersion(versionBase);
|
|
145
|
+
const common = buildCommonPayload(config, version);
|
|
146
146
|
const devicePairingData = {
|
|
147
147
|
buildHash: config.buildHash ? toBytesView(config.buildHash) : md5Bytes(versionBase),
|
|
148
148
|
deviceProps: config.deviceProps
|
|
149
149
|
? toBytesView(config.deviceProps)
|
|
150
|
-
: defaultDeviceProps(versionBase, config),
|
|
150
|
+
: defaultDeviceProps(versionBase, config, version),
|
|
151
151
|
eRegid: intToBytes(4, registrationId),
|
|
152
|
-
eKeytype: intToBytes(1,
|
|
152
|
+
eKeytype: intToBytes(1, 5),
|
|
153
153
|
eIdent: toBytesView(config.registrationInfo.identityKeyPair.pubKey),
|
|
154
154
|
eSkeyId: intToBytes(3, signedPreKeyId),
|
|
155
155
|
eSkeyVal: toBytesView(config.signedPreKey.keyPair.pubKey),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ed25519, toSerializedPubKey } from '../../crypto/index.js';
|
|
2
2
|
import { montgomeryToEdwardsPublic } from '../../crypto/curves/X25519.js';
|
|
3
3
|
import { proto } from '../../proto.js';
|
|
4
4
|
import { ROOT_CA_PUBLIC_KEY_HEX, ROOT_CA_SERIAL } from '../noise/constants.js';
|
|
@@ -6,7 +6,7 @@ import { assertByteLength, decodeProtoBytes, hexToBytes, uint8Equal } from '../.
|
|
|
6
6
|
import { toSafeNumber } from '../../util/primitives.js';
|
|
7
7
|
async function verifySignalVariant(serializedPublicKey, message, signatureInput) {
|
|
8
8
|
const publicKey = toSerializedPubKey(serializedPublicKey);
|
|
9
|
-
if (
|
|
9
|
+
if (signatureInput.length !== 64) {
|
|
10
10
|
return false;
|
|
11
11
|
}
|
|
12
12
|
const signature = new Uint8Array(signatureInput);
|
|
@@ -17,7 +17,7 @@ async function verifySignalVariant(serializedPublicKey, message, signatureInput)
|
|
|
17
17
|
const signBit = lastByte & 0x80;
|
|
18
18
|
signature[63] = lastByte & 0x7f;
|
|
19
19
|
const edwardsPublicKey = montgomeryToEdwardsPublic(publicKey.subarray(1), signBit);
|
|
20
|
-
return
|
|
20
|
+
return Ed25519.verify(message, signature, edwardsPublicKey);
|
|
21
21
|
}
|
|
22
22
|
function parseNoiseCertificate(certificate) {
|
|
23
23
|
if (!certificate) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { X25519 } from '../../crypto/index.js';
|
|
2
2
|
import { ConsoleLogger } from '../../infra/log/ConsoleLogger.js';
|
|
3
|
-
import { BoundedTaskQueue } from '../../infra/perf/BoundedTaskQueue.js';
|
|
4
3
|
import { proto } from '../../proto.js';
|
|
5
4
|
import { WA_DEFAULTS } from '../../protocol/constants.js';
|
|
6
5
|
import { NOISE_IK_NAME, NOISE_XX_FALLBACK_NAME, NOISE_XX_NAME, WA_PROTO_HEADER } from '../noise/constants.js';
|
|
@@ -48,6 +47,8 @@ function buildRoutingInfoPrefix(routingInfo) {
|
|
|
48
47
|
}
|
|
49
48
|
export class WaNoiseSession {
|
|
50
49
|
constructor(sendWire, logger = new ConsoleLogger('info')) {
|
|
50
|
+
this.writeChain = Promise.resolve();
|
|
51
|
+
this.readChain = Promise.resolve();
|
|
51
52
|
this.frameCodec = null;
|
|
52
53
|
this.handshakeInbox = [];
|
|
53
54
|
this.handshakeInboxHead = 0;
|
|
@@ -60,8 +61,6 @@ export class WaNoiseSession {
|
|
|
60
61
|
this.handshakeFrameTimeoutMs = WA_DEFAULTS.CONNECT_TIMEOUT_MS;
|
|
61
62
|
this.sendWire = sendWire;
|
|
62
63
|
this.logger = logger;
|
|
63
|
-
this.writeQueue = new BoundedTaskQueue(4096, 1);
|
|
64
|
-
this.readQueue = new BoundedTaskQueue(4096, 1);
|
|
65
64
|
}
|
|
66
65
|
async start(config) {
|
|
67
66
|
this.reset();
|
|
@@ -93,12 +92,24 @@ export class WaNoiseSession {
|
|
|
93
92
|
await this.decodeBufferedPostHandshakeFrames();
|
|
94
93
|
this.logger.info('noise session established via full handshake');
|
|
95
94
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
encryptFrame(frame) {
|
|
96
|
+
const socket = this.noiseSocket;
|
|
97
|
+
const codec = this.frameCodec;
|
|
98
|
+
if (!socket || !codec) {
|
|
99
|
+
return Promise.reject(new Error('noise session is not established'));
|
|
100
|
+
}
|
|
101
|
+
let encryptPromise;
|
|
102
|
+
try {
|
|
103
|
+
encryptPromise = socket.encrypt(socket.reserveWriteNonce(), frame);
|
|
99
104
|
}
|
|
100
|
-
|
|
101
|
-
|
|
105
|
+
catch (error) {
|
|
106
|
+
return Promise.reject(error);
|
|
107
|
+
}
|
|
108
|
+
const result = this.writeChain
|
|
109
|
+
.then(() => encryptPromise)
|
|
110
|
+
.then((encrypted) => codec.encodeFrame(encrypted));
|
|
111
|
+
this.writeChain = result.then(() => { }, () => { });
|
|
112
|
+
return result;
|
|
102
113
|
}
|
|
103
114
|
async pushWireChunk(chunk) {
|
|
104
115
|
const codec = this.frameCodec;
|
|
@@ -107,7 +118,9 @@ export class WaNoiseSession {
|
|
|
107
118
|
}
|
|
108
119
|
const out = [];
|
|
109
120
|
if (this.pendingDecryptedFrames.length > 0) {
|
|
110
|
-
|
|
121
|
+
for (let i = 0; i < this.pendingDecryptedFrames.length; i += 1) {
|
|
122
|
+
out.push(this.pendingDecryptedFrames[i]);
|
|
123
|
+
}
|
|
111
124
|
this.pendingDecryptedFrames = [];
|
|
112
125
|
}
|
|
113
126
|
const frames = codec.pushWireChunk(chunk);
|
|
@@ -125,9 +138,15 @@ export class WaNoiseSession {
|
|
|
125
138
|
}
|
|
126
139
|
return out;
|
|
127
140
|
}
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
|
|
141
|
+
if (frames.length > 0) {
|
|
142
|
+
const decryptBatch = this.decryptFramesBatch(this.noiseSocket, frames);
|
|
143
|
+
this.readChain = this.readChain
|
|
144
|
+
.then(() => decryptBatch)
|
|
145
|
+
.then(() => { }, () => { });
|
|
146
|
+
const decrypted = await decryptBatch;
|
|
147
|
+
for (let i = 0; i < decrypted.length; i++) {
|
|
148
|
+
out.push(decrypted[i]);
|
|
149
|
+
}
|
|
131
150
|
}
|
|
132
151
|
return out;
|
|
133
152
|
}
|
|
@@ -142,6 +161,16 @@ export class WaNoiseSession {
|
|
|
142
161
|
rejecter(closeError);
|
|
143
162
|
}
|
|
144
163
|
}
|
|
164
|
+
async decryptFramesBatch(socket, frames) {
|
|
165
|
+
if (frames.length === 1) {
|
|
166
|
+
return [await socket.decrypt(socket.reserveReadNonce(), frames[0])];
|
|
167
|
+
}
|
|
168
|
+
const pending = new Array(frames.length);
|
|
169
|
+
for (let i = 0; i < frames.length; i++) {
|
|
170
|
+
pending[i] = socket.decrypt(socket.reserveReadNonce(), frames[i]);
|
|
171
|
+
}
|
|
172
|
+
return Promise.all(pending);
|
|
173
|
+
}
|
|
145
174
|
reset() {
|
|
146
175
|
this.logger.trace('noise session reset');
|
|
147
176
|
this.frameCodec = null;
|
|
@@ -152,11 +181,10 @@ export class WaNoiseSession {
|
|
|
152
181
|
this.closedError = null;
|
|
153
182
|
this.noiseSocket = null;
|
|
154
183
|
this.serverStaticKey = null;
|
|
184
|
+
this.writeChain = Promise.resolve();
|
|
185
|
+
this.readChain = Promise.resolve();
|
|
155
186
|
}
|
|
156
187
|
getServerStaticKey() {
|
|
157
|
-
if (!this.serverStaticKey) {
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
160
188
|
return this.serverStaticKey;
|
|
161
189
|
}
|
|
162
190
|
async fullHandshake(clientStaticKeyPair, ephemeralKeyPair, payload, protocolHeader, verifyCertificates) {
|
|
@@ -186,10 +214,12 @@ export class WaNoiseSession {
|
|
|
186
214
|
await handshake.start(NOISE_IK_NAME, protocolHeader);
|
|
187
215
|
await handshake.authenticate(serverStaticKey);
|
|
188
216
|
await handshake.authenticate(ephemeralKeyPair.pubKey);
|
|
189
|
-
const agreement1 = await
|
|
217
|
+
const [agreement1, agreement2] = await Promise.all([
|
|
218
|
+
X25519.scalarMult(ephemeralKeyPair.privKey, serverStaticKey),
|
|
219
|
+
X25519.scalarMult(clientStaticKeyPair.privKey, serverStaticKey)
|
|
220
|
+
]);
|
|
190
221
|
await handshake.mixIntoKey(agreement1);
|
|
191
222
|
const encryptedClientStatic = await handshake.encrypt(clientStaticKeyPair.pubKey);
|
|
192
|
-
const agreement2 = await X25519.scalarMult(clientStaticKeyPair.privKey, serverStaticKey);
|
|
193
223
|
await handshake.mixIntoKey(agreement2);
|
|
194
224
|
const encryptedPayload = await handshake.encrypt(payload);
|
|
195
225
|
const clientHello = proto.HandshakeMessage.encode({
|
|
@@ -216,8 +246,12 @@ export class WaNoiseSession {
|
|
|
216
246
|
}
|
|
217
247
|
const serverEphemeral = toBytesView(serverHello.ephemeral);
|
|
218
248
|
await handshake.authenticate(serverEphemeral);
|
|
219
|
-
|
|
220
|
-
|
|
249
|
+
const [dh1, dh2] = await Promise.all([
|
|
250
|
+
X25519.scalarMult(ephemeralKeyPair.privKey, serverEphemeral),
|
|
251
|
+
X25519.scalarMult(clientStaticKeyPair.privKey, serverEphemeral)
|
|
252
|
+
]);
|
|
253
|
+
await handshake.mixIntoKey(dh1);
|
|
254
|
+
await handshake.mixIntoKey(dh2);
|
|
221
255
|
await handshake.decrypt(toBytesView(serverHello.payload));
|
|
222
256
|
this.serverStaticKey = serverStaticKey;
|
|
223
257
|
this.logger.info('noise resume handshake successful without fallback');
|
|
@@ -319,10 +353,17 @@ export class WaNoiseSession {
|
|
|
319
353
|
this.logger.debug('decoding buffered post-handshake frames', {
|
|
320
354
|
count: this.handshakeInbox.length - this.handshakeInboxHead
|
|
321
355
|
});
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
this.
|
|
356
|
+
const start = this.handshakeInboxHead;
|
|
357
|
+
const frames = this.handshakeInbox.slice(start);
|
|
358
|
+
if (frames.length > 0) {
|
|
359
|
+
const decryptBatch = this.decryptFramesBatch(this.noiseSocket, frames);
|
|
360
|
+
this.readChain = this.readChain
|
|
361
|
+
.then(() => decryptBatch)
|
|
362
|
+
.then(() => { }, () => { });
|
|
363
|
+
const decrypted = await decryptBatch;
|
|
364
|
+
for (let i = 0; i < decrypted.length; i++) {
|
|
365
|
+
this.pendingDecryptedFrames.push(decrypted[i]);
|
|
366
|
+
}
|
|
326
367
|
}
|
|
327
368
|
this.handshakeInbox.length = this.handshakeInboxHead = 0;
|
|
328
369
|
}
|
|
@@ -6,12 +6,16 @@ export class WaNoiseSocket {
|
|
|
6
6
|
this.writeCounter = 0;
|
|
7
7
|
this.readCounter = 0;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
reserveWriteNonce() {
|
|
10
|
+
return buildNonce(this.writeCounter++);
|
|
11
|
+
}
|
|
12
|
+
encrypt(nonce, frame, additionalData) {
|
|
11
13
|
return aesGcmEncrypt(this.encryptKey, nonce, frame, additionalData);
|
|
12
14
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
reserveReadNonce() {
|
|
16
|
+
return buildNonce(this.readCounter++);
|
|
17
|
+
}
|
|
18
|
+
decrypt(nonce, frame, additionalData) {
|
|
15
19
|
return aesGcmDecrypt(this.decryptKey, nonce, frame, additionalData);
|
|
16
20
|
}
|
|
17
21
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { WA_STREAM_SIGNALING } from '../../protocol/constants.js';
|
|
2
2
|
import { findNodeChild, hasNodeChild } from '../node/helpers.js';
|
|
3
3
|
import { base64ToBytesChecked } from '../../util/bytes.js';
|
|
4
|
-
import { parseOptionalInt
|
|
4
|
+
import { parseOptionalInt } from '../../util/primitives.js';
|
|
5
|
+
const DIGITS_ONLY_RE = /^\d+$/;
|
|
5
6
|
export function parseStreamControlNode(node) {
|
|
6
7
|
if (node.tag === WA_STREAM_SIGNALING.XML_STREAM_END_TAG) {
|
|
7
8
|
return { kind: 'xmlstreamend' };
|
|
@@ -15,9 +16,12 @@ export function parseStreamControlNode(node) {
|
|
|
15
16
|
? { kind: 'stream_error_replaced' }
|
|
16
17
|
: { kind: 'stream_error_device_removed' };
|
|
17
18
|
}
|
|
18
|
-
const
|
|
19
|
-
if (
|
|
20
|
-
|
|
19
|
+
const codeStr = node.attrs.code;
|
|
20
|
+
if (codeStr && DIGITS_ONLY_RE.test(codeStr)) {
|
|
21
|
+
const code = Number(codeStr);
|
|
22
|
+
if (Number.isSafeInteger(code)) {
|
|
23
|
+
return { kind: 'stream_error_code', code };
|
|
24
|
+
}
|
|
21
25
|
}
|
|
22
26
|
const ackNode = findNodeChild(node, WA_STREAM_SIGNALING.ACK_TAG);
|
|
23
27
|
if (ackNode) {
|
package/dist/esm/util/bytes.js
CHANGED
|
@@ -120,14 +120,10 @@ export function decodeBase64Url(value, field) {
|
|
|
120
120
|
.padEnd(Math.ceil(value.length / 4) * 4, '=');
|
|
121
121
|
return base64ToBytesChecked(padded, field);
|
|
122
122
|
}
|
|
123
|
-
export function assertByteLength(value, expectedLength, errorMessage
|
|
123
|
+
export function assertByteLength(value, expectedLength, errorMessage) {
|
|
124
124
|
if (value.length !== expectedLength) {
|
|
125
|
-
if (!throwOnMismatch) {
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
125
|
throw new Error(errorMessage);
|
|
129
126
|
}
|
|
130
|
-
return true;
|
|
131
127
|
}
|
|
132
128
|
export function decodeProtoBytes(value, field) {
|
|
133
129
|
if (value === null || value === undefined) {
|
|
@@ -194,12 +190,15 @@ function encodeBase64(value, alphabet, pad) {
|
|
|
194
190
|
return out.join('');
|
|
195
191
|
}
|
|
196
192
|
export function concatBytes(parts) {
|
|
197
|
-
|
|
193
|
+
let total = 0;
|
|
194
|
+
for (let i = 0; i < parts.length; i += 1) {
|
|
195
|
+
total += parts[i].length;
|
|
196
|
+
}
|
|
198
197
|
const out = new Uint8Array(total);
|
|
199
198
|
let offset = 0;
|
|
200
|
-
for (
|
|
201
|
-
out.set(
|
|
202
|
-
offset +=
|
|
199
|
+
for (let i = 0; i < parts.length; i += 1) {
|
|
200
|
+
out.set(parts[i], offset);
|
|
201
|
+
offset += parts[i].length;
|
|
203
202
|
}
|
|
204
203
|
return out;
|
|
205
204
|
}
|
|
@@ -240,10 +239,21 @@ export function uint8Equal(a, b) {
|
|
|
240
239
|
return diff === 0;
|
|
241
240
|
}
|
|
242
241
|
export function removeAt(items, index) {
|
|
243
|
-
|
|
242
|
+
if (items.length === 0) {
|
|
243
|
+
return [];
|
|
244
|
+
}
|
|
245
|
+
if (index < 0 || index >= items.length) {
|
|
246
|
+
const out = new Array(items.length);
|
|
247
|
+
for (let i = 0; i < items.length; i += 1) {
|
|
248
|
+
out[i] = items[i];
|
|
249
|
+
}
|
|
250
|
+
return out;
|
|
251
|
+
}
|
|
252
|
+
const out = new Array(items.length - 1);
|
|
253
|
+
let k = 0;
|
|
244
254
|
for (let i = 0; i < items.length; i += 1) {
|
|
245
255
|
if (i !== index) {
|
|
246
|
-
out
|
|
256
|
+
out[k++] = items[i];
|
|
247
257
|
}
|
|
248
258
|
}
|
|
249
259
|
return out;
|
|
@@ -283,11 +293,5 @@ export async function readAllBytes(stream, options = {}) {
|
|
|
283
293
|
if (chunks.length === 1) {
|
|
284
294
|
return chunks[0];
|
|
285
295
|
}
|
|
286
|
-
|
|
287
|
-
let offset = 0;
|
|
288
|
-
for (const chunk of chunks) {
|
|
289
|
-
merged.set(chunk, offset);
|
|
290
|
-
offset += chunk.byteLength;
|
|
291
|
-
}
|
|
292
|
-
return merged;
|
|
296
|
+
return concatBytes(chunks);
|
|
293
297
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { bytesToHex, hexToBytes, toBytesView, uint8Equal } from './bytes.js';
|
|
2
|
+
export { asBytes, asNumber, asOptionalBytes, asOptionalNumber, asOptionalString, asString, resolvePositive, toBoolOrUndef } from './coercion.js';
|
|
3
|
+
export { normalizeQueryLimit } from './collections.js';
|
|
4
|
+
export { toSafeNumber } from './primitives.js';
|
|
5
|
+
export { isBunRuntime } from './runtime.js';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const DIGITS_ONLY_RE = /^\d+$/;
|
|
1
2
|
export function toError(value) {
|
|
2
3
|
if (value instanceof Error)
|
|
3
4
|
return value;
|
|
@@ -42,8 +43,8 @@ export function normalizeNonNegativeInteger(value, fallback) {
|
|
|
42
43
|
return fallback;
|
|
43
44
|
return Math.max(0, Math.trunc(value));
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
-
if (
|
|
46
|
+
function parseStrictUnsignedInt(value) {
|
|
47
|
+
if (!DIGITS_ONLY_RE.test(value))
|
|
47
48
|
return undefined;
|
|
48
49
|
const parsed = Number(value);
|
|
49
50
|
if (!Number.isSafeInteger(parsed))
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.proto = exports.WA_XMLNS = exports.WA_SUPPORTED_DIRTY_TYPES = exports.WA_STREAM_SIGNALING = exports.WA_SIGNALING = exports.WA_RETRYABLE_ACK_CODES = exports.WA_READY_STATES = exports.WA_PREVIEW_MEDIA_HKDF_INFO = exports.WA_PAIRING_KDF_INFO = exports.WA_NODE_TAGS = exports.WA_MEDIA_HKDF_INFO = exports.WA_MESSAGE_TYPES = exports.WA_MESSAGE_TAGS = exports.WA_LOGOUT_REASONS = exports.WA_IQ_TYPES = exports.WA_DISCONNECT_REASONS = exports.WA_DIRTY_TYPES = exports.WA_DIRTY_PROTOCOLS = exports.WA_DEFAULTS = exports.WA_COMPANION_PLATFORM_IDS = exports.WA_BROWSERS = exports.WA_APP_STATE_SYNC_DATA_TYPE = exports.WA_APP_STATE_KEY_TYPES = exports.WA_APP_STATE_KDF_INFO = exports.WA_APP_STATE_ERROR_CODES = exports.WA_APP_STATE_COLLECTION_STATES = exports.WA_APP_STATE_COLLECTIONS = exports.WA_ACCOUNT_SYNC_PROTOCOLS = exports.toUserJid = exports.splitJid = exports.parseSignalAddressFromJid = exports.parsePhoneJid = exports.normalizeRecipientJid = exports.normalizeDeviceJid = exports.isGroupJid = exports.getWaMediaHkdfInfo = exports.getWaCompanionPlatformId = exports.getLoginIdentity = exports.createStore = exports.createPinoLogger = exports.PinoLogger = exports.ConsoleLogger = exports.WaClient = void 0;
|
|
3
|
+
exports.proto = exports.WA_XMLNS = exports.WA_PRIVACY_VALUES = exports.WA_PRIVACY_TAGS = exports.WA_PRIVACY_SETTING_TO_CATEGORY = exports.WA_PRIVACY_DISALLOWED_LIST_CATEGORIES = exports.WA_PRIVACY_CATEGORY_TO_SETTING = exports.WA_PRIVACY_CATEGORIES = exports.WA_SUPPORTED_DIRTY_TYPES = exports.WA_STREAM_SIGNALING = exports.WA_SIGNALING = exports.WA_RETRYABLE_ACK_CODES = exports.WA_READY_STATES = exports.WA_PREVIEW_MEDIA_HKDF_INFO = exports.WA_PAIRING_KDF_INFO = exports.WA_NODE_TAGS = exports.WA_MEDIA_HKDF_INFO = exports.WA_MESSAGE_TYPES = exports.WA_MESSAGE_TAGS = exports.WA_LOGOUT_REASONS = exports.WA_IQ_TYPES = exports.WA_DISCONNECT_REASONS = exports.WA_DIRTY_TYPES = exports.WA_DIRTY_PROTOCOLS = exports.WA_DEFAULTS = exports.WA_COMPANION_PLATFORM_IDS = exports.WA_BROWSERS = exports.WA_APP_STATE_SYNC_DATA_TYPE = exports.WA_APP_STATE_KEY_TYPES = exports.WA_APP_STATE_KDF_INFO = exports.WA_APP_STATE_ERROR_CODES = exports.WA_APP_STATE_COLLECTION_STATES = exports.WA_APP_STATE_COLLECTIONS = exports.WA_ACCOUNT_SYNC_PROTOCOLS = exports.toUserJid = exports.splitJid = exports.parseSignalAddressFromJid = exports.parsePhoneJid = exports.normalizeRecipientJid = exports.normalizeDeviceJid = exports.isGroupJid = exports.getWaMediaHkdfInfo = exports.getWaCompanionPlatformId = exports.getLoginIdentity = exports.createStore = exports.createPinoLogger = exports.PinoLogger = exports.ConsoleLogger = exports.WaClient = void 0;
|
|
4
4
|
var _client_1 = require("./client/index.js");
|
|
5
5
|
Object.defineProperty(exports, "WaClient", { enumerable: true, get: function () { return _client_1.WaClient; } });
|
|
6
6
|
var ConsoleLogger_1 = require("./infra/log/ConsoleLogger");
|
|
@@ -47,6 +47,12 @@ Object.defineProperty(exports, "WA_RETRYABLE_ACK_CODES", { enumerable: true, get
|
|
|
47
47
|
Object.defineProperty(exports, "WA_SIGNALING", { enumerable: true, get: function () { return _protocol_1.WA_SIGNALING; } });
|
|
48
48
|
Object.defineProperty(exports, "WA_STREAM_SIGNALING", { enumerable: true, get: function () { return _protocol_1.WA_STREAM_SIGNALING; } });
|
|
49
49
|
Object.defineProperty(exports, "WA_SUPPORTED_DIRTY_TYPES", { enumerable: true, get: function () { return _protocol_1.WA_SUPPORTED_DIRTY_TYPES; } });
|
|
50
|
+
Object.defineProperty(exports, "WA_PRIVACY_CATEGORIES", { enumerable: true, get: function () { return _protocol_1.WA_PRIVACY_CATEGORIES; } });
|
|
51
|
+
Object.defineProperty(exports, "WA_PRIVACY_CATEGORY_TO_SETTING", { enumerable: true, get: function () { return _protocol_1.WA_PRIVACY_CATEGORY_TO_SETTING; } });
|
|
52
|
+
Object.defineProperty(exports, "WA_PRIVACY_DISALLOWED_LIST_CATEGORIES", { enumerable: true, get: function () { return _protocol_1.WA_PRIVACY_DISALLOWED_LIST_CATEGORIES; } });
|
|
53
|
+
Object.defineProperty(exports, "WA_PRIVACY_SETTING_TO_CATEGORY", { enumerable: true, get: function () { return _protocol_1.WA_PRIVACY_SETTING_TO_CATEGORY; } });
|
|
54
|
+
Object.defineProperty(exports, "WA_PRIVACY_TAGS", { enumerable: true, get: function () { return _protocol_1.WA_PRIVACY_TAGS; } });
|
|
55
|
+
Object.defineProperty(exports, "WA_PRIVACY_VALUES", { enumerable: true, get: function () { return _protocol_1.WA_PRIVACY_VALUES; } });
|
|
50
56
|
Object.defineProperty(exports, "WA_XMLNS", { enumerable: true, get: function () { return _protocol_1.WA_XMLNS; } });
|
|
51
57
|
var _proto_1 = require("./proto.js");
|
|
52
58
|
Object.defineProperty(exports, "proto", { enumerable: true, get: function () { return _proto_1.proto; } });
|