func (m Multikeypair) Decode() (Keypair, error) {
	return Decode(m)
}
Decode unpacks a multikeypair into a Keypair struct.
package multikeypair
import (
	"encoding/binary"
	"errors"
	b58 "github.com/mr-tron/base58/base58"
	varint "github.com/multiformats/go-varint"
	cryptobyte "golang.org/x/crypto/cryptobyte"
)
const (
	MIN_KEY_LENGTH = 2
	MAX_KEY_LENGTH = 256
)
var (
	ErrUnknownCode         = errors.New("unknown multikeypair code")
	ErrTooShort            = errors.New("multikeypair too short. must be >= 2 bytes")
	ErrTooLong             = errors.New("multikeypair too long. must be < 129 bytes")
	ErrInvalidMultikeypair = errors.New("input isn't valid multikeypair")
	ErrVarintBufferShort   = errors.New("uvarint: buffer too small")
	ErrVarintTooLong       = errors.New("uvarint: varint too big (max 64bit)")
)
const (
	IDENTITY = uint64(0x00)
	ED_25519 = uint64(0x11)
	BIP_32   = uint64(0x22)
	DSA      = uint64(0x33)
	RSA      = uint64(0x44)
)
var Names = map[string]uint64{
	"identity": IDENTITY,
	"ed25519":  ED_25519,
	"bip32":    BIP_32,
	"dsa":      DSA,
	"res":      RSA,
}
var Codes = map[uint64]string{
	IDENTITY: "identity",
	ED_25519: "ed25519",
	BIP_32:   "bip32",
	DSA:      "dsa",
	RSA:      "rsa",
}
type Keypair struct {
	Code uint64
	Name string
	Public []byte
	PublicLength int
	Private []byte
	PrivateLength int
}
type Multikeypair []byte
func Encode(private []byte, public []byte, code uint64) (Multikeypair, error) {
	if err := validCode(code); err != nil {
		return Multikeypair{}, err
	}
	b := encodeKeypair(private, public, code)
	return Multikeypair(b), nil
}
func EncodeName(private []byte, public []byte, name string) (Multikeypair, error) {
	code := Names[name]
	return Encode(private, public, code)
}
func (k Keypair) Encode() (Multikeypair, error) {
	if err := validCode(k.Code); err != nil {
		return Multikeypair{}, err
	}
	return Encode(k.Private, k.Public, k.Code)
}
func validCode(code uint64) error {
	for k := range Codes {
		if k == code {
			return nil
		}
	}
	return ErrUnknownCode
}
func encodeKeypair(private []byte, public []byte, code uint64) []byte {
	codeBuf := PackCode(code)
	var b cryptobyte.Builder
	b.AddUint24LengthPrefixed(func(b *cryptobyte.Builder) {
		b.AddUint16LengthPrefixed(func(b *cryptobyte.Builder) {
			b.AddBytes(codeBuf)
		})
		b.AddUint16LengthPrefixed(func(b *cryptobyte.Builder) {
			b.AddBytes(private)
		})
		b.AddUint16LengthPrefixed(func(b *cryptobyte.Builder) {
			b.AddBytes(public)
		})
	})
	result, err := b.Bytes()
	if err != nil {
		panic(err)
	}
	return result
}
func Decode(m Multikeypair) (Keypair, error) {
	keypair, err := decodeKeypair([]byte(m))
	if err != nil {
		return Keypair{}, err
	}
	return *keypair, nil
}