spec/bitcoin/secp256k1_spec.rb in bitcoin-ruby-0.0.9 vs spec/bitcoin/secp256k1_spec.rb in bitcoin-ruby-0.0.10

- old
+ new

@@ -25,10 +25,11 @@ it 'sign and verify' do priv, pub = Bitcoin::Secp256k1.generate_key_pair signature = Bitcoin::Secp256k1.sign("derp", priv) Bitcoin::Secp256k1.verify("derp", signature, pub).should == true + Bitcoin::Secp256k1.verify("DERP", signature, pub).should == true end it 'sign compact and recover' do priv, pub = Bitcoin::Secp256k1.generate_key_pair(compressed=true) signature = Bitcoin::Secp256k1.sign_compact("derp", priv, compressed=true) @@ -49,8 +50,29 @@ it 'deterministic signature using rfc6979' do priv, pub = Bitcoin::Secp256k1.generate_key_pair first = Bitcoin::Secp256k1.sign("derp", priv) second = Bitcoin::Secp256k1.sign("derp", priv) first.should == second + + priv, pub = Bitcoin::Secp256k1.generate_key_pair + second = Bitcoin::Secp256k1.sign("derp", priv) + first.should != second + end + + it 'openssl vs Secp256k1' do + k = Bitcoin::Key.new("82a0c421a0f67c7a88a329b2c15f2849aa1c8cfa9c9a6513f056f80ee8eaacc4", nil, compresed=false); k.pub + k.pub.should == "0490b0854581a291b83c1945775f156da22445df99e445581321ac3aa62535ff369334316dfd157acc7bb2e4d3eb85951f6d1b7f62f6f60a09e0dbd5c87d3ffae9" + + message = "hello world" + priv = [k.priv].pack("H*") + + sig1 = Bitcoin::OpenSSL_EC.sign_compact(message, priv, nil, compressed=false) + sig2 = Bitcoin::Secp256k1.sign_compact(message, priv, compressed=false) + + Bitcoin::OpenSSL_EC.recover_compact(message, sig1).should == k.pub + Bitcoin::Secp256k1.recover_compact(message, sig1).unpack("H*")[0].should == k.pub + + Bitcoin::OpenSSL_EC.recover_compact(message, sig2).should == k.pub + Bitcoin::Secp256k1.recover_compact(message, sig2).unpack("H*")[0] == k.pub end end