public async Task <IActionResult> GetVersion(Guid versionId)
        {
            NetworkVersion version = await _networkVersionsService.GetVersionAsync(versionId);

            bool canAccess = User.Identity.IsAuthenticated
                ? await _networkService.CanAccessNetworkAsync(version.Metadata.NetworkId, User.GetId())
                : await _networkService.CanAccessNetworkAnonymouslyAsync(version.Metadata.NetworkId);

            if (!canAccess)
            {
                return(Forbid());
            }

            var model = new NetworkDiagramModel(version.Diagram);

            return(Ok(model));
        }
Exemple #2
0
        string GenerateAddress(PubKey pubKey, NetworkVersion networkVersion)
        {
            var minLength   = -1;
            var publicKey   = pubKey.Decompress();
            var pubKeyBytes = publicKey.ToBytes();

            var version    = (int)networkVersion;
            var versionHex = Convert.ToString(version, 16);

            var pubKeyHash160BytesSha256 = NBitcoin.Crypto.Hashes.SHA256(pubKeyBytes);
            var pubKeyHash160Bytes       = NBitcoin.Crypto.Hashes.RIPEMD160(pubKeyHash160BytesSha256, pubKeyHash160BytesSha256.Length);
            var pubKeyHash160Hex         = pubKeyHash160Bytes.ToHexString();

            var hash160Regex = new Regex(@"/^[0-9a-fA-F]{40}$/");

            if (hash160Regex.Match(pubKeyHash160Hex).Length > 0)
            {
                throw new ArgumentException("Invalid argument: not a hash160 hex string");
            }

            var checksumInputHex   = $"{versionHex}{pubKeyHash160Hex}";
            var checksumInputBytes = checksumInputHex.FromHexToByteArray();

            if (version < 0 || version >= 32)
            {
                throw new ArgumentOutOfRangeException("Invalid version (must be between 0 and 31)");
            }

            if (versionHex.Length == 1)
            {
                versionHex = $"0{versionHex}";
            }

            var checksumRegex = new Regex(@"/^[0-9a-fA-F]*$/");

            if (checksumRegex.Match(checksumInputHex).Length > 0)
            {
                throw new ArgumentException("Invalid data (not a hex string)");
            }

            var doubleHashedChecksumInputBytes = NBitcoin.Crypto.Hashes.SHA256(NBitcoin.Crypto.Hashes.SHA256(checksumInputBytes));
            var checksumHex = doubleHashedChecksumInputBytes[..4].ToHexString();
Exemple #3
0
        public FtpManager(string host, int port, string directory, string username, SecureString password,
                          WebProxy proxy, bool usePassiveMode, string transferAssemblyFilePath, int protcol, NetworkVersion networkVersion)
        {
            TransferAssemblyPath = transferAssemblyFilePath;
            GetTransferProvider();

            _transferProvider.Host           = host;
            _transferProvider.Port           = port;
            _transferProvider.Directory      = directory;
            _transferProvider.Username       = username;
            _transferProvider.Password       = password.Copy();
            _transferProvider.Proxy          = proxy;
            _transferProvider.UsePassiveMode = usePassiveMode;

            if (!string.IsNullOrWhiteSpace(transferAssemblyFilePath))
            {
                return;
            }
            Protocol       = (FtpsSecurityProtocol)protcol;
            NetworkVersion = networkVersion;
        }
Exemple #4
0
 public string GetAddress(NetworkVersion networkVersion = NetworkVersion.Mainnet)
 {
     return(new AddressGenerator().GenerateAddress(base.PublicKey.ToBytes(), networkVersion));
 }