Beispiel #1
0
        static List <string> getAddress(string input)
        {
            List <string> result = new List <string>();

            Console.WriteLine($"输入了助记词{input}");
            SHA256 sha256 = new SHA256Managed();

            {
                byte[] hash = sha256.ComputeHash(Encoding.UTF8.GetBytes(input));
                // var privateKey = HexToBigInteger.inputHex("e8d96a53e9c597e5a1e2ceaddd0b5ebe75588b26e71846b46a9b5f3666409355");

                //var inputSting = "e8d96a53e9c597e5a1e2ceaddd0b5ebe75588b26e71846b46a9b5f3666409355";
                //var inputSting = ;
                var privateKey = Bytes32.ConvetToBigInteger(hash);
                privateKey = privateKey % Secp256k1.q;
                var privateByte = hash;

                {
                    var resultAdd = Calculate.BiteSplitJoint(new byte[] { 0x80 }, privateByte);
                    resultAdd = Calculate.BiteSplitJoint(resultAdd, new byte[] { 0x01 });
                    byte[] chechHash = Calculate.GetCheckSum(resultAdd);
                    resultAdd = Calculate.BiteSplitJoint(resultAdd, chechHash);
                    var privateKey1 = Calculate.Encode(resultAdd);
                    Console.WriteLine($"您压缩后的私钥为{privateKey1}");
                }
                {
                    var    resultAdd = Calculate.BiteSplitJoint(new byte[] { 0x80 }, privateByte);
                    byte[] chechHash = Calculate.GetCheckSum(resultAdd);
                    resultAdd = Calculate.BiteSplitJoint(resultAdd, chechHash);
                    var privateKey1 = Calculate.Encode(resultAdd);
                    Console.WriteLine($"您压缩前的私钥为{privateKey1}");
                }
                var publicKey = Calculate.getPublicByPrivate(privateKey);
                if (publicKey != null)
                {
                    var walletOfcompressed = PublicKeyF.GetAddressOfcompressed(publicKey);
                    Console.WriteLine($"压缩钱包地址为:{walletOfcompressed}");
                    var walletOfUncompressed = PublicKeyF.GetAddressOfUncompressed(publicKey);
                    Console.WriteLine($"非压缩钱包地址为:{walletOfUncompressed}");
                    result.Add(walletOfcompressed);
                    result.Add(walletOfUncompressed);
                }
            }

            {
                byte[] hash = sha256.ComputeHash(sha256.ComputeHash(Encoding.UTF8.GetBytes(input)));
                // var privateKey = HexToBigInteger.inputHex("e8d96a53e9c597e5a1e2ceaddd0b5ebe75588b26e71846b46a9b5f3666409355");

                //var inputSting = "e8d96a53e9c597e5a1e2ceaddd0b5ebe75588b26e71846b46a9b5f3666409355";
                //var inputSting = ;
                var privateKey = Bytes32.ConvetToBigInteger(hash);
                privateKey = privateKey % Secp256k1.q;
                var privateByte = hash;

                {
                    var resultAdd = Calculate.BiteSplitJoint(new byte[] { 0x80 }, privateByte);
                    resultAdd = Calculate.BiteSplitJoint(resultAdd, new byte[] { 0x01 });
                    byte[] chechHash = Calculate.GetCheckSum(resultAdd);
                    resultAdd = Calculate.BiteSplitJoint(resultAdd, chechHash);
                    var privateKey1 = Calculate.Encode(resultAdd);
                    Console.WriteLine($"您压缩后的私钥为{privateKey1}");
                }
                {
                    var    resultAdd = Calculate.BiteSplitJoint(new byte[] { 0x80 }, privateByte);
                    byte[] chechHash = Calculate.GetCheckSum(resultAdd);
                    resultAdd = Calculate.BiteSplitJoint(resultAdd, chechHash);
                    var privateKey1 = Calculate.Encode(resultAdd);
                    Console.WriteLine($"您压缩前的私钥为{privateKey1}");
                }
                var publicKey = Calculate.getPublicByPrivate(privateKey);
                if (publicKey != null)
                {
                    var walletOfcompressed = PublicKeyF.GetAddressOfcompressed(publicKey);
                    Console.WriteLine($"压缩钱包地址为:{walletOfcompressed}");
                    var walletOfUncompressed = PublicKeyF.GetAddressOfUncompressed(publicKey);
                    Console.WriteLine($"非压缩钱包地址为:{walletOfUncompressed}");
                    result.Add(walletOfcompressed);
                    result.Add(walletOfUncompressed);
                }
            }

            return(result);
        }