def from_int(cls, num): """ :param num: A private key in raw integer form. :type num: ``int`` :rtype: :class:`~bit.PrivateKeyTestnet` """ return PrivateKeyTestnet(derive_private_key(num))
def from_hex(cls, hexed): """ :param hexed: A private key previously encoded as hex. :type hexed: ``str`` :rtype: :class:`~bit.PrivateKeyTestnet` """ return PrivateKeyTestnet(derive_private_key(hex_to_int(hexed)))
def __init__(self, wif=None): if wif: if isinstance(wif, str): private_key_hex, compressed, version = wif_to_hex(wif) self._pk = derive_private_key(hex_to_int(private_key_hex)) elif isinstance(wif, EllipticCurvePrivateKey): self._pk = wif compressed = True else: raise TypeError('Wallet Import Format must be a string.') else: self._pk = generate_private_key() compressed = True self._public_point = None self._public_key = point_to_public_key( self._pk.public_key().public_numbers(), compressed=compressed)
def __init__(self, wif=None): if wif: if isinstance(wif, str): private_key_int, compressed, version = wif_to_int(wif) self._pk = derive_private_key(private_key_int) elif isinstance(wif, EllipticCurvePrivateKey): self._pk = wif compressed = True else: raise TypeError('Wallet Import Format must be a string.') else: self._pk = generate_private_key() compressed = True self._public_point = None self._public_key = coords_to_public_key(*get_ec_point(self._pk), compressed=compressed)
def test_derive_private_key(): private_key = derive_private_key(PRIVATE_KEY_NUM) public_point = private_key.public_key().public_numbers() assert public_point.x == PUBLIC_KEY_X assert public_point.y == PUBLIC_KEY_Y