Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
fix: temporary work around for json ld canonizing issue
Browse files Browse the repository at this point in the history
- Excluding "credentialStatus.type" from VC which is causing document
canonizing issue (#1592)
- closes #1593

Signed-off-by: sudesh.shetty <sudesh.shetty@securekey.com>
  • Loading branch information
sudeshrshetty committed Apr 9, 2020
1 parent 7e4eafc commit bce8aaf
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/doc/signature/proof/jws.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ func createVerifyJWS(suite signatureSuite, jsonldDoc map[string]interface{}, p *

proofOptionsDigest := suite.GetDigest(canonicalProofOptions)

// TODO this filter function to be removed [Issue #1592]
filterJsonldObject(jsonldDoc)

canonicalDoc, err := prepareDocumentForJWS(suite, jsonldDoc)
if err != nil {
return nil, err
Expand All @@ -103,6 +106,18 @@ func createVerifyJWS(suite signatureSuite, jsonldDoc map[string]interface{}, p *
return append([]byte(jwtHeader+"."), verifyData...), nil
}

// TODO this is a temporary fix to remove fields from JSON LD doc which is causing incorrect
// canonized docs. To be removed as part of [Issue #1592]
func filterJsonldObject(jsonldDoc map[string]interface{}) {
// remove 'type' from credential status object
if crStatus, ok := jsonldDoc["credentialStatus"]; ok {
if crstatusMap, ok := crStatus.(map[string]interface{}); ok {
delete(crstatusMap, "type")
jsonldDoc["credentialStatus"] = crstatusMap
}
}
}

func prepareJWSProof(suite signatureSuite, proofOptions map[string]interface{}) ([]byte, error) {
proofOptions[jsonldContext] = securityContext

Expand Down
30 changes: 30 additions & 0 deletions pkg/doc/signature/proof/jws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,33 @@ func TestGetJWTSignature(t *testing.T) {
require.EqualError(t, err, "invalid JWT")
require.Empty(t, signature)
}

func TestFilterJsonldObject(t *testing.T) {
const doc = `{
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://www.w3.org/2018/credentials/examples/v1"
],
"credentialSchema": [],
"credentialStatus": {
"id": "http://issuer.vc.rest.example.com:8070/status/1",
"type": "CredentialStatusList2017"
}
}`

var jsonldDoc map[string]interface{}
err := json.Unmarshal([]byte(doc), &jsonldDoc)
require.NoError(t, err)
require.NotEmpty(t, jsonldDoc)

credStatus, ok := jsonldDoc["credentialStatus"].(map[string]interface{})
require.True(t, ok)

len := len(credStatus)
filterJsonldObject(jsonldDoc)

credStatus, ok = jsonldDoc["credentialStatus"].(map[string]interface{})
require.True(t, ok)
require.Len(t, credStatus, len-1)

}

0 comments on commit bce8aaf

Please sign in to comment.