Skip to content

Commit

Permalink
feat: [WACI-Issuance] Support to read credential manifest
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 21, 2022
1 parent 8c4b652 commit e7b3984
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 11 deletions.
7 changes: 4 additions & 3 deletions cmd/adapter-rest/startcmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -835,8 +835,8 @@ 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 = readCMOutputDescriptorFile(parameters.cmOutputDescriptorsFilePath)

cmOutputDescriptor, err := readCMOutputDescriptorFile(parameters.cmOutputDescriptorsFilePath)
if err != nil {
return fmt.Errorf("failed to read and validate manifest output descriptors : %w", err)
}
Expand All @@ -857,7 +857,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
// TODO #575 Persist the manifest output descriptor in database
// add issuer endpoints
issuerService, err := issuer.New(&issuerops.Config{
AriesCtx: ariesCtx,
Expand All @@ -872,6 +872,7 @@ func addIssuerHandlers(parameters *adapterRestParameters, framework *aries.Aries
ExternalURL: parameters.externalURL,
DidDomain: parameters.trustblocDomain,
JSONLDDocumentLoader: ariesCtx.JSONLDDocumentLoader(),
CmOutputDescriptor: cmOutputDescriptor,
})
if err != nil {
return fmt.Errorf("failed to init issuer ops: %w", err)
Expand Down
3 changes: 2 additions & 1 deletion pkg/profile/issuer/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"fmt"
"time"

"github.com/hyperledger/aries-framework-go/pkg/doc/cm"
"github.com/hyperledger/aries-framework-go/spi/storage"

"github.com/trustbloc/edge-adapter/pkg/internal/common/adapterutil"
Expand Down Expand Up @@ -45,7 +46,7 @@ type ProfileData struct {
OIDCClientParams *OIDCClientParams `json:"oidcParams,omitempty"`
CredentialScopes []string `json:"credScopes,omitempty"`
LinkedWalletURL string `json:"linkedWallet,omitempty"`
// Todo #issue Add credential manifest issuer object
CredentialManifestIssuer cm.Issuer `json:"issuer,omitempty"`
}

// OIDCClientParams optional set of oidc client parameters that the issuer may set, for static client registration.
Expand Down
6 changes: 6 additions & 0 deletions pkg/profile/issuer/profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import (
"errors"
"testing"

"github.com/google/uuid"
"github.com/hyperledger/aries-framework-go/component/storageutil/mem"
mockstorage "github.com/hyperledger/aries-framework-go/component/storageutil/mock"
"github.com/hyperledger/aries-framework-go/pkg/doc/cm"
"github.com/hyperledger/aries-framework-go/spi/storage"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -53,6 +55,10 @@ func TestCredentialRecord_SaveProfile(t *testing.T) {
Name: "Issuer Profile 1",
SupportedVCContexts: []string{"https://w3id.org/citizenship/v3"},
URL: "http://issuer.example.com",
CredentialManifestIssuer: cm.Issuer{
ID: uuid.New().String(),
Name: "Example University",
},
}

err = record.SaveProfile(value)
Expand Down
26 changes: 20 additions & 6 deletions pkg/restapi/issuer/operation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const (

// WACI interaction constants
credentialManifestFormat = "dif/credential-manifest/[email protected]"
credentialManifestVersion = "1.0.0"
credentialFulfillmentFormat = "dif/credential-manifest/[email protected]"
offerCredentialAttachMediaType = "application/json"
redirectStatusOK = "OK"
Expand Down Expand Up @@ -155,6 +156,7 @@ type Config struct {
ExternalURL string
DidDomain string
JSONLDDocumentLoader ld.DocumentLoader
CmOutputDescriptor map[string][]*cm.OutputDescriptor
}

// New returns issuer rest instance.
Expand Down Expand Up @@ -342,6 +344,7 @@ type Operation struct {
getOIDCClientFunc func(string, string) (oidcClient, error)
didDomain string
jsonldDocLoader ld.DocumentLoader
cmOutputDescriptor map[string][]*cm.OutputDescriptor
}

// GetRESTHandlers get all controller API handler available for this service.
Expand Down Expand Up @@ -1291,7 +1294,7 @@ func (o *Operation) handleProposeCredential(msg service.DIDCommAction) (issuecre
}

// get manifest
manifest := o.readCredentialManifest()
manifest := o.readCredentialManifest(profile)

// get unsigned credential
vc, err := o.createCredential(getUserDataURL(profile.URL), userInvMap.TxToken, oauthToken,
Expand Down Expand Up @@ -1728,12 +1731,23 @@ func (o *Operation) hanlDIDExStateMsg(msg service.StateMsg) error {
return nil
}

// read credential manifest from profile URL endpoints
// TODO for now returning empty manifest, TO BE IMPLEMENTED [issue##561 & issue#563]
func (o *Operation) readCredentialManifest() *cm.CredentialManifest {
return &cm.CredentialManifest{
ID: uuid.NewString(),
// read credential manifest issuer detail from persisted profile data
func (o *Operation) readCredentialManifest(profileData *issuer.ProfileData) *cm.CredentialManifest {
for scope, cmDesciptor := range o.cmOutputDescriptor {
// TODO issue#561 Add credential manifest presentation definition
for _, profileCredScope := range profileData.CredentialScopes {
if scope == profileCredScope {
return &cm.CredentialManifest{
ID: uuid.NewString(),
Version: credentialManifestVersion,
Issuer: profileData.CredentialManifestIssuer,
OutputDescriptors: cmDesciptor,
}
}
}
}

return nil
}

func prepareOfferCredentialMessage(manifest *cm.CredentialManifest, fulfillment *verifiable.Presentation) *issuecredsvc.OfferCredentialParams { // nolint:lll
Expand Down
33 changes: 32 additions & 1 deletion pkg/restapi/issuer/operation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3454,11 +3454,25 @@ func TestWACIIssuanceHandler(t *testing.T) {
ConnIDByDIDs: connID,
}

c.cmOutputDescriptor = map[string][]*cm.OutputDescriptor{
"prc": {
&cm.OutputDescriptor{
ID: uuid.New().String(),
Schema: "https://www.w3.org/2018/credentials/examples/v1",
},
},
}

invitationID := uuid.New().String()
issuerID := uuid.New().String()

profile := createProfileData(issuerID)
profile.SupportsWACI = true
profile.CredentialScopes = []string{"prc", "udc"}
profile.CredentialManifestIssuer = cm.Issuer{
ID: uuid.New().String(),
Name: "Example University",
}

err = c.profileStore.SaveProfile(profile)
require.NoError(t, err)
Expand Down Expand Up @@ -3502,9 +3516,21 @@ func TestWACIIssuanceHandler(t *testing.T) {

invitationID := uuid.New().String()
issuerID := uuid.New().String()

c.cmOutputDescriptor = map[string][]*cm.OutputDescriptor{
"prc": {
&cm.OutputDescriptor{
ID: uuid.New().String(),
Schema: "https://www.w3.org/2018/credentials/examples/v1",
},
},
}
profile := createProfileData(issuerID)
profile.SupportsWACI = true
profile.CredentialScopes = []string{"prc", "udc"}
profile.CredentialManifestIssuer = cm.Issuer{
ID: uuid.New().String(),
Name: "Example University",
}

err = c.profileStore.SaveProfile(profile)
require.NoError(t, err)
Expand Down Expand Up @@ -3615,6 +3641,11 @@ func TestWACIIssuanceHandler(t *testing.T) {

profile = createProfileData(issuerID)
profile.SupportsWACI = true
profile.CredentialScopes = []string{"prc", "udc"}
profile.CredentialManifestIssuer = cm.Issuer{
ID: uuid.New().String(),
Name: "Example University",
}

err = c.profileStore.SaveProfile(profile)
require.NoError(t, err)
Expand Down

0 comments on commit e7b3984

Please sign in to comment.