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,24 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createDeviceFanoutResolver = createDeviceFanoutResolver;
|
|
4
|
+
const PromiseDedup_1 = require("../../infra/perf/PromiseDedup");
|
|
4
5
|
const jid_1 = require("../../protocol/jid");
|
|
5
6
|
const primitives_1 = require("../../util/primitives");
|
|
6
7
|
function createDeviceFanoutResolver(options) {
|
|
7
8
|
const { signalDeviceSync, getCurrentMeJid, getCurrentMeLid, logger } = options;
|
|
8
|
-
const
|
|
9
|
-
const meJid = getCurrentMeJid();
|
|
10
|
-
if (meJid) {
|
|
11
|
-
return meJid;
|
|
12
|
-
}
|
|
13
|
-
throw new Error(`${context} requires registered meJid`);
|
|
14
|
-
};
|
|
9
|
+
const dedup = new PromiseDedup_1.PromiseDedup();
|
|
15
10
|
const resolveDirectFanoutDeviceJids = async (recipientJid, selfDeviceJidForRecipient) => {
|
|
16
11
|
const recipientUserJid = (0, jid_1.toUserJid)(recipientJid);
|
|
17
12
|
const meUserJid = (0, jid_1.toUserJid)(selfDeviceJidForRecipient);
|
|
18
13
|
const targets = recipientUserJid === meUserJid ? [recipientUserJid] : [recipientUserJid, meUserJid];
|
|
19
14
|
try {
|
|
20
15
|
const synced = await signalDeviceSync.syncDeviceList(targets);
|
|
21
|
-
const byUser = new Map(
|
|
16
|
+
const byUser = new Map();
|
|
17
|
+
for (let index = 0; index < synced.length; index += 1) {
|
|
18
|
+
const entry = synced[index];
|
|
19
|
+
byUser.set((0, jid_1.toUserJid)(entry.jid), entry.deviceJids);
|
|
20
|
+
}
|
|
22
21
|
const fanout = new Set();
|
|
23
22
|
const recipientDevices = byUser.get(recipientUserJid) ?? [];
|
|
24
23
|
if (recipientDevices.length === 0) {
|
|
@@ -48,7 +47,7 @@ function createDeviceFanoutResolver(options) {
|
|
|
48
47
|
return [recipientUserJid];
|
|
49
48
|
}
|
|
50
49
|
};
|
|
51
|
-
const
|
|
50
|
+
const resolveGroupParticipantDeviceJidsInternal = async (participantUserJids) => {
|
|
52
51
|
const meDeviceJids = new Set();
|
|
53
52
|
const meJid = getCurrentMeJid();
|
|
54
53
|
if (meJid) {
|
|
@@ -74,7 +73,11 @@ function createDeviceFanoutResolver(options) {
|
|
|
74
73
|
});
|
|
75
74
|
}
|
|
76
75
|
}
|
|
77
|
-
const
|
|
76
|
+
const candidateUserSet = new Set();
|
|
77
|
+
for (let index = 0; index < participantUserJids.length; index += 1) {
|
|
78
|
+
candidateUserSet.add(participantUserJids[index]);
|
|
79
|
+
}
|
|
80
|
+
const candidateUsers = Array.from(candidateUserSet);
|
|
78
81
|
if (candidateUsers.length === 0) {
|
|
79
82
|
return [];
|
|
80
83
|
}
|
|
@@ -92,6 +95,9 @@ function createDeviceFanoutResolver(options) {
|
|
|
92
95
|
}
|
|
93
96
|
for (const deviceJid of entry.deviceJids) {
|
|
94
97
|
const normalizedDeviceJid = (0, jid_1.normalizeDeviceJid)(deviceJid);
|
|
98
|
+
if ((0, jid_1.isHostedDeviceJid)(normalizedDeviceJid)) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
95
101
|
if (meDeviceJids.has(normalizedDeviceJid)) {
|
|
96
102
|
continue;
|
|
97
103
|
}
|
|
@@ -125,7 +131,10 @@ function createDeviceFanoutResolver(options) {
|
|
|
125
131
|
}
|
|
126
132
|
};
|
|
127
133
|
const resolveOwnPeerDeviceJids = async () => {
|
|
128
|
-
const meJid =
|
|
134
|
+
const meJid = getCurrentMeJid();
|
|
135
|
+
if (!meJid) {
|
|
136
|
+
throw new Error('resolveOwnPeerDeviceJids requires registered meJid');
|
|
137
|
+
}
|
|
129
138
|
const meUserJid = (0, jid_1.toUserJid)(meJid);
|
|
130
139
|
const meDevices = new Set();
|
|
131
140
|
meDevices.add((0, jid_1.normalizeDeviceJid)(meJid));
|
|
@@ -180,6 +189,7 @@ function createDeviceFanoutResolver(options) {
|
|
|
180
189
|
}
|
|
181
190
|
return meLid;
|
|
182
191
|
};
|
|
192
|
+
const resolveGroupParticipantDeviceJids = (participantUserJids) => dedup.run(`group:${participantUserJids.join(',')}`, () => resolveGroupParticipantDeviceJidsInternal(participantUserJids));
|
|
183
193
|
return {
|
|
184
194
|
resolveDirectFanoutDeviceJids,
|
|
185
195
|
resolveGroupParticipantDeviceJids,
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createGroupParticipantsCache = createGroupParticipantsCache;
|
|
4
|
+
const PromiseDedup_1 = require("../../infra/perf/PromiseDedup");
|
|
4
5
|
const jid_1 = require("../../protocol/jid");
|
|
5
6
|
const primitives_1 = require("../../util/primitives");
|
|
6
7
|
function createGroupParticipantsCache(options) {
|
|
7
8
|
const { participantsStore, queryGroupParticipantJids, logger } = options;
|
|
9
|
+
const dedup = new PromiseDedup_1.PromiseDedup();
|
|
8
10
|
const sanitizeParticipantUsers = (participants) => {
|
|
9
11
|
const deduped = new Set();
|
|
10
12
|
for (const participant of participants) {
|
|
@@ -120,7 +122,7 @@ function createGroupParticipantsCache(options) {
|
|
|
120
122
|
}
|
|
121
123
|
return sanitizeParticipantUsers(candidates);
|
|
122
124
|
};
|
|
123
|
-
const refreshParticipantUsers = async (
|
|
125
|
+
const refreshParticipantUsers = (groupJid) => dedup.run(`refresh:${groupJid}`, async () => {
|
|
124
126
|
const queried = await queryGroupParticipantJids(groupJid);
|
|
125
127
|
const participants = sanitizeParticipantUsers(queried);
|
|
126
128
|
await participantsStore.upsertGroupParticipants({
|
|
@@ -129,14 +131,14 @@ function createGroupParticipantsCache(options) {
|
|
|
129
131
|
updatedAtMs: Date.now()
|
|
130
132
|
});
|
|
131
133
|
return participants;
|
|
132
|
-
};
|
|
133
|
-
const resolveParticipantUsers = async (
|
|
134
|
+
});
|
|
135
|
+
const resolveParticipantUsers = (groupJid) => dedup.run(`resolve:${groupJid}`, async () => {
|
|
134
136
|
const cached = await participantsStore.getGroupParticipants(groupJid);
|
|
135
137
|
if (cached && cached.participants.length > 0) {
|
|
136
138
|
return sanitizeParticipantUsers(cached.participants);
|
|
137
139
|
}
|
|
138
140
|
return refreshParticipantUsers(groupJid);
|
|
139
|
-
};
|
|
141
|
+
});
|
|
140
142
|
const mutateFromGroupEvent = async (event) => {
|
|
141
143
|
const groupJid = resolveGroupJidForParticipantCacheEvent(event);
|
|
142
144
|
if (!groupJid) {
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WriteBehindPersistence = void 0;
|
|
4
|
+
const BackgroundQueue_1 = require("../../infra/perf/BackgroundQueue");
|
|
5
|
+
const primitives_1 = require("../../util/primitives");
|
|
6
|
+
function mergeThread(previous, incoming) {
|
|
7
|
+
return {
|
|
8
|
+
jid: incoming.jid,
|
|
9
|
+
name: incoming.name ?? previous.name,
|
|
10
|
+
unreadCount: incoming.unreadCount ?? previous.unreadCount,
|
|
11
|
+
archived: incoming.archived ?? previous.archived,
|
|
12
|
+
pinned: incoming.pinned ?? previous.pinned,
|
|
13
|
+
muteEndMs: incoming.muteEndMs ?? previous.muteEndMs,
|
|
14
|
+
markedAsUnread: incoming.markedAsUnread ?? previous.markedAsUnread,
|
|
15
|
+
ephemeralExpiration: incoming.ephemeralExpiration ?? previous.ephemeralExpiration
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function mergeContact(previous, incoming) {
|
|
19
|
+
return {
|
|
20
|
+
jid: incoming.jid,
|
|
21
|
+
displayName: incoming.displayName ?? previous.displayName,
|
|
22
|
+
pushName: incoming.pushName ?? previous.pushName,
|
|
23
|
+
lid: incoming.lid ?? previous.lid,
|
|
24
|
+
phoneNumber: incoming.phoneNumber ?? previous.phoneNumber,
|
|
25
|
+
lastUpdatedMs: Math.max(previous.lastUpdatedMs, incoming.lastUpdatedMs)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
class WriteBehindPersistence {
|
|
29
|
+
constructor(stores, logger, options = {}) {
|
|
30
|
+
this.logger = logger;
|
|
31
|
+
this.flushTimeoutMs = options.flushTimeoutMs ?? 5000;
|
|
32
|
+
const queueOptions = (domain) => ({
|
|
33
|
+
maxPendingKeys: options.maxPendingKeys ?? 4096,
|
|
34
|
+
maxWriteConcurrency: options.maxWriteConcurrency ?? 4,
|
|
35
|
+
flushTimeoutMs: this.flushTimeoutMs,
|
|
36
|
+
onError: (key, error, attempt) => {
|
|
37
|
+
this.logger.warn('write-behind error', {
|
|
38
|
+
domain,
|
|
39
|
+
key,
|
|
40
|
+
attempt,
|
|
41
|
+
message: (0, primitives_1.toError)(error).message
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
onPressure: (pendingKeys) => {
|
|
45
|
+
this.logger.warn('write-behind pressure', {
|
|
46
|
+
domain,
|
|
47
|
+
pendingKeys
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
onDiscard: (key) => {
|
|
51
|
+
this.logger.warn('write-behind discarded pending write', {
|
|
52
|
+
domain,
|
|
53
|
+
key
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
this.queues = {
|
|
58
|
+
messages: new BackgroundQueue_1.BackgroundQueue((_key, value) => stores.messageStore.upsert(value), queueOptions('messages')),
|
|
59
|
+
threads: new BackgroundQueue_1.BackgroundQueue((_key, value) => stores.threadStore.upsert(value), {
|
|
60
|
+
...queueOptions('threads'),
|
|
61
|
+
coalesce: (previous, incoming) => mergeThread(previous, incoming)
|
|
62
|
+
}),
|
|
63
|
+
contacts: new BackgroundQueue_1.BackgroundQueue((_key, value) => stores.contactStore.upsert(value), {
|
|
64
|
+
...queueOptions('contacts'),
|
|
65
|
+
coalesce: (previous, incoming) => mergeContact(previous, incoming)
|
|
66
|
+
})
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
persistMessage(record) {
|
|
70
|
+
this.queues.messages.enqueue(`msg:${record.id}`, record);
|
|
71
|
+
}
|
|
72
|
+
persistMessageAsync(record) {
|
|
73
|
+
return this.queues.messages.enqueueAsync(`msg:${record.id}`, record);
|
|
74
|
+
}
|
|
75
|
+
persistThread(record) {
|
|
76
|
+
this.queues.threads.enqueue(`thread:${record.jid}`, record);
|
|
77
|
+
}
|
|
78
|
+
persistThreadAsync(record) {
|
|
79
|
+
return this.queues.threads.enqueueAsync(`thread:${record.jid}`, record);
|
|
80
|
+
}
|
|
81
|
+
persistContact(record) {
|
|
82
|
+
this.queues.contacts.enqueue(`contact:${record.jid}`, record);
|
|
83
|
+
}
|
|
84
|
+
persistContactAsync(record) {
|
|
85
|
+
return this.queues.contacts.enqueueAsync(`contact:${record.jid}`, record);
|
|
86
|
+
}
|
|
87
|
+
async flush(timeoutMs = this.flushTimeoutMs) {
|
|
88
|
+
const [messages, threads, contacts] = await Promise.all([
|
|
89
|
+
this.queues.messages.flush(timeoutMs),
|
|
90
|
+
this.queues.threads.flush(timeoutMs),
|
|
91
|
+
this.queues.contacts.flush(timeoutMs)
|
|
92
|
+
]);
|
|
93
|
+
const result = this.toDrainResult(messages, threads, contacts);
|
|
94
|
+
if (result.remaining > 0) {
|
|
95
|
+
this.logger.warn('write-behind flush finished with pending writes', {
|
|
96
|
+
messagesRemaining: messages.remaining,
|
|
97
|
+
threadsRemaining: threads.remaining,
|
|
98
|
+
contactsRemaining: contacts.remaining
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
async destroy(timeoutMs = this.flushTimeoutMs) {
|
|
104
|
+
const [messages, threads, contacts] = await Promise.all([
|
|
105
|
+
this.queues.messages.destroy(timeoutMs),
|
|
106
|
+
this.queues.threads.destroy(timeoutMs),
|
|
107
|
+
this.queues.contacts.destroy(timeoutMs)
|
|
108
|
+
]);
|
|
109
|
+
const result = this.toDrainResult(messages, threads, contacts);
|
|
110
|
+
if (result.remaining > 0) {
|
|
111
|
+
this.logger.warn('write-behind destroy finished with pending writes', {
|
|
112
|
+
messagesRemaining: messages.remaining,
|
|
113
|
+
threadsRemaining: threads.remaining,
|
|
114
|
+
contactsRemaining: contacts.remaining
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
toDrainResult(messages, threads, contacts) {
|
|
120
|
+
return {
|
|
121
|
+
messages,
|
|
122
|
+
threads,
|
|
123
|
+
contacts,
|
|
124
|
+
flushed: messages.flushed + threads.flushed + contacts.flushed,
|
|
125
|
+
remaining: messages.remaining + threads.remaining + contacts.remaining
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exports.WriteBehindPersistence = WriteBehindPersistence;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CsTokenGenerator = void 0;
|
|
4
|
+
const core_1 = require("../../crypto/core");
|
|
5
|
+
const bytes_1 = require("../../util/bytes");
|
|
6
|
+
const collections_1 = require("../../util/collections");
|
|
7
|
+
const CS_TOKEN_CACHE_MAX = 5;
|
|
8
|
+
class CsTokenGenerator {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.cachedKey = null;
|
|
11
|
+
this.cachedSalt = null;
|
|
12
|
+
this.cache = new Map();
|
|
13
|
+
}
|
|
14
|
+
async generate(nctSalt, accountLid) {
|
|
15
|
+
const cached = this.cache.get(accountLid);
|
|
16
|
+
if (cached && this.isSameSalt(nctSalt)) {
|
|
17
|
+
return cached;
|
|
18
|
+
}
|
|
19
|
+
const key = await this.resolveKey(nctSalt);
|
|
20
|
+
const result = await (0, core_1.hmacSign)(key, bytes_1.TEXT_ENCODER.encode(accountLid));
|
|
21
|
+
(0, collections_1.setBoundedMapEntry)(this.cache, accountLid, result, CS_TOKEN_CACHE_MAX);
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
invalidate() {
|
|
25
|
+
this.cachedKey = null;
|
|
26
|
+
this.cachedSalt = null;
|
|
27
|
+
this.cache.clear();
|
|
28
|
+
}
|
|
29
|
+
isSameSalt(salt) {
|
|
30
|
+
if (!this.cachedSalt || this.cachedSalt.length !== salt.length) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
for (let i = 0; i < salt.length; i += 1) {
|
|
34
|
+
if (this.cachedSalt[i] !== salt[i]) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
async resolveKey(salt) {
|
|
41
|
+
if (this.cachedKey && this.isSameSalt(salt)) {
|
|
42
|
+
return this.cachedKey;
|
|
43
|
+
}
|
|
44
|
+
this.cachedKey = await (0, core_1.importHmacKey)(salt);
|
|
45
|
+
this.cachedSalt = salt;
|
|
46
|
+
this.cache.clear();
|
|
47
|
+
return this.cachedKey;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.CsTokenGenerator = CsTokenGenerator;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computeBucket = computeBucket;
|
|
4
|
+
exports.tokenExpirationCutoffS = tokenExpirationCutoffS;
|
|
5
|
+
exports.isTokenExpired = isTokenExpired;
|
|
6
|
+
exports.shouldSendNewToken = shouldSendNewToken;
|
|
7
|
+
exports.clampDuration = clampDuration;
|
|
8
|
+
function computeBucket(unixTimeS, durationS) {
|
|
9
|
+
return Math.floor(unixTimeS / durationS);
|
|
10
|
+
}
|
|
11
|
+
function tokenExpirationCutoffS(nowS, durationS, numBuckets) {
|
|
12
|
+
const currentBucket = computeBucket(nowS, durationS);
|
|
13
|
+
const cutoffBucket = currentBucket - numBuckets;
|
|
14
|
+
return cutoffBucket * durationS;
|
|
15
|
+
}
|
|
16
|
+
function isTokenExpired(tokenTimestampS, nowS, durationS, numBuckets) {
|
|
17
|
+
const cutoff = tokenExpirationCutoffS(nowS, durationS, numBuckets);
|
|
18
|
+
return tokenTimestampS < cutoff;
|
|
19
|
+
}
|
|
20
|
+
function shouldSendNewToken(senderTimestampS, nowS, senderDurationS) {
|
|
21
|
+
return computeBucket(senderTimestampS, senderDurationS) !== computeBucket(nowS, senderDurationS);
|
|
22
|
+
}
|
|
23
|
+
function clampDuration(durationS, maxDurationS) {
|
|
24
|
+
return Math.min(durationS, maxDurationS);
|
|
25
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Cryptographic utilities
|
|
4
4
|
*/
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.aesCtrDecrypt = exports.aesCtrEncrypt = exports.pbkdf2DeriveAesCtrKey = exports.hmacSign = exports.importHmacSha512Key = exports.importHmacKey = exports.aesCbcDecrypt = exports.aesCbcEncrypt = exports.importAesCbcKey = exports.aesGcmDecrypt = exports.aesGcmEncrypt = exports.importAesGcmKey = exports.sha512 = exports.sha256 = exports.sha1 = exports.randomIntAsync = exports.randomFillAsync = exports.randomBytesAsync = exports.buildNonce = exports.readVersionedContent = exports.prependVersion = exports.toRawPubKey = exports.toSerializedPubKey = exports.hkdfSplit = exports.hkdf = exports.X25519 = exports.Ed25519 = void 0;
|
|
7
7
|
var Ed25519_1 = require("../curves/Ed25519");
|
|
8
8
|
Object.defineProperty(exports, "Ed25519", { enumerable: true, get: function () { return Ed25519_1.Ed25519; } });
|
|
9
9
|
var X25519_1 = require("../curves/X25519");
|
|
@@ -20,6 +20,7 @@ var nonce_1 = require("../core/nonce");
|
|
|
20
20
|
Object.defineProperty(exports, "buildNonce", { enumerable: true, get: function () { return nonce_1.buildNonce; } });
|
|
21
21
|
var random_1 = require("../core/random");
|
|
22
22
|
Object.defineProperty(exports, "randomBytesAsync", { enumerable: true, get: function () { return random_1.randomBytesAsync; } });
|
|
23
|
+
Object.defineProperty(exports, "randomFillAsync", { enumerable: true, get: function () { return random_1.randomFillAsync; } });
|
|
23
24
|
Object.defineProperty(exports, "randomIntAsync", { enumerable: true, get: function () { return random_1.randomIntAsync; } });
|
|
24
25
|
var primitives_1 = require("../core/primitives");
|
|
25
26
|
Object.defineProperty(exports, "sha1", { enumerable: true, get: function () { return primitives_1.sha1; } });
|
|
@@ -37,4 +38,3 @@ Object.defineProperty(exports, "hmacSign", { enumerable: true, get: function ()
|
|
|
37
38
|
Object.defineProperty(exports, "pbkdf2DeriveAesCtrKey", { enumerable: true, get: function () { return primitives_1.pbkdf2DeriveAesCtrKey; } });
|
|
38
39
|
Object.defineProperty(exports, "aesCtrEncrypt", { enumerable: true, get: function () { return primitives_1.aesCtrEncrypt; } });
|
|
39
40
|
Object.defineProperty(exports, "aesCtrDecrypt", { enumerable: true, get: function () { return primitives_1.aesCtrDecrypt; } });
|
|
40
|
-
Object.defineProperty(exports, "ed25519VerifyRaw", { enumerable: true, get: function () { return primitives_1.ed25519VerifyRaw; } });
|
package/dist/crypto/core/keys.js
CHANGED
|
@@ -5,21 +5,21 @@ exports.toRawPubKey = toRawPubKey;
|
|
|
5
5
|
exports.versionByte = versionByte;
|
|
6
6
|
exports.prependVersion = prependVersion;
|
|
7
7
|
exports.readVersionedContent = readVersionedContent;
|
|
8
|
-
const constants_1 = require("../core/constants");
|
|
9
8
|
const bytes_1 = require("../../util/bytes");
|
|
9
|
+
const SERIALIZED_PUB_KEY_PREFIX = 5;
|
|
10
10
|
/**
|
|
11
11
|
* Converts a 32-byte raw public key to 33-byte serialized format (with 0x05 prefix)
|
|
12
12
|
*/
|
|
13
13
|
function toSerializedPubKey(key) {
|
|
14
14
|
if (key.length === 33) {
|
|
15
|
-
if (key[0] !==
|
|
15
|
+
if (key[0] !== SERIALIZED_PUB_KEY_PREFIX) {
|
|
16
16
|
throw new Error('invalid serialized signal public key prefix');
|
|
17
17
|
}
|
|
18
18
|
return key;
|
|
19
19
|
}
|
|
20
20
|
(0, bytes_1.assertByteLength)(key, 32, `invalid signal public key length ${key.length}`);
|
|
21
21
|
const out = new Uint8Array(33);
|
|
22
|
-
out[0] =
|
|
22
|
+
out[0] = SERIALIZED_PUB_KEY_PREFIX;
|
|
23
23
|
out.set(key, 1);
|
|
24
24
|
return out;
|
|
25
25
|
}
|
|
@@ -30,7 +30,7 @@ function toRawPubKey(key) {
|
|
|
30
30
|
if (key.length === 32) {
|
|
31
31
|
return key;
|
|
32
32
|
}
|
|
33
|
-
if (key.length === 33 && key[0] ===
|
|
33
|
+
if (key.length === 33 && key[0] === SERIALIZED_PUB_KEY_PREFIX) {
|
|
34
34
|
return key.subarray(1);
|
|
35
35
|
}
|
|
36
36
|
throw new Error(`invalid signal public key length ${key.length}`);
|
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.buildNonce = buildNonce;
|
|
4
4
|
/**
|
|
5
5
|
* Builds a 12-byte nonce for AES-GCM encryption with counter in the last 4 bytes.
|
|
6
|
+
* Allocates a new buffer per call because concurrent Noise encrypt/decrypt operations
|
|
7
|
+
* may hold references to different nonces simultaneously.
|
|
6
8
|
* Throws if counter exceeds uint32 range to prevent nonce reuse.
|
|
7
9
|
*/
|
|
8
10
|
function buildNonce(counter) {
|
|
@@ -19,7 +19,6 @@ exports.hmacSign = hmacSign;
|
|
|
19
19
|
exports.pbkdf2DeriveAesCtrKey = pbkdf2DeriveAesCtrKey;
|
|
20
20
|
exports.aesCtrEncrypt = aesCtrEncrypt;
|
|
21
21
|
exports.aesCtrDecrypt = aesCtrDecrypt;
|
|
22
|
-
exports.ed25519VerifyRaw = ed25519VerifyRaw;
|
|
23
22
|
const node_crypto_1 = require("node:crypto");
|
|
24
23
|
const bytes_1 = require("../../util/bytes");
|
|
25
24
|
async function digestBytes(algorithm, value) {
|
|
@@ -109,10 +108,3 @@ async function aesCtrEncrypt(key, counter, plaintext) {
|
|
|
109
108
|
async function aesCtrDecrypt(key, counter, ciphertext) {
|
|
110
109
|
return (0, bytes_1.toBytesView)(await node_crypto_1.webcrypto.subtle.decrypt({ name: 'AES-CTR', counter, length: 64 }, key, ciphertext));
|
|
111
110
|
}
|
|
112
|
-
// ============================================
|
|
113
|
-
// Ed25519 raw verify (for Signal variant sigs)
|
|
114
|
-
// ============================================
|
|
115
|
-
async function ed25519VerifyRaw(publicKey, signature, message) {
|
|
116
|
-
const cryptoKey = await node_crypto_1.webcrypto.subtle.importKey('raw', publicKey, { name: 'Ed25519' }, false, ['verify']);
|
|
117
|
-
return node_crypto_1.webcrypto.subtle.verify('Ed25519', cryptoKey, signature, message);
|
|
118
|
-
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.randomIntAsync = void 0;
|
|
4
4
|
exports.randomBytesAsync = randomBytesAsync;
|
|
5
|
+
exports.randomFillAsync = randomFillAsync;
|
|
5
6
|
const node_crypto_1 = require("node:crypto");
|
|
6
7
|
const node_util_1 = require("node:util");
|
|
7
8
|
const bytes_1 = require("../../util/bytes");
|
|
@@ -10,4 +11,25 @@ const randomIntAsyncImpl = (0, node_util_1.promisify)(node_crypto_1.randomInt);
|
|
|
10
11
|
async function randomBytesAsync(size) {
|
|
11
12
|
return (0, bytes_1.toBytesView)(await randomBytesAsyncImpl(size));
|
|
12
13
|
}
|
|
14
|
+
async function randomFillAsync(target, offset, size) {
|
|
15
|
+
await new Promise((resolve, reject) => {
|
|
16
|
+
const onDone = (error) => {
|
|
17
|
+
if (error) {
|
|
18
|
+
reject(error);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
resolve();
|
|
22
|
+
};
|
|
23
|
+
if (offset === undefined) {
|
|
24
|
+
(0, node_crypto_1.randomFill)(target, onDone);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (size === undefined) {
|
|
28
|
+
(0, node_crypto_1.randomFill)(target, offset, onDone);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
(0, node_crypto_1.randomFill)(target, offset, size, onDone);
|
|
32
|
+
});
|
|
33
|
+
return target;
|
|
34
|
+
}
|
|
13
35
|
exports.randomIntAsync = randomIntAsyncImpl;
|
|
@@ -6,9 +6,24 @@ exports.montgomeryToEdwardsPublic = montgomeryToEdwardsPublic;
|
|
|
6
6
|
const node_crypto_1 = require("node:crypto");
|
|
7
7
|
const constants_1 = require("../curves/constants");
|
|
8
8
|
const types_1 = require("../curves/types");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
9
|
+
const constants_2 = require("../math/constants");
|
|
10
|
+
const fe_1 = require("../math/fe");
|
|
11
11
|
const bytes_1 = require("../../util/bytes");
|
|
12
|
+
// Pre-allocated temps for montgomeryToEdwardsPublic (safe: single-threaded)
|
|
13
|
+
const _mx = (0, fe_1.fe)();
|
|
14
|
+
const _m1 = (0, fe_1.fe)();
|
|
15
|
+
const _m2 = (0, fe_1.fe)();
|
|
16
|
+
const _m3 = (0, fe_1.fe)();
|
|
17
|
+
// p-1 = 2^255-20 in LE bytes: 0xEC, 0xFF×30, 0x7F
|
|
18
|
+
// Mask bit 255 before comparing (non-canonical inputs may have it set)
|
|
19
|
+
function isFieldPMinus1(b) {
|
|
20
|
+
if (b[0] !== 0xec || (b[31] & 0x7f) !== 0x7f)
|
|
21
|
+
return false;
|
|
22
|
+
for (let i = 1; i < 31; i++)
|
|
23
|
+
if (b[i] !== 0xff)
|
|
24
|
+
return false;
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
12
27
|
function clampCurvePrivateKeyInPlace(privateKey) {
|
|
13
28
|
(0, bytes_1.assertByteLength)(privateKey, 32, `invalid curve25519 private key length ${privateKey.length}`);
|
|
14
29
|
privateKey[0] &= 248;
|
|
@@ -18,12 +33,16 @@ function clampCurvePrivateKeyInPlace(privateKey) {
|
|
|
18
33
|
}
|
|
19
34
|
function montgomeryToEdwardsPublic(curvePublicKey, signBit) {
|
|
20
35
|
(0, bytes_1.assertByteLength)(curvePublicKey, 32, `invalid curve25519 public key length ${curvePublicKey.length}`);
|
|
21
|
-
|
|
22
|
-
if (x === mod_1.FIELD_P - 1n) {
|
|
36
|
+
if (isFieldPMinus1(curvePublicKey)) {
|
|
23
37
|
throw new Error('invalid curve25519 low-order public key');
|
|
24
38
|
}
|
|
25
|
-
|
|
26
|
-
|
|
39
|
+
(0, fe_1.feFromBytes)(_mx, curvePublicKey);
|
|
40
|
+
(0, fe_1.feSub)(_m1, _mx, constants_2.FE_ONE);
|
|
41
|
+
(0, fe_1.feAdd)(_m2, _mx, constants_2.FE_ONE);
|
|
42
|
+
(0, fe_1.feInv)(_m3, _m2);
|
|
43
|
+
(0, fe_1.feMul)(_m1, _m1, _m3);
|
|
44
|
+
const encoded = new Uint8Array(32);
|
|
45
|
+
(0, fe_1.fePack)(encoded, _m1);
|
|
27
46
|
encoded[31] = (encoded[31] & 0x7f) | (signBit & 0x80);
|
|
28
47
|
return encoded;
|
|
29
48
|
}
|
package/dist/crypto/index.js
CHANGED
|
@@ -14,4 +14,7 @@ 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.X25519 = void 0;
|
|
17
18
|
__exportStar(require("./core"), exports);
|
|
19
|
+
var X25519_1 = require("./curves/X25519");
|
|
20
|
+
Object.defineProperty(exports, "X25519", { enumerable: true, get: function () { return X25519_1.X25519; } });
|
|
@@ -1,44 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.IDENTITY_POINT = exports.BASE_POINT = exports.
|
|
3
|
+
exports.IDENTITY_POINT = exports.BASE_POINT = exports.FE_ONE = exports.FE_ZERO = exports.FE_TWO_D = exports.GROUP_L = exports.FIELD_P = void 0;
|
|
4
|
+
const fe_1 = require("../math/fe");
|
|
4
5
|
exports.FIELD_P = (1n << 255n) - 19n;
|
|
5
6
|
exports.GROUP_L = (1n << 252n) + 27742317777372353535851937790883648493n;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
function modPowField(base, exponent) {
|
|
11
|
-
let result = 1n;
|
|
12
|
-
let current = modField(base);
|
|
13
|
-
let power = exponent;
|
|
14
|
-
while (power > 0n) {
|
|
15
|
-
if ((power & 1n) === 1n) {
|
|
16
|
-
result = modField(result * current);
|
|
17
|
-
}
|
|
18
|
-
current = modField(current * current);
|
|
19
|
-
power >>= 1n;
|
|
20
|
-
}
|
|
21
|
-
return result;
|
|
22
|
-
}
|
|
23
|
-
function modInvField(value) {
|
|
24
|
-
if (value === 0n) {
|
|
25
|
-
throw new Error('field inversion by zero');
|
|
26
|
-
}
|
|
27
|
-
return modPowField(value, exports.FIELD_P - 2n);
|
|
28
|
-
}
|
|
29
|
-
const BASE_X = 15112221349535400772501151409588531511454012693041857206046113283949847762202n;
|
|
30
|
-
const BASE_Y = 46316835694926478169428394003475163141307993866256225615783033603165251855960n;
|
|
31
|
-
exports.EDWARDS_D = modField(-121665n * modInvField(121666n));
|
|
32
|
-
exports.TWO_D = modField(2n * exports.EDWARDS_D);
|
|
7
|
+
exports.FE_TWO_D = (0, fe_1.feFromBigInt)(16295367250680780974490674513165176452449235426866156013048779062215315747161n);
|
|
8
|
+
exports.FE_ZERO = (0, fe_1.fe)();
|
|
9
|
+
exports.FE_ONE = (0, fe_1.feFromBigInt)(1n);
|
|
33
10
|
exports.BASE_POINT = Object.freeze({
|
|
34
|
-
x:
|
|
35
|
-
y:
|
|
36
|
-
z: 1n,
|
|
37
|
-
t:
|
|
11
|
+
x: (0, fe_1.feFromBigInt)(15112221349535400772501151409588531511454012693041857206046113283949847762202n),
|
|
12
|
+
y: (0, fe_1.feFromBigInt)(46316835694926478169428394003475163141307993866256225615783033603165251855960n),
|
|
13
|
+
z: (0, fe_1.feFromBigInt)(1n),
|
|
14
|
+
t: (0, fe_1.feFromBigInt)(46827403850823179245072216630277197565144205554125654976674165829533817101731n)
|
|
38
15
|
});
|
|
39
16
|
exports.IDENTITY_POINT = Object.freeze({
|
|
40
|
-
x: 0n,
|
|
41
|
-
y: 1n,
|
|
42
|
-
z: 1n,
|
|
43
|
-
t: 0n
|
|
17
|
+
x: (0, fe_1.feFromBigInt)(0n),
|
|
18
|
+
y: (0, fe_1.feFromBigInt)(1n),
|
|
19
|
+
z: (0, fe_1.feFromBigInt)(1n),
|
|
20
|
+
t: (0, fe_1.feFromBigInt)(0n)
|
|
44
21
|
});
|