shellzapy 0.1.0__py3-none-any.whl
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.
- shellzapy-0.1.0.dist-info/METADATA +112 -0
- shellzapy-0.1.0.dist-info/RECORD +345 -0
- shellzapy-0.1.0.dist-info/WHEEL +4 -0
- shellzapy-0.1.0.dist-info/licenses/LICENSE +21 -0
- shellzapy-0.1.0.dist-info/licenses/NOTICE +9 -0
- zapy/__init__.py +58 -0
- zapy/_appstate/__init__.py +59 -0
- zapy/_appstate/constants.py +82 -0
- zapy/_appstate/crypto/__init__.py +17 -0
- zapy/_appstate/crypto/app_state_crypto.py +401 -0
- zapy/_appstate/parsers/__init__.py +23 -0
- zapy/_appstate/parsers/encoding.py +157 -0
- zapy/_appstate/parsers/response_parser.py +135 -0
- zapy/_appstate/sync/__init__.py +11 -0
- zapy/_appstate/sync/sync_client.py +1559 -0
- zapy/_appstate/types.py +137 -0
- zapy/_appstate/utils.py +100 -0
- zapy/_auth/__init__.py +3 -0
- zapy/_auth/auth_client.py +618 -0
- zapy/_auth/credentials_flow.py +290 -0
- zapy/_auth/pairing/__init__.py +3 -0
- zapy/_auth/pairing/companion_host.py +239 -0
- zapy/_auth/pairing/flow.py +808 -0
- zapy/_auth/pairing/pairing_code_crypto.py +143 -0
- zapy/_auth/pairing/qr_flow.py +123 -0
- zapy/_auth/pairing/shortcake_crypto.py +122 -0
- zapy/_auth/pairing/shortcake_flow.py +393 -0
- zapy/_auth/types.py +110 -0
- zapy/_client/__init__.py +26 -0
- zapy/_client/client.py +972 -0
- zapy/_client/connection/__init__.py +6 -0
- zapy/_client/connection/manager.py +525 -0
- zapy/_client/connection/receipt_queue.py +74 -0
- zapy/_client/coordinators/__init__.py +81 -0
- zapy/_client/coordinators/ab_props.py +260 -0
- zapy/_client/coordinators/app_state_mutation.py +2538 -0
- zapy/_client/coordinators/bot.py +830 -0
- zapy/_client/coordinators/broadcast_list.py +101 -0
- zapy/_client/coordinators/business.py +247 -0
- zapy/_client/coordinators/email.py +158 -0
- zapy/_client/coordinators/group.py +1478 -0
- zapy/_client/coordinators/incoming_node.py +758 -0
- zapy/_client/coordinators/low_level.py +119 -0
- zapy/_client/coordinators/message.py +1153 -0
- zapy/_client/coordinators/message_dispatch.py +1637 -0
- zapy/_client/coordinators/newsletter.py +110 -0
- zapy/_client/coordinators/offline_resume.py +271 -0
- zapy/_client/coordinators/passive_tasks.py +447 -0
- zapy/_client/coordinators/presence.py +103 -0
- zapy/_client/coordinators/privacy.py +623 -0
- zapy/_client/coordinators/profile.py +1024 -0
- zapy/_client/coordinators/retry.py +1878 -0
- zapy/_client/coordinators/status.py +132 -0
- zapy/_client/coordinators/stream_control.py +260 -0
- zapy/_client/coordinators/trusted_contact_token.py +417 -0
- zapy/_client/events/__init__.py +266 -0
- zapy/_client/events/abprops.py +58 -0
- zapy/_client/events/appstate_mutation.py +248 -0
- zapy/_client/events/business.py +565 -0
- zapy/_client/events/call.py +144 -0
- zapy/_client/events/chatstate.py +41 -0
- zapy/_client/events/devices.py +122 -0
- zapy/_client/events/dirty.py +384 -0
- zapy/_client/events/group.py +655 -0
- zapy/_client/events/identity.py +40 -0
- zapy/_client/events/incoming.py +1079 -0
- zapy/_client/events/mex_notification.py +317 -0
- zapy/_client/events/offline.py +123 -0
- zapy/_client/events/picture.py +67 -0
- zapy/_client/events/presence.py +74 -0
- zapy/_client/events/privacy.py +187 -0
- zapy/_client/events/privacy_token.py +72 -0
- zapy/_client/events/receipt.py +109 -0
- zapy/_client/events/registration.py +70 -0
- zapy/_client/events/username.py +76 -0
- zapy/_client/factory.py +2020 -0
- zapy/_client/media.py +829 -0
- zapy/_client/newsletter/__init__.py +90 -0
- zapy/_client/newsletter/admin.py +323 -0
- zapy/_client/newsletter/content.py +499 -0
- zapy/_client/newsletter/discovery.py +233 -0
- zapy/_client/newsletter/messaging.py +396 -0
- zapy/_client/newsletter/mex.py +99 -0
- zapy/_client/newsletter/parse.py +406 -0
- zapy/_client/newsletter/types.py +393 -0
- zapy/_client/persistence/__init__.py +89 -0
- zapy/_client/persistence/companion_host.py +133 -0
- zapy/_client/persistence/ephemeral_setting.py +245 -0
- zapy/_client/persistence/group_history.py +361 -0
- zapy/_client/persistence/history_blob.py +169 -0
- zapy/_client/persistence/history_sync.py +646 -0
- zapy/_client/persistence/mailbox.py +232 -0
- zapy/_client/persistence/write_behind_persistence.py +368 -0
- zapy/_client/plugins/__init__.py +23 -0
- zapy/_client/plugins/define.py +44 -0
- zapy/_client/plugins/install.py +254 -0
- zapy/_client/plugins/types.py +64 -0
- zapy/_client/tokens/__init__.py +21 -0
- zapy/_client/tokens/cs_token.py +47 -0
- zapy/_client/tokens/tc_token.py +43 -0
- zapy/_client/types.py +988 -0
- zapy/_crypto/__init__.py +65 -0
- zapy/_crypto/core/__init__.py +62 -0
- zapy/_crypto/core/hkdf.py +41 -0
- zapy/_crypto/core/keys.py +51 -0
- zapy/_crypto/core/nonce.py +25 -0
- zapy/_crypto/core/primitives.py +179 -0
- zapy/_crypto/core/random.py +32 -0
- zapy/_crypto/core/xeddsa.py +72 -0
- zapy/_crypto/curves/__init__.py +3 -0
- zapy/_crypto/curves/constants.py +10 -0
- zapy/_crypto/curves/ed25519.py +61 -0
- zapy/_crypto/curves/types.py +18 -0
- zapy/_crypto/curves/x25519.py +117 -0
- zapy/_crypto/math/__init__.py +3 -0
- zapy/_crypto/math/constants.py +35 -0
- zapy/_crypto/math/edwards.py +174 -0
- zapy/_crypto/math/fe.py +120 -0
- zapy/_crypto/math/le.py +13 -0
- zapy/_crypto/math/mod.py +15 -0
- zapy/_crypto/math/prime.py +11 -0
- zapy/_crypto/math/types.py +25 -0
- zapy/_crypto/native_backend.py +40 -0
- zapy/_infra/__init__.py +3 -0
- zapy/_infra/log.py +142 -0
- zapy/_infra/perf.py +77 -0
- zapy/_media/__init__.py +64 -0
- zapy/_media/constants.py +133 -0
- zapy/_media/container.py +110 -0
- zapy/_media/crypto/__init__.py +19 -0
- zapy/_media/crypto/crypto.py +633 -0
- zapy/_media/crypto/media_retry.py +107 -0
- zapy/_media/processor.py +100 -0
- zapy/_media/sticker/__init__.py +8 -0
- zapy/_media/sticker/pack.py +188 -0
- zapy/_media/transfer/__init__.py +15 -0
- zapy/_media/transfer/client.py +635 -0
- zapy/_media/transfer/conn.py +48 -0
- zapy/_media/types.py +169 -0
- zapy/_message/__init__.py +121 -0
- zapy/_message/addons/__init__.py +5 -0
- zapy/_message/addons/link_preview/__init__.py +54 -0
- zapy/_message/addons/link_preview/builder.py +56 -0
- zapy/_message/addons/link_preview/detect.py +72 -0
- zapy/_message/addons/link_preview/fetcher.py +553 -0
- zapy/_message/addons/link_preview/types.py +100 -0
- zapy/_message/client.py +486 -0
- zapy/_message/context_info.py +424 -0
- zapy/_message/crypto/__init__.py +71 -0
- zapy/_message/crypto/addon_crypto.py +656 -0
- zapy/_message/crypto/icdc.py +138 -0
- zapy/_message/crypto/phash.py +87 -0
- zapy/_message/crypto/reporting_token.py +498 -0
- zapy/_message/crypto/use_case_secret.py +113 -0
- zapy/_message/encode/__init__.py +84 -0
- zapy/_message/encode/content.py +636 -0
- zapy/_message/encode/device_sent.py +88 -0
- zapy/_message/encode/media_payload.py +122 -0
- zapy/_message/encode/padding.py +27 -0
- zapy/_message/kinds/__init__.py +1 -0
- zapy/_message/kinds/bot.py +179 -0
- zapy/_message/kinds/group_history.py +206 -0
- zapy/_message/kinds/newsletter.py +388 -0
- zapy/_message/kinds/sticker_pack.py +74 -0
- zapy/_message/messaging/__init__.py +336 -0
- zapy/_message/messaging/companion_host.py +117 -0
- zapy/_message/messaging/fanout.py +311 -0
- zapy/_message/messaging/group_metadata.py +444 -0
- zapy/_message/messaging/ignore_key.py +264 -0
- zapy/_message/messaging/key_protocol.py +217 -0
- zapy/_message/messaging/link_preview.py +448 -0
- zapy/_message/messaging/messages.py +1429 -0
- zapy/_message/primitives/__init__.py +1 -0
- zapy/_message/primitives/ack.py +232 -0
- zapy/_message/primitives/incoming.py +1141 -0
- zapy/_message/primitives/media_retry.py +451 -0
- zapy/_message/primitives/peer_data_operation.py +271 -0
- zapy/_message/types.py +434 -0
- zapy/_proto/WAProto_pb2.py +2584 -0
- zapy/_proto/__init__.py +1 -0
- zapy/_protocol/__init__.py +3 -0
- zapy/_protocol/abprops_spec.py +6216 -0
- zapy/_protocol/auth.py +17 -0
- zapy/_protocol/browser.py +57 -0
- zapy/_protocol/defaults.py +38 -0
- zapy/_protocol/device_identity.py +54 -0
- zapy/_protocol/jid.py +241 -0
- zapy/_protocol/message.py +127 -0
- zapy/_protocol/nodes.py +144 -0
- zapy/_protocol/notification.py +18 -0
- zapy/_retry/__init__.py +77 -0
- zapy/_retry/codec.py +209 -0
- zapy/_retry/constants.py +28 -0
- zapy/_retry/parse.py +132 -0
- zapy/_retry/reason.py +65 -0
- zapy/_retry/replay.py +483 -0
- zapy/_retry/tracker.py +161 -0
- zapy/_retry/types.py +122 -0
- zapy/_signal/__init__.py +171 -0
- zapy/_signal/api/__init__.py +133 -0
- zapy/_signal/api/codec.py +164 -0
- zapy/_signal/api/constants.py +14 -0
- zapy/_signal/api/device_sync.py +915 -0
- zapy/_signal/api/digest_sync.py +363 -0
- zapy/_signal/api/identity_sync.py +250 -0
- zapy/_signal/api/missing_pre_keys_sync.py +267 -0
- zapy/_signal/api/prekeys.py +191 -0
- zapy/_signal/api/result_map.py +40 -0
- zapy/_signal/api/rotate_key.py +111 -0
- zapy/_signal/api/session_sync.py +297 -0
- zapy/_signal/attestation.py +145 -0
- zapy/_signal/constants.py +22 -0
- zapy/_signal/encoding.py +78 -0
- zapy/_signal/group/__init__.py +35 -0
- zapy/_signal/group/chain.py +139 -0
- zapy/_signal/group/codec.py +78 -0
- zapy/_signal/group/encoding.py +166 -0
- zapy/_signal/group/manager.py +361 -0
- zapy/_signal/registration/__init__.py +44 -0
- zapy/_signal/registration/keygen.py +46 -0
- zapy/_signal/registration/reg_encoding.py +66 -0
- zapy/_signal/registration/reg_utils.py +52 -0
- zapy/_signal/session/__init__.py +114 -0
- zapy/_signal/session/encoding.py +385 -0
- zapy/_signal/session/protocol.py +590 -0
- zapy/_signal/session/ratchet.py +381 -0
- zapy/_signal/session/resolver.py +630 -0
- zapy/_signal/session/serializer.py +96 -0
- zapy/_signal/session/session.py +272 -0
- zapy/_signal/types.py +214 -0
- zapy/_store/__init__.py +118 -0
- zapy/_store/cache/__init__.py +166 -0
- zapy/_store/cache/identity.py +130 -0
- zapy/_store/cache/privacy_token.py +116 -0
- zapy/_store/cache/sender_key.py +168 -0
- zapy/_store/cache/session.py +142 -0
- zapy/_store/contracts/__init__.py +84 -0
- zapy/_store/contracts/appstate.py +82 -0
- zapy/_store/contracts/auth.py +16 -0
- zapy/_store/contracts/chat_metadata.py +29 -0
- zapy/_store/contracts/contact.py +31 -0
- zapy/_store/contracts/device_list.py +35 -0
- zapy/_store/contracts/group_metadata.py +33 -0
- zapy/_store/contracts/identity.py +18 -0
- zapy/_store/contracts/message.py +36 -0
- zapy/_store/contracts/message_secret.py +41 -0
- zapy/_store/contracts/pre_key.py +32 -0
- zapy/_store/contracts/privacy_token.py +32 -0
- zapy/_store/contracts/retry.py +47 -0
- zapy/_store/contracts/sender_key.py +37 -0
- zapy/_store/contracts/session.py +21 -0
- zapy/_store/contracts/signal.py +23 -0
- zapy/_store/contracts/thread.py +35 -0
- zapy/_store/create_store.py +890 -0
- zapy/_store/locks.py +1154 -0
- zapy/_store/memory/__init__.py +40 -0
- zapy/_store/memory/appstate.py +200 -0
- zapy/_store/memory/auth.py +24 -0
- zapy/_store/memory/chat_metadata.py +124 -0
- zapy/_store/memory/contact.py +125 -0
- zapy/_store/memory/device_list.py +161 -0
- zapy/_store/memory/group_metadata.py +125 -0
- zapy/_store/memory/identity.py +86 -0
- zapy/_store/memory/message.py +85 -0
- zapy/_store/memory/message_secret.py +145 -0
- zapy/_store/memory/pre_key.py +112 -0
- zapy/_store/memory/privacy_token.py +103 -0
- zapy/_store/memory/retry.py +250 -0
- zapy/_store/memory/sender_key.py +162 -0
- zapy/_store/memory/session.py +111 -0
- zapy/_store/memory/signal.py +45 -0
- zapy/_store/memory/thread.py +66 -0
- zapy/_store/noop.py +279 -0
- zapy/_transport/__init__.py +3 -0
- zapy/_transport/binary/__init__.py +77 -0
- zapy/_transport/binary/constants.py +80 -0
- zapy/_transport/binary/decoder.py +260 -0
- zapy/_transport/binary/encoder.py +279 -0
- zapy/_transport/binary/tokens.py +1289 -0
- zapy/_transport/comms.py +759 -0
- zapy/_transport/keepalive/__init__.py +3 -0
- zapy/_transport/keepalive/keep_alive.py +252 -0
- zapy/_transport/node/__init__.py +3 -0
- zapy/_transport/node/builders/__init__.py +9 -0
- zapy/_transport/node/builders/abprops.py +33 -0
- zapy/_transport/node/builders/account_sync.py +120 -0
- zapy/_transport/node/builders/bot.py +56 -0
- zapy/_transport/node/builders/business.py +261 -0
- zapy/_transport/node/builders/chatstate.py +74 -0
- zapy/_transport/node/builders/community.py +116 -0
- zapy/_transport/node/builders/device.py +30 -0
- zapy/_transport/node/builders/email.py +181 -0
- zapy/_transport/node/builders/global_.py +74 -0
- zapy/_transport/node/builders/group.py +279 -0
- zapy/_transport/node/builders/media.py +21 -0
- zapy/_transport/node/builders/message.py +436 -0
- zapy/_transport/node/builders/mobile.py +227 -0
- zapy/_transport/node/builders/newsletter.py +293 -0
- zapy/_transport/node/builders/offline.py +20 -0
- zapy/_transport/node/builders/pairing.py +130 -0
- zapy/_transport/node/builders/passive.py +28 -0
- zapy/_transport/node/builders/prekeys.py +215 -0
- zapy/_transport/node/builders/presence.py +100 -0
- zapy/_transport/node/builders/privacy.py +243 -0
- zapy/_transport/node/builders/privacy_token.py +94 -0
- zapy/_transport/node/builders/profile.py +176 -0
- zapy/_transport/node/builders/retry.py +156 -0
- zapy/_transport/node/builders/shortcake.py +87 -0
- zapy/_transport/node/builders/tos.py +92 -0
- zapy/_transport/node/builders/usync.py +185 -0
- zapy/_transport/node/helpers.py +201 -0
- zapy/_transport/node/orchestrator.py +210 -0
- zapy/_transport/node/query.py +82 -0
- zapy/_transport/node/transport.py +105 -0
- zapy/_transport/node/usync.py +33 -0
- zapy/_transport/node/xml.py +38 -0
- zapy/_transport/noise/__init__.py +7 -0
- zapy/_transport/noise/cert.py +85 -0
- zapy/_transport/noise/client_payload.py +344 -0
- zapy/_transport/noise/constants.py +12 -0
- zapy/_transport/noise/frame_codec.py +120 -0
- zapy/_transport/noise/handshake.py +92 -0
- zapy/_transport/noise/session.py +493 -0
- zapy/_transport/noise/socket.py +45 -0
- zapy/_transport/noise/types.py +66 -0
- zapy/_transport/noise/version.json +3 -0
- zapy/_transport/proxy.py +35 -0
- zapy/_transport/types.py +19 -0
- zapy/_transport/wa_version_fetcher.py +159 -0
- zapy/_transport/web_socket.py +602 -0
- zapy/_util/__init__.py +3 -0
- zapy/_util/bytes.py +131 -0
- zapy/_util/coercion.py +29 -0
- zapy/_util/collections.py +45 -0
- zapy/_util/primitives.py +49 -0
- zapy/client.py +840 -0
- zapy/errors.py +148 -0
- zapy/events.py +564 -0
- zapy/jid.py +140 -0
- zapy/py.typed +0 -0
- zapy/stores/__init__.py +50 -0
- zapy/stores/base.py +1627 -0
- zapy/stores/json_file.py +359 -0
- zapy/stores/memory.py +322 -0
- zapy/stores/sqlite.py +343 -0
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
"""Newsletter node builders (mirrors ``builders/newsletter.ts``).
|
|
2
|
+
|
|
3
|
+
TEMPORARY: the edit-attr strings below are verbatim copies of the
|
|
4
|
+
``WA_EDIT_ATTRS`` rows the oracle uses. They move to ``zapy._protocol`` once
|
|
5
|
+
that layer lands; the call-site shapes already match the canonical ones.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from dataclasses import dataclass
|
|
11
|
+
|
|
12
|
+
from zapy._protocol import defaults as _defaults
|
|
13
|
+
from zapy._protocol.nodes import WA_IQ_TYPES, WA_NODE_TAGS, WA_XMLNS
|
|
14
|
+
from zapy._transport.node.query import build_iq_node
|
|
15
|
+
from zapy._transport.types import BinaryNode
|
|
16
|
+
|
|
17
|
+
# Verbatim ``src/protocol/message.ts`` (newsletter edit markers).
|
|
18
|
+
NEWSLETTER_EDIT_ATTR: str = "3"
|
|
19
|
+
SENDER_REVOKE_EDIT_ATTR: str = "7"
|
|
20
|
+
ADMIN_REVOKE_EDIT_ATTR: str = "8"
|
|
21
|
+
|
|
22
|
+
# Newsletter message kinds (mirrors ``BuildNewsletterMessageInput``).
|
|
23
|
+
NEWSLETTER_MESSAGE_TEXT: str = "text"
|
|
24
|
+
NEWSLETTER_MESSAGE_MEDIA: str = "media"
|
|
25
|
+
NEWSLETTER_MESSAGE_EDIT_TEXT: str = "edit-text"
|
|
26
|
+
NEWSLETTER_MESSAGE_EDIT_MEDIA: str = "edit-media"
|
|
27
|
+
NEWSLETTER_MESSAGE_REACTION: str = "reaction"
|
|
28
|
+
NEWSLETTER_MESSAGE_REACTION_REVOKE: str = "reaction-revoke"
|
|
29
|
+
NEWSLETTER_MESSAGE_REVOKE: str = "revoke"
|
|
30
|
+
NEWSLETTER_MESSAGE_POLL_CREATION: str = "poll-creation"
|
|
31
|
+
NEWSLETTER_MESSAGE_POLL_VOTE: str = "poll-vote"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@dataclass(frozen=True, slots=True)
|
|
35
|
+
class NewsletterMessageBase:
|
|
36
|
+
"""Shared addressing for newsletter message stanzas."""
|
|
37
|
+
|
|
38
|
+
to: str = ""
|
|
39
|
+
additional_attributes: dict[str, str] | None = None
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@dataclass(frozen=True, slots=True)
|
|
43
|
+
class BuildNewsletterMessageInput:
|
|
44
|
+
"""One newsletter message/reaction/poll/revoke send.
|
|
45
|
+
|
|
46
|
+
``kind`` selects the shape; only the fields each kind needs are read:
|
|
47
|
+
new sends use ``id``, edits use ``parent_message_id``, replies and votes
|
|
48
|
+
use ``parent_message_server_id``, media kinds use ``plaintext`` plus
|
|
49
|
+
``media_type``/``media_handle``, reactions use ``reaction_code``, votes
|
|
50
|
+
use ``votes``, and poll creation may set ``content_type``.
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
kind: str = NEWSLETTER_MESSAGE_TEXT
|
|
54
|
+
to: str = ""
|
|
55
|
+
id: str | None = None
|
|
56
|
+
parent_message_id: str | None = None
|
|
57
|
+
parent_message_server_id: int | None = None
|
|
58
|
+
plaintext: bytes = b""
|
|
59
|
+
media_type: str | None = None
|
|
60
|
+
media_handle: str | None = None
|
|
61
|
+
reaction_code: str | None = None
|
|
62
|
+
votes: tuple[bytes, ...] = ()
|
|
63
|
+
content_type: str | None = None
|
|
64
|
+
additional_attributes: dict[str, str] | None = None
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _plaintext_child(plaintext: bytes, media_type: str | None = None) -> BinaryNode:
|
|
68
|
+
attrs: dict[str, str] = {}
|
|
69
|
+
if media_type:
|
|
70
|
+
attrs["mediatype"] = media_type
|
|
71
|
+
return BinaryNode(
|
|
72
|
+
tag=WA_NODE_TAGS["PLAINTEXT"], attrs=attrs, content=bytes(plaintext)
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _poll_meta_child(poll_type: str, content_type: str | None = None) -> BinaryNode:
|
|
77
|
+
attrs: dict[str, str] = {"polltype": poll_type}
|
|
78
|
+
if content_type:
|
|
79
|
+
attrs["contenttype"] = content_type
|
|
80
|
+
return BinaryNode(tag="meta", attrs=attrs)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def build_newsletter_message_node(input: BuildNewsletterMessageInput) -> BinaryNode:
|
|
84
|
+
"""Build the ``<message to>`` stanza for one newsletter send."""
|
|
85
|
+
attrs: dict[str, str] = {"to": input.to}
|
|
86
|
+
content: list[BinaryNode] | None = None
|
|
87
|
+
kind = input.kind
|
|
88
|
+
if kind == NEWSLETTER_MESSAGE_TEXT:
|
|
89
|
+
assert input.id is not None
|
|
90
|
+
attrs["id"] = input.id
|
|
91
|
+
attrs["type"] = "text"
|
|
92
|
+
content = [_plaintext_child(input.plaintext)]
|
|
93
|
+
elif kind == NEWSLETTER_MESSAGE_MEDIA:
|
|
94
|
+
assert input.id is not None
|
|
95
|
+
attrs["id"] = input.id
|
|
96
|
+
attrs["type"] = "media"
|
|
97
|
+
if input.media_handle:
|
|
98
|
+
attrs["media_id"] = input.media_handle
|
|
99
|
+
content = [_plaintext_child(input.plaintext, input.media_type)]
|
|
100
|
+
elif kind == NEWSLETTER_MESSAGE_EDIT_TEXT:
|
|
101
|
+
assert input.parent_message_id is not None
|
|
102
|
+
attrs["id"] = input.parent_message_id
|
|
103
|
+
attrs["type"] = "text"
|
|
104
|
+
attrs["edit"] = NEWSLETTER_EDIT_ATTR
|
|
105
|
+
content = [_plaintext_child(input.plaintext)]
|
|
106
|
+
elif kind == NEWSLETTER_MESSAGE_EDIT_MEDIA:
|
|
107
|
+
assert input.parent_message_id is not None
|
|
108
|
+
attrs["id"] = input.parent_message_id
|
|
109
|
+
attrs["type"] = "media"
|
|
110
|
+
attrs["edit"] = NEWSLETTER_EDIT_ATTR
|
|
111
|
+
content = [_plaintext_child(input.plaintext, input.media_type)]
|
|
112
|
+
elif kind == NEWSLETTER_MESSAGE_REACTION:
|
|
113
|
+
assert input.id is not None and input.parent_message_server_id is not None
|
|
114
|
+
attrs["id"] = input.id
|
|
115
|
+
attrs["server_id"] = str(input.parent_message_server_id)
|
|
116
|
+
attrs["type"] = "reaction"
|
|
117
|
+
assert input.reaction_code is not None
|
|
118
|
+
content = [BinaryNode(tag="reaction", attrs={"code": input.reaction_code})]
|
|
119
|
+
elif kind == NEWSLETTER_MESSAGE_REACTION_REVOKE:
|
|
120
|
+
assert input.id is not None and input.parent_message_server_id is not None
|
|
121
|
+
attrs["id"] = input.id
|
|
122
|
+
attrs["server_id"] = str(input.parent_message_server_id)
|
|
123
|
+
attrs["type"] = "reaction"
|
|
124
|
+
attrs["edit"] = SENDER_REVOKE_EDIT_ATTR
|
|
125
|
+
content = [BinaryNode(tag="reaction", attrs={})]
|
|
126
|
+
elif kind == NEWSLETTER_MESSAGE_REVOKE:
|
|
127
|
+
assert input.parent_message_id is not None
|
|
128
|
+
attrs["id"] = input.parent_message_id
|
|
129
|
+
attrs["type"] = "text"
|
|
130
|
+
attrs["edit"] = ADMIN_REVOKE_EDIT_ATTR
|
|
131
|
+
content = [BinaryNode(tag=WA_NODE_TAGS["PLAINTEXT"], attrs={})]
|
|
132
|
+
elif kind == NEWSLETTER_MESSAGE_POLL_CREATION:
|
|
133
|
+
assert input.id is not None
|
|
134
|
+
attrs["id"] = input.id
|
|
135
|
+
attrs["type"] = "poll"
|
|
136
|
+
content = [
|
|
137
|
+
_plaintext_child(input.plaintext),
|
|
138
|
+
_poll_meta_child("creation", input.content_type),
|
|
139
|
+
]
|
|
140
|
+
elif kind == NEWSLETTER_MESSAGE_POLL_VOTE:
|
|
141
|
+
if len(input.votes) == 0:
|
|
142
|
+
raise ValueError("newsletter poll vote requires at least one vote payload")
|
|
143
|
+
assert input.id is not None and input.parent_message_server_id is not None
|
|
144
|
+
attrs["id"] = input.id
|
|
145
|
+
attrs["server_id"] = str(input.parent_message_server_id)
|
|
146
|
+
attrs["type"] = "poll"
|
|
147
|
+
content = [
|
|
148
|
+
BinaryNode(
|
|
149
|
+
tag="votes",
|
|
150
|
+
attrs={},
|
|
151
|
+
content=[
|
|
152
|
+
BinaryNode(tag="vote", attrs={}, content=bytes(vote))
|
|
153
|
+
for vote in input.votes
|
|
154
|
+
],
|
|
155
|
+
),
|
|
156
|
+
_poll_meta_child("vote", input.content_type),
|
|
157
|
+
]
|
|
158
|
+
else:
|
|
159
|
+
raise ValueError(f"unknown newsletter message kind: {kind}")
|
|
160
|
+
if input.additional_attributes:
|
|
161
|
+
attrs.update(input.additional_attributes)
|
|
162
|
+
return BinaryNode(tag="message", attrs=attrs, content=content)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
@dataclass(frozen=True, slots=True)
|
|
166
|
+
class BuildNewsletterViewReceiptInput:
|
|
167
|
+
"""View receipt for delivered newsletter items."""
|
|
168
|
+
|
|
169
|
+
to: str = ""
|
|
170
|
+
id: str = ""
|
|
171
|
+
item_server_ids: tuple[int, ...] = ()
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def build_newsletter_view_receipt_node(
|
|
175
|
+
input: BuildNewsletterViewReceiptInput,
|
|
176
|
+
) -> BinaryNode:
|
|
177
|
+
"""Build the ``<receipt type=view><list><item server_id/>`` stanza."""
|
|
178
|
+
if len(input.item_server_ids) == 0:
|
|
179
|
+
raise ValueError("newsletter view receipt requires at least one item")
|
|
180
|
+
return BinaryNode(
|
|
181
|
+
tag="receipt",
|
|
182
|
+
attrs={"to": input.to, "id": input.id, "type": "view"},
|
|
183
|
+
content=[
|
|
184
|
+
BinaryNode(
|
|
185
|
+
tag="list",
|
|
186
|
+
attrs={},
|
|
187
|
+
content=[
|
|
188
|
+
BinaryNode(tag="item", attrs={"server_id": str(server_id)})
|
|
189
|
+
for server_id in input.item_server_ids
|
|
190
|
+
],
|
|
191
|
+
)
|
|
192
|
+
],
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def build_newsletter_subscribe_live_updates_iq(newsletter_jid: str) -> BinaryNode:
|
|
197
|
+
"""Build the ``live_updates`` subscribe IQ for a newsletter."""
|
|
198
|
+
return build_iq_node(
|
|
199
|
+
WA_IQ_TYPES["SET"],
|
|
200
|
+
newsletter_jid,
|
|
201
|
+
WA_XMLNS["NEWSLETTER"],
|
|
202
|
+
[BinaryNode(tag="live_updates", attrs={})],
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
@dataclass(frozen=True, slots=True)
|
|
207
|
+
class BuildNewsletterMessagesInput:
|
|
208
|
+
"""Newsletter message history page: count plus one cursor."""
|
|
209
|
+
|
|
210
|
+
newsletter_jid: str = ""
|
|
211
|
+
count: int = 0
|
|
212
|
+
before: int | None = None
|
|
213
|
+
after: int | None = None
|
|
214
|
+
view_role: str | None = None
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def build_newsletter_messages_iq(input: BuildNewsletterMessagesInput) -> BinaryNode:
|
|
218
|
+
"""Build the newsletter ``<messages>`` history IQ."""
|
|
219
|
+
attrs: dict[str, str] = {
|
|
220
|
+
"type": "jid",
|
|
221
|
+
"jid": input.newsletter_jid,
|
|
222
|
+
"count": str(input.count),
|
|
223
|
+
}
|
|
224
|
+
if input.before is not None:
|
|
225
|
+
attrs["before"] = str(input.before)
|
|
226
|
+
elif input.after is not None:
|
|
227
|
+
attrs["after"] = str(input.after)
|
|
228
|
+
if input.view_role:
|
|
229
|
+
attrs["view_role"] = input.view_role
|
|
230
|
+
return build_iq_node(
|
|
231
|
+
WA_IQ_TYPES["GET"],
|
|
232
|
+
_defaults.HOST_DOMAIN,
|
|
233
|
+
WA_XMLNS["NEWSLETTER"],
|
|
234
|
+
[BinaryNode(tag="messages", attrs=attrs)],
|
|
235
|
+
)
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
@dataclass(frozen=True, slots=True)
|
|
239
|
+
class BuildNewsletterMessageUpdatesInput:
|
|
240
|
+
"""Newsletter message updates page: count plus a before/after cursor."""
|
|
241
|
+
|
|
242
|
+
newsletter_jid: str = ""
|
|
243
|
+
count: int = 0
|
|
244
|
+
since: int | None = None
|
|
245
|
+
before: int | None = None
|
|
246
|
+
after: int | None = None
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
def build_newsletter_message_updates_iq(
|
|
250
|
+
input: BuildNewsletterMessageUpdatesInput,
|
|
251
|
+
) -> BinaryNode:
|
|
252
|
+
"""Build the newsletter ``<message_updates>`` IQ."""
|
|
253
|
+
if input.before is None and input.after is None:
|
|
254
|
+
raise ValueError("newsletter message updates require before or after")
|
|
255
|
+
attrs: dict[str, str] = {"count": str(input.count)}
|
|
256
|
+
if input.since is not None:
|
|
257
|
+
attrs["since"] = str(input.since)
|
|
258
|
+
if input.before is not None:
|
|
259
|
+
attrs["before"] = str(input.before)
|
|
260
|
+
elif input.after is not None:
|
|
261
|
+
attrs["after"] = str(input.after)
|
|
262
|
+
return build_iq_node(
|
|
263
|
+
WA_IQ_TYPES["GET"],
|
|
264
|
+
input.newsletter_jid,
|
|
265
|
+
WA_XMLNS["NEWSLETTER"],
|
|
266
|
+
[BinaryNode(tag="message_updates", attrs=attrs)],
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
__all__ = [
|
|
271
|
+
"ADMIN_REVOKE_EDIT_ATTR",
|
|
272
|
+
"NEWSLETTER_EDIT_ATTR",
|
|
273
|
+
"NEWSLETTER_MESSAGE_EDIT_MEDIA",
|
|
274
|
+
"NEWSLETTER_MESSAGE_EDIT_TEXT",
|
|
275
|
+
"NEWSLETTER_MESSAGE_MEDIA",
|
|
276
|
+
"NEWSLETTER_MESSAGE_POLL_CREATION",
|
|
277
|
+
"NEWSLETTER_MESSAGE_POLL_VOTE",
|
|
278
|
+
"NEWSLETTER_MESSAGE_REACTION",
|
|
279
|
+
"NEWSLETTER_MESSAGE_REACTION_REVOKE",
|
|
280
|
+
"NEWSLETTER_MESSAGE_REVOKE",
|
|
281
|
+
"NEWSLETTER_MESSAGE_TEXT",
|
|
282
|
+
"SENDER_REVOKE_EDIT_ATTR",
|
|
283
|
+
"BuildNewsletterMessageInput",
|
|
284
|
+
"BuildNewsletterMessageUpdatesInput",
|
|
285
|
+
"BuildNewsletterMessagesInput",
|
|
286
|
+
"BuildNewsletterViewReceiptInput",
|
|
287
|
+
"NewsletterMessageBase",
|
|
288
|
+
"build_newsletter_message_node",
|
|
289
|
+
"build_newsletter_message_updates_iq",
|
|
290
|
+
"build_newsletter_messages_iq",
|
|
291
|
+
"build_newsletter_subscribe_live_updates_iq",
|
|
292
|
+
"build_newsletter_view_receipt_node",
|
|
293
|
+
]
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""Offline-resume node builders (mirrors ``builders/offline.ts``)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from zapy._protocol.nodes import WA_NODE_TAGS
|
|
6
|
+
from zapy._transport.types import BinaryNode
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def build_offline_batch_node(count: int) -> BinaryNode:
|
|
10
|
+
"""Build the ``<ib><offline_batch count=.../>`` resume window request."""
|
|
11
|
+
return BinaryNode(
|
|
12
|
+
tag=WA_NODE_TAGS["INFO_BULLETIN"],
|
|
13
|
+
attrs={},
|
|
14
|
+
content=[
|
|
15
|
+
BinaryNode(tag="offline_batch", attrs={"count": str(count)}),
|
|
16
|
+
],
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
__all__ = ["build_offline_batch_node"]
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"""Pairing node builders (full implementation of ``builders/pairing.ts``)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from zapy._protocol import defaults as _defaults
|
|
6
|
+
from zapy._protocol.auth import WA_SIGNALING
|
|
7
|
+
from zapy._protocol.nodes import WA_IQ_TYPES, WA_NODE_TAGS, WA_XMLNS
|
|
8
|
+
from zapy._transport.types import BinaryNode
|
|
9
|
+
from zapy._util.bytes import ZERO_BYTES
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def build_companion_hello_request_node(
|
|
13
|
+
*,
|
|
14
|
+
phone_jid: str,
|
|
15
|
+
should_show_push_notification: bool,
|
|
16
|
+
wrapped_companion_ephemeral_pub: bytes | bytearray,
|
|
17
|
+
companion_server_auth_key_pub: bytes | bytearray,
|
|
18
|
+
companion_platform_id: str,
|
|
19
|
+
companion_platform_display: str,
|
|
20
|
+
) -> BinaryNode:
|
|
21
|
+
"""``<iq type=set xmlns=md><link_code_companion_reg stage=companion_hello …/>``."""
|
|
22
|
+
return BinaryNode(
|
|
23
|
+
tag=WA_NODE_TAGS["IQ"],
|
|
24
|
+
attrs={
|
|
25
|
+
"to": _defaults.HOST_DOMAIN,
|
|
26
|
+
"type": WA_IQ_TYPES["SET"],
|
|
27
|
+
"xmlns": WA_XMLNS["MD"],
|
|
28
|
+
},
|
|
29
|
+
content=[
|
|
30
|
+
BinaryNode(
|
|
31
|
+
tag=WA_NODE_TAGS["LINK_CODE_COMPANION_REG"],
|
|
32
|
+
attrs={
|
|
33
|
+
"jid": phone_jid,
|
|
34
|
+
"stage": WA_SIGNALING["LINK_CODE_STAGE_COMPANION_HELLO"],
|
|
35
|
+
"should_show_push_notification": "true"
|
|
36
|
+
if should_show_push_notification
|
|
37
|
+
else "false",
|
|
38
|
+
},
|
|
39
|
+
content=[
|
|
40
|
+
BinaryNode(
|
|
41
|
+
tag="link_code_pairing_wrapped_companion_ephemeral_pub",
|
|
42
|
+
attrs={},
|
|
43
|
+
content=bytes(wrapped_companion_ephemeral_pub),
|
|
44
|
+
),
|
|
45
|
+
BinaryNode(
|
|
46
|
+
tag="companion_server_auth_key_pub",
|
|
47
|
+
attrs={},
|
|
48
|
+
content=bytes(companion_server_auth_key_pub),
|
|
49
|
+
),
|
|
50
|
+
BinaryNode(
|
|
51
|
+
tag="companion_platform_id",
|
|
52
|
+
attrs={},
|
|
53
|
+
content=companion_platform_id,
|
|
54
|
+
),
|
|
55
|
+
BinaryNode(
|
|
56
|
+
tag="companion_platform_display",
|
|
57
|
+
attrs={},
|
|
58
|
+
content=companion_platform_display,
|
|
59
|
+
),
|
|
60
|
+
BinaryNode(
|
|
61
|
+
tag="link_code_pairing_nonce",
|
|
62
|
+
attrs={},
|
|
63
|
+
content=bytes(ZERO_BYTES),
|
|
64
|
+
),
|
|
65
|
+
],
|
|
66
|
+
)
|
|
67
|
+
],
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def build_get_country_code_request_node() -> BinaryNode:
|
|
72
|
+
"""``<iq type=get xmlns=md><link_code_companion_reg stage=get_country_code/>``."""
|
|
73
|
+
return BinaryNode(
|
|
74
|
+
tag=WA_NODE_TAGS["IQ"],
|
|
75
|
+
attrs={
|
|
76
|
+
"to": _defaults.HOST_DOMAIN,
|
|
77
|
+
"type": WA_IQ_TYPES["GET"],
|
|
78
|
+
"xmlns": WA_XMLNS["MD"],
|
|
79
|
+
},
|
|
80
|
+
content=[
|
|
81
|
+
BinaryNode(
|
|
82
|
+
tag=WA_NODE_TAGS["LINK_CODE_COMPANION_REG"],
|
|
83
|
+
attrs={"stage": WA_SIGNALING["LINK_CODE_STAGE_GET_COUNTRY_CODE"]},
|
|
84
|
+
)
|
|
85
|
+
],
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def build_companion_finish_request_node(
|
|
90
|
+
*,
|
|
91
|
+
phone_jid: str,
|
|
92
|
+
wrapped_key_bundle: bytes | bytearray,
|
|
93
|
+
companion_identity_public: bytes | bytearray,
|
|
94
|
+
ref: bytes | bytearray,
|
|
95
|
+
) -> BinaryNode:
|
|
96
|
+
"""``<iq type=set xmlns=md><link_code_companion_reg stage=companion_finish …/>``."""
|
|
97
|
+
return BinaryNode(
|
|
98
|
+
tag=WA_NODE_TAGS["IQ"],
|
|
99
|
+
attrs={
|
|
100
|
+
"to": _defaults.HOST_DOMAIN,
|
|
101
|
+
"type": WA_IQ_TYPES["SET"],
|
|
102
|
+
"xmlns": WA_XMLNS["MD"],
|
|
103
|
+
},
|
|
104
|
+
content=[
|
|
105
|
+
BinaryNode(
|
|
106
|
+
tag=WA_NODE_TAGS["LINK_CODE_COMPANION_REG"],
|
|
107
|
+
attrs={
|
|
108
|
+
"jid": phone_jid,
|
|
109
|
+
"stage": WA_SIGNALING["LINK_CODE_STAGE_COMPANION_FINISH"],
|
|
110
|
+
},
|
|
111
|
+
content=[
|
|
112
|
+
BinaryNode(
|
|
113
|
+
tag="link_code_pairing_wrapped_key_bundle",
|
|
114
|
+
attrs={},
|
|
115
|
+
content=bytes(wrapped_key_bundle),
|
|
116
|
+
),
|
|
117
|
+
BinaryNode(
|
|
118
|
+
tag="companion_identity_public",
|
|
119
|
+
attrs={},
|
|
120
|
+
content=bytes(companion_identity_public),
|
|
121
|
+
),
|
|
122
|
+
BinaryNode(
|
|
123
|
+
tag=WA_NODE_TAGS["LINK_CODE_PAIRING_REF"],
|
|
124
|
+
attrs={},
|
|
125
|
+
content=bytes(ref),
|
|
126
|
+
),
|
|
127
|
+
],
|
|
128
|
+
)
|
|
129
|
+
],
|
|
130
|
+
)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""Passive-mode stanza builder (full implementation of ``builders/passive.ts``)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Literal
|
|
6
|
+
|
|
7
|
+
from zapy._protocol import defaults as _defaults
|
|
8
|
+
from zapy._protocol.nodes import WA_IQ_TYPES, WA_XMLNS
|
|
9
|
+
from zapy._transport.node.query import build_iq_node
|
|
10
|
+
from zapy._transport.types import BinaryNode
|
|
11
|
+
|
|
12
|
+
WaPassiveMode = Literal["active", "passive"]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def build_passive_mode_iq_node(mode: WaPassiveMode) -> BinaryNode:
|
|
16
|
+
"""Build the ``<iq type=set xmlns=passive>`` mode-switch stanza."""
|
|
17
|
+
return build_iq_node(
|
|
18
|
+
WA_IQ_TYPES["SET"],
|
|
19
|
+
_defaults.HOST_DOMAIN,
|
|
20
|
+
WA_XMLNS["PASSIVE"],
|
|
21
|
+
[BinaryNode(tag=mode, attrs={})],
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
__all__ = [
|
|
26
|
+
"WaPassiveMode",
|
|
27
|
+
"build_passive_mode_iq_node",
|
|
28
|
+
]
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"""Pre-key node builders (mirrors ``builders/prekeys.ts``).
|
|
2
|
+
|
|
3
|
+
TEMPORARY: key material here is opaque bytes supplied by the signal layer;
|
|
4
|
+
only the stanza shapes are owned here. The ``to_raw_pub_key`` helper mirrors
|
|
5
|
+
``toRawPubKey`` for the fixed ``type + key`` encoding the oracle uses.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from dataclasses import dataclass
|
|
11
|
+
|
|
12
|
+
from zapy._protocol import defaults as _defaults
|
|
13
|
+
from zapy._protocol.nodes import WA_IQ_TYPES, WA_NODE_TAGS, WA_XMLNS
|
|
14
|
+
from zapy._signal.api.constants import SIGNAL_KEY_BUNDLE_TYPE_BYTES
|
|
15
|
+
from zapy._transport.node.query import build_iq_node
|
|
16
|
+
from zapy._transport.types import BinaryNode
|
|
17
|
+
from zapy._util.bytes import int_to_bytes
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def to_raw_pub_key(public_key: bytes | bytearray) -> bytes:
|
|
21
|
+
"""Encode ``type(1) + raw(32)`` like ``toRawPubKey`` for pre-key nodes."""
|
|
22
|
+
raw = bytes(public_key)
|
|
23
|
+
if len(raw) == 33 and raw[0] == SIGNAL_KEY_BUNDLE_TYPE_BYTES[0]:
|
|
24
|
+
return raw
|
|
25
|
+
return bytes([SIGNAL_KEY_BUNDLE_TYPE_BYTES[0]]) + raw
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass(frozen=True, slots=True)
|
|
29
|
+
class PreKeyRecordInput:
|
|
30
|
+
"""One one-time pre-key: numeric id plus raw public key."""
|
|
31
|
+
|
|
32
|
+
key_id: int = 0
|
|
33
|
+
public_key: bytes = b""
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@dataclass(frozen=True, slots=True)
|
|
37
|
+
class SignedPreKeyRecordInput:
|
|
38
|
+
"""Signed pre-key: id, raw public key, and the identity signature."""
|
|
39
|
+
|
|
40
|
+
key_id: int = 0
|
|
41
|
+
public_key: bytes = b""
|
|
42
|
+
signature: bytes = b""
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@dataclass(frozen=True, slots=True)
|
|
46
|
+
class RegistrationInfoInput:
|
|
47
|
+
"""Identity key pair plus registration id for the upload bundle."""
|
|
48
|
+
|
|
49
|
+
identity_public_key: bytes = b""
|
|
50
|
+
registration_id: int = 0
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _build_signed_pre_key_node(signed_pre_key: SignedPreKeyRecordInput) -> BinaryNode:
|
|
54
|
+
return BinaryNode(
|
|
55
|
+
tag=WA_NODE_TAGS["SKEY"],
|
|
56
|
+
attrs={},
|
|
57
|
+
content=[
|
|
58
|
+
BinaryNode(
|
|
59
|
+
tag=WA_NODE_TAGS["ID"],
|
|
60
|
+
attrs={},
|
|
61
|
+
content=int_to_bytes(3, signed_pre_key.key_id),
|
|
62
|
+
),
|
|
63
|
+
BinaryNode(
|
|
64
|
+
tag=WA_NODE_TAGS["VALUE"],
|
|
65
|
+
attrs={},
|
|
66
|
+
content=to_raw_pub_key(signed_pre_key.public_key),
|
|
67
|
+
),
|
|
68
|
+
BinaryNode(
|
|
69
|
+
tag=WA_NODE_TAGS["SIGNATURE"],
|
|
70
|
+
attrs={},
|
|
71
|
+
content=bytes(signed_pre_key.signature),
|
|
72
|
+
),
|
|
73
|
+
],
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def build_pre_key_upload_iq(
|
|
78
|
+
registration_info: RegistrationInfoInput,
|
|
79
|
+
signed_pre_key: SignedPreKeyRecordInput,
|
|
80
|
+
pre_keys: list[PreKeyRecordInput],
|
|
81
|
+
) -> BinaryNode:
|
|
82
|
+
"""Build the ``<iq type=set xmlns=encrypt>`` pre-key bundle upload."""
|
|
83
|
+
children: list[BinaryNode] = [
|
|
84
|
+
BinaryNode(
|
|
85
|
+
tag=WA_NODE_TAGS["IDENTITY"],
|
|
86
|
+
attrs={},
|
|
87
|
+
content=to_raw_pub_key(registration_info.identity_public_key),
|
|
88
|
+
),
|
|
89
|
+
BinaryNode(
|
|
90
|
+
tag=WA_NODE_TAGS["REGISTRATION"],
|
|
91
|
+
attrs={},
|
|
92
|
+
content=int_to_bytes(4, registration_info.registration_id),
|
|
93
|
+
),
|
|
94
|
+
BinaryNode(
|
|
95
|
+
tag=WA_NODE_TAGS["TYPE"],
|
|
96
|
+
attrs={},
|
|
97
|
+
content=bytes(SIGNAL_KEY_BUNDLE_TYPE_BYTES),
|
|
98
|
+
),
|
|
99
|
+
BinaryNode(
|
|
100
|
+
tag=WA_NODE_TAGS["LIST"],
|
|
101
|
+
attrs={},
|
|
102
|
+
content=[
|
|
103
|
+
BinaryNode(
|
|
104
|
+
tag=WA_NODE_TAGS["KEY"],
|
|
105
|
+
attrs={},
|
|
106
|
+
content=[
|
|
107
|
+
BinaryNode(
|
|
108
|
+
tag=WA_NODE_TAGS["ID"],
|
|
109
|
+
attrs={},
|
|
110
|
+
content=int_to_bytes(3, record.key_id),
|
|
111
|
+
),
|
|
112
|
+
BinaryNode(
|
|
113
|
+
tag=WA_NODE_TAGS["VALUE"],
|
|
114
|
+
attrs={},
|
|
115
|
+
content=to_raw_pub_key(record.public_key),
|
|
116
|
+
),
|
|
117
|
+
],
|
|
118
|
+
)
|
|
119
|
+
for record in pre_keys
|
|
120
|
+
],
|
|
121
|
+
),
|
|
122
|
+
_build_signed_pre_key_node(signed_pre_key),
|
|
123
|
+
]
|
|
124
|
+
return build_iq_node(
|
|
125
|
+
WA_IQ_TYPES["SET"], _defaults.HOST_DOMAIN, WA_XMLNS["SIGNAL"], children
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def build_signed_pre_key_rotate_iq(
|
|
130
|
+
signed_pre_key: SignedPreKeyRecordInput,
|
|
131
|
+
) -> BinaryNode:
|
|
132
|
+
"""Build the signed-pre-key ``<rotate>`` IQ."""
|
|
133
|
+
return build_iq_node(
|
|
134
|
+
WA_IQ_TYPES["SET"],
|
|
135
|
+
_defaults.HOST_DOMAIN,
|
|
136
|
+
WA_XMLNS["SIGNAL"],
|
|
137
|
+
[
|
|
138
|
+
BinaryNode(
|
|
139
|
+
tag=WA_NODE_TAGS["ROTATE"],
|
|
140
|
+
attrs={},
|
|
141
|
+
content=[_build_signed_pre_key_node(signed_pre_key)],
|
|
142
|
+
)
|
|
143
|
+
],
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
@dataclass(frozen=True, slots=True)
|
|
148
|
+
class MissingPreKeysDeviceTarget:
|
|
149
|
+
"""One device whose key bundle the server should return."""
|
|
150
|
+
|
|
151
|
+
device_id: int = 0
|
|
152
|
+
registration_id: int = 0
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
@dataclass(frozen=True, slots=True)
|
|
156
|
+
class MissingPreKeysUserTarget:
|
|
157
|
+
"""One user (plus devices) missing from the local session store."""
|
|
158
|
+
|
|
159
|
+
user_jid: str = ""
|
|
160
|
+
devices: tuple[MissingPreKeysDeviceTarget, ...] = ()
|
|
161
|
+
reason_identity: bool = False
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def build_missing_pre_keys_fetch_iq(
|
|
165
|
+
users: list[MissingPreKeysUserTarget],
|
|
166
|
+
) -> BinaryNode:
|
|
167
|
+
"""Build the ``<key_fetch>`` IQ for users missing key bundles."""
|
|
168
|
+
return build_iq_node(
|
|
169
|
+
WA_IQ_TYPES["GET"],
|
|
170
|
+
_defaults.HOST_DOMAIN,
|
|
171
|
+
WA_XMLNS["SIGNAL"],
|
|
172
|
+
[
|
|
173
|
+
BinaryNode(
|
|
174
|
+
tag=WA_NODE_TAGS["KEY_FETCH"],
|
|
175
|
+
attrs={},
|
|
176
|
+
content=[
|
|
177
|
+
BinaryNode(
|
|
178
|
+
tag=WA_NODE_TAGS["USER"],
|
|
179
|
+
attrs={
|
|
180
|
+
"jid": user.user_jid,
|
|
181
|
+
**({"reason": "identity"} if user.reason_identity else {}),
|
|
182
|
+
},
|
|
183
|
+
content=[
|
|
184
|
+
BinaryNode(
|
|
185
|
+
tag=WA_NODE_TAGS["DEVICE"],
|
|
186
|
+
attrs={"id": str(device.device_id)},
|
|
187
|
+
content=[
|
|
188
|
+
BinaryNode(
|
|
189
|
+
tag=WA_NODE_TAGS["REGISTRATION"],
|
|
190
|
+
attrs={},
|
|
191
|
+
content=int_to_bytes(4, device.registration_id),
|
|
192
|
+
)
|
|
193
|
+
],
|
|
194
|
+
)
|
|
195
|
+
for device in user.devices
|
|
196
|
+
],
|
|
197
|
+
)
|
|
198
|
+
for user in users
|
|
199
|
+
],
|
|
200
|
+
)
|
|
201
|
+
],
|
|
202
|
+
)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
__all__ = [
|
|
206
|
+
"MissingPreKeysDeviceTarget",
|
|
207
|
+
"MissingPreKeysUserTarget",
|
|
208
|
+
"PreKeyRecordInput",
|
|
209
|
+
"RegistrationInfoInput",
|
|
210
|
+
"SignedPreKeyRecordInput",
|
|
211
|
+
"build_missing_pre_keys_fetch_iq",
|
|
212
|
+
"build_pre_key_upload_iq",
|
|
213
|
+
"build_signed_pre_key_rotate_iq",
|
|
214
|
+
"to_raw_pub_key",
|
|
215
|
+
]
|