branta 3.2.3__tar.gz → 3.2.4__tar.gz

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.
Files changed (31) hide show
  1. {branta-3.2.3 → branta-3.2.4}/CHANGELOG.md +5 -0
  2. {branta-3.2.3 → branta-3.2.4}/PKG-INFO +1 -1
  3. {branta-3.2.3 → branta-3.2.4}/branta/v2/parser.py +15 -1
  4. {branta-3.2.3 → branta-3.2.4}/pyproject.toml +1 -1
  5. {branta-3.2.3 → branta-3.2.4}/tests/test_qr_parser.py +22 -0
  6. {branta-3.2.3 → branta-3.2.4}/tests/test_service.py +18 -0
  7. {branta-3.2.3 → branta-3.2.4}/.github/workflows/tests.yml +0 -0
  8. {branta-3.2.3 → branta-3.2.4}/.gitignore +0 -0
  9. {branta-3.2.3 → branta-3.2.4}/CLAUDE.md +0 -0
  10. {branta-3.2.3 → branta-3.2.4}/LICENSE +0 -0
  11. {branta-3.2.3 → branta-3.2.4}/README.md +0 -0
  12. {branta-3.2.3 → branta-3.2.4}/SECURITY.md +0 -0
  13. {branta-3.2.3 → branta-3.2.4}/branta/__init__.py +0 -0
  14. {branta-3.2.3 → branta-3.2.4}/branta/enums.py +0 -0
  15. {branta-3.2.3 → branta-3.2.4}/branta/exceptions.py +0 -0
  16. {branta-3.2.3 → branta-3.2.4}/branta/extensions.py +0 -0
  17. {branta-3.2.3 → branta-3.2.4}/branta/models.py +0 -0
  18. {branta-3.2.3 → branta-3.2.4}/branta/options.py +0 -0
  19. {branta-3.2.3 → branta-3.2.4}/branta/v2/__init__.py +0 -0
  20. {branta-3.2.3 → branta-3.2.4}/branta/v2/builder.py +0 -0
  21. {branta-3.2.3 → branta-3.2.4}/branta/v2/client.py +0 -0
  22. {branta-3.2.3 → branta-3.2.4}/branta/v2/encryption.py +0 -0
  23. {branta-3.2.3 → branta-3.2.4}/branta/v2/secret_generator.py +0 -0
  24. {branta-3.2.3 → branta-3.2.4}/branta/v2/serialization.py +0 -0
  25. {branta-3.2.3 → branta-3.2.4}/branta/v2/service.py +0 -0
  26. {branta-3.2.3 → branta-3.2.4}/tests/__init__.py +0 -0
  27. {branta-3.2.3 → branta-3.2.4}/tests/test_builder.py +0 -0
  28. {branta-3.2.3 → branta-3.2.4}/tests/test_client.py +0 -0
  29. {branta-3.2.3 → branta-3.2.4}/tests/test_encryption.py +0 -0
  30. {branta-3.2.3 → branta-3.2.4}/tests/test_extensions.py +0 -0
  31. {branta-3.2.3 → branta-3.2.4}/tests/test_integration.py +0 -0
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [3.2.4] - 2026-10-28
8
+
9
+ ### Fixed
10
+ - `get_payments_by_qr_code` strips the same control characters as `urlparse` — tab, line feed, and carriage return anywhere, plus leading C0 controls — before it types a QR destination. A control byte inside `bitcoin:` no longer leaves the address untyped, so a swapped address still raises `Tampered`.
11
+
7
12
  ## [3.2.3] - 2026-10-28
8
13
 
9
14
  ### Added
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: branta
3
- Version: 3.2.3
3
+ Version: 3.2.4
4
4
  Summary: Python SDK for the Branta V2 API — payment destination lookup and registration with zero-knowledge encryption support
5
5
  Project-URL: Homepage, https://branta.pro
6
6
  Project-URL: Repository, https://github.com/BrantaOps/branta-python
@@ -9,6 +9,20 @@ from branta.extensions import is_ark, is_bolt11, is_silent_payment
9
9
 
10
10
  _LN_ADDRESS_RE = re.compile(r"^[^@\s]+@[^@\s]+\.[^@\s]+$")
11
11
  _ETH_HEX_RE = re.compile(r"^[0-9a-fA-F]{40}$")
12
+ # urllib.parse.urlparse strips these before it reads the scheme: leading C0 controls
13
+ # and spaces, then tab/LF/CR anywhere. It does not strip trailing C0 controls.
14
+ _URLPARSE_LEADING_C0_OR_SPACE = "".join(chr(code) for code in range(0x21))
15
+
16
+
17
+ def _normalize_qr_text(qr_text: str) -> str:
18
+ # Destination typing reads the raw text. It has to see the same string urlparse
19
+ # does, or a control byte inside "bitcoin:" leaves the address untyped and the
20
+ # swap check never runs.
21
+ value = qr_text.strip()
22
+ value = value.lstrip(_URLPARSE_LEADING_C0_OR_SPACE)
23
+ for char in ("\t", "\n", "\r"):
24
+ value = value.replace(char, "")
25
+ return value
12
26
 
13
27
 
14
28
  def _is_ethereum_address(value: str) -> bool:
@@ -106,7 +120,7 @@ class QRParser:
106
120
  self.on_chain_encryption_text: Optional[str] = None
107
121
  self.on_chain_encryption_secret: Optional[str] = None
108
122
 
109
- text = qr_text.strip()
123
+ text = _normalize_qr_text(qr_text)
110
124
 
111
125
  try:
112
126
  parsed = urlparse(text)
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "branta"
7
- version = "3.2.3"
7
+ version = "3.2.4"
8
8
  description = "Python SDK for the Branta V2 API — payment destination lookup and registration with zero-knowledge encryption support"
9
9
  readme = "README.md"
10
10
  license = { text = "MIT" }
@@ -173,6 +173,28 @@ class TestQRParserEdgeCases:
173
173
  assert parser.destinations[1].value == "sp1qqwl5p9jhz0000h5zkvlf9gfqv9dl9qjp5ggq5x3fw"
174
174
  assert parser.destinations[1].type == DestinationType.SilentPayment
175
175
 
176
+ @pytest.mark.parametrize(
177
+ "prefix",
178
+ ["bitcoi\tn:", "bitcoi\nn:", "bitcoi\rn:", "\x01bitcoin:"],
179
+ )
180
+ def test_control_char_in_scheme_types_bitcoin_address(self, prefix):
181
+ parser = QRParser(f"{prefix}1attackeraddr?branta_id=ID1&branta_secret=SEC1")
182
+ assert parser.is_on_chain_zk() is True
183
+ assert parser.destination == "1attackeraddr"
184
+ assert parser.destination_type == DestinationType.BitcoinAddress
185
+ assert parser.on_chain_encryption_text == "ID1"
186
+ assert parser.on_chain_encryption_secret == "SEC1"
187
+
188
+ def test_tab_inside_address_uses_the_address_urlparse_would_pay(self):
189
+ parser = QRParser("bitcoin:1attac\tkeraddr?branta_id=ID1&branta_secret=SEC1")
190
+ assert parser.destination == "1attackeraddr"
191
+ assert parser.destination_type == DestinationType.BitcoinAddress
192
+
193
+ def test_tab_inside_lightning_scheme_still_types_bolt11(self):
194
+ parser = QRParser("lightnin\tg:lnbc100n1ptest")
195
+ assert parser.destination == "lnbc100n1ptest"
196
+ assert parser.destination_type == DestinationType.Bolt11
197
+
176
198
 
177
199
  class TestQRParserCombined:
178
200
  def test_combined_zk_qr(self):
@@ -261,6 +261,24 @@ class TestGetPaymentsByQrCodeAddressBinding:
261
261
  await service.get_payments_by_qr_code(qr)
262
262
  assert exc_info.value.reason == BrantaPaymentExceptionReason.Tampered
263
263
 
264
+ @pytest.mark.parametrize(
265
+ "prefix",
266
+ ["bitcoi\tn:", "bitcoi\nn:", "bitcoi\rn:", "\x01bitcoin:"],
267
+ )
268
+ async def test_control_char_in_scheme_swapped_address_rejects(
269
+ self, service, client_mock, aes_mock, prefix
270
+ ):
271
+ async def get_side_effect(lookup, opts=None, signal=None):
272
+ if lookup == ENCRYPTED_BITCOIN_ADDRESS:
273
+ return [zk_bitcoin_payment()]
274
+ return []
275
+ client_mock.get_payments = AsyncMock(side_effect=get_side_effect)
276
+
277
+ qr = f"{prefix}{SWAPPED_ADDRESS}?branta_id={ENCRYPTED_BITCOIN_ADDRESS}&branta_secret={SECRET}"
278
+ with pytest.raises(BrantaPaymentException) as exc_info:
279
+ await service.get_payments_by_qr_code(qr)
280
+ assert exc_info.value.reason == BrantaPaymentExceptionReason.Tampered
281
+
264
282
  async def test_matching_address_does_not_throw(self, service, client_mock, aes_mock):
265
283
  async def get_side_effect(lookup, opts=None, signal=None):
266
284
  if lookup == ENCRYPTED_BITCOIN_ADDRESS:
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes