Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding statuslist conversion #280

Merged
merged 2 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions credential/status/statuslist2021.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,10 @@ func bitstringExpansion(compressedBitstring string) ([]string, error) {

// ValidateCredentialInStatusList determines whether a credential is contained in a status list 2021 credential
// https://w3c-ccg.github.io/vc-status-list-2021/#validate-algorithm
// NOTE: this method does perform credential signature/proof block verification
// NOTE: this method does not perform credential signature/proof block verification
func ValidateCredentialInStatusList(credentialToValidate credential.VerifiableCredential, statusCredential credential.VerifiableCredential) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the godoc?

// 1. Let credentialToValidate be a verifiable credentials containing a credentialStatus entry that is a StatusList2021Entry.
statusListEntryValue, ok := credentialToValidate.CredentialStatus.(StatusList2021Entry)
statusListEntryValue, ok := toStatusList2021Entry(credentialToValidate.CredentialStatus)
if !ok {
return false, fmt.Errorf("credential to validate<%s> not using the StatusList2021 credentialStatus "+
"property", credentialToValidate.ID)
Expand Down Expand Up @@ -303,3 +303,25 @@ func ValidateCredentialInStatusList(credentialToValidate credential.VerifiableCr
}
return false, nil
}

func toStatusList2021Entry(credStatus interface{}) (*StatusList2021Entry, bool) {
statusListEntryValue, ok := credStatus.(StatusList2021Entry)
if ok {
return &statusListEntryValue, true
}

credStatusMap, ok := credStatus.(map[string]interface{})
if !ok {
return nil, false
}

statusListEntry := StatusList2021Entry{
ID: credStatusMap["id"].(string),
Type: credStatusMap["type"].(string),
StatusPurpose: StatusPurpose(credStatusMap["statusPurpose"].(string)),
StatusListIndex: credStatusMap["statusListIndex"].(string),
StatusListCredential: credStatusMap["statusListCredential"].(string),
}

return &statusListEntry, true
}
34 changes: 34 additions & 0 deletions credential/status/statuslist2021_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,40 @@ func TestValidateCredentialInStatusList(t *testing.T) {
assert.True(tt, valid)
})

t.Run("happy path validation with credential status interface", func(tt *testing.T) {
revocationID := "revocation-id"
testIssuer := "test-issuer"
testCred1 := credential.VerifiableCredential{
Context: []interface{}{"https://www.w3.org/2018/credentials/v1",
"https://w3id.org/security/suites/jws-2020/v1"},
ID: "test-verifiable-credential-2",
Type: []string{"VerifiableCredential"},
Issuer: testIssuer,
IssuanceDate: "2021-01-01T19:23:24Z",
CredentialSubject: map[string]interface{}{
"id": "test-vc-id-1",
"company": "Block",
"website": "https://block.xyz",
},
CredentialStatus: map[string]interface{}{
"id": revocationID,
"type": "Block",
"statusPurpose": "revocation",
"statusListIndex": "123",
"statusListCredential": "test-cred",
},
}

statusListCredential, err := GenerateStatusList2021Credential(revocationID, testIssuer, StatusRevocation, []credential.VerifiableCredential{testCred1})
assert.NoError(tt, err)
assert.NotEmpty(tt, statusListCredential)

// valid = revoked
valid, err := ValidateCredentialInStatusList(testCred1, *statusListCredential)
assert.NoError(tt, err)
assert.True(tt, valid)
})

t.Run("check for missing cred", func(tt *testing.T) {
revocationID := "revocation-id"
testIssuer := "test-issuer"
Expand Down
Binary file modified wasm/static/main.wasm
Binary file not shown.