oobOfferCredential function

OutOfBandMessage oobOfferCredential({
  1. required Map<String, dynamic> credential,
  2. required String oobId,
  3. required String threadId,
  4. required List<String> replyTo,
  5. required String issuerDid,
  6. required String connectionDid,
  7. String proofType = 'Ed25519Signature',
})

offers a credential using oob

a credential is understood as a template having the following syntax

{
  "@context": ["context1", "context2"],
  "type": ["type1", "type2"],

}

Implementation

OutOfBandMessage oobOfferCredential({
  required Map<String, dynamic> credential,
  required String oobId,
  required String threadId,
  required List<String> replyTo,
  required String issuerDid,
  required String connectionDid,
  String proofType = 'Ed25519Signature',
}) {

  try {
    addElementToListOrInit(credential, ['@context'],
        'https://www.w3.org/2018/credentials/v1');
  } on JsonPathException catch (e) {
    throw OobTemplateWrongValueException('The @context field is invalid.\n'
        'Details: $e',
        code: 234234543);
  }

  try {
    forceAsList(credential, ['type']);
  } on JsonPathException catch (e) {
    throw OobTemplateMissingValueException('The credential must have a `type`'
        ' field set.\nDetails: $e',
        code: 34583495834);
  }

  /// @TODO why that?
  if (!credential.containsKey('id')) {
    credential['id'] = 'did:key:000';
  }
  var vc = VerifiableCredential(
      context: (credential.remove('@context') as List).cast<String>(),
      type: ['VerifiableCredential', ...credential.remove('type')],
      issuer: issuerDid,
      credentialSubject: credential,
      issuanceDate: DateTime.now());

  var offer = OfferCredential(id: oobId, threadId: threadId, detail: [
    LdProofVcDetail(
        credential: vc,
        options: LdProofVcDetailOptions(proofType: proofType))
  ], replyTo: replyTo);

  return OutOfBandMessage(
      id: oobId,
      threadId: threadId,
      from: connectionDid,
      replyTo: replyTo,
      goalCode: 'streamlined-vc',
      attachments: [Attachment(data: AttachmentData(json: offer.toJson()))]);
}