public void CanUseKeyPath() { var keyPath = KeyPath.Parse("0/1/2/3"); Assert.Equal(keyPath.ToString(), "0/1/2/3"); var key = new ExtKey(); Assert.Equal(key .Derive(0) .Derive(1) .Derive(2) .Derive(3) .ToString(Network.Main), key.Derive(keyPath).ToString(Network.Main)); var neuter = key.Neuter(); Assert.Equal(neuter .Derive(0) .Derive(1) .Derive(2) .Derive(3) .ToString(Network.Main), neuter.Derive(keyPath).ToString(Network.Main)); Assert.Equal(neuter.Derive(keyPath).ToString(Network.Main), key.Derive(keyPath).Neuter().ToString(Network.Main)); keyPath = new KeyPath(0x8000002Cu, 1u); Assert.Equal(keyPath.ToString(), "44'/1"); keyPath = KeyPath.Parse("44'/1"); Assert.False(keyPath.IsHardened); Assert.True(KeyPath.Parse("44'/1'").IsHardened); Assert.Equal(keyPath[0], 0x8000002Cu); Assert.Equal(keyPath[1], 1u); key = new ExtKey(); Assert.Equal(key.Derive(keyPath).ToString(Network.Main), key.Derive(44, true).Derive(1, false).ToString(Network.Main)); keyPath = KeyPath.Parse(""); keyPath = keyPath.Derive(44, true).Derive(1, false); Assert.Equal(keyPath.ToString(), "44'/1"); Assert.Equal(keyPath.Increment().ToString(), "44'/2"); Assert.Equal(keyPath.Derive(1, true).Increment().ToString(), "44'/1/2'"); Assert.Equal(keyPath.Parent.ToString(), "44'"); Assert.Equal(keyPath.Parent.Parent.ToString(), ""); Assert.Equal(keyPath.Parent.Parent.Parent, null); Assert.Equal(keyPath.Parent.Parent.Increment(), null); Assert.Equal(key.Derive(keyPath).ToString(Network.Main), key.Derive(44, true).Derive(1, false).ToString(Network.Main)); Assert.True(key.Derive(44, true).IsHardened); Assert.False(key.Derive(44, false).IsHardened); neuter = key.Derive(44, true).Neuter(); Assert.True(neuter.IsHardened); neuter = key.Derive(44, false).Neuter(); Assert.False(neuter.IsHardened); }
public void CanUseKeyPath() { var keyPath = KeyPath.Parse("0/1/2/3"); Assert.Equal("0/1/2/3", keyPath.ToString()); var key = new ExtKey(); Assert.Equal(key .Derive(0) .Derive(1) .Derive(2) .Derive(3) .ToString(Network.PurpleMain), key.Derive(keyPath).ToString(Network.PurpleMain)); var neuter = key.Neuter(); Assert.Equal(neuter .Derive(0) .Derive(1) .Derive(2) .Derive(3) .ToString(Network.PurpleMain), neuter.Derive(keyPath).ToString(Network.PurpleMain)); Assert.Equal(neuter.Derive(keyPath).ToString(Network.PurpleMain), key.Derive(keyPath).Neuter().ToString(Network.PurpleMain)); keyPath = new KeyPath(new uint[] { 0x8000002Cu, 1u }); Assert.Equal("44'/1", keyPath.ToString()); keyPath = KeyPath.Parse("44'/1"); Assert.False(keyPath.IsHardened); Assert.True(KeyPath.Parse("44'/1'").IsHardened); Assert.Equal(0x8000002Cu, keyPath[0]); Assert.Equal(1u, keyPath[1]); key = new ExtKey(); Assert.Equal(key.Derive(keyPath).ToString(Network.PurpleMain), key.Derive(44, true).Derive(1, false).ToString(Network.PurpleMain)); keyPath = KeyPath.Parse(""); keyPath = keyPath.Derive(44, true).Derive(1, false); Assert.Equal("44'/1", keyPath.ToString()); Assert.Equal("44'/2", keyPath.Increment().ToString()); Assert.Equal("44'/1/2'", keyPath.Derive(1, true).Increment().ToString()); Assert.Equal("44'", keyPath.Parent.ToString()); Assert.Equal("", keyPath.Parent.Parent.ToString()); Assert.Null(keyPath.Parent.Parent.Parent); Assert.Null(keyPath.Parent.Parent.Increment()); Assert.Equal(key.Derive(keyPath).ToString(Network.PurpleMain), key.Derive(44, true).Derive(1, false).ToString(Network.PurpleMain)); Assert.True(key.Derive(44, true).IsHardened); Assert.False(key.Derive(44, false).IsHardened); neuter = key.Derive(44, true).Neuter(); Assert.True(neuter.IsHardened); neuter = key.Derive(44, false).Neuter(); Assert.False(neuter.IsHardened); }
public SyncWallet(WalletSettings settings, Network network) { _masterPrivKey = ExtKey.Parse(settings.MasterPrivKey); _masterPubKey = _masterPrivKey.Neuter(); _keyPath = settings.KeyPath ?? new KeyPath("0/0"); _curPath = new KeyPath(_keyPath.Indexes); for (var index = 0; index < 1; index++) { var pubkey = _masterPubKey.Derive(_curPath).PubKey; var address = new SyncAddress(pubkey, _curPath, network); _addresses.Add(address); _curPath = _curPath.Increment(); } //_keyPath.Increment(); }
public void CanUseKeyPath() { var keyPath = KeyPath.Parse("0/1/2/3"); Assert.Equal("0/1/2/3", keyPath.ToString()); var key = new ExtKey(); Assert.Equal(key .Derive(0) .Derive(1) .Derive(2) .Derive(3) .ToString(Network.Main), key.Derive(keyPath).ToString(Network.Main)); var neuter = key.Neuter(); Assert.Equal(neuter .Derive(0) .Derive(1) .Derive(2) .Derive(3) .ToString(Network.Main), neuter.Derive(keyPath).ToString(Network.Main)); Assert.Equal(neuter.Derive(keyPath).ToString(Network.Main), key.Derive(keyPath).Neuter().ToString(Network.Main)); keyPath = new KeyPath(new uint[] { 0x8000002Cu, 1u }); Assert.Equal("44'/1", keyPath.ToString()); keyPath = KeyPath.Parse("44'/1"); Assert.False(keyPath.IsHardened); Assert.True(KeyPath.Parse("44'/1'").IsHardened); Assert.Equal(0x8000002Cu, keyPath[0]); Assert.Equal(1u, keyPath[1]); key = new ExtKey(); Assert.Equal(key.Derive(keyPath).ToString(Network.Main), key.Derive(44, true).Derive(1, false).ToString(Network.Main)); keyPath = KeyPath.Parse(""); keyPath = keyPath.Derive(44, true).Derive(1, false); Assert.Equal("44'/1", keyPath.ToString()); Assert.Equal("44'/2", keyPath.Increment().ToString()); Assert.Equal("44'/1/2'", keyPath.Derive(1, true).Increment().ToString()); Assert.Equal("44'", keyPath.Parent.ToString()); Assert.Equal("", keyPath.Parent.Parent.ToString()); Assert.Null(keyPath.Parent.Parent.Parent); Assert.Throws <InvalidOperationException>(() => keyPath.Parent.Parent.Increment()); Assert.Equal(key.Derive(keyPath).ToString(Network.Main), key.Derive(44, true).Derive(1, false).ToString(Network.Main)); Assert.True(key.Derive(44, true).IsHardened); Assert.False(key.Derive(44, false).IsHardened); neuter = key.Derive(44, true).Neuter(); Assert.True(neuter.IsHardened); neuter = key.Derive(44, false).Neuter(); Assert.False(neuter.IsHardened); KeyPath a = new KeyPath("3/2"); KeyPath b = new KeyPath("5/6"); Assert.Equal(new KeyPath("3/2/5/6"), a + b); b = null; Assert.Equal(a, a + b); a = null; Assert.Null(a + b); b = new KeyPath("5/6"); Assert.Equal(new KeyPath("5/6"), a + b); a += new KeyPath("3/2"); a += new KeyPath("5/6"); Assert.Equal(new KeyPath("3/2/5/6"), a); }
public void CanUseKeyPath() { var keyPath = KeyPath.Parse("0/1/2/3"); Assert.Equal(keyPath.ToString(), "0/1/2/3"); var key = new ExtKey(); Assert.Equal(key .Derive(0) .Derive(1) .Derive(2) .Derive(3) .ToString(Network.Main), key.Derive(keyPath).ToString(Network.Main)); var neuter = key.Neuter(); Assert.Equal(neuter .Derive(0) .Derive(1) .Derive(2) .Derive(3) .ToString(Network.Main), neuter.Derive(keyPath).ToString(Network.Main)); Assert.Equal(neuter.Derive(keyPath).ToString(Network.Main), key.Derive(keyPath).Neuter().ToString(Network.Main)); keyPath = new KeyPath(new uint[] { 0x8000002Cu, 1u }); Assert.Equal(keyPath.ToString(), "44'/1"); keyPath = KeyPath.Parse("44'/1"); Assert.False(keyPath.IsHardened); Assert.True(KeyPath.Parse("44'/1'").IsHardened); Assert.Equal(keyPath[0], 0x8000002Cu); Assert.Equal(keyPath[1], 1u); key = new ExtKey(); Assert.Equal(key.Derive(keyPath).ToString(Network.Main), key.Derive(44, true).Derive(1, false).ToString(Network.Main)); keyPath = KeyPath.Parse(""); keyPath = keyPath.Derive(44, true).Derive(1, false); Assert.Equal(keyPath.ToString(), "44'/1"); Assert.Equal(keyPath.Increment().ToString(), "44'/2"); Assert.Equal(keyPath.Derive(1,true).Increment().ToString(), "44'/1/2'"); Assert.Equal(keyPath.Parent.ToString(), "44'"); Assert.Equal(keyPath.Parent.Parent.ToString(), ""); Assert.Equal(keyPath.Parent.Parent.Parent, null); Assert.Equal(keyPath.Parent.Parent.Increment(), null); Assert.Equal(key.Derive(keyPath).ToString(Network.Main), key.Derive(44, true).Derive(1, false).ToString(Network.Main)); Assert.True(key.Derive(44, true).IsHardened); Assert.False(key.Derive(44, false).IsHardened); neuter = key.Derive(44, true).Neuter(); Assert.True(neuter.IsHardened); neuter = key.Derive(44, false).Neuter(); Assert.False(neuter.IsHardened); }