static DependencyResolver() { var iotaRepository = new CachedIotaRestRepository( new FallbackIotaClient(new List <string> { "https://nodes.devnet.thetangle.org:443" }, 5000), new PoWSrvService()); var channelFactory = new MamChannelFactory(CurlMamFactory.Default, CurlMerkleTreeFactory.Default, iotaRepository); var subscriptionFactory = new MamChannelSubscriptionFactory(iotaRepository, CurlMamParser.Default, CurlMask.Default); var encryption = new RijndaelEncryption("somenicekey", "somenicesalt"); var resourceTracker = new SqlLiteResourceTracker(channelFactory, subscriptionFactory, encryption); var fhirRepository = new IotaFhirRepository( iotaRepository, new FhirJsonTryteSerializer(), resourceTracker, new SqlLiteDeterministicSeedManager( resourceTracker, new IssSigningHelper(new Curl(), new Curl(), new Curl()), new AddressGenerator(), iotaRepository, encryption)); var fhirParser = new FhirJsonParser(); var searchRepository = new SqlLiteSearchRepository(fhirParser); CreateResourceInteractor = new CreateResourceInteractor(fhirRepository, fhirParser, searchRepository); ReadResourceInteractor = new ReadResourceInteractor(fhirRepository, searchRepository); ValidateResourceInteractor = new ValidateResourceInteractor(fhirRepository, fhirParser); SearchResourcesInteractor = new SearchResourcesInteractor(fhirRepository, searchRepository); ResourceTracker = resourceTracker; }
public async Task TestResourceUpdateAddsAndUpdatesInformation() { var iotaRepository = IotaResourceProvider.Repository; var channelFactory = new MamChannelFactory(CurlMamFactory.Default, CurlMerkleTreeFactory.Default, iotaRepository); var subscriptionFactory = new MamChannelSubscriptionFactory(iotaRepository, CurlMamParser.Default, CurlMask.Default); var tracker = new SqlLiteResourceTracker(channelFactory, subscriptionFactory, new RijndaelEncryption(Seed.Random().Value, Seed.Random().Value)); // fhir id will only be 64 chars long var resourceId = Seed.Random().Value.Substring(0, 64); await tracker.AddEntryAsync( new ResourceEntry { Channel = channelFactory.Create(Mode.Restricted, Seed.Random(), SecurityLevel.Medium, Seed.Random().Value, true), Subscription = subscriptionFactory.Create(new Hash(Seed.Random().Value), Mode.Restricted, Seed.Random().Value, true), ResourceRoots = new List <string> { resourceId } }); var resource = await tracker.GetEntryAsync(resourceId); resource.ResourceRoots.Add(Seed.Random().Value.Substring(0, 64)); await tracker.UpdateEntryAsync(resource); Assert.AreEqual(2, (await tracker.GetEntryAsync(resourceId)).ResourceRoots.Count); }
public ClaimsService(ILogger <ClaimsService> logger) { m_logger = logger; // Connect to a node on one of the main networks. var iotaRepositoryUrl = Environment.GetEnvironmentVariable("IOTA_REPOSITORY"); m_logger.LogInformation($"Using IOTA_REPOSITORY={iotaRepositoryUrl}"); m_restIotaRepository = new RestIotaRepository(new RestClient(iotaRepositoryUrl)); m_mamChannelFactory = new MamChannelFactory(CurlMamFactory.Default, CurlMerkleTreeFactory.Default, m_restIotaRepository); m_mamChannelSubscriptionFactory = new MamChannelSubscriptionFactory(m_restIotaRepository, CurlMamParser.Default, CurlMask.Default); }
public ResourceTracker( MamChannelFactory channelFactory, MamChannelSubscriptionFactory subscriptionFactory, IEncryption encryption, string databaseFilename = "iotafhir.sqlite") { this.ChannelFactory = channelFactory; this.SubscriptionFactory = subscriptionFactory; this.Encryption = encryption; this.ConnectionString = databaseFilename; this.Init(databaseFilename); }
/// <inheritdoc /> protected override void Load(ContainerBuilder builder) { var connectionSupplier = new DefaultDbConnectionSupplier(); var iotaRepository = new CachedIotaRestRepository( new FallbackIotaClient(new List <string> { "https://nodes.devnet.thetangle.org:443" }, 5000), new PoWSrvService(), null, connectionSupplier, $"{DependencyResolver.LocalStoragePath}\\iotacache.sqlite"); var channelFactory = new MamChannelFactory(CurlMamFactory.Default, CurlMerkleTreeFactory.Default, iotaRepository); var subscriptionFactory = new MamChannelSubscriptionFactory(iotaRepository, CurlMamParser.Default, CurlMask.Default); var encryption = new RijndaelEncryption("somenicekey", "somenicesalt"); var resourceTracker = new SqlLiteResourceTracker( channelFactory, subscriptionFactory, encryption, connectionSupplier, $"{DependencyResolver.LocalStoragePath}\\iotafhir.sqlite"); var seedManager = new SqlLiteDeterministicSeedManager( resourceTracker, new IssSigningHelper(new Curl(), new Curl(), new Curl()), new AddressGenerator(), iotaRepository, encryption, connectionSupplier, $"{DependencyResolver.LocalStoragePath}\\iotafhir.sqlite"); var fhirRepository = new IotaFhirRepository(iotaRepository, new FhirJsonTryteSerializer(), resourceTracker, seedManager); var fhirParser = new FhirJsonParser(); var searchRepository = new SqlLiteSearchRepository(fhirParser, connectionSupplier, $"{DependencyResolver.LocalStoragePath}\\resources.sqlite"); var createInteractor = new CreateResourceInteractor(fhirRepository, fhirParser, searchRepository); var readInteractor = new ReadResourceInteractor(fhirRepository, searchRepository); var validationInteractor = new ValidateResourceInteractor(fhirRepository, fhirParser); var searchInteractor = new SearchResourcesInteractor(fhirRepository, searchRepository); var resourceImporter = new ResourceImporter(searchRepository, fhirRepository, seedManager); builder.RegisterInstance(createInteractor); builder.RegisterInstance(readInteractor); builder.RegisterInstance(validationInteractor); builder.RegisterInstance(searchInteractor); builder.RegisterInstance(resourceImporter); builder.RegisterInstance(seedManager).As <ISeedManager>(); builder.RegisterInstance(subscriptionFactory); }
private void InjectDependencies(IServiceCollection services) { var iotaRepository = new CachedIotaRestRepository( new FallbackIotaClient(new List <string> { "https://nodes.devnet.thetangle.org:443" }, 5000), new PoWService(new CpuPearlDiver())); var channelFactory = new MamChannelFactory(CurlMamFactory.Default, CurlMerkleTreeFactory.Default, iotaRepository); var subscriptionFactory = new MamChannelSubscriptionFactory(iotaRepository, CurlMamParser.Default, CurlMask.Default); var encryption = new RijndaelEncryption("somenicekey", "somenicesalt"); var resourceTracker = new SqlLiteResourceTracker(channelFactory, subscriptionFactory, encryption); var seedManager = new SqlLiteDeterministicSeedManager( resourceTracker, new IssSigningHelper(new Curl(), new Curl(), new Curl()), new AddressGenerator(), iotaRepository, encryption); var fhirRepository = new IotaFhirRepository(iotaRepository, new FhirJsonTryteSerializer(), resourceTracker, seedManager); var fhirParser = new FhirJsonParser(); var searchRepository = new SqlLiteSearchRepository(fhirParser); var createInteractor = new CreateResourceInteractor(fhirRepository, fhirParser, searchRepository); var readInteractor = new ReadResourceInteractor(fhirRepository, searchRepository); var readVersionInteractor = new ReadResourceVersionInteractor(fhirRepository); var readHistoryInteractor = new ReadResourceHistoryInteractor(fhirRepository); var capabilitiesInteractor = new GetCapabilitiesInteractor(fhirRepository, new AppConfigSystemInformation(this.Configuration)); var validationInteractor = new ValidateResourceInteractor(fhirRepository, fhirParser); var searchInteractor = new SearchResourcesInteractor(fhirRepository, searchRepository); var deleteInteractor = new DeleteResourceInteractor(fhirRepository, searchRepository); var resourceImporter = new ResourceImporter(searchRepository, fhirRepository, seedManager); services.AddScoped(provider => createInteractor); services.AddScoped(provider => readInteractor); services.AddScoped(provider => capabilitiesInteractor); services.AddScoped(provider => validationInteractor); services.AddScoped(provider => searchInteractor); services.AddScoped(provider => resourceImporter); services.AddScoped(provider => readVersionInteractor); services.AddScoped(provider => readHistoryInteractor); services.AddScoped(provider => deleteInteractor); services.AddScoped <ISeedManager>(provider => seedManager); services.AddSingleton <IMemoryCache>(new Microsoft.Extensions.Caching.Memory.MemoryCache(new MemoryCacheOptions())); }
public void TestSubscriptionCreationAndRecreation() { var mask = new CurlMask(); var subscriptionFactory = new MamChannelSubscriptionFactory(new InMemoryIotaRepository(), CurlMamParser.Default, mask); var root = new Hash(Seed.Random().Value); var channelKey = Seed.Random(); var subscription = subscriptionFactory.Create(root, Mode.Restricted, channelKey.Value, true); var serializedSubscription = subscription.ToJson(); var recreatedSubscription = subscriptionFactory.CreateFromJson(serializedSubscription); Assert.AreEqual(root.Value, recreatedSubscription.MessageRoot.Value); }
public SqlLiteResourceTracker( MamChannelFactory channelFactory, MamChannelSubscriptionFactory subscriptionFactory, IEncryption encryption, IDbConnectionSupplier connectionSupplier = null, string databaseFilename = "iotafhir.sqlite") { this.ChannelFactory = channelFactory; this.SubscriptionFactory = subscriptionFactory; this.Encryption = encryption; this.ConnectionSupplier = connectionSupplier ?? new DefaultDbConnectionSupplier(); this.ConnectionString = $"Data Source={databaseFilename};Version=3;"; DatabaseInitializer.InitFhirDatabase(this.ConnectionSupplier, databaseFilename); }
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()); }
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()); }
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()); }
public async Task TestEntryCanBeWrittenAndRead() { var iotaRepository = IotaResourceProvider.Repository; var channelFactory = new MamChannelFactory(CurlMamFactory.Default, CurlMerkleTreeFactory.Default, iotaRepository); var subscriptionFactory = new MamChannelSubscriptionFactory(iotaRepository, CurlMamParser.Default, CurlMask.Default); var tracker = new SqlLiteResourceTracker(channelFactory, subscriptionFactory, new RijndaelEncryption(Seed.Random().Value, Seed.Random().Value)); // fhir id will only be 64 chars long var resourceId = Seed.Random().Value.Substring(0, 64); await tracker.AddEntryAsync( new ResourceEntry { Channel = channelFactory.Create(Mode.Restricted, Seed.Random(), SecurityLevel.Medium, Seed.Random().Value, true), Subscription = subscriptionFactory.Create(new Hash(Seed.Random().Value), Mode.Restricted, Seed.Random().Value, true), ResourceRoots = new List <string> { resourceId } }); var resource = await tracker.GetEntryAsync(resourceId); Assert.IsTrue(resource.ResourceRoots.FirstOrDefault(h => h == resourceId) != null); }
public async Task TestNoMessagesAreOnMamStreamShouldThrowException() { var iotaRepository = IotaResourceProvider.Repository; var channelFactory = new MamChannelFactory(CurlMamFactory.Default, CurlMerkleTreeFactory.Default, iotaRepository); var subscriptionFactory = new MamChannelSubscriptionFactory(iotaRepository, CurlMamParser.Default, CurlMask.Default); var resourceTracker = new InMemoryResourceTracker(); await resourceTracker.AddEntryAsync( new ResourceEntry { Channel = channelFactory.Create(Mode.Restricted, Seed.Random(), SecurityLevel.Medium, Seed.Random().Value, true), Subscription = subscriptionFactory.Create(new Hash(Seed.Random().Value), Mode.Restricted, Seed.Random().Value, true), ResourceRoots = new List <string> { "SOMEID" } }); var repository = new IotaFhirRepository( iotaRepository, new FhirJsonTryteSerializer(), resourceTracker, new RandomSeedManager()); await repository.ReadResourceAsync("SOMEID"); }
public ResourceEntry ToResourceEntry(IEncryption encryption, MamChannelFactory channelFactory, MamChannelSubscriptionFactory subscriptionFactory) { var decryptedChannel = encryption.Decrypt(this.Channel); var decryptedSubscription = encryption.Decrypt(this.Subscription); return(new ResourceEntry { ResourceRoots = this.Roots.Split(';').ToList(), Channel = string.IsNullOrEmpty(decryptedChannel) ? null : channelFactory.CreateFromJson(decryptedChannel), Subscription = subscriptionFactory.CreateFromJson(decryptedSubscription) }); }
/// <inheritdoc /> protected override void Load(ContainerBuilder builder) { var iotaRepository = new RestIotaRepository( new FallbackIotaClient(new List <string> { "https://nodes.devnet.thetangle.org:443" }, 5000), new PoWService(new CpuPearlDiver())); var channelFactory = new MamChannelFactory(CurlMamFactory.Default, CurlMerkleTreeFactory.Default, iotaRepository); var subscriptionFactory = new MamChannelSubscriptionFactory(iotaRepository, CurlMamParser.Default, CurlMask.Default); var encryption = new RijndaelEncryption("somenicekey", "somenicesalt"); var resourceTracker = new ResourceTracker( channelFactory, subscriptionFactory, encryption, $"{DependencyResolver.LocalStoragePath}\\resources.sqlite"); var seedManager = new SeedManager( resourceTracker, new IssSigningHelper(new Curl(), new Curl(), new Curl()), new AddressGenerator(), iotaRepository, encryption, $"{DependencyResolver.LocalStoragePath}\\seedmanager.sqlite"); var fhirRepository = new IotaFhirRepository(iotaRepository, new FhirJsonTryteSerializer(), resourceTracker, seedManager); var fhirParser = new FhirJsonParser(); var searchRepository = new SearchRepository($"{DependencyResolver.LocalStoragePath}\\search.sqlite"); var createInteractor = new CreateResourceInteractor(fhirRepository, fhirParser, searchRepository); var readInteractor = new ReadResourceInteractor(fhirRepository, searchRepository); var validationInteractor = new ValidateResourceInteractor(fhirRepository, fhirParser); var searchInteractor = new SearchResourcesInteractor(fhirRepository, searchRepository); var resourceImporter = new ResourceImporter(searchRepository, fhirRepository, seedManager); builder.RegisterInstance(searchRepository).As <ISearchRepository>(); builder.RegisterInstance(resourceTracker).As <IResourceTracker>(); builder.RegisterInstance(createInteractor); builder.RegisterInstance(readInteractor); builder.RegisterInstance(validationInteractor); builder.RegisterInstance(searchInteractor); builder.RegisterInstance(resourceImporter); builder.RegisterInstance(seedManager).As <ISeedManager>(); builder.RegisterInstance(subscriptionFactory); builder.RegisterInstance(fhirRepository).As <IFhirRepository>(); builder.RegisterInstance(new AndroidLogout()).As <ILogout>(); var backgroundWorker = new BackgroundWorkerService(); var glucoseService = new FhirGlucoseService( new CreateResourceInteractor(fhirRepository, fhirParser, searchRepository), new UpdateResourceInteractor(fhirRepository, fhirParser), new ReadResourceInteractor(fhirRepository, searchRepository), searchRepository); var glucoseRepository = new DexcomGlucoseManagementRepository(new RestClient("https://sandbox-api.dexcom.com")); //backgoundWorker.RegisterTaskWorker(new ContinuousGlucoseTaskWorker(glucoseService, glucoseRepository)); backgroundWorker.RegisterTaskWorker(new AggregateGlucoseTaskWorker(glucoseService, glucoseRepository)); }