lib/bitcoin/key.rb in bitcoin-ruby-0.0.6 vs lib/bitcoin/key.rb in bitcoin-ruby-0.0.7
- old
+ new
@@ -96,18 +96,28 @@
# Sign +data+ with the key.
# key1 = Bitcoin::Key.generate
# sig = key1.sign("some data")
def sign(data)
- @key.dsa_sign_asn1(data)
+ sig = @key.dsa_sign_asn1(data)
+ if Script::is_low_der_signature?(sig)
+ sig
+ else
+ Bitcoin::OpenSSL_EC.signature_to_low_s(sig)
+ end
end
# Verify signature +sig+ for +data+.
# key2 = Bitcoin::Key.new(nil, key1.pub)
# key2.verify("some data", sig)
def verify(data, sig)
regenerate_pubkey unless @key.public_key
- @key.dsa_verify_asn1(data, sig)
+ sig = Bitcoin::OpenSSL_EC.repack_der_signature(sig)
+ if sig
+ @key.dsa_verify_asn1(data, sig)
+ else
+ false
+ end
end
def sign_message(message)
Bitcoin.sign_message(priv, pub, message)['signature']