selfsdk 0.0.223 → 0.0.225

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: e01c4dae273f3546f383e210f31b66d75a1d8b3154805e943a4f90ce8ff51f2b
4
- data.tar.gz: f9081aaeb82f33f593c635c83a64ab00dd2ea0f1e12a1f1e0ebded73e3d690cd
3
+ metadata.gz: a3984e978f7582e2bd3840787766747f29417a08835f7c0c7e8c88791ca6ec4e
4
+ data.tar.gz: 1b52143809c1551df704cc2b686577fa163aa284b9ac52ec082ccec752ef944c
5
5
  SHA512:
6
- metadata.gz: 3f42df63fda36b70919f5a23db332d39dd886225bbbdb6fe28dece6f8fb6581b3ea286f7e1e8ebca194a579ffe50049bee7fe18425f21ad712ab6ffc4787fb34
7
- data.tar.gz: c6fb329eb380e739963d94fa5e244bdd03c0d8207d4551f82fbe556a79fca94d1cc36838765ca3358700bc73caa33b963448f605d5c94843d35ea9e2f4a875cb
6
+ metadata.gz: 20d79f18d45c07c0ba2a35faa54db04a85833f541e4276ee6513db5b295d120c4e3d286dc7c81ca409669091cca2f1abf3c989dbba80aef4aab7eace4cf711b7
7
+ data.tar.gz: f88e9169c678a9914b4d1d730269d8e78d984ec9dbbdcd8a15bbac6c7c2f02a69912ca0eea238aa4b8783c85843717b4cc37f24233f766a95111a236ee40e989
@@ -74,12 +74,14 @@ module SelfSDK
74
74
  end
75
75
 
76
76
  def to_payload
77
+ k = build_key(@key, @nonce)
77
78
  {
78
79
  name: @name,
79
80
  link: @link,
80
- key: build_key(@key, @nonce),
81
+ key: k,
81
82
  mime: @mime,
82
- expires: @expires
83
+ expires: @expires,
84
+ public: (k == "")
83
85
  }
84
86
  end
85
87
 
@@ -111,4 +113,4 @@ module SelfSDK
111
113
  end
112
114
  end
113
115
  end
114
- end
116
+ end
@@ -7,34 +7,35 @@ require_relative '../ntptime'
7
7
  module SelfSDK
8
8
  module Messages
9
9
  class Attestation
10
- attr_accessor :verified, :origin, :source, :value, :operator, :expected_value, :fact_name, :to, :audience
10
+ attr_accessor :verified, :origin, :source, :value, :operator, :expected_value, :fact_name, :to, :audience, :payload
11
11
 
12
12
  def initialize(messaging)
13
13
  @messaging = messaging
14
14
  end
15
15
 
16
16
  def parse(name, attestation)
17
- payload = JSON.parse(@messaging.jwt.decode(attestation[:payload]), symbolize_names: true)
18
- @origin = payload[:iss]
19
- @to = payload[:sub]
20
- @audience = payload[:aud]
21
- @source = payload[:source]
17
+ @payload = JSON.parse(@messaging.jwt.decode(attestation[:payload]), symbolize_names: true)
18
+ @origin = @payload[:iss]
19
+ @to = @payload[:sub]
20
+ @audience = @payload[:aud]
21
+ @source = @payload[:source]
22
22
  header = JSON.parse(@messaging.jwt.decode(attestation[:protected]), symbolize_names: true)
23
23
  @verified = valid_signature?(attestation, header[:kid])
24
- @expected_value = payload[:expected_value]
25
- @operator = payload[:operator]
24
+ @expected_value = @payload[:expected_value]
25
+ @operator = @payload[:operator]
26
26
  @fact_name = name.to_s
27
- if payload[name].nil?
28
- return if payload[:facts].nil?
29
27
 
30
- payload[:facts].each do |f|
28
+ if @payload[name].nil?
29
+ return if @payload[:facts].nil?
30
+
31
+ @payload[:facts].each do |f|
31
32
  if f[:key] == name.to_s
32
33
  @value = f[:value]
33
34
  break
34
35
  end
35
36
  end
36
37
  else
37
- @value = payload[name]
38
+ @value = @payload[name]
38
39
  end
39
40
  end
40
41
 
data/lib/messages/fact.rb CHANGED
@@ -31,7 +31,7 @@ module SelfSDK
31
31
  fact[:attestations]&.each do |a|
32
32
  attestation = SelfSDK::Messages::Attestation.new(@messaging)
33
33
  attestation.parse(fact[:fact].to_sym, a)
34
- @attestations.push(attestation)
34
+ @attestations.push(attestation) unless attestation.value.nil?
35
35
  end
36
36
  end
37
37
 
@@ -35,6 +35,9 @@ module SelfSDK
35
35
  payload[:facts].each do |f|
36
36
  begin
37
37
  fact = SelfSDK::Messages::Fact.new(@messaging)
38
+ if f[:fact] == 'photo'
39
+ f[:fact] = :image_hash
40
+ end
38
41
  fact.parse(f)
39
42
  @facts.push(fact)
40
43
  rescue StandardError => e
@@ -45,22 +48,37 @@ module SelfSDK
45
48
  issuer = envelope.sender.split(":")
46
49
  @from_device = issuer.last
47
50
  end
51
+
48
52
  end
49
53
 
50
54
  def fact(name)
51
55
  name = @messaging.source.normalize_fact_name(name)
56
+ name = "image_hash" if name == 'photo'
52
57
  @facts.select{|f| f.name == name}.first
53
58
  end
54
59
 
60
+
61
+ # Returns an attestation by name
62
+ #
63
+ # @param name [String] the name of the fact to retrieve the attestation for
64
+ # @return [Object, nil] the first attestation of the fact, or nil if no fact is found
65
+ def attestation(name)
66
+ f = fact(name)
67
+ return nil if f.nil?
68
+
69
+ f.attestations.first
70
+ end
71
+
55
72
  def attestations_for(name)
56
73
  f = fact(name)
57
74
  return [] if f.nil?
75
+
58
76
  f.attestations
59
77
  end
60
78
 
61
79
  def attestation_values_for(name)
62
- a = attestations_for(name)
63
- a.map{|a| a.value}
80
+ aa = attestations_for(name)
81
+ aa.map{|a| a.value}
64
82
  end
65
83
 
66
84
  def validate!(original)
@@ -92,6 +110,16 @@ module SelfSDK
92
110
  def auth_response?
93
111
  @auth == true
94
112
  end
113
+
114
+ def object(hash)
115
+ payload[:objects].each do |o|
116
+ if o[:image_hash] == hash
117
+ return SelfSDK::Chat::FileObject.new(
118
+ @messaging.client.jwt.auth_token,
119
+ @messaging.client.self_url).build_from_object(o)
120
+ end
121
+ end
122
+ end
95
123
  end
96
124
  end
97
125
  end
data/lib/services/chat.rb CHANGED
@@ -52,7 +52,7 @@ module SelfSDK
52
52
  cm.mark_as_delivered unless opts[:mark_as_delivered] == false
53
53
  cm.mark_as_read if opts[:mark_as_read] == true
54
54
 
55
- block.call(cm)
55
+ call(block, cm)
56
56
  end
57
57
  end
58
58
 
@@ -104,19 +104,19 @@ module SelfSDK
104
104
  def on_invite(&block)
105
105
  @messaging.subscribe :chat_invite do |msg|
106
106
  g = SelfSDK::Chat::Group.new(self, msg.payload)
107
- block.call(g)
107
+ call(block, g)
108
108
  end
109
109
  end
110
110
 
111
111
  def on_join(&block)
112
112
  @messaging.subscribe :chat_join do |msg|
113
- block.call(iss: msg.payload[:iss], gid: msg.payload[:gid])
113
+ call(block, {iss: msg.payload[:iss], gid: msg.payload[:gid]})
114
114
  end
115
115
  end
116
116
 
117
117
  def on_leave(&block)
118
118
  @messaging.subscribe :chat_remove do |msg|
119
- block.call(iss: msg.payload[:iss], gid: msg.payload[:gid])
119
+ call(block, {iss: msg.payload[:iss], gid: msg.payload[:gid]})
120
120
  end
121
121
  end
122
122
 
@@ -194,7 +194,7 @@ module SelfSDK
194
194
  # @yield [request] Invokes the block with a connection response message.
195
195
  def on_connection(&block)
196
196
  @messaging.subscribe :connection_response do |msg|
197
- block.call(msg)
197
+ call(block, msg)
198
198
  end
199
199
  end
200
200
 
@@ -243,6 +243,17 @@ module SelfSDK
243
243
  posterior_members = true if m == @app_id
244
244
  end
245
245
  end
246
+
247
+ def call(block, *args)
248
+ block.call(*args)
249
+ rescue StandardError => e
250
+ SelfSDK.logger.error("A StandardError occurred: #{e.message}")
251
+ SelfSDK.logger.error("Backtrace:\n\t#{e.backtrace.join("\n\t")}")
252
+ rescue Exception => e
253
+ SelfSDK.logger.error("An unexpected exception occurred: #{e.message}")
254
+ SelfSDK.logger.error("Backtrace:\n\t#{e.backtrace.join("\n\t")}")
255
+ end
256
+
246
257
  end
247
258
  end
248
259
  end
@@ -29,7 +29,7 @@ module SelfSDK
29
29
  # Subscribes to chat.voice.setup messages.
30
30
  def on_setup(&block)
31
31
  @messaging.subscribe :voice_setup do |msg|
32
- block.call(msg.payload[:iss], msg.payload[:cid], msg.payload[:data])
32
+ call(block, msg.payload[:iss], msg.payload[:cid], msg.payload[:data])
33
33
  end
34
34
  end
35
35
 
@@ -46,17 +46,18 @@ module SelfSDK
46
46
  # Subscribes to chat.voice.start messages.
47
47
  def on_start(&block)
48
48
  @messaging.subscribe :voice_start do |msg|
49
- block.call(msg.payload[:iss],
50
- cid: msg.payload[:cid],
51
- call_id: msg.payload[:call_id],
52
- peer_info: msg.payload[:peer_info],
53
- data: msg.payload[:data])
49
+ call(block,
50
+ msg.payload[:iss],
51
+ cid: msg.payload[:cid],
52
+ call_id: msg.payload[:call_id],
53
+ peer_info: msg.payload[:peer_info],
54
+ data: msg.payload[:data])
54
55
  end
55
56
  end
56
57
 
57
58
  # Sends a chat.voice.accept message accepting a specific call.
58
59
  def accept(recipient, cid, call_id, peer_info)
59
- payload = {
60
+ payload = {
60
61
  typ: SelfSDK::Messages::VoiceAccept::MSG_TYPE,
61
62
  cid: cid,
62
63
  call_id: call_id,
@@ -68,16 +69,17 @@ module SelfSDK
68
69
  # Subscribes to chat.voice.accept messages.
69
70
  def on_accept(&block)
70
71
  @messaging.subscribe :voice_accept do |msg|
71
- block.call(msg.payload[:iss],
72
- cid: msg.payload[:cid],
73
- call_id: msg.payload[:call_id],
74
- peer_info: msg.payload[:peer_info])
72
+ call(block,
73
+ msg.payload[:iss],
74
+ cid: msg.payload[:cid],
75
+ call_id: msg.payload[:call_id],
76
+ peer_info: msg.payload[:peer_info])
75
77
  end
76
78
  end
77
79
 
78
80
  # Sends a chat.voice.accept message finishing the call.
79
81
  def stop(recipient, cid, call_id)
80
- payload = {
82
+ payload = {
81
83
  typ: SelfSDK::Messages::VoiceStop::MSG_TYPE,
82
84
  cid: cid,
83
85
  call_id: call_id,
@@ -88,10 +90,11 @@ module SelfSDK
88
90
  # Subscribes to chat.voice.stop messages.
89
91
  def on_stop(&block)
90
92
  @messaging.subscribe :voice_stop do |msg|
91
- block.call(msg.payload[:iss],
92
- cid: msg.payload[:cid],
93
- call_id: msg.payload[:call_id],
94
- peer_info: msg.payload[:peer_info])
93
+ call(block,
94
+ msg.payload[:iss],
95
+ cid: msg.payload[:cid],
96
+ call_id: msg.payload[:call_id],
97
+ peer_info: msg.payload[:peer_info])
95
98
  end
96
99
  end
97
100
 
@@ -106,10 +109,11 @@ module SelfSDK
106
109
  # Subscribes to chat.voice.busy messages.
107
110
  def on_busy(&block)
108
111
  @messaging.subscribe :voice_busy do |msg|
109
- block.call(msg.payload[:iss],
110
- cid: msg.payload[:cid],
111
- call_id: msg.payload[:call_id],
112
- peer_info: msg.payload[:peer_info])
112
+ call(block,
113
+ msg.payload[:iss],
114
+ cid: msg.payload[:cid],
115
+ call_id: msg.payload[:call_id],
116
+ peer_info: msg.payload[:peer_info])
113
117
  end
114
118
  end
115
119
 
@@ -124,10 +128,11 @@ module SelfSDK
124
128
  # Subscribes to chat.voice.summary messages.
125
129
  def on_summary(&block)
126
130
  @messaging.subscribe :voice_summary do |msg|
127
- block.call(msg.payload[:iss],
128
- cid: msg.payload[:cid],
129
- call_id: msg.payload[:call_id],
130
- peer_info: msg.payload[:peer_info])
131
+ call(block,
132
+ msg.payload[:iss],
133
+ cid: msg.payload[:cid],
134
+ call_id: msg.payload[:call_id],
135
+ peer_info: msg.payload[:peer_info])
131
136
  end
132
137
  end
133
138
 
@@ -142,6 +147,17 @@ module SelfSDK
142
147
  end
143
148
  m
144
149
  end
150
+
151
+ def call(block, *args)
152
+ block.call(*args)
153
+ rescue StandardError => e
154
+ SelfSDK.logger.error("A StandardError occurred: #{e.message}")
155
+ SelfSDK.logger.error("Backtrace:\n\t#{e.backtrace.join("\n\t")}")
156
+ rescue Exception => e
157
+ SelfSDK.logger.error("An unexpected exception occurred: #{e.message}")
158
+ SelfSDK.logger.error("Backtrace:\n\t#{e.backtrace.join("\n\t")}")
159
+ end
160
+
145
161
  end
146
162
  end
147
163
  end
@@ -43,18 +43,6 @@ module SelfSDK
43
43
  "nationality",
44
44
  "country_of_issuance"
45
45
  ],
46
- "twitter" => [
47
- "account_id",
48
- "nickname"
49
- ],
50
- "linkedin" => [
51
- "account_id",
52
- "nickname"
53
- ],
54
- "facebook" => [
55
- "account_id",
56
- "nickname"
57
- ],
58
46
  "live" => [
59
47
  "selfie_verification"
60
48
  ]
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.223
4
+ version: 0.0.225
5
5
  platform: ruby
6
6
  authors:
7
7
  - Self Group Ltd.