A minimal Python implementation of the secp256k1 elliptic curve and ECDSA digital signatures.
Includes full curve math, key generation, signing, and verification.
- secp256k1 curve operations (point addition, doubling, scalar multiplication)
- Private/public key generation
- Message signing with ECDSA (Keccak-256)
- Signature verification
This project is a simple proof of concept to help understand how secp256k1 and ECDSA work.
For any serious use, rely on optimized and well-tested cryptography libraries.
git clone https://github.com/0xMouiz/python-secp256k1.git
cd python-secp256k1
pip install pycryptodome
python3 main.py
[+] Private key: 0x1393b6573adf24c61b73561768d9ea4ba1670dcc77554f25938cbca621ed7645
[+] Public key: 0475ca8eaf8393377b7026664e661f63c130db105be05dd26f4431095feeed37ea48f35d4c941730943c37f5df7402e3afbbfd6e0739c67474218f8abdcd4a4dbe
[+] Signature: (23130664403154537087452900596597043914635898182345128000144997681634561679895, 80900801433921084062591453631520598013543041876276918936230036858357811199263)
[+] Signature valid? True
-
Generates a random 256-bit private key.
-
Derives the corresponding public key by scalar multiplication of the generator point
G
on the secp256k1 curve. -
Hashes the input message with Keccak-256.
-
Produces an ECDSA signature
(r, s)
. -
Verifies the signature using the public key.