Skip to content

Commit

Permalink
credentialStatus.id must be a URI, not URL (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
reinkrul authored Oct 2, 2023
1 parent c1495ef commit 8571790
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
3 changes: 1 addition & 2 deletions vc/vc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"github.com/nuts-foundation/go-did/did"
"net/url"
"time"

ssi "github.com/nuts-foundation/go-did"
Expand Down Expand Up @@ -57,7 +56,7 @@ type VerifiableCredential struct {

// CredentialStatus defines the method on how to determine a credential is revoked.
type CredentialStatus struct {
ID url.URL `json:"id"`
ID ssi.URI `json:"id"`
Type string `json:"type"`
}

Expand Down
20 changes: 20 additions & 0 deletions vc/vc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package vc
import (
"encoding/json"
ssi "github.com/nuts-foundation/go-did"
"github.com/stretchr/testify/require"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -28,6 +29,25 @@ func TestVerifiableCredential_UnmarshalCredentialSubject(t *testing.T) {
})
}

func TestCredentialStatus(t *testing.T) {
t.Run("can unmarshal JWT VC Presentation Profile JWT-VC example", func(t *testing.T) {
// CredentialStatus example taken from https://identity.foundation/jwt-vc-presentation-profile/#vc-jwt
// Regression: earlier defined credentialStatus.id as url.URL, which breaks since it's specified as URI by the core specification.
expectedJSON := `{
"id": "urn:uuid:7facf41c-1dc5-486b-87e6-587d015e76d7?bit-index=10",
"type": "RevocationList2021Status",
"statusListIndex": "10",
"statusListCredential": "did:ion:EiD7M8RYnUuir2bm21uu-5YmWcqqQEie-T-jYEOEBeEWJQ:eyJkZWx0YSI6eyJwYXRjaGVzIjpbeyJhY3Rpb24iOiJyZXBsYWNlIiwiZG9jdW1lbnQiOnsicHVibGljS2V5cyI6W3siaWQiOiJzaWduIiwicHVibGljS2V5SndrIjp7ImNydiI6InNlY3AyNTZrMSIsImt0eSI6IkVDIiwieCI6InNnamhTdVFsZkdYVjg1QlVSWkg5aEtQR2RhTDRlYmdSN0dERERFbkJteXMiLCJ5IjoiRGw4Z3dqazRPN2h5cDVqVjZjUjFCT3l0el9TSUZtN0ljWUlsLXBqd1JUVSJ9LCJwdXJwb3NlcyI6WyJhdXRoZW50aWNhdGlvbiJdLCJ0eXBlIjoiRWNkc2FTZWNwMjU2azFWZXJpZmljYXRpb25LZXkyMDE5In1dfX1dLCJ1cGRhdGVDb21taXRtZW50IjoiRWlBUjZWbjlHeGJiSFhEcDBoZjl6NV9ZT3gzcFJhZWd5LVFUdEp3YjNDcUdCdyJ9LCJzdWZmaXhEYXRhIjp7ImRlbHRhSGFzaCI6IkVpQ05hbDZYUnV5VjFkX2p2UlZEbmpFTXNqSUJLZjE2VzYxdDF2cndOZ1QtbVEiLCJyZWNvdmVyeUNvbW1pdG1lbnQiOiJFaUJoOWRrSDBEdVZOUGcyTnJmWi0zZ1BmYzZXVl9CN3dOZ1hNZWlBekxBaDFnIn19?service=IdentityHub&queries=W3sibWV0aG9kIjoiQ29sbGVjdGlvbnNRdWVyeSIsInNjaGVtYSI6Imh0dHBzOi8vdzNpZC5vcmcvdmMtc3RhdHVzLWxpc3QtMjAyMS92MSIsIm9iamVjdElkIjoiZjljYTFmNDAtODg0NS00NWE1LTgwNWYtYzJlNWJjNDZhN2I5In1d"
}`
var actual CredentialStatus

err := json.Unmarshal([]byte(expectedJSON), &actual)
require.NoError(t, err)

assert.Equal(t, "urn:uuid:7facf41c-1dc5-486b-87e6-587d015e76d7?bit-index=10", actual.ID.String())
})
}

func TestVerifiableCredential_UnmarshalProof(t *testing.T) {
type jsonWebSignature struct {
Jws string
Expand Down

0 comments on commit 8571790

Please sign in to comment.