|
| 1 | +use crate::context::calls::{PublicCall, PublicStaticCall}; |
| 2 | +use crate::protocol::{abis::function_selector::FunctionSelector, address::AztecAddress, traits::ToField}; |
| 3 | + |
| 4 | +/// Hand-written interface stub for the `AuthRegistry` canonical contract. |
| 5 | +/// |
| 6 | +/// The `AuthRegistry` contract records public authentication witnesses |
| 7 | +/// (`set_authorized`, `set_reject_all`) and atomically consumes them at |
| 8 | +/// the consumer (`consume`). Consumer code in aztec-nr's `authwit::public` |
| 9 | +/// module calls into the registry via this interface. |
| 10 | +/// |
| 11 | +/// The selectors are derived with `comptime { FunctionSelector::from_signature(...) }`, |
| 12 | +/// which matches exactly what the `#[aztec]` macro generates for the real contract. |
| 13 | +pub struct AuthRegistryInterface { |
| 14 | + pub target_contract: AztecAddress, |
| 15 | +} |
| 16 | + |
| 17 | +impl AuthRegistryInterface { |
| 18 | + pub fn at(target_contract: AztecAddress) -> Self { |
| 19 | + Self { target_contract } |
| 20 | + } |
| 21 | + |
| 22 | + pub fn _set_authorized( |
| 23 | + self, |
| 24 | + approver: AztecAddress, |
| 25 | + message_hash: Field, |
| 26 | + authorize: bool, |
| 27 | + ) -> PublicCall<15, 3, ()> { |
| 28 | + let selector = comptime { FunctionSelector::from_signature("_set_authorized((Field),Field,bool)") }; |
| 29 | + PublicCall::new( |
| 30 | + self.target_contract, |
| 31 | + selector, |
| 32 | + "_set_authorized", |
| 33 | + [approver.to_field(), message_hash, authorize as Field], |
| 34 | + ) |
| 35 | + } |
| 36 | + |
| 37 | + pub fn consume(self, on_behalf_of: AztecAddress, inner_hash: Field) -> PublicCall<7, 2, Field> { |
| 38 | + let selector = comptime { FunctionSelector::from_signature("consume((Field),Field)") }; |
| 39 | + PublicCall::new( |
| 40 | + self.target_contract, |
| 41 | + selector, |
| 42 | + "consume", |
| 43 | + [on_behalf_of.to_field(), inner_hash], |
| 44 | + ) |
| 45 | + } |
| 46 | + |
| 47 | + pub fn is_consumable(self, on_behalf_of: AztecAddress, message_hash: Field) -> PublicStaticCall<13, 2, bool> { |
| 48 | + let selector = comptime { FunctionSelector::from_signature("is_consumable((Field),Field)") }; |
| 49 | + PublicStaticCall::new( |
| 50 | + self.target_contract, |
| 51 | + selector, |
| 52 | + "is_consumable", |
| 53 | + [on_behalf_of.to_field(), message_hash], |
| 54 | + ) |
| 55 | + } |
| 56 | + |
| 57 | + pub fn is_reject_all(self, on_behalf_of: AztecAddress) -> PublicStaticCall<13, 1, bool> { |
| 58 | + let selector = comptime { FunctionSelector::from_signature("is_reject_all((Field))") }; |
| 59 | + PublicStaticCall::new( |
| 60 | + self.target_contract, |
| 61 | + selector, |
| 62 | + "is_reject_all", |
| 63 | + [on_behalf_of.to_field()], |
| 64 | + ) |
| 65 | + } |
| 66 | + |
| 67 | + pub fn set_authorized(self, message_hash: Field, authorize: bool) -> PublicCall<14, 2, ()> { |
| 68 | + let selector = comptime { FunctionSelector::from_signature("set_authorized(Field,bool)") }; |
| 69 | + PublicCall::new( |
| 70 | + self.target_contract, |
| 71 | + selector, |
| 72 | + "set_authorized", |
| 73 | + [message_hash, authorize as Field], |
| 74 | + ) |
| 75 | + } |
| 76 | + |
| 77 | + pub fn set_reject_all(self, reject: bool) -> PublicCall<14, 1, ()> { |
| 78 | + let selector = comptime { FunctionSelector::from_signature("set_reject_all(bool)") }; |
| 79 | + PublicCall::new( |
| 80 | + self.target_contract, |
| 81 | + selector, |
| 82 | + "set_reject_all", |
| 83 | + [reject as Field], |
| 84 | + ) |
| 85 | + } |
| 86 | +} |
0 commit comments