/// <inheritdoc />
        public virtual async Task <ParseResponseResult> LookupDefinitionAsync(Pool pool,
                                                                              string definitionId)
        {
            var req = await IndyLedger.BuildGetCredDefRequestAsync(null, definitionId);

            var res = await IndyLedger.SubmitRequestAsync(pool, req);

            return(await IndyLedger.ParseGetCredDefResponseAsync(res));
        }
        /// <inheritdoc />
        public virtual async Task RegisterAttributeAsync(IAgentContext context, string submittedDid, string targetDid,
                                                         string attributeName, object value, TransactionCost paymentInfo = null)
        {
            var data = $"{{\"{attributeName}\": {value.ToJson()}}}";

            var req = await IndyLedger.BuildAttribRequestAsync(submittedDid, targetDid, null, data, null);

            var res = await SignAndSubmitAsync(context, submittedDid, req, paymentInfo);
        }
        /// <inheritdoc />
        public virtual async Task <ParseResponseResult> LookupRevocationRegistryDefinitionAsync(IAgentContext agentContext,
                                                                                                string registryId)
        {
            var req = await IndyLedger.BuildGetRevocRegDefRequestAsync(null, registryId);

            var res = await IndyLedger.SubmitRequestAsync(await agentContext.Pool, req);

            return(await IndyLedger.ParseGetRevocRegDefResponseAsync(res));
        }
예제 #4
0
        /// <inheritdoc />
        public async Task <string> LookupNymAsync(IAgentContext agentContext, string did)
        {
            var req = await IndyLedger.BuildGetNymRequestAsync(null, did);

            var res = await IndyLedger.SubmitRequestAsync(await agentContext.Pool, req);

            EnsureSuccessResponse(res);

            return(res);
        }
예제 #5
0
        /// <inheritdoc />
        public virtual async Task SendRevocationRegistryEntryAsync(IAgentContext context, string issuerDid,
                                                                   string revocationRegistryDefinitionId, string revocationDefinitionType, string value, TransactionCost paymentInfo = null)
        {
            var req = await IndyLedger.BuildRevocRegEntryRequestAsync(issuerDid, revocationRegistryDefinitionId,
                                                                      revocationDefinitionType, value);

            var res = await SignAndSubmitAsync(context, issuerDid, req, paymentInfo);

            EnsureSuccessResponse(res);
        }
        /// <inheritdoc />
        public virtual async Task <ParseResponseResult> LookupSchemaAsync(Pool pool, string schemaId)
        {
            var req = await IndyLedger.BuildGetSchemaRequestAsync(null, schemaId);

            var res = await IndyLedger.SubmitRequestAsync(pool, req);

            EnsureSuccessResponse(res);

            return(await IndyLedger.ParseGetSchemaResponseAsync(res));
        }
예제 #7
0
        /// <inheritdoc />
        public virtual async Task <ParseRegistryResponseResult> LookupRevocationRegistryAsync(IAgentContext agentContext, string revocationRegistryId,
                                                                                              long timestamp)
        {
            var req = await IndyLedger.BuildGetRevocRegRequestAsync(null, revocationRegistryId, timestamp);

            var res = await IndyLedger.SubmitRequestAsync(await agentContext.Pool, req);

            EnsureSuccessResponse(res);

            return(await IndyLedger.ParseGetRevocRegResponseAsync(res));
        }
        /// <inheritdoc />
        public virtual async Task <ParseRegistryResponseResult> LookupRevocationRegistryDeltaAsync(Pool pool, string revocationRegistryId,
                                                                                                   long from, long to)
        {
            var req = await IndyLedger.BuildGetRevocRegDeltaRequestAsync(null, revocationRegistryId, from, to);

            var res = await IndyLedger.SubmitRequestAsync(pool, req);

            EnsureSuccessResponse(res);

            return(await IndyLedger.ParseGetRevocRegDeltaResponseAsync(res));
        }
예제 #9
0
        /// <inheritdoc />
        public async Task <IList <AuthorizationRule> > LookupAuthorizationRulesAsync(IAgentContext agentContext)
        {
            var req = await IndyLedger.BuildGetAuthRuleRequestAsync(null, null, null, null, null, null);

            var res = await IndyLedger.SubmitRequestAsync(await agentContext.Pool, req);

            EnsureSuccessResponse(res);

            var jobj = JObject.Parse(res);

            return(jobj["result"]["data"].ToObject <IList <AuthorizationRule> >());
        }
예제 #10
0
        /// <inheritdoc />
        public virtual async Task RegisterNymAsync(IAgentContext context, string submitterDid, string theirDid,
                                                   string theirVerkey, string role, TransactionCost paymentInfo = null)
        {
            if (DidUtils.IsFullVerkey(theirVerkey))
            {
                theirVerkey = await Did.AbbreviateVerkeyAsync(theirDid, theirVerkey);
            }

            var req = await IndyLedger.BuildNymRequestAsync(submitterDid, theirDid, theirVerkey, null, role);

            var res = await SignAndSubmitAsync(context, submitterDid, req, paymentInfo);
        }
예제 #11
0
        /// <inheritdoc />
        public virtual async Task <ParseResponseResult> LookupDefinitionAsync(IAgentContext agentContext,
                                                                              string definitionId)
        {
            async Task <ParseResponseResult> LookupDefinition()
            {
                var req = await IndyLedger.BuildGetCredDefRequestAsync(null, definitionId);

                var res = await IndyLedger.SubmitRequestAsync(await agentContext.Pool, req);

                return(await IndyLedger.ParseGetCredDefResponseAsync(res));
            }

            return(await ResilienceUtils.RetryPolicyAsync(
                       action : LookupDefinition,
                       exceptionPredicate : (IndyException e) => e.SdkErrorCode == 309));
        }
예제 #12
0
        /// <inheritdoc />
        public virtual async Task <ParseResponseResult> LookupSchemaAsync(IAgentContext agentContext, string schemaId)
        {
            async Task <ParseResponseResult> LookupSchema()
            {
                var req = await IndyLedger.BuildGetSchemaRequestAsync(null, schemaId);

                var res = await IndyLedger.SubmitRequestAsync(await agentContext.Pool, req);

                EnsureSuccessResponse(res);

                return(await IndyLedger.ParseGetSchemaResponseAsync(res));
            };

            return(await ResilienceUtils.RetryPolicyAsync(
                       action : LookupSchema,
                       exceptionPredicate : (IndyException e) => e.SdkErrorCode == 309));
        }
예제 #13
0
        private async Task <string> SignAndSubmitAsync(IAgentContext context, string submitterDid, string request, TransactionCost paymentInfo)
        {
            if (paymentInfo != null)
            {
                var requestWithFees = await IndyPayments.AddRequestFeesAsync(
                    wallet : context.Wallet,
                    submitterDid : null,
                    reqJson : request,
                    inputsJson : paymentInfo.PaymentAddress.Sources.Select(x => x.Source).ToJson(),
                    outputsJson : new[]
                {
                    new IndyPaymentOutputSource
                    {
                        Recipient = paymentInfo.PaymentAddress.Address,
                        Amount    = paymentInfo.PaymentAddress.Balance - paymentInfo.Amount
                    }
                }.ToJson(),
                    extra : null);

                request = requestWithFees.Result;
            }
            var signedRequest = await _signingService.SignRequestAsync(context, submitterDid, request);

            var response = await IndyLedger.SubmitRequestAsync(await context.Pool, signedRequest);

            EnsureSuccessResponse(response);

            if (paymentInfo != null)
            {
                var responsePayment = await IndyPayments.ParseResponseWithFeesAsync(paymentInfo.PaymentMethod, response);

                var paymentOutputs = responsePayment.ToObject <IList <IndyPaymentOutputSource> >();
                paymentInfo.PaymentAddress.Sources = paymentOutputs
                                                     .Where(x => x.Recipient == paymentInfo.PaymentAddress.Address)
                                                     .Select(x => new IndyPaymentInputSource
                {
                    Amount         = x.Amount,
                    PaymentAddress = x.Recipient,
                    Source         = x.Receipt
                })
                                                     .ToList();
            }
            return(response);
        }
예제 #14
0
        /// <inheritdoc />
        public virtual async Task RegisterCredentialDefinitionAsync(IAgentContext context, string submitterDid, string data, TransactionCost paymentInfo = null)
        {
            var req = await IndyLedger.BuildCredDefRequestAsync(submitterDid, data);

            var res = await SignAndSubmitAsync(context, submitterDid, req, paymentInfo);
        }
예제 #15
0
        /// <inheritdoc />
        public virtual async Task RegisterSchemaAsync(IAgentContext context, string issuerDid, string schemaJson, TransactionCost paymentInfo = null)
        {
            var req = await IndyLedger.BuildSchemaRequestAsync(issuerDid, schemaJson);

            var res = await SignAndSubmitAsync(context, issuerDid, req, paymentInfo);
        }
        /// <summary>
        /// Processes the incoming <see cref="AgentMessage" />
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="agentContext">The message agentContext.</param>
        /// <param name="messageContext">The message context.</param>
        /// <returns></returns>
        protected override async Task <AgentMessage> ProcessAsync(BasicMessage message, IAgentContext agentContext, UnpackedMessageContext messageContext)
        {
            var jObject = JObject.Parse(message.Content);

            if (jObject.ContainsKey("~CustomType"))
            {
                var customType = (string)jObject["~CustomType"];
                switch (customType)
                {
                case "LedgerLookupDefinition":
                {
                    var definitionID = (string)jObject["~DefinitionID"];
                    var req          = await IndyLedger.BuildGetCredDefRequestAsync(null, definitionID);

                    var res = await IndyLedger.SubmitRequestAsync(await agentContext.Pool, req);

                    var resMessage = new BasicMessage
                    {
                        Content = res
                    };
                    return(resMessage);
                }

                case "LedgerLookupRevocationRegistryDefinition":
                {
                    var registryId = (string)jObject["~RegistryID"];
                    var req        = await IndyLedger.BuildGetRevocRegDefRequestAsync(null, registryId);

                    var res = await IndyLedger.SubmitRequestAsync(await agentContext.Pool, req);

                    var resMessage = new BasicMessage
                    {
                        Content = res
                    };
                    return(resMessage);
                }

                case "LedgerLookupSchema":
                {
                    var schemaId = (string)jObject["~SchemaID"];
                    var req      = await IndyLedger.BuildGetSchemaRequestAsync(null, schemaId);

                    var res = await IndyLedger.SubmitRequestAsync(await agentContext.Pool, req);

                    var resMessage = new BasicMessage
                    {
                        Content = res
                    };
                    return(resMessage);
                }

                case "LedgerLookupRevocationRegistryDelta":
                {
                    var revocationRegistryId = (string)jObject["~RevocationRegistryId"];
                    var from = (string)jObject["~From"];
                    var to   = (string)jObject["~To"];
                    var req  = await IndyLedger.BuildGetRevocRegDeltaRequestAsync(null, revocationRegistryId, Convert.ToInt64(from), Convert.ToInt64(to));

                    var res = await IndyLedger.SubmitRequestAsync(await agentContext.Pool, req);

                    var resMessage = new BasicMessage
                    {
                        Content = res
                    };
                    return(resMessage);
                }
                }
            }

            var record = new BasicMessageRecord
            {
                Id           = Guid.NewGuid().ToString(),
                ConnectionId = messageContext.Connection.Id,
                Text         = message.Content,
                SentTime     = DateTime.TryParse(message.SentTime, out var dateTime) ? dateTime : DateTime.UtcNow,
                Direction    = MessageDirection.Incoming
            };
            await _recordService.AddAsync(agentContext.Wallet, record);

            messageContext.ContextRecord = record;

            return(null);
        }
    }