OfferCredential.fromJson constructor

OfferCredential.fromJson(
  1. dynamic jsonObject
)

Implementation

OfferCredential.fromJson(super.jsonObject) : super.fromJson() {
  if (type != DidcommMessages.offerCredential) {
    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) {
        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) {
        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) {
        credentialManifest =
            CredentialManifestAttachment.fromJson(a.data.json);
      } else if (a.format != null &&
          a.format == AttachmentFormat.credentialFulfillment) {
        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) {
        throw UnimplementedError('indy Attachment is not supported');
      } else {
        continue;
      }
    }
  }
}