MCPcopy Create free account
hub / github.com/ProvableHQ/sdk / authorize_request

Method authorize_request

wasm/src/programs/manager/authorize.rs:139–209  ·  view source on GitHub ↗
(
        request: &ExecutionRequest,
        program: &str,
        unchecked: bool,
        edition: Option<u16>,
        imports: Option<Object>,
        private_key: Option<PrivateKey>,
        pr

Source from the content-addressed store, hash-verified

137 /// @param {PrivateKey | undefined} [private_key] Optional private key of the signer. If not provided, functions which call other programs may not succeed.
138 #[wasm_bindgen(js_name = buildAuthorizationFromExecutionRequest)]
139 pub async fn authorize_request(
140 request: &ExecutionRequest,
141 program: &str,
142 unchecked: bool,
143 edition: Option<u16>,
144 imports: Option<Object>,
145 private_key: Option<PrivateKey>,
146 program_imports: Option<ProgramImports>,
147 ) -> Result<Authorization, String> {
148 let edition = edition.unwrap_or(1);
149
150 let mut resolved = ResolvedProcess::resolve(&program_imports, program, edition, imports)?;
151 let program_native = resolved.program().clone();
152 let process = resolved.process_mut();
153
154 // Get the private key.
155 let private_key_native = private_key.map(|pk| PrivateKeyNative::from(pk));
156
157 // Get the request from the wasm wrapper.
158 let request_native = RequestNative::from(request);
159
160 // Check that the program id matches the program id in the request.
161 let request_program_id = request_native.program_id();
162 if request_program_id != program_native.id() {
163 return Err(format!(
164 "ExecutionRequest program id '{}' does not match provided program source id '{}'",
165 request_program_id,
166 program_native.id()
167 ));
168 }
169
170 log(&format!("Creating proving request for {request_program_id}:{}", request.function_name()));
171 let rng = &mut rand::rng();
172 // Add the program to the process (no-op if ensure_program already added it).
173 if request_program_id.to_string() != "credits.aleo" && !process.contains_program(request_program_id) {
174 log("Adding program to the process");
175 process.lock().add_program_with_edition(&program_native, edition).map_err(|e| e.to_string())?;
176 }
177
178 // If a private key is provided, use it to authorize the request, otherwise use authorize_request method.
179 let authorization = match private_key_native {
180 Some(private_key_native) => {
181 // Initialize the authorization from the request.
182 let authorization = AuthorizationNative::new(request_native.clone());
183
184 // Get the stack.
185 let stack = process.get_stack(program_native.id()).map_err(|e| e.to_string())?;
186
187 // Construct the call stack.
188 let call_stack =
189 CallStackNative::Authorize(vec![request_native], Some(private_key_native), authorization.clone());
190 let caller = None;
191 let root_tvk = None;
192
193 // Build unchecked or checked authorization depending on the flag.
194 if unchecked {
195 let _response = stack
196 .evaluate_function::<CurrentAleo, _>(call_stack, caller, root_tvk, rng)

Callers

nothing calls this directly

Calls 7

programMethod · 0.80
process_mutMethod · 0.80
logFunction · 0.50
cloneMethod · 0.45
program_idMethod · 0.45
idMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected