diff --git a/src/@context/Asset.tsx b/src/@context/Asset.tsx index f5d20809..7ca800d2 100644 --- a/src/@context/Asset.tsx +++ b/src/@context/Asset.tsx @@ -43,7 +43,7 @@ export interface AssetProviderValue { serviceCredentialIdMatch?: boolean serviceCredentialVersion: string verifiedServiceProviderName: string - matchVerifiable?: boolean + isIdMatchVerifiable?: boolean | string fetchAsset: (token?: CancelToken) => Promise } @@ -83,7 +83,9 @@ function AssetProvider({ useState() const [verifiedServiceProviderName, setVerifiedServiceProviderName] = useState() - const [matchVerifiable, setMatchVerifiable] = useState() + const [isIdMatchVerifiable, setisIdMatchVerifiable] = useState< + boolean | string + >() const newCancelToken = useCancelToken() const isMounted = useIsMounted() @@ -204,14 +206,14 @@ function AssetProvider({ ? await getServiceCredential(serviceCredential?.url) : serviceCredential?.raw - const { verified, complianceApiVersion, idMatch, matchVerifiable } = + const { verified, complianceApiVersion, idMatch, isIdMatchVerifiable } = await verifyRawServiceCredential(serviceCredentialContent, asset.id) setIsServiceCredentialVerified(verified && !!serviceCredentialContent) setServiceCredentialIdMatch( - verified && !!serviceCredentialContent && idMatch && matchVerifiable + verified && !!serviceCredentialContent && idMatch ) - setMatchVerifiable(matchVerifiable) + setisIdMatchVerifiable(isIdMatchVerifiable) setServiceCredentialVersion(complianceApiVersion) const serviceProviderName = getPublisherFromServiceCredential( serviceCredentialContent @@ -325,7 +327,7 @@ function AssetProvider({ serviceCredentialIdMatch, serviceCredentialVersion, verifiedServiceProviderName, - matchVerifiable + isIdMatchVerifiable } as AssetProviderValue } > diff --git a/src/components/@shared/VerifiedBadge/index.tsx b/src/components/@shared/VerifiedBadge/index.tsx index 54bab9ac..8b5695dc 100644 --- a/src/components/@shared/VerifiedBadge/index.tsx +++ b/src/components/@shared/VerifiedBadge/index.tsx @@ -11,12 +11,12 @@ const cx = classNames.bind(styles) export function Badge({ isValid, - matchVerifiable, + isIdMatchVerifiable, verifiedService, className }: { isValid: boolean - matchVerifiable?: boolean + isIdMatchVerifiable?: boolean | string verifiedService: string className?: string }): ReactElement { @@ -25,24 +25,22 @@ export function Badge({ className={cx({ mainLabel: true, isValid, - isWarning: matchVerifiable === false, + isWarning: isIdMatchVerifiable === false, [className]: className })} > - {matchVerifiable === false && ( - - )} - {verifiedService} - {typeof matchVerifiable === 'undefined' ? ( - isValid ? ( - - ) : ( - - ) - ) : isValid && matchVerifiable ? ( - + {typeof isIdMatchVerifiable === 'string' ? ( + +
+ {verifiedService} + +
+
) : ( - + <> + {verifiedService} + {isValid ? : } + )} ) @@ -52,7 +50,7 @@ export default function VerifiedBadge({ className, isValid, idMatch, - matchVerifiable, + isIdMatchVerifiable, isLoading, apiVersion, timestamp @@ -60,7 +58,7 @@ export default function VerifiedBadge({ className?: string isValid?: boolean idMatch?: boolean - matchVerifiable?: boolean + isIdMatchVerifiable?: boolean | string isLoading?: boolean apiVersion?: string timestamp?: boolean @@ -82,7 +80,7 @@ export default function VerifiedBadge({
diff --git a/src/components/Asset/AssetContent/MetaMain/index.tsx b/src/components/Asset/AssetContent/MetaMain/index.tsx index 7d1480b4..0ae13f47 100644 --- a/src/components/Asset/AssetContent/MetaMain/index.tsx +++ b/src/components/Asset/AssetContent/MetaMain/index.tsx @@ -18,7 +18,7 @@ export default function MetaMain({ const { isServiceCredentialVerified, serviceCredentialIdMatch, - matchVerifiable, + isIdMatchVerifiable, serviceCredentialVersion, isVerifyingServiceCredential, verifiedServiceProviderName @@ -45,7 +45,7 @@ export default function MetaMain({ isLoading={isVerifyingServiceCredential} isValid={isServiceCredentialVerified} idMatch={serviceCredentialIdMatch} - matchVerifiable={matchVerifiable} + isIdMatchVerifiable={isIdMatchVerifiable} apiVersion={serviceCredentialVersion} timestamp={isServiceCredentialVerified} /> diff --git a/src/components/Publish/_utils.ts b/src/components/Publish/_utils.ts index 40f7dd93..221898ba 100644 --- a/src/components/Publish/_utils.ts +++ b/src/components/Publish/_utils.ts @@ -485,7 +485,7 @@ export async function verifyRawServiceCredential( verified: boolean complianceApiVersion?: string idMatch?: boolean - matchVerifiable?: boolean + isIdMatchVerifiable?: boolean | string responseBody?: any }> { if (!rawServiceCredential) return { verified: false } @@ -507,27 +507,48 @@ export async function verifyRawServiceCredential( } } if (response?.status === 201) { - const dependsOn = parsedServiceCredential.verifiableCredential - .filter( - (credential) => - credential?.credentialSubject['gx:dependsOn'] !== undefined - ) - .map( - (credential) => credential?.credentialSubject['gx:dependsOn'][0].id - ) - const serviceOffering = + const serviceOfferings = parsedServiceCredential.verifiableCredential.filter( (credential) => - credential?.credentialSubject?.type === 'gx:ServiceOffering' && - credential?.credentialSubject?.id !== dependsOn?.[0] + credential?.credentialSubject?.type === 'gx:ServiceOffering' ) - const credentialId = serviceOffering[0]?.credentialSubject?.id - - return { - verified: true, - complianceApiVersion, - idMatch: did && did?.toLowerCase() === credentialId?.toLowerCase(), - matchVerifiable: dependsOn.length > 0 + if (serviceOfferings.length === 1) { + return { + verified: true, + complianceApiVersion, + idMatch: + did && + did?.toLowerCase() === + serviceOfferings?.credentialSubject?.id.toLowerCase(), + isIdMatchVerifiable: true + } + } else { + const dependsOnIds = serviceOfferings + .filter((service) => service?.credentialSubject?.['gx:dependsOn']) + .flatMap( + (service) => service?.credentialSubject?.['gx:dependsOn']?.[0]?.id + ) + const rootService = serviceOfferings + .filter( + (service) => !dependsOnIds.includes(service?.credentialSubject?.id) + ) + .flatMap((service) => service?.credentialSubject?.id) + + if (rootService.length !== 1) { + return { + verified: true, + complianceApiVersion, + idMatch: rootService?.includes(did || did.toLowerCase()), + isIdMatchVerifiable: 'Too many root services' + } + } else { + return { + verified: true, + complianceApiVersion, + idMatch: rootService?.includes(did || did.toLowerCase()), + isIdMatchVerifiable: true + } + } } }