func (s *StoreImplementation) GetCredential(id string) (*verifiable.Credential, error) {
	vcBytes, err := s.store.Get(id)
	if err != nil {
		return nil, fmt.Errorf("failed to get vc: %w", err)
	}
	vc, err := verifiable.ParseCredential(vcBytes, verifiable.WithDisabledProofCheck(),
		verifiable.WithJSONLDDocumentLoader(s.documentLoader))
	if err != nil {
		return nil, fmt.Errorf("new credential failed: %w", err)
	}
	return vc, nil
}
GetCredential retrieves a verifiable credential based on ID.
package verifiable
import (
	"encoding/json"
	"errors"
	"fmt"
	"github.com/google/uuid"
	"github.com/piprate/json-gold/ld"
	"github.com/hyperledger/aries-framework-go/pkg/common/log"
	"github.com/hyperledger/aries-framework-go/pkg/doc/verifiable"
	"github.com/hyperledger/aries-framework-go/spi/storage"
)
const (
	NameSpace = "verifiable"
	credentialNameKey              = "vcname_"
	presentationNameKey            = "vpname_"
	credentialNameDataKeyPattern   = credentialNameKey + "%s"
	presentationNameDataKeyPattern = presentationNameKey + "%s"
)
var logger = log.New("aries-framework/store/verifiable")
type Opt func(o *options)
type options struct {
	MyDID    string
	TheirDID string
}
func WithMyDID(val string) Opt {
	return func(o *options) {
		o.MyDID = val
	}
}
func WithTheirDID(val string) Opt {
	return func(o *options) {
		o.TheirDID = val
	}
}
type Store interface {
	SaveCredential(name string, vc *verifiable.Credential, opts ...Opt) error
	SavePresentation(name string, vp *verifiable.Presentation, opts ...Opt) error
	GetCredential(id string) (*verifiable.Credential, error)
	GetPresentation(id string) (*verifiable.Presentation, error)
	GetCredentialIDByName(name string) (string, error)
	GetPresentationIDByName(name string) (string, error)
	GetCredentials() ([]*Record, error)
	GetPresentations() ([]*Record, error)
	RemoveCredentialByName(name string) error
	RemovePresentationByName(name string) error
}
type StoreImplementation struct {
	store          storage.Store
	documentLoader ld.DocumentLoader
}
type provider interface {
	StorageProvider() storage.Provider
	JSONLDDocumentLoader() ld.DocumentLoader
}
func New(ctx provider) (*StoreImplementation, error) {
	store, err := ctx.StorageProvider().OpenStore(NameSpace)
	if err != nil {
		return nil, fmt.Errorf("failed to open vc store: %w", err)
	}
	err = ctx.StorageProvider().SetStoreConfig(NameSpace,
		storage.StoreConfiguration{TagNames: []string{credentialNameKey, presentationNameKey}})
	if err != nil {
		return nil, fmt.Errorf("failed to set store configuration: %w", err)
	}
	return &StoreImplementation{
		store:          store,
		documentLoader: ctx.JSONLDDocumentLoader(),
	}, nil
}
func (s *StoreImplementation) SaveCredential(name string, vc *verifiable.Credential, opts ...Opt) error {
	if name == "" {
		return errors.New("credential name is mandatory")
	}
	id, err := s.GetCredentialIDByName(name)
	if err != nil && !errors.Is(err, storage.ErrDataNotFound) {
		return fmt.Errorf("get credential id using name : %w", err)
	}
	if id != "" {
		return errors.New("credential name already exists")
	}
	vcBytes, err := vc.MarshalJSON()
	if err != nil {
		return fmt.Errorf("failed to marshal vc: %w", err)
	}
	id = vc.ID
	if id == "" {
		id = uuid.New().String()
	}
	if e := s.store.Put(id, vcBytes); e != nil {
		return fmt.Errorf("failed to put vc: %w", e)
	}
	o := &options{}
	for _, opt := range opts {
		opt(o)
	}
	recordBytes, err := json.Marshal(&Record{
		ID:        id,
		Name:      name,
		Context:   vc.Context,
		Type:      vc.Types,
		MyDID:     o.MyDID,
		TheirDID:  o.TheirDID,
		SubjectID: getVCSubjectID(vc),
	})
	if err != nil {
		return fmt.Errorf("failed to marshal record: %w", err)
	}
	return s.store.Put(credentialNameDataKey(name), recordBytes, storage.Tag{Name: credentialNameKey})
}
func (s *StoreImplementation) SavePresentation(name string, vp *verifiable.Presentation, opts ...Opt) error {
	if name == "" {
		return errors.New("presentation name is mandatory")
	}
	id, err := s.GetPresentationIDByName(name)
	if err != nil && !errors.Is(err, storage.ErrDataNotFound) {
		return fmt.Errorf("get presentation id using name : %w", err)
	}
	if id != "" {
		return errors.New("presentation name already exists")
	}
	vpBytes, err := vp.MarshalJSON()
	if err != nil {
		return fmt.Errorf("failed to marshal vp: %w", err)
	}
	id = vp.ID
	if id == "" {
		id = uuid.New().String()
	}
	o := &options{}
	for _, opt := range opts {
		opt(o)
	}
	recordBytes, err := json.Marshal(&Record{
		ID:        id,
		Name:      name,
		Context:   vp.Context,
		Type:      vp.Type,
		MyDID:     o.MyDID,
		TheirDID:  o.TheirDID,
		SubjectID: vp.Holder,
	})
	if err != nil {
		return fmt.Errorf("failed to marshal record: %w", err)
	}
	if err := s.store.Put(id, vpBytes); err != nil {
		return fmt.Errorf("failed to put vp: %w", err)
	}
	return s.store.Put(presentationNameDataKey(name), recordBytes, storage.Tag{Name: presentationNameKey})
}