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.
8 9 10 |
# File 'lib/messages/attestation.rb', line 8 def initialize(messaging) @messaging = messaging end |
Instance Attribute Details
permalink #audience ⇒ Object
Returns the value of attribute audience.
6 7 8 |
# File 'lib/messages/attestation.rb', line 6 def audience @audience end |
permalink #expected_value ⇒ Object
Returns the value of attribute expected_value.
6 7 8 |
# File 'lib/messages/attestation.rb', line 6 def expected_value @expected_value end |
permalink #fact_name ⇒ Object
Returns the value of attribute fact_name.
6 7 8 |
# File 'lib/messages/attestation.rb', line 6 def fact_name @fact_name end |
permalink #operator ⇒ Object
Returns the value of attribute operator.
6 7 8 |
# File 'lib/messages/attestation.rb', line 6 def operator @operator end |
permalink #origin ⇒ Object
Returns the value of attribute origin.
6 7 8 |
# File 'lib/messages/attestation.rb', line 6 def origin @origin end |
permalink #source ⇒ Object
Returns the value of attribute source.
6 7 8 |
# File 'lib/messages/attestation.rb', line 6 def source @source end |
permalink #to ⇒ Object
Returns the value of attribute to.
6 7 8 |
# File 'lib/messages/attestation.rb', line 6 def to @to end |
permalink #value ⇒ Object
Returns the value of attribute value.
6 7 8 |
# File 'lib/messages/attestation.rb', line 6 def value @value end |
permalink #verified ⇒ Object
Returns the value of attribute verified.
6 7 8 |
# File 'lib/messages/attestation.rb', line 6 def verified @verified end |
Instance Method Details
permalink #parse(name, attestation) ⇒ Object
[View source]
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/messages/attestation.rb', line 12 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]
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/messages/attestation.rb', line 39 def signed o = { sub: @to, iss: @origin, 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
28 29 30 31 32 33 |
# File 'lib/messages/attestation.rb', line 28 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
35 36 37 |
# File 'lib/messages/attestation.rb', line 35 def validate!(original) raise ::StandardError.new("invalid origin") if @to != original.to end |