vkobel / ethereum-generate-wallet

Scripts collection to generate ECDSA keypairs and derive their Ethereum address
https://kobl.one/blog/create-full-ethereum-keypair-and-address/
MIT License
267 stars 115 forks source link

REST API : Return Address and Private Key #16

Closed cullsin closed 6 years ago

cullsin commented 6 years ago

Thanks for the reference. I am trying to generate the address and the private key through a REST API Call using your code. But the address is showing the same as the input. can you please review my code. is that correct?

from ecdsa import SigningKey, SECP256k1 import sha3

PRIVATE_KEY = 'private_key' PUBLIC_KEY = 'public_key' ADDRESS = 'address'

def generate_user_burn_address(request_args):
    addr_str = request_args['addr_str'];
    keccak = sha3.keccak_256()
    out = ''
    addr = addr_str.lower().replace('0x', '')
    keccak.update(addr.encode('ascii'))
    hash_addr = keccak.hexdigest()
    for i, c in enumerate(addr):
        if int(hash_addr[i], 16) >= 8:
            out += c.upper()
        else:
            out += c
    address = '0x' + out
    priv = SigningKey.generate(curve=SECP256k1)
    pub = priv.get_verifying_key().to_string()
    private_key = priv.to_string().hex()
    public_key = pub.hex()
    return {PRIVATE_KEY: private_key, ADDRESS: address}

Thanks, Raja K

vkobel commented 6 years ago

This isn't an issue

vkobel commented 6 years ago

this is expected, the address returned by the checksum function is the same, it will just change an address' case to match what has been defined in EIP55