fixes transactions
This commit is contained in:
parent
34a78d3e64
commit
711f7b1c63
@ -38,33 +38,33 @@ class Tx:
|
||||
return True
|
||||
|
||||
else:
|
||||
# total_in = 0
|
||||
# total_out = 0
|
||||
# message = self.__gather()
|
||||
# for addr,amount in self.inputs:
|
||||
# found = False
|
||||
# for s in self.sigs:
|
||||
# if Signature.verify(message, s, addr):
|
||||
# found = True
|
||||
# if not found:
|
||||
# return False
|
||||
# if amount < 0:
|
||||
# return False
|
||||
# total_in = total_in + amount
|
||||
# for addr in self.reqd:
|
||||
# found = False
|
||||
# for s in self.sigs:
|
||||
# if Signature.verify(message, s, addr):
|
||||
# found = True
|
||||
# if not found:
|
||||
# return False
|
||||
# for addr,amount in self.outputs:
|
||||
# if amount < 0:
|
||||
# return False
|
||||
# total_out = total_out + amount
|
||||
total_in = 0
|
||||
total_out = 0
|
||||
message = self.__gather()
|
||||
for addr,amount in self.inputs:
|
||||
found = False
|
||||
for s in self.sigs:
|
||||
if Signature.verify(message, s, addr):
|
||||
found = True
|
||||
if not found:
|
||||
return False
|
||||
if amount < 0:
|
||||
return False
|
||||
total_in = total_in + amount
|
||||
for addr in self.reqd:
|
||||
found = False
|
||||
for s in self.sigs:
|
||||
if Signature.verify(message, s, addr):
|
||||
found = True
|
||||
if not found:
|
||||
return False
|
||||
for addr,amount in self.outputs:
|
||||
if amount < 0:
|
||||
return False
|
||||
total_out = total_out + amount
|
||||
|
||||
# if total_out > total_in:
|
||||
# return False
|
||||
if total_out > total_in:
|
||||
return False
|
||||
return True
|
||||
|
||||
def __gather(self):
|
||||
|
@ -3,6 +3,7 @@ from cryptography.hazmat.primitives.asymmetric import rsa
|
||||
from cryptography.hazmat.primitives import serialization
|
||||
from cryptography.hazmat.primitives import hashes
|
||||
from cryptography.hazmat.primitives.asymmetric import padding
|
||||
from cryptography.hazmat.backends import default_backend
|
||||
|
||||
def generateKeys():
|
||||
private_key = rsa.generate_private_key(public_exponent=65537,key_size=2048)
|
||||
@ -43,29 +44,31 @@ def bytesToKeys(private_ser, public_ser):
|
||||
|
||||
def publicBytesToKey(public_ser):
|
||||
public_key = serialization.load_pem_public_key(
|
||||
public_ser
|
||||
public_ser,
|
||||
backend=default_backend()
|
||||
)
|
||||
return public_key
|
||||
|
||||
def privateBytesToKey(private_ser):
|
||||
private_key = serialization.load_pem_private_key(
|
||||
private_ser,
|
||||
password=None
|
||||
password=None,
|
||||
backend=default_backend()
|
||||
)
|
||||
return private_key
|
||||
|
||||
def sign(message, private_key):
|
||||
message = bytes(str(message), 'utf-8')
|
||||
key = privateBytesToKey(private_key)
|
||||
signature = key.sign(
|
||||
signature = private_key.sign(
|
||||
message,
|
||||
padding.PSS(mgf=padding.MGF1(hashes.SHA256()), salt_length=padding.PSS.MAX_LENGTH),
|
||||
hashes.SHA256()
|
||||
)
|
||||
return signature
|
||||
|
||||
def verify(message, signature, public_key):
|
||||
def verify(message, signature, public_ser):
|
||||
message = bytes(str(message), 'utf-8')
|
||||
public_key = publicBytesToKey(public_ser)
|
||||
try:
|
||||
public_key.verify(
|
||||
signature,
|
||||
|
Loading…
x
Reference in New Issue
Block a user