selfsdk 0.0.184 → 0.0.185

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: 2c16f1734a708b0ebd37ca4fa0cea0e48db09344d4efb0654e5b4df6a37fd2d4
4
- data.tar.gz: 32313fa1c28a57370c43d7100bdacc06bad28f0722ba0589a63c24bd0327bfd2
3
+ metadata.gz: 46b877bce1cf941473947fe1980fcc28dd2998a4bf19781a8eb7563b50e5576d
4
+ data.tar.gz: bcaa5355a79c64e88e846fed291f83f23034258817611e3bf23810fd9e6f57e6
5
5
  SHA512:
6
- metadata.gz: 9a015baa1ed364efcc422af5de6a54f87cbb953cdb45de7f397aa8cd2273b99c8ce4f6fbba0fc62f0ef803f38edf8155fbb1e9e14042b4f4ff76b391147da614
7
- data.tar.gz: dfec1973db212e016774292d57bda452727cadd201ecdb80ab0f507a97ff3df244887ffde06704a618de63e0d101c75b7e8c879ff983654892d9496a50db7889
6
+ metadata.gz: 6365053015bbf9aff47e00eb1d40fd9a2609e1353404abab7389ce37747a3792de36c5d30e1dc3e85f3d57a2c2fe1f5de2219bf549b8008e94908974fd8f0dee
7
+ data.tar.gz: ff241c95f89d25f006d1ed74cf890b7cb9c6db7580fb1e9695b082fca8200f14282b2023b7aa3b0388201c190f905e8f9e5cfa4c4ba251d693f26e1e92df3372
@@ -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
@@ -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
@@ -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 = {})
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.184
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