Class: BitcoinCigs::PrivateKey
- Inherits:
-
Object
- Object
- BitcoinCigs::PrivateKey
- Includes:
- CryptoHelper
- Defined in:
- lib/bitcoin_cigs/private_key.rb
Instance Attribute Summary collapse
-
#public_key ⇒ Object
Returns the value of attribute public_key.
-
#secret_multiplier ⇒ Object
Returns the value of attribute secret_multiplier.
Instance Method Summary collapse
-
#initialize(public_key, secret_multiplier) ⇒ PrivateKey
constructor
A new instance of PrivateKey.
- #sign(hash, random_k) ⇒ Object
Methods included from CryptoHelper
#decode58, #decode64, #decode_hex, #encode58, #encode64, #inverse_mod, #leftmost_bit, #ripemd160, #sha256, #sqrt_mod, #str_to_num
Constructor Details
#initialize(public_key, secret_multiplier) ⇒ PrivateKey
Returns a new instance of PrivateKey.
7 8 9 10 |
# File 'lib/bitcoin_cigs/private_key.rb', line 7 def initialize(public_key, secret_multiplier) self.public_key = public_key self.secret_multiplier = secret_multiplier end |
Instance Attribute Details
#public_key ⇒ Object
Returns the value of attribute public_key.
5 6 7 |
# File 'lib/bitcoin_cigs/private_key.rb', line 5 def public_key @public_key end |
#secret_multiplier ⇒ Object
Returns the value of attribute secret_multiplier.
5 6 7 |
# File 'lib/bitcoin_cigs/private_key.rb', line 5 def secret_multiplier @secret_multiplier end |
Instance Method Details
#sign(hash, random_k) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/bitcoin_cigs/private_key.rb', line 12 def sign(hash, random_k) hash = str_to_num(hash) if hash.is_a?(String) g = public_key.generator n = g.order k = random_k % n p1 = g * k r = p1.x raise raise ::BitcoinCigs::Error, "Random number r is 0" if r == 0 s = (inverse_mod(k, n) * (hash + (secret_multiplier * r) % n)) % n raise raise ::BitcoinCigs::Error, "Random number s is 0" if s == 0 Signature.new(r, s) end |