Esempio n. 1
0
        public void VerifySignature()
        {
            TestType testType = new TestType
            {
                StringType  = "test",
                AddressType = ZeroAddress,
                IntegerType = 0,
                BoolType    = true,
                BytesType   = new byte[1],
                Bytes16Type = new byte[16],
                NestedType  = new NestedType
                {
                    StringType = "test"
                }
            };
            EIP712Domain domain = new EIP712Domain()
            {
                Name              = "Test domain name",
                Version           = "1",
                ChainId           = 3,
                Salt              = new byte[32],
                VerifyingContract = ZeroAddress
            };

            EthereumSignature sig = EIP712Service.Sign(testType, domain, PrivateKey);
            bool sigValid         = EIP712Service.VerifySignature(testType, domain,
                                                                  Address, sig.Packed);

            Assert.IsTrue(sigValid);
        }
Esempio n. 2
0
        // Potentially async in the future due to fact some signature types require interaction with Ethereum network
        /// <summary>
        /// Verifies order signature
        /// </summary>
        /// <param name="exchangeAddress">Exchange contract address</param>
        /// <param name="signerAddress">Signer address</param>
        /// <param name="signature">Signature</param>
        /// <returns><c>true</c> if signature is valid, false otherwise</returns>
        public bool VerifySignature(EthereumAddress exchangeAddress, EthereumAddress signerAddress, byte[] signature)
        {
            if (signature[65] != Constants.EIP712SignatureType[0])
            {
                throw new NotImplementedException("Only EIP712 signature types are supported");
            }

            return(EIP712Service.VerifySignature(EIP712Order, GetEIP712Domain(exchangeAddress),
                                                 signerAddress, ReformatSignature(signature)));
        }