diff --git a/vc/vcjwt.go b/vc/vcjwt.go index 57d3ce7..141c981 100644 --- a/vc/vcjwt.go +++ b/vc/vcjwt.go @@ -55,6 +55,10 @@ func Decode[T CredentialSubject](vcJWT string) (DecodedVCJWT[T], error) { return DecodedVCJWT[T]{}, fmt.Errorf("failed to decode vc claim: %w", err) } + if vc.Type == nil { + return DecodedVCJWT[T]{}, errors.New("vc-jwt missing vc type") + } + // the following conditionals are included to conform with the jwt decoding section // of the specification defined here: https://www.w3.org/TR/vc-data-model/#jwt-decoding if decoded.Claims.Issuer != "" { diff --git a/vc/vcjwt_test.go b/vc/vcjwt_test.go index 58ef3e7..7ebc1dc 100644 --- a/vc/vcjwt_test.go +++ b/vc/vcjwt_test.go @@ -1,10 +1,12 @@ package vc_test import ( + "fmt" "testing" "time" "github.com/alecthomas/assert/v2" + web5go "github.com/tbd54566975/web5-go" "github.com/tbd54566975/web5-go/dids/didjwk" "github.com/tbd54566975/web5-go/jwt" "github.com/tbd54566975/web5-go/vc" @@ -164,3 +166,24 @@ func TestVerify(t *testing.T) { }) } } + +func TestVector_Decode(t *testing.T) { + testVectors, err := + web5go.ReadTestVector[string, any]("../web5-spec/test-vectors/vc_jwt/decode.json") + assert.NoError(t, err) + fmt.Println("Running test vectors: ", testVectors.Description) + + for _, vector := range testVectors.Vectors { + t.Run(vector.Description, func(t *testing.T) { + fmt.Println("Running test vector: ", vector.Description) + + _, err := vc.Decode[vc.Claims](vector.Input) + + if vector.Errors { + assert.Error(t, err) + } else { + assert.NoError(t, err) + } + }) + } +}