Class: SelfSDK::Messages::Attestation
- Inherits:
-
Object
- Object
- SelfSDK::Messages::Attestation
- Defined in:
- lib/messages/attestation.rb
Instance Attribute Summary collapse
-
#audience ⇒ Object
Returns the value of attribute audience.
-
#expected_value ⇒ Object
Returns the value of attribute expected_value.
-
#fact_name ⇒ Object
Returns the value of attribute fact_name.
-
#operator ⇒ Object
Returns the value of attribute operator.
-
#origin ⇒ Object
Returns the value of attribute origin.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#source ⇒ Object
Returns the value of attribute source.
-
#to ⇒ Object
Returns the value of attribute to.
-
#value ⇒ Object
Returns the value of attribute value.
-
#verified ⇒ Object
Returns the value of attribute verified.
Instance Method Summary collapse
-
#initialize(messaging) ⇒ Attestation
constructor
A new instance of Attestation.
- #parse(name, attestation) ⇒ Object
- #signed ⇒ Object
- #valid_signature?(body, kid) ⇒ Boolean
- #validate!(original) ⇒ Object
Constructor Details
#initialize(messaging) ⇒ Attestation
Returns a new instance of Attestation.
12 13 14 |
# File 'lib/messages/attestation.rb', line 12 def initialize(messaging) @messaging = messaging end |
Instance Attribute Details
#audience ⇒ Object
Returns the value of attribute audience.
10 11 12 |
# File 'lib/messages/attestation.rb', line 10 def audience @audience end |
#expected_value ⇒ Object
Returns the value of attribute expected_value.
10 11 12 |
# File 'lib/messages/attestation.rb', line 10 def expected_value @expected_value end |
#fact_name ⇒ Object
Returns the value of attribute fact_name.
10 11 12 |
# File 'lib/messages/attestation.rb', line 10 def fact_name @fact_name end |
#operator ⇒ Object
Returns the value of attribute operator.
10 11 12 |
# File 'lib/messages/attestation.rb', line 10 def operator @operator end |
#origin ⇒ Object
Returns the value of attribute origin.
10 11 12 |
# File 'lib/messages/attestation.rb', line 10 def origin @origin end |
#payload ⇒ Object
Returns the value of attribute payload.
10 11 12 |
# File 'lib/messages/attestation.rb', line 10 def payload @payload end |
#source ⇒ Object
Returns the value of attribute source.
10 11 12 |
# File 'lib/messages/attestation.rb', line 10 def source @source end |
#to ⇒ Object
Returns the value of attribute to.
10 11 12 |
# File 'lib/messages/attestation.rb', line 10 def to @to end |
#value ⇒ Object
Returns the value of attribute value.
10 11 12 |
# File 'lib/messages/attestation.rb', line 10 def value @value end |
#verified ⇒ Object
Returns the value of attribute verified.
10 11 12 |
# File 'lib/messages/attestation.rb', line 10 def verified @verified end |
Instance Method Details
#parse(name, attestation) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/messages/attestation.rb', line 16 def parse(name, attestation) @payload = JSON.parse(@messaging.jwt.decode(attestation[:payload]), symbolize_names: true) @origin = @payload[:iss] @to = @payload[:sub] @audience = @payload[:aud] @source = @payload[:source] header = JSON.parse(@messaging.jwt.decode(attestation[:protected]), symbolize_names: true) @verified = valid_signature?(attestation, header[:kid]) @expected_value = @payload[:expected_value] @operator = @payload[:operator] @fact_name = name.to_s if @payload[name].nil? return if @payload[:facts].nil? @payload[:facts].each do |f| if f[:key] == name.to_s @value = f[:value] break end end else @value = @payload[name] end end |
#signed ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/messages/attestation.rb', line 53 def signed o = { sub: @to, iss: @origin, iat: SelfSDK::Time.now.strftime('%FT%TZ'), source: @source, fact: @fact_name, expected_value: @expected_value, operator: @operator, } o[:aud] = @audience unless @audience.nil? o[@fact_name.to_sym] = @value @messaging.jwt.signed(o) end |
#valid_signature?(body, kid) ⇒ Boolean
42 43 44 45 46 47 |
# File 'lib/messages/attestation.rb', line 42 def valid_signature?(body, kid) k = @messaging.client.public_key(@origin, kid).raw_public_key raise ::StandardError.new("invalid signature") unless @messaging.jwt.verify(body, k) true end |
#validate!(original) ⇒ Object
49 50 51 |
# File 'lib/messages/attestation.rb', line 49 def validate!(original) raise ::StandardError.new("invalid origin") if @to.split(":").first != original.to end |