Skip to content

Commit

Permalink
Add DidComm Discovery Protocol Query/Disclosure message
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyr-basiuk committed Dec 19, 2024
1 parent 93b1094 commit 7a67b22
Show file tree
Hide file tree
Showing 3 changed files with 241 additions and 0 deletions.
6 changes: 6 additions & 0 deletions protocol/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ const (
//
// Notice: this functionality is in beta and can be deleted or be non-backward compatible in the future releases.
CredentialPaymentMessageType iden3comm.ProtocolMessage = iden3comm.Iden3Protocol + "credentials/0.1/payment"

// DiscoverFeatureQueriesMessageType is type for discover-features queries message
DiscoverFeatureQueriesMessageType iden3comm.ProtocolMessage = iden3comm.DidCommProtocol + "discover-features/2.0/queries"

// DiscoverFeatureDiscloseMessageType is type for discover-features disclose message
DiscoverFeatureDiscloseMessageType iden3comm.ProtocolMessage = iden3comm.DidCommProtocol + "discover-features/2.0/disclose"
)

// CredentialIssuanceRequestMessage represent Iden3message for credential request
Expand Down
67 changes: 67 additions & 0 deletions protocol/discovery_protocol.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package protocol

import "github.com/iden3/iden3comm/v2"

// DiscoveryFeatureType is type for query feature-type.

Check warning on line 5 in protocol/discovery_protocol.go

View workflow job for this annotation

GitHub Actions / lint

exported: comment on exported type DiscoveryProtocolFeatureType should be of the form "DiscoveryProtocolFeatureType ..." (with optional leading article) (revive)
type DiscoveryProtocolFeatureType string

const (
DiscoveryProtocolFeatureTypeAccept DiscoveryProtocolFeatureType = "accept"

Check warning on line 9 in protocol/discovery_protocol.go

View workflow job for this annotation

GitHub Actions / lint

exported: exported const DiscoveryProtocolFeatureTypeAccept should have comment (or a comment on this block) or be unexported (revive)
DiscoveryProtocolFeatureTypeProtocol DiscoveryProtocolFeatureType = "protocol"
DiscoveryProtocolFeatureTypeGoalCode DiscoveryProtocolFeatureType = "goal-code"
DiscoveryProtocolFeatureTypeHeader DiscoveryProtocolFeatureType = "header"
)

// DiscoverFeatureQueriesMessage represents discover feature queries message.
type DiscoverFeatureQueriesMessage struct {
ID string `json:"id"`
Typ iden3comm.MediaType `json:"typ,omitempty"`
Type iden3comm.ProtocolMessage `json:"type"`
ThreadID string `json:"thid,omitempty"`

Body DiscoverFeatureQueriesMessageBody `json:"body,omitempty"`

From string `json:"from,omitempty"`
To string `json:"to,omitempty"`

CreatedTime *int64 `json:"created_time,omitempty"`
ExpiresTime *int64 `json:"expires_time,omitempty"`
}

// DiscoverFeatureQueriesMessageBody represents the body of the DiscoverFeatureQueriesMessage.
type DiscoverFeatureQueriesMessageBody struct {
Queries []DiscoverFeatureQuery `json:"queries"`
}

// DiscoverFeatureQuery represents discover feature query.
type DiscoverFeatureQuery struct {
FeatureType DiscoveryProtocolFeatureType `json:"feature-type"`
Match string `json:"match,omitempty"`
}

// DiscoverFeatureDiscloseMessage represents discover feature disclose message.
type DiscoverFeatureDiscloseMessage struct {
ID string `json:"id"`
Typ iden3comm.MediaType `json:"typ,omitempty"`
Type iden3comm.ProtocolMessage `json:"type"`
ThreadID string `json:"thid,omitempty"`

Body DiscoverFeatureDiscloseMessageBody `json:"body,omitempty"`

From string `json:"from,omitempty"`
To string `json:"to,omitempty"`

CreatedTime *int64 `json:"created_time,omitempty"`
ExpiresTime *int64 `json:"expires_time,omitempty"`
}

// DiscoverFeatureDiscloseMessageBody represents the body of the DiscoverFeatureDiscloseMessage.
type DiscoverFeatureDiscloseMessageBody struct {
Disclosures []DiscoverFeatureDisclosure `json:"disclosures"`
}

// DiscoverFeatureDisclosure represents discover feature disclosure.
type DiscoverFeatureDisclosure struct {
FeatureType DiscoveryProtocolFeatureType `json:"feature-type"`
Id string `json:"id"`

Check warning on line 66 in protocol/discovery_protocol.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: struct field Id should be ID (revive)
}
168 changes: 168 additions & 0 deletions protocol/discovery_protocol_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
package protocol_test

import (
"encoding/json"
"testing"

uuid "github.com/google/uuid"
"github.com/iden3/iden3comm/v2/packers"
"github.com/iden3/iden3comm/v2/protocol"
"github.com/stretchr/testify/require"
)

func TestDiscoverFeatureQueriesMessageCreation(t *testing.T) {

var err error
id, err := uuid.Parse("f0885dd0-e60e-11ee-b3e8-de17148ce1ce")
require.NoError(t, err)

thID, err := uuid.Parse("f08860d2-e60e-11ee-b3e8-de17148ce1ce")
require.NoError(t, err)

queryMessage := protocol.DiscoverFeatureQueriesMessage{
ID: id.String(),
Typ: packers.MediaTypePlainMessage,
Type: protocol.DiscoverFeatureQueriesMessageType,
ThreadID: thID.String(),
Body: protocol.DiscoverFeatureQueriesMessageBody{
Queries: []protocol.DiscoverFeatureQuery{
{
FeatureType: protocol.DiscoveryProtocolFeatureTypeAccept,
},
{
FeatureType: protocol.DiscoveryProtocolFeatureTypeProtocol,
Match: "https://iden3-communication.io/authorization/1.*",
},
{
FeatureType: protocol.DiscoveryProtocolFeatureTypeHeader,
},
},
},
From: "did:polygonid:polygon:mumbai:2qK2Rwf2zqzzhqVLqTWXetGUbs1Sc79woomP5cDLBE",
}

marshalledReq, err := json.Marshal(queryMessage)
require.NoError(t, err)

require.JSONEq(t, `{
"id": "f0885dd0-e60e-11ee-b3e8-de17148ce1ce",
"typ": "application/iden3comm-plain-json",
"type": "https://didcomm.org/discover-features/2.0/queries",
"thid": "f08860d2-e60e-11ee-b3e8-de17148ce1ce",
"body": {
"queries": [
{
"feature-type": "accept"
},
{
"feature-type": "protocol",
"match": "https://iden3-communication.io/authorization/1.*"
},
{
"feature-type": "header"
}
]
},
"from": "did:polygonid:polygon:mumbai:2qK2Rwf2zqzzhqVLqTWXetGUbs1Sc79woomP5cDLBE"
}`, string(marshalledReq))
}

func TestDiscoverFeatureDisclosuresMessageCreation(t *testing.T) {

var err error
id, err := uuid.Parse("f0885dd0-e60e-11ee-b3e8-de17148ce1ce")
require.NoError(t, err)

thID, err := uuid.Parse("f08860d2-e60e-11ee-b3e8-de17148ce1ce")
require.NoError(t, err)

queryMessage := protocol.DiscoverFeatureDiscloseMessage{
ID: id.String(),
Typ: packers.MediaTypePlainMessage,
Type: protocol.DiscoverFeatureDiscloseMessageType,
ThreadID: thID.String(),
Body: protocol.DiscoverFeatureDiscloseMessageBody{
Disclosures: []protocol.DiscoverFeatureDisclosure{
{
FeatureType: protocol.DiscoveryProtocolFeatureTypeAccept,
Id: "iden3comm/v1;env=application/iden3-zkp-json;circuitId=authV2,authV3;alg=groth16",
},
{
FeatureType: protocol.DiscoveryProtocolFeatureTypeAccept,
Id: "iden3comm/v1;env=application/iden3comm-signed-json;alg=ES256K-R",
},
{
FeatureType: protocol.DiscoveryProtocolFeatureTypeProtocol,
Id: "https://iden3-communication.io/authorization/1.0",
},
{
FeatureType: protocol.DiscoveryProtocolFeatureTypeHeader,
Id: "id",
},
{
FeatureType: protocol.DiscoveryProtocolFeatureTypeHeader,
Id: "type",
},
{
FeatureType: protocol.DiscoveryProtocolFeatureTypeHeader,
Id: "body",
},
{
FeatureType: protocol.DiscoveryProtocolFeatureTypeHeader,
Id: "created_time",
},
{
FeatureType: protocol.DiscoveryProtocolFeatureTypeHeader,
Id: "expires_time",
},
},
},
To: "did:polygonid:polygon:mumbai:2qK2Rwf2zqzzhqVLqTWXetGUbs1Sc79woomP5cDLBE",
}

marshalledReq, err := json.Marshal(queryMessage)
require.NoError(t, err)
require.JSONEq(t, `{
"id": "f0885dd0-e60e-11ee-b3e8-de17148ce1ce",
"typ": "application/iden3comm-plain-json",
"type": "https://didcomm.org/discover-features/2.0/disclose",
"thid": "f08860d2-e60e-11ee-b3e8-de17148ce1ce",
"body": {
"disclosures": [
{
"feature-type": "accept",
"id": "iden3comm/v1;env=application/iden3-zkp-json;circuitId=authV2,authV3;alg=groth16"
},
{
"feature-type": "accept",
"id": "iden3comm/v1;env=application/iden3comm-signed-json;alg=ES256K-R"
},
{
"feature-type": "protocol",
"id": "https://iden3-communication.io/authorization/1.0"
},
{
"feature-type": "header",
"id": "id"
},
{
"feature-type": "header",
"id": "type"
},
{
"feature-type": "header",
"id": "body"
},
{
"feature-type": "header",
"id": "created_time"
},
{
"feature-type": "header",
"id": "expires_time"
}
]
},
"to": "did:polygonid:polygon:mumbai:2qK2Rwf2zqzzhqVLqTWXetGUbs1Sc79woomP5cDLBE"
}`, string(marshalledReq))
}

0 comments on commit 7a67b22

Please sign in to comment.