public void TestPublicKeyToAddress() { var pubKey = "0x0465e790f6065164e2f610297b5358b6c474f999fb5b4d2574fcaffccb59342c1f6f28f0b684ec97946da65cd08a1b9fc276f79d90caed80e56456cebbc165938e".ToBytes(); var address = "0x7567d83b7b8d80addcb281a71d54fc7b3364ffed"; Assert.True(SimpleWallet.PublicKeyToAddress(pubKey) == address); }
private string GetDelegator() { if (!this.GetDelegated()) { return(""); } if (!this.GetSignatureValid()) { return(""); } try { byte[] signingHash = this.SigningHash(this.Origin); byte[] delegatorSignature = new byte[65]; Array.Copy(this.Signature, 65, delegatorSignature, 0, 65); byte[] delegatorpubKey = Secp256k1.RecoverPublickey(signingHash, delegatorSignature); return(SimpleWallet.PublicKeyToAddress(delegatorpubKey)); } catch { return(""); } }
private string GetOrigin() { if (!this.GetSignatureValid()) { return(""); } try { byte[] signingHash = this.SigningHash(); byte[] originSigh = new byte[65]; Array.Copy(this.Signature, 0, originSigh, 0, 65); byte[] pubKey = Secp256k1.RecoverPublickey(signingHash, originSigh); return(SimpleWallet.PublicKeyToAddress(pubKey)); } catch { return(""); } }
/// <summary> /// verify certificate signture /// </summary> /// <param name="certificate"></param> /// <returns></returns> public static bool Verify(ICertificate certificate) { const bool result = false; if (certificate.Signer == null || certificate.Signature.Length != 65) { throw new ArgumentException("invalid signature"); } try { byte[] msgHash = SigningHash(certificate); byte[] publicKey = Secp256k1.RecoverPublickey(msgHash, certificate.Signature); return(certificate.Signer.Equals(SimpleWallet.PublicKeyToAddress(publicKey))); } catch { } return(result); }