How to use the indy-sdk.issuerCreateCredentialOffer function in indy-sdk

To help you get started, we’ve selected a few indy-sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hyperledger / indy-agent / nodejs / indy / src / credentials / index.js View on Github external
async function issueCredentialToSelf(credentialDefinitionId, credentialData) {
  try {
    let endpointDID = await indy.did.getEndpointDid();
    let wallet = await indy.wallet.get();
    let pool = await indy.pool.get();
    let credentialOffer = await sdk.issuerCreateCredentialOffer(wallet, credentialDefinitionId);
    try {
      credentialOffer.data = JSON.parse(credentialData);
    } catch (e) {
      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])};
      }
github hyperledger / indy-agent / nodejs / indy / src / credentials / index.js View on Github external
exports.sendOffer = async function (theirDid, credentialDefinitionId, credentialData) {
    if(theirDid === '_self_') {
        return issueCredentialToSelf(credentialDefinitionId, credentialData);
    }
    else {
      let credOffer = await sdk.issuerCreateCredentialOffer(await indy.wallet.get(), credentialDefinitionId);
      try {
        credOffer.data = JSON.parse(credentialData);
      } catch (e) {
        credOffer.data = {};
        console.log(e);
      }
      await indy.store.pendingCredentialOffers.write(credOffer);
      let pairwise = await sdk.getPairwise(await indy.wallet.get(), theirDid);
      let myDid = pairwise.my_did;
      let message = await indy.crypto.buildAuthcryptedMessage(myDid, theirDid, MESSAGE_TYPES.OFFER, credOffer);
      let meta = JSON.parse(pairwise.metadata);
      let theirEndpointDid = meta.theirEndpointDid;
      return indy.crypto.sendAnonCryptedMessage(theirEndpointDid, message);
    }
};