Class: Zold::Prefixes

Inherits:
Object
  • Object
show all
Defined in:
lib/zold/prefixes.rb

Overview

Payment prefixes

Instance Method Summary collapse

Constructor Details

#initialize(wallet) ⇒ Prefixes

Returns a new instance of Prefixes.



33
34
35
# File 'lib/zold/prefixes.rb', line 33

def initialize(wallet)
  @wallet = wallet
end

Instance Method Details

#create(length = 8) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/zold/prefixes.rb', line 37

def create(length = 8)
  raise "Length #{length} is too small" if length < 8
  raise "Length #{length} is too big" if length > 32
  key = @wallet.key.to_pub
  prefix = ''
  rnd = Random.new
  until prefix =~ /^[a-zA-Z0-9]+$/
    start = rnd.rand(key.length - length)
    prefix = key[start..(start + length - 1)]
  end
  prefix
end