9
9
generateCredential ,
10
10
generateEnvelope ,
11
11
secureCredential ,
12
- setupMatrix
12
+ setupMatrix ,
13
+ verifyCredential ,
14
+ verifyPresentation
13
15
} from './helpers.js' ;
14
16
import {
15
17
vc_jwt ,
@@ -18,7 +20,6 @@ import {
18
20
import assert from 'node:assert/strict' ;
19
21
import chai from 'chai' ;
20
22
import { filterByTag } from 'vc-test-suite-implementations' ;
21
- import { TestEndpoints } from './TestEndpoints.js' ;
22
23
23
24
const should = chai . should ( ) ;
24
25
@@ -29,17 +30,16 @@ const {match} = filterByTag({tags: [tag]});
29
30
describe ( 'Enveloped Verifiable Credentials' , function ( ) {
30
31
setupMatrix . call ( this , match ) ;
31
32
for ( const [ name , implementation ] of match ) {
32
- const endpoints = new TestEndpoints ( { implementation, tag} ) ;
33
33
const issuer = implementation . issuers ?. find (
34
34
issuer => issuer . tags . has ( tag ) ) || null ;
35
35
const verifier = implementation . verifiers ?. find (
36
36
verifier => verifier . tags . has ( tag ) ) || null ;
37
37
38
38
describe ( name , function ( ) {
39
- let envelopedCredential ;
39
+ let verifiableCredential ;
40
40
let negativeFixture ;
41
41
before ( async function ( ) {
42
- envelopedCredential = generateEnvelope ( {
42
+ verifiableCredential = generateEnvelope ( {
43
43
type : 'EnvelopedVerifiableCredential' ,
44
44
id : `data:application/vc+jwt,${ vc_jwt } `
45
45
} ) ;
@@ -57,22 +57,26 @@ describe('Enveloped Verifiable Credentials', function() {
57
57
{ issuer, credential : generateCredential ( ) } ) ;
58
58
should . exist ( issuedVc , 'Expected credential to be issued.' ) ;
59
59
issuedVc . should . have . property ( '@context' ) ;
60
+ verifiableCredential = issuedVc ;
60
61
}
61
62
if ( verifier ) {
62
- await assert . doesNotReject ( endpoints . verify ( envelopedCredential ) ,
63
+ await assert . doesNotReject (
64
+ verifyCredential ( { verifier, verifiableCredential} ) ,
63
65
'Failed to accept an enveloped VC.' ) ;
64
66
65
67
// Replace context with an empty array
66
- negativeFixture = structuredClone ( envelopedCredential ) ;
68
+ negativeFixture = structuredClone ( verifiableCredential ) ;
67
69
negativeFixture [ '@context' ] = [ ] ;
68
- await assert . rejects ( endpoints . verify ( negativeFixture ) ,
69
- 'Failed to reject an enveloped VC with an empty context.' ) ;
70
+ await assert . rejects (
71
+ verifyCredential ( { verifier, negativeFixture} ) ,
72
+ 'Failed to reject an enveloped VC with invalid context.' ) ;
70
73
71
74
// Replace context with an invalid value
72
- negativeFixture = structuredClone ( envelopedCredential ) ;
75
+ negativeFixture = structuredClone ( verifiableCredential ) ;
73
76
negativeFixture [ '@context' ] = 'https://www.w3.org/ns/credentials/examples/v2' ;
74
- await assert . rejects ( endpoints . verify ( negativeFixture ) ,
75
- 'Failed to reject an enveloped VC with an invalid context.' ) ;
77
+ await assert . rejects (
78
+ verifyCredential ( { verifier, negativeFixture} ) ,
79
+ 'Failed to reject an enveloped VC with invalid context.' ) ;
76
80
}
77
81
} ) ;
78
82
@@ -85,18 +89,19 @@ describe('Enveloped Verifiable Credentials', function() {
85
89
const issuedVc = await secureCredential (
86
90
{ issuer, credential : generateCredential ( ) } ) ;
87
91
should . exist ( issuedVc , 'Expected credential to be issued.' ) ;
88
- issuedVc . should . have . property ( 'id' ) . that . does
89
- . include ( 'data:' ,
90
- `Expecting id field to be a 'data:' scheme URL [RFC2397].` ) ;
92
+ issuedVc . should . have . property ( '@context' ) ;
93
+ verifiableCredential = issuedVc ;
91
94
}
92
95
if ( verifier ) {
93
- await assert . doesNotReject ( endpoints . verify ( envelopedCredential ) ,
96
+ await assert . doesNotReject (
97
+ verifyCredential ( { verifier, verifiableCredential} ) ,
94
98
'Failed to accept an enveloped VC.' ) ;
95
99
96
100
// Remove data uri portion of the id field
97
- negativeFixture = structuredClone ( envelopedCredential ) ;
101
+ negativeFixture = structuredClone ( verifiableCredential ) ;
98
102
negativeFixture . id = negativeFixture . id . split ( ',' ) . pop ( ) ;
99
- await assert . rejects ( endpoints . verify ( negativeFixture ) ,
103
+ await assert . rejects (
104
+ verifyCredential ( { verifier, negativeFixture} ) ,
100
105
'Failed to reject an enveloped VC with an invalid data url id.' ) ;
101
106
}
102
107
} ) ;
@@ -108,25 +113,27 @@ describe('Enveloped Verifiable Credentials', function() {
108
113
const issuedVc = await secureCredential (
109
114
{ issuer, credential : generateCredential ( ) } ) ;
110
115
should . exist ( issuedVc , 'Expected credential to be issued.' ) ;
111
- issuedVc . should . have . property ( 'type' ) . that . is . equal (
112
- 'EnvelopedVerifiableCredential' ,
113
- `Expecting type field to be EnvelopedVerifiableCredential` ) ;
116
+ issuedVc . should . have . property ( '@context' ) ;
117
+ verifiableCredential = issuedVc ;
114
118
}
115
119
if ( verifier ) {
116
- await assert . doesNotReject ( endpoints . verify ( envelopedCredential ) ,
120
+ await assert . doesNotReject (
121
+ verifyCredential ( { verifier, verifiableCredential} ) ,
117
122
'Failed to accept an enveloped VC.' ) ;
118
123
119
124
// Remove type field
120
- negativeFixture = structuredClone ( envelopedCredential ) ;
125
+ negativeFixture = structuredClone ( verifiableCredential ) ;
121
126
delete negativeFixture . type ;
122
- await assert . rejects ( endpoints . verify ( negativeFixture ) ,
127
+ await assert . rejects (
128
+ verifyCredential ( { verifier, negativeFixture} ) ,
123
129
'Failed to reject an enveloped VC with an enveloped VC with a ' +
124
130
'missing `type`.' ) ;
125
131
126
132
// Replace type field
127
- negativeFixture = structuredClone ( envelopedCredential ) ;
128
- negativeFixture . type = [ 'VerifiableCredential' ] ;
129
- await assert . rejects ( endpoints . verify ( negativeFixture ) ,
133
+ negativeFixture = structuredClone ( verifiableCredential ) ;
134
+ negativeFixture . type = 'VerifiableCredential' ;
135
+ await assert . rejects (
136
+ verifyCredential ( { verifier, negativeFixture} ) ,
130
137
'Failed to reject an enveloped VC with an ' +
131
138
'invalid `type`.' ) ;
132
139
}
@@ -139,17 +146,16 @@ describe('Enveloped Verifiable Credentials', function() {
139
146
describe ( 'Enveloped Verifiable Presentations' , function ( ) {
140
147
setupMatrix . call ( this , match ) ;
141
148
for ( const [ name , implementation ] of match ) {
142
- const endpoints = new TestEndpoints ( { implementation, tag} ) ;
143
149
const vpVerifier = implementation . vpVerifiers ?. find (
144
150
vpVerifier => vpVerifier . tags . has ( tag ) ) || null ;
145
151
146
152
describe ( name , function ( ) {
147
- let envelopedPresentation ;
153
+ let verifiablePresentation ;
148
154
let negativeFixture ;
149
155
before ( async function ( ) {
150
- envelopedPresentation = generateEnvelope ( {
156
+ verifiablePresentation = generateEnvelope ( {
151
157
type : 'EnvelopedVerifiablePresentation' ,
152
- id : `data:application/vp+ jwt,${ vp_jwt } `
158
+ id : `data:application/jwt,${ vp_jwt } `
153
159
} ) ;
154
160
} ) ;
155
161
beforeEach ( addPerTestMetadata ) ;
@@ -162,21 +168,22 @@ describe('Enveloped Verifiable Presentations', function() {
162
168
this . test . link = `https://w3c.github.io/vc-data-model/#enveloped-verifiable-presentations:~:text=The%20%40context%20property%20of%20the%20object%20MUST%20be%20present%20and%20include%20a%20context%2C%20such%20as%20the%20base%20context%20for%20this%20specification%2C%20that%20defines%20at%20least%20the%20id%2C%20type%2C%20and%20EnvelopedVerifiablePresentation%20terms%20as%20defined%20by%20the%20base%20context%20provided%20by%20this%20specification.` ;
163
169
164
170
if ( vpVerifier ) {
165
- await assert . doesNotReject ( endpoints . verifyVp ( envelopedPresentation ) ,
171
+ await assert . doesNotReject (
172
+ verifyPresentation ( { vpVerifier, verifiablePresentation} ) ,
166
173
'Failed to accept an enveloped VP.' ) ;
167
174
168
175
// Replace context field with empty array
169
- negativeFixture = structuredClone ( envelopedPresentation ) ;
176
+ negativeFixture = structuredClone ( verifiablePresentation ) ;
170
177
negativeFixture [ '@context' ] = [ ] ;
171
178
await assert . rejects (
172
- endpoints . verifyVp ( negativeFixture ) ,
179
+ verifyPresentation ( { vpVerifier , negativeFixture} ) ,
173
180
'Failed to reject Enveloped VP missing contexts.' ) ;
174
181
175
182
// Replace context field with invalid context
176
- negativeFixture = structuredClone ( envelopedPresentation ) ;
183
+ negativeFixture = structuredClone ( verifiablePresentation ) ;
177
184
negativeFixture [ '@context' ] = [ 'https://www.w3.org/ns/credentials/examples/v2' ] ;
178
185
await assert . rejects (
179
- endpoints . verifyVp ( negativeFixture ) ,
186
+ verifyPresentation ( { vpVerifier , negativeFixture} ) ,
180
187
'Failed to reject Enveloped VP missing contexts.' ) ;
181
188
}
182
189
} ) ;
@@ -188,14 +195,15 @@ describe('Enveloped Verifiable Presentations', function() {
188
195
this . test . link = `https://w3c.github.io/vc-data-model/#enveloped-verifiable-presentations:~:text=The%20id%20value%20of%20the%20object%20MUST%20be%20a%20data%3A%20URL%20%5BRFC2397%5D%20that%20expresses%20a%20secured%20verifiable%20presentation%20using%20an%20enveloping%20securing%20mechanism%2C%20such%20as%20Securing%20Verifiable%20Credentials%20using%20JOSE%20and%20COSE%20%5BVC%2DJOSE%2DCOSE%5D.` ;
189
196
190
197
if ( vpVerifier ) {
191
- await assert . doesNotReject ( endpoints . verifyVp ( envelopedPresentation ) ,
198
+ await assert . doesNotReject (
199
+ verifyPresentation ( { vpVerifier, verifiablePresentation} ) ,
192
200
'Failed to accept an enveloped VP.' ) ;
193
201
194
202
// Remove data uri portion from id field
195
- negativeFixture = structuredClone ( envelopedPresentation ) ;
203
+ negativeFixture = structuredClone ( verifiablePresentation ) ;
196
204
negativeFixture . id = negativeFixture . id . split ( ',' ) . pop ( ) ;
197
205
await assert . rejects (
198
- endpoints . verifyVp ( negativeFixture ) ,
206
+ verifyPresentation ( { vpVerifier , negativeFixture} ) ,
199
207
'Failed to reject Enveloped VP with an id that is not a data url.' ) ;
200
208
}
201
209
} ) ;
@@ -205,14 +213,15 @@ describe('Enveloped Verifiable Presentations', function() {
205
213
this . test . link = `https://w3c.github.io/vc-data-model/#enveloped-verifiable-presentations:~:text=The%20type%20value%20of%20the%20object%20MUST%20be%20EnvelopedVerifiablePresentation.` ;
206
214
207
215
if ( vpVerifier ) {
208
- await assert . doesNotReject ( endpoints . verifyVp ( envelopedPresentation ) ,
216
+ await assert . doesNotReject (
217
+ verifyPresentation ( { vpVerifier, verifiablePresentation} ) ,
209
218
'Failed to accept an enveloped VP.' ) ;
210
219
211
220
// Replace type field
212
- negativeFixture = structuredClone ( envelopedPresentation ) ;
221
+ negativeFixture = structuredClone ( verifiablePresentation ) ;
213
222
negativeFixture . type = [ 'VerifiablePresentation' ] ;
214
223
await assert . rejects (
215
- endpoints . verifyVp ( negativeFixture ) ,
224
+ verifyPresentation ( { vpVerifier , negativeFixture} ) ,
216
225
'Failed to reject VP w/o type "EnvelopedVerifiablePresentation".' ) ;
217
226
}
218
227
} ) ;
0 commit comments