Class: IcAgent::DelegateIdentity

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identity, delegation) ⇒ DelegateIdentity

Returns a new instance of DelegateIdentity.



95
96
97
98
99
# File 'lib/ic_agent/identity.rb', line 95

def initialize(identity, delegation)
  @identity = identity
  @delegations = delegation['delegations'].map { |d| d }
  @der_pubkey = [delegation['publicKey']].pack('H*')
end

Instance Attribute Details

#delegationsObject (readonly)

Returns the value of attribute delegations.



93
94
95
# File 'lib/ic_agent/identity.rb', line 93

def delegations
  @delegations
end

#der_pubkeyObject (readonly)

Returns the value of attribute der_pubkey.



93
94
95
# File 'lib/ic_agent/identity.rb', line 93

def der_pubkey
  @der_pubkey
end

#identityObject (readonly)

Returns the value of attribute identity.



93
94
95
# File 'lib/ic_agent/identity.rb', line 93

def identity
  @identity
end

Class Method Details

.from_json(ic_identity, ic_delegation) ⇒ Object



109
110
111
112
113
114
115
116
117
# File 'lib/ic_agent/identity.rb', line 109

def self.from_json(ic_identity, ic_delegation)
  parsed_ic_identity = JSON.parse(ic_identity)
  parsed_ic_delegation = JSON.parse(ic_delegation)

  DelegateIdentity.new(
    Identity.new(parsed_ic_identity[1][0...64]),
    parsed_ic_delegation
  )
end

Instance Method Details

#senderObject



105
106
107
# File 'lib/ic_agent/identity.rb', line 105

def sender
  Principal.self_authenticating(@der_pubkey)
end

#sign(msg) ⇒ Object



101
102
103
# File 'lib/ic_agent/identity.rb', line 101

def sign(msg)
  @identity.sign(msg)
end

#to_sObject Also known as: inspect



119
120
121
# File 'lib/ic_agent/identity.rb', line 119

def to_s
  "(#{@identity.to_s},\n#{@delegations.to_s})"
end