@@ -15,6 +15,7 @@ import (
1515 "github.com/hyperledger/aries-framework-go/pkg/doc/sdjwt/common"
1616 "github.com/hyperledger/aries-framework-go/pkg/doc/sdjwt/holder"
1717 "github.com/hyperledger/aries-framework-go/pkg/doc/sdjwt/issuer"
18+ json2 "github.com/hyperledger/aries-framework-go/pkg/doc/util/json"
1819)
1920
2021type marshalDisclosureOpts struct {
@@ -389,6 +390,56 @@ func (vc *Credential) CreateDisplayCredential( // nolint:funlen,gocyclo
389390 return newVC , nil
390391}
391392
393+ // CreateDisplayCredentialMap creates, for SD-JWT credentials, a Credential whose selective-disclosure subject fields
394+ // are replaced with the disclosure data.
395+ //
396+ // Options may be provided to filter the disclosures that will be included in the display credential. If a disclosure is
397+ // not included, the associated claim will not be present in the returned credential.
398+ //
399+ // If the calling Credential is not an SD-JWT credential, this method returns the credential itself.
400+ func (vc * Credential ) CreateDisplayCredentialMap ( // nolint:funlen,gocyclo
401+ opts ... DisplayCredentialOption ,
402+ ) (map [string ]interface {}, error ) {
403+ options := & displayCredOpts {}
404+
405+ for _ , opt := range opts {
406+ opt (options )
407+ }
408+
409+ if options .displayAll && len (options .displayGiven ) > 0 {
410+ return nil , fmt .Errorf ("incompatible options provided" )
411+ }
412+
413+ if vc .SDJWTHashAlg == "" || vc .JWT == "" {
414+ bytes , err := vc .MarshalJSON ()
415+ if err != nil {
416+ return nil , err
417+ }
418+
419+ return json2 .ToMap (bytes )
420+ }
421+
422+ credClaims , err := unmarshalJWSClaims (vc .JWT , false , nil )
423+ if err != nil {
424+ return nil , fmt .Errorf ("unmarshal VC JWT claims: %w" , err )
425+ }
426+
427+ credClaims .refineFromJWTClaims ()
428+
429+ useDisclosures := filterDisclosureList (vc .SDJWTDisclosures , options )
430+
431+ newVCObj , err := common .GetDisclosedClaims (useDisclosures , credClaims .VC )
432+ if err != nil {
433+ return nil , fmt .Errorf ("assembling disclosed claims into vc: %w" , err )
434+ }
435+
436+ if subj , ok := newVCObj ["credentialSubject" ].(map [string ]interface {}); ok {
437+ clearEmpty (subj )
438+ }
439+
440+ return newVCObj , nil
441+ }
442+
392443func filterDisclosureList (disclosures []* common.DisclosureClaim , options * displayCredOpts ) []* common.DisclosureClaim {
393444 if options .displayAll {
394445 return disclosures
0 commit comments