pub fn version_check_decode(
	input: impl AsRef<str>,
) -> Result<(AddressVersion, Vec<u8>), C32Error> {
	let input = input.as_ref();

	if !input.is_ascii() {
		return Err(C32Error::InvalidC32);
	}

	let (encoded_version_bytes, encoded_data_bytes) = input.split_at(1);

	let decoded_version_bytes = decode(encoded_version_bytes)?;
	let decoded_version_byte = *decoded_version_bytes.first().unwrap();
	let decoded_data_bytes = decode(encoded_data_bytes)?;

	if decoded_data_bytes.len() < 4 {
		return Err(C32Error::InvalidC32);
	}

	let (data_bytes, expected_checksum) =
		decoded_data_bytes.split_at(decoded_data_bytes.len() - 4);

	let mut buffer_to_check = vec![decoded_version_byte];
	buffer_to_check.extend_from_slice(data_bytes);

	let computed_checksum = DoubleSha256Hasher::new(buffer_to_check).checksum();

	if computed_checksum != expected_checksum {
		return Err(C32Error::InvalidChecksum(
			computed_checksum,
			expected_checksum.to_vec(),
		));
	}

	Ok((
		decoded_version_byte
			.try_into()
			.map_err(|_| C32Error::InvalidVersion(decoded_version_byte))?,
		data_bytes.to_vec(),
	))
}
C32 decode the given data with a version check
stacks-core/src/c32.rs