Exemplo n.º 1
0
        public string Flatten(IMicheline value)
        {
            if (value is MichelineString micheString)
            {
                return(micheString.Value);
            }
            else if (value is MichelineBytes micheBytes)
            {
                if (micheBytes.Value.Length < 22)
                {
                    return(Hex.Convert(micheBytes.Value));
                }

                byte[] prefix;
                if (micheBytes.Value[0] == 0)
                {
                    if (micheBytes.Value[1] == 0)
                    {
                        prefix = Prefix.tz1;
                    }
                    else if (micheBytes.Value[1] == 1)
                    {
                        prefix = Prefix.tz2;
                    }
                    else if (micheBytes.Value[1] == 2)
                    {
                        prefix = Prefix.tz3;
                    }
                    else
                    {
                        return(Hex.Convert(micheBytes.Value));
                    }
                }
                else if (micheBytes.Value[0] == 1)
                {
                    if (micheBytes.Value[21] == 0)
                    {
                        prefix = Prefix.KT1;
                    }
                    else
                    {
                        return(Hex.Convert(micheBytes.Value));
                    }
                }
                else
                {
                    return(Hex.Convert(micheBytes.Value));
                }

                var bytes = micheBytes.Value[0] == 0
                    ? micheBytes.Value.GetBytes(2, 20)
                    : micheBytes.Value.GetBytes(1, 20);

                var address    = Base58.Convert(bytes, prefix);
                var entrypoint = micheBytes.Value.Length > 22
                    ? Utf8.Convert(micheBytes.Value.GetBytes(22, micheBytes.Value.Length - 22))
                    : string.Empty;

                return(entrypoint.Length == 0 ? address : $"{address}%{entrypoint}");
            }
            else
            {
                throw FormatException(value);
            }
        }
Exemplo n.º 2
0
        public void Base58Hashing()
        {
            var result = Base58.Encode(Encoding.UTF8.GetBytes("*****@*****.**"));

            Assert.Equal("2rjpGWoxbc8ASyDVx", result);
        }
Exemplo n.º 3
0
 public PublicKeyType(string value)
 {
     Data = Base58.DecodePublicWif(value, Prefix);
 }
Exemplo n.º 4
0
        /// <summary>
        /// Returns true if the passed bitcoin address is valid.
        /// </summary>
        /// <param name="Address">The bitcoin address.</param>
        /// <returns>
        ///   <c>true</c> if the specified address is valid; otherwise, <c>false</c>.
        /// </returns>
        internal static bool IsValid(string Address)
        {
            //
            // Check if the length of the address is between 26 and 35 characters.
            //

            if (Address.Length < 26 || Address.Length > 35)
            {
                return(false);
            }

            //
            // Check if the address only contains alpha-numeric characters.
            //

            if (!Address.All("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".Contains))
            {
                return(false);
            }

            //
            // Decode the address using Base58.
            //

            var DecodedAddress = Base58.ToByteArray(Address);

            if (DecodedAddress == null ||
                DecodedAddress.Length < 4)
            {
                return(false);
            }

            //
            // Parse the address without its ending checksum.
            //

            var LengthWithoutChecksum = DecodedAddress.Length - 4;
            var BytesWithoutChecksum  = new byte[LengthWithoutChecksum];

            Array.Copy(DecodedAddress, BytesWithoutChecksum, LengthWithoutChecksum);

            //
            // Calculate the checksum ourselves.
            //

            var ChecksumCalculator = new Sha256Digest();

            ChecksumCalculator.BlockUpdate(BytesWithoutChecksum, 0, BytesWithoutChecksum.Length);
            var Checksum = new byte[32];

            ChecksumCalculator.DoFinal(Checksum, 0);
            ChecksumCalculator.BlockUpdate(Checksum, 0, Checksum.Length);
            ChecksumCalculator.DoFinal(Checksum, 0);

            //
            // Compare the checksum we've calculated ourselves with the one
            // we parsed at the end of the address we've been given.
            //

            if (Checksum[0] != DecodedAddress[LengthWithoutChecksum] ||
                Checksum[1] != DecodedAddress[LengthWithoutChecksum + 1] ||
                Checksum[2] != DecodedAddress[LengthWithoutChecksum + 2] ||
                Checksum[3] != DecodedAddress[LengthWithoutChecksum + 3])
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 5
0
 public string GetPrivateKey(string words)
 {
     return(Base58.Encode(Encoding.UTF8.GetBytes(words)));
 }
Exemplo n.º 6
0
 public void TestEncode()
 {
     Base58.Encode(decoded1).Should().Be(encoded1);
 }
Exemplo n.º 7
0
    public List <Players> GetPlayers(string address, int height)
    {
        List <Players> playersList = new List <Players>();
        var            node        = new Node(Node.MainNetHost);

        Dictionary <string, object>[] enemies = node.GetTransactionsByAddress(AddressInfo.recipient[0], 1000);
        for (int j = 0; j < enemies.Length; j++)
        {
            bool correctTx = int.Parse(enemies[j].GetValue("type").ToString()) == 4 &&
                             enemies[j].GetValue("assetId") != null &&
                             enemies[j].GetValue("assetId").ToString() == AddressInfo.Asset &&
                             int.Parse(enemies[j].GetValue("amount").ToString()) >= 100000000 &&
                             !string.IsNullOrEmpty(enemies[j].GetValue("attachment").ToString()) &&
                             int.Parse(enemies[j].GetValue("height").ToString()) <= height;

            if (correctTx && enemies[j].GetValue("sender").ToString() != address)
            {
                string enemy    = enemies[j].GetValue("sender").ToString();
                bool   equalStr = false;
                for (int k = 0; k < playersList.Count; k++)
                {
                    if (enemy == playersList[k].Address)
                    {
                        equalStr = true;
                        //has prev skills
                    }
                }
                if (!equalStr)
                {
                    string DecodedAttachment = AttachmentBase58.Base58NumericDecode(Encoding.UTF8.GetString(Base58.Decode(enemies[j].GetValue("attachment").ToString())));

                    string[] info = new string[3];
                    info = DecodedAttachment.Split('A');
                    if (string.IsNullOrEmpty(info[0]))
                    {
                        info[0] = "0";
                    }
                    int[] skillsEnemies = new int[3];
                    try
                    {
                        if (int.TryParse(info[0], out skillsEnemies[0]) &&
                            int.TryParse(info[1], out skillsEnemies[1]) &&
                            int.TryParse(info[2], out skillsEnemies[2]) &&
                            skillsEnemies[0] >= 0 && skillsEnemies[0] < FindObjectOfType <Skills>().skills.Count&&
                            skillsEnemies[1] >= 0 && skillsEnemies[1] < FindObjectOfType <Skills>().skills.Count&&
                            skillsEnemies[2] >= 0 && skillsEnemies[2] < FindObjectOfType <Skills>().skills.Count)
                        {
                            playersList.Add(new Players(enemies[j].GetValue("sender").ToString(), skillsEnemies));
                        }
                    }
                    catch
                    {
                        continue;
                    }
                }
            }
        }
        return(playersList);
    }
Exemplo n.º 8
0
 public string ComputeBitsharesPubKey()
 {
     return(kAddressPrefix + Base58.FromByteArray(ComputeBitsharesPubKeyBytes()));
 }
Exemplo n.º 9
0
 /// <summary>	Calculates the bitshares address from bitcoin public key </summary>
 ///
 /// <remarks>	Paul, 08/12/2014. </remarks>
 ///
 /// <param name="compressedBtcPubKey">	The compressed btc pub key. </param>
 /// <param name="ripe">				    The ripe. </param>
 ///
 /// <returns>	The calculated bitshares address. </returns>
 static public string ComputeBitsharesAddress(byte[] compressedBtcPubKey, RIPEMD160 ripe)
 {
     return(kAddressPrefix + Base58.FromByteArray(ComputeBitsharesAddressFromBtcPubKey(compressedBtcPubKey, ripe)));
 }
Exemplo n.º 10
0
        public void WriteJson(JsonWriter writer, JsonSerializer serializer)
        {
            var wif = Base58.EncodePublicWif(Data, Prefix);

            writer.WriteValue(wif);
        }
Exemplo n.º 11
0
 public static string ToAddress(UInt160 scriptHash)
 {
     byte[] data = new byte[] { CoinVersion }.Concat(scriptHash.ToArray()).ToArray();
     return(Base58.Encode(data.Concat(data.Sha256().Sha256().Take(4)).ToArray()));
 }
Exemplo n.º 12
0
        private void btnArchive_Click(object sender, EventArgs e)
        {
            DialogResult prompt = MessageBox.Show("You are about to permanently etch a profile onto " + Main.CoinType + "." + Environment.NewLine + "            !!! Apertus may lock up during this process !!!" + Environment.NewLine + "       Please be patient.  We will thread it better next time.", "Confirmation", MessageBoxButtons.YesNoCancel);

            if (prompt == DialogResult.Yes)
            {
                Main.ProfileID    = "";
                Main.ProfileLabel = "";
                var    mainForm      = Application.OpenForms.OfType <Main>().Single();
                string tempSignature = Main.SignatureLabel;
                Main.SignatureLabel = "~~" + cmbProfileAddress.Text;
                Match  match            = Regex.Match(openFileDialog1.FileName, @"([a-fA-F0-9]{64})");
                string profileImagePath = "";
                if (openFileDialog1.FileName != "openFileDialog1" && !match.Success)

                {
                    mainForm.PerformArchive(Main.CoinType, openFileDialog1.FileName, "");
                    var b            = new CoinRPC(new Uri(GetURL(Main.coinIP[Main.CoinType]) + ":" + Main.coinPort[Main.CoinType]), new NetworkCredential(Main.coinUser[Main.CoinType], Main.coinPassword[Main.CoinType]));
                    var transactions = b.ListTransactions("~~~~" + cmbProfileAddress.Text, 100, 0);

                    foreach (var transaction in transactions.Reverse())
                    {
                        if (transaction.category == "receive")
                        {
                            if (mainForm.CreateArchive(transaction.txid, Main.CoinType, false, true, null, null, false))
                            {
                                if (System.IO.File.Exists("root//" + transaction.txid + "//" + Path.GetFileName(openFileDialog1.FileName)))
                                {
                                    profileImagePath = "../" + transaction.txid + "/" + Path.GetFileName(openFileDialog1.FileName);
                                    break;
                                }
                            }
                        }
                    }
                }

                if (match.Success)
                {
                    profileImagePath = "../" + match.Value + "/" + Path.GetFileName(openFileDialog1.FileName);
                }


                String processId = Guid.NewGuid().ToString();
                System.IO.Directory.CreateDirectory("process//" + processId);
                System.IO.StreamWriter proFile = new System.IO.StreamWriter("process//" + processId + "//PRO");
                proFile.WriteLine("IMG=" + profileImagePath);
                proFile.WriteLine("NIK=" + txtNickName.Text);
                proFile.WriteLine("PRE=" + txtPrefix.Text);
                proFile.WriteLine("FNM=" + txtFirstName.Text);
                proFile.WriteLine("MNM=" + txtMiddleName.Text);
                proFile.WriteLine("LNM=" + txtLastName.Text);
                proFile.WriteLine("SUF=" + txtSuffix.Text);
                proFile.WriteLine("AD1=" + txtAddress1.Text);
                proFile.WriteLine("AD2=" + txtAddress2.Text);
                proFile.WriteLine("AD3=" + txtAddress3.Text);
                CoinRPC a = new CoinRPC(new Uri(GetURL(Main.coinIP[Main.CoinType]) + ":" + Main.coinPort[Main.CoinType]), new NetworkCredential(Main.coinUser[Main.CoinType], Main.coinPassword[Main.CoinType]));
                IEnumerable <string> Address = null;
                if (cmbTipAddress.SelectedIndex > 0)
                {
                    Address = a.GetAddressesByAccount("~~~~~" + cmbTipAddress.Text);
                    proFile.WriteLine("TIP=" + Address.First());
                }
                Address = a.GetAddressesByAccount("~~~~" + cmbProfileAddress.Text);
                var privKeyHex = BitConverter.ToString(Base58.Decode(a.DumpPrivateKey(Address.First()))).Replace("-", "");
                privKeyHex = privKeyHex.Substring(2, 64);
                BigInteger privateKey = Hex.HexToBigInteger(privKeyHex);
                ECPoint    publicKey  = Secp256k1.Secp256k1.G.Multiply(privateKey);

                proFile.WriteLine("MSG=" + Address.First());
                proFile.WriteLine("PKX=" + publicKey.X.ToHex());
                proFile.WriteLine("PKY=" + publicKey.Y.ToHex());
                proFile.Close();

                mainForm.PerformArchive(Main.CoinType, Application.StartupPath + "//process//" + processId + "//PRO", "");
                Main.SignatureLabel = tempSignature;
                BuildSelectedProfile();
                Main.ProfileID    = txtTransID.Text;
                Main.ProfileLabel = cmbProfileAddress.Text;
                mainForm.AddProfile(cmbProfileAddress.Text);
            }
        }
Exemplo n.º 13
0
 public string ToBase58() => Base58.Convert(Bytes, Prefix);
Exemplo n.º 14
0
 public static string HashProto(IMessage message)
 {
     return(Base58.Encode(Sha256Hash(message.ToByteArray())));
 }
Exemplo n.º 15
0
 public static Network NetworkFromPrefix(byte prefix)
 {
     return(NetworkFromPrefix(Base58.Encode(new byte[] { prefix })[0]));
 }
 public static string Encode(string text)
 => Base58.EncodePlain(Encoding.UTF8.GetBytes(text));
Exemplo n.º 17
0
 public Base58Sevice(Report rep) : base(rep)
 {
     inputService = new InputService();
     encoder      = new Base58();
     sha          = new Sha256(true);
 }
 public static string Decode(string base64Text)
 => Encoding.UTF8.GetString(Base58.DecodePlain(base64Text));
Exemplo n.º 19
0
    public SkillsPlayer AddressSkills(string address, int height)
    {
        SkillsPlayer skills = new SkillsPlayer();
        var          node   = new Node(Node.MainNetHost);

        Dictionary <string, object>[] player = node.GetTransactionsByAddress(AddressInfo.recipient[0], 1000);
        for (int j = 0; j < player.Length; j++)
        {
            bool correctTx = int.Parse(player[j].GetValue("type").ToString()) == 4 &&
                             player[j].GetValue("assetId") != null &&
                             player[j].GetValue("assetId").ToString() == AddressInfo.Asset &&
                             int.Parse(player[j].GetValue("amount").ToString()) >= 100000000 &&
                             !string.IsNullOrEmpty(player[j].GetValue("attachment").ToString()) &&
                             int.Parse(player[j].GetValue("height").ToString()) <= height;

            if (correctTx && player[j].GetValue("sender").ToString() == address)
            {
                string DecodedAttachment = AttachmentBase58.Base58NumericDecode(Encoding.UTF8.GetString(Base58.Decode(player[j].GetValue("attachment").ToString())));

                string[] info = new string[3];
                info = DecodedAttachment.Split('A');
                if (string.IsNullOrEmpty(info[0]))
                {
                    info[0] = "0";
                }
                int[] skillsArr = new int[3];
                try
                {
                    if (int.TryParse(info[0], out skillsArr[0]) &&
                        int.TryParse(info[1], out skillsArr[1]) &&
                        int.TryParse(info[2], out skillsArr[2]) &&
                        skillsArr[0] >= 0 && skillsArr[0] < FindObjectOfType <Skills>().skills.Count&&
                        skillsArr[1] >= 0 && skillsArr[1] < FindObjectOfType <Skills>().skills.Count&&
                        skillsArr[2] >= 0 && skillsArr[2] < FindObjectOfType <Skills>().skills.Count)
                    {
                        if (skills.Height == -1)
                        {
                            skills = new SkillsPlayer(skillsArr, int.Parse(player[j].GetValue("height").ToString()));
                        }
                        else
                        {
                            skills.SetPrevSkills(true, int.Parse(player[j].GetValue("height").ToString()));
                            return(skills);
                        }
                    }
                }
                catch
                {
                    continue;
                }
            }
        }

        return(skills);
    }
 public static PublicKey ParseBase58(string base58String)
 {
     return(new PublicKey(Base58.Decode(base58String)));
 }
Exemplo n.º 21
0
 public static string ToAddress(UInt160 scriptHash)
 {
     byte[] data = new byte[] { AddressVersion }.Concat(scriptHash.ToArray()).ToArray();
     return(Base58.Encode(data.Concat(Crypto.Default.Hash256(data).Take(4)).ToArray()));
 }
Exemplo n.º 22
0
 private static byte[] Base58CheckDecode(this string input)
 {
   byte[] buffer = Base58.Decode(input);
   if (buffer.Length \\ 0 ? b[b.Length - 1] : 255 - b[b.Length - 1]);
 }
Exemplo n.º 23
0
 public string GetWallet(string privateKey)
 {
     return(Encoding.UTF8.GetString(Base58.Decode(privateKey)));
 }
 public static ContainerID FromString(string id)
 {
     return(FromValue(Base58.Decode(id)));
 }
Exemplo n.º 25
0
 public void TestInvalidAddress()
 {
     Assert.Throws <AddressFormatException>(() => Base58.Decode("This isn't valid base58"));
 }
 public string String()
 {
     return(Base58.Encode(Value.ToByteArray()));
 }
Exemplo n.º 27
0
 public string base58Encode()
 {
     return(Base58.encode(value));
 }
Exemplo n.º 28
0
 public static byte BytePrefixForNetwork(Network network)
 {
     return(Base58.Decode(PrefixForNetwork(network).ToString())[0]);
 }
Exemplo n.º 29
0
        public void ReadJson(JsonReader reader, JsonSerializer serializer)
        {
            var value = reader.Value.ToString();

            Data = Base58.DecodePublicWif(value, Prefix);
        }
Exemplo n.º 30
0
        static async Task ObjectHead(ObjectHeadOptions opts)
        {
            byte[] cid;

            var key = privateKey.FromHex().LoadKey();

            try
            {
                cid = Base58.Decode(opts.CID);
            }
            catch (Exception err)
            {
                Console.WriteLine("wrong cid format: {0}", err.Message);
                return;
            }

            var channel = new Channel(opts.Host, ChannelCredentials.Insecure);

            channel.UsedHost().GetHealth(SingleForwardedTTL, key, opts.Debug).Say();

            var req = new HeadRequest
            {
                FullHeaders = opts.Full,
                Address     = new NeoFS.API.Refs.Address
                {
                    CID      = ByteString.CopyFrom(cid),
                    ObjectID = ByteString.CopyFrom(opts.OID.Bytes()),
                },
            };

            req.SetTTL(SingleForwardedTTL);
            req.SignHeader(key, opts.Debug);

            var res = new Service.ServiceClient(channel).Head(req);

            Console.WriteLine();

            Console.WriteLine("Received object headers");
            Console.WriteLine("\nSystemHeaders\n" +
                              "Version: {0}\n" +
                              "PayloadLength: {1}\n" +
                              "ObjectID: {2}\n" +
                              "OwnerID: {3}\n" +
                              "CID: {4}\n" +
                              "CreatedAt: {5}\n",
                              res.Object.SystemHeader.Version,
                              res.Object.SystemHeader.PayloadLength,
                              res.Object.SystemHeader.ID.ToUUID(),
                              res.Object.SystemHeader.OwnerID.ToAddress(),
                              res.Object.SystemHeader.CID.ToCID(),
                              res.Object.SystemHeader.CreatedAt);

            if (opts.Full)
            {
                Console.WriteLine("Headers:");
                for (var i = 0; i < res.Object.Headers.Count; i++)
                {
                    Console.WriteLine(res.Object.Headers[i]);
                }
                Console.WriteLine();
            }

            Console.WriteLine("Meta:\n{0}", res.Meta);
            await Task.Delay(TimeSpan.FromMilliseconds(100));
        }