Exemple #1
0
        /// *** This is a temporary work-around. ***
        /// We do not know which of the two possible public keys from the commit to use,
        /// so here we try both of them and succeed if either works.
        /// This is sub-optimal in terms of performance.
        /// I believe apoelstra has a strategy for fixing this in the secp256k1-zkp lib.
        public static void verify_from_commit(this Secp256K1 self, Message msg, Signiture sig, Commitment commit)
        {
            if (self.Caps != ContextFlag.Commit)
            {
                throw new Exception("IncapableContext");
            }

            // If we knew which one we cared about here we would just use it,
            // but for now return both so we can try them both.
            var pubkeys = commit.to_two_pubkeys(self);

            // Attempt to verify with the first public key,
            // if verify fails try the other one.
            // The first will fail on average 50% of the time.

            try
            {
                self.Verify(msg, sig, pubkeys[0]);
            }
            catch (Exception)
            {
                self.Verify(msg, sig, pubkeys[1]);
            }
        }