コード例 #1
0
        /// <inheritdoc />
        public virtual async Task <string> ProcessProofAsync(Wallet wallet, ProofMessage proof)
        {
            var(didOrKey, _) = MessageUtils.ParseMessageType(proof.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 {proof.Type}");
            }
            var connection = connectionSearch.First();

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

            var proofJson = requestDetails.ProofJson;

            var proofRecordSearch =
                await RecordService.SearchAsync <ProofRecord>(wallet,
                                                              new SearchRecordQuery { { TagConstants.Nonce, requestDetails.RequestNonce } }, null, 1);

            if (!proofRecordSearch.Any())
            {
                throw new Exception($"Can't find proof record");
            }
            var proofRecord = proofRecordSearch.Single();

            proofRecord.ProofJson = proofJson;
            await proofRecord.TriggerAsync(ProofTrigger.Accept);

            await RecordService.UpdateAsync(wallet, proofRecord);

            return(proofRecord.GetId());
        }
コード例 #2
0
        /// <inheritdoc />
        public virtual async Task <string> ProcessOfferAsync(Wallet wallet, CredentialOfferMessage credentialOffer)
        {
            var(didOrKey, _) = MessageUtils.ParseMessageType(credentialOffer.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 {credentialOffer.Type}");
            }
            var connection = connectionSearch.First();

            var(offerDetails, _) = await MessageSerializer.UnpackSealedAsync <CredentialOfferDetails>(
                credentialOffer.Content, wallet, connection.MyVk);

            var offerJson = offerDetails.OfferJson;

            var offer        = JObject.Parse(offerJson);
            var definitionId = offer["cred_def_id"].ToObject <string>();
            var schemaId     = offer["schema_id"].ToObject <string>();
            var nonce        = offer["nonce"].ToObject <string>();

            // Write offer record to local wallet
            var credentialRecord = new CredentialRecord
            {
                Id                     = Guid.NewGuid().ToString(),
                OfferJson              = offerJson,
                ConnectionId           = connection.GetId(),
                CredentialDefinitionId = definitionId,
                State                  = CredentialState.Offered
            };

            credentialRecord.Tags.Add(TagConstants.ConnectionId, connection.GetId());
            credentialRecord.Tags.Add(TagConstants.Role, TagConstants.Holder);
            credentialRecord.Tags.Add(TagConstants.Nonce, nonce);
            credentialRecord.Tags.Add(TagConstants.SchemaId, schemaId);
            credentialRecord.Tags.Add(TagConstants.DefinitionId, definitionId);

            await RecordService.AddAsync(wallet, credentialRecord);

            return(credentialRecord.GetId());
        }
コード例 #3
0
        /// <inheritdoc />
        public async Task <string> ProcessRequestAsync(Wallet wallet, ConnectionRequestMessage request)
        {
            Logger.LogInformation(LoggingEvents.StoreConnectionRequest, "Key {0}", request.Key);

            var(didOrKey, _) = MessageUtils.ParseMessageType(request.Type);

            var connectionSearch = await RecordService.SearchAsync <ConnectionRecord>(wallet,
                                                                                      new SearchRecordQuery { { TagConstants.ConnectionKey, didOrKey } }, null, 1);

            var connection = connectionSearch.Single();

            var(their, theirKey) =
                await MessageSerializer.UnpackSealedAsync <ConnectionDetails>(request.Content, wallet, request.Key);

            if (!their.Verkey.Equals(theirKey))
            {
                throw new ArgumentException("Signed and enclosed keys don't match");
            }

            await connection.TriggerAsync(ConnectionTrigger.InvitationAccept);

            var my = await Did.CreateAndStoreMyDidAsync(wallet, "{}");

            await Did.StoreTheirDidAsync(wallet, new { did = their.Did, verkey = their.Verkey }.ToJson());

            connection.Endpoint = their.Endpoint;
            connection.TheirDid = their.Did;
            connection.TheirVk  = their.Verkey;
            connection.MyDid    = my.Did;
            connection.MyVk     = my.VerKey;
            connection.Tags[TagConstants.MyDid]    = my.Did;
            connection.Tags[TagConstants.TheirDid] = their.Did;

            await RecordService.UpdateAsync(wallet, connection);

            if (connection.Tags.Any(_ => _.Key == TagConstants.AutoAcceptConnection && _.Value == "true"))
            {
                await AcceptRequestAsync(wallet, connection.ConnectionId);
            }

            return(connection.GetId());
        }