public KzWalletJarvis(string passPhrase) { var m = KzExtPrivKey.Master(passPhrase, new[] { _kp_magic, _kp_protocol }); if (m == null) { throw new ArgumentException("This pass phrase cannot be used. Please generate another with at least 256 bits of entropy."); } _magic = m.Derive(_kp_magic).GetPubKey().ToHash160(); _protocolKey = m.Derive(_kp_protocol.Parent); _task = Task.Run(async() => await JarvisMain()); }
public void electrumsv_PubKey_without_custom_words() { var seed = "police off kit fee village rather kind when turn crowd fun that"; var customWords = (string)null; var pub = "xpub661MyMwAqRbcGAH5Lmmp6Tq7qtwnDfkJnMjz96AsLZTJZbHyGZe4CL792x3Eu1cNVt7BVXTAQWeQb2HBgrbcd3QZKc8M2UcX2tXy7RkLGXx"; var seedHash = "df4ec2782c76449989f780483b57775fc6ac66c2c274abc27566b5427875529881faf0aac27aea4b294ea27e5213a44f28f8ef4fae66cd070e76bd6a6adeb08f"; var iterations = 2048; var hash = KzHashes.pbkdf2_hmac_sha512(seed.UTF8ToBytes(), $"electrum{customWords}".UTF8ToBytes(), iterations); var key = KzExtPrivKey.Master(hash.Span); Assert.Equal(seedHash, hash.ToHex()); Assert.Equal(pub, key.GetExtPubKey().ToString()); Assert.Equal(key, KzElectrumSv.GetMasterPrivKey(seed)); }
public void electrumsv_PubKey_with_custom_words() { var seed = "bachelor nominee surprise visa oak negative anxiety observe catch sibling act hawk"; var customWords = "fred fruitbat"; var pub = "xpub661MyMwAqRbcH576xNa2EBv7NKLFqeGhwxqMVjLe7oKpQhdMEUjitTZzhEJRX2vAz8xn9x7V8vDhAJ87EoSgBoqNi5jCrdSrdwad6tb2trR"; var seedHash = "f53fcf294737ded129179824d437b9f393d00afddaabc58918e15cef9246bbdcbae20af66ae15420a66c2e7115b3066296dc3d9e893d3a41bff9fe47ca702f1d"; var iterations = 2048; var hash = KzHashes.pbkdf2_hmac_sha512(seed.UTF8ToBytes(), $"electrum{customWords}".UTF8ToBytes(), iterations); var key = KzExtPrivKey.Master(hash.Span); Assert.Equal(seedHash, hash.ToHex()); Assert.Equal(pub, key.GetExtPubKey().ToString()); Assert.Equal(key, KzElectrumSv.GetMasterPrivKey(seed, customWords)); }
public void TestCases() { foreach (var tv in tvs) { var seed = tv.m.HexToBytes(); var m = KzExtPrivKey.Master(seed); foreach (var d in tv.tds) { var path = new KzKeyPath(d.p); var priv = m.Derive(path); var pub = priv.GetExtPubKey(); var spriv = priv.ToString(); var spub = pub.ToString(); Assert.Equal(d.prv, spriv); Assert.Equal(d.pub, spub); var data = new byte[74]; priv.Encode(data); pub.Encode(data); // Test private key var b58key = new KzB58ExtPrivKey(); b58key.SetKey(priv); Assert.Equal(d.prv, b58key.ToString()); var b58keyDecodeCheck = new KzB58ExtPrivKey(d.prv); var checkKey = b58keyDecodeCheck.GetKey(); var eq = checkKey == priv; // ensure a base58 decoded pubkey also matches Assert.Equal(checkKey, priv); if (priv.Hardened == false && path.Parent != null) { // Compare with public derivation var pubkeyNew2 = m.Derive(path.Parent).GetExtPubKey().Derive((int)path.Indices.Last()); Assert.True(pubkeyNew2 != null); Assert.Equal(pub, pubkeyNew2); } } } }