Class: IOTA::Multisig::Address

Inherits:
Object
  • Object
show all
Defined in:
lib/iota/multisig/address.rb

Instance Method Summary collapse

Constructor Details

#initialize(digests = nil) ⇒ Address

Returns a new instance of Address.



4
5
6
7
8
9
10
# File 'lib/iota/multisig/address.rb', line 4

def initialize(digests = nil)
  # Initialize kerl instance
  @kerl = IOTA::Crypto::Kerl.new

  # Add digests if passed
  absorb(digests) if digests
end

Instance Method Details

#absorb(digest) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/iota/multisig/address.rb', line 12

def absorb(digest)
  # Construct array
  digests = digest.class == Array ? digest : [digest]

  # Add digests
  digests.each do |d|
    # Get trits of digest
    digestTrits = IOTA::Crypto::Converter.trits(d)

    # Absorb
    @kerl.absorb(digestTrits, 0, digestTrits.length)
  end

  self
end

#finalize(digest = nil) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/iota/multisig/address.rb', line 28

def finalize(digest = nil)
  # Absorb last digest if passed
  absorb(digest) if digest

  # Squeeze the address trits
  addressTrits = []
  @kerl.squeeze(addressTrits, 0, IOTA::Crypto::Kerl::HASH_LENGTH)

  # Convert trits into trytes and return the address
  IOTA::Crypto::Converter.trytes(addressTrits)
end