selfsdk 0.0.184 → 0.0.187

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: 2c16f1734a708b0ebd37ca4fa0cea0e48db09344d4efb0654e5b4df6a37fd2d4
4
- data.tar.gz: 32313fa1c28a57370c43d7100bdacc06bad28f0722ba0589a63c24bd0327bfd2
3
+ metadata.gz: b2efe13e1c9449fe24bbfbe5754377fe0ef1dc3bd8a5815b6ccc77f854ab8339
4
+ data.tar.gz: 07c371286f2aa7fd97ac2a4423daeb2ac3b767be2bb54c0233a7d5db8d1bde91
5
5
  SHA512:
6
- metadata.gz: 9a015baa1ed364efcc422af5de6a54f87cbb953cdb45de7f397aa8cd2273b99c8ce4f6fbba0fc62f0ef803f38edf8155fbb1e9e14042b4f4ff76b391147da614
7
- data.tar.gz: dfec1973db212e016774292d57bda452727cadd201ecdb80ab0f507a97ff3df244887ffde06704a618de63e0d101c75b7e8c879ff983654892d9496a50db7889
6
+ metadata.gz: '0748ed14d36949e1a96b8299d325189ea0a8f554e2b31d95d0831763051c74f0440f6f319e1808372bc1f09a43c3da7035bf1554843df9adda6d1eecaa51eae6'
7
+ data.tar.gz: 73f72a6b7357359af3d07bb5067b718147a32395fdee1a24fca29a82adeaafe7956483860ab7e8b74864d9e2dbb4fef11e9193651dd79c41e56f1a21f9c65984
data/lib/crypto.rb CHANGED
@@ -141,12 +141,17 @@ module SelfSDK
141
141
  if File.exist?(session_file_name)
142
142
  # 7a) if carol's session file exists load the pickle from the file
143
143
  session_with_bob = SelfCrypto::Session.from_pickle(File.read(session_file_name), @storage_key)
144
- else
145
- # 7b-i) if you have not previously sent or received a message to/from bob,
146
- # you should extract the initial message from the group message intended
147
- # for your account id.
148
- m = SelfCrypto::GroupMessage.new(message.to_s).get_message("#{@client.jwt.id}:#{@device}")
144
+ end
145
+
146
+ # 7b-i) if you have not previously sent or received a message to/from bob,
147
+ # you should extract the initial message from the group message intended
148
+ # for your account id.
149
+ m = SelfCrypto::GroupMessage.new(message.to_s).get_message("#{@client.jwt.id}:#{@device}")
149
150
 
151
+ # if there is no session, create one
152
+ # if there is an existing session and we are sent a one time key message, check
153
+ # if it belongs to this current session and create a new inbound session if it doesn't
154
+ if session_with_bob.nil? || m.instance_of?(SelfCrypto::PreKeyMessage) and !session_with_bob.will_receive?(m)
150
155
  # 7b-ii) use the initial message to create a session for bob or carol
151
156
  session_with_bob = @account.inbound_session(m)
152
157
 
@@ -37,7 +37,7 @@ module SelfSDK
37
37
  end
38
38
 
39
39
  def validate!(original)
40
- raise ::StandardError.new("invalid origin") if @to != original.to
40
+ raise ::StandardError.new("invalid origin") if @to.split(":").first != original.to
41
41
  end
42
42
 
43
43
  def signed
@@ -0,0 +1,44 @@
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 DocumentSignResponse < Base
12
+ MSG_TYPE = "document.sign.resp"
13
+ DEFAULT_EXP_TIMEOUT = 900
14
+
15
+ attr_accessor :objects, :signed_objects
16
+
17
+ def initialize(messaging)
18
+ @typ = MSG_TYPE
19
+ super
20
+ end
21
+
22
+ def parse(input, envelope)
23
+ @input = input
24
+ @typ = SelfSDK::Messages::DocumentSignResponse::MSG_TYPE
25
+ @payload = get_payload(input)
26
+ @id = payload[:cid]
27
+ @from = payload[:iss]
28
+ @to = payload[:sub]
29
+ @expires = ::Time.parse(payload[:exp])
30
+ @issued = ::Time.parse(payload[:iat])
31
+ @audience = payload[:aud]
32
+ @status = payload[:status]
33
+ @objects = payload[:objects]
34
+ @signed_objects = payload[:signed_objects]
35
+ end
36
+
37
+ protected
38
+
39
+ def proto(to_device)
40
+ nil
41
+ end
42
+ end
43
+ end
44
+ end
@@ -35,6 +35,7 @@ module SelfSDK
35
35
  @description = opts.include?(:description) ? opts[:description] : nil
36
36
  @exp_timeout = opts.fetch(:exp_timeout, DEFAULT_EXP_TIMEOUT)
37
37
  @allowed_for = opts.fetch(:allowed_for, nil)
38
+ @auth = opts.fetch(:auth, false)
38
39
 
39
40
  @intermediary = if opts.include?(:intermediary)
40
41
  opts[:intermediary]
@@ -91,6 +92,7 @@ module SelfSDK
91
92
  b[:options] = @options unless (@options.nil? || @options == false)
92
93
  b[:description] = @description unless (@description.nil? || @description.empty?)
93
94
  b[:allowed_until] = (SelfSDK::Time.now + @allowed_for).strftime('%FT%TZ') unless @allowed_for.nil?
95
+ b[:auth] = @auth unless @auth.nil?
94
96
  b
95
97
  end
96
98
 
@@ -11,7 +11,7 @@ module SelfSDK
11
11
  class FactResponse < Base
12
12
  MSG_TYPE = "identities.facts.query.resp"
13
13
 
14
- attr_accessor :facts, :audience
14
+ attr_accessor :facts, :audience, :auth
15
15
 
16
16
  def parse(input, envelope=nil)
17
17
  @input = input
@@ -24,6 +24,7 @@ module SelfSDK
24
24
  @issued = ::Time.parse(payload[:iat])
25
25
  @audience = payload[:aud]
26
26
  @status = payload[:status]
27
+ @auth = payload[:auth]
27
28
  @facts = []
28
29
  payload[:facts] = [] if payload[:facts].nil?
29
30
  payload[:facts].each do |f|
@@ -69,7 +70,7 @@ module SelfSDK
69
70
  @facts.each do |fact|
70
71
  encoded_facts.push(fact.to_hash)
71
72
  end
72
-
73
+
73
74
  { typ: MSG_TYPE,
74
75
  iss: @jwt.id,
75
76
  sub: @sub || @to,
@@ -79,7 +80,8 @@ module SelfSDK
79
80
  cid: @id,
80
81
  jti: SecureRandom.uuid,
81
82
  status: @status,
82
- facts: encoded_facts }
83
+ facts: encoded_facts,
84
+ auth: @auth }
83
85
  end
84
86
 
85
87
  protected
@@ -12,6 +12,7 @@ require_relative "chat_message_delivered"
12
12
  require_relative "chat_invite"
13
13
  require_relative "chat_join"
14
14
  require_relative "chat_remove"
15
+ require_relative "document_sign_resp"
15
16
 
16
17
  module SelfSDK
17
18
  module Messages
@@ -59,6 +60,9 @@ module SelfSDK
59
60
  when SelfSDK::Messages::ChatJoin::MSG_TYPE
60
61
  m = ChatJoin.new(messaging)
61
62
  m.parse(body, envelope)
63
+ when SelfSDK::Messages::DocumentSignResponse::MSG_TYPE
64
+ m = DocumentSignResponse.new(messaging)
65
+ m.parse(body, envelope)
62
66
  else
63
67
  raise StandardError.new("Invalid message type #{payload[:typ]}.")
64
68
  end
data/lib/selfsdk.rb CHANGED
@@ -21,6 +21,7 @@ require_relative 'services/facts'
21
21
  require_relative 'services/identity'
22
22
  require_relative 'services/messaging'
23
23
  require_relative 'services/chat'
24
+ require_relative 'services/docs'
24
25
 
25
26
  # Namespace for classes and modules that handle Self interactions.
26
27
  module SelfSDK
@@ -88,6 +89,11 @@ module SelfSDK
88
89
  @chat ||= SelfSDK::Services::Chat.new(messaging, identity)
89
90
  end
90
91
 
92
+ # Provides access to SelfSDK::Services::Docs service
93
+ def docs
94
+ @docs ||= SelfSDK::Services::Docs.new(messaging, @client.self_url)
95
+ end
96
+
91
97
  def app_id
92
98
  client.jwt.id
93
99
  end
data/lib/services/auth.rb CHANGED
@@ -89,11 +89,11 @@ module SelfSDK
89
89
  body = @client.jwt.encode(request(selfid, opts))
90
90
 
91
91
  if @client.env.empty?
92
- return "https://joinself.page.link/?link=#{callback}%3Fqr=#{body}&apn=com.joinself.app"
92
+ return "https://links.joinself.com/?link=#{callback}%3Fqr=#{body}&apn=com.joinself.app"
93
93
  elsif @client.env == 'development'
94
- return "https://joinself.page.link/?link=#{callback}%3Fqr=#{body}&apn=com.joinself.app.dev"
94
+ return "https://links.joinself.com/?link=#{callback}%3Fqr=#{body}&apn=com.joinself.app.dev"
95
95
  end
96
- "https://joinself.page.link/?link=#{callback}%3Fqr=#{body}&apn=com.joinself.app.#{@client.env}"
96
+ "https://#{@client.env}.links.joinself.com/?link=#{callback}%3Fqr=#{body}&apn=com.joinself.app.#{@client.env}"
97
97
  end
98
98
 
99
99
  # Adds an observer for an authentication response
@@ -0,0 +1,71 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
3
+ # frozen_string_literal: true
4
+
5
+ # Namespace for classes and modules that handle SelfSDK gem
6
+ module SelfSDK
7
+ # Namespace for classes and modules that handle selfsdk-gem public ui
8
+ module Services
9
+ # Input class to handle document requests on self network.
10
+ class Docs
11
+ attr_accessor :app_id
12
+
13
+ # Creates a new docs service.
14
+ # Docs service mainly allows you to send document signature requests.
15
+ #
16
+ # @param messaging [SelfSDK::Messaging] messaging object.
17
+ #
18
+ # @return [SelfSDK::Services::Docs] docs service.
19
+ def initialize(messaging, url)
20
+ @messaging = messaging
21
+ @self_url = url
22
+ end
23
+
24
+ # Sends a signature request to the specified user.
25
+ #
26
+ # @param recipient [string] the recipient of the request.
27
+ # @param body [string] the message to be displayed to the user.
28
+ # @param objects [Array] array of objects to be signed. provide an empty array if
29
+ # you just want the body to be signed.
30
+ # @yield [request] Invokes the given block when a response is received.
31
+ def request_signature(recipient, body, objects, &block)
32
+ jti = SecureRandom.uuid
33
+ req = {
34
+ jti: jti,
35
+ typ: "document.sign.req",
36
+ aud: recipient,
37
+ msg: body,
38
+ objects: [],
39
+ }
40
+
41
+ auth_token = @messaging.client.jwt.auth_token
42
+ objects.each do |o|
43
+ req[:objects] << SelfSDK::Chat::FileObject.new(auth_token, @self_url).build_from_data(
44
+ o[:name],
45
+ o[:data],
46
+ o[:mime]
47
+ ).to_payload
48
+ end
49
+
50
+ if block_given?
51
+ @messaging.client.set_observer(OpenStruct.new({
52
+ id: jti,
53
+ to: recipient,
54
+ from: @messaging.client.jwt.id
55
+ }), timeout: 60 * 60 * 10, &block)
56
+
57
+ return @messaging.send(recipient, req)
58
+ end
59
+
60
+ @messaging.send(recipient, req)
61
+ end
62
+
63
+ # Subscribes to all document sign responses.
64
+ #
65
+ # @yield [request] Invokes the given block when a response is received.
66
+ def subscribe(&block)
67
+ @messaging.subscribe(:document_sign_response, &block)
68
+ end
69
+ end
70
+ end
71
+ end
@@ -8,7 +8,7 @@ module SelfSDK
8
8
  module Services
9
9
  # Self provides this self-hosted verified intermediary.
10
10
  DEFAULT_INTERMEDIARY = "self_intermediary"
11
- # Input class to handle authentication requests on self network.
11
+ # Input class to handle fact requests on self network.
12
12
  class Facts
13
13
  # Creates a new facts service.
14
14
  # Facts service mainly manages fact requests against self users wanting
@@ -32,7 +32,7 @@ module SelfSDK
32
32
  # @param selfid [string] the receiver of the authentication request.
33
33
  # @param [Hash] opts the options to authenticate.
34
34
  # @option opts [String] :cid The unique identifier of the authentication request.
35
- # @yield [request] Invokes the block with a street name for each result.
35
+ # @yield [request] Invokes the given block when a response is received.
36
36
  # @return [Object] SelfSDK:::Messages::FactRequest
37
37
  #
38
38
  # @overload request(selfid, facts, opts = {})
@@ -41,6 +41,7 @@ module SelfSDK
41
41
  # @option opts [String] :cid The unique identifier of the authentication request.
42
42
  # @option opts [Integer] :exp_timeout timeout in seconds to expire the request.
43
43
  # @option opts [Integer] :allowed_for number of seconds for enabling recurrent requests.
44
+ # @option opts [Boolean] :auth allows displaying the request as anuthentication request with facts.
44
45
  # @return [Object] SelfSDK:::Messages::FactRequest
45
46
  def request(selfid, facts, opts = {}, &block)
46
47
  SelfSDK.logger.info "authenticating #{selfid}"
@@ -116,11 +117,11 @@ module SelfSDK
116
117
  body = @client.jwt.encode(request(selfid, facts, opts))
117
118
 
118
119
  if @client.env.empty?
119
- return "https://joinself.page.link/?link=#{callback}%3Fqr=#{body}&apn=com.joinself.app"
120
+ return "https://links.joinself.com/?link=#{callback}%3Fqr=#{body}&apn=com.joinself.app"
120
121
  elsif @client.env == 'development'
121
- return "https://joinself.page.link/?link=#{callback}%3Fqr=#{body}&apn=com.joinself.app.dev"
122
+ return "https://links.joinself.com/?link=#{callback}%3Fqr=#{body}&apn=com.joinself.app.dev"
122
123
  end
123
- "https://joinself.page.link/?link=#{callback}%3Fqr=#{body}&apn=com.joinself.app.#{@client.env}"
124
+ "https://#{@client.env}.links.joinself.com/?link=#{callback}%3Fqr=#{body}&apn=com.joinself.app.#{@client.env}"
124
125
  end
125
126
 
126
127
  private
@@ -151,7 +152,13 @@ module SelfSDK
151
152
  raise 'provided fact does not specify a name' if f[:fact].empty?
152
153
  return unless f.has_key? :sources
153
154
 
154
- valid_sources = [SOURCE_USER_SPECIFIED, SOURCE_PASSPORT, SOURCE_DRIVING_LICENSE, SOURCE_IDENTITY_CARD]
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 ]
155
162
  factsForPassport = [ FACT_DOCUMENT_NUMBER,
156
163
  FACT_SURNAME,
157
164
  FACT_GIVEN_NAMES,
@@ -176,7 +183,11 @@ module SelfSDK
176
183
  FACT_DISPLAY_NAME,
177
184
  FACT_EMAIL,
178
185
  FACT_PHONE ]
179
-
186
+
187
+ factsForTwitter = [ FACT_ACCOUNT_ID, FACT_NICKNAME ]
188
+ factsForLinkedin = [ FACT_ACCOUNT_ID, FACT_NICKNAME ]
189
+ factsForFacebook = [ FACT_ACCOUNT_ID, FACT_NICKNAME ]
190
+
180
191
  f[:sources].each do |s|
181
192
  raise errInvalidSource unless valid_sources.include? s.to_s
182
193
 
@@ -191,6 +202,18 @@ module SelfSDK
191
202
  if s.to_s == SOURCE_USER_SPECIFIED
192
203
  raise errInvalidFactToSource unless factsForUser.include? f[:fact].to_s
193
204
  end
205
+
206
+ if s.to_s == SOURCE_TWITTER
207
+ raise errInvalidFactToSource unless factsForTwitter.include? f[:fact].to_s
208
+ end
209
+
210
+ if s.to_s == SOURCE_LINKEDIN
211
+ raise errInvalidFactToSource unless factsForLinkedin.include? f[:fact].to_s
212
+ end
213
+
214
+ if s.to_s == SOURCE_FACEBOOK
215
+ raise errInvalidFactToSource unless factsForFacebok.include? f[:fact].to_s
216
+ end
194
217
  end
195
218
  end
196
219
  end
data/lib/sources.rb CHANGED
@@ -22,11 +22,16 @@ module SelfSDK
22
22
  FACT_CATEGORIES = "categories"
23
23
  FACT_SORT_CODE = "sort_code"
24
24
  FACT_COUNTRY_OF_ISSUANCE = "country_of_issuance"
25
+ FACT_ACCOUNT_ID = "account_id"
26
+ FACT_NICKNAME = "nickname"
25
27
 
26
28
  SOURCE_USER_SPECIFIED = "user_specified"
27
29
  SOURCE_PASSPORT = "passport"
28
30
  SOURCE_DRIVING_LICENSE = "driving_license"
29
31
  SOURCE_IDENTITY_CARD = "identity_card"
32
+ SOURCE_TWITTER = "twitter"
33
+ SOURCE_LINKEDIN = "linkedin"
34
+ SOURCE_FACEBOOK = "facebook"
30
35
 
31
36
  class << self
32
37
  def message_type(s)
@@ -40,6 +45,7 @@ module SelfSDK
40
45
  chat_invite: SelfSDK::Messages::ChatInvite::MSG_TYPE,
41
46
  chat_join: SelfSDK::Messages::ChatJoin::MSG_TYPE,
42
47
  chat_remove: SelfSDK::Messages::ChatRemove::MSG_TYPE,
48
+ document_sign_response: SelfSDK::Messages::DocumentSignResponse::MSG_TYPE,
43
49
  }
44
50
  raise "invalid message type '#{s}'" unless types.key? s
45
51
  return types[s]
@@ -74,7 +80,9 @@ module SelfSDK
74
80
  valid_to: FACT_VALID_TO,
75
81
  categories: FACT_CATEGORIES,
76
82
  sort_code: FACT_SORT_CODE,
77
- country_of_issuance: FACT_COUNTRY_OF_ISSUANCE }
83
+ country_of_issuance: FACT_COUNTRY_OF_ISSUANCE,
84
+ account_id: FACT_ACCOUNT_ID,
85
+ nickname: FACT_NICKNAME }
78
86
  get(facts, input, "fact")
79
87
  end
80
88
 
@@ -82,7 +90,10 @@ module SelfSDK
82
90
  sources = { user_specified: SOURCE_USER_SPECIFIED,
83
91
  passport: SOURCE_PASSPORT,
84
92
  driving_license: SOURCE_DRIVING_LICENSE,
85
- identity_card: SOURCE_IDENTITY_CARD }
93
+ identity_card: SOURCE_IDENTITY_CARD,
94
+ twitter: SOURCE_TWITTER,
95
+ linkedin: SOURCE_LINKEDIN,
96
+ facebook: SOURCE_FACEBOOK }
86
97
  get(sources, input, "source")
87
98
  end
88
99
 
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.184
4
+ version: 0.0.187
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aldgate Ventures
@@ -345,6 +345,7 @@ files:
345
345
  - lib/messages/chat_message_delivered.rb
346
346
  - lib/messages/chat_message_read.rb
347
347
  - lib/messages/chat_remove.rb
348
+ - lib/messages/document_sign_resp.rb
348
349
  - lib/messages/fact.rb
349
350
  - lib/messages/fact_request.rb
350
351
  - lib/messages/fact_response.rb
@@ -354,6 +355,7 @@ files:
354
355
  - lib/selfsdk.rb
355
356
  - lib/services/auth.rb
356
357
  - lib/services/chat.rb
358
+ - lib/services/docs.rb
357
359
  - lib/services/facts.rb
358
360
  - lib/services/identity.rb
359
361
  - lib/services/messaging.rb