import hashlib


def deterministic_key(wallet_seed, index):
    """
    Return the 32-byte seed to feed to ed25519 keypair generation for
    the given key index
    """
    assert isinstance(wallet_seed, bytes)
    assert len(wallet_seed) == 32
    assert isinstance(index, int)
    
    hash = hashlib.blake2b(digest_size=32)
    hash.update(wallet_seed)
    index = int.to_bytes(index, 4, byteorder='big')
    hash.update(index)
    seed = hash.digest()
    
    return seed