public async Task VerifyPubKey() { var r = new KzPaymailClient(); foreach (var tc in new [] { new { r = true, p = "*****@*****.**", k = "02c4aa80834a289b43870b56a6483c924b57650eebe6e5185b19258c76656baa35" }, new { r = true, p = "*****@*****.**", k = "02fe6a13c0734578b77d28680aac58a78eb1722dd654117451b8820c9380b10e68" }, new { r = true, p = "*****@*****.**", k = "02e36811b6a8db1593aa5cf97f91dd2211af1c38b9890567e58367945137dca8ef" }, new { r = false, p = "*****@*****.**", k = "02e36811b6a8db1593aa5cf97f91dd2211af1c38b9890567e58367945137dca8ef" }, new { r = false, p = "*****@*****.**", k = "02fe6a13c0734578b77d28680aac58a78eb1722dd654117451b8820c9380b10e68" }, }) { var pubkey = new KzPubKey(tc.k); var ok = await r.VerifyPubKey(tc.p, pubkey); if (tc.r) { Assert.True(ok); } else { Assert.False(ok); } } }
KzPubKey ValidatePubKey() { if (_pk == null) { _pk = DeriveNext(int.MaxValue, -1).k; } return(_pk); }
public KzBScriptSigP2PKH(KzPubKey pubKey) { IsPub = false; _TemplateId = KzScriptTemplateId.P2PKH; this .Push(new byte[72]) // This will become the CHECKSIG signature .Push(pubKey.Span) ; }
public KzBScriptSigP2PKH(KzPubKey pubKey) { IsPub = false; _type = KzBScriptType.P2PKH; this .Push() // This will become the CHECKSIG signature .Push(pubKey.Span) ; }
public void SignatureTest() { //var pk = await new KzPaymailClient().GetPubKey("*****@*****.**"); var pub = new KzPubKey("02e36811b6a8db1593aa5cf97f91dd2211af1c38b9890567e58367945137dca8ef"); var message = "[email protected]:55:57.562ZPayment with Money Button"; var signature = "H4Q8tvj632hXiirmiiDJkuUN9Z20zDu3KaFuwY8cInZiLhgVJKJdKrZx1RZN06E/AARnFX7Fn618OUBQigCis4M="; var ok = pub.VerifyMessage(message, signature); Assert.True(ok); }
public static KzBTxOut ToP2PKH(KzPubKey pubKey, KzAmount value) { var pub = KzBScript.NewPubP2PKH(pubKey.ToHash160()); var r = new KzBTxOut { Value = value, ScriptPub = pub, PubKey = pubKey }; return(r); }
public void Decode() { foreach (var hex in new [] { "76a914c2eaba3b9c29575322c6e24fdc1b49bdfe405bad88ac", "4730440220327588eb1c9e502358142b67b3cd799cb6163fde4f1a92490affda78734bc63c0220639a29e63d78c971177a1792cec1b0a7e65c973edbf03eba3b3380d97b829f80412103ea03d07638e40b53d8098b62e964112f562af5ba1bffaa146ffd9e7f7d1a5c67", "6a22314c74794d45366235416e4d6f70517242504c6b3446474e3855427568784b71726e0101337b2274223a32302e36322c2268223a35392c2270223a313031322c2263223a312c227773223a362e322c227764223a3236307d22314a6d64484e4456336f6434796e614c7635696b4d6234616f763737507a665169580a31353537303838383133" }) { var sb = new KzScript(hex); var s = sb.ToString(); } var address = new KzPubKey(true); var e = new KzUInt160("c2eaba3b9c29575322c6e24fdc1b49bdfe405bad", true); var s1 = KzEncoders.B58Check.Encode(Kz.PUBKEY_ADDRESS, e.ReadOnlySpan); var s2 = KzEncoders.B58Check.Encode(Kz.SCRIPT_ADDRESS, e.ReadOnlySpan); //e.Span.CopyTo(address.Span); //var id = address.GetID(); }
public async Task GetPubKey() { var r = new KzPaymailClient(); foreach (var tc in new [] { new { p = "*****@*****.**", k = "02c4aa80834a289b43870b56a6483c924b57650eebe6e5185b19258c76656baa35" }, new { p = "*****@*****.**", k = "02fe6a13c0734578b77d28680aac58a78eb1722dd654117451b8820c9380b10e68" }, new { p = "*****@*****.**", k = "02e36811b6a8db1593aa5cf97f91dd2211af1c38b9890567e58367945137dca8ef" }, }) { //var privkey = KzElectrumSv.GetMasterPrivKey("<replace with actual wallet seed>").Derive($"0/{int.MaxValue}").PrivKey; //var privkey = KzPrivKey.FromB58("KxXvocKqZtdHvZP5HHNShrwDQVz2muNPisrzoyeyhXc4tZhBj1nM"); //var pubkey = privkey.GetPubKey(); var pubkey = new KzPubKey(tc.k); var k = await r.GetPubKey(tc.p); Assert.Equal(k, pubkey); } }
public void KzB58PrivKeyTests() { var bsecret1 = new KzB58PrivKey(); var bsecret2 = new KzB58PrivKey(); var bsecret1C = new KzB58PrivKey(); var bsecret2C = new KzB58PrivKey(); var baddress1 = new KzB58PrivKey(); Assert.True(bsecret1.SetString(strSecret1)); Assert.True(bsecret2.SetString(strSecret2)); Assert.True(bsecret1C.SetString(strSecret1C)); Assert.True(bsecret2C.SetString(strSecret2C)); Assert.False(baddress1.SetString(strAddressBad)); var key1 = bsecret1.GetKey(); Assert.False(key1.IsCompressed); var key2 = bsecret2.GetKey(); Assert.False(key2.IsCompressed); var key1C = bsecret1C.GetKey(); Assert.True(key1C.IsCompressed); var key2C = bsecret2C.GetKey(); Assert.True(key2C.IsCompressed); var pubkey1 = key1.GetPubKey(); var pubkey2 = key2.GetPubKey(); var pubkey1C = key1C.GetPubKey(); var pubkey2C = key2C.GetPubKey(); var a = pubkey1.ToAddress(); Assert.True(key1.VerifyPubKey(pubkey1)); Assert.False(key1.VerifyPubKey(pubkey1C)); Assert.False(key1.VerifyPubKey(pubkey2)); Assert.False(key1.VerifyPubKey(pubkey2C)); Assert.False(key1C.VerifyPubKey(pubkey1)); Assert.True(key1C.VerifyPubKey(pubkey1C)); Assert.False(key1C.VerifyPubKey(pubkey2)); Assert.False(key1C.VerifyPubKey(pubkey2C)); Assert.False(key2.VerifyPubKey(pubkey1)); Assert.False(key2.VerifyPubKey(pubkey1C)); Assert.True(key2.VerifyPubKey(pubkey2)); Assert.False(key2.VerifyPubKey(pubkey2C)); Assert.False(key2C.VerifyPubKey(pubkey1)); Assert.False(key2C.VerifyPubKey(pubkey1C)); Assert.False(key2C.VerifyPubKey(pubkey2)); Assert.True(key2C.VerifyPubKey(pubkey2C)); for (var n = 0; n < 16; n++) { var strMsg = $"Very secret message {n}: 11"; var hashMsg = KzHashes.HASH256(Encoding.ASCII.GetBytes(strMsg)); // normal signatures var(ok1, sign1) = key1.Sign(hashMsg); var(ok1C, sign1C) = key1C.Sign(hashMsg); var(ok2, sign2) = key2.Sign(hashMsg); var(ok2C, sign2C) = key2C.Sign(hashMsg); Assert.True(ok1 && ok1C && ok2 && ok2C); Assert.True(pubkey1.Verify(hashMsg, sign1)); Assert.True(pubkey1.Verify(hashMsg, sign1C)); Assert.False(pubkey1.Verify(hashMsg, sign2)); Assert.False(pubkey1.Verify(hashMsg, sign2C)); Assert.True(pubkey1C.Verify(hashMsg, sign1)); Assert.True(pubkey1C.Verify(hashMsg, sign1C)); Assert.False(pubkey1C.Verify(hashMsg, sign2)); Assert.False(pubkey1C.Verify(hashMsg, sign2C)); Assert.False(pubkey2.Verify(hashMsg, sign1)); Assert.False(pubkey2.Verify(hashMsg, sign1C)); Assert.True(pubkey2.Verify(hashMsg, sign2)); Assert.True(pubkey2.Verify(hashMsg, sign2C)); Assert.False(pubkey2C.Verify(hashMsg, sign1)); Assert.False(pubkey2C.Verify(hashMsg, sign1C)); Assert.True(pubkey2C.Verify(hashMsg, sign2)); Assert.True(pubkey2C.Verify(hashMsg, sign2C)); // compact signatures (with key recovery) var(cok1, csign1) = key1.SignCompact(hashMsg); var(cok1C, csign1C) = key1C.SignCompact(hashMsg); var(cok2, csign2) = key2.SignCompact(hashMsg); var(cok2C, csign2C) = key2C.SignCompact(hashMsg); Assert.True(cok1 && cok1C && cok2 && cok2C); var(rok1, rkey1) = KzPubKey.FromRecoverCompact(hashMsg, csign1); var(rok2, rkey2) = KzPubKey.FromRecoverCompact(hashMsg, csign2); var(rok1C, rkey1C) = KzPubKey.FromRecoverCompact(hashMsg, csign1C); var(rok2C, rkey2C) = KzPubKey.FromRecoverCompact(hashMsg, csign2C); Assert.True(rok1 && rok2 && rok1C && rok2C); Assert.True(rkey1 == pubkey1); Assert.True(rkey2 == pubkey2); Assert.True(rkey1C == pubkey1C); Assert.True(rkey2C == pubkey2C); } }