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

Commit

Permalink
fix: Pass VC Test Suite where JWS is passed as input data
Browse files Browse the repository at this point in the history
closes #947

Signed-off-by: Dima <dkinoshenko@gmail.com>
  • Loading branch information
kdimak committed Dec 16, 2019
1 parent 92ac19f commit 14f9826
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
42 changes: 38 additions & 4 deletions pkg/doc/verifiable/test-suite/verifiable_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ func encodeVCToJWS(vcBytes []byte, privateKey interface{}) {
}

func encodeVPToJWS(vpBytes []byte, audience string, privateKey interface{}) {
vp, err := verifiable.NewPresentation(vpBytes, verifiable.WithPresSkippedEmbeddedProofCheck())
vp, err := verifiable.NewPresentation(vpBytes,
verifiable.WithPresSkippedEmbeddedProofCheck(),
// the public key is used to decode verifiable credentials passed as JWS to the presentation
verifiable.WithPresPublicKeyFetcher(verifiable.SingleKey(getJWTDecodePublicKey())))
if err != nil {
abort("failed to decode presentation: %v", err)
}
Expand Down Expand Up @@ -128,9 +131,7 @@ func encodeVCToJWTUnsecured(vcBytes []byte) {
func decodeVCJWTToJSON(vcBytes []byte, publicKey interface{}) {
// Asked to decode JWT
credential, _, err := verifiable.NewCredential(vcBytes,
verifiable.WithPublicKeyFetcher(func(issuerID, keyID string) (interface{}, error) {
return publicKey, nil
}))
verifiable.WithPublicKeyFetcher(verifiable.SingleKey(publicKey)))
if err != nil {
abort("failed to decode credential: %v", err)
}
Expand Down Expand Up @@ -186,6 +187,39 @@ func parseKeys(packedKeys string) (private, public interface{}) {
return privateKey, publicKey
}

func getJWTDecodePublicKey() interface{} {
//nolint:lll
jwkStr := `
{
"kty": "RSA",
"n": "0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMstn64tZ_2W-5JsGY4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Ob8YeiKkTiBj0",
"dq": "s9lAH9fggBsoFR8Oac2R_E2gw282rT2kGOAhvIllETE1efrA6huUUvMfBcMpn8lqeW6vzznYY5SSQF7pMdC_agI3nG8Ibp1BUb0JUiraRNqUfLhcQb_d9GF4Dh7e74WbRsobRonujTYN1xCaP6TO61jvWrX-L18txXw494Q_cgk",
"qi": "GyM_p6JrXySiz1toFgKbWV-JdI3jQ4ypu9rbMWx3rQJBfmt0FoYzgUIZEVFEcOqwemRN81zoDAaa-Bk0KWNGDjJHZDdDmFhW3AN7lI-puxk_mHZGJ11rxyR8O55XLSe3SPmRfKwZI6yU24ZxvQKFYItdldUKGzO6Ia6zTKhAVRU",
"alg": "RS256",
"kid": "did:example:0xab#verikey-1"
}
`

jwk := &jose.JSONWebKey{}

err := jwk.UnmarshalJSON([]byte(jwkStr))
if err != nil {
abort("JWK unmarshalling error: %v", err)
}

privateKey, ok := jwk.Key.(*rsa.PrivateKey)
if !ok {
abort("expected to get *rsa.PrivateKey, but got smth different")
}

return privateKey.Public()
}

func encodeVCToJSON(vcBytes []byte) {
credential, _, err := verifiable.NewCredential(vcBytes, verifiable.WithNoCustomSchemaCheck())
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion scripts/run_vc_test_suite.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export PATH=$PATH:`pwd`

# get the suite
rm -rf ${SUITE_DIR}
git clone --depth=1 -q https://github.com/w3c/vc-test-suite suite
# todo clone from https://github.com/w3c/vc-test-suite as soon as https://github.com/w3c/vc-test-suite/pull/102 is merged.
git clone --depth=1 -q https://github.com/kdimak/vc-test-suite -b vc-jwt-with-known-json-web-key suite

# build the suite
cd ${SUITE_DIR}
Expand Down

0 comments on commit 14f9826

Please sign in to comment.