/// <summary> /// Creates transaction encoder based on Plasma version /// </summary> /// <param name="rootChainVersion">version of plasma. Defaults to RootChainABI.DefaultVersion</param> /// <param name="rootChainAddress">root chain address</param> /// <returns></returns> public static ITransactionEncoder Create(RootChainVersion rootChainVersion, string rootChainAddress) { if (rootChainVersion == RootChainVersion.Default) { rootChainVersion = RootChainABI.DefaultVersion; } if (rootChainVersion == RootChainVersion.Ari) { return(new RawTransactionEncoder()); } else if (rootChainVersion == RootChainVersion.Samrong) { EIP712Domain defaultDomain = new EIP712Domain( "OMG Network", "1", rootChainAddress, "0xfad5c7f626d80f9256ef01929f3beb96e058b8b4b0e3fe52d84f054c0e2a7a83".HexToByteArray()); return(new TypedDataTransactionEncoder(defaultDomain)); } else { throw new NotSupportedException(); } }
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); }
/// <summary> /// Hashes given order /// </summary> /// <param name="exchangeAddress">Exchange contract address</param> /// <returns>Order signature</returns> /// <exception cref="ArgumentNullException">exchangeAddress is <c>null</c></exception> public byte[] Hash(EthereumAddress exchangeAddress) { if (exchangeAddress == null) { throw new ArgumentNullException(nameof(exchangeAddress)); } EIP712Domain domain = GetEIP712Domain(exchangeAddress); return(EIP712Service.Hash(EIP712Order, domain)); }
/// <summary> /// Constructs typed data transaction encoder with given domain /// </summary> /// <param name="_domain">EIP-712 domain</param> public TypedDataTransactionEncoder(EIP712Domain _domain) { domain = _domain; }