class WebAuthn::AuthenticatorAttestationResponse

def self.from_client(response, relying_party: WebAuthn.configuration.relying_party)

def self.from_client(response, relying_party: WebAuthn.configuration.relying_party)
  encoder = relying_party.encoder
  new(
    attestation_object: encoder.decode(response["attestationObject"]),
    transports: response["transports"],
    client_data_json: encoder.decode(response["clientDataJSON"]),
    relying_party: relying_party
  )
end

def attestation_object

def attestation_object
  @attestation_object ||= WebAuthn::AttestationObject.deserialize(attestation_object_bytes, relying_party)
end

def initialize(attestation_object:, transports: [], **options)

def initialize(attestation_object:, transports: [], **options)
  super(**options)
  @attestation_object_bytes = attestation_object
  @transports = transports
  @relying_party = relying_party
end

def type

def type
  WebAuthn::TYPES[:create]
end

def valid_attestation_statement?

def valid_attestation_statement?
  @attestation_type, @attestation_trust_path = attestation_object.valid_attestation_statement?(client_data.hash)
end

def valid_attested_credential?

def valid_attested_credential?
  attestation_object.valid_attested_credential? &&
    relying_party.algorithms.include?(authenticator_data.credential.algorithm)
end

def verify(expected_challenge, expected_origin = nil, user_presence: nil, user_verification: nil, rp_id: nil)

def verify(expected_challenge, expected_origin = nil, user_presence: nil, user_verification: nil, rp_id: nil)
  super
  verify_item(:attested_credential)
  if relying_party.verify_attestation_statement
    verify_item(:attestation_statement)
  end
  true
end