presentproof

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: BSD-2-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package presentproof implements the DIDComm present-proof protocol 3.0. This protocol enables requesting and presenting verifiable credentials and presentations between DIDComm agents.

Protocol URI: https://didcomm.org/present-proof/3.0

Message flow:

  1. Verifier sends request-presentation to Holder
  2. Holder sends presentation to Verifier OR
  3. Holder sends propose-presentation to negotiate what to present

See: https://identity.foundation/didcomm-messaging/spec/

Index

Constants

View Source
const (
	// Protocol identifier
	ProtocolURI = "https://didcomm.org/present-proof/3.0"

	// Message types
	TypeProposePresentation = ProtocolURI + "/propose-presentation"
	TypeRequestPresentation = ProtocolURI + "/request-presentation"
	TypePresentation        = ProtocolURI + "/presentation"
	TypePresentationAck     = ProtocolURI + "/ack"
	TypePresentationProblem = ProtocolURI + "/problem-report"

	// Attachment formats
	FormatDIFPresentationExchange   = "dif/presentation-exchange/definitions@v2.0"
	FormatDIFPresentationSubmission = "dif/presentation-exchange/submission@v2.0"
	FormatW3CVC                     = "w3c/vc@v2.0"
	FormatW3CVP                     = "w3c/vp@v2.0"

	// MediaTypeJSON is the standard JSON media type for attachments.
	MediaTypeJSON = "application/json"
)

Variables

This section is empty.

Functions

func NewPresentation

func NewPresentation(request *message.Message, vp json.RawMessage, opts ...RequestOption) (*message.Message, error)

NewPresentation creates a new presentation message in response to a request. The vp should be a W3C Verifiable Presentation (JSON).

func NewProposePresentation

func NewProposePresentation(from, to string, proposal json.RawMessage, opts ...RequestOption) (*message.Message, error)

NewProposePresentation creates a new presentation proposal message.

func NewRequestPresentation

func NewRequestPresentation(from, to string, presentationDef json.RawMessage, opts ...RequestOption) (*message.Message, error)

NewRequestPresentation creates a new presentation request message. The presentationDef should be a DIF Presentation Definition (JSON).

Types

type Attachment

type Attachment struct {
	ID        string         `json:"@id"`
	MediaType string         `json:"media_type,omitempty"`
	Format    string         `json:"format,omitempty"`
	Data      AttachmentData `json:"data"`
}

Attachment represents a DIDComm attachment carrying credential/presentation data.

type AttachmentData

type AttachmentData struct {
	JSON   json.RawMessage `json:"json,omitempty"`
	Base64 string          `json:"base64,omitempty"`
	Links  []string        `json:"links,omitempty"`
	JWS    string          `json:"jws,omitempty"`
}

AttachmentData holds the content of an attachment.

type CredentialFinder

type CredentialFinder interface {
	// FindCredentials finds credentials matching a presentation definition.
	// Returns the matching credentials as JSON.
	FindCredentials(ctx context.Context, presentationDef json.RawMessage) ([]json.RawMessage, error)
}

CredentialFinder provides access to stored credentials for presentation.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler handles present-proof protocol messages.

func NewHandler

func NewHandler(holderDID string, opts ...HandlerOption) *Handler

NewHandler creates a new present-proof protocol handler.

func (*Handler) Handle

func (h *Handler) Handle(ctx context.Context, msg *message.Message) (*message.Message, error)

Handle processes an incoming present-proof message.

func (*Handler) MessageTypes

func (h *Handler) MessageTypes() []string

MessageTypes returns the message types this handler supports.

func (*Handler) RequestPresentation

func (h *Handler) RequestPresentation(verifierDID, holderDID string, presentationDef json.RawMessage, opts ...RequestOption) (*message.Message, error)

RequestPresentation sends a presentation request to a holder. This is a helper for verifiers initiating the protocol.

type HandlerOption

type HandlerOption func(*Handler)

HandlerOption configures the handler.

func WithCredentialStore

func WithCredentialStore(store CredentialFinder) HandlerOption

WithCredentialStore sets the credential store for finding matching credentials.

func WithPresentationBuilder

func WithPresentationBuilder(builder PresentationBuilder) HandlerOption

WithPresentationBuilder sets the builder for creating presentations.

func WithPresentationHandler

func WithPresentationHandler(handler func(ctx context.Context, presentation *Presentation, msg *message.Message) (*message.Message, error)) HandlerOption

WithPresentationHandler sets a custom handler for received presentations.

func WithPresentationVerifier

func WithPresentationVerifier(verifier PresentationVerifier) HandlerOption

WithPresentationVerifier sets the verifier for incoming presentations.

func WithRequestHandler

func WithRequestHandler(handler func(ctx context.Context, request *RequestPresentation, msg *message.Message) (*message.Message, error)) HandlerOption

WithRequestHandler sets a custom handler for presentation requests. If not set, the default auto-respond behavior is used.

type Presentation

type Presentation struct {
	GoalCode           string       `json:"goal_code,omitempty"`
	Comment            string       `json:"comment,omitempty"`
	LastPresentation   bool         `json:"last_presentation,omitempty"`
	PresentationAttach []Attachment `json:"presentations~attach"`
}

Presentation represents a credential presentation from holder to verifier.

func ParsePresentation

func ParsePresentation(msg *message.Message) (*Presentation, error)

ParsePresentation parses the body of a presentation message.

func (*Presentation) GetVerifiablePresentation

func (p *Presentation) GetVerifiablePresentation() (json.RawMessage, error)

GetVerifiablePresentation extracts the first verifiable presentation.

type PresentationBuilder

type PresentationBuilder interface {
	// BuildPresentation creates a VP from credentials for a presentation definition.
	BuildPresentation(ctx context.Context, credentials []json.RawMessage, presentationDef json.RawMessage, holderDID string) (json.RawMessage, error)
}

PresentationBuilder builds verifiable presentations from credentials.

type PresentationVerifier

type PresentationVerifier interface {
	// VerifyPresentation verifies a VP against a presentation definition.
	// Returns the extracted credentials if valid.
	VerifyPresentation(ctx context.Context, vp json.RawMessage, presentationDef json.RawMessage) ([]json.RawMessage, error)
}

PresentationVerifier verifies received presentations.

type ProposePresentation

type ProposePresentation struct {
	GoalCode       string       `json:"goal_code,omitempty"`
	Comment        string       `json:"comment,omitempty"`
	ProposalAttach []Attachment `json:"proposals~attach,omitempty"`
}

ProposePresentation represents a proposal from holder to verifier about what credentials they could present.

type RequestOption

type RequestOption func(*requestConfig)

RequestOption configures request creation.

func WithComment

func WithComment(comment string) RequestOption

WithComment adds a human-readable comment.

func WithConfirmation

func WithConfirmation(confirm bool) RequestOption

WithConfirmation indicates the verifier will send an ack.

func WithGoalCode

func WithGoalCode(code string) RequestOption

WithGoalCode sets the goal code for the request.

type RequestPresentation

type RequestPresentation struct {
	GoalCode      string       `json:"goal_code,omitempty"`
	Comment       string       `json:"comment,omitempty"`
	WillConfirm   bool         `json:"will_confirm,omitempty"`
	RequestAttach []Attachment `json:"request_presentations~attach"`
}

RequestPresentation represents a request from verifier to holder for specific credentials or presentations.

func ParseRequestPresentation

func ParseRequestPresentation(msg *message.Message) (*RequestPresentation, error)

ParseRequestPresentation parses the body of a request-presentation message.

func (*RequestPresentation) GetPresentationDefinition

func (r *RequestPresentation) GetPresentationDefinition() (json.RawMessage, error)

GetPresentationDefinition extracts the first presentation definition from a request.

Jump to

Keyboard shortcuts

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