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 da185b8
Show file tree
Hide file tree
Showing 10 changed files with 340 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
68 changes: 54 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,cyclop
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 @@ -818,6 +834,11 @@ func addIssuerHandlers(parameters *adapterRestParameters, framework *aries.Aries
if err != nil {
return fmt.Errorf("aries-framework - failed to get aries context : %w", err)
}
// TODO #572 Pass the output descriptors to issuer
_, err = readOutputDescriptorFile(parameters.outputDescriptorsFile)
if err != nil {
return fmt.Errorf("failed to read and validate manifest output descriptors : %w", err)
}

clientStoreKey, err := getIssuerOIDCClientStoreKey(parameters.oidcClientDBKeyPath)
if err != nil {
Expand All @@ -835,7 +856,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 Expand Up @@ -1116,3 +1137,22 @@ func getPresentationExchangeProvider(configFile string) (*presentationex.Provide

return p, nil
}

func readOutputDescriptorFile(outputDescriptorsFile string) (outputDescriptors []*cm.OutputDescriptor, err error) {
credentialManifestBytes, err := ioutil.ReadFile(filepath.Clean(outputDescriptorsFile))
if err != nil {
return nil, fmt.Errorf("read output descriptors file : %w", err)
}

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

err = cm.Validate(outputDescriptors)
if err != nil {
return nil, fmt.Errorf("aries-framework - failed to validate output discriptors: %w", err)
}

return outputDescriptors, nil
}
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
70 changes: 70 additions & 0 deletions cmd/adapter-rest/startcmd/testdata/outputdescriptors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
[
{
"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"
}
}
}
]
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 da185b8

Please sign in to comment.