Browse Source

more docs

tb
ofek 7 years ago
parent
commit
6a1a3724ce
  1. 88
      README.rst
  2. 17
      coincurve/keys.py

88
README.rst

@ -60,18 +60,24 @@ All instances have a ``public_key`` of type ``coincurve.PublicKey``
* Parameters:
- **secret** (``bytes``) - The secret to use.
- **context** (``coincurve.Context``)
- **secret** (``bytes``) - The secret to use.
- **context** (``coincurve.Context``)
Methods
~~~~~~~
*classmethod* ``from_int(num, context=GLOBAL_CONTEXT)``
*classmethod* ``from_pem(pem, context=GLOBAL_CONTEXT)``
*classmethod* ``from_der(der, context=GLOBAL_CONTEXT)``
``sign(message, hasher=sha256)``
* Parameters:
- **message** (``bytes``) - The message to sign.
- **hasher** - The hash function to use. hasher(message) must return 32 bytes.
- **message** (``bytes``) - The message to sign.
- **hasher** - The hash function to use. hasher(message) must return 32 bytes.
* Returns: ``bytes``. 71 <= len(signature) <= 72
@ -79,8 +85,8 @@ Methods
* Parameters:
- **message** (``bytes``) - The message to sign.
- **hasher** - The hash function to use. hasher(message) must return 32 bytes.
- **message** (``bytes``) - The message to sign.
- **hasher** - The hash function to use. hasher(message) must return 32 bytes.
* Returns: ``bytes``
@ -88,8 +94,8 @@ Methods
* Parameters:
- **scalar** (``bytes``) - The scalar to add.
- **update** - If ``True``, will update and return ``self``.
- **scalar** (``bytes``) - The scalar to add.
- **update** - If ``True``, will update and return ``self``.
* Returns: ``coincurve.PrivateKey``
@ -97,8 +103,8 @@ Methods
* Parameters:
- **scalar** (``bytes``) - The scalar to multiply.
- **update** - If ``True``, will update and return ``self``.
- **scalar** (``bytes``) - The scalar to multiply.
- **update** - If ``True``, will update and return ``self``.
* Returns: ``coincurve.PrivateKey``
@ -108,11 +114,67 @@ Methods
``to_der()``
*classmethod* ``from_int(num, context=GLOBAL_CONTEXT)``
coincurve.PublicKey
^^^^^^^^^^^^^^^^^^^
``PublicKey(data, context=GLOBAL_CONTEXT)``
* Parameters:
- **data** (``bytes``) - The public key in compressed or uncompressed form.
- **context** (``coincurve.Context``)
*classmethod* ``from_secret(secret, context=GLOBAL_CONTEXT)``
*classmethod* ``from_valid_secret(secret, context=GLOBAL_CONTEXT)``
*classmethod* ``from_point(x, y, context=GLOBAL_CONTEXT)``
``format(compressed=True)``
* Parameters:
- **compressed** (``bool``)
* Returns: The public key serialized to ``bytes``.
``point()``
* Returns: (x, y)
``verify(signature, message, hasher=sha256)``
Verifies some message was signed by the owner of this public key.
* Parameters:
- **signature** (``bytes``) - The signature to verify.
- **message** (``bytes``) - The message that was supposedly signed.
- **hasher** - The hash function to use. hasher(message) must return 32 bytes.
* Returns: The public key serialized to ``bytes``.
``add(scalar, update=False)``
* Parameters:
- **scalar** (``bytes``) - The scalar to add.
- **update** - If ``True``, will update and return ``self``.
* Returns: ``coincurve.PublicKey``
``multiply(scalar, update=False)``
* Parameters:
- **scalar** (``bytes``) - The scalar to multiply.
- **update** - If ``True``, will update and return ``self``.
* Returns: ``coincurve.PublicKey``
*classmethod* ``from_pem(pem, context=GLOBAL_CONTEXT)``
*classmethod* ``from_der(der, context=GLOBAL_CONTEXT)``

17
coincurve/keys.py

@ -59,10 +59,6 @@ class PrivateKey:
return recoverable_to_der(signature, self.context)
def add(self, scalar, update=False):
"""
Tweak the current private key by adding a 32 byte scalar
to it and return a new raw private key composed of 32 bytes.
"""
scalar = pad_scalar(scalar)
secret = ffi.new('unsigned char [32]', self.secret)
@ -85,10 +81,6 @@ class PrivateKey:
return PrivateKey(secret, self.context)
def multiply(self, scalar, update=False):
"""
Tweak the current private key by multiplying it by a 32 byte scalar
and return a new raw private key composed of 32 bytes.
"""
scalar = validate_secret(scalar)
secret = ffi.new('unsigned char [32]', self.secret)
@ -263,10 +255,6 @@ class PublicKey:
return bytes(ffi.buffer(secret, 32))
def add(self, scalar, update=False):
"""
Tweak the current public key by adding a 32 byte scalar times
the generator to it and return a new PublicKey instance.
"""
scalar = pad_scalar(scalar)
new_key = ffi.new('secp256k1_pubkey *', self.public_key[0])
@ -286,10 +274,6 @@ class PublicKey:
return PublicKey(new_key, self.context)
def multiply(self, scalar, update=False):
"""
Tweak the current public key by multiplying it by a 32 byte scalar
and return a new PublicKey instance.
"""
scalar = validate_secret(scalar)
new_key = ffi.new('secp256k1_pubkey *', self.public_key[0])
@ -305,7 +289,6 @@ class PublicKey:
return PublicKey(new_key, self.context)
def combine(self, public_keys, update=False):
"""Add a number of public keys together."""
new_key = ffi.new('secp256k1_pubkey *')
combined = lib.secp256k1_ec_pubkey_combine(

Loading…
Cancel
Save