Beispiel #1
0
        public async Task TestRestrictedMamCreationAndDecryption()
        {
            var seed = new Seed("JETCPWLCYRM9XYQMMZIFZLDBZZEWRMRVGWGGNCUH9LFNEHKEMLXAVEOFFVOATCNKVKELNQFAGOVUNWEJI");
            var mask = new CurlMask();

            var iotaRepository = new InMemoryIotaRepository();
            var channelFactory = new MamChannelFactory(CurlMamFactory.Default, CurlMerkleTreeFactory.Default, iotaRepository);
            var channelKey     = new TryteString("NXRZEZIKWGKIYDPVBRKWLYTWLUVSDLDCHVVSVIWDCIUZRAKPJUIABQDZBV9EGTJWUFTIGAUT9STIENCBC");
            var channel        = channelFactory.Create(Mode.Restricted, seed, SecurityLevel.Medium, channelKey);

            var message = channel.CreateMessage(TryteString.FromUtf8String("Hello everyone!"));
            await channel.PublishAsync(message);

            var messageTwo = channel.CreateMessage(TryteString.FromUtf8String("Hello everyone the second!"));
            await channel.PublishAsync(messageTwo);

            var messageThree = channel.CreateMessage(TryteString.FromUtf8String("Hello everyone the third!"));
            await channel.PublishAsync(messageThree);

            var subcriptionFactory = new MamChannelSubscriptionFactory(
                iotaRepository,
                CurlMamParser.Default,
                mask);

            var subscription = subcriptionFactory.Create(message.Root, Mode.Restricted, channelKey);

            var unmaskedMessages = await subscription.FetchAsync();

            Assert.AreEqual("Hello everyone!", unmaskedMessages[0].Message.ToUtf8String());
            Assert.AreEqual(message.NextRoot.Value, unmaskedMessages[0].NextRoot.Value);
            Assert.AreEqual(message.Root.Value, unmaskedMessages[0].Root.Value);
            Assert.AreEqual("Hello everyone the second!", unmaskedMessages[1].Message.ToUtf8String());
            Assert.AreEqual("Hello everyone the third!", unmaskedMessages[2].Message.ToUtf8String());

            var messageFour = channel.CreateMessage(TryteString.FromUtf8String("Hello everyone the fourth!"));
            await channel.PublishAsync(messageFour);

            unmaskedMessages = await subscription.FetchNext();

            Assert.AreEqual(1, unmaskedMessages.Count);
            Assert.AreEqual("Hello everyone the fourth!", unmaskedMessages[0].Message.ToUtf8String());

            var unmaskedSingleMessage = await subscription.FetchSingle(messageTwo.Root);

            Assert.AreEqual("Hello everyone the second!", unmaskedSingleMessage.Message.ToUtf8String());
        }
Beispiel #2
0
        public async Task TestPrivateMamCreationAndDecryption()
        {
            var seed = new Seed("JETCPWLCYRM9XYQMMZIFZLDBZZEWRMRVGWGGNCUH9LFNEHKEMLXAVEOFFVOATCNKVKELNQFAGOVUNWEJI");
            var mask = new CurlMask();

            var iotaRepository = new InMemoryIotaRepository();
            var channelFactory = new MamChannelFactory(CurlMamFactory.Default, CurlMerkleTreeFactory.Default, iotaRepository);
            var channel        = channelFactory.Create(Mode.Private, seed);

            var message = channel.CreateMessage(TryteString.FromUtf8String("Hello everyone!"));
            await channel.PublishAsync(message);

            var messageTwo = channel.CreateMessage(TryteString.FromUtf8String("Hello everyone the second!"));
            await channel.PublishAsync(messageTwo);

            var messageThree = channel.CreateMessage(TryteString.FromUtf8String("Hello everyone the third!"));
            await channel.PublishAsync(messageThree);

            var subcriptionFactory = new MamChannelSubscriptionFactory(iotaRepository, CurlMamParser.Default, mask);
            var subscription       = subcriptionFactory.Create(message.Root, Mode.Private);

            var unmaskedMessages = await subscription.FetchAsync();

            Assert.AreEqual("Hello everyone!", unmaskedMessages[0].Message.ToUtf8String());
            Assert.AreEqual(message.NextRoot.Value, unmaskedMessages[0].NextRoot.Value);
            Assert.AreEqual(message.Root.Value, unmaskedMessages[0].Root.Value);
            Assert.AreEqual("Hello everyone the second!", unmaskedMessages[1].Message.ToUtf8String());
            Assert.AreEqual("Hello everyone the third!", unmaskedMessages[2].Message.ToUtf8String());

            var messageFour = channel.CreateMessage(TryteString.FromUtf8String("Hello everyone the fourth!"));
            await channel.PublishAsync(messageFour);

            unmaskedMessages = await subscription.FetchNext();

            Assert.AreEqual(1, unmaskedMessages.Count);
            Assert.AreEqual("Hello everyone the fourth!", unmaskedMessages[0].Message.ToUtf8String());
        }
Beispiel #3
0
        public async Task TestInvalidMessageOnMamStreamShouldBeIgnored()
        {
            var seed = new Seed("JETCPWLCYRM9XYQMMZIFZLDBZZEWRMRVGWGGNCUH9LFNEHKEMLXAVEOFFVOATCNKVKELNQFAGOVUNWEJI");
            var mask = new CurlMask();

            var iotaRepository = new InMemoryIotaRepository();
            var channelFactory = new MamChannelFactory(CurlMamFactory.Default, CurlMerkleTreeFactory.Default, iotaRepository);
            var channelKey     = new TryteString("NXRZEZIKWGKIYDPVBRKWLYTWLUVSDLDCHVVSVIWDCIUZRAKPJUIABQDZBV9EGTJWUFTIGAUT9STIENCBC");
            var channel        = channelFactory.Create(Mode.Restricted, seed, SecurityLevel.Medium, channelKey);

            var message = channel.CreateMessage(TryteString.FromUtf8String("Hello everyone!"));
            await channel.PublishAsync(message);

            var bundle = new Bundle();

            bundle.AddTransfer(new Transfer
            {
                Address   = message.Address,
                Message   = TryteString.FromUtf8String("I do not belong here and should be ignored!"),
                Tag       = Tag.Empty,
                Timestamp = Timestamp.UnixSecondsTimestamp
            });

            bundle.Finalize();
            bundle.Sign();

            await iotaRepository.SendTrytesAsync(bundle.Transactions, 27, 14);

            var subcriptionFactory = new MamChannelSubscriptionFactory(iotaRepository, CurlMamParser.Default, mask);
            var subscription       = subcriptionFactory.Create(message.Root, Mode.Restricted, channelKey);

            var unmaskedMessages = await subscription.FetchAsync();

            Assert.AreEqual(1, unmaskedMessages.Count);
            Assert.AreEqual("Hello everyone!", unmaskedMessages[0].Message.ToUtf8String());
        }