Class: Bitcoin::Key

Inherits:
Object
  • Object
show all
Defined in:
lib/coin-op/bit.rb

Instance Method Summary collapse

Instance Method Details

#sign(data) ⇒ Object

Sign data with the key.

key1 = Bitcoin::Key.generate
sig = key1.sign("some data")


167
168
169
170
171
172
173
174
# File 'lib/coin-op/bit.rb', line 167

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
end

#verify(data, sig) ⇒ Object

Verify signature sig for data.

key2 = Bitcoin::Key.new(nil, key1.pub)
key2.verify("some data", sig)


179
180
181
182
183
184
185
186
187
# File 'lib/coin-op/bit.rb', line 179

def verify(data, sig)
  regenerate_pubkey unless @key.public_key
  sig = Bitcoin::OpenSSL_EC.repack_der_signature(sig)
  if sig
    @key.dsa_verify_asn1(data, sig)
  else
    false
  end
end