public void Sha256Test()
        {
            var sw1 = new Stopwatch();
            var sw2 = new Stopwatch();

            var rand = new Random();
            for (int i = 0; i < 10000; i++)
            {
                var buf = new byte[rand.Next(1, 1000)];
                rand.NextBytes(buf);

                sw1.Start();
                var rez2 = Proxy.GetMessageHash(buf);
                sw1.Stop();

                sw2.Start();
                var rez1 = Secp256k1Manager.GetMessageHash(buf);
                sw2.Stop();

                Assert.IsTrue(rez1.Length == rez2.Length);
                for (var j = 0; j < rez1.Length; j++)
                {
                    Assert.IsTrue(rez1[j].Equals(rez2[j]), $"{buf.Length}");
                }
            }

            Console.WriteLine($"Proxy time {sw1.ElapsedTicks} / Secp256k1Manager time {sw2.ElapsedTicks}");
        }
示例#2
0
        public byte[] Sign(byte[] privateKey, IEnumerable <byte[]> data)
        {
            var dataHash  = HashBytes(data);
            var signature = Secp256k1Manager.SignCompressedCompact(dataHash, privateKey);
            var r         = signature.Skip(1).Take(32).ToArray();
            var s         = signature.Skip(33).Take(32).ToArray();
            var sig       = r.Concat(s).ToArray();

            return(sig);
        }
        private static void Callback(object state)
        {
            var ts = GetReconectToken();

            TryRunTask(TryСonect, ts);
            // static constructor initialization.
            var init = new Secp256k1Manager();

            UpdateLocalizationAsync();
            LazyLoadTimer.Dispose();
        }
        public void SignCompressedCompactTest()
        {
            var sw1 = new Stopwatch();
            var sw2 = new Stopwatch();
            var rand = new Random();
            byte[] msg;
            for (int i = 1; i < 1000; i++)
            {
                msg = new byte[i];
                rand.NextBytes(msg);
                var hex = Base58.GetBytes(TestWif);

                var hash = Secp256k1Manager.GetMessageHash(msg);

                sw1.Start();
                var signature1 = Proxy.SignCompressedCompact(hash, hex);
                sw1.Stop();

                sw2.Start();
                var signature2 = Secp256k1Manager.SignCompressedCompact(hash, hex);
                sw2.Stop();

                Assert.IsTrue(signature1.Length == 65);
                Assert.IsTrue(signature2.Length == 65);
                Assert.IsTrue(Secp256k1Manager.IsCanonical(signature2, 1));
                if (Secp256k1Manager.IsCanonical(signature1, 1))
                {
                    for (int j = 0; j < signature1.Length; j++)
                    {
                        Assert.IsTrue(signature1[j] == signature2[j]);
                    }
                }
                else
                {
                    Console.WriteLine($"signature1 not canonical - skip [{i}]");
                }
            }

            Console.WriteLine($"Proxy time {sw1.ElapsedTicks} / Secp256k1Manager time {sw2.ElapsedTicks}");
        }
示例#5
0
        public Transaction CreateTransaction(DynamicGlobalPropertyApiObj propertyApiObj, IEnumerable <byte[]> userPrivateKeys, params BaseOperation[] operations)
        {
            var transaction = new Transaction
            {
                ChainId        = _chainId,
                RefBlockNum    = (ushort)(propertyApiObj.HeadBlockNumber & 0xffff),
                RefBlockPrefix = (uint)BitConverter.ToInt32(Hex.HexToBytes(propertyApiObj.HeadBlockId), 4),
                Expiration     = propertyApiObj.Time.AddSeconds(30),
                BaseOperations = operations
            };

            var msg  = SerializeHelper.TransactionToMessage(transaction);
            var data = Secp256k1Manager.GetMessageHash(msg);

            foreach (var userPrivateKey in userPrivateKeys)
            {
                var sig = Secp256k1Manager.SignCompressedCompact(data, userPrivateKey);
                transaction.Signatures.Add(sig);
            }

            return(transaction);
        }
        static BasePresenter()
        {
            CultureInfo = CultureInfo.InvariantCulture;
            User        = new User();
            User.Load();
            Chain = User.Chain;
            //TODO:KOA: endpoint for CurencyConvertation needed
            CurencyConvertationDic = new Dictionary <string, double> {
                { "GBG", 2.4645 }, { "SBD", 1 }
            };

            Api = new SteepshotApiClient();

            var ts = GetReconectToken();

            Api.InitConnector(Chain, AppSettings.IsDev, ts);
            TryRunTask(TryСonect, ts);
            // static constructor initialization.
            Task.Run(() =>
            {
                var init = new Secp256k1Manager();
            });
        }
示例#7
0
 /// <summary>
 /// Creates a new <see cref="Signer"/> and generates a <see cref="PrivateKey"/> and a <see cref="PublicKey"/>.
 /// </summary>
 public Signer()
 {
     PrivateKey = Secp256k1Manager.GenerateRandomKey();
     PublicKey  = _algorithm.GetPublicKey(PrivateKey);
 }