Beispiel #1
0
        /// <summary>
        /// Derives an extended child key at the given path relative to the current key
        /// </summary>
        /// <param name="path">HD key path</param>
        /// <returns>Derived extended child key</returns>
        public HDKey Derive(HDPath path)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            if (!path.Any())
            {
                return(this);
            }

            using (Store.Unlock())
            {
                var prvKey    = Store.Data;
                var chainCode = _ChainCode;

                foreach (var uind in path)
                {
                    (prvKey, chainCode) = HD.GetChildPrivateKey(Curve, prvKey, chainCode, uind);
                }

                return(new(new(prvKey, Curve.Kind, true), chainCode));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Converts the path string, formatted like m/44'/1729'/0/0', to the HDPath object
        /// </summary>
        /// <param name="path">HD key path string, formatted like m/44'/1729'/0/0'</param>
        /// <param name="res">Successfully parsed HDPath</param>
        /// <returns>True if the HDPath is parsed successfully, otherwise false</returns>
        public static bool TryParse(string path, out HDPath res)
        {
            res = null;
            if (path == null)
            {
                return(false);
            }

            path = path.TrimStart('m').Trim('/');
            if (path.Length == 0)
            {
                res = new();
                return(true);
            }

            var ss      = path.Split('/');
            var indexes = new uint[ss.Length];

            for (int i = 0; i < ss.Length; i++)
            {
                if (!TryParseIndex(ss[i], out var ind))
                {
                    return(false);
                }
                indexes[i] = ind;
            }

            res = new(indexes);
            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Derives an extended child key at the given index
        /// </summary>
        /// <param name="index">Index of the child key, starting from zero</param>
        /// <param name="hardened">If true, hardened derivation will be performed</param>
        /// <returns>Derived extended child key</returns>
        public HDKey Derive(int index, bool hardened = false)
        {
            var uind = HDPath.GetIndex(index, hardened);

            using (Store.Unlock())
            {
                var(prvKey, chainCode) = HD.GetChildPrivateKey(Curve, Store.Data, _ChainCode, uind);
                return(new(new(prvKey, Curve.Kind, true), chainCode));
            }
        }
Beispiel #4
0
 /// <summary>
 /// Derives an extended child key at the given path relative to the current key
 /// </summary>
 /// <param name="path">HD key path string, formatted like m/44'/1729'/0/0'</param>
 /// <returns>Derived extended child key</returns>
 public HDKey Derive(string path) => Derive(HDPath.Parse(path));