22 * Copyright 2024 Digital Bazaar, Inc.
33 * SPDX-License-Identifier: BSD-3-Clause
44 */
5+ import {
6+ assertAllUtf8 ,
7+ assertCryptosuiteProof ,
8+ assertDataIntegrityProof
9+ } from './assertions.js' ;
510import {
611 generateCredential ,
712 isValidDatetime ,
813 proofExists ,
914 secureCredential ,
1015 setupReportableTestSuite ,
11- setupRow
16+ setupRow ,
17+ verifyError ,
18+ verifySuccess
1219} from './helpers.js' ;
13- import {
14- assertAllUtf8
15- } from './assertions.js' ;
1620import chai from 'chai' ;
21+ import { ecdsaRdfcVectors } from './vectors.js' ;
1722import { endpoints } from 'vc-test-suite-implementations' ;
23+ import { expect } from 'chai' ;
1824
1925const should = chai . should ( ) ;
2026
@@ -27,6 +33,74 @@ const {match: issuers} = endpoints.filterByTag({
2733 property : 'issuers'
2834} ) ;
2935
36+ const { match : verifiers } = endpoints . filterByTag ( {
37+ tags : cryptosuites ,
38+ property : 'verifiers'
39+ } ) ;
40+
41+ describe ( 'Algorithms - Create Proof (ecdsa-rdfc-2019)' , function ( ) {
42+ setupReportableTestSuite ( this ) ;
43+ this . implemented = [ ...issuers . keys ( ) ] ;
44+ for ( const [ columnId , { endpoints} ] of issuers ) {
45+ describe ( columnId , function ( ) {
46+ const [ issuer ] = endpoints ;
47+ let securedCredential ;
48+ before ( async function ( ) {
49+ securedCredential = await secureCredential (
50+ { issuer, vc : generateCredential ( ) } ) ;
51+ } ) ;
52+ beforeEach ( setupRow ) ;
53+ it ( 'A data integrity proof (map), or an error, is produced as output.' ,
54+ async function ( ) {
55+ this . test . link = 'https://www.w3.org/TR/vc-di-ecdsa/#create-proof-ecdsa-rdfc-2019' ;
56+ const proof = proofExists ( securedCredential ) ;
57+ assertDataIntegrityProof ( proof , 'ecdsa-rdfc-2019' ) ;
58+ // Since we are not sending proof options, we only do a positive test
59+ } ) ;
60+ it ( 'Let proof.proofValue be a base58-btc-encoded ' +
61+ 'Multibase value of the proofBytes.' ,
62+ async function ( ) {
63+ this . test . link = 'https://www.w3.org/TR/vc-di-ecdsa/#create-proof-ecdsa-rdfc-2019' ;
64+ // Shallow multibase test
65+ // TODO try decoding
66+ const proof = proofExists ( securedCredential ) ;
67+ should . exist ( proof . proofValue ,
68+ 'Expected proof to have proofValue.' ) ;
69+ expect ( proof . proofValue . startsWith ( 'z' ) ) . to . be . true ;
70+ } ) ;
71+ } ) ;
72+ }
73+ } ) ;
74+
75+ describe ( 'Algorithms - Verify Proof (ecdsa-rdfc-2019)' , function ( ) {
76+ setupReportableTestSuite ( this ) ;
77+ for ( const [ columnId , { endpoints} ] of verifiers ) {
78+ describe ( columnId , function ( ) {
79+ const [ verifier ] = endpoints ;
80+ beforeEach ( setupRow ) ;
81+ it ( 'The following algorithm specifies how to verify a ' +
82+ 'data integrity proof given an secured data document. ' +
83+ 'Required inputs are an secured data document (map securedDocument). ' +
84+ 'This algorithm returns a verification result.' ,
85+ async function ( ) {
86+ this . test . link = 'https://www.w3.org/TR/vc-di-ecdsa/#verify-proof-ecdsa-rdfc-2019' ;
87+ for ( const curve of verifier . settings . supportedEcdsaKeyTypes ) {
88+ // Send a valid VC and an invalid VC to the verifier
89+ // Check for success/error on response
90+ const testVector = structuredClone ( ecdsaRdfcVectors [ curve ] ) ;
91+ await verifySuccess ( verifier , testVector ) ;
92+
93+ // Slice the proof
94+ testVector . proof . proofValue =
95+ testVector . proof . proofValue . slice ( 0 , - 1 ) ;
96+ await verifyError ( verifier , testVector ) ;
97+ // TODO, create a verifyProblemDetails function
98+ }
99+ } ) ;
100+ } ) ;
101+ }
102+ } ) ;
103+
30104describe ( 'Algorithms - Transformation (ecdsa-rdfc-2019)' , function ( ) {
31105 setupReportableTestSuite ( this ) ;
32106 this . implemented = [ ...issuers . keys ( ) ] ;
@@ -40,8 +114,8 @@ describe('Algorithms - Transformation (ecdsa-rdfc-2019)', function() {
40114 } ) ;
41115 beforeEach ( setupRow ) ;
42116 it ( 'The transformation options MUST contain a type identifier ' +
43- 'for the cryptographic suite (type) and a cryptosuite identifier ' +
44- '(cryptosuite).' ,
117+ 'for the cryptographic suite (type) and a cryptosuite identifier ' +
118+ '(cryptosuite).' ,
45119 async function ( ) {
46120 this . test . link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-rdfc-2019' ;
47121 const proof = proofExists ( securedCredential ) ;
@@ -50,28 +124,20 @@ describe('Algorithms - Transformation (ecdsa-rdfc-2019)', function() {
50124 should . exist ( proof . cryptosuite ,
51125 'Expected a cryptosuite identifier on the proof.' ) ;
52126 } ) ;
53- it ( 'Whenever this algorithm encodes strings, ' +
54- 'it MUST use UTF-8 encoding.' ,
55- async function ( ) {
56- this . test . link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-rdfc-2019' ;
57- const proof = proofExists ( securedCredential ) ;
58- assertAllUtf8 ( proof ) ;
59- } ) ;
127+ it ( 'Whenever this algorithm encodes strings, it MUST use UTF-8 encoding.' ,
128+ async function ( ) {
129+ this . test . link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-rdfc-2019' ;
130+ const proof = proofExists ( securedCredential ) ;
131+ assertAllUtf8 ( proof ) ;
132+ } ) ;
60133 it ( 'If options.type is not set to the string DataIntegrityProof or ' +
61134 'options.cryptosuite is not set to the string ecdsa-rdfc-2019, ' +
62135 'an error MUST be raised and SHOULD convey an error type ' +
63136 'of PROOF_TRANSFORMATION_ERROR.' ,
64137 async function ( ) {
65138 this . test . link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-rdfc-2019' ;
66139 const proof = proofExists ( securedCredential ) ;
67- should . exist ( proof . type ,
68- 'Expected a type identifier on the proof.' ) ;
69- should . exist ( proof . cryptosuite ,
70- 'Expected a cryptosuite identifier on the proof.' ) ;
71- proof . type . should . equal ( 'DataIntegrityProof' ,
72- 'Expected DataIntegrityProof type.' ) ;
73- proof . cryptosuite . should . equal ( 'ecdsa-rdfc-2019' ,
74- 'Expected ecdsa-rdfc-2019 cryptosuite.' ) ;
140+ assertCryptosuiteProof ( proof , 'ecdsa-rdfc-2019' ) ;
75141 } ) ;
76142 } ) ;
77143 }
@@ -107,14 +173,7 @@ describe('Algorithms - Proof Configuration (ecdsa-rdfc-2019)', function() {
107173 async function ( ) {
108174 this . test . link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-rdfc-2019' ;
109175 const proof = proofExists ( securedCredential ) ;
110- should . exist ( proof . type ,
111- 'Expected a type identifier on the proof.' ) ;
112- should . exist ( proof . cryptosuite ,
113- 'Expected a cryptosuite identifier on the proof.' ) ;
114- proof . type . should . equal ( 'DataIntegrityProof' ,
115- 'Expected DataIntegrityProof type.' ) ;
116- proof . cryptosuite . should . equal ( 'ecdsa-rdfc-2019' ,
117- 'Expected ecdsa-rdfc-2019 cryptosuite.' ) ;
176+ assertCryptosuiteProof ( proof , 'ecdsa-rdfc-2019' ) ;
118177 } ) ;
119178 it ( 'If proofConfig.created is set and if the value is not a ' +
120179 'valid [XMLSCHEMA11-2] datetime, an error MUST be raised and ' +
0 commit comments