Skip to content

Commit

Permalink
feat: fix order field position
Browse files Browse the repository at this point in the history
Signed-off-by: Mykhailo Sizov <[email protected]>
  • Loading branch information
mishasizov-SK committed Feb 21, 2024
1 parent e965efa commit 428959a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export TERM := xterm-256color

ANDROID_EMULATOR_NAME ?= WalletSDKDeviceEmulator

VCS_COMMIT ?= 85f957d9f6554679b3fff86828d4e97ae556d05d
VCS_COMMIT ?= 3eafabe27767fe7aa6055afe81634ba12a60db94

.PHONY: all
all: checks unit-test integration-test
Expand Down
14 changes: 8 additions & 6 deletions cmd/wallet-sdk-gomobile/display/testdata/issuer_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
"credential_configurations_supported": {
"UniversityDegreeCredential_jwt_vc_json_v1": {
"format": "jwt_vc_json",
"order": [
"id",
"given_name",
"surname"
],
"credential_definition": {
"credentialSubject": {
"id": {
Expand All @@ -24,8 +29,7 @@
"locale": "en-US"
}
],
"value_type": "string",
"order": 0
"value_type": "string"
},
"given_name": {
"display": [
Expand All @@ -34,8 +38,7 @@
"locale": "en-US"
}
],
"value_type": "string",
"order": 1
"value_type": "string"
},
"surname": {
"display": [
Expand All @@ -44,8 +47,7 @@
"locale": "en-US"
}
],
"value_type": "string",
"order": 2
"value_type": "string"
},
"gpa": {
"display": [
Expand Down
17 changes: 9 additions & 8 deletions pkg/credentialschema/credentialdisplay.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ func resolveClaims(
var resolvedClaims []ResolvedClaim

for fieldName, claim := range credentialConfigurationSupported.CredentialDefinition.CredentialSubject {
resolvedClaim, err := resolveClaim(fieldName, claim, credentialSubject, preferredLocale, maskingString)
resolvedClaim, err := resolveClaim(
fieldName, claim, credentialSubject, credentialConfigurationSupported, preferredLocale, maskingString)
if err != nil && !errors.Is(err, errNoClaimDisplays) && !errors.Is(err, errClaimValueNotFoundInVC) {
return nil, err
}
Expand All @@ -190,7 +191,11 @@ func resolveClaims(
return resolvedClaims, nil
}

func resolveClaim(fieldName string, claim *issuer.Claim, credentialSubject *verifiable.Subject,
func resolveClaim(
fieldName string,
claim *issuer.Claim,
credentialSubject *verifiable.Subject,
credentialConfigurationSupported *issuer.CredentialConfigurationSupported,
preferredLocale, maskingString string,
) (*ResolvedClaim, error) {
if len(claim.LocalizedClaimDisplays) == 0 {
Expand Down Expand Up @@ -219,12 +224,8 @@ func resolveClaim(fieldName string, claim *issuer.Claim, credentialSubject *veri

var order *int

if claim.Order != nil {
orderAsInt, err := claim.OrderAsInt()
if err != nil {
return nil, err
}

orderAsInt, err := credentialConfigurationSupported.ClaimOrderAsInt(fieldName)
if err == nil {
order = &orderAsInt
}

Expand Down
14 changes: 8 additions & 6 deletions pkg/credentialschema/testdata/issuer_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
"credential_configurations_supported": {
"UniversityDegreeCredential_jwt_vc_json-ld_v1": {
"format": "jwt_vc_json",
"order": [
"id",
"given_name",
"surname"
],
"credential_definition": {
"credentialSubject": {
"id": {
Expand All @@ -24,8 +29,7 @@
"locale": "en-US"
}
],
"value_type": "string",
"order": 0
"value_type": "string"
},
"given_name": {
"display": [
Expand All @@ -34,8 +38,7 @@
"locale": "en-US"
}
],
"value_type": "string",
"order": 1
"value_type": "string"
},
"surname": {
"display": [
Expand All @@ -44,8 +47,7 @@
"locale": "en-US"
}
],
"value_type": "string",
"order": 2
"value_type": "string"
},
"gpa": {
"display": [
Expand Down
28 changes: 16 additions & 12 deletions test/integration/fixtures/profile/profiles.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
"credential_configurations_supported": {
"VerifiedEmployee_jwt_vc_json_v1": {
"format": "jwt_vc_json",
"order": [
"displayName",
"givenName",
"jobTitle"
],
"credential_definition": {
"type": [
"VerifiableCredential",
Expand All @@ -69,8 +74,7 @@
"name": "Employee"
}
],
"value_type": "string",
"order": 0
"value_type": "string"
},
"givenName": {
"display": [
Expand All @@ -79,8 +83,7 @@
"name": "Given Name"
}
],
"value_type": "string",
"order": 1
"value_type": "string"
},
"jobTitle": {
"display": [
Expand All @@ -89,8 +92,7 @@
"name": "Job Title"
}
],
"value_type": "string",
"order": 2
"value_type": "string"
},
"mail": {
"display": [
Expand Down Expand Up @@ -430,6 +432,11 @@
"credential_configurations_supported": {
"VerifiedEmployee_jwt_vc_json_v1": {
"format": "jwt_vc_json",
"order": [
"displayName",
"givenName",
"jobTitle"
],
"credential_definition": {
"type": [
"VerifiableCredential",
Expand All @@ -443,8 +450,7 @@
"locale": "en-US"
}
],
"value_type": "string",
"order": 0
"value_type": "string"
},
"givenName": {
"display": [
Expand All @@ -453,8 +459,7 @@
"locale": "en-US"
}
],
"value_type": "string",
"order": 1
"value_type": "string"
},
"jobTitle": {
"display": [
Expand All @@ -463,8 +468,7 @@
"locale": "en-US"
}
],
"value_type": "string",
"order": 2
"value_type": "string"
},
"surname": {
"display": [
Expand Down

0 comments on commit 428959a

Please sign in to comment.