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(""); } }
public void TestSecp256k1() { var priKey = Secp256k1.GeneratePrivateKey(); var pubKey = Secp256k1.DerivePublicKey(priKey); var msgHash = Keccack256.CalculateHash("hello world"); var signature = Secp256k1.Sign(msgHash, priKey); var recoveredPubKey = Secp256k1.RecoverPublickey(Keccack256.CalculateHash("hello world"), signature); Assert.True(pubKey.SequenceEqual(recoveredPubKey)); }
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); }