func encodeSegWitAddress(hrp string, witnessVersion byte, witnessProgram []byte) (string, error) {
	converted, err := bech32.ConvertBits(witnessProgram, 8, 5, true)
	if err != nil {
		return "", err
	}
	combined := make([]byte, len(converted)+1)
	combined[0] = witnessVersion
	copy(combined[1:], converted)
	bech, err := bech32.Encode(hrp, combined)
	if err != nil {
		return "", err
	}
	version, program, err := decodeSegWitAddress(bech)
	if err != nil {
		return "", fmt.Errorf("invalid segwit address: %v", err)
	}
	if version != witnessVersion || !bytes.Equal(program, witnessProgram) {
		return "", fmt.Errorf("invalid segwit address")
	}
	return bech, nil
}
encodeSegWitAddress creates a bech32 encoded address string representation
from witness version and witness program.
package soterutil
import (
	"bytes"
	"encoding/hex"
	"errors"
	"fmt"
	"strings"
	"github.com/soteria-dag/soterd/soterec"
	"github.com/soteria-dag/soterd/chaincfg"
	"github.com/soteria-dag/soterd/soterutil/base58"
	"github.com/soteria-dag/soterd/soterutil/bech32"
	"golang.org/x/crypto/ripemd160"
)
type UnsupportedWitnessVerError byte
func (e UnsupportedWitnessVerError) Error() string {
	return "unsupported witness version: " + string(e)
}
type UnsupportedWitnessProgLenError int
func (e UnsupportedWitnessProgLenError) Error() string {
	return "unsupported witness program length: " + string(e)
}
var (
	ErrChecksumMismatch = errors.New("checksum mismatch")
	ErrUnknownAddressType = errors.New("unknown address type")
	ErrAddressCollision = errors.New("address collision")
)
func encodeAddress(hash160 []byte, netID byte) string {
	return base58.CheckEncode(hash160[:ripemd160.Size], netID)
}