zapo-js 0.3.0 → 1.0.1
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/LICENSE +21 -0
- package/README.md +98 -178
- package/dist/appstate/{WaAppStateCrypto.js → crypto/WaAppStateCrypto.js} +58 -49
- package/dist/appstate/index.js +7 -6
- package/dist/appstate/{encoding.js → parsers/encoding.js} +11 -4
- package/dist/appstate/{response-parser.js → parsers/response-parser.js} +20 -8
- package/dist/appstate/{WaAppStateSyncClient.js → sync/WaAppStateSyncClient.js} +174 -53
- package/dist/appstate/utils.js +16 -0
- package/dist/appstate-spec.js +89 -0
- package/dist/auth/WaAuthClient.js +100 -5
- package/dist/auth/credentials-flow.js +20 -8
- package/dist/auth/pairing/WaPairingFlow.js +35 -26
- package/dist/auth/pairing/pairing-code-crypto.js +17 -19
- package/dist/client/WaClient.js +343 -474
- package/dist/client/WaClientFactory.js +281 -78
- package/dist/client/connection/WaConnectionManager.js +28 -11
- package/dist/client/coordinators/WaAbPropsCoordinator.js +1 -2
- package/dist/client/coordinators/WaAppStateMutationCoordinator.js +663 -143
- package/dist/client/coordinators/WaBotCoordinator.js +345 -0
- package/dist/client/coordinators/WaBroadcastListCoordinator.js +20 -0
- package/dist/client/coordinators/WaBusinessCoordinator.js +81 -171
- package/dist/client/coordinators/WaEmailCoordinator.js +1 -0
- package/dist/client/coordinators/WaGroupCoordinator.js +529 -52
- package/dist/client/coordinators/WaIncomingNodeCoordinator.js +97 -12
- package/dist/client/coordinators/WaLowLevelCoordinator.js +41 -0
- package/dist/client/coordinators/WaMessageCoordinator.js +365 -0
- package/dist/client/coordinators/WaMessageDispatchCoordinator.js +685 -207
- package/dist/client/coordinators/WaNewsletterCoordinator.js +18 -0
- package/dist/client/coordinators/WaPassiveTasksCoordinator.js +17 -4
- package/dist/client/coordinators/WaPresenceCoordinator.js +21 -0
- package/dist/client/coordinators/WaPrivacyCoordinator.js +7 -5
- package/dist/client/coordinators/WaProfileCoordinator.js +220 -49
- package/dist/client/coordinators/WaRetryCoordinator.js +257 -126
- package/dist/client/coordinators/WaStatusCoordinator.js +49 -0
- package/dist/client/coordinators/WaStreamControlCoordinator.js +8 -9
- package/dist/client/coordinators/WaTrustedContactTokenCoordinator.js +7 -6
- package/dist/client/events/appstate-mutation.js +133 -0
- package/dist/client/events/business.js +375 -0
- package/dist/client/events/call.js +58 -0
- package/dist/client/events/chatstate.js +23 -0
- package/dist/client/events/devices.js +15 -16
- package/dist/client/{dirty.js → events/dirty.js} +33 -19
- package/dist/client/events/group.js +13 -24
- package/dist/client/events/identity.js +2 -1
- package/dist/client/events/incoming.js +502 -0
- package/dist/client/events/mex-notification.js +181 -0
- package/dist/client/events/picture.js +33 -0
- package/dist/client/events/presence.js +44 -0
- package/dist/client/events/receipt.js +26 -0
- package/dist/client/media.js +163 -6
- package/dist/client/messaging/fanout.js +9 -10
- package/dist/client/messaging/{participants.js → group-metadata.js} +93 -44
- package/dist/client/messaging/ignore-key.js +132 -0
- package/dist/client/messaging/key-protocol.js +4 -18
- package/dist/client/messaging/link-preview.js +159 -0
- package/dist/client/messaging/messages.js +671 -0
- package/dist/client/newsletter/admin.js +165 -0
- package/dist/client/newsletter/content.js +253 -0
- package/dist/client/newsletter/discovery.js +115 -0
- package/dist/client/newsletter/messaging.js +197 -0
- package/dist/client/newsletter/mex.js +41 -0
- package/dist/client/newsletter/parse.js +217 -0
- package/dist/client/persistence/WriteBehindPersistence.js +31 -4
- package/dist/client/{history-sync.js → persistence/history-sync.js} +125 -18
- package/dist/client/persistence/mailbox.js +104 -0
- package/dist/client/tokens/cs-token.js +11 -17
- package/dist/crypto/core/hkdf.js +12 -12
- package/dist/crypto/core/index.js +6 -8
- package/dist/crypto/core/keys.js +1 -8
- package/dist/crypto/core/nonce.js +12 -12
- package/dist/crypto/core/primitives.js +123 -93
- package/dist/crypto/core/random.js +6 -0
- package/dist/crypto/core/xeddsa.js +11 -9
- package/dist/crypto/curves/Ed25519.js +32 -21
- package/dist/crypto/curves/X25519.js +70 -34
- package/dist/crypto/curves/constants.js +2 -1
- package/dist/crypto/math/constants.js +1 -2
- package/dist/crypto/math/mod.js +0 -33
- package/dist/esm/appstate/{WaAppStateCrypto.js → crypto/WaAppStateCrypto.js} +58 -49
- package/dist/esm/appstate/index.js +5 -5
- package/dist/esm/appstate/{encoding.js → parsers/encoding.js} +11 -4
- package/dist/esm/appstate/{response-parser.js → parsers/response-parser.js} +20 -8
- package/dist/esm/appstate/{WaAppStateSyncClient.js → sync/WaAppStateSyncClient.js} +174 -52
- package/dist/esm/appstate/utils.js +16 -0
- package/dist/esm/appstate-spec.js +79 -0
- package/dist/esm/auth/WaAuthClient.js +100 -5
- package/dist/esm/auth/credentials-flow.js +18 -6
- package/dist/esm/auth/pairing/WaPairingFlow.js +34 -25
- package/dist/esm/auth/pairing/pairing-code-crypto.js +12 -14
- package/dist/esm/client/WaClient.js +345 -476
- package/dist/esm/client/WaClientFactory.js +282 -79
- package/dist/esm/client/connection/WaConnectionManager.js +28 -11
- package/dist/esm/client/coordinators/WaAbPropsCoordinator.js +2 -3
- package/dist/esm/client/coordinators/WaAppStateMutationCoordinator.js +665 -145
- package/dist/esm/client/coordinators/WaBotCoordinator.js +342 -0
- package/dist/esm/client/coordinators/WaBroadcastListCoordinator.js +17 -0
- package/dist/esm/client/coordinators/WaBusinessCoordinator.js +79 -169
- package/dist/esm/client/coordinators/WaEmailCoordinator.js +1 -0
- package/dist/esm/client/coordinators/WaGroupCoordinator.js +532 -55
- package/dist/esm/client/coordinators/WaIncomingNodeCoordinator.js +98 -13
- package/dist/esm/client/coordinators/WaLowLevelCoordinator.js +38 -0
- package/dist/esm/client/coordinators/WaMessageCoordinator.js +361 -0
- package/dist/esm/client/coordinators/WaMessageDispatchCoordinator.js +686 -208
- package/dist/esm/client/coordinators/WaNewsletterCoordinator.js +13 -0
- package/dist/esm/client/coordinators/WaPassiveTasksCoordinator.js +18 -5
- package/dist/esm/client/coordinators/WaPresenceCoordinator.js +18 -0
- package/dist/esm/client/coordinators/WaPrivacyCoordinator.js +7 -5
- package/dist/esm/client/coordinators/WaProfileCoordinator.js +223 -52
- package/dist/esm/client/coordinators/WaRetryCoordinator.js +258 -127
- package/dist/esm/client/coordinators/WaStatusCoordinator.js +46 -0
- package/dist/esm/client/coordinators/WaStreamControlCoordinator.js +8 -9
- package/dist/esm/client/coordinators/WaTrustedContactTokenCoordinator.js +7 -6
- package/dist/esm/client/events/appstate-mutation.js +130 -0
- package/dist/esm/client/events/business.js +370 -0
- package/dist/esm/client/events/call.js +55 -0
- package/dist/esm/client/events/chatstate.js +20 -0
- package/dist/esm/client/events/devices.js +15 -16
- package/dist/esm/client/{dirty.js → events/dirty.js} +33 -19
- package/dist/esm/client/events/group.js +14 -25
- package/dist/esm/client/events/identity.js +2 -1
- package/dist/esm/client/events/incoming.js +487 -0
- package/dist/esm/client/events/mex-notification.js +178 -0
- package/dist/esm/client/events/picture.js +30 -0
- package/dist/esm/client/events/presence.js +41 -0
- package/dist/esm/client/events/receipt.js +23 -0
- package/dist/esm/client/media.js +158 -8
- package/dist/esm/client/messaging/fanout.js +10 -11
- package/dist/esm/client/messaging/{participants.js → group-metadata.js} +92 -43
- package/dist/esm/client/messaging/ignore-key.js +126 -0
- package/dist/esm/client/messaging/key-protocol.js +3 -17
- package/dist/esm/client/messaging/link-preview.js +156 -0
- package/dist/esm/client/messaging/messages.js +667 -0
- package/dist/esm/client/newsletter/admin.js +162 -0
- package/dist/esm/client/newsletter/content.js +249 -0
- package/dist/esm/client/newsletter/discovery.js +112 -0
- package/dist/esm/client/newsletter/messaging.js +194 -0
- package/dist/esm/client/newsletter/mex.js +37 -0
- package/dist/esm/client/newsletter/parse.js +200 -0
- package/dist/esm/client/persistence/WriteBehindPersistence.js +31 -4
- package/dist/esm/client/{history-sync.js → persistence/history-sync.js} +124 -18
- package/dist/esm/client/persistence/mailbox.js +101 -0
- package/dist/esm/client/tokens/cs-token.js +12 -18
- package/dist/esm/crypto/core/hkdf.js +14 -14
- package/dist/esm/crypto/core/index.js +2 -2
- package/dist/esm/crypto/core/keys.js +1 -7
- package/dist/esm/crypto/core/nonce.js +11 -11
- package/dist/esm/crypto/core/primitives.js +121 -88
- package/dist/esm/crypto/core/random.js +6 -0
- package/dist/esm/crypto/core/xeddsa.js +11 -9
- package/dist/esm/crypto/curves/Ed25519.js +35 -24
- package/dist/esm/crypto/curves/X25519.js +72 -36
- package/dist/esm/crypto/curves/constants.js +1 -0
- package/dist/esm/crypto/math/constants.js +1 -2
- package/dist/esm/crypto/math/mod.js +0 -32
- package/dist/esm/index.js +7 -2
- package/dist/esm/infra/log/ConsoleLogger.js +30 -6
- package/dist/esm/infra/log/PinoLogger.js +64 -0
- package/dist/esm/infra/log/types.js +4 -2
- package/dist/esm/infra/perf/BackgroundQueue.js +55 -13
- package/dist/esm/media/constants.js +33 -2
- package/dist/esm/media/crypto/WaMediaCrypto.js +374 -0
- package/dist/esm/media/index.js +4 -3
- package/dist/esm/media/sticker/sticker-pack.js +133 -0
- package/dist/esm/media/{WaMediaTransferClient.js → transfer/WaMediaTransferClient.js} +37 -6
- package/dist/esm/media/{conn.js → transfer/conn.js} +10 -5
- package/dist/esm/message/WaMessageClient.js +46 -15
- package/dist/esm/message/addons/link-preview/builder.js +36 -0
- package/dist/esm/message/addons/link-preview/detect.js +55 -0
- package/dist/esm/message/addons/link-preview/fetcher.js +391 -0
- package/dist/esm/message/addons/link-preview/types.js +1 -0
- package/dist/esm/message/context-info.js +123 -0
- package/dist/esm/message/{addon-crypto.js → crypto/addon-crypto.js} +68 -10
- package/dist/esm/message/{icdc.js → crypto/icdc.js} +5 -7
- package/dist/esm/message/crypto/phash.js +133 -0
- package/dist/esm/message/{reporting-token.js → crypto/reporting-token.js} +6 -6
- package/dist/esm/message/{use-case-secret.js → crypto/use-case-secret.js} +20 -3
- package/dist/esm/message/{content.js → encode/content.js} +176 -7
- package/dist/esm/message/encode/media-payload.js +42 -0
- package/dist/esm/message/{padding.js → encode/padding.js} +9 -3
- package/dist/esm/message/index.js +2 -2
- package/dist/esm/message/kinds/bot.js +111 -0
- package/dist/esm/message/kinds/newsletter.js +244 -0
- package/dist/esm/message/kinds/sticker-pack.js +29 -0
- package/dist/esm/message/{ack.js → primitives/ack.js} +8 -1
- package/dist/esm/message/{incoming.js → primitives/incoming.js} +215 -31
- package/dist/esm/message/primitives/peer-data-operation.js +93 -0
- package/dist/esm/mex.js +1 -0
- package/dist/esm/protocol/abprops.js +10 -0
- package/dist/esm/protocol/appstate.js +6 -30
- package/dist/esm/protocol/auth.js +3 -2
- package/dist/esm/protocol/bot.js +77 -0
- package/dist/esm/protocol/browser.js +8 -0
- package/dist/esm/protocol/business.js +19 -0
- package/dist/esm/protocol/call.js +48 -0
- package/dist/esm/protocol/constants.js +8 -2
- package/dist/esm/protocol/defaults.js +3 -0
- package/dist/esm/protocol/index.js +1 -1
- package/dist/esm/protocol/jid.js +102 -5
- package/dist/esm/protocol/media.js +25 -12
- package/dist/esm/protocol/message.js +4 -1
- package/dist/esm/protocol/newsletter.js +61 -0
- package/dist/esm/protocol/nodes.js +22 -2
- package/dist/esm/protocol/notification.js +18 -2
- package/dist/esm/protocol/presence.js +13 -0
- package/dist/esm/protocol/status.js +6 -0
- package/dist/esm/retry/codec.js +5 -0
- package/dist/esm/retry/parse.js +20 -38
- package/dist/esm/retry/reason.js +5 -0
- package/dist/esm/retry/replay.js +131 -37
- package/dist/esm/retry/tracker.js +4 -8
- package/dist/esm/signal/api/SignalDeviceSyncApi.js +69 -20
- package/dist/esm/signal/api/SignalDigestSyncApi.js +7 -2
- package/dist/esm/signal/api/SignalIdentitySyncApi.js +9 -0
- package/dist/esm/signal/api/SignalMissingPreKeysSyncApi.js +24 -63
- package/dist/esm/signal/api/SignalRotateKeyApi.js +10 -0
- package/dist/esm/signal/api/SignalSessionSyncApi.js +23 -51
- package/dist/esm/signal/api/codec.js +52 -1
- package/dist/esm/signal/api/prekeys.js +4 -0
- package/dist/esm/signal/{crypto → attestation}/WaAdvSignature.js +5 -6
- package/dist/esm/signal/constants.js +3 -0
- package/dist/esm/signal/encoding.js +6 -289
- package/dist/esm/signal/group/SenderKeyChain.js +18 -33
- package/dist/esm/signal/group/SenderKeyManager.js +25 -8
- package/dist/esm/signal/group/encoding.js +96 -0
- package/dist/esm/signal/index.js +4 -1
- package/dist/esm/signal/registration/encoding.js +34 -0
- package/dist/esm/signal/registration/keygen.js +10 -0
- package/dist/esm/signal/registration/utils.js +8 -1
- package/dist/esm/signal/session/SignalProtocol.js +113 -11
- package/dist/esm/signal/session/SignalRatchet.js +29 -58
- package/dist/esm/signal/session/SignalSession.js +7 -14
- package/dist/esm/signal/session/encoding.js +173 -0
- package/dist/esm/signal/session/resolver.js +139 -30
- package/dist/esm/store/cache/identity.cache.js +75 -0
- package/dist/esm/store/cache/privacy-token.cache.js +57 -0
- package/dist/esm/store/cache/sender-key.cache.js +101 -0
- package/dist/esm/store/cache/session.cache.js +92 -0
- package/dist/esm/store/contracts/group-metadata.store.js +1 -0
- package/dist/esm/store/createStore.js +91 -37
- package/dist/esm/store/index.js +15 -14
- package/dist/esm/store/locks/contact.lock.js +1 -0
- package/dist/esm/store/locks/device-list.lock.js +1 -0
- package/dist/esm/store/locks/group-metadata.lock.js +20 -0
- package/dist/esm/store/locks/pre-key.lock.js +4 -1
- package/dist/esm/store/{providers/memory → memory}/appstate.store.js +5 -5
- package/dist/esm/store/memory/auth.store.js +24 -0
- package/dist/esm/store/memory/contact.store.js +79 -0
- package/dist/esm/store/memory/device-list.store.js +103 -0
- package/dist/esm/store/{providers/memory/participants.store.js → memory/group-metadata.store.js} +22 -13
- package/dist/esm/store/{providers/memory → memory}/identity.store.js +3 -3
- package/dist/esm/store/{providers/memory → memory}/message-secret.store.js +17 -8
- package/dist/esm/store/{providers/memory → memory}/message.store.js +2 -2
- package/dist/esm/store/{providers/memory → memory}/pre-key.store.js +2 -2
- package/dist/esm/store/{providers/memory → memory}/privacy-token.store.js +1 -1
- package/dist/esm/store/{providers/memory → memory}/retry.store.js +28 -7
- package/dist/esm/store/{providers/memory → memory}/sender-key.store.js +3 -3
- package/dist/esm/store/{providers/memory → memory}/session.store.js +3 -3
- package/dist/esm/store/{providers/memory → memory}/thread.store.js +2 -2
- package/dist/esm/store/noop.store.js +6 -4
- package/dist/esm/transport/WaComms.js +14 -5
- package/dist/esm/transport/WaWebSocket.js +32 -8
- package/dist/esm/transport/binary/constants.js +10 -4
- package/dist/esm/transport/binary/decoder.js +21 -15
- package/dist/esm/transport/binary/encoder.js +96 -21
- package/dist/esm/transport/binary/tokens.js +12 -12
- package/dist/esm/transport/index.js +1 -0
- package/dist/esm/transport/keepalive/WaKeepAlive.js +18 -4
- package/dist/esm/transport/node/WaMobileTcpSocket.js +6 -0
- package/dist/esm/transport/node/WaNodeOrchestrator.js +9 -5
- package/dist/esm/transport/node/WaNodeTransport.js +13 -0
- package/dist/esm/transport/node/builders/abprops.js +2 -2
- package/dist/esm/transport/node/builders/account-sync.js +7 -15
- package/dist/esm/transport/node/builders/bot.js +38 -0
- package/dist/esm/transport/node/builders/business.js +30 -30
- package/dist/esm/transport/node/builders/chatstate.js +28 -0
- package/dist/esm/transport/node/builders/community.js +53 -0
- package/dist/esm/transport/node/builders/device.js +2 -2
- package/dist/esm/transport/node/builders/email.js +6 -5
- package/dist/esm/transport/node/builders/global.js +1 -1
- package/dist/esm/transport/node/builders/group.js +114 -4
- package/dist/esm/transport/node/builders/media.js +2 -2
- package/dist/esm/transport/node/builders/message.js +83 -49
- package/dist/esm/transport/node/builders/newsletter.js +176 -0
- package/dist/esm/transport/node/builders/passive.js +7 -0
- package/dist/esm/transport/node/builders/prekeys.js +4 -4
- package/dist/esm/transport/node/builders/presence.js +27 -1
- package/dist/esm/transport/node/builders/privacy-token.js +2 -2
- package/dist/esm/transport/node/builders/privacy.js +6 -6
- package/dist/esm/transport/node/builders/profile.js +28 -8
- package/dist/esm/transport/node/builders/tos.js +58 -0
- package/dist/esm/transport/node/builders/usync.js +51 -2
- package/dist/esm/transport/node/helpers.js +3 -1
- package/dist/esm/transport/node/mex/argo-decoder.js +2 -2
- package/dist/esm/transport/node/mex/client.js +22 -0
- package/dist/esm/transport/node/query.js +17 -0
- package/dist/esm/transport/node/usync.js +12 -0
- package/dist/esm/transport/noise/WaClientPayload.js +8 -8
- package/dist/esm/transport/noise/WaMobileClientPayload.js +5 -0
- package/dist/esm/transport/noise/WaNoiseCert.js +5 -0
- package/dist/esm/transport/noise/WaNoiseHandshake.js +27 -25
- package/dist/esm/transport/noise/WaNoiseSession.js +39 -59
- package/dist/esm/transport/noise/WaNoiseSocket.js +19 -13
- package/dist/esm/transport/noise/constants.js +0 -1
- package/dist/esm/transport/proxy.js +5 -0
- package/dist/esm/transport/stream/parse.js +3 -7
- package/dist/esm/transport/wa-web-version-fetcher.js +91 -0
- package/dist/esm/util/async.js +4 -0
- package/dist/esm/util/bytes.js +37 -2
- package/dist/esm/util/clock.js +15 -0
- package/dist/esm/util/coercion.js +45 -3
- package/dist/esm/util/collections.js +11 -0
- package/dist/esm/util/index.js +2 -2
- package/dist/esm/util/primitives.js +19 -0
- package/dist/esm/util/runtime.js +5 -0
- package/dist/esm/version-spec.js +1 -0
- package/dist/index.js +35 -5
- package/dist/infra/log/ConsoleLogger.js +30 -6
- package/dist/infra/log/PinoLogger.js +64 -0
- package/dist/infra/log/types.js +4 -2
- package/dist/infra/perf/BackgroundQueue.js +55 -13
- package/dist/media/constants.js +34 -3
- package/dist/media/crypto/WaMediaCrypto.js +378 -0
- package/dist/media/index.js +9 -4
- package/dist/media/sticker/sticker-pack.js +136 -0
- package/dist/media/{WaMediaTransferClient.js → transfer/WaMediaTransferClient.js} +37 -6
- package/dist/media/{conn.js → transfer/conn.js} +10 -5
- package/dist/message/WaMessageClient.js +46 -15
- package/dist/message/addons/link-preview/builder.js +39 -0
- package/dist/message/addons/link-preview/detect.js +58 -0
- package/dist/message/addons/link-preview/fetcher.js +394 -0
- package/dist/message/addons/link-preview/types.js +2 -0
- package/dist/message/context-info.js +129 -0
- package/dist/message/{addon-crypto.js → crypto/addon-crypto.js} +68 -10
- package/dist/message/{icdc.js → crypto/icdc.js} +5 -7
- package/dist/message/crypto/phash.js +136 -0
- package/dist/message/{reporting-token.js → crypto/reporting-token.js} +6 -6
- package/dist/message/{use-case-secret.js → crypto/use-case-secret.js} +20 -3
- package/dist/message/{content.js → encode/content.js} +192 -7
- package/dist/message/encode/media-payload.js +45 -0
- package/dist/message/{padding.js → encode/padding.js} +9 -3
- package/dist/message/index.js +2 -2
- package/dist/message/kinds/bot.js +120 -0
- package/dist/message/kinds/newsletter.js +248 -0
- package/dist/message/kinds/sticker-pack.js +34 -0
- package/dist/message/{ack.js → primitives/ack.js} +8 -1
- package/dist/message/{incoming.js → primitives/incoming.js} +216 -31
- package/dist/message/primitives/peer-data-operation.js +96 -0
- package/dist/mex.js +6 -0
- package/dist/proto.js +1 -1
- package/dist/protocol/abprops.js +10 -0
- package/dist/protocol/appstate.js +7 -31
- package/dist/protocol/auth.js +3 -2
- package/dist/protocol/bot.js +81 -0
- package/dist/protocol/browser.js +8 -0
- package/dist/protocol/business.js +22 -0
- package/dist/protocol/call.js +51 -0
- package/dist/protocol/constants.js +39 -3
- package/dist/protocol/defaults.js +3 -0
- package/dist/protocol/index.js +12 -3
- package/dist/protocol/jid.js +107 -5
- package/dist/protocol/media.js +25 -12
- package/dist/protocol/message.js +4 -1
- package/dist/protocol/newsletter.js +64 -0
- package/dist/protocol/nodes.js +22 -2
- package/dist/protocol/notification.js +19 -3
- package/dist/protocol/presence.js +16 -0
- package/dist/protocol/status.js +9 -0
- package/dist/retry/codec.js +5 -0
- package/dist/retry/parse.js +16 -34
- package/dist/retry/reason.js +5 -0
- package/dist/retry/replay.js +130 -36
- package/dist/retry/tracker.js +3 -7
- package/dist/signal/api/SignalDeviceSyncApi.js +67 -18
- package/dist/signal/api/SignalDigestSyncApi.js +7 -2
- package/dist/signal/api/SignalIdentitySyncApi.js +9 -0
- package/dist/signal/api/SignalMissingPreKeysSyncApi.js +21 -60
- package/dist/signal/api/SignalRotateKeyApi.js +10 -0
- package/dist/signal/api/SignalSessionSyncApi.js +20 -48
- package/dist/signal/api/codec.js +52 -0
- package/dist/signal/api/prekeys.js +4 -0
- package/dist/signal/{crypto → attestation}/WaAdvSignature.js +6 -8
- package/dist/signal/constants.js +4 -1
- package/dist/signal/encoding.js +5 -303
- package/dist/signal/group/SenderKeyChain.js +18 -33
- package/dist/signal/group/SenderKeyCodec.js +2 -2
- package/dist/signal/group/SenderKeyManager.js +26 -9
- package/dist/signal/group/encoding.js +101 -0
- package/dist/signal/index.js +13 -10
- package/dist/signal/registration/encoding.js +39 -0
- package/dist/signal/registration/keygen.js +11 -1
- package/dist/signal/registration/utils.js +8 -1
- package/dist/signal/session/SignalProtocol.js +113 -11
- package/dist/signal/session/SignalRatchet.js +26 -56
- package/dist/signal/session/SignalSerializer.js +2 -2
- package/dist/signal/session/SignalSession.js +7 -15
- package/dist/signal/session/encoding.js +183 -0
- package/dist/signal/session/resolver.js +139 -30
- package/dist/store/cache/identity.cache.js +78 -0
- package/dist/store/cache/privacy-token.cache.js +60 -0
- package/dist/store/cache/sender-key.cache.js +104 -0
- package/dist/store/cache/session.cache.js +95 -0
- package/dist/store/contracts/group-metadata.store.js +2 -0
- package/dist/store/createStore.js +90 -36
- package/dist/store/index.js +18 -16
- package/dist/store/locks/contact.lock.js +1 -0
- package/dist/store/locks/device-list.lock.js +1 -0
- package/dist/store/locks/group-metadata.lock.js +23 -0
- package/dist/store/locks/pre-key.lock.js +4 -1
- package/dist/store/{providers/memory → memory}/appstate.store.js +5 -5
- package/dist/store/memory/auth.store.js +28 -0
- package/dist/store/memory/contact.store.js +83 -0
- package/dist/store/memory/device-list.store.js +107 -0
- package/dist/store/{providers/memory/participants.store.js → memory/group-metadata.store.js} +24 -15
- package/dist/store/{providers/memory → memory}/identity.store.js +3 -3
- package/dist/store/{providers/memory → memory}/message-secret.store.js +17 -8
- package/dist/store/{providers/memory → memory}/message.store.js +2 -2
- package/dist/store/{providers/memory → memory}/pre-key.store.js +2 -2
- package/dist/store/{providers/memory → memory}/privacy-token.store.js +1 -1
- package/dist/store/{providers/memory → memory}/retry.store.js +28 -7
- package/dist/store/{providers/memory → memory}/sender-key.store.js +3 -3
- package/dist/store/{providers/memory → memory}/session.store.js +3 -3
- package/dist/store/{providers/memory → memory}/thread.store.js +2 -2
- package/dist/store/noop.store.js +7 -5
- package/dist/transport/WaComms.js +14 -5
- package/dist/transport/WaWebSocket.js +32 -8
- package/dist/transport/binary/constants.js +11 -5
- package/dist/transport/binary/decoder.js +24 -18
- package/dist/transport/binary/encoder.js +109 -34
- package/dist/transport/binary/tokens.js +12 -12
- package/dist/transport/index.js +3 -1
- package/dist/transport/keepalive/WaKeepAlive.js +18 -4
- package/dist/transport/node/WaMobileTcpSocket.js +6 -0
- package/dist/transport/node/WaNodeOrchestrator.js +9 -5
- package/dist/transport/node/WaNodeTransport.js +13 -0
- package/dist/transport/node/builders/abprops.js +1 -1
- package/dist/transport/node/builders/account-sync.js +7 -16
- package/dist/transport/node/builders/bot.js +43 -0
- package/dist/transport/node/builders/business.js +31 -31
- package/dist/transport/node/builders/chatstate.js +31 -0
- package/dist/transport/node/builders/community.js +59 -0
- package/dist/transport/node/builders/device.js +1 -1
- package/dist/transport/node/builders/email.js +6 -5
- package/dist/transport/node/builders/global.js +2 -2
- package/dist/transport/node/builders/group.js +121 -3
- package/dist/transport/node/builders/media.js +1 -1
- package/dist/transport/node/builders/message.js +84 -49
- package/dist/transport/node/builders/newsletter.js +183 -0
- package/dist/transport/node/builders/passive.js +10 -0
- package/dist/transport/node/builders/prekeys.js +3 -3
- package/dist/transport/node/builders/presence.js +28 -1
- package/dist/transport/node/builders/privacy-token.js +1 -1
- package/dist/transport/node/builders/privacy.js +5 -5
- package/dist/transport/node/builders/profile.js +30 -7
- package/dist/transport/node/builders/tos.js +63 -0
- package/dist/transport/node/builders/usync.js +52 -1
- package/dist/transport/node/helpers.js +3 -2
- package/dist/transport/node/mex/argo-decoder.js +2 -2
- package/dist/transport/node/mex/client.js +23 -0
- package/dist/transport/node/query.js +17 -0
- package/dist/transport/node/usync.js +13 -0
- package/dist/transport/noise/WaClientPayload.js +9 -9
- package/dist/transport/noise/WaMobileClientPayload.js +6 -1
- package/dist/transport/noise/WaNoiseCert.js +7 -2
- package/dist/transport/noise/WaNoiseHandshake.js +26 -24
- package/dist/transport/noise/WaNoiseSession.js +41 -61
- package/dist/transport/noise/WaNoiseSocket.js +19 -13
- package/dist/transport/noise/constants.js +1 -2
- package/dist/transport/proxy.js +5 -0
- package/dist/transport/stream/parse.js +3 -7
- package/dist/transport/wa-web-version-fetcher.js +94 -0
- package/dist/types/appstate/constants.d.ts +1 -1
- package/dist/types/appstate/{WaAppStateCrypto.d.ts → crypto/WaAppStateCrypto.d.ts} +26 -9
- package/dist/types/appstate/index.d.ts +5 -5
- package/dist/types/appstate/{encoding.d.ts → parsers/encoding.d.ts} +8 -1
- package/dist/types/appstate/{response-parser.d.ts → parsers/response-parser.d.ts} +13 -3
- package/dist/types/appstate/sync/WaAppStateSyncClient.d.ts +105 -0
- package/dist/types/appstate/types.d.ts +1 -1
- package/dist/types/appstate/utils.d.ts +18 -2
- package/dist/types/appstate-spec.d.ts +24 -0
- package/dist/types/auth/WaAuthClient.d.ts +89 -3
- package/dist/types/auth/credentials-flow.d.ts +4 -3
- package/dist/types/auth/pairing/pairing-code-crypto.d.ts +0 -1
- package/dist/types/auth/types.d.ts +49 -2
- package/dist/types/client/WaClient.d.ts +178 -71
- package/dist/types/client/WaClientFactory.d.ts +30 -5
- package/dist/types/client/connection/WaConnectionManager.d.ts +4 -2
- package/dist/types/client/connection/WaReceiptQueue.d.ts +1 -1
- package/dist/types/client/coordinators/WaAppStateMutationCoordinator.d.ts +215 -5
- package/dist/types/client/coordinators/WaBotCoordinator.d.ts +117 -0
- package/dist/types/client/coordinators/WaBroadcastListCoordinator.d.ts +39 -0
- package/dist/types/client/coordinators/WaBusinessCoordinator.d.ts +44 -43
- package/dist/types/client/coordinators/WaEmailCoordinator.d.ts +16 -0
- package/dist/types/client/coordinators/WaGroupCoordinator.d.ts +311 -9
- package/dist/types/client/coordinators/WaIncomingNodeCoordinator.d.ts +11 -4
- package/dist/types/client/coordinators/WaLowLevelCoordinator.d.ts +47 -0
- package/dist/types/client/coordinators/WaMessageCoordinator.d.ts +232 -0
- package/dist/types/client/coordinators/WaMessageDispatchCoordinator.d.ts +55 -32
- package/dist/types/client/coordinators/WaNewsletterCoordinator.d.ts +13 -0
- package/dist/types/client/coordinators/WaPassiveTasksCoordinator.d.ts +4 -3
- package/dist/types/client/coordinators/WaPresenceCoordinator.d.ts +27 -0
- package/dist/types/client/coordinators/WaPrivacyCoordinator.d.ts +27 -0
- package/dist/types/client/coordinators/WaProfileCoordinator.d.ts +113 -0
- package/dist/types/client/coordinators/WaRetryCoordinator.d.ts +19 -17
- package/dist/types/client/coordinators/WaStatusCoordinator.d.ts +42 -0
- package/dist/types/client/coordinators/WaTrustedContactTokenCoordinator.d.ts +5 -1
- package/dist/types/client/events/abprops.d.ts +2 -1
- package/dist/types/client/events/appstate-mutation.d.ts +3 -0
- package/dist/types/client/events/business.d.ts +10 -0
- package/dist/types/client/events/call.d.ts +31 -0
- package/dist/types/client/events/chatstate.d.ts +9 -0
- package/dist/types/client/events/devices.d.ts +5 -4
- package/dist/types/client/{dirty.d.ts → events/dirty.d.ts} +4 -3
- package/dist/types/client/events/group.d.ts +2 -1
- package/dist/types/client/events/identity.d.ts +2 -1
- package/dist/types/client/{incoming.d.ts → events/incoming.d.ts} +27 -4
- package/dist/types/client/events/mex-notification.d.ts +6 -0
- package/dist/types/client/events/picture.d.ts +8 -0
- package/dist/types/client/events/presence.d.ts +28 -0
- package/dist/types/client/events/receipt.d.ts +14 -0
- package/dist/types/client/events/registration.d.ts +4 -3
- package/dist/types/client/index.d.ts +1 -1
- package/dist/types/client/media.d.ts +35 -1
- package/dist/types/client/messaging/fanout.d.ts +2 -2
- package/dist/types/client/messaging/group-metadata.d.ts +19 -0
- package/dist/types/client/messaging/ignore-key.d.ts +11 -0
- package/dist/types/client/messaging/key-protocol.d.ts +9 -7
- package/dist/types/client/messaging/link-preview.d.ts +19 -0
- package/dist/types/client/messaging/messages.d.ts +28 -0
- package/dist/types/client/newsletter/admin.d.ts +71 -0
- package/dist/types/client/newsletter/content.d.ts +42 -0
- package/dist/types/client/newsletter/discovery.d.ts +33 -0
- package/dist/types/client/newsletter/messaging.d.ts +66 -0
- package/dist/types/client/newsletter/mex.d.ts +14 -0
- package/dist/types/client/newsletter/parse.d.ts +19 -0
- package/dist/types/client/newsletter/types.d.ts +190 -0
- package/dist/types/client/persistence/WriteBehindPersistence.d.ts +12 -1
- package/dist/types/client/persistence/history-sync.d.ts +29 -0
- package/dist/types/client/{mailbox.d.ts → persistence/mailbox.d.ts} +4 -4
- package/dist/types/client/tokens/cs-token.d.ts +1 -3
- package/dist/types/client/types.d.ts +844 -72
- package/dist/types/crypto/core/hkdf.d.ts +10 -2
- package/dist/types/crypto/core/index.d.ts +2 -2
- package/dist/types/crypto/core/keys.d.ts +0 -4
- package/dist/types/crypto/core/nonce.d.ts +4 -5
- package/dist/types/crypto/core/primitives.d.ts +31 -20
- package/dist/types/crypto/core/random.d.ts +6 -0
- package/dist/types/crypto/core/xeddsa.d.ts +9 -0
- package/dist/types/crypto/curves/Ed25519.d.ts +7 -1
- package/dist/types/crypto/curves/X25519.d.ts +20 -1
- package/dist/types/crypto/curves/constants.d.ts +4 -3
- package/dist/types/crypto/curves/types.d.ts +0 -5
- package/dist/types/crypto/math/constants.d.ts +0 -1
- package/dist/types/crypto/math/mod.d.ts +0 -1
- package/dist/types/index.d.ts +34 -8
- package/dist/types/infra/log/ConsoleLogger.d.ts +18 -1
- package/dist/types/infra/log/PinoLogger.d.ts +55 -1
- package/dist/types/infra/log/types.d.ts +6 -0
- package/dist/types/infra/perf/BackgroundQueue.d.ts +19 -0
- package/dist/types/media/constants.d.ts +7 -2
- package/dist/types/media/crypto/WaMediaCrypto.d.ts +59 -0
- package/dist/types/media/index.d.ts +7 -5
- package/dist/types/media/processor.d.ts +27 -5
- package/dist/types/media/sticker/sticker-pack.d.ts +6 -0
- package/dist/types/media/{WaMediaTransferClient.d.ts → transfer/WaMediaTransferClient.d.ts} +30 -1
- package/dist/types/media/transfer/conn.d.ts +7 -0
- package/dist/types/media/types.d.ts +1 -2
- package/dist/types/message/WaMessageClient.d.ts +14 -0
- package/dist/types/message/addons/link-preview/builder.d.ts +13 -0
- package/dist/types/message/addons/link-preview/detect.d.ts +5 -0
- package/dist/types/message/addons/link-preview/fetcher.d.ts +13 -0
- package/dist/types/message/addons/link-preview/types.d.ts +51 -0
- package/dist/types/message/context-info.d.ts +66 -0
- package/dist/types/message/{addon-crypto.d.ts → crypto/addon-crypto.d.ts} +27 -5
- package/dist/types/message/{icdc.d.ts → crypto/icdc.d.ts} +4 -4
- package/dist/types/message/{phash.d.ts → crypto/phash.d.ts} +1 -1
- package/dist/types/message/{reporting-token.d.ts → crypto/reporting-token.d.ts} +2 -2
- package/dist/types/message/{use-case-secret.d.ts → crypto/use-case-secret.d.ts} +17 -1
- package/dist/types/message/encode/content.d.ts +43 -0
- package/dist/types/message/{device-sent.d.ts → encode/device-sent.d.ts} +1 -1
- package/dist/types/message/encode/media-payload.d.ts +12 -0
- package/dist/types/message/index.d.ts +2 -2
- package/dist/types/message/kinds/bot.d.ts +31 -0
- package/dist/types/message/kinds/newsletter.d.ts +12 -0
- package/dist/types/message/kinds/sticker-pack.d.ts +6 -0
- package/dist/types/message/{ack.d.ts → primitives/ack.d.ts} +1 -1
- package/dist/types/message/primitives/incoming.d.ts +21 -0
- package/dist/types/message/primitives/peer-data-operation.d.ts +23 -0
- package/dist/types/message/types.d.ts +209 -11
- package/dist/types/mex.d.ts +2 -0
- package/dist/types/proto.d.ts +2 -2
- package/dist/types/protocol/abprops.d.ts +9 -0
- package/dist/types/protocol/appstate.d.ts +4 -49
- package/dist/types/protocol/auth.d.ts +2 -2
- package/dist/types/protocol/bot.d.ts +45 -0
- package/dist/types/protocol/browser.d.ts +8 -0
- package/dist/types/protocol/business.d.ts +21 -0
- package/dist/types/protocol/call.d.ts +44 -0
- package/dist/types/protocol/constants.d.ts +16 -3
- package/dist/types/protocol/defaults.d.ts +3 -0
- package/dist/types/protocol/group.d.ts +1 -1
- package/dist/types/protocol/index.d.ts +2 -1
- package/dist/types/protocol/jid.d.ts +78 -0
- package/dist/types/protocol/media.d.ts +21 -13
- package/dist/types/protocol/message.d.ts +4 -0
- package/dist/types/protocol/newsletter.d.ts +65 -0
- package/dist/types/protocol/nodes.d.ts +20 -0
- package/dist/types/protocol/notification.d.ts +16 -0
- package/dist/types/protocol/presence.d.ts +16 -0
- package/dist/types/protocol/status.d.ts +7 -0
- package/dist/types/retry/codec.d.ts +5 -0
- package/dist/types/retry/index.d.ts +1 -1
- package/dist/types/retry/parse.d.ts +9 -0
- package/dist/types/retry/reason.d.ts +5 -0
- package/dist/types/retry/replay.d.ts +19 -5
- package/dist/types/retry/tracker.d.ts +10 -3
- package/dist/types/retry/types.d.ts +3 -8
- package/dist/types/signal/api/SignalDeviceSyncApi.d.ts +20 -0
- package/dist/types/signal/api/SignalDigestSyncApi.d.ts +10 -0
- package/dist/types/signal/api/SignalIdentitySyncApi.d.ts +9 -0
- package/dist/types/signal/api/SignalMissingPreKeysSyncApi.d.ts +8 -0
- package/dist/types/signal/api/SignalRotateKeyApi.d.ts +10 -0
- package/dist/types/signal/api/SignalSessionSyncApi.d.ts +13 -0
- package/dist/types/signal/api/codec.d.ts +20 -0
- package/dist/types/signal/api/constants.d.ts +1 -1
- package/dist/types/signal/api/prekeys.d.ts +4 -0
- package/dist/types/signal/{crypto → attestation}/WaAdvSignature.d.ts +2 -2
- package/dist/types/signal/attestation/constants.d.ts +4 -0
- package/dist/types/signal/constants.d.ts +7 -4
- package/dist/types/signal/encoding.d.ts +6 -68
- package/dist/types/signal/group/SenderKeyChain.d.ts +1 -1
- package/dist/types/signal/group/SenderKeyManager.d.ts +18 -1
- package/dist/types/signal/group/encoding.d.ts +25 -0
- package/dist/types/signal/index.d.ts +4 -1
- package/dist/types/signal/registration/encoding.d.ts +30 -0
- package/dist/types/signal/registration/keygen.d.ts +10 -0
- package/dist/types/signal/registration/utils.d.ts +5 -0
- package/dist/types/signal/session/SignalProtocol.d.ts +55 -0
- package/dist/types/signal/session/SignalRatchet.d.ts +2 -3
- package/dist/types/signal/session/SignalSession.d.ts +0 -1
- package/dist/types/signal/session/encoding.d.ts +28 -0
- package/dist/types/signal/session/resolver.d.ts +14 -0
- package/dist/types/signal/types.d.ts +1 -1
- package/dist/types/store/cache/identity.cache.d.ts +15 -0
- package/dist/types/store/cache/privacy-token.cache.d.ts +15 -0
- package/dist/types/store/cache/sender-key.cache.d.ts +18 -0
- package/dist/types/store/cache/session.cache.d.ts +23 -0
- package/dist/types/store/contracts/contact.store.d.ts +14 -0
- package/dist/types/store/contracts/device-list.store.d.ts +13 -0
- package/dist/types/store/contracts/group-metadata.store.d.ts +14 -0
- package/dist/types/store/contracts/message.store.d.ts +0 -2
- package/dist/types/store/createStore.d.ts +54 -2
- package/dist/types/store/index.d.ts +17 -16
- package/dist/types/store/locks/group-metadata.lock.d.ts +2 -0
- package/dist/types/store/{providers/memory → memory}/appstate.store.d.ts +2 -2
- package/dist/types/store/memory/auth.store.d.ts +18 -0
- package/dist/types/store/{providers/memory → memory}/contact.store.d.ts +6 -1
- package/dist/types/store/{providers/memory → memory}/device-list.store.d.ts +15 -2
- package/dist/types/store/memory/group-metadata.store.d.ts +27 -0
- package/dist/types/store/{providers/memory → memory}/identity.store.d.ts +2 -2
- package/dist/types/store/{providers/memory → memory}/message-secret.store.d.ts +12 -2
- package/dist/types/store/{providers/memory → memory}/message.store.d.ts +1 -1
- package/dist/types/store/{providers/memory → memory}/pre-key.store.d.ts +2 -2
- package/dist/types/store/{providers/memory → memory}/privacy-token.store.d.ts +1 -1
- package/dist/types/store/{providers/memory → memory}/retry.store.d.ts +16 -3
- package/dist/types/store/{providers/memory → memory}/sender-key.store.d.ts +2 -2
- package/dist/types/store/{providers/memory → memory}/session.store.d.ts +2 -2
- package/dist/types/store/{providers/memory → memory}/signal.store.d.ts +2 -2
- package/dist/types/store/{providers/memory → memory}/thread.store.d.ts +1 -1
- package/dist/types/store/noop.store.d.ts +2 -2
- package/dist/types/store/types.d.ts +250 -6
- package/dist/types/transport/WaComms.d.ts +5 -0
- package/dist/types/transport/WaWebSocket.d.ts +5 -0
- package/dist/types/transport/binary/constants.d.ts +8 -2
- package/dist/types/transport/binary/decoder.d.ts +5 -0
- package/dist/types/transport/binary/encoder.d.ts +5 -0
- package/dist/types/transport/binary/tokens.d.ts +6 -6
- package/dist/types/transport/index.d.ts +3 -1
- package/dist/types/transport/keepalive/WaKeepAlive.d.ts +7 -0
- package/dist/types/transport/node/WaMobileTcpSocket.d.ts +6 -0
- package/dist/types/transport/node/WaNodeOrchestrator.d.ts +5 -0
- package/dist/types/transport/node/WaNodeTransport.d.ts +13 -0
- package/dist/types/transport/node/builders/account-sync.d.ts +1 -2
- package/dist/types/transport/node/builders/bot.d.ts +4 -0
- package/dist/types/transport/node/builders/business.d.ts +21 -4
- package/dist/types/transport/node/builders/chatstate.d.ts +11 -0
- package/dist/types/transport/node/builders/community.d.ts +17 -0
- package/dist/types/transport/node/builders/group.d.ts +44 -2
- package/dist/types/transport/node/builders/message.d.ts +11 -6
- package/dist/types/transport/node/builders/newsletter.d.ts +73 -0
- package/dist/types/transport/node/builders/passive.d.ts +3 -0
- package/dist/types/transport/node/builders/presence.d.ts +8 -1
- package/dist/types/transport/node/builders/profile.d.ts +3 -0
- package/dist/types/transport/node/builders/tos.d.ts +12 -0
- package/dist/types/transport/node/builders/usync.d.ts +16 -0
- package/dist/types/transport/node/helpers.d.ts +1 -2
- package/dist/types/transport/node/mex/client.d.ts +12 -1
- package/dist/types/transport/node/query.d.ts +19 -1
- package/dist/types/transport/node/usync.d.ts +3 -0
- package/dist/types/transport/noise/WaMobileClientPayload.d.ts +6 -1
- package/dist/types/transport/noise/WaNoiseCert.d.ts +5 -0
- package/dist/types/transport/noise/WaNoiseHandshake.d.ts +12 -6
- package/dist/types/transport/noise/WaNoiseSession.d.ts +0 -1
- package/dist/types/transport/noise/WaNoiseSocket.d.ts +12 -6
- package/dist/types/transport/noise/constants.d.ts +4 -5
- package/dist/types/transport/noise/types.d.ts +1 -1
- package/dist/types/transport/proxy.d.ts +5 -0
- package/dist/types/transport/types.d.ts +14 -7
- package/dist/types/transport/wa-web-version-fetcher.d.ts +44 -0
- package/dist/types/util/async.d.ts +4 -0
- package/dist/types/util/bytes.d.ts +36 -1
- package/dist/types/util/clock.d.ts +6 -0
- package/dist/types/util/coercion.d.ts +25 -0
- package/dist/types/util/collections.d.ts +8 -0
- package/dist/types/util/index.d.ts +2 -2
- package/dist/types/util/primitives.d.ts +11 -0
- package/dist/types/util/runtime.d.ts +5 -0
- package/dist/types/version-spec.d.ts +1 -0
- package/dist/util/async.js +4 -0
- package/dist/util/bytes.js +37 -2
- package/dist/util/clock.js +18 -0
- package/dist/util/coercion.js +48 -3
- package/dist/util/collections.js +12 -0
- package/dist/util/index.js +7 -1
- package/dist/util/primitives.js +20 -0
- package/dist/util/runtime.js +5 -0
- package/dist/version-spec.js +5 -0
- package/package.json +32 -8
- package/spec/appstate/index.d.ts +188 -0
- package/spec/appstate/index.js +850 -0
- package/spec/mex/index.d.ts +4172 -0
- package/spec/mex/index.js +261 -0
- package/spec/proto/index.d.ts +16305 -0
- package/spec/proto/index.js +1 -0
- package/spec/version/index.d.ts +4 -0
- package/spec/version/index.js +9 -0
- package/spec/version/version.json +3 -0
- package/dist/client/events/chat.js +0 -227
- package/dist/client/incoming.js +0 -306
- package/dist/client/mailbox.js +0 -66
- package/dist/client/messages.js +0 -305
- package/dist/esm/client/events/chat.js +0 -224
- package/dist/esm/client/incoming.js +0 -296
- package/dist/esm/client/mailbox.js +0 -63
- package/dist/esm/client/messages.js +0 -301
- package/dist/esm/media/WaMediaCrypto.js +0 -499
- package/dist/esm/message/phash.js +0 -47
- package/dist/esm/store/locks/participants.lock.js +0 -20
- package/dist/esm/store/providers/memory/contact.store.js +0 -28
- package/dist/esm/store/providers/memory/device-list.store.js +0 -67
- package/dist/esm/transport/node/mex/persist-ids.js +0 -10
- package/dist/media/WaMediaCrypto.js +0 -503
- package/dist/message/phash.js +0 -50
- package/dist/store/locks/participants.lock.js +0 -23
- package/dist/store/providers/memory/contact.store.js +0 -32
- package/dist/store/providers/memory/device-list.store.js +0 -71
- package/dist/transport/node/mex/persist-ids.js +0 -13
- package/dist/types/appstate/WaAppStateSyncClient.d.ts +0 -70
- package/dist/types/client/events/chat.d.ts +0 -3
- package/dist/types/client/history-sync.d.ts +0 -20
- package/dist/types/client/messages.d.ts +0 -18
- package/dist/types/client/messaging/participants.d.ts +0 -13
- package/dist/types/media/WaMediaCrypto.d.ts +0 -22
- package/dist/types/media/conn.d.ts +0 -3
- package/dist/types/message/content.d.ts +0 -14
- package/dist/types/message/incoming.d.ts +0 -18
- package/dist/types/signal/crypto/constants.d.ts +0 -4
- package/dist/types/store/contracts/participants.store.d.ts +0 -13
- package/dist/types/store/locks/participants.lock.d.ts +0 -2
- package/dist/types/store/providers/memory/participants.store.d.ts +0 -17
- package/dist/types/transport/node/mex/persist-ids.d.ts +0 -14
- package/proto/index.d.ts +0 -10903
- package/proto/index.js +0 -1
- /package/dist/{store/contracts/participants.store.js → client/newsletter/types.js} +0 -0
- /package/dist/esm/{store/contracts/participants.store.js → client/newsletter/types.js} +0 -0
- /package/dist/esm/message/{device-sent.js → encode/device-sent.js} +0 -0
- /package/dist/esm/signal/{crypto → attestation}/constants.js +0 -0
- /package/dist/esm/store/{providers/memory → memory}/signal.store.js +0 -0
- /package/dist/message/{device-sent.js → encode/device-sent.js} +0 -0
- /package/dist/signal/{crypto → attestation}/constants.js +0 -0
- /package/dist/store/{providers/memory → memory}/signal.store.js +0 -0
- /package/dist/types/message/{padding.d.ts → encode/padding.d.ts} +0 -0
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { applyContextInfo } from '../../message/context-info.js';
|
|
3
|
+
import { resolveParentMessageSecret } from '../../message/crypto/addon-crypto.js';
|
|
4
|
+
import { unwrapMessage } from '../../message/encode/content.js';
|
|
5
|
+
import { attachBotMetadata, attachBotThread, decryptBotChunk } from '../../message/kinds/bot.js';
|
|
6
|
+
import { proto } from '../../proto.js';
|
|
7
|
+
import { resolveBotFbidJid, WA_BLOKS_VERSIONING_ID, WA_BOT_DEFAULT_CAPABILITIES, WA_BOT_RENDERING_PIXEL_DENSITY } from '../../protocol/bot.js';
|
|
8
|
+
import { WA_BOT_MSG_EDIT_TYPES, WA_BOT_NODE_ATTRS, WA_DEFAULTS, WA_META_NODE_ATTRS_BOT, WA_NODE_TAGS } from '../../protocol/constants.js';
|
|
9
|
+
import { isBotJid, toUserJid } from '../../protocol/jid.js';
|
|
10
|
+
import { buildBotListIq, buildBotProfileUsyncUserNodeContent, buildGetBotProfileUsyncQueryNode } from '../../transport/node/builders/bot.js';
|
|
11
|
+
import { buildUsyncIq, iterateUsyncUsers, parseUsyncResultEnvelope } from '../../transport/node/builders/usync.js';
|
|
12
|
+
import { findNodeChild, getNodeChildrenByTag, getNodeTextContent } from '../../transport/node/helpers.js';
|
|
13
|
+
import { assertIqResult } from '../../transport/node/query.js';
|
|
14
|
+
import { logUsyncProtocolErrors } from '../../transport/node/usync.js';
|
|
15
|
+
import { parseOptionalInt, toError } from '../../util/primitives.js';
|
|
16
|
+
function deriveFbidJid(jid, personaId) {
|
|
17
|
+
const mapped = resolveBotFbidJid(jid);
|
|
18
|
+
if (mapped)
|
|
19
|
+
return mapped;
|
|
20
|
+
const fbidUser = personaId.split('$', 1)[0];
|
|
21
|
+
return `${fbidUser}@${WA_DEFAULTS.BOT_SERVER}`;
|
|
22
|
+
}
|
|
23
|
+
function parseBotListResult(result) {
|
|
24
|
+
const botRoot = findNodeChild(result, WA_NODE_TAGS.BOT);
|
|
25
|
+
if (!botRoot)
|
|
26
|
+
return [];
|
|
27
|
+
const defaultJid = findNodeChild(botRoot, 'default')?.attrs.jid;
|
|
28
|
+
const sections = getNodeChildrenByTag(botRoot, 'section');
|
|
29
|
+
const out = [];
|
|
30
|
+
for (let i = 0; i < sections.length; i += 1) {
|
|
31
|
+
const section = sections[i];
|
|
32
|
+
const sectionName = typeof section.attrs.name === 'string' ? section.attrs.name : undefined;
|
|
33
|
+
const bots = getNodeChildrenByTag(section, WA_NODE_TAGS.BOT);
|
|
34
|
+
for (let j = 0; j < bots.length; j += 1) {
|
|
35
|
+
const node = bots[j];
|
|
36
|
+
const jid = node.attrs.jid;
|
|
37
|
+
const personaId = node.attrs.persona_id;
|
|
38
|
+
if (typeof jid !== 'string' || typeof personaId !== 'string')
|
|
39
|
+
continue;
|
|
40
|
+
out.push({
|
|
41
|
+
jid,
|
|
42
|
+
fbidJid: deriveFbidJid(jid, personaId),
|
|
43
|
+
personaId,
|
|
44
|
+
isDefault: defaultJid !== undefined && jid === defaultJid,
|
|
45
|
+
section: sectionName,
|
|
46
|
+
count: parseOptionalInt(node.attrs.count)
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
function parseBotProfilePrompts(promptsNode) {
|
|
53
|
+
if (!promptsNode)
|
|
54
|
+
return [];
|
|
55
|
+
const children = getNodeChildrenByTag(promptsNode, 'prompt');
|
|
56
|
+
const out = new Array(children.length);
|
|
57
|
+
let count = 0;
|
|
58
|
+
for (let i = 0; i < children.length; i += 1) {
|
|
59
|
+
const promptNode = children[i];
|
|
60
|
+
const emoji = getNodeTextContent(findNodeChild(promptNode, 'emoji')) ?? '';
|
|
61
|
+
const text = getNodeTextContent(findNodeChild(promptNode, 'text')) ?? '';
|
|
62
|
+
out[count] = { emoji, text };
|
|
63
|
+
count += 1;
|
|
64
|
+
}
|
|
65
|
+
out.length = count;
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
function parseBotProfileCommands(commandsNode) {
|
|
69
|
+
if (!commandsNode)
|
|
70
|
+
return { commands: [], commandsDescription: null };
|
|
71
|
+
const commandsDescription = getNodeTextContent(findNodeChild(commandsNode, 'description')) || null;
|
|
72
|
+
const commandNodes = getNodeChildrenByTag(commandsNode, 'command');
|
|
73
|
+
const commands = new Array(commandNodes.length);
|
|
74
|
+
let count = 0;
|
|
75
|
+
for (let i = 0; i < commandNodes.length; i += 1) {
|
|
76
|
+
const cmdNode = commandNodes[i];
|
|
77
|
+
const name = getNodeTextContent(findNodeChild(cmdNode, 'name')) ?? '';
|
|
78
|
+
const description = getNodeTextContent(findNodeChild(cmdNode, 'description')) ?? '';
|
|
79
|
+
commands[count] = { name, description };
|
|
80
|
+
count += 1;
|
|
81
|
+
}
|
|
82
|
+
commands.length = count;
|
|
83
|
+
return { commands, commandsDescription };
|
|
84
|
+
}
|
|
85
|
+
function parsePosingAsProfessional(node) {
|
|
86
|
+
if (!node)
|
|
87
|
+
return null;
|
|
88
|
+
const type = node.attrs.type;
|
|
89
|
+
if (type === 'unknown' || type === 'yes' || type === 'no') {
|
|
90
|
+
return type;
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
function parseBotProfileUsync(result) {
|
|
95
|
+
const userNodes = iterateUsyncUsers(result) ?? [];
|
|
96
|
+
for (let i = 0; i < userNodes.length; i += 1) {
|
|
97
|
+
const userNode = userNodes[i];
|
|
98
|
+
const userContent = userNode.content;
|
|
99
|
+
if (!Array.isArray(userContent))
|
|
100
|
+
continue;
|
|
101
|
+
for (let j = 0; j < userContent.length; j += 1) {
|
|
102
|
+
const botNode = userContent[j];
|
|
103
|
+
if (botNode.tag !== WA_NODE_TAGS.BOT)
|
|
104
|
+
continue;
|
|
105
|
+
const errorNode = findNodeChild(botNode, WA_NODE_TAGS.ERROR);
|
|
106
|
+
if (errorNode)
|
|
107
|
+
return null;
|
|
108
|
+
const profileNode = findNodeChild(botNode, 'profile');
|
|
109
|
+
if (!profileNode)
|
|
110
|
+
return null;
|
|
111
|
+
const isMetaCreatedRaw = getNodeTextContent(findNodeChild(profileNode, 'is_meta_created'));
|
|
112
|
+
const creatorNode = findNodeChild(profileNode, 'creator');
|
|
113
|
+
const { commands, commandsDescription } = parseBotProfileCommands(findNodeChild(profileNode, 'commands'));
|
|
114
|
+
return {
|
|
115
|
+
name: getNodeTextContent(findNodeChild(profileNode, 'name')) || null,
|
|
116
|
+
attributes: getNodeTextContent(findNodeChild(profileNode, 'attributes')) || null,
|
|
117
|
+
description: getNodeTextContent(findNodeChild(profileNode, 'description')) || null,
|
|
118
|
+
category: getNodeTextContent(findNodeChild(profileNode, 'category')) || null,
|
|
119
|
+
isDefault: getNodeTextContent(findNodeChild(profileNode, 'default')) === 'true',
|
|
120
|
+
prompts: parseBotProfilePrompts(findNodeChild(profileNode, 'prompts')),
|
|
121
|
+
personaId: profileNode.attrs.persona_id ?? null,
|
|
122
|
+
commands,
|
|
123
|
+
commandsDescription,
|
|
124
|
+
isMetaCreated: isMetaCreatedRaw === undefined ? null : isMetaCreatedRaw === 'true',
|
|
125
|
+
creatorName: creatorNode
|
|
126
|
+
? getNodeTextContent(findNodeChild(creatorNode, 'name')) || null
|
|
127
|
+
: null,
|
|
128
|
+
creatorProfileUrl: creatorNode
|
|
129
|
+
? getNodeTextContent(findNodeChild(creatorNode, 'profile_url')) || null
|
|
130
|
+
: null,
|
|
131
|
+
posingAsProfessional: parsePosingAsProfessional(findNodeChild(profileNode, 'posing_as_professional'))
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
function normalizeBotJidToFbid(botJid) {
|
|
138
|
+
const mapped = resolveBotFbidJid(botJid);
|
|
139
|
+
if (mapped)
|
|
140
|
+
return mapped;
|
|
141
|
+
throw new Error(`cannot resolve FBID for bot jid "${botJid}" – pass a @bot jid or use the fbidJid from listBots`);
|
|
142
|
+
}
|
|
143
|
+
/** Builds a {@link WaBotCoordinator} from its IQ/message/store dependencies. */
|
|
144
|
+
export function createBotCoordinator(options) {
|
|
145
|
+
const { logger, queryWithContext, buildMessageContent, sendMessage, messageStore, messageSecretStore, getCurrentCredentials, emitBotChunk, generateSid } = options;
|
|
146
|
+
return {
|
|
147
|
+
listBots: async () => {
|
|
148
|
+
const node = buildBotListIq();
|
|
149
|
+
const result = await queryWithContext('bot.listBots', node);
|
|
150
|
+
assertIqResult(result, 'bot.listBots');
|
|
151
|
+
return parseBotListResult(result);
|
|
152
|
+
},
|
|
153
|
+
getBotProfile: async (jid, opts) => {
|
|
154
|
+
const sid = await generateSid();
|
|
155
|
+
const usyncNode = buildUsyncIq({
|
|
156
|
+
sid,
|
|
157
|
+
queryProtocolNodes: [buildGetBotProfileUsyncQueryNode()],
|
|
158
|
+
users: [
|
|
159
|
+
{
|
|
160
|
+
jid,
|
|
161
|
+
content: buildBotProfileUsyncUserNodeContent(opts?.personaId)
|
|
162
|
+
}
|
|
163
|
+
]
|
|
164
|
+
});
|
|
165
|
+
const result = await queryWithContext('bot.getBotProfile', usyncNode, undefined, {
|
|
166
|
+
jid
|
|
167
|
+
});
|
|
168
|
+
assertIqResult(result, 'bot.getBotProfile');
|
|
169
|
+
logUsyncProtocolErrors(parseUsyncResultEnvelope(result), logger, 'bot.getBotProfile');
|
|
170
|
+
return parseBotProfileUsync(result);
|
|
171
|
+
},
|
|
172
|
+
sendPrompt: async (to, content, opts = {}) => {
|
|
173
|
+
// `to` wins when it is a @bot jid – caller chose a specific bot; ignore
|
|
174
|
+
// opts.botJid so it cannot misroute the prompt to a different bot.
|
|
175
|
+
const isDirect = isBotJid(to);
|
|
176
|
+
const botJid = isDirect ? to : opts.botJid;
|
|
177
|
+
if (!botJid) {
|
|
178
|
+
throw new Error('bot.sendPrompt: opts.botJid is required when `to` is not a @bot jid');
|
|
179
|
+
}
|
|
180
|
+
const fbidBotJid = normalizeBotJidToFbid(botJid);
|
|
181
|
+
const { message: baseMessage } = await buildMessageContent(content);
|
|
182
|
+
if (isDirect) {
|
|
183
|
+
const aiThreadId = opts.aiThreadId ?? randomUUID();
|
|
184
|
+
const withMetadata = attachBotMetadata(baseMessage, {
|
|
185
|
+
personaId: opts.personaId,
|
|
186
|
+
capabilities: opts.capabilities ?? WA_BOT_DEFAULT_CAPABILITIES
|
|
187
|
+
});
|
|
188
|
+
const enriched = attachBotThread(withMetadata, {
|
|
189
|
+
aiThreadId,
|
|
190
|
+
remoteJid: fbidBotJid,
|
|
191
|
+
threadType: opts.aiThreadType
|
|
192
|
+
});
|
|
193
|
+
return sendMessage(fbidBotJid, enriched, opts);
|
|
194
|
+
}
|
|
195
|
+
// Mention envelope must NOT carry personaId/invokerJid/capabilities/
|
|
196
|
+
// botThreadInfo – Meta AI silently drops the request otherwise.
|
|
197
|
+
const mentionedJids = [fbidBotJid];
|
|
198
|
+
if (opts.extraMentionedJids) {
|
|
199
|
+
for (const jid of opts.extraMentionedJids) {
|
|
200
|
+
if (jid !== fbidBotJid)
|
|
201
|
+
mentionedJids.push(jid);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
const inner = applyContextInfo(baseMessage, {
|
|
205
|
+
mentionedJids,
|
|
206
|
+
raw: {
|
|
207
|
+
botMessageSharingInfo: {
|
|
208
|
+
botEntryPointOrigin: proto.BotMetricsEntryPoint.INVOKE_META_AI_GROUP,
|
|
209
|
+
forwardScore: 0
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
const wrapped = {
|
|
214
|
+
messageContextInfo: {
|
|
215
|
+
threadId: [],
|
|
216
|
+
botMetadata: {
|
|
217
|
+
botRenderingConfigMetadata: {
|
|
218
|
+
bloksVersioningId: WA_BLOKS_VERSIONING_ID,
|
|
219
|
+
pixelDensity: WA_BOT_RENDERING_PIXEL_DENSITY
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
botInvokeMessage: { message: inner }
|
|
224
|
+
};
|
|
225
|
+
return sendMessage(to, wrapped, opts);
|
|
226
|
+
},
|
|
227
|
+
tryDecryptChunk: async (event) => {
|
|
228
|
+
const message = event.message;
|
|
229
|
+
if (!message)
|
|
230
|
+
return;
|
|
231
|
+
const inner = unwrapMessage(message);
|
|
232
|
+
const sec = inner.secretEncryptedMessage;
|
|
233
|
+
if (!sec || !sec.encIv || !sec.encPayload)
|
|
234
|
+
return;
|
|
235
|
+
const botNode = findNodeChild(event.rawNode, WA_NODE_TAGS.BOT);
|
|
236
|
+
if (!botNode)
|
|
237
|
+
return;
|
|
238
|
+
const metaNode = findNodeChild(event.rawNode, WA_NODE_TAGS.META);
|
|
239
|
+
// msmsg chunks omit targetMessageKey; the prompt id lives in <meta target_id>
|
|
240
|
+
const targetMessageId = sec.targetMessageKey?.id ?? metaNode?.attrs[WA_META_NODE_ATTRS_BOT.TARGET_ID];
|
|
241
|
+
if (!targetMessageId)
|
|
242
|
+
return;
|
|
243
|
+
const editAttr = botNode.attrs[WA_BOT_NODE_ATTRS.EDIT];
|
|
244
|
+
const editType = editAttr === WA_BOT_MSG_EDIT_TYPES.FIRST ||
|
|
245
|
+
editAttr === WA_BOT_MSG_EDIT_TYPES.INNER ||
|
|
246
|
+
editAttr === WA_BOT_MSG_EDIT_TYPES.LAST ||
|
|
247
|
+
editAttr === WA_BOT_MSG_EDIT_TYPES.FULL
|
|
248
|
+
? editAttr
|
|
249
|
+
: WA_BOT_MSG_EDIT_TYPES.FULL;
|
|
250
|
+
const editTargetId = botNode.attrs[WA_BOT_NODE_ATTRS.EDIT_TARGET_ID] || undefined;
|
|
251
|
+
const useEditTargetSalt = editType === WA_BOT_MSG_EDIT_TYPES.INNER || editType === WA_BOT_MSG_EDIT_TYPES.LAST;
|
|
252
|
+
const saltId = useEditTargetSalt ? editTargetId : event.key.id;
|
|
253
|
+
if (!saltId) {
|
|
254
|
+
logger.debug('bot chunk missing salt id', {
|
|
255
|
+
id: event.key.id,
|
|
256
|
+
editType,
|
|
257
|
+
hasEditTargetId: !!editTargetId
|
|
258
|
+
});
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
const senderJid = event.key.participant ?? event.key.remoteJid;
|
|
262
|
+
if (!senderJid) {
|
|
263
|
+
logger.debug('bot chunk missing sender jid', { id: event.key.id });
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
const metaTargetSenderJid = metaNode?.attrs[WA_META_NODE_ATTRS_BOT.TARGET_SENDER_JID];
|
|
267
|
+
const credentials = getCurrentCredentials();
|
|
268
|
+
const isFbidBotChat = event.key.remoteJid ? isBotJid(event.key.remoteJid) : false;
|
|
269
|
+
// FBID bot (`*@bot`) keys on user LID; legacy PN bot keys on user PN
|
|
270
|
+
const meFallbackJid = isFbidBotChat
|
|
271
|
+
? (credentials?.meLid ?? credentials?.meJid)
|
|
272
|
+
: credentials?.meJid;
|
|
273
|
+
const targetSenderJid = metaTargetSenderJid
|
|
274
|
+
? toUserJid(metaTargetSenderJid)
|
|
275
|
+
: meFallbackJid
|
|
276
|
+
? toUserJid(meFallbackJid)
|
|
277
|
+
: undefined;
|
|
278
|
+
if (!targetSenderJid) {
|
|
279
|
+
logger.debug('bot chunk missing target sender jid (no me jid)', {
|
|
280
|
+
id: event.key.id,
|
|
281
|
+
isFbidBotChat
|
|
282
|
+
});
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
const parentEntry = await resolveParentMessageSecret(targetMessageId, messageSecretStore, messageStore);
|
|
286
|
+
if (!parentEntry) {
|
|
287
|
+
logger.debug('bot chunk parent message secret not found', {
|
|
288
|
+
id: event.key.id,
|
|
289
|
+
targetId: targetMessageId
|
|
290
|
+
});
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
let plaintext;
|
|
294
|
+
try {
|
|
295
|
+
plaintext = decryptBotChunk({
|
|
296
|
+
parentMessageSecret: parentEntry.secret,
|
|
297
|
+
saltId,
|
|
298
|
+
targetSenderJid,
|
|
299
|
+
authorJid: toUserJid(senderJid),
|
|
300
|
+
encIv: sec.encIv,
|
|
301
|
+
encPayload: sec.encPayload
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
catch (error) {
|
|
305
|
+
logger.warn('failed to decrypt bot chunk', {
|
|
306
|
+
id: event.key.id,
|
|
307
|
+
targetId: targetMessageId,
|
|
308
|
+
editType,
|
|
309
|
+
message: toError(error).message
|
|
310
|
+
});
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
let decoded;
|
|
314
|
+
try {
|
|
315
|
+
// msmsg payloads are not PKCS7-padded (unlike Signal messages);
|
|
316
|
+
// wa-web decodes the gcm plaintext directly as a proto Message.
|
|
317
|
+
decoded = proto.Message.decode(plaintext);
|
|
318
|
+
}
|
|
319
|
+
catch (error) {
|
|
320
|
+
logger.warn('failed to decode decrypted bot chunk', {
|
|
321
|
+
id: event.key.id,
|
|
322
|
+
targetId: targetMessageId,
|
|
323
|
+
message: toError(error).message
|
|
324
|
+
});
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
emitBotChunk({
|
|
328
|
+
rawNode: event.rawNode,
|
|
329
|
+
key: event.key,
|
|
330
|
+
stanzaType: event.stanzaType,
|
|
331
|
+
offline: event.offline,
|
|
332
|
+
targetMessageId,
|
|
333
|
+
editType,
|
|
334
|
+
editTargetId,
|
|
335
|
+
saltId,
|
|
336
|
+
plaintext,
|
|
337
|
+
message: decoded,
|
|
338
|
+
raw: message
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Builds a {@link WaBroadcastListCoordinator} from its dependencies. */
|
|
2
|
+
export function createBroadcastListCoordinator(options) {
|
|
3
|
+
return {
|
|
4
|
+
setList: (input) => options.appStateMutations.setBroadcastList(input),
|
|
5
|
+
removeList: (id) => options.appStateMutations.removeBroadcastList(id),
|
|
6
|
+
send: async (input) => {
|
|
7
|
+
const built = await options.buildMessageContent(input.content);
|
|
8
|
+
const published = await options.publishBroadcastListMessage({
|
|
9
|
+
listJid: input.listJid,
|
|
10
|
+
message: built.message,
|
|
11
|
+
recipients: input.recipients,
|
|
12
|
+
options: input.options
|
|
13
|
+
});
|
|
14
|
+
return built.upload ? { ...published, upload: built.upload } : published;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { parseBusinessProfileNode, parseVerifiedNameNode } from '../events/business.js';
|
|
2
|
+
import { assertMediaUploadStatus, parseMediaUploadJsonBody, performPlaintextMediaUpload } from '../media.js';
|
|
3
|
+
import { PPS_UPLOAD_PATHS } from '../../media/constants.js';
|
|
4
|
+
import { WA_NODE_TAGS } from '../../protocol/nodes.js';
|
|
5
|
+
import { WA_BUSINESS_NOTIFICATION_TAGS } from '../../protocol/notification.js';
|
|
6
|
+
import { buildCoverPhotoIq, buildEditBusinessProfileIq, buildGetBusinessProfileIq, buildGetBusinessUsyncQueryNode, buildGetVerifiedNameIq } from '../../transport/node/builders/business.js';
|
|
7
|
+
import { buildUsyncIq, iterateUsyncUsers, parseUsyncResultEnvelope } from '../../transport/node/builders/usync.js';
|
|
8
|
+
import { findNodeChild, getNodeChildren } from '../../transport/node/helpers.js';
|
|
4
9
|
import { assertIqResult } from '../../transport/node/query.js';
|
|
5
|
-
import {
|
|
10
|
+
import { logUsyncProtocolErrors } from '../../transport/node/usync.js';
|
|
6
11
|
function parseBusinessProfiles(result) {
|
|
7
12
|
const bizNode = findNodeChild(result, 'business_profile');
|
|
8
13
|
if (!bizNode) {
|
|
@@ -12,181 +17,47 @@ function parseBusinessProfiles(result) {
|
|
|
12
17
|
const results = new Array(profileNodes.length);
|
|
13
18
|
let count = 0;
|
|
14
19
|
for (let i = 0; i < profileNodes.length; i += 1) {
|
|
15
|
-
const
|
|
16
|
-
if (
|
|
20
|
+
const parsed = parseBusinessProfileNode(profileNodes[i]);
|
|
21
|
+
if (!parsed)
|
|
17
22
|
continue;
|
|
18
|
-
|
|
19
|
-
if (!jid)
|
|
20
|
-
continue;
|
|
21
|
-
const entry = { jid };
|
|
22
|
-
const tag = profileNode.attrs.tag;
|
|
23
|
-
if (tag)
|
|
24
|
-
entry.tag = tag;
|
|
25
|
-
const children = profileNode.content;
|
|
26
|
-
if (!Array.isArray(children)) {
|
|
27
|
-
results[count] = entry;
|
|
28
|
-
count += 1;
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
const websites = [];
|
|
32
|
-
for (let j = 0; j < children.length; j += 1) {
|
|
33
|
-
const child = children[j];
|
|
34
|
-
const text = getNodeTextContent(child);
|
|
35
|
-
switch (child.tag) {
|
|
36
|
-
case 'description':
|
|
37
|
-
if (text !== undefined)
|
|
38
|
-
entry.description = text;
|
|
39
|
-
break;
|
|
40
|
-
case 'address':
|
|
41
|
-
if (text !== undefined)
|
|
42
|
-
entry.address = text;
|
|
43
|
-
break;
|
|
44
|
-
case 'email':
|
|
45
|
-
if (text !== undefined)
|
|
46
|
-
entry.email = text;
|
|
47
|
-
break;
|
|
48
|
-
case 'website':
|
|
49
|
-
if (text !== undefined)
|
|
50
|
-
websites.push({ url: text });
|
|
51
|
-
break;
|
|
52
|
-
case 'latitude':
|
|
53
|
-
if (text !== undefined) {
|
|
54
|
-
const val = Number.parseFloat(text);
|
|
55
|
-
if (!Number.isNaN(val))
|
|
56
|
-
entry.latitude = val;
|
|
57
|
-
}
|
|
58
|
-
break;
|
|
59
|
-
case 'longitude':
|
|
60
|
-
if (text !== undefined) {
|
|
61
|
-
const val = Number.parseFloat(text);
|
|
62
|
-
if (!Number.isNaN(val))
|
|
63
|
-
entry.longitude = val;
|
|
64
|
-
}
|
|
65
|
-
break;
|
|
66
|
-
case 'categories':
|
|
67
|
-
entry.categories = parseBusinessCategories(child);
|
|
68
|
-
break;
|
|
69
|
-
case 'business_hours':
|
|
70
|
-
entry.businessHours = parseBusinessHoursNode(child);
|
|
71
|
-
break;
|
|
72
|
-
case 'profile_options':
|
|
73
|
-
entry.profileOptions = parseProfileOptions(child);
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if (websites.length > 0)
|
|
78
|
-
entry.websites = websites;
|
|
79
|
-
results[count] = entry;
|
|
23
|
+
results[count] = parsed;
|
|
80
24
|
count += 1;
|
|
81
25
|
}
|
|
82
26
|
results.length = count;
|
|
83
27
|
return results;
|
|
84
28
|
}
|
|
85
|
-
function parseBusinessCategories(node) {
|
|
86
|
-
const children = getNodeChildren(node);
|
|
87
|
-
const categories = new Array(children.length);
|
|
88
|
-
let count = 0;
|
|
89
|
-
for (let i = 0; i < children.length; i += 1) {
|
|
90
|
-
const child = children[i];
|
|
91
|
-
if (child.tag !== 'category')
|
|
92
|
-
continue;
|
|
93
|
-
const id = child.attrs.id;
|
|
94
|
-
if (!id)
|
|
95
|
-
continue;
|
|
96
|
-
categories[count] = { id, name: getNodeTextContent(child) ?? '' };
|
|
97
|
-
count += 1;
|
|
98
|
-
}
|
|
99
|
-
categories.length = count;
|
|
100
|
-
return categories;
|
|
101
|
-
}
|
|
102
|
-
function parseBusinessHoursNode(node) {
|
|
103
|
-
const timezone = node.attrs.timezone;
|
|
104
|
-
const children = getNodeChildren(node);
|
|
105
|
-
const config = new Array(children.length);
|
|
106
|
-
let count = 0;
|
|
107
|
-
for (let i = 0; i < children.length; i += 1) {
|
|
108
|
-
const child = children[i];
|
|
109
|
-
if (child.tag !== 'business_hours_config')
|
|
110
|
-
continue;
|
|
111
|
-
const dayOfWeek = child.attrs.day_of_week;
|
|
112
|
-
const mode = child.attrs.mode;
|
|
113
|
-
if (!dayOfWeek || !mode)
|
|
114
|
-
continue;
|
|
115
|
-
const entry = { dayOfWeek, mode };
|
|
116
|
-
const openTime = child.attrs.open_time;
|
|
117
|
-
const closeTime = child.attrs.close_time;
|
|
118
|
-
if (openTime)
|
|
119
|
-
entry.openTime = Number.parseInt(openTime, 10);
|
|
120
|
-
if (closeTime)
|
|
121
|
-
entry.closeTime = Number.parseInt(closeTime, 10);
|
|
122
|
-
config[count] = entry;
|
|
123
|
-
count += 1;
|
|
124
|
-
}
|
|
125
|
-
config.length = count;
|
|
126
|
-
return { timezone, config };
|
|
127
|
-
}
|
|
128
|
-
function parseProfileOptions(node) {
|
|
129
|
-
const children = getNodeChildren(node);
|
|
130
|
-
const options = {};
|
|
131
|
-
for (let i = 0; i < children.length; i += 1) {
|
|
132
|
-
const child = children[i];
|
|
133
|
-
const text = getNodeTextContent(child);
|
|
134
|
-
if (text !== undefined) {
|
|
135
|
-
options[child.tag] = text;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return options;
|
|
139
|
-
}
|
|
140
|
-
const VN_ISSUER_API = 'ent:wa';
|
|
141
|
-
const VN_ISSUER_SMB = 'smb:wa';
|
|
142
|
-
function parseCertificateContent(contentBytes) {
|
|
143
|
-
try {
|
|
144
|
-
const cert = proto.VerifiedNameCertificate.decode(contentBytes);
|
|
145
|
-
if (!cert.details)
|
|
146
|
-
return null;
|
|
147
|
-
const details = proto.VerifiedNameCertificate.Details.decode(cert.details);
|
|
148
|
-
return {
|
|
149
|
-
name: details.verifiedName ?? undefined,
|
|
150
|
-
serial: details.serial !== null && details.serial !== undefined
|
|
151
|
-
? String(longToNumber(details.serial))
|
|
152
|
-
: undefined,
|
|
153
|
-
isApi: details.issuer === VN_ISSUER_API,
|
|
154
|
-
isSmb: details.issuer === VN_ISSUER_SMB
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
catch {
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
29
|
function parseVerifiedName(result) {
|
|
162
|
-
const vnNode = findNodeChild(result,
|
|
30
|
+
const vnNode = findNodeChild(result, WA_BUSINESS_NOTIFICATION_TAGS.VERIFIED_NAME);
|
|
163
31
|
if (!vnNode)
|
|
164
32
|
return null;
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
33
|
+
return parseVerifiedNameNode(vnNode);
|
|
34
|
+
}
|
|
35
|
+
function parseUsyncVerifiedNames(result) {
|
|
36
|
+
const userNodes = iterateUsyncUsers(result) ?? [];
|
|
37
|
+
const out = new Array(userNodes.length);
|
|
38
|
+
let count = 0;
|
|
39
|
+
for (let i = 0; i < userNodes.length; i += 1) {
|
|
40
|
+
const userNode = userNodes[i];
|
|
41
|
+
const jid = userNode.attrs.jid;
|
|
42
|
+
if (!jid)
|
|
43
|
+
continue;
|
|
44
|
+
const businessNode = findNodeChild(userNode, WA_NODE_TAGS.BUSINESS);
|
|
45
|
+
const errorNode = businessNode ? findNodeChild(businessNode, WA_NODE_TAGS.ERROR) : undefined;
|
|
46
|
+
const vnNode = businessNode && !errorNode
|
|
47
|
+
? findNodeChild(businessNode, WA_BUSINESS_NOTIFICATION_TAGS.VERIFIED_NAME)
|
|
48
|
+
: undefined;
|
|
49
|
+
out[count] = {
|
|
50
|
+
jid,
|
|
51
|
+
verifiedName: vnNode ? parseVerifiedNameNode(vnNode) : null
|
|
184
52
|
};
|
|
53
|
+
count += 1;
|
|
185
54
|
}
|
|
186
|
-
|
|
55
|
+
out.length = count;
|
|
56
|
+
return out;
|
|
187
57
|
}
|
|
58
|
+
/** Builds a {@link WaBusinessCoordinator} from its IQ/media dependencies. */
|
|
188
59
|
export function createBusinessCoordinator(options) {
|
|
189
|
-
const { queryWithContext } = options;
|
|
60
|
+
const { queryWithContext, mediaTransfer, getMediaConn, logger, generateSid } = options;
|
|
190
61
|
return {
|
|
191
62
|
getBusinessProfile: async (jids) => {
|
|
192
63
|
if (jids.length === 0)
|
|
@@ -211,15 +82,54 @@ export function createBusinessCoordinator(options) {
|
|
|
211
82
|
assertIqResult(result, 'business.getVerifiedName');
|
|
212
83
|
return parseVerifiedName(result);
|
|
213
84
|
},
|
|
214
|
-
|
|
215
|
-
|
|
85
|
+
getVerifiedNames: async (jids) => {
|
|
86
|
+
if (jids.length === 0)
|
|
87
|
+
return [];
|
|
88
|
+
const sid = await generateSid();
|
|
89
|
+
const usyncNode = buildUsyncIq({
|
|
90
|
+
sid,
|
|
91
|
+
queryProtocolNodes: [buildGetBusinessUsyncQueryNode()],
|
|
92
|
+
users: jids.map((jid) => ({ jid }))
|
|
93
|
+
});
|
|
94
|
+
const result = await queryWithContext('business.getVerifiedNames', usyncNode, undefined, { count: jids.length });
|
|
95
|
+
assertIqResult(result, 'business.getVerifiedNames');
|
|
96
|
+
logUsyncProtocolErrors(parseUsyncResultEnvelope(result), logger, 'business.getVerifiedNames');
|
|
97
|
+
return parseUsyncVerifiedNames(result);
|
|
98
|
+
},
|
|
99
|
+
updateCoverPhoto: async (media) => {
|
|
100
|
+
const mediaConn = await getMediaConn();
|
|
101
|
+
const upload = await performPlaintextMediaUpload({ mediaTransfer, mediaConn, logger }, {
|
|
102
|
+
source: media,
|
|
103
|
+
path: PPS_UPLOAD_PATHS['biz-cover-photo'],
|
|
104
|
+
logLabel: 'sending business cover photo upload'
|
|
105
|
+
});
|
|
106
|
+
assertMediaUploadStatus(upload.status, 'business cover photo upload');
|
|
107
|
+
const parsed = parseMediaUploadJsonBody(upload.responseBytes, 'business cover photo upload');
|
|
108
|
+
if (parsed.fbid === undefined ||
|
|
109
|
+
parsed.fbid === null ||
|
|
110
|
+
parsed.fbid === '' ||
|
|
111
|
+
parsed.ts === undefined ||
|
|
112
|
+
parsed.ts === null ||
|
|
113
|
+
parsed.ts === '' ||
|
|
114
|
+
!parsed.meta_hmac) {
|
|
115
|
+
throw new Error('business cover photo upload response missing fbid/ts/meta_hmac');
|
|
116
|
+
}
|
|
117
|
+
const id = String(parsed.fbid);
|
|
118
|
+
const ts = String(parsed.ts);
|
|
119
|
+
const node = buildCoverPhotoIq({
|
|
120
|
+
op: 'update',
|
|
121
|
+
id,
|
|
122
|
+
timestamp: ts,
|
|
123
|
+
token: parsed.meta_hmac
|
|
124
|
+
});
|
|
216
125
|
const result = await queryWithContext('business.updateCoverPhoto', node, undefined, {
|
|
217
126
|
id
|
|
218
127
|
});
|
|
219
128
|
assertIqResult(result, 'business.updateCoverPhoto');
|
|
129
|
+
return { id };
|
|
220
130
|
},
|
|
221
131
|
deleteCoverPhoto: async (id) => {
|
|
222
|
-
const node =
|
|
132
|
+
const node = buildCoverPhotoIq({ op: 'delete', id });
|
|
223
133
|
const result = await queryWithContext('business.deleteCoverPhoto', node, undefined, {
|
|
224
134
|
id
|
|
225
135
|
});
|
|
@@ -2,6 +2,7 @@ import { WA_EMAIL_TAGS } from '../../protocol/email.js';
|
|
|
2
2
|
import { buildConfirmEmailIq, buildGetEmailIq, buildRequestEmailVerificationCodeIq, buildSetEmailIq, buildVerifyEmailCodeIq } from '../../transport/node/builders/email.js';
|
|
3
3
|
import { findNodeChild, getNodeTextContent } from '../../transport/node/helpers.js';
|
|
4
4
|
import { assertIqResult } from '../../transport/node/query.js';
|
|
5
|
+
/** Builds a {@link WaEmailCoordinator} backed by the given IQ query function. */
|
|
5
6
|
export function createEmailCoordinator(options) {
|
|
6
7
|
const { queryWithContext } = options;
|
|
7
8
|
return {
|