Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const verifyWithResolver = async (signedData, resolver) => {
const verificationMethod = signedData.proof.verificationMethod
? signedData.proof.verificationMethod
: signedData.proof.creator;
const doc = await resolver.resolve(verificationMethod);
const didPublicKey = doc.publicKey.find(k => {
return k.id == verificationMethod;
});
if (didPublicKey.type === "Ed25519VerificationKey2018") {
const result = await jsigs.verify(signedData, {
documentLoader: wrappedDocumentLoader({
//args that are needed in the wrapper.. such as zcaps
}),
suite: new Ed25519Signature2018({
key: new Ed25519KeyPair(didPublicKey)
}),
purpose: new AssertionProofPurpose({ controller: doc })
});
return result.verified;
}
return OpenPgpSignature2019.verify({
data: signedData,
signatureAttribute: "proof",
publicKey: getPublicKeyFromDIDDoc(doc, verificationMethod)
.map(c => {
const credential = JSON.parse(JSON.stringify(c));
credential['@context'] = presentation['@context'];
return verify({credential, documentLoader, ...options});
}));
const allCredentialsVerified = credentialResult.every(r => r.verified);
const {controller, domain, challenge} = options;
const purpose = options.purpose || new CredentialIssuancePurpose({
controller,
domain,
challenge
});
const presentationResult = jsigs.verify(presentation, {purpose, documentLoader, ...options});
return {
verified: (presentationResult.verified && allCredentialsVerified),
results: [].concat([presentationResult, credentialResult]),
error: presentationResult.error
};
}
return {
verified: false,
results: [{credential, verified: false, error}],
error
};
}
const documentLoader = options.documentLoader || defaultDocumentLoader;
const {controller, domain} = options;
const purpose = options.purpose || new CredentialIssuancePurpose({
controller,
domain
});
return jsigs.verify(credential, {purpose, documentLoader, ...options});
}