use std::marker::PhantomData; use near_sdk::near; use near_sdk::serde::de::DeserializeOwned; use crate::encoding; use super::with_raw_string::WithRawString; use super::{ CheckSignatureError, ExecutionContextProvider, HashForSigning, Key, MessageWithSignature, MessageWithValidSignature, Payload, }; pub mod eip191; pub mod raw; pub mod sep53; pub trait Ed25519Variant { const PREFIX: &'static [u8]; } #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] #[near(serializers = [json])] #[serde(transparent, bound = "T: DeserializeOwned")] pub struct Message( pub WithRawString>, #[serde(skip)] pub PhantomData, ); impl HashForSigning for Message { const MAGIC_NUMBER: &'static [u8] = K::PREFIX; fn content_bytes(&self) -> Vec { self.0.raw.as_bytes().to_vec() } } impl, T> super::SignableMessage for Message { type Key = K; type Signature = encoding::ed25519::Signature; type Auxiliary = (); } impl, T: near_sdk::serde::Serialize> Message { pub fn new(inner: WithRawString>) -> Self { Self(inner, PhantomData) } pub fn from_parsed(payload: Payload) -> Self { Self(WithRawString::from_parsed(payload), PhantomData) } pub fn with_signature( self, signature: encoding::ed25519::Signature, ) -> MessageWithSignature { MessageWithSignature { message: self, signature, auxiliary: (), } } } impl From>> for Message { fn from(value: WithRawString>) -> Self { Self(value, PhantomData) } } impl>, T> ExecutionContextProvider for MessageWithValidSignature> { type Payload = T; fn payload(self) -> Payload { self.0.message.0.parsed } fn origin(&self) -> Option<&str> { None } }