@sphereon/gx-compliance-client
Version:
<!--suppress HtmlDeprecatedAttribute --> <h1 align="center"> <br> <a href="https://www.sphereon.com"><img src="https://sphereon.com/content/themes/sphereon/assets/img/logo.svg" alt="Sphereon" width="400"></a> <br>Gaia-X Compliance client (Typescript
33 lines (32 loc) • 1.68 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractApiTypeFromVC = exports.extractSubjectDIDFromVCs = void 0;
const types_1 = require("../types");
function extractSubjectDIDFromVCs(verifiableCredentials) {
const credentialSubject = Array.isArray(verifiableCredentials)
? verifiableCredentials[0].credentialSubject
: verifiableCredentials.credentialSubject; // todo: check whether other credentials have the same subject?
let participantDID;
if (Array.isArray(credentialSubject)) {
const singleCredentialSubject = credentialSubject.filter((s) => !!s.id).pop();
if (!credentialSubject) {
throw new Error('No subject DID present');
}
participantDID = singleCredentialSubject['id'];
}
else {
participantDID = credentialSubject['id'];
}
if (!participantDID) {
throw new Error("Subject DID can't be extracted from received VerifiableCredentials. Please make sure the credentialSubject id is set");
}
return participantDID;
}
exports.extractSubjectDIDFromVCs = extractSubjectDIDFromVCs;
function extractApiTypeFromVC(vc) {
const types = Array.isArray(vc.type) ? vc.type : [vc.type];
// todo: This is too naive as you can have more than 2 types on a VC. Should simply search for the specific type in the array and if found return it
const credentialType = types.find((type) => type !== 'VerifiableCredential');
return credentialType === types_1.IGaiaxCredentialType.LegalPerson || types_1.IGaiaxCredentialType.NaturalPerson ? 'participant' : 'service-offering';
}
exports.extractApiTypeFromVC = extractApiTypeFromVC;