Module: BTC::StringExtensions

Included in:
String
Defined in:
lib/btcruby/extensions.rb

Instance Method Summary collapse

Instance Method Details

#from_hexObject

Converts hex string into a binary data



21
22
23
# File 'lib/btcruby/extensions.rb', line 21

def from_hex
  BTC.from_hex(self)
end

#from_wifObject

Decodes string in WIF format into a binary private key (32 bytes)



10
11
12
13
# File 'lib/btcruby/extensions.rb', line 10

def from_wif
  addr = BTC::WIF.new(string: self)
  addr ? addr.private_key : nil
end

#hash160Object



30
31
32
# File 'lib/btcruby/extensions.rb', line 30

def hash160
  BTC.hash160(self)
end

#hash256Object

Various hash functions



26
27
28
# File 'lib/btcruby/extensions.rb', line 26

def hash256
  BTC.hash256(self)
end

#ripemd160Object



38
39
40
# File 'lib/btcruby/extensions.rb', line 38

def ripemd160
  BTC.ripemd160(self)
end

#sha1Object



34
35
36
# File 'lib/btcruby/extensions.rb', line 34

def sha1
  BTC.sha1(self)
end

#sha256Object



42
43
44
# File 'lib/btcruby/extensions.rb', line 42

def sha256
  BTC.sha256(self)
end

#sha512Object



46
47
48
# File 'lib/btcruby/extensions.rb', line 46

def sha512
  BTC.sha512(self)
end

#to_hexObject

Converts binary data into hex string



16
17
18
# File 'lib/btcruby/extensions.rb', line 16

def to_hex
  BTC.to_hex(self)
end

#to_wif(network: nil, public_key_compressed: nil) ⇒ Object

Converts binary string as a private key to a WIF Base58 format.



5
6
7
# File 'lib/btcruby/extensions.rb', line 5

def to_wif(network: nil, public_key_compressed: nil)
  BTC::WIF.new(private_key: self, network: network, public_key_compressed: public_key_compressed).to_s
end