Skip to content

Commit

Permalink
fix: align according to new oa v4 (beta) types
Browse files Browse the repository at this point in the history
  • Loading branch information
HJunyuan committed May 17, 2024
1 parent a826b6d commit 7c8854d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 27 deletions.
41 changes: 16 additions & 25 deletions src/verifiers/documentStatus/didSigned/didSignedDocumentStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ const verifyV3 = async (
};

const verifyV4 = async (
document: SignedWrappedDocument<v4.OpenAttestationDocument>,
document: v4.SignedWrappedDocument<v4.OpenAttestationDocument>,
options: VerifierOptions
): Promise<
OpenAttestationDidSignedDocumentStatusValidFragmentV4 | OpenAttestationDidSignedDocumentStatusInvalidFragmentV4
Expand All @@ -359,25 +359,21 @@ const verifyV4 = async (
})
);

if (!document.credentialStatus?.credentialStatusType) {
throw new CodedError(
"credentialStatus (revocation) block not found for an issuer",
OpenAttestationDidSignedDocumentStatusCode.MISSING_REVOCATION,
"MISSING_REVOCATION"
);
}

const issuedOnAll = verificationResult.issued;

const getRevocationStatus = async (
docType: v4.CredentialStatusType,
location: string | undefined
credentialStatus: v4.OpenAttestationDocument["credentialStatus"]
): Promise<RevocationStatus> => {
switch (docType) {
case v4.CredentialStatusType.RevocationStore:
if (typeof location === "string") {
// No revocation type specified (i.e. an unrevocable document)
if (!credentialStatus) {
return { revoked: false };
}

switch (credentialStatus.type) {
case "OpenAttestationRevocationStore":
if (typeof credentialStatus.id === "string") {
return isRevokedOnDocumentStore({
documentStore: location,
documentStore: credentialStatus.id,
merkleRoot,
targetHash,
proofs,
Expand All @@ -389,35 +385,30 @@ const verifyV4 = async (
OpenAttestationDidSignedDocumentStatusCode.REVOCATION_LOCATION_MISSING,
"REVOCATION_LOCATION_MISSING"
);
case v4.CredentialStatusType.OcspResponder:
if (typeof location === "string") {
case "OpenAttestationOcspResponder":
if (typeof credentialStatus.id === "string") {
return isRevokedByOcspResponder({
merkleRoot,
targetHash,
proofs,
location,
location: credentialStatus.id,
});
}
throw new CodedError(
"missing revocation location for an issuer",
OpenAttestationDidSignedDocumentStatusCode.REVOCATION_LOCATION_MISSING,
"REVOCATION_LOCATION_MISSING"
);
case v4.CredentialStatusType.None:
return { revoked: false };
default:
throw new CodedError(
"revocation type not found for an issuer",
"unknown revocation type",
OpenAttestationDidSignedDocumentStatusCode.UNRECOGNIZED_REVOCATION_TYPE,
"UNRECOGNIZED_REVOCATION_TYPE"
);
}
};

const revocationStatus = await getRevocationStatus(
document.credentialStatus.credentialStatusType,
document.credentialStatus.location
);
const revocationStatus = await getRevocationStatus(document.credentialStatus);

const revokedOnAny = revocationStatus.revoked;

Expand Down
4 changes: 2 additions & 2 deletions src/verifiers/issuerIdentity/dnsDid/dnsDidProof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const test: VerifierType["test"] = (document) => {
} else if (utils.isSignedWrappedV3Document(document)) {
return document.openAttestationMetadata.identityProof.type === v3.IdentityProofType.DNSDid;
} else if (utils.isWrappedV4Document(document)) {
return document.issuer.identityProof.identityProofType === v4.IdentityProofType.DNSDid;
return document.issuer.identityProof.identityProofType === "DNS-DID";
}
return false;
};
Expand Down Expand Up @@ -185,7 +185,7 @@ const verify: VerifierType["verify"] = async (document) => {
else if (utils.isSignedWrappedV3Document(document)) return verifyV3(document);
else if (utils.isSignedWrappedV4Document(document)) return verifyV4(document);
throw new CodedError(
"Document does not match either v2 or v3 formats. Consider using `utils.diagnose` from open-attestation to find out more.",
"Document does not match either v2, v3 or v4 formats. Consider using `utils.diagnose` from open-attestation to find out more.",
OpenAttestationDnsDidCode.UNRECOGNIZED_DOCUMENT,
OpenAttestationDnsDidCode[OpenAttestationDnsDidCode.UNRECOGNIZED_DOCUMENT]
);
Expand Down

0 comments on commit 7c8854d

Please sign in to comment.