33 * SPDX-License-Identifier: BSD-3-Clause
44 */
55import {
6+ assertIssuedVc ,
67 config ,
78 createInitialVc ,
89 createValidCredential ,
@@ -26,6 +27,42 @@ const {match: issuers} = endpoints.filterByTag({
2627 property : 'issuers'
2728} ) ;
2829
30+ describe ( 'ecdsa-jcs-2019 - Algorithms - Create Proof' , function ( ) {
31+ setupReportableTestSuite ( this ) ;
32+ this . implemented = [ ...issuers . keys ( ) ] ;
33+ let validCredential ;
34+ before ( async function ( ) {
35+ validCredential = await createValidCredential ( ) ;
36+ } ) ;
37+ for ( const [ columnId , { endpoints} ] of issuers ) {
38+ describe ( columnId , function ( ) {
39+ const [ issuer ] = endpoints ;
40+ let issuedVc ;
41+ let proofs ;
42+ let filteredProofs = [ ] ;
43+ before ( async function ( ) {
44+ issuedVc = await createInitialVc ( { issuer, vc : validCredential } ) ;
45+ proofs = getProofs ( issuedVc ) ;
46+ if ( proofs ?. length ) {
47+ filteredProofs = proofs . filter (
48+ proof => proof ?. cryptosuite === cryptosuite ) ;
49+ }
50+ } ) ;
51+ beforeEach ( setupRow ) ;
52+ it ( 'If unsecuredDocument.@context is present, ' +
53+ 'set proof.@context to unsecuredDocument.@context.' ,
54+ async function ( ) {
55+ this . test . link = 'https://www.w3.org/TR/vc-di-ecdsa/#create-proof-ecdsa-jcs-2019' ;
56+ assertIssuedVc ( issuedVc , proofs , filteredProofs ) ;
57+ for ( const proof of filteredProofs ) {
58+ proof . should . have ( '@context' ,
59+ 'Expected proof to have context.' ) ;
60+ }
61+ } ) ;
62+ } ) ;
63+ }
64+ } ) ;
65+
2966describe ( 'ecdsa-jcs-2019 - Algorithms - Transformation' , function ( ) {
3067 setupReportableTestSuite ( this ) ;
3168 this . implemented = [ ...issuers . keys ( ) ] ;
@@ -38,30 +75,23 @@ describe('ecdsa-jcs-2019 - Algorithms - Transformation', function() {
3875 const [ issuer ] = endpoints ;
3976 let issuedVc ;
4077 let proofs ;
41- let jcs2019Proofs = [ ] ;
78+ let filteredProofs = [ ] ;
4279 before ( async function ( ) {
4380 issuedVc = await createInitialVc ( { issuer, vc : validCredential } ) ;
4481 proofs = getProofs ( issuedVc ) ;
4582 if ( proofs ?. length ) {
46- jcs2019Proofs = proofs . filter (
83+ filteredProofs = proofs . filter (
4784 proof => proof ?. cryptosuite === cryptosuite ) ;
4885 }
4986 } ) ;
5087 beforeEach ( setupRow ) ;
51- const assertBefore = ( ) => {
52- should . exist ( issuedVc , 'Expected issuer to have issued a ' +
53- 'credential.' ) ;
54- should . exist ( proofs , 'Expected credential to have a proof.' ) ;
55- jcs2019Proofs . length . should . be . gte ( 1 , 'Expected at least one ' +
56- 'ecdsa-jcs-2019 cryptosuite.' ) ;
57- } ;
5888 it ( 'The proof options MUST contain a type identifier for the ' +
59- 'cryptographic suite (type) and MAY contain a cryptosuite ' +
60- 'identifier (cryptosuite).' ,
89+ 'cryptographic suite (type) and MAY contain a cryptosuite ' +
90+ 'identifier (cryptosuite).' ,
6191 async function ( ) {
6292 this . test . link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-serialization-ecdsa-jcs-2019' ;
63- assertBefore ( ) ;
64- for ( const proof of jcs2019Proofs ) {
93+ assertIssuedVc ( issuedVc , proofs , filteredProofs ) ;
94+ for ( const proof of filteredProofs ) {
6595 should . exist ( proof . type ,
6696 'Expected a type identifier on the proof.' ) ;
6797 }
@@ -71,8 +101,8 @@ describe('ecdsa-jcs-2019 - Algorithms - Transformation', function() {
71101 '(cryptosuite).' ,
72102 async function ( ) {
73103 this . test . link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-jcs-2019' ;
74- assertBefore ( ) ;
75- for ( const proof of jcs2019Proofs ) {
104+ assertIssuedVc ( issuedVc , proofs , filteredProofs ) ;
105+ for ( const proof of filteredProofs ) {
76106 should . exist ( proof . type , 'Expected a type identifier on ' +
77107 'the proof.' ) ;
78108 should . exist ( proof . cryptosuite ,
@@ -83,8 +113,8 @@ describe('ecdsa-jcs-2019 - Algorithms - Transformation', function() {
83113 'it MUST use UTF-8 encoding.' ,
84114 async function ( ) {
85115 this . test . link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-jcs-2019' ;
86- assertBefore ( ) ;
87- for ( const proof of jcs2019Proofs ) {
116+ assertIssuedVc ( issuedVc , proofs , filteredProofs ) ;
117+ for ( const proof of filteredProofs ) {
88118 should . exist ( proof ?. proofValue ,
89119 'Expected proofValue to exist.' ) ;
90120 isValidUtf8 ( proof . proofValue ) . should . equal (
@@ -94,13 +124,13 @@ describe('ecdsa-jcs-2019 - Algorithms - Transformation', function() {
94124 }
95125 } ) ;
96126 it ( 'If options.type is not set to the string DataIntegrityProof or ' +
97- 'options.cryptosuite is not set to the string ecdsa-jcs-2019, ' +
98- 'an error MUST be raised and SHOULD convey an error type ' +
99- 'of PROOF_TRANSFORMATION_ERROR.' ,
127+ 'options.cryptosuite is not set to the string ecdsa-jcs-2019, ' +
128+ 'an error MUST be raised and SHOULD convey an error type ' +
129+ 'of PROOF_TRANSFORMATION_ERROR.' ,
100130 async function ( ) {
101131 this . test . link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-jcs-2019' ;
102- assertBefore ( ) ;
103- for ( const proof of jcs2019Proofs ) {
132+ assertIssuedVc ( issuedVc , proofs , filteredProofs ) ;
133+ for ( const proof of filteredProofs ) {
104134 should . exist ( proof . type ,
105135 'Expected a type identifier on the proof.' ) ;
106136 should . exist ( proof . cryptosuite ,
@@ -127,30 +157,23 @@ describe('ecdsa-jcs-2019 - Algorithms - Proof Configuration', function() {
127157 const [ issuer ] = endpoints ;
128158 let issuedVc ;
129159 let proofs ;
130- let jcs2019Proofs = [ ] ;
160+ let filteredProofs = [ ] ;
131161 before ( async function ( ) {
132162 issuedVc = await createInitialVc ( { issuer, vc : validCredential } ) ;
133163 proofs = getProofs ( issuedVc ) ;
134164 if ( proofs ?. length ) {
135- jcs2019Proofs = proofs . filter (
165+ filteredProofs = proofs . filter (
136166 proof => proof ?. cryptosuite === cryptosuite ) ;
137167 }
138168 } ) ;
139169 beforeEach ( setupRow ) ;
140- const assertBefore = ( ) => {
141- should . exist ( issuedVc , 'Expected issuer to have issued a ' +
142- 'credential.' ) ;
143- should . exist ( proofs , 'Expected credential to have a proof.' ) ;
144- jcs2019Proofs . length . should . be . gte ( 1 , 'Expected at least one ' +
145- 'ecdsa-jcs-2019 cryptosuite.' ) ;
146- } ;
147170 it ( 'The proof options MUST contain a type identifier for the ' +
148171 'cryptographic suite (type) and MUST contain a cryptosuite ' +
149172 'identifier (cryptosuite).' ,
150173 async function ( ) {
151174 this . test . link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-jcs-2019' ;
152- assertBefore ( ) ;
153- for ( const proof of jcs2019Proofs ) {
175+ assertIssuedVc ( issuedVc , proofs , filteredProofs ) ;
176+ for ( const proof of filteredProofs ) {
154177 should . exist ( proof . type ,
155178 'Expected a type identifier on the proof.' ) ;
156179 should . exist ( proof . cryptosuite ,
@@ -163,8 +186,8 @@ describe('ecdsa-jcs-2019 - Algorithms - Proof Configuration', function() {
163186 'of PROOF_GENERATION_ERROR.' ,
164187 async function ( ) {
165188 this . test . link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-jcs-2019' ;
166- assertBefore ( ) ;
167- for ( const proof of jcs2019Proofs ) {
189+ assertIssuedVc ( issuedVc , proofs , filteredProofs ) ;
190+ for ( const proof of filteredProofs ) {
168191 should . exist ( proof . type ,
169192 'Expected a type identifier on the proof.' ) ;
170193 should . exist ( proof . cryptosuite ,
@@ -180,7 +203,8 @@ describe('ecdsa-jcs-2019 - Algorithms - Proof Configuration', function() {
180203 'SHOULD convey an error type of PROOF_GENERATION_ERROR.' ,
181204 async function ( ) {
182205 this . test . link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-jcs-2019' ;
183- for ( const proof of jcs2019Proofs ) {
206+ assertIssuedVc ( issuedVc , proofs , filteredProofs ) ;
207+ for ( const proof of filteredProofs ) {
184208 if ( proof ?. created ) {
185209 isValidDatetime ( proof . created ) . should . equal (
186210 true ,
@@ -205,30 +229,23 @@ describe('ecdsa-jcs-2019 - Algorithms - Proof Serialization', function() {
205229 const [ issuer ] = endpoints ;
206230 let issuedVc ;
207231 let proofs ;
208- let jcs2019Proofs = [ ] ;
232+ let filteredProofs = [ ] ;
209233 before ( async function ( ) {
210234 issuedVc = await createInitialVc ( { issuer, vc : validCredential } ) ;
211235 proofs = getProofs ( issuedVc ) ;
212236 if ( proofs ?. length ) {
213- jcs2019Proofs = proofs . filter (
237+ filteredProofs = proofs . filter (
214238 proof => proof ?. cryptosuite === cryptosuite ) ;
215239 }
216240 } ) ;
217241 beforeEach ( setupRow ) ;
218- const assertBefore = ( ) => {
219- should . exist ( issuedVc , 'Expected issuer to have issued a ' +
220- 'credential.' ) ;
221- should . exist ( proofs , 'Expected credential to have a proof.' ) ;
222- jcs2019Proofs . length . should . be . gte ( 1 , 'Expected at least one ' +
223- 'ecdsa-jcs-2019 cryptosuite.' ) ;
224- } ;
225242 it ( 'The proof options MUST contain a type identifier for the ' +
226243 'cryptographic suite (type) and MAY contain a cryptosuite identifier ' +
227244 '(cryptosuite).' ,
228245 async function ( ) {
229246 this . test . link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-serialization-ecdsa-jcs-2019' ;
230- assertBefore ( ) ;
231- for ( const proof of jcs2019Proofs ) {
247+ assertIssuedVc ( issuedVc , proofs , filteredProofs ) ;
248+ for ( const proof of filteredProofs ) {
232249 should . exist ( proof . type ,
233250 'Expected a type identifier on the proof.' ) ;
234251 }
0 commit comments