@@ -52,7 +52,7 @@ export function commonAlgorithms({
52
52
'specific cryptosuite proof generation algorithm.' , async function ( ) {
53
53
this . test . link = 'https://w3c.github.io/vc-di-ecdsa/#algorithms:~:text=When%20generating%20ECDSA%20signatures%2C%20the%20signature%20value%20MUST%20be%20expressed%20according%20to%20section%207%20of%20%5BRFC4754%5D%20(sometimes%20referred%20to%20as%20the%20IEEE%20P1363%20format)%20and%20encoded%20according%20to%20the%20specific%20cryptosuite%20proof%20generation%20algorithm' ;
54
54
for ( const [ keyType , fixtures ] of credentials ) {
55
- await assertions . verificationSuccess ( {
55
+ await assertions . verificationFail ( {
56
56
credential : fixtures . get ( 'invalidHash' ) ,
57
57
verifier,
58
58
reason : `Should not verify VC signed w/ ${ keyType } & invalidHash.`
@@ -63,7 +63,7 @@ export function commonAlgorithms({
63
63
it ( 'For P-256 keys, the default hashing function, SHA-2 with 256 ' +
64
64
'bits of output, MUST be used.' , async function ( ) {
65
65
this . test . link = 'https://w3c.github.io/vc-di-ecdsa/#algorithms:~:text=For%20P%2D256%20keys%2C%20the%20default%20hashing%20function%2C%20SHA%2D2%20with%20256%20bits%20of%20output%2C%20MUST%20be%20used.' ;
66
- await assertions . verificationSuccess ( {
66
+ await assertions . verificationFail ( {
67
67
credential : credentials . get ( 'P-256' ) . get ( 'invalidHash' ) ,
68
68
verifier,
69
69
reason : `Should not verify VC with invalid hash.`
@@ -316,14 +316,19 @@ async function _commonSetup({
316
316
} ) ;
317
317
credentials . set ( 'invalidHash' , await issueCloned ( {
318
318
credential : _credential ,
319
- suite : invalidHashProxy ( { suite, suiteName} ) ,
320
- selectiveSuite : invalidHashProxy ( { suite : selectiveSuite , suiteName} )
319
+ suite : invalidHashProxy ( { suite, suiteName, keyType} ) ,
320
+ selectiveSuite : invalidHashProxy ( {
321
+ suite : selectiveSuite ,
322
+ suiteName,
323
+ keyType
324
+ } )
321
325
} ) ) ;
322
326
return credentials ;
323
327
}
324
328
325
329
function invalidHashProxy ( {
326
330
suiteName,
331
+ keyType,
327
332
suite,
328
333
} ) {
329
334
if ( typeof suite !== 'object' ) {
@@ -340,8 +345,7 @@ function invalidHashProxy({
340
345
cryptosuite, document, proof,
341
346
documentLoader, dataIntegrityProof
342
347
} = { } ) {
343
- const algorithm = 'SHA-512' ;
344
-
348
+ const algorithm = ( keyType === 'P-256' ) ? 'sha384' : 'sha256' ;
345
349
const c14nOptions = {
346
350
documentLoader,
347
351
safe : true ,
@@ -355,13 +359,13 @@ function invalidHashProxy({
355
359
// canonize and hash proof
356
360
_canonizeProof ( proof , {
357
361
document, cryptosuite, dataIntegrityProof, c14nOptions
358
- } ) . then ( c14nProofOptions => sha512 ( {
362
+ } ) . then ( c14nProofOptions => sha ( {
359
363
algorithm,
360
364
string : c14nProofOptions
361
365
} ) ) ,
362
366
// canonize and hash document
363
367
cryptosuite . canonize ( document , c14nOptions ) . then (
364
- c14nDocument => sha512 ( { algorithm, string : c14nDocument } ) )
368
+ c14nDocument => sha ( { algorithm, string : c14nDocument } ) )
365
369
] ) ;
366
370
// concatenate hash of c14n proof options and hash of c14n document
367
371
return _concat ( proofHash , docHash ) ;
@@ -381,8 +385,8 @@ function _concat(b1, b2) {
381
385
return rval ;
382
386
}
383
387
384
- export async function sha512 ( { string} ) {
385
- return new Uint8Array ( crypto . createHash ( 'sha512' ) . update ( string ) . digest ( ) ) ;
388
+ export async function sha ( { algorithm , string} ) {
389
+ return new Uint8Array ( crypto . createHash ( algorithm ) . update ( string ) . digest ( ) ) ;
386
390
}
387
391
388
392
async function _canonizeProof ( proof , {
0 commit comments