I tried to get a private view key but somehow I can't get it to work. However, I do manage to get the hash of the seed from the hexadecimal seed created from the mnemonic.

The hexadecimal seed was obtained from here for testing. I seem to manage to get the correct hash of th seed by keccak_256 hexadecimal seed.

I read many sites state that private view keys can be obtained by sc_reduce32 the hash of seed. But I don't get it working.

Here is my code; it runs in Python 2.7.

Can someone show me how to get the private view key from the hash of the seed?

If possible I prefer the method to work in Python 2.7 since most of my previous work was done in that Python version.

1 Answer 1


Your sc_reduce32 function was using the wrong value to reduce by, and you had not reversed the endianness of your bytes. Here is working code:

import sha3

l = 2 ** 252 + 27742317777372353535851937790883648493

def reverse_byte_order(hex):
    if(len(hex)%2==1): hex = '0' + hex
    return "".join(reversed([hex[i:i+2] for i in range(0, len(hex), 2)]))

def sc_reduce32(key):
    return reverse_byte_order("%x" % int((int(reverse_byte_order(key), 16) % l)))

def cn_fast_hash(hex):
    k = sha3.keccak_256()
    return k.hexdigest()

hexadecimal_seed = "852249bca4446e65501cc7f8338027ec"
hash_of_seed = cn_fast_hash(hexadecimal_seed)
private_spend_key = sc_reduce32(hash_of_seed)
private_view_key = sc_reduce32(cn_fast_hash(hash_of_seed))

print "Non-standard Seed = ", hexadecimal_seed
print "Normalized Seed   = ", hash_of_seed
print "Private Spend Key = ", private_spend_key
print "Private View Key  = ", private_view_key
  • Thank you. I have completed the python code that will generate public address by giving seed of mymonero. Here is the final code link in case the community need it. The code will work Python 2.7. Jul 3, 2018 at 18:42
  • @ChoonBoonKhoo Thanks for sharing your link. Please could you also share your base58 encoder, for completeness?
    – knaccc
    Jul 3, 2018 at 19:22
  • 1
    The base58 code was obtained from here link. Should be open-source and I don't own the code. Jul 4, 2018 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.