Class: IOTA::Models::Seed

Inherits:
Base
  • Object
show all
Defined in:
lib/iota/models/seed.rb

Instance Method Summary collapse

Methods inherited from Base

#inspect, #symbolize_keys

Constructor Details

#initialize(seed) ⇒ Seed


4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/iota/models/seed.rb', line 4

def initialize(seed)
  @utils = IOTA::Utils::Utils.new

  # Check if correct seed
  if seed.class == String && !@utils.validator.isTrytes(seed)
    raise StandardError, "Invalid seed provided"
  end

  seed += "9" * (81 - seed.length) if seed.length < 81

  @seed = seed
end

Instance Method Details

#as_tritsObject

Converter methods


28
29
30
# File 'lib/iota/models/seed.rb', line 28

def as_trits
  IOTA::Crypto::Converter.trits(@seed)
end

#getAddress(index, security, checksum) ⇒ Object


17
18
19
20
21
22
23
24
25
# File 'lib/iota/models/seed.rb', line 17

def getAddress(index, security, checksum)
  pk = IOTA::Crypto::PrivateKey.new(self.as_trits, index, security)
  address_trits = IOTA::Crypto::Signing.address(pk.digests)
  address = IOTA::Crypto::Converter.trytes(address_trits)

  address = @utils.addChecksum(address) if checksum

  address
end