jimmysong / programmingbitcoin

Repository for the book
Other
1.75k stars 656 forks source link

Private key used for sec in tx signing? #232

Closed mshearer0 closed 2 years ago

mshearer0 commented 2 years ago

In sign_input in tx.py why is the private and not public key used to generate the sec?

calculate the sec sec = private_key.point.sec()

aniketambore commented 2 years ago

why is the private and not public key used to generate the sec?

We will be generating public_key from the private_key :). The purpose of passing private_key in sign_input is because we want to generate the der signature by signing z.

Also, the PrivateKey class in ecc.py is the one where we've the access of sec from the sec() method of S256Point.

Also, if you check the Exercise 1 of chapter 4 , we'd used private_key only, to find the uncompressed sec format.

That's the correct way of generating sec public key.

Thank you.

mshearer0 commented 2 years ago

Many thanks @aniketambore

I’d missed the fact that the point initialised in the private key class is actually the public key:

def init(self, secret): self.secret = secret self.point = secret * G