selfsdk 0.0.181 → 0.0.185

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: 391f652b3009218dc6e2374671e7fe85afd3a10aa0b248dd8d342c449290648b
4
- data.tar.gz: 9eaec2daf495fbd3b52e0845bc35283c8143c3a83d8dfeeff1600e9469737536
3
+ metadata.gz: 46b877bce1cf941473947fe1980fcc28dd2998a4bf19781a8eb7563b50e5576d
4
+ data.tar.gz: bcaa5355a79c64e88e846fed291f83f23034258817611e3bf23810fd9e6f57e6
5
5
  SHA512:
6
- metadata.gz: 6248153eb71713ae24a0d4c3bcc4ba5632272a7ac87ce1a7e6eec82cbb2f5a74ce5a1650499cc37e56545b2d09b9e947c9b7b3b63c465f2ecd36060d1a45559c
7
- data.tar.gz: ddd5bf11393639aedb9d092eafacc6f92d1732477b461e934e9cfaa9fc911cf9e0fa9608346c62cdf1fd1496c977927ef57cd67440fa5cf3a4938aa165e8bad4
6
+ metadata.gz: 6365053015bbf9aff47e00eb1d40fd9a2609e1353404abab7389ce37747a3792de36c5d30e1dc3e85f3d57a2c2fe1f5de2219bf549b8008e94908974fd8f0dee
7
+ data.tar.gz: ff241c95f89d25f006d1ed74cf890b7cb9c6db7580fb1e9695b082fca8200f14282b2023b7aa3b0388201c190f905e8f9e5cfa4c4ba251d693f26e1e92df3372
data/lib/crypto.rb CHANGED
@@ -47,9 +47,9 @@ module SelfSDK
47
47
 
48
48
  begin
49
49
  session_with_bob = get_outbound_session_with_bob(r[:id], r[:device_id], session_file_name)
50
- rescue
50
+ rescue => e
51
51
  ::SelfSDK.logger.warn(" there is a problem adding group participant #{r[:id]}:#{r[:device_id]}, skipping...")
52
- ::SelfSDK.logger.warn(error)
52
+ ::SelfSDK.logger.warn(e)
53
53
  next
54
54
  end
55
55
 
@@ -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,7 @@ 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)
37
38
 
38
39
  @intermediary = if opts.include?(:intermediary)
39
40
  opts[:intermediary]
@@ -89,6 +90,7 @@ module SelfSDK
89
90
  }
90
91
  b[:options] = @options unless (@options.nil? || @options == false)
91
92
  b[:description] = @description unless (@description.nil? || @description.empty?)
93
+ b[:allowed_until] = (SelfSDK::Time.now + @allowed_for).strftime('%FT%TZ') unless @allowed_for.nil?
92
94
  b
93
95
  end
94
96
 
@@ -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/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,7 @@ 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.
43
44
  # @return [Object] SelfSDK:::Messages::FactRequest
44
45
  def request(selfid, facts, opts = {}, &block)
45
46
  SelfSDK.logger.info "authenticating #{selfid}"
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.181
4
+ version: 0.0.185
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