pub struct TypedData {
pub domain: Eip712Domain,
pub resolver: Resolver,
pub primary_type: String,
pub message: Value,
}
eip712
only.Expand description
Represents the EIP-712 typed data object.
Typed data is a JSON object containing type information, domain separator parameters and the message object which has the following schema:
{
"type": "object",
"properties": {
"types": {
"type": "object",
"properties": {
"EIP712Domain": { "type": "array" }
},
"additionalProperties": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": { "type": "string" },
"type": { "type": "string" }
},
"required": ["name", "type"]
}
},
"required": ["EIP712Domain"]
},
"primaryType": { "type": "string" },
"domain": { "type": "object" },
"message": { "type": "object" }
},
"required": ["types", "primaryType", "domain", "message"]
}
Fields§
§domain: Eip712Domain
Signing domain metadata. The signing domain is the intended context for the signature (e.g. the dapp, protocol, etc. that it’s intended for). This data is used to construct the domain separator of the message.
resolver: Resolver
The custom types used by this message.
primary_type: String
The type of the message.
message: Value
The message to be signed.
Implementations§
Source§impl TypedData
impl TypedData
Sourcepub fn from_struct<S: SolStruct + Serialize>(
s: &S,
domain: Option<Eip712Domain>,
) -> Self
pub fn from_struct<S: SolStruct + Serialize>( s: &S, domain: Option<Eip712Domain>, ) -> Self
Instantiate TypedData
from a SolStruct
that implements
serde::Serialize
.
Sourcepub const fn domain(&self) -> &Eip712Domain
pub const fn domain(&self) -> &Eip712Domain
Returns the domain for this typed data.
Sourcepub fn coerce(&self) -> Result<DynSolValue>
pub fn coerce(&self) -> Result<DynSolValue>
Coerce the message to the type specified by primary_type
, using the
types map as a resolver.
Sourcepub fn type_hash(&self) -> Result<B256>
pub fn type_hash(&self) -> Result<B256>
Calculate the Keccak-256 hash of encodeType
for this value.
Fails if this type is not a struct.
Sourcepub fn hash_struct(&self) -> Result<B256>
pub fn hash_struct(&self) -> Result<B256>
Calculate the hashStruct
for this value.
Fails if this type is not a struct.
Sourcepub fn encode_data(&self) -> Result<Vec<u8>>
pub fn encode_data(&self) -> Result<Vec<u8>>
Calculate the encodeData
for this value.
Fails if this type is not a struct.
Sourcepub fn encode_type(&self) -> Result<String>
pub fn encode_type(&self) -> Result<String>
Calculate the encodeType
for this value.
Fails if this type is not a struct.
Sourcepub fn eip712_signing_hash(&self) -> Result<B256>
pub fn eip712_signing_hash(&self) -> Result<B256>
Calculate the EIP-712 signing hash for this value.
This is the hash of the magic bytes 0x1901 concatenated with the domain
separator and the hashStruct
result.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for TypedData
impl<'de> Deserialize<'de> for TypedData
TypedData
is most likely going to be a stringified JSON object, so we have
to implement Deserialize manually to parse the string first.
See:
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
impl Eq for TypedData
impl StructuralPartialEq for TypedData
Auto Trait Implementations§
impl Freeze for TypedData
impl RefUnwindSafe for TypedData
impl Send for TypedData
impl Sync for TypedData
impl Unpin for TypedData
impl UnwindSafe for TypedData
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)