Skip to content

Commit

Permalink
Issue #2755 An access_token request does not work for VCs with jwt_vc…
Browse files Browse the repository at this point in the history
…_json because https://identity.foundation/claim-format-registry/ expects jwt_vc.

- Add format aliases to credential formats. Updated the Formats struct and associated methods in the vcr/credential/formats.go file to include the handling of format aliases. This provides additional flexibility in mapping equivalent format names. Also created a new method "normalizeFormat" to facilitate the normalization of these format aliases.
  • Loading branch information
rolandgroen committed Jan 30, 2024
1 parent 1068be4 commit 7c286a3
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions vcr/credential/formats.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func DIFClaimFormats(formats map[string]map[string][]string) Formats {
ParamAliases: map[string]string{
// no aliases for this type
},
FormatAliases: map[string]string{
"jwt_vp_json": "jwt_vp",
"jwt_vc_json": "jwt_vc",
},
}
}

Expand All @@ -43,8 +47,9 @@ func OpenIDSupportedFormats(formats map[string]map[string][]string) Formats {
// Formats is a map of supported formats and their parameters according to https://identity.foundation/claim-format-registry/
// E.g., ldp_vp: {proof_type: [Ed25519Signature2018, JsonWebSignature2020]}
type Formats struct {
Map map[string]map[string][]string
ParamAliases map[string]string
Map map[string]map[string][]string
ParamAliases map[string]string
FormatAliases map[string]string
}

// Match takes the other supports formats and returns the formats that are supported by both sets.
Expand All @@ -58,7 +63,8 @@ func (f Formats) Match(other Formats) Formats {
}

for thisFormat, thisFormatParams := range f.Map {
otherFormatParams := other.normalizeParameters(other.Map[thisFormat])
otherFormat := other.normalizeFormat(thisFormat)
otherFormatParams := other.normalizeParameters(other.Map[otherFormat])
if otherFormatParams == nil {
// format not supported by other
continue
Expand Down Expand Up @@ -100,6 +106,13 @@ func (f Formats) normalizeParameter(param string) string {
return param
}

func (f Formats) normalizeFormat(format string) string {
if alias, ok := f.FormatAliases[format]; ok {
return alias
}
return format
}

// normalizeParameters normalizes the parameter map to the names used in the DIF spec.
func (f Formats) normalizeParameters(params map[string][]string) map[string][]string {
if params == nil {
Expand Down

0 comments on commit 7c286a3

Please sign in to comment.