Esempio n. 1
0
        public void TestHDKeyGenerationNist()
        {
            var path       = new HDPath("m/44/1729/0/0/1");
            var key        = new HDKey(ECKind.NistP256);
            var derived    = key.Derive(path);
            var pubDerived = key.HDPubKey.Derive(path);

            Assert.Equal(derived.Address, pubDerived.Address);
        }
Esempio n. 2
0
            public (KeyPath KeyPath, Key Key) GetNextKey()
            {
                if (HDKey is null || NextKeyPath is null)
                {
                    throw new InvalidOperationException("Invalid keyset");
                }
                var k    = HDKey.Derive(NextKeyPath).PrivateKey;
                var path = NextKeyPath;

                NextKeyPath = NextKeyPath.Increment() !;
                return(path, k);
            }
Esempio n. 3
0
        public void TestHdKeyGenerationSecp()
        {
            var path       = new HDPath("m/44/1729/0/0/0");
            var key        = new HDKey(ECKind.Secp256k1);
            var anotherKey = new HDKey(ECKind.Secp256k1);

            Assert.NotEqual(key.Address, anotherKey.Address);

            var derived    = key.Derive(path);
            var pubDerived = key.HDPubKey.Derive(path);

            Assert.Equal(derived.Address, pubDerived.Address);
        }
Esempio n. 4
0
 public Key GetKey(RootedKeyPath keyPath)
 {
     if (SingleKey is Key)
     {
         if (SingleKey.PubKey.GetHDFingerPrint() != keyPath.MasterFingerprint)
         {
             throw new InvalidOperationException("The fingerprint of the keyset, does not match the mnemonic");
         }
         if (keyPath.KeyPath.Indexes.Length != 0)
         {
             throw new InvalidOperationException("Indices in the keypath are not valid for this keyset");
         }
         return(SingleKey);
     }
     if (HDKey is null)
     {
         throw new InvalidOperationException("The keyset does not have a mnemonic set");
     }
     if (HDKey.GetPublicKey().GetHDFingerPrint() != keyPath.MasterFingerprint)
     {
         throw new InvalidOperationException("The fingerprint of the keyset, does not match the mnemonic");
     }
     return(HDKey.Derive(keyPath.KeyPath).PrivateKey);
 }