selfsdk 0.0.139 → 0.0.144

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: fd7dee3974b09378a7893e93df82bf77a9e082dfcc386b61dc5def8660276233
4
- data.tar.gz: b2cc3bec34b678a941cb13ca7f46e82851a7b29ef2f5a4c0a6d5047dfb0aa73d
3
+ metadata.gz: d9d49a7cde97a88c5c56c6233b964b72c66d9b046b2521cac189475646be55f2
4
+ data.tar.gz: 600b68b342c99830aba799eb13da1650d02cecd4bd824aeb38f51c768c77a13a
5
5
  SHA512:
6
- metadata.gz: 603796714f57dae9c509dd5d8bfdae2a9433f41d6bdeb653e55ec8e0aeb6c3b953799fac5651f21e83f3a9526c276e84bd55b655a489074765e13baf21924764
7
- data.tar.gz: 3e8b669f3449d9e2335e113fbc638795fc42ac2ef3b5463f14d560460a1bd6ff5d542e453e8b8702ef19454038fcc53f95205e5f21e63965428238b4662bc9d6
6
+ metadata.gz: 3c7989e1245b7b2993e4c5784373d05c25870a1e4e695da1a49571e5ada8d779fb90c5d5f37fd9174e3cef51b054655c9efdb8470f573a98bdfa10ea950d1d8c
7
+ data.tar.gz: 8e30b0e94b496efdc80f6dc4d5bdb655e8236ff098880bf28f46bc8433f08182fe7bfca3942abe893cfd698f8be720ae598611ae24ea6c98b4adfac2db1c9c5b
@@ -66,19 +66,31 @@ module SelfSDK
66
66
  end
67
67
 
68
68
  def post(endpoint, body)
69
- p HTTParty.post("#{@self_url}#{endpoint}",
70
- headers: {
71
- 'Content-Type' => 'application/json',
72
- 'Authorization' => "Bearer #{@jwt.auth_token}"
73
- },
74
- body: body)
69
+ res = nil
70
+ loop do
71
+ res = HTTParty.post("#{@self_url}#{endpoint}",
72
+ headers: {
73
+ 'Content-Type' => 'application/json',
74
+ 'Authorization' => "Bearer #{@jwt.auth_token}"
75
+ },
76
+ body: body)
77
+ break if res.code != 503
78
+ sleep 2
79
+ end
80
+ return res
75
81
  end
76
82
 
77
83
  def get(endpoint)
78
- HTTParty.get("#{@self_url}#{endpoint}", headers: {
84
+ res = nil
85
+ loop do
86
+ res = HTTParty.get("#{@self_url}#{endpoint}", headers: {
79
87
  'Content-Type' => 'application/json',
80
88
  'Authorization' => "Bearer #{@jwt.auth_token}"
81
- })
89
+ })
90
+ break if res.code != 503
91
+ sleep 2
92
+ end
93
+ return res
82
94
  end
83
95
 
84
96
  # Lists all public keys stored on self for the given ID
@@ -8,9 +8,9 @@ module SelfSDK
8
8
  @storage_key = storage_key
9
9
  @storage_folder = storage_folder
10
10
 
11
- if File.exist?('account.pickle')
11
+ if File.exist?(account_path)
12
12
  # 1a) if alice's account file exists load the pickle from the file
13
- @account = SelfCrypto::Account.from_pickle(File.read('account.pickle'), @storage_key)
13
+ @account = SelfCrypto::Account.from_pickle(File.read(account_path), @storage_key)
14
14
  else
15
15
  # 1b-i) if create a new account for alice if one doesn't exist already
16
16
  @account = SelfCrypto::Account.from_seed(@client.jwt.key)
@@ -25,12 +25,12 @@ module SelfSDK
25
25
  @client.post("/v1/apps/#{@client.jwt.id}/devices/#{@device}/pre_keys", keys)
26
26
 
27
27
  # 1b-v) store the account to a file
28
- File.write('account.pickle', @account.to_pickle(storage_key))
28
+ File.write(account_path, @account.to_pickle(storage_key))
29
29
  end
30
30
  end
31
31
 
32
32
  def encrypt(message, recipient, recipient_device)
33
- session_file_name = "#{recipient}:#{recipient_device}-session.pickle"
33
+ session_file_name = session_path(recipient, recipient_device)
34
34
 
35
35
  if File.exist?(session_file_name)
36
36
  # 2a) if bob's session file exists load the pickle from the file
@@ -55,9 +55,6 @@ module SelfSDK
55
55
 
56
56
  # 2b-iv) create the session with bob
57
57
  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
58
  end
62
59
 
63
60
  # 3) create a group session and set the identity of the account youre using
@@ -67,11 +64,16 @@ module SelfSDK
67
64
  gs.add_participant("#{recipient}:#{recipient_device}", session_with_bob)
68
65
 
69
66
  # 5) encrypt a message
70
- gs.encrypt(message).to_s
67
+ ct = gs.encrypt(message).to_s
68
+
69
+ # 6) store the session to a file
70
+ File.write(session_file_name, session_with_bob.to_pickle(@storage_key))
71
+
72
+ ct
71
73
  end
72
74
 
73
75
  def decrypt(message, sender, sender_device)
74
- session_file_name = "#{sender}:#{sender_device}-session.pickle"
76
+ session_file_name = session_path(sender, sender_device)
75
77
 
76
78
  if File.exist?(session_file_name)
77
79
  # 7a) if carol's session file exists load the pickle from the file
@@ -84,9 +86,6 @@ module SelfSDK
84
86
 
85
87
  # 7b-ii) use the initial message to create a session for bob or carol
86
88
  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
89
  end
91
90
 
92
91
  # 8) create a group session and set the identity of the account you're using
@@ -96,7 +95,22 @@ module SelfSDK
96
95
  gs.add_participant("#{sender}:#{sender_device}", session_with_bob)
97
96
 
98
97
  # 10) decrypt the message ciphertext
99
- gs.decrypt("#{sender}:#{sender_device}", message).to_s
98
+ pt = gs.decrypt("#{sender}:#{sender_device}", message).to_s
99
+
100
+ # 11) store the session to a file
101
+ File.write(session_file_name, session_with_bob.to_pickle(@storage_key))
102
+
103
+ pt
104
+ end
105
+
106
+ private
107
+
108
+ def account_path
109
+ "#{@storage_folder}/account.pickle"
110
+ end
111
+
112
+ def session_path(selfid, device)
113
+ "#{@storage_folder}/#{selfid}:#{device}-session.pickle"
100
114
  end
101
115
  end
102
116
  end
@@ -39,6 +39,9 @@ module SelfSDK
39
39
  protected
40
40
 
41
41
  def proto
42
+ app = @client.app(@jwt.id)
43
+ raise "Your credits have expired, please log in to the developer portal and top up your account." if app[:paid_actions] == false
44
+
42
45
  @to_device = @client.devices(@to).first
43
46
  Msgproto::Message.new(type: Msgproto::MsgType::MSG,
44
47
  sender: "#{@jwt.id}:#{@messaging.device_id}",
@@ -86,6 +86,9 @@ module SelfSDK
86
86
  protected
87
87
 
88
88
  def proto
89
+ app = @client.app(@jwt.id)
90
+ raise "Your credits have expired, please log in to the developer portal and top up your account." if app[:paid_actions] == false
91
+
89
92
  devices = if @intermediary.nil?
90
93
  @client.devices(@to)
91
94
  else
@@ -11,7 +11,7 @@ module SelfSDK
11
11
  body = if input.is_a? String
12
12
  input
13
13
  else
14
- issuer = input.recipient.split(":")
14
+ issuer = input.sender.split(":")
15
15
  messaging.encryption_client.decrypt(input.ciphertext, issuer.first, issuer.last)
16
16
  end
17
17
 
@@ -30,7 +30,7 @@ module SelfSDK
30
30
  # @params storage_folder [String] folder to perist messaging encryption
31
31
  # @option opts [Bool] :auto_reconnect Automatically reconnects to websocket if connection is lost (defaults to true).
32
32
  # @option opts [String] :device_id The device id to be used by the app defaults to "1".
33
- def initialize(url, client, storage_key, storage_folder, options = {})
33
+ def initialize(url, client, storage_key, options = {})
34
34
  @mon = Monitor.new
35
35
  @url = url
36
36
  @messages = {}
@@ -49,7 +49,7 @@ module SelfSDK
49
49
 
50
50
  FileUtils.mkdir_p @storage_dir unless File.exist? @storage_dir
51
51
  unless options.include? :no_crypto
52
- @encryption_client = Crypto.new(@client, @device_id, storage_folder, storage_key)
52
+ @encryption_client = Crypto.new(@client, @device_id, @storage_dir, storage_key)
53
53
  end
54
54
 
55
55
  if options.include? :ws
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.139
4
+ version: 0.0.144
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aldgate Ventures