From f1ba6f9231c23a4254bd88cc0d14fac9f43541f0 Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Wed, 28 May 2025 09:04:15 +0000 Subject: [PATCH] fix(endorserServer): improve type safety in claim handling - Fix type conversion in claimSpecialDescription to properly handle GenericVerifiableCredential - Update claim type checking to use 'claim' in claim for proper type narrowing - Add type assertions for claim.object to ensure type safety - Remove incorrect GenericCredWrapper type cast This change resolves the type conversion error by properly handling different claim types and ensuring type safety when passing objects to claimSummary. The code now correctly distinguishes between GenericVerifiableCredential and GenericCredWrapper types. --- src/libs/endorserServer.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/endorserServer.ts b/src/libs/endorserServer.ts index ce4f65f3..56a377eb 100644 --- a/src/libs/endorserServer.ts +++ b/src/libs/endorserServer.ts @@ -1155,8 +1155,8 @@ export const claimSpecialDescription = ( contacts: Array, ) => { let claim = record.claim; - if (claim.claim) { - // it's probably a Verified Credential + if ('claim' in claim) { + // it's a nested GenericCredWrapper claim = claim.claim; } @@ -1164,9 +1164,9 @@ export const claimSpecialDescription = ( const type = claim["@type"] || "UnknownType"; if (type === "AgreeAction") { - return issuer + " agreed with " + claimSummary(claim.object); + return issuer + " agreed with " + claimSummary(claim.object as GenericVerifiableCredential); } else if (isAccept(claim)) { - return issuer + " accepted " + claimSummary(claim.object); + return issuer + " accepted " + claimSummary(claim.object as GenericVerifiableCredential); } else if (type === "GiveAction") { // agent.did is for legacy data, before March 2023 const giver = claim.agent?.identifier || claim.agent?.did; @@ -1246,7 +1246,7 @@ export const claimSpecialDescription = ( return ( issuer + " declared " + - claimSummary(claim as GenericCredWrapper) + claimSummary(claim) ); } };