introduce

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 6, 2020 License: Apache-2.0 Imports: 6 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. 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 added in v0.1.3

func WithOOBRequest(req *outofband.Request) introduce.Opt

WithOOBRequest is used when introducee wants to provide invitation. NOTE: Introducee can provide invitation only after receiving ProposalMsgType USAGE: event.Continue(WithOOBRequest(inv))

func WithPublicOOBRequest added in v0.1.3

func WithPublicOOBRequest(req *outofband.Request, to *introduce.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 added in v0.1.2

func WithRecipients(to *introduce.To, recipient *introduce.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 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) AcceptProposalWithOOBRequest added in v0.1.3

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

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

func (*Client) AcceptRequestWithPublicOOBRequest added in v0.1.3

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

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

func (*Client) AcceptRequestWithRecipients added in v0.1.2

func (c *Client) AcceptRequestWithRecipients(piID string, to *introduce.To, recipient *introduce.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. NOTE: For async usage. Introducer can provide recipients only after receiving RequestMsgType.

func (*Client) Actions added in v0.1.2

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

Actions returns unfinished actions for the async usage

func (*Client) SendProposal

func (c *Client) SendProposal(recipient1, recipient2 *introduce.Recipient) 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),
}

var 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(
	&introduce.Recipient{
		MyDID:    Alice,
		TheirDID: Bob,
	},
	&introduce.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 added in v0.1.3

func (c *Client) SendProposalWithOOBRequest(req *outofband.Request, recipient *introduce.Recipient) 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),
}

var 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,
	},
	&introduce.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 *introduce.PleaseIntroduceTo, myDID, theirDID 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),
}

var 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(&introduce.To{Name: Carol}, &introduce.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(
	&introduce.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),
}

var 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,
			}, &introduce.To{Name: Carol}))
		case e := <-actionsBob:
			e.Continue(nil)
		}
	}
}()

err = clientBob.SendRequest(
	&introduce.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 ProtocolService added in v0.1.2

type ProtocolService interface {
	service.DIDComm
	Continue(piID string, opt introduce.Opt) error
	Actions() ([]introduce.Action, 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()

Jump to

Keyboard shortcuts

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