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 24, 2022
1 parent 8c4b652 commit 3919b0f
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 20 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
34 changes: 27 additions & 7 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 @@ -1290,8 +1293,13 @@ func (o *Operation) handleProposeCredential(msg service.DIDCommAction) (issuecre
}
}

// get manifest
manifest := o.readCredentialManifest()
txn, err := o.getTxn(userInvMap.TxID)
if err != nil {
return nil, fmt.Errorf("failed to get trasaction data: %w", err)
}

// read credential manifest
manifest := o.readCredentialManifest(profile, txn.CredScope)

// get unsigned credential
vc, err := o.createCredential(getUserDataURL(profile.URL), userInvMap.TxToken, oauthToken,
Expand Down Expand Up @@ -1728,12 +1736,24 @@ 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 and scope
from the persisted transaction cred scope.
*/
// TODO issue#561 Add credential manifest presentation definition
func (o *Operation) readCredentialManifest(profileData *issuer.ProfileData, txnCredScope string) *cm.CredentialManifest {
for scope, cmDesciptor := range o.cmOutputDescriptor {
if scope == txnCredScope {
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
74 changes: 66 additions & 8 deletions pkg/restapi/issuer/operation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const (
inviteeDID = "did:example:0d76fa4e1386"
inviterDID = "did:example:e6025bfdbb8f"
mockOIDCProvider = "mock.provider.local"
mockCredScope = "prc"
)

func TestNew(t *testing.T) {
Expand Down Expand Up @@ -3454,22 +3455,48 @@ func TestWACIIssuanceHandler(t *testing.T) {
ConnIDByDIDs: connID,
}

c.cmOutputDescriptor = map[string][]*cm.OutputDescriptor{
mockCredScope: {
&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.CredentialManifestIssuer = cm.Issuer{
ID: uuid.New().String(),
Name: "Example University",
}

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

err = c.storeUserInvitationMapping(&UserInvitationMapping{
usrInvitationMapping := &UserInvitationMapping{
InvitationID: invitationID,
IssuerID: issuerID,
TxID: uuid.New().String(),
TxToken: uuid.New().String(),
})
}

err = c.storeUserInvitationMapping(usrInvitationMapping)
require.NoError(t, err)

txDataSample := &txnData{
IssuerID: profile.ID,
CredScope: mockCredScope,
}

tdByte, err := json.Marshal(txDataSample)
require.NoError(t, err)

c.txnStore.Put(usrInvitationMapping.TxID, tdByte)

go c.didCommActionListener(actionCh)

done := make(chan struct{})
Expand Down Expand Up @@ -3502,20 +3529,44 @@ func TestWACIIssuanceHandler(t *testing.T) {

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

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

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

err = c.storeUserInvitationMapping(&UserInvitationMapping{
usrInvitationMapping := &UserInvitationMapping{
InvitationID: invitationID,
IssuerID: issuerID,
TxID: uuid.New().String(),
TxToken: uuid.New().String(),
})
}

err = c.storeUserInvitationMapping(usrInvitationMapping)
require.NoError(t, err)

txDataSample := &txnData{
IssuerID: profile.ID,
CredScope: mockCredScope,
}

tdByte, err := json.Marshal(txDataSample)
require.NoError(t, err)

c.txnStore.Put(usrInvitationMapping.TxID, tdByte)

go c.didCommActionListener(actionCh)

// credential data error
Expand Down Expand Up @@ -3603,18 +3654,23 @@ func TestWACIIssuanceHandler(t *testing.T) {
InvitationID: newInvitationID,
}), "failed to get OIDC access token for WACI transaction")

// token store put error
newInvitationID = uuid.New().String()
issuerID = uuid.New().String()
err = c.storeUserInvitationMapping(&UserInvitationMapping{
usrInvitationMapping = &UserInvitationMapping{
InvitationID: newInvitationID,
IssuerID: issuerID,
TxID: usrInvitationMapping.TxID,
TxToken: uuid.New().String(),
})
}
err = c.storeUserInvitationMapping(usrInvitationMapping)
require.NoError(t, err)

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

err = c.profileStore.SaveProfile(profile)
require.NoError(t, err)
Expand All @@ -3629,6 +3685,8 @@ func TestWACIIssuanceHandler(t *testing.T) {
errPut: errors.New("error inserting data"),
}

c.txnStore.Put(usrInvitationMapping.TxID, tdByte)

c.httpClient = &mockHTTPClient{
respValue: &http.Response{
StatusCode: http.StatusOK,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
}
}
],
"prc": [
"PermanentResidentCard": [
{
"id": "prc_output",
"schema": "https://w3id.org/citizenship/v1",
Expand Down

0 comments on commit 3919b0f

Please sign in to comment.