33 * SPDX-License-Identifier: BSD-3-Clause
44 */
55import {
6+ assertAllUtf8 ,
67 assertDataIntegrityProof ,
78 assertSecuredCredential
89} from './assertions.js' ;
910import {
10- baseCredential ,
11+ generateCredential ,
1112 getProofs ,
13+ isValidDatetime ,
1214 secureCredential ,
1315 setupReportableTestSuite ,
14- setupRow
16+ setupRow ,
17+ verifyFail ,
18+ verifySuccess
1519} from './helpers.js' ;
1620import canonicalize from 'json-canon' ;
1721import chai from 'chai' ;
22+ import { ecdsaJcsVectors } from './vectors.js' ;
1823import { endpoints } from 'vc-test-suite-implementations' ;
1924import { expect } from 'chai' ;
2025
@@ -34,7 +39,7 @@ const {match: verifiers} = endpoints.filterByTag({
3439 property : 'verifiers'
3540} ) ;
3641
37- describe ( 'Create Proof (ecdsa-jcs-2019)' , function ( ) {
42+ describe ( 'Algorithms - Create Proof (ecdsa-jcs-2019)' , function ( ) {
3843 setupReportableTestSuite ( this ) ;
3944 this . implemented = [ ...issuers . keys ( ) ] ;
4045 for ( const [ columnId , { endpoints} ] of issuers ) {
@@ -44,7 +49,7 @@ describe('Create Proof (ecdsa-jcs-2019)', function() {
4449 let proof ;
4550 before ( async function ( ) {
4651 securedCredential = await secureCredential (
47- { issuer, vc : baseCredential ( ) } ) ;
52+ { issuer, vc : generateCredential ( ) } ) ;
4853 proof = getProofs ( securedCredential ) [ 0 ] ;
4954 } ) ;
5055 beforeEach ( setupRow ) ;
@@ -86,18 +91,162 @@ describe('Algorithms - Verify Proof (ecdsa-jcs-2019)', function() {
8691 setupReportableTestSuite ( this ) ;
8792 for ( const [ columnId , { endpoints} ] of verifiers ) {
8893 describe ( columnId , function ( ) {
89- const [ issuer ] = issuers . get ( columnId ) . endpoints ;
9094 const [ verifier ] = endpoints ;
95+ beforeEach ( setupRow ) ;
96+ it ( 'The following algorithm specifies how to verify a ' +
97+ 'data integrity proof given an secured data document. ' +
98+ 'Required inputs are an secured data document (map securedDocument). ' +
99+ 'This algorithm returns a verification result.' ,
100+ async function ( ) {
101+ this . test . link = 'https://www.w3.org/TR/vc-di-ecdsa/#verify-proof-ecdsa-rdfc-2019' ;
102+ for ( const curve of verifier . settings . supportedEcdsaKeyTypes ) {
103+ const testVector = structuredClone ( ecdsaJcsVectors [ curve ] ) ;
104+ await verifySuccess ( verifier , testVector ) ;
105+
106+ // Slice the proof
107+ testVector . proof . proofValue =
108+ testVector . proof . proofValue . slice ( 0 , - 1 ) ;
109+ await verifyFail ( verifier , testVector ) ;
110+ }
111+ } ) ;
112+ } ) ;
113+ }
114+ } ) ;
115+
116+ describe ( 'Algorithms - Transformation' , function ( ) {
117+ setupReportableTestSuite ( this ) ;
118+ this . implemented = [ ...issuers . keys ( ) ] ;
119+ for ( const [ columnId , { endpoints} ] of issuers ) {
120+ describe ( columnId , function ( ) {
121+ const [ issuer ] = endpoints ;
91122 let securedCredential ;
123+ let proof ;
92124 before ( async function ( ) {
93125 securedCredential = await secureCredential (
94- { issuer, vc : baseCredential ( ) } ) ;
126+ { issuer, vc : generateCredential ( ) } ) ;
127+ proof = getProofs ( securedCredential ) [ 0 ] ;
95128 } ) ;
96129 beforeEach ( setupRow ) ;
97- it ( '' ,
98- async function ( ) {
99- this . test . link = 'https://www.w3.org/TR/vc-di-ecdsa/#verify-proof-ecdsa-rdfc-2019' ;
100- } ) ;
130+ it ( 'The proof options MUST contain a type identifier for the ' +
131+ 'cryptographic suite (type) and MAY contain a cryptosuite ' +
132+ 'identifier (cryptosuite).' ,
133+ async function ( ) {
134+ this . test . link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-serialization-ecdsa-jcs-2019' ;
135+ should . exist ( proof . type ,
136+ 'Expected a type identifier on the proof.' ) ;
137+ } ) ;
138+ it ( 'The transformation options MUST contain a type identifier ' +
139+ 'for the cryptographic suite (type) and a cryptosuite identifier ' +
140+ '(cryptosuite).' ,
141+ async function ( ) {
142+ this . test . link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-jcs-2019' ;
143+ should . exist ( proof . type , 'Expected a type identifier on ' +
144+ 'the proof.' ) ;
145+ should . exist ( proof . cryptosuite ,
146+ 'Expected a cryptosuite identifier on the proof.' ) ;
147+ } ) ;
148+ it ( 'Whenever this algorithm encodes strings, ' +
149+ 'it MUST use UTF-8 encoding.' ,
150+ async function ( ) {
151+ this . test . link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-jcs-2019' ;
152+ assertAllUtf8 ( proof ) ;
153+ } ) ;
154+ it ( 'If options.type is not set to the string DataIntegrityProof or ' +
155+ 'options.cryptosuite is not set to the string ecdsa-jcs-2019, ' +
156+ 'an error MUST be raised and SHOULD convey an error type ' +
157+ 'of PROOF_TRANSFORMATION_ERROR.' ,
158+ async function ( ) {
159+ this . test . link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-jcs-2019' ;
160+ should . exist ( proof . type ,
161+ 'Expected a type identifier on the proof.' ) ;
162+ should . exist ( proof . cryptosuite ,
163+ 'Expected a cryptosuite identifier on the proof.' ) ;
164+ proof . type . should . equal ( 'DataIntegrityProof' ,
165+ 'Expected DataIntegrityProof type.' ) ;
166+ proof . cryptosuite . should . equal ( 'ecdsa-jcs-2019' ,
167+ 'Expected ecdsa-jcs-2019 cryptosuite.' ) ;
168+ } ) ;
169+ } ) ;
170+ }
171+ } ) ;
172+
173+ describe ( 'ecdsa-jcs-2019 - Algorithms - Proof Configuration' , function ( ) {
174+ setupReportableTestSuite ( this ) ;
175+ this . implemented = [ ...issuers . keys ( ) ] ;
176+ for ( const [ columnId , { endpoints} ] of issuers ) {
177+ describe ( columnId , function ( ) {
178+ const [ issuer ] = endpoints ;
179+ let securedCredential ;
180+ let proof ;
181+ before ( async function ( ) {
182+ securedCredential = await secureCredential (
183+ { issuer, vc : generateCredential ( ) } ) ;
184+ proof = getProofs ( securedCredential ) [ 0 ] ;
185+ } ) ;
186+ beforeEach ( setupRow ) ;
187+ it ( 'The proof options MUST contain a type identifier for the ' +
188+ 'cryptographic suite (type) and MUST contain a cryptosuite ' +
189+ 'identifier (cryptosuite).' ,
190+ async function ( ) {
191+ this . test . link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-jcs-2019' ;
192+ should . exist ( proof . type ,
193+ 'Expected a type identifier on the proof.' ) ;
194+ should . exist ( proof . cryptosuite ,
195+ 'Expected a cryptosuite identifier on the proof.' ) ;
196+ } ) ;
197+ it ( 'If proofConfig.type is not set to DataIntegrityProof ' +
198+ 'and/or proofConfig.cryptosuite is not set to ecdsa-jcs-2019, ' +
199+ 'an error MUST be raised and SHOULD convey an error type ' +
200+ 'of PROOF_GENERATION_ERROR.' ,
201+ async function ( ) {
202+ this . test . link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-jcs-2019' ;
203+ should . exist ( proof . type ,
204+ 'Expected a type identifier on the proof.' ) ;
205+ should . exist ( proof . cryptosuite ,
206+ 'Expected a cryptosuite identifier on the proof.' ) ;
207+ proof . type . should . equal ( 'DataIntegrityProof' ,
208+ 'Expected DataIntegrityProof type.' ) ;
209+ proof . cryptosuite . should . equal ( 'ecdsa-jcs-2019' ,
210+ 'Expected ecdsa-jcs-2019 cryptosuite.' ) ;
211+ } ) ;
212+ it ( 'If proofConfig.created is set and if the value is not a ' +
213+ 'valid [XMLSCHEMA11-2] datetime, an error MUST be raised and ' +
214+ 'SHOULD convey an error type of PROOF_GENERATION_ERROR.' ,
215+ async function ( ) {
216+ this . test . link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-jcs-2019' ;
217+ if ( proof ?. created ) {
218+ isValidDatetime ( proof . created ) . should . equal (
219+ true ,
220+ 'Expected created value to be a valid datetime string.'
221+ ) ;
222+ }
223+ } ) ;
224+ } ) ;
225+ }
226+ } ) ;
227+
228+ describe ( 'ecdsa-jcs-2019 - Algorithms - Proof Serialization' , function ( ) {
229+ setupReportableTestSuite ( this ) ;
230+ this . implemented = [ ...issuers . keys ( ) ] ;
231+ for ( const [ columnId , { endpoints} ] of issuers ) {
232+ describe ( columnId , function ( ) {
233+ const [ issuer ] = endpoints ;
234+ let securedCredential ;
235+ let proof ;
236+ before ( async function ( ) {
237+ securedCredential = await secureCredential (
238+ { issuer, vc : generateCredential ( ) } ) ;
239+ proof = getProofs ( securedCredential ) [ 0 ] ;
240+ } ) ;
241+ beforeEach ( setupRow ) ;
242+ it ( 'The proof options MUST contain a type identifier for the ' +
243+ 'cryptographic suite (type) and MAY contain a cryptosuite identifier ' +
244+ '(cryptosuite).' ,
245+ async function ( ) {
246+ this . test . link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-serialization-ecdsa-jcs-2019' ;
247+ should . exist ( proof . type ,
248+ 'Expected a type identifier on the proof.' ) ;
249+ } ) ;
101250 } ) ;
102251 }
103252} ) ;
0 commit comments