Module: Sidetree::Util::JWK
- Defined in:
- lib/sidetree/util/jwk.rb
Class Method Summary collapse
-
.parse(params) ⇒ JSON::JWK
Parse jwk hash object.
-
.validate!(jwk) ⇒ Object
Validate jwk object as sidetree jwk.
Class Method Details
.parse(params) ⇒ JSON::JWK
Parse jwk hash object. The returned jwk does not include the kid.
10 11 12 13 14 |
# File 'lib/sidetree/util/jwk.rb', line 10 def parse(params) jwk = JSON::JWK.new(params) jwk.delete("kid") jwk end |
.validate!(jwk) ⇒ Object
Validate jwk object as sidetree jwk.
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 |
# File 'lib/sidetree/util/jwk.rb', line 19 def validate!(jwk) raise Sidetree::Error unless jwk.is_a?(JSON::JWK) jwk.keys.each do |k| unless %w[kty crv x y].include?(k) raise Sidetree::Error, "JWK Es256k has unknown property" end end unless jwk[:kty] == "EC" raise Sidetree::Error, "JWK Es256k missing or invalid kty" end unless jwk[:crv] == "secp256k1" raise Sidetree::Error, "JWK Es256k missing or invalid crv" end unless jwk[:x].is_a?(String) raise Sidetree::Error, "JWK Es256k missing or invalid type x" end unless jwk[:y].is_a?(String) raise Sidetree::Error, "JWK Es256k missing or invalid type y" end unless jwk[:x].length == 43 raise Sidetree::Error, "JWK Es256k has incorrect length of x" end unless jwk[:y].length == 43 raise Sidetree::Error, "JWK Es256k has incorrect length of y" end end |