// GetP2wpkh pubKey.WitHash.ScriptPubKey.GetDestinationAddress(Network); // GetP2pkhAddress pubKey.Hash.ScriptPubKey.GetDestinationAddress(Network); // GetP2shOverP2wpkhAddress pubKey.WitHash.ScriptPubKey.Hash.ScriptPubKey.GetDestinationAddress(Network); public BitcoinAddress GetAddress(AddressType type, int index, HdPathType hdPathType = HdPathType.Receive, SafeAccount account = null) { BitcoinAddress cachedAddress = SafeCache.FirstOrDefault(x => x.Key.Item1 == type && x.Key.Item2 == index && x.Key.Item3 == hdPathType && x.Key.Item4 == account).Value; if (cachedAddress != null) { return(cachedAddress); } PubKey pubKey = GetPubKey(index, hdPathType, account); BitcoinAddress address = null; if (type == AddressType.Pay2WitnessPublicKeyHash) { address = pubKey.WitHash.ScriptPubKey.GetDestinationAddress(Network); } else if (type == AddressType.Pay2PublicKeyHash) { address = pubKey.Hash.ScriptPubKey.GetDestinationAddress(Network); } else if (type == AddressType.Pay2ScriptHashOverPay2WitnessPublicKeyHash) { address = pubKey.WitHash.ScriptPubKey.Hash.ScriptPubKey.GetDestinationAddress(Network); } else { throw new NotSupportedException(type.ToString()); } SafeCache.TryAdd(new Tuple <AddressType, int, HdPathType, SafeAccount>(type, index, hdPathType, account), address); return(address); }
public BitcoinExtKey GetPrivateKey(int index, HdPathType hdPathType = HdPathType.Receive, SafeAccount account = null) { string firstPart = ""; if (account != null) { firstPart += Hierarchy.GetPathString(account) + "/"; } firstPart += Hierarchy.GetPathString(hdPathType); string lastPart; if (hdPathType == HdPathType.NonHardened) { lastPart = $"/{index}"; } else { lastPart = $"/{index}'"; } KeyPath keyPath = new KeyPath(firstPart + lastPart); return(ExtKey.Derive(keyPath).GetWif(Network)); }
public IList <BitcoinAddress> GetFirstNAddresses(int addressCount, HdPathType hdPathType = HdPathType.Receive, SafeAccount account = null) { var addresses = new List <BitcoinAddress>(); for (var i = 0; i < addressCount; i++) { addresses.Add(GetAddress(i, hdPathType, account)); } return(addresses); }
public HashSet <BitcoinAddress> GetFirstNAddresses(int addressCount, HdPathType hdPathType = HdPathType.Receive) { var addresses = new HashSet <BitcoinAddress>(); for (var i = 0; i < addressCount; i++) { addresses.Add(GetAddress(i, hdPathType)); } return(addresses); }
private void UpdateSafeTrackingByHdPathType(HdPathType hdPathType) { if (TracksDefaultSafe) { UpdateSafeTrackingByPath(hdPathType); } foreach (var acc in SafeAccounts) { UpdateSafeTrackingByPath(hdPathType, acc); } }
public static string GetPathString(HdPathType type) { switch (type) { case HdPathType.Stealth: return("0'"); case HdPathType.Receive: return("1'"); case HdPathType.Change: return("2'"); default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } }
public BitcoinExtKey GetBitcoinExtKey(int?index = null, HdPathType hdPathType = HdPathType.Receive) { var firstPart = ""; firstPart += Hierarchy.GetPathString(hdPathType); string lastPart; if (index == null) { lastPart = ""; } else { lastPart = $"/{index}'"; } var keyPath = new KeyPath(firstPart + lastPart); return(ExtKey.Derive(keyPath).GetWif(Network)); }
internal BitcoinExtKey GetPrivateKey(int index, HdPathType hdPathType = HdPathType.Receive) { string startPath; if (hdPathType == HdPathType.Receive) { startPath = ReceiveHdPath; } else if (hdPathType == HdPathType.Change) { startPath = ChangeHdPath; } else { throw new Exception("HdPathType not exists"); } var keyPath = new KeyPath(startPath + "/" + index + "'"); return(_seedPrivateKey.Derive(keyPath).GetWif(_network)); }
internal BitcoinExtKey GetPrivateKey(int index, HdPathType hdPathType = HdPathType.Receive) { KeyPath keyPath; if (hdPathType == HdPathType.Receive) { keyPath = new KeyPath($"{ReceiveHdPath}/{index}'"); } else if (hdPathType == HdPathType.Change) { keyPath = new KeyPath($"{ChangeHdPath}/{index}'"); } else if (hdPathType == HdPathType.NonHardened) { keyPath = new KeyPath($"{NonHardenedHdPath}/{index}"); } else { throw new Exception("HdPathType not exists"); } return(ExtKey.Derive(keyPath).GetWif(Network)); }
public static string GetPathString(HdPathType type) { switch (type) { case HdPathType.Stealth: return("0'"); case HdPathType.Receive: return("1'"); case HdPathType.Change: return("2'"); case HdPathType.NonHardened: return("3"); case HdPathType.Account: return("4'"); // special default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } }
private void UpdateSafeTrackingByPath(HdPathType hdPathType, SafeAccount account = null) { int i = 0; var cleanCount = 0; while (true) { Script scriptPubkey = account == null?Safe.GetAddress(i, hdPathType).ScriptPubKey : Safe.GetAddress(i, hdPathType, account).ScriptPubKey; Tracker.TrackedScriptPubKeys.Add(scriptPubkey); // if clean elevate cleancount and if max reached don't look for more if (Tracker.IsClean(scriptPubkey)) { cleanCount++; if (cleanCount > MaxCleanAddressCount) { return; } } i++; } }
public PubKey GetPubKey(int index, HdPathType hdPathType, SafeAccount account) { return(GetBitcoinExtKey(index, hdPathType, account).PrivateKey.PubKey); }
public BitcoinExtPubKey GetBitcoinExtPubKey(int?index = null, HdPathType hdPathType = HdPathType.Receive, SafeAccount account = null) => GetBitcoinExtKey(index, hdPathType, account).Neuter();
public BitcoinExtPubKey GetBitcoinExtPubKey(int?index = null, HdPathType hdPathType = HdPathType.Receive) { return(GetBitcoinExtKey(index, hdPathType).Neuter()); }
public BitcoinAddress GetAddress(int index, HdPathType hdPathType = HdPathType.Receive, SafeAccount account = null) { return(GetPrivateKey(index, hdPathType, account).ScriptPubKey.GetDestinationAddress(Network)); }
public BitcoinAddress GetAddress(int index, HdPathType hdPathType = HdPathType.Receive) { return(GetBitcoinExtKey(index, hdPathType).ScriptPubKey.GetDestinationAddress(Network)); }
public IEnumerable <Script> GetUnusedScriptPubKeys(SafeAccount account = null, HdPathType hdPathType = HdPathType.Receive) { AssertAccount(account); HashSet <Script> scriptPubKeys = new HashSet <Script>(); int i = 0; while (true) { Script scriptPubkey = account == null?Safe.GetAddress(i, hdPathType).ScriptPubKey : Safe.GetAddress(i, hdPathType, account).ScriptPubKey; if (Tracker.IsClean(scriptPubkey)) { scriptPubKeys.Add(scriptPubkey); if (scriptPubKeys.Count >= MaxCleanAddressCount) { return(scriptPubKeys); } } i++; } }