예제 #1
0
        public void GenerateKeys()
        {
            WriteLine("password key:");
            var privateKey = Secp256K1Manager.GenerateRandomKey();
            var privateWif = "P" + Base58.EncodePrivateWif(privateKey);

            WriteLine(privateWif);
            WriteLine(Hex.ToString(privateKey));

            var publicKey       = Secp256K1Manager.GetPublicKey(privateKey, true);
            var encodePublicWif = Base58.EncodePublicWif(publicKey, "STM");

            WriteLine(encodePublicWif);
            WriteLine(Hex.ToString(publicKey));

            var name = "userlogin";

            string[] roles = { "posting", "active", "owner", "memo" };

            foreach (var role in roles)
            {
                WriteLine(role);
                var subWif = Base58.GetSubWif(name, privateWif, role);
                WriteLine(subWif);
                var pk = Base58.DecodePrivateWif(subWif);
                WriteLine(Hex.ToString(pk));
                var subPublicKey = Secp256K1Manager.GetPublicKey(pk, true);
                var publicWif    = Base58.EncodePublicWif(subPublicKey, "STM");
                WriteLine(publicWif);
                WriteLine(Hex.ToString(subPublicKey));
            }
        }
예제 #2
0
        public void Base58HexTest(string key, string value)
        {
            var hex  = Base58.DecodePrivateWif(key);
            var sHex = string.Join(string.Empty, hex.Select(i => i.ToString("x2")));

            Assert.Equal(sHex, value);
        }
예제 #3
0
        public void GetPublicKeyTest(string privateKey, string expectedPubKey)
        {
            var pk        = Base58.DecodePrivateWif(privateKey);
            var publicKey = Secp256K1Manager.GetPublicKey(pk, true);
            var pWif      = Base58.EncodePublicWif(publicKey, "STM");

            Assert.Equal(expectedPubKey, pWif);
        }
예제 #4
0
        protected async Task <TokenModel> AuthorizeToGolos(CancellationToken token = default(CancellationToken))
        {
            var login    = ConfigurationManager.AppSettings["GolosLogin"];
            var password = ConfigurationManager.AppSettings["GolosPostingWif"];

            var keys = new List <byte[]> {
                Base58.DecodePrivateWif(password)
            };
            var op         = new Ditch.Golos.Operations.FollowOperation(login, "steepshot", Ditch.Golos.Models.FollowType.Blog, login);
            var properties = new Ditch.Golos.Models.DynamicGlobalPropertyObject
            {
                HeadBlockId     = "0000000000000000000000000000000000000000",
                Time            = DateTime.Now,
                HeadBlockNumber = 0
            };

            var operationManager = new Ditch.Golos.OperationManager(null);

            var tr = await operationManager.CreateTransactionAsync(properties, keys, op, token).ConfigureAwait(false);

            var trx = JsonConvert.SerializeObject(tr, operationManager.JsonSerializerSettings);

            var authModel = new AuthModel
            {
                Args     = trx,
                AuthType = AuthType.Golos
            };
            HttpContent content = new StringContent(JsonConvert.SerializeObject(authModel), Encoding.UTF8, "application/json");

            var httpClient = new HttpClient();
            var response   = await httpClient.PostAsync(AuthApiUrl, content, token).ConfigureAwait(false);

            var opt = await CreateResultAsync <TokenModel>(response, token).ConfigureAwait(false);

            Assert.IsTrue(opt.IsSuccess, opt.Exception?.Message);
            Assert.IsTrue(opt.Result.Login.Equals(login));
            Assert.IsTrue(opt.Result.Type == AuthType.Golos);
            return(opt.Result);
        }