Esempio n. 1
0
 def __init__(self, pubkey=None, raw=False, flags=FLAG_VERIFY, ctx=None):
     Base.__init__(self, ctx, flags)
     if pubkey is not None:
         if raw:
             if not isinstance(pubkey, bytes):
                 raise TypeError('raw pubkey must be bytes')
             self.public_key = self.deserialize(pubkey)
         else:
             if not isinstance(pubkey, ffi.CData):
                 raise TypeError('pubkey must be an internal object')
             assert ffi.typeof(pubkey) is ffi.typeof('secp256k1_pubkey *')
             self.public_key = pubkey
     else:
         self.public_key = None
Esempio n. 2
0
    def combine(self, pubkeys):
        """Add a number of public keys together."""
        assert len(pubkeys) > 0

        outpub = ffi.new('secp256k1_pubkey *')
        for item in pubkeys:
            assert ffi.typeof(item) is ffi.typeof('secp256k1_pubkey *')

        res = lib.secp256k1_ec_pubkey_combine(
            self.ctx, outpub, pubkeys, len(pubkeys))
        if not res:
            raise Exception('failed to combine public keys')

        self.public_key = outpub
        return outpub