public void TestSecurityLevelLowerThanDefault()
    {
      var generator = new AddressGenerator();

      var addresses = generator.GetAddresses(this.seedOne, SecurityLevel.Low, 0, 3);
      Assert.AreEqual("KNDWDEEWWFVZLISLYRABGVWZCHZNZLNSEJXFKVGAUFLL9UMZYEZMEJB9BDLAASWTHEKFREUDIUPY9ICKW", addresses[0].Value);
      Assert.AreEqual("CHOBTRTQWTMH9GWFWGWUODRSGPOJOIVJUNIQIBZLHSWNYPHOD9APWJBMJMGLHFZENWFKDYWHX9JDFXTAB", addresses[1].Value);
      Assert.AreEqual("YHTOYQUCLDHAIDILFNPITVPYSTOCFAZIUNDYTRDZCVMVGZPONPINNVPJTOAOKHHZWLOKIZPVASTOGAKPA", addresses[2].Value);
    }
    public void TestSecurityLevelHigherThanDefault()
    {
      var generator = new AddressGenerator();

      var addresses = generator.GetAddresses(this.seedOne, SecurityLevel.High, 0, 3);
      Assert.AreEqual("BGHTGOUKKNTYFHYUAAPSRUEVN9QQXFOGVCH9Y9BONWXUBDLSKAWEOFZIVMHXBAYVPGDZEYCKNTUJCLPAX", addresses[0].Value);
      Assert.AreEqual("EGMRJEUIYFUGWAIXXZCHCZUVUUYITICVHDSHCQXGFHJIVDCLTI9ZVRIKRLZQWW9CPOIXVDCBAHVGLUHI9", addresses[1].Value);
      Assert.AreEqual("ENPSARVJZGMMPWZTAIRHADEOZCEVIFNJWSZQHNEIRVEVI9GYMFNEOGNUYCPGPSEFCSDHUHOQKDPVGDKYC", addresses[2].Value);
    }
    public void TestGetMultipleAddresses()
    {
      var generator = new AddressGenerator();

      var addresses = generator.GetAddresses(this.seedTwo, SecurityLevel.Medium, 1, 1);
      Assert.AreEqual(1, addresses.Count);

      addresses = generator.GetAddresses(this.seedTwo, SecurityLevel.Medium, 0, 3);
      Assert.AreEqual("FNKCVJPUANHNWNBAHFBTCONMCUBC9KCZ9EKREBCJAFMABCTEPLGGXDJXVGPXDCFOUCRBWFJFLEAVOEUPY", addresses[0].Value);
      Assert.IsNotNull(addresses[0].PrivateKey);
      Assert.AreEqual("MSYILYYZLSJ99TDMGQHDOBWGHTBARCBGJZE9PIMQLTEXJXKTDREGVTPA9NDGGLQHTMGISGRAKSLYPGWMB", addresses[1].Value);
      Assert.AreEqual("IIREHGHXUHARKVZDMHGUUCHZLUEQQULLEUSJHIIBWFYZIZDUFTOVHAWCKRJXUZ9CSUVLTRYSUGBVRMTOW", addresses[2].Value);
      Assert.AreEqual(3, addresses.Count);

      addresses = generator.GetAddresses(this.seedTwo, SecurityLevel.Medium, 10, 3);
      Assert.AreEqual("BPXMVV9UPKBTVPJXPBHHOJYAFLALOYCGTSEDLZBHNFMGEHREBQTRIPZAPREANPMZJNZZNCDIUFOYYGGFY", addresses[0].Value);
      Assert.AreEqual("RUCZQJWKXVDIXTLHHOKGMHOV9AKVDBG9HUQHPWNZUNKJNFVMULUSLKFJGSTBSNJMRYSJOBVBQSKVXISZB", addresses[1].Value);
      Assert.AreEqual("FQAKF9XVCLTBESJKWCHFOCTVABYEEJP9RXUVAEUWENFUUQK9VCHFEORHCYDUJQHNUDWNRDUDZTUGKHSPD", addresses[2].Value);
      Assert.AreEqual(3, addresses.Count);
    }
Esempio n. 4
0
        public async Task <User> UniquePublicKey()
        {
            var publicKeyList = await IotaHelper.GetPublicKeysAndContactAddresses(this.user.TangleMessenger, this.user.PublicKeyAddress, true);

            var requestAdressTrytes = new TryteString(this.user.NtruKeyPair.PublicKey.ToBytes().EncodeBytesAsString() + ChiotaConstants.LineBreak + this.user.RequestAddress + ChiotaConstants.End);

            // after a snapshot, upload public key again
            if (publicKeyList.Count == 0)
            {
                await this.user.TangleMessenger.SendMessageAsync(requestAdressTrytes, this.user.PublicKeyAddress);
            }
            else if (publicKeyList.Count > 1)
            {
                // more than one key at this address
                // generate a new public key address based on a changed seed until you find an unused address
                // this way the attacker doesn't know the next public key address
                List <Contact> newContacts;
                var            addresses = new List <Address> {
                    new Address(this.user.PublicKeyAddress)
                };
                do
                {
                    var newSeed          = this.user.Seed.ToString().Substring(0, 75) + addresses[0].ToString().Substring(0, 6);
                    var addressGenerator = new AddressGenerator(new Kerl(), new KeyGenerator(new Kerl(), new IssSigningHelper()));
                    addresses = await Task.Factory.StartNew(() => addressGenerator.GetAddresses(new Seed(newSeed), SecurityLevel.Medium, 0, 1));

                    // returns also null if something wrong with ntru key pair
                    newContacts = await IotaHelper.GetPublicKeysAndContactAddresses(this.user.TangleMessenger, addresses[0].ToString(), true);

                    if (newContacts == null || newContacts.Count == 0)
                    {
                        await this.user.TangleMessenger.SendMessageAsync(requestAdressTrytes, addresses[0].ToString());
                    }

                    this.user.PublicKeyAddress = addresses[0].ToString();
                }while (newContacts?.Count > 1);
            }

            return(this.user);
        }
Esempio n. 5
0
        /// <summary>
        /// The main.
        /// </summary>
        /// <param name="args">
        /// The args.
        /// </param>
        private static void Main(string[] args)
        {
            var factory    = new RestIotaRepositoryFactory();
            var repo       = factory.CreateAsync(true).Result;
            var repository = new RestIotaRepository(new RestClient("http://localhost:14265"), new PoWService(new CpuPearlDiver()));
            var acc        = repository.GetAccountData(Seed.Random(), true, SecurityLevel.Medium, 0);

            var seed             = Seed.Random();
            var addressGenerator = new AddressGenerator(new Kerl(), new KeyGenerator(new Kerl(), new IssSigningHelper()));

            var addresses = addressGenerator.GetAddresses(seed, SecurityLevel.Medium, 0, 6);
            var addressesWithSpentInformation = repository.WereAddressesSpentFrom(addresses);

            var transactionStackCounter = 10;

            for (var i = 1; i <= transactionStackCounter; i++)
            {
                var stopwatch = new Stopwatch();
                stopwatch.Start();
                var transfers = new List <Transfer>();
                for (var j = 1; j <= i; j++)
                {
                    transfers.Add(new Transfer
                    {
                        Address =
                            new Address("YTXCUUWTXIXVRQIDSECVFRTKAFOEZITGDPLWYVUVFURMNVDPIRXEIQN9JHNFNVKVJMQVMA9GDZJROTSFZHIVJOVAEC")
                        {
                            Balance = 0
                        },
                        Message   = TryteString.FromAsciiString("Hello world! With " + i + " transactions."),
                        Tag       = new Tag("CSHARP"),
                        Timestamp = Timestamp.UnixSecondsTimestamp
                    });
                }

                var bundle = new Bundle();

                transfers.ForEach(bundle.AddTransfer);

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

                var resultTransactions = repository.SendTrytes(bundle.Transactions, 27, 14);
                Console.WriteLine("Finished sending bundle with {0} transactions. Time elapsed: {1} seconds.", i, stopwatch.ElapsedMilliseconds / 1000);
            }


            var accountData = repository.GetAccountData(new Seed("SOMESEEDHERE"), true, SecurityLevel.Medium, 0);

            var latestInclusion =
                repository.GetLatestInclusion(
                    new List <Hash> {
                new Hash("HG9KCXQZGQDVTFGRHOZDZ99RMKGVRIQXEKXWXTPWYRGXQQVFVMTLQLUPJSIDONDEURVKHMBPRYGP99999")
            });

            var inputs = repository.GetInputs(new Seed("SOMESEEDHERE"), 99900000, SecurityLevel.Medium, 0);

            var newAddresses = repository.GetNewAddresses(Seed.Random(), 0, 5, SecurityLevel.Medium);

            var transactions =
                repository.FindTransactionsByAddresses(
                    new List <Address> {
                new Address("HHZSJANZQULQICZFXJHHAFJTWEITWKQYJKU9TYFA9AFJLVIYOUCFQRYTLKRGCVY9KPOCCHK99TTKQGXA9")
            });

            var tips             = repository.GetTips();
            var inclusionsStates =
                repository.GetInclusionStates(
                    new List <Hash> {
                new Hash("HG9KCXQZGQDVTFGRHOZDZ99RMKGVRIQXEKXWXTPWYRGXQQVFVMTLQLUPJSIDONDEURVKHMBPRYGP99999")
            },
                    tips.Hashes.GetRange(0, 10));

            var transactionTrytes =
                repository.GetTrytes(new List <Hash> {
                new Hash("HG9KCXQZGQDVTFGRHOZDZ99RMKGVRIQXEKXWXTPWYRGXQQVFVMTLQLUPJSIDONDEURVKHMBPRYGP99999")
            });

            var transactionData = transactionTrytes.Select(t => Transaction.FromTrytes(t)).ToList();

            var transactionsToApprove = repository.GetTransactionsToApprove();

            var balances =
                repository.GetBalances(
                    new List <Address>
            {
                new Address("GVZSJANZQULQICZFXJHHAFJTWEITWKQYJKU9TYFA9AFJLVIYOUCFQRYTLKRGCVY9KPOCCHK99TTKQGXA9"),
                new Address("HBBYKAKTILIPVUKFOTSLHGENPTXYBNKXZFQFR9VQFWNBMTQNRVOUKPVPRNBSZVVILMAFBKOTBLGLWLOHQ999999999")
            });

            var nodeInfo = repository.GetNodeInfo();

            var neighbours = repository.GetNeighbors();

            Console.WriteLine("Done");
            Console.ReadKey();
        }