Class: IcAgent::AccountIdentifier
- Inherits:
-
Object
- Object
- IcAgent::AccountIdentifier
- Defined in:
- lib/ic_agent/principal.rb
Instance Attribute Summary collapse
-
#bytes ⇒ Object
readonly
Returns the value of attribute bytes.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hash) ⇒ AccountIdentifier
constructor
A new instance of AccountIdentifier.
- #to_s ⇒ Object
- #to_str ⇒ Object
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
#bytes ⇒ Object (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, sub_account = 0) sha224 = Digest::SHA224.new sha224 << "\naccount-id" sha224 << principal.bytes sub_account = [sub_account].pack('N') sha224 << sub_account hash = sha224.digest checksum = Zlib.crc32(hash) & 0xFFFFFFFF account = [checksum].pack('N') + hash AccountIdentifier.new(account) end |
Instance Method Details
#to_s ⇒ Object
96 97 98 |
# File 'lib/ic_agent/principal.rb', line 96 def to_s to_str end |
#to_str ⇒ Object
92 93 94 |
# File 'lib/ic_agent/principal.rb', line 92 def to_str '0x' + @bytes.unpack1('H*') end |