import hashlib


def derive_seed(privkey, other_pubkey, offer_info):
    """ Derive personal seed from a given offer info, counterparty
    pubkey, and own messaging key. This will be used to construct
    per-swap private keys and secrets."""
    mykey = privkey.to_bytes(32,'big')
    obytes = offer_info.to_bytes()
    h = hashlib.sha512()
    h.update(b'OpenSwapDeriveSwapSeed')
    h.update(mykey)
    h.update(other_pubkey)
    h.update(len(obytes).to_bytes(4,'big'))
    h.update(obytes)
    h.update(mykey)
    return h.digest()