lib/bitcoin/key.rb in bitcoin-ruby-0.0.7 vs lib/bitcoin/key.rb in bitcoin-ruby-0.0.8
- old
+ new
@@ -3,10 +3,12 @@
module Bitcoin
# Elliptic Curve key as used in bitcoin.
class Key
+ attr_reader :key
+
# Generate a new keypair.
# Bitcoin::Key.generate
def self.generate(opts={compressed: true})
k = new(nil, nil, opts); k.generate; k
end
@@ -52,10 +54,11 @@
end
# Set the private key to +priv+ (in hex).
def priv= priv
set_priv(priv)
+ regenerate_pubkey
end
# Get the public key (in hex).
# In case the key was initialized with only
# a private key, the public key is regenerated.
@@ -96,15 +99,10 @@
# Sign +data+ with the key.
# key1 = Bitcoin::Key.generate
# sig = key1.sign("some data")
def sign(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
+ Bitcoin.sign_data(key, data)
end
# Verify signature +sig+ for +data+.
# key2 = Bitcoin::Key.new(nil, key1.pub)
# key2.verify("some data", sig)