Example #1
0
        /// <inheritdoc />
        public virtual async Task <string> AcceptInvitationAsync(Wallet wallet, ConnectionInvitationMessage invitation)
        {
            Logger.LogInformation(LoggingEvents.AcceptInvitation, "Key {0}, Endpoint {1}",
                                  invitation.ConnectionKey, invitation.Endpoint.Uri);

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

            var connection = new ConnectionRecord
            {
                Endpoint     = invitation.Endpoint,
                MyDid        = my.Did,
                MyVk         = my.VerKey,
                ConnectionId = Guid.NewGuid().ToString().ToLowerInvariant()
            };

            connection.Tags.Add(TagConstants.MyDid, my.Did);

            if (!string.IsNullOrEmpty(invitation.Name) || !string.IsNullOrEmpty(invitation.ImageUrl))
            {
                connection.Alias = new ConnectionAlias
                {
                    Name     = invitation.Name,
                    ImageUrl = invitation.ImageUrl
                };

                if (string.IsNullOrEmpty(invitation.Name))
                {
                    connection.Tags.Add(TagConstants.Alias, invitation.Name);
                }
            }

            await connection.TriggerAsync(ConnectionTrigger.InvitationAccept);

            await RecordService.AddAsync(wallet, connection);

            var provisioning = await ProvisioningService.GetProvisioningAsync(wallet);

            var connectionDetails = new ConnectionDetails
            {
                Did      = my.Did,
                Verkey   = my.VerKey,
                Endpoint = provisioning.Endpoint
            };

            var request = await MessageSerializer.PackSealedAsync <ConnectionRequestMessage>(connectionDetails, wallet,
                                                                                             my.VerKey, invitation.ConnectionKey);

            request.Key  = invitation.ConnectionKey;
            request.Type = MessageUtils.FormatKeyMessageType(invitation.ConnectionKey, MessageTypes.ConnectionRequest);

            var forwardMessage = new ForwardToKeyEnvelopeMessage
            {
                Type    = MessageUtils.FormatKeyMessageType(invitation.ConnectionKey, MessageTypes.ForwardToKey),
                Content = request.ToJson()
            };

            await RouterService.ForwardAsync(forwardMessage, invitation.Endpoint);

            return(connection.GetId());
        }
Example #2
0
        public async Task CanParseKeyPattern()
        {
            var key = await Crypto.CreateKeyAsync(_wallet, "{}");

            var messageType = MessageUtils.FormatKeyMessageType(key, MessageTypes.ForwardToKey);

            var(parsedKey, parsedType) = MessageUtils.ParseMessageType(messageType);

            Assert.Equal(key, parsedKey);
            Assert.Equal(parsedType, MessageTypes.ForwardToKey);
        }
Example #3
0
        public void CanConvertContentMessage()
        {
            var type = MessageUtils.FormatKeyMessageType("2J6h65V5CjvWceHDMq7htRkG6EdCE2SiDEtCRyfngwfw",
                                                         MessageTypes.ConnectionRequest);

            var expected = new ConnectionRequestMessage
            {
                Key  = "2J6h65V5CjvWceHDMq7htRkG6EdCE2SiDEtCRyfngwfw",
                Type = type
            };
            var json = JsonConvert.SerializeObject(expected);

            var actual = JsonConvert.DeserializeObject <IContentMessage>(json);

            Assert.IsType <ConnectionRequestMessage>(actual);
            Assert.Equal(type, ((ConnectionRequestMessage)actual).Type);
        }