Exemple #1
0
    def from_hex(hex_str):
        try:
            public_key = __PK__.deserialize(binascii.unhexlify(hex_str))

            return Secp256k1PublicKey(
                secp256k1.PublicKey(public_key, ctx=__CTX__))
        except Exception as e:
            raise ParseError('Unable to parse public key: {}'.format(e))
Exemple #2
0
 def from_wif(wif):
     """Decodes a PrivateKey from a wif-encoded string
     """
     try:
         priv = pybitcointools.encode_privkey(wif, 'hex')
         priv = binascii.unhexlify(priv)
         return Secp256k1PrivateKey(secp256k1.PrivateKey(priv, ctx=__CTX__))
     except Exception as e:
         raise ParseError('Unable to parse wif key: {}'.format(e))
Exemple #3
0
    def assertIsPublicKey(self, key):
        """Sanity checks a public key

        key -- hex string, bytes, or Secp256k1PublicKey
        returns -- Secp256k1PublicKey"""
        self.assertIsNotNone(key)
        if isinstance(key, Secp256k1PublicKey):
            return self.assertIsPublicKeySecp256k1(key)
        if isinstance(key, str):
            return self.assertIsPublicKeyHex(key)
        if isinstance(key, bytes):
            return self.assertIsPublicKeyBytes(key)

        raise ParseError("Unable to parse public key: {}".format(type(key)))
    def assertIsPrivateKey(self, key):
        """Sanity checks a private key

        key:      hex string, bytes, or Secp256k1PrivateKey
        returns:  Secp256k1PrivateKey"""
        self.assertIsNotNone(key)
        if isinstance(key, Secp256k1PrivateKey):
            return self.assertIsPrivateKeySecp256k1(key)
        elif isinstance(key, str):
            return self.assertIsPrivateKeyHex(key)
        elif isinstance(key, bytes):
            return self.assertIsPrivateKeyBytes(key)
        else:
            raise ParseError("Unable to parse private key: {}".format(
                type(key)))
Exemple #5
0
 def from_hex(hex_str):
     try:
         priv = binascii.unhexlify(hex_str)
         return Secp256k1PrivateKey(secp256k1.PrivateKey(priv, ctx=__CTX__))
     except Exception as e:
         raise ParseError('Unable to parse hex private key: {}'.format(e))
 def from_hex(hex_str):
     try:
         return Secp256k1PublicKey.from_bytes(binascii.unhexlify(hex_str))
     except Exception as e:
         raise ParseError('Unable to parse hex public key: {}'.format(e))