public void EncodeIntegerValues()
        {
            // int max
            var value    = "2147483647";
            var expected = "2147483647";
            var actual   = CredentialUtils.GetEncoded(value);

            Assert.Equal(expected, actual);

            // int min
            value    = "-2147483648";
            expected = "-2147483648";
            actual   = CredentialUtils.GetEncoded(value);
            Assert.Equal(expected, actual);

            // int max + 1
            value    = "2147483648";
            expected = "26221484005389514539852548961319751347124425277437769688639924217837557266135";
            actual   = CredentialUtils.GetEncoded(value);
            Assert.Equal(expected, actual);

            // int min - 1
            value    = "-2147483649";
            expected = "68956915425095939579909400566452872085353864667122112803508671228696852865689";
            actual   = CredentialUtils.GetEncoded(value);
            Assert.Equal(expected, actual);
        }
        public void CanFormatStringCredentialValues()
        {
            var attributeValues = new List <CredentialPreviewAttribute>
            {
                new CredentialPreviewAttribute("first_name", "Test"),
                new CredentialPreviewAttribute("last_name", "holder")
            };

            var expectedResult = new
            {
                first_name = new
                {
                    raw     = "Test",
                    encoded = CredentialUtils.GetEncoded("Test")
                },
                last_name = new
                {
                    raw     = "holder",
                    encoded = CredentialUtils.GetEncoded("holder")
                }
            }.ToJson();

            var formatedCredentialUtils = CredentialUtils.FormatCredentialValues(attributeValues);

            var expectedResultObj = JObject.Parse(expectedResult);
            var formatedCredObj   = JObject.Parse(formatedCredentialUtils);

            Assert.Equal(expectedResultObj, formatedCredObj);
        }
        public void EncodeRawValue()
        {
            var value    = "SLC";
            var expected = "101327353979588246869873249766058188995681113722618593621043638294296500696424";

            var actual = CredentialUtils.GetEncoded(value);

            Assert.Equal(expected, actual);

            value    = "101 Wilson Lane";
            expected = "68086943237164982734333428280784300550565381723532936263016368251445461241953";
            actual   = CredentialUtils.GetEncoded(value);
            Assert.Equal(expected, actual);

            // null value
            value    = null;
            expected = "102987336249554097029535212322581322789799900648198034993379397001115665086549";
            actual   = CredentialUtils.GetEncoded(value);
            Assert.Equal(expected, actual);

            // empty string value
            value    = string.Empty;
            expected = "102987336249554097029535212322581322789799900648198034993379397001115665086549";
            actual   = CredentialUtils.GetEncoded(value);
            Assert.Equal(expected, actual);
        }
        /// <inheritdoc />
        public virtual async Task <bool> VerifyProofAsync(IAgentContext agentContext, string proofRequestJson, string proofJson, bool validateEncoding = true)
        {
            var proof        = JsonConvert.DeserializeObject <PartialProof>(proofJson);
            var proofRequest = proofRequestJson.ToObject <ProofRequest>();

            // If any values are revealed, validate encoding
            // against expected values
            if (validateEncoding && proof.RequestedProof.RevealedAttributes != null)
            {
                foreach (var attribute in proof.RequestedProof.RevealedAttributes)
                {
                    if (!CredentialUtils.CheckValidEncoding(attribute.Value.Raw, attribute.Value.Encoded))
                    {
                        throw new AriesFrameworkException(ErrorCode.InvalidProofEncoding,
                                                          $"The encoded value for '{attribute.Key}' is invalid. " +
                                                          $"Expected '{CredentialUtils.GetEncoded(attribute.Value.Raw)}'. " +
                                                          $"Actual '{attribute.Value.Encoded}'");
                    }
                }
            }

            var schemas = await BuildSchemasAsync(agentContext,
                                                  proof.Identifiers
                                                  .Select(x => x.SchemaId)
                                                  .Where(x => x != null)
                                                  .Distinct());

            var definitions = await BuildCredentialDefinitionsAsync(agentContext,
                                                                    proof.Identifiers
                                                                    .Select(x => x.CredentialDefintionId)
                                                                    .Where(x => x != null)
                                                                    .Distinct());

            var revocationDefinitions = await BuildRevocationRegistryDefinitionsAsync(agentContext,
                                                                                      proof.Identifiers
                                                                                      .Select(x => x.RevocationRegistryId)
                                                                                      .Where(x => x != null)
                                                                                      .Distinct());

            var revocationRegistries = await BuildRevocationRegistriesAsync(
                agentContext,
                proof.Identifiers.Where(x => x.RevocationRegistryId != null));

            return(await AnonCreds.VerifierVerifyProofAsync(
                       proofRequestJson,
                       proofJson,
                       schemas,
                       definitions,
                       revocationDefinitions,
                       revocationRegistries));
        }