15 lines
505 B
Python
15 lines
505 B
Python
import ecdsa
|
|
from hashlib import sha256
|
|
|
|
|
|
class Signer:
|
|
def sign_rfc6979(self, private_key: bytes, message: bytes) -> bytes:
|
|
if len(private_key) == 0 or private_key is None:
|
|
raise ValueError(f"Incorrect private_key: {private_key}")
|
|
|
|
# SECP256k1 is the Bitcoin elliptic curve
|
|
sk = ecdsa.SigningKey.from_string(private_key, curve=ecdsa.SECP256k1, hashfunc=sha256)
|
|
|
|
signature = sk.sign(message, sigencode=ecdsa.util.sigencode_string)
|
|
|
|
return signature
|