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

Initializes a new instance of the DelegateIdentity class.

Parameters:

  • identity: The Identity associated with the DelegateIdentity.

  • delegation: The delegation JSON object containing the delegated keys.



131
132
133
134
135
# File 'lib/ic_agent/identity.rb', line 131

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.



124
125
126
# File 'lib/ic_agent/identity.rb', line 124

def delegations
  @delegations
end

#der_pubkeyObject (readonly)

Returns the value of attribute der_pubkey.



124
125
126
# File 'lib/ic_agent/identity.rb', line 124

def der_pubkey
  @der_pubkey
end

#identityObject (readonly)

Returns the value of attribute identity.



124
125
126
# File 'lib/ic_agent/identity.rb', line 124

def identity
  @identity
end

Class Method Details

.from_json(ic_identity, ic_delegation) ⇒ Object

Creates a new DelegateIdentity instance from JSON representations of the Identity and delegation.

Parameters:

  • ic_identity: The JSON representation of the Identity.

  • ic_delegation: The JSON representation of the delegation.

Returns: The DelegateIdentity instance.



161
162
163
164
165
166
167
168
169
# File 'lib/ic_agent/identity.rb', line 161

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

Returns the sender Principal associated with the DelegateIdentity.

Returns: The sender Principal.



150
151
152
# File 'lib/ic_agent/identity.rb', line 150

def sender
  Principal.self_authenticating(@der_pubkey)
end

#sign(msg) ⇒ Object

Signs a message using the DelegateIdentity.

Parameters:

  • msg: The message to sign.

Returns: An array containing the DER-encoded public key and the signature.



143
144
145
# File 'lib/ic_agent/identity.rb', line 143

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

#to_sObject Also known as: inspect



171
172
173
# File 'lib/ic_agent/identity.rb', line 171

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