func PubKeyBytesToJWK(bytes []byte, keyType kms.KeyType) (*jwk.JWK, error) {  
	switch keyType {
	case kms.ED25519Type:
		return JWKFromKey(ed25519.PublicKey(bytes))
	case kms.BLS12381G2Type:
		bbsKey, err := bbs12381g2pub.UnmarshalPublicKey(bytes)
		if err != nil {
			return nil, err
		}
		return JWKFromKey(bbsKey)
	case kms.ECDSAP256TypeIEEEP1363, kms.ECDSAP384TypeIEEEP1363, kms.ECDSAP521TypeIEEEP1363:
		crv := getECDSACurve(keyType)
		x, y := elliptic.Unmarshal(crv, bytes)
		return JWKFromKey(&ecdsa.PublicKey{Curve: crv, X: x, Y: y})
	case kms.ECDSAP256TypeDER, kms.ECDSAP384TypeDER, kms.ECDSAP521TypeDER:
		pubKey, err := x509.ParsePKIXPublicKey(bytes)
		if err != nil {
			return nil, err
		}
		ecKey, ok := pubKey.(*ecdsa.PublicKey)
		if !ok {
			return nil, errors.New("invalid EC key")
		}
		return JWKFromKey(ecKey)
	case kms.NISTP256ECDHKWType, kms.NISTP384ECDHKWType, kms.NISTP521ECDHKWType:
		crv := getECDSACurve(keyType)
		pubKey := &cryptoapi.PublicKey{}
		err := json.Unmarshal(bytes, pubKey)
		if err != nil {
			return nil, err
		}
		ecdsaKey := &ecdsa.PublicKey{
			Curve: crv,
			X:     new(big.Int).SetBytes(pubKey.X),
			Y:     new(big.Int).SetBytes(pubKey.Y),
		}
		return JWKFromKey(ecdsaKey)
	case kms.X25519ECDHKWType:
		return JWKFromX25519Key(bytes)
	default:
		return nil, fmt.Errorf("convertPubKeyJWK: invalid key type: %s", keyType)
	}
}
PubKeyBytesToJWK converts marshalled bytes of keyType into JWK.
package jwksupport
import (
	"crypto/ecdsa"
	"crypto/ed25519"
	"crypto/elliptic"
	"crypto/x509"
	"encoding/json"
	"errors"
	"fmt"
	"math/big"
	"github.com/square/go-jose/v3"
	cryptoapi "github.com/hyperledger/aries-framework-go/pkg/crypto"
	"github.com/hyperledger/aries-framework-go/pkg/crypto/primitive/bbs12381g2pub"
	"github.com/hyperledger/aries-framework-go/pkg/doc/jose/jwk"
	"github.com/hyperledger/aries-framework-go/pkg/kms"
)
const (
	ecKty          = "EC"
	okpKty         = "OKP"
	x25519Crv      = "X25519"
	bls12381G2Crv  = "BLS12381_G2"
	bls12381G2Size = 96
)
func JWKFromKey(opaqueKey interface{}) (*jwk.JWK, error) {
	key := &jwk.JWK{
		JSONWebKey: jose.JSONWebKey{
			Key: opaqueKey,
		},
	}
	keyBytes, err := key.MarshalJSON()
	if err != nil {
		return nil, fmt.Errorf("create JWK: %w", err)
	}
	err = key.UnmarshalJSON(keyBytes)
	if err != nil {
		return nil, fmt.Errorf("create JWK: %w", err)
	}
	return key, nil
}
func JWKFromX25519Key(pubKey []byte) (*jwk.JWK, error) {
	key := &jwk.JWK{
		JSONWebKey: jose.JSONWebKey{
			Key: pubKey,
		},
		Crv: x25519Crv,
		Kty: okpKty,
	}
	keyBytes, err := key.MarshalJSON()
	if err != nil {
		return nil, fmt.Errorf("create JWK: %w", err)
	}
	err = key.UnmarshalJSON(keyBytes)
	if err != nil {
		return nil, fmt.Errorf("create JWK: %w", err)
	}
	return key, nil
}