1
- use dep::protocol_types::constants:: {EMPTY_NULLIFIED_COMMITMENT , GENERATOR_INDEX__SIGNATURE_PAYLOAD };
2
- use dep::aztec:: {
3
- context ::{PrivateContext , PublicContext , Context },
4
- types::address::AztecAddress ,
5
- abi:: hash_args ,
6
- hash:: pedersen_hash ,
1
+ use dep::protocol_types:: {
2
+ abis::function_selector::FunctionSelector ,
3
+ address::AztecAddress ,
4
+ constants ::{
5
+ EMPTY_NULLIFIED_COMMITMENT ,
6
+ GENERATOR_INDEX__SIGNATURE_PAYLOAD ,
7
+ },
8
+ hash ::{
9
+ hash_args ,
10
+ pedersen_hash ,
11
+ },
12
+ };
13
+ use dep::aztec::context:: {
14
+ PrivateContext ,
15
+ PublicContext ,
16
+ Context ,
7
17
};
8
18
9
19
global IS_VALID_SELECTOR = 0xe86ab4ff ;
@@ -14,7 +24,8 @@ global IS_VALID_PUBLIC_SELECTOR = 0xf3661153;
14
24
// docs:start:assert_valid_authwit
15
25
// Assert that `on_behalf_of` have authorized `message_hash` with a valid authentication witness
16
26
pub fn assert_valid_authwit (context : &mut PrivateContext , on_behalf_of : AztecAddress , message_hash : Field ) {
17
- let result = context .call_private_function (on_behalf_of .address , IS_VALID_SELECTOR , [message_hash ])[0 ];
27
+ let is_valid_selector = FunctionSelector ::from_field (IS_VALID_SELECTOR );
28
+ let result = context .call_private_function (on_behalf_of , is_valid_selector , [message_hash ])[0 ];
18
29
context .push_new_nullifier (message_hash , EMPTY_NULLIFIED_COMMITMENT );
19
30
assert (result == IS_VALID_SELECTOR , "Message not authorized by account" );
20
31
}
@@ -24,7 +35,7 @@ pub fn assert_valid_authwit(context: &mut PrivateContext, on_behalf_of: AztecAdd
24
35
// Assert that `on_behalf_of` have authorized the current call with a valid authentication witness
25
36
pub fn assert_current_call_valid_authwit (context : &mut PrivateContext , on_behalf_of : AztecAddress ) {
26
37
// message_hash = H(caller, contract_this, selector, args_hash)
27
- let message_hash = pedersen_hash ([context .msg_sender (), context .this_address (), context .selector (), context .args_hash ],
38
+ let message_hash = pedersen_hash ([context .msg_sender (). to_field () , context .this_address (). to_field () , context .selector (). to_field (), context .args_hash ],
28
39
GENERATOR_INDEX__SIGNATURE_PAYLOAD );
29
40
assert_valid_authwit (context , on_behalf_of , message_hash );
30
41
}
@@ -33,7 +44,8 @@ pub fn assert_current_call_valid_authwit(context: &mut PrivateContext, on_behalf
33
44
// docs:start:assert_valid_authwit_public
34
45
// Assert that `on_behalf_of` have authorized `message_hash` in a public context
35
46
pub fn assert_valid_authwit_public (context : &mut PublicContext , on_behalf_of : AztecAddress , message_hash : Field ) {
36
- let result = context .call_public_function (on_behalf_of .address , IS_VALID_PUBLIC_SELECTOR , [message_hash ])[0 ];
47
+ let is_valid_public_selector = FunctionSelector ::from_field (IS_VALID_PUBLIC_SELECTOR );
48
+ let result = context .call_public_function (on_behalf_of , is_valid_public_selector , [message_hash ])[0 ];
37
49
context .push_new_nullifier (message_hash , EMPTY_NULLIFIED_COMMITMENT );
38
50
assert (result == IS_VALID_SELECTOR , "Message not authorized by account" );
39
51
}
@@ -43,17 +55,17 @@ pub fn assert_valid_authwit_public(context: &mut PublicContext, on_behalf_of: Az
43
55
// Assert that `on_behalf_of` have authorized the current call in a public context
44
56
pub fn assert_current_call_valid_authwit_public (context : &mut PublicContext , on_behalf_of : AztecAddress ) {
45
57
// message_hash = H(caller, contract_this, selector, args_hash)
46
- let message_hash = pedersen_hash ([context .msg_sender (), context .this_address (), context .selector (), context .args_hash ],
58
+ let message_hash = pedersen_hash ([context .msg_sender (). to_field () , context .this_address (). to_field () , context .selector (). to_field (), context .args_hash ],
47
59
GENERATOR_INDEX__SIGNATURE_PAYLOAD );
48
60
assert_valid_authwit_public (context , on_behalf_of , message_hash );
49
61
}
50
62
// docs:end:assert_current_call_valid_authwit_public
51
63
52
64
// docs:start:compute_authwit_message_hash
53
65
// Compute the message hash to be used by an authentication witness
54
- pub fn compute_authwit_message_hash <N >(caller : AztecAddress , target : AztecAddress , selector : Field , args : [Field ; N ]) -> Field {
66
+ pub fn compute_authwit_message_hash <N >(caller : AztecAddress , target : AztecAddress , selector : FunctionSelector , args : [Field ; N ]) -> Field {
55
67
let args_hash = hash_args (args );
56
- pedersen_hash ([caller .address , target .address , selector , args_hash ],
68
+ pedersen_hash ([caller .to_field () , target .to_field () , selector . to_field () , args_hash ],
57
69
GENERATOR_INDEX__SIGNATURE_PAYLOAD )
58
70
}
59
71
// docs :end :compute_authwit_message_hash
0 commit comments