Skip to content

Commit

Permalink
feat(sdk): Display API - Option to skip non-claim related data (#810)
Browse files Browse the repository at this point in the history
Signed-off-by: Rolson Quadras <[email protected]>
  • Loading branch information
rolsonquadras authored Sep 4, 2024
1 parent af6fd7b commit 3b5ad3f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
8 changes: 8 additions & 0 deletions cmd/wallet-sdk-gomobile/display/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Opts struct {
disableHTTPClientTLSVerification bool
maskingString *string
didResolver api.DIDResolver
skipNonClaimData bool
}

// NewOpts returns a new Opts object.
Expand Down Expand Up @@ -108,3 +109,10 @@ func (o *Opts) SetDIDResolver(didResolver api.DIDResolver) *Opts {

return o
}

// SkipNonClaimData skips the non-claims related data like issue and expiry date.
func (o *Opts) SkipNonClaimData() *Opts {
o.skipNonClaimData = true

return o
}
6 changes: 6 additions & 0 deletions cmd/wallet-sdk-gomobile/display/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ func generateGoAPIOpts(vcs *verifiable.CredentialsArray, issuerURI string,
goAPIOpts = append(goAPIOpts, goAPIOpt)
}

if opts.skipNonClaimData {
goAPIOpt := goapicredentialschema.WithSkipNonClaimData()

goAPIOpts = append(goAPIOpts, goAPIOpt)
}

if opts.didResolver != nil {
jwtVerifier := defaults.NewDefaultProofChecker(
common.NewVDRKeyResolver(&wrapper.VDRResolverWrapper{
Expand Down
15 changes: 13 additions & 2 deletions pkg/credentialschema/credentialdisplay.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ func buildCredentialDisplaysAllLocale(
vcs []*verifiable.Credential,
credentialConfigurationsSupported map[issuer.CredentialConfigurationID]*issuer.CredentialConfigurationSupported,
maskingString string,
skipNonClaimData bool,
) ([]Credential, error) {
var credentialDisplays []Credential

Expand All @@ -436,7 +437,8 @@ func buildCredentialDisplaysAllLocale(
continue
}

credentialDisplay, err := buildCredentialDisplayAllLocale(credentialConfigurationSupported, vc, subject, maskingString)
credentialDisplay, err := buildCredentialDisplayAllLocale(credentialConfigurationSupported, vc, subject,
maskingString, skipNonClaimData)
if err != nil {
return nil, err
}
Expand All @@ -455,8 +457,10 @@ func buildCredentialDisplayAllLocale(
vc *verifiable.Credential,
subject *verifiable.Subject,
maskingString string,
skipNonClaimData bool,
) (*Credential, error) {
resolvedClaims, err := resolveClaimsAllLocale(credentialConfigurationSupported, vc, subject, maskingString)
resolvedClaims, err := resolveClaimsAllLocale(credentialConfigurationSupported, vc, subject,
maskingString, skipNonClaimData)
if err != nil {
return nil, err
}
Expand All @@ -480,10 +484,17 @@ func resolveClaimsAllLocale(
vc *verifiable.Credential,
credentialSubject *verifiable.Subject,
maskingString string,
skipNonClaimData bool,
) ([]Subject, error) {
var resolvedClaims []Subject

for fieldName, claim := range credentialConfigurationSupported.CredentialDefinition.CredentialSubject {
if skipNonClaimData &&
strings.HasPrefix(fieldName, "$.") &&
!strings.HasPrefix(fieldName, "$.credentialSubject.") {
continue
}

resolvedClaim, err := resolveClaimAllLocale(
fieldName, claim, vc, credentialSubject, credentialConfigurationSupported, maskingString)
if err != nil && !errors.Is(err, errNoClaimDisplays) && !errors.Is(err, errClaimValueNotFoundInVC) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/credentialschema/credentialschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ func ResolveCredential(opts ...ResolveOpt) (*ResolvedData, error) {
return nil, err
}

rOpts := mergeOpts(opts)

if maskingString == nil {
defaultMaskingString := "•"
maskingString = &defaultMaskingString
}

credentialDisplays, err := buildCredentialDisplaysAllLocale(vcs, metadata.CredentialConfigurationsSupported,
*maskingString)
*maskingString, rOpts.skipNonClaimData)
if err != nil {
return nil, err
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/credentialschema/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type resolveOpts struct {
httpClient httpClient
maskingString *string
signatureVerifier jwt.ProofChecker
skipNonClaimData bool
}

// ResolveOpt represents an option for the Resolve function.
Expand Down Expand Up @@ -162,6 +163,13 @@ func WithJWTSignatureVerifier(signatureVerifier jwt.ProofChecker) ResolveOpt {
}
}

// WithSkipNonClaimData skips the non-claims related data like issue and expiry date.
func WithSkipNonClaimData() ResolveOpt {
return func(opts *resolveOpts) {
opts.skipNonClaimData = true
}
}

func processOpts(opts []ResolveOpt) ([]*verifiable.Credential, *issuer.Metadata, string, *string, error) {
mergedOpts := mergeOpts(opts)

Expand Down

0 comments on commit 3b5ad3f

Please sign in to comment.