Beispiel #1
0
 public FullTransactionSingleModule(ILoggerService loggerService, IClientCommunicationServiceRepository clientCommunicationServiceRepository,
                                    IConfigurationService configurationService, IIdentityKeyProvidersRegistry identityKeyProvidersRegistry,
                                    ISerializersFactory signatureSupportSerializersFactory, INodesDataService nodesDataService,
                                    ISigningService cryptoService, IPerformanceCountersRepository performanceCountersRepository, IHashCalculationsRepository hashCalculationRepository)
     : base(loggerService, clientCommunicationServiceRepository, configurationService, identityKeyProvidersRegistry, signatureSupportSerializersFactory, nodesDataService, cryptoService, performanceCountersRepository, hashCalculationRepository)
 {
 }
Beispiel #2
0
        public ElevationManager(ILog logger, ISigningService signService)
        {
            Logger = logger;

            lockObj      = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
            authTokenMap = new Dictionary <Guid, ManagedSession>();

            signingService = signService;
        }
 public AuthController(
     IAuthRepository repository,
     IUserRepository usersRepository,
     IConfiguration configuration,
     ISigningService signing,
     IMapper mapper)
 {
     _repository      = repository;
     _usersRepository = usersRepository;
     _configuration   = configuration;
     _signing         = signing;
     _mapper          = mapper;
 }
Beispiel #4
0
 public LoadModuleBase(ILoggerService loggerService, IClientCommunicationServiceRepository clientCommunicationServiceRepository,
                       IConfigurationService configurationService, IIdentityKeyProvidersRegistry identityKeyProvidersRegistry,
                       ISerializersFactory signatureSupportSerializersFactory, INodesDataService nodesDataService, ISigningService cryptoService,
                       IPerformanceCountersRepository performanceCountersRepository, IHashCalculationsRepository hashCalculationRepository)
     : base(loggerService)
 {
     _communicationService   = clientCommunicationServiceRepository.GetInstance(nameof(TcpClientCommunicationService));
     _configurationService   = configurationService;
     _serializersFactory     = signatureSupportSerializersFactory;
     _nodesDataService       = nodesDataService;
     _cryptoService          = cryptoService;
     _identityKeyProvider    = identityKeyProvidersRegistry.GetInstance();
     _loadCountersService    = performanceCountersRepository.GetInstance <LoadCountersService>();
     _hashCalculation        = hashCalculationRepository.Create(Globals.DEFAULT_HASH);
     _proofOfWorkCalculation = hashCalculationRepository.Create(Globals.POW_TYPE);
 }
 public MainPlatform(
     IUserInput userInputService,
     IOptions <UserInfoSettings> options,
     ISigningService signingService,
     IGamePlatform gamePlatform,
     ILogger <MainPlatform> logger,
     ISingleStorage <AuthInfo> authInfo,
     IStatisticsService statisticsService)
 {
     _userInputService  = userInputService;
     _settings          = options.Value;
     _signingService    = signingService;
     _gamePlatform      = gamePlatform;
     _logger            = logger;
     _authInfo          = authInfo;
     _statisticsService = statisticsService;
 }
Beispiel #6
0
        public void Initialize(byte[] secretKey, CancellationToken ct)
        {
            if (secretKey == null)
            {
                throw new ArgumentNullException(nameof(secretKey));
            }

            ISigningService signingService = _signingServicesRepository.GetInstance("AccountSigningService");

            signingService.Initialize(secretKey);
            _nodeContext.Initialize(signingService);

            InitializeCommunicationLayer();

            ObtainConfiguredModules();

            InitializeModules(ct);
        }
Beispiel #7
0
        public TestBase()
        {
            _transactionHashKeyProvider         = Substitute.For <IIdentityKeyProvider>();
            _identityKeyProvider                = Substitute.For <IIdentityKeyProvider>();
            _identityKeyProvidersRegistry       = Substitute.For <IIdentityKeyProvidersRegistry>();
            _hashCalculationRepository          = Substitute.For <IHashCalculationsRepository>();
            _blockParsersRepositoriesRepository = Substitute.For <IBlockParsersRepositoriesRepository>();
            _blockParsersRepository             = Substitute.For <IBlockParsersRepository>();
            _signingService = Substitute.For <ISigningService>();

            _identityKeyProvidersRegistry.GetInstance().Returns(_identityKeyProvider);
            _identityKeyProvidersRegistry.GetTransactionsIdenityKeyProvider().Returns(_transactionHashKeyProvider);
            _identityKeyProvider.GetKey(null).ReturnsForAnyArgs(c => new Key32()
            {
                Value = c.Arg <Memory <byte> >()
            });
            _transactionHashKeyProvider.GetKey(null).ReturnsForAnyArgs(c => new Key16()
            {
                Value = c.Arg <Memory <byte> >()
            });
            _hashCalculationRepository.Create(HashType.MurMur).Returns(new MurMurHashCalculation());
            _blockParsersRepositoriesRepository.GetBlockParsersRepository(PacketType.Registry).ReturnsForAnyArgs(_blockParsersRepository);

            _privateKey     = ConfidentialAssetsHelper.GetRandomSeed();
            _privateViewKey = ConfidentialAssetsHelper.GetRandomSeed();
            Ed25519.KeyPairFromSeed(out _publicKey, out _expandedPrivateKey, _privateKey);

            _signingService.WhenForAnyArgs(s => s.Sign(null, null)).Do(c =>
            {
                ((SignedPacketBase)c.ArgAt <IPacket>(0)).Signer    = new Key32(_publicKey);
                ((SignedPacketBase)c.ArgAt <IPacket>(0)).Signature = Ed25519.Sign(((SignedPacketBase)c.ArgAt <IPacket>(0)).BodyBytes.ToArray(), _expandedPrivateKey);
            });
            _signingService.PublicKeys.Returns(new IKey[] { new Key32()
                                                            {
                                                                Value = _publicKey
                                                            } });

            _utxoSigningService = new UtxoSigningService(_identityKeyProvidersRegistry);
            _utxoSigningService.Initialize(_privateKey, _privateViewKey);


            ServiceLocator.Current.GetInstance <IUnityContainer>().RegisterInstance(_blockParsersRepositoriesRepository);
        }
Beispiel #8
0
        private static SortedList <ushort, RegistryRegisterBlock> GetTransactionHeaders(ulong syncBlockHeight, ulong blockHeight, uint nonce, ushort expectedCount)
        {
            PacketType expectedReferencedPacketType = PacketType.Transactional;
            ushort     expectedReferencedBlockType  = BlockTypes.Transaction_TransferFunds;

            SortedList <ushort, RegistryRegisterBlock> transactionHeaders = new SortedList <ushort, RegistryRegisterBlock>(expectedCount);

            for (ushort j = 0; j < expectedCount; j++)
            {
                RegistryRegisterBlock registryRegisterBlock = new RegistryRegisterBlock
                {
                    SyncBlockHeight      = syncBlockHeight,
                    Nonce                = nonce + j,
                    PowHash              = BinaryHelper.GetPowHash(1234 + j),
                    BlockHeight          = blockHeight,
                    ReferencedPacketType = expectedReferencedPacketType,
                    ReferencedBlockType  = expectedReferencedBlockType,
                    ReferencedBodyHash   = BinaryHelper.GetDefaultHash(473826643 + j),
                    ReferencedTarget     = BinaryHelper.GetDefaultHash(BinaryHelper.GetRandomPublicKey())
                };

                ISigningService signingService = GetRandomCryptoService();

                IIdentityKeyProvider transactionIdentityKeyProvider = Substitute.For <IIdentityKeyProvider>();
                transactionIdentityKeyProvider.GetKey(null).ReturnsForAnyArgs(c => new Key16(c.ArgAt <Memory <byte> >(0)));
                IIdentityKeyProvidersRegistry transactionIdentityKeyProvidersRegistry = Substitute.For <IIdentityKeyProvidersRegistry>();
                transactionIdentityKeyProvidersRegistry.GetTransactionsIdenityKeyProvider().Returns(transactionIdentityKeyProvider);

                IHashCalculationsRepository transactionHashCalculationsRepository = Substitute.For <IHashCalculationsRepository>();
                transactionHashCalculationsRepository.Create(HashType.MurMur).Returns(new MurMurHashCalculation());

                RegistryRegisterBlockSerializer serializer1 = new RegistryRegisterBlockSerializer();
                serializer1.Initialize(registryRegisterBlock);
                serializer1.SerializeBody();
                signingService.Sign(registryRegisterBlock);
                serializer1.SerializeFully();

                transactionHeaders.Add(j, registryRegisterBlock);
            }

            return(transactionHeaders);
        }
Beispiel #9
0
        private static ISigningService GetRandomCryptoService()
        {
            ISigningService signingService = Substitute.For <ISigningService>();

            byte[] privateKey = ConfidentialAssetsHelper.GetRandomSeed();
            byte[] expandedPrivateKey;
            byte[] publicKey;
            Ed25519.KeyPairFromSeed(out publicKey, out expandedPrivateKey, privateKey);
            signingService.WhenForAnyArgs(s => s.Sign(null, null)).Do(c =>
            {
                ((SignedPacketBase)c.ArgAt <IPacket>(0)).Signer = new Key32()
                {
                    Value = publicKey
                };
                ((SignedPacketBase)c.ArgAt <IPacket>(0)).Signature = Ed25519.Sign(c.Arg <byte[]>(), expandedPrivateKey);
            });
            signingService.PublicKeys.Returns(new IKey[] { new Key32()
                                                           {
                                                               Value = publicKey
                                                           } });
            return(signingService);
        }
Beispiel #10
0
 public TransactionRegistrationLoadModule(ILoggerService loggerService, IClientCommunicationServiceRepository clientCommunicationServiceRepository, IConfigurationService configurationService, IIdentityKeyProvidersRegistry identityKeyProvidersRegistry, ISerializersFactory signatureSupportSerializersFactory, INodesDataService nodesDataService, ISigningService cryptoService, IPerformanceCountersRepository performanceCountersRepository, IStatesRepository statesRepository, IHashCalculationsRepository proofOfWorkCalculationRepository, IHashCalculationsRepository hashCalculationRepository)
     : base(loggerService, clientCommunicationServiceRepository, configurationService, identityKeyProvidersRegistry, signatureSupportSerializersFactory, nodesDataService, cryptoService, performanceCountersRepository, hashCalculationRepository)
 {
     _synchronizationContext = statesRepository.GetInstance <ISynchronizationContext>();
     _proofOfWorkCalculation = proofOfWorkCalculationRepository.Create(Globals.POW_TYPE);
 }
Beispiel #11
0
        public void MemPool_AddedNonUniqueTransactions_NotAllContained()
        {
            SynchronizationDescriptor synchronizationDescriptor = new SynchronizationDescriptor(1, new byte[Globals.DEFAULT_HASH_SIZE], DateTime.Now, DateTime.Now, 1);
            IHash                         transactionKeyHash    = HashFactory.Hash128.CreateMurmur3_128();
            ILogger                       logger                       = Substitute.For <ILogger>();
            ILoggerService                loggerService                = Substitute.For <ILoggerService>();
            IIdentityKeyProvider          identityKeyProvider          = new TransactionRegistryKeyProvider();
            IIdentityKeyProvidersRegistry identityKeyProvidersRegistry = Substitute.For <IIdentityKeyProvidersRegistry>();
            IHashCalculationsRepository   hashCalculationsRepository   = Substitute.For <IHashCalculationsRepository>();
            ISigningService               signingService               = Substitute.For <ISigningService>();
            SynchronizationContext        synchronizationContext       = new SynchronizationContext(loggerService);

            synchronizationContext.UpdateLastSyncBlockDescriptor(synchronizationDescriptor);
            IStatesRepository statesRepository = Substitute.For <IStatesRepository>();

            hashCalculationsRepository.Create(HashType.MurMur).Returns(new MurMurHashCalculation());

            logger.WhenForAnyArgs(l => l.Error(null)).DoNotCallBase();
            logger.WhenForAnyArgs(l => l.Warning(null)).DoNotCallBase();
            logger.WhenForAnyArgs(l => l.Info(null)).DoNotCallBase();
            loggerService.GetLogger(null).Returns(logger);

            identityKeyProvidersRegistry.GetTransactionsIdenityKeyProvider().ReturnsForAnyArgs(identityKeyProvider);
            //identityKeyProvider.GetKey(null).ReturnsForAnyArgs(c => new Key16() { Value = c.Arg<Memory<byte>>() });

            statesRepository.GetInstance <ISynchronizationContext>().Returns(synchronizationContext);

            byte[] privateKey = ConfidentialAssetsHelper.GetRandomSeed();
            Ed25519.KeyPairFromSeed(out byte[] publicKey, out byte[] expandedPrivateKey, privateKey);

            signingService.WhenForAnyArgs(s => s.Sign(null, null)).Do(c =>
            {
                ((SignedPacketBase)c.ArgAt <IPacket>(0)).Signer    = new Key32(publicKey);
                ((SignedPacketBase)c.ArgAt <IPacket>(0)).Signature = Ed25519.Sign(c.Arg <byte[]>(), expandedPrivateKey);
            });
            signingService.PublicKeys.ReturnsForAnyArgs(new IKey[] { new Key32(publicKey) });

            TransactionRegistryMemPool transactionRegistryMemPool = new TransactionRegistryMemPool(loggerService, identityKeyProvidersRegistry, statesRepository, hashCalculationsRepository);

            SortedList <ushort, RegistryRegisterBlock> expectedBlocks = new SortedList <ushort, RegistryRegisterBlock>();

            ulong[] heights = new ulong[] { 1, 2, 2, 5, 4, 3, 4, 3, 4, 5, 3 };

            HashSet <ulong> addedHeights = new HashSet <ulong>();
            ushort          order        = 0;

            for (ulong i = 0; i < (ulong)heights.Length; i++)
            {
                RegistryRegisterBlock transactionRegisterBlock = PacketsBuilder.GetTransactionRegisterBlock(synchronizationContext.LastBlockDescriptor.BlockHeight, 1, null,
                                                                                                            heights[i], PacketType.Transactional, BlockTypes.Transaction_TransferFunds, new byte[Globals.POW_HASH_SIZE], new byte[Globals.DEFAULT_HASH_SIZE], privateKey);

                RegistryRegisterBlockSerializer serializer = new RegistryRegisterBlockSerializer();
                serializer.Initialize(transactionRegisterBlock);
                serializer.SerializeBody();
                signingService.Sign(transactionRegisterBlock);
                serializer.SerializeFully();

                if (!addedHeights.Contains(heights[i]))
                {
                    expectedBlocks.Add(order++, transactionRegisterBlock);
                    addedHeights.Add(heights[i]);
                }

                transactionRegistryMemPool.EnqueueTransactionWitness(transactionRegisterBlock);
            }

            SortedList <ushort, RegistryRegisterBlock> actualBlocks = transactionRegistryMemPool.DequeueStateWitnessBulk();

            Assert.Equal(expectedBlocks.Count, actualBlocks.Count);
            for (ushort i = 0; i < (ushort)expectedBlocks.Count; i++)
            {
                Assert.Equal(expectedBlocks[i].BlockHeight, actualBlocks[i].BlockHeight);
            }
        }
Beispiel #12
0
 public void Initialize(ISigningService signingService)
 {
     SigningService = signingService;
     AccountKey     = SigningService.PublicKeys[0];
 }
Beispiel #13
0
        public void GetMostConfidentFullBlockTest()
        {
            List <RegistryFullBlock>  registryFullBlocks    = new List <RegistryFullBlock>();
            List <RegistryShortBlock> registryShortBlocks   = new List <RegistryShortBlock>();
            Dictionary <IKey, int>    votesPerShortBlockKey = new Dictionary <IKey, int>();

            int   fullBlockCount  = 10;
            int   votersCount     = 100;
            ulong syncBlockHeight = 1;
            ulong blockHeight     = 12;
            uint  nonce           = 0;

            byte[]           powHash = BinaryHelper.GetPowHash(1234);
            IHashCalculation hashCalculationTransactionKey = new MurMurHashCalculation();

            IHashCalculation              hashCalculationDefault            = new Keccak256HashCalculation();
            IHashCalculation              hashCalculationMurMur             = new MurMurHashCalculation();
            ISerializersFactory           serializersFactory                = Substitute.For <ISerializersFactory>();
            IHashCalculationsRepository   hashCalculationsRepository        = Substitute.For <IHashCalculationsRepository>();
            IIdentityKeyProvider          identityKeyProviderTransactionKey = Substitute.For <IIdentityKeyProvider>();
            IIdentityKeyProvidersRegistry identityKeyProvidersRegistry      = Substitute.For <IIdentityKeyProvidersRegistry>();
            ISigningService         signingService         = GetRandomCryptoService();
            ILoggerService          loggerService          = Substitute.For <ILoggerService>();
            IStatesRepository       statesRepository       = Substitute.For <IStatesRepository>();
            ISynchronizationContext synchronizationContext = new Wist.Core.Synchronization.SynchronizationContext(loggerService);

            statesRepository.GetInstance <ISynchronizationContext>().ReturnsForAnyArgs(synchronizationContext);

            identityKeyProviderTransactionKey.GetKey(null).ReturnsForAnyArgs(c => new Key16(c.ArgAt <Memory <byte> >(0)));

            identityKeyProvidersRegistry.GetInstance("DefaultHash").Returns(new DefaultHashKeyProvider());
            identityKeyProvidersRegistry.GetTransactionsIdenityKeyProvider().Returns(identityKeyProviderTransactionKey);

            hashCalculationsRepository.Create(HashType.Keccak256).Returns(hashCalculationDefault);
            hashCalculationsRepository.Create(HashType.MurMur).Returns(hashCalculationMurMur);

            serializersFactory.Create(null).ReturnsForAnyArgs(c =>
            {
                RegistryShortBlockSerializer registryShortBlockSerializer = new RegistryShortBlockSerializer();
                registryShortBlockSerializer.Initialize(c.Arg <SignedPacketBase>());
                return(registryShortBlockSerializer);
            });

            SyncRegistryMemPool syncRegistryMemPool = new SyncRegistryMemPool(loggerService, hashCalculationsRepository);

            for (int i = 0; i < fullBlockCount; i++)
            {
                ISigningService signingService1 = GetRandomCryptoService();
                ushort          expectedCount   = 1000;

                SortedList <ushort, RegistryRegisterBlock> transactionHeaders = GetTransactionHeaders(syncBlockHeight, blockHeight, nonce, expectedCount);
                WitnessStateKey[] transactionHeaderKeys = GetTransactionHeaderKeys(transactionHeaders);

                RegistryShortBlock registryShortBlock = new RegistryShortBlock
                {
                    SyncBlockHeight  = syncBlockHeight,
                    BlockHeight      = blockHeight,
                    Nonce            = nonce,
                    PowHash          = powHash,
                    WitnessStateKeys = transactionHeaderKeys
                };

                RegistryShortBlockSerializer registryShortBlockSerializer = new RegistryShortBlockSerializer();
                registryShortBlockSerializer.Initialize(registryShortBlock);
                registryShortBlockSerializer.SerializeBody();
                signingService1.Sign(registryShortBlock);
                registryShortBlockSerializer.SerializeFully();

                RegistryFullBlock registryFullBlock = new RegistryFullBlock
                {
                    SyncBlockHeight = syncBlockHeight,
                    BlockHeight     = blockHeight,
                    Nonce           = nonce,
                    PowHash         = powHash,
                    StateWitnesses  = transactionHeaders.Values.ToArray(),
                    ShortBlockHash  = hashCalculationDefault.CalculateHash(registryShortBlock.RawData)
                };

                RegistryFullBlockSerializer serializer = new RegistryFullBlockSerializer();
                serializer.Initialize(registryFullBlock);
                serializer.SerializeBody();
                signingService.Sign(registryFullBlock);
                serializer.SerializeFully();

                registryFullBlocks.Add(registryFullBlock);
                registryShortBlocks.Add(registryShortBlock);
            }

            foreach (RegistryFullBlock fullBlock in registryFullBlocks)
            {
                syncRegistryMemPool.AddCandidateBlock(fullBlock);
            }

            IKey expectedMostConfidentKey = votesPerShortBlockKey.OrderByDescending(kv => kv.Value).Select(kv => kv.Key).First();

            IEnumerable <RegistryFullBlock> actualFullBlocks = syncRegistryMemPool.GetRegistryBlocks();
        }
Beispiel #14
0
 public SignController(ISigningService signingService)
 {
     _signingService = signingService;
 }
Beispiel #15
0
 public JwtFactory(IOptions <JwtTokenOptions> options, ISigningService signingConfiguration)
 {
     _options = options;
     _signingConfiguration = signingConfiguration;
 }
Beispiel #16
0
 public SyncConfirmedSingleModule(ILoggerService loggerService, IClientCommunicationServiceRepository clientCommunicationServiceRepository, IConfigurationService configurationService, IIdentityKeyProvidersRegistry identityKeyProvidersRegistry, ISerializersFactory signatureSupportSerializersFactory, INodesDataService nodesDataService, ISigningService cryptoService, IPerformanceCountersRepository performanceCountersRepository, IStatesRepository statesRepository, IHashCalculationsRepository hashCalculationRepository)
     : base(loggerService, clientCommunicationServiceRepository, configurationService, identityKeyProvidersRegistry, signatureSupportSerializersFactory, nodesDataService, cryptoService, performanceCountersRepository, hashCalculationRepository)
 {
     _synchronizationContext = statesRepository.GetInstance <ISynchronizationContext>();
 }