branta 3.2.2__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.
- {branta-3.2.2 → branta-3.2.4}/CHANGELOG.md +10 -0
- {branta-3.2.2 → branta-3.2.4}/PKG-INFO +1 -1
- {branta-3.2.2 → branta-3.2.4}/branta/extensions.py +2 -1
- {branta-3.2.2 → branta-3.2.4}/branta/v2/parser.py +17 -3
- {branta-3.2.2 → branta-3.2.4}/pyproject.toml +1 -1
- {branta-3.2.2 → branta-3.2.4}/tests/test_extensions.py +5 -0
- {branta-3.2.2 → branta-3.2.4}/tests/test_qr_parser.py +26 -0
- {branta-3.2.2 → branta-3.2.4}/tests/test_service.py +18 -0
- branta-3.2.2/example.py +0 -40
- {branta-3.2.2 → branta-3.2.4}/.github/workflows/tests.yml +0 -0
- {branta-3.2.2 → branta-3.2.4}/.gitignore +0 -0
- {branta-3.2.2 → branta-3.2.4}/CLAUDE.md +0 -0
- {branta-3.2.2 → branta-3.2.4}/LICENSE +0 -0
- {branta-3.2.2 → branta-3.2.4}/README.md +0 -0
- {branta-3.2.2 → branta-3.2.4}/SECURITY.md +0 -0
- {branta-3.2.2 → branta-3.2.4}/branta/__init__.py +0 -0
- {branta-3.2.2 → branta-3.2.4}/branta/enums.py +0 -0
- {branta-3.2.2 → branta-3.2.4}/branta/exceptions.py +0 -0
- {branta-3.2.2 → branta-3.2.4}/branta/models.py +0 -0
- {branta-3.2.2 → branta-3.2.4}/branta/options.py +0 -0
- {branta-3.2.2 → branta-3.2.4}/branta/v2/__init__.py +0 -0
- {branta-3.2.2 → branta-3.2.4}/branta/v2/builder.py +0 -0
- {branta-3.2.2 → branta-3.2.4}/branta/v2/client.py +0 -0
- {branta-3.2.2 → branta-3.2.4}/branta/v2/encryption.py +0 -0
- {branta-3.2.2 → branta-3.2.4}/branta/v2/secret_generator.py +0 -0
- {branta-3.2.2 → branta-3.2.4}/branta/v2/serialization.py +0 -0
- {branta-3.2.2 → branta-3.2.4}/branta/v2/service.py +0 -0
- {branta-3.2.2 → branta-3.2.4}/tests/__init__.py +0 -0
- {branta-3.2.2 → branta-3.2.4}/tests/test_builder.py +0 -0
- {branta-3.2.2 → branta-3.2.4}/tests/test_client.py +0 -0
- {branta-3.2.2 → branta-3.2.4}/tests/test_encryption.py +0 -0
- {branta-3.2.2 → branta-3.2.4}/tests/test_integration.py +0 -0
|
@@ -4,6 +4,16 @@ 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
|
+
|
|
12
|
+
## [3.2.3] - 2026-10-28
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
- Recognize signet and regtest Ark addresses (`tark1`) as `ark_address`, alongside mainnet `ark1`. Strict-mode hash-ZK lookup and registration treat them the same way as `ark1`.
|
|
16
|
+
|
|
7
17
|
## [3.2.2] - 2026-09-30
|
|
8
18
|
|
|
9
19
|
### Fixed
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: branta
|
|
3
|
-
Version: 3.2.
|
|
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
|
|
@@ -67,7 +67,8 @@ def is_bolt11(value: str) -> bool:
|
|
|
67
67
|
|
|
68
68
|
|
|
69
69
|
def is_ark(value: str) -> bool:
|
|
70
|
-
|
|
70
|
+
lower = value.lower()
|
|
71
|
+
return lower.startswith("ark1") or lower.startswith("tark1")
|
|
71
72
|
|
|
72
73
|
|
|
73
74
|
def is_silent_payment(value: str) -> bool:
|
|
@@ -5,10 +5,24 @@ from typing import Dict, List, Optional
|
|
|
5
5
|
from urllib.parse import parse_qs, unquote, urlparse
|
|
6
6
|
|
|
7
7
|
from branta.enums import DestinationType
|
|
8
|
-
from branta.extensions import is_bolt11, is_silent_payment
|
|
8
|
+
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:
|
|
@@ -27,7 +41,7 @@ def _detect_plain_text_type(value: str) -> Optional[DestinationType]:
|
|
|
27
41
|
return DestinationType.Bolt12
|
|
28
42
|
if lower.startswith("lnurl"):
|
|
29
43
|
return DestinationType.LnUrl
|
|
30
|
-
if
|
|
44
|
+
if is_ark(value):
|
|
31
45
|
return DestinationType.ArkAddress
|
|
32
46
|
if is_silent_payment(value):
|
|
33
47
|
return DestinationType.SilentPayment
|
|
@@ -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
|
|
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.
|
|
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" }
|
|
@@ -53,6 +53,10 @@ class TestIsArk:
|
|
|
53
53
|
def test_uppercase_is_ark(self):
|
|
54
54
|
assert is_ark("ARK1TESTADDRESS") is True
|
|
55
55
|
|
|
56
|
+
def test_tark1_prefix_is_ark(self):
|
|
57
|
+
assert is_ark("tark1testaddress") is True
|
|
58
|
+
assert is_ark("TARK1TESTADDRESS") is True
|
|
59
|
+
|
|
56
60
|
def test_bitcoin_address_not_ark(self):
|
|
57
61
|
assert is_ark("bc1qtest") is False
|
|
58
62
|
|
|
@@ -77,6 +81,7 @@ class TestGetHashZkType:
|
|
|
77
81
|
|
|
78
82
|
def test_ark_returns_ark_type(self):
|
|
79
83
|
assert get_hash_zk_type("ark1testaddress") == DestinationType.ArkAddress
|
|
84
|
+
assert get_hash_zk_type("tark1testaddress") == DestinationType.ArkAddress
|
|
80
85
|
|
|
81
86
|
def test_silent_payment_returns_silent_payment_type(self):
|
|
82
87
|
assert get_hash_zk_type("sp1testpayment") == DestinationType.SilentPayment
|
|
@@ -30,6 +30,10 @@ class TestQRParserPlainText:
|
|
|
30
30
|
parser = QRParser("ark1testaddress")
|
|
31
31
|
assert parser.destination_type == DestinationType.ArkAddress
|
|
32
32
|
|
|
33
|
+
def test_signet_ark_address_detected(self):
|
|
34
|
+
parser = QRParser("tark1testaddress")
|
|
35
|
+
assert parser.destination_type == DestinationType.ArkAddress
|
|
36
|
+
|
|
33
37
|
def test_silent_payment_detected(self):
|
|
34
38
|
parser = QRParser("sp1testpayment")
|
|
35
39
|
assert parser.destination_type == DestinationType.SilentPayment
|
|
@@ -169,6 +173,28 @@ class TestQRParserEdgeCases:
|
|
|
169
173
|
assert parser.destinations[1].value == "sp1qqwl5p9jhz0000h5zkvlf9gfqv9dl9qjp5ggq5x3fw"
|
|
170
174
|
assert parser.destinations[1].type == DestinationType.SilentPayment
|
|
171
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
|
+
|
|
172
198
|
|
|
173
199
|
class TestQRParserCombined:
|
|
174
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:
|
branta-3.2.2/example.py
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import asyncio
|
|
2
|
-
import json
|
|
3
|
-
import os
|
|
4
|
-
|
|
5
|
-
from branta.enums import BrantaServerBaseUrl, DestinationType, PrivacyMode
|
|
6
|
-
from branta.options import BrantaClientOptions
|
|
7
|
-
from branta.v2 import BrantaService
|
|
8
|
-
|
|
9
|
-
API_KEY = "77bc078af334fbcb616cec0b3e6f7e04c976c8629df8c616310924a65b24e3d6"
|
|
10
|
-
|
|
11
|
-
options = BrantaClientOptions(
|
|
12
|
-
base_url=BrantaServerBaseUrl.Localhost,
|
|
13
|
-
default_api_key=API_KEY,
|
|
14
|
-
privacy=PrivacyMode.Strict,
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
async def main() -> None:
|
|
19
|
-
async with BrantaService(options) as service:
|
|
20
|
-
payment = (
|
|
21
|
-
service.create_payment_builder()
|
|
22
|
-
.add_destination("bc1qar0srrr7xfkvy5l643lydnw9re59gtzzwf5mdq", DestinationType.BitcoinAddress)
|
|
23
|
-
.set_zk()
|
|
24
|
-
.set_child_platform("ChildCo", logo_url="https://example.com/logo.png")
|
|
25
|
-
.build()
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
result = await service.add_payment(payment)
|
|
29
|
-
|
|
30
|
-
print("Secret: ", result.secret)
|
|
31
|
-
print("Verify URL:", result.verify_url)
|
|
32
|
-
print("Payment:")
|
|
33
|
-
print(json.dumps(
|
|
34
|
-
{"destinations": [{"value": d.value, "type": d.type, "is_zk": d.is_zk} for d in result.payment.destinations]},
|
|
35
|
-
indent=2,
|
|
36
|
-
))
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if __name__ == "__main__":
|
|
40
|
-
asyncio.run(main())
|
|
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
|
|
File without changes
|