Skip to content

Commit

Permalink
Correct
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomocaironi committed Nov 28, 2021
1 parent e43bbea commit 3b153e1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions btclib_libsecp256k1/dsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

def sign(
msg_bytes: bytes, prvkey: Union[bytes, int], ndata: Optional[bytes] = None
) -> int:
"Creates an ECDSA signature."
) -> bytes:
"Create an ECDSA signature."

if isinstance(prvkey, int):
prvkey_bytes = prvkey.to_bytes(32, "big")
Expand All @@ -29,14 +29,14 @@ def sign(
ndata = secrets.token_bytes(32)
ndata = b"\x00" * (32 - len(ndata)) + ndata
if not lib.secp256k1_ecdsa_sign(ctx, sig, msg_bytes, prvkey_bytes, null, ndata):
return 0
raise Exception
if not lib.secp256k1_ecdsa_signature_serialize_der(ctx, sig_bytes, length, sig):
return 0
raise Exception
return ffi.unpack(sig_bytes, length[0])


def verify(msg_bytes: bytes, pubkey_bytes: bytes, signature_bytes: bytes) -> int:
"Verifies a ECDSA signature"
"Verify a ECDSA signature"

signature = ffi.new("secp256k1_ecdsa_signature *")
lib.secp256k1_ecdsa_signature_parse_der(
Expand Down
8 changes: 4 additions & 4 deletions btclib_libsecp256k1/ssa.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

def sign(
msg_bytes: bytes, prvkey: Union[bytes, int], aux_rand32: Optional[bytes] = None
) -> int:
"Creates a Schhnorr signature"
) -> bytes:
"Create a Schhnorr signature"

if isinstance(prvkey, int):
prvkey_bytes = prvkey.to_bytes(32, "big")
Expand All @@ -31,11 +31,11 @@ def sign(
aux_rand32 = b"\x00" * (32 - len(aux_rand32)) + aux_rand32
if lib.secp256k1_schnorrsig_sign(ctx, sig, msg_bytes, keypair, aux_rand32):
return ffi.unpack(sig, 64)
return 0
raise Exception


def verify(msg_bytes: bytes, pubkey_bytes: bytes, signature_bytes: bytes) -> int:
"Verifies a Schhnorr signature"
"Verify a Schhnorr signature"

if len(pubkey_bytes) == 32:
pubkey_bytes = b"\x02" + pubkey_bytes
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ max-line-length = 100
[tool.pylint.master]
extension-pkg-whitelist="_btclib_libsecp256k1"
min-similarity-lines=6
disable = ["duplicate-code" # R0801]
disable = ["duplicate-code"] # R0801

0 comments on commit 3b153e1

Please sign in to comment.