28 lines
942 B
Python
28 lines
942 B
Python
import ecdsa
|
|
from hashlib import sha256, sha512
|
|
|
|
|
|
class Signer:
|
|
@staticmethod
|
|
def sign_rfc6979(private_key: bytes, message: bytes) -> bytes:
|
|
if len(private_key) == 0 or private_key is None:
|
|
raise ValueError(f"Incorrect private_key: {private_key}")
|
|
|
|
sk = ecdsa.SigningKey.from_string(private_key, curve=ecdsa.NIST256p, hashfunc=sha256)
|
|
|
|
signature = sk.sign_deterministic(message)
|
|
|
|
return signature
|
|
|
|
@staticmethod
|
|
def sign(private_key: bytes, message: bytes) -> bytes:
|
|
if len(private_key) == 0 or private_key is None:
|
|
raise ValueError(f"Incorrect private key: {private_key}")
|
|
|
|
sk = ecdsa.SigningKey.from_string(private_key, curve=ecdsa.NIST256p, hashfunc=sha512)
|
|
signature = sk.sign(message)
|
|
|
|
# the first byte indicates the node version marker
|
|
signature_with_marker = bytes([0x04]) + signature
|
|
|
|
return signature_with_marker
|