selfsdk 0.0.182 → 0.0.186

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: f69744dc023bc671a461138870259c77060a8631d447abe9e4da89df57fa2c19
4
- data.tar.gz: 0a906d47e3b30c43dab5f96ff58452fbb9280a91768516cdb318336598901823
3
+ metadata.gz: 537d89a4c6f35651b5c5935b12861a3b76966a34858fc8c0cce2e6a0c079a574
4
+ data.tar.gz: a1e8991eff4ccaf30dd7ee633a17009f43e68e383b28cedb29cd61977135b575
5
5
  SHA512:
6
- metadata.gz: 10feb47142b359f87b428719b5e5916ce7d3f173ca73be6ec7670149979ef2985850dbf9b2043cba6f847c5022031b6b45885c3c6930ef103d6303cfd8830524
7
- data.tar.gz: bfe025909daadde71071c161acaa389145deea760543aa328c5bd3c4d8da04e88da79918cde1f836d28232f50fe0f7837ca96fb08b04a5cf2addcc2ea7add8ed
6
+ metadata.gz: f2c2a074476b655870575194c68781a905b5a6186823c732c70a612d61baa530f2e10cc501b80013571119befcc9d0decd18dc55c15e999751eb908d7576e9d8
7
+ data.tar.gz: 7587e69db01c25ccaa558da3ef9f70d9a668c16d6b93c12b178f86ca8956f5a90b966e8107b9157a7211e6a2cb78ef801644792c1886ee0ea129c8d22363c5cc
@@ -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
@@ -34,6 +34,8 @@ module SelfSDK
34
34
  @options = opts.fetch(:options, false)
35
35
  @description = opts.include?(:description) ? opts[:description] : nil
36
36
  @exp_timeout = opts.fetch(:exp_timeout, DEFAULT_EXP_TIMEOUT)
37
+ @allowed_for = opts.fetch(:allowed_for, nil)
38
+ @auth = opts.fetch(:auth, false)
37
39
 
38
40
  @intermediary = if opts.include?(:intermediary)
39
41
  opts[:intermediary]
@@ -89,6 +91,8 @@ module SelfSDK
89
91
  }
90
92
  b[:options] = @options unless (@options.nil? || @options == false)
91
93
  b[:description] = @description unless (@description.nil? || @description.empty?)
94
+ b[:allowed_until] = (SelfSDK::Time.now + @allowed_for).strftime('%FT%TZ') unless @allowed_for.nil?
95
+ b[:auth] = @auth unless @auth.nil?
92
96
  b
93
97
  end
94
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/messaging.rb CHANGED
@@ -92,6 +92,11 @@ module SelfSDK
92
92
  send_message m
93
93
  end
94
94
 
95
+ def session?(identifier, device)
96
+ path = @encryption_client.session_path(identifier, device)
97
+ File.file?(path)
98
+ end
99
+
95
100
  # Send custom mmessage
96
101
  #
97
102
  # @param recipient [string] selfID to be requested
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
@@ -85,7 +86,12 @@ module SelfSDK
85
86
 
86
87
  # Provides access to SelfSDK::Services::Chat service
87
88
  def chat
88
- @chat ||= SelfSDK::Services::Chat.new(messaging, @client)
89
+ @chat ||= SelfSDK::Services::Chat.new(messaging, identity)
90
+ end
91
+
92
+ # Provides access to SelfSDK::Services::Docs service
93
+ def docs
94
+ @docs ||= SelfSDK::Services::Docs.new(messaging, @client.self_url)
89
95
  end
90
96
 
91
97
  def app_id
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
data/lib/services/chat.rb CHANGED
@@ -14,7 +14,9 @@ module SelfSDK
14
14
  def initialize(messaging, client)
15
15
  @messaging = messaging
16
16
  @client = client
17
- @app_id = @client.jwt.id
17
+ @app_id = @messaging.client.client.jwt.id
18
+ @auth_token = @messaging.client.client.jwt.auth_token
19
+ @self_url = @messaging.client.client.self_url
18
20
  end
19
21
 
20
22
  # Sends a message to a list of recipients.
@@ -32,7 +34,7 @@ module SelfSDK
32
34
  payload[:rid] = opts[:rid] if opts.key? :rid
33
35
  payload[:objects] = opts[:objects] if opts.key? :objects
34
36
 
35
- m = SelfSDK::Chat::Message.new(self, recipients, payload, @messaging.client.jwt.auth_token, @client.self_url)
37
+ m = SelfSDK::Chat::Message.new(self, recipients, payload, @auth_token, @self_url)
36
38
  _req = send(m.recipients, m.payload)
37
39
 
38
40
  m
@@ -41,8 +43,7 @@ module SelfSDK
41
43
  # Subscribes to an incoming chat message
42
44
  def on_message(opts = {}, &block)
43
45
  @messaging.subscribe :chat_message do |msg|
44
- puts "(#{msg.payload[:iss]}, #{msg.payload[:jti]})"
45
- cm = SelfSDK::Chat::Message.new(self, msg.payload[:aud], msg.payload, @messaging.client.jwt.auth_token, @client.self_url)
46
+ cm = SelfSDK::Chat::Message.new(self, msg.payload[:aud], msg.payload, @auth_token, @self_url)
46
47
 
47
48
  cm.mark_as_delivered unless opts[:mark_as_delivered] == false
48
49
  cm.mark_as_read if opts[:mark_as_read] == true
@@ -127,7 +128,7 @@ module SelfSDK
127
128
  members: members }
128
129
 
129
130
  if opts.key? :data
130
- obj = SelfSDK::Chat::FileObject.new(@messaging.client.jwt.auth_token, @client.self_url)
131
+ obj = SelfSDK::Chat::FileObject.new(@auth_token, @self_url)
131
132
  obj_payload = obj.build_from_data("", opts[:data], opts[:mime]).to_payload
132
133
  obj_payload.delete(:name)
133
134
  payload.merge! obj_payload
@@ -142,6 +143,12 @@ module SelfSDK
142
143
  # @param gid [string] group id.
143
144
  # @param members [array] list of group members.
144
145
  def join(gid, members)
146
+ # Allow incoming connections from the given members
147
+
148
+ # Create missing sessions with group members.
149
+ create_missing_sessions(members)
150
+
151
+ # Send joining confirmation.
145
152
  send(members, typ: 'chat.join', gid: gid, aud: gid)
146
153
  end
147
154
 
@@ -173,6 +180,31 @@ module SelfSDK
173
180
  end
174
181
  m
175
182
  end
183
+
184
+ # Group invites may come with members of the group we haven't set up a session
185
+ # previously, for those identitiese need to establish a session, but only if
186
+ # our identity appears before the others in the list members.
187
+ def create_missing_sessions(members)
188
+ return if members.empty?
189
+
190
+ posterior_members = false
191
+ requests = []
192
+
193
+ members.each do |m|
194
+ if posterior_members
195
+ @client.devices(m).each do |d|
196
+ continue unless @messaging.client.session?(m, d)
197
+
198
+ requests << @messaging.send("#{m}:#{d}", {
199
+ typ: 'sessions.create',
200
+ aud: m
201
+ })
202
+ end
203
+ end
204
+
205
+ posterior_members = true if m == @app_id
206
+ end
207
+ end
176
208
  end
177
209
  end
178
210
  end
@@ -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 = {})
@@ -40,6 +40,8 @@ module SelfSDK
40
40
  # @param [Hash] opts the options to authenticate.
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
+ # @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.
43
45
  # @return [Object] SelfSDK:::Messages::FactRequest
44
46
  def request(selfid, facts, opts = {}, &block)
45
47
  SelfSDK.logger.info "authenticating #{selfid}"
@@ -115,11 +117,11 @@ module SelfSDK
115
117
  body = @client.jwt.encode(request(selfid, facts, opts))
116
118
 
117
119
  if @client.env.empty?
118
- 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"
119
121
  elsif @client.env == 'development'
120
- 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"
121
123
  end
122
- "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}"
123
125
  end
124
126
 
125
127
  private
data/lib/sources.rb CHANGED
@@ -40,6 +40,7 @@ module SelfSDK
40
40
  chat_invite: SelfSDK::Messages::ChatInvite::MSG_TYPE,
41
41
  chat_join: SelfSDK::Messages::ChatJoin::MSG_TYPE,
42
42
  chat_remove: SelfSDK::Messages::ChatRemove::MSG_TYPE,
43
+ document_sign_response: SelfSDK::Messages::DocumentSignResponse::MSG_TYPE,
43
44
  }
44
45
  raise "invalid message type '#{s}'" unless types.key? s
45
46
  return types[s]
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.182
4
+ version: 0.0.186
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