Documentation ¶
Index ¶
- Constants
- func AutoExecuteActionEvent(ch chan DIDCommAction)
- type Action
- type DIDComm
- type DIDCommAction
- type DIDCommMsg
- type DIDCommMsgMap
- func (m DIDCommMsgMap) Clone() DIDCommMsgMap
- func (m DIDCommMsgMap) Decode(v interface{}) error
- func (m DIDCommMsgMap) ID() string
- func (m DIDCommMsgMap) MarshalJSON() ([]byte, error)
- func (m DIDCommMsgMap) Metadata() map[string]interface{}
- func (m DIDCommMsgMap) ParentThreadID() string
- func (m DIDCommMsgMap) SetID(id string) error
- func (m DIDCommMsgMap) ThreadID() (string, error)
- func (m DIDCommMsgMap) Type() string
- func (m *DIDCommMsgMap) UnmarshalJSON(b []byte) error
- type Destination
- type Empty
- type Event
- type EventProperties
- type Handler
- type InboundHandler
- type Message
- type Messenger
- type MessengerHandler
- type Metadata
- type NestedReplyOpts
- type OutboundHandler
- type StateMsg
- type StateMsgType
Constants ¶
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.
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 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 DIDCommMsg ¶
type DIDCommMsg interface { ID() string SetID(id string) error Type() string ThreadID() (string, error) ParentThreadID() string Clone() DIDCommMsgMap Metadata() map[string]interface{} Decode(v interface{}) error }
DIDCommMsg describes message interface.
type DIDCommMsgMap ¶
type DIDCommMsgMap map[string]interface{}
DIDCommMsgMap did comm msg.
func NewDIDCommMsgMap ¶
func NewDIDCommMsgMap(v interface{}) DIDCommMsgMap
NewDIDCommMsgMap converts structure(model) to DIDCommMsgMap.
func ParseDIDCommMsgMap ¶
func ParseDIDCommMsgMap(payload []byte) (DIDCommMsgMap, error)
ParseDIDCommMsgMap returns DIDCommMsg with Header.
func (DIDCommMsgMap) Clone ¶
func (m DIDCommMsgMap) Clone() DIDCommMsgMap
Clone copies first level keys-values into another map (DIDCommMsgMap).
func (DIDCommMsgMap) Decode ¶
func (m DIDCommMsgMap) Decode(v interface{}) error
Decode converts message to struct.
func (DIDCommMsgMap) MarshalJSON ¶
func (m DIDCommMsgMap) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (DIDCommMsgMap) Metadata ¶
func (m DIDCommMsgMap) Metadata() map[string]interface{}
Metadata returns message metadata.
func (DIDCommMsgMap) ParentThreadID ¶
func (m DIDCommMsgMap) ParentThreadID() string
ParentThreadID returns the message parent threadID.
func (DIDCommMsgMap) SetID ¶
func (m DIDCommMsgMap) SetID(id string) error
SetID sets the message id.
func (DIDCommMsgMap) ThreadID ¶
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) UnmarshalJSON ¶
func (m *DIDCommMsgMap) UnmarshalJSON(b []byte) error
UnmarshalJSON implements the json.Unmarshaler interface.
type Destination ¶
type Destination struct { RecipientKeys []string ServiceEndpoint string RoutingKeys []string TransportReturnRoute string }
Destination provides the recipientKeys, routingKeys, and serviceEndpoint for an outbound message.
func CreateDestination ¶
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 ¶
func GetDestination(did 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 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 ¶
type InboundHandler interface { // HandleInbound handles inbound messages. HandleInbound(msg DIDCommMsg, myDID, theirDID string) (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) RegisterMsgEvent ¶
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 ¶
UnregisterMsgEvent on protocol messages. Refer RegisterMsgEvent().
type Messenger ¶
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) 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) error // Send sends the message by starting a new thread. Send(msg DIDCommMsgMap, myDID, theirDID string) error // SendToDestination sends the message to given destination by starting a new thread. SendToDestination(msg DIDCommMsgMap, sender string, destination *Destination) 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 ¶
type MessengerHandler interface { Messenger // HandleInbound handles all inbound messages HandleInbound(msg DIDCommMsgMap, myDID, theirDID string) error }
MessengerHandler includes Messenger interface and Handle function to handle inbound messages.
type Metadata ¶
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 ¶
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 }
NestedReplyOpts options for performing `ReplyToNested` operation.
type OutboundHandler ¶
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 )