github.com/hyperledger/aries-framework-go@v0.3.2/pkg/didcomm/protocol/introduce/metadata.go (about)

     1  /*
     2  Copyright SecureKey Technologies Inc. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package introduce
     8  
     9  import (
    10  	"github.com/google/uuid"
    11  
    12  	"github.com/hyperledger/aries-framework-go/pkg/didcomm/common/service"
    13  	"github.com/hyperledger/aries-framework-go/pkg/didcomm/protocol/decorator"
    14  	"github.com/hyperledger/aries-framework-go/pkg/didcomm/protocol/outofband"
    15  )
    16  
    17  const (
    18  	// protocol instance ID.
    19  	metaPIID         = Introduce + "_pi_id"
    20  	metaSkipProposal = Introduce + "_skip_proposal"
    21  	metaOOBMessage   = Introduce + "_oobmessage"
    22  	metaRecipients   = Introduce + "_recipients"
    23  	metaAttachment   = Introduce + "_attachment"
    24  )
    25  
    26  // Opt describes option signature for the Continue function.
    27  type Opt func(m map[string]interface{})
    28  
    29  // WithOOBInvitation is used when introducee wants to provide an out-of-band request.
    30  // NOTE: Introducee can provide this request only after receiving ProposalMsgType
    31  // USAGE: event.Continue(WithOOBInvitation(req)).
    32  func WithOOBInvitation(inv *outofband.Invitation, attachments ...*decorator.Attachment) Opt {
    33  	return func(m map[string]interface{}) {
    34  		m[metaOOBMessage] = service.NewDIDCommMsgMap(inv)
    35  		m[metaAttachment] = attachments
    36  	}
    37  }
    38  
    39  // WithPublicOOBInvitation is used when introducer wants to provide public an out-of-band request.
    40  // NOTE: Introducer can provide this request only after receiving RequestMsgType
    41  // USAGE: event.Continue(WithPublicOOBInvitation(req, to)).
    42  func WithPublicOOBInvitation(inv *outofband.Invitation, to *To) Opt {
    43  	return func(m map[string]interface{}) {
    44  		m[metaOOBMessage] = service.NewDIDCommMsgMap(inv)
    45  		m[metaSkipProposal] = true
    46  		m[metaRecipients] = []interface{}{&Recipient{
    47  			To: to,
    48  		}}
    49  	}
    50  }
    51  
    52  // WithRecipients is used when the introducer does not have a public invitation
    53  // but he is willing to introduce agents to each other.
    54  // NOTE: Introducer can provide recipients only after receiving RequestMsgType.
    55  // USAGE: event.Continue(WithRecipients(to, recipient)).
    56  func WithRecipients(to *To, recipient *Recipient) Opt {
    57  	return func(m map[string]interface{}) {
    58  		m[metaRecipients] = []interface{}{
    59  			&Recipient{To: to}, recipient,
    60  		}
    61  	}
    62  }
    63  
    64  // WrapWithMetadataPIID wraps message with metadata.
    65  // The function is used by the introduce client to define that a few messages are related to each other.
    66  // e.g When two proposals are sent simultaneously piID helps the protocol to determine that messages are related.
    67  func WrapWithMetadataPIID(msgMap ...service.DIDCommMsg) {
    68  	piID := uuid.New().String()
    69  
    70  	for _, msg := range msgMap {
    71  		msg.Metadata()[metaPIID] = piID
    72  	}
    73  }
    74  
    75  // WrapWithMetadataPublicOOBInvitation wraps message with metadata.
    76  // The function is used by the introduce client to define skip proposal.
    77  // It also saves invitation and will provide it later to the introducee.
    78  func WrapWithMetadataPublicOOBInvitation(msg service.DIDCommMsgMap, req *outofband.Invitation) {
    79  	msg.Metadata()[metaOOBMessage] = service.NewDIDCommMsgMap(req)
    80  	msg.Metadata()[metaSkipProposal] = true
    81  }
    82  
    83  func copyMetadata(from, to service.DIDCommMsg) {
    84  	for k, v := range from.Metadata() {
    85  		to.Metadata()[k] = v
    86  	}
    87  }