Exemple #1
0
        public void SetKey(ExtPrivateKey privateKey)
        {
            var prefix = RootService.Network.ExtSecretKey;
            var data   = new byte[prefix.Length + ExtKey.Bip32KeySize];

            prefix.CopyTo(data.Slice(0, prefix.Length));
            privateKey.Encode(data.Slice(prefix.Length));
            SetData(data, prefix.Length);
        }
Exemple #2
0
        public ExtPrivateKey GetKey()
        {
            var privateKey = new ExtPrivateKey();

            if (KeyData.Length == ExtKey.Bip32KeySize)
            {
                privateKey.Decode(KeyData);
            }
            return(privateKey);
        }
Exemple #3
0
 public static ExtPublicKey FromPrivateKey(ExtPrivateKey privateKey)
 {
     return(new ExtPublicKey
     {
         Depth = privateKey.Depth,
         Fingerprint = privateKey.Fingerprint,
         Child = privateKey.IndexWithHardened,
         ChainCode = privateKey.ChainCode,
         PublicKey = privateKey.PrivateKey.CreatePublicKey()
     });
 }
Exemple #4
0
        /// <summary>
        /// Derives a child hierarchical deterministic public key specified by a key path.
        /// </summary>
        /// <param name="index"></param>
        /// <param name="hardened"></param>
        /// <returns></returns>
        protected override ExtKey DeriveBase(int index, bool hardened)
        {
            Trace.Assert(index >= 0);
            var cek = new ExtPrivateKey {
                Depth       = (byte)(Depth + 1),
                Child       = (uint)index | (hardened ? HardenedBit : 0),
                Fingerprint = BitConverter.ToInt32(PrivateKey.CreatePublicKey().GetId().Span.Slice(0, 4))
            };

            bool ok;

            (ok, cek.PrivateKey, cek.ChainCode) = PrivateKey.Derive(cek.Child, ChainCode);
            return(ok ? cek : null);
        }
Exemple #5
0
 public Base58ExtPrivateKey(ExtPrivateKey privateKey)
 {
     SetKey(privateKey);
 }