introduce

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2020 License: Apache-2.0 Imports: 9 Imported by: 3

Documentation

Overview

Package introduce is responsible for the introduction between agents. The protocol involves at least two participants. A maximum of three participants is currently supported. When creating a client a default invitation might be provided. It simplifies the usage when someone wants to do introduction with your client. The simplest way to handle incoming messages (actions) is:

introduce := client.New(...)
introduce.RegisterActionEvent(actions)
for {
  select {
    case event := <-actions:
      thID, _ := event.Message.ThreadID()
      event.Continue(introduce.InvitationEnvelope(thID))
  }
}

But also there is an exception, when receiving a request. After receiving a request one of the following functions must be executed. - HandleRequest - is used when you do not have a public invitation and it should be provided by one of the introducees. - HandleRequestWithInvitation - is used when you have a public invitation. A bit complicated way to handle incoming messages (actions) is:

introduce := client.New(...)
introduce.RegisterActionEvent(actions)
for {
  select {
    case event := <-actions:
      if event.Message.Type() == introduce.RequestMsgType {
        introduce.HandleRequest(event.Message, to, recipient)
        OR
        introduce.HandleRequestWithInvitation(event.Message, inv, to)
      }
      thID, _ := event.Message.ThreadID()
      event.Continue(introduce.InvitationEnvelope(thID))
  }
}

Possible use cases: 1) The introducer wants to commit an introduction. To do that SendProposal or SendProposalWithInvitation functions should be used. SendProposalWithInvitation is used in case if introducer has a public invitation. Otherwise, SendProposal function is used. An invitation, in that case, should be provided by one of the introducees. 2) Introducee asks the introducer about the agent. SendRequest function is used to do that.

Basic Flow:
1) Prepare client context
2) Create client
3) Register for action events
4) Handle actions
5) Send proposal

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	service.Event
	// contains filtered or unexported fields
}

Client enable access to introduce API

func New

func New(ctx Provider, inv *didexchange.Invitation) (*Client, error)

New return new instance of introduce client

func (*Client) HandleRequest

func (c *Client) HandleRequest(msg service.DIDCommMsg, to *introduce.To, recipient *introduce.Recipient) error

HandleRequest is a helper function to prepare the right protocol dependency interface. It can be executed after receiving a Request action message (the client does not have a public Invitation)

func (*Client) HandleRequestWithInvitation

func (c *Client) HandleRequestWithInvitation(msg service.DIDCommMsg,
	inv *didexchange.Invitation, to *introduce.To) error

HandleRequestWithInvitation is a helper function to prepare the right protocol dependency interface. It can be executed after receiving a Request action message (the client has a public Invitation)

func (*Client) InvitationEnvelope added in v0.1.1

func (c *Client) InvitationEnvelope(thID string) *InvitationEnvelope

InvitationEnvelope is a helper function that returns the dependency needed for the service to proceed with the protocol. Dependency should be passed to the service through `Continue` function. The function should never return an error. Instead of an error we provide a callable interface and a state machine that will act according to the provided data. Dependency is populated after executing the following functions:

  • SendProposal
  • SendProposalWithInvitation
  • HandleRequest
  • HandleRequestWithInvitation

usage: e.Continue(c.InvitationEnvelope(threadID))

func (*Client) SendProposal

func (c *Client) SendProposal(recipient1, recipient2 *introduce.Recipient) error

SendProposal sends a proposal to the introducees (the client does not have a public Invitation).

func (*Client) SendProposalWithInvitation

func (c *Client) SendProposalWithInvitation(inv *didexchange.Invitation, recipient *introduce.Recipient) error

SendProposalWithInvitation sends a proposal to the introducee (the client has a public Invitation).

func (*Client) SendRequest

func (c *Client) SendRequest(to *introduce.PleaseIntroduceTo, myDID, theirDID string) error

SendRequest sends a request. Sending a request means that the introducee is willing to share its invitation.

type InvitationEnvelope added in v0.1.1

type InvitationEnvelope struct {
	// Invitation must be set when we have a public Invitation
	Inv *didexchange.Invitation `json:"invitation,omitempty"`
	// Recipients contain one or two elements
	// one element - for the public Invitation, otherwise two elements
	Recps []*introduce.Recipient `json:"recipients,omitempty"`
}

InvitationEnvelope keeps the information needed for sending a proposal

func (*InvitationEnvelope) Invitation added in v0.1.1

func (o *InvitationEnvelope) Invitation() *didexchange.Invitation

Invitation returns an Invitation needed for the service (state machine depends on it)

func (*InvitationEnvelope) Recipients added in v0.1.1

func (o *InvitationEnvelope) Recipients() []*introduce.Recipient

Recipients returns data needed for the service (state machine depends on it)

type Provider

type Provider interface {
	Service(id string) (interface{}, error)
	StorageProvider() storage.Provider
}

Provider contains dependencies for the introduce protocol and is typically created by using aries.Context()

Jump to

Keyboard shortcuts

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