dev@locazia: edit signer method
This commit is contained in:
parent
492ab9d2ac
commit
86d6dde5ae
|
|
@ -9,7 +9,7 @@ import time
|
||||||
from app.api import app
|
from app.api import app
|
||||||
from app.bot import dp as uploader_bot_dp
|
from app.bot import dp as uploader_bot_dp
|
||||||
from app.client_bot import dp as client_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._utils.create_maria_tables import create_maria_tables
|
||||||
from app.core.logger import make_log
|
from app.core.logger import make_log
|
||||||
from app.core.models import Memory
|
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"Application normally started. HTTP port: {SANIC_PORT}")
|
||||||
make_log(None, f"Telegram bot: https://t.me/{telegram_bot_username}")
|
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"MariaDB host: {MYSQL_URI.split('@')[1].split('/')[0].replace('/', '')}")
|
||||||
|
make_log(None, f"API host: {PROJECT_HOST}")
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
_cmd = app.ctx.memory._execute_queue.pop(0)
|
_cmd = app.ctx.memory._execute_queue.pop(0)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
from Crypto.PublicKey import ECC
|
import nacl.signing
|
||||||
from Crypto.Hash import SHA256
|
import nacl.encoding
|
||||||
from Crypto.Signature import DSS
|
|
||||||
import base58
|
import base58
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -8,22 +7,18 @@ class Signer:
|
||||||
def __init__(self, seed: bytes):
|
def __init__(self, seed: bytes):
|
||||||
if len(seed) != 32:
|
if len(seed) != 32:
|
||||||
raise ValueError("Seed must be 32 bytes")
|
raise ValueError("Seed must be 32 bytes")
|
||||||
|
self.signing_key = nacl.signing.SigningKey(seed)
|
||||||
self.key = ECC.generate(curve='P-256', randfunc=lambda n: seed)
|
self.verify_key = self.signing_key.verify_key
|
||||||
self.verifier = DSS.new(self.key, 'fips-186-3')
|
|
||||||
|
|
||||||
def sign(self, data_bytes: bytes) -> str:
|
def sign(self, data_bytes: bytes) -> str:
|
||||||
hash_obj = SHA256.new(data_bytes)
|
signed_message = self.signing_key.sign(data_bytes)
|
||||||
signature = self.verifier.sign(hash_obj)
|
signature = signed_message.signature
|
||||||
signature_str = base58.b58encode(signature).decode()
|
return base58.b58encode(signature).decode()
|
||||||
return signature_str
|
|
||||||
|
|
||||||
def verify(self, data_bytes: str, signature: str) -> bool:
|
def verify(self, data_bytes: bytes, signature: str) -> bool:
|
||||||
data_bytes = base58.b58decode(data_bytes)
|
|
||||||
signature_bytes = base58.b58decode(signature)
|
signature_bytes = base58.b58decode(signature)
|
||||||
hash_obj = SHA256.new(data_bytes)
|
|
||||||
try:
|
try:
|
||||||
self.verifier.verify(hash_obj, signature_bytes)
|
self.verify_key.verify(data_bytes, signature_bytes)
|
||||||
return True
|
return True
|
||||||
except ValueError:
|
except nacl.exceptions.BadSignatureError:
|
||||||
return False
|
return False
|
||||||
|
|
|
||||||
|
|
@ -10,3 +10,4 @@ tonsdk==1.0.13
|
||||||
httpx==0.25.0
|
httpx==0.25.0
|
||||||
docker==7.0.0
|
docker==7.0.0
|
||||||
pycryptodome==3.20.0
|
pycryptodome==3.20.0
|
||||||
|
pynacl==1.5.0
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue