Skip to content

Commit

Permalink
Update to Presentation Exchange v2 and Latest CM (#248)
Browse files Browse the repository at this point in the history
* add new fields

* update to presentation exchange v2

* update pe and cm schemas

* update test

* update codeowners
  • Loading branch information
decentralgabe committed Nov 4, 2022
1 parent 4aaa87c commit 6dad71a
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 20 deletions.
2 changes: 1 addition & 1 deletion CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# The format is described: https://github.blog/2017-07-06-introducing-code-owners/

# These owners will be the default owners for everything in the repo.
* @decentralgabe @nitro-neal
* @decentralgabe @nitro-neal @andresuribe87


# -----------------------------------------------
Expand Down
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
8 changes: 8 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)

// set a bad issuer
err = builder.SetIssuer(Issuer{
Name: "Satoshi",
Expand Down Expand Up @@ -108,6 +114,8 @@ func TestCredentialManifestBuilder(t *testing.T) {
manifest, err := builder.Build()
assert.NoError(t, err)
assert.NotEmpty(t, manifest)
assert.Equal(t, "name", manifest.Name)
assert.Equal(t, "description", manifest.Description)
}

func TestCredentialApplicationBuilder(t *testing.T) {
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
6 changes: 6 additions & 0 deletions schema/known_schemas/pe-presentation-definition-envelope.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
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"
}
},
"required": ["id", "path", "format"],
Expand Down

0 comments on commit 6dad71a

Please sign in to comment.