private static byte[] SerializePublicKey(PubKey publicKey, bool compressed)
        {
            int outputlen = compressed ? 33 : 65;

            byte[] output = new byte[outputlen];
            if (!Secp256K1T.EcPubkeySerialize(output, ref outputlen, publicKey, compressed ? Options.EcCompressed : Options.FlagsTypeCompression))
            {
                return((byte[])null);
            }
            if (outputlen == output.Length)
            {
                return(output);
            }
            byte[] numArray = new byte[outputlen];
            Array.Copy((Array)output, 0, (Array)numArray, 0, outputlen);
            return(numArray);
        }
        public static byte[] GetPublicKey(byte[] privateKey, bool compressed)
        {
            if (privateKey == null)
            {
                throw new ArgumentNullException(nameof(privateKey));
            }
            if (privateKey.Length != 32)
            {
                throw new ArgumentOutOfRangeException(nameof(privateKey));
            }
            PubKey pubKey = new PubKey();

            if (!Secp256K1T.EcPubKeyCreate(Secp256K1Manager.Ctx, pubKey, privateKey))
            {
                return((byte[])null);
            }
            return(Secp256K1Manager.SerializePublicKey(pubKey, compressed));
        }
Exemplo n.º 3
0
        private static byte[] SerializePublicKey(PubKey publicKey, bool compressed)
        {
            var count  = compressed ? 33 : 65;
            var pubkey = new byte[count];

            {
                if (!Secp256K1T.EcPubkeySerialize(pubkey, ref count, publicKey, compressed ? Options.EcCompressed : Options.EcUncompressed))
                {
                    return(null);
                }
            }
            if (count == pubkey.Length)
            {
                return(pubkey);
            }

            var smallkey = new byte[count];

            Array.Copy(pubkey, 0, smallkey, 0, count);
            return(smallkey);
        }