introduce

package
v0.1.6-0...-5c25bcb Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

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. The example below shows how to use the client.

introduce := client.New(...)
introduce.RegisterActionEvent(actions)
for {
  select {
    case event := <-actions:
      if event.Message.Type() == introduce.RequestMsgType {
        // if you want to accept request and you do not have a public out-of-band message
        event.Continue(WithRecipients(...))
        // or you have a public out-of-band message (eg. request)
        event.Continue(WithPublicOOBRequest(...))
      } else {
        // to share your out-of-band message (eg. request)
        event.Continue(WithOOBRequest(...))
        // or if you do not want to share your out-of-band message
        event.Continue(nil)
      }
  }
}

Possible use cases: 1) The introducer wants to commit an introduction. To do that SendProposal or SendProposalWithOOBRequest functions should be used. SendProposalWithOOBRequest is used in case if introducer has a public out-of-band request. Otherwise, SendProposal function is used. A request, 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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithOOBRequest

func WithOOBRequest(req *outofband.Request, a ...*decorator.Attachment) introduce.Opt

WithOOBRequest is used when introducee wants to provide an out-of-band request with an optional series of attachments. NOTE: Introducee can provide the request only after receiving ProposalMsgType USAGE: event.Continue(WithOOBRequest(inv)).

func WithPublicOOBRequest

func WithPublicOOBRequest(req *outofband.Request, to *To) introduce.Opt

WithPublicOOBRequest is used when introducer wants to provide a published out-of-band request. NOTE: Introducer can provide this request only after receiving RequestMsgType USAGE: event.Continue(WithPublicOOBRequest(req, to)).

func WithRecipients

func WithRecipients(to *To, recipient *Recipient) introduce.Opt

WithRecipients is used when the introducer does not have a published out-of-band message on hand but he is willing to introduce agents to each other. NOTE: Introducer can provide recipients only after receiving RequestMsgType. USAGE: event.Continue(WithRecipients(to, recipient)).

Types

type Action

type Action introduce.Action

Action contains helpful information about action.

type Client

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

Client enable access to introduce API.

func New

func New(ctx Provider) (*Client, error)

New return new instance of introduce client.

func (*Client) AcceptProblemReport

func (c *Client) AcceptProblemReport(piID string) error

AcceptProblemReport accepts problem report action.

func (*Client) AcceptProposal

func (c *Client) AcceptProposal(piID string) error

AcceptProposal is used when introducee wants to accept a proposal without providing a OOBRequest.

func (*Client) AcceptProposalWithOOBRequest

func (c *Client) AcceptProposalWithOOBRequest(piID string, req *outofband.Request) error

AcceptProposalWithOOBRequest is used when introducee wants to provide an out-of-band request. Introducee can provide this request only after receiving ProposalMsgType.

func (*Client) AcceptRequestWithPublicOOBRequest

func (c *Client) AcceptRequestWithPublicOOBRequest(piID string, req *outofband.Request, to *To) error

AcceptRequestWithPublicOOBRequest is used when introducer wants to provide a published out-of-band request. Introducer can provide invitation only after receiving RequestMsgType.

func (*Client) AcceptRequestWithRecipients

func (c *Client) AcceptRequestWithRecipients(piID string, to *To, recipient *Recipient) error

AcceptRequestWithRecipients is used when the introducer does not have a published out-of-band message on hand but he is willing to introduce agents to each other. Introducer can provide recipients only after receiving RequestMsgType.

func (*Client) Actions

func (c *Client) Actions() ([]Action, error)

Actions returns unfinished actions for the async usage.

func (*Client) DeclineProposal

func (c *Client) DeclineProposal(piID, reason string) error

DeclineProposal is used to reject the proposal. NOTE: For async usage.

func (*Client) DeclineRequest

func (c *Client) DeclineRequest(piID, reason string) error

DeclineRequest is used to reject the request. NOTE: For async usage.

func (*Client) SendProposal

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

SendProposal sends a proposal to the introducees (the client has not published an out-of-band message).

Example

nolint: gocyclo

transport := map[string]chan payload{
	Alice: make(chan payload),
	Bob:   make(chan payload),
	Carol: make(chan payload),
}

done := make(chan struct{})

// Alice creates client
clientAlice, err := New(mockContext(Alice, transport, done))
if err != nil {
	panic(err)
}

// Alice registers channel for actions
actionsAlice := make(chan service.DIDCommAction)

err = clientAlice.RegisterActionEvent(actionsAlice)
if err != nil {
	panic(err)
}

// Bob creates client
clientBob, err := New(mockContext(Bob, transport, done))
if err != nil {
	panic(err)
}

// Bob registers channel for actions
actionsBob := make(chan service.DIDCommAction)

err = clientBob.RegisterActionEvent(actionsBob)
if err != nil {
	panic(err)
}

// Bob creates client
clientCarol, err := New(mockContext(Carol, transport, done))
if err != nil {
	panic(err)
}

// Carol registers channel for actions
actionsCarol := make(chan service.DIDCommAction)

err = clientCarol.RegisterActionEvent(actionsCarol)
if err != nil {
	panic(err)
}

go func() {
	for {
		select {
		case e := <-actionsAlice:
			e.Continue(nil)
		case e := <-actionsBob:
			e.Continue(nil)
		case e := <-actionsCarol:
			e.Continue(WithOOBRequest(&outofband.Request{
				Type: outofband.RequestMsgType,
			}))
		}
	}
}()

_, err = clientAlice.SendProposal(
	&Recipient{
		MyDID:    Alice,
		TheirDID: Bob,
	},
	&Recipient{
		MyDID:    Alice,
		TheirDID: Carol,
	},
)

if err != nil {
	fmt.Println(err)
}

<-done
Output:

Bob received https://didcomm.org/introduce/1.0/proposal from Alice
Alice received https://didcomm.org/introduce/1.0/response from Bob
Carol received https://didcomm.org/introduce/1.0/proposal from Alice
Alice received https://didcomm.org/introduce/1.0/response from Carol
Bob received https://didcomm.org/oob-request/1.0/request from Alice

func (*Client) SendProposalWithOOBRequest

func (c *Client) SendProposalWithOOBRequest(req *outofband.Request, recipient *Recipient) (string, error)

SendProposalWithOOBRequest sends a proposal to the introducee (the client has published an out-of-band request).

Example
transport := map[string]chan payload{
	Alice: make(chan payload),
	Bob:   make(chan payload),
}

done := make(chan struct{})

// Alice creates client
clientAlice, err := New(mockContext(Alice, transport, done))
if err != nil {
	panic(err)
}

// Alice registers channel for actions
actionsAlice := make(chan service.DIDCommAction)

err = clientAlice.RegisterActionEvent(actionsAlice)
if err != nil {
	panic(err)
}

// Bob creates client
clientBob, err := New(mockContext(Bob, transport, done))
if err != nil {
	panic(err)
}

// Bob registers channel for actions
actionsBob := make(chan service.DIDCommAction)

err = clientBob.RegisterActionEvent(actionsBob)
if err != nil {
	panic(err)
}

go func() {
	for {
		select {
		case e := <-actionsAlice:
			e.Continue(nil)
		case e := <-actionsBob:
			e.Continue(nil)
		}
	}
}()

_, err = clientAlice.SendProposalWithOOBRequest(
	&outofband.Request{
		Type: outofband.RequestMsgType,
	},
	&Recipient{
		MyDID:    Alice,
		TheirDID: Bob,
	},
)

if err != nil {
	fmt.Println(err)
}

<-done
Output:

Bob received https://didcomm.org/introduce/1.0/proposal from Alice
Alice received https://didcomm.org/introduce/1.0/response from Bob
Bob received https://didcomm.org/oob-request/1.0/request from Alice

func (*Client) SendRequest

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

SendRequest sends a request. Sending a request means that the introducee is willing to share their own out-of-band message.

Example

nolint: gocyclo

transport := map[string]chan payload{
	Alice: make(chan payload),
	Bob:   make(chan payload),
	Carol: make(chan payload),
}

done := make(chan struct{})

// Alice creates client
clientAlice, err := New(mockContext(Alice, transport, done))
if err != nil {
	panic(err)
}

// Alice registers channel for actions
actionsAlice := make(chan service.DIDCommAction)

err = clientAlice.RegisterActionEvent(actionsAlice)
if err != nil {
	panic(err)
}

// Bob creates client
clientBob, err := New(mockContext(Bob, transport, done))
if err != nil {
	panic(err)
}

// Bob registers channel for actions
actionsBob := make(chan service.DIDCommAction)

err = clientBob.RegisterActionEvent(actionsBob)
if err != nil {
	panic(err)
}

// Bob creates client
clientCarol, err := New(mockContext(Carol, transport, done))
if err != nil {
	panic(err)
}

// Carol registers channel for actions
actionsCarol := make(chan service.DIDCommAction)

err = clientCarol.RegisterActionEvent(actionsCarol)
if err != nil {
	panic(err)
}

go func() {
	for {
		select {
		case e := <-actionsAlice:
			e.Continue(WithRecipients(&To{Name: Carol}, &Recipient{
				To:       &introduce.To{Name: Bob},
				MyDID:    Alice,
				TheirDID: Carol,
			}))
		case e := <-actionsBob:
			e.Continue(nil)
		case e := <-actionsCarol:
			e.Continue(WithOOBRequest(&outofband.Request{
				Type: outofband.RequestMsgType,
			}))
		}
	}
}()

_, err = clientBob.SendRequest(
	&PleaseIntroduceTo{
		To: introduce.To{Name: Carol},
	},
	Bob, Alice,
)

if err != nil {
	fmt.Println(err)
}

<-done
Output:

Alice received https://didcomm.org/introduce/1.0/request from Bob
Bob received https://didcomm.org/introduce/1.0/proposal from Alice
Alice received https://didcomm.org/introduce/1.0/response from Bob
Carol received https://didcomm.org/introduce/1.0/proposal from Alice
Alice received https://didcomm.org/introduce/1.0/response from Carol
Bob received https://didcomm.org/oob-request/1.0/request from Alice
Example (Second)
transport := map[string]chan payload{
	Alice: make(chan payload),
	Bob:   make(chan payload),
	Carol: make(chan payload),
}

done := make(chan struct{})

// Alice creates client
clientAlice, err := New(mockContext(Alice, transport, done))
if err != nil {
	panic(err)
}

// Alice registers channel for actions
actionsAlice := make(chan service.DIDCommAction)

err = clientAlice.RegisterActionEvent(actionsAlice)
if err != nil {
	panic(err)
}

// Bob creates client
clientBob, err := New(mockContext(Bob, transport, done))
if err != nil {
	panic(err)
}

// Bob registers channel for actions
actionsBob := make(chan service.DIDCommAction)

err = clientBob.RegisterActionEvent(actionsBob)
if err != nil {
	panic(err)
}

go func() {
	for {
		select {
		case e := <-actionsAlice:
			e.Continue(WithPublicOOBRequest(&outofband.Request{
				Type: outofband.RequestMsgType,
			}, &To{Name: Carol}))
		case e := <-actionsBob:
			e.Continue(nil)
		}
	}
}()

_, err = clientBob.SendRequest(
	&PleaseIntroduceTo{
		To: introduce.To{Name: Carol},
	},
	Bob, Alice,
)

if err != nil {
	fmt.Println(err)
}

<-done
Output:

Alice received https://didcomm.org/introduce/1.0/request from Bob
Bob received https://didcomm.org/introduce/1.0/proposal from Alice
Alice received https://didcomm.org/introduce/1.0/response from Bob
Bob received https://didcomm.org/oob-request/1.0/request from Alice

type PleaseIntroduceTo

type PleaseIntroduceTo introduce.PleaseIntroduceTo

PleaseIntroduceTo includes all field from To structure also it has Discovered the field which should be provided by help-me-discover protocol.

type ProtocolService

type ProtocolService interface {
	service.DIDComm
	Actions() ([]introduce.Action, error)
	ActionContinue(piID string, opt introduce.Opt) error
	ActionStop(piID string, err error) error
}

ProtocolService defines the introduce service.

type Provider

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

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

type Recipient

type Recipient introduce.Recipient

Recipient keeps information needed for the service 'To' field is needed for the proposal message 'MyDID' and 'TheirDID' fields are needed for sending messages e.g report-problem, proposal, ack etc.

type To

type To introduce.To

To introducee descriptor keeps information about the introduction.

Jump to

Keyboard shortcuts

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