@@ -330,22 +330,40 @@ export async function revokeDocumentHashOnChain(
330
330
res : express . Response
331
331
) {
332
332
try {
333
- const fileHash = req ?. body . filehash ;
334
- if ( ! fileHash ) {
335
- return res . status ( 400 ) . json ( { err : 'No file uploaded' } ) ;
336
- }
333
+ const fileHash = req ?. body . filehash ;
334
+ const identifierReq = req ?. body . identifier ;
335
+ let statementUri = `` ;
337
336
const api = Cord . ConfigService . get ( 'api' ) ;
338
-
339
- const space = Cord . Identifier . uriToIdentifier ( CHAIN_SPACE_ID ) ;
340
- const identifierencoded = await api . query . statement . identifierLookup (
341
- fileHash as `0x${string } `,
342
- space
337
+ if ( fileHash ) {
338
+ const space = Cord . Identifier . uriToIdentifier ( CHAIN_SPACE_ID ) ;
339
+ const identifierencoded = await api . query . statement . identifierLookup (
340
+ fileHash as `0x${string } `,
341
+ space
342
+ ) ;
343
+ const identifier = identifierencoded . toHuman ( ) ;
344
+ const digest = fileHash . replace ( / ^ 0 x / , '' ) ;
345
+ statementUri = `stmt:cord:${ identifier } :${ digest } ` ;
346
+ } else if ( identifierReq ) {
347
+ const statementDetails = await Cord . Statement . getDetailsfromChain (
348
+ identifierReq
349
+ ) ;
350
+ const digest = statementDetails ?. digest . replace ( / ^ 0 x / , '' ) ;
351
+ statementUri = `${ statementDetails ?. uri } :${ digest } ` ;
352
+ } else {
353
+ return res
354
+ . status ( 400 )
355
+ . json ( { err : 'File hash or identifier is required for revoke' } ) ;
356
+ }
357
+ const statementStatus = await Cord . Statement . fetchStatementDetailsfromChain (
358
+ statementUri as `stmt:cord:${string } `
343
359
) ;
344
- const identifier = identifierencoded . toHuman ( ) ;
345
- const digest = fileHash . replace ( / ^ 0 x / , "" ) ;
346
- const statmentid = `stmt:cord:${ identifier } :${ digest } `
347
- const statement1 = await Cord . Statement . dispatchRevokeToChain (
348
- statmentid as `stmt:cord:${string } `,
360
+ if ( statementStatus ?. revoked ) {
361
+ return res
362
+ . status ( 400 )
363
+ . json ( { err : 'Document is already revoked on chain' } ) ;
364
+ }
365
+ const revokeResponse = await Cord . Statement . dispatchRevokeToChain (
366
+ statementUri as `stmt:cord:${string } `,
349
367
issuerDid . uri ,
350
368
authorIdentity ,
351
369
CHAIN_SPACE_AUTH as `auth:cord:${string } `,
@@ -355,11 +373,67 @@ export async function revokeDocumentHashOnChain(
355
373
} )
356
374
) ;
357
375
358
- const statementStatus = await Cord . Statement . fetchStatementDetailsfromChain ( statmentid as `stmt:cord:${string } `) ;
359
- if ( statementStatus ?. revoked ) {
360
- return res . status ( 200 ) . json ( { result :{ msg :'Successfully revoked' } } ) ;
361
- } else {
362
- return res . status ( 400 ) . json ( { err :'Document not revoked' } ) ;
376
+ const statementStatusRevoked =
377
+ await Cord . Statement . fetchStatementDetailsfromChain (
378
+ statementUri as `stmt:cord:${string } `
379
+ ) ;
380
+ if ( statementStatusRevoked ?. revoked ) {
381
+ return res . status ( 200 ) . json ( { result : { msg : 'Successfully revoked' } } ) ;
382
+ } else {
383
+ return res . status ( 400 ) . json ( { err : 'Document not revoked' } ) ;
384
+ }
385
+ } catch ( error : any ) {
386
+ console . log ( 'errr: ' , error ) ;
387
+ return res . status ( 400 ) . json ( { err : error . message ? error . message : error } ) ;
388
+ }
389
+ }
390
+
391
+ export async function udpateDocumentHashonChain (
392
+ req : express . Request ,
393
+ res : express . Response
394
+ ) {
395
+ try {
396
+ const fileHash = req ?. body . filehash ;
397
+ const identifierReq = req ?. body . identifier ;
398
+ if ( ! req . params . id ) {
399
+ return res . status ( 400 ) . json ( { err : 'Please enter correct id' } ) ;
400
+ }
401
+ const api = Cord . ConfigService . get ( 'api' ) ;
402
+ if ( ! CHAIN_SPACE_ID ) {
403
+ return res . status ( 400 ) . json ( { err : 'chain space id not' } ) ;
404
+ }
405
+ const statementDetails = await Cord . Statement . getDetailsfromChain (
406
+ req . params . id
407
+ ) ;
408
+ if ( statementDetails ?. digest ) {
409
+ const digest = statementDetails . digest . replace ( / ^ 0 x / , '' ) ;
410
+ const elementUri = `${ statementDetails . uri } :digest` ;
411
+ const updatedStatementEntry = Cord . Statement . buildFromUpdateProperties (
412
+ elementUri as `stmt:cord:${string } `,
413
+ statementDetails ?. digest ,
414
+ CHAIN_SPACE_ID as `space:cord:${string } `,
415
+ issuerDid . uri
416
+ ) ;
417
+ console . dir ( updatedStatementEntry , {
418
+ depth : null ,
419
+ colors : true ,
420
+ } ) ;
421
+
422
+ const updatedStatement = await Cord . Statement . dispatchUpdateToChain (
423
+ updatedStatementEntry ,
424
+ issuerDid . uri ,
425
+ authorIdentity ,
426
+ CHAIN_SPACE_AUTH as `auth:cord:${string } `,
427
+ async ( { data } ) => ( {
428
+ signature : issuerKeysProperty . authentication . sign ( data ) ,
429
+ keyType : issuerKeysProperty . authentication . type ,
430
+ } )
431
+ ) ;
432
+ console . log ( `✅ Statement element registered - ${ updatedStatement } ` ) ;
433
+
434
+ return res . status ( 200 ) . json ( { result : { msg : 'Successfully update' } } ) ;
435
+ } else {
436
+ return res . status ( 400 ) . json ( { err : 'Unable to find the digest' } ) ;
363
437
}
364
438
} catch ( error : any ) {
365
439
console . log ( 'errr: ' , error ) ;
0 commit comments