diff --git a/protocol/credentials.go b/protocol/credentials.go index 5643981..ffb15fa 100644 --- a/protocol/credentials.go +++ b/protocol/credentials.go @@ -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 diff --git a/protocol/discovery_protocol.go b/protocol/discovery_protocol.go new file mode 100644 index 0000000..314658e --- /dev/null +++ b/protocol/discovery_protocol.go @@ -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"` +} diff --git a/protocol/discovery_protocol_test.go b/protocol/discovery_protocol_test.go new file mode 100644 index 0000000..5273888 --- /dev/null +++ b/protocol/discovery_protocol_test.go @@ -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)) +}