dev@locazia: edit signer method

This commit is contained in:
user 2024-03-06 12:43:41 +03:00
parent 492ab9d2ac
commit 86d6dde5ae
3 changed files with 13 additions and 16 deletions

View File

@ -9,7 +9,7 @@ import time
from app.api import app
from app.bot import dp as uploader_bot_dp
from app.client_bot import dp as client_bot_dp
from app.core._config import SANIC_PORT, MYSQL_URI, TELEGRAM_API_KEY
from app.core._config import SANIC_PORT, MYSQL_URI, PROJECT_HOST
from app.core._utils.create_maria_tables import create_maria_tables
from app.core.logger import make_log
from app.core.models import Memory
@ -36,6 +36,7 @@ async def execute_queue(app):
make_log(None, f"Application normally started. HTTP port: {SANIC_PORT}")
make_log(None, f"Telegram bot: https://t.me/{telegram_bot_username}")
make_log(None, f"MariaDB host: {MYSQL_URI.split('@')[1].split('/')[0].replace('/', '')}")
make_log(None, f"API host: {PROJECT_HOST}")
while True:
try:
_cmd = app.ctx.memory._execute_queue.pop(0)

View File

@ -1,6 +1,5 @@
from Crypto.PublicKey import ECC
from Crypto.Hash import SHA256
from Crypto.Signature import DSS
import nacl.signing
import nacl.encoding
import base58
@ -8,22 +7,18 @@ class Signer:
def __init__(self, seed: bytes):
if len(seed) != 32:
raise ValueError("Seed must be 32 bytes")
self.key = ECC.generate(curve='P-256', randfunc=lambda n: seed)
self.verifier = DSS.new(self.key, 'fips-186-3')
self.signing_key = nacl.signing.SigningKey(seed)
self.verify_key = self.signing_key.verify_key
def sign(self, data_bytes: bytes) -> str:
hash_obj = SHA256.new(data_bytes)
signature = self.verifier.sign(hash_obj)
signature_str = base58.b58encode(signature).decode()
return signature_str
signed_message = self.signing_key.sign(data_bytes)
signature = signed_message.signature
return base58.b58encode(signature).decode()
def verify(self, data_bytes: str, signature: str) -> bool:
data_bytes = base58.b58decode(data_bytes)
def verify(self, data_bytes: bytes, signature: str) -> bool:
signature_bytes = base58.b58decode(signature)
hash_obj = SHA256.new(data_bytes)
try:
self.verifier.verify(hash_obj, signature_bytes)
self.verify_key.verify(data_bytes, signature_bytes)
return True
except ValueError:
except nacl.exceptions.BadSignatureError:
return False

View File

@ -10,3 +10,4 @@ tonsdk==1.0.13
httpx==0.25.0
docker==7.0.0
pycryptodome==3.20.0
pynacl==1.5.0