public bool IsCertificateSignatureValid() { var signer = new EthereumMessageSigner(); var recoveredAddress = signer.EcRecover(ImmunityCertificate.GetHashCertificate(), Signature.ToHex()); return(recoveredAddress.IsTheSameAddress(ImmunityCertificate.SignerAddress)); }
public void ShouldRecover() { var signature = "0x0976a177078198a261faf206287b8bb93ebb233347ab09a57c8691733f5772f67f398084b30fc6379ffee2cc72d510fd0f8a7ac2ee0162b95dc5d61146b40ffa1c"; var text = "test"; var hasher = new Sha3Keccack(); var hash = hasher.CalculateHash(text); var signer = new EthereumMessageSigner(); var account = signer.EcRecover(hash.HexToByteArray(), signature); Assert.Equal("0x12890d2cce102216644c59dae5baed380d84830c", account.EnsureHexPrefix().ToLower()); signature = signer.Sign(hash.HexToByteArray(), "0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7"); account = signer.EcRecover(hash.HexToByteArray(), signature); Assert.Equal("0x12890d2cce102216644c59dae5baed380d84830c".ToLower(), account.EnsureHexPrefix().ToLower()); }
public EthECDSASignature Sign(string contract, string makerAddress, string makerToken, string takerToken, string makerAmount, string takerAmount, string expires, string nonce) { var plainData = new Object[] { contract, takerToken, BigInteger.Parse(takerAmount), makerToken, BigInteger.Parse(makerAmount), BigInteger.Parse(expires), BigInteger.Parse(nonce) }; var prms = new[] { new Parameter("address", 1), new Parameter("address", 1), new Parameter("uint256", 1), new Parameter("address", 1), new Parameter("uint256", 1), new Parameter("uint256", 1), new Parameter("uint256", 1) }; var data = SolidityPack(plainData, prms); var keystoreCrypto = new KeyStoreCrypto(); //for etherDelta its SHA256, for IDEX just change with SHA3 var hashed = keystoreCrypto.CalculateSha256Hash(data); var signer = new EthereumMessageSigner(); var newHash = signer.HashPrefixedMessage(hashed); var signatureRaw = signer.SignAndCalculateV(newHash, _userDataProvider.PrivateKey); var signature = EthECDSASignature.CreateStringSignature(signatureRaw); var probe = signer.EcRecover(hashed, signature); var ethEcdsa = MessageSigner.ExtractEcdsaSignature(signature); if (probe == makerAddress) { return(ethEcdsa); } //depending on usage, but it would be better to throw exc here if fails return(null); //throw new Exception("Signing failed"); }
public string RecoveryBouncy() { EthECKey.SignRecoverable = false; var signature = "0x0976a177078198a261faf206287b8bb93ebb233347ab09a57c8691733f5772f67f398084b30fc6379ffee2cc72d510fd0f8a7ac2ee0162b95dc5d61146b40ffa1c"; var text = "test"; var hasher = new Sha3Keccack(); var hash = hasher.CalculateHash(text); var signer = new EthereumMessageSigner(); var account = signer.EcRecover(hash.HexToByteArray(), signature); return(account); }
public RecoverModel EcRecover(Address sender, Signature signature, Hash hash) { var ethereumSigner = new EthereumMessageSigner(); var signer = Address.Of(ethereumSigner.EcRecover(hash.GetBytes(), signature)); logger.LogDebug("Hash {0} , Signature {1}, Signer {2}, Sender {3}", hash, signature, signer, sender); return(new RecoverModel { Signer = signer, Hash = hash, Valid = signer == sender }); }
public static bool IsSignatureValid(string sentSignature, string sentAddress, string msg) { var msgHash = Encoding.UTF8.GetBytes(msg); var signer = new EthereumMessageSigner(); //var signature = signer.HashAndSign(msg, msg); var address = signer.EcRecover(msgHash, sentSignature); if (address.ToLower() == sentAddress.ToLower()) { return(true); } else { return(false); } }
public void test4() { var signature = "0xdb46c6be4b1ee0ef670625630d38899213ea5d63d749954d82a4651b81f7d44f6d16e2e4903038c022b71d11baa26b08142c6b9f5db106d7b96b57d1836ce10e1b"; var text = "test"; var hasher = new Sha3Keccack(); var hash = hasher.CalculateHash(text); var signer = new EthereumMessageSigner(); var account = signer.EncodeUTF8AndEcRecover(text, signature); Assert.Equal("0xe77992311815D6961cBB231CFd2009990203385F".ToLower(), account.EnsureHexPrefix().ToLower()); signature = signer.Sign(hash.HexToByteArray(), "0xd3a7d42d881a9b59ccefcac0f5bcc69f85e68fdf0bfb6fcbbe42373320de420f"); account = signer.EcRecover(hash.HexToByteArray(), signature); Assert.Equal("0x12890d2cce102216644c59dae5baed380d84830c".ToLower(), account.EnsureHexPrefix().ToLower()); }
/// <summary> /// Returns HoardID that signed given message /// </summary> /// <param name="message">message</param> /// <param name="signature">signature string (from Profile.SignMessage)</param> /// <returns>Signer of the message</returns> public static HoardID RecoverHoardIdFromMessage(byte[] message, string signature) { var msgSigner = new EthereumMessageSigner(); return(new HoardID(msgSigner.EcRecover(message, signature))); }