Sha256: 3005c59456ae7b191ac2f8373711f4d4dcf7e758894212b5f4fbf3c669facfa6

Contents?: true

Size: 1.21 KB

Versions: 7

Compression:

Stored size: 1.21 KB

Contents

module Mastercoin
  class Util
    def self.sort_keys(public_keys)
      public_keys.sort{|x,y| x[0..1] <=> y[0..1]}
    end

    def self.strip_key(key)
      return key[2..-1]
    end


    def self.sort_and_strip_keys(keys)
      Util.sort_keys(keys).collect{|key| Util.strip_key(key)}
    end

    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

    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

    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

    def self.get_sequence(bitcoin_address, encoding = false)
      decoded = Bitcoin.decode_base58(bitcoin_address)
      seq = decoded[2..3].to_i(16)

      if encoding
         seq -= 1
      end

      if seq < 0
        seq += 256
      end

      return seq
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
mastercoin-ruby-0.2.9 lib/mastercoin-ruby/util.rb
mastercoin-ruby-0.2.8 lib/mastercoin-ruby/util.rb
mastercoin-ruby-0.2.7 lib/mastercoin-ruby/util.rb
mastercoin-ruby-0.2.6 lib/mastercoin-ruby/util.rb
mastercoin-ruby-0.2.5 lib/mastercoin-ruby/util.rb
mastercoin-ruby-0.2.4 lib/mastercoin-ruby/util.rb
mastercoin-ruby-0.2.3 lib/mastercoin-ruby/util.rb