public void Base58EncodingLeadingZero() { const string privkey = "91axuYLa8xK796DnBXXsMbjuc8pDYxYgJyQMvFzrZ6UfXaGYuqL"; var key = new DumpedPrivateKey(NetworkParameters.TestNet(), privkey).Key; Assert.AreEqual(privkey, key.GetPrivateKeyEncoded(NetworkParameters.TestNet()).ToString()); Assert.AreEqual(0, key.GetPrivKeyBytes()[0]); }
public void Base58Encoding() { const string addr = "mqAJmaxMcG5pPHHc3H3NtyXzY7kGbJLuMF"; const string privkey = "92shANodC6Y4evT5kFzjNFQAdjqTtHAnDTLzqBBq4BbKUPyx6CD"; var key = new DumpedPrivateKey(NetworkParameters.TestNet(), privkey).Key; Assert.AreEqual(privkey, key.GetPrivateKeyEncoded(NetworkParameters.TestNet()).ToString()); Assert.AreEqual(addr, key.ToAddress(NetworkParameters.TestNet()).ToString()); }
public void Base58EncodingStress() { // Replace the loop bound with 1000 to get some keys with leading zero byte for (var i = 0; i < 20; i++) { var key = new EcKey(); var key1 = new DumpedPrivateKey(NetworkParameters.TestNet(), key.GetPrivateKeyEncoded(NetworkParameters.TestNet()).ToString()).Key; Assert.AreEqual(Utils.BytesToHexString(key.GetPrivKeyBytes()), Utils.BytesToHexString(key1.GetPrivKeyBytes())); } }
public static void Run(string[] args) { // TODO: Assumes production network not testnet. Make it selectable. var @params = NetworkParameters.ProdNet(); try { // Decode the private key from Satoshi's Base58 variant. If 51 characters long then it's from BitCoins // "dumpprivkey" command and includes a version byte and checksum. Otherwise assume it's a raw key. EcKey key; if (args[0].Length == 51) { var dumpedPrivateKey = new DumpedPrivateKey(@params, args[0]); key = dumpedPrivateKey.Key; } else { var privKey = Base58.DecodeToBigInteger(args[0]); key = new EcKey(privKey); } Console.WriteLine("Address from private key is: " + key.ToAddress(@params)); // And the address ... var destination = new Address(@params, args[1]); // Import the private key to a fresh wallet. var wallet = new Wallet(@params); wallet.AddKey(key); // Find the transactions that involve those coins. using (var blockStore = new MemoryBlockStore(@params)) { var chain = new BlockChain(@params, wallet, blockStore); var peerGroup = new PeerGroup(blockStore, @params, chain); peerGroup.AddAddress(new PeerAddress(IPAddress.Loopback)); peerGroup.Start(); peerGroup.DownloadBlockChain(); peerGroup.Stop(); // And take them! Console.WriteLine("Claiming " + Utils.BitcoinValueToFriendlyString(wallet.GetBalance()) + " coins"); wallet.SendCoins(peerGroup, destination, wallet.GetBalance()); // Wait a few seconds to let the packets flush out to the network (ugly). Thread.Sleep(5000); } } catch (IndexOutOfRangeException) { Console.WriteLine("First arg should be private key in Base58 format. Second argument should be address to send to."); } }
public static void Run(string[] args) { // TODO: Assumes production network not testnet. Make it selectable. var networkParams = NetworkParameters.ProdNet(); try { // Decode the private key from Satoshi's Base58 variant. If 51 characters long then it's from BitCoins // "dumpprivkey" command and includes a version byte and checksum. Otherwise assume it's a raw key. EcKey key; if (args[0].Length == 51) { var dumpedPrivateKey = new DumpedPrivateKey(networkParams, args[0]); key = dumpedPrivateKey.Key; } else { var privKey = Base58.DecodeToBigInteger(args[0]); key = new EcKey(privKey); } Console.WriteLine("Address from private key is: " + key.ToAddress(networkParams)); // And the address ... var destination = new Address(networkParams, args[1]); // Import the private key to a fresh wallet. var wallet = new Wallet(networkParams); wallet.AddKey(key); // Find the transactions that involve those coins. using (var blockStore = new MemoryBlockStore(networkParams)) { var chain = new BlockChain(networkParams, wallet, blockStore); var peerGroup = new PeerGroup(blockStore, networkParams, chain); peerGroup.AddAddress(new PeerAddress(IPAddress.Loopback)); peerGroup.Start(); peerGroup.DownloadBlockChain(); peerGroup.Stop(); // And take them! Console.WriteLine("Claiming " + Utils.BitcoinValueToFriendlystring(wallet.GetBalance()) + " coins"); wallet.SendCoins(peerGroup, destination, wallet.GetBalance()); // Wait a few seconds to let the packets flush out to the network (ugly). Thread.Sleep(5000); } } catch (IndexOutOfRangeException) { Console.WriteLine("First arg should be private key in Base58 format. Second argument should be address to send to."); } }