zapo-js 0.1.1 → 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 +20 -4
- package/dist/appstate/WaAppStateCrypto.js +19 -26
- package/dist/appstate/WaAppStateSyncClient.js +293 -181
- package/dist/appstate/WaAppStateSyncResponseParser.js +16 -5
- package/dist/appstate/constants.js +4 -3
- package/dist/appstate/{store/sqlite.js → encoding.js} +13 -8
- package/dist/appstate/index.js +8 -6
- package/dist/appstate/utils.js +9 -34
- package/dist/auth/WaAuthClient.js +43 -61
- package/dist/auth/flow/WaAuthCredentialsFlow.js +22 -15
- package/dist/auth/index.js +1 -8
- package/dist/auth/pairing/WaPairingCodeCrypto.js +6 -4
- package/dist/auth/pairing/WaPairingFlow.js +34 -26
- package/dist/auth/pairing/WaQrFlow.js +37 -24
- package/dist/client/WaClient.js +275 -324
- package/dist/client/WaClientFactory.js +500 -133
- package/dist/client/connection/WaConnectionManager.js +301 -0
- package/dist/client/connection/WaKeyShareCoordinator.js +63 -0
- package/dist/client/connection/WaReceiptQueue.js +51 -0
- package/dist/client/coordinators/WaAppStateMutationCoordinator.js +471 -0
- package/dist/client/coordinators/WaBusinessCoordinator.js +241 -0
- package/dist/client/coordinators/WaGroupCoordinator.js +30 -16
- package/dist/client/coordinators/WaIncomingNodeCoordinator.js +21 -27
- package/dist/client/coordinators/WaMessageDispatchCoordinator.js +439 -701
- 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 +242 -57
- package/dist/client/coordinators/WaStreamControlCoordinator.js +18 -11
- package/dist/client/coordinators/WaTrustedContactTokenCoordinator.js +166 -0
- package/dist/client/dirty.js +74 -48
- package/dist/client/events/chat.js +4 -3
- package/dist/client/events/devices.js +72 -0
- package/dist/client/events/group.js +62 -47
- package/dist/client/events/identity.js +22 -0
- package/dist/client/events/privacy-token.js +39 -0
- package/dist/client/history-sync.js +94 -63
- package/dist/client/incoming.js +60 -27
- package/dist/client/mailbox.js +24 -23
- package/dist/client/messages.js +107 -31
- package/dist/client/messaging/fanout.js +199 -0
- package/dist/client/messaging/key-protocol.js +130 -0
- package/dist/client/messaging/participants.js +193 -0
- 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/hkdf.js +3 -8
- package/dist/crypto/core/index.js +2 -5
- package/dist/crypto/core/keys.js +6 -7
- package/dist/crypto/core/nonce.js +2 -0
- package/dist/crypto/core/primitives.js +12 -23
- package/dist/crypto/core/random.js +26 -23
- package/dist/crypto/curves/Ed25519.js +7 -8
- package/dist/crypto/curves/X25519.js +38 -22
- package/dist/crypto/index.js +1 -3
- 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 +7 -14
- package/dist/esm/appstate/WaAppStateSyncClient.js +284 -172
- package/dist/esm/appstate/WaAppStateSyncResponseParser.js +17 -6
- package/dist/esm/appstate/constants.js +3 -2
- 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 +8 -30
- package/dist/esm/auth/WaAuthClient.js +43 -61
- package/dist/esm/auth/flow/WaAuthCredentialsFlow.js +22 -15
- package/dist/esm/auth/index.js +0 -3
- package/dist/esm/auth/pairing/WaPairingCodeCrypto.js +6 -4
- package/dist/esm/auth/pairing/WaPairingFlow.js +28 -20
- package/dist/esm/auth/pairing/WaQrFlow.js +37 -24
- package/dist/esm/client/WaClient.js +275 -324
- package/dist/esm/client/WaClientFactory.js +501 -134
- package/dist/esm/client/connection/WaConnectionManager.js +297 -0
- package/dist/esm/client/connection/WaKeyShareCoordinator.js +59 -0
- package/dist/esm/client/connection/WaReceiptQueue.js +47 -0
- package/dist/esm/client/coordinators/WaAppStateMutationCoordinator.js +467 -0
- package/dist/esm/client/coordinators/WaBusinessCoordinator.js +238 -0
- package/dist/esm/client/coordinators/WaGroupCoordinator.js +23 -9
- package/dist/esm/client/coordinators/WaIncomingNodeCoordinator.js +21 -27
- package/dist/esm/client/coordinators/WaMessageDispatchCoordinator.js +443 -705
- 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 +244 -59
- package/dist/esm/client/coordinators/WaStreamControlCoordinator.js +19 -12
- package/dist/esm/client/coordinators/WaTrustedContactTokenCoordinator.js +162 -0
- package/dist/esm/client/dirty.js +69 -43
- package/dist/esm/client/events/chat.js +4 -3
- package/dist/esm/client/events/devices.js +68 -0
- package/dist/esm/client/events/group.js +53 -39
- 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 +91 -60
- package/dist/esm/client/incoming.js +61 -28
- package/dist/esm/client/mailbox.js +24 -23
- package/dist/esm/client/messages.js +108 -32
- package/dist/esm/client/messaging/fanout.js +196 -0
- package/dist/esm/client/messaging/key-protocol.js +127 -0
- package/dist/esm/client/messaging/participants.js +190 -0
- 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/hkdf.js +3 -8
- package/dist/esm/crypto/core/index.js +2 -3
- package/dist/esm/crypto/core/keys.js +3 -4
- package/dist/esm/crypto/core/nonce.js +2 -0
- package/dist/esm/crypto/core/primitives.js +12 -22
- package/dist/esm/crypto/core/random.js +25 -23
- package/dist/esm/crypto/curves/Ed25519.js +4 -5
- package/dist/esm/crypto/curves/X25519.js +35 -19
- package/dist/esm/crypto/index.js +0 -1
- 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/log/ConsoleLogger.js +18 -17
- package/dist/esm/infra/log/PinoLogger.js +15 -9
- package/dist/esm/infra/log/types.js +11 -1
- package/dist/esm/infra/perf/BackgroundQueue.js +478 -0
- package/dist/esm/infra/perf/BoundedTaskQueue.js +16 -18
- 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 +96 -16
- package/dist/esm/media/WaMediaTransferClient.js +251 -91
- package/dist/esm/media/conn.js +10 -6
- package/dist/esm/media/constants.js +6 -2
- package/dist/esm/message/WaMessageClient.js +30 -32
- package/dist/esm/message/ack.js +6 -6
- package/dist/esm/message/addon-crypto.js +59 -0
- package/dist/esm/message/content.js +195 -9
- package/dist/esm/message/icdc.js +76 -0
- package/dist/esm/message/incoming.js +129 -122
- package/dist/esm/message/index.js +2 -0
- package/dist/esm/message/phash.js +3 -1
- package/dist/esm/message/reporting-token.js +425 -0
- package/dist/esm/message/use-case-secret.js +49 -0
- package/dist/esm/protocol/appstate.js +27 -0
- package/dist/esm/protocol/browser.js +10 -18
- package/dist/esm/protocol/constants.js +6 -3
- package/dist/esm/protocol/defaults.js +6 -0
- package/dist/esm/protocol/index.js +2 -11
- package/dist/esm/protocol/jid.js +133 -52
- package/dist/esm/protocol/media.js +3 -3
- package/dist/esm/protocol/message.js +61 -1
- package/dist/esm/protocol/nodes.js +4 -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/protocol/usync.js +11 -0
- package/dist/esm/retry/codec.js +216 -0
- package/dist/esm/retry/constants.js +1 -1
- package/dist/esm/retry/index.js +3 -2
- package/dist/esm/retry/parse.js +88 -86
- package/dist/esm/retry/replay.js +54 -51
- package/dist/esm/retry/tracker.js +94 -0
- package/dist/esm/signal/api/SignalDeviceSyncApi.js +276 -92
- package/dist/esm/signal/api/SignalDigestSyncApi.js +17 -8
- package/dist/esm/signal/api/SignalIdentitySyncApi.js +67 -37
- package/dist/esm/signal/api/SignalMissingPreKeysSyncApi.js +86 -67
- package/dist/esm/signal/api/SignalRotateKeyApi.js +4 -2
- package/dist/esm/signal/api/SignalSessionSyncApi.js +36 -34
- 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 +13 -9
- package/dist/esm/signal/{store/sqlite.js → encoding.js} +93 -60
- package/dist/esm/signal/group/SenderKeyChain.js +28 -23
- package/dist/esm/signal/group/SenderKeyCodec.js +5 -6
- package/dist/esm/signal/group/SenderKeyManager.js +144 -115
- package/dist/esm/signal/index.js +2 -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 +164 -53
- package/dist/esm/signal/session/SignalRatchet.js +24 -15
- package/dist/esm/signal/session/SignalSession.js +14 -9
- package/dist/esm/signal/session/resolver.js +221 -0
- package/dist/esm/store/contracts/privacy-token.store.js +1 -0
- package/dist/esm/store/createStore.js +100 -188
- 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 +4 -7
- package/dist/esm/store/providers/memory/appstate.store.js +38 -16
- package/dist/esm/store/providers/memory/contact.store.js +5 -0
- package/dist/esm/store/providers/memory/device-list.store.js +12 -34
- package/dist/esm/store/providers/memory/message.store.js +11 -5
- package/dist/esm/store/providers/memory/participants.store.js +1 -8
- 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 +11 -8
- package/dist/esm/store/providers/memory/signal.store.js +47 -18
- package/dist/esm/store/providers/memory/thread.store.js +5 -0
- package/dist/esm/transport/WaComms.js +28 -24
- package/dist/esm/transport/WaWebSocket.js +115 -18
- package/dist/esm/transport/binary/constants.js +0 -30
- package/dist/esm/transport/binary/decoder.js +8 -8
- package/dist/esm/transport/binary/encoder.js +10 -9
- package/dist/esm/transport/binary/index.js +0 -1
- package/dist/esm/transport/index.js +1 -0
- package/dist/esm/transport/keepalive/WaKeepAlive.js +2 -8
- package/dist/esm/transport/node/WaNodeOrchestrator.js +25 -21
- package/dist/esm/transport/node/WaNodeTransport.js +0 -3
- package/dist/esm/transport/node/builders/{accountSync.js → account-sync.js} +16 -36
- 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 +7 -3
- package/dist/esm/transport/node/builders/message.js +63 -230
- package/dist/esm/transport/node/builders/pairing.js +2 -27
- 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 +45 -0
- package/dist/esm/transport/node/helpers.js +125 -5
- package/dist/esm/transport/node/usync.js +5 -0
- package/dist/esm/transport/node/xml.js +35 -14
- package/dist/esm/transport/noise/WaClientPayload.js +10 -10
- package/dist/esm/transport/noise/WaFrameCodec.js +48 -33
- package/dist/esm/transport/noise/WaNoiseCert.js +4 -7
- package/dist/esm/transport/noise/WaNoiseSession.js +77 -29
- package/dist/esm/transport/noise/WaNoiseSocket.js +8 -4
- package/dist/esm/transport/proxy.js +27 -0
- package/dist/esm/transport/stream/parse.js +17 -48
- package/dist/esm/util/bytes.js +67 -45
- package/dist/esm/util/coercion.js +6 -14
- package/dist/esm/util/index.js +5 -0
- package/dist/esm/util/primitives.js +40 -14
- package/dist/index.js +7 -1
- package/dist/infra/log/ConsoleLogger.js +18 -17
- package/dist/infra/log/PinoLogger.js +15 -9
- package/dist/infra/log/types.js +12 -0
- package/dist/infra/perf/BackgroundQueue.js +482 -0
- package/dist/infra/perf/BoundedTaskQueue.js +16 -18
- 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 +95 -15
- package/dist/media/WaMediaTransferClient.js +284 -91
- package/dist/media/conn.js +10 -6
- package/dist/media/constants.js +6 -2
- package/dist/message/WaMessageClient.js +31 -33
- package/dist/message/ack.js +6 -6
- package/dist/message/addon-crypto.js +65 -0
- package/dist/message/content.js +198 -9
- package/dist/message/icdc.js +81 -0
- package/dist/message/incoming.js +127 -120
- package/dist/message/index.js +2 -0
- package/dist/message/phash.js +3 -1
- package/dist/message/reporting-token.js +429 -0
- package/dist/message/use-case-secret.js +55 -0
- package/dist/protocol/appstate.js +28 -1
- package/dist/protocol/browser.js +10 -18
- package/dist/protocol/constants.js +26 -1
- package/dist/protocol/defaults.js +6 -0
- package/dist/protocol/index.js +23 -42
- package/dist/protocol/jid.js +140 -52
- package/dist/protocol/media.js +3 -3
- package/dist/protocol/message.js +62 -2
- package/dist/protocol/nodes.js +4 -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/protocol/usync.js +14 -0
- package/dist/retry/codec.js +220 -0
- package/dist/retry/constants.js +1 -1
- package/dist/retry/index.js +7 -5
- package/dist/retry/parse.js +88 -85
- package/dist/retry/replay.js +52 -49
- package/dist/retry/tracker.js +97 -0
- package/dist/signal/api/SignalDeviceSyncApi.js +273 -89
- package/dist/signal/api/SignalDigestSyncApi.js +17 -8
- package/dist/signal/api/SignalIdentitySyncApi.js +66 -36
- package/dist/signal/api/SignalMissingPreKeysSyncApi.js +82 -63
- package/dist/signal/api/SignalRotateKeyApi.js +4 -2
- package/dist/signal/api/SignalSessionSyncApi.js +36 -34
- package/dist/signal/api/result-map.js +13 -0
- package/dist/signal/constants.js +1 -5
- package/dist/signal/crypto/WaAdvSignature.js +11 -7
- package/dist/signal/{store/sqlite.js → encoding.js} +94 -61
- package/dist/signal/group/SenderKeyChain.js +27 -22
- package/dist/signal/group/SenderKeyCodec.js +5 -6
- package/dist/signal/group/SenderKeyManager.js +144 -115
- package/dist/signal/index.js +15 -1
- package/dist/signal/registration/keygen.js +6 -2
- package/dist/signal/registration/utils.js +1 -0
- package/dist/signal/session/SignalProtocol.js +164 -53
- package/dist/signal/session/SignalRatchet.js +24 -15
- package/dist/signal/session/SignalSession.js +14 -9
- package/dist/signal/session/resolver.js +224 -0
- package/dist/store/contracts/privacy-token.store.js +2 -0
- package/dist/store/createStore.js +100 -188
- 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 +4 -7
- package/dist/store/providers/memory/appstate.store.js +36 -14
- package/dist/store/providers/memory/contact.store.js +5 -0
- package/dist/store/providers/memory/device-list.store.js +12 -34
- package/dist/store/providers/memory/message.store.js +11 -5
- package/dist/store/providers/memory/participants.store.js +1 -8
- 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 +14 -11
- package/dist/store/providers/memory/signal.store.js +54 -25
- package/dist/store/providers/memory/thread.store.js +5 -0
- package/dist/transport/WaComms.js +30 -26
- package/dist/transport/WaWebSocket.js +148 -18
- package/dist/transport/binary/constants.js +1 -31
- package/dist/transport/binary/decoder.js +8 -8
- package/dist/transport/binary/encoder.js +10 -9
- package/dist/transport/binary/index.js +0 -4
- package/dist/transport/index.js +7 -1
- package/dist/transport/keepalive/WaKeepAlive.js +1 -7
- package/dist/transport/node/WaNodeOrchestrator.js +25 -21
- package/dist/transport/node/WaNodeTransport.js +0 -3
- package/dist/transport/node/builders/{accountSync.js → account-sync.js} +15 -35
- 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 +29 -17
- package/dist/transport/node/builders/message.js +64 -236
- package/dist/transport/node/builders/pairing.js +2 -29
- 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 +49 -0
- package/dist/transport/node/helpers.js +131 -4
- package/dist/transport/node/usync.js +8 -0
- package/dist/transport/node/xml.js +35 -14
- package/dist/transport/noise/WaClientPayload.js +13 -13
- package/dist/transport/noise/WaFrameCodec.js +47 -32
- package/dist/transport/noise/WaNoiseCert.js +5 -8
- package/dist/transport/noise/WaNoiseSession.js +77 -29
- package/dist/transport/noise/WaNoiseSocket.js +8 -4
- package/dist/transport/proxy.js +34 -0
- package/dist/transport/stream/parse.js +20 -52
- package/dist/types/appstate/WaAppStateCrypto.d.ts +0 -1
- package/dist/types/appstate/WaAppStateSyncClient.d.ts +5 -2
- package/dist/types/appstate/constants.d.ts +1 -0
- 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 -3
- package/dist/types/auth/WaAuthClient.d.ts +10 -12
- package/dist/types/auth/flow/WaAuthCredentialsFlow.d.ts +1 -1
- package/dist/types/auth/index.d.ts +0 -4
- package/dist/types/auth/pairing/WaQrFlow.d.ts +1 -1
- package/dist/types/auth/types.d.ts +7 -9
- package/dist/types/client/WaClient.d.ts +42 -25
- package/dist/types/client/WaClientFactory.d.ts +33 -26
- package/dist/types/client/connection/WaConnectionManager.d.ts +66 -0
- package/dist/types/client/connection/WaKeyShareCoordinator.d.ts +14 -0
- package/dist/types/client/connection/WaReceiptQueue.d.ts +13 -0
- package/dist/types/client/coordinators/WaAppStateMutationCoordinator.d.ts +46 -0
- package/dist/types/client/coordinators/WaBusinessCoordinator.d.ts +57 -0
- package/dist/types/client/coordinators/WaIncomingNodeCoordinator.d.ts +3 -2
- package/dist/types/client/coordinators/WaMessageDispatchCoordinator.d.ts +29 -38
- 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 +8 -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/dirty.d.ts +1 -0
- package/dist/types/client/events/devices.d.ts +20 -0
- package/dist/types/client/events/group.d.ts +2 -1
- 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/messaging/fanout.d.ts +14 -0
- package/dist/types/client/messaging/key-protocol.d.ts +18 -0
- package/dist/types/client/messaging/participants.d.ts +13 -0
- 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 +75 -4
- package/dist/types/crypto/core/hkdf.d.ts +0 -6
- package/dist/types/crypto/core/index.d.ts +2 -3
- 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 +2 -7
- package/dist/types/crypto/index.d.ts +0 -1
- 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/log/ConsoleLogger.d.ts +2 -1
- package/dist/types/infra/log/PinoLogger.d.ts +1 -1
- package/dist/types/infra/log/types.d.ts +1 -0
- package/dist/types/infra/perf/BackgroundQueue.d.ts +58 -0
- package/dist/types/infra/perf/BoundedTaskQueue.d.ts +1 -1
- 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 +16 -15
- 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 +15 -2
- package/dist/types/message/addon-crypto.d.ts +25 -0
- package/dist/types/message/content.d.ts +8 -0
- package/dist/types/message/icdc.d.ts +13 -0
- package/dist/types/message/index.d.ts +2 -0
- package/dist/types/message/reporting-token.d.ts +18 -0
- package/dist/types/message/types.d.ts +45 -6
- package/dist/types/message/use-case-secret.d.ts +20 -0
- package/dist/types/protocol/appstate.d.ts +47 -0
- package/dist/types/protocol/constants.d.ts +8 -3
- package/dist/types/protocol/defaults.d.ts +6 -0
- package/dist/types/protocol/index.d.ts +2 -11
- package/dist/types/protocol/jid.d.ts +22 -5
- package/dist/types/protocol/message.d.ts +60 -0
- package/dist/types/protocol/nodes.d.ts +4 -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/protocol/usync.d.ts +11 -0
- package/dist/types/retry/codec.d.ts +3 -0
- package/dist/types/retry/index.d.ts +4 -3
- package/dist/types/retry/parse.d.ts +5 -2
- package/dist/types/retry/replay.d.ts +0 -4
- package/dist/types/retry/tracker.d.ts +20 -0
- package/dist/types/retry/types.d.ts +10 -4
- package/dist/types/signal/api/SignalDeviceSyncApi.d.ts +15 -2
- 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/SenderKeyCodec.d.ts +4 -6
- package/dist/types/signal/group/SenderKeyManager.d.ts +10 -5
- package/dist/types/signal/index.d.ts +3 -0
- package/dist/types/signal/session/SignalProtocol.d.ts +19 -4
- package/dist/types/signal/session/resolver.d.ts +22 -0
- package/dist/types/store/contracts/appstate.store.d.ts +4 -1
- package/dist/types/store/contracts/contact.store.d.ts +1 -0
- package/dist/types/store/contracts/device-list.store.d.ts +0 -3
- package/dist/types/store/contracts/message.store.d.ts +1 -0
- package/dist/types/store/contracts/participants.store.d.ts +0 -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/sender-key.store.d.ts +0 -1
- package/dist/types/store/contracts/signal.store.d.ts +13 -0
- package/dist/types/store/contracts/thread.store.d.ts +1 -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 +3 -1
- package/dist/types/store/providers/memory/contact.store.d.ts +1 -0
- package/dist/types/store/providers/memory/device-list.store.d.ts +0 -3
- package/dist/types/store/providers/memory/message.store.d.ts +1 -0
- package/dist/types/store/providers/memory/participants.store.d.ts +0 -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/sender-key.store.d.ts +0 -1
- package/dist/types/store/providers/memory/signal.store.d.ts +8 -1
- package/dist/types/store/providers/memory/thread.store.d.ts +1 -0
- package/dist/types/store/types.d.ts +49 -58
- package/dist/types/transport/WaWebSocket.d.ts +3 -1
- package/dist/types/transport/binary/constants.d.ts +0 -30
- package/dist/types/transport/binary/index.d.ts +0 -1
- package/dist/types/transport/index.d.ts +2 -1
- package/dist/types/transport/keepalive/WaKeepAlive.d.ts +0 -1
- package/dist/types/transport/node/WaNodeOrchestrator.d.ts +3 -4
- package/dist/types/transport/node/WaNodeTransport.d.ts +0 -9
- 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/group.d.ts +4 -6
- package/dist/types/transport/node/builders/index.d.ts +7 -3
- package/dist/types/transport/node/builders/message.d.ts +20 -30
- 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 +2 -5
- package/dist/types/transport/node/builders/usync.d.ts +21 -0
- package/dist/types/transport/node/helpers.d.ts +13 -0
- package/dist/types/transport/node/usync.d.ts +2 -0
- package/dist/types/transport/noise/WaFrameCodec.d.ts +3 -0
- package/dist/types/transport/noise/WaNoiseSession.d.ts +4 -2
- package/dist/types/transport/noise/WaNoiseSocket.d.ts +4 -2
- package/dist/types/transport/proxy.d.ts +6 -0
- package/dist/types/transport/stream/parse.d.ts +0 -1
- package/dist/types/transport/types.d.ts +18 -1
- package/dist/types/util/bytes.d.ts +5 -0
- package/dist/types/util/index.d.ts +5 -0
- package/dist/types/util/primitives.d.ts +2 -0
- package/dist/util/bytes.js +72 -46
- package/dist/util/coercion.js +6 -14
- package/dist/util/index.js +23 -0
- package/dist/util/primitives.js +42 -14
- package/package.json +52 -9
- package/proto/index.js +1 -1
- package/dist/crypto/core/constants.js +0 -4
- package/dist/crypto/core/encoding.js +0 -29
- package/dist/esm/crypto/core/constants.js +0 -1
- package/dist/esm/crypto/core/encoding.js +0 -25
- package/dist/esm/retry/outbound.js +0 -83
- package/dist/esm/store/providers/sqlite/BaseSqliteStore.js +0 -37
- package/dist/esm/store/providers/sqlite/appstate.store.js +0 -169
- package/dist/esm/store/providers/sqlite/auth.store.js +0 -176
- package/dist/esm/store/providers/sqlite/connection.js +0 -240
- package/dist/esm/store/providers/sqlite/contact.store.js +0 -61
- package/dist/esm/store/providers/sqlite/device-list.store.js +0 -155
- package/dist/esm/store/providers/sqlite/message.store.js +0 -119
- package/dist/esm/store/providers/sqlite/migrations.js +0 -347
- package/dist/esm/store/providers/sqlite/participants.store.js +0 -85
- package/dist/esm/store/providers/sqlite/retry.store.js +0 -144
- package/dist/esm/store/providers/sqlite/sender-key.store.js +0 -203
- package/dist/esm/store/providers/sqlite/signal.store.js +0 -353
- package/dist/esm/store/providers/sqlite/thread.store.js +0 -72
- package/dist/esm/util/base64.js +0 -18
- package/dist/esm/util/signal-address.js +0 -5
- package/dist/retry/outbound.js +0 -88
- package/dist/store/providers/sqlite/BaseSqliteStore.js +0 -41
- package/dist/store/providers/sqlite/appstate.store.js +0 -173
- package/dist/store/providers/sqlite/auth.store.js +0 -180
- package/dist/store/providers/sqlite/connection.js +0 -276
- package/dist/store/providers/sqlite/contact.store.js +0 -65
- package/dist/store/providers/sqlite/device-list.store.js +0 -159
- package/dist/store/providers/sqlite/message.store.js +0 -123
- package/dist/store/providers/sqlite/migrations.js +0 -350
- package/dist/store/providers/sqlite/participants.store.js +0 -89
- package/dist/store/providers/sqlite/retry.store.js +0 -148
- package/dist/store/providers/sqlite/sender-key.store.js +0 -207
- package/dist/store/providers/sqlite/signal.store.js +0 -357
- package/dist/store/providers/sqlite/thread.store.js +0 -76
- package/dist/types/appstate/store/sqlite.d.ts +0 -21
- package/dist/types/crypto/core/constants.d.ts +0 -1
- package/dist/types/crypto/core/encoding.d.ts +0 -11
- 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 -15
- 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 -10
- package/dist/types/store/providers/sqlite/device-list.store.d.ts +0 -18
- package/dist/types/store/providers/sqlite/message.store.d.ts +0 -11
- package/dist/types/store/providers/sqlite/migrations.d.ts +0 -3
- package/dist/types/store/providers/sqlite/participants.store.d.ts +0 -13
- package/dist/types/store/providers/sqlite/retry.store.d.ts +0 -16
- package/dist/types/store/providers/sqlite/sender-key.store.d.ts +0 -25
- package/dist/types/store/providers/sqlite/signal.store.d.ts +0 -46
- package/dist/types/store/providers/sqlite/thread.store.d.ts +0 -11
- package/dist/types/util/base64.d.ts +0 -4
- package/dist/types/util/signal-address.d.ts +0 -2
- package/dist/util/base64.js +0 -24
- package/dist/util/signal-address.js +0 -8
- /package/dist/types/transport/node/builders/{accountSync.d.ts → account-sync.d.ts} +0 -0
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createGroupParticipantsCache = createGroupParticipantsCache;
|
|
4
|
+
const PromiseDedup_1 = require("../../infra/perf/PromiseDedup");
|
|
5
|
+
const jid_1 = require("../../protocol/jid");
|
|
6
|
+
const primitives_1 = require("../../util/primitives");
|
|
7
|
+
function createGroupParticipantsCache(options) {
|
|
8
|
+
const { participantsStore, queryGroupParticipantJids, logger } = options;
|
|
9
|
+
const dedup = new PromiseDedup_1.PromiseDedup();
|
|
10
|
+
const sanitizeParticipantUsers = (participants) => {
|
|
11
|
+
const deduped = new Set();
|
|
12
|
+
for (const participant of participants) {
|
|
13
|
+
if (!participant || !participant.includes('@')) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
deduped.add((0, jid_1.toUserJid)(participant));
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
logger.trace('ignoring malformed participant jid', {
|
|
21
|
+
participant,
|
|
22
|
+
message: (0, primitives_1.toError)(error).message
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return [...deduped];
|
|
27
|
+
};
|
|
28
|
+
const areParticipantListsEqual = (left, right) => {
|
|
29
|
+
if (left.length !== right.length) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
for (let index = 0; index < left.length; index += 1) {
|
|
33
|
+
if (left[index] !== right[index]) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return true;
|
|
38
|
+
};
|
|
39
|
+
const mergeParticipantUsersIntoCache = async (groupJid, cachedParticipants, participantsToAdd) => {
|
|
40
|
+
if (participantsToAdd.length === 0) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const nextParticipants = [...cachedParticipants];
|
|
44
|
+
const existing = new Set(cachedParticipants);
|
|
45
|
+
for (const participant of participantsToAdd) {
|
|
46
|
+
if (existing.has(participant)) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
existing.add(participant);
|
|
50
|
+
nextParticipants.push(participant);
|
|
51
|
+
}
|
|
52
|
+
if (nextParticipants.length === cachedParticipants.length) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
await participantsStore.upsertGroupParticipants({
|
|
56
|
+
groupJid,
|
|
57
|
+
participants: nextParticipants,
|
|
58
|
+
updatedAtMs: Date.now()
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
const removeParticipantUsersFromCache = async (groupJid, cachedParticipants, participantsToRemove) => {
|
|
62
|
+
if (participantsToRemove.length === 0) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const removed = new Set(participantsToRemove);
|
|
66
|
+
const nextParticipants = cachedParticipants.filter((participant) => !removed.has(participant));
|
|
67
|
+
if (nextParticipants.length === cachedParticipants.length) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (nextParticipants.length === 0) {
|
|
71
|
+
await participantsStore.deleteGroupParticipants(groupJid);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
await participantsStore.upsertGroupParticipants({
|
|
75
|
+
groupJid,
|
|
76
|
+
participants: nextParticipants,
|
|
77
|
+
updatedAtMs: Date.now()
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
const replaceParticipantUsersInCache = async (groupJid, cachedParticipants, participantsToReplace, replacementParticipants) => {
|
|
81
|
+
const toReplace = new Set(participantsToReplace);
|
|
82
|
+
const nextParticipants = cachedParticipants.filter((participant) => !toReplace.has(participant));
|
|
83
|
+
const existing = new Set(nextParticipants);
|
|
84
|
+
for (const participant of replacementParticipants) {
|
|
85
|
+
if (existing.has(participant)) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
existing.add(participant);
|
|
89
|
+
nextParticipants.push(participant);
|
|
90
|
+
}
|
|
91
|
+
if (areParticipantListsEqual(cachedParticipants, nextParticipants)) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (nextParticipants.length === 0) {
|
|
95
|
+
await participantsStore.deleteGroupParticipants(groupJid);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
await participantsStore.upsertGroupParticipants({
|
|
99
|
+
groupJid,
|
|
100
|
+
participants: nextParticipants,
|
|
101
|
+
updatedAtMs: Date.now()
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
const resolveGroupJidForParticipantCacheEvent = (event) => {
|
|
105
|
+
if (event.action === 'linked_group_promote' || event.action === 'linked_group_demote') {
|
|
106
|
+
return event.contextGroupJid ?? event.groupJid ?? null;
|
|
107
|
+
}
|
|
108
|
+
return event.groupJid ?? null;
|
|
109
|
+
};
|
|
110
|
+
const extractParticipantUsersFromGroupEvent = (event) => {
|
|
111
|
+
const candidates = [];
|
|
112
|
+
for (const participant of event.participants ?? []) {
|
|
113
|
+
if (participant.jid) {
|
|
114
|
+
candidates.push(participant.jid);
|
|
115
|
+
}
|
|
116
|
+
if (participant.lidJid) {
|
|
117
|
+
candidates.push(participant.lidJid);
|
|
118
|
+
}
|
|
119
|
+
if (participant.phoneJid) {
|
|
120
|
+
candidates.push(participant.phoneJid);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return sanitizeParticipantUsers(candidates);
|
|
124
|
+
};
|
|
125
|
+
const refreshParticipantUsers = (groupJid) => dedup.run(`refresh:${groupJid}`, async () => {
|
|
126
|
+
const queried = await queryGroupParticipantJids(groupJid);
|
|
127
|
+
const participants = sanitizeParticipantUsers(queried);
|
|
128
|
+
await participantsStore.upsertGroupParticipants({
|
|
129
|
+
groupJid,
|
|
130
|
+
participants,
|
|
131
|
+
updatedAtMs: Date.now()
|
|
132
|
+
});
|
|
133
|
+
return participants;
|
|
134
|
+
});
|
|
135
|
+
const resolveParticipantUsers = (groupJid) => dedup.run(`resolve:${groupJid}`, async () => {
|
|
136
|
+
const cached = await participantsStore.getGroupParticipants(groupJid);
|
|
137
|
+
if (cached && cached.participants.length > 0) {
|
|
138
|
+
return sanitizeParticipantUsers(cached.participants);
|
|
139
|
+
}
|
|
140
|
+
return refreshParticipantUsers(groupJid);
|
|
141
|
+
});
|
|
142
|
+
const mutateFromGroupEvent = async (event) => {
|
|
143
|
+
const groupJid = resolveGroupJidForParticipantCacheEvent(event);
|
|
144
|
+
if (!groupJid) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (event.action === 'delete') {
|
|
148
|
+
await participantsStore.deleteGroupParticipants(groupJid);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const participantUsers = extractParticipantUsersFromGroupEvent(event);
|
|
152
|
+
if (event.action === 'create') {
|
|
153
|
+
if (participantUsers.length === 0) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
await participantsStore.upsertGroupParticipants({
|
|
157
|
+
groupJid,
|
|
158
|
+
participants: participantUsers,
|
|
159
|
+
updatedAtMs: Date.now()
|
|
160
|
+
});
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const cached = await participantsStore.getGroupParticipants(groupJid);
|
|
164
|
+
if (!cached || cached.participants.length === 0) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const cachedParticipants = sanitizeParticipantUsers(cached.participants);
|
|
168
|
+
if (cachedParticipants.length === 0) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (event.action === 'add' ||
|
|
172
|
+
event.action === 'promote' ||
|
|
173
|
+
event.action === 'demote' ||
|
|
174
|
+
event.action === 'linked_group_promote' ||
|
|
175
|
+
event.action === 'linked_group_demote') {
|
|
176
|
+
await mergeParticipantUsersIntoCache(groupJid, cachedParticipants, participantUsers);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (event.action === 'remove') {
|
|
180
|
+
await removeParticipantUsersFromCache(groupJid, cachedParticipants, participantUsers);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (event.action === 'modify') {
|
|
184
|
+
const authorUsers = event.authorJid ? sanitizeParticipantUsers([event.authorJid]) : [];
|
|
185
|
+
await replaceParticipantUsersInCache(groupJid, cachedParticipants, authorUsers, participantUsers);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
return {
|
|
189
|
+
resolveParticipantUsers,
|
|
190
|
+
refreshParticipantUsers,
|
|
191
|
+
mutateFromGroupEvent
|
|
192
|
+
};
|
|
193
|
+
}
|
|
@@ -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
|
+
}
|
package/dist/crypto/core/hkdf.js
CHANGED
|
@@ -4,23 +4,18 @@ exports.hkdf = hkdf;
|
|
|
4
4
|
exports.hkdfSplit = hkdfSplit;
|
|
5
5
|
const node_crypto_1 = require("node:crypto");
|
|
6
6
|
const bytes_1 = require("../../util/bytes");
|
|
7
|
-
/**
|
|
8
|
-
* HKDF key derivation using SHA-256
|
|
9
|
-
*/
|
|
10
7
|
async function hkdf(ikm, salt, info, outLength) {
|
|
11
8
|
const key = await node_crypto_1.webcrypto.subtle.importKey('raw', ikm, 'HKDF', false, ['deriveBits']);
|
|
9
|
+
const infoBytes = typeof info === 'string' ? (info === '' ? bytes_1.EMPTY_BYTES : bytes_1.TEXT_ENCODER.encode(info)) : info;
|
|
12
10
|
const bits = await node_crypto_1.webcrypto.subtle.deriveBits({
|
|
13
11
|
name: 'HKDF',
|
|
14
12
|
hash: 'SHA-256',
|
|
15
13
|
salt: salt ?? bytes_1.EMPTY_BYTES,
|
|
16
|
-
info:
|
|
14
|
+
info: infoBytes
|
|
17
15
|
}, key, outLength * 8);
|
|
18
16
|
return (0, bytes_1.toBytesView)(bits);
|
|
19
17
|
}
|
|
20
|
-
/**
|
|
21
|
-
* HKDF key derivation that outputs two 32-byte keys
|
|
22
|
-
*/
|
|
23
18
|
async function hkdfSplit(ikm, salt, info) {
|
|
24
19
|
const out = await hkdf(ikm, salt, info, 64);
|
|
25
|
-
return [out.subarray(0, 32), out.subarray(32
|
|
20
|
+
return [out.subarray(0, 32), out.subarray(32)];
|
|
26
21
|
}
|
|
@@ -3,14 +3,11 @@
|
|
|
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");
|
|
10
10
|
Object.defineProperty(exports, "X25519", { enumerable: true, get: function () { return X25519_1.X25519; } });
|
|
11
|
-
var encoding_1 = require("../core/encoding");
|
|
12
|
-
Object.defineProperty(exports, "decodeBase64Url", { enumerable: true, get: function () { return encoding_1.decodeBase64Url; } });
|
|
13
|
-
Object.defineProperty(exports, "assert32", { enumerable: true, get: function () { return encoding_1.assert32; } });
|
|
14
11
|
var hkdf_1 = require("../core/hkdf");
|
|
15
12
|
Object.defineProperty(exports, "hkdf", { enumerable: true, get: function () { return hkdf_1.hkdf; } });
|
|
16
13
|
Object.defineProperty(exports, "hkdfSplit", { enumerable: true, get: function () { return hkdf_1.hkdfSplit; } });
|
|
@@ -23,6 +20,7 @@ var nonce_1 = require("../core/nonce");
|
|
|
23
20
|
Object.defineProperty(exports, "buildNonce", { enumerable: true, get: function () { return nonce_1.buildNonce; } });
|
|
24
21
|
var random_1 = require("../core/random");
|
|
25
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; } });
|
|
26
24
|
Object.defineProperty(exports, "randomIntAsync", { enumerable: true, get: function () { return random_1.randomIntAsync; } });
|
|
27
25
|
var primitives_1 = require("../core/primitives");
|
|
28
26
|
Object.defineProperty(exports, "sha1", { enumerable: true, get: function () { return primitives_1.sha1; } });
|
|
@@ -40,4 +38,3 @@ Object.defineProperty(exports, "hmacSign", { enumerable: true, get: function ()
|
|
|
40
38
|
Object.defineProperty(exports, "pbkdf2DeriveAesCtrKey", { enumerable: true, get: function () { return primitives_1.pbkdf2DeriveAesCtrKey; } });
|
|
41
39
|
Object.defineProperty(exports, "aesCtrEncrypt", { enumerable: true, get: function () { return primitives_1.aesCtrEncrypt; } });
|
|
42
40
|
Object.defineProperty(exports, "aesCtrDecrypt", { enumerable: true, get: function () { return primitives_1.aesCtrDecrypt; } });
|
|
43
|
-
Object.defineProperty(exports, "ed25519VerifyRaw", { enumerable: true, get: function () { return primitives_1.ed25519VerifyRaw; } });
|
package/dist/crypto/core/keys.js
CHANGED
|
@@ -5,22 +5,21 @@ exports.toRawPubKey = toRawPubKey;
|
|
|
5
5
|
exports.versionByte = versionByte;
|
|
6
6
|
exports.prependVersion = prependVersion;
|
|
7
7
|
exports.readVersionedContent = readVersionedContent;
|
|
8
|
-
const
|
|
8
|
+
const bytes_1 = require("../../util/bytes");
|
|
9
|
+
const SERIALIZED_PUB_KEY_PREFIX = 5;
|
|
9
10
|
/**
|
|
10
11
|
* Converts a 32-byte raw public key to 33-byte serialized format (with 0x05 prefix)
|
|
11
12
|
*/
|
|
12
13
|
function toSerializedPubKey(key) {
|
|
13
14
|
if (key.length === 33) {
|
|
14
|
-
if (key[0] !==
|
|
15
|
+
if (key[0] !== SERIALIZED_PUB_KEY_PREFIX) {
|
|
15
16
|
throw new Error('invalid serialized signal public key prefix');
|
|
16
17
|
}
|
|
17
18
|
return key;
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
throw new Error(`invalid signal public key length ${key.length}`);
|
|
21
|
-
}
|
|
20
|
+
(0, bytes_1.assertByteLength)(key, 32, `invalid signal public key length ${key.length}`);
|
|
22
21
|
const out = new Uint8Array(33);
|
|
23
|
-
out[0] =
|
|
22
|
+
out[0] = SERIALIZED_PUB_KEY_PREFIX;
|
|
24
23
|
out.set(key, 1);
|
|
25
24
|
return out;
|
|
26
25
|
}
|
|
@@ -31,7 +30,7 @@ function toRawPubKey(key) {
|
|
|
31
30
|
if (key.length === 32) {
|
|
32
31
|
return key;
|
|
33
32
|
}
|
|
34
|
-
if (key.length === 33 && key[0] ===
|
|
33
|
+
if (key.length === 33 && key[0] === SERIALIZED_PUB_KEY_PREFIX) {
|
|
35
34
|
return key.subarray(1);
|
|
36
35
|
}
|
|
37
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,20 +19,22 @@ 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");
|
|
24
|
+
async function digestBytes(algorithm, value) {
|
|
25
|
+
return (0, bytes_1.toBytesView)(await node_crypto_1.webcrypto.subtle.digest(algorithm, value));
|
|
26
|
+
}
|
|
25
27
|
// ============================================
|
|
26
28
|
// Hash functions
|
|
27
29
|
// ============================================
|
|
28
30
|
async function sha256(value) {
|
|
29
|
-
return (
|
|
31
|
+
return digestBytes('SHA-256', value);
|
|
30
32
|
}
|
|
31
33
|
async function sha1(value) {
|
|
32
|
-
return (
|
|
34
|
+
return digestBytes('SHA-1', value);
|
|
33
35
|
}
|
|
34
36
|
async function sha512(value) {
|
|
35
|
-
return (
|
|
37
|
+
return digestBytes('SHA-512', value);
|
|
36
38
|
}
|
|
37
39
|
function md5Bytes(input) {
|
|
38
40
|
return (0, bytes_1.toBytesView)((0, node_crypto_1.createHash)('md5').update(input).digest());
|
|
@@ -44,12 +46,10 @@ async function importAesGcmKey(raw, usages) {
|
|
|
44
46
|
return node_crypto_1.webcrypto.subtle.importKey('raw', raw, 'AES-GCM', false, usages);
|
|
45
47
|
}
|
|
46
48
|
async function aesGcmEncrypt(key, nonce, plaintext, aad = bytes_1.EMPTY_BYTES) {
|
|
47
|
-
|
|
48
|
-
return (0, bytes_1.toBytesView)(result);
|
|
49
|
+
return (0, bytes_1.toBytesView)(await node_crypto_1.webcrypto.subtle.encrypt({ name: 'AES-GCM', iv: nonce, additionalData: aad }, key, plaintext));
|
|
49
50
|
}
|
|
50
51
|
async function aesGcmDecrypt(key, nonce, ciphertext, aad = bytes_1.EMPTY_BYTES) {
|
|
51
|
-
|
|
52
|
-
return (0, bytes_1.toBytesView)(result);
|
|
52
|
+
return (0, bytes_1.toBytesView)(await node_crypto_1.webcrypto.subtle.decrypt({ name: 'AES-GCM', iv: nonce, additionalData: aad }, key, ciphertext));
|
|
53
53
|
}
|
|
54
54
|
// ============================================
|
|
55
55
|
// AES-CBC (for Signal protocol)
|
|
@@ -61,12 +61,10 @@ async function importAesCbcKey(keyBytes) {
|
|
|
61
61
|
]);
|
|
62
62
|
}
|
|
63
63
|
async function aesCbcEncrypt(key, iv, plaintext) {
|
|
64
|
-
|
|
65
|
-
return (0, bytes_1.toBytesView)(result);
|
|
64
|
+
return (0, bytes_1.toBytesView)(await node_crypto_1.webcrypto.subtle.encrypt({ name: 'AES-CBC', iv }, key, plaintext));
|
|
66
65
|
}
|
|
67
66
|
async function aesCbcDecrypt(key, iv, ciphertext) {
|
|
68
|
-
|
|
69
|
-
return (0, bytes_1.toBytesView)(result);
|
|
67
|
+
return (0, bytes_1.toBytesView)(await node_crypto_1.webcrypto.subtle.decrypt({ name: 'AES-CBC', iv }, key, ciphertext));
|
|
70
68
|
}
|
|
71
69
|
// ============================================
|
|
72
70
|
// HMAC-SHA256 (for Signal protocol)
|
|
@@ -105,17 +103,8 @@ async function pbkdf2DeriveAesCtrKey(password, salt, iterations) {
|
|
|
105
103
|
// AES-CTR (for pairing code crypto)
|
|
106
104
|
// ============================================
|
|
107
105
|
async function aesCtrEncrypt(key, counter, plaintext) {
|
|
108
|
-
|
|
109
|
-
return (0, bytes_1.toBytesView)(result);
|
|
106
|
+
return (0, bytes_1.toBytesView)(await node_crypto_1.webcrypto.subtle.encrypt({ name: 'AES-CTR', counter, length: 64 }, key, plaintext));
|
|
110
107
|
}
|
|
111
108
|
async function aesCtrDecrypt(key, counter, ciphertext) {
|
|
112
|
-
|
|
113
|
-
return (0, bytes_1.toBytesView)(result);
|
|
114
|
-
}
|
|
115
|
-
// ============================================
|
|
116
|
-
// Ed25519 raw verify (for Signal variant sigs)
|
|
117
|
-
// ============================================
|
|
118
|
-
async function ed25519VerifyRaw(publicKey, signature, message) {
|
|
119
|
-
const cryptoKey = await node_crypto_1.webcrypto.subtle.importKey('raw', publicKey, { name: 'Ed25519' }, false, ['verify']);
|
|
120
|
-
return node_crypto_1.webcrypto.subtle.verify('Ed25519', cryptoKey, signature, message);
|
|
109
|
+
return (0, bytes_1.toBytesView)(await node_crypto_1.webcrypto.subtle.decrypt({ name: 'AES-CTR', counter, length: 64 }, key, ciphertext));
|
|
121
110
|
}
|
|
@@ -1,32 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.randomIntAsync = void 0;
|
|
3
4
|
exports.randomBytesAsync = randomBytesAsync;
|
|
4
|
-
exports.
|
|
5
|
+
exports.randomFillAsync = randomFillAsync;
|
|
5
6
|
const node_crypto_1 = require("node:crypto");
|
|
7
|
+
const node_util_1 = require("node:util");
|
|
6
8
|
const bytes_1 = require("../../util/bytes");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return new Promise((resolve, reject) => {
|
|
12
|
-
(0, node_crypto_1.randomBytes)(size, (error, buffer) => {
|
|
13
|
-
if (error)
|
|
14
|
-
reject(error);
|
|
15
|
-
else
|
|
16
|
-
resolve((0, bytes_1.toBytesView)(buffer));
|
|
17
|
-
});
|
|
18
|
-
});
|
|
9
|
+
const randomBytesAsyncImpl = (0, node_util_1.promisify)(node_crypto_1.randomBytes);
|
|
10
|
+
const randomIntAsyncImpl = (0, node_util_1.promisify)(node_crypto_1.randomInt);
|
|
11
|
+
async function randomBytesAsync(size) {
|
|
12
|
+
return (0, bytes_1.toBytesView)(await randomBytesAsyncImpl(size));
|
|
19
13
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return new Promise((resolve, reject) => {
|
|
25
|
-
(0, node_crypto_1.randomInt)(min, max, (error, value) => {
|
|
26
|
-
if (error)
|
|
14
|
+
async function randomFillAsync(target, offset, size) {
|
|
15
|
+
await new Promise((resolve, reject) => {
|
|
16
|
+
const onDone = (error) => {
|
|
17
|
+
if (error) {
|
|
27
18
|
reject(error);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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);
|
|
31
32
|
});
|
|
33
|
+
return target;
|
|
32
34
|
}
|
|
35
|
+
exports.randomIntAsync = randomIntAsyncImpl;
|