Example #1
0
        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);
        }
Example #2
0
 public static string GetPathString(SafeAccount account) => account.PathString;
Example #3
0
 public BitcoinAddress GetAddress(int index, HdPathType hdPathType = HdPathType.Receive, SafeAccount account = null)
 {
     return(GetPrivateKey(index, hdPathType, account).ScriptPubKey.GetDestinationAddress(Network));
 }
Example #4
0
        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));
        }
Example #5
0
        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());
        }
Example #6
0
 public BitcoinExtPubKey GetBitcoinExtPubKey(int?index = null, HdPathType hdPathType = HdPathType.Receive, SafeAccount account = null) => GetBitcoinExtKey(index, hdPathType, account).Neuter();
Example #7
0
 public bool Equals(SafeAccount other) => PathString.Equals(other.PathString, StringComparison.Ordinal);