func decode(src []byte) ([]byte, error) {
	raw := make([]byte, b32Enc.DecodedLen(len(src)))
	n, err := b32Enc.Decode(raw, src)
	if err != nil {
		return nil, err
	}
	raw = raw[:n]
	if len(raw) < 4 {
		return nil, ErrInvalidEncoding
	}
	var crc uint16
	checksum := bytes.NewReader(raw[len(raw)-2:])
	if err := binary.Read(checksum, binary.LittleEndian, &crc); err != nil {
		return nil, err
	}
	if err := validate(raw[0:len(raw)-2], crc); err != nil {
		return nil, err
	}
	return raw[:len(raw)-2], nil
}
decode will decode the base32 and check crc16 and the prefix for validity.
package nkeys
import (
	"bytes"
	"encoding/base32"
	"encoding/binary"
	"golang.org/x/crypto/ed25519"
)
type PrefixByte byte
const (
	PrefixByteSeed PrefixByte = 18 << 3  
	PrefixBytePrivate PrefixByte = 15 << 3  
	PrefixByteServer PrefixByte = 13 << 3  
	PrefixByteCluster PrefixByte = 2 << 3  
	PrefixByteOperator PrefixByte = 14 << 3  
	PrefixByteAccount PrefixByte = 0  
	PrefixByteUser PrefixByte = 20 << 3  
	PrefixByteUnknown PrefixByte = 23 << 3  
)
var b32Enc = base32.StdEncoding.WithPadding(base32.NoPadding)
func Encode(prefix PrefixByte, src []byte) ([]byte, error) {
	if err := checkValidPrefixByte(prefix); err != nil {
		return nil, err
	}
	var raw bytes.Buffer
	if err := raw.WriteByte(byte(prefix)); err != nil {
		return nil, err
	}
	if _, err := raw.Write(src); err != nil {
		return nil, err
	}
	err := binary.Write(&raw, binary.LittleEndian, crc16(raw.Bytes()))
	if err != nil {
		return nil, err
	}
	data := raw.Bytes()
	buf := make([]byte, b32Enc.EncodedLen(len(data)))
	b32Enc.Encode(buf, data)
	return buf[:], nil
}
func EncodeSeed(public PrefixByte, src []byte) ([]byte, error) {
	if err := checkValidPublicPrefixByte(public); err != nil {
		return nil, err
	}
	if len(src) != ed25519.SeedSize {
		return nil, ErrInvalidSeedLen
	}
	b1 := byte(PrefixByteSeed) | (byte(public) >> 5)
	b2 := (byte(public) & 31) << 3  
	var raw bytes.Buffer
	raw.WriteByte(b1)
	raw.WriteByte(b2)
	if _, err := raw.Write(src); err != nil {
		return nil, err
	}
	err := binary.Write(&raw, binary.LittleEndian, crc16(raw.Bytes()))
	if err != nil {
		return nil, err
	}
	data := raw.Bytes()
	buf := make([]byte, b32Enc.EncodedLen(len(data)))
	b32Enc.Encode(buf, data)
	return buf, nil
}
func IsValidEncoding(src []byte) bool {
	_, err := decode(src)
	return err == nil
}