use near_mpc_sdk::{ foreign_chain::starknet::StarknetFinality, near_mpc_contract_interface::types::{AptosFinality, EvmFinality}, }; use near_sdk::near; /// Finality enum that supports both EVM and Starknet chains. #[near(serializers = [borsh, json])] #[derive(Debug, Clone, PartialEq)] pub enum MpcFinality { Evm(EvmFinality), Starknet(StarknetFinality), Aptos(AptosFinality), } #[near(serializers = [json])] #[derive(Clone, Debug)] pub struct AffinePoint { pub affine_point: String, } #[near(serializers = [json])] #[derive(Clone, Debug)] pub struct Scalar { pub scalar: String, } #[near(serializers = [json])] #[derive(Clone, Debug)] pub struct SignatureResponse { pub big_r: AffinePoint, pub s: Scalar, pub recovery_id: u8, } impl SignatureResponse { /// # Panics /// /// This function will panic in the following cases: /// - If `self.big_r.affine_point` is not a valid hexadecimal string. /// - If `self.s.scalar` is not a valid hexadecimal string. /// - If the decoded `self.big_r.affine_point` is shorter than 1 byte. /// /// The error message "Incorrect Signature" will be displayed in case of a panic. pub fn to_bytes(&self) -> Vec { let mut bytes = Vec::new(); bytes.extend_from_slice( &hex::decode(&self.big_r.affine_point).expect("Incorrect Signature")[1..], ); bytes.extend_from_slice(&hex::decode(&self.s.scalar).expect("Incorrect Signature")); bytes.push(self.recovery_id + 27); bytes } }