Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: release on January 07, 2021, 12:53:27 PM



Title: Help with python elliptic curve generator
Post by: release on January 07, 2021, 12:53:27 PM
I'm still in training wheels but enjoying learning how to generate my own private key etc. Want help finding good python library to help with the point addition process from private key to generating public key. I dont want to generate all steps in one As I'm enjoying doing it step by step. Thanks


Title: Re: Help with python elliptic curve generator
Post by: NotATether on January 07, 2021, 01:29:06 PM
fastecdsa is a Python module that exposes methods for point addition and multiplication, and it also gives you a convenience method to derive the public key from the private key. I know you don't want that part but it's worth mentioning if you ever want to get t without all the hard work.

Then you can just run the expression Pub = Prv*G directly to get the public key from the private key, assuming you get the x and y coordinates of the G (generator) point of secp256k1.

Code:
from fastecdsa.curve import secp256k1
from fastecdsa.point import Point

# x and y are 256-bit hex numbers
Prv = Point(x, y, curve=secp256k1)

# update: fixed incorrect G points
gx = 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798
gy = 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8
G = Point(gx, gy, curve=secp256k1)

Pub = Prv*G

https://pypi.org/project/fastecdsa/


Title: Re: Help with python elliptic curve generator
Post by: BASE16 on January 14, 2021, 05:09:44 PM
I agree with you it's better to work on the bit level.
With the above you have G[1] so now you can compute G[2] to G[256] and use that as a starting point.
Then you add all 1's in the binary private key and this will take you step by step, or point by point to your final public point.
You really don't need any external libraries for that.