Ejemplo n.º 1
0
        public string CheckPrivateKey(string key)
        {
            if (!b58End.HasValidChars(key))
            {
                return("The given key contains invalid base-58 characters.");
            }
            if (!b58End.HasValidCheckSum(key))
            {
                return("The given key has an invalid checksum.");
            }

            byte[] keyBa = b58End.DecodeWithCheckSum(key);
            if (keyBa[0] != Constants.PrivKeyFirstByte)
            {
                return($"Invalid first key byte (actual={keyBa[0]}, expected={Constants.PrivKeyFirstByte}).");
            }

            if (keyBa.Length == 33)
            {
                if (!IsPrivateKeyInRange(keyBa.SubArray(1)))
                {
                    return("Invalid key integer value (outside of the range defined by secp256k1 curve).");
                }

                return("The given key is a valid uncompressed private key.");
            }
            else if (keyBa.Length == 34)
            {
                if (keyBa[^ 1] != Constants.PrivKeyCompLastByte)