Skip to content
This repository has been archived by the owner on Apr 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #599 from talwinder50/issue-564
Browse files Browse the repository at this point in the history
feat: Reading and Validating Credential application from wallet
  • Loading branch information
sudeshrshetty authored Feb 7, 2022
2 parents ee371c1 + 29bee77 commit 5cdc30d
Show file tree
Hide file tree
Showing 9 changed files with 639 additions and 447 deletions.
27 changes: 14 additions & 13 deletions cmd/adapter-rest/startcmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const (
cmOutputDescriptorsFilePathFlagUsage = "Path to the output descriptors file of credential manifests " +
"supported by the adapter'" + "Alternatively, this can be set with the following " +
"environment variable: " + cmOutputDescriptorsFilePathEnvKey
cmOutputDescriptorsFilePathEnvKey = "ADAPTER_REST_OUTPUT_DESCRIPTORS_FILE"
cmOutputDescriptorsFilePathEnvKey = "ADAPTER_REST_CM_DESCRIPTORS_FILE"

tlsSystemCertPoolFlagName = "tls-systemcertpool"
tlsSystemCertPoolFlagUsage = "Use system certificate pool." +
Expand Down Expand Up @@ -824,7 +824,7 @@ func addIssuerHandlers(parameters *adapterRestParameters, framework *aries.Aries
return fmt.Errorf("aries-framework - failed to get aries context : %w", err)
}

cmOutputDescriptor, err := readCMOutputDescriptorFile(parameters.cmOutputDescriptorsFilePath)
cmDescriptors, err := readCMOutputDescriptorFile(parameters.cmOutputDescriptorsFilePath)
if err != nil {
return fmt.Errorf("failed to read and validate manifest output descriptors : %w", err)
}
Expand Down Expand Up @@ -861,7 +861,7 @@ func addIssuerHandlers(parameters *adapterRestParameters, framework *aries.Aries
ExternalURL: parameters.externalURL,
DidDomain: parameters.trustblocDomain,
JSONLDDocumentLoader: ariesCtx.JSONLDDocumentLoader(),
CmOutputDescriptor: cmOutputDescriptor,
CMDescriptors: cmDescriptors,
})
if err != nil {
return fmt.Errorf("failed to init issuer ops: %w", err)
Expand Down Expand Up @@ -1160,28 +1160,29 @@ func getPresentationExchangeProvider(configFile string) (*presentationex.Provide
return p, nil
}

func readCMOutputDescriptorFile(outputDescriptorsFile string) (cmOutputDescriptors map[string][]*cm.OutputDescriptor,
func readCMOutputDescriptorFile(cmDescriptorsFile string) (cmDescriptor map[string]*issuerops.CMAttachmentDescriptors,
err error) {
if outputDescriptorsFile == "" {
return make(map[string][]*cm.OutputDescriptor), nil
if cmDescriptorsFile == "" {
return make(map[string]*issuerops.CMAttachmentDescriptors), nil
}

credentialManifestBytes, err := ioutil.ReadFile(filepath.Clean(outputDescriptorsFile))
credentialDescriptorsBytes, err := ioutil.ReadFile(filepath.Clean(cmDescriptorsFile))
if err != nil {
return nil, fmt.Errorf("read output descriptors file : %w", err)
return nil, fmt.Errorf("read credential manifest descriptors file : %w", err)
}

err = json.Unmarshal(credentialManifestBytes, &cmOutputDescriptors)
err = json.Unmarshal(credentialDescriptorsBytes, &cmDescriptor)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal output descriptor file: %w", err)
return nil, fmt.Errorf("failed to unmarshal credential manifest descriptors file: %w", err)
}

for _, outputDescriptorsValues := range cmOutputDescriptors {
err = cm.ValidateOutputDescriptors(outputDescriptorsValues)
for _, descriptors := range cmDescriptor {
err := cm.ValidateOutputDescriptors(descriptors.OutputDesc)
if err != nil {
return nil, fmt.Errorf("aries-framework - failed to validate output descriptors: %w", err)
}
}
// TODO Issue#563 validate input descriptor if exists

return cmOutputDescriptors, nil
return cmDescriptor, nil
}
2 changes: 1 addition & 1 deletion cmd/adapter-rest/startcmd/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ func TestReadOutputDescriptorFile(t *testing.T) { // nolint:paralleltest
func(t *testing.T) {
cmOutputdesc, err := readCMOutputDescriptorFile("./testingWrongFile")
require.Error(t, err)
require.Equal(t, "read output descriptors file : open testingWrongFile: no such file or directory",
require.Equal(t, "read credential manifest descriptors file : open testingWrongFile: no such file or directory",
err.Error())
require.Nil(t, cmOutputdesc)
})
Expand Down
190 changes: 122 additions & 68 deletions cmd/adapter-rest/startcmd/testdata/outputdescriptors.json
Original file line number Diff line number Diff line change
@@ -1,72 +1,126 @@
{
"udc-scope-1": [
{
"id": "udc_output",
"schema": "https://www.w3.org/2018/credentials/examples/v1",
"display": {
"title": {
"path": [
"$.title",
"$.vc.title"
],
"schema": {
"type": "string"
},
"fallback": "Bachelor's Degree"
},
"subtitle": {
"path": [
"$.minor",
"$.vc.minor"
],
"schema": {
"type": "string"
},
"fallback": ""
},
"description": {
"text": "Awarded for completing a four year program at Example University."
},
"properties": [
{
"path": [
"$.name",
"$.credentialSubject.name"
],
"schema": {
"type": "string"
},
"fallback": "Not Applicable",
"label": "Degree Holder's name"
},
{
"path": [
"$.credentialSubject.degree.type"
],
"schema": {
"type": "string"
},
"fallback": "Unknown",
"label": "Degree"
}
]
"udc-scope-1":{
"output_descriptor":[
{
"id":"udc_output",
"schema":"https://www.w3.org/2018/credentials/examples/v1",
"display":{
"title":{
"path":[
"$.title",
"$.vc.title"
],
"schema":{
"type":"string"
},
"fallback":"Bachelor's Degree"
},
"subtitle":{
"path":[
"$.minor",
"$.vc.minor"
],
"schema":{
"type":"string"
},
"fallback":""
},
"description":{
"text":"Awarded for completing a four year program at Example University."
},
"properties":[
{
"path":[
"$.name",
"$.credentialSubject.name"
],
"schema":{
"type":"string"
},
"fallback":"Not Applicable",
"label":"Degree Holder's name"
},
{
"path":[
"$.credentialSubject.degree.type"
],
"schema":{
"type":"string"
},
"fallback":"Unknown",
"label":"Degree"
}
]
},
"styles": {
"thumbnail": {
"uri": "http://example-university.org/logo.png",
"alt": "Example University logo"
},
"hero": {
"uri": "http://example-university.org/hero.png",
"alt": "Example University students in graduation ceremony"
},
"background": {
"color": "#ff0000"
},
"text": {
"color": "#d4d400"
}
"styles":{
"thumbnail":{
"uri":"http://example-university.org/logo.png",
"alt":"Example University logo"
},
"hero":{
"uri":"http://example-university.org/hero.png",
"alt":"Example University students in graduation ceremony"
},
"background":{
"color":"#ff0000"
},
"text":{
"color":"#d4d400"
}
}
}
]
}
],
"input_descriptor":[
{
"id":"prc_input",
"name":"Permanent Resident Card",
"purpose":"We need PRC to verify your status.",
"schema":[
{
"uri":"https://w3id.org/citizenship#PermanentResidentCard"
}
],
"constraints":{
"fields":[
{
"path":[
"$.credentialSubject.givenName"
],
"filter":{
"type":"string"
}
},
{
"path":[
"$.credentialSubject.familyName"
],
"filter":{
"type":"string"
}
},
{
"path":[
"$.credentialSubject.birthCountry"
],
"filter":{
"type":"string"
}
},
{
"path":[
"$.credentialSubject.birthDate"
],
"filter":{
"type":"string"
}
}
]
}
}
],
"options":{
"challenge":"508adef4-b8e0-4edf-a53d-a260371c1423",
"domain":"9rf25a28rs96"
}
}
}
2 changes: 1 addition & 1 deletion pkg/restapi/issuer/operation/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type UserConnectionMapping struct {
ConnectionID string `json:"connectionID,omitempty"`
IssuerID string `json:"issuerID,omitempty"`
Token string `json:"token,omitempty"`
OauthID string `json:"oauthid,omitempty"`
TxnID string `json:"oauthid,omitempty"`
State string `json:"state,omitempty"`
}

Expand Down
Loading

0 comments on commit 5cdc30d

Please sign in to comment.