selfsdk 0.0.197 → 0.0.200
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/messages/attestation.rb +10 -1
 - data/lib/messages/connection_request.rb +64 -0
 - data/lib/messages/connection_response.rb +52 -0
 - data/lib/messages/fact.rb +7 -2
 - data/lib/messages/fact_issue.rb +95 -0
 - data/lib/messages/fact_request.rb +1 -1
 - data/lib/messages/fact_response.rb +1 -1
 - data/lib/messages/message.rb +4 -0
 - data/lib/messaging.rb +1 -2
 - data/lib/services/chat.rb +42 -0
 - data/lib/services/facts.rb +52 -1
 - data/lib/services/requester.rb +10 -67
 - data/lib/sources.rb +14 -4
 - metadata +13 -4
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 74f1c051fdeb2d35ce3d50da6c0f84169f99ea0ad403c456a131a1b992da29ae
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: a3a869a1ec7240c3bc0076d44540c53456438008636382bd165e1ab89a32e045
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 8723dbb549e965ba752e20a35fddc93034ac9dc719344025858eee1c3c2050f411e93a4db48cd38102182d8a801f45c64cebe67aed45c33ad7196e95b764cb43
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 32971cdca3e179fc85ac190ad87fa5ba48fe92f1b63212f6cc948a6a2c989063c471a0dd65219036895a8a28441da99ed5b4ede67f88bf56c37f3aa4a9d5ca11
         
     | 
    
        data/lib/messages/attestation.rb
    CHANGED
    
    | 
         @@ -24,7 +24,16 @@ module SelfSDK 
     | 
|
| 
       24 
24 
     | 
    
         
             
                    @expected_value = payload[:expected_value]
         
     | 
| 
       25 
25 
     | 
    
         
             
                    @operator = payload[:operator]
         
     | 
| 
       26 
26 
     | 
    
         
             
                    @fact_name = name.to_s
         
     | 
| 
       27 
     | 
    
         
            -
                     
     | 
| 
      
 27 
     | 
    
         
            +
                    if payload[name].nil?
         
     | 
| 
      
 28 
     | 
    
         
            +
                      return if payload[:facts].nil?
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                      payload[:facts].each do |f|
         
     | 
| 
      
 31 
     | 
    
         
            +
                        if f[:key] == name.to_s
         
     | 
| 
      
 32 
     | 
    
         
            +
                          @value = f[:value]
         
     | 
| 
      
 33 
     | 
    
         
            +
                          break
         
     | 
| 
      
 34 
     | 
    
         
            +
                        end
         
     | 
| 
      
 35 
     | 
    
         
            +
                      end
         
     | 
| 
      
 36 
     | 
    
         
            +
                    else
         
     | 
| 
       28 
37 
     | 
    
         
             
                      @value = payload[name]
         
     | 
| 
       29 
38 
     | 
    
         
             
                    end
         
     | 
| 
       30 
39 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -0,0 +1,64 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Copyright 2020 Self Group Ltd. All Rights Reserved.
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            require 'self_msgproto'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require_relative 'base'
         
     | 
| 
      
 7 
     | 
    
         
            +
            require_relative '../ntptime'
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            module SelfSDK
         
     | 
| 
      
 10 
     | 
    
         
            +
              module Messages
         
     | 
| 
      
 11 
     | 
    
         
            +
                class ConnectionRequest < Base
         
     | 
| 
      
 12 
     | 
    
         
            +
                  MSG_TYPE = "identities.connections.req"
         
     | 
| 
      
 13 
     | 
    
         
            +
                  DEFAULT_EXP_TIMEOUT = 9000
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                  attr_accessor :facts, :options, :auth
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                  def initialize(messaging)
         
     | 
| 
      
 18 
     | 
    
         
            +
                    @typ = MSG_TYPE
         
     | 
| 
      
 19 
     | 
    
         
            +
                    super
         
     | 
| 
      
 20 
     | 
    
         
            +
                  end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                  def populate(selfid, opts)
         
     | 
| 
      
 23 
     | 
    
         
            +
                    @id = SecureRandom.uuid
         
     | 
| 
      
 24 
     | 
    
         
            +
                    @from = @client.jwt.id
         
     | 
| 
      
 25 
     | 
    
         
            +
                    @to = selfid
         
     | 
| 
      
 26 
     | 
    
         
            +
                    @exp_timeout = opts.fetch(:exp_timeout, DEFAULT_EXP_TIMEOUT)
         
     | 
| 
      
 27 
     | 
    
         
            +
                  end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
                  def parse(input, envelope=nil)
         
     | 
| 
      
 30 
     | 
    
         
            +
                    super
         
     | 
| 
      
 31 
     | 
    
         
            +
                    @typ = MSG_TYPE
         
     | 
| 
      
 32 
     | 
    
         
            +
                    @body = @payload[:msg]
         
     | 
| 
      
 33 
     | 
    
         
            +
                  end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                  def body
         
     | 
| 
      
 36 
     | 
    
         
            +
                    {
         
     | 
| 
      
 37 
     | 
    
         
            +
                      typ: MSG_TYPE,
         
     | 
| 
      
 38 
     | 
    
         
            +
                      iss: @jwt.id,
         
     | 
| 
      
 39 
     | 
    
         
            +
                      aud: @to,
         
     | 
| 
      
 40 
     | 
    
         
            +
                      sub: @to,
         
     | 
| 
      
 41 
     | 
    
         
            +
                      iat: SelfSDK::Time.now.strftime('%FT%TZ'),
         
     | 
| 
      
 42 
     | 
    
         
            +
                      exp: (SelfSDK::Time.now + @exp_timeout).strftime('%FT%TZ'),
         
     | 
| 
      
 43 
     | 
    
         
            +
                      jti: SecureRandom.uuid,
         
     | 
| 
      
 44 
     | 
    
         
            +
                      require_confirmation: true,
         
     | 
| 
      
 45 
     | 
    
         
            +
                    }
         
     | 
| 
      
 46 
     | 
    
         
            +
                  end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                  protected
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                  def proto(to_device)
         
     | 
| 
      
 51 
     | 
    
         
            +
                    @to_device = to_device
         
     | 
| 
      
 52 
     | 
    
         
            +
                    recipient = "#{@to}:#{@to_device}"
         
     | 
| 
      
 53 
     | 
    
         
            +
                    ciphertext = encrypt_message(@jwt.prepare(body), [{id: @to, device_id: @to_device}])
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                    m = SelfMsg::Message.new
         
     | 
| 
      
 56 
     | 
    
         
            +
                    m.id = @id
         
     | 
| 
      
 57 
     | 
    
         
            +
                    m.sender = "#{@jwt.id}:#{@messaging.device_id}"
         
     | 
| 
      
 58 
     | 
    
         
            +
                    m.recipient = recipient
         
     | 
| 
      
 59 
     | 
    
         
            +
                    m.ciphertext = ciphertext
         
     | 
| 
      
 60 
     | 
    
         
            +
                    m
         
     | 
| 
      
 61 
     | 
    
         
            +
                  end
         
     | 
| 
      
 62 
     | 
    
         
            +
                end
         
     | 
| 
      
 63 
     | 
    
         
            +
              end
         
     | 
| 
      
 64 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,52 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Copyright 2020 Self Group Ltd. All Rights Reserved.
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            require 'self_msgproto'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require_relative 'base'
         
     | 
| 
      
 7 
     | 
    
         
            +
            require_relative '../ntptime'
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            module SelfSDK
         
     | 
| 
      
 10 
     | 
    
         
            +
              module Messages
         
     | 
| 
      
 11 
     | 
    
         
            +
                class ConnectionResponse < Base
         
     | 
| 
      
 12 
     | 
    
         
            +
                  MSG_TYPE = "identities.connections.resp"
         
     | 
| 
      
 13 
     | 
    
         
            +
                  DEFAULT_EXP_TIMEOUT = 900
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                  attr_accessor :facts, :options, :auth
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                  def initialize(messaging)
         
     | 
| 
      
 18 
     | 
    
         
            +
                    @typ = MSG_TYPE
         
     | 
| 
      
 19 
     | 
    
         
            +
                    super
         
     | 
| 
      
 20 
     | 
    
         
            +
                  end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                  def populate(selfid)
         
     | 
| 
      
 23 
     | 
    
         
            +
                    @id = SecureRandom.uuid
         
     | 
| 
      
 24 
     | 
    
         
            +
                    @from = @client.jwt.id
         
     | 
| 
      
 25 
     | 
    
         
            +
                    @to = selfid
         
     | 
| 
      
 26 
     | 
    
         
            +
                  end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                  def parse(input, envelope=nil)
         
     | 
| 
      
 29 
     | 
    
         
            +
                    @typ = MSG_TYPE
         
     | 
| 
      
 30 
     | 
    
         
            +
                    @payload = get_payload input
         
     | 
| 
      
 31 
     | 
    
         
            +
                    @body = @payload[:msg]
         
     | 
| 
      
 32 
     | 
    
         
            +
                    @status = @payload[:status]
         
     | 
| 
      
 33 
     | 
    
         
            +
                  end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                  def get_payload(input)
         
     | 
| 
      
 36 
     | 
    
         
            +
                    body = if input.is_a? String
         
     | 
| 
      
 37 
     | 
    
         
            +
                             input
         
     | 
| 
      
 38 
     | 
    
         
            +
                           else
         
     | 
| 
      
 39 
     | 
    
         
            +
                             input.ciphertext
         
     | 
| 
      
 40 
     | 
    
         
            +
                           end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
                    jwt = JSON.parse(body, symbolize_names: true)
         
     | 
| 
      
 43 
     | 
    
         
            +
                    payload = JSON.parse(@jwt.decode(jwt[:payload]), symbolize_names: true)
         
     | 
| 
      
 44 
     | 
    
         
            +
                    header = JSON.parse(@jwt.decode(jwt[:protected]), symbolize_names: true)
         
     | 
| 
      
 45 
     | 
    
         
            +
                    @from = payload[:iss]
         
     | 
| 
      
 46 
     | 
    
         
            +
                    verify! jwt, header[:kid]
         
     | 
| 
      
 47 
     | 
    
         
            +
                    payload
         
     | 
| 
      
 48 
     | 
    
         
            +
                  end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                end
         
     | 
| 
      
 51 
     | 
    
         
            +
              end
         
     | 
| 
      
 52 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/messages/fact.rb
    CHANGED
    
    | 
         @@ -14,11 +14,15 @@ module SelfSDK 
     | 
|
| 
       14 
14 
     | 
    
         
             
                  end
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
                  def parse(fact)
         
     | 
| 
       17 
     | 
    
         
            -
                    @name = @messaging.source.normalize_fact_name 
     | 
| 
      
 17 
     | 
    
         
            +
                    @name = @messaging.source.normalize_fact_name fact[:fact]
         
     | 
| 
       18 
18 
     | 
    
         
             
                    @operator = @messaging.source.normalize_operator!(fact[:operator])
         
     | 
| 
       19 
19 
     | 
    
         
             
                    @sources = []
         
     | 
| 
       20 
20 
     | 
    
         
             
                    fact[:sources]&.each do |s|
         
     | 
| 
       21 
     | 
    
         
            -
                      @sources <<  
     | 
| 
      
 21 
     | 
    
         
            +
                      @sources << s.to_s
         
     | 
| 
      
 22 
     | 
    
         
            +
                    end
         
     | 
| 
      
 23 
     | 
    
         
            +
                    @issuers = []
         
     | 
| 
      
 24 
     | 
    
         
            +
                    fact[:issuers]&.each do |i|
         
     | 
| 
      
 25 
     | 
    
         
            +
                      @issuers << i.to_s
         
     | 
| 
       22 
26 
     | 
    
         
             
                    end
         
     | 
| 
       23 
27 
     | 
    
         | 
| 
       24 
28 
     | 
    
         
             
                    @expected_value = fact[:expected_value] || ""
         
     | 
| 
         @@ -39,6 +43,7 @@ module SelfSDK 
     | 
|
| 
       39 
43 
     | 
    
         | 
| 
       40 
44 
     | 
    
         
             
                  def to_hash
         
     | 
| 
       41 
45 
     | 
    
         
             
                    h = { fact: @name }
         
     | 
| 
      
 46 
     | 
    
         
            +
                    h[:issuers] = @issuers if @issuers.length > 0
         
     | 
| 
       42 
47 
     | 
    
         
             
                    unless @sources.nil?
         
     | 
| 
       43 
48 
     | 
    
         
             
                      h[:sources] = @sources if @sources.length > 0
         
     | 
| 
       44 
49 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -0,0 +1,95 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Copyright 2020 Self Group Ltd. All Rights Reserved.
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            require 'self_msgproto'
         
     | 
| 
      
 6 
     | 
    
         
            +
            require_relative 'base'
         
     | 
| 
      
 7 
     | 
    
         
            +
            require_relative '../ntptime'
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            module SelfSDK
         
     | 
| 
      
 10 
     | 
    
         
            +
              module Messages
         
     | 
| 
      
 11 
     | 
    
         
            +
                class FactIssue < Base
         
     | 
| 
      
 12 
     | 
    
         
            +
                  MSG_TYPE = "identities.facts.issue"
         
     | 
| 
      
 13 
     | 
    
         
            +
                  DEFAULT_EXP_TIMEOUT = 900
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                  def initialize(messaging)
         
     | 
| 
      
 16 
     | 
    
         
            +
                    @typ = MSG_TYPE
         
     | 
| 
      
 17 
     | 
    
         
            +
                    super
         
     | 
| 
      
 18 
     | 
    
         
            +
                  end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                  def populate(selfid, facts, opts)
         
     | 
| 
      
 21 
     | 
    
         
            +
                    @id = opts.fetch(:cid, SecureRandom.uuid)
         
     | 
| 
      
 22 
     | 
    
         
            +
                    @exp_timeout = opts.fetch(:exp_timeout, DEFAULT_EXP_TIMEOUT)
         
     | 
| 
      
 23 
     | 
    
         
            +
                    @viewers = opts.fetch(:viewers, nil)
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                    @from = @jwt.id
         
     | 
| 
      
 26 
     | 
    
         
            +
                    @to = selfid
         
     | 
| 
      
 27 
     | 
    
         
            +
                    @attestations = build_attestations!(facts)
         
     | 
| 
      
 28 
     | 
    
         
            +
                  end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                  def body
         
     | 
| 
      
 31 
     | 
    
         
            +
                    b = {
         
     | 
| 
      
 32 
     | 
    
         
            +
                      typ: MSG_TYPE,
         
     | 
| 
      
 33 
     | 
    
         
            +
                      iss: @jwt.id,
         
     | 
| 
      
 34 
     | 
    
         
            +
                      aud: @to,
         
     | 
| 
      
 35 
     | 
    
         
            +
                      sub: @to,
         
     | 
| 
      
 36 
     | 
    
         
            +
                      iat: SelfSDK::Time.now.strftime('%FT%TZ'),
         
     | 
| 
      
 37 
     | 
    
         
            +
                      exp: (SelfSDK::Time.now + @exp_timeout).strftime('%FT%TZ'),
         
     | 
| 
      
 38 
     | 
    
         
            +
                      cid: @id,
         
     | 
| 
      
 39 
     | 
    
         
            +
                      jti: SecureRandom.uuid,
         
     | 
| 
      
 40 
     | 
    
         
            +
                      status: 'verified',
         
     | 
| 
      
 41 
     | 
    
         
            +
                      attestations: @attestations
         
     | 
| 
      
 42 
     | 
    
         
            +
                    }
         
     | 
| 
      
 43 
     | 
    
         
            +
                    # viewers
         
     | 
| 
      
 44 
     | 
    
         
            +
                    b[:viewers] = @viewers unless @viewers.nil?
         
     | 
| 
      
 45 
     | 
    
         
            +
                    b
         
     | 
| 
      
 46 
     | 
    
         
            +
                  end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                  protected
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                  def proto(to_device)
         
     | 
| 
      
 51 
     | 
    
         
            +
                    @to_device = to_device
         
     | 
| 
      
 52 
     | 
    
         
            +
                    recipient = "#{@to}:#{@to_device}"
         
     | 
| 
      
 53 
     | 
    
         
            +
                    ciphertext = encrypt_message(@jwt.prepare(body), [{id: @to, device_id: @to_device}])
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
                    m = SelfMsg::Message.new
         
     | 
| 
      
 56 
     | 
    
         
            +
                    m.id = @id
         
     | 
| 
      
 57 
     | 
    
         
            +
                    m.sender = "#{@jwt.id}:#{@messaging.device_id}"
         
     | 
| 
      
 58 
     | 
    
         
            +
                    m.recipient = recipient
         
     | 
| 
      
 59 
     | 
    
         
            +
                    m.ciphertext = ciphertext
         
     | 
| 
      
 60 
     | 
    
         
            +
                    m
         
     | 
| 
      
 61 
     | 
    
         
            +
                  end
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                  private
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                  def build_attestations!(facts)
         
     | 
| 
      
 66 
     | 
    
         
            +
                    raise 'facts must be provided in the form of an array' unless facts.kind_of?(Array)
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                    attestations = []
         
     | 
| 
      
 69 
     | 
    
         
            +
                    facts.each do |fact|
         
     | 
| 
      
 70 
     | 
    
         
            +
                      att = fact.transform_keys(&:to_sym)
         
     | 
| 
      
 71 
     | 
    
         
            +
                      raise 'invalid attestation : does not provide a key' if !att.has_key?(:key) || att[:key].empty?
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
                      raise 'invalid attestation : does not provide a value' if !att.has_key?(:value) || att[:value].empty?
         
     | 
| 
      
 74 
     | 
    
         
            +
                      att.delete(:source)
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                      attestations << sign(fact[:source], att)
         
     | 
| 
      
 77 
     | 
    
         
            +
                    end
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
                    attestations
         
     | 
| 
      
 80 
     | 
    
         
            +
                  end
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
      
 82 
     | 
    
         
            +
                  def sign(source, facts)
         
     | 
| 
      
 83 
     | 
    
         
            +
                    fact = { jti: SecureRandom.uuid,
         
     | 
| 
      
 84 
     | 
    
         
            +
                             sub: @to,
         
     | 
| 
      
 85 
     | 
    
         
            +
                             iss: @from,
         
     | 
| 
      
 86 
     | 
    
         
            +
                             iat: SelfSDK::Time.now.strftime('%FT%TZ'),
         
     | 
| 
      
 87 
     | 
    
         
            +
                             exp: (SelfSDK::Time.now + @exp_timeout).strftime('%FT%TZ'),
         
     | 
| 
      
 88 
     | 
    
         
            +
                             source: source,
         
     | 
| 
      
 89 
     | 
    
         
            +
                             verified: true,
         
     | 
| 
      
 90 
     | 
    
         
            +
                             facts: [ facts ] }
         
     | 
| 
      
 91 
     | 
    
         
            +
                    @client.jwt.signed(fact)
         
     | 
| 
      
 92 
     | 
    
         
            +
                  end
         
     | 
| 
      
 93 
     | 
    
         
            +
                end
         
     | 
| 
      
 94 
     | 
    
         
            +
              end
         
     | 
| 
      
 95 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/messages/message.rb
    CHANGED
    
    | 
         @@ -11,6 +11,7 @@ require_relative "chat_invite" 
     | 
|
| 
       11 
11 
     | 
    
         
             
            require_relative "chat_join"
         
     | 
| 
       12 
12 
     | 
    
         
             
            require_relative "chat_remove"
         
     | 
| 
       13 
13 
     | 
    
         
             
            require_relative "document_sign_resp"
         
     | 
| 
      
 14 
     | 
    
         
            +
            require_relative "connection_response"
         
     | 
| 
       14 
15 
     | 
    
         | 
| 
       15 
16 
     | 
    
         
             
            module SelfSDK
         
     | 
| 
       16 
17 
     | 
    
         
             
              module Messages
         
     | 
| 
         @@ -55,6 +56,9 @@ module SelfSDK 
     | 
|
| 
       55 
56 
     | 
    
         
             
                  when SelfSDK::Messages::DocumentSignResponse::MSG_TYPE
         
     | 
| 
       56 
57 
     | 
    
         
             
                    m = DocumentSignResponse.new(messaging)
         
     | 
| 
       57 
58 
     | 
    
         
             
                    m.parse(body, envelope)
         
     | 
| 
      
 59 
     | 
    
         
            +
                  when SelfSDK::Messages::ConnectionResponse::MSG_TYPE
         
     | 
| 
      
 60 
     | 
    
         
            +
                    m = ConnectionResponse.new(messaging)
         
     | 
| 
      
 61 
     | 
    
         
            +
                    m.parse(body, envelope)
         
     | 
| 
       58 
62 
     | 
    
         
             
                  else
         
     | 
| 
       59 
63 
     | 
    
         
             
                    raise StandardError.new("Invalid message type #{payload[:typ]}.")
         
     | 
| 
       60 
64 
     | 
    
         
             
                  end
         
     | 
    
        data/lib/messaging.rb
    CHANGED
    
    | 
         @@ -430,9 +430,8 @@ module SelfSDK 
     | 
|
| 
       430 
430 
     | 
    
         
             
                    message.validate! @uuid_observer[message.id][:original_message] if @uuid_observer.include? message.id
         
     | 
| 
       431 
431 
     | 
    
         
             
                    notify_observer(message)
         
     | 
| 
       432 
432 
     | 
    
         
             
                  end
         
     | 
| 
       433 
     | 
    
         
            -
             
     | 
| 
       434 
433 
     | 
    
         
             
                rescue StandardError => e
         
     | 
| 
       435 
     | 
    
         
            -
                  p "Error processing incoming message #{ 
     | 
| 
      
 434 
     | 
    
         
            +
                  p "Error processing incoming message #{e.message}"
         
     | 
| 
       436 
435 
     | 
    
         
             
                  SelfSDK.logger.info e
         
     | 
| 
       437 
436 
     | 
    
         
             
                  # p e.backtrace
         
     | 
| 
       438 
437 
     | 
    
         
             
                  nil
         
     | 
    
        data/lib/services/chat.rb
    CHANGED
    
    | 
         @@ -6,6 +6,8 @@ require 'self_crypto' 
     | 
|
| 
       6 
6 
     | 
    
         
             
            require_relative '../chat/file_object'
         
     | 
| 
       7 
7 
     | 
    
         
             
            require_relative '../chat/group'
         
     | 
| 
       8 
8 
     | 
    
         
             
            require_relative '../chat/message'
         
     | 
| 
      
 9 
     | 
    
         
            +
            require_relative "../messages/connection_request"
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
       9 
11 
     | 
    
         
             
            module SelfSDK
         
     | 
| 
       10 
12 
     | 
    
         
             
              module Services
         
     | 
| 
       11 
13 
     | 
    
         
             
                class Chat
         
     | 
| 
         @@ -160,6 +162,46 @@ module SelfSDK 
     | 
|
| 
       160 
162 
     | 
    
         
             
                    send(members, typ: "chat.remove", gid: gid )
         
     | 
| 
       161 
163 
     | 
    
         
             
                  end
         
     | 
| 
       162 
164 
     | 
    
         | 
| 
      
 165 
     | 
    
         
            +
                  # Generates a connection request in form of QR
         
     | 
| 
      
 166 
     | 
    
         
            +
                  #
         
     | 
| 
      
 167 
     | 
    
         
            +
                  #  @opts opts [Integer] :exp_timeout timeout in seconds to expire the request.
         
     | 
| 
      
 168 
     | 
    
         
            +
                  def generate_connection_qr(opts = {})
         
     | 
| 
      
 169 
     | 
    
         
            +
                    req = SelfSDK::Messages::ConnectionRequest.new(@messaging)
         
     | 
| 
      
 170 
     | 
    
         
            +
                    req.populate(@jwt.id, opts)
         
     | 
| 
      
 171 
     | 
    
         
            +
                    body = @jwt.prepare(req.body)
         
     | 
| 
      
 172 
     | 
    
         
            +
             
     | 
| 
      
 173 
     | 
    
         
            +
                    ::RQRCode::QRCode.new(body, level: 'l')
         
     | 
| 
      
 174 
     | 
    
         
            +
                  end
         
     | 
| 
      
 175 
     | 
    
         
            +
             
     | 
| 
      
 176 
     | 
    
         
            +
                  # Generates a connection request in form of deep link
         
     | 
| 
      
 177 
     | 
    
         
            +
                  #
         
     | 
| 
      
 178 
     | 
    
         
            +
                  # @param callback [String] the url you'll be redirected if the app is not installed.
         
     | 
| 
      
 179 
     | 
    
         
            +
                  #  @opts opts [Integer] :exp_timeout timeout in seconds to expire the request.
         
     | 
| 
      
 180 
     | 
    
         
            +
                  def generate_connection_deep_link(callback, opts = {})
         
     | 
| 
      
 181 
     | 
    
         
            +
                    req = SelfSDK::Messages::ConnectionRequest.new(@messaging)
         
     | 
| 
      
 182 
     | 
    
         
            +
                    req.populate(@jwt.id, opts)
         
     | 
| 
      
 183 
     | 
    
         
            +
                    body = @jwt.prepare(req.body)
         
     | 
| 
      
 184 
     | 
    
         
            +
                    body = @jwt.encode(body)
         
     | 
| 
      
 185 
     | 
    
         
            +
             
     | 
| 
      
 186 
     | 
    
         
            +
                    env = @messaging.client.client.env
         
     | 
| 
      
 187 
     | 
    
         
            +
                    if env.empty?
         
     | 
| 
      
 188 
     | 
    
         
            +
                      return "https://links.joinself.com/?link=#{callback}%3Fqr=#{body}&apn=com.joinself.app"
         
     | 
| 
      
 189 
     | 
    
         
            +
                    elsif env == 'development'
         
     | 
| 
      
 190 
     | 
    
         
            +
                      return "https://links.joinself.com/?link=#{callback}%3Fqr=#{body}&apn=com.joinself.app.dev"
         
     | 
| 
      
 191 
     | 
    
         
            +
                    end
         
     | 
| 
      
 192 
     | 
    
         
            +
             
     | 
| 
      
 193 
     | 
    
         
            +
                    "https://#{env}.links.joinself.com/?link=#{callback}%3Fqr=#{body}&apn=com.joinself.app.#{env}"
         
     | 
| 
      
 194 
     | 
    
         
            +
                  end
         
     | 
| 
      
 195 
     | 
    
         
            +
             
     | 
| 
      
 196 
     | 
    
         
            +
                  # Subscribes to a connection response
         
     | 
| 
      
 197 
     | 
    
         
            +
                  #
         
     | 
| 
      
 198 
     | 
    
         
            +
                  #  @yield [request] Invokes the block with a connection response message.
         
     | 
| 
      
 199 
     | 
    
         
            +
                  def on_connection(&block)
         
     | 
| 
      
 200 
     | 
    
         
            +
                    @messaging.subscribe :connection_response do |msg|
         
     | 
| 
      
 201 
     | 
    
         
            +
                      block.call(msg)
         
     | 
| 
      
 202 
     | 
    
         
            +
                    end
         
     | 
| 
      
 203 
     | 
    
         
            +
                  end
         
     | 
| 
      
 204 
     | 
    
         
            +
             
     | 
| 
       163 
205 
     | 
    
         
             
                  private
         
     | 
| 
       164 
206 
     | 
    
         | 
| 
       165 
207 
     | 
    
         
             
                  # sends a confirmation for a list of messages to a list of recipients.
         
     | 
    
        data/lib/services/facts.rb
    CHANGED
    
    | 
         @@ -1,13 +1,13 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # Copyright 2020 Self Group Ltd. All Rights Reserved.
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
3 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
      
 4 
     | 
    
         
            +
            require_relative '../messages/fact_issue.rb'
         
     | 
| 
       4 
5 
     | 
    
         | 
| 
       5 
6 
     | 
    
         
             
            # Namespace for classes and modules that handle SelfSDK gem
         
     | 
| 
       6 
7 
     | 
    
         
             
            module SelfSDK
         
     | 
| 
       7 
8 
     | 
    
         
             
              # Namespace for classes and modules that handle selfsdk-gem public ui
         
     | 
| 
       8 
9 
     | 
    
         
             
              module Services
         
     | 
| 
       9 
10 
     | 
    
         
             
                # Self provides this self-hosted verified intermediary.
         
     | 
| 
       10 
     | 
    
         
            -
                DEFAULT_INTERMEDIARY = "self_intermediary"
         
     | 
| 
       11 
11 
     | 
    
         
             
                # Input class to handle fact requests on self network.
         
     | 
| 
       12 
12 
     | 
    
         
             
                class Facts
         
     | 
| 
       13 
13 
     | 
    
         
             
                  # Creates a new facts service.
         
     | 
| 
         @@ -93,6 +93,57 @@ module SelfSDK 
     | 
|
| 
       93 
93 
     | 
    
         
             
                    opts[:auth] = false
         
     | 
| 
       94 
94 
     | 
    
         
             
                    @requester.generate_deep_link(facts, callback, opts)
         
     | 
| 
       95 
95 
     | 
    
         
             
                  end
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
                  # Issues a custom fact and sends it to the user.
         
     | 
| 
      
 98 
     | 
    
         
            +
                  #
         
     | 
| 
      
 99 
     | 
    
         
            +
                  # @param selfid [String] self identifier for the message recipient.
         
     | 
| 
      
 100 
     | 
    
         
            +
                  # @param facts [Array<Fact>] facts to be sent to the user
         
     | 
| 
      
 101 
     | 
    
         
            +
                  # @option opts [String] :viewers list of self identifiers for the user that will have access to this facts.
         
     | 
| 
      
 102 
     | 
    
         
            +
                  def issue(selfid, facts, opts = {})
         
     | 
| 
      
 103 
     | 
    
         
            +
                    hased_facts = []
         
     | 
| 
      
 104 
     | 
    
         
            +
                    facts.each do |f|
         
     | 
| 
      
 105 
     | 
    
         
            +
                      hased_facts << f.to_hash
         
     | 
| 
      
 106 
     | 
    
         
            +
                    end
         
     | 
| 
      
 107 
     | 
    
         
            +
             
     | 
| 
      
 108 
     | 
    
         
            +
                    SelfSDK.logger.info "issuing facts for #{selfid}"
         
     | 
| 
      
 109 
     | 
    
         
            +
                    msg = SelfSDK::Messages::FactIssue.new(@requester.messaging)
         
     | 
| 
      
 110 
     | 
    
         
            +
                    msg.populate(selfid, hased_facts, opts)
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
                    msg.send_message
         
     | 
| 
      
 113 
     | 
    
         
            +
                  end
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
                  # Facts to be issued
         
     | 
| 
      
 116 
     | 
    
         
            +
                  class Fact
         
     | 
| 
      
 117 
     | 
    
         
            +
                    attr_accessor :key, :value, :group
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
      
 119 
     | 
    
         
            +
                    def initialize(key, value, source, group = nil)
         
     | 
| 
      
 120 
     | 
    
         
            +
                      @key = key
         
     | 
| 
      
 121 
     | 
    
         
            +
                      @value = value
         
     | 
| 
      
 122 
     | 
    
         
            +
                      @source = source
         
     | 
| 
      
 123 
     | 
    
         
            +
                      @group = group
         
     | 
| 
      
 124 
     | 
    
         
            +
                    end
         
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
      
 126 
     | 
    
         
            +
                    def to_hash
         
     | 
| 
      
 127 
     | 
    
         
            +
                      b = { key: @key, value: @value, source: @source }
         
     | 
| 
      
 128 
     | 
    
         
            +
                      b[:group] = @group.to_hash unless @group.nil?
         
     | 
| 
      
 129 
     | 
    
         
            +
                      b
         
     | 
| 
      
 130 
     | 
    
         
            +
                    end
         
     | 
| 
      
 131 
     | 
    
         
            +
                  end
         
     | 
| 
      
 132 
     | 
    
         
            +
             
     | 
| 
      
 133 
     | 
    
         
            +
                  class Group
         
     | 
| 
      
 134 
     | 
    
         
            +
                    attr_accessor :name, :icon
         
     | 
| 
      
 135 
     | 
    
         
            +
             
     | 
| 
      
 136 
     | 
    
         
            +
                    def initialize(name, icon = "")
         
     | 
| 
      
 137 
     | 
    
         
            +
                      @name = name
         
     | 
| 
      
 138 
     | 
    
         
            +
                      @icon = icon
         
     | 
| 
      
 139 
     | 
    
         
            +
                    end
         
     | 
| 
      
 140 
     | 
    
         
            +
             
     | 
| 
      
 141 
     | 
    
         
            +
                    def to_hash
         
     | 
| 
      
 142 
     | 
    
         
            +
                      b = { name: @name }
         
     | 
| 
      
 143 
     | 
    
         
            +
                      b[:icon] = @icon unless @icon.empty?
         
     | 
| 
      
 144 
     | 
    
         
            +
                      b
         
     | 
| 
      
 145 
     | 
    
         
            +
                    end
         
     | 
| 
      
 146 
     | 
    
         
            +
                  end
         
     | 
| 
       96 
147 
     | 
    
         
             
                end
         
     | 
| 
       97 
148 
     | 
    
         
             
              end
         
     | 
| 
       98 
149 
     | 
    
         
             
            end
         
     | 
    
        data/lib/services/requester.rb
    CHANGED
    
    | 
         @@ -10,6 +10,8 @@ module SelfSDK 
     | 
|
| 
       10 
10 
     | 
    
         
             
                DEFAULT_INTERMEDIARY = "self_intermediary"
         
     | 
| 
       11 
11 
     | 
    
         
             
                # Input class to handle fact requests on self network.
         
     | 
| 
       12 
12 
     | 
    
         
             
                class Requester
         
     | 
| 
      
 13 
     | 
    
         
            +
                  attr_reader :messaging
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
       13 
15 
     | 
    
         
             
                  # Creates a new facts service.
         
     | 
| 
       14 
16 
     | 
    
         
             
                  # Facts service mainly manages fact requests against self users wanting
         
     | 
| 
       15 
17 
     | 
    
         
             
                  # to share their verified facts with your app.
         
     | 
| 
         @@ -155,7 +157,7 @@ module SelfSDK 
     | 
|
| 
       155 
157 
     | 
    
         
             
                             else
         
     | 
| 
       156 
158 
     | 
    
         
             
                               { fact: f }
         
     | 
| 
       157 
159 
     | 
    
         
             
                             end
         
     | 
| 
       158 
     | 
    
         
            -
                       
     | 
| 
      
 160 
     | 
    
         
            +
                      validate_fact!(fact) unless fact.key?('issuers')
         
     | 
| 
       159 
161 
     | 
    
         
             
                      fs << fact
         
     | 
| 
       160 
162 
     | 
    
         
             
                    end
         
     | 
| 
       161 
163 
     | 
    
         
             
                    fs
         
     | 
| 
         @@ -164,77 +166,18 @@ module SelfSDK 
     | 
|
| 
       164 
166 
     | 
    
         
             
                  def validate_fact!(f)
         
     | 
| 
       165 
167 
     | 
    
         
             
                    errInvalidFactToSource = 'provided source does not support given fact'
         
     | 
| 
       166 
168 
     | 
    
         
             
                    errInvalidSource = 'provided fact does not specify a valid source'
         
     | 
| 
      
 169 
     | 
    
         
            +
                    fact_name = f[:fact].to_s
         
     | 
| 
       167 
170 
     | 
    
         | 
| 
       168 
     | 
    
         
            -
                    raise 'provided fact does not specify a name' if  
     | 
| 
      
 171 
     | 
    
         
            +
                    raise 'provided fact does not specify a name' if fact_name.empty?
         
     | 
| 
       169 
172 
     | 
    
         
             
                    return unless f.has_key? :sources
         
     | 
| 
      
 173 
     | 
    
         
            +
                    return if f.has_key? :issuers # skip the validation if is a custom fact
         
     | 
| 
       170 
174 
     | 
    
         | 
| 
       171 
     | 
    
         
            -
                     
     | 
| 
       172 
     | 
    
         
            -
                                     SOURCE_PASSPORT,
         
     | 
| 
       173 
     | 
    
         
            -
                                     SOURCE_DRIVING_LICENSE,
         
     | 
| 
       174 
     | 
    
         
            -
                                     SOURCE_IDENTITY_CARD,
         
     | 
| 
       175 
     | 
    
         
            -
                                     SOURCE_TWITTER,
         
     | 
| 
       176 
     | 
    
         
            -
                                     SOURCE_LINKEDIN,
         
     | 
| 
       177 
     | 
    
         
            -
                                     SOURCE_FACEBOK]
         
     | 
| 
       178 
     | 
    
         
            -
                    fact_for_passport = [FACT_DOCUMENT_NUMBER,
         
     | 
| 
       179 
     | 
    
         
            -
                                         FACT_SURNAME,
         
     | 
| 
       180 
     | 
    
         
            -
                                         FACT_GIVEN_NAMES,
         
     | 
| 
       181 
     | 
    
         
            -
                                         FACT_DATE_OF_BIRTH,
         
     | 
| 
       182 
     | 
    
         
            -
                                         FACT_DATE_OF_EXPIRATION,
         
     | 
| 
       183 
     | 
    
         
            -
                                         FACT_SEX,
         
     | 
| 
       184 
     | 
    
         
            -
                                         FACT_NATIONALITY,
         
     | 
| 
       185 
     | 
    
         
            -
                                         FACT_COUNTRY_OF_ISSUANCE]
         
     | 
| 
       186 
     | 
    
         
            -
             
     | 
| 
       187 
     | 
    
         
            -
                    facts_for_dl = [FACT_DOCUMENT_NUMBER,
         
     | 
| 
       188 
     | 
    
         
            -
                                    FACT_SURNAME,
         
     | 
| 
       189 
     | 
    
         
            -
                                    FACT_GIVEN_NAMES,
         
     | 
| 
       190 
     | 
    
         
            -
                                    FACT_DATE_OF_BIRTH,
         
     | 
| 
       191 
     | 
    
         
            -
                                    FACT_DATE_OF_ISSUANCE,
         
     | 
| 
       192 
     | 
    
         
            -
                                    FACT_DATE_OF_EXPIRATION,
         
     | 
| 
       193 
     | 
    
         
            -
                                    FACT_ADDRESS, 
         
     | 
| 
       194 
     | 
    
         
            -
                                    FACT_ISSUING_AUTHORITY,
         
     | 
| 
       195 
     | 
    
         
            -
                                    FACT_PLACE_OF_BIRTH, 
         
     | 
| 
       196 
     | 
    
         
            -
                                    FACT_COUNTRY_OF_ISSUANCE]
         
     | 
| 
       197 
     | 
    
         
            -
             
     | 
| 
       198 
     | 
    
         
            -
                    facts_for_user = [FACT_DOCUMENT_NUMBER,
         
     | 
| 
       199 
     | 
    
         
            -
                                      FACT_DISPLAY_NAME,
         
     | 
| 
       200 
     | 
    
         
            -
                                      FACT_EMAIL,
         
     | 
| 
       201 
     | 
    
         
            -
                                      FACT_PHONE]
         
     | 
| 
       202 
     | 
    
         
            -
             
     | 
| 
       203 
     | 
    
         
            -
                    facts_for_twitter = [FACT_ACCOUNT_ID, FACT_NICKNAME]
         
     | 
| 
       204 
     | 
    
         
            -
                    facts_for_linkedin = [FACT_ACCOUNT_ID, FACT_NICKNAME]
         
     | 
| 
       205 
     | 
    
         
            -
                    facts_for_facebook = [FACT_ACCOUNT_ID, FACT_NICKNAME]
         
     | 
| 
       206 
     | 
    
         
            -
                    facts_for_live = [FACT_SELFIE]
         
     | 
| 
      
 175 
     | 
    
         
            +
                    raise "invalid fact '#{fact_name}'" unless @messaging.source.core_fact?(fact_name)
         
     | 
| 
       207 
176 
     | 
    
         | 
| 
      
 177 
     | 
    
         
            +
                    spec = @messaging.source.sources
         
     | 
| 
       208 
178 
     | 
    
         
             
                    f[:sources].each do |s|
         
     | 
| 
       209 
     | 
    
         
            -
                      raise errInvalidSource unless  
     | 
| 
       210 
     | 
    
         
            -
             
     | 
| 
       211 
     | 
    
         
            -
                      if s.to_s == SOURCE_PASSPORT || s.to_s == SOURCE_IDENTITY_CARD
         
     | 
| 
       212 
     | 
    
         
            -
                        raise errInvalidFactToSource unless fact_for_passport.include? f[:fact]
         
     | 
| 
       213 
     | 
    
         
            -
                      end
         
     | 
| 
       214 
     | 
    
         
            -
             
     | 
| 
       215 
     | 
    
         
            -
                      if s.to_s == SOURCE_DRIVING_LICENSE
         
     | 
| 
       216 
     | 
    
         
            -
                        raise errInvalidFactToSource unless facts_for_dl.include? f[:fact]
         
     | 
| 
       217 
     | 
    
         
            -
                      end
         
     | 
| 
       218 
     | 
    
         
            -
             
     | 
| 
       219 
     | 
    
         
            -
                      if s.to_s == SOURCE_USER_SPECIFIED
         
     | 
| 
       220 
     | 
    
         
            -
                        raise errInvalidFactToSource unless facts_for_user.include? f[:fact].to_s
         
     | 
| 
       221 
     | 
    
         
            -
                      end
         
     | 
| 
       222 
     | 
    
         
            -
             
     | 
| 
       223 
     | 
    
         
            -
                      if s.to_s == SOURCE_TWITTER
         
     | 
| 
       224 
     | 
    
         
            -
                        raise errInvalidFactToSource unless facts_for_twitter.include? f[:fact].to_s
         
     | 
| 
       225 
     | 
    
         
            -
                      end
         
     | 
| 
       226 
     | 
    
         
            -
             
     | 
| 
       227 
     | 
    
         
            -
                      if s.to_s == SOURCE_LINKEDIN
         
     | 
| 
       228 
     | 
    
         
            -
                        raise errInvalidFactToSource unless facts_for_linkedin.include? f[:fact].to_s
         
     | 
| 
       229 
     | 
    
         
            -
                      end
         
     | 
| 
       230 
     | 
    
         
            -
             
     | 
| 
       231 
     | 
    
         
            -
                      if s.to_s == SOURCE_FACEBOOK
         
     | 
| 
       232 
     | 
    
         
            -
                        raise errInvalidFactToSource unless facts_for_facebook.include? f[:fact].to_s
         
     | 
| 
       233 
     | 
    
         
            -
                      end
         
     | 
| 
       234 
     | 
    
         
            -
             
     | 
| 
       235 
     | 
    
         
            -
                      if s.to_s == SOURCE_LIVE
         
     | 
| 
       236 
     | 
    
         
            -
                        raise errInvalidFactToSource unless facts_for_live.include? f[:fact].to_s
         
     | 
| 
       237 
     | 
    
         
            -
                      end
         
     | 
| 
      
 179 
     | 
    
         
            +
                      raise errInvalidSource unless spec.key?(s.to_s)
         
     | 
| 
      
 180 
     | 
    
         
            +
                      raise errInvalidFactToSource unless spec[s.to_s].include? fact_name.to_s
         
     | 
| 
       238 
181 
     | 
    
         
             
                    end
         
     | 
| 
       239 
182 
     | 
    
         
             
                  end
         
     | 
| 
       240 
183 
     | 
    
         
             
                end
         
     | 
    
        data/lib/sources.rb
    CHANGED
    
    | 
         @@ -7,6 +7,8 @@ require_relative "source_definition.rb" 
     | 
|
| 
       7 
7 
     | 
    
         | 
| 
       8 
8 
     | 
    
         
             
            module SelfSDK
         
     | 
| 
       9 
9 
     | 
    
         
             
              class Sources
         
     | 
| 
      
 10 
     | 
    
         
            +
                attr_reader :sources, :facts
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
       10 
12 
     | 
    
         
             
                def initialize(sources_file)
         
     | 
| 
       11 
13 
     | 
    
         
             
                  @sources = SOURCE_DATA["sources"]
         
     | 
| 
       12 
14 
     | 
    
         
             
                  @facts = []
         
     | 
| 
         @@ -15,10 +17,12 @@ module SelfSDK 
     | 
|
| 
       15 
17 
     | 
    
         
             
                  end
         
     | 
| 
       16 
18 
     | 
    
         
             
                end
         
     | 
| 
       17 
19 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
                def normalize_fact_name 
     | 
| 
       19 
     | 
    
         
            -
                  fact 
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
      
 20 
     | 
    
         
            +
                def normalize_fact_name(fact)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  fact.to_s
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                def normalize_source(source)
         
     | 
| 
      
 25 
     | 
    
         
            +
                  source.to_s
         
     | 
| 
       22 
26 
     | 
    
         
             
                end
         
     | 
| 
       23 
27 
     | 
    
         | 
| 
       24 
28 
     | 
    
         
             
                def validate_source!(source)
         
     | 
| 
         @@ -37,6 +41,10 @@ module SelfSDK 
     | 
|
| 
       37 
41 
     | 
    
         
             
                  get(operators, input, "operator")
         
     | 
| 
       38 
42 
     | 
    
         
             
                end
         
     | 
| 
       39 
43 
     | 
    
         | 
| 
      
 44 
     | 
    
         
            +
                def core_fact?(fact)
         
     | 
| 
      
 45 
     | 
    
         
            +
                  @facts.include? fact.to_s
         
     | 
| 
      
 46 
     | 
    
         
            +
                end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
       40 
48 
     | 
    
         
             
                def message_type(s)
         
     | 
| 
       41 
49 
     | 
    
         
             
                  types = { fact_request: SelfSDK::Messages::FactRequest::MSG_TYPE,
         
     | 
| 
       42 
50 
     | 
    
         
             
                            fact_response: SelfSDK::Messages::FactResponse::MSG_TYPE,
         
     | 
| 
         @@ -47,11 +55,13 @@ module SelfSDK 
     | 
|
| 
       47 
55 
     | 
    
         
             
                            chat_join: SelfSDK::Messages::ChatJoin::MSG_TYPE,
         
     | 
| 
       48 
56 
     | 
    
         
             
                            chat_remove: SelfSDK::Messages::ChatRemove::MSG_TYPE,
         
     | 
| 
       49 
57 
     | 
    
         
             
                            document_sign_response: SelfSDK::Messages::DocumentSignResponse::MSG_TYPE,
         
     | 
| 
      
 58 
     | 
    
         
            +
                            connection_response: SelfSDK::Messages::ConnectionResponse::MSG_TYPE,
         
     | 
| 
       50 
59 
     | 
    
         
             
                           }
         
     | 
| 
       51 
60 
     | 
    
         
             
                  raise "invalid message type '#{s}'" unless types.key? s
         
     | 
| 
       52 
61 
     | 
    
         
             
                  return types[s]
         
     | 
| 
       53 
62 
     | 
    
         
             
                end
         
     | 
| 
       54 
63 
     | 
    
         | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
       55 
65 
     | 
    
         
             
                private
         
     | 
| 
       56 
66 
     | 
    
         | 
| 
       57 
67 
     | 
    
         
             
                def get(options, input, option_type)
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: selfsdk
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.0.200
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Aldgate Ventures
         
     | 
| 
         @@ -184,14 +184,20 @@ dependencies: 
     | 
|
| 
       184 
184 
     | 
    
         
             
                requirements:
         
     | 
| 
       185 
185 
     | 
    
         
             
                - - "~>"
         
     | 
| 
       186 
186 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       187 
     | 
    
         
            -
                    version: ' 
     | 
| 
      
 187 
     | 
    
         
            +
                    version: '2.3'
         
     | 
| 
      
 188 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 189 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 190 
     | 
    
         
            +
                    version: 2.3.13
         
     | 
| 
       188 
191 
     | 
    
         
             
              type: :development
         
     | 
| 
       189 
192 
     | 
    
         
             
              prerelease: false
         
     | 
| 
       190 
193 
     | 
    
         
             
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
       191 
194 
     | 
    
         
             
                requirements:
         
     | 
| 
       192 
195 
     | 
    
         
             
                - - "~>"
         
     | 
| 
       193 
196 
     | 
    
         
             
                  - !ruby/object:Gem::Version
         
     | 
| 
       194 
     | 
    
         
            -
                    version: ' 
     | 
| 
      
 197 
     | 
    
         
            +
                    version: '2.3'
         
     | 
| 
      
 198 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 199 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 200 
     | 
    
         
            +
                    version: 2.3.13
         
     | 
| 
       195 
201 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       196 
202 
     | 
    
         
             
              name: minitest
         
     | 
| 
       197 
203 
     | 
    
         
             
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
         @@ -342,8 +348,11 @@ files: 
     | 
|
| 
       342 
348 
     | 
    
         
             
            - lib/messages/chat_message_delivered.rb
         
     | 
| 
       343 
349 
     | 
    
         
             
            - lib/messages/chat_message_read.rb
         
     | 
| 
       344 
350 
     | 
    
         
             
            - lib/messages/chat_remove.rb
         
     | 
| 
      
 351 
     | 
    
         
            +
            - lib/messages/connection_request.rb
         
     | 
| 
      
 352 
     | 
    
         
            +
            - lib/messages/connection_response.rb
         
     | 
| 
       345 
353 
     | 
    
         
             
            - lib/messages/document_sign_resp.rb
         
     | 
| 
       346 
354 
     | 
    
         
             
            - lib/messages/fact.rb
         
     | 
| 
      
 355 
     | 
    
         
            +
            - lib/messages/fact_issue.rb
         
     | 
| 
       347 
356 
     | 
    
         
             
            - lib/messages/fact_request.rb
         
     | 
| 
       348 
357 
     | 
    
         
             
            - lib/messages/fact_response.rb
         
     | 
| 
       349 
358 
     | 
    
         
             
            - lib/messages/message.rb
         
     | 
| 
         @@ -381,7 +390,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       381 
390 
     | 
    
         
             
                - !ruby/object:Gem::Version
         
     | 
| 
       382 
391 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       383 
392 
     | 
    
         
             
            requirements: []
         
     | 
| 
       384 
     | 
    
         
            -
            rubygems_version: 3. 
     | 
| 
      
 393 
     | 
    
         
            +
            rubygems_version: 3.1.6
         
     | 
| 
       385 
394 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       386 
395 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       387 
396 
     | 
    
         
             
            summary: joinself sdk
         
     |