Skip to content
This repository has been archived by the owner on Sep 10, 2019. It is now read-only.

Refactor Crypto.Sign #29

Merged
merged 3 commits into from
Jan 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions neocore/Cryptography/Crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,13 @@ def ToAddress(script_hash):
return scripthash_to_address(script_hash.Data)

@staticmethod
def Sign(message, private_key, public_key):
def Sign(message, private_key):
"""
Sign the message with the given private key.

Args:
message (str): message to be signed
private_key (str): 32 byte key as a double digit hex string (e.g. having a length of 64)
public_key: UNUSED.
Returns:
bytearray: the signature of the message.
"""
Expand Down Expand Up @@ -189,30 +188,29 @@ def Hash256(self, message):
"""
return Crypto.Hash256(message)

def Sign(self, message, prikey, public_key):
def Sign(self, message, private_key):
"""
Sign the message with the given private key.

Args:
message (str): message to be signed
prikey (str): 32 byte key as a double digit hex string (e.g. having a length of 64)
public_key: UNUSED.
private_key (str): 32 byte key as a double digit hex string (e.g. having a length of 64)

Returns:
bytearray: the signature of the message.
"""
return Crypto.Sign(message, prikey, public_key)
return Crypto.Sign(message, private_key)

def VerifySignature(self, message, signature, pubkey):
def VerifySignature(self, message, signature, public_key):
"""
Verify the integrity of the message.

Args:
message (str): the message to verify.
signature (bytearray): the signature belonging to the message.
pubkey (ECPoint): the public key to use for verifying the signature.
public_key (ECPoint): the public key to use for verifying the signature.

Returns:
bool: True if verification passes. False otherwise.
"""
return Crypto.VerifySignature(message, signature, pubkey)
return Crypto.VerifySignature(message, signature, public_key)
4 changes: 2 additions & 2 deletions tests/test_cryptography.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ def test_sign_and_verify(self):
keypair = KeyPair(privkey)
hashdata = b'aabbcc'

keypair_signature = Crypto.Sign(hashdata, bytes(keypair.PrivateKey), keypair.PublicKey)
keypair_signature2 = Crypto.Default().Sign(hashdata, bytes(keypair.PrivateKey), keypair.PublicKey)
keypair_signature = Crypto.Sign(hashdata, bytes(keypair.PrivateKey))
keypair_signature2 = Crypto.Default().Sign(hashdata, bytes(keypair.PrivateKey))
self.assertEqual(keypair_signature, keypair_signature2)

verification_result = Crypto.VerifySignature(hashdata.decode('utf8'), keypair_signature, keypair.PublicKey)
Expand Down