public async Task WaitFor(ExtPubKey pubKey, CancellationToken cancellation = default(CancellationToken)) { TaskCompletionSource <bool> completion = new TaskCompletionSource <bool>(); var key = Hashes.Hash160(pubKey.ToBytes()); lock (_WaitFor) { _WaitFor.Add(key, completion); } cancellation.Register(() => { completion.TrySetCanceled(); }); try { await completion.Task; } finally { lock (_WaitFor) { _WaitFor.Remove(key, completion); } } }
private void RunTest(TestVector test) { var seed = TestUtils.ParseHex(test.strHexMaster); ExtKey key = new ExtKey(seed); ExtPubKey pubkey = key.Neuter(); foreach (TestDerivation derive in test.vDerive) { byte[] data = key.ToBytes(); Assert.Equal(74, data.Length); data = pubkey.ToBytes(); Assert.Equal(74, data.Length); // Test private key BitcoinExtKey b58key = Network.Main.CreateBitcoinExtKey(key); var a = Encoders.Hex.EncodeData(Encoders.Base58Check.DecodeData(b58key.ToString())); var expected = Encoders.Hex.EncodeData(Encoders.Base58Check.DecodeData(derive.prv)); Assert.True(b58key.ToString() == derive.prv); // Test public key BitcoinExtPubKey b58pubkey = Network.Main.CreateBitcoinExtPubKey(pubkey); Assert.True(b58pubkey.ToString() == derive.pub); // Derive new keys ExtKey keyNew = key.Derive(derive.nChild); ExtPubKey pubkeyNew = keyNew.Neuter(); if (!((derive.nChild & 0x80000000) != 0)) { // Compare with public derivation ExtPubKey pubkeyNew2 = pubkey.Derive(derive.nChild); Assert.True(pubkeyNew == pubkeyNew2); } key = keyNew; pubkey = pubkeyNew; } }
public KeyInformation GetKeyInformation(ExtPubKey pubKey, Script script) { var info = GetKeyInformation(script); if (info == null || !pubKey.ToBytes().SequenceEqual(info.RootKey)) { return(null); } return(info); }
public void CanCheckChildKey() { var parent = new ExtKey(); ExtKey child = parent.Derive(1); var notchild = new ExtKey(); Assert.True(child.IsChildOf(parent)); Assert.True(parent.IsParentOf(child)); Assert.False(notchild.IsChildOf(parent)); Assert.False(parent.IsParentOf(notchild)); Assert.True(child.Neuter().IsChildOf(parent.Neuter())); Assert.True(parent.Neuter().IsParentOf(child.Neuter())); Assert.False(notchild.Neuter().IsChildOf(parent.Neuter())); Assert.False(parent.Neuter().IsParentOf(notchild.Neuter())); ExtPubKey keyA = parent.Neuter(); var keyB = new ExtPubKey(keyA.ToBytes()); AssertEx.CollectionEquals(keyA.ToBytes(), keyB.ToBytes()); }
public void CleanTransactions(ExtPubKey pubkey, List <TrackedTransaction> cleanList) { if (cleanList == null || cleanList.Count == 0) { return; } var tableName = $"T-{Hashes.Hash160(pubkey.ToBytes()).ToString()}"; using (var tx = _Engine.GetTransaction()) { foreach (var tracked in cleanList) { tx.RemoveKey(tableName, tracked.GetRowKey()); } tx.Commit(); } }
public void CreatePlatformKey(out byte[] key1, out byte[] key2) { var userExtKey = new ExtKey(); ExtPubKey pubkey = userExtKey.Neuter(); key1 = userExtKey.PrivateKey.ToBytes(); key2 = pubkey.ToBytes(); var userDerivationScheme = this.Network.DerivationStrategyFactory.CreateDirectDerivationStrategy(pubkey, new DerivationStrategyOptions() { // Use non-segwit Legacy = true }); //set the key to NBXplorer server this.NbxClient.Track(userDerivationScheme); }
private void Notify(ExtPubKey pubkey, bool log) { if (log) { Logs.Explorer.LogInformation($"A wallet received money"); } var key = Hashes.Hash160(pubkey.ToBytes()); lock (_WaitFor) { IReadOnlyCollection <Completion> completions; if (_WaitFor.TryGetValue(key, out completions)) { foreach (var completion in completions.ToList()) { completion.TrySetResult(true); } } } }
public void CanCheckChildKey() { var parent = new ExtKey(); var child = parent.Derive(1); var notchild = new ExtKey(); Assert.True(child.IsChildOf(parent)); Assert.True(parent.IsParentOf(child)); Assert.False(notchild.IsChildOf(parent)); Assert.False(parent.IsParentOf(notchild)); Assert.True(child.Neuter().IsChildOf(parent.Neuter())); Assert.True(parent.Neuter().IsParentOf(child.Neuter())); Assert.False(notchild.Neuter().IsChildOf(parent.Neuter())); Assert.False(parent.Neuter().IsParentOf(notchild.Neuter())); var keyA = parent.Neuter(); var keyB = new ExtPubKey(keyA.ToBytes()); AssertEx.CollectionEquals(keyA.ToBytes(), keyB.ToBytes()); }
public KeyInformation(ExtPubKey pubKey, KeyPath keyPath) { KeyPath = keyPath; RootKey = pubKey.ToBytes(); }