Class: HealthCards::Issuer

Inherits:
Object
  • Object
show all
Defined in:
lib/health_cards/issuer.rb

Overview

Issue Health Cards based on a stored private key

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, url: nil) ⇒ Issuer

Create an Issuer

Parameters:



13
14
15
16
17
# File 'lib/health_cards/issuer.rb', line 13

def initialize(key:, url: nil)
  @url = url
  PrivateKey.enforce_valid_key_type!(key)
  self.key = key
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



8
9
10
# File 'lib/health_cards/issuer.rb', line 8

def key
  @key
end

#urlObject (readonly)

Returns the value of attribute url.



8
9
10
# File 'lib/health_cards/issuer.rb', line 8

def url
  @url
end

Instance Method Details

#create_payload(bundle, type: Payload) ⇒ Payload::

Create a Payload from the supplied FHIR bundle

Parameters:

  • bundle (FHIR::Bundle, String)

    the FHIR bundle used as the Health Card payload

Returns:



23
24
25
# File 'lib/health_cards/issuer.rb', line 23

def create_payload(bundle, type: Payload)
  type.new(issuer: url, bundle: bundle)
end

#issue_health_card(bundle, type: Payload) ⇒ Object



38
39
40
41
# File 'lib/health_cards/issuer.rb', line 38

def issue_health_card(bundle, type: Payload)
  jws = issue_jws(bundle, type: type)
  HealthCards::HealthCard.new(jws)
end

#issue_jws(bundle, type: Payload) ⇒ HealthCards::JWS

Create a JWS for a given payload

Leave blank for default SMART Health Card behavior

Parameters:

  • bundle (FHIR::Bundle)

    A FHIR::Bundle that will form the payload of the JWS object

  • type (Class) (defaults to: Payload)

    A subclass of HealthCards::Card that processes the bundle according to a specific IG.

Returns:

  • (HealthCards::JWS)

    An instance of JWS using the payload and signed by the issuer’s private key



33
34
35
36
# File 'lib/health_cards/issuer.rb', line 33

def issue_jws(bundle, type: Payload)
  card = create_payload(bundle, type: type)
  JWS.new(header: jws_header, payload: card.to_s, key: key)
end

#to_jwkString

Returns the public key matching this issuer’s private key as a JWK KeySet JSON string useful for .well-known endpoints

Returns:

  • (String)

    JSON string in JWK standard



55
56
57
# File 'lib/health_cards/issuer.rb', line 55

def to_jwk
  KeySet.new(key.public_key).to_jwk
end