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.
-
#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
permalink #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
permalink #audience ⇒ Object
Returns the value of attribute audience.
10 11 12 |
# File 'lib/messages/attestation.rb', line 10 def audience @audience end |
permalink #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 |
permalink #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 |
permalink #operator ⇒ Object
Returns the value of attribute operator.
10 11 12 |
# File 'lib/messages/attestation.rb', line 10 def operator @operator end |
permalink #origin ⇒ Object
Returns the value of attribute origin.
10 11 12 |
# File 'lib/messages/attestation.rb', line 10 def origin @origin end |
permalink #source ⇒ Object
Returns the value of attribute source.
10 11 12 |
# File 'lib/messages/attestation.rb', line 10 def source @source end |
permalink #to ⇒ Object
Returns the value of attribute to.
10 11 12 |
# File 'lib/messages/attestation.rb', line 10 def to @to end |
permalink #value ⇒ Object
Returns the value of attribute value.
10 11 12 |
# File 'lib/messages/attestation.rb', line 10 def value @value end |
permalink #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
permalink #parse(name, attestation) ⇒ Object
[View source]
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# 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 unless payload[name].nil? @value = payload[name] end end |
permalink #signed ⇒ Object
[View source]
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/messages/attestation.rb', line 43 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 |
permalink #valid_signature?(body, kid) ⇒ Boolean
32 33 34 35 36 37 |
# File 'lib/messages/attestation.rb', line 32 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 |
permalink #validate!(original) ⇒ Object
39 40 41 |
# File 'lib/messages/attestation.rb', line 39 def validate!(original) raise ::StandardError.new("invalid origin") if @to != original.to end |