Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Presentation Exchange v2 and Latest CM #248

Merged
merged 5 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions credential/exchange/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ type PresentationDefinitionEnvelope struct {
// PresentationDefinition https://identity.foundation/presentation-exchange/#presentation-definition
type PresentationDefinition struct {
ID string `json:"id,omitempty" validate:"required"`
InputDescriptors []InputDescriptor `json:"input_descriptors" validate:"required,dive"`
Name string `json:"name,omitempty"`
Purpose string `json:"purpose,omitempty"`
Format *ClaimFormat `json:"format,omitempty" validate:"omitempty,dive"`
InputDescriptors []InputDescriptor `json:"input_descriptors" validate:"required,dive"`
SubmissionRequirements []SubmissionRequirement `json:"submission_requirements,omitempty" validate:"omitempty,dive"`

// https://identity.foundation/presentation-exchange/#json-ld-framing-feature
Expand Down Expand Up @@ -186,7 +186,7 @@ func (cf *ClaimFormat) FormatValues() []string {

// AlgOrProofTypePerFormat for a given format, return the supported alg or proof types. A nil response indicates
// that the format is not supported.
func (cf *ClaimFormat) AlgOrProofTypePerFormat(_ string) []string {
func (cf *ClaimFormat) AlgOrProofTypePerFormat() []string {
var res []string
if cf.JWT != nil {
for _, a := range cf.JWT.Alg {
Expand Down Expand Up @@ -269,14 +269,16 @@ type Constraints struct {
}

type Field struct {
Path []string `json:"path,omitempty" validate:"required"`
ID string `json:"id,omitempty"`
Purpose string `json:"purpose,omitempty"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Path []string `json:"path,omitempty" validate:"required"`
Purpose string `json:"purpose,omitempty"`
Optional bool `json:"optional,omitempty"`
IntentToRetain bool `json:"intent_to_retain,omitempty"`
// If a predicate property is present, filter must be too
// https://identity.foundation/presentation-exchange/#predicate-feature
Predicate *Preference `json:"predicate,omitempty"`
Filter *Filter `json:"filter,omitempty"`
Optional bool `json:"optional,omitempty"`
}

type RelationalConstraint struct {
Expand Down
2 changes: 1 addition & 1 deletion credential/exchange/submission.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func filterClaimsByFormat(claims []NormalizedClaim, format *ClaimFormat) []Norma
// if the format matches, check the alg type
if util.Contains(claim.Format, formatValues) {
// get the supported alg or proof types for this format
algOrProofTypes := format.AlgOrProofTypePerFormat(claim.Format)
algOrProofTypes := format.AlgOrProofTypePerFormat()
if util.Contains(claim.AlgOrProofType, algOrProofTypes) {
filteredClaims = append(filteredClaims, claim)
}
Expand Down
18 changes: 18 additions & 0 deletions credential/manifest/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ func (cmb *CredentialManifestBuilder) IsEmpty() bool {
return reflect.DeepEqual(cmb, &CredentialManifestBuilder{})
}

func (cmb *CredentialManifestBuilder) SetName(name string) error {
if cmb.IsEmpty() {
return errors.New(BuilderEmptyError)
}

cmb.Name = name
return nil
}

func (cmb *CredentialManifestBuilder) SetDescription(description string) error {
if cmb.IsEmpty() {
return errors.New(BuilderEmptyError)
}

cmb.Description = description
return nil
}

func (cmb *CredentialManifestBuilder) SetIssuer(i Issuer) error {
if cmb.IsEmpty() {
return errors.New(BuilderEmptyError)
Expand Down
6 changes: 6 additions & 0 deletions credential/manifest/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ func TestCredentialManifestBuilder(t *testing.T) {

assert.False(t, builder.IsEmpty())

err = builder.SetName("name")
assert.NoError(t, err)

err = builder.SetDescription("description")
assert.NoError(t, err)
Comment on lines +24 to +25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this test verify that the correct values are set when the CM is built?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added


// set a bad issuer
err = builder.SetIssuer(Issuer{
Name: "Satoshi",
Expand Down
2 changes: 2 additions & 0 deletions credential/manifest/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const (
type CredentialManifest struct {
ID string `json:"id" validate:"required"`
SpecVersion string `json:"spec_version" validate:"required"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Issuer Issuer `json:"issuer" validate:"required,dive"`
OutputDescriptors []OutputDescriptor `json:"output_descriptors" validate:"required,dive"`
Format *exchange.ClaimFormat `json:"format,omitempty" validate:"omitempty,dive"`
Expand Down
54 changes: 43 additions & 11 deletions schema/known_schemas/cm-credential-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,30 @@
"title": "Credential Manifest",
"type": "object",
"properties": {
"id": { "type": "string" },
"spec_version": { "type" : "string" },
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"spec_version": {
"type": "string"
},
"issuer": {
"type": "object",
"required": ["id"],
"required": [
"id"
],
"properties": {
"id": { "type": "string" },
"name": { "type": "string" },
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"styles": {
"$ref": "https://identity.foundation/wallet-rendering/schemas/entity-styles.json"
}
Expand All @@ -21,12 +37,23 @@
"type": "array",
"items": {
"type": "object",
"required": ["id", "schema"],
"required": [
"id",
"schema"
],
"properties": {
"id": { "type": "string" },
"name": { "type": "string" },
"description": { "type": "string" },
"schema": { "type": "string" },
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"schema": {
"type": "string"
},
"display": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -62,6 +89,11 @@
"$ref": "https://identity.foundation/claim-format-registry/schemas/presentation-definition-claim-format-designations.json"
}
},
"required": ["id", "spec_version", "issuer", "output_descriptors"],
"required": [
"id",
"spec_version",
"issuer",
"output_descriptors"
],
"additionalProperties": false
}
18 changes: 18 additions & 0 deletions schema/known_schemas/pe-input-descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
"id": {
"type": "string"
},
"optional": {
"type": "boolean"
},
"path": {
"type": "array",
"items": {
Expand All @@ -40,6 +43,12 @@
"purpose": {
"type": "string"
},
"intent_to_retain": {
"type": "boolean"
},
"name": {
"type": "string"
},
"filter": {
"$ref": "http://json-schema.org/draft-07/schema#"
}
Expand All @@ -54,6 +63,9 @@
"id": {
"type": "string"
},
"optional": {
"type": "boolean"
},
"path": {
"type": "array",
"items": {
Expand All @@ -63,9 +75,15 @@
"purpose": {
"type": "string"
},
"intent_to_retain": {
"type": "boolean"
},
"filter": {
"$ref": "http://json-schema.org/draft-07/schema#"
},
"name": {
"type": "string"
},
"predicate": {
"type": "string",
"enum": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
"purpose": {
"type": "string"
},
"name": {
"type": "string"
},
"intent_to_retain": {
"type": "boolean"
},
Expand Down Expand Up @@ -78,6 +81,9 @@
"filter": {
"$ref": "http://json-schema.org/draft-07/schema#"
},
"name": {
"type": "string"
},
"predicate": {
"type": "string",
"enum": [
Expand Down
6 changes: 6 additions & 0 deletions schema/known_schemas/pe-presentation-definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
"purpose": {
"type": "string"
},
"name": {
"type": "string"
},
"intent_to_retain": {
"type": "boolean"
},
Expand Down Expand Up @@ -78,6 +81,9 @@
"filter": {
"$ref": "http://json-schema.org/draft-07/schema#"
},
"name": {
"type": "string"
},
"predicate": {
"type": "string",
"enum": [
Expand Down
2 changes: 1 addition & 1 deletion schema/known_schemas/pe-presentation-submission.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"$ref": "#/definitions/descriptor"
},
"format": {
"$ref": "https://identity.foundation/claim-format-registry/schemas/presentation-submission-claim-format-designations.json#/definitions/format"
"$ref": "http://identity.foundation/claim-format-registry/schemas/presentation-submission-claim-format-designations.json#/definitions/format"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we not use https?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

json schema breaks when you do 😢

}
},
"required": ["id", "path", "format"],
Expand Down