Ejemplo n.º 1
0
        private static CoinKeyPair _P2WpkhGenerator()
        {
            var priv    = _NewPrivKey();
            var privKey = priv.Item1;
            var wif     = priv.Item2;
            var pub     = _PrivToPubKey(privKey);

            var pkHash = new Ripemd160Managed().ComputeHash(new SHA256Managed().ComputeHash(pub));

            return(new CoinKeyPair(wif, new Bech32Encoder().Encode("bc", pkHash)));
        }
Ejemplo n.º 2
0
        private static CoinKeyPair _P2ShGenerator()
        {
            var priv    = _NewPrivKey();
            var privKey = priv.Item1;
            var wif     = priv.Item2;
            var pub     = _PrivToPubKey(privKey);

            var redeemScript = new byte[35];

            redeemScript[0]  = 0x21;
            redeemScript[34] = 0xac;
            Array.Copy(pub, 0, redeemScript, 1, 33);

            var psVersioned = new byte[20 + 1];

            psVersioned[0] = 0x05;

            var sHash = new Ripemd160Managed().ComputeHash(new SHA256Managed().ComputeHash(redeemScript));

            Array.Copy(sHash, 0, psVersioned, 1, 20);
            return(new CoinKeyPair(wif, new Base58CheckEncoder().Encode(psVersioned)));
        }
Ejemplo n.º 3
0
        private static CoinKeyPair _P2PkhGenerator()
        {
regenerate:
            var priv = _NewPrivKey();
            var privKey = priv.Item1;
            var wif     = priv.Item2;
            var pub     = _PrivToPubKey(privKey);

            var pkHash          = new Ripemd160Managed().ComputeHash(new SHA256Managed().ComputeHash(pub));
            var pkHashVersioned = new byte[20 + 1];

            pkHashVersioned[0] = 0x00;
            Array.Copy(pkHash, 0, pkHashVersioned, 1, 20);
            var addr = new Base58CheckEncoder().Encode(pkHashVersioned);

            // Some addresses ends up to be 26 chars while most are 27 chars long.
            // For stability reason, 26 chars long addresses are filtered out and the program would redo the generation.
            if (addr.Length != 27)
            {
                goto regenerate;
            }
            return(new CoinKeyPair(wif, addr));
        }