selfsdk 0.0.143 → 0.0.148

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d317a3c78c03af0c8882cf280a3811060d97b5fbfa1dd6c2261bfe8c1246d209
4
- data.tar.gz: e346b04c24246db81a29f4d366d4af858f3936961396a5459ce6ebc446bfa468
3
+ metadata.gz: '0489757472503790f285fcdfce314e52981f082b7b31a4afec79a47c22adcff3'
4
+ data.tar.gz: 5a1cb3d7ec828961e8329760336df729e66eb718e281d1b87c81f5f82f86a291
5
5
  SHA512:
6
- metadata.gz: 6bd2d793deae3a91747ded4371d99a54f35979c494993be3cdb3514aef520f7b83354852d932c4ecf057cb6a08c3cf9502ab974d820d0b9ae87ba13eb6bd337b
7
- data.tar.gz: be302ede9fb1498e2b9572bbb7ff6b4ff2a4fce9dfb326f223462869e3956319b8582a925f299beed23c0937ff85f23077edcaac7c4e0240644e695a3265976d
6
+ metadata.gz: 1c86af6a558c41be3aec63ac26c394663202bfd83d1d2fc11ddd0ec7677d080108cc8caac456f397212b7ad0bad3c9990277f0fec686b430f934b4fcfe8c8990
7
+ data.tar.gz: 265155454c1f5c2efbbf7aa8f79c9525e1062d1a3ec47a6fd09230c44cb939aba0210ae596aaccbe9a916e748a7757a4c09225a8665ed8a0baa29d35d309ed0d
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'
@@ -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,13 +40,12 @@ module SelfSDK
38
40
 
39
41
  protected
40
42
 
41
- def proto
42
- @to_device = @client.devices(@to).first
43
+ def proto(to_device)
43
44
  Msgproto::Message.new(type: Msgproto::MsgType::MSG,
44
45
  sender: "#{@jwt.id}:#{@messaging.device_id}",
45
46
  id: @id,
46
- recipient: "#{@to}:#{@to_device}",
47
- ciphertext: encrypt_message(@jwt.prepare(body), @to, @to_device))
47
+ recipient: "#{@to}:#{to_device}",
48
+ ciphertext: encrypt_message(@jwt.prepare(body), @to, to_device))
48
49
  end
49
50
 
50
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,14 +87,8 @@ module SelfSDK
85
87
 
86
88
  protected
87
89
 
88
- def proto
89
- devices = if @intermediary.nil?
90
- @client.devices(@to)
91
- else
92
- @client.devices(@intermediary)
93
- end
94
- @to_device = devices.first
95
-
90
+ def proto(to_device)
91
+ @to_device = to_device
96
92
  if @intermediary.nil?
97
93
  recipient = "#{@to}:#{@to_device}"
98
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_DATEOF_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.143
4
+ version: 0.0.148
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aldgate Ventures