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

Commit

Permalink
Merge pull request #29 from ixje/refactor_sign
Browse files Browse the repository at this point in the history
Refactor Crypto.Sign
  • Loading branch information
metachris committed Jan 9, 2018
2 parents 9ebba05 + fee0df3 commit cf16825
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
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

0 comments on commit cf16825

Please sign in to comment.