2StepsFromHell
2StepsFromHell

Reputation: 39

Python ECDSA failing to verify signature

I am trying to verify a Bitcoin signature using ECDSA in python but finding it very hard, many attempts failed already.

The params:

address: 33ELcBdg6W7parjGxNYUz5uHVHwPqopNjE

message: hzpPiNlB

signature(base64): I2fKdGNtR5owOWVoWchMVWwC/gf4qyYZ8G+kvuR7CaBhU/0SO149a3/ylBaiVWzfUoXI5HlgYPjkrptk0HfW1NQ=

Note: I have converted the signature from base64 to hexstring as that is required by ECDSA. Whenever I try to verify it, it says:

Expected 64 byte signature (128 hexstring), provided 65 byte signature (130 hexstring)

I had a look at many stackoverflow questions about ECDSA but none of the answers were 100% relevant to my qs. Your help is appreciated guys.

Update: I have used Bitcoin Python package. Have done this first to get the public key & then verify:

pip install bitcoin

>>> message = 'hzpPiNlB'
>>> signature = 'I2fKdGNtR5owOWVoWchMVWwC/gf4qyYZ8G+kvuR7CaBhU/0SO149a3/ylBaiVWzfUoXI5HlgYPjkrptk0HfW1NQ='
>>> import bitcoin
>>> recover_key = bitcoin.ecdsa_recover(message, signature)
>>> print(recover_key)
04bbdd00bafea40bf7b268baff4ec7635a0b12e94542067cf4077369be938f7b733c731248b88bb0f8b14783247705e568effd54e57643fc827852cf77d0ed8313
>>> verify = bitcoin.ecdsa_verify(message, signature, recover_key)
>>> print(verify)
True

Although the recovered pubkey is wrong up its somehow passing True. When using the correct pubkey which I have extracted from wallet I am getting False as result of verifying the signature.

 >>> message = 'hzpPiNlB'
 >>> signature = 'I2fKdGNtR5owOWVoWchMVWwC/gf4qyYZ8G+kvuR7CaBhU/0SO149a3/ylBaiVWzfUoXI5HlgYPjkrptk0HfW1NQ='
 >>> pub_key = '0352ab1e8ef8553fb307ae8dcafd2395fd06e5ca882f0e27143cb15cf495cc435e'
 >>> import bitcoin
 >>> verify = bitcoin.ecdsa_verify(message, signature, pub_key)
 >>> print(verify)
 False

Upvotes: 0

Views: 1188

Answers (1)

2StepsFromHell
2StepsFromHell

Reputation: 39

After extracting the pubkey by using the correct path, I can confirm that:

verify = bitcoin.ecdsa_verify(message, signature, pub_key).

is returning True.

Upvotes: -2

Related Questions