(
private_key: PrivateKey,
program_id: String,
function_name: String,
inputs: Array,
input_types: Array,
root_tvk: Option<Field>,
program_checks
| 232 | /// @param {boolean} is_dynamic Flag to indicate if this is a dynamic call. |
| 233 | #[allow(clippy::too_many_arguments)] |
| 234 | pub fn sign( |
| 235 | private_key: PrivateKey, |
| 236 | program_id: String, |
| 237 | function_name: String, |
| 238 | inputs: Array, |
| 239 | input_types: Array, |
| 240 | root_tvk: Option<Field>, |
| 241 | program_checksum: Option<Field>, |
| 242 | is_root: bool, |
| 243 | is_dynamic: bool, |
| 244 | ) -> Result<ExecutionRequest, String> { |
| 245 | // Convert the ProgramID and function name to their native objects. |
| 246 | let program_id = ProgramIDNative::from_str(&program_id).map_err(|e| e.to_string())?; |
| 247 | let function_name = IdentifierNative::from_str(&function_name).map_err(|e| e.to_string())?; |
| 248 | |
| 249 | // Ensure the inputs are valid Aleo types. |
| 250 | let inputs = inputs |
| 251 | .iter() |
| 252 | .enumerate() |
| 253 | .map(|(i, input)| { |
| 254 | let s = input.as_string().ok_or_else(|| format!("Input {i} is not a string"))?; |
| 255 | ValueNative::from_str(&s).map_err(|e| format!("Failed to deserialize input {i} as value '{s}' - please check the input at position {i} and try again: {e}")) |
| 256 | }) |
| 257 | .collect::<Result<Vec<ValueNative>, String>>()?; |
| 258 | |
| 259 | // Ensure the input types specified match the types of the specified inputs. |
| 260 | let input_types = input_types |
| 261 | .iter() |
| 262 | .enumerate() |
| 263 | .map(|(i, input_type)| { |
| 264 | let s = input_type.as_string().ok_or_else(|| format!("Input type {i} is not a string"))?; |
| 265 | ValueTypeNative::from_str(&s).map_err(|e| format!("Failed to deserialize input {i} as input type '{s}' - please check the input at position {i} and try again: {e}")) |
| 266 | }) |
| 267 | .collect::<Result<Vec<ValueTypeNative>, String>>()?; |
| 268 | |
| 269 | // Get the root tvk if it was specified. |
| 270 | let root_tvk = root_tvk.map(FieldNative::from); |
| 271 | let program_checksum = program_checksum.map(FieldNative::from); |
| 272 | |
| 273 | // Generate an RNG for the function from system entropy. |
| 274 | let mut rng = rand::rng(); |
| 275 | |
| 276 | // Generate the signature over the (program_id, function, input, and private_key) tuple. |
| 277 | let request = RequestNative::sign( |
| 278 | &private_key, |
| 279 | program_id, |
| 280 | function_name, |
| 281 | inputs.into_iter(), |
| 282 | &input_types, |
| 283 | root_tvk, |
| 284 | is_root, |
| 285 | program_checksum, |
| 286 | is_dynamic, |
| 287 | &mut rng, |
| 288 | ) |
| 289 | .map_err(|e| e.to_string())?; |
| 290 | |
| 291 | // Return the execution request. |
no test coverage detected