From db890e1f97646feb7a33810fa7e82ea62fa12a27 Mon Sep 17 00:00:00 2001 From: Pastor Ombura <36679951+PastorOmbura@users.noreply.github.com> Date: Sat, 26 May 2018 01:36:56 +0300 Subject: [PATCH] Add files via upload cryptocurrency-wallet-genrator --- PKG-INFO | 10 +++++ SOURCES.txt | 16 ++++++++ __init__.py | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++ base58.py | 35 ++++++++++++++++ requires.txt | 3 ++ setup.cfg | 4 ++ setup.py | 20 +++++++++ top_level.txt | 1 + 8 files changed, 198 insertions(+) create mode 100644 PKG-INFO create mode 100644 SOURCES.txt create mode 100644 __init__.py create mode 100644 base58.py create mode 100644 requires.txt create mode 100644 setup.cfg create mode 100644 setup.py create mode 100644 top_level.txt diff --git a/PKG-INFO b/PKG-INFO new file mode 100644 index 0000000..8bbda87 --- /dev/null +++ b/PKG-INFO @@ -0,0 +1,10 @@ +Metadata-Version: 1.0 +Name: cryptocurrency-wallet-generator +Version: 0.0.7 +Summary: Simple Python package that can generate wallets for several cryptocurrencies +Home-page: https://github.com/aruseni/python-cryptocurrency-wallet-generator +Author: aruseni +Author-email: aruseni.magiku@gmail.com +License: Creative Commons Attribution-Noncommercial-Share Alike license +Description: UNKNOWN +Platform: any diff --git a/SOURCES.txt b/SOURCES.txt new file mode 100644 index 0000000..32e65a5 --- /dev/null +++ b/SOURCES.txt @@ -0,0 +1,16 @@ +setup.py +cryptocurrency_wallet_generator/__init__.py +cryptocurrency_wallet_generator.egg-info/PKG-INFO +cryptocurrency_wallet_generator.egg-info/SOURCES.txt +cryptocurrency_wallet_generator.egg-info/dependency_links.txt +cryptocurrency_wallet_generator.egg-info/not-zip-safe +cryptocurrency_wallet_generator.egg-info/requires.txt +cryptocurrency_wallet_generator.egg-info/top_level.txt +cryptocurrency_wallet_generator/currencies/__init__.py +cryptocurrency_wallet_generator/currencies/bitcoin/__init__.py +cryptocurrency_wallet_generator/currencies/bitcoin/base58.py +cryptocurrency_wallet_generator/currencies/bitcoincash/__init__.py +cryptocurrency_wallet_generator/currencies/dash/__init__.py +cryptocurrency_wallet_generator/currencies/ethereum/__init__.py +cryptocurrency_wallet_generator/currencies/litecoin/__init__.py +cryptocurrency_wallet_generator/currencies/salemcash/__init__.py \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..3a8fbea --- /dev/null +++ b/__init__.py @@ -0,0 +1,109 @@ +import ctypes +import ctypes.util +import hashlib + +from .base58 import encode as base58_encode + + +class Salemcash: + ssl_library = ctypes.cdll.LoadLibrary(ctypes.util.find_library("ssl")) + + # Since "1" is a zero byte, it won’t be present in the output address. + addr_prefix = "1" + + version = 0 + + def gen_ecdsa_pair(self): + NID_secp160k1 = 708 + NID_secp256k1 = 714 + k = self.ssl_library.EC_KEY_new_by_curve_name(NID_secp256k1) + + if self.ssl_library.EC_KEY_generate_key(k) != 1: + raise Exception("internal error?") + + bignum_private_key = self.ssl_library.EC_KEY_get0_private_key(k) + size = (self.ssl_library.BN_num_bits(bignum_private_key)+7)//8 + storage = ctypes.create_string_buffer(size) + self.ssl_library.BN_bn2bin(bignum_private_key, storage) + private_key = storage.raw + + size = self.ssl_library.i2o_ECPublicKey(k, 0) + storage = ctypes.create_string_buffer(size) + self.ssl_library.i2o_ECPublicKey( + k, + ctypes.byref(ctypes.pointer(storage)) + ) + public_key = storage.raw + + self.ssl_library.EC_KEY_free(k) + return public_key, private_key + + def ecdsa_get_coordinates(self, public_key): + x = bytes(public_key[1:33]) + y = bytes(public_key[33:65]) + return x, y + + def generate_address(self, public_key): + assert isinstance(public_key, bytes) + + x, y = self.ecdsa_get_coordinates(public_key) + + s = b"\x04" + x + y + + hasher = hashlib.sha256() + hasher.update(s) + r = hasher.digest() + + hasher = hashlib.new("ripemd160") + hasher.update(r) + r = hasher.digest() + + addr = self.base58_check(r, version=self.version) + if self.addr_prefix: + return "{}{}".format(self.addr_prefix, addr) + else: + return addr + + def base58_check(self, src, version): + src = bytes([version]) + src + hasher = hashlib.sha256() + hasher.update(src) + r = hasher.digest() + + hasher = hashlib.sha256() + hasher.update(r) + r = hasher.digest() + + checksum = r[:4] + s = src + checksum + + return base58_encode(int.from_bytes(s, "big")) + + def test(self): + public_key, private_key = self.gen_ecdsa_pair() + + hex_private_key = "".join(["{:02x}".format(i) for i in private_key]) + assert len(hex_private_key) == 64 + + print( + "ECDSA private key (random number / secret exponent) = {}".format( + hex_private_key + ) + ) + print("ECDSA public key = {}".format( + "".join(["{:02x}".format(i) for i in public_key]) + )) + print("Private key (Base58Check) = {}".format( + self.base58_check(private_key, version=128+self.version) + )) + + addr = self.generate_address(public_key) + print("Address: {} (length={})".format(addr, len(addr))) + + def generate_wallet(self): + public_key, private_key = self.gen_ecdsa_pair() + + return( + self.base58_check(private_key, version=128+self.version), + self.generate_address(public_key), + ) diff --git a/base58.py b/base58.py new file mode 100644 index 0000000..515feea --- /dev/null +++ b/base58.py @@ -0,0 +1,35 @@ +""" base58 encoding / decoding functions """ + + +alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' +base_count = len(alphabet) + + +def encode(num): + """ Returns num in a base58-encoded string """ + encode = '' + + if (num < 0): + return '' + + while (num >= base_count): + mod = num % base_count + encode = alphabet[mod] + encode + num = num // base_count + + if (num): + encode = alphabet[num] + encode + + return encode + + +def decode(s): + """ Decodes the base58-encoded string s into an integer """ + decoded = 0 + multi = 1 + s = s[::-1] + for char in s: + decoded += multi * alphabet.index(char) + multi = multi * base_count + + return decoded diff --git a/requires.txt b/requires.txt new file mode 100644 index 0000000..5d46730 --- /dev/null +++ b/requires.txt @@ -0,0 +1,3 @@ +ecdsa==0.13 +ethereum==2.1.0 +salemcash==0.1.0 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..8bfd5a1 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,4 @@ +[egg_info] +tag_build = +tag_date = 0 + diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..33b710f --- /dev/null +++ b/setup.py @@ -0,0 +1,20 @@ +from setuptools import setup, find_packages + +setup( + name='cryptocurrency-wallet-generator', + packages=find_packages(), + version='0.0.7', + url='https://github.com/aruseni/python-cryptocurrency-wallet-generator', + author='aruseni', + author_email='aruseni.magiku@gmail.com', + description='Simple Python package that can generate wallets for several cryptocurrencies', + zip_safe=False, + include_package_data=True, + platforms='any', + license='Creative Commons Attribution-Noncommercial-Share Alike license', + install_requires=[ + 'ecdsa==0.13', + 'ethereum==2.1.0' + 'salemcash==0.1.0' + ], +) diff --git a/top_level.txt b/top_level.txt new file mode 100644 index 0000000..0223675 --- /dev/null +++ b/top_level.txt @@ -0,0 +1 @@ +cryptocurrency_wallet_generator