From e5cafd9d53ece2d1587c4340c5e40c4d867c8c4d Mon Sep 17 00:00:00 2001
From: bashrc
Date: Sun, 5 Jul 2026 11:15:08 +0100
Subject: [PATCH] Add qrcode for briar address
---
src/briar.py | 46 +++++++++++++++++++++++++++++++++++-
src/daemon_get.py | 4 +++-
src/daemon_get_images.py | 6 +++++
src/daemon_post_profile.py | 14 +++++++----
src/webapp_person_options.py | 10 ++++++--
src/webapp_profile.py | 11 +++++++--
6 files changed, 80 insertions(+), 11 deletions(-)
diff --git a/src/briar.py b/src/briar.py
index d0ac2033f..84d4a9401 100644
--- a/src/briar.py
+++ b/src/briar.py
@@ -8,8 +8,13 @@ __status__ = "Production"
__module_group__ = "Profile Metadata"
+import pyqrcode
+from src.utils import load_json
+from src.utils import acct_dir
from src.utils import get_attachment_property_value
from src.utils import remove_html
+from src.data import is_a_file
+from src.data import erase_file
def get_briar_address(actor_json: {}) -> str:
@@ -64,9 +69,47 @@ def get_briar_address(actor_json: {}) -> str:
return ''
-def set_briar_address(actor_json: {}, briar_address: str) -> None:
+def save_briar_qrcode(base_dir: str,
+ nickname: str, domain: str,
+ scale: int = 6) -> bool:
+ """Saves a qrcode image for the briar address of the person
+ This helps to transfer onion or i2p handles to a mobile device
+ """
+ qrcode_filename = \
+ acct_dir(base_dir, nickname, domain) + '/qrcode_briar.png'
+ if is_a_file(qrcode_filename):
+ return False
+ actor_filename = \
+ acct_dir(base_dir, nickname, domain) + '.json'
+ if not is_a_file(actor_filename):
+ return False
+ actor_json = load_json(actor_filename)
+ if not actor_json:
+ return False
+ briar_address = get_briar_address(actor_json)
+ if not briar_address:
+ return False
+ url = pyqrcode.create(briar_address)
+ try:
+ url.png(qrcode_filename, scale)
+ return True
+ except ModuleNotFoundError:
+ print('EX: save_briar_qrcode pyqrcode png module not found')
+ return False
+
+
+def set_briar_address(base_dir: str, nickname: str, domain: str,
+ actor_json: {}, briar_address: str,
+ qrcode_scale: int) -> None:
"""Sets an briar address for the given actor
"""
+ if not briar_address:
+ qrcode_filename = \
+ acct_dir(base_dir, nickname, domain) + '/qrcode_briar.png'
+ if is_a_file(qrcode_filename):
+ erase_file(qrcode_filename,
+ 'EX: cannot remove briar qrcode ' + qrcode_filename)
+
not_briar_address: bool = False
if len(briar_address) < 50:
@@ -147,3 +190,4 @@ def set_briar_address(actor_json: {}, briar_address: str) -> None:
"value": briar_address
}
actor_json['attachment'].append(new_briar_address)
+ save_briar_qrcode(base_dir, nickname, domain, qrcode_scale)
diff --git a/src/daemon_get.py b/src/daemon_get.py
index b84a5c308..3d6218f9e 100644
--- a/src/daemon_get.py
+++ b/src/daemon_get.py
@@ -2716,7 +2716,8 @@ def daemon_http_get(self) -> None:
if is_image_file(self.path) and \
(string_starts_with(self.path,
('/login.', '/qrcode.png', '/qrcode_lxmf.png',
- '/qrcode_ricochet.png', '/qrcode_enigma.png'))):
+ '/qrcode_ricochet.png', '/qrcode_enigma.png',
+ '/qrcode_briar.png'))):
icon_filename = data_dir(self.server.base_dir) + self.path
if is_a_file(icon_filename):
if etag_exists(self, icon_filename):
@@ -2757,6 +2758,7 @@ def daemon_http_get(self) -> None:
(self.path.endswith('/qrcode.png') or
self.path.endswith('/qrcode_lxmf.png') or
self.path.endswith('/qrcode_ricochet.png') or
+ self.path.endswith('/qrcode_briar.png') or
self.path.endswith('/qrcode_enigma.png'))):
if show_qrcode(self, calling_domain, self.path,
self.server.base_dir,
diff --git a/src/daemon_get_images.py b/src/daemon_get_images.py
index 75aad044b..45c417a0e 100644
--- a/src/daemon_get_images.py
+++ b/src/daemon_get_images.py
@@ -31,6 +31,7 @@ from src.person import save_person_qrcode
from src.lxmf import save_lxmf_qrcode
from src.ricochet import save_ricochet_qrcode
from src.enigma import save_enigma_qrcode
+from src.briar import save_briar_qrcode
from src.data import load_string
from src.data import load_binary
from src.data import is_a_file
@@ -488,6 +489,11 @@ def show_qrcode(self, calling_domain: str, path: str,
acct_dir(base_dir, nickname, domain) + '/qrcode_enigma.png'
qrcode_scale = 6
save_enigma_qrcode(base_dir, nickname, domain, qrcode_scale)
+ elif path.endswith('_briar.png'):
+ qr_filename = \
+ acct_dir(base_dir, nickname, domain) + '/qrcode_briar.png'
+ qrcode_scale = 6
+ save_briar_qrcode(base_dir, nickname, domain, qrcode_scale)
else:
if onion_domain:
qrcode_domain = onion_domain
diff --git a/src/daemon_post_profile.py b/src/daemon_post_profile.py
index 037009259..c8a0ed61a 100644
--- a/src/daemon_post_profile.py
+++ b/src/daemon_post_profile.py
@@ -1770,19 +1770,22 @@ def _profile_post_cwtch_address(fields: {}, actor_json: {},
return actor_changed
-def _profile_post_briar_address(fields: {}, actor_json: {},
+def _profile_post_briar_address(base_dir: str, nickname: str, domain: str,
+ fields: {}, actor_json: {},
actor_changed: bool) -> bool:
""" HTTP POST change briar address
"""
+ qrcode_scale = 6
current_briar_address = get_briar_address(actor_json)
if fields.get('briarAddress'):
if fields['briarAddress'] != current_briar_address:
- set_briar_address(actor_json,
- fields['briarAddress'])
+ set_briar_address(base_dir, nickname, domain, actor_json,
+ fields['briarAddress'], qrcode_scale)
actor_changed = True
else:
if current_briar_address:
- set_briar_address(actor_json, '')
+ set_briar_address(base_dir, nickname, domain,
+ actor_json, '', qrcode_scale)
actor_changed = True
return actor_changed
@@ -3101,7 +3104,8 @@ def profile_edit(self, calling_domain: str, cookie: str,
actor_changed)
actor_changed = \
- _profile_post_briar_address(fields, actor_json,
+ _profile_post_briar_address(base_dir, nickname, domain,
+ fields, actor_json,
actor_changed)
actor_changed = \
diff --git a/src/webapp_person_options.py b/src/webapp_person_options.py
index 7dfcb8eb6..581834c7f 100644
--- a/src/webapp_person_options.py
+++ b/src/webapp_person_options.py
@@ -515,11 +515,17 @@ def html_person_options(default_timeline: str,
if briar_address.startswith('briar://'):
options_str += \
' ' + \
- remove_html(briar_address) + '
\n'
+ remove_html(briar_address)
else:
options_str += \
' briar://' + \
- remove_html(briar_address) + '
\n'
+ remove_html(briar_address)
+ options_str += \
+ ' ' + \
+ '![' + translate['QR Code'] + \
+ '](/icons/qrcode.png)
\n'
if ricochet_address:
if ricochet_address.startswith('ricochet:'):
options_str += \
diff --git a/src/webapp_profile.py b/src/webapp_profile.py
index 7ec1210ec..a290037a6 100644
--- a/src/webapp_profile.py
+++ b/src/webapp_profile.py
@@ -1502,11 +1502,18 @@ def html_profile(signing_priv_key_pem: str,
if briar_address.startswith('briar://'):
donate_section += \
'\n'
+ briar_address + ''
else:
donate_section += \
'briar://
\n'
+ briar_address + ''
+ donate_section += \
+ ' ' + \
+ '
\n'
if ricochet_address:
if ricochet_address.startswith('ricochet:'):
donate_section += \