service

package
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2021 License: Apache-2.0 Imports: 11 Imported by: 99

Documentation

Index

Constants

View Source
const (
	ErrChannelRegistered = serviceError("channel is already registered for the action event")
	ErrNilChannel        = serviceError("cannot pass nil channel")
	ErrInvalidChannel    = serviceError("invalid channel passed to unregister the action event")
	ErrThreadIDNotFound  = serviceError("threadID not found")
	ErrInvalidMessage    = serviceError("invalid message")
	ErrNilMessage        = serviceError("message is nil")
)

Service errors.

View Source
const ForwardMsgType = "https://didcomm.org/routing/1.0/forward"

ForwardMsgType defines the route forward message type.

Variables

This section is empty.

Functions

func AutoExecuteActionEvent

func AutoExecuteActionEvent(ch chan DIDCommAction)

AutoExecuteActionEvent is a utility function to execute Action events automatically. The function requires a channel to be passed-in to listen to dispatcher.DIDCommAction and triggers the Continue function on the action event. This is a blocking function and use this function with a goroutine.

Usage:

 s := didexchange.New(....)
	actionCh := make(chan dispatcher.DIDCommAction)
	err = s.RegisterActionEvent(actionCh)
	go service.AutoExecuteActionEvent(actionCh)

Types

type Action

type Action struct {
	// contains filtered or unexported fields
}

Action thread-safe action register structure.

func (*Action) ActionEvent

func (a *Action) ActionEvent() chan<- DIDCommAction

ActionEvent returns event action channel.

func (*Action) RegisterActionEvent

func (a *Action) RegisterActionEvent(ch chan<- DIDCommAction) error

RegisterActionEvent on protocol messages. The consumer need to invoke the callback to resume processing. Only one channel can be registered for the action events. The function will throw error if a channel is already registered.

func (*Action) UnregisterActionEvent

func (a *Action) UnregisterActionEvent(ch chan<- DIDCommAction) error

UnregisterActionEvent on protocol messages. Refer RegisterActionEvent().

type DIDComm

type DIDComm interface {
	// service handler
	Handler
	// event service
	Event
}

DIDComm defines service APIs.

type DIDCommAction

type DIDCommAction struct {
	// Name of the protocol.
	//
	// Supported protocols
	//   - DID Exchange :  didexchange.DIDExchange
	ProtocolName string

	// DIDComm message
	Message DIDCommMsg

	// Continue function to be called by the consumer for further processing the message.
	Continue func(args interface{})

	// Stop invocation notifies the service that the consumer action event processing has failed or the consumer wants
	// to stop the processing.
	Stop func(err error)

	// Properties contains value based on specific protocol. The consumers need to call the protocol client
	// functions to get the data.
	//
	// Clients function to retrieve data based on protocol.
	//   - DID Exchange :  didexchange.EventProperties
	Properties EventProperties
}

DIDCommAction message type to pass events in go channels.

type DIDCommContext added in v0.1.7

type DIDCommContext interface {
	MyDID() string
	TheirDID() string
	EventProperties
}

DIDCommContext holds information on the context in which a DIDCommMsg is being processed.

func EmptyDIDCommContext added in v0.1.7

func EmptyDIDCommContext() DIDCommContext

EmptyDIDCommContext returns a DIDCommContext with no DIDs nor properties.

func NewDIDCommContext added in v0.1.7

func NewDIDCommContext(myDID, theirDID string, props map[string]interface{}) DIDCommContext

NewDIDCommContext returns a new DIDCommContext with the given DIDs and properties.

type DIDCommMsg

type DIDCommMsg interface {
	ID() string
	SetID(id string, opts ...Opt)
	SetThread(thid, pthid string, opts ...Opt)
	UnsetThread()
	Type() string
	ThreadID() (string, error)
	ParentThreadID() string
	Clone() DIDCommMsgMap
	Metadata() map[string]interface{}
	Decode(v interface{}) error
}

DIDCommMsg describes message interface.

type DIDCommMsgMap added in v0.1.1

type DIDCommMsgMap map[string]interface{}

DIDCommMsgMap did comm msg.

func NewDIDCommMsgMap added in v0.1.1

func NewDIDCommMsgMap(v interface{}) DIDCommMsgMap

NewDIDCommMsgMap converts structure(model) to DIDCommMsgMap.

func ParseDIDCommMsgMap added in v0.1.1

func ParseDIDCommMsgMap(payload []byte) (DIDCommMsgMap, error)

ParseDIDCommMsgMap returns DIDCommMsg with Header.

func (DIDCommMsgMap) Clone added in v0.1.2

func (m DIDCommMsgMap) Clone() DIDCommMsgMap

Clone copies first level keys-values into another map (DIDCommMsgMap).

func (DIDCommMsgMap) Decode added in v0.1.1

func (m DIDCommMsgMap) Decode(v interface{}) error

Decode converts message to struct.

func (DIDCommMsgMap) ID added in v0.1.1

func (m DIDCommMsgMap) ID() string

ID returns the message id.

func (DIDCommMsgMap) MarshalJSON added in v0.1.4

func (m DIDCommMsgMap) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (DIDCommMsgMap) Metadata added in v0.1.2

func (m DIDCommMsgMap) Metadata() map[string]interface{}

Metadata returns message metadata.

func (DIDCommMsgMap) ParentThreadID added in v0.1.2

func (m DIDCommMsgMap) ParentThreadID() string

ParentThreadID returns the message parent threadID.

func (DIDCommMsgMap) SetID added in v0.1.3

func (m DIDCommMsgMap) SetID(id string, opts ...Opt)

SetID sets the message id.

func (DIDCommMsgMap) SetThread added in v0.1.7

func (m DIDCommMsgMap) SetThread(thid, pthid string, opts ...Opt)

SetThread sets the message thread.

func (DIDCommMsgMap) ThreadID added in v0.1.1

func (m DIDCommMsgMap) ThreadID() (string, error)

ThreadID returns msg ~thread.thid if there is no ~thread.thid returns msg @id message is invalid if ~thread.thid exist and @id is absent.

func (DIDCommMsgMap) Type added in v0.1.1

func (m DIDCommMsgMap) Type() string

Type returns the message type.

func (*DIDCommMsgMap) UnmarshalJSON added in v0.1.4

func (m *DIDCommMsgMap) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (DIDCommMsgMap) UnsetThread added in v0.1.7

func (m DIDCommMsgMap) UnsetThread()

UnsetThread unsets thread.

type Destination

type Destination struct {
	RecipientKeys        []string
	ServiceEndpoint      string
	RoutingKeys          []string
	TransportReturnRoute string
	MediaTypeProfiles    []string
	DIDDoc               *did.Doc
}

Destination provides the recipientKeys, routingKeys, and serviceEndpoint for an outbound message.

func CreateDestination added in v0.1.1

func CreateDestination(didDoc *diddoc.Doc) (*Destination, error)

CreateDestination makes a DIDComm Destination object from a DID Doc as per the DIDComm service conventions: https://github.com/hyperledger/aries-rfcs/blob/master/features/0067-didcomm-diddoc-conventions/README.md.

func GetDestination added in v0.1.1

func GetDestination(didID string, vdr vdrapi.Registry) (*Destination, error)

GetDestination constructs a Destination struct based on the given DID and parameters It resolves the DID using the given VDR, and uses CreateDestination under the hood.

type Empty

type Empty struct{}

Empty is used if there are no arguments to Continue.

type Event

type Event interface {
	// RegisterActionEvent on protocol messages. The events are triggered for incoming message types based on
	// the protocol service. The consumer need to invoke the callback to resume processing.
	// Only one channel can be registered for the action events. The function will throw error if a channel is already
	// registered.
	RegisterActionEvent(ch chan<- DIDCommAction) error

	// UnregisterActionEvent on protocol messages. Refer RegisterActionEvent().
	UnregisterActionEvent(ch chan<- DIDCommAction) error

	// RegisterMsgEvent on protocol messages. The message events are triggered for incoming messages. Service
	// will not expect any callback on these events unlike Action event.
	RegisterMsgEvent(ch chan<- StateMsg) error

	// UnregisterMsgEvent on protocol messages. Refer RegisterMsgEvent().
	UnregisterMsgEvent(ch chan<- StateMsg) error
}

Event event related apis.

type EventProperties

type EventProperties interface {
	All() map[string]interface{}
}

EventProperties type for event related data. NOTE: Properties always should be serializable.

type Handler

type Handler interface {
	InboundHandler
	OutboundHandler
}

Handler provides protocol service handle api.

type InboundHandler added in v0.1.1

type InboundHandler interface {
	// HandleInbound handles inbound messages.
	HandleInbound(msg DIDCommMsg, ctx DIDCommContext) (string, error)
}

InboundHandler is handler for inbound messages.

type Message

type Message struct {
	// contains filtered or unexported fields
}

Message thread-safe message register structure.

func (*Message) MsgEvents

func (m *Message) MsgEvents() []chan<- StateMsg

MsgEvents returns event message channels.

func (*Message) RegisterMsgEvent

func (m *Message) RegisterMsgEvent(ch chan<- StateMsg) error

RegisterMsgEvent on protocol messages. The message events are triggered for incoming messages. Event will not expect any callback on these events unlike Action events.

func (*Message) UnregisterMsgEvent

func (m *Message) UnregisterMsgEvent(ch chan<- StateMsg) error

UnregisterMsgEvent on protocol messages. Refer RegisterMsgEvent().

type Messenger added in v0.1.1

type Messenger interface {
	// ReplyTo replies to the message by given msgID.
	// Keeps threadID in the *decorator.Thread.
	// Using this function means that communication will be on the same thread.
	//
	// Deprecated: Please do not use it anymore. The function can be removed in future release.
	ReplyTo(msgID string, msg DIDCommMsgMap, opts ...Opt) error

	// ReplyToMsg replies to the given message.
	// Keeps threadID in the *decorator.Thread.
	// Using this function means that communication will be on the same thread.
	ReplyToMsg(in, out DIDCommMsgMap, myDID, theirDID string, opts ...Opt) error

	// Send sends the message by starting a new thread.
	Send(msg DIDCommMsgMap, myDID, theirDID string, opts ...Opt) error

	// SendToDestination sends the message to given destination by starting a new thread.
	SendToDestination(msg DIDCommMsgMap, sender string, destination *Destination, opts ...Opt) error

	// ReplyToNested sends the message by starting a new thread.
	// Keeps parent threadID in the *decorator.Thread
	ReplyToNested(msg DIDCommMsgMap, opts *NestedReplyOpts) error
}

Messenger provides methods for the communication.

type MessengerHandler added in v0.1.1

type MessengerHandler interface {
	Messenger
	// HandleInbound handles all inbound messages
	HandleInbound(msg DIDCommMsgMap, ctx DIDCommContext) error
}

MessengerHandler includes Messenger interface and Handle function to handle inbound messages.

type Metadata added in v0.1.2

type Metadata struct {
	Payload map[string]interface{} `json:"_internal_metadata,omitempty"`
}

Metadata may contain additional payload for the protocol. It might be populated by the client/protocol for outbound messages. If metadata were populated, the messenger will automatically add it to the incoming messages by the threadID. If Metadata is <nil> in the outbound message the previous payload will be added to the incoming message. Otherwise, the payload will be rewritten. NOTE: Metadata is not a part of the JSON message. The payload will not be sent to another agent. Metadata should be used by embedding it to the model structure. e.g

type A struct {
	Metadata `json:",squash"`
}

type NestedReplyOpts added in v0.1.5

type NestedReplyOpts struct {
	// ThreadID is parent thread ID for nested reply,
	// if not provided then 'ThreadID' from message record will be used
	ThreadID string
	// MyDID for nested reply message,
	// if not provided then 'MyDID' from message record will be used
	MyDID string
	// TheirDID for nested reply message,
	// if not provided then 'TheirDID' from message record will be used
	TheirDID string
	// MsgID to which nested reply to be sent,
	// optional when all the above parameters are provided.
	//
	// Deprecated: Please do not use it anymore. The field can be removed in future release.
	MsgID string
	V     Version
}

NestedReplyOpts options for performing `ReplyToNested` operation.

type Opt added in v0.1.7

type Opt func(o *options)

Opt represents an option.

func WithVersion added in v0.1.7

func WithVersion(v Version) Opt

WithVersion specifies which version to use.

type OutboundHandler added in v0.1.1

type OutboundHandler interface {
	// HandleOutbound handles outbound messages.
	HandleOutbound(msg DIDCommMsg, myDID, theirDID string) (string, error)
}

OutboundHandler is handler for outbound messages.

type StateMsg

type StateMsg struct {
	// Name of the protocol.
	//
	// Supported protocols
	//   - DID Exchange :  didexchange.DIDExchange
	ProtocolName string

	// type of the message (pre or post), refer service.StateMsgType
	Type StateMsgType

	// current state. Refer protocol RFC for possible states.
	StateID string

	// DIDComm message along with message type
	Msg DIDCommMsg

	// Properties contains value based on specific protocol. The consumers need to call the protocol client
	// functions to get the data.
	//
	// Clients function to retrieve data based on protocol.
	//   - DID Exchange :  didexchange.Event
	Properties EventProperties
}

StateMsg is used in MsgEvent to pass the state details to the consumer. Refer service.Event.RegisterMsgEvent for more details.

type StateMsgType

type StateMsgType int

StateMsgType state msg type.

const (
	// PreState pre state.
	PreState StateMsgType = iota

	// PostState post state.
	PostState
)

type Version added in v0.1.7

type Version string

Version represents DIDComm protocol version.

const (
	V1 Version = "v1"
	V2 Version = "v2"
)

DIDComm versions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL