selfsdk 0.0.141 → 0.0.146
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/acl.rb +2 -0
- data/lib/authenticated.rb +2 -0
- data/lib/client.rb +2 -0
- data/lib/crypto.rb +14 -8
- data/lib/jwt_service.rb +2 -0
- data/lib/log.rb +2 -0
- data/lib/messages/attestation.rb +2 -0
- data/lib/messages/authentication_message.rb +2 -0
- data/lib/messages/authentication_req.rb +5 -4
- data/lib/messages/authentication_resp.rb +2 -0
- data/lib/messages/base.rb +27 -5
- data/lib/messages/fact.rb +2 -0
- data/lib/messages/fact_request.rb +4 -8
- data/lib/messages/fact_response.rb +2 -0
- data/lib/messages/message.rb +3 -1
- data/lib/messaging.rb +8 -3
- data/lib/ntptime.rb +2 -0
- data/lib/proto/acl_pb.rb +2 -0
- data/lib/proto/aclcommand_pb.rb +2 -0
- data/lib/proto/auth_pb.rb +2 -0
- data/lib/proto/errtype_pb.rb +2 -0
- data/lib/proto/header_pb.rb +2 -0
- data/lib/proto/message_pb.rb +2 -0
- data/lib/proto/msgtype_pb.rb +2 -0
- data/lib/proto/notification_pb.rb +2 -0
- data/lib/selfsdk.rb +2 -0
- data/lib/services/auth.rb +2 -0
- data/lib/services/facts.rb +2 -0
- data/lib/services/identity.rb +2 -0
- data/lib/services/messaging.rb +2 -0
- data/lib/signature_graph.rb +2 -0
- data/lib/sources.rb +10 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e44cc9f9cc2d07bcbd78946498b6180cee65cccef98486ca559b0a6b8839510a
|
4
|
+
data.tar.gz: bf5c9e0e24a7d89c83bc10eaa564758fcd356187e8e2fea27a9d87c86261883c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd6e0766f4887b2af9c6a5b6684e337674ec6047eb0c899c4b290efe03db81ffbf1a7e486a60f6a8c843e888ad651d12eca3ef57f69445dd1caf62b2b8c3ba83
|
7
|
+
data.tar.gz: 2bdb29ed477d0675e1ab4a954a9c64796e3feb7d49e89b4e35f0631289ff99ac9f44d6ef14013ce9a0a586dfa9c66b527026dfce6ce3f9b6492d4cf8a9b15be9
|
data/lib/acl.rb
CHANGED
data/lib/authenticated.rb
CHANGED
data/lib/client.rb
CHANGED
data/lib/crypto.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# Copyright 2020 Self Group Ltd. All Rights Reserved.
|
2
|
+
|
1
3
|
require 'self_crypto'
|
2
4
|
|
3
5
|
module SelfSDK
|
@@ -55,9 +57,6 @@ module SelfSDK
|
|
55
57
|
|
56
58
|
# 2b-iv) create the session with bob
|
57
59
|
session_with_bob = @account.outbound_session(curve25519_identity_key, one_time_key)
|
58
|
-
|
59
|
-
# 2b-v) store the session to a file
|
60
|
-
File.write(session_file_name, session_with_bob.to_pickle(@storage_key))
|
61
60
|
end
|
62
61
|
|
63
62
|
# 3) create a group session and set the identity of the account youre using
|
@@ -67,7 +66,12 @@ module SelfSDK
|
|
67
66
|
gs.add_participant("#{recipient}:#{recipient_device}", session_with_bob)
|
68
67
|
|
69
68
|
# 5) encrypt a message
|
70
|
-
gs.encrypt(message).to_s
|
69
|
+
ct = gs.encrypt(message).to_s
|
70
|
+
|
71
|
+
# 6) store the session to a file
|
72
|
+
File.write(session_file_name, session_with_bob.to_pickle(@storage_key))
|
73
|
+
|
74
|
+
ct
|
71
75
|
end
|
72
76
|
|
73
77
|
def decrypt(message, sender, sender_device)
|
@@ -84,9 +88,6 @@ module SelfSDK
|
|
84
88
|
|
85
89
|
# 7b-ii) use the initial message to create a session for bob or carol
|
86
90
|
session_with_bob = @account.inbound_session(m)
|
87
|
-
|
88
|
-
# 7b-iii) store the session to a file
|
89
|
-
File.write(session_file_name, session_with_bob.to_pickle(@storage_key))
|
90
91
|
end
|
91
92
|
|
92
93
|
# 8) create a group session and set the identity of the account you're using
|
@@ -96,7 +97,12 @@ module SelfSDK
|
|
96
97
|
gs.add_participant("#{sender}:#{sender_device}", session_with_bob)
|
97
98
|
|
98
99
|
# 10) decrypt the message ciphertext
|
99
|
-
gs.decrypt("#{sender}:#{sender_device}", message).to_s
|
100
|
+
pt = gs.decrypt("#{sender}:#{sender_device}", message).to_s
|
101
|
+
|
102
|
+
# 11) store the session to a file
|
103
|
+
File.write(session_file_name, session_with_bob.to_pickle(@storage_key))
|
104
|
+
|
105
|
+
pt
|
100
106
|
end
|
101
107
|
|
102
108
|
private
|
data/lib/jwt_service.rb
CHANGED
data/lib/log.rb
CHANGED
data/lib/messages/attestation.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# Copyright 2020 Self Group Ltd. All Rights Reserved.
|
2
|
+
|
1
3
|
# frozen_string_literal: true
|
2
4
|
|
3
5
|
require_relative 'base'
|
@@ -38,13 +40,12 @@ module SelfSDK
|
|
38
40
|
|
39
41
|
protected
|
40
42
|
|
41
|
-
def proto
|
42
|
-
@to_device = @client.devices(@to).first
|
43
|
+
def proto(to_device)
|
43
44
|
Msgproto::Message.new(type: Msgproto::MsgType::MSG,
|
44
45
|
sender: "#{@jwt.id}:#{@messaging.device_id}",
|
45
46
|
id: @id,
|
46
|
-
recipient: "#{@to}:#{
|
47
|
-
ciphertext: encrypt_message(@jwt.prepare(body), @to,
|
47
|
+
recipient: "#{@to}:#{to_device}",
|
48
|
+
ciphertext: encrypt_message(@jwt.prepare(body), @to, to_device))
|
48
49
|
end
|
49
50
|
|
50
51
|
end
|
data/lib/messages/base.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# Copyright 2020 Self Group Ltd. All Rights Reserved.
|
2
|
+
|
1
3
|
# frozen_string_literal: true
|
2
4
|
|
3
5
|
module SelfSDK
|
@@ -15,15 +17,24 @@ module SelfSDK
|
|
15
17
|
end
|
16
18
|
|
17
19
|
def request
|
18
|
-
|
19
|
-
|
20
|
+
check_credits!
|
21
|
+
msgs = []
|
22
|
+
devices.each do |d|
|
23
|
+
msgs << proto(d)
|
24
|
+
end
|
25
|
+
res = @messaging.send_and_wait_for_response(msgs, self)
|
26
|
+
SelfSDK.logger.info "synchronously messaging to #{@to}:#{@d}"
|
20
27
|
res
|
21
28
|
end
|
22
29
|
|
23
30
|
def send_message
|
24
|
-
|
25
|
-
|
26
|
-
|
31
|
+
check_credits!
|
32
|
+
res = []
|
33
|
+
devices.each do |d|
|
34
|
+
res << @messaging.send_message(proto(d))
|
35
|
+
SelfSDK.logger.info "asynchronously requested information to #{@to}:#{@d}"
|
36
|
+
end
|
37
|
+
res.first
|
27
38
|
end
|
28
39
|
|
29
40
|
def encrypt_message(message, recipient, recipient_device)
|
@@ -65,6 +76,17 @@ module SelfSDK
|
|
65
76
|
raise ::StandardError.new("must define this method")
|
66
77
|
end
|
67
78
|
|
79
|
+
def devices
|
80
|
+
return @client.devices(@to) if @intermediary.nil?
|
81
|
+
|
82
|
+
@client.devices(@intermediary)
|
83
|
+
end
|
84
|
+
|
85
|
+
def check_credits!
|
86
|
+
app = @client.app(@jwt.id)
|
87
|
+
raise "Your credits have expired, please log in to the developer portal and top up your account." if app[:paid_actions] == false
|
88
|
+
end
|
89
|
+
|
68
90
|
private
|
69
91
|
|
70
92
|
def get_payload(input)
|
data/lib/messages/fact.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# Copyright 2020 Self Group Ltd. All Rights Reserved.
|
2
|
+
|
1
3
|
# frozen_string_literal: true
|
2
4
|
|
3
5
|
require_relative 'base'
|
@@ -85,14 +87,8 @@ module SelfSDK
|
|
85
87
|
|
86
88
|
protected
|
87
89
|
|
88
|
-
def proto
|
89
|
-
|
90
|
-
@client.devices(@to)
|
91
|
-
else
|
92
|
-
@client.devices(@intermediary)
|
93
|
-
end
|
94
|
-
@to_device = devices.first
|
95
|
-
|
90
|
+
def proto(to_device)
|
91
|
+
@to_device = to_device
|
96
92
|
if @intermediary.nil?
|
97
93
|
recipient = "#{@to}:#{@to_device}"
|
98
94
|
ciphertext = encrypt_message(@jwt.prepare(body), @to, @to_device)
|
data/lib/messages/message.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# Copyright 2020 Self Group Ltd. All Rights Reserved.
|
2
|
+
|
1
3
|
# frozen_string_literal: true
|
2
4
|
|
3
5
|
require_relative "fact_request"
|
@@ -11,7 +13,7 @@ module SelfSDK
|
|
11
13
|
body = if input.is_a? String
|
12
14
|
input
|
13
15
|
else
|
14
|
-
issuer = input.
|
16
|
+
issuer = input.sender.split(":")
|
15
17
|
messaging.encryption_client.decrypt(input.ciphertext, issuer.first, issuer.last)
|
16
18
|
end
|
17
19
|
|
data/lib/messaging.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# Copyright 2020 Self Group Ltd. All Rights Reserved.
|
2
|
+
|
1
3
|
# frozen_string_literal: true
|
2
4
|
|
3
5
|
require 'json'
|
@@ -94,6 +96,7 @@ module SelfSDK
|
|
94
96
|
# @param type [string] message type
|
95
97
|
# @param request [hash] original message requesing information
|
96
98
|
def send_custom(recipient, request_body)
|
99
|
+
# TODO (adriacidre) this is sending the message to the first device only
|
97
100
|
@to_device = @client.devices(recipient).first
|
98
101
|
send_message msg = Msgproto::Message.new(
|
99
102
|
type: Msgproto::MsgType::MSG,
|
@@ -142,9 +145,11 @@ module SelfSDK
|
|
142
145
|
# Sends a message and waits for the response
|
143
146
|
#
|
144
147
|
# @params msg [Msgproto::Message] message object to be sent
|
145
|
-
def send_and_wait_for_response(
|
146
|
-
wait_for msg.id, original do
|
147
|
-
|
148
|
+
def send_and_wait_for_response(msgs, original)
|
149
|
+
wait_for msg.first.id, original do
|
150
|
+
msgs.each do |msg|
|
151
|
+
send_message msg
|
152
|
+
end
|
148
153
|
end
|
149
154
|
end
|
150
155
|
|
data/lib/ntptime.rb
CHANGED
data/lib/proto/acl_pb.rb
CHANGED
data/lib/proto/aclcommand_pb.rb
CHANGED
data/lib/proto/auth_pb.rb
CHANGED
data/lib/proto/errtype_pb.rb
CHANGED
data/lib/proto/header_pb.rb
CHANGED
data/lib/proto/message_pb.rb
CHANGED
data/lib/proto/msgtype_pb.rb
CHANGED
data/lib/selfsdk.rb
CHANGED
data/lib/services/auth.rb
CHANGED
data/lib/services/facts.rb
CHANGED
data/lib/services/identity.rb
CHANGED
data/lib/services/messaging.rb
CHANGED
data/lib/signature_graph.rb
CHANGED
data/lib/sources.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# Copyright 2020 Self Group Ltd. All Rights Reserved.
|
2
|
+
|
1
3
|
# frozen_string_literal: true
|
2
4
|
|
3
5
|
module SelfSDK
|
@@ -15,10 +17,16 @@ module SelfSDK
|
|
15
17
|
FACT_DATE_OF_BIRTH = "date_of_birth"
|
16
18
|
FACT_DATE_OF_ISSUANCE = "date_of_issuance"
|
17
19
|
FACT_DATE_OF_EXPIRATION = "date_of_expiration"
|
20
|
+
FACT_VALID_FROM = "valid_from"
|
21
|
+
FACT_VALID_TO = "valid_to"
|
22
|
+
FACT_CATEGORIES = "categories"
|
23
|
+
FACT_SORT_CODE = "sort_code"
|
24
|
+
FACT_COUNTRY_OF_ISSUANCE = "country_of_issuance"
|
18
25
|
|
19
26
|
SOURCE_USER_SPECIFIED = "user_specified"
|
20
27
|
SOURCE_PASSPORT = "passport"
|
21
28
|
SOURCE_DRIVING_LICENSE = "driving_license"
|
29
|
+
SOURCE_ID_CARD = "identity_card"
|
22
30
|
|
23
31
|
class << self
|
24
32
|
def message_type(s)
|
@@ -61,7 +69,8 @@ module SelfSDK
|
|
61
69
|
def source(input)
|
62
70
|
sources = { user_specified: SOURCE_USER_SPECIFIED,
|
63
71
|
passport: SOURCE_PASSPORT,
|
64
|
-
driving_license: SOURCE_DRIVING_LICENSE
|
72
|
+
driving_license: SOURCE_DRIVING_LICENSE,
|
73
|
+
id_card: SOURCE_ID_CARD }
|
65
74
|
get(sources, input, "source")
|
66
75
|
end
|
67
76
|
|