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.
This commit is contained in:
@@ -1155,8 +1155,8 @@ export const claimSpecialDescription = (
|
||||
contacts: Array<Contact>,
|
||||
) => {
|
||||
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<GenericVerifiableCredential>)
|
||||
claimSummary(claim)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user