public void Sign_With_PubKey_From_Commitment() { using (var secp256k1 = new Secp256k1()) using (var pedersen = new Pedersen()) { string ToHex(byte[] data) { return(BitConverter.ToString(data).Replace("-", string.Empty)); } var blinding = secp256k1.CreatePrivateKey(); var commit = pedersen.Commit(0, blinding); var msg = "Message for signing"; var msgBytes = Encoding.UTF8.GetBytes(msg); var msgHash = System.Security.Cryptography.SHA256.Create().ComputeHash(msgBytes); var sig = secp256k1.Sign(msgHash, blinding); var pubKey = pedersen.ToPublicKey(commit); Assert.True(secp256k1.Verify(sig, msgHash, pubKey)); var actualPubKey = secp256k1.CreatePublicKey(blinding); Assert.Equal(ToHex(pubKey), ToHex(actualPubKey)); } }
static void TestToPublicKey() { using (var secp256k1 = new Secp256k1()) using (var pedersen = new Pedersen()) { var blinding = secp256k1.CreatePrivateKey(); var commitPos = pedersen.Commit(0, blinding); var commitNeg = pedersen.Commit(0, blinding); var blindSum = pedersen.BlindSum(new List <byte[]> { blinding, blinding }, new List <byte[]> { }); var commitSum = pedersen.CommitSum(new List <byte[]> { commitPos }, new List <byte[]> { commitNeg }); var msg = "Message for signing"; var msgBytes = Encoding.UTF8.GetBytes(msg); var msgHash = System.Security.Cryptography.SHA256.Create().ComputeHash(msgBytes); var sig = secp256k1.Sign(msgHash, blinding); var pubKey = pedersen.ToPublicKey(commitSum); var verified1 = secp256k1.Verify(sig, msgHash, pubKey); var pub = secp256k1.CreatePublicKey(blinding); } }