Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Secret scalar must be greater than 0 and less than.. #2

Closed
hrishikeshio opened this issue Apr 17, 2017 · 1 comment
Closed

Secret scalar must be greater than 0 and less than.. #2

hrishikeshio opened this issue Apr 17, 2017 · 1 comment

Comments

@hrishikeshio
Copy link

hrishikeshio commented Apr 17, 2017

In [94]: pk
Out[94]: <coincurve.keys.PrivateKey instance at 0x109cc2998>

In [95]: privatekey_to_address(pk)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-95-a6cecae842d3> in <module>()
----> 1 privatekey_to_address(pk)

<ipython-input-91-3fca11b6c95d> in privatekey_to_address(private_key_bin)
    120 
    121 def privatekey_to_address(private_key_bin):
--> 122     private_key = PrivateKey(private_key_bin)
    123     pubkey = private_key.public_key.format(compressed=False)
    124     return publickey_to_address(pubkey)

/Users/hhuilgolkar/raid/lib/python2.7/site-packages/coincurve/keys.pyc in __init__(self, secret, context)
     20 class PrivateKey:
     21     def __init__(self, secret=None, context=GLOBAL_CONTEXT):
---> 22         self.secret = (validate_secret(secret) if secret is not None
     23                        else get_valid_secret())
     24         self.context = context

/Users/hhuilgolkar/raid/lib/python2.7/site-packages/coincurve/utils.pyc in validate_secret(secret)
    105     if not ZERO < secret < GROUP_ORDER:
    106         raise ValueError('Secret scalar must be greater than 0 and less than '
--> 107                          '{}.'.format(GROUP_ORDER_INT))
    108     return pad_scalar(secret)
    109 

ValueError: Secret scalar must be greater than 0 and less than 115792089237316195423570985008687907852837564279074904382605163141518161494337.

In [100]: pk.to_int()
Out[100]: 72314643180786136016222690850571465731842288350546105134113403345693409491713L


@ofek
Copy link
Owner

ofek commented Apr 17, 2017

Coincurve does not have the same API as secp256k1-py. Therefore, your privatekey_to_address is ill-defined. Change it to:

def privatekey_to_address(private_key):
    pubkey = private_key.public_key.format(compressed=False)
    return publickey_to_address(pubkey)

@ofek ofek closed this as completed Apr 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants