Skip to content

Commit 35a6be9

Browse files
authored
Create security.py
1 parent 23bfd74 commit 35a6be9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/security.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from cryptography.hazmat.primitives.asymmetric import ec
2+
from cryptography.hazmat.primitives import serialization
3+
4+
class Security:
5+
def __init__(self):
6+
self.private_key = ec.generate_private_key(ec.SECP256R1())
7+
self.public_key = self.private_key.public_key()
8+
9+
def sign_transaction(self, transaction):
10+
signature = self.private_key.sign(transaction.encode())
11+
return signature
12+
13+
def verify_signature(self, transaction, signature):
14+
try:
15+
self.public_key.verify(signature, transaction.encode())
16+
return True
17+
except Exception:
18+
return False

0 commit comments

Comments
 (0)