zapo-js 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -4
- package/dist/appstate/WaAppStateCrypto.js +1 -1
- package/dist/appstate/WaAppStateSyncClient.js +138 -93
- package/dist/appstate/{store/sqlite.js → encoding.js} +13 -8
- package/dist/appstate/index.js +8 -6
- package/dist/appstate/utils.js +0 -5
- package/dist/auth/WaAuthClient.js +36 -47
- package/dist/auth/flow/WaAuthCredentialsFlow.js +7 -7
- package/dist/auth/index.js +1 -6
- package/dist/auth/pairing/WaPairingCodeCrypto.js +6 -4
- package/dist/auth/pairing/WaPairingFlow.js +13 -3
- package/dist/client/WaClient.js +225 -101
- package/dist/client/WaClientFactory.js +294 -44
- package/dist/client/connection/WaConnectionManager.js +19 -10
- package/dist/client/coordinators/WaBusinessCoordinator.js +241 -0
- package/dist/client/coordinators/WaGroupCoordinator.js +11 -7
- package/dist/client/coordinators/WaIncomingNodeCoordinator.js +1 -0
- package/dist/client/coordinators/WaMessageDispatchCoordinator.js +292 -99
- package/dist/client/coordinators/WaPassiveTasksCoordinator.js +74 -31
- package/dist/client/coordinators/WaPrivacyCoordinator.js +134 -0
- package/dist/client/coordinators/WaProfileCoordinator.js +212 -0
- package/dist/client/coordinators/WaRetryCoordinator.js +179 -27
- package/dist/client/coordinators/WaStreamControlCoordinator.js +18 -11
- package/dist/client/coordinators/WaTrustedContactTokenCoordinator.js +166 -0
- package/dist/client/dirty.js +40 -20
- package/dist/client/events/devices.js +72 -0
- package/dist/client/events/group.js +3 -11
- package/dist/client/events/identity.js +22 -0
- package/dist/client/events/privacy-token.js +39 -0
- package/dist/client/history-sync.js +50 -9
- package/dist/client/incoming.js +37 -7
- package/dist/client/mailbox.js +24 -23
- package/dist/client/messages.js +107 -31
- package/dist/client/messaging/fanout.js +21 -11
- package/dist/client/messaging/participants.js +6 -4
- package/dist/client/persistence/WriteBehindPersistence.js +129 -0
- package/dist/client/tokens/cs-token.js +50 -0
- package/dist/client/tokens/tc-token.js +25 -0
- package/dist/crypto/core/index.js +2 -2
- package/dist/crypto/core/keys.js +4 -4
- package/dist/crypto/core/nonce.js +2 -0
- package/dist/crypto/core/primitives.js +0 -8
- package/dist/crypto/core/random.js +22 -0
- package/dist/crypto/curves/X25519.js +25 -6
- package/dist/crypto/index.js +3 -0
- package/dist/crypto/math/constants.js +13 -36
- package/dist/crypto/math/edwards.js +171 -44
- package/dist/crypto/math/fe.js +706 -0
- package/dist/crypto/math/mod.js +10 -3
- package/dist/esm/appstate/WaAppStateCrypto.js +1 -1
- package/dist/esm/appstate/WaAppStateSyncClient.js +138 -93
- package/dist/esm/appstate/{store/sqlite.js → encoding.js} +13 -8
- package/dist/esm/appstate/index.js +2 -2
- package/dist/esm/appstate/utils.js +2 -5
- package/dist/esm/auth/WaAuthClient.js +36 -47
- package/dist/esm/auth/flow/WaAuthCredentialsFlow.js +7 -7
- package/dist/esm/auth/index.js +0 -2
- package/dist/esm/auth/pairing/WaPairingCodeCrypto.js +6 -4
- package/dist/esm/auth/pairing/WaPairingFlow.js +14 -4
- package/dist/esm/client/WaClient.js +225 -101
- package/dist/esm/client/WaClientFactory.js +295 -45
- package/dist/esm/client/connection/WaConnectionManager.js +19 -10
- package/dist/esm/client/coordinators/WaBusinessCoordinator.js +238 -0
- package/dist/esm/client/coordinators/WaGroupCoordinator.js +11 -7
- package/dist/esm/client/coordinators/WaIncomingNodeCoordinator.js +1 -0
- package/dist/esm/client/coordinators/WaMessageDispatchCoordinator.js +295 -102
- package/dist/esm/client/coordinators/WaPassiveTasksCoordinator.js +74 -31
- package/dist/esm/client/coordinators/WaPrivacyCoordinator.js +131 -0
- package/dist/esm/client/coordinators/WaProfileCoordinator.js +209 -0
- package/dist/esm/client/coordinators/WaRetryCoordinator.js +181 -29
- package/dist/esm/client/coordinators/WaStreamControlCoordinator.js +19 -12
- package/dist/esm/client/coordinators/WaTrustedContactTokenCoordinator.js +162 -0
- package/dist/esm/client/dirty.js +40 -20
- package/dist/esm/client/events/devices.js +68 -0
- package/dist/esm/client/events/group.js +3 -11
- package/dist/esm/client/events/identity.js +19 -0
- package/dist/esm/client/events/privacy-token.js +36 -0
- package/dist/esm/client/history-sync.js +50 -9
- package/dist/esm/client/incoming.js +38 -8
- package/dist/esm/client/mailbox.js +24 -23
- package/dist/esm/client/messages.js +108 -32
- package/dist/esm/client/messaging/fanout.js +22 -12
- package/dist/esm/client/messaging/participants.js +6 -4
- package/dist/esm/client/persistence/WriteBehindPersistence.js +125 -0
- package/dist/esm/client/tokens/cs-token.js +46 -0
- package/dist/esm/client/tokens/tc-token.js +18 -0
- package/dist/esm/crypto/core/index.js +2 -2
- package/dist/esm/crypto/core/keys.js +1 -1
- package/dist/esm/crypto/core/nonce.js +2 -0
- package/dist/esm/crypto/core/primitives.js +0 -7
- package/dist/esm/crypto/core/random.js +22 -1
- package/dist/esm/crypto/curves/X25519.js +25 -6
- package/dist/esm/crypto/index.js +1 -0
- package/dist/esm/crypto/math/constants.js +12 -35
- package/dist/esm/crypto/math/edwards.js +174 -47
- package/dist/esm/crypto/math/fe.js +691 -0
- package/dist/esm/crypto/math/mod.js +10 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/infra/perf/BackgroundQueue.js +478 -0
- package/dist/esm/infra/perf/BoundedTaskQueue.js +3 -1
- package/dist/esm/infra/perf/PromiseDedup.js +20 -0
- package/dist/esm/infra/perf/SharedExclusiveGate.js +109 -0
- package/dist/esm/infra/perf/StoreLock.js +77 -0
- package/dist/esm/media/WaMediaCrypto.js +95 -13
- package/dist/esm/media/WaMediaTransferClient.js +39 -47
- package/dist/esm/media/constants.js +2 -1
- package/dist/esm/message/WaMessageClient.js +26 -19
- package/dist/esm/message/content.js +195 -9
- package/dist/esm/message/icdc.js +76 -0
- package/dist/esm/message/incoming.js +24 -12
- package/dist/esm/message/phash.js +3 -1
- package/dist/esm/message/reporting-token.js +14 -27
- package/dist/esm/protocol/appstate.js +9 -40
- package/dist/esm/protocol/browser.js +10 -18
- package/dist/esm/protocol/constants.js +5 -3
- package/dist/esm/protocol/defaults.js +6 -0
- package/dist/esm/protocol/index.js +1 -2
- package/dist/esm/protocol/jid.js +105 -36
- package/dist/esm/protocol/message.js +61 -1
- package/dist/esm/protocol/nodes.js +2 -0
- package/dist/esm/protocol/notification.js +3 -1
- package/dist/esm/protocol/privacy-token.js +17 -0
- package/dist/esm/protocol/privacy.js +55 -0
- package/dist/esm/protocol/stream.js +26 -1
- package/dist/esm/retry/codec.js +216 -0
- package/dist/esm/retry/constants.js +1 -1
- package/dist/esm/retry/index.js +2 -2
- package/dist/esm/retry/parse.js +50 -30
- package/dist/esm/retry/replay.js +11 -7
- package/dist/esm/retry/tracker.js +50 -12
- package/dist/esm/signal/api/SignalDeviceSyncApi.js +49 -32
- package/dist/esm/signal/api/SignalDigestSyncApi.js +13 -9
- package/dist/esm/signal/api/SignalIdentitySyncApi.js +26 -11
- package/dist/esm/signal/api/SignalMissingPreKeysSyncApi.js +18 -7
- package/dist/esm/signal/api/SignalRotateKeyApi.js +4 -2
- package/dist/esm/signal/api/SignalSessionSyncApi.js +16 -7
- package/dist/esm/signal/api/result-map.js +10 -0
- package/dist/esm/signal/constants.js +0 -4
- package/dist/esm/signal/crypto/WaAdvSignature.js +12 -6
- package/dist/esm/signal/{store/sqlite.js → encoding.js} +78 -24
- package/dist/esm/signal/group/SenderKeyCodec.js +3 -2
- package/dist/esm/signal/group/SenderKeyManager.js +125 -106
- package/dist/esm/signal/index.js +1 -0
- package/dist/esm/signal/registration/keygen.js +6 -2
- package/dist/esm/signal/registration/utils.js +1 -0
- package/dist/esm/signal/session/SignalProtocol.js +150 -74
- package/dist/esm/signal/session/resolver.js +137 -102
- package/dist/esm/store/contracts/privacy-token.store.js +1 -0
- package/dist/esm/store/createStore.js +101 -187
- package/dist/esm/store/index.js +1 -10
- package/dist/esm/store/locks/appstate.lock.js +26 -0
- package/dist/esm/store/locks/auth.lock.js +15 -0
- package/dist/esm/store/locks/contact.lock.js +20 -0
- package/dist/esm/store/locks/device-list.lock.js +20 -0
- package/dist/esm/store/locks/message.lock.js +21 -0
- package/dist/esm/store/locks/participants.lock.js +20 -0
- package/dist/esm/store/locks/privacy-token.lock.js +18 -0
- package/dist/esm/store/locks/retry.lock.js +29 -0
- package/dist/esm/store/locks/sender-key.lock.js +52 -0
- package/dist/esm/store/locks/signal.lock.js +63 -0
- package/dist/esm/store/locks/thread.lock.js +21 -0
- package/dist/esm/store/noop.store.js +1 -1
- package/dist/esm/store/providers/memory/appstate.store.js +22 -24
- package/dist/esm/store/providers/memory/device-list.store.js +10 -5
- package/dist/esm/store/providers/memory/privacy-token.store.js +43 -0
- package/dist/esm/store/providers/memory/retry.store.js +77 -2
- package/dist/esm/store/providers/memory/sender-key.store.js +6 -1
- package/dist/esm/store/providers/memory/signal.store.js +36 -19
- package/dist/esm/transport/WaComms.js +3 -1
- package/dist/esm/transport/WaWebSocket.js +0 -6
- package/dist/esm/transport/binary/constants.js +0 -30
- package/dist/esm/transport/binary/decoder.js +4 -4
- package/dist/esm/transport/binary/encoder.js +8 -15
- package/dist/esm/transport/binary/index.js +0 -1
- package/dist/esm/transport/node/WaNodeOrchestrator.js +25 -19
- package/dist/esm/transport/node/builders/business.js +129 -0
- package/dist/esm/transport/node/builders/global.js +370 -0
- package/dist/esm/transport/node/builders/index.js +5 -2
- package/dist/esm/transport/node/builders/message.js +63 -239
- package/dist/esm/transport/node/builders/pairing.js +0 -24
- package/dist/esm/transport/node/builders/privacy-token.js +41 -0
- package/dist/esm/transport/node/builders/privacy.js +48 -0
- package/dist/esm/transport/node/builders/profile.js +70 -0
- package/dist/esm/transport/node/builders/retry.js +10 -22
- package/dist/esm/transport/node/builders/usync.js +6 -2
- package/dist/esm/transport/node/helpers.js +19 -1
- package/dist/esm/transport/node/usync.js +3 -33
- package/dist/esm/transport/node/xml.js +35 -14
- package/dist/esm/transport/noise/WaClientPayload.js +10 -10
- package/dist/esm/transport/noise/WaNoiseCert.js +3 -3
- package/dist/esm/transport/noise/WaNoiseSession.js +64 -23
- package/dist/esm/transport/noise/WaNoiseSocket.js +8 -4
- package/dist/esm/transport/stream/parse.js +8 -4
- package/dist/esm/util/bytes.js +22 -18
- package/dist/esm/util/index.js +5 -0
- package/dist/esm/util/primitives.js +3 -2
- package/dist/index.js +7 -1
- package/dist/infra/perf/BackgroundQueue.js +482 -0
- package/dist/infra/perf/BoundedTaskQueue.js +3 -1
- package/dist/infra/perf/PromiseDedup.js +24 -0
- package/dist/infra/perf/SharedExclusiveGate.js +113 -0
- package/dist/infra/perf/StoreLock.js +81 -0
- package/dist/media/WaMediaCrypto.js +94 -12
- package/dist/media/WaMediaTransferClient.js +39 -47
- package/dist/media/constants.js +2 -1
- package/dist/message/WaMessageClient.js +26 -19
- package/dist/message/content.js +198 -9
- package/dist/message/icdc.js +81 -0
- package/dist/message/incoming.js +24 -12
- package/dist/message/phash.js +3 -1
- package/dist/message/reporting-token.js +14 -28
- package/dist/protocol/appstate.js +10 -41
- package/dist/protocol/browser.js +10 -18
- package/dist/protocol/constants.js +21 -2
- package/dist/protocol/defaults.js +6 -0
- package/dist/protocol/index.js +8 -5
- package/dist/protocol/jid.js +111 -36
- package/dist/protocol/message.js +62 -2
- package/dist/protocol/nodes.js +2 -0
- package/dist/protocol/notification.js +3 -1
- package/dist/protocol/privacy-token.js +20 -0
- package/dist/protocol/privacy.js +58 -0
- package/dist/protocol/stream.js +27 -2
- package/dist/retry/codec.js +220 -0
- package/dist/retry/constants.js +1 -1
- package/dist/retry/index.js +5 -5
- package/dist/retry/parse.js +51 -30
- package/dist/retry/replay.js +10 -6
- package/dist/retry/tracker.js +50 -12
- package/dist/signal/api/SignalDeviceSyncApi.js +48 -31
- package/dist/signal/api/SignalDigestSyncApi.js +13 -9
- package/dist/signal/api/SignalIdentitySyncApi.js +25 -10
- package/dist/signal/api/SignalMissingPreKeysSyncApi.js +17 -6
- package/dist/signal/api/SignalRotateKeyApi.js +4 -2
- package/dist/signal/api/SignalSessionSyncApi.js +16 -7
- package/dist/signal/api/result-map.js +13 -0
- package/dist/signal/constants.js +1 -5
- package/dist/signal/crypto/WaAdvSignature.js +11 -5
- package/dist/signal/{store/sqlite.js → encoding.js} +79 -25
- package/dist/signal/group/SenderKeyCodec.js +4 -3
- package/dist/signal/group/SenderKeyManager.js +125 -106
- package/dist/signal/index.js +13 -1
- package/dist/signal/registration/keygen.js +6 -2
- package/dist/signal/registration/utils.js +1 -0
- package/dist/signal/session/SignalProtocol.js +150 -74
- package/dist/signal/session/resolver.js +135 -100
- package/dist/store/contracts/privacy-token.store.js +2 -0
- package/dist/store/createStore.js +101 -187
- package/dist/store/index.js +15 -33
- package/dist/store/locks/appstate.lock.js +29 -0
- package/dist/store/locks/auth.lock.js +18 -0
- package/dist/store/locks/contact.lock.js +23 -0
- package/dist/store/locks/device-list.lock.js +23 -0
- package/dist/store/locks/message.lock.js +24 -0
- package/dist/store/locks/participants.lock.js +23 -0
- package/dist/store/locks/privacy-token.lock.js +21 -0
- package/dist/store/locks/retry.lock.js +32 -0
- package/dist/store/locks/sender-key.lock.js +55 -0
- package/dist/store/locks/signal.lock.js +66 -0
- package/dist/store/locks/thread.lock.js +24 -0
- package/dist/store/noop.store.js +1 -1
- package/dist/store/providers/memory/appstate.store.js +22 -24
- package/dist/store/providers/memory/device-list.store.js +10 -5
- package/dist/store/providers/memory/privacy-token.store.js +47 -0
- package/dist/store/providers/memory/retry.store.js +77 -2
- package/dist/store/providers/memory/sender-key.store.js +6 -1
- package/dist/store/providers/memory/signal.store.js +36 -19
- package/dist/transport/WaComms.js +3 -1
- package/dist/transport/WaWebSocket.js +0 -6
- package/dist/transport/binary/constants.js +1 -31
- package/dist/transport/binary/decoder.js +4 -4
- package/dist/transport/binary/encoder.js +8 -15
- package/dist/transport/binary/index.js +0 -4
- package/dist/transport/node/WaNodeOrchestrator.js +24 -18
- package/dist/transport/node/builders/business.js +137 -0
- package/dist/transport/node/builders/global.js +375 -0
- package/dist/transport/node/builders/index.js +18 -9
- package/dist/transport/node/builders/message.js +64 -245
- package/dist/transport/node/builders/pairing.js +0 -26
- package/dist/transport/node/builders/privacy-token.js +46 -0
- package/dist/transport/node/builders/privacy.js +55 -0
- package/dist/transport/node/builders/profile.js +78 -0
- package/dist/transport/node/builders/retry.js +9 -21
- package/dist/transport/node/builders/usync.js +6 -2
- package/dist/transport/node/helpers.js +20 -1
- package/dist/transport/node/usync.js +2 -32
- package/dist/transport/node/xml.js +35 -14
- package/dist/transport/noise/WaClientPayload.js +13 -13
- package/dist/transport/noise/WaNoiseCert.js +2 -2
- package/dist/transport/noise/WaNoiseSession.js +64 -23
- package/dist/transport/noise/WaNoiseSocket.js +8 -4
- package/dist/transport/stream/parse.js +7 -3
- package/dist/types/appstate/encoding.d.ts +7 -0
- package/dist/types/appstate/index.d.ts +3 -3
- package/dist/types/appstate/utils.d.ts +0 -2
- package/dist/types/auth/flow/WaAuthCredentialsFlow.d.ts +1 -1
- package/dist/types/auth/index.d.ts +0 -2
- package/dist/types/auth/types.d.ts +1 -0
- package/dist/types/client/WaClient.d.ts +27 -12
- package/dist/types/client/WaClientFactory.d.ts +12 -4
- package/dist/types/client/connection/WaConnectionManager.d.ts +2 -0
- package/dist/types/client/coordinators/WaBusinessCoordinator.d.ts +57 -0
- package/dist/types/client/coordinators/WaIncomingNodeCoordinator.d.ts +3 -1
- package/dist/types/client/coordinators/WaMessageDispatchCoordinator.d.ts +14 -0
- package/dist/types/client/coordinators/WaPassiveTasksCoordinator.d.ts +4 -0
- package/dist/types/client/coordinators/WaPrivacyCoordinator.d.ts +26 -0
- package/dist/types/client/coordinators/WaProfileCoordinator.d.ts +36 -0
- package/dist/types/client/coordinators/WaRetryCoordinator.d.ts +6 -0
- package/dist/types/client/coordinators/WaStreamControlCoordinator.d.ts +3 -2
- package/dist/types/client/coordinators/WaTrustedContactTokenCoordinator.d.ts +45 -0
- package/dist/types/client/events/devices.d.ts +20 -0
- package/dist/types/client/events/identity.d.ts +9 -0
- package/dist/types/client/events/privacy-token.d.ts +7 -0
- package/dist/types/client/history-sync.d.ts +9 -6
- package/dist/types/client/incoming.d.ts +3 -1
- package/dist/types/client/index.d.ts +1 -1
- package/dist/types/client/mailbox.d.ts +3 -5
- package/dist/types/client/messages.d.ts +1 -2
- package/dist/types/client/persistence/WriteBehindPersistence.d.ts +34 -0
- package/dist/types/client/tokens/cs-token.d.ts +10 -0
- package/dist/types/client/tokens/tc-token.d.ts +5 -0
- package/dist/types/client/types.d.ts +51 -3
- package/dist/types/crypto/core/index.d.ts +2 -2
- package/dist/types/crypto/core/nonce.d.ts +2 -0
- package/dist/types/crypto/core/primitives.d.ts +0 -1
- package/dist/types/crypto/core/random.d.ts +1 -0
- package/dist/types/crypto/index.d.ts +1 -0
- package/dist/types/crypto/math/constants.d.ts +4 -2
- package/dist/types/crypto/math/fe.d.ts +30 -0
- package/dist/types/crypto/math/mod.d.ts +0 -2
- package/dist/types/crypto/math/types.d.ts +11 -4
- package/dist/types/index.d.ts +5 -3
- package/dist/types/infra/perf/BackgroundQueue.d.ts +58 -0
- package/dist/types/infra/perf/PromiseDedup.d.ts +4 -0
- package/dist/types/infra/perf/SharedExclusiveGate.d.ts +17 -0
- package/dist/types/infra/perf/StoreLock.d.ts +10 -0
- package/dist/types/media/WaMediaCrypto.d.ts +3 -2
- package/dist/types/media/WaMediaTransferClient.d.ts +3 -12
- package/dist/types/media/constants.d.ts +1 -1
- package/dist/types/media/index.d.ts +1 -1
- package/dist/types/media/types.d.ts +10 -2
- package/dist/types/message/content.d.ts +8 -0
- package/dist/types/message/icdc.d.ts +13 -0
- package/dist/types/message/reporting-token.d.ts +0 -1
- package/dist/types/message/types.d.ts +45 -6
- package/dist/types/protocol/appstate.d.ts +0 -11
- package/dist/types/protocol/constants.d.ts +7 -3
- package/dist/types/protocol/defaults.d.ts +6 -0
- package/dist/types/protocol/index.d.ts +1 -2
- package/dist/types/protocol/jid.d.ts +19 -2
- package/dist/types/protocol/message.d.ts +60 -0
- package/dist/types/protocol/nodes.d.ts +2 -0
- package/dist/types/protocol/notification.d.ts +2 -0
- package/dist/types/protocol/privacy-token.d.ts +17 -0
- package/dist/types/protocol/privacy.d.ts +75 -0
- package/dist/types/protocol/stream.d.ts +30 -0
- package/dist/types/retry/codec.d.ts +3 -0
- package/dist/types/retry/index.d.ts +3 -3
- package/dist/types/retry/parse.d.ts +5 -2
- package/dist/types/retry/tracker.d.ts +1 -0
- package/dist/types/retry/types.d.ts +6 -1
- package/dist/types/signal/api/SignalDeviceSyncApi.d.ts +2 -1
- package/dist/types/signal/api/SignalDigestSyncApi.d.ts +6 -0
- package/dist/types/signal/api/SignalIdentitySyncApi.d.ts +2 -0
- package/dist/types/signal/api/SignalRotateKeyApi.d.ts +4 -5
- package/dist/types/signal/api/SignalSessionSyncApi.d.ts +8 -6
- package/dist/types/signal/api/result-map.d.ts +1 -0
- package/dist/types/signal/constants.d.ts +0 -3
- package/dist/types/signal/{store/sqlite.d.ts → encoding.d.ts} +3 -3
- package/dist/types/signal/group/SenderKeyManager.d.ts +10 -5
- package/dist/types/signal/index.d.ts +2 -0
- package/dist/types/signal/session/SignalProtocol.d.ts +10 -4
- package/dist/types/signal/session/resolver.d.ts +7 -2
- package/dist/types/store/contracts/appstate.store.d.ts +1 -1
- package/dist/types/store/contracts/privacy-token.store.d.ts +16 -0
- package/dist/types/store/contracts/retry.store.d.ts +7 -0
- package/dist/types/store/contracts/signal.store.d.ts +7 -0
- package/dist/types/store/createStore.d.ts +1 -1
- package/dist/types/store/index.d.ts +5 -13
- package/dist/types/store/locks/appstate.lock.d.ts +3 -0
- package/dist/types/store/locks/auth.lock.d.ts +3 -0
- package/dist/types/store/locks/contact.lock.d.ts +3 -0
- package/dist/types/store/locks/device-list.lock.d.ts +2 -0
- package/dist/types/store/locks/message.lock.d.ts +3 -0
- package/dist/types/store/locks/participants.lock.d.ts +2 -0
- package/dist/types/store/locks/privacy-token.lock.d.ts +2 -0
- package/dist/types/store/locks/retry.lock.d.ts +2 -0
- package/dist/types/store/locks/sender-key.lock.d.ts +3 -0
- package/dist/types/store/locks/signal.lock.d.ts +3 -0
- package/dist/types/store/locks/thread.lock.d.ts +3 -0
- package/dist/types/store/providers/memory/appstate.store.d.ts +1 -1
- package/dist/types/store/providers/memory/privacy-token.store.d.ts +13 -0
- package/dist/types/store/providers/memory/retry.store.d.ts +8 -0
- package/dist/types/store/providers/memory/signal.store.d.ts +2 -1
- package/dist/types/store/types.d.ts +49 -61
- package/dist/types/transport/WaWebSocket.d.ts +0 -1
- package/dist/types/transport/binary/constants.d.ts +0 -30
- package/dist/types/transport/binary/index.d.ts +0 -1
- package/dist/types/transport/node/WaNodeOrchestrator.d.ts +3 -4
- package/dist/types/transport/node/builders/business.d.ts +29 -0
- package/dist/types/transport/node/builders/global.d.ts +102 -0
- package/dist/types/transport/node/builders/index.d.ts +5 -2
- package/dist/types/transport/node/builders/message.d.ts +8 -7
- package/dist/types/transport/node/builders/pairing.d.ts +0 -2
- package/dist/types/transport/node/builders/privacy-token.d.ts +9 -0
- package/dist/types/transport/node/builders/privacy.d.ts +7 -0
- package/dist/types/transport/node/builders/profile.d.ts +8 -0
- package/dist/types/transport/node/builders/retry.d.ts +0 -1
- package/dist/types/transport/node/helpers.d.ts +5 -0
- package/dist/types/transport/noise/WaNoiseSession.d.ts +3 -2
- package/dist/types/transport/noise/WaNoiseSocket.d.ts +4 -2
- package/dist/types/util/bytes.d.ts +1 -1
- package/dist/types/util/index.d.ts +5 -0
- package/dist/types/util/primitives.d.ts +0 -1
- package/dist/util/bytes.js +22 -18
- package/dist/util/index.js +23 -0
- package/dist/util/primitives.js +2 -2
- package/package.json +29 -7
- package/proto/index.js +1 -1
- package/dist/crypto/core/constants.js +0 -4
- package/dist/esm/crypto/core/constants.js +0 -1
- package/dist/esm/retry/outbound.js +0 -82
- package/dist/esm/store/providers/sqlite/BaseSqliteStore.js +0 -37
- package/dist/esm/store/providers/sqlite/appstate.store.js +0 -250
- package/dist/esm/store/providers/sqlite/auth.store.js +0 -176
- package/dist/esm/store/providers/sqlite/connection.js +0 -245
- package/dist/esm/store/providers/sqlite/contact.store.js +0 -74
- package/dist/esm/store/providers/sqlite/device-list.store.js +0 -127
- package/dist/esm/store/providers/sqlite/message.store.js +0 -132
- package/dist/esm/store/providers/sqlite/migrations.js +0 -347
- package/dist/esm/store/providers/sqlite/participants.store.js +0 -77
- package/dist/esm/store/providers/sqlite/retry.store.js +0 -141
- package/dist/esm/store/providers/sqlite/sender-key.store.js +0 -198
- package/dist/esm/store/providers/sqlite/signal.store.js +0 -435
- package/dist/esm/store/providers/sqlite/table-names.js +0 -107
- package/dist/esm/store/providers/sqlite/thread.store.js +0 -85
- package/dist/retry/outbound.js +0 -87
- package/dist/store/providers/sqlite/BaseSqliteStore.js +0 -41
- package/dist/store/providers/sqlite/appstate.store.js +0 -254
- package/dist/store/providers/sqlite/auth.store.js +0 -180
- package/dist/store/providers/sqlite/connection.js +0 -281
- package/dist/store/providers/sqlite/contact.store.js +0 -78
- package/dist/store/providers/sqlite/device-list.store.js +0 -131
- package/dist/store/providers/sqlite/message.store.js +0 -136
- package/dist/store/providers/sqlite/migrations.js +0 -350
- package/dist/store/providers/sqlite/participants.store.js +0 -81
- package/dist/store/providers/sqlite/retry.store.js +0 -145
- package/dist/store/providers/sqlite/sender-key.store.js +0 -202
- package/dist/store/providers/sqlite/signal.store.js +0 -439
- package/dist/store/providers/sqlite/table-names.js +0 -113
- package/dist/store/providers/sqlite/thread.store.js +0 -89
- package/dist/types/appstate/store/sqlite.d.ts +0 -7
- package/dist/types/crypto/core/constants.d.ts +0 -1
- package/dist/types/retry/outbound.d.ts +0 -4
- package/dist/types/store/providers/sqlite/BaseSqliteStore.d.ts +0 -12
- package/dist/types/store/providers/sqlite/appstate.store.d.ts +0 -17
- package/dist/types/store/providers/sqlite/auth.store.d.ts +0 -10
- package/dist/types/store/providers/sqlite/connection.d.ts +0 -10
- package/dist/types/store/providers/sqlite/contact.store.d.ts +0 -12
- package/dist/types/store/providers/sqlite/device-list.store.d.ts +0 -15
- package/dist/types/store/providers/sqlite/message.store.d.ts +0 -13
- package/dist/types/store/providers/sqlite/migrations.d.ts +0 -3
- package/dist/types/store/providers/sqlite/participants.store.d.ts +0 -12
- package/dist/types/store/providers/sqlite/retry.store.d.ts +0 -15
- package/dist/types/store/providers/sqlite/sender-key.store.d.ts +0 -24
- package/dist/types/store/providers/sqlite/signal.store.d.ts +0 -53
- package/dist/types/store/providers/sqlite/table-names.d.ts +0 -5
- package/dist/types/store/providers/sqlite/thread.store.d.ts +0 -13
|
@@ -63,22 +63,22 @@ function parsePacked(reader, alphabet) {
|
|
|
63
63
|
const odd = (lengthByte & 0x80) !== 0;
|
|
64
64
|
const byteCount = lengthByte & 0x7f;
|
|
65
65
|
const outLength = byteCount * 2 - (odd ? 1 : 0);
|
|
66
|
-
const
|
|
66
|
+
const buf = new Uint8Array(outLength);
|
|
67
67
|
let outIndex = 0;
|
|
68
68
|
for (let i = 0; i < byteCount; i += 1) {
|
|
69
69
|
const packed = reader.readUint8();
|
|
70
70
|
const high = (packed >>> 4) & 0x0f;
|
|
71
71
|
const low = packed & 0x0f;
|
|
72
72
|
if (outIndex < outLength) {
|
|
73
|
-
|
|
73
|
+
buf[outIndex] = alphabet[high].charCodeAt(0);
|
|
74
74
|
outIndex += 1;
|
|
75
75
|
}
|
|
76
76
|
if (outIndex < outLength) {
|
|
77
|
-
|
|
77
|
+
buf[outIndex] = alphabet[low].charCodeAt(0);
|
|
78
78
|
outIndex += 1;
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
return
|
|
81
|
+
return bytes_1.TEXT_DECODER.decode(buf);
|
|
82
82
|
}
|
|
83
83
|
function readBinary(reader, token) {
|
|
84
84
|
if (token === constants_2.BINARY_8) {
|
|
@@ -171,20 +171,14 @@ function writeListSize(size, writer) {
|
|
|
171
171
|
writer.writeUint16(size);
|
|
172
172
|
}
|
|
173
173
|
function writeNodeInternal(node, writer) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
if (Object.prototype.hasOwnProperty.call(node.attrs, key)) {
|
|
177
|
-
attrsLen += 1;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
174
|
+
const keys = Object.keys(node.attrs);
|
|
175
|
+
const attrsLen = keys.length;
|
|
180
176
|
const hasContent = node.content !== null && node.content !== undefined;
|
|
181
177
|
const listSize = 1 + attrsLen * 2 + (hasContent ? 1 : 0);
|
|
182
178
|
writeListSize(listSize, writer);
|
|
183
179
|
writeString(node.tag, writer);
|
|
184
|
-
for (
|
|
185
|
-
|
|
186
|
-
continue;
|
|
187
|
-
}
|
|
180
|
+
for (let i = 0; i < keys.length; i += 1) {
|
|
181
|
+
const key = keys[i];
|
|
188
182
|
writeString(key, writer);
|
|
189
183
|
writeString(node.attrs[key], writer);
|
|
190
184
|
}
|
|
@@ -214,9 +208,8 @@ function encodeBinaryNode(node) {
|
|
|
214
208
|
return writer.toUint8Array();
|
|
215
209
|
}
|
|
216
210
|
function encodeBinaryNodeStanza(node) {
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
return out;
|
|
211
|
+
const writer = new ByteWriter();
|
|
212
|
+
writer.writeUint8(0x00);
|
|
213
|
+
writeNodeInternal(node, writer);
|
|
214
|
+
return writer.toUint8Array();
|
|
222
215
|
}
|
|
@@ -14,10 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.WapEncodeConstants = exports.WapDecodeConstants = void 0;
|
|
18
17
|
__exportStar(require("../binary/tokens"), exports);
|
|
19
18
|
__exportStar(require("../binary/encoder"), exports);
|
|
20
19
|
__exportStar(require("../binary/decoder"), exports);
|
|
21
|
-
var constants_1 = require("../binary/constants");
|
|
22
|
-
Object.defineProperty(exports, "WapDecodeConstants", { enumerable: true, get: function () { return constants_1.WAP_DECODE_CONSTANTS; } });
|
|
23
|
-
Object.defineProperty(exports, "WapEncodeConstants", { enumerable: true, get: function () { return constants_1.WAP_ENCODE_CONSTANTS; } });
|
|
@@ -10,8 +10,8 @@ class WaNodeOrchestrator {
|
|
|
10
10
|
this.sendNodeFn = options.sendNode;
|
|
11
11
|
this.defaultTimeoutMs = options.defaultTimeoutMs ?? constants_1.WA_DEFAULTS.NODE_QUERY_TIMEOUT_MS;
|
|
12
12
|
this.hostDomain = options.hostDomain ?? constants_1.WA_DEFAULTS.HOST_DOMAIN;
|
|
13
|
-
this.
|
|
14
|
-
this.
|
|
13
|
+
this.idGenerator = null;
|
|
14
|
+
this.idGeneratorReady = null;
|
|
15
15
|
this.pendingQueries = new Map();
|
|
16
16
|
}
|
|
17
17
|
hasPending() {
|
|
@@ -73,11 +73,11 @@ class WaNodeOrchestrator {
|
|
|
73
73
|
return true;
|
|
74
74
|
}
|
|
75
75
|
async sendNode(node) {
|
|
76
|
-
const outbound = this.withAutoId(node);
|
|
76
|
+
const outbound = await this.withAutoId(node);
|
|
77
77
|
await this.sendNodeFn(outbound);
|
|
78
78
|
}
|
|
79
79
|
async query(node, timeoutMs = this.defaultTimeoutMs) {
|
|
80
|
-
const outbound = this.withAutoId(node);
|
|
80
|
+
const outbound = await this.withAutoId(node);
|
|
81
81
|
const id = outbound.attrs.id;
|
|
82
82
|
if (!id) {
|
|
83
83
|
throw new Error('query node id is required');
|
|
@@ -113,13 +113,11 @@ class WaNodeOrchestrator {
|
|
|
113
113
|
});
|
|
114
114
|
});
|
|
115
115
|
}
|
|
116
|
-
withAutoId(node) {
|
|
116
|
+
async withAutoId(node) {
|
|
117
117
|
if (node.attrs.id) {
|
|
118
118
|
return node;
|
|
119
119
|
}
|
|
120
|
-
const
|
|
121
|
-
this.stanzaCounter += 1;
|
|
122
|
-
const generatedId = `${prefix}${this.stanzaCounter}`;
|
|
120
|
+
const generatedId = (await this.getIdGenerator()).next();
|
|
123
121
|
this.logger.trace('generated stanza id', { id: generatedId });
|
|
124
122
|
return {
|
|
125
123
|
...node,
|
|
@@ -129,17 +127,25 @@ class WaNodeOrchestrator {
|
|
|
129
127
|
}
|
|
130
128
|
};
|
|
131
129
|
}
|
|
132
|
-
|
|
133
|
-
if (this.
|
|
134
|
-
return this.
|
|
130
|
+
async getIdGenerator() {
|
|
131
|
+
if (this.idGenerator) {
|
|
132
|
+
return this.idGenerator;
|
|
133
|
+
}
|
|
134
|
+
if (!this.idGeneratorReady) {
|
|
135
|
+
this.idGeneratorReady = (0, helpers_1.createNodeIdGenerator)();
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
const generator = await this.idGeneratorReady;
|
|
139
|
+
if (!this.idGenerator) {
|
|
140
|
+
this.idGenerator = generator;
|
|
141
|
+
this.logger.debug('generated stanza prefix', { prefix: generator.prefix });
|
|
142
|
+
}
|
|
143
|
+
return generator;
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
this.idGeneratorReady = null;
|
|
147
|
+
throw (0, primitives_1.toError)(error);
|
|
135
148
|
}
|
|
136
|
-
this.stanzaPrefix = this.generateStanzaPrefix();
|
|
137
|
-
return this.stanzaPrefix;
|
|
138
|
-
}
|
|
139
|
-
generateStanzaPrefix() {
|
|
140
|
-
const prefix = (0, helpers_1.formatNodeIdPrefixFromSeed)(crypto.getRandomValues(new Uint8Array(4)));
|
|
141
|
-
this.logger.debug('generated stanza prefix', { prefix });
|
|
142
|
-
return prefix;
|
|
143
149
|
}
|
|
144
150
|
}
|
|
145
151
|
exports.WaNodeOrchestrator = WaNodeOrchestrator;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WA_BUSINESS_PROFILE_VERSION = void 0;
|
|
4
|
+
exports.buildGetBusinessProfileIq = buildGetBusinessProfileIq;
|
|
5
|
+
exports.buildEditBusinessProfileIq = buildEditBusinessProfileIq;
|
|
6
|
+
exports.buildGetVerifiedNameIq = buildGetVerifiedNameIq;
|
|
7
|
+
exports.buildUpdateCoverPhotoIq = buildUpdateCoverPhotoIq;
|
|
8
|
+
exports.buildDeleteCoverPhotoIq = buildDeleteCoverPhotoIq;
|
|
9
|
+
const constants_1 = require("../../../protocol/constants");
|
|
10
|
+
const query_1 = require("../../node/query");
|
|
11
|
+
exports.WA_BUSINESS_PROFILE_VERSION = 116;
|
|
12
|
+
function buildGetBusinessProfileIq(jids, version = exports.WA_BUSINESS_PROFILE_VERSION) {
|
|
13
|
+
return (0, query_1.buildIqNode)('get', constants_1.WA_DEFAULTS.HOST_DOMAIN, constants_1.WA_XMLNS.BUSINESS, [
|
|
14
|
+
{
|
|
15
|
+
tag: 'business_profile',
|
|
16
|
+
attrs: { v: `${version}` },
|
|
17
|
+
content: jids.map((jid) => ({
|
|
18
|
+
tag: 'profile',
|
|
19
|
+
attrs: { jid }
|
|
20
|
+
}))
|
|
21
|
+
}
|
|
22
|
+
]);
|
|
23
|
+
}
|
|
24
|
+
function buildEditBusinessProfileIq(input) {
|
|
25
|
+
const children = [];
|
|
26
|
+
if (input.address !== undefined) {
|
|
27
|
+
children.push({ tag: 'address', attrs: {}, content: input.address });
|
|
28
|
+
}
|
|
29
|
+
if (input.description !== undefined) {
|
|
30
|
+
children.push({ tag: 'description', attrs: {}, content: input.description });
|
|
31
|
+
}
|
|
32
|
+
if (input.email !== undefined) {
|
|
33
|
+
children.push({ tag: 'email', attrs: {}, content: input.email });
|
|
34
|
+
}
|
|
35
|
+
if (input.latitude !== undefined) {
|
|
36
|
+
children.push({ tag: 'latitude', attrs: {}, content: `${input.latitude}` });
|
|
37
|
+
}
|
|
38
|
+
if (input.longitude !== undefined) {
|
|
39
|
+
children.push({ tag: 'longitude', attrs: {}, content: `${input.longitude}` });
|
|
40
|
+
}
|
|
41
|
+
if (input.websites !== undefined) {
|
|
42
|
+
if (input.websites.length > 2) {
|
|
43
|
+
throw new Error('business profile supports at most 2 websites');
|
|
44
|
+
}
|
|
45
|
+
if (input.websites.length === 0) {
|
|
46
|
+
children.push({ tag: 'website', attrs: {} });
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
children.push({ tag: 'website', attrs: {}, content: input.websites[0].url });
|
|
50
|
+
if (input.websites.length > 1) {
|
|
51
|
+
children.push({ tag: 'website', attrs: {}, content: input.websites[1].url });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (input.categories !== undefined) {
|
|
56
|
+
children.push({
|
|
57
|
+
tag: 'categories',
|
|
58
|
+
attrs: {},
|
|
59
|
+
content: input.categories.map((cat) => ({
|
|
60
|
+
tag: 'category',
|
|
61
|
+
attrs: { id: cat.id }
|
|
62
|
+
}))
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
if (input.businessHours !== undefined) {
|
|
66
|
+
children.push(buildBusinessHoursNode(input.businessHours));
|
|
67
|
+
}
|
|
68
|
+
return (0, query_1.buildIqNode)('set', constants_1.WA_DEFAULTS.HOST_DOMAIN, constants_1.WA_XMLNS.BUSINESS, [
|
|
69
|
+
{
|
|
70
|
+
tag: 'business_profile',
|
|
71
|
+
attrs: { v: '3', mutation_type: 'delta' },
|
|
72
|
+
content: children
|
|
73
|
+
}
|
|
74
|
+
]);
|
|
75
|
+
}
|
|
76
|
+
function buildBusinessHoursNode(hours) {
|
|
77
|
+
const configNodes = new Array(hours.config.length);
|
|
78
|
+
for (let i = 0; i < hours.config.length; i += 1) {
|
|
79
|
+
const entry = hours.config[i];
|
|
80
|
+
const attrs = {
|
|
81
|
+
day_of_week: entry.dayOfWeek,
|
|
82
|
+
mode: entry.mode
|
|
83
|
+
};
|
|
84
|
+
if (entry.openTime !== undefined) {
|
|
85
|
+
attrs.open_time = `${entry.openTime}`;
|
|
86
|
+
}
|
|
87
|
+
if (entry.closeTime !== undefined) {
|
|
88
|
+
attrs.close_time = `${entry.closeTime}`;
|
|
89
|
+
}
|
|
90
|
+
configNodes[i] = { tag: 'business_hours_config', attrs };
|
|
91
|
+
}
|
|
92
|
+
const hoursAttrs = {};
|
|
93
|
+
if (hours.timezone) {
|
|
94
|
+
hoursAttrs.timezone = hours.timezone;
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
tag: 'business_hours',
|
|
98
|
+
attrs: hoursAttrs,
|
|
99
|
+
content: configNodes
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function buildGetVerifiedNameIq(jid) {
|
|
103
|
+
return (0, query_1.buildIqNode)('get', constants_1.WA_DEFAULTS.HOST_DOMAIN, constants_1.WA_XMLNS.BUSINESS, [
|
|
104
|
+
{
|
|
105
|
+
tag: 'verified_name',
|
|
106
|
+
attrs: { jid }
|
|
107
|
+
}
|
|
108
|
+
]);
|
|
109
|
+
}
|
|
110
|
+
function buildUpdateCoverPhotoIq(id, timestamp, token) {
|
|
111
|
+
return (0, query_1.buildIqNode)('set', constants_1.WA_DEFAULTS.HOST_DOMAIN, constants_1.WA_XMLNS.BUSINESS, [
|
|
112
|
+
{
|
|
113
|
+
tag: 'business_profile',
|
|
114
|
+
attrs: { v: '3', mutation_type: 'delta' },
|
|
115
|
+
content: [
|
|
116
|
+
{
|
|
117
|
+
tag: 'cover_photo',
|
|
118
|
+
attrs: { op: 'update', id, ts: timestamp, token }
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
]);
|
|
123
|
+
}
|
|
124
|
+
function buildDeleteCoverPhotoIq(id) {
|
|
125
|
+
return (0, query_1.buildIqNode)('set', constants_1.WA_DEFAULTS.HOST_DOMAIN, constants_1.WA_XMLNS.BUSINESS, [
|
|
126
|
+
{
|
|
127
|
+
tag: 'business_profile',
|
|
128
|
+
attrs: { v: '3', mutation_type: 'delta' },
|
|
129
|
+
content: [
|
|
130
|
+
{
|
|
131
|
+
tag: 'cover_photo',
|
|
132
|
+
attrs: { op: 'delete', id }
|
|
133
|
+
}
|
|
134
|
+
]
|
|
135
|
+
}
|
|
136
|
+
]);
|
|
137
|
+
}
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildAckNode = buildAckNode;
|
|
4
|
+
exports.buildReceiptNode = buildReceiptNode;
|
|
5
|
+
exports.buildIqResultNode = buildIqResultNode;
|
|
6
|
+
const _protocol_1 = require("../../../protocol/index.js");
|
|
7
|
+
const jid_1 = require("../../../protocol/jid");
|
|
8
|
+
function buildListItemsNode(ids) {
|
|
9
|
+
if (ids.length < 2) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
const items = new Array(ids.length - 1);
|
|
13
|
+
for (let i = 1; i < ids.length; i += 1) {
|
|
14
|
+
items[i - 1] = {
|
|
15
|
+
tag: 'item',
|
|
16
|
+
attrs: { id: ids[i] }
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
tag: _protocol_1.WA_NODE_TAGS.LIST,
|
|
21
|
+
attrs: {},
|
|
22
|
+
content: items
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function normalizeNackClass(stanzaTag) {
|
|
26
|
+
if (stanzaTag === _protocol_1.WA_MESSAGE_TAGS.MESSAGE) {
|
|
27
|
+
return _protocol_1.WA_MESSAGE_TYPES.ACK_CLASS_MESSAGE;
|
|
28
|
+
}
|
|
29
|
+
if (stanzaTag === _protocol_1.WA_MESSAGE_TAGS.RECEIPT) {
|
|
30
|
+
return 'receipt';
|
|
31
|
+
}
|
|
32
|
+
if (stanzaTag === _protocol_1.WA_NODE_TAGS.NOTIFICATION) {
|
|
33
|
+
return _protocol_1.WA_NODE_TAGS.NOTIFICATION;
|
|
34
|
+
}
|
|
35
|
+
return stanzaTag;
|
|
36
|
+
}
|
|
37
|
+
function buildAckNode(input) {
|
|
38
|
+
if (input.kind === 'notification') {
|
|
39
|
+
const attrs = {
|
|
40
|
+
to: input.node.attrs.from ?? _protocol_1.WA_DEFAULTS.HOST_DOMAIN,
|
|
41
|
+
class: _protocol_1.WA_NODE_TAGS.NOTIFICATION
|
|
42
|
+
};
|
|
43
|
+
const includeType = input.includeType ?? true;
|
|
44
|
+
if (includeType) {
|
|
45
|
+
attrs.type = input.typeOverride ?? input.node.attrs.type ?? _protocol_1.WA_NODE_TAGS.NOTIFICATION;
|
|
46
|
+
}
|
|
47
|
+
if (input.node.attrs.id) {
|
|
48
|
+
attrs.id = input.node.attrs.id;
|
|
49
|
+
}
|
|
50
|
+
if (input.includeParticipant && input.node.attrs.participant) {
|
|
51
|
+
attrs.participant = input.node.attrs.participant;
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
tag: _protocol_1.WA_MESSAGE_TAGS.ACK,
|
|
55
|
+
attrs,
|
|
56
|
+
content: input.content
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (input.kind === 'message') {
|
|
60
|
+
const attrs = {
|
|
61
|
+
id: input.id,
|
|
62
|
+
to: input.to,
|
|
63
|
+
class: _protocol_1.WA_MESSAGE_TYPES.ACK_CLASS_MESSAGE
|
|
64
|
+
};
|
|
65
|
+
const type = input.typeOverride ?? input.node.attrs.type;
|
|
66
|
+
if (type) {
|
|
67
|
+
attrs.type = type;
|
|
68
|
+
}
|
|
69
|
+
const participant = input.participant ?? input.node.attrs.participant;
|
|
70
|
+
if (participant) {
|
|
71
|
+
attrs.participant = participant;
|
|
72
|
+
}
|
|
73
|
+
if (input.recipient) {
|
|
74
|
+
attrs.recipient = input.recipient;
|
|
75
|
+
}
|
|
76
|
+
if (input.from) {
|
|
77
|
+
attrs.from = input.from;
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
tag: _protocol_1.WA_MESSAGE_TAGS.ACK,
|
|
81
|
+
attrs
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (input.kind === 'aggregate_message') {
|
|
85
|
+
if (input.ids.length === 0) {
|
|
86
|
+
throw new Error('aggregate message ack requires at least one id');
|
|
87
|
+
}
|
|
88
|
+
const attrs = {
|
|
89
|
+
id: input.ids[0],
|
|
90
|
+
to: input.to,
|
|
91
|
+
class: _protocol_1.WA_MESSAGE_TYPES.ACK_CLASS_MESSAGE,
|
|
92
|
+
type: input.type ?? 'text'
|
|
93
|
+
};
|
|
94
|
+
if (input.recipient) {
|
|
95
|
+
attrs.recipient = input.recipient;
|
|
96
|
+
}
|
|
97
|
+
if (input.participant) {
|
|
98
|
+
attrs.participant = input.participant;
|
|
99
|
+
}
|
|
100
|
+
const listNode = buildListItemsNode(input.ids);
|
|
101
|
+
return {
|
|
102
|
+
tag: _protocol_1.WA_MESSAGE_TAGS.ACK,
|
|
103
|
+
attrs,
|
|
104
|
+
content: listNode ? [listNode] : undefined
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if (input.kind === 'nack') {
|
|
108
|
+
const attrs = {
|
|
109
|
+
id: input.id,
|
|
110
|
+
to: input.to,
|
|
111
|
+
class: normalizeNackClass(input.stanzaTag),
|
|
112
|
+
error: String(input.error)
|
|
113
|
+
};
|
|
114
|
+
if (input.type) {
|
|
115
|
+
attrs.type = input.type;
|
|
116
|
+
}
|
|
117
|
+
if (input.participant) {
|
|
118
|
+
attrs.participant = input.participant;
|
|
119
|
+
}
|
|
120
|
+
const content = input.failureReason === undefined
|
|
121
|
+
? undefined
|
|
122
|
+
: [
|
|
123
|
+
{
|
|
124
|
+
tag: 'meta',
|
|
125
|
+
attrs: {
|
|
126
|
+
failure_reason: String(input.failureReason)
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
];
|
|
130
|
+
return {
|
|
131
|
+
tag: _protocol_1.WA_MESSAGE_TAGS.ACK,
|
|
132
|
+
attrs,
|
|
133
|
+
content
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
if (input.kind === 'custom') {
|
|
137
|
+
const attrs = {
|
|
138
|
+
class: input.ackClass,
|
|
139
|
+
to: input.to
|
|
140
|
+
};
|
|
141
|
+
if (input.id) {
|
|
142
|
+
attrs.id = input.id;
|
|
143
|
+
}
|
|
144
|
+
if (input.type) {
|
|
145
|
+
attrs.type = input.type;
|
|
146
|
+
}
|
|
147
|
+
if (input.participant) {
|
|
148
|
+
attrs.participant = input.participant;
|
|
149
|
+
}
|
|
150
|
+
if (input.recipient) {
|
|
151
|
+
attrs.recipient = input.recipient;
|
|
152
|
+
}
|
|
153
|
+
if (input.from) {
|
|
154
|
+
attrs.from = input.from;
|
|
155
|
+
}
|
|
156
|
+
if (input.error !== undefined) {
|
|
157
|
+
attrs.error = String(input.error);
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
tag: _protocol_1.WA_MESSAGE_TAGS.ACK,
|
|
161
|
+
attrs,
|
|
162
|
+
content: input.content
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
const attrs = {
|
|
166
|
+
class: 'receipt'
|
|
167
|
+
};
|
|
168
|
+
if (input.retryType) {
|
|
169
|
+
attrs.type = input.typeOverride ?? _protocol_1.WA_MESSAGE_TYPES.RECEIPT_TYPE_RETRY;
|
|
170
|
+
}
|
|
171
|
+
else if (input.node.attrs.type) {
|
|
172
|
+
attrs.type = input.node.attrs.type;
|
|
173
|
+
}
|
|
174
|
+
if (input.node.attrs.id) {
|
|
175
|
+
attrs.id = input.node.attrs.id;
|
|
176
|
+
}
|
|
177
|
+
if (input.node.attrs.from) {
|
|
178
|
+
attrs.to = input.node.attrs.from;
|
|
179
|
+
}
|
|
180
|
+
if (input.retryType) {
|
|
181
|
+
if (input.node.attrs.participant) {
|
|
182
|
+
attrs.participant = input.node.attrs.participant;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else if ((input.includeParticipant ?? true) &&
|
|
186
|
+
input.node.attrs.participant &&
|
|
187
|
+
(!input.node.attrs.from || input.node.attrs.participant !== input.node.attrs.from)) {
|
|
188
|
+
attrs.participant = input.node.attrs.participant;
|
|
189
|
+
}
|
|
190
|
+
if (input.includeRecipient && input.node.attrs.recipient) {
|
|
191
|
+
attrs.recipient = input.node.attrs.recipient;
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
tag: _protocol_1.WA_MESSAGE_TAGS.ACK,
|
|
195
|
+
attrs
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function buildReceiptNode(input) {
|
|
199
|
+
if (input.kind === 'delivery') {
|
|
200
|
+
const attrs = {
|
|
201
|
+
id: input.id,
|
|
202
|
+
to: input.to
|
|
203
|
+
};
|
|
204
|
+
if (input.node.attrs.participant && (0, jid_1.isGroupOrBroadcastJid)(input.to)) {
|
|
205
|
+
attrs.participant = input.node.attrs.participant;
|
|
206
|
+
}
|
|
207
|
+
if (input.node.attrs.category === 'peer') {
|
|
208
|
+
attrs.type = _protocol_1.WA_MESSAGE_TYPES.RECEIPT_TYPE_PEER;
|
|
209
|
+
}
|
|
210
|
+
return {
|
|
211
|
+
tag: _protocol_1.WA_MESSAGE_TAGS.RECEIPT,
|
|
212
|
+
attrs
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
if (input.kind === 'outbound') {
|
|
216
|
+
const attrs = {
|
|
217
|
+
id: input.id,
|
|
218
|
+
to: input.to
|
|
219
|
+
};
|
|
220
|
+
if (input.type) {
|
|
221
|
+
attrs.type = input.type;
|
|
222
|
+
}
|
|
223
|
+
if (input.participant) {
|
|
224
|
+
attrs.participant = input.participant;
|
|
225
|
+
}
|
|
226
|
+
if (input.recipient) {
|
|
227
|
+
attrs.recipient = input.recipient;
|
|
228
|
+
}
|
|
229
|
+
if (input.category) {
|
|
230
|
+
attrs.category = input.category;
|
|
231
|
+
}
|
|
232
|
+
if (input.from) {
|
|
233
|
+
attrs.from = input.from;
|
|
234
|
+
}
|
|
235
|
+
if (input.t) {
|
|
236
|
+
attrs.t = input.t;
|
|
237
|
+
}
|
|
238
|
+
if (input.peerParticipantPn) {
|
|
239
|
+
attrs.peer_participant_pn = input.peerParticipantPn;
|
|
240
|
+
}
|
|
241
|
+
const content = input.content ? [...input.content] : [];
|
|
242
|
+
const listNode = input.listIds ? buildListItemsNode(input.listIds) : null;
|
|
243
|
+
if (listNode) {
|
|
244
|
+
content.push(listNode);
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
tag: _protocol_1.WA_MESSAGE_TAGS.RECEIPT,
|
|
248
|
+
attrs,
|
|
249
|
+
content: content.length > 0 ? content : undefined
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
if (input.kind === 'retry_custom') {
|
|
253
|
+
const attrs = {
|
|
254
|
+
id: input.id,
|
|
255
|
+
to: input.to,
|
|
256
|
+
type: _protocol_1.WA_MESSAGE_TYPES.RECEIPT_TYPE_RETRY
|
|
257
|
+
};
|
|
258
|
+
if (input.participant) {
|
|
259
|
+
attrs.participant = input.participant;
|
|
260
|
+
}
|
|
261
|
+
if (input.recipient) {
|
|
262
|
+
attrs.recipient = input.recipient;
|
|
263
|
+
}
|
|
264
|
+
if (input.categoryPeer) {
|
|
265
|
+
attrs.category = 'peer';
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
tag: _protocol_1.WA_MESSAGE_TAGS.RECEIPT,
|
|
269
|
+
attrs,
|
|
270
|
+
content: input.content
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
if (input.kind === 'server_error') {
|
|
274
|
+
const attrs = {
|
|
275
|
+
id: input.id,
|
|
276
|
+
to: input.to,
|
|
277
|
+
type: _protocol_1.WA_MESSAGE_TYPES.RECEIPT_TYPE_SERVER_ERROR
|
|
278
|
+
};
|
|
279
|
+
if (input.categoryPeer) {
|
|
280
|
+
attrs.category = 'peer';
|
|
281
|
+
}
|
|
282
|
+
const content = [
|
|
283
|
+
{
|
|
284
|
+
tag: 'encrypt',
|
|
285
|
+
attrs: {},
|
|
286
|
+
content: [
|
|
287
|
+
{
|
|
288
|
+
tag: 'enc_p',
|
|
289
|
+
attrs: {},
|
|
290
|
+
content: input.encryptCiphertext
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
tag: 'enc_iv',
|
|
294
|
+
attrs: {},
|
|
295
|
+
content: input.encryptIv
|
|
296
|
+
}
|
|
297
|
+
]
|
|
298
|
+
}
|
|
299
|
+
];
|
|
300
|
+
if (input.rmrJid || input.rmrFromMe !== undefined || input.rmrParticipant) {
|
|
301
|
+
const rmrAttrs = {};
|
|
302
|
+
if (input.rmrJid) {
|
|
303
|
+
rmrAttrs.jid = input.rmrJid;
|
|
304
|
+
}
|
|
305
|
+
if (input.rmrFromMe !== undefined) {
|
|
306
|
+
rmrAttrs.from_me = String(input.rmrFromMe);
|
|
307
|
+
}
|
|
308
|
+
if (input.rmrParticipant) {
|
|
309
|
+
rmrAttrs.participant = input.rmrParticipant;
|
|
310
|
+
}
|
|
311
|
+
content.push({
|
|
312
|
+
tag: 'rmr',
|
|
313
|
+
attrs: rmrAttrs
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
return {
|
|
317
|
+
tag: _protocol_1.WA_MESSAGE_TAGS.RECEIPT,
|
|
318
|
+
attrs,
|
|
319
|
+
content
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
if (input.kind === 'custom') {
|
|
323
|
+
return {
|
|
324
|
+
tag: _protocol_1.WA_MESSAGE_TAGS.RECEIPT,
|
|
325
|
+
attrs: {
|
|
326
|
+
...input.attrs
|
|
327
|
+
},
|
|
328
|
+
content: input.content
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
const attrs = {
|
|
332
|
+
id: input.id,
|
|
333
|
+
to: input.to,
|
|
334
|
+
type: _protocol_1.WA_MESSAGE_TYPES.RECEIPT_TYPE_RETRY
|
|
335
|
+
};
|
|
336
|
+
if (input.node.attrs.category === 'peer') {
|
|
337
|
+
attrs.category = 'peer';
|
|
338
|
+
}
|
|
339
|
+
if (input.node.attrs.recipient && input.node.attrs.category !== 'peer') {
|
|
340
|
+
attrs.recipient = input.node.attrs.recipient;
|
|
341
|
+
}
|
|
342
|
+
if (input.node.attrs.participant && (0, jid_1.isGroupOrBroadcastJid)(input.to)) {
|
|
343
|
+
attrs.participant = input.node.attrs.participant;
|
|
344
|
+
}
|
|
345
|
+
const retryCount = input.retryCount ?? 1;
|
|
346
|
+
const normalizedRetryCount = Number.isSafeInteger(retryCount) && retryCount > 0 ? retryCount : 1;
|
|
347
|
+
const retryAttrs = {
|
|
348
|
+
count: String(normalizedRetryCount),
|
|
349
|
+
id: input.id
|
|
350
|
+
};
|
|
351
|
+
const timestamp = input.node.attrs.t;
|
|
352
|
+
if (timestamp) {
|
|
353
|
+
retryAttrs.t = timestamp;
|
|
354
|
+
}
|
|
355
|
+
return {
|
|
356
|
+
tag: _protocol_1.WA_MESSAGE_TAGS.RECEIPT,
|
|
357
|
+
attrs,
|
|
358
|
+
content: [
|
|
359
|
+
{
|
|
360
|
+
tag: 'retry',
|
|
361
|
+
attrs: retryAttrs
|
|
362
|
+
}
|
|
363
|
+
]
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
function buildIqResultNode(iqNode) {
|
|
367
|
+
return {
|
|
368
|
+
tag: _protocol_1.WA_NODE_TAGS.IQ,
|
|
369
|
+
attrs: {
|
|
370
|
+
...(iqNode.attrs.id ? { id: iqNode.attrs.id } : {}),
|
|
371
|
+
to: iqNode.attrs.from ?? _protocol_1.WA_DEFAULTS.HOST_DOMAIN,
|
|
372
|
+
type: _protocol_1.WA_IQ_TYPES.RESULT
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
}
|