selfsdk 0.0.192 → 0.0.195

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b84b3c0de37f3796956af4b2dad2ac22c36d607abac1dee60cf6eceb4d3ff38
4
- data.tar.gz: 802b73496bc17ca86f09035e13a85c6d572b9607aac42b9688bd0cd2a0a0e994
3
+ metadata.gz: e41a8293552addc1b1de4266ae6116de304f94da70410d0c6edc159e579a6787
4
+ data.tar.gz: 974a651863325ae66fd015af0cbcaf95757a79baf90b6336b4a79e15780d824b
5
5
  SHA512:
6
- metadata.gz: 82458fb940a2d07acd9a2ae91f4b6abc71b25e3acb43c297026de425998a9b666441c2c10d8f206c5a26a85bd76cd947fc498d0f4e092bfd9e43e06b0819ddfe
7
- data.tar.gz: 36447c612f393d0c1cae07ddf88380532346eae60828114389e4e0f741ce08cdbc65e13c62b19fd704493d1867a962141d6ecc76ff4b4089b24e6678aa4cb690
6
+ metadata.gz: b53fca4a9a5d211438f38e8c97768b2f84d9513e78adfc10282f1472bd8346e8aa8801659cff543f77d19909bc4588d3f987ca2ee65e909529b48585e5eeabfe
7
+ data.tar.gz: 643f600065d4fad7c551bf57fd07ac3f316ac9a1f17f496f11aed4d67ec8618371247c1ce2b742d3d6b9a19525689e4e123328bae6e0db3b55e1b4acd21b7a4a
@@ -6,7 +6,7 @@ require 'open-uri'
6
6
  module SelfSDK
7
7
  module Chat
8
8
  class FileObject
9
- attr_accessor :link, :mime, :content, :key, :nonce, :ciphertext
9
+ attr_accessor :name, :link, :mime, :content, :key, :nonce, :ciphertext
10
10
 
11
11
  def initialize(token, url)
12
12
  @token = token
@@ -35,7 +35,22 @@ module SelfSDK
35
35
  # Incoming objects
36
36
  def build_from_object(input)
37
37
  # Download from CDN
38
- ciphertext = URI.open(input[:link], "Authorization" => "Bearer #{@token}").read
38
+ ciphertext = ""
39
+ 5.times do
40
+ begin
41
+ ciphertext = URI.open(input[:link], "Authorization" => "Bearer #{@token}").read
42
+ break
43
+ rescue => e
44
+ SelfSDK.logger.info e.message
45
+ SelfSDK.logger.info e.backtrace.join("\n")
46
+ sleep 1
47
+ end
48
+ end
49
+
50
+ if ciphertext.empty?
51
+ SelfSDK.logger.warn "unable to process incoming object"
52
+ return
53
+ end
39
54
 
40
55
  @content = ciphertext
41
56
  @key = nil
data/lib/messages/fact.rb CHANGED
@@ -14,14 +14,11 @@ module SelfSDK
14
14
  end
15
15
 
16
16
  def parse(fact)
17
- @name = SelfSDK::fact_name(fact[:fact])
18
-
19
- @operator = ""
20
- @operator = SelfSDK::operator(fact[:operator]) if fact[:operator]
21
-
17
+ @name = @messaging.source.normalize_fact_name! fact[:fact]
18
+ @operator = @messaging.source.normalize_operator!(fact[:operator])
22
19
  @sources = []
23
20
  fact[:sources]&.each do |s|
24
- @sources << SelfSDK::source(s)
21
+ @sources << @messaging.source.normalize_source!(s)
25
22
  end
26
23
 
27
24
  @expected_value = fact[:expected_value] || ""
@@ -43,7 +43,7 @@ module SelfSDK
43
43
  end
44
44
 
45
45
  def fact(name)
46
- name = SelfSDK::fact_name(name)
46
+ name = @messaging.source.normalize_fact_name!(name)
47
47
  @facts.select{|f| f.name == name}.first
48
48
  end
49
49
 
data/lib/messaging.rb CHANGED
@@ -17,7 +17,7 @@ module SelfSDK
17
17
  DEFAULT_STORAGE_DIR="./.self_storage"
18
18
  ON_DEMAND_CLOSE_CODE=3999
19
19
 
20
- attr_accessor :client, :jwt, :device_id, :ack_timeout, :timeout, :type_observer, :uuid_observer, :encryption_client
20
+ attr_accessor :client, :jwt, :device_id, :ack_timeout, :timeout, :type_observer, :uuid_observer, :encryption_client, :source
21
21
 
22
22
  # RestClient initializer
23
23
  #
@@ -47,6 +47,7 @@ module SelfSDK
47
47
  FileUtils.mkdir_p @storage_dir unless File.exist? @storage_dir
48
48
  @offset_file = "#{@storage_dir}/#{@jwt.id}:#{@device_id}.offset"
49
49
  @offset = read_offset
50
+ @source = SelfSDK::Sources.new("#{__dir__}/sources.json")
50
51
  migrate_old_storage_format
51
52
 
52
53
  unless options.include? :no_crypto
@@ -283,7 +284,7 @@ module SelfSDK
283
284
  end
284
285
 
285
286
  def subscribe(type, &block)
286
- type = SelfSDK::message_type(type) if type.is_a? Symbol
287
+ type = @source.message_type(type) if type.is_a? Symbol
287
288
  @type_observer[type] = { block: block }
288
289
  end
289
290
 
@@ -62,6 +62,10 @@ module SelfSDK
62
62
  return req.send_message
63
63
  end
64
64
 
65
+ if opts[:async] == true
66
+ return req.send_message
67
+ end
68
+
65
69
  # Otherwise the request is synchronous
66
70
  req.request
67
71
  end
@@ -135,13 +139,13 @@ module SelfSDK
135
139
  fs = []
136
140
  facts.each do |f|
137
141
  fact = if f.is_a?(Hash)
138
- f
139
- else
140
- { fact: f }
141
- end
142
+ f
143
+ else
144
+ { fact: f }
145
+ end
142
146
  # validate_fact!(fact)
143
147
  fs << fact
144
- end
148
+ end
145
149
  fs
146
150
  end
147
151
 
@@ -152,67 +156,72 @@ module SelfSDK
152
156
  raise 'provided fact does not specify a name' if f[:fact].empty?
153
157
  return unless f.has_key? :sources
154
158
 
155
- valid_sources = [ SOURCE_USER_SPECIFIED,
156
- SOURCE_PASSPORT,
157
- SOURCE_DRIVING_LICENSE,
158
- SOURCE_IDENTITY_CARD,
159
- SOURCE_TWITTER,
160
- SOURCE_LINKEDIN,
161
- SOURCE_FACEBOK ]
162
- factsForPassport = [ FACT_DOCUMENT_NUMBER,
163
- FACT_SURNAME,
164
- FACT_GIVEN_NAMES,
165
- FACT_DATE_OF_BIRTH,
166
- FACT_DATE_OF_EXPIRATION,
167
- FACT_SEX,
168
- FACT_NATIONALITY,
169
- FACT_COUNTRY_OF_ISSUANCE ]
170
-
171
- factsForDL = [ FACT_DOCUMENT_NUMBER,
172
- FACT_SURNAME,
173
- FACT_GIVEN_NAMES,
174
- FACT_DATE_OF_BIRTH,
175
- FACT_DATE_OF_ISSUANCE,
176
- FACT_DATE_OF_EXPIRATION,
177
- FACT_ADDRESS,
178
- FACT_ISSUING_AUTHORITY,
179
- FACT_PLACE_OF_BIRTH,
180
- FACT_COUNTRY_OF_ISSUANCE ]
181
-
182
- factsForUser = [ FACT_DOCUMENT_NUMBER,
183
- FACT_DISPLAY_NAME,
184
- FACT_EMAIL,
185
- FACT_PHONE ]
186
-
187
- factsForTwitter = [ FACT_ACCOUNT_ID, FACT_NICKNAME ]
188
- factsForLinkedin = [ FACT_ACCOUNT_ID, FACT_NICKNAME ]
189
- factsForFacebook = [ FACT_ACCOUNT_ID, FACT_NICKNAME ]
190
-
159
+ valid_sources = [SOURCE_USER_SPECIFIED,
160
+ SOURCE_PASSPORT,
161
+ SOURCE_DRIVING_LICENSE,
162
+ SOURCE_IDENTITY_CARD,
163
+ SOURCE_TWITTER,
164
+ SOURCE_LINKEDIN,
165
+ SOURCE_FACEBOK]
166
+ fact_for_passport = [FACT_DOCUMENT_NUMBER,
167
+ FACT_SURNAME,
168
+ FACT_GIVEN_NAMES,
169
+ FACT_DATE_OF_BIRTH,
170
+ FACT_DATE_OF_EXPIRATION,
171
+ FACT_SEX,
172
+ FACT_NATIONALITY,
173
+ FACT_COUNTRY_OF_ISSUANCE]
174
+
175
+ facts_for_dl = [FACT_DOCUMENT_NUMBER,
176
+ FACT_SURNAME,
177
+ FACT_GIVEN_NAMES,
178
+ FACT_DATE_OF_BIRTH,
179
+ FACT_DATE_OF_ISSUANCE,
180
+ FACT_DATE_OF_EXPIRATION,
181
+ FACT_ADDRESS,
182
+ FACT_ISSUING_AUTHORITY,
183
+ FACT_PLACE_OF_BIRTH,
184
+ FACT_COUNTRY_OF_ISSUANCE]
185
+
186
+ facts_for_user = [FACT_DOCUMENT_NUMBER,
187
+ FACT_DISPLAY_NAME,
188
+ FACT_EMAIL,
189
+ FACT_PHONE]
190
+
191
+ facts_for_twitter = [FACT_ACCOUNT_ID, FACT_NICKNAME]
192
+ facts_for_linkedin = [FACT_ACCOUNT_ID, FACT_NICKNAME]
193
+ facts_for_facebook = [FACT_ACCOUNT_ID, FACT_NICKNAME]
194
+ facts_for_live = [FACT_SELFIE]
195
+
191
196
  f[:sources].each do |s|
192
197
  raise errInvalidSource unless valid_sources.include? s.to_s
193
198
 
194
199
  if s.to_s == SOURCE_PASSPORT || s.to_s == SOURCE_IDENTITY_CARD
195
- raise errInvalidFactToSource unless factsForPassport.include? f[:fact]
200
+ raise errInvalidFactToSource unless fact_for_passport.include? f[:fact]
196
201
  end
197
202
 
198
203
  if s.to_s == SOURCE_DRIVING_LICENSE
199
- raise errInvalidFactToSource unless factsForDL.include? f[:fact]
204
+ raise errInvalidFactToSource unless facts_for_dl.include? f[:fact]
200
205
  end
201
206
 
202
207
  if s.to_s == SOURCE_USER_SPECIFIED
203
- raise errInvalidFactToSource unless factsForUser.include? f[:fact].to_s
208
+ raise errInvalidFactToSource unless facts_for_user.include? f[:fact].to_s
204
209
  end
205
210
 
206
211
  if s.to_s == SOURCE_TWITTER
207
- raise errInvalidFactToSource unless factsForTwitter.include? f[:fact].to_s
212
+ raise errInvalidFactToSource unless facts_for_twitter.include? f[:fact].to_s
208
213
  end
209
214
 
210
215
  if s.to_s == SOURCE_LINKEDIN
211
- raise errInvalidFactToSource unless factsForLinkedin.include? f[:fact].to_s
216
+ raise errInvalidFactToSource unless facts_for_linkedin.include? f[:fact].to_s
212
217
  end
213
218
 
214
219
  if s.to_s == SOURCE_FACEBOOK
215
- raise errInvalidFactToSource unless factsForFacebok.include? f[:fact].to_s
220
+ raise errInvalidFactToSource unless facts_for_facebook.include? f[:fact].to_s
221
+ end
222
+
223
+ if s.to_s == SOURCE_LIVE
224
+ raise errInvalidFactToSource unless facts_for_live.include? f[:fact].to_s
216
225
  end
217
226
  end
218
227
  end
data/lib/sources.rb CHANGED
@@ -2,38 +2,95 @@
2
2
 
3
3
  # frozen_string_literal: true
4
4
 
5
+ require "json"
5
6
  module SelfSDK
6
- FACT_EMAIL = "email_address"
7
- FACT_PHONE = "phone_number"
8
- FACT_DISPLAY_NAME = "display_name"
9
- FACT_DOCUMENT_NUMBER = "document_number"
10
- FACT_GIVEN_NAMES = "given_names"
11
- FACT_SURNAME = "surname"
12
- FACT_SEX = "sex"
13
- FACT_ISSUING_AUTHORITY = "issuing_authority"
14
- FACT_NATIONALITY = "nationality"
15
- FACT_ADDRESS = "address"
16
- FACT_PLACE_OF_BIRTH = "place_of_birth"
17
- FACT_DATE_OF_BIRTH = "date_of_birth"
18
- FACT_DATE_OF_ISSUANCE = "date_of_issuance"
19
- FACT_DATE_OF_EXPIRATION = "date_of_expiration"
20
- FACT_VALID_FROM = "valid_from"
21
- FACT_VALID_TO = "valid_to"
22
- FACT_CATEGORIES = "categories"
23
- FACT_SORT_CODE = "sort_code"
24
- FACT_COUNTRY_OF_ISSUANCE = "country_of_issuance"
25
- FACT_ACCOUNT_ID = "account_id"
26
- FACT_NICKNAME = "nickname"
7
+ class Sources
8
+ def initialize(sources_file)
9
+ data = JSON.parse('{
10
+ "sources": {
11
+ "user_specified": [
12
+ "document_number",
13
+ "display_name",
14
+ "email_address",
15
+ "phone_number"
16
+ ],
17
+ "passport": [
18
+ "document_number",
19
+ "surname",
20
+ "given_names",
21
+ "date_of_birth",
22
+ "date_of_expiration",
23
+ "sex",
24
+ "nationality",
25
+ "country_of_issuance"
26
+ ],
27
+ "driving_license": [
28
+ "document_number",
29
+ "surname",
30
+ "given_names",
31
+ "date_of_birth",
32
+ "date_of_issuance",
33
+ "date_of_expiration",
34
+ "address",
35
+ "issuing_authority",
36
+ "place_of_birth"
37
+ ],
38
+ "identity_card": [
39
+ "document_number",
40
+ "surname",
41
+ "given_names",
42
+ "date_of_birth",
43
+ "date_of_expiration",
44
+ "sex",
45
+ "nationality",
46
+ "country_of_issuance"
47
+ ],
48
+ "twitter": [
49
+ "account_id",
50
+ "nickname"
51
+ ],
52
+ "linkedin": [
53
+ "account_id",
54
+ "nickname"
55
+ ],
56
+ "facebook": [
57
+ "account_id",
58
+ "nickname"
59
+ ],
60
+ "live": [
61
+ "selfie_verification"
62
+ ]
63
+ }
64
+ }')
65
+ @sources = data["sources"]
66
+ @facts = []
67
+ @sources.each do |source, facts|
68
+ @facts.push(*facts)
69
+ end
70
+ end
71
+
72
+ def normalize_fact_name!(fact)
73
+ fact = fact.to_s
74
+ raise "invalid fact '#{fact}'" unless @facts.include?(fact)
75
+ fact
76
+ end
77
+
78
+ def validate_source!(source)
79
+ raise "invalid source '#{source}'" unless @sources.keys.include?(source.to_s)
80
+ end
81
+
82
+ def normalize_operator!(input)
83
+ return "" unless input
27
84
 
28
- SOURCE_USER_SPECIFIED = "user_specified"
29
- SOURCE_PASSPORT = "passport"
30
- SOURCE_DRIVING_LICENSE = "driving_license"
31
- SOURCE_IDENTITY_CARD = "identity_card"
32
- SOURCE_TWITTER = "twitter"
33
- SOURCE_LINKEDIN = "linkedin"
34
- SOURCE_FACEBOOK = "facebook"
85
+ operators = { equals: '==',
86
+ different: '!=',
87
+ great_or_equal_than: '>=',
88
+ less_or_equal: '<=',
89
+ great_than: '>',
90
+ less_than: '<' }
91
+ get(operators, input, "operator")
92
+ end
35
93
 
36
- class << self
37
94
  def message_type(s)
38
95
  types = { authentication_request: SelfSDK::Messages::AuthenticationReq::MSG_TYPE,
39
96
  authentication_response: SelfSDK::Messages::AuthenticationResp::MSG_TYPE,
@@ -51,51 +108,7 @@ module SelfSDK
51
108
  return types[s]
52
109
  end
53
110
 
54
- def operator(input)
55
- operators = { equals: '==',
56
- different: '!=',
57
- great_or_equal_than: '>=',
58
- less_or_equal: '<=',
59
- great_than: '>',
60
- less_than: '<' }
61
- get(operators, input, "operator")
62
- end
63
-
64
- def fact_name(input)
65
- facts = { email_address: FACT_EMAIL,
66
- phone_number: FACT_PHONE,
67
- display_name: FACT_DISPLAY_NAME,
68
- document_number: FACT_DOCUMENT_NUMBER,
69
- given_names: FACT_GIVEN_NAMES,
70
- surname: FACT_SURNAME,
71
- sex: FACT_SEX,
72
- issuing_authority: FACT_ISSUING_AUTHORITY,
73
- nationality: FACT_NATIONALITY,
74
- address: FACT_ADDRESS,
75
- place_of_birth: FACT_PLACE_OF_BIRTH,
76
- date_of_birth: FACT_DATE_OF_BIRTH,
77
- date_of_issuance: FACT_DATE_OF_ISSUANCE,
78
- date_of_expiration: FACT_DATE_OF_EXPIRATION,
79
- valid_from: FACT_VALID_FROM,
80
- valid_to: FACT_VALID_TO,
81
- categories: FACT_CATEGORIES,
82
- sort_code: FACT_SORT_CODE,
83
- country_of_issuance: FACT_COUNTRY_OF_ISSUANCE,
84
- account_id: FACT_ACCOUNT_ID,
85
- nickname: FACT_NICKNAME }
86
- get(facts, input, "fact")
87
- end
88
-
89
- def source(input)
90
- sources = { user_specified: SOURCE_USER_SPECIFIED,
91
- passport: SOURCE_PASSPORT,
92
- driving_license: SOURCE_DRIVING_LICENSE,
93
- identity_card: SOURCE_IDENTITY_CARD,
94
- twitter: SOURCE_TWITTER,
95
- linkedin: SOURCE_LINKEDIN,
96
- facebook: SOURCE_FACEBOOK }
97
- get(sources, input, "source")
98
- end
111
+ private
99
112
 
100
113
  def get(options, input, option_type)
101
114
  if input.is_a? Symbol
@@ -105,6 +118,5 @@ module SelfSDK
105
118
  raise "invalid #{option_type} '#{input}'" unless options.values.include? input
106
119
  input
107
120
  end
108
-
109
121
  end
110
122
  end
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.192
4
+ version: 0.0.195
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aldgate Ventures