-
-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathclient_data.rb
More file actions
45 lines (35 loc) · 791 Bytes
/
client_data.rb
File metadata and controls
45 lines (35 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# frozen_string_literal: true
require "json"
require "openssl"
require "webauthn/encoder"
require "webauthn/error"
module WebAuthn
class ClientDataMissingError < Error; end
class ClientData
def initialize(client_data_json)
@client_data_json = client_data_json
end
def type
data["type"]
end
def challenge
WebAuthn.standard_encoder.decode(data["challenge"])
end
def origin
data["origin"]
end
def hash
OpenSSL::Digest::SHA256.digest(client_data_json)
end
private
attr_reader :client_data_json
def data
@data ||=
if client_data_json
JSON.parse(client_data_json)
else
raise ClientDataMissingError, "Client Data JSON is missing"
end
end
end
end