Ejemplo n.º 1
0
 def __init__(self,
              public_key: VerifyingKey,
              chain_code,
              index,
              depth,
              parent_fingerprint=b'\x00\x00\x00\x00'):
     super().__init__(public_key, chain_code, index, depth,
                      parent_fingerprint)
     x_str = util.number_to_string(self._key.pubkey.point.x(),
                                   self._key.pubkey.order)
     if self._key.pubkey.point.y() % 2 == 0:
         self._compressed_key = util.b('\x02') + x_str
     else:
         self._compressed_key = util.b('\x03') + x_str
Ejemplo n.º 2
0
 def ec_get_pubkey_by_prikey(privateKey: bytes, curveName):
     if curveName == Curve.P256:
         private_key = SigningKey.from_string(string=(privateKey), curve=NIST256p)
         # public_key = private_key.get_verifying_key().to_string()
         verifying_key = private_key.get_verifying_key()
         order = verifying_key.pubkey.order
         x_str = util.number_to_string(verifying_key.pubkey.point.x(), order)
         y_str = util.number_to_string(verifying_key.pubkey.point.y(), order)
         point_str = util.b("\x04") + x_str + y_str
         if verifying_key.pubkey.point.y() % 2 == 0:
             point_str = util.b("\x02") + x_str
         else:
             point_str = util.b("\x03") + x_str
     else:
         raise TypeError
     return point_str
 def ec_get_pubkey_by_prikey(privateKey: bytes, curve_name):
     if curve_name == Curve.P256:
         private_key = SigningKey.from_string(string=(privateKey), curve=NIST256p)
         # public_key = private_key.get_verifying_key().to_string()
         verifying_key = private_key.get_verifying_key()
         order = verifying_key.pubkey.order
         x_str = util.number_to_string(verifying_key.pubkey.point.x(), order)
         # TODO: add verify
         # y_str = util.number_to_string(verifying_key.pubkey.point.y(), order)
         # point_str = util.b("\x04") + x_str + y_str
         if verifying_key.pubkey.point.y() % 2 == 0:
             point_str = util.b("\x02") + x_str
         else:
             point_str = util.b("\x03") + x_str
     elif curve_name == Curve.P224:
         raise SDKException(ErrorCode.unsupported_key_type)
     elif curve_name == Curve.P384:
         raise SDKException(ErrorCode.unsupported_key_type)
     elif curve_name == Curve.P521:
         raise SDKException(ErrorCode.unsupported_key_type)
     else:
         raise SDKException(ErrorCode.unknown_key_type)
     return point_str
Ejemplo n.º 4
0
 def ec_get_public_key_by_private_key(private_key: bytes,
                                      curve_name) -> bytes:
     if curve_name == Curve.P256:
         private_key = SigningKey.from_string(string=private_key,
                                              curve=curves.NIST256p)
         verifying_key = private_key.get_verifying_key()
         order = verifying_key.pubkey.order
         x_int = verifying_key.pubkey.point.x()
         y_int = verifying_key.pubkey.point.y()
         x_str = util.number_to_string(x_int, order)
         if y_int % 2 == 0:
             point_str = util.b('\x02') + x_str
         else:
             point_str = util.b('\x03') + x_str
     elif curve_name == Curve.P224:
         raise SDKException(ErrorCode.unsupported_key_type)
     elif curve_name == Curve.P384:
         raise SDKException(ErrorCode.unsupported_key_type)
     elif curve_name == Curve.P521:
         raise SDKException(ErrorCode.unsupported_key_type)
     else:
         raise SDKException(ErrorCode.unsupported_key_type)
     return point_str