snarkvm_synthesizer_process/stack/
authorize.rs1use super::*;
17
18impl<N: Network> Stack<N> {
19 #[inline]
21 pub fn authorize<A: circuit::Aleo<Network = N>, R: Rng + CryptoRng>(
22 &self,
23 private_key: &PrivateKey<N>,
24 function_name: impl TryInto<Identifier<N>>,
25 inputs: impl ExactSizeIterator<Item = impl TryInto<Value<N>>>,
26 rng: &mut R,
27 ) -> Result<Authorization<N>> {
28 let timer = timer!("Stack::authorize");
29
30 let program_id = *self.program.id();
32 let function_name = function_name.try_into().map_err(|_| anyhow!("Invalid function name"))?;
34 let input_types = self.get_function(&function_name)?.input_types();
36 lap!(timer, "Retrieve the input types");
37 let is_root = true;
39 let program_checksum = match self.program().contains_constructor() {
41 true => Some(self.program_checksum_as_field()?),
42 false => None,
43 };
44
45 let caller = None;
47 let root_tvk = None;
49 let request = Request::sign(
51 private_key,
52 program_id,
53 function_name,
54 inputs,
55 &input_types,
56 root_tvk,
57 is_root,
58 program_checksum,
59 rng,
60 )?;
61 lap!(timer, "Compute the request");
62 let authorization = Authorization::new(request.clone());
64 let call_stack = CallStack::Authorize(vec![request], Some(*private_key), authorization.clone());
66 let _response = self.execute_function::<A, R>(call_stack, caller, root_tvk, rng)?;
68 finish!(timer, "Construct the authorization from the function");
69
70 Ok(authorization)
72 }
73
74 #[inline]
77 pub fn authorize_unchecked<A: circuit::Aleo<Network = N>, R: Rng + CryptoRng>(
78 &self,
79 private_key: &PrivateKey<N>,
80 function_name: impl TryInto<Identifier<N>>,
81 inputs: impl ExactSizeIterator<Item = impl TryInto<Value<N>>>,
82 rng: &mut R,
83 ) -> Result<Authorization<N>> {
84 let timer = timer!("Stack::authorize_unchecked");
85
86 let program_id = *self.program.id();
88 let function_name = function_name.try_into().map_err(|_| anyhow!("Invalid function name"))?;
90 let input_types = self.get_function(&function_name)?.input_types();
92 lap!(timer, "Retrieve the input types");
93 let is_root = true;
95
96 let caller = None;
98 let root_tvk = None;
100 let program_checksum = match self.program().contains_constructor() {
102 true => Some(self.program_checksum_as_field()?),
103 false => None,
104 };
105 let request = Request::sign(
107 private_key,
108 program_id,
109 function_name,
110 inputs,
111 &input_types,
112 root_tvk,
113 is_root,
114 program_checksum,
115 rng,
116 )?;
117 lap!(timer, "Compute the request");
118 let authorization = Authorization::new(request.clone());
120 let call_stack = CallStack::Authorize(vec![request], Some(*private_key), authorization.clone());
122 let _response = self.evaluate_function::<A, R>(call_stack, caller, root_tvk, rng)?;
124 finish!(timer, "Construct the authorization from the function");
125
126 Ok(authorization)
128 }
129
130 #[inline]
133 pub fn authorize_request<A: circuit::Aleo<Network = N>, R: Rng + CryptoRng>(
134 &self,
135 request: Request<N>,
136 rng: &mut R,
137 ) -> Result<Authorization<N>> {
138 let timer = timer!("Stack::authorize_request");
139
140 let program_id = *self.program.id();
142 ensure!(program_id.to_string() == "credits.aleo", "Program ID must be credits.aleo");
144 let authorization = Authorization::new(request.clone());
146 let call_stack = CallStack::Authorize(vec![request], None, authorization.clone());
148 let caller = None;
150 let root_tvk = None;
152 let _response = self.evaluate_function::<A, R>(call_stack, caller, root_tvk, rng)?;
154 finish!(timer, "Construct the authorization from the function");
155
156 Ok(authorization)
158 }
159}