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

Commit 14f9826

Browse files
committed
fix: Pass VC Test Suite where JWS is passed as input data
closes #947 Signed-off-by: Dima <dkinoshenko@gmail.com>
1 parent 92ac19f commit 14f9826

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

pkg/doc/verifiable/test-suite/verifiable_suite_test.go

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ func encodeVCToJWS(vcBytes []byte, privateKey interface{}) {
9191
}
9292

9393
func encodeVPToJWS(vpBytes []byte, audience string, privateKey interface{}) {
94-
vp, err := verifiable.NewPresentation(vpBytes, verifiable.WithPresSkippedEmbeddedProofCheck())
94+
vp, err := verifiable.NewPresentation(vpBytes,
95+
verifiable.WithPresSkippedEmbeddedProofCheck(),
96+
// the public key is used to decode verifiable credentials passed as JWS to the presentation
97+
verifiable.WithPresPublicKeyFetcher(verifiable.SingleKey(getJWTDecodePublicKey())))
9598
if err != nil {
9699
abort("failed to decode presentation: %v", err)
97100
}
@@ -128,9 +131,7 @@ func encodeVCToJWTUnsecured(vcBytes []byte) {
128131
func decodeVCJWTToJSON(vcBytes []byte, publicKey interface{}) {
129132
// Asked to decode JWT
130133
credential, _, err := verifiable.NewCredential(vcBytes,
131-
verifiable.WithPublicKeyFetcher(func(issuerID, keyID string) (interface{}, error) {
132-
return publicKey, nil
133-
}))
134+
verifiable.WithPublicKeyFetcher(verifiable.SingleKey(publicKey)))
134135
if err != nil {
135136
abort("failed to decode credential: %v", err)
136137
}
@@ -186,6 +187,39 @@ func parseKeys(packedKeys string) (private, public interface{}) {
186187
return privateKey, publicKey
187188
}
188189

190+
func getJWTDecodePublicKey() interface{} {
191+
//nolint:lll
192+
jwkStr := `
193+
{
194+
"kty": "RSA",
195+
"n": "0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebW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A77Qe_NmtuYZc3C3m3I24G2GvR5sSDxUyAN2zq8Lfn9EUms6rY3Ob8YeiKkTiBj0",
201+
"dq": "s9lAH9fggBsoFR8Oac2R_E2gw282rT2kGOAhvIllETE1efrA6huUUvMfBcMpn8lqeW6vzznYY5SSQF7pMdC_agI3nG8Ibp1BUb0JUiraRNqUfLhcQb_d9GF4Dh7e74WbRsobRonujTYN1xCaP6TO61jvWrX-L18txXw494Q_cgk",
202+
"qi": "GyM_p6JrXySiz1toFgKbWV-JdI3jQ4ypu9rbMWx3rQJBfmt0FoYzgUIZEVFEcOqwemRN81zoDAaa-Bk0KWNGDjJHZDdDmFhW3AN7lI-puxk_mHZGJ11rxyR8O55XLSe3SPmRfKwZI6yU24ZxvQKFYItdldUKGzO6Ia6zTKhAVRU",
203+
"alg": "RS256",
204+
"kid": "did:example:0xab#verikey-1"
205+
}
206+
`
207+
208+
jwk := &jose.JSONWebKey{}
209+
210+
err := jwk.UnmarshalJSON([]byte(jwkStr))
211+
if err != nil {
212+
abort("JWK unmarshalling error: %v", err)
213+
}
214+
215+
privateKey, ok := jwk.Key.(*rsa.PrivateKey)
216+
if !ok {
217+
abort("expected to get *rsa.PrivateKey, but got smth different")
218+
}
219+
220+
return privateKey.Public()
221+
}
222+
189223
func encodeVCToJSON(vcBytes []byte) {
190224
credential, _, err := verifiable.NewCredential(vcBytes, verifiable.WithNoCustomSchemaCheck())
191225
if err != nil {

scripts/run_vc_test_suite.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export PATH=$PATH:`pwd`
3131

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

3637
# build the suite
3738
cd ${SUITE_DIR}

0 commit comments

Comments
 (0)