// Contract replicating "normal" Aeternity authentication
contract BasicAuth =
  record state = { nonce : int, owner : address }

  entrypoint init() = { nonce = 1, owner = Call.caller }

  stateful entrypoint authorize(n : int, s : signature) : bool =
    require(n >= state.nonce, "Nonce too low")
    require(n =< state.nonce, "Nonce too high")
    put(state{ nonce = n + 1 })
    switch(Auth.tx_hash)
      None          => abort("Not in Auth context")
      Some(tx_hash) => Crypto.verify_sig(to_sign(tx_hash, n), state.owner, s)

  entrypoint to_sign(h : hash, n : int) =
    Crypto.blake2b((h, n))

  entrypoint weird_string() : string =
    "\x19Weird String\x42\nMore\n"
