OfferCredential.fromJson constructor

OfferCredential.fromJson(
  1. dynamic jsonObject
)

Implementation

OfferCredential.fromJson(dynamic jsonObject) : super.fromJson(jsonObject) {
  if (type != DidcommMessages.offerCredential.value) {
    throw Exception('Unknown Message type or version');
  }
  goalCode = body['goal_code'];
  comment = body['comment'];
  replacementId = body['replacement_id'];
  if (body.containsKey('credential_preview')) {
    credentialPreview =
        PreviewCredential.fromJson(body['credential_preview']);
  }
  if (attachments != null && attachments!.isNotEmpty) {
    detail = [];
    for (var a in attachments!) {
      if (a.format != null &&
          a.format == AttachmentFormat.ldProofVcDetail.value) {
        if (a.mediaType != null && a.mediaType == 'application/json') {
          a.data.resolveData();
          detail!.add(LdProofVcDetail.fromJson(a.data.json!));
        }
      } else if (a.format != null &&
          a.format == AttachmentFormat.credentialManifestAries.value) {
        throw UnimplementedError(
            'dif credential Manifest Attachment as specified in Aries RFC 0511 is not supported yet');
      } else if (a.format != null &&
          a.format == AttachmentFormat.credentialManifest.value) {
        credentialManifest = CredentialManifest.fromJson(a.data.json);
      } else if (a.format != null &&
          a.format == AttachmentFormat.credentialFulfillment.value) {
        fulfillment = VerifiablePresentation.fromJson(a.data.json);
        if (fulfillment?.credentialFulfillment == null) {
          throw Exception(
              'the presentation used here must contain a credential fulfillment');
        }
      } else if (a.format != null &&
          a.format == AttachmentFormat.indyCredentialAbstract.value) {
        throw UnimplementedError('indy Attachment is not supported');
      } else {
        continue;
      }
    }
  }
}