public static MiniKeyPair CreateDeterministic(string seed)
        {
            // flow:
            // 1. take SHA256 of seed to yield 32 bytes
            // 2. base58-encode those 32 bytes as though it were a regular private key. now we have 51 characters.
            // 3. remove all instances of the digit 1. (likely source of typos)
            // 4. take 29 characters starting with position 4
            //    (this is to skip those first characters of a base58check-encoded private key with low entropy)
            // 5. test to see if it matches the typo check.  while it does not, increment and try again.
            UTF8Encoding utf8 = new UTF8Encoding(false);
            byte[] sha256ofseed = Util.ComputeSha256(seed);

            string asbase58 = new KeyPair(sha256ofseed).PrivateKeyBase58.Replace("1","");

            string keytotry = "S" + asbase58.Substring(4, 29);
            char[] chars = keytotry.ToCharArray();
            char[] charstest = (keytotry + "?").ToCharArray();

            while (Util.ComputeSha256(utf8.GetBytes(charstest))[0] != 0) {
                // As long as key doesn't pass typo check, increment it.
                for (int i = chars.Length - 1; i >= 0; i--) {
                    char c = chars[i];
                    if (c == '9') {
                        charstest[i] = chars[i] = 'A';
                        break;
                    } else if (c == 'H') {
                        charstest[i] = chars[i] = 'J';
                        break;
                    } else if (c == 'N') {
                        charstest[i] = chars[i] = 'P';
                        break;
                    } else if (c == 'Z') {
                        charstest[i] = chars[i] = 'a';
                        break;
                    } else if (c == 'k') {
                        charstest[i] = chars[i] = 'm';
                        break;
                    } else if (c == 'z') {
                        charstest[i] = chars[i] = '2';
                        // No break - let loop increment prior character.
                    } else {
                        charstest[i] = chars[i] = ++c;
                        break;
                    }
                }
            }
            return new MiniKeyPair(new String(chars));
        }
Example #2
0
        public static MiniKeyPair CreateDeterministic(string seed)
        {
            // flow:
            // 1. take SHA256 of seed to yield 32 bytes
            // 2. base58-encode those 32 bytes as though it were a regular private key. now we have 51 characters.
            // 3. remove all instances of the digit 1. (likely source of typos)
            // 4. take 29 characters starting with position 4
            //    (this is to skip those first characters of a base58check-encoded private key with low entropy)
            // 5. test to see if it matches the typo check.  while it does not, increment and try again.
            UTF8Encoding utf8 = new UTF8Encoding(false);

            byte[] sha256ofseed = Util.ComputeSha256(seed);

            string asbase58 = new KeyPair(sha256ofseed).PrivateKeyBase58.Replace("1", "");

            string keytotry = "S" + asbase58.Substring(4, 29);

            char[] chars     = keytotry.ToCharArray();
            char[] charstest = (keytotry + "?").ToCharArray();

            while (Util.ComputeSha256(utf8.GetBytes(charstest))[0] != 0)
            {
                // As long as key doesn't pass typo check, increment it.
                for (int i = chars.Length - 1; i >= 0; i--)
                {
                    char c = chars[i];
                    if (c == '9')
                    {
                        charstest[i] = chars[i] = 'A';
                        break;
                    }
                    else if (c == 'H')
                    {
                        charstest[i] = chars[i] = 'J';
                        break;
                    }
                    else if (c == 'N')
                    {
                        charstest[i] = chars[i] = 'P';
                        break;
                    }
                    else if (c == 'Z')
                    {
                        charstest[i] = chars[i] = 'a';
                        break;
                    }
                    else if (c == 'k')
                    {
                        charstest[i] = chars[i] = 'm';
                        break;
                    }
                    else if (c == 'z')
                    {
                        charstest[i] = chars[i] = '2';
                        // No break - let loop increment prior character.
                    }
                    else
                    {
                        charstest[i] = chars[i] = ++c;
                        break;
                    }
                }
            }
            return(new MiniKeyPair(new String(chars)));
        }
        /// <summary>
        /// flow:
        /// 1. take SHA256 of seed to yield 32 bytes
        /// 2. base58-encode those 32 bytes as though it were a regular private key. now we have 51 characters.
        /// 3. remove all instances of the digit 1. (likely source of typos)
        /// 4. take 29 characters starting with position 4
        ///    (this is to skip those first characters of a base58check-encoded private key with low entropy)
        /// 5. test to see if it matches the typo check.  while it does not, increment and try again.
        /// </summary>
        /// <returns></returns>
        public static MiniKeyPair CreateDeterministic(string seed, byte addressType = 0)
        {
            UTF8Encoding utf8 = new UTF8Encoding(false);
            byte[] sha256ofseed = Util.ComputeSha256(seed);

            string asbase58 = new KeyPair(sha256ofseed).PrivateKeyBase58.Replace("1","");

            string keytotry = "S" + asbase58.Substring(4, 29);
            char[] chars = keytotry.ToCharArray();
            char[] charstest = (keytotry + "?").ToCharArray();

            while (Util.ComputeSha256(utf8.GetBytes(charstest))[0] != 0) {
                // As long as key doesn't pass typo check, increment it.
                for (int i = chars.Length - 1; i >= 0; i--) {
                    char c = chars[i];
                    if (c == '9') {
                        charstest[i] = chars[i] = 'A';
                        break;
                    } else if (c == 'H') {
                        charstest[i] = chars[i] = 'J';
                        break;
                    } else if (c == 'N') {
                        charstest[i] = chars[i] = 'P';
                        break;
                    } else if (c == 'Z') {
                        charstest[i] = chars[i] = 'a';
                        break;
                    } else if (c == 'k') {
                        charstest[i] = chars[i] = 'm';
                        break;
                    } else if (c == 'z') {
                        charstest[i] = chars[i] = '2';
                        // No break - let loop increment prior character.
                    } else {
                        charstest[i] = chars[i] = ++c;
                        break;
                    }
                }
            }
            return new MiniKeyPair(new String(chars), addressType);
        }