Files
fizzy/lib/action_pack/web_authn/public_key_credential.rb
T
Stanko K.R. 4bb0a2929c Implement WebAuthn protocol
- Add a CBOR decoder
- Add public key credential options
- Add COSE key decoder
- Add authenticator attestation and assertion
- Add credentials
- Add exclude_credentials
2026-03-18 11:47:48 +01:00

42 lines
1.2 KiB
Ruby

class ActionPack::WebAuthn::PublicKeyCredential
attr_reader :id, :public_key, :sign_count, :owner
class << self
def create(client_data_json:, attestation_object:, challenge:, origin:, owner: nil)
response = ActionPack::WebAuthn::Authenticator::AttestationResponse.new(
client_data_json: client_data_json,
attestation_object: attestation_object
)
response.validate!(challenge: challenge, origin: origin)
new(
id: response.attestation.credential_id,
public_key: response.attestation.public_key,
sign_count: response.attestation.sign_count,
owner: owner
)
end
end
def initialize(id:, public_key:, sign_count:, owner: nil)
@id = id
@public_key = public_key
@sign_count = sign_count
@owner = owner
end
def authenticate(client_data_json:, authenticator_data:, signature:, challenge:, origin:)
response = ActionPack::WebAuthn::Authenticator::AssertionResponse.new(
client_data_json: client_data_json,
authenticator_data: authenticator_data,
signature: signature,
credential: self
)
response.validate!(challenge: challenge, origin: origin)
@sign_count = response.authenticator_data.sign_count
end
end