Verified Commit 26348939 authored by Jakob Moser's avatar Jakob Moser
Browse files

Implement encrypted exports

parent 50049a5f
Loading
Loading
Loading
Loading
+21 −2
Original line number Diff line number Diff line
@@ -3,12 +3,15 @@ from pathlib import Path
from typing import Annotated

import typer
from pyrage import encrypt as age_encrypt
from pyrage import x25519
from sqlalchemy import select

from poolpay import db, paths
from poolpay.model.BankAccount import BankAccount
from poolpay.model.messages.UpdateBalanceMessage import UpdateBalanceMessage
from poolpay.model.Transaction import Transaction
from poolpay.paths import recipient_key_file

app = typer.Typer()

@@ -40,6 +43,12 @@ def export(
            help="An optonal regex to keep only transactions with matching purpose"
        ),
    ] = r"Aufladen",
    encrypt: Annotated[
        bool,
        typer.Option(
            help="If the export should be encrypted with the poolpay age key."
        ),
    ] = False,
) -> None:
    """
    Export all relevant transactions as messages to be applied in a running PoolPay instance via the Wire server.
@@ -63,8 +72,18 @@ def export(
        for transaction in transactions
    ]

    for message in messages:
        print(message)
    messages_string = "\n".join(str(m) for m in messages)

    if encrypt:
        recipient = x25519.Recipient.from_str(
            recipient_key_file.read_text(encoding="utf-8")
        )
        encrypted = age_encrypt(
            messages_string.encode("utf-8"), [recipient], armored=True
        )
        print(encrypted.decode("utf-8"))
    else:
        print(messages_string)


if __name__ == "__main__":
+11 −1
Original line number Diff line number Diff line
@@ -2,8 +2,18 @@ from pathlib import Path

proj_dir = Path(__file__).parent.parent.resolve()
instance_dir = proj_dir / "instance"
keys_dir = proj_dir / "keys"

vault_file = proj_dir / "instance.img"
db_file = instance_dir / "poolpay.db"
socket_path = proj_dir / "wire.socket"
recipient_key_file = keys_dir / "recipient.txt"

__all__ = ["proj_dir", "instance_dir", "vault_file", "db_file"]
__all__ = [
    "proj_dir",
    "instance_dir",
    "keys_dir",
    "vault_file",
    "db_file",
    "recipient_key_file",
]
+1 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ dependencies = [
    "mfrc522~=0.0.7",
    "pi-rc522~=2.3.0",
    "pygame~=2.6.1",
    "pyrage>=1.3.0",
    "rpi-lgpio~=0.6",
    "schwifty>=2026.3.0",
    "sqlalchemy~=2.0.38",
+14 −0
Original line number Diff line number Diff line
@@ -431,6 +431,7 @@ dependencies = [
    { name = "mfrc522" },
    { name = "pi-rc522" },
    { name = "pygame" },
    { name = "pyrage" },
    { name = "rpi-lgpio" },
    { name = "schwifty" },
    { name = "sqlalchemy" },
@@ -446,6 +447,7 @@ requires-dist = [
    { name = "mfrc522", specifier = "~=0.0.7" },
    { name = "pi-rc522", specifier = "~=2.3.0" },
    { name = "pygame", specifier = "~=2.6.1" },
    { name = "pyrage", specifier = ">=1.3.0" },
    { name = "rpi-lgpio", specifier = "~=0.6" },
    { name = "schwifty", specifier = ">=2026.3.0" },
    { name = "sqlalchemy", specifier = "~=2.0.38" },
@@ -493,6 +495,18 @@ wheels = [
    { url = "https://files.pythonhosted.org/packages/f4/7e/a72dd26f3b0f4f2bf1dd8923c85f7ceb43172af56d63c7383eb62b332364/pygments-2.20.0-py3-none-any.whl", hash = "sha256:81a9e26dd42fd28a23a2d169d86d7ac03b46e2f8b59ed4698fb4785f946d0176", size = 1231151, upload-time = "2026-03-29T13:29:30.038Z" },
]

[[package]]
name = "pyrage"
version = "1.3.0"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/ee/e8/918161376594d69b294e920bd6444f1d9997e6e6dd2aca18e15f1ef72463/pyrage-1.3.0.tar.gz", hash = "sha256:b283a2e3d688cbf68c707f57d93fdab3304ff57c7e2e6b710c0b4bc9096ad9da", size = 30120, upload-time = "2025-06-14T01:28:04.108Z" }
wheels = [
    { url = "https://files.pythonhosted.org/packages/f7/6e/3095678ee12f0401e1de17f4d6993783b20a4b807daf69e23b170724e5f4/pyrage-1.3.0-cp39-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:907901ada8d63d674cc9005889150846c7349ef587ee8bf5e9278b79c54b4679", size = 1563258, upload-time = "2025-06-14T01:27:57.886Z" },
    { url = "https://files.pythonhosted.org/packages/3b/e7/f515fbc972a5d83e9fa82d1c23a16f733f4dd6c2c6ae33d9054ca04a8d92/pyrage-1.3.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ea452cb9c9c47083a96b309467dea5614d12530e1de4b6585f10aa04d3d19d1c", size = 785930, upload-time = "2025-06-14T01:27:59.755Z" },
    { url = "https://files.pythonhosted.org/packages/38/f3/e91bf604fd40c42c60e8f95075cddb0b85d0bdf452f736b533b1bad550e0/pyrage-1.3.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ab066b22925c5a0ec5fead2e21e4586b21d5da730055c7e46caa978bd99de936", size = 847692, upload-time = "2025-06-14T01:28:01.042Z" },
    { url = "https://files.pythonhosted.org/packages/88/59/15fd1945b02e6f93eff5a2ff352e67f85f51bf543769484f9bd960868c19/pyrage-1.3.0-cp39-abi3-win_amd64.whl", hash = "sha256:3be314a9746809c2710bfd144a6acf0c54a40f43e306857b9778a9d871ad97b3", size = 767566, upload-time = "2025-06-14T01:28:02.597Z" },
]

[[package]]
name = "requests"
version = "2.34.2"