Module: Sidetree::Util::JWS
- Defined in:
- lib/sidetree/util/jws.rb
Class Method Summary collapse
-
.parse(jws_string) ⇒ JSON::JWS
Parse
jws_string
to JSON::JWS. -
.sign(claim, private_key) ⇒ JSON::JWS
Sign to
claim
byprivate_key
. -
.valid?(jws) ⇒ Boolean
Check whether valid
jws
or not as sidetree jws. -
.validate!(jws) ⇒ Object
Validate
jws
as sidetree jws.
Class Method Details
.parse(jws_string) ⇒ JSON::JWS
Parse jws_string
to JSON::JWS
20 21 22 23 24 25 |
# File 'lib/sidetree/util/jws.rb', line 20 def parse(jws_string) jws = JSON::JWS.decode_compact_serialized(jws_string, :skip_verification) validate!(jws) jws end |
.sign(claim, private_key) ⇒ JSON::JWS
Sign to claim
by private_key
.
10 11 12 13 14 |
# File 'lib/sidetree/util/jws.rb', line 10 def sign(claim, private_key) jwt = JSON::JWT.new(claim) jwt.header.delete(:typ) jwt.sign(private_key.jws_sign_key, :ES256K) end |
.valid?(jws) ⇒ Boolean
Check whether valid jws
or not as sidetree jws.
30 31 32 33 34 35 36 37 |
# File 'lib/sidetree/util/jws.rb', line 30 def valid?(jws) begin validate!(jws) true rescue Sidetree::Error false end end |
.validate!(jws) ⇒ Object
Validate jws
as sidetree jws.
42 43 44 45 46 47 48 49 |
# File 'lib/sidetree/util/jws.rb', line 42 def validate!(jws) unless jws.header.length == 1 raise Sidetree::Error, "jws header missing or unknown property" end unless jws.header[:alg] == "ES256K" raise Sidetree::Error, "jws header missing or incorrect alg" end end |