Exemple #1
0
        /// <summary>
        /// Encodes data according to EIP-712.
        /// </summary>
        public byte[] EncodeTypedData <TDomain>(TypedData <TDomain> typedData) where TDomain : IDomain
        {
            using (var memoryStream = new MemoryStream())
                using (var writer = new BinaryWriter(memoryStream))
                {
                    writer.Write("1901".HexToByteArray());
                    writer.Write(HashStruct(typedData.Types, "EIP712Domain", MemberValueFactory.CreateFromMessage(typedData.Domain)));
                    writer.Write(HashStruct(typedData.Types, typedData.PrimaryType, typedData.Message));

                    writer.Flush();
                    var result = memoryStream.ToArray();
                    return(result);
                }
        }
Exemple #2
0
 /// <summary>
 /// Encodes data according to EIP-712, it uses a predefined typed data schema and converts and encodes the provide the message value
 /// </summary>
 public byte[] EncodeTypedData <T, TDomain>(T message, TypedData <TDomain> typedData) where TDomain : IDomain
 {
     typedData.Message = MemberValueFactory.CreateFromMessage(message);
     return(EncodeTypedData(typedData));
 }