예제 #1
0
        public string GetAddress()
        {
            var sec  = GetPublicKeyBytes();
            var h160 = HashUtilities.Hash160(sec);

            byte[] rawBytes = new byte[21];
            if (TestNet)
            {
                rawBytes[0] = 0x6F;
            }
            else
            {
                rawBytes[0] = 0x00;
            }
            Buffer.BlockCopy(h160, 0, rawBytes, 1, h160.Length);

            return(Base58Utilities.EncodeBase58Check(rawBytes));
        }
예제 #2
0
        public static PrivateKey CreateFromWifString(string wifString)
        {
            bool testNet;
            bool wifCompressed;

            byte[] rawBytes        = Base58Utilities.DecodeBase58Check(wifString);
            byte[] privateKeyBytes = new byte[32];

            // Compressed is 34 bytes, uncompressed is 33 bytes
            if (rawBytes.Length == 34 || rawBytes.Length == 33)
            {
                Buffer.BlockCopy(rawBytes, 1, privateKeyBytes, 0, 32);
                if (rawBytes[0] == 0xEF)
                {
                    testNet = true;
                }
                else if (rawBytes[0] == 0x80)
                {
                    testNet = false;
                }
                else
                {
                    throw new ArgumentException(nameof(wifString) + " prefix is invalid");
                }

                wifCompressed = rawBytes.Length == 34;
            }
            else
            {
                throw new ArgumentException(nameof(wifString) + " is invalid");
            }

            var val = BigIntegerUtilities.CreateFromUnsignedBigEndianBytes(privateKeyBytes);

            return(new PrivateKey(val, testNet, wifCompressed));
        }
예제 #3
0
        public string GetWifString()
        {
            var bytes = GetWifBytes();

            return(Base58Utilities.EncodeBase58Check(bytes));
        }