Exemple #1
0
        /// <inheritdoc />
        public virtual async Task <string> ProcessProofRequestAsync(IAgentContext agentContext,
                                                                    ProofRequestMessage proofRequest, ConnectionRecord connection)
        {
            var requestJson = proofRequest.ProofRequestJson;

            // Write offer record to local wallet
            var proofRecord = new ProofRecord
            {
                Id           = Guid.NewGuid().ToString(),
                RequestJson  = requestJson,
                ConnectionId = connection.Id,
                State        = ProofState.Requested
            };

            proofRecord.SetTag(TagConstants.LastThreadId, proofRequest.GetThreadId());
            proofRecord.SetTag(TagConstants.Role, TagConstants.Holder);

            await RecordService.AddAsync(agentContext.Wallet, proofRecord);

            EventAggregator.Publish(new ServiceMessageProcessingEvent
            {
                RecordId    = proofRecord.Id,
                MessageType = proofRequest.Type,
                ThreadId    = proofRequest.GetThreadId()
            });

            return(proofRecord.Id);
        }
        /// <inheritdoc />
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
                                        JsonSerializer serializer)
        {
            var item = JObject.Load(reader);

            var(_, messageType) = MessageUtils.ParseMessageType(item["@type"].ToObject <string>());

            IContentMessage message;

            switch (messageType)
            {
            case MessageTypes.ConnectionRequest:
                message = new ConnectionRequestMessage();
                break;

            case MessageTypes.ConnectionResponse:
                message = new ConnectionResponseMessage();
                break;

            case MessageTypes.CredentialOffer:
                message = new CredentialOfferMessage();
                break;

            case MessageTypes.CredentialRequest:
                message = new CredentialRequestMessage();
                break;

            case MessageTypes.Credential:
                message = new CredentialMessage();
                break;

            case MessageTypes.ProofRequest:
                message = new ProofRequestMessage();
                break;

            case MessageTypes.DisclosedProof:
                message = new ProofMessage();
                break;

            default: throw new TypeLoadException("Unsupported serialization type.");
            }

            serializer.Populate(item.CreateReader(), message);
            return(message);
        }
        /// <inheritdoc />
        public virtual async Task <string> ProcessProofRequestAsync(IAgentContext agentContext,
                                                                    ProofRequestMessage proofRequest, ConnectionRecord connection, bool isVcOidc)
        {
            var requestJson = proofRequest.ProofRequestJson;


            // Write offer record to local wallet
            var proofRecord = new ProofRecord
            {
                Id           = Guid.NewGuid().ToString(),
                RequestJson  = requestJson,
                ConnectionId = isVcOidc ? null : connection.Id,
                State        = ProofState.Requested
            };

            proofRecord.SetTag(TagConstants.LastThreadId, proofRequest.GetThreadId());
            proofRecord.SetTag(TagConstants.Role, TagConstants.Holder);

            if (!connection.Sso && !isVcOidc)
            {
                await RecordService.AddAsync(agentContext.Wallet, proofRecord);

                EventAggregator.Publish(new ServiceMessageProcessingEvent
                {
                    RecordId    = proofRecord.Id,
                    MessageType = proofRequest.Type,
                    ThreadId    = proofRequest.GetThreadId()
                });
            }
            else
            {
                if (isVcOidc)
                {
                    connection.Endpoint = new AgentEndpoint {
                        Uri = proofRequest.ServiceDecorator.ServiceEndpoint?.ToString()
                    };
                }
                await SelectCredentialsForProofAsync(agentContext, proofRecord, connection);
            }

            return(proofRecord.Id);
        }
        /// <inheritdoc />
        public virtual async Task <string> ProcessProofRequestAsync(Wallet wallet, ProofRequestMessage proofRequest)
        {
            var(didOrKey, _) = MessageUtils.ParseMessageType(proofRequest.Type);

            var connectionSearch =
                await ConnectionService.ListAsync(wallet, new SearchRecordQuery { { TagConstants.MyDid, didOrKey } });

            if (!connectionSearch.Any())
            {
                throw new Exception($"Can't find connection record for type {proofRequest.Type}");
            }
            var connection = connectionSearch.First();

            var(requestDetails, _) =
                await MessageSerializer.UnpackSealedAsync <ProofRequestDetails>(proofRequest.Content, wallet,
                                                                                connection.MyVk);

            var requestJson = requestDetails.ProofRequestJson;

            var offer = JObject.Parse(requestJson);
            var nonce = offer["nonce"].ToObject <string>();

            // Write offer record to local wallet
            var proofRecord = new ProofRecord
            {
                Id           = Guid.NewGuid().ToString(),
                RequestJson  = requestJson,
                ConnectionId = connection.GetId(),
                State        = ProofState.Requested
            };

            proofRecord.Tags[TagConstants.ConnectionId] = connection.GetId();
            proofRecord.Tags[TagConstants.Nonce]        = nonce;
            proofRecord.Tags[TagConstants.Role]         = TagConstants.Holder;

            await RecordService.AddAsync(wallet, proofRecord);

            return(proofRecord.GetId());
        }
Exemple #5
0
        /// <inheritdoc />
        public virtual async Task <string> ProcessProofRequestAsync(IAgentContext agentContext, ProofRequestMessage proofRequest)
        {
            var requestJson = proofRequest.ProofRequestJson;

            var offer = JObject.Parse(requestJson);
            var nonce = offer["nonce"].ToObject <string>();

            // Write offer record to local wallet
            var proofRecord = new ProofRecord
            {
                Id           = Guid.NewGuid().ToString(),
                RequestJson  = requestJson,
                ConnectionId = agentContext.Connection.Id,
                State        = ProofState.Requested
            };

            proofRecord.SetTag(TagConstants.Nonce, nonce);
            proofRecord.SetTag(TagConstants.Role, TagConstants.Holder);

            await RecordService.AddAsync(agentContext.Wallet, proofRecord);

            EventAggregator.Publish(new ServiceMessageProcessingEvent
            {
                RecordId    = proofRecord.Id,
                MessageType = proofRequest.Type,
            });

            return(proofRecord.Id);
        }