コード例 #1
0
        /// <summary>
        /// Signature signing
        /// </summary>
        /// <param name="exchangeAddress">Exchange contract address</param>
        /// <param name="privateKey">Private key</param>
        /// <returns>Order signature (currently only EIP712 signature type is supported)</returns>
        public byte[] Sign(EthereumAddress exchangeAddress, string privateKey)
        {
            EthereumSignature signature = EIP712Service.Sign(EIP712Order,
                                                             GetEIP712Domain(exchangeAddress), privateKey);

            return(ByteUtil.Merge(signature.V, signature.R, signature.S, Constants.EIP712SignatureType));
        }
コード例 #2
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);
        }