Class: IcAgent::AccountIdentifier

Inherits:
Object
  • Object
show all
Defined in:
lib/ic_agent/principal.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ AccountIdentifier

Returns a new instance of AccountIdentifier.



86
87
88
89
90
# File 'lib/ic_agent/principal.rb', line 86

def initialize(hash)
  raise 'Invalid hash length' unless hash.length == 32

  @bytes = hash
end

Instance Attribute Details

#bytesObject (readonly)

Returns the value of attribute bytes.



84
85
86
# File 'lib/ic_agent/principal.rb', line 84

def bytes
  @bytes
end

Class Method Details

.new(principal, sub_account = 0) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
# File 'lib/ic_agent/principal.rb', line 100

def self.new(principal,  = 0)
  sha224 = Digest::SHA224.new
  sha224 << "\naccount-id"
  sha224 << principal.bytes
   = [].pack('N')
  sha224 << 
  hash = sha224.digest
  checksum = Zlib.crc32(hash) & 0xFFFFFFFF
   = [checksum].pack('N') + hash
  AccountIdentifier.new()
end

Instance Method Details

#to_sObject



96
97
98
# File 'lib/ic_agent/principal.rb', line 96

def to_s
  to_str
end

#to_strObject



92
93
94
# File 'lib/ic_agent/principal.rb', line 92

def to_str
  '0x' + @bytes.unpack1('H*')
end