@@ -23,14 +23,21 @@ import (
2323 "github.com/stretchr/testify/require"
2424
2525 "github.com/hyperledger/aries-framework-go/pkg/crypto/primitive/bbs12381g2pub"
26+ "github.com/hyperledger/aries-framework-go/pkg/crypto/tinkcrypto"
2627 "github.com/hyperledger/aries-framework-go/pkg/doc/ld"
2728 . "github.com/hyperledger/aries-framework-go/pkg/doc/presexch"
2829 "github.com/hyperledger/aries-framework-go/pkg/doc/signature/jsonld"
2930 "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite"
3031 "github.com/hyperledger/aries-framework-go/pkg/doc/signature/suite/bbsblssignature2020"
3132 "github.com/hyperledger/aries-framework-go/pkg/doc/util"
33+ "github.com/hyperledger/aries-framework-go/pkg/doc/util/signature"
3234 "github.com/hyperledger/aries-framework-go/pkg/doc/verifiable"
3335 "github.com/hyperledger/aries-framework-go/pkg/internal/ldtestutil"
36+ "github.com/hyperledger/aries-framework-go/pkg/kms"
37+ "github.com/hyperledger/aries-framework-go/pkg/kms/localkms"
38+ mockkms "github.com/hyperledger/aries-framework-go/pkg/mock/kms"
39+ "github.com/hyperledger/aries-framework-go/pkg/mock/storage"
40+ "github.com/hyperledger/aries-framework-go/pkg/secretlock/noop"
3441)
3542
3643const errMsgSchema = "credentials do not satisfy requirements"
@@ -79,7 +86,66 @@ func TestPresentationDefinition_CreateVP(t *testing.T) {
7986 })
8087
8188 t .Run ("Checks submission requirements" , func (t * testing.T ) {
82- issuerID := uuid .New ().String ()
89+ issuerID := "did:example:76e12ec712ebc6f1c221ebfeb1f"
90+
91+ vc1JWT := & verifiable.Credential {
92+ Issued : util .NewTime (time .Now ()),
93+ Context : []string {verifiable .ContextURI },
94+ Types : []string {verifiable .VCType },
95+ ID : "http://example.edu/credentials/1872" ,
96+ Subject : []verifiable.Subject {{ID : issuerID }},
97+ Issuer : verifiable.Issuer {ID : issuerID },
98+ CustomFields : map [string ]interface {}{
99+ "first_name" : "Jesse" ,
100+ "last_name" : "Travis" ,
101+ "age" : 17 ,
102+ },
103+ // vc as jwt does not use proof, do not set it here.
104+ }
105+
106+ ed25519Signer , err := newCryptoSigner (kms .ED25519Type )
107+ require .NoError (t , err )
108+
109+ vc1JWT .JWT = createEdDSAJWS (t , vc1JWT , ed25519Signer , "76e12ec712ebc6f1c221ebfeb1f" , true )
110+
111+ candidateVCs := []* verifiable.Credential {
112+ vc1JWT ,
113+ {
114+ Context : []string {verifiable .ContextURI },
115+ Types : []string {verifiable .VCType },
116+ ID : "http://example.edu/credentials/1872" ,
117+ CustomFields : map [string ]interface {}{
118+ "first_name" : "Jesse" ,
119+ },
120+ Proofs : []verifiable.Proof {{"type" : "JsonWebSignature2020" }},
121+ },
122+ {
123+ Context : []string {verifiable .ContextURI },
124+ Types : []string {verifiable .VCType },
125+ ID : "http://example.edu/credentials/1872" ,
126+ Subject : []verifiable.Subject {{ID : issuerID }},
127+ Issuer : verifiable.Issuer {ID : issuerID },
128+ CustomFields : map [string ]interface {}{
129+ "first_name" : "Jesse" ,
130+ "last_name" : "Travis" ,
131+ "age" : 17 ,
132+ },
133+ Proofs : []verifiable.Proof {{"type" : "JsonWebSignature2020" }},
134+ },
135+ {
136+ Context : []string {verifiable .ContextURI },
137+ Types : []string {verifiable .VCType },
138+ ID : "http://example.edu/credentials/1872" ,
139+ Subject : []verifiable.Subject {{ID : issuerID }},
140+ Issuer : verifiable.Issuer {ID : issuerID },
141+ CustomFields : map [string ]interface {}{
142+ "first_name" : "Jesse" ,
143+ "last_name" : "Travis" ,
144+ "age" : 2 ,
145+ },
146+ Proofs : []verifiable.Proof {{"type" : "JsonWebSignature2020" }},
147+ },
148+ }
83149
84150 tests := []struct {
85151 name string
@@ -107,6 +173,27 @@ func TestPresentationDefinition_CreateVP(t *testing.T) {
107173 LdpVC : & LdpType {ProofType : []string {"JsonWebSignature2020" }},
108174 },
109175 },
176+ {
177+ name : "test JWT format" ,
178+ format : FormatJWT ,
179+ vFormat : & Format {
180+ Jwt : & JwtType {Alg : []string {"EdDSA" }},
181+ },
182+ },
183+ {
184+ name : "test JWTVC format" ,
185+ format : FormatJWTVC ,
186+ vFormat : & Format {
187+ JwtVC : & JwtType {Alg : []string {"EdDSA" }},
188+ },
189+ },
190+ {
191+ name : "test JWTVP format" ,
192+ format : FormatJWTVP ,
193+ vFormat : & Format {
194+ JwtVP : & JwtType {Alg : []string {"EdDSA" }},
195+ },
196+ },
110197 }
111198
112199 for _ , tc := range tests {
@@ -205,46 +292,7 @@ func TestPresentationDefinition_CreateVP(t *testing.T) {
205292 Format : tc .vFormat ,
206293 }
207294
208- vp , err := pd .CreateVP ([]* verifiable.Credential {
209- {
210- Context : []string {verifiable .ContextURI },
211- Types : []string {verifiable .VCType },
212- ID : uuid .New ().String (),
213- CustomFields : map [string ]interface {}{
214- "first_name" : "Jesse" ,
215- },
216- // since Format in InputDescriptor works only with proofs, need to add it in the vc.
217- Proofs : []verifiable.Proof {{"type" : "JsonWebSignature2020" }},
218- },
219- {
220- Context : []string {verifiable .ContextURI },
221- Types : []string {verifiable .VCType },
222- ID : uuid .New ().String (),
223- Subject : []verifiable.Subject {{ID : issuerID }},
224- Issuer : verifiable.Issuer {ID : issuerID },
225- CustomFields : map [string ]interface {}{
226- "first_name" : "Jesse" ,
227- "last_name" : "Travis" ,
228- "age" : 17 ,
229- },
230- // since Format in InputDescriptor works only with proofs, need to add it in the vc.
231- Proofs : []verifiable.Proof {{"type" : "JsonWebSignature2020" }},
232- },
233- {
234- Context : []string {verifiable .ContextURI },
235- Types : []string {verifiable .VCType },
236- ID : uuid .New ().String (),
237- Subject : []verifiable.Subject {{ID : issuerID }},
238- Issuer : verifiable.Issuer {ID : issuerID },
239- CustomFields : map [string ]interface {}{
240- "first_name" : "Jesse" ,
241- "last_name" : "Travis" ,
242- "age" : 2 ,
243- },
244- // since Format in InputDescriptor works only with proofs, need to add it in the vc.
245- Proofs : []verifiable.Proof {{"type" : "JsonWebSignature2020" }},
246- },
247- }, lddl )
295+ vp , err := pd .CreateVP (candidateVCs , lddl )
248296
249297 require .NoError (t , err )
250298 require .NotNil (t , vp )
@@ -1473,6 +1521,41 @@ func TestPresentationDefinition_CreateVP(t *testing.T) {
14731521 })
14741522}
14751523
1524+ func createEdDSAJWS (t * testing.T , cred * verifiable.Credential , signer verifiable.Signer ,
1525+ keyID string , minimize bool ) string {
1526+ t .Helper ()
1527+
1528+ jwtClaims , err := cred .JWTClaims (minimize )
1529+ require .NoError (t , err )
1530+ vcJWT , err := jwtClaims .MarshalJWS (verifiable .EdDSA , signer , cred .Issuer .ID + "#keys-" + keyID )
1531+ require .NoError (t , err )
1532+
1533+ return vcJWT
1534+ }
1535+
1536+ func createKMS () (* localkms.LocalKMS , error ) {
1537+ p , err := mockkms .NewProviderForKMS (storage .NewMockStoreProvider (), & noop.NoLock {})
1538+ if err != nil {
1539+ return nil , err
1540+ }
1541+
1542+ return localkms .New ("local-lock://custom/master/key/" , p )
1543+ }
1544+
1545+ func newCryptoSigner (keyType kms.KeyType ) (signature.Signer , error ) {
1546+ localKMS , err := createKMS ()
1547+ if err != nil {
1548+ return nil , err
1549+ }
1550+
1551+ tinkCrypto , err := tinkcrypto .New ()
1552+ if err != nil {
1553+ return nil , err
1554+ }
1555+
1556+ return signature .NewCryptoSigner (tinkCrypto , localKMS , keyType )
1557+ }
1558+
14761559func checkSubmission (t * testing.T , vp * verifiable.Presentation , pd * PresentationDefinition ) {
14771560 t .Helper ()
14781561
0 commit comments