zapo-js 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -3
- package/dist/appstate/WaAppStateCrypto.js +49 -41
- package/dist/appstate/WaAppStateSyncClient.js +79 -42
- package/dist/appstate/index.js +2 -2
- package/dist/auth/WaAuthClient.js +20 -11
- package/dist/auth/{flow/WaAuthCredentialsFlow.js → credentials-flow.js} +83 -18
- package/dist/auth/pairing/WaPairingFlow.js +26 -29
- package/dist/auth/pairing/{WaPairingCodeCrypto.js → pairing-code-crypto.js} +29 -13
- package/dist/client/WaClient.js +115 -75
- package/dist/client/WaClientFactory.js +113 -30
- package/dist/client/connection/WaConnectionManager.js +4 -1
- package/dist/client/coordinators/WaAbPropsCoordinator.js +141 -0
- package/dist/client/coordinators/WaBusinessCoordinator.js +3 -12
- package/dist/client/coordinators/WaEmailCoordinator.js +63 -0
- package/dist/client/coordinators/WaIncomingNodeCoordinator.js +33 -8
- package/dist/client/coordinators/WaMessageDispatchCoordinator.js +55 -25
- package/dist/client/coordinators/WaOfflineResumeCoordinator.js +114 -0
- package/dist/client/coordinators/WaPassiveTasksCoordinator.js +38 -20
- package/dist/client/coordinators/WaProfileCoordinator.js +3 -1
- package/dist/client/coordinators/WaRetryCoordinator.js +11 -9
- package/dist/client/coordinators/WaTrustedContactTokenCoordinator.js +22 -4
- package/dist/client/dirty.js +1 -1
- package/dist/client/events/abprops.js +43 -0
- package/dist/client/events/privacy-token.js +1 -2
- package/dist/client/events/registration.js +42 -0
- package/dist/client/incoming.js +37 -0
- package/dist/client/mailbox.js +17 -1
- package/dist/client/media.js +243 -0
- package/dist/client/messages.js +163 -86
- package/dist/crypto/core/index.js +4 -1
- package/dist/crypto/core/random.js +3 -9
- package/dist/crypto/core/xeddsa.js +57 -0
- package/dist/crypto/curves/X25519.js +18 -0
- package/dist/crypto/curves/constants.js +2 -1
- package/dist/esm/appstate/WaAppStateCrypto.js +39 -31
- package/dist/esm/appstate/WaAppStateSyncClient.js +68 -31
- package/dist/esm/appstate/index.js +1 -1
- package/dist/esm/appstate/{WaAppStateSyncResponseParser.js → response-parser.js} +1 -1
- package/dist/esm/auth/WaAuthClient.js +17 -8
- package/dist/esm/auth/{flow/WaAuthCredentialsFlow.js → credentials-flow.js} +83 -18
- package/dist/esm/auth/pairing/WaPairingFlow.js +25 -28
- package/dist/esm/auth/pairing/{WaPairingCodeCrypto.js → pairing-code-crypto.js} +20 -6
- package/dist/esm/client/WaClient.js +116 -76
- package/dist/esm/client/WaClientFactory.js +114 -31
- package/dist/esm/client/connection/WaConnectionManager.js +4 -1
- package/dist/esm/client/coordinators/WaAbPropsCoordinator.js +137 -0
- package/dist/esm/client/coordinators/WaBusinessCoordinator.js +4 -13
- package/dist/esm/client/coordinators/WaEmailCoordinator.js +60 -0
- package/dist/esm/client/coordinators/WaIncomingNodeCoordinator.js +35 -10
- package/dist/esm/client/coordinators/WaMessageDispatchCoordinator.js +47 -17
- package/dist/esm/client/coordinators/WaOfflineResumeCoordinator.js +110 -0
- package/dist/esm/client/coordinators/WaPassiveTasksCoordinator.js +38 -20
- package/dist/esm/client/coordinators/WaProfileCoordinator.js +3 -1
- package/dist/esm/client/coordinators/WaRetryCoordinator.js +11 -9
- package/dist/esm/client/coordinators/WaTrustedContactTokenCoordinator.js +24 -6
- package/dist/esm/client/dirty.js +1 -1
- package/dist/esm/client/events/abprops.js +40 -0
- package/dist/esm/client/events/privacy-token.js +1 -2
- package/dist/esm/client/events/registration.js +39 -0
- package/dist/esm/client/incoming.js +36 -0
- package/dist/esm/client/mailbox.js +17 -1
- package/dist/esm/client/media.js +234 -0
- package/dist/esm/client/messages.js +162 -85
- package/dist/esm/crypto/core/index.js +1 -0
- package/dist/esm/crypto/core/random.js +2 -7
- package/dist/esm/crypto/core/xeddsa.js +53 -0
- package/dist/esm/crypto/curves/X25519.js +20 -2
- package/dist/esm/crypto/curves/constants.js +1 -0
- package/dist/esm/infra/perf/StoreLock.js +7 -4
- package/dist/esm/media/WaMediaCrypto.js +257 -62
- package/dist/esm/media/WaMediaTransferClient.js +47 -190
- package/dist/esm/media/constants.js +2 -0
- package/dist/esm/media/processor.js +1 -0
- package/dist/esm/message/addon-crypto.js +130 -3
- package/dist/esm/message/content.js +12 -6
- package/dist/esm/message/icdc.js +8 -8
- package/dist/esm/message/incoming.js +14 -12
- package/dist/esm/message/phash.js +32 -12
- package/dist/esm/message/reporting-token.js +3 -3
- package/dist/esm/message/use-case-secret.js +1 -1
- package/dist/esm/protocol/abprops.js +159 -0
- package/dist/esm/protocol/browser.js +14 -0
- package/dist/esm/protocol/constants.js +3 -1
- package/dist/esm/protocol/email.js +30 -0
- package/dist/esm/protocol/jid.js +44 -10
- package/dist/esm/protocol/nodes.js +6 -2
- package/dist/esm/protocol/notification.js +7 -1
- package/dist/esm/retry/reason.js +1 -1
- package/dist/esm/signal/api/SignalDeviceSyncApi.js +5 -2
- package/dist/esm/signal/api/SignalDigestSyncApi.js +8 -6
- package/dist/esm/signal/api/SignalIdentitySyncApi.js +4 -4
- package/dist/esm/signal/api/SignalMissingPreKeysSyncApi.js +1 -1
- package/dist/esm/signal/api/SignalSessionSyncApi.js +1 -1
- package/dist/esm/signal/crypto/WaAdvSignature.js +5 -51
- package/dist/esm/signal/crypto/constants.js +0 -4
- package/dist/esm/signal/encoding.js +11 -54
- package/dist/esm/signal/group/SenderKeyChain.js +3 -3
- package/dist/esm/signal/group/SenderKeyCodec.js +5 -6
- package/dist/esm/signal/group/SenderKeyManager.js +13 -10
- package/dist/esm/signal/registration/keygen.js +2 -3
- package/dist/esm/signal/registration/utils.js +2 -2
- package/dist/esm/signal/session/SignalProtocol.js +18 -17
- package/dist/esm/signal/session/SignalRatchet.js +21 -10
- package/dist/esm/signal/session/SignalSerializer.js +5 -6
- package/dist/esm/signal/session/SignalSession.js +11 -9
- package/dist/esm/signal/session/resolver.js +6 -6
- package/dist/esm/store/contracts/identity.store.js +1 -0
- package/dist/esm/store/contracts/message-secret.store.js +1 -0
- package/dist/esm/store/contracts/pre-key.store.js +1 -0
- package/dist/esm/store/contracts/session.store.js +1 -0
- package/dist/esm/store/createStore.js +48 -12
- package/dist/esm/store/index.js +4 -0
- package/dist/esm/store/locks/identity.lock.js +16 -0
- package/dist/esm/store/locks/message-secret.lock.js +17 -0
- package/dist/esm/store/locks/pre-key.lock.js +27 -0
- package/dist/esm/store/locks/session.lock.js +19 -0
- package/dist/esm/store/locks/signal.lock.js +0 -24
- package/dist/esm/store/noop.store.js +20 -0
- package/dist/esm/store/providers/memory/device-list.store.js +3 -0
- package/dist/esm/store/providers/memory/identity.store.js +31 -0
- package/dist/esm/store/providers/memory/message-secret.store.js +81 -0
- package/dist/esm/store/providers/memory/participants.store.js +3 -0
- package/dist/esm/store/providers/memory/pre-key.store.js +97 -0
- package/dist/esm/store/providers/memory/retry.store.js +25 -11
- package/dist/esm/store/providers/memory/session.store.js +45 -0
- package/dist/esm/store/providers/memory/signal.store.js +1 -164
- package/dist/esm/transport/WaComms.js +4 -3
- package/dist/esm/transport/WaWebSocket.js +9 -1
- package/dist/esm/transport/index.js +6 -0
- package/dist/esm/transport/keepalive/WaKeepAlive.js +17 -8
- package/dist/esm/transport/node/WaMobileTcpSocket.js +114 -0
- package/dist/esm/transport/node/WaNodeOrchestrator.js +17 -8
- package/dist/esm/transport/node/builders/abprops.js +20 -0
- package/dist/esm/transport/node/builders/device.js +11 -0
- package/dist/esm/transport/node/builders/email.js +65 -0
- package/dist/esm/transport/node/builders/offline.js +14 -0
- package/dist/esm/transport/node/builders/prekeys.js +37 -40
- package/dist/esm/transport/node/builders/presence.js +13 -0
- package/dist/esm/transport/node/builders/privacy-token.js +19 -23
- package/dist/esm/transport/node/builders/retry.js +1 -1
- package/dist/esm/transport/node/helpers.js +24 -0
- package/dist/esm/transport/node/mex/argo-decoder.js +152 -0
- package/dist/esm/transport/node/mex/client.js +83 -0
- package/dist/esm/transport/node/mex/persist-ids.js +10 -0
- package/dist/esm/transport/noise/WaClientPayload.js +15 -10
- package/dist/esm/transport/noise/WaFrameCodec.js +2 -2
- package/dist/esm/transport/noise/WaMobileClientPayload.js +53 -0
- package/dist/esm/transport/noise/WaNoiseCert.js +9 -27
- package/dist/esm/transport/noise/WaNoiseSession.js +12 -11
- package/dist/infra/perf/StoreLock.js +7 -4
- package/dist/media/WaMediaCrypto.js +253 -58
- package/dist/media/WaMediaTransferClient.js +50 -223
- package/dist/media/constants.js +3 -1
- package/dist/media/processor.js +2 -0
- package/dist/message/addon-crypto.js +131 -0
- package/dist/message/content.js +13 -5
- package/dist/message/icdc.js +8 -8
- package/dist/message/incoming.js +14 -12
- package/dist/message/phash.js +32 -12
- package/dist/message/reporting-token.js +2 -2
- package/dist/message/use-case-secret.js +1 -1
- package/dist/protocol/abprops.js +163 -0
- package/dist/protocol/browser.js +15 -0
- package/dist/protocol/constants.js +14 -2
- package/dist/protocol/email.js +33 -0
- package/dist/protocol/jid.js +45 -10
- package/dist/protocol/nodes.js +6 -2
- package/dist/protocol/notification.js +8 -2
- package/dist/retry/reason.js +1 -1
- package/dist/signal/api/SignalDeviceSyncApi.js +5 -2
- package/dist/signal/api/SignalDigestSyncApi.js +8 -6
- package/dist/signal/api/SignalIdentitySyncApi.js +4 -4
- package/dist/signal/crypto/WaAdvSignature.js +2 -50
- package/dist/signal/crypto/constants.js +1 -5
- package/dist/signal/encoding.js +11 -49
- package/dist/signal/group/SenderKeyChain.js +2 -2
- package/dist/signal/group/SenderKeyCodec.js +4 -5
- package/dist/signal/group/SenderKeyManager.js +12 -9
- package/dist/signal/registration/keygen.js +1 -2
- package/dist/signal/registration/utils.js +2 -2
- package/dist/signal/session/SignalProtocol.js +18 -17
- package/dist/signal/session/SignalRatchet.js +19 -8
- package/dist/signal/session/SignalSerializer.js +5 -6
- package/dist/signal/session/SignalSession.js +11 -9
- package/dist/signal/session/resolver.js +6 -6
- package/dist/store/contracts/identity.store.js +2 -0
- package/dist/store/contracts/message-secret.store.js +2 -0
- package/dist/store/contracts/pre-key.store.js +2 -0
- package/dist/store/contracts/session.store.js +2 -0
- package/dist/store/createStore.js +47 -11
- package/dist/store/index.js +9 -1
- package/dist/store/locks/identity.lock.js +19 -0
- package/dist/store/locks/message-secret.lock.js +20 -0
- package/dist/store/locks/pre-key.lock.js +30 -0
- package/dist/store/locks/session.lock.js +22 -0
- package/dist/store/locks/signal.lock.js +0 -24
- package/dist/store/noop.store.js +21 -1
- package/dist/store/providers/memory/device-list.store.js +3 -0
- package/dist/store/providers/memory/identity.store.js +35 -0
- package/dist/store/providers/memory/message-secret.store.js +85 -0
- package/dist/store/providers/memory/participants.store.js +3 -0
- package/dist/store/providers/memory/pre-key.store.js +101 -0
- package/dist/store/providers/memory/retry.store.js +24 -10
- package/dist/store/providers/memory/session.store.js +49 -0
- package/dist/store/providers/memory/signal.store.js +1 -164
- package/dist/transport/WaComms.js +4 -3
- package/dist/transport/WaWebSocket.js +9 -1
- package/dist/transport/index.js +17 -1
- package/dist/transport/keepalive/WaKeepAlive.js +17 -8
- package/dist/transport/node/WaMobileTcpSocket.js +118 -0
- package/dist/transport/node/WaNodeOrchestrator.js +16 -7
- package/dist/transport/node/builders/abprops.js +23 -0
- package/dist/transport/node/builders/device.js +14 -0
- package/dist/transport/node/builders/email.js +72 -0
- package/dist/transport/node/builders/offline.js +17 -0
- package/dist/transport/node/builders/prekeys.js +36 -39
- package/dist/transport/node/builders/presence.js +16 -0
- package/dist/transport/node/builders/privacy-token.js +18 -22
- package/dist/transport/node/builders/retry.js +1 -1
- package/dist/transport/node/helpers.js +26 -0
- package/dist/transport/node/mex/argo-decoder.js +189 -0
- package/dist/transport/node/mex/client.js +86 -0
- package/dist/transport/node/mex/persist-ids.js +13 -0
- package/dist/transport/noise/WaClientPayload.js +14 -9
- package/dist/transport/noise/WaFrameCodec.js +1 -1
- package/dist/transport/noise/WaMobileClientPayload.js +56 -0
- package/dist/transport/noise/WaNoiseCert.js +8 -26
- package/dist/transport/noise/WaNoiseSession.js +11 -10
- package/dist/types/appstate/WaAppStateCrypto.d.ts +11 -8
- package/dist/types/appstate/WaAppStateSyncClient.d.ts +6 -2
- package/dist/types/appstate/index.d.ts +1 -1
- package/dist/types/appstate/{WaAppStateSyncResponseParser.d.ts → response-parser.d.ts} +1 -1
- package/dist/types/appstate/types.d.ts +1 -1
- package/dist/types/auth/WaAuthClient.d.ts +9 -3
- package/dist/types/auth/credentials-flow.d.ts +20 -0
- package/dist/types/auth/pairing/WaPairingFlow.d.ts +3 -2
- package/dist/types/auth/pairing/{WaPairingCodeCrypto.d.ts → pairing-code-crypto.d.ts} +6 -1
- package/dist/types/auth/types.d.ts +40 -0
- package/dist/types/client/WaClient.d.ts +19 -8
- package/dist/types/client/WaClientFactory.d.ts +10 -4
- package/dist/types/client/coordinators/WaAbPropsCoordinator.d.ts +26 -0
- package/dist/types/client/coordinators/WaBusinessCoordinator.d.ts +1 -1
- package/dist/types/client/coordinators/WaEmailCoordinator.d.ts +24 -0
- package/dist/types/client/coordinators/WaIncomingNodeCoordinator.d.ts +6 -1
- package/dist/types/client/coordinators/WaMessageDispatchCoordinator.d.ts +15 -2
- package/dist/types/client/coordinators/WaOfflineResumeCoordinator.d.ts +31 -0
- package/dist/types/client/coordinators/WaPassiveTasksCoordinator.d.ts +13 -2
- package/dist/types/client/coordinators/WaPrivacyCoordinator.d.ts +1 -1
- package/dist/types/client/coordinators/WaProfileCoordinator.d.ts +4 -2
- package/dist/types/client/coordinators/WaRetryCoordinator.d.ts +6 -0
- package/dist/types/client/coordinators/WaTrustedContactTokenCoordinator.d.ts +11 -1
- package/dist/types/client/dirty.d.ts +3 -1
- package/dist/types/client/events/abprops.d.ts +14 -0
- package/dist/types/client/events/registration.d.ts +17 -0
- package/dist/types/client/incoming.d.ts +6 -1
- package/dist/types/client/mailbox.d.ts +2 -0
- package/dist/types/client/media.d.ts +31 -0
- package/dist/types/client/messages.d.ts +2 -0
- package/dist/types/client/persistence/WriteBehindPersistence.d.ts +1 -1
- package/dist/types/client/types.d.ts +100 -1
- package/dist/types/crypto/core/index.d.ts +1 -0
- package/dist/types/crypto/core/primitives.d.ts +1 -1
- package/dist/types/crypto/core/random.d.ts +1 -1
- package/dist/types/crypto/core/xeddsa.d.ts +2 -0
- package/dist/types/crypto/curves/constants.d.ts +1 -0
- package/dist/types/crypto/index.d.ts +1 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/infra/log/ConsoleLogger.d.ts +1 -1
- package/dist/types/infra/log/PinoLogger.d.ts +1 -1
- package/dist/types/infra/perf/StoreLock.d.ts +1 -0
- package/dist/types/media/WaMediaCrypto.d.ts +15 -6
- package/dist/types/media/WaMediaTransferClient.d.ts +3 -11
- package/dist/types/media/constants.d.ts +2 -0
- package/dist/types/media/index.d.ts +1 -0
- package/dist/types/media/processor.d.ts +28 -0
- package/dist/types/media/types.d.ts +9 -3
- package/dist/types/message/addon-crypto.d.ts +34 -3
- package/dist/types/message/content.d.ts +3 -1
- package/dist/types/message/icdc.d.ts +4 -4
- package/dist/types/message/types.d.ts +16 -24
- package/dist/types/protocol/abprops.d.ts +142 -0
- package/dist/types/protocol/browser.d.ts +1 -0
- package/dist/types/protocol/constants.d.ts +5 -1
- package/dist/types/protocol/email.d.ts +32 -0
- package/dist/types/protocol/jid.d.ts +1 -0
- package/dist/types/protocol/nodes.d.ts +4 -0
- package/dist/types/protocol/notification.d.ts +6 -0
- package/dist/types/protocol/stream.d.ts +1 -0
- package/dist/types/retry/reason.d.ts +1 -1
- package/dist/types/signal/api/SignalDigestSyncApi.d.ts +3 -0
- package/dist/types/signal/api/SignalIdentitySyncApi.d.ts +3 -3
- package/dist/types/signal/crypto/WaAdvSignature.d.ts +0 -2
- package/dist/types/signal/crypto/constants.d.ts +0 -1
- package/dist/types/signal/encoding.d.ts +7 -1
- package/dist/types/signal/group/SenderKeyChain.d.ts +1 -1
- package/dist/types/signal/group/SenderKeyManager.d.ts +7 -2
- package/dist/types/signal/registration/utils.d.ts +2 -1
- package/dist/types/signal/session/SignalProtocol.d.ts +11 -2
- package/dist/types/signal/session/SignalSerializer.d.ts +2 -1
- package/dist/types/signal/session/resolver.d.ts +4 -2
- package/dist/types/signal/types.d.ts +16 -4
- package/dist/types/store/contracts/identity.store.d.ts +11 -0
- package/dist/types/store/contracts/message-secret.store.d.ts +16 -0
- package/dist/types/store/contracts/pre-key.store.d.ts +13 -0
- package/dist/types/store/contracts/session.store.d.ts +14 -0
- package/dist/types/store/contracts/signal.store.d.ts +1 -34
- package/dist/types/store/index.d.ts +9 -1
- package/dist/types/store/locks/identity.lock.d.ts +3 -0
- package/dist/types/store/locks/message-secret.lock.d.ts +3 -0
- package/dist/types/store/locks/pre-key.lock.d.ts +3 -0
- package/dist/types/store/locks/session.lock.d.ts +3 -0
- package/dist/types/store/noop.store.d.ts +4 -0
- package/dist/types/store/providers/memory/identity.store.d.ts +18 -0
- package/dist/types/store/providers/memory/message-secret.store.d.ts +21 -0
- package/dist/types/store/providers/memory/pre-key.store.d.ts +23 -0
- package/dist/types/store/providers/memory/retry.store.d.ts +7 -1
- package/dist/types/store/providers/memory/session.store.d.ts +21 -0
- package/dist/types/store/providers/memory/signal.store.d.ts +3 -45
- package/dist/types/store/providers/memory/thread.store.d.ts +1 -1
- package/dist/types/store/types.d.ts +21 -1
- package/dist/types/transport/WaWebSocket.d.ts +1 -0
- package/dist/types/transport/index.d.ts +8 -1
- package/dist/types/transport/keepalive/WaKeepAlive.d.ts +4 -1
- package/dist/types/transport/node/WaMobileTcpSocket.d.ts +18 -0
- package/dist/types/transport/node/WaNodeOrchestrator.d.ts +6 -2
- package/dist/types/transport/node/builders/abprops.d.ts +5 -0
- package/dist/types/transport/node/builders/device.d.ts +2 -0
- package/dist/types/transport/node/builders/email.d.ts +11 -0
- package/dist/types/transport/node/builders/offline.d.ts +2 -0
- package/dist/types/transport/node/builders/prekeys.d.ts +4 -3
- package/dist/types/transport/node/builders/presence.d.ts +6 -0
- package/dist/types/transport/node/helpers.d.ts +3 -0
- package/dist/types/transport/node/mex/argo-decoder.d.ts +11 -0
- package/dist/types/transport/node/mex/client.d.ts +18 -0
- package/dist/types/transport/node/mex/persist-ids.d.ts +14 -0
- package/dist/types/transport/noise/WaMobileClientPayload.d.ts +29 -0
- package/dist/types/transport/noise/WaNoiseCert.d.ts +7 -1
- package/dist/types/transport/noise/WaNoiseSession.d.ts +1 -0
- package/dist/types/transport/types.d.ts +8 -0
- package/package.json +6 -4
- package/dist/auth/pairing/constants.js +0 -5
- package/dist/client/connection/WaKeyShareCoordinator.js +0 -63
- package/dist/esm/auth/pairing/constants.js +0 -2
- package/dist/esm/client/connection/WaKeyShareCoordinator.js +0 -59
- package/dist/esm/transport/node/builders/index.js +0 -11
- package/dist/transport/node/builders/index.js +0 -51
- package/dist/types/auth/flow/WaAuthCredentialsFlow.d.ts +0 -14
- package/dist/types/auth/pairing/constants.d.ts +0 -2
- package/dist/types/client/connection/WaKeyShareCoordinator.d.ts +0 -14
- package/dist/types/transport/node/builders/index.d.ts +0 -11
- /package/dist/appstate/{WaAppStateSyncResponseParser.js → response-parser.js} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { hkdf, hmacSign, importHmacKey } from '../crypto/index.js';
|
|
2
2
|
import { proto } from '../proto.js';
|
|
3
|
-
import { base64ToBytesChecked, concatBytes, EMPTY_BYTES, TEXT_ENCODER
|
|
3
|
+
import { base64ToBytesChecked, concatBytes, EMPTY_BYTES, TEXT_ENCODER } from '../util/bytes.js';
|
|
4
4
|
const WA_REPORTING_TOKEN_BYTES = 16;
|
|
5
5
|
const WA_REPORTING_TOKEN_KEY_BYTES = 32;
|
|
6
6
|
const WA_REPORTING_TOKEN_USE_CASE = 'Report Token';
|
|
@@ -15,7 +15,7 @@ export async function buildReportingTokenArtifacts(input) {
|
|
|
15
15
|
return null;
|
|
16
16
|
}
|
|
17
17
|
const messageSecret = input.message.messageContextInfo?.messageSecret;
|
|
18
|
-
if (!messageSecret ||
|
|
18
|
+
if (!messageSecret || messageSecret.byteLength === 0) {
|
|
19
19
|
return null;
|
|
20
20
|
}
|
|
21
21
|
const reportingTokenContent = computeReportingTokenContent(proto.Message.encode(input.message).finish(), input.version ?? WA_REPORTING_TOKEN_VERSION);
|
|
@@ -23,7 +23,7 @@ export async function buildReportingTokenArtifacts(input) {
|
|
|
23
23
|
return null;
|
|
24
24
|
}
|
|
25
25
|
const secretInfo = TEXT_ENCODER.encode(stanzaId + input.senderUserJid + input.remoteJid + WA_REPORTING_TOKEN_USE_CASE);
|
|
26
|
-
const reportingTokenKey = await hkdf(
|
|
26
|
+
const reportingTokenKey = await hkdf(messageSecret, null, secretInfo, WA_REPORTING_TOKEN_KEY_BYTES);
|
|
27
27
|
const hmacKey = await importHmacKey(reportingTokenKey);
|
|
28
28
|
const reportingToken = (await hmacSign(hmacKey, reportingTokenContent)).subarray(0, WA_REPORTING_TOKEN_BYTES);
|
|
29
29
|
const version = input.version ?? WA_REPORTING_TOKEN_VERSION;
|
|
@@ -19,7 +19,7 @@ export function assertMessageSecret(messageSecret, context = 'message secret') {
|
|
|
19
19
|
}
|
|
20
20
|
export async function ensureMessageSecret(message) {
|
|
21
21
|
const messageSecret = message.messageContextInfo?.messageSecret;
|
|
22
|
-
if (messageSecret &&
|
|
22
|
+
if (messageSecret && messageSecret.byteLength > 0) {
|
|
23
23
|
return message;
|
|
24
24
|
}
|
|
25
25
|
const generatedMessageSecret = await randomBytesAsync(WA_MESSAGE_SECRET_BYTES);
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
export const WA_ABPROPS_PROTOCOL_VERSION = '1';
|
|
2
|
+
export const WA_ABPROPS_REFRESH_BOUNDS = Object.freeze({
|
|
3
|
+
MIN_S: 600,
|
|
4
|
+
MAX_S: 604800,
|
|
5
|
+
DEFAULT_S: 86400
|
|
6
|
+
});
|
|
7
|
+
function prop(configCode, type, defaultValue) {
|
|
8
|
+
return { configCode, type, defaultValue };
|
|
9
|
+
}
|
|
10
|
+
export const AB_PROP_CONFIGS = Object.freeze({
|
|
11
|
+
// --- app state sync (syncd) ---
|
|
12
|
+
syncd_key_max_use_days: prop(5498, 'int', 90),
|
|
13
|
+
syncd_wait_for_key_timeout_days: prop(5499, 'int', 30),
|
|
14
|
+
syncd_sentinel_timeout_seconds: prop(5500, 'int', 60),
|
|
15
|
+
syncd_inline_mutations_max_count: prop(5501, 'int', 1000),
|
|
16
|
+
syncd_patch_protobuf_max_size: prop(5502, 'int', 1048576),
|
|
17
|
+
syncd_additional_mutations_count: prop(2777, 'int', 1),
|
|
18
|
+
syncd_periodic_sync_days: prop(1400, 'int', 0),
|
|
19
|
+
syncd_mutation_and_bundle_logging: prop(11821, 'string', '{"allowlist": []}'),
|
|
20
|
+
wa_web_enable_syncd_key_persistence_only_after_server_ack: prop(27069, 'bool', false),
|
|
21
|
+
web_request_missing_keys_for_removes: prop(11695, 'bool', false),
|
|
22
|
+
web_syncd_max_mutations_to_process_during_resume: prop(15808, 'int', 10000),
|
|
23
|
+
web_syncd_fatal_fields_from_L1104589PRV2: prop(1808, 'bool', false),
|
|
24
|
+
web_enable_improved_bulk_merge: prop(19854, 'bool', false),
|
|
25
|
+
snapshot_recovery_max_mutations_count_allowed: prop(18786, 'int', 2000),
|
|
26
|
+
md_syncd_logging_spec_enabled: prop(14499, 'bool', false),
|
|
27
|
+
kmp_syncd_engine_crypto_enabled: prop(15909, 'bool', false),
|
|
28
|
+
enable_syncd_debug_data_in_patch: prop(6614, 'bool', false),
|
|
29
|
+
enable_mention_everyone_syncd_sender: prop(24244, 'bool', false),
|
|
30
|
+
username_contact_syncd_support_enable: prop(17614, 'bool', false),
|
|
31
|
+
// --- message sending / encryption ---
|
|
32
|
+
after_read_sending_enabled: prop(7293, 'bool', false),
|
|
33
|
+
after_read_fallback_duration: prop(7294, 'int', 86400),
|
|
34
|
+
after_read_receiver_enabled: prop(7295, 'bool', false),
|
|
35
|
+
privacy_token_sending_on_all_1_on_1_messages: prop(9281, 'bool', false),
|
|
36
|
+
flows_termination_message_v2_sending_enabled: prop(9157, 'bool', false),
|
|
37
|
+
dm_initiator_trigger_groups: prop(7141, 'bool', false),
|
|
38
|
+
placeholder_message_resend_maximum_days_limit: prop(3639, 'int', 14),
|
|
39
|
+
message_edit_to_message_secret_sender_enabled: prop(16057, 'bool', false),
|
|
40
|
+
message_edit_to_message_secret_receiver_enabled: prop(17811, 'bool', false),
|
|
41
|
+
top_level_message_secret_check: prop(23796, 'bool', false),
|
|
42
|
+
parse_encrypted_dsm_msg_fix: prop(26772, 'bool', false),
|
|
43
|
+
rt_sender_dual_encrypted_msg_enabled: prop(12623, 'bool', true),
|
|
44
|
+
rt_receiver_dual_encrypted_msg_enabled: prop(15258, 'bool', true),
|
|
45
|
+
lid_one_to_one_migration_event_response_force_pn_jid: prop(15791, 'bool', false),
|
|
46
|
+
web_anr_async_msg_send_handler: prop(27249, 'bool', false),
|
|
47
|
+
message_keys_async_chunk_size: prop(22815, 'int', 50),
|
|
48
|
+
synced_message_keys_processing_type: prop(22825, 'string', 'control'),
|
|
49
|
+
limit_sharing_protocol_message_receiver_enabled: prop(15129, 'bool', false),
|
|
50
|
+
web_pnless_stanzas: prop(26211, 'bool', false),
|
|
51
|
+
// --- NCT tokens ---
|
|
52
|
+
wa_nct_token_send_enabled: prop(24941, 'bool', false),
|
|
53
|
+
wa_nct_token_syncd_enabled: prop(25253, 'bool', false),
|
|
54
|
+
wa_nct_token_history_sync_enabled: prop(25189, 'bool', false),
|
|
55
|
+
// --- group ---
|
|
56
|
+
community_announcement_group_size_limit: prop(2774, 'int', 5000),
|
|
57
|
+
group_size_limit: prop(1304, 'int', 257),
|
|
58
|
+
group_max_subject: prop(3597, 'int', 100),
|
|
59
|
+
group_description_length: prop(14778, 'int', 2048),
|
|
60
|
+
anyone_can_link_to_groups: prop(3978, 'bool', false),
|
|
61
|
+
group_call_max_participants: prop(4190, 'int', 32),
|
|
62
|
+
group_history_receive: prop(15311, 'bool', false),
|
|
63
|
+
group_history_send: prop(15313, 'bool', false),
|
|
64
|
+
group_history_settings: prop(21261, 'bool', false),
|
|
65
|
+
group_history_settings_query: prop(22230, 'bool', false),
|
|
66
|
+
group_history_message_count_limit: prop(18405, 'int', 100),
|
|
67
|
+
group_history_message_count_receiver_upper_limit: prop(19811, 'int', 100),
|
|
68
|
+
group_history_messages_time_limit_receiver_enforcement_secs: prop(21313, 'int', 1209600),
|
|
69
|
+
group_history_bundle_time_limit_receiver_enforcement_secs: prop(25910, 'int', 1209600),
|
|
70
|
+
group_history_notice_receive: prop(15722, 'bool', false),
|
|
71
|
+
group_history_out_of_window_pin_sender: prop(26037, 'bool', false),
|
|
72
|
+
group_history_out_of_window_pins_receiver: prop(26039, 'bool', false),
|
|
73
|
+
group_history_reporting: prop(22329, 'bool', true),
|
|
74
|
+
group_create_add_using_lid_jids: prop(16192, 'bool', false),
|
|
75
|
+
group_member_updates_hide_in_thread_enabled: prop(24584, 'bool', false),
|
|
76
|
+
group_status_receiver_enabled: prop(13956, 'bool', false),
|
|
77
|
+
web_send_invisible_msg_max_group_size: prop(13289, 'int', 256),
|
|
78
|
+
web_send_invisible_msg_min_group_size: prop(13290, 'int', 50),
|
|
79
|
+
admin_only_mention_everyone_group_size: prop(18500, 'int', 0),
|
|
80
|
+
// --- history sync ---
|
|
81
|
+
web_abprop_drop_full_history_sync: prop(13034, 'bool', false),
|
|
82
|
+
wa_web_history_sync_dynamic_throttling: prop(19110, 'bool', true),
|
|
83
|
+
web_e2e_backfill_expire_time: prop(3234, 'int', 5),
|
|
84
|
+
history_sync_on_demand: prop(3337, 'bool', false),
|
|
85
|
+
history_sync_on_demand_message_count: prop(3811, 'int', 50),
|
|
86
|
+
history_sync_on_demand_failure_limit: prop(4364, 'int', 10),
|
|
87
|
+
history_sync_on_demand_cooldown_sec: prop(4365, 'int', 7200),
|
|
88
|
+
history_sync_on_demand_complete_companion: prop(21024, 'bool', false),
|
|
89
|
+
history_sync_on_demand_with_android_beta: prop(4135, 'bool', false),
|
|
90
|
+
web_anr_throttle_history_sync_db_writes: prop(19298, 'bool', false),
|
|
91
|
+
web_force_lid_chats_in_history: prop(24343, 'bool', false),
|
|
92
|
+
web_history_sync_allow_duplicate_in_bulk_error: prop(10842, 'bool', false),
|
|
93
|
+
// --- media ---
|
|
94
|
+
default_media_limit_mb: prop(3660, 'int', 16),
|
|
95
|
+
web_image_max_edge: prop(10371, 'int', 1600),
|
|
96
|
+
web_image_max_hd_edge: prop(3204, 'int', 2560),
|
|
97
|
+
web_channel_video_server_transcode_upload: prop(19920, 'bool', false),
|
|
98
|
+
web_deprecate_mms4_hash_based_download: prop(3152, 'bool', false),
|
|
99
|
+
kaleidoscope_thumbnail_validation: prop(18114, 'bool', false),
|
|
100
|
+
web_use_kaleidoscope_media_check_enabled: prop(20375, 'bool', false),
|
|
101
|
+
low_cache_hit_rate_media_types: prop(4836, 'string', 'ptt,audio,document,ppic'),
|
|
102
|
+
web_anr_async_media_decryption_enabled: prop(23200, 'bool', false),
|
|
103
|
+
web_anr_media_chunk_enc_delay_enabled: prop(22931, 'bool', false),
|
|
104
|
+
web_media_compute_in_worker_enabled: prop(25641, 'bool', false),
|
|
105
|
+
// --- device management / auth ---
|
|
106
|
+
adv_accept_hosted_devices: prop(6939, 'bool', false),
|
|
107
|
+
num_days_key_index_list_expiration: prop(730, 'int', 35),
|
|
108
|
+
num_days_before_device_expiry_check: prop(731, 'int', 7),
|
|
109
|
+
web_adv_logout_on_self_device_list_expired: prop(11011, 'bool', false),
|
|
110
|
+
md_icdc_hash_length: prop(310, 'int', 10),
|
|
111
|
+
noise_pq_mode: prop(20161, 'int', 0),
|
|
112
|
+
// --- trusted contacts / privacy tokens ---
|
|
113
|
+
tctoken_duration: prop(865, 'int', 604800),
|
|
114
|
+
tctoken_num_buckets: prop(909, 'int', 4),
|
|
115
|
+
tctoken_num_buckets_sender: prop(997, 'int', 4),
|
|
116
|
+
tctoken_duration_sender: prop(996, 'int', 604800),
|
|
117
|
+
// --- connection / offline ---
|
|
118
|
+
heartbeat_interval_s: prop(1430, 'int', 10),
|
|
119
|
+
web_offline_message_processor_timeout_seconds: prop(12834, 'int', 15),
|
|
120
|
+
web_offline_resume_wait_for_ping_response_enabled: prop(14567, 'bool', false),
|
|
121
|
+
web_offline_resume_wait_for_ping_timeout_seconds: prop(14568, 'int', 5),
|
|
122
|
+
web_comms_socket_reconnect_enabled: prop(7854, 'bool', false),
|
|
123
|
+
// --- receipts ---
|
|
124
|
+
web_resume_optimized_read_receipt_send_interval: prop(13978, 'int', 3000),
|
|
125
|
+
web_reaction_inactive_receipt: prop(25954, 'bool', false),
|
|
126
|
+
lid_status_non_soaked_client_support_enabled: prop(19696, 'bool', true),
|
|
127
|
+
// --- signal protocol ---
|
|
128
|
+
s567418_mitigation_enabled: prop(22029, 'bool', true),
|
|
129
|
+
web_signal_future_messages_max: prop(12509, 'int', 20000),
|
|
130
|
+
// --- polls ---
|
|
131
|
+
poll_add_option_enabled: prop(24517, 'bool', false),
|
|
132
|
+
poll_add_option_receiving_enabled: prop(25758, 'int', 0),
|
|
133
|
+
poll_creator_edit_enabled: prop(24887, 'bool', false),
|
|
134
|
+
poll_creator_edit_receiving_version: prop(24886, 'int', 0),
|
|
135
|
+
poll_end_time_enabled: prop(24405, 'bool', false),
|
|
136
|
+
poll_end_time_receiving_enabled: prop(24884, 'bool', false),
|
|
137
|
+
poll_hide_voters_enabled: prop(24518, 'bool', false),
|
|
138
|
+
poll_hide_voters_receiving_enabled: prop(24885, 'int', 0),
|
|
139
|
+
// --- status / ephemeral ---
|
|
140
|
+
text_status_ttl_seconds_allowlist: prop(6153, 'string', '1800,3600,7200,14400,28800,86400'),
|
|
141
|
+
// --- username ---
|
|
142
|
+
username_enabled_on_companion: prop(23817, 'bool', false),
|
|
143
|
+
username_max_length: prop(20459, 'int', 35),
|
|
144
|
+
username_min_length: prop(20494, 'int', 3),
|
|
145
|
+
// --- message capping ---
|
|
146
|
+
wa_individual_new_chat_msg_capping_enabled: prop(20865, 'bool', false),
|
|
147
|
+
wa_individual_new_chat_msg_capping_limit: prop(17845, 'int', 0),
|
|
148
|
+
wa_individual_new_chat_msg_capping_fetch_ttl_seconds: prop(20649, 'int', 3600),
|
|
149
|
+
// --- calling ---
|
|
150
|
+
enable_web_calling: prop(15461, 'bool', false),
|
|
151
|
+
calling_lid_version: prop(3358, 'int', 0)
|
|
152
|
+
});
|
|
153
|
+
const CONFIG_CODE_TO_NAME = new Map();
|
|
154
|
+
for (const [name, entry] of Object.entries(AB_PROP_CONFIGS)) {
|
|
155
|
+
CONFIG_CODE_TO_NAME.set(entry.configCode, name);
|
|
156
|
+
}
|
|
157
|
+
export function resolveAbPropNameByCode(configCode) {
|
|
158
|
+
return CONFIG_CODE_TO_NAME.get(configCode);
|
|
159
|
+
}
|
|
@@ -7,6 +7,8 @@ export const WA_BROWSERS = Object.freeze({
|
|
|
7
7
|
OPERA: 'opera',
|
|
8
8
|
EDGE: 'edge'
|
|
9
9
|
});
|
|
10
|
+
// Distinct from proto.DeviceProps.PlatformType: these are the string IDs sent
|
|
11
|
+
// as companionPlatformId in the pairing link_code XML stanza, not the proto enum.
|
|
10
12
|
export const WA_COMPANION_PLATFORM_IDS = Object.freeze({
|
|
11
13
|
UNKNOWN: '0',
|
|
12
14
|
CHROME: '1',
|
|
@@ -27,7 +29,19 @@ const BROWSER_TO_PLATFORM_ID = {
|
|
|
27
29
|
[WA_BROWSERS.SAFARI]: WA_COMPANION_PLATFORM_IDS.SAFARI,
|
|
28
30
|
[WA_BROWSERS.EDGE]: WA_COMPANION_PLATFORM_IDS.EDGE
|
|
29
31
|
};
|
|
32
|
+
const BROWSER_TO_DISPLAY_NAME = {
|
|
33
|
+
[WA_BROWSERS.CHROME]: 'Chrome',
|
|
34
|
+
[WA_BROWSERS.CHROMIUM]: 'Chromium',
|
|
35
|
+
[WA_BROWSERS.FIREFOX]: 'Firefox',
|
|
36
|
+
[WA_BROWSERS.IE]: 'IE',
|
|
37
|
+
[WA_BROWSERS.OPERA]: 'Opera',
|
|
38
|
+
[WA_BROWSERS.SAFARI]: 'Safari',
|
|
39
|
+
[WA_BROWSERS.EDGE]: 'Edge'
|
|
40
|
+
};
|
|
30
41
|
export function getWaCompanionPlatformId(browser) {
|
|
31
42
|
return (BROWSER_TO_PLATFORM_ID[browser.trim().toLowerCase()] ??
|
|
32
43
|
WA_COMPANION_PLATFORM_IDS.OTHER_WEB_CLIENT);
|
|
33
44
|
}
|
|
45
|
+
export function getWaBrowserDisplayName(browser) {
|
|
46
|
+
return BROWSER_TO_DISPLAY_NAME[browser.trim().toLowerCase()] ?? browser;
|
|
47
|
+
}
|
|
@@ -6,9 +6,11 @@ export { WA_EDIT_ATTRS, WA_ENC_MEDIA_TYPES, WA_EVENT_META_TYPES, WA_MESSAGE_TAGS
|
|
|
6
6
|
export { WA_APP_STATE_COLLECTIONS, WA_APP_STATE_COLLECTION_STATES, WA_APP_STATE_CHAT_MUTATION_SPECS, WA_APP_STATE_ERROR_CODES, WA_APP_STATE_KDF_INFO, WA_APP_STATE_KEY_TYPES, WA_APP_STATE_SYNC_DATA_TYPE } from './appstate.js';
|
|
7
7
|
export { getWaMediaHkdfInfo, WA_MEDIA_HKDF_INFO, WA_PREVIEW_MEDIA_HKDF_INFO } from './media.js';
|
|
8
8
|
export { WA_ACCOUNT_SYNC_PROTOCOLS, WA_DIRTY_PROTOCOLS, WA_DIRTY_TYPES, WA_SUPPORTED_DIRTY_TYPES } from './dirty.js';
|
|
9
|
-
export { WA_GROUP_NOTIFICATION_TAGS, WA_NOTIFICATION_TYPES } from './notification.js';
|
|
9
|
+
export { WA_GROUP_NOTIFICATION_TAGS, WA_NOTIFICATION_TYPES, WA_REGISTRATION_NOTIFICATION_TAGS } from './notification.js';
|
|
10
10
|
export { WA_PRIVACY_TOKEN_NOTIFICATION_TYPE, WA_PRIVACY_TOKEN_TAGS, WA_PRIVACY_TOKEN_TYPES, WA_TC_TOKEN_DEFAULTS } from './privacy-token.js';
|
|
11
11
|
export { WA_PRIVACY_CATEGORIES, WA_PRIVACY_CATEGORY_TO_SETTING, WA_PRIVACY_DISALLOWED_LIST_CATEGORIES, WA_PRIVACY_SETTING_TO_CATEGORY, WA_PRIVACY_TAGS, WA_PRIVACY_VALUES } from './privacy.js';
|
|
12
12
|
export { WA_DEFAULTS } from './defaults.js';
|
|
13
|
+
export { WA_EMAIL_CONTEXTS, WA_EMAIL_ERROR_CODES, WA_EMAIL_LIMITS, WA_EMAIL_TAGS, WA_EMAIL_XMLNS } from './email.js';
|
|
14
|
+
export { AB_PROP_CONFIGS, resolveAbPropNameByCode, WA_ABPROPS_PROTOCOL_VERSION, WA_ABPROPS_REFRESH_BOUNDS } from './abprops.js';
|
|
13
15
|
export { WA_GROUP_PARTICIPANT_TYPES } from './group.js';
|
|
14
16
|
export { WA_USYNC_CONTEXTS, WA_USYNC_DEFAULTS, WA_USYNC_MODES } from './usync.js';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export const WA_EMAIL_XMLNS = 'urn:xmpp:whatsapp:account';
|
|
2
|
+
export const WA_EMAIL_TAGS = Object.freeze({
|
|
3
|
+
EMAIL: 'email',
|
|
4
|
+
EMAIL_ADDRESS: 'email_address',
|
|
5
|
+
VERIFY_EMAIL: 'verify_email',
|
|
6
|
+
CONFIRM_EMAIL: 'confirm_email',
|
|
7
|
+
CONTEXT: 'context',
|
|
8
|
+
CODE: 'code',
|
|
9
|
+
LG: 'lg',
|
|
10
|
+
LC: 'lc',
|
|
11
|
+
AUTO_VERIFY: 'auto_verify',
|
|
12
|
+
CONFIRMED: 'confirmed'
|
|
13
|
+
});
|
|
14
|
+
export const WA_EMAIL_CONTEXTS = Object.freeze({
|
|
15
|
+
ONBOARDING: 'onboarding',
|
|
16
|
+
SETTINGS: 'settings'
|
|
17
|
+
});
|
|
18
|
+
export const WA_EMAIL_LIMITS = Object.freeze({
|
|
19
|
+
EMAIL_MAX_LENGTH: 320,
|
|
20
|
+
CODE_LENGTH: 6,
|
|
21
|
+
LOCALE_MIN_LENGTH: 2,
|
|
22
|
+
LOCALE_MAX_LENGTH: 3
|
|
23
|
+
});
|
|
24
|
+
export const WA_EMAIL_ERROR_CODES = Object.freeze({
|
|
25
|
+
FORBIDDEN: 403,
|
|
26
|
+
LOCKOUT: 534,
|
|
27
|
+
CODE_EXPIRED: 535,
|
|
28
|
+
CODE_INCORRECT: 536,
|
|
29
|
+
TOO_MANY_RETRIES: 537
|
|
30
|
+
});
|
package/dist/esm/protocol/jid.js
CHANGED
|
@@ -58,7 +58,13 @@ export function normalizeRecipientJid(to) {
|
|
|
58
58
|
}
|
|
59
59
|
function isJidType(jid, type) {
|
|
60
60
|
const atIndex = jid.length - type.length - 1;
|
|
61
|
-
return atIndex >= 1 &&
|
|
61
|
+
return (atIndex >= 1 &&
|
|
62
|
+
jid.charCodeAt(atIndex) === 64 &&
|
|
63
|
+
jid.indexOf('@') === atIndex &&
|
|
64
|
+
jid.endsWith(type));
|
|
65
|
+
}
|
|
66
|
+
export function isLidJid(jid) {
|
|
67
|
+
return isJidType(jid, WA_DEFAULTS.LID_SERVER);
|
|
62
68
|
}
|
|
63
69
|
export function isGroupJid(jid) {
|
|
64
70
|
return isJidType(jid, WA_DEFAULTS.GROUP_SERVER);
|
|
@@ -76,9 +82,17 @@ export function parseSignalAddressFromJid(jid) {
|
|
|
76
82
|
if (colonIndex === -1 || colonIndex > atIndex) {
|
|
77
83
|
return { user: jid.slice(0, atIndex), server, device: 0 };
|
|
78
84
|
}
|
|
79
|
-
|
|
80
|
-
if (!Number.isFinite(device) || device < 0)
|
|
85
|
+
if (colonIndex >= atIndex - 1)
|
|
81
86
|
throw new Error(`invalid jid device: ${jid}`);
|
|
87
|
+
let device = 0;
|
|
88
|
+
for (let i = colonIndex + 1; i < atIndex; i += 1) {
|
|
89
|
+
const digit = jid.charCodeAt(i) - 48;
|
|
90
|
+
if (digit < 0 || digit > 9)
|
|
91
|
+
throw new Error(`invalid jid device: ${jid}`);
|
|
92
|
+
device = device * 10 + digit;
|
|
93
|
+
if (device > Number.MAX_SAFE_INTEGER)
|
|
94
|
+
throw new Error(`invalid jid device: ${jid}`);
|
|
95
|
+
}
|
|
82
96
|
return { user: jid.slice(0, colonIndex), server, device };
|
|
83
97
|
}
|
|
84
98
|
export function parseJidFull(jid) {
|
|
@@ -102,8 +116,18 @@ export function canonicalizeSignalJid(jid, hostDomain = WA_DEFAULTS.HOST_DOMAIN)
|
|
|
102
116
|
return `${address.user}:${address.device}@${server}`;
|
|
103
117
|
}
|
|
104
118
|
export function toUserJid(jid, options = {}) {
|
|
119
|
+
const canonicalize = options.canonicalizeSignalServer === true;
|
|
120
|
+
if (!canonicalize) {
|
|
121
|
+
const atIndex = jid.indexOf('@');
|
|
122
|
+
if (atIndex >= 1 && atIndex < jid.length - 1) {
|
|
123
|
+
const colonIndex = jid.indexOf(':', 0);
|
|
124
|
+
if (colonIndex === -1 || colonIndex > atIndex) {
|
|
125
|
+
return jid;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
105
129
|
const address = parseSignalAddressFromJid(jid);
|
|
106
|
-
const server =
|
|
130
|
+
const server = canonicalize
|
|
107
131
|
? canonicalizeSignalServer(address.server ?? WA_DEFAULTS.HOST_DOMAIN, options.hostDomain ?? WA_DEFAULTS.HOST_DOMAIN)
|
|
108
132
|
: address.server;
|
|
109
133
|
return `${address.user}@${server}`;
|
|
@@ -121,16 +145,26 @@ export function isHostedServer(server) {
|
|
|
121
145
|
return server === WA_DEFAULTS.HOSTED_SERVER || server === WA_DEFAULTS.HOSTED_LID_SERVER;
|
|
122
146
|
}
|
|
123
147
|
export function isHostedDeviceJid(jid) {
|
|
124
|
-
|
|
125
|
-
|
|
148
|
+
if (isJidType(jid, WA_DEFAULTS.HOSTED_SERVER) ||
|
|
149
|
+
isJidType(jid, WA_DEFAULTS.HOSTED_LID_SERVER)) {
|
|
126
150
|
return true;
|
|
127
151
|
}
|
|
128
|
-
const
|
|
129
|
-
if (
|
|
152
|
+
const atIndex = jid.indexOf('@');
|
|
153
|
+
if (atIndex < 1 || atIndex >= jid.length - 1)
|
|
154
|
+
return false;
|
|
155
|
+
const colonIndex = jid.indexOf(':');
|
|
156
|
+
if (colonIndex < 0 || colonIndex >= atIndex - 1)
|
|
130
157
|
return false;
|
|
158
|
+
let deviceId = 0;
|
|
159
|
+
for (let i = colonIndex + 1; i < atIndex; i += 1) {
|
|
160
|
+
const digit = jid.charCodeAt(i) - 48;
|
|
161
|
+
if (digit < 0 || digit > 9)
|
|
162
|
+
return false;
|
|
163
|
+
deviceId = deviceId * 10 + digit;
|
|
164
|
+
if (deviceId > Number.MAX_SAFE_INTEGER)
|
|
165
|
+
return false;
|
|
131
166
|
}
|
|
132
|
-
|
|
133
|
-
return Number.isSafeInteger(deviceId) && isHostedDeviceId(deviceId);
|
|
167
|
+
return isHostedDeviceId(deviceId);
|
|
134
168
|
}
|
|
135
169
|
export function buildDeviceJid(user, normalizedServer, deviceId, options = {}) {
|
|
136
170
|
if (options.isHosted === true) {
|
|
@@ -32,6 +32,7 @@ export const WA_NODE_TAGS = Object.freeze({
|
|
|
32
32
|
DESCRIPTION: 'description',
|
|
33
33
|
MY_ADDONS: 'my_addons',
|
|
34
34
|
KEY: 'key',
|
|
35
|
+
OP: 'op',
|
|
35
36
|
REGISTRATION: 'registration',
|
|
36
37
|
TYPE: 'type',
|
|
37
38
|
IDENTITY: 'identity',
|
|
@@ -60,7 +61,8 @@ export const WA_NODE_TAGS = Object.freeze({
|
|
|
60
61
|
ANNOUNCEMENT: 'announcement',
|
|
61
62
|
EPHEMERAL: 'ephemeral',
|
|
62
63
|
MEMBERSHIP_APPROVAL_MODE: 'membership_approval_mode',
|
|
63
|
-
GROUP_JOIN: 'group_join'
|
|
64
|
+
GROUP_JOIN: 'group_join',
|
|
65
|
+
ABPROPS: 'abprops'
|
|
64
66
|
});
|
|
65
67
|
export const WA_IQ_TYPES = Object.freeze({
|
|
66
68
|
GET: 'get',
|
|
@@ -83,5 +85,7 @@ export const WA_XMLNS = Object.freeze({
|
|
|
83
85
|
GROUPS: 'w:g2',
|
|
84
86
|
NEWSLETTER: 'newsletter',
|
|
85
87
|
XMPP_PING: 'urn:xmpp:ping',
|
|
86
|
-
WHATSAPP_PING: 'w:p'
|
|
88
|
+
WHATSAPP_PING: 'w:p',
|
|
89
|
+
ABPROPS: 'abt',
|
|
90
|
+
MEX: 'w:mex'
|
|
87
91
|
});
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
export const WA_NOTIFICATION_TYPES = Object.freeze({
|
|
2
2
|
GROUP: 'w:gp2',
|
|
3
3
|
ENCRYPT: 'encrypt',
|
|
4
|
-
DEVICES: 'devices'
|
|
4
|
+
DEVICES: 'devices',
|
|
5
|
+
SERVER: 'server',
|
|
6
|
+
REGISTRATION: 'registration'
|
|
7
|
+
});
|
|
8
|
+
export const WA_REGISTRATION_NOTIFICATION_TAGS = Object.freeze({
|
|
9
|
+
WA_OLD_REGISTRATION: 'wa_old_registration',
|
|
10
|
+
DEVICE_LOGOUT: 'device_logout'
|
|
5
11
|
});
|
|
6
12
|
export const WA_GROUP_NOTIFICATION_TAGS = Object.freeze({
|
|
7
13
|
REMOVE: 'remove',
|
package/dist/esm/retry/reason.js
CHANGED
|
@@ -327,7 +327,10 @@ export class SignalDeviceSyncApi {
|
|
|
327
327
|
return [];
|
|
328
328
|
}
|
|
329
329
|
const parsedNormalizedUser = splitJid(normalizedUserJid);
|
|
330
|
-
const
|
|
330
|
+
const rawAtIndex = rawUserJid.indexOf('@');
|
|
331
|
+
const rawServer = rawAtIndex >= 1 && rawAtIndex < rawUserJid.length - 1
|
|
332
|
+
? rawUserJid.slice(rawAtIndex + 1)
|
|
333
|
+
: parsedNormalizedUser.server;
|
|
331
334
|
const dedup = new Set();
|
|
332
335
|
for (const deviceNode of getNodeChildrenByTag(deviceListNode, 'device')) {
|
|
333
336
|
const parsedId = deviceNode.attrs.id
|
|
@@ -338,7 +341,7 @@ export class SignalDeviceSyncApi {
|
|
|
338
341
|
}
|
|
339
342
|
const isHostedDevice = isHostedDeviceId(parsedId) || deviceNode.attrs.is_hosted === 'true';
|
|
340
343
|
dedup.add(buildDeviceJid(parsedNormalizedUser.user, parsedNormalizedUser.server, parsedId, {
|
|
341
|
-
rawServer
|
|
344
|
+
rawServer,
|
|
342
345
|
isHosted: isHostedDevice
|
|
343
346
|
}));
|
|
344
347
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { sha1 } from '../../crypto/index.js';
|
|
2
|
+
import { toRawPubKey } from '../../crypto/core/keys.js';
|
|
2
3
|
import { WA_DEFAULTS, WA_IQ_TYPES, WA_NODE_TAGS, WA_XMLNS } from '../../protocol/constants.js';
|
|
3
4
|
import { decodeExactLength, parseUint } from '../api/codec.js';
|
|
4
5
|
import { SIGNAL_KEY_BUNDLE_TYPE_BYTES, SIGNAL_KEY_BUNDLE_TYPE_LENGTH, SIGNAL_KEY_DATA_LENGTH, SIGNAL_KEY_ID_LENGTH, SIGNAL_REGISTRATION_ID_LENGTH, SIGNAL_SIGNATURE_LENGTH } from '../api/constants.js';
|
|
@@ -10,6 +11,7 @@ export class SignalDigestSyncApi {
|
|
|
10
11
|
this.logger = options.logger;
|
|
11
12
|
this.query = options.query;
|
|
12
13
|
this.signalStore = options.signalStore;
|
|
14
|
+
this.preKeyStore = options.preKeyStore;
|
|
13
15
|
this.defaultTimeoutMs =
|
|
14
16
|
options.defaultTimeoutMs ?? WA_DEFAULTS.SIGNAL_FETCH_KEY_BUNDLES_TIMEOUT_MS;
|
|
15
17
|
this.hostDomain = options.hostDomain ?? WA_DEFAULTS.HOST_DOMAIN;
|
|
@@ -82,7 +84,7 @@ export class SignalDigestSyncApi {
|
|
|
82
84
|
preKeyCount: digest.preKeyIds.length
|
|
83
85
|
};
|
|
84
86
|
}
|
|
85
|
-
if (!uint8Equal(registrationInfo.identityKeyPair.pubKey, digest.identity)) {
|
|
87
|
+
if (!uint8Equal(toRawPubKey(registrationInfo.identityKeyPair.pubKey), toRawPubKey(digest.identity))) {
|
|
86
88
|
return {
|
|
87
89
|
valid: false,
|
|
88
90
|
shouldReupload: true,
|
|
@@ -91,7 +93,7 @@ export class SignalDigestSyncApi {
|
|
|
91
93
|
};
|
|
92
94
|
}
|
|
93
95
|
if (signedPreKey.keyId !== digest.signedKey.id ||
|
|
94
|
-
!uint8Equal(signedPreKey.keyPair.pubKey, digest.signedKey.publicKey) ||
|
|
96
|
+
!uint8Equal(toRawPubKey(signedPreKey.keyPair.pubKey), toRawPubKey(digest.signedKey.publicKey)) ||
|
|
95
97
|
!uint8Equal(signedPreKey.signature, digest.signedKey.signature)) {
|
|
96
98
|
return {
|
|
97
99
|
valid: false,
|
|
@@ -100,10 +102,10 @@ export class SignalDigestSyncApi {
|
|
|
100
102
|
preKeyCount: digest.preKeyIds.length
|
|
101
103
|
};
|
|
102
104
|
}
|
|
103
|
-
const preKeys = await this.
|
|
105
|
+
const preKeys = await this.preKeyStore.getPreKeysById(digest.preKeyIds);
|
|
104
106
|
const bytesToHash = [
|
|
105
|
-
registrationInfo.identityKeyPair.pubKey,
|
|
106
|
-
signedPreKey.keyPair.pubKey,
|
|
107
|
+
toRawPubKey(registrationInfo.identityKeyPair.pubKey),
|
|
108
|
+
toRawPubKey(signedPreKey.keyPair.pubKey),
|
|
107
109
|
signedPreKey.signature
|
|
108
110
|
];
|
|
109
111
|
for (let index = 0; index < preKeys.length; index += 1) {
|
|
@@ -116,7 +118,7 @@ export class SignalDigestSyncApi {
|
|
|
116
118
|
preKeyCount: digest.preKeyIds.length
|
|
117
119
|
};
|
|
118
120
|
}
|
|
119
|
-
bytesToHash.push(preKey.keyPair.pubKey);
|
|
121
|
+
bytesToHash.push(toRawPubKey(preKey.keyPair.pubKey));
|
|
120
122
|
}
|
|
121
123
|
const localHash = (await sha1(concatBytes(bytesToHash))).subarray(0, digest.hash.byteLength);
|
|
122
124
|
if (!uint8Equal(localHash, digest.hash)) {
|
|
@@ -11,7 +11,7 @@ export class SignalIdentitySyncApi {
|
|
|
11
11
|
this.syncDedup = new PromiseDedup();
|
|
12
12
|
this.logger = options.logger;
|
|
13
13
|
this.query = options.query;
|
|
14
|
-
this.
|
|
14
|
+
this.identityStore = options.identityStore;
|
|
15
15
|
this.defaultTimeoutMs =
|
|
16
16
|
options.defaultTimeoutMs ?? WA_DEFAULTS.SIGNAL_FETCH_KEY_BUNDLES_TIMEOUT_MS;
|
|
17
17
|
this.hostDomain = options.hostDomain ?? WA_DEFAULTS.HOST_DOMAIN;
|
|
@@ -66,8 +66,8 @@ export class SignalIdentitySyncApi {
|
|
|
66
66
|
]
|
|
67
67
|
}, timeoutMs);
|
|
68
68
|
const entries = this.parseIdentitySyncResponse(response, normalizedTargets);
|
|
69
|
-
const {
|
|
70
|
-
if (
|
|
69
|
+
const { identityStore } = this;
|
|
70
|
+
if (identityStore && entries.length > 0) {
|
|
71
71
|
const identities = new Array(entries.length);
|
|
72
72
|
for (let index = 0; index < entries.length; index += 1) {
|
|
73
73
|
const entry = entries[index];
|
|
@@ -76,7 +76,7 @@ export class SignalIdentitySyncApi {
|
|
|
76
76
|
identityKey: toSerializedPubKey(entry.identity)
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
|
-
await
|
|
79
|
+
await identityStore.setRemoteIdentities(identities);
|
|
80
80
|
}
|
|
81
81
|
this.logger.debug('signal identity sync success', {
|
|
82
82
|
requested: normalizedTargets.length,
|
|
@@ -4,7 +4,7 @@ import { decodeExactLength, parseUint } from '../api/codec.js';
|
|
|
4
4
|
import { SIGNAL_KEY_DATA_LENGTH, SIGNAL_KEY_ID_LENGTH, SIGNAL_REGISTRATION_ID_LENGTH, SIGNAL_SIGNATURE_LENGTH } from '../api/constants.js';
|
|
5
5
|
import { buildMissingPreKeysFetchIq } from '../api/prekeys.js';
|
|
6
6
|
import { registerParsedResultByRawAndCanonicalKey } from '../api/result-map.js';
|
|
7
|
-
import { decodeNodeContentBase64OrBytes,
|
|
7
|
+
import { decodeNodeContentBase64OrBytes, findNodeChild, findNodeChildrenByTags, getNodeChildrenByTag } from '../../transport/node/helpers.js';
|
|
8
8
|
import { assertIqResult } from '../../transport/node/query.js';
|
|
9
9
|
function isMissingPreKeysUserResultPreferred(result) {
|
|
10
10
|
return 'devices' in result;
|
|
@@ -3,7 +3,7 @@ import { canonicalizeSignalJid } from '../../protocol/jid.js';
|
|
|
3
3
|
import { decodeExactLength, parseUint } from '../api/codec.js';
|
|
4
4
|
import { SIGNAL_KEY_DATA_LENGTH, SIGNAL_KEY_ID_LENGTH, SIGNAL_REGISTRATION_ID_LENGTH, SIGNAL_SIGNATURE_LENGTH } from '../api/constants.js';
|
|
5
5
|
import { registerParsedResultByRawAndCanonicalKey } from '../api/result-map.js';
|
|
6
|
-
import { findNodeChild, getNodeChildrenByTag
|
|
6
|
+
import { decodeNodeContentBase64OrBytes, findNodeChild, getNodeChildrenByTag } from '../../transport/node/helpers.js';
|
|
7
7
|
import { assertIqResult } from '../../transport/node/query.js';
|
|
8
8
|
function isKeyBundleResultPreferred(result) {
|
|
9
9
|
return 'bundle' in result;
|
|
@@ -1,62 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { bytesToBigIntLE, bigIntToBytesLE } from '../../crypto/math/le.js';
|
|
5
|
-
import { modGroup } from '../../crypto/math/mod.js';
|
|
6
|
-
import { ADV_PREFIX_ACCOUNT_SIGNATURE, ADV_PREFIX_DEVICE_SIGNATURE, ADV_PREFIX_HOSTED_ACCOUNT_SIGNATURE, ADV_PREFIX_HOSTED_DEVICE_SIGNATURE, SIGNAL_PREFIX_SIGNATURE_RANDOM } from '../crypto/constants.js';
|
|
7
|
-
import { assertByteLength, concatBytes } from '../../util/bytes.js';
|
|
1
|
+
import { hmacSign, importHmacKey, toRawPubKey, xeddsaSign, xeddsaVerify } from '../../crypto/index.js';
|
|
2
|
+
import { ADV_PREFIX_ACCOUNT_SIGNATURE, ADV_PREFIX_DEVICE_SIGNATURE, ADV_PREFIX_HOSTED_ACCOUNT_SIGNATURE, ADV_PREFIX_HOSTED_DEVICE_SIGNATURE } from '../crypto/constants.js';
|
|
3
|
+
import { concatBytes } from '../../util/bytes.js';
|
|
8
4
|
export { ADV_PREFIX_ACCOUNT_SIGNATURE, ADV_PREFIX_DEVICE_SIGNATURE, ADV_PREFIX_HOSTED_ACCOUNT_SIGNATURE, ADV_PREFIX_HOSTED_DEVICE_SIGNATURE } from '../crypto/constants.js';
|
|
9
|
-
export async function verifySignalSignature(publicKey, message, signature) {
|
|
10
|
-
if (signature.length !== 64) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
if ((signature[63] & 0x60) !== 0) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
const signatureLastByteIndex = 63;
|
|
17
|
-
const originalSignatureLastByte = signature[signatureLastByteIndex];
|
|
18
|
-
const signBit = originalSignatureLastByte & 0x80;
|
|
19
|
-
signature[signatureLastByteIndex] = originalSignatureLastByte & 0x7f;
|
|
20
|
-
const curvePublic = toRawPubKey(publicKey);
|
|
21
|
-
const edPublic = montgomeryToEdwardsPublic(curvePublic, signBit);
|
|
22
|
-
try {
|
|
23
|
-
return await Ed25519.verify(message, signature, edPublic);
|
|
24
|
-
}
|
|
25
|
-
finally {
|
|
26
|
-
signature[signatureLastByteIndex] = originalSignatureLastByte;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
export async function signSignalMessage(privateKey, message) {
|
|
30
|
-
assertByteLength(privateKey, 32, `invalid curve25519 private key length ${privateKey.length}`);
|
|
31
|
-
const clampedPrivateKey = clampCurvePrivateKeyInPlace(privateKey);
|
|
32
|
-
const privateScalar = bytesToBigIntLE(clampedPrivateKey);
|
|
33
|
-
const encodedPublic = encodeExtendedPoint(scalarMultBase(privateScalar));
|
|
34
|
-
const pubKeySignBit = encodedPublic[31] & 0x80;
|
|
35
|
-
const randomSuffix = await randomBytesAsync(64);
|
|
36
|
-
const hashInput = concatBytes([
|
|
37
|
-
SIGNAL_PREFIX_SIGNATURE_RANDOM,
|
|
38
|
-
clampedPrivateKey,
|
|
39
|
-
message,
|
|
40
|
-
randomSuffix
|
|
41
|
-
]);
|
|
42
|
-
const r = modGroup(bytesToBigIntLE(await sha512(hashInput)));
|
|
43
|
-
const encodedR = encodeExtendedPoint(scalarMultBase(r));
|
|
44
|
-
const hInput = concatBytes([encodedR, encodedPublic, message]);
|
|
45
|
-
const h = modGroup(bytesToBigIntLE(await sha512(hInput)));
|
|
46
|
-
const s = modGroup(r + h * privateScalar);
|
|
47
|
-
const encodedS = bigIntToBytesLE(s, 32);
|
|
48
|
-
encodedS[31] = (encodedS[31] & 0x7f) | pubKeySignBit;
|
|
49
|
-
return concatBytes([encodedR, encodedS]);
|
|
50
|
-
}
|
|
51
5
|
export async function verifyDeviceIdentityAccountSignature(details, accountSignature, identityPublicKey, accountSignatureKey, isHosted = false) {
|
|
52
6
|
const prefix = isHosted ? ADV_PREFIX_HOSTED_ACCOUNT_SIGNATURE : ADV_PREFIX_ACCOUNT_SIGNATURE;
|
|
53
7
|
const message = concatBytes([prefix, details, identityPublicKey]);
|
|
54
|
-
return
|
|
8
|
+
return xeddsaVerify(toRawPubKey(accountSignatureKey), message, accountSignature);
|
|
55
9
|
}
|
|
56
10
|
export async function generateDeviceSignature(details, identityKeyPair, accountSignatureKey, isHosted = false) {
|
|
57
11
|
const prefix = isHosted ? ADV_PREFIX_HOSTED_DEVICE_SIGNATURE : ADV_PREFIX_DEVICE_SIGNATURE;
|
|
58
12
|
const message = concatBytes([prefix, details, identityKeyPair.pubKey, accountSignatureKey]);
|
|
59
|
-
return
|
|
13
|
+
return xeddsaSign(identityKeyPair.privKey, message);
|
|
60
14
|
}
|
|
61
15
|
export async function computeAdvIdentityHmac(secretKey, details) {
|
|
62
16
|
const key = await importHmacKey(secretKey);
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
export const SIGNAL_PREFIX_SIGNATURE_RANDOM = new Uint8Array([
|
|
2
|
-
0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
3
|
-
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
|
|
4
|
-
]);
|
|
5
1
|
export const ADV_PREFIX_ACCOUNT_SIGNATURE = new Uint8Array([6, 0]);
|
|
6
2
|
export const ADV_PREFIX_DEVICE_SIGNATURE = new Uint8Array([6, 1]);
|
|
7
3
|
export const ADV_PREFIX_HOSTED_ACCOUNT_SIGNATURE = new Uint8Array([6, 5]);
|