Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
cryptocurrency-wallet-genrator
  • Loading branch information
PastorOmbura authored May 25, 2018
1 parent 0db223d commit db890e1
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 0 deletions.
10 changes: 10 additions & 0 deletions PKG-INFO
Original file line number Diff line number Diff line change
@@ -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: [email protected]
License: Creative Commons Attribution-Noncommercial-Share Alike license
Description: UNKNOWN
Platform: any
16 changes: 16 additions & 0 deletions SOURCES.txt
Original file line number Diff line number Diff line change
@@ -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
109 changes: 109 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -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),
)
35 changes: 35 additions & 0 deletions base58.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions requires.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ecdsa==0.13
ethereum==2.1.0
salemcash==0.1.0
4 changes: 4 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[egg_info]
tag_build =
tag_date = 0

20 changes: 20 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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='[email protected]',
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'
],
)
1 change: 1 addition & 0 deletions top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cryptocurrency_wallet_generator

0 comments on commit db890e1

Please sign in to comment.