func (s *Provider) DeleteReference(referenceType spi.ReferenceType, objectIRI, referenceIRI *url.URL) error {
	logger.Debugf("[%s] Deleting reference of type %s from object %s: %s",
		s.serviceName, referenceType, objectIRI, referenceIRI)
	referenceStore, exists := s.referenceStores[referenceType]
	if !exists {
		return fmt.Errorf("no store found for %s", string(referenceType))
	}
	err := referenceStore.Delete(objectIRI.String() + referenceIRI.String())
	if err != nil {
		return orberrors.NewTransient(fmt.Errorf("failed to delete reference: %w", err))
	}
	return nil
}
DeleteReference deletes the reference of the given type from the given object.
package ariesstore
import (
	"encoding/base64"
	"encoding/json"
	"errors"
	"fmt"
	"net/url"
	"strconv"
	"time"
	ariesstorage "github.com/hyperledger/aries-framework-go/spi/storage"
	"github.com/trustbloc/edge-core/pkg/log"
	"github.com/trustbloc/orb/pkg/activitypub/store/memstore"
	"github.com/trustbloc/orb/pkg/activitypub/store/spi"
	"github.com/trustbloc/orb/pkg/activitypub/store/storeutil"
	"github.com/trustbloc/orb/pkg/activitypub/vocab"
	orberrors "github.com/trustbloc/orb/pkg/errors"
)
const (
	activityTag         = "Activity"
	objectIRITagName    = "ObjectIRI"
	timeAddedTagName    = "TimeAdded"
	activityTypeTagName = "ActivityType"
)
var logger = log.New("activitypub_store")
type Provider struct {
	serviceName             string
	activityStore           ariesstorage.Store
	referenceStores         map[spi.ReferenceType]ariesstorage.Store
	actorStore              ariesstorage.Store
	multipleTagQueryCapable bool
}
func New(serviceName string, provider ariesstorage.Provider, multipleTagQueryCapable bool) (*Provider, error) {
	stores, err := openStores(provider)
	if err != nil {
		return nil, fmt.Errorf("failed to open stores: %w", err)
	}
	return &Provider{
		serviceName:             serviceName,
		activityStore:           stores.activities,
		referenceStores:         stores.reference,
		actorStore:              stores.actor,
		multipleTagQueryCapable: multipleTagQueryCapable,
	}, nil
}
func (s *Provider) PutActor(actor *vocab.ActorType) error {
	logger.Debugf("[%s] Storing actor [%s]", s.serviceName, actor.ID())
	actorBytes, err := json.Marshal(actor)
	if err != nil {
		return fmt.Errorf("failed to marshal actor: %w", err)
	}
	err = s.actorStore.Put(actor.ID().String(), actorBytes)
	if err != nil {
		return orberrors.NewTransient(fmt.Errorf("failed to store actor: %w", err))
	}
	return nil
}
func (s *Provider) GetActor(iri *url.URL) (*vocab.ActorType, error) {  
	logger.Debugf("[%s] Retrieving actor [%s]", s.serviceName, iri)
	actorBytes, err := s.actorStore.Get(iri.String())
	if err != nil {
		if errors.Is(err, ariesstorage.ErrDataNotFound) {
			return nil, spi.ErrNotFound
		}
		return nil,
			orberrors.NewTransient(fmt.Errorf("unexpected failure while getting actor from store: %w", err))
	}
	var actor vocab.ActorType
	err = json.Unmarshal(actorBytes, &actor)
	if err != nil {
		return nil, fmt.Errorf("failed to unmarshal actor bytes: %w", err)
	}
	return &actor, nil
}
func (s *Provider) AddActivity(activity *vocab.ActivityType) error {
	logger.Debugf("[%s] Storing activity - Type: %s, ID: %s",
		s.serviceName, activity.Type(), activity.ID())
	activityBytes, err := json.Marshal(activity)
	if err != nil {
		return fmt.Errorf("failed to marshal activity: %w", err)
	}
	err = s.activityStore.Put(activity.ID().String(), activityBytes,
		ariesstorage.Tag{
			Name: activityTag,
		}, ariesstorage.Tag{
			Name:  timeAddedTagName,
			Value: strconv.FormatInt(time.Now().UnixNano(), 10),
		})
	if err != nil {
		return orberrors.NewTransient(fmt.Errorf("failed to store activity: %w", err))
	}
	return nil
}
func (s *Provider) GetActivity(activityID *url.URL) (*vocab.ActivityType, error) {  
	logger.Debugf("[%s] Retrieving activity - ID: %s", s.serviceName, activityID)
	activityBytes, err := s.activityStore.Get(activityID.String())
	if err != nil {
		if errors.Is(err, ariesstorage.ErrDataNotFound) {
			return nil, spi.ErrNotFound
		}
		return nil,
			orberrors.NewTransient(fmt.Errorf("unexpected failure while getting activity from store: %w", err))
	}
	var activity vocab.ActivityType
	err = json.Unmarshal(activityBytes, &activity)
	if err != nil {
		return nil, fmt.Errorf("failed to unmarshal activity bytes: %w", err)
	}
	return &activity, nil
}
func (s *Provider) QueryActivities(query *spi.Criteria, opts ...spi.QueryOpt) (spi.ActivityIterator, error) {
	logger.Debugf("[%s] Querying activities - Query: %+v", s.serviceName, query)
	options := storeutil.GetQueryOptions(opts...)
	if query.ReferenceType != "" && query.ObjectIRI != nil {
		return s.queryActivitiesByRef(query.ReferenceType, query, opts...)
	}
	if len(query.ActivityIRIs) == 0 && len(query.Types) == 0 {  
		iterator, err := s.activityStore.Query(activityTag,
			ariesstorage.WithSortOrder(&ariesstorage.SortOptions{
				Order:   ariesstorage.SortOrder(options.SortOrder),
				TagName: timeAddedTagName,
			}),
			ariesstorage.WithPageSize(options.PageSize),
			ariesstorage.WithInitialPageNum(options.PageNumber))
		if err != nil {
			return nil, orberrors.NewTransient(fmt.Errorf("failed to query store: %w", err))
		}
		return &activityIterator{ariesIterator: iterator}, nil
	}
	return nil, errors.New("unsupported query criteria")
}
func (s *Provider) AddReference(referenceType spi.ReferenceType, objectIRI *url.URL, referenceIRI *url.URL,
	refMetaDataOpts ...spi.RefMetadataOpt) error {
	logger.Debugf("[%s] Adding reference of type %s to object %s: %s",
		s.serviceName, referenceType, objectIRI, referenceIRI)
	referenceStore, exists := s.referenceStores[referenceType]
	if !exists {
		return fmt.Errorf("no store found for %s", string(referenceType))
	}
	valueBytes, err := json.Marshal(referenceIRI.String())
	if err != nil {
		return fmt.Errorf("marshal: %w", err)
	}
	tags := determineTags(objectIRI, refMetaDataOpts)
	err = referenceStore.Put(objectIRI.String()+referenceIRI.String(), valueBytes, tags...)
	if err != nil {
		return orberrors.NewTransient(fmt.Errorf("failed to store reference: %w", err))
	}
	return nil
}