Esempio n. 1
0
        public void TestSignatureVerificationShouldFail()
        {
            var seed      = Ed25519Seed.FromMnemonic("witch collapse practice feed shame open despair creek road again ice least");
            var signature = Ed25519.Sign("Sign this!".Utf8ToBytes(), seed);

            Assert.IsFalse(Ed25519.Verify("Something".Utf8ToBytes(), signature));
        }
Esempio n. 2
0
        public void TestKeyPairGeneration()
        {
            var seed = Ed25519Seed.FromMnemonic("witch collapse practice feed shame open despair creek road again ice least");

            var expectedPrivateKey = new byte[]
            {
                205, 207, 133, 190, 162, 105, 181, 176, 78, 164, 207,
                31, 198, 111, 187, 209, 191, 233, 158, 80, 14, 240,
                49, 109, 253, 90, 174, 183, 55, 155, 94, 31, 47,
                105, 159, 170, 174, 177, 49, 97, 153, 60, 98, 162,
                162, 163, 90, 84, 146, 55, 23, 96, 1, 4, 119,
                221, 38, 180, 84, 149, 189, 66, 197, 72
            };

            var expectedPublicKey = new byte[]
            {
                47, 105, 159, 170, 174, 177, 49, 97,
                153, 60, 98, 162, 162, 163, 90, 84,
                146, 55, 23, 96, 1, 4, 119, 221,
                38, 180, 84, 149, 189, 66, 197, 72
            };

            CollectionAssert.AreEqual(expectedPublicKey, seed.KeyPair.PublicKey);
            CollectionAssert.AreEqual(expectedPrivateKey, seed.KeyPair.PrivateKey);
        }
Esempio n. 3
0
        public void TestSignatureVerificationShouldSucceed()
        {
            var seed      = Ed25519Seed.FromMnemonic("witch collapse practice feed shame open despair creek road again ice least");
            var payload   = "Sign this!".Utf8ToBytes();
            var signature = Ed25519.Sign(payload, seed);

            Assert.IsTrue(Ed25519.Verify(payload, signature));
        }
Esempio n. 4
0
 public SendTransferRequest(Ed25519Seed seed, TransferOutput output, int accountIndex = 0,
                            AddressOptions addressOptions = null,
                            string indexationKey          = "", string data = "") : this(seed, new List <TransferOutput> {
     output
 }, accountIndex,
                                                                                         addressOptions, indexationKey, data)
 {
 }
        public void TestAddressGenerationFromPublicKey()
        {
            var expected = "0bebd6f0febfaf32b4c77eae6755b1d83478dcc9185c33c318d4b0a24ba54d68";

            var seed    = Ed25519Seed.FromMnemonic("witch collapse practice feed shame open despair creek road again ice least");
            var address = Ed25519Address.FromPublicKey(seed.KeyPair.PublicKey);

            Assert.AreEqual(expected, address.Address);
        }
Esempio n. 6
0
 public SendTransferRequest(Ed25519Seed seed, List <TransferOutput> outputs, int accountIndex = 0,
                            AddressOptions addressOptions = null,
                            string indexationKey          = "", string data = "") : base(indexationKey, data)
 {
     Seed           = seed;
     AccountIndex   = accountIndex;
     Outputs        = outputs;
     AddressOptions = addressOptions ?? new AddressOptions();
 }
Esempio n. 7
0
        public void TestSigantureGeneration()
        {
            var expected =
                "0acae5d099c82549ead3989cd49b671a72b33118150d00bb699ce31238b548c862d06e675243cbc4195a8239ef593530733142961ac08620c0d8855758581908";

            var seed   = Ed25519Seed.FromMnemonic("witch collapse practice feed shame open despair creek road again ice least");
            var actual = Ed25519.Sign("Sign this!".Utf8ToBytes(), seed);

            Assert.AreEqual(expected, actual.Signature);
        }
Esempio n. 8
0
 public SendTransferRequest(Ed25519Seed seed, string receiverBech32Address, long amount, string indexationKey,
                            string data) : base(indexationKey, data)
 {
     Seed         = seed;
     AccountIndex = 0;
     Outputs      = new List <TransferOutput>
     {
         new TransferOutput(new Bech32Address(receiverBech32Address), amount)
     };
     AddressOptions = new AddressOptions();
 }
Esempio n. 9
0
        public void TestSubseedGenerationFromPath()
        {
            var seed = Ed25519Seed.FromMnemonic("witch collapse practice feed shame open despair creek road again ice least");
            var path = Bip44AddressGenerator.GenerateAddress(1, 1, false);

            var subseed = seed.GenerateSeedFromPath(path);

            var expectedSeed = "56b7b7c582f3ebdfbe904ead6b3455a2a4595029a39126e6c2ebbadd98702ecd";

            Assert.AreEqual(expectedSeed, subseed.SecretKey.ToHex());
        }
Esempio n. 10
0
        public static Ed25519Signature Sign(byte[] payload, Ed25519Seed seed)
        {
            var ed25519 = new Rebex.Security.Cryptography.Ed25519();

            ed25519.FromSeed(seed.SecretKey.Take(32).ToArray());

            var signature = ed25519.SignMessage(payload);

            return(new Ed25519Signature
            {
                PublicKey = seed.KeyPair.PublicKey.ToHex(),
                Signature = signature.ToHex()
            });
        }
Esempio n. 11
0
        public void TestSeedGenerationFromMnemonic()
        {
            var seed = Ed25519Seed.FromMnemonic("witch collapse practice feed shame open despair creek road again ice least");

            var expected = new byte[]
            {
                205, 207, 133, 190, 162, 105, 181, 176, 78, 164, 207,
                31, 198, 111, 187, 209, 191, 233, 158, 80, 14, 240,
                49, 109, 253, 90, 174, 183, 55, 155, 94, 31, 189,
                176, 2, 220, 158, 61, 232, 126, 203, 212, 88, 48,
                65, 112, 11, 98, 103, 147, 73, 39, 18, 250, 159,
                171, 177, 193, 124, 98, 165, 226, 151, 173
            };

            CollectionAssert.AreEqual(expected, seed.SecretKey);
        }
        public async void Execute()
        {
            // sending data is a high level operation. construct high level client and input the node client
            // (node client can be constructed with a custom URI if needed - default is https://chrysalis-nodes.iota.org)
            var client = new HighLevelClient(new NodeRestClient());

            // the transfer request can be build in multiple ways
            // in any case it needs the seed to get the funds from
            // the receiver can either be input as a bech32 or ed25519 address
            // the bech32 type is the one displayed in Firefly
            // IMPORTANT: Due to dust protection, the network only allows transactions with a value of 1 Mi or more!
            var request = new SendTransferRequest(Ed25519Seed.FromMnemonic("some mnemonic"),
                                                  "iota1qqh6pxkg4huzv506623l6lrt4daraktak6rvxwsvtewakj89vy7mj4enzsp", 1000000);

            //send request
            var response = await client.SendTransferAsync(request);

            // the response contains the id of the message | needed to later retrieve the message again
            Console.WriteLine(response.MessageId);
        }
Esempio n. 13
0
        private static async Task HighLevelOperations(NodeRestClient client)
        {
            var highLevelClient = new HighLevelClient(client);

            Console.WriteLine("Sending Transfer -----------------------");
            var seed = Ed25519Seed.FromMnemonic("");
            var sendTransferResponse = await highLevelClient.SendTransferAsync(new SendTransferRequest(seed, "iota1qqh6pxkg4huzv506623l6lrt4daraktak6rvxwsvtewakj89vy7mj4enzsp", 1000000, "Tangle .Net", "Test"));

            Console.WriteLine(JsonConvert.SerializeObject(sendTransferResponse, Formatting.Indented));
            Console.WriteLine("---------------------------------------");

            Console.WriteLine("Sending High Level Data -----------------------");
            var sendDataResponse = await highLevelClient.SendDataAsync(new SendDataRequest("Tangle .Net", "High Level Data"));

            Console.WriteLine(JsonConvert.SerializeObject(sendDataResponse, Formatting.Indented));
            Console.WriteLine("---------------------------------------");

            Console.WriteLine("Retrieving High Level Data -----------------------");
            var retrieveDataResponse = await highLevelClient.RetrieveDataAsync(new MessageRequest(sendDataResponse.MessageId));

            Console.WriteLine(JsonConvert.SerializeObject(retrieveDataResponse, Formatting.Indented));
            Console.WriteLine("---------------------------------------");
        }
Esempio n. 14
0
        private async Task <Dictionary <UTXOInput, Ed25519Seed> > CalculateInputsAsync(Ed25519Seed seed, List <TransferOutput> outputs, int zeroCount, int accountIndex, int startIndex)
        {
            var state = new InMemoryBip44GeneratorState
            {
                AccountIndex = accountIndex,
                AddressIndex = startIndex,
                IsInternal   = false
            };

            var inputs           = new Dictionary <UTXOInput, Ed25519Seed>();
            var consumedBalance  = 0L;
            var isFirst          = true;
            var zeroBalanceCount = 0;
            var requiredBalance  = outputs.Sum(o => o.Amount);

            var foundAll = false;

            do
            {
                var bip32Path = Bip44AddressGenerator.GenerateAddress(state, isFirst);
                isFirst = false;

                var addressSeed = seed.GenerateSeedFromPath(bip32Path);
                var address     = Ed25519Address.FromPublicKey(addressSeed.KeyPair.PublicKey);

                var addressOutputs = await this.Client.GetOutputsFromEd25519Async(address.Address);

                if (addressOutputs.Count == 0)
                {
                    zeroBalanceCount++;
                    if (zeroBalanceCount >= zeroCount)
                    {
                        foundAll = true;
                    }
                }
                else
                {
                    foreach (var outputId in addressOutputs.OutputIds)
                    {
                        var addressOutput = await this.Client.FindOutputByIdAsync(outputId);

                        if (!addressOutput.IsSpent &&
                            consumedBalance < requiredBalance)
                        {
                            if (addressOutput.Output.Amount == 0)
                            {
                                zeroBalanceCount++;
                                if (zeroBalanceCount >= zeroCount)
                                {
                                    foundAll = true;
                                }
                            }
                            else
                            {
                                consumedBalance += addressOutput.Output.Amount;

                                inputs.Add(
                                    new UTXOInput
                                {
                                    TransactionId = addressOutput.TransactionId, TransactionOutputIndex = addressOutput.OutputIndex
                                },
                                    addressSeed);

                                if (consumedBalance < requiredBalance)
                                {
                                    continue;
                                }

                                if (consumedBalance - requiredBalance > 0)
                                {
                                    outputs.Add(new TransferOutput(addressOutput.Output.Address, consumedBalance - requiredBalance));
                                }

                                foundAll = true;
                            }
                        }
                    }
                }
            } while (!foundAll);

            return(inputs);
        }
Esempio n. 15
0
 public GetUnspentAddressesRequest(Ed25519Seed seed, int accountIndex = 0, AddressOptions addressOptions = null)
 {
     Seed           = seed;
     AccountIndex   = accountIndex;
     AddressOptions = addressOptions ?? new AddressOptions();
 }
Esempio n. 16
0
 public SendTransferRequest(Ed25519Seed seed, Ed25519Address receiver, long amount) : this(seed,
                                                                                           new TransferOutput(receiver, amount))
 {
 }
Esempio n. 17
0
 public SendTransferRequest(Ed25519Seed seed, string receiverBech32Address, long amount) : this(seed,
                                                                                                receiverBech32Address, amount, "", "")
 {
 }