module HealthCards::Importer

Converts a JWS to formats needed by endpoints (e.g. $issue-health-card, download and qr code)

Public Class Methods

scan(qr_contents) click to toggle source

Scan QR code @param [Array<String>] Array containing numeric QR chunks @return [Hash] Hash containing the JWS payload and verification contents

# File lib/health_cards/importer.rb, line 20
def self.scan(qr_contents)
  qr_codes = QRCodes.new(qr_contents)
  verify_jws qr_codes.to_jws
end
upload(jws_string) click to toggle source

Import JWS from file upload @param [String] JSON string containing file upload contents @return [Array<Hash>] An array of Hashes containing JWS payload and verification contents

# File lib/health_cards/importer.rb, line 9
def self.upload(jws_string)
  vc = JSON.parse(jws_string)
  vc_jws = vc['verifiableCredential']
  vc_jws.map do |j|
    verify_jws j
  end
end

Private Class Methods

verify_jws(jws_string) click to toggle source

Verify JWS signature @param [String] JWS string @return [Hash] Hash containing the JWS payload and verification contents

# File lib/health_cards/importer.rb, line 28
                     def self.verify_jws(jws_string)
  jws = JWS.from_jws jws_string
  result = { payload: HealthCard.decompress_payload(jws.payload) }
  begin
    result[:verified] = Verifier.verify jws
    result[:error_message] = 'Signature Invalid' if result[:verified] == false
  rescue MissingPublicKeyError, UnresolvableKeySetError => e
    result[:verified] = false
    result[:error_message] = e.message
  end

  result
end