selfsdk 0.0.144 → 0.0.149

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: d9d49a7cde97a88c5c56c6233b964b72c66d9b046b2521cac189475646be55f2
4
- data.tar.gz: 600b68b342c99830aba799eb13da1650d02cecd4bd824aeb38f51c768c77a13a
3
+ metadata.gz: 7d487478c6ceb2f7fb8608d962166ff216881c4103a27f58e5af4f251546965d
4
+ data.tar.gz: a6acca2829e1be56e53f254d8bee1ffb3292b8583e50bf73a1a0f2eba829cc99
5
5
  SHA512:
6
- metadata.gz: 3c7989e1245b7b2993e4c5784373d05c25870a1e4e695da1a49571e5ada8d779fb90c5d5f37fd9174e3cef51b054655c9efdb8470f573a98bdfa10ea950d1d8c
7
- data.tar.gz: 8e30b0e94b496efdc80f6dc4d5bdb655e8236ff098880bf28f46bc8433f08182fe7bfca3942abe893cfd698f8be720ae598611ae24ea6c98b4adfac2db1c9c5b
6
+ metadata.gz: cb153ee5559cac115d6d2a71d8502d82e07b8fb50207e0746c10c267be3d9accdd90a0a09e60546690315e91904bc7399e34abcb151fdcdc8415f7ada534b283
7
+ data.tar.gz: f72d24cef7b29a17e2ab4dde6e636925a3163f3b8379a7ae5701d4013c448bfdb67727eba8bde49279625ea1da72e1166d9e90435898995bfdac206701331739
data/lib/acl.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # frozen_string_literal: true
2
4
 
3
5
  require 'date'
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  module SelfSDK
2
4
  class Authenticated
3
5
  attr_accessor :payload, :uuid, :selfsdk, :status
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # frozen_string_literal: true
2
4
 
3
5
  require 'httparty'
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  require 'self_crypto'
2
4
 
3
5
  module SelfSDK
@@ -44,7 +46,8 @@ module SelfSDK
44
46
  res = @client.get("/v1/identities/#{recipient}/devices/#{recipient_device}/pre_keys")
45
47
 
46
48
  if res.code != 200
47
- Selfid.logger.error "identity response : #{res.body[:message]}"
49
+ b = JSON.parse(res.body)
50
+ ::SelfSDK.logger.error "identity response : #{b['message']}"
48
51
  raise "could not get identity pre_keys"
49
52
  end
50
53
 
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # frozen_string_literal: true
2
4
 
3
5
  require 'base64'
data/lib/log.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # frozen_string_literal: true
2
4
 
3
5
  require 'logger'
@@ -7,9 +9,11 @@ module SelfSDK
7
9
  attr_writer :logger
8
10
 
9
11
  def logger
10
- @logger ||= ::Logger.new($stdout).tap do |log|
11
- log.progname = name
12
- end
12
+ @logger ||= Logger.new('/dev/null')
13
+
14
+ #@logger ||= ::Logger.new($stdout).tap do |log|
15
+ # log.progname = name
16
+ #end
13
17
  end
14
18
  end
15
19
  end
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # frozen_string_literal: true
2
4
 
3
5
  module SelfSDK
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # frozen_string_literal: true
2
4
 
3
5
  require_relative 'base'
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # frozen_string_literal: true
2
4
 
3
5
  require_relative 'base'
@@ -38,16 +40,12 @@ module SelfSDK
38
40
 
39
41
  protected
40
42
 
41
- def proto
42
- app = @client.app(@jwt.id)
43
- raise "Your credits have expired, please log in to the developer portal and top up your account." if app[:paid_actions] == false
44
-
45
- @to_device = @client.devices(@to).first
43
+ def proto(to_device)
46
44
  Msgproto::Message.new(type: Msgproto::MsgType::MSG,
47
45
  sender: "#{@jwt.id}:#{@messaging.device_id}",
48
46
  id: @id,
49
- recipient: "#{@to}:#{@to_device}",
50
- ciphertext: encrypt_message(@jwt.prepare(body), @to, @to_device))
47
+ recipient: "#{@to}:#{to_device}",
48
+ ciphertext: encrypt_message(@jwt.prepare(body), @to, to_device))
51
49
  end
52
50
 
53
51
  end
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # frozen_string_literal: true
2
4
 
3
5
  require_relative 'base'
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # frozen_string_literal: true
2
4
 
3
5
  module SelfSDK
@@ -15,15 +17,24 @@ module SelfSDK
15
17
  end
16
18
 
17
19
  def request
18
- res = @messaging.send_and_wait_for_response(proto, self)
19
- SelfSDK.logger.info "synchronously messaging to #{@to}:#{@to_device}"
20
+ check_credits!
21
+ msgs = []
22
+ devices.each do |d|
23
+ msgs << proto(d)
24
+ end
25
+ res = @messaging.send_and_wait_for_response(msgs, self)
26
+ SelfSDK.logger.info "synchronously messaging to #{@to}:#{@d}"
20
27
  res
21
28
  end
22
29
 
23
30
  def send_message
24
- res = @messaging.send_message proto
25
- SelfSDK.logger.info "asynchronously requested information to #{@to}:#{@to_device}"
26
- res
31
+ check_credits!
32
+ res = []
33
+ devices.each do |d|
34
+ res << @messaging.send_message(proto(d))
35
+ SelfSDK.logger.info "asynchronously requested information to #{@to}:#{@d}"
36
+ end
37
+ res.first
27
38
  end
28
39
 
29
40
  def encrypt_message(message, recipient, recipient_device)
@@ -65,6 +76,17 @@ module SelfSDK
65
76
  raise ::StandardError.new("must define this method")
66
77
  end
67
78
 
79
+ def devices
80
+ return @client.devices(@to) if @intermediary.nil?
81
+
82
+ @client.devices(@intermediary)
83
+ end
84
+
85
+ def check_credits!
86
+ app = @client.app(@jwt.id)
87
+ raise "Your credits have expired, please log in to the developer portal and top up your account." if app[:paid_actions] == false
88
+ end
89
+
68
90
  private
69
91
 
70
92
  def get_payload(input)
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # frozen_string_literal: true
2
4
 
3
5
  require_relative 'attestation'
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # frozen_string_literal: true
2
4
 
3
5
  require_relative 'base'
@@ -85,17 +87,8 @@ module SelfSDK
85
87
 
86
88
  protected
87
89
 
88
- def proto
89
- app = @client.app(@jwt.id)
90
- raise "Your credits have expired, please log in to the developer portal and top up your account." if app[:paid_actions] == false
91
-
92
- devices = if @intermediary.nil?
93
- @client.devices(@to)
94
- else
95
- @client.devices(@intermediary)
96
- end
97
- @to_device = devices.first
98
-
90
+ def proto(to_device)
91
+ @to_device = to_device
99
92
  if @intermediary.nil?
100
93
  recipient = "#{@to}:#{@to_device}"
101
94
  ciphertext = encrypt_message(@jwt.prepare(body), @to, @to_device)
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # frozen_string_literal: true
2
4
 
3
5
  require_relative 'base'
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # frozen_string_literal: true
2
4
 
3
5
  require_relative "fact_request"
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # frozen_string_literal: true
2
4
 
3
5
  require 'json'
@@ -94,6 +96,7 @@ module SelfSDK
94
96
  # @param type [string] message type
95
97
  # @param request [hash] original message requesing information
96
98
  def send_custom(recipient, request_body)
99
+ # TODO (adriacidre) this is sending the message to the first device only
97
100
  @to_device = @client.devices(recipient).first
98
101
  send_message msg = Msgproto::Message.new(
99
102
  type: Msgproto::MsgType::MSG,
@@ -142,9 +145,11 @@ module SelfSDK
142
145
  # Sends a message and waits for the response
143
146
  #
144
147
  # @params msg [Msgproto::Message] message object to be sent
145
- def send_and_wait_for_response(msg, original)
146
- wait_for msg.id, original do
147
- send_message msg
148
+ def send_and_wait_for_response(msgs, original)
149
+ wait_for msgs.first.id, original do
150
+ msgs.each do |msg|
151
+ send_message msg
152
+ end
148
153
  end
149
154
  end
150
155
 
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # frozen_string_literal: true
2
4
 
3
5
  require 'time'
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # Generated by the protocol buffer compiler. DO NOT EDIT!
2
4
  # source: acl.proto
3
5
 
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # Generated by the protocol buffer compiler. DO NOT EDIT!
2
4
  # source: aclcommand.proto
3
5
 
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # Generated by the protocol buffer compiler. DO NOT EDIT!
2
4
  # source: auth.proto
3
5
 
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # Generated by the protocol buffer compiler. DO NOT EDIT!
2
4
  # source: errtype.proto
3
5
 
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # Generated by the protocol buffer compiler. DO NOT EDIT!
2
4
  # source: header.proto
3
5
 
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # Generated by the protocol buffer compiler. DO NOT EDIT!
2
4
  # source: message.proto
3
5
 
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # Generated by the protocol buffer compiler. DO NOT EDIT!
2
4
  # source: msgtype.proto
3
5
 
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # Generated by the protocol buffer compiler. DO NOT EDIT!
2
4
  # source: notification.proto
3
5
 
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # frozen_string_literal: true
2
4
 
3
5
  require 'securerandom'
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # frozen_string_literal: true
2
4
 
3
5
  # Namespace for classes and modules that handle SelfSDK gem
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # frozen_string_literal: true
2
4
 
3
5
  # Namespace for classes and modules that handle SelfSDK gem
@@ -130,14 +132,66 @@ module SelfSDK
130
132
  def prepare_facts(facts)
131
133
  fs = []
132
134
  facts.each do |f|
133
- fs << if f.is_a?(Hash)
135
+ fact = if f.is_a?(Hash)
134
136
  f
135
137
  else
136
138
  { fact: f }
137
139
  end
138
- end
140
+ validate_fact!(fact)
141
+ fs << fact
142
+ end
139
143
  fs
140
144
  end
145
+
146
+ def validate_fact!(f)
147
+ errInvalidFactToSource = 'provided source does not support given fact'
148
+ errInvalidSource = 'provided fact does not specify a valid source'
149
+
150
+ raise 'provided fact does not specify a name' if f[:fact].empty?
151
+ return unless f.has_key? :sources
152
+
153
+ valid_sources = [SOURCE_USER_SPECIFIED, SOURCE_PASSPORT, SOURCE_DRIVING_LICENSE, SOURCE_ID_CARD]
154
+ factsForPassport = [ FACT_DOCUMENT_NUMBER,
155
+ FACT_SURNAME,
156
+ FACT_GIVEN_NAMES,
157
+ FACT_DATE_OF_BIRTH,
158
+ FACT_DATE_OF_EXPIRATION,
159
+ FACT_SEX,
160
+ FACT_NATIONALITY,
161
+ FACT_COUNTRY_OF_ISSUANCE ]
162
+
163
+ factsForDL = [ FACT_DOCUMENT_NUMBER,
164
+ FACT_SURNAME,
165
+ FACT_GIVEN_NAMES,
166
+ FACT_DATE_OF_BIRTH,
167
+ FACT_DATE_OF_ISSUANCE,
168
+ FACT_DATE_OF_EXPIRATION,
169
+ FACT_ADDRESS,
170
+ FACT_ISSUING_AUTHORITY,
171
+ FACT_PLACE_OF_BIRTH,
172
+ FACT_COUNTRY_OF_ISSUANCE ]
173
+
174
+ factsForUser = [ FACT_DOCUMENT_NUMBER,
175
+ FACT_DISPLAY_NAME,
176
+ FACT_EMAIL,
177
+ FACT_PHONE ]
178
+
179
+ f[:sources].each do |s|
180
+ raise errInvalidSource unless valid_sources.include? s
181
+
182
+ if s == SOURCE_PASSPORT || s == SOURCE_ID_CARD
183
+ raise errInvalidFactToSource unless factsForPassport.include? f[:fact]
184
+ end
185
+
186
+ if s == SOURCE_DRIVING_LICENSE
187
+ raise errInvalidFactToSource unless factsForDL.include? f[:fact]
188
+ end
189
+
190
+ if s == SOURCE_USER_SPECIFIED
191
+ raise errInvalidFactToSource unless factsForUser.include? f[:fact]
192
+ end
193
+ end
194
+ end
141
195
  end
142
196
  end
143
197
  end
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # frozen_string_literal: true
2
4
 
3
5
  # Namespace for classes and modules that handle SelfSDK gem
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # frozen_string_literal: true
2
4
 
3
5
  # Namespace for classes and modules that handle SelfSDK gem
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # frozen_string_literal: true
2
4
 
3
5
  require 'base64'
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # frozen_string_literal: true
2
4
 
3
5
  module SelfSDK
@@ -15,10 +17,16 @@ module SelfSDK
15
17
  FACT_DATE_OF_BIRTH = "date_of_birth"
16
18
  FACT_DATE_OF_ISSUANCE = "date_of_issuance"
17
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"
18
25
 
19
26
  SOURCE_USER_SPECIFIED = "user_specified"
20
27
  SOURCE_PASSPORT = "passport"
21
28
  SOURCE_DRIVING_LICENSE = "driving_license"
29
+ SOURCE_ID_CARD = "identity_card"
22
30
 
23
31
  class << self
24
32
  def message_type(s)
@@ -61,7 +69,8 @@ module SelfSDK
61
69
  def source(input)
62
70
  sources = { user_specified: SOURCE_USER_SPECIFIED,
63
71
  passport: SOURCE_PASSPORT,
64
- driving_license: SOURCE_DRIVING_LICENSE }
72
+ driving_license: SOURCE_DRIVING_LICENSE,
73
+ id_card: SOURCE_ID_CARD }
65
74
  get(sources, input, "source")
66
75
  end
67
76
 
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.144
4
+ version: 0.0.149
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aldgate Ventures