selfsdk 0.0.159 → 0.0.164

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: 1a1de83ae25387f6180432dd419f36568956a458bdbfd5df988ea9292588e50a
4
- data.tar.gz: 55717411b03f983659ee503493a233d3ceea14f35fd991eec9494a6bc01fe9b2
3
+ metadata.gz: 37a0711ed0feb251165f49fcfdce3573cb3845dea3e02263395baada7af5d0f6
4
+ data.tar.gz: dd281cf75f58dc8ff14e22a8e71e32b400aa78a7ea806038a33c9cb8d9bf61ac
5
5
  SHA512:
6
- metadata.gz: 291ba0d883273e9aa94eb61aa936014a1fd4a6031c9e921d0affc5da4064c39a4cc5b073bb68823ae73d53a33c2808f9cb4921eeac0e043308715d8eb37b9239
7
- data.tar.gz: d73be5eb6086614300de7469026715881b640ea51fd9e9e5d8054a7b9c387b9d67f3cb21e72f358ff899833176bf9bb38962832405dd68461fc489e8d217d345
6
+ metadata.gz: 81ce8dcd9ebdbccfd0991b0479ddba10d46806588d660a4c7ace4f76cc534d62c7c3ef3074060989504b11a7876c51e66bb5ec780ddce889d780750cc5724e85
7
+ data.tar.gz: 296412709b0ad51d9e4ee748d2116f07f940168aa00c7ad9494ff432fca532f81e7c996e833641c36417f94a319a82d012fa49665eb8b7f2e651b39419ba77b5
@@ -9,7 +9,7 @@ module SelfSDK
9
9
  module Messages
10
10
  class AuthenticationMessage < Base
11
11
 
12
- def parse(input, original=nil)
12
+ def parse(input, envelope=nil)
13
13
  @input = input
14
14
  @typ = @typ
15
15
  @payload = get_payload input
@@ -21,6 +21,10 @@ module SelfSDK
21
21
  @expires = ::Time.parse(payload[:exp])
22
22
  @issued = ::Time.parse(payload[:iat])
23
23
  @status = payload[:status]
24
+ if envelope
25
+ issuer = envelope.sender.split(":")
26
+ @from_device = issuer.last
27
+ end
24
28
  end
25
29
  end
26
30
  end
data/lib/messages/base.rb CHANGED
@@ -27,10 +27,12 @@ module SelfSDK
27
27
  res
28
28
  end
29
29
 
30
- def send_message
30
+ def send_message(device_id = nil)
31
31
  check_credits!
32
+ dds = devices
33
+ dds = [device_id] if device_id
32
34
  res = []
33
- devices.each do |d|
35
+ dds.each do |d|
34
36
  res << @messaging.send_message(proto(d))
35
37
  SelfSDK.logger.info "asynchronously requested information to #{@to}:#{d}"
36
38
  end
@@ -39,17 +39,23 @@ module SelfSDK
39
39
  end
40
40
  end
41
41
 
42
- def parse(input)
42
+ def parse(input, envelope=nil)
43
43
  @input = input
44
44
  @typ = MSG_TYPE
45
45
  @payload = get_payload input
46
46
  @id = @payload[:cid]
47
47
  @from = @payload[:iss]
48
48
  @to = @payload[:sub]
49
+ @audience = payload[:aud]
49
50
  @expires = @payload[:exp]
50
51
  @description = @payload.include?(:description) ? @payload[:description] : nil
51
52
  @facts = @payload[:facts]
52
53
  @options = @payload[:options]
54
+
55
+ if envelope
56
+ issuer = envelope.sender.split(":")
57
+ @from_device = issuer.last
58
+ end
53
59
  end
54
60
 
55
61
  def build_response
@@ -57,9 +63,8 @@ module SelfSDK
57
63
  m.id = @id
58
64
  m.from = @to
59
65
  m.to = @from
66
+ m.sub = @to
60
67
  m.audience = @from
61
- m.to_device = @messaging.device_id
62
- m.from_device = @to_device
63
68
  m.facts = @facts
64
69
  m
65
70
  end
@@ -13,7 +13,7 @@ module SelfSDK
13
13
 
14
14
  attr_accessor :facts, :audience
15
15
 
16
- def parse(input)
16
+ def parse(input, envelope=nil)
17
17
  @input = input
18
18
  @typ = MSG_TYPE
19
19
  @payload = get_payload input
@@ -35,6 +35,10 @@ module SelfSDK
35
35
  SelfSDK.logger.info e.message
36
36
  end
37
37
  end
38
+ if envelope
39
+ issuer = envelope.sender.split(":")
40
+ @from_device = issuer.last
41
+ end
38
42
  end
39
43
 
40
44
  def fact(name)
@@ -60,15 +64,13 @@ module SelfSDK
60
64
  end
61
65
  end
62
66
 
63
- protected
64
-
65
- def proto(to_device)
67
+ def body
66
68
  encoded_facts = []
67
69
  @facts.each do |fact|
68
70
  encoded_facts.push(fact.to_hash)
69
71
  end
70
- body = @jwt.prepare(
71
- typ: MSG_TYPE,
72
+
73
+ { typ: MSG_TYPE,
72
74
  iss: @jwt.id,
73
75
  sub: @sub || @to,
74
76
  aud: @audience,
@@ -77,15 +79,19 @@ module SelfSDK
77
79
  cid: @id,
78
80
  jti: SecureRandom.uuid,
79
81
  status: @status,
80
- facts: encoded_facts,
81
- )
82
+ facts: encoded_facts }
83
+ end
84
+
85
+ protected
82
86
 
87
+ def proto(to_device)
88
+ @to_device = to_device
83
89
  Msgproto::Message.new(
84
90
  type: Msgproto::MsgType::MSG,
85
91
  id: SecureRandom.uuid,
86
92
  sender: "#{@jwt.id}:#{@messaging.device_id}",
87
93
  recipient: "#{@to}:#{@to_device}",
88
- ciphertext: encrypt_message(body, @to, @to_device)
94
+ ciphertext: encrypt_message(@jwt.prepare(body), @to, @to_device)
89
95
  )
90
96
  end
91
97
  end
@@ -10,11 +10,13 @@ require_relative "authentication_req"
10
10
  module SelfSDK
11
11
  module Messages
12
12
  def self.parse(input, messaging, original=nil)
13
+ envelope = nil
13
14
  body = if input.is_a? String
14
- input
15
+ input
15
16
  else
16
- issuer = input.sender.split(":")
17
- messaging.encryption_client.decrypt(input.ciphertext, issuer.first, issuer.last)
17
+ envelope = input
18
+ issuer = input.sender.split(":")
19
+ messaging.encryption_client.decrypt(input.ciphertext, issuer.first, issuer.last)
18
20
  end
19
21
 
20
22
  jwt = JSON.parse(body, symbolize_names: true)
@@ -23,16 +25,16 @@ module SelfSDK
23
25
  case payload[:typ]
24
26
  when "identities.facts.query.req"
25
27
  m = FactRequest.new(messaging)
26
- m.parse(body)
28
+ m.parse(body, envelope)
27
29
  when "identities.facts.query.resp"
28
30
  m = FactResponse.new(messaging)
29
- m.parse(body)
31
+ m.parse(body, envelope)
30
32
  when "identities.authenticate.resp"
31
33
  m = AuthenticationResp.new(messaging)
32
- m.parse(body)
34
+ m.parse(body, envelope)
33
35
  when "identities.authenticate.req"
34
36
  m = AuthenticationReq.new(messaging)
35
- m.parse(body)
37
+ m.parse(body, envelope)
36
38
  else
37
39
  raise StandardError.new("Invalid message type.")
38
40
  end
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.159
4
+ version: 0.0.164
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aldgate Ventures