func (a *BitpayAddressPubKeyHash) String() string {
	return a.EncodeAddress()
}
String returns a human-readable string for the pay-to-pubkey-hash address.
This is equivalent to calling EncodeAddress, but is provided so the type can
be used as a fmt.Stringer.
package bchutil
import (
	"errors"
	"fmt"
	"github.com/btcsuite/btcd/chaincfg"
	"github.com/btcsuite/btcutil"
	"github.com/btcsuite/btcutil/base58"
	"golang.org/x/crypto/ripemd160"
)
var (
	bitpayP2PkH = byte(0x1C)
	bitpayP2SH  = byte(0x28)
)
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)
}
func encodeBitpayAddress(hash160 []byte, netID byte) string {
	return base58.CheckEncode(hash160[:ripemd160.Size], netID)
}
func DecodeBitpay(addr string, defaultNet *chaincfg.Params) (btcutil.Address, error) {
	decoded, netID, err := base58.CheckDecode(addr)
	if err != nil {
		if err == base58.ErrChecksum {
			return nil, ErrChecksumMismatch
		}
		return nil, errors.New("decoded address is of unknown format")
	}
	switch len(decoded) {
	case ripemd160.Size:  
		isP2PKH := chaincfg.IsPubKeyHashAddrID(netID) || netID == bitpayP2PkH
		isP2SH := chaincfg.IsScriptHashAddrID(netID) || netID == bitpayP2SH
		switch hash160 := decoded; {
		case isP2PKH && isP2SH:
			return nil, ErrAddressCollision
		case isP2PKH:
			return newBitpayAddressPubKeyHash(hash160, netID)
		case isP2SH:
			return newBitpayAddressScriptHashFromHash(hash160, netID)
		default:
			return nil, ErrUnknownAddressType
		}
	default:
		return nil, errors.New("decoded address is of unknown size")
	}
}
type BitpayAddressPubKeyHash struct {
	hash  [ripemd160.Size]byte
	netID byte
}
func NewBitpayAddressPubKeyHash(pkHash []byte, net *chaincfg.Params) (*BitpayAddressPubKeyHash, error) {
	var v byte
	if net.Name == chaincfg.MainNetParams.Name {
		v = bitpayP2PkH
	} else {
		v = net.PubKeyHashAddrID
	}
	return newBitpayAddressPubKeyHash(pkHash, v)
}
func newBitpayAddressPubKeyHash(pkHash []byte, netID byte) (*BitpayAddressPubKeyHash, error) {
	if len(pkHash) != ripemd160.Size {
		return nil, errors.New("pkHash must be 20 bytes")
	}
	addr := &BitpayAddressPubKeyHash{netID: netID}
	copy(addr.hash[:], pkHash)
	return addr, nil
}
func (a *BitpayAddressPubKeyHash) EncodeAddress() string {
	return encodeBitpayAddress(a.hash[:], a.netID)
}
func (a *BitpayAddressPubKeyHash) ScriptAddress() []byte {
	return a.hash[:]
}
func (a *BitpayAddressPubKeyHash) IsForNet(net *chaincfg.Params) bool {
	return a.netID == net.PubKeyHashAddrID
}