generateProposeCredentialMessage function

Future<ProposeCredential> generateProposeCredentialMessage({
  1. required OfferCredential offer,
  2. required WalletStore wallet,
  3. required String connectionDid,
  4. required List<String> replyTo,
  5. required String credentialDid,
})

will sign the offer using the key derived in credentialDid resulting in a VerifiableCredential. The result is wrapped in a ProposeCredential message, while the offer itself is added as an attachment

this flow is Holder --> Issuer

Implementation

Future<ProposeCredential> generateProposeCredentialMessage({
  required OfferCredential offer,
  required WalletStore wallet,
  required String connectionDid,
  required List<String> replyTo,
  required String credentialDid,
}) async {
  var offeredCred = offer.detail!.first.credential;
  var credSubject = offeredCred.credentialSubject;

  // substitute the did in the credential (i.e., claim it)
  credSubject['id'] = credentialDid;
  var newCred = VerifiableCredential(
      id: credentialDid, // new did here also
      context: offeredCred.context,
      type: offeredCred.type,
      issuer: offeredCred.issuer,
      credentialSubject: credSubject,
      issuanceDate: offeredCred.issuanceDate,
      credentialSchema: offeredCred.credentialSchema,
      expirationDate: offeredCred.expirationDate);

  var message = ProposeCredential(
      threadId: offer.threadId ?? offer.id,
      from: connectionDid,
      to: [offer.from!],
      replyTo: replyTo,
      detail: [
        LdProofVcDetail(
            credential: newCred, options: offer.detail!.first.options)
      ]);

  //Sign attachment with credentialDid
  for (var a in message.attachments!) {
    await a.data.sign(wallet, credentialDid);
  }

  return message;
}