introduce

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: May 9, 2023 License: Apache-2.0 Imports: 7 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(WithPublicOOBInvitation(...))
      } else {
        // to share your out-of-band message (eg. request)
        event.Continue(WithOOBInvitation(...))
        // 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 SendProposalWithOOBInvitation functions should be used. SendProposalWithOOBInvitation is used in case if introducer has a public out-of-band invitation. 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 WithOOBInvitation added in v0.1.7

func WithOOBInvitation(req *outofband.Invitation, a ...*decorator.Attachment) introduce.Opt

WithOOBInvitation 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(WithOOBInvitation(inv)).

func WithPublicOOBInvitation added in v0.1.7

func WithPublicOOBInvitation(req *outofband.Invitation, to *To) introduce.Opt

WithPublicOOBInvitation 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(WithPublicOOBInvitation(req, to)).

func WithRecipients added in v0.1.2

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 added in v0.1.4

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 added in v0.1.4

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

AcceptProblemReport accepts problem report action.

func (*Client) AcceptProposal added in v0.1.2

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

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

func (*Client) AcceptProposalWithOOBInvitation added in v0.1.7

func (c *Client) AcceptProposalWithOOBInvitation(piID string, inv *outofband.Invitation) error

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

func (*Client) AcceptRequestWithPublicOOBInvitation added in v0.1.7

func (c *Client) AcceptRequestWithPublicOOBInvitation(piID string, inv *outofband.Invitation, to *To) error

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

func (*Client) AcceptRequestWithRecipients added in v0.1.2

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 added in v0.1.2

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

Actions returns unfinished actions for the async usage.

func (*Client) DeclineProposal added in v0.1.4

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

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

func (*Client) DeclineRequest added in v0.1.4

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(WithOOBInvitation(&outofband.Invitation{
				Type: outofband.InvitationMsgType,
			}))
		}
	}
}()

_, 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/out-of-band/1.0/invitation from Alice

func (*Client) SendProposalWithOOBInvitation added in v0.1.7

func (c *Client) SendProposalWithOOBInvitation(inv *outofband.Invitation, recipient *Recipient) (string, error)

SendProposalWithOOBInvitation 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.SendProposalWithOOBInvitation(
	&outofband.Invitation{
		Type: outofband.InvitationMsgType,
	},
	&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/out-of-band/1.0/invitation 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(WithOOBInvitation(&outofband.Invitation{
				Type: outofband.InvitationMsgType,
			}))
		}
	}
}()

_, 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/out-of-band/1.0/invitation 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(WithPublicOOBInvitation(&outofband.Invitation{
				Type: outofband.InvitationMsgType,
			}, &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/out-of-band/1.0/invitation from Alice

type PleaseIntroduceTo added in v0.1.4

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 added in v0.1.2

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 added in v0.1.4

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 added in v0.1.4

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