sophia/test/contracts/bitcoin_auth.aes
2019-06-28 09:42:28 +02:00

17 lines
580 B
Plaintext

contract BitcoinAuth =
record state = { nonce : int, owner : bytes(64) }
entrypoint init(owner' : bytes(64)) = { nonce = 1, owner = owner' }
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.ecverify_secp256k1(to_sign(tx_hash, n), state.owner, s)
entrypoint to_sign(h : hash, n : int) : hash =
Crypto.blake2b((h, n))