def test_sign_and_verify(self): data = hex_to_bytes(concat(['ab' for _ in range(32)])) secret_key = WitPrivateKey.from_hex(concat(['cd' for _ in range(32)])) public_key = secret_key.to_public() local_signature = secret_key.sign_hash(data) expected_signature = '3044' \ '0220' \ '3dc4fa74655c21b7ffc0740e29bfd88647e8dfe2b68c507cf96264e4e7439c1f' \ '0220' \ '7aa61261b18eebdfdb704ca7bab4c7bcf7961ae0ade5309f6f1398e21aec0f9f' recovered_signature = Signature.from_hex(expected_signature) assert local_signature.verify_hash(data, public_key) assert recovered_signature.verify_hash(data, public_key)
def from_seed(cls, seed: Union[bytes, str], network_key=b'Bitcoin seed') -> 'Xprv': """ :param seed: :param network_key: :return: """ if isinstance(seed, str): seed = hex_to_bytes(seed) assert 16 <= len(seed) <= 64, 'Seed should be between 128 and 512 bits' I = hmac.new(key=network_key, msg=seed, digestmod=hashlib.sha512).digest() I_L, I_R = I[:32], I[32:] if bytes_to_int(I_L) == 0 or bytes_to_int(I_L) > CURVE.order: raise KeyDerivationError key, code = WitPrivateKey(I_L), I_R # print(f'\tMaster Secret Key: {bytes_to_hex(I_L)}') # print(f'\tMaster Chain Code: {bytes_to_hex(I_R)}') return cls(key, code)
def from_hex(cls, h): return cls(hex_to_bytes(h))
def from_string(cls, data: str): return Hash(SHA256=hex_to_bytes(data))
def from_hex(cls, hex_string): return cls.decode(hex_to_bytes(hex_string))
def from_hex(cls, hexstring: str) -> 'WitPublicKey': return cls.decode(hex_to_bytes(hexstring))