Skip to content

Commit

Permalink
Add test vector for vcjwt decode
Browse files Browse the repository at this point in the history
  • Loading branch information
KendallWeihe committed Apr 3, 2024
1 parent 26ff1c4 commit 2861b54
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions vc/vcjwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
23 changes: 23 additions & 0 deletions vc/vcjwt_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
}
})
}
}

0 comments on commit 2861b54

Please sign in to comment.