Browse Source

add PublicKey.combine_keys

tb
ofek 7 years ago
parent
commit
08926046dd
  1. 9
      README.rst
  2. 14
      coincurve/keys.py

9
README.rst

@ -182,6 +182,15 @@ coincurve.PublicKey
*classmethod* ``from_signature_and_message(serialized_sig, message, hasher=sha256, context=GLOBAL_CONTEXT)``
*classmethod* ``combine_keys(public_keys, context=GLOBAL_CONTEXT)``
* Parameters:
- **public_keys** (``list``) - A ``list`` of ``coincurve.PublicKey`` to add.
- **context** (``coincurve.Context``)
* Returns: ``coincurve.PublicKey``
``format(compressed=True)``
* Parameters:

14
coincurve/keys.py

@ -243,6 +243,20 @@ class PublicKey:
context=context
))
@classmethod
def combine_keys(cls, public_keys, context=GLOBAL_CONTEXT):
public_key = ffi.new('secp256k1_pubkey *')
combined = lib.secp256k1_ec_pubkey_combine(
context.ctx, public_key, [pk.public_key for pk in public_keys],
len(public_keys)
)
if not combined:
raise ValueError('The sum of the public keys is invalid.')
return PublicKey(public_key, context)
def format(self, compressed=True):
length = 33 if compressed else 65
serialized = ffi.new('unsigned char [%d]' % length)

Loading…
Cancel
Save