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 static string GetPathString(SafeAccount account) => account.PathString;
public BitcoinAddress GetAddress(int index, HdPathType hdPathType = HdPathType.Receive, SafeAccount account = null) { return(GetPrivateKey(index, hdPathType, account).ScriptPubKey.GetDestinationAddress(Network)); }
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 BitcoinExtKey FindPrivateKey(BitcoinAddress address, int stopSearchAfterIteration = 100000, SafeAccount account = null) { for (int i = 0; i < stopSearchAfterIteration; i++) { if (GetAddress(i, HdPathType.Receive, account) == address) { return(GetPrivateKey(i, HdPathType.Receive, account)); } if (GetAddress(i, HdPathType.Change, account) == address) { return(GetPrivateKey(i, HdPathType.Change, account)); } if (GetAddress(i, HdPathType.NonHardened, account) == address) { return(GetPrivateKey(i, HdPathType.NonHardened, account)); } } throw new KeyNotFoundException(address.ToWif()); }
public BitcoinExtPubKey GetBitcoinExtPubKey(int?index = null, HdPathType hdPathType = HdPathType.Receive, SafeAccount account = null) => GetBitcoinExtKey(index, hdPathType, account).Neuter();
public bool Equals(SafeAccount other) => PathString.Equals(other.PathString, StringComparison.Ordinal);