Beispiel #1
0
 static KzPubKey()
 {
     lazySecp256k1 = new Lazy <Secp256k1>(() => {
         var ctx = new Secp256k1(sign: true, verify: true);
         ctx.Randomize(KzRandom.GetStrongRandBytes(32));
         return(ctx);
     }, true);
 }
Beispiel #2
0
 public void MakeNewKey(bool compressed)
 {
     do
     {
         KzRandom.GetStrongRandBytes(keydata.Span);
     } while (!Check(keydata.ReadOnlySpan));
     fValid      = true;
     fCompressed = compressed;
 }
Beispiel #3
0
        /// <summary>
        /// Create a new KzMnemonic from a desired entropy length in bits.
        /// length should be a multiple of 32.
        /// </summary>
        /// <param name="length">Entropy length in bits. Should be a multiple of 32.</param>
        /// <param name="wordList">string[] of 2048 unique words.</param>
        /// <param name="language">optional Languages key to use. Defaults to Unknown.</param>
        public KzMnemonic(int length, string[] wordList, Languages language = Languages.Unknown)
        {
            Entropy = new byte[length / 8];
            KzRandom.GetStrongRandBytes(Entropy);

            Language = language;
            WordList = wordList;
            Words    = ConvertDataToWords(Entropy, WordList);
        }
Beispiel #4
0
        /// <summary>
        /// Verify thoroughly whether a private key and a public key match.
        /// This is done using a different mechanism than just regenerating it.
        /// </summary>
        /// <param name="pubKey"></param>
        /// <returns></returns>
        public bool VerifyPubKey(KzPubKey pubkey)
        {
            if (pubkey.IsCompressed != fCompressed)
            {
                return(false);
            }

            var rnd = KzRandom.GetStrongRandBytes(8).ToArray();
            var str = "Bitcoin key verification\n";

            var hash = KzHashes.HASH256(Encoding.ASCII.GetBytes(str).Concat(rnd).ToArray());

            var(ok, sig) = Sign(hash);

            if (!ok)
            {
                return(false);
            }

            return(pubkey.Verify(hash, sig));
        }