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