class SelfSDK::Messages::FactResponse

Constants

MSG_TYPE

Attributes

audience[RW]
facts[RW]

Public Instance Methods

attestation_values_for(name) click to toggle source
# File lib/messages/fact_response.rb, line 55
def attestation_values_for(name)
  a = attestations_for(name)
  a.map{|a| a.value}
end
attestations_for(name) click to toggle source
# File lib/messages/fact_response.rb, line 49
def attestations_for(name)
  f = fact(name)
  return [] if f.nil?
  f.attestations
end
body() click to toggle source
# File lib/messages/fact_response.rb, line 67
def body
  encoded_facts = []
  @facts.each do |fact|
    encoded_facts.push(fact.to_hash)
  end
  
  { typ: MSG_TYPE,
    iss: @jwt.id,
    sub: @sub || @to,
    aud: @audience,
    iat: SelfSDK::Time.now.strftime('%FT%TZ'),
    exp: (SelfSDK::Time.now + 3600).strftime('%FT%TZ'),
    cid: @id,
    jti: SecureRandom.uuid,
    status: @status,
    facts: encoded_facts }        
end
fact(name) click to toggle source
# File lib/messages/fact_response.rb, line 44
def fact(name)
  name = SelfSDK::fact_name(name)
  @facts.select{|f| f.name == name}.first
end
parse(input, envelope=nil) click to toggle source
# File lib/messages/fact_response.rb, line 16
def parse(input, envelope=nil)
  @input = input
  @typ = MSG_TYPE
  @payload = get_payload input
  @id = payload[:cid]
  @from = payload[:iss]
  @to = payload[:sub]
  @expires = ::Time.parse(payload[:exp])
  @issued = ::Time.parse(payload[:iat])
  @audience = payload[:aud]
  @status = payload[:status]
  @facts = []
  payload[:facts] = [] if payload[:facts].nil?
  payload[:facts].each do |f|
    begin
      fact = SelfSDK::Messages::Fact.new(@messaging)
      fact.parse(f)
      @facts.push(fact)
    rescue StandardError => e
      SelfSDK.logger.info e.message
    end
  end
  if envelope
    issuer = envelope.sender.split(":")
    @from_device = issuer.last
  end
end
validate!(original) click to toggle source
Calls superclass method SelfSDK::Messages::Base#validate!
# File lib/messages/fact_response.rb, line 60
def validate!(original)
  super
  @facts.each do |f|
    f.validate! original
  end
end

Protected Instance Methods

proto(to_device) click to toggle source
# File lib/messages/fact_response.rb, line 87
def proto(to_device)
  @to_device = to_device
  Msgproto::Message.new(
    type: Msgproto::MsgType::MSG,
    id: SecureRandom.uuid,
    sender: "#{@jwt.id}:#{@messaging.device_id}",
    recipient: "#{@to}:#{@to_device}",
    ciphertext: encrypt_message(@jwt.prepare(body), @to, @to_device)
  )
end