Esempio n. 1
0
 public async Task ImportPrivKeyAsync(BitcoinSecret secret)
 {
     await SendCommandAsync(RPCOperations.importprivkey, secret.ToWif()).ConfigureAwait(false);
 }
Esempio n. 2
0
        // importprivkey

        public void ImportPrivKey(BitcoinSecret secret)
        {
            SendCommand(RPCOperations.importprivkey, secret.ToWif());
        }
Esempio n. 3
0
 public void ImportPrivKey(BitcoinSecret secret, string label, bool rescan)
 {
     SendCommand(RPCOperations.importprivkey, secret.ToWif(), label, rescan);
 }
Esempio n. 4
0
        // importprivkey

        public void ImportPrivKey(BitcoinSecret secret)
        {
            SendCommand("importprivkey", secret.ToWif());
        }
Esempio n. 5
0
 public async Task ImportPrivKeyAsync(BitcoinSecret secret, string label, bool rescan)
 {
     await SendCommandAsync("importprivkey", secret.ToWif(), label, rescan).ConfigureAwait(false);
 }
Esempio n. 6
0
		public async Task ImportPrivKeyAsync(BitcoinSecret secret)
		{
			await SendCommandAsync("importprivkey", secret.ToWif()).ConfigureAwait(false);
		}
Esempio n. 7
0
		public async Task ImportPrivKeyAsync(BitcoinSecret secret, string label, bool rescan)
		{
			await SendCommandAsync("importprivkey", secret.ToWif(), label, rescan).ConfigureAwait(false);
		}
Esempio n. 8
0
		public void ImportPrivKey(BitcoinSecret secret, string label, bool rescan)
		{
			SendCommand("importprivkey", secret.ToWif(), label, rescan);
		}
Esempio n. 9
0
		public void ImportPrivKey(BitcoinSecret secret)
		{
			SendCommand("importprivkey", secret.ToWif());
		}
        private void FormDetails_Load(object sender, EventArgs e)
        {
            if (Key == null)
            {
                return;
            }

            string         privateKey = "";
            string         pubKey     = "";
            string         address    = "";
            string         hash       = "";
            string         script     = "";
            string         base58Type = "";
            BitcoinAddress bitcoinAddress;

            Type type = Key.GetType();

            using (new HourGlass())
            {
                switch (type.ToString())
                {
                case "knoledge_keychain.KeyPair":
                    KeyPair keyPair = Key as KeyPair;
                    privateKey = keyPair.PrivateKeyString;
                    pubKey     = keyPair.PubKey.ToString();
                    address    = keyPair.Address.ToString();
                    hash       = keyPair.PubKey.ExtPubKey.PubKey.Hash.ToString();
                    script     = keyPair.PubKey.ScriptPubKey.ToString();

                    if (keyPair.PrivateKey != null)
                    {
                        base58Type = keyPair.PrivateKey.Type.ToString();
                    }
                    else
                    {
                        base58Type = keyPair.PubKey.Type.ToString();
                    }
                    break;

                case "NBitcoin.BitcoinSecret":
                    BitcoinSecret secret = Key as BitcoinSecret;
                    privateKey     = secret.ToWif();
                    bitcoinAddress = secret.GetAddress();
                    address        = bitcoinAddress.ToString();
                    hash           = secret.PubKey.Hash.ToString();
                    script         = bitcoinAddress.ScriptPubKey.ToString();
                    base58Type     = secret.Type.ToString();
                    break;

                case "NBitcoin.ExtKey":
                    ExtKey extKey = Key as ExtKey;
                    privateKey     = extKey.ToString(Network.TestNet);
                    bitcoinAddress = extKey.ScriptPubKey.GetDestinationAddress(Network.TestNet);
                    address        = bitcoinAddress.ToString();
                    script         = bitcoinAddress.ScriptPubKey.ToString();
                    break;
                }
            }

            textBoxType.Text           = base58Type;
            textBoxPrivateKey.Text     = privateKey;
            textBoxBitcoinAddress.Text = address;
            textBoxPubHash.Text        = hash;
            textBoxPubKey.Text         = pubKey;
            textBoxScriptPubKey.Text   = script;

            textBoxPrivateKey.Focus();
        }
Esempio n. 11
0
        private async void bGenerate_Click(object sender, EventArgs e)
        {
            try
            {
                var dictionary = await ReadWordList();

                var settings = Settings.ReadAppSettings();

                var wordList         = textWordList.Text;
                var splittedWordList = wordList.Split(new char[] { ' ' });
                splittedWordList = splittedWordList.Where(c => !string.IsNullOrEmpty(c)).ToArray();
                if (splittedWordList.Count() != 12)
                {
                    Alert("The count of words should be exactly 12");
                }
                else
                {
                    for (int i = 0; i < 12; i++)
                    {
                        if (!dictionary.ContainsKey(splittedWordList[i]))
                        {
                            Alert(string.Format("{0} is not present in the dictionary", splittedWordList[i]));
                            return;
                        }
                    }

                    var initialKey = GenerateKeyFrom12Words(splittedWordList, dictionary);
                    textGeneratedBitcoinPrivateKey.Text = string.Empty;
                    if (string.IsNullOrEmpty(textBitcoinPrivateAddr.Text.Trim()))
                    {
                        BitcoinSecret secret = new BitcoinSecret(initialKey, settings.Network);
                        textGeneratedBitcoinPrivateKey.Text = secret.ToWif();

                        var addr = secret.GetAddress();
                        textBitcoinPrivateAddr.Text = addr.ToString();
                    }
                    else
                    {
                        var            initialKeyBytes = initialKey.ToBytes();
                        BitcoinAddress addr            = null;
                        try
                        {
                            addr = BitcoinAddress.GetFromBase58Data(textBitcoinPrivateAddr.Text.Trim(), settings.Network) as BitcoinAddress;
                            var bitcoinAddressFound = false;

                            for (byte i = 0; i <= 255; i++)
                            {
                                var keyBytes = initialKeyBytes;
                                keyBytes[0] = i;
                                Key key = new Key(keyBytes);

                                BitcoinSecret secret = new BitcoinSecret(key, settings.Network);
                                if (secret.GetAddress() == addr)
                                {
                                    textGeneratedBitcoinPrivateKey.Text = secret.ToWif();
                                    bitcoinAddressFound = true;
                                }

                                if (i == 255)
                                {
                                    break;
                                }
                            }

                            if (!bitcoinAddressFound)
                            {
                                Alert("The provided address is not a valid Bitcoin address for 12 words.");
                            }
                        }
                        catch (Exception exp)
                        {
                            Alert("Invalid address string: " + exp.ToString());
                        }
                    }

                    textGeneratedEthereumPrivateKey.Text = string.Empty;
                    var ethPrivateAddr = textEthereumPrivateAddr.Text.Trim();
                    if (ethPrivateAddr != "Ethereum address to get the private key for" &&
                        !String.IsNullOrEmpty(ethPrivateAddr))
                    {
                        var ethPrivateKeyFound = false;
                        for (byte i = 0; i <= 255; i++)
                        {
                            var keyBytes = initialKey.ToBytes();
                            keyBytes[0]    = i;
                            ethPrivateAddr = ethPrivateAddr.ToLower();
                            var ethAccount = new Account(keyBytes.ToHex()).Address.ToLower();
                            if (ethAccount == ethPrivateAddr ||
                                ethAccount == string.Concat("0x", ethPrivateAddr))
                            {
                                textGeneratedEthereumPrivateKey.Text = keyBytes.ToHex();
                                ethPrivateKeyFound = true;
                            }

                            if (i == 255)
                            {
                                break;
                            }
                        }

                        if (!ethPrivateKeyFound)
                        {
                            Alert("The provided address is not a valid ethereum address for 12 words.");
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                Alert(exp.ToString());
            }
        }
        public async Task <string> CreateTransfer(string clientPubKey, decimal amount, IAsset asset, string clientPrevPrivateKey)
        {
            var address = await _multisigService.GetMultisig(clientPubKey);

            if (address == null)
            {
                throw new BackendException($"Client {clientPubKey} is not registered", ErrorCode.BadInputParameter);
            }

            var channel = await _offchainChannelRepository.GetChannel(address.MultisigAddress, asset.Id);

            if (channel == null)
            {
                throw new BackendException("Channel is not found", ErrorCode.ShouldOpenNewChannel);
            }

            if (!channel.IsBroadcasted)
            {
                throw new BackendException("Channel is not finalized", ErrorCode.ChannelNotFinalized);
            }

            if (amount < 0 && channel.ClientAmount < Math.Abs(amount))
            {
                throw new BackendException("Client amount in channel is low than required", ErrorCode.ShouldOpenNewChannel);
            }

            if (amount > 0 && channel.HubAmount < amount)
            {
                throw new BackendException("Hub amount in channel is low than required", ErrorCode.ShouldOpenNewChannel);
            }

            if (string.IsNullOrWhiteSpace(clientPrevPrivateKey))
            {
                throw new BackendException("Private key for previous commitment is required", ErrorCode.ShouldOpenNewChannel);
            }

            var prevCommitment = await _commitmentRepository.GetLastCommitment(address.MultisigAddress, asset.Id, CommitmentType.Client);

            var secret = new BitcoinSecret(clientPrevPrivateKey);

            if (prevCommitment.RevokePubKey != secret.PubKey.ToHex())
            {
                throw new BackendException("Client private key for previous commitment is invalid", ErrorCode.ShouldOpenNewChannel);
            }

            await _signatureApiProvider.AddKey(clientPrevPrivateKey);

            await _commitmentRepository.UpdateClientPrivateKey(prevCommitment.CommitmentId, address.MultisigAddress, asset.Id, secret.ToWif());

            var hubRevokeKey = new Key();


            var newHubAmount    = channel.HubAmount - amount;
            var newClientAmount = channel.ClientAmount + amount;

            var commitmentResult = CreateCommitmentTransaction(address, new PubKey(address.ExchangePubKey), new PubKey(clientPubKey), hubRevokeKey.PubKey, new PubKey(clientPubKey), asset,
                                                               newHubAmount, newClientAmount, channel.FullySignedChannel);

            await _commitmentRepository.CreateCommitment(CommitmentType.Hub, channel.ChannelId, address.MultisigAddress, asset.Id,
                                                         new BitcoinSecret(hubRevokeKey, _connectionParams.Network).ToString(), hubRevokeKey.PubKey.ToHex(),
                                                         commitmentResult.Transaction.ToHex(), newClientAmount, newHubAmount, commitmentResult.LockedAddress, commitmentResult.LockedScript);

            return(commitmentResult.Transaction.ToHex());
        }