Compare commits
3 Commits
master
...
generalize
Author | SHA1 | Date | |
---|---|---|---|
![]() |
fd6dac2257 | ||
![]() |
b2a0c9d8be | ||
![]() |
078af45c92 |
@ -3,7 +3,7 @@
|
|||||||
{erl_opts, [debug_info]}.
|
{erl_opts, [debug_info]}.
|
||||||
|
|
||||||
{deps, [ {aebytecode, {git, "https://github.com/aeternity/aebytecode.git",
|
{deps, [ {aebytecode, {git, "https://github.com/aeternity/aebytecode.git",
|
||||||
{ref,"2d599df"}}}
|
{ref, "9041423"}}}
|
||||||
, {getopt, "1.0.1"}
|
, {getopt, "1.0.1"}
|
||||||
, {jsx, {git, "https://github.com/talentdeficit/jsx.git",
|
, {jsx, {git, "https://github.com/talentdeficit/jsx.git",
|
||||||
{tag, "2.8.0"}}}
|
{tag, "2.8.0"}}}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{"1.1.0",
|
{"1.1.0",
|
||||||
[{<<"aebytecode">>,
|
[{<<"aebytecode">>,
|
||||||
{git,"https://github.com/aeternity/aebytecode.git",
|
{git,"https://github.com/aeternity/aebytecode.git",
|
||||||
{ref,"2d599df0ea059df597a49e140e7100b0e8585cd9"}},
|
{ref,"9041423906247a7267a5a94530307b19c4490e8c"}},
|
||||||
0},
|
0},
|
||||||
{<<"aeserialization">>,
|
{<<"aeserialization">>,
|
||||||
{git,"https://github.com/aeternity/aeserialization.git",
|
{git,"https://github.com/aeternity/aeserialization.git",
|
||||||
|
@ -443,6 +443,11 @@ global_env() ->
|
|||||||
{"sha256", Fun1(A, Hash)},
|
{"sha256", Fun1(A, Hash)},
|
||||||
{"blake2b", Fun1(A, Hash)}]) },
|
{"blake2b", Fun1(A, Hash)}]) },
|
||||||
|
|
||||||
|
%% Authentication
|
||||||
|
AuthScope = #scope
|
||||||
|
{ funs = MkDefs(
|
||||||
|
[{"tx_hash", Option(Hash)}]) },
|
||||||
|
|
||||||
%% Strings
|
%% Strings
|
||||||
StringScope = #scope
|
StringScope = #scope
|
||||||
{ funs = MkDefs(
|
{ funs = MkDefs(
|
||||||
@ -477,6 +482,7 @@ global_env() ->
|
|||||||
, ["Oracle"] => OracleScope
|
, ["Oracle"] => OracleScope
|
||||||
, ["AENS"] => AENSScope
|
, ["AENS"] => AENSScope
|
||||||
, ["Map"] => MapScope
|
, ["Map"] => MapScope
|
||||||
|
, ["Auth"] => AuthScope
|
||||||
, ["Crypto"] => CryptoScope
|
, ["Crypto"] => CryptoScope
|
||||||
, ["String"] => StringScope
|
, ["String"] => StringScope
|
||||||
, ["Bits"] => BitsScope
|
, ["Bits"] => BitsScope
|
||||||
|
@ -182,6 +182,11 @@ ast_body(?id_app("abort", [String], _, _), Icode) ->
|
|||||||
#funcall{ function = #var_ref{ name = {builtin, abort} },
|
#funcall{ function = #var_ref{ name = {builtin, abort} },
|
||||||
args = [ast_body(String, Icode)] };
|
args = [ast_body(String, Icode)] };
|
||||||
|
|
||||||
|
%% Authentication
|
||||||
|
ast_body({qid, _, ["Auth", "tx_hash"]}, _Icode) ->
|
||||||
|
prim_call(?PRIM_CALL_AUTH_TX_HASH, #integer{value = 0},
|
||||||
|
[], [], aeso_icode:option_typerep(word));
|
||||||
|
|
||||||
%% Oracles
|
%% Oracles
|
||||||
ast_body(?qid_app(["Oracle", "register"], Args, _, ?oracle_t(QType, RType)), Icode) ->
|
ast_body(?qid_app(["Oracle", "register"], Args, _, ?oracle_t(QType, RType)), Icode) ->
|
||||||
{Sign, [Acct, QFee, TTL]} = get_signature_arg(Args),
|
{Sign, [Acct, QFee, TTL]} = get_signature_arg(Args),
|
||||||
|
@ -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