Example #1
0
        public void ToPrivateKeyTest()
        {
            byte[]    key       = "2121212121212121212121212121212121212121212121212121212121212121".HexToByteArray();
            ECKeyPair ecKeyPair = new ECKeyPair(key, true);

            var privateKey = ecKeyPair.ToPrivateKey();

            Assert.Equal(key.ToHex(), privateKey.GetBytes().ToHex());
        }
        public void Initialize(ECKeyPair key, NetworkParameters networkParameters)
        {
            CreateClient(networkParameters);

            var secret = key.ToPrivateKey().GetBitcoinSecret(NBitcoin.Network.GetNetwork(networkParameters.Name));

            try
            {
                bool alreadyImported = HasImportedKey(secret);

                if (!alreadyImported)
                {
                    ImportPrivateKey(secret, SecretLabel, true);
                }
            }
            catch (WebException webException)
            {
                string error = "Initialize failed: bitcoind is not available. ";
                _logger.LogError(error + webException, webException);
                throw new BlockchainClientException(error, webException);
            }
        }