Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.acceptCredential = async function(theirDid, encryptedMessage) {
let myDid = await indy.pairwise.getMyDid(theirDid);
let credential = await await indy.crypto.authDecrypt(myDid, encryptedMessage);
let credentialRequestMetadata;
let pendingCredentialRequests = indy.store.pendingCredentialRequests.getAll();
for(let pendingCredReq of pendingCredentialRequests) {
if(pendingCredReq.credRequestJson.cred_def_id === credential.cred_def_id) { // FIXME: Check for match
credentialRequestMetadata = pendingCredReq.credRequestMetadataJson;
}
}
let [, credentialDefinition] = await indy.issuer.getCredDef(await indy.pool.get(), await indy.did.getEndpointDid(), credential.cred_def_id);
await sdk.proverStoreCredential(await indy.wallet.get(), null, credentialRequestMetadata, credential, credentialDefinition);
let credentials = await indy.credentials.getAll();
console.log(credentials);
};
credentialOffer.data = {};
console.log(e);
}
let [, credentialDefinition] = await indy.issuer.getCredDef(pool, endpointDID, credentialOffer.cred_def_id);
let masterSecretId = await indy.did.getEndpointDidAttribute('master_secret_id');
let [credRequestJson, credRequestMetadataJson] = await sdk.proverCreateCredentialReq(wallet, endpointDID, credentialOffer, credentialDefinition, masterSecretId);
let schema = await indy.issuer.getSchema(credentialOffer.schema_id);
let credentialValues = {};
for (let attr of schema.attrNames) {
if (credentialOffer.data[attr]) {
credentialValues[attr] = {raw: credentialOffer.data[attr], encoded: indy.credentials.encode(credentialOffer.data[attr])};
}
}
let [credential] = await sdk.issuerCreateCredential(wallet, credentialOffer, credRequestJson, credentialValues);
await sdk.proverStoreCredential(wallet, null, credRequestMetadataJson, credential, credentialDefinition);
} catch (e) {
console.log(e);
}
}