Documentation
¶
Overview ¶
Package presentproof provides support for the Present Proof Protocol 2.0: https://github.com/hyperledger/aries-rfcs/blob/master/features/0454-present-proof-v2/README.md.
A protocol supporting a general purpose verifiable presentation exchange regardless of the specifics of the underlying verifiable presentation request and verifiable presentation format.
1. Create your client:
client, err := presentproof.New(ctx)
if err != nil {
panic(err)
}
2. Register an action event channel.
actions := make(chan service.DIDCommAction) client.RegisterActionEvent(actions)
3. Handle incoming actions.
for {
select {
case event := <-actions:
piid := e.Properties.All()["piid"].(string)
if event.Message.Type() == presentproof.ProposePresentationMsgType {
// If Verifier is willing to accept the proposal.
client.AcceptProposePresentationV2(piid, &RequestPresentationV2{})
// If Verifier is not willing to accept the proposal.
client.DeclineProposePresentation(piid, reason)
}
if event.Message.Type() == presentproof.RequestPresentationMsgType {
// If Prover is willing to accept a request.
client.AcceptRequestPresentationV2(piid, &PresentationV2{})
// If Prover wants to counter a request they received with a proposal.
client.NegotiateRequestPresentationV2(piid, &ProposePresentationV2{})
// If Prover is not willing to accept a request.
client.DeclineRequestPresentation(piid, reason)
}
if event.Message.Type() == presentproof.PresentationMsgType {
// If Verifier is willing to accept the presentation.
client.AcceptPresentation(piid, names)
// If Verifier is not willing to accept the presentation.
client.DeclinePresentation(piid, reason)
}
if event.Message.Type() == presentproof.ProblemReportMsgType {
Problem report message is triggered to notify client about the error.
In that case, there is only one option - accept it.
client.AcceptProblemReport(piid)
}
}
}
How to initiate the protocol? The protocol can be initiated by the Verifier or by the Prover. Prover initiates the protocol.
client.SendProposePresentationV2(&ProposePresentationV2{}, myDID, theirDID)
Verifier initiates the protocol.
client.SendRequestPresentationV2(&RequestPresentationV2{}, myDID, theirDID)
Index ¶
- func WithAddProofFn(sign addProof) presentproof.Opt
- func WithMultiOptions(opts ...presentproof.Opt) presentproof.Opt
- func WithPresentation(msg *Presentation) presentproof.Opt
- func WithProposePresentation(msg *ProposePresentation) presentproof.Opt
- func WithRequestPresentation(msg *RequestPresentation) presentproof.Opt
- type AcceptPresentationOptions
- type Action
- type Client
- func (c *Client) AcceptPresentation(piID string, options ...AcceptPresentationOptions) error
- func (c *Client) AcceptProblemReport(piID string) error
- func (c *Client) AcceptProposePresentation(piID string, msg *RequestPresentation) error
- func (c *Client) AcceptRequestPresentation(piID string, msg *Presentation, sign addProof) error
- func (c *Client) Actions() ([]Action, error)
- func (c *Client) DeclinePresentation(piID string, options ...DeclinePresentationOptions) error
- func (c *Client) DeclineProposePresentation(piID string, options ...DeclinePresentationOptions) error
- func (c *Client) DeclineRequestPresentation(piID, reason string) error
- func (c *Client) NegotiateRequestPresentation(piID string, msg *ProposePresentation) error
- func (c *Client) SendProposePresentation(params *ProposePresentation, connRec *connection.Record) (string, error)
- func (c *Client) SendRequestPresentation(params *RequestPresentation, connRec *connection.Record) (string, error)
- type DeclinePresentationOptions
- type Presentation
- type PresentationV2
- type PresentationV3
- type ProposePresentation
- type ProposePresentationV2
- type ProposePresentationV3
- type ProtocolService
- type Provider
- type RequestPresentation
- type RequestPresentationV2
- type RequestPresentationV3
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithAddProofFn ¶ added in v0.1.6
func WithAddProofFn(sign addProof) presentproof.Opt
WithAddProofFn allows providing function that will sign the Presentation. Use this option to respond to RequestPresentation.
func WithMultiOptions ¶ added in v0.1.6
func WithMultiOptions(opts ...presentproof.Opt) presentproof.Opt
WithMultiOptions allows combining several options into one.
func WithPresentation ¶
func WithPresentation(msg *Presentation) presentproof.Opt
WithPresentation allows providing Presentation message. Use this option to respond to RequestPresentation.
func WithProposePresentation ¶
func WithProposePresentation(msg *ProposePresentation) presentproof.Opt
WithProposePresentation allows providing ProposePresentation message. Use this option to respond to RequestPresentation.
func WithRequestPresentation ¶
func WithRequestPresentation(msg *RequestPresentation) presentproof.Opt
WithRequestPresentation allows providing RequestPresentation message. Use this option to respond to ProposePresentation.
Types ¶
type AcceptPresentationOptions ¶ added in v0.1.8
type AcceptPresentationOptions func(opts *acceptPresentationOpts)
AcceptPresentationOptions is custom option for accepting presentation message from prover.
func AcceptByFriendlyNames ¶ added in v0.1.8
func AcceptByFriendlyNames(names ...string) AcceptPresentationOptions
AcceptByFriendlyNames option to provide optional friendly names for accepting presentation message.
func AcceptByRequestingRedirect ¶ added in v0.1.8
func AcceptByRequestingRedirect(url string) AcceptPresentationOptions
AcceptByRequestingRedirect option to provide optional redirect URL requesting prover to redirect.
type Client ¶
Client enable access to presentproof API https://github.com/hyperledger/aries-rfcs/tree/master/features/0037-present-proof
func (*Client) AcceptPresentation ¶
func (c *Client) AcceptPresentation(piID string, options ...AcceptPresentationOptions) error
AcceptPresentation is used by the Verifier to accept a presentation.
func (*Client) AcceptProblemReport ¶ added in v0.1.4
AcceptProblemReport accepts problem report action.
func (*Client) AcceptProposePresentation ¶
func (c *Client) AcceptProposePresentation(piID string, msg *RequestPresentation) error
AcceptProposePresentation is used when the Verifier is willing to accept the propose presentation.
func (*Client) AcceptRequestPresentation ¶
func (c *Client) AcceptRequestPresentation(piID string, msg *Presentation, sign addProof) error
AcceptRequestPresentation is used by the Prover is to accept a presentation request.
func (*Client) DeclinePresentation ¶
func (c *Client) DeclinePresentation(piID string, options ...DeclinePresentationOptions) error
DeclinePresentation is used by the Verifier to decline a presentation.
func (*Client) DeclineProposePresentation ¶
func (c *Client) DeclineProposePresentation(piID string, options ...DeclinePresentationOptions) error
DeclineProposePresentation is used when the Verifier does not want to accept the propose presentation.
func (*Client) DeclineRequestPresentation ¶
DeclineRequestPresentation is used when the Prover does not want to accept the request presentation.
func (*Client) NegotiateRequestPresentation ¶
func (c *Client) NegotiateRequestPresentation(piID string, msg *ProposePresentation) error
NegotiateRequestPresentation is used by the Prover to counter a presentation request they received with a proposal.
func (*Client) SendProposePresentation ¶
func (c *Client) SendProposePresentation( params *ProposePresentation, connRec *connection.Record) (string, error)
SendProposePresentation is used by the Prover to send a propose presentation. It returns the threadID of the new instance of the protocol.
Example ¶
nolint: gocyclo
transport := map[string]chan payload{
Alice: make(chan payload),
Bob: make(chan payload),
}
// Alice creates client
clientAlice, err := New(mockContext(Alice, transport))
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))
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 {
var acceptErr error
var e service.DIDCommAction
select {
case e = <-actionsAlice:
case e = <-actionsBob:
}
piid, ok := e.Properties.All()["piid"].(string)
if !ok {
fmt.Println("empty piid")
}
if e.Message.Type() == presentproof.PresentationMsgTypeV2 {
acceptErr = clientBob.AcceptPresentation(piid)
}
if e.Message.Type() == presentproof.ProposePresentationMsgTypeV2 {
acceptErr = clientBob.AcceptProposePresentation(piid, &RequestPresentation{WillConfirm: true})
}
if e.Message.Type() == presentproof.RequestPresentationMsgTypeV2 {
acceptErr = clientAlice.AcceptRequestPresentation(piid, &Presentation{}, nil)
}
if acceptErr != nil {
fmt.Println(acceptErr)
}
}
}()
conn := connection.Record{
ConnectionID: uuid.New().String(),
MyDID: Alice,
TheirDID: Bob,
}
// Alice
waitForAlice := waitForFn(clientAlice)
// Bob
waitForBob := waitForFn(clientBob)
_, err = clientAlice.SendProposePresentation(&ProposePresentation{}, &conn)
if err != nil {
fmt.Println(err)
}
waitForAlice()
waitForBob()
Output: Bob received https://didcomm.org/present-proof/2.0/propose-presentation from Alice Alice received https://didcomm.org/present-proof/2.0/request-presentation from Bob Bob received https://didcomm.org/present-proof/2.0/presentation from Alice Alice received https://didcomm.org/present-proof/2.0/ack from Bob
Example (Using_v3) ¶
nolint: gocyclo
transport := map[string]chan payload{
Alice: make(chan payload),
Bob: make(chan payload),
}
// Alice creates client
clientAlice, err := New(mockContext(Alice, transport))
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))
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 {
var acceptErr error
var e service.DIDCommAction
select {
case e = <-actionsAlice:
case e = <-actionsBob:
}
piid, ok := e.Properties.All()["piid"].(string)
if !ok {
fmt.Println("empty piid")
}
if e.Message.Type() == presentproof.PresentationMsgTypeV3 {
acceptErr = clientBob.AcceptPresentation(piid)
}
if e.Message.Type() == presentproof.ProposePresentationMsgTypeV3 {
rp3 := &RequestPresentation{}
rp3.WillConfirm = true
acceptErr = clientBob.AcceptProposePresentation(piid, rp3)
}
if e.Message.Type() == presentproof.RequestPresentationMsgTypeV3 {
acceptErr = clientAlice.AcceptRequestPresentation(piid, &Presentation{}, nil)
}
if acceptErr != nil {
fmt.Println(acceptErr)
}
}
}()
conn := connection.Record{
ConnectionID: uuid.New().String(),
MyDID: Alice,
TheirDID: Bob,
DIDCommVersion: service.V2,
}
// Alice
waitForAlice := waitForFn(clientAlice)
// Bob
waitForBob := waitForFn(clientBob)
_, err = clientAlice.SendProposePresentation(&ProposePresentation{}, &conn)
if err != nil {
fmt.Println(err)
}
waitForAlice()
waitForBob()
Output: Bob received https://didcomm.org/present-proof/3.0/propose-presentation from Alice Alice received https://didcomm.org/present-proof/3.0/request-presentation from Bob Bob received https://didcomm.org/present-proof/3.0/presentation from Alice Alice received https://didcomm.org/present-proof/3.0/ack from Bob
func (*Client) SendRequestPresentation ¶
func (c *Client) SendRequestPresentation( params *RequestPresentation, connRec *connection.Record) (string, error)
SendRequestPresentation is used by the Verifier to send a request presentation. It returns the threadID of the new instance of the protocol.
Example ¶
transport := map[string]chan payload{
Alice: make(chan payload),
Bob: make(chan payload),
}
// Alice creates client
clientAlice, err := New(mockContext(Alice, transport))
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))
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 {
var acceptErr error
select {
case e := <-actionsAlice:
acceptErr = clientAlice.AcceptPresentation(e.Properties.All()["piid"].(string))
case e := <-actionsBob:
acceptErr = clientBob.AcceptRequestPresentation(e.Properties.All()["piid"].(string), &Presentation{}, nil)
}
if acceptErr != nil {
fmt.Println(acceptErr)
}
}
}()
conn := connection.Record{
ConnectionID: uuid.New().String(),
MyDID: Alice,
TheirDID: Bob,
}
// Alice
waitForAlice := waitForFn(clientAlice)
// Bob
waitForBob := waitForFn(clientBob)
_, err = clientAlice.SendRequestPresentation(&RequestPresentation{}, &conn)
if err != nil {
fmt.Println(err)
}
waitForAlice()
waitForBob()
Output: Bob received https://didcomm.org/present-proof/2.0/request-presentation from Alice Alice received https://didcomm.org/present-proof/2.0/presentation from Bob
Example (Third) ¶
transport := map[string]chan payload{
Alice: make(chan payload),
Bob: make(chan payload),
}
// Alice creates client
clientAlice, err := New(mockContext(Alice, transport))
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))
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 {
var acceptErr error
select {
case e := <-actionsAlice:
acceptErr = clientAlice.AcceptPresentation(e.Properties.All()["piid"].(string))
case e := <-actionsBob:
acceptErr = clientBob.AcceptRequestPresentation(e.Properties.All()["piid"].(string), &Presentation{}, nil)
}
if acceptErr != nil {
fmt.Println(acceptErr)
}
}
}()
conn := connection.Record{
ConnectionID: uuid.New().String(),
MyDID: Alice,
TheirDID: Bob,
}
// Alice
waitForAlice := waitForFn(clientAlice)
// Bob
waitForBob := waitForFn(clientBob)
_, err = clientAlice.SendRequestPresentation(&RequestPresentation{WillConfirm: true}, &conn)
if err != nil {
fmt.Println(err)
}
waitForAlice()
waitForBob()
Output: Bob received https://didcomm.org/present-proof/2.0/request-presentation from Alice Alice received https://didcomm.org/present-proof/2.0/presentation from Bob Bob received https://didcomm.org/present-proof/2.0/ack from Alice
Example (Using_v3) ¶
transport := map[string]chan payload{
Alice: make(chan payload),
Bob: make(chan payload),
}
// Alice creates client
clientAlice, err := New(mockContext(Alice, transport))
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))
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 {
var acceptErr error
select {
case e := <-actionsAlice:
acceptErr = clientAlice.AcceptPresentation(e.Properties.All()["piid"].(string))
case e := <-actionsBob:
acceptErr = clientBob.AcceptRequestPresentation(e.Properties.All()["piid"].(string), &Presentation{}, nil)
}
if acceptErr != nil {
fmt.Println(acceptErr)
}
}
}()
conn := connection.Record{
ConnectionID: uuid.New().String(),
MyDID: Alice,
TheirDID: Bob,
DIDCommVersion: service.V2,
}
// Alice
waitForAlice := waitForFn(clientAlice)
// Bob
waitForBob := waitForFn(clientBob)
_, err = clientAlice.SendRequestPresentation(&RequestPresentation{}, &conn)
if err != nil {
fmt.Println(err)
}
waitForAlice()
waitForBob()
Output: Bob received https://didcomm.org/present-proof/3.0/request-presentation from Alice Alice received https://didcomm.org/present-proof/3.0/presentation from Bob
Example (Using_v3_second) ¶
transport := map[string]chan payload{
Alice: make(chan payload),
Bob: make(chan payload),
}
// Alice creates client
clientAlice, err := New(mockContext(Alice, transport))
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))
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 {
var acceptErr error
select {
case e := <-actionsAlice:
acceptErr = clientAlice.AcceptPresentation(e.Properties.All()["piid"].(string))
case e := <-actionsBob:
acceptErr = clientBob.AcceptRequestPresentation(e.Properties.All()["piid"].(string), &Presentation{}, nil)
}
if acceptErr != nil {
fmt.Println(acceptErr)
}
}
}()
conn := connection.Record{
ConnectionID: uuid.New().String(),
MyDID: Alice,
TheirDID: Bob,
DIDCommVersion: service.V2,
}
// Alice
waitForAlice := waitForFn(clientAlice)
// Bob
waitForBob := waitForFn(clientBob)
_, err = clientAlice.SendRequestPresentation(&RequestPresentation{WillConfirm: true}, &conn)
if err != nil {
fmt.Println(err)
}
waitForAlice()
waitForBob()
Output: Bob received https://didcomm.org/present-proof/3.0/request-presentation from Alice Alice received https://didcomm.org/present-proof/3.0/presentation from Bob Bob received https://didcomm.org/present-proof/3.0/ack from Alice
type DeclinePresentationOptions ¶ added in v0.1.8
type DeclinePresentationOptions func(opts *declinePresentationOpts)
DeclinePresentationOptions is custom option for declining propose presentation and presentation messages from prover.
func DeclineReason ¶ added in v0.1.8
func DeclineReason(reason string) DeclinePresentationOptions
DeclineReason option to provide optional reason for declining given message.
func DeclineRedirect ¶ added in v0.1.8
func DeclineRedirect(url string) DeclinePresentationOptions
DeclineRedirect option to provide optional redirect URL requesting prover to redirect.
type Presentation ¶
type Presentation = presentproof.PresentationParams
Presentation is a response to a RequestPresentation message and contains signed presentations.
type PresentationV2 ¶ added in v0.1.8
type PresentationV2 presentproof.PresentationV2
PresentationV2 is a response to a RequestPresentationV2 message and contains signed presentations.
type PresentationV3 ¶ added in v0.1.7
type PresentationV3 presentproof.PresentationV3
PresentationV3 is a response to a RequestPresentationV3 message and contains signed presentations.
type ProposePresentation ¶
type ProposePresentation = presentproof.ProposePresentationParams
ProposePresentation is an optional message sent by the Prover to the verifier to initiate a proof presentation process, or in response to a request-presentation message when the Prover wants to propose using a different presentation format.
type ProposePresentationV2 ¶ added in v0.1.8
type ProposePresentationV2 presentproof.ProposePresentationV2
ProposePresentationV2 is an optional message sent by the Prover to the verifier to initiate a proof presentation process, or in response to a request-presentation message when the Prover wants to propose using a different presentation format.
type ProposePresentationV3 ¶ added in v0.1.7
type ProposePresentationV3 presentproof.ProposePresentationV3
ProposePresentationV3 is an optional message sent by the Prover to the verifier to initiate a proof presentation process, or in response to a request-presentation message when the Prover wants to propose using a different presentation format.
type ProtocolService ¶
type ProtocolService interface {
service.DIDComm
Actions() ([]presentproof.Action, error)
ActionContinue(piID string, opt ...presentproof.Opt) error
ActionStop(piID string, err error, opt ...presentproof.Opt) error
}
ProtocolService defines the presentproof service.
type Provider ¶
Provider contains dependencies for the protocol and is typically created by using aries.Context().
type RequestPresentation ¶
type RequestPresentation = presentproof.RequestPresentationParams
RequestPresentation describes values that need to be revealed and predicates that need to be fulfilled.
type RequestPresentationV2 ¶ added in v0.1.8
type RequestPresentationV2 presentproof.RequestPresentationV2
RequestPresentationV2 describes values that need to be revealed and predicates that need to be fulfilled.
type RequestPresentationV3 ¶ added in v0.1.7
type RequestPresentationV3 presentproof.RequestPresentationV3
RequestPresentationV3 describes values that need to be revealed and predicates that need to be fulfilled.