verifyProof function

Future<bool> verifyProof(
  1. dynamic proofInput
)

Implementation

Future<bool> verifyProof(dynamic proofInput) async {
  // Handle array of proofs
  if (proofInput is List) {
    try {
      for (var proof in proofInput) {
        bool isValid = await verifyProof(proof);
        if (!isValid) {
          return false;
        }
      }
      return true;
    } catch (e) {
      logger.info('Error verifying array of proofs: ${e.toString()}');
      return false;
    }
  }

  // Handle single proof
  final proof = proofInput as Proof;
  if (proof.signatures.isEmpty) {
    logger.info('No signatures');
    throw signatureNotFoundError('No signatures');
  }

  try {
    List<String> witnesses = [];
    if (proof.witnesses.isNotEmpty &&
        proof.witnesses[0].url == 'manual-verify') {
      witnesses.add(proof.witnesses[0].id);
    } else {
      witnesses = await getWitnessesForClaim(
          proof.claimData.epoch, proof.identifier, proof.claimData.timestampS);
    }

    ClaimInfo claimInfo = ClaimInfo.fromJson(proof.claimData.toJson());
    // then hash the claim info with the encoded ctx to get the identifier
    final calculatedIdentifier = getIdentifierFromClaimInfo(claimInfo);

    proof.identifier = proof.identifier.replaceAll('"', '');
    if (calculatedIdentifier != proof.identifier) {
      logger.info('Identifier Mismatch');
      throw proofNotVerifiedError('Identifier Mismatch');
    }

    final signedClaim = SignedClaim(
      claim: proof.claimData,
      signatures: proof.signatures.map((s) => hexToBytes(s)).toList(),
    );

    assertValidSignedClaim(signedClaim, witnesses);
  } catch (e) {
    logger.info('Error verifying proof: ${e.toString()}');
    return false;
  }

  return true;
}