github.com/hyperledger/aries-framework-go@v0.3.2/pkg/didcomm/packer/api.go (about)

     1  /*
     2  Copyright SecureKey Technologies Inc. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package packer
     8  
     9  import (
    10  	cryptoapi "github.com/hyperledger/aries-framework-go/pkg/crypto"
    11  	"github.com/hyperledger/aries-framework-go/pkg/didcomm/transport"
    12  	vdrapi "github.com/hyperledger/aries-framework-go/pkg/framework/aries/api/vdr"
    13  	"github.com/hyperledger/aries-framework-go/pkg/kms"
    14  	"github.com/hyperledger/aries-framework-go/spi/storage"
    15  )
    16  
    17  const (
    18  	// EnvelopeEncodingTypeV2 is the default JWE `typ` protected header value as per:
    19  	// https://identity.foundation/didcomm-messaging/spec/#didcomm-encrypted-message
    20  	// and
    21  	//nolint:lll
    22  	// https://github.com/hyperledger/aries-rfcs/blob/master/features/0044-didcomm-file-and-mime-types/README.md#detecting-didcomm-versions
    23  	// for DIDComm compliance.
    24  	EnvelopeEncodingTypeV2 = "application/didcomm-encrypted+json"
    25  
    26  	// ContentEncodingTypeV1 is the old `cty` protected header value, added to maintain backward compatibility as per:
    27  	// https://github.com/hyperledger/aries-rfcs/tree/master/features/0587-encryption-envelope-v2#didcomm-v2-transition.
    28  	ContentEncodingTypeV1 = "application/json;flavor=didcomm-msg"
    29  	// ContentEncodingTypeV2 is the default JWE `cty` protected header.
    30  	ContentEncodingTypeV2 = "application/didcomm-plain+json"
    31  )
    32  
    33  // Provider interface for Packer ctx.
    34  type Provider interface {
    35  	KMS() kms.KeyManager
    36  	Crypto() cryptoapi.Crypto
    37  	StorageProvider() storage.Provider
    38  	VDRegistry() vdrapi.Registry
    39  }
    40  
    41  // Creator method to create new Packer service.
    42  type Creator func(prov Provider) (Packer, error)
    43  
    44  // Packer is an Aries envelope packer/unpacker to support
    45  // secure DIDComm exchange of envelopes between Aries agents.
    46  type Packer interface {
    47  	// Pack a payload of type ContentType in an Aries compliant format using the sender keypair
    48  	// and a list of recipients public keys
    49  	// returns:
    50  	// 		[]byte containing the encrypted envelope
    51  	//		error if encryption failed
    52  	Pack(contentType string, payload []byte, senderKey []byte, recipients [][]byte) ([]byte, error)
    53  	// Unpack an envelope in an Aries compliant format.
    54  	// 		The recipient's key will be the one found in KMS that matches one of the list of recipients in the envelope
    55  	//
    56  	// returns:
    57  	// 		Envelope containing the message, decryption key, and sender key
    58  	//		error if decryption failed
    59  	Unpack(envelope []byte) (*transport.Envelope, error)
    60  
    61  	// EncodingType returns the type of the encoding, as found in the protected header 'typ' field
    62  	EncodingType() string
    63  }