public HDKeyData GetKey(int n) { var network = ExtPubKeys.Select(e => e.Network).FirstOrDefault(); var root = Path ?? new KeyPath(); var next = root.Derive(n, false); var keyData = new HDKeyData(); keyData.ExtPubKeys = ExtPubKeys .Select(k => k.ExtPubKey.Derive(next).GetWif(network)).ToArray(); keyData.Path = next; keyData.RedeemScript = CreateScriptPubKey(keyData.ExtPubKeys); if (!P2SH) { keyData.ScriptPubKey = keyData.RedeemScript; keyData.RedeemScript = null; keyData.Address = keyData.ScriptPubKey.GetDestinationAddress(network); } else { keyData.ScriptPubKey = keyData.RedeemScript.Hash.ScriptPubKey; keyData.Address = keyData.ScriptPubKey.GetDestinationAddress(network); } return(keyData); }
protected override async Task CreateTask(System.Threading.CancellationToken cancelation) { HDKeySet keyset = new HDKeySet(); keyset.Name = Name; keyset.Path = String.IsNullOrWhiteSpace(KeyPath) ? null : new KeyPath(KeyPath); keyset.SignatureCount = SignatureCount; keyset.ExtPubKeys = ExtPubKeys .Select(_ => new BitcoinExtPubKey(_.Value, _Network)) .ToArray(); var client = _Parent._Parent.ClientFactory.CreateClient(); await client.CreateKeySet(_Parent.Name, keyset); Info("Keyset created"); _Parent.Refresh.Execute(false); }
private void UpdateExtPubKeys() { int i = 0; for (i = 0; i < KeyCount; i++) { if (ExtPubKeys.Count < i + 1) { ExtPubKeys.Add(new ExtPubkeyViewModel(_Network) { FieldName = "Key " + (i + 1), }); } } while (ExtPubKeys.Count != KeyCount) { ExtPubKeys.RemoveAt(ExtPubKeys.Count - 1); } }