selfsdk 0.0.141 → 0.0.146

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: 1fc84c8ad47b159c7f07f33226c1273bf30202f3b999ceba02ef51f6b35763fb
4
- data.tar.gz: 4c88fbad5ffa05cc69977554d454ca7fcc796663400f2e74b770879afe05c2a7
3
+ metadata.gz: e44cc9f9cc2d07bcbd78946498b6180cee65cccef98486ca559b0a6b8839510a
4
+ data.tar.gz: bf5c9e0e24a7d89c83bc10eaa564758fcd356187e8e2fea27a9d87c86261883c
5
5
  SHA512:
6
- metadata.gz: c5f9b8cf446fb87a089d2094449691cd73806af84ce5d3f712a0357a0bdc5c4b2f7fef0dd6552591d56c4c5dd07fcaadcad02173b67b500f07ae80aec519fc2f
7
- data.tar.gz: ee291b8ca0f22787067ae2edca5a59fee3fea4950a06cfd921c00c9d283d7c769cefeac7dd8bcee0bd2eeee7784fab307a52919d81f87942b8c8ccd4eff6d045
6
+ metadata.gz: fd6e0766f4887b2af9c6a5b6684e337674ec6047eb0c899c4b290efe03db81ffbf1a7e486a60f6a8c843e888ad651d12eca3ef57f69445dd1caf62b2b8c3ba83
7
+ data.tar.gz: 2bdb29ed477d0675e1ab4a954a9c64796e3feb7d49e89b4e35f0631289ff99ac9f44d6ef14013ce9a0a586dfa9c66b527026dfce6ce3f9b6492d4cf8a9b15be9
data/lib/acl.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 'date'
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  module SelfSDK
2
4
  class Authenticated
3
5
  attr_accessor :payload, :uuid, :selfsdk, :status
@@ -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 'httparty'
@@ -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
@@ -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 'base64'
data/lib/log.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 'logger'
@@ -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
@@ -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'
@@ -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}:#{@to_device}",
47
- ciphertext: encrypt_message(@jwt.prepare(body), @to, @to_device))
47
+ recipient: "#{@to}:#{to_device}",
48
+ ciphertext: encrypt_message(@jwt.prepare(body), @to, to_device))
48
49
  end
49
50
 
50
51
  end
@@ -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'
@@ -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
- res = @messaging.send_and_wait_for_response(proto, self)
19
- SelfSDK.logger.info "synchronously messaging to #{@to}:#{@to_device}"
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
- res = @messaging.send_message proto
25
- SelfSDK.logger.info "asynchronously requested information to #{@to}:#{@to_device}"
26
- res
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)
@@ -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 'attestation'
@@ -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
- devices = if @intermediary.nil?
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)
@@ -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'
@@ -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.recipient.split(":")
16
+ issuer = input.sender.split(":")
15
17
  messaging.encryption_client.decrypt(input.ciphertext, issuer.first, issuer.last)
16
18
  end
17
19
 
@@ -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(msg, original)
146
- wait_for msg.id, original do
147
- send_message msg
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
 
@@ -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 'time'
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # Generated by the protocol buffer compiler. DO NOT EDIT!
2
4
  # source: acl.proto
3
5
 
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # Generated by the protocol buffer compiler. DO NOT EDIT!
2
4
  # source: aclcommand.proto
3
5
 
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # Generated by the protocol buffer compiler. DO NOT EDIT!
2
4
  # source: auth.proto
3
5
 
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # Generated by the protocol buffer compiler. DO NOT EDIT!
2
4
  # source: errtype.proto
3
5
 
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # Generated by the protocol buffer compiler. DO NOT EDIT!
2
4
  # source: header.proto
3
5
 
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # Generated by the protocol buffer compiler. DO NOT EDIT!
2
4
  # source: message.proto
3
5
 
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # Generated by the protocol buffer compiler. DO NOT EDIT!
2
4
  # source: msgtype.proto
3
5
 
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # Generated by the protocol buffer compiler. DO NOT EDIT!
2
4
  # source: notification.proto
3
5
 
@@ -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 'securerandom'
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # frozen_string_literal: true
2
4
 
3
5
  # Namespace for classes and modules that handle SelfSDK gem
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # frozen_string_literal: true
2
4
 
3
5
  # Namespace for classes and modules that handle SelfSDK gem
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # frozen_string_literal: true
2
4
 
3
5
  # Namespace for classes and modules that handle SelfSDK gem
@@ -1,3 +1,5 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
1
3
  # frozen_string_literal: true
2
4
 
3
5
  # Namespace for classes and modules that handle SelfSDK gem
@@ -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 'base64'
@@ -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
 
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.141
4
+ version: 0.0.146
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aldgate Ventures