Test Auth.tx_hash compilation
This commit is contained in:
parent
db64978d2e
commit
d6a55e144e
@ -97,7 +97,8 @@ compilable_contracts() ->
|
|||||||
"variant_types",
|
"variant_types",
|
||||||
"state_handling",
|
"state_handling",
|
||||||
"events",
|
"events",
|
||||||
"include"
|
"include",
|
||||||
|
"basic_auth"
|
||||||
].
|
].
|
||||||
|
|
||||||
%% Contracts that should produce type errors
|
%% Contracts that should produce type errors
|
||||||
|
19
test/contracts/basic_auth.aes
Normal file
19
test/contracts/basic_auth.aes
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// Contract replicating "normal" Aeternity authentication
|
||||||
|
contract BasicAuth =
|
||||||
|
record state = { nonce : int, owner : address }
|
||||||
|
|
||||||
|
function init() = { nonce = 1, owner = Call.caller }
|
||||||
|
|
||||||
|
function 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(to_sign(tx_hash, n), state.owner, s)
|
||||||
|
|
||||||
|
function to_sign(h : hash, n : int) =
|
||||||
|
Crypto.blake2b((h, n))
|
||||||
|
|
||||||
|
private function require(b : bool, err : string) =
|
||||||
|
if(!b) abort(err)
|
Loading…
x
Reference in New Issue
Block a user