Coder Social home page Coder Social logo

secp256k2 / secp256k2 Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 5.0 28.99 MB

Basic Arithmetic or Advanced Cryptographic Protocols, SECP256k2 Provides the Essential Functions Needed for Modern Cryptography Generating & Converting

Home Page: https://secp256k2.readthedocs.io/en/latest/

License: MIT License

Python 100.00%
bitcoin ethereum package privatekey python python-packages python3 secp256k1 wallet secp256k2

secp256k2's Introduction

SECP256k2: A Modern Library for Elliptic Curve Cryptography

Google Colab PyPI - Downloads GitHub closed pull requests GitHub issues PyPI - License PyPI - Status Read the Docs programmer Official Website


Introduction

SECP256k2 is a high-performance and easy-to-use library for working with the SECP256k1 elliptic curve. This library is meticulously designed to provide a robust set of functionalities needed for the development of secure, fast, and efficient cryptographic applications.

Features

  • Optimized Performance: Leveraging optimized algorithms and efficient code structures for high-speed operations on the SECP256k1 curve.
  • Comprehensive Toolset: Offering a wide array of functionalities ranging from basic arithmetic operations to advanced cryptographic protocols.
  • Cross-Platform: Written in C & Python, SECP256k2 is designed to be used on multiple operating systems including Windows and Linux & Mac.

Getting Started

Installation

windows with pip

pip install --upgrade secp256k2

linux and Mac with pip3

pip3 install --upgrade secp256k2

Generate and Converet 10,000 Key to Compress and Uncompress Address. ( Check Now in Google Colab )

import os, timeit

setup_code = """
from os import urandom
from secp256k2 import Contactor

cont = Contactor()

def test_Profile_1():
    numd = urandom(32)[0]
    caddr = cont.privatekey_to_address(0, True, numd)
    uaddr = cont.privatekey_to_address(0, False, numd)
"""

# // Total Generated 
num = 10000

time1 = timeit.timeit("test_Profile_1()", setup=setup_code, number=num)


print(f"Generated & Convereted {format(num, ',')} Key To : {time1:.6f} sec")

Note

Output : Generated & Convereted 10,000 Key To : 0.393369 sec

Usage

A quick example to get you started with SECP256k2:

from secp256k2 import Contactor

cont = Contactor()

dec = 0x00000000000000000000000000000000000000000000001

wif_compress = cont.Decimal_To_Wif(dec, True)

wif_uncompress = cont.Decimal_To_Wif(dec, False)

compressed and uncompressed bitcoin address wallet from decimal (integer).

from secp256k2 import Contactor
# added Contactor class to project script
co = Contactor()
# dec
dec = 0xffffffffffffffffffffff880000000000000
compress_address = co.Decimal_To_Addr(dec, addr_type=0, compress=True)
uncompress_address = co.Decimal_To_Addr(dec, addr_type=0, compress=False)

Convert Decimal (Number) To Ethereum Address (Maximum Range: 115792089237316195423570985008687907852837564279074904382605163141518161494337):

from secp256k2 import Contactor

cont = Contactor()

dec_num = 1 # example , can use any range number to 
# ethereum address generated from decimal number 
eth_address = cont.Decimal_To_ETH_Addr(dec_num)

convert and Generated Wif Key from decimal Number:

from secp256k2 import Contactor

co = Contactor()

dec = 0xffffffffffffffffffffffffff8999999999333666666
wif_compress = co.Decimal_To_Wif(dec, True)
wif_uncompress = co.Decimal_To_Wif(dec, False)

Decimal to RIPEMD160

from secp256k2 import Contactor

co = Contactor()

dec = 0xfffffffffffffffffff99999999999

ripemd160 = co.Decimal_To_RIPEMD160(dec)

convert wif key to private key (hex):

from secp256k2 import Contactor

co = Contactor()

WIF = "WIF_KEY_HERE"

privatekey = co.Wif_To_Hex(WIF)

Convert Private Key To Wif Compressed and Uncompressed

from secp256k2 import Contactor

cont = Contactor()

privatekey = "PRIVATE_KEY_HERE"

wif_compress = cont.btc_pvk_to_wif(privatekey, True)

wif_uncompress = cont.btc_pvk_to_wif(privatekey, False)

Convert Wif to Private Key (integer/decimal):

from secp256k2 import Contactor

cont = Contactor()

wif = "WIF_KEY_HERE"

privatekey = cont.btc_wif_to_pvk_int(wif)

Convert Wif to Private Key (hex):

from secp256k2 import Contactor

cont = Contactor()

wif = "WIF_KEY_HERE"

privatekey = cont.btc_wif_to_pvk_hex(wif)

Convert Private Key (decimal) To RIPEMD160 (h160)

from secp256k2 import Contactor

cont = Contactor()

privatekey = 12345678901234567891234567891234567789

ripemd160 = cont.privatekey_to_h160(privatekey)

Convert Private Key (Decimal) To Compressed and uncompressed Address

  • addr_type (int) : P2PKH = 0, P2SH = 1, P2WPKH = 2
  • compress (bool) : True : Compress, False : Uncompress
  • private key (decimal) : 0 - 115792089237316195423570985008687907852837564279074904382605163141518161494337
from secp256k2 import Contactor

cont = Contactor()

privatekey = 12345678901234567891234567891234567789

address_compress = cont.privatekey_to_address(0, True, privatekey)

address_uncompress = cont.privatekey_to_address(0, False, privatekey)

Documentation

For more detailed information and advanced usage, please refer to the full documentation.

Contribution

We welcome contributions from the open-source community. If you find any issues or would like to propose enhancements, please feel free to open an issue or submit a pull request.

License

SECP256k2 is licensed under MIT. For more information, please see the LICENSE file.


Donate:

Bitcoin:1MMDRZA12xdBLD1P5AfEfvEMErp588vmF9

Programmer And Owner : PyMmdrza

Email : [email protected]

official website : MMDRZA.COM

secp256k2's People

Contributors

pymmdrza avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

secp256k2's Issues

need to understand usage

hi,
I tried to use your library but have problems, can you check the codes and give examples to implement your lib instead of k1?

"""
USAGE :

python3 address.py -a 1rSnXMr63jdCuegJFuidJqWxUPV7AtUf7 -b 24
python3 address.py -a 13zb1hQbWVsc2S7ZTZnP2G4undNNpdh5so -b 66 -r 2048 -c 6
"""

from argparse import ArgumentParser
import multiprocessing as MP
from random import randint
from secp256k1 import (
b58_decode as b58,
privatekey_to_h160 as p2h,
privatekey_loop_h160_sse as loop)
import sys
import time
from multiprocessing import Value, Process, Event, Array
import ctypes

parser = ArgumentParser(description='It splits the bit range and assigns a random number in each allocated range, searching backwards and forwards by -r.', epilog='')
parser.add_argument("-a", "--address", help = "P2PKH Address", required=True)
parser.add_argument("-b", "--bit", help = "Bit Range (20 - 256)", required=True)
parser.add_argument("-r", "--range", help = "The number or range of steps to search for in the fragmented bit range. | Default : 16384")
parser.add_argument("-c", "--cpu", help = "CPU Count | Default : 4")
if len(sys.argv)==1: parser.print_help(), sys.exit(1)
args = parser.parse_args()
address, bit, RANGE, cpu_count = args.address, int(args.bit), int(args.range) if args.range else 16384, int(args.cpu) if args.cpu else 4
_ = 2**(bit-1)
P = bytes.fromhex(b58(address)[2:-8])

def found(x):
for i in range(RANGE):
p, p = x + i, x - i
T = p2h(0, True, p) + p2h(0, True, p)
if P in T:
V = hex(_p)[2:] if p2h(0, True, p) == P else hex(p)
print('#'*30 + f'\nPrivate Key : {V}\n' + '#'*30)
open('found.txt', 'a').write('#'*30 + f'\nPrivate Key : {V}\n' + '#'*30 + '\n')
return True

last_key = Array('c', b'0' * 64)

def RUN(q, f, total_attempts, start_time, last_key):
while not q.is_set():
M = randint(16, 64)
B = _ // M
S = [_ + (B * i) for i in range(M + 1)]
R = randint(1, S[1] - S[0])

    for I in range(M):
        K = S[I] + R
        with last_key.get_lock():  # Son anahtar değerini güncelle
            last_key.value = hex(K)[2:].encode('utf-8')
        T = loop(RANGE, 0, True, K) + loop(RANGE, 0, True, K - RANGE)
        with total_attempts.get_lock():
            total_attempts.value += 2 * RANGE

        if P in T:
            found(K)
            f.set()
            return

if name == 'main':
q, f = Event(), Event()
total_attempts = Value(ctypes.c_ulonglong, 0)
start_time = Value(ctypes.c_double, time.time())

processes = []
for i in range(cpu_count):
    p = Process(target=RUN, args=(q, f, total_attempts, start_time, last_key))
    processes.append(p)
    p.start()

try:
    while not f.is_set():
        with total_attempts.get_lock():
            elapsed_time = time.time() - start_time.value
            scan_rate = total_attempts.value / elapsed_time if elapsed_time > 0 else 0
            print(f"\rTotal Time: {elapsed_time:.2f} s. Total Attempts: {total_attempts.value / 1_000_000:.2f} Mkeys. Attempts per Second: {scan_rate / 1_000_000:.2f} Mkeys/s. Last Key: {last_key.value.decode('utf-8')}", end='')
        time.sleep(1)
finally:
    q.set()
    for p in processes:
        p.join()

contractor error

when i tried to run the examples for ex:
from secp256k2 import Contactor

cont = Contactor()

privatekey = 12345678901234567891234567891234567789

ripemd160 = cont.privatekey_to_h160(privatekey)

i get this error:
ripemd160 = cont.privatekey_to_h160(privatekey)
^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'Contactor' object has no attribute 'privatekey_to_h160'

i get similar errors from the other examples.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.