-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PLGNACredentialStatusCheck function
- Loading branch information
Showing
5 changed files
with
121 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package c_polygonid | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"errors" | ||
|
||
core "github.com/iden3/go-iden3-core/v2" | ||
"github.com/iden3/go-iden3-core/v2/w3c" | ||
) | ||
|
||
func CredentialStatusCheck(ctx context.Context, cfg EnvConfig, | ||
jsonReq []byte) (bool, error) { | ||
|
||
var req struct { | ||
IssuerDID w3c.DID `json:"issuer"` | ||
CredentialStatus jsonObj `json:"credentialStatus"` | ||
} | ||
|
||
err := json.Unmarshal(jsonReq, &req) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
issuerID, err := core.IDFromDID(req.IssuerDID) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
_, err = buildAndValidateCredentialStatus(ctx, cfg, req.CredentialStatus, | ||
&issuerID, false) | ||
if errors.Is(err, errCredentialsRevoked) { | ||
return false, nil | ||
} else if err != nil { | ||
return false, err | ||
} | ||
return true, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package c_polygonid | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
|
||
httpmock "github.com/0xPolygonID/c-polygonid/testing" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func readJsonFile(t testing.TB, filename string) []byte { | ||
jsonIn, err := os.ReadFile("testdata/" + filename) | ||
require.NoError(t, err) | ||
return jsonIn | ||
} | ||
|
||
func TestCredentialStatusCheck(t *testing.T) { | ||
defer httpmock.MockHTTPClient(t, map[string]string{ | ||
"http://localhost:8001/api/v1/identities/did%3Aiden3%3Apolygon%3Amumbai%3AwuQT8NtFq736wsJahUuZpbA8otTzjKGyKj4i4yWtU/claims/revocation/status/0": "testdata/httpresp_rev_status_wuQT8NtFq736wsJahUuZpbA8otTzjKGyKj4i4yWtU_0.json", | ||
}, httpmock.IgnoreUntouchedURLs())() | ||
|
||
jsonIn := readJsonFile(t, "credential_status_request.json") | ||
|
||
ctx := context.Background() | ||
isValid, err := CredentialStatusCheck(ctx, EnvConfig{}, jsonIn) | ||
require.NoError(t, err) | ||
require.True(t, isValid) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"issuer": "did:iden3:polygon:mumbai:wuQT8NtFq736wsJahUuZpbA8otTzjKGyKj4i4yWtU", | ||
"credentialStatus": { | ||
"id": "http://localhost:8001/api/v1/identities/did%3Aiden3%3Apolygon%3Amumbai%3AwuQT8NtFq736wsJahUuZpbA8otTzjKGyKj4i4yWtU/claims/revocation/status/0", | ||
"revocationNonce": 0, | ||
"type": "SparseMerkleTreeProof" | ||
} | ||
} |