Skip to content

Commit

Permalink
feat: [WACI-Issuance] Support to pass credential output descriptors
Browse files Browse the repository at this point in the history
closes trustbloc#561

Signed-off-by: talwinder50 <[email protected]>
  • Loading branch information
talwinder50 committed Jan 19, 2022
1 parent 5d5deae commit eb8eb75
Show file tree
Hide file tree
Showing 10 changed files with 456 additions and 624 deletions.
2 changes: 1 addition & 1 deletion cmd/adapter-rest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/google/uuid v1.3.0
github.com/gorilla/mux v1.8.0
github.com/hyperledger/aries-framework-go v0.1.8-0.20220106195936-a9d6794663ed
github.com/hyperledger/aries-framework-go v0.1.8-0.20220119075823-4b3b1a0e69eb
github.com/hyperledger/aries-framework-go-ext/component/storage/mongodb v0.0.0-20211117223600-626fe1bae44d
github.com/hyperledger/aries-framework-go-ext/component/storage/mysql v0.0.0-20210909220549-ce3a2ee13e22
github.com/hyperledger/aries-framework-go/component/storageutil v0.0.0-20220106195936-a9d6794663ed
Expand Down
4 changes: 2 additions & 2 deletions cmd/adapter-rest/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -814,8 +814,8 @@ github.com/hyperledger/aries-framework-go v0.1.7-0.20210816113201-26c0665ef2b9/g
github.com/hyperledger/aries-framework-go v0.1.7/go.mod h1:uve8/q23AUnq4EM0vBkEr1lKZRC67q5RcaHXh0ZOt0Y=
github.com/hyperledger/aries-framework-go v0.1.8-0.20211201185059-733a3370f501/go.mod h1:uve8/q23AUnq4EM0vBkEr1lKZRC67q5RcaHXh0ZOt0Y=
github.com/hyperledger/aries-framework-go v0.1.8-0.20211217135421-f68d5698237a/go.mod h1:rBMOJVwyHyYbOqbb3IB/ExBkHyvFLht/W81s24GmjcE=
github.com/hyperledger/aries-framework-go v0.1.8-0.20220106195936-a9d6794663ed h1:1n1vlQHLG9yBI40w9sY6hBzqSkYthARexSEU0rHfZS8=
github.com/hyperledger/aries-framework-go v0.1.8-0.20220106195936-a9d6794663ed/go.mod h1:rBMOJVwyHyYbOqbb3IB/ExBkHyvFLht/W81s24GmjcE=
github.com/hyperledger/aries-framework-go v0.1.8-0.20220119075823-4b3b1a0e69eb h1:SC5gKf0+VSHRoyg72k+syZJpz592vEsID6xX8kfTH+M=
github.com/hyperledger/aries-framework-go v0.1.8-0.20220119075823-4b3b1a0e69eb/go.mod h1:rBMOJVwyHyYbOqbb3IB/ExBkHyvFLht/W81s24GmjcE=
github.com/hyperledger/aries-framework-go-ext/component/storage/couchdb v0.0.0-20210909220549-ce3a2ee13e22/go.mod h1:FtlFhPHMyLORgrPpvWSmEQSNhLiwAQ4V6rqNPfuDj0o=
github.com/hyperledger/aries-framework-go-ext/component/storage/mongodb v0.0.0-20210909220549-ce3a2ee13e22/go.mod h1:aiO9mXZBykIEwmgp9sSdpMuTw0P7b+ZFUltcIB9ZccY=
github.com/hyperledger/aries-framework-go-ext/component/storage/mongodb v0.0.0-20211117223600-626fe1bae44d h1:h91rxhZkAjxcIwY08RxUTE+B8WxfiWbRHNl5X98+ziA=
Expand Down
59 changes: 45 additions & 14 deletions cmd/adapter-rest/startcmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package startcmd
import (
"crypto/tls"
"crypto/x509"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
Expand All @@ -33,6 +34,7 @@ import (
ldrest "github.com/hyperledger/aries-framework-go/pkg/controller/rest/ld"
"github.com/hyperledger/aries-framework-go/pkg/didcomm/messaging/msghandler"
arieshttp "github.com/hyperledger/aries-framework-go/pkg/didcomm/transport/http"
"github.com/hyperledger/aries-framework-go/pkg/doc/cm"
ariesld "github.com/hyperledger/aries-framework-go/pkg/doc/ld"
"github.com/hyperledger/aries-framework-go/pkg/doc/ldcontext/remote"
"github.com/hyperledger/aries-framework-go/pkg/framework/aries"
Expand Down Expand Up @@ -98,6 +100,11 @@ const (
"Alternatively, this can be set with the following environment variable: " + staticFilesPathEnvKey
staticFilesPathEnvKey = "ADAPTER_REST_STATIC_FILES"

outputDescriptorsFilePathFlagName = "output-descriptors-path"
outputDescriptorsFilePathFlagUsage = "Path to the output descriptors JSON file" +
"Alternatively, this can be set with the following environment variable: " + outputDescriptorsFilePathEnvKey
outputDescriptorsFilePathEnvKey = "ADAPTER_REST_OUTPUT_DESCRIPTORS_FILE"

tlsSystemCertPoolFlagName = "tls-systemcertpool"
tlsSystemCertPoolFlagUsage = "Use system certificate pool." +
" Possible values [true] [false]. Defaults to false if not set." +
Expand Down Expand Up @@ -265,18 +272,19 @@ type adapterRestParameters struct {
staticFiles string
presentationDefinitionsFile string
// TODO assuming same base path for all hydra endpoints for now
hydraURL string
mode string
didCommParameters *didCommParameters // didcomm
trustblocDomain string
universalResolverURL string
governanceVCSURL string
requestTokens map[string]string
walletAppURL string
oidcClientDBKeyPath string
externalURL string
didAnchorOrigin string
contextProviderURLs []string
hydraURL string
mode string
didCommParameters *didCommParameters // didcomm
trustblocDomain string
universalResolverURL string
governanceVCSURL string
requestTokens map[string]string
walletAppURL string
oidcClientDBKeyPath string
externalURL string
didAnchorOrigin string
contextProviderURLs []string
outputDescriptorsFile string
}

// governanceProvider governance provider.
Expand Down Expand Up @@ -358,6 +366,12 @@ func getAdapterRestParameters(cmd *cobra.Command) (*adapterRestParameters, error
return nil, fmt.Errorf(confErrMsg, err)
}

outputDescriptorsFile, err := cmdutils.GetUserSetVarFromString(cmd, outputDescriptorsFilePathFlagName,
outputDescriptorsFilePathEnvKey, true)
if err != nil {
return nil, fmt.Errorf(confErrMsg, err)
}

mode, err := cmdutils.GetUserSetVarFromString(cmd, modeFlagName, modeEnvKey, true)
if err != nil {
return nil, fmt.Errorf(confErrMsg, err)
Expand Down Expand Up @@ -452,6 +466,7 @@ func getAdapterRestParameters(cmd *cobra.Command) (*adapterRestParameters, error
externalURL: externalURL,
didAnchorOrigin: didAnchorOrigin,
contextProviderURLs: contextProviderURLs,
outputDescriptorsFile: outputDescriptorsFile,
}, nil
}

Expand Down Expand Up @@ -609,6 +624,7 @@ func createFlags(startCmd *cobra.Command) {
startCmd.Flags().StringP(datasourceNameFlagName, "", "", datasourceNameFlagUsage)
startCmd.Flags().StringP(datasourceTimeoutFlagName, "", "", datasourceTimeoutFlagUsage)
startCmd.Flags().StringP(staticFilesPathFlagName, "", "", staticFilesPathFlagUsage)
startCmd.Flags().StringP(outputDescriptorsFilePathFlagName, "", "", outputDescriptorsFilePathFlagUsage)
startCmd.Flags().StringP(presentationDefinitionsFlagName, "", "", presentationDefinitionsFlagUsage)
startCmd.Flags().StringP(hydraURLFlagName, "", "", hydraURLFlagUsage)
startCmd.Flags().StringP(modeFlagName, "", "", modeFlagUsage)
Expand Down Expand Up @@ -794,7 +810,7 @@ func addRPHandlers(parameters *adapterRestParameters, framework *aries.Aries, ro
return nil
}

// nolint:funlen
// nolint:funlen,gocyclo
func addIssuerHandlers(parameters *adapterRestParameters, framework *aries.Aries, router *mux.Router,
rootCAs *x509.CertPool, msgRegistrar *msghandler.Registrar) error {
store, err := initStore(parameters.dsnParams.dsn, parameters.dsnParams.timeout, issuerAdapterStorePrefix)
Expand All @@ -819,6 +835,21 @@ func addIssuerHandlers(parameters *adapterRestParameters, framework *aries.Aries
return fmt.Errorf("aries-framework - failed to get aries context : %w", err)
}

credentialManifestBytes, err := ioutil.ReadFile(parameters.outputDescriptorsFile)
if err != nil {
return fmt.Errorf("aries-framework - read output descriptors file : %w", err)
}
var outputDescriptors []*cm.OutputDescriptor

err = json.Unmarshal(credentialManifestBytes, &outputDescriptors)
if err != nil {
return fmt.Errorf("failed to read credential output descriptor file: %w", err)
}
err = cm.Validate(outputDescriptors)
if err != nil {
return fmt.Errorf("failed to validate output discriptors: %w", err)
}

clientStoreKey, err := getIssuerOIDCClientStoreKey(parameters.oidcClientDBKeyPath)
if err != nil {
return fmt.Errorf("failed to fetch OIDC client store key: %w", err)
Expand All @@ -835,7 +866,7 @@ func addIssuerHandlers(parameters *adapterRestParameters, framework *aries.Aries
if err != nil {
return fmt.Errorf("failed to init trustbloc did creator: %w", err)
}

// TODO #572 Pass the output descriptors to issuer
// add issuer endpoints
issuerService, err := issuer.New(&issuerops.Config{
AriesCtx: ariesCtx,
Expand Down
8 changes: 6 additions & 2 deletions cmd/adapter-rest/startcmd/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ func TestStartCmdDIDComm(t *testing.T) { // nolint:paralleltest // shared enviro
"--" + datasourceNameFlagName, "mem://test",
"--" + datasourceTimeoutFlagName, "30",
"--" + issuerOIDCClientStoreKeyFlagName, file.Name(),
"--" + outputDescriptorsFilePathFlagName, "./testdata/outputdescriptors.json",
}
startCmd.SetArgs(args)

Expand Down Expand Up @@ -419,6 +420,7 @@ func TestAdapterModes(t *testing.T) { // nolint:paralleltest // shared environme
"--" + datasourceTimeoutFlagName, "30",
"--" + governanceVCSURLFlagName, "http://example.vcs.com",
"--" + issuerOIDCClientStoreKeyFlagName, file.Name(),
"--" + outputDescriptorsFilePathFlagName, "./testdata/outputdescriptors.json",
}
startCmd.SetArgs(args)

Expand Down Expand Up @@ -506,6 +508,7 @@ func TestAdapterModes(t *testing.T) { // nolint:paralleltest // shared environme
"--" + datasourceTimeoutFlagName, "30",
"--" + governanceVCSURLFlagName, "http://example.vcs.com",
"--" + issuerOIDCClientStoreKeyFlagName, file.Name() + "-nonexistent",
"--" + outputDescriptorsFilePathFlagName, "./testdata/outputdescriptors.json",
}
startCmd.SetArgs(args)

Expand All @@ -531,8 +534,9 @@ func TestAdapterModes(t *testing.T) { // nolint:paralleltest // shared environme
dsnParams: &dsnParams{
dsn: "mem://test",
},
didCommParameters: &didCommParameters{},
oidcClientDBKeyPath: file.Name(),
didCommParameters: &didCommParameters{},
oidcClientDBKeyPath: file.Name(),
outputDescriptorsFile: "./testdata/outputdescriptors.json",
}

issuerAries, err := aries.New(aries.WithStoreProvider(&storage.MockStoreProvider{
Expand Down
195 changes: 195 additions & 0 deletions cmd/adapter-rest/startcmd/testdata/outputdescriptors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
[
{
"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"
}
}
},
{
"id": "prc_output",
"schema": "https://w3id.org/citizenship/v1",
"display": {
"title": {
"path": [
"$.name",
"$.vc.name"
],
"schema": {
"type": "string"
},
"fallback": "Permanent Resident Card"
},
"subtitle": {
"path": [
"$.description",
"$.vc.description"
],
"schema": {
"type": "string"
},
"fallback": ""
},
"description": {
"text": "PR card of John Smith."
},
"properties": [
{
"path": [
"$.credentialSubject.givenName"
],
"schema": {
"type": "string"
},
"fallback": "Not Applicable",
"label": "Card Holder's first name"
},
{
"path": [
"$.credentialSubject.familyName"
],
"schema": {
"type": "string"
},
"fallback": "Unknown",
"label": "Card Holder's family name"
}
]
},
"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"
}
}
},
{
"id":"driver_license_output",
"schema":"https://schema.org/EducationalOccupationalCredential",
"display":{
"title":{
"path":[
"$.name",
"$.vc.name"
],
"schema": {
"type": "string"
},
"fallback":"Washington State Driver License"
},
"subtitle":{
"path":[
"$.class",
"$.vc.class"
],
"schema": {
"type": "string"
},
"fallback":"Class A, Commercial"
},
"description":{
"text":"License to operate a vehicle with a gross combined weight rating (GCWR) of 26,001 or more pounds, as long as the GVWR of the vehicle(s) being towed is over 10,000 pounds."
},
"properties":[
{
"path":[
"$.donor",
"$.credentialSubject.license.number"
],
"schema": {
"type": "boolean"
},
"fallback":"Unknown",
"label":"Driving License Number"
}
]
},
"styles":{
"thumbnail":{
"uri":"https://dol.wa.com/logo.png",
"alt":"Washington State Seal"
},
"hero":{
"uri":"https://dol.wa.com/happy-people-driving.png",
"alt":"Happy people driving"
},
"background":{
"color":"#ff0000"
},
"text":{
"color":"#d4d400"
}
}
}
]
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/google/uuid v1.3.0
github.com/gorilla/mux v1.8.0
github.com/hyperledger/aries-framework-go v0.1.8-0.20220106195936-a9d6794663ed
github.com/hyperledger/aries-framework-go v0.1.8-0.20220119075823-4b3b1a0e69eb
github.com/hyperledger/aries-framework-go-ext/component/vdr/orb v0.1.4-0.20211219215001-23cd75276fdc
github.com/hyperledger/aries-framework-go/component/storageutil v0.0.0-20220106195936-a9d6794663ed
github.com/hyperledger/aries-framework-go/spi v0.0.0-20220106195936-a9d6794663ed
Expand Down
Loading

0 comments on commit eb8eb75

Please sign in to comment.