Class: Mastercoin::Util
- Inherits:
-
Object
- Object
- Mastercoin::Util
- Defined in:
- lib/mastercoin-ruby/util.rb
Class Method Summary collapse
- .get_sequence(bitcoin_address) ⇒ Object
- .multiple_hash(target, times = 1) ⇒ Object
- .sort_and_strip_keys(keys) ⇒ Object
- .sort_keys(public_keys) ⇒ Object
- .strip_key(key) ⇒ Object
- .valid_ecdsa_point?(pub_key) ⇒ Boolean
- .xor_pack_unpack_strings(s1, s2) ⇒ Object
Class Method Details
.get_sequence(bitcoin_address) ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/mastercoin-ruby/util.rb', line 42 def self.get_sequence(bitcoin_address) decoded = Bitcoin.decode_base58(bitcoin_address) seq = decoded[2..3].to_i(16) - 1 if seq < 0 seq += 256 end return seq end |
.multiple_hash(target, times = 1) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/mastercoin-ruby/util.rb', line 22 def self.multiple_hash(target, times = 1) times -= 1 new_target = Digest::SHA256.hexdigest(target).upcase if times > 0 return multiple_hash(new_target, times) end return new_target end |
.sort_and_strip_keys(keys) ⇒ Object
12 13 14 |
# File 'lib/mastercoin-ruby/util.rb', line 12 def self.sort_and_strip_keys(keys) Util.sort_keys(keys).collect{|key| Util.strip_key(key)} end |
.sort_keys(public_keys) ⇒ Object
3 4 5 |
# File 'lib/mastercoin-ruby/util.rb', line 3 def self.sort_keys(public_keys) public_keys.sort{|x,y| x[0..1] <=> y[0..1]} end |
.strip_key(key) ⇒ Object
7 8 9 |
# File 'lib/mastercoin-ruby/util.rb', line 7 def self.strip_key(key) return key[2..-1] end |
.valid_ecdsa_point?(pub_key) ⇒ Boolean
32 33 34 35 36 37 38 39 40 |
# File 'lib/mastercoin-ruby/util.rb', line 32 def self.valid_ecdsa_point?(pub_key) begin Bitcoin::Key.new(nil, pub_key).addr rescue OpenSSL::PKey::EC::Point::Error return false end return true end |
.xor_pack_unpack_strings(s1, s2) ⇒ Object
16 17 18 19 20 |
# File 'lib/mastercoin-ruby/util.rb', line 16 def self.xor_pack_unpack_strings(s1, s2) s1_bytes = [s1].pack("H*").unpack("C*") s2_bytes = [s2].pack("H*").unpack("C*") s1_bytes.zip(s2_bytes).map { |a, b| (a ^ b).to_s(16).rjust(2,"0") }.join end |