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)
public string CheckBase58Bip38(string bip38) { if (!b58Enc.HasValidChars(bip38)) { return("The given BIP-38 string contains invalid base-58 characters."); } if (!b58Enc.IsValid(bip38)) { return("The given BIP-38 string has an invalid checksum."); } byte[] data = b58Enc.DecodeWithCheckSum(bip38); if (data.Length != ConstantsFO.Bip38ByteLen) { return("The given BIP-38 string has an invalid byte length."); } if (data[0] != 1 || (data[1] != 0x42 && data[1] != 0x43)) { return("The given BIP-38 string has invalid starting bytes."); } return("The given BIP-38 string is valid."); }
public void HasValidCharsTest(string s, bool expected) { Assert.Equal(expected, encoder.HasValidChars(s)); }