-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DidComm Discovery Protocol Query/Disclosure message
- Loading branch information
1 parent
93b1094
commit 7a67b22
Showing
3 changed files
with
241 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
type DiscoveryProtocolFeatureType string | ||
|
||
const ( | ||
DiscoveryProtocolFeatureTypeAccept DiscoveryProtocolFeatureType = "accept" | ||
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"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |